1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2015  Masahiro Yamada <yamada.masahiro@com>
4  */
5 
6 #ifndef __PINCTRL_H
7 #define __PINCTRL_H
8 
9 #include <linux/errno.h>
10 
11 #define PINNAME_SIZE	10
12 #define PINMUX_SIZE	90
13 
14 /**
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
20  */
21 struct 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  *
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.
36  */
37 struct pinctrl_ops {
38 	/**
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 	 */
48 	int (*get_pins_count)(struct udevice *dev);
49 
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 	 */
63 	const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
64 
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 	 */
75 	int (*get_groups_count)(struct udevice *dev);
76 
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 	 */
90 	const char *(*get_group_name)(struct udevice *dev, unsigned selector);
91 
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 	 */
102 	int (*get_functions_count)(struct udevice *dev);
103 
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 	 */
118 	const char *(*get_function_name)(struct udevice *dev,
119 					 unsigned selector);
120 
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 	 */
136 	int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
137 			  unsigned func_selector);
138 
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 	 */
154 	int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
155 				unsigned func_selector);
156 
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 	 */
174 	int (*pinmux_property_set)(struct udevice *dev, u32 pinmux_group);
175 
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 	 */
181 	unsigned int pinconf_num_params;
182 
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 	 */
188 	const struct pinconf_param *pinconf_params;
189 
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 	 */
207 	int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
208 			   unsigned param, unsigned argument);
209 
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 	 */
228 	int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
229 				 unsigned param, unsigned argument);
230 
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 	 */
245 	int (*set_state)(struct udevice *dev, struct udevice *config);
246 
247 	/**
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 	 */
259 	int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
260 
261 	/**
262 	 * @request: Request a particular pinctrl function
263 	 *
264 	 * @dev: Device to adjust (%UCLASS_PINCTRL)
265 	 *
266 	 * @func: Function number (driver-specific)
267 	 *
268 	 * This activates the selected function.
269 	 *
270 	 * @Return: 0 if OK, or negative error code on failure
271 	 */
272 	int (*request)(struct udevice *dev, int func, int flags);
273 
274 	/**
275 	* @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
280 	*
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
284 	* should be).
285 	*
286 	* @Return:
287 	*	Peripheral ID of @periph, or %-ENOENT on error
288 	*/
289 	int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
290 
291 	/**
292 	 * @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
299 	 *
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 	 *
306 	 * @Return:
307 	 *	Mux value (SoC-specific, e.g. 0 for input, 1 for output)
308 	 */
309 	int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
310 
311 	/**
312 	 * @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
321 	 *
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.
326 	 *
327 	 * @Return: 0 if OK, or negative error code on failure
328 	 */
329 	 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
330 			       char *buf, int size);
331 
332 	/**
333 	 * @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.
344 	 *
345 	 * @Return:
346 	 *	0 if OK, or negative error code on failure
347 	 */
348 	int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
349 
350 	/**
351 	 * @gpio_disable_free: Free up GPIO muxing on a certain pin.
352 	 *
353 	 * @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
360 	 */
361 	int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
362 };
363 
364 #define pinctrl_get_ops(dev)	((struct pinctrl_ops *)(dev)->driver->ops)
365 
366 /**
367  * enum pin_config_param - Generic pin configuration parameters
368  *
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
382  *	impedance.
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
418  *	input.
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
435  *	it.
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
446  *	slew rate to use.
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.
456  */
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 */
482 };
483 
484 #if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
485 /**
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
489  *
490  * Parse the DT node of @config and its children and handle generic properties
491  * such as "pins", "groups", "functions", and pin configuration parameters.
492  *
493  * Return: 0 on success, or negative error code on failure
494  */
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,
497 				     const char *prefix);
498 #else
pinctrl_generic_set_state(struct udevice * pctldev,struct udevice * config)499 static inline int pinctrl_generic_set_state(struct udevice *pctldev,
500 					    struct udevice *config)
501 {
502 	return -ENOSYS;
503 }
504 #endif
505 
506 #if CONFIG_IS_ENABLED(PINCTRL)
507 /**
508  * pinctrl_select_state() - Set a device to a given state
509  * @dev:	Peripheral device
510  * @statename:	State name, like "default"
511  *
512  * Return: 0 on success, or negative error code on failure
513  */
514 int pinctrl_select_state(struct udevice *dev, const char *statename);
515 #else
pinctrl_select_state(struct udevice * dev,const char * statename)516 static inline int pinctrl_select_state(struct udevice *dev,
517 				       const char *statename)
518 {
519 	return -ENOSYS;
520 }
521 #endif
522 
523 /**
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)
528  *
529  * Return: 0 if OK, or negative error code on failure
530  */
531 int pinctrl_request(struct udevice *dev, int func, int flags);
532 
533 /**
534  * pinctrl_request_noflags() - Request a particular pinctrl function
535  * @dev:	Pinctrl device to use
536  * @func:	Function number (driver-specific)
537  *
538  * This is similar to pinctrl_request() but uses 0 for @flags.
539  *
540  * Return: 0 if OK, or negative error code on failure
541  */
542 int pinctrl_request_noflags(struct udevice *dev, int func);
543 
544 /**
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
548  *
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  *
553  * Return: Peripheral ID of @periph, or -ENOENT on error
554  */
555 int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
556 
557 /**
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
562  *
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  *
569  * Return: Mux value (SoC-specific, e.g. 0 for input, 1 for output)
570 */
571 int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
572 
573 /**
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
579  *
580  * This allows to display the muxing description of the given pin for
581  * debug purpose
582  *
583  * Return: 0 if OK, or negative error code on failure
584  */
585 int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
586 			   int size);
587 
588 /**
589  * pinctrl_get_pins_count() - Display pin-controller pins number
590  * @dev:	Pinctrl device to use
591  *
592  * This allows to know the number of pins owned by a given pin-controller
593  *
594  * Return: Number of pins if OK, or -ENOSYS when not supported
595  */
596 int pinctrl_get_pins_count(struct udevice *dev);
597 
598 /**
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
604  *
605  * This allows to display the pin's name for debug purpose
606  *
607  * Return: 0 if OK, or negative error code on failure
608  */
609 int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
610 			 int size);
611 
612 /**
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
616  * @label:	GPIO label
617  *
618  * Return: 0 on success, or negative error code on failure
619  */
620 int pinctrl_gpio_request(struct udevice *dev, unsigned offset, const char *label);
621 
622 /**
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
626  *
627  * Return: 0 on success, or negative error code on failure
628  */
629 int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
630 
631 #endif /* __PINCTRL_H */
632