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