1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 279a9becdSAlexandre Courbot #ifndef __LINUX_GPIO_DRIVER_H 379a9becdSAlexandre Courbot #define __LINUX_GPIO_DRIVER_H 479a9becdSAlexandre Courbot 5ff2b1359SLinus Walleij #include <linux/device.h> 679a9becdSAlexandre Courbot #include <linux/types.h> 714250520SLinus Walleij #include <linux/irq.h> 814250520SLinus Walleij #include <linux/irqchip/chained_irq.h> 914250520SLinus Walleij #include <linux/irqdomain.h> 10a0a8bcf4SGrygorii Strashko #include <linux/lockdep.h> 11964cb341SLinus Walleij #include <linux/pinctrl/pinctrl.h> 122956b5d9SMika Westerberg #include <linux/pinctrl/pinconf-generic.h> 1379a9becdSAlexandre Courbot 1479a9becdSAlexandre Courbot struct gpio_desc; 15c9a9972bSAlexandre Courbot struct of_phandle_args; 16c9a9972bSAlexandre Courbot struct device_node; 17f3ed0b66SStephen Rothwell struct seq_file; 18ff2b1359SLinus Walleij struct gpio_device; 19d47529b2SPaul Gortmaker struct module; 2021abf103SLinus Walleij enum gpiod_flags; 215923ea6cSLinus Walleij enum gpio_lookup_flags; 2279a9becdSAlexandre Courbot 23fdd61a01SLinus Walleij struct gpio_chip; 24fdd61a01SLinus Walleij 259208b1e7SMatti Vaittinen #define GPIO_LINE_DIRECTION_IN 1 269208b1e7SMatti Vaittinen #define GPIO_LINE_DIRECTION_OUT 0 279208b1e7SMatti Vaittinen 28c44eafd7SThierry Reding /** 29c44eafd7SThierry Reding * struct gpio_irq_chip - GPIO interrupt controller 30c44eafd7SThierry Reding */ 31c44eafd7SThierry Reding struct gpio_irq_chip { 32c44eafd7SThierry Reding /** 33da80ff81SThierry Reding * @chip: 34da80ff81SThierry Reding * 35da80ff81SThierry Reding * GPIO IRQ chip implementation, provided by GPIO driver. 36da80ff81SThierry Reding */ 37da80ff81SThierry Reding struct irq_chip *chip; 38da80ff81SThierry Reding 39da80ff81SThierry Reding /** 40f0fbe7bcSThierry Reding * @domain: 41f0fbe7bcSThierry Reding * 42f0fbe7bcSThierry Reding * Interrupt translation domain; responsible for mapping between GPIO 43f0fbe7bcSThierry Reding * hwirq number and Linux IRQ number. 44f0fbe7bcSThierry Reding */ 45f0fbe7bcSThierry Reding struct irq_domain *domain; 46f0fbe7bcSThierry Reding 47f0fbe7bcSThierry Reding /** 48c44eafd7SThierry Reding * @domain_ops: 49c44eafd7SThierry Reding * 50c44eafd7SThierry Reding * Table of interrupt domain operations for this IRQ chip. 51c44eafd7SThierry Reding */ 52c44eafd7SThierry Reding const struct irq_domain_ops *domain_ops; 53c44eafd7SThierry Reding 54fdd61a01SLinus Walleij #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 55fdd61a01SLinus Walleij /** 56fdd61a01SLinus Walleij * @fwnode: 57fdd61a01SLinus Walleij * 58fdd61a01SLinus Walleij * Firmware node corresponding to this gpiochip/irqchip, necessary 59fdd61a01SLinus Walleij * for hierarchical irqdomain support. 60fdd61a01SLinus Walleij */ 61fdd61a01SLinus Walleij struct fwnode_handle *fwnode; 62fdd61a01SLinus Walleij 63fdd61a01SLinus Walleij /** 64fdd61a01SLinus Walleij * @parent_domain: 65fdd61a01SLinus Walleij * 66fdd61a01SLinus Walleij * If non-NULL, will be set as the parent of this GPIO interrupt 67fdd61a01SLinus Walleij * controller's IRQ domain to establish a hierarchical interrupt 68fdd61a01SLinus Walleij * domain. The presence of this will activate the hierarchical 69fdd61a01SLinus Walleij * interrupt support. 70fdd61a01SLinus Walleij */ 71fdd61a01SLinus Walleij struct irq_domain *parent_domain; 72fdd61a01SLinus Walleij 73fdd61a01SLinus Walleij /** 74fdd61a01SLinus Walleij * @child_to_parent_hwirq: 75fdd61a01SLinus Walleij * 76fdd61a01SLinus Walleij * This callback translates a child hardware IRQ offset to a parent 77fdd61a01SLinus Walleij * hardware IRQ offset on a hierarchical interrupt chip. The child 78fdd61a01SLinus Walleij * hardware IRQs correspond to the GPIO index 0..ngpio-1 (see the 79fdd61a01SLinus Walleij * ngpio field of struct gpio_chip) and the corresponding parent 80fdd61a01SLinus Walleij * hardware IRQ and type (such as IRQ_TYPE_*) shall be returned by 81fdd61a01SLinus Walleij * the driver. The driver can calculate this from an offset or using 82fdd61a01SLinus Walleij * a lookup table or whatever method is best for this chip. Return 83fdd61a01SLinus Walleij * 0 on successful translation in the driver. 84fdd61a01SLinus Walleij * 85fdd61a01SLinus Walleij * If some ranges of hardware IRQs do not have a corresponding parent 86fdd61a01SLinus Walleij * HWIRQ, return -EINVAL, but also make sure to fill in @valid_mask and 87fdd61a01SLinus Walleij * @need_valid_mask to make these GPIO lines unavailable for 88fdd61a01SLinus Walleij * translation. 89fdd61a01SLinus Walleij */ 90a0b66a73SLinus Walleij int (*child_to_parent_hwirq)(struct gpio_chip *gc, 91fdd61a01SLinus Walleij unsigned int child_hwirq, 92fdd61a01SLinus Walleij unsigned int child_type, 93fdd61a01SLinus Walleij unsigned int *parent_hwirq, 94fdd61a01SLinus Walleij unsigned int *parent_type); 95fdd61a01SLinus Walleij 96fdd61a01SLinus Walleij /** 9724258761SKevin Hao * @populate_parent_alloc_arg : 98fdd61a01SLinus Walleij * 9924258761SKevin Hao * This optional callback allocates and populates the specific struct 10024258761SKevin Hao * for the parent's IRQ domain. If this is not specified, then 101fdd61a01SLinus Walleij * &gpiochip_populate_parent_fwspec_twocell will be used. A four-cell 102fdd61a01SLinus Walleij * variant named &gpiochip_populate_parent_fwspec_fourcell is also 103fdd61a01SLinus Walleij * available. 104fdd61a01SLinus Walleij */ 105a0b66a73SLinus Walleij void *(*populate_parent_alloc_arg)(struct gpio_chip *gc, 106fdd61a01SLinus Walleij unsigned int parent_hwirq, 107fdd61a01SLinus Walleij unsigned int parent_type); 108fdd61a01SLinus Walleij 109fdd61a01SLinus Walleij /** 110fdd61a01SLinus Walleij * @child_offset_to_irq: 111fdd61a01SLinus Walleij * 112fdd61a01SLinus Walleij * This optional callback is used to translate the child's GPIO line 113fdd61a01SLinus Walleij * offset on the GPIO chip to an IRQ number for the GPIO to_irq() 114fdd61a01SLinus Walleij * callback. If this is not specified, then a default callback will be 115fdd61a01SLinus Walleij * provided that returns the line offset. 116fdd61a01SLinus Walleij */ 117a0b66a73SLinus Walleij unsigned int (*child_offset_to_irq)(struct gpio_chip *gc, 118fdd61a01SLinus Walleij unsigned int pin); 119fdd61a01SLinus Walleij 120fdd61a01SLinus Walleij /** 121fdd61a01SLinus Walleij * @child_irq_domain_ops: 122fdd61a01SLinus Walleij * 123fdd61a01SLinus Walleij * The IRQ domain operations that will be used for this GPIO IRQ 124fdd61a01SLinus Walleij * chip. If no operations are provided, then default callbacks will 125fdd61a01SLinus Walleij * be populated to setup the IRQ hierarchy. Some drivers need to 126fdd61a01SLinus Walleij * supply their own translate function. 127fdd61a01SLinus Walleij */ 128fdd61a01SLinus Walleij struct irq_domain_ops child_irq_domain_ops; 129fdd61a01SLinus Walleij #endif 130fdd61a01SLinus Walleij 131c44eafd7SThierry Reding /** 132c7a0aa59SThierry Reding * @handler: 133c7a0aa59SThierry Reding * 134c7a0aa59SThierry Reding * The IRQ handler to use (often a predefined IRQ core function) for 135c7a0aa59SThierry Reding * GPIO IRQs, provided by GPIO driver. 136c7a0aa59SThierry Reding */ 137c7a0aa59SThierry Reding irq_flow_handler_t handler; 138c7a0aa59SThierry Reding 139c7a0aa59SThierry Reding /** 1403634eeb0SThierry Reding * @default_type: 1413634eeb0SThierry Reding * 1423634eeb0SThierry Reding * Default IRQ triggering type applied during GPIO driver 1433634eeb0SThierry Reding * initialization, provided by GPIO driver. 1443634eeb0SThierry Reding */ 1453634eeb0SThierry Reding unsigned int default_type; 1463634eeb0SThierry Reding 1473634eeb0SThierry Reding /** 148ca9df053SThierry Reding * @lock_key: 149ca9df053SThierry Reding * 15002ad0437SRandy Dunlap * Per GPIO IRQ chip lockdep class for IRQ lock. 151ca9df053SThierry Reding */ 152ca9df053SThierry Reding struct lock_class_key *lock_key; 15302ad0437SRandy Dunlap 15402ad0437SRandy Dunlap /** 15502ad0437SRandy Dunlap * @request_key: 15602ad0437SRandy Dunlap * 15702ad0437SRandy Dunlap * Per GPIO IRQ chip lockdep class for IRQ request. 15802ad0437SRandy Dunlap */ 15939c3fd58SAndrew Lunn struct lock_class_key *request_key; 160ca9df053SThierry Reding 161ca9df053SThierry Reding /** 162c44eafd7SThierry Reding * @parent_handler: 163c44eafd7SThierry Reding * 164c44eafd7SThierry Reding * The interrupt handler for the GPIO chip's parent interrupts, may be 165c44eafd7SThierry Reding * NULL if the parent interrupts are nested rather than cascaded. 166c44eafd7SThierry Reding */ 167c44eafd7SThierry Reding irq_flow_handler_t parent_handler; 168c44eafd7SThierry Reding 169c44eafd7SThierry Reding /** 170c44eafd7SThierry Reding * @parent_handler_data: 171c44eafd7SThierry Reding * 172c44eafd7SThierry Reding * Data associated, and passed to, the handler for the parent 173c44eafd7SThierry Reding * interrupt. 174c44eafd7SThierry Reding */ 175c44eafd7SThierry Reding void *parent_handler_data; 17639e5f096SThierry Reding 17739e5f096SThierry Reding /** 17839e5f096SThierry Reding * @num_parents: 17939e5f096SThierry Reding * 18039e5f096SThierry Reding * The number of interrupt parents of a GPIO chip. 18139e5f096SThierry Reding */ 18239e5f096SThierry Reding unsigned int num_parents; 18339e5f096SThierry Reding 18439e5f096SThierry Reding /** 18539e5f096SThierry Reding * @parents: 18639e5f096SThierry Reding * 18739e5f096SThierry Reding * A list of interrupt parents of a GPIO chip. This is owned by the 18839e5f096SThierry Reding * driver, so the core will only reference this list, not modify it. 18939e5f096SThierry Reding */ 19039e5f096SThierry Reding unsigned int *parents; 191dc6bafeeSThierry Reding 192dc6bafeeSThierry Reding /** 193e0d89728SThierry Reding * @map: 194e0d89728SThierry Reding * 195e0d89728SThierry Reding * A list of interrupt parents for each line of a GPIO chip. 196e0d89728SThierry Reding */ 197e0d89728SThierry Reding unsigned int *map; 198e0d89728SThierry Reding 199e0d89728SThierry Reding /** 20060ed54caSThierry Reding * @threaded: 201dc6bafeeSThierry Reding * 20260ed54caSThierry Reding * True if set the interrupt handling uses nested threads. 203dc6bafeeSThierry Reding */ 20460ed54caSThierry Reding bool threaded; 205dc7b0387SThierry Reding 206dc7b0387SThierry Reding /** 2079411e3aaSAndy Shevchenko * @init_hw: optional routine to initialize hardware before 2089411e3aaSAndy Shevchenko * an IRQ chip will be added. This is quite useful when 2099411e3aaSAndy Shevchenko * a particular driver wants to clear IRQ related registers 2109411e3aaSAndy Shevchenko * in order to avoid undesired events. 2119411e3aaSAndy Shevchenko */ 212a0b66a73SLinus Walleij int (*init_hw)(struct gpio_chip *gc); 2139411e3aaSAndy Shevchenko 2149411e3aaSAndy Shevchenko /** 2155fbe5b58SLinus Walleij * @init_valid_mask: optional routine to initialize @valid_mask, to be 2165fbe5b58SLinus Walleij * used if not all GPIO lines are valid interrupts. Sometimes some 2175fbe5b58SLinus Walleij * lines just cannot fire interrupts, and this routine, when defined, 2185fbe5b58SLinus Walleij * is passed a bitmap in "valid_mask" and it will have ngpios 2195fbe5b58SLinus Walleij * bits from 0..(ngpios-1) set to "1" as in valid. The callback can 2205fbe5b58SLinus Walleij * then directly set some bits to "0" if they cannot be used for 2215fbe5b58SLinus Walleij * interrupts. 222dc7b0387SThierry Reding */ 223a0b66a73SLinus Walleij void (*init_valid_mask)(struct gpio_chip *gc, 2245fbe5b58SLinus Walleij unsigned long *valid_mask, 2255fbe5b58SLinus Walleij unsigned int ngpios); 226dc7b0387SThierry Reding 227dc7b0387SThierry Reding /** 228dc7b0387SThierry Reding * @valid_mask: 229dc7b0387SThierry Reding * 230dc7b0387SThierry Reding * If not %NULL holds bitmask of GPIOs which are valid to be included 231dc7b0387SThierry Reding * in IRQ domain of the chip. 232dc7b0387SThierry Reding */ 233dc7b0387SThierry Reding unsigned long *valid_mask; 2348302cf58SThierry Reding 2358302cf58SThierry Reding /** 2368302cf58SThierry Reding * @first: 2378302cf58SThierry Reding * 2388302cf58SThierry Reding * Required for static IRQ allocation. If set, irq_domain_add_simple() 2398302cf58SThierry Reding * will allocate and map all IRQs during initialization. 2408302cf58SThierry Reding */ 2418302cf58SThierry Reding unsigned int first; 242461c1a7dSHans Verkuil 243461c1a7dSHans Verkuil /** 244461c1a7dSHans Verkuil * @irq_enable: 245461c1a7dSHans Verkuil * 246461c1a7dSHans Verkuil * Store old irq_chip irq_enable callback 247461c1a7dSHans Verkuil */ 248461c1a7dSHans Verkuil void (*irq_enable)(struct irq_data *data); 249461c1a7dSHans Verkuil 250461c1a7dSHans Verkuil /** 251461c1a7dSHans Verkuil * @irq_disable: 252461c1a7dSHans Verkuil * 253461c1a7dSHans Verkuil * Store old irq_chip irq_disable callback 254461c1a7dSHans Verkuil */ 255461c1a7dSHans Verkuil void (*irq_disable)(struct irq_data *data); 256a8173820SMaulik Shah /** 257a8173820SMaulik Shah * @irq_unmask: 258a8173820SMaulik Shah * 259a8173820SMaulik Shah * Store old irq_chip irq_unmask callback 260a8173820SMaulik Shah */ 261a8173820SMaulik Shah void (*irq_unmask)(struct irq_data *data); 262a8173820SMaulik Shah 263a8173820SMaulik Shah /** 264a8173820SMaulik Shah * @irq_mask: 265a8173820SMaulik Shah * 266a8173820SMaulik Shah * Store old irq_chip irq_mask callback 267a8173820SMaulik Shah */ 268a8173820SMaulik Shah void (*irq_mask)(struct irq_data *data); 269c44eafd7SThierry Reding }; 270c44eafd7SThierry Reding 27179a9becdSAlexandre Courbot /** 27279a9becdSAlexandre Courbot * struct gpio_chip - abstract a GPIO controller 273df4878e9SLinus Walleij * @label: a functional name for the GPIO device, such as a part 274df4878e9SLinus Walleij * number or the name of the SoC IP-block implementing it. 275ff2b1359SLinus Walleij * @gpiodev: the internal state holder, opaque struct 27658383c78SLinus Walleij * @parent: optional parent device providing the GPIOs 27779a9becdSAlexandre Courbot * @owner: helps prevent removal of modules exporting active GPIOs 27879a9becdSAlexandre Courbot * @request: optional hook for chip-specific activation, such as 27979a9becdSAlexandre Courbot * enabling module power and clock; may sleep 28079a9becdSAlexandre Courbot * @free: optional hook for chip-specific deactivation, such as 28179a9becdSAlexandre Courbot * disabling module power and clock; may sleep 28279a9becdSAlexandre Courbot * @get_direction: returns direction for signal "offset", 0=out, 1=in, 28336b52154SDouglas Anderson * (same as GPIO_LINE_DIRECTION_OUT / GPIO_LINE_DIRECTION_IN), 28436b52154SDouglas Anderson * or negative error. It is recommended to always implement this 28536b52154SDouglas Anderson * function, even on input-only or output-only gpio chips. 28679a9becdSAlexandre Courbot * @direction_input: configures signal "offset" as input, or returns error 287e48d194dSLinus Walleij * This can be omitted on input-only or output-only gpio chips. 28879a9becdSAlexandre Courbot * @direction_output: configures signal "offset" as output, or returns error 289e48d194dSLinus Walleij * This can be omitted on input-only or output-only gpio chips. 29060befd2eSVladimir Zapolskiy * @get: returns value for signal "offset", 0=low, 1=high, or negative error 291eec1d566SLukas Wunner * @get_multiple: reads values for multiple signals defined by "mask" and 292eec1d566SLukas Wunner * stores them in "bits", returns 0 on success or negative error 29379a9becdSAlexandre Courbot * @set: assigns output value for signal "offset" 2945f424243SRojhalat Ibrahim * @set_multiple: assigns output values for multiple signals defined by "mask" 2952956b5d9SMika Westerberg * @set_config: optional hook for all kinds of settings. Uses the same 2962956b5d9SMika Westerberg * packed config format as generic pinconf. 29779a9becdSAlexandre Courbot * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 29879a9becdSAlexandre Courbot * implementation may not sleep 29979a9becdSAlexandre Courbot * @dbg_show: optional routine to show contents in debugfs; default code 30079a9becdSAlexandre Courbot * will be used when this is omitted, but custom code can show extra 30179a9becdSAlexandre Courbot * state (such as pullup/pulldown configuration). 302f99d479bSGeert Uytterhoeven * @init_valid_mask: optional routine to initialize @valid_mask, to be used if 303f99d479bSGeert Uytterhoeven * not all GPIOs are valid. 304b056ca1cSAndy Shevchenko * @add_pin_ranges: optional routine to initialize pin ranges, to be used when 305b056ca1cSAndy Shevchenko * requires special mapping of the pins that provides GPIO functionality. 306b056ca1cSAndy Shevchenko * It is called after adding GPIO chip and before adding IRQ chip. 307af6c235dSLinus Walleij * @base: identifies the first GPIO number handled by this chip; 308af6c235dSLinus Walleij * or, if negative during registration, requests dynamic ID allocation. 309af6c235dSLinus Walleij * DEPRECATION: providing anything non-negative and nailing the base 31030bb6fb3SGeert Uytterhoeven * offset of GPIO chips is deprecated. Please pass -1 as base to 311af6c235dSLinus Walleij * let gpiolib select the chip base in all possible cases. We want to 312af6c235dSLinus Walleij * get rid of the static GPIO number space in the long run. 31379a9becdSAlexandre Courbot * @ngpio: the number of GPIOs handled by this controller; the last GPIO 31479a9becdSAlexandre Courbot * handled is (base + ngpio - 1). 31579a9becdSAlexandre Courbot * @names: if set, must be an array of strings to use as alternative 31679a9becdSAlexandre Courbot * names for the GPIOs in this chip. Any entry in the array 31779a9becdSAlexandre Courbot * may be NULL if there is no alias for the GPIO, however the 31879a9becdSAlexandre Courbot * array must be @ngpio entries long. A name can include a single printk 31979a9becdSAlexandre Courbot * format specifier for an unsigned int. It is substituted by the actual 32079a9becdSAlexandre Courbot * number of the gpio. 3219fb1f39eSLinus Walleij * @can_sleep: flag must be set iff get()/set() methods sleep, as they 3221c8732bbSLinus Walleij * must while accessing GPIO expander chips over I2C or SPI. This 3231c8732bbSLinus Walleij * implies that if the chip supports IRQs, these IRQs need to be threaded 3241c8732bbSLinus Walleij * as the chip access may sleep when e.g. reading out the IRQ status 3251c8732bbSLinus Walleij * registers. 3260f4630f3SLinus Walleij * @read_reg: reader function for generic GPIO 3270f4630f3SLinus Walleij * @write_reg: writer function for generic GPIO 32824efd94bSLinus Walleij * @be_bits: if the generic GPIO has big endian bit order (bit 31 is representing 32924efd94bSLinus Walleij * line 0, bit 30 is line 1 ... bit 0 is line 31) this is set to true by the 33024efd94bSLinus Walleij * generic GPIO core. It is for internal housekeeping only. 3310f4630f3SLinus Walleij * @reg_dat: data (in) register for generic GPIO 3320f4630f3SLinus Walleij * @reg_set: output set register (out=high) for generic GPIO 33308bcd3edSAnthony Best * @reg_clr: output clear register (out=low) for generic GPIO 334f69e00bdSLinus Walleij * @reg_dir_out: direction out setting register for generic GPIO 335f69e00bdSLinus Walleij * @reg_dir_in: direction in setting register for generic GPIO 336f69e00bdSLinus Walleij * @bgpio_dir_unreadable: indicates that the direction register(s) cannot 337f69e00bdSLinus Walleij * be read and we need to rely on out internal state tracking. 3380f4630f3SLinus Walleij * @bgpio_bits: number of register bits used for a generic GPIO i.e. 3390f4630f3SLinus Walleij * <register width> * 8 3400f4630f3SLinus Walleij * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep 3410f4630f3SLinus Walleij * shadowed and real data registers writes together. 3420f4630f3SLinus Walleij * @bgpio_data: shadowed data register for generic GPIO to clear/set bits 3430f4630f3SLinus Walleij * safely. 3440f4630f3SLinus Walleij * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 345f69e00bdSLinus Walleij * direction safely. A "1" in this word means the line is set as 346f69e00bdSLinus Walleij * output. 34779a9becdSAlexandre Courbot * 34879a9becdSAlexandre Courbot * A gpio_chip can help platforms abstract various sources of GPIOs so 34979a9becdSAlexandre Courbot * they can all be accessed through a common programing interface. 35079a9becdSAlexandre Courbot * Example sources would be SOC controllers, FPGAs, multifunction 35179a9becdSAlexandre Courbot * chips, dedicated GPIO expanders, and so on. 35279a9becdSAlexandre Courbot * 35379a9becdSAlexandre Courbot * Each chip controls a number of signals, identified in method calls 35479a9becdSAlexandre Courbot * by "offset" values in the range 0..(@ngpio - 1). When those signals 35579a9becdSAlexandre Courbot * are referenced through calls like gpio_get_value(gpio), the offset 35679a9becdSAlexandre Courbot * is calculated by subtracting @base from the gpio number. 35779a9becdSAlexandre Courbot */ 35879a9becdSAlexandre Courbot struct gpio_chip { 35979a9becdSAlexandre Courbot const char *label; 360ff2b1359SLinus Walleij struct gpio_device *gpiodev; 36158383c78SLinus Walleij struct device *parent; 36279a9becdSAlexandre Courbot struct module *owner; 36379a9becdSAlexandre Courbot 364a0b66a73SLinus Walleij int (*request)(struct gpio_chip *gc, 3658d091012SDouglas Anderson unsigned int offset); 366a0b66a73SLinus Walleij void (*free)(struct gpio_chip *gc, 3678d091012SDouglas Anderson unsigned int offset); 368a0b66a73SLinus Walleij int (*get_direction)(struct gpio_chip *gc, 3698d091012SDouglas Anderson unsigned int offset); 370a0b66a73SLinus Walleij int (*direction_input)(struct gpio_chip *gc, 3718d091012SDouglas Anderson unsigned int offset); 372a0b66a73SLinus Walleij int (*direction_output)(struct gpio_chip *gc, 3738d091012SDouglas Anderson unsigned int offset, int value); 374a0b66a73SLinus Walleij int (*get)(struct gpio_chip *gc, 3758d091012SDouglas Anderson unsigned int offset); 376a0b66a73SLinus Walleij int (*get_multiple)(struct gpio_chip *gc, 377eec1d566SLukas Wunner unsigned long *mask, 378eec1d566SLukas Wunner unsigned long *bits); 379a0b66a73SLinus Walleij void (*set)(struct gpio_chip *gc, 3808d091012SDouglas Anderson unsigned int offset, int value); 381a0b66a73SLinus Walleij void (*set_multiple)(struct gpio_chip *gc, 3825f424243SRojhalat Ibrahim unsigned long *mask, 3835f424243SRojhalat Ibrahim unsigned long *bits); 384a0b66a73SLinus Walleij int (*set_config)(struct gpio_chip *gc, 3858d091012SDouglas Anderson unsigned int offset, 3862956b5d9SMika Westerberg unsigned long config); 387a0b66a73SLinus Walleij int (*to_irq)(struct gpio_chip *gc, 3888d091012SDouglas Anderson unsigned int offset); 38979a9becdSAlexandre Courbot 39079a9becdSAlexandre Courbot void (*dbg_show)(struct seq_file *s, 391a0b66a73SLinus Walleij struct gpio_chip *gc); 392f8ec92a9SRicardo Ribalda Delgado 393a0b66a73SLinus Walleij int (*init_valid_mask)(struct gpio_chip *gc, 394c9fc5affSLinus Walleij unsigned long *valid_mask, 395c9fc5affSLinus Walleij unsigned int ngpios); 396f8ec92a9SRicardo Ribalda Delgado 397a0b66a73SLinus Walleij int (*add_pin_ranges)(struct gpio_chip *gc); 398b056ca1cSAndy Shevchenko 39979a9becdSAlexandre Courbot int base; 40079a9becdSAlexandre Courbot u16 ngpio; 40179a9becdSAlexandre Courbot const char *const *names; 4029fb1f39eSLinus Walleij bool can_sleep; 40379a9becdSAlexandre Courbot 4040f4630f3SLinus Walleij #if IS_ENABLED(CONFIG_GPIO_GENERIC) 4050f4630f3SLinus Walleij unsigned long (*read_reg)(void __iomem *reg); 4060f4630f3SLinus Walleij void (*write_reg)(void __iomem *reg, unsigned long data); 40724efd94bSLinus Walleij bool be_bits; 4080f4630f3SLinus Walleij void __iomem *reg_dat; 4090f4630f3SLinus Walleij void __iomem *reg_set; 4100f4630f3SLinus Walleij void __iomem *reg_clr; 411f69e00bdSLinus Walleij void __iomem *reg_dir_out; 412f69e00bdSLinus Walleij void __iomem *reg_dir_in; 413f69e00bdSLinus Walleij bool bgpio_dir_unreadable; 4140f4630f3SLinus Walleij int bgpio_bits; 4150f4630f3SLinus Walleij spinlock_t bgpio_lock; 4160f4630f3SLinus Walleij unsigned long bgpio_data; 4170f4630f3SLinus Walleij unsigned long bgpio_dir; 418f310f2efSEnrico Weigelt #endif /* CONFIG_GPIO_GENERIC */ 4190f4630f3SLinus Walleij 42014250520SLinus Walleij #ifdef CONFIG_GPIOLIB_IRQCHIP 42114250520SLinus Walleij /* 4227d75a871SPaul Bolle * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib 42314250520SLinus Walleij * to handle IRQs for most practical cases. 42414250520SLinus Walleij */ 425c44eafd7SThierry Reding 426c44eafd7SThierry Reding /** 427c44eafd7SThierry Reding * @irq: 428c44eafd7SThierry Reding * 429c44eafd7SThierry Reding * Integrates interrupt chip functionality with the GPIO chip. Can be 430c44eafd7SThierry Reding * used to handle IRQs for most practical cases. 431c44eafd7SThierry Reding */ 432c44eafd7SThierry Reding struct gpio_irq_chip irq; 433f310f2efSEnrico Weigelt #endif /* CONFIG_GPIOLIB_IRQCHIP */ 43414250520SLinus Walleij 435726cb3baSStephen Boyd /** 436726cb3baSStephen Boyd * @valid_mask: 437726cb3baSStephen Boyd * 438726cb3baSStephen Boyd * If not %NULL holds bitmask of GPIOs which are valid to be used 439726cb3baSStephen Boyd * from the chip. 440726cb3baSStephen Boyd */ 441726cb3baSStephen Boyd unsigned long *valid_mask; 442726cb3baSStephen Boyd 44379a9becdSAlexandre Courbot #if defined(CONFIG_OF_GPIO) 44479a9becdSAlexandre Courbot /* 44579a9becdSAlexandre Courbot * If CONFIG_OF is enabled, then all GPIO controllers described in the 44679a9becdSAlexandre Courbot * device tree automatically may have an OF translation 44779a9becdSAlexandre Courbot */ 44867049c50SThierry Reding 44967049c50SThierry Reding /** 45067049c50SThierry Reding * @of_node: 45167049c50SThierry Reding * 45267049c50SThierry Reding * Pointer to a device tree node representing this GPIO controller. 45367049c50SThierry Reding */ 45479a9becdSAlexandre Courbot struct device_node *of_node; 45567049c50SThierry Reding 45667049c50SThierry Reding /** 45767049c50SThierry Reding * @of_gpio_n_cells: 45867049c50SThierry Reding * 45967049c50SThierry Reding * Number of cells used to form the GPIO specifier. 46067049c50SThierry Reding */ 461e3b445d7SThierry Reding unsigned int of_gpio_n_cells; 46267049c50SThierry Reding 46367049c50SThierry Reding /** 46467049c50SThierry Reding * @of_xlate: 46567049c50SThierry Reding * 46667049c50SThierry Reding * Callback to translate a device tree GPIO specifier into a chip- 46767049c50SThierry Reding * relative GPIO number and flags. 46867049c50SThierry Reding */ 46979a9becdSAlexandre Courbot int (*of_xlate)(struct gpio_chip *gc, 47079a9becdSAlexandre Courbot const struct of_phandle_args *gpiospec, u32 *flags); 471f310f2efSEnrico Weigelt #endif /* CONFIG_OF_GPIO */ 47279a9becdSAlexandre Courbot }; 47379a9becdSAlexandre Courbot 474a0b66a73SLinus Walleij extern const char *gpiochip_is_requested(struct gpio_chip *gc, 4758d091012SDouglas Anderson unsigned int offset); 47679a9becdSAlexandre Courbot 47779a9becdSAlexandre Courbot /* add/remove chips */ 478a0b66a73SLinus Walleij extern int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, 47939c3fd58SAndrew Lunn struct lock_class_key *lock_key, 48039c3fd58SAndrew Lunn struct lock_class_key *request_key); 481959bc7b2SThierry Reding 482959bc7b2SThierry Reding /** 483959bc7b2SThierry Reding * gpiochip_add_data() - register a gpio_chip 484959bc7b2SThierry Reding * @chip: the chip to register, with chip->base initialized 485959bc7b2SThierry Reding * @data: driver-private data associated with this chip 486959bc7b2SThierry Reding * 487959bc7b2SThierry Reding * Context: potentially before irqs will work 488959bc7b2SThierry Reding * 489959bc7b2SThierry Reding * When gpiochip_add_data() is called very early during boot, so that GPIOs 490959bc7b2SThierry Reding * can be freely used, the chip->parent device must be registered before 491959bc7b2SThierry Reding * the gpio framework's arch_initcall(). Otherwise sysfs initialization 492959bc7b2SThierry Reding * for GPIOs will fail rudely. 493959bc7b2SThierry Reding * 494959bc7b2SThierry Reding * gpiochip_add_data() must only be called after gpiolib initialization, 495959bc7b2SThierry Reding * ie after core_initcall(). 496959bc7b2SThierry Reding * 497959bc7b2SThierry Reding * If chip->base is negative, this requests dynamic assignment of 498959bc7b2SThierry Reding * a range of valid GPIOs. 499959bc7b2SThierry Reding * 500959bc7b2SThierry Reding * Returns: 501959bc7b2SThierry Reding * A negative errno if the chip can't be registered, such as because the 502959bc7b2SThierry Reding * chip->base is invalid or already associated with a different chip. 503959bc7b2SThierry Reding * Otherwise it returns zero as a success code. 504959bc7b2SThierry Reding */ 505959bc7b2SThierry Reding #ifdef CONFIG_LOCKDEP 506a0b66a73SLinus Walleij #define gpiochip_add_data(gc, data) ({ \ 50739c3fd58SAndrew Lunn static struct lock_class_key lock_key; \ 50839c3fd58SAndrew Lunn static struct lock_class_key request_key; \ 509a0b66a73SLinus Walleij gpiochip_add_data_with_key(gc, data, &lock_key, \ 51039c3fd58SAndrew Lunn &request_key); \ 511959bc7b2SThierry Reding }) 512959bc7b2SThierry Reding #else 513a0b66a73SLinus Walleij #define gpiochip_add_data(gc, data) gpiochip_add_data_with_key(gc, data, NULL, NULL) 514f310f2efSEnrico Weigelt #endif /* CONFIG_LOCKDEP */ 515959bc7b2SThierry Reding 516a0b66a73SLinus Walleij static inline int gpiochip_add(struct gpio_chip *gc) 517b08ea35aSLinus Walleij { 518a0b66a73SLinus Walleij return gpiochip_add_data(gc, NULL); 519b08ea35aSLinus Walleij } 520a0b66a73SLinus Walleij extern void gpiochip_remove(struct gpio_chip *gc); 521a0b66a73SLinus Walleij extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *gc, 5220cf3292cSLaxman Dewangan void *data); 5230cf3292cSLaxman Dewangan 52479a9becdSAlexandre Courbot extern struct gpio_chip *gpiochip_find(void *data, 525a0b66a73SLinus Walleij int (*match)(struct gpio_chip *gc, void *data)); 52679a9becdSAlexandre Courbot 527a0b66a73SLinus Walleij bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); 528a0b66a73SLinus Walleij int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); 529a0b66a73SLinus Walleij void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset); 530a0b66a73SLinus Walleij void gpiochip_disable_irq(struct gpio_chip *gc, unsigned int offset); 531a0b66a73SLinus Walleij void gpiochip_enable_irq(struct gpio_chip *gc, unsigned int offset); 53279a9becdSAlexandre Courbot 533143b65d6SLinus Walleij /* Line status inquiry for drivers */ 534a0b66a73SLinus Walleij bool gpiochip_line_is_open_drain(struct gpio_chip *gc, unsigned int offset); 535a0b66a73SLinus Walleij bool gpiochip_line_is_open_source(struct gpio_chip *gc, unsigned int offset); 536143b65d6SLinus Walleij 53705f479bfSCharles Keepax /* Sleep persistence inquiry for drivers */ 538a0b66a73SLinus Walleij bool gpiochip_line_is_persistent(struct gpio_chip *gc, unsigned int offset); 539a0b66a73SLinus Walleij bool gpiochip_line_is_valid(const struct gpio_chip *gc, unsigned int offset); 54005f479bfSCharles Keepax 541b08ea35aSLinus Walleij /* get driver data */ 542a0b66a73SLinus Walleij void *gpiochip_get_data(struct gpio_chip *gc); 543b08ea35aSLinus Walleij 5440f4630f3SLinus Walleij struct bgpio_pdata { 5450f4630f3SLinus Walleij const char *label; 5460f4630f3SLinus Walleij int base; 5470f4630f3SLinus Walleij int ngpio; 5480f4630f3SLinus Walleij }; 5490f4630f3SLinus Walleij 550fdd61a01SLinus Walleij #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 551fdd61a01SLinus Walleij 552a0b66a73SLinus Walleij void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, 553fdd61a01SLinus Walleij unsigned int parent_hwirq, 554fdd61a01SLinus Walleij unsigned int parent_type); 555a0b66a73SLinus Walleij void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, 556fdd61a01SLinus Walleij unsigned int parent_hwirq, 557fdd61a01SLinus Walleij unsigned int parent_type); 558fdd61a01SLinus Walleij 559fdd61a01SLinus Walleij #else 560fdd61a01SLinus Walleij 561a0b66a73SLinus Walleij static inline void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, 562fdd61a01SLinus Walleij unsigned int parent_hwirq, 563fdd61a01SLinus Walleij unsigned int parent_type) 564fdd61a01SLinus Walleij { 5659c6722d8SKevin Hao return NULL; 566fdd61a01SLinus Walleij } 567fdd61a01SLinus Walleij 568a0b66a73SLinus Walleij static inline void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, 569fdd61a01SLinus Walleij unsigned int parent_hwirq, 570fdd61a01SLinus Walleij unsigned int parent_type) 571fdd61a01SLinus Walleij { 5729c6722d8SKevin Hao return NULL; 573fdd61a01SLinus Walleij } 574fdd61a01SLinus Walleij 575fdd61a01SLinus Walleij #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ 576fdd61a01SLinus Walleij 5770f4630f3SLinus Walleij int bgpio_init(struct gpio_chip *gc, struct device *dev, 5780f4630f3SLinus Walleij unsigned long sz, void __iomem *dat, void __iomem *set, 5790f4630f3SLinus Walleij void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 5800f4630f3SLinus Walleij unsigned long flags); 5810f4630f3SLinus Walleij 5820f4630f3SLinus Walleij #define BGPIOF_BIG_ENDIAN BIT(0) 5830f4630f3SLinus Walleij #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 5840f4630f3SLinus Walleij #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 5850f4630f3SLinus Walleij #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 5860f4630f3SLinus Walleij #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 5870f4630f3SLinus Walleij #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 588d19d2de6SChuanhong Guo #define BGPIOF_NO_SET_ON_INPUT BIT(6) 5890f4630f3SLinus Walleij 5901b95b4ebSThierry Reding int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 5911b95b4ebSThierry Reding irq_hw_number_t hwirq); 5921b95b4ebSThierry Reding void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq); 5931b95b4ebSThierry Reding 594ef74f70eSBrian Masney int gpiochip_irq_domain_activate(struct irq_domain *domain, 595ef74f70eSBrian Masney struct irq_data *data, bool reserve); 596ef74f70eSBrian Masney void gpiochip_irq_domain_deactivate(struct irq_domain *domain, 597ef74f70eSBrian Masney struct irq_data *data); 598ef74f70eSBrian Masney 599a0b66a73SLinus Walleij void gpiochip_set_nested_irqchip(struct gpio_chip *gc, 600d245b3f9SLinus Walleij struct irq_chip *irqchip, 6016f79309aSThierry Reding unsigned int parent_irq); 602d245b3f9SLinus Walleij 603a0b66a73SLinus Walleij int gpiochip_irqchip_add_key(struct gpio_chip *gc, 60414250520SLinus Walleij struct irq_chip *irqchip, 60514250520SLinus Walleij unsigned int first_irq, 60614250520SLinus Walleij irq_flow_handler_t handler, 607a0a8bcf4SGrygorii Strashko unsigned int type, 60860ed54caSThierry Reding bool threaded, 60939c3fd58SAndrew Lunn struct lock_class_key *lock_key, 61039c3fd58SAndrew Lunn struct lock_class_key *request_key); 611a0a8bcf4SGrygorii Strashko 612a0b66a73SLinus Walleij bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gc, 61364ff2c8eSStephen Boyd unsigned int offset); 61464ff2c8eSStephen Boyd 6156a45b0e2SMichael Walle int gpiochip_irqchip_add_domain(struct gpio_chip *gc, 6166a45b0e2SMichael Walle struct irq_domain *domain); 6176a45b0e2SMichael Walle 618739e6f59SLinus Walleij #ifdef CONFIG_LOCKDEP 619739e6f59SLinus Walleij 620739e6f59SLinus Walleij /* 621739e6f59SLinus Walleij * Lockdep requires that each irqchip instance be created with a 622739e6f59SLinus Walleij * unique key so as to avoid unnecessary warnings. This upfront 623739e6f59SLinus Walleij * boilerplate static inlines provides such a key for each 624739e6f59SLinus Walleij * unique instance. 625739e6f59SLinus Walleij */ 626a0b66a73SLinus Walleij static inline int gpiochip_irqchip_add(struct gpio_chip *gc, 627739e6f59SLinus Walleij struct irq_chip *irqchip, 628739e6f59SLinus Walleij unsigned int first_irq, 629739e6f59SLinus Walleij irq_flow_handler_t handler, 630739e6f59SLinus Walleij unsigned int type) 631739e6f59SLinus Walleij { 63239c3fd58SAndrew Lunn static struct lock_class_key lock_key; 63339c3fd58SAndrew Lunn static struct lock_class_key request_key; 634739e6f59SLinus Walleij 635a0b66a73SLinus Walleij return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 63639c3fd58SAndrew Lunn handler, type, false, 63739c3fd58SAndrew Lunn &lock_key, &request_key); 638739e6f59SLinus Walleij } 639739e6f59SLinus Walleij 640a0b66a73SLinus Walleij static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc, 641d245b3f9SLinus Walleij struct irq_chip *irqchip, 642d245b3f9SLinus Walleij unsigned int first_irq, 643d245b3f9SLinus Walleij irq_flow_handler_t handler, 644d245b3f9SLinus Walleij unsigned int type) 645d245b3f9SLinus Walleij { 646739e6f59SLinus Walleij 64739c3fd58SAndrew Lunn static struct lock_class_key lock_key; 64839c3fd58SAndrew Lunn static struct lock_class_key request_key; 649739e6f59SLinus Walleij 650a0b66a73SLinus Walleij return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 65139c3fd58SAndrew Lunn handler, type, true, 65239c3fd58SAndrew Lunn &lock_key, &request_key); 653739e6f59SLinus Walleij } 654f310f2efSEnrico Weigelt #else /* ! CONFIG_LOCKDEP */ 655a0b66a73SLinus Walleij static inline int gpiochip_irqchip_add(struct gpio_chip *gc, 656739e6f59SLinus Walleij struct irq_chip *irqchip, 657739e6f59SLinus Walleij unsigned int first_irq, 658739e6f59SLinus Walleij irq_flow_handler_t handler, 659739e6f59SLinus Walleij unsigned int type) 660739e6f59SLinus Walleij { 661a0b66a73SLinus Walleij return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 66239c3fd58SAndrew Lunn handler, type, false, NULL, NULL); 663d245b3f9SLinus Walleij } 664d245b3f9SLinus Walleij 665a0b66a73SLinus Walleij static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gc, 666739e6f59SLinus Walleij struct irq_chip *irqchip, 667739e6f59SLinus Walleij unsigned int first_irq, 668739e6f59SLinus Walleij irq_flow_handler_t handler, 669739e6f59SLinus Walleij unsigned int type) 670739e6f59SLinus Walleij { 671a0b66a73SLinus Walleij return gpiochip_irqchip_add_key(gc, irqchip, first_irq, 67239c3fd58SAndrew Lunn handler, type, true, NULL, NULL); 673739e6f59SLinus Walleij } 674739e6f59SLinus Walleij #endif /* CONFIG_LOCKDEP */ 67514250520SLinus Walleij 6768d091012SDouglas Anderson int gpiochip_generic_request(struct gpio_chip *gc, unsigned int offset); 6778d091012SDouglas Anderson void gpiochip_generic_free(struct gpio_chip *gc, unsigned int offset); 6788d091012SDouglas Anderson int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset, 6792956b5d9SMika Westerberg unsigned long config); 680c771c2f4SJonas Gorski 681964cb341SLinus Walleij /** 682964cb341SLinus Walleij * struct gpio_pin_range - pin range controlled by a gpio chip 683950d55f5SThierry Reding * @node: list for maintaining set of pin ranges, used internally 684964cb341SLinus Walleij * @pctldev: pinctrl device which handles corresponding pins 685964cb341SLinus Walleij * @range: actual range of pins controlled by a gpio controller 686964cb341SLinus Walleij */ 687964cb341SLinus Walleij struct gpio_pin_range { 688964cb341SLinus Walleij struct list_head node; 689964cb341SLinus Walleij struct pinctrl_dev *pctldev; 690964cb341SLinus Walleij struct pinctrl_gpio_range range; 691964cb341SLinus Walleij }; 692964cb341SLinus Walleij 6939091373aSMasahiro Yamada #ifdef CONFIG_PINCTRL 6949091373aSMasahiro Yamada 695a0b66a73SLinus Walleij int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 696964cb341SLinus Walleij unsigned int gpio_offset, unsigned int pin_offset, 697964cb341SLinus Walleij unsigned int npins); 698a0b66a73SLinus Walleij int gpiochip_add_pingroup_range(struct gpio_chip *gc, 699964cb341SLinus Walleij struct pinctrl_dev *pctldev, 700964cb341SLinus Walleij unsigned int gpio_offset, const char *pin_group); 701a0b66a73SLinus Walleij void gpiochip_remove_pin_ranges(struct gpio_chip *gc); 702964cb341SLinus Walleij 703f310f2efSEnrico Weigelt #else /* ! CONFIG_PINCTRL */ 704964cb341SLinus Walleij 705964cb341SLinus Walleij static inline int 706a0b66a73SLinus Walleij gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, 707964cb341SLinus Walleij unsigned int gpio_offset, unsigned int pin_offset, 708964cb341SLinus Walleij unsigned int npins) 709964cb341SLinus Walleij { 710964cb341SLinus Walleij return 0; 711964cb341SLinus Walleij } 712964cb341SLinus Walleij static inline int 713a0b66a73SLinus Walleij gpiochip_add_pingroup_range(struct gpio_chip *gc, 714964cb341SLinus Walleij struct pinctrl_dev *pctldev, 715964cb341SLinus Walleij unsigned int gpio_offset, const char *pin_group) 716964cb341SLinus Walleij { 717964cb341SLinus Walleij return 0; 718964cb341SLinus Walleij } 719964cb341SLinus Walleij 720964cb341SLinus Walleij static inline void 721a0b66a73SLinus Walleij gpiochip_remove_pin_ranges(struct gpio_chip *gc) 722964cb341SLinus Walleij { 723964cb341SLinus Walleij } 724964cb341SLinus Walleij 725964cb341SLinus Walleij #endif /* CONFIG_PINCTRL */ 726964cb341SLinus Walleij 727a0b66a73SLinus Walleij struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc, 72806863620SBartosz Golaszewski unsigned int hwnum, 72921abf103SLinus Walleij const char *label, 7305923ea6cSLinus Walleij enum gpio_lookup_flags lflags, 7315923ea6cSLinus Walleij enum gpiod_flags dflags); 732f7d4ad98SGuenter Roeck void gpiochip_free_own_desc(struct gpio_desc *desc); 733f7d4ad98SGuenter Roeck 734a0b66a73SLinus Walleij void devprop_gpiochip_set_names(struct gpio_chip *gc, 73564ebde5bSJan Kundrát const struct fwnode_handle *fwnode); 73664ebde5bSJan Kundrát 737ae0755b5SLinus Walleij #ifdef CONFIG_GPIOLIB 738ae0755b5SLinus Walleij 739c7663fa2SYueHaibing /* lock/unlock as IRQ */ 740a0b66a73SLinus Walleij int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset); 741a0b66a73SLinus Walleij void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset); 742c7663fa2SYueHaibing 7439091373aSMasahiro Yamada 7449091373aSMasahiro Yamada struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 7459091373aSMasahiro Yamada 746bb1e88ccSAlexandre Courbot #else /* CONFIG_GPIOLIB */ 747bb1e88ccSAlexandre Courbot 748bb1e88ccSAlexandre Courbot static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 749bb1e88ccSAlexandre Courbot { 750bb1e88ccSAlexandre Courbot /* GPIO can never have been requested */ 751bb1e88ccSAlexandre Courbot WARN_ON(1); 752bb1e88ccSAlexandre Courbot return ERR_PTR(-ENODEV); 753bb1e88ccSAlexandre Courbot } 754bb1e88ccSAlexandre Courbot 755a0b66a73SLinus Walleij static inline int gpiochip_lock_as_irq(struct gpio_chip *gc, 756c7663fa2SYueHaibing unsigned int offset) 757c7663fa2SYueHaibing { 758c7663fa2SYueHaibing WARN_ON(1); 759c7663fa2SYueHaibing return -EINVAL; 760c7663fa2SYueHaibing } 761c7663fa2SYueHaibing 762a0b66a73SLinus Walleij static inline void gpiochip_unlock_as_irq(struct gpio_chip *gc, 763c7663fa2SYueHaibing unsigned int offset) 764c7663fa2SYueHaibing { 765c7663fa2SYueHaibing WARN_ON(1); 766c7663fa2SYueHaibing } 767bb1e88ccSAlexandre Courbot #endif /* CONFIG_GPIOLIB */ 768bb1e88ccSAlexandre Courbot 7699091373aSMasahiro Yamada #endif /* __LINUX_GPIO_DRIVER_H */ 770