090-mtd-nand-add-common-DT-init-code.patch 3.3 KB

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