diff options
Diffstat (limited to 'drivers/input/keyboard/stmpe-keypad.c')
-rw-r--r-- | drivers/input/keyboard/stmpe-keypad.c | 141 |
1 files changed, 80 insertions, 61 deletions
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c index ef5e67fb567e..fe6e3f22eed7 100644 --- a/drivers/input/keyboard/stmpe-keypad.c +++ b/drivers/input/keyboard/stmpe-keypad.c | |||
@@ -45,13 +45,14 @@ | |||
45 | #define STMPE_KEYPAD_MAX_ROWS 8 | 45 | #define STMPE_KEYPAD_MAX_ROWS 8 |
46 | #define STMPE_KEYPAD_MAX_COLS 8 | 46 | #define STMPE_KEYPAD_MAX_COLS 8 |
47 | #define STMPE_KEYPAD_ROW_SHIFT 3 | 47 | #define STMPE_KEYPAD_ROW_SHIFT 3 |
48 | #define STMPE_KEYPAD_KEYMAP_SIZE \ | 48 | #define STMPE_KEYPAD_KEYMAP_MAX_SIZE \ |
49 | (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) | 49 | (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * struct stmpe_keypad_variant - model-specific attributes | 52 | * struct stmpe_keypad_variant - model-specific attributes |
53 | * @auto_increment: whether the KPC_DATA_BYTE register address | 53 | * @auto_increment: whether the KPC_DATA_BYTE register address |
54 | * auto-increments on multiple read | 54 | * auto-increments on multiple read |
55 | * @set_pullup: whether the pins need to have their pull-ups set | ||
55 | * @num_data: number of data bytes | 56 | * @num_data: number of data bytes |
56 | * @num_normal_data: number of normal keys' data bytes | 57 | * @num_normal_data: number of normal keys' data bytes |
57 | * @max_cols: maximum number of columns supported | 58 | * @max_cols: maximum number of columns supported |
@@ -61,6 +62,7 @@ | |||
61 | */ | 62 | */ |
62 | struct stmpe_keypad_variant { | 63 | struct stmpe_keypad_variant { |
63 | bool auto_increment; | 64 | bool auto_increment; |
65 | bool set_pullup; | ||
64 | int num_data; | 66 | int num_data; |
65 | int num_normal_data; | 67 | int num_normal_data; |
66 | int max_cols; | 68 | int max_cols; |
@@ -81,6 +83,7 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { | |||
81 | }, | 83 | }, |
82 | [STMPE2401] = { | 84 | [STMPE2401] = { |
83 | .auto_increment = false, | 85 | .auto_increment = false, |
86 | .set_pullup = true, | ||
84 | .num_data = 3, | 87 | .num_data = 3, |
85 | .num_normal_data = 2, | 88 | .num_normal_data = 2, |
86 | .max_cols = 8, | 89 | .max_cols = 8, |
@@ -90,6 +93,7 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { | |||
90 | }, | 93 | }, |
91 | [STMPE2403] = { | 94 | [STMPE2403] = { |
92 | .auto_increment = true, | 95 | .auto_increment = true, |
96 | .set_pullup = true, | ||
93 | .num_data = 5, | 97 | .num_data = 5, |
94 | .num_normal_data = 3, | 98 | .num_normal_data = 3, |
95 | .max_cols = 8, | 99 | .max_cols = 8, |
@@ -99,16 +103,30 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { | |||
99 | }, | 103 | }, |
100 | }; | 104 | }; |
101 | 105 | ||
106 | /** | ||
107 | * struct stmpe_keypad - STMPE keypad state container | ||
108 | * @stmpe: pointer to parent STMPE device | ||
109 | * @input: spawned input device | ||
110 | * @variant: STMPE variant | ||
111 | * @debounce_ms: debounce interval, in ms. Maximum is | ||
112 | * %STMPE_KEYPAD_MAX_DEBOUNCE. | ||
113 | * @scan_count: number of key scanning cycles to confirm key data. | ||
114 | * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT. | ||
115 | * @no_autorepeat: disable key autorepeat | ||
116 | * @rows: bitmask for the rows | ||
117 | * @cols: bitmask for the columns | ||
118 | * @keymap: the keymap | ||
119 | */ | ||
102 | struct stmpe_keypad { | 120 | struct stmpe_keypad { |
103 | struct stmpe *stmpe; | 121 | struct stmpe *stmpe; |
104 | struct input_dev *input; | 122 | struct input_dev *input; |
105 | const struct stmpe_keypad_variant *variant; | 123 | const struct stmpe_keypad_variant *variant; |
106 | const struct stmpe_keypad_platform_data *plat; | 124 | unsigned int debounce_ms; |
107 | 125 | unsigned int scan_count; | |
126 | bool no_autorepeat; | ||
108 | unsigned int rows; | 127 | unsigned int rows; |
109 | unsigned int cols; | 128 | unsigned int cols; |
110 | 129 | unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE]; | |
111 | unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE]; | ||
112 | }; | 130 | }; |
113 | 131 | ||
114 | static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) | 132 | static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) |
@@ -171,7 +189,10 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad) | |||
171 | unsigned int col_gpios = variant->col_gpios; | 189 | unsigned int col_gpios = variant->col_gpios; |
172 | unsigned int row_gpios = variant->row_gpios; | 190 | unsigned int row_gpios = variant->row_gpios; |
173 | struct stmpe *stmpe = keypad->stmpe; | 191 | struct stmpe *stmpe = keypad->stmpe; |
192 | u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB]; | ||
174 | unsigned int pins = 0; | 193 | unsigned int pins = 0; |
194 | unsigned int pu_pins = 0; | ||
195 | int ret; | ||
175 | int i; | 196 | int i; |
176 | 197 | ||
177 | /* | 198 | /* |
@@ -188,8 +209,10 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad) | |||
188 | for (i = 0; i < variant->max_cols; i++) { | 209 | for (i = 0; i < variant->max_cols; i++) { |
189 | int num = __ffs(col_gpios); | 210 | int num = __ffs(col_gpios); |
190 | 211 | ||
191 | if (keypad->cols & (1 << i)) | 212 | if (keypad->cols & (1 << i)) { |
192 | pins |= 1 << num; | 213 | pins |= 1 << num; |
214 | pu_pins |= 1 << num; | ||
215 | } | ||
193 | 216 | ||
194 | col_gpios &= ~(1 << num); | 217 | col_gpios &= ~(1 << num); |
195 | } | 218 | } |
@@ -203,20 +226,43 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad) | |||
203 | row_gpios &= ~(1 << num); | 226 | row_gpios &= ~(1 << num); |
204 | } | 227 | } |
205 | 228 | ||
206 | return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD); | 229 | ret = stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD); |
230 | if (ret) | ||
231 | return ret; | ||
232 | |||
233 | /* | ||
234 | * On STMPE24xx, set pin bias to pull-up on all keypad input | ||
235 | * pins (columns), this incidentally happen to be maximum 8 pins | ||
236 | * and placed at GPIO0-7 so only the LSB of the pull up register | ||
237 | * ever needs to be written. | ||
238 | */ | ||
239 | if (variant->set_pullup) { | ||
240 | u8 val; | ||
241 | |||
242 | ret = stmpe_reg_read(stmpe, pureg); | ||
243 | if (ret) | ||
244 | return ret; | ||
245 | |||
246 | /* Do not touch unused pins, may be used for GPIO */ | ||
247 | val = ret & ~pu_pins; | ||
248 | val |= pu_pins; | ||
249 | |||
250 | ret = stmpe_reg_write(stmpe, pureg, val); | ||
251 | } | ||
252 | |||
253 | return 0; | ||
207 | } | 254 | } |
208 | 255 | ||
209 | static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) | 256 | static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) |
210 | { | 257 | { |
211 | const struct stmpe_keypad_platform_data *plat = keypad->plat; | ||
212 | const struct stmpe_keypad_variant *variant = keypad->variant; | 258 | const struct stmpe_keypad_variant *variant = keypad->variant; |
213 | struct stmpe *stmpe = keypad->stmpe; | 259 | struct stmpe *stmpe = keypad->stmpe; |
214 | int ret; | 260 | int ret; |
215 | 261 | ||
216 | if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE) | 262 | if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE) |
217 | return -EINVAL; | 263 | return -EINVAL; |
218 | 264 | ||
219 | if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT) | 265 | if (keypad->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT) |
220 | return -EINVAL; | 266 | return -EINVAL; |
221 | 267 | ||
222 | ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD); | 268 | ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD); |
@@ -245,7 +291,7 @@ static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) | |||
245 | 291 | ||
246 | ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB, | 292 | ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB, |
247 | STMPE_KPC_CTRL_MSB_SCAN_COUNT, | 293 | STMPE_KPC_CTRL_MSB_SCAN_COUNT, |
248 | plat->scan_count << 4); | 294 | keypad->scan_count << 4); |
249 | if (ret < 0) | 295 | if (ret < 0) |
250 | return ret; | 296 | return ret; |
251 | 297 | ||
@@ -253,17 +299,18 @@ static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) | |||
253 | STMPE_KPC_CTRL_LSB_SCAN | | 299 | STMPE_KPC_CTRL_LSB_SCAN | |
254 | STMPE_KPC_CTRL_LSB_DEBOUNCE, | 300 | STMPE_KPC_CTRL_LSB_DEBOUNCE, |
255 | STMPE_KPC_CTRL_LSB_SCAN | | 301 | STMPE_KPC_CTRL_LSB_SCAN | |
256 | (plat->debounce_ms << 1)); | 302 | (keypad->debounce_ms << 1)); |
257 | } | 303 | } |
258 | 304 | ||
259 | static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad) | 305 | static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad, |
306 | u32 used_rows, u32 used_cols) | ||
260 | { | 307 | { |
261 | int row, col; | 308 | int row, col; |
262 | 309 | ||
263 | for (row = 0; row < STMPE_KEYPAD_MAX_ROWS; row++) { | 310 | for (row = 0; row < used_rows; row++) { |
264 | for (col = 0; col < STMPE_KEYPAD_MAX_COLS; col++) { | 311 | for (col = 0; col < used_cols; col++) { |
265 | int code = MATRIX_SCAN_CODE(row, col, | 312 | int code = MATRIX_SCAN_CODE(row, col, |
266 | STMPE_KEYPAD_ROW_SHIFT); | 313 | STMPE_KEYPAD_ROW_SHIFT); |
267 | if (keypad->keymap[code] != KEY_RESERVED) { | 314 | if (keypad->keymap[code] != KEY_RESERVED) { |
268 | keypad->rows |= 1 << row; | 315 | keypad->rows |= 1 << row; |
269 | keypad->cols |= 1 << col; | 316 | keypad->cols |= 1 << col; |
@@ -272,51 +319,17 @@ static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad) | |||
272 | } | 319 | } |
273 | } | 320 | } |
274 | 321 | ||
275 | #ifdef CONFIG_OF | ||
276 | static const struct stmpe_keypad_platform_data * | ||
277 | stmpe_keypad_of_probe(struct device *dev) | ||
278 | { | ||
279 | struct device_node *np = dev->of_node; | ||
280 | struct stmpe_keypad_platform_data *plat; | ||
281 | |||
282 | if (!np) | ||
283 | return ERR_PTR(-ENODEV); | ||
284 | |||
285 | plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); | ||
286 | if (!plat) | ||
287 | return ERR_PTR(-ENOMEM); | ||
288 | |||
289 | of_property_read_u32(np, "debounce-interval", &plat->debounce_ms); | ||
290 | of_property_read_u32(np, "st,scan-count", &plat->scan_count); | ||
291 | |||
292 | plat->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat"); | ||
293 | |||
294 | return plat; | ||
295 | } | ||
296 | #else | ||
297 | static inline const struct stmpe_keypad_platform_data * | ||
298 | stmpe_keypad_of_probe(struct device *dev) | ||
299 | { | ||
300 | return ERR_PTR(-EINVAL); | ||
301 | } | ||
302 | #endif | ||
303 | |||
304 | static int stmpe_keypad_probe(struct platform_device *pdev) | 322 | static int stmpe_keypad_probe(struct platform_device *pdev) |
305 | { | 323 | { |
306 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); | 324 | struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); |
307 | const struct stmpe_keypad_platform_data *plat; | 325 | struct device_node *np = pdev->dev.of_node; |
308 | struct stmpe_keypad *keypad; | 326 | struct stmpe_keypad *keypad; |
309 | struct input_dev *input; | 327 | struct input_dev *input; |
328 | u32 rows; | ||
329 | u32 cols; | ||
310 | int error; | 330 | int error; |
311 | int irq; | 331 | int irq; |
312 | 332 | ||
313 | plat = stmpe->pdata->keypad; | ||
314 | if (!plat) { | ||
315 | plat = stmpe_keypad_of_probe(&pdev->dev); | ||
316 | if (IS_ERR(plat)) | ||
317 | return PTR_ERR(plat); | ||
318 | } | ||
319 | |||
320 | irq = platform_get_irq(pdev, 0); | 333 | irq = platform_get_irq(pdev, 0); |
321 | if (irq < 0) | 334 | if (irq < 0) |
322 | return irq; | 335 | return irq; |
@@ -326,6 +339,13 @@ static int stmpe_keypad_probe(struct platform_device *pdev) | |||
326 | if (!keypad) | 339 | if (!keypad) |
327 | return -ENOMEM; | 340 | return -ENOMEM; |
328 | 341 | ||
342 | keypad->stmpe = stmpe; | ||
343 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; | ||
344 | |||
345 | of_property_read_u32(np, "debounce-interval", &keypad->debounce_ms); | ||
346 | of_property_read_u32(np, "st,scan-count", &keypad->scan_count); | ||
347 | keypad->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat"); | ||
348 | |||
329 | input = devm_input_allocate_device(&pdev->dev); | 349 | input = devm_input_allocate_device(&pdev->dev); |
330 | if (!input) | 350 | if (!input) |
331 | return -ENOMEM; | 351 | return -ENOMEM; |
@@ -334,23 +354,22 @@ static int stmpe_keypad_probe(struct platform_device *pdev) | |||
334 | input->id.bustype = BUS_I2C; | 354 | input->id.bustype = BUS_I2C; |
335 | input->dev.parent = &pdev->dev; | 355 | input->dev.parent = &pdev->dev; |
336 | 356 | ||
337 | error = matrix_keypad_build_keymap(plat->keymap_data, NULL, | 357 | error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols); |
338 | STMPE_KEYPAD_MAX_ROWS, | 358 | if (error) |
339 | STMPE_KEYPAD_MAX_COLS, | 359 | return error; |
360 | |||
361 | error = matrix_keypad_build_keymap(NULL, NULL, rows, cols, | ||
340 | keypad->keymap, input); | 362 | keypad->keymap, input); |
341 | if (error) | 363 | if (error) |
342 | return error; | 364 | return error; |
343 | 365 | ||
344 | input_set_capability(input, EV_MSC, MSC_SCAN); | 366 | input_set_capability(input, EV_MSC, MSC_SCAN); |
345 | if (!plat->no_autorepeat) | 367 | if (!keypad->no_autorepeat) |
346 | __set_bit(EV_REP, input->evbit); | 368 | __set_bit(EV_REP, input->evbit); |
347 | 369 | ||
348 | stmpe_keypad_fill_used_pins(keypad); | 370 | stmpe_keypad_fill_used_pins(keypad, rows, cols); |
349 | 371 | ||
350 | keypad->stmpe = stmpe; | ||
351 | keypad->plat = plat; | ||
352 | keypad->input = input; | 372 | keypad->input = input; |
353 | keypad->variant = &stmpe_keypad_variants[stmpe->partnum]; | ||
354 | 373 | ||
355 | error = stmpe_keypad_chip_init(keypad); | 374 | error = stmpe_keypad_chip_init(keypad); |
356 | if (error < 0) | 375 | if (error < 0) |