1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@com>
9 #include <linux/errno.h>
11 #define PINNAME_SIZE 10
12 #define PINMUX_SIZE 90
15 * struct pinconf_param - pin config parameters
16 * @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
21 struct pinconf_param {
22 const char * const property;
28 * struct pinctrl_ops - pin control operations, to be implemented by
29 * pin controller drivers.
31 * 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
35 * depending on your necessity.
39 * @get_pins_count: Get the number of selectable pins
41 * @dev: Pinctrl device to use
43 * This function is necessary to parse the "pins" property in DTS.
46 * number of selectable named pins available in this driver
48 int (*get_pins_count)(struct udevice *dev);
51 * @get_pin_name: Get the name of a pin
53 * @dev: Pinctrl device of the pin
55 * @selector: The pin selector
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"
61 * @Return: const pointer to the name of the pin
63 const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
66 * @get_groups_count: Get the number of selectable groups
68 * @dev: Pinctrl device to use
70 * This function is necessary to parse the "groups" property in DTS.
73 * number of selectable named groups available in the driver
75 int (*get_groups_count)(struct udevice *dev);
78 * @get_group_name: Get the name of a group
80 * @dev: Pinctrl device of the group
82 * @selector: The group selector
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.
88 * @Return: Pointer to the name of the group
90 const char *(*get_group_name)(struct udevice *dev, unsigned selector);
93 * @get_functions_count: Get the number of selectable functions
95 * @dev: Pinctrl device to use
97 * This function is necessary for pin-muxing.
100 * number of selectable named functions available in this driver
102 int (*get_functions_count)(struct udevice *dev);
105 * @get_function_name: Get the name of a function
107 * @dev: Pinmux device of the function
109 * @selector: The function selector
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
116 * Pointer to the function name of the muxing selector
118 const char *(*get_function_name)(struct udevice *dev,
122 * @pinmux_set: Mux a pin to a function
124 * @dev: Pinctrl device to use
126 * @pin_selector: The pin selector
128 * @func_selector: The func selector
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
134 * @Return: 0 if OK, or negative error code on failure
136 int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
137 unsigned func_selector);
140 * @pinmux_group_set: Mux a group of pins to a function
142 * @dev: Pinctrl device to use
144 * @group_selector: The group selector
146 * @func_selector: The func selector
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
152 * @Return: 0 if OK, or negative error code on failure
154 int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
155 unsigned func_selector);
158 * @pinmux_property_set: Enable a pinmux group
160 * @dev: Pinctrl device to use
162 * @pinmux_group: A u32 representing the pin identifier and mux
163 * settings. The exact format of a pinmux group is left
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.
171 * Pin selector for the muxed pin if OK, or negative error code on
174 int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
177 * @pinconf_num_params:
178 * Number of driver-specific parameters to be parsed from device
179 * trees. This member is necessary for pin configuration.
181 unsigned int pinconf_num_params;
185 * List of driver-specific parameters to be parsed from the device
186 * tree. This member is necessary for pin configuration.
188 const struct pinconf_param *pinconf_params;
191 * @pinconf_set: Configure an individual pin with a parameter
193 * @dev: Pinctrl device to use
195 * @pin_selector: The pin selector
197 * @param: An &enum pin_config_param from @pinconf_params
199 * @argument: The argument to this param from the device tree, or
200 * @pinconf_params.default_value
202 * This function is necessary for pin configuration against a single
205 * @Return: 0 if OK, or negative error code on failure
207 int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
208 unsigned param, unsigned argument);
211 * @pinconf_group_set: Configure all pins in a group with a parameter
213 * @dev: Pinctrl device to use
215 * @pin_selector: The group selector
217 * @param: A &enum pin_config_param from
220 * @argument: The argument to this param from the device tree, or
221 * @pinconf_params.default_value
223 * This function is necessary for pin configuration against a group of
226 * @Return: 0 if OK, or negative error code on failure
228 int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
229 unsigned param, unsigned argument);
232 * @set_state: Configure a pinctrl device
234 * @dev: Pinctrl device to use
236 * @config: Pseudo device pointing a config node
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
243 * @Return: 0 if OK, or negative error code on failure
245 int (*set_state)(struct udevice *dev, struct udevice *config);
248 * @set_state_simple: Configure a pinctrl device
250 * @dev: Pinctrl device to use
252 * @config: Pseudo-device pointing a config node
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.
257 * @Return: 0 if OK, or negative error code on failure
259 int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
262 * @request: Request a particular pinctrl function
264 * @dev: Device to adjust (%UCLASS_PINCTRL)
266 * @func: Function number (driver-specific)
268 * This activates the selected function.
270 * @Return: 0 if OK, or negative error code on failure
272 int (*request)(struct udevice *dev, int func, int flags);
275 * @get_periph_id: Get the peripheral ID for a device
277 * @dev: Pinctrl device to use for decoding
279 * @periph: Device to check
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
283 * &enum periph_id. so long as this is defined by the platform (which it
287 * Peripheral ID of @periph, or %-ENOENT on error
289 int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
292 * @get_gpio_mux: Get the mux value for a particular GPIO
294 * @dev: Pinctrl device to use
296 * @banknum: GPIO bank number
298 * @index: GPIO index within the bank
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.
307 * Mux value (SoC-specific, e.g. 0 for input, 1 for output)
309 int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
312 * @get_pin_muxing: Show pin muxing
314 * @dev: Pinctrl device to use
316 * @selector: Pin selector
318 * @buf: Buffer to fill with pin muxing description
320 * @size: Size of @buf
322 * This allows to display the muxing of a given pin. It's useful for
323 * 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.
327 * @Return: 0 if OK, or negative error code on failure
329 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
330 char *buf, int size);
333 * @gpio_request_enable: Request and enable GPIO on a certain pin.
335 * @dev: Pinctrl device to use
337 * @selector: Pin selector
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
346 * 0 if OK, or negative error code on failure
348 int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
351 * @gpio_disable_free: Free up GPIO muxing on a certain pin.
353 * @dev: Pinctrl device to use
355 * @selector: Pin selector
357 * This function is the reverse of @gpio_request_enable.
359 * @Return: 0 if OK, or negative error code on failure
361 int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
364 #define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
367 * enum pin_config_param - Generic pin configuration parameters
369 * @PIN_CONFIG_BIAS_BUS_HOLD: The pin will be set to weakly latch so that it
370 * 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.
374 * @PIN_CONFIG_BIAS_DISABLE: Disable any pin bias on the pin, a
375 * transition from say pull-up to pull-down implies that you disable
376 * pull-up in the process, this setting disables all biasing.
377 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: The pin will be set to a high impedance
378 * 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
383 * @PIN_CONFIG_BIAS_PULL_DOWN: The pin will be pulled down (usually with high
384 * 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.
386 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: The pin will be pulled up or down based
387 * 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.
394 * @PIN_CONFIG_BIAS_PULL_UP: The pin will be pulled up (usually with high
395 * 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.
397 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: The pin will be driven with open drain (open
398 * 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.
401 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: The pin will be driven with open source
402 * (open emitter). Setting this config will enable open source mode, the
403 * argument is ignored.
404 * @PIN_CONFIG_DRIVE_PUSH_PULL: The pin will be driven actively high and
405 * 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.
408 * @PIN_CONFIG_DRIVE_STRENGTH: The pin will sink or source at most the current
409 * passed as argument. The argument is in mA.
410 * @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,
413 * 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.
416 * @PIN_CONFIG_INPUT_ENABLE: Enable the pin's input. Note that this does not
417 * affect the pin's ability to drive output. 1 enables input, 0 disables
419 * @PIN_CONFIG_INPUT_SCHMITT: This will configure an input pin to run in
420 * 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.
423 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: Control schmitt-trigger mode on the pin.
424 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
425 * schmitt-trigger mode is disabled.
426 * @PIN_CONFIG_LOW_POWER_MODE: This will configure the pin for low power
427 * 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.
430 * @PIN_CONFIG_OUTPUT_ENABLE: This will enable the pin's output mode
431 * 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
436 * @PIN_CONFIG_OUTPUT: This will configure the pin as an output and drive a
437 * 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.)
440 * @PIN_CONFIG_POWER_SOURCE: If the pin can select between different power
441 * supplies, the argument to this parameter (on a custom format) tells
442 * the driver which alternative power source to use.
443 * @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
445 * this parameter (on a custom format) tells the driver which alternative
447 * @PIN_CONFIG_SKEW_DELAY: If the pin has programmable skew rate (on inputs)
448 * 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.
451 * @PIN_CONFIG_END: This is the last enumerator for pin configurations, if
452 * you need to pass in custom configurations to the pin controller, use
453 * PIN_CONFIG_END+1 as the base offset.
454 * @PIN_CONFIG_MAX: This is the maximum configuration value that can be
455 * presented using the packed format.
457 enum pin_config_param {
458 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 */
484 #if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
486 * 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
490 * Parse the DT node of @config and its children and handle generic properties
491 * such as "pins", "groups", "functions", and pin configuration parameters.
493 * Return: 0 on success, or negative error code on failure
495 int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
496 int pinctrl_generic_set_state_prefix(struct udevice *pctldev, struct udevice *config,
499 static inline int pinctrl_generic_set_state(struct udevice *pctldev,
500 struct udevice *config)
506 #if CONFIG_IS_ENABLED(PINCTRL)
508 * pinctrl_select_state() - Set a device to a given state
509 * @dev: Peripheral device
510 * @statename: State name, like "default"
512 * Return: 0 on success, or negative error code on failure
514 int pinctrl_select_state(struct udevice *dev, const char *statename);
516 static inline int pinctrl_select_state(struct udevice *dev,
517 const char *statename)
524 * pinctrl_request() - Request a particular pinctrl function
525 * @dev: Pinctrl device to use
526 * @func: Function number (driver-specific)
527 * @flags: Flags (driver-specific)
529 * Return: 0 if OK, or negative error code on failure
531 int pinctrl_request(struct udevice *dev, int func, int flags);
534 * pinctrl_request_noflags() - Request a particular pinctrl function
535 * @dev: Pinctrl device to use
536 * @func: Function number (driver-specific)
538 * This is similar to pinctrl_request() but uses 0 for @flags.
540 * Return: 0 if OK, or negative error code on failure
542 int pinctrl_request_noflags(struct udevice *dev, int func);
545 * pinctrl_get_periph_id() - Get the peripheral ID for a device
546 * @dev: Pinctrl device to use for decoding
547 * @periph: Device to check
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).
553 * Return: Peripheral ID of @periph, or -ENOENT on error
555 int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
558 * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
559 * @dev: Pinctrl device to use
560 * @banknum: GPIO bank number
561 * @index: GPIO index within the bank
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.
569 * Return: Mux value (SoC-specific, e.g. 0 for input, 1 for output)
571 int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
574 * pinctrl_get_pin_muxing() - Returns the muxing description
575 * @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
580 * This allows to display the muxing description of the given pin for
583 * Return: 0 if OK, or negative error code on failure
585 int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
589 * pinctrl_get_pins_count() - Display pin-controller pins number
590 * @dev: Pinctrl device to use
592 * This allows to know the number of pins owned by a given pin-controller
594 * Return: Number of pins if OK, or -ENOSYS when not supported
596 int pinctrl_get_pins_count(struct udevice *dev);
599 * pinctrl_get_pin_name() - Returns the pin's name
600 * @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
605 * This allows to display the pin's name for debug purpose
607 * Return: 0 if OK, or negative error code on failure
609 int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
613 * 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
618 * Return: 0 on success, or negative error code on failure
620 int pinctrl_gpio_request(struct udevice *dev, unsigned offset, const char *label);
623 * pinctrl_gpio_free() - Free a single pin used as GPIO
624 * @dev: GPIO peripheral device
625 * @offset: GPIO pin offset from the GPIO controller
627 * Return: 0 on success, or negative error code on failure
629 int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
631 #endif /* __PINCTRL_H */