blob: 63a7d55b88808c428c71ff243f5850262af30121 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Masahiro Yamadad90a5a32015-08-27 12:44:29 +09002/*
3 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadad90a5a32015-08-27 12:44:29 +09004 */
5
6#ifndef __PINCTRL_H
7#define __PINCTRL_H
8
Patrice Chotardd5a83132018-10-24 14:10:17 +02009#define PINNAME_SIZE 10
10#define PINMUX_SIZE 40
11
Masahiro Yamadad90a5a32015-08-27 12:44:29 +090012/**
13 * struct pinconf_param - pin config parameters
14 *
15 * @property: property name in DT nodes
16 * @param: ID for this config parameter
17 * @default_value: default value for this config parameter used in case
18 * no value is specified in DT nodes
19 */
20struct pinconf_param {
21 const char * const property;
22 unsigned int param;
23 u32 default_value;
24};
25
26/**
27 * struct pinctrl_ops - pin control operations, to be implemented by
28 * pin controller drivers.
29 *
30 * The @set_state is the only mandatory operation. You can implement your
31 * pinctrl driver with its own @set_state. In this case, the other callbacks
32 * are not required. Otherwise, generic pinctrl framework is also available;
33 * use pinctrl_generic_set_state for @set_state, and implement other operations
34 * depending on your necessity.
35 *
36 * @get_pins_count: return number of selectable named pins available
37 * in this driver. (necessary to parse "pins" property in DTS)
38 * @get_pin_name: return the pin name of the pin selector,
39 * called by the core to figure out which pin it shall do
40 * operations to. (necessary to parse "pins" property in DTS)
41 * @get_groups_count: return number of selectable named groups available
42 * in this driver. (necessary to parse "groups" property in DTS)
43 * @get_group_name: return the group name of the group selector,
44 * called by the core to figure out which pin group it shall do
45 * operations to. (necessary to parse "groups" property in DTS)
46 * @get_functions_count: return number of selectable named functions available
47 * in this driver. (necessary for pin-muxing)
48 * @get_function_name: return the function name of the muxing selector,
49 * called by the core to figure out which mux setting it shall map a
50 * certain device to. (necessary for pin-muxing)
51 * @pinmux_set: enable a certain muxing function with a certain pin.
52 * The @func_selector selects a certain function whereas @pin_selector
53 * selects a certain pin to be used. On simple controllers one of them
54 * may be ignored. (necessary for pin-muxing against a single pin)
55 * @pinmux_group_set: enable a certain muxing function with a certain pin
56 * group. The @func_selector selects a certain function whereas
57 * @group_selector selects a certain set of pins to be used. On simple
58 * controllers one of them may be ignored.
59 * (necessary for pin-muxing against a pin group)
60 * @pinconf_num_params: number of driver-specific parameters to be parsed
61 * from device trees (necessary for pin-configuration)
62 * @pinconf_params: list of driver_specific parameters to be parsed from
63 * device trees (necessary for pin-configuration)
64 * @pinconf_set: configure an individual pin with a given parameter.
65 * (necessary for pin-configuration against a single pin)
66 * @pinconf_group_set: configure all pins in a group with a given parameter.
67 * (necessary for pin-configuration against a pin group)
68 * @set_state: do pinctrl operations specified by @config, a pseudo device
69 * pointing a config node. (necessary for pinctrl_full)
70 * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
71 * (necessary for pinctrl_simple)
Patrice Chotardf55a0c02018-10-24 14:10:13 +020072 * @get_pin_muxing: display the muxing of a given pin.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +090073 */
74struct pinctrl_ops {
75 int (*get_pins_count)(struct udevice *dev);
76 const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
77 int (*get_groups_count)(struct udevice *dev);
78 const char *(*get_group_name)(struct udevice *dev, unsigned selector);
79 int (*get_functions_count)(struct udevice *dev);
80 const char *(*get_function_name)(struct udevice *dev,
81 unsigned selector);
82 int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
83 unsigned func_selector);
84 int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
85 unsigned func_selector);
86 unsigned int pinconf_num_params;
87 const struct pinconf_param *pinconf_params;
88 int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
89 unsigned param, unsigned argument);
90 int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
91 unsigned param, unsigned argument);
92 int (*set_state)(struct udevice *dev, struct udevice *config);
Simon Glassc5acf4a2015-08-30 16:55:13 -060093
94 /* for pinctrl-simple */
Masahiro Yamadad90a5a32015-08-27 12:44:29 +090095 int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
Simon Glassc5acf4a2015-08-30 16:55:13 -060096 /**
97 * request() - Request a particular pinctrl function
98 *
99 * This activates the selected function.
100 *
101 * @dev: Device to adjust (UCLASS_PINCTRL)
102 * @func: Function number (driver-specific)
103 * @return 0 if OK, -ve on error
104 */
105 int (*request)(struct udevice *dev, int func, int flags);
106
107 /**
108 * get_periph_id() - get the peripheral ID for a device
109 *
110 * This generally looks at the peripheral's device tree node to work
111 * out the peripheral ID. The return value is normally interpreted as
112 * enum periph_id. so long as this is defined by the platform (which it
113 * should be).
114 *
115 * @dev: Pinctrl device to use for decoding
116 * @periph: Device to check
117 * @return peripheral ID of @periph, or -ENOENT on error
118 */
119 int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
Simon Glass77eaa192016-01-21 19:43:56 -0700120
121 /**
122 * get_gpio_mux() - get the mux value for a particular GPIO
123 *
124 * This allows the raw mux value for a GPIO to be obtained. It is
125 * useful for displaying the function being used by that GPIO, such
126 * as with the 'gpio' command. This function is internal to the GPIO
127 * subsystem and should not be used by generic code. Typically it is
128 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
129 *
130 * @dev: Pinctrl device to use
131 * @banknum: GPIO bank number
132 * @index: GPIO index within the bank
133 * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
134 */
135 int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
Patrice Chotardf55a0c02018-10-24 14:10:13 +0200136
137 /**
138 * get_pin_muxing() - show pin muxing
139 *
140 * This allows to display the muxing of a given pin. It's useful for
141 * debug purpose to know if a pin is configured as GPIO or as an
142 * alternate function and which one.
143 * Typically it is used by a PINCTRL driver with knowledge of the SoC
144 * pinctrl setup.
145 *
146 * @dev: Pinctrl device to use
147 * @selector: Pin selector
148 * @buf Pin's muxing description
149 * @size Pin's muxing description length
150 * return 0 if OK, -ve on error
151 */
152 int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
153 char *buf, int size);
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900154};
155
156#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
157
158/**
159 * Generic pin configuration paramters
160 *
Peng Fan0fe4e412018-01-05 14:05:17 +0800161 * enum pin_config_param - possible pin configuration parameters
162 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
163 * weakly drives the last value on a tristate bus, also known as a "bus
164 * holder", "bus keeper" or "repeater". This allows another device on the
165 * bus to change the value by driving the bus high or low and switching to
166 * tristate. The argument is ignored.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900167 * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
168 * transition from say pull-up to pull-down implies that you disable
169 * pull-up in the process, this setting disables all biasing.
170 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
171 * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
172 * On output pins this effectively disconnects the pin, which is useful
173 * if for example some other pin is going to drive the signal connected
174 * to it for a while. Pins used for input are usually always high
175 * impedance.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900176 * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
177 * impedance to GROUND). If the argument is != 0 pull-down is enabled,
178 * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
179 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
180 * on embedded knowledge of the controller hardware, like current mux
181 * function. The pull direction and possibly strength too will normally
182 * be decided completely inside the hardware block and not be readable
183 * from the kernel side.
184 * If the argument is != 0 pull up/down is enabled, if it is 0, the
185 * configuration is ignored. The proper way to disable it is to use
186 * @PIN_CONFIG_BIAS_DISABLE.
Peng Fan0fe4e412018-01-05 14:05:17 +0800187 * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
188 * impedance to VDD). If the argument is != 0 pull-up is enabled,
189 * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900190 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
191 * collector) which means it is usually wired with other output ports
192 * which are then pulled up with an external resistor. Setting this
193 * config will enable open drain mode, the argument is ignored.
194 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
195 * (open emitter). Setting this config will enable open source mode, the
196 * argument is ignored.
Peng Fan0fe4e412018-01-05 14:05:17 +0800197 * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
198 * low, this is the most typical case and is typically achieved with two
199 * active transistors on the output. Setting this config will enable
200 * push-pull mode, the argument is ignored.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900201 * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
202 * passed as argument. The argument is in mA.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900203 * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
204 * which means it will wait for signals to settle when reading inputs. The
205 * argument gives the debounce time in usecs. Setting the
206 * argument to zero turns debouncing off.
Peng Fan0fe4e412018-01-05 14:05:17 +0800207 * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
208 * affect the pin's ability to drive output. 1 enables input, 0 disables
209 * input.
210 * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
211 * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
212 * the threshold value is given on a custom format as argument when
213 * setting pins to this mode.
214 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
215 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
216 * schmitt-trigger mode is disabled.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900217 * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
218 * operation, if several modes of operation are supported these can be
219 * passed in the argument on a custom form, else just use argument 1
220 * to indicate low power mode, argument 0 turns low power mode off.
Peng Fan0fe4e412018-01-05 14:05:17 +0800221 * @PIN_CONFIG_OUTPUT_ENABLE: this will enable the pin's output mode
222 * without driving a value there. For most platforms this reduces to
223 * enable the output buffers and then let the pin controller current
224 * configuration (eg. the currently selected mux function) drive values on
225 * the line. Use argument 1 to enable output mode, argument 0 to disable
226 * it.
227 * @PIN_CONFIG_OUTPUT: this will configure the pin as an output and drive a
228 * value on the line. Use argument 1 to indicate high level, argument 0 to
229 * indicate low level. (Please see Documentation/driver-api/pinctl.rst,
230 * section "GPIO mode pitfalls" for a discussion around this parameter.)
231 * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
232 * supplies, the argument to this parameter (on a custom format) tells
233 * the driver which alternative power source to use.
234 * @PIN_CONFIG_SLEEP_HARDWARE_STATE: indicate this is sleep related state.
235 * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
236 * this parameter (on a custom format) tells the driver which alternative
237 * slew rate to use.
238 * @PIN_CONFIG_SKEW_DELAY: if the pin has programmable skew rate (on inputs)
239 * or latch delay (on outputs) this parameter (in a custom format)
240 * specifies the clock skew or latch delay. It typically controls how
241 * many double inverters are put in front of the line.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900242 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
243 * you need to pass in custom configurations to the pin controller, use
244 * PIN_CONFIG_END+1 as the base offset.
Peng Fan0fe4e412018-01-05 14:05:17 +0800245 * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
246 * presented using the packed format.
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900247 */
Peng Fan0fe4e412018-01-05 14:05:17 +0800248enum pin_config_param {
249 PIN_CONFIG_BIAS_BUS_HOLD,
250 PIN_CONFIG_BIAS_DISABLE,
251 PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
252 PIN_CONFIG_BIAS_PULL_DOWN,
253 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
254 PIN_CONFIG_BIAS_PULL_UP,
255 PIN_CONFIG_DRIVE_OPEN_DRAIN,
256 PIN_CONFIG_DRIVE_OPEN_SOURCE,
257 PIN_CONFIG_DRIVE_PUSH_PULL,
258 PIN_CONFIG_DRIVE_STRENGTH,
259 PIN_CONFIG_INPUT_DEBOUNCE,
260 PIN_CONFIG_INPUT_ENABLE,
261 PIN_CONFIG_INPUT_SCHMITT,
262 PIN_CONFIG_INPUT_SCHMITT_ENABLE,
263 PIN_CONFIG_LOW_POWER_MODE,
264 PIN_CONFIG_OUTPUT_ENABLE,
265 PIN_CONFIG_OUTPUT,
266 PIN_CONFIG_POWER_SOURCE,
267 PIN_CONFIG_SLEEP_HARDWARE_STATE,
268 PIN_CONFIG_SLEW_RATE,
269 PIN_CONFIG_SKEW_DELAY,
270 PIN_CONFIG_END = 0x7F,
271 PIN_CONFIG_MAX = 0xFF,
272};
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900273
274#if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
275/**
276 * pinctrl_generic_set_state() - generic set_state operation
277 * Parse the DT node of @config and its children and handle generic properties
278 * such as "pins", "groups", "functions", and pin configuration parameters.
279 *
280 * @pctldev: pinctrl device
281 * @config: config device (pseudo device), pointing a config node in DTS
282 * @return: 0 on success, or negative error code on failure
283 */
284int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
285#else
286static inline int pinctrl_generic_set_state(struct udevice *pctldev,
287 struct udevice *config)
288{
289 return -EINVAL;
290}
291#endif
292
293#if CONFIG_IS_ENABLED(PINCTRL)
294/**
295 * pinctrl_select_state() - set a device to a given state
296 *
297 * @dev: peripheral device
298 * @statename: state name, like "default"
299 * @return: 0 on success, or negative error code on failure
300 */
301int pinctrl_select_state(struct udevice *dev, const char *statename);
302#else
303static inline int pinctrl_select_state(struct udevice *dev,
304 const char *statename)
305{
306 return -EINVAL;
307}
308#endif
309
Simon Glassc5acf4a2015-08-30 16:55:13 -0600310/**
311 * pinctrl_request() - Request a particular pinctrl function
312 *
313 * @dev: Device to check (UCLASS_PINCTRL)
314 * @func: Function number (driver-specific)
315 * @flags: Flags (driver-specific)
316 * @return 0 if OK, -ve on error
317 */
318int pinctrl_request(struct udevice *dev, int func, int flags);
319
320/**
321 * pinctrl_request_noflags() - Request a particular pinctrl function
322 *
323 * This is similar to pinctrl_request() but uses 0 for @flags.
324 *
325 * @dev: Device to check (UCLASS_PINCTRL)
326 * @func: Function number (driver-specific)
327 * @return 0 if OK, -ve on error
328 */
329int pinctrl_request_noflags(struct udevice *dev, int func);
330
331/**
332 * pinctrl_get_periph_id() - get the peripheral ID for a device
333 *
334 * This generally looks at the peripheral's device tree node to work out the
335 * peripheral ID. The return value is normally interpreted as enum periph_id.
336 * so long as this is defined by the platform (which it should be).
337 *
338 * @dev: Pinctrl device to use for decoding
339 * @periph: Device to check
340 * @return peripheral ID of @periph, or -ENOENT on error
341 */
342int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
343
Simon Glass52db39a2016-01-21 19:43:26 -0700344/**
345 * pinctrl_decode_pin_config() - decode pin configuration flags
346 *
347 * This decodes some of the PIN_CONFIG values into flags, with each value
348 * being (1 << pin_cfg). This does not support things with values like the
349 * slew rate.
350 *
351 * @blob: Device tree blob
352 * @node: Node containing the PIN_CONFIG values
353 * @return decoded flag value, or -ve on error
354 */
355int pinctrl_decode_pin_config(const void *blob, int node);
356
Simon Glass77eaa192016-01-21 19:43:56 -0700357/**
358 * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
359 *
360 * This allows the raw mux value for a GPIO to be obtained. It is
361 * useful for displaying the function being used by that GPIO, such
362 * as with the 'gpio' command. This function is internal to the GPIO
363 * subsystem and should not be used by generic code. Typically it is
364 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
365 *
366 * @dev: Pinctrl device to use
367 * @banknum: GPIO bank number
368 * @index: GPIO index within the bank
369 * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
370*/
371int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
372
Patrice Chotardf55a0c02018-10-24 14:10:13 +0200373/**
374 * pinctrl_get_pin_muxing() - Returns the muxing description
375 *
376 * This allows to display the muxing description of the given pin for
377 * debug purpose
378 *
379 * @dev: Pinctrl device to use
380 * @selector Pin index within pin-controller
381 * @buf Pin's muxing description
382 * @size Pin's muxing description length
383 * @return 0 if OK, -ve on error
384 */
385int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
386 int size);
387
Patrice Chotard8bbb5b22018-10-24 14:10:14 +0200388/**
389 * pinctrl_get_pins_count() - display pin-controller pins number
390 *
391 * This allows to know the number of pins owned by a given pin-controller
392 *
393 * @dev: Pinctrl device to use
394 * @return pins number if OK, -ve on error
395 */
396int pinctrl_get_pins_count(struct udevice *dev);
397
398/**
399 * pinctrl_get_pin_name() - Returns the pin's name
400 *
401 * This allows to display the pin's name for debug purpose
402 *
403 * @dev: Pinctrl device to use
404 * @selector Pin index within pin-controller
405 * @buf Pin's name
406 * @return 0 if OK, -ve on error
407 */
408int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
409 int size);
Masahiro Yamadad90a5a32015-08-27 12:44:29 +0900410#endif /* __PINCTRL_H */