omap-keypad.c (b74b953b998bcc2db91b694446f3a2619ec32de6) omap-keypad.c (da1f026b532ce944d74461497dc6d8c16456466e)
1/*
2 * linux/drivers/input/keyboard/omap-keypad.c
3 *
4 * OMAP Keypad Driver
5 *
6 * Copyright (C) 2003 Nokia Corporation
7 * Written by Timo Teräs <ext-timo.teras@nokia.com>
8 *

--- 51 unchanged lines hidden (view full) ---

60 unsigned int rows;
61 unsigned int cols;
62 unsigned long delay;
63 unsigned int debounce;
64};
65
66static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
67
1/*
2 * linux/drivers/input/keyboard/omap-keypad.c
3 *
4 * OMAP Keypad Driver
5 *
6 * Copyright (C) 2003 Nokia Corporation
7 * Written by Timo Teräs <ext-timo.teras@nokia.com>
8 *

--- 51 unchanged lines hidden (view full) ---

60 unsigned int rows;
61 unsigned int cols;
62 unsigned long delay;
63 unsigned int debounce;
64};
65
66static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
67
68static int *keymap;
69static unsigned int *row_gpios;
70static unsigned int *col_gpios;
71
72#ifdef CONFIG_ARCH_OMAP2
73static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value)
74{
75 int col;
76

--- 80 unchanged lines hidden (view full) ---

157 state[col] = ~omap_readw(OMAP1_MPUIO_BASE +
158 OMAP_MPUIO_KBR_LATCH) & 0xff;
159 }
160 omap_writew(0x00, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC);
161 udelay(2);
162 }
163}
164
68static unsigned int *row_gpios;
69static unsigned int *col_gpios;
70
71#ifdef CONFIG_ARCH_OMAP2
72static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value)
73{
74 int col;
75

--- 80 unchanged lines hidden (view full) ---

156 state[col] = ~omap_readw(OMAP1_MPUIO_BASE +
157 OMAP_MPUIO_KBR_LATCH) & 0xff;
158 }
159 omap_writew(0x00, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC);
160 udelay(2);
161 }
162}
163
165static inline int omap_kp_find_key(int col, int row)
166{
167 int i, key;
168
169 key = KEY(col, row, 0);
170 for (i = 0; keymap[i] != 0; i++)
171 if ((keymap[i] & 0xff000000) == key)
172 return keymap[i] & 0x00ffffff;
173 return -1;
174}
175
176static void omap_kp_tasklet(unsigned long data)
177{
178 struct omap_kp *omap_kp_data = (struct omap_kp *) data;
164static void omap_kp_tasklet(unsigned long data)
165{
166 struct omap_kp *omap_kp_data = (struct omap_kp *) data;
167 unsigned short *keycodes = omap_kp_data->input->keycode;
168 unsigned int row_shift = get_count_order(omap_kp_data->cols);
179 unsigned char new_state[8], changed, key_down = 0;
180 int col, row;
181 int spurious = 0;
182
183 /* check for any changes */
184 omap_kp_scan_keypad(omap_kp_data, new_state);
185
186 /* check for changes and print those */

--- 7 unchanged lines hidden (view full) ---

194 int key;
195 if (!(changed & (1 << row)))
196 continue;
197#ifdef NEW_BOARD_LEARNING_MODE
198 printk(KERN_INFO "omap-keypad: key %d-%d %s\n", col,
199 row, (new_state[col] & (1 << row)) ?
200 "pressed" : "released");
201#else
169 unsigned char new_state[8], changed, key_down = 0;
170 int col, row;
171 int spurious = 0;
172
173 /* check for any changes */
174 omap_kp_scan_keypad(omap_kp_data, new_state);
175
176 /* check for changes and print those */

--- 7 unchanged lines hidden (view full) ---

184 int key;
185 if (!(changed & (1 << row)))
186 continue;
187#ifdef NEW_BOARD_LEARNING_MODE
188 printk(KERN_INFO "omap-keypad: key %d-%d %s\n", col,
189 row, (new_state[col] & (1 << row)) ?
190 "pressed" : "released");
191#else
202 key = omap_kp_find_key(col, row);
192 key = keycodes[MATRIX_SCAN_CODE(row, col, row_shift)];
203 if (key < 0) {
204 printk(KERN_WARNING
205 "omap-keypad: Spurious key event %d-%d\n",
206 col, row);
207 /* We scan again after a couple of seconds */
208 spurious = 1;
209 continue;
210 }

--- 82 unchanged lines hidden (view full) ---

293#endif
294
295static int __devinit omap_kp_probe(struct platform_device *pdev)
296{
297 struct omap_kp *omap_kp;
298 struct input_dev *input_dev;
299 struct omap_kp_platform_data *pdata = pdev->dev.platform_data;
300 int i, col_idx, row_idx, irq_idx, ret;
193 if (key < 0) {
194 printk(KERN_WARNING
195 "omap-keypad: Spurious key event %d-%d\n",
196 col, row);
197 /* We scan again after a couple of seconds */
198 spurious = 1;
199 continue;
200 }

--- 82 unchanged lines hidden (view full) ---

283#endif
284
285static int __devinit omap_kp_probe(struct platform_device *pdev)
286{
287 struct omap_kp *omap_kp;
288 struct input_dev *input_dev;
289 struct omap_kp_platform_data *pdata = pdev->dev.platform_data;
290 int i, col_idx, row_idx, irq_idx, ret;
291 unsigned int row_shift, keycodemax;
301
292
302 if (!pdata->rows || !pdata->cols || !pdata->keymap) {
303 printk(KERN_ERR "No rows, cols or keymap from pdata\n");
293 if (!pdata->rows || !pdata->cols || !pdata->keymap_data) {
294 printk(KERN_ERR "No rows, cols or keymap_data from pdata\n");
304 return -EINVAL;
305 }
306
295 return -EINVAL;
296 }
297
307 omap_kp = kzalloc(sizeof(struct omap_kp), GFP_KERNEL);
298 row_shift = get_count_order(pdata->cols);
299 keycodemax = pdata->rows << row_shift;
300
301 omap_kp = kzalloc(sizeof(struct omap_kp) +
302 keycodemax * sizeof(unsigned short), GFP_KERNEL);
308 input_dev = input_allocate_device();
309 if (!omap_kp || !input_dev) {
310 kfree(omap_kp);
311 input_free_device(input_dev);
312 return -ENOMEM;
313 }
314
315 platform_set_drvdata(pdev, omap_kp);
316
317 omap_kp->input = input_dev;
318
319 /* Disable the interrupt for the MPUIO keyboard */
320 if (!cpu_is_omap24xx())
321 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
322
303 input_dev = input_allocate_device();
304 if (!omap_kp || !input_dev) {
305 kfree(omap_kp);
306 input_free_device(input_dev);
307 return -ENOMEM;
308 }
309
310 platform_set_drvdata(pdev, omap_kp);
311
312 omap_kp->input = input_dev;
313
314 /* Disable the interrupt for the MPUIO keyboard */
315 if (!cpu_is_omap24xx())
316 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
317
323 keymap = pdata->keymap;
318 input_dev->keycode = &omap_kp[1];
319 input_dev->keycodesize = sizeof(unsigned short);
320 input_dev->keycodemax = keycodemax;
324
325 if (pdata->rep)
326 __set_bit(EV_REP, input_dev->evbit);
327
328 if (pdata->delay)
329 omap_kp->delay = pdata->delay;
330
331 if (pdata->row_gpios && pdata->col_gpios) {

--- 37 unchanged lines hidden (view full) ---

369 kp_tasklet.data = (unsigned long) omap_kp;
370
371 ret = device_create_file(&pdev->dev, &dev_attr_enable);
372 if (ret < 0)
373 goto err2;
374
375 /* setup input device */
376 __set_bit(EV_KEY, input_dev->evbit);
321
322 if (pdata->rep)
323 __set_bit(EV_REP, input_dev->evbit);
324
325 if (pdata->delay)
326 omap_kp->delay = pdata->delay;
327
328 if (pdata->row_gpios && pdata->col_gpios) {

--- 37 unchanged lines hidden (view full) ---

366 kp_tasklet.data = (unsigned long) omap_kp;
367
368 ret = device_create_file(&pdev->dev, &dev_attr_enable);
369 if (ret < 0)
370 goto err2;
371
372 /* setup input device */
373 __set_bit(EV_KEY, input_dev->evbit);
377 for (i = 0; keymap[i] != 0; i++)
378 __set_bit(keymap[i] & KEY_MAX, input_dev->keybit);
374 matrix_keypad_build_keymap(pdata->keymap_data, row_shift,
375 input_dev->keycode, input_dev->keybit);
379 input_dev->name = "omap-keypad";
380 input_dev->phys = "omap-keypad/input0";
381 input_dev->dev.parent = &pdev->dev;
382
383 input_dev->id.bustype = BUS_HOST;
384 input_dev->id.vendor = 0x0001;
385 input_dev->id.product = 0x0001;
386 input_dev->id.version = 0x0100;

--- 24 unchanged lines hidden (view full) ---

411 IRQF_TRIGGER_FALLING,
412 "omap-keypad", omap_kp) < 0)
413 goto err5;
414 }
415 }
416 return 0;
417err5:
418 for (i = irq_idx - 1; i >=0; i--)
376 input_dev->name = "omap-keypad";
377 input_dev->phys = "omap-keypad/input0";
378 input_dev->dev.parent = &pdev->dev;
379
380 input_dev->id.bustype = BUS_HOST;
381 input_dev->id.vendor = 0x0001;
382 input_dev->id.product = 0x0001;
383 input_dev->id.version = 0x0100;

--- 24 unchanged lines hidden (view full) ---

408 IRQF_TRIGGER_FALLING,
409 "omap-keypad", omap_kp) < 0)
410 goto err5;
411 }
412 }
413 return 0;
414err5:
415 for (i = irq_idx - 1; i >=0; i--)
419 free_irq(row_gpios[i], 0);
416 free_irq(row_gpios[i], NULL);
420err4:
421 input_unregister_device(omap_kp->input);
422 input_dev = NULL;
423err3:
424 device_remove_file(&pdev->dev, &dev_attr_enable);
425err2:
426 for (i = row_idx - 1; i >=0; i--)
427 gpio_free(row_gpios[i]);

--- 14 unchanged lines hidden (view full) ---

442 /* disable keypad interrupt handling */
443 tasklet_disable(&kp_tasklet);
444 if (cpu_is_omap24xx()) {
445 int i;
446 for (i = 0; i < omap_kp->cols; i++)
447 gpio_free(col_gpios[i]);
448 for (i = 0; i < omap_kp->rows; i++) {
449 gpio_free(row_gpios[i]);
417err4:
418 input_unregister_device(omap_kp->input);
419 input_dev = NULL;
420err3:
421 device_remove_file(&pdev->dev, &dev_attr_enable);
422err2:
423 for (i = row_idx - 1; i >=0; i--)
424 gpio_free(row_gpios[i]);

--- 14 unchanged lines hidden (view full) ---

439 /* disable keypad interrupt handling */
440 tasklet_disable(&kp_tasklet);
441 if (cpu_is_omap24xx()) {
442 int i;
443 for (i = 0; i < omap_kp->cols; i++)
444 gpio_free(col_gpios[i]);
445 for (i = 0; i < omap_kp->rows; i++) {
446 gpio_free(row_gpios[i]);
450 free_irq(gpio_to_irq(row_gpios[i]), 0);
447 free_irq(gpio_to_irq(row_gpios[i]), NULL);
451 }
452 } else {
453 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
448 }
449 } else {
450 omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
454 free_irq(omap_kp->irq, 0);
451 free_irq(omap_kp->irq, NULL);
455 }
456
457 del_timer_sync(&omap_kp->timer);
458 tasklet_kill(&kp_tasklet);
459
460 /* unregister everything */
461 input_unregister_device(omap_kp->input);
462

--- 34 unchanged lines hidden ---
452 }
453
454 del_timer_sync(&omap_kp->timer);
455 tasklet_kill(&kp_tasklet);
456
457 /* unregister everything */
458 input_unregister_device(omap_kp->input);
459

--- 34 unchanged lines hidden ---