i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / input / keyboard / jornada720_kbd.c
blobeeafc30b207ba123293fcf17c9d840277408a297
1 /*
2 * drivers/input/keyboard/jornada720_kbd.c
4 * HP Jornada 720 keyboard platform driver
6 * Copyright (C) 2006/2007 Kristoffer Ericson <Kristoffer.Ericson@Gmail.com>
8 * Copyright (C) 2006 jornada 720 kbd driver by
9 Filip Zyzniewsk <Filip.Zyzniewski@tefnet.plX
10 * based on (C) 2004 jornada 720 kbd driver by
11 Alex Lange <chicken@handhelds.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #include <linux/device.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <linux/init.h>
22 #include <linux/input.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/slab.h>
28 #include <mach/jornada720.h>
29 #include <mach/hardware.h>
31 MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>");
32 MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver");
33 MODULE_LICENSE("GPL v2");
35 static unsigned short jornada_std_keymap[128] = { /* ROW */
36 0, KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, /* #1 */
37 KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, /* -> */
38 0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, /* #2 */
39 KEY_0, KEY_MINUS, KEY_EQUAL,0, 0, 0, /* -> */
40 0, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, /* #3 */
41 KEY_P, KEY_BACKSLASH, KEY_BACKSPACE, 0, 0, 0, /* -> */
42 0, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, /* #4 */
43 KEY_SEMICOLON, KEY_LEFTBRACE, KEY_RIGHTBRACE, 0, 0, 0, /* -> */
44 0, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, KEY_COMMA, /* #5 */
45 KEY_DOT, KEY_KPMINUS, KEY_APOSTROPHE, KEY_ENTER, 0, 0,0, /* -> */
46 0, KEY_TAB, 0, KEY_LEFTSHIFT, 0, KEY_APOSTROPHE, 0, 0, 0, 0, /* #6 */
47 KEY_UP, 0, KEY_RIGHTSHIFT, 0, 0, 0,0, 0, 0, 0, 0, KEY_LEFTALT, KEY_GRAVE, /* -> */
48 0, 0, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0,0, KEY_KPASTERISK, /* -> */
49 KEY_LEFTCTRL, 0, KEY_SPACE, 0, 0, 0, KEY_SLASH, KEY_DELETE, 0, 0, /* -> */
50 0, 0, 0, KEY_POWER, /* -> */
53 struct jornadakbd {
54 unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)];
55 struct input_dev *input;
58 static irqreturn_t jornada720_kbd_interrupt(int irq, void *dev_id)
60 struct platform_device *pdev = dev_id;
61 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
62 struct input_dev *input = jornadakbd->input;
63 u8 count, kbd_data, scan_code;
65 /* startup ssp with spinlock */
66 jornada_ssp_start();
68 if (jornada_ssp_inout(GETSCANKEYCODE) != TXDUMMY) {
69 printk(KERN_DEBUG
70 "jornada720_kbd: "
71 "GetKeycode command failed with ETIMEDOUT, "
72 "flushed bus\n");
73 } else {
74 /* How many keycodes are waiting for us? */
75 count = jornada_ssp_byte(TXDUMMY);
77 /* Lets drag them out one at a time */
78 while (count--) {
79 /* Exchange TxDummy for location (keymap[kbddata]) */
80 kbd_data = jornada_ssp_byte(TXDUMMY);
81 scan_code = kbd_data & 0x7f;
83 input_event(input, EV_MSC, MSC_SCAN, scan_code);
84 input_report_key(input, jornadakbd->keymap[scan_code],
85 !(kbd_data & 0x80));
86 input_sync(input);
90 /* release spinlock and turn off ssp */
91 jornada_ssp_end();
93 return IRQ_HANDLED;
96 static int __devinit jornada720_kbd_probe(struct platform_device *pdev)
98 struct jornadakbd *jornadakbd;
99 struct input_dev *input_dev;
100 int i, err;
102 jornadakbd = kzalloc(sizeof(struct jornadakbd), GFP_KERNEL);
103 input_dev = input_allocate_device();
104 if (!jornadakbd || !input_dev) {
105 err = -ENOMEM;
106 goto fail1;
109 platform_set_drvdata(pdev, jornadakbd);
111 memcpy(jornadakbd->keymap, jornada_std_keymap,
112 sizeof(jornada_std_keymap));
113 jornadakbd->input = input_dev;
115 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
116 input_dev->name = "HP Jornada 720 keyboard";
117 input_dev->phys = "jornadakbd/input0";
118 input_dev->keycode = jornadakbd->keymap;
119 input_dev->keycodesize = sizeof(unsigned short);
120 input_dev->keycodemax = ARRAY_SIZE(jornada_std_keymap);
121 input_dev->id.bustype = BUS_HOST;
122 input_dev->dev.parent = &pdev->dev;
124 for (i = 0; i < ARRAY_SIZE(jornadakbd->keymap); i++)
125 __set_bit(jornadakbd->keymap[i], input_dev->keybit);
126 __clear_bit(KEY_RESERVED, input_dev->keybit);
128 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
130 err = request_irq(IRQ_GPIO0,
131 jornada720_kbd_interrupt,
132 IRQF_TRIGGER_FALLING,
133 "jornadakbd", pdev);
134 if (err) {
135 printk(KERN_INFO "jornadakbd720_kbd: Unable to grab IRQ\n");
136 goto fail1;
139 err = input_register_device(jornadakbd->input);
140 if (err)
141 goto fail2;
143 return 0;
145 fail2: /* IRQ, DEVICE, MEMORY */
146 free_irq(IRQ_GPIO0, pdev);
147 fail1: /* DEVICE, MEMORY */
148 platform_set_drvdata(pdev, NULL);
149 input_free_device(input_dev);
150 kfree(jornadakbd);
151 return err;
154 static int __devexit jornada720_kbd_remove(struct platform_device *pdev)
156 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
158 free_irq(IRQ_GPIO0, pdev);
159 platform_set_drvdata(pdev, NULL);
160 input_unregister_device(jornadakbd->input);
161 kfree(jornadakbd);
163 return 0;
166 /* work with hotplug and coldplug */
167 MODULE_ALIAS("platform:jornada720_kbd");
169 static struct platform_driver jornada720_kbd_driver = {
170 .driver = {
171 .name = "jornada720_kbd",
172 .owner = THIS_MODULE,
174 .probe = jornada720_kbd_probe,
175 .remove = __devexit_p(jornada720_kbd_remove),
177 module_platform_driver(jornada720_kbd_driver);