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