diff options
author | Richard Purdie <rpurdie@rpsys.net> | 2005-09-13 04:25:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-13 11:22:31 -0400 |
commit | fff71312e7227c6850f367ff9c72f96d5b33b1d0 (patch) | |
tree | e8a1c7b129d8120832a93f0887ce8c51c5ece809 /drivers/input | |
parent | 0dd28f1dd83a0e49b75d5171477bc56158681411 (diff) |
[PATCH] SharpSL: Add an input keyboard driver for Zaurus cxx00 series
Add a input driver for the keyboard found on the Zaurus Cxx00 series (Spitz,
Akita, Borzoi). Its based on corgikbd but there are enough subtle differences
to justify a separate driver.
Signed-Off-by: Richard Purdie <rpurdie@rpsys.net>
Cc: Vojtech Pavlik <vojtech@suse.cz>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/Kconfig | 11 | ||||
-rw-r--r-- | drivers/input/keyboard/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/keyboard/spitzkbd.c | 478 |
3 files changed, 490 insertions, 0 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index e55dee390775..444f7756fee6 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig | |||
@@ -132,6 +132,17 @@ config KEYBOARD_CORGI | |||
132 | To compile this driver as a module, choose M here: the | 132 | To compile this driver as a module, choose M here: the |
133 | module will be called corgikbd. | 133 | module will be called corgikbd. |
134 | 134 | ||
135 | config KEYBOARD_SPITZ | ||
136 | tristate "Spitz keyboard" | ||
137 | depends on PXA_SHARPSL | ||
138 | default y | ||
139 | help | ||
140 | Say Y here to enable the keyboard on the Sharp Zaurus SL-C1000, | ||
141 | SL-C3000 and Sl-C3100 series of PDAs. | ||
142 | |||
143 | To compile this driver as a module, choose M here: the | ||
144 | module will be called spitzkbd. | ||
145 | |||
135 | config KEYBOARD_MAPLE | 146 | config KEYBOARD_MAPLE |
136 | tristate "Maple bus keyboard" | 147 | tristate "Maple bus keyboard" |
137 | depends on SH_DREAMCAST && MAPLE | 148 | depends on SH_DREAMCAST && MAPLE |
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index b02eeceea3c3..9ce0b87f2fac 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile | |||
@@ -14,6 +14,7 @@ obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o | |||
14 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o | 14 | obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o |
15 | obj-$(CONFIG_KEYBOARD_98KBD) += 98kbd.o | 15 | obj-$(CONFIG_KEYBOARD_98KBD) += 98kbd.o |
16 | obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o | 16 | obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o |
17 | obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o | ||
17 | obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o | 18 | obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o |
18 | obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o | 19 | obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o |
19 | 20 | ||
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c new file mode 100644 index 000000000000..1714045a182b --- /dev/null +++ b/drivers/input/keyboard/spitzkbd.c | |||
@@ -0,0 +1,478 @@ | |||
1 | /* | ||
2 | * Keyboard driver for Sharp Spitz, Borzoi and Akita (SL-Cxx00 series) | ||
3 | * | ||
4 | * Copyright (c) 2005 Richard Purdie | ||
5 | * | ||
6 | * Based on corgikbd.c | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/delay.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/input.h> | ||
18 | #include <linux/interrupt.h> | ||
19 | #include <linux/jiffies.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <asm/irq.h> | ||
23 | |||
24 | #include <asm/arch/spitz.h> | ||
25 | #include <asm/arch/hardware.h> | ||
26 | #include <asm/arch/pxa-regs.h> | ||
27 | |||
28 | #define KB_ROWS 7 | ||
29 | #define KB_COLS 11 | ||
30 | #define KB_ROWMASK(r) (1 << (r)) | ||
31 | #define SCANCODE(r,c) (((r)<<4) + (c) + 1) | ||
32 | #define NR_SCANCODES ((KB_ROWS<<4) + 1) | ||
33 | |||
34 | #define HINGE_SCAN_INTERVAL (150) /* ms */ | ||
35 | |||
36 | #define SPITZ_KEY_CALENDER KEY_F1 | ||
37 | #define SPITZ_KEY_ADDRESS KEY_F2 | ||
38 | #define SPITZ_KEY_FN KEY_F3 | ||
39 | #define SPITZ_KEY_CANCEL KEY_F4 | ||
40 | #define SPITZ_KEY_EXOK KEY_F5 | ||
41 | #define SPITZ_KEY_EXCANCEL KEY_F6 | ||
42 | #define SPITZ_KEY_EXJOGDOWN KEY_F7 | ||
43 | #define SPITZ_KEY_EXJOGUP KEY_F8 | ||
44 | #define SPITZ_KEY_JAP1 KEY_LEFTALT | ||
45 | #define SPITZ_KEY_JAP2 KEY_RIGHTCTRL | ||
46 | #define SPITZ_KEY_SYNC KEY_F9 | ||
47 | #define SPITZ_KEY_MAIL KEY_F10 | ||
48 | #define SPITZ_KEY_OK KEY_F11 | ||
49 | #define SPITZ_KEY_MENU KEY_F12 | ||
50 | |||
51 | static unsigned char spitzkbd_keycode[NR_SCANCODES] = { | ||
52 | 0, /* 0 */ | ||
53 | KEY_LEFTCTRL, KEY_1, KEY_3, KEY_5, KEY_6, KEY_7, KEY_9, KEY_0, KEY_BACKSPACE, SPITZ_KEY_EXOK, SPITZ_KEY_EXCANCEL, 0, 0, 0, 0, 0, /* 1-16 */ | ||
54 | 0, KEY_2, KEY_4, KEY_R, KEY_Y, KEY_8, KEY_I, KEY_O, KEY_P, SPITZ_KEY_EXJOGDOWN, SPITZ_KEY_EXJOGUP, 0, 0, 0, 0, 0, /* 17-32 */ | ||
55 | KEY_TAB, KEY_Q, KEY_E, KEY_T, KEY_G, KEY_U, KEY_J, KEY_K, 0, 0, 0, 0, 0, 0, 0, 0, /* 33-48 */ | ||
56 | SPITZ_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, /* 49-64 */ | ||
57 | SPITZ_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, 0, /* 65-80 */ | ||
58 | SPITZ_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, SPITZ_KEY_FN, 0, 0, 0, 0, 0, /* 81-96 */ | ||
59 | KEY_SYSRQ, SPITZ_KEY_JAP1, SPITZ_KEY_JAP2, SPITZ_KEY_CANCEL, SPITZ_KEY_OK, SPITZ_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0 /* 97-112 */ | ||
60 | }; | ||
61 | |||
62 | static int spitz_strobes[] = { | ||
63 | SPITZ_GPIO_KEY_STROBE0, | ||
64 | SPITZ_GPIO_KEY_STROBE1, | ||
65 | SPITZ_GPIO_KEY_STROBE2, | ||
66 | SPITZ_GPIO_KEY_STROBE3, | ||
67 | SPITZ_GPIO_KEY_STROBE4, | ||
68 | SPITZ_GPIO_KEY_STROBE5, | ||
69 | SPITZ_GPIO_KEY_STROBE6, | ||
70 | SPITZ_GPIO_KEY_STROBE7, | ||
71 | SPITZ_GPIO_KEY_STROBE8, | ||
72 | SPITZ_GPIO_KEY_STROBE9, | ||
73 | SPITZ_GPIO_KEY_STROBE10, | ||
74 | }; | ||
75 | |||
76 | static int spitz_senses[] = { | ||
77 | SPITZ_GPIO_KEY_SENSE0, | ||
78 | SPITZ_GPIO_KEY_SENSE1, | ||
79 | SPITZ_GPIO_KEY_SENSE2, | ||
80 | SPITZ_GPIO_KEY_SENSE3, | ||
81 | SPITZ_GPIO_KEY_SENSE4, | ||
82 | SPITZ_GPIO_KEY_SENSE5, | ||
83 | SPITZ_GPIO_KEY_SENSE6, | ||
84 | }; | ||
85 | |||
86 | struct spitzkbd { | ||
87 | unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)]; | ||
88 | struct input_dev input; | ||
89 | char phys[32]; | ||
90 | |||
91 | spinlock_t lock; | ||
92 | struct timer_list timer; | ||
93 | struct timer_list htimer; | ||
94 | |||
95 | unsigned int suspended; | ||
96 | unsigned long suspend_jiffies; | ||
97 | }; | ||
98 | |||
99 | #define KB_DISCHARGE_DELAY 10 | ||
100 | #define KB_ACTIVATE_DELAY 10 | ||
101 | |||
102 | /* Helper functions for reading the keyboard matrix | ||
103 | * Note: We should really be using pxa_gpio_mode to alter GPDR but it | ||
104 | * requires a function call per GPIO bit which is excessive | ||
105 | * when we need to access 11 bits at once, multiple times. | ||
106 | * These functions must be called within local_irq_save()/local_irq_restore() | ||
107 | * or similar. | ||
108 | */ | ||
109 | static inline void spitzkbd_discharge_all(void) | ||
110 | { | ||
111 | /* STROBE All HiZ */ | ||
112 | GPCR0 = SPITZ_GPIO_G0_STROBE_BIT; | ||
113 | GPDR0 &= ~SPITZ_GPIO_G0_STROBE_BIT; | ||
114 | GPCR1 = SPITZ_GPIO_G1_STROBE_BIT; | ||
115 | GPDR1 &= ~SPITZ_GPIO_G1_STROBE_BIT; | ||
116 | GPCR2 = SPITZ_GPIO_G2_STROBE_BIT; | ||
117 | GPDR2 &= ~SPITZ_GPIO_G2_STROBE_BIT; | ||
118 | GPCR3 = SPITZ_GPIO_G3_STROBE_BIT; | ||
119 | GPDR3 &= ~SPITZ_GPIO_G3_STROBE_BIT; | ||
120 | } | ||
121 | |||
122 | static inline void spitzkbd_activate_all(void) | ||
123 | { | ||
124 | /* STROBE ALL -> High */ | ||
125 | GPSR0 = SPITZ_GPIO_G0_STROBE_BIT; | ||
126 | GPDR0 |= SPITZ_GPIO_G0_STROBE_BIT; | ||
127 | GPSR1 = SPITZ_GPIO_G1_STROBE_BIT; | ||
128 | GPDR1 |= SPITZ_GPIO_G1_STROBE_BIT; | ||
129 | GPSR2 = SPITZ_GPIO_G2_STROBE_BIT; | ||
130 | GPDR2 |= SPITZ_GPIO_G2_STROBE_BIT; | ||
131 | GPSR3 = SPITZ_GPIO_G3_STROBE_BIT; | ||
132 | GPDR3 |= SPITZ_GPIO_G3_STROBE_BIT; | ||
133 | |||
134 | udelay(KB_DISCHARGE_DELAY); | ||
135 | |||
136 | /* Clear any interrupts we may have triggered when altering the GPIO lines */ | ||
137 | GEDR0 = SPITZ_GPIO_G0_SENSE_BIT; | ||
138 | GEDR1 = SPITZ_GPIO_G1_SENSE_BIT; | ||
139 | GEDR2 = SPITZ_GPIO_G2_SENSE_BIT; | ||
140 | GEDR3 = SPITZ_GPIO_G3_SENSE_BIT; | ||
141 | } | ||
142 | |||
143 | static inline void spitzkbd_activate_col(int col) | ||
144 | { | ||
145 | int gpio = spitz_strobes[col]; | ||
146 | GPDR0 &= ~SPITZ_GPIO_G0_STROBE_BIT; | ||
147 | GPDR1 &= ~SPITZ_GPIO_G1_STROBE_BIT; | ||
148 | GPDR2 &= ~SPITZ_GPIO_G2_STROBE_BIT; | ||
149 | GPDR3 &= ~SPITZ_GPIO_G3_STROBE_BIT; | ||
150 | GPSR(gpio) = GPIO_bit(gpio); | ||
151 | GPDR(gpio) |= GPIO_bit(gpio); | ||
152 | } | ||
153 | |||
154 | static inline void spitzkbd_reset_col(int col) | ||
155 | { | ||
156 | int gpio = spitz_strobes[col]; | ||
157 | GPDR0 &= ~SPITZ_GPIO_G0_STROBE_BIT; | ||
158 | GPDR1 &= ~SPITZ_GPIO_G1_STROBE_BIT; | ||
159 | GPDR2 &= ~SPITZ_GPIO_G2_STROBE_BIT; | ||
160 | GPDR3 &= ~SPITZ_GPIO_G3_STROBE_BIT; | ||
161 | GPCR(gpio) = GPIO_bit(gpio); | ||
162 | GPDR(gpio) |= GPIO_bit(gpio); | ||
163 | } | ||
164 | |||
165 | static inline int spitzkbd_get_row_status(int col) | ||
166 | { | ||
167 | return ((GPLR0 >> 12) & 0x01) | ((GPLR0 >> 16) & 0x02) | ||
168 | | ((GPLR2 >> 25) & 0x04) | ((GPLR1 << 1) & 0x08) | ||
169 | | ((GPLR1 >> 0) & 0x10) | ((GPLR1 >> 1) & 0x60); | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * The spitz keyboard only generates interrupts when a key is pressed. | ||
174 | * When a key is pressed, we enable a timer which then scans the | ||
175 | * keyboard to detect when the key is released. | ||
176 | */ | ||
177 | |||
178 | /* Scan the hardware keyboard and push any changes up through the input layer */ | ||
179 | static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs *regs) | ||
180 | { | ||
181 | unsigned int row, col, rowd; | ||
182 | unsigned long flags; | ||
183 | unsigned int num_pressed, pwrkey = ((GPLR(SPITZ_GPIO_ON_KEY) & GPIO_bit(SPITZ_GPIO_ON_KEY)) != 0); | ||
184 | |||
185 | if (spitzkbd_data->suspended) | ||
186 | return; | ||
187 | |||
188 | spin_lock_irqsave(&spitzkbd_data->lock, flags); | ||
189 | |||
190 | if (regs) | ||
191 | input_regs(&spitzkbd_data->input, regs); | ||
192 | |||
193 | num_pressed = 0; | ||
194 | for (col = 0; col < KB_COLS; col++) { | ||
195 | /* | ||
196 | * Discharge the output driver capacitatance | ||
197 | * in the keyboard matrix. (Yes it is significant..) | ||
198 | */ | ||
199 | |||
200 | spitzkbd_discharge_all(); | ||
201 | udelay(KB_DISCHARGE_DELAY); | ||
202 | |||
203 | spitzkbd_activate_col(col); | ||
204 | udelay(KB_ACTIVATE_DELAY); | ||
205 | |||
206 | rowd = spitzkbd_get_row_status(col); | ||
207 | for (row = 0; row < KB_ROWS; row++) { | ||
208 | unsigned int scancode, pressed; | ||
209 | |||
210 | scancode = SCANCODE(row, col); | ||
211 | pressed = rowd & KB_ROWMASK(row); | ||
212 | |||
213 | input_report_key(&spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed); | ||
214 | |||
215 | if (pressed) | ||
216 | num_pressed++; | ||
217 | } | ||
218 | spitzkbd_reset_col(col); | ||
219 | } | ||
220 | |||
221 | spitzkbd_activate_all(); | ||
222 | |||
223 | input_report_key(&spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 ); | ||
224 | input_report_key(&spitzkbd_data->input, KEY_SUSPEND, pwrkey); | ||
225 | |||
226 | if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) { | ||
227 | input_event(&spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1); | ||
228 | spitzkbd_data->suspend_jiffies = jiffies; | ||
229 | } | ||
230 | |||
231 | input_sync(&spitzkbd_data->input); | ||
232 | |||
233 | /* if any keys are pressed, enable the timer */ | ||
234 | if (num_pressed) | ||
235 | mod_timer(&spitzkbd_data->timer, jiffies + msecs_to_jiffies(100)); | ||
236 | |||
237 | spin_unlock_irqrestore(&spitzkbd_data->lock, flags); | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * spitz keyboard interrupt handler. | ||
242 | */ | ||
243 | static irqreturn_t spitzkbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
244 | { | ||
245 | struct spitzkbd *spitzkbd_data = dev_id; | ||
246 | |||
247 | if (!timer_pending(&spitzkbd_data->timer)) { | ||
248 | /** wait chattering delay **/ | ||
249 | udelay(20); | ||
250 | spitzkbd_scankeyboard(spitzkbd_data, regs); | ||
251 | } | ||
252 | |||
253 | return IRQ_HANDLED; | ||
254 | } | ||
255 | |||
256 | /* | ||
257 | * spitz timer checking for released keys | ||
258 | */ | ||
259 | static void spitzkbd_timer_callback(unsigned long data) | ||
260 | { | ||
261 | struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data; | ||
262 | spitzkbd_scankeyboard(spitzkbd_data, NULL); | ||
263 | } | ||
264 | |||
265 | /* | ||
266 | * The hinge switches generate an interrupt. | ||
267 | * We debounce the switches and pass them to the input system. | ||
268 | */ | ||
269 | |||
270 | static irqreturn_t spitzkbd_hinge_isr(int irq, void *dev_id, struct pt_regs *regs) | ||
271 | { | ||
272 | struct spitzkbd *spitzkbd_data = dev_id; | ||
273 | |||
274 | if (!timer_pending(&spitzkbd_data->htimer)) | ||
275 | mod_timer(&spitzkbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); | ||
276 | |||
277 | return IRQ_HANDLED; | ||
278 | } | ||
279 | |||
280 | #define HINGE_STABLE_COUNT 2 | ||
281 | static int sharpsl_hinge_state; | ||
282 | static int hinge_count; | ||
283 | |||
284 | static void spitzkbd_hinge_timer(unsigned long data) | ||
285 | { | ||
286 | struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data; | ||
287 | unsigned long state; | ||
288 | unsigned long flags; | ||
289 | |||
290 | state = GPLR(SPITZ_GPIO_SWA) & (GPIO_bit(SPITZ_GPIO_SWA)|GPIO_bit(SPITZ_GPIO_SWB)); | ||
291 | if (state != sharpsl_hinge_state) { | ||
292 | hinge_count = 0; | ||
293 | sharpsl_hinge_state = state; | ||
294 | } else if (hinge_count < HINGE_STABLE_COUNT) { | ||
295 | hinge_count++; | ||
296 | } | ||
297 | |||
298 | if (hinge_count >= HINGE_STABLE_COUNT) { | ||
299 | spin_lock_irqsave(&spitzkbd_data->lock, flags); | ||
300 | |||
301 | input_report_switch(&spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0)); | ||
302 | input_report_switch(&spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0)); | ||
303 | input_sync(&spitzkbd_data->input); | ||
304 | |||
305 | spin_unlock_irqrestore(&spitzkbd_data->lock, flags); | ||
306 | } else { | ||
307 | mod_timer(&spitzkbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | #ifdef CONFIG_PM | ||
312 | static int spitzkbd_suspend(struct device *dev, pm_message_t state, uint32_t level) | ||
313 | { | ||
314 | if (level == SUSPEND_POWER_DOWN) { | ||
315 | int i; | ||
316 | struct spitzkbd *spitzkbd = dev_get_drvdata(dev); | ||
317 | spitzkbd->suspended = 1; | ||
318 | |||
319 | /* Set Strobe lines as inputs - *except* strobe line 0 leave this | ||
320 | enabled so we can detect a power button press for resume */ | ||
321 | for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++) | ||
322 | pxa_gpio_mode(spitz_strobes[i] | GPIO_IN); | ||
323 | } | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | static int spitzkbd_resume(struct device *dev, uint32_t level) | ||
328 | { | ||
329 | if (level == RESUME_POWER_ON) { | ||
330 | int i; | ||
331 | struct spitzkbd *spitzkbd = dev_get_drvdata(dev); | ||
332 | |||
333 | for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++) | ||
334 | pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH); | ||
335 | |||
336 | /* Upon resume, ignore the suspend key for a short while */ | ||
337 | spitzkbd->suspend_jiffies = jiffies; | ||
338 | spitzkbd->suspended = 0; | ||
339 | } | ||
340 | return 0; | ||
341 | } | ||
342 | #else | ||
343 | #define spitzkbd_suspend NULL | ||
344 | #define spitzkbd_resume NULL | ||
345 | #endif | ||
346 | |||
347 | static int __init spitzkbd_probe(struct device *dev) | ||
348 | { | ||
349 | int i; | ||
350 | struct spitzkbd *spitzkbd; | ||
351 | |||
352 | spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL); | ||
353 | if (!spitzkbd) | ||
354 | return -ENOMEM; | ||
355 | |||
356 | dev_set_drvdata(dev,spitzkbd); | ||
357 | strcpy(spitzkbd->phys, "spitzkbd/input0"); | ||
358 | |||
359 | spin_lock_init(&spitzkbd->lock); | ||
360 | |||
361 | /* Init Keyboard rescan timer */ | ||
362 | init_timer(&spitzkbd->timer); | ||
363 | spitzkbd->timer.function = spitzkbd_timer_callback; | ||
364 | spitzkbd->timer.data = (unsigned long) spitzkbd; | ||
365 | |||
366 | /* Init Hinge Timer */ | ||
367 | init_timer(&spitzkbd->htimer); | ||
368 | spitzkbd->htimer.function = spitzkbd_hinge_timer; | ||
369 | spitzkbd->htimer.data = (unsigned long) spitzkbd; | ||
370 | |||
371 | spitzkbd->suspend_jiffies=jiffies; | ||
372 | |||
373 | init_input_dev(&spitzkbd->input); | ||
374 | spitzkbd->input.private = spitzkbd; | ||
375 | spitzkbd->input.name = "Spitz Keyboard"; | ||
376 | spitzkbd->input.dev = dev; | ||
377 | spitzkbd->input.phys = spitzkbd->phys; | ||
378 | spitzkbd->input.id.bustype = BUS_HOST; | ||
379 | spitzkbd->input.id.vendor = 0x0001; | ||
380 | spitzkbd->input.id.product = 0x0001; | ||
381 | spitzkbd->input.id.version = 0x0100; | ||
382 | spitzkbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); | ||
383 | spitzkbd->input.keycode = spitzkbd->keycode; | ||
384 | spitzkbd->input.keycodesize = sizeof(unsigned char); | ||
385 | spitzkbd->input.keycodemax = ARRAY_SIZE(spitzkbd_keycode); | ||
386 | |||
387 | memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode)); | ||
388 | for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++) | ||
389 | set_bit(spitzkbd->keycode[i], spitzkbd->input.keybit); | ||
390 | clear_bit(0, spitzkbd->input.keybit); | ||
391 | set_bit(SW_0, spitzkbd->input.swbit); | ||
392 | set_bit(SW_1, spitzkbd->input.swbit); | ||
393 | |||
394 | input_register_device(&spitzkbd->input); | ||
395 | mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); | ||
396 | |||
397 | /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ | ||
398 | for (i = 0; i < SPITZ_KEY_SENSE_NUM; i++) { | ||
399 | pxa_gpio_mode(spitz_senses[i] | GPIO_IN); | ||
400 | if (request_irq(IRQ_GPIO(spitz_senses[i]), spitzkbd_interrupt, | ||
401 | SA_INTERRUPT, "Spitzkbd Sense", spitzkbd)) | ||
402 | printk(KERN_WARNING "spitzkbd: Can't get Sense IRQ: %d!\n", i); | ||
403 | else | ||
404 | set_irq_type(IRQ_GPIO(spitz_senses[i]),IRQT_RISING); | ||
405 | } | ||
406 | |||
407 | /* Set Strobe lines as outputs - set high */ | ||
408 | for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++) | ||
409 | pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH); | ||
410 | |||
411 | pxa_gpio_mode(SPITZ_GPIO_SYNC | GPIO_IN); | ||
412 | pxa_gpio_mode(SPITZ_GPIO_ON_KEY | GPIO_IN); | ||
413 | pxa_gpio_mode(SPITZ_GPIO_SWA | GPIO_IN); | ||
414 | pxa_gpio_mode(SPITZ_GPIO_SWB | GPIO_IN); | ||
415 | |||
416 | request_irq(SPITZ_IRQ_GPIO_SYNC, spitzkbd_interrupt, SA_INTERRUPT, "Spitzkbd Sync", spitzkbd); | ||
417 | request_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd_interrupt, SA_INTERRUPT, "Spitzkbd PwrOn", spitzkbd); | ||
418 | request_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd_hinge_isr, SA_INTERRUPT, "Spitzkbd SWA", spitzkbd); | ||
419 | request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr, SA_INTERRUPT, "Spitzkbd SWB", spitzkbd); | ||
420 | |||
421 | set_irq_type(SPITZ_IRQ_GPIO_SYNC, IRQT_BOTHEDGE); | ||
422 | set_irq_type(SPITZ_IRQ_GPIO_ON_KEY, IRQT_BOTHEDGE); | ||
423 | set_irq_type(SPITZ_IRQ_GPIO_SWA, IRQT_BOTHEDGE); | ||
424 | set_irq_type(SPITZ_IRQ_GPIO_SWB, IRQT_BOTHEDGE); | ||
425 | |||
426 | printk(KERN_INFO "input: Spitz Keyboard Registered\n"); | ||
427 | |||
428 | return 0; | ||
429 | } | ||
430 | |||
431 | static int spitzkbd_remove(struct device *dev) | ||
432 | { | ||
433 | int i; | ||
434 | struct spitzkbd *spitzkbd = dev_get_drvdata(dev); | ||
435 | |||
436 | for (i = 0; i < SPITZ_KEY_SENSE_NUM; i++) | ||
437 | free_irq(IRQ_GPIO(spitz_senses[i]), spitzkbd); | ||
438 | |||
439 | free_irq(SPITZ_IRQ_GPIO_SYNC, spitzkbd); | ||
440 | free_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd); | ||
441 | free_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd); | ||
442 | free_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd); | ||
443 | |||
444 | del_timer_sync(&spitzkbd->htimer); | ||
445 | del_timer_sync(&spitzkbd->timer); | ||
446 | |||
447 | input_unregister_device(&spitzkbd->input); | ||
448 | |||
449 | kfree(spitzkbd); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | static struct device_driver spitzkbd_driver = { | ||
455 | .name = "spitz-keyboard", | ||
456 | .bus = &platform_bus_type, | ||
457 | .probe = spitzkbd_probe, | ||
458 | .remove = spitzkbd_remove, | ||
459 | .suspend = spitzkbd_suspend, | ||
460 | .resume = spitzkbd_resume, | ||
461 | }; | ||
462 | |||
463 | static int __devinit spitzkbd_init(void) | ||
464 | { | ||
465 | return driver_register(&spitzkbd_driver); | ||
466 | } | ||
467 | |||
468 | static void __exit spitzkbd_exit(void) | ||
469 | { | ||
470 | driver_unregister(&spitzkbd_driver); | ||
471 | } | ||
472 | |||
473 | module_init(spitzkbd_init); | ||
474 | module_exit(spitzkbd_exit); | ||
475 | |||
476 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); | ||
477 | MODULE_DESCRIPTION("Spitz Keyboard Driver"); | ||
478 | MODULE_LICENSE("GPLv2"); | ||