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