1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
23a198059SLinus Walleij #ifndef PINCTRL_PINCTRL_NOMADIK_H
33a198059SLinus Walleij #define PINCTRL_PINCTRL_NOMADIK_H
43a198059SLinus Walleij 
5*937e7a39SAndy Shevchenko #include <linux/kernel.h>
6*937e7a39SAndy Shevchenko #include <linux/types.h>
7*937e7a39SAndy Shevchenko 
8*937e7a39SAndy Shevchenko #include <linux/pinctrl/pinctrl.h>
9*937e7a39SAndy Shevchenko 
103a198059SLinus Walleij /* Package definitions */
113a198059SLinus Walleij #define PINCTRL_NMK_STN8815	0
123a198059SLinus Walleij #define PINCTRL_NMK_DB8500	1
133a198059SLinus Walleij 
143a198059SLinus Walleij /* Alternate functions: function C is set in hw by setting both A and B */
153a198059SLinus Walleij #define NMK_GPIO_ALT_GPIO	0
163a198059SLinus Walleij #define NMK_GPIO_ALT_A	1
173a198059SLinus Walleij #define NMK_GPIO_ALT_B	2
183a198059SLinus Walleij #define NMK_GPIO_ALT_C	(NMK_GPIO_ALT_A | NMK_GPIO_ALT_B)
193a198059SLinus Walleij 
203a198059SLinus Walleij #define NMK_GPIO_ALT_CX_SHIFT 2
213a198059SLinus Walleij #define NMK_GPIO_ALT_C1	((1<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
223a198059SLinus Walleij #define NMK_GPIO_ALT_C2	((2<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
233a198059SLinus Walleij #define NMK_GPIO_ALT_C3	((3<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
243a198059SLinus Walleij #define NMK_GPIO_ALT_C4	((4<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
253a198059SLinus Walleij 
263a198059SLinus Walleij #define PRCM_GPIOCR_ALTCX(pin_num,\
273a198059SLinus Walleij 	altc1_used, altc1_ri, altc1_cb,\
283a198059SLinus Walleij 	altc2_used, altc2_ri, altc2_cb,\
293a198059SLinus Walleij 	altc3_used, altc3_ri, altc3_cb,\
303a198059SLinus Walleij 	altc4_used, altc4_ri, altc4_cb)\
313a198059SLinus Walleij {\
323a198059SLinus Walleij 	.pin = pin_num,\
333a198059SLinus Walleij 	.altcx[PRCM_IDX_GPIOCR_ALTC1] = {\
343a198059SLinus Walleij 		.used = altc1_used,\
353a198059SLinus Walleij 		.reg_index = altc1_ri,\
363a198059SLinus Walleij 		.control_bit = altc1_cb\
373a198059SLinus Walleij 	},\
383a198059SLinus Walleij 	.altcx[PRCM_IDX_GPIOCR_ALTC2] = {\
393a198059SLinus Walleij 		.used = altc2_used,\
403a198059SLinus Walleij 		.reg_index = altc2_ri,\
413a198059SLinus Walleij 		.control_bit = altc2_cb\
423a198059SLinus Walleij 	},\
433a198059SLinus Walleij 	.altcx[PRCM_IDX_GPIOCR_ALTC3] = {\
443a198059SLinus Walleij 		.used = altc3_used,\
453a198059SLinus Walleij 		.reg_index = altc3_ri,\
463a198059SLinus Walleij 		.control_bit = altc3_cb\
473a198059SLinus Walleij 	},\
483a198059SLinus Walleij 	.altcx[PRCM_IDX_GPIOCR_ALTC4] = {\
493a198059SLinus Walleij 		.used = altc4_used,\
503a198059SLinus Walleij 		.reg_index = altc4_ri,\
513a198059SLinus Walleij 		.control_bit = altc4_cb\
523a198059SLinus Walleij 	},\
533a198059SLinus Walleij }
543a198059SLinus Walleij 
553a198059SLinus Walleij /**
563a198059SLinus Walleij  * enum prcm_gpiocr_reg_index
573a198059SLinus Walleij  * Used to reference an PRCM GPIOCR register address.
583a198059SLinus Walleij  */
593a198059SLinus Walleij enum prcm_gpiocr_reg_index {
603a198059SLinus Walleij 	PRCM_IDX_GPIOCR1,
613a198059SLinus Walleij 	PRCM_IDX_GPIOCR2,
623a198059SLinus Walleij 	PRCM_IDX_GPIOCR3
633a198059SLinus Walleij };
643a198059SLinus Walleij /**
653a198059SLinus Walleij  * enum prcm_gpiocr_altcx_index
663a198059SLinus Walleij  * Used to reference an Other alternate-C function.
673a198059SLinus Walleij  */
683a198059SLinus Walleij enum prcm_gpiocr_altcx_index {
693a198059SLinus Walleij 	PRCM_IDX_GPIOCR_ALTC1,
703a198059SLinus Walleij 	PRCM_IDX_GPIOCR_ALTC2,
713a198059SLinus Walleij 	PRCM_IDX_GPIOCR_ALTC3,
723a198059SLinus Walleij 	PRCM_IDX_GPIOCR_ALTC4,
733a198059SLinus Walleij 	PRCM_IDX_GPIOCR_ALTC_MAX,
743a198059SLinus Walleij };
753a198059SLinus Walleij 
763a198059SLinus Walleij /**
773a198059SLinus Walleij  * struct prcm_gpio_altcx - Other alternate-C function
783a198059SLinus Walleij  * @used: other alternate-C function availability
793a198059SLinus Walleij  * @reg_index: PRCM GPIOCR register index used to control the function
803a198059SLinus Walleij  * @control_bit: PRCM GPIOCR bit used to control the function
813a198059SLinus Walleij  */
823a198059SLinus Walleij struct prcm_gpiocr_altcx {
833a198059SLinus Walleij 	bool used:1;
843a198059SLinus Walleij 	u8 reg_index:2;
853a198059SLinus Walleij 	u8 control_bit:5;
863a198059SLinus Walleij } __packed;
873a198059SLinus Walleij 
883a198059SLinus Walleij /**
893a198059SLinus Walleij  * struct prcm_gpio_altcx_pin_desc - Other alternate-C pin
903a198059SLinus Walleij  * @pin: The pin number
913a198059SLinus Walleij  * @altcx: array of other alternate-C[1-4] functions
923a198059SLinus Walleij  */
933a198059SLinus Walleij struct prcm_gpiocr_altcx_pin_desc {
943a198059SLinus Walleij 	unsigned short pin;
953a198059SLinus Walleij 	struct prcm_gpiocr_altcx altcx[PRCM_IDX_GPIOCR_ALTC_MAX];
963a198059SLinus Walleij };
973a198059SLinus Walleij 
983a198059SLinus Walleij /**
993a198059SLinus Walleij  * struct nmk_function - Nomadik pinctrl mux function
1003a198059SLinus Walleij  * @name: The name of the function, exported to pinctrl core.
1013a198059SLinus Walleij  * @groups: An array of pin groups that may select this function.
1023a198059SLinus Walleij  * @ngroups: The number of entries in @groups.
1033a198059SLinus Walleij  */
1043a198059SLinus Walleij struct nmk_function {
1053a198059SLinus Walleij 	const char *name;
1063a198059SLinus Walleij 	const char * const *groups;
1073a198059SLinus Walleij 	unsigned ngroups;
1083a198059SLinus Walleij };
1093a198059SLinus Walleij 
1103a198059SLinus Walleij /**
1113a198059SLinus Walleij  * struct nmk_pingroup - describes a Nomadik pin group
11239b707faSAndy Shevchenko  * @grp: Generic data of the pin group (name and pins)
1133a198059SLinus Walleij  * @altsetting: the altsetting to apply to all pins in this group to
1143a198059SLinus Walleij  *	configure them to be used by a function
1153a198059SLinus Walleij  */
1163a198059SLinus Walleij struct nmk_pingroup {
11739b707faSAndy Shevchenko 	struct pingroup grp;
1183a198059SLinus Walleij 	int altsetting;
1193a198059SLinus Walleij };
1203a198059SLinus Walleij 
12139b707faSAndy Shevchenko #define NMK_PIN_GROUP(a, b)							\
12239b707faSAndy Shevchenko 	{									\
12339b707faSAndy Shevchenko 		.grp = PINCTRL_PINGROUP(#a, a##_pins, ARRAY_SIZE(a##_pins)),	\
12439b707faSAndy Shevchenko 		.altsetting = b,						\
12539b707faSAndy Shevchenko 	}
12639b707faSAndy Shevchenko 
1273a198059SLinus Walleij /**
1283a198059SLinus Walleij  * struct nmk_pinctrl_soc_data - Nomadik pin controller per-SoC configuration
1293a198059SLinus Walleij  * @pins:	An array describing all pins the pin controller affects.
1303a198059SLinus Walleij  *		All pins which are also GPIOs must be listed first within the
1313a198059SLinus Walleij  *		array, and be numbered identically to the GPIO controller's
1323a198059SLinus Walleij  *		numbering.
1333a198059SLinus Walleij  * @npins:	The number of entries in @pins.
1343a198059SLinus Walleij  * @functions:	The functions supported on this SoC.
1353a198059SLinus Walleij  * @nfunction:	The number of entries in @functions.
1363a198059SLinus Walleij  * @groups:	An array describing all pin groups the pin SoC supports.
1373a198059SLinus Walleij  * @ngroups:	The number of entries in @groups.
1383a198059SLinus Walleij  * @altcx_pins:	The pins that support Other alternate-C function on this SoC
1393a198059SLinus Walleij  * @npins_altcx: The number of Other alternate-C pins
1403a198059SLinus Walleij  * @prcm_gpiocr_registers: The array of PRCM GPIOCR registers on this SoC
1413a198059SLinus Walleij  */
1423a198059SLinus Walleij struct nmk_pinctrl_soc_data {
1433a198059SLinus Walleij 	const struct pinctrl_pin_desc *pins;
1443a198059SLinus Walleij 	unsigned npins;
1453a198059SLinus Walleij 	const struct nmk_function *functions;
1463a198059SLinus Walleij 	unsigned nfunctions;
1473a198059SLinus Walleij 	const struct nmk_pingroup *groups;
1483a198059SLinus Walleij 	unsigned ngroups;
1493a198059SLinus Walleij 	const struct prcm_gpiocr_altcx_pin_desc *altcx_pins;
1503a198059SLinus Walleij 	unsigned npins_altcx;
1513a198059SLinus Walleij 	const u16 *prcm_gpiocr_registers;
1523a198059SLinus Walleij };
1533a198059SLinus Walleij 
1543a198059SLinus Walleij #ifdef CONFIG_PINCTRL_STN8815
1553a198059SLinus Walleij 
1563a198059SLinus Walleij void nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data **soc);
1573a198059SLinus Walleij 
1583a198059SLinus Walleij #else
1593a198059SLinus Walleij 
1603a198059SLinus Walleij static inline void
nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data ** soc)1613a198059SLinus Walleij nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data **soc)
1623a198059SLinus Walleij {
1633a198059SLinus Walleij }
1643a198059SLinus Walleij 
1653a198059SLinus Walleij #endif
1663a198059SLinus Walleij 
1673a198059SLinus Walleij #ifdef CONFIG_PINCTRL_DB8500
1683a198059SLinus Walleij 
1693a198059SLinus Walleij void nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data **soc);
1703a198059SLinus Walleij 
1713a198059SLinus Walleij #else
1723a198059SLinus Walleij 
1733a198059SLinus Walleij static inline void
nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data ** soc)1743a198059SLinus Walleij nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data **soc)
1753a198059SLinus Walleij {
1763a198059SLinus Walleij }
1773a198059SLinus Walleij 
1783a198059SLinus Walleij #endif
1793a198059SLinus Walleij 
1803a198059SLinus Walleij #endif /* PINCTRL_PINCTRL_NOMADIK_H */
181