blob: 2081cd6750c86feea9115c04e15ec6b667b78fe4 [file] [log] [blame]
Horatiu Vultur50375022019-01-23 16:39:41 +01001// 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 Vultur50375022019-01-23 16:39:41 +01009#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
22enum {
23 FUNC_NONE,
24 FUNC_GPIO,
25 FUNC_IRQ0,
26 FUNC_IRQ1,
27 FUNC_MIIM1,
28 FUNC_PCI_WAKE,
29 FUNC_PTP0,
30 FUNC_PTP1,
31 FUNC_PTP2,
32 FUNC_PTP3,
33 FUNC_PWM,
34 FUNC_RECO_CLK0,
35 FUNC_RECO_CLK1,
36 FUNC_SFP0,
37 FUNC_SFP1,
38 FUNC_SFP2,
39 FUNC_SFP3,
40 FUNC_SFP4,
41 FUNC_SFP5,
42 FUNC_SFP6,
43 FUNC_SFP7,
44 FUNC_SFP8,
45 FUNC_SFP9,
46 FUNC_SFP10,
47 FUNC_SIO,
48 FUNC_SI,
49 FUNC_TACHO,
50 FUNC_TWI,
51 FUNC_TWI_SCL_M,
52 FUNC_UART,
53 FUNC_UART2,
54 FUNC_MD,
55 FUNC_PTP1588,
56 FUNC_MAX
57};
58
59static char * const serval_function_names[] = {
60 [FUNC_NONE] = "none",
61 [FUNC_GPIO] = "gpio",
62 [FUNC_IRQ0] = "irq0",
63 [FUNC_IRQ1] = "irq1",
64 [FUNC_MIIM1] = "miim1",
65 [FUNC_PCI_WAKE] = "pci_wake",
66 [FUNC_PTP0] = "ptp0",
67 [FUNC_PTP1] = "ptp1",
68 [FUNC_PTP2] = "ptp2",
69 [FUNC_PTP3] = "ptp3",
70 [FUNC_PWM] = "pwm",
71 [FUNC_RECO_CLK0] = "reco_clk0",
72 [FUNC_RECO_CLK1] = "reco_clk1",
73 [FUNC_SFP0] = "sfp0",
74 [FUNC_SFP1] = "sfp1",
75 [FUNC_SFP2] = "sfp2",
76 [FUNC_SFP3] = "sfp3",
77 [FUNC_SFP4] = "sfp4",
78 [FUNC_SFP5] = "sfp5",
79 [FUNC_SFP6] = "sfp6",
80 [FUNC_SFP7] = "sfp7",
81 [FUNC_SFP8] = "sfp8",
82 [FUNC_SFP9] = "sfp9",
83 [FUNC_SFP10] = "sfp10",
84 [FUNC_SIO] = "sio",
85 [FUNC_SI] = "si",
86 [FUNC_TACHO] = "tacho",
87 [FUNC_TWI] = "twi",
88 [FUNC_TWI_SCL_M] = "twi_scl_m",
89 [FUNC_UART] = "uart",
90 [FUNC_UART2] = "uart2",
91 [FUNC_MD] = "md",
92 [FUNC_PTP1588] = "1588",
93};
94
95MSCC_P(0, SIO, NONE, NONE);
96MSCC_P(1, SIO, NONE, NONE);
97MSCC_P(2, SIO, NONE, NONE);
98MSCC_P(3, SIO, NONE, NONE);
99MSCC_P(4, TACHO, NONE, NONE);
100MSCC_P(5, PWM, NONE, NONE);
101MSCC_P(6, TWI, NONE, NONE);
102MSCC_P(7, TWI, NONE, NONE);
103MSCC_P(8, SI, NONE, NONE);
104MSCC_P(9, SI, MD, NONE);
105MSCC_P(10, SI, MD, NONE);
106MSCC_P(11, SFP0, MD, TWI_SCL_M);
107MSCC_P(12, SFP1, MD, TWI_SCL_M);
108MSCC_P(13, SFP2, UART2, TWI_SCL_M);
109MSCC_P(14, SFP3, UART2, TWI_SCL_M);
110MSCC_P(15, SFP4, PTP1588, TWI_SCL_M);
111MSCC_P(16, SFP5, PTP1588, TWI_SCL_M);
112MSCC_P(17, SFP6, PCI_WAKE, TWI_SCL_M);
113MSCC_P(18, SFP7, NONE, TWI_SCL_M);
114MSCC_P(19, SFP8, NONE, TWI_SCL_M);
115MSCC_P(20, SFP9, NONE, TWI_SCL_M);
116MSCC_P(21, SFP10, NONE, TWI_SCL_M);
117MSCC_P(22, NONE, NONE, NONE);
118MSCC_P(23, NONE, NONE, NONE);
119MSCC_P(24, NONE, NONE, NONE);
120MSCC_P(25, NONE, NONE, NONE);
121MSCC_P(26, UART, NONE, NONE);
122MSCC_P(27, UART, NONE, NONE);
123MSCC_P(28, IRQ0, NONE, NONE);
124MSCC_P(29, IRQ1, NONE, NONE);
125MSCC_P(30, PTP1588, NONE, NONE);
126MSCC_P(31, PTP1588, NONE, NONE);
127
128#define SERVAL_PIN(n) { \
129 .name = "GPIO_"#n, \
130 .drv_data = &mscc_pin_##n \
131}
132
133static const struct mscc_pin_data serval_pins[] = {
134 SERVAL_PIN(0),
135 SERVAL_PIN(1),
136 SERVAL_PIN(2),
137 SERVAL_PIN(3),
138 SERVAL_PIN(4),
139 SERVAL_PIN(5),
140 SERVAL_PIN(6),
141 SERVAL_PIN(7),
142 SERVAL_PIN(8),
143 SERVAL_PIN(9),
144 SERVAL_PIN(10),
145 SERVAL_PIN(11),
146 SERVAL_PIN(12),
147 SERVAL_PIN(13),
148 SERVAL_PIN(14),
149 SERVAL_PIN(15),
150 SERVAL_PIN(16),
151 SERVAL_PIN(17),
152 SERVAL_PIN(18),
153 SERVAL_PIN(19),
154 SERVAL_PIN(20),
155 SERVAL_PIN(21),
156 SERVAL_PIN(22),
157 SERVAL_PIN(23),
158 SERVAL_PIN(24),
159 SERVAL_PIN(25),
160 SERVAL_PIN(26),
161 SERVAL_PIN(27),
162 SERVAL_PIN(28),
163 SERVAL_PIN(29),
164 SERVAL_PIN(30),
165 SERVAL_PIN(31),
166};
167
168static const unsigned long serval_gpios[] = {
169 [MSCC_GPIO_OUT_SET] = 0x00,
170 [MSCC_GPIO_OUT_CLR] = 0x04,
171 [MSCC_GPIO_OUT] = 0x08,
172 [MSCC_GPIO_IN] = 0x0c,
173 [MSCC_GPIO_OE] = 0x10,
174 [MSCC_GPIO_INTR] = 0x14,
175 [MSCC_GPIO_INTR_ENA] = 0x18,
176 [MSCC_GPIO_INTR_IDENT] = 0x1c,
177 [MSCC_GPIO_ALT0] = 0x20,
178 [MSCC_GPIO_ALT1] = 0x24,
179};
180
181static int serval_gpio_probe(struct udevice *dev)
182{
183 struct gpio_dev_priv *uc_priv;
184
185 uc_priv = dev_get_uclass_priv(dev);
186 uc_priv->bank_name = "serval-gpio";
187 uc_priv->gpio_count = ARRAY_SIZE(serval_pins);
188
189 return 0;
190}
191
192static struct driver serval_gpio_driver = {
193 .name = "serval-gpio",
194 .id = UCLASS_GPIO,
195 .probe = serval_gpio_probe,
196 .ops = &mscc_gpio_ops,
197};
198
199static int serval_pinctrl_probe(struct udevice *dev)
200{
201 int ret;
202
203 ret = mscc_pinctrl_probe(dev, FUNC_MAX, serval_pins,
204 ARRAY_SIZE(serval_pins),
205 serval_function_names,
206 serval_gpios);
207
208 if (ret)
209 return ret;
210
Simon Glass6996c662020-11-28 17:50:03 -0700211 ret = device_bind(dev, &serval_gpio_driver, "serval-gpio", NULL,
212 dev_ofnode(dev), NULL);
Horatiu Vultur50375022019-01-23 16:39:41 +0100213
214 if (ret)
215 return ret;
216
217 return 0;
218}
219
220static const struct udevice_id serval_pinctrl_of_match[] = {
221 { .compatible = "mscc,serval-pinctrl" },
222 {},
223};
224
225U_BOOT_DRIVER(serval_pinctrl) = {
226 .name = "serval-pinctrl",
227 .id = UCLASS_PINCTRL,
228 .of_match = of_match_ptr(serval_pinctrl_of_match),
229 .probe = serval_pinctrl_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700230 .priv_auto = sizeof(struct mscc_pinctrl),
Horatiu Vultur50375022019-01-23 16:39:41 +0100231 .ops = &mscc_pinctrl_ops,
232};