blob: fd8e15ea9149a72c489dc934a2cf26e7166a4ce0 [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>
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040029
30MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>");
31MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver");
Al Viro839cd312008-05-21 06:32:11 +010032MODULE_LICENSE("GPL v2");
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040033
34static unsigned short jornada_std_keymap[128] = { /* ROW */
35 0, KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, /* #1 */
36 KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_MUTE, /* -> */
37 0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, /* #2 */
38 KEY_0, KEY_MINUS, KEY_EQUAL,0, 0, 0, /* -> */
39 0, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, /* #3 */
40 KEY_P, KEY_BACKSLASH, KEY_BACKSPACE, 0, 0, 0, /* -> */
41 0, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, /* #4 */
42 KEY_SEMICOLON, KEY_LEFTBRACE, KEY_RIGHTBRACE, 0, 0, 0, /* -> */
43 0, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, KEY_COMMA, /* #5 */
44 KEY_DOT, KEY_KPMINUS, KEY_APOSTROPHE, KEY_ENTER, 0, 0,0, /* -> */
45 0, KEY_TAB, 0, KEY_LEFTSHIFT, 0, KEY_APOSTROPHE, 0, 0, 0, 0, /* #6 */
46 KEY_UP, 0, KEY_RIGHTSHIFT, 0, 0, 0,0, 0, 0, 0, 0, KEY_LEFTALT, KEY_GRAVE, /* -> */
47 0, 0, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0,0, KEY_KPASTERISK, /* -> */
48 KEY_LEFTCTRL, 0, KEY_SPACE, 0, 0, 0, KEY_SLASH, KEY_DELETE, 0, 0, /* -> */
49 0, 0, 0, KEY_POWER, /* -> */
50};
51
52struct jornadakbd {
53 unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)];
54 struct input_dev *input;
55};
56
57static irqreturn_t jornada720_kbd_interrupt(int irq, void *dev_id)
58{
59 struct platform_device *pdev = dev_id;
60 struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040061 struct input_dev *input = jornadakbd->input;
62 u8 count, kbd_data, scan_code;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040063
64 /* startup ssp with spinlock */
65 jornada_ssp_start();
66
67 if (jornada_ssp_inout(GETSCANKEYCODE) != TXDUMMY) {
Dmitry Torokhov99ff4d32016-08-19 10:03:59 -070068 dev_dbg(&pdev->dev,
69 "GetKeycode command failed with ETIMEDOUT, flushed bus\n");
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040070 } else {
71 /* How many keycodes are waiting for us? */
72 count = jornada_ssp_byte(TXDUMMY);
73
74 /* Lets drag them out one at a time */
75 while (count--) {
76 /* Exchange TxDummy for location (keymap[kbddata]) */
77 kbd_data = jornada_ssp_byte(TXDUMMY);
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040078 scan_code = kbd_data & 0x7f;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040079
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040080 input_event(input, EV_MSC, MSC_SCAN, scan_code);
81 input_report_key(input, jornadakbd->keymap[scan_code],
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040082 !(kbd_data & 0x80));
Dmitry Torokhov72f9df42007-10-11 00:48:48 -040083 input_sync(input);
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040084 }
85 }
86
87 /* release spinlock and turn off ssp */
88 jornada_ssp_end();
89
90 return IRQ_HANDLED;
91};
92
Bill Pemberton5298cc42012-11-23 21:38:25 -080093static int jornada720_kbd_probe(struct platform_device *pdev)
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -040094{
95 struct jornadakbd *jornadakbd;
96 struct input_dev *input_dev;
Russell King0f631d82016-08-19 09:41:47 -070097 int i, err, irq;
98
99 irq = platform_get_irq(pdev, 0);
100 if (irq <= 0)
101 return irq < 0 ? irq : -EINVAL;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400102
Russell Kinga8a7bdc2016-08-19 09:40:58 -0700103 jornadakbd = devm_kzalloc(&pdev->dev, sizeof(*jornadakbd), GFP_KERNEL);
104 input_dev = devm_input_allocate_device(&pdev->dev);
105 if (!jornadakbd || !input_dev)
106 return -ENOMEM;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400107
108 platform_set_drvdata(pdev, jornadakbd);
109
110 memcpy(jornadakbd->keymap, jornada_std_keymap,
111 sizeof(jornada_std_keymap));
112 jornadakbd->input = input_dev;
113
114 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
115 input_dev->name = "HP Jornada 720 keyboard";
116 input_dev->phys = "jornadakbd/input0";
117 input_dev->keycode = jornadakbd->keymap;
118 input_dev->keycodesize = sizeof(unsigned short);
119 input_dev->keycodemax = ARRAY_SIZE(jornada_std_keymap);
120 input_dev->id.bustype = BUS_HOST;
121 input_dev->dev.parent = &pdev->dev;
122
123 for (i = 0; i < ARRAY_SIZE(jornadakbd->keymap); i++)
124 __set_bit(jornadakbd->keymap[i], input_dev->keybit);
125 __clear_bit(KEY_RESERVED, input_dev->keybit);
126
Dmitry Torokhov72f9df42007-10-11 00:48:48 -0400127 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
128
Russell King0f631d82016-08-19 09:41:47 -0700129 err = devm_request_irq(&pdev->dev, irq, jornada720_kbd_interrupt,
Russell Kinga8a7bdc2016-08-19 09:40:58 -0700130 IRQF_TRIGGER_FALLING, "jornadakbd", pdev);
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400131 if (err) {
Russell King0f631d82016-08-19 09:41:47 -0700132 dev_err(&pdev->dev, "unable to grab IRQ%d: %d\n", irq, err);
Russell Kinga8a7bdc2016-08-19 09:40:58 -0700133 return err;
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400134 }
135
Russell Kinga8a7bdc2016-08-19 09:40:58 -0700136 return input_register_device(jornadakbd->input);
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400137};
138
Kay Sieversd7b52472008-04-18 00:24:42 -0400139/* work with hotplug and coldplug */
140MODULE_ALIAS("platform:jornada720_kbd");
141
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400142static struct platform_driver jornada720_kbd_driver = {
143 .driver = {
144 .name = "jornada720_kbd",
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400145 },
146 .probe = jornada720_kbd_probe,
Kristoffer Ericsonb0a4e1a2007-09-26 00:02:49 -0400147};
JJ Ding5146c842011-11-29 11:08:39 -0800148module_platform_driver(jornada720_kbd_driver);