162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Marvell Berlin BG2CD pinctrl driver.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2014 Marvell Technology Group Ltd.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Antoine Ténart <antoine.tenart@free-electrons.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/init.h>
1162306a36Sopenharmony_ci#include <linux/of_device.h>
1262306a36Sopenharmony_ci#include <linux/platform_device.h>
1362306a36Sopenharmony_ci#include <linux/regmap.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include "berlin.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cistatic const struct berlin_desc_group berlin2cd_soc_pinctrl_groups[] = {
1862306a36Sopenharmony_ci	/* G */
1962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x3, 0x00,
2062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
2162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
2262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "led"),
2362306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "pwm")),
2462306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x3, 0x03,
2562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
2662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
2762306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
2862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
2962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x3, 0x06,
3062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
3162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "fe"),
3362306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
3462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
3562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
3662306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x3, 0x09,
3762306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
3862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "twsi2"),
4062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
4162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x4, "fe"),
4262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
4362306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
4462306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x3, 0x0c,
4562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
4662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
4762306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
4862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
4962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
5062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
5162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
5262306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x0f,
5362306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
5462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
5562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
5662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "arc"),
5762306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
5862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
5962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
6062306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x3, 0x12,
6162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
6262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
6362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x15,
6462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "eddc"),
6562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
6662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "gpio")),
6762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x18,
6862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SS0n */
6962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
7062306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x1b,
7162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
7262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"), /* SS1n/SS2n */
7362306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x3, "twsi0")),
7462306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x1e,
7562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* CLK */
7662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
7762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G11", 0x04, 0x2, 0x00,
7862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"), /* SDI/SDO */
7962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
8062306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G12", 0x04, 0x3, 0x02,
8162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "usb1"),
8262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
8362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x05,
8462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
8562306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "usb0_dbg"),
8662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x2, "usb1_dbg")),
8762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x08,
8862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
8962306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
9062306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x3, 0x09,
9162306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
9262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
9362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x0c,
9462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
9562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x0f,
9662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
9762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x2, 0x12,
9862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
9962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x2, 0x14,
10062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10162306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x2, 0x16,
10262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x18,
10462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x1b,
10662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G23", 0x08, 0x3, 0x00,
10862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G24", 0x08, 0x2, 0x03,
11062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11162306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G25", 0x08, 0x2, 0x05,
11262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G26", 0x08, 0x1, 0x07,
11462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G27", 0x08, 0x2, 0x08,
11662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G28", 0x08, 0x3, 0x0a,
11862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("G29", 0x08, 0x3, 0x0d,
12062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12162306a36Sopenharmony_ci};
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_cistatic const struct berlin_desc_group berlin2cd_sysmgr_pinctrl_groups[] = {
12462306a36Sopenharmony_ci	/* GSM */
12562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM0", 0x40, 0x2, 0x00,
12662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM1", 0x40, 0x2, 0x02,
12862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM2", 0x40, 0x2, 0x04,
13062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13162306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM3", 0x40, 0x2, 0x06,
13262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM4", 0x40, 0x2, 0x08,
13462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM5", 0x40, 0x2, 0x0a,
13662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM6", 0x40, 0x2, 0x0c,
13862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13962306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM7", 0x40, 0x1, 0x0e,
14062306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14162306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM8", 0x40, 0x1, 0x0f,
14262306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14362306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM9", 0x40, 0x1, 0x10,
14462306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14562306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM10", 0x40, 0x1, 0x11,
14662306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14762306a36Sopenharmony_ci	BERLIN_PINCTRL_GROUP("GSM11", 0x40, 0x1, 0x12,
14862306a36Sopenharmony_ci		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14962306a36Sopenharmony_ci};
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic const struct berlin_pinctrl_desc berlin2cd_soc_pinctrl_data = {
15262306a36Sopenharmony_ci	.groups = berlin2cd_soc_pinctrl_groups,
15362306a36Sopenharmony_ci	.ngroups = ARRAY_SIZE(berlin2cd_soc_pinctrl_groups),
15462306a36Sopenharmony_ci};
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cistatic const struct berlin_pinctrl_desc berlin2cd_sysmgr_pinctrl_data = {
15762306a36Sopenharmony_ci	.groups = berlin2cd_sysmgr_pinctrl_groups,
15862306a36Sopenharmony_ci	.ngroups = ARRAY_SIZE(berlin2cd_sysmgr_pinctrl_groups),
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistatic const struct of_device_id berlin2cd_pinctrl_match[] = {
16262306a36Sopenharmony_ci	{
16362306a36Sopenharmony_ci		.compatible = "marvell,berlin2cd-soc-pinctrl",
16462306a36Sopenharmony_ci		.data = &berlin2cd_soc_pinctrl_data
16562306a36Sopenharmony_ci	},
16662306a36Sopenharmony_ci	{
16762306a36Sopenharmony_ci		.compatible = "marvell,berlin2cd-system-pinctrl",
16862306a36Sopenharmony_ci		.data = &berlin2cd_sysmgr_pinctrl_data
16962306a36Sopenharmony_ci	},
17062306a36Sopenharmony_ci	{}
17162306a36Sopenharmony_ci};
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cistatic int berlin2cd_pinctrl_probe(struct platform_device *pdev)
17462306a36Sopenharmony_ci{
17562306a36Sopenharmony_ci	const struct of_device_id *match =
17662306a36Sopenharmony_ci		of_match_device(berlin2cd_pinctrl_match, &pdev->dev);
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	return berlin_pinctrl_probe(pdev, match->data);
17962306a36Sopenharmony_ci}
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_cistatic struct platform_driver berlin2cd_pinctrl_driver = {
18262306a36Sopenharmony_ci	.probe	= berlin2cd_pinctrl_probe,
18362306a36Sopenharmony_ci	.driver	= {
18462306a36Sopenharmony_ci		.name = "berlin-bg2cd-pinctrl",
18562306a36Sopenharmony_ci		.of_match_table = berlin2cd_pinctrl_match,
18662306a36Sopenharmony_ci	},
18762306a36Sopenharmony_ci};
18862306a36Sopenharmony_cibuiltin_platform_driver(berlin2cd_pinctrl_driver);
189