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 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/corgi.h> |
| 24 | #include <mach/hardware.h> |
| 25 | #include <mach/pxa-regs.h> |
| 26 | #include <mach/pxa2xx-gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #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 Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 33 | /* zero code, 124 scancodes */ |
| 34 | #define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 36 | #define SCAN_INTERVAL (50) /* ms */ |
| 37 | #define HINGE_SCAN_INTERVAL (250) /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #define CORGI_KEY_CALENDER KEY_F1 |
| 40 | #define CORGI_KEY_ADDRESS KEY_F2 |
| 41 | #define CORGI_KEY_FN KEY_F3 |
Richard Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 42 | #define CORGI_KEY_CANCEL KEY_F4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #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 Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 50 | #define CORGI_KEY_MAIL KEY_F10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define CORGI_KEY_OK KEY_F11 |
| 52 | #define CORGI_KEY_MENU KEY_F12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | static 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 Purdie | 6af2cf5 | 2005-05-29 02:27:06 -0500 | [diff] [blame] | 61 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 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] | 64 | }; |
| 65 | |
| 66 | |
| 67 | struct corgikbd { |
| 68 | unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)]; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 69 | struct input_dev *input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | spinlock_t lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | struct timer_list timer; |
| 73 | struct timer_list htimer; |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 74 | |
| 75 | unsigned int suspended; |
| 76 | unsigned long suspend_jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define KB_DISCHARGE_DELAY 10 |
| 80 | #define KB_ACTIVATE_DELAY 10 |
| 81 | |
| 82 | /* Helper functions for reading the keyboard matrix |
Russell King | 73b610a | 2008-09-25 13:35:27 +0100 | [diff] [blame] | 83 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * These functions must be called within local_irq_save()/local_irq_restore() |
| 87 | * or similar. |
| 88 | */ |
| 89 | static inline void corgikbd_discharge_all(void) |
| 90 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 91 | /* STROBE All HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | GPCR2 = CORGI_GPIO_ALL_STROBE_BIT; |
| 93 | GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT; |
| 94 | } |
| 95 | |
| 96 | static inline void corgikbd_activate_all(void) |
| 97 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 98 | /* STROBE ALL -> High */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | GPSR2 = CORGI_GPIO_ALL_STROBE_BIT; |
| 100 | GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT; |
| 101 | |
| 102 | udelay(KB_DISCHARGE_DELAY); |
| 103 | |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 104 | /* Clear any interrupts we may have triggered when altering the GPIO lines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT; |
| 106 | GEDR2 = CORGI_GPIO_LOW_SENSE_BIT; |
| 107 | } |
| 108 | |
| 109 | static inline void corgikbd_activate_col(int col) |
| 110 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 111 | /* STROBE col -> High, not col -> HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | GPSR2 = CORGI_GPIO_STROBE_BIT(col); |
| 113 | GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); |
| 114 | } |
| 115 | |
| 116 | static inline void corgikbd_reset_col(int col) |
| 117 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 118 | /* STROBE col -> Low */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | GPCR2 = CORGI_GPIO_STROBE_BIT(col); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 120 | /* STROBE col -> out, not col -> HiZ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 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 Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 133 | static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 135 | unsigned int row, col, rowd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | unsigned long flags; |
| 137 | unsigned int num_pressed; |
| 138 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 139 | if (corgikbd_data->suspended) |
| 140 | return; |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | spin_lock_irqsave(&corgikbd_data->lock, flags); |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | 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 Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 159 | unsigned int scancode, pressed; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | scancode = SCANCODE(row, col); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 162 | pressed = rowd & KB_ROWMASK(row); |
| 163 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 164 | input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 165 | |
| 166 | if (pressed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | num_pressed++; |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 168 | |
| 169 | if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) |
| 170 | && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 171 | input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 172 | corgikbd_data->suspend_jiffies=jiffies; |
| 173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | corgikbd_reset_col(col); |
| 176 | } |
| 177 | |
| 178 | corgikbd_activate_all(); |
| 179 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 180 | input_sync(corgikbd_data->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | /* if any keys are pressed, enable the timer */ |
| 183 | if (num_pressed) |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 184 | mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | spin_unlock_irqrestore(&corgikbd_data->lock, flags); |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * corgi keyboard interrupt handler. |
| 191 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 192 | static irqreturn_t corgikbd_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | struct corgikbd *corgikbd_data = dev_id; |
| 195 | |
| 196 | if (!timer_pending(&corgikbd_data->timer)) { |
| 197 | /** wait chattering delay **/ |
| 198 | udelay(20); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 199 | corgikbd_scankeyboard(corgikbd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | return IRQ_HANDLED; |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * corgi timer checking for released keys |
| 207 | */ |
| 208 | static void corgikbd_timer_callback(unsigned long data) |
| 209 | { |
| 210 | struct corgikbd *corgikbd_data = (struct corgikbd *) data; |
Russell King | 36bd262 | 2006-10-15 13:50:02 +0100 | [diff] [blame] | 211 | corgikbd_scankeyboard(corgikbd_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* |
| 215 | * The hinge switches generate no interrupt so they need to be |
| 216 | * monitored by a timer. |
| 217 | * |
Richard Purdie | 948e12f | 2005-09-06 15:19:00 -0700 | [diff] [blame] | 218 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | */ |
| 224 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 225 | #define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | #define HINGE_STABLE_COUNT 2 |
| 227 | static int sharpsl_hinge_state; |
| 228 | static int hinge_count; |
| 229 | |
| 230 | static 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 Purdie | aba5a4c | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 236 | 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] | 237 | gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | 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 Purdie | ed8f9e2 | 2006-05-29 23:31:03 -0400 | [diff] [blame] | 246 | 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 Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 249 | input_sync(corgikbd_data->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | spin_unlock_irqrestore(&corgikbd_data->lock, flags); |
| 252 | } |
| 253 | } |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 254 | mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 257 | #ifdef CONFIG_PM |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 258 | static int corgikbd_suspend(struct platform_device *dev, pm_message_t state) |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 259 | { |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 260 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 261 | struct corgikbd *corgikbd = platform_get_drvdata(dev); |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 262 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 263 | corgikbd->suspended = 1; |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 264 | /* 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 King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 268 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 272 | static int corgikbd_resume(struct platform_device *dev) |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 273 | { |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 274 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 275 | struct corgikbd *corgikbd = platform_get_drvdata(dev); |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 276 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 277 | 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 King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 280 | /* Upon resume, ignore the suspend key for a short while */ |
| 281 | corgikbd->suspend_jiffies=jiffies; |
| 282 | corgikbd->suspended = 0; |
| 283 | |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 284 | return 0; |
| 285 | } |
| 286 | #else |
| 287 | #define corgikbd_suspend NULL |
| 288 | #define corgikbd_resume NULL |
| 289 | #endif |
| 290 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 291 | static int __init corgikbd_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | struct corgikbd *corgikbd; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 294 | struct input_dev *input_dev; |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 295 | int i, err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Pekka Enberg | a97e148 | 2005-09-06 15:18:33 -0700 | [diff] [blame] | 297 | corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 298 | input_dev = input_allocate_device(); |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 299 | if (!corgikbd || !input_dev) |
| 300 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 302 | platform_set_drvdata(pdev, corgikbd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 304 | corgikbd->input = input_dev; |
Richard Purdie | aba5a4c | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 305 | spin_lock_init(&corgikbd->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 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 Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 317 | corgikbd->suspend_jiffies=jiffies; |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 321 | 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 Torokhov | 469ba4d | 2007-04-12 01:34:58 -0400 | [diff] [blame] | 327 | input_dev->dev.parent = &pdev->dev; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 328 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 329 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | |
| 330 | BIT_MASK(EV_PWR) | BIT_MASK(EV_SW); |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 331 | 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 Purdie | ed8f9e2 | 2006-05-29 23:31:03 -0400 | [diff] [blame] | 338 | 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 Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 341 | |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 342 | err = input_register_device(corgikbd->input); |
| 343 | if (err) |
| 344 | goto fail; |
Dmitry Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 345 | |
Richard Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 346 | mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 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 Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 352 | IRQF_DISABLED | IRQF_TRIGGER_RISING, |
Russell King | 9ded96f | 2006-01-08 01:02:07 -0800 | [diff] [blame] | 353 | "corgikbd", corgikbd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 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 Purdie | 4872f78 | 2006-03-14 00:12:32 -0500 | [diff] [blame] | 361 | /* Setup the headphone jack as an input */ |
| 362 | pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN); |
| 363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return 0; |
Dmitry Torokhov | 2b03b60 | 2006-11-05 22:39:56 -0500 | [diff] [blame] | 365 | |
| 366 | fail: input_free_device(input_dev); |
| 367 | kfree(corgikbd); |
| 368 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 371 | static int corgikbd_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
| 373 | int i; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 374 | struct corgikbd *corgikbd = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 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 Torokhov | 3c42f0c | 2005-09-15 02:01:45 -0500 | [diff] [blame] | 382 | input_unregister_device(corgikbd->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | kfree(corgikbd); |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 389 | static struct platform_driver corgikbd_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | .probe = corgikbd_probe, |
| 391 | .remove = corgikbd_remove, |
Richard Purdie | 8240a4a | 2005-09-06 15:18:59 -0700 | [diff] [blame] | 392 | .suspend = corgikbd_suspend, |
| 393 | .resume = corgikbd_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 394 | .driver = { |
| 395 | .name = "corgi-keyboard", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 396 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 397 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | }; |
| 399 | |
| 400 | static int __devinit corgikbd_init(void) |
| 401 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 402 | return platform_driver_register(&corgikbd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void __exit corgikbd_exit(void) |
| 406 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 407 | platform_driver_unregister(&corgikbd_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | module_init(corgikbd_init); |
| 411 | module_exit(corgikbd_exit); |
| 412 | |
| 413 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
| 414 | MODULE_DESCRIPTION("Corgi Keyboard Driver"); |
Al Viro | 839cd31 | 2008-05-21 06:32:11 +0100 | [diff] [blame] | 415 | MODULE_LICENSE("GPL v2"); |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 416 | MODULE_ALIAS("platform:corgi-keyboard"); |