27 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/input.h>
32 #include <linux/kernel.h>
36 #include <linux/errno.h>
37 #include <linux/slab.h>
42 #undef NEW_BOARD_LEARNING_MODE
44 static void omap_kp_tasklet(
unsigned long);
45 static void omap_kp_timer(
unsigned long);
47 static unsigned char keypad_state[8];
49 static int kp_enable = 1;
50 static int kp_cur_group = -1;
65 static unsigned int *row_gpios;
66 static unsigned int *col_gpios;
68 #ifdef CONFIG_ARCH_OMAP2
73 for (col = 0; col < omap_kp->
cols; col++)
82 for (row = 0; row < omap_kp->
rows; row++) {
89 #define set_col_gpio_val(x, y) do {} while (0)
90 #define get_row_gpio_val(x) 0
98 tasklet_schedule(&kp_tasklet);
103 static void omap_kp_timer(
unsigned long data)
105 tasklet_schedule(&kp_tasklet);
108 static void omap_kp_scan_keypad(
struct omap_kp *omap_kp,
unsigned char *
state)
117 for (col = 0; col < omap_kp->
cols; col++) {
130 static void omap_kp_tasklet(
unsigned long data)
132 struct omap_kp *omap_kp_data = (
struct omap_kp *) data;
133 unsigned short *keycodes = omap_kp_data->
input->keycode;
134 unsigned int row_shift = get_count_order(omap_kp_data->
cols);
140 omap_kp_scan_keypad(omap_kp_data, new_state);
143 for (col = 0; col < omap_kp_data->
cols; col++) {
144 changed = new_state[col] ^ keypad_state[col];
145 key_down |= new_state[col];
149 for (row = 0; row < omap_kp_data->
rows; row++) {
151 if (!(changed & (1 << row)))
153 #ifdef NEW_BOARD_LEARNING_MODE
155 row, (new_state[col] & (1 << row)) ?
156 "pressed" :
"released");
161 "omap-keypad: Spurious key event %d-%d\n",
173 input_report_key(omap_kp_data->
input, key & ~GROUP_MASK,
174 new_state[col] & (1 << row));
178 input_sync(omap_kp_data->
input);
179 memcpy(keypad_state, new_state,
sizeof(keypad_state));
198 return sprintf(buf,
"%u\n", kp_enable);
207 if (
sscanf(buf,
"%u", &state) != 1)
210 if ((state != 1) && (state != 0))
214 if (state != kp_enable) {
243 #define omap_kp_suspend NULL
244 #define omap_kp_resume NULL
249 struct omap_kp *omap_kp;
250 struct input_dev *input_dev;
252 int i, col_idx, row_idx,
ret;
253 unsigned int row_shift, keycodemax;
260 row_shift = get_count_order(pdata->
cols);
261 keycodemax = pdata->
rows << row_shift;
263 omap_kp = kzalloc(
sizeof(
struct omap_kp) +
264 keycodemax *
sizeof(
unsigned short),
GFP_KERNEL);
265 input_dev = input_allocate_device();
266 if (!omap_kp || !input_dev) {
268 input_free_device(input_dev);
272 platform_set_drvdata(pdev, omap_kp);
274 omap_kp->
input = input_dev;
296 tasklet_enable(&kp_tasklet);
297 kp_tasklet.data = (
unsigned long) omap_kp;
304 input_dev->name =
"omap-keypad";
305 input_dev->phys =
"omap-keypad/input0";
306 input_dev->dev.parent = &pdev->
dev;
309 input_dev->id.vendor = 0x0001;
310 input_dev->id.product = 0x0001;
311 input_dev->id.version = 0x0100;
318 omap_kp->keymap, input_dev);
322 ret = input_register_device(omap_kp->input);
332 omap_kp_scan_keypad(omap_kp, keypad_state);
334 if (omap_kp->irq >= 0) {
335 if (
request_irq(omap_kp->irq, omap_kp_interrupt, 0,
336 "omap-keypad", omap_kp) < 0)
344 input_unregister_device(omap_kp->input);
349 for (i = row_idx - 1; i >= 0; i--)
351 for (i = col_idx - 1; i >= 0; i--)
355 input_free_device(input_dev);
362 struct omap_kp *omap_kp = platform_get_drvdata(pdev);
365 tasklet_disable(&kp_tasklet);
373 input_unregister_device(omap_kp->
input);
381 .probe = omap_kp_probe,
386 .name =
"omap-keypad",