148b6bce3SAntoine Tenart /*
248b6bce3SAntoine Tenart  * Marvell Berlin BG2CD pinctrl driver.
348b6bce3SAntoine Tenart  *
448b6bce3SAntoine Tenart  * Copyright (C) 2014 Marvell Technology Group Ltd.
548b6bce3SAntoine Tenart  *
648b6bce3SAntoine Tenart  * Antoine Ténart <antoine.tenart@free-electrons.com>
748b6bce3SAntoine Tenart  *
848b6bce3SAntoine Tenart  * This file is licensed under the terms of the GNU General Public
948b6bce3SAntoine Tenart  * License version 2. This program is licensed "as is" without any
1048b6bce3SAntoine Tenart  * warranty of any kind, whether express or implied.
1148b6bce3SAntoine Tenart  */
1248b6bce3SAntoine Tenart 
1348b6bce3SAntoine Tenart #include <linux/module.h>
1448b6bce3SAntoine Tenart #include <linux/of_device.h>
1548b6bce3SAntoine Tenart #include <linux/platform_device.h>
1648b6bce3SAntoine Tenart #include <linux/regmap.h>
1748b6bce3SAntoine Tenart 
1848b6bce3SAntoine Tenart #include "berlin.h"
1948b6bce3SAntoine Tenart 
2048b6bce3SAntoine Tenart static const struct berlin_desc_group berlin2cd_soc_pinctrl_groups[] = {
2148b6bce3SAntoine Tenart 	/* G */
2248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G0", 0x00, 0x1, 0x00,
2348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
2448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio"),
2548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "led"),
2648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pwm")),
2748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G1", 0x00, 0x2, 0x01,
2848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
2948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
3148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
3248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G2", 0x00, 0x2, 0x02,
3348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
3448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
3548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "fe"),
3648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
3748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
3848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
3948b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G3", 0x00, 0x2, 0x04,
4048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
4148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
4248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi2"),
4348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
4448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "fe"),
4548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
4648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
4748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G4", 0x00, 0x2, 0x06,
4848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
4948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
5048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
5148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "pll"),
5248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
5348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
5448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
5548b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G5", 0x00, 0x3, 0x08,
5648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
5748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "sd0"),
5848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi3"),
5948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x3, "arc"),
6048b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x4, "pwm"),
6148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x6, "usb0_dbg"),
6248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x7, "usb1_dbg")),
6348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G6", 0x00, 0x2, 0x0b,
6448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "uart0"),	/* RX/TX */
6548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
6648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G7", 0x00, 0x3, 0x0d,
6748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "eddc"),
6848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "twsi1"),
6948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "gpio")),
7048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G8", 0x00, 0x3, 0x10,
7148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "ss0"),
7248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
7348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G9", 0x00, 0x3, 0x13,
7448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "gpio"),
7548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "spi1"),
7648b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "twsi0")),
7748b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G10", 0x00, 0x2, 0x16,
7848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"),
7948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
8048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G11", 0x00, 0x2, 0x18,
8148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "spi1"),
8248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
8348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G12", 0x00, 0x3, 0x1a,
8448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "usb1"),
8548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
8648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G13", 0x04, 0x3, 0x00,
8748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
8848b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "usb0_dbg"),
8948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x2, "usb1_dbg")),
9048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G14", 0x04, 0x1, 0x03,
9148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "nand"),
9248b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
9348b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G15", 0x04, 0x2, 0x04,
9448b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x0, "jtag"),
9548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION(0x1, "gpio")),
9648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G16", 0x04, 0x3, 0x06,
9748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
9848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G17", 0x04, 0x3, 0x09,
9948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G18", 0x04, 0x1, 0x0c,
10148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G19", 0x04, 0x1, 0x0d,
10348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10448b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G20", 0x04, 0x1, 0x0e,
10548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G21", 0x04, 0x3, 0x0f,
10748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
10848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G22", 0x04, 0x3, 0x12,
10948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G23", 0x04, 0x3, 0x15,
11148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G24", 0x04, 0x2, 0x18,
11348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11448b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G25", 0x04, 0x2, 0x1a,
11548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G26", 0x04, 0x1, 0x1c,
11748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
11848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G27", 0x04, 0x1, 0x1d,
11948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("G28", 0x04, 0x2, 0x1e,
12148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12248b6bce3SAntoine Tenart };
12348b6bce3SAntoine Tenart 
12448b6bce3SAntoine Tenart static const struct berlin_desc_group berlin2cd_sysmgr_pinctrl_groups[] = {
12548b6bce3SAntoine Tenart 	/* GSM */
12648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM0", 0x40, 0x2, 0x00,
12748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
12848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM1", 0x40, 0x2, 0x02,
12948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM2", 0x40, 0x2, 0x04,
13148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM3", 0x40, 0x2, 0x06,
13348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13448b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM4", 0x40, 0x2, 0x08,
13548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM5", 0x40, 0x2, 0x0a,
13748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
13848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM6", 0x40, 0x2, 0x0c,
13948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14048b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM7", 0x40, 0x1, 0x0e,
14148b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14248b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM8", 0x40, 0x1, 0x0f,
14348b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14448b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM9", 0x40, 0x1, 0x10,
14548b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14648b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM10", 0x40, 0x1, 0x11,
14748b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
14848b6bce3SAntoine Tenart 	BERLIN_PINCTRL_GROUP("GSM11", 0x40, 0x1, 0x12,
14948b6bce3SAntoine Tenart 		BERLIN_PINCTRL_FUNCTION_UNKNOWN),
15048b6bce3SAntoine Tenart };
15148b6bce3SAntoine Tenart 
15248b6bce3SAntoine Tenart static const struct berlin_pinctrl_desc berlin2cd_soc_pinctrl_data = {
15348b6bce3SAntoine Tenart 	.groups = berlin2cd_soc_pinctrl_groups,
15448b6bce3SAntoine Tenart 	.ngroups = ARRAY_SIZE(berlin2cd_soc_pinctrl_groups),
15548b6bce3SAntoine Tenart };
15648b6bce3SAntoine Tenart 
15748b6bce3SAntoine Tenart static const struct berlin_pinctrl_desc berlin2cd_sysmgr_pinctrl_data = {
15848b6bce3SAntoine Tenart 	.groups = berlin2cd_sysmgr_pinctrl_groups,
15948b6bce3SAntoine Tenart 	.ngroups = ARRAY_SIZE(berlin2cd_sysmgr_pinctrl_groups),
16048b6bce3SAntoine Tenart };
16148b6bce3SAntoine Tenart 
16248b6bce3SAntoine Tenart static const struct of_device_id berlin2cd_pinctrl_match[] = {
16348b6bce3SAntoine Tenart 	{
16448b6bce3SAntoine Tenart 		.compatible = "marvell,berlin2cd-chip-ctrl",
16548b6bce3SAntoine Tenart 		.data = &berlin2cd_soc_pinctrl_data
16648b6bce3SAntoine Tenart 	},
16748b6bce3SAntoine Tenart 	{
16848b6bce3SAntoine Tenart 		.compatible = "marvell,berlin2cd-system-ctrl",
16948b6bce3SAntoine Tenart 		.data = &berlin2cd_sysmgr_pinctrl_data
17048b6bce3SAntoine Tenart 	},
17148b6bce3SAntoine Tenart 	{}
17248b6bce3SAntoine Tenart };
17348b6bce3SAntoine Tenart MODULE_DEVICE_TABLE(of, berlin2cd_pinctrl_match);
17448b6bce3SAntoine Tenart 
17548b6bce3SAntoine Tenart static int berlin2cd_pinctrl_probe(struct platform_device *pdev)
17648b6bce3SAntoine Tenart {
17748b6bce3SAntoine Tenart 	const struct of_device_id *match =
17848b6bce3SAntoine Tenart 		of_match_device(berlin2cd_pinctrl_match, &pdev->dev);
17948b6bce3SAntoine Tenart 	struct regmap_config *rmconfig;
18048b6bce3SAntoine Tenart 	struct regmap *regmap;
18148b6bce3SAntoine Tenart 	struct resource *res;
18248b6bce3SAntoine Tenart 	void __iomem *base;
18348b6bce3SAntoine Tenart 
18448b6bce3SAntoine Tenart 	rmconfig = devm_kzalloc(&pdev->dev, sizeof(*rmconfig), GFP_KERNEL);
18548b6bce3SAntoine Tenart 	if (!rmconfig)
18648b6bce3SAntoine Tenart 		return -ENOMEM;
18748b6bce3SAntoine Tenart 
18848b6bce3SAntoine Tenart 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
18949cfabc2SJingoo Han 	base = devm_ioremap_resource(&pdev->dev, res);
19049cfabc2SJingoo Han 	if (IS_ERR(base))
19149cfabc2SJingoo Han 		return PTR_ERR(base);
19248b6bce3SAntoine Tenart 
19348b6bce3SAntoine Tenart 	rmconfig->reg_bits = 32,
19448b6bce3SAntoine Tenart 	rmconfig->val_bits = 32,
19548b6bce3SAntoine Tenart 	rmconfig->reg_stride = 4,
19648b6bce3SAntoine Tenart 	rmconfig->max_register = resource_size(res);
19748b6bce3SAntoine Tenart 
19848b6bce3SAntoine Tenart 	regmap = devm_regmap_init_mmio(&pdev->dev, base, rmconfig);
19948b6bce3SAntoine Tenart 	if (IS_ERR(regmap))
20048b6bce3SAntoine Tenart 		return PTR_ERR(regmap);
20148b6bce3SAntoine Tenart 
20248b6bce3SAntoine Tenart 	return berlin_pinctrl_probe(pdev, match->data);
20348b6bce3SAntoine Tenart }
20448b6bce3SAntoine Tenart 
20548b6bce3SAntoine Tenart static struct platform_driver berlin2cd_pinctrl_driver = {
20648b6bce3SAntoine Tenart 	.probe	= berlin2cd_pinctrl_probe,
20748b6bce3SAntoine Tenart 	.driver	= {
20848b6bce3SAntoine Tenart 		.name = "berlin-bg2cd-pinctrl",
20948b6bce3SAntoine Tenart 		.owner = THIS_MODULE,
21048b6bce3SAntoine Tenart 		.of_match_table = berlin2cd_pinctrl_match,
21148b6bce3SAntoine Tenart 	},
21248b6bce3SAntoine Tenart };
21348b6bce3SAntoine Tenart module_platform_driver(berlin2cd_pinctrl_driver);
21448b6bce3SAntoine Tenart 
21548b6bce3SAntoine Tenart MODULE_AUTHOR("Antoine Ténart <antoine.tenart@free-electrons.com>");
21648b6bce3SAntoine Tenart MODULE_DESCRIPTION("Marvell Berlin BG2CD pinctrl driver");
21748b6bce3SAntoine Tenart MODULE_LICENSE("GPL");
218