xref: /linux/drivers/pinctrl/mvebu/pinctrl-orion.c (revision 2874c5fd284268364ece81a7bd936f3c8168e567)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2fd67f884SThomas Petazzoni /*
3fd67f884SThomas Petazzoni  * Marvell Orion pinctrl driver based on mvebu pinctrl core
4fd67f884SThomas Petazzoni  *
5fd67f884SThomas Petazzoni  * Author: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
6fd67f884SThomas Petazzoni  *
7fd67f884SThomas Petazzoni  * The first 16 MPP pins on Orion are easy to handle: they are
8fd67f884SThomas Petazzoni  * configured through 2 consecutive registers, located at the base
9fd67f884SThomas Petazzoni  * address of the MPP device.
10fd67f884SThomas Petazzoni  *
11fd67f884SThomas Petazzoni  * However the last 4 MPP pins are handled by a register at offset
12fd67f884SThomas Petazzoni  * 0x50 from the base address, so it is not consecutive with the first
13fd67f884SThomas Petazzoni  * two registers.
14fd67f884SThomas Petazzoni  */
15fd67f884SThomas Petazzoni 
16fd67f884SThomas Petazzoni #include <linux/err.h>
17fd67f884SThomas Petazzoni #include <linux/init.h>
18fd67f884SThomas Petazzoni #include <linux/io.h>
19fd67f884SThomas Petazzoni #include <linux/platform_device.h>
20fd67f884SThomas Petazzoni #include <linux/clk.h>
21fd67f884SThomas Petazzoni #include <linux/of.h>
22fd67f884SThomas Petazzoni #include <linux/of_device.h>
23fd67f884SThomas Petazzoni #include <linux/pinctrl/pinctrl.h>
24fd67f884SThomas Petazzoni 
25fd67f884SThomas Petazzoni #include "pinctrl-mvebu.h"
26fd67f884SThomas Petazzoni 
27fd67f884SThomas Petazzoni static void __iomem *mpp_base;
28fd67f884SThomas Petazzoni static void __iomem *high_mpp_base;
29fd67f884SThomas Petazzoni 
3020955c5fSRussell King static int orion_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data,
3120955c5fSRussell King 			      unsigned pid, unsigned long *config)
32fd67f884SThomas Petazzoni {
33fd67f884SThomas Petazzoni 	unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
34fd67f884SThomas Petazzoni 
35fd67f884SThomas Petazzoni 	if (pid < 16) {
36fd67f884SThomas Petazzoni 		unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
37fd67f884SThomas Petazzoni 		*config = (readl(mpp_base + off) >> shift) & MVEBU_MPP_MASK;
38fd67f884SThomas Petazzoni 	}
39fd67f884SThomas Petazzoni 	else {
40fd67f884SThomas Petazzoni 		*config = (readl(high_mpp_base) >> shift) & MVEBU_MPP_MASK;
41fd67f884SThomas Petazzoni 	}
42fd67f884SThomas Petazzoni 
43fd67f884SThomas Petazzoni 	return 0;
44fd67f884SThomas Petazzoni }
45fd67f884SThomas Petazzoni 
4620955c5fSRussell King static int orion_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data,
4720955c5fSRussell King 			      unsigned pid, unsigned long config)
48fd67f884SThomas Petazzoni {
49fd67f884SThomas Petazzoni 	unsigned shift = (pid % MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
50fd67f884SThomas Petazzoni 
51fd67f884SThomas Petazzoni 	if (pid < 16) {
52fd67f884SThomas Petazzoni 		unsigned off = (pid / MVEBU_MPPS_PER_REG) * MVEBU_MPP_BITS;
53fd67f884SThomas Petazzoni 		u32 reg = readl(mpp_base + off) & ~(MVEBU_MPP_MASK << shift);
54fd67f884SThomas Petazzoni 		writel(reg | (config << shift), mpp_base + off);
55fd67f884SThomas Petazzoni 	}
56fd67f884SThomas Petazzoni 	else {
57fd67f884SThomas Petazzoni 		u32 reg = readl(high_mpp_base) & ~(MVEBU_MPP_MASK << shift);
58fd67f884SThomas Petazzoni 		writel(reg | (config << shift), high_mpp_base);
59fd67f884SThomas Petazzoni 	}
60fd67f884SThomas Petazzoni 
61fd67f884SThomas Petazzoni 	return 0;
62fd67f884SThomas Petazzoni }
63fd67f884SThomas Petazzoni 
64c336dc7dSJamie Lentin #define V(f5181, f5182, f5281) \
65c336dc7dSJamie Lentin 	((f5181 << 0) | (f5182 << 1) | (f5281 << 2))
66fd67f884SThomas Petazzoni 
67fd67f884SThomas Petazzoni enum orion_variant {
68c336dc7dSJamie Lentin 	V_5181  = V(1, 0, 0),
69fd67f884SThomas Petazzoni 	V_5182  = V(0, 1, 0),
70fd67f884SThomas Petazzoni 	V_5281  = V(0, 0, 1),
71fd67f884SThomas Petazzoni 	V_ALL   = V(1, 1, 1),
72fd67f884SThomas Petazzoni };
73fd67f884SThomas Petazzoni 
74fd67f884SThomas Petazzoni static struct mvebu_mpp_mode orion_mpp_modes[] = {
75fd67f884SThomas Petazzoni 	MPP_MODE(0,
76fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "pcie", "rstout",    V_ALL),
77fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "req2",       V_ALL),
78fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x3, "gpio", NULL,        V_ALL)),
79fd67f884SThomas Petazzoni 	MPP_MODE(1,
80fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
81fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "gnt2",       V_ALL)),
82fd67f884SThomas Petazzoni 	MPP_MODE(2,
83fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
84fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "req3",       V_ALL),
85fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x3, "pci-1", "pme",      V_ALL)),
86fd67f884SThomas Petazzoni 	MPP_MODE(3,
87fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
88fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "gnt3",       V_ALL)),
89fd67f884SThomas Petazzoni 	MPP_MODE(4,
90fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
91fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "req4",       V_ALL),
92fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "bootnand", "re",    V_5182 | V_5281),
93fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata0", "prsnt",    V_5182)),
94fd67f884SThomas Petazzoni 	MPP_MODE(5,
95fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
96fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "gnt4",       V_ALL),
97fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "bootnand", "we",    V_5182 | V_5281),
98fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata1", "prsnt",    V_5182)),
99fd67f884SThomas Petazzoni 	MPP_MODE(6,
100fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
101fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "req5",       V_ALL),
102fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "re0",       V_5182 | V_5281),
103c336dc7dSJamie Lentin 		 MPP_VAR_FUNCTION(0x5, "pci-1", "clk",      V_5181),
104fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata0", "act",      V_5182)),
105fd67f884SThomas Petazzoni 	MPP_MODE(7,
106fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
107fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x2, "pci", "gnt5",       V_ALL),
108fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "we0",       V_5182 | V_5281),
109c336dc7dSJamie Lentin 		 MPP_VAR_FUNCTION(0x5, "pci-1", "clk",      V_5181),
110fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata1", "act",      V_5182)),
111fd67f884SThomas Petazzoni 	MPP_MODE(8,
112fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
113fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "col",         V_ALL)),
114fd67f884SThomas Petazzoni 	MPP_MODE(9,
115fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
116fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "rxerr",       V_ALL)),
117fd67f884SThomas Petazzoni 	MPP_MODE(10,
118fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
119fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "crs",         V_ALL)),
120fd67f884SThomas Petazzoni 	MPP_MODE(11,
121fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
122fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "txerr",       V_ALL)),
123fd67f884SThomas Petazzoni 	MPP_MODE(12,
124fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
125fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "txd4",        V_ALL),
126fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "re1",       V_5182 | V_5281),
127fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata0", "ledprsnt", V_5182)),
128fd67f884SThomas Petazzoni 	MPP_MODE(13,
129fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
130fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "txd5",        V_ALL),
131fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "we1",       V_5182 | V_5281),
132fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata1", "ledprsnt", V_5182)),
133fd67f884SThomas Petazzoni 	MPP_MODE(14,
134fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
135fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "txd6",        V_ALL),
136fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "re2",       V_5182 | V_5281),
137fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata0", "ledact",   V_5182)),
138fd67f884SThomas Petazzoni 	MPP_MODE(15,
139fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "gpio", NULL,        V_ALL),
140fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "txd7",        V_ALL),
141fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x4, "nand", "we2",       V_5182 | V_5281),
142fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "sata1", "ledact",   V_5182)),
143fd67f884SThomas Petazzoni 	MPP_MODE(16,
144fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "uart1", "rxd",      V_5182 | V_5281),
145fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "rxd4",        V_ALL),
146fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "gpio", NULL,        V_5182)),
147fd67f884SThomas Petazzoni 	MPP_MODE(17,
148fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "uart1", "txd",      V_5182 | V_5281),
149fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "rxd5",        V_ALL),
150fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "gpio", NULL,        V_5182)),
151fd67f884SThomas Petazzoni 	MPP_MODE(18,
152fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "uart1", "cts",      V_5182 | V_5281),
153fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "rxd6",        V_ALL),
154fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "gpio", NULL,        V_5182)),
155fd67f884SThomas Petazzoni 	MPP_MODE(19,
156fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x0, "uart1", "rts",      V_5182 | V_5281),
157fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x1, "ge", "rxd7",        V_ALL),
158fd67f884SThomas Petazzoni 		 MPP_VAR_FUNCTION(0x5, "gpio", NULL,        V_5182)),
159fd67f884SThomas Petazzoni };
160fd67f884SThomas Petazzoni 
16130be3fb9SRussell King static const struct mvebu_mpp_ctrl orion_mpp_controls[] = {
162fd67f884SThomas Petazzoni 	MPP_FUNC_CTRL(0, 19, NULL, orion_mpp_ctrl),
163fd67f884SThomas Petazzoni };
164fd67f884SThomas Petazzoni 
165c336dc7dSJamie Lentin static struct pinctrl_gpio_range mv88f5181_gpio_ranges[] = {
166fd67f884SThomas Petazzoni 	MPP_GPIO_RANGE(0, 0, 0, 16),
167fd67f884SThomas Petazzoni };
168fd67f884SThomas Petazzoni 
169fd67f884SThomas Petazzoni static struct pinctrl_gpio_range mv88f5182_gpio_ranges[] = {
170fd67f884SThomas Petazzoni 	MPP_GPIO_RANGE(0, 0, 0, 19),
171fd67f884SThomas Petazzoni };
172fd67f884SThomas Petazzoni 
173fd67f884SThomas Petazzoni static struct pinctrl_gpio_range mv88f5281_gpio_ranges[] = {
174fd67f884SThomas Petazzoni 	MPP_GPIO_RANGE(0, 0, 0, 16),
175fd67f884SThomas Petazzoni };
176fd67f884SThomas Petazzoni 
177c336dc7dSJamie Lentin static struct mvebu_pinctrl_soc_info mv88f5181_info = {
178c336dc7dSJamie Lentin 	.variant = V_5181,
179fd67f884SThomas Petazzoni 	.controls = orion_mpp_controls,
180fd67f884SThomas Petazzoni 	.ncontrols = ARRAY_SIZE(orion_mpp_controls),
181fd67f884SThomas Petazzoni 	.modes = orion_mpp_modes,
182fd67f884SThomas Petazzoni 	.nmodes = ARRAY_SIZE(orion_mpp_modes),
183c336dc7dSJamie Lentin 	.gpioranges = mv88f5181_gpio_ranges,
184c336dc7dSJamie Lentin 	.ngpioranges = ARRAY_SIZE(mv88f5181_gpio_ranges),
185fd67f884SThomas Petazzoni };
186fd67f884SThomas Petazzoni 
187fd67f884SThomas Petazzoni static struct mvebu_pinctrl_soc_info mv88f5182_info = {
188fd67f884SThomas Petazzoni 	.variant = V_5182,
189fd67f884SThomas Petazzoni 	.controls = orion_mpp_controls,
190fd67f884SThomas Petazzoni 	.ncontrols = ARRAY_SIZE(orion_mpp_controls),
191fd67f884SThomas Petazzoni 	.modes = orion_mpp_modes,
192fd67f884SThomas Petazzoni 	.nmodes = ARRAY_SIZE(orion_mpp_modes),
193fd67f884SThomas Petazzoni 	.gpioranges = mv88f5182_gpio_ranges,
194fd67f884SThomas Petazzoni 	.ngpioranges = ARRAY_SIZE(mv88f5182_gpio_ranges),
195fd67f884SThomas Petazzoni };
196fd67f884SThomas Petazzoni 
197fd67f884SThomas Petazzoni static struct mvebu_pinctrl_soc_info mv88f5281_info = {
198fd67f884SThomas Petazzoni 	.variant = V_5281,
199fd67f884SThomas Petazzoni 	.controls = orion_mpp_controls,
200fd67f884SThomas Petazzoni 	.ncontrols = ARRAY_SIZE(orion_mpp_controls),
201fd67f884SThomas Petazzoni 	.modes = orion_mpp_modes,
202fd67f884SThomas Petazzoni 	.nmodes = ARRAY_SIZE(orion_mpp_modes),
203fd67f884SThomas Petazzoni 	.gpioranges = mv88f5281_gpio_ranges,
204fd67f884SThomas Petazzoni 	.ngpioranges = ARRAY_SIZE(mv88f5281_gpio_ranges),
205fd67f884SThomas Petazzoni };
206fd67f884SThomas Petazzoni 
207fd67f884SThomas Petazzoni /*
208fd67f884SThomas Petazzoni  * There are multiple variants of the Orion SoCs, but in terms of pin
209fd67f884SThomas Petazzoni  * muxing, they are identical.
210fd67f884SThomas Petazzoni  */
211baa9946eSFabian Frederick static const struct of_device_id orion_pinctrl_of_match[] = {
212c336dc7dSJamie Lentin 	{ .compatible = "marvell,88f5181-pinctrl", .data = &mv88f5181_info },
213c336dc7dSJamie Lentin 	{ .compatible = "marvell,88f5181l-pinctrl", .data = &mv88f5181_info },
214fd67f884SThomas Petazzoni 	{ .compatible = "marvell,88f5182-pinctrl", .data = &mv88f5182_info },
215fd67f884SThomas Petazzoni 	{ .compatible = "marvell,88f5281-pinctrl", .data = &mv88f5281_info },
216fd67f884SThomas Petazzoni 	{ }
217fd67f884SThomas Petazzoni };
218fd67f884SThomas Petazzoni 
219fd67f884SThomas Petazzoni static int orion_pinctrl_probe(struct platform_device *pdev)
220fd67f884SThomas Petazzoni {
221fd67f884SThomas Petazzoni 	const struct of_device_id *match =
222fd67f884SThomas Petazzoni 		of_match_device(orion_pinctrl_of_match, &pdev->dev);
223fd67f884SThomas Petazzoni 	struct resource *res;
224fd67f884SThomas Petazzoni 
225fd67f884SThomas Petazzoni 	pdev->dev.platform_data = (void*)match->data;
226fd67f884SThomas Petazzoni 
227fd67f884SThomas Petazzoni 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
228fd67f884SThomas Petazzoni 	mpp_base = devm_ioremap_resource(&pdev->dev, res);
229fd67f884SThomas Petazzoni 	if (IS_ERR(mpp_base))
230fd67f884SThomas Petazzoni 		return PTR_ERR(mpp_base);
231fd67f884SThomas Petazzoni 
232fd67f884SThomas Petazzoni 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
233fd67f884SThomas Petazzoni 	high_mpp_base = devm_ioremap_resource(&pdev->dev, res);
234fd67f884SThomas Petazzoni 	if (IS_ERR(high_mpp_base))
235fd67f884SThomas Petazzoni 		return PTR_ERR(high_mpp_base);
236fd67f884SThomas Petazzoni 
237fd67f884SThomas Petazzoni 	return mvebu_pinctrl_probe(pdev);
238fd67f884SThomas Petazzoni }
239fd67f884SThomas Petazzoni 
240fd67f884SThomas Petazzoni static struct platform_driver orion_pinctrl_driver = {
241fd67f884SThomas Petazzoni 	.driver = {
242fd67f884SThomas Petazzoni 		.name = "orion-pinctrl",
243fd67f884SThomas Petazzoni 		.of_match_table = of_match_ptr(orion_pinctrl_of_match),
244fd67f884SThomas Petazzoni 	},
245fd67f884SThomas Petazzoni 	.probe = orion_pinctrl_probe,
246fd67f884SThomas Petazzoni };
247fdbde81bSPaul Gortmaker builtin_platform_driver(orion_pinctrl_driver);
248