Horatiu Vultur | 2f6462a | 2019-01-17 15:33:26 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR MIT) |
| 2 | /* |
| 3 | * Microsemi SoCs pinctrl driver |
| 4 | * |
| 5 | * Author: <horatiu.vultur@microchip.com> |
| 6 | * Copyright (c) 2019 Microsemi Corporation |
| 7 | */ |
| 8 | |
Horatiu Vultur | 2f6462a | 2019-01-17 15:33:26 +0100 | [diff] [blame] | 9 | #include <config.h> |
| 10 | #include <dm.h> |
| 11 | #include <dm/device-internal.h> |
| 12 | #include <dm/lists.h> |
| 13 | #include <dm/pinctrl.h> |
| 14 | #include <dm/root.h> |
| 15 | #include <errno.h> |
| 16 | #include <fdtdec.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <asm/gpio.h> |
| 19 | #include <asm/system.h> |
| 20 | #include "mscc-common.h" |
| 21 | |
| 22 | enum { |
| 23 | FUNC_NONE, |
| 24 | FUNC_GPIO, |
| 25 | FUNC_IRQ0_IN, |
| 26 | FUNC_IRQ0_OUT, |
| 27 | FUNC_IRQ1_IN, |
| 28 | FUNC_IRQ1_OUT, |
| 29 | FUNC_MIIM1, |
| 30 | FUNC_MIIM2, |
| 31 | FUNC_PCI_WAKE, |
| 32 | FUNC_PTP0, |
| 33 | FUNC_PTP1, |
| 34 | FUNC_PTP2, |
| 35 | FUNC_PTP3, |
| 36 | FUNC_PWM, |
| 37 | FUNC_RCVRD_CLK0, |
| 38 | FUNC_RCVRD_CLK1, |
| 39 | FUNC_RCVRD_CLK2, |
| 40 | FUNC_RCVRD_CLK3, |
| 41 | FUNC_REF_CLK0, |
| 42 | FUNC_REF_CLK1, |
| 43 | FUNC_REF_CLK2, |
| 44 | FUNC_REF_CLK3, |
| 45 | FUNC_SFP0, |
| 46 | FUNC_SFP1, |
| 47 | FUNC_SFP2, |
| 48 | FUNC_SFP3, |
| 49 | FUNC_SFP4, |
| 50 | FUNC_SFP5, |
| 51 | FUNC_SFP6, |
| 52 | FUNC_SFP7, |
| 53 | FUNC_SFP8, |
| 54 | FUNC_SFP9, |
| 55 | FUNC_SFP10, |
| 56 | FUNC_SFP11, |
| 57 | FUNC_SFP12, |
| 58 | FUNC_SFP13, |
| 59 | FUNC_SFP14, |
| 60 | FUNC_SFP15, |
| 61 | FUNC_SIO, |
| 62 | FUNC_SPI, |
| 63 | FUNC_TACHO, |
| 64 | FUNC_TWI, |
| 65 | FUNC_TWI2, |
| 66 | FUNC_TWI_SCL_M, |
| 67 | FUNC_UART, |
| 68 | FUNC_UART2, |
| 69 | FUNC_MAX |
| 70 | }; |
| 71 | |
| 72 | static char * const servalt_function_names[] = { |
| 73 | [FUNC_NONE] = "none", |
| 74 | [FUNC_GPIO] = "gpio", |
| 75 | [FUNC_IRQ0_IN] = "irq0_in", |
| 76 | [FUNC_IRQ0_OUT] = "irq0_out", |
| 77 | [FUNC_IRQ1_IN] = "irq1_in", |
| 78 | [FUNC_IRQ1_OUT] = "irq1_out", |
| 79 | [FUNC_MIIM1] = "miim1", |
| 80 | [FUNC_MIIM2] = "miim2", |
| 81 | [FUNC_PCI_WAKE] = "pci_wake", |
| 82 | [FUNC_PTP0] = "ptp0", |
| 83 | [FUNC_PTP1] = "ptp1", |
| 84 | [FUNC_PTP2] = "ptp2", |
| 85 | [FUNC_PTP3] = "ptp3", |
| 86 | [FUNC_PWM] = "pwm", |
| 87 | [FUNC_RCVRD_CLK0] = "rcvrd_clk0", |
| 88 | [FUNC_RCVRD_CLK1] = "rcvrd_clk1", |
| 89 | [FUNC_RCVRD_CLK2] = "rcvrd_clk2", |
| 90 | [FUNC_RCVRD_CLK3] = "rcvrd_clk3", |
| 91 | [FUNC_REF_CLK0] = "ref_clk0", |
| 92 | [FUNC_REF_CLK1] = "ref_clk1", |
| 93 | [FUNC_REF_CLK2] = "ref_clk2", |
| 94 | [FUNC_REF_CLK3] = "ref_clk3", |
| 95 | [FUNC_SFP0] = "sfp0", |
| 96 | [FUNC_SFP1] = "sfp1", |
| 97 | [FUNC_SFP2] = "sfp2", |
| 98 | [FUNC_SFP3] = "sfp3", |
| 99 | [FUNC_SFP4] = "sfp4", |
| 100 | [FUNC_SFP5] = "sfp5", |
| 101 | [FUNC_SFP6] = "sfp6", |
| 102 | [FUNC_SFP7] = "sfp7", |
| 103 | [FUNC_SFP8] = "sfp8", |
| 104 | [FUNC_SFP9] = "sfp9", |
| 105 | [FUNC_SFP10] = "sfp10", |
| 106 | [FUNC_SFP11] = "sfp11", |
| 107 | [FUNC_SFP12] = "sfp12", |
| 108 | [FUNC_SFP13] = "sfp13", |
| 109 | [FUNC_SFP14] = "sfp14", |
| 110 | [FUNC_SFP15] = "sfp15", |
| 111 | [FUNC_SIO] = "sio", |
| 112 | [FUNC_SPI] = "spi", |
| 113 | [FUNC_TACHO] = "tacho", |
| 114 | [FUNC_TWI] = "twi", |
| 115 | [FUNC_TWI2] = "twi2", |
| 116 | [FUNC_TWI_SCL_M] = "twi_scl_m", |
| 117 | [FUNC_UART] = "uart", |
| 118 | [FUNC_UART2] = "uart2", |
| 119 | }; |
| 120 | |
| 121 | MSCC_P(0, SIO, NONE, NONE); |
| 122 | MSCC_P(1, SIO, NONE, NONE); |
| 123 | MSCC_P(2, SIO, NONE, NONE); |
| 124 | MSCC_P(3, SIO, NONE, NONE); |
| 125 | MSCC_P(4, IRQ0_IN, IRQ0_OUT, TWI_SCL_M); |
| 126 | MSCC_P(5, IRQ1_IN, IRQ1_OUT, TWI_SCL_M); |
| 127 | MSCC_P(6, UART, NONE, NONE); |
| 128 | MSCC_P(7, UART, NONE, NONE); |
| 129 | MSCC_P(8, SPI, SFP0, TWI_SCL_M); |
| 130 | MSCC_P(9, PCI_WAKE, SFP1, SPI); |
| 131 | MSCC_P(10, PTP0, SFP2, TWI_SCL_M); |
| 132 | MSCC_P(11, PTP1, SFP3, TWI_SCL_M); |
| 133 | MSCC_P(12, REF_CLK0, SFP4, TWI_SCL_M); |
| 134 | MSCC_P(13, REF_CLK1, SFP5, TWI_SCL_M); |
| 135 | MSCC_P(14, REF_CLK2, IRQ0_OUT, SPI); |
| 136 | MSCC_P(15, REF_CLK3, IRQ1_OUT, SPI); |
| 137 | MSCC_P(16, TACHO, SFP6, SPI); |
| 138 | MSCC_P(17, PWM, NONE, TWI_SCL_M); |
| 139 | MSCC_P(18, PTP2, SFP7, SPI); |
| 140 | MSCC_P(19, PTP3, SFP8, SPI); |
| 141 | MSCC_P(20, UART2, SFP9, SPI); |
| 142 | MSCC_P(21, UART2, NONE, NONE); |
| 143 | MSCC_P(22, MIIM1, SFP10, TWI2); |
| 144 | MSCC_P(23, MIIM1, SFP11, TWI2); |
| 145 | MSCC_P(24, TWI, NONE, NONE); |
| 146 | MSCC_P(25, TWI, SFP12, TWI_SCL_M); |
| 147 | MSCC_P(26, TWI_SCL_M, SFP13, SPI); |
| 148 | MSCC_P(27, TWI_SCL_M, SFP14, SPI); |
| 149 | MSCC_P(28, TWI_SCL_M, SFP15, SPI); |
| 150 | MSCC_P(29, TWI_SCL_M, NONE, NONE); |
| 151 | MSCC_P(30, TWI_SCL_M, NONE, NONE); |
| 152 | MSCC_P(31, TWI_SCL_M, NONE, NONE); |
| 153 | MSCC_P(32, TWI_SCL_M, NONE, NONE); |
| 154 | MSCC_P(33, RCVRD_CLK0, NONE, NONE); |
| 155 | MSCC_P(34, RCVRD_CLK1, NONE, NONE); |
| 156 | MSCC_P(35, RCVRD_CLK2, NONE, NONE); |
| 157 | MSCC_P(36, RCVRD_CLK3, NONE, NONE); |
| 158 | |
| 159 | #define SERVALT_PIN(n) { \ |
| 160 | .name = "GPIO_"#n, \ |
| 161 | .drv_data = &mscc_pin_##n \ |
| 162 | } |
| 163 | |
| 164 | static const struct mscc_pin_data servalt_pins[] = { |
| 165 | SERVALT_PIN(0), |
| 166 | SERVALT_PIN(1), |
| 167 | SERVALT_PIN(2), |
| 168 | SERVALT_PIN(3), |
| 169 | SERVALT_PIN(4), |
| 170 | SERVALT_PIN(5), |
| 171 | SERVALT_PIN(6), |
| 172 | SERVALT_PIN(7), |
| 173 | SERVALT_PIN(8), |
| 174 | SERVALT_PIN(9), |
| 175 | SERVALT_PIN(10), |
| 176 | SERVALT_PIN(11), |
| 177 | SERVALT_PIN(12), |
| 178 | SERVALT_PIN(13), |
| 179 | SERVALT_PIN(14), |
| 180 | SERVALT_PIN(15), |
| 181 | SERVALT_PIN(16), |
| 182 | SERVALT_PIN(17), |
| 183 | SERVALT_PIN(18), |
| 184 | SERVALT_PIN(19), |
| 185 | SERVALT_PIN(20), |
| 186 | SERVALT_PIN(21), |
| 187 | SERVALT_PIN(22), |
| 188 | SERVALT_PIN(23), |
| 189 | SERVALT_PIN(24), |
| 190 | SERVALT_PIN(25), |
| 191 | SERVALT_PIN(26), |
| 192 | SERVALT_PIN(27), |
| 193 | SERVALT_PIN(28), |
| 194 | SERVALT_PIN(29), |
| 195 | SERVALT_PIN(30), |
| 196 | SERVALT_PIN(31), |
| 197 | SERVALT_PIN(32), |
| 198 | SERVALT_PIN(33), |
| 199 | SERVALT_PIN(34), |
| 200 | SERVALT_PIN(35), |
| 201 | SERVALT_PIN(36), |
| 202 | }; |
| 203 | |
| 204 | static const unsigned long servalt_gpios[] = { |
| 205 | [MSCC_GPIO_OUT_SET] = 0x00, |
| 206 | [MSCC_GPIO_OUT_CLR] = 0x08, |
| 207 | [MSCC_GPIO_OUT] = 0x10, |
| 208 | [MSCC_GPIO_IN] = 0x18, |
| 209 | [MSCC_GPIO_OE] = 0x20, |
| 210 | [MSCC_GPIO_INTR] = 0x28, |
| 211 | [MSCC_GPIO_INTR_ENA] = 0x30, |
| 212 | [MSCC_GPIO_INTR_IDENT] = 0x38, |
| 213 | [MSCC_GPIO_ALT0] = 0x40, |
| 214 | [MSCC_GPIO_ALT1] = 0x48, |
| 215 | }; |
| 216 | |
| 217 | static int servalt_gpio_probe(struct udevice *dev) |
| 218 | { |
| 219 | struct gpio_dev_priv *uc_priv; |
| 220 | |
| 221 | uc_priv = dev_get_uclass_priv(dev); |
| 222 | uc_priv->bank_name = "servalt-gpio"; |
| 223 | uc_priv->gpio_count = ARRAY_SIZE(servalt_pins); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static struct driver servalt_gpio_driver = { |
| 229 | .name = "servalt-gpio", |
| 230 | .id = UCLASS_GPIO, |
| 231 | .probe = servalt_gpio_probe, |
| 232 | .ops = &mscc_gpio_ops, |
| 233 | }; |
| 234 | |
| 235 | static int servalt_pinctrl_probe(struct udevice *dev) |
| 236 | { |
| 237 | int ret; |
| 238 | |
| 239 | ret = mscc_pinctrl_probe(dev, FUNC_MAX, servalt_pins, |
| 240 | ARRAY_SIZE(servalt_pins), |
| 241 | servalt_function_names, |
| 242 | servalt_gpios); |
| 243 | |
| 244 | if (ret) |
| 245 | return ret; |
| 246 | |
Simon Glass | 6996c66 | 2020-11-28 17:50:03 -0700 | [diff] [blame] | 247 | ret = device_bind(dev, &servalt_gpio_driver, "servalt-gpio", NULL, |
| 248 | dev_ofnode(dev), NULL); |
Horatiu Vultur | 2f6462a | 2019-01-17 15:33:26 +0100 | [diff] [blame] | 249 | |
| 250 | if (ret) |
| 251 | return ret; |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static const struct udevice_id servalt_pinctrl_of_match[] = { |
| 257 | { .compatible = "mscc,servalt-pinctrl" }, |
| 258 | {}, |
| 259 | }; |
| 260 | |
| 261 | U_BOOT_DRIVER(servalt_pinctrl) = { |
| 262 | .name = "servalt-pinctrl", |
| 263 | .id = UCLASS_PINCTRL, |
| 264 | .of_match = of_match_ptr(servalt_pinctrl_of_match), |
| 265 | .probe = servalt_pinctrl_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 266 | .priv_auto = sizeof(struct mscc_pinctrl), |
Horatiu Vultur | 2f6462a | 2019-01-17 15:33:26 +0100 | [diff] [blame] | 267 | .ops = &mscc_pinctrl_ops, |
| 268 | }; |