162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * OWL SoC's Pinctrl definitions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2014 Actions Semi Inc.
662306a36Sopenharmony_ci * Author: David Liu <liuwei@actions-semi.com>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Copyright (c) 2018 Linaro Ltd.
962306a36Sopenharmony_ci * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifndef __PINCTRL_OWL_H__
1362306a36Sopenharmony_ci#define __PINCTRL_OWL_H__
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define OWL_PINCONF_SLEW_SLOW 0
1662306a36Sopenharmony_ci#define OWL_PINCONF_SLEW_FAST 1
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define MUX_PG(group_name, reg, shift, width)				\
1962306a36Sopenharmony_ci	{								\
2062306a36Sopenharmony_ci		.name = #group_name,					\
2162306a36Sopenharmony_ci		.pads = group_name##_pads,				\
2262306a36Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
2362306a36Sopenharmony_ci		.funcs = group_name##_funcs,				\
2462306a36Sopenharmony_ci		.nfuncs = ARRAY_SIZE(group_name##_funcs),		\
2562306a36Sopenharmony_ci		.mfpctl_reg  = MFCTL##reg,				\
2662306a36Sopenharmony_ci		.mfpctl_shift = shift,					\
2762306a36Sopenharmony_ci		.mfpctl_width = width,					\
2862306a36Sopenharmony_ci		.drv_reg = -1,						\
2962306a36Sopenharmony_ci		.drv_shift = -1,					\
3062306a36Sopenharmony_ci		.drv_width = -1,					\
3162306a36Sopenharmony_ci		.sr_reg = -1,						\
3262306a36Sopenharmony_ci		.sr_shift = -1,						\
3362306a36Sopenharmony_ci		.sr_width = -1,						\
3462306a36Sopenharmony_ci	}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define DRV_PG(group_name, reg, shift, width)				\
3762306a36Sopenharmony_ci	{								\
3862306a36Sopenharmony_ci		.name = #group_name,					\
3962306a36Sopenharmony_ci		.pads = group_name##_pads,				\
4062306a36Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
4162306a36Sopenharmony_ci		.mfpctl_reg  = -1,					\
4262306a36Sopenharmony_ci		.mfpctl_shift = -1,					\
4362306a36Sopenharmony_ci		.mfpctl_width = -1,					\
4462306a36Sopenharmony_ci		.drv_reg = PAD_DRV##reg,				\
4562306a36Sopenharmony_ci		.drv_shift = shift,					\
4662306a36Sopenharmony_ci		.drv_width = width,					\
4762306a36Sopenharmony_ci		.sr_reg = -1,						\
4862306a36Sopenharmony_ci		.sr_shift = -1,						\
4962306a36Sopenharmony_ci		.sr_width = -1,						\
5062306a36Sopenharmony_ci	}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define SR_PG(group_name, reg, shift, width)				\
5362306a36Sopenharmony_ci	{								\
5462306a36Sopenharmony_ci		.name = #group_name,					\
5562306a36Sopenharmony_ci		.pads = group_name##_pads,				\
5662306a36Sopenharmony_ci		.npads = ARRAY_SIZE(group_name##_pads),			\
5762306a36Sopenharmony_ci		.mfpctl_reg  = -1,					\
5862306a36Sopenharmony_ci		.mfpctl_shift = -1,					\
5962306a36Sopenharmony_ci		.mfpctl_width = -1,					\
6062306a36Sopenharmony_ci		.drv_reg = -1,						\
6162306a36Sopenharmony_ci		.drv_shift = -1,					\
6262306a36Sopenharmony_ci		.drv_width = -1,					\
6362306a36Sopenharmony_ci		.sr_reg = PAD_SR##reg,					\
6462306a36Sopenharmony_ci		.sr_shift = shift,					\
6562306a36Sopenharmony_ci		.sr_width = width,					\
6662306a36Sopenharmony_ci	}
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define FUNCTION(fname)					\
6962306a36Sopenharmony_ci	{						\
7062306a36Sopenharmony_ci		.name = #fname,				\
7162306a36Sopenharmony_ci		.groups = fname##_groups,		\
7262306a36Sopenharmony_ci		.ngroups = ARRAY_SIZE(fname##_groups),	\
7362306a36Sopenharmony_ci	}
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/* PAD PULL UP/DOWN CONFIGURES */
7662306a36Sopenharmony_ci#define PULLCTL_CONF(pull_reg, pull_sft, pull_wdt)	\
7762306a36Sopenharmony_ci	{						\
7862306a36Sopenharmony_ci		.reg = PAD_PULLCTL##pull_reg,		\
7962306a36Sopenharmony_ci		.shift = pull_sft,			\
8062306a36Sopenharmony_ci		.width = pull_wdt,			\
8162306a36Sopenharmony_ci	}
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define PAD_PULLCTL_CONF(pad_name, pull_reg, pull_sft, pull_wdt)	\
8462306a36Sopenharmony_ci	struct owl_pullctl pad_name##_pullctl_conf			\
8562306a36Sopenharmony_ci		= PULLCTL_CONF(pull_reg, pull_sft, pull_wdt)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define ST_CONF(st_reg, st_sft, st_wdt)			\
8862306a36Sopenharmony_ci	{						\
8962306a36Sopenharmony_ci		.reg = PAD_ST##st_reg,			\
9062306a36Sopenharmony_ci		.shift = st_sft,			\
9162306a36Sopenharmony_ci		.width = st_wdt,			\
9262306a36Sopenharmony_ci	}
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#define PAD_ST_CONF(pad_name, st_reg, st_sft, st_wdt)	\
9562306a36Sopenharmony_ci	struct owl_st pad_name##_st_conf		\
9662306a36Sopenharmony_ci		= ST_CONF(st_reg, st_sft, st_wdt)
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci#define PAD_INFO(name)					\
9962306a36Sopenharmony_ci	{						\
10062306a36Sopenharmony_ci		.pad = name,				\
10162306a36Sopenharmony_ci		.pullctl = NULL,			\
10262306a36Sopenharmony_ci		.st = NULL,				\
10362306a36Sopenharmony_ci	}
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define PAD_INFO_ST(name)				\
10662306a36Sopenharmony_ci	{						\
10762306a36Sopenharmony_ci		.pad = name,				\
10862306a36Sopenharmony_ci		.pullctl = NULL,			\
10962306a36Sopenharmony_ci		.st = &name##_st_conf,			\
11062306a36Sopenharmony_ci	}
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define PAD_INFO_PULLCTL(name)				\
11362306a36Sopenharmony_ci	{						\
11462306a36Sopenharmony_ci		.pad = name,				\
11562306a36Sopenharmony_ci		.pullctl = &name##_pullctl_conf,	\
11662306a36Sopenharmony_ci		.st = NULL,				\
11762306a36Sopenharmony_ci	}
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define PAD_INFO_PULLCTL_ST(name)			\
12062306a36Sopenharmony_ci	{						\
12162306a36Sopenharmony_ci		.pad = name,				\
12262306a36Sopenharmony_ci		.pullctl = &name##_pullctl_conf,	\
12362306a36Sopenharmony_ci		.st = &name##_st_conf,			\
12462306a36Sopenharmony_ci	}
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#define OWL_GPIO_PORT_A		0
12762306a36Sopenharmony_ci#define OWL_GPIO_PORT_B		1
12862306a36Sopenharmony_ci#define OWL_GPIO_PORT_C		2
12962306a36Sopenharmony_ci#define OWL_GPIO_PORT_D		3
13062306a36Sopenharmony_ci#define OWL_GPIO_PORT_E		4
13162306a36Sopenharmony_ci#define OWL_GPIO_PORT_F		5
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci#define OWL_GPIO_PORT(port, base, count, _outen, _inen, _dat, _intc_ctl,\
13462306a36Sopenharmony_ci			_intc_pd, _intc_msk, _intc_type, _share)	\
13562306a36Sopenharmony_ci	[OWL_GPIO_PORT_##port] = {				\
13662306a36Sopenharmony_ci		.offset = base,					\
13762306a36Sopenharmony_ci		.pins = count,					\
13862306a36Sopenharmony_ci		.outen = _outen,				\
13962306a36Sopenharmony_ci		.inen = _inen,					\
14062306a36Sopenharmony_ci		.dat = _dat,					\
14162306a36Sopenharmony_ci		.intc_ctl = _intc_ctl,				\
14262306a36Sopenharmony_ci		.intc_pd = _intc_pd,				\
14362306a36Sopenharmony_ci		.intc_msk = _intc_msk,				\
14462306a36Sopenharmony_ci		.intc_type = _intc_type,			\
14562306a36Sopenharmony_ci		.shared_ctl_offset = _share,			\
14662306a36Sopenharmony_ci	}
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_cienum owl_pinconf_drv {
14962306a36Sopenharmony_ci	OWL_PINCONF_DRV_2MA,
15062306a36Sopenharmony_ci	OWL_PINCONF_DRV_4MA,
15162306a36Sopenharmony_ci	OWL_PINCONF_DRV_8MA,
15262306a36Sopenharmony_ci	OWL_PINCONF_DRV_12MA,
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci/* GPIO CTRL Bit Definition */
15662306a36Sopenharmony_ci#define OWL_GPIO_CTLR_PENDING		0
15762306a36Sopenharmony_ci#define OWL_GPIO_CTLR_ENABLE		1
15862306a36Sopenharmony_ci#define OWL_GPIO_CTLR_SAMPLE_CLK_24M	2
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/* GPIO TYPE Bit Definition */
16162306a36Sopenharmony_ci#define OWL_GPIO_INT_LEVEL_HIGH		0
16262306a36Sopenharmony_ci#define OWL_GPIO_INT_LEVEL_LOW		1
16362306a36Sopenharmony_ci#define OWL_GPIO_INT_EDGE_RISING	2
16462306a36Sopenharmony_ci#define OWL_GPIO_INT_EDGE_FALLING	3
16562306a36Sopenharmony_ci#define OWL_GPIO_INT_MASK		3
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci/**
16862306a36Sopenharmony_ci * struct owl_pullctl - Actions pad pull control register
16962306a36Sopenharmony_ci * @reg: offset to the pull control register
17062306a36Sopenharmony_ci * @shift: shift value of the register
17162306a36Sopenharmony_ci * @width: width of the register
17262306a36Sopenharmony_ci */
17362306a36Sopenharmony_cistruct owl_pullctl {
17462306a36Sopenharmony_ci	int reg;
17562306a36Sopenharmony_ci	unsigned int shift;
17662306a36Sopenharmony_ci	unsigned int width;
17762306a36Sopenharmony_ci};
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/**
18062306a36Sopenharmony_ci * struct owl_st - Actions pad schmitt trigger enable register
18162306a36Sopenharmony_ci * @reg: offset to the schmitt trigger enable register
18262306a36Sopenharmony_ci * @shift: shift value of the register
18362306a36Sopenharmony_ci * @width: width of the register
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_cistruct owl_st {
18662306a36Sopenharmony_ci	int reg;
18762306a36Sopenharmony_ci	unsigned int shift;
18862306a36Sopenharmony_ci	unsigned int width;
18962306a36Sopenharmony_ci};
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci/**
19262306a36Sopenharmony_ci * struct owl_pingroup - Actions pingroup definition
19362306a36Sopenharmony_ci * @name: name of the  pin group
19462306a36Sopenharmony_ci * @pads: list of pins assigned to this pingroup
19562306a36Sopenharmony_ci * @npads: size of @pads array
19662306a36Sopenharmony_ci * @funcs: list of pinmux functions for this pingroup
19762306a36Sopenharmony_ci * @nfuncs: size of @funcs array
19862306a36Sopenharmony_ci * @mfpctl_reg: multiplexing control register offset
19962306a36Sopenharmony_ci * @mfpctl_shift: multiplexing control register bit mask
20062306a36Sopenharmony_ci * @mfpctl_width: multiplexing control register width
20162306a36Sopenharmony_ci * @drv_reg: drive control register offset
20262306a36Sopenharmony_ci * @drv_shift: drive control register bit mask
20362306a36Sopenharmony_ci * @drv_width: driver control register width
20462306a36Sopenharmony_ci * @sr_reg: slew rate control register offset
20562306a36Sopenharmony_ci * @sr_shift: slew rate control register bit mask
20662306a36Sopenharmony_ci * @sr_width: slew rate control register width
20762306a36Sopenharmony_ci */
20862306a36Sopenharmony_cistruct owl_pingroup {
20962306a36Sopenharmony_ci	const char *name;
21062306a36Sopenharmony_ci	unsigned int *pads;
21162306a36Sopenharmony_ci	unsigned int npads;
21262306a36Sopenharmony_ci	unsigned int *funcs;
21362306a36Sopenharmony_ci	unsigned int nfuncs;
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci	int mfpctl_reg;
21662306a36Sopenharmony_ci	unsigned int mfpctl_shift;
21762306a36Sopenharmony_ci	unsigned int mfpctl_width;
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	int drv_reg;
22062306a36Sopenharmony_ci	unsigned int drv_shift;
22162306a36Sopenharmony_ci	unsigned int drv_width;
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	int sr_reg;
22462306a36Sopenharmony_ci	unsigned int sr_shift;
22562306a36Sopenharmony_ci	unsigned int sr_width;
22662306a36Sopenharmony_ci};
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci/**
22962306a36Sopenharmony_ci * struct owl_padinfo - Actions pinctrl pad info
23062306a36Sopenharmony_ci * @pad: pad name of the SoC
23162306a36Sopenharmony_ci * @pullctl: pull control register info
23262306a36Sopenharmony_ci * @st: schmitt trigger register info
23362306a36Sopenharmony_ci */
23462306a36Sopenharmony_cistruct owl_padinfo {
23562306a36Sopenharmony_ci	int pad;
23662306a36Sopenharmony_ci	struct owl_pullctl *pullctl;
23762306a36Sopenharmony_ci	struct owl_st *st;
23862306a36Sopenharmony_ci};
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci/**
24162306a36Sopenharmony_ci * struct owl_pinmux_func - Actions pinctrl mux functions
24262306a36Sopenharmony_ci * @name: name of the pinmux function.
24362306a36Sopenharmony_ci * @groups: array of pin groups that may select this function.
24462306a36Sopenharmony_ci * @ngroups: number of entries in @groups.
24562306a36Sopenharmony_ci */
24662306a36Sopenharmony_cistruct owl_pinmux_func {
24762306a36Sopenharmony_ci	const char *name;
24862306a36Sopenharmony_ci	const char * const *groups;
24962306a36Sopenharmony_ci	unsigned int ngroups;
25062306a36Sopenharmony_ci};
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci/**
25362306a36Sopenharmony_ci * struct owl_gpio_port - Actions GPIO port info
25462306a36Sopenharmony_ci * @offset: offset of the GPIO port.
25562306a36Sopenharmony_ci * @pins: number of pins belongs to the GPIO port.
25662306a36Sopenharmony_ci * @outen: offset of the output enable register.
25762306a36Sopenharmony_ci * @inen: offset of the input enable register.
25862306a36Sopenharmony_ci * @dat: offset of the data register.
25962306a36Sopenharmony_ci * @intc_ctl: offset of the interrupt control register.
26062306a36Sopenharmony_ci * @intc_pd: offset of the interrupt pending register.
26162306a36Sopenharmony_ci * @intc_msk: offset of the interrupt mask register.
26262306a36Sopenharmony_ci * @intc_type: offset of the interrupt type register.
26362306a36Sopenharmony_ci */
26462306a36Sopenharmony_cistruct owl_gpio_port {
26562306a36Sopenharmony_ci	unsigned int offset;
26662306a36Sopenharmony_ci	unsigned int pins;
26762306a36Sopenharmony_ci	unsigned int outen;
26862306a36Sopenharmony_ci	unsigned int inen;
26962306a36Sopenharmony_ci	unsigned int dat;
27062306a36Sopenharmony_ci	unsigned int intc_ctl;
27162306a36Sopenharmony_ci	unsigned int intc_pd;
27262306a36Sopenharmony_ci	unsigned int intc_msk;
27362306a36Sopenharmony_ci	unsigned int intc_type;
27462306a36Sopenharmony_ci	u8 shared_ctl_offset;
27562306a36Sopenharmony_ci};
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci/**
27862306a36Sopenharmony_ci * struct owl_pinctrl_soc_data - Actions pin controller driver configuration
27962306a36Sopenharmony_ci * @pins: array describing all pins of the pin controller.
28062306a36Sopenharmony_ci * @npins: number of entries in @pins.
28162306a36Sopenharmony_ci * @functions: array describing all mux functions of this SoC.
28262306a36Sopenharmony_ci * @nfunction: number of entries in @functions.
28362306a36Sopenharmony_ci * @groups: array describing all pin groups of this SoC.
28462306a36Sopenharmony_ci * @ngroups: number of entries in @groups.
28562306a36Sopenharmony_ci * @padinfo: array describing the pad info of this SoC.
28662306a36Sopenharmony_ci * @ngpios: number of pingroups the driver should expose as GPIOs.
28762306a36Sopenharmony_ci * @ports: array describing all GPIO ports of this SoC.
28862306a36Sopenharmony_ci * @nports: number of GPIO ports in this SoC.
28962306a36Sopenharmony_ci */
29062306a36Sopenharmony_cistruct owl_pinctrl_soc_data {
29162306a36Sopenharmony_ci	const struct pinctrl_pin_desc *pins;
29262306a36Sopenharmony_ci	unsigned int npins;
29362306a36Sopenharmony_ci	const struct owl_pinmux_func *functions;
29462306a36Sopenharmony_ci	unsigned int nfunctions;
29562306a36Sopenharmony_ci	const struct owl_pingroup *groups;
29662306a36Sopenharmony_ci	unsigned int ngroups;
29762306a36Sopenharmony_ci	const struct owl_padinfo *padinfo;
29862306a36Sopenharmony_ci	unsigned int ngpios;
29962306a36Sopenharmony_ci	const struct owl_gpio_port *ports;
30062306a36Sopenharmony_ci	unsigned int nports;
30162306a36Sopenharmony_ci	int (*padctl_val2arg)(const struct owl_padinfo *padinfo,
30262306a36Sopenharmony_ci				unsigned int param,
30362306a36Sopenharmony_ci				u32 *arg);
30462306a36Sopenharmony_ci	int (*padctl_arg2val)(const struct owl_padinfo *info,
30562306a36Sopenharmony_ci				unsigned int param,
30662306a36Sopenharmony_ci				u32 *arg);
30762306a36Sopenharmony_ci};
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ciint owl_pinctrl_probe(struct platform_device *pdev,
31062306a36Sopenharmony_ci		struct owl_pinctrl_soc_data *soc_data);
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci#endif /* __PINCTRL_OWL_H__ */
313