rcu: Maintain special bits at bottom of ->dynticks counter
[linux/fpc-iii.git] / drivers / input / keyboard / jornada720_kbd.c
blob1277c39f9482b55dce9ed9eecaeb5deeeebc7c47
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/input.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
27 #include <mach/jornada720.h>
29 MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>");
30 MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver");
31 MODULE_LICENSE("GPL v2");
33 static unsigned short jornada_std_keymap[128] = { /* ROW */
34 0, KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, /* #1 */
35 KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, /* -> */
36 0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, /* #2 */
37 KEY_0, KEY_MINUS, KEY_EQUAL,0, 0, 0, /* -> */
38 0, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, /* #3 */
39 KEY_P, KEY_BACKSLASH, KEY_BACKSPACE, 0, 0, 0, /* -> */
40 0, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, /* #4 */
41 KEY_SEMICOLON, KEY_LEFTBRACE, KEY_RIGHTBRACE, 0, 0, 0, /* -> */
42 0, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, KEY_COMMA, /* #5 */
43 KEY_DOT, KEY_KPMINUS, KEY_APOSTROPHE, KEY_ENTER, 0, 0,0, /* -> */
44 0, KEY_TAB, 0, KEY_LEFTSHIFT, 0, KEY_APOSTROPHE, 0, 0, 0, 0, /* #6 */
45 KEY_UP, 0, KEY_RIGHTSHIFT, 0, 0, 0,0, 0, 0, 0, 0, KEY_LEFTALT, KEY_GRAVE, /* -> */
46 0, 0, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0,0, KEY_KPASTERISK, /* -> */
47 KEY_LEFTCTRL, 0, KEY_SPACE, 0, 0, 0, KEY_SLASH, KEY_DELETE, 0, 0, /* -> */
48 0, 0, 0, KEY_POWER, /* -> */
51 struct jornadakbd {
52 unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)];
53 struct input_dev *input;
56 static irqreturn_t jornada720_kbd_interrupt(int irq, void *dev_id)
58 struct platform_device *pdev = dev_id;
59 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
60 struct input_dev *input = jornadakbd->input;
61 u8 count, kbd_data, scan_code;
63 /* startup ssp with spinlock */
64 jornada_ssp_start();
66 if (jornada_ssp_inout(GETSCANKEYCODE) != TXDUMMY) {
67 dev_dbg(&pdev->dev,
68 "GetKeycode command failed with ETIMEDOUT, flushed bus\n");
69 } else {
70 /* How many keycodes are waiting for us? */
71 count = jornada_ssp_byte(TXDUMMY);
73 /* Lets drag them out one at a time */
74 while (count--) {
75 /* Exchange TxDummy for location (keymap[kbddata]) */
76 kbd_data = jornada_ssp_byte(TXDUMMY);
77 scan_code = kbd_data & 0x7f;
79 input_event(input, EV_MSC, MSC_SCAN, scan_code);
80 input_report_key(input, jornadakbd->keymap[scan_code],
81 !(kbd_data & 0x80));
82 input_sync(input);
86 /* release spinlock and turn off ssp */
87 jornada_ssp_end();
89 return IRQ_HANDLED;
92 static int jornada720_kbd_probe(struct platform_device *pdev)
94 struct jornadakbd *jornadakbd;
95 struct input_dev *input_dev;
96 int i, err, irq;
98 irq = platform_get_irq(pdev, 0);
99 if (irq <= 0)
100 return irq < 0 ? irq : -EINVAL;
102 jornadakbd = devm_kzalloc(&pdev->dev, sizeof(*jornadakbd), GFP_KERNEL);
103 input_dev = devm_input_allocate_device(&pdev->dev);
104 if (!jornadakbd || !input_dev)
105 return -ENOMEM;
107 platform_set_drvdata(pdev, jornadakbd);
109 memcpy(jornadakbd->keymap, jornada_std_keymap,
110 sizeof(jornada_std_keymap));
111 jornadakbd->input = input_dev;
113 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
114 input_dev->name = "HP Jornada 720 keyboard";
115 input_dev->phys = "jornadakbd/input0";
116 input_dev->keycode = jornadakbd->keymap;
117 input_dev->keycodesize = sizeof(unsigned short);
118 input_dev->keycodemax = ARRAY_SIZE(jornada_std_keymap);
119 input_dev->id.bustype = BUS_HOST;
120 input_dev->dev.parent = &pdev->dev;
122 for (i = 0; i < ARRAY_SIZE(jornadakbd->keymap); i++)
123 __set_bit(jornadakbd->keymap[i], input_dev->keybit);
124 __clear_bit(KEY_RESERVED, input_dev->keybit);
126 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
128 err = devm_request_irq(&pdev->dev, irq, jornada720_kbd_interrupt,
129 IRQF_TRIGGER_FALLING, "jornadakbd", pdev);
130 if (err) {
131 dev_err(&pdev->dev, "unable to grab IRQ%d: %d\n", irq, err);
132 return err;
135 return input_register_device(jornadakbd->input);
138 /* work with hotplug and coldplug */
139 MODULE_ALIAS("platform:jornada720_kbd");
141 static struct platform_driver jornada720_kbd_driver = {
142 .driver = {
143 .name = "jornada720_kbd",
145 .probe = jornada720_kbd_probe,
147 module_platform_driver(jornada720_kbd_driver);