brcm2708: Add support for raspberry pi 3 b+.
[openwrt/staging/wigyori.git] / target / linux / bcm53xx / patches-4.4 / 140-mtd-brcmnand-set-initial-ECC-params-based-on-info-fr.patch
1 From eff78bc2c385f592294278582f38ad5fa4ed2b34 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 27 Jan 2016 08:47:03 +0100
4 Subject: [PATCH] mtd: brcmnand: set initial ECC params based on info from HW
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 So far we were depending on nand_dt_init getting ECC info from DT and
10 setting it in ECC struct. It is possible to simply read this info from
11 hardware registers which makes adding support for new hardware way
12 easier (no more guessing & trying all combinations).
13 Please note it still gives a precedence to DT which was overwrite
14 whatever was initially set by the driver.
15
16 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
17 ---
18 It took me hours to figure out how to setup NAND on my D-Link DIR-885L.
19 This should be very helpful for ppl adding new devices support.
20 ---
21 drivers/mtd/nand/brcmnand/brcmnand.c | 14 ++++++++++++++
22 1 file changed, 14 insertions(+)
23
24 --- a/drivers/mtd/nand/brcmnand/brcmnand.c
25 +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
26 @@ -645,6 +645,17 @@ static inline u32 brcmnand_ecc_level_mas
27 return mask << NAND_ACC_CONTROL_ECC_SHIFT;
28 }
29
30 +static int brcmnand_get_ecc_strength(struct brcmnand_host *host)
31 +{
32 + struct brcmnand_controller *ctrl = host->ctrl;
33 + u32 mask = brcmnand_ecc_level_mask(ctrl);
34 + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs,
35 + BRCMNAND_CS_ACC_CONTROL);
36 +
37 + return (nand_readreg(ctrl, acc_control_offs) & mask) >>
38 + NAND_ACC_CONTROL_ECC_SHIFT;
39 +}
40 +
41 static void brcmnand_set_ecc_enabled(struct brcmnand_host *host, int en)
42 {
43 struct brcmnand_controller *ctrl = host->ctrl;
44 @@ -1990,6 +2001,9 @@ static int brcmnand_init_cs(struct brcmn
45 nand_writereg(ctrl, cfg_offs,
46 nand_readreg(ctrl, cfg_offs) & ~CFG_BUS_WIDTH);
47
48 + chip->ecc.strength = brcmnand_get_ecc_strength(host);
49 + chip->ecc.size = brcmnand_get_sector_size_1k(host) ? 1024 : 512;
50 +
51 if (nand_scan_ident(mtd, 1, NULL))
52 return -ENXIO;
53