Thomas Gleixner | 1f67b59 | 2019-06-04 10:10:57 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) ST-Ericsson SA 2010 |
| 4 | * |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 5 | * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 9 | #include <linux/slab.h> |
| 10 | #include <linux/input.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/input/matrix_keypad.h> |
| 14 | #include <linux/mfd/stmpe.h> |
| 15 | |
| 16 | /* These are at the same addresses in all STMPE variants */ |
| 17 | #define STMPE_KPC_COL 0x60 |
| 18 | #define STMPE_KPC_ROW_MSB 0x61 |
| 19 | #define STMPE_KPC_ROW_LSB 0x62 |
| 20 | #define STMPE_KPC_CTRL_MSB 0x63 |
| 21 | #define STMPE_KPC_CTRL_LSB 0x64 |
| 22 | #define STMPE_KPC_COMBI_KEY_0 0x65 |
| 23 | #define STMPE_KPC_COMBI_KEY_1 0x66 |
| 24 | #define STMPE_KPC_COMBI_KEY_2 0x67 |
| 25 | #define STMPE_KPC_DATA_BYTE0 0x68 |
| 26 | #define STMPE_KPC_DATA_BYTE1 0x69 |
| 27 | #define STMPE_KPC_DATA_BYTE2 0x6a |
| 28 | #define STMPE_KPC_DATA_BYTE3 0x6b |
| 29 | #define STMPE_KPC_DATA_BYTE4 0x6c |
| 30 | |
| 31 | #define STMPE_KPC_CTRL_LSB_SCAN (0x1 << 0) |
| 32 | #define STMPE_KPC_CTRL_LSB_DEBOUNCE (0x7f << 1) |
| 33 | #define STMPE_KPC_CTRL_MSB_SCAN_COUNT (0xf << 4) |
| 34 | |
| 35 | #define STMPE_KPC_ROW_MSB_ROWS 0xff |
| 36 | |
| 37 | #define STMPE_KPC_DATA_UP (0x1 << 7) |
| 38 | #define STMPE_KPC_DATA_ROW (0xf << 3) |
| 39 | #define STMPE_KPC_DATA_COL (0x7 << 0) |
| 40 | #define STMPE_KPC_DATA_NOKEY_MASK 0x78 |
| 41 | |
| 42 | #define STMPE_KEYPAD_MAX_DEBOUNCE 127 |
| 43 | #define STMPE_KEYPAD_MAX_SCAN_COUNT 15 |
| 44 | |
| 45 | #define STMPE_KEYPAD_MAX_ROWS 8 |
| 46 | #define STMPE_KEYPAD_MAX_COLS 8 |
| 47 | #define STMPE_KEYPAD_ROW_SHIFT 3 |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 48 | #define STMPE_KEYPAD_KEYMAP_MAX_SIZE \ |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 49 | (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) |
| 50 | |
Gustavo A. R. Silva | 1c4bfce | 2018-03-10 10:16:41 -0800 | [diff] [blame] | 51 | |
| 52 | #define STMPE1601_NUM_DATA 5 |
| 53 | #define STMPE2401_NUM_DATA 3 |
| 54 | #define STMPE2403_NUM_DATA 5 |
| 55 | |
| 56 | /* Make sure it covers all cases above */ |
| 57 | #define MAX_NUM_DATA 5 |
| 58 | |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 59 | /** |
| 60 | * struct stmpe_keypad_variant - model-specific attributes |
| 61 | * @auto_increment: whether the KPC_DATA_BYTE register address |
| 62 | * auto-increments on multiple read |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 63 | * @set_pullup: whether the pins need to have their pull-ups set |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 64 | * @num_data: number of data bytes |
| 65 | * @num_normal_data: number of normal keys' data bytes |
| 66 | * @max_cols: maximum number of columns supported |
| 67 | * @max_rows: maximum number of rows supported |
| 68 | * @col_gpios: bitmask of gpios which can be used for columns |
| 69 | * @row_gpios: bitmask of gpios which can be used for rows |
| 70 | */ |
| 71 | struct stmpe_keypad_variant { |
| 72 | bool auto_increment; |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 73 | bool set_pullup; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 74 | int num_data; |
| 75 | int num_normal_data; |
| 76 | int max_cols; |
| 77 | int max_rows; |
| 78 | unsigned int col_gpios; |
| 79 | unsigned int row_gpios; |
| 80 | }; |
| 81 | |
| 82 | static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { |
| 83 | [STMPE1601] = { |
| 84 | .auto_increment = true, |
Gustavo A. R. Silva | 1c4bfce | 2018-03-10 10:16:41 -0800 | [diff] [blame] | 85 | .num_data = STMPE1601_NUM_DATA, |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 86 | .num_normal_data = 3, |
| 87 | .max_cols = 8, |
| 88 | .max_rows = 8, |
| 89 | .col_gpios = 0x000ff, /* GPIO 0 - 7 */ |
| 90 | .row_gpios = 0x0ff00, /* GPIO 8 - 15 */ |
| 91 | }, |
| 92 | [STMPE2401] = { |
| 93 | .auto_increment = false, |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 94 | .set_pullup = true, |
Gustavo A. R. Silva | 1c4bfce | 2018-03-10 10:16:41 -0800 | [diff] [blame] | 95 | .num_data = STMPE2401_NUM_DATA, |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 96 | .num_normal_data = 2, |
| 97 | .max_cols = 8, |
| 98 | .max_rows = 12, |
| 99 | .col_gpios = 0x0000ff, /* GPIO 0 - 7*/ |
Linus Walleij | 2175b0f | 2014-10-24 14:36:54 -0700 | [diff] [blame] | 100 | .row_gpios = 0x1f7f00, /* GPIO 8-14, 16-20 */ |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 101 | }, |
| 102 | [STMPE2403] = { |
| 103 | .auto_increment = true, |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 104 | .set_pullup = true, |
Gustavo A. R. Silva | 1c4bfce | 2018-03-10 10:16:41 -0800 | [diff] [blame] | 105 | .num_data = STMPE2403_NUM_DATA, |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 106 | .num_normal_data = 3, |
| 107 | .max_cols = 8, |
| 108 | .max_rows = 12, |
| 109 | .col_gpios = 0x0000ff, /* GPIO 0 - 7*/ |
| 110 | .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */ |
| 111 | }, |
| 112 | }; |
| 113 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 114 | /** |
| 115 | * struct stmpe_keypad - STMPE keypad state container |
| 116 | * @stmpe: pointer to parent STMPE device |
| 117 | * @input: spawned input device |
| 118 | * @variant: STMPE variant |
| 119 | * @debounce_ms: debounce interval, in ms. Maximum is |
| 120 | * %STMPE_KEYPAD_MAX_DEBOUNCE. |
| 121 | * @scan_count: number of key scanning cycles to confirm key data. |
| 122 | * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT. |
| 123 | * @no_autorepeat: disable key autorepeat |
| 124 | * @rows: bitmask for the rows |
| 125 | * @cols: bitmask for the columns |
| 126 | * @keymap: the keymap |
| 127 | */ |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 128 | struct stmpe_keypad { |
| 129 | struct stmpe *stmpe; |
| 130 | struct input_dev *input; |
| 131 | const struct stmpe_keypad_variant *variant; |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 132 | unsigned int debounce_ms; |
| 133 | unsigned int scan_count; |
| 134 | bool no_autorepeat; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 135 | unsigned int rows; |
| 136 | unsigned int cols; |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 137 | unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE]; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) |
| 141 | { |
| 142 | const struct stmpe_keypad_variant *variant = keypad->variant; |
| 143 | struct stmpe *stmpe = keypad->stmpe; |
| 144 | int ret; |
| 145 | int i; |
| 146 | |
| 147 | if (variant->auto_increment) |
| 148 | return stmpe_block_read(stmpe, STMPE_KPC_DATA_BYTE0, |
| 149 | variant->num_data, data); |
| 150 | |
| 151 | for (i = 0; i < variant->num_data; i++) { |
| 152 | ret = stmpe_reg_read(stmpe, STMPE_KPC_DATA_BYTE0 + i); |
| 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | |
| 156 | data[i] = ret; |
| 157 | } |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static irqreturn_t stmpe_keypad_irq(int irq, void *dev) |
| 163 | { |
| 164 | struct stmpe_keypad *keypad = dev; |
| 165 | struct input_dev *input = keypad->input; |
| 166 | const struct stmpe_keypad_variant *variant = keypad->variant; |
Gustavo A. R. Silva | 1c4bfce | 2018-03-10 10:16:41 -0800 | [diff] [blame] | 167 | u8 fifo[MAX_NUM_DATA]; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 168 | int ret; |
| 169 | int i; |
| 170 | |
| 171 | ret = stmpe_keypad_read_data(keypad, fifo); |
| 172 | if (ret < 0) |
| 173 | return IRQ_NONE; |
| 174 | |
| 175 | for (i = 0; i < variant->num_normal_data; i++) { |
| 176 | u8 data = fifo[i]; |
| 177 | int row = (data & STMPE_KPC_DATA_ROW) >> 3; |
| 178 | int col = data & STMPE_KPC_DATA_COL; |
| 179 | int code = MATRIX_SCAN_CODE(row, col, STMPE_KEYPAD_ROW_SHIFT); |
| 180 | bool up = data & STMPE_KPC_DATA_UP; |
| 181 | |
| 182 | if ((data & STMPE_KPC_DATA_NOKEY_MASK) |
| 183 | == STMPE_KPC_DATA_NOKEY_MASK) |
| 184 | continue; |
| 185 | |
| 186 | input_event(input, EV_MSC, MSC_SCAN, code); |
| 187 | input_report_key(input, keypad->keymap[code], !up); |
| 188 | input_sync(input); |
| 189 | } |
| 190 | |
| 191 | return IRQ_HANDLED; |
| 192 | } |
| 193 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 194 | static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 195 | { |
| 196 | const struct stmpe_keypad_variant *variant = keypad->variant; |
| 197 | unsigned int col_gpios = variant->col_gpios; |
| 198 | unsigned int row_gpios = variant->row_gpios; |
| 199 | struct stmpe *stmpe = keypad->stmpe; |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 200 | u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB]; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 201 | unsigned int pins = 0; |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 202 | unsigned int pu_pins = 0; |
| 203 | int ret; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 204 | int i; |
| 205 | |
| 206 | /* |
| 207 | * Figure out which pins need to be set to the keypad alternate |
| 208 | * function. |
| 209 | * |
| 210 | * {cols,rows}_gpios are bitmasks of which pins on the chip can be used |
| 211 | * for the keypad. |
| 212 | * |
| 213 | * keypad->{cols,rows} are a bitmask of which pins (of the ones useable |
| 214 | * for the keypad) are used on the board. |
| 215 | */ |
| 216 | |
| 217 | for (i = 0; i < variant->max_cols; i++) { |
| 218 | int num = __ffs(col_gpios); |
| 219 | |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 220 | if (keypad->cols & (1 << i)) { |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 221 | pins |= 1 << num; |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 222 | pu_pins |= 1 << num; |
| 223 | } |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 224 | |
| 225 | col_gpios &= ~(1 << num); |
| 226 | } |
| 227 | |
| 228 | for (i = 0; i < variant->max_rows; i++) { |
| 229 | int num = __ffs(row_gpios); |
| 230 | |
| 231 | if (keypad->rows & (1 << i)) |
| 232 | pins |= 1 << num; |
| 233 | |
| 234 | row_gpios &= ~(1 << num); |
| 235 | } |
| 236 | |
Linus Walleij | 7c12a5b | 2014-12-15 22:23:40 -0800 | [diff] [blame] | 237 | ret = stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | |
| 241 | /* |
| 242 | * On STMPE24xx, set pin bias to pull-up on all keypad input |
| 243 | * pins (columns), this incidentally happen to be maximum 8 pins |
| 244 | * and placed at GPIO0-7 so only the LSB of the pull up register |
| 245 | * ever needs to be written. |
| 246 | */ |
| 247 | if (variant->set_pullup) { |
| 248 | u8 val; |
| 249 | |
| 250 | ret = stmpe_reg_read(stmpe, pureg); |
| 251 | if (ret) |
| 252 | return ret; |
| 253 | |
| 254 | /* Do not touch unused pins, may be used for GPIO */ |
| 255 | val = ret & ~pu_pins; |
| 256 | val |= pu_pins; |
| 257 | |
| 258 | ret = stmpe_reg_write(stmpe, pureg, val); |
| 259 | } |
| 260 | |
| 261 | return 0; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 262 | } |
| 263 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 264 | static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 265 | { |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 266 | const struct stmpe_keypad_variant *variant = keypad->variant; |
| 267 | struct stmpe *stmpe = keypad->stmpe; |
| 268 | int ret; |
| 269 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 270 | if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 273 | if (keypad->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 274 | return -EINVAL; |
| 275 | |
| 276 | ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD); |
| 277 | if (ret < 0) |
| 278 | return ret; |
| 279 | |
| 280 | ret = stmpe_keypad_altfunc_init(keypad); |
| 281 | if (ret < 0) |
| 282 | return ret; |
| 283 | |
| 284 | ret = stmpe_reg_write(stmpe, STMPE_KPC_COL, keypad->cols); |
| 285 | if (ret < 0) |
| 286 | return ret; |
| 287 | |
| 288 | ret = stmpe_reg_write(stmpe, STMPE_KPC_ROW_LSB, keypad->rows); |
| 289 | if (ret < 0) |
| 290 | return ret; |
| 291 | |
| 292 | if (variant->max_rows > 8) { |
| 293 | ret = stmpe_set_bits(stmpe, STMPE_KPC_ROW_MSB, |
| 294 | STMPE_KPC_ROW_MSB_ROWS, |
| 295 | keypad->rows >> 8); |
| 296 | if (ret < 0) |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB, |
| 301 | STMPE_KPC_CTRL_MSB_SCAN_COUNT, |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 302 | keypad->scan_count << 4); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 303 | if (ret < 0) |
| 304 | return ret; |
| 305 | |
| 306 | return stmpe_set_bits(stmpe, STMPE_KPC_CTRL_LSB, |
| 307 | STMPE_KPC_CTRL_LSB_SCAN | |
| 308 | STMPE_KPC_CTRL_LSB_DEBOUNCE, |
| 309 | STMPE_KPC_CTRL_LSB_SCAN | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 310 | (keypad->debounce_ms << 1)); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 311 | } |
| 312 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 313 | static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad, |
| 314 | u32 used_rows, u32 used_cols) |
Dmitry Torokhov | 6ea3238 | 2012-11-14 08:55:21 -0800 | [diff] [blame] | 315 | { |
| 316 | int row, col; |
| 317 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 318 | for (row = 0; row < used_rows; row++) { |
| 319 | for (col = 0; col < used_cols; col++) { |
Dmitry Torokhov | 6ea3238 | 2012-11-14 08:55:21 -0800 | [diff] [blame] | 320 | int code = MATRIX_SCAN_CODE(row, col, |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 321 | STMPE_KEYPAD_ROW_SHIFT); |
Dmitry Torokhov | 6ea3238 | 2012-11-14 08:55:21 -0800 | [diff] [blame] | 322 | if (keypad->keymap[code] != KEY_RESERVED) { |
| 323 | keypad->rows |= 1 << row; |
| 324 | keypad->cols |= 1 << col; |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 330 | static int stmpe_keypad_probe(struct platform_device *pdev) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 331 | { |
| 332 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 333 | struct device_node *np = pdev->dev.of_node; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 334 | struct stmpe_keypad *keypad; |
| 335 | struct input_dev *input; |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 336 | u32 rows; |
| 337 | u32 cols; |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 338 | int error; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 339 | int irq; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 340 | |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 341 | irq = platform_get_irq(pdev, 0); |
| 342 | if (irq < 0) |
| 343 | return irq; |
| 344 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 345 | keypad = devm_kzalloc(&pdev->dev, sizeof(struct stmpe_keypad), |
| 346 | GFP_KERNEL); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 347 | if (!keypad) |
| 348 | return -ENOMEM; |
| 349 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 350 | keypad->stmpe = stmpe; |
| 351 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; |
| 352 | |
| 353 | of_property_read_u32(np, "debounce-interval", &keypad->debounce_ms); |
| 354 | of_property_read_u32(np, "st,scan-count", &keypad->scan_count); |
| 355 | keypad->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat"); |
| 356 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 357 | input = devm_input_allocate_device(&pdev->dev); |
| 358 | if (!input) |
| 359 | return -ENOMEM; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 360 | |
| 361 | input->name = "STMPE keypad"; |
| 362 | input->id.bustype = BUS_I2C; |
| 363 | input->dev.parent = &pdev->dev; |
| 364 | |
Dmitry Torokhov | aef01aa | 2016-11-11 12:43:12 -0800 | [diff] [blame] | 365 | error = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols); |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 366 | if (error) |
| 367 | return error; |
| 368 | |
| 369 | error = matrix_keypad_build_keymap(NULL, NULL, rows, cols, |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 370 | keypad->keymap, input); |
| 371 | if (error) |
| 372 | return error; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 373 | |
Dmitry Torokhov | 1932811 | 2012-05-10 22:37:08 -0700 | [diff] [blame] | 374 | input_set_capability(input, EV_MSC, MSC_SCAN); |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 375 | if (!keypad->no_autorepeat) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 376 | __set_bit(EV_REP, input->evbit); |
| 377 | |
Linus Walleij | a416486 | 2014-11-03 16:51:26 -0800 | [diff] [blame] | 378 | stmpe_keypad_fill_used_pins(keypad, rows, cols); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 379 | |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 380 | keypad->input = input; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 381 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 382 | error = stmpe_keypad_chip_init(keypad); |
| 383 | if (error < 0) |
| 384 | return error; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 385 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 386 | error = devm_request_threaded_irq(&pdev->dev, irq, |
| 387 | NULL, stmpe_keypad_irq, |
| 388 | IRQF_ONESHOT, "stmpe-keypad", keypad); |
| 389 | if (error) { |
| 390 | dev_err(&pdev->dev, "unable to get irq: %d\n", error); |
| 391 | return error; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 392 | } |
| 393 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 394 | error = input_register_device(input); |
| 395 | if (error) { |
| 396 | dev_err(&pdev->dev, |
| 397 | "unable to register input device: %d\n", error); |
| 398 | return error; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | platform_set_drvdata(pdev, keypad); |
| 402 | |
| 403 | return 0; |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 404 | } |
| 405 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 406 | static int stmpe_keypad_remove(struct platform_device *pdev) |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 407 | { |
| 408 | struct stmpe_keypad *keypad = platform_get_drvdata(pdev); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 409 | |
Viresh Kumar | aaa4f2a | 2012-11-10 00:11:10 -0800 | [diff] [blame] | 410 | stmpe_disable(keypad->stmpe, STMPE_BLOCK_KEYPAD); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static struct platform_driver stmpe_keypad_driver = { |
| 416 | .driver.name = "stmpe-keypad", |
| 417 | .driver.owner = THIS_MODULE, |
| 418 | .probe = stmpe_keypad_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 419 | .remove = stmpe_keypad_remove, |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 420 | }; |
JJ Ding | 5146c84 | 2011-11-29 11:08:39 -0800 | [diff] [blame] | 421 | module_platform_driver(stmpe_keypad_driver); |
Rabin Vincent | 76f1084 | 2010-07-02 16:52:10 +0530 | [diff] [blame] | 422 | |
| 423 | MODULE_LICENSE("GPL v2"); |
| 424 | MODULE_DESCRIPTION("STMPExxxx keypad driver"); |
| 425 | MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>"); |