bcm53xx: add early support for Linksys EA6300 V1
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-4.1 / 090-mtd-nand-add-common-DT-init-code.patch
1 From 5844feeaa4154d1c46d3462c7a4653d22356d8b4 Mon Sep 17 00:00:00 2001
2 From: Brian Norris <computersforpeace@gmail.com>
3 Date: Fri, 23 Jan 2015 00:22:27 -0800
4 Subject: [PATCH 20/32] mtd: nand: add common DT init code
5
6 These are already-documented common bindings for NAND chips. Let's
7 handle them in nand_base.
8
9 If NAND controller drivers need to act on this data before bringing up
10 the NAND chip (e.g., fill out ECC callback functions, change HW modes,
11 etc.), then they can do so between calling nand_scan_ident() and
12 nand_scan_tail().
13
14 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
15 ---
16 drivers/mtd/nand/nand_base.c | 41 +++++++++++++++++++++++++++++++++++++++++
17 include/linux/mtd/nand.h | 5 +++++
18 2 files changed, 46 insertions(+)
19
20 --- a/drivers/mtd/nand/nand_base.c
21 +++ b/drivers/mtd/nand/nand_base.c
22 @@ -48,6 +48,7 @@
23 #include <linux/leds.h>
24 #include <linux/io.h>
25 #include <linux/mtd/partitions.h>
26 +#include <linux/of_mtd.h>
27
28 /* Define default oob placement schemes for large and small page devices */
29 static struct nand_ecclayout nand_oob_8 = {
30 @@ -3798,6 +3799,39 @@ ident_done:
31 return type;
32 }
33
34 +static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip,
35 + struct device_node *dn)
36 +{
37 + int ecc_mode, ecc_strength, ecc_step;
38 +
39 + if (of_get_nand_bus_width(dn) == 16)
40 + chip->options |= NAND_BUSWIDTH_16;
41 +
42 + if (of_get_nand_on_flash_bbt(dn))
43 + chip->bbt_options |= NAND_BBT_USE_FLASH;
44 +
45 + ecc_mode = of_get_nand_ecc_mode(dn);
46 + ecc_strength = of_get_nand_ecc_strength(dn);
47 + ecc_step = of_get_nand_ecc_step_size(dn);
48 +
49 + if ((ecc_step >= 0 && !(ecc_strength >= 0)) ||
50 + (!(ecc_step >= 0) && ecc_strength >= 0)) {
51 + pr_err("must set both strength and step size in DT\n");
52 + return -EINVAL;
53 + }
54 +
55 + if (ecc_mode >= 0)
56 + chip->ecc.mode = ecc_mode;
57 +
58 + if (ecc_strength >= 0)
59 + chip->ecc.strength = ecc_strength;
60 +
61 + if (ecc_step > 0)
62 + chip->ecc.size = ecc_step;
63 +
64 + return 0;
65 +}
66 +
67 /**
68 * nand_scan_ident - [NAND Interface] Scan for the NAND device
69 * @mtd: MTD device structure
70 @@ -3815,6 +3849,13 @@ int nand_scan_ident(struct mtd_info *mtd
71 int i, nand_maf_id, nand_dev_id;
72 struct nand_chip *chip = mtd->priv;
73 struct nand_flash_dev *type;
74 + int ret;
75 +
76 + if (chip->dn) {
77 + ret = nand_dt_init(mtd, chip, chip->dn);
78 + if (ret)
79 + return ret;
80 + }
81
82 /* Set the default functions */
83 nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
84 --- a/include/linux/mtd/nand.h
85 +++ b/include/linux/mtd/nand.h
86 @@ -26,6 +26,8 @@
87
88 struct mtd_info;
89 struct nand_flash_dev;
90 +struct device_node;
91 +
92 /* Scan and identify a NAND device */
93 extern int nand_scan(struct mtd_info *mtd, int max_chips);
94 /*
95 @@ -542,6 +544,7 @@ struct nand_buffers {
96 * flash device
97 * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the
98 * flash device.
99 + * @dn: [BOARDSPECIFIC] device node describing this instance
100 * @read_byte: [REPLACEABLE] read one byte from the chip
101 * @read_word: [REPLACEABLE] read one word from the chip
102 * @write_byte: [REPLACEABLE] write a single byte to the chip on the
103 @@ -644,6 +647,8 @@ struct nand_chip {
104 void __iomem *IO_ADDR_R;
105 void __iomem *IO_ADDR_W;
106
107 + struct device_node *dn;
108 +
109 uint8_t (*read_byte)(struct mtd_info *mtd);
110 u16 (*read_word)(struct mtd_info *mtd);
111 void (*write_byte)(struct mtd_info *mtd, uint8_t byte);