blob: e41baea6200c313ed2a3d1ef595979665a3acac5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +09002/*
Sean Andersonabe2a6b2020-09-14 11:01:56 -04003 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@com>
Masahiro Yamadaf8efa632015-08-27 12:44:29 +09004 */
5
6#ifndef __PINCTRL_H
7#define __PINCTRL_H
8
Max Krummenacher0e226eb2024-01-18 19:10:47 +01009#include <linux/errno.h>
10
Patrice Chotardc4b4ef02018-10-24 14:10:17 +020011#define PINNAME_SIZE 10
Venkatesh Yadav Abbarapu0b9d9922023-09-20 08:30:06 +053012#define PINMUX_SIZE 90
Patrice Chotardc4b4ef02018-10-24 14:10:17 +020013
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090014/**
15 * struct pinconf_param - pin config parameters
Sean Andersonabe2a6b2020-09-14 11:01:56 -040016 * @property: Property name in DT nodes
17 * @param: ID for this config parameter
18 * @default_value: default value for this config parameter used in case
19 * no value is specified in DT nodes
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090020 */
21struct pinconf_param {
22 const char * const property;
23 unsigned int param;
24 u32 default_value;
25};
26
27/**
28 * struct pinctrl_ops - pin control operations, to be implemented by
29 * pin controller drivers.
30 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -040031 * set_state() is the only mandatory operation. You can implement your pinctrl
32 * driver with its own @set_state. In this case, the other callbacks are not
33 * required. Otherwise, generic pinctrl framework is also available; use
34 * pinctrl_generic_set_state for @set_state, and implement other operations
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090035 * depending on your necessity.
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090036 */
37struct pinctrl_ops {
Sean Andersonabe2a6b2020-09-14 11:01:56 -040038 /**
39 * @get_pins_count: Get the number of selectable pins
40 *
41 * @dev: Pinctrl device to use
42 *
43 * This function is necessary to parse the "pins" property in DTS.
44 *
45 * @Return:
46 * number of selectable named pins available in this driver
47 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090048 int (*get_pins_count)(struct udevice *dev);
Sean Andersonabe2a6b2020-09-14 11:01:56 -040049
50 /**
51 * @get_pin_name: Get the name of a pin
52 *
53 * @dev: Pinctrl device of the pin
54 *
55 * @selector: The pin selector
56 *
57 * This function is called by the core to figure out which pin it will
58 * do operations to. This function is necessary to parse the "pins"
59 * property in DTS.
60 *
61 * @Return: const pointer to the name of the pin
62 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090063 const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
Sean Andersonabe2a6b2020-09-14 11:01:56 -040064
65 /**
66 * @get_groups_count: Get the number of selectable groups
67 *
68 * @dev: Pinctrl device to use
69 *
70 * This function is necessary to parse the "groups" property in DTS.
71 *
72 * @Return:
73 * number of selectable named groups available in the driver
74 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090075 int (*get_groups_count)(struct udevice *dev);
Sean Andersonabe2a6b2020-09-14 11:01:56 -040076
77 /**
78 * @get_group_name: Get the name of a group
79 *
80 * @dev: Pinctrl device of the group
81 *
82 * @selector: The group selector
83 *
84 * This function is called by the core to figure out which group it
85 * will do operations to. This function is necessary to parse the
86 * "groups" property in DTS.
87 *
88 * @Return: Pointer to the name of the group
89 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090090 const char *(*get_group_name)(struct udevice *dev, unsigned selector);
Sean Andersonabe2a6b2020-09-14 11:01:56 -040091
92 /**
93 * @get_functions_count: Get the number of selectable functions
94 *
95 * @dev: Pinctrl device to use
96 *
97 * This function is necessary for pin-muxing.
98 *
99 * @Return:
100 * number of selectable named functions available in this driver
101 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900102 int (*get_functions_count)(struct udevice *dev);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400103
104 /**
105 * @get_function_name: Get the name of a function
106 *
107 * @dev: Pinmux device of the function
108 *
109 * @selector: The function selector
110 *
111 * This function is called by the core to figure out which mux setting
112 * it will map a certain device to. This function is necessary for
113 * pin-muxing.
114 *
115 * @Return:
116 * Pointer to the function name of the muxing selector
117 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900118 const char *(*get_function_name)(struct udevice *dev,
119 unsigned selector);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400120
121 /**
122 * @pinmux_set: Mux a pin to a function
123 *
124 * @dev: Pinctrl device to use
125 *
126 * @pin_selector: The pin selector
127 *
128 * @func_selector: The func selector
129 *
130 * On simple controllers one of @pin_selector or @func_selector may be
131 * ignored. This function is necessary for pin-muxing against a single
132 * pin.
133 *
134 * @Return: 0 if OK, or negative error code on failure
135 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900136 int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
137 unsigned func_selector);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400138
139 /**
140 * @pinmux_group_set: Mux a group of pins to a function
141 *
142 * @dev: Pinctrl device to use
143 *
144 * @group_selector: The group selector
145 *
146 * @func_selector: The func selector
147 *
148 * On simple controllers one of @group_selector or @func_selector may be
149 * ignored. This function is necessary for pin-muxing against a group of
150 * pins.
151 *
152 * @Return: 0 if OK, or negative error code on failure
153 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900154 int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
155 unsigned func_selector);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400156
157 /**
158 * @pinmux_property_set: Enable a pinmux group
159 *
160 * @dev: Pinctrl device to use
161 *
162 * @pinmux_group: A u32 representing the pin identifier and mux
163 * settings. The exact format of a pinmux group is left
164 * up to the driver.
165 *
166 * Mux a single pin to a single function based on a driver-specific
167 * pinmux group. This function is necessary for parsing the "pinmux"
168 * property in DTS, and for pin-muxing against a pinmux group.
169 *
170 * @Return:
171 * Pin selector for the muxed pin if OK, or negative error code on
172 * failure
173 */
Sean Anderson319ca702020-09-14 11:01:55 -0400174 int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400175
176 /**
177 * @pinconf_num_params:
178 * Number of driver-specific parameters to be parsed from device
179 * trees. This member is necessary for pin configuration.
180 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900181 unsigned int pinconf_num_params;
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400182
183 /**
184 * @pinconf_params:
185 * List of driver-specific parameters to be parsed from the device
186 * tree. This member is necessary for pin configuration.
187 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900188 const struct pinconf_param *pinconf_params;
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400189
190 /**
191 * @pinconf_set: Configure an individual pin with a parameter
192 *
193 * @dev: Pinctrl device to use
194 *
195 * @pin_selector: The pin selector
196 *
197 * @param: An &enum pin_config_param from @pinconf_params
198 *
199 * @argument: The argument to this param from the device tree, or
200 * @pinconf_params.default_value
201 *
202 * This function is necessary for pin configuration against a single
203 * pin.
204 *
205 * @Return: 0 if OK, or negative error code on failure
206 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900207 int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
208 unsigned param, unsigned argument);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400209
210 /**
211 * @pinconf_group_set: Configure all pins in a group with a parameter
212 *
213 * @dev: Pinctrl device to use
214 *
215 * @pin_selector: The group selector
216 *
217 * @param: A &enum pin_config_param from
218 * @pinconf_params
219 *
220 * @argument: The argument to this param from the device tree, or
221 * @pinconf_params.default_value
222 *
223 * This function is necessary for pin configuration against a group of
224 * pins.
225 *
226 * @Return: 0 if OK, or negative error code on failure
227 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900228 int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
229 unsigned param, unsigned argument);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400230
231 /**
232 * @set_state: Configure a pinctrl device
233 *
234 * @dev: Pinctrl device to use
235 *
236 * @config: Pseudo device pointing a config node
237 *
238 * This function is required to be implemented by all pinctrl drivers.
239 * Drivers may set this member to pinctrl_generic_set_state(), which
240 * will call other functions in &struct pinctrl_ops to parse
241 * @config.
242 *
243 * @Return: 0 if OK, or negative error code on failure
244 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900245 int (*set_state)(struct udevice *dev, struct udevice *config);
Simon Glassac2ee652015-08-30 16:55:13 -0600246
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400247 /**
248 * @set_state_simple: Configure a pinctrl device
249 *
250 * @dev: Pinctrl device to use
251 *
252 * @config: Pseudo-device pointing a config node
253 *
254 * This function is usually a simpler version of set_state(). Only the
255 * first pinctrl device on the system is supported by this function.
256 *
257 * @Return: 0 if OK, or negative error code on failure
258 */
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900259 int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400260
Simon Glassac2ee652015-08-30 16:55:13 -0600261 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400262 * @request: Request a particular pinctrl function
263 *
264 * @dev: Device to adjust (%UCLASS_PINCTRL)
265 *
266 * @func: Function number (driver-specific)
Simon Glassac2ee652015-08-30 16:55:13 -0600267 *
268 * This activates the selected function.
269 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400270 * @Return: 0 if OK, or negative error code on failure
Simon Glassac2ee652015-08-30 16:55:13 -0600271 */
272 int (*request)(struct udevice *dev, int func, int flags);
273
274 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400275 * @get_periph_id: Get the peripheral ID for a device
276 *
277 * @dev: Pinctrl device to use for decoding
278 *
279 * @periph: Device to check
Simon Glassac2ee652015-08-30 16:55:13 -0600280 *
281 * This generally looks at the peripheral's device tree node to work
282 * out the peripheral ID. The return value is normally interpreted as
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400283 * &enum periph_id. so long as this is defined by the platform (which it
Simon Glassac2ee652015-08-30 16:55:13 -0600284 * should be).
285 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400286 * @Return:
287 * Peripheral ID of @periph, or %-ENOENT on error
Simon Glassac2ee652015-08-30 16:55:13 -0600288 */
289 int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700290
291 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400292 * @get_gpio_mux: Get the mux value for a particular GPIO
293 *
294 * @dev: Pinctrl device to use
295 *
296 * @banknum: GPIO bank number
297 *
298 * @index: GPIO index within the bank
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700299 *
300 * This allows the raw mux value for a GPIO to be obtained. It is
301 * useful for displaying the function being used by that GPIO, such
302 * as with the 'gpio' command. This function is internal to the GPIO
303 * subsystem and should not be used by generic code. Typically it is
304 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
305 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400306 * @Return:
307 * Mux value (SoC-specific, e.g. 0 for input, 1 for output)
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700308 */
309 int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200310
311 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400312 * @get_pin_muxing: Show pin muxing
313 *
314 * @dev: Pinctrl device to use
315 *
316 * @selector: Pin selector
317 *
318 * @buf: Buffer to fill with pin muxing description
319 *
320 * @size: Size of @buf
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200321 *
322 * This allows to display the muxing of a given pin. It's useful for
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400323 * debug purposes to know if a pin is configured as GPIO or as an
324 * alternate function and which one. Typically it is used by a PINCTRL
325 * driver with knowledge of the SoC pinctrl setup.
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200326 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400327 * @Return: 0 if OK, or negative error code on failure
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200328 */
329 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
330 char *buf, int size);
Marek Vasut87510962019-04-21 23:57:23 +0200331
332 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400333 * @gpio_request_enable: Request and enable GPIO on a certain pin.
334 *
335 * @dev: Pinctrl device to use
336 *
337 * @selector: Pin selector
338 *
339 * Implement this only if you can mux every pin individually as GPIO.
340 * The affected GPIO range is passed along with an offset(pin number)
341 * into that specific GPIO range - function selectors and pin groups are
342 * orthogonal to this, the core will however make sure the pins do not
343 * collide.
Marek Vasut87510962019-04-21 23:57:23 +0200344 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400345 * @Return:
346 * 0 if OK, or negative error code on failure
Marek Vasut87510962019-04-21 23:57:23 +0200347 */
348 int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
349
350 /**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400351 * @gpio_disable_free: Free up GPIO muxing on a certain pin.
Marek Vasut87510962019-04-21 23:57:23 +0200352 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400353 * @dev: Pinctrl device to use
354 *
355 * @selector: Pin selector
356 *
357 * This function is the reverse of @gpio_request_enable.
358 *
359 * @Return: 0 if OK, or negative error code on failure
Marek Vasut87510962019-04-21 23:57:23 +0200360 */
361 int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900362};
363
364#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
365
366/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400367 * enum pin_config_param - Generic pin configuration parameters
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900368 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400369 * @PIN_CONFIG_BIAS_BUS_HOLD: The pin will be set to weakly latch so that it
Peng Fan99490a72018-01-05 14:05:17 +0800370 * weakly drives the last value on a tristate bus, also known as a "bus
371 * holder", "bus keeper" or "repeater". This allows another device on the
372 * bus to change the value by driving the bus high or low and switching to
373 * tristate. The argument is ignored.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400374 * @PIN_CONFIG_BIAS_DISABLE: Disable any pin bias on the pin, a
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900375 * transition from say pull-up to pull-down implies that you disable
376 * pull-up in the process, this setting disables all biasing.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400377 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: The pin will be set to a high impedance
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900378 * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
379 * On output pins this effectively disconnects the pin, which is useful
380 * if for example some other pin is going to drive the signal connected
381 * to it for a while. Pins used for input are usually always high
382 * impedance.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400383 * @PIN_CONFIG_BIAS_PULL_DOWN: The pin will be pulled down (usually with high
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900384 * impedance to GROUND). If the argument is != 0 pull-down is enabled,
385 * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400386 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: The pin will be pulled up or down based
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900387 * on embedded knowledge of the controller hardware, like current mux
388 * function. The pull direction and possibly strength too will normally
389 * be decided completely inside the hardware block and not be readable
390 * from the kernel side.
391 * If the argument is != 0 pull up/down is enabled, if it is 0, the
392 * configuration is ignored. The proper way to disable it is to use
393 * @PIN_CONFIG_BIAS_DISABLE.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400394 * @PIN_CONFIG_BIAS_PULL_UP: The pin will be pulled up (usually with high
Peng Fan99490a72018-01-05 14:05:17 +0800395 * impedance to VDD). If the argument is != 0 pull-up is enabled,
396 * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400397 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: The pin will be driven with open drain (open
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900398 * collector) which means it is usually wired with other output ports
399 * which are then pulled up with an external resistor. Setting this
400 * config will enable open drain mode, the argument is ignored.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400401 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: The pin will be driven with open source
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900402 * (open emitter). Setting this config will enable open source mode, the
403 * argument is ignored.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400404 * @PIN_CONFIG_DRIVE_PUSH_PULL: The pin will be driven actively high and
Peng Fan99490a72018-01-05 14:05:17 +0800405 * low, this is the most typical case and is typically achieved with two
406 * active transistors on the output. Setting this config will enable
407 * push-pull mode, the argument is ignored.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400408 * @PIN_CONFIG_DRIVE_STRENGTH: The pin will sink or source at most the current
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900409 * passed as argument. The argument is in mA.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400410 * @PIN_CONFIG_DRIVE_STRENGTH_UA: The pin will sink or source at most the
411 * current passed as argument. The argument is in uA.
412 * @PIN_CONFIG_INPUT_DEBOUNCE: This will configure the pin to debounce mode,
Peng Fan99490a72018-01-05 14:05:17 +0800413 * which means it will wait for signals to settle when reading inputs. The
414 * argument gives the debounce time in usecs. Setting the
415 * argument to zero turns debouncing off.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400416 * @PIN_CONFIG_INPUT_ENABLE: Enable the pin's input. Note that this does not
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900417 * affect the pin's ability to drive output. 1 enables input, 0 disables
418 * input.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400419 * @PIN_CONFIG_INPUT_SCHMITT: This will configure an input pin to run in
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900420 * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
421 * the threshold value is given on a custom format as argument when
422 * setting pins to this mode.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400423 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: Control schmitt-trigger mode on the pin.
Peng Fan99490a72018-01-05 14:05:17 +0800424 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
425 * schmitt-trigger mode is disabled.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400426 * @PIN_CONFIG_LOW_POWER_MODE: This will configure the pin for low power
Peng Fan99490a72018-01-05 14:05:17 +0800427 * operation, if several modes of operation are supported these can be
428 * passed in the argument on a custom form, else just use argument 1
429 * to indicate low power mode, argument 0 turns low power mode off.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400430 * @PIN_CONFIG_OUTPUT_ENABLE: This will enable the pin's output mode
Peng Fan99490a72018-01-05 14:05:17 +0800431 * without driving a value there. For most platforms this reduces to
432 * enable the output buffers and then let the pin controller current
433 * configuration (eg. the currently selected mux function) drive values on
434 * the line. Use argument 1 to enable output mode, argument 0 to disable
435 * it.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400436 * @PIN_CONFIG_OUTPUT: This will configure the pin as an output and drive a
Peng Fan99490a72018-01-05 14:05:17 +0800437 * value on the line. Use argument 1 to indicate high level, argument 0 to
438 * indicate low level. (Please see Documentation/driver-api/pinctl.rst,
439 * section "GPIO mode pitfalls" for a discussion around this parameter.)
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400440 * @PIN_CONFIG_POWER_SOURCE: If the pin can select between different power
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900441 * supplies, the argument to this parameter (on a custom format) tells
442 * the driver which alternative power source to use.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400443 * @PIN_CONFIG_SLEEP_HARDWARE_STATE: Indicate this is sleep related state.
444 * @PIN_CONFIG_SLEW_RATE: If the pin can select slew rate, the argument to
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900445 * this parameter (on a custom format) tells the driver which alternative
446 * slew rate to use.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400447 * @PIN_CONFIG_SKEW_DELAY: If the pin has programmable skew rate (on inputs)
Peng Fan99490a72018-01-05 14:05:17 +0800448 * or latch delay (on outputs) this parameter (in a custom format)
449 * specifies the clock skew or latch delay. It typically controls how
450 * many double inverters are put in front of the line.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400451 * @PIN_CONFIG_END: This is the last enumerator for pin configurations, if
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900452 * you need to pass in custom configurations to the pin controller, use
453 * PIN_CONFIG_END+1 as the base offset.
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400454 * @PIN_CONFIG_MAX: This is the maximum configuration value that can be
Peng Fan99490a72018-01-05 14:05:17 +0800455 * presented using the packed format.
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900456 */
Peng Fan99490a72018-01-05 14:05:17 +0800457enum pin_config_param {
Ashok Reddy Soma9ee52fb2022-02-23 15:02:51 +0100458 PIN_CONFIG_BIAS_BUS_HOLD = 0,
459 PIN_CONFIG_BIAS_DISABLE = 1,
460 PIN_CONFIG_BIAS_HIGH_IMPEDANCE = 2,
461 PIN_CONFIG_BIAS_PULL_DOWN = 3,
462 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT = 4,
463 PIN_CONFIG_BIAS_PULL_UP = 5,
464 PIN_CONFIG_DRIVE_OPEN_DRAIN = 6,
465 PIN_CONFIG_DRIVE_OPEN_SOURCE = 7,
466 PIN_CONFIG_DRIVE_PUSH_PULL = 8,
467 PIN_CONFIG_DRIVE_STRENGTH = 9,
468 PIN_CONFIG_DRIVE_STRENGTH_UA = 10,
469 PIN_CONFIG_INPUT_DEBOUNCE = 11,
470 PIN_CONFIG_INPUT_ENABLE = 12,
471 PIN_CONFIG_INPUT_SCHMITT = 13,
472 PIN_CONFIG_INPUT_SCHMITT_ENABLE = 14,
473 PIN_CONFIG_LOW_POWER_MODE = 15,
474 PIN_CONFIG_OUTPUT_ENABLE = 16,
475 PIN_CONFIG_OUTPUT = 17,
476 PIN_CONFIG_POWER_SOURCE = 18,
477 PIN_CONFIG_SLEEP_HARDWARE_STATE = 19,
478 PIN_CONFIG_SLEW_RATE = 20,
479 PIN_CONFIG_SKEW_DELAY = 21,
480 PIN_CONFIG_END = 127, /* 0x7F */
481 PIN_CONFIG_MAX = 255, /* 0xFF */
Peng Fan99490a72018-01-05 14:05:17 +0800482};
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900483
484#if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
485/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400486 * pinctrl_generic_set_state() - Generic set_state operation
487 * @pctldev: Pinctrl device to use
488 * @config: Config device (pseudo device), pointing a config node in DTS
489 *
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900490 * Parse the DT node of @config and its children and handle generic properties
491 * such as "pins", "groups", "functions", and pin configuration parameters.
492 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400493 * Return: 0 on success, or negative error code on failure
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900494 */
495int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
Pali Rohárd80ed172022-07-25 13:56:08 +0200496int pinctrl_generic_set_state_prefix(struct udevice *pctldev, struct udevice *config,
497 const char *prefix);
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900498#else
499static inline int pinctrl_generic_set_state(struct udevice *pctldev,
500 struct udevice *config)
501{
Patrick Delaunaye8e001e2021-11-19 10:02:26 +0100502 return -ENOSYS;
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900503}
504#endif
505
506#if CONFIG_IS_ENABLED(PINCTRL)
507/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400508 * pinctrl_select_state() - Set a device to a given state
509 * @dev: Peripheral device
510 * @statename: State name, like "default"
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900511 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400512 * Return: 0 on success, or negative error code on failure
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900513 */
514int pinctrl_select_state(struct udevice *dev, const char *statename);
515#else
516static inline int pinctrl_select_state(struct udevice *dev,
517 const char *statename)
518{
Patrick Delaunaye8e001e2021-11-19 10:02:26 +0100519 return -ENOSYS;
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900520}
521#endif
522
Simon Glassac2ee652015-08-30 16:55:13 -0600523/**
524 * pinctrl_request() - Request a particular pinctrl function
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400525 * @dev: Pinctrl device to use
Simon Glassac2ee652015-08-30 16:55:13 -0600526 * @func: Function number (driver-specific)
527 * @flags: Flags (driver-specific)
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400528 *
529 * Return: 0 if OK, or negative error code on failure
Simon Glassac2ee652015-08-30 16:55:13 -0600530 */
531int pinctrl_request(struct udevice *dev, int func, int flags);
532
533/**
534 * pinctrl_request_noflags() - Request a particular pinctrl function
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400535 * @dev: Pinctrl device to use
536 * @func: Function number (driver-specific)
Simon Glassac2ee652015-08-30 16:55:13 -0600537 *
538 * This is similar to pinctrl_request() but uses 0 for @flags.
539 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400540 * Return: 0 if OK, or negative error code on failure
Simon Glassac2ee652015-08-30 16:55:13 -0600541 */
542int pinctrl_request_noflags(struct udevice *dev, int func);
543
544/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400545 * pinctrl_get_periph_id() - Get the peripheral ID for a device
546 * @dev: Pinctrl device to use for decoding
547 * @periph: Device to check
Simon Glassac2ee652015-08-30 16:55:13 -0600548 *
549 * This generally looks at the peripheral's device tree node to work out the
550 * peripheral ID. The return value is normally interpreted as enum periph_id.
551 * so long as this is defined by the platform (which it should be).
552 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400553 * Return: Peripheral ID of @periph, or -ENOENT on error
Simon Glassac2ee652015-08-30 16:55:13 -0600554 */
555int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
556
Simon Glassa0984472016-01-21 19:43:26 -0700557/**
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700558 * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400559 * @dev: Pinctrl device to use
560 * @banknum: GPIO bank number
561 * @index: GPIO index within the bank
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700562 *
563 * This allows the raw mux value for a GPIO to be obtained. It is
564 * useful for displaying the function being used by that GPIO, such
565 * as with the 'gpio' command. This function is internal to the GPIO
566 * subsystem and should not be used by generic code. Typically it is
567 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
568 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400569 * Return: Mux value (SoC-specific, e.g. 0 for input, 1 for output)
Simon Glass2d4fa3c2016-01-21 19:43:56 -0700570*/
571int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
572
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200573/**
574 * pinctrl_get_pin_muxing() - Returns the muxing description
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400575 * @dev: Pinctrl device to use
576 * @selector: Pin index within pin-controller
577 * @buf: Pin's muxing description
578 * @size: Pin's muxing description length
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200579 *
580 * This allows to display the muxing description of the given pin for
581 * debug purpose
582 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400583 * Return: 0 if OK, or negative error code on failure
Patrice Chotard74ba3f22018-10-24 14:10:13 +0200584 */
585int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
586 int size);
587
Patrice Chotardfbf80822018-10-24 14:10:14 +0200588/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400589 * pinctrl_get_pins_count() - Display pin-controller pins number
590 * @dev: Pinctrl device to use
Patrice Chotardfbf80822018-10-24 14:10:14 +0200591 *
592 * This allows to know the number of pins owned by a given pin-controller
593 *
Patrick Delaunayda453682021-05-21 09:47:31 +0200594 * Return: Number of pins if OK, or -ENOSYS when not supported
Patrice Chotardfbf80822018-10-24 14:10:14 +0200595 */
596int pinctrl_get_pins_count(struct udevice *dev);
597
598/**
599 * pinctrl_get_pin_name() - Returns the pin's name
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400600 * @dev: Pinctrl device to use
601 * @selector: Pin index within pin-controller
602 * @buf: Buffer to fill with the name of the pin
603 * @size: Size of @buf
Patrice Chotardfbf80822018-10-24 14:10:14 +0200604 *
605 * This allows to display the pin's name for debug purpose
606 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400607 * Return: 0 if OK, or negative error code on failure
Patrice Chotardfbf80822018-10-24 14:10:14 +0200608 */
609int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
610 int size);
Marek Vasut87510962019-04-21 23:57:23 +0200611
612/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400613 * pinctrl_gpio_request() - Request a single pin to be used as GPIO
614 * @dev: GPIO peripheral device
615 * @offset: GPIO pin offset from the GPIO controller
Pali Rohár69cee502022-07-25 13:56:11 +0200616 * @label: GPIO label
Marek Vasut87510962019-04-21 23:57:23 +0200617 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400618 * Return: 0 on success, or negative error code on failure
Marek Vasut87510962019-04-21 23:57:23 +0200619 */
Pali Rohár69cee502022-07-25 13:56:11 +0200620int pinctrl_gpio_request(struct udevice *dev, unsigned offset, const char *label);
Marek Vasut87510962019-04-21 23:57:23 +0200621
622/**
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400623 * pinctrl_gpio_free() - Free a single pin used as GPIO
624 * @dev: GPIO peripheral device
625 * @offset: GPIO pin offset from the GPIO controller
Marek Vasut87510962019-04-21 23:57:23 +0200626 *
Sean Andersonabe2a6b2020-09-14 11:01:56 -0400627 * Return: 0 on success, or negative error code on failure
Marek Vasut87510962019-04-21 23:57:23 +0200628 */
629int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
630
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900631#endif /* __PINCTRL_H */