Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 1 | /* |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 2 | * linux/drivers/input/keyboard/pxa27x_keypad.c |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 3 | * |
| 4 | * Driver for the pxa27x matrix keyboard controller. |
| 5 | * |
| 6 | * Created: Feb 22, 2007 |
| 7 | * Author: Rodolfo Giometti <giometti@linux.it> |
| 8 | * |
| 9 | * Based on a previous implementations by Kevin O'Connor |
| 10 | * <kevin_at_koconnor.net> and Alex Osborne <bobofdoom@gmail.com> and |
Nicolas Pitre | 2f82af0 | 2009-09-14 03:25:28 -0400 | [diff] [blame] | 11 | * on some suggestions by Nicolas Pitre <nico@fluxnic.net>. |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/input.h> |
| 24 | #include <linux/device.h> |
| 25 | #include <linux/platform_device.h> |
Russell King | 22d8a73 | 2007-08-20 10:19:39 +0100 | [diff] [blame] | 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 28 | #include <linux/input/matrix_keypad.h> |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 29 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 30 | #include <asm/mach/arch.h> |
| 31 | #include <asm/mach/map.h> |
| 32 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 33 | #include <mach/hardware.h> |
| 34 | #include <mach/pxa27x_keypad.h> |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 35 | /* |
| 36 | * Keypad Controller registers |
| 37 | */ |
| 38 | #define KPC 0x0000 /* Keypad Control register */ |
| 39 | #define KPDK 0x0008 /* Keypad Direct Key register */ |
| 40 | #define KPREC 0x0010 /* Keypad Rotary Encoder register */ |
| 41 | #define KPMK 0x0018 /* Keypad Matrix Key register */ |
| 42 | #define KPAS 0x0020 /* Keypad Automatic Scan register */ |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 43 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 44 | /* Keypad Automatic Scan Multiple Key Presser register 0-3 */ |
| 45 | #define KPASMKP0 0x0028 |
| 46 | #define KPASMKP1 0x0030 |
| 47 | #define KPASMKP2 0x0038 |
| 48 | #define KPASMKP3 0x0040 |
| 49 | #define KPKDI 0x0048 |
| 50 | |
| 51 | /* bit definitions */ |
Samuel Ortiz | 688dad4 | 2008-03-20 09:48:14 -0400 | [diff] [blame] | 52 | #define KPC_MKRN(n) ((((n) - 1) & 0x7) << 26) /* matrix key row number */ |
| 53 | #define KPC_MKCN(n) ((((n) - 1) & 0x7) << 23) /* matrix key column number */ |
| 54 | #define KPC_DKN(n) ((((n) - 1) & 0x7) << 6) /* direct key number */ |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 55 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 56 | #define KPC_AS (0x1 << 30) /* Automatic Scan bit */ |
| 57 | #define KPC_ASACT (0x1 << 29) /* Automatic Scan on Activity */ |
| 58 | #define KPC_MI (0x1 << 22) /* Matrix interrupt bit */ |
| 59 | #define KPC_IMKP (0x1 << 21) /* Ignore Multiple Key Press */ |
| 60 | |
| 61 | #define KPC_MS(n) (0x1 << (13 + (n))) /* Matrix scan line 'n' */ |
| 62 | #define KPC_MS_ALL (0xff << 13) |
| 63 | |
| 64 | #define KPC_ME (0x1 << 12) /* Matrix Keypad Enable */ |
| 65 | #define KPC_MIE (0x1 << 11) /* Matrix Interrupt Enable */ |
| 66 | #define KPC_DK_DEB_SEL (0x1 << 9) /* Direct Keypad Debounce Select */ |
| 67 | #define KPC_DI (0x1 << 5) /* Direct key interrupt bit */ |
| 68 | #define KPC_RE_ZERO_DEB (0x1 << 4) /* Rotary Encoder Zero Debounce */ |
| 69 | #define KPC_REE1 (0x1 << 3) /* Rotary Encoder1 Enable */ |
| 70 | #define KPC_REE0 (0x1 << 2) /* Rotary Encoder0 Enable */ |
| 71 | #define KPC_DE (0x1 << 1) /* Direct Keypad Enable */ |
| 72 | #define KPC_DIE (0x1 << 0) /* Direct Keypad interrupt Enable */ |
| 73 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 74 | #define KPDK_DKP (0x1 << 31) |
| 75 | #define KPDK_DK(n) ((n) & 0xff) |
| 76 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 77 | #define KPREC_OF1 (0x1 << 31) |
| 78 | #define kPREC_UF1 (0x1 << 30) |
| 79 | #define KPREC_OF0 (0x1 << 15) |
| 80 | #define KPREC_UF0 (0x1 << 14) |
| 81 | |
| 82 | #define KPREC_RECOUNT0(n) ((n) & 0xff) |
| 83 | #define KPREC_RECOUNT1(n) (((n) >> 16) & 0xff) |
| 84 | |
| 85 | #define KPMK_MKP (0x1 << 31) |
| 86 | #define KPAS_SO (0x1 << 31) |
| 87 | #define KPASMKPx_SO (0x1 << 31) |
| 88 | |
| 89 | #define KPAS_MUKP(n) (((n) >> 26) & 0x1f) |
| 90 | #define KPAS_RP(n) (((n) >> 4) & 0xf) |
| 91 | #define KPAS_CP(n) ((n) & 0xf) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 92 | |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 93 | #define KPASMKP_MKC_MASK (0xff) |
| 94 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 95 | #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) |
| 96 | #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) |
| 97 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 98 | #define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) |
| 99 | #define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 100 | |
| 101 | struct pxa27x_keypad { |
| 102 | struct pxa27x_keypad_platform_data *pdata; |
| 103 | |
| 104 | struct clk *clk; |
| 105 | struct input_dev *input_dev; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 106 | void __iomem *mmio_base; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 107 | |
Eric Miao | 39ab9dd | 2008-06-02 11:20:55 -0400 | [diff] [blame] | 108 | int irq; |
| 109 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 110 | unsigned short keycodes[MAX_KEYPAD_KEYS]; |
| 111 | int rotary_rel_code[2]; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 112 | |
| 113 | /* state row bits of each column scan */ |
| 114 | uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS]; |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 115 | uint32_t direct_key_state; |
| 116 | |
| 117 | unsigned int direct_key_mask; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static void pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) |
| 121 | { |
| 122 | struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
| 123 | struct input_dev *input_dev = keypad->input_dev; |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 124 | unsigned short keycode; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 125 | int i; |
| 126 | |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 127 | for (i = 0; i < pdata->matrix_key_map_size; i++) { |
| 128 | unsigned int key = pdata->matrix_key_map[i]; |
| 129 | unsigned int row = KEY_ROW(key); |
| 130 | unsigned int col = KEY_COL(key); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 131 | unsigned int scancode = MATRIX_SCAN_CODE(row, col, |
| 132 | MATRIX_ROW_SHIFT); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 133 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 134 | keycode = KEY_VAL(key); |
| 135 | keypad->keycodes[scancode] = keycode; |
| 136 | __set_bit(keycode, input_dev->keybit); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 137 | } |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 138 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 139 | for (i = 0; i < pdata->direct_key_num; i++) { |
| 140 | keycode = pdata->direct_key_map[i]; |
| 141 | keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; |
| 142 | __set_bit(keycode, input_dev->keybit); |
| 143 | } |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 144 | |
Antonio Ospite | 471637a | 2008-05-28 14:35:52 -0400 | [diff] [blame] | 145 | if (pdata->enable_rotary0) { |
| 146 | if (pdata->rotary0_up_key && pdata->rotary0_down_key) { |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 147 | keycode = pdata->rotary0_up_key; |
| 148 | keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; |
| 149 | __set_bit(keycode, input_dev->keybit); |
| 150 | |
| 151 | keycode = pdata->rotary0_down_key; |
| 152 | keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; |
| 153 | __set_bit(keycode, input_dev->keybit); |
| 154 | |
| 155 | keypad->rotary_rel_code[0] = -1; |
| 156 | } else { |
| 157 | keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 158 | __set_bit(pdata->rotary0_rel_code, input_dev->relbit); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 159 | } |
Antonio Ospite | 471637a | 2008-05-28 14:35:52 -0400 | [diff] [blame] | 160 | } |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 161 | |
Antonio Ospite | 471637a | 2008-05-28 14:35:52 -0400 | [diff] [blame] | 162 | if (pdata->enable_rotary1) { |
| 163 | if (pdata->rotary1_up_key && pdata->rotary1_down_key) { |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 164 | keycode = pdata->rotary1_up_key; |
| 165 | keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; |
| 166 | __set_bit(keycode, input_dev->keybit); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 167 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 168 | keycode = pdata->rotary1_down_key; |
| 169 | keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; |
| 170 | __set_bit(keycode, input_dev->keybit); |
| 171 | |
| 172 | keypad->rotary_rel_code[1] = -1; |
| 173 | } else { |
| 174 | keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; |
| 175 | __set_bit(pdata->rotary1_rel_code, input_dev->relbit); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | __clear_bit(KEY_RESERVED, input_dev->keybit); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) |
| 183 | { |
| 184 | struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 185 | struct input_dev *input_dev = keypad->input_dev; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 186 | int row, col, num_keys_pressed = 0; |
| 187 | uint32_t new_state[MAX_MATRIX_KEY_COLS]; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 188 | uint32_t kpas = keypad_readl(KPAS); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 189 | |
| 190 | num_keys_pressed = KPAS_MUKP(kpas); |
| 191 | |
| 192 | memset(new_state, 0, sizeof(new_state)); |
| 193 | |
| 194 | if (num_keys_pressed == 0) |
| 195 | goto scan; |
| 196 | |
| 197 | if (num_keys_pressed == 1) { |
| 198 | col = KPAS_CP(kpas); |
| 199 | row = KPAS_RP(kpas); |
| 200 | |
| 201 | /* if invalid row/col, treat as no key pressed */ |
| 202 | if (col >= pdata->matrix_key_cols || |
| 203 | row >= pdata->matrix_key_rows) |
| 204 | goto scan; |
| 205 | |
| 206 | new_state[col] = (1 << row); |
| 207 | goto scan; |
| 208 | } |
| 209 | |
| 210 | if (num_keys_pressed > 1) { |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 211 | uint32_t kpasmkp0 = keypad_readl(KPASMKP0); |
| 212 | uint32_t kpasmkp1 = keypad_readl(KPASMKP1); |
| 213 | uint32_t kpasmkp2 = keypad_readl(KPASMKP2); |
| 214 | uint32_t kpasmkp3 = keypad_readl(KPASMKP3); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 215 | |
| 216 | new_state[0] = kpasmkp0 & KPASMKP_MKC_MASK; |
| 217 | new_state[1] = (kpasmkp0 >> 16) & KPASMKP_MKC_MASK; |
| 218 | new_state[2] = kpasmkp1 & KPASMKP_MKC_MASK; |
| 219 | new_state[3] = (kpasmkp1 >> 16) & KPASMKP_MKC_MASK; |
| 220 | new_state[4] = kpasmkp2 & KPASMKP_MKC_MASK; |
| 221 | new_state[5] = (kpasmkp2 >> 16) & KPASMKP_MKC_MASK; |
| 222 | new_state[6] = kpasmkp3 & KPASMKP_MKC_MASK; |
| 223 | new_state[7] = (kpasmkp3 >> 16) & KPASMKP_MKC_MASK; |
| 224 | } |
| 225 | scan: |
| 226 | for (col = 0; col < pdata->matrix_key_cols; col++) { |
| 227 | uint32_t bits_changed; |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 228 | int code; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 229 | |
| 230 | bits_changed = keypad->matrix_key_state[col] ^ new_state[col]; |
| 231 | if (bits_changed == 0) |
| 232 | continue; |
| 233 | |
| 234 | for (row = 0; row < pdata->matrix_key_rows; row++) { |
| 235 | if ((bits_changed & (1 << row)) == 0) |
| 236 | continue; |
| 237 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 238 | code = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT); |
| 239 | input_event(input_dev, EV_MSC, MSC_SCAN, code); |
| 240 | input_report_key(input_dev, keypad->keycodes[code], |
| 241 | new_state[col] & (1 << row)); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 242 | } |
| 243 | } |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 244 | input_sync(input_dev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 245 | memcpy(keypad->matrix_key_state, new_state, sizeof(new_state)); |
| 246 | } |
Russell King | 22d8a73 | 2007-08-20 10:19:39 +0100 | [diff] [blame] | 247 | |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 248 | #define DEFAULT_KPREC (0x007f007f) |
| 249 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 250 | static inline int rotary_delta(uint32_t kprec) |
| 251 | { |
| 252 | if (kprec & KPREC_OF0) |
| 253 | return (kprec & 0xff) + 0x7f; |
| 254 | else if (kprec & KPREC_UF0) |
| 255 | return (kprec & 0xff) - 0x7f - 0xff; |
| 256 | else |
| 257 | return (kprec & 0xff) - 0x7f; |
| 258 | } |
| 259 | |
| 260 | static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) |
| 261 | { |
| 262 | struct input_dev *dev = keypad->input_dev; |
| 263 | |
| 264 | if (delta == 0) |
| 265 | return; |
| 266 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 267 | if (keypad->rotary_rel_code[r] == -1) { |
| 268 | int code = MAX_MATRIX_KEY_NUM + 2 * r + (delta > 0 ? 0 : 1); |
| 269 | unsigned char keycode = keypad->keycodes[code]; |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 270 | |
| 271 | /* simulate a press-n-release */ |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 272 | input_event(dev, EV_MSC, MSC_SCAN, code); |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 273 | input_report_key(dev, keycode, 1); |
| 274 | input_sync(dev); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 275 | input_event(dev, EV_MSC, MSC_SCAN, code); |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 276 | input_report_key(dev, keycode, 0); |
| 277 | input_sync(dev); |
| 278 | } else { |
| 279 | input_report_rel(dev, keypad->rotary_rel_code[r], delta); |
| 280 | input_sync(dev); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) |
| 285 | { |
| 286 | struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
| 287 | uint32_t kprec; |
| 288 | |
| 289 | /* read and reset to default count value */ |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 290 | kprec = keypad_readl(KPREC); |
| 291 | keypad_writel(KPREC, DEFAULT_KPREC); |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 292 | |
| 293 | if (pdata->enable_rotary0) |
| 294 | report_rotary_event(keypad, 0, rotary_delta(kprec)); |
| 295 | |
| 296 | if (pdata->enable_rotary1) |
| 297 | report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); |
| 298 | } |
| 299 | |
| 300 | static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) |
| 301 | { |
| 302 | struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 303 | struct input_dev *input_dev = keypad->input_dev; |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 304 | unsigned int new_state; |
| 305 | uint32_t kpdk, bits_changed; |
| 306 | int i; |
| 307 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 308 | kpdk = keypad_readl(KPDK); |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 309 | |
| 310 | if (pdata->enable_rotary0 || pdata->enable_rotary1) |
| 311 | pxa27x_keypad_scan_rotary(keypad); |
| 312 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 313 | new_state = KPDK_DK(kpdk) & keypad->direct_key_mask; |
| 314 | bits_changed = keypad->direct_key_state ^ new_state; |
| 315 | |
| 316 | if (bits_changed == 0) |
| 317 | return; |
| 318 | |
| 319 | for (i = 0; i < pdata->direct_key_num; i++) { |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 320 | if (bits_changed & (1 << i)) { |
| 321 | int code = MAX_MATRIX_KEY_NUM + i; |
| 322 | |
| 323 | input_event(input_dev, EV_MSC, MSC_SCAN, code); |
| 324 | input_report_key(input_dev, keypad->keycodes[code], |
| 325 | new_state & (1 << i)); |
| 326 | } |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 327 | } |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 328 | input_sync(input_dev); |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 329 | keypad->direct_key_state = new_state; |
| 330 | } |
| 331 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 332 | static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 333 | { |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 334 | struct pxa27x_keypad *keypad = dev_id; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 335 | unsigned long kpc = keypad_readl(KPC); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 336 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 337 | if (kpc & KPC_DI) |
| 338 | pxa27x_keypad_scan_direct(keypad); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 339 | |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 340 | if (kpc & KPC_MI) |
| 341 | pxa27x_keypad_scan_matrix(keypad); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 342 | |
| 343 | return IRQ_HANDLED; |
| 344 | } |
| 345 | |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 346 | static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) |
| 347 | { |
| 348 | struct pxa27x_keypad_platform_data *pdata = keypad->pdata; |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 349 | unsigned int mask = 0, direct_key_num = 0; |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 350 | unsigned long kpc = 0; |
| 351 | |
| 352 | /* enable matrix keys with automatic scan */ |
| 353 | if (pdata->matrix_key_rows && pdata->matrix_key_cols) { |
| 354 | kpc |= KPC_ASACT | KPC_MIE | KPC_ME | KPC_MS_ALL; |
| 355 | kpc |= KPC_MKRN(pdata->matrix_key_rows) | |
| 356 | KPC_MKCN(pdata->matrix_key_cols); |
| 357 | } |
| 358 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 359 | /* enable rotary key, debounce interval same as direct keys */ |
| 360 | if (pdata->enable_rotary0) { |
| 361 | mask |= 0x03; |
| 362 | direct_key_num = 2; |
| 363 | kpc |= KPC_REE0; |
| 364 | } |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 365 | |
Eric Miao | 62059d9 | 2008-01-31 00:59:03 -0500 | [diff] [blame] | 366 | if (pdata->enable_rotary1) { |
| 367 | mask |= 0x0c; |
| 368 | direct_key_num = 4; |
| 369 | kpc |= KPC_REE1; |
| 370 | } |
| 371 | |
| 372 | if (pdata->direct_key_num > direct_key_num) |
| 373 | direct_key_num = pdata->direct_key_num; |
| 374 | |
| 375 | keypad->direct_key_mask = ((2 << direct_key_num) - 1) & ~mask; |
| 376 | |
| 377 | /* enable direct key */ |
| 378 | if (direct_key_num) |
| 379 | kpc |= KPC_DE | KPC_DIE | KPC_DKN(direct_key_num); |
| 380 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 381 | keypad_writel(KPC, kpc | KPC_RE_ZERO_DEB); |
| 382 | keypad_writel(KPREC, DEFAULT_KPREC); |
Eric Miao | 76cb44e | 2008-01-31 00:59:23 -0500 | [diff] [blame] | 383 | keypad_writel(KPKDI, pdata->debounce_interval); |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 386 | static int pxa27x_keypad_open(struct input_dev *dev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 387 | { |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 388 | struct pxa27x_keypad *keypad = input_get_drvdata(dev); |
| 389 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 390 | /* Enable unit clock */ |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 391 | clk_enable(keypad->clk); |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 392 | pxa27x_keypad_config(keypad); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 397 | static void pxa27x_keypad_close(struct input_dev *dev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 398 | { |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 399 | struct pxa27x_keypad *keypad = input_get_drvdata(dev); |
| 400 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 401 | /* Disable clock unit */ |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 402 | clk_disable(keypad->clk); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | #ifdef CONFIG_PM |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 406 | static int pxa27x_keypad_suspend(struct device *dev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 407 | { |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 408 | struct platform_device *pdev = to_platform_device(dev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 409 | struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 410 | |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 411 | clk_disable(keypad->clk); |
Eric Miao | 39ab9dd | 2008-06-02 11:20:55 -0400 | [diff] [blame] | 412 | |
| 413 | if (device_may_wakeup(&pdev->dev)) |
| 414 | enable_irq_wake(keypad->irq); |
| 415 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 419 | static int pxa27x_keypad_resume(struct device *dev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 420 | { |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 421 | struct platform_device *pdev = to_platform_device(dev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 422 | struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 423 | struct input_dev *input_dev = keypad->input_dev; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 424 | |
Eric Miao | 39ab9dd | 2008-06-02 11:20:55 -0400 | [diff] [blame] | 425 | if (device_may_wakeup(&pdev->dev)) |
| 426 | disable_irq_wake(keypad->irq); |
| 427 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 428 | mutex_lock(&input_dev->mutex); |
| 429 | |
| 430 | if (input_dev->users) { |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 431 | /* Enable unit clock */ |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 432 | clk_enable(keypad->clk); |
Eric Miao | d7416f9 | 2008-01-31 00:58:52 -0500 | [diff] [blame] | 433 | pxa27x_keypad_config(keypad); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | mutex_unlock(&input_dev->mutex); |
| 437 | |
| 438 | return 0; |
| 439 | } |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 440 | |
| 441 | static const struct dev_pm_ops pxa27x_keypad_pm_ops = { |
| 442 | .suspend = pxa27x_keypad_suspend, |
| 443 | .resume = pxa27x_keypad_resume, |
| 444 | }; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 445 | #endif |
| 446 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 447 | static int __devinit pxa27x_keypad_probe(struct platform_device *pdev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 448 | { |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 449 | struct pxa27x_keypad_platform_data *pdata = pdev->dev.platform_data; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 450 | struct pxa27x_keypad *keypad; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 451 | struct input_dev *input_dev; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 452 | struct resource *res; |
| 453 | int irq, error; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 454 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 455 | if (pdata == NULL) { |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 456 | dev_err(&pdev->dev, "no platform data defined\n"); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 457 | return -EINVAL; |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 458 | } |
| 459 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 460 | irq = platform_get_irq(pdev, 0); |
| 461 | if (irq < 0) { |
| 462 | dev_err(&pdev->dev, "failed to get keypad irq\n"); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 463 | return -ENXIO; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 467 | if (res == NULL) { |
| 468 | dev_err(&pdev->dev, "failed to get I/O memory\n"); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 469 | return -ENXIO; |
| 470 | } |
| 471 | |
| 472 | keypad = kzalloc(sizeof(struct pxa27x_keypad), GFP_KERNEL); |
| 473 | input_dev = input_allocate_device(); |
| 474 | if (!keypad || !input_dev) { |
| 475 | dev_err(&pdev->dev, "failed to allocate memory\n"); |
| 476 | error = -ENOMEM; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 477 | goto failed_free; |
| 478 | } |
| 479 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 480 | keypad->pdata = pdata; |
| 481 | keypad->input_dev = input_dev; |
| 482 | keypad->irq = irq; |
| 483 | |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 484 | res = request_mem_region(res->start, resource_size(res), pdev->name); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 485 | if (res == NULL) { |
| 486 | dev_err(&pdev->dev, "failed to request I/O memory\n"); |
| 487 | error = -EBUSY; |
| 488 | goto failed_free; |
| 489 | } |
| 490 | |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 491 | keypad->mmio_base = ioremap(res->start, resource_size(res)); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 492 | if (keypad->mmio_base == NULL) { |
| 493 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); |
| 494 | error = -ENXIO; |
| 495 | goto failed_free_mem; |
| 496 | } |
| 497 | |
Russell King | e0d8b13 | 2008-11-11 17:52:32 +0000 | [diff] [blame] | 498 | keypad->clk = clk_get(&pdev->dev, NULL); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 499 | if (IS_ERR(keypad->clk)) { |
| 500 | dev_err(&pdev->dev, "failed to get keypad clock\n"); |
| 501 | error = PTR_ERR(keypad->clk); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 502 | goto failed_free_io; |
Russell King | 22d8a73 | 2007-08-20 10:19:39 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 505 | input_dev->name = pdev->name; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 506 | input_dev->id.bustype = BUS_HOST; |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 507 | input_dev->open = pxa27x_keypad_open; |
| 508 | input_dev->close = pxa27x_keypad_close; |
Dmitry Torokhov | 469ba4d | 2007-04-12 01:34:58 -0400 | [diff] [blame] | 509 | input_dev->dev.parent = &pdev->dev; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 510 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 511 | input_dev->keycode = keypad->keycodes; |
| 512 | input_dev->keycodesize = sizeof(keypad->keycodes[0]); |
| 513 | input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); |
| 514 | |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 515 | input_set_drvdata(input_dev, keypad); |
| 516 | |
Antonio Ospite | 471637a | 2008-05-28 14:35:52 -0400 | [diff] [blame] | 517 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 518 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 519 | |
| 520 | pxa27x_keypad_build_keycode(keypad); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 521 | |
| 522 | if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || |
| 523 | (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { |
| 524 | input_dev->evbit[0] |= BIT_MASK(EV_REL); |
| 525 | } |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 526 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 527 | error = request_irq(irq, pxa27x_keypad_irq_handler, IRQF_DISABLED, |
| 528 | pdev->name, keypad); |
| 529 | if (error) { |
| 530 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 531 | goto failed_put_clk; |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 534 | /* Register the input device */ |
| 535 | error = input_register_device(input_dev); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 536 | if (error) { |
| 537 | dev_err(&pdev->dev, "failed to register input device\n"); |
| 538 | goto failed_free_irq; |
| 539 | } |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 540 | |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 541 | platform_set_drvdata(pdev, keypad); |
Eric Miao | 39ab9dd | 2008-06-02 11:20:55 -0400 | [diff] [blame] | 542 | device_init_wakeup(&pdev->dev, 1); |
| 543 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 544 | return 0; |
| 545 | |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 546 | failed_free_irq: |
| 547 | free_irq(irq, pdev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 548 | failed_put_clk: |
| 549 | clk_put(keypad->clk); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 550 | failed_free_io: |
| 551 | iounmap(keypad->mmio_base); |
| 552 | failed_free_mem: |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 553 | release_mem_region(res->start, resource_size(res)); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 554 | failed_free: |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 555 | input_free_device(input_dev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 556 | kfree(keypad); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 557 | return error; |
| 558 | } |
| 559 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 560 | static int __devexit pxa27x_keypad_remove(struct platform_device *pdev) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 561 | { |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 562 | struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 563 | struct resource *res; |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 564 | |
Eric Miao | 39ab9dd | 2008-06-02 11:20:55 -0400 | [diff] [blame] | 565 | free_irq(keypad->irq, pdev); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 566 | clk_put(keypad->clk); |
| 567 | |
| 568 | input_unregister_device(keypad->input_dev); |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 569 | input_free_device(keypad->input_dev); |
| 570 | |
| 571 | iounmap(keypad->mmio_base); |
| 572 | |
| 573 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Dmitry Torokhov | 52ec775 | 2009-07-22 21:51:40 -0700 | [diff] [blame] | 574 | release_mem_region(res->start, resource_size(res)); |
Eric Miao | 1814db6 | 2008-01-31 00:58:37 -0500 | [diff] [blame] | 575 | |
| 576 | platform_set_drvdata(pdev, NULL); |
| 577 | kfree(keypad); |
Dmitry Torokhov | bd96f37 | 2009-09-04 23:46:18 -0700 | [diff] [blame] | 578 | |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 582 | /* work with hotplug and coldplug */ |
| 583 | MODULE_ALIAS("platform:pxa27x-keypad"); |
| 584 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 585 | static struct platform_driver pxa27x_keypad_driver = { |
| 586 | .probe = pxa27x_keypad_probe, |
| 587 | .remove = __devexit_p(pxa27x_keypad_remove), |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 588 | .driver = { |
Eric Miao | 9c60deb | 2008-01-31 00:59:15 -0500 | [diff] [blame] | 589 | .name = "pxa27x-keypad", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 590 | .owner = THIS_MODULE, |
Dmitry Torokhov | b001091 | 2009-07-24 22:01:43 -0700 | [diff] [blame] | 591 | #ifdef CONFIG_PM |
| 592 | .pm = &pxa27x_keypad_pm_ops, |
| 593 | #endif |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 594 | }, |
| 595 | }; |
| 596 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 597 | static int __init pxa27x_keypad_init(void) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 598 | { |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 599 | return platform_driver_register(&pxa27x_keypad_driver); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 602 | static void __exit pxa27x_keypad_exit(void) |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 603 | { |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 604 | platform_driver_unregister(&pxa27x_keypad_driver); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 605 | } |
| 606 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 607 | module_init(pxa27x_keypad_init); |
| 608 | module_exit(pxa27x_keypad_exit); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 609 | |
Eric Miao | 0e5f11a | 2008-01-31 00:56:46 -0500 | [diff] [blame] | 610 | MODULE_DESCRIPTION("PXA27x Keypad Controller Driver"); |
Rodolfo Giometti | 5a90e5b | 2007-03-16 00:58:52 -0400 | [diff] [blame] | 611 | MODULE_LICENSE("GPL"); |