uboot/include/dm/pinctrl.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0+ */
   2/*
   3 * Copyright (C) 2015  Masahiro Yamada <yamada.masahiro@socionext.com>
   4 */
   5
   6#ifndef __PINCTRL_H
   7#define __PINCTRL_H
   8
   9#define PINNAME_SIZE    10
  10#define PINMUX_SIZE     40
  11
  12/**
  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)
  72 * @get_pin_muxing: display the muxing of a given pin.
  73 * @gpio_request_enable: requests and enables GPIO on a certain pin.
  74 *      Implement this only if you can mux every pin individually as GPIO. The
  75 *      affected GPIO range is passed along with an offset(pin number) into that
  76 *      specific GPIO range - function selectors and pin groups are orthogonal
  77 *      to this, the core will however make sure the pins do not collide.
  78 * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of
  79 *      @gpio_request_enable
  80 */
  81struct pinctrl_ops {
  82        int (*get_pins_count)(struct udevice *dev);
  83        const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
  84        int (*get_groups_count)(struct udevice *dev);
  85        const char *(*get_group_name)(struct udevice *dev, unsigned selector);
  86        int (*get_functions_count)(struct udevice *dev);
  87        const char *(*get_function_name)(struct udevice *dev,
  88                                         unsigned selector);
  89        int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
  90                          unsigned func_selector);
  91        int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
  92                                unsigned func_selector);
  93        unsigned int pinconf_num_params;
  94        const struct pinconf_param *pinconf_params;
  95        int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
  96                           unsigned param, unsigned argument);
  97        int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
  98                                 unsigned param, unsigned argument);
  99        int (*set_state)(struct udevice *dev, struct udevice *config);
 100
 101        /* for pinctrl-simple */
 102        int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
 103        /**
 104         * request() - Request a particular pinctrl function
 105         *
 106         * This activates the selected function.
 107         *
 108         * @dev:        Device to adjust (UCLASS_PINCTRL)
 109         * @func:       Function number (driver-specific)
 110         * @return 0 if OK, -ve on error
 111         */
 112        int (*request)(struct udevice *dev, int func, int flags);
 113
 114        /**
 115        * get_periph_id() - get the peripheral ID for a device
 116        *
 117        * This generally looks at the peripheral's device tree node to work
 118        * out the peripheral ID. The return value is normally interpreted as
 119        * enum periph_id. so long as this is defined by the platform (which it
 120        * should be).
 121        *
 122        * @dev:         Pinctrl device to use for decoding
 123        * @periph:      Device to check
 124        * @return peripheral ID of @periph, or -ENOENT on error
 125        */
 126        int (*get_periph_id)(struct udevice *dev, struct udevice *periph);
 127
 128        /**
 129         * get_gpio_mux() - get the mux value for a particular GPIO
 130         *
 131         * This allows the raw mux value for a GPIO to be obtained. It is
 132         * useful for displaying the function being used by that GPIO, such
 133         * as with the 'gpio' command. This function is internal to the GPIO
 134         * subsystem and should not be used by generic code. Typically it is
 135         * used by a GPIO driver with knowledge of the SoC pinctrl setup.
 136         *
 137        * @dev:         Pinctrl device to use
 138        * @banknum:     GPIO bank number
 139        * @index:       GPIO index within the bank
 140        * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
 141         */
 142        int (*get_gpio_mux)(struct udevice *dev, int banknum, int index);
 143
 144        /**
 145         * get_pin_muxing() - show pin muxing
 146         *
 147         * This allows to display the muxing of a given pin. It's useful for
 148         * debug purpose to know if a pin is configured as GPIO or as an
 149         * alternate function and which one.
 150         * Typically it is used by a PINCTRL driver with knowledge of the SoC
 151         * pinctrl setup.
 152         *
 153         * @dev:        Pinctrl device to use
 154         * @selector:   Pin selector
 155         * @buf         Pin's muxing description
 156         * @size        Pin's muxing description length
 157         * return 0 if OK, -ve on error
 158         */
 159         int (*get_pin_muxing)(struct udevice *dev, unsigned int selector,
 160                               char *buf, int size);
 161
 162        /**
 163         * gpio_request_enable: requests and enables GPIO on a certain pin.
 164         *
 165         * @dev:        Pinctrl device to use
 166         * @selector:   Pin selector
 167         * return 0 if OK, -ve on error
 168         */
 169        int (*gpio_request_enable)(struct udevice *dev, unsigned int selector);
 170
 171        /**
 172         * gpio_disable_free: free up GPIO muxing on a certain pin.
 173         *
 174         * @dev:        Pinctrl device to use
 175         * @selector:   Pin selector
 176         * return 0 if OK, -ve on error
 177         */
 178        int (*gpio_disable_free)(struct udevice *dev, unsigned int selector);
 179};
 180
 181#define pinctrl_get_ops(dev)    ((struct pinctrl_ops *)(dev)->driver->ops)
 182
 183/**
 184 * Generic pin configuration paramters
 185 *
 186 * enum pin_config_param - possible pin configuration parameters
 187 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
 188 *      weakly drives the last value on a tristate bus, also known as a "bus
 189 *      holder", "bus keeper" or "repeater". This allows another device on the
 190 *      bus to change the value by driving the bus high or low and switching to
 191 *      tristate. The argument is ignored.
 192 * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
 193 *      transition from say pull-up to pull-down implies that you disable
 194 *      pull-up in the process, this setting disables all biasing.
 195 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
 196 *      mode, also know as "third-state" (tristate) or "high-Z" or "floating".
 197 *      On output pins this effectively disconnects the pin, which is useful
 198 *      if for example some other pin is going to drive the signal connected
 199 *      to it for a while. Pins used for input are usually always high
 200 *      impedance.
 201 * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
 202 *      impedance to GROUND). If the argument is != 0 pull-down is enabled,
 203 *      if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
 204 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
 205 *      on embedded knowledge of the controller hardware, like current mux
 206 *      function. The pull direction and possibly strength too will normally
 207 *      be decided completely inside the hardware block and not be readable
 208 *      from the kernel side.
 209 *      If the argument is != 0 pull up/down is enabled, if it is 0, the
 210 *      configuration is ignored. The proper way to disable it is to use
 211 *      @PIN_CONFIG_BIAS_DISABLE.
 212 * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
 213 *      impedance to VDD). If the argument is != 0 pull-up is enabled,
 214 *      if it is 0, pull-up is total, i.e. the pin is connected to VDD.
 215 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
 216 *      collector) which means it is usually wired with other output ports
 217 *      which are then pulled up with an external resistor. Setting this
 218 *      config will enable open drain mode, the argument is ignored.
 219 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
 220 *      (open emitter). Setting this config will enable open source mode, the
 221 *      argument is ignored.
 222 * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
 223 *      low, this is the most typical case and is typically achieved with two
 224 *      active transistors on the output. Setting this config will enable
 225 *      push-pull mode, the argument is ignored.
 226 * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
 227 *      passed as argument. The argument is in mA.
 228 * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the current
 229 *      passed as argument. The argument is in uA.
 230 * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
 231 *      which means it will wait for signals to settle when reading inputs. The
 232 *      argument gives the debounce time in usecs. Setting the
 233 *      argument to zero turns debouncing off.
 234 * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input.  Note that this does not
 235 *      affect the pin's ability to drive output.  1 enables input, 0 disables
 236 *      input.
 237 * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
 238 *      schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
 239 *      the threshold value is given on a custom format as argument when
 240 *      setting pins to this mode.
 241 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
 242 *      If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
 243 *      schmitt-trigger mode is disabled.
 244 * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
 245 *      operation, if several modes of operation are supported these can be
 246 *      passed in the argument on a custom form, else just use argument 1
 247 *      to indicate low power mode, argument 0 turns low power mode off.
 248 * @PIN_CONFIG_OUTPUT_ENABLE: this will enable the pin's output mode
 249 *      without driving a value there. For most platforms this reduces to
 250 *      enable the output buffers and then let the pin controller current
 251 *      configuration (eg. the currently selected mux function) drive values on
 252 *      the line. Use argument 1 to enable output mode, argument 0 to disable
 253 *      it.
 254 * @PIN_CONFIG_OUTPUT: this will configure the pin as an output and drive a
 255 *      value on the line. Use argument 1 to indicate high level, argument 0 to
 256 *      indicate low level. (Please see Documentation/driver-api/pinctl.rst,
 257 *      section "GPIO mode pitfalls" for a discussion around this parameter.)
 258 * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
 259 *      supplies, the argument to this parameter (on a custom format) tells
 260 *      the driver which alternative power source to use.
 261 * @PIN_CONFIG_SLEEP_HARDWARE_STATE: indicate this is sleep related state.
 262 * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
 263 *      this parameter (on a custom format) tells the driver which alternative
 264 *      slew rate to use.
 265 * @PIN_CONFIG_SKEW_DELAY: if the pin has programmable skew rate (on inputs)
 266 *      or latch delay (on outputs) this parameter (in a custom format)
 267 *      specifies the clock skew or latch delay. It typically controls how
 268 *      many double inverters are put in front of the line.
 269 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
 270 *      you need to pass in custom configurations to the pin controller, use
 271 *      PIN_CONFIG_END+1 as the base offset.
 272 * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
 273 *      presented using the packed format.
 274 */
 275enum pin_config_param {
 276        PIN_CONFIG_BIAS_BUS_HOLD,
 277        PIN_CONFIG_BIAS_DISABLE,
 278        PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
 279        PIN_CONFIG_BIAS_PULL_DOWN,
 280        PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
 281        PIN_CONFIG_BIAS_PULL_UP,
 282        PIN_CONFIG_DRIVE_OPEN_DRAIN,
 283        PIN_CONFIG_DRIVE_OPEN_SOURCE,
 284        PIN_CONFIG_DRIVE_PUSH_PULL,
 285        PIN_CONFIG_DRIVE_STRENGTH,
 286        PIN_CONFIG_DRIVE_STRENGTH_UA,
 287        PIN_CONFIG_INPUT_DEBOUNCE,
 288        PIN_CONFIG_INPUT_ENABLE,
 289        PIN_CONFIG_INPUT_SCHMITT,
 290        PIN_CONFIG_INPUT_SCHMITT_ENABLE,
 291        PIN_CONFIG_LOW_POWER_MODE,
 292        PIN_CONFIG_OUTPUT_ENABLE,
 293        PIN_CONFIG_OUTPUT,
 294        PIN_CONFIG_POWER_SOURCE,
 295        PIN_CONFIG_SLEEP_HARDWARE_STATE,
 296        PIN_CONFIG_SLEW_RATE,
 297        PIN_CONFIG_SKEW_DELAY,
 298        PIN_CONFIG_END = 0x7F,
 299        PIN_CONFIG_MAX = 0xFF,
 300};
 301
 302#if CONFIG_IS_ENABLED(PINCTRL_GENERIC)
 303/**
 304 * pinctrl_generic_set_state() - generic set_state operation
 305 * Parse the DT node of @config and its children and handle generic properties
 306 * such as "pins", "groups", "functions", and pin configuration parameters.
 307 *
 308 * @pctldev: pinctrl device
 309 * @config: config device (pseudo device), pointing a config node in DTS
 310 * @return: 0 on success, or negative error code on failure
 311 */
 312int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config);
 313#else
 314static inline int pinctrl_generic_set_state(struct udevice *pctldev,
 315                                            struct udevice *config)
 316{
 317        return -EINVAL;
 318}
 319#endif
 320
 321#if CONFIG_IS_ENABLED(PINCTRL)
 322/**
 323 * pinctrl_select_state() - set a device to a given state
 324 *
 325 * @dev: peripheral device
 326 * @statename: state name, like "default"
 327 * @return: 0 on success, or negative error code on failure
 328 */
 329int pinctrl_select_state(struct udevice *dev, const char *statename);
 330#else
 331static inline int pinctrl_select_state(struct udevice *dev,
 332                                       const char *statename)
 333{
 334        return -EINVAL;
 335}
 336#endif
 337
 338/**
 339 * pinctrl_request() - Request a particular pinctrl function
 340 *
 341 * @dev:        Device to check (UCLASS_PINCTRL)
 342 * @func:       Function number (driver-specific)
 343 * @flags:      Flags (driver-specific)
 344 * @return 0 if OK, -ve on error
 345 */
 346int pinctrl_request(struct udevice *dev, int func, int flags);
 347
 348/**
 349 * pinctrl_request_noflags() - Request a particular pinctrl function
 350 *
 351 * This is similar to pinctrl_request() but uses 0 for @flags.
 352 *
 353 * @dev:        Device to check (UCLASS_PINCTRL)
 354 * @func:       Function number (driver-specific)
 355 * @return 0 if OK, -ve on error
 356 */
 357int pinctrl_request_noflags(struct udevice *dev, int func);
 358
 359/**
 360 * pinctrl_get_periph_id() - get the peripheral ID for a device
 361 *
 362 * This generally looks at the peripheral's device tree node to work out the
 363 * peripheral ID. The return value is normally interpreted as enum periph_id.
 364 * so long as this is defined by the platform (which it should be).
 365 *
 366 * @dev:        Pinctrl device to use for decoding
 367 * @periph:     Device to check
 368 * @return peripheral ID of @periph, or -ENOENT on error
 369 */
 370int pinctrl_get_periph_id(struct udevice *dev, struct udevice *periph);
 371
 372/**
 373 * pinctrl_decode_pin_config() - decode pin configuration flags
 374 *
 375 * This decodes some of the PIN_CONFIG values into flags, with each value
 376 * being (1 << pin_cfg). This does not support things with values like the
 377 * slew rate.
 378 *
 379 * @blob:       Device tree blob
 380 * @node:       Node containing the PIN_CONFIG values
 381 * @return decoded flag value, or -ve on error
 382 */
 383int pinctrl_decode_pin_config(const void *blob, int node);
 384
 385/**
 386 * pinctrl_get_gpio_mux() - get the mux value for a particular GPIO
 387 *
 388 * This allows the raw mux value for a GPIO to be obtained. It is
 389 * useful for displaying the function being used by that GPIO, such
 390 * as with the 'gpio' command. This function is internal to the GPIO
 391 * subsystem and should not be used by generic code. Typically it is
 392 * used by a GPIO driver with knowledge of the SoC pinctrl setup.
 393 *
 394 * @dev:        Pinctrl device to use
 395 * @banknum:    GPIO bank number
 396 * @index:      GPIO index within the bank
 397 * @return mux value (SoC-specific, e.g. 0 for input, 1 for output)
 398*/
 399int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
 400
 401/**
 402 * pinctrl_get_pin_muxing() - Returns the muxing description
 403 *
 404 * This allows to display the muxing description of the given pin for
 405 * debug purpose
 406 *
 407 * @dev:        Pinctrl device to use
 408 * @selector    Pin index within pin-controller
 409 * @buf         Pin's muxing description
 410 * @size        Pin's muxing description length
 411 * @return 0 if OK, -ve on error
 412 */
 413int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
 414                           int size);
 415
 416/**
 417 * pinctrl_get_pins_count() - display pin-controller pins number
 418 *
 419 * This allows to know the number of pins owned by a given pin-controller
 420 *
 421 * @dev:        Pinctrl device to use
 422 * @return pins number if OK, -ve on error
 423 */
 424int pinctrl_get_pins_count(struct udevice *dev);
 425
 426/**
 427 * pinctrl_get_pin_name() - Returns the pin's name
 428 *
 429 * This allows to display the pin's name for debug purpose
 430 *
 431 * @dev:        Pinctrl device to use
 432 * @selector    Pin index within pin-controller
 433 * @buf         Pin's name
 434 * @return 0 if OK, -ve on error
 435 */
 436int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf,
 437                         int size);
 438
 439/**
 440 * pinctrl_gpio_request() - request a single pin to be used as GPIO
 441 *
 442 * @dev: GPIO peripheral device
 443 * @offset: the GPIO pin offset from the GPIO controller
 444 * @return: 0 on success, or negative error code on failure
 445 */
 446int pinctrl_gpio_request(struct udevice *dev, unsigned offset);
 447
 448/**
 449 * pinctrl_gpio_free() - free a single pin used as GPIO
 450 *
 451 * @dev: GPIO peripheral device
 452 * @offset: the GPIO pin offset from the GPIO controller
 453 * @return: 0 on success, or negative error code on failure
 454 */
 455int pinctrl_gpio_free(struct udevice *dev, unsigned offset);
 456
 457#endif /* __PINCTRL_H */
 458