1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_GPIO_DRIVER_H 3 #define __LINUX_GPIO_DRIVER_H 4 5 #include <linux/device.h> 6 #include <linux/types.h> 7 #include <linux/irq.h> 8 #include <linux/irqchip/chained_irq.h> 9 #include <linux/irqdomain.h> 10 #include <linux/lockdep.h> 11 #include <linux/pinctrl/pinctrl.h> 12 #include <linux/pinctrl/pinconf-generic.h> 13 14 struct gpio_desc; 15 struct of_phandle_args; 16 struct device_node; 17 struct seq_file; 18 struct gpio_device; 19 struct module; 20 enum gpiod_flags; 21 enum gpio_lookup_flags; 22 23 struct gpio_chip; 24 25 #define GPIO_LINE_DIRECTION_IN 1 26 #define GPIO_LINE_DIRECTION_OUT 0 27 28 /** 29 * struct gpio_irq_chip - GPIO interrupt controller 30 */ 31 struct gpio_irq_chip { 32 /** 33 * @chip: 34 * 35 * GPIO IRQ chip implementation, provided by GPIO driver. 36 */ 37 struct irq_chip *chip; 38 39 /** 40 * @domain: 41 * 42 * Interrupt translation domain; responsible for mapping between GPIO 43 * hwirq number and Linux IRQ number. 44 */ 45 struct irq_domain *domain; 46 47 /** 48 * @domain_ops: 49 * 50 * Table of interrupt domain operations for this IRQ chip. 51 */ 52 const struct irq_domain_ops *domain_ops; 53 54 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 55 /** 56 * @fwnode: 57 * 58 * Firmware node corresponding to this gpiochip/irqchip, necessary 59 * for hierarchical irqdomain support. 60 */ 61 struct fwnode_handle *fwnode; 62 63 /** 64 * @parent_domain: 65 * 66 * If non-NULL, will be set as the parent of this GPIO interrupt 67 * controller's IRQ domain to establish a hierarchical interrupt 68 * domain. The presence of this will activate the hierarchical 69 * interrupt support. 70 */ 71 struct irq_domain *parent_domain; 72 73 /** 74 * @child_to_parent_hwirq: 75 * 76 * This callback translates a child hardware IRQ offset to a parent 77 * hardware IRQ offset on a hierarchical interrupt chip. The child 78 * hardware IRQs correspond to the GPIO index 0..ngpio-1 (see the 79 * ngpio field of struct gpio_chip) and the corresponding parent 80 * hardware IRQ and type (such as IRQ_TYPE_*) shall be returned by 81 * the driver. The driver can calculate this from an offset or using 82 * a lookup table or whatever method is best for this chip. Return 83 * 0 on successful translation in the driver. 84 * 85 * If some ranges of hardware IRQs do not have a corresponding parent 86 * HWIRQ, return -EINVAL, but also make sure to fill in @valid_mask and 87 * @need_valid_mask to make these GPIO lines unavailable for 88 * translation. 89 */ 90 int (*child_to_parent_hwirq)(struct gpio_chip *chip, 91 unsigned int child_hwirq, 92 unsigned int child_type, 93 unsigned int *parent_hwirq, 94 unsigned int *parent_type); 95 96 /** 97 * @populate_parent_fwspec: 98 * 99 * This optional callback populates the &struct irq_fwspec for the 100 * parent's IRQ domain. If this is not specified, then 101 * &gpiochip_populate_parent_fwspec_twocell will be used. A four-cell 102 * variant named &gpiochip_populate_parent_fwspec_fourcell is also 103 * available. 104 */ 105 void (*populate_parent_fwspec)(struct gpio_chip *chip, 106 struct irq_fwspec *fwspec, 107 unsigned int parent_hwirq, 108 unsigned int parent_type); 109 110 /** 111 * @child_offset_to_irq: 112 * 113 * This optional callback is used to translate the child's GPIO line 114 * offset on the GPIO chip to an IRQ number for the GPIO to_irq() 115 * callback. If this is not specified, then a default callback will be 116 * provided that returns the line offset. 117 */ 118 unsigned int (*child_offset_to_irq)(struct gpio_chip *chip, 119 unsigned int pin); 120 121 /** 122 * @child_irq_domain_ops: 123 * 124 * The IRQ domain operations that will be used for this GPIO IRQ 125 * chip. If no operations are provided, then default callbacks will 126 * be populated to setup the IRQ hierarchy. Some drivers need to 127 * supply their own translate function. 128 */ 129 struct irq_domain_ops child_irq_domain_ops; 130 #endif 131 132 /** 133 * @handler: 134 * 135 * The IRQ handler to use (often a predefined IRQ core function) for 136 * GPIO IRQs, provided by GPIO driver. 137 */ 138 irq_flow_handler_t handler; 139 140 /** 141 * @default_type: 142 * 143 * Default IRQ triggering type applied during GPIO driver 144 * initialization, provided by GPIO driver. 145 */ 146 unsigned int default_type; 147 148 /** 149 * @lock_key: 150 * 151 * Per GPIO IRQ chip lockdep class for IRQ lock. 152 */ 153 struct lock_class_key *lock_key; 154 155 /** 156 * @request_key: 157 * 158 * Per GPIO IRQ chip lockdep class for IRQ request. 159 */ 160 struct lock_class_key *request_key; 161 162 /** 163 * @parent_handler: 164 * 165 * The interrupt handler for the GPIO chip's parent interrupts, may be 166 * NULL if the parent interrupts are nested rather than cascaded. 167 */ 168 irq_flow_handler_t parent_handler; 169 170 /** 171 * @parent_handler_data: 172 * 173 * Data associated, and passed to, the handler for the parent 174 * interrupt. 175 */ 176 void *parent_handler_data; 177 178 /** 179 * @num_parents: 180 * 181 * The number of interrupt parents of a GPIO chip. 182 */ 183 unsigned int num_parents; 184 185 /** 186 * @parents: 187 * 188 * A list of interrupt parents of a GPIO chip. This is owned by the 189 * driver, so the core will only reference this list, not modify it. 190 */ 191 unsigned int *parents; 192 193 /** 194 * @map: 195 * 196 * A list of interrupt parents for each line of a GPIO chip. 197 */ 198 unsigned int *map; 199 200 /** 201 * @threaded: 202 * 203 * True if set the interrupt handling uses nested threads. 204 */ 205 bool threaded; 206 207 /** 208 * @init_hw: optional routine to initialize hardware before 209 * an IRQ chip will be added. This is quite useful when 210 * a particular driver wants to clear IRQ related registers 211 * in order to avoid undesired events. 212 */ 213 int (*init_hw)(struct gpio_chip *chip); 214 215 /** 216 * @init_valid_mask: optional routine to initialize @valid_mask, to be 217 * used if not all GPIO lines are valid interrupts. Sometimes some 218 * lines just cannot fire interrupts, and this routine, when defined, 219 * is passed a bitmap in "valid_mask" and it will have ngpios 220 * bits from 0..(ngpios-1) set to "1" as in valid. The callback can 221 * then directly set some bits to "0" if they cannot be used for 222 * interrupts. 223 */ 224 void (*init_valid_mask)(struct gpio_chip *chip, 225 unsigned long *valid_mask, 226 unsigned int ngpios); 227 228 /** 229 * @valid_mask: 230 * 231 * If not %NULL holds bitmask of GPIOs which are valid to be included 232 * in IRQ domain of the chip. 233 */ 234 unsigned long *valid_mask; 235 236 /** 237 * @first: 238 * 239 * Required for static IRQ allocation. If set, irq_domain_add_simple() 240 * will allocate and map all IRQs during initialization. 241 */ 242 unsigned int first; 243 244 /** 245 * @irq_enable: 246 * 247 * Store old irq_chip irq_enable callback 248 */ 249 void (*irq_enable)(struct irq_data *data); 250 251 /** 252 * @irq_disable: 253 * 254 * Store old irq_chip irq_disable callback 255 */ 256 void (*irq_disable)(struct irq_data *data); 257 }; 258 259 /** 260 * struct gpio_chip - abstract a GPIO controller 261 * @label: a functional name for the GPIO device, such as a part 262 * number or the name of the SoC IP-block implementing it. 263 * @gpiodev: the internal state holder, opaque struct 264 * @parent: optional parent device providing the GPIOs 265 * @owner: helps prevent removal of modules exporting active GPIOs 266 * @request: optional hook for chip-specific activation, such as 267 * enabling module power and clock; may sleep 268 * @free: optional hook for chip-specific deactivation, such as 269 * disabling module power and clock; may sleep 270 * @get_direction: returns direction for signal "offset", 0=out, 1=in, 271 * (same as GPIOF_DIR_XXX), or negative error. 272 * It is recommended to always implement this function, even on 273 * input-only or output-only gpio chips. 274 * @direction_input: configures signal "offset" as input, or returns error 275 * This can be omitted on input-only or output-only gpio chips. 276 * @direction_output: configures signal "offset" as output, or returns error 277 * This can be omitted on input-only or output-only gpio chips. 278 * @get: returns value for signal "offset", 0=low, 1=high, or negative error 279 * @get_multiple: reads values for multiple signals defined by "mask" and 280 * stores them in "bits", returns 0 on success or negative error 281 * @set: assigns output value for signal "offset" 282 * @set_multiple: assigns output values for multiple signals defined by "mask" 283 * @set_config: optional hook for all kinds of settings. Uses the same 284 * packed config format as generic pinconf. 285 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 286 * implementation may not sleep 287 * @dbg_show: optional routine to show contents in debugfs; default code 288 * will be used when this is omitted, but custom code can show extra 289 * state (such as pullup/pulldown configuration). 290 * @init_valid_mask: optional routine to initialize @valid_mask, to be used if 291 * not all GPIOs are valid. 292 * @add_pin_ranges: optional routine to initialize pin ranges, to be used when 293 * requires special mapping of the pins that provides GPIO functionality. 294 * It is called after adding GPIO chip and before adding IRQ chip. 295 * @base: identifies the first GPIO number handled by this chip; 296 * or, if negative during registration, requests dynamic ID allocation. 297 * DEPRECATION: providing anything non-negative and nailing the base 298 * offset of GPIO chips is deprecated. Please pass -1 as base to 299 * let gpiolib select the chip base in all possible cases. We want to 300 * get rid of the static GPIO number space in the long run. 301 * @ngpio: the number of GPIOs handled by this controller; the last GPIO 302 * handled is (base + ngpio - 1). 303 * @names: if set, must be an array of strings to use as alternative 304 * names for the GPIOs in this chip. Any entry in the array 305 * may be NULL if there is no alias for the GPIO, however the 306 * array must be @ngpio entries long. A name can include a single printk 307 * format specifier for an unsigned int. It is substituted by the actual 308 * number of the gpio. 309 * @can_sleep: flag must be set iff get()/set() methods sleep, as they 310 * must while accessing GPIO expander chips over I2C or SPI. This 311 * implies that if the chip supports IRQs, these IRQs need to be threaded 312 * as the chip access may sleep when e.g. reading out the IRQ status 313 * registers. 314 * @read_reg: reader function for generic GPIO 315 * @write_reg: writer function for generic GPIO 316 * @be_bits: if the generic GPIO has big endian bit order (bit 31 is representing 317 * line 0, bit 30 is line 1 ... bit 0 is line 31) this is set to true by the 318 * generic GPIO core. It is for internal housekeeping only. 319 * @reg_dat: data (in) register for generic GPIO 320 * @reg_set: output set register (out=high) for generic GPIO 321 * @reg_clr: output clear register (out=low) for generic GPIO 322 * @reg_dir_out: direction out setting register for generic GPIO 323 * @reg_dir_in: direction in setting register for generic GPIO 324 * @bgpio_dir_unreadable: indicates that the direction register(s) cannot 325 * be read and we need to rely on out internal state tracking. 326 * @bgpio_bits: number of register bits used for a generic GPIO i.e. 327 * <register width> * 8 328 * @bgpio_lock: used to lock chip->bgpio_data. Also, this is needed to keep 329 * shadowed and real data registers writes together. 330 * @bgpio_data: shadowed data register for generic GPIO to clear/set bits 331 * safely. 332 * @bgpio_dir: shadowed direction register for generic GPIO to clear/set 333 * direction safely. A "1" in this word means the line is set as 334 * output. 335 * 336 * A gpio_chip can help platforms abstract various sources of GPIOs so 337 * they can all be accessed through a common programing interface. 338 * Example sources would be SOC controllers, FPGAs, multifunction 339 * chips, dedicated GPIO expanders, and so on. 340 * 341 * Each chip controls a number of signals, identified in method calls 342 * by "offset" values in the range 0..(@ngpio - 1). When those signals 343 * are referenced through calls like gpio_get_value(gpio), the offset 344 * is calculated by subtracting @base from the gpio number. 345 */ 346 struct gpio_chip { 347 const char *label; 348 struct gpio_device *gpiodev; 349 struct device *parent; 350 struct module *owner; 351 352 int (*request)(struct gpio_chip *chip, 353 unsigned offset); 354 void (*free)(struct gpio_chip *chip, 355 unsigned offset); 356 int (*get_direction)(struct gpio_chip *chip, 357 unsigned offset); 358 int (*direction_input)(struct gpio_chip *chip, 359 unsigned offset); 360 int (*direction_output)(struct gpio_chip *chip, 361 unsigned offset, int value); 362 int (*get)(struct gpio_chip *chip, 363 unsigned offset); 364 int (*get_multiple)(struct gpio_chip *chip, 365 unsigned long *mask, 366 unsigned long *bits); 367 void (*set)(struct gpio_chip *chip, 368 unsigned offset, int value); 369 void (*set_multiple)(struct gpio_chip *chip, 370 unsigned long *mask, 371 unsigned long *bits); 372 int (*set_config)(struct gpio_chip *chip, 373 unsigned offset, 374 unsigned long config); 375 int (*to_irq)(struct gpio_chip *chip, 376 unsigned offset); 377 378 void (*dbg_show)(struct seq_file *s, 379 struct gpio_chip *chip); 380 381 int (*init_valid_mask)(struct gpio_chip *chip, 382 unsigned long *valid_mask, 383 unsigned int ngpios); 384 385 int (*add_pin_ranges)(struct gpio_chip *chip); 386 387 int base; 388 u16 ngpio; 389 const char *const *names; 390 bool can_sleep; 391 392 #if IS_ENABLED(CONFIG_GPIO_GENERIC) 393 unsigned long (*read_reg)(void __iomem *reg); 394 void (*write_reg)(void __iomem *reg, unsigned long data); 395 bool be_bits; 396 void __iomem *reg_dat; 397 void __iomem *reg_set; 398 void __iomem *reg_clr; 399 void __iomem *reg_dir_out; 400 void __iomem *reg_dir_in; 401 bool bgpio_dir_unreadable; 402 int bgpio_bits; 403 spinlock_t bgpio_lock; 404 unsigned long bgpio_data; 405 unsigned long bgpio_dir; 406 #endif /* CONFIG_GPIO_GENERIC */ 407 408 #ifdef CONFIG_GPIOLIB_IRQCHIP 409 /* 410 * With CONFIG_GPIOLIB_IRQCHIP we get an irqchip inside the gpiolib 411 * to handle IRQs for most practical cases. 412 */ 413 414 /** 415 * @irq: 416 * 417 * Integrates interrupt chip functionality with the GPIO chip. Can be 418 * used to handle IRQs for most practical cases. 419 */ 420 struct gpio_irq_chip irq; 421 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 422 423 /** 424 * @valid_mask: 425 * 426 * If not %NULL holds bitmask of GPIOs which are valid to be used 427 * from the chip. 428 */ 429 unsigned long *valid_mask; 430 431 #if defined(CONFIG_OF_GPIO) 432 /* 433 * If CONFIG_OF is enabled, then all GPIO controllers described in the 434 * device tree automatically may have an OF translation 435 */ 436 437 /** 438 * @of_node: 439 * 440 * Pointer to a device tree node representing this GPIO controller. 441 */ 442 struct device_node *of_node; 443 444 /** 445 * @of_gpio_n_cells: 446 * 447 * Number of cells used to form the GPIO specifier. 448 */ 449 unsigned int of_gpio_n_cells; 450 451 /** 452 * @of_xlate: 453 * 454 * Callback to translate a device tree GPIO specifier into a chip- 455 * relative GPIO number and flags. 456 */ 457 int (*of_xlate)(struct gpio_chip *gc, 458 const struct of_phandle_args *gpiospec, u32 *flags); 459 #endif /* CONFIG_OF_GPIO */ 460 }; 461 462 extern const char *gpiochip_is_requested(struct gpio_chip *chip, 463 unsigned offset); 464 465 /* add/remove chips */ 466 extern int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, 467 struct lock_class_key *lock_key, 468 struct lock_class_key *request_key); 469 470 /** 471 * gpiochip_add_data() - register a gpio_chip 472 * @chip: the chip to register, with chip->base initialized 473 * @data: driver-private data associated with this chip 474 * 475 * Context: potentially before irqs will work 476 * 477 * When gpiochip_add_data() is called very early during boot, so that GPIOs 478 * can be freely used, the chip->parent device must be registered before 479 * the gpio framework's arch_initcall(). Otherwise sysfs initialization 480 * for GPIOs will fail rudely. 481 * 482 * gpiochip_add_data() must only be called after gpiolib initialization, 483 * ie after core_initcall(). 484 * 485 * If chip->base is negative, this requests dynamic assignment of 486 * a range of valid GPIOs. 487 * 488 * Returns: 489 * A negative errno if the chip can't be registered, such as because the 490 * chip->base is invalid or already associated with a different chip. 491 * Otherwise it returns zero as a success code. 492 */ 493 #ifdef CONFIG_LOCKDEP 494 #define gpiochip_add_data(chip, data) ({ \ 495 static struct lock_class_key lock_key; \ 496 static struct lock_class_key request_key; \ 497 gpiochip_add_data_with_key(chip, data, &lock_key, \ 498 &request_key); \ 499 }) 500 #else 501 #define gpiochip_add_data(chip, data) gpiochip_add_data_with_key(chip, data, NULL, NULL) 502 #endif /* CONFIG_LOCKDEP */ 503 504 static inline int gpiochip_add(struct gpio_chip *chip) 505 { 506 return gpiochip_add_data(chip, NULL); 507 } 508 extern void gpiochip_remove(struct gpio_chip *chip); 509 extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip, 510 void *data); 511 512 extern struct gpio_chip *gpiochip_find(void *data, 513 int (*match)(struct gpio_chip *chip, void *data)); 514 515 bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset); 516 int gpiochip_reqres_irq(struct gpio_chip *chip, unsigned int offset); 517 void gpiochip_relres_irq(struct gpio_chip *chip, unsigned int offset); 518 void gpiochip_disable_irq(struct gpio_chip *chip, unsigned int offset); 519 void gpiochip_enable_irq(struct gpio_chip *chip, unsigned int offset); 520 521 /* Line status inquiry for drivers */ 522 bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset); 523 bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset); 524 525 /* Sleep persistence inquiry for drivers */ 526 bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset); 527 bool gpiochip_line_is_valid(const struct gpio_chip *chip, unsigned int offset); 528 529 /* get driver data */ 530 void *gpiochip_get_data(struct gpio_chip *chip); 531 532 struct bgpio_pdata { 533 const char *label; 534 int base; 535 int ngpio; 536 }; 537 538 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY 539 540 void gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *chip, 541 struct irq_fwspec *fwspec, 542 unsigned int parent_hwirq, 543 unsigned int parent_type); 544 void gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *chip, 545 struct irq_fwspec *fwspec, 546 unsigned int parent_hwirq, 547 unsigned int parent_type); 548 549 #else 550 551 static inline void gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *chip, 552 struct irq_fwspec *fwspec, 553 unsigned int parent_hwirq, 554 unsigned int parent_type) 555 { 556 } 557 558 static inline void gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *chip, 559 struct irq_fwspec *fwspec, 560 unsigned int parent_hwirq, 561 unsigned int parent_type) 562 { 563 } 564 565 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ 566 567 int bgpio_init(struct gpio_chip *gc, struct device *dev, 568 unsigned long sz, void __iomem *dat, void __iomem *set, 569 void __iomem *clr, void __iomem *dirout, void __iomem *dirin, 570 unsigned long flags); 571 572 #define BGPIOF_BIG_ENDIAN BIT(0) 573 #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */ 574 #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */ 575 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3) 576 #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */ 577 #define BGPIOF_NO_OUTPUT BIT(5) /* only input */ 578 579 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq, 580 irq_hw_number_t hwirq); 581 void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq); 582 583 int gpiochip_irq_domain_activate(struct irq_domain *domain, 584 struct irq_data *data, bool reserve); 585 void gpiochip_irq_domain_deactivate(struct irq_domain *domain, 586 struct irq_data *data); 587 588 void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 589 struct irq_chip *irqchip, 590 unsigned int parent_irq, 591 irq_flow_handler_t parent_handler); 592 593 void gpiochip_set_nested_irqchip(struct gpio_chip *gpiochip, 594 struct irq_chip *irqchip, 595 unsigned int parent_irq); 596 597 int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip, 598 struct irq_chip *irqchip, 599 unsigned int first_irq, 600 irq_flow_handler_t handler, 601 unsigned int type, 602 bool threaded, 603 struct lock_class_key *lock_key, 604 struct lock_class_key *request_key); 605 606 bool gpiochip_irqchip_irq_valid(const struct gpio_chip *gpiochip, 607 unsigned int offset); 608 609 #ifdef CONFIG_LOCKDEP 610 611 /* 612 * Lockdep requires that each irqchip instance be created with a 613 * unique key so as to avoid unnecessary warnings. This upfront 614 * boilerplate static inlines provides such a key for each 615 * unique instance. 616 */ 617 static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 618 struct irq_chip *irqchip, 619 unsigned int first_irq, 620 irq_flow_handler_t handler, 621 unsigned int type) 622 { 623 static struct lock_class_key lock_key; 624 static struct lock_class_key request_key; 625 626 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 627 handler, type, false, 628 &lock_key, &request_key); 629 } 630 631 static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 632 struct irq_chip *irqchip, 633 unsigned int first_irq, 634 irq_flow_handler_t handler, 635 unsigned int type) 636 { 637 638 static struct lock_class_key lock_key; 639 static struct lock_class_key request_key; 640 641 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 642 handler, type, true, 643 &lock_key, &request_key); 644 } 645 #else /* ! CONFIG_LOCKDEP */ 646 static inline int gpiochip_irqchip_add(struct gpio_chip *gpiochip, 647 struct irq_chip *irqchip, 648 unsigned int first_irq, 649 irq_flow_handler_t handler, 650 unsigned int type) 651 { 652 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 653 handler, type, false, NULL, NULL); 654 } 655 656 static inline int gpiochip_irqchip_add_nested(struct gpio_chip *gpiochip, 657 struct irq_chip *irqchip, 658 unsigned int first_irq, 659 irq_flow_handler_t handler, 660 unsigned int type) 661 { 662 return gpiochip_irqchip_add_key(gpiochip, irqchip, first_irq, 663 handler, type, true, NULL, NULL); 664 } 665 #endif /* CONFIG_LOCKDEP */ 666 667 int gpiochip_generic_request(struct gpio_chip *chip, unsigned offset); 668 void gpiochip_generic_free(struct gpio_chip *chip, unsigned offset); 669 int gpiochip_generic_config(struct gpio_chip *chip, unsigned offset, 670 unsigned long config); 671 672 /** 673 * struct gpio_pin_range - pin range controlled by a gpio chip 674 * @node: list for maintaining set of pin ranges, used internally 675 * @pctldev: pinctrl device which handles corresponding pins 676 * @range: actual range of pins controlled by a gpio controller 677 */ 678 struct gpio_pin_range { 679 struct list_head node; 680 struct pinctrl_dev *pctldev; 681 struct pinctrl_gpio_range range; 682 }; 683 684 #ifdef CONFIG_PINCTRL 685 686 int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 687 unsigned int gpio_offset, unsigned int pin_offset, 688 unsigned int npins); 689 int gpiochip_add_pingroup_range(struct gpio_chip *chip, 690 struct pinctrl_dev *pctldev, 691 unsigned int gpio_offset, const char *pin_group); 692 void gpiochip_remove_pin_ranges(struct gpio_chip *chip); 693 694 #else /* ! CONFIG_PINCTRL */ 695 696 static inline int 697 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 698 unsigned int gpio_offset, unsigned int pin_offset, 699 unsigned int npins) 700 { 701 return 0; 702 } 703 static inline int 704 gpiochip_add_pingroup_range(struct gpio_chip *chip, 705 struct pinctrl_dev *pctldev, 706 unsigned int gpio_offset, const char *pin_group) 707 { 708 return 0; 709 } 710 711 static inline void 712 gpiochip_remove_pin_ranges(struct gpio_chip *chip) 713 { 714 } 715 716 #endif /* CONFIG_PINCTRL */ 717 718 struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 719 const char *label, 720 enum gpio_lookup_flags lflags, 721 enum gpiod_flags dflags); 722 void gpiochip_free_own_desc(struct gpio_desc *desc); 723 724 void devprop_gpiochip_set_names(struct gpio_chip *chip, 725 const struct fwnode_handle *fwnode); 726 727 #ifdef CONFIG_GPIOLIB 728 729 /* lock/unlock as IRQ */ 730 int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset); 731 void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset); 732 733 734 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); 735 736 #else /* CONFIG_GPIOLIB */ 737 738 static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) 739 { 740 /* GPIO can never have been requested */ 741 WARN_ON(1); 742 return ERR_PTR(-ENODEV); 743 } 744 745 static inline int gpiochip_lock_as_irq(struct gpio_chip *chip, 746 unsigned int offset) 747 { 748 WARN_ON(1); 749 return -EINVAL; 750 } 751 752 static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip, 753 unsigned int offset) 754 { 755 WARN_ON(1); 756 } 757 #endif /* CONFIG_GPIOLIB */ 758 759 #endif /* __LINUX_GPIO_DRIVER_H */ 760