Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/input.h> |
| 18 | #include <linux/interrupt.h> |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 19 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 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 Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 32 | /* zero code, 124 scancodes */ |
| 33 | #define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 35 | #define SCAN_INTERVAL (50) /* ms */ |
| 36 | #define HINGE_SCAN_INTERVAL (250) /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #define CORGI_KEY_CALENDER KEY_F1 |
| 39 | #define CORGI_KEY_ADDRESS KEY_F2 |
| 40 | #define CORGI_KEY_FN KEY_F3 |
Richard Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 41 | #define CORGI_KEY_CANCEL KEY_F4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #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 Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 49 | #define CORGI_KEY_MAIL KEY_F10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define CORGI_KEY_OK KEY_F11 |
| 51 | #define CORGI_KEY_MENU KEY_F12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | static 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 Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 60 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | |
| 66 | struct corgikbd { |
| 67 | unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)]; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 68 | struct input_dev *input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | spinlock_t lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct timer_list timer; |
| 72 | struct timer_list htimer; |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 73 | |
| 74 | unsigned int suspended; |
| 75 | unsigned long suspend_jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #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 | */ |
| 88 | static inline void corgikbd_discharge_all(void) |
| 89 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 90 | /* STROBE All HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | GPCR2 = CORGI_GPIO_ALL_STROBE_BIT; |
| 92 | GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT; |
| 93 | } |
| 94 | |
| 95 | static inline void corgikbd_activate_all(void) |
| 96 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 97 | /* STROBE ALL -> High */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | GPSR2 = CORGI_GPIO_ALL_STROBE_BIT; |
| 99 | GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT; |
| 100 | |
| 101 | udelay(KB_DISCHARGE_DELAY); |
| 102 | |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 103 | /* Clear any interrupts we may have triggered when altering the GPIO lines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT; |
| 105 | GEDR2 = CORGI_GPIO_LOW_SENSE_BIT; |
| 106 | } |
| 107 | |
| 108 | static inline void corgikbd_activate_col(int col) |
| 109 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 110 | /* STROBE col -> High, not col -> HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | GPSR2 = CORGI_GPIO_STROBE_BIT(col); |
| 112 | GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); |
| 113 | } |
| 114 | |
| 115 | static inline void corgikbd_reset_col(int col) |
| 116 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 117 | /* STROBE col -> Low */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | GPCR2 = CORGI_GPIO_STROBE_BIT(col); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 119 | /* STROBE col -> out, not col -> HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | 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 */ |
| 132 | static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs *regs) |
| 133 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 134 | unsigned int row, col, rowd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | unsigned long flags; |
| 136 | unsigned int num_pressed; |
| 137 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 138 | if (corgikbd_data->suspended) |
| 139 | return; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | spin_lock_irqsave(&corgikbd_data->lock, flags); |
| 142 | |
| 143 | if (regs) |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 144 | input_regs(corgikbd_data->input, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | num_pressed = 0; |
| 147 | for (col = 0; col < KB_COLS; col++) { |
| 148 | /* |
| 149 | * Discharge the output driver capacitatance |
| 150 | * in the keyboard matrix. (Yes it is significant..) |
| 151 | */ |
| 152 | |
| 153 | corgikbd_discharge_all(); |
| 154 | udelay(KB_DISCHARGE_DELAY); |
| 155 | |
| 156 | corgikbd_activate_col(col); |
| 157 | udelay(KB_ACTIVATE_DELAY); |
| 158 | |
| 159 | rowd = GET_ROWS_STATUS(col); |
| 160 | for (row = 0; row < KB_ROWS; row++) { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 161 | unsigned int scancode, pressed; |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | scancode = SCANCODE(row, col); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 164 | pressed = rowd & KB_ROWMASK(row); |
| 165 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 166 | input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 167 | |
| 168 | if (pressed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | num_pressed++; |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 170 | |
| 171 | if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) |
| 172 | && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 173 | input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 174 | corgikbd_data->suspend_jiffies=jiffies; |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | corgikbd_reset_col(col); |
| 178 | } |
| 179 | |
| 180 | corgikbd_activate_all(); |
| 181 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 182 | input_sync(corgikbd_data->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* if any keys are pressed, enable the timer */ |
| 185 | if (num_pressed) |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 186 | mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | spin_unlock_irqrestore(&corgikbd_data->lock, flags); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * corgi keyboard interrupt handler. |
| 193 | */ |
| 194 | static irqreturn_t corgikbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 195 | { |
| 196 | struct corgikbd *corgikbd_data = dev_id; |
| 197 | |
| 198 | if (!timer_pending(&corgikbd_data->timer)) { |
| 199 | /** wait chattering delay **/ |
| 200 | udelay(20); |
| 201 | corgikbd_scankeyboard(corgikbd_data, regs); |
| 202 | } |
| 203 | |
| 204 | return IRQ_HANDLED; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * corgi timer checking for released keys |
| 209 | */ |
| 210 | static void corgikbd_timer_callback(unsigned long data) |
| 211 | { |
| 212 | struct corgikbd *corgikbd_data = (struct corgikbd *) data; |
| 213 | corgikbd_scankeyboard(corgikbd_data, NULL); |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * The hinge switches generate no interrupt so they need to be |
| 218 | * monitored by a timer. |
| 219 | * |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 220 | * We debounce the switches and pass them to the input system. |
| 221 | * |
| 222 | * gprr == 0x00 - Keyboard with Landscape Screen |
| 223 | * 0x08 - No Keyboard with Portrait Screen |
| 224 | * 0x0c - Keyboard and Screen Closed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | */ |
| 226 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 227 | #define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | #define HINGE_STABLE_COUNT 2 |
| 229 | static int sharpsl_hinge_state; |
| 230 | static int hinge_count; |
| 231 | |
| 232 | static void corgikbd_hinge_timer(unsigned long data) |
| 233 | { |
| 234 | struct corgikbd *corgikbd_data = (struct corgikbd *) data; |
| 235 | unsigned long gprr; |
| 236 | unsigned long flags; |
| 237 | |
Richard Purdie | aba5a4c | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 238 | gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB); |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 239 | gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | if (gprr != sharpsl_hinge_state) { |
| 241 | hinge_count = 0; |
| 242 | sharpsl_hinge_state = gprr; |
| 243 | } else if (hinge_count < HINGE_STABLE_COUNT) { |
| 244 | hinge_count++; |
| 245 | if (hinge_count >= HINGE_STABLE_COUNT) { |
| 246 | spin_lock_irqsave(&corgikbd_data->lock, flags); |
| 247 | |
Richard Purdie | ed8f9e2 | 2006-05-29 23:31:03 -0400 | [diff] [blame] | 248 | input_report_switch(corgikbd_data->input, SW_LID, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0)); |
| 249 | input_report_switch(corgikbd_data->input, SW_TABLET_MODE, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0)); |
| 250 | input_report_switch(corgikbd_data->input, SW_HEADPHONE_INSERT, (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0)); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 251 | input_sync(corgikbd_data->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | spin_unlock_irqrestore(&corgikbd_data->lock, flags); |
| 254 | } |
| 255 | } |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 256 | mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 259 | #ifdef CONFIG_PM |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 260 | static int corgikbd_suspend(struct platform_device *dev, pm_message_t state) |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 261 | { |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 262 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 263 | struct corgikbd *corgikbd = platform_get_drvdata(dev); |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 264 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 265 | corgikbd->suspended = 1; |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 266 | /* strobe 0 is the power key so this can't be made an input for |
| 267 | powersaving therefore i = 1 */ |
| 268 | for (i = 1; i < CORGI_KEY_STROBE_NUM; i++) |
| 269 | pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_IN); |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 270 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 274 | static int corgikbd_resume(struct platform_device *dev) |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 275 | { |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 276 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 277 | struct corgikbd *corgikbd = platform_get_drvdata(dev); |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 278 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 279 | for (i = 1; i < CORGI_KEY_STROBE_NUM; i++) |
| 280 | pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH); |
| 281 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 282 | /* Upon resume, ignore the suspend key for a short while */ |
| 283 | corgikbd->suspend_jiffies=jiffies; |
| 284 | corgikbd->suspended = 0; |
| 285 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | #else |
| 289 | #define corgikbd_suspend NULL |
| 290 | #define corgikbd_resume NULL |
| 291 | #endif |
| 292 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 293 | static int __init corgikbd_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | struct corgikbd *corgikbd; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 296 | struct input_dev *input_dev; |
| 297 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Pekka Enberg | a97e148 | 2005-09-06 15:18:33 -0700 | [diff] [blame] | 299 | corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 300 | input_dev = input_allocate_device(); |
| 301 | if (!corgikbd || !input_dev) { |
| 302 | kfree(corgikbd); |
| 303 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return -ENOMEM; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 307 | platform_set_drvdata(pdev, corgikbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 309 | corgikbd->input = input_dev; |
Richard Purdie | aba5a4c | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 310 | spin_lock_init(&corgikbd->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | /* Init Keyboard rescan timer */ |
| 313 | init_timer(&corgikbd->timer); |
| 314 | corgikbd->timer.function = corgikbd_timer_callback; |
| 315 | corgikbd->timer.data = (unsigned long) corgikbd; |
| 316 | |
| 317 | /* Init Hinge Timer */ |
| 318 | init_timer(&corgikbd->htimer); |
| 319 | corgikbd->htimer.function = corgikbd_hinge_timer; |
| 320 | corgikbd->htimer.data = (unsigned long) corgikbd; |
| 321 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 322 | corgikbd->suspend_jiffies=jiffies; |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 326 | input_dev->name = "Corgi Keyboard"; |
| 327 | input_dev->phys = "corgikbd/input0"; |
| 328 | input_dev->id.bustype = BUS_HOST; |
| 329 | input_dev->id.vendor = 0x0001; |
| 330 | input_dev->id.product = 0x0001; |
| 331 | input_dev->id.version = 0x0100; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 332 | input_dev->cdev.dev = &pdev->dev; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 333 | input_dev->private = corgikbd; |
| 334 | |
| 335 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); |
| 336 | input_dev->keycode = corgikbd->keycode; |
| 337 | input_dev->keycodesize = sizeof(unsigned char); |
| 338 | input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode); |
| 339 | |
| 340 | for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++) |
| 341 | set_bit(corgikbd->keycode[i], input_dev->keybit); |
| 342 | clear_bit(0, input_dev->keybit); |
Richard Purdie | ed8f9e2 | 2006-05-29 23:31:03 -0400 | [diff] [blame] | 343 | set_bit(SW_LID, input_dev->swbit); |
| 344 | set_bit(SW_TABLET_MODE, input_dev->swbit); |
| 345 | set_bit(SW_HEADPHONE_INSERT, input_dev->swbit); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 346 | |
| 347 | input_register_device(corgikbd->input); |
| 348 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 349 | mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ |
| 352 | for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) { |
| 353 | pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN); |
| 354 | if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt, |
Russell King | 9ded96f | 2006-01-08 01:02:07 -0800 | [diff] [blame] | 355 | SA_INTERRUPT | SA_TRIGGER_RISING, |
| 356 | "corgikbd", corgikbd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* Set Strobe lines as outputs - set high */ |
| 361 | for (i = 0; i < CORGI_KEY_STROBE_NUM; i++) |
| 362 | pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH); |
| 363 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 364 | /* Setup the headphone jack as an input */ |
| 365 | pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN); |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 370 | static int corgikbd_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 373 | struct corgikbd *corgikbd = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
| 375 | for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) |
| 376 | free_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd); |
| 377 | |
| 378 | del_timer_sync(&corgikbd->htimer); |
| 379 | del_timer_sync(&corgikbd->timer); |
| 380 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 381 | input_unregister_device(corgikbd->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | kfree(corgikbd); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 388 | static struct platform_driver corgikbd_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | .probe = corgikbd_probe, |
| 390 | .remove = corgikbd_remove, |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 391 | .suspend = corgikbd_suspend, |
| 392 | .resume = corgikbd_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 393 | .driver = { |
| 394 | .name = "corgi-keyboard", |
| 395 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | static int __devinit corgikbd_init(void) |
| 399 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 400 | return platform_driver_register(&corgikbd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static void __exit corgikbd_exit(void) |
| 404 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 405 | platform_driver_unregister(&corgikbd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | module_init(corgikbd_init); |
| 409 | module_exit(corgikbd_exit); |
| 410 | |
| 411 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
| 412 | MODULE_DESCRIPTION("Corgi Keyboard Driver"); |
| 413 | MODULE_LICENSE("GPLv2"); |