machine.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __LINUX_GPIO_MACHINE_H
  2. #define __LINUX_GPIO_MACHINE_H
  3. #include <linux/types.h>
  4. #include <linux/list.h>
  5. enum gpio_lookup_flags {
  6. GPIO_ACTIVE_HIGH = (0 << 0),
  7. GPIO_ACTIVE_LOW = (1 << 0),
  8. GPIO_OPEN_DRAIN = (1 << 1),
  9. GPIO_OPEN_SOURCE = (1 << 2),
  10. GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3),
  11. GPIO_SLEEP_MAY_LOSE_VALUE = (1 << 3),
  12. };
  13. /**
  14. * struct gpiod_lookup - lookup table
  15. * @chip_label: name of the chip the GPIO belongs to
  16. * @chip_hwnum: hardware number (i.e. relative to the chip) of the GPIO
  17. * @con_id: name of the GPIO from the device's point of view
  18. * @idx: index of the GPIO in case several GPIOs share the same name
  19. * @flags: mask of GPIO_* values
  20. *
  21. * gpiod_lookup is a lookup table for associating GPIOs to specific devices and
  22. * functions using platform data.
  23. */
  24. struct gpiod_lookup {
  25. const char *chip_label;
  26. u16 chip_hwnum;
  27. const char *con_id;
  28. unsigned int idx;
  29. enum gpio_lookup_flags flags;
  30. };
  31. struct gpiod_lookup_table {
  32. struct list_head list;
  33. const char *dev_id;
  34. struct gpiod_lookup table[];
  35. };
  36. /*
  37. * Simple definition of a single GPIO under a con_id
  38. */
  39. #define GPIO_LOOKUP(_chip_label, _chip_hwnum, _con_id, _flags) \
  40. GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, 0, _flags)
  41. /*
  42. * Use this macro if you need to have several GPIOs under the same con_id.
  43. * Each GPIO needs to use a different index and can be accessed using
  44. * gpiod_get_index()
  45. */
  46. #define GPIO_LOOKUP_IDX(_chip_label, _chip_hwnum, _con_id, _idx, _flags) \
  47. { \
  48. .chip_label = _chip_label, \
  49. .chip_hwnum = _chip_hwnum, \
  50. .con_id = _con_id, \
  51. .idx = _idx, \
  52. .flags = _flags, \
  53. }
  54. #ifdef CONFIG_GPIOLIB
  55. void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
  56. void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
  57. void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
  58. #else
  59. static inline
  60. void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
  61. static inline
  62. void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
  63. static inline
  64. void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
  65. #endif
  66. #endif /* __LINUX_GPIO_MACHINE_H */