pinctrl-orion.c 8.7 KB

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