Arve Hjønnevåg | c3fffcb | 2008-10-15 18:23:47 -0700 | [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 | struct gpio_event_input_devs { |
| 22 | int count; |
| 23 | struct input_dev *dev[]; |
| 24 | }; |
| 25 | enum { |
| 26 | GPIO_EVENT_FUNC_UNINIT = 0x0, |
| 27 | GPIO_EVENT_FUNC_INIT = 0x1, |
| 28 | GPIO_EVENT_FUNC_SUSPEND = 0x2, |
| 29 | GPIO_EVENT_FUNC_RESUME = 0x3, |
| 30 | }; |
| 31 | struct gpio_event_info { |
| 32 | int (*func)(struct gpio_event_input_devs *input_devs, |
| 33 | struct gpio_event_info *info, |
| 34 | void **data, int func); |
| 35 | int (*event)(struct gpio_event_input_devs *input_devs, |
| 36 | struct gpio_event_info *info, |
| 37 | void **data, unsigned int dev, unsigned int type, |
| 38 | unsigned int code, int value); /* out events */ |
| 39 | bool no_suspend; |
Flemmard | c36b867 | 2013-10-23 17:43:54 +0200 | [diff] [blame] | 40 | #ifdef CONFIG_OPTICALJOYSTICK_CRUCIAL |
| 41 | bool oj_btn; |
| 42 | #endif |
Arve Hjønnevåg | c3fffcb | 2008-10-15 18:23:47 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct gpio_event_platform_data { |
| 46 | const char *name; |
| 47 | struct gpio_event_info **info; |
| 48 | size_t info_count; |
| 49 | int (*power)(const struct gpio_event_platform_data *pdata, bool on); |
| 50 | const char *names[]; /* If name is NULL, names contain a NULL */ |
| 51 | /* terminated list of input devices to create */ |
| 52 | }; |
| 53 | |
| 54 | #define GPIO_EVENT_DEV_NAME "gpio-event" |
| 55 | |
| 56 | /* Key matrix */ |
| 57 | |
| 58 | enum gpio_event_matrix_flags { |
| 59 | /* unset: drive active output low, set: drive active output high */ |
| 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 | /* initialize to gpio_event_matrix_func */ |
| 81 | struct gpio_event_info info; |
| 82 | /* size must be ninputs * noutputs */ |
| 83 | const unsigned short *keymap; |
| 84 | unsigned int *input_gpios; |
| 85 | unsigned int *output_gpios; |
| 86 | unsigned int ninputs; |
| 87 | unsigned int noutputs; |
| 88 | /* time to wait before reading inputs after driving each output */ |
| 89 | ktime_t settle_time; |
| 90 | /* time to wait before scanning the keypad a second time */ |
| 91 | ktime_t debounce_delay; |
| 92 | ktime_t poll_time; |
| 93 | unsigned flags; |
| 94 | }; |
| 95 | |
| 96 | /* Directly connected inputs and outputs */ |
| 97 | |
| 98 | enum gpio_event_direct_flags { |
| 99 | GPIOEDF_ACTIVE_HIGH = 1U << 0, |
| 100 | /* GPIOEDF_USE_DOWN_IRQ = 1U << 1, */ |
| 101 | /* GPIOEDF_USE_IRQ = (1U << 2) | GPIOIDF_USE_DOWN_IRQ, */ |
| 102 | GPIOEDF_PRINT_KEYS = 1U << 8, |
| 103 | GPIOEDF_PRINT_KEY_DEBOUNCE = 1U << 9, |
| 104 | GPIOEDF_PRINT_KEY_UNSTABLE = 1U << 10, |
| 105 | }; |
| 106 | |
| 107 | struct gpio_event_direct_entry { |
| 108 | uint32_t gpio:16; |
| 109 | uint32_t code:10; |
| 110 | uint32_t dev:6; |
Flemmard | 3d07cb9 | 2013-10-23 18:02:07 +0200 | [diff] [blame] | 111 | bool not_wakeup_src; |
Arve Hjønnevåg | c3fffcb | 2008-10-15 18:23:47 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* inputs */ |
| 115 | extern int gpio_event_input_func(struct gpio_event_input_devs *input_devs, |
| 116 | struct gpio_event_info *info, void **data, int func); |
| 117 | struct gpio_event_input_info { |
| 118 | /* initialize to gpio_event_input_func */ |
| 119 | struct gpio_event_info info; |
| 120 | ktime_t debounce_time; |
| 121 | ktime_t poll_time; |
| 122 | uint16_t flags; |
| 123 | uint16_t type; |
| 124 | const struct gpio_event_direct_entry *keymap; |
| 125 | size_t keymap_size; |
| 126 | }; |
| 127 | |
| 128 | /* outputs */ |
| 129 | extern int gpio_event_output_func(struct gpio_event_input_devs *input_devs, |
| 130 | struct gpio_event_info *info, void **data, int func); |
| 131 | extern int gpio_event_output_event(struct gpio_event_input_devs *input_devs, |
| 132 | struct gpio_event_info *info, void **data, |
| 133 | unsigned int dev, unsigned int type, |
| 134 | unsigned int code, int value); |
| 135 | struct gpio_event_output_info { |
| 136 | /* initialize to gpio_event_output_func and gpio_event_output_event */ |
| 137 | struct gpio_event_info info; |
| 138 | uint16_t flags; |
| 139 | uint16_t type; |
| 140 | const struct gpio_event_direct_entry *keymap; |
| 141 | size_t keymap_size; |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | /* axes */ |
| 146 | |
| 147 | enum gpio_event_axis_flags { |
| 148 | GPIOEAF_PRINT_UNKNOWN_DIRECTION = 1U << 16, |
| 149 | GPIOEAF_PRINT_RAW = 1U << 17, |
| 150 | GPIOEAF_PRINT_EVENT = 1U << 18, |
| 151 | }; |
| 152 | |
| 153 | extern int gpio_event_axis_func(struct gpio_event_input_devs *input_devs, |
| 154 | struct gpio_event_info *info, void **data, int func); |
| 155 | struct gpio_event_axis_info { |
| 156 | /* initialize to gpio_event_axis_func */ |
| 157 | struct gpio_event_info info; |
| 158 | uint8_t count; /* number of gpios for this axis */ |
| 159 | uint8_t dev; /* device index when using multiple input devices */ |
| 160 | uint8_t type; /* EV_REL or EV_ABS */ |
| 161 | uint16_t code; |
| 162 | uint16_t decoded_size; |
| 163 | uint16_t (*map)(struct gpio_event_axis_info *info, uint16_t in); |
| 164 | uint32_t *gpio; |
| 165 | uint32_t flags; |
| 166 | }; |
| 167 | #define gpio_axis_2bit_gray_map gpio_axis_4bit_gray_map |
| 168 | #define gpio_axis_3bit_gray_map gpio_axis_4bit_gray_map |
| 169 | uint16_t gpio_axis_4bit_gray_map( |
| 170 | struct gpio_event_axis_info *info, uint16_t in); |
| 171 | uint16_t gpio_axis_5bit_singletrack_map( |
| 172 | struct gpio_event_axis_info *info, uint16_t in); |
| 173 | |
Flemmard | 3d07cb9 | 2013-10-23 18:02:07 +0200 | [diff] [blame] | 174 | /* switchs */ |
| 175 | extern int gpio_event_switch_func(struct gpio_event_input_devs *input_devs, |
| 176 | struct gpio_event_info *info, void **data, int func); |
| 177 | struct gpio_event_switch_info { |
| 178 | /* initialize to gpio_event_switch_func */ |
| 179 | struct gpio_event_info info; |
| 180 | ktime_t debounce_time; |
| 181 | ktime_t poll_time; |
| 182 | uint16_t flags; |
| 183 | uint16_t type; |
| 184 | const struct gpio_event_direct_entry *keymap; |
| 185 | size_t keymap_size; |
| 186 | void (*setup_switch_gpio)(void); |
| 187 | void (*set_qty_irq)(uint8_t); |
| 188 | }; |
Arve Hjønnevåg | c3fffcb | 2008-10-15 18:23:47 -0700 | [diff] [blame] | 189 | #endif |