Commit bac22980b008ed810c56054d7f8bd73c02326b3f

Authored by Linus Torvalds

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

Showing 15 changed files Side-by-side Diff

Documentation/devicetree/bindings/input/gpio-keys.txt
... ... @@ -10,12 +10,13 @@
10 10 Each button (key) is represented as a sub-node of "gpio-keys":
11 11 Subnode properties:
12 12  
  13 + - gpios: OF device-tree gpio specification.
  14 + - interrupts: the interrupt line for that input.
13 15 - label: Descriptive name of the key.
14 16 - linux,code: Keycode to emit.
15 17  
16   -Required mutual exclusive subnode-properties:
17   - - gpios: OF device-tree gpio specification.
18   - - interrupts: the interrupt line for that input
  18 +Note that either "interrupts" or "gpios" properties can be omitted, but not
  19 +both at the same time. Specifying both properties is allowed.
19 20  
20 21 Optional subnode-properties:
21 22 - linux,input-type: Specify event type this button/key generates.
... ... @@ -23,6 +24,9 @@
23 24 - debounce-interval: Debouncing interval time in milliseconds.
24 25 If not specified defaults to 5.
25 26 - gpio-key,wakeup: Boolean, button can wake-up the system.
  27 + - linux,can-disable: Boolean, indicates that button is connected
  28 + to dedicated (not shared) interrupt which can be disabled to
  29 + suppress events from the button.
26 30  
27 31 Example nodes:
28 32  
Documentation/devicetree/bindings/input/stmpe-keypad.txt
... ... @@ -8,6 +8,8 @@
8 8 - debounce-interval : Debouncing interval time in milliseconds
9 9 - st,scan-count : Scanning cycles elapsed before key data is updated
10 10 - st,no-autorepeat : If specified device will not autorepeat
  11 + - keypad,num-rows : See ./matrix-keymap.txt
  12 + - keypad,num-columns : See ./matrix-keymap.txt
11 13  
12 14 Example:
13 15  
drivers/input/evdev.c
... ... @@ -28,6 +28,13 @@
28 28 #include <linux/cdev.h>
29 29 #include "input-compat.h"
30 30  
  31 +enum evdev_clock_type {
  32 + EV_CLK_REAL = 0,
  33 + EV_CLK_MONO,
  34 + EV_CLK_BOOT,
  35 + EV_CLK_MAX
  36 +};
  37 +
31 38 struct evdev {
32 39 int open;
33 40 struct input_handle handle;
34 41  
... ... @@ -49,12 +56,32 @@
49 56 struct fasync_struct *fasync;
50 57 struct evdev *evdev;
51 58 struct list_head node;
52   - int clkid;
  59 + int clk_type;
53 60 bool revoked;
54 61 unsigned int bufsize;
55 62 struct input_event buffer[];
56 63 };
57 64  
  65 +static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid)
  66 +{
  67 + switch (clkid) {
  68 +
  69 + case CLOCK_REALTIME:
  70 + client->clk_type = EV_CLK_REAL;
  71 + break;
  72 + case CLOCK_MONOTONIC:
  73 + client->clk_type = EV_CLK_MONO;
  74 + break;
  75 + case CLOCK_BOOTTIME:
  76 + client->clk_type = EV_CLK_BOOT;
  77 + break;
  78 + default:
  79 + return -EINVAL;
  80 + }
  81 +
  82 + return 0;
  83 +}
  84 +
58 85 /* flush queued events of type @type, caller must hold client->buffer_lock */
59 86 static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)
60 87 {
... ... @@ -108,8 +135,11 @@
108 135 struct input_event ev;
109 136 ktime_t time;
110 137  
111   - time = (client->clkid == CLOCK_MONOTONIC) ?
112   - ktime_get() : ktime_get_real();
  138 + time = client->clk_type == EV_CLK_REAL ?
  139 + ktime_get_real() :
  140 + client->clk_type == EV_CLK_MONO ?
  141 + ktime_get() :
  142 + ktime_get_boottime();
113 143  
114 144 ev.time = ktime_to_timeval(time);
115 145 ev.type = EV_SYN;
... ... @@ -159,7 +189,7 @@
159 189  
160 190 static void evdev_pass_values(struct evdev_client *client,
161 191 const struct input_value *vals, unsigned int count,
162   - ktime_t mono, ktime_t real)
  192 + ktime_t *ev_time)
163 193 {
164 194 struct evdev *evdev = client->evdev;
165 195 const struct input_value *v;
... ... @@ -169,8 +199,7 @@
169 199 if (client->revoked)
170 200 return;
171 201  
172   - event.time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ?
173   - mono : real);
  202 + event.time = ktime_to_timeval(ev_time[client->clk_type]);
174 203  
175 204 /* Interrupts are disabled, just acquire the lock. */
176 205 spin_lock(&client->buffer_lock);
177 206  
178 207  
179 208  
... ... @@ -198,21 +227,22 @@
198 227 {
199 228 struct evdev *evdev = handle->private;
200 229 struct evdev_client *client;
201   - ktime_t time_mono, time_real;
  230 + ktime_t ev_time[EV_CLK_MAX];
202 231  
203   - time_mono = ktime_get();
204   - time_real = ktime_mono_to_real(time_mono);
  232 + ev_time[EV_CLK_MONO] = ktime_get();
  233 + ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
  234 + ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],
  235 + TK_OFFS_BOOT);
205 236  
206 237 rcu_read_lock();
207 238  
208 239 client = rcu_dereference(evdev->grab);
209 240  
210 241 if (client)
211   - evdev_pass_values(client, vals, count, time_mono, time_real);
  242 + evdev_pass_values(client, vals, count, ev_time);
212 243 else
213 244 list_for_each_entry_rcu(client, &evdev->client_list, node)
214   - evdev_pass_values(client, vals, count,
215   - time_mono, time_real);
  245 + evdev_pass_values(client, vals, count, ev_time);
216 246  
217 247 rcu_read_unlock();
218 248 }
... ... @@ -877,10 +907,8 @@
877 907 case EVIOCSCLOCKID:
878 908 if (copy_from_user(&i, p, sizeof(unsigned int)))
879 909 return -EFAULT;
880   - if (i != CLOCK_MONOTONIC && i != CLOCK_REALTIME)
881   - return -EINVAL;
882   - client->clkid = i;
883   - return 0;
  910 +
  911 + return evdev_set_clk_type(client, i);
884 912  
885 913 case EVIOCGKEYCODE:
886 914 return evdev_handle_get_keycode(dev, p);
drivers/input/input.c
... ... @@ -1974,18 +1974,22 @@
1974 1974  
1975 1975 events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */
1976 1976  
1977   - for (i = 0; i < ABS_CNT; i++) {
1978   - if (test_bit(i, dev->absbit)) {
1979   - if (input_is_mt_axis(i))
1980   - events += mt_slots;
1981   - else
1982   - events++;
  1977 + if (test_bit(EV_ABS, dev->evbit)) {
  1978 + for (i = 0; i < ABS_CNT; i++) {
  1979 + if (test_bit(i, dev->absbit)) {
  1980 + if (input_is_mt_axis(i))
  1981 + events += mt_slots;
  1982 + else
  1983 + events++;
  1984 + }
1983 1985 }
1984 1986 }
1985 1987  
1986   - for (i = 0; i < REL_CNT; i++)
1987   - if (test_bit(i, dev->relbit))
1988   - events++;
  1988 + if (test_bit(EV_REL, dev->evbit)) {
  1989 + for (i = 0; i < REL_CNT; i++)
  1990 + if (test_bit(i, dev->relbit))
  1991 + events++;
  1992 + }
1989 1993  
1990 1994 /* Make room for KEY and MSC events */
1991 1995 events += 7;
drivers/input/keyboard/Kconfig
... ... @@ -559,6 +559,7 @@
559 559 config KEYBOARD_STMPE
560 560 tristate "STMPE keypad support"
561 561 depends on MFD_STMPE
  562 + depends on OF
562 563 select INPUT_MATRIXKMAP
563 564 help
564 565 Say Y here if you want to use the keypad controller on STMPE I/O
drivers/input/keyboard/gpio_keys.c
... ... @@ -35,9 +35,13 @@
35 35 struct gpio_button_data {
36 36 const struct gpio_keys_button *button;
37 37 struct input_dev *input;
38   - struct timer_list timer;
39   - struct work_struct work;
40   - unsigned int timer_debounce; /* in msecs */
  38 +
  39 + struct timer_list release_timer;
  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 45 unsigned int irq;
42 46 spinlock_t lock;
43 47 bool disabled;
44 48  
45 49  
... ... @@ -116,12 +120,15 @@
116 120 {
117 121 if (!bdata->disabled) {
118 122 /*
119   - * Disable IRQ and possible debouncing timer.
  123 + * Disable IRQ and associated timer/work structure.
120 124 */
121 125 disable_irq(bdata->irq);
122   - if (bdata->timer_debounce)
123   - del_timer_sync(&bdata->timer);
124 126  
  127 + if (gpio_is_valid(bdata->button->gpio))
  128 + cancel_delayed_work_sync(&bdata->work);
  129 + else
  130 + del_timer_sync(&bdata->release_timer);
  131 +
125 132 bdata->disabled = true;
126 133 }
127 134 }
... ... @@ -343,7 +350,7 @@
343 350 static void gpio_keys_gpio_work_func(struct work_struct *work)
344 351 {
345 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 355 gpio_keys_gpio_report_event(bdata);
349 356  
... ... @@ -351,13 +358,6 @@
351 358 pm_relax(bdata->input->dev.parent);
352 359 }
353 360  
354   -static 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   -
361 361 static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
362 362 {
363 363 struct gpio_button_data *bdata = dev_id;
364 364  
... ... @@ -366,12 +366,11 @@
366 366  
367 367 if (bdata->button->wakeup)
368 368 pm_stay_awake(bdata->input->dev.parent);
369   - if (bdata->timer_debounce)
370   - mod_timer(&bdata->timer,
371   - jiffies + msecs_to_jiffies(bdata->timer_debounce));
372   - else
373   - schedule_work(&bdata->work);
374 369  
  370 + mod_delayed_work(system_wq,
  371 + &bdata->work,
  372 + msecs_to_jiffies(bdata->software_debounce));
  373 +
375 374 return IRQ_HANDLED;
376 375 }
377 376  
... ... @@ -408,7 +407,7 @@
408 407 input_event(input, EV_KEY, button->code, 1);
409 408 input_sync(input);
410 409  
411   - if (!bdata->timer_debounce) {
  410 + if (!bdata->release_delay) {
412 411 input_event(input, EV_KEY, button->code, 0);
413 412 input_sync(input);
414 413 goto out;
... ... @@ -417,9 +416,9 @@
417 416 bdata->key_pressed = true;
418 417 }
419 418  
420   - if (bdata->timer_debounce)
421   - mod_timer(&bdata->timer,
422   - jiffies + msecs_to_jiffies(bdata->timer_debounce));
  419 + if (bdata->release_delay)
  420 + mod_timer(&bdata->release_timer,
  421 + jiffies + msecs_to_jiffies(bdata->release_delay));
423 422 out:
424 423 spin_unlock_irqrestore(&bdata->lock, flags);
425 424 return IRQ_HANDLED;
... ... @@ -429,10 +428,10 @@
429 428 {
430 429 struct gpio_button_data *bdata = data;
431 430  
432   - if (bdata->timer_debounce)
433   - del_timer_sync(&bdata->timer);
434   -
435   - cancel_work_sync(&bdata->work);
  431 + if (gpio_is_valid(bdata->button->gpio))
  432 + cancel_delayed_work_sync(&bdata->work);
  433 + else
  434 + del_timer_sync(&bdata->release_timer);
436 435 }
437 436  
438 437 static int gpio_keys_setup_key(struct platform_device *pdev,
439 438  
440 439  
441 440  
... ... @@ -466,23 +465,25 @@
466 465 button->debounce_interval * 1000);
467 466 /* use timer if gpiolib doesn't provide debounce */
468 467 if (error < 0)
469   - bdata->timer_debounce =
  468 + bdata->software_debounce =
470 469 button->debounce_interval;
471 470 }
472 471  
473   - irq = gpio_to_irq(button->gpio);
474   - if (irq < 0) {
475   - error = irq;
476   - dev_err(dev,
477   - "Unable to get irq number for GPIO %d, error %d\n",
478   - button->gpio, error);
479   - return error;
  472 + if (button->irq) {
  473 + bdata->irq = button->irq;
  474 + } else {
  475 + irq = gpio_to_irq(button->gpio);
  476 + if (irq < 0) {
  477 + error = irq;
  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);
484   - setup_timer(&bdata->timer,
485   - gpio_keys_gpio_timer, (unsigned long)bdata);
  486 + INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func);
486 487  
487 488 isr = gpio_keys_gpio_isr;
488 489 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
... ... @@ -499,8 +500,8 @@
499 500 return -EINVAL;
500 501 }
501 502  
502   - bdata->timer_debounce = button->debounce_interval;
503   - setup_timer(&bdata->timer,
  503 + bdata->release_delay = button->debounce_interval;
  504 + setup_timer(&bdata->release_timer,
504 505 gpio_keys_irq_timer, (unsigned long)bdata);
505 506  
506 507 isr = gpio_keys_irq_isr;
... ... @@ -510,7 +511,7 @@
510 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 515 * workqueue item.
515 516 */
516 517 error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata);
517 518  
518 519  
519 520  
520 521  
... ... @@ -618,34 +619,31 @@
618 619  
619 620 i = 0;
620 621 for_each_child_of_node(node, pp) {
621   - int gpio = -1;
622 622 enum of_gpio_flags flags;
623 623  
624 624 button = &pdata->buttons[i++];
625 625  
626   - if (!of_find_property(pp, "gpios", NULL)) {
627   - button->irq = irq_of_parse_and_map(pp, 0);
628   - if (button->irq == 0) {
629   - i--;
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;
  626 + button->gpio = of_get_gpio_flags(pp, 0, &flags);
  627 + if (button->gpio < 0) {
  628 + error = button->gpio;
  629 + if (error != -ENOENT) {
638 630 if (error != -EPROBE_DEFER)
639 631 dev_err(dev,
640 632 "Failed to get gpio flags, error: %d\n",
641 633 error);
642 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;
647   - button->active_low = flags & OF_GPIO_ACTIVE_LOW;
  640 + button->irq = irq_of_parse_and_map(pp, 0);
648 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 + }
  646 +
649 647 if (of_property_read_u32(pp, "linux,code", &button->code)) {
650 648 dev_err(dev, "Button without keycode: 0x%x\n",
651 649 button->gpio);
... ... @@ -658,6 +656,8 @@
658 656 button->type = EV_KEY;
659 657  
660 658 button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
  659 +
  660 + button->can_disable = !!of_get_property(pp, "linux,can-disable", NULL);
661 661  
662 662 if (of_property_read_u32(pp, "debounce-interval",
663 663 &button->debounce_interval))
drivers/input/keyboard/hil_kbd.c
... ... @@ -473,7 +473,7 @@
473 473 if (error)
474 474 goto bail1;
475 475  
476   - init_completion(&dev->cmd_done);
  476 + reinit_completion(&dev->cmd_done);
477 477 serio_write(serio, 0);
478 478 serio_write(serio, 0);
479 479 serio_write(serio, HIL_PKT_CMD >> 8);
... ... @@ -482,7 +482,7 @@
482 482 if (error)
483 483 goto bail1;
484 484  
485   - init_completion(&dev->cmd_done);
  485 + reinit_completion(&dev->cmd_done);
486 486 serio_write(serio, 0);
487 487 serio_write(serio, 0);
488 488 serio_write(serio, HIL_PKT_CMD >> 8);
... ... @@ -491,7 +491,7 @@
491 491 if (error)
492 492 goto bail1;
493 493  
494   - init_completion(&dev->cmd_done);
  494 + reinit_completion(&dev->cmd_done);
495 495 serio_write(serio, 0);
496 496 serio_write(serio, 0);
497 497 serio_write(serio, HIL_PKT_CMD >> 8);
drivers/input/keyboard/stmpe-keypad.c
... ... @@ -45,13 +45,14 @@
45 45 #define STMPE_KEYPAD_MAX_ROWS 8
46 46 #define STMPE_KEYPAD_MAX_COLS 8
47 47 #define STMPE_KEYPAD_ROW_SHIFT 3
48   -#define STMPE_KEYPAD_KEYMAP_SIZE \
  48 +#define STMPE_KEYPAD_KEYMAP_MAX_SIZE \
49 49 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
50 50  
51 51 /**
52 52 * struct stmpe_keypad_variant - model-specific attributes
53 53 * @auto_increment: whether the KPC_DATA_BYTE register address
54 54 * auto-increments on multiple read
  55 + * @set_pullup: whether the pins need to have their pull-ups set
55 56 * @num_data: number of data bytes
56 57 * @num_normal_data: number of normal keys' data bytes
57 58 * @max_cols: maximum number of columns supported
... ... @@ -61,6 +62,7 @@
61 62 */
62 63 struct stmpe_keypad_variant {
63 64 bool auto_increment;
  65 + bool set_pullup;
64 66 int num_data;
65 67 int num_normal_data;
66 68 int max_cols;
... ... @@ -81,6 +83,7 @@
81 83 },
82 84 [STMPE2401] = {
83 85 .auto_increment = false,
  86 + .set_pullup = true,
84 87 .num_data = 3,
85 88 .num_normal_data = 2,
86 89 .max_cols = 8,
... ... @@ -90,6 +93,7 @@
90 93 },
91 94 [STMPE2403] = {
92 95 .auto_increment = true,
  96 + .set_pullup = true,
93 97 .num_data = 5,
94 98 .num_normal_data = 3,
95 99 .max_cols = 8,
96 100  
97 101  
... ... @@ -99,16 +103,30 @@
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 120 struct stmpe_keypad {
103 121 struct stmpe *stmpe;
104 122 struct input_dev *input;
105 123 const struct stmpe_keypad_variant *variant;
106   - const struct stmpe_keypad_platform_data *plat;
107   -
  124 + unsigned int debounce_ms;
  125 + unsigned int scan_count;
  126 + bool no_autorepeat;
108 127 unsigned int rows;
109 128 unsigned int cols;
110   -
111   - unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
  129 + unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE];
112 130 };
113 131  
114 132 static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
115 133  
... ... @@ -171,7 +189,10 @@
171 189 unsigned int col_gpios = variant->col_gpios;
172 190 unsigned int row_gpios = variant->row_gpios;
173 191 struct stmpe *stmpe = keypad->stmpe;
  192 + u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB];
174 193 unsigned int pins = 0;
  194 + unsigned int pu_pins = 0;
  195 + int ret;
175 196 int i;
176 197  
177 198 /*
178 199  
... ... @@ -188,8 +209,10 @@
188 209 for (i = 0; i < variant->max_cols; i++) {
189 210 int num = __ffs(col_gpios);
190 211  
191   - if (keypad->cols & (1 << i))
  212 + if (keypad->cols & (1 << i)) {
192 213 pins |= 1 << num;
  214 + pu_pins |= 1 << num;
  215 + }
193 216  
194 217 col_gpios &= ~(1 << num);
195 218 }
196 219  
197 220  
198 221  
... ... @@ -203,20 +226,43 @@
203 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 256 static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
210 257 {
211   - const struct stmpe_keypad_platform_data *plat = keypad->plat;
212 258 const struct stmpe_keypad_variant *variant = keypad->variant;
213 259 struct stmpe *stmpe = keypad->stmpe;
214 260 int ret;
215 261  
216   - if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
  262 + if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
217 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 266 return -EINVAL;
221 267  
222 268 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
... ... @@ -245,7 +291,7 @@
245 291  
246 292 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
247 293 STMPE_KPC_CTRL_MSB_SCAN_COUNT,
248   - plat->scan_count << 4);
  294 + keypad->scan_count << 4);
249 295 if (ret < 0)
250 296 return ret;
251 297  
252 298  
253 299  
254 300  
... ... @@ -253,17 +299,18 @@
253 299 STMPE_KPC_CTRL_LSB_SCAN |
254 300 STMPE_KPC_CTRL_LSB_DEBOUNCE,
255 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 308 int row, col;
262 309  
263   - for (row = 0; row < STMPE_KEYPAD_MAX_ROWS; row++) {
264   - for (col = 0; col < STMPE_KEYPAD_MAX_COLS; col++) {
  310 + for (row = 0; row < used_rows; row++) {
  311 + for (col = 0; col < used_cols; col++) {
265 312 int code = MATRIX_SCAN_CODE(row, col,
266   - STMPE_KEYPAD_ROW_SHIFT);
  313 + STMPE_KEYPAD_ROW_SHIFT);
267 314 if (keypad->keymap[code] != KEY_RESERVED) {
268 315 keypad->rows |= 1 << row;
269 316 keypad->cols |= 1 << col;
270 317  
271 318  
272 319  
... ... @@ -272,51 +319,17 @@
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 322 static int stmpe_keypad_probe(struct platform_device *pdev)
305 323 {
306 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 326 struct stmpe_keypad *keypad;
309 327 struct input_dev *input;
  328 + u32 rows;
  329 + u32 cols;
310 330 int error;
311 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 333 irq = platform_get_irq(pdev, 0);
321 334 if (irq < 0)
322 335 return irq;
... ... @@ -326,6 +339,13 @@
326 339 if (!keypad)
327 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 349 input = devm_input_allocate_device(&pdev->dev);
330 350 if (!input)
331 351 return -ENOMEM;
332 352  
333 353  
334 354  
335 355  
... ... @@ -334,23 +354,22 @@
334 354 input->id.bustype = BUS_I2C;
335 355 input->dev.parent = &pdev->dev;
336 356  
337   - error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
338   - STMPE_KEYPAD_MAX_ROWS,
339   - STMPE_KEYPAD_MAX_COLS,
  357 + error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);
  358 + if (error)
  359 + return error;
  360 +
  361 + error = matrix_keypad_build_keymap(NULL, NULL, rows, cols,
340 362 keypad->keymap, input);
341 363 if (error)
342 364 return error;
343 365  
344 366 input_set_capability(input, EV_MSC, MSC_SCAN);
345   - if (!plat->no_autorepeat)
  367 + if (!keypad->no_autorepeat)
346 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 372 keypad->input = input;
353   - keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
354 373  
355 374 error = stmpe_keypad_chip_init(keypad);
356 375 if (error < 0)
drivers/input/mouse/alps.c
... ... @@ -881,6 +881,34 @@
881 881 unsigned char *pkt,
882 882 unsigned char pkt_id)
883 883 {
  884 + /*
  885 + * packet-fmt b7 b6 b5 b4 b3 b2 b1 b0
  886 + * Byte0 TWO & MULTI L 1 R M 1 Y0-2 Y0-1 Y0-0
  887 + * Byte0 NEW L 1 X1-5 1 1 Y0-2 Y0-1 Y0-0
  888 + * Byte1 Y0-10 Y0-9 Y0-8 Y0-7 Y0-6 Y0-5 Y0-4 Y0-3
  889 + * Byte2 X0-11 1 X0-10 X0-9 X0-8 X0-7 X0-6 X0-5
  890 + * Byte3 X1-11 1 X0-4 X0-3 1 X0-2 X0-1 X0-0
  891 + * Byte4 TWO X1-10 TWO X1-9 X1-8 X1-7 X1-6 X1-5 X1-4
  892 + * Byte4 MULTI X1-10 TWO X1-9 X1-8 X1-7 X1-6 Y1-5 1
  893 + * Byte4 NEW X1-10 TWO X1-9 X1-8 X1-7 X1-6 0 0
  894 + * Byte5 TWO & NEW Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 Y1-5 Y1-4
  895 + * Byte5 MULTI Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 F-1 F-0
  896 + * L: Left button
  897 + * R / M: Non-clickpads: Right / Middle button
  898 + * Clickpads: When > 2 fingers are down, and some fingers
  899 + * are in the button area, then the 2 coordinates reported
  900 + * are for fingers outside the button area and these report
  901 + * extra fingers being present in the right / left button
  902 + * area. Note these fingers are not added to the F field!
  903 + * so if a TWO packet is received and R = 1 then there are
  904 + * 3 fingers down, etc.
  905 + * TWO: 1: Two touches present, byte 0/4/5 are in TWO fmt
  906 + * 0: If byte 4 bit 0 is 1, then byte 0/4/5 are in MULTI fmt
  907 + * otherwise byte 0 bit 4 must be set and byte 0/4/5 are
  908 + * in NEW fmt
  909 + * F: Number of fingers - 3, 0 means 3 fingers, 1 means 4 ...
  910 + */
  911 +
884 912 mt[0].x = ((pkt[2] & 0x80) << 4);
885 913 mt[0].x |= ((pkt[2] & 0x3F) << 5);
886 914 mt[0].x |= ((pkt[3] & 0x30) >> 1);
887 915  
888 916  
889 917  
... ... @@ -919,18 +947,21 @@
919 947  
920 948 static int alps_get_mt_count(struct input_mt_pos *mt)
921 949 {
922   - int i;
  950 + int i, fingers = 0;
923 951  
924   - for (i = 0; i < MAX_TOUCHES && mt[i].x != 0 && mt[i].y != 0; i++)
925   - /* empty */;
  952 + for (i = 0; i < MAX_TOUCHES; i++) {
  953 + if (mt[i].x != 0 || mt[i].y != 0)
  954 + fingers++;
  955 + }
926 956  
927   - return i;
  957 + return fingers;
928 958 }
929 959  
930 960 static int alps_decode_packet_v7(struct alps_fields *f,
931 961 unsigned char *p,
932 962 struct psmouse *psmouse)
933 963 {
  964 + struct alps_data *priv = psmouse->private;
934 965 unsigned char pkt_id;
935 966  
936 967 pkt_id = alps_get_packet_id_v7(p);
937 968  
938 969  
... ... @@ -938,19 +969,52 @@
938 969 return 0;
939 970 if (pkt_id == V7_PACKET_ID_UNKNOWN)
940 971 return -1;
  972 + /*
  973 + * NEW packets are send to indicate a discontinuity in the finger
  974 + * coordinate reporting. Specifically a finger may have moved from
  975 + * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for
  976 + * us.
  977 + *
  978 + * NEW packets have 3 problems:
  979 + * 1) They do not contain middle / right button info (on non clickpads)
  980 + * this can be worked around by preserving the old button state
  981 + * 2) They do not contain an accurate fingercount, and they are
  982 + * typically send when the number of fingers changes. We cannot use
  983 + * the old finger count as that may mismatch with the amount of
  984 + * touch coordinates we've available in the NEW packet
  985 + * 3) Their x data for the second touch is inaccurate leading to
  986 + * a possible jump of the x coordinate by 16 units when the first
  987 + * non NEW packet comes in
  988 + * Since problems 2 & 3 cannot be worked around, just ignore them.
  989 + */
  990 + if (pkt_id == V7_PACKET_ID_NEW)
  991 + return 1;
941 992  
942 993 alps_get_finger_coordinate_v7(f->mt, p, pkt_id);
943 994  
944   - if (pkt_id == V7_PACKET_ID_TWO || pkt_id == V7_PACKET_ID_MULTI) {
945   - f->left = (p[0] & 0x80) >> 7;
  995 + if (pkt_id == V7_PACKET_ID_TWO)
  996 + f->fingers = alps_get_mt_count(f->mt);
  997 + else /* pkt_id == V7_PACKET_ID_MULTI */
  998 + f->fingers = 3 + (p[5] & 0x03);
  999 +
  1000 + f->left = (p[0] & 0x80) >> 7;
  1001 + if (priv->flags & ALPS_BUTTONPAD) {
  1002 + if (p[0] & 0x20)
  1003 + f->fingers++;
  1004 + if (p[0] & 0x10)
  1005 + f->fingers++;
  1006 + } else {
946 1007 f->right = (p[0] & 0x20) >> 5;
947 1008 f->middle = (p[0] & 0x10) >> 4;
948 1009 }
949 1010  
950   - if (pkt_id == V7_PACKET_ID_TWO)
951   - f->fingers = alps_get_mt_count(f->mt);
952   - else if (pkt_id == V7_PACKET_ID_MULTI)
953   - f->fingers = 3 + (p[5] & 0x03);
  1011 + /* Sometimes a single touch is reported in mt[1] rather then mt[0] */
  1012 + if (f->fingers == 1 && f->mt[0].x == 0 && f->mt[0].y == 0) {
  1013 + f->mt[0].x = f->mt[1].x;
  1014 + f->mt[0].y = f->mt[1].y;
  1015 + f->mt[1].x = 0;
  1016 + f->mt[1].y = 0;
  1017 + }
954 1018  
955 1019 return 0;
956 1020 }
drivers/input/mouse/trackpoint.c
... ... @@ -227,6 +227,7 @@
227 227 TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH, TP_DEF_UP_THRESH);
228 228 TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME, TP_DEF_Z_TIME);
229 229 TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV, TP_DEF_JENKS_CURV);
  230 +TRACKPOINT_INT_ATTR(drift_time, TP_DRIFT_TIME, TP_DEF_DRIFT_TIME);
230 231  
231 232 TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, 0,
232 233 TP_DEF_PTSON);
... ... @@ -246,6 +247,7 @@
246 247 &psmouse_attr_upthresh.dattr.attr,
247 248 &psmouse_attr_ztime.dattr.attr,
248 249 &psmouse_attr_jenks.dattr.attr,
  250 + &psmouse_attr_drift_time.dattr.attr,
249 251 &psmouse_attr_press_to_select.dattr.attr,
250 252 &psmouse_attr_skipback.dattr.attr,
251 253 &psmouse_attr_ext_dev.dattr.attr,
... ... @@ -312,6 +314,7 @@
312 314 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, upthresh);
313 315 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, ztime);
314 316 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, jenks);
  317 + TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, drift_time);
315 318  
316 319 /* toggles */
317 320 TRACKPOINT_UPDATE(in_power_on_state, psmouse, tp, press_to_select);
... ... @@ -332,6 +335,7 @@
332 335 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, upthresh);
333 336 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, ztime);
334 337 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, jenks);
  338 + TRACKPOINT_SET_POWER_ON_DEFAULT(tp, drift_time);
335 339 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, inertia);
336 340  
337 341 /* toggles */
drivers/input/mouse/trackpoint.h
... ... @@ -70,6 +70,9 @@
70 70 #define TP_UP_THRESH 0x5A /* Used to generate a 'click' on Z-axis */
71 71 #define TP_Z_TIME 0x5E /* How sharp of a press */
72 72 #define TP_JENKS_CURV 0x5D /* Minimum curvature for double click */
  73 +#define TP_DRIFT_TIME 0x5F /* How long a 'hands off' condition */
  74 + /* must last (x*107ms) for drift */
  75 + /* correction to occur */
73 76  
74 77 /*
75 78 * Toggling Flag bits
... ... @@ -120,6 +123,7 @@
120 123 #define TP_DEF_UP_THRESH 0xFF
121 124 #define TP_DEF_Z_TIME 0x26
122 125 #define TP_DEF_JENKS_CURV 0x87
  126 +#define TP_DEF_DRIFT_TIME 0x05
123 127  
124 128 /* Toggles */
125 129 #define TP_DEF_MB 0x00
... ... @@ -137,6 +141,7 @@
137 141 unsigned char draghys, mindrag;
138 142 unsigned char thresh, upthresh;
139 143 unsigned char ztime, jenks;
  144 + unsigned char drift_time;
140 145  
141 146 /* toggles */
142 147 unsigned char press_to_select;
drivers/input/touchscreen/edt-ft5x06.c
... ... @@ -850,9 +850,11 @@
850 850 }
851 851  
852 852 #define EDT_ATTR_CHECKSET(name, reg) \
  853 +do { \
853 854 if (pdata->name >= edt_ft5x06_attr_##name.limit_low && \
854 855 pdata->name <= edt_ft5x06_attr_##name.limit_high) \
855   - edt_ft5x06_register_write(tsdata, reg, pdata->name)
  856 + edt_ft5x06_register_write(tsdata, reg, pdata->name); \
  857 +} while (0)
856 858  
857 859 #define EDT_GET_PROP(name, reg) { \
858 860 u32 val; \
... ... @@ -519,6 +519,7 @@
519 519 [STMPE_IDX_GPDR_LSB] = STMPE1601_REG_GPIO_SET_DIR_LSB,
520 520 [STMPE_IDX_GPRER_LSB] = STMPE1601_REG_GPIO_RE_LSB,
521 521 [STMPE_IDX_GPFER_LSB] = STMPE1601_REG_GPIO_FE_LSB,
  522 + [STMPE_IDX_GPPUR_LSB] = STMPE1601_REG_GPIO_PU_LSB,
522 523 [STMPE_IDX_GPAFR_U_MSB] = STMPE1601_REG_GPIO_AF_U_MSB,
523 524 [STMPE_IDX_IEGPIOR_LSB] = STMPE1601_REG_INT_EN_GPIO_MASK_LSB,
524 525 [STMPE_IDX_ISGPIOR_MSB] = STMPE1601_REG_INT_STA_GPIO_MSB,
... ... @@ -667,6 +668,7 @@
667 668 [STMPE_IDX_GPDR_LSB] = STMPE1801_REG_GPIO_SET_DIR_LOW,
668 669 [STMPE_IDX_GPRER_LSB] = STMPE1801_REG_GPIO_RE_LOW,
669 670 [STMPE_IDX_GPFER_LSB] = STMPE1801_REG_GPIO_FE_LOW,
  671 + [STMPE_IDX_GPPUR_LSB] = STMPE1801_REG_GPIO_PULL_UP_LOW,
670 672 [STMPE_IDX_IEGPIOR_LSB] = STMPE1801_REG_INT_EN_GPIO_MASK_LOW,
671 673 [STMPE_IDX_ISGPIOR_LSB] = STMPE1801_REG_INT_STA_GPIO_LOW,
672 674 };
... ... @@ -750,6 +752,8 @@
750 752 [STMPE_IDX_GPDR_LSB] = STMPE24XX_REG_GPDR_LSB,
751 753 [STMPE_IDX_GPRER_LSB] = STMPE24XX_REG_GPRER_LSB,
752 754 [STMPE_IDX_GPFER_LSB] = STMPE24XX_REG_GPFER_LSB,
  755 + [STMPE_IDX_GPPUR_LSB] = STMPE24XX_REG_GPPUR_LSB,
  756 + [STMPE_IDX_GPPDR_LSB] = STMPE24XX_REG_GPPDR_LSB,
753 757 [STMPE_IDX_GPAFR_U_MSB] = STMPE24XX_REG_GPAFR_U_MSB,
754 758 [STMPE_IDX_IEGPIOR_LSB] = STMPE24XX_REG_IEGPIOR_LSB,
755 759 [STMPE_IDX_ISGPIOR_MSB] = STMPE24XX_REG_ISGPIOR_MSB,
... ... @@ -188,6 +188,7 @@
188 188 #define STMPE1601_REG_GPIO_ED_MSB 0x8A
189 189 #define STMPE1601_REG_GPIO_RE_LSB 0x8D
190 190 #define STMPE1601_REG_GPIO_FE_LSB 0x8F
  191 +#define STMPE1601_REG_GPIO_PU_LSB 0x91
191 192 #define STMPE1601_REG_GPIO_AF_U_MSB 0x92
192 193  
193 194 #define STMPE1601_SYS_CTRL_ENABLE_GPIO (1 << 3)
... ... @@ -276,6 +277,8 @@
276 277 #define STMPE24XX_REG_GPEDR_MSB 0x8C
277 278 #define STMPE24XX_REG_GPRER_LSB 0x91
278 279 #define STMPE24XX_REG_GPFER_LSB 0x94
  280 +#define STMPE24XX_REG_GPPUR_LSB 0x97
  281 +#define STMPE24XX_REG_GPPDR_LSB 0x9a
279 282 #define STMPE24XX_REG_GPAFR_U_MSB 0x9B
280 283  
281 284 #define STMPE24XX_SYS_CTRL_ENABLE_GPIO (1 << 3)
include/linux/mfd/stmpe.h
... ... @@ -50,6 +50,8 @@
50 50 STMPE_IDX_GPEDR_MSB,
51 51 STMPE_IDX_GPRER_LSB,
52 52 STMPE_IDX_GPFER_LSB,
  53 + STMPE_IDX_GPPUR_LSB,
  54 + STMPE_IDX_GPPDR_LSB,
53 55 STMPE_IDX_GPAFR_U_MSB,
54 56 STMPE_IDX_IEGPIOR_LSB,
55 57 STMPE_IDX_ISGPIOR_LSB,
... ... @@ -113,24 +115,6 @@
113 115 extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
114 116 extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
115 117  
116   -struct matrix_keymap_data;
117   -
118   -/**
119   - * struct stmpe_keypad_platform_data - STMPE keypad platform data
120   - * @keymap_data: key map table and size
121   - * @debounce_ms: debounce interval, in ms. Maximum is
122   - * %STMPE_KEYPAD_MAX_DEBOUNCE.
123   - * @scan_count: number of key scanning cycles to confirm key data.
124   - * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
125   - * @no_autorepeat: disable key autorepeat
126   - */
127   -struct stmpe_keypad_platform_data {
128   - const struct matrix_keymap_data *keymap_data;
129   - unsigned int debounce_ms;
130   - unsigned int scan_count;
131   - bool no_autorepeat;
132   -};
133   -
134 118 #define STMPE_GPIO_NOREQ_811_TOUCH (0xf0)
135 119  
136 120 /**
... ... @@ -199,7 +183,6 @@
199 183 * @irq_gpio: gpio number over which irq will be requested (significant only if
200 184 * irq_over_gpio is true)
201 185 * @gpio: GPIO-specific platform data
202   - * @keypad: keypad-specific platform data
203 186 * @ts: touchscreen-specific platform data
204 187 */
205 188 struct stmpe_platform_data {
... ... @@ -212,7 +195,6 @@
212 195 int autosleep_timeout;
213 196  
214 197 struct stmpe_gpio_platform_data *gpio;
215   - struct stmpe_keypad_platform_data *keypad;
216 198 struct stmpe_ts_platform_data *ts;
217 199 };
218 200