xref: /openbmc/linux/drivers/pinctrl/tegra/pinctrl-tegra.h (revision 82a040a8fa9b4f3845eff73a69a9931a59335902)
12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
225cbac77SMasahiro Yamada /*
325cbac77SMasahiro Yamada  * Driver for the NVIDIA Tegra pinmux
425cbac77SMasahiro Yamada  *
525cbac77SMasahiro Yamada  * Copyright (c) 2011, NVIDIA CORPORATION.  All rights reserved.
625cbac77SMasahiro Yamada  */
725cbac77SMasahiro Yamada 
825cbac77SMasahiro Yamada #ifndef __PINMUX_TEGRA_H__
925cbac77SMasahiro Yamada #define __PINMUX_TEGRA_H__
1025cbac77SMasahiro Yamada 
11c5948707SDmitry Osipenko struct tegra_pmx {
12c5948707SDmitry Osipenko 	struct device *dev;
13c5948707SDmitry Osipenko 	struct pinctrl_dev *pctl;
14c5948707SDmitry Osipenko 
15c5948707SDmitry Osipenko 	const struct tegra_pinctrl_soc_data *soc;
16*fad57233SThierry Reding 	struct tegra_function *functions;
17c5948707SDmitry Osipenko 	const char **group_pins;
18c5948707SDmitry Osipenko 
195a004736SThierry Reding 	struct pinctrl_gpio_range gpio_range;
205a004736SThierry Reding 	struct pinctrl_desc desc;
21c5948707SDmitry Osipenko 	int nbanks;
22c5948707SDmitry Osipenko 	void __iomem **regs;
239870acd3SSowjanya Komatineni 	u32 *backup_regs;
24c5948707SDmitry Osipenko };
25c5948707SDmitry Osipenko 
2625cbac77SMasahiro Yamada enum tegra_pinconf_param {
2725cbac77SMasahiro Yamada 	/* argument: tegra_pinconf_pull */
2825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_PULL,
2925cbac77SMasahiro Yamada 	/* argument: tegra_pinconf_tristate */
3025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_TRISTATE,
3125cbac77SMasahiro Yamada 	/* argument: Boolean */
3225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_ENABLE_INPUT,
3325cbac77SMasahiro Yamada 	/* argument: Boolean */
3425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_OPEN_DRAIN,
3525cbac77SMasahiro Yamada 	/* argument: Boolean */
3625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_LOCK,
3725cbac77SMasahiro Yamada 	/* argument: Boolean */
3825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_IORESET,
3925cbac77SMasahiro Yamada 	/* argument: Boolean */
4025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_RCV_SEL,
4125cbac77SMasahiro Yamada 	/* argument: Boolean */
4225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_HIGH_SPEED_MODE,
4325cbac77SMasahiro Yamada 	/* argument: Boolean */
4425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SCHMITT,
4525cbac77SMasahiro Yamada 	/* argument: Boolean */
4625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_LOW_POWER_MODE,
4725cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
4825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_DOWN_STRENGTH,
4925cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_UP_STRENGTH,
5125cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SLEW_RATE_FALLING,
5325cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SLEW_RATE_RISING,
5525cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_TYPE,
5725cbac77SMasahiro Yamada };
5825cbac77SMasahiro Yamada 
5925cbac77SMasahiro Yamada enum tegra_pinconf_pull {
6025cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_NONE,
6125cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_DOWN,
6225cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_UP,
6325cbac77SMasahiro Yamada };
6425cbac77SMasahiro Yamada 
6525cbac77SMasahiro Yamada enum tegra_pinconf_tristate {
6625cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_DRIVEN,
6725cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_TRISTATE,
6825cbac77SMasahiro Yamada };
6925cbac77SMasahiro Yamada 
7025cbac77SMasahiro Yamada #define TEGRA_PINCONF_PACK(_param_, _arg_) ((_param_) << 16 | (_arg_))
7125cbac77SMasahiro Yamada #define TEGRA_PINCONF_UNPACK_PARAM(_conf_) ((_conf_) >> 16)
7225cbac77SMasahiro Yamada #define TEGRA_PINCONF_UNPACK_ARG(_conf_) ((_conf_) & 0xffff)
7325cbac77SMasahiro Yamada 
7425cbac77SMasahiro Yamada /**
7525cbac77SMasahiro Yamada  * struct tegra_function - Tegra pinctrl mux function
7625cbac77SMasahiro Yamada  * @name: The name of the function, exported to pinctrl core.
7725cbac77SMasahiro Yamada  * @groups: An array of pin groups that may select this function.
7825cbac77SMasahiro Yamada  * @ngroups: The number of entries in @groups.
7925cbac77SMasahiro Yamada  */
8025cbac77SMasahiro Yamada struct tegra_function {
8125cbac77SMasahiro Yamada 	const char *name;
8225cbac77SMasahiro Yamada 	const char **groups;
8325cbac77SMasahiro Yamada 	unsigned ngroups;
8425cbac77SMasahiro Yamada };
8525cbac77SMasahiro Yamada 
8625cbac77SMasahiro Yamada /**
8725cbac77SMasahiro Yamada  * struct tegra_pingroup - Tegra pin group
8825cbac77SMasahiro Yamada  * @name		The name of the pin group.
8925cbac77SMasahiro Yamada  * @pins		An array of pin IDs included in this pin group.
9025cbac77SMasahiro Yamada  * @npins		The number of entries in @pins.
9125cbac77SMasahiro Yamada  * @funcs		The mux functions which can be muxed onto this group.
9225cbac77SMasahiro Yamada  * @mux_reg:		Mux register offset.
9325cbac77SMasahiro Yamada  *			This register contains the mux, einput, odrain, lock,
9425cbac77SMasahiro Yamada  *			ioreset, rcv_sel parameters.
9525cbac77SMasahiro Yamada  * @mux_bank:		Mux register bank.
9625cbac77SMasahiro Yamada  * @mux_bit:		Mux register bit.
9725cbac77SMasahiro Yamada  * @pupd_reg:		Pull-up/down register offset.
9825cbac77SMasahiro Yamada  * @pupd_bank:		Pull-up/down register bank.
9925cbac77SMasahiro Yamada  * @pupd_bit:		Pull-up/down register bit.
10025cbac77SMasahiro Yamada  * @tri_reg:		Tri-state register offset.
10125cbac77SMasahiro Yamada  * @tri_bank:		Tri-state register bank.
10225cbac77SMasahiro Yamada  * @tri_bit:		Tri-state register bit.
10325cbac77SMasahiro Yamada  * @einput_bit:		Enable-input register bit.
10425cbac77SMasahiro Yamada  * @odrain_bit:		Open-drain register bit.
10525cbac77SMasahiro Yamada  * @lock_bit:		Lock register bit.
10625cbac77SMasahiro Yamada  * @ioreset_bit:	IO reset register bit.
10725cbac77SMasahiro Yamada  * @rcv_sel_bit:	Receiver select bit.
10825cbac77SMasahiro Yamada  * @drv_reg:		Drive fields register offset.
10925cbac77SMasahiro Yamada  *			This register contains hsm, schmitt, lpmd, drvdn,
11025cbac77SMasahiro Yamada  *			drvup, slwr, slwf, and drvtype parameters.
11125cbac77SMasahiro Yamada  * @drv_bank:		Drive fields register bank.
11225cbac77SMasahiro Yamada  * @hsm_bit:		High Speed Mode register bit.
113368b62f2SThierry Reding  * @sfsel_bit:		GPIO/SFIO selection register bit.
11466539e6eSThierry Reding  * @schmitt_bit:	Schmitt register bit.
11525cbac77SMasahiro Yamada  * @lpmd_bit:		Low Power Mode register bit.
11625cbac77SMasahiro Yamada  * @drvdn_bit:		Drive Down register bit.
11725cbac77SMasahiro Yamada  * @drvdn_width:	Drive Down field width.
11825cbac77SMasahiro Yamada  * @drvup_bit:		Drive Up register bit.
11925cbac77SMasahiro Yamada  * @drvup_width:	Drive Up field width.
12025cbac77SMasahiro Yamada  * @slwr_bit:		Slew Rising register bit.
12125cbac77SMasahiro Yamada  * @slwr_width:		Slew Rising field width.
12225cbac77SMasahiro Yamada  * @slwf_bit:		Slew Falling register bit.
12325cbac77SMasahiro Yamada  * @slwf_width:		Slew Falling field width.
1248d886bbaSSuresh Mangipudi  * @lpdr_bit:		Base driver enabling bit.
12525cbac77SMasahiro Yamada  * @drvtype_bit:	Drive type register bit.
126cf75b8f2SThierry Reding  * @parked_bitmask:	Parked register mask. 0 if unsupported.
12725cbac77SMasahiro Yamada  *
12825cbac77SMasahiro Yamada  * -1 in a *_reg field means that feature is unsupported for this group.
12925cbac77SMasahiro Yamada  * *_bank and *_reg values are irrelevant when *_reg is -1.
13025cbac77SMasahiro Yamada  * When *_reg is valid, *_bit may be -1 to indicate an unsupported feature.
13125cbac77SMasahiro Yamada  *
13225cbac77SMasahiro Yamada  * A representation of a group of pins (possibly just one pin) in the Tegra
13325cbac77SMasahiro Yamada  * pin controller. Each group allows some parameter or parameters to be
13425cbac77SMasahiro Yamada  * configured. The most common is mux function selection. Many others exist
13525cbac77SMasahiro Yamada  * such as pull-up/down, tri-state, etc. Tegra's pin controller is complex;
13625cbac77SMasahiro Yamada  * certain groups may only support configuring certain parameters, hence
13725cbac77SMasahiro Yamada  * each parameter is optional.
13825cbac77SMasahiro Yamada  */
13925cbac77SMasahiro Yamada struct tegra_pingroup {
14025cbac77SMasahiro Yamada 	const char *name;
14125cbac77SMasahiro Yamada 	const unsigned *pins;
14225cbac77SMasahiro Yamada 	u8 npins;
14325cbac77SMasahiro Yamada 	u8 funcs[4];
144b4e18ba2SKrishna Yarlagadda 	s32 mux_reg;
145b4e18ba2SKrishna Yarlagadda 	s32 pupd_reg;
146b4e18ba2SKrishna Yarlagadda 	s32 tri_reg;
147b4e18ba2SKrishna Yarlagadda 	s32 drv_reg;
14825cbac77SMasahiro Yamada 	u32 mux_bank:2;
14925cbac77SMasahiro Yamada 	u32 pupd_bank:2;
15025cbac77SMasahiro Yamada 	u32 tri_bank:2;
15125cbac77SMasahiro Yamada 	u32 drv_bank:2;
15225cbac77SMasahiro Yamada 	s32 mux_bit:6;
15325cbac77SMasahiro Yamada 	s32 pupd_bit:6;
15425cbac77SMasahiro Yamada 	s32 tri_bit:6;
15525cbac77SMasahiro Yamada 	s32 einput_bit:6;
15625cbac77SMasahiro Yamada 	s32 odrain_bit:6;
15725cbac77SMasahiro Yamada 	s32 lock_bit:6;
15825cbac77SMasahiro Yamada 	s32 ioreset_bit:6;
15925cbac77SMasahiro Yamada 	s32 rcv_sel_bit:6;
16025cbac77SMasahiro Yamada 	s32 hsm_bit:6;
161368b62f2SThierry Reding 	s32 sfsel_bit:6;
16225cbac77SMasahiro Yamada 	s32 schmitt_bit:6;
16325cbac77SMasahiro Yamada 	s32 lpmd_bit:6;
16425cbac77SMasahiro Yamada 	s32 drvdn_bit:6;
16525cbac77SMasahiro Yamada 	s32 drvup_bit:6;
16625cbac77SMasahiro Yamada 	s32 slwr_bit:6;
16725cbac77SMasahiro Yamada 	s32 slwf_bit:6;
1688d886bbaSSuresh Mangipudi 	s32 lpdr_bit:6;
16925cbac77SMasahiro Yamada 	s32 drvtype_bit:6;
17025cbac77SMasahiro Yamada 	s32 drvdn_width:6;
17125cbac77SMasahiro Yamada 	s32 drvup_width:6;
17225cbac77SMasahiro Yamada 	s32 slwr_width:6;
17325cbac77SMasahiro Yamada 	s32 slwf_width:6;
174cf75b8f2SThierry Reding 	u32 parked_bitmask;
17525cbac77SMasahiro Yamada };
17625cbac77SMasahiro Yamada 
17725cbac77SMasahiro Yamada /**
17825cbac77SMasahiro Yamada  * struct tegra_pinctrl_soc_data - Tegra pin controller driver configuration
17925cbac77SMasahiro Yamada  * @ngpios:	The number of GPIO pins the pin controller HW affects.
18025cbac77SMasahiro Yamada  * @pins:	An array describing all pins the pin controller affects.
18125cbac77SMasahiro Yamada  *		All pins which are also GPIOs must be listed first within the
18225cbac77SMasahiro Yamada  *		array, and be numbered identically to the GPIO controller's
18325cbac77SMasahiro Yamada  *		numbering.
18425cbac77SMasahiro Yamada  * @npins:	The numbmer of entries in @pins.
18525cbac77SMasahiro Yamada  * @functions:	An array describing all mux functions the SoC supports.
18625cbac77SMasahiro Yamada  * @nfunctions:	The numbmer of entries in @functions.
18725cbac77SMasahiro Yamada  * @groups:	An array describing all pin groups the pin SoC supports.
18825cbac77SMasahiro Yamada  * @ngroups:	The numbmer of entries in @groups.
18925cbac77SMasahiro Yamada  */
19025cbac77SMasahiro Yamada struct tegra_pinctrl_soc_data {
19125cbac77SMasahiro Yamada 	unsigned ngpios;
1923c94d2d0SStefan Agner 	const char *gpio_compatible;
19325cbac77SMasahiro Yamada 	const struct pinctrl_pin_desc *pins;
19425cbac77SMasahiro Yamada 	unsigned npins;
195*fad57233SThierry Reding 	const char * const *functions;
19625cbac77SMasahiro Yamada 	unsigned nfunctions;
19725cbac77SMasahiro Yamada 	const struct tegra_pingroup *groups;
19825cbac77SMasahiro Yamada 	unsigned ngroups;
19925cbac77SMasahiro Yamada 	bool hsm_in_mux;
20025cbac77SMasahiro Yamada 	bool schmitt_in_mux;
20125cbac77SMasahiro Yamada 	bool drvtype_in_mux;
202368b62f2SThierry Reding 	bool sfsel_in_mux;
20325cbac77SMasahiro Yamada };
20425cbac77SMasahiro Yamada 
2059870acd3SSowjanya Komatineni extern const struct dev_pm_ops tegra_pinctrl_pm;
2069870acd3SSowjanya Komatineni 
20725cbac77SMasahiro Yamada int tegra_pinctrl_probe(struct platform_device *pdev,
20825cbac77SMasahiro Yamada 			const struct tegra_pinctrl_soc_data *soc_data);
20925cbac77SMasahiro Yamada #endif
210