gpio_event.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* include/linux/gpio_event.h
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #ifndef _LINUX_GPIO_EVENT_H
  16. #define _LINUX_GPIO_EVENT_H
  17. #include <linux/input.h>
  18. struct gpio_event_input_devs {
  19. int count;
  20. struct input_dev *dev[];
  21. };
  22. enum {
  23. GPIO_EVENT_FUNC_UNINIT = 0x0,
  24. GPIO_EVENT_FUNC_INIT = 0x1,
  25. GPIO_EVENT_FUNC_SUSPEND = 0x2,
  26. GPIO_EVENT_FUNC_RESUME = 0x3,
  27. };
  28. struct gpio_event_info {
  29. int (*func)(struct gpio_event_input_devs *input_devs,
  30. struct gpio_event_info *info,
  31. void **data, int func);
  32. int (*event)(struct gpio_event_input_devs *input_devs,
  33. struct gpio_event_info *info,
  34. void **data, unsigned int dev, unsigned int type,
  35. unsigned int code, int value); /* out events */
  36. bool no_suspend;
  37. };
  38. struct gpio_event_platform_data {
  39. const char *name;
  40. struct gpio_event_info **info;
  41. size_t info_count;
  42. int (*power)(const struct gpio_event_platform_data *pdata, bool on);
  43. const char *names[]; /* If name is NULL, names contain a NULL */
  44. /* terminated list of input devices to create */
  45. };
  46. #define GPIO_EVENT_DEV_NAME "gpio-event"
  47. /* Key matrix */
  48. enum gpio_event_matrix_flags {
  49. /* unset: drive active output low, set: drive active output high */
  50. GPIOKPF_ACTIVE_HIGH = 1U << 0,
  51. GPIOKPF_DEBOUNCE = 1U << 1,
  52. GPIOKPF_REMOVE_SOME_PHANTOM_KEYS = 1U << 2,
  53. GPIOKPF_REMOVE_PHANTOM_KEYS = GPIOKPF_REMOVE_SOME_PHANTOM_KEYS |
  54. GPIOKPF_DEBOUNCE,
  55. GPIOKPF_DRIVE_INACTIVE = 1U << 3,
  56. GPIOKPF_LEVEL_TRIGGERED_IRQ = 1U << 4,
  57. GPIOKPF_PRINT_UNMAPPED_KEYS = 1U << 16,
  58. GPIOKPF_PRINT_MAPPED_KEYS = 1U << 17,
  59. GPIOKPF_PRINT_PHANTOM_KEYS = 1U << 18,
  60. };
  61. #define MATRIX_CODE_BITS (10)
  62. #define MATRIX_KEY_MASK ((1U << MATRIX_CODE_BITS) - 1)
  63. #define MATRIX_KEY(dev, code) \
  64. (((dev) << MATRIX_CODE_BITS) | (code & MATRIX_KEY_MASK))
  65. extern int gpio_event_matrix_func(struct gpio_event_input_devs *input_devs,
  66. struct gpio_event_info *info, void **data, int func);
  67. struct gpio_event_matrix_info {
  68. /* initialize to gpio_event_matrix_func */
  69. struct gpio_event_info info;
  70. /* size must be ninputs * noutputs */
  71. const unsigned short *keymap;
  72. unsigned int *input_gpios;
  73. unsigned int *output_gpios;
  74. unsigned int ninputs;
  75. unsigned int noutputs;
  76. /* time to wait before reading inputs after driving each output */
  77. ktime_t settle_time;
  78. /* time to wait before scanning the keypad a second time */
  79. ktime_t debounce_delay;
  80. ktime_t poll_time;
  81. unsigned flags;
  82. };
  83. /* Directly connected inputs and outputs */
  84. enum gpio_event_direct_flags {
  85. GPIOEDF_ACTIVE_HIGH = 1U << 0,
  86. /* GPIOEDF_USE_DOWN_IRQ = 1U << 1, */
  87. /* GPIOEDF_USE_IRQ = (1U << 2) | GPIOIDF_USE_DOWN_IRQ, */
  88. GPIOEDF_PRINT_KEYS = 1U << 8,
  89. GPIOEDF_PRINT_KEY_DEBOUNCE = 1U << 9,
  90. GPIOEDF_PRINT_KEY_UNSTABLE = 1U << 10,
  91. };
  92. struct gpio_event_direct_entry {
  93. uint32_t gpio:16;
  94. uint32_t code:10;
  95. uint32_t dev:6;
  96. };
  97. /* inputs */
  98. extern int gpio_event_input_func(struct gpio_event_input_devs *input_devs,
  99. struct gpio_event_info *info, void **data, int func);
  100. struct gpio_event_input_info {
  101. /* initialize to gpio_event_input_func */
  102. struct gpio_event_info info;
  103. ktime_t debounce_time;
  104. ktime_t poll_time;
  105. uint16_t flags;
  106. uint16_t type;
  107. const struct gpio_event_direct_entry *keymap;
  108. size_t keymap_size;
  109. };
  110. /* outputs */
  111. extern int gpio_event_output_func(struct gpio_event_input_devs *input_devs,
  112. struct gpio_event_info *info, void **data, int func);
  113. extern int gpio_event_output_event(struct gpio_event_input_devs *input_devs,
  114. struct gpio_event_info *info, void **data,
  115. unsigned int dev, unsigned int type,
  116. unsigned int code, int value);
  117. struct gpio_event_output_info {
  118. /* initialize to gpio_event_output_func and gpio_event_output_event */
  119. struct gpio_event_info info;
  120. uint16_t flags;
  121. uint16_t type;
  122. const struct gpio_event_direct_entry *keymap;
  123. size_t keymap_size;
  124. };
  125. /* axes */
  126. enum gpio_event_axis_flags {
  127. GPIOEAF_PRINT_UNKNOWN_DIRECTION = 1U << 16,
  128. GPIOEAF_PRINT_RAW = 1U << 17,
  129. GPIOEAF_PRINT_EVENT = 1U << 18,
  130. };
  131. extern int gpio_event_axis_func(struct gpio_event_input_devs *input_devs,
  132. struct gpio_event_info *info, void **data, int func);
  133. struct gpio_event_axis_info {
  134. /* initialize to gpio_event_axis_func */
  135. struct gpio_event_info info;
  136. uint8_t count; /* number of gpios for this axis */
  137. uint8_t dev; /* device index when using multiple input devices */
  138. uint8_t type; /* EV_REL or EV_ABS */
  139. uint16_t code;
  140. uint16_t decoded_size;
  141. uint16_t (*map)(struct gpio_event_axis_info *info, uint16_t in);
  142. uint32_t *gpio;
  143. uint32_t flags;
  144. };
  145. #define gpio_axis_2bit_gray_map gpio_axis_4bit_gray_map
  146. #define gpio_axis_3bit_gray_map gpio_axis_4bit_gray_map
  147. uint16_t gpio_axis_4bit_gray_map(
  148. struct gpio_event_axis_info *info, uint16_t in);
  149. uint16_t gpio_axis_5bit_singletrack_map(
  150. struct gpio_event_axis_info *info, uint16_t in);
  151. #endif