1*d90a5a30SMasahiro Yamada /* 2*d90a5a30SMasahiro Yamada * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> 3*d90a5a30SMasahiro Yamada * 4*d90a5a30SMasahiro Yamada * SPDX-License-Identifier: GPL-2.0+ 5*d90a5a30SMasahiro Yamada */ 6*d90a5a30SMasahiro Yamada 7*d90a5a30SMasahiro Yamada #ifndef __PINCTRL_H 8*d90a5a30SMasahiro Yamada #define __PINCTRL_H 9*d90a5a30SMasahiro Yamada 10*d90a5a30SMasahiro Yamada /** 11*d90a5a30SMasahiro Yamada * struct pinconf_param - pin config parameters 12*d90a5a30SMasahiro Yamada * 13*d90a5a30SMasahiro Yamada * @property: property name in DT nodes 14*d90a5a30SMasahiro Yamada * @param: ID for this config parameter 15*d90a5a30SMasahiro Yamada * @default_value: default value for this config parameter used in case 16*d90a5a30SMasahiro Yamada * no value is specified in DT nodes 17*d90a5a30SMasahiro Yamada */ 18*d90a5a30SMasahiro Yamada struct pinconf_param { 19*d90a5a30SMasahiro Yamada const char * const property; 20*d90a5a30SMasahiro Yamada unsigned int param; 21*d90a5a30SMasahiro Yamada u32 default_value; 22*d90a5a30SMasahiro Yamada }; 23*d90a5a30SMasahiro Yamada 24*d90a5a30SMasahiro Yamada /** 25*d90a5a30SMasahiro Yamada * struct pinctrl_ops - pin control operations, to be implemented by 26*d90a5a30SMasahiro Yamada * pin controller drivers. 27*d90a5a30SMasahiro Yamada * 28*d90a5a30SMasahiro Yamada * The @set_state is the only mandatory operation. You can implement your 29*d90a5a30SMasahiro Yamada * pinctrl driver with its own @set_state. In this case, the other callbacks 30*d90a5a30SMasahiro Yamada * are not required. Otherwise, generic pinctrl framework is also available; 31*d90a5a30SMasahiro Yamada * use pinctrl_generic_set_state for @set_state, and implement other operations 32*d90a5a30SMasahiro Yamada * depending on your necessity. 33*d90a5a30SMasahiro Yamada * 34*d90a5a30SMasahiro Yamada * @get_pins_count: return number of selectable named pins available 35*d90a5a30SMasahiro Yamada * in this driver. (necessary to parse "pins" property in DTS) 36*d90a5a30SMasahiro Yamada * @get_pin_name: return the pin name of the pin selector, 37*d90a5a30SMasahiro Yamada * called by the core to figure out which pin it shall do 38*d90a5a30SMasahiro Yamada * operations to. (necessary to parse "pins" property in DTS) 39*d90a5a30SMasahiro Yamada * @get_groups_count: return number of selectable named groups available 40*d90a5a30SMasahiro Yamada * in this driver. (necessary to parse "groups" property in DTS) 41*d90a5a30SMasahiro Yamada * @get_group_name: return the group name of the group selector, 42*d90a5a30SMasahiro Yamada * called by the core to figure out which pin group it shall do 43*d90a5a30SMasahiro Yamada * operations to. (necessary to parse "groups" property in DTS) 44*d90a5a30SMasahiro Yamada * @get_functions_count: return number of selectable named functions available 45*d90a5a30SMasahiro Yamada * in this driver. (necessary for pin-muxing) 46*d90a5a30SMasahiro Yamada * @get_function_name: return the function name of the muxing selector, 47*d90a5a30SMasahiro Yamada * called by the core to figure out which mux setting it shall map a 48*d90a5a30SMasahiro Yamada * certain device to. (necessary for pin-muxing) 49*d90a5a30SMasahiro Yamada * @pinmux_set: enable a certain muxing function with a certain pin. 50*d90a5a30SMasahiro Yamada * The @func_selector selects a certain function whereas @pin_selector 51*d90a5a30SMasahiro Yamada * selects a certain pin to be used. On simple controllers one of them 52*d90a5a30SMasahiro Yamada * may be ignored. (necessary for pin-muxing against a single pin) 53*d90a5a30SMasahiro Yamada * @pinmux_group_set: enable a certain muxing function with a certain pin 54*d90a5a30SMasahiro Yamada * group. The @func_selector selects a certain function whereas 55*d90a5a30SMasahiro Yamada * @group_selector selects a certain set of pins to be used. On simple 56*d90a5a30SMasahiro Yamada * controllers one of them may be ignored. 57*d90a5a30SMasahiro Yamada * (necessary for pin-muxing against a pin group) 58*d90a5a30SMasahiro Yamada * @pinconf_num_params: number of driver-specific parameters to be parsed 59*d90a5a30SMasahiro Yamada * from device trees (necessary for pin-configuration) 60*d90a5a30SMasahiro Yamada * @pinconf_params: list of driver_specific parameters to be parsed from 61*d90a5a30SMasahiro Yamada * device trees (necessary for pin-configuration) 62*d90a5a30SMasahiro Yamada * @pinconf_set: configure an individual pin with a given parameter. 63*d90a5a30SMasahiro Yamada * (necessary for pin-configuration against a single pin) 64*d90a5a30SMasahiro Yamada * @pinconf_group_set: configure all pins in a group with a given parameter. 65*d90a5a30SMasahiro Yamada * (necessary for pin-configuration against a pin group) 66*d90a5a30SMasahiro Yamada * @set_state: do pinctrl operations specified by @config, a pseudo device 67*d90a5a30SMasahiro Yamada * pointing a config node. (necessary for pinctrl_full) 68*d90a5a30SMasahiro Yamada * @set_state_simple: do needed pinctrl operations for a peripherl @periph. 69*d90a5a30SMasahiro Yamada * (necessary for pinctrl_simple) 70*d90a5a30SMasahiro Yamada */ 71*d90a5a30SMasahiro Yamada struct pinctrl_ops { 72*d90a5a30SMasahiro Yamada int (*get_pins_count)(struct udevice *dev); 73*d90a5a30SMasahiro Yamada const char *(*get_pin_name)(struct udevice *dev, unsigned selector); 74*d90a5a30SMasahiro Yamada int (*get_groups_count)(struct udevice *dev); 75*d90a5a30SMasahiro Yamada const char *(*get_group_name)(struct udevice *dev, unsigned selector); 76*d90a5a30SMasahiro Yamada int (*get_functions_count)(struct udevice *dev); 77*d90a5a30SMasahiro Yamada const char *(*get_function_name)(struct udevice *dev, 78*d90a5a30SMasahiro Yamada unsigned selector); 79*d90a5a30SMasahiro Yamada int (*pinmux_set)(struct udevice *dev, unsigned pin_selector, 80*d90a5a30SMasahiro Yamada unsigned func_selector); 81*d90a5a30SMasahiro Yamada int (*pinmux_group_set)(struct udevice *dev, unsigned group_selector, 82*d90a5a30SMasahiro Yamada unsigned func_selector); 83*d90a5a30SMasahiro Yamada unsigned int pinconf_num_params; 84*d90a5a30SMasahiro Yamada const struct pinconf_param *pinconf_params; 85*d90a5a30SMasahiro Yamada int (*pinconf_set)(struct udevice *dev, unsigned pin_selector, 86*d90a5a30SMasahiro Yamada unsigned param, unsigned argument); 87*d90a5a30SMasahiro Yamada int (*pinconf_group_set)(struct udevice *dev, unsigned group_selector, 88*d90a5a30SMasahiro Yamada unsigned param, unsigned argument); 89*d90a5a30SMasahiro Yamada int (*set_state)(struct udevice *dev, struct udevice *config); 90*d90a5a30SMasahiro Yamada int (*set_state_simple)(struct udevice *dev, struct udevice *periph); 91*d90a5a30SMasahiro Yamada }; 92*d90a5a30SMasahiro Yamada 93*d90a5a30SMasahiro Yamada #define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops) 94*d90a5a30SMasahiro Yamada 95*d90a5a30SMasahiro Yamada /** 96*d90a5a30SMasahiro Yamada * Generic pin configuration paramters 97*d90a5a30SMasahiro Yamada * 98*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a 99*d90a5a30SMasahiro Yamada * transition from say pull-up to pull-down implies that you disable 100*d90a5a30SMasahiro Yamada * pull-up in the process, this setting disables all biasing. 101*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance 102*d90a5a30SMasahiro Yamada * mode, also know as "third-state" (tristate) or "high-Z" or "floating". 103*d90a5a30SMasahiro Yamada * On output pins this effectively disconnects the pin, which is useful 104*d90a5a30SMasahiro Yamada * if for example some other pin is going to drive the signal connected 105*d90a5a30SMasahiro Yamada * to it for a while. Pins used for input are usually always high 106*d90a5a30SMasahiro Yamada * impedance. 107*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it 108*d90a5a30SMasahiro Yamada * weakly drives the last value on a tristate bus, also known as a "bus 109*d90a5a30SMasahiro Yamada * holder", "bus keeper" or "repeater". This allows another device on the 110*d90a5a30SMasahiro Yamada * bus to change the value by driving the bus high or low and switching to 111*d90a5a30SMasahiro Yamada * tristate. The argument is ignored. 112*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high 113*d90a5a30SMasahiro Yamada * impedance to VDD). If the argument is != 0 pull-up is enabled, 114*d90a5a30SMasahiro Yamada * if it is 0, pull-up is total, i.e. the pin is connected to VDD. 115*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high 116*d90a5a30SMasahiro Yamada * impedance to GROUND). If the argument is != 0 pull-down is enabled, 117*d90a5a30SMasahiro Yamada * if it is 0, pull-down is total, i.e. the pin is connected to GROUND. 118*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based 119*d90a5a30SMasahiro Yamada * on embedded knowledge of the controller hardware, like current mux 120*d90a5a30SMasahiro Yamada * function. The pull direction and possibly strength too will normally 121*d90a5a30SMasahiro Yamada * be decided completely inside the hardware block and not be readable 122*d90a5a30SMasahiro Yamada * from the kernel side. 123*d90a5a30SMasahiro Yamada * If the argument is != 0 pull up/down is enabled, if it is 0, the 124*d90a5a30SMasahiro Yamada * configuration is ignored. The proper way to disable it is to use 125*d90a5a30SMasahiro Yamada * @PIN_CONFIG_BIAS_DISABLE. 126*d90a5a30SMasahiro Yamada * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and 127*d90a5a30SMasahiro Yamada * low, this is the most typical case and is typically achieved with two 128*d90a5a30SMasahiro Yamada * active transistors on the output. Setting this config will enable 129*d90a5a30SMasahiro Yamada * push-pull mode, the argument is ignored. 130*d90a5a30SMasahiro Yamada * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open 131*d90a5a30SMasahiro Yamada * collector) which means it is usually wired with other output ports 132*d90a5a30SMasahiro Yamada * which are then pulled up with an external resistor. Setting this 133*d90a5a30SMasahiro Yamada * config will enable open drain mode, the argument is ignored. 134*d90a5a30SMasahiro Yamada * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source 135*d90a5a30SMasahiro Yamada * (open emitter). Setting this config will enable open source mode, the 136*d90a5a30SMasahiro Yamada * argument is ignored. 137*d90a5a30SMasahiro Yamada * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current 138*d90a5a30SMasahiro Yamada * passed as argument. The argument is in mA. 139*d90a5a30SMasahiro Yamada * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not 140*d90a5a30SMasahiro Yamada * affect the pin's ability to drive output. 1 enables input, 0 disables 141*d90a5a30SMasahiro Yamada * input. 142*d90a5a30SMasahiro Yamada * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin. 143*d90a5a30SMasahiro Yamada * If the argument != 0, schmitt-trigger mode is enabled. If it's 0, 144*d90a5a30SMasahiro Yamada * schmitt-trigger mode is disabled. 145*d90a5a30SMasahiro Yamada * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in 146*d90a5a30SMasahiro Yamada * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis, 147*d90a5a30SMasahiro Yamada * the threshold value is given on a custom format as argument when 148*d90a5a30SMasahiro Yamada * setting pins to this mode. 149*d90a5a30SMasahiro Yamada * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode, 150*d90a5a30SMasahiro Yamada * which means it will wait for signals to settle when reading inputs. The 151*d90a5a30SMasahiro Yamada * argument gives the debounce time in usecs. Setting the 152*d90a5a30SMasahiro Yamada * argument to zero turns debouncing off. 153*d90a5a30SMasahiro Yamada * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power 154*d90a5a30SMasahiro Yamada * supplies, the argument to this parameter (on a custom format) tells 155*d90a5a30SMasahiro Yamada * the driver which alternative power source to use. 156*d90a5a30SMasahiro Yamada * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to 157*d90a5a30SMasahiro Yamada * this parameter (on a custom format) tells the driver which alternative 158*d90a5a30SMasahiro Yamada * slew rate to use. 159*d90a5a30SMasahiro Yamada * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power 160*d90a5a30SMasahiro Yamada * operation, if several modes of operation are supported these can be 161*d90a5a30SMasahiro Yamada * passed in the argument on a custom form, else just use argument 1 162*d90a5a30SMasahiro Yamada * to indicate low power mode, argument 0 turns low power mode off. 163*d90a5a30SMasahiro Yamada * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument 164*d90a5a30SMasahiro Yamada * 1 to indicate high level, argument 0 to indicate low level. (Please 165*d90a5a30SMasahiro Yamada * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a 166*d90a5a30SMasahiro Yamada * discussion around this parameter.) 167*d90a5a30SMasahiro Yamada * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if 168*d90a5a30SMasahiro Yamada * you need to pass in custom configurations to the pin controller, use 169*d90a5a30SMasahiro Yamada * PIN_CONFIG_END+1 as the base offset. 170*d90a5a30SMasahiro Yamada */ 171*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_DISABLE 0 172*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_HIGH_IMPEDANCE 1 173*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_BUS_HOLD 2 174*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_PULL_UP 3 175*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_PULL_DOWN 4 176*d90a5a30SMasahiro Yamada #define PIN_CONFIG_BIAS_PULL_PIN_DEFAULT 5 177*d90a5a30SMasahiro Yamada #define PIN_CONFIG_DRIVE_PUSH_PULL 6 178*d90a5a30SMasahiro Yamada #define PIN_CONFIG_DRIVE_OPEN_DRAIN 7 179*d90a5a30SMasahiro Yamada #define PIN_CONFIG_DRIVE_OPEN_SOURCE 8 180*d90a5a30SMasahiro Yamada #define PIN_CONFIG_DRIVE_STRENGTH 9 181*d90a5a30SMasahiro Yamada #define PIN_CONFIG_INPUT_ENABLE 10 182*d90a5a30SMasahiro Yamada #define PIN_CONFIG_INPUT_SCHMITT_ENABLE 11 183*d90a5a30SMasahiro Yamada #define PIN_CONFIG_INPUT_SCHMITT 12 184*d90a5a30SMasahiro Yamada #define PIN_CONFIG_INPUT_DEBOUNCE 13 185*d90a5a30SMasahiro Yamada #define PIN_CONFIG_POWER_SOURCE 14 186*d90a5a30SMasahiro Yamada #define PIN_CONFIG_SLEW_RATE 15 187*d90a5a30SMasahiro Yamada #define PIN_CONFIG_LOW_POWER_MODE 16 188*d90a5a30SMasahiro Yamada #define PIN_CONFIG_OUTPUT 17 189*d90a5a30SMasahiro Yamada #define PIN_CONFIG_END 0x7FFF 190*d90a5a30SMasahiro Yamada 191*d90a5a30SMasahiro Yamada #if CONFIG_IS_ENABLED(PINCTRL_GENERIC) 192*d90a5a30SMasahiro Yamada /** 193*d90a5a30SMasahiro Yamada * pinctrl_generic_set_state() - generic set_state operation 194*d90a5a30SMasahiro Yamada * Parse the DT node of @config and its children and handle generic properties 195*d90a5a30SMasahiro Yamada * such as "pins", "groups", "functions", and pin configuration parameters. 196*d90a5a30SMasahiro Yamada * 197*d90a5a30SMasahiro Yamada * @pctldev: pinctrl device 198*d90a5a30SMasahiro Yamada * @config: config device (pseudo device), pointing a config node in DTS 199*d90a5a30SMasahiro Yamada * @return: 0 on success, or negative error code on failure 200*d90a5a30SMasahiro Yamada */ 201*d90a5a30SMasahiro Yamada int pinctrl_generic_set_state(struct udevice *pctldev, struct udevice *config); 202*d90a5a30SMasahiro Yamada #else 203*d90a5a30SMasahiro Yamada static inline int pinctrl_generic_set_state(struct udevice *pctldev, 204*d90a5a30SMasahiro Yamada struct udevice *config) 205*d90a5a30SMasahiro Yamada { 206*d90a5a30SMasahiro Yamada return -EINVAL; 207*d90a5a30SMasahiro Yamada } 208*d90a5a30SMasahiro Yamada #endif 209*d90a5a30SMasahiro Yamada 210*d90a5a30SMasahiro Yamada #if CONFIG_IS_ENABLED(PINCTRL) 211*d90a5a30SMasahiro Yamada /** 212*d90a5a30SMasahiro Yamada * pinctrl_select_state() - set a device to a given state 213*d90a5a30SMasahiro Yamada * 214*d90a5a30SMasahiro Yamada * @dev: peripheral device 215*d90a5a30SMasahiro Yamada * @statename: state name, like "default" 216*d90a5a30SMasahiro Yamada * @return: 0 on success, or negative error code on failure 217*d90a5a30SMasahiro Yamada */ 218*d90a5a30SMasahiro Yamada int pinctrl_select_state(struct udevice *dev, const char *statename); 219*d90a5a30SMasahiro Yamada #else 220*d90a5a30SMasahiro Yamada static inline int pinctrl_select_state(struct udevice *dev, 221*d90a5a30SMasahiro Yamada const char *statename) 222*d90a5a30SMasahiro Yamada { 223*d90a5a30SMasahiro Yamada return -EINVAL; 224*d90a5a30SMasahiro Yamada } 225*d90a5a30SMasahiro Yamada #endif 226*d90a5a30SMasahiro Yamada 227*d90a5a30SMasahiro Yamada #endif /* __PINCTRL_H */ 228