xref: /linux/drivers/input/keyboard/jornada720_kbd.c (revision f5bb3a5e9dcdb8435471562b6cada89525cf4df1)
1 /*
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>
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 
27 #include <asm/arch/jornada720.h>
28 #include <asm/hardware.h>
29 
30 MODULE_AUTHOR("Kristoffer Ericson <Kristoffer.Ericson@gmail.com>");
31 MODULE_DESCRIPTION("HP Jornada 710/720/728 keyboard driver");
32 MODULE_LICENSE("GPLv2");
33 
34 static 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 
52 struct jornadakbd {
53 	unsigned short keymap[ARRAY_SIZE(jornada_std_keymap)];
54 	struct input_dev *input;
55 };
56 
57 static 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);
61 	struct input_dev *input = jornadakbd->input;
62 	u8 count, kbd_data, scan_code;
63 
64 	/* startup ssp with spinlock */
65 	jornada_ssp_start();
66 
67 	if (jornada_ssp_inout(GETSCANKEYCODE) != TXDUMMY) {
68 		printk(KERN_DEBUG
69 			"jornada720_kbd: "
70 			"GetKeycode command failed with ETIMEDOUT, "
71 			"flushed bus\n");
72 	} else {
73 		/* How many keycodes are waiting for us? */
74 		count = jornada_ssp_byte(TXDUMMY);
75 
76 		/* Lets drag them out one at a time */
77 		while (count--) {
78 			/* Exchange TxDummy for location (keymap[kbddata]) */
79 			kbd_data = jornada_ssp_byte(TXDUMMY);
80 			scan_code = kbd_data & 0x7f;
81 
82 			input_event(input, EV_MSC, MSC_SCAN, scan_code);
83 			input_report_key(input, jornadakbd->keymap[scan_code],
84 					 !(kbd_data & 0x80));
85 			input_sync(input);
86 		}
87 	}
88 
89 	/* release spinlock and turn off ssp */
90 	jornada_ssp_end();
91 
92 	return IRQ_HANDLED;
93 };
94 
95 static int __devinit jornada720_kbd_probe(struct platform_device *pdev)
96 {
97 	struct jornadakbd *jornadakbd;
98 	struct input_dev *input_dev;
99 	int i, err;
100 
101 	jornadakbd = kzalloc(sizeof(struct jornadakbd), GFP_KERNEL);
102 	input_dev = input_allocate_device();
103 	if (!jornadakbd || !input_dev) {
104 		err = -ENOMEM;
105 		goto fail1;
106 	}
107 
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 
127 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
128 
129 	err = request_irq(IRQ_GPIO0,
130 			  jornada720_kbd_interrupt,
131 			  IRQF_DISABLED | IRQF_TRIGGER_FALLING,
132 			  "jornadakbd", pdev);
133 	if (err) {
134 		printk(KERN_INFO "jornadakbd720_kbd: Unable to grab IRQ\n");
135 		goto fail1;
136 	}
137 
138 	err = input_register_device(jornadakbd->input);
139 	if (err)
140 		goto fail2;
141 
142 	return 0;
143 
144  fail2:	/* IRQ, DEVICE, MEMORY */
145 	free_irq(IRQ_GPIO0, pdev);
146  fail1:	/* DEVICE, MEMORY */
147 	platform_set_drvdata(pdev, NULL);
148 	input_free_device(input_dev);
149 	kfree(jornadakbd);
150 	return err;
151 };
152 
153 static int __devexit jornada720_kbd_remove(struct platform_device *pdev)
154 {
155 	struct jornadakbd *jornadakbd = platform_get_drvdata(pdev);
156 
157 	free_irq(IRQ_GPIO0, pdev);
158 	platform_set_drvdata(pdev, NULL);
159 	input_unregister_device(jornadakbd->input);
160 	kfree(jornadakbd);
161 
162 	return 0;
163 }
164 
165 static struct platform_driver jornada720_kbd_driver = {
166 	.driver  = {
167 		.name    = "jornada720_kbd",
168 	 },
169 	.probe   = jornada720_kbd_probe,
170 	.remove  = __devexit_p(jornada720_kbd_remove),
171 };
172 
173 static int __init jornada720_kbd_init(void)
174 {
175 	return platform_driver_register(&jornada720_kbd_driver);
176 }
177 
178 static void __exit jornada720_kbd_exit(void)
179 {
180 	platform_driver_unregister(&jornada720_kbd_driver);
181 }
182 
183 module_init(jornada720_kbd_init);
184 module_exit(jornada720_kbd_exit);
185