blob: 421d9c55b0e896ed3f8d144f1544a4a98ae095a1 [file] [log] [blame]
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -04001/*
2 * drivers/input/keyboard/jornada720_kbd.c
3 *
4 * HP Jornada 720 keyboard platform driver
5 *
6 * Copyright (C) 2006/2007 Kristoffer Ericson <Kristoffer.Ericson@Gmail.com>
7 *
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>
12 *
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.
16 *
17 */
18#include <linux/device.h>
19#include <linux/errno.h>
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040020#include <linux/interrupt.h>
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040021#include <linux/input.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040026
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/jornada720.h>
28#include <mach/hardware.h>
Rob Herring3638dd22012-02-23 14:28:36 +010029#include <mach/irqs.h>
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040030
31MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>");
32MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver");
Al Viro839cd312008-05-21 06:32:11 +010033MODULE_LICENSE("GPL v2");
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040034
35static 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, /* -> */
51};
52
53struct jornadakbd {
54 unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)];
55 struct input_dev *input;
56};
57
58static irqreturn_t jornada720_kbd_interrupt(int irq, void *dev_id)
59{
60 struct platform_device *pdev = dev_id;
61 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040062 struct input_dev *input = jornadakbd->input;
63 u8 count, kbd_data, scan_code;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040064
65 /* startup ssp with spinlock */
66 jornada_ssp_start();
67
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);
76
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);
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040081 scan_code = kbd_data & 0x7f;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040082
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040083 input_event(input, EV_MSC, MSC_SCAN, scan_code);
84 input_report_key(input, jornadakbd->keymap[scan_code],
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040085 !(kbd_data & 0x80));
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040086 input_sync(input);
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040087 }
88 }
89
90 /* release spinlock and turn off ssp */
91 jornada_ssp_end();
92
93 return IRQ_HANDLED;
94};
95
Bill Pemberton5298cc42012-11-23 21:38:25 -080096static int jornada720_kbd_probe(struct platform_device *pdev)
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040097{
98 struct jornadakbd *jornadakbd;
99 struct input_dev *input_dev;
100 int i, err;
101
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;
107 }
108
109 platform_set_drvdata(pdev, jornadakbd);
110
111 memcpy(jornadakbd->keymap, jornada_std_keymap,
112 sizeof(jornada_std_keymap));
113 jornadakbd->input = input_dev;
114
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;
123
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);
127
Dmitry Torokhov72f9df42007-10-11 00:48:48 -0400128 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
129
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400130 err = request_irq(IRQ_GPIO0,
131 jornada720_kbd_interrupt,
Yong Zhangec4665c2011-09-07 14:04:16 -0700132 IRQF_TRIGGER_FALLING,
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400133 "jornadakbd", pdev);
134 if (err) {
135 printk(KERN_INFO "jornadakbd720_kbd: Unable to grab IRQ\n");
136 goto fail1;
137 }
138
139 err = input_register_device(jornadakbd->input);
140 if (err)
141 goto fail2;
142
143 return 0;
144
145 fail2: /* IRQ, DEVICE, MEMORY */
146 free_irq(IRQ_GPIO0, pdev);
147 fail1: /* DEVICE, MEMORY */
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400148 input_free_device(input_dev);
149 kfree(jornadakbd);
150 return err;
151};
152
Bill Pembertone2619cf2012-11-23 21:50:47 -0800153static int jornada720_kbd_remove(struct platform_device *pdev)
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400154{
155 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
156
157 free_irq(IRQ_GPIO0, pdev);
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400158 input_unregister_device(jornadakbd->input);
159 kfree(jornadakbd);
160
161 return 0;
162}
163
Kay Sieversd7b52472008-04-18 00:24:42 -0400164/* work with hotplug and coldplug */
165MODULE_ALIAS("platform:jornada720_kbd");
166
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400167static struct platform_driver jornada720_kbd_driver = {
168 .driver = {
169 .name = "jornada720_kbd",
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400170 },
171 .probe = jornada720_kbd_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800172 .remove = jornada720_kbd_remove,
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400173};
JJ Ding5146c842011-11-29 11:08:39 -0800174module_platform_driver(jornada720_kbd_driver);