153bdae24SGregory CLEMENT /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
253bdae24SGregory CLEMENT /*
353bdae24SGregory CLEMENT  * Microsemi SoCs pinctrl driver
453bdae24SGregory CLEMENT  *
553bdae24SGregory CLEMENT  * Author: <alexandre.belloni@free-electrons.com>
653bdae24SGregory CLEMENT  * License: Dual MIT/GPL
753bdae24SGregory CLEMENT  * Copyright (c) 2017 Microsemi Corporation
853bdae24SGregory CLEMENT  */
953bdae24SGregory CLEMENT 
1053bdae24SGregory CLEMENT #define MSCC_FUNC_PER_PIN	4
1153bdae24SGregory CLEMENT 
12*051de9b3SHoratiu Vultur enum mscc_regs_gpio {
13*051de9b3SHoratiu Vultur 	MSCC_GPIO_OUT_SET,
14*051de9b3SHoratiu Vultur 	MSCC_GPIO_OUT_CLR,
15*051de9b3SHoratiu Vultur 	MSCC_GPIO_OUT,
16*051de9b3SHoratiu Vultur 	MSCC_GPIO_IN,
17*051de9b3SHoratiu Vultur 	MSCC_GPIO_OE,
18*051de9b3SHoratiu Vultur 	MSCC_GPIO_INTR,
19*051de9b3SHoratiu Vultur 	MSCC_GPIO_INTR_ENA,
20*051de9b3SHoratiu Vultur 	MSCC_GPIO_INTR_IDENT,
21*051de9b3SHoratiu Vultur 	MSCC_GPIO_ALT0,
22*051de9b3SHoratiu Vultur 	MSCC_GPIO_ALT1,
23*051de9b3SHoratiu Vultur };
24*051de9b3SHoratiu Vultur 
2553bdae24SGregory CLEMENT struct mscc_pin_caps {
2653bdae24SGregory CLEMENT 	unsigned int pin;
2753bdae24SGregory CLEMENT 	unsigned char functions[MSCC_FUNC_PER_PIN];
2853bdae24SGregory CLEMENT };
2953bdae24SGregory CLEMENT 
3053bdae24SGregory CLEMENT struct mscc_pin_data {
3153bdae24SGregory CLEMENT 	const char *name;
3253bdae24SGregory CLEMENT 	struct mscc_pin_caps *drv_data;
3353bdae24SGregory CLEMENT };
3453bdae24SGregory CLEMENT 
3553bdae24SGregory CLEMENT #define MSCC_P(p, f0, f1, f2)						\
3653bdae24SGregory CLEMENT static struct mscc_pin_caps mscc_pin_##p = {				\
3753bdae24SGregory CLEMENT 	.pin = p,							\
3853bdae24SGregory CLEMENT 	.functions = {							\
3953bdae24SGregory CLEMENT 			FUNC_GPIO, FUNC_##f0, FUNC_##f1, FUNC_##f2,	\
4053bdae24SGregory CLEMENT 	},								\
4153bdae24SGregory CLEMENT }
4253bdae24SGregory CLEMENT 
4353bdae24SGregory CLEMENT struct mscc_pmx_func {
4453bdae24SGregory CLEMENT 	const char **groups;
4553bdae24SGregory CLEMENT 	unsigned int ngroups;
4653bdae24SGregory CLEMENT };
4753bdae24SGregory CLEMENT 
4853bdae24SGregory CLEMENT struct mscc_pinctrl {
4953bdae24SGregory CLEMENT 	struct udevice *dev;
5053bdae24SGregory CLEMENT 	struct pinctrl_dev *pctl;
5153bdae24SGregory CLEMENT 	void __iomem *regs;
5253bdae24SGregory CLEMENT 	struct mscc_pmx_func *func;
5353bdae24SGregory CLEMENT 	int num_func;
5453bdae24SGregory CLEMENT 	const struct mscc_pin_data *mscc_pins;
5553bdae24SGregory CLEMENT 	int num_pins;
5653bdae24SGregory CLEMENT 	char * const *function_names;
57*051de9b3SHoratiu Vultur 	const unsigned long *mscc_gpios;
5853bdae24SGregory CLEMENT };
5953bdae24SGregory CLEMENT 
6053bdae24SGregory CLEMENT int mscc_pinctrl_probe(struct udevice *dev, int num_func,
6153bdae24SGregory CLEMENT 		       const struct mscc_pin_data *mscc_pins, int num_pins,
62*051de9b3SHoratiu Vultur 		       char * const *function_names,
63*051de9b3SHoratiu Vultur 		       const unsigned long *mscc_gpios);
6453bdae24SGregory CLEMENT const struct pinctrl_ops mscc_pinctrl_ops;
6553bdae24SGregory CLEMENT 
6653bdae24SGregory CLEMENT const struct dm_gpio_ops mscc_gpio_ops;
67