aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-pxa/tosa.c43
-rw-r--r--drivers/input/keyboard/Kconfig21
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/tosakbd.c415
-rw-r--r--include/asm-arm/arch-pxa/tosa.h30
5 files changed, 510 insertions, 0 deletions
diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c
index 240fd042083d..e7e0f52d6083 100644
--- a/arch/arm/mach-pxa/tosa.c
+++ b/arch/arm/mach-pxa/tosa.c
@@ -21,6 +21,8 @@
21#include <linux/mmc/host.h> 21#include <linux/mmc/host.h>
22#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/gpio_keys.h>
25#include <linux/input.h>
24 26
25#include <asm/setup.h> 27#include <asm/setup.h>
26#include <asm/memory.h> 28#include <asm/memory.h>
@@ -253,6 +255,46 @@ static struct platform_device tosakbd_device = {
253 .id = -1, 255 .id = -1,
254}; 256};
255 257
258static struct gpio_keys_button tosa_gpio_keys[] = {
259 {
260 .type = EV_PWR,
261 .code = KEY_SUSPEND,
262 .gpio = TOSA_GPIO_ON_KEY,
263 .desc = "On key",
264 .wakeup = 1,
265 .active_low = 1,
266 },
267 {
268 .type = EV_KEY,
269 .code = TOSA_KEY_RECORD,
270 .gpio = TOSA_GPIO_RECORD_BTN,
271 .desc = "Record Button",
272 .wakeup = 1,
273 .active_low = 1,
274 },
275 {
276 .type = EV_KEY,
277 .code = TOSA_KEY_SYNC,
278 .gpio = TOSA_GPIO_SYNC,
279 .desc = "Sync Button",
280 .wakeup = 1,
281 .active_low = 1,
282 },
283};
284
285static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
286 .buttons = tosa_gpio_keys,
287 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
288};
289
290static struct platform_device tosa_gpio_keys_device = {
291 .name = "gpio-keys",
292 .id = -1,
293 .dev = {
294 .platform_data = &tosa_gpio_keys_platform_data,
295 },
296};
297
256/* 298/*
257 * Tosa LEDs 299 * Tosa LEDs
258 */ 300 */
@@ -265,6 +307,7 @@ static struct platform_device *devices[] __initdata = {
265 &tosascoop_device, 307 &tosascoop_device,
266 &tosascoop_jc_device, 308 &tosascoop_jc_device,
267 &tosakbd_device, 309 &tosakbd_device,
310 &tosa_gpio_keys_device,
268 &tosaled_device, 311 &tosaled_device,
269}; 312};
270 313
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 086d58c0ccbe..0c327621bd86 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -154,6 +154,27 @@ config KEYBOARD_SPITZ
154 To compile this driver as a module, choose M here: the 154 To compile this driver as a module, choose M here: the
155 module will be called spitzkbd. 155 module will be called spitzkbd.
156 156
157config KEYBOARD_TOSA
158 tristate "Tosa keyboard"
159 depends on MACH_TOSA
160 default y
161 help
162 Say Y here to enable the keyboard on the Sharp Zaurus SL-6000x (Tosa)
163
164 To compile this driver as a module, choose M here: the
165 module will be called tosakbd.
166
167config KEYBOARD_TOSA_USE_EXT_KEYCODES
168 bool "Tosa keyboard: use extended keycodes"
169 depends on KEYBOARD_TOSA
170 default n
171 help
172 Say Y here to enable the tosa keyboard driver to generate extended
173 (>= 127) keycodes. Be aware, that they can't be correctly interpreted
174 by either console keyboard driver or by Kdrive keybd driver.
175
176 Say Y only if you know, what you are doing!
177
157config KEYBOARD_AMIGA 178config KEYBOARD_AMIGA
158 tristate "Amiga keyboard" 179 tristate "Amiga keyboard"
159 depends on AMIGA 180 depends on AMIGA
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index e97455fdcc83..6caa065e27ae 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
15obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 15obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
16obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o 16obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
17obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o 17obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
18obj-$(CONFIG_KEYBOARD_TOSA) += tosakbd.o
18obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 19obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
19obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 20obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
20obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 21obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
diff --git a/drivers/input/keyboard/tosakbd.c b/drivers/input/keyboard/tosakbd.c
new file mode 100644
index 000000000000..3884d1e3f070
--- /dev/null
+++ b/drivers/input/keyboard/tosakbd.c
@@ -0,0 +1,415 @@
1/*
2 * Keyboard driver for Sharp Tosa models (SL-6000x)
3 *
4 * Copyright (c) 2005 Dirk Opfer
5 * Copyright (c) 2007 Dmitry Baryshkov
6 *
7 * Based on xtkbd.c/locomkbd.c/corgikbd.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/input.h>
19#include <linux/delay.h>
20#include <linux/interrupt.h>
21
22#include <asm/arch/gpio.h>
23#include <asm/arch/tosa.h>
24
25#define KB_ROWMASK(r) (1 << (r))
26#define SCANCODE(r, c) (((r)<<4) + (c) + 1)
27#define NR_SCANCODES SCANCODE(TOSA_KEY_SENSE_NUM - 1, TOSA_KEY_STROBE_NUM - 1) + 1
28
29#define SCAN_INTERVAL (HZ/10)
30
31#define KB_DISCHARGE_DELAY 10
32#define KB_ACTIVATE_DELAY 10
33
34static unsigned int tosakbd_keycode[NR_SCANCODES] = {
350,
360, KEY_W, 0, 0, 0, KEY_K, KEY_BACKSPACE, KEY_P,
370, 0, 0, 0, 0, 0, 0, 0,
38KEY_Q, KEY_E, KEY_T, KEY_Y, 0, KEY_O, KEY_I, KEY_COMMA,
390, 0, 0, 0, 0, 0, 0, 0,
40KEY_A, KEY_D, KEY_G, KEY_U, 0, KEY_L, KEY_ENTER, KEY_DOT,
410, 0, 0, 0, 0, 0, 0, 0,
42KEY_Z, KEY_C, KEY_V, KEY_J, TOSA_KEY_ADDRESSBOOK, TOSA_KEY_CANCEL, TOSA_KEY_CENTER, TOSA_KEY_OK,
43KEY_LEFTSHIFT, 0, 0, 0, 0, 0, 0, 0,
44KEY_S, KEY_R, KEY_B, KEY_N, TOSA_KEY_CALENDAR, TOSA_KEY_HOMEPAGE, KEY_LEFTCTRL, TOSA_KEY_LIGHT,
450, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0,
46KEY_TAB, KEY_SLASH, KEY_H, KEY_M, TOSA_KEY_MENU, 0, KEY_UP, 0,
470, 0, TOSA_KEY_FN, 0, 0, 0, 0, 0,
48KEY_X, KEY_F, KEY_SPACE, KEY_APOSTROPHE, TOSA_KEY_MAIL, KEY_LEFT, KEY_DOWN, KEY_RIGHT,
490, 0, 0,
50};
51
52struct tosakbd {
53 unsigned int keycode[ARRAY_SIZE(tosakbd_keycode)];
54 struct input_dev *input;
55
56 spinlock_t lock; /* protect kbd scanning */
57 struct timer_list timer;
58};
59
60
61/* Helper functions for reading the keyboard matrix
62 * Note: We should really be using pxa_gpio_mode to alter GPDR but it
63 * requires a function call per GPIO bit which is excessive
64 * when we need to access 12 bits at once, multiple times.
65 * These functions must be called within local_irq_save()/local_irq_restore()
66 * or similar.
67 */
68#define GET_ROWS_STATUS(c) ((GPLR2 & TOSA_GPIO_ALL_SENSE_BIT) >> TOSA_GPIO_ALL_SENSE_RSHIFT)
69
70static inline void tosakbd_discharge_all(void)
71{
72 /* STROBE All HiZ */
73 GPCR1 = TOSA_GPIO_HIGH_STROBE_BIT;
74 GPDR1 &= ~TOSA_GPIO_HIGH_STROBE_BIT;
75 GPCR2 = TOSA_GPIO_LOW_STROBE_BIT;
76 GPDR2 &= ~TOSA_GPIO_LOW_STROBE_BIT;
77}
78
79static inline void tosakbd_activate_all(void)
80{
81 /* STROBE ALL -> High */
82 GPSR1 = TOSA_GPIO_HIGH_STROBE_BIT;
83 GPDR1 |= TOSA_GPIO_HIGH_STROBE_BIT;
84 GPSR2 = TOSA_GPIO_LOW_STROBE_BIT;
85 GPDR2 |= TOSA_GPIO_LOW_STROBE_BIT;
86
87 udelay(KB_DISCHARGE_DELAY);
88
89 /* STATE CLEAR */
90 GEDR2 |= TOSA_GPIO_ALL_SENSE_BIT;
91}
92
93static inline void tosakbd_activate_col(int col)
94{
95 if (col <= 5) {
96 /* STROBE col -> High, not col -> HiZ */
97 GPSR1 = TOSA_GPIO_STROBE_BIT(col);
98 GPDR1 = (GPDR1 & ~TOSA_GPIO_HIGH_STROBE_BIT) | TOSA_GPIO_STROBE_BIT(col);
99 } else {
100 /* STROBE col -> High, not col -> HiZ */
101 GPSR2 = TOSA_GPIO_STROBE_BIT(col);
102 GPDR2 = (GPDR2 & ~TOSA_GPIO_LOW_STROBE_BIT) | TOSA_GPIO_STROBE_BIT(col);
103 }
104}
105
106static inline void tosakbd_reset_col(int col)
107{
108 if (col <= 5) {
109 /* STROBE col -> Low */
110 GPCR1 = TOSA_GPIO_STROBE_BIT(col);
111 /* STROBE col -> out, not col -> HiZ */
112 GPDR1 = (GPDR1 & ~TOSA_GPIO_HIGH_STROBE_BIT) | TOSA_GPIO_STROBE_BIT(col);
113 } else {
114 /* STROBE col -> Low */
115 GPCR2 = TOSA_GPIO_STROBE_BIT(col);
116 /* STROBE col -> out, not col -> HiZ */
117 GPDR2 = (GPDR2 & ~TOSA_GPIO_LOW_STROBE_BIT) | TOSA_GPIO_STROBE_BIT(col);
118 }
119}
120/*
121 * The tosa keyboard only generates interrupts when a key is pressed.
122 * So when a key is pressed, we enable a timer. This timer scans the
123 * keyboard, and this is how we detect when the key is released.
124 */
125
126/* Scan the hardware keyboard and push any changes up through the input layer */
127static void tosakbd_scankeyboard(struct platform_device *dev)
128{
129 struct tosakbd *tosakbd = platform_get_drvdata(dev);
130 unsigned int row, col, rowd;
131 unsigned long flags;
132 unsigned int num_pressed = 0;
133
134 spin_lock_irqsave(&tosakbd->lock, flags);
135
136 for (col = 0; col < TOSA_KEY_STROBE_NUM; col++) {
137 /*
138 * Discharge the output driver capacitatance
139 * in the keyboard matrix. (Yes it is significant..)
140 */
141 tosakbd_discharge_all();
142 udelay(KB_DISCHARGE_DELAY);
143
144 tosakbd_activate_col(col);
145 udelay(KB_ACTIVATE_DELAY);
146
147 rowd = GET_ROWS_STATUS(col);
148
149 for (row = 0; row < TOSA_KEY_SENSE_NUM; row++) {
150 unsigned int scancode, pressed;
151 scancode = SCANCODE(row, col);
152 pressed = rowd & KB_ROWMASK(row);
153
154 if (pressed && !tosakbd->keycode[scancode])
155 dev_warn(&dev->dev,
156 "unhandled scancode: 0x%02x\n",
157 scancode);
158
159 input_report_key(tosakbd->input,
160 tosakbd->keycode[scancode],
161 pressed);
162 if (pressed)
163 num_pressed++;
164 }
165
166 tosakbd_reset_col(col);
167 }
168
169 tosakbd_activate_all();
170
171 input_sync(tosakbd->input);
172
173 /* if any keys are pressed, enable the timer */
174 if (num_pressed)
175 mod_timer(&tosakbd->timer, jiffies + SCAN_INTERVAL);
176
177 spin_unlock_irqrestore(&tosakbd->lock, flags);
178}
179
180/*
181 * tosa keyboard interrupt handler.
182 */
183static irqreturn_t tosakbd_interrupt(int irq, void *__dev)
184{
185 struct platform_device *dev = __dev;
186 struct tosakbd *tosakbd = platform_get_drvdata(dev);
187
188 if (!timer_pending(&tosakbd->timer)) {
189 /** wait chattering delay **/
190 udelay(20);
191 tosakbd_scankeyboard(dev);
192 }
193
194 return IRQ_HANDLED;
195}
196
197/*
198 * tosa timer checking for released keys
199 */
200static void tosakbd_timer_callback(unsigned long __dev)
201{
202 struct platform_device *dev = (struct platform_device *)__dev;
203 tosakbd_scankeyboard(dev);
204}
205
206#ifdef CONFIG_PM
207static int tosakbd_suspend(struct platform_device *dev, pm_message_t state)
208{
209 struct tosakbd *tosakbd = platform_get_drvdata(dev);
210
211 del_timer_sync(&tosakbd->timer);
212
213 return 0;
214}
215
216static int tosakbd_resume(struct platform_device *dev)
217{
218 tosakbd_scankeyboard(dev);
219
220 return 0;
221}
222#else
223#define tosakbd_suspend NULL
224#define tosakbd_resume NULL
225#endif
226
227static int __devinit tosakbd_probe(struct platform_device *pdev) {
228
229 int i;
230 struct tosakbd *tosakbd;
231 struct input_dev *input_dev;
232 int error;
233
234 tosakbd = kzalloc(sizeof(struct tosakbd), GFP_KERNEL);
235 if (!tosakbd)
236 return -ENOMEM;
237
238 input_dev = input_allocate_device();
239 if (!input_dev) {
240 kfree(tosakbd);
241 return -ENOMEM;
242 }
243
244 platform_set_drvdata(pdev, tosakbd);
245
246 spin_lock_init(&tosakbd->lock);
247
248 /* Init Keyboard rescan timer */
249 init_timer(&tosakbd->timer);
250 tosakbd->timer.function = tosakbd_timer_callback;
251 tosakbd->timer.data = (unsigned long) pdev;
252
253 tosakbd->input = input_dev;
254
255 input_set_drvdata(input_dev, tosakbd);
256 input_dev->name = "Tosa Keyboard";
257 input_dev->phys = "tosakbd/input0";
258 input_dev->dev.parent = &pdev->dev;
259
260 input_dev->id.bustype = BUS_HOST;
261 input_dev->id.vendor = 0x0001;
262 input_dev->id.product = 0x0001;
263 input_dev->id.version = 0x0100;
264
265 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
266 input_dev->keycode = tosakbd->keycode;
267 input_dev->keycodesize = sizeof(unsigned int);
268 input_dev->keycodemax = ARRAY_SIZE(tosakbd_keycode);
269
270 memcpy(tosakbd->keycode, tosakbd_keycode, sizeof(tosakbd_keycode));
271
272 for (i = 0; i < ARRAY_SIZE(tosakbd_keycode); i++)
273 __set_bit(tosakbd->keycode[i], input_dev->keybit);
274 clear_bit(0, input_dev->keybit);
275
276 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
277 for (i = 0; i < TOSA_KEY_SENSE_NUM; i++) {
278 int gpio = TOSA_GPIO_KEY_SENSE(i);
279 int irq;
280 error = gpio_request(gpio, "tosakbd");
281 if (error < 0) {
282 printk(KERN_ERR "tosakbd: failed to request GPIO %d, "
283 " error %d\n", gpio, error);
284 goto fail;
285 }
286
287 error = gpio_direction_input(TOSA_GPIO_KEY_SENSE(i));
288 if (error < 0) {
289 printk(KERN_ERR "tosakbd: failed to configure input"
290 " direction for GPIO %d, error %d\n",
291 gpio, error);
292 gpio_free(gpio);
293 goto fail;
294 }
295
296 irq = gpio_to_irq(gpio);
297 if (irq < 0) {
298 error = irq;
299 printk(KERN_ERR "gpio-keys: Unable to get irq number"
300 " for GPIO %d, error %d\n",
301 gpio, error);
302 gpio_free(gpio);
303 goto fail;
304 }
305
306 error = request_irq(irq, tosakbd_interrupt,
307 IRQF_DISABLED | IRQF_TRIGGER_RISING,
308 "tosakbd", pdev);
309
310 if (error) {
311 printk("tosakbd: Can't get IRQ: %d: error %d!\n",
312 irq, error);
313 gpio_free(gpio);
314 goto fail;
315 }
316 }
317
318 /* Set Strobe lines as outputs - set high */
319 for (i = 0; i < TOSA_KEY_STROBE_NUM; i++) {
320 int gpio = TOSA_GPIO_KEY_STROBE(i);
321 error = gpio_request(gpio, "tosakbd");
322 if (error < 0) {
323 printk(KERN_ERR "tosakbd: failed to request GPIO %d, "
324 " error %d\n", gpio, error);
325 goto fail2;
326 }
327
328 error = gpio_direction_output(gpio, 1);
329 if (error < 0) {
330 printk(KERN_ERR "tosakbd: failed to configure input"
331 " direction for GPIO %d, error %d\n",
332 gpio, error);
333 gpio_free(gpio);
334 goto fail;
335 }
336
337 }
338
339 error = input_register_device(input_dev);
340 if (error) {
341 printk(KERN_ERR "tosakbd: Unable to register input device, "
342 "error: %d\n", error);
343 goto fail;
344 }
345
346 printk(KERN_INFO "input: Tosa Keyboard Registered\n");
347
348 return 0;
349
350fail2:
351 while (--i >= 0)
352 gpio_free(TOSA_GPIO_KEY_STROBE(i));
353
354 i = TOSA_KEY_SENSE_NUM;
355fail:
356 while (--i >= 0) {
357 free_irq(gpio_to_irq(TOSA_GPIO_KEY_SENSE(i)), pdev);
358 gpio_free(TOSA_GPIO_KEY_SENSE(i));
359 }
360
361 platform_set_drvdata(pdev, NULL);
362 input_free_device(input_dev);
363 kfree(tosakbd);
364
365 return error;
366}
367
368static int __devexit tosakbd_remove(struct platform_device *dev) {
369
370 int i;
371 struct tosakbd *tosakbd = platform_get_drvdata(dev);
372
373 for (i = 0; i < TOSA_KEY_STROBE_NUM; i++)
374 gpio_free(TOSA_GPIO_KEY_STROBE(i));
375
376 for (i = 0; i < TOSA_KEY_SENSE_NUM; i++) {
377 free_irq(gpio_to_irq(TOSA_GPIO_KEY_SENSE(i)), dev);
378 gpio_free(TOSA_GPIO_KEY_SENSE(i));
379 }
380
381 del_timer_sync(&tosakbd->timer);
382
383 input_unregister_device(tosakbd->input);
384
385 kfree(tosakbd);
386
387 return 0;
388}
389
390static struct platform_driver tosakbd_driver = {
391 .probe = tosakbd_probe,
392 .remove = __devexit_p(tosakbd_remove),
393 .suspend = tosakbd_suspend,
394 .resume = tosakbd_resume,
395 .driver = {
396 .name = "tosa-keyboard",
397 },
398};
399
400static int __devinit tosakbd_init(void)
401{
402 return platform_driver_register(&tosakbd_driver);
403}
404
405static void __exit tosakbd_exit(void)
406{
407 platform_driver_unregister(&tosakbd_driver);
408}
409
410module_init(tosakbd_init);
411module_exit(tosakbd_exit);
412
413MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>");
414MODULE_DESCRIPTION("Tosa Keyboard Driver");
415MODULE_LICENSE("GPL v2");
diff --git a/include/asm-arm/arch-pxa/tosa.h b/include/asm-arm/arch-pxa/tosa.h
index c3364a2c4758..c05e4faf85a6 100644
--- a/include/asm-arm/arch-pxa/tosa.h
+++ b/include/asm-arm/arch-pxa/tosa.h
@@ -163,4 +163,34 @@
163 163
164extern struct platform_device tosascoop_jc_device; 164extern struct platform_device tosascoop_jc_device;
165extern struct platform_device tosascoop_device; 165extern struct platform_device tosascoop_device;
166
167#define TOSA_KEY_SYNC KEY_102ND /* ??? */
168
169
170#ifndef CONFIG_KEYBOARD_TOSA_USE_EXT_KEYCODES
171#define TOSA_KEY_RECORD KEY_YEN
172#define TOSA_KEY_ADDRESSBOOK KEY_KATAKANA
173#define TOSA_KEY_CANCEL KEY_ESC
174#define TOSA_KEY_CENTER KEY_HIRAGANA
175#define TOSA_KEY_OK KEY_HENKAN
176#define TOSA_KEY_CALENDAR KEY_KATAKANAHIRAGANA
177#define TOSA_KEY_HOMEPAGE KEY_HANGEUL
178#define TOSA_KEY_LIGHT KEY_MUHENKAN
179#define TOSA_KEY_MENU KEY_HANJA
180#define TOSA_KEY_FN KEY_RIGHTALT
181#define TOSA_KEY_MAIL KEY_ZENKAKUHANKAKU
182#else
183#define TOSA_KEY_RECORD KEY_RECORD
184#define TOSA_KEY_ADDRESSBOOK KEY_ADDRESSBOOK
185#define TOSA_KEY_CANCEL KEY_CANCEL
186#define TOSA_KEY_CENTER KEY_SELECT /* ??? */
187#define TOSA_KEY_OK KEY_OK
188#define TOSA_KEY_CALENDAR KEY_CALENDAR
189#define TOSA_KEY_HOMEPAGE KEY_HOMEPAGE
190#define TOSA_KEY_LIGHT KEY_KBDILLUMTOGGLE
191#define TOSA_KEY_MENU KEY_MENU
192#define TOSA_KEY_FN KEY_FN
193#define TOSA_KEY_MAIL KEY_MAIL
194#endif
195
166#endif /* _ASM_ARCH_TOSA_H_ */ 196#endif /* _ASM_ARCH_TOSA_H_ */