aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-30 19:59:59 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-30 19:59:59 -0500
commitbac22980b008ed810c56054d7f8bd73c02326b3f (patch)
tree820dd874b5c09d9c00506595c7aa05a093bd0f62 /drivers/input/keyboard
parent831a39c241e1254b6ddb8dea3144e77b9bbf44b3 (diff)
parentcceeb872d60f77f9305d9e138c7d0acee1d60038 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
Pull input layer fixes from Dmitry Torokhov: "Fixes for v7 protocol for ALPS devices and few other driver fixes. Also users can request input events to be stamped with boot time timestamps, in addition to real and monotonic timestamps" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: Input: hil_kbd - fix incorrect use of init_completion Input: alps - v7: document the v7 touchpad packet protocol Input: alps - v7: fix finger counting for > 2 fingers on clickpads Input: alps - v7: sometimes a single touch is reported in mt[1] Input: alps - v7: ignore new packets Input: evdev - add CLOCK_BOOTTIME support Input: psmouse - expose drift duration for IBM trackpoints Input: stmpe - bias keypad columns properly Input: stmpe - enforce device tree only mode mfd: stmpe: add pull up/down register offsets for STMPE Input: optimize events_per_packet count calculation Input: edt-ft5x06 - fixed a macro coding style issue Input: gpio_keys - replace timer and workqueue with delayed workqueue Input: gpio_keys - allow separating gpio and irq in device tree
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/Kconfig1
-rw-r--r--drivers/input/keyboard/gpio_keys.c114
-rw-r--r--drivers/input/keyboard/hil_kbd.c6
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c141
4 files changed, 141 insertions, 121 deletions
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 96ee26c555e0..a5d9b3f3c871 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -559,6 +559,7 @@ config KEYBOARD_SH_KEYSC
559config KEYBOARD_STMPE 559config KEYBOARD_STMPE
560 tristate "STMPE keypad support" 560 tristate "STMPE keypad support"
561 depends on MFD_STMPE 561 depends on MFD_STMPE
562 depends on OF
562 select INPUT_MATRIXKMAP 563 select INPUT_MATRIXKMAP
563 help 564 help
564 Say Y here if you want to use the keypad controller on STMPE I/O 565 Say Y here if you want to use the keypad controller on STMPE I/O
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index d4dd78a7d56b..883d6aed5b9a 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -35,9 +35,13 @@
35struct gpio_button_data { 35struct gpio_button_data {
36 const struct gpio_keys_button *button; 36 const struct gpio_keys_button *button;
37 struct input_dev *input; 37 struct input_dev *input;
38 struct timer_list timer; 38
39 struct work_struct work; 39 struct timer_list release_timer;
40 unsigned int timer_debounce; /* in msecs */ 40 unsigned int release_delay; /* in msecs, for IRQ-only buttons */
41
42 struct delayed_work work;
43 unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */
44
41 unsigned int irq; 45 unsigned int irq;
42 spinlock_t lock; 46 spinlock_t lock;
43 bool disabled; 47 bool disabled;
@@ -116,11 +120,14 @@ static void gpio_keys_disable_button(struct gpio_button_data *bdata)
116{ 120{
117 if (!bdata->disabled) { 121 if (!bdata->disabled) {
118 /* 122 /*
119 * Disable IRQ and possible debouncing timer. 123 * Disable IRQ and associated timer/work structure.
120 */ 124 */
121 disable_irq(bdata->irq); 125 disable_irq(bdata->irq);
122 if (bdata->timer_debounce) 126
123 del_timer_sync(&bdata->timer); 127 if (gpio_is_valid(bdata->button->gpio))
128 cancel_delayed_work_sync(&bdata->work);
129 else
130 del_timer_sync(&bdata->release_timer);
124 131
125 bdata->disabled = true; 132 bdata->disabled = true;
126 } 133 }
@@ -343,7 +350,7 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
343static void gpio_keys_gpio_work_func(struct work_struct *work) 350static void gpio_keys_gpio_work_func(struct work_struct *work)
344{ 351{
345 struct gpio_button_data *bdata = 352 struct gpio_button_data *bdata =
346 container_of(work, struct gpio_button_data, work); 353 container_of(work, struct gpio_button_data, work.work);
347 354
348 gpio_keys_gpio_report_event(bdata); 355 gpio_keys_gpio_report_event(bdata);
349 356
@@ -351,13 +358,6 @@ static void gpio_keys_gpio_work_func(struct work_struct *work)
351 pm_relax(bdata->input->dev.parent); 358 pm_relax(bdata->input->dev.parent);
352} 359}
353 360
354static void gpio_keys_gpio_timer(unsigned long _data)
355{
356 struct gpio_button_data *bdata = (struct gpio_button_data *)_data;
357
358 schedule_work(&bdata->work);
359}
360
361static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) 361static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
362{ 362{
363 struct gpio_button_data *bdata = dev_id; 363 struct gpio_button_data *bdata = dev_id;
@@ -366,11 +366,10 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
366 366
367 if (bdata->button->wakeup) 367 if (bdata->button->wakeup)
368 pm_stay_awake(bdata->input->dev.parent); 368 pm_stay_awake(bdata->input->dev.parent);
369 if (bdata->timer_debounce) 369
370 mod_timer(&bdata->timer, 370 mod_delayed_work(system_wq,
371 jiffies + msecs_to_jiffies(bdata->timer_debounce)); 371 &bdata->work,
372 else 372 msecs_to_jiffies(bdata->software_debounce));
373 schedule_work(&bdata->work);
374 373
375 return IRQ_HANDLED; 374 return IRQ_HANDLED;
376} 375}
@@ -408,7 +407,7 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
408 input_event(input, EV_KEY, button->code, 1); 407 input_event(input, EV_KEY, button->code, 1);
409 input_sync(input); 408 input_sync(input);
410 409
411 if (!bdata->timer_debounce) { 410 if (!bdata->release_delay) {
412 input_event(input, EV_KEY, button->code, 0); 411 input_event(input, EV_KEY, button->code, 0);
413 input_sync(input); 412 input_sync(input);
414 goto out; 413 goto out;
@@ -417,9 +416,9 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
417 bdata->key_pressed = true; 416 bdata->key_pressed = true;
418 } 417 }
419 418
420 if (bdata->timer_debounce) 419 if (bdata->release_delay)
421 mod_timer(&bdata->timer, 420 mod_timer(&bdata->release_timer,
422 jiffies + msecs_to_jiffies(bdata->timer_debounce)); 421 jiffies + msecs_to_jiffies(bdata->release_delay));
423out: 422out:
424 spin_unlock_irqrestore(&bdata->lock, flags); 423 spin_unlock_irqrestore(&bdata->lock, flags);
425 return IRQ_HANDLED; 424 return IRQ_HANDLED;
@@ -429,10 +428,10 @@ static void gpio_keys_quiesce_key(void *data)
429{ 428{
430 struct gpio_button_data *bdata = data; 429 struct gpio_button_data *bdata = data;
431 430
432 if (bdata->timer_debounce) 431 if (gpio_is_valid(bdata->button->gpio))
433 del_timer_sync(&bdata->timer); 432 cancel_delayed_work_sync(&bdata->work);
434 433 else
435 cancel_work_sync(&bdata->work); 434 del_timer_sync(&bdata->release_timer);
436} 435}
437 436
438static int gpio_keys_setup_key(struct platform_device *pdev, 437static int gpio_keys_setup_key(struct platform_device *pdev,
@@ -466,23 +465,25 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
466 button->debounce_interval * 1000); 465 button->debounce_interval * 1000);
467 /* use timer if gpiolib doesn't provide debounce */ 466 /* use timer if gpiolib doesn't provide debounce */
468 if (error < 0) 467 if (error < 0)
469 bdata->timer_debounce = 468 bdata->software_debounce =
470 button->debounce_interval; 469 button->debounce_interval;
471 } 470 }
472 471
473 irq = gpio_to_irq(button->gpio); 472 if (button->irq) {
474 if (irq < 0) { 473 bdata->irq = button->irq;
475 error = irq; 474 } else {
476 dev_err(dev, 475 irq = gpio_to_irq(button->gpio);
477 "Unable to get irq number for GPIO %d, error %d\n", 476 if (irq < 0) {
478 button->gpio, error); 477 error = irq;
479 return error; 478 dev_err(dev,
479 "Unable to get irq number for GPIO %d, error %d\n",
480 button->gpio, error);
481 return error;
482 }
483 bdata->irq = irq;
480 } 484 }
481 bdata->irq = irq;
482 485
483 INIT_WORK(&bdata->work, gpio_keys_gpio_work_func); 486 INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func);
484 setup_timer(&bdata->timer,
485 gpio_keys_gpio_timer, (unsigned long)bdata);
486 487
487 isr = gpio_keys_gpio_isr; 488 isr = gpio_keys_gpio_isr;
488 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; 489 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
@@ -499,8 +500,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
499 return -EINVAL; 500 return -EINVAL;
500 } 501 }
501 502
502 bdata->timer_debounce = button->debounce_interval; 503 bdata->release_delay = button->debounce_interval;
503 setup_timer(&bdata->timer, 504 setup_timer(&bdata->release_timer,
504 gpio_keys_irq_timer, (unsigned long)bdata); 505 gpio_keys_irq_timer, (unsigned long)bdata);
505 506
506 isr = gpio_keys_irq_isr; 507 isr = gpio_keys_irq_isr;
@@ -510,7 +511,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
510 input_set_capability(input, button->type ?: EV_KEY, button->code); 511 input_set_capability(input, button->type ?: EV_KEY, button->code);
511 512
512 /* 513 /*
513 * Install custom action to cancel debounce timer and 514 * Install custom action to cancel release timer and
514 * workqueue item. 515 * workqueue item.
515 */ 516 */
516 error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata); 517 error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata);
@@ -618,33 +619,30 @@ gpio_keys_get_devtree_pdata(struct device *dev)
618 619
619 i = 0; 620 i = 0;
620 for_each_child_of_node(node, pp) { 621 for_each_child_of_node(node, pp) {
621 int gpio = -1;
622 enum of_gpio_flags flags; 622 enum of_gpio_flags flags;
623 623
624 button = &pdata->buttons[i++]; 624 button = &pdata->buttons[i++];
625 625
626 if (!of_find_property(pp, "gpios", NULL)) { 626 button->gpio = of_get_gpio_flags(pp, 0, &flags);
627 button->irq = irq_of_parse_and_map(pp, 0); 627 if (button->gpio < 0) {
628 if (button->irq == 0) { 628 error = button->gpio;
629 i--; 629 if (error != -ENOENT) {
630 pdata->nbuttons--;
631 dev_warn(dev, "Found button without gpios or irqs\n");
632 continue;
633 }
634 } else {
635 gpio = of_get_gpio_flags(pp, 0, &flags);
636 if (gpio < 0) {
637 error = gpio;
638 if (error != -EPROBE_DEFER) 630 if (error != -EPROBE_DEFER)
639 dev_err(dev, 631 dev_err(dev,
640 "Failed to get gpio flags, error: %d\n", 632 "Failed to get gpio flags, error: %d\n",
641 error); 633 error);
642 return ERR_PTR(error); 634 return ERR_PTR(error);
643 } 635 }
636 } else {
637 button->active_low = flags & OF_GPIO_ACTIVE_LOW;
644 } 638 }
645 639
646 button->gpio = gpio; 640 button->irq = irq_of_parse_and_map(pp, 0);
647 button->active_low = flags & OF_GPIO_ACTIVE_LOW; 641
642 if (!gpio_is_valid(button->gpio) && !button->irq) {
643 dev_err(dev, "Found button without gpios or irqs\n");
644 return ERR_PTR(-EINVAL);
645 }
648 646
649 if (of_property_read_u32(pp, "linux,code", &button->code)) { 647 if (of_property_read_u32(pp, "linux,code", &button->code)) {
650 dev_err(dev, "Button without keycode: 0x%x\n", 648 dev_err(dev, "Button without keycode: 0x%x\n",
@@ -659,6 +657,8 @@ gpio_keys_get_devtree_pdata(struct device *dev)
659 657
660 button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); 658 button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
661 659
660 button->can_disable = !!of_get_property(pp, "linux,can-disable", NULL);
661
662 if (of_property_read_u32(pp, "debounce-interval", 662 if (of_property_read_u32(pp, "debounce-interval",
663 &button->debounce_interval)) 663 &button->debounce_interval))
664 button->debounce_interval = 5; 664 button->debounce_interval = 5;
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index 610a8af795a1..5b152f25a8e1 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -473,7 +473,7 @@ static int hil_dev_connect(struct serio *serio, struct serio_driver *drv)
473 if (error) 473 if (error)
474 goto bail1; 474 goto bail1;
475 475
476 init_completion(&dev->cmd_done); 476 reinit_completion(&dev->cmd_done);
477 serio_write(serio, 0); 477 serio_write(serio, 0);
478 serio_write(serio, 0); 478 serio_write(serio, 0);
479 serio_write(serio, HIL_PKT_CMD >> 8); 479 serio_write(serio, HIL_PKT_CMD >> 8);
@@ -482,7 +482,7 @@ static int hil_dev_connect(struct serio *serio, struct serio_driver *drv)
482 if (error) 482 if (error)
483 goto bail1; 483 goto bail1;
484 484
485 init_completion(&dev->cmd_done); 485 reinit_completion(&dev->cmd_done);
486 serio_write(serio, 0); 486 serio_write(serio, 0);
487 serio_write(serio, 0); 487 serio_write(serio, 0);
488 serio_write(serio, HIL_PKT_CMD >> 8); 488 serio_write(serio, HIL_PKT_CMD >> 8);
@@ -491,7 +491,7 @@ static int hil_dev_connect(struct serio *serio, struct serio_driver *drv)
491 if (error) 491 if (error)
492 goto bail1; 492 goto bail1;
493 493
494 init_completion(&dev->cmd_done); 494 reinit_completion(&dev->cmd_done);
495 serio_write(serio, 0); 495 serio_write(serio, 0);
496 serio_write(serio, 0); 496 serio_write(serio, 0);
497 serio_write(serio, HIL_PKT_CMD >> 8); 497 serio_write(serio, HIL_PKT_CMD >> 8);
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 */
62struct stmpe_keypad_variant { 63struct 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 */
102struct stmpe_keypad { 120struct 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
114static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data) 132static 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
209static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad) 256static 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
259static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad) 305static 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
276static const struct stmpe_keypad_platform_data *
277stmpe_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
297static inline const struct stmpe_keypad_platform_data *
298stmpe_keypad_of_probe(struct device *dev)
299{
300 return ERR_PTR(-EINVAL);
301}
302#endif
303
304static int stmpe_keypad_probe(struct platform_device *pdev) 322static 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)