6 * This file is released under the GPLv2
9 #include <linux/kernel.h>
10 #include <linux/of_mtd.h>
11 #include <linux/mtd/nand.h>
12 #include <linux/export.h>
15 * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
16 * into the device tree binding of 'nand-ecc', so that MTD
17 * device driver can get nand ecc from device tree.
19 static const char *nand_ecc_modes[] = {
20 [NAND_ECC_NONE] = "none",
21 [NAND_ECC_SOFT] = "soft",
23 [NAND_ECC_HW_SYNDROME] = "hw_syndrome",
24 [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
25 [NAND_ECC_SOFT_BCH] = "soft_bch",
29 * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
30 * @np: Pointer to the given device_node
32 * The function gets ecc mode string from property 'nand-ecc-mode',
33 * and return its index in nand_ecc_modes table, or errno in error case.
35 int of_get_nand_ecc_mode(struct device_node *np)
40 err = of_property_read_string(np, "nand-ecc-mode", &pm);
44 for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
45 if (!strcasecmp(pm, nand_ecc_modes[i]))
50 EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
53 * of_get_nand_ecc_step_size - Get ECC step size associated to
54 * the required ECC strength (see below).
55 * @np: Pointer to the given device_node
57 * return the ECC step size, or errno in error case.
59 int of_get_nand_ecc_step_size(struct device_node *np)
64 ret = of_property_read_u32(np, "nand-ecc-step-size", &val);
65 return ret ? ret : val;
67 EXPORT_SYMBOL_GPL(of_get_nand_ecc_step_size);
70 * of_get_nand_ecc_strength - Get required ECC strength over the
71 * correspnding step size as defined by 'nand-ecc-size'
72 * @np: Pointer to the given device_node
74 * return the ECC strength, or errno in error case.
76 int of_get_nand_ecc_strength(struct device_node *np)
81 ret = of_property_read_u32(np, "nand-ecc-strength", &val);
82 return ret ? ret : val;
84 EXPORT_SYMBOL_GPL(of_get_nand_ecc_strength);
87 * of_get_nand_bus_width - Get nand bus witdh for given device_node
88 * @np: Pointer to the given device_node
90 * return bus width option, or errno in error case.
92 int of_get_nand_bus_width(struct device_node *np)
96 if (of_property_read_u32(np, "nand-bus-width", &val))
107 EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
110 * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
111 * @np: Pointer to the given device_node
113 * return true if present false other wise
115 bool of_get_nand_on_flash_bbt(struct device_node *np)
117 return of_property_read_bool(np, "nand-on-flash-bbt");
119 EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);