807-v5.17-0003-nvmem-core-Fix-a-conflict-between-MTD-and-NVMEM-on-w.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From f6c052afe6f802d87c74153b7a57c43b2e9faf07 Mon Sep 17 00:00:00 2001
  2. From: Christophe Kerello <[email protected]>
  3. Date: Sun, 20 Feb 2022 15:14:31 +0000
  4. Subject: [PATCH] nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios
  5. property
  6. Wp-gpios property can be used on NVMEM nodes and the same property can
  7. be also used on MTD NAND nodes. In case of the wp-gpios property is
  8. defined at NAND level node, the GPIO management is done at NAND driver
  9. level. Write protect is disabled when the driver is probed or resumed
  10. and is enabled when the driver is released or suspended.
  11. When no partitions are defined in the NAND DT node, then the NAND DT node
  12. will be passed to NVMEM framework. If wp-gpios property is defined in
  13. this node, the GPIO resource is taken twice and the NAND controller
  14. driver fails to probe.
  15. It would be possible to set config->wp_gpio at MTD level before calling
  16. nvmem_register function but NVMEM framework will toggle this GPIO on
  17. each write when this GPIO should only be controlled at NAND level driver
  18. to ensure that the Write Protect has not been enabled.
  19. A way to fix this conflict is to add a new boolean flag in nvmem_config
  20. named ignore_wp. In case ignore_wp is set, the GPIO resource will
  21. be managed by the provider.
  22. Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
  23. Cc: [email protected]
  24. Signed-off-by: Christophe Kerello <[email protected]>
  25. Signed-off-by: Srinivas Kandagatla <[email protected]>
  26. Link: https://lore.kernel.org/r/[email protected]
  27. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  28. ---
  29. drivers/nvmem/core.c | 2 +-
  30. include/linux/nvmem-provider.h | 4 +++-
  31. 2 files changed, 4 insertions(+), 2 deletions(-)
  32. --- a/drivers/nvmem/core.c
  33. +++ b/drivers/nvmem/core.c
  34. @@ -771,7 +771,7 @@ struct nvmem_device *nvmem_register(cons
  35. if (config->wp_gpio)
  36. nvmem->wp_gpio = config->wp_gpio;
  37. - else
  38. + else if (!config->ignore_wp)
  39. nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
  40. GPIOD_OUT_HIGH);
  41. if (IS_ERR(nvmem->wp_gpio)) {
  42. --- a/include/linux/nvmem-provider.h
  43. +++ b/include/linux/nvmem-provider.h
  44. @@ -70,7 +70,8 @@ struct nvmem_keepout {
  45. * @word_size: Minimum read/write access granularity.
  46. * @stride: Minimum read/write access stride.
  47. * @priv: User context passed to read/write callbacks.
  48. - * @wp-gpio: Write protect pin
  49. + * @wp-gpio: Write protect pin
  50. + * @ignore_wp: Write Protect pin is managed by the provider.
  51. *
  52. * Note: A default "nvmem<id>" name will be assigned to the device if
  53. * no name is specified in its configuration. In such case "<id>" is
  54. @@ -92,6 +93,7 @@ struct nvmem_config {
  55. enum nvmem_type type;
  56. bool read_only;
  57. bool root_only;
  58. + bool ignore_wp;
  59. struct device_node *of_node;
  60. bool no_of_node;
  61. nvmem_reg_read_t reg_read;