blob: d59d684d3496f5215da5fe2bc1a1fc2dcacbd5c2 [file] [log] [blame]
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi SoCs pinctrl driver
4 *
5 * Author: <alexandre.belloni@free-electrons.com>
6 * License: Dual MIT/GPL
7 * Copyright (c) 2017 Microsemi Corporation
8 */
9
10#include <linux/gpio/driver.h>
11#include <linux/interrupt.h>
12#include <linux/io.h>
13#include <linux/of_device.h>
Quentin Schulzbe36abb2018-07-25 14:26:21 +020014#include <linux/of_irq.h>
Alexandre Bellonice8dc092018-01-06 01:09:26 +010015#include <linux/of_platform.h>
16#include <linux/pinctrl/pinctrl.h>
17#include <linux/pinctrl/pinmux.h>
18#include <linux/pinctrl/pinconf.h>
19#include <linux/pinctrl/pinconf-generic.h>
20#include <linux/platform_device.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23
24#include "core.h"
25#include "pinconf.h"
26#include "pinmux.h"
27
Lars Povlsenf8a74762020-06-15 15:32:37 +020028#define ocelot_clrsetbits(addr, clear, set) \
29 writel((readl(addr) & ~(clear)) | (set), (addr))
30
31/* PINCONFIG bits (sparx5 only) */
32enum {
33 PINCONF_BIAS,
34 PINCONF_SCHMITT,
35 PINCONF_DRIVE_STRENGTH,
36};
37
38#define BIAS_PD_BIT BIT(4)
39#define BIAS_PU_BIT BIT(3)
40#define BIAS_BITS (BIAS_PD_BIT|BIAS_PU_BIT)
41#define SCHMITT_BIT BIT(2)
42#define DRIVE_BITS GENMASK(1, 0)
43
44/* GPIO standard registers */
Alexandre Bellonice8dc092018-01-06 01:09:26 +010045#define OCELOT_GPIO_OUT_SET 0x0
46#define OCELOT_GPIO_OUT_CLR 0x4
47#define OCELOT_GPIO_OUT 0x8
48#define OCELOT_GPIO_IN 0xc
49#define OCELOT_GPIO_OE 0x10
50#define OCELOT_GPIO_INTR 0x14
51#define OCELOT_GPIO_INTR_ENA 0x18
52#define OCELOT_GPIO_INTR_IDENT 0x1c
53#define OCELOT_GPIO_ALT0 0x20
54#define OCELOT_GPIO_ALT1 0x24
55#define OCELOT_GPIO_SD_MAP 0x28
56
Alexandre Bellonice8dc092018-01-06 01:09:26 +010057#define OCELOT_FUNC_PER_PIN 4
58
59enum {
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +053060 FUNC_CAN0_a,
61 FUNC_CAN0_b,
62 FUNC_CAN1,
Alexandre Bellonice8dc092018-01-06 01:09:26 +010063 FUNC_NONE,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +053064 FUNC_FC0_a,
65 FUNC_FC0_b,
66 FUNC_FC0_c,
67 FUNC_FC1_a,
68 FUNC_FC1_b,
69 FUNC_FC1_c,
70 FUNC_FC2_a,
71 FUNC_FC2_b,
72 FUNC_FC3_a,
73 FUNC_FC3_b,
74 FUNC_FC3_c,
75 FUNC_FC4_a,
76 FUNC_FC4_b,
77 FUNC_FC4_c,
78 FUNC_FC_SHRD0,
79 FUNC_FC_SHRD1,
80 FUNC_FC_SHRD2,
81 FUNC_FC_SHRD3,
82 FUNC_FC_SHRD4,
83 FUNC_FC_SHRD5,
84 FUNC_FC_SHRD6,
85 FUNC_FC_SHRD7,
86 FUNC_FC_SHRD8,
87 FUNC_FC_SHRD9,
88 FUNC_FC_SHRD10,
89 FUNC_FC_SHRD11,
90 FUNC_FC_SHRD12,
91 FUNC_FC_SHRD13,
92 FUNC_FC_SHRD14,
93 FUNC_FC_SHRD15,
94 FUNC_FC_SHRD16,
95 FUNC_FC_SHRD17,
96 FUNC_FC_SHRD18,
97 FUNC_FC_SHRD19,
98 FUNC_FC_SHRD20,
Alexandre Bellonice8dc092018-01-06 01:09:26 +010099 FUNC_GPIO,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530100 FUNC_IB_TRG_a,
101 FUNC_IB_TRG_b,
102 FUNC_IB_TRG_c,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200103 FUNC_IRQ0,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530104 FUNC_IRQ_IN_a,
105 FUNC_IRQ_IN_b,
106 FUNC_IRQ_IN_c,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100107 FUNC_IRQ0_IN,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530108 FUNC_IRQ_OUT_a,
109 FUNC_IRQ_OUT_b,
110 FUNC_IRQ_OUT_c,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100111 FUNC_IRQ0_OUT,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200112 FUNC_IRQ1,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100113 FUNC_IRQ1_IN,
114 FUNC_IRQ1_OUT,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200115 FUNC_EXT_IRQ,
Lars Povlsenedc72542020-05-13 14:55:20 +0200116 FUNC_MIIM,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530117 FUNC_MIIM_a,
118 FUNC_MIIM_b,
119 FUNC_MIIM_c,
120 FUNC_MIIM_Sa,
121 FUNC_MIIM_Sb,
122 FUNC_OB_TRG,
123 FUNC_OB_TRG_a,
124 FUNC_OB_TRG_b,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200125 FUNC_PHY_LED,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100126 FUNC_PCI_WAKE,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200127 FUNC_MD,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100128 FUNC_PTP0,
129 FUNC_PTP1,
130 FUNC_PTP2,
131 FUNC_PTP3,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530132 FUNC_PTPSYNC_1,
133 FUNC_PTPSYNC_2,
134 FUNC_PTPSYNC_3,
135 FUNC_PTPSYNC_4,
136 FUNC_PTPSYNC_5,
137 FUNC_PTPSYNC_6,
138 FUNC_PTPSYNC_7,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100139 FUNC_PWM,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530140 FUNC_QSPI1,
141 FUNC_QSPI2,
142 FUNC_R,
143 FUNC_RECO_a,
144 FUNC_RECO_b,
Lars Povlsenedc72542020-05-13 14:55:20 +0200145 FUNC_RECO_CLK,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530146 FUNC_SD,
Lars Povlsenedc72542020-05-13 14:55:20 +0200147 FUNC_SFP,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530148 FUNC_SFP_SD,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100149 FUNC_SG0,
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100150 FUNC_SG1,
151 FUNC_SG2,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530152 FUNC_SGPIO_a,
153 FUNC_SGPIO_b,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100154 FUNC_SI,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200155 FUNC_SI2,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100156 FUNC_TACHO,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530157 FUNC_TACHO_a,
158 FUNC_TACHO_b,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100159 FUNC_TWI,
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100160 FUNC_TWI2,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200161 FUNC_TWI3,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100162 FUNC_TWI_SCL_M,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530163 FUNC_TWI_SLC_GATE,
164 FUNC_TWI_SLC_GATE_AD,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100165 FUNC_UART,
166 FUNC_UART2,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200167 FUNC_UART3,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530168 FUNC_USB_H_a,
169 FUNC_USB_H_b,
170 FUNC_USB_H_c,
171 FUNC_USB_S_a,
172 FUNC_USB_S_b,
173 FUNC_USB_S_c,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200174 FUNC_PLL_STAT,
175 FUNC_EMMC,
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530176 FUNC_EMMC_SD,
Lars Povlsenf8a74762020-06-15 15:32:37 +0200177 FUNC_REF_CLK,
178 FUNC_RCVRD_CLK,
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100179 FUNC_MAX
180};
181
182static const char *const ocelot_function_names[] = {
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530183 [FUNC_CAN0_a] = "can0_a",
184 [FUNC_CAN0_b] = "can0_b",
185 [FUNC_CAN1] = "can1",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100186 [FUNC_NONE] = "none",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530187 [FUNC_FC0_a] = "fc0_a",
188 [FUNC_FC0_b] = "fc0_b",
189 [FUNC_FC0_c] = "fc0_c",
190 [FUNC_FC1_a] = "fc1_a",
191 [FUNC_FC1_b] = "fc1_b",
192 [FUNC_FC1_c] = "fc1_c",
193 [FUNC_FC2_a] = "fc2_a",
194 [FUNC_FC2_b] = "fc2_b",
195 [FUNC_FC3_a] = "fc3_a",
196 [FUNC_FC3_b] = "fc3_b",
197 [FUNC_FC3_c] = "fc3_c",
198 [FUNC_FC4_a] = "fc4_a",
199 [FUNC_FC4_b] = "fc4_b",
200 [FUNC_FC4_c] = "fc4_c",
201 [FUNC_FC_SHRD0] = "fc_shrd0",
202 [FUNC_FC_SHRD1] = "fc_shrd1",
203 [FUNC_FC_SHRD2] = "fc_shrd2",
204 [FUNC_FC_SHRD3] = "fc_shrd3",
205 [FUNC_FC_SHRD4] = "fc_shrd4",
206 [FUNC_FC_SHRD5] = "fc_shrd5",
207 [FUNC_FC_SHRD6] = "fc_shrd6",
208 [FUNC_FC_SHRD7] = "fc_shrd7",
209 [FUNC_FC_SHRD8] = "fc_shrd8",
210 [FUNC_FC_SHRD9] = "fc_shrd9",
211 [FUNC_FC_SHRD10] = "fc_shrd10",
212 [FUNC_FC_SHRD11] = "fc_shrd11",
213 [FUNC_FC_SHRD12] = "fc_shrd12",
214 [FUNC_FC_SHRD13] = "fc_shrd13",
215 [FUNC_FC_SHRD14] = "fc_shrd14",
216 [FUNC_FC_SHRD15] = "fc_shrd15",
217 [FUNC_FC_SHRD16] = "fc_shrd16",
218 [FUNC_FC_SHRD17] = "fc_shrd17",
219 [FUNC_FC_SHRD18] = "fc_shrd18",
220 [FUNC_FC_SHRD19] = "fc_shrd19",
221 [FUNC_FC_SHRD20] = "fc_shrd20",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100222 [FUNC_GPIO] = "gpio",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530223 [FUNC_IB_TRG_a] = "ib_trig_a",
224 [FUNC_IB_TRG_b] = "ib_trig_b",
225 [FUNC_IB_TRG_c] = "ib_trig_c",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200226 [FUNC_IRQ0] = "irq0",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530227 [FUNC_IRQ_IN_a] = "irq_in_a",
228 [FUNC_IRQ_IN_b] = "irq_in_b",
229 [FUNC_IRQ_IN_c] = "irq_in_c",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100230 [FUNC_IRQ0_IN] = "irq0_in",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530231 [FUNC_IRQ_OUT_a] = "irq_out_a",
232 [FUNC_IRQ_OUT_b] = "irq_out_b",
233 [FUNC_IRQ_OUT_c] = "irq_out_c",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100234 [FUNC_IRQ0_OUT] = "irq0_out",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200235 [FUNC_IRQ1] = "irq1",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100236 [FUNC_IRQ1_IN] = "irq1_in",
237 [FUNC_IRQ1_OUT] = "irq1_out",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200238 [FUNC_EXT_IRQ] = "ext_irq",
Lars Povlsenedc72542020-05-13 14:55:20 +0200239 [FUNC_MIIM] = "miim",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530240 [FUNC_MIIM_a] = "miim_a",
241 [FUNC_MIIM_b] = "miim_b",
242 [FUNC_MIIM_c] = "miim_c",
243 [FUNC_MIIM_Sa] = "miim_slave_a",
244 [FUNC_MIIM_Sb] = "miim_slave_b",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200245 [FUNC_PHY_LED] = "phy_led",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100246 [FUNC_PCI_WAKE] = "pci_wake",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200247 [FUNC_MD] = "md",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530248 [FUNC_OB_TRG] = "ob_trig",
249 [FUNC_OB_TRG_a] = "ob_trig_a",
250 [FUNC_OB_TRG_b] = "ob_trig_b",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100251 [FUNC_PTP0] = "ptp0",
252 [FUNC_PTP1] = "ptp1",
253 [FUNC_PTP2] = "ptp2",
254 [FUNC_PTP3] = "ptp3",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530255 [FUNC_PTPSYNC_1] = "ptpsync_1",
256 [FUNC_PTPSYNC_2] = "ptpsync_2",
257 [FUNC_PTPSYNC_3] = "ptpsync_3",
258 [FUNC_PTPSYNC_4] = "ptpsync_4",
259 [FUNC_PTPSYNC_5] = "ptpsync_5",
260 [FUNC_PTPSYNC_6] = "ptpsync_6",
261 [FUNC_PTPSYNC_7] = "ptpsync_7",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100262 [FUNC_PWM] = "pwm",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530263 [FUNC_QSPI1] = "qspi1",
264 [FUNC_QSPI2] = "qspi2",
265 [FUNC_R] = "reserved",
266 [FUNC_RECO_a] = "reco_a",
267 [FUNC_RECO_b] = "reco_b",
Lars Povlsenedc72542020-05-13 14:55:20 +0200268 [FUNC_RECO_CLK] = "reco_clk",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530269 [FUNC_SD] = "sd",
Lars Povlsenedc72542020-05-13 14:55:20 +0200270 [FUNC_SFP] = "sfp",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530271 [FUNC_SFP_SD] = "sfp_sd",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100272 [FUNC_SG0] = "sg0",
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100273 [FUNC_SG1] = "sg1",
274 [FUNC_SG2] = "sg2",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530275 [FUNC_SGPIO_a] = "sgpio_a",
276 [FUNC_SGPIO_b] = "sgpio_b",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100277 [FUNC_SI] = "si",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200278 [FUNC_SI2] = "si2",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100279 [FUNC_TACHO] = "tacho",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530280 [FUNC_TACHO_a] = "tacho_a",
281 [FUNC_TACHO_b] = "tacho_b",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100282 [FUNC_TWI] = "twi",
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100283 [FUNC_TWI2] = "twi2",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200284 [FUNC_TWI3] = "twi3",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100285 [FUNC_TWI_SCL_M] = "twi_scl_m",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530286 [FUNC_TWI_SLC_GATE] = "twi_slc_gate",
287 [FUNC_TWI_SLC_GATE_AD] = "twi_slc_gate_ad",
288 [FUNC_USB_H_a] = "usb_host_a",
289 [FUNC_USB_H_b] = "usb_host_b",
290 [FUNC_USB_H_c] = "usb_host_c",
291 [FUNC_USB_S_a] = "usb_slave_a",
292 [FUNC_USB_S_b] = "usb_slave_b",
293 [FUNC_USB_S_c] = "usb_slave_c",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100294 [FUNC_UART] = "uart",
295 [FUNC_UART2] = "uart2",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200296 [FUNC_UART3] = "uart3",
297 [FUNC_PLL_STAT] = "pll_stat",
298 [FUNC_EMMC] = "emmc",
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530299 [FUNC_EMMC_SD] = "emmc_sd",
Lars Povlsenf8a74762020-06-15 15:32:37 +0200300 [FUNC_REF_CLK] = "ref_clk",
301 [FUNC_RCVRD_CLK] = "rcvrd_clk",
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100302};
303
304struct ocelot_pmx_func {
305 const char **groups;
306 unsigned int ngroups;
307};
308
309struct ocelot_pin_caps {
310 unsigned int pin;
311 unsigned char functions[OCELOT_FUNC_PER_PIN];
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530312 unsigned char a_functions[OCELOT_FUNC_PER_PIN]; /* Additional functions */
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100313};
314
315struct ocelot_pinctrl {
316 struct device *dev;
317 struct pinctrl_dev *pctl;
318 struct gpio_chip gpio_chip;
319 struct regmap *map;
Lars Povlsenf8a74762020-06-15 15:32:37 +0200320 void __iomem *pincfg;
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100321 struct pinctrl_desc *desc;
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100322 struct ocelot_pmx_func func[FUNC_MAX];
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100323 u8 stride;
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100324};
325
Lars Povlsen8f274402020-11-06 10:31:17 +0100326#define LUTON_P(p, f0, f1) \
327static struct ocelot_pin_caps luton_pin_##p = { \
328 .pin = p, \
329 .functions = { \
330 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_NONE, \
331 }, \
332}
333
334LUTON_P(0, SG0, NONE);
335LUTON_P(1, SG0, NONE);
336LUTON_P(2, SG0, NONE);
337LUTON_P(3, SG0, NONE);
338LUTON_P(4, TACHO, NONE);
339LUTON_P(5, TWI, PHY_LED);
340LUTON_P(6, TWI, PHY_LED);
341LUTON_P(7, NONE, PHY_LED);
342LUTON_P(8, EXT_IRQ, PHY_LED);
343LUTON_P(9, EXT_IRQ, PHY_LED);
344LUTON_P(10, SFP, PHY_LED);
345LUTON_P(11, SFP, PHY_LED);
346LUTON_P(12, SFP, PHY_LED);
347LUTON_P(13, SFP, PHY_LED);
348LUTON_P(14, SI, PHY_LED);
349LUTON_P(15, SI, PHY_LED);
350LUTON_P(16, SI, PHY_LED);
351LUTON_P(17, SFP, PHY_LED);
352LUTON_P(18, SFP, PHY_LED);
353LUTON_P(19, SFP, PHY_LED);
354LUTON_P(20, SFP, PHY_LED);
355LUTON_P(21, SFP, PHY_LED);
356LUTON_P(22, SFP, PHY_LED);
357LUTON_P(23, SFP, PHY_LED);
358LUTON_P(24, SFP, PHY_LED);
359LUTON_P(25, SFP, PHY_LED);
360LUTON_P(26, SFP, PHY_LED);
361LUTON_P(27, SFP, PHY_LED);
362LUTON_P(28, SFP, PHY_LED);
363LUTON_P(29, PWM, NONE);
364LUTON_P(30, UART, NONE);
365LUTON_P(31, UART, NONE);
366
367#define LUTON_PIN(n) { \
368 .number = n, \
369 .name = "GPIO_"#n, \
370 .drv_data = &luton_pin_##n \
371}
372
373static const struct pinctrl_pin_desc luton_pins[] = {
374 LUTON_PIN(0),
375 LUTON_PIN(1),
376 LUTON_PIN(2),
377 LUTON_PIN(3),
378 LUTON_PIN(4),
379 LUTON_PIN(5),
380 LUTON_PIN(6),
381 LUTON_PIN(7),
382 LUTON_PIN(8),
383 LUTON_PIN(9),
384 LUTON_PIN(10),
385 LUTON_PIN(11),
386 LUTON_PIN(12),
387 LUTON_PIN(13),
388 LUTON_PIN(14),
389 LUTON_PIN(15),
390 LUTON_PIN(16),
391 LUTON_PIN(17),
392 LUTON_PIN(18),
393 LUTON_PIN(19),
394 LUTON_PIN(20),
395 LUTON_PIN(21),
396 LUTON_PIN(22),
397 LUTON_PIN(23),
398 LUTON_PIN(24),
399 LUTON_PIN(25),
400 LUTON_PIN(26),
401 LUTON_PIN(27),
402 LUTON_PIN(28),
403 LUTON_PIN(29),
404 LUTON_PIN(30),
405 LUTON_PIN(31),
406};
407
Lars Povlsen6e6347e2020-11-06 10:31:18 +0100408#define SERVAL_P(p, f0, f1, f2) \
409static struct ocelot_pin_caps serval_pin_##p = { \
410 .pin = p, \
411 .functions = { \
412 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2, \
413 }, \
414}
415
416SERVAL_P(0, SG0, NONE, NONE);
417SERVAL_P(1, SG0, NONE, NONE);
418SERVAL_P(2, SG0, NONE, NONE);
419SERVAL_P(3, SG0, NONE, NONE);
420SERVAL_P(4, TACHO, NONE, NONE);
421SERVAL_P(5, PWM, NONE, NONE);
422SERVAL_P(6, TWI, NONE, NONE);
423SERVAL_P(7, TWI, NONE, NONE);
424SERVAL_P(8, SI, NONE, NONE);
425SERVAL_P(9, SI, MD, NONE);
426SERVAL_P(10, SI, MD, NONE);
427SERVAL_P(11, SFP, MD, TWI_SCL_M);
428SERVAL_P(12, SFP, MD, TWI_SCL_M);
429SERVAL_P(13, SFP, UART2, TWI_SCL_M);
430SERVAL_P(14, SFP, UART2, TWI_SCL_M);
431SERVAL_P(15, SFP, PTP0, TWI_SCL_M);
432SERVAL_P(16, SFP, PTP0, TWI_SCL_M);
433SERVAL_P(17, SFP, PCI_WAKE, TWI_SCL_M);
434SERVAL_P(18, SFP, NONE, TWI_SCL_M);
435SERVAL_P(19, SFP, NONE, TWI_SCL_M);
436SERVAL_P(20, SFP, NONE, TWI_SCL_M);
437SERVAL_P(21, SFP, NONE, TWI_SCL_M);
438SERVAL_P(22, NONE, NONE, NONE);
439SERVAL_P(23, NONE, NONE, NONE);
440SERVAL_P(24, NONE, NONE, NONE);
441SERVAL_P(25, NONE, NONE, NONE);
442SERVAL_P(26, UART, NONE, NONE);
443SERVAL_P(27, UART, NONE, NONE);
444SERVAL_P(28, IRQ0, NONE, NONE);
445SERVAL_P(29, IRQ1, NONE, NONE);
446SERVAL_P(30, PTP0, NONE, NONE);
447SERVAL_P(31, PTP0, NONE, NONE);
448
449#define SERVAL_PIN(n) { \
450 .number = n, \
451 .name = "GPIO_"#n, \
452 .drv_data = &serval_pin_##n \
453}
454
455static const struct pinctrl_pin_desc serval_pins[] = {
456 SERVAL_PIN(0),
457 SERVAL_PIN(1),
458 SERVAL_PIN(2),
459 SERVAL_PIN(3),
460 SERVAL_PIN(4),
461 SERVAL_PIN(5),
462 SERVAL_PIN(6),
463 SERVAL_PIN(7),
464 SERVAL_PIN(8),
465 SERVAL_PIN(9),
466 SERVAL_PIN(10),
467 SERVAL_PIN(11),
468 SERVAL_PIN(12),
469 SERVAL_PIN(13),
470 SERVAL_PIN(14),
471 SERVAL_PIN(15),
472 SERVAL_PIN(16),
473 SERVAL_PIN(17),
474 SERVAL_PIN(18),
475 SERVAL_PIN(19),
476 SERVAL_PIN(20),
477 SERVAL_PIN(21),
478 SERVAL_PIN(22),
479 SERVAL_PIN(23),
480 SERVAL_PIN(24),
481 SERVAL_PIN(25),
482 SERVAL_PIN(26),
483 SERVAL_PIN(27),
484 SERVAL_PIN(28),
485 SERVAL_PIN(29),
486 SERVAL_PIN(30),
487 SERVAL_PIN(31),
488};
489
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100490#define OCELOT_P(p, f0, f1, f2) \
491static struct ocelot_pin_caps ocelot_pin_##p = { \
492 .pin = p, \
493 .functions = { \
494 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2, \
495 }, \
496}
497
498OCELOT_P(0, SG0, NONE, NONE);
499OCELOT_P(1, SG0, NONE, NONE);
500OCELOT_P(2, SG0, NONE, NONE);
501OCELOT_P(3, SG0, NONE, NONE);
Alexandre Belloni17f79082018-07-11 15:01:26 +0200502OCELOT_P(4, IRQ0_IN, IRQ0_OUT, TWI_SCL_M);
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100503OCELOT_P(5, IRQ1_IN, IRQ1_OUT, PCI_WAKE);
504OCELOT_P(6, UART, TWI_SCL_M, NONE);
505OCELOT_P(7, UART, TWI_SCL_M, NONE);
506OCELOT_P(8, SI, TWI_SCL_M, IRQ0_OUT);
507OCELOT_P(9, SI, TWI_SCL_M, IRQ1_OUT);
Lars Povlsenedc72542020-05-13 14:55:20 +0200508OCELOT_P(10, PTP2, TWI_SCL_M, SFP);
509OCELOT_P(11, PTP3, TWI_SCL_M, SFP);
510OCELOT_P(12, UART2, TWI_SCL_M, SFP);
511OCELOT_P(13, UART2, TWI_SCL_M, SFP);
512OCELOT_P(14, MIIM, TWI_SCL_M, SFP);
513OCELOT_P(15, MIIM, TWI_SCL_M, SFP);
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100514OCELOT_P(16, TWI, NONE, SI);
515OCELOT_P(17, TWI, TWI_SCL_M, SI);
516OCELOT_P(18, PTP0, TWI_SCL_M, NONE);
517OCELOT_P(19, PTP1, TWI_SCL_M, NONE);
Lars Povlsenedc72542020-05-13 14:55:20 +0200518OCELOT_P(20, RECO_CLK, TACHO, TWI_SCL_M);
519OCELOT_P(21, RECO_CLK, PWM, TWI_SCL_M);
Alexandre Bellonice8dc092018-01-06 01:09:26 +0100520
521#define OCELOT_PIN(n) { \
522 .number = n, \
523 .name = "GPIO_"#n, \
524 .drv_data = &ocelot_pin_##n \
525}
526
527static const struct pinctrl_pin_desc ocelot_pins[] = {
528 OCELOT_PIN(0),
529 OCELOT_PIN(1),
530 OCELOT_PIN(2),
531 OCELOT_PIN(3),
532 OCELOT_PIN(4),
533 OCELOT_PIN(5),
534 OCELOT_PIN(6),
535 OCELOT_PIN(7),
536 OCELOT_PIN(8),
537 OCELOT_PIN(9),
538 OCELOT_PIN(10),
539 OCELOT_PIN(11),
540 OCELOT_PIN(12),
541 OCELOT_PIN(13),
542 OCELOT_PIN(14),
543 OCELOT_PIN(15),
544 OCELOT_PIN(16),
545 OCELOT_PIN(17),
546 OCELOT_PIN(18),
547 OCELOT_PIN(19),
548 OCELOT_PIN(20),
549 OCELOT_PIN(21),
550};
551
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100552#define JAGUAR2_P(p, f0, f1) \
553static struct ocelot_pin_caps jaguar2_pin_##p = { \
554 .pin = p, \
555 .functions = { \
556 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_NONE \
557 }, \
558}
559
560JAGUAR2_P(0, SG0, NONE);
561JAGUAR2_P(1, SG0, NONE);
562JAGUAR2_P(2, SG0, NONE);
563JAGUAR2_P(3, SG0, NONE);
564JAGUAR2_P(4, SG1, NONE);
565JAGUAR2_P(5, SG1, NONE);
566JAGUAR2_P(6, IRQ0_IN, IRQ0_OUT);
567JAGUAR2_P(7, IRQ1_IN, IRQ1_OUT);
568JAGUAR2_P(8, PTP0, NONE);
569JAGUAR2_P(9, PTP1, NONE);
570JAGUAR2_P(10, UART, NONE);
571JAGUAR2_P(11, UART, NONE);
572JAGUAR2_P(12, SG1, NONE);
573JAGUAR2_P(13, SG1, NONE);
574JAGUAR2_P(14, TWI, TWI_SCL_M);
575JAGUAR2_P(15, TWI, NONE);
576JAGUAR2_P(16, SI, TWI_SCL_M);
577JAGUAR2_P(17, SI, TWI_SCL_M);
578JAGUAR2_P(18, SI, TWI_SCL_M);
579JAGUAR2_P(19, PCI_WAKE, NONE);
580JAGUAR2_P(20, IRQ0_OUT, TWI_SCL_M);
581JAGUAR2_P(21, IRQ1_OUT, TWI_SCL_M);
582JAGUAR2_P(22, TACHO, NONE);
583JAGUAR2_P(23, PWM, NONE);
584JAGUAR2_P(24, UART2, NONE);
585JAGUAR2_P(25, UART2, SI);
586JAGUAR2_P(26, PTP2, SI);
587JAGUAR2_P(27, PTP3, SI);
588JAGUAR2_P(28, TWI2, SI);
589JAGUAR2_P(29, TWI2, SI);
590JAGUAR2_P(30, SG2, SI);
591JAGUAR2_P(31, SG2, SI);
592JAGUAR2_P(32, SG2, SI);
593JAGUAR2_P(33, SG2, SI);
594JAGUAR2_P(34, NONE, TWI_SCL_M);
595JAGUAR2_P(35, NONE, TWI_SCL_M);
596JAGUAR2_P(36, NONE, TWI_SCL_M);
597JAGUAR2_P(37, NONE, TWI_SCL_M);
598JAGUAR2_P(38, NONE, TWI_SCL_M);
599JAGUAR2_P(39, NONE, TWI_SCL_M);
600JAGUAR2_P(40, NONE, TWI_SCL_M);
601JAGUAR2_P(41, NONE, TWI_SCL_M);
602JAGUAR2_P(42, NONE, TWI_SCL_M);
603JAGUAR2_P(43, NONE, TWI_SCL_M);
Lars Povlsenedc72542020-05-13 14:55:20 +0200604JAGUAR2_P(44, NONE, SFP);
605JAGUAR2_P(45, NONE, SFP);
606JAGUAR2_P(46, NONE, SFP);
607JAGUAR2_P(47, NONE, SFP);
608JAGUAR2_P(48, SFP, NONE);
609JAGUAR2_P(49, SFP, SI);
610JAGUAR2_P(50, SFP, SI);
611JAGUAR2_P(51, SFP, SI);
612JAGUAR2_P(52, SFP, NONE);
613JAGUAR2_P(53, SFP, NONE);
614JAGUAR2_P(54, SFP, NONE);
615JAGUAR2_P(55, SFP, NONE);
616JAGUAR2_P(56, MIIM, SFP);
617JAGUAR2_P(57, MIIM, SFP);
618JAGUAR2_P(58, MIIM, SFP);
619JAGUAR2_P(59, MIIM, SFP);
Alexandre Bellonida801ab2018-12-20 15:44:31 +0100620JAGUAR2_P(60, NONE, NONE);
621JAGUAR2_P(61, NONE, NONE);
622JAGUAR2_P(62, NONE, NONE);
623JAGUAR2_P(63, NONE, NONE);
624
625#define JAGUAR2_PIN(n) { \
626 .number = n, \
627 .name = "GPIO_"#n, \
628 .drv_data = &jaguar2_pin_##n \
629}
630
631static const struct pinctrl_pin_desc jaguar2_pins[] = {
632 JAGUAR2_PIN(0),
633 JAGUAR2_PIN(1),
634 JAGUAR2_PIN(2),
635 JAGUAR2_PIN(3),
636 JAGUAR2_PIN(4),
637 JAGUAR2_PIN(5),
638 JAGUAR2_PIN(6),
639 JAGUAR2_PIN(7),
640 JAGUAR2_PIN(8),
641 JAGUAR2_PIN(9),
642 JAGUAR2_PIN(10),
643 JAGUAR2_PIN(11),
644 JAGUAR2_PIN(12),
645 JAGUAR2_PIN(13),
646 JAGUAR2_PIN(14),
647 JAGUAR2_PIN(15),
648 JAGUAR2_PIN(16),
649 JAGUAR2_PIN(17),
650 JAGUAR2_PIN(18),
651 JAGUAR2_PIN(19),
652 JAGUAR2_PIN(20),
653 JAGUAR2_PIN(21),
654 JAGUAR2_PIN(22),
655 JAGUAR2_PIN(23),
656 JAGUAR2_PIN(24),
657 JAGUAR2_PIN(25),
658 JAGUAR2_PIN(26),
659 JAGUAR2_PIN(27),
660 JAGUAR2_PIN(28),
661 JAGUAR2_PIN(29),
662 JAGUAR2_PIN(30),
663 JAGUAR2_PIN(31),
664 JAGUAR2_PIN(32),
665 JAGUAR2_PIN(33),
666 JAGUAR2_PIN(34),
667 JAGUAR2_PIN(35),
668 JAGUAR2_PIN(36),
669 JAGUAR2_PIN(37),
670 JAGUAR2_PIN(38),
671 JAGUAR2_PIN(39),
672 JAGUAR2_PIN(40),
673 JAGUAR2_PIN(41),
674 JAGUAR2_PIN(42),
675 JAGUAR2_PIN(43),
676 JAGUAR2_PIN(44),
677 JAGUAR2_PIN(45),
678 JAGUAR2_PIN(46),
679 JAGUAR2_PIN(47),
680 JAGUAR2_PIN(48),
681 JAGUAR2_PIN(49),
682 JAGUAR2_PIN(50),
683 JAGUAR2_PIN(51),
684 JAGUAR2_PIN(52),
685 JAGUAR2_PIN(53),
686 JAGUAR2_PIN(54),
687 JAGUAR2_PIN(55),
688 JAGUAR2_PIN(56),
689 JAGUAR2_PIN(57),
690 JAGUAR2_PIN(58),
691 JAGUAR2_PIN(59),
692 JAGUAR2_PIN(60),
693 JAGUAR2_PIN(61),
694 JAGUAR2_PIN(62),
695 JAGUAR2_PIN(63),
696};
697
Lars Povlsenf8a74762020-06-15 15:32:37 +0200698#define SPARX5_P(p, f0, f1, f2) \
699static struct ocelot_pin_caps sparx5_pin_##p = { \
700 .pin = p, \
701 .functions = { \
702 FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2 \
703 }, \
704}
705
706SPARX5_P(0, SG0, PLL_STAT, NONE);
707SPARX5_P(1, SG0, NONE, NONE);
708SPARX5_P(2, SG0, NONE, NONE);
709SPARX5_P(3, SG0, NONE, NONE);
710SPARX5_P(4, SG1, NONE, NONE);
711SPARX5_P(5, SG1, NONE, NONE);
712SPARX5_P(6, IRQ0_IN, IRQ0_OUT, SFP);
713SPARX5_P(7, IRQ1_IN, IRQ1_OUT, SFP);
714SPARX5_P(8, PTP0, NONE, SFP);
715SPARX5_P(9, PTP1, SFP, TWI_SCL_M);
716SPARX5_P(10, UART, NONE, NONE);
717SPARX5_P(11, UART, NONE, NONE);
718SPARX5_P(12, SG1, NONE, NONE);
719SPARX5_P(13, SG1, NONE, NONE);
720SPARX5_P(14, TWI, TWI_SCL_M, NONE);
721SPARX5_P(15, TWI, NONE, NONE);
722SPARX5_P(16, SI, TWI_SCL_M, SFP);
723SPARX5_P(17, SI, TWI_SCL_M, SFP);
724SPARX5_P(18, SI, TWI_SCL_M, SFP);
725SPARX5_P(19, PCI_WAKE, TWI_SCL_M, SFP);
726SPARX5_P(20, IRQ0_OUT, TWI_SCL_M, SFP);
727SPARX5_P(21, IRQ1_OUT, TACHO, SFP);
728SPARX5_P(22, TACHO, IRQ0_OUT, TWI_SCL_M);
729SPARX5_P(23, PWM, UART3, TWI_SCL_M);
730SPARX5_P(24, PTP2, UART3, TWI_SCL_M);
731SPARX5_P(25, PTP3, SI, TWI_SCL_M);
732SPARX5_P(26, UART2, SI, TWI_SCL_M);
733SPARX5_P(27, UART2, SI, TWI_SCL_M);
734SPARX5_P(28, TWI2, SI, SFP);
735SPARX5_P(29, TWI2, SI, SFP);
736SPARX5_P(30, SG2, SI, PWM);
737SPARX5_P(31, SG2, SI, TWI_SCL_M);
738SPARX5_P(32, SG2, SI, TWI_SCL_M);
739SPARX5_P(33, SG2, SI, SFP);
740SPARX5_P(34, NONE, TWI_SCL_M, EMMC);
741SPARX5_P(35, SFP, TWI_SCL_M, EMMC);
742SPARX5_P(36, SFP, TWI_SCL_M, EMMC);
743SPARX5_P(37, SFP, NONE, EMMC);
744SPARX5_P(38, NONE, TWI_SCL_M, EMMC);
745SPARX5_P(39, SI2, TWI_SCL_M, EMMC);
746SPARX5_P(40, SI2, TWI_SCL_M, EMMC);
747SPARX5_P(41, SI2, TWI_SCL_M, EMMC);
748SPARX5_P(42, SI2, TWI_SCL_M, EMMC);
749SPARX5_P(43, SI2, TWI_SCL_M, EMMC);
750SPARX5_P(44, SI, SFP, EMMC);
751SPARX5_P(45, SI, SFP, EMMC);
752SPARX5_P(46, NONE, SFP, EMMC);
753SPARX5_P(47, NONE, SFP, EMMC);
754SPARX5_P(48, TWI3, SI, SFP);
755SPARX5_P(49, TWI3, NONE, SFP);
756SPARX5_P(50, SFP, NONE, TWI_SCL_M);
757SPARX5_P(51, SFP, SI, TWI_SCL_M);
758SPARX5_P(52, SFP, MIIM, TWI_SCL_M);
759SPARX5_P(53, SFP, MIIM, TWI_SCL_M);
760SPARX5_P(54, SFP, PTP2, TWI_SCL_M);
761SPARX5_P(55, SFP, PTP3, PCI_WAKE);
762SPARX5_P(56, MIIM, SFP, TWI_SCL_M);
763SPARX5_P(57, MIIM, SFP, TWI_SCL_M);
764SPARX5_P(58, MIIM, SFP, TWI_SCL_M);
765SPARX5_P(59, MIIM, SFP, NONE);
766SPARX5_P(60, RECO_CLK, NONE, NONE);
767SPARX5_P(61, RECO_CLK, NONE, NONE);
768SPARX5_P(62, RECO_CLK, PLL_STAT, NONE);
769SPARX5_P(63, RECO_CLK, NONE, NONE);
770
771#define SPARX5_PIN(n) { \
772 .number = n, \
773 .name = "GPIO_"#n, \
774 .drv_data = &sparx5_pin_##n \
775}
776
777static const struct pinctrl_pin_desc sparx5_pins[] = {
778 SPARX5_PIN(0),
779 SPARX5_PIN(1),
780 SPARX5_PIN(2),
781 SPARX5_PIN(3),
782 SPARX5_PIN(4),
783 SPARX5_PIN(5),
784 SPARX5_PIN(6),
785 SPARX5_PIN(7),
786 SPARX5_PIN(8),
787 SPARX5_PIN(9),
788 SPARX5_PIN(10),
789 SPARX5_PIN(11),
790 SPARX5_PIN(12),
791 SPARX5_PIN(13),
792 SPARX5_PIN(14),
793 SPARX5_PIN(15),
794 SPARX5_PIN(16),
795 SPARX5_PIN(17),
796 SPARX5_PIN(18),
797 SPARX5_PIN(19),
798 SPARX5_PIN(20),
799 SPARX5_PIN(21),
800 SPARX5_PIN(22),
801 SPARX5_PIN(23),
802 SPARX5_PIN(24),
803 SPARX5_PIN(25),
804 SPARX5_PIN(26),
805 SPARX5_PIN(27),
806 SPARX5_PIN(28),
807 SPARX5_PIN(29),
808 SPARX5_PIN(30),
809 SPARX5_PIN(31),
810 SPARX5_PIN(32),
811 SPARX5_PIN(33),
812 SPARX5_PIN(34),
813 SPARX5_PIN(35),
814 SPARX5_PIN(36),
815 SPARX5_PIN(37),
816 SPARX5_PIN(38),
817 SPARX5_PIN(39),
818 SPARX5_PIN(40),
819 SPARX5_PIN(41),
820 SPARX5_PIN(42),
821 SPARX5_PIN(43),
822 SPARX5_PIN(44),
823 SPARX5_PIN(45),
824 SPARX5_PIN(46),
825 SPARX5_PIN(47),
826 SPARX5_PIN(48),
827 SPARX5_PIN(49),
828 SPARX5_PIN(50),
829 SPARX5_PIN(51),
830 SPARX5_PIN(52),
831 SPARX5_PIN(53),
832 SPARX5_PIN(54),
833 SPARX5_PIN(55),
834 SPARX5_PIN(56),
835 SPARX5_PIN(57),
836 SPARX5_PIN(58),
837 SPARX5_PIN(59),
838 SPARX5_PIN(60),
839 SPARX5_PIN(61),
840 SPARX5_PIN(62),
841 SPARX5_PIN(63),
842};
843
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +0530844#define LAN966X_P(p, f0, f1, f2, f3, f4, f5, f6, f7) \
845static struct ocelot_pin_caps lan966x_pin_##p = { \
846 .pin = p, \
847 .functions = { \
848 FUNC_##f0, FUNC_##f1, FUNC_##f2, \
849 FUNC_##f3 \
850 }, \
851 .a_functions = { \
852 FUNC_##f4, FUNC_##f5, FUNC_##f6, \
853 FUNC_##f7 \
854 }, \
855}
856
857/* Pinmuxing table taken from data sheet */
858/* Pin FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 */
859LAN966X_P(0, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
860LAN966X_P(1, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
861LAN966X_P(2, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
862LAN966X_P(3, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
863LAN966X_P(4, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
864LAN966X_P(5, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
865LAN966X_P(6, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
866LAN966X_P(7, GPIO, NONE, NONE, NONE, NONE, NONE, NONE, R);
867LAN966X_P(8, GPIO, FC0_a, USB_H_b, NONE, USB_S_b, NONE, NONE, R);
868LAN966X_P(9, GPIO, FC0_a, USB_H_b, NONE, NONE, NONE, NONE, R);
869LAN966X_P(10, GPIO, FC0_a, NONE, NONE, NONE, NONE, NONE, R);
870LAN966X_P(11, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R);
871LAN966X_P(12, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R);
872LAN966X_P(13, GPIO, FC1_a, NONE, NONE, NONE, NONE, NONE, R);
873LAN966X_P(14, GPIO, FC2_a, NONE, NONE, NONE, NONE, NONE, R);
874LAN966X_P(15, GPIO, FC2_a, NONE, NONE, NONE, NONE, NONE, R);
875LAN966X_P(16, GPIO, FC2_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R);
876LAN966X_P(17, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R);
877LAN966X_P(18, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R);
878LAN966X_P(19, GPIO, FC3_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, IRQ_OUT_c, R);
879LAN966X_P(20, GPIO, FC4_a, IB_TRG_a, NONE, OB_TRG_a, IRQ_IN_c, NONE, R);
880LAN966X_P(21, GPIO, FC4_a, NONE, NONE, OB_TRG_a, NONE, NONE, R);
881LAN966X_P(22, GPIO, FC4_a, NONE, NONE, OB_TRG_a, NONE, NONE, R);
882LAN966X_P(23, GPIO, NONE, NONE, NONE, OB_TRG_a, NONE, NONE, R);
883LAN966X_P(24, GPIO, FC0_b, IB_TRG_a, USB_H_c, OB_TRG_a, IRQ_IN_c, TACHO_a, R);
884LAN966X_P(25, GPIO, FC0_b, IB_TRG_a, USB_H_c, OB_TRG_a, IRQ_OUT_c, SFP_SD, R);
885LAN966X_P(26, GPIO, FC0_b, IB_TRG_a, USB_S_c, OB_TRG_a, CAN0_a, SFP_SD, R);
886LAN966X_P(27, GPIO, NONE, NONE, NONE, OB_TRG_a, CAN0_a, NONE, R);
887LAN966X_P(28, GPIO, MIIM_a, NONE, NONE, OB_TRG_a, IRQ_OUT_c, SFP_SD, R);
888LAN966X_P(29, GPIO, MIIM_a, NONE, NONE, OB_TRG_a, NONE, NONE, R);
889LAN966X_P(30, GPIO, FC3_c, CAN1, NONE, OB_TRG, RECO_b, NONE, R);
890LAN966X_P(31, GPIO, FC3_c, CAN1, NONE, OB_TRG, RECO_b, NONE, R);
891LAN966X_P(32, GPIO, FC3_c, NONE, SGPIO_a, NONE, MIIM_Sa, NONE, R);
892LAN966X_P(33, GPIO, FC1_b, NONE, SGPIO_a, NONE, MIIM_Sa, MIIM_b, R);
893LAN966X_P(34, GPIO, FC1_b, NONE, SGPIO_a, NONE, MIIM_Sa, MIIM_b, R);
894LAN966X_P(35, GPIO, FC1_b, NONE, SGPIO_a, CAN0_b, NONE, NONE, R);
895LAN966X_P(36, GPIO, NONE, PTPSYNC_1, NONE, CAN0_b, NONE, NONE, R);
896LAN966X_P(37, GPIO, FC_SHRD0, PTPSYNC_2, TWI_SLC_GATE_AD, NONE, NONE, NONE, R);
897LAN966X_P(38, GPIO, NONE, PTPSYNC_3, NONE, NONE, NONE, NONE, R);
898LAN966X_P(39, GPIO, NONE, PTPSYNC_4, NONE, NONE, NONE, NONE, R);
899LAN966X_P(40, GPIO, FC_SHRD1, PTPSYNC_5, NONE, NONE, NONE, NONE, R);
900LAN966X_P(41, GPIO, FC_SHRD2, PTPSYNC_6, TWI_SLC_GATE_AD, NONE, NONE, NONE, R);
901LAN966X_P(42, GPIO, FC_SHRD3, PTPSYNC_7, TWI_SLC_GATE_AD, NONE, NONE, NONE, R);
902LAN966X_P(43, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, RECO_a, IRQ_IN_a, R);
903LAN966X_P(44, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, RECO_a, IRQ_IN_a, R);
904LAN966X_P(45, GPIO, FC2_b, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, NONE, IRQ_IN_a, R);
905LAN966X_P(46, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD4, IRQ_IN_a, R);
906LAN966X_P(47, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD5, IRQ_IN_a, R);
907LAN966X_P(48, GPIO, FC1_c, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, FC_SHRD6, IRQ_IN_a, R);
908LAN966X_P(49, GPIO, FC_SHRD7, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, TWI_SLC_GATE, IRQ_IN_a, R);
909LAN966X_P(50, GPIO, FC_SHRD16, OB_TRG_b, IB_TRG_b, IRQ_OUT_a, TWI_SLC_GATE, NONE, R);
910LAN966X_P(51, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, NONE, IRQ_IN_b, R);
911LAN966X_P(52, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TACHO_b, IRQ_IN_b, R);
912LAN966X_P(53, GPIO, FC3_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, NONE, IRQ_IN_b, R);
913LAN966X_P(54, GPIO, FC_SHRD8, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TWI_SLC_GATE, IRQ_IN_b, R);
914LAN966X_P(55, GPIO, FC_SHRD9, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, TWI_SLC_GATE, IRQ_IN_b, R);
915LAN966X_P(56, GPIO, FC4_b, OB_TRG_b, IB_TRG_c, IRQ_OUT_b, FC_SHRD10, IRQ_IN_b, R);
916LAN966X_P(57, GPIO, FC4_b, TWI_SLC_GATE, IB_TRG_c, IRQ_OUT_b, FC_SHRD11, IRQ_IN_b, R);
917LAN966X_P(58, GPIO, FC4_b, TWI_SLC_GATE, IB_TRG_c, IRQ_OUT_b, FC_SHRD12, IRQ_IN_b, R);
918LAN966X_P(59, GPIO, QSPI1, MIIM_c, NONE, NONE, MIIM_Sb, NONE, R);
919LAN966X_P(60, GPIO, QSPI1, MIIM_c, NONE, NONE, MIIM_Sb, NONE, R);
920LAN966X_P(61, GPIO, QSPI1, NONE, SGPIO_b, FC0_c, MIIM_Sb, NONE, R);
921LAN966X_P(62, GPIO, QSPI1, FC_SHRD13, SGPIO_b, FC0_c, TWI_SLC_GATE, SFP_SD, R);
922LAN966X_P(63, GPIO, QSPI1, FC_SHRD14, SGPIO_b, FC0_c, TWI_SLC_GATE, SFP_SD, R);
923LAN966X_P(64, GPIO, QSPI1, FC4_c, SGPIO_b, FC_SHRD15, TWI_SLC_GATE, SFP_SD, R);
924LAN966X_P(65, GPIO, USB_H_a, FC4_c, NONE, IRQ_OUT_c, TWI_SLC_GATE_AD, NONE, R);
925LAN966X_P(66, GPIO, USB_H_a, FC4_c, USB_S_a, IRQ_OUT_c, IRQ_IN_c, NONE, R);
926LAN966X_P(67, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
927LAN966X_P(68, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
928LAN966X_P(69, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
929LAN966X_P(70, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
930LAN966X_P(71, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
931LAN966X_P(72, GPIO, EMMC_SD, NONE, QSPI2, NONE, NONE, NONE, R);
932LAN966X_P(73, GPIO, EMMC, NONE, NONE, SD, NONE, NONE, R);
933LAN966X_P(74, GPIO, EMMC, NONE, FC_SHRD17, SD, TWI_SLC_GATE, NONE, R);
934LAN966X_P(75, GPIO, EMMC, NONE, FC_SHRD18, SD, TWI_SLC_GATE, NONE, R);
935LAN966X_P(76, GPIO, EMMC, NONE, FC_SHRD19, SD, TWI_SLC_GATE, NONE, R);
936LAN966X_P(77, GPIO, EMMC_SD, NONE, FC_SHRD20, NONE, TWI_SLC_GATE, NONE, R);
937
938#define LAN966X_PIN(n) { \
939 .number = n, \
940 .name = "GPIO_"#n, \
941 .drv_data = &lan966x_pin_##n \
942}
943
944static const struct pinctrl_pin_desc lan966x_pins[] = {
945 LAN966X_PIN(0),
946 LAN966X_PIN(1),
947 LAN966X_PIN(2),
948 LAN966X_PIN(3),
949 LAN966X_PIN(4),
950 LAN966X_PIN(5),
951 LAN966X_PIN(6),
952 LAN966X_PIN(7),
953 LAN966X_PIN(8),
954 LAN966X_PIN(9),
955 LAN966X_PIN(10),
956 LAN966X_PIN(11),
957 LAN966X_PIN(12),
958 LAN966X_PIN(13),
959 LAN966X_PIN(14),
960 LAN966X_PIN(15),
961 LAN966X_PIN(16),
962 LAN966X_PIN(17),
963 LAN966X_PIN(18),
964 LAN966X_PIN(19),
965 LAN966X_PIN(20),
966 LAN966X_PIN(21),
967 LAN966X_PIN(22),
968 LAN966X_PIN(23),
969 LAN966X_PIN(24),
970 LAN966X_PIN(25),
971 LAN966X_PIN(26),
972 LAN966X_PIN(27),
973 LAN966X_PIN(28),
974 LAN966X_PIN(29),
975 LAN966X_PIN(30),
976 LAN966X_PIN(31),
977 LAN966X_PIN(32),
978 LAN966X_PIN(33),
979 LAN966X_PIN(34),
980 LAN966X_PIN(35),
981 LAN966X_PIN(36),
982 LAN966X_PIN(37),
983 LAN966X_PIN(38),
984 LAN966X_PIN(39),
985 LAN966X_PIN(40),
986 LAN966X_PIN(41),
987 LAN966X_PIN(42),
988 LAN966X_PIN(43),
989 LAN966X_PIN(44),
990 LAN966X_PIN(45),
991 LAN966X_PIN(46),
992 LAN966X_PIN(47),
993 LAN966X_PIN(48),
994 LAN966X_PIN(49),
995 LAN966X_PIN(50),
996 LAN966X_PIN(51),
997 LAN966X_PIN(52),
998 LAN966X_PIN(53),
999 LAN966X_PIN(54),
1000 LAN966X_PIN(55),
1001 LAN966X_PIN(56),
1002 LAN966X_PIN(57),
1003 LAN966X_PIN(58),
1004 LAN966X_PIN(59),
1005 LAN966X_PIN(60),
1006 LAN966X_PIN(61),
1007 LAN966X_PIN(62),
1008 LAN966X_PIN(63),
1009 LAN966X_PIN(64),
1010 LAN966X_PIN(65),
1011 LAN966X_PIN(66),
1012 LAN966X_PIN(67),
1013 LAN966X_PIN(68),
1014 LAN966X_PIN(69),
1015 LAN966X_PIN(70),
1016 LAN966X_PIN(71),
1017 LAN966X_PIN(72),
1018 LAN966X_PIN(73),
1019 LAN966X_PIN(74),
1020 LAN966X_PIN(75),
1021 LAN966X_PIN(76),
1022 LAN966X_PIN(77),
1023};
1024
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001025static int ocelot_get_functions_count(struct pinctrl_dev *pctldev)
1026{
1027 return ARRAY_SIZE(ocelot_function_names);
1028}
1029
1030static const char *ocelot_get_function_name(struct pinctrl_dev *pctldev,
1031 unsigned int function)
1032{
1033 return ocelot_function_names[function];
1034}
1035
1036static int ocelot_get_function_groups(struct pinctrl_dev *pctldev,
1037 unsigned int function,
1038 const char *const **groups,
1039 unsigned *const num_groups)
1040{
1041 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1042
1043 *groups = info->func[function].groups;
1044 *num_groups = info->func[function].ngroups;
1045
1046 return 0;
1047}
1048
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001049static int ocelot_pin_function_idx(struct ocelot_pinctrl *info,
1050 unsigned int pin, unsigned int function)
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001051{
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001052 struct ocelot_pin_caps *p = info->desc->pins[pin].drv_data;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001053 int i;
1054
1055 for (i = 0; i < OCELOT_FUNC_PER_PIN; i++) {
1056 if (function == p->functions[i])
1057 return i;
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301058
1059 if (function == p->a_functions[i])
1060 return i + OCELOT_FUNC_PER_PIN;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001061 }
1062
1063 return -1;
1064}
1065
Alexandre Belloni4b360822019-06-20 20:30:37 +02001066#define REG_ALT(msb, info, p) (OCELOT_GPIO_ALT0 * (info)->stride + 4 * ((msb) + ((info)->stride * ((p) / 32))))
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001067
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001068static int ocelot_pinmux_set_mux(struct pinctrl_dev *pctldev,
1069 unsigned int selector, unsigned int group)
1070{
1071 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001072 struct ocelot_pin_caps *pin = info->desc->pins[group].drv_data;
1073 unsigned int p = pin->pin % 32;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001074 int f;
1075
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001076 f = ocelot_pin_function_idx(info, group, selector);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001077 if (f < 0)
1078 return -EINVAL;
1079
1080 /*
1081 * f is encoded on two bits.
Alexandre Belloni4b360822019-06-20 20:30:37 +02001082 * bit 0 of f goes in BIT(pin) of ALT[0], bit 1 of f goes in BIT(pin) of
1083 * ALT[1]
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001084 * This is racy because both registers can't be updated at the same time
1085 * but it doesn't matter much for now.
Lars Povlsenf8a74762020-06-15 15:32:37 +02001086 * Note: ALT0/ALT1 are organized specially for 64 gpio targets
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001087 */
Alexandre Belloni4b360822019-06-20 20:30:37 +02001088 regmap_update_bits(info->map, REG_ALT(0, info, pin->pin),
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001089 BIT(p), f << p);
Alexandre Belloni4b360822019-06-20 20:30:37 +02001090 regmap_update_bits(info->map, REG_ALT(1, info, pin->pin),
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001091 BIT(p), f << (p - 1));
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001092
1093 return 0;
1094}
1095
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301096static int lan966x_pinmux_set_mux(struct pinctrl_dev *pctldev,
1097 unsigned int selector, unsigned int group)
1098{
1099 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1100 struct ocelot_pin_caps *pin = info->desc->pins[group].drv_data;
1101 unsigned int p = pin->pin % 32;
1102 int f;
1103
1104 f = ocelot_pin_function_idx(info, group, selector);
1105 if (f < 0)
1106 return -EINVAL;
1107
1108 /*
1109 * f is encoded on three bits.
1110 * bit 0 of f goes in BIT(pin) of ALT[0], bit 1 of f goes in BIT(pin) of
1111 * ALT[1], bit 2 of f goes in BIT(pin) of ALT[2]
1112 * This is racy because three registers can't be updated at the same time
1113 * but it doesn't matter much for now.
1114 * Note: ALT0/ALT1/ALT2 are organized specially for 78 gpio targets
1115 */
1116 regmap_update_bits(info->map, REG_ALT(0, info, pin->pin),
1117 BIT(p), f << p);
1118 regmap_update_bits(info->map, REG_ALT(1, info, pin->pin),
1119 BIT(p), (f >> 1) << p);
1120 regmap_update_bits(info->map, REG_ALT(2, info, pin->pin),
1121 BIT(p), (f >> 2) << p);
1122
1123 return 0;
1124}
1125
Alexandre Belloni4b360822019-06-20 20:30:37 +02001126#define REG(r, info, p) ((r) * (info)->stride + (4 * ((p) / 32)))
1127
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001128static int ocelot_gpio_set_direction(struct pinctrl_dev *pctldev,
1129 struct pinctrl_gpio_range *range,
1130 unsigned int pin, bool input)
1131{
1132 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001133 unsigned int p = pin % 32;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001134
Alexandre Bellonif2818ba2019-06-20 20:30:36 +02001135 regmap_update_bits(info->map, REG(OCELOT_GPIO_OE, info, pin), BIT(p),
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001136 input ? 0 : BIT(p));
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001137
1138 return 0;
1139}
1140
1141static int ocelot_gpio_request_enable(struct pinctrl_dev *pctldev,
1142 struct pinctrl_gpio_range *range,
1143 unsigned int offset)
1144{
1145 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001146 unsigned int p = offset % 32;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001147
Alexandre Belloni4b360822019-06-20 20:30:37 +02001148 regmap_update_bits(info->map, REG_ALT(0, info, offset),
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001149 BIT(p), 0);
Alexandre Belloni4b360822019-06-20 20:30:37 +02001150 regmap_update_bits(info->map, REG_ALT(1, info, offset),
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001151 BIT(p), 0);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001152
1153 return 0;
1154}
1155
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301156static int lan966x_gpio_request_enable(struct pinctrl_dev *pctldev,
1157 struct pinctrl_gpio_range *range,
1158 unsigned int offset)
1159{
1160 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1161 unsigned int p = offset % 32;
1162
1163 regmap_update_bits(info->map, REG_ALT(0, info, offset),
1164 BIT(p), 0);
1165 regmap_update_bits(info->map, REG_ALT(1, info, offset),
1166 BIT(p), 0);
1167 regmap_update_bits(info->map, REG_ALT(2, info, offset),
1168 BIT(p), 0);
1169
1170 return 0;
1171}
1172
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001173static const struct pinmux_ops ocelot_pmx_ops = {
1174 .get_functions_count = ocelot_get_functions_count,
1175 .get_function_name = ocelot_get_function_name,
1176 .get_function_groups = ocelot_get_function_groups,
1177 .set_mux = ocelot_pinmux_set_mux,
1178 .gpio_set_direction = ocelot_gpio_set_direction,
1179 .gpio_request_enable = ocelot_gpio_request_enable,
1180};
1181
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301182static const struct pinmux_ops lan966x_pmx_ops = {
1183 .get_functions_count = ocelot_get_functions_count,
1184 .get_function_name = ocelot_get_function_name,
1185 .get_function_groups = ocelot_get_function_groups,
1186 .set_mux = lan966x_pinmux_set_mux,
1187 .gpio_set_direction = ocelot_gpio_set_direction,
1188 .gpio_request_enable = lan966x_gpio_request_enable,
1189};
1190
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001191static int ocelot_pctl_get_groups_count(struct pinctrl_dev *pctldev)
1192{
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001193 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1194
1195 return info->desc->npins;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001196}
1197
1198static const char *ocelot_pctl_get_group_name(struct pinctrl_dev *pctldev,
1199 unsigned int group)
1200{
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001201 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1202
1203 return info->desc->pins[group].name;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001204}
1205
1206static int ocelot_pctl_get_group_pins(struct pinctrl_dev *pctldev,
1207 unsigned int group,
1208 const unsigned int **pins,
1209 unsigned int *num_pins)
1210{
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001211 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1212
1213 *pins = &info->desc->pins[group].number;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001214 *num_pins = 1;
1215
1216 return 0;
1217}
1218
Lars Povlsenf8a74762020-06-15 15:32:37 +02001219static int ocelot_hw_get_value(struct ocelot_pinctrl *info,
1220 unsigned int pin,
1221 unsigned int reg,
1222 int *val)
1223{
1224 int ret = -EOPNOTSUPP;
1225
1226 if (info->pincfg) {
1227 u32 regcfg = readl(info->pincfg + (pin * sizeof(u32)));
1228
1229 ret = 0;
1230 switch (reg) {
1231 case PINCONF_BIAS:
1232 *val = regcfg & BIAS_BITS;
1233 break;
1234
1235 case PINCONF_SCHMITT:
1236 *val = regcfg & SCHMITT_BIT;
1237 break;
1238
1239 case PINCONF_DRIVE_STRENGTH:
1240 *val = regcfg & DRIVE_BITS;
1241 break;
1242
1243 default:
1244 ret = -EOPNOTSUPP;
1245 break;
1246 }
1247 }
1248 return ret;
1249}
1250
1251static int ocelot_hw_set_value(struct ocelot_pinctrl *info,
1252 unsigned int pin,
1253 unsigned int reg,
1254 int val)
1255{
1256 int ret = -EOPNOTSUPP;
1257
1258 if (info->pincfg) {
1259 void __iomem *regaddr = info->pincfg + (pin * sizeof(u32));
1260
1261 ret = 0;
1262 switch (reg) {
1263 case PINCONF_BIAS:
1264 ocelot_clrsetbits(regaddr, BIAS_BITS, val);
1265 break;
1266
1267 case PINCONF_SCHMITT:
1268 ocelot_clrsetbits(regaddr, SCHMITT_BIT, val);
1269 break;
1270
1271 case PINCONF_DRIVE_STRENGTH:
1272 if (val <= 3)
1273 ocelot_clrsetbits(regaddr, DRIVE_BITS, val);
1274 else
1275 ret = -EINVAL;
1276 break;
1277
1278 default:
1279 ret = -EOPNOTSUPP;
1280 break;
1281 }
1282 }
1283 return ret;
1284}
1285
1286static int ocelot_pinconf_get(struct pinctrl_dev *pctldev,
1287 unsigned int pin, unsigned long *config)
1288{
1289 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1290 u32 param = pinconf_to_config_param(*config);
1291 int val, err;
1292
1293 switch (param) {
1294 case PIN_CONFIG_BIAS_DISABLE:
1295 case PIN_CONFIG_BIAS_PULL_UP:
1296 case PIN_CONFIG_BIAS_PULL_DOWN:
1297 err = ocelot_hw_get_value(info, pin, PINCONF_BIAS, &val);
1298 if (err)
1299 return err;
1300 if (param == PIN_CONFIG_BIAS_DISABLE)
Kaixu Xia54515252020-11-06 16:36:35 +08001301 val = (val == 0);
Lars Povlsenf8a74762020-06-15 15:32:37 +02001302 else if (param == PIN_CONFIG_BIAS_PULL_DOWN)
1303 val = (val & BIAS_PD_BIT ? true : false);
1304 else /* PIN_CONFIG_BIAS_PULL_UP */
1305 val = (val & BIAS_PU_BIT ? true : false);
1306 break;
1307
1308 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
1309 err = ocelot_hw_get_value(info, pin, PINCONF_SCHMITT, &val);
1310 if (err)
1311 return err;
1312
1313 val = (val & SCHMITT_BIT ? true : false);
1314 break;
1315
1316 case PIN_CONFIG_DRIVE_STRENGTH:
1317 err = ocelot_hw_get_value(info, pin, PINCONF_DRIVE_STRENGTH,
1318 &val);
1319 if (err)
1320 return err;
1321 break;
1322
1323 case PIN_CONFIG_OUTPUT:
1324 err = regmap_read(info->map, REG(OCELOT_GPIO_OUT, info, pin),
1325 &val);
1326 if (err)
1327 return err;
1328 val = !!(val & BIT(pin % 32));
1329 break;
1330
1331 case PIN_CONFIG_INPUT_ENABLE:
1332 case PIN_CONFIG_OUTPUT_ENABLE:
1333 err = regmap_read(info->map, REG(OCELOT_GPIO_OE, info, pin),
1334 &val);
1335 if (err)
1336 return err;
1337 val = val & BIT(pin % 32);
1338 if (param == PIN_CONFIG_OUTPUT_ENABLE)
1339 val = !!val;
1340 else
1341 val = !val;
1342 break;
1343
1344 default:
1345 return -EOPNOTSUPP;
1346 }
1347
1348 *config = pinconf_to_config_packed(param, val);
1349
1350 return 0;
1351}
1352
1353static int ocelot_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
1354 unsigned long *configs, unsigned int num_configs)
1355{
1356 struct ocelot_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
1357 u32 param, arg, p;
1358 int cfg, err = 0;
1359
1360 for (cfg = 0; cfg < num_configs; cfg++) {
1361 param = pinconf_to_config_param(configs[cfg]);
1362 arg = pinconf_to_config_argument(configs[cfg]);
1363
1364 switch (param) {
1365 case PIN_CONFIG_BIAS_DISABLE:
1366 case PIN_CONFIG_BIAS_PULL_UP:
1367 case PIN_CONFIG_BIAS_PULL_DOWN:
1368 arg = (param == PIN_CONFIG_BIAS_DISABLE) ? 0 :
1369 (param == PIN_CONFIG_BIAS_PULL_UP) ? BIAS_PU_BIT :
1370 BIAS_PD_BIT;
1371
1372 err = ocelot_hw_set_value(info, pin, PINCONF_BIAS, arg);
1373 if (err)
1374 goto err;
1375
1376 break;
1377
1378 case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
1379 arg = arg ? SCHMITT_BIT : 0;
1380 err = ocelot_hw_set_value(info, pin, PINCONF_SCHMITT,
1381 arg);
1382 if (err)
1383 goto err;
1384
1385 break;
1386
1387 case PIN_CONFIG_DRIVE_STRENGTH:
1388 err = ocelot_hw_set_value(info, pin,
1389 PINCONF_DRIVE_STRENGTH,
1390 arg);
1391 if (err)
1392 goto err;
1393
1394 break;
1395
1396 case PIN_CONFIG_OUTPUT_ENABLE:
1397 case PIN_CONFIG_INPUT_ENABLE:
1398 case PIN_CONFIG_OUTPUT:
1399 p = pin % 32;
1400 if (arg)
1401 regmap_write(info->map,
1402 REG(OCELOT_GPIO_OUT_SET, info,
1403 pin),
1404 BIT(p));
1405 else
1406 regmap_write(info->map,
1407 REG(OCELOT_GPIO_OUT_CLR, info,
1408 pin),
1409 BIT(p));
1410 regmap_update_bits(info->map,
1411 REG(OCELOT_GPIO_OE, info, pin),
1412 BIT(p),
1413 param == PIN_CONFIG_INPUT_ENABLE ?
1414 0 : BIT(p));
1415 break;
1416
1417 default:
1418 err = -EOPNOTSUPP;
1419 }
1420 }
1421err:
1422 return err;
1423}
1424
1425static const struct pinconf_ops ocelot_confops = {
1426 .is_generic = true,
1427 .pin_config_get = ocelot_pinconf_get,
1428 .pin_config_set = ocelot_pinconf_set,
1429 .pin_config_config_dbg_show = pinconf_generic_dump_config,
1430};
1431
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001432static const struct pinctrl_ops ocelot_pctl_ops = {
1433 .get_groups_count = ocelot_pctl_get_groups_count,
1434 .get_group_name = ocelot_pctl_get_group_name,
1435 .get_group_pins = ocelot_pctl_get_group_pins,
1436 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
1437 .dt_free_map = pinconf_generic_dt_free_map,
1438};
1439
Lars Povlsen8f274402020-11-06 10:31:17 +01001440static struct pinctrl_desc luton_desc = {
1441 .name = "luton-pinctrl",
1442 .pins = luton_pins,
1443 .npins = ARRAY_SIZE(luton_pins),
1444 .pctlops = &ocelot_pctl_ops,
1445 .pmxops = &ocelot_pmx_ops,
1446 .owner = THIS_MODULE,
1447};
1448
Lars Povlsen6e6347e2020-11-06 10:31:18 +01001449static struct pinctrl_desc serval_desc = {
1450 .name = "serval-pinctrl",
1451 .pins = serval_pins,
1452 .npins = ARRAY_SIZE(serval_pins),
1453 .pctlops = &ocelot_pctl_ops,
1454 .pmxops = &ocelot_pmx_ops,
1455 .owner = THIS_MODULE,
1456};
1457
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001458static struct pinctrl_desc ocelot_desc = {
1459 .name = "ocelot-pinctrl",
1460 .pins = ocelot_pins,
1461 .npins = ARRAY_SIZE(ocelot_pins),
1462 .pctlops = &ocelot_pctl_ops,
1463 .pmxops = &ocelot_pmx_ops,
1464 .owner = THIS_MODULE,
1465};
1466
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001467static struct pinctrl_desc jaguar2_desc = {
1468 .name = "jaguar2-pinctrl",
1469 .pins = jaguar2_pins,
1470 .npins = ARRAY_SIZE(jaguar2_pins),
1471 .pctlops = &ocelot_pctl_ops,
1472 .pmxops = &ocelot_pmx_ops,
1473 .owner = THIS_MODULE,
1474};
1475
Lars Povlsenf8a74762020-06-15 15:32:37 +02001476static struct pinctrl_desc sparx5_desc = {
1477 .name = "sparx5-pinctrl",
1478 .pins = sparx5_pins,
1479 .npins = ARRAY_SIZE(sparx5_pins),
1480 .pctlops = &ocelot_pctl_ops,
1481 .pmxops = &ocelot_pmx_ops,
1482 .confops = &ocelot_confops,
1483 .owner = THIS_MODULE,
1484};
1485
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301486static struct pinctrl_desc lan966x_desc = {
1487 .name = "lan966x-pinctrl",
1488 .pins = lan966x_pins,
1489 .npins = ARRAY_SIZE(lan966x_pins),
1490 .pctlops = &ocelot_pctl_ops,
1491 .pmxops = &lan966x_pmx_ops,
1492 .confops = &ocelot_confops,
1493 .owner = THIS_MODULE,
1494};
1495
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001496static int ocelot_create_group_func_map(struct device *dev,
1497 struct ocelot_pinctrl *info)
1498{
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001499 int f, npins, i;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001500 u8 *pins = kcalloc(info->desc->npins, sizeof(u8), GFP_KERNEL);
1501
1502 if (!pins)
1503 return -ENOMEM;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001504
1505 for (f = 0; f < FUNC_MAX; f++) {
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001506 for (npins = 0, i = 0; i < info->desc->npins; i++) {
1507 if (ocelot_pin_function_idx(info, i, f) >= 0)
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001508 pins[npins++] = i;
1509 }
1510
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001511 if (!npins)
1512 continue;
1513
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001514 info->func[f].ngroups = npins;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001515 info->func[f].groups = devm_kcalloc(dev, npins, sizeof(char *),
1516 GFP_KERNEL);
1517 if (!info->func[f].groups) {
1518 kfree(pins);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001519 return -ENOMEM;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001520 }
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001521
1522 for (i = 0; i < npins; i++)
Lars Povlsenf8a74762020-06-15 15:32:37 +02001523 info->func[f].groups[i] =
1524 info->desc->pins[pins[i]].name;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001525 }
1526
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001527 kfree(pins);
1528
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001529 return 0;
1530}
1531
1532static int ocelot_pinctrl_register(struct platform_device *pdev,
1533 struct ocelot_pinctrl *info)
1534{
1535 int ret;
1536
1537 ret = ocelot_create_group_func_map(&pdev->dev, info);
1538 if (ret) {
1539 dev_err(&pdev->dev, "Unable to create group func map.\n");
1540 return ret;
1541 }
1542
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001543 info->pctl = devm_pinctrl_register(&pdev->dev, info->desc, info);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001544 if (IS_ERR(info->pctl)) {
1545 dev_err(&pdev->dev, "Failed to register pinctrl\n");
1546 return PTR_ERR(info->pctl);
1547 }
1548
1549 return 0;
1550}
1551
1552static int ocelot_gpio_get(struct gpio_chip *chip, unsigned int offset)
1553{
1554 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1555 unsigned int val;
1556
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001557 regmap_read(info->map, REG(OCELOT_GPIO_IN, info, offset), &val);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001558
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001559 return !!(val & BIT(offset % 32));
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001560}
1561
1562static void ocelot_gpio_set(struct gpio_chip *chip, unsigned int offset,
1563 int value)
1564{
1565 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1566
1567 if (value)
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001568 regmap_write(info->map, REG(OCELOT_GPIO_OUT_SET, info, offset),
1569 BIT(offset % 32));
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001570 else
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001571 regmap_write(info->map, REG(OCELOT_GPIO_OUT_CLR, info, offset),
1572 BIT(offset % 32));
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001573}
1574
1575static int ocelot_gpio_get_direction(struct gpio_chip *chip,
1576 unsigned int offset)
1577{
1578 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1579 unsigned int val;
1580
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001581 regmap_read(info->map, REG(OCELOT_GPIO_OE, info, offset), &val);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001582
Matti Vaittinen3c827872020-02-14 15:57:12 +02001583 if (val & BIT(offset % 32))
1584 return GPIO_LINE_DIRECTION_OUT;
1585
1586 return GPIO_LINE_DIRECTION_IN;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001587}
1588
1589static int ocelot_gpio_direction_input(struct gpio_chip *chip,
1590 unsigned int offset)
1591{
1592 return pinctrl_gpio_direction_input(chip->base + offset);
1593}
1594
1595static int ocelot_gpio_direction_output(struct gpio_chip *chip,
1596 unsigned int offset, int value)
1597{
1598 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001599 unsigned int pin = BIT(offset % 32);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001600
1601 if (value)
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001602 regmap_write(info->map, REG(OCELOT_GPIO_OUT_SET, info, offset),
1603 pin);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001604 else
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001605 regmap_write(info->map, REG(OCELOT_GPIO_OUT_CLR, info, offset),
1606 pin);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001607
1608 return pinctrl_gpio_direction_output(chip->base + offset);
1609}
1610
1611static const struct gpio_chip ocelot_gpiolib_chip = {
1612 .request = gpiochip_generic_request,
1613 .free = gpiochip_generic_free,
1614 .set = ocelot_gpio_set,
1615 .get = ocelot_gpio_get,
1616 .get_direction = ocelot_gpio_get_direction,
1617 .direction_input = ocelot_gpio_direction_input,
1618 .direction_output = ocelot_gpio_direction_output,
1619 .owner = THIS_MODULE,
1620};
1621
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001622static void ocelot_irq_mask(struct irq_data *data)
1623{
1624 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
1625 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1626 unsigned int gpio = irqd_to_hwirq(data);
1627
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001628 regmap_update_bits(info->map, REG(OCELOT_GPIO_INTR_ENA, info, gpio),
1629 BIT(gpio % 32), 0);
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001630}
1631
1632static void ocelot_irq_unmask(struct irq_data *data)
1633{
1634 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
1635 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1636 unsigned int gpio = irqd_to_hwirq(data);
1637
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001638 regmap_update_bits(info->map, REG(OCELOT_GPIO_INTR_ENA, info, gpio),
1639 BIT(gpio % 32), BIT(gpio % 32));
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001640}
1641
1642static void ocelot_irq_ack(struct irq_data *data)
1643{
1644 struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
1645 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
1646 unsigned int gpio = irqd_to_hwirq(data);
1647
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001648 regmap_write_bits(info->map, REG(OCELOT_GPIO_INTR, info, gpio),
1649 BIT(gpio % 32), BIT(gpio % 32));
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001650}
1651
1652static int ocelot_irq_set_type(struct irq_data *data, unsigned int type);
1653
1654static struct irq_chip ocelot_eoi_irqchip = {
1655 .name = "gpio",
1656 .irq_mask = ocelot_irq_mask,
1657 .irq_eoi = ocelot_irq_ack,
1658 .irq_unmask = ocelot_irq_unmask,
1659 .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED,
1660 .irq_set_type = ocelot_irq_set_type,
1661};
1662
1663static struct irq_chip ocelot_irqchip = {
1664 .name = "gpio",
1665 .irq_mask = ocelot_irq_mask,
1666 .irq_ack = ocelot_irq_ack,
1667 .irq_unmask = ocelot_irq_unmask,
1668 .irq_set_type = ocelot_irq_set_type,
1669};
1670
1671static int ocelot_irq_set_type(struct irq_data *data, unsigned int type)
1672{
1673 type &= IRQ_TYPE_SENSE_MASK;
1674
1675 if (!(type & (IRQ_TYPE_EDGE_BOTH | IRQ_TYPE_LEVEL_HIGH)))
1676 return -EINVAL;
1677
1678 if (type & IRQ_TYPE_LEVEL_HIGH)
1679 irq_set_chip_handler_name_locked(data, &ocelot_eoi_irqchip,
1680 handle_fasteoi_irq, NULL);
1681 if (type & IRQ_TYPE_EDGE_BOTH)
1682 irq_set_chip_handler_name_locked(data, &ocelot_irqchip,
1683 handle_edge_irq, NULL);
1684
1685 return 0;
1686}
1687
1688static void ocelot_irq_handler(struct irq_desc *desc)
1689{
1690 struct irq_chip *parent_chip = irq_desc_get_chip(desc);
1691 struct gpio_chip *chip = irq_desc_get_handler_data(desc);
1692 struct ocelot_pinctrl *info = gpiochip_get_data(chip);
Lars Povlsen0b47afc62020-05-13 14:55:21 +02001693 unsigned int id_reg = OCELOT_GPIO_INTR_IDENT * info->stride;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001694 unsigned int reg = 0, irq, i;
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001695 unsigned long irqs;
1696
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001697 for (i = 0; i < info->stride; i++) {
Lars Povlsen0b47afc62020-05-13 14:55:21 +02001698 regmap_read(info->map, id_reg + 4 * i, &reg);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001699 if (!reg)
1700 continue;
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001701
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001702 chained_irq_enter(parent_chip, desc);
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001703
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001704 irqs = reg;
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001705
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001706 for_each_set_bit(irq, &irqs,
1707 min(32U, info->desc->npins - 32 * i))
Marc Zyngiera9cb09b2021-05-04 17:42:18 +01001708 generic_handle_domain_irq(chip->irq.domain, irq + 32 * i);
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001709
1710 chained_irq_exit(parent_chip, desc);
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001711 }
Quentin Schulzbe36abb2018-07-25 14:26:21 +02001712}
1713
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001714static int ocelot_gpiochip_register(struct platform_device *pdev,
1715 struct ocelot_pinctrl *info)
1716{
1717 struct gpio_chip *gc;
Linus Walleijd874bec2019-10-02 13:44:54 +02001718 struct gpio_irq_chip *girq;
Qinglang Miao17f2c8d2020-09-21 21:10:57 +08001719 int irq;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001720
1721 info->gpio_chip = ocelot_gpiolib_chip;
1722
1723 gc = &info->gpio_chip;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001724 gc->ngpio = info->desc->npins;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001725 gc->parent = &pdev->dev;
Colin Fostera159c2b2021-11-19 11:59:26 -08001726 gc->base = -1;
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001727 gc->of_node = info->dev->of_node;
1728 gc->label = "ocelot-gpio";
1729
Lars Povlsen550713e2020-05-13 14:55:19 +02001730 irq = irq_of_parse_and_map(gc->of_node, 0);
1731 if (irq) {
1732 girq = &gc->irq;
1733 girq->chip = &ocelot_irqchip;
1734 girq->parent_handler = ocelot_irq_handler;
1735 girq->num_parents = 1;
1736 girq->parents = devm_kcalloc(&pdev->dev, 1,
1737 sizeof(*girq->parents),
1738 GFP_KERNEL);
1739 if (!girq->parents)
1740 return -ENOMEM;
1741 girq->parents[0] = irq;
1742 girq->default_type = IRQ_TYPE_NONE;
1743 girq->handler = handle_edge_irq;
1744 }
Linus Walleijd874bec2019-10-02 13:44:54 +02001745
Qinglang Miao17f2c8d2020-09-21 21:10:57 +08001746 return devm_gpiochip_add_data(&pdev->dev, gc, info);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001747}
1748
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001749static const struct of_device_id ocelot_pinctrl_of_match[] = {
Lars Povlsen8f274402020-11-06 10:31:17 +01001750 { .compatible = "mscc,luton-pinctrl", .data = &luton_desc },
Lars Povlsen6e6347e2020-11-06 10:31:18 +01001751 { .compatible = "mscc,serval-pinctrl", .data = &serval_desc },
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001752 { .compatible = "mscc,ocelot-pinctrl", .data = &ocelot_desc },
1753 { .compatible = "mscc,jaguar2-pinctrl", .data = &jaguar2_desc },
Lars Povlsenf8a74762020-06-15 15:32:37 +02001754 { .compatible = "microchip,sparx5-pinctrl", .data = &sparx5_desc },
Kavyasree Kotagiri531d6ab2021-11-18 16:55:48 +05301755 { .compatible = "microchip,lan966x-pinctrl", .data = &lan966x_desc },
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001756 {},
1757};
1758
Colin Ian Kingce3e7f02018-02-08 14:24:37 +00001759static int ocelot_pinctrl_probe(struct platform_device *pdev)
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001760{
1761 struct device *dev = &pdev->dev;
1762 struct ocelot_pinctrl *info;
1763 void __iomem *base;
1764 int ret;
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001765 struct regmap_config regmap_config = {
1766 .reg_bits = 32,
1767 .val_bits = 32,
1768 .reg_stride = 4,
1769 };
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001770
1771 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
1772 if (!info)
1773 return -ENOMEM;
1774
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001775 info->desc = (struct pinctrl_desc *)device_get_match_data(dev);
1776
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001777 base = devm_ioremap_resource(dev,
1778 platform_get_resource(pdev, IORESOURCE_MEM, 0));
Zhen Lei0f9facd2021-05-11 17:09:36 +08001779 if (IS_ERR(base))
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001780 return PTR_ERR(base);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001781
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001782 info->stride = 1 + (info->desc->npins - 1) / 32;
Lars Povlsenf8a74762020-06-15 15:32:37 +02001783
Alexandre Bellonida801ab2018-12-20 15:44:31 +01001784 regmap_config.max_register = OCELOT_GPIO_SD_MAP * info->stride + 15 * 4;
1785
1786 info->map = devm_regmap_init_mmio(dev, base, &regmap_config);
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001787 if (IS_ERR(info->map)) {
1788 dev_err(dev, "Failed to create regmap\n");
1789 return PTR_ERR(info->map);
1790 }
1791 dev_set_drvdata(dev, info->map);
1792 info->dev = dev;
1793
Lars Povlsenf8a74762020-06-15 15:32:37 +02001794 /* Pinconf registers */
1795 if (info->desc->confops) {
Colin Fosterad961112021-11-19 11:59:25 -08001796 base = devm_platform_ioremap_resource(pdev, 0);
Lars Povlsenf8a74762020-06-15 15:32:37 +02001797 if (IS_ERR(base))
1798 dev_dbg(dev, "Failed to ioremap config registers (no extended pinconf)\n");
1799 else
1800 info->pincfg = base;
1801 }
1802
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001803 ret = ocelot_pinctrl_register(pdev, info);
1804 if (ret)
1805 return ret;
1806
1807 ret = ocelot_gpiochip_register(pdev, info);
1808 if (ret)
1809 return ret;
1810
Lars Povlsenf8a74762020-06-15 15:32:37 +02001811 dev_info(dev, "driver registered\n");
1812
Alexandre Bellonice8dc092018-01-06 01:09:26 +01001813 return 0;
1814}
1815
1816static struct platform_driver ocelot_pinctrl_driver = {
1817 .driver = {
1818 .name = "pinctrl-ocelot",
1819 .of_match_table = of_match_ptr(ocelot_pinctrl_of_match),
1820 .suppress_bind_attrs = true,
1821 },
1822 .probe = ocelot_pinctrl_probe,
1823};
1824builtin_platform_driver(ocelot_pinctrl_driver);