Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

Pull input updates from Dmitry Torokhov:

- new driver for PhoenixRC Flight Controller Adapter

- new driver for RAVE SP Power button

- fixes for autosuspend-related deadlocks in a few unput USB dirvers

- support for 2nd wheel in ATech PS/2 mouse

- fix for ALPS trackpoint detection on Thinkpad L570 and Latitude 7370

- bunch of cleanups in various in PS/2 protocols

- other assorted changes and fixes

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (35 commits)
Input: i8042 - enable MUX on Sony VAIO VGN-CS series to fix touchpad
Input: stmfts, s6sy761 - update my e-mail
Input: stmfts - use async probe & suspend/resume to avoid 2s delay
Input: ALPS - fix TrackStick detection on Thinkpad L570 and Latitude 7370
Input: xpad - add PDP device id 0x02a4
Input: alps - report pressure of v3 and v7 trackstick
Input: pxrc - new driver for PhoenixRC Flight Controller Adapter
Input: usbtouchscreen - do not rely on input_dev->users
Input: usbtouchscreen - fix deadlock in autosuspend
Input: pegasus_notetaker - do not rely on input_dev->users
Input: pagasus_notetaker - fix deadlock in autosuspend
Input: synaptics_usb - do not rely on input_dev->users
Input: synaptics_usb - fix deadlock in autosuspend
Input: gpio-keys - add support for wakeup event action
Input: appletouch - use true and false for boolean values
Input: silead - add Chuwi Hi8 support
Input: analog - use get_cycles() on PPC
Input: stmpe-keypad - remove VLA usage
Input: i8042 - add Lenovo ThinkPad L460 to i8042 reset list
Input: add RAVE SP Powerbutton driver
...

+1359 -492
+8
Documentation/devicetree/bindings/input/gpio-keys.txt
··· 26 26 If not specified defaults to 5. 27 27 - wakeup-source: Boolean, button can wake-up the system. 28 28 (Legacy property supported: "gpio-key,wakeup") 29 + - wakeup-event-action: Specifies whether the key should wake the 30 + system when asserted, when deasserted, or both. This property is 31 + only valid for keys that wake up the system (e.g., when the 32 + "wakeup-source" property is also provided). 33 + Supported values are defined in linux-event-codes.h: 34 + EV_ACT_ASSERTED - asserted 35 + EV_ACT_DEASSERTED - deasserted 36 + EV_ACT_ANY - both asserted and deasserted 29 37 - linux,can-disable: Boolean, indicates that button is connected 30 38 to dedicated (not shared) interrupt which can be disabled to 31 39 suppress events from the button.
+22
Documentation/devicetree/bindings/input/zii,rave-sp-pwrbutton.txt
··· 1 + Zodiac Inflight Innovations RAVE Supervisory Processor Power Button Bindings 2 + 3 + RAVE SP input device is a "MFD cell" device corresponding to power 4 + button functionality of RAVE Supervisory Processor. It is expected 5 + that its Device Tree node is specified as a child of the node 6 + corresponding to the parent RAVE SP device (as documented in 7 + Documentation/devicetree/bindings/mfd/zii,rave-sp.txt) 8 + 9 + Required properties: 10 + 11 + - compatible: Should be "zii,rave-sp-pwrbutton" 12 + 13 + Example: 14 + 15 + rave-sp { 16 + compatible = "zii,rave-sp-rdu1"; 17 + current-speed = <38400>; 18 + 19 + pwrbutton { 20 + compatible = "zii,rave-sp-pwrbutton"; 21 + }; 22 + }
+57
Documentation/input/devices/pxrc.rst
··· 1 + ======================================================= 2 + pxrc - PhoenixRC Flight Controller Adapter 3 + ======================================================= 4 + 5 + :Author: Marcus Folkesson <marcus.folkesson@gmail.com> 6 + 7 + This driver let you use your own RC controller plugged into the 8 + adapter that comes with PhoenixRC [1]_ or other compatible adapters. 9 + 10 + The adapter supports 7 analog channels and 1 digital input switch. 11 + 12 + Notes 13 + ===== 14 + 15 + Many RC controllers is able to configure which stick goes to which channel. 16 + This is also configurable in most simulators, so a matching is not necessary. 17 + 18 + The driver is generating the following input event for analog channels: 19 + 20 + +---------+----------------+ 21 + | Channel | Event | 22 + +=========+================+ 23 + | 1 | ABS_X | 24 + +---------+----------------+ 25 + | 2 | ABS_Y | 26 + +---------+----------------+ 27 + | 3 | ABS_RX | 28 + +---------+----------------+ 29 + | 4 | ABS_RY | 30 + +---------+----------------+ 31 + | 5 | ABS_RUDDER | 32 + +---------+----------------+ 33 + | 6 | ABS_THROTTLE | 34 + +---------+----------------+ 35 + | 7 | ABS_MISC | 36 + +---------+----------------+ 37 + 38 + The digital input switch is generated as an `BTN_A` event. 39 + 40 + Manual Testing 41 + ============== 42 + 43 + To test this driver's functionality you may use `input-event` which is part of 44 + the `input layer utilities` suite [2]_. 45 + 46 + For example:: 47 + 48 + > modprobe pxrc 49 + > input-events <devnr> 50 + 51 + To print all input events from input `devnr`. 52 + 53 + References 54 + ========== 55 + 56 + .. [1] http://www.phoenix-sim.com/ 57 + .. [2] https://www.kraxel.org/cgit/input/
+10
drivers/input/joystick/Kconfig
··· 351 351 352 352 To drive rumble motor a dedicated power supply is required. 353 353 354 + config JOYSTICK_PXRC 355 + tristate "PhoenixRC Flight Controller Adapter" 356 + depends on USB_ARCH_HAS_HCD 357 + select USB 358 + help 359 + Say Y here if you want to use the PhoenixRC Flight Controller Adapter. 360 + 361 + To compile this driver as a module, choose M here: the 362 + module will be called pxrc. 363 + 354 364 endif
+1
drivers/input/joystick/Makefile
··· 23 23 obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o 24 24 obj-$(CONFIG_JOYSTICK_MAPLE) += maplecontrol.o 25 25 obj-$(CONFIG_JOYSTICK_PSXPAD_SPI) += psxpad-spi.o 26 + obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o 26 27 obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o 27 28 obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o 28 29 obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o
+1 -1
drivers/input/joystick/analog.c
··· 163 163 #define GET_TIME(x) do { x = (unsigned int)rdtsc(); } while (0) 164 164 #define DELTA(x,y) ((y)-(x)) 165 165 #define TIME_NAME "TSC" 166 - #elif defined(__alpha__) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_RISCV) 166 + #elif defined(__alpha__) || defined(CONFIG_ARM) || defined(CONFIG_ARM64) || defined(CONFIG_PPC) || defined(CONFIG_RISCV) 167 167 #define GET_TIME(x) do { x = get_cycles(); } while (0) 168 168 #define DELTA(x,y) ((y)-(x)) 169 169 #define TIME_NAME "get_cycles"
+303
drivers/input/joystick/pxrc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Driver for Phoenix RC Flight Controller Adapter 4 + * 5 + * Copyright (C) 2018 Marcus Folkesson <marcus.folkesson@gmail.com> 6 + * 7 + */ 8 + 9 + #include <linux/kernel.h> 10 + #include <linux/errno.h> 11 + #include <linux/slab.h> 12 + #include <linux/module.h> 13 + #include <linux/uaccess.h> 14 + #include <linux/usb.h> 15 + #include <linux/usb/input.h> 16 + #include <linux/mutex.h> 17 + #include <linux/input.h> 18 + 19 + #define PXRC_VENDOR_ID (0x1781) 20 + #define PXRC_PRODUCT_ID (0x0898) 21 + 22 + static const struct usb_device_id pxrc_table[] = { 23 + { USB_DEVICE(PXRC_VENDOR_ID, PXRC_PRODUCT_ID) }, 24 + { } 25 + }; 26 + MODULE_DEVICE_TABLE(usb, pxrc_table); 27 + 28 + struct pxrc { 29 + struct input_dev *input; 30 + struct usb_device *udev; 31 + struct usb_interface *intf; 32 + struct urb *urb; 33 + struct mutex pm_mutex; 34 + bool is_open; 35 + __u8 epaddr; 36 + char phys[64]; 37 + unsigned char *data; 38 + size_t bsize; 39 + }; 40 + 41 + static void pxrc_usb_irq(struct urb *urb) 42 + { 43 + struct pxrc *pxrc = urb->context; 44 + int error; 45 + 46 + switch (urb->status) { 47 + case 0: 48 + /* success */ 49 + break; 50 + case -ETIME: 51 + /* this urb is timing out */ 52 + dev_dbg(&pxrc->intf->dev, 53 + "%s - urb timed out - was the device unplugged?\n", 54 + __func__); 55 + return; 56 + case -ECONNRESET: 57 + case -ENOENT: 58 + case -ESHUTDOWN: 59 + case -EPIPE: 60 + /* this urb is terminated, clean up */ 61 + dev_dbg(&pxrc->intf->dev, "%s - urb shutting down with status: %d\n", 62 + __func__, urb->status); 63 + return; 64 + default: 65 + dev_dbg(&pxrc->intf->dev, "%s - nonzero urb status received: %d\n", 66 + __func__, urb->status); 67 + goto exit; 68 + } 69 + 70 + if (urb->actual_length == 8) { 71 + input_report_abs(pxrc->input, ABS_X, pxrc->data[0]); 72 + input_report_abs(pxrc->input, ABS_Y, pxrc->data[2]); 73 + input_report_abs(pxrc->input, ABS_RX, pxrc->data[3]); 74 + input_report_abs(pxrc->input, ABS_RY, pxrc->data[4]); 75 + input_report_abs(pxrc->input, ABS_RUDDER, pxrc->data[5]); 76 + input_report_abs(pxrc->input, ABS_THROTTLE, pxrc->data[6]); 77 + input_report_abs(pxrc->input, ABS_MISC, pxrc->data[7]); 78 + 79 + input_report_key(pxrc->input, BTN_A, pxrc->data[1]); 80 + } 81 + 82 + exit: 83 + /* Resubmit to fetch new fresh URBs */ 84 + error = usb_submit_urb(urb, GFP_ATOMIC); 85 + if (error && error != -EPERM) 86 + dev_err(&pxrc->intf->dev, 87 + "%s - usb_submit_urb failed with result: %d", 88 + __func__, error); 89 + } 90 + 91 + static int pxrc_open(struct input_dev *input) 92 + { 93 + struct pxrc *pxrc = input_get_drvdata(input); 94 + int retval; 95 + 96 + mutex_lock(&pxrc->pm_mutex); 97 + retval = usb_submit_urb(pxrc->urb, GFP_KERNEL); 98 + if (retval) { 99 + dev_err(&pxrc->intf->dev, 100 + "%s - usb_submit_urb failed, error: %d\n", 101 + __func__, retval); 102 + retval = -EIO; 103 + goto out; 104 + } 105 + 106 + pxrc->is_open = true; 107 + 108 + out: 109 + mutex_unlock(&pxrc->pm_mutex); 110 + return retval; 111 + } 112 + 113 + static void pxrc_close(struct input_dev *input) 114 + { 115 + struct pxrc *pxrc = input_get_drvdata(input); 116 + 117 + mutex_lock(&pxrc->pm_mutex); 118 + usb_kill_urb(pxrc->urb); 119 + pxrc->is_open = false; 120 + mutex_unlock(&pxrc->pm_mutex); 121 + } 122 + 123 + static int pxrc_usb_init(struct pxrc *pxrc) 124 + { 125 + struct usb_endpoint_descriptor *epirq; 126 + unsigned int pipe; 127 + int retval; 128 + 129 + /* Set up the endpoint information */ 130 + /* This device only has an interrupt endpoint */ 131 + retval = usb_find_common_endpoints(pxrc->intf->cur_altsetting, 132 + NULL, NULL, &epirq, NULL); 133 + if (retval) { 134 + dev_err(&pxrc->intf->dev, 135 + "Could not find endpoint\n"); 136 + goto error; 137 + } 138 + 139 + pxrc->bsize = usb_endpoint_maxp(epirq); 140 + pxrc->epaddr = epirq->bEndpointAddress; 141 + pxrc->data = devm_kmalloc(&pxrc->intf->dev, pxrc->bsize, GFP_KERNEL); 142 + if (!pxrc->data) { 143 + retval = -ENOMEM; 144 + goto error; 145 + } 146 + 147 + usb_set_intfdata(pxrc->intf, pxrc); 148 + usb_make_path(pxrc->udev, pxrc->phys, sizeof(pxrc->phys)); 149 + strlcat(pxrc->phys, "/input0", sizeof(pxrc->phys)); 150 + 151 + pxrc->urb = usb_alloc_urb(0, GFP_KERNEL); 152 + if (!pxrc->urb) { 153 + retval = -ENOMEM; 154 + goto error; 155 + } 156 + 157 + pipe = usb_rcvintpipe(pxrc->udev, pxrc->epaddr), 158 + usb_fill_int_urb(pxrc->urb, pxrc->udev, pipe, pxrc->data, pxrc->bsize, 159 + pxrc_usb_irq, pxrc, 1); 160 + 161 + error: 162 + return retval; 163 + 164 + 165 + } 166 + 167 + static int pxrc_input_init(struct pxrc *pxrc) 168 + { 169 + pxrc->input = devm_input_allocate_device(&pxrc->intf->dev); 170 + if (pxrc->input == NULL) { 171 + dev_err(&pxrc->intf->dev, "couldn't allocate input device\n"); 172 + return -ENOMEM; 173 + } 174 + 175 + pxrc->input->name = "PXRC Flight Controller Adapter"; 176 + pxrc->input->phys = pxrc->phys; 177 + usb_to_input_id(pxrc->udev, &pxrc->input->id); 178 + 179 + pxrc->input->open = pxrc_open; 180 + pxrc->input->close = pxrc_close; 181 + 182 + input_set_capability(pxrc->input, EV_KEY, BTN_A); 183 + input_set_abs_params(pxrc->input, ABS_X, 0, 255, 0, 0); 184 + input_set_abs_params(pxrc->input, ABS_Y, 0, 255, 0, 0); 185 + input_set_abs_params(pxrc->input, ABS_RX, 0, 255, 0, 0); 186 + input_set_abs_params(pxrc->input, ABS_RY, 0, 255, 0, 0); 187 + input_set_abs_params(pxrc->input, ABS_RUDDER, 0, 255, 0, 0); 188 + input_set_abs_params(pxrc->input, ABS_THROTTLE, 0, 255, 0, 0); 189 + input_set_abs_params(pxrc->input, ABS_MISC, 0, 255, 0, 0); 190 + 191 + input_set_drvdata(pxrc->input, pxrc); 192 + 193 + return input_register_device(pxrc->input); 194 + } 195 + 196 + static int pxrc_probe(struct usb_interface *intf, 197 + const struct usb_device_id *id) 198 + { 199 + struct pxrc *pxrc; 200 + int retval; 201 + 202 + pxrc = devm_kzalloc(&intf->dev, sizeof(*pxrc), GFP_KERNEL); 203 + if (!pxrc) 204 + return -ENOMEM; 205 + 206 + mutex_init(&pxrc->pm_mutex); 207 + pxrc->udev = usb_get_dev(interface_to_usbdev(intf)); 208 + pxrc->intf = intf; 209 + 210 + retval = pxrc_usb_init(pxrc); 211 + if (retval) 212 + goto error; 213 + 214 + retval = pxrc_input_init(pxrc); 215 + if (retval) 216 + goto err_free_urb; 217 + 218 + return 0; 219 + 220 + err_free_urb: 221 + usb_free_urb(pxrc->urb); 222 + 223 + error: 224 + return retval; 225 + } 226 + 227 + static void pxrc_disconnect(struct usb_interface *intf) 228 + { 229 + struct pxrc *pxrc = usb_get_intfdata(intf); 230 + 231 + usb_free_urb(pxrc->urb); 232 + usb_set_intfdata(intf, NULL); 233 + } 234 + 235 + static int pxrc_suspend(struct usb_interface *intf, pm_message_t message) 236 + { 237 + struct pxrc *pxrc = usb_get_intfdata(intf); 238 + 239 + mutex_lock(&pxrc->pm_mutex); 240 + if (pxrc->is_open) 241 + usb_kill_urb(pxrc->urb); 242 + mutex_unlock(&pxrc->pm_mutex); 243 + 244 + return 0; 245 + } 246 + 247 + static int pxrc_resume(struct usb_interface *intf) 248 + { 249 + struct pxrc *pxrc = usb_get_intfdata(intf); 250 + int retval = 0; 251 + 252 + mutex_lock(&pxrc->pm_mutex); 253 + if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0) 254 + retval = -EIO; 255 + 256 + mutex_unlock(&pxrc->pm_mutex); 257 + return retval; 258 + } 259 + 260 + static int pxrc_pre_reset(struct usb_interface *intf) 261 + { 262 + struct pxrc *pxrc = usb_get_intfdata(intf); 263 + 264 + mutex_lock(&pxrc->pm_mutex); 265 + usb_kill_urb(pxrc->urb); 266 + return 0; 267 + } 268 + 269 + static int pxrc_post_reset(struct usb_interface *intf) 270 + { 271 + struct pxrc *pxrc = usb_get_intfdata(intf); 272 + int retval = 0; 273 + 274 + if (pxrc->is_open && usb_submit_urb(pxrc->urb, GFP_KERNEL) < 0) 275 + retval = -EIO; 276 + 277 + mutex_unlock(&pxrc->pm_mutex); 278 + 279 + return retval; 280 + } 281 + 282 + static int pxrc_reset_resume(struct usb_interface *intf) 283 + { 284 + return pxrc_resume(intf); 285 + } 286 + 287 + static struct usb_driver pxrc_driver = { 288 + .name = "pxrc", 289 + .probe = pxrc_probe, 290 + .disconnect = pxrc_disconnect, 291 + .id_table = pxrc_table, 292 + .suspend = pxrc_suspend, 293 + .resume = pxrc_resume, 294 + .pre_reset = pxrc_pre_reset, 295 + .post_reset = pxrc_post_reset, 296 + .reset_resume = pxrc_reset_resume, 297 + }; 298 + 299 + module_usb_driver(pxrc_driver); 300 + 301 + MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>"); 302 + MODULE_DESCRIPTION("PhoenixRC Flight Controller Adapter"); 303 + MODULE_LICENSE("GPL v2");
+7 -2
drivers/input/joystick/xpad.c
··· 227 227 { 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 228 228 { 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE }, 229 229 { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE }, 230 + { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE }, 230 231 { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 }, 231 232 { 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE }, 232 233 { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 }, ··· 476 475 477 476 /* 478 477 * This packet is required for some of the PDP pads to start 479 - * sending input reports. One of those pads is (0x0e6f:0x02ab). 478 + * sending input reports. These pads include: (0x0e6f:0x02ab), 479 + * (0x0e6f:0x02a4). 480 480 */ 481 481 static const u8 xboxone_pdp_init1[] = { 482 482 0x0a, 0x20, 0x00, 0x03, 0x00, 0x01, 0x14 ··· 485 483 486 484 /* 487 485 * This packet is required for some of the PDP pads to start 488 - * sending input reports. One of those pads is (0x0e6f:0x02ab). 486 + * sending input reports. These pads include: (0x0e6f:0x02ab), 487 + * (0x0e6f:0x02a4). 489 488 */ 490 489 static const u8 xboxone_pdp_init2[] = { 491 490 0x06, 0x20, 0x00, 0x02, 0x01, 0x00 ··· 524 521 XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_fw2015_init), 525 522 XBOXONE_INIT_PKT(0x0e6f, 0x02ab, xboxone_pdp_init1), 526 523 XBOXONE_INIT_PKT(0x0e6f, 0x02ab, xboxone_pdp_init2), 524 + XBOXONE_INIT_PKT(0x0e6f, 0x02a4, xboxone_pdp_init1), 525 + XBOXONE_INIT_PKT(0x0e6f, 0x02a4, xboxone_pdp_init2), 527 526 XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init), 528 527 XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumblebegin_init), 529 528 XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumblebegin_init),
+131 -14
drivers/input/keyboard/gpio_keys.c
··· 30 30 #include <linux/of.h> 31 31 #include <linux/of_irq.h> 32 32 #include <linux/spinlock.h> 33 + #include <dt-bindings/input/gpio-keys.h> 33 34 34 35 struct gpio_button_data { 35 36 const struct gpio_keys_button *button; ··· 46 45 unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */ 47 46 48 47 unsigned int irq; 48 + unsigned int wakeup_trigger_type; 49 49 spinlock_t lock; 50 50 bool disabled; 51 51 bool key_pressed; ··· 542 540 } 543 541 544 542 if (bdata->gpiod) { 543 + bool active_low = gpiod_is_active_low(bdata->gpiod); 544 + 545 545 if (button->debounce_interval) { 546 546 error = gpiod_set_debounce(bdata->gpiod, 547 547 button->debounce_interval * 1000); ··· 572 568 isr = gpio_keys_gpio_isr; 573 569 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; 574 570 571 + switch (button->wakeup_event_action) { 572 + case EV_ACT_ASSERTED: 573 + bdata->wakeup_trigger_type = active_low ? 574 + IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING; 575 + break; 576 + case EV_ACT_DEASSERTED: 577 + bdata->wakeup_trigger_type = active_low ? 578 + IRQ_TYPE_EDGE_RISING : IRQ_TYPE_EDGE_FALLING; 579 + break; 580 + case EV_ACT_ANY: 581 + /* fall through */ 582 + default: 583 + /* 584 + * For other cases, we are OK letting suspend/resume 585 + * not reconfigure the trigger type. 586 + */ 587 + break; 588 + } 575 589 } else { 576 590 if (!button->irq) { 577 591 dev_err(dev, "Found button without gpio or irq\n"); ··· 608 586 609 587 isr = gpio_keys_irq_isr; 610 588 irqflags = 0; 589 + 590 + /* 591 + * For IRQ buttons, there is no interrupt for release. 592 + * So we don't need to reconfigure the trigger type for wakeup. 593 + */ 611 594 } 612 595 613 596 bdata->code = &ddata->keymap[idx]; ··· 745 718 /* legacy name */ 746 719 fwnode_property_read_bool(child, "gpio-key,wakeup"); 747 720 721 + fwnode_property_read_u32(child, "wakeup-event-action", 722 + &button->wakeup_event_action); 723 + 748 724 button->can_disable = 749 725 fwnode_property_read_bool(child, "linux,can-disable"); 750 726 ··· 875 845 return 0; 876 846 } 877 847 848 + static int __maybe_unused 849 + gpio_keys_button_enable_wakeup(struct gpio_button_data *bdata) 850 + { 851 + int error; 852 + 853 + error = enable_irq_wake(bdata->irq); 854 + if (error) { 855 + dev_err(bdata->input->dev.parent, 856 + "failed to configure IRQ %d as wakeup source: %d\n", 857 + bdata->irq, error); 858 + return error; 859 + } 860 + 861 + if (bdata->wakeup_trigger_type) { 862 + error = irq_set_irq_type(bdata->irq, 863 + bdata->wakeup_trigger_type); 864 + if (error) { 865 + dev_err(bdata->input->dev.parent, 866 + "failed to set wakeup trigger %08x for IRQ %d: %d\n", 867 + bdata->wakeup_trigger_type, bdata->irq, error); 868 + disable_irq_wake(bdata->irq); 869 + return error; 870 + } 871 + } 872 + 873 + return 0; 874 + } 875 + 876 + static void __maybe_unused 877 + gpio_keys_button_disable_wakeup(struct gpio_button_data *bdata) 878 + { 879 + int error; 880 + 881 + /* 882 + * The trigger type is always both edges for gpio-based keys and we do 883 + * not support changing wakeup trigger for interrupt-based keys. 884 + */ 885 + if (bdata->wakeup_trigger_type) { 886 + error = irq_set_irq_type(bdata->irq, IRQ_TYPE_EDGE_BOTH); 887 + if (error) 888 + dev_warn(bdata->input->dev.parent, 889 + "failed to restore interrupt trigger for IRQ %d: %d\n", 890 + bdata->irq, error); 891 + } 892 + 893 + error = disable_irq_wake(bdata->irq); 894 + if (error) 895 + dev_warn(bdata->input->dev.parent, 896 + "failed to disable IRQ %d as wake source: %d\n", 897 + bdata->irq, error); 898 + } 899 + 900 + static int __maybe_unused 901 + gpio_keys_enable_wakeup(struct gpio_keys_drvdata *ddata) 902 + { 903 + struct gpio_button_data *bdata; 904 + int error; 905 + int i; 906 + 907 + for (i = 0; i < ddata->pdata->nbuttons; i++) { 908 + bdata = &ddata->data[i]; 909 + if (bdata->button->wakeup) { 910 + error = gpio_keys_button_enable_wakeup(bdata); 911 + if (error) 912 + goto err_out; 913 + } 914 + bdata->suspended = true; 915 + } 916 + 917 + return 0; 918 + 919 + err_out: 920 + while (i--) { 921 + bdata = &ddata->data[i]; 922 + if (bdata->button->wakeup) 923 + gpio_keys_button_disable_wakeup(bdata); 924 + bdata->suspended = false; 925 + } 926 + 927 + return error; 928 + } 929 + 930 + static void __maybe_unused 931 + gpio_keys_disable_wakeup(struct gpio_keys_drvdata *ddata) 932 + { 933 + struct gpio_button_data *bdata; 934 + int i; 935 + 936 + for (i = 0; i < ddata->pdata->nbuttons; i++) { 937 + bdata = &ddata->data[i]; 938 + bdata->suspended = false; 939 + if (irqd_is_wakeup_set(irq_get_irq_data(bdata->irq))) 940 + gpio_keys_button_disable_wakeup(bdata); 941 + } 942 + } 943 + 878 944 static int __maybe_unused gpio_keys_suspend(struct device *dev) 879 945 { 880 946 struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); 881 947 struct input_dev *input = ddata->input; 882 - int i; 948 + int error; 883 949 884 950 if (device_may_wakeup(dev)) { 885 - for (i = 0; i < ddata->pdata->nbuttons; i++) { 886 - struct gpio_button_data *bdata = &ddata->data[i]; 887 - if (bdata->button->wakeup) 888 - enable_irq_wake(bdata->irq); 889 - bdata->suspended = true; 890 - } 951 + error = gpio_keys_enable_wakeup(ddata); 952 + if (error) 953 + return error; 891 954 } else { 892 955 mutex_lock(&input->mutex); 893 956 if (input->users) ··· 996 873 struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); 997 874 struct input_dev *input = ddata->input; 998 875 int error = 0; 999 - int i; 1000 876 1001 877 if (device_may_wakeup(dev)) { 1002 - for (i = 0; i < ddata->pdata->nbuttons; i++) { 1003 - struct gpio_button_data *bdata = &ddata->data[i]; 1004 - if (bdata->button->wakeup) 1005 - disable_irq_wake(bdata->irq); 1006 - bdata->suspended = false; 1007 - } 878 + gpio_keys_disable_wakeup(ddata); 1008 879 } else { 1009 880 mutex_lock(&input->mutex); 1010 881 if (input->users)
+12 -4
drivers/input/keyboard/stmpe-keypad.c
··· 48 48 #define STMPE_KEYPAD_KEYMAP_MAX_SIZE \ 49 49 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS) 50 50 51 + 52 + #define STMPE1601_NUM_DATA 5 53 + #define STMPE2401_NUM_DATA 3 54 + #define STMPE2403_NUM_DATA 5 55 + 56 + /* Make sure it covers all cases above */ 57 + #define MAX_NUM_DATA 5 58 + 51 59 /** 52 60 * struct stmpe_keypad_variant - model-specific attributes 53 61 * @auto_increment: whether the KPC_DATA_BYTE register address ··· 82 74 static const struct stmpe_keypad_variant stmpe_keypad_variants[] = { 83 75 [STMPE1601] = { 84 76 .auto_increment = true, 85 - .num_data = 5, 77 + .num_data = STMPE1601_NUM_DATA, 86 78 .num_normal_data = 3, 87 79 .max_cols = 8, 88 80 .max_rows = 8, ··· 92 84 [STMPE2401] = { 93 85 .auto_increment = false, 94 86 .set_pullup = true, 95 - .num_data = 3, 87 + .num_data = STMPE2401_NUM_DATA, 96 88 .num_normal_data = 2, 97 89 .max_cols = 8, 98 90 .max_rows = 12, ··· 102 94 [STMPE2403] = { 103 95 .auto_increment = true, 104 96 .set_pullup = true, 105 - .num_data = 5, 97 + .num_data = STMPE2403_NUM_DATA, 106 98 .num_normal_data = 3, 107 99 .max_cols = 8, 108 100 .max_rows = 12, ··· 164 156 struct stmpe_keypad *keypad = dev; 165 157 struct input_dev *input = keypad->input; 166 158 const struct stmpe_keypad_variant *variant = keypad->variant; 167 - u8 fifo[variant->num_data]; 159 + u8 fifo[MAX_NUM_DATA]; 168 160 int ret; 169 161 int i; 170 162
+9
drivers/input/misc/Kconfig
··· 832 832 To compile this driver as a module, choose M here: the 833 833 module will be called hisi_powerkey. 834 834 835 + config INPUT_RAVE_SP_PWRBUTTON 836 + tristate "RAVE SP Power button Driver" 837 + depends on RAVE_SP_CORE 838 + help 839 + Say Y here if you want to enable power key reporting from RAVE SP 840 + 841 + To compile this driver as a module, choose M here: the 842 + module will be called rave-sp-pwrbutton. 843 + 835 844 endif
+1
drivers/input/misc/Makefile
··· 59 59 obj-$(CONFIG_INPUT_POWERMATE) += powermate.o 60 60 obj-$(CONFIG_INPUT_PWM_BEEPER) += pwm-beeper.o 61 61 obj-$(CONFIG_INPUT_PWM_VIBRA) += pwm-vibra.o 62 + obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o 62 63 obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o 63 64 obj-$(CONFIG_INPUT_REGULATOR_HAPTIC) += regulator-haptic.o 64 65 obj-$(CONFIG_INPUT_RETU_PWRBUTTON) += retu-pwrbutton.o
+94
drivers/input/misc/rave-sp-pwrbutton.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + // 3 + // Power Button driver for RAVE SP 4 + // 5 + // Copyright (C) 2017 Zodiac Inflight Innovations 6 + // 7 + // 8 + 9 + #include <linux/input.h> 10 + #include <linux/kernel.h> 11 + #include <linux/module.h> 12 + #include <linux/mfd/rave-sp.h> 13 + #include <linux/platform_device.h> 14 + 15 + #define RAVE_SP_EVNT_BUTTON_PRESS (RAVE_SP_EVNT_BASE + 0x00) 16 + 17 + struct rave_sp_power_button { 18 + struct input_dev *idev; 19 + struct notifier_block nb; 20 + }; 21 + 22 + static int rave_sp_power_button_event(struct notifier_block *nb, 23 + unsigned long action, void *data) 24 + { 25 + struct rave_sp_power_button *pb = 26 + container_of(nb, struct rave_sp_power_button, nb); 27 + const u8 event = rave_sp_action_unpack_event(action); 28 + const u8 value = rave_sp_action_unpack_value(action); 29 + struct input_dev *idev = pb->idev; 30 + 31 + if (event == RAVE_SP_EVNT_BUTTON_PRESS) { 32 + input_report_key(idev, KEY_POWER, value); 33 + input_sync(idev); 34 + 35 + return NOTIFY_STOP; 36 + } 37 + 38 + return NOTIFY_DONE; 39 + } 40 + 41 + static int rave_sp_pwrbutton_probe(struct platform_device *pdev) 42 + { 43 + struct device *dev = &pdev->dev; 44 + struct rave_sp_power_button *pb; 45 + struct input_dev *idev; 46 + int error; 47 + 48 + pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL); 49 + if (!pb) 50 + return -ENOMEM; 51 + 52 + idev = devm_input_allocate_device(dev); 53 + if (!idev) 54 + return -ENOMEM; 55 + 56 + idev->name = pdev->name; 57 + 58 + input_set_capability(idev, EV_KEY, KEY_POWER); 59 + 60 + error = input_register_device(idev); 61 + if (error) 62 + return error; 63 + 64 + pb->idev = idev; 65 + pb->nb.notifier_call = rave_sp_power_button_event; 66 + pb->nb.priority = 128; 67 + 68 + error = devm_rave_sp_register_event_notifier(dev, &pb->nb); 69 + if (error) 70 + return error; 71 + 72 + return 0; 73 + } 74 + 75 + static const struct of_device_id rave_sp_pwrbutton_of_match[] = { 76 + { .compatible = "zii,rave-sp-pwrbutton" }, 77 + {} 78 + }; 79 + 80 + static struct platform_driver rave_sp_pwrbutton_driver = { 81 + .probe = rave_sp_pwrbutton_probe, 82 + .driver = { 83 + .name = KBUILD_MODNAME, 84 + .of_match_table = rave_sp_pwrbutton_of_match, 85 + }, 86 + }; 87 + module_platform_driver(rave_sp_pwrbutton_driver); 88 + 89 + MODULE_DEVICE_TABLE(of, rave_sp_pwrbutton_of_match); 90 + MODULE_LICENSE("GPL"); 91 + MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>"); 92 + MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>"); 93 + MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>"); 94 + MODULE_DESCRIPTION("RAVE SP Power Button driver");
+34 -30
drivers/input/mouse/alps.c
··· 139 139 }; 140 140 141 141 static const struct alps_protocol_info alps_v3_protocol_data = { 142 - ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT 142 + ALPS_PROTO_V3, 0x8f, 0x8f, ALPS_DUALPOINT | ALPS_DUALPOINT_WITH_PRESSURE 143 143 }; 144 144 145 145 static const struct alps_protocol_info alps_v3_rushmore_data = { 146 - ALPS_PROTO_V3_RUSHMORE, 0x8f, 0x8f, ALPS_DUALPOINT 146 + ALPS_PROTO_V3_RUSHMORE, 0x8f, 0x8f, ALPS_DUALPOINT | ALPS_DUALPOINT_WITH_PRESSURE 147 147 }; 148 148 149 149 static const struct alps_protocol_info alps_v4_protocol_data = { ··· 155 155 }; 156 156 157 157 static const struct alps_protocol_info alps_v7_protocol_data = { 158 - ALPS_PROTO_V7, 0x48, 0x48, ALPS_DUALPOINT 158 + ALPS_PROTO_V7, 0x48, 0x48, ALPS_DUALPOINT | ALPS_DUALPOINT_WITH_PRESSURE 159 159 }; 160 160 161 161 static const struct alps_protocol_info alps_v8_protocol_data = { ··· 583 583 584 584 x = (s8)(((packet[0] & 0x20) << 2) | (packet[1] & 0x7f)); 585 585 y = (s8)(((packet[0] & 0x10) << 3) | (packet[2] & 0x7f)); 586 - z = (packet[4] & 0x7c) >> 2; 586 + z = packet[4] & 0x7c; 587 587 588 588 /* 589 589 * The x and y values tend to be quite large, and when used ··· 595 595 596 596 input_report_rel(dev, REL_X, x); 597 597 input_report_rel(dev, REL_Y, -y); 598 + input_report_abs(dev, ABS_PRESSURE, z); 598 599 599 600 /* 600 601 * Most ALPS models report the trackstick buttons in the touchpad ··· 828 827 unsigned char *packet = psmouse->packet; 829 828 struct input_dev *dev = psmouse->dev; 830 829 struct input_dev *dev2 = priv->dev2; 831 - int x, y, z, left, right, middle; 830 + int x, y, z; 832 831 833 832 /* 834 833 * We can use Byte5 to distinguish if the packet is from Touchpad ··· 848 847 x = packet[1] | ((packet[3] & 0x20) << 2); 849 848 y = packet[2] | ((packet[3] & 0x40) << 1); 850 849 z = packet[4]; 851 - left = packet[3] & 0x01; 852 - right = packet[3] & 0x02; 853 - middle = packet[3] & 0x04; 854 850 855 851 /* To prevent the cursor jump when finger lifted */ 856 852 if (x == 0x7F && y == 0x7F && z == 0x7F) ··· 857 859 input_report_rel(dev2, REL_X, (char)x / 4); 858 860 input_report_rel(dev2, REL_Y, -((char)y / 4)); 859 861 860 - input_report_key(dev2, BTN_LEFT, left); 861 - input_report_key(dev2, BTN_RIGHT, right); 862 - input_report_key(dev2, BTN_MIDDLE, middle); 862 + psmouse_report_standard_buttons(dev2, packet[3]); 863 863 864 864 input_sync(dev2); 865 865 return; ··· 867 871 x = packet[1] | ((packet[3] & 0x78) << 4); 868 872 y = packet[2] | ((packet[4] & 0x78) << 4); 869 873 z = packet[5]; 870 - left = packet[3] & 0x01; 871 - right = packet[3] & 0x02; 872 874 873 875 if (z > 30) 874 876 input_report_key(dev, BTN_TOUCH, 1); ··· 882 888 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 883 889 884 890 /* v6 touchpad does not have middle button */ 885 - input_report_key(dev, BTN_LEFT, left); 886 - input_report_key(dev, BTN_RIGHT, right); 891 + packet[3] &= ~BIT(2); 892 + psmouse_report_standard_buttons(dev2, packet[3]); 887 893 888 894 input_sync(dev); 889 895 } ··· 1092 1098 struct alps_data *priv = psmouse->private; 1093 1099 unsigned char *packet = psmouse->packet; 1094 1100 struct input_dev *dev2 = priv->dev2; 1095 - int x, y, z, left, right, middle; 1101 + int x, y, z; 1096 1102 1097 1103 /* It should be a DualPoint when received trackstick packet */ 1098 1104 if (!(priv->flags & ALPS_DUALPOINT)) { ··· 1106 1112 ((packet[3] & 0x20) << 1); 1107 1113 z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1); 1108 1114 1109 - left = (packet[1] & 0x01); 1110 - right = (packet[1] & 0x02) >> 1; 1111 - middle = (packet[1] & 0x04) >> 2; 1112 - 1113 1115 input_report_rel(dev2, REL_X, (char)x); 1114 1116 input_report_rel(dev2, REL_Y, -((char)y)); 1117 + input_report_abs(dev2, ABS_PRESSURE, z); 1115 1118 1116 - input_report_key(dev2, BTN_LEFT, left); 1117 - input_report_key(dev2, BTN_RIGHT, right); 1118 - input_report_key(dev2, BTN_MIDDLE, middle); 1119 + psmouse_report_standard_buttons(dev2, packet[1]); 1119 1120 1120 1121 input_sync(dev2); 1121 1122 } ··· 1492 1503 alps_report_buttons(dev, dev2, 1493 1504 packet[0] & 1, packet[0] & 2, packet[0] & 4); 1494 1505 1495 - input_report_rel(dev, REL_X, 1496 - packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); 1497 - input_report_rel(dev, REL_Y, 1498 - packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); 1506 + psmouse_report_standard_motion(dev, packet); 1499 1507 1500 1508 input_sync(dev); 1501 1509 } ··· 2530 2544 } 2531 2545 2532 2546 static int alps_update_dual_info_ss4_v2(unsigned char otp[][4], 2533 - struct alps_data *priv) 2547 + struct alps_data *priv, 2548 + struct psmouse *psmouse) 2534 2549 { 2535 2550 bool is_dual = false; 2551 + int reg_val = 0; 2552 + struct ps2dev *ps2dev = &psmouse->ps2dev; 2536 2553 2537 - if (IS_SS4PLUS_DEV(priv->dev_id)) 2554 + if (IS_SS4PLUS_DEV(priv->dev_id)) { 2538 2555 is_dual = (otp[0][0] >> 4) & 0x01; 2556 + 2557 + if (!is_dual) { 2558 + /* For support TrackStick of Thinkpad L/E series */ 2559 + if (alps_exit_command_mode(psmouse) == 0 && 2560 + alps_enter_command_mode(psmouse) == 0) { 2561 + reg_val = alps_command_mode_read_reg(psmouse, 2562 + 0xD7); 2563 + } 2564 + alps_exit_command_mode(psmouse); 2565 + ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE); 2566 + 2567 + if (reg_val == 0x0C || reg_val == 0x1D) 2568 + is_dual = true; 2569 + } 2570 + } 2539 2571 2540 2572 if (is_dual) 2541 2573 priv->flags |= ALPS_DUALPOINT | ··· 2577 2573 2578 2574 alps_update_btn_info_ss4_v2(otp, priv); 2579 2575 2580 - alps_update_dual_info_ss4_v2(otp, priv); 2576 + alps_update_dual_info_ss4_v2(otp, priv, psmouse); 2581 2577 2582 2578 return 0; 2583 2579 }
+3 -3
drivers/input/mouse/appletouch.c
··· 587 587 /* Perform size detection, if not done already */ 588 588 if (unlikely(!dev->size_detect_done)) { 589 589 atp_detect_size(dev); 590 - dev->size_detect_done = 1; 590 + dev->size_detect_done = true; 591 591 goto exit; 592 592 } 593 593 } ··· 813 813 if (usb_submit_urb(dev->urb, GFP_ATOMIC)) 814 814 return -EIO; 815 815 816 - dev->open = 1; 816 + dev->open = true; 817 817 return 0; 818 818 } 819 819 ··· 823 823 824 824 usb_kill_urb(dev->urb); 825 825 cancel_work_sync(&dev->work); 826 - dev->open = 0; 826 + dev->open = false; 827 827 } 828 828 829 829 static int atp_handle_geyser(struct atp *dev)
+16 -24
drivers/input/mouse/elantech.c
··· 35 35 static int synaptics_send_cmd(struct psmouse *psmouse, unsigned char c, 36 36 unsigned char *param) 37 37 { 38 - if (psmouse_sliced_command(psmouse, c) || 38 + if (ps2_sliced_command(&psmouse->ps2dev, c) || 39 39 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) { 40 40 psmouse_err(psmouse, "%s query 0x%02x failed.\n", __func__, c); 41 41 return -1; ··· 107 107 108 108 switch (etd->hw_version) { 109 109 case 1: 110 - if (psmouse_sliced_command(psmouse, ETP_REGISTER_READ) || 111 - psmouse_sliced_command(psmouse, reg) || 110 + if (ps2_sliced_command(&psmouse->ps2dev, ETP_REGISTER_READ) || 111 + ps2_sliced_command(&psmouse->ps2dev, reg) || 112 112 ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_GETINFO)) { 113 113 rc = -1; 114 114 } ··· 162 162 163 163 switch (etd->hw_version) { 164 164 case 1: 165 - if (psmouse_sliced_command(psmouse, ETP_REGISTER_WRITE) || 166 - psmouse_sliced_command(psmouse, reg) || 167 - psmouse_sliced_command(psmouse, val) || 165 + if (ps2_sliced_command(&psmouse->ps2dev, ETP_REGISTER_WRITE) || 166 + ps2_sliced_command(&psmouse->ps2dev, reg) || 167 + ps2_sliced_command(&psmouse->ps2dev, val) || 168 168 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) { 169 169 rc = -1; 170 170 } ··· 279 279 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1); 280 280 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 281 281 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 282 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 283 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 282 + 283 + psmouse_report_standard_buttons(dev, packet[0]); 284 284 285 285 if (etd->fw_version < 0x020000 && 286 286 (etd->capabilities[0] & ETP_CAP_HAS_ROCKER)) { ··· 390 390 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 391 391 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 392 392 input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4); 393 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 394 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 393 + psmouse_report_standard_buttons(dev, packet[0]); 395 394 if (etd->reports_pressure) { 396 395 input_report_abs(dev, ABS_PRESSURE, pres); 397 396 input_report_abs(dev, ABS_TOOL_WIDTH, width); ··· 433 434 x = packet[4] - (int)((packet[1]^0x80) << 1); 434 435 y = (int)((packet[2]^0x80) << 1) - packet[5]; 435 436 436 - input_report_key(tp_dev, BTN_LEFT, packet[0] & 0x01); 437 - input_report_key(tp_dev, BTN_RIGHT, packet[0] & 0x02); 438 - input_report_key(tp_dev, BTN_MIDDLE, packet[0] & 0x04); 437 + psmouse_report_standard_buttons(tp_dev, packet[0]); 439 438 440 439 input_report_rel(tp_dev, REL_X, x); 441 440 input_report_rel(tp_dev, REL_Y, y); ··· 523 526 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 524 527 525 528 /* For clickpads map both buttons to BTN_LEFT */ 526 - if (etd->fw_version & 0x001000) { 529 + if (etd->fw_version & 0x001000) 527 530 input_report_key(dev, BTN_LEFT, packet[0] & 0x03); 528 - } else { 529 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 530 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 531 - } 531 + else 532 + psmouse_report_standard_buttons(dev, packet[0]); 532 533 533 534 input_report_abs(dev, ABS_PRESSURE, pres); 534 535 input_report_abs(dev, ABS_TOOL_WIDTH, width); ··· 541 546 unsigned char *packet = psmouse->packet; 542 547 543 548 /* For clickpads map both buttons to BTN_LEFT */ 544 - if (etd->fw_version & 0x001000) { 549 + if (etd->fw_version & 0x001000) 545 550 input_report_key(dev, BTN_LEFT, packet[0] & 0x03); 546 - } else { 547 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 548 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 549 - input_report_key(dev, BTN_MIDDLE, packet[0] & 0x04); 550 - } 551 + else 552 + psmouse_report_standard_buttons(dev, packet[0]); 551 553 552 554 input_mt_report_pointer_emulation(dev, true); 553 555 input_sync(dev);
+33 -29
drivers/input/mouse/lifebook.c
··· 17 17 #include <linux/libps2.h> 18 18 #include <linux/dmi.h> 19 19 #include <linux/slab.h> 20 + #include <linux/types.h> 20 21 21 22 #include "psmouse.h" 22 23 #include "lifebook.h" ··· 137 136 struct lifebook_data *priv = psmouse->private; 138 137 struct input_dev *dev1 = psmouse->dev; 139 138 struct input_dev *dev2 = priv ? priv->dev2 : NULL; 140 - unsigned char *packet = psmouse->packet; 139 + u8 *packet = psmouse->packet; 141 140 bool relative_packet = packet[0] & 0x08; 142 141 143 142 if (relative_packet || !lifebook_use_6byte_proto) { ··· 189 188 } 190 189 191 190 if (dev2) { 192 - if (relative_packet) { 193 - input_report_rel(dev2, REL_X, 194 - ((packet[0] & 0x10) ? packet[1] - 256 : packet[1])); 195 - input_report_rel(dev2, REL_Y, 196 - -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2])); 197 - } 198 - input_report_key(dev2, BTN_LEFT, packet[0] & 0x01); 199 - input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02); 191 + if (relative_packet) 192 + psmouse_report_standard_motion(dev2, packet); 193 + 194 + psmouse_report_standard_buttons(dev2, packet[0]); 200 195 input_sync(dev2); 201 196 } 202 197 ··· 202 205 static int lifebook_absolute_mode(struct psmouse *psmouse) 203 206 { 204 207 struct ps2dev *ps2dev = &psmouse->ps2dev; 205 - unsigned char param; 208 + u8 param; 209 + int error; 206 210 207 - if (psmouse_reset(psmouse)) 208 - return -1; 211 + error = psmouse_reset(psmouse); 212 + if (error) 213 + return error; 209 214 210 215 /* 211 216 * Enable absolute output -- ps2_command fails always but if ··· 223 224 static void lifebook_relative_mode(struct psmouse *psmouse) 224 225 { 225 226 struct ps2dev *ps2dev = &psmouse->ps2dev; 226 - unsigned char param = 0x06; 227 + u8 param = 0x06; 227 228 228 229 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES); 229 230 } 230 231 231 232 static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution) 232 233 { 233 - static const unsigned char params[] = { 0, 1, 2, 2, 3 }; 234 - unsigned char p; 234 + static const u8 params[] = { 0, 1, 2, 2, 3 }; 235 + u8 p; 235 236 236 237 if (resolution == 0 || resolution > 400) 237 238 resolution = 400; ··· 256 257 int lifebook_detect(struct psmouse *psmouse, bool set_properties) 257 258 { 258 259 if (!lifebook_present) 259 - return -1; 260 + return -ENXIO; 260 261 261 262 if (desired_serio_phys && 262 263 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys)) 263 - return -1; 264 + return -ENXIO; 264 265 265 266 if (set_properties) { 266 267 psmouse->vendor = "Fujitsu"; ··· 293 294 dev2->id.version = 0x0000; 294 295 dev2->dev.parent = &psmouse->ps2dev.serio->dev; 295 296 296 - dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 297 - dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 298 - dev2->keybit[BIT_WORD(BTN_LEFT)] = 299 - BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); 297 + input_set_capability(dev2, EV_REL, REL_X); 298 + input_set_capability(dev2, EV_REL, REL_Y); 299 + input_set_capability(dev2, EV_KEY, BTN_LEFT); 300 + input_set_capability(dev2, EV_KEY, BTN_RIGHT); 300 301 301 302 error = input_register_device(priv->dev2); 302 303 if (error) ··· 315 316 { 316 317 struct input_dev *dev1 = psmouse->dev; 317 318 int max_coord = lifebook_use_6byte_proto ? 4096 : 1024; 319 + int error; 318 320 319 - if (lifebook_absolute_mode(psmouse)) 320 - return -1; 321 + error = lifebook_absolute_mode(psmouse); 322 + if (error) 323 + return error; 321 324 322 - dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); 323 - dev1->relbit[0] = 0; 324 - dev1->keybit[BIT_WORD(BTN_MOUSE)] = 0; 325 - dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 325 + /* Clear default capabilities */ 326 + bitmap_zero(dev1->evbit, EV_CNT); 327 + bitmap_zero(dev1->relbit, REL_CNT); 328 + bitmap_zero(dev1->keybit, KEY_CNT); 329 + 330 + input_set_capability(dev1, EV_KEY, BTN_TOUCH); 326 331 input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0); 327 332 input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0); 328 333 329 334 if (!desired_serio_phys) { 330 - if (lifebook_create_relative_device(psmouse)) { 335 + error = lifebook_create_relative_device(psmouse); 336 + if (error) { 331 337 lifebook_relative_mode(psmouse); 332 - return -1; 338 + return error; 333 339 } 334 340 } 335 341
+87 -65
drivers/input/mouse/logips2pp.c
··· 9 9 * the Free Software Foundation. 10 10 */ 11 11 12 + #include <linux/bitops.h> 12 13 #include <linux/input.h> 13 14 #include <linux/serio.h> 14 15 #include <linux/libps2.h> 16 + #include <linux/types.h> 15 17 #include "psmouse.h" 16 18 #include "logips2pp.h" 17 19 ··· 24 22 #define PS2PP_KIND_TRACKMAN 4 25 23 26 24 /* Logitech mouse features */ 27 - #define PS2PP_WHEEL 0x01 28 - #define PS2PP_HWHEEL 0x02 29 - #define PS2PP_SIDE_BTN 0x04 30 - #define PS2PP_EXTRA_BTN 0x08 31 - #define PS2PP_TASK_BTN 0x10 32 - #define PS2PP_NAV_BTN 0x20 25 + #define PS2PP_WHEEL BIT(0) 26 + #define PS2PP_HWHEEL BIT(1) 27 + #define PS2PP_SIDE_BTN BIT(2) 28 + #define PS2PP_EXTRA_BTN BIT(3) 29 + #define PS2PP_TASK_BTN BIT(4) 30 + #define PS2PP_NAV_BTN BIT(5) 33 31 34 32 struct ps2pp_info { 35 33 u8 model; ··· 44 42 static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse) 45 43 { 46 44 struct input_dev *dev = psmouse->dev; 47 - unsigned char *packet = psmouse->packet; 45 + u8 *packet = psmouse->packet; 48 46 49 47 if (psmouse->pktcnt < 3) 50 48 return PSMOUSE_GOOD_DATA; ··· 60 58 61 59 case 0x0d: /* Mouse extra info */ 62 60 63 - input_report_rel(dev, packet[2] & 0x80 ? REL_HWHEEL : REL_WHEEL, 64 - (int) (packet[2] & 8) - (int) (packet[2] & 7)); 65 - input_report_key(dev, BTN_SIDE, (packet[2] >> 4) & 1); 66 - input_report_key(dev, BTN_EXTRA, (packet[2] >> 5) & 1); 61 + input_report_rel(dev, 62 + packet[2] & 0x80 ? REL_HWHEEL : REL_WHEEL, 63 + -sign_extend32(packet[2], 3)); 64 + input_report_key(dev, BTN_SIDE, packet[2] & BIT(4)); 65 + input_report_key(dev, BTN_EXTRA, packet[2] & BIT(5)); 67 66 68 67 break; 69 68 70 69 case 0x0e: /* buttons 4, 5, 6, 7, 8, 9, 10 info */ 71 70 72 - input_report_key(dev, BTN_SIDE, (packet[2]) & 1); 73 - input_report_key(dev, BTN_EXTRA, (packet[2] >> 1) & 1); 74 - input_report_key(dev, BTN_BACK, (packet[2] >> 3) & 1); 75 - input_report_key(dev, BTN_FORWARD, (packet[2] >> 4) & 1); 76 - input_report_key(dev, BTN_TASK, (packet[2] >> 2) & 1); 71 + input_report_key(dev, BTN_SIDE, packet[2] & BIT(0)); 72 + input_report_key(dev, BTN_EXTRA, packet[2] & BIT(1)); 73 + input_report_key(dev, BTN_TASK, packet[2] & BIT(2)); 74 + input_report_key(dev, BTN_BACK, packet[2] & BIT(3)); 75 + input_report_key(dev, BTN_FORWARD, packet[2] & BIT(4)); 77 76 78 77 break; 79 78 80 79 case 0x0f: /* TouchPad extra info */ 81 80 82 - input_report_rel(dev, packet[2] & 0x08 ? REL_HWHEEL : REL_WHEEL, 83 - (int) ((packet[2] >> 4) & 8) - (int) ((packet[2] >> 4) & 7)); 84 - packet[0] = packet[2] | 0x08; 81 + input_report_rel(dev, 82 + packet[2] & 0x08 ? REL_HWHEEL : REL_WHEEL, 83 + -sign_extend32(packet[2] >> 4, 3)); 84 + packet[0] = packet[2] | BIT(3); 85 85 break; 86 86 87 87 default: ··· 92 88 (packet[1] >> 4) | (packet[0] & 0x30)); 93 89 break; 94 90 } 91 + 92 + psmouse_report_standard_buttons(dev, packet[0]); 93 + 95 94 } else { 96 95 /* Standard PS/2 motion data */ 97 - input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); 98 - input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); 96 + psmouse_report_standard_packet(dev, packet); 99 97 } 100 - 101 - input_report_key(dev, BTN_LEFT, packet[0] & 1); 102 - input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 103 - input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); 104 98 105 99 input_sync(dev); 106 100 ··· 113 111 * Ugly. 114 112 */ 115 113 116 - static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned char command) 114 + static int ps2pp_cmd(struct psmouse *psmouse, u8 *param, u8 command) 117 115 { 118 - if (psmouse_sliced_command(psmouse, command)) 119 - return -1; 116 + int error; 120 117 121 - if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL | 0x0300)) 122 - return -1; 118 + error = ps2_sliced_command(&psmouse->ps2dev, command); 119 + if (error) 120 + return error; 121 + 122 + error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL | 0x0300); 123 + if (error) 124 + return error; 123 125 124 126 return 0; 125 127 } ··· 139 133 static void ps2pp_set_smartscroll(struct psmouse *psmouse, bool smartscroll) 140 134 { 141 135 struct ps2dev *ps2dev = &psmouse->ps2dev; 142 - unsigned char param[4]; 136 + u8 param[4]; 143 137 144 138 ps2pp_cmd(psmouse, param, 0x32); 145 139 ··· 177 171 } 178 172 179 173 PSMOUSE_DEFINE_ATTR(smartscroll, S_IWUSR | S_IRUGO, NULL, 180 - ps2pp_attr_show_smartscroll, ps2pp_attr_set_smartscroll); 174 + ps2pp_attr_show_smartscroll, ps2pp_attr_set_smartscroll); 181 175 182 176 /* 183 177 * Support 800 dpi resolution _only_ if the user wants it (there are good ··· 185 179 * also good reasons to use it, let the user decide). 186 180 */ 187 181 188 - static void ps2pp_set_resolution(struct psmouse *psmouse, unsigned int resolution) 182 + static void ps2pp_set_resolution(struct psmouse *psmouse, 183 + unsigned int resolution) 189 184 { 190 185 if (resolution > 400) { 191 186 struct ps2dev *ps2dev = &psmouse->ps2dev; 192 - unsigned char param = 3; 187 + u8 param = 3; 193 188 194 189 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); 195 190 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE11); ··· 203 196 204 197 static void ps2pp_disconnect(struct psmouse *psmouse) 205 198 { 206 - device_remove_file(&psmouse->ps2dev.serio->dev, &psmouse_attr_smartscroll.dattr); 199 + device_remove_file(&psmouse->ps2dev.serio->dev, 200 + &psmouse_attr_smartscroll.dattr); 207 201 } 208 202 209 203 static const struct ps2pp_info *get_model_info(unsigned char model) ··· 277 269 struct input_dev *input_dev = psmouse->dev; 278 270 279 271 if (model_info->features & PS2PP_SIDE_BTN) 280 - __set_bit(BTN_SIDE, input_dev->keybit); 272 + input_set_capability(input_dev, EV_KEY, BTN_SIDE); 281 273 282 274 if (model_info->features & PS2PP_EXTRA_BTN) 283 - __set_bit(BTN_EXTRA, input_dev->keybit); 275 + input_set_capability(input_dev, EV_KEY, BTN_EXTRA); 284 276 285 277 if (model_info->features & PS2PP_TASK_BTN) 286 - __set_bit(BTN_TASK, input_dev->keybit); 278 + input_set_capability(input_dev, EV_KEY, BTN_TASK); 287 279 288 280 if (model_info->features & PS2PP_NAV_BTN) { 289 - __set_bit(BTN_FORWARD, input_dev->keybit); 290 - __set_bit(BTN_BACK, input_dev->keybit); 281 + input_set_capability(input_dev, EV_KEY, BTN_FORWARD); 282 + input_set_capability(input_dev, EV_KEY, BTN_BACK); 291 283 } 292 284 293 285 if (model_info->features & PS2PP_WHEEL) 294 - __set_bit(REL_WHEEL, input_dev->relbit); 286 + input_set_capability(input_dev, EV_REL, REL_WHEEL); 295 287 296 288 if (model_info->features & PS2PP_HWHEEL) 297 - __set_bit(REL_HWHEEL, input_dev->relbit); 289 + input_set_capability(input_dev, EV_REL, REL_HWHEEL); 298 290 299 291 switch (model_info->kind) { 300 292 ··· 326 318 } 327 319 } 328 320 321 + static int ps2pp_setup_protocol(struct psmouse *psmouse, 322 + const struct ps2pp_info *model_info) 323 + { 324 + int error; 325 + 326 + psmouse->protocol_handler = ps2pp_process_byte; 327 + psmouse->pktsize = 3; 328 + 329 + if (model_info->kind != PS2PP_KIND_TP3) { 330 + psmouse->set_resolution = ps2pp_set_resolution; 331 + psmouse->disconnect = ps2pp_disconnect; 332 + 333 + error = device_create_file(&psmouse->ps2dev.serio->dev, 334 + &psmouse_attr_smartscroll.dattr); 335 + if (error) { 336 + psmouse_err(psmouse, 337 + "failed to create smartscroll sysfs attribute, error: %d\n", 338 + error); 339 + return error; 340 + } 341 + } 342 + 343 + return 0; 344 + } 329 345 330 346 /* 331 347 * Logitech magic init. Detect whether the mouse is a Logitech one ··· 360 328 int ps2pp_detect(struct psmouse *psmouse, bool set_properties) 361 329 { 362 330 struct ps2dev *ps2dev = &psmouse->ps2dev; 363 - unsigned char param[4]; 364 - unsigned char model, buttons; 365 331 const struct ps2pp_info *model_info; 332 + u8 param[4]; 333 + u8 model, buttons; 366 334 bool use_ps2pp = false; 367 335 int error; 368 336 ··· 378 346 buttons = param[1]; 379 347 380 348 if (!model || !buttons) 381 - return -1; 349 + return -ENXIO; 382 350 383 351 model_info = get_model_info(model); 384 352 if (model_info) { ··· 400 368 401 369 param[0] = 0; 402 370 if (!ps2_command(ps2dev, param, 0x13d1) && 403 - param[0] == 0x06 && param[1] == 0x00 && param[2] == 0x14) { 371 + param[0] == 0x06 && param[1] == 0x00 && 372 + param[2] == 0x14) { 404 373 use_ps2pp = true; 405 374 } 406 375 ··· 420 387 } 421 388 422 389 } else { 423 - psmouse_warn(psmouse, "Detected unknown Logitech mouse model %d\n", model); 390 + psmouse_warn(psmouse, 391 + "Detected unknown Logitech mouse model %d\n", 392 + model); 424 393 } 425 394 426 395 if (set_properties) { ··· 430 395 psmouse->model = model; 431 396 432 397 if (use_ps2pp) { 433 - psmouse->protocol_handler = ps2pp_process_byte; 434 - psmouse->pktsize = 3; 435 - 436 - if (model_info->kind != PS2PP_KIND_TP3) { 437 - psmouse->set_resolution = ps2pp_set_resolution; 438 - psmouse->disconnect = ps2pp_disconnect; 439 - 440 - error = device_create_file(&ps2dev->serio->dev, 441 - &psmouse_attr_smartscroll.dattr); 442 - if (error) { 443 - psmouse_err(psmouse, 444 - "failed to create smartscroll sysfs attribute, error: %d\n", 445 - error); 446 - return -1; 447 - } 448 - } 398 + error = ps2pp_setup_protocol(psmouse, model_info); 399 + if (error) 400 + return error; 449 401 } 450 402 451 403 if (buttons >= 3) 452 - __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 404 + input_set_capability(psmouse->dev, EV_KEY, BTN_MIDDLE); 453 405 454 406 if (model_info) 455 407 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp); 456 408 } 457 409 458 - return use_ps2pp ? 0 : -1; 410 + return use_ps2pp ? 0 : -ENXIO; 459 411 } 460 412
+103 -86
drivers/input/mouse/psmouse-base.c
··· 14 14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 15 #define psmouse_fmt(fmt) fmt 16 16 17 + #include <linux/bitops.h> 17 18 #include <linux/delay.h> 18 19 #include <linux/module.h> 19 20 #include <linux/slab.h> ··· 24 23 #include <linux/init.h> 25 24 #include <linux/libps2.h> 26 25 #include <linux/mutex.h> 26 + #include <linux/types.h> 27 27 28 28 #include "psmouse.h" 29 29 #include "synaptics.h" ··· 69 67 static bool psmouse_smartscroll = true; 70 68 module_param_named(smartscroll, psmouse_smartscroll, bool, 0644); 71 69 MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled."); 70 + 71 + static bool psmouse_a4tech_2wheels; 72 + module_param_named(a4tech_workaround, psmouse_a4tech_2wheels, bool, 0644); 73 + MODULE_PARM_DESC(a4tech_workaround, "A4Tech second scroll wheel workaround, 1 = enabled, 0 = disabled (default)."); 72 74 73 75 static unsigned int psmouse_resetafter = 5; 74 76 module_param_named(resetafter, psmouse_resetafter, uint, 0644); ··· 122 116 123 117 static struct workqueue_struct *kpsmoused_wq; 124 118 125 - static void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) 119 + void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) 126 120 { 127 121 input_report_key(dev, BTN_LEFT, buttons & BIT(0)); 128 122 input_report_key(dev, BTN_MIDDLE, buttons & BIT(2)); 129 123 input_report_key(dev, BTN_RIGHT, buttons & BIT(1)); 124 + } 125 + 126 + void psmouse_report_standard_motion(struct input_dev *dev, u8 *packet) 127 + { 128 + int x, y; 129 + 130 + x = packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0; 131 + y = packet[2] ? packet[2] - ((packet[0] << 3) & 0x100) : 0; 132 + 133 + input_report_rel(dev, REL_X, x); 134 + input_report_rel(dev, REL_Y, -y); 135 + } 136 + 137 + void psmouse_report_standard_packet(struct input_dev *dev, u8 *packet) 138 + { 139 + psmouse_report_standard_buttons(dev, packet[0]); 140 + psmouse_report_standard_motion(dev, packet); 130 141 } 131 142 132 143 /* ··· 153 130 psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) 154 131 { 155 132 struct input_dev *dev = psmouse->dev; 156 - unsigned char *packet = psmouse->packet; 133 + u8 *packet = psmouse->packet; 134 + int wheel; 157 135 158 136 if (psmouse->pktcnt < psmouse->pktsize) 159 137 return PSMOUSE_GOOD_DATA; ··· 164 140 switch (psmouse->protocol->type) { 165 141 case PSMOUSE_IMPS: 166 142 /* IntelliMouse has scroll wheel */ 167 - input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 143 + input_report_rel(dev, REL_WHEEL, -(s8) packet[3]); 168 144 break; 169 145 170 146 case PSMOUSE_IMEX: 171 147 /* Scroll wheel and buttons on IntelliMouse Explorer */ 172 148 switch (packet[3] & 0xC0) { 173 149 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ 174 - input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); 150 + input_report_rel(dev, REL_WHEEL, 151 + -sign_extend32(packet[3], 5)); 175 152 break; 176 153 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */ 177 - input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); 154 + input_report_rel(dev, REL_HWHEEL, 155 + -sign_extend32(packet[3], 5)); 178 156 break; 179 157 case 0x00: 180 158 case 0xC0: 181 - input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7)); 182 - input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1); 183 - input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); 159 + wheel = sign_extend32(packet[3], 3); 160 + 161 + /* 162 + * Some A4Tech mice have two scroll wheels, with first 163 + * one reporting +/-1 in the lower nibble, and second 164 + * one reporting +/-2. 165 + */ 166 + if (psmouse_a4tech_2wheels && abs(wheel) > 1) 167 + input_report_rel(dev, REL_HWHEEL, wheel / 2); 168 + else 169 + input_report_rel(dev, REL_WHEEL, -wheel); 170 + 171 + input_report_key(dev, BTN_SIDE, BIT(4)); 172 + input_report_key(dev, BTN_EXTRA, BIT(5)); 184 173 break; 185 174 } 186 175 break; 187 176 188 177 case PSMOUSE_GENPS: 189 178 /* Report scroll buttons on NetMice */ 190 - input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 179 + input_report_rel(dev, REL_WHEEL, -(s8) packet[3]); 191 180 192 181 /* Extra buttons on Genius NewNet 3D */ 193 - input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); 194 - input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); 182 + input_report_key(dev, BTN_SIDE, BIT(6)); 183 + input_report_key(dev, BTN_EXTRA, BIT(7)); 195 184 break; 196 185 197 186 case PSMOUSE_THINKPS: 198 187 /* Extra button on ThinkingMouse */ 199 - input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); 188 + input_report_key(dev, BTN_EXTRA, BIT(3)); 200 189 201 190 /* 202 191 * Without this bit of weirdness moving up gives wildly ··· 223 186 * Cortron PS2 Trackball reports SIDE button in the 224 187 * 4th bit of the first byte. 225 188 */ 226 - input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); 227 - packet[0] |= 0x08; 189 + input_report_key(dev, BTN_SIDE, BIT(3)); 190 + packet[0] |= BIT(3); 228 191 break; 229 192 230 193 default: ··· 232 195 } 233 196 234 197 /* Generic PS/2 Mouse */ 235 - psmouse_report_standard_buttons(dev, 236 - packet[0] | psmouse->extra_buttons); 237 - 238 - input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); 239 - input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); 198 + packet[0] |= psmouse->extra_buttons; 199 + psmouse_report_standard_packet(dev, packet); 240 200 241 201 input_sync(dev); 242 202 ··· 289 255 psmouse_notice(psmouse, 290 256 "issuing reconnect request\n"); 291 257 serio_reconnect(psmouse->ps2dev.serio); 292 - return -1; 258 + return -EIO; 293 259 } 294 260 } 295 261 psmouse->pktcnt = 0; ··· 340 306 * for normal processing or gathering them as command response. 341 307 */ 342 308 static irqreturn_t psmouse_interrupt(struct serio *serio, 343 - unsigned char data, unsigned int flags) 309 + u8 data, unsigned int flags) 344 310 { 345 311 struct psmouse *psmouse = serio_get_drvdata(serio); 346 312 ··· 432 398 } 433 399 434 400 /* 435 - * psmouse_sliced_command() sends an extended PS/2 command to the mouse 436 - * using sliced syntax, understood by advanced devices, such as Logitech 437 - * or Synaptics touchpads. The command is encoded as: 438 - * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu 439 - * is the command. 440 - */ 441 - int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command) 442 - { 443 - int i; 444 - 445 - if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) 446 - return -1; 447 - 448 - for (i = 6; i >= 0; i -= 2) { 449 - unsigned char d = (command >> i) & 3; 450 - if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES)) 451 - return -1; 452 - } 453 - 454 - return 0; 455 - } 456 - 457 - /* 458 401 * psmouse_reset() resets the mouse into power-on state. 459 402 */ 460 403 int psmouse_reset(struct psmouse *psmouse) 461 404 { 462 - unsigned char param[2]; 405 + u8 param[2]; 406 + int error; 463 407 464 - if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT)) 465 - return -1; 408 + error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT); 409 + if (error) 410 + return error; 466 411 467 412 if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID) 468 - return -1; 413 + return -EIO; 469 414 470 415 return 0; 471 416 } ··· 454 441 */ 455 442 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) 456 443 { 457 - static const unsigned char params[] = { 0, 1, 2, 2, 3 }; 458 - unsigned char p; 444 + static const u8 params[] = { 0, 1, 2, 2, 3 }; 445 + u8 p; 459 446 460 447 if (resolution == 0 || resolution > 200) 461 448 resolution = 200; ··· 470 457 */ 471 458 static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) 472 459 { 473 - static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; 474 - unsigned char r; 460 + static const u8 rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; 461 + u8 r; 475 462 int i = 0; 476 463 477 - while (rates[i] > rate) i++; 464 + while (rates[i] > rate) 465 + i++; 478 466 r = rates[i]; 479 467 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE); 480 468 psmouse->rate = r; ··· 547 533 static int genius_detect(struct psmouse *psmouse, bool set_properties) 548 534 { 549 535 struct ps2dev *ps2dev = &psmouse->ps2dev; 550 - unsigned char param[4]; 536 + u8 param[4]; 551 537 552 538 param[0] = 3; 553 539 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); ··· 557 543 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); 558 544 559 545 if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55) 560 - return -1; 546 + return -ENODEV; 561 547 562 548 if (set_properties) { 563 549 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); ··· 579 565 static int intellimouse_detect(struct psmouse *psmouse, bool set_properties) 580 566 { 581 567 struct ps2dev *ps2dev = &psmouse->ps2dev; 582 - unsigned char param[2]; 568 + u8 param[2]; 583 569 584 570 param[0] = 200; 585 571 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); ··· 590 576 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 591 577 592 578 if (param[0] != 3) 593 - return -1; 579 + return -ENODEV; 594 580 595 581 if (set_properties) { 596 582 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); ··· 612 598 static int im_explorer_detect(struct psmouse *psmouse, bool set_properties) 613 599 { 614 600 struct ps2dev *ps2dev = &psmouse->ps2dev; 615 - unsigned char param[2]; 601 + u8 param[2]; 616 602 617 603 intellimouse_detect(psmouse, 0); 618 604 ··· 625 611 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 626 612 627 613 if (param[0] != 4) 628 - return -1; 614 + return -ENODEV; 629 615 630 616 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */ 631 617 param[0] = 200; ··· 658 644 static int thinking_detect(struct psmouse *psmouse, bool set_properties) 659 645 { 660 646 struct ps2dev *ps2dev = &psmouse->ps2dev; 661 - unsigned char param[2]; 662 - static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 }; 647 + u8 param[2]; 648 + static const u8 seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 }; 663 649 int i; 664 650 665 651 param[0] = 10; ··· 673 659 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 674 660 675 661 if (param[0] != 2) 676 - return -1; 662 + return -ENODEV; 677 663 678 664 if (set_properties) { 679 665 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); ··· 701 687 * We have no way of figuring true number of buttons so let's 702 688 * assume that the device has 3. 703 689 */ 704 - __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 690 + input_set_capability(psmouse->dev, EV_KEY, BTN_MIDDLE); 705 691 } 706 692 707 693 return 0; ··· 956 942 { 957 943 struct input_dev *input_dev = psmouse->dev; 958 944 959 - memset(input_dev->evbit, 0, sizeof(input_dev->evbit)); 960 - memset(input_dev->keybit, 0, sizeof(input_dev->keybit)); 961 - memset(input_dev->relbit, 0, sizeof(input_dev->relbit)); 962 - memset(input_dev->absbit, 0, sizeof(input_dev->absbit)); 963 - memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit)); 945 + bitmap_zero(input_dev->evbit, EV_CNT); 946 + bitmap_zero(input_dev->keybit, KEY_CNT); 947 + bitmap_zero(input_dev->relbit, REL_CNT); 948 + bitmap_zero(input_dev->absbit, ABS_CNT); 949 + bitmap_zero(input_dev->mscbit, MSC_CNT); 964 950 965 - __set_bit(EV_KEY, input_dev->evbit); 966 - __set_bit(EV_REL, input_dev->evbit); 951 + input_set_capability(input_dev, EV_KEY, BTN_LEFT); 952 + input_set_capability(input_dev, EV_KEY, BTN_RIGHT); 967 953 968 - __set_bit(BTN_LEFT, input_dev->keybit); 969 - __set_bit(BTN_RIGHT, input_dev->keybit); 970 - 971 - __set_bit(REL_X, input_dev->relbit); 972 - __set_bit(REL_Y, input_dev->relbit); 954 + input_set_capability(input_dev, EV_REL, REL_X); 955 + input_set_capability(input_dev, EV_REL, REL_Y); 973 956 974 957 __set_bit(INPUT_PROP_POINTER, input_dev->propbit); 975 958 ··· 1236 1225 static int psmouse_probe(struct psmouse *psmouse) 1237 1226 { 1238 1227 struct ps2dev *ps2dev = &psmouse->ps2dev; 1239 - unsigned char param[2]; 1228 + u8 param[2]; 1229 + int error; 1240 1230 1241 1231 /* 1242 1232 * First, we check if it's a mouse. It should send 0x00 or 0x03 in ··· 1246 1234 * subsequent ID queries, probably due to a firmware bug. 1247 1235 */ 1248 1236 param[0] = 0xa5; 1249 - if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) 1250 - return -1; 1237 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 1238 + if (error) 1239 + return error; 1251 1240 1252 1241 if (param[0] != 0x00 && param[0] != 0x03 && 1253 1242 param[0] != 0x04 && param[0] != 0xff) 1254 - return -1; 1243 + return -ENODEV; 1255 1244 1256 1245 /* 1257 1246 * Then we reset and disable the mouse so that it doesn't generate 1258 1247 * events. 1259 1248 */ 1260 - if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS)) 1261 - psmouse_warn(psmouse, "Failed to reset mouse on %s\n", 1262 - ps2dev->serio->phys); 1249 + error = ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 1250 + if (error) 1251 + psmouse_warn(psmouse, "Failed to reset mouse on %s: %d\n", 1252 + ps2dev->serio->phys, error); 1263 1253 1264 1254 return 0; 1265 1255 } ··· 1302 1288 */ 1303 1289 int psmouse_deactivate(struct psmouse *psmouse) 1304 1290 { 1305 - if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) { 1306 - psmouse_warn(psmouse, "Failed to deactivate mouse on %s\n", 1307 - psmouse->ps2dev.serio->phys); 1308 - return -1; 1291 + int error; 1292 + 1293 + error = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE); 1294 + if (error) { 1295 + psmouse_warn(psmouse, "Failed to deactivate mouse on %s: %d\n", 1296 + psmouse->ps2dev.serio->phys, error); 1297 + return error; 1309 1298 } 1310 1299 1311 1300 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
+4 -1
drivers/input/mouse/psmouse.h
··· 131 131 132 132 void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, 133 133 unsigned long delay); 134 - int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command); 135 134 int psmouse_reset(struct psmouse *psmouse); 136 135 void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state); 137 136 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); ··· 138 139 int psmouse_activate(struct psmouse *psmouse); 139 140 int psmouse_deactivate(struct psmouse *psmouse); 140 141 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]); 142 + 143 + void psmouse_report_standard_buttons(struct input_dev *, u8 buttons); 144 + void psmouse_report_standard_motion(struct input_dev *, u8 *packet); 145 + void psmouse_report_standard_packet(struct input_dev *, u8 *packet); 141 146 142 147 struct psmouse_attribute { 143 148 struct device_attribute dattr;
+1 -10
drivers/input/mouse/sentelic.c
··· 710 710 unsigned char *packet = psmouse->packet; 711 711 unsigned char button_status = 0, lscroll = 0, rscroll = 0; 712 712 unsigned short abs_x, abs_y, fgrs = 0; 713 - int rel_x, rel_y; 714 713 715 714 if (psmouse->pktcnt < 4) 716 715 return PSMOUSE_GOOD_DATA; ··· 839 840 /* 840 841 * Standard PS/2 Mouse 841 842 */ 842 - input_report_key(dev, BTN_LEFT, packet[0] & 1); 843 - input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 844 - input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); 845 - 846 - rel_x = packet[1] ? (int)packet[1] - (int)((packet[0] << 4) & 0x100) : 0; 847 - rel_y = packet[2] ? (int)((packet[0] << 3) & 0x100) - (int)packet[2] : 0; 848 - 849 - input_report_rel(dev, REL_X, rel_x); 850 - input_report_rel(dev, REL_Y, rel_y); 843 + psmouse_report_standard_packet(dev, packet); 851 844 break; 852 845 } 853 846
+52 -38
drivers/input/mouse/synaptics.c
··· 84 84 u8 param[1]; 85 85 int error; 86 86 87 - error = psmouse_sliced_command(psmouse, mode); 87 + error = ps2_sliced_command(&psmouse->ps2dev, mode); 88 88 if (error) 89 89 return error; 90 90 ··· 189 189 { 190 190 int error; 191 191 192 - error = psmouse_sliced_command(psmouse, cmd); 192 + error = ps2_sliced_command(&psmouse->ps2dev, cmd); 193 193 if (error) 194 194 return error; 195 195 ··· 546 546 static u8 param = 0xc8; 547 547 int error; 548 548 549 - error = psmouse_sliced_command(psmouse, SYN_QUE_MODEL); 549 + error = ps2_sliced_command(&psmouse->ps2dev, SYN_QUE_MODEL); 550 550 if (error) 551 551 return error; 552 552 ··· 613 613 u8 rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ 614 614 int error; 615 615 616 - error = psmouse_sliced_command(parent, c); 616 + error = ps2_sliced_command(&parent->ps2dev, c); 617 617 if (error) 618 618 return error; 619 619 ··· 1227 1227 input_abs_set_res(dev, y_code, info->y_res); 1228 1228 } 1229 1229 1230 - static void set_input_params(struct psmouse *psmouse, 1231 - struct synaptics_data *priv) 1230 + static int set_input_params(struct psmouse *psmouse, 1231 + struct synaptics_data *priv) 1232 1232 { 1233 1233 struct input_dev *dev = psmouse->dev; 1234 1234 struct synaptics_device_info *info = &priv->info; 1235 1235 int i; 1236 + int error; 1237 + 1238 + /* Reset default psmouse capabilities */ 1239 + __clear_bit(EV_REL, dev->evbit); 1240 + bitmap_zero(dev->relbit, REL_CNT); 1241 + bitmap_zero(dev->keybit, KEY_CNT); 1236 1242 1237 1243 /* Things that apply to both modes */ 1238 1244 __set_bit(INPUT_PROP_POINTER, dev->propbit); 1239 - __set_bit(EV_KEY, dev->evbit); 1240 - __set_bit(BTN_LEFT, dev->keybit); 1241 - __set_bit(BTN_RIGHT, dev->keybit); 1242 1245 1243 - if (SYN_CAP_MIDDLE_BUTTON(info->capabilities)) 1244 - __set_bit(BTN_MIDDLE, dev->keybit); 1246 + input_set_capability(dev, EV_KEY, BTN_LEFT); 1247 + 1248 + /* Clickpads report only left button */ 1249 + if (!SYN_CAP_CLICKPAD(info->ext_cap_0c)) { 1250 + input_set_capability(dev, EV_KEY, BTN_RIGHT); 1251 + if (SYN_CAP_MIDDLE_BUTTON(info->capabilities)) 1252 + input_set_capability(dev, EV_KEY, BTN_MIDDLE); 1253 + } 1245 1254 1246 1255 if (!priv->absolute_mode) { 1247 1256 /* Relative mode */ 1248 - __set_bit(EV_REL, dev->evbit); 1249 - __set_bit(REL_X, dev->relbit); 1250 - __set_bit(REL_Y, dev->relbit); 1251 - return; 1257 + input_set_capability(dev, EV_REL, REL_X); 1258 + input_set_capability(dev, EV_REL, REL_Y); 1259 + return 0; 1252 1260 } 1253 1261 1254 1262 /* Absolute mode */ 1255 - __set_bit(EV_ABS, dev->evbit); 1256 1263 set_abs_position_params(dev, &priv->info, ABS_X, ABS_Y); 1257 1264 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); 1258 1265 ··· 1271 1264 ABS_MT_POSITION_X, ABS_MT_POSITION_Y); 1272 1265 /* Image sensors can report per-contact pressure */ 1273 1266 input_set_abs_params(dev, ABS_MT_PRESSURE, 0, 255, 0, 0); 1274 - input_mt_init_slots(dev, 2, INPUT_MT_POINTER | INPUT_MT_TRACK); 1267 + 1268 + error = input_mt_init_slots(dev, 2, 1269 + INPUT_MT_POINTER | INPUT_MT_TRACK); 1270 + if (error) 1271 + return error; 1275 1272 1276 1273 /* Image sensors can signal 4 and 5 finger clicks */ 1277 - __set_bit(BTN_TOOL_QUADTAP, dev->keybit); 1278 - __set_bit(BTN_TOOL_QUINTTAP, dev->keybit); 1274 + input_set_capability(dev, EV_KEY, BTN_TOOL_QUADTAP); 1275 + input_set_capability(dev, EV_KEY, BTN_TOOL_QUINTTAP); 1279 1276 } else if (SYN_CAP_ADV_GESTURE(info->ext_cap_0c)) { 1280 1277 set_abs_position_params(dev, info, 1281 1278 ABS_MT_POSITION_X, ABS_MT_POSITION_Y); ··· 1287 1276 * Profile sensor in CR-48 tracks contacts reasonably well, 1288 1277 * other non-image sensors with AGM use semi-mt. 1289 1278 */ 1290 - input_mt_init_slots(dev, 2, 1291 - INPUT_MT_POINTER | 1292 - (cr48_profile_sensor ? 1293 - INPUT_MT_TRACK : INPUT_MT_SEMI_MT)); 1279 + error = input_mt_init_slots(dev, 2, 1280 + INPUT_MT_POINTER | 1281 + (cr48_profile_sensor ? 1282 + INPUT_MT_TRACK : 1283 + INPUT_MT_SEMI_MT)); 1284 + if (error) 1285 + return error; 1294 1286 1295 1287 /* 1296 1288 * For semi-mt devices we send ABS_X/Y ourselves instead of ··· 1309 1295 if (SYN_CAP_PALMDETECT(info->capabilities)) 1310 1296 input_set_abs_params(dev, ABS_TOOL_WIDTH, 0, 15, 0, 0); 1311 1297 1312 - __set_bit(BTN_TOUCH, dev->keybit); 1313 - __set_bit(BTN_TOOL_FINGER, dev->keybit); 1298 + input_set_capability(dev, EV_KEY, BTN_TOUCH); 1299 + input_set_capability(dev, EV_KEY, BTN_TOOL_FINGER); 1314 1300 1315 1301 if (synaptics_has_multifinger(priv)) { 1316 - __set_bit(BTN_TOOL_DOUBLETAP, dev->keybit); 1317 - __set_bit(BTN_TOOL_TRIPLETAP, dev->keybit); 1302 + input_set_capability(dev, EV_KEY, BTN_TOOL_DOUBLETAP); 1303 + input_set_capability(dev, EV_KEY, BTN_TOOL_TRIPLETAP); 1318 1304 } 1319 1305 1320 1306 if (SYN_CAP_FOUR_BUTTON(info->capabilities) || 1321 1307 SYN_CAP_MIDDLE_BUTTON(info->capabilities)) { 1322 - __set_bit(BTN_FORWARD, dev->keybit); 1323 - __set_bit(BTN_BACK, dev->keybit); 1308 + input_set_capability(dev, EV_KEY, BTN_FORWARD); 1309 + input_set_capability(dev, EV_KEY, BTN_BACK); 1324 1310 } 1325 1311 1326 1312 if (!SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10)) 1327 1313 for (i = 0; i < SYN_CAP_MULTI_BUTTON_NO(info->ext_cap); i++) 1328 - __set_bit(BTN_0 + i, dev->keybit); 1329 - 1330 - __clear_bit(EV_REL, dev->evbit); 1331 - __clear_bit(REL_X, dev->relbit); 1332 - __clear_bit(REL_Y, dev->relbit); 1314 + input_set_capability(dev, EV_KEY, BTN_0 + i); 1333 1315 1334 1316 if (SYN_CAP_CLICKPAD(info->ext_cap_0c)) { 1335 1317 __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); 1336 1318 if (psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) && 1337 1319 !SYN_CAP_EXT_BUTTONS_STICK(info->ext_cap_10)) 1338 1320 __set_bit(INPUT_PROP_TOPBUTTONPAD, dev->propbit); 1339 - /* Clickpads report only left button */ 1340 - __clear_bit(BTN_RIGHT, dev->keybit); 1341 - __clear_bit(BTN_MIDDLE, dev->keybit); 1342 1321 } 1322 + 1323 + return 0; 1343 1324 } 1344 1325 1345 1326 static ssize_t synaptics_show_disable_gesture(struct psmouse *psmouse, ··· 1572 1563 info->capabilities, info->ext_cap, info->ext_cap_0c, 1573 1564 info->ext_cap_10, info->board_id, info->firmware_id); 1574 1565 1575 - set_input_params(psmouse, priv); 1566 + err = set_input_params(psmouse, priv); 1567 + if (err) { 1568 + psmouse_err(psmouse, 1569 + "failed to set up capabilities: %d\n", err); 1570 + goto init_fail; 1571 + } 1576 1572 1577 1573 /* 1578 1574 * Encode touchpad model so that it can be used to set
+19 -12
drivers/input/mouse/synaptics_usb.c
··· 82 82 struct urb *urb; 83 83 unsigned char *data; 84 84 85 + /* serialize access to open/suspend */ 86 + struct mutex pm_mutex; 87 + bool is_open; 88 + 85 89 /* input device related data structures */ 86 90 struct input_dev *input; 87 91 char name[128]; ··· 256 252 return retval; 257 253 } 258 254 255 + mutex_lock(&synusb->pm_mutex); 259 256 retval = usb_submit_urb(synusb->urb, GFP_KERNEL); 260 257 if (retval) { 261 258 dev_err(&synusb->intf->dev, ··· 267 262 } 268 263 269 264 synusb->intf->needs_remote_wakeup = 1; 265 + synusb->is_open = true; 270 266 271 267 out: 268 + mutex_unlock(&synusb->pm_mutex); 272 269 usb_autopm_put_interface(synusb->intf); 273 270 return retval; 274 271 } ··· 282 275 283 276 autopm_error = usb_autopm_get_interface(synusb->intf); 284 277 278 + mutex_lock(&synusb->pm_mutex); 285 279 usb_kill_urb(synusb->urb); 286 280 synusb->intf->needs_remote_wakeup = 0; 281 + synusb->is_open = false; 282 + mutex_unlock(&synusb->pm_mutex); 287 283 288 284 if (!autopm_error) 289 285 usb_autopm_put_interface(synusb->intf); ··· 325 315 synusb->udev = udev; 326 316 synusb->intf = intf; 327 317 synusb->input = input_dev; 318 + mutex_init(&synusb->pm_mutex); 328 319 329 320 synusb->flags = id->driver_info; 330 321 if (synusb->flags & SYNUSB_COMBO) { ··· 477 466 static int synusb_suspend(struct usb_interface *intf, pm_message_t message) 478 467 { 479 468 struct synusb *synusb = usb_get_intfdata(intf); 480 - struct input_dev *input_dev = synusb->input; 481 469 482 - mutex_lock(&input_dev->mutex); 470 + mutex_lock(&synusb->pm_mutex); 483 471 usb_kill_urb(synusb->urb); 484 - mutex_unlock(&input_dev->mutex); 472 + mutex_unlock(&synusb->pm_mutex); 485 473 486 474 return 0; 487 475 } ··· 488 478 static int synusb_resume(struct usb_interface *intf) 489 479 { 490 480 struct synusb *synusb = usb_get_intfdata(intf); 491 - struct input_dev *input_dev = synusb->input; 492 481 int retval = 0; 493 482 494 - mutex_lock(&input_dev->mutex); 483 + mutex_lock(&synusb->pm_mutex); 495 484 496 - if ((input_dev->users || (synusb->flags & SYNUSB_IO_ALWAYS)) && 485 + if ((synusb->is_open || (synusb->flags & SYNUSB_IO_ALWAYS)) && 497 486 usb_submit_urb(synusb->urb, GFP_NOIO) < 0) { 498 487 retval = -EIO; 499 488 } 500 489 501 - mutex_unlock(&input_dev->mutex); 490 + mutex_unlock(&synusb->pm_mutex); 502 491 503 492 return retval; 504 493 } ··· 505 496 static int synusb_pre_reset(struct usb_interface *intf) 506 497 { 507 498 struct synusb *synusb = usb_get_intfdata(intf); 508 - struct input_dev *input_dev = synusb->input; 509 499 510 - mutex_lock(&input_dev->mutex); 500 + mutex_lock(&synusb->pm_mutex); 511 501 usb_kill_urb(synusb->urb); 512 502 513 503 return 0; ··· 515 507 static int synusb_post_reset(struct usb_interface *intf) 516 508 { 517 509 struct synusb *synusb = usb_get_intfdata(intf); 518 - struct input_dev *input_dev = synusb->input; 519 510 int retval = 0; 520 511 521 - if ((input_dev->users || (synusb->flags & SYNUSB_IO_ALWAYS)) && 512 + if ((synusb->is_open || (synusb->flags & SYNUSB_IO_ALWAYS)) && 522 513 usb_submit_urb(synusb->urb, GFP_NOIO) < 0) { 523 514 retval = -EIO; 524 515 } 525 516 526 - mutex_unlock(&input_dev->mutex); 517 + mutex_unlock(&synusb->pm_mutex); 527 518 528 519 return retval; 529 520 }
+24 -36
drivers/input/mouse/trackpoint.c
··· 33 33 */ 34 34 static int trackpoint_power_on_reset(struct ps2dev *ps2dev) 35 35 { 36 - u8 results[2]; 37 - int tries = 0; 36 + u8 param[2] = { TP_POR }; 37 + int err; 38 38 39 - /* Issue POR command, and repeat up to once if 0xFC00 received */ 40 - do { 41 - if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 42 - ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 2, TP_POR))) 43 - return -1; 44 - } while (results[0] == 0xFC && results[1] == 0x00 && ++tries < 2); 39 + err = ps2_command(ps2dev, param, MAKE_PS2_CMD(1, 2, TP_COMMAND)); 40 + if (err) 41 + return err; 45 42 46 43 /* Check for success response -- 0xAA00 */ 47 - if (results[0] != 0xAA || results[1] != 0x00) 44 + if (param[0] != 0xAA || param[1] != 0x00) 48 45 return -ENODEV; 49 46 50 47 return 0; ··· 52 55 */ 53 56 static int trackpoint_read(struct ps2dev *ps2dev, u8 loc, u8 *results) 54 57 { 55 - if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 56 - ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) { 57 - return -1; 58 - } 58 + results[0] = loc; 59 59 60 - return 0; 60 + return ps2_command(ps2dev, results, MAKE_PS2_CMD(1, 1, TP_COMMAND)); 61 61 } 62 62 63 63 static int trackpoint_write(struct ps2dev *ps2dev, u8 loc, u8 val) 64 64 { 65 - if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 66 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) || 67 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 68 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) { 69 - return -1; 70 - } 65 + u8 param[3] = { TP_WRITE_MEM, loc, val }; 71 66 72 - return 0; 67 + return ps2_command(ps2dev, param, MAKE_PS2_CMD(3, 0, TP_COMMAND)); 73 68 } 74 69 75 70 static int trackpoint_toggle_bit(struct ps2dev *ps2dev, u8 loc, u8 mask) 76 71 { 72 + u8 param[3] = { TP_TOGGLE, loc, mask }; 73 + 77 74 /* Bad things will happen if the loc param isn't in this range */ 78 75 if (loc < 0x20 || loc >= 0x2F) 79 - return -1; 76 + return -EINVAL; 80 77 81 - if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 82 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) || 83 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 84 - ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) { 85 - return -1; 86 - } 87 - 88 - return 0; 78 + return ps2_command(ps2dev, param, MAKE_PS2_CMD(3, 0, TP_COMMAND)); 89 79 } 90 80 91 81 static int trackpoint_update_bit(struct ps2dev *ps2dev, 92 82 u8 loc, u8 mask, u8 value) 93 83 { 94 - int retval = 0; 84 + int retval; 95 85 u8 data; 96 86 97 - trackpoint_read(ps2dev, loc, &data); 87 + retval = trackpoint_read(ps2dev, loc, &data); 88 + if (retval) 89 + return retval; 90 + 98 91 if (((data & mask) == mask) != !!value) 99 92 retval = trackpoint_toggle_bit(ps2dev, loc, mask); 100 93 ··· 129 142 return err; 130 143 131 144 *field = value; 132 - trackpoint_write(&psmouse->ps2dev, attr->command, value); 145 + err = trackpoint_write(&psmouse->ps2dev, attr->command, value); 133 146 134 - return count; 147 + return err ?: count; 135 148 } 136 149 137 150 #define TRACKPOINT_INT_ATTR(_name, _command, _default) \ ··· 162 175 163 176 if (*field != value) { 164 177 *field = value; 165 - trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask); 178 + err = trackpoint_toggle_bit(&psmouse->ps2dev, 179 + attr->command, attr->mask); 166 180 } 167 181 168 - return count; 182 + return err ?: count; 169 183 } 170 184 171 185
+24
drivers/input/serio/i8042-x86ia64io.h
··· 530 530 { } 531 531 }; 532 532 533 + static const struct dmi_system_id i8042_dmi_forcemux_table[] __initconst = { 534 + { 535 + /* 536 + * Sony Vaio VGN-CS series require MUX or the touch sensor 537 + * buttons will disturb touchpad operation 538 + */ 539 + .matches = { 540 + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 541 + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-CS"), 542 + }, 543 + }, 544 + { } 545 + }; 546 + 533 547 /* 534 548 * On some Asus laptops, just running self tests cause problems. 535 549 */ ··· 632 618 .matches = { 633 619 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 634 620 DMI_MATCH(DMI_PRODUCT_NAME, "20046"), 621 + }, 622 + }, 623 + { 624 + /* Lenovo ThinkPad L460 */ 625 + .matches = { 626 + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 627 + DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad L460"), 635 628 }, 636 629 }, 637 630 { ··· 1183 1162 1184 1163 if (dmi_check_system(i8042_dmi_nomux_table)) 1185 1164 i8042_nomux = true; 1165 + 1166 + if (dmi_check_system(i8042_dmi_forcemux_table)) 1167 + i8042_nomux = false; 1186 1168 1187 1169 if (dmi_check_system(i8042_dmi_notimeout_table)) 1188 1170 i8042_notimeout = true;
+220 -104
drivers/input/serio/libps2.c
··· 26 26 MODULE_DESCRIPTION("PS/2 driver library"); 27 27 MODULE_LICENSE("GPL"); 28 28 29 + static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte, 30 + unsigned int timeout, unsigned int max_attempts) 31 + __releases(&ps2dev->serio->lock) __acquires(&ps2dev->serio->lock) 32 + { 33 + int attempt = 0; 34 + int error; 35 + 36 + lockdep_assert_held(&ps2dev->serio->lock); 37 + 38 + do { 39 + ps2dev->nak = 1; 40 + ps2dev->flags |= PS2_FLAG_ACK; 41 + 42 + serio_continue_rx(ps2dev->serio); 43 + 44 + error = serio_write(ps2dev->serio, byte); 45 + if (error) 46 + dev_dbg(&ps2dev->serio->dev, 47 + "failed to write %#02x: %d\n", byte, error); 48 + else 49 + wait_event_timeout(ps2dev->wait, 50 + !(ps2dev->flags & PS2_FLAG_ACK), 51 + msecs_to_jiffies(timeout)); 52 + 53 + serio_pause_rx(ps2dev->serio); 54 + } while (ps2dev->nak == PS2_RET_NAK && ++attempt < max_attempts); 55 + 56 + ps2dev->flags &= ~PS2_FLAG_ACK; 57 + 58 + if (!error) { 59 + switch (ps2dev->nak) { 60 + case 0: 61 + break; 62 + case PS2_RET_NAK: 63 + error = -EAGAIN; 64 + break; 65 + case PS2_RET_ERR: 66 + error = -EPROTO; 67 + break; 68 + default: 69 + error = -EIO; 70 + break; 71 + } 72 + } 73 + 74 + if (error || attempt > 1) 75 + dev_dbg(&ps2dev->serio->dev, 76 + "%02x - %d (%x), attempt %d\n", 77 + byte, error, ps2dev->nak, attempt); 78 + 79 + return error; 80 + } 81 + 29 82 /* 30 83 * ps2_sendbyte() sends a byte to the device and waits for acknowledge. 31 - * It doesn't handle retransmission, though it could - because if there 32 - * is a need for retransmissions device has to be replaced anyway. 84 + * It doesn't handle retransmission, the caller is expected to handle 85 + * it when needed. 33 86 * 34 87 * ps2_sendbyte() can only be called from a process context. 35 88 */ 36 89 37 - int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout) 90 + int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) 38 91 { 39 - serio_pause_rx(ps2dev->serio); 40 - ps2dev->nak = 1; 41 - ps2dev->flags |= PS2_FLAG_ACK; 42 - serio_continue_rx(ps2dev->serio); 43 - 44 - if (serio_write(ps2dev->serio, byte) == 0) 45 - wait_event_timeout(ps2dev->wait, 46 - !(ps2dev->flags & PS2_FLAG_ACK), 47 - msecs_to_jiffies(timeout)); 92 + int retval; 48 93 49 94 serio_pause_rx(ps2dev->serio); 50 - ps2dev->flags &= ~PS2_FLAG_ACK; 95 + 96 + retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); 97 + dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); 98 + 51 99 serio_continue_rx(ps2dev->serio); 52 100 53 - return -ps2dev->nak; 101 + return retval; 54 102 } 55 103 EXPORT_SYMBOL(ps2_sendbyte); 56 104 ··· 123 75 * and discards them. 124 76 */ 125 77 126 - void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout) 78 + void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) 127 79 { 128 80 if (maxbytes > sizeof(ps2dev->cmdbuf)) { 129 81 WARN_ON(1); ··· 150 102 * known keyboard IDs. 151 103 */ 152 104 153 - int ps2_is_keyboard_id(char id_byte) 105 + bool ps2_is_keyboard_id(u8 id_byte) 154 106 { 155 - static const char keyboard_ids[] = { 107 + static const u8 keyboard_ids[] = { 156 108 0xab, /* Regular keyboards */ 157 109 0xac, /* NCD Sun keyboard */ 158 110 0x2b, /* Trust keyboard, translated */ ··· 171 123 * completion. 172 124 */ 173 125 174 - static int ps2_adjust_timeout(struct ps2dev *ps2dev, int command, int timeout) 126 + static int ps2_adjust_timeout(struct ps2dev *ps2dev, 127 + unsigned int command, unsigned int timeout) 175 128 { 176 129 switch (command) { 177 - case PS2_CMD_RESET_BAT: 178 - /* 179 - * Device has sent the first response byte after 180 - * reset command, reset is thus done, so we can 181 - * shorten the timeout. 182 - * The next byte will come soon (keyboard) or not 183 - * at all (mouse). 184 - */ 185 - if (timeout > msecs_to_jiffies(100)) 186 - timeout = msecs_to_jiffies(100); 187 - break; 130 + case PS2_CMD_RESET_BAT: 131 + /* 132 + * Device has sent the first response byte after 133 + * reset command, reset is thus done, so we can 134 + * shorten the timeout. 135 + * The next byte will come soon (keyboard) or not 136 + * at all (mouse). 137 + */ 138 + if (timeout > msecs_to_jiffies(100)) 139 + timeout = msecs_to_jiffies(100); 140 + break; 188 141 189 - case PS2_CMD_GETID: 190 - /* 191 - * Microsoft Natural Elite keyboard responds to 192 - * the GET ID command as it were a mouse, with 193 - * a single byte. Fail the command so atkbd will 194 - * use alternative probe to detect it. 195 - */ 196 - if (ps2dev->cmdbuf[1] == 0xaa) { 197 - serio_pause_rx(ps2dev->serio); 198 - ps2dev->flags = 0; 199 - serio_continue_rx(ps2dev->serio); 200 - timeout = 0; 201 - } 142 + case PS2_CMD_GETID: 143 + /* 144 + * Microsoft Natural Elite keyboard responds to 145 + * the GET ID command as it were a mouse, with 146 + * a single byte. Fail the command so atkbd will 147 + * use alternative probe to detect it. 148 + */ 149 + if (ps2dev->cmdbuf[1] == 0xaa) { 150 + serio_pause_rx(ps2dev->serio); 151 + ps2dev->flags = 0; 152 + serio_continue_rx(ps2dev->serio); 153 + timeout = 0; 154 + } 202 155 203 - /* 204 - * If device behind the port is not a keyboard there 205 - * won't be 2nd byte of ID response. 206 - */ 207 - if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { 208 - serio_pause_rx(ps2dev->serio); 209 - ps2dev->flags = ps2dev->cmdcnt = 0; 210 - serio_continue_rx(ps2dev->serio); 211 - timeout = 0; 212 - } 213 - break; 156 + /* 157 + * If device behind the port is not a keyboard there 158 + * won't be 2nd byte of ID response. 159 + */ 160 + if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { 161 + serio_pause_rx(ps2dev->serio); 162 + ps2dev->flags = ps2dev->cmdcnt = 0; 163 + serio_continue_rx(ps2dev->serio); 164 + timeout = 0; 165 + } 166 + break; 214 167 215 - default: 216 - break; 168 + default: 169 + break; 217 170 } 218 171 219 172 return timeout; ··· 227 178 * ps2_command() can only be called from a process context 228 179 */ 229 180 230 - int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) 181 + int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) 231 182 { 232 - int timeout; 233 - int send = (command >> 12) & 0xf; 234 - int receive = (command >> 8) & 0xf; 235 - int rc = -1; 183 + unsigned int timeout; 184 + unsigned int send = (command >> 12) & 0xf; 185 + unsigned int receive = (command >> 8) & 0xf; 186 + int rc; 236 187 int i; 188 + u8 send_param[16]; 237 189 238 190 if (receive > sizeof(ps2dev->cmdbuf)) { 239 191 WARN_ON(1); 240 - return -1; 192 + return -EINVAL; 241 193 } 242 194 243 195 if (send && !param) { 244 196 WARN_ON(1); 245 - return -1; 197 + return -EINVAL; 246 198 } 247 199 200 + memcpy(send_param, param, send); 201 + 248 202 serio_pause_rx(ps2dev->serio); 203 + 249 204 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; 250 205 ps2dev->cmdcnt = receive; 251 206 if (receive && param) 252 207 for (i = 0; i < receive; i++) 253 208 ps2dev->cmdbuf[(receive - 1) - i] = param[i]; 254 - serio_continue_rx(ps2dev->serio); 209 + 210 + /* Signal that we are sending the command byte */ 211 + ps2dev->flags |= PS2_FLAG_ACK_CMD; 255 212 256 213 /* 257 214 * Some devices (Synaptics) peform the reset before 258 215 * ACKing the reset command, and so it can take a long 259 216 * time before the ACK arrives. 260 217 */ 261 - if (ps2_sendbyte(ps2dev, command & 0xff, 262 - command == PS2_CMD_RESET_BAT ? 1000 : 200)) { 263 - serio_pause_rx(ps2dev->serio); 218 + timeout = command == PS2_CMD_RESET_BAT ? 1000 : 200; 219 + 220 + rc = ps2_do_sendbyte(ps2dev, command & 0xff, timeout, 2); 221 + if (rc) 264 222 goto out_reset_flags; 265 - } 223 + 224 + /* Now we are sending command parameters, if any */ 225 + ps2dev->flags &= ~PS2_FLAG_ACK_CMD; 266 226 267 227 for (i = 0; i < send; i++) { 268 - if (ps2_sendbyte(ps2dev, param[i], 200)) { 269 - serio_pause_rx(ps2dev->serio); 228 + rc = ps2_do_sendbyte(ps2dev, param[i], 200, 2); 229 + if (rc) 270 230 goto out_reset_flags; 271 - } 272 231 } 232 + 233 + serio_continue_rx(ps2dev->serio); 273 234 274 235 /* 275 236 * The reset command takes a long time to execute. ··· 302 243 for (i = 0; i < receive; i++) 303 244 param[i] = ps2dev->cmdbuf[(receive - 1) - i]; 304 245 305 - if (ps2dev->cmdcnt && (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) 246 + if (ps2dev->cmdcnt && 247 + (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) { 248 + rc = -EPROTO; 306 249 goto out_reset_flags; 250 + } 307 251 308 252 rc = 0; 309 253 ··· 314 252 ps2dev->flags = 0; 315 253 serio_continue_rx(ps2dev->serio); 316 254 317 - return rc; 255 + dev_dbg(&ps2dev->serio->dev, 256 + "%02x [%*ph] - %x/%08lx [%*ph]\n", 257 + command & 0xff, send, send_param, 258 + ps2dev->nak, ps2dev->flags, 259 + receive, param ?: send_param); 260 + 261 + /* 262 + * ps_command() handles resends itself, so do not leak -EAGAIN 263 + * to the callers. 264 + */ 265 + return rc != -EAGAIN ? rc : -EPROTO; 318 266 } 319 267 EXPORT_SYMBOL(__ps2_command); 320 268 321 - int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) 269 + int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) 322 270 { 323 271 int rc; 324 272 ··· 339 267 return rc; 340 268 } 341 269 EXPORT_SYMBOL(ps2_command); 270 + 271 + /* 272 + * ps2_sliced_command() sends an extended PS/2 command to the mouse 273 + * using sliced syntax, understood by advanced devices, such as Logitech 274 + * or Synaptics touchpads. The command is encoded as: 275 + * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu 276 + * is the command. 277 + */ 278 + 279 + int ps2_sliced_command(struct ps2dev *ps2dev, u8 command) 280 + { 281 + int i; 282 + int retval; 283 + 284 + ps2_begin_command(ps2dev); 285 + 286 + retval = __ps2_command(ps2dev, NULL, PS2_CMD_SETSCALE11); 287 + if (retval) 288 + goto out; 289 + 290 + for (i = 6; i >= 0; i -= 2) { 291 + u8 d = (command >> i) & 3; 292 + retval = __ps2_command(ps2dev, &d, PS2_CMD_SETRES); 293 + if (retval) 294 + break; 295 + } 296 + 297 + out: 298 + dev_dbg(&ps2dev->serio->dev, "%02x - %d\n", command, retval); 299 + ps2_end_command(ps2dev); 300 + return retval; 301 + } 302 + EXPORT_SYMBOL(ps2_sliced_command); 342 303 343 304 /* 344 305 * ps2_init() initializes ps2dev structure ··· 391 286 * to properly process ACK/NAK of a command from a PS/2 device. 392 287 */ 393 288 394 - int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data) 289 + bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data) 395 290 { 396 291 switch (data) { 397 - case PS2_RET_ACK: 292 + case PS2_RET_ACK: 293 + ps2dev->nak = 0; 294 + break; 295 + 296 + case PS2_RET_NAK: 297 + ps2dev->flags |= PS2_FLAG_NAK; 298 + ps2dev->nak = PS2_RET_NAK; 299 + break; 300 + 301 + case PS2_RET_ERR: 302 + if (ps2dev->flags & PS2_FLAG_NAK) { 303 + ps2dev->flags &= ~PS2_FLAG_NAK; 304 + ps2dev->nak = PS2_RET_ERR; 305 + break; 306 + } 307 + 308 + /* 309 + * Workaround for mice which don't ACK the Get ID command. 310 + * These are valid mouse IDs that we recognize. 311 + */ 312 + case 0x00: 313 + case 0x03: 314 + case 0x04: 315 + if (ps2dev->flags & PS2_FLAG_WAITID) { 398 316 ps2dev->nak = 0; 399 317 break; 400 - 401 - case PS2_RET_NAK: 402 - ps2dev->flags |= PS2_FLAG_NAK; 403 - ps2dev->nak = PS2_RET_NAK; 404 - break; 405 - 406 - case PS2_RET_ERR: 407 - if (ps2dev->flags & PS2_FLAG_NAK) { 408 - ps2dev->flags &= ~PS2_FLAG_NAK; 409 - ps2dev->nak = PS2_RET_ERR; 410 - break; 411 - } 412 - 318 + } 319 + /* Fall through */ 320 + default: 413 321 /* 414 - * Workaround for mice which don't ACK the Get ID command. 415 - * These are valid mouse IDs that we recognize. 322 + * Do not signal errors if we get unexpected reply while 323 + * waiting for an ACK to the initial (first) command byte: 324 + * the device might not be quiesced yet and continue 325 + * delivering data. 326 + * Note that we reset PS2_FLAG_WAITID flag, so the workaround 327 + * for mice not acknowledging the Get ID command only triggers 328 + * on the 1st byte; if device spews data we really want to see 329 + * a real ACK from it. 416 330 */ 417 - case 0x00: 418 - case 0x03: 419 - case 0x04: 420 - if (ps2dev->flags & PS2_FLAG_WAITID) { 421 - ps2dev->nak = 0; 422 - break; 423 - } 424 - /* Fall through */ 425 - default: 426 - return 0; 331 + dev_dbg(&ps2dev->serio->dev, "unexpected %#02x\n", data); 332 + ps2dev->flags &= ~PS2_FLAG_WAITID; 333 + return ps2dev->flags & PS2_FLAG_ACK_CMD; 427 334 } 428 - 429 335 430 336 if (!ps2dev->nak) { 431 337 ps2dev->flags &= ~PS2_FLAG_NAK; ··· 450 334 if (data != PS2_RET_ACK) 451 335 ps2_handle_response(ps2dev, data); 452 336 453 - return 1; 337 + return true; 454 338 } 455 339 EXPORT_SYMBOL(ps2_handle_ack); 456 340 ··· 460 344 * waiting for completion of the command. 461 345 */ 462 346 463 - int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data) 347 + bool ps2_handle_response(struct ps2dev *ps2dev, u8 data) 464 348 { 465 349 if (ps2dev->cmdcnt) 466 350 ps2dev->cmdbuf[--ps2dev->cmdcnt] = data; ··· 476 360 wake_up(&ps2dev->wait); 477 361 } 478 362 479 - return 1; 363 + return true; 480 364 } 481 365 EXPORT_SYMBOL(ps2_handle_response); 482 366
+24 -8
drivers/input/tablet/pegasus_notetaker.c
··· 41 41 #include <linux/usb/input.h> 42 42 #include <linux/slab.h> 43 43 #include <linux/workqueue.h> 44 + #include <linux/mutex.h> 44 45 45 46 /* USB HID defines */ 46 47 #define USB_REQ_GET_REPORT 0x01 ··· 77 76 struct usb_device *usbdev; 78 77 struct usb_interface *intf; 79 78 struct urb *irq; 79 + 80 + /* serialize access to open/suspend */ 81 + struct mutex pm_mutex; 82 + bool is_open; 83 + 80 84 char name[128]; 81 85 char phys[64]; 82 86 struct work_struct init; ··· 222 216 if (error) 223 217 return error; 224 218 219 + mutex_lock(&pegasus->pm_mutex); 225 220 pegasus->irq->dev = pegasus->usbdev; 226 221 if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) { 227 222 error = -EIO; ··· 233 226 if (error) 234 227 goto err_kill_urb; 235 228 229 + pegasus->is_open = true; 230 + mutex_unlock(&pegasus->pm_mutex); 236 231 return 0; 237 232 238 233 err_kill_urb: 239 234 usb_kill_urb(pegasus->irq); 240 235 cancel_work_sync(&pegasus->init); 241 236 err_autopm_put: 237 + mutex_unlock(&pegasus->pm_mutex); 242 238 usb_autopm_put_interface(pegasus->intf); 243 239 return error; 244 240 } ··· 250 240 { 251 241 struct pegasus *pegasus = input_get_drvdata(dev); 252 242 243 + mutex_lock(&pegasus->pm_mutex); 253 244 usb_kill_urb(pegasus->irq); 254 245 cancel_work_sync(&pegasus->init); 246 + pegasus->is_open = false; 247 + mutex_unlock(&pegasus->pm_mutex); 248 + 255 249 usb_autopm_put_interface(pegasus->intf); 256 250 } 257 251 ··· 287 273 error = -ENOMEM; 288 274 goto err_free_mem; 289 275 } 276 + 277 + mutex_init(&pegasus->pm_mutex); 290 278 291 279 pegasus->usbdev = dev; 292 280 pegasus->dev = input_dev; ··· 404 388 { 405 389 struct pegasus *pegasus = usb_get_intfdata(intf); 406 390 407 - mutex_lock(&pegasus->dev->mutex); 391 + mutex_lock(&pegasus->pm_mutex); 408 392 usb_kill_urb(pegasus->irq); 409 393 cancel_work_sync(&pegasus->init); 410 - mutex_unlock(&pegasus->dev->mutex); 394 + mutex_unlock(&pegasus->pm_mutex); 411 395 412 396 return 0; 413 397 } ··· 417 401 struct pegasus *pegasus = usb_get_intfdata(intf); 418 402 int retval = 0; 419 403 420 - mutex_lock(&pegasus->dev->mutex); 421 - if (pegasus->dev->users && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 404 + mutex_lock(&pegasus->pm_mutex); 405 + if (pegasus->is_open && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 422 406 retval = -EIO; 423 - mutex_unlock(&pegasus->dev->mutex); 407 + mutex_unlock(&pegasus->pm_mutex); 424 408 425 409 return retval; 426 410 } ··· 430 414 struct pegasus *pegasus = usb_get_intfdata(intf); 431 415 int retval = 0; 432 416 433 - mutex_lock(&pegasus->dev->mutex); 434 - if (pegasus->dev->users) { 417 + mutex_lock(&pegasus->pm_mutex); 418 + if (pegasus->is_open) { 435 419 retval = pegasus_set_mode(pegasus, PEN_MODE_XY, 436 420 NOTETAKER_LED_MOUSE); 437 421 if (!retval && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) 438 422 retval = -EIO; 439 423 } 440 - mutex_unlock(&pegasus->dev->mutex); 424 + mutex_unlock(&pegasus->pm_mutex); 441 425 442 426 return retval; 443 427 }
+1 -1
drivers/input/touchscreen/s6sy761.c
··· 2 2 // Samsung S6SY761 Touchscreen device driver 3 3 // 4 4 // Copyright (c) 2017 Samsung Electronics Co., Ltd. 5 - // Copyright (c) 2017 Andi Shyti <andi.shyti@samsung.com> 5 + // Copyright (c) 2017 Andi Shyti <andi@etezian.org> 6 6 7 7 #include <asm/unaligned.h> 8 8 #include <linux/delay.h>
+1
drivers/input/touchscreen/silead.c
··· 602 602 { "GSL3675", 0 }, 603 603 { "GSL3692", 0 }, 604 604 { "MSSL1680", 0 }, 605 + { "MSSL0001", 0 }, 605 606 { } 606 607 }; 607 608 MODULE_DEVICE_TABLE(acpi, silead_ts_acpi_match);
+3 -1
drivers/input/touchscreen/stmfts.c
··· 2 2 // STMicroelectronics FTS Touchscreen device driver 3 3 // 4 4 // Copyright (c) 2017 Samsung Electronics Co., Ltd. 5 - // Copyright (c) 2017 Andi Shyti <andi.shyti@samsung.com> 5 + // Copyright (c) 2017 Andi Shyti <andi@etezian.org> 6 6 7 7 #include <linux/delay.h> 8 8 #include <linux/i2c.h> ··· 730 730 return err; 731 731 732 732 pm_runtime_enable(&client->dev); 733 + device_enable_async_suspend(&client->dev); 733 734 734 735 return 0; 735 736 } ··· 806 805 .name = STMFTS_DEV_NAME, 807 806 .of_match_table = of_match_ptr(stmfts_of_match), 808 807 .pm = &stmfts_pm_ops, 808 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 809 809 }, 810 810 .probe = stmfts_probe, 811 811 .remove = stmfts_remove,
+16 -8
drivers/input/touchscreen/usbtouchscreen.c
··· 54 54 #include <linux/usb.h> 55 55 #include <linux/usb/input.h> 56 56 #include <linux/hid.h> 57 + #include <linux/mutex.h> 57 58 58 59 static bool swap_xy; 59 60 module_param(swap_xy, bool, 0644); ··· 108 107 struct usb_interface *interface; 109 108 struct input_dev *input; 110 109 struct usbtouch_device_info *type; 110 + struct mutex pm_mutex; /* serialize access to open/suspend */ 111 + bool is_open; 111 112 char name[128]; 112 113 char phys[64]; 113 114 void *priv; ··· 1453 1450 if (r < 0) 1454 1451 goto out; 1455 1452 1453 + mutex_lock(&usbtouch->pm_mutex); 1456 1454 if (!usbtouch->type->irq_always) { 1457 1455 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) { 1458 1456 r = -EIO; ··· 1462 1458 } 1463 1459 1464 1460 usbtouch->interface->needs_remote_wakeup = 1; 1461 + usbtouch->is_open = true; 1465 1462 out_put: 1463 + mutex_unlock(&usbtouch->pm_mutex); 1466 1464 usb_autopm_put_interface(usbtouch->interface); 1467 1465 out: 1468 1466 return r; ··· 1475 1469 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1476 1470 int r; 1477 1471 1472 + mutex_lock(&usbtouch->pm_mutex); 1478 1473 if (!usbtouch->type->irq_always) 1479 1474 usb_kill_urb(usbtouch->irq); 1475 + usbtouch->is_open = false; 1476 + mutex_unlock(&usbtouch->pm_mutex); 1477 + 1480 1478 r = usb_autopm_get_interface(usbtouch->interface); 1481 1479 usbtouch->interface->needs_remote_wakeup = 0; 1482 1480 if (!r) ··· 1500 1490 static int usbtouch_resume(struct usb_interface *intf) 1501 1491 { 1502 1492 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 1503 - struct input_dev *input = usbtouch->input; 1504 1493 int result = 0; 1505 1494 1506 - mutex_lock(&input->mutex); 1507 - if (input->users || usbtouch->type->irq_always) 1495 + mutex_lock(&usbtouch->pm_mutex); 1496 + if (usbtouch->is_open || usbtouch->type->irq_always) 1508 1497 result = usb_submit_urb(usbtouch->irq, GFP_NOIO); 1509 - mutex_unlock(&input->mutex); 1498 + mutex_unlock(&usbtouch->pm_mutex); 1510 1499 1511 1500 return result; 1512 1501 } ··· 1513 1504 static int usbtouch_reset_resume(struct usb_interface *intf) 1514 1505 { 1515 1506 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 1516 - struct input_dev *input = usbtouch->input; 1517 1507 int err = 0; 1518 1508 1519 1509 /* reinit the device */ ··· 1527 1519 } 1528 1520 1529 1521 /* restart IO if needed */ 1530 - mutex_lock(&input->mutex); 1531 - if (input->users) 1522 + mutex_lock(&usbtouch->pm_mutex); 1523 + if (usbtouch->is_open) 1532 1524 err = usb_submit_urb(usbtouch->irq, GFP_NOIO); 1533 - mutex_unlock(&input->mutex); 1525 + mutex_unlock(&usbtouch->pm_mutex); 1534 1526 1535 1527 return err; 1536 1528 }
+13
include/dt-bindings/input/gpio-keys.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * This header provides constants for gpio keys bindings. 4 + */ 5 + 6 + #ifndef _DT_BINDINGS_GPIO_KEYS_H 7 + #define _DT_BINDINGS_GPIO_KEYS_H 8 + 9 + #define EV_ACT_ANY 0x00 /* asserted or deasserted */ 10 + #define EV_ACT_ASSERTED 0x01 /* asserted */ 11 + #define EV_ACT_DEASSERTED 0x02 /* deasserted */ 12 + 13 + #endif /* _DT_BINDINGS_GPIO_KEYS_H */
+2
include/linux/gpio_keys.h
··· 13 13 * @desc: label that will be attached to button's gpio 14 14 * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS) 15 15 * @wakeup: configure the button as a wake-up source 16 + * @wakeup_event_action: event action to trigger wakeup 16 17 * @debounce_interval: debounce ticks interval in msecs 17 18 * @can_disable: %true indicates that userspace is allowed to 18 19 * disable button via sysfs ··· 27 26 const char *desc; 28 27 unsigned int type; 29 28 int wakeup; 29 + int wakeup_event_action; 30 30 int debounce_interval; 31 31 bool can_disable; 32 32 int value;
+23 -15
include/linux/libps2.h
··· 10 10 * the Free Software Foundation. 11 11 */ 12 12 13 + #include <linux/bitops.h> 14 + #include <linux/mutex.h> 15 + #include <linux/types.h> 16 + #include <linux/wait.h> 13 17 18 + #define PS2_CMD_SETSCALE11 0x00e6 19 + #define PS2_CMD_SETRES 0x10e8 14 20 #define PS2_CMD_GETID 0x02f2 15 21 #define PS2_CMD_RESET_BAT 0x02ff 16 22 ··· 26 20 #define PS2_RET_NAK 0xfe 27 21 #define PS2_RET_ERR 0xfc 28 22 29 - #define PS2_FLAG_ACK 1 /* Waiting for ACK/NAK */ 30 - #define PS2_FLAG_CMD 2 /* Waiting for command to finish */ 31 - #define PS2_FLAG_CMD1 4 /* Waiting for the first byte of command response */ 32 - #define PS2_FLAG_WAITID 8 /* Command execiting is GET ID */ 33 - #define PS2_FLAG_NAK 16 /* Last transmission was NAKed */ 23 + #define PS2_FLAG_ACK BIT(0) /* Waiting for ACK/NAK */ 24 + #define PS2_FLAG_CMD BIT(1) /* Waiting for a command to finish */ 25 + #define PS2_FLAG_CMD1 BIT(2) /* Waiting for the first byte of command response */ 26 + #define PS2_FLAG_WAITID BIT(3) /* Command executing is GET ID */ 27 + #define PS2_FLAG_NAK BIT(4) /* Last transmission was NAKed */ 28 + #define PS2_FLAG_ACK_CMD BIT(5) /* Waiting to ACK the command (first) byte */ 34 29 35 30 struct ps2dev { 36 31 struct serio *serio; ··· 43 36 wait_queue_head_t wait; 44 37 45 38 unsigned long flags; 46 - unsigned char cmdbuf[8]; 47 - unsigned char cmdcnt; 48 - unsigned char nak; 39 + u8 cmdbuf[8]; 40 + u8 cmdcnt; 41 + u8 nak; 49 42 }; 50 43 51 44 void ps2_init(struct ps2dev *ps2dev, struct serio *serio); 52 - int ps2_sendbyte(struct ps2dev *ps2dev, unsigned char byte, int timeout); 53 - void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout); 45 + int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout); 46 + void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout); 54 47 void ps2_begin_command(struct ps2dev *ps2dev); 55 48 void ps2_end_command(struct ps2dev *ps2dev); 56 - int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); 57 - int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command); 58 - int ps2_handle_ack(struct ps2dev *ps2dev, unsigned char data); 59 - int ps2_handle_response(struct ps2dev *ps2dev, unsigned char data); 49 + int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); 50 + int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command); 51 + int ps2_sliced_command(struct ps2dev *ps2dev, u8 command); 52 + bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data); 53 + bool ps2_handle_response(struct ps2dev *ps2dev, u8 data); 60 54 void ps2_cmd_aborted(struct ps2dev *ps2dev); 61 - int ps2_is_keyboard_id(char id); 55 + bool ps2_is_keyboard_id(u8 id); 62 56 63 57 #endif /* _LIBPS2_H */