blob: 826388c2f7462b8783a562cf575d785b6a3f1a52 [file] [log] [blame]
Gregory CLEMENT2a626432018-12-08 09:59:01 +01001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * Microsemi SoCs pinctrl driver
4 *
5 * Author: <alexandre.belloni@free-electrons.com>
6 * Author: <gregory.clement@bootlin.com>
7 * License: Dual MIT/GPL
8 * Copyright (c) 2017 Microsemi Corporation
9 */
10
11#include <asm/gpio.h>
12#include <asm/system.h>
Gregory CLEMENT2a626432018-12-08 09:59:01 +010013#include <config.h>
14#include <dm.h>
15#include <dm/device-internal.h>
16#include <dm/lists.h>
17#include <dm/pinctrl.h>
18#include <dm/root.h>
19#include <errno.h>
20#include <fdtdec.h>
21#include <linux/io.h>
22#include "mscc-common.h"
23
24enum {
25 FUNC_NONE,
26 FUNC_GPIO,
27 FUNC_IRQ0_IN,
28 FUNC_IRQ0_OUT,
29 FUNC_IRQ1_IN,
30 FUNC_IRQ1_OUT,
31 FUNC_MIIM1,
32 FUNC_PCI_WAKE,
33 FUNC_PTP0,
34 FUNC_PTP1,
35 FUNC_PTP2,
36 FUNC_PTP3,
37 FUNC_PWM,
38 FUNC_RECO_CLK0,
39 FUNC_RECO_CLK1,
40 FUNC_SFP0,
41 FUNC_SFP1,
42 FUNC_SFP2,
43 FUNC_SFP3,
44 FUNC_SFP4,
45 FUNC_SFP5,
46 FUNC_SG0,
47 FUNC_SI,
48 FUNC_TACHO,
49 FUNC_TWI,
50 FUNC_TWI_SCL_M,
51 FUNC_UART,
52 FUNC_UART2,
53 FUNC_MAX
54};
55
56static char * const ocelot_function_names[] = {
57 [FUNC_NONE] = "none",
58 [FUNC_GPIO] = "gpio",
59 [FUNC_IRQ0_IN] = "irq0_in",
60 [FUNC_IRQ0_OUT] = "irq0_out",
61 [FUNC_IRQ1_IN] = "irq1_in",
62 [FUNC_IRQ1_OUT] = "irq1_out",
63 [FUNC_MIIM1] = "miim1",
64 [FUNC_PCI_WAKE] = "pci_wake",
65 [FUNC_PTP0] = "ptp0",
66 [FUNC_PTP1] = "ptp1",
67 [FUNC_PTP2] = "ptp2",
68 [FUNC_PTP3] = "ptp3",
69 [FUNC_PWM] = "pwm",
70 [FUNC_RECO_CLK0] = "reco_clk0",
71 [FUNC_RECO_CLK1] = "reco_clk1",
72 [FUNC_SFP0] = "sfp0",
73 [FUNC_SFP1] = "sfp1",
74 [FUNC_SFP2] = "sfp2",
75 [FUNC_SFP3] = "sfp3",
76 [FUNC_SFP4] = "sfp4",
77 [FUNC_SFP5] = "sfp5",
78 [FUNC_SG0] = "sg0",
79 [FUNC_SI] = "si",
80 [FUNC_TACHO] = "tacho",
81 [FUNC_TWI] = "twi",
82 [FUNC_TWI_SCL_M] = "twi_scl_m",
83 [FUNC_UART] = "uart",
84 [FUNC_UART2] = "uart2",
85};
86
87MSCC_P(0, SG0, NONE, NONE);
88MSCC_P(1, SG0, NONE, NONE);
89MSCC_P(2, SG0, NONE, NONE);
90MSCC_P(3, SG0, NONE, NONE);
91MSCC_P(4, IRQ0_IN, IRQ0_OUT, TWI);
92MSCC_P(5, IRQ1_IN, IRQ1_OUT, PCI_WAKE);
93MSCC_P(6, UART, TWI_SCL_M, NONE);
94MSCC_P(7, UART, TWI_SCL_M, NONE);
95MSCC_P(8, SI, TWI_SCL_M, IRQ0_OUT);
96MSCC_P(9, SI, TWI_SCL_M, IRQ1_OUT);
97MSCC_P(10, PTP2, TWI_SCL_M, SFP0);
98MSCC_P(11, PTP3, TWI_SCL_M, SFP1);
99MSCC_P(12, UART2, TWI_SCL_M, SFP2);
100MSCC_P(13, UART2, TWI_SCL_M, SFP3);
101MSCC_P(14, MIIM1, TWI_SCL_M, SFP4);
102MSCC_P(15, MIIM1, TWI_SCL_M, SFP5);
103MSCC_P(16, TWI, NONE, SI);
104MSCC_P(17, TWI, TWI_SCL_M, SI);
105MSCC_P(18, PTP0, TWI_SCL_M, NONE);
106MSCC_P(19, PTP1, TWI_SCL_M, NONE);
107MSCC_P(20, RECO_CLK0, TACHO, NONE);
108MSCC_P(21, RECO_CLK1, PWM, NONE);
109
110#define OCELOT_PIN(n) { \
111 .name = "GPIO_"#n, \
112 .drv_data = &mscc_pin_##n \
113}
114
115static const struct mscc_pin_data ocelot_pins[] = {
116 OCELOT_PIN(0),
117 OCELOT_PIN(1),
118 OCELOT_PIN(2),
119 OCELOT_PIN(3),
120 OCELOT_PIN(4),
121 OCELOT_PIN(5),
122 OCELOT_PIN(6),
123 OCELOT_PIN(7),
124 OCELOT_PIN(8),
125 OCELOT_PIN(9),
126 OCELOT_PIN(10),
127 OCELOT_PIN(11),
128 OCELOT_PIN(12),
129 OCELOT_PIN(13),
130 OCELOT_PIN(14),
131 OCELOT_PIN(15),
132 OCELOT_PIN(16),
133 OCELOT_PIN(17),
134 OCELOT_PIN(18),
135 OCELOT_PIN(19),
136 OCELOT_PIN(20),
137 OCELOT_PIN(21),
138};
139
Horatiu Vultur2d4fb842019-01-12 18:56:55 +0100140static const unsigned long ocelot_gpios[] = {
141 [MSCC_GPIO_OUT_SET] = 0x00,
142 [MSCC_GPIO_OUT_CLR] = 0x04,
143 [MSCC_GPIO_OUT] = 0x08,
144 [MSCC_GPIO_IN] = 0x0c,
145 [MSCC_GPIO_OE] = 0x10,
146 [MSCC_GPIO_INTR] = 0x14,
147 [MSCC_GPIO_INTR_ENA] = 0x18,
148 [MSCC_GPIO_INTR_IDENT] = 0x1c,
149 [MSCC_GPIO_ALT0] = 0x20,
150 [MSCC_GPIO_ALT1] = 0x24,
151};
152
Gregory CLEMENT2a626432018-12-08 09:59:01 +0100153static int ocelot_gpio_probe(struct udevice *dev)
154{
155 struct gpio_dev_priv *uc_priv;
156
157 uc_priv = dev_get_uclass_priv(dev);
158 uc_priv->bank_name = "ocelot-gpio";
159 uc_priv->gpio_count = ARRAY_SIZE(ocelot_pins);
160
161 return 0;
162}
163
164static struct driver ocelot_gpio_driver = {
165 .name = "ocelot-gpio",
166 .id = UCLASS_GPIO,
167 .probe = ocelot_gpio_probe,
168 .ops = &mscc_gpio_ops,
169};
170
171int ocelot_pinctrl_probe(struct udevice *dev)
172{
173 int ret;
174
175 ret = mscc_pinctrl_probe(dev, FUNC_MAX, ocelot_pins,
176 ARRAY_SIZE(ocelot_pins),
Horatiu Vultur2d4fb842019-01-12 18:56:55 +0100177 ocelot_function_names,
178 ocelot_gpios);
Gregory CLEMENT2a626432018-12-08 09:59:01 +0100179
180 if (ret)
181 return ret;
182
Simon Glass6996c662020-11-28 17:50:03 -0700183 ret = device_bind(dev, &ocelot_gpio_driver, "ocelot-gpio", NULL,
184 dev_ofnode(dev), NULL);
Gregory CLEMENT2a626432018-12-08 09:59:01 +0100185
186 return ret;
187}
188
189static const struct udevice_id ocelot_pinctrl_of_match[] = {
190 {.compatible = "mscc,ocelot-pinctrl"},
191 {},
192};
193
194U_BOOT_DRIVER(ocelot_pinctrl) = {
195 .name = "ocelot-pinctrl",
196 .id = UCLASS_PINCTRL,
197 .of_match = of_match_ptr(ocelot_pinctrl_of_match),
198 .probe = ocelot_pinctrl_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700199 .priv_auto = sizeof(struct mscc_pinctrl),
Gregory CLEMENT2a626432018-12-08 09:59:01 +0100200 .ops = &mscc_pinctrl_ops,
201};