H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Cirrus EP93xx matrix keypad controller. |
| 3 | * |
| 4 | * Copyright (c) 2008 H Hartley Sweeten <hsweeten@visionengravers.com> |
| 5 | * |
| 6 | * Based on the pxa27x matrix keypad controller by Rodolfo Giometti. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * NOTE: |
| 13 | * |
| 14 | * The 3-key reset is triggered by pressing the 3 keys in |
| 15 | * Row 0, Columns 2, 4, and 7 at the same time. This action can |
| 16 | * be disabled by setting the EP93XX_KEYPAD_DISABLE_3_KEY flag. |
| 17 | * |
| 18 | * Normal operation for the matrix does not autorepeat the key press. |
| 19 | * This action can be enabled by setting the EP93XX_KEYPAD_AUTOREPEAT |
| 20 | * flag. |
| 21 | */ |
| 22 | |
Axel Lin | b9cc510 | 2011-08-21 12:48:08 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/interrupt.h> |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 26 | #include <linux/clk.h> |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 27 | #include <linux/io.h> |
| 28 | #include <linux/input/matrix_keypad.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 30 | |
| 31 | #include <mach/hardware.h> |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 32 | #include <mach/ep93xx_keypad.h> |
| 33 | |
| 34 | /* |
| 35 | * Keypad Interface Register offsets |
| 36 | */ |
| 37 | #define KEY_INIT 0x00 /* Key Scan Initialization register */ |
| 38 | #define KEY_DIAG 0x04 /* Key Scan Diagnostic register */ |
| 39 | #define KEY_REG 0x08 /* Key Value Capture register */ |
| 40 | |
| 41 | /* Key Scan Initialization Register bit defines */ |
| 42 | #define KEY_INIT_DBNC_MASK (0x00ff0000) |
| 43 | #define KEY_INIT_DBNC_SHIFT (16) |
| 44 | #define KEY_INIT_DIS3KY (1<<15) |
| 45 | #define KEY_INIT_DIAG (1<<14) |
| 46 | #define KEY_INIT_BACK (1<<13) |
| 47 | #define KEY_INIT_T2 (1<<12) |
| 48 | #define KEY_INIT_PRSCL_MASK (0x000003ff) |
| 49 | #define KEY_INIT_PRSCL_SHIFT (0) |
| 50 | |
| 51 | /* Key Scan Diagnostic Register bit defines */ |
| 52 | #define KEY_DIAG_MASK (0x0000003f) |
| 53 | #define KEY_DIAG_SHIFT (0) |
| 54 | |
| 55 | /* Key Value Capture Register bit defines */ |
| 56 | #define KEY_REG_K (1<<15) |
| 57 | #define KEY_REG_INT (1<<14) |
| 58 | #define KEY_REG_2KEYS (1<<13) |
| 59 | #define KEY_REG_1KEY (1<<12) |
| 60 | #define KEY_REG_KEY2_MASK (0x00000fc0) |
| 61 | #define KEY_REG_KEY2_SHIFT (6) |
| 62 | #define KEY_REG_KEY1_MASK (0x0000003f) |
| 63 | #define KEY_REG_KEY1_SHIFT (0) |
| 64 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 65 | #define EP93XX_MATRIX_SIZE (EP93XX_MATRIX_ROWS * EP93XX_MATRIX_COLS) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 66 | |
| 67 | struct ep93xx_keypad { |
| 68 | struct ep93xx_keypad_platform_data *pdata; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 69 | struct input_dev *input_dev; |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 70 | struct clk *clk; |
| 71 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 72 | void __iomem *mmio_base; |
| 73 | |
H Hartley Sweeten | a5abd95 | 2010-01-13 00:34:12 -0800 | [diff] [blame] | 74 | unsigned short keycodes[EP93XX_MATRIX_SIZE]; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 75 | |
| 76 | int key1; |
| 77 | int key2; |
| 78 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 79 | int irq; |
| 80 | |
| 81 | bool enabled; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 84 | static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id) |
| 85 | { |
| 86 | struct ep93xx_keypad *keypad = dev_id; |
| 87 | struct input_dev *input_dev = keypad->input_dev; |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 88 | unsigned int status; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 89 | int keycode, key1, key2; |
| 90 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 91 | status = __raw_readl(keypad->mmio_base + KEY_REG); |
| 92 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 93 | keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT; |
H Hartley Sweeten | a5abd95 | 2010-01-13 00:34:12 -0800 | [diff] [blame] | 94 | key1 = keypad->keycodes[keycode]; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 95 | |
| 96 | keycode = (status & KEY_REG_KEY2_MASK) >> KEY_REG_KEY2_SHIFT; |
H Hartley Sweeten | a5abd95 | 2010-01-13 00:34:12 -0800 | [diff] [blame] | 97 | key2 = keypad->keycodes[keycode]; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 98 | |
| 99 | if (status & KEY_REG_2KEYS) { |
| 100 | if (keypad->key1 && key1 != keypad->key1 && key2 != keypad->key1) |
| 101 | input_report_key(input_dev, keypad->key1, 0); |
| 102 | |
| 103 | if (keypad->key2 && key1 != keypad->key2 && key2 != keypad->key2) |
| 104 | input_report_key(input_dev, keypad->key2, 0); |
| 105 | |
| 106 | input_report_key(input_dev, key1, 1); |
| 107 | input_report_key(input_dev, key2, 1); |
| 108 | |
| 109 | keypad->key1 = key1; |
| 110 | keypad->key2 = key2; |
| 111 | |
| 112 | } else if (status & KEY_REG_1KEY) { |
| 113 | if (keypad->key1 && key1 != keypad->key1) |
| 114 | input_report_key(input_dev, keypad->key1, 0); |
| 115 | |
| 116 | if (keypad->key2 && key1 != keypad->key2) |
| 117 | input_report_key(input_dev, keypad->key2, 0); |
| 118 | |
| 119 | input_report_key(input_dev, key1, 1); |
| 120 | |
| 121 | keypad->key1 = key1; |
| 122 | keypad->key2 = 0; |
| 123 | |
| 124 | } else { |
| 125 | input_report_key(input_dev, keypad->key1, 0); |
| 126 | input_report_key(input_dev, keypad->key2, 0); |
| 127 | |
| 128 | keypad->key1 = keypad->key2 = 0; |
| 129 | } |
| 130 | input_sync(input_dev); |
| 131 | |
| 132 | return IRQ_HANDLED; |
| 133 | } |
| 134 | |
| 135 | static void ep93xx_keypad_config(struct ep93xx_keypad *keypad) |
| 136 | { |
| 137 | struct ep93xx_keypad_platform_data *pdata = keypad->pdata; |
| 138 | unsigned int val = 0; |
| 139 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 140 | if (pdata->flags & EP93XX_KEYPAD_KDIV) |
| 141 | clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV4); |
| 142 | else |
| 143 | clk_set_rate(keypad->clk, EP93XX_KEYTCHCLK_DIV16); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 144 | |
| 145 | if (pdata->flags & EP93XX_KEYPAD_DISABLE_3_KEY) |
| 146 | val |= KEY_INIT_DIS3KY; |
| 147 | if (pdata->flags & EP93XX_KEYPAD_DIAG_MODE) |
| 148 | val |= KEY_INIT_DIAG; |
| 149 | if (pdata->flags & EP93XX_KEYPAD_BACK_DRIVE) |
| 150 | val |= KEY_INIT_BACK; |
| 151 | if (pdata->flags & EP93XX_KEYPAD_TEST_MODE) |
| 152 | val |= KEY_INIT_T2; |
| 153 | |
| 154 | val |= ((pdata->debounce << KEY_INIT_DBNC_SHIFT) & KEY_INIT_DBNC_MASK); |
| 155 | |
| 156 | val |= ((pdata->prescale << KEY_INIT_PRSCL_SHIFT) & KEY_INIT_PRSCL_MASK); |
| 157 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 158 | __raw_writel(val, keypad->mmio_base + KEY_INIT); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static int ep93xx_keypad_open(struct input_dev *pdev) |
| 162 | { |
| 163 | struct ep93xx_keypad *keypad = input_get_drvdata(pdev); |
| 164 | |
| 165 | if (!keypad->enabled) { |
| 166 | ep93xx_keypad_config(keypad); |
| 167 | clk_enable(keypad->clk); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 168 | keypad->enabled = true; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static void ep93xx_keypad_close(struct input_dev *pdev) |
| 175 | { |
| 176 | struct ep93xx_keypad *keypad = input_get_drvdata(pdev); |
| 177 | |
| 178 | if (keypad->enabled) { |
| 179 | clk_disable(keypad->clk); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 180 | keypad->enabled = false; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 185 | #ifdef CONFIG_PM_SLEEP |
| 186 | static int ep93xx_keypad_suspend(struct device *dev) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 187 | { |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 188 | struct platform_device *pdev = to_platform_device(dev); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 189 | struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); |
| 190 | struct input_dev *input_dev = keypad->input_dev; |
| 191 | |
| 192 | mutex_lock(&input_dev->mutex); |
| 193 | |
| 194 | if (keypad->enabled) { |
| 195 | clk_disable(keypad->clk); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 196 | keypad->enabled = false; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | mutex_unlock(&input_dev->mutex); |
| 200 | |
| 201 | if (device_may_wakeup(&pdev->dev)) |
| 202 | enable_irq_wake(keypad->irq); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 207 | static int ep93xx_keypad_resume(struct device *dev) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 208 | { |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 209 | struct platform_device *pdev = to_platform_device(dev); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 210 | struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); |
| 211 | struct input_dev *input_dev = keypad->input_dev; |
| 212 | |
| 213 | if (device_may_wakeup(&pdev->dev)) |
| 214 | disable_irq_wake(keypad->irq); |
| 215 | |
| 216 | mutex_lock(&input_dev->mutex); |
| 217 | |
| 218 | if (input_dev->users) { |
| 219 | if (!keypad->enabled) { |
| 220 | ep93xx_keypad_config(keypad); |
| 221 | clk_enable(keypad->clk); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 222 | keypad->enabled = true; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | mutex_unlock(&input_dev->mutex); |
| 227 | |
| 228 | return 0; |
| 229 | } |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 230 | #endif |
| 231 | |
| 232 | static SIMPLE_DEV_PM_OPS(ep93xx_keypad_pm_ops, |
| 233 | ep93xx_keypad_suspend, ep93xx_keypad_resume); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 234 | |
| 235 | static int __devinit ep93xx_keypad_probe(struct platform_device *pdev) |
| 236 | { |
| 237 | struct ep93xx_keypad *keypad; |
H Hartley Sweeten | a5abd95 | 2010-01-13 00:34:12 -0800 | [diff] [blame] | 238 | const struct matrix_keymap_data *keymap_data; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 239 | struct input_dev *input_dev; |
| 240 | struct resource *res; |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 241 | int err; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 242 | |
| 243 | keypad = kzalloc(sizeof(struct ep93xx_keypad), GFP_KERNEL); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 244 | if (!keypad) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 245 | return -ENOMEM; |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 246 | |
| 247 | keypad->pdata = pdev->dev.platform_data; |
| 248 | if (!keypad->pdata) { |
| 249 | err = -EINVAL; |
| 250 | goto failed_free; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 251 | } |
| 252 | |
H Hartley Sweeten | a5abd95 | 2010-01-13 00:34:12 -0800 | [diff] [blame] | 253 | keymap_data = keypad->pdata->keymap_data; |
| 254 | if (!keymap_data) { |
| 255 | err = -EINVAL; |
| 256 | goto failed_free; |
| 257 | } |
| 258 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 259 | keypad->irq = platform_get_irq(pdev, 0); |
| 260 | if (!keypad->irq) { |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 261 | err = -ENXIO; |
| 262 | goto failed_free; |
| 263 | } |
| 264 | |
| 265 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 266 | if (!res) { |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 267 | err = -ENXIO; |
| 268 | goto failed_free; |
| 269 | } |
| 270 | |
| 271 | res = request_mem_region(res->start, resource_size(res), pdev->name); |
| 272 | if (!res) { |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 273 | err = -EBUSY; |
| 274 | goto failed_free; |
| 275 | } |
| 276 | |
| 277 | keypad->mmio_base = ioremap(res->start, resource_size(res)); |
| 278 | if (keypad->mmio_base == NULL) { |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 279 | err = -ENXIO; |
| 280 | goto failed_free_mem; |
| 281 | } |
| 282 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 283 | err = ep93xx_keypad_acquire_gpio(pdev); |
| 284 | if (err) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 285 | goto failed_free_io; |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 286 | |
| 287 | keypad->clk = clk_get(&pdev->dev, NULL); |
| 288 | if (IS_ERR(keypad->clk)) { |
| 289 | err = PTR_ERR(keypad->clk); |
| 290 | goto failed_free_gpio; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 291 | } |
| 292 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 293 | input_dev = input_allocate_device(); |
| 294 | if (!input_dev) { |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 295 | err = -ENOMEM; |
| 296 | goto failed_put_clk; |
| 297 | } |
| 298 | |
| 299 | keypad->input_dev = input_dev; |
| 300 | |
| 301 | input_dev->name = pdev->name; |
| 302 | input_dev->id.bustype = BUS_HOST; |
| 303 | input_dev->open = ep93xx_keypad_open; |
| 304 | input_dev->close = ep93xx_keypad_close; |
| 305 | input_dev->dev.parent = &pdev->dev; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 306 | |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 307 | err = matrix_keypad_build_keymap(keymap_data, NULL, |
| 308 | EP93XX_MATRIX_ROWS, EP93XX_MATRIX_COLS, |
| 309 | keypad->keycodes, input_dev); |
| 310 | if (err) |
| 311 | goto failed_free_dev; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 312 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 313 | if (keypad->pdata->flags & EP93XX_KEYPAD_AUTOREPEAT) |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 314 | __set_bit(EV_REP, input_dev->evbit); |
| 315 | input_set_drvdata(input_dev, keypad); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 316 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 317 | err = request_irq(keypad->irq, ep93xx_keypad_irq_handler, |
Yong Zhang | ec4665c | 2011-09-07 14:04:16 -0700 | [diff] [blame] | 318 | 0, pdev->name, keypad); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 319 | if (err) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 320 | goto failed_free_dev; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 321 | |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 322 | err = input_register_device(input_dev); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 323 | if (err) |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 324 | goto failed_free_irq; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 325 | |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 326 | platform_set_drvdata(pdev, keypad); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 327 | device_init_wakeup(&pdev->dev, 1); |
| 328 | |
| 329 | return 0; |
| 330 | |
| 331 | failed_free_irq: |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 332 | free_irq(keypad->irq, pdev); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 333 | platform_set_drvdata(pdev, NULL); |
| 334 | failed_free_dev: |
| 335 | input_free_device(input_dev); |
| 336 | failed_put_clk: |
| 337 | clk_put(keypad->clk); |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 338 | failed_free_gpio: |
| 339 | ep93xx_keypad_release_gpio(pdev); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 340 | failed_free_io: |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 341 | iounmap(keypad->mmio_base); |
| 342 | failed_free_mem: |
| 343 | release_mem_region(res->start, resource_size(res)); |
| 344 | failed_free: |
| 345 | kfree(keypad); |
| 346 | return err; |
| 347 | } |
| 348 | |
| 349 | static int __devexit ep93xx_keypad_remove(struct platform_device *pdev) |
| 350 | { |
| 351 | struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); |
| 352 | struct resource *res; |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 353 | |
| 354 | free_irq(keypad->irq, pdev); |
| 355 | |
| 356 | platform_set_drvdata(pdev, NULL); |
| 357 | |
| 358 | if (keypad->enabled) |
| 359 | clk_disable(keypad->clk); |
| 360 | clk_put(keypad->clk); |
| 361 | |
| 362 | input_unregister_device(keypad->input_dev); |
| 363 | |
H Hartley Sweeten | 60214f0 | 2009-12-15 08:39:51 -0800 | [diff] [blame] | 364 | ep93xx_keypad_release_gpio(pdev); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 365 | |
| 366 | iounmap(keypad->mmio_base); |
| 367 | |
| 368 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 369 | release_mem_region(res->start, resource_size(res)); |
| 370 | |
| 371 | kfree(keypad); |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static struct platform_driver ep93xx_keypad_driver = { |
| 377 | .driver = { |
| 378 | .name = "ep93xx-keypad", |
| 379 | .owner = THIS_MODULE, |
Dmitry Torokhov | b5e9528 | 2012-04-11 00:13:50 -0700 | [diff] [blame] | 380 | .pm = &ep93xx_keypad_pm_ops, |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 381 | }, |
| 382 | .probe = ep93xx_keypad_probe, |
| 383 | .remove = __devexit_p(ep93xx_keypad_remove), |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 384 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 385 | module_platform_driver(ep93xx_keypad_driver); |
H Hartley Sweeten | e06003a | 2009-04-18 23:43:57 -0700 | [diff] [blame] | 386 | |
| 387 | MODULE_LICENSE("GPL"); |
| 388 | MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); |
| 389 | MODULE_DESCRIPTION("EP93xx Matrix Keypad Controller"); |
| 390 | MODULE_ALIAS("platform:ep93xx-keypad"); |