[U-Boot] [PATCH v5 2/3] pinctrl: add pin control uclass support
Linus Walleij
linus.walleij at linaro.org
Tue Sep 8 15:54:13 CEST 2015
On Thu, Aug 27, 2015 at 5:44 AM, Masahiro Yamada
<yamada.masahiro at socionext.com> wrote:
> This creates a new framework for handling of pin control devices,
> i.e. devices that control different aspects of package pins.
Hey cool!
For things like this:
> +/**
> + * struct pinctrl_ops - pin control operations, to be implemented by
> + * pin controller drivers.
> + *
> + * The @set_state is the only mandatory operation. You can implement your
> + * pinctrl driver with its own @set_state. In this case, the other callbacks
> + * are not required. Otherwise, generic pinctrl framework is also available;
> + * use pinctrl_generic_set_state for @set_state, and implement other operations
> + * depending on your necessity.
> + *
> + * @get_pins_count: return number of selectable named pins available
> + * in this driver. (necessary to parse "pins" property in DTS)
> + * @get_pin_name: return the pin name of the pin selector,
> + * called by the core to figure out which pin it shall do
> + * operations to. (necessary to parse "pins" property in DTS)
> + * @get_groups_count: return number of selectable named groups available
> + * in this driver. (necessary to parse "groups" property in DTS)
> + * @get_group_name: return the group name of the group selector,
> + * called by the core to figure out which pin group it shall do
> + * operations to. (necessary to parse "groups" property in DTS)
> + * @get_functions_count: return number of selectable named functions available
> + * in this driver. (necessary for pin-muxing)
> + * @get_function_name: return the function name of the muxing selector,
> + * called by the core to figure out which mux setting it shall map a
> + * certain device to. (necessary for pin-muxing)
> + * @pinmux_set: enable a certain muxing function with a certain pin.
> + * The @func_selector selects a certain function whereas @pin_selector
> + * selects a certain pin to be used. On simple controllers one of them
> + * may be ignored. (necessary for pin-muxing against a single pin)
> + * @pinmux_group_set: enable a certain muxing function with a certain pin
> + * group. The @func_selector selects a certain function whereas
> + * @group_selector selects a certain set of pins to be used. On simple
> + * controllers one of them may be ignored.
> + * (necessary for pin-muxing against a pin group)
> + * @pinconf_num_params: number of driver-specific parameters to be parsed
> + * from device trees (necessary for pin-configuration)
> + * @pinconf_params: list of driver_specific parameters to be parsed from
> + * device trees (necessary for pin-configuration)
> + * @pinconf_set: configure an individual pin with a given parameter.
> + * (necessary for pin-configuration against a single pin)
> + * @pinconf_group_set: configure all pins in a group with a given parameter.
> + * (necessary for pin-configuration against a pin group)
> + * @set_state: do pinctrl operations specified by @config, a pseudo device
> + * pointing a config node. (necessary for pinctrl_full)
> + * @set_state_simple: do needed pinctrl operations for a peripherl @periph.
> + * (necessary for pinctrl_simple)
> + */
> +struct pinctrl_ops {
> + int (*get_pins_count)(struct udevice *dev);
> + const char *(*get_pin_name)(struct udevice *dev, unsigned selector);
> + int (*get_groups_count)(struct udevice *dev);
> + const char *(*get_group_name)(struct udevice *dev, unsigned selector);
> + int (*get_functions_count)(struct udevice *dev);
> + const char *(*get_function_name)(struct udevice *dev,
> + unsigned selector);
> + int (*pinmux_set)(struct udevice *dev, unsigned pin_selector,
> + unsigned func_selector);
> + int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector,
> + unsigned func_selector);
> + unsigned int pinconf_num_params;
> + const struct pinconf_param *pinconf_params;
> + int (*pinconf_set)(struct udevice *dev, unsigned pin_selector,
> + unsigned param, unsigned argument);
> + int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector,
> + unsigned param, unsigned argument);
> + int (*set_state)(struct udevice *dev, struct udevice *config);
> + int (*set_state_simple)(struct udevice *dev, struct udevice *periph);
> +};
> +
> +#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops)
> +
> +/**
> + * Generic pin configuration paramters
> + *
> + * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
> + * transition from say pull-up to pull-down implies that you disable
> + * pull-up in the process, this setting disables all biasing.
> + * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
> + * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
> + * On output pins this effectively disconnects the pin, which is useful
> + * if for example some other pin is going to drive the signal connected
> + * to it for a while. Pins used for input are usually always high
> + * impedance.
> + * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
> + * weakly drives the last value on a tristate bus, also known as a "bus
> + * holder", "bus keeper" or "repeater". This allows another device on the
> + * bus to change the value by driving the bus high or low and switching to
> + * tristate. The argument is ignored.
> + * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
> + * impedance to VDD). If the argument is != 0 pull-up is enabled,
> + * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
> + * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
> + * impedance to GROUND). If the argument is != 0 pull-down is enabled,
> + * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
> + * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
> + * on embedded knowledge of the controller hardware, like current mux
> + * function. The pull direction and possibly strength too will normally
> + * be decided completely inside the hardware block and not be readable
> + * from the kernel side.
> + * If the argument is != 0 pull up/down is enabled, if it is 0, the
> + * configuration is ignored. The proper way to disable it is to use
> + * @PIN_CONFIG_BIAS_DISABLE.
> + * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
> + * low, this is the most typical case and is typically achieved with two
> + * active transistors on the output. Setting this config will enable
> + * push-pull mode, the argument is ignored.
> + * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
> + * collector) which means it is usually wired with other output ports
> + * which are then pulled up with an external resistor. Setting this
> + * config will enable open drain mode, the argument is ignored.
> + * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
> + * (open emitter). Setting this config will enable open source mode, the
> + * argument is ignored.
> + * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
> + * passed as argument. The argument is in mA.
> + * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
> + * affect the pin's ability to drive output. 1 enables input, 0 disables
> + * input.
> + * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
> + * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
> + * schmitt-trigger mode is disabled.
> + * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
> + * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
> + * the threshold value is given on a custom format as argument when
> + * setting pins to this mode.
> + * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
> + * which means it will wait for signals to settle when reading inputs. The
> + * argument gives the debounce time in usecs. Setting the
> + * argument to zero turns debouncing off.
> + * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
> + * supplies, the argument to this parameter (on a custom format) tells
> + * the driver which alternative power source to use.
> + * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
> + * this parameter (on a custom format) tells the driver which alternative
> + * slew rate to use.
> + * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
> + * operation, if several modes of operation are supported these can be
> + * passed in the argument on a custom form, else just use argument 1
> + * to indicate low power mode, argument 0 turns low power mode off.
> + * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument
> + * 1 to indicate high level, argument 0 to indicate low level. (Please
> + * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
> + * discussion around this parameter.)
> + * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
> + * you need to pass in custom configurations to the pin controller, use
> + * PIN_CONFIG_END+1 as the base offset.
> + */
This is obviously copied from the Linux kernel <include/linux/pinctrl/*>,
it is helpful to provide a comment in the file stating the source, so
that others that come along can compare, it happens that we add stuff
to the Linux include file(s) so unless you say where it is coming from,
it can be hard to keep it in sync.
Yours,
Linus Walleij
More information about the U-Boot
mailing list