xref: /openbmc/u-boot/include/dm/pinctrl.h (revision 7436f5e54d35bcad53befec90e2e67288071f74e)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2d90a5a30SMasahiro Yamada /*
3d90a5a30SMasahiro Yamada  * Copyright (C) 2015  Masahiro Yamada <yamada.masahiro@socionext.com>
4d90a5a30SMasahiro Yamada  */
5d90a5a30SMasahiro Yamada 
6d90a5a30SMasahiro Yamada #ifndef __PINCTRL_H
7d90a5a30SMasahiro Yamada #define __PINCTRL_H
8d90a5a30SMasahiro Yamada 
9d5a83139SPatrice Chotard #define PINNAME_SIZE	10
10d5a83139SPatrice Chotard #define PINMUX_SIZE	40
11d5a83139SPatrice Chotard 
12d90a5a30SMasahiro Yamada /**
13d90a5a30SMasahiro Yamada  * struct pinconf_param - pin config parameters
14d90a5a30SMasahiro Yamada  *
15d90a5a30SMasahiro Yamada  * @property: property name in DT nodes
16d90a5a30SMasahiro Yamada  * @param: ID for this config parameter
17d90a5a30SMasahiro Yamada  * @default_value: default value for this config parameter used in case
18d90a5a30SMasahiro Yamada  *	no value is specified in DT nodes
19d90a5a30SMasahiro Yamada  */
20d90a5a30SMasahiro Yamada struct pinconf_param {
21d90a5a30SMasahiro Yamada 	const char * const property;
22d90a5a30SMasahiro Yamada 	unsigned int param;
23d90a5a30SMasahiro Yamada 	u32 default_value;
24d90a5a30SMasahiro Yamada };
25d90a5a30SMasahiro Yamada 
26d90a5a30SMasahiro Yamada /**
27d90a5a30SMasahiro Yamada  * struct pinctrl_ops - pin control operations, to be implemented by
28d90a5a30SMasahiro Yamada  * pin controller drivers.
29d90a5a30SMasahiro Yamada  *
30d90a5a30SMasahiro Yamada  * The @set_state is the only mandatory operation.  You can implement your
31d90a5a30SMasahiro Yamada  * pinctrl driver with its own @set_state.  In this case, the other callbacks
32d90a5a30SMasahiro Yamada  * are not required.  Otherwise, generic pinctrl framework is also available;
33d90a5a30SMasahiro Yamada  * use pinctrl_generic_set_state for @set_state, and implement other operations
34d90a5a30SMasahiro Yamada  * depending on your necessity.
35d90a5a30SMasahiro Yamada  *
36d90a5a30SMasahiro Yamada  * @get_pins_count: return number of selectable named pins available
37d90a5a30SMasahiro Yamada  *	in this driver.  (necessary to parse "pins" property in DTS)
38d90a5a30SMasahiro Yamada  * @get_pin_name: return the pin name of the pin selector,
39d90a5a30SMasahiro Yamada  *	called by the core to figure out which pin it shall do
40d90a5a30SMasahiro Yamada  *	operations to.  (necessary to parse "pins" property in DTS)
41d90a5a30SMasahiro Yamada  * @get_groups_count: return number of selectable named groups available
42d90a5a30SMasahiro Yamada  *	in this driver.  (necessary to parse "groups" property in DTS)
43d90a5a30SMasahiro Yamada  * @get_group_name: return the group name of the group selector,
44d90a5a30SMasahiro Yamada  *	called by the core to figure out which pin group it shall do
45d90a5a30SMasahiro Yamada  *	operations to.  (necessary to parse "groups" property in DTS)
46d90a5a30SMasahiro Yamada  * @get_functions_count: return number of selectable named functions available
47d90a5a30SMasahiro Yamada  *	in this driver.  (necessary for pin-muxing)
48d90a5a30SMasahiro Yamada  * @get_function_name: return the function name of the muxing selector,
49d90a5a30SMasahiro Yamada  *	called by the core to figure out which mux setting it shall map a
50d90a5a30SMasahiro Yamada  *	certain device to.  (necessary for pin-muxing)
51d90a5a30SMasahiro Yamada  * @pinmux_set: enable a certain muxing function with a certain pin.
52d90a5a30SMasahiro Yamada  *	The @func_selector selects a certain function whereas @pin_selector
53d90a5a30SMasahiro Yamada  *	selects a certain pin to be used. On simple controllers one of them
54d90a5a30SMasahiro Yamada  *	may be ignored.  (necessary for pin-muxing against a single pin)
55d90a5a30SMasahiro Yamada  * @pinmux_group_set: enable a certain muxing function with a certain pin
56d90a5a30SMasahiro Yamada  *	group.  The @func_selector selects a certain function whereas
57d90a5a30SMasahiro Yamada  *	@group_selector selects a certain set of pins to be used. On simple
58d90a5a30SMasahiro Yamada  *	controllers one of them may be ignored.
59d90a5a30SMasahiro Yamada  *	(necessary for pin-muxing against a pin group)
60d90a5a30SMasahiro Yamada  * @pinconf_num_params: number of driver-specific parameters to be parsed
61d90a5a30SMasahiro Yamada  *	from device trees  (necessary for pin-configuration)
62d90a5a30SMasahiro Yamada  * @pinconf_params: list of driver_specific parameters to be parsed from
63d90a5a30SMasahiro Yamada  *	device trees  (necessary for pin-configuration)
64d90a5a30SMasahiro Yamada  * @pinconf_set: configure an individual pin with a given parameter.
65d90a5a30SMasahiro Yamada  *	(necessary for pin-configuration against a single pin)
66d90a5a30SMasahiro Yamada  * @pinconf_group_set: configure all pins in a group with a given parameter.
67d90a5a30SMasahiro Yamada  *	(necessary for pin-configuration against a pin group)
68d90a5a30SMasahiro Yamada  * @set_state: do pinctrl operations specified by @config, a pseudo device
69d90a5a30SMasahiro Yamada  *	pointing a config node. (necessary for pinctrl_full)
70d90a5a30SMasahiro Yamada  * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
71d90a5a30SMasahiro Yamada  *	(necessary for pinctrl_simple)
72f55a0c0aSPatrice Chotard  * @get_pin_muxing: display the muxing of a given pin.
73d90a5a30SMasahiro Yamada  */
74d90a5a30SMasahiro Yamada struct pinctrl_ops {
75d90a5a30SMasahiro Yamada 	int (*get_pins_count)(struct udevice *dev);
76d90a5a30SMasahiro Yamada 	const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
77d90a5a30SMasahiro Yamada 	int (*get_groups_count)(struct udevice *dev);
78d90a5a30SMasahiro Yamada 	const char *(*get_group_name)(struct udevice *dev, unsigned selector);
79d90a5a30SMasahiro Yamada 	int (*get_functions_count)(struct udevice *dev);
80d90a5a30SMasahiro Yamada 	const char *(*get_function_name)(struct udevice *dev,
81d90a5a30SMasahiro Yamada 					 unsigned selector);
82d90a5a30SMasahiro Yamada 	int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
83d90a5a30SMasahiro Yamada 			  unsigned func_selector);
84d90a5a30SMasahiro Yamada 	int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
85d90a5a30SMasahiro Yamada 				unsigned func_selector);
86d90a5a30SMasahiro Yamada 	unsigned int pinconf_num_params;
87d90a5a30SMasahiro Yamada 	const struct pinconf_param *pinconf_params;
88d90a5a30SMasahiro Yamada 	int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
89d90a5a30SMasahiro Yamada 			   unsigned param, unsigned argument);
90d90a5a30SMasahiro Yamada 	int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
91d90a5a30SMasahiro Yamada 				 unsigned param, unsigned argument);
92d90a5a30SMasahiro Yamada 	int (*set_state)(struct udevice *dev, struct udevice *config);
93c5acf4a2SSimon Glass 
94c5acf4a2SSimon Glass 	/* for pinctrl-simple */
95d90a5a30SMasahiro Yamada 	int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
96c5acf4a2SSimon Glass 	/**
97c5acf4a2SSimon Glass 	 * request() - Request a particular pinctrl function
98c5acf4a2SSimon Glass 	 *
99c5acf4a2SSimon Glass 	 * This activates the selected function.
100c5acf4a2SSimon Glass 	 *
101c5acf4a2SSimon Glass 	 * @dev:	Device to adjust (UCLASS_PINCTRL)
102c5acf4a2SSimon Glass 	 * @func:	Function number (driver-specific)
103c5acf4a2SSimon Glass 	 * @return 0 if OK, -ve on error
104c5acf4a2SSimon Glass 	 */
105c5acf4a2SSimon Glass 	int (*request)(struct udevice *dev, int func, int flags);
106c5acf4a2SSimon Glass 
107c5acf4a2SSimon Glass 	/**
108c5acf4a2SSimon Glass 	* get_periph_id() - get the peripheral ID for a device
109c5acf4a2SSimon Glass 	*
110c5acf4a2SSimon Glass 	* This generally looks at the peripheral's device tree node to work
111c5acf4a2SSimon Glass 	* out the peripheral ID. The return value is normally interpreted as
112c5acf4a2SSimon Glass 	* enum periph_id. so long as this is defined by the platform (which it
113c5acf4a2SSimon Glass 	* should be).
114c5acf4a2SSimon Glass 	*
115c5acf4a2SSimon Glass 	* @dev:		Pinctrl device to use for decoding
116c5acf4a2SSimon Glass 	* @periph:	Device to check
117c5acf4a2SSimon Glass 	* @return peripheral ID of @periph, or -ENOENT on error
118c5acf4a2SSimon Glass 	*/
119c5acf4a2SSimon Glass 	int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
12077eaa19eSSimon Glass 
12177eaa19eSSimon Glass 	/**
12277eaa19eSSimon Glass 	 * get_gpio_mux() - get the mux value for a particular GPIO
12377eaa19eSSimon Glass 	 *
12477eaa19eSSimon Glass 	 * This allows the raw mux value for a GPIO to be obtained. It is
12577eaa19eSSimon Glass 	 * useful for displaying the function being used by that GPIO, such
12677eaa19eSSimon Glass 	 * as with the 'gpio' command. This function is internal to the GPIO
12777eaa19eSSimon Glass 	 * subsystem and should not be used by generic code. Typically it is
12877eaa19eSSimon Glass 	 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
12977eaa19eSSimon Glass 	 *
13077eaa19eSSimon Glass 	* @dev:		Pinctrl device to use
13177eaa19eSSimon Glass 	* @banknum:	GPIO bank number
13277eaa19eSSimon Glass 	* @index:	GPIO index within the bank
13377eaa19eSSimon Glass 	* @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
13477eaa19eSSimon Glass 	 */
13577eaa19eSSimon Glass 	int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
136f55a0c0aSPatrice Chotard 
137f55a0c0aSPatrice Chotard 	/**
138f55a0c0aSPatrice Chotard 	 * get_pin_muxing() - show pin muxing
139f55a0c0aSPatrice Chotard 	 *
140f55a0c0aSPatrice Chotard 	 * This allows to display the muxing of a given pin. It's useful for
141f55a0c0aSPatrice Chotard 	 * debug purpose to know if a pin is configured as GPIO or as an
142f55a0c0aSPatrice Chotard 	 * alternate function and which one.
143f55a0c0aSPatrice Chotard 	 * Typically it is used by a PINCTRL driver with knowledge of the SoC
144f55a0c0aSPatrice Chotard 	 * pinctrl setup.
145f55a0c0aSPatrice Chotard 	 *
146f55a0c0aSPatrice Chotard 	 * @dev:	Pinctrl device to use
147f55a0c0aSPatrice Chotard 	 * @selector:	Pin selector
148f55a0c0aSPatrice Chotard 	 * @buf		Pin's muxing description
149f55a0c0aSPatrice Chotard 	 * @size	Pin's muxing description length
150f55a0c0aSPatrice Chotard 	 * return 0 if OK, -ve on error
151f55a0c0aSPatrice Chotard 	 */
152f55a0c0aSPatrice Chotard 	 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
153f55a0c0aSPatrice Chotard 			       char *buf, int size);
154d90a5a30SMasahiro Yamada };
155d90a5a30SMasahiro Yamada 
156d90a5a30SMasahiro Yamada #define pinctrl_get_ops(dev)	((struct pinctrl_ops *)(dev)->driver->ops)
157d90a5a30SMasahiro Yamada 
158d90a5a30SMasahiro Yamada /**
159d90a5a30SMasahiro Yamada  * Generic pin configuration paramters
160d90a5a30SMasahiro Yamada  *
1610fe4e418SPeng Fan  * enum pin_config_param - possible pin configuration parameters
1620fe4e418SPeng Fan  * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
1630fe4e418SPeng Fan  *	weakly drives the last value on a tristate bus, also known as a "bus
1640fe4e418SPeng Fan  *	holder", "bus keeper" or "repeater". This allows another device on the
1650fe4e418SPeng Fan  *	bus to change the value by driving the bus high or low and switching to
1660fe4e418SPeng Fan  *	tristate. The argument is ignored.
167d90a5a30SMasahiro Yamada  * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
168d90a5a30SMasahiro Yamada  *	transition from say pull-up to pull-down implies that you disable
169d90a5a30SMasahiro Yamada  *	pull-up in the process, this setting disables all biasing.
170d90a5a30SMasahiro Yamada  * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
171d90a5a30SMasahiro Yamada  *	mode, also know as "third-state" (tristate) or "high-Z" or "floating".
172d90a5a30SMasahiro Yamada  *	On output pins this effectively disconnects the pin, which is useful
173d90a5a30SMasahiro Yamada  *	if for example some other pin is going to drive the signal connected
174d90a5a30SMasahiro Yamada  *	to it for a while. Pins used for input are usually always high
175d90a5a30SMasahiro Yamada  *	impedance.
176d90a5a30SMasahiro Yamada  * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
177d90a5a30SMasahiro Yamada  *	impedance to GROUND). If the argument is != 0 pull-down is enabled,
178d90a5a30SMasahiro Yamada  *	if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
179d90a5a30SMasahiro Yamada  * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
180d90a5a30SMasahiro Yamada  *	on embedded knowledge of the controller hardware, like current mux
181d90a5a30SMasahiro Yamada  *	function. The pull direction and possibly strength too will normally
182d90a5a30SMasahiro Yamada  *	be decided completely inside the hardware block and not be readable
183d90a5a30SMasahiro Yamada  *	from the kernel side.
184d90a5a30SMasahiro Yamada  *	If the argument is != 0 pull up/down is enabled, if it is 0, the
185d90a5a30SMasahiro Yamada  *	configuration is ignored. The proper way to disable it is to use
186d90a5a30SMasahiro Yamada  *	@PIN_CONFIG_BIAS_DISABLE.
1870fe4e418SPeng Fan  * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
1880fe4e418SPeng Fan  *	impedance to VDD). If the argument is != 0 pull-up is enabled,
1890fe4e418SPeng Fan  *	if it is 0, pull-up is total, i.e. the pin is connected to VDD.
190d90a5a30SMasahiro Yamada  * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
191d90a5a30SMasahiro Yamada  *	collector) which means it is usually wired with other output ports
192d90a5a30SMasahiro Yamada  *	which are then pulled up with an external resistor. Setting this
193d90a5a30SMasahiro Yamada  *	config will enable open drain mode, the argument is ignored.
194d90a5a30SMasahiro Yamada  * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
195d90a5a30SMasahiro Yamada  *	(open emitter). Setting this config will enable open source mode, the
196d90a5a30SMasahiro Yamada  *	argument is ignored.
1970fe4e418SPeng Fan  * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
1980fe4e418SPeng Fan  *	low, this is the most typical case and is typically achieved with two
1990fe4e418SPeng Fan  *	active transistors on the output. Setting this config will enable
2000fe4e418SPeng Fan  *	push-pull mode, the argument is ignored.
201d90a5a30SMasahiro Yamada  * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
202d90a5a30SMasahiro Yamada  *	passed as argument. The argument is in mA.
203d90a5a30SMasahiro Yamada  * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
204d90a5a30SMasahiro Yamada  *	which means it will wait for signals to settle when reading inputs. The
205d90a5a30SMasahiro Yamada  *	argument gives the debounce time in usecs. Setting the
206d90a5a30SMasahiro Yamada  *	argument to zero turns debouncing off.
2070fe4e418SPeng Fan  * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input.  Note that this does not
2080fe4e418SPeng Fan  *	affect the pin's ability to drive output.  1 enables input, 0 disables
2090fe4e418SPeng Fan  *	input.
2100fe4e418SPeng Fan  * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
2110fe4e418SPeng Fan  *	schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
2120fe4e418SPeng Fan  *	the threshold value is given on a custom format as argument when
2130fe4e418SPeng Fan  *	setting pins to this mode.
2140fe4e418SPeng Fan  * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
2150fe4e418SPeng Fan  *      If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
2160fe4e418SPeng Fan  *      schmitt-trigger mode is disabled.
217d90a5a30SMasahiro Yamada  * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
218d90a5a30SMasahiro Yamada  *	operation, if several modes of operation are supported these can be
219d90a5a30SMasahiro Yamada  *	passed in the argument on a custom form, else just use argument 1
220d90a5a30SMasahiro Yamada  *	to indicate low power mode, argument 0 turns low power mode off.
2210fe4e418SPeng Fan  * @PIN_CONFIG_OUTPUT_ENABLE: this will enable the pin's output mode
2220fe4e418SPeng Fan  *	without driving a value there. For most platforms this reduces to
2230fe4e418SPeng Fan  *	enable the output buffers and then let the pin controller current
2240fe4e418SPeng Fan  *	configuration (eg. the currently selected mux function) drive values on
2250fe4e418SPeng Fan  *	the line. Use argument 1 to enable output mode, argument 0 to disable
2260fe4e418SPeng Fan  *	it.
2270fe4e418SPeng Fan  * @PIN_CONFIG_OUTPUT: this will configure the pin as an output and drive a
2280fe4e418SPeng Fan  *	value on the line. Use argument 1 to indicate high level, argument 0 to
2290fe4e418SPeng Fan  *	indicate low level. (Please see Documentation/driver-api/pinctl.rst,
2300fe4e418SPeng Fan  *	section "GPIO mode pitfalls" for a discussion around this parameter.)
2310fe4e418SPeng Fan  * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
2320fe4e418SPeng Fan  *	supplies, the argument to this parameter (on a custom format) tells
2330fe4e418SPeng Fan  *	the driver which alternative power source to use.
2340fe4e418SPeng Fan  * @PIN_CONFIG_SLEEP_HARDWARE_STATE: indicate this is sleep related state.
2350fe4e418SPeng Fan  * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
2360fe4e418SPeng Fan  *	this parameter (on a custom format) tells the driver which alternative
2370fe4e418SPeng Fan  *	slew rate to use.
2380fe4e418SPeng Fan  * @PIN_CONFIG_SKEW_DELAY: if the pin has programmable skew rate (on inputs)
2390fe4e418SPeng Fan  *	or latch delay (on outputs) this parameter (in a custom format)
2400fe4e418SPeng Fan  *	specifies the clock skew or latch delay. It typically controls how
2410fe4e418SPeng Fan  *	many double inverters are put in front of the line.
242d90a5a30SMasahiro Yamada  * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
243d90a5a30SMasahiro Yamada  *	you need to pass in custom configurations to the pin controller, use
244d90a5a30SMasahiro Yamada  *	PIN_CONFIG_END+1 as the base offset.
2450fe4e418SPeng Fan  * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
2460fe4e418SPeng Fan  *	presented using the packed format.
247d90a5a30SMasahiro Yamada  */
2480fe4e418SPeng Fan enum pin_config_param {
2490fe4e418SPeng Fan 	PIN_CONFIG_BIAS_BUS_HOLD,
2500fe4e418SPeng Fan 	PIN_CONFIG_BIAS_DISABLE,
2510fe4e418SPeng Fan 	PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
2520fe4e418SPeng Fan 	PIN_CONFIG_BIAS_PULL_DOWN,
2530fe4e418SPeng Fan 	PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
2540fe4e418SPeng Fan 	PIN_CONFIG_BIAS_PULL_UP,
2550fe4e418SPeng Fan 	PIN_CONFIG_DRIVE_OPEN_DRAIN,
2560fe4e418SPeng Fan 	PIN_CONFIG_DRIVE_OPEN_SOURCE,
2570fe4e418SPeng Fan 	PIN_CONFIG_DRIVE_PUSH_PULL,
2580fe4e418SPeng Fan 	PIN_CONFIG_DRIVE_STRENGTH,
2590fe4e418SPeng Fan 	PIN_CONFIG_INPUT_DEBOUNCE,
2600fe4e418SPeng Fan 	PIN_CONFIG_INPUT_ENABLE,
2610fe4e418SPeng Fan 	PIN_CONFIG_INPUT_SCHMITT,
2620fe4e418SPeng Fan 	PIN_CONFIG_INPUT_SCHMITT_ENABLE,
2630fe4e418SPeng Fan 	PIN_CONFIG_LOW_POWER_MODE,
2640fe4e418SPeng Fan 	PIN_CONFIG_OUTPUT_ENABLE,
2650fe4e418SPeng Fan 	PIN_CONFIG_OUTPUT,
2660fe4e418SPeng Fan 	PIN_CONFIG_POWER_SOURCE,
2670fe4e418SPeng Fan 	PIN_CONFIG_SLEEP_HARDWARE_STATE,
2680fe4e418SPeng Fan 	PIN_CONFIG_SLEW_RATE,
2690fe4e418SPeng Fan 	PIN_CONFIG_SKEW_DELAY,
2700fe4e418SPeng Fan 	PIN_CONFIG_END = 0x7F,
2710fe4e418SPeng Fan 	PIN_CONFIG_MAX = 0xFF,
2720fe4e418SPeng Fan };
273d90a5a30SMasahiro Yamada 
274d90a5a30SMasahiro Yamada #if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
275d90a5a30SMasahiro Yamada /**
276d90a5a30SMasahiro Yamada  * pinctrl_generic_set_state() - generic set_state operation
277d90a5a30SMasahiro Yamada  * Parse the DT node of @config and its children and handle generic properties
278d90a5a30SMasahiro Yamada  * such as "pins", "groups", "functions", and pin configuration parameters.
279d90a5a30SMasahiro Yamada  *
280d90a5a30SMasahiro Yamada  * @pctldev: pinctrl device
281d90a5a30SMasahiro Yamada  * @config: config device (pseudo device), pointing a config node in DTS
282d90a5a30SMasahiro Yamada  * @return: 0 on success, or negative error code on failure
283d90a5a30SMasahiro Yamada  */
284d90a5a30SMasahiro Yamada int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
285d90a5a30SMasahiro Yamada #else
pinctrl_generic_set_state(struct udevice * pctldev,struct udevice * config)286d90a5a30SMasahiro Yamada static inline int pinctrl_generic_set_state(struct udevice *pctldev,
287d90a5a30SMasahiro Yamada 					    struct udevice *config)
288d90a5a30SMasahiro Yamada {
289d90a5a30SMasahiro Yamada 	return -EINVAL;
290d90a5a30SMasahiro Yamada }
291d90a5a30SMasahiro Yamada #endif
292d90a5a30SMasahiro Yamada 
293d90a5a30SMasahiro Yamada #if CONFIG_IS_ENABLED(PINCTRL)
294d90a5a30SMasahiro Yamada /**
295d90a5a30SMasahiro Yamada  * pinctrl_select_state() - set a device to a given state
296d90a5a30SMasahiro Yamada  *
297d90a5a30SMasahiro Yamada  * @dev: peripheral device
298d90a5a30SMasahiro Yamada  * @statename: state name, like "default"
299d90a5a30SMasahiro Yamada  * @return: 0 on success, or negative error code on failure
300d90a5a30SMasahiro Yamada  */
301d90a5a30SMasahiro Yamada int pinctrl_select_state(struct udevice *dev, const char *statename);
302d90a5a30SMasahiro Yamada #else
pinctrl_select_state(struct udevice * dev,const char * statename)303d90a5a30SMasahiro Yamada static inline int pinctrl_select_state(struct udevice *dev,
304d90a5a30SMasahiro Yamada 				       const char *statename)
305d90a5a30SMasahiro Yamada {
306d90a5a30SMasahiro Yamada 	return -EINVAL;
307d90a5a30SMasahiro Yamada }
308d90a5a30SMasahiro Yamada #endif
309d90a5a30SMasahiro Yamada 
310c5acf4a2SSimon Glass /**
311c5acf4a2SSimon Glass  * pinctrl_request() - Request a particular pinctrl function
312c5acf4a2SSimon Glass  *
313c5acf4a2SSimon Glass  * @dev:	Device to check (UCLASS_PINCTRL)
314c5acf4a2SSimon Glass  * @func:	Function number (driver-specific)
315c5acf4a2SSimon Glass  * @flags:	Flags (driver-specific)
316c5acf4a2SSimon Glass  * @return 0 if OK, -ve on error
317c5acf4a2SSimon Glass  */
318c5acf4a2SSimon Glass int pinctrl_request(struct udevice *dev, int func, int flags);
319c5acf4a2SSimon Glass 
320c5acf4a2SSimon Glass /**
321c5acf4a2SSimon Glass  * pinctrl_request_noflags() - Request a particular pinctrl function
322c5acf4a2SSimon Glass  *
323c5acf4a2SSimon Glass  * This is similar to pinctrl_request() but uses 0 for @flags.
324c5acf4a2SSimon Glass  *
325c5acf4a2SSimon Glass  * @dev:	Device to check (UCLASS_PINCTRL)
326c5acf4a2SSimon Glass  * @func:	Function number (driver-specific)
327c5acf4a2SSimon Glass  * @return 0 if OK, -ve on error
328c5acf4a2SSimon Glass  */
329c5acf4a2SSimon Glass int pinctrl_request_noflags(struct udevice *dev, int func);
330c5acf4a2SSimon Glass 
331c5acf4a2SSimon Glass /**
332c5acf4a2SSimon Glass  * pinctrl_get_periph_id() - get the peripheral ID for a device
333c5acf4a2SSimon Glass  *
334c5acf4a2SSimon Glass  * This generally looks at the peripheral's device tree node to work out the
335c5acf4a2SSimon Glass  * peripheral ID. The return value is normally interpreted as enum periph_id.
336c5acf4a2SSimon Glass  * so long as this is defined by the platform (which it should be).
337c5acf4a2SSimon Glass  *
338c5acf4a2SSimon Glass  * @dev:	Pinctrl device to use for decoding
339c5acf4a2SSimon Glass  * @periph:	Device to check
340c5acf4a2SSimon Glass  * @return peripheral ID of @periph, or -ENOENT on error
341c5acf4a2SSimon Glass  */
342c5acf4a2SSimon Glass int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
343c5acf4a2SSimon Glass 
34452db39a2SSimon Glass /**
34552db39a2SSimon Glass  * pinctrl_decode_pin_config() - decode pin configuration flags
34652db39a2SSimon Glass  *
34752db39a2SSimon Glass  * This decodes some of the PIN_CONFIG values into flags, with each value
34852db39a2SSimon Glass  * being (1 << pin_cfg). This does not support things with values like the
34952db39a2SSimon Glass  * slew rate.
35052db39a2SSimon Glass  *
35152db39a2SSimon Glass  * @blob:	Device tree blob
35252db39a2SSimon Glass  * @node:	Node containing the PIN_CONFIG values
35352db39a2SSimon Glass  * @return decoded flag value, or -ve on error
35452db39a2SSimon Glass  */
35552db39a2SSimon Glass int pinctrl_decode_pin_config(const void *blob, int node);
35652db39a2SSimon Glass 
35777eaa19eSSimon Glass /**
358*5ff77688SChristoph Muellner  * pinctrl_decode_pin_config_dm() - decode pin configuration flags
359*5ff77688SChristoph Muellner  *
360*5ff77688SChristoph Muellner  * This decodes some of the PIN_CONFIG values into flags, with each value
361*5ff77688SChristoph Muellner  * being (1 << pin_cfg). This does not support things with values like the
362*5ff77688SChristoph Muellner  * slew rate.
363*5ff77688SChristoph Muellner  *
364*5ff77688SChristoph Muellner  * @pinconfig:	Pinconfig udevice
365*5ff77688SChristoph Muellner  * @return decoded flag value, or -ve on error
366*5ff77688SChristoph Muellner  */
367*5ff77688SChristoph Muellner int pinctrl_decode_pin_config_dm(struct udevice *dev);
368*5ff77688SChristoph Muellner 
369*5ff77688SChristoph Muellner /**
37077eaa19eSSimon Glass  * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
37177eaa19eSSimon Glass  *
37277eaa19eSSimon Glass  * This allows the raw mux value for a GPIO to be obtained. It is
37377eaa19eSSimon Glass  * useful for displaying the function being used by that GPIO, such
37477eaa19eSSimon Glass  * as with the 'gpio' command. This function is internal to the GPIO
37577eaa19eSSimon Glass  * subsystem and should not be used by generic code. Typically it is
37677eaa19eSSimon Glass  * used by a GPIO driver with knowledge of the SoC pinctrl setup.
37777eaa19eSSimon Glass  *
37877eaa19eSSimon Glass  * @dev:	Pinctrl device to use
37977eaa19eSSimon Glass  * @banknum:	GPIO bank number
38077eaa19eSSimon Glass  * @index:	GPIO index within the bank
38177eaa19eSSimon Glass  * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
38277eaa19eSSimon Glass */
38377eaa19eSSimon Glass int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
38477eaa19eSSimon Glass 
385f55a0c0aSPatrice Chotard /**
386f55a0c0aSPatrice Chotard  * pinctrl_get_pin_muxing() - Returns the muxing description
387f55a0c0aSPatrice Chotard  *
388f55a0c0aSPatrice Chotard  * This allows to display the muxing description of the given pin for
389f55a0c0aSPatrice Chotard  * debug purpose
390f55a0c0aSPatrice Chotard  *
391f55a0c0aSPatrice Chotard  * @dev:	Pinctrl device to use
392f55a0c0aSPatrice Chotard  * @selector	Pin index within pin-controller
393f55a0c0aSPatrice Chotard  * @buf		Pin's muxing description
394f55a0c0aSPatrice Chotard  * @size	Pin's muxing description length
395f55a0c0aSPatrice Chotard  * @return 0 if OK, -ve on error
396f55a0c0aSPatrice Chotard  */
397f55a0c0aSPatrice Chotard int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
398f55a0c0aSPatrice Chotard 			   int size);
399f55a0c0aSPatrice Chotard 
4008bbb5b20SPatrice Chotard /**
4018bbb5b20SPatrice Chotard  * pinctrl_get_pins_count() - display pin-controller pins number
4028bbb5b20SPatrice Chotard  *
4038bbb5b20SPatrice Chotard  * This allows to know the number of pins owned by a given pin-controller
4048bbb5b20SPatrice Chotard  *
4058bbb5b20SPatrice Chotard  * @dev:	Pinctrl device to use
4068bbb5b20SPatrice Chotard  * @return pins number if OK, -ve on error
4078bbb5b20SPatrice Chotard  */
4088bbb5b20SPatrice Chotard int pinctrl_get_pins_count(struct udevice *dev);
4098bbb5b20SPatrice Chotard 
4108bbb5b20SPatrice Chotard /**
4118bbb5b20SPatrice Chotard  * pinctrl_get_pin_name() - Returns the pin's name
4128bbb5b20SPatrice Chotard  *
4138bbb5b20SPatrice Chotard  * This allows to display the pin's name for debug purpose
4148bbb5b20SPatrice Chotard  *
4158bbb5b20SPatrice Chotard  * @dev:	Pinctrl device to use
4168bbb5b20SPatrice Chotard  * @selector	Pin index within pin-controller
4178bbb5b20SPatrice Chotard  * @buf		Pin's name
4188bbb5b20SPatrice Chotard  * @return 0 if OK, -ve on error
4198bbb5b20SPatrice Chotard  */
4208bbb5b20SPatrice Chotard int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
4218bbb5b20SPatrice Chotard 			 int size);
422d90a5a30SMasahiro Yamada #endif /* __PINCTRL_H */
423