1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Marvell Berlin BG2CD pinctrl driver.
4  *
5  * Copyright (C) 2014 Marvell Technology Group Ltd.
6  *
7  * Antoine Ténart <antoine.tenart@free-electrons.com>
8  */
9 
10 #include <linux/init.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/property.h>
14 #include <linux/regmap.h>
15 
16 #include "berlin.h"
17 
18 static const struct berlin_desc_group berlin2cd_soc_pinctrl_groups[] = {
19 	/* G */
20 	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x3, 0x00,
21 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
22 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
23 		BERLIN_PINCTRL_FUNCTION(0x2, "led"),
24 		BERLIN_PINCTRL_FUNCTION(0x3, "pwm")),
25 	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x3, 0x03,
26 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
27 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
28 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
29 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
30 	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x3, 0x06,
31 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
32 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
33 		BERLIN_PINCTRL_FUNCTION(0x2, "fe"),
34 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
35 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
36 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
37 	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x3, 0x09,
38 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
39 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
40 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi2"),
41 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
42 		BERLIN_PINCTRL_FUNCTION(0x4, "fe"),
43 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
44 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
45 	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x3, 0x0c,
46 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
47 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
48 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
49 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
50 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
51 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
52 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
53 	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x0f,
54 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
55 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
56 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
57 		BERLIN_PINCTRL_FUNCTION(0x3, "arc"),
58 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
59 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
60 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
61 	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x3, 0x12,
62 		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
63 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
64 	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x15,
65 		BERLIN_PINCTRL_FUNCTION(0x0, "eddc"),
66 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
67 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio")),
68 	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x18,
69 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SS0n */
70 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
71 	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x1b,
72 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
73 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"), /* SS1n/SS2n */
74 		BERLIN_PINCTRL_FUNCTION(0x3, "twsi0")),
75 	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x1e,
76 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* CLK */
77 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
78 	BERLIN_PINCTRL_GROUP("G11", 0x04, 0x2, 0x00,
79 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SDI/SDO */
80 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
81 	BERLIN_PINCTRL_GROUP("G12", 0x04, 0x3, 0x02,
82 		BERLIN_PINCTRL_FUNCTION(0x0, "usb1"),
83 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
84 	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x05,
85 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
86 		BERLIN_PINCTRL_FUNCTION(0x1, "usb0_dbg"),
87 		BERLIN_PINCTRL_FUNCTION(0x2, "usb1_dbg")),
88 	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x08,
89 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
90 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
91 	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x3, 0x09,
92 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
93 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
94 	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x0c,
95 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
96 	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x0f,
97 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
98 	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x2, 0x12,
99 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
100 	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x2, 0x14,
101 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
102 	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x2, 0x16,
103 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
104 	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x18,
105 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
106 	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x1b,
107 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
108 	BERLIN_PINCTRL_GROUP("G23", 0x08, 0x3, 0x00,
109 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
110 	BERLIN_PINCTRL_GROUP("G24", 0x08, 0x2, 0x03,
111 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
112 	BERLIN_PINCTRL_GROUP("G25", 0x08, 0x2, 0x05,
113 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
114 	BERLIN_PINCTRL_GROUP("G26", 0x08, 0x1, 0x07,
115 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
116 	BERLIN_PINCTRL_GROUP("G27", 0x08, 0x2, 0x08,
117 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
118 	BERLIN_PINCTRL_GROUP("G28", 0x08, 0x3, 0x0a,
119 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
120 	BERLIN_PINCTRL_GROUP("G29", 0x08, 0x3, 0x0d,
121 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
122 };
123 
124 static const struct berlin_desc_group berlin2cd_sysmgr_pinctrl_groups[] = {
125 	/* GSM */
126 	BERLIN_PINCTRL_GROUP("GSM0", 0x40, 0x2, 0x00,
127 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
128 	BERLIN_PINCTRL_GROUP("GSM1", 0x40, 0x2, 0x02,
129 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
130 	BERLIN_PINCTRL_GROUP("GSM2", 0x40, 0x2, 0x04,
131 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
132 	BERLIN_PINCTRL_GROUP("GSM3", 0x40, 0x2, 0x06,
133 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
134 	BERLIN_PINCTRL_GROUP("GSM4", 0x40, 0x2, 0x08,
135 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
136 	BERLIN_PINCTRL_GROUP("GSM5", 0x40, 0x2, 0x0a,
137 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
138 	BERLIN_PINCTRL_GROUP("GSM6", 0x40, 0x2, 0x0c,
139 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
140 	BERLIN_PINCTRL_GROUP("GSM7", 0x40, 0x1, 0x0e,
141 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
142 	BERLIN_PINCTRL_GROUP("GSM8", 0x40, 0x1, 0x0f,
143 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
144 	BERLIN_PINCTRL_GROUP("GSM9", 0x40, 0x1, 0x10,
145 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
146 	BERLIN_PINCTRL_GROUP("GSM10", 0x40, 0x1, 0x11,
147 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
148 	BERLIN_PINCTRL_GROUP("GSM11", 0x40, 0x1, 0x12,
149 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
150 };
151 
152 static const struct berlin_pinctrl_desc berlin2cd_soc_pinctrl_data = {
153 	.groups = berlin2cd_soc_pinctrl_groups,
154 	.ngroups = ARRAY_SIZE(berlin2cd_soc_pinctrl_groups),
155 };
156 
157 static const struct berlin_pinctrl_desc berlin2cd_sysmgr_pinctrl_data = {
158 	.groups = berlin2cd_sysmgr_pinctrl_groups,
159 	.ngroups = ARRAY_SIZE(berlin2cd_sysmgr_pinctrl_groups),
160 };
161 
162 static const struct of_device_id berlin2cd_pinctrl_match[] = {
163 	{
164 		.compatible = "marvell,berlin2cd-soc-pinctrl",
165 		.data = &berlin2cd_soc_pinctrl_data
166 	},
167 	{
168 		.compatible = "marvell,berlin2cd-system-pinctrl",
169 		.data = &berlin2cd_sysmgr_pinctrl_data
170 	},
171 	{}
172 };
173 
berlin2cd_pinctrl_probe(struct platform_device * pdev)174 static int berlin2cd_pinctrl_probe(struct platform_device *pdev)
175 {
176 	return berlin_pinctrl_probe(pdev, device_get_match_data(&pdev->dev));
177 }
178 
179 static struct platform_driver berlin2cd_pinctrl_driver = {
180 	.probe	= berlin2cd_pinctrl_probe,
181 	.driver	= {
182 		.name = "berlin-bg2cd-pinctrl",
183 		.of_match_table = berlin2cd_pinctrl_match,
184 	},
185 };
186 builtin_platform_driver(berlin2cd_pinctrl_driver);
187