pinctrl-luton.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. /*
  3. * Microsemi SoCs pinctrl driver
  4. *
  5. * Author: <gregory.clement@bootlin.com>
  6. * License: Dual MIT/GPL
  7. * Copyright (c) 2018 Microsemi Corporation
  8. */
  9. #include <common.h>
  10. #include <config.h>
  11. #include <dm.h>
  12. #include <dm/device-internal.h>
  13. #include <dm/lists.h>
  14. #include <dm/pinctrl.h>
  15. #include <dm/root.h>
  16. #include <errno.h>
  17. #include <fdtdec.h>
  18. #include <linux/io.h>
  19. #include <asm/gpio.h>
  20. #include <asm/system.h>
  21. #include "mscc-common.h"
  22. enum {
  23. FUNC_NONE,
  24. FUNC_GPIO,
  25. FUNC_SIO,
  26. FUNC_TACHO,
  27. FUNC_TWI,
  28. FUNC_PHY_LED,
  29. FUNC_EXT_IRQ,
  30. FUNC_SFP,
  31. FUNC_SI,
  32. FUNC_PWM,
  33. FUNC_UART,
  34. FUNC_MAX
  35. };
  36. static char * const luton_function_names[] = {
  37. [FUNC_NONE] = "none",
  38. [FUNC_GPIO] = "gpio",
  39. [FUNC_SIO] = "sio",
  40. [FUNC_TACHO] = "tacho",
  41. [FUNC_TWI] = "twi",
  42. [FUNC_PHY_LED] = "phy_led",
  43. [FUNC_EXT_IRQ] = "ext_irq",
  44. [FUNC_SFP] = "sfp",
  45. [FUNC_SI] = "si",
  46. [FUNC_PWM] = "pwm",
  47. [FUNC_UART] = "uart",
  48. };
  49. MSCC_P(0, SIO, NONE, NONE);
  50. MSCC_P(1, SIO, NONE, NONE);
  51. MSCC_P(2, SIO, NONE, NONE);
  52. MSCC_P(3, SIO, NONE, NONE);
  53. MSCC_P(4, TACHO, NONE, NONE);
  54. MSCC_P(5, TWI, PHY_LED, NONE);
  55. MSCC_P(6, TWI, PHY_LED, NONE);
  56. MSCC_P(7, NONE, PHY_LED, NONE);
  57. MSCC_P(8, EXT_IRQ, PHY_LED, NONE);
  58. MSCC_P(9, EXT_IRQ, PHY_LED, NONE);
  59. MSCC_P(10, SFP, PHY_LED, NONE);
  60. MSCC_P(11, SFP, PHY_LED, NONE);
  61. MSCC_P(12, SFP, PHY_LED, NONE);
  62. MSCC_P(13, SFP, PHY_LED, NONE);
  63. MSCC_P(14, SI, PHY_LED, NONE);
  64. MSCC_P(15, SI, PHY_LED, NONE);
  65. MSCC_P(16, SI, PHY_LED, NONE);
  66. MSCC_P(17, SFP, PHY_LED, NONE);
  67. MSCC_P(18, SFP, PHY_LED, NONE);
  68. MSCC_P(19, SFP, PHY_LED, NONE);
  69. MSCC_P(20, SFP, PHY_LED, NONE);
  70. MSCC_P(21, SFP, PHY_LED, NONE);
  71. MSCC_P(22, SFP, PHY_LED, NONE);
  72. MSCC_P(23, SFP, PHY_LED, NONE);
  73. MSCC_P(24, SFP, PHY_LED, NONE);
  74. MSCC_P(25, SFP, PHY_LED, NONE);
  75. MSCC_P(26, SFP, PHY_LED, NONE);
  76. MSCC_P(27, SFP, PHY_LED, NONE);
  77. MSCC_P(28, SFP, PHY_LED, NONE);
  78. MSCC_P(29, PWM, NONE, NONE);
  79. MSCC_P(30, UART, NONE, NONE);
  80. MSCC_P(31, UART, NONE, NONE);
  81. #define LUTON_PIN(n) { \
  82. .name = "GPIO_"#n, \
  83. .drv_data = &mscc_pin_##n \
  84. }
  85. static const struct mscc_pin_data luton_pins[] = {
  86. LUTON_PIN(0),
  87. LUTON_PIN(1),
  88. LUTON_PIN(2),
  89. LUTON_PIN(3),
  90. LUTON_PIN(4),
  91. LUTON_PIN(5),
  92. LUTON_PIN(6),
  93. LUTON_PIN(7),
  94. LUTON_PIN(8),
  95. LUTON_PIN(9),
  96. LUTON_PIN(10),
  97. LUTON_PIN(11),
  98. LUTON_PIN(12),
  99. LUTON_PIN(13),
  100. LUTON_PIN(14),
  101. LUTON_PIN(15),
  102. LUTON_PIN(16),
  103. LUTON_PIN(17),
  104. LUTON_PIN(18),
  105. LUTON_PIN(19),
  106. LUTON_PIN(20),
  107. LUTON_PIN(21),
  108. LUTON_PIN(22),
  109. LUTON_PIN(23),
  110. LUTON_PIN(24),
  111. LUTON_PIN(25),
  112. LUTON_PIN(26),
  113. LUTON_PIN(27),
  114. LUTON_PIN(28),
  115. LUTON_PIN(29),
  116. LUTON_PIN(30),
  117. LUTON_PIN(31),
  118. };
  119. static const unsigned long luton_gpios[] = {
  120. [MSCC_GPIO_OUT_SET] = 0x00,
  121. [MSCC_GPIO_OUT_CLR] = 0x04,
  122. [MSCC_GPIO_OUT] = 0x08,
  123. [MSCC_GPIO_IN] = 0x0c,
  124. [MSCC_GPIO_OE] = 0x10,
  125. [MSCC_GPIO_INTR] = 0x14,
  126. [MSCC_GPIO_INTR_ENA] = 0x18,
  127. [MSCC_GPIO_INTR_IDENT] = 0x1c,
  128. [MSCC_GPIO_ALT0] = 0x20,
  129. [MSCC_GPIO_ALT1] = 0x24,
  130. };
  131. static int luton_gpio_probe(struct udevice *dev)
  132. {
  133. struct gpio_dev_priv *uc_priv;
  134. uc_priv = dev_get_uclass_priv(dev);
  135. uc_priv->bank_name = "luton-gpio";
  136. uc_priv->gpio_count = ARRAY_SIZE(luton_pins);
  137. return 0;
  138. }
  139. static struct driver luton_gpio_driver = {
  140. .name = "luton-gpio",
  141. .id = UCLASS_GPIO,
  142. .probe = luton_gpio_probe,
  143. .ops = &mscc_gpio_ops,
  144. };
  145. int luton_pinctrl_probe(struct udevice *dev)
  146. {
  147. int ret;
  148. ret = mscc_pinctrl_probe(dev, FUNC_MAX, luton_pins,
  149. ARRAY_SIZE(luton_pins), luton_function_names,
  150. luton_gpios);
  151. if (ret)
  152. return ret;
  153. ret = device_bind(dev, &luton_gpio_driver, "luton-gpio", NULL,
  154. dev_of_offset(dev), NULL);
  155. return 0;
  156. }
  157. static const struct udevice_id luton_pinctrl_of_match[] = {
  158. {.compatible = "mscc,luton-pinctrl"},
  159. {},
  160. };
  161. U_BOOT_DRIVER(luton_pinctrl) = {
  162. .name = "luton-pinctrl",
  163. .id = UCLASS_PINCTRL,
  164. .of_match = of_match_ptr(luton_pinctrl_of_match),
  165. .probe = luton_pinctrl_probe,
  166. .priv_auto_alloc_size = sizeof(struct mscc_pinctrl),
  167. .ops = &mscc_pinctrl_ops,
  168. };