···1010Each button (key) is represented as a sub-node of "gpio-keys":1111Subnode properties:12121313+ - gpios: OF device-tree gpio specification.1414+ - interrupts: the interrupt line for that input.1315 - label: Descriptive name of the key.1416 - linux,code: Keycode to emit.15171616-Required mutual exclusive subnode-properties:1717- - gpios: OF device-tree gpio specification.1818- - interrupts: the interrupt line for that input1818+Note that either "interrupts" or "gpios" properties can be omitted, but not1919+both at the same time. Specifying both properties is allowed.19202021Optional subnode-properties:2122 - linux,input-type: Specify event type this button/key generates.···2423 - debounce-interval: Debouncing interval time in milliseconds.2524 If not specified defaults to 5.2625 - gpio-key,wakeup: Boolean, button can wake-up the system.2626+ - linux,can-disable: Boolean, indicates that button is connected2727+ to dedicated (not shared) interrupt which can be disabled to2828+ suppress events from the button.27292830Example nodes:2931
···88 - debounce-interval : Debouncing interval time in milliseconds99 - st,scan-count : Scanning cycles elapsed before key data is updated1010 - st,no-autorepeat : If specified device will not autorepeat1111+ - keypad,num-rows : See ./matrix-keymap.txt1212+ - keypad,num-columns : See ./matrix-keymap.txt11131214Example:1315
+44-16
drivers/input/evdev.c
···2828#include <linux/cdev.h>2929#include "input-compat.h"30303131+enum evdev_clock_type {3232+ EV_CLK_REAL = 0,3333+ EV_CLK_MONO,3434+ EV_CLK_BOOT,3535+ EV_CLK_MAX3636+};3737+3138struct evdev {3239 int open;3340 struct input_handle handle;···5649 struct fasync_struct *fasync;5750 struct evdev *evdev;5851 struct list_head node;5959- int clkid;5252+ int clk_type;6053 bool revoked;6154 unsigned int bufsize;6255 struct input_event buffer[];6356};5757+5858+static int evdev_set_clk_type(struct evdev_client *client, unsigned int clkid)5959+{6060+ switch (clkid) {6161+6262+ case CLOCK_REALTIME:6363+ client->clk_type = EV_CLK_REAL;6464+ break;6565+ case CLOCK_MONOTONIC:6666+ client->clk_type = EV_CLK_MONO;6767+ break;6868+ case CLOCK_BOOTTIME:6969+ client->clk_type = EV_CLK_BOOT;7070+ break;7171+ default:7272+ return -EINVAL;7373+ }7474+7575+ return 0;7676+}64776578/* flush queued events of type @type, caller must hold client->buffer_lock */6679static void __evdev_flush_queue(struct evdev_client *client, unsigned int type)···135108 struct input_event ev;136109 ktime_t time;137110138138- time = (client->clkid == CLOCK_MONOTONIC) ?139139- ktime_get() : ktime_get_real();111111+ time = client->clk_type == EV_CLK_REAL ?112112+ ktime_get_real() :113113+ client->clk_type == EV_CLK_MONO ?114114+ ktime_get() :115115+ ktime_get_boottime();140116141117 ev.time = ktime_to_timeval(time);142118 ev.type = EV_SYN;···189159190160static void evdev_pass_values(struct evdev_client *client,191161 const struct input_value *vals, unsigned int count,192192- ktime_t mono, ktime_t real)162162+ ktime_t *ev_time)193163{194164 struct evdev *evdev = client->evdev;195165 const struct input_value *v;···199169 if (client->revoked)200170 return;201171202202- event.time = ktime_to_timeval(client->clkid == CLOCK_MONOTONIC ?203203- mono : real);172172+ event.time = ktime_to_timeval(ev_time[client->clk_type]);204173205174 /* Interrupts are disabled, just acquire the lock. */206175 spin_lock(&client->buffer_lock);···227198{228199 struct evdev *evdev = handle->private;229200 struct evdev_client *client;230230- ktime_t time_mono, time_real;201201+ ktime_t ev_time[EV_CLK_MAX];231202232232- time_mono = ktime_get();233233- time_real = ktime_mono_to_real(time_mono);203203+ ev_time[EV_CLK_MONO] = ktime_get();204204+ ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);205205+ ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],206206+ TK_OFFS_BOOT);234207235208 rcu_read_lock();236209237210 client = rcu_dereference(evdev->grab);238211239212 if (client)240240- evdev_pass_values(client, vals, count, time_mono, time_real);213213+ evdev_pass_values(client, vals, count, ev_time);241214 else242215 list_for_each_entry_rcu(client, &evdev->client_list, node)243243- evdev_pass_values(client, vals, count,244244- time_mono, time_real);216216+ evdev_pass_values(client, vals, count, ev_time);245217246218 rcu_read_unlock();247219}···907877 case EVIOCSCLOCKID:908878 if (copy_from_user(&i, p, sizeof(unsigned int)))909879 return -EFAULT;910910- if (i != CLOCK_MONOTONIC && i != CLOCK_REALTIME)911911- return -EINVAL;912912- client->clkid = i;913913- return 0;880880+881881+ return evdev_set_clk_type(client, i);914882915883 case EVIOCGKEYCODE:916884 return evdev_handle_get_keycode(dev, p);
+13-9
drivers/input/input.c
···1974197419751975 events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */1976197619771977- for (i = 0; i < ABS_CNT; i++) {19781978- if (test_bit(i, dev->absbit)) {19791979- if (input_is_mt_axis(i))19801980- events += mt_slots;19811981- else19821982- events++;19771977+ if (test_bit(EV_ABS, dev->evbit)) {19781978+ for (i = 0; i < ABS_CNT; i++) {19791979+ if (test_bit(i, dev->absbit)) {19801980+ if (input_is_mt_axis(i))19811981+ events += mt_slots;19821982+ else19831983+ events++;19841984+ }19831985 }19841986 }1985198719861986- for (i = 0; i < REL_CNT; i++)19871987- if (test_bit(i, dev->relbit))19881988- events++;19881988+ if (test_bit(EV_REL, dev->evbit)) {19891989+ for (i = 0; i < REL_CNT; i++)19901990+ if (test_bit(i, dev->relbit))19911991+ events++;19921992+ }1989199319901994 /* Make room for KEY and MSC events */19911995 events += 7;
+1
drivers/input/keyboard/Kconfig
···559559config KEYBOARD_STMPE560560 tristate "STMPE keypad support"561561 depends on MFD_STMPE562562+ depends on OF562563 select INPUT_MATRIXKMAP563564 help564565 Say Y here if you want to use the keypad controller on STMPE I/O
+57-57
drivers/input/keyboard/gpio_keys.c
···3535struct gpio_button_data {3636 const struct gpio_keys_button *button;3737 struct input_dev *input;3838- struct timer_list timer;3939- struct work_struct work;4040- unsigned int timer_debounce; /* in msecs */3838+3939+ struct timer_list release_timer;4040+ unsigned int release_delay; /* in msecs, for IRQ-only buttons */4141+4242+ struct delayed_work work;4343+ unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */4444+4145 unsigned int irq;4246 spinlock_t lock;4347 bool disabled;···120116{121117 if (!bdata->disabled) {122118 /*123123- * Disable IRQ and possible debouncing timer.119119+ * Disable IRQ and associated timer/work structure.124120 */125121 disable_irq(bdata->irq);126126- if (bdata->timer_debounce)127127- del_timer_sync(&bdata->timer);122122+123123+ if (gpio_is_valid(bdata->button->gpio))124124+ cancel_delayed_work_sync(&bdata->work);125125+ else126126+ del_timer_sync(&bdata->release_timer);128127129128 bdata->disabled = true;130129 }···350343static void gpio_keys_gpio_work_func(struct work_struct *work)351344{352345 struct gpio_button_data *bdata =353353- container_of(work, struct gpio_button_data, work);346346+ container_of(work, struct gpio_button_data, work.work);354347355348 gpio_keys_gpio_report_event(bdata);356349357350 if (bdata->button->wakeup)358351 pm_relax(bdata->input->dev.parent);359359-}360360-361361-static void gpio_keys_gpio_timer(unsigned long _data)362362-{363363- struct gpio_button_data *bdata = (struct gpio_button_data *)_data;364364-365365- schedule_work(&bdata->work);366352}367353368354static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)···366366367367 if (bdata->button->wakeup)368368 pm_stay_awake(bdata->input->dev.parent);369369- if (bdata->timer_debounce)370370- mod_timer(&bdata->timer,371371- jiffies + msecs_to_jiffies(bdata->timer_debounce));372372- else373373- schedule_work(&bdata->work);369369+370370+ mod_delayed_work(system_wq,371371+ &bdata->work,372372+ msecs_to_jiffies(bdata->software_debounce));374373375374 return IRQ_HANDLED;376375}···407408 input_event(input, EV_KEY, button->code, 1);408409 input_sync(input);409410410410- if (!bdata->timer_debounce) {411411+ if (!bdata->release_delay) {411412 input_event(input, EV_KEY, button->code, 0);412413 input_sync(input);413414 goto out;···416417 bdata->key_pressed = true;417418 }418419419419- if (bdata->timer_debounce)420420- mod_timer(&bdata->timer,421421- jiffies + msecs_to_jiffies(bdata->timer_debounce));420420+ if (bdata->release_delay)421421+ mod_timer(&bdata->release_timer,422422+ jiffies + msecs_to_jiffies(bdata->release_delay));422423out:423424 spin_unlock_irqrestore(&bdata->lock, flags);424425 return IRQ_HANDLED;···428429{429430 struct gpio_button_data *bdata = data;430431431431- if (bdata->timer_debounce)432432- del_timer_sync(&bdata->timer);433433-434434- cancel_work_sync(&bdata->work);432432+ if (gpio_is_valid(bdata->button->gpio))433433+ cancel_delayed_work_sync(&bdata->work);434434+ else435435+ del_timer_sync(&bdata->release_timer);435436}436437437438static int gpio_keys_setup_key(struct platform_device *pdev,···465466 button->debounce_interval * 1000);466467 /* use timer if gpiolib doesn't provide debounce */467468 if (error < 0)468468- bdata->timer_debounce =469469+ bdata->software_debounce =469470 button->debounce_interval;470471 }471472472472- irq = gpio_to_irq(button->gpio);473473- if (irq < 0) {474474- error = irq;475475- dev_err(dev,476476- "Unable to get irq number for GPIO %d, error %d\n",477477- button->gpio, error);478478- return error;473473+ if (button->irq) {474474+ bdata->irq = button->irq;475475+ } else {476476+ irq = gpio_to_irq(button->gpio);477477+ if (irq < 0) {478478+ error = irq;479479+ dev_err(dev,480480+ "Unable to get irq number for GPIO %d, error %d\n",481481+ button->gpio, error);482482+ return error;483483+ }484484+ bdata->irq = irq;479485 }480480- bdata->irq = irq;481486482482- INIT_WORK(&bdata->work, gpio_keys_gpio_work_func);483483- setup_timer(&bdata->timer,484484- gpio_keys_gpio_timer, (unsigned long)bdata);487487+ INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func);485488486489 isr = gpio_keys_gpio_isr;487490 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;···500499 return -EINVAL;501500 }502501503503- bdata->timer_debounce = button->debounce_interval;504504- setup_timer(&bdata->timer,502502+ bdata->release_delay = button->debounce_interval;503503+ setup_timer(&bdata->release_timer,505504 gpio_keys_irq_timer, (unsigned long)bdata);506505507506 isr = gpio_keys_irq_isr;···511510 input_set_capability(input, button->type ?: EV_KEY, button->code);512511513512 /*514514- * Install custom action to cancel debounce timer and513513+ * Install custom action to cancel release timer and515514 * workqueue item.516515 */517516 error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata);···619618620619 i = 0;621620 for_each_child_of_node(node, pp) {622622- int gpio = -1;623621 enum of_gpio_flags flags;624622625623 button = &pdata->buttons[i++];626624627627- if (!of_find_property(pp, "gpios", NULL)) {628628- button->irq = irq_of_parse_and_map(pp, 0);629629- if (button->irq == 0) {630630- i--;631631- pdata->nbuttons--;632632- dev_warn(dev, "Found button without gpios or irqs\n");633633- continue;634634- }635635- } else {636636- gpio = of_get_gpio_flags(pp, 0, &flags);637637- if (gpio < 0) {638638- error = gpio;625625+ button->gpio = of_get_gpio_flags(pp, 0, &flags);626626+ if (button->gpio < 0) {627627+ error = button->gpio;628628+ if (error != -ENOENT) {639629 if (error != -EPROBE_DEFER)640630 dev_err(dev,641631 "Failed to get gpio flags, error: %d\n",642632 error);643633 return ERR_PTR(error);644634 }635635+ } else {636636+ button->active_low = flags & OF_GPIO_ACTIVE_LOW;645637 }646638647647- button->gpio = gpio;648648- button->active_low = flags & OF_GPIO_ACTIVE_LOW;639639+ button->irq = irq_of_parse_and_map(pp, 0);640640+641641+ if (!gpio_is_valid(button->gpio) && !button->irq) {642642+ dev_err(dev, "Found button without gpios or irqs\n");643643+ return ERR_PTR(-EINVAL);644644+ }649645650646 if (of_property_read_u32(pp, "linux,code", &button->code)) {651647 dev_err(dev, "Button without keycode: 0x%x\n",···656658 button->type = EV_KEY;657659658660 button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);661661+662662+ button->can_disable = !!of_get_property(pp, "linux,can-disable", NULL);659663660664 if (of_property_read_u32(pp, "debounce-interval",661665 &button->debounce_interval))
+80-61
drivers/input/keyboard/stmpe-keypad.c
···4545#define STMPE_KEYPAD_MAX_ROWS 84646#define STMPE_KEYPAD_MAX_COLS 84747#define STMPE_KEYPAD_ROW_SHIFT 34848-#define STMPE_KEYPAD_KEYMAP_SIZE \4848+#define STMPE_KEYPAD_KEYMAP_MAX_SIZE \4949 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)50505151/**5252 * struct stmpe_keypad_variant - model-specific attributes5353 * @auto_increment: whether the KPC_DATA_BYTE register address5454 * auto-increments on multiple read5555+ * @set_pullup: whether the pins need to have their pull-ups set5556 * @num_data: number of data bytes5657 * @num_normal_data: number of normal keys' data bytes5758 * @max_cols: maximum number of columns supported···6261 */6362struct stmpe_keypad_variant {6463 bool auto_increment;6464+ bool set_pullup;6565 int num_data;6666 int num_normal_data;6767 int max_cols;···8381 },8482 [STMPE2401] = {8583 .auto_increment = false,8484+ .set_pullup = true,8685 .num_data = 3,8786 .num_normal_data = 2,8887 .max_cols = 8,···9390 },9491 [STMPE2403] = {9592 .auto_increment = true,9393+ .set_pullup = true,9694 .num_data = 5,9795 .num_normal_data = 3,9896 .max_cols = 8,···10399 },104100};105101102102+/**103103+ * struct stmpe_keypad - STMPE keypad state container104104+ * @stmpe: pointer to parent STMPE device105105+ * @input: spawned input device106106+ * @variant: STMPE variant107107+ * @debounce_ms: debounce interval, in ms. Maximum is108108+ * %STMPE_KEYPAD_MAX_DEBOUNCE.109109+ * @scan_count: number of key scanning cycles to confirm key data.110110+ * Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.111111+ * @no_autorepeat: disable key autorepeat112112+ * @rows: bitmask for the rows113113+ * @cols: bitmask for the columns114114+ * @keymap: the keymap115115+ */106116struct stmpe_keypad {107117 struct stmpe *stmpe;108118 struct input_dev *input;109119 const struct stmpe_keypad_variant *variant;110110- const struct stmpe_keypad_platform_data *plat;111111-120120+ unsigned int debounce_ms;121121+ unsigned int scan_count;122122+ bool no_autorepeat;112123 unsigned int rows;113124 unsigned int cols;114114-115115- unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];125125+ unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE];116126};117127118128static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)···189171 unsigned int col_gpios = variant->col_gpios;190172 unsigned int row_gpios = variant->row_gpios;191173 struct stmpe *stmpe = keypad->stmpe;174174+ u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB];192175 unsigned int pins = 0;176176+ unsigned int pu_pins = 0;177177+ int ret;193178 int i;194179195180 /*···209188 for (i = 0; i < variant->max_cols; i++) {210189 int num = __ffs(col_gpios);211190212212- if (keypad->cols & (1 << i))191191+ if (keypad->cols & (1 << i)) {213192 pins |= 1 << num;193193+ pu_pins |= 1 << num;194194+ }214195215196 col_gpios &= ~(1 << num);216197 }···226203 row_gpios &= ~(1 << num);227204 }228205229229- return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);206206+ ret = stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);207207+ if (ret)208208+ return ret;209209+210210+ /*211211+ * On STMPE24xx, set pin bias to pull-up on all keypad input212212+ * pins (columns), this incidentally happen to be maximum 8 pins213213+ * and placed at GPIO0-7 so only the LSB of the pull up register214214+ * ever needs to be written.215215+ */216216+ if (variant->set_pullup) {217217+ u8 val;218218+219219+ ret = stmpe_reg_read(stmpe, pureg);220220+ if (ret)221221+ return ret;222222+223223+ /* Do not touch unused pins, may be used for GPIO */224224+ val = ret & ~pu_pins;225225+ val |= pu_pins;226226+227227+ ret = stmpe_reg_write(stmpe, pureg, val);228228+ }229229+230230+ return 0;230231}231232232233static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)233234{234234- const struct stmpe_keypad_platform_data *plat = keypad->plat;235235 const struct stmpe_keypad_variant *variant = keypad->variant;236236 struct stmpe *stmpe = keypad->stmpe;237237 int ret;238238239239- if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)239239+ if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)240240 return -EINVAL;241241242242- if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)242242+ if (keypad->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)243243 return -EINVAL;244244245245 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);···291245292246 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,293247 STMPE_KPC_CTRL_MSB_SCAN_COUNT,294294- plat->scan_count << 4);248248+ keypad->scan_count << 4);295249 if (ret < 0)296250 return ret;297251···299253 STMPE_KPC_CTRL_LSB_SCAN |300254 STMPE_KPC_CTRL_LSB_DEBOUNCE,301255 STMPE_KPC_CTRL_LSB_SCAN |302302- (plat->debounce_ms << 1));256256+ (keypad->debounce_ms << 1));303257}304258305305-static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad)259259+static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad,260260+ u32 used_rows, u32 used_cols)306261{307262 int row, col;308263309309- for (row = 0; row < STMPE_KEYPAD_MAX_ROWS; row++) {310310- for (col = 0; col < STMPE_KEYPAD_MAX_COLS; col++) {264264+ for (row = 0; row < used_rows; row++) {265265+ for (col = 0; col < used_cols; col++) {311266 int code = MATRIX_SCAN_CODE(row, col,312312- STMPE_KEYPAD_ROW_SHIFT);267267+ STMPE_KEYPAD_ROW_SHIFT);313268 if (keypad->keymap[code] != KEY_RESERVED) {314269 keypad->rows |= 1 << row;315270 keypad->cols |= 1 << col;···319272 }320273}321274322322-#ifdef CONFIG_OF323323-static const struct stmpe_keypad_platform_data *324324-stmpe_keypad_of_probe(struct device *dev)325325-{326326- struct device_node *np = dev->of_node;327327- struct stmpe_keypad_platform_data *plat;328328-329329- if (!np)330330- return ERR_PTR(-ENODEV);331331-332332- plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);333333- if (!plat)334334- return ERR_PTR(-ENOMEM);335335-336336- of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);337337- of_property_read_u32(np, "st,scan-count", &plat->scan_count);338338-339339- plat->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");340340-341341- return plat;342342-}343343-#else344344-static inline const struct stmpe_keypad_platform_data *345345-stmpe_keypad_of_probe(struct device *dev)346346-{347347- return ERR_PTR(-EINVAL);348348-}349349-#endif350350-351275static int stmpe_keypad_probe(struct platform_device *pdev)352276{353277 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);354354- const struct stmpe_keypad_platform_data *plat;278278+ struct device_node *np = pdev->dev.of_node;355279 struct stmpe_keypad *keypad;356280 struct input_dev *input;281281+ u32 rows;282282+ u32 cols;357283 int error;358284 int irq;359359-360360- plat = stmpe->pdata->keypad;361361- if (!plat) {362362- plat = stmpe_keypad_of_probe(&pdev->dev);363363- if (IS_ERR(plat))364364- return PTR_ERR(plat);365365- }366285367286 irq = platform_get_irq(pdev, 0);368287 if (irq < 0)···339326 if (!keypad)340327 return -ENOMEM;341328329329+ keypad->stmpe = stmpe;330330+ keypad->variant = &stmpe_keypad_variants[stmpe->partnum];331331+332332+ of_property_read_u32(np, "debounce-interval", &keypad->debounce_ms);333333+ of_property_read_u32(np, "st,scan-count", &keypad->scan_count);334334+ keypad->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");335335+342336 input = devm_input_allocate_device(&pdev->dev);343337 if (!input)344338 return -ENOMEM;···354334 input->id.bustype = BUS_I2C;355335 input->dev.parent = &pdev->dev;356336357357- error = matrix_keypad_build_keymap(plat->keymap_data, NULL,358358- STMPE_KEYPAD_MAX_ROWS,359359- STMPE_KEYPAD_MAX_COLS,337337+ error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);338338+ if (error)339339+ return error;340340+341341+ error = matrix_keypad_build_keymap(NULL, NULL, rows, cols,360342 keypad->keymap, input);361343 if (error)362344 return error;363345364346 input_set_capability(input, EV_MSC, MSC_SCAN);365365- if (!plat->no_autorepeat)347347+ if (!keypad->no_autorepeat)366348 __set_bit(EV_REP, input->evbit);367349368368- stmpe_keypad_fill_used_pins(keypad);350350+ stmpe_keypad_fill_used_pins(keypad, rows, cols);369351370370- keypad->stmpe = stmpe;371371- keypad->plat = plat;372352 keypad->input = input;373373- keypad->variant = &stmpe_keypad_variants[stmpe->partnum];374353375354 error = stmpe_keypad_chip_init(keypad);376355 if (error < 0)
+74-10
drivers/input/mouse/alps.c
···881881 unsigned char *pkt,882882 unsigned char pkt_id)883883{884884+ /*885885+ * packet-fmt b7 b6 b5 b4 b3 b2 b1 b0886886+ * Byte0 TWO & MULTI L 1 R M 1 Y0-2 Y0-1 Y0-0887887+ * Byte0 NEW L 1 X1-5 1 1 Y0-2 Y0-1 Y0-0888888+ * Byte1 Y0-10 Y0-9 Y0-8 Y0-7 Y0-6 Y0-5 Y0-4 Y0-3889889+ * Byte2 X0-11 1 X0-10 X0-9 X0-8 X0-7 X0-6 X0-5890890+ * Byte3 X1-11 1 X0-4 X0-3 1 X0-2 X0-1 X0-0891891+ * Byte4 TWO X1-10 TWO X1-9 X1-8 X1-7 X1-6 X1-5 X1-4892892+ * Byte4 MULTI X1-10 TWO X1-9 X1-8 X1-7 X1-6 Y1-5 1893893+ * Byte4 NEW X1-10 TWO X1-9 X1-8 X1-7 X1-6 0 0894894+ * Byte5 TWO & NEW Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 Y1-5 Y1-4895895+ * Byte5 MULTI Y1-10 0 Y1-9 Y1-8 Y1-7 Y1-6 F-1 F-0896896+ * L: Left button897897+ * R / M: Non-clickpads: Right / Middle button898898+ * Clickpads: When > 2 fingers are down, and some fingers899899+ * are in the button area, then the 2 coordinates reported900900+ * are for fingers outside the button area and these report901901+ * extra fingers being present in the right / left button902902+ * area. Note these fingers are not added to the F field!903903+ * so if a TWO packet is received and R = 1 then there are904904+ * 3 fingers down, etc.905905+ * TWO: 1: Two touches present, byte 0/4/5 are in TWO fmt906906+ * 0: If byte 4 bit 0 is 1, then byte 0/4/5 are in MULTI fmt907907+ * otherwise byte 0 bit 4 must be set and byte 0/4/5 are908908+ * in NEW fmt909909+ * F: Number of fingers - 3, 0 means 3 fingers, 1 means 4 ...910910+ */911911+884912 mt[0].x = ((pkt[2] & 0x80) << 4);885913 mt[0].x |= ((pkt[2] & 0x3F) << 5);886914 mt[0].x |= ((pkt[3] & 0x30) >> 1);···947919948920static int alps_get_mt_count(struct input_mt_pos *mt)949921{950950- int i;922922+ int i, fingers = 0;951923952952- for (i = 0; i < MAX_TOUCHES && mt[i].x != 0 && mt[i].y != 0; i++)953953- /* empty */;924924+ for (i = 0; i < MAX_TOUCHES; i++) {925925+ if (mt[i].x != 0 || mt[i].y != 0)926926+ fingers++;927927+ }954928955955- return i;929929+ return fingers;956930}957931958932static int alps_decode_packet_v7(struct alps_fields *f,959933 unsigned char *p,960934 struct psmouse *psmouse)961935{936936+ struct alps_data *priv = psmouse->private;962937 unsigned char pkt_id;963938964939 pkt_id = alps_get_packet_id_v7(p);···969938 return 0;970939 if (pkt_id == V7_PACKET_ID_UNKNOWN)971940 return -1;941941+ /*942942+ * NEW packets are send to indicate a discontinuity in the finger943943+ * coordinate reporting. Specifically a finger may have moved from944944+ * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for945945+ * us.946946+ *947947+ * NEW packets have 3 problems:948948+ * 1) They do not contain middle / right button info (on non clickpads)949949+ * this can be worked around by preserving the old button state950950+ * 2) They do not contain an accurate fingercount, and they are951951+ * typically send when the number of fingers changes. We cannot use952952+ * the old finger count as that may mismatch with the amount of953953+ * touch coordinates we've available in the NEW packet954954+ * 3) Their x data for the second touch is inaccurate leading to955955+ * a possible jump of the x coordinate by 16 units when the first956956+ * non NEW packet comes in957957+ * Since problems 2 & 3 cannot be worked around, just ignore them.958958+ */959959+ if (pkt_id == V7_PACKET_ID_NEW)960960+ return 1;972961973962 alps_get_finger_coordinate_v7(f->mt, p, pkt_id);974963975975- if (pkt_id == V7_PACKET_ID_TWO || pkt_id == V7_PACKET_ID_MULTI) {976976- f->left = (p[0] & 0x80) >> 7;964964+ if (pkt_id == V7_PACKET_ID_TWO)965965+ f->fingers = alps_get_mt_count(f->mt);966966+ else /* pkt_id == V7_PACKET_ID_MULTI */967967+ f->fingers = 3 + (p[5] & 0x03);968968+969969+ f->left = (p[0] & 0x80) >> 7;970970+ if (priv->flags & ALPS_BUTTONPAD) {971971+ if (p[0] & 0x20)972972+ f->fingers++;973973+ if (p[0] & 0x10)974974+ f->fingers++;975975+ } else {977976 f->right = (p[0] & 0x20) >> 5;978977 f->middle = (p[0] & 0x10) >> 4;979978 }980979981981- if (pkt_id == V7_PACKET_ID_TWO)982982- f->fingers = alps_get_mt_count(f->mt);983983- else if (pkt_id == V7_PACKET_ID_MULTI)984984- f->fingers = 3 + (p[5] & 0x03);980980+ /* Sometimes a single touch is reported in mt[1] rather then mt[0] */981981+ if (f->fingers == 1 && f->mt[0].x == 0 && f->mt[0].y == 0) {982982+ f->mt[0].x = f->mt[1].x;983983+ f->mt[0].y = f->mt[1].y;984984+ f->mt[1].x = 0;985985+ f->mt[1].y = 0;986986+ }985987986988 return 0;987989}