sunxi: add support for 4.1
[openwrt/svn-archive/archive.git] / target / linux / sunxi / patches-4.1 / 115-mtd-fetch-randomizer-mode.patch
1 From eb7f9115409710732ebc4dfe1be629252280910e Mon Sep 17 00:00:00 2001
2 From: Boris BREZILLON <boris.brezillon@free-electrons.com>
3 Date: Mon, 28 Jul 2014 14:47:04 +0200
4 Subject: [PATCH] of: mtd: Add NAND randomizer mode retrieval
5
6 Add a of_get_nand_rnd_mode() helper function.
7
8 Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
9 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 ---
11 drivers/of/of_mtd.c | 35 +++++++++++++++++++++++++++++++++++
12 include/linux/of_mtd.h | 6 ++++++
13 2 files changed, 41 insertions(+)
14
15 diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
16 index b7361ed..4e42c26 100644
17 --- a/drivers/of/of_mtd.c
18 +++ b/drivers/of/of_mtd.c
19 @@ -84,6 +84,41 @@ int of_get_nand_ecc_strength(struct device_node *np)
20 EXPORT_SYMBOL_GPL(of_get_nand_ecc_strength);
21
22 /**
23 + * It maps 'enum nand_rnd_modes_t' found in include/linux/mtd/nand.h
24 + * into the device tree binding of 'nand-rnd', so that MTD
25 + * device driver can get nand rnd from device tree.
26 + */
27 +static const char *nand_rnd_modes[] = {
28 + [NAND_RND_NONE] = "none",
29 + [NAND_RND_SOFT] = "soft",
30 + [NAND_RND_HW] = "hw",
31 +};
32 +
33 +/**
34 + * of_get_nand_rnd_mode - Get nand randomizer mode for given device_node
35 + * @np: Pointer to the given device_node
36 + *
37 + * The function gets randomizer mode string from property 'nand-rnd-mode',
38 + * and return its index in nand_rnd_modes table, or errno in error case.
39 + */
40 +int of_get_nand_rnd_mode(struct device_node *np)
41 +{
42 + const char *pm;
43 + int err, i;
44 +
45 + err = of_property_read_string(np, "nand-rnd-mode", &pm);
46 + if (err < 0)
47 + return err;
48 +
49 + for (i = 0; i < ARRAY_SIZE(nand_rnd_modes); i++)
50 + if (!strcasecmp(pm, nand_rnd_modes[i]))
51 + return i;
52 +
53 + return -ENODEV;
54 +}
55 +EXPORT_SYMBOL_GPL(of_get_nand_rnd_mode);
56 +
57 +/**
58 * of_get_nand_bus_width - Get nand bus witdh for given device_node
59 * @np: Pointer to the given device_node
60 *
61 diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
62 index e266caa..1059472 100644
63 --- a/include/linux/of_mtd.h
64 +++ b/include/linux/of_mtd.h
65 @@ -15,6 +15,7 @@
66 int of_get_nand_ecc_mode(struct device_node *np);
67 int of_get_nand_ecc_step_size(struct device_node *np);
68 int of_get_nand_ecc_strength(struct device_node *np);
69 +int of_get_nand_rnd_mode(struct device_node *np);
70 int of_get_nand_bus_width(struct device_node *np);
71 bool of_get_nand_on_flash_bbt(struct device_node *np);
72
73 @@ -35,6 +36,11 @@ static inline int of_get_nand_ecc_strength(struct device_node *np)
74 return -ENOSYS;
75 }
76
77 +static inline int of_get_nand_rnd_mode(struct device_node *np)
78 +{
79 + return -ENOSYS;
80 +}
81 +
82 static inline int of_get_nand_bus_width(struct device_node *np)
83 {
84 return -ENOSYS;