115-mtd-fetch-randomizer-mode.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From eb7f9115409710732ebc4dfe1be629252280910e Mon Sep 17 00:00:00 2001
  2. From: Boris BREZILLON <boris.brezillon@free-electrons.com>
  3. Date: Mon, 28 Jul 2014 14:47:04 +0200
  4. Subject: [PATCH] of: mtd: Add NAND randomizer mode retrieval
  5. Add a of_get_nand_rnd_mode() helper function.
  6. Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
  7. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  8. ---
  9. drivers/of/of_mtd.c | 35 +++++++++++++++++++++++++++++++++++
  10. include/linux/of_mtd.h | 6 ++++++
  11. 2 files changed, 41 insertions(+)
  12. --- a/drivers/of/of_mtd.c
  13. +++ b/drivers/of/of_mtd.c
  14. @@ -84,6 +84,41 @@ int of_get_nand_ecc_strength(struct devi
  15. EXPORT_SYMBOL_GPL(of_get_nand_ecc_strength);
  16. /**
  17. + * It maps 'enum nand_rnd_modes_t' found in include/linux/mtd/nand.h
  18. + * into the device tree binding of 'nand-rnd', so that MTD
  19. + * device driver can get nand rnd from device tree.
  20. + */
  21. +static const char *nand_rnd_modes[] = {
  22. + [NAND_RND_NONE] = "none",
  23. + [NAND_RND_SOFT] = "soft",
  24. + [NAND_RND_HW] = "hw",
  25. +};
  26. +
  27. +/**
  28. + * of_get_nand_rnd_mode - Get nand randomizer mode for given device_node
  29. + * @np: Pointer to the given device_node
  30. + *
  31. + * The function gets randomizer mode string from property 'nand-rnd-mode',
  32. + * and return its index in nand_rnd_modes table, or errno in error case.
  33. + */
  34. +int of_get_nand_rnd_mode(struct device_node *np)
  35. +{
  36. + const char *pm;
  37. + int err, i;
  38. +
  39. + err = of_property_read_string(np, "nand-rnd-mode", &pm);
  40. + if (err < 0)
  41. + return err;
  42. +
  43. + for (i = 0; i < ARRAY_SIZE(nand_rnd_modes); i++)
  44. + if (!strcasecmp(pm, nand_rnd_modes[i]))
  45. + return i;
  46. +
  47. + return -ENODEV;
  48. +}
  49. +EXPORT_SYMBOL_GPL(of_get_nand_rnd_mode);
  50. +
  51. +/**
  52. * of_get_nand_bus_width - Get nand bus witdh for given device_node
  53. * @np: Pointer to the given device_node
  54. *
  55. --- a/include/linux/of_mtd.h
  56. +++ b/include/linux/of_mtd.h
  57. @@ -15,6 +15,7 @@
  58. int of_get_nand_ecc_mode(struct device_node *np);
  59. int of_get_nand_ecc_step_size(struct device_node *np);
  60. int of_get_nand_ecc_strength(struct device_node *np);
  61. +int of_get_nand_rnd_mode(struct device_node *np);
  62. int of_get_nand_bus_width(struct device_node *np);
  63. bool of_get_nand_on_flash_bbt(struct device_node *np);
  64. @@ -34,6 +35,11 @@ static inline int of_get_nand_ecc_streng
  65. {
  66. return -ENOSYS;
  67. }
  68. +
  69. +static inline int of_get_nand_rnd_mode(struct device_node *np)
  70. +{
  71. + return -ENOSYS;
  72. +}
  73. static inline int of_get_nand_bus_width(struct device_node *np)
  74. {