machine.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_GPIO_MACHINE_H
  3. #define __LINUX_GPIO_MACHINE_H
  4. #include <linux/types.h>
  5. #include <linux/list.h>
  6. enum gpio_lookup_flags {
  7. GPIO_ACTIVE_HIGH = (0 << 0),
  8. GPIO_ACTIVE_LOW = (1 << 0),
  9. GPIO_OPEN_DRAIN = (1 << 1),
  10. GPIO_OPEN_SOURCE = (1 << 2),
  11. GPIO_PERSISTENT = (0 << 3),
  12. GPIO_TRANSITORY = (1 << 3),
  13. };
  14. /**
  15. * struct gpiod_lookup - lookup table
  16. * @chip_label: name of the chip the GPIO belongs to
  17. * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
  18. * @con_id: name of the GPIO from the device's point of view
  19. * @idx: index of the GPIO in case several GPIOs share the same name
  20. * @flags: mask of GPIO_* values
  21. *
  22. * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
  23. * functions using platform data.
  24. */
  25. struct gpiod_lookup {
  26. const char *chip_label;
  27. u16 chip_hwnum;
  28. const char *con_id;
  29. unsigned int idx;
  30. enum gpio_lookup_flags flags;
  31. };
  32. struct gpiod_lookup_table {
  33. struct list_head list;
  34. const char *dev_id;
  35. struct gpiod_lookup table[];
  36. };
  37. /**
  38. * struct gpiod_hog - GPIO line hog table
  39. * @chip_label: name of the chip the GPIO belongs to
  40. * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
  41. * @line_name: consumer name for the hogged line
  42. * @lflags: mask of GPIO lookup flags
  43. * @dflags: GPIO flags used to specify the direction and value
  44. */
  45. struct gpiod_hog {
  46. struct list_head list;
  47. const char *chip_label;
  48. u16 chip_hwnum;
  49. const char *line_name;
  50. enum gpio_lookup_flags lflags;
  51. int dflags;
  52. };
  53. /*
  54. * Simple definition of a single GPIO under a con_id
  55. */
  56. #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
  57. GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
  58. /*
  59. * Use this macro if you need to have several GPIOs under the same con_id.
  60. * Each GPIO needs to use a different index and can be accessed using
  61. * gpiod_get_index()
  62. */
  63. #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
  64. { \
  65. .chip_label = _chip_label, \
  66. .chip_hwnum = _chip_hwnum, \
  67. .con_id = _con_id, \
  68. .idx = _idx, \
  69. .flags = _flags, \
  70. }
  71. /*
  72. * Simple definition of a single GPIO hog in an array.
  73. */
  74. #define GPIO_HOG(_chip_label, _chip_hwnum, _line_name, _lflags, _dflags) \
  75. { \
  76. .chip_label = _chip_label, \
  77. .chip_hwnum = _chip_hwnum, \
  78. .line_name = _line_name, \
  79. .lflags = _lflags, \
  80. .dflags = _dflags, \
  81. }
  82. #ifdef CONFIG_GPIOLIB
  83. void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
  84. void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
  85. void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
  86. void gpiod_add_hogs(struct gpiod_hog *hogs);
  87. #else
  88. static inline
  89. void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
  90. static inline
  91. void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
  92. static inline
  93. void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
  94. static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {}
  95. #endif
  96. #endif /* __LINUX_GPIO_MACHINE_H */