1c6114f21SJisheng Zhang // SPDX-License-Identifier: GPL-2.0
248b6bce3SAntoine Tenart /*
348b6bce3SAntoine Tenart  * Marvell Berlin BG2CD pinctrl driver.
448b6bce3SAntoine Tenart  *
548b6bce3SAntoine Tenart  * Copyright (C) 2014 Marvell Technology Group Ltd.
648b6bce3SAntoine Tenart  *
71d48fb6eSAntoine Ténart  * Antoine Ténart <antoine.tenart@free-electrons.com>
848b6bce3SAntoine Tenart  */
948b6bce3SAntoine Tenart 
109ec1a286SPaul Gortmaker #include <linux/init.h>
1148b6bce3SAntoine Tenart #include <linux/of_device.h>
1248b6bce3SAntoine Tenart #include <linux/platform_device.h>
1348b6bce3SAntoine Tenart #include <linux/regmap.h>
1448b6bce3SAntoine Tenart 
1548b6bce3SAntoine Tenart #include "berlin.h"
1648b6bce3SAntoine Tenart 
1748b6bce3SAntoine Tenart static const struct berlin_desc_group berlin2cd_soc_pinctrl_groups[] = {
1848b6bce3SAntoine Tenart 	/* G */
193c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x3, 0x00,
2048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
2148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
2248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "led"),
2348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pwm")),
243c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x3, 0x03,
2548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
2648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
2748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
2848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
293c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x3, 0x06,
3048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
3148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "fe"),
3348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
3448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
3548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
363c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x3, 0x09,
3748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
3848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi2"),
4048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
4148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "fe"),
4248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
4348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
443c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x3, 0x0c,
4548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
4648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
4748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
4848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
4948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
5048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
5148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
523c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x0f,
5348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
5448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
5548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
5648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "arc"),
5748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
5848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
5948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
603c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x3, 0x12,
6148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
6248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
633c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x15,
6448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "eddc"),
6548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
6648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio")),
673c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x18,
682e89f4c3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SS0n */
6948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
703c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x1b,
7148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
722e89f4c3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"), /* SS1n/SS2n */
733c6531c7SThomas Hebb 		BERLIN_PINCTRL_FUNCTION(0x3, "twsi0")),
743c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x1e,
752e89f4c3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* CLK */
7648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
773c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G11", 0x04, 0x2, 0x00,
782e89f4c3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SDI/SDO */
7948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
803c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G12", 0x04, 0x3, 0x02,
8148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "usb1"),
8248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
833c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x05,
8448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
8548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "usb0_dbg"),
8648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "usb1_dbg")),
873c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x08,
8848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
8948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
903c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x3, 0x09,
9148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
9248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
933c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x0c,
9448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
953c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x0f,
9648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
973c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x2, 0x12,
9848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
993c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x2, 0x14,
10048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1013c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x2, 0x16,
10248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1033c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x18,
10448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1053c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x1b,
10648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1073c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G23", 0x08, 0x3, 0x00,
10848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1093c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G24", 0x08, 0x2, 0x03,
11048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1113c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G25", 0x08, 0x2, 0x05,
11248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1133c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G26", 0x08, 0x1, 0x07,
11448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1153c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G27", 0x08, 0x2, 0x08,
11648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1173c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G28", 0x08, 0x3, 0x0a,
1183c6531c7SThomas Hebb 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
1193c6531c7SThomas Hebb 	BERLIN_PINCTRL_GROUP("G29", 0x08, 0x3, 0x0d,
12048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12148b6bce3SAntoine Tenart };
12248b6bce3SAntoine Tenart 
12348b6bce3SAntoine Tenart static const struct berlin_desc_group berlin2cd_sysmgr_pinctrl_groups[] = {
12448b6bce3SAntoine Tenart 	/* GSM */
12548b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM0", 0x40, 0x2, 0x00,
12648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM1", 0x40, 0x2, 0x02,
12848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12948b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM2", 0x40, 0x2, 0x04,
13048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13148b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM3", 0x40, 0x2, 0x06,
13248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM4", 0x40, 0x2, 0x08,
13448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13548b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM5", 0x40, 0x2, 0x0a,
13648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM6", 0x40, 0x2, 0x0c,
13848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13948b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM7", 0x40, 0x1, 0x0e,
14048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14148b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM8", 0x40, 0x1, 0x0f,
14248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM9", 0x40, 0x1, 0x10,
14448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14548b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM10", 0x40, 0x1, 0x11,
14648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM11", 0x40, 0x1, 0x12,
14848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14948b6bce3SAntoine Tenart };
15048b6bce3SAntoine Tenart 
15148b6bce3SAntoine Tenart static const struct berlin_pinctrl_desc berlin2cd_soc_pinctrl_data = {
15248b6bce3SAntoine Tenart 	.groups = berlin2cd_soc_pinctrl_groups,
15348b6bce3SAntoine Tenart 	.ngroups = ARRAY_SIZE(berlin2cd_soc_pinctrl_groups),
15448b6bce3SAntoine Tenart };
15548b6bce3SAntoine Tenart 
15648b6bce3SAntoine Tenart static const struct berlin_pinctrl_desc berlin2cd_sysmgr_pinctrl_data = {
15748b6bce3SAntoine Tenart 	.groups = berlin2cd_sysmgr_pinctrl_groups,
15848b6bce3SAntoine Tenart 	.ngroups = ARRAY_SIZE(berlin2cd_sysmgr_pinctrl_groups),
15948b6bce3SAntoine Tenart };
16048b6bce3SAntoine Tenart 
16148b6bce3SAntoine Tenart static const struct of_device_id berlin2cd_pinctrl_match[] = {
16248b6bce3SAntoine Tenart 	{
163f52bf55cSAntoine Tenart 		.compatible = "marvell,berlin2cd-soc-pinctrl",
16448b6bce3SAntoine Tenart 		.data = &berlin2cd_soc_pinctrl_data
16548b6bce3SAntoine Tenart 	},
16648b6bce3SAntoine Tenart 	{
167f52bf55cSAntoine Tenart 		.compatible = "marvell,berlin2cd-system-pinctrl",
16848b6bce3SAntoine Tenart 		.data = &berlin2cd_sysmgr_pinctrl_data
16948b6bce3SAntoine Tenart 	},
17048b6bce3SAntoine Tenart 	{}
17148b6bce3SAntoine Tenart };
17248b6bce3SAntoine Tenart 
berlin2cd_pinctrl_probe(struct platform_device * pdev)17348b6bce3SAntoine Tenart static int berlin2cd_pinctrl_probe(struct platform_device *pdev)
17448b6bce3SAntoine Tenart {
17548b6bce3SAntoine Tenart 	const struct of_device_id *match =
17648b6bce3SAntoine Tenart 		of_match_device(berlin2cd_pinctrl_match, &pdev->dev);
17748b6bce3SAntoine Tenart 
17848b6bce3SAntoine Tenart 	return berlin_pinctrl_probe(pdev, match->data);
17948b6bce3SAntoine Tenart }
18048b6bce3SAntoine Tenart 
18148b6bce3SAntoine Tenart static struct platform_driver berlin2cd_pinctrl_driver = {
18248b6bce3SAntoine Tenart 	.probe	= berlin2cd_pinctrl_probe,
18348b6bce3SAntoine Tenart 	.driver	= {
18448b6bce3SAntoine Tenart 		.name = "berlin-bg2cd-pinctrl",
18548b6bce3SAntoine Tenart 		.of_match_table = berlin2cd_pinctrl_match,
18648b6bce3SAntoine Tenart 	},
18748b6bce3SAntoine Tenart };
1889ec1a286SPaul Gortmaker builtin_platform_driver(berlin2cd_pinctrl_driver);
189