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> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/io.h> |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 29 | #include <linux/of.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 30 | #include <linux/input.h> |
| 31 | #include <linux/slab.h> |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 33 | |
Felipe Balbi | 0f1142a | 2012-03-16 22:47:48 -0700 | [diff] [blame] | 34 | #include <linux/platform_data/omap4-keypad.h> |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 35 | |
| 36 | /* OMAP4 registers */ |
| 37 | #define OMAP4_KBD_REVISION 0x00 |
| 38 | #define OMAP4_KBD_SYSCONFIG 0x10 |
| 39 | #define OMAP4_KBD_SYSSTATUS 0x14 |
| 40 | #define OMAP4_KBD_IRQSTATUS 0x18 |
| 41 | #define OMAP4_KBD_IRQENABLE 0x1C |
| 42 | #define OMAP4_KBD_WAKEUPENABLE 0x20 |
| 43 | #define OMAP4_KBD_PENDING 0x24 |
| 44 | #define OMAP4_KBD_CTRL 0x28 |
| 45 | #define OMAP4_KBD_DEBOUNCINGTIME 0x2C |
| 46 | #define OMAP4_KBD_LONGKEYTIME 0x30 |
| 47 | #define OMAP4_KBD_TIMEOUT 0x34 |
| 48 | #define OMAP4_KBD_STATEMACHINE 0x38 |
| 49 | #define OMAP4_KBD_ROWINPUTS 0x3C |
| 50 | #define OMAP4_KBD_COLUMNOUTPUTS 0x40 |
| 51 | #define OMAP4_KBD_FULLCODE31_0 0x44 |
| 52 | #define OMAP4_KBD_FULLCODE63_32 0x48 |
| 53 | |
| 54 | /* OMAP4 bit definitions */ |
Illia Smyrnov | 875ad69 | 2013-08-25 23:25:18 -0700 | [diff] [blame] | 55 | #define OMAP4_DEF_IRQENABLE_EVENTEN BIT(0) |
| 56 | #define OMAP4_DEF_IRQENABLE_LONGKEY BIT(1) |
| 57 | #define OMAP4_DEF_WUP_EVENT_ENA BIT(0) |
| 58 | #define OMAP4_DEF_WUP_LONG_KEY_ENA BIT(1) |
| 59 | #define OMAP4_DEF_CTRL_NOSOFTMODE BIT(1) |
| 60 | #define OMAP4_DEF_CTRL_PTV_SHIFT 2 |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 61 | |
| 62 | /* OMAP4 values */ |
Illia Smyrnov | 875ad69 | 2013-08-25 23:25:18 -0700 | [diff] [blame] | 63 | #define OMAP4_VAL_IRQDISABLE 0x0 |
| 64 | #define OMAP4_VAL_DEBOUNCINGTIME 0x7 |
| 65 | #define OMAP4_VAL_PVT 0x7 |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 66 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 67 | enum { |
| 68 | KBD_REVISION_OMAP4 = 0, |
| 69 | KBD_REVISION_OMAP5, |
| 70 | }; |
| 71 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 72 | struct omap4_keypad { |
| 73 | struct input_dev *input; |
| 74 | |
| 75 | void __iomem *base; |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 76 | bool irq_wake_enabled; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 77 | unsigned int irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 78 | |
| 79 | unsigned int rows; |
| 80 | unsigned int cols; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 81 | u32 reg_offset; |
| 82 | u32 irqreg_offset; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 83 | unsigned int row_shift; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 84 | bool no_autorepeat; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 85 | unsigned char key_state[8]; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 86 | unsigned short *keymap; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 89 | static int kbd_readl(struct omap4_keypad *keypad_data, u32 offset) |
| 90 | { |
| 91 | return __raw_readl(keypad_data->base + |
| 92 | keypad_data->reg_offset + offset); |
| 93 | } |
| 94 | |
| 95 | static void kbd_writel(struct omap4_keypad *keypad_data, u32 offset, u32 value) |
| 96 | { |
| 97 | __raw_writel(value, |
| 98 | keypad_data->base + keypad_data->reg_offset + offset); |
| 99 | } |
| 100 | |
| 101 | static int kbd_read_irqreg(struct omap4_keypad *keypad_data, u32 offset) |
| 102 | { |
| 103 | return __raw_readl(keypad_data->base + |
| 104 | keypad_data->irqreg_offset + offset); |
| 105 | } |
| 106 | |
| 107 | static void kbd_write_irqreg(struct omap4_keypad *keypad_data, |
| 108 | u32 offset, u32 value) |
| 109 | { |
| 110 | __raw_writel(value, |
| 111 | keypad_data->base + keypad_data->irqreg_offset + offset); |
| 112 | } |
| 113 | |
| 114 | |
Illia Smyrnov | c683da3 | 2013-08-25 23:25:50 -0700 | [diff] [blame] | 115 | /* Interrupt handlers */ |
| 116 | static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id) |
| 117 | { |
| 118 | struct omap4_keypad *keypad_data = dev_id; |
| 119 | |
| 120 | if (kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)) { |
| 121 | /* Disable interrupts */ |
| 122 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 123 | OMAP4_VAL_IRQDISABLE); |
| 124 | return IRQ_WAKE_THREAD; |
| 125 | } |
| 126 | |
| 127 | return IRQ_NONE; |
| 128 | } |
| 129 | |
| 130 | static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 131 | { |
| 132 | struct omap4_keypad *keypad_data = dev_id; |
| 133 | struct input_dev *input_dev = keypad_data->input; |
| 134 | unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)]; |
| 135 | unsigned int col, row, code, changed; |
| 136 | u32 *new_state = (u32 *) key_state; |
| 137 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 138 | *new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0); |
| 139 | *(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 140 | |
| 141 | for (row = 0; row < keypad_data->rows; row++) { |
| 142 | changed = key_state[row] ^ keypad_data->key_state[row]; |
| 143 | if (!changed) |
| 144 | continue; |
| 145 | |
| 146 | for (col = 0; col < keypad_data->cols; col++) { |
| 147 | if (changed & (1 << col)) { |
| 148 | code = MATRIX_SCAN_CODE(row, col, |
| 149 | keypad_data->row_shift); |
| 150 | input_event(input_dev, EV_MSC, MSC_SCAN, code); |
| 151 | input_report_key(input_dev, |
| 152 | keypad_data->keymap[code], |
| 153 | key_state[row] & (1 << col)); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | input_sync(input_dev); |
| 159 | |
| 160 | memcpy(keypad_data->key_state, key_state, |
| 161 | sizeof(keypad_data->key_state)); |
| 162 | |
| 163 | /* clear pending interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 164 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
| 165 | kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 166 | |
| 167 | /* enable interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 168 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 169 | OMAP4_DEF_IRQENABLE_EVENTEN | |
| 170 | OMAP4_DEF_IRQENABLE_LONGKEY); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 171 | |
| 172 | return IRQ_HANDLED; |
| 173 | } |
| 174 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 175 | static int omap4_keypad_open(struct input_dev *input) |
| 176 | { |
| 177 | struct omap4_keypad *keypad_data = input_get_drvdata(input); |
| 178 | |
| 179 | pm_runtime_get_sync(input->dev.parent); |
| 180 | |
| 181 | disable_irq(keypad_data->irq); |
| 182 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 183 | kbd_writel(keypad_data, OMAP4_KBD_CTRL, |
Illia Smyrnov | 875ad69 | 2013-08-25 23:25:18 -0700 | [diff] [blame] | 184 | OMAP4_DEF_CTRL_NOSOFTMODE | |
| 185 | (OMAP4_VAL_PVT << OMAP4_DEF_CTRL_PTV_SHIFT)); |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 186 | kbd_writel(keypad_data, OMAP4_KBD_DEBOUNCINGTIME, |
| 187 | OMAP4_VAL_DEBOUNCINGTIME); |
Illia Smyrnov | afbac60b | 2013-08-25 23:26:16 -0700 | [diff] [blame] | 188 | /* clear pending interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 189 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
Illia Smyrnov | afbac60b | 2013-08-25 23:26:16 -0700 | [diff] [blame] | 190 | kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)); |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 191 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 192 | OMAP4_DEF_IRQENABLE_EVENTEN | |
| 193 | OMAP4_DEF_IRQENABLE_LONGKEY); |
| 194 | kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE, |
| 195 | OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 196 | |
| 197 | enable_irq(keypad_data->irq); |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static void omap4_keypad_close(struct input_dev *input) |
| 203 | { |
| 204 | struct omap4_keypad *keypad_data = input_get_drvdata(input); |
| 205 | |
| 206 | disable_irq(keypad_data->irq); |
| 207 | |
| 208 | /* Disable interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 209 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE, |
| 210 | OMAP4_VAL_IRQDISABLE); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 211 | |
| 212 | /* clear pending interrupts */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 213 | kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, |
| 214 | kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS)); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 215 | |
| 216 | enable_irq(keypad_data->irq); |
| 217 | |
| 218 | pm_runtime_put_sync(input->dev.parent); |
| 219 | } |
| 220 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 221 | #ifdef CONFIG_OF |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 222 | static int omap4_keypad_parse_dt(struct device *dev, |
| 223 | struct omap4_keypad *keypad_data) |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 224 | { |
| 225 | struct device_node *np = dev->of_node; |
Simon Glass | 4384041 | 2013-02-25 14:08:40 -0800 | [diff] [blame] | 226 | int err; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 227 | |
Simon Glass | 4384041 | 2013-02-25 14:08:40 -0800 | [diff] [blame] | 228 | err = matrix_keypad_parse_of_params(dev, &keypad_data->rows, |
| 229 | &keypad_data->cols); |
| 230 | if (err) |
| 231 | return err; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 232 | |
| 233 | if (of_get_property(np, "linux,input-no-autorepeat", NULL)) |
| 234 | keypad_data->no_autorepeat = true; |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | #else |
| 239 | static inline int omap4_keypad_parse_dt(struct device *dev, |
| 240 | struct omap4_keypad *keypad_data) |
| 241 | { |
| 242 | return -ENOSYS; |
| 243 | } |
| 244 | #endif |
| 245 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 246 | static int omap4_keypad_probe(struct platform_device *pdev) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 247 | { |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 248 | const struct omap4_keypad_platform_data *pdata = |
| 249 | dev_get_platdata(&pdev->dev); |
| 250 | const struct matrix_keymap_data *keymap_data = |
| 251 | pdata ? pdata->keymap_data : NULL; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 252 | struct omap4_keypad *keypad_data; |
| 253 | struct input_dev *input_dev; |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 254 | struct resource *res; |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 255 | unsigned int max_keys; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 256 | int rev; |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 257 | int irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 258 | int error; |
| 259 | |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 260 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 261 | if (!res) { |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 262 | dev_err(&pdev->dev, "no base address specified\n"); |
| 263 | return -EINVAL; |
| 264 | } |
| 265 | |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 266 | irq = platform_get_irq(pdev, 0); |
| 267 | if (!irq) { |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 268 | dev_err(&pdev->dev, "no keyboard irq assigned\n"); |
| 269 | return -EINVAL; |
| 270 | } |
| 271 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 272 | keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 273 | if (!keypad_data) { |
| 274 | dev_err(&pdev->dev, "keypad_data memory allocation failed\n"); |
| 275 | return -ENOMEM; |
| 276 | } |
| 277 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 278 | keypad_data->irq = irq; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 279 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 280 | if (pdata) { |
| 281 | keypad_data->rows = pdata->rows; |
| 282 | keypad_data->cols = pdata->cols; |
| 283 | } else { |
| 284 | error = omap4_keypad_parse_dt(&pdev->dev, keypad_data); |
| 285 | if (error) |
| 286 | return error; |
| 287 | } |
| 288 | |
| 289 | res = request_mem_region(res->start, resource_size(res), pdev->name); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 290 | if (!res) { |
| 291 | dev_err(&pdev->dev, "can't request mem region\n"); |
| 292 | error = -EBUSY; |
| 293 | goto err_free_keypad; |
| 294 | } |
| 295 | |
| 296 | keypad_data->base = ioremap(res->start, resource_size(res)); |
| 297 | if (!keypad_data->base) { |
| 298 | dev_err(&pdev->dev, "can't ioremap mem resource\n"); |
| 299 | error = -ENOMEM; |
| 300 | goto err_release_mem; |
| 301 | } |
| 302 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 303 | |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 304 | /* |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 305 | * Enable clocks for the keypad module so that we can read |
| 306 | * revision register. |
| 307 | */ |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 308 | pm_runtime_enable(&pdev->dev); |
| 309 | error = pm_runtime_get_sync(&pdev->dev); |
| 310 | if (error) { |
| 311 | dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); |
| 312 | goto err_unmap; |
| 313 | } |
| 314 | rev = __raw_readl(keypad_data->base + OMAP4_KBD_REVISION); |
| 315 | rev &= 0x03 << 30; |
| 316 | rev >>= 30; |
| 317 | switch (rev) { |
| 318 | case KBD_REVISION_OMAP4: |
| 319 | keypad_data->reg_offset = 0x00; |
| 320 | keypad_data->irqreg_offset = 0x00; |
| 321 | break; |
| 322 | case KBD_REVISION_OMAP5: |
| 323 | keypad_data->reg_offset = 0x10; |
| 324 | keypad_data->irqreg_offset = 0x0c; |
| 325 | break; |
| 326 | default: |
| 327 | dev_err(&pdev->dev, |
| 328 | "Keypad reports unsupported revision %d", rev); |
| 329 | error = -EINVAL; |
| 330 | goto err_pm_put_sync; |
| 331 | } |
| 332 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 333 | /* input device allocation */ |
| 334 | keypad_data->input = input_dev = input_allocate_device(); |
| 335 | if (!input_dev) { |
| 336 | error = -ENOMEM; |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 337 | goto err_pm_put_sync; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | input_dev->name = pdev->name; |
| 341 | input_dev->dev.parent = &pdev->dev; |
| 342 | input_dev->id.bustype = BUS_HOST; |
| 343 | input_dev->id.vendor = 0x0001; |
| 344 | input_dev->id.product = 0x0001; |
| 345 | input_dev->id.version = 0x0001; |
| 346 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 347 | input_dev->open = omap4_keypad_open; |
| 348 | input_dev->close = omap4_keypad_close; |
| 349 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 350 | input_set_capability(input_dev, EV_MSC, MSC_SCAN); |
| 351 | if (!keypad_data->no_autorepeat) |
| 352 | __set_bit(EV_REP, input_dev->evbit); |
| 353 | |
| 354 | input_set_drvdata(input_dev, keypad_data); |
| 355 | |
| 356 | keypad_data->row_shift = get_count_order(keypad_data->cols); |
| 357 | max_keys = keypad_data->rows << keypad_data->row_shift; |
| 358 | keypad_data->keymap = kzalloc(max_keys * sizeof(keypad_data->keymap[0]), |
| 359 | GFP_KERNEL); |
| 360 | if (!keypad_data->keymap) { |
| 361 | dev_err(&pdev->dev, "Not enough memory for keymap\n"); |
| 362 | error = -ENOMEM; |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 363 | goto err_free_input; |
| 364 | } |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 365 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 366 | error = matrix_keypad_build_keymap(keymap_data, NULL, |
| 367 | keypad_data->rows, keypad_data->cols, |
| 368 | keypad_data->keymap, input_dev); |
| 369 | if (error) { |
| 370 | dev_err(&pdev->dev, "failed to build keymap\n"); |
| 371 | goto err_free_keymap; |
| 372 | } |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 373 | |
Illia Smyrnov | c683da3 | 2013-08-25 23:25:50 -0700 | [diff] [blame] | 374 | error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler, |
Illia Smyrnov | 50f3c16 | 2013-08-25 23:32:45 -0700 | [diff] [blame] | 375 | omap4_keypad_irq_thread_fn, 0, |
Illia Smyrnov | c683da3 | 2013-08-25 23:25:50 -0700 | [diff] [blame] | 376 | "omap4-keypad", keypad_data); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 377 | if (error) { |
| 378 | dev_err(&pdev->dev, "failed to register interrupt\n"); |
| 379 | goto err_free_input; |
| 380 | } |
| 381 | |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 382 | device_init_wakeup(&pdev->dev, true); |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 383 | pm_runtime_put_sync(&pdev->dev); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 384 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 385 | error = input_register_device(keypad_data->input); |
| 386 | if (error < 0) { |
| 387 | dev_err(&pdev->dev, "failed to register input device\n"); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 388 | goto err_pm_disable; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 391 | platform_set_drvdata(pdev, keypad_data); |
| 392 | return 0; |
| 393 | |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 394 | err_pm_disable: |
| 395 | pm_runtime_disable(&pdev->dev); |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 396 | device_init_wakeup(&pdev->dev, false); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 397 | free_irq(keypad_data->irq, keypad_data); |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 398 | err_free_keymap: |
| 399 | kfree(keypad_data->keymap); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 400 | err_free_input: |
| 401 | input_free_device(input_dev); |
Poddar, Sourav | f77621c | 2012-05-10 22:32:00 -0700 | [diff] [blame] | 402 | err_pm_put_sync: |
| 403 | pm_runtime_put_sync(&pdev->dev); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 404 | err_unmap: |
| 405 | iounmap(keypad_data->base); |
| 406 | err_release_mem: |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 407 | release_mem_region(res->start, resource_size(res)); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 408 | err_free_keypad: |
| 409 | kfree(keypad_data); |
| 410 | return error; |
| 411 | } |
| 412 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 413 | static int omap4_keypad_remove(struct platform_device *pdev) |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 414 | { |
| 415 | struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 416 | struct resource *res; |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 417 | |
| 418 | free_irq(keypad_data->irq, keypad_data); |
Abraham Arce | 5ad567f | 2011-02-22 22:25:59 -0800 | [diff] [blame] | 419 | |
| 420 | pm_runtime_disable(&pdev->dev); |
| 421 | |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 422 | device_init_wakeup(&pdev->dev, false); |
| 423 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 424 | input_unregister_device(keypad_data->input); |
Abraham Arce | f3a1ba6 | 2010-09-29 23:35:57 -0700 | [diff] [blame] | 425 | |
| 426 | iounmap(keypad_data->base); |
| 427 | |
| 428 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 429 | release_mem_region(res->start, resource_size(res)); |
| 430 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 431 | kfree(keypad_data->keymap); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 432 | kfree(keypad_data); |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 433 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 437 | #ifdef CONFIG_OF |
| 438 | static const struct of_device_id omap_keypad_dt_match[] = { |
| 439 | { .compatible = "ti,omap4-keypad" }, |
| 440 | {}, |
| 441 | }; |
| 442 | MODULE_DEVICE_TABLE(of, omap_keypad_dt_match); |
| 443 | #endif |
| 444 | |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 445 | #ifdef CONFIG_PM_SLEEP |
| 446 | static int omap4_keypad_suspend(struct device *dev) |
| 447 | { |
| 448 | struct platform_device *pdev = to_platform_device(dev); |
| 449 | struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); |
| 450 | int error; |
| 451 | |
| 452 | if (device_may_wakeup(&pdev->dev)) { |
| 453 | error = enable_irq_wake(keypad_data->irq); |
| 454 | if (!error) |
| 455 | keypad_data->irq_wake_enabled = true; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int omap4_keypad_resume(struct device *dev) |
| 462 | { |
| 463 | struct platform_device *pdev = to_platform_device(dev); |
| 464 | struct omap4_keypad *keypad_data = platform_get_drvdata(pdev); |
| 465 | |
| 466 | if (device_may_wakeup(&pdev->dev) && keypad_data->irq_wake_enabled) { |
| 467 | disable_irq_wake(keypad_data->irq); |
| 468 | keypad_data->irq_wake_enabled = false; |
| 469 | } |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | #endif |
| 474 | |
| 475 | static SIMPLE_DEV_PM_OPS(omap4_keypad_pm_ops, |
| 476 | omap4_keypad_suspend, omap4_keypad_resume); |
| 477 | |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 478 | static struct platform_driver omap4_keypad_driver = { |
| 479 | .probe = omap4_keypad_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 480 | .remove = omap4_keypad_remove, |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 481 | .driver = { |
| 482 | .name = "omap4-keypad", |
| 483 | .owner = THIS_MODULE, |
Illia Smyrnov | 78608a0 | 2013-08-25 23:29:30 -0700 | [diff] [blame] | 484 | .pm = &omap4_keypad_pm_ops, |
Sourav Poddar | 1398743 | 2012-07-13 00:10:47 -0700 | [diff] [blame] | 485 | .of_match_table = of_match_ptr(omap_keypad_dt_match), |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 486 | }, |
| 487 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 488 | module_platform_driver(omap4_keypad_driver); |
Abraham Arce | a17f795 | 2010-08-31 17:05:27 -0700 | [diff] [blame] | 489 | |
| 490 | MODULE_AUTHOR("Texas Instruments"); |
| 491 | MODULE_DESCRIPTION("OMAP4 Keypad Driver"); |
| 492 | MODULE_LICENSE("GPL"); |
| 493 | MODULE_ALIAS("platform:omap4-keypad"); |