regmap.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _LINUX_GPIO_REGMAP_H
  3. #define _LINUX_GPIO_REGMAP_H
  4. struct device;
  5. struct fwnode_handle;
  6. struct gpio_regmap;
  7. struct irq_domain;
  8. struct regmap;
  9. #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
  10. #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
  11. /**
  12. * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
  13. * @parent: The parent device
  14. * @regmap: The regmap used to access the registers
  15. * given, the name of the device is used
  16. * @fwnode: (Optional) The firmware node.
  17. * If not given, the fwnode of the parent is used.
  18. * @label: (Optional) Descriptive name for GPIO controller.
  19. * If not given, the name of the device is used.
  20. * @ngpio: Number of GPIOs
  21. * @names: (Optional) Array of names for gpios
  22. * @reg_dat_base: (Optional) (in) register base address
  23. * @reg_set_base: (Optional) set register base address
  24. * @reg_clr_base: (Optional) clear register base address
  25. * @reg_dir_in_base: (Optional) in setting register base address
  26. * @reg_dir_out_base: (Optional) out setting register base address
  27. * @reg_stride: (Optional) May be set if the registers (of the
  28. * same type, dat, set, etc) are not consecutive.
  29. * @ngpio_per_reg: Number of GPIOs per register
  30. * @irq_domain: (Optional) IRQ domain if the controller is
  31. * interrupt-capable
  32. * @reg_mask_xlate: (Optional) Translates base address and GPIO
  33. * offset to a register/bitmask pair. If not
  34. * given the default gpio_regmap_simple_xlate()
  35. * is used.
  36. * @drvdata: (Optional) Pointer to driver specific data which is
  37. * not used by gpio-remap but is provided "as is" to the
  38. * driver callback(s).
  39. *
  40. * The ->reg_mask_xlate translates a given base address and GPIO offset to
  41. * register and mask pair. The base address is one of the given register
  42. * base addresses in this structure.
  43. *
  44. * Although all register base addresses are marked as optional, there are
  45. * several rules:
  46. * 1. if you only have @reg_dat_base set, then it is input-only
  47. * 2. if you only have @reg_set_base set, then it is output-only
  48. * 3. if you have either @reg_dir_in_base or @reg_dir_out_base set, then
  49. * you have to set both @reg_dat_base and @reg_set_base
  50. * 4. if you have @reg_set_base set, you may also set @reg_clr_base to have
  51. * two different registers for setting and clearing the output. This is
  52. * also valid for the output-only case.
  53. * 5. @reg_dir_in_base and @reg_dir_out_base are exclusive; is there really
  54. * hardware which has redundant registers?
  55. *
  56. * Note: All base addresses may have the special value %GPIO_REGMAP_ADDR_ZERO
  57. * which forces the address to the value 0.
  58. */
  59. struct gpio_regmap_config {
  60. struct device *parent;
  61. struct regmap *regmap;
  62. struct fwnode_handle *fwnode;
  63. const char *label;
  64. int ngpio;
  65. const char *const *names;
  66. unsigned int reg_dat_base;
  67. unsigned int reg_set_base;
  68. unsigned int reg_clr_base;
  69. unsigned int reg_dir_in_base;
  70. unsigned int reg_dir_out_base;
  71. int reg_stride;
  72. int ngpio_per_reg;
  73. struct irq_domain *irq_domain;
  74. int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
  75. unsigned int offset, unsigned int *reg,
  76. unsigned int *mask);
  77. void *drvdata;
  78. };
  79. struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config);
  80. void gpio_regmap_unregister(struct gpio_regmap *gpio);
  81. struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
  82. const struct gpio_regmap_config *config);
  83. void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio);
  84. #endif /* _LINUX_GPIO_REGMAP_H */