oxnas: backport upstream NAND driver
[openwrt/staging/chunkeey.git] / target / linux / oxnas / patches-4.4 / 0073-of-mtd-prepare-helper-reading-NAND-ECC-algo-from-DT.patch
1 From 410a91f6efa1c4c3c4369d1dd2c31286749dff33 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 23 Mar 2016 11:19:01 +0100
4 Subject: [PATCH 073/102] of: mtd: prepare helper reading NAND ECC algo from
5 DT
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 NAND subsystem is being slightly reworked to store ECC details in
11 separated fields. In future we'll want to add support for more DT
12 properties as specifying every possible setup with a single
13 "nand-ecc-mode" is a pretty bad idea.
14 To allow this let's add a helper that will support something like
15 "nand-ecc-algo" in future. Right now we use it for keeping backward
16 compatibility.
17
18 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
19 Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
20 ---
21 drivers/of/of_mtd.c | 36 ++++++++++++++++++++++++++++++++++++
22 include/linux/of_mtd.h | 6 ++++++
23 2 files changed, 42 insertions(+)
24
25 --- a/drivers/of/of_mtd.c
26 +++ b/drivers/of/of_mtd.c
27 @@ -50,6 +50,42 @@ int of_get_nand_ecc_mode(struct device_n
28 EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
29
30 /**
31 + * of_get_nand_ecc_algo - Get nand ecc algorithm for given device_node
32 + * @np: Pointer to the given device_node
33 + *
34 + * The function gets ecc algorithm and returns its enum value, or errno in error
35 + * case.
36 + */
37 +int of_get_nand_ecc_algo(struct device_node *np)
38 +{
39 + const char *pm;
40 + int err;
41 +
42 + /*
43 + * TODO: Read ECC algo OF property and map it to enum nand_ecc_algo.
44 + * It's not implemented yet as currently NAND subsystem ignores
45 + * algorithm explicitly set this way. Once it's handled we should
46 + * document & support new property.
47 + */
48 +
49 + /*
50 + * For backward compatibility we also read "nand-ecc-mode" checking
51 + * for some obsoleted values that were specifying ECC algorithm.
52 + */
53 + err = of_property_read_string(np, "nand-ecc-mode", &pm);
54 + if (err < 0)
55 + return err;
56 +
57 + if (!strcasecmp(pm, "soft"))
58 + return NAND_ECC_HAMMING;
59 + else if (!strcasecmp(pm, "soft_bch"))
60 + return NAND_ECC_BCH;
61 +
62 + return -ENODEV;
63 +}
64 +EXPORT_SYMBOL_GPL(of_get_nand_ecc_algo);
65 +
66 +/**
67 * of_get_nand_ecc_step_size - Get ECC step size associated to
68 * the required ECC strength (see below).
69 * @np: Pointer to the given device_node
70 --- a/include/linux/of_mtd.h
71 +++ b/include/linux/of_mtd.h
72 @@ -13,6 +13,7 @@
73
74 #include <linux/of.h>
75 int of_get_nand_ecc_mode(struct device_node *np);
76 +int of_get_nand_ecc_algo(struct device_node *np);
77 int of_get_nand_ecc_step_size(struct device_node *np);
78 int of_get_nand_ecc_strength(struct device_node *np);
79 int of_get_nand_bus_width(struct device_node *np);
80 @@ -24,6 +25,11 @@ static inline int of_get_nand_ecc_mode(s
81 {
82 return -ENOSYS;
83 }
84 +
85 +static inline int of_get_nand_ecc_algo(struct device_node *np)
86 +{
87 + return -ENOSYS;
88 +}
89
90 static inline int of_get_nand_ecc_step_size(struct device_node *np)
91 {