0073-of-mtd-prepare-helper-reading-NAND-ECC-algo-from-DT.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. NAND subsystem is being slightly reworked to store ECC details in
  10. separated fields. In future we'll want to add support for more DT
  11. properties as specifying every possible setup with a single
  12. "nand-ecc-mode" is a pretty bad idea.
  13. To allow this let's add a helper that will support something like
  14. "nand-ecc-algo" in future. Right now we use it for keeping backward
  15. compatibility.
  16. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  17. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  18. ---
  19. drivers/of/of_mtd.c | 36 ++++++++++++++++++++++++++++++++++++
  20. include/linux/of_mtd.h | 6 ++++++
  21. 2 files changed, 42 insertions(+)
  22. --- a/drivers/of/of_mtd.c
  23. +++ b/drivers/of/of_mtd.c
  24. @@ -50,6 +50,42 @@ int of_get_nand_ecc_mode(struct device_n
  25. EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
  26. /**
  27. + * of_get_nand_ecc_algo - Get nand ecc algorithm for given device_node
  28. + * @np: Pointer to the given device_node
  29. + *
  30. + * The function gets ecc algorithm and returns its enum value, or errno in error
  31. + * case.
  32. + */
  33. +int of_get_nand_ecc_algo(struct device_node *np)
  34. +{
  35. + const char *pm;
  36. + int err;
  37. +
  38. + /*
  39. + * TODO: Read ECC algo OF property and map it to enum nand_ecc_algo.
  40. + * It's not implemented yet as currently NAND subsystem ignores
  41. + * algorithm explicitly set this way. Once it's handled we should
  42. + * document & support new property.
  43. + */
  44. +
  45. + /*
  46. + * For backward compatibility we also read "nand-ecc-mode" checking
  47. + * for some obsoleted values that were specifying ECC algorithm.
  48. + */
  49. + err = of_property_read_string(np, "nand-ecc-mode", &pm);
  50. + if (err < 0)
  51. + return err;
  52. +
  53. + if (!strcasecmp(pm, "soft"))
  54. + return NAND_ECC_HAMMING;
  55. + else if (!strcasecmp(pm, "soft_bch"))
  56. + return NAND_ECC_BCH;
  57. +
  58. + return -ENODEV;
  59. +}
  60. +EXPORT_SYMBOL_GPL(of_get_nand_ecc_algo);
  61. +
  62. +/**
  63. * of_get_nand_ecc_step_size - Get ECC step size associated to
  64. * the required ECC strength (see below).
  65. * @np: Pointer to the given device_node
  66. --- a/include/linux/of_mtd.h
  67. +++ b/include/linux/of_mtd.h
  68. @@ -13,6 +13,7 @@
  69. #include <linux/of.h>
  70. int of_get_nand_ecc_mode(struct device_node *np);
  71. +int of_get_nand_ecc_algo(struct device_node *np);
  72. int of_get_nand_ecc_step_size(struct device_node *np);
  73. int of_get_nand_ecc_strength(struct device_node *np);
  74. int of_get_nand_bus_width(struct device_node *np);
  75. @@ -24,6 +25,11 @@ static inline int of_get_nand_ecc_mode(s
  76. {
  77. return -ENOSYS;
  78. }
  79. +
  80. +static inline int of_get_nand_ecc_algo(struct device_node *np)
  81. +{
  82. + return -ENOSYS;
  83. +}
  84. static inline int of_get_nand_ecc_step_size(struct device_node *np)
  85. {