ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / bcm4908 / patches-5.10 / 085-v5.18-0002-pinctrl-bcm-add-driver-for-BCM4908-pinmux.patch
1 From f7e322d99f1180270fb4a3e1ae992b3116cfcf34 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Mon, 24 Jan 2022 11:22:43 +0100
4 Subject: [PATCH] pinctrl: bcm: add driver for BCM4908 pinmux
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 BCM4908 has its own pins layout so it needs a custom binding and a Linux
10 driver.
11
12 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
13 Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
14 Link: https://lore.kernel.org/r/20220124102243.14912-2-zajec5@gmail.com
15 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
16 ---
17 MAINTAINERS | 1 +
18 drivers/pinctrl/bcm/Kconfig | 14 +
19 drivers/pinctrl/bcm/Makefile | 1 +
20 drivers/pinctrl/bcm/pinctrl-bcm4908.c | 563 ++++++++++++++++++++++++++
21 4 files changed, 579 insertions(+)
22 create mode 100644 drivers/pinctrl/bcm/pinctrl-bcm4908.c
23
24 --- a/MAINTAINERS
25 +++ b/MAINTAINERS
26 @@ -3442,6 +3442,7 @@ M: bcm-kernel-feedback-list@broadcom.com
27 L: linux-gpio@vger.kernel.org
28 S: Maintained
29 F: Documentation/devicetree/bindings/pinctrl/brcm,bcm4908-pinctrl.yaml
30 +F: drivers/pinctrl/bcm/pinctrl-bcm4908.c
31
32 BROADCOM BCM5301X ARM ARCHITECTURE
33 M: Hauke Mehrtens <hauke@hauke-m.de>
34 --- a/drivers/pinctrl/bcm/Kconfig
35 +++ b/drivers/pinctrl/bcm/Kconfig
36 @@ -29,6 +29,20 @@ config PINCTRL_BCM2835
37 help
38 Say Y here to enable the Broadcom BCM2835 GPIO driver.
39
40 +config PINCTRL_BCM4908
41 + tristate "Broadcom BCM4908 pinmux driver"
42 + depends on OF && (ARCH_BCM4908 || COMPILE_TEST)
43 + select PINMUX
44 + select PINCONF
45 + select GENERIC_PINCONF
46 + select GENERIC_PINCTRL_GROUPS
47 + select GENERIC_PINMUX_FUNCTIONS
48 + default ARCH_BCM4908
49 + help
50 + Driver for BCM4908 family SoCs with integrated pin controller.
51 +
52 + If compiled as module it will be called pinctrl-bcm4908.
53 +
54 config PINCTRL_IPROC_GPIO
55 bool "Broadcom iProc GPIO (with PINCONF) driver"
56 depends on OF_GPIO && (ARCH_BCM_IPROC || COMPILE_TEST)
57 --- a/drivers/pinctrl/bcm/Makefile
58 +++ b/drivers/pinctrl/bcm/Makefile
59 @@ -3,6 +3,7 @@
60
61 obj-$(CONFIG_PINCTRL_BCM281XX) += pinctrl-bcm281xx.o
62 obj-$(CONFIG_PINCTRL_BCM2835) += pinctrl-bcm2835.o
63 +obj-$(CONFIG_PINCTRL_BCM4908) += pinctrl-bcm4908.o
64 obj-$(CONFIG_PINCTRL_IPROC_GPIO) += pinctrl-iproc-gpio.o
65 obj-$(CONFIG_PINCTRL_CYGNUS_MUX) += pinctrl-cygnus-mux.o
66 obj-$(CONFIG_PINCTRL_NS) += pinctrl-ns.o
67 --- /dev/null
68 +++ b/drivers/pinctrl/bcm/pinctrl-bcm4908.c
69 @@ -0,0 +1,560 @@
70 +// SPDX-License-Identifier: GPL-2.0
71 +/* Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl> */
72 +
73 +#include <linux/err.h>
74 +#include <linux/io.h>
75 +#include <linux/mod_devicetable.h>
76 +#include <linux/module.h>
77 +#include <linux/pinctrl/pinconf-generic.h>
78 +#include <linux/pinctrl/pinctrl.h>
79 +#include <linux/pinctrl/pinmux.h>
80 +#include <linux/platform_device.h>
81 +#include <linux/slab.h>
82 +#include <linux/string_helpers.h>
83 +
84 +#include "../core.h"
85 +#include "../pinmux.h"
86 +
87 +#define BCM4908_NUM_PINS 86
88 +
89 +#define BCM4908_TEST_PORT_BLOCK_EN_LSB 0x00
90 +#define BCM4908_TEST_PORT_BLOCK_DATA_MSB 0x04
91 +#define BCM4908_TEST_PORT_BLOCK_DATA_LSB 0x08
92 +#define BCM4908_TEST_PORT_LSB_PINMUX_DATA_SHIFT 12
93 +#define BCM4908_TEST_PORT_COMMAND 0x0c
94 +#define BCM4908_TEST_PORT_CMD_LOAD_MUX_REG 0x00000021
95 +
96 +struct bcm4908_pinctrl {
97 + struct device *dev;
98 + void __iomem *base;
99 + struct mutex mutex;
100 + struct pinctrl_dev *pctldev;
101 + struct pinctrl_desc pctldesc;
102 +};
103 +
104 +/*
105 + * Groups
106 + */
107 +
108 +struct bcm4908_pinctrl_pin_setup {
109 + unsigned int number;
110 + unsigned int function;
111 +};
112 +
113 +static const struct bcm4908_pinctrl_pin_setup led_0_pins_a[] = {
114 + { 0, 3 },
115 +};
116 +
117 +static const struct bcm4908_pinctrl_pin_setup led_1_pins_a[] = {
118 + { 1, 3 },
119 +};
120 +
121 +static const struct bcm4908_pinctrl_pin_setup led_2_pins_a[] = {
122 + { 2, 3 },
123 +};
124 +
125 +static const struct bcm4908_pinctrl_pin_setup led_3_pins_a[] = {
126 + { 3, 3 },
127 +};
128 +
129 +static const struct bcm4908_pinctrl_pin_setup led_4_pins_a[] = {
130 + { 4, 3 },
131 +};
132 +
133 +static const struct bcm4908_pinctrl_pin_setup led_5_pins_a[] = {
134 + { 5, 3 },
135 +};
136 +
137 +static const struct bcm4908_pinctrl_pin_setup led_6_pins_a[] = {
138 + { 6, 3 },
139 +};
140 +
141 +static const struct bcm4908_pinctrl_pin_setup led_7_pins_a[] = {
142 + { 7, 3 },
143 +};
144 +
145 +static const struct bcm4908_pinctrl_pin_setup led_8_pins_a[] = {
146 + { 8, 3 },
147 +};
148 +
149 +static const struct bcm4908_pinctrl_pin_setup led_9_pins_a[] = {
150 + { 9, 3 },
151 +};
152 +
153 +static const struct bcm4908_pinctrl_pin_setup led_10_pins_a[] = {
154 + { 10, 3 },
155 +};
156 +
157 +static const struct bcm4908_pinctrl_pin_setup led_11_pins_a[] = {
158 + { 11, 3 },
159 +};
160 +
161 +static const struct bcm4908_pinctrl_pin_setup led_12_pins_a[] = {
162 + { 12, 3 },
163 +};
164 +
165 +static const struct bcm4908_pinctrl_pin_setup led_13_pins_a[] = {
166 + { 13, 3 },
167 +};
168 +
169 +static const struct bcm4908_pinctrl_pin_setup led_14_pins_a[] = {
170 + { 14, 3 },
171 +};
172 +
173 +static const struct bcm4908_pinctrl_pin_setup led_15_pins_a[] = {
174 + { 15, 3 },
175 +};
176 +
177 +static const struct bcm4908_pinctrl_pin_setup led_16_pins_a[] = {
178 + { 16, 3 },
179 +};
180 +
181 +static const struct bcm4908_pinctrl_pin_setup led_17_pins_a[] = {
182 + { 17, 3 },
183 +};
184 +
185 +static const struct bcm4908_pinctrl_pin_setup led_18_pins_a[] = {
186 + { 18, 3 },
187 +};
188 +
189 +static const struct bcm4908_pinctrl_pin_setup led_19_pins_a[] = {
190 + { 19, 3 },
191 +};
192 +
193 +static const struct bcm4908_pinctrl_pin_setup led_20_pins_a[] = {
194 + { 20, 3 },
195 +};
196 +
197 +static const struct bcm4908_pinctrl_pin_setup led_21_pins_a[] = {
198 + { 21, 3 },
199 +};
200 +
201 +static const struct bcm4908_pinctrl_pin_setup led_22_pins_a[] = {
202 + { 22, 3 },
203 +};
204 +
205 +static const struct bcm4908_pinctrl_pin_setup led_23_pins_a[] = {
206 + { 23, 3 },
207 +};
208 +
209 +static const struct bcm4908_pinctrl_pin_setup led_24_pins_a[] = {
210 + { 24, 3 },
211 +};
212 +
213 +static const struct bcm4908_pinctrl_pin_setup led_25_pins_a[] = {
214 + { 25, 3 },
215 +};
216 +
217 +static const struct bcm4908_pinctrl_pin_setup led_26_pins_a[] = {
218 + { 26, 3 },
219 +};
220 +
221 +static const struct bcm4908_pinctrl_pin_setup led_27_pins_a[] = {
222 + { 27, 3 },
223 +};
224 +
225 +static const struct bcm4908_pinctrl_pin_setup led_28_pins_a[] = {
226 + { 28, 3 },
227 +};
228 +
229 +static const struct bcm4908_pinctrl_pin_setup led_29_pins_a[] = {
230 + { 29, 3 },
231 +};
232 +
233 +static const struct bcm4908_pinctrl_pin_setup led_30_pins_a[] = {
234 + { 30, 3 },
235 +};
236 +
237 +static const struct bcm4908_pinctrl_pin_setup led_31_pins_a[] = {
238 + { 31, 3 },
239 +};
240 +
241 +static const struct bcm4908_pinctrl_pin_setup led_10_pins_b[] = {
242 + { 8, 2 },
243 +};
244 +
245 +static const struct bcm4908_pinctrl_pin_setup led_11_pins_b[] = {
246 + { 9, 2 },
247 +};
248 +
249 +static const struct bcm4908_pinctrl_pin_setup led_12_pins_b[] = {
250 + { 0, 2 },
251 +};
252 +
253 +static const struct bcm4908_pinctrl_pin_setup led_13_pins_b[] = {
254 + { 1, 2 },
255 +};
256 +
257 +static const struct bcm4908_pinctrl_pin_setup led_31_pins_b[] = {
258 + { 30, 2 },
259 +};
260 +
261 +static const struct bcm4908_pinctrl_pin_setup hs_uart_pins[] = {
262 + { 10, 0 }, /* CTS */
263 + { 11, 0 }, /* RTS */
264 + { 12, 0 }, /* RXD */
265 + { 13, 0 }, /* TXD */
266 +};
267 +
268 +static const struct bcm4908_pinctrl_pin_setup i2c_pins_a[] = {
269 + { 18, 0 }, /* SDA */
270 + { 19, 0 }, /* SCL */
271 +};
272 +
273 +static const struct bcm4908_pinctrl_pin_setup i2c_pins_b[] = {
274 + { 22, 0 }, /* SDA */
275 + { 23, 0 }, /* SCL */
276 +};
277 +
278 +static const struct bcm4908_pinctrl_pin_setup i2s_pins[] = {
279 + { 27, 0 }, /* MCLK */
280 + { 28, 0 }, /* LRCK */
281 + { 29, 0 }, /* SDATA */
282 + { 30, 0 }, /* SCLK */
283 +};
284 +
285 +static const struct bcm4908_pinctrl_pin_setup nand_ctrl_pins[] = {
286 + { 32, 0 },
287 + { 33, 0 },
288 + { 34, 0 },
289 + { 43, 0 },
290 + { 44, 0 },
291 + { 45, 0 },
292 + { 56, 1 },
293 +};
294 +
295 +static const struct bcm4908_pinctrl_pin_setup nand_data_pins[] = {
296 + { 35, 0 },
297 + { 36, 0 },
298 + { 37, 0 },
299 + { 38, 0 },
300 + { 39, 0 },
301 + { 40, 0 },
302 + { 41, 0 },
303 + { 42, 0 },
304 +};
305 +
306 +static const struct bcm4908_pinctrl_pin_setup emmc_ctrl_pins[] = {
307 + { 46, 0 },
308 + { 47, 0 },
309 +};
310 +
311 +static const struct bcm4908_pinctrl_pin_setup usb0_pwr_pins[] = {
312 + { 63, 0 },
313 + { 64, 0 },
314 +};
315 +
316 +static const struct bcm4908_pinctrl_pin_setup usb1_pwr_pins[] = {
317 + { 66, 0 },
318 + { 67, 0 },
319 +};
320 +
321 +struct bcm4908_pinctrl_grp {
322 + const char *name;
323 + const struct bcm4908_pinctrl_pin_setup *pins;
324 + const unsigned int num_pins;
325 +};
326 +
327 +static const struct bcm4908_pinctrl_grp bcm4908_pinctrl_grps[] = {
328 + { "led_0_grp_a", led_0_pins_a, ARRAY_SIZE(led_0_pins_a) },
329 + { "led_1_grp_a", led_1_pins_a, ARRAY_SIZE(led_1_pins_a) },
330 + { "led_2_grp_a", led_2_pins_a, ARRAY_SIZE(led_2_pins_a) },
331 + { "led_3_grp_a", led_3_pins_a, ARRAY_SIZE(led_3_pins_a) },
332 + { "led_4_grp_a", led_4_pins_a, ARRAY_SIZE(led_4_pins_a) },
333 + { "led_5_grp_a", led_5_pins_a, ARRAY_SIZE(led_5_pins_a) },
334 + { "led_6_grp_a", led_6_pins_a, ARRAY_SIZE(led_6_pins_a) },
335 + { "led_7_grp_a", led_7_pins_a, ARRAY_SIZE(led_7_pins_a) },
336 + { "led_8_grp_a", led_8_pins_a, ARRAY_SIZE(led_8_pins_a) },
337 + { "led_9_grp_a", led_9_pins_a, ARRAY_SIZE(led_9_pins_a) },
338 + { "led_10_grp_a", led_10_pins_a, ARRAY_SIZE(led_10_pins_a) },
339 + { "led_11_grp_a", led_11_pins_a, ARRAY_SIZE(led_11_pins_a) },
340 + { "led_12_grp_a", led_12_pins_a, ARRAY_SIZE(led_12_pins_a) },
341 + { "led_13_grp_a", led_13_pins_a, ARRAY_SIZE(led_13_pins_a) },
342 + { "led_14_grp_a", led_14_pins_a, ARRAY_SIZE(led_14_pins_a) },
343 + { "led_15_grp_a", led_15_pins_a, ARRAY_SIZE(led_15_pins_a) },
344 + { "led_16_grp_a", led_16_pins_a, ARRAY_SIZE(led_16_pins_a) },
345 + { "led_17_grp_a", led_17_pins_a, ARRAY_SIZE(led_17_pins_a) },
346 + { "led_18_grp_a", led_18_pins_a, ARRAY_SIZE(led_18_pins_a) },
347 + { "led_19_grp_a", led_19_pins_a, ARRAY_SIZE(led_19_pins_a) },
348 + { "led_20_grp_a", led_20_pins_a, ARRAY_SIZE(led_20_pins_a) },
349 + { "led_21_grp_a", led_21_pins_a, ARRAY_SIZE(led_21_pins_a) },
350 + { "led_22_grp_a", led_22_pins_a, ARRAY_SIZE(led_22_pins_a) },
351 + { "led_23_grp_a", led_23_pins_a, ARRAY_SIZE(led_23_pins_a) },
352 + { "led_24_grp_a", led_24_pins_a, ARRAY_SIZE(led_24_pins_a) },
353 + { "led_25_grp_a", led_25_pins_a, ARRAY_SIZE(led_25_pins_a) },
354 + { "led_26_grp_a", led_26_pins_a, ARRAY_SIZE(led_26_pins_a) },
355 + { "led_27_grp_a", led_27_pins_a, ARRAY_SIZE(led_27_pins_a) },
356 + { "led_28_grp_a", led_28_pins_a, ARRAY_SIZE(led_28_pins_a) },
357 + { "led_29_grp_a", led_29_pins_a, ARRAY_SIZE(led_29_pins_a) },
358 + { "led_30_grp_a", led_30_pins_a, ARRAY_SIZE(led_30_pins_a) },
359 + { "led_31_grp_a", led_31_pins_a, ARRAY_SIZE(led_31_pins_a) },
360 + { "led_10_grp_b", led_10_pins_b, ARRAY_SIZE(led_10_pins_b) },
361 + { "led_11_grp_b", led_11_pins_b, ARRAY_SIZE(led_11_pins_b) },
362 + { "led_12_grp_b", led_12_pins_b, ARRAY_SIZE(led_12_pins_b) },
363 + { "led_13_grp_b", led_13_pins_b, ARRAY_SIZE(led_13_pins_b) },
364 + { "led_31_grp_b", led_31_pins_b, ARRAY_SIZE(led_31_pins_b) },
365 + { "hs_uart_grp", hs_uart_pins, ARRAY_SIZE(hs_uart_pins) },
366 + { "i2c_grp_a", i2c_pins_a, ARRAY_SIZE(i2c_pins_a) },
367 + { "i2c_grp_b", i2c_pins_b, ARRAY_SIZE(i2c_pins_b) },
368 + { "i2s_grp", i2s_pins, ARRAY_SIZE(i2s_pins) },
369 + { "nand_ctrl_grp", nand_ctrl_pins, ARRAY_SIZE(nand_ctrl_pins) },
370 + { "nand_data_grp", nand_data_pins, ARRAY_SIZE(nand_data_pins) },
371 + { "emmc_ctrl_grp", emmc_ctrl_pins, ARRAY_SIZE(emmc_ctrl_pins) },
372 + { "usb0_pwr_grp", usb0_pwr_pins, ARRAY_SIZE(usb0_pwr_pins) },
373 + { "usb1_pwr_grp", usb1_pwr_pins, ARRAY_SIZE(usb1_pwr_pins) },
374 +};
375 +
376 +/*
377 + * Functions
378 + */
379 +
380 +struct bcm4908_pinctrl_function {
381 + const char *name;
382 + const char * const *groups;
383 + const unsigned int num_groups;
384 +};
385 +
386 +static const char * const led_0_groups[] = { "led_0_grp_a" };
387 +static const char * const led_1_groups[] = { "led_1_grp_a" };
388 +static const char * const led_2_groups[] = { "led_2_grp_a" };
389 +static const char * const led_3_groups[] = { "led_3_grp_a" };
390 +static const char * const led_4_groups[] = { "led_4_grp_a" };
391 +static const char * const led_5_groups[] = { "led_5_grp_a" };
392 +static const char * const led_6_groups[] = { "led_6_grp_a" };
393 +static const char * const led_7_groups[] = { "led_7_grp_a" };
394 +static const char * const led_8_groups[] = { "led_8_grp_a" };
395 +static const char * const led_9_groups[] = { "led_9_grp_a" };
396 +static const char * const led_10_groups[] = { "led_10_grp_a", "led_10_grp_b" };
397 +static const char * const led_11_groups[] = { "led_11_grp_a", "led_11_grp_b" };
398 +static const char * const led_12_groups[] = { "led_12_grp_a", "led_12_grp_b" };
399 +static const char * const led_13_groups[] = { "led_13_grp_a", "led_13_grp_b" };
400 +static const char * const led_14_groups[] = { "led_14_grp_a" };
401 +static const char * const led_15_groups[] = { "led_15_grp_a" };
402 +static const char * const led_16_groups[] = { "led_16_grp_a" };
403 +static const char * const led_17_groups[] = { "led_17_grp_a" };
404 +static const char * const led_18_groups[] = { "led_18_grp_a" };
405 +static const char * const led_19_groups[] = { "led_19_grp_a" };
406 +static const char * const led_20_groups[] = { "led_20_grp_a" };
407 +static const char * const led_21_groups[] = { "led_21_grp_a" };
408 +static const char * const led_22_groups[] = { "led_22_grp_a" };
409 +static const char * const led_23_groups[] = { "led_23_grp_a" };
410 +static const char * const led_24_groups[] = { "led_24_grp_a" };
411 +static const char * const led_25_groups[] = { "led_25_grp_a" };
412 +static const char * const led_26_groups[] = { "led_26_grp_a" };
413 +static const char * const led_27_groups[] = { "led_27_grp_a" };
414 +static const char * const led_28_groups[] = { "led_28_grp_a" };
415 +static const char * const led_29_groups[] = { "led_29_grp_a" };
416 +static const char * const led_30_groups[] = { "led_30_grp_a" };
417 +static const char * const led_31_groups[] = { "led_31_grp_a", "led_31_grp_b" };
418 +static const char * const hs_uart_groups[] = { "hs_uart_grp" };
419 +static const char * const i2c_groups[] = { "i2c_grp_a", "i2c_grp_b" };
420 +static const char * const i2s_groups[] = { "i2s_grp" };
421 +static const char * const nand_ctrl_groups[] = { "nand_ctrl_grp" };
422 +static const char * const nand_data_groups[] = { "nand_data_grp" };
423 +static const char * const emmc_ctrl_groups[] = { "emmc_ctrl_grp" };
424 +static const char * const usb0_pwr_groups[] = { "usb0_pwr_grp" };
425 +static const char * const usb1_pwr_groups[] = { "usb1_pwr_grp" };
426 +
427 +static const struct bcm4908_pinctrl_function bcm4908_pinctrl_functions[] = {
428 + { "led_0", led_0_groups, ARRAY_SIZE(led_0_groups) },
429 + { "led_1", led_1_groups, ARRAY_SIZE(led_1_groups) },
430 + { "led_2", led_2_groups, ARRAY_SIZE(led_2_groups) },
431 + { "led_3", led_3_groups, ARRAY_SIZE(led_3_groups) },
432 + { "led_4", led_4_groups, ARRAY_SIZE(led_4_groups) },
433 + { "led_5", led_5_groups, ARRAY_SIZE(led_5_groups) },
434 + { "led_6", led_6_groups, ARRAY_SIZE(led_6_groups) },
435 + { "led_7", led_7_groups, ARRAY_SIZE(led_7_groups) },
436 + { "led_8", led_8_groups, ARRAY_SIZE(led_8_groups) },
437 + { "led_9", led_9_groups, ARRAY_SIZE(led_9_groups) },
438 + { "led_10", led_10_groups, ARRAY_SIZE(led_10_groups) },
439 + { "led_11", led_11_groups, ARRAY_SIZE(led_11_groups) },
440 + { "led_12", led_12_groups, ARRAY_SIZE(led_12_groups) },
441 + { "led_13", led_13_groups, ARRAY_SIZE(led_13_groups) },
442 + { "led_14", led_14_groups, ARRAY_SIZE(led_14_groups) },
443 + { "led_15", led_15_groups, ARRAY_SIZE(led_15_groups) },
444 + { "led_16", led_16_groups, ARRAY_SIZE(led_16_groups) },
445 + { "led_17", led_17_groups, ARRAY_SIZE(led_17_groups) },
446 + { "led_18", led_18_groups, ARRAY_SIZE(led_18_groups) },
447 + { "led_19", led_19_groups, ARRAY_SIZE(led_19_groups) },
448 + { "led_20", led_20_groups, ARRAY_SIZE(led_20_groups) },
449 + { "led_21", led_21_groups, ARRAY_SIZE(led_21_groups) },
450 + { "led_22", led_22_groups, ARRAY_SIZE(led_22_groups) },
451 + { "led_23", led_23_groups, ARRAY_SIZE(led_23_groups) },
452 + { "led_24", led_24_groups, ARRAY_SIZE(led_24_groups) },
453 + { "led_25", led_25_groups, ARRAY_SIZE(led_25_groups) },
454 + { "led_26", led_26_groups, ARRAY_SIZE(led_26_groups) },
455 + { "led_27", led_27_groups, ARRAY_SIZE(led_27_groups) },
456 + { "led_28", led_28_groups, ARRAY_SIZE(led_28_groups) },
457 + { "led_29", led_29_groups, ARRAY_SIZE(led_29_groups) },
458 + { "led_30", led_30_groups, ARRAY_SIZE(led_30_groups) },
459 + { "led_31", led_31_groups, ARRAY_SIZE(led_31_groups) },
460 + { "hs_uart", hs_uart_groups, ARRAY_SIZE(hs_uart_groups) },
461 + { "i2c", i2c_groups, ARRAY_SIZE(i2c_groups) },
462 + { "i2s", i2s_groups, ARRAY_SIZE(i2s_groups) },
463 + { "nand_ctrl", nand_ctrl_groups, ARRAY_SIZE(nand_ctrl_groups) },
464 + { "nand_data", nand_data_groups, ARRAY_SIZE(nand_data_groups) },
465 + { "emmc_ctrl", emmc_ctrl_groups, ARRAY_SIZE(emmc_ctrl_groups) },
466 + { "usb0_pwr", usb0_pwr_groups, ARRAY_SIZE(usb0_pwr_groups) },
467 + { "usb1_pwr", usb1_pwr_groups, ARRAY_SIZE(usb1_pwr_groups) },
468 +};
469 +
470 +/*
471 + * Groups code
472 + */
473 +
474 +static const struct pinctrl_ops bcm4908_pinctrl_ops = {
475 + .get_groups_count = pinctrl_generic_get_group_count,
476 + .get_group_name = pinctrl_generic_get_group_name,
477 + .get_group_pins = pinctrl_generic_get_group_pins,
478 + .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
479 + .dt_free_map = pinconf_generic_dt_free_map,
480 +};
481 +
482 +/*
483 + * Functions code
484 + */
485 +
486 +static int bcm4908_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
487 + unsigned int func_selector,
488 + unsigned int group_selector)
489 +{
490 + struct bcm4908_pinctrl *bcm4908_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
491 + const struct bcm4908_pinctrl_grp *group;
492 + struct group_desc *group_desc;
493 + int i;
494 +
495 + group_desc = pinctrl_generic_get_group(pctrl_dev, group_selector);
496 + if (!group_desc)
497 + return -EINVAL;
498 + group = group_desc->data;
499 +
500 + mutex_lock(&bcm4908_pinctrl->mutex);
501 + for (i = 0; i < group->num_pins; i++) {
502 + u32 lsb = 0;
503 +
504 + lsb |= group->pins[i].number;
505 + lsb |= group->pins[i].function << BCM4908_TEST_PORT_LSB_PINMUX_DATA_SHIFT;
506 +
507 + writel(0x0, bcm4908_pinctrl->base + BCM4908_TEST_PORT_BLOCK_DATA_MSB);
508 + writel(lsb, bcm4908_pinctrl->base + BCM4908_TEST_PORT_BLOCK_DATA_LSB);
509 + writel(BCM4908_TEST_PORT_CMD_LOAD_MUX_REG,
510 + bcm4908_pinctrl->base + BCM4908_TEST_PORT_COMMAND);
511 + }
512 + mutex_unlock(&bcm4908_pinctrl->mutex);
513 +
514 + return 0;
515 +}
516 +
517 +static const struct pinmux_ops bcm4908_pinctrl_pmxops = {
518 + .get_functions_count = pinmux_generic_get_function_count,
519 + .get_function_name = pinmux_generic_get_function_name,
520 + .get_function_groups = pinmux_generic_get_function_groups,
521 + .set_mux = bcm4908_pinctrl_set_mux,
522 +};
523 +
524 +/*
525 + * Controller code
526 + */
527 +
528 +static struct pinctrl_desc bcm4908_pinctrl_desc = {
529 + .name = "bcm4908-pinctrl",
530 + .pctlops = &bcm4908_pinctrl_ops,
531 + .pmxops = &bcm4908_pinctrl_pmxops,
532 +};
533 +
534 +static const struct of_device_id bcm4908_pinctrl_of_match_table[] = {
535 + { .compatible = "brcm,bcm4908-pinctrl", },
536 + { }
537 +};
538 +
539 +static int bcm4908_pinctrl_probe(struct platform_device *pdev)
540 +{
541 + struct device *dev = &pdev->dev;
542 + struct bcm4908_pinctrl *bcm4908_pinctrl;
543 + struct pinctrl_desc *pctldesc;
544 + struct pinctrl_pin_desc *pins;
545 + int i;
546 +
547 + bcm4908_pinctrl = devm_kzalloc(dev, sizeof(*bcm4908_pinctrl), GFP_KERNEL);
548 + if (!bcm4908_pinctrl)
549 + return -ENOMEM;
550 + pctldesc = &bcm4908_pinctrl->pctldesc;
551 + platform_set_drvdata(pdev, bcm4908_pinctrl);
552 +
553 + /* Set basic properties */
554 +
555 + bcm4908_pinctrl->dev = dev;
556 +
557 + bcm4908_pinctrl->base = devm_platform_ioremap_resource(pdev, 0);
558 + if (IS_ERR(bcm4908_pinctrl->base))
559 + return PTR_ERR(bcm4908_pinctrl->base);
560 +
561 + mutex_init(&bcm4908_pinctrl->mutex);
562 +
563 + memcpy(pctldesc, &bcm4908_pinctrl_desc, sizeof(*pctldesc));
564 +
565 + /* Set pinctrl properties */
566 +
567 + pins = devm_kcalloc(dev, BCM4908_NUM_PINS, sizeof(*pins), GFP_KERNEL);
568 + if (!pins)
569 + return -ENOMEM;
570 + for (i = 0; i < BCM4908_NUM_PINS; i++) {
571 + pins[i].number = i;
572 + pins[i].name = devm_kasprintf(dev, GFP_KERNEL, "pin-%d", i);
573 + if (!pins[i].name)
574 + return -ENOMEM;
575 + }
576 + pctldesc->pins = pins;
577 + pctldesc->npins = BCM4908_NUM_PINS;
578 +
579 + /* Register */
580 +
581 + bcm4908_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, bcm4908_pinctrl);
582 + if (IS_ERR(bcm4908_pinctrl->pctldev))
583 + return dev_err_probe(dev, PTR_ERR(bcm4908_pinctrl->pctldev),
584 + "Failed to register pinctrl\n");
585 +
586 + /* Groups */
587 +
588 + for (i = 0; i < ARRAY_SIZE(bcm4908_pinctrl_grps); i++) {
589 + const struct bcm4908_pinctrl_grp *group = &bcm4908_pinctrl_grps[i];
590 + int *pins;
591 + int j;
592 +
593 + pins = devm_kcalloc(dev, group->num_pins, sizeof(*pins), GFP_KERNEL);
594 + if (!pins)
595 + return -ENOMEM;
596 + for (j = 0; j < group->num_pins; j++)
597 + pins[j] = group->pins[j].number;
598 +
599 + pinctrl_generic_add_group(bcm4908_pinctrl->pctldev, group->name,
600 + pins, group->num_pins, (void *)group);
601 + }
602 +
603 + /* Functions */
604 +
605 + for (i = 0; i < ARRAY_SIZE(bcm4908_pinctrl_functions); i++) {
606 + const struct bcm4908_pinctrl_function *function = &bcm4908_pinctrl_functions[i];
607 +
608 + pinmux_generic_add_function(bcm4908_pinctrl->pctldev,
609 + function->name,
610 + function->groups,
611 + function->num_groups, NULL);
612 + }
613 +
614 + return 0;
615 +}
616 +
617 +static struct platform_driver bcm4908_pinctrl_driver = {
618 + .probe = bcm4908_pinctrl_probe,
619 + .driver = {
620 + .name = "bcm4908-pinctrl",
621 + .of_match_table = bcm4908_pinctrl_of_match_table,
622 + },
623 +};
624 +
625 +module_platform_driver(bcm4908_pinctrl_driver);
626 +
627 +MODULE_AUTHOR("Rafał Miłecki");
628 +MODULE_LICENSE("GPL v2");
629 +MODULE_DEVICE_TABLE(of, bcm4908_pinctrl_of_match_table);