Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP4 Keypad Driver |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments |
| 5 | * |
| 6 | * Author: Abraham Arce <x0066660@ti.com> |
| 7 | * Initial Code: Syed Rafiuddin <rafiuddin.syed@ti.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/io.h> |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 30 | #include <linux/of.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 31 | #include <linux/input.h> |
| 32 | #include <linux/slab.h> |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 34 | |
Felipe Balbi | 0f1142a | 2012-03-16 22:47:48 -0700 | [diff] [blame] | 35 | #include <linux/platform_data/omap4-keypad.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 36 | |
| 37 | /* OMAP4 registers */ |
| 38 | #define OMAP4_KBD_REVISION 0x00 |
| 39 | #define OMAP4_KBD_SYSCONFIG 0x10 |
| 40 | #define OMAP4_KBD_SYSSTATUS 0x14 |
| 41 | #define OMAP4_KBD_IRQSTATUS 0x18 |
| 42 | #define OMAP4_KBD_IRQENABLE 0x1C |
| 43 | #define OMAP4_KBD_WAKEUPENABLE 0x20 |
| 44 | #define OMAP4_KBD_PENDING 0x24 |
| 45 | #define OMAP4_KBD_CTRL 0x28 |
| 46 | #define OMAP4_KBD_DEBOUNCINGTIME 0x2C |
| 47 | #define OMAP4_KBD_LONGKEYTIME 0x30 |
| 48 | #define OMAP4_KBD_TIMEOUT 0x34 |
| 49 | #define OMAP4_KBD_STATEMACHINE 0x38 |
| 50 | #define OMAP4_KBD_ROWINPUTS 0x3C |
| 51 | #define OMAP4_KBD_COLUMNOUTPUTS 0x40 |
| 52 | #define OMAP4_KBD_FULLCODE31_0 0x44 |
| 53 | #define OMAP4_KBD_FULLCODE63_32 0x48 |
| 54 | |
| 55 | /* OMAP4 bit definitions */ |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 56 | #define OMAP4_DEF_IRQENABLE_EVENTEN (1 << 0) |
| 57 | #define OMAP4_DEF_IRQENABLE_LONGKEY (1 << 1) |
| 58 | #define OMAP4_DEF_IRQENABLE_TIMEOUTEN (1 << 2) |
Mike Turquette | 9a34bc6 | 2010-09-29 23:38:01 -0700 | [diff] [blame] | 59 | #define OMAP4_DEF_WUP_EVENT_ENA (1 << 0) |
| 60 | #define OMAP4_DEF_WUP_LONG_KEY_ENA (1 << 1) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 61 | #define OMAP4_DEF_CTRL_NOSOFTMODE (1 << 1) |
| 62 | #define OMAP4_DEF_CTRLPTVVALUE (1 << 2) |
| 63 | #define OMAP4_DEF_CTRLPTV (1 << 1) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 64 | |
| 65 | /* OMAP4 values */ |
Abraham Arce | 05362f4 | 2010-09-29 23:36:48 -0700 | [diff] [blame] | 66 | #define OMAP4_VAL_IRQDISABLE 0x00 |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 67 | #define OMAP4_VAL_DEBOUNCINGTIME 0x07 |
| 68 | #define OMAP4_VAL_FUNCTIONALCFG 0x1E |
| 69 | |
| 70 | #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF |
| 71 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 72 | enum { |
| 73 | KBD_REVISION_OMAP4 = 0, |
| 74 | KBD_REVISION_OMAP5, |
| 75 | }; |
| 76 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 77 | struct omap4_keypad { |
| 78 | struct input_dev *input; |
| 79 | |
| 80 | void __iomem *base; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 81 | unsigned int irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 82 | |
| 83 | unsigned int rows; |
| 84 | unsigned int cols; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 85 | u32 reg_offset; |
| 86 | u32 irqreg_offset; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 87 | unsigned int row_shift; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 88 | bool no_autorepeat; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 89 | unsigned char key_state[8]; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 90 | unsigned short *keymap; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 93 | static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset) |
| 94 | { |
| 95 | return __raw_readl(keypad_data->base + |
| 96 | keypad_data->reg_offset + offset); |
| 97 | } |
| 98 | |
| 99 | static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value) |
| 100 | { |
| 101 | __raw_writel(value, |
| 102 | keypad_data->base + keypad_data->reg_offset + offset); |
| 103 | } |
| 104 | |
| 105 | static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset) |
| 106 | { |
| 107 | return __raw_readl(keypad_data->base + |
| 108 | keypad_data->irqreg_offset + offset); |
| 109 | } |
| 110 | |
| 111 | static void kbd_write_irqreg(struct omap4_keypad *keypad_data, |
| 112 | u32 offset, u32 value) |
| 113 | { |
| 114 | __raw_writel(value, |
| 115 | keypad_data->base + keypad_data->irqreg_offset + offset); |
| 116 | } |
| 117 | |
| 118 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 119 | /* Interrupt handler */ |
| 120 | static irqreturn_t omap4_keypad_interrupt(int irq, void *dev_id) |
| 121 | { |
| 122 | struct omap4_keypad *keypad_data = dev_id; |
| 123 | struct input_dev *input_dev = keypad_data->input; |
| 124 | unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)]; |
| 125 | unsigned int col, row, code, changed; |
| 126 | u32 *new_state = (u32 *) key_state; |
| 127 | |
| 128 | /* Disable interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 129 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 130 | OMAP4_VAL_IRQDISABLE); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 131 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 132 | *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0); |
| 133 | *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 134 | |
| 135 | for (row = 0; row < keypad_data->rows; row++) { |
| 136 | changed = key_state[row] ^ keypad_data->key_state[row]; |
| 137 | if (!changed) |
| 138 | continue; |
| 139 | |
| 140 | for (col = 0; col < keypad_data->cols; col++) { |
| 141 | if (changed & (1 << col)) { |
| 142 | code = MATRIX_SCAN_CODE(row, col, |
| 143 | keypad_data->row_shift); |
| 144 | input_event(input_dev, EV_MSC, MSC_SCAN, code); |
| 145 | input_report_key(input_dev, |
| 146 | keypad_data->keymap[code], |
| 147 | key_state[row] & (1 << col)); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | input_sync(input_dev); |
| 153 | |
| 154 | memcpy(keypad_data->key_state, key_state, |
| 155 | sizeof(keypad_data->key_state)); |
| 156 | |
| 157 | /* clear pending interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 158 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
| 159 | kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 160 | |
| 161 | /* enable interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 162 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 163 | OMAP4_DEF_IRQENABLE_EVENTEN | |
| 164 | OMAP4_DEF_IRQENABLE_LONGKEY); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 165 | |
| 166 | return IRQ_HANDLED; |
| 167 | } |
| 168 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 169 | static int omap4_keypad_open(struct input_dev *input) |
| 170 | { |
| 171 | struct omap4_keypad *keypad_data = input_get_drvdata(input); |
| 172 | |
| 173 | pm_runtime_get_sync(input->dev.parent); |
| 174 | |
| 175 | disable_irq(keypad_data->irq); |
| 176 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 177 | kbd_writel(keypad_data, OMAP4_KBD_CTRL, |
| 178 | OMAP4_VAL_FUNCTIONALCFG); |
| 179 | kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME, |
| 180 | OMAP4_VAL_DEBOUNCINGTIME); |
| 181 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
| 182 | OMAP4_VAL_IRQDISABLE); |
| 183 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 184 | OMAP4_DEF_IRQENABLE_EVENTEN | |
| 185 | OMAP4_DEF_IRQENABLE_LONGKEY); |
| 186 | kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE, |
| 187 | OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 188 | |
| 189 | enable_irq(keypad_data->irq); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static void omap4_keypad_close(struct input_dev *input) |
| 195 | { |
| 196 | struct omap4_keypad *keypad_data = input_get_drvdata(input); |
| 197 | |
| 198 | disable_irq(keypad_data->irq); |
| 199 | |
| 200 | /* Disable interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 201 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 202 | OMAP4_VAL_IRQDISABLE); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 203 | |
| 204 | /* clear pending interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 205 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
| 206 | kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 207 | |
| 208 | enable_irq(keypad_data->irq); |
| 209 | |
| 210 | pm_runtime_put_sync(input->dev.parent); |
| 211 | } |
| 212 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 213 | #ifdef CONFIG_OF |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 214 | static int omap4_keypad_parse_dt(struct device *dev, |
| 215 | struct omap4_keypad *keypad_data) |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 216 | { |
| 217 | struct device_node *np = dev->of_node; |
Simon Glass | 4384041 | 2013-02-25 14:08:40 -0800 | [diff] [blame] | 218 | int err; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 219 | |
Simon Glass | 4384041 | 2013-02-25 14:08:40 -0800 | [diff] [blame] | 220 | err = matrix_keypad_parse_of_params(dev, &keypad_data->rows, |
| 221 | &keypad_data->cols); |
| 222 | if (err) |
| 223 | return err; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 224 | |
| 225 | if (of_get_property(np, "linux,input-no-autorepeat", NULL)) |
| 226 | keypad_data->no_autorepeat = true; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | #else |
| 231 | static inline int omap4_keypad_parse_dt(struct device *dev, |
| 232 | struct omap4_keypad *keypad_data) |
| 233 | { |
| 234 | return -ENOSYS; |
| 235 | } |
| 236 | #endif |
| 237 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 238 | static int omap4_keypad_probe(struct platform_device *pdev) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 239 | { |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 240 | const struct omap4_keypad_platform_data *pdata = |
| 241 | dev_get_platdata(&pdev->dev); |
| 242 | const struct matrix_keymap_data *keymap_data = |
| 243 | pdata ? pdata->keymap_data : NULL; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 244 | struct omap4_keypad *keypad_data; |
| 245 | struct input_dev *input_dev; |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 246 | struct resource *res; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 247 | unsigned int max_keys; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 248 | int rev; |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 249 | int irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 250 | int error; |
| 251 | |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 252 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 253 | if (!res) { |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 254 | dev_err(&pdev->dev, "no base address specified\n"); |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 258 | irq = platform_get_irq(pdev, 0); |
| 259 | if (!irq) { |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 260 | dev_err(&pdev->dev, "no keyboard irq assigned\n"); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 264 | keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 265 | if (!keypad_data) { |
| 266 | dev_err(&pdev->dev, "keypad_data memory allocation failed\n"); |
| 267 | return -ENOMEM; |
| 268 | } |
| 269 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 270 | keypad_data->irq = irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 271 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 272 | if (pdata) { |
| 273 | keypad_data->rows = pdata->rows; |
| 274 | keypad_data->cols = pdata->cols; |
| 275 | } else { |
| 276 | error = omap4_keypad_parse_dt(&pdev->dev, keypad_data); |
| 277 | if (error) |
| 278 | return error; |
| 279 | } |
| 280 | |
| 281 | res = request_mem_region(res->start, resource_size(res), pdev->name); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 282 | if (!res) { |
| 283 | dev_err(&pdev->dev, "can't request mem region\n"); |
| 284 | error = -EBUSY; |
| 285 | goto err_free_keypad; |
| 286 | } |
| 287 | |
| 288 | keypad_data->base = ioremap(res->start, resource_size(res)); |
| 289 | if (!keypad_data->base) { |
| 290 | dev_err(&pdev->dev, "can't ioremap mem resource\n"); |
| 291 | error = -ENOMEM; |
| 292 | goto err_release_mem; |
| 293 | } |
| 294 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 295 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 296 | /* |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 297 | * Enable clocks for the keypad module so that we can read |
| 298 | * revision register. |
| 299 | */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 300 | pm_runtime_enable(&pdev->dev); |
| 301 | error = pm_runtime_get_sync(&pdev->dev); |
| 302 | if (error) { |
| 303 | dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); |
| 304 | goto err_unmap; |
| 305 | } |
| 306 | rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION); |
| 307 | rev &= 0x03 << 30; |
| 308 | rev >>= 30; |
| 309 | switch (rev) { |
| 310 | case KBD_REVISION_OMAP4: |
| 311 | keypad_data->reg_offset = 0x00; |
| 312 | keypad_data->irqreg_offset = 0x00; |
| 313 | break; |
| 314 | case KBD_REVISION_OMAP5: |
| 315 | keypad_data->reg_offset = 0x10; |
| 316 | keypad_data->irqreg_offset = 0x0c; |
| 317 | break; |
| 318 | default: |
| 319 | dev_err(&pdev->dev, |
| 320 | "Keypad reports unsupported revision %d", rev); |
| 321 | error = -EINVAL; |
| 322 | goto err_pm_put_sync; |
| 323 | } |
| 324 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 325 | /* input device allocation */ |
| 326 | keypad_data->input = input_dev = input_allocate_device(); |
| 327 | if (!input_dev) { |
| 328 | error = -ENOMEM; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 329 | goto err_pm_put_sync; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | input_dev->name = pdev->name; |
| 333 | input_dev->dev.parent = &pdev->dev; |
| 334 | input_dev->id.bustype = BUS_HOST; |
| 335 | input_dev->id.vendor = 0x0001; |
| 336 | input_dev->id.product = 0x0001; |
| 337 | input_dev->id.version = 0x0001; |
| 338 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 339 | input_dev->open = omap4_keypad_open; |
| 340 | input_dev->close = omap4_keypad_close; |
| 341 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 342 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); |
| 343 | if (!keypad_data->no_autorepeat) |
| 344 | __set_bit(EV_REP, input_dev->evbit); |
| 345 | |
| 346 | input_set_drvdata(input_dev, keypad_data); |
| 347 | |
| 348 | keypad_data->row_shift = get_count_order(keypad_data->cols); |
| 349 | max_keys = keypad_data->rows << keypad_data->row_shift; |
| 350 | keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]), |
| 351 | GFP_KERNEL); |
| 352 | if (!keypad_data->keymap) { |
| 353 | dev_err(&pdev->dev, "Not enough memory for keymap\n"); |
| 354 | error = -ENOMEM; |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 355 | goto err_free_input; |
| 356 | } |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 357 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 358 | error = matrix_keypad_build_keymap(keymap_data, NULL, |
| 359 | keypad_data->rows, keypad_data->cols, |
| 360 | keypad_data->keymap, input_dev); |
| 361 | if (error) { |
| 362 | dev_err(&pdev->dev, "failed to build keymap\n"); |
| 363 | goto err_free_keymap; |
| 364 | } |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 365 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 366 | error = request_irq(keypad_data->irq, omap4_keypad_interrupt, |
Abraham Arce | f8038c4 | 2010-09-29 23:37:04 -0700 | [diff] [blame] | 367 | IRQF_TRIGGER_RISING, |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 368 | "omap4-keypad", keypad_data); |
| 369 | if (error) { |
| 370 | dev_err(&pdev->dev, "failed to register interrupt\n"); |
| 371 | goto err_free_input; |
| 372 | } |
| 373 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 374 | pm_runtime_put_sync(&pdev->dev); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 375 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 376 | error = input_register_device(keypad_data->input); |
| 377 | if (error < 0) { |
| 378 | dev_err(&pdev->dev, "failed to register input device\n"); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 379 | goto err_pm_disable; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 382 | platform_set_drvdata(pdev, keypad_data); |
| 383 | return 0; |
| 384 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 385 | err_pm_disable: |
| 386 | pm_runtime_disable(&pdev->dev); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 387 | free_irq(keypad_data->irq, keypad_data); |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 388 | err_free_keymap: |
| 389 | kfree(keypad_data->keymap); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 390 | err_free_input: |
| 391 | input_free_device(input_dev); |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 392 | err_pm_put_sync: |
| 393 | pm_runtime_put_sync(&pdev->dev); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 394 | err_unmap: |
| 395 | iounmap(keypad_data->base); |
| 396 | err_release_mem: |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 397 | release_mem_region(res->start, resource_size(res)); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 398 | err_free_keypad: |
| 399 | kfree(keypad_data); |
| 400 | return error; |
| 401 | } |
| 402 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 403 | static int omap4_keypad_remove(struct platform_device *pdev) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 404 | { |
| 405 | struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 406 | struct resource *res; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 407 | |
| 408 | free_irq(keypad_data->irq, keypad_data); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 409 | |
| 410 | pm_runtime_disable(&pdev->dev); |
| 411 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 412 | input_unregister_device(keypad_data->input); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 413 | |
| 414 | iounmap(keypad_data->base); |
| 415 | |
| 416 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 417 | release_mem_region(res->start, resource_size(res)); |
| 418 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 419 | kfree(keypad_data->keymap); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 420 | kfree(keypad_data); |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 421 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 422 | return 0; |
| 423 | } |
| 424 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 425 | #ifdef CONFIG_OF |
| 426 | static const struct of_device_id omap_keypad_dt_match[] = { |
| 427 | { .compatible = "ti,omap4-keypad" }, |
| 428 | {}, |
| 429 | }; |
| 430 | MODULE_DEVICE_TABLE(of, omap_keypad_dt_match); |
| 431 | #endif |
| 432 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 433 | static struct platform_driver omap4_keypad_driver = { |
| 434 | .probe = omap4_keypad_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 435 | .remove = omap4_keypad_remove, |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 436 | .driver = { |
| 437 | .name = "omap4-keypad", |
| 438 | .owner = THIS_MODULE, |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 439 | .of_match_table = of_match_ptr(omap_keypad_dt_match), |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 440 | }, |
| 441 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 442 | module_platform_driver(omap4_keypad_driver); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 443 | |
| 444 | MODULE_AUTHOR("Texas Instruments"); |
| 445 | MODULE_DESCRIPTION("OMAP4 Keypad Driver"); |
| 446 | MODULE_LICENSE("GPL"); |
| 447 | MODULE_ALIAS("platform:omap4-keypad"); |