diff options
| author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-01-27 23:12:36 -0500 |
|---|---|---|
| committer | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-03-15 11:28:19 -0400 |
| commit | 770d7c39af940da24dd4c2c048576d778ac0abd4 (patch) | |
| tree | 7cf7f6c89bcc1a8c4db93d695b80116962df4e04 | |
| parent | fa4d34ccd0914ac87336ea2c17e9370dfecef286 (diff) | |
of/mtd/nand: add generic bindings and helpers
- nand-ecc-mode : String, operation mode of the NAND ecc mode.
Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
"soft_bch".
- nand-bus-width : 8 or 16 bus width if not present 8
- nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Stefan Roese <sr@denx.de>
| -rw-r--r-- | Documentation/devicetree/bindings/mtd/nand.txt | 7 | ||||
| -rw-r--r-- | drivers/of/Kconfig | 4 | ||||
| -rw-r--r-- | drivers/of/Makefile | 1 | ||||
| -rw-r--r-- | drivers/of/of_mtd.c | 85 | ||||
| -rw-r--r-- | include/linux/of_mtd.h | 19 |
5 files changed, 116 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/mtd/nand.txt b/Documentation/devicetree/bindings/mtd/nand.txt new file mode 100644 index 000000000000..03855c8c492a --- /dev/null +++ b/Documentation/devicetree/bindings/mtd/nand.txt | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | * MTD generic binding | ||
| 2 | |||
| 3 | - nand-ecc-mode : String, operation mode of the NAND ecc mode. | ||
| 4 | Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first", | ||
| 5 | "soft_bch". | ||
| 6 | - nand-bus-width : 8 or 16 bus width if not present 8 | ||
| 7 | - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false | ||
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 268163dd71c7..fa666a93540c 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
| @@ -90,4 +90,8 @@ config OF_PCI_IRQ | |||
| 90 | help | 90 | help |
| 91 | OpenFirmware PCI IRQ routing helpers | 91 | OpenFirmware PCI IRQ routing helpers |
| 92 | 92 | ||
| 93 | config OF_MTD | ||
| 94 | depends on MTD | ||
| 95 | def_bool y | ||
| 96 | |||
| 93 | endmenu # OF | 97 | endmenu # OF |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index a73f5a51ff4c..aa90e602c8a7 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
| @@ -12,3 +12,4 @@ obj-$(CONFIG_OF_SELFTEST) += selftest.o | |||
| 12 | obj-$(CONFIG_OF_MDIO) += of_mdio.o | 12 | obj-$(CONFIG_OF_MDIO) += of_mdio.o |
| 13 | obj-$(CONFIG_OF_PCI) += of_pci.o | 13 | obj-$(CONFIG_OF_PCI) += of_pci.o |
| 14 | obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o | 14 | obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o |
| 15 | obj-$(CONFIG_OF_MTD) += of_mtd.o | ||
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c new file mode 100644 index 000000000000..e7cad627a5d1 --- /dev/null +++ b/drivers/of/of_mtd.c | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | ||
| 3 | * | ||
| 4 | * OF helpers for mtd. | ||
| 5 | * | ||
| 6 | * This file is released under the GPLv2 | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | #include <linux/kernel.h> | ||
| 10 | #include <linux/of_mtd.h> | ||
| 11 | #include <linux/mtd/nand.h> | ||
| 12 | #include <linux/export.h> | ||
| 13 | |||
| 14 | /** | ||
| 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. | ||
| 18 | */ | ||
| 19 | static const char *nand_ecc_modes[] = { | ||
| 20 | [NAND_ECC_NONE] = "none", | ||
| 21 | [NAND_ECC_SOFT] = "soft", | ||
| 22 | [NAND_ECC_HW] = "hw", | ||
| 23 | [NAND_ECC_HW_SYNDROME] = "hw_syndrome", | ||
| 24 | [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first", | ||
| 25 | [NAND_ECC_SOFT_BCH] = "soft_bch", | ||
| 26 | }; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * of_get_nand_ecc_mode - Get nand ecc mode for given device_node | ||
| 30 | * @np: Pointer to the given device_node | ||
| 31 | * | ||
| 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. | ||
| 34 | */ | ||
| 35 | const int of_get_nand_ecc_mode(struct device_node *np) | ||
| 36 | { | ||
| 37 | const char *pm; | ||
| 38 | int err, i; | ||
| 39 | |||
| 40 | err = of_property_read_string(np, "nand-ecc-mode", &pm); | ||
| 41 | if (err < 0) | ||
| 42 | return err; | ||
| 43 | |||
| 44 | for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++) | ||
| 45 | if (!strcasecmp(pm, nand_ecc_modes[i])) | ||
| 46 | return i; | ||
| 47 | |||
| 48 | return -ENODEV; | ||
| 49 | } | ||
| 50 | EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * of_get_nand_bus_width - Get nand bus witdh for given device_node | ||
| 54 | * @np: Pointer to the given device_node | ||
| 55 | * | ||
| 56 | * return bus width option, or errno in error case. | ||
| 57 | */ | ||
| 58 | int of_get_nand_bus_width(struct device_node *np) | ||
| 59 | { | ||
| 60 | u32 val; | ||
| 61 | |||
| 62 | if (of_property_read_u32(np, "nand-bus-width", &val)) | ||
| 63 | return 8; | ||
| 64 | |||
| 65 | switch(val) { | ||
| 66 | case 8: | ||
| 67 | case 16: | ||
| 68 | return val; | ||
| 69 | default: | ||
| 70 | return -EIO; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | EXPORT_SYMBOL_GPL(of_get_nand_bus_width); | ||
| 74 | |||
| 75 | /** | ||
| 76 | * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node | ||
| 77 | * @np: Pointer to the given device_node | ||
| 78 | * | ||
| 79 | * return true if present false other wise | ||
| 80 | */ | ||
| 81 | bool of_get_nand_on_flash_bbt(struct device_node *np) | ||
| 82 | { | ||
| 83 | return of_property_read_bool(np, "nand-on-flash-bbt"); | ||
| 84 | } | ||
| 85 | EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt); | ||
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h new file mode 100644 index 000000000000..bae1b6094c63 --- /dev/null +++ b/include/linux/of_mtd.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | ||
| 3 | * | ||
| 4 | * OF helpers for mtd. | ||
| 5 | * | ||
| 6 | * This file is released under the GPLv2 | ||
| 7 | */ | ||
| 8 | |||
| 9 | #ifndef __LINUX_OF_MTD_H | ||
| 10 | #define __LINUX_OF_NET_H | ||
| 11 | |||
| 12 | #ifdef CONFIG_OF_MTD | ||
| 13 | #include <linux/of.h> | ||
| 14 | extern const int of_get_nand_ecc_mode(struct device_node *np); | ||
| 15 | int of_get_nand_bus_width(struct device_node *np); | ||
| 16 | bool of_get_nand_on_flash_bbt(struct device_node *np); | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #endif /* __LINUX_OF_MTD_H */ | ||
