18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * OWL SoC's Pinctrl definitions
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2014 Actions Semi Inc.
68c2ecf20Sopenharmony_ci * Author: David Liu <liuwei@actions-semi.com>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (c) 2018 Linaro Ltd.
98c2ecf20Sopenharmony_ci * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __PINCTRL_OWL_H__
138c2ecf20Sopenharmony_ci#define __PINCTRL_OWL_H__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define OWL_PINCONF_SLEW_SLOW 0
168c2ecf20Sopenharmony_ci#define OWL_PINCONF_SLEW_FAST 1
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define MUX_PG(group_name, reg, shift, width)				\
198c2ecf20Sopenharmony_ci	{								\
208c2ecf20Sopenharmony_ci		.name = #group_name,					\
218c2ecf20Sopenharmony_ci		.pads = group_name##_pads,				\
228c2ecf20Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
238c2ecf20Sopenharmony_ci		.funcs = group_name##_funcs,				\
248c2ecf20Sopenharmony_ci		.nfuncs = ARRAY_SIZE(group_name##_funcs),		\
258c2ecf20Sopenharmony_ci		.mfpctl_reg  = MFCTL##reg,				\
268c2ecf20Sopenharmony_ci		.mfpctl_shift = shift,					\
278c2ecf20Sopenharmony_ci		.mfpctl_width = width,					\
288c2ecf20Sopenharmony_ci		.drv_reg = -1,						\
298c2ecf20Sopenharmony_ci		.drv_shift = -1,					\
308c2ecf20Sopenharmony_ci		.drv_width = -1,					\
318c2ecf20Sopenharmony_ci		.sr_reg = -1,						\
328c2ecf20Sopenharmony_ci		.sr_shift = -1,						\
338c2ecf20Sopenharmony_ci		.sr_width = -1,						\
348c2ecf20Sopenharmony_ci	}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define DRV_PG(group_name, reg, shift, width)				\
378c2ecf20Sopenharmony_ci	{								\
388c2ecf20Sopenharmony_ci		.name = #group_name,					\
398c2ecf20Sopenharmony_ci		.pads = group_name##_pads,				\
408c2ecf20Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
418c2ecf20Sopenharmony_ci		.mfpctl_reg  = -1,					\
428c2ecf20Sopenharmony_ci		.mfpctl_shift = -1,					\
438c2ecf20Sopenharmony_ci		.mfpctl_width = -1,					\
448c2ecf20Sopenharmony_ci		.drv_reg = PAD_DRV##reg,				\
458c2ecf20Sopenharmony_ci		.drv_shift = shift,					\
468c2ecf20Sopenharmony_ci		.drv_width = width,					\
478c2ecf20Sopenharmony_ci		.sr_reg = -1,						\
488c2ecf20Sopenharmony_ci		.sr_shift = -1,						\
498c2ecf20Sopenharmony_ci		.sr_width = -1,						\
508c2ecf20Sopenharmony_ci	}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define SR_PG(group_name, reg, shift, width)				\
538c2ecf20Sopenharmony_ci	{								\
548c2ecf20Sopenharmony_ci		.name = #group_name,					\
558c2ecf20Sopenharmony_ci		.pads = group_name##_pads,				\
568c2ecf20Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
578c2ecf20Sopenharmony_ci		.mfpctl_reg  = -1,					\
588c2ecf20Sopenharmony_ci		.mfpctl_shift = -1,					\
598c2ecf20Sopenharmony_ci		.mfpctl_width = -1,					\
608c2ecf20Sopenharmony_ci		.drv_reg = -1,						\
618c2ecf20Sopenharmony_ci		.drv_shift = -1,					\
628c2ecf20Sopenharmony_ci		.drv_width = -1,					\
638c2ecf20Sopenharmony_ci		.sr_reg = PAD_SR##reg,					\
648c2ecf20Sopenharmony_ci		.sr_shift = shift,					\
658c2ecf20Sopenharmony_ci		.sr_width = width,					\
668c2ecf20Sopenharmony_ci	}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define FUNCTION(fname)					\
698c2ecf20Sopenharmony_ci	{						\
708c2ecf20Sopenharmony_ci		.name = #fname,				\
718c2ecf20Sopenharmony_ci		.groups = fname##_groups,		\
728c2ecf20Sopenharmony_ci		.ngroups = ARRAY_SIZE(fname##_groups),	\
738c2ecf20Sopenharmony_ci	}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* PAD PULL UP/DOWN CONFIGURES */
768c2ecf20Sopenharmony_ci#define PULLCTL_CONF(pull_reg, pull_sft, pull_wdt)	\
778c2ecf20Sopenharmony_ci	{						\
788c2ecf20Sopenharmony_ci		.reg = PAD_PULLCTL##pull_reg,		\
798c2ecf20Sopenharmony_ci		.shift = pull_sft,			\
808c2ecf20Sopenharmony_ci		.width = pull_wdt,			\
818c2ecf20Sopenharmony_ci	}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define PAD_PULLCTL_CONF(pad_name, pull_reg, pull_sft, pull_wdt)	\
848c2ecf20Sopenharmony_ci	struct owl_pullctl pad_name##_pullctl_conf			\
858c2ecf20Sopenharmony_ci		= PULLCTL_CONF(pull_reg, pull_sft, pull_wdt)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define ST_CONF(st_reg, st_sft, st_wdt)			\
888c2ecf20Sopenharmony_ci	{						\
898c2ecf20Sopenharmony_ci		.reg = PAD_ST##st_reg,			\
908c2ecf20Sopenharmony_ci		.shift = st_sft,			\
918c2ecf20Sopenharmony_ci		.width = st_wdt,			\
928c2ecf20Sopenharmony_ci	}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define PAD_ST_CONF(pad_name, st_reg, st_sft, st_wdt)	\
958c2ecf20Sopenharmony_ci	struct owl_st pad_name##_st_conf		\
968c2ecf20Sopenharmony_ci		= ST_CONF(st_reg, st_sft, st_wdt)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define PAD_INFO(name)					\
998c2ecf20Sopenharmony_ci	{						\
1008c2ecf20Sopenharmony_ci		.pad = name,				\
1018c2ecf20Sopenharmony_ci		.pullctl = NULL,			\
1028c2ecf20Sopenharmony_ci		.st = NULL,				\
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define PAD_INFO_ST(name)				\
1068c2ecf20Sopenharmony_ci	{						\
1078c2ecf20Sopenharmony_ci		.pad = name,				\
1088c2ecf20Sopenharmony_ci		.pullctl = NULL,			\
1098c2ecf20Sopenharmony_ci		.st = &name##_st_conf,			\
1108c2ecf20Sopenharmony_ci	}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define PAD_INFO_PULLCTL(name)				\
1138c2ecf20Sopenharmony_ci	{						\
1148c2ecf20Sopenharmony_ci		.pad = name,				\
1158c2ecf20Sopenharmony_ci		.pullctl = &name##_pullctl_conf,	\
1168c2ecf20Sopenharmony_ci		.st = NULL,				\
1178c2ecf20Sopenharmony_ci	}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define PAD_INFO_PULLCTL_ST(name)			\
1208c2ecf20Sopenharmony_ci	{						\
1218c2ecf20Sopenharmony_ci		.pad = name,				\
1228c2ecf20Sopenharmony_ci		.pullctl = &name##_pullctl_conf,	\
1238c2ecf20Sopenharmony_ci		.st = &name##_st_conf,			\
1248c2ecf20Sopenharmony_ci	}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_A		0
1278c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_B		1
1288c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_C		2
1298c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_D		3
1308c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_E		4
1318c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT_F		5
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define OWL_GPIO_PORT(port, base, count, _outen, _inen, _dat, _intc_ctl,\
1348c2ecf20Sopenharmony_ci			_intc_pd, _intc_msk, _intc_type, _share)	\
1358c2ecf20Sopenharmony_ci	[OWL_GPIO_PORT_##port] = {				\
1368c2ecf20Sopenharmony_ci		.offset = base,					\
1378c2ecf20Sopenharmony_ci		.pins = count,					\
1388c2ecf20Sopenharmony_ci		.outen = _outen,				\
1398c2ecf20Sopenharmony_ci		.inen = _inen,					\
1408c2ecf20Sopenharmony_ci		.dat = _dat,					\
1418c2ecf20Sopenharmony_ci		.intc_ctl = _intc_ctl,				\
1428c2ecf20Sopenharmony_ci		.intc_pd = _intc_pd,				\
1438c2ecf20Sopenharmony_ci		.intc_msk = _intc_msk,				\
1448c2ecf20Sopenharmony_ci		.intc_type = _intc_type,			\
1458c2ecf20Sopenharmony_ci		.shared_ctl_offset = _share,			\
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cienum owl_pinconf_drv {
1498c2ecf20Sopenharmony_ci	OWL_PINCONF_DRV_2MA,
1508c2ecf20Sopenharmony_ci	OWL_PINCONF_DRV_4MA,
1518c2ecf20Sopenharmony_ci	OWL_PINCONF_DRV_8MA,
1528c2ecf20Sopenharmony_ci	OWL_PINCONF_DRV_12MA,
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci/* GPIO CTRL Bit Definition */
1568c2ecf20Sopenharmony_ci#define OWL_GPIO_CTLR_PENDING		0
1578c2ecf20Sopenharmony_ci#define OWL_GPIO_CTLR_ENABLE		1
1588c2ecf20Sopenharmony_ci#define OWL_GPIO_CTLR_SAMPLE_CLK_24M	2
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* GPIO TYPE Bit Definition */
1618c2ecf20Sopenharmony_ci#define OWL_GPIO_INT_LEVEL_HIGH		0
1628c2ecf20Sopenharmony_ci#define OWL_GPIO_INT_LEVEL_LOW		1
1638c2ecf20Sopenharmony_ci#define OWL_GPIO_INT_EDGE_RISING	2
1648c2ecf20Sopenharmony_ci#define OWL_GPIO_INT_EDGE_FALLING	3
1658c2ecf20Sopenharmony_ci#define OWL_GPIO_INT_MASK		3
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci/**
1688c2ecf20Sopenharmony_ci * struct owl_pullctl - Actions pad pull control register
1698c2ecf20Sopenharmony_ci * @reg: offset to the pull control register
1708c2ecf20Sopenharmony_ci * @shift: shift value of the register
1718c2ecf20Sopenharmony_ci * @width: width of the register
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistruct owl_pullctl {
1748c2ecf20Sopenharmony_ci	int reg;
1758c2ecf20Sopenharmony_ci	unsigned int shift;
1768c2ecf20Sopenharmony_ci	unsigned int width;
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/**
1808c2ecf20Sopenharmony_ci * struct owl_st - Actions pad schmitt trigger enable register
1818c2ecf20Sopenharmony_ci * @reg: offset to the schmitt trigger enable register
1828c2ecf20Sopenharmony_ci * @shift: shift value of the register
1838c2ecf20Sopenharmony_ci * @width: width of the register
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_cistruct owl_st {
1868c2ecf20Sopenharmony_ci	int reg;
1878c2ecf20Sopenharmony_ci	unsigned int shift;
1888c2ecf20Sopenharmony_ci	unsigned int width;
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci/**
1928c2ecf20Sopenharmony_ci * struct owl_pingroup - Actions pingroup definition
1938c2ecf20Sopenharmony_ci * @name: name of the  pin group
1948c2ecf20Sopenharmony_ci * @pads: list of pins assigned to this pingroup
1958c2ecf20Sopenharmony_ci * @npads: size of @pads array
1968c2ecf20Sopenharmony_ci * @funcs: list of pinmux functions for this pingroup
1978c2ecf20Sopenharmony_ci * @nfuncs: size of @funcs array
1988c2ecf20Sopenharmony_ci * @mfpctl_reg: multiplexing control register offset
1998c2ecf20Sopenharmony_ci * @mfpctl_shift: multiplexing control register bit mask
2008c2ecf20Sopenharmony_ci * @mfpctl_width: multiplexing control register width
2018c2ecf20Sopenharmony_ci * @drv_reg: drive control register offset
2028c2ecf20Sopenharmony_ci * @drv_shift: drive control register bit mask
2038c2ecf20Sopenharmony_ci * @drv_width: driver control register width
2048c2ecf20Sopenharmony_ci * @sr_reg: slew rate control register offset
2058c2ecf20Sopenharmony_ci * @sr_shift: slew rate control register bit mask
2068c2ecf20Sopenharmony_ci * @sr_width: slew rate control register width
2078c2ecf20Sopenharmony_ci */
2088c2ecf20Sopenharmony_cistruct owl_pingroup {
2098c2ecf20Sopenharmony_ci	const char *name;
2108c2ecf20Sopenharmony_ci	unsigned int *pads;
2118c2ecf20Sopenharmony_ci	unsigned int npads;
2128c2ecf20Sopenharmony_ci	unsigned int *funcs;
2138c2ecf20Sopenharmony_ci	unsigned int nfuncs;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	int mfpctl_reg;
2168c2ecf20Sopenharmony_ci	unsigned int mfpctl_shift;
2178c2ecf20Sopenharmony_ci	unsigned int mfpctl_width;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	int drv_reg;
2208c2ecf20Sopenharmony_ci	unsigned int drv_shift;
2218c2ecf20Sopenharmony_ci	unsigned int drv_width;
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	int sr_reg;
2248c2ecf20Sopenharmony_ci	unsigned int sr_shift;
2258c2ecf20Sopenharmony_ci	unsigned int sr_width;
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/**
2298c2ecf20Sopenharmony_ci * struct owl_padinfo - Actions pinctrl pad info
2308c2ecf20Sopenharmony_ci * @pad: pad name of the SoC
2318c2ecf20Sopenharmony_ci * @pullctl: pull control register info
2328c2ecf20Sopenharmony_ci * @st: schmitt trigger register info
2338c2ecf20Sopenharmony_ci */
2348c2ecf20Sopenharmony_cistruct owl_padinfo {
2358c2ecf20Sopenharmony_ci	int pad;
2368c2ecf20Sopenharmony_ci	struct owl_pullctl *pullctl;
2378c2ecf20Sopenharmony_ci	struct owl_st *st;
2388c2ecf20Sopenharmony_ci};
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/**
2418c2ecf20Sopenharmony_ci * struct owl_pinmux_func - Actions pinctrl mux functions
2428c2ecf20Sopenharmony_ci * @name: name of the pinmux function.
2438c2ecf20Sopenharmony_ci * @groups: array of pin groups that may select this function.
2448c2ecf20Sopenharmony_ci * @ngroups: number of entries in @groups.
2458c2ecf20Sopenharmony_ci */
2468c2ecf20Sopenharmony_cistruct owl_pinmux_func {
2478c2ecf20Sopenharmony_ci	const char *name;
2488c2ecf20Sopenharmony_ci	const char * const *groups;
2498c2ecf20Sopenharmony_ci	unsigned int ngroups;
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/**
2538c2ecf20Sopenharmony_ci * struct owl_gpio_port - Actions GPIO port info
2548c2ecf20Sopenharmony_ci * @offset: offset of the GPIO port.
2558c2ecf20Sopenharmony_ci * @pins: number of pins belongs to the GPIO port.
2568c2ecf20Sopenharmony_ci * @outen: offset of the output enable register.
2578c2ecf20Sopenharmony_ci * @inen: offset of the input enable register.
2588c2ecf20Sopenharmony_ci * @dat: offset of the data register.
2598c2ecf20Sopenharmony_ci * @intc_ctl: offset of the interrupt control register.
2608c2ecf20Sopenharmony_ci * @intc_pd: offset of the interrupt pending register.
2618c2ecf20Sopenharmony_ci * @intc_msk: offset of the interrupt mask register.
2628c2ecf20Sopenharmony_ci * @intc_type: offset of the interrupt type register.
2638c2ecf20Sopenharmony_ci */
2648c2ecf20Sopenharmony_cistruct owl_gpio_port {
2658c2ecf20Sopenharmony_ci	unsigned int offset;
2668c2ecf20Sopenharmony_ci	unsigned int pins;
2678c2ecf20Sopenharmony_ci	unsigned int outen;
2688c2ecf20Sopenharmony_ci	unsigned int inen;
2698c2ecf20Sopenharmony_ci	unsigned int dat;
2708c2ecf20Sopenharmony_ci	unsigned int intc_ctl;
2718c2ecf20Sopenharmony_ci	unsigned int intc_pd;
2728c2ecf20Sopenharmony_ci	unsigned int intc_msk;
2738c2ecf20Sopenharmony_ci	unsigned int intc_type;
2748c2ecf20Sopenharmony_ci	u8 shared_ctl_offset;
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/**
2788c2ecf20Sopenharmony_ci * struct owl_pinctrl_soc_data - Actions pin controller driver configuration
2798c2ecf20Sopenharmony_ci * @pins: array describing all pins of the pin controller.
2808c2ecf20Sopenharmony_ci * @npins: number of entries in @pins.
2818c2ecf20Sopenharmony_ci * @functions: array describing all mux functions of this SoC.
2828c2ecf20Sopenharmony_ci * @nfunction: number of entries in @functions.
2838c2ecf20Sopenharmony_ci * @groups: array describing all pin groups of this SoC.
2848c2ecf20Sopenharmony_ci * @ngroups: number of entries in @groups.
2858c2ecf20Sopenharmony_ci * @padinfo: array describing the pad info of this SoC.
2868c2ecf20Sopenharmony_ci * @ngpios: number of pingroups the driver should expose as GPIOs.
2878c2ecf20Sopenharmony_ci * @ports: array describing all GPIO ports of this SoC.
2888c2ecf20Sopenharmony_ci * @nports: number of GPIO ports in this SoC.
2898c2ecf20Sopenharmony_ci */
2908c2ecf20Sopenharmony_cistruct owl_pinctrl_soc_data {
2918c2ecf20Sopenharmony_ci	const struct pinctrl_pin_desc *pins;
2928c2ecf20Sopenharmony_ci	unsigned int npins;
2938c2ecf20Sopenharmony_ci	const struct owl_pinmux_func *functions;
2948c2ecf20Sopenharmony_ci	unsigned int nfunctions;
2958c2ecf20Sopenharmony_ci	const struct owl_pingroup *groups;
2968c2ecf20Sopenharmony_ci	unsigned int ngroups;
2978c2ecf20Sopenharmony_ci	const struct owl_padinfo *padinfo;
2988c2ecf20Sopenharmony_ci	unsigned int ngpios;
2998c2ecf20Sopenharmony_ci	const struct owl_gpio_port *ports;
3008c2ecf20Sopenharmony_ci	unsigned int nports;
3018c2ecf20Sopenharmony_ci	int (*padctl_val2arg)(const struct owl_padinfo *padinfo,
3028c2ecf20Sopenharmony_ci				unsigned int param,
3038c2ecf20Sopenharmony_ci				u32 *arg);
3048c2ecf20Sopenharmony_ci	int (*padctl_arg2val)(const struct owl_padinfo *info,
3058c2ecf20Sopenharmony_ci				unsigned int param,
3068c2ecf20Sopenharmony_ci				u32 *arg);
3078c2ecf20Sopenharmony_ci};
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ciint owl_pinctrl_probe(struct platform_device *pdev,
3108c2ecf20Sopenharmony_ci		struct owl_pinctrl_soc_data *soc_data);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci#endif /* __PINCTRL_OWL_H__ */
313