2
0

0006-mtd-physmap_of_gemini-Handle-pin-control.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. From 8e5e628a9de439d02914b85a48e1ac3e04ea486a Mon Sep 17 00:00:00 2001
  2. From: Linus Walleij <[email protected]>
  3. Date: Thu, 11 Oct 2018 20:03:49 +0200
  4. Subject: [PATCH 06/18] mtd: physmap_of_gemini: Handle pin control
  5. This enables the complex mapping for the Gemini and kicks in
  6. custom read/write functions that will wrap the existing
  7. simple functions in calls to enable/disable the parallel
  8. flash pins using pin controls.
  9. This is necessary on some hardware such as the D-Link
  10. DIR-685 where all flash pins are patched in/out at the same
  11. time, but some of the flash pins are in practice unused by
  12. the flash and have anyway been reused as GPIO.
  13. This concerns specifically CE1 on the Gemini. There is only
  14. one flash chip, so only CE0 is used, and the line for CE1
  15. has been reused as chip select for the emulated SPI port
  16. connected to the display. If we try to use the same lines
  17. for flash and GPIO at the same time, one of them will loose:
  18. the GPIO line will disappear because it gets disconnected
  19. from the pin when the flash group is muxed out.
  20. Fix this by introducing two pin control states named simply
  21. "enabled" and "disabled" and only enable the flash lines
  22. when absolutely necessary (during read/write/copy). This
  23. way, they are available for GPIO at all other times and
  24. the display works.
  25. Collect all the state variables in a struct named
  26. struct gemini_flash and allocate this struct at probe
  27. time.
  28. Signed-off-by: Linus Walleij <[email protected]>
  29. ---
  30. drivers/mtd/maps/Kconfig | 1 +
  31. drivers/mtd/maps/physmap_of_gemini.c | 105 ++++++++++++++++++++++++++-
  32. 2 files changed, 105 insertions(+), 1 deletion(-)
  33. --- a/drivers/mtd/maps/Kconfig
  34. +++ b/drivers/mtd/maps/Kconfig
  35. @@ -89,6 +89,7 @@ config MTD_PHYSMAP_OF_GEMINI
  36. depends on MTD_PHYSMAP_OF
  37. depends on MFD_SYSCON
  38. default ARCH_GEMINI
  39. + select MTD_COMPLEX_MAPPINGS
  40. help
  41. This provides some extra DT physmap parsing for the Gemini
  42. platforms, some detection and setting up parallel mode on the
  43. --- a/drivers/mtd/maps/physmap_of_gemini.c
  44. +++ b/drivers/mtd/maps/physmap_of_gemini.c
  45. @@ -10,9 +10,11 @@
  46. #include <linux/of.h>
  47. #include <linux/of_device.h>
  48. #include <linux/mtd/map.h>
  49. +#include <linux/mtd/xip.h>
  50. #include <linux/mfd/syscon.h>
  51. #include <linux/regmap.h>
  52. #include <linux/bitops.h>
  53. +#include <linux/pinctrl/consumer.h>
  54. #include "physmap_of_gemini.h"
  55. /*
  56. @@ -49,6 +51,77 @@ static const struct of_device_id syscon_
  57. { },
  58. };
  59. +struct gemini_flash {
  60. + struct device *dev;
  61. + struct pinctrl *p;
  62. + struct pinctrl_state *enabled_state;
  63. + struct pinctrl_state *disabled_state;
  64. +};
  65. +
  66. +/* Static local state */
  67. +static struct gemini_flash *gf;
  68. +
  69. +static void gemini_flash_enable_pins(void)
  70. +{
  71. + int ret;
  72. +
  73. + if (IS_ERR(gf->enabled_state))
  74. + return;
  75. + ret = pinctrl_select_state(gf->p, gf->enabled_state);
  76. + if (ret)
  77. + dev_err(gf->dev, "failed to enable pins\n");
  78. +}
  79. +
  80. +static void gemini_flash_disable_pins(void)
  81. +{
  82. + int ret;
  83. +
  84. + if (IS_ERR(gf->disabled_state))
  85. + return;
  86. + ret = pinctrl_select_state(gf->p, gf->disabled_state);
  87. + if (ret)
  88. + dev_err(gf->dev, "failed to disable pins\n");
  89. +}
  90. +
  91. +static map_word __xipram gemini_flash_map_read(struct map_info *map,
  92. + unsigned long ofs)
  93. +{
  94. + map_word __xipram ret;
  95. +
  96. + gemini_flash_enable_pins();
  97. + ret = inline_map_read(map, ofs);
  98. + gemini_flash_disable_pins();
  99. +
  100. + return ret;
  101. +}
  102. +
  103. +static void __xipram gemini_flash_map_write(struct map_info *map,
  104. + const map_word datum,
  105. + unsigned long ofs)
  106. +{
  107. + gemini_flash_enable_pins();
  108. + inline_map_write(map, datum, ofs);
  109. + gemini_flash_disable_pins();
  110. +}
  111. +
  112. +static void __xipram gemini_flash_map_copy_from(struct map_info *map,
  113. + void *to, unsigned long from,
  114. + ssize_t len)
  115. +{
  116. + gemini_flash_enable_pins();
  117. + inline_map_copy_from(map, to, from, len);
  118. + gemini_flash_disable_pins();
  119. +}
  120. +
  121. +static void __xipram gemini_flash_map_copy_to(struct map_info *map,
  122. + unsigned long to,
  123. + const void *from, ssize_t len)
  124. +{
  125. + gemini_flash_enable_pins();
  126. + inline_map_copy_to(map, to, from, len);
  127. + gemini_flash_disable_pins();
  128. +}
  129. +
  130. int of_flash_probe_gemini(struct platform_device *pdev,
  131. struct device_node *np,
  132. struct map_info *map)
  133. @@ -62,6 +135,11 @@ int of_flash_probe_gemini(struct platfor
  134. if (!of_device_is_compatible(np, "cortina,gemini-flash"))
  135. return 0;
  136. + gf = devm_kzalloc(dev, sizeof(*gf), GFP_KERNEL);
  137. + if (!gf)
  138. + return -ENOMEM;
  139. + gf->dev = dev;
  140. +
  141. rmap = syscon_regmap_lookup_by_phandle(np, "syscon");
  142. if (IS_ERR(rmap)) {
  143. dev_err(dev, "no syscon\n");
  144. @@ -96,7 +174,32 @@ int of_flash_probe_gemini(struct platfor
  145. map->bankwidth * 8);
  146. }
  147. - dev_info(&pdev->dev, "initialized Gemini-specific physmap control\n");
  148. + gf->p = devm_pinctrl_get(dev);
  149. + if (IS_ERR(gf->p)) {
  150. + dev_err(dev, "no pinctrl handle\n");
  151. + ret = PTR_ERR(gf->p);
  152. + return ret;
  153. + }
  154. +
  155. + gf->enabled_state = pinctrl_lookup_state(gf->p, "enabled");
  156. + if (IS_ERR(gf->enabled_state))
  157. + dev_err(dev, "no enabled pin control state\n");
  158. +
  159. + gf->disabled_state = pinctrl_lookup_state(gf->p, "disabled");
  160. + if (IS_ERR(gf->enabled_state)) {
  161. + dev_err(dev, "no disabled pin control state\n");
  162. + } else {
  163. + ret = pinctrl_select_state(gf->p, gf->disabled_state);
  164. + if (ret)
  165. + dev_err(gf->dev, "failed to disable pins\n");
  166. + }
  167. +
  168. + map->read = gemini_flash_map_read;
  169. + map->write = gemini_flash_map_write;
  170. + map->copy_from = gemini_flash_map_copy_from;
  171. + map->copy_to = gemini_flash_map_copy_to;
  172. +
  173. + dev_info(dev, "initialized Gemini-specific physmap control\n");
  174. return 0;
  175. }