1 /*
2  * Marvell Berlin BG2CD pinctrl driver.
3  *
4  * Copyright (C) 2014 Marvell Technology Group Ltd.
5  *
6  * Antoine Ténart <antoine.tenart@free-electrons.com>
7  *
8  * This file is licensed under the terms of the GNU General Public
9  * License version 2. This program is licensed "as is" without any
10  * warranty of any kind, whether express or implied.
11  */
12 
13 #include <linux/module.h>
14 #include <linux/of_device.h>
15 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
17 
18 #include "berlin.h"
19 
20 static const struct berlin_desc_group berlin2cd_soc_pinctrl_groups[] = {
21 	/* G */
22 	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x1, 0x00,
23 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
24 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
25 		BERLIN_PINCTRL_FUNCTION(0x2, "led"),
26 		BERLIN_PINCTRL_FUNCTION(0x3, "pwm")),
27 	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x2, 0x01,
28 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
29 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
30 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
31 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
32 	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x2, 0x02,
33 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
34 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
35 		BERLIN_PINCTRL_FUNCTION(0x2, "fe"),
36 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
37 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
38 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
39 	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x2, 0x04,
40 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
41 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
42 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi2"),
43 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
44 		BERLIN_PINCTRL_FUNCTION(0x4, "fe"),
45 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
46 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
47 	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x2, 0x06,
48 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
49 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
50 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
51 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
52 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
53 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
54 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
55 	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x08,
56 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
57 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
58 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
59 		BERLIN_PINCTRL_FUNCTION(0x3, "arc"),
60 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
61 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
62 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
63 	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x2, 0x0b,
64 		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
65 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
66 	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x0d,
67 		BERLIN_PINCTRL_FUNCTION(0x0, "eddc"),
68 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
69 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio")),
70 	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x10,
71 		BERLIN_PINCTRL_FUNCTION(0x0, "ss0"),
72 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
73 	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x13,
74 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
75 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"),
76 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi0")),
77 	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x16,
78 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"),
79 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
80 	BERLIN_PINCTRL_GROUP("G11", 0x00, 0x2, 0x18,
81 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"),
82 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
83 	BERLIN_PINCTRL_GROUP("G12", 0x00, 0x3, 0x1a,
84 		BERLIN_PINCTRL_FUNCTION(0x0, "usb1"),
85 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
86 	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x00,
87 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
88 		BERLIN_PINCTRL_FUNCTION(0x1, "usb0_dbg"),
89 		BERLIN_PINCTRL_FUNCTION(0x2, "usb1_dbg")),
90 	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x03,
91 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
92 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
93 	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x2, 0x04,
94 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
95 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
96 	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x06,
97 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
98 	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x09,
99 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
100 	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x1, 0x0c,
101 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
102 	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x1, 0x0d,
103 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
104 	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x1, 0x0e,
105 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
106 	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x0f,
107 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
108 	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x12,
109 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
110 	BERLIN_PINCTRL_GROUP("G23", 0x04, 0x3, 0x15,
111 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
112 	BERLIN_PINCTRL_GROUP("G24", 0x04, 0x2, 0x18,
113 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
114 	BERLIN_PINCTRL_GROUP("G25", 0x04, 0x2, 0x1a,
115 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
116 	BERLIN_PINCTRL_GROUP("G26", 0x04, 0x1, 0x1c,
117 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
118 	BERLIN_PINCTRL_GROUP("G27", 0x04, 0x1, 0x1d,
119 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
120 	BERLIN_PINCTRL_GROUP("G28", 0x04, 0x2, 0x1e,
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-chip-ctrl",
165 		.data = &berlin2cd_soc_pinctrl_data
166 	},
167 	{
168 		.compatible = "marvell,berlin2cd-system-ctrl",
169 		.data = &berlin2cd_sysmgr_pinctrl_data
170 	},
171 	{}
172 };
173 MODULE_DEVICE_TABLE(of, berlin2cd_pinctrl_match);
174 
175 static int berlin2cd_pinctrl_probe(struct platform_device *pdev)
176 {
177 	const struct of_device_id *match =
178 		of_match_device(berlin2cd_pinctrl_match, &pdev->dev);
179 	struct regmap_config *rmconfig;
180 	struct regmap *regmap;
181 	struct resource *res;
182 	void __iomem *base;
183 
184 	rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL);
185 	if (!rmconfig)
186 		return -ENOMEM;
187 
188 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
189 	base = devm_ioremap_resource(&pdev->dev, res);
190 	if (IS_ERR(base))
191 		return PTR_ERR(base);
192 
193 	rmconfig->reg_bits = 32,
194 	rmconfig->val_bits = 32,
195 	rmconfig->reg_stride = 4,
196 	rmconfig->max_register = resource_size(res);
197 
198 	regmap = devm_regmap_init_mmio(&pdev->dev, base, rmconfig);
199 	if (IS_ERR(regmap))
200 		return PTR_ERR(regmap);
201 
202 	return berlin_pinctrl_probe(pdev, match->data);
203 }
204 
205 static struct platform_driver berlin2cd_pinctrl_driver = {
206 	.probe	= berlin2cd_pinctrl_probe,
207 	.driver	= {
208 		.name = "berlin-bg2cd-pinctrl",
209 		.owner = THIS_MODULE,
210 		.of_match_table = berlin2cd_pinctrl_match,
211 	},
212 };
213 module_platform_driver(berlin2cd_pinctrl_driver);
214 
215 MODULE_AUTHOR("Antoine Ténart <antoine.tenart@free-electrons.com>");
216 MODULE_DESCRIPTION("Marvell Berlin BG2CD pinctrl driver");
217 MODULE_LICENSE("GPL");
218