blob: c8ed065ea0cbd9f2d360331c101b2052bc8d2ebb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Keyboard driver for Sharp Corgi models (SL-C7xx)
3 *
4 * Copyright (c) 2004-2005 Richard Purdie
5 *
6 * Based on xtkbd.c/locomkbd.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>
Russell Kingd052d1b2005-10-29 19:07:23 +010015#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
17#include <linux/input.h>
18#include <linux/interrupt.h>
Richard Purdie8240a4a2005-09-06 15:18:59 -070019#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
21#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Russell Kinga09e64f2008-08-05 16:14:15 +010023#include <mach/corgi.h>
24#include <mach/hardware.h>
25#include <mach/pxa-regs.h>
26#include <mach/pxa2xx-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/hardware/scoop.h>
28
29#define KB_ROWS 8
30#define KB_COLS 12
31#define KB_ROWMASK(r) (1 << (r))
32#define SCANCODE(r,c) ( ((r)<<4) + (c) + 1 )
Richard Purdie4872f782006-03-14 00:12:32 -050033/* zero code, 124 scancodes */
34#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 )
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Richard Purdie4872f782006-03-14 00:12:32 -050036#define SCAN_INTERVAL (50) /* ms */
37#define HINGE_SCAN_INTERVAL (250) /* ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#define CORGI_KEY_CALENDER KEY_F1
40#define CORGI_KEY_ADDRESS KEY_F2
41#define CORGI_KEY_FN KEY_F3
Richard Purdie6af2cf52005-05-29 02:27:06 -050042#define CORGI_KEY_CANCEL KEY_F4
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define CORGI_KEY_OFF KEY_SUSPEND
44#define CORGI_KEY_EXOK KEY_F5
45#define CORGI_KEY_EXCANCEL KEY_F6
46#define CORGI_KEY_EXJOGDOWN KEY_F7
47#define CORGI_KEY_EXJOGUP KEY_F8
48#define CORGI_KEY_JAP1 KEY_LEFTCTRL
49#define CORGI_KEY_JAP2 KEY_LEFTALT
Richard Purdie6af2cf52005-05-29 02:27:06 -050050#define CORGI_KEY_MAIL KEY_F10
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define CORGI_KEY_OK KEY_F11
52#define CORGI_KEY_MENU KEY_F12
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54static unsigned char corgikbd_keycode[NR_SCANCODES] = {
55 0, /* 0 */
56 0, KEY_1, KEY_3, KEY_5, KEY_6, KEY_7, KEY_9, KEY_0, KEY_BACKSPACE, 0, 0, 0, 0, 0, 0, 0, /* 1-16 */
57 0, KEY_2, KEY_4, KEY_R, KEY_Y, KEY_8, KEY_I, KEY_O, KEY_P, 0, 0, 0, 0, 0, 0, 0, /* 17-32 */
58 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 */
59 CORGI_KEY_CALENDER, KEY_W, KEY_S, KEY_F, KEY_V, KEY_H, KEY_M, KEY_L, 0, KEY_RIGHTSHIFT, 0, 0, 0, 0, 0, 0, /* 49-64 */
60 CORGI_KEY_ADDRESS, KEY_A, KEY_D, KEY_C, KEY_B, KEY_N, KEY_DOT, 0, KEY_ENTER, 0, KEY_LEFTSHIFT, 0, 0, 0, 0, 0, /* 65-80 */
Richard Purdie6af2cf52005-05-29 02:27:06 -050061 CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */
62 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66
67struct corgikbd {
68 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)];
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -050069 struct input_dev *input;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 struct timer_list timer;
73 struct timer_list htimer;
Richard Purdie8240a4a2005-09-06 15:18:59 -070074
75 unsigned int suspended;
76 unsigned long suspend_jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define KB_DISCHARGE_DELAY 10
80#define KB_ACTIVATE_DELAY 10
81
82/* Helper functions for reading the keyboard matrix
Russell King73b610a2008-09-25 13:35:27 +010083 * Note: We should really be using the generic gpio functions to alter
84 * GPDR but it requires a function call per GPIO bit which is
85 * excessive when we need to access 12 bits at once, multiple times.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * These functions must be called within local_irq_save()/local_irq_restore()
87 * or similar.
88 */
89static inline void corgikbd_discharge_all(void)
90{
Richard Purdie948e12f2005-09-06 15:19:00 -070091 /* STROBE All HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 GPCR2 = CORGI_GPIO_ALL_STROBE_BIT;
93 GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT;
94}
95
96static inline void corgikbd_activate_all(void)
97{
Richard Purdie948e12f2005-09-06 15:19:00 -070098 /* STROBE ALL -> High */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 GPSR2 = CORGI_GPIO_ALL_STROBE_BIT;
100 GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT;
101
102 udelay(KB_DISCHARGE_DELAY);
103
Richard Purdie948e12f2005-09-06 15:19:00 -0700104 /* Clear any interrupts we may have triggered when altering the GPIO lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT;
106 GEDR2 = CORGI_GPIO_LOW_SENSE_BIT;
107}
108
109static inline void corgikbd_activate_col(int col)
110{
Richard Purdie948e12f2005-09-06 15:19:00 -0700111 /* STROBE col -> High, not col -> HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 GPSR2 = CORGI_GPIO_STROBE_BIT(col);
113 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
114}
115
116static inline void corgikbd_reset_col(int col)
117{
Richard Purdie948e12f2005-09-06 15:19:00 -0700118 /* STROBE col -> Low */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 GPCR2 = CORGI_GPIO_STROBE_BIT(col);
Richard Purdie948e12f2005-09-06 15:19:00 -0700120 /* STROBE col -> out, not col -> HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
122}
123
124#define GET_ROWS_STATUS(c) (((GPLR1 & CORGI_GPIO_HIGH_SENSE_BIT) >> CORGI_GPIO_HIGH_SENSE_RSHIFT) | ((GPLR2 & CORGI_GPIO_LOW_SENSE_BIT) << CORGI_GPIO_LOW_SENSE_LSHIFT))
125
126/*
127 * The corgi keyboard only generates interrupts when a key is pressed.
128 * When a key is pressed, we enable a timer which then scans the
129 * keyboard to detect when the key is released.
130 */
131
132/* Scan the hardware keyboard and push any changes up through the input layer */
David Howells7d12e782006-10-05 14:55:46 +0100133static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Richard Purdie948e12f2005-09-06 15:19:00 -0700135 unsigned int row, col, rowd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 unsigned long flags;
137 unsigned int num_pressed;
138
Richard Purdie8240a4a2005-09-06 15:18:59 -0700139 if (corgikbd_data->suspended)
140 return;
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 spin_lock_irqsave(&corgikbd_data->lock, flags);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 num_pressed = 0;
145 for (col = 0; col < KB_COLS; col++) {
146 /*
147 * Discharge the output driver capacitatance
148 * in the keyboard matrix. (Yes it is significant..)
149 */
150
151 corgikbd_discharge_all();
152 udelay(KB_DISCHARGE_DELAY);
153
154 corgikbd_activate_col(col);
155 udelay(KB_ACTIVATE_DELAY);
156
157 rowd = GET_ROWS_STATUS(col);
158 for (row = 0; row < KB_ROWS; row++) {
Richard Purdie948e12f2005-09-06 15:19:00 -0700159 unsigned int scancode, pressed;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 scancode = SCANCODE(row, col);
Richard Purdie948e12f2005-09-06 15:19:00 -0700162 pressed = rowd & KB_ROWMASK(row);
163
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500164 input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
Richard Purdie948e12f2005-09-06 15:19:00 -0700165
166 if (pressed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 num_pressed++;
Richard Purdie948e12f2005-09-06 15:19:00 -0700168
169 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
170 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500171 input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
Richard Purdie948e12f2005-09-06 15:19:00 -0700172 corgikbd_data->suspend_jiffies=jiffies;
173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175 corgikbd_reset_col(col);
176 }
177
178 corgikbd_activate_all();
179
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500180 input_sync(corgikbd_data->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 /* if any keys are pressed, enable the timer */
183 if (num_pressed)
Richard Purdie4872f782006-03-14 00:12:32 -0500184 mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
187}
188
189/*
190 * corgi keyboard interrupt handler.
191 */
David Howells7d12e782006-10-05 14:55:46 +0100192static irqreturn_t corgikbd_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 struct corgikbd *corgikbd_data = dev_id;
195
196 if (!timer_pending(&corgikbd_data->timer)) {
197 /** wait chattering delay **/
198 udelay(20);
David Howells7d12e782006-10-05 14:55:46 +0100199 corgikbd_scankeyboard(corgikbd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 }
201
202 return IRQ_HANDLED;
203}
204
205/*
206 * corgi timer checking for released keys
207 */
208static void corgikbd_timer_callback(unsigned long data)
209{
210 struct corgikbd *corgikbd_data = (struct corgikbd *) data;
Russell King36bd2622006-10-15 13:50:02 +0100211 corgikbd_scankeyboard(corgikbd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
214/*
215 * The hinge switches generate no interrupt so they need to be
216 * monitored by a timer.
217 *
Richard Purdie948e12f2005-09-06 15:19:00 -0700218 * We debounce the switches and pass them to the input system.
219 *
220 * gprr == 0x00 - Keyboard with Landscape Screen
221 * 0x08 - No Keyboard with Portrait Screen
222 * 0x0c - Keyboard and Screen Closed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 */
224
Richard Purdie4872f782006-03-14 00:12:32 -0500225#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define HINGE_STABLE_COUNT 2
227static int sharpsl_hinge_state;
228static int hinge_count;
229
230static void corgikbd_hinge_timer(unsigned long data)
231{
232 struct corgikbd *corgikbd_data = (struct corgikbd *) data;
233 unsigned long gprr;
234 unsigned long flags;
235
Richard Purdieaba5a4c2005-09-06 15:18:59 -0700236 gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB);
Richard Purdie4872f782006-03-14 00:12:32 -0500237 gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (gprr != sharpsl_hinge_state) {
239 hinge_count = 0;
240 sharpsl_hinge_state = gprr;
241 } else if (hinge_count < HINGE_STABLE_COUNT) {
242 hinge_count++;
243 if (hinge_count >= HINGE_STABLE_COUNT) {
244 spin_lock_irqsave(&corgikbd_data->lock, flags);
245
Richard Purdieed8f9e22006-05-29 23:31:03 -0400246 input_report_switch(corgikbd_data->input, SW_LID, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
247 input_report_switch(corgikbd_data->input, SW_TABLET_MODE, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
248 input_report_switch(corgikbd_data->input, SW_HEADPHONE_INSERT, (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0));
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500249 input_sync(corgikbd_data->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
252 }
253 }
Richard Purdie4872f782006-03-14 00:12:32 -0500254 mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Richard Purdie8240a4a2005-09-06 15:18:59 -0700257#ifdef CONFIG_PM
Russell King3ae5eae2005-11-09 22:32:44 +0000258static int corgikbd_suspend(struct platform_device *dev, pm_message_t state)
Richard Purdie8240a4a2005-09-06 15:18:59 -0700259{
Richard Purdie4872f782006-03-14 00:12:32 -0500260 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000261 struct corgikbd *corgikbd = platform_get_drvdata(dev);
Richard Purdie4872f782006-03-14 00:12:32 -0500262
Russell King9480e302005-10-28 09:52:56 -0700263 corgikbd->suspended = 1;
Richard Purdie4872f782006-03-14 00:12:32 -0500264 /* strobe 0 is the power key so this can't be made an input for
265 powersaving therefore i = 1 */
266 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
267 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_IN);
Russell King9480e302005-10-28 09:52:56 -0700268
Richard Purdie8240a4a2005-09-06 15:18:59 -0700269 return 0;
270}
271
Russell King3ae5eae2005-11-09 22:32:44 +0000272static int corgikbd_resume(struct platform_device *dev)
Richard Purdie8240a4a2005-09-06 15:18:59 -0700273{
Richard Purdie4872f782006-03-14 00:12:32 -0500274 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000275 struct corgikbd *corgikbd = platform_get_drvdata(dev);
Richard Purdie8240a4a2005-09-06 15:18:59 -0700276
Richard Purdie4872f782006-03-14 00:12:32 -0500277 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
278 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
279
Russell King9480e302005-10-28 09:52:56 -0700280 /* Upon resume, ignore the suspend key for a short while */
281 corgikbd->suspend_jiffies=jiffies;
282 corgikbd->suspended = 0;
283
Richard Purdie8240a4a2005-09-06 15:18:59 -0700284 return 0;
285}
286#else
287#define corgikbd_suspend NULL
288#define corgikbd_resume NULL
289#endif
290
Russell King3ae5eae2005-11-09 22:32:44 +0000291static int __init corgikbd_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct corgikbd *corgikbd;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500294 struct input_dev *input_dev;
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500295 int i, err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Pekka Enberga97e1482005-09-06 15:18:33 -0700297 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500298 input_dev = input_allocate_device();
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500299 if (!corgikbd || !input_dev)
300 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Russell King3ae5eae2005-11-09 22:32:44 +0000302 platform_set_drvdata(pdev, corgikbd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500304 corgikbd->input = input_dev;
Richard Purdieaba5a4c2005-09-06 15:18:59 -0700305 spin_lock_init(&corgikbd->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 /* Init Keyboard rescan timer */
308 init_timer(&corgikbd->timer);
309 corgikbd->timer.function = corgikbd_timer_callback;
310 corgikbd->timer.data = (unsigned long) corgikbd;
311
312 /* Init Hinge Timer */
313 init_timer(&corgikbd->htimer);
314 corgikbd->htimer.function = corgikbd_hinge_timer;
315 corgikbd->htimer.data = (unsigned long) corgikbd;
316
Richard Purdie8240a4a2005-09-06 15:18:59 -0700317 corgikbd->suspend_jiffies=jiffies;
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500321 input_dev->name = "Corgi Keyboard";
322 input_dev->phys = "corgikbd/input0";
323 input_dev->id.bustype = BUS_HOST;
324 input_dev->id.vendor = 0x0001;
325 input_dev->id.product = 0x0001;
326 input_dev->id.version = 0x0100;
Dmitry Torokhov469ba4d2007-04-12 01:34:58 -0400327 input_dev->dev.parent = &pdev->dev;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500328
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700329 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
330 BIT_MASK(EV_PWR) | BIT_MASK(EV_SW);
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500331 input_dev->keycode = corgikbd->keycode;
332 input_dev->keycodesize = sizeof(unsigned char);
333 input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
334
335 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
336 set_bit(corgikbd->keycode[i], input_dev->keybit);
337 clear_bit(0, input_dev->keybit);
Richard Purdieed8f9e22006-05-29 23:31:03 -0400338 set_bit(SW_LID, input_dev->swbit);
339 set_bit(SW_TABLET_MODE, input_dev->swbit);
340 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500341
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500342 err = input_register_device(corgikbd->input);
343 if (err)
344 goto fail;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500345
Richard Purdie4872f782006-03-14 00:12:32 -0500346 mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
349 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) {
350 pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN);
351 if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt,
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700352 IRQF_DISABLED | IRQF_TRIGGER_RISING,
Russell King9ded96f2006-01-08 01:02:07 -0800353 "corgikbd", corgikbd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 /* Set Strobe lines as outputs - set high */
358 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
359 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
360
Richard Purdie4872f782006-03-14 00:12:32 -0500361 /* Setup the headphone jack as an input */
362 pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return 0;
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500365
366 fail: input_free_device(input_dev);
367 kfree(corgikbd);
368 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
Russell King3ae5eae2005-11-09 22:32:44 +0000371static int corgikbd_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
373 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000374 struct corgikbd *corgikbd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++)
377 free_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd);
378
379 del_timer_sync(&corgikbd->htimer);
380 del_timer_sync(&corgikbd->timer);
381
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500382 input_unregister_device(corgikbd->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 kfree(corgikbd);
385
386 return 0;
387}
388
Russell King3ae5eae2005-11-09 22:32:44 +0000389static struct platform_driver corgikbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .probe = corgikbd_probe,
391 .remove = corgikbd_remove,
Richard Purdie8240a4a2005-09-06 15:18:59 -0700392 .suspend = corgikbd_suspend,
393 .resume = corgikbd_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000394 .driver = {
395 .name = "corgi-keyboard",
Kay Sieversd7b52472008-04-18 00:24:42 -0400396 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +0000397 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
400static int __devinit corgikbd_init(void)
401{
Russell King3ae5eae2005-11-09 22:32:44 +0000402 return platform_driver_register(&corgikbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
405static void __exit corgikbd_exit(void)
406{
Russell King3ae5eae2005-11-09 22:32:44 +0000407 platform_driver_unregister(&corgikbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410module_init(corgikbd_init);
411module_exit(corgikbd_exit);
412
413MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
414MODULE_DESCRIPTION("Corgi Keyboard Driver");
Al Viro839cd312008-05-21 06:32:11 +0100415MODULE_LICENSE("GPL v2");
Kay Sieversd7b52472008-04-18 00:24:42 -0400416MODULE_ALIAS("platform:corgi-keyboard");