xref: /openbmc/linux/drivers/pinctrl/tegra/pinctrl-tegra.h (revision cf75b8f2cd8f1f9beb64c2fa2eb93a7c265b59c1)
125cbac77SMasahiro Yamada /*
225cbac77SMasahiro Yamada  * Driver for the NVIDIA Tegra pinmux
325cbac77SMasahiro Yamada  *
425cbac77SMasahiro Yamada  * Copyright (c) 2011, NVIDIA CORPORATION.  All rights reserved.
525cbac77SMasahiro Yamada  *
625cbac77SMasahiro Yamada  * This program is free software; you can redistribute it and/or modify it
725cbac77SMasahiro Yamada  * under the terms and conditions of the GNU General Public License,
825cbac77SMasahiro Yamada  * version 2, as published by the Free Software Foundation.
925cbac77SMasahiro Yamada  *
1025cbac77SMasahiro Yamada  * This program is distributed in the hope it will be useful, but WITHOUT
1125cbac77SMasahiro Yamada  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1225cbac77SMasahiro Yamada  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1325cbac77SMasahiro Yamada  * more details.
1425cbac77SMasahiro Yamada  */
1525cbac77SMasahiro Yamada 
1625cbac77SMasahiro Yamada #ifndef __PINMUX_TEGRA_H__
1725cbac77SMasahiro Yamada #define __PINMUX_TEGRA_H__
1825cbac77SMasahiro Yamada 
19c5948707SDmitry Osipenko struct tegra_pmx {
20c5948707SDmitry Osipenko 	struct device *dev;
21c5948707SDmitry Osipenko 	struct pinctrl_dev *pctl;
22c5948707SDmitry Osipenko 
23c5948707SDmitry Osipenko 	const struct tegra_pinctrl_soc_data *soc;
24c5948707SDmitry Osipenko 	const char **group_pins;
25c5948707SDmitry Osipenko 
26c5948707SDmitry Osipenko 	int nbanks;
27c5948707SDmitry Osipenko 	void __iomem **regs;
28c5948707SDmitry Osipenko };
29c5948707SDmitry Osipenko 
3025cbac77SMasahiro Yamada enum tegra_pinconf_param {
3125cbac77SMasahiro Yamada 	/* argument: tegra_pinconf_pull */
3225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_PULL,
3325cbac77SMasahiro Yamada 	/* argument: tegra_pinconf_tristate */
3425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_TRISTATE,
3525cbac77SMasahiro Yamada 	/* argument: Boolean */
3625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_ENABLE_INPUT,
3725cbac77SMasahiro Yamada 	/* argument: Boolean */
3825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_OPEN_DRAIN,
3925cbac77SMasahiro Yamada 	/* argument: Boolean */
4025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_LOCK,
4125cbac77SMasahiro Yamada 	/* argument: Boolean */
4225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_IORESET,
4325cbac77SMasahiro Yamada 	/* argument: Boolean */
4425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_RCV_SEL,
4525cbac77SMasahiro Yamada 	/* argument: Boolean */
4625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_HIGH_SPEED_MODE,
4725cbac77SMasahiro Yamada 	/* argument: Boolean */
4825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SCHMITT,
4925cbac77SMasahiro Yamada 	/* argument: Boolean */
5025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_LOW_POWER_MODE,
5125cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5225cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_DOWN_STRENGTH,
5325cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5425cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_UP_STRENGTH,
5525cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5625cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SLEW_RATE_FALLING,
5725cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
5825cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_SLEW_RATE_RISING,
5925cbac77SMasahiro Yamada 	/* argument: Integer, range is HW-dependant */
6025cbac77SMasahiro Yamada 	TEGRA_PINCONF_PARAM_DRIVE_TYPE,
6125cbac77SMasahiro Yamada };
6225cbac77SMasahiro Yamada 
6325cbac77SMasahiro Yamada enum tegra_pinconf_pull {
6425cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_NONE,
6525cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_DOWN,
6625cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_PULL_UP,
6725cbac77SMasahiro Yamada };
6825cbac77SMasahiro Yamada 
6925cbac77SMasahiro Yamada enum tegra_pinconf_tristate {
7025cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_DRIVEN,
7125cbac77SMasahiro Yamada 	TEGRA_PINCONFIG_TRISTATE,
7225cbac77SMasahiro Yamada };
7325cbac77SMasahiro Yamada 
7425cbac77SMasahiro Yamada #define TEGRA_PINCONF_PACK(_param_, _arg_) ((_param_) << 16 | (_arg_))
7525cbac77SMasahiro Yamada #define TEGRA_PINCONF_UNPACK_PARAM(_conf_) ((_conf_) >> 16)
7625cbac77SMasahiro Yamada #define TEGRA_PINCONF_UNPACK_ARG(_conf_) ((_conf_) & 0xffff)
7725cbac77SMasahiro Yamada 
7825cbac77SMasahiro Yamada /**
7925cbac77SMasahiro Yamada  * struct tegra_function - Tegra pinctrl mux function
8025cbac77SMasahiro Yamada  * @name: The name of the function, exported to pinctrl core.
8125cbac77SMasahiro Yamada  * @groups: An array of pin groups that may select this function.
8225cbac77SMasahiro Yamada  * @ngroups: The number of entries in @groups.
8325cbac77SMasahiro Yamada  */
8425cbac77SMasahiro Yamada struct tegra_function {
8525cbac77SMasahiro Yamada 	const char *name;
8625cbac77SMasahiro Yamada 	const char **groups;
8725cbac77SMasahiro Yamada 	unsigned ngroups;
8825cbac77SMasahiro Yamada };
8925cbac77SMasahiro Yamada 
9025cbac77SMasahiro Yamada /**
9125cbac77SMasahiro Yamada  * struct tegra_pingroup - Tegra pin group
9225cbac77SMasahiro Yamada  * @name		The name of the pin group.
9325cbac77SMasahiro Yamada  * @pins		An array of pin IDs included in this pin group.
9425cbac77SMasahiro Yamada  * @npins		The number of entries in @pins.
9525cbac77SMasahiro Yamada  * @funcs		The mux functions which can be muxed onto this group.
9625cbac77SMasahiro Yamada  * @mux_reg:		Mux register offset.
9725cbac77SMasahiro Yamada  *			This register contains the mux, einput, odrain, lock,
9825cbac77SMasahiro Yamada  *			ioreset, rcv_sel parameters.
9925cbac77SMasahiro Yamada  * @mux_bank:		Mux register bank.
10025cbac77SMasahiro Yamada  * @mux_bit:		Mux register bit.
10125cbac77SMasahiro Yamada  * @pupd_reg:		Pull-up/down register offset.
10225cbac77SMasahiro Yamada  * @pupd_bank:		Pull-up/down register bank.
10325cbac77SMasahiro Yamada  * @pupd_bit:		Pull-up/down register bit.
10425cbac77SMasahiro Yamada  * @tri_reg:		Tri-state register offset.
10525cbac77SMasahiro Yamada  * @tri_bank:		Tri-state register bank.
10625cbac77SMasahiro Yamada  * @tri_bit:		Tri-state register bit.
10725cbac77SMasahiro Yamada  * @einput_bit:		Enable-input register bit.
10825cbac77SMasahiro Yamada  * @odrain_bit:		Open-drain register bit.
10925cbac77SMasahiro Yamada  * @lock_bit:		Lock register bit.
11025cbac77SMasahiro Yamada  * @ioreset_bit:	IO reset register bit.
11125cbac77SMasahiro Yamada  * @rcv_sel_bit:	Receiver select bit.
11225cbac77SMasahiro Yamada  * @drv_reg:		Drive fields register offset.
11325cbac77SMasahiro Yamada  *			This register contains hsm, schmitt, lpmd, drvdn,
11425cbac77SMasahiro Yamada  *			drvup, slwr, slwf, and drvtype parameters.
11525cbac77SMasahiro Yamada  * @drv_bank:		Drive fields register bank.
11625cbac77SMasahiro Yamada  * @hsm_bit:		High Speed Mode register bit.
11725cbac77SMasahiro Yamada  * @schmitt_bit:	Scmitt register bit.
11825cbac77SMasahiro Yamada  * @lpmd_bit:		Low Power Mode register bit.
11925cbac77SMasahiro Yamada  * @drvdn_bit:		Drive Down register bit.
12025cbac77SMasahiro Yamada  * @drvdn_width:	Drive Down field width.
12125cbac77SMasahiro Yamada  * @drvup_bit:		Drive Up register bit.
12225cbac77SMasahiro Yamada  * @drvup_width:	Drive Up field width.
12325cbac77SMasahiro Yamada  * @slwr_bit:		Slew Rising register bit.
12425cbac77SMasahiro Yamada  * @slwr_width:		Slew Rising field width.
12525cbac77SMasahiro Yamada  * @slwf_bit:		Slew Falling register bit.
12625cbac77SMasahiro Yamada  * @slwf_width:		Slew Falling field width.
12725cbac77SMasahiro Yamada  * @drvtype_bit:	Drive type register bit.
128*cf75b8f2SThierry Reding  * @parked_bitmask:	Parked register mask. 0 if unsupported.
12925cbac77SMasahiro Yamada  *
13025cbac77SMasahiro Yamada  * -1 in a *_reg field means that feature is unsupported for this group.
13125cbac77SMasahiro Yamada  * *_bank and *_reg values are irrelevant when *_reg is -1.
13225cbac77SMasahiro Yamada  * When *_reg is valid, *_bit may be -1 to indicate an unsupported feature.
13325cbac77SMasahiro Yamada  *
13425cbac77SMasahiro Yamada  * A representation of a group of pins (possibly just one pin) in the Tegra
13525cbac77SMasahiro Yamada  * pin controller. Each group allows some parameter or parameters to be
13625cbac77SMasahiro Yamada  * configured. The most common is mux function selection. Many others exist
13725cbac77SMasahiro Yamada  * such as pull-up/down, tri-state, etc. Tegra's pin controller is complex;
13825cbac77SMasahiro Yamada  * certain groups may only support configuring certain parameters, hence
13925cbac77SMasahiro Yamada  * each parameter is optional.
14025cbac77SMasahiro Yamada  */
14125cbac77SMasahiro Yamada struct tegra_pingroup {
14225cbac77SMasahiro Yamada 	const char *name;
14325cbac77SMasahiro Yamada 	const unsigned *pins;
14425cbac77SMasahiro Yamada 	u8 npins;
14525cbac77SMasahiro Yamada 	u8 funcs[4];
146b4e18ba2SKrishna Yarlagadda 	s32 mux_reg;
147b4e18ba2SKrishna Yarlagadda 	s32 pupd_reg;
148b4e18ba2SKrishna Yarlagadda 	s32 tri_reg;
149b4e18ba2SKrishna Yarlagadda 	s32 drv_reg;
15025cbac77SMasahiro Yamada 	u32 mux_bank:2;
15125cbac77SMasahiro Yamada 	u32 pupd_bank:2;
15225cbac77SMasahiro Yamada 	u32 tri_bank:2;
15325cbac77SMasahiro Yamada 	u32 drv_bank:2;
15425cbac77SMasahiro Yamada 	s32 mux_bit:6;
15525cbac77SMasahiro Yamada 	s32 pupd_bit:6;
15625cbac77SMasahiro Yamada 	s32 tri_bit:6;
15725cbac77SMasahiro Yamada 	s32 einput_bit:6;
15825cbac77SMasahiro Yamada 	s32 odrain_bit:6;
15925cbac77SMasahiro Yamada 	s32 lock_bit:6;
16025cbac77SMasahiro Yamada 	s32 ioreset_bit:6;
16125cbac77SMasahiro Yamada 	s32 rcv_sel_bit:6;
16225cbac77SMasahiro Yamada 	s32 hsm_bit:6;
16325cbac77SMasahiro Yamada 	s32 schmitt_bit:6;
16425cbac77SMasahiro Yamada 	s32 lpmd_bit:6;
16525cbac77SMasahiro Yamada 	s32 drvdn_bit:6;
16625cbac77SMasahiro Yamada 	s32 drvup_bit:6;
16725cbac77SMasahiro Yamada 	s32 slwr_bit:6;
16825cbac77SMasahiro Yamada 	s32 slwf_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;
174*cf75b8f2SThierry 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;
19525cbac77SMasahiro Yamada 	struct tegra_function *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;
20225cbac77SMasahiro Yamada };
20325cbac77SMasahiro Yamada 
20425cbac77SMasahiro Yamada int tegra_pinctrl_probe(struct platform_device *pdev,
20525cbac77SMasahiro Yamada 			const struct tegra_pinctrl_soc_data *soc_data);
20625cbac77SMasahiro Yamada #endif
207