pinctrl-orion.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Marvell Orion pinctrl driver based on mvebu pinctrl core
  4. *
  5. * Author: Thomas Petazzoni <[email protected]>
  6. *
  7. * The first 16 MPP pins on Orion are easy to handle: they are
  8. * configured through 2 consecutive registers, located at the base
  9. * address of the MPP device.
  10. *
  11. * However the last 4 MPP pins are handled by a register at offset
  12. * 0x50 from the base address, so it is not consecutive with the first
  13. * two registers.
  14. */
  15. #include <linux/err.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/clk.h>
  20. #include <linux/of.h>
  21. #include <linux/of_device.h>
  22. #include <linux/pinctrl/pinctrl.h>
  23. #include "pinctrl-mvebu.h"
  24. static void __iomem *mpp_base;
  25. static void __iomem *high_mpp_base;
  26. static int orion_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data,
  27. unsigned pid, unsigned long *config)
  28. {
  29. unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
  30. if (pid < 16) {
  31. unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
  32. *config = (readl(mpp_base + off) >> shift) & MVEBU_MPP_MASK;
  33. }
  34. else {
  35. *config = (readl(high_mpp_base) >> shift) & MVEBU_MPP_MASK;
  36. }
  37. return 0;
  38. }
  39. static int orion_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data,
  40. unsigned pid, unsigned long config)
  41. {
  42. unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
  43. if (pid < 16) {
  44. unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
  45. u32 reg = readl(mpp_base + off) & ~(MVEBU_MPP_MASK << shift);
  46. writel(reg | (config << shift), mpp_base + off);
  47. }
  48. else {
  49. u32 reg = readl(high_mpp_base) & ~(MVEBU_MPP_MASK << shift);
  50. writel(reg | (config << shift), high_mpp_base);
  51. }
  52. return 0;
  53. }
  54. #define V(f5181, f5182, f5281) \
  55. ((f5181 << 0) | (f5182 << 1) | (f5281 << 2))
  56. enum orion_variant {
  57. V_5181 = V(1, 0, 0),
  58. V_5182 = V(0, 1, 0),
  59. V_5281 = V(0, 0, 1),
  60. V_ALL = V(1, 1, 1),
  61. };
  62. static struct mvebu_mpp_mode orion_mpp_modes[] = {
  63. MPP_MODE(0,
  64. MPP_VAR_FUNCTION(0x0, "pcie", "rstout", V_ALL),
  65. MPP_VAR_FUNCTION(0x2, "pci", "req2", V_ALL),
  66. MPP_VAR_FUNCTION(0x3, "gpio", NULL, V_ALL)),
  67. MPP_MODE(1,
  68. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  69. MPP_VAR_FUNCTION(0x2, "pci", "gnt2", V_ALL)),
  70. MPP_MODE(2,
  71. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  72. MPP_VAR_FUNCTION(0x2, "pci", "req3", V_ALL),
  73. MPP_VAR_FUNCTION(0x3, "pci-1", "pme", V_ALL)),
  74. MPP_MODE(3,
  75. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  76. MPP_VAR_FUNCTION(0x2, "pci", "gnt3", V_ALL)),
  77. MPP_MODE(4,
  78. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  79. MPP_VAR_FUNCTION(0x2, "pci", "req4", V_ALL),
  80. MPP_VAR_FUNCTION(0x4, "bootnand", "re", V_5182 | V_5281),
  81. MPP_VAR_FUNCTION(0x5, "sata0", "prsnt", V_5182)),
  82. MPP_MODE(5,
  83. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  84. MPP_VAR_FUNCTION(0x2, "pci", "gnt4", V_ALL),
  85. MPP_VAR_FUNCTION(0x4, "bootnand", "we", V_5182 | V_5281),
  86. MPP_VAR_FUNCTION(0x5, "sata1", "prsnt", V_5182)),
  87. MPP_MODE(6,
  88. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  89. MPP_VAR_FUNCTION(0x2, "pci", "req5", V_ALL),
  90. MPP_VAR_FUNCTION(0x4, "nand", "re0", V_5182 | V_5281),
  91. MPP_VAR_FUNCTION(0x5, "pci-1", "clk", V_5181),
  92. MPP_VAR_FUNCTION(0x5, "sata0", "act", V_5182)),
  93. MPP_MODE(7,
  94. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  95. MPP_VAR_FUNCTION(0x2, "pci", "gnt5", V_ALL),
  96. MPP_VAR_FUNCTION(0x4, "nand", "we0", V_5182 | V_5281),
  97. MPP_VAR_FUNCTION(0x5, "pci-1", "clk", V_5181),
  98. MPP_VAR_FUNCTION(0x5, "sata1", "act", V_5182)),
  99. MPP_MODE(8,
  100. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  101. MPP_VAR_FUNCTION(0x1, "ge", "col", V_ALL)),
  102. MPP_MODE(9,
  103. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  104. MPP_VAR_FUNCTION(0x1, "ge", "rxerr", V_ALL)),
  105. MPP_MODE(10,
  106. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  107. MPP_VAR_FUNCTION(0x1, "ge", "crs", V_ALL)),
  108. MPP_MODE(11,
  109. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  110. MPP_VAR_FUNCTION(0x1, "ge", "txerr", V_ALL)),
  111. MPP_MODE(12,
  112. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  113. MPP_VAR_FUNCTION(0x1, "ge", "txd4", V_ALL),
  114. MPP_VAR_FUNCTION(0x4, "nand", "re1", V_5182 | V_5281),
  115. MPP_VAR_FUNCTION(0x5, "sata0", "ledprsnt", V_5182)),
  116. MPP_MODE(13,
  117. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  118. MPP_VAR_FUNCTION(0x1, "ge", "txd5", V_ALL),
  119. MPP_VAR_FUNCTION(0x4, "nand", "we1", V_5182 | V_5281),
  120. MPP_VAR_FUNCTION(0x5, "sata1", "ledprsnt", V_5182)),
  121. MPP_MODE(14,
  122. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  123. MPP_VAR_FUNCTION(0x1, "ge", "txd6", V_ALL),
  124. MPP_VAR_FUNCTION(0x4, "nand", "re2", V_5182 | V_5281),
  125. MPP_VAR_FUNCTION(0x5, "sata0", "ledact", V_5182)),
  126. MPP_MODE(15,
  127. MPP_VAR_FUNCTION(0x0, "gpio", NULL, V_ALL),
  128. MPP_VAR_FUNCTION(0x1, "ge", "txd7", V_ALL),
  129. MPP_VAR_FUNCTION(0x4, "nand", "we2", V_5182 | V_5281),
  130. MPP_VAR_FUNCTION(0x5, "sata1", "ledact", V_5182)),
  131. MPP_MODE(16,
  132. MPP_VAR_FUNCTION(0x0, "uart1", "rxd", V_5182 | V_5281),
  133. MPP_VAR_FUNCTION(0x1, "ge", "rxd4", V_ALL),
  134. MPP_VAR_FUNCTION(0x5, "gpio", NULL, V_5182)),
  135. MPP_MODE(17,
  136. MPP_VAR_FUNCTION(0x0, "uart1", "txd", V_5182 | V_5281),
  137. MPP_VAR_FUNCTION(0x1, "ge", "rxd5", V_ALL),
  138. MPP_VAR_FUNCTION(0x5, "gpio", NULL, V_5182)),
  139. MPP_MODE(18,
  140. MPP_VAR_FUNCTION(0x0, "uart1", "cts", V_5182 | V_5281),
  141. MPP_VAR_FUNCTION(0x1, "ge", "rxd6", V_ALL),
  142. MPP_VAR_FUNCTION(0x5, "gpio", NULL, V_5182)),
  143. MPP_MODE(19,
  144. MPP_VAR_FUNCTION(0x0, "uart1", "rts", V_5182 | V_5281),
  145. MPP_VAR_FUNCTION(0x1, "ge", "rxd7", V_ALL),
  146. MPP_VAR_FUNCTION(0x5, "gpio", NULL, V_5182)),
  147. };
  148. static const struct mvebu_mpp_ctrl orion_mpp_controls[] = {
  149. MPP_FUNC_CTRL(0, 19, NULL, orion_mpp_ctrl),
  150. };
  151. static struct pinctrl_gpio_range mv88f5181_gpio_ranges[] = {
  152. MPP_GPIO_RANGE(0, 0, 0, 16),
  153. };
  154. static struct pinctrl_gpio_range mv88f5182_gpio_ranges[] = {
  155. MPP_GPIO_RANGE(0, 0, 0, 19),
  156. };
  157. static struct pinctrl_gpio_range mv88f5281_gpio_ranges[] = {
  158. MPP_GPIO_RANGE(0, 0, 0, 16),
  159. };
  160. static struct mvebu_pinctrl_soc_info mv88f5181_info = {
  161. .variant = V_5181,
  162. .controls = orion_mpp_controls,
  163. .ncontrols = ARRAY_SIZE(orion_mpp_controls),
  164. .modes = orion_mpp_modes,
  165. .nmodes = ARRAY_SIZE(orion_mpp_modes),
  166. .gpioranges = mv88f5181_gpio_ranges,
  167. .ngpioranges = ARRAY_SIZE(mv88f5181_gpio_ranges),
  168. };
  169. static struct mvebu_pinctrl_soc_info mv88f5182_info = {
  170. .variant = V_5182,
  171. .controls = orion_mpp_controls,
  172. .ncontrols = ARRAY_SIZE(orion_mpp_controls),
  173. .modes = orion_mpp_modes,
  174. .nmodes = ARRAY_SIZE(orion_mpp_modes),
  175. .gpioranges = mv88f5182_gpio_ranges,
  176. .ngpioranges = ARRAY_SIZE(mv88f5182_gpio_ranges),
  177. };
  178. static struct mvebu_pinctrl_soc_info mv88f5281_info = {
  179. .variant = V_5281,
  180. .controls = orion_mpp_controls,
  181. .ncontrols = ARRAY_SIZE(orion_mpp_controls),
  182. .modes = orion_mpp_modes,
  183. .nmodes = ARRAY_SIZE(orion_mpp_modes),
  184. .gpioranges = mv88f5281_gpio_ranges,
  185. .ngpioranges = ARRAY_SIZE(mv88f5281_gpio_ranges),
  186. };
  187. /*
  188. * There are multiple variants of the Orion SoCs, but in terms of pin
  189. * muxing, they are identical.
  190. */
  191. static const struct of_device_id orion_pinctrl_of_match[] = {
  192. { .compatible = "marvell,88f5181-pinctrl", .data = &mv88f5181_info },
  193. { .compatible = "marvell,88f5181l-pinctrl", .data = &mv88f5181_info },
  194. { .compatible = "marvell,88f5182-pinctrl", .data = &mv88f5182_info },
  195. { .compatible = "marvell,88f5281-pinctrl", .data = &mv88f5281_info },
  196. { }
  197. };
  198. static int orion_pinctrl_probe(struct platform_device *pdev)
  199. {
  200. const struct of_device_id *match =
  201. of_match_device(orion_pinctrl_of_match, &pdev->dev);
  202. pdev->dev.platform_data = (void*)match->data;
  203. mpp_base = devm_platform_ioremap_resource(pdev, 0);
  204. if (IS_ERR(mpp_base))
  205. return PTR_ERR(mpp_base);
  206. high_mpp_base = devm_platform_ioremap_resource(pdev, 1);
  207. if (IS_ERR(high_mpp_base))
  208. return PTR_ERR(high_mpp_base);
  209. return mvebu_pinctrl_probe(pdev);
  210. }
  211. static struct platform_driver orion_pinctrl_driver = {
  212. .driver = {
  213. .name = "orion-pinctrl",
  214. .of_match_table = of_match_ptr(orion_pinctrl_of_match),
  215. },
  216. .probe = orion_pinctrl_probe,
  217. };
  218. builtin_platform_driver(orion_pinctrl_driver);