blob: 6578bfff644bdc5099f0da31d9876c451af4fa27 [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
23#include <asm/arch/corgi.h>
24#include <asm/arch/hardware.h>
25#include <asm/arch/pxa-regs.h>
26#include <asm/hardware/scoop.h>
27
28#define KB_ROWS 8
29#define KB_COLS 12
30#define KB_ROWMASK(r) (1 << (r))
31#define SCANCODE(r,c) ( ((r)<<4) + (c) + 1 )
Richard Purdie4872f782006-03-14 00:12:32 -050032/* zero code, 124 scancodes */
33#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 )
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Richard Purdie4872f782006-03-14 00:12:32 -050035#define SCAN_INTERVAL (50) /* ms */
36#define HINGE_SCAN_INTERVAL (250) /* ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#define CORGI_KEY_CALENDER KEY_F1
39#define CORGI_KEY_ADDRESS KEY_F2
40#define CORGI_KEY_FN KEY_F3
Richard Purdie6af2cf52005-05-29 02:27:06 -050041#define CORGI_KEY_CANCEL KEY_F4
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define CORGI_KEY_OFF KEY_SUSPEND
43#define CORGI_KEY_EXOK KEY_F5
44#define CORGI_KEY_EXCANCEL KEY_F6
45#define CORGI_KEY_EXJOGDOWN KEY_F7
46#define CORGI_KEY_EXJOGUP KEY_F8
47#define CORGI_KEY_JAP1 KEY_LEFTCTRL
48#define CORGI_KEY_JAP2 KEY_LEFTALT
Richard Purdie6af2cf52005-05-29 02:27:06 -050049#define CORGI_KEY_MAIL KEY_F10
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define CORGI_KEY_OK KEY_F11
51#define CORGI_KEY_MENU KEY_F12
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53static unsigned char corgikbd_keycode[NR_SCANCODES] = {
54 0, /* 0 */
55 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 */
56 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 */
57 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 */
58 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 */
59 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 -050060 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 */
61 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 -070062 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 -070063};
64
65
66struct corgikbd {
67 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)];
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -050068 struct input_dev *input;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 struct timer_list timer;
72 struct timer_list htimer;
Richard Purdie8240a4a2005-09-06 15:18:59 -070073
74 unsigned int suspended;
75 unsigned long suspend_jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define KB_DISCHARGE_DELAY 10
79#define KB_ACTIVATE_DELAY 10
80
81/* Helper functions for reading the keyboard matrix
82 * Note: We should really be using pxa_gpio_mode to alter GPDR but it
83 * requires a function call per GPIO bit which is excessive
84 * when we need to access 12 bits at once multiple times.
85 * These functions must be called within local_irq_save()/local_irq_restore()
86 * or similar.
87 */
88static inline void corgikbd_discharge_all(void)
89{
Richard Purdie948e12f2005-09-06 15:19:00 -070090 /* STROBE All HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 GPCR2 = CORGI_GPIO_ALL_STROBE_BIT;
92 GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT;
93}
94
95static inline void corgikbd_activate_all(void)
96{
Richard Purdie948e12f2005-09-06 15:19:00 -070097 /* STROBE ALL -> High */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 GPSR2 = CORGI_GPIO_ALL_STROBE_BIT;
99 GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT;
100
101 udelay(KB_DISCHARGE_DELAY);
102
Richard Purdie948e12f2005-09-06 15:19:00 -0700103 /* Clear any interrupts we may have triggered when altering the GPIO lines */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT;
105 GEDR2 = CORGI_GPIO_LOW_SENSE_BIT;
106}
107
108static inline void corgikbd_activate_col(int col)
109{
Richard Purdie948e12f2005-09-06 15:19:00 -0700110 /* STROBE col -> High, not col -> HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 GPSR2 = CORGI_GPIO_STROBE_BIT(col);
112 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
113}
114
115static inline void corgikbd_reset_col(int col)
116{
Richard Purdie948e12f2005-09-06 15:19:00 -0700117 /* STROBE col -> Low */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 GPCR2 = CORGI_GPIO_STROBE_BIT(col);
Richard Purdie948e12f2005-09-06 15:19:00 -0700119 /* STROBE col -> out, not col -> HiZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
121}
122
123#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))
124
125/*
126 * The corgi keyboard only generates interrupts when a key is pressed.
127 * When a key is pressed, we enable a timer which then scans the
128 * keyboard to detect when the key is released.
129 */
130
131/* Scan the hardware keyboard and push any changes up through the input layer */
David Howells7d12e782006-10-05 14:55:46 +0100132static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Richard Purdie948e12f2005-09-06 15:19:00 -0700134 unsigned int row, col, rowd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 unsigned long flags;
136 unsigned int num_pressed;
137
Richard Purdie8240a4a2005-09-06 15:18:59 -0700138 if (corgikbd_data->suspended)
139 return;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 spin_lock_irqsave(&corgikbd_data->lock, flags);
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 num_pressed = 0;
144 for (col = 0; col < KB_COLS; col++) {
145 /*
146 * Discharge the output driver capacitatance
147 * in the keyboard matrix. (Yes it is significant..)
148 */
149
150 corgikbd_discharge_all();
151 udelay(KB_DISCHARGE_DELAY);
152
153 corgikbd_activate_col(col);
154 udelay(KB_ACTIVATE_DELAY);
155
156 rowd = GET_ROWS_STATUS(col);
157 for (row = 0; row < KB_ROWS; row++) {
Richard Purdie948e12f2005-09-06 15:19:00 -0700158 unsigned int scancode, pressed;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 scancode = SCANCODE(row, col);
Richard Purdie948e12f2005-09-06 15:19:00 -0700161 pressed = rowd & KB_ROWMASK(row);
162
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500163 input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
Richard Purdie948e12f2005-09-06 15:19:00 -0700164
165 if (pressed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 num_pressed++;
Richard Purdie948e12f2005-09-06 15:19:00 -0700167
168 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
169 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500170 input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
Richard Purdie948e12f2005-09-06 15:19:00 -0700171 corgikbd_data->suspend_jiffies=jiffies;
172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174 corgikbd_reset_col(col);
175 }
176
177 corgikbd_activate_all();
178
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500179 input_sync(corgikbd_data->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 /* if any keys are pressed, enable the timer */
182 if (num_pressed)
Richard Purdie4872f782006-03-14 00:12:32 -0500183 mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
186}
187
188/*
189 * corgi keyboard interrupt handler.
190 */
David Howells7d12e782006-10-05 14:55:46 +0100191static irqreturn_t corgikbd_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 struct corgikbd *corgikbd_data = dev_id;
194
195 if (!timer_pending(&corgikbd_data->timer)) {
196 /** wait chattering delay **/
197 udelay(20);
David Howells7d12e782006-10-05 14:55:46 +0100198 corgikbd_scankeyboard(corgikbd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 }
200
201 return IRQ_HANDLED;
202}
203
204/*
205 * corgi timer checking for released keys
206 */
207static void corgikbd_timer_callback(unsigned long data)
208{
209 struct corgikbd *corgikbd_data = (struct corgikbd *) data;
Russell King36bd2622006-10-15 13:50:02 +0100210 corgikbd_scankeyboard(corgikbd_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213/*
214 * The hinge switches generate no interrupt so they need to be
215 * monitored by a timer.
216 *
Richard Purdie948e12f2005-09-06 15:19:00 -0700217 * We debounce the switches and pass them to the input system.
218 *
219 * gprr == 0x00 - Keyboard with Landscape Screen
220 * 0x08 - No Keyboard with Portrait Screen
221 * 0x0c - Keyboard and Screen Closed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 */
223
Richard Purdie4872f782006-03-14 00:12:32 -0500224#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define HINGE_STABLE_COUNT 2
226static int sharpsl_hinge_state;
227static int hinge_count;
228
229static void corgikbd_hinge_timer(unsigned long data)
230{
231 struct corgikbd *corgikbd_data = (struct corgikbd *) data;
232 unsigned long gprr;
233 unsigned long flags;
234
Richard Purdieaba5a4c2005-09-06 15:18:59 -0700235 gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB);
Richard Purdie4872f782006-03-14 00:12:32 -0500236 gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (gprr != sharpsl_hinge_state) {
238 hinge_count = 0;
239 sharpsl_hinge_state = gprr;
240 } else if (hinge_count < HINGE_STABLE_COUNT) {
241 hinge_count++;
242 if (hinge_count >= HINGE_STABLE_COUNT) {
243 spin_lock_irqsave(&corgikbd_data->lock, flags);
244
Richard Purdieed8f9e22006-05-29 23:31:03 -0400245 input_report_switch(corgikbd_data->input, SW_LID, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
246 input_report_switch(corgikbd_data->input, SW_TABLET_MODE, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
247 input_report_switch(corgikbd_data->input, SW_HEADPHONE_INSERT, (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0));
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500248 input_sync(corgikbd_data->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
251 }
252 }
Richard Purdie4872f782006-03-14 00:12:32 -0500253 mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
Richard Purdie8240a4a2005-09-06 15:18:59 -0700256#ifdef CONFIG_PM
Russell King3ae5eae2005-11-09 22:32:44 +0000257static int corgikbd_suspend(struct platform_device *dev, pm_message_t state)
Richard Purdie8240a4a2005-09-06 15:18:59 -0700258{
Richard Purdie4872f782006-03-14 00:12:32 -0500259 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000260 struct corgikbd *corgikbd = platform_get_drvdata(dev);
Richard Purdie4872f782006-03-14 00:12:32 -0500261
Russell King9480e302005-10-28 09:52:56 -0700262 corgikbd->suspended = 1;
Richard Purdie4872f782006-03-14 00:12:32 -0500263 /* strobe 0 is the power key so this can't be made an input for
264 powersaving therefore i = 1 */
265 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
266 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_IN);
Russell King9480e302005-10-28 09:52:56 -0700267
Richard Purdie8240a4a2005-09-06 15:18:59 -0700268 return 0;
269}
270
Russell King3ae5eae2005-11-09 22:32:44 +0000271static int corgikbd_resume(struct platform_device *dev)
Richard Purdie8240a4a2005-09-06 15:18:59 -0700272{
Richard Purdie4872f782006-03-14 00:12:32 -0500273 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000274 struct corgikbd *corgikbd = platform_get_drvdata(dev);
Richard Purdie8240a4a2005-09-06 15:18:59 -0700275
Richard Purdie4872f782006-03-14 00:12:32 -0500276 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
277 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
278
Russell King9480e302005-10-28 09:52:56 -0700279 /* Upon resume, ignore the suspend key for a short while */
280 corgikbd->suspend_jiffies=jiffies;
281 corgikbd->suspended = 0;
282
Richard Purdie8240a4a2005-09-06 15:18:59 -0700283 return 0;
284}
285#else
286#define corgikbd_suspend NULL
287#define corgikbd_resume NULL
288#endif
289
Russell King3ae5eae2005-11-09 22:32:44 +0000290static int __init corgikbd_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 struct corgikbd *corgikbd;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500293 struct input_dev *input_dev;
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500294 int i, err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Pekka Enberga97e1482005-09-06 15:18:33 -0700296 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500297 input_dev = input_allocate_device();
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500298 if (!corgikbd || !input_dev)
299 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Russell King3ae5eae2005-11-09 22:32:44 +0000301 platform_set_drvdata(pdev, corgikbd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500303 corgikbd->input = input_dev;
Richard Purdieaba5a4c2005-09-06 15:18:59 -0700304 spin_lock_init(&corgikbd->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* Init Keyboard rescan timer */
307 init_timer(&corgikbd->timer);
308 corgikbd->timer.function = corgikbd_timer_callback;
309 corgikbd->timer.data = (unsigned long) corgikbd;
310
311 /* Init Hinge Timer */
312 init_timer(&corgikbd->htimer);
313 corgikbd->htimer.function = corgikbd_hinge_timer;
314 corgikbd->htimer.data = (unsigned long) corgikbd;
315
Richard Purdie8240a4a2005-09-06 15:18:59 -0700316 corgikbd->suspend_jiffies=jiffies;
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500320 input_dev->name = "Corgi Keyboard";
321 input_dev->phys = "corgikbd/input0";
322 input_dev->id.bustype = BUS_HOST;
323 input_dev->id.vendor = 0x0001;
324 input_dev->id.product = 0x0001;
325 input_dev->id.version = 0x0100;
Dmitry Torokhov469ba4d2007-04-12 01:34:58 -0400326 input_dev->dev.parent = &pdev->dev;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500327
328 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
329 input_dev->keycode = corgikbd->keycode;
330 input_dev->keycodesize = sizeof(unsigned char);
331 input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
332
333 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
334 set_bit(corgikbd->keycode[i], input_dev->keybit);
335 clear_bit(0, input_dev->keybit);
Richard Purdieed8f9e22006-05-29 23:31:03 -0400336 set_bit(SW_LID, input_dev->swbit);
337 set_bit(SW_TABLET_MODE, input_dev->swbit);
338 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500339
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500340 err = input_register_device(corgikbd->input);
341 if (err)
342 goto fail;
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500343
Richard Purdie4872f782006-03-14 00:12:32 -0500344 mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
347 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) {
348 pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN);
349 if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt,
Thomas Gleixnerdace1452006-07-01 19:29:38 -0700350 IRQF_DISABLED | IRQF_TRIGGER_RISING,
Russell King9ded96f2006-01-08 01:02:07 -0800351 "corgikbd", corgikbd))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354
355 /* Set Strobe lines as outputs - set high */
356 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
357 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
358
Richard Purdie4872f782006-03-14 00:12:32 -0500359 /* Setup the headphone jack as an input */
360 pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return 0;
Dmitry Torokhov2b03b602006-11-05 22:39:56 -0500363
364 fail: input_free_device(input_dev);
365 kfree(corgikbd);
366 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
Russell King3ae5eae2005-11-09 22:32:44 +0000369static int corgikbd_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
371 int i;
Russell King3ae5eae2005-11-09 22:32:44 +0000372 struct corgikbd *corgikbd = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++)
375 free_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd);
376
377 del_timer_sync(&corgikbd->htimer);
378 del_timer_sync(&corgikbd->timer);
379
Dmitry Torokhov3c42f0c2005-09-15 02:01:45 -0500380 input_unregister_device(corgikbd->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 kfree(corgikbd);
383
384 return 0;
385}
386
Russell King3ae5eae2005-11-09 22:32:44 +0000387static struct platform_driver corgikbd_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 .probe = corgikbd_probe,
389 .remove = corgikbd_remove,
Richard Purdie8240a4a2005-09-06 15:18:59 -0700390 .suspend = corgikbd_suspend,
391 .resume = corgikbd_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000392 .driver = {
393 .name = "corgi-keyboard",
394 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395};
396
397static int __devinit corgikbd_init(void)
398{
Russell King3ae5eae2005-11-09 22:32:44 +0000399 return platform_driver_register(&corgikbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
402static void __exit corgikbd_exit(void)
403{
Russell King3ae5eae2005-11-09 22:32:44 +0000404 platform_driver_unregister(&corgikbd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
407module_init(corgikbd_init);
408module_exit(corgikbd_exit);
409
410MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
411MODULE_DESCRIPTION("Corgi Keyboard Driver");
412MODULE_LICENSE("GPLv2");