Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 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 | |
| 16 | #ifndef _LINUX_GPIO_EVENT_H |
| 17 | #define _LINUX_GPIO_EVENT_H |
| 18 | |
| 19 | #include <linux/input.h> |
| 20 | |
| 21 | #define KEY_LOGD(fmt, args...) printk(KERN_DEBUG "[KEY] "fmt, ##args) |
| 22 | #define KEY_LOGI(fmt, args...) printk(KERN_INFO "[KEY] "fmt, ##args) |
| 23 | #define KEY_LOGE(fmt, args...) printk(KERN_ERR "[KEY] "fmt, ##args) |
| 24 | |
| 25 | struct gpio_event_input_devs { |
| 26 | int count; |
| 27 | struct input_dev *dev[]; |
| 28 | }; |
| 29 | enum { |
| 30 | GPIO_EVENT_FUNC_UNINIT = 0x0, |
| 31 | GPIO_EVENT_FUNC_INIT = 0x1, |
| 32 | GPIO_EVENT_FUNC_SUSPEND = 0x2, |
| 33 | GPIO_EVENT_FUNC_RESUME = 0x3, |
| 34 | }; |
| 35 | struct gpio_event_info { |
| 36 | int (*func)(struct gpio_event_input_devs *input_devs, |
| 37 | struct gpio_event_info *info, |
| 38 | void **data, int func); |
| 39 | int (*event)(struct gpio_event_input_devs *input_devs, |
| 40 | struct gpio_event_info *info, |
| 41 | void **data, unsigned int dev, unsigned int type, |
| 42 | unsigned int code, int value); |
| 43 | bool no_suspend; |
| 44 | }; |
| 45 | |
| 46 | struct gpio_event_platform_data { |
| 47 | const char *name; |
| 48 | struct gpio_event_info **info; |
| 49 | size_t info_count; |
| 50 | int (*power)(const struct gpio_event_platform_data *pdata, bool on); |
| 51 | const char *names[]; |
| 52 | |
| 53 | }; |
| 54 | |
| 55 | #define GPIO_EVENT_DEV_NAME "gpio-event" |
| 56 | |
| 57 | |
| 58 | enum gpio_event_matrix_flags { |
| 59 | |
| 60 | GPIOKPF_ACTIVE_HIGH = 1U << 0, |
| 61 | GPIOKPF_DEBOUNCE = 1U << 1, |
| 62 | GPIOKPF_REMOVE_SOME_PHANTOM_KEYS = 1U << 2, |
| 63 | GPIOKPF_REMOVE_PHANTOM_KEYS = GPIOKPF_REMOVE_SOME_PHANTOM_KEYS | |
| 64 | GPIOKPF_DEBOUNCE, |
| 65 | GPIOKPF_DRIVE_INACTIVE = 1U << 3, |
| 66 | GPIOKPF_LEVEL_TRIGGERED_IRQ = 1U << 4, |
| 67 | GPIOKPF_PRINT_UNMAPPED_KEYS = 1U << 16, |
| 68 | GPIOKPF_PRINT_MAPPED_KEYS = 1U << 17, |
| 69 | GPIOKPF_PRINT_PHANTOM_KEYS = 1U << 18, |
| 70 | }; |
| 71 | |
| 72 | #define MATRIX_CODE_BITS (10) |
| 73 | #define MATRIX_KEY_MASK ((1U << MATRIX_CODE_BITS) - 1) |
| 74 | #define MATRIX_KEY(dev, code) \ |
| 75 | (((dev) << MATRIX_CODE_BITS) | (code & MATRIX_KEY_MASK)) |
| 76 | |
| 77 | extern int gpio_event_matrix_func(struct gpio_event_input_devs *input_devs, |
| 78 | struct gpio_event_info *info, void **data, int func); |
| 79 | struct gpio_event_matrix_info { |
| 80 | |
| 81 | struct gpio_event_info info; |
| 82 | |
| 83 | const unsigned short *keymap; |
| 84 | unsigned int *input_gpios; |
| 85 | unsigned int *output_gpios; |
| 86 | unsigned int ninputs; |
| 87 | unsigned int noutputs; |
| 88 | |
| 89 | struct timespec settle_time; |
| 90 | |
| 91 | struct timespec debounce_delay; |
| 92 | struct timespec poll_time; |
| 93 | unsigned flags; |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | enum gpio_event_direct_flags { |
| 98 | GPIOEDF_ACTIVE_HIGH = 1U << 0, |
| 99 | GPIOEDF_PRINT_KEYS = 1U << 8, |
| 100 | GPIOEDF_PRINT_KEY_DEBOUNCE = 1U << 9, |
| 101 | GPIOEDF_PRINT_KEY_UNSTABLE = 1U << 10, |
| 102 | }; |
| 103 | |
| 104 | struct gpio_event_direct_entry { |
| 105 | uint32_t gpio:16; |
| 106 | uint32_t code:10; |
| 107 | uint32_t dev:6; |
| 108 | bool not_wakeup_src; |
| 109 | }; |
| 110 | |
| 111 | extern int gpio_event_input_func(struct gpio_event_input_devs *input_devs, |
| 112 | struct gpio_event_info *info, void **data, int func); |
| 113 | struct gpio_event_input_info { |
| 114 | |
| 115 | struct gpio_event_info info; |
| 116 | ktime_t debounce_time; |
| 117 | ktime_t poll_time; |
| 118 | uint16_t flags; |
| 119 | uint16_t type; |
| 120 | const struct gpio_event_direct_entry *keymap; |
| 121 | size_t keymap_size; |
| 122 | void (*setup_input_gpio)(void); |
| 123 | void (*set_qty_irq)(uint8_t); |
| 124 | void (*clear_hw_reset)(void); |
| 125 | }; |
| 126 | |
| 127 | extern int gpio_event_output_func(struct gpio_event_input_devs *input_devs, |
| 128 | struct gpio_event_info *info, void **data, int func); |
| 129 | extern int gpio_event_output_event(struct gpio_event_input_devs *input_devs, |
| 130 | struct gpio_event_info *info, void **data, |
| 131 | unsigned int dev, unsigned int type, |
| 132 | unsigned int code, int value); |
| 133 | struct gpio_event_output_info { |
| 134 | |
| 135 | struct gpio_event_info info; |
| 136 | uint16_t flags; |
| 137 | uint16_t type; |
| 138 | const struct gpio_event_direct_entry *keymap; |
| 139 | size_t keymap_size; |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | |
| 144 | enum gpio_event_axis_flags { |
| 145 | GPIOEAF_PRINT_UNKNOWN_DIRECTION = 1U << 16, |
| 146 | GPIOEAF_PRINT_RAW = 1U << 17, |
| 147 | GPIOEAF_PRINT_EVENT = 1U << 18, |
| 148 | }; |
| 149 | |
| 150 | extern int gpio_event_axis_func(struct gpio_event_input_devs *input_devs, |
| 151 | struct gpio_event_info *info, void **data, int func); |
| 152 | struct gpio_event_axis_info { |
| 153 | |
| 154 | struct gpio_event_info info; |
| 155 | uint8_t count; |
| 156 | uint8_t dev; |
| 157 | uint8_t type; |
| 158 | uint16_t code; |
| 159 | uint16_t decoded_size; |
| 160 | uint16_t (*map)(struct gpio_event_axis_info *info, uint16_t in); |
| 161 | uint32_t *gpio; |
| 162 | uint32_t flags; |
| 163 | }; |
| 164 | #define gpio_axis_2bit_gray_map gpio_axis_4bit_gray_map |
| 165 | #define gpio_axis_3bit_gray_map gpio_axis_4bit_gray_map |
| 166 | uint16_t gpio_axis_4bit_gray_map( |
| 167 | struct gpio_event_axis_info *info, uint16_t in); |
| 168 | uint16_t gpio_axis_5bit_singletrack_map( |
| 169 | struct gpio_event_axis_info *info, uint16_t in); |
| 170 | |
| 171 | extern int gpio_event_switch_func(struct gpio_event_input_devs *input_devs, |
| 172 | struct gpio_event_info *info, void **data, int func); |
| 173 | struct gpio_event_switch_info { |
| 174 | |
| 175 | struct gpio_event_info info; |
| 176 | ktime_t debounce_time; |
| 177 | ktime_t poll_time; |
| 178 | uint16_t flags; |
| 179 | uint16_t type; |
| 180 | const struct gpio_event_direct_entry *keymap; |
| 181 | size_t keymap_size; |
| 182 | void (*setup_switch_gpio)(void); |
| 183 | void (*set_qty_irq)(uint8_t); |
| 184 | }; |
| 185 | #endif |