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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'input-for-v7.1-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

Pull input updates from Dmitry Torokhov:

- a new charlieplex GPIO keypad driver

- an update to aw86927 driver to support 86938 chip

- an update for Chrome OS EC keyboard driver to support Fn-<key> keymap
extension

- an UAF fix in debugfs teardown in EDT touchscreen driver

- a number of conversions for input drivers to use guard() and __free()
cleanup primitives

- several drivers for bus mice (inport, logibm) and other very old
devices have been removed

- OLPC HGPK PS/2 protocol has been removed as it's been broken and
inactive for 10 something years

- dedicated kpsmoused has been removed from psmouse driver

- other assorted cleanups and fixups

* tag 'input-for-v7.1-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (101 commits)
Input: charlieplex_keypad - add GPIO charlieplex keypad
dt-bindings: input: add GPIO charlieplex keypad
dt-bindings: input: add settling-time-us common property
dt-bindings: input: add debounce-delay-ms common property
Input: imx_keypad - fix spelling mistake "Colums" -> "Columns"
Input: edt-ft5x06 - fix use-after-free in debugfs teardown
Input: ims-pcu - fix heap-buffer-overflow in ims_pcu_process_data()
Input: ct82c710 - remove driver
Input: mk712 - remove driver
Input: logibm - remove driver
Input: inport - remove driver
Input: qt1070 - inline i2c_check_functionality check
Input: qt1050 - inline i2c_check_functionality check
Input: aiptek - validate raw macro indices before updating state
Input: gf2k - skip invalid hat lookup values
Input: xpad - add RedOctane Games vendor id
Input: xpad - remove stale TODO and changelog header
Input: usbtouchscreen - refactor endpoint lookup
Input: aw86927 - add support for Awinic AW86938
dt-bindings: input: awinic,aw86927: Add Awinic AW86938
...

+1815 -3374
+2 -3
Documentation/devicetree/bindings/auxdisplay/holtek,ht16k33.yaml
··· 10 10 - Robin van der Gracht <robin@protonic.nl> 11 11 12 12 allOf: 13 + - $ref: /schemas/input/input.yaml# 13 14 - $ref: /schemas/input/matrix-keymap.yaml# 14 15 15 16 properties: ··· 34 33 interrupts: 35 34 maxItems: 1 36 35 37 - debounce-delay-ms: 38 - maxItems: 1 39 - description: Debouncing interval time in milliseconds 36 + debounce-delay-ms: true 40 37 41 38 linux,keymap: true 42 39
+6 -1
Documentation/devicetree/bindings/input/awinic,aw86927.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - const: awinic,aw86927 14 + oneOf: 15 + - const: awinic,aw86927 16 + - items: 17 + - enum: 18 + - awinic,aw86938 19 + - const: awinic,aw86927 15 20 16 21 reg: 17 22 maxItems: 1
+3 -4
Documentation/devicetree/bindings/input/cirrus,ep9307-keypad.yaml
··· 10 10 - Alexander Sverdlin <alexander.sverdlin@gmail.com> 11 11 12 12 allOf: 13 + - $ref: input.yaml# 13 14 - $ref: /schemas/input/matrix-keymap.yaml# 14 15 15 16 description: ··· 38 37 clocks: 39 38 maxItems: 1 40 39 41 - debounce-delay-ms: 42 - description: | 43 - Time in microseconds that key must be pressed or 44 - released for state change interrupt to trigger. 40 + # Time for state change interrupt to trigger 41 + debounce-delay-ms: true 45 42 46 43 cirrus,prescale: 47 44 description: row/column counter pre-scaler load value
+108
Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + 5 + $id: http://devicetree.org/schemas/input/gpio-charlieplex-keypad.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: GPIO charlieplex keypad 9 + 10 + maintainers: 11 + - Hugo Villeneuve <hvilleneuve@dimonoff.com> 12 + 13 + description: | 14 + The charlieplex keypad supports N^2)-N different key combinations (where N is 15 + the number of I/O lines). Key presses and releases are detected by configuring 16 + only one line as output at a time, and reading other line states. This process 17 + is repeated for each line. Diodes are required to ensure current flows in only 18 + one direction between any pair of pins, as well as pull-up or pull-down 19 + resistors on all I/O lines. 20 + This mechanism doesn't allow to detect simultaneous key presses. 21 + 22 + Wiring example for 3 lines keyboard with 6 switches and 3 diodes (pull-up/down 23 + resistors not shown but needed on L0, L1 and L2): 24 + 25 + L0 --+---------------------+----------------------+ 26 + | | | 27 + L1 -------+-----------+---------------------+ | 28 + | | | | | | 29 + L2 -------------+----------------+-----+ | | 30 + | | | | | | | | | 31 + | | | | | | | | | 32 + | S1 \ S2 \ | S3 \ S4 \ | S5 \ S6 \ 33 + | | | | | | | | | 34 + | +--+--+ | +--+--+ | +--+--+ 35 + | | | | | | 36 + | D1 v | D2 v | D3 v 37 + | - (k) | - (k) | - (k) 38 + | | | | | | 39 + +-------+ +-------+ +-------+ 40 + 41 + L: GPIO line 42 + S: switch 43 + D: diode (k indicates cathode) 44 + 45 + allOf: 46 + - $ref: input.yaml# 47 + - $ref: /schemas/input/matrix-keymap.yaml# 48 + 49 + properties: 50 + compatible: 51 + const: gpio-charlieplex-keypad 52 + 53 + autorepeat: true 54 + 55 + debounce-delay-ms: 56 + default: 5 57 + 58 + line-gpios: 59 + description: 60 + List of GPIOs used as lines. The gpio specifier for this property 61 + depends on the gpio controller to which these lines are connected. 62 + 63 + linux,keymap: true 64 + 65 + poll-interval: true 66 + 67 + settling-time-us: true 68 + 69 + wakeup-source: true 70 + 71 + required: 72 + - compatible 73 + - line-gpios 74 + - linux,keymap 75 + - poll-interval 76 + 77 + additionalProperties: false 78 + 79 + examples: 80 + - | 81 + #include <dt-bindings/gpio/gpio.h> 82 + #include <dt-bindings/input/input.h> 83 + 84 + keyboard { 85 + compatible = "gpio-charlieplex-keypad"; 86 + debounce-delay-ms = <20>; 87 + poll-interval = <5>; 88 + settling-time-us = <2>; 89 + 90 + line-gpios = <&gpio2 25 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) 91 + &gpio2 26 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) 92 + &gpio2 27 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; 93 + 94 + /* MATRIX_KEY(output, input, key-code) */ 95 + linux,keymap = < 96 + /* 97 + * According to wiring diagram above, if L1 is configured as 98 + * output and HIGH, and we detect a HIGH level on input L0, 99 + * then it means S1 is pressed: MATRIX_KEY(L1, L0, KEY...) 100 + */ 101 + MATRIX_KEY(1, 0, KEY_F1) /* S1 */ 102 + MATRIX_KEY(2, 0, KEY_F2) /* S2 */ 103 + MATRIX_KEY(0, 1, KEY_F3) /* S3 */ 104 + MATRIX_KEY(2, 1, KEY_F4) /* S4 */ 105 + MATRIX_KEY(1, 2, KEY_F5) /* S5 */ 106 + MATRIX_KEY(0, 2, KEY_F6) /* S6 */ 107 + >; 108 + };
+2 -3
Documentation/devicetree/bindings/input/gpio-matrix-keypad.yaml
··· 18 18 report the event using GPIO interrupts to the cpu. 19 19 20 20 allOf: 21 + - $ref: input.yaml# 21 22 - $ref: /schemas/input/matrix-keymap.yaml# 22 23 23 24 properties: ··· 47 46 Force GPIO polarity to active low. 48 47 In the absence of this property GPIOs are treated as active high. 49 48 50 - debounce-delay-ms: 51 - description: Debounce interval in milliseconds. 52 - default: 0 49 + debounce-delay-ms: true 53 50 54 51 col-scan-delay-us: 55 52 description:
+16
Documentation/devicetree/bindings/input/input.yaml
··· 14 14 description: Enable autorepeat when key is pressed and held down. 15 15 type: boolean 16 16 17 + debounce-delay-ms: 18 + description: 19 + Debounce delay in milliseconds. This is the time during which the key 20 + press or release signal must remain stable before it is considered valid. 21 + minimum: 0 22 + maximum: 999 23 + default: 0 24 + 17 25 linux,keycodes: 18 26 description: 19 27 Specifies an array of numeric keycode values to be used for reporting ··· 65 57 Duration in seconds which the key should be kept pressed for device to 66 58 reset automatically. Device with key pressed reset feature can specify 67 59 this property. 60 + 61 + settling-time-us: 62 + description: 63 + Delay, in microseconds, when activating an output line/col/row before 64 + we can reliably read other input lines that maybe affected by this 65 + output. This can be the case for an output with a RC circuit that affects 66 + ramp-up/down times. 67 + default: 0 68 68 69 69 dependencies: 70 70 linux,input-type: [ "linux,code" ]
+2 -2
Documentation/devicetree/bindings/input/matrix-keymap.yaml
··· 4 4 $id: http://devicetree.org/schemas/input/matrix-keymap.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Common Key Matrices on Matrix-connected Key Boards 7 + title: Common Key Matrices on Matrix-connected Keyboards 8 8 9 9 maintainers: 10 10 - Olof Johansson <olof@lixom.net> 11 11 12 12 description: | 13 - A simple common binding for matrix-connected key boards. Currently targeted at 13 + A simple common binding for matrix-connected keyboards. Currently targeted at 14 14 defining the keys in the scope of linux key codes since that is a stable and 15 15 standardized interface at this time. 16 16
+1
Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
··· 10 10 - Mattijs Korpershoek <mkorpershoek@kernel.org> 11 11 12 12 allOf: 13 + - $ref: input.yaml# 13 14 - $ref: /schemas/input/matrix-keymap.yaml# 14 15 15 16 description: |
+68
Documentation/devicetree/bindings/input/parade,tc3408.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/input/parade,tc3408.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Parade TC3408 touchscreen controller 8 + 9 + maintainers: 10 + - Langyan Ye <yelangyan@huaqin.corp-partner.google.com> 11 + 12 + description: | 13 + Parade TC3408 is a touchscreen controller supporting the I2C-HID protocol. 14 + It requires a reset GPIO and two power supplies (3.3V and 1.8V). 15 + 16 + allOf: 17 + - $ref: /schemas/input/touchscreen/touchscreen.yaml# 18 + 19 + properties: 20 + compatible: 21 + const: parade,tc3408 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + reset-gpios: 30 + maxItems: 1 31 + 32 + vcc33-supply: 33 + description: The 3.3V supply to the touchscreen. 34 + 35 + vccio-supply: 36 + description: The 1.8V supply to the touchscreen. 37 + 38 + required: 39 + - compatible 40 + - reg 41 + - interrupts 42 + - reset-gpios 43 + - vcc33-supply 44 + - vccio-supply 45 + 46 + unevaluatedProperties: false 47 + 48 + examples: 49 + - | 50 + #include <dt-bindings/gpio/gpio.h> 51 + #include <dt-bindings/interrupt-controller/irq.h> 52 + 53 + i2c { 54 + #address-cells = <1>; 55 + #size-cells = <0>; 56 + 57 + touchscreen: touchscreen@24 { 58 + compatible = "parade,tc3408"; 59 + reg = <0x24>; 60 + 61 + interrupt-parent = <&pio>; 62 + interrupts = <15 IRQ_TYPE_LEVEL_LOW>; 63 + 64 + reset-gpios = <&pio 126 GPIO_ACTIVE_LOW>; 65 + vcc33-supply = <&pp3300_tchscr_x>; 66 + vccio-supply = <&pp1800_tchscr_report_disable>; 67 + }; 68 + };
+17 -13
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml
··· 33 33 34 34 properties: 35 35 compatible: 36 - enum: 37 - - edt,edt-ft5206 38 - - edt,edt-ft5306 39 - - edt,edt-ft5406 40 - - edt,edt-ft5506 41 - - evervision,ev-ft5726 42 - - focaltech,ft3518 43 - - focaltech,ft5426 44 - - focaltech,ft5452 45 - - focaltech,ft6236 46 - - focaltech,ft8201 47 - - focaltech,ft8716 48 - - focaltech,ft8719 36 + oneOf: 37 + - enum: 38 + - edt,edt-ft5206 39 + - edt,edt-ft5306 40 + - edt,edt-ft5406 41 + - edt,edt-ft5506 42 + - evervision,ev-ft5726 43 + - focaltech,ft3518 44 + - focaltech,ft5426 45 + - focaltech,ft5452 46 + - focaltech,ft6236 47 + - focaltech,ft8201 48 + - focaltech,ft8716 49 + - focaltech,ft8719 50 + - items: 51 + - const: focaltech,ft3519 52 + - const: focaltech,ft3518 49 53 50 54 reg: 51 55 maxItems: 1
+4
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml
··· 32 32 description: A phandle to the reset GPIO 33 33 maxItems: 1 34 34 35 + wakeup-source: 36 + type: boolean 37 + 35 38 required: 36 39 - compatible 37 40 - reg ··· 54 51 reg = <0x55>; 55 52 interrupts = <2 0>; 56 53 gpios = <&gpio1 166 0>; 54 + wakeup-source; 57 55 58 56 touch-overlay { 59 57 segment-0 {
+42
Documentation/devicetree/bindings/input/touchscreen/technologic,ts4800-ts.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/input/touchscreen/technologic,ts4800-ts.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: TS-4800 Touchscreen 8 + 9 + maintainers: 10 + - Eduard Bostina <egbostina@gmail.com> 11 + 12 + properties: 13 + compatible: 14 + const: technologic,ts4800-ts 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + syscon: 20 + $ref: /schemas/types.yaml#/definitions/phandle-array 21 + items: 22 + - items: 23 + - description: Phandle to the FPGA's syscon 24 + - description: Offset to the touchscreen register 25 + - description: Offset to the touchscreen enable bit 26 + description: Phandle / integers array that points to the syscon node which 27 + describes the FPGA's syscon registers. 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - syscon 33 + 34 + additionalProperties: false 35 + 36 + examples: 37 + - | 38 + touchscreen@1000 { 39 + compatible = "technologic,ts4800-ts"; 40 + reg = <0x1000 0x100>; 41 + syscon = <&fpga_syscon 0x20 3>; 42 + };
+3 -3
Documentation/devicetree/bindings/input/touchscreen/trivial-touch.yaml
··· 53 53 54 54 wakeup-source: true 55 55 56 - allOf: 57 - - $ref: touchscreen.yaml 58 - 59 56 required: 60 57 - compatible 61 58 - reg 62 59 - interrupts 60 + 61 + allOf: 62 + - $ref: touchscreen.yaml 63 63 64 64 unevaluatedProperties: false 65 65
-11
Documentation/devicetree/bindings/input/touchscreen/ts4800-ts.txt
··· 1 - * TS-4800 Touchscreen bindings 2 - 3 - Required properties: 4 - - compatible: must be "technologic,ts4800-ts" 5 - - reg: physical base address of the controller and length of memory mapped 6 - region. 7 - - syscon: phandle / integers array that points to the syscon node which 8 - describes the FPGA's syscon registers. 9 - - phandle to FPGA's syscon 10 - - offset to the touchscreen register 11 - - offset to the touchscreen enable bit
-2
Documentation/devicetree/bindings/mfd/fsl,mc13xxx.yaml
··· 76 76 debounce-delay-ms: 77 77 enum: [0, 30, 150, 750] 78 78 default: 30 79 - description: 80 - Sets the debouncing delay in milliseconds. 81 79 82 80 active-low: 83 81 description: Set active when pin is pulled low.
+7
MAINTAINERS
··· 5959 5959 F: Documentation/hwmon/powerz.rst 5960 5960 F: drivers/hwmon/powerz.c 5961 5961 5962 + CHARLIEPLEX KEYPAD DRIVER 5963 + M: Hugo Villeneuve <hvilleneuve@dimonoff.com> 5964 + S: Supported 5965 + W: http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/electronic-circuits/matrix-keypad-scan-decode 5966 + F: Documentation/devicetree/bindings/input/gpio-charlieplex-keypad.yaml 5967 + F: drivers/input/keyboard/charlieplex_keypad.c 5968 + 5962 5969 CHECKPATCH 5963 5970 M: Andy Whitcroft <apw@canonical.com> 5964 5971 M: Joe Perches <joe@perches.com>
+8
drivers/hid/i2c-hid/i2c-hid-of-elan.c
··· 195 195 .main_supply_name = "vcc33", 196 196 }; 197 197 198 + static const struct elan_i2c_hid_chip_data parade_tc3408_chip_data = { 199 + .post_power_delay_ms = 10, 200 + .post_gpio_reset_on_delay_ms = 300, 201 + .hid_descriptor_address = 0x0001, 202 + .main_supply_name = "vcc33", 203 + }; 204 + 198 205 static const struct of_device_id elan_i2c_hid_of_match[] = { 199 206 { .compatible = "elan,ekth6915", .data = &elan_ekth6915_chip_data }, 200 207 { .compatible = "elan,ekth6a12nay", .data = &elan_ekth6a12nay_chip_data }, 201 208 { .compatible = "focaltech,ft8112", .data = &focaltech_ft8112_chip_data }, 202 209 { .compatible = "ilitek,ili9882t", .data = &ilitek_ili9882t_chip_data }, 203 210 { .compatible = "ilitek,ili2901", .data = &ilitek_ili2901_chip_data }, 211 + { .compatible = "parade,tc3408", .data = &parade_tc3408_chip_data }, 204 212 { } 205 213 }; 206 214 MODULE_DEVICE_TABLE(of, elan_i2c_hid_of_match);
+20 -3
drivers/input/input.c
··· 800 800 return 0; 801 801 } 802 802 803 - static int input_default_setkeycode(struct input_dev *dev, 804 - const struct input_keymap_entry *ke, 805 - unsigned int *old_keycode) 803 + /** 804 + * input_default_setkeycode - default setkeycode method 805 + * @dev: input device which keymap is being updated. 806 + * @ke: new keymap entry. 807 + * @old_keycode: pointer to the location where old keycode should be stored. 808 + * 809 + * This function is the default implementation of &input_dev.setkeycode() 810 + * method. It is typically used when a driver does not provide its own 811 + * implementation, but it is also exported so drivers can extend it. 812 + * 813 + * The function must be called with &input_dev.event_lock held. 814 + * 815 + * Return: 0 on success, or a negative error code on failure. 816 + */ 817 + int input_default_setkeycode(struct input_dev *dev, 818 + const struct input_keymap_entry *ke, 819 + unsigned int *old_keycode) 806 820 { 807 821 unsigned int index; 808 822 int error; 809 823 int i; 824 + 825 + lockdep_assert_held(&dev->event_lock); 810 826 811 827 if (!dev->keycodesize) 812 828 return -EINVAL; ··· 877 861 __set_bit(ke->keycode, dev->keybit); 878 862 return 0; 879 863 } 864 + EXPORT_SYMBOL(input_default_setkeycode); 880 865 881 866 /** 882 867 * input_get_keycode - retrieve keycode currently mapped to a given scancode
+4 -2
drivers/input/joystick/gf2k.c
··· 165 165 166 166 t = GB(40,4,0); 167 167 168 - for (i = 0; i < gf2k_hats[gf2k->id]; i++) 169 - input_report_abs(dev, ABS_HAT0X + i, gf2k_hat_to_axis[t][i]); 168 + if (t < ARRAY_SIZE(gf2k_hat_to_axis)) 169 + for (i = 0; i < gf2k_hats[gf2k->id]; i++) 170 + input_report_abs(dev, ABS_HAT0X + i, 171 + gf2k_hat_to_axis[t][i]); 170 172 171 173 t = GB(44,2,0) | GB(32,8,2) | GB(78,2,10); 172 174
+1 -34
drivers/input/joystick/xpad.c
··· 25 25 * - Greg Kroah-Hartman - usb-skeleton driver 26 26 * - Xbox Linux project - extra USB IDs 27 27 * - Pekka Pöyry (quantus) - Xbox One controller reverse-engineering 28 - * 29 - * TODO: 30 - * - fine tune axes (especially trigger axes) 31 - * - fix "analog" buttons (reported as digital now) 32 - * - get rumble working 33 - * - need USB IDs for other dance pads 34 - * 35 - * History: 36 - * 37 - * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller" 38 - * 39 - * 2002-07-02 - 0.0.2 : basic working version 40 - * - all axes and 9 of the 10 buttons work (german InterAct device) 41 - * - the black button does not work 42 - * 43 - * 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik 44 - * - indentation fixes 45 - * - usb + input init sequence fixes 46 - * 47 - * 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3 48 - * - verified the lack of HID and report descriptors 49 - * - verified that ALL buttons WORK 50 - * - fixed d-pad to axes mapping 51 - * 52 - * 2002-07-17 - 0.0.5 : simplified d-pad handling 53 - * 54 - * 2004-10-02 - 0.0.6 : DDR pad support 55 - * - borrowed from the Xbox Linux kernel 56 - * - USB id's for commonly used dance pads are present 57 - * - dance pads will map D-PAD to buttons, not axes 58 - * - pass the module paramater 'dpad_to_buttons' to force 59 - * the D-PAD to map to buttons if your pad is not detected 60 - * 61 - * Later changes can be tracked in SCM. 62 28 */ 63 29 64 30 #include <linux/bits.h> ··· 556 590 XPAD_XBOX360_VENDOR(0x3651), /* CRKD Controllers */ 557 591 XPAD_XBOXONE_VENDOR(0x366c), /* ByoWave controllers */ 558 592 XPAD_XBOX360_VENDOR(0x37d7), /* Flydigi Controllers */ 593 + XPAD_XBOX360_VENDOR(0x3958), /* RedOctane Games Controllers */ 559 594 XPAD_XBOX360_VENDOR(0x413d), /* Black Shark Green Ghost Controller */ 560 595 { } 561 596 };
+14
drivers/input/keyboard/Kconfig
··· 289 289 To compile this driver as a module, choose M here: the 290 290 module will be called matrix_keypad. 291 291 292 + config KEYBOARD_CHARLIEPLEX 293 + tristate "GPIO driven charlieplex keypad support" 294 + depends on GPIOLIB || COMPILE_TEST 295 + select INPUT_MATRIXKMAP 296 + help 297 + Enable support for GPIO driven charlieplex keypad. A charlieplex 298 + keypad allows to use fewer GPIO lines to interface to key switches. 299 + For example, an N lines charlieplex keypad can be used to interface 300 + to N^2-N different key switches. However, this type of keypad 301 + cannot detect more than one key press at a time. 302 + 303 + To compile this driver as a module, choose M here: the 304 + module will be called charlieplex_keypad. 305 + 292 306 config KEYBOARD_HIL_OLD 293 307 tristate "HP HIL keyboard support (simple driver)" 294 308 depends on GSC || HP300
+1
drivers/input/keyboard/Makefile
··· 15 15 obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o 16 16 obj-$(CONFIG_KEYBOARD_BCM) += bcm-keypad.o 17 17 obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o 18 + obj-$(CONFIG_KEYBOARD_CHARLIEPLEX) += charlieplex_keypad.o 18 19 obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o 19 20 obj-$(CONFIG_KEYBOARD_CROS_EC) += cros_ec_keyb.o 20 21 obj-$(CONFIG_KEYBOARD_CYPRESS_SF) += cypress-sf.o
+56 -77
drivers/input/keyboard/atkbd.c
··· 3 3 * AT and PS/2 keyboard driver 4 4 * 5 5 * Copyright (c) 1999-2002 Vojtech Pavlik 6 - */ 7 - 8 - 9 - /* 6 + * 10 7 * This driver can handle standard AT keyboards and PS/2 keyboards in 11 8 * Translated and Raw Set 2 and Set 3, as well as AT keyboards on dumb 12 9 * input-only controllers and AT keyboards connected over a one way RS232 ··· 62 65 module_param_named(terminal, atkbd_terminal, bool, 0); 63 66 MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2"); 64 67 65 - #define SCANCODE(keymap) ((keymap >> 16) & 0xFFFF) 66 - #define KEYCODE(keymap) (keymap & 0xFFFF) 68 + #define SCANCODE(keymap) (((keymap) >> 16) & 0xFFFF) 69 + #define KEYCODE(keymap) ((keymap) & 0xFFFF) 67 70 68 71 /* 69 72 * Scancode to keycode tables. These are just the default setting, and ··· 73 76 #define ATKBD_KEYMAP_SIZE 512 74 77 75 78 static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = { 76 - 77 79 #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES 78 80 79 81 /* XXX: need a more general approach */ ··· 103 107 }; 104 108 105 109 static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = { 106 - 107 110 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60, 108 111 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62, 109 112 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64, ··· 117 122 148,149,147,140 118 123 }; 119 124 120 - static const unsigned short atkbd_unxlate_table[128] = { 121 - 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13, 122 - 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27, 123 - 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42, 124 - 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3, 125 - 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105, 126 - 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63, 127 - 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111, 128 - 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110 125 + static const u8 atkbd_unxlate_table[128] = { 126 + 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13, 127 + 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27, 128 + 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42, 129 + 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3, 130 + 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105, 131 + 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63, 132 + 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111, 133 + 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110 129 134 }; 130 135 131 136 #define ATKBD_CMD_SETLEDS 0x10ed ··· 179 184 180 185 static const struct { 181 186 unsigned short keycode; 182 - unsigned char set2; 187 + u8 set2; 183 188 } atkbd_scroll_keys[] = { 184 189 { ATKBD_SCR_1, 0xc5 }, 185 190 { ATKBD_SCR_2, 0x9d }, ··· 195 200 */ 196 201 197 202 struct atkbd { 198 - 199 203 struct ps2dev ps2dev; 200 204 struct input_dev *dev; 201 205 ··· 205 211 unsigned short id; 206 212 unsigned short keycode[ATKBD_KEYMAP_SIZE]; 207 213 DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE); 208 - unsigned char set; 214 + u8 set; 209 215 bool translated; 210 216 bool extra; 211 217 bool write; ··· 215 221 bool enabled; 216 222 217 223 /* Accessed only from interrupt */ 218 - unsigned char emul; 224 + u8 emul; 219 225 bool resend; 220 226 bool release; 221 227 unsigned long xl_bit; ··· 247 253 static bool atkbd_skip_deactivate; 248 254 249 255 static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, 250 - ssize_t (*handler)(struct atkbd *, char *)); 256 + ssize_t (*handler)(struct atkbd *, char *)); 251 257 static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count, 252 - ssize_t (*handler)(struct atkbd *, const char *, size_t)); 258 + ssize_t (*handler)(struct atkbd *, const char *, size_t)); 253 259 #define ATKBD_DEFINE_ATTR(_name) \ 254 260 static ssize_t atkbd_show_##_name(struct atkbd *, char *); \ 255 261 static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \ ··· 264 270 return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \ 265 271 } \ 266 272 static struct device_attribute atkbd_attr_##_name = \ 267 - __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name); 273 + __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name) 268 274 269 275 ATKBD_DEFINE_ATTR(extra); 270 276 ATKBD_DEFINE_ATTR(force_release); ··· 281 287 return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \ 282 288 } \ 283 289 static struct device_attribute atkbd_attr_##_name = \ 284 - __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL); 290 + __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL) 285 291 286 292 ATKBD_DEFINE_RO_ATTR(err_count); 287 293 ATKBD_DEFINE_RO_ATTR(function_row_physmap); ··· 311 317 } 312 318 313 319 static umode_t atkbd_attr_is_visible(struct kobject *kobj, 314 - struct attribute *attr, int i) 320 + struct attribute *attr, int i) 315 321 { 316 322 struct device *dev = kobj_to_dev(kobj); 317 323 struct serio *serio = to_serio_port(dev); ··· 331 337 332 338 __ATTRIBUTE_GROUPS(atkbd_attribute); 333 339 334 - static const unsigned int xl_table[] = { 340 + static const u8 xl_table[] = { 335 341 ATKBD_RET_BAT, ATKBD_RET_ERR, ATKBD_RET_ACK, 336 342 ATKBD_RET_NAK, ATKBD_RET_HANJA, ATKBD_RET_HANGEUL, 337 343 }; ··· 340 346 * Checks if we should mangle the scancode to extract 'release' bit 341 347 * in translated mode. 342 348 */ 343 - static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code) 349 + static bool atkbd_need_xlate(unsigned long xl_bit, u8 code) 344 350 { 345 351 int i; 346 352 ··· 359 365 * between make/break pair of scancodes for select keys and PS/2 360 366 * protocol responses. 361 367 */ 362 - static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code) 368 + static void atkbd_calculate_xl_bit(struct atkbd *atkbd, u8 code) 363 369 { 364 370 int i; 365 371 ··· 383 389 if (atkbd->set == 3) { 384 390 if (atkbd->emul == 1) 385 391 code |= 0x100; 386 - } else { 392 + } else { 387 393 code = (code & 0x7f) | ((code & 0x80) << 1); 388 394 if (atkbd->emul == 1) 389 395 code |= 0x80; ··· 425 431 426 432 dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags); 427 433 428 - #if !defined(__i386__) && !defined (__x86_64__) 434 + #if !defined(__i386__) && !defined(__x86_64__) 429 435 if (atkbd_handle_frame_error(ps2dev, data, flags)) 430 436 return PS2_IGNORE; 431 437 #endif ··· 454 460 code = atkbd_platform_scancode_fixup(atkbd, code); 455 461 456 462 if (atkbd->translated) { 457 - 458 463 if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) { 459 464 atkbd->release = code >> 7; 460 465 code &= 0x7f; ··· 479 486 return; 480 487 case ATKBD_RET_ACK: 481 488 case ATKBD_RET_NAK: 482 - if (printk_ratelimit()) 483 - dev_warn(&serio->dev, 484 - "Spurious %s on %s. " 485 - "Some program might be trying to access hardware directly.\n", 486 - data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys); 489 + dev_warn_ratelimited(&serio->dev, 490 + "Spurious %s on %s. Some program might be trying to access hardware directly.\n", 491 + data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys); 487 492 return; 488 493 case ATKBD_RET_ERR: 489 494 atkbd->err_count++; ··· 573 582 574 583 static int atkbd_set_repeat_rate(struct atkbd *atkbd) 575 584 { 576 - const short period[32] = 577 - { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 578 - 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 }; 579 - const short delay[4] = 580 - { 250, 500, 750, 1000 }; 585 + const short period[32] = { 586 + 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125, 587 + 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 588 + }; 589 + const short delay[4] = { 250, 500, 750, 1000 }; 581 590 582 591 struct input_dev *dev = atkbd->dev; 583 - unsigned char param; 592 + u8 param; 584 593 int i = 0, j = 0; 585 594 586 595 while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD]) ··· 598 607 static int atkbd_set_leds(struct atkbd *atkbd) 599 608 { 600 609 struct input_dev *dev = atkbd->dev; 601 - unsigned char param[2]; 610 + u8 param[2]; 602 611 603 612 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 604 613 | (test_bit(LED_NUML, dev->led) ? 2 : 0) ··· 639 648 * it may not be ready yet. In this case we need to keep 640 649 * rescheduling till reconnect completes. 641 650 */ 642 - schedule_delayed_work(&atkbd->event_work, 643 - msecs_to_jiffies(100)); 651 + schedule_delayed_work(&atkbd->event_work, msecs_to_jiffies(100)); 644 652 } else { 645 653 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) 646 654 atkbd_set_leds(atkbd); ··· 673 683 */ 674 684 675 685 static int atkbd_event(struct input_dev *dev, 676 - unsigned int type, unsigned int code, int value) 686 + unsigned int type, unsigned int code, int value) 677 687 { 678 688 struct atkbd *atkbd = input_get_drvdata(dev); 679 689 ··· 681 691 return -1; 682 692 683 693 switch (type) { 684 - 685 694 case EV_LED: 686 695 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT); 687 696 return 0; ··· 797 808 static int atkbd_probe(struct atkbd *atkbd) 798 809 { 799 810 struct ps2dev *ps2dev = &atkbd->ps2dev; 800 - unsigned char param[2]; 811 + u8 param[2]; 801 812 802 813 /* 803 814 * Some systems, where the bit-twiddling when testing the io-lines of the ··· 825 836 826 837 param[0] = param[1] = 0xa5; /* initialize with invalid values */ 827 838 if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) { 828 - 829 839 /* 830 840 * If the get ID command failed, we check if we can at least set 831 841 * the LEDs on the keyboard. This should work on every keyboard out there. ··· 844 856 845 857 if (atkbd->id == 0xaca1 && atkbd->translated) { 846 858 dev_err(&ps2dev->serio->dev, 847 - "NCD terminal keyboards are only supported on non-translating controllers. " 848 - "Use i8042.direct=1 to disable translation.\n"); 859 + "NCD terminal keyboards are only supported on non-translating controllers. Use i8042.direct=1 to disable translation.\n"); 849 860 return -1; 850 861 } 851 862 ··· 868 881 static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra) 869 882 { 870 883 struct ps2dev *ps2dev = &atkbd->ps2dev; 871 - unsigned char param[2]; 884 + u8 param[2]; 872 885 873 886 atkbd->extra = false; 874 887 /* ··· 928 941 929 942 static int atkbd_reset_state(struct atkbd *atkbd) 930 943 { 931 - struct ps2dev *ps2dev = &atkbd->ps2dev; 932 - unsigned char param[1]; 944 + struct ps2dev *ps2dev = &atkbd->ps2dev; 945 + u8 param[1]; 933 946 934 947 /* 935 948 * Set the LEDs to a predefined state (all off). ··· 954 967 * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a 955 968 * reboot. 956 969 */ 957 - 958 970 static void atkbd_cleanup(struct serio *serio) 959 971 { 960 972 struct atkbd *atkbd = atkbd_from_serio(serio); ··· 962 976 ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF); 963 977 } 964 978 965 - 966 979 /* 967 980 * atkbd_disconnect() closes and frees. 968 981 */ 969 - 970 982 static void atkbd_disconnect(struct serio *serio) 971 983 { 972 984 struct atkbd *atkbd = atkbd_from_serio(serio); ··· 989 1005 /* 990 1006 * generate release events for the keycodes given in data 991 1007 */ 992 - static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd, 993 - const void *data) 1008 + static void atkbd_apply_forced_release_keylist(struct atkbd *atkbd, const void *data) 994 1009 { 995 1010 const unsigned int *keys = data; 996 1011 unsigned int i; ··· 1071 1088 { 1072 1089 struct device *dev = &atkbd->ps2dev.serio->dev; 1073 1090 int i, n; 1074 - u32 *ptr; 1075 1091 u16 scancode, keycode; 1076 1092 1077 1093 /* Parse "linux,keymap" property */ ··· 1078 1096 if (n <= 0 || n > ATKBD_KEYMAP_SIZE) 1079 1097 return -ENXIO; 1080 1098 1081 - ptr = kcalloc(n, sizeof(u32), GFP_KERNEL); 1099 + u32 *ptr __free(kfree) = kcalloc(n, sizeof(*ptr), GFP_KERNEL); 1082 1100 if (!ptr) 1083 1101 return -ENOMEM; 1084 1102 1085 1103 if (device_property_read_u32_array(dev, "linux,keymap", ptr, n)) { 1086 1104 dev_err(dev, "problem parsing FW keymap property\n"); 1087 - kfree(ptr); 1088 1105 return -EINVAL; 1089 1106 } 1090 1107 ··· 1091 1110 for (i = 0; i < n; i++) { 1092 1111 scancode = SCANCODE(ptr[i]); 1093 1112 keycode = KEYCODE(ptr[i]); 1113 + if (scancode >= ATKBD_KEYMAP_SIZE) { 1114 + dev_warn(dev, "invalid scancode %#x in FW keymap entry %d\n", 1115 + scancode, i); 1116 + return -EINVAL; 1117 + } 1094 1118 atkbd->keycode[scancode] = keycode; 1095 1119 } 1096 1120 1097 - kfree(ptr); 1098 1121 return 0; 1099 1122 } 1100 1123 ··· 1220 1235 } 1221 1236 1222 1237 input_dev->keycode = atkbd->keycode; 1223 - input_dev->keycodesize = sizeof(unsigned short); 1238 + input_dev->keycodesize = sizeof(atkbd->keycode[0]); 1224 1239 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 1225 1240 1226 1241 for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) { ··· 1274 1289 mutex_init(&atkbd->mutex); 1275 1290 1276 1291 switch (serio->id.type) { 1277 - 1278 1292 case SERIO_8042_XL: 1279 1293 atkbd->translated = true; 1280 1294 fallthrough; ··· 1298 1314 goto fail2; 1299 1315 1300 1316 if (atkbd->write) { 1301 - 1302 1317 if (atkbd_probe(atkbd)) { 1303 1318 err = -ENODEV; 1304 1319 goto fail3; ··· 1337 1354 * atkbd_reconnect() tries to restore keyboard into a sane state and is 1338 1355 * most likely called on resume. 1339 1356 */ 1340 - 1341 1357 static int atkbd_reconnect(struct serio *serio) 1342 1358 { 1343 1359 struct atkbd *atkbd = atkbd_from_serio(serio); ··· 1371 1389 atkbd_set_leds(atkbd); 1372 1390 if (!atkbd->softrepeat) 1373 1391 atkbd_set_repeat_rate(atkbd); 1374 - 1375 1392 } 1376 1393 1377 1394 /* ··· 1426 1445 }; 1427 1446 1428 1447 static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf, 1429 - ssize_t (*handler)(struct atkbd *, char *)) 1448 + ssize_t (*handler)(struct atkbd *, char *)) 1430 1449 { 1431 1450 struct serio *serio = to_serio_port(dev); 1432 1451 struct atkbd *atkbd = atkbd_from_serio(serio); ··· 1435 1454 } 1436 1455 1437 1456 static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count, 1438 - ssize_t (*handler)(struct atkbd *, const char *, size_t)) 1457 + ssize_t (*handler)(struct atkbd *, const char *, size_t)) 1439 1458 { 1440 1459 struct serio *serio = to_serio_port(dev); 1441 1460 struct atkbd *atkbd = atkbd_from_serio(serio); ··· 1463 1482 unsigned int value; 1464 1483 int err; 1465 1484 bool old_extra; 1466 - unsigned char old_set; 1485 + u8 old_set; 1467 1486 1468 1487 if (!atkbd->write) 1469 1488 return -EIO; ··· 1508 1527 return err; 1509 1528 } 1510 1529 input_unregister_device(old_dev); 1511 - 1512 1530 } 1531 + 1513 1532 return count; 1514 1533 } 1515 1534 ··· 1525 1544 } 1526 1545 1527 1546 static ssize_t atkbd_set_force_release(struct atkbd *atkbd, 1528 - const char *buf, size_t count) 1547 + const char *buf, size_t count) 1529 1548 { 1530 1549 /* 64 bytes on stack should be acceptable */ 1531 1550 DECLARE_BITMAP(new_mask, ATKBD_KEYMAP_SIZE); ··· 1538 1557 memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask)); 1539 1558 return count; 1540 1559 } 1541 - 1542 1560 1543 1561 static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf) 1544 1562 { ··· 1597 1617 struct input_dev *old_dev, *new_dev; 1598 1618 unsigned int value; 1599 1619 int err; 1600 - unsigned char old_set; 1620 + u8 old_set; 1601 1621 bool old_extra; 1602 1622 1603 1623 if (!atkbd->write) ··· 1694 1714 } 1695 1715 return count; 1696 1716 } 1697 - 1698 1717 1699 1718 static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf) 1700 1719 {
+232
drivers/input/keyboard/charlieplex_keypad.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * GPIO driven charlieplex keypad driver 4 + * 5 + * Copyright (c) 2026 Hugo Villeneuve <hvilleneuve@dimonoff.com> 6 + * 7 + * Based on matrix_keyboard.c 8 + */ 9 + 10 + #include <linux/bitops.h> 11 + #include <linux/delay.h> 12 + #include <linux/dev_printk.h> 13 + #include <linux/device/devres.h> 14 + #include <linux/err.h> 15 + #include <linux/gpio/consumer.h> 16 + #include <linux/input.h> 17 + #include <linux/input/matrix_keypad.h> 18 + #include <linux/math.h> 19 + #include <linux/module.h> 20 + #include <linux/mod_devicetable.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/property.h> 23 + #include <linux/string_helpers.h> 24 + #include <linux/types.h> 25 + 26 + struct charlieplex_keypad { 27 + struct input_dev *input_dev; 28 + struct gpio_descs *line_gpios; 29 + unsigned int nlines; 30 + unsigned int settling_time_us; 31 + unsigned int debounce_threshold; 32 + unsigned int debounce_count; 33 + int debounce_code; 34 + int current_code; 35 + }; 36 + 37 + static void charlieplex_keypad_report_key(struct input_dev *input) 38 + { 39 + struct charlieplex_keypad *keypad = input_get_drvdata(input); 40 + const unsigned short *keycodes = input->keycode; 41 + 42 + if (keypad->current_code > 0) { 43 + input_event(input, EV_MSC, MSC_SCAN, keypad->current_code); 44 + input_report_key(input, keycodes[keypad->current_code], 0); 45 + input_sync(input); 46 + } 47 + 48 + if (keypad->debounce_code) { 49 + input_event(input, EV_MSC, MSC_SCAN, keypad->debounce_code); 50 + input_report_key(input, keycodes[keypad->debounce_code], 1); 51 + input_sync(input); 52 + } 53 + 54 + keypad->current_code = keypad->debounce_code; 55 + } 56 + 57 + static void charlieplex_keypad_check_switch_change(struct input_dev *input, 58 + unsigned int code) 59 + { 60 + struct charlieplex_keypad *keypad = input_get_drvdata(input); 61 + 62 + if (code != keypad->debounce_code) { 63 + keypad->debounce_count = 0; 64 + keypad->debounce_code = code; 65 + } 66 + 67 + if (keypad->debounce_code != keypad->current_code) { 68 + if (keypad->debounce_count++ >= keypad->debounce_threshold) 69 + charlieplex_keypad_report_key(input); 70 + } 71 + } 72 + 73 + static int charlieplex_keypad_scan_line(struct charlieplex_keypad *keypad, 74 + unsigned int oline) 75 + { 76 + struct gpio_descs *line_gpios = keypad->line_gpios; 77 + DECLARE_BITMAP(values, MATRIX_MAX_ROWS); 78 + int err; 79 + 80 + /* Activate only one line as output at a time. */ 81 + gpiod_direction_output(line_gpios->desc[oline], 1); 82 + 83 + if (keypad->settling_time_us) 84 + fsleep(keypad->settling_time_us); 85 + 86 + /* Read input on all other lines. */ 87 + err = gpiod_get_array_value_cansleep(line_gpios->ndescs, line_gpios->desc, 88 + line_gpios->info, values); 89 + 90 + gpiod_direction_input(line_gpios->desc[oline]); 91 + 92 + if (err) 93 + return err; 94 + 95 + for (unsigned int iline = 0; iline < keypad->nlines; iline++) { 96 + if (iline == oline) 97 + continue; /* Do not read active output line. */ 98 + 99 + /* Check if GPIO is asserted. */ 100 + if (test_bit(iline, values)) 101 + return MATRIX_SCAN_CODE(oline, iline, 102 + get_count_order(keypad->nlines)); 103 + } 104 + 105 + return 0; 106 + } 107 + 108 + static void charlieplex_keypad_poll(struct input_dev *input) 109 + { 110 + struct charlieplex_keypad *keypad = input_get_drvdata(input); 111 + int code = 0; 112 + 113 + for (unsigned int oline = 0; oline < keypad->nlines; oline++) { 114 + code = charlieplex_keypad_scan_line(keypad, oline); 115 + if (code != 0) 116 + break; 117 + } 118 + 119 + if (code >= 0) 120 + charlieplex_keypad_check_switch_change(input, code); 121 + } 122 + 123 + static int charlieplex_keypad_init_gpio(struct platform_device *pdev, 124 + struct charlieplex_keypad *keypad) 125 + { 126 + char **pin_names; 127 + char label[32]; 128 + 129 + snprintf(label, sizeof(label), "%s-pin", pdev->name); 130 + 131 + keypad->line_gpios = devm_gpiod_get_array(&pdev->dev, "line", GPIOD_IN); 132 + if (IS_ERR(keypad->line_gpios)) 133 + return PTR_ERR(keypad->line_gpios); 134 + 135 + keypad->nlines = keypad->line_gpios->ndescs; 136 + 137 + if (keypad->nlines > MATRIX_MAX_ROWS) 138 + return -EINVAL; 139 + 140 + pin_names = devm_kasprintf_strarray(&pdev->dev, label, keypad->nlines); 141 + if (IS_ERR(pin_names)) 142 + return PTR_ERR(pin_names); 143 + 144 + for (unsigned int i = 0; i < keypad->line_gpios->ndescs; i++) 145 + gpiod_set_consumer_name(keypad->line_gpios->desc[i], pin_names[i]); 146 + 147 + return 0; 148 + } 149 + 150 + static int charlieplex_keypad_probe(struct platform_device *pdev) 151 + { 152 + struct charlieplex_keypad *keypad; 153 + struct input_dev *input_dev; 154 + unsigned int debounce_interval_ms = 5; 155 + unsigned int poll_interval_ms; 156 + int err; 157 + 158 + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); 159 + if (!keypad) 160 + return -ENOMEM; 161 + 162 + input_dev = devm_input_allocate_device(&pdev->dev); 163 + if (!input_dev) 164 + return -ENOMEM; 165 + 166 + keypad->input_dev = input_dev; 167 + 168 + err = device_property_read_u32(&pdev->dev, "poll-interval", &poll_interval_ms); 169 + if (err) 170 + return dev_err_probe(&pdev->dev, err, 171 + "failed to parse 'poll-interval' property\n"); 172 + 173 + if (poll_interval_ms == 0) 174 + return dev_err_probe(&pdev->dev, -EINVAL, "invalid 'poll-interval' value\n"); 175 + 176 + device_property_read_u32(&pdev->dev, "debounce-delay-ms", &debounce_interval_ms); 177 + device_property_read_u32(&pdev->dev, "settling-time-us", &keypad->settling_time_us); 178 + 179 + keypad->current_code = -1; 180 + keypad->debounce_code = -1; 181 + keypad->debounce_threshold = DIV_ROUND_UP(debounce_interval_ms, poll_interval_ms); 182 + 183 + err = charlieplex_keypad_init_gpio(pdev, keypad); 184 + if (err) 185 + return err; 186 + 187 + input_dev->name = pdev->name; 188 + input_dev->id.bustype = BUS_HOST; 189 + 190 + err = matrix_keypad_build_keymap(NULL, NULL, keypad->nlines, 191 + keypad->nlines, NULL, input_dev); 192 + if (err) 193 + return dev_err_probe(&pdev->dev, err, "failed to build keymap\n"); 194 + 195 + if (device_property_read_bool(&pdev->dev, "autorepeat")) 196 + __set_bit(EV_REP, input_dev->evbit); 197 + 198 + input_set_capability(input_dev, EV_MSC, MSC_SCAN); 199 + 200 + err = input_setup_polling(input_dev, charlieplex_keypad_poll); 201 + if (err) 202 + return dev_err_probe(&pdev->dev, err, "unable to set up polling\n"); 203 + 204 + input_set_poll_interval(input_dev, poll_interval_ms); 205 + 206 + input_set_drvdata(input_dev, keypad); 207 + 208 + err = input_register_device(keypad->input_dev); 209 + if (err) 210 + return err; 211 + 212 + return 0; 213 + } 214 + 215 + static const struct of_device_id charlieplex_keypad_dt_match[] = { 216 + { .compatible = "gpio-charlieplex-keypad" }, 217 + { } 218 + }; 219 + MODULE_DEVICE_TABLE(of, charlieplex_keypad_dt_match); 220 + 221 + static struct platform_driver charlieplex_keypad_driver = { 222 + .probe = charlieplex_keypad_probe, 223 + .driver = { 224 + .name = "charlieplex-keypad", 225 + .of_match_table = charlieplex_keypad_dt_match, 226 + }, 227 + }; 228 + module_platform_driver(charlieplex_keypad_driver); 229 + 230 + MODULE_AUTHOR("Hugo Villeneuve <hvilleneuve@dimonoff.com>"); 231 + MODULE_DESCRIPTION("GPIO driven charlieplex keypad driver"); 232 + MODULE_LICENSE("GPL");
+203 -56
drivers/input/keyboard/cros_ec_keyb.c
··· 29 29 30 30 #include <linux/unaligned.h> 31 31 32 + /* 33 + * Maximum size of the normal key matrix, this is limited by the host command 34 + * key_matrix field defined in ec_response_get_next_data_v3 35 + */ 36 + #define CROS_EC_KEYBOARD_COLS_MAX 18 37 + 32 38 /** 33 39 * struct cros_ec_keyb - Structure representing EC keyboard device 34 40 * ··· 50 44 * @bs_idev: The input device for non-matrix buttons and switches (or NULL). 51 45 * @notifier: interrupt event notifier for transport devices 52 46 * @vdata: vivaldi function row data 47 + * @has_fn_map: whether the driver uses an fn function-map layer 48 + * @fn_active: tracks whether the function key is currently pressed 49 + * @fn_combo_active: tracks whether another key was pressed while fn is active 53 50 */ 54 51 struct cros_ec_keyb { 55 52 unsigned int rows; 56 53 unsigned int cols; 57 54 int row_shift; 58 55 bool ghost_filter; 59 - uint8_t *valid_keys; 60 - uint8_t *old_kb_state; 56 + u8 valid_keys[CROS_EC_KEYBOARD_COLS_MAX]; 57 + u8 old_kb_state[CROS_EC_KEYBOARD_COLS_MAX]; 61 58 62 59 struct device *dev; 63 60 struct cros_ec_device *ec; ··· 70 61 struct notifier_block notifier; 71 62 72 63 struct vivaldi_data vdata; 64 + 65 + bool has_fn_map; 66 + bool fn_active; 67 + bool fn_combo_active; 73 68 }; 74 69 75 70 /** ··· 145 132 * Returns true when there is at least one combination of pressed keys that 146 133 * results in ghosting. 147 134 */ 148 - static bool cros_ec_keyb_has_ghosting(struct cros_ec_keyb *ckdev, uint8_t *buf) 135 + static bool cros_ec_keyb_has_ghosting(struct cros_ec_keyb *ckdev, u8 *buf) 149 136 { 150 137 int col1, col2, buf1, buf2; 151 138 struct device *dev = ckdev->dev; 152 - uint8_t *valid_keys = ckdev->valid_keys; 139 + u8 *valid_keys = ckdev->valid_keys; 153 140 154 141 /* 155 142 * Ghosting happens if for any pressed key X there are other keys ··· 179 166 return false; 180 167 } 181 168 169 + static void cros_ec_emit_fn_key(struct input_dev *input, unsigned int pos) 170 + { 171 + input_event(input, EV_MSC, MSC_SCAN, pos); 172 + input_report_key(input, KEY_FN, true); 173 + input_sync(input); 174 + 175 + input_event(input, EV_MSC, MSC_SCAN, pos); 176 + input_report_key(input, KEY_FN, false); 177 + } 178 + 179 + static void cros_ec_keyb_process_key_plain(struct cros_ec_keyb *ckdev, 180 + int row, int col, bool state) 181 + { 182 + struct input_dev *idev = ckdev->idev; 183 + const unsigned short *keycodes = idev->keycode; 184 + int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); 185 + 186 + input_event(idev, EV_MSC, MSC_SCAN, pos); 187 + input_report_key(idev, keycodes[pos], state); 188 + } 189 + 190 + static void cros_ec_keyb_process_key_fn_map(struct cros_ec_keyb *ckdev, 191 + int row, int col, bool state) 192 + { 193 + struct input_dev *idev = ckdev->idev; 194 + const unsigned short *keycodes = idev->keycode; 195 + unsigned int pos, fn_pos; 196 + unsigned int code, fn_code; 197 + 198 + pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); 199 + code = keycodes[pos]; 200 + 201 + if (code == KEY_FN) { 202 + ckdev->fn_active = state; 203 + if (state) { 204 + ckdev->fn_combo_active = false; 205 + } else if (!ckdev->fn_combo_active) { 206 + /* 207 + * Send both Fn press and release events if nothing 208 + * else has been pressed together with Fn. 209 + */ 210 + cros_ec_emit_fn_key(idev, pos); 211 + } 212 + return; 213 + } 214 + 215 + fn_pos = MATRIX_SCAN_CODE(row + ckdev->rows, col, ckdev->row_shift); 216 + fn_code = keycodes[fn_pos]; 217 + 218 + if (state) { 219 + if (ckdev->fn_active) { 220 + ckdev->fn_combo_active = true; 221 + if (!fn_code) 222 + return; /* Discard if no Fn mapping exists */ 223 + 224 + pos = fn_pos; 225 + code = fn_code; 226 + } 227 + } else { 228 + /* 229 + * If the Fn-remapped code is currently pressed, release it. 230 + * Otherwise, release the standard code (if it was pressed). 231 + */ 232 + if (fn_code && test_bit(fn_code, idev->key)) { 233 + pos = fn_pos; 234 + code = fn_code; 235 + } else if (!test_bit(code, idev->key)) { 236 + return; /* Discard, key press code was not sent */ 237 + } 238 + } 239 + 240 + input_event(idev, EV_MSC, MSC_SCAN, pos); 241 + input_report_key(idev, code, state); 242 + } 243 + 244 + static void cros_ec_keyb_process_col(struct cros_ec_keyb *ckdev, int col, 245 + u8 col_state, u8 changed) 246 + { 247 + for (int row = 0; row < ckdev->rows; row++) { 248 + if (changed & BIT(row)) { 249 + u8 key_state = col_state & BIT(row); 250 + 251 + dev_dbg(ckdev->dev, "changed: [r%d c%d]: byte %02x\n", 252 + row, col, key_state); 253 + 254 + if (ckdev->has_fn_map) 255 + cros_ec_keyb_process_key_fn_map(ckdev, row, col, 256 + key_state); 257 + else 258 + cros_ec_keyb_process_key_plain(ckdev, row, col, 259 + key_state); 260 + } 261 + } 262 + } 182 263 183 264 /* 184 265 * Compares the new keyboard state to the old one and produces key 185 - * press/release events accordingly. The keyboard state is 13 bytes (one byte 186 - * per column) 266 + * press/release events accordingly. The keyboard state is one byte 267 + * per column. 187 268 */ 188 - static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev, 189 - uint8_t *kb_state, int len) 269 + static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev, u8 *kb_state, int len) 190 270 { 191 - struct input_dev *idev = ckdev->idev; 192 - int col, row; 193 - int new_state; 194 - int old_state; 195 - 196 271 if (ckdev->ghost_filter && cros_ec_keyb_has_ghosting(ckdev, kb_state)) { 197 272 /* 198 273 * Simple-minded solution: ignore this state. The obvious ··· 291 190 return; 292 191 } 293 192 294 - for (col = 0; col < ckdev->cols; col++) { 295 - for (row = 0; row < ckdev->rows; row++) { 296 - int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); 297 - const unsigned short *keycodes = idev->keycode; 193 + for (int col = 0; col < ckdev->cols; col++) { 194 + u8 changed = kb_state[col] ^ ckdev->old_kb_state[col]; 298 195 299 - new_state = kb_state[col] & (1 << row); 300 - old_state = ckdev->old_kb_state[col] & (1 << row); 301 - if (new_state != old_state) { 302 - dev_dbg(ckdev->dev, 303 - "changed: [r%d c%d]: byte %02x\n", 304 - row, col, new_state); 305 - 306 - input_event(idev, EV_MSC, MSC_SCAN, pos); 307 - input_report_key(idev, keycodes[pos], 308 - new_state); 309 - } 310 - } 311 - ckdev->old_kb_state[col] = kb_state[col]; 196 + if (changed) 197 + cros_ec_keyb_process_col(ckdev, col, kb_state[col], 198 + changed); 312 199 } 200 + 201 + memcpy(ckdev->old_kb_state, kb_state, sizeof(ckdev->old_kb_state)); 313 202 input_sync(ckdev->idev); 314 203 } 315 204 ··· 337 246 { 338 247 struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb, 339 248 notifier); 340 - u32 val; 249 + struct ec_response_get_next_event_v3 *event_data; 250 + unsigned int event_size; 341 251 unsigned int ev_type; 252 + u32 val; 342 253 343 254 /* 344 255 * If not wake enabled, discard key state changes during ··· 350 257 if (queued_during_suspend && !device_may_wakeup(ckdev->dev)) 351 258 return NOTIFY_OK; 352 259 353 - switch (ckdev->ec->event_data.event_type) { 260 + event_data = &ckdev->ec->event_data; 261 + event_size = ckdev->ec->event_size; 262 + 263 + switch (event_data->event_type) { 354 264 case EC_MKBP_EVENT_KEY_MATRIX: 355 265 pm_wakeup_event(ckdev->dev, 0); 356 266 357 267 if (!ckdev->idev) { 358 - dev_warn_once(ckdev->dev, 359 - "Unexpected key matrix event\n"); 268 + dev_warn_once(ckdev->dev, "Unexpected key matrix event\n"); 360 269 return NOTIFY_OK; 361 270 } 362 271 363 - if (ckdev->ec->event_size != ckdev->cols) { 272 + if (event_size != ckdev->cols) { 364 273 dev_err(ckdev->dev, 365 274 "Discarded key matrix event, unexpected length: %d != %d\n", 366 275 ckdev->ec->event_size, ckdev->cols); 367 276 return NOTIFY_OK; 368 277 } 369 278 370 - cros_ec_keyb_process(ckdev, 371 - ckdev->ec->event_data.data.key_matrix, 372 - ckdev->ec->event_size); 279 + cros_ec_keyb_process(ckdev, event_data->data.key_matrix, event_size); 373 280 break; 374 281 375 282 case EC_MKBP_EVENT_SYSRQ: 376 283 pm_wakeup_event(ckdev->dev, 0); 377 284 378 - val = get_unaligned_le32(&ckdev->ec->event_data.data.sysrq); 285 + val = get_unaligned_le32(&event_data->data.sysrq); 379 286 dev_dbg(ckdev->dev, "sysrq code from EC: %#x\n", val); 380 287 handle_sysrq(val); 381 288 break; ··· 384 291 case EC_MKBP_EVENT_SWITCH: 385 292 pm_wakeup_event(ckdev->dev, 0); 386 293 387 - if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) { 388 - val = get_unaligned_le32( 389 - &ckdev->ec->event_data.data.buttons); 294 + if (event_data->event_type == EC_MKBP_EVENT_BUTTON) { 295 + val = get_unaligned_le32(&event_data->data.buttons); 390 296 ev_type = EV_KEY; 391 297 } else { 392 - val = get_unaligned_le32( 393 - &ckdev->ec->event_data.data.switches); 298 + val = get_unaligned_le32(&event_data->data.switches); 394 299 ev_type = EV_SW; 395 300 } 396 301 cros_ec_keyb_report_bs(ckdev, ev_type, val); ··· 417 326 for (col = 0; col < ckdev->cols; col++) { 418 327 for (row = 0; row < ckdev->rows; row++) { 419 328 code = keymap[MATRIX_SCAN_CODE(row, col, row_shift)]; 420 - if (code && (code != KEY_BATTERY)) 421 - ckdev->valid_keys[col] |= 1 << row; 329 + if (code != KEY_RESERVED && code != KEY_BATTERY) 330 + ckdev->valid_keys[col] |= BIT(row); 422 331 } 423 332 dev_dbg(ckdev->dev, "valid_keys[%02d] = 0x%02x\n", 424 333 col, ckdev->valid_keys[col]); ··· 674 583 ckdev->vdata.num_function_row_keys = n_physmap; 675 584 } 676 585 586 + /* Returns true if there is a KEY_FN code defined in the normal keymap */ 587 + static bool cros_ec_keyb_has_fn_key(struct cros_ec_keyb *ckdev) 588 + { 589 + const unsigned short *keycodes = ckdev->idev->keycode; 590 + int i; 591 + 592 + for (i = 0; i < MATRIX_SCAN_CODE(ckdev->rows, 0, ckdev->row_shift); i++) { 593 + if (keycodes[i] == KEY_FN) 594 + return true; 595 + } 596 + 597 + return false; 598 + } 599 + 600 + /* 601 + * Returns true if there is a KEY_FN defined and at least one key in the fn 602 + * layer keymap 603 + */ 604 + static bool cros_ec_keyb_has_fn_map(struct cros_ec_keyb *ckdev) 605 + { 606 + struct input_dev *idev = ckdev->idev; 607 + const unsigned short *keycodes = ckdev->idev->keycode; 608 + int i; 609 + 610 + if (!cros_ec_keyb_has_fn_key(ckdev)) 611 + return false; 612 + 613 + for (i = MATRIX_SCAN_CODE(ckdev->rows, 0, ckdev->row_shift); 614 + i < idev->keycodemax; i++) { 615 + if (keycodes[i] != KEY_RESERVED) 616 + return true; 617 + } 618 + 619 + return false; 620 + } 621 + 622 + /* 623 + * Custom handler for the set keycode ioctl, calls the default handler and 624 + * recomputes has_fn_map. 625 + */ 626 + static int cros_ec_keyb_setkeycode(struct input_dev *idev, 627 + const struct input_keymap_entry *ke, 628 + unsigned int *old_keycode) 629 + { 630 + struct cros_ec_keyb *ckdev = input_get_drvdata(idev); 631 + int ret; 632 + 633 + ret = input_default_setkeycode(idev, ke, old_keycode); 634 + if (ret) 635 + return ret; 636 + 637 + ckdev->has_fn_map = cros_ec_keyb_has_fn_map(ckdev); 638 + 639 + return 0; 640 + } 641 + 677 642 /** 678 643 * cros_ec_keyb_register_matrix - Register matrix keys 679 644 * ··· 751 604 if (err) 752 605 return err; 753 606 754 - ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL); 755 - if (!ckdev->valid_keys) 756 - return -ENOMEM; 757 - 758 - ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL); 759 - if (!ckdev->old_kb_state) 760 - return -ENOMEM; 607 + if (ckdev->cols > CROS_EC_KEYBOARD_COLS_MAX) { 608 + dev_err(dev, "keypad,num-columns too large: %d (max: %d)\n", 609 + ckdev->cols, CROS_EC_KEYBOARD_COLS_MAX); 610 + return -EINVAL; 611 + } 761 612 762 613 /* 763 614 * We call the keyboard matrix 'input0'. Allocate phys before input ··· 777 632 idev->id.version = 1; 778 633 idev->id.product = 0; 779 634 idev->dev.parent = dev; 635 + idev->setkeycode = cros_ec_keyb_setkeycode; 780 636 781 - ckdev->ghost_filter = device_property_read_bool(dev, 782 - "google,needs-ghost-filter"); 637 + ckdev->ghost_filter = device_property_read_bool(dev, "google,needs-ghost-filter"); 783 638 784 - err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols, 639 + err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows * 2, ckdev->cols, 785 640 NULL, idev); 786 641 if (err) { 787 642 dev_err(dev, "cannot build key matrix\n"); ··· 795 650 ckdev->idev = idev; 796 651 cros_ec_keyb_compute_valid_keys(ckdev); 797 652 cros_ec_keyb_parse_vivaldi_physmap(ckdev); 653 + 654 + ckdev->has_fn_map = cros_ec_keyb_has_fn_map(ckdev); 798 655 799 656 err = input_register_device(ckdev->idev); 800 657 if (err) {
+2 -2
drivers/input/keyboard/imx_keypad.c
··· 324 324 reg_val |= (keypad->cols_en_mask & 0xff) << 8; /* cols */ 325 325 writew(reg_val, keypad->mmio_base + KPCR); 326 326 327 - /* Write 0's to KPDR[15:8] (Colums) */ 327 + /* Write 0's to KPDR[15:8] (Columns) */ 328 328 reg_val = readw(keypad->mmio_base + KPDR); 329 329 reg_val &= 0x00ff; 330 330 writew(reg_val, keypad->mmio_base + KPDR); ··· 357 357 reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD; 358 358 writew(reg_val, keypad->mmio_base + KPSR); 359 359 360 - /* Colums as open drain and disable all rows */ 360 + /* Columns as open drain and disable all rows */ 361 361 reg_val = (keypad->cols_en_mask & 0xff) << 8; 362 362 writew(reg_val, keypad->mmio_base + KPCR); 363 363 }
-8
drivers/input/keyboard/mpr121_touchkey.c
··· 295 295 return error; 296 296 297 297 i2c_set_clientdata(client, mpr121); 298 - device_init_wakeup(dev, 299 - device_property_read_bool(dev, "wakeup-source")); 300 298 301 299 return 0; 302 300 } ··· 302 304 static int mpr_suspend(struct device *dev) 303 305 { 304 306 struct i2c_client *client = to_i2c_client(dev); 305 - 306 - if (device_may_wakeup(&client->dev)) 307 - enable_irq_wake(client->irq); 308 307 309 308 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 0x00); 310 309 ··· 312 317 { 313 318 struct i2c_client *client = to_i2c_client(dev); 314 319 struct mpr121_touchkey *mpr121 = i2c_get_clientdata(client); 315 - 316 - if (device_may_wakeup(&client->dev)) 317 - disable_irq_wake(client->irq); 318 320 319 321 i2c_smbus_write_byte_data(client, ELECTRODE_CONF_ADDR, 320 322 mpr121->keycount);
+1 -2
drivers/input/keyboard/qt1050.c
··· 435 435 int err; 436 436 437 437 /* Check basic functionality */ 438 - err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE); 439 - if (!err) { 438 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { 440 439 dev_err(&client->dev, "%s adapter not supported\n", 441 440 dev_driver_string(&client->adapter->dev)); 442 441 return -ENODEV;
+1 -2
drivers/input/keyboard/qt1070.c
··· 133 133 int i; 134 134 int err; 135 135 136 - err = i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE); 137 - if (!err) { 136 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { 138 137 dev_err(&client->dev, "%s adapter not supported\n", 139 138 dev_driver_string(&client->adapter->dev)); 140 139 return -ENODEV;
+1 -4
drivers/input/misc/adxl34x-i2c.c
··· 77 77 static int adxl34x_i2c_probe(struct i2c_client *client) 78 78 { 79 79 struct adxl34x *ac; 80 - int error; 81 80 82 - error = i2c_check_functionality(client->adapter, 83 - I2C_FUNC_SMBUS_BYTE_DATA); 84 - if (!error) { 81 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 85 82 dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); 86 83 return -EIO; 87 84 }
+12 -10
drivers/input/misc/atlas_btns.c
··· 14 14 #include <linux/input.h> 15 15 #include <linux/types.h> 16 16 #include <linux/acpi.h> 17 + #include <linux/platform_device.h> 17 18 #include <linux/uaccess.h> 18 19 19 20 #define ACPI_ATLAS_NAME "Atlas ACPI" ··· 58 57 return status; 59 58 } 60 59 61 - static int atlas_acpi_button_add(struct acpi_device *device) 60 + static int atlas_acpi_button_probe(struct platform_device *pdev) 62 61 { 62 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 63 63 acpi_status status; 64 64 int i; 65 65 int err; ··· 108 106 return err; 109 107 } 110 108 111 - static void atlas_acpi_button_remove(struct acpi_device *device) 109 + static void atlas_acpi_button_remove(struct platform_device *pdev) 112 110 { 111 + struct acpi_device *device = ACPI_COMPANION(&pdev->dev); 113 112 acpi_status status; 114 113 115 114 status = acpi_remove_address_space_handler(device->handle, ··· 127 124 }; 128 125 MODULE_DEVICE_TABLE(acpi, atlas_device_ids); 129 126 130 - static struct acpi_driver atlas_acpi_driver = { 131 - .name = ACPI_ATLAS_NAME, 132 - .class = ACPI_ATLAS_CLASS, 133 - .ids = atlas_device_ids, 134 - .ops = { 135 - .add = atlas_acpi_button_add, 136 - .remove = atlas_acpi_button_remove, 127 + static struct platform_driver atlas_acpi_driver = { 128 + .probe = atlas_acpi_button_probe, 129 + .remove = atlas_acpi_button_remove, 130 + .driver = { 131 + .name = ACPI_ATLAS_NAME, 132 + .acpi_match_table = atlas_device_ids, 137 133 }, 138 134 }; 139 - module_acpi_driver(atlas_acpi_driver); 135 + module_platform_driver(atlas_acpi_driver); 140 136 141 137 MODULE_AUTHOR("Jaya Kumar"); 142 138 MODULE_LICENSE("GPL");
+51 -15
drivers/input/misc/aw86927.c
··· 43 43 #define AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK GENMASK(6, 0) 44 44 #define AW86927_PLAYCFG1_BST_8500MV 0x50 45 45 46 + #define AW86938_PLAYCFG1_REG 0x06 47 + #define AW86938_PLAYCFG1_BST_MODE_MASK GENMASK(5, 5) 48 + #define AW86938_PLAYCFG1_BST_MODE_BYPASS 0 49 + #define AW86938_PLAYCFG1_BST_VOUT_VREFSET_MASK GENMASK(4, 0) 50 + #define AW86938_PLAYCFG1_BST_7000MV 0x11 51 + 46 52 #define AW86927_PLAYCFG2_REG 0x07 47 53 48 54 #define AW86927_PLAYCFG3_REG 0x08 ··· 146 140 #define AW86927_CHIPIDH_REG 0x57 147 141 #define AW86927_CHIPIDL_REG 0x58 148 142 #define AW86927_CHIPID 0x9270 143 + #define AW86938_CHIPID 0x9380 149 144 150 145 #define AW86927_TMCFG_REG 0x5b 151 146 #define AW86927_TMCFG_UNLOCK 0x7d ··· 180 173 AW86927_RAM_MODE, 181 174 }; 182 175 176 + enum aw86927_model { 177 + AW86927, 178 + AW86938, 179 + }; 180 + 183 181 struct aw86927_data { 182 + enum aw86927_model model; 184 183 struct work_struct play_work; 185 184 struct device *dev; 186 185 struct input_dev *input_dev; 187 186 struct i2c_client *client; 188 187 struct regmap *regmap; 189 188 struct gpio_desc *reset_gpio; 190 - bool running; 189 + u16 level; 191 190 }; 192 191 193 192 static const struct regmap_config aw86927_regmap_config = { ··· 338 325 if (!level) 339 326 level = effect->u.rumble.weak_magnitude; 340 327 341 - /* If already running, don't restart playback */ 342 - if (haptics->running && level) 328 + /* If level does not change, don't restart playback */ 329 + if (haptics->level == level) 343 330 return 0; 344 331 345 - haptics->running = level; 332 + haptics->level = level; 333 + 346 334 schedule_work(&haptics->play_work); 347 335 348 336 return 0; ··· 390 376 if (err) 391 377 return err; 392 378 393 - /* set gain to value lower than 0x80 to avoid distorted playback */ 394 - err = regmap_write(haptics->regmap, AW86927_PLAYCFG2_REG, 0x7c); 379 + err = regmap_write(haptics->regmap, AW86927_PLAYCFG2_REG, haptics->level * 0x80 / 0xffff); 395 380 if (err) 396 381 return err; 397 382 ··· 422 409 struct device *dev = &haptics->client->dev; 423 410 int err; 424 411 425 - if (haptics->running) 412 + if (haptics->level) 426 413 err = aw86927_play_sine(haptics); 427 414 else 428 415 err = aw86927_stop(haptics); ··· 578 565 if (err) 579 566 return err; 580 567 581 - err = regmap_update_bits(haptics->regmap, 582 - AW86927_PLAYCFG1_REG, 583 - AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 584 - FIELD_PREP(AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 585 - AW86927_PLAYCFG1_BST_8500MV)); 586 - if (err) 587 - return err; 568 + switch (haptics->model) { 569 + case AW86927: 570 + err = regmap_update_bits(haptics->regmap, 571 + AW86927_PLAYCFG1_REG, 572 + AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 573 + FIELD_PREP(AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 574 + AW86927_PLAYCFG1_BST_8500MV)); 575 + if (err) 576 + return err; 577 + break; 578 + case AW86938: 579 + err = regmap_update_bits(haptics->regmap, 580 + AW86938_PLAYCFG1_REG, 581 + AW86938_PLAYCFG1_BST_VOUT_VREFSET_MASK, 582 + FIELD_PREP(AW86938_PLAYCFG1_BST_VOUT_VREFSET_MASK, 583 + AW86938_PLAYCFG1_BST_7000MV)); 584 + if (err) 585 + return err; 586 + break; 587 + } 588 588 589 589 err = regmap_update_bits(haptics->regmap, 590 590 AW86927_PLAYCFG3_REG, ··· 624 598 AW86927_SYSCTRL3_EN_RAMINIT_MASK, 625 599 FIELD_PREP(AW86927_SYSCTRL3_EN_RAMINIT_MASK, 626 600 AW86927_SYSCTRL3_EN_RAMINIT_ON)); 601 + 602 + /* AW86938 wants a 1ms delay here */ 603 + usleep_range(1000, 1500); 627 604 628 605 /* Set base address for the start of the SRAM waveforms */ 629 606 err = regmap_write(haptics->regmap, ··· 746 717 747 718 chip_id = be16_to_cpu(read_buf); 748 719 749 - if (chip_id != AW86927_CHIPID) { 720 + switch (chip_id) { 721 + case AW86927_CHIPID: 722 + haptics->model = AW86927; 723 + break; 724 + case AW86938_CHIPID: 725 + haptics->model = AW86938; 726 + break; 727 + default: 750 728 dev_err(haptics->dev, "Unexpected CHIPID value 0x%x\n", chip_id); 751 729 return -ENODEV; 752 730 }
+47 -3
drivers/input/misc/drv260x.c
··· 7 7 * Copyright: (C) 2014 Texas Instruments, Inc. 8 8 */ 9 9 10 + #include <linux/acpi.h> 11 + #include <linux/delay.h> 12 + #include <linux/device/devres.h> 13 + #include <linux/gpio/consumer.h> 10 14 #include <linux/i2c.h> 11 15 #include <linux/input.h> 12 16 #include <linux/module.h> 13 17 #include <linux/regmap.h> 14 - #include <linux/slab.h> 15 - #include <linux/delay.h> 16 - #include <linux/gpio/consumer.h> 17 18 #include <linux/regulator/consumer.h> 19 + #include <linux/slab.h> 18 20 19 21 #include <dt-bindings/input/ti-drv260x.h> 20 22 ··· 167 165 #define DRV260X_AUTOCAL_TIME_500MS (2 << 4) 168 166 #define DRV260X_AUTOCAL_TIME_1000MS (3 << 4) 169 167 168 + /* 169 + * Timeout for waiting for the GO status bit, in seconds. Should be reasonably 170 + * large to wait for a auto-calibration cycle completion. 171 + */ 172 + #define DRV260X_GO_TIMEOUT_S 5 173 + 170 174 /** 171 175 * struct drv260x_data - 172 176 * @input_dev: Pointer to the input device ··· 316 308 { 317 309 int error; 318 310 unsigned int cal_buf; 311 + unsigned long timeout; 319 312 320 313 error = regmap_write(haptics->regmap, 321 314 DRV260X_RATED_VOLT, haptics->rated_voltage); ··· 406 397 return error; 407 398 } 408 399 400 + timeout = jiffies + DRV260X_GO_TIMEOUT_S * HZ; 409 401 do { 410 402 usleep_range(15000, 15500); 411 403 error = regmap_read(haptics->regmap, DRV260X_GO, &cal_buf); ··· 415 405 "Failed to read GO register: %d\n", 416 406 error); 417 407 return error; 408 + } 409 + if (time_after(jiffies, timeout)) { 410 + dev_err(&haptics->client->dev, 411 + "Calibration timeout. The device cannot be used.\n"); 412 + return -ETIMEDOUT; 418 413 } 419 414 } while (cal_buf == DRV260X_GO_BIT); 420 415 ··· 433 418 .max_register = DRV260X_MAX_REG, 434 419 .cache_type = REGCACHE_NONE, 435 420 }; 421 + 422 + static void drv260x_power_off(void *data) 423 + { 424 + struct drv260x_data *haptics = data; 425 + 426 + regulator_disable(haptics->regulator); 427 + } 436 428 437 429 static int drv260x_probe(struct i2c_client *client) 438 430 { ··· 505 483 dev_err(dev, "unable to get regulator, error: %d\n", error); 506 484 return error; 507 485 } 486 + 487 + error = regulator_enable(haptics->regulator); 488 + if (error) { 489 + dev_err(dev, "Failed to enable regulator: %d\n", error); 490 + return error; 491 + } 492 + 493 + error = devm_add_action_or_reset(dev, drv260x_power_off, haptics); 494 + if (error) 495 + return error; 508 496 509 497 haptics->enable_gpio = devm_gpiod_get_optional(dev, "enable", 510 498 GPIOD_OUT_HIGH); ··· 630 598 static DEFINE_SIMPLE_DEV_PM_OPS(drv260x_pm_ops, drv260x_suspend, drv260x_resume); 631 599 632 600 static const struct i2c_device_id drv260x_id[] = { 601 + { "drv2604" }, 602 + { "drv2604l" }, 603 + { "drv2605" }, 633 604 { "drv2605l" }, 634 605 { } 635 606 }; 636 607 MODULE_DEVICE_TABLE(i2c, drv260x_id); 608 + 609 + #ifdef CONFIG_ACPI 610 + static const struct acpi_device_id drv260x_acpi_match[] = { 611 + { "DRV2604" }, 612 + { } 613 + }; 614 + MODULE_DEVICE_TABLE(acpi, drv260x_acpi_match); 615 + #endif 637 616 638 617 static const struct of_device_id drv260x_of_match[] = { 639 618 { .compatible = "ti,drv2604", }, ··· 659 616 .probe = drv260x_probe, 660 617 .driver = { 661 618 .name = "drv260x-haptics", 619 + .acpi_match_table = ACPI_PTR(drv260x_acpi_match), 662 620 .of_match_table = drv260x_of_match, 663 621 .pm = pm_sleep_ptr(&drv260x_pm_ops), 664 622 },
+26 -6
drivers/input/misc/ims-pcu.c
··· 438 438 } 439 439 } 440 440 441 + static void ims_pcu_reset_packet(struct ims_pcu *pcu) 442 + { 443 + pcu->have_stx = true; 444 + pcu->have_dle = false; 445 + pcu->read_pos = 0; 446 + pcu->check_sum = 0; 447 + } 448 + 441 449 static void ims_pcu_process_data(struct ims_pcu *pcu, struct urb *urb) 442 450 { 443 451 int i; ··· 458 450 continue; 459 451 460 452 if (pcu->have_dle) { 453 + if (pcu->read_pos >= IMS_PCU_BUF_SIZE) { 454 + dev_warn(pcu->dev, 455 + "Packet too long (%d bytes), discarding\n", 456 + pcu->read_pos); 457 + ims_pcu_reset_packet(pcu); 458 + continue; 459 + } 460 + 461 461 pcu->have_dle = false; 462 462 pcu->read_buf[pcu->read_pos++] = data; 463 463 pcu->check_sum += data; ··· 478 462 dev_warn(pcu->dev, 479 463 "Unexpected STX at byte %d, discarding old data\n", 480 464 pcu->read_pos); 465 + ims_pcu_reset_packet(pcu); 481 466 pcu->have_stx = true; 482 - pcu->have_dle = false; 483 - pcu->read_pos = 0; 484 - pcu->check_sum = 0; 485 467 break; 486 468 487 469 case IMS_PCU_PROTOCOL_DLE: ··· 499 485 ims_pcu_handle_response(pcu); 500 486 } 501 487 502 - pcu->have_stx = false; 503 - pcu->have_dle = false; 504 - pcu->read_pos = 0; 488 + ims_pcu_reset_packet(pcu); 505 489 break; 506 490 507 491 default: 492 + if (pcu->read_pos >= IMS_PCU_BUF_SIZE) { 493 + dev_warn(pcu->dev, 494 + "Packet too long (%d bytes), discarding\n", 495 + pcu->read_pos); 496 + ims_pcu_reset_packet(pcu); 497 + continue; 498 + } 499 + 508 500 pcu->read_buf[pcu->read_pos++] = data; 509 501 pcu->check_sum += data; 510 502 break;
+2 -20
drivers/input/misc/keyspan_remote.c
··· 420 420 usb_kill_urb(remote->irq_urb); 421 421 } 422 422 423 - static struct usb_endpoint_descriptor *keyspan_get_in_endpoint(struct usb_host_interface *iface) 424 - { 425 - 426 - struct usb_endpoint_descriptor *endpoint; 427 - int i; 428 - 429 - for (i = 0; i < iface->desc.bNumEndpoints; ++i) { 430 - endpoint = &iface->endpoint[i].desc; 431 - 432 - if (usb_endpoint_is_int_in(endpoint)) { 433 - /* we found our interrupt in endpoint */ 434 - return endpoint; 435 - } 436 - } 437 - 438 - return NULL; 439 - } 440 - 441 423 /* 442 424 * Routine that sets up the driver to handle a specific USB device detected on the bus. 443 425 */ ··· 431 449 struct input_dev *input_dev; 432 450 int i, error; 433 451 434 - endpoint = keyspan_get_in_endpoint(interface->cur_altsetting); 435 - if (!endpoint) 452 + error = usb_find_int_in_endpoint(interface->cur_altsetting, &endpoint); 453 + if (error) 436 454 return -ENODEV; 437 455 438 456 remote = kzalloc_obj(*remote);
-36
drivers/input/mouse/Kconfig
··· 164 164 165 165 If unsure, say N. 166 166 167 - config MOUSE_PS2_OLPC 168 - bool "OLPC PS/2 mouse protocol extension" 169 - depends on MOUSE_PS2 && OLPC 170 - help 171 - Say Y here if you have an OLPC XO-1 laptop (with built-in 172 - PS/2 touchpad/tablet device). The manufacturer calls the 173 - touchpad an HGPK. 174 - 175 - If unsure, say N. 176 - 177 167 config MOUSE_PS2_FOCALTECH 178 168 bool "FocalTech PS/2 mouse protocol extension" if EXPERT 179 169 default y ··· 289 299 a SMbus adapter. 290 300 291 301 If unsure, say Y. 292 - 293 - config MOUSE_INPORT 294 - tristate "InPort/MS/ATIXL busmouse" 295 - depends on ISA 296 - help 297 - Say Y here if you have an InPort, Microsoft or ATI XL busmouse. 298 - They are rather rare these days. 299 - 300 - To compile this driver as a module, choose M here: the 301 - module will be called inport. 302 - 303 - config MOUSE_ATIXL 304 - bool "ATI XL variant" 305 - depends on MOUSE_INPORT 306 - help 307 - Say Y here if your mouse is of the ATI XL variety. 308 - 309 - config MOUSE_LOGIBM 310 - tristate "Logitech busmouse" 311 - depends on ISA 312 - help 313 - Say Y here if you have a Logitech busmouse. 314 - They are rather rare these days. 315 - 316 - To compile this driver as a module, choose M here: the 317 - module will be called logibm. 318 302 319 303 config MOUSE_AMIGA 320 304 tristate "Amiga mouse"
-3
drivers/input/mouse/Makefile
··· 12 12 obj-$(CONFIG_MOUSE_CYAPA) += cyapatp.o 13 13 obj-$(CONFIG_MOUSE_ELAN_I2C) += elan_i2c.o 14 14 obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o 15 - obj-$(CONFIG_MOUSE_INPORT) += inport.o 16 - obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o 17 15 obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o 18 16 obj-$(CONFIG_MOUSE_PS2) += psmouse.o 19 17 obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o ··· 26 28 psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o 27 29 psmouse-$(CONFIG_MOUSE_PS2_BYD) += byd.o 28 30 psmouse-$(CONFIG_MOUSE_PS2_ELANTECH) += elantech.o 29 - psmouse-$(CONFIG_MOUSE_PS2_OLPC) += hgpk.o 30 31 psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o 31 32 psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o 32 33 psmouse-$(CONFIG_MOUSE_PS2_SENTELIC) += sentelic.o
+5 -6
drivers/input/mouse/alps.c
··· 12 12 * tpconfig utility (by C. Scott Ananian and Bruce Kall). 13 13 */ 14 14 15 + #include "linux/workqueue.h" 15 16 #include <linux/slab.h> 16 17 #include <linux/input.h> 17 18 #include <linux/input/mt.h> ··· 1453 1452 static void alps_register_bare_ps2_mouse(struct work_struct *work) 1454 1453 { 1455 1454 struct alps_data *priv = container_of(work, struct alps_data, 1456 - dev3_register_work.work); 1455 + dev3_register_work); 1457 1456 int error; 1458 1457 1459 1458 guard(mutex)(&alps_mutex); ··· 1486 1485 } else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) { 1487 1486 /* Register dev3 mouse if we received PS/2 packet first time */ 1488 1487 if (!IS_ERR(priv->dev3)) 1489 - psmouse_queue_work(psmouse, &priv->dev3_register_work, 1490 - 0); 1488 + schedule_work(&priv->dev3_register_work); 1491 1489 return; 1492 1490 } else { 1493 1491 dev = priv->dev3; ··· 2975 2975 2976 2976 psmouse_reset(psmouse); 2977 2977 timer_shutdown_sync(&priv->timer); 2978 - disable_delayed_work_sync(&priv->dev3_register_work); 2978 + disable_work_sync(&priv->dev3_register_work); 2979 2979 if (priv->dev2) 2980 2980 input_unregister_device(priv->dev2); 2981 2981 if (!IS_ERR_OR_NULL(priv->dev3)) ··· 3147 3147 3148 3148 priv->psmouse = psmouse; 3149 3149 3150 - INIT_DELAYED_WORK(&priv->dev3_register_work, 3151 - alps_register_bare_ps2_mouse); 3150 + INIT_WORK(&priv->dev3_register_work, alps_register_bare_ps2_mouse); 3152 3151 3153 3152 psmouse->protocol_handler = alps_process_byte; 3154 3153 psmouse->poll = alps_poll;
+2 -2
drivers/input/mouse/alps.h
··· 257 257 * @dev3: Generic PS/2 mouse (can be NULL, delayed registering). 258 258 * @phys2: Physical path for the trackstick device. 259 259 * @phys3: Physical path for the generic PS/2 mouse. 260 - * @dev3_register_work: Delayed work for registering PS/2 mouse. 260 + * @dev3_register_work: A work instance for registering PS/2 mouse. 261 261 * @nibble_commands: Command mapping used for touchpad register accesses. 262 262 * @addr_command: Command used to tell the touchpad that a register address 263 263 * follows. ··· 289 289 struct input_dev *dev3; 290 290 char phys2[32]; 291 291 char phys3[32]; 292 - struct delayed_work dev3_register_work; 292 + struct work_struct dev3_register_work; 293 293 294 294 /* these are autodetected when the device is identified */ 295 295 const struct alps_nibble_commands *nibble_commands;
+6 -15
drivers/input/mouse/appletouch.c
··· 829 829 struct atp *dev; 830 830 struct input_dev *input_dev; 831 831 struct usb_device *udev = interface_to_usbdev(iface); 832 - struct usb_host_interface *iface_desc; 833 - struct usb_endpoint_descriptor *endpoint; 834 - int int_in_endpointAddr = 0; 835 - int i, error = -ENOMEM; 832 + struct usb_endpoint_descriptor *ep; 833 + int error; 836 834 const struct atp_info *info = (const struct atp_info *)id->driver_info; 837 835 838 836 /* set up the endpoint information */ 839 837 /* use only the first interrupt-in endpoint */ 840 - iface_desc = iface->cur_altsetting; 841 - for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 842 - endpoint = &iface_desc->endpoint[i].desc; 843 - if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) { 844 - /* we found an interrupt in endpoint */ 845 - int_in_endpointAddr = endpoint->bEndpointAddress; 846 - break; 847 - } 848 - } 849 - if (!int_in_endpointAddr) { 838 + error = usb_find_int_in_endpoint(iface->cur_altsetting, &ep); 839 + if (error) { 850 840 dev_err(&iface->dev, "Could not find int-in endpoint\n"); 851 841 return -EIO; 852 842 } 853 843 854 844 /* allocate memory for our device state and initialize it */ 845 + error = -ENOMEM; 855 846 dev = kzalloc_obj(*dev); 856 847 input_dev = input_allocate_device(); 857 848 if (!dev || !input_dev) { ··· 866 875 goto err_free_urb; 867 876 868 877 usb_fill_int_urb(dev->urb, udev, 869 - usb_rcvintpipe(udev, int_in_endpointAddr), 878 + usb_rcvintpipe(udev, usb_endpoint_num(ep)), 870 879 dev->data, dev->info->datalen, 871 880 dev->info->callback, dev, 1); 872 881
-1063
drivers/input/mouse/hgpk.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * OLPC HGPK (XO-1) touchpad PS/2 mouse driver 4 - * 5 - * Copyright (c) 2006-2008 One Laptop Per Child 6 - * Authors: 7 - * Zephaniah E. Hull 8 - * Andres Salomon <dilinger@debian.org> 9 - * 10 - * This driver is partly based on the ALPS driver, which is: 11 - * 12 - * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> 13 - * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com> 14 - * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> 15 - * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> 16 - */ 17 - 18 - /* 19 - * The spec from ALPS is available from 20 - * <http://wiki.laptop.org/go/Touch_Pad/Tablet>. It refers to this 21 - * device as HGPK (Hybrid GS, PT, and Keymatrix). 22 - * 23 - * The earliest versions of the device had simultaneous reporting; that 24 - * was removed. After that, the device used the Advanced Mode GS/PT streaming 25 - * stuff. That turned out to be too buggy to support, so we've finally 26 - * switched to Mouse Mode (which utilizes only the center 1/3 of the touchpad). 27 - */ 28 - 29 - #define DEBUG 30 - #include <linux/slab.h> 31 - #include <linux/input.h> 32 - #include <linux/module.h> 33 - #include <linux/serio.h> 34 - #include <linux/libps2.h> 35 - #include <linux/delay.h> 36 - #include <asm/olpc.h> 37 - 38 - #include "psmouse.h" 39 - #include "hgpk.h" 40 - 41 - #define ILLEGAL_XY 999999 42 - 43 - static bool tpdebug; 44 - module_param(tpdebug, bool, 0644); 45 - MODULE_PARM_DESC(tpdebug, "enable debugging, dumping packets to KERN_DEBUG."); 46 - 47 - static int recalib_delta = 100; 48 - module_param(recalib_delta, int, 0644); 49 - MODULE_PARM_DESC(recalib_delta, 50 - "packets containing a delta this large will be discarded, and a " 51 - "recalibration may be scheduled."); 52 - 53 - static int jumpy_delay = 20; 54 - module_param(jumpy_delay, int, 0644); 55 - MODULE_PARM_DESC(jumpy_delay, 56 - "delay (ms) before recal after jumpiness detected"); 57 - 58 - static int spew_delay = 1; 59 - module_param(spew_delay, int, 0644); 60 - MODULE_PARM_DESC(spew_delay, 61 - "delay (ms) before recal after packet spew detected"); 62 - 63 - static int recal_guard_time; 64 - module_param(recal_guard_time, int, 0644); 65 - MODULE_PARM_DESC(recal_guard_time, 66 - "interval (ms) during which recal will be restarted if packet received"); 67 - 68 - static int post_interrupt_delay = 40; 69 - module_param(post_interrupt_delay, int, 0644); 70 - MODULE_PARM_DESC(post_interrupt_delay, 71 - "delay (ms) before recal after recal interrupt detected"); 72 - 73 - static bool autorecal = true; 74 - module_param(autorecal, bool, 0644); 75 - MODULE_PARM_DESC(autorecal, "enable recalibration in the driver"); 76 - 77 - static char hgpk_mode_name[16]; 78 - module_param_string(hgpk_mode, hgpk_mode_name, sizeof(hgpk_mode_name), 0644); 79 - MODULE_PARM_DESC(hgpk_mode, 80 - "default hgpk mode: mouse, glidesensor or pentablet"); 81 - 82 - static int hgpk_default_mode = HGPK_MODE_MOUSE; 83 - 84 - static const char * const hgpk_mode_names[] = { 85 - [HGPK_MODE_MOUSE] = "Mouse", 86 - [HGPK_MODE_GLIDESENSOR] = "GlideSensor", 87 - [HGPK_MODE_PENTABLET] = "PenTablet", 88 - }; 89 - 90 - static int hgpk_mode_from_name(const char *buf, int len) 91 - { 92 - int i; 93 - 94 - for (i = 0; i < ARRAY_SIZE(hgpk_mode_names); i++) { 95 - const char *name = hgpk_mode_names[i]; 96 - if (strlen(name) == len && !strncasecmp(name, buf, len)) 97 - return i; 98 - } 99 - 100 - return HGPK_MODE_INVALID; 101 - } 102 - 103 - /* 104 - * see if new value is within 20% of half of old value 105 - */ 106 - static int approx_half(int curr, int prev) 107 - { 108 - int belowhalf, abovehalf; 109 - 110 - if (curr < 5 || prev < 5) 111 - return 0; 112 - 113 - belowhalf = (prev * 8) / 20; 114 - abovehalf = (prev * 12) / 20; 115 - 116 - return belowhalf < curr && curr <= abovehalf; 117 - } 118 - 119 - /* 120 - * Throw out oddly large delta packets, and any that immediately follow whose 121 - * values are each approximately half of the previous. It seems that the ALPS 122 - * firmware emits errant packets, and they get averaged out slowly. 123 - */ 124 - static int hgpk_discard_decay_hack(struct psmouse *psmouse, int x, int y) 125 - { 126 - struct hgpk_data *priv = psmouse->private; 127 - int avx, avy; 128 - bool do_recal = false; 129 - 130 - avx = abs(x); 131 - avy = abs(y); 132 - 133 - /* discard if too big, or half that but > 4 times the prev delta */ 134 - if (avx > recalib_delta || 135 - (avx > recalib_delta / 2 && ((avx / 4) > priv->xlast))) { 136 - psmouse_warn(psmouse, "detected %dpx jump in x\n", x); 137 - priv->xbigj = avx; 138 - } else if (approx_half(avx, priv->xbigj)) { 139 - psmouse_warn(psmouse, "detected secondary %dpx jump in x\n", x); 140 - priv->xbigj = avx; 141 - priv->xsaw_secondary++; 142 - } else { 143 - if (priv->xbigj && priv->xsaw_secondary > 1) 144 - do_recal = true; 145 - priv->xbigj = 0; 146 - priv->xsaw_secondary = 0; 147 - } 148 - 149 - if (avy > recalib_delta || 150 - (avy > recalib_delta / 2 && ((avy / 4) > priv->ylast))) { 151 - psmouse_warn(psmouse, "detected %dpx jump in y\n", y); 152 - priv->ybigj = avy; 153 - } else if (approx_half(avy, priv->ybigj)) { 154 - psmouse_warn(psmouse, "detected secondary %dpx jump in y\n", y); 155 - priv->ybigj = avy; 156 - priv->ysaw_secondary++; 157 - } else { 158 - if (priv->ybigj && priv->ysaw_secondary > 1) 159 - do_recal = true; 160 - priv->ybigj = 0; 161 - priv->ysaw_secondary = 0; 162 - } 163 - 164 - priv->xlast = avx; 165 - priv->ylast = avy; 166 - 167 - if (do_recal && jumpy_delay) { 168 - psmouse_warn(psmouse, "scheduling recalibration\n"); 169 - psmouse_queue_work(psmouse, &priv->recalib_wq, 170 - msecs_to_jiffies(jumpy_delay)); 171 - } 172 - 173 - return priv->xbigj || priv->ybigj; 174 - } 175 - 176 - static void hgpk_reset_spew_detection(struct hgpk_data *priv) 177 - { 178 - priv->spew_count = 0; 179 - priv->dupe_count = 0; 180 - priv->x_tally = 0; 181 - priv->y_tally = 0; 182 - priv->spew_flag = NO_SPEW; 183 - } 184 - 185 - static void hgpk_reset_hack_state(struct psmouse *psmouse) 186 - { 187 - struct hgpk_data *priv = psmouse->private; 188 - 189 - priv->abs_x = priv->abs_y = -1; 190 - priv->xlast = priv->ylast = ILLEGAL_XY; 191 - priv->xbigj = priv->ybigj = 0; 192 - priv->xsaw_secondary = priv->ysaw_secondary = 0; 193 - hgpk_reset_spew_detection(priv); 194 - } 195 - 196 - /* 197 - * We have no idea why this particular hardware bug occurs. The touchpad 198 - * will randomly start spewing packets without anything touching the 199 - * pad. This wouldn't necessarily be bad, but it's indicative of a 200 - * severely miscalibrated pad; attempting to use the touchpad while it's 201 - * spewing means the cursor will jump all over the place, and act "drunk". 202 - * 203 - * The packets that are spewed tend to all have deltas between -2 and 2, and 204 - * the cursor will move around without really going very far. It will 205 - * tend to end up in the same location; if we tally up the changes over 206 - * 100 packets, we end up w/ a final delta of close to 0. This happens 207 - * pretty regularly when the touchpad is spewing, and is pretty hard to 208 - * manually trigger (at least for *my* fingers). So, it makes a perfect 209 - * scheme for detecting spews. 210 - */ 211 - static void hgpk_spewing_hack(struct psmouse *psmouse, 212 - int l, int r, int x, int y) 213 - { 214 - struct hgpk_data *priv = psmouse->private; 215 - 216 - /* ignore button press packets; many in a row could trigger 217 - * a false-positive! */ 218 - if (l || r) 219 - return; 220 - 221 - /* don't track spew if the workaround feature has been turned off */ 222 - if (!spew_delay) 223 - return; 224 - 225 - if (abs(x) > 3 || abs(y) > 3) { 226 - /* no spew, or spew ended */ 227 - hgpk_reset_spew_detection(priv); 228 - return; 229 - } 230 - 231 - /* Keep a tally of the overall delta to the cursor position caused by 232 - * the spew */ 233 - priv->x_tally += x; 234 - priv->y_tally += y; 235 - 236 - switch (priv->spew_flag) { 237 - case NO_SPEW: 238 - /* we're not spewing, but this packet might be the start */ 239 - priv->spew_flag = MAYBE_SPEWING; 240 - 241 - fallthrough; 242 - 243 - case MAYBE_SPEWING: 244 - priv->spew_count++; 245 - 246 - if (priv->spew_count < SPEW_WATCH_COUNT) 247 - break; 248 - 249 - /* excessive spew detected, request recalibration */ 250 - priv->spew_flag = SPEW_DETECTED; 251 - 252 - fallthrough; 253 - 254 - case SPEW_DETECTED: 255 - /* only recalibrate when the overall delta to the cursor 256 - * is really small. if the spew is causing significant cursor 257 - * movement, it is probably a case of the user moving the 258 - * cursor very slowly across the screen. */ 259 - if (abs(priv->x_tally) < 3 && abs(priv->y_tally) < 3) { 260 - psmouse_warn(psmouse, "packet spew detected (%d,%d)\n", 261 - priv->x_tally, priv->y_tally); 262 - priv->spew_flag = RECALIBRATING; 263 - psmouse_queue_work(psmouse, &priv->recalib_wq, 264 - msecs_to_jiffies(spew_delay)); 265 - } 266 - 267 - break; 268 - case RECALIBRATING: 269 - /* we already detected a spew and requested a recalibration, 270 - * just wait for the queue to kick into action. */ 271 - break; 272 - } 273 - } 274 - 275 - /* 276 - * HGPK Mouse Mode format (standard mouse format, sans middle button) 277 - * 278 - * byte 0: y-over x-over y-neg x-neg 1 0 swr swl 279 - * byte 1: x7 x6 x5 x4 x3 x2 x1 x0 280 - * byte 2: y7 y6 y5 y4 y3 y2 y1 y0 281 - * 282 - * swr/swl are the left/right buttons. 283 - * x-neg/y-neg are the x and y delta negative bits 284 - * x-over/y-over are the x and y overflow bits 285 - * 286 - * --- 287 - * 288 - * HGPK Advanced Mode - single-mode format 289 - * 290 - * byte 0(PT): 1 1 0 0 1 1 1 1 291 - * byte 0(GS): 1 1 1 1 1 1 1 1 292 - * byte 1: 0 x6 x5 x4 x3 x2 x1 x0 293 - * byte 2(PT): 0 0 x9 x8 x7 ? pt-dsw 0 294 - * byte 2(GS): 0 x10 x9 x8 x7 ? gs-dsw pt-dsw 295 - * byte 3: 0 y9 y8 y7 1 0 swr swl 296 - * byte 4: 0 y6 y5 y4 y3 y2 y1 y0 297 - * byte 5: 0 z6 z5 z4 z3 z2 z1 z0 298 - * 299 - * ?'s are not defined in the protocol spec, may vary between models. 300 - * 301 - * swr/swl are the left/right buttons. 302 - * 303 - * pt-dsw/gs-dsw indicate that the pt/gs sensor is detecting a 304 - * pen/finger 305 - */ 306 - static bool hgpk_is_byte_valid(struct psmouse *psmouse, unsigned char *packet) 307 - { 308 - struct hgpk_data *priv = psmouse->private; 309 - int pktcnt = psmouse->pktcnt; 310 - bool valid; 311 - 312 - switch (priv->mode) { 313 - case HGPK_MODE_MOUSE: 314 - valid = (packet[0] & 0x0C) == 0x08; 315 - break; 316 - 317 - case HGPK_MODE_GLIDESENSOR: 318 - valid = pktcnt == 1 ? 319 - packet[0] == HGPK_GS : !(packet[pktcnt - 1] & 0x80); 320 - break; 321 - 322 - case HGPK_MODE_PENTABLET: 323 - valid = pktcnt == 1 ? 324 - packet[0] == HGPK_PT : !(packet[pktcnt - 1] & 0x80); 325 - break; 326 - 327 - default: 328 - valid = false; 329 - break; 330 - } 331 - 332 - if (!valid) 333 - psmouse_dbg(psmouse, 334 - "bad data, mode %d (%d) %*ph\n", 335 - priv->mode, pktcnt, 6, psmouse->packet); 336 - 337 - return valid; 338 - } 339 - 340 - static void hgpk_process_advanced_packet(struct psmouse *psmouse) 341 - { 342 - struct hgpk_data *priv = psmouse->private; 343 - struct input_dev *idev = psmouse->dev; 344 - unsigned char *packet = psmouse->packet; 345 - int down = !!(packet[2] & 2); 346 - int left = !!(packet[3] & 1); 347 - int right = !!(packet[3] & 2); 348 - int x = packet[1] | ((packet[2] & 0x78) << 4); 349 - int y = packet[4] | ((packet[3] & 0x70) << 3); 350 - 351 - if (priv->mode == HGPK_MODE_GLIDESENSOR) { 352 - int pt_down = !!(packet[2] & 1); 353 - int finger_down = !!(packet[2] & 2); 354 - int z = packet[5]; 355 - 356 - input_report_abs(idev, ABS_PRESSURE, z); 357 - if (tpdebug) 358 - psmouse_dbg(psmouse, "pd=%d fd=%d z=%d", 359 - pt_down, finger_down, z); 360 - } else { 361 - /* 362 - * PenTablet mode does not report pressure, so we don't 363 - * report it here 364 - */ 365 - if (tpdebug) 366 - psmouse_dbg(psmouse, "pd=%d ", down); 367 - } 368 - 369 - if (tpdebug) 370 - psmouse_dbg(psmouse, "l=%d r=%d x=%d y=%d\n", 371 - left, right, x, y); 372 - 373 - input_report_key(idev, BTN_TOUCH, down); 374 - input_report_key(idev, BTN_LEFT, left); 375 - input_report_key(idev, BTN_RIGHT, right); 376 - 377 - /* 378 - * If this packet says that the finger was removed, reset our position 379 - * tracking so that we don't erroneously detect a jump on next press. 380 - */ 381 - if (!down) { 382 - hgpk_reset_hack_state(psmouse); 383 - goto done; 384 - } 385 - 386 - /* 387 - * Weed out duplicate packets (we get quite a few, and they mess up 388 - * our jump detection) 389 - */ 390 - if (x == priv->abs_x && y == priv->abs_y) { 391 - if (++priv->dupe_count > SPEW_WATCH_COUNT) { 392 - if (tpdebug) 393 - psmouse_dbg(psmouse, "hard spew detected\n"); 394 - priv->spew_flag = RECALIBRATING; 395 - psmouse_queue_work(psmouse, &priv->recalib_wq, 396 - msecs_to_jiffies(spew_delay)); 397 - } 398 - goto done; 399 - } 400 - 401 - /* not a duplicate, continue with position reporting */ 402 - priv->dupe_count = 0; 403 - 404 - /* Don't apply hacks in PT mode, it seems reliable */ 405 - if (priv->mode != HGPK_MODE_PENTABLET && priv->abs_x != -1) { 406 - int x_diff = priv->abs_x - x; 407 - int y_diff = priv->abs_y - y; 408 - if (hgpk_discard_decay_hack(psmouse, x_diff, y_diff)) { 409 - if (tpdebug) 410 - psmouse_dbg(psmouse, "discarding\n"); 411 - goto done; 412 - } 413 - hgpk_spewing_hack(psmouse, left, right, x_diff, y_diff); 414 - } 415 - 416 - input_report_abs(idev, ABS_X, x); 417 - input_report_abs(idev, ABS_Y, y); 418 - priv->abs_x = x; 419 - priv->abs_y = y; 420 - 421 - done: 422 - input_sync(idev); 423 - } 424 - 425 - static void hgpk_process_simple_packet(struct psmouse *psmouse) 426 - { 427 - struct input_dev *dev = psmouse->dev; 428 - unsigned char *packet = psmouse->packet; 429 - int left = packet[0] & 1; 430 - int right = (packet[0] >> 1) & 1; 431 - int x = packet[1] - ((packet[0] << 4) & 0x100); 432 - int y = ((packet[0] << 3) & 0x100) - packet[2]; 433 - 434 - if (packet[0] & 0xc0) 435 - psmouse_dbg(psmouse, 436 - "overflow -- 0x%02x 0x%02x 0x%02x\n", 437 - packet[0], packet[1], packet[2]); 438 - 439 - if (hgpk_discard_decay_hack(psmouse, x, y)) { 440 - if (tpdebug) 441 - psmouse_dbg(psmouse, "discarding\n"); 442 - return; 443 - } 444 - 445 - hgpk_spewing_hack(psmouse, left, right, x, y); 446 - 447 - if (tpdebug) 448 - psmouse_dbg(psmouse, "l=%d r=%d x=%d y=%d\n", 449 - left, right, x, y); 450 - 451 - input_report_key(dev, BTN_LEFT, left); 452 - input_report_key(dev, BTN_RIGHT, right); 453 - 454 - input_report_rel(dev, REL_X, x); 455 - input_report_rel(dev, REL_Y, y); 456 - 457 - input_sync(dev); 458 - } 459 - 460 - static psmouse_ret_t hgpk_process_byte(struct psmouse *psmouse) 461 - { 462 - struct hgpk_data *priv = psmouse->private; 463 - 464 - if (!hgpk_is_byte_valid(psmouse, psmouse->packet)) 465 - return PSMOUSE_BAD_DATA; 466 - 467 - if (psmouse->pktcnt >= psmouse->pktsize) { 468 - if (priv->mode == HGPK_MODE_MOUSE) 469 - hgpk_process_simple_packet(psmouse); 470 - else 471 - hgpk_process_advanced_packet(psmouse); 472 - return PSMOUSE_FULL_PACKET; 473 - } 474 - 475 - if (priv->recalib_window) { 476 - if (time_before(jiffies, priv->recalib_window)) { 477 - /* 478 - * ugh, got a packet inside our recalibration 479 - * window, schedule another recalibration. 480 - */ 481 - psmouse_dbg(psmouse, 482 - "packet inside calibration window, queueing another recalibration\n"); 483 - psmouse_queue_work(psmouse, &priv->recalib_wq, 484 - msecs_to_jiffies(post_interrupt_delay)); 485 - } 486 - priv->recalib_window = 0; 487 - } 488 - 489 - return PSMOUSE_GOOD_DATA; 490 - } 491 - 492 - static int hgpk_select_mode(struct psmouse *psmouse) 493 - { 494 - struct ps2dev *ps2dev = &psmouse->ps2dev; 495 - struct hgpk_data *priv = psmouse->private; 496 - int i; 497 - int cmd; 498 - 499 - /* 500 - * 4 disables to enable advanced mode 501 - * then 3 0xf2 bytes as the preamble for GS/PT selection 502 - */ 503 - const int advanced_init[] = { 504 - PSMOUSE_CMD_DISABLE, PSMOUSE_CMD_DISABLE, 505 - PSMOUSE_CMD_DISABLE, PSMOUSE_CMD_DISABLE, 506 - 0xf2, 0xf2, 0xf2, 507 - }; 508 - 509 - switch (priv->mode) { 510 - case HGPK_MODE_MOUSE: 511 - psmouse->pktsize = 3; 512 - break; 513 - 514 - case HGPK_MODE_GLIDESENSOR: 515 - case HGPK_MODE_PENTABLET: 516 - psmouse->pktsize = 6; 517 - 518 - /* Switch to 'Advanced mode.', four disables in a row. */ 519 - for (i = 0; i < ARRAY_SIZE(advanced_init); i++) 520 - if (ps2_command(ps2dev, NULL, advanced_init[i])) 521 - return -EIO; 522 - 523 - /* select between GlideSensor (mouse) or PenTablet */ 524 - cmd = priv->mode == HGPK_MODE_GLIDESENSOR ? 525 - PSMOUSE_CMD_SETSCALE11 : PSMOUSE_CMD_SETSCALE21; 526 - 527 - if (ps2_command(ps2dev, NULL, cmd)) 528 - return -EIO; 529 - break; 530 - 531 - default: 532 - return -EINVAL; 533 - } 534 - 535 - return 0; 536 - } 537 - 538 - static void hgpk_setup_input_device(struct input_dev *input, 539 - struct input_dev *old_input, 540 - enum hgpk_mode mode) 541 - { 542 - if (old_input) { 543 - input->name = old_input->name; 544 - input->phys = old_input->phys; 545 - input->id = old_input->id; 546 - input->dev.parent = old_input->dev.parent; 547 - } 548 - 549 - memset(input->evbit, 0, sizeof(input->evbit)); 550 - memset(input->relbit, 0, sizeof(input->relbit)); 551 - memset(input->keybit, 0, sizeof(input->keybit)); 552 - 553 - /* All modes report left and right buttons */ 554 - __set_bit(EV_KEY, input->evbit); 555 - __set_bit(BTN_LEFT, input->keybit); 556 - __set_bit(BTN_RIGHT, input->keybit); 557 - 558 - switch (mode) { 559 - case HGPK_MODE_MOUSE: 560 - __set_bit(EV_REL, input->evbit); 561 - __set_bit(REL_X, input->relbit); 562 - __set_bit(REL_Y, input->relbit); 563 - break; 564 - 565 - case HGPK_MODE_GLIDESENSOR: 566 - __set_bit(BTN_TOUCH, input->keybit); 567 - __set_bit(BTN_TOOL_FINGER, input->keybit); 568 - 569 - __set_bit(EV_ABS, input->evbit); 570 - 571 - /* GlideSensor has pressure sensor, PenTablet does not */ 572 - input_set_abs_params(input, ABS_PRESSURE, 0, 15, 0, 0); 573 - 574 - /* From device specs */ 575 - input_set_abs_params(input, ABS_X, 0, 399, 0, 0); 576 - input_set_abs_params(input, ABS_Y, 0, 290, 0, 0); 577 - 578 - /* Calculated by hand based on usable size (52mm x 38mm) */ 579 - input_abs_set_res(input, ABS_X, 8); 580 - input_abs_set_res(input, ABS_Y, 8); 581 - break; 582 - 583 - case HGPK_MODE_PENTABLET: 584 - __set_bit(BTN_TOUCH, input->keybit); 585 - __set_bit(BTN_TOOL_FINGER, input->keybit); 586 - 587 - __set_bit(EV_ABS, input->evbit); 588 - 589 - /* From device specs */ 590 - input_set_abs_params(input, ABS_X, 0, 999, 0, 0); 591 - input_set_abs_params(input, ABS_Y, 5, 239, 0, 0); 592 - 593 - /* Calculated by hand based on usable size (156mm x 38mm) */ 594 - input_abs_set_res(input, ABS_X, 6); 595 - input_abs_set_res(input, ABS_Y, 8); 596 - break; 597 - 598 - default: 599 - BUG(); 600 - } 601 - } 602 - 603 - static int hgpk_reset_device(struct psmouse *psmouse, bool recalibrate) 604 - { 605 - int err; 606 - 607 - psmouse_reset(psmouse); 608 - 609 - if (recalibrate) { 610 - struct ps2dev *ps2dev = &psmouse->ps2dev; 611 - 612 - /* send the recalibrate request */ 613 - if (ps2_command(ps2dev, NULL, 0xf5) || 614 - ps2_command(ps2dev, NULL, 0xf5) || 615 - ps2_command(ps2dev, NULL, 0xe6) || 616 - ps2_command(ps2dev, NULL, 0xf5)) { 617 - return -1; 618 - } 619 - 620 - /* according to ALPS, 150mS is required for recalibration */ 621 - msleep(150); 622 - } 623 - 624 - err = hgpk_select_mode(psmouse); 625 - if (err) { 626 - psmouse_err(psmouse, "failed to select mode\n"); 627 - return err; 628 - } 629 - 630 - hgpk_reset_hack_state(psmouse); 631 - 632 - return 0; 633 - } 634 - 635 - static int hgpk_force_recalibrate(struct psmouse *psmouse) 636 - { 637 - struct hgpk_data *priv = psmouse->private; 638 - int err; 639 - 640 - /* C-series touchpads added the recalibrate command */ 641 - if (psmouse->model < HGPK_MODEL_C) 642 - return 0; 643 - 644 - if (!autorecal) { 645 - psmouse_dbg(psmouse, "recalibration disabled, ignoring\n"); 646 - return 0; 647 - } 648 - 649 - psmouse_dbg(psmouse, "recalibrating touchpad..\n"); 650 - 651 - /* we don't want to race with the irq handler, nor with resyncs */ 652 - psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 653 - 654 - /* start by resetting the device */ 655 - err = hgpk_reset_device(psmouse, true); 656 - if (err) 657 - return err; 658 - 659 - /* 660 - * XXX: If a finger is down during this delay, recalibration will 661 - * detect capacitance incorrectly. This is a hardware bug, and 662 - * we don't have a good way to deal with it. The 2s window stuff 663 - * (below) is our best option for now. 664 - */ 665 - if (psmouse_activate(psmouse)) 666 - return -1; 667 - 668 - if (tpdebug) 669 - psmouse_dbg(psmouse, "touchpad reactivated\n"); 670 - 671 - /* 672 - * If we get packets right away after recalibrating, it's likely 673 - * that a finger was on the touchpad. If so, it's probably 674 - * miscalibrated, so we optionally schedule another. 675 - */ 676 - if (recal_guard_time) 677 - priv->recalib_window = jiffies + 678 - msecs_to_jiffies(recal_guard_time); 679 - 680 - return 0; 681 - } 682 - 683 - /* 684 - * This puts the touchpad in a power saving mode; according to ALPS, current 685 - * consumption goes down to 50uA after running this. To turn power back on, 686 - * we drive MS-DAT low. Measuring with a 1mA resolution ammeter says that 687 - * the current on the SUS_3.3V rail drops from 3mA or 4mA to 0 when we do this. 688 - * 689 - * We have no formal spec that details this operation -- the low-power 690 - * sequence came from a long-lost email trail. 691 - */ 692 - static int hgpk_toggle_powersave(struct psmouse *psmouse, int enable) 693 - { 694 - struct ps2dev *ps2dev = &psmouse->ps2dev; 695 - int timeo; 696 - int err; 697 - 698 - /* Added on D-series touchpads */ 699 - if (psmouse->model < HGPK_MODEL_D) 700 - return 0; 701 - 702 - if (enable) { 703 - psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 704 - 705 - /* 706 - * Sending a byte will drive MS-DAT low; this will wake up 707 - * the controller. Once we get an ACK back from it, it 708 - * means we can continue with the touchpad re-init. ALPS 709 - * tells us that 1s should be long enough, so set that as 710 - * the upper bound. (in practice, it takes about 3 loops.) 711 - */ 712 - for (timeo = 20; timeo > 0; timeo--) { 713 - if (!ps2_sendbyte(ps2dev, PSMOUSE_CMD_DISABLE, 20)) 714 - break; 715 - msleep(25); 716 - } 717 - 718 - err = hgpk_reset_device(psmouse, false); 719 - if (err) { 720 - psmouse_err(psmouse, "Failed to reset device!\n"); 721 - return err; 722 - } 723 - 724 - /* should be all set, enable the touchpad */ 725 - psmouse_activate(psmouse); 726 - psmouse_dbg(psmouse, "Touchpad powered up.\n"); 727 - } else { 728 - psmouse_dbg(psmouse, "Powering off touchpad.\n"); 729 - 730 - if (ps2_command(ps2dev, NULL, 0xec) || 731 - ps2_command(ps2dev, NULL, 0xec) || 732 - ps2_command(ps2dev, NULL, 0xea)) { 733 - return -1; 734 - } 735 - 736 - psmouse_set_state(psmouse, PSMOUSE_IGNORE); 737 - 738 - /* probably won't see an ACK, the touchpad will be off */ 739 - ps2_sendbyte(ps2dev, 0xec, 20); 740 - } 741 - 742 - return 0; 743 - } 744 - 745 - static int hgpk_poll(struct psmouse *psmouse) 746 - { 747 - /* We can't poll, so always return failure. */ 748 - return -1; 749 - } 750 - 751 - static int hgpk_reconnect(struct psmouse *psmouse) 752 - { 753 - struct hgpk_data *priv = psmouse->private; 754 - 755 - /* 756 - * During suspend/resume the ps2 rails remain powered. We don't want 757 - * to do a reset because it's flush data out of buffers; however, 758 - * earlier prototypes (B1) had some brokenness that required a reset. 759 - */ 760 - if (olpc_board_at_least(olpc_board(0xb2))) 761 - if (psmouse->ps2dev.serio->dev.power.power_state.event != 762 - PM_EVENT_ON) 763 - return 0; 764 - 765 - priv->powered = 1; 766 - return hgpk_reset_device(psmouse, false); 767 - } 768 - 769 - static ssize_t hgpk_show_powered(struct psmouse *psmouse, void *data, char *buf) 770 - { 771 - struct hgpk_data *priv = psmouse->private; 772 - 773 - return sprintf(buf, "%d\n", priv->powered); 774 - } 775 - 776 - static ssize_t hgpk_set_powered(struct psmouse *psmouse, void *data, 777 - const char *buf, size_t count) 778 - { 779 - struct hgpk_data *priv = psmouse->private; 780 - unsigned int value; 781 - int err; 782 - 783 - err = kstrtouint(buf, 10, &value); 784 - if (err) 785 - return err; 786 - 787 - if (value > 1) 788 - return -EINVAL; 789 - 790 - if (value != priv->powered) { 791 - /* 792 - * hgpk_toggle_power will deal w/ state so 793 - * we're not racing w/ irq 794 - */ 795 - err = hgpk_toggle_powersave(psmouse, value); 796 - if (!err) 797 - priv->powered = value; 798 - } 799 - 800 - return err ? err : count; 801 - } 802 - 803 - __PSMOUSE_DEFINE_ATTR(powered, S_IWUSR | S_IRUGO, NULL, 804 - hgpk_show_powered, hgpk_set_powered, false); 805 - 806 - static ssize_t attr_show_mode(struct psmouse *psmouse, void *data, char *buf) 807 - { 808 - struct hgpk_data *priv = psmouse->private; 809 - 810 - return sprintf(buf, "%s\n", hgpk_mode_names[priv->mode]); 811 - } 812 - 813 - static ssize_t attr_set_mode(struct psmouse *psmouse, void *data, 814 - const char *buf, size_t len) 815 - { 816 - struct hgpk_data *priv = psmouse->private; 817 - enum hgpk_mode old_mode = priv->mode; 818 - enum hgpk_mode new_mode = hgpk_mode_from_name(buf, len); 819 - struct input_dev *old_dev = psmouse->dev; 820 - struct input_dev *new_dev; 821 - int err; 822 - 823 - if (new_mode == HGPK_MODE_INVALID) 824 - return -EINVAL; 825 - 826 - if (old_mode == new_mode) 827 - return len; 828 - 829 - new_dev = input_allocate_device(); 830 - if (!new_dev) 831 - return -ENOMEM; 832 - 833 - psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 834 - 835 - /* Switch device into the new mode */ 836 - priv->mode = new_mode; 837 - err = hgpk_reset_device(psmouse, false); 838 - if (err) 839 - goto err_try_restore; 840 - 841 - hgpk_setup_input_device(new_dev, old_dev, new_mode); 842 - 843 - psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 844 - 845 - err = input_register_device(new_dev); 846 - if (err) 847 - goto err_try_restore; 848 - 849 - psmouse->dev = new_dev; 850 - input_unregister_device(old_dev); 851 - 852 - return len; 853 - 854 - err_try_restore: 855 - input_free_device(new_dev); 856 - priv->mode = old_mode; 857 - hgpk_reset_device(psmouse, false); 858 - 859 - return err; 860 - } 861 - 862 - PSMOUSE_DEFINE_ATTR(hgpk_mode, S_IWUSR | S_IRUGO, NULL, 863 - attr_show_mode, attr_set_mode); 864 - 865 - static ssize_t hgpk_trigger_recal_show(struct psmouse *psmouse, 866 - void *data, char *buf) 867 - { 868 - return -EINVAL; 869 - } 870 - 871 - static ssize_t hgpk_trigger_recal(struct psmouse *psmouse, void *data, 872 - const char *buf, size_t count) 873 - { 874 - struct hgpk_data *priv = psmouse->private; 875 - unsigned int value; 876 - int err; 877 - 878 - err = kstrtouint(buf, 10, &value); 879 - if (err) 880 - return err; 881 - 882 - if (value != 1) 883 - return -EINVAL; 884 - 885 - /* 886 - * We queue work instead of doing recalibration right here 887 - * to avoid adding locking to hgpk_force_recalibrate() 888 - * since workqueue provides serialization. 889 - */ 890 - psmouse_queue_work(psmouse, &priv->recalib_wq, 0); 891 - return count; 892 - } 893 - 894 - __PSMOUSE_DEFINE_ATTR(recalibrate, S_IWUSR | S_IRUGO, NULL, 895 - hgpk_trigger_recal_show, hgpk_trigger_recal, false); 896 - 897 - static void hgpk_disconnect(struct psmouse *psmouse) 898 - { 899 - struct hgpk_data *priv = psmouse->private; 900 - 901 - device_remove_file(&psmouse->ps2dev.serio->dev, 902 - &psmouse_attr_powered.dattr); 903 - device_remove_file(&psmouse->ps2dev.serio->dev, 904 - &psmouse_attr_hgpk_mode.dattr); 905 - 906 - if (psmouse->model >= HGPK_MODEL_C) 907 - device_remove_file(&psmouse->ps2dev.serio->dev, 908 - &psmouse_attr_recalibrate.dattr); 909 - 910 - psmouse_reset(psmouse); 911 - kfree(priv); 912 - } 913 - 914 - static void hgpk_recalib_work(struct work_struct *work) 915 - { 916 - struct delayed_work *w = to_delayed_work(work); 917 - struct hgpk_data *priv = container_of(w, struct hgpk_data, recalib_wq); 918 - struct psmouse *psmouse = priv->psmouse; 919 - 920 - if (hgpk_force_recalibrate(psmouse)) 921 - psmouse_err(psmouse, "recalibration failed!\n"); 922 - } 923 - 924 - static int hgpk_register(struct psmouse *psmouse) 925 - { 926 - struct hgpk_data *priv = psmouse->private; 927 - int err; 928 - 929 - /* register handlers */ 930 - psmouse->protocol_handler = hgpk_process_byte; 931 - psmouse->poll = hgpk_poll; 932 - psmouse->disconnect = hgpk_disconnect; 933 - psmouse->reconnect = hgpk_reconnect; 934 - 935 - /* Disable the idle resync. */ 936 - psmouse->resync_time = 0; 937 - /* Reset after a lot of bad bytes. */ 938 - psmouse->resetafter = 1024; 939 - 940 - hgpk_setup_input_device(psmouse->dev, NULL, priv->mode); 941 - 942 - err = device_create_file(&psmouse->ps2dev.serio->dev, 943 - &psmouse_attr_powered.dattr); 944 - if (err) { 945 - psmouse_err(psmouse, "Failed creating 'powered' sysfs node\n"); 946 - return err; 947 - } 948 - 949 - err = device_create_file(&psmouse->ps2dev.serio->dev, 950 - &psmouse_attr_hgpk_mode.dattr); 951 - if (err) { 952 - psmouse_err(psmouse, 953 - "Failed creating 'hgpk_mode' sysfs node\n"); 954 - goto err_remove_powered; 955 - } 956 - 957 - /* C-series touchpads added the recalibrate command */ 958 - if (psmouse->model >= HGPK_MODEL_C) { 959 - err = device_create_file(&psmouse->ps2dev.serio->dev, 960 - &psmouse_attr_recalibrate.dattr); 961 - if (err) { 962 - psmouse_err(psmouse, 963 - "Failed creating 'recalibrate' sysfs node\n"); 964 - goto err_remove_mode; 965 - } 966 - } 967 - 968 - return 0; 969 - 970 - err_remove_mode: 971 - device_remove_file(&psmouse->ps2dev.serio->dev, 972 - &psmouse_attr_hgpk_mode.dattr); 973 - err_remove_powered: 974 - device_remove_file(&psmouse->ps2dev.serio->dev, 975 - &psmouse_attr_powered.dattr); 976 - return err; 977 - } 978 - 979 - int hgpk_init(struct psmouse *psmouse) 980 - { 981 - struct hgpk_data *priv; 982 - int err; 983 - 984 - priv = kzalloc_obj(*priv); 985 - if (!priv) { 986 - err = -ENOMEM; 987 - goto alloc_fail; 988 - } 989 - 990 - psmouse->private = priv; 991 - 992 - priv->psmouse = psmouse; 993 - priv->powered = true; 994 - priv->mode = hgpk_default_mode; 995 - INIT_DELAYED_WORK(&priv->recalib_wq, hgpk_recalib_work); 996 - 997 - err = hgpk_reset_device(psmouse, false); 998 - if (err) 999 - goto init_fail; 1000 - 1001 - err = hgpk_register(psmouse); 1002 - if (err) 1003 - goto init_fail; 1004 - 1005 - return 0; 1006 - 1007 - init_fail: 1008 - kfree(priv); 1009 - alloc_fail: 1010 - return err; 1011 - } 1012 - 1013 - static enum hgpk_model_t hgpk_get_model(struct psmouse *psmouse) 1014 - { 1015 - struct ps2dev *ps2dev = &psmouse->ps2dev; 1016 - unsigned char param[3]; 1017 - 1018 - /* E7, E7, E7, E9 gets us a 3 byte identifier */ 1019 - if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || 1020 - ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || 1021 - ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) || 1022 - ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) { 1023 - return -EIO; 1024 - } 1025 - 1026 - psmouse_dbg(psmouse, "ID: %*ph\n", 3, param); 1027 - 1028 - /* HGPK signature: 0x67, 0x00, 0x<model> */ 1029 - if (param[0] != 0x67 || param[1] != 0x00) 1030 - return -ENODEV; 1031 - 1032 - psmouse_info(psmouse, "OLPC touchpad revision 0x%x\n", param[2]); 1033 - 1034 - return param[2]; 1035 - } 1036 - 1037 - int hgpk_detect(struct psmouse *psmouse, bool set_properties) 1038 - { 1039 - int version; 1040 - 1041 - version = hgpk_get_model(psmouse); 1042 - if (version < 0) 1043 - return version; 1044 - 1045 - if (set_properties) { 1046 - psmouse->vendor = "ALPS"; 1047 - psmouse->name = "HGPK"; 1048 - psmouse->model = version; 1049 - } 1050 - 1051 - return 0; 1052 - } 1053 - 1054 - void hgpk_module_init(void) 1055 - { 1056 - hgpk_default_mode = hgpk_mode_from_name(hgpk_mode_name, 1057 - strlen(hgpk_mode_name)); 1058 - if (hgpk_default_mode == HGPK_MODE_INVALID) { 1059 - hgpk_default_mode = HGPK_MODE_MOUSE; 1060 - strscpy(hgpk_mode_name, hgpk_mode_names[HGPK_MODE_MOUSE], 1061 - sizeof(hgpk_mode_name)); 1062 - } 1063 - }
-61
drivers/input/mouse/hgpk.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * OLPC HGPK (XO-1) touchpad PS/2 mouse driver 4 - */ 5 - 6 - #ifndef _HGPK_H 7 - #define _HGPK_H 8 - 9 - #define HGPK_GS 0xff /* The GlideSensor */ 10 - #define HGPK_PT 0xcf /* The PenTablet */ 11 - 12 - enum hgpk_model_t { 13 - HGPK_MODEL_PREA = 0x0a, /* pre-B1s */ 14 - HGPK_MODEL_A = 0x14, /* found on B1s, PT disabled in hardware */ 15 - HGPK_MODEL_B = 0x28, /* B2s, has capacitance issues */ 16 - HGPK_MODEL_C = 0x3c, 17 - HGPK_MODEL_D = 0x50, /* C1, mass production */ 18 - }; 19 - 20 - enum hgpk_spew_flag { 21 - NO_SPEW, 22 - MAYBE_SPEWING, 23 - SPEW_DETECTED, 24 - RECALIBRATING, 25 - }; 26 - 27 - #define SPEW_WATCH_COUNT 42 /* at 12ms/packet, this is 1/2 second */ 28 - 29 - enum hgpk_mode { 30 - HGPK_MODE_MOUSE, 31 - HGPK_MODE_GLIDESENSOR, 32 - HGPK_MODE_PENTABLET, 33 - HGPK_MODE_INVALID 34 - }; 35 - 36 - struct hgpk_data { 37 - struct psmouse *psmouse; 38 - enum hgpk_mode mode; 39 - bool powered; 40 - enum hgpk_spew_flag spew_flag; 41 - int spew_count, x_tally, y_tally; /* spew detection */ 42 - unsigned long recalib_window; 43 - struct delayed_work recalib_wq; 44 - int abs_x, abs_y; 45 - int dupe_count; 46 - int xbigj, ybigj, xlast, ylast; /* jumpiness detection */ 47 - int xsaw_secondary, ysaw_secondary; /* jumpiness detection */ 48 - }; 49 - 50 - int hgpk_detect(struct psmouse *psmouse, bool set_properties); 51 - int hgpk_init(struct psmouse *psmouse); 52 - 53 - #ifdef CONFIG_MOUSE_PS2_OLPC 54 - void hgpk_module_init(void); 55 - #else 56 - static inline void hgpk_module_init(void) 57 - { 58 - } 59 - #endif 60 - 61 - #endif
-177
drivers/input/mouse/inport.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (c) 1999-2001 Vojtech Pavlik 4 - * 5 - * Based on the work of: 6 - * Teemu Rantanen Derrick Cole 7 - * Peter Cervasio Christoph Niemann 8 - * Philip Blundell Russell King 9 - * Bob Harris 10 - */ 11 - 12 - /* 13 - * Inport (ATI XL and Microsoft) busmouse driver for Linux 14 - */ 15 - 16 - #include <linux/module.h> 17 - #include <linux/ioport.h> 18 - #include <linux/init.h> 19 - #include <linux/interrupt.h> 20 - #include <linux/input.h> 21 - 22 - #include <asm/io.h> 23 - #include <asm/irq.h> 24 - 25 - MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 26 - MODULE_DESCRIPTION("Inport (ATI XL and Microsoft) busmouse driver"); 27 - MODULE_LICENSE("GPL"); 28 - 29 - #define INPORT_BASE 0x23c 30 - #define INPORT_EXTENT 4 31 - 32 - #define INPORT_CONTROL_PORT INPORT_BASE + 0 33 - #define INPORT_DATA_PORT INPORT_BASE + 1 34 - #define INPORT_SIGNATURE_PORT INPORT_BASE + 2 35 - 36 - #define INPORT_REG_BTNS 0x00 37 - #define INPORT_REG_X 0x01 38 - #define INPORT_REG_Y 0x02 39 - #define INPORT_REG_MODE 0x07 40 - #define INPORT_RESET 0x80 41 - 42 - #ifdef CONFIG_MOUSE_ATIXL 43 - #define INPORT_NAME "ATI XL Mouse" 44 - #define INPORT_VENDOR 0x0002 45 - #define INPORT_SPEED_30HZ 0x01 46 - #define INPORT_SPEED_50HZ 0x02 47 - #define INPORT_SPEED_100HZ 0x03 48 - #define INPORT_SPEED_200HZ 0x04 49 - #define INPORT_MODE_BASE INPORT_SPEED_100HZ 50 - #define INPORT_MODE_IRQ 0x08 51 - #else 52 - #define INPORT_NAME "Microsoft InPort Mouse" 53 - #define INPORT_VENDOR 0x0001 54 - #define INPORT_MODE_BASE 0x10 55 - #define INPORT_MODE_IRQ 0x01 56 - #endif 57 - #define INPORT_MODE_HOLD 0x20 58 - 59 - #define INPORT_IRQ 5 60 - 61 - static int inport_irq = INPORT_IRQ; 62 - module_param_hw_named(irq, inport_irq, uint, irq, 0); 63 - MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 64 - 65 - static struct input_dev *inport_dev; 66 - 67 - static irqreturn_t inport_interrupt(int irq, void *dev_id) 68 - { 69 - unsigned char buttons; 70 - 71 - outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 72 - outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 73 - 74 - outb(INPORT_REG_X, INPORT_CONTROL_PORT); 75 - input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT)); 76 - 77 - outb(INPORT_REG_Y, INPORT_CONTROL_PORT); 78 - input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT)); 79 - 80 - outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); 81 - buttons = inb(INPORT_DATA_PORT); 82 - 83 - input_report_key(inport_dev, BTN_MIDDLE, buttons & 1); 84 - input_report_key(inport_dev, BTN_LEFT, buttons & 2); 85 - input_report_key(inport_dev, BTN_RIGHT, buttons & 4); 86 - 87 - outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 88 - outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 89 - 90 - input_sync(inport_dev); 91 - return IRQ_HANDLED; 92 - } 93 - 94 - static int inport_open(struct input_dev *dev) 95 - { 96 - if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL)) 97 - return -EBUSY; 98 - outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 99 - outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 100 - 101 - return 0; 102 - } 103 - 104 - static void inport_close(struct input_dev *dev) 105 - { 106 - outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 107 - outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 108 - free_irq(inport_irq, NULL); 109 - } 110 - 111 - static int __init inport_init(void) 112 - { 113 - unsigned char a, b, c; 114 - int err; 115 - 116 - if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 117 - printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 118 - return -EBUSY; 119 - } 120 - 121 - a = inb(INPORT_SIGNATURE_PORT); 122 - b = inb(INPORT_SIGNATURE_PORT); 123 - c = inb(INPORT_SIGNATURE_PORT); 124 - if (a == b || a != c) { 125 - printk(KERN_INFO "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); 126 - err = -ENODEV; 127 - goto err_release_region; 128 - } 129 - 130 - inport_dev = input_allocate_device(); 131 - if (!inport_dev) { 132 - printk(KERN_ERR "inport.c: Not enough memory for input device\n"); 133 - err = -ENOMEM; 134 - goto err_release_region; 135 - } 136 - 137 - inport_dev->name = INPORT_NAME; 138 - inport_dev->phys = "isa023c/input0"; 139 - inport_dev->id.bustype = BUS_ISA; 140 - inport_dev->id.vendor = INPORT_VENDOR; 141 - inport_dev->id.product = 0x0001; 142 - inport_dev->id.version = 0x0100; 143 - 144 - inport_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 145 - inport_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | 146 - BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 147 - inport_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 148 - 149 - inport_dev->open = inport_open; 150 - inport_dev->close = inport_close; 151 - 152 - outb(INPORT_RESET, INPORT_CONTROL_PORT); 153 - outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 154 - outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 155 - 156 - err = input_register_device(inport_dev); 157 - if (err) 158 - goto err_free_dev; 159 - 160 - return 0; 161 - 162 - err_free_dev: 163 - input_free_device(inport_dev); 164 - err_release_region: 165 - release_region(INPORT_BASE, INPORT_EXTENT); 166 - 167 - return err; 168 - } 169 - 170 - static void __exit inport_exit(void) 171 - { 172 - input_unregister_device(inport_dev); 173 - release_region(INPORT_BASE, INPORT_EXTENT); 174 - } 175 - 176 - module_init(inport_init); 177 - module_exit(inport_exit);
-166
drivers/input/mouse/logibm.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (c) 1999-2001 Vojtech Pavlik 4 - * 5 - * Based on the work of: 6 - * James Banks Matthew Dillon 7 - * David Giller Nathan Laredo 8 - * Linus Torvalds Johan Myreen 9 - * Cliff Matthews Philip Blundell 10 - * Russell King 11 - */ 12 - 13 - /* 14 - * Logitech Bus Mouse Driver for Linux 15 - */ 16 - 17 - #include <linux/module.h> 18 - #include <linux/delay.h> 19 - #include <linux/ioport.h> 20 - #include <linux/init.h> 21 - #include <linux/input.h> 22 - #include <linux/interrupt.h> 23 - 24 - #include <asm/io.h> 25 - #include <asm/irq.h> 26 - 27 - MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 28 - MODULE_DESCRIPTION("Logitech busmouse driver"); 29 - MODULE_LICENSE("GPL"); 30 - 31 - #define LOGIBM_BASE 0x23c 32 - #define LOGIBM_EXTENT 4 33 - 34 - #define LOGIBM_DATA_PORT LOGIBM_BASE + 0 35 - #define LOGIBM_SIGNATURE_PORT LOGIBM_BASE + 1 36 - #define LOGIBM_CONTROL_PORT LOGIBM_BASE + 2 37 - #define LOGIBM_CONFIG_PORT LOGIBM_BASE + 3 38 - 39 - #define LOGIBM_ENABLE_IRQ 0x00 40 - #define LOGIBM_DISABLE_IRQ 0x10 41 - #define LOGIBM_READ_X_LOW 0x80 42 - #define LOGIBM_READ_X_HIGH 0xa0 43 - #define LOGIBM_READ_Y_LOW 0xc0 44 - #define LOGIBM_READ_Y_HIGH 0xe0 45 - 46 - #define LOGIBM_DEFAULT_MODE 0x90 47 - #define LOGIBM_CONFIG_BYTE 0x91 48 - #define LOGIBM_SIGNATURE_BYTE 0xa5 49 - 50 - #define LOGIBM_IRQ 5 51 - 52 - static int logibm_irq = LOGIBM_IRQ; 53 - module_param_hw_named(irq, logibm_irq, uint, irq, 0); 54 - MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 55 - 56 - static struct input_dev *logibm_dev; 57 - 58 - static irqreturn_t logibm_interrupt(int irq, void *dev_id) 59 - { 60 - char dx, dy; 61 - unsigned char buttons; 62 - 63 - outb(LOGIBM_READ_X_LOW, LOGIBM_CONTROL_PORT); 64 - dx = (inb(LOGIBM_DATA_PORT) & 0xf); 65 - outb(LOGIBM_READ_X_HIGH, LOGIBM_CONTROL_PORT); 66 - dx |= (inb(LOGIBM_DATA_PORT) & 0xf) << 4; 67 - outb(LOGIBM_READ_Y_LOW, LOGIBM_CONTROL_PORT); 68 - dy = (inb(LOGIBM_DATA_PORT) & 0xf); 69 - outb(LOGIBM_READ_Y_HIGH, LOGIBM_CONTROL_PORT); 70 - buttons = inb(LOGIBM_DATA_PORT); 71 - dy |= (buttons & 0xf) << 4; 72 - buttons = ~buttons >> 5; 73 - 74 - input_report_rel(logibm_dev, REL_X, dx); 75 - input_report_rel(logibm_dev, REL_Y, dy); 76 - input_report_key(logibm_dev, BTN_RIGHT, buttons & 1); 77 - input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2); 78 - input_report_key(logibm_dev, BTN_LEFT, buttons & 4); 79 - input_sync(logibm_dev); 80 - 81 - outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); 82 - return IRQ_HANDLED; 83 - } 84 - 85 - static int logibm_open(struct input_dev *dev) 86 - { 87 - if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) { 88 - printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq); 89 - return -EBUSY; 90 - } 91 - outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); 92 - return 0; 93 - } 94 - 95 - static void logibm_close(struct input_dev *dev) 96 - { 97 - outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 98 - free_irq(logibm_irq, NULL); 99 - } 100 - 101 - static int __init logibm_init(void) 102 - { 103 - int err; 104 - 105 - if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { 106 - printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE); 107 - return -EBUSY; 108 - } 109 - 110 - outb(LOGIBM_CONFIG_BYTE, LOGIBM_CONFIG_PORT); 111 - outb(LOGIBM_SIGNATURE_BYTE, LOGIBM_SIGNATURE_PORT); 112 - udelay(100); 113 - 114 - if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) { 115 - printk(KERN_INFO "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE); 116 - err = -ENODEV; 117 - goto err_release_region; 118 - } 119 - 120 - outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); 121 - outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 122 - 123 - logibm_dev = input_allocate_device(); 124 - if (!logibm_dev) { 125 - printk(KERN_ERR "logibm.c: Not enough memory for input device\n"); 126 - err = -ENOMEM; 127 - goto err_release_region; 128 - } 129 - 130 - logibm_dev->name = "Logitech bus mouse"; 131 - logibm_dev->phys = "isa023c/input0"; 132 - logibm_dev->id.bustype = BUS_ISA; 133 - logibm_dev->id.vendor = 0x0003; 134 - logibm_dev->id.product = 0x0001; 135 - logibm_dev->id.version = 0x0100; 136 - 137 - logibm_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 138 - logibm_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | 139 - BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 140 - logibm_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 141 - 142 - logibm_dev->open = logibm_open; 143 - logibm_dev->close = logibm_close; 144 - 145 - err = input_register_device(logibm_dev); 146 - if (err) 147 - goto err_free_dev; 148 - 149 - return 0; 150 - 151 - err_free_dev: 152 - input_free_device(logibm_dev); 153 - err_release_region: 154 - release_region(LOGIBM_BASE, LOGIBM_EXTENT); 155 - 156 - return err; 157 - } 158 - 159 - static void __exit logibm_exit(void) 160 - { 161 - input_unregister_device(logibm_dev); 162 - release_region(LOGIBM_BASE, LOGIBM_EXTENT); 163 - } 164 - 165 - module_init(logibm_init); 166 - module_exit(logibm_exit);
+7 -44
drivers/input/mouse/psmouse-base.c
··· 26 26 #include "synaptics.h" 27 27 #include "logips2pp.h" 28 28 #include "alps.h" 29 - #include "hgpk.h" 30 29 #include "lifebook.h" 31 30 #include "trackpoint.h" 32 31 #include "touchkit_ps2.h" ··· 112 113 * is taken in "slow" paths it is not worth it. 113 114 */ 114 115 static DEFINE_MUTEX(psmouse_mutex); 115 - 116 - static struct workqueue_struct *kpsmoused_wq; 117 116 118 117 struct psmouse *psmouse_from_serio(struct serio *serio) 119 118 { ··· 236 239 input_sync(dev); 237 240 238 241 return PSMOUSE_FULL_PACKET; 239 - } 240 - 241 - void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, 242 - unsigned long delay) 243 - { 244 - queue_delayed_work(kpsmoused_wq, work, delay); 245 242 } 246 243 247 244 /* ··· 371 380 psmouse->name, psmouse->phys, psmouse->pktcnt); 372 381 psmouse->badbyte = psmouse->packet[0]; 373 382 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); 374 - psmouse_queue_work(psmouse, &psmouse->resync_work, 0); 383 + schedule_work(&psmouse->resync_work); 375 384 return; 376 385 } 377 386 ··· 384 393 return; 385 394 } 386 395 387 - if (psmouse->packet[1] == PSMOUSE_RET_ID || 388 - (psmouse->protocol->type == PSMOUSE_HGPK && 389 - psmouse->packet[1] == PSMOUSE_RET_BAT)) { 396 + if (psmouse->packet[1] == PSMOUSE_RET_ID) { 390 397 __psmouse_set_state(psmouse, PSMOUSE_IGNORE); 391 398 serio_reconnect(ps2dev->serio); 392 399 return; ··· 407 418 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) { 408 419 psmouse->badbyte = psmouse->packet[0]; 409 420 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); 410 - psmouse_queue_work(psmouse, &psmouse->resync_work, 0); 421 + schedule_work(&psmouse->resync_work); 411 422 return; 412 423 } 413 424 ··· 826 837 .detect = touchkit_ps2_detect, 827 838 }, 828 839 #endif 829 - #ifdef CONFIG_MOUSE_PS2_OLPC 830 - { 831 - .type = PSMOUSE_HGPK, 832 - .name = "OLPC HGPK", 833 - .alias = "hgpk", 834 - .detect = hgpk_detect, 835 - }, 836 - #endif 837 840 #ifdef CONFIG_MOUSE_PS2_ELANTECH 838 841 { 839 842 .type = PSMOUSE_ELANTECH, ··· 1134 1153 return PSMOUSE_ALPS; 1135 1154 } 1136 1155 1137 - /* Try OLPC HGPK touchpad */ 1138 - if (max_proto > PSMOUSE_IMEX && 1139 - psmouse_try_protocol(psmouse, PSMOUSE_HGPK, &max_proto, 1140 - set_properties, true)) { 1141 - return PSMOUSE_HGPK; 1142 - } 1143 - 1144 1156 /* Try Elantech touchpad */ 1145 1157 if (max_proto > PSMOUSE_IMEX && 1146 1158 psmouse_try_protocol(psmouse, PSMOUSE_ELANTECH, ··· 1305 1331 static void psmouse_resync(struct work_struct *work) 1306 1332 { 1307 1333 struct psmouse *parent = NULL, *psmouse = 1308 - container_of(work, struct psmouse, resync_work.work); 1334 + container_of(work, struct psmouse, resync_work); 1309 1335 struct serio *serio = psmouse->ps2dev.serio; 1310 1336 psmouse_ret_t rc = PSMOUSE_GOOD_DATA; 1311 1337 bool failed = false, enabled = false; ··· 1458 1484 1459 1485 /* make sure we don't have a resync in progress */ 1460 1486 mutex_unlock(&psmouse_mutex); 1461 - flush_workqueue(kpsmoused_wq); 1487 + disable_work_sync(&psmouse->resync_work); 1462 1488 mutex_lock(&psmouse_mutex); 1463 1489 1464 1490 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { ··· 1572 1598 1573 1599 ps2_init(&psmouse->ps2dev, serio, 1574 1600 psmouse_pre_receive_byte, psmouse_receive_byte); 1575 - INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync); 1601 + INIT_WORK(&psmouse->resync_work, psmouse_resync); 1576 1602 psmouse->dev = input_dev; 1577 1603 scnprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys); 1578 1604 ··· 2009 2035 2010 2036 lifebook_module_init(); 2011 2037 synaptics_module_init(); 2012 - hgpk_module_init(); 2013 2038 2014 2039 err = psmouse_smbus_module_init(); 2015 2040 if (err) 2016 2041 return err; 2017 2042 2018 - kpsmoused_wq = alloc_ordered_workqueue("kpsmoused", 0); 2019 - if (!kpsmoused_wq) { 2020 - pr_err("failed to create kpsmoused workqueue\n"); 2021 - err = -ENOMEM; 2022 - goto err_smbus_exit; 2023 - } 2024 - 2025 2043 err = serio_register_driver(&psmouse_drv); 2026 2044 if (err) 2027 - goto err_destroy_wq; 2045 + goto err_smbus_exit; 2028 2046 2029 2047 return 0; 2030 2048 2031 - err_destroy_wq: 2032 - destroy_workqueue(kpsmoused_wq); 2033 2049 err_smbus_exit: 2034 2050 psmouse_smbus_module_exit(); 2035 2051 return err; ··· 2028 2064 static void __exit psmouse_exit(void) 2029 2065 { 2030 2066 serio_unregister_driver(&psmouse_drv); 2031 - destroy_workqueue(kpsmoused_wq); 2032 2067 psmouse_smbus_module_exit(); 2033 2068 } 2034 2069
+2 -4
drivers/input/mouse/psmouse.h
··· 59 59 PSMOUSE_TRACKPOINT, 60 60 PSMOUSE_TOUCHKIT_PS2, 61 61 PSMOUSE_CORTRON, 62 - PSMOUSE_HGPK, 62 + PSMOUSE_HGPK, /* No longer used */ 63 63 PSMOUSE_ELANTECH, 64 64 PSMOUSE_FSP, 65 65 PSMOUSE_SYNAPTICS_RELATIVE, ··· 90 90 void *private; 91 91 struct input_dev *dev; 92 92 struct ps2dev ps2dev; 93 - struct delayed_work resync_work; 93 + struct work_struct resync_work; 94 94 const char *vendor; 95 95 const char *name; 96 96 const struct psmouse_protocol *protocol; ··· 132 132 133 133 struct psmouse *psmouse_from_serio(struct serio *serio); 134 134 135 - void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work, 136 - unsigned long delay); 137 135 int psmouse_reset(struct psmouse *psmouse); 138 136 void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state); 139 137 void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
+2 -21
drivers/input/mouse/synaptics_usb.c
··· 220 220 __func__, error); 221 221 } 222 222 223 - static struct usb_endpoint_descriptor * 224 - synusb_get_in_endpoint(struct usb_host_interface *iface) 225 - { 226 - 227 - struct usb_endpoint_descriptor *endpoint; 228 - int i; 229 - 230 - for (i = 0; i < iface->desc.bNumEndpoints; ++i) { 231 - endpoint = &iface->endpoint[i].desc; 232 - 233 - if (usb_endpoint_is_int_in(endpoint)) { 234 - /* we found our interrupt in endpoint */ 235 - return endpoint; 236 - } 237 - } 238 - 239 - return NULL; 240 - } 241 - 242 223 static int synusb_open(struct input_dev *dev) 243 224 { 244 225 struct synusb *synusb = input_get_drvdata(dev); ··· 288 307 return error; 289 308 } 290 309 291 - ep = synusb_get_in_endpoint(intf->cur_altsetting); 292 - if (!ep) 310 + error = usb_find_int_in_endpoint(intf->cur_altsetting, &ep); 311 + if (error) 293 312 return -ENODEV; 294 313 295 314 synusb = kzalloc_obj(*synusb);
-13
drivers/input/serio/Kconfig
··· 55 55 To compile this driver as a module, choose M here: the 56 56 module will be called serport. 57 57 58 - config SERIO_CT82C710 59 - tristate "ct82c710 Aux port controller" 60 - depends on X86 61 - help 62 - Say Y here if you have a Texas Instruments TravelMate notebook 63 - equipped with the ct82c710 chip and want to use a mouse connected 64 - to the "QuickPort". 65 - 66 - If unsure, say N. 67 - 68 - To compile this driver as a module, choose M here: the 69 - module will be called ct82c710. 70 - 71 58 config SERIO_Q40KBD 72 59 tristate "Q40 keyboard controller" 73 60 depends on Q40
-1
drivers/input/serio/Makefile
··· 9 9 obj-$(CONFIG_SERIO_I8042) += i8042.o 10 10 obj-$(CONFIG_SERIO_PARKBD) += parkbd.o 11 11 obj-$(CONFIG_SERIO_SERPORT) += serport.o 12 - obj-$(CONFIG_SERIO_CT82C710) += ct82c710.o 13 12 obj-$(CONFIG_SERIO_RPCKBD) += rpckbd.o 14 13 obj-$(CONFIG_SERIO_SA1111) += sa1111ps2.o 15 14 obj-$(CONFIG_SERIO_AMBAKMI) += ambakmi.o
-239
drivers/input/serio/ct82c710.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Copyright (c) 1999-2001 Vojtech Pavlik 4 - */ 5 - 6 - /* 7 - * 82C710 C&T mouse port chip driver for Linux 8 - */ 9 - 10 - #include <linux/delay.h> 11 - #include <linux/module.h> 12 - #include <linux/ioport.h> 13 - #include <linux/init.h> 14 - #include <linux/interrupt.h> 15 - #include <linux/serio.h> 16 - #include <linux/errno.h> 17 - #include <linux/err.h> 18 - #include <linux/platform_device.h> 19 - #include <linux/slab.h> 20 - 21 - #include <asm/io.h> 22 - 23 - MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 24 - MODULE_DESCRIPTION("82C710 C&T mouse port chip driver"); 25 - MODULE_LICENSE("GPL"); 26 - 27 - /* 28 - * ct82c710 interface 29 - */ 30 - 31 - #define CT82C710_DEV_IDLE 0x01 /* Device Idle */ 32 - #define CT82C710_RX_FULL 0x02 /* Device Char received */ 33 - #define CT82C710_TX_IDLE 0x04 /* Device XMIT Idle */ 34 - #define CT82C710_RESET 0x08 /* Device Reset */ 35 - #define CT82C710_INTS_ON 0x10 /* Device Interrupt On */ 36 - #define CT82C710_ERROR_FLAG 0x20 /* Device Error */ 37 - #define CT82C710_CLEAR 0x40 /* Device Clear */ 38 - #define CT82C710_ENABLE 0x80 /* Device Enable */ 39 - 40 - #define CT82C710_IRQ 12 41 - 42 - #define CT82C710_DATA ct82c710_iores.start 43 - #define CT82C710_STATUS (ct82c710_iores.start + 1) 44 - 45 - static struct serio *ct82c710_port; 46 - static struct platform_device *ct82c710_device; 47 - static struct resource ct82c710_iores; 48 - 49 - /* 50 - * Interrupt handler for the 82C710 mouse port. A character 51 - * is waiting in the 82C710. 52 - */ 53 - 54 - static irqreturn_t ct82c710_interrupt(int cpl, void *dev_id) 55 - { 56 - return serio_interrupt(ct82c710_port, inb(CT82C710_DATA), 0); 57 - } 58 - 59 - /* 60 - * Wait for device to send output char and flush any input char. 61 - */ 62 - 63 - static int ct82c170_wait(void) 64 - { 65 - int timeout = 60000; 66 - 67 - while ((inb(CT82C710_STATUS) & (CT82C710_RX_FULL | CT82C710_TX_IDLE | CT82C710_DEV_IDLE)) 68 - != (CT82C710_DEV_IDLE | CT82C710_TX_IDLE) && timeout) { 69 - 70 - if (inb_p(CT82C710_STATUS) & CT82C710_RX_FULL) inb_p(CT82C710_DATA); 71 - 72 - udelay(1); 73 - timeout--; 74 - } 75 - 76 - return !timeout; 77 - } 78 - 79 - static void ct82c710_close(struct serio *serio) 80 - { 81 - if (ct82c170_wait()) 82 - printk(KERN_WARNING "ct82c710.c: Device busy in close()\n"); 83 - 84 - outb_p(inb_p(CT82C710_STATUS) & ~(CT82C710_ENABLE | CT82C710_INTS_ON), CT82C710_STATUS); 85 - 86 - if (ct82c170_wait()) 87 - printk(KERN_WARNING "ct82c710.c: Device busy in close()\n"); 88 - 89 - free_irq(CT82C710_IRQ, NULL); 90 - } 91 - 92 - static int ct82c710_open(struct serio *serio) 93 - { 94 - unsigned char status; 95 - int err; 96 - 97 - err = request_irq(CT82C710_IRQ, ct82c710_interrupt, 0, "ct82c710", NULL); 98 - if (err) 99 - return err; 100 - 101 - status = inb_p(CT82C710_STATUS); 102 - 103 - status |= (CT82C710_ENABLE | CT82C710_RESET); 104 - outb_p(status, CT82C710_STATUS); 105 - 106 - status &= ~(CT82C710_RESET); 107 - outb_p(status, CT82C710_STATUS); 108 - 109 - status |= CT82C710_INTS_ON; 110 - outb_p(status, CT82C710_STATUS); /* Enable interrupts */ 111 - 112 - while (ct82c170_wait()) { 113 - printk(KERN_ERR "ct82c710: Device busy in open()\n"); 114 - status &= ~(CT82C710_ENABLE | CT82C710_INTS_ON); 115 - outb_p(status, CT82C710_STATUS); 116 - free_irq(CT82C710_IRQ, NULL); 117 - return -EBUSY; 118 - } 119 - 120 - return 0; 121 - } 122 - 123 - /* 124 - * Write to the 82C710 mouse device. 125 - */ 126 - 127 - static int ct82c710_write(struct serio *port, unsigned char c) 128 - { 129 - if (ct82c170_wait()) return -1; 130 - outb_p(c, CT82C710_DATA); 131 - return 0; 132 - } 133 - 134 - /* 135 - * See if we can find a 82C710 device. Read mouse address. 136 - */ 137 - 138 - static int __init ct82c710_detect(void) 139 - { 140 - outb_p(0x55, 0x2fa); /* Any value except 9, ff or 36 */ 141 - outb_p(0xaa, 0x3fa); /* Inverse of 55 */ 142 - outb_p(0x36, 0x3fa); /* Address the chip */ 143 - outb_p(0xe4, 0x3fa); /* 390/4; 390 = config address */ 144 - outb_p(0x1b, 0x2fa); /* Inverse of e4 */ 145 - outb_p(0x0f, 0x390); /* Write index */ 146 - if (inb_p(0x391) != 0xe4) /* Config address found? */ 147 - return -ENODEV; /* No: no 82C710 here */ 148 - 149 - outb_p(0x0d, 0x390); /* Write index */ 150 - ct82c710_iores.start = inb_p(0x391) << 2; /* Get mouse I/O address */ 151 - ct82c710_iores.end = ct82c710_iores.start + 1; 152 - ct82c710_iores.flags = IORESOURCE_IO; 153 - outb_p(0x0f, 0x390); 154 - outb_p(0x0f, 0x391); /* Close config mode */ 155 - 156 - return 0; 157 - } 158 - 159 - static int ct82c710_probe(struct platform_device *dev) 160 - { 161 - ct82c710_port = kzalloc_obj(*ct82c710_port); 162 - if (!ct82c710_port) 163 - return -ENOMEM; 164 - 165 - ct82c710_port->id.type = SERIO_8042; 166 - ct82c710_port->dev.parent = &dev->dev; 167 - ct82c710_port->open = ct82c710_open; 168 - ct82c710_port->close = ct82c710_close; 169 - ct82c710_port->write = ct82c710_write; 170 - strscpy(ct82c710_port->name, "C&T 82c710 mouse port", 171 - sizeof(ct82c710_port->name)); 172 - snprintf(ct82c710_port->phys, sizeof(ct82c710_port->phys), 173 - "isa%16llx/serio0", (unsigned long long)CT82C710_DATA); 174 - 175 - serio_register_port(ct82c710_port); 176 - 177 - printk(KERN_INFO "serio: C&T 82c710 mouse port at %#llx irq %d\n", 178 - (unsigned long long)CT82C710_DATA, CT82C710_IRQ); 179 - 180 - return 0; 181 - } 182 - 183 - static void ct82c710_remove(struct platform_device *dev) 184 - { 185 - serio_unregister_port(ct82c710_port); 186 - } 187 - 188 - static struct platform_driver ct82c710_driver = { 189 - .driver = { 190 - .name = "ct82c710", 191 - }, 192 - .probe = ct82c710_probe, 193 - .remove = ct82c710_remove, 194 - }; 195 - 196 - 197 - static int __init ct82c710_init(void) 198 - { 199 - int error; 200 - 201 - error = ct82c710_detect(); 202 - if (error) 203 - return error; 204 - 205 - error = platform_driver_register(&ct82c710_driver); 206 - if (error) 207 - return error; 208 - 209 - ct82c710_device = platform_device_alloc("ct82c710", -1); 210 - if (!ct82c710_device) { 211 - error = -ENOMEM; 212 - goto err_unregister_driver; 213 - } 214 - 215 - error = platform_device_add_resources(ct82c710_device, &ct82c710_iores, 1); 216 - if (error) 217 - goto err_free_device; 218 - 219 - error = platform_device_add(ct82c710_device); 220 - if (error) 221 - goto err_free_device; 222 - 223 - return 0; 224 - 225 - err_free_device: 226 - platform_device_put(ct82c710_device); 227 - err_unregister_driver: 228 - platform_driver_unregister(&ct82c710_driver); 229 - return error; 230 - } 231 - 232 - static void __exit ct82c710_exit(void) 233 - { 234 - platform_device_unregister(ct82c710_device); 235 - platform_driver_unregister(&ct82c710_driver); 236 - } 237 - 238 - module_init(ct82c710_init); 239 - module_exit(ct82c710_exit);
+3 -9
drivers/input/serio/libps2.c
··· 154 154 */ 155 155 void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) 156 156 { 157 - if (maxbytes > sizeof(ps2dev->cmdbuf)) { 158 - WARN_ON(1); 157 + if (WARN_ON(maxbytes > sizeof(ps2dev->cmdbuf))) 159 158 maxbytes = sizeof(ps2dev->cmdbuf); 160 - } 161 159 162 160 ps2_begin_command(ps2dev); 163 161 ··· 268 270 int i; 269 271 u8 send_param[16]; 270 272 271 - if (receive > sizeof(ps2dev->cmdbuf)) { 272 - WARN_ON(1); 273 + if (WARN_ON(receive > sizeof(ps2dev->cmdbuf))) 273 274 return -EINVAL; 274 - } 275 275 276 - if (send && !param) { 277 - WARN_ON(1); 276 + if (WARN_ON(send && !param)) 278 277 return -EINVAL; 279 - } 280 278 281 279 memcpy(send_param, param, send); 282 280
+12 -8
drivers/input/tablet/aiptek.c
··· 57 57 * http://aiptektablet.sourceforge.net. 58 58 */ 59 59 60 + #include <linux/hid.h> 60 61 #include <linux/jiffies.h> 61 62 #include <linux/kernel.h> 62 63 #include <linux/slab.h> ··· 165 164 166 165 #define USB_VENDOR_ID_AIPTEK 0x08ca 167 166 #define USB_VENDOR_ID_KYE 0x0458 168 - #define USB_REQ_GET_REPORT 0x01 169 - #define USB_REQ_SET_REPORT 0x09 170 167 171 168 /* PointerMode codes 172 169 */ ··· 657 658 pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0; 658 659 659 660 macro = dv && p && tip && !(data[3] & 1) ? (data[3] >> 1) : -1; 661 + if (macro >= ARRAY_SIZE(macroKeyEvents)) 662 + macro = -1; 660 663 z = get_unaligned_le16(data + 4); 661 664 662 665 if (dv) { ··· 700 699 left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0; 701 700 right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0; 702 701 middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0; 703 - macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : 0; 702 + macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : -1; 703 + if (macro >= ARRAY_SIZE(macroKeyEvents)) 704 + macro = -1; 704 705 705 706 if (dv) { 706 707 /* If the selected tool changed, reset the old ··· 740 737 */ 741 738 else if (data[0] == 6) { 742 739 macro = get_unaligned_le16(data + 1); 743 - if (macro > 0) { 740 + if (macro > 0 && macro - 1 < ARRAY_SIZE(macroKeyEvents)) { 744 741 input_report_key(inputdev, macroKeyEvents[macro - 1], 745 742 0); 746 743 } 747 - if (macro < 25) { 744 + if (macro + 1 < ARRAY_SIZE(macroKeyEvents)) { 748 745 input_report_key(inputdev, macroKeyEvents[macro + 1], 749 746 0); 750 747 } ··· 763 760 aiptek->curSetting.toolMode; 764 761 } 765 762 766 - input_report_key(inputdev, macroKeyEvents[macro], 1); 763 + if (macro < ARRAY_SIZE(macroKeyEvents)) 764 + input_report_key(inputdev, macroKeyEvents[macro], 1); 767 765 input_report_abs(inputdev, ABS_MISC, 768 766 1 | AIPTEK_REPORT_TOOL_UNKNOWN); 769 767 input_sync(inputdev); ··· 860 856 861 857 return usb_control_msg(udev, 862 858 usb_sndctrlpipe(udev, 0), 863 - USB_REQ_SET_REPORT, 859 + HID_REQ_SET_REPORT, 864 860 USB_TYPE_CLASS | USB_RECIP_INTERFACE | 865 861 USB_DIR_OUT, (report_type << 8) + report_id, 866 862 aiptek->ifnum, buffer, size, 5000); ··· 875 871 876 872 return usb_control_msg(udev, 877 873 usb_rcvctrlpipe(udev, 0), 878 - USB_REQ_GET_REPORT, 874 + HID_REQ_GET_REPORT, 879 875 USB_TYPE_CLASS | USB_RECIP_INTERFACE | 880 876 USB_DIR_IN, (report_type << 8) + report_id, 881 877 aiptek->ifnum, buffer, size, 5000);
+2 -5
drivers/input/tablet/pegasus_notetaker.c
··· 36 36 * T Tip 37 37 */ 38 38 39 + #include <linux/hid.h> 39 40 #include <linux/kernel.h> 40 41 #include <linux/module.h> 41 42 #include <linux/input.h> ··· 44 43 #include <linux/slab.h> 45 44 #include <linux/workqueue.h> 46 45 #include <linux/mutex.h> 47 - 48 - /* USB HID defines */ 49 - #define USB_REQ_GET_REPORT 0x01 50 - #define USB_REQ_SET_REPORT 0x09 51 46 52 47 #define USB_VENDOR_ID_PEGASUSTECH 0x0e20 53 48 #define USB_DEVICE_ID_PEGASUS_NOTETAKER_EN100 0x0101 ··· 105 108 106 109 result = usb_control_msg(pegasus->usbdev, 107 110 usb_sndctrlpipe(pegasus->usbdev, 0), 108 - USB_REQ_SET_REPORT, 111 + HID_REQ_SET_REPORT, 109 112 USB_TYPE_VENDOR | USB_DIR_OUT, 110 113 0, 0, cmd_buf, sizeof_buf, 111 114 USB_CTRL_SET_TIMEOUT);
-12
drivers/input/touchscreen/Kconfig
··· 723 723 To compile this driver as a module, choose M here: the 724 724 module will be called inexio. 725 725 726 - config TOUCHSCREEN_MK712 727 - tristate "ICS MicroClock MK712 touchscreen" 728 - depends on ISA 729 - help 730 - Say Y here if you have the ICS MicroClock MK712 touchscreen 731 - controller chip in your system. 732 - 733 - If unsure, say N. 734 - 735 - To compile this driver as a module, choose M here: the 736 - module will be called mk712. 737 - 738 726 config TOUCHSCREEN_HP600 739 727 tristate "HP Jornada 6xx touchscreen" 740 728 depends on SH_HP6XX && SH_ADC
-1
drivers/input/touchscreen/Makefile
··· 68 68 obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o 69 69 obj-$(CONFIG_TOUCHSCREEN_MSG2638) += msg2638.o 70 70 obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 71 - obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 72 71 obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS) += novatek-nvt-ts.o 73 72 obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 74 73 obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o
+12 -20
drivers/input/touchscreen/ad7877.c
··· 376 376 static void ad7877_timer(struct timer_list *t) 377 377 { 378 378 struct ad7877 *ts = timer_container_of(ts, t, timer); 379 - unsigned long flags; 380 379 381 - spin_lock_irqsave(&ts->lock, flags); 380 + guard(spinlock_irqsave)(&ts->lock); 382 381 ad7877_ts_event_release(ts); 383 - spin_unlock_irqrestore(&ts->lock, flags); 384 382 } 385 383 386 384 static irqreturn_t ad7877_irq(int irq, void *handle) 387 385 { 388 386 struct ad7877 *ts = handle; 389 - unsigned long flags; 390 387 int error; 391 388 392 389 error = spi_sync(ts->spi, &ts->msg); ··· 392 395 goto out; 393 396 } 394 397 395 - spin_lock_irqsave(&ts->lock, flags); 396 - error = ad7877_process_data(ts); 397 - if (!error) 398 + scoped_guard(spinlock_irqsave, &ts->lock) { 399 + error = ad7877_process_data(ts); 400 + if (error) 401 + goto out; 402 + 398 403 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); 399 - spin_unlock_irqrestore(&ts->lock, flags); 404 + } 400 405 401 406 out: 402 407 return IRQ_HANDLED; ··· 408 409 { 409 410 struct ad7877 *ts = data; 410 411 411 - mutex_lock(&ts->mutex); 412 + guard(mutex)(&ts->mutex); 412 413 413 414 if (!ts->disabled) { 414 415 ts->disabled = true; ··· 422 423 * We know the chip's in lowpower mode since we always 423 424 * leave it that way after every request 424 425 */ 425 - 426 - mutex_unlock(&ts->mutex); 427 426 } 428 427 429 428 static void ad7877_enable(struct ad7877 *ts) 430 429 { 431 - mutex_lock(&ts->mutex); 430 + guard(mutex)(&ts->mutex); 432 431 433 432 if (ts->disabled) { 434 433 ts->disabled = false; 435 434 enable_irq(ts->spi->irq); 436 435 } 437 - 438 - mutex_unlock(&ts->mutex); 439 436 } 440 437 441 438 #define SHOW(name) static ssize_t \ ··· 504 509 if (error) 505 510 return error; 506 511 507 - mutex_lock(&ts->mutex); 512 + guard(mutex)(&ts->mutex); 508 513 ts->dac = val & 0xFF; 509 514 ad7877_write(ts->spi, AD7877_REG_DAC, (ts->dac << 4) | AD7877_DAC_CONF); 510 - mutex_unlock(&ts->mutex); 511 515 512 516 return count; 513 517 } ··· 533 539 if (error) 534 540 return error; 535 541 536 - mutex_lock(&ts->mutex); 542 + guard(mutex)(&ts->mutex); 537 543 ts->gpio3 = !!val; 538 544 ad7877_write(ts->spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | 539 545 (ts->gpio4 << 4) | (ts->gpio3 << 5)); 540 - mutex_unlock(&ts->mutex); 541 546 542 547 return count; 543 548 } ··· 563 570 if (error) 564 571 return error; 565 572 566 - mutex_lock(&ts->mutex); 573 + guard(mutex)(&ts->mutex); 567 574 ts->gpio4 = !!val; 568 575 ad7877_write(ts->spi, AD7877_REG_EXTWRITE, AD7877_EXTW_GPIO_DATA | 569 576 (ts->gpio4 << 4) | (ts->gpio3 << 5)); 570 - mutex_unlock(&ts->mutex); 571 577 572 578 return count; 573 579 }
+15 -31
drivers/input/touchscreen/ad7879.c
··· 305 305 { 306 306 struct ad7879 *ts = dev_get_drvdata(dev); 307 307 308 - mutex_lock(&ts->input->mutex); 308 + guard(mutex)(&ts->input->mutex); 309 309 310 310 if (!ts->suspended && !ts->disabled && input_device_enabled(ts->input)) 311 311 __ad7879_disable(ts); 312 312 313 313 ts->suspended = true; 314 - 315 - mutex_unlock(&ts->input->mutex); 316 314 317 315 return 0; 318 316 } ··· 319 321 { 320 322 struct ad7879 *ts = dev_get_drvdata(dev); 321 323 322 - mutex_lock(&ts->input->mutex); 324 + guard(mutex)(&ts->input->mutex); 323 325 324 326 if (ts->suspended && !ts->disabled && input_device_enabled(ts->input)) 325 327 __ad7879_enable(ts); 326 328 327 329 ts->suspended = false; 328 - 329 - mutex_unlock(&ts->input->mutex); 330 330 331 331 return 0; 332 332 } ··· 334 338 335 339 static void ad7879_toggle(struct ad7879 *ts, bool disable) 336 340 { 337 - mutex_lock(&ts->input->mutex); 341 + guard(mutex)(&ts->input->mutex); 338 342 339 343 if (!ts->suspended && input_device_enabled(ts->input)) { 340 344 ··· 348 352 } 349 353 350 354 ts->disabled = disable; 351 - 352 - mutex_unlock(&ts->input->mutex); 353 355 } 354 356 355 357 static ssize_t ad7879_disable_show(struct device *dev, ··· 397 403 unsigned gpio) 398 404 { 399 405 struct ad7879 *ts = gpiochip_get_data(chip); 400 - int err; 401 406 402 - mutex_lock(&ts->mutex); 407 + guard(mutex)(&ts->mutex); 408 + 403 409 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; 404 - err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 405 - mutex_unlock(&ts->mutex); 406 - 407 - return err; 410 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 408 411 } 409 412 410 413 static int ad7879_gpio_direction_output(struct gpio_chip *chip, 411 414 unsigned gpio, int level) 412 415 { 413 416 struct ad7879 *ts = gpiochip_get_data(chip); 414 - int err; 415 417 416 - mutex_lock(&ts->mutex); 418 + guard(mutex)(&ts->mutex); 419 + 417 420 ts->cmd_crtl2 &= ~AD7879_GPIODIR; 418 421 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; 419 422 if (level) ··· 418 427 else 419 428 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 420 429 421 - err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 422 - mutex_unlock(&ts->mutex); 423 - 424 - return err; 430 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 425 431 } 426 432 427 - static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio) 433 + static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned int gpio) 428 434 { 429 435 struct ad7879 *ts = gpiochip_get_data(chip); 430 436 u16 val; 431 437 432 - mutex_lock(&ts->mutex); 433 - val = ad7879_read(ts, AD7879_REG_CTRL2); 434 - mutex_unlock(&ts->mutex); 438 + guard(mutex)(&ts->mutex); 435 439 440 + val = ad7879_read(ts, AD7879_REG_CTRL2); 436 441 return !!(val & AD7879_GPIO_DATA); 437 442 } 438 443 ··· 436 449 int value) 437 450 { 438 451 struct ad7879 *ts = gpiochip_get_data(chip); 439 - int ret; 440 452 441 - mutex_lock(&ts->mutex); 453 + guard(mutex)(&ts->mutex); 454 + 442 455 if (value) 443 456 ts->cmd_crtl2 |= AD7879_GPIO_DATA; 444 457 else 445 458 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; 446 459 447 - ret = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 448 - mutex_unlock(&ts->mutex); 449 - 450 - return ret; 460 + return ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); 451 461 } 452 462 453 463 static int ad7879_gpio_add(struct ad7879 *ts)
+16 -28
drivers/input/touchscreen/ads7846.c
··· 289 289 290 290 static void ads7846_disable(struct ads7846 *ts) 291 291 { 292 - mutex_lock(&ts->lock); 292 + guard(mutex)(&ts->lock); 293 293 294 294 if (!ts->disabled) { 295 295 ··· 298 298 299 299 ts->disabled = true; 300 300 } 301 - 302 - mutex_unlock(&ts->lock); 303 301 } 304 302 305 303 static void ads7846_enable(struct ads7846 *ts) 306 304 { 307 - mutex_lock(&ts->lock); 305 + guard(mutex)(&ts->lock); 308 306 309 307 if (ts->disabled) { 310 308 ··· 311 313 if (!ts->suspended) 312 314 __ads7846_enable(ts); 313 315 } 314 - 315 - mutex_unlock(&ts->lock); 316 316 } 317 317 318 318 /*--------------------------------------------------------------------------*/ ··· 350 354 { 351 355 struct spi_device *spi = to_spi_device(dev); 352 356 struct ads7846 *ts = dev_get_drvdata(dev); 353 - struct ser_req *req; 354 357 int status; 355 358 356 - req = kzalloc_obj(*req); 359 + struct ser_req *req __free(kfree) = kzalloc_obj(*req); 357 360 if (!req) 358 361 return -ENOMEM; 359 362 ··· 413 418 CS_CHANGE(req->xfer[7]); 414 419 spi_message_add_tail(&req->xfer[7], &req->msg); 415 420 416 - mutex_lock(&ts->lock); 417 - ads7846_stop(ts); 418 - status = spi_sync(spi, &req->msg); 419 - ads7846_restart(ts); 420 - mutex_unlock(&ts->lock); 421 + scoped_guard(mutex, &ts->lock) { 422 + ads7846_stop(ts); 423 + status = spi_sync(spi, &req->msg); 424 + ads7846_restart(ts); 425 + } 421 426 422 427 if (status == 0) { 423 428 /* on-wire is a must-ignore bit, a BE12 value, then padding */ ··· 426 431 status &= 0x0fff; 427 432 } 428 433 429 - kfree(req); 430 434 return status; 431 435 } 432 436 ··· 433 439 { 434 440 struct spi_device *spi = to_spi_device(dev); 435 441 struct ads7846 *ts = dev_get_drvdata(dev); 436 - struct ads7845_ser_req *req; 437 442 int status; 438 443 439 - req = kzalloc_obj(*req); 444 + struct ads7845_ser_req *req __free(kfree) = kzalloc_obj(*req); 440 445 if (!req) 441 446 return -ENOMEM; 442 447 ··· 447 454 req->xfer[0].len = 3; 448 455 spi_message_add_tail(&req->xfer[0], &req->msg); 449 456 450 - mutex_lock(&ts->lock); 451 - ads7846_stop(ts); 452 - status = spi_sync(spi, &req->msg); 453 - ads7846_restart(ts); 454 - mutex_unlock(&ts->lock); 457 + scoped_guard(mutex, &ts->lock) { 458 + ads7846_stop(ts); 459 + status = spi_sync(spi, &req->msg); 460 + ads7846_restart(ts); 461 + } 455 462 456 463 if (status == 0) { 457 464 /* BE12 value, then padding */ ··· 460 467 status &= 0x0fff; 461 468 } 462 469 463 - kfree(req); 464 470 return status; 465 471 } 466 472 ··· 958 966 { 959 967 struct ads7846 *ts = dev_get_drvdata(dev); 960 968 961 - mutex_lock(&ts->lock); 969 + guard(mutex)(&ts->lock); 962 970 963 971 if (!ts->suspended) { 964 972 ··· 971 979 ts->suspended = true; 972 980 } 973 981 974 - mutex_unlock(&ts->lock); 975 - 976 982 return 0; 977 983 } 978 984 ··· 978 988 { 979 989 struct ads7846 *ts = dev_get_drvdata(dev); 980 990 981 - mutex_lock(&ts->lock); 991 + guard(mutex)(&ts->lock); 982 992 983 993 if (ts->suspended) { 984 994 ··· 990 1000 if (!ts->disabled) 991 1001 __ads7846_enable(ts); 992 1002 } 993 - 994 - mutex_unlock(&ts->lock); 995 1003 996 1004 return 0; 997 1005 }
+136 -154
drivers/input/touchscreen/atmel_mxt_ts.c
··· 713 713 const void *val) 714 714 { 715 715 bool retried = false; 716 - u8 *buf; 717 - size_t count; 716 + size_t count = len + 2; 717 + int error; 718 718 int ret; 719 719 720 - count = len + 2; 721 - buf = kmalloc(count, GFP_KERNEL); 720 + u8 *buf __free(kfree) = kmalloc(count, GFP_KERNEL); 722 721 if (!buf) 723 722 return -ENOMEM; 724 723 ··· 727 728 728 729 retry: 729 730 ret = i2c_master_send(client, buf, count); 730 - if (ret == count) { 731 - ret = 0; 732 - } else if (!retried && mxt_wakeup_toggle(client, true, true)) { 731 + if (ret == count) 732 + return 0; 733 + 734 + if (!retried && mxt_wakeup_toggle(client, true, true)) { 733 735 retried = true; 734 736 goto retry; 735 - } else { 736 - if (ret >= 0) 737 - ret = -EIO; 738 - dev_err(&client->dev, "%s: i2c send failed (%d)\n", 739 - __func__, ret); 740 737 } 741 738 742 - kfree(buf); 743 - return ret; 739 + error = ret < 0 ? ret : -EIO; 740 + dev_err(&client->dev, "%s: i2c send failed (%d)\n", __func__, error); 741 + return error; 744 742 } 745 743 746 744 static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) ··· 1543 1547 { 1544 1548 struct device *dev = &data->client->dev; 1545 1549 struct mxt_cfg cfg; 1546 - int ret; 1550 + int error; 1547 1551 int offset; 1548 1552 int i; 1549 1553 u32 info_crc, config_crc, calculated_crc; 1550 1554 u16 crc_start = 0; 1551 1555 1552 1556 /* Make zero terminated copy of the OBP_RAW file */ 1553 - cfg.raw = kmemdup_nul(fw->data, fw->size, GFP_KERNEL); 1557 + u8 *raw_buf __free(kfree) = cfg.raw = kmemdup_nul(fw->data, fw->size, 1558 + GFP_KERNEL); 1554 1559 if (!cfg.raw) 1555 1560 return -ENOMEM; 1556 1561 ··· 1561 1564 1562 1565 if (strncmp(cfg.raw, MXT_CFG_MAGIC, strlen(MXT_CFG_MAGIC))) { 1563 1566 dev_err(dev, "Unrecognised config file\n"); 1564 - ret = -EINVAL; 1565 - goto release_raw; 1567 + return -EINVAL; 1566 1568 } 1567 1569 1568 1570 cfg.raw_pos = strlen(MXT_CFG_MAGIC); 1569 1571 1570 1572 /* Load information block and check */ 1571 1573 for (i = 0; i < sizeof(struct mxt_info); i++) { 1572 - ret = sscanf(cfg.raw + cfg.raw_pos, "%hhx%n", 1573 - (unsigned char *)&cfg.info + i, 1574 - &offset); 1575 - if (ret != 1) { 1574 + if (sscanf(cfg.raw + cfg.raw_pos, "%hhx%n", 1575 + (unsigned char *)&cfg.info + i, &offset) != 1) { 1576 1576 dev_err(dev, "Bad format\n"); 1577 - ret = -EINVAL; 1578 - goto release_raw; 1577 + return -EINVAL; 1579 1578 } 1580 1579 1581 1580 cfg.raw_pos += offset; ··· 1579 1586 1580 1587 if (cfg.info.family_id != data->info->family_id) { 1581 1588 dev_err(dev, "Family ID mismatch!\n"); 1582 - ret = -EINVAL; 1583 - goto release_raw; 1589 + return -EINVAL; 1584 1590 } 1585 1591 1586 1592 if (cfg.info.variant_id != data->info->variant_id) { 1587 1593 dev_err(dev, "Variant ID mismatch!\n"); 1588 - ret = -EINVAL; 1589 - goto release_raw; 1594 + return -EINVAL; 1590 1595 } 1591 1596 1592 1597 /* Read CRCs */ 1593 - ret = sscanf(cfg.raw + cfg.raw_pos, "%x%n", &info_crc, &offset); 1594 - if (ret != 1) { 1598 + if (sscanf(cfg.raw + cfg.raw_pos, "%x%n", &info_crc, &offset) != 1) { 1595 1599 dev_err(dev, "Bad format: failed to parse Info CRC\n"); 1596 - ret = -EINVAL; 1597 - goto release_raw; 1600 + return -EINVAL; 1598 1601 } 1599 1602 cfg.raw_pos += offset; 1600 1603 1601 - ret = sscanf(cfg.raw + cfg.raw_pos, "%x%n", &config_crc, &offset); 1602 - if (ret != 1) { 1604 + if (sscanf(cfg.raw + cfg.raw_pos, "%x%n", &config_crc, &offset) != 1) { 1603 1605 dev_err(dev, "Bad format: failed to parse Config CRC\n"); 1604 - ret = -EINVAL; 1605 - goto release_raw; 1606 + return -EINVAL; 1606 1607 } 1607 1608 cfg.raw_pos += offset; 1608 1609 ··· 1612 1625 } else if (config_crc == data->config_crc) { 1613 1626 dev_dbg(dev, "Config CRC 0x%06X: OK\n", 1614 1627 data->config_crc); 1615 - ret = 0; 1616 - goto release_raw; 1628 + return 0; 1617 1629 } else { 1618 1630 dev_info(dev, "Config CRC 0x%06X: does not match file 0x%06X\n", 1619 1631 data->config_crc, config_crc); ··· 1628 1642 data->info->object_num * sizeof(struct mxt_object) + 1629 1643 MXT_INFO_CHECKSUM_SIZE; 1630 1644 cfg.mem_size = data->mem_size - cfg.start_ofs; 1631 - cfg.mem = kzalloc(cfg.mem_size, GFP_KERNEL); 1632 - if (!cfg.mem) { 1633 - ret = -ENOMEM; 1634 - goto release_raw; 1635 - } 1636 1645 1637 - ret = mxt_prepare_cfg_mem(data, &cfg); 1638 - if (ret) 1639 - goto release_mem; 1646 + u8 *mem_buf __free(kfree) = cfg.mem = kzalloc(cfg.mem_size, GFP_KERNEL); 1647 + if (!cfg.mem) 1648 + return -ENOMEM; 1649 + 1650 + error = mxt_prepare_cfg_mem(data, &cfg); 1651 + if (error) 1652 + return error; 1640 1653 1641 1654 /* Calculate crc of the received configs (not the raw config file) */ 1642 1655 if (data->T71_address) ··· 1655 1670 calculated_crc, config_crc); 1656 1671 } 1657 1672 1658 - ret = mxt_upload_cfg_mem(data, &cfg); 1659 - if (ret) 1660 - goto release_mem; 1673 + error = mxt_upload_cfg_mem(data, &cfg); 1674 + if (error) 1675 + return error; 1661 1676 1662 1677 mxt_update_crc(data, MXT_COMMAND_BACKUPNV, MXT_BACKUP_VALUE); 1663 1678 1664 - ret = mxt_check_retrigen(data); 1665 - if (ret) 1666 - goto release_mem; 1679 + error = mxt_check_retrigen(data); 1680 + if (error) 1681 + return error; 1667 1682 1668 - ret = mxt_soft_reset(data); 1669 - if (ret) 1670 - goto release_mem; 1683 + error = mxt_soft_reset(data); 1684 + if (error) 1685 + return error; 1671 1686 1672 1687 dev_info(dev, "Config successfully updated\n"); 1673 1688 1674 1689 /* T7 config may have changed */ 1675 1690 mxt_init_t7_power_cfg(data); 1676 1691 1677 - release_mem: 1678 - kfree(cfg.mem); 1679 - release_raw: 1680 - kfree(cfg.raw); 1681 - return ret; 1692 + return 0; 1682 1693 } 1683 1694 1684 1695 static void mxt_free_input_device(struct mxt_data *data) ··· 1838 1857 struct i2c_client *client = data->client; 1839 1858 int error; 1840 1859 size_t size; 1841 - void *id_buf, *buf; 1842 1860 uint8_t num_objects; 1843 1861 u32 calculated_crc; 1844 1862 u8 *crc_ptr; ··· 1848 1868 1849 1869 /* Read 7-byte ID information block starting at address 0 */ 1850 1870 size = sizeof(struct mxt_info); 1851 - id_buf = kzalloc(size, GFP_KERNEL); 1871 + void *id_buf __free(kfree) = kzalloc(size, GFP_KERNEL); 1852 1872 if (!id_buf) 1853 1873 return -ENOMEM; 1854 1874 1855 1875 error = __mxt_read_reg(client, 0, size, id_buf); 1856 1876 if (error) 1857 - goto err_free_mem; 1877 + return error; 1858 1878 1859 1879 /* Resize buffer to give space for rest of info block */ 1860 1880 num_objects = ((struct mxt_info *)id_buf)->object_num; 1861 1881 size += (num_objects * sizeof(struct mxt_object)) 1862 1882 + MXT_INFO_CHECKSUM_SIZE; 1863 1883 1864 - buf = krealloc(id_buf, size, GFP_KERNEL); 1865 - if (!buf) { 1866 - error = -ENOMEM; 1867 - goto err_free_mem; 1868 - } 1884 + void *buf = krealloc(id_buf, size, GFP_KERNEL); 1885 + if (!buf) 1886 + return -ENOMEM; 1887 + 1869 1888 id_buf = buf; 1870 1889 1871 1890 /* Read rest of info block */ ··· 1872 1893 size - MXT_OBJECT_START, 1873 1894 id_buf + MXT_OBJECT_START); 1874 1895 if (error) 1875 - goto err_free_mem; 1896 + return error; 1876 1897 1877 1898 /* Extract & calculate checksum */ 1878 1899 crc_ptr = id_buf + size - MXT_INFO_CHECKSUM_SIZE; ··· 1889 1910 dev_err(&client->dev, 1890 1911 "Info Block CRC error calculated=0x%06X read=0x%06X\n", 1891 1912 calculated_crc, data->info_crc); 1892 - error = -EIO; 1893 - goto err_free_mem; 1913 + return -EIO; 1894 1914 } 1895 1915 1896 - data->raw_info_block = id_buf; 1897 - data->info = (struct mxt_info *)id_buf; 1916 + data->raw_info_block = no_free_ptr(id_buf); 1917 + data->info = (struct mxt_info *)data->raw_info_block; 1898 1918 1899 1919 dev_info(&client->dev, 1900 1920 "Family: %u Variant: %u Firmware V%u.%u.%02X Objects: %u\n", ··· 1902 1924 data->info->build, data->info->object_num); 1903 1925 1904 1926 /* Parse object table information */ 1905 - error = mxt_parse_object_table(data, id_buf + MXT_OBJECT_START); 1927 + error = mxt_parse_object_table(data, 1928 + data->raw_info_block + MXT_OBJECT_START); 1906 1929 if (error) { 1907 1930 dev_err(&client->dev, "Error %d parsing object table\n", error); 1908 1931 mxt_free_object_table(data); 1909 1932 return error; 1910 1933 } 1911 1934 1912 - data->object_table = (struct mxt_object *)(id_buf + MXT_OBJECT_START); 1935 + data->object_table = 1936 + (struct mxt_object *)(data->raw_info_block + MXT_OBJECT_START); 1913 1937 1914 1938 return 0; 1915 - 1916 - err_free_mem: 1917 - kfree(id_buf); 1918 - return error; 1919 1939 } 1920 1940 1921 1941 static int mxt_read_t9_resolution(struct mxt_data *data) ··· 2890 2914 return -EINVAL; 2891 2915 } 2892 2916 2893 - static int mxt_load_fw(struct device *dev, const char *fn) 2917 + static int mxt_flash_fw(struct mxt_data *data, const struct firmware *fw) 2894 2918 { 2895 - struct mxt_data *data = dev_get_drvdata(dev); 2896 - const struct firmware *fw = NULL; 2919 + struct device *dev = &data->client->dev; 2897 2920 unsigned int frame_size; 2898 2921 unsigned int pos = 0; 2899 2922 unsigned int retry = 0; 2900 2923 unsigned int frame = 0; 2901 - int ret; 2902 - 2903 - ret = request_firmware(&fw, fn, dev); 2904 - if (ret) { 2905 - dev_err(dev, "Unable to open firmware %s\n", fn); 2906 - return ret; 2907 - } 2908 - 2909 - /* Check for incorrect enc file */ 2910 - ret = mxt_check_firmware_format(dev, fw); 2911 - if (ret) 2912 - goto release_firmware; 2913 - 2914 - if (!data->in_bootloader) { 2915 - /* Change to the bootloader mode */ 2916 - data->in_bootloader = true; 2917 - 2918 - ret = mxt_t6_command(data, MXT_COMMAND_RESET, 2919 - MXT_BOOT_VALUE, false); 2920 - if (ret) 2921 - goto release_firmware; 2922 - 2923 - msleep(MXT_RESET_TIME); 2924 - 2925 - /* Do not need to scan since we know family ID */ 2926 - ret = mxt_lookup_bootloader_address(data, 0); 2927 - if (ret) 2928 - goto release_firmware; 2929 - 2930 - mxt_free_input_device(data); 2931 - mxt_free_object_table(data); 2932 - } else { 2933 - enable_irq(data->irq); 2934 - } 2924 + int error; 2935 2925 2936 2926 reinit_completion(&data->bl_completion); 2937 2927 2938 - ret = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); 2939 - if (ret) { 2928 + error = mxt_check_bootloader(data, MXT_WAITING_BOOTLOAD_CMD, false); 2929 + if (error) { 2940 2930 /* Bootloader may still be unlocked from previous attempt */ 2941 - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, false); 2942 - if (ret) 2943 - goto disable_irq; 2931 + error = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, 2932 + false); 2933 + if (error) 2934 + return error; 2944 2935 } else { 2945 2936 dev_info(dev, "Unlocking bootloader\n"); 2946 2937 2947 2938 /* Unlock bootloader */ 2948 - ret = mxt_send_bootloader_cmd(data, true); 2949 - if (ret) 2950 - goto disable_irq; 2939 + error = mxt_send_bootloader_cmd(data, true); 2940 + if (error) 2941 + return error; 2951 2942 } 2952 2943 2953 2944 while (pos < fw->size) { 2954 - ret = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, true); 2955 - if (ret) 2956 - goto disable_irq; 2945 + error = mxt_check_bootloader(data, MXT_WAITING_FRAME_DATA, 2946 + true); 2947 + if (error) 2948 + return error; 2957 2949 2958 2950 frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); 2959 2951 ··· 2929 2985 frame_size += 2; 2930 2986 2931 2987 /* Write one frame to device */ 2932 - ret = mxt_bootloader_write(data, fw->data + pos, frame_size); 2933 - if (ret) 2934 - goto disable_irq; 2988 + error = mxt_bootloader_write(data, fw->data + pos, frame_size); 2989 + if (error) 2990 + return error; 2935 2991 2936 - ret = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); 2937 - if (ret) { 2992 + error = mxt_check_bootloader(data, MXT_FRAME_CRC_PASS, true); 2993 + if (error) { 2938 2994 retry++; 2939 2995 2940 2996 /* Back off by 20ms per retry */ ··· 2942 2998 2943 2999 if (retry > 20) { 2944 3000 dev_err(dev, "Retry count exceeded\n"); 2945 - goto disable_irq; 3001 + return error; 2946 3002 } 2947 3003 } else { 2948 3004 retry = 0; ··· 2956 3012 } 2957 3013 2958 3014 /* Wait for flash. */ 2959 - ret = mxt_wait_for_completion(data, &data->bl_completion, 2960 - MXT_FW_RESET_TIME); 2961 - if (ret) 2962 - goto disable_irq; 3015 + error = mxt_wait_for_completion(data, &data->bl_completion, 3016 + MXT_FW_RESET_TIME); 3017 + if (error) 3018 + return error; 2963 3019 2964 3020 dev_dbg(dev, "Sent %d frames, %d bytes\n", frame, pos); 2965 3021 ··· 2969 3025 * errors. 2970 3026 */ 2971 3027 mxt_wait_for_completion(data, &data->bl_completion, MXT_FW_RESET_TIME); 2972 - 2973 3028 data->in_bootloader = false; 2974 3029 2975 - disable_irq: 3030 + return 0; 3031 + } 3032 + 3033 + static int mxt_load_fw(struct device *dev, const char *fn) 3034 + { 3035 + struct mxt_data *data = dev_get_drvdata(dev); 3036 + int retval; 3037 + int error; 3038 + 3039 + const struct firmware *fw __free(firmware) = NULL; 3040 + error = request_firmware(&fw, fn, dev); 3041 + if (error) { 3042 + dev_err(dev, "Unable to open firmware %s\n", fn); 3043 + return error; 3044 + } 3045 + 3046 + /* Check for incorrect enc file */ 3047 + error = mxt_check_firmware_format(dev, fw); 3048 + if (error) 3049 + return error; 3050 + 3051 + if (!data->in_bootloader) { 3052 + /* Change to the bootloader mode */ 3053 + data->in_bootloader = true; 3054 + 3055 + error = mxt_t6_command(data, MXT_COMMAND_RESET, 3056 + MXT_BOOT_VALUE, false); 3057 + if (error) 3058 + return error; 3059 + 3060 + msleep(MXT_RESET_TIME); 3061 + 3062 + /* Do not need to scan since we know family ID */ 3063 + error = mxt_lookup_bootloader_address(data, 0); 3064 + if (error) 3065 + return error; 3066 + 3067 + mxt_free_input_device(data); 3068 + mxt_free_object_table(data); 3069 + } else { 3070 + enable_irq(data->irq); 3071 + } 3072 + 3073 + retval = mxt_flash_fw(data, fw); 3074 + 2976 3075 disable_irq(data->irq); 2977 - release_firmware: 2978 - release_firmware(fw); 2979 - return ret; 3076 + 3077 + return retval; 2980 3078 } 2981 3079 2982 3080 static ssize_t mxt_update_fw_store(struct device *dev, ··· 3361 3375 if (!input_dev) 3362 3376 return 0; 3363 3377 3364 - mutex_lock(&input_dev->mutex); 3365 - 3366 - if (input_device_enabled(input_dev)) 3367 - mxt_stop(data); 3368 - 3369 - mutex_unlock(&input_dev->mutex); 3378 + scoped_guard(mutex, &input_dev->mutex) { 3379 + if (input_device_enabled(input_dev)) 3380 + mxt_stop(data); 3381 + } 3370 3382 3371 3383 disable_irq(data->irq); 3372 3384 ··· 3382 3398 3383 3399 enable_irq(data->irq); 3384 3400 3385 - mutex_lock(&input_dev->mutex); 3386 - 3387 - if (input_device_enabled(input_dev)) 3388 - mxt_start(data); 3389 - 3390 - mutex_unlock(&input_dev->mutex); 3401 + scoped_guard(mutex, &input_dev->mutex) { 3402 + if (input_device_enabled(input_dev)) 3403 + mxt_start(data); 3404 + } 3391 3405 3392 3406 return 0; 3393 3407 }
+22 -21
drivers/input/touchscreen/auo-pixcir-ts.c
··· 415 415 struct i2c_client *client = to_i2c_client(dev); 416 416 struct auo_pixcir_ts *ts = i2c_get_clientdata(client); 417 417 struct input_dev *input = ts->input; 418 - int ret = 0; 418 + int error; 419 419 420 - mutex_lock(&input->mutex); 420 + guard(mutex)(&input->mutex); 421 421 422 422 /* when configured as wakeup source, device should always wake system 423 423 * therefore start device if necessary ··· 425 425 if (device_may_wakeup(&client->dev)) { 426 426 /* need to start device if not open, to be wakeup source */ 427 427 if (!input_device_enabled(input)) { 428 - ret = auo_pixcir_start(ts); 429 - if (ret) 430 - goto unlock; 428 + error = auo_pixcir_start(ts); 429 + if (error) 430 + return error; 431 431 } 432 432 433 433 enable_irq_wake(client->irq); 434 - ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP); 434 + error = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP); 435 + if (error) 436 + return error; 437 + 435 438 } else if (input_device_enabled(input)) { 436 - ret = auo_pixcir_stop(ts); 439 + error = auo_pixcir_stop(ts); 440 + if (error) 441 + return error; 437 442 } 438 443 439 - unlock: 440 - mutex_unlock(&input->mutex); 441 - 442 - return ret; 444 + return 0; 443 445 } 444 446 445 447 static int auo_pixcir_resume(struct device *dev) ··· 449 447 struct i2c_client *client = to_i2c_client(dev); 450 448 struct auo_pixcir_ts *ts = i2c_get_clientdata(client); 451 449 struct input_dev *input = ts->input; 452 - int ret = 0; 450 + int error; 453 451 454 - mutex_lock(&input->mutex); 452 + guard(mutex)(&input->mutex); 455 453 456 454 if (device_may_wakeup(&client->dev)) { 457 455 disable_irq_wake(client->irq); 458 456 459 457 /* need to stop device if it was not open on suspend */ 460 458 if (!input_device_enabled(input)) { 461 - ret = auo_pixcir_stop(ts); 462 - if (ret) 463 - goto unlock; 459 + error = auo_pixcir_stop(ts); 460 + if (error) 461 + return error; 464 462 } 465 463 466 464 /* device wakes automatically from SLEEP */ 467 465 } else if (input_device_enabled(input)) { 468 - ret = auo_pixcir_start(ts); 466 + error = auo_pixcir_start(ts); 467 + if (error) 468 + return error; 469 469 } 470 470 471 - unlock: 472 - mutex_unlock(&input->mutex); 473 - 474 - return ret; 471 + return 0; 475 472 } 476 473 477 474 static DEFINE_SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
+4 -4
drivers/input/touchscreen/bu21029_ts.c
··· 416 416 struct bu21029_ts_data *bu21029 = i2c_get_clientdata(i2c); 417 417 418 418 if (!device_may_wakeup(dev)) { 419 - mutex_lock(&bu21029->in_dev->mutex); 419 + guard(mutex)(&bu21029->in_dev->mutex); 420 + 420 421 if (input_device_enabled(bu21029->in_dev)) 421 422 bu21029_stop_chip(bu21029->in_dev); 422 - mutex_unlock(&bu21029->in_dev->mutex); 423 423 } 424 424 425 425 return 0; ··· 431 431 struct bu21029_ts_data *bu21029 = i2c_get_clientdata(i2c); 432 432 433 433 if (!device_may_wakeup(dev)) { 434 - mutex_lock(&bu21029->in_dev->mutex); 434 + guard(mutex)(&bu21029->in_dev->mutex); 435 + 435 436 if (input_device_enabled(bu21029->in_dev)) 436 437 bu21029_start_chip(bu21029->in_dev); 437 - mutex_unlock(&bu21029->in_dev->mutex); 438 438 } 439 439 440 440 return 0;
+4 -4
drivers/input/touchscreen/chipone_icn8318.c
··· 152 152 { 153 153 struct icn8318_data *data = i2c_get_clientdata(to_i2c_client(dev)); 154 154 155 - mutex_lock(&data->input->mutex); 155 + guard(mutex)(&data->input->mutex); 156 + 156 157 if (input_device_enabled(data->input)) 157 158 icn8318_stop(data->input); 158 - mutex_unlock(&data->input->mutex); 159 159 160 160 return 0; 161 161 } ··· 164 164 { 165 165 struct icn8318_data *data = i2c_get_clientdata(to_i2c_client(dev)); 166 166 167 - mutex_lock(&data->input->mutex); 167 + guard(mutex)(&data->input->mutex); 168 + 168 169 if (input_device_enabled(data->input)) 169 170 icn8318_start(data->input); 170 - mutex_unlock(&data->input->mutex); 171 171 172 172 return 0; 173 173 }
+8 -12
drivers/input/touchscreen/cyttsp_core.c
··· 494 494 static int cyttsp_suspend(struct device *dev) 495 495 { 496 496 struct cyttsp *ts = dev_get_drvdata(dev); 497 - int retval = 0; 497 + int error; 498 498 499 - mutex_lock(&ts->input->mutex); 499 + guard(mutex)(&ts->input->mutex); 500 500 501 501 if (input_device_enabled(ts->input)) { 502 - retval = cyttsp_disable(ts); 503 - if (retval == 0) 504 - ts->suspended = true; 502 + error = cyttsp_disable(ts); 503 + if (error) 504 + return error; 505 505 } 506 506 507 - mutex_unlock(&ts->input->mutex); 508 - 509 - return retval; 507 + ts->suspended = true; 508 + return 0; 510 509 } 511 510 512 511 static int cyttsp_resume(struct device *dev) 513 512 { 514 513 struct cyttsp *ts = dev_get_drvdata(dev); 515 514 516 - mutex_lock(&ts->input->mutex); 515 + guard(mutex)(&ts->input->mutex); 517 516 518 517 if (input_device_enabled(ts->input)) 519 518 cyttsp_enable(ts); 520 519 521 520 ts->suspended = false; 522 - 523 - mutex_unlock(&ts->input->mutex); 524 - 525 521 return 0; 526 522 } 527 523
+34 -56
drivers/input/touchscreen/edt-ft5x06.c
··· 380 380 container_of(dattr, struct edt_ft5x06_attribute, dattr); 381 381 u8 *field = (u8 *)tsdata + attr->field_offset; 382 382 unsigned int val; 383 - size_t count = 0; 384 - int error = 0; 383 + int error; 385 384 u8 addr; 386 385 387 - mutex_lock(&tsdata->mutex); 386 + guard(mutex)(&tsdata->mutex); 388 387 389 - if (tsdata->factory_mode) { 390 - error = -EIO; 391 - goto out; 392 - } 388 + if (tsdata->factory_mode) 389 + return -EIO; 393 390 394 391 switch (tsdata->version) { 395 392 case EDT_M06: ··· 404 407 break; 405 408 406 409 default: 407 - error = -ENODEV; 408 - goto out; 410 + return -ENODEV; 409 411 } 410 412 411 413 if (addr != NO_REGISTER) { ··· 413 417 dev_err(&tsdata->client->dev, 414 418 "Failed to fetch attribute %s, error %d\n", 415 419 dattr->attr.name, error); 416 - goto out; 420 + return error; 417 421 } 418 422 } else { 419 423 val = *field; ··· 426 430 *field = val; 427 431 } 428 432 429 - count = sysfs_emit(buf, "%d\n", val); 430 - out: 431 - mutex_unlock(&tsdata->mutex); 432 - return error ?: count; 433 + return sysfs_emit(buf, "%d\n", val); 433 434 } 434 435 435 436 static ssize_t edt_ft5x06_setting_store(struct device *dev, ··· 442 449 int error; 443 450 u8 addr; 444 451 445 - mutex_lock(&tsdata->mutex); 452 + guard(mutex)(&tsdata->mutex); 446 453 447 - if (tsdata->factory_mode) { 448 - error = -EIO; 449 - goto out; 450 - } 454 + if (tsdata->factory_mode) 455 + return -EIO; 451 456 452 457 error = kstrtouint(buf, 0, &val); 453 458 if (error) 454 - goto out; 459 + return error; 455 460 456 - if (val < attr->limit_low || val > attr->limit_high) { 457 - error = -ERANGE; 458 - goto out; 459 - } 461 + if (val < attr->limit_low || val > attr->limit_high) 462 + return -ERANGE; 460 463 461 464 switch (tsdata->version) { 462 465 case EDT_M06: ··· 470 481 break; 471 482 472 483 default: 473 - error = -ENODEV; 474 - goto out; 484 + return -ENODEV; 475 485 } 476 486 477 487 if (addr != NO_REGISTER) { ··· 479 491 dev_err(&tsdata->client->dev, 480 492 "Failed to update attribute %s, error: %d\n", 481 493 dattr->attr.name, error); 482 - goto out; 494 + return error; 483 495 } 484 496 } 485 497 *field = val; 486 498 487 - out: 488 - mutex_unlock(&tsdata->mutex); 489 - return error ?: count; 499 + return count; 490 500 } 491 501 492 502 /* m06, m09: range 0-31, m12: range 0-5 */ ··· 700 714 static int edt_ft5x06_debugfs_mode_set(void *data, u64 mode) 701 715 { 702 716 struct edt_ft5x06_ts_data *tsdata = data; 703 - int retval = 0; 704 717 705 718 if (mode > 1) 706 719 return -ERANGE; 707 720 708 - mutex_lock(&tsdata->mutex); 721 + guard(mutex)(&tsdata->mutex); 709 722 710 - if (mode != tsdata->factory_mode) { 711 - retval = mode ? edt_ft5x06_factory_mode(tsdata) : 712 - edt_ft5x06_work_mode(tsdata); 713 - } 723 + if (mode == tsdata->factory_mode) 724 + return 0; 714 725 715 - mutex_unlock(&tsdata->mutex); 716 - 717 - return retval; 726 + return mode ? edt_ft5x06_factory_mode(tsdata) : 727 + edt_ft5x06_work_mode(tsdata); 718 728 }; 719 729 720 730 DEFINE_SIMPLE_ATTRIBUTE(debugfs_mode_fops, edt_ft5x06_debugfs_mode_get, ··· 732 750 if (*off < 0 || *off >= tsdata->raw_bufsize) 733 751 return 0; 734 752 735 - mutex_lock(&tsdata->mutex); 753 + guard(mutex)(&tsdata->mutex); 736 754 737 - if (!tsdata->factory_mode || !tsdata->raw_buffer) { 738 - error = -EIO; 739 - goto out; 740 - } 755 + if (!tsdata->factory_mode || !tsdata->raw_buffer) 756 + return -EIO; 741 757 742 758 error = regmap_write(tsdata->regmap, 0x08, 0x01); 743 759 if (error) { 744 760 dev_err(&client->dev, 745 761 "failed to write 0x08 register, error %d\n", error); 746 - goto out; 762 + return error; 747 763 } 748 764 749 765 do { ··· 751 771 dev_err(&client->dev, 752 772 "failed to read 0x08 register, error %d\n", 753 773 error); 754 - goto out; 774 + return error; 755 775 } 756 776 757 777 if (val == 1) ··· 761 781 if (retries == 0) { 762 782 dev_err(&client->dev, 763 783 "timed out waiting for register to settle\n"); 764 - error = -ETIMEDOUT; 765 - goto out; 784 + return -ETIMEDOUT; 766 785 } 767 786 768 787 rdbuf = tsdata->raw_buffer; ··· 771 792 rdbuf[0] = i; /* column index */ 772 793 error = regmap_bulk_read(tsdata->regmap, 0xf5, rdbuf, colbytes); 773 794 if (error) 774 - goto out; 795 + return error; 775 796 776 797 rdbuf += colbytes; 777 798 } 778 799 779 800 read = min_t(size_t, count, tsdata->raw_bufsize - *off); 780 - if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) { 781 - error = -EFAULT; 782 - goto out; 783 - } 801 + if (copy_to_user(buf, tsdata->raw_buffer + *off, read)) 802 + return -EFAULT; 784 803 785 804 *off += read; 786 - out: 787 - mutex_unlock(&tsdata->mutex); 788 - return error ?: read; 805 + return read; 789 806 }; 790 807 791 808 static const struct file_operations debugfs_raw_data_fops = { ··· 804 829 805 830 static void edt_ft5x06_ts_teardown_debugfs(struct edt_ft5x06_ts_data *tsdata) 806 831 { 832 + guard(mutex)(&tsdata->mutex); 833 + 807 834 kfree(tsdata->raw_buffer); 835 + tsdata->raw_buffer = NULL; 808 836 } 809 837 810 838 #else
+10 -17
drivers/input/touchscreen/eeti_ts.c
··· 89 89 struct eeti_ts *eeti = dev_id; 90 90 int error; 91 91 92 - mutex_lock(&eeti->mutex); 92 + guard(mutex)(&eeti->mutex); 93 93 94 94 do { 95 95 /* ··· 109 109 110 110 } while (eeti->running && eeti->attn_gpio); 111 111 112 - mutex_unlock(&eeti->mutex); 113 112 return IRQ_HANDLED; 114 113 } 115 114 116 115 static void eeti_ts_start(struct eeti_ts *eeti) 117 116 { 118 - mutex_lock(&eeti->mutex); 117 + guard(mutex)(&eeti->mutex); 119 118 120 119 eeti->running = true; 121 120 enable_irq(eeti->client->irq); ··· 126 127 */ 127 128 if (eeti->attn_gpio && gpiod_get_value_cansleep(eeti->attn_gpio)) 128 129 eeti_ts_read(eeti); 129 - 130 - mutex_unlock(&eeti->mutex); 131 130 } 132 131 133 132 static void eeti_ts_stop(struct eeti_ts *eeti) ··· 235 238 struct eeti_ts *eeti = i2c_get_clientdata(client); 236 239 struct input_dev *input_dev = eeti->input; 237 240 238 - mutex_lock(&input_dev->mutex); 239 - 240 - if (input_device_enabled(input_dev)) 241 - eeti_ts_stop(eeti); 242 - 243 - mutex_unlock(&input_dev->mutex); 241 + scoped_guard(mutex, &input_dev->mutex) { 242 + if (input_device_enabled(input_dev)) 243 + eeti_ts_stop(eeti); 244 + } 244 245 245 246 if (device_may_wakeup(&client->dev)) 246 247 enable_irq_wake(client->irq); ··· 255 260 if (device_may_wakeup(&client->dev)) 256 261 disable_irq_wake(client->irq); 257 262 258 - mutex_lock(&input_dev->mutex); 259 - 260 - if (input_device_enabled(input_dev)) 261 - eeti_ts_start(eeti); 262 - 263 - mutex_unlock(&input_dev->mutex); 263 + scoped_guard(mutex, &input_dev->mutex) { 264 + if (input_device_enabled(input_dev)) 265 + eeti_ts_start(eeti); 266 + } 264 267 265 268 return 0; 266 269 }
+4 -4
drivers/input/touchscreen/ektf2127.c
··· 187 187 { 188 188 struct ektf2127_ts *ts = i2c_get_clientdata(to_i2c_client(dev)); 189 189 190 - mutex_lock(&ts->input->mutex); 190 + guard(mutex)(&ts->input->mutex); 191 + 191 192 if (input_device_enabled(ts->input)) 192 193 ektf2127_stop(ts->input); 193 - mutex_unlock(&ts->input->mutex); 194 194 195 195 return 0; 196 196 } ··· 199 199 { 200 200 struct ektf2127_ts *ts = i2c_get_clientdata(to_i2c_client(dev)); 201 201 202 - mutex_lock(&ts->input->mutex); 202 + guard(mutex)(&ts->input->mutex); 203 + 203 204 if (input_device_enabled(ts->input)) 204 205 ektf2127_start(ts->input); 205 - mutex_unlock(&ts->input->mutex); 206 206 207 207 return 0; 208 208 }
+40 -53
drivers/input/touchscreen/elants_i2c.c
··· 303 303 static const u8 rek[] = { CMD_HEADER_WRITE, 0x29, 0x00, 0x01 }; 304 304 static const u8 rek_resp[] = { CMD_HEADER_REK, 0x66, 0x66, 0x66 }; 305 305 306 - disable_irq(client->irq); 306 + scoped_guard(disable_irq, &client->irq) { 307 + ts->state = ELAN_WAIT_RECALIBRATION; 308 + reinit_completion(&ts->cmd_done); 307 309 308 - ts->state = ELAN_WAIT_RECALIBRATION; 309 - reinit_completion(&ts->cmd_done); 310 - 311 - elants_i2c_send(client, w_flashkey, sizeof(w_flashkey)); 312 - elants_i2c_send(client, rek, sizeof(rek)); 313 - 314 - enable_irq(client->irq); 310 + elants_i2c_send(client, w_flashkey, sizeof(w_flashkey)); 311 + elants_i2c_send(client, rek, sizeof(rek)); 312 + } 315 313 316 314 ret = wait_for_completion_interruptible_timeout(&ts->cmd_done, 317 315 msecs_to_jiffies(ELAN_CALI_TIMEOUT_MSEC)); ··· 904 906 static int elants_i2c_fw_update(struct elants_data *ts) 905 907 { 906 908 struct i2c_client *client = ts->client; 907 - const struct firmware *fw; 908 - char *fw_name; 909 909 int error; 910 910 911 - fw_name = kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version); 911 + const char *fw_name __free(kfree) = 912 + kasprintf(GFP_KERNEL, "elants_i2c_%04x.bin", ts->hw_version); 912 913 if (!fw_name) 913 914 return -ENOMEM; 914 915 915 916 dev_info(&client->dev, "requesting fw name = %s\n", fw_name); 917 + 918 + const struct firmware *fw __free(firmware) = NULL; 916 919 error = request_firmware(&fw, fw_name, &client->dev); 917 - kfree(fw_name); 918 920 if (error) { 919 921 dev_err(&client->dev, "failed to request firmware: %d\n", 920 922 error); ··· 924 926 if (fw->size % ELAN_FW_PAGESIZE) { 925 927 dev_err(&client->dev, "invalid firmware length: %zu\n", 926 928 fw->size); 927 - error = -EINVAL; 928 - goto out; 929 + return -EINVAL; 929 930 } 930 931 931 - disable_irq(client->irq); 932 + scoped_guard(disable_irq, &client->irq) { 933 + bool force_update = ts->iap_mode == ELAN_IAP_RECOVERY; 932 934 933 - error = elants_i2c_do_update_firmware(client, fw, 934 - ts->iap_mode == ELAN_IAP_RECOVERY); 935 - if (error) { 936 - dev_err(&client->dev, "firmware update failed: %d\n", error); 937 - ts->iap_mode = ELAN_IAP_RECOVERY; 938 - goto out_enable_irq; 935 + error = elants_i2c_do_update_firmware(client, fw, force_update); 936 + if (error) { 937 + dev_err(&client->dev, "firmware update failed: %d\n", 938 + error); 939 + } else { 940 + error = elants_i2c_initialize(ts); 941 + if (error) 942 + dev_err(&client->dev, 943 + "failed to initialize device after firmware update: %d\n", 944 + error); 945 + } 946 + 947 + ts->iap_mode = error ? ELAN_IAP_RECOVERY : ELAN_IAP_OPERATIONAL; 948 + ts->state = ELAN_STATE_NORMAL; 939 949 } 940 - 941 - error = elants_i2c_initialize(ts); 942 - if (error) { 943 - dev_err(&client->dev, 944 - "failed to initialize device after firmware update: %d\n", 945 - error); 946 - ts->iap_mode = ELAN_IAP_RECOVERY; 947 - goto out_enable_irq; 948 - } 949 - 950 - ts->iap_mode = ELAN_IAP_OPERATIONAL; 951 - 952 - out_enable_irq: 953 - ts->state = ELAN_STATE_NORMAL; 954 - enable_irq(client->irq); 955 950 msleep(100); 956 951 957 952 if (!error) 958 953 elants_i2c_calibrate(ts); 959 - out: 960 - release_firmware(fw); 954 + 961 955 return error; 962 956 } 963 957 ··· 1176 1186 struct elants_data *ts = i2c_get_clientdata(client); 1177 1187 int error; 1178 1188 1179 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 1180 - if (error) 1181 - return error; 1189 + scoped_cond_guard(mutex_intr, return -EINTR, &ts->sysfs_mutex) { 1190 + error = elants_i2c_calibrate(ts); 1191 + if (error) 1192 + return error; 1193 + } 1182 1194 1183 - error = elants_i2c_calibrate(ts); 1184 - 1185 - mutex_unlock(&ts->sysfs_mutex); 1186 - return error ?: count; 1195 + return count; 1187 1196 } 1188 1197 1189 1198 static ssize_t write_update_fw(struct device *dev, ··· 1193 1204 struct elants_data *ts = i2c_get_clientdata(client); 1194 1205 int error; 1195 1206 1196 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 1197 - if (error) 1198 - return error; 1207 + scoped_cond_guard(mutex_intr, return -EINTR, &ts->sysfs_mutex) { 1208 + error = elants_i2c_fw_update(ts); 1209 + if (error) 1210 + return error; 1211 + } 1199 1212 1200 - error = elants_i2c_fw_update(ts); 1201 - dev_dbg(dev, "firmware update result: %d\n", error); 1202 - 1203 - mutex_unlock(&ts->sysfs_mutex); 1204 - return error ?: count; 1213 + return count; 1205 1214 } 1206 1215 1207 1216 static ssize_t show_iap_mode(struct device *dev,
+16 -16
drivers/input/touchscreen/elo.c
··· 219 219 220 220 static int elo_command_10(struct elo *elo, unsigned char *packet) 221 221 { 222 - int rc = -1; 222 + int error; 223 223 int i; 224 224 unsigned char csum = 0xaa + ELO10_LEAD_BYTE; 225 225 226 - mutex_lock(&elo->cmd_mutex); 226 + guard(mutex)(&elo->cmd_mutex); 227 227 228 228 scoped_guard(serio_pause_rx, elo->serio) { 229 229 elo->expected_packet = toupper(packet[0]); 230 230 init_completion(&elo->cmd_done); 231 231 } 232 232 233 - if (serio_write(elo->serio, ELO10_LEAD_BYTE)) 234 - goto out; 233 + error = serio_write(elo->serio, ELO10_LEAD_BYTE); 234 + if (error) 235 + return error; 235 236 236 237 for (i = 0; i < ELO10_PACKET_LEN; i++) { 237 238 csum += packet[i]; 238 - if (serio_write(elo->serio, packet[i])) 239 - goto out; 239 + error = serio_write(elo->serio, packet[i]); 240 + if (error) 241 + return error; 240 242 } 241 243 242 - if (serio_write(elo->serio, csum)) 243 - goto out; 244 + error = serio_write(elo->serio, csum); 245 + if (error) 246 + return error; 244 247 245 248 wait_for_completion_timeout(&elo->cmd_done, HZ); 246 249 247 - if (elo->expected_packet == ELO10_TOUCH_PACKET) { 248 - /* We are back in reporting mode, the command was ACKed */ 249 - memcpy(packet, elo->response, ELO10_PACKET_LEN); 250 - rc = 0; 251 - } 250 + if (elo->expected_packet != ELO10_TOUCH_PACKET) 251 + return -EIO; 252 252 253 - out: 254 - mutex_unlock(&elo->cmd_mutex); 255 - return rc; 253 + /* We are back in reporting mode, the command was ACKed */ 254 + memcpy(packet, elo->response, ELO10_PACKET_LEN); 255 + return 0; 256 256 } 257 257 258 258 static int elo_setup_10(struct elo *elo)
+10 -21
drivers/input/touchscreen/exc3000.c
··· 234 234 int ret; 235 235 unsigned long time_left; 236 236 237 - mutex_lock(&data->query_lock); 237 + guard(mutex)(&data->query_lock); 238 238 239 239 reinit_completion(&data->wait_event); 240 240 ··· 243 243 244 244 ret = i2c_master_send(data->client, buf, EXC3000_LEN_VENDOR_REQUEST); 245 245 if (ret < 0) 246 - goto out_unlock; 246 + return ret; 247 247 248 - if (response) { 249 - time_left = wait_for_completion_timeout(&data->wait_event, 250 - timeout * HZ); 251 - if (time_left == 0) { 252 - ret = -ETIMEDOUT; 253 - goto out_unlock; 254 - } 248 + time_left = wait_for_completion_timeout(&data->wait_event, 249 + timeout * HZ); 250 + if (time_left == 0) 251 + return -ETIMEDOUT; 255 252 256 - if (data->buf[3] >= EXC3000_LEN_FRAME) { 257 - ret = -ENOSPC; 258 - goto out_unlock; 259 - } 253 + if (data->buf[3] >= EXC3000_LEN_FRAME) 254 + return -ENOSPC; 260 255 261 - memcpy(response, &data->buf[4], data->buf[3]); 262 - ret = data->buf[3]; 263 - } 264 - 265 - out_unlock: 266 - mutex_unlock(&data->query_lock); 267 - 268 - return ret; 256 + memcpy(response, &data->buf[4], data->buf[3]); 257 + return data->buf[3]; 269 258 } 270 259 271 260 static ssize_t fw_version_show(struct device *dev,
+8
drivers/input/touchscreen/goodix_berlin_core.c
··· 628 628 629 629 touchscreen_parse_properties(cd->input_dev, true, &cd->props); 630 630 631 + /* 632 + * The resolution of these touchscreens is about 10 units/mm, the actual 633 + * resolution does not matter much since we set INPUT_PROP_DIRECT. 634 + * Set it to 10 to ensure userspace isn't off by an order of magnitude. 635 + */ 636 + input_abs_set_res(cd->input_dev, ABS_MT_POSITION_X, 10); 637 + input_abs_set_res(cd->input_dev, ABS_MT_POSITION_Y, 10); 638 + 631 639 error = input_mt_init_slots(cd->input_dev, GOODIX_BERLIN_MAX_TOUCH, 632 640 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); 633 641 if (error)
+15 -14
drivers/input/touchscreen/goodix_fwupload.c
··· 188 188 189 189 static int goodix_firmware_upload(struct goodix_ts_data *ts) 190 190 { 191 - const struct firmware *fw; 192 191 char fw_name[64]; 193 192 const u8 *data; 194 193 int error; 195 194 196 195 snprintf(fw_name, sizeof(fw_name), "goodix/%s", ts->firmware_name); 197 196 197 + const struct firmware *fw __free(firmware) = NULL; 198 198 error = request_firmware(&fw, fw_name, &ts->client->dev); 199 199 if (error) { 200 200 dev_err(&ts->client->dev, "Firmware request error %d\n", error); ··· 203 203 204 204 error = goodix_firmware_verify(&ts->client->dev, fw); 205 205 if (error) 206 - goto release; 206 + return error; 207 207 208 208 error = goodix_reset_no_int_sync(ts); 209 209 if (error) 210 - goto release; 210 + return error; 211 211 212 212 error = goodix_enter_upload_mode(ts->client); 213 213 if (error) 214 - goto release; 214 + return error; 215 215 216 216 /* Select SRAM bank 0 and upload section 1 & 2 */ 217 217 error = goodix_i2c_write_u8(ts->client, 218 218 GOODIX_REG_MISCTL_SRAM_BANK, 0x00); 219 219 if (error) 220 - goto release; 220 + return error; 221 221 222 222 data = fw->data + GOODIX_FW_HEADER_LENGTH; 223 223 error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 224 224 data, 2 * GOODIX_FW_SECTION_LENGTH); 225 225 if (error) 226 - goto release; 226 + return error; 227 227 228 228 /* Select SRAM bank 1 and upload section 3 & 4 */ 229 229 error = goodix_i2c_write_u8(ts->client, 230 230 GOODIX_REG_MISCTL_SRAM_BANK, 0x01); 231 231 if (error) 232 - goto release; 232 + return error; 233 233 234 234 data += 2 * GOODIX_FW_SECTION_LENGTH; 235 235 error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 236 236 data, 2 * GOODIX_FW_SECTION_LENGTH); 237 237 if (error) 238 - goto release; 238 + return error; 239 239 240 240 /* Select SRAM bank 2 and upload the DSP firmware */ 241 241 error = goodix_i2c_write_u8(ts->client, 242 242 GOODIX_REG_MISCTL_SRAM_BANK, 0x02); 243 243 if (error) 244 - goto release; 244 + return error; 245 245 246 246 data += 2 * GOODIX_FW_SECTION_LENGTH; 247 247 error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 248 248 data, GOODIX_FW_DSP_LENGTH); 249 249 if (error) 250 - goto release; 250 + return error; 251 251 252 252 error = goodix_start_firmware(ts->client); 253 253 if (error) 254 - goto release; 254 + return error; 255 255 256 256 error = goodix_int_sync(ts); 257 - release: 258 - release_firmware(fw); 259 - return error; 257 + if (error) 258 + return error; 259 + 260 + return 0; 260 261 } 261 262 262 263 static int goodix_prepare_bak_ref(struct goodix_ts_data *ts)
+20 -34
drivers/input/touchscreen/hideep.c
··· 869 869 { 870 870 struct i2c_client *client = to_i2c_client(dev); 871 871 struct hideep_ts *ts = i2c_get_clientdata(client); 872 - const struct firmware *fw_entry; 873 - char *fw_name; 874 872 int mode; 875 873 int error; 876 874 ··· 876 878 if (error) 877 879 return error; 878 880 879 - fw_name = kasprintf(GFP_KERNEL, "hideep_ts_%04x.bin", 880 - be16_to_cpu(ts->dwz_info.product_id)); 881 + const char *fw_name __free(kfree) = 882 + kasprintf(GFP_KERNEL, "hideep_ts_%04x.bin", 883 + be16_to_cpu(ts->dwz_info.product_id)); 881 884 if (!fw_name) 882 885 return -ENOMEM; 883 886 887 + const struct firmware *fw_entry __free(firmware) = NULL; 884 888 error = request_firmware(&fw_entry, fw_name, dev); 885 889 if (error) { 886 890 dev_err(dev, "failed to request firmware %s: %d", 887 891 fw_name, error); 888 - goto out_free_fw_name; 892 + return error; 889 893 } 890 894 891 895 if (fw_entry->size % sizeof(__be32)) { 892 896 dev_err(dev, "invalid firmware size %zu\n", fw_entry->size); 893 - error = -EINVAL; 894 - goto out_release_fw; 897 + return -EINVAL; 895 898 } 896 899 897 900 if (fw_entry->size > ts->fw_size) { 898 901 dev_err(dev, "fw size (%zu) is too big (memory size %d)\n", 899 902 fw_entry->size, ts->fw_size); 900 - error = -EFBIG; 901 - goto out_release_fw; 903 + return -EFBIG; 902 904 } 903 905 904 - mutex_lock(&ts->dev_mutex); 905 - disable_irq(client->irq); 906 + scoped_guard(mutex, &ts->dev_mutex) { 907 + guard(disable_irq)(&client->irq); 906 908 907 - error = hideep_update_firmware(ts, (const __be32 *)fw_entry->data, 908 - fw_entry->size); 909 + error = hideep_update_firmware(ts, 910 + (const __be32 *)fw_entry->data, 911 + fw_entry->size); 912 + if (error) 913 + return error; 914 + } 909 915 910 - enable_irq(client->irq); 911 - mutex_unlock(&ts->dev_mutex); 912 - 913 - out_release_fw: 914 - release_firmware(fw_entry); 915 - out_free_fw_name: 916 - kfree(fw_name); 917 - 918 - return error ?: count; 916 + return count; 919 917 } 920 918 921 919 static ssize_t hideep_fw_version_show(struct device *dev, ··· 919 925 { 920 926 struct i2c_client *client = to_i2c_client(dev); 921 927 struct hideep_ts *ts = i2c_get_clientdata(client); 922 - ssize_t len; 923 928 924 - mutex_lock(&ts->dev_mutex); 925 - len = sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.release_ver)); 926 - mutex_unlock(&ts->dev_mutex); 927 - 928 - return len; 929 + guard(mutex)(&ts->dev_mutex); 930 + return sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.release_ver)); 929 931 } 930 932 931 933 static ssize_t hideep_product_id_show(struct device *dev, ··· 929 939 { 930 940 struct i2c_client *client = to_i2c_client(dev); 931 941 struct hideep_ts *ts = i2c_get_clientdata(client); 932 - ssize_t len; 933 942 934 - mutex_lock(&ts->dev_mutex); 935 - len = sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.product_id)); 936 - mutex_unlock(&ts->dev_mutex); 937 - 938 - return len; 943 + guard(mutex)(&ts->dev_mutex); 944 + return sysfs_emit(buf, "%04x\n", be16_to_cpu(ts->dwz_info.product_id)); 939 945 } 940 946 941 947 static DEVICE_ATTR(version, 0664, hideep_fw_version_show, NULL);
+11 -20
drivers/input/touchscreen/hycon-hy46xx.c
··· 181 181 struct hycon_hy46xx_attribute *attr = 182 182 container_of(dattr, struct hycon_hy46xx_attribute, dattr); 183 183 u8 *field = (u8 *)tsdata + attr->field_offset; 184 - size_t count = 0; 185 184 int error = 0; 186 185 int val; 187 186 188 - mutex_lock(&tsdata->mutex); 187 + guard(mutex)(&tsdata->mutex); 189 188 190 189 error = regmap_read(tsdata->regmap, attr->address, &val); 191 - if (error < 0) { 190 + if (error) { 192 191 dev_err(&tsdata->client->dev, 193 192 "Failed to fetch attribute %s, error %d\n", 194 193 dattr->attr.name, error); 195 - goto out; 194 + return error; 196 195 } 197 196 198 197 if (val != *field) { ··· 201 202 *field = val; 202 203 } 203 204 204 - count = sysfs_emit(buf, "%d\n", val); 205 - 206 - out: 207 - mutex_unlock(&tsdata->mutex); 208 - return error ?: count; 205 + return sysfs_emit(buf, "%d\n", val); 209 206 } 210 207 211 208 static ssize_t hycon_hy46xx_setting_store(struct device *dev, ··· 216 221 unsigned int val; 217 222 int error; 218 223 219 - mutex_lock(&tsdata->mutex); 224 + guard(mutex)(&tsdata->mutex); 220 225 221 226 error = kstrtouint(buf, 0, &val); 222 227 if (error) 223 - goto out; 228 + return error; 224 229 225 - if (val < attr->limit_low || val > attr->limit_high) { 226 - error = -ERANGE; 227 - goto out; 228 - } 230 + if (val < attr->limit_low || val > attr->limit_high) 231 + return -ERANGE; 229 232 230 233 error = regmap_write(tsdata->regmap, attr->address, val); 231 - if (error < 0) { 234 + if (error) { 232 235 dev_err(&tsdata->client->dev, 233 236 "Failed to update attribute %s, error: %d\n", 234 237 dattr->attr.name, error); 235 - goto out; 238 + return error; 236 239 } 237 240 *field = val; 238 241 239 - out: 240 - mutex_unlock(&tsdata->mutex); 241 - return error ?: count; 242 + return count; 242 243 } 243 244 244 245 static HYCON_ATTR_U8(threshold, 0644, HY46XX_THRESHOLD, 0, 255);
+16 -14
drivers/input/touchscreen/imagis.c
··· 366 366 { 367 367 struct i2c_client *client = to_i2c_client(dev); 368 368 struct imagis_ts *ts = i2c_get_clientdata(client); 369 - int retval = 0; 369 + int error; 370 370 371 - mutex_lock(&ts->input_dev->mutex); 371 + guard(mutex)(&ts->input_dev->mutex); 372 372 373 - if (input_device_enabled(ts->input_dev)) 374 - retval = imagis_stop(ts); 373 + if (input_device_enabled(ts->input_dev)) { 374 + error = imagis_stop(ts); 375 + if (error) 376 + return error; 377 + } 375 378 376 - mutex_unlock(&ts->input_dev->mutex); 377 - 378 - return retval; 379 + return 0; 379 380 } 380 381 381 382 static int imagis_resume(struct device *dev) 382 383 { 383 384 struct i2c_client *client = to_i2c_client(dev); 384 385 struct imagis_ts *ts = i2c_get_clientdata(client); 385 - int retval = 0; 386 + int error; 386 387 387 - mutex_lock(&ts->input_dev->mutex); 388 + guard(mutex)(&ts->input_dev->mutex); 388 389 389 - if (input_device_enabled(ts->input_dev)) 390 - retval = imagis_start(ts); 390 + if (input_device_enabled(ts->input_dev)) { 391 + error = imagis_start(ts); 392 + if (error) 393 + return error; 394 + } 391 395 392 - mutex_unlock(&ts->input_dev->mutex); 393 - 394 - return retval; 396 + return 0; 395 397 } 396 398 397 399 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
+9 -10
drivers/input/touchscreen/imx6ul_tsc.c
··· 551 551 struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); 552 552 struct input_dev *input_dev = tsc->input; 553 553 554 - mutex_lock(&input_dev->mutex); 554 + guard(mutex)(&input_dev->mutex); 555 555 556 556 if (input_device_enabled(input_dev)) 557 557 imx6ul_tsc_stop(tsc); 558 - 559 - mutex_unlock(&input_dev->mutex); 560 558 561 559 return 0; 562 560 } ··· 564 566 struct platform_device *pdev = to_platform_device(dev); 565 567 struct imx6ul_tsc *tsc = platform_get_drvdata(pdev); 566 568 struct input_dev *input_dev = tsc->input; 567 - int retval = 0; 569 + int error; 568 570 569 - mutex_lock(&input_dev->mutex); 571 + guard(mutex)(&input_dev->mutex); 570 572 571 - if (input_device_enabled(input_dev)) 572 - retval = imx6ul_tsc_start(tsc); 573 + if (input_device_enabled(input_dev)) { 574 + error = imx6ul_tsc_start(tsc); 575 + if (error) 576 + return error; 577 + } 573 578 574 - mutex_unlock(&input_dev->mutex); 575 - 576 - return retval; 579 + return 0; 577 580 } 578 581 579 582 static DEFINE_SIMPLE_DEV_PM_OPS(imx6ul_tsc_pm_ops,
+2 -6
drivers/input/touchscreen/ipaq-micro-ts.c
··· 47 47 { 48 48 struct ipaq_micro *micro = ts->micro; 49 49 50 - spin_lock_irq(&micro->lock); 50 + guard(spinlock_irq)(&micro->lock); 51 51 52 52 if (enable) { 53 53 micro->ts = micro_ts_receive; ··· 56 56 micro->ts = NULL; 57 57 micro->ts_data = NULL; 58 58 } 59 - 60 - spin_unlock_irq(&ts->micro->lock); 61 59 } 62 60 63 61 static int micro_ts_open(struct input_dev *input) ··· 131 133 struct touchscreen_data *ts = dev_get_drvdata(dev); 132 134 struct input_dev *input = ts->input; 133 135 134 - mutex_lock(&input->mutex); 136 + guard(mutex)(&input->mutex); 135 137 136 138 if (input_device_enabled(input)) 137 139 micro_ts_toggle_receive(ts, true); 138 - 139 - mutex_unlock(&input->mutex); 140 140 141 141 return 0; 142 142 }
+86 -104
drivers/input/touchscreen/iqs5xx.c
··· 73 73 #define IQS5XX_CSTM_LEN (IQS5XX_PMAP_END + 1 - IQS5XX_CSTM) 74 74 #define IQS5XX_PMAP_LEN (IQS5XX_PMAP_END + 1 - IQS5XX_CHKSM) 75 75 76 - #define IQS5XX_REC_HDR_LEN 4 77 - #define IQS5XX_REC_LEN_MAX 255 76 + /* Length of firmware header in hexadecimal characters */ 77 + #define IQS5XX_REC_HDR_LEN_HEX (1 /* start */ + 2 /* size */ + \ 78 + 4 /* addr */ + 2 /* type */) 79 + #define IQS5XX_REC_HDR_SIZE 4 /* size + addr (2 bytes) + type, in bytes*/ 80 + #define IQS5XX_REC_DATA_SIZE 255 /* maximum size of the data portion */ 78 81 #define IQS5XX_REC_TYPE_DATA 0x00 79 82 #define IQS5XX_REC_TYPE_EOF 0x01 80 83 ··· 99 96 u8 major_ver; 100 97 u8 minor_ver; 101 98 u8 bl_status; 102 - } __packed; 103 - 104 - struct iqs5xx_ihex_rec { 105 - char start; 106 - char len[2]; 107 - char addr[4]; 108 - char type[2]; 109 - char data[2]; 110 99 } __packed; 111 100 112 101 struct iqs5xx_touch_data { ··· 351 356 } 352 357 353 358 static int iqs5xx_bl_write(struct i2c_client *client, 354 - u16 bl_addr, u8 *pmap_data, u16 pmap_len) 359 + u16 bl_addr, const u8 *pmap_data, u16 pmap_len) 355 360 { 356 361 struct i2c_msg msg; 357 362 int ret, i; ··· 390 395 } 391 396 392 397 static int iqs5xx_bl_verify(struct i2c_client *client, 393 - u16 bl_addr, u8 *pmap_data, u16 pmap_len) 398 + u16 bl_addr, const u8 *pmap_data, u16 pmap_len) 394 399 { 395 400 struct i2c_msg msg; 396 401 int ret, i; ··· 441 446 if (!iqs5xx->dev_id_info.bl_status) 442 447 return 0; 443 448 444 - mutex_lock(&iqs5xx->lock); 449 + guard(mutex)(&iqs5xx->lock); 445 450 446 451 /* 447 452 * Addressing the device outside of a communication window prompts it 448 453 * to assert the RDY output, so disable the interrupt line to prevent 449 454 * the handler from servicing a false interrupt. 450 455 */ 451 - disable_irq(client->irq); 456 + guard(disable_irq)(&client->irq); 452 457 453 458 error1 = iqs5xx_write_byte(client, IQS5XX_SYS_CTRL1, state); 454 459 error2 = iqs5xx_write_byte(client, IQS5XX_END_COMM, 0); 455 460 456 461 usleep_range(50, 100); 457 - enable_irq(client->irq); 458 462 459 - mutex_unlock(&iqs5xx->lock); 460 - 461 - if (error1) 462 - return error1; 463 - 464 - return error2; 463 + return error1 ?: error2; 465 464 } 466 465 467 466 static int iqs5xx_open(struct input_dev *input) ··· 692 703 static int iqs5xx_fw_file_parse(struct i2c_client *client, 693 704 const char *fw_file, u8 *pmap) 694 705 { 695 - const struct firmware *fw; 696 - struct iqs5xx_ihex_rec *rec; 697 706 size_t pos = 0; 698 707 int error, i; 699 708 u16 rec_num = 1; 700 709 u16 rec_addr; 701 710 u8 rec_len, rec_type, rec_chksm, chksm; 702 - u8 rec_hdr[IQS5XX_REC_HDR_LEN]; 703 - u8 rec_data[IQS5XX_REC_LEN_MAX]; 711 + u8 rec_hdr[IQS5XX_REC_HDR_SIZE]; 712 + u8 rec_data[IQS5XX_REC_DATA_SIZE]; 704 713 705 714 /* 706 715 * Firmware exported from the vendor's configuration tool deviates from ··· 709 722 * Because the ihex2fw tool tolerates neither (1) nor (2), the slightly 710 723 * nonstandard ihex firmware is parsed directly by the driver. 711 724 */ 725 + const struct firmware *fw __free(firmware) = NULL; 712 726 error = request_firmware(&fw, fw_file, &client->dev); 713 727 if (error) { 714 728 dev_err(&client->dev, "Failed to request firmware %s: %d\n", ··· 718 730 } 719 731 720 732 do { 721 - if (pos + sizeof(*rec) > fw->size) { 733 + if (pos + IQS5XX_REC_HDR_LEN_HEX > fw->size) { 722 734 dev_err(&client->dev, "Insufficient firmware size\n"); 723 - error = -EINVAL; 724 - break; 735 + return -EINVAL; 725 736 } 726 - rec = (struct iqs5xx_ihex_rec *)(fw->data + pos); 727 - pos += sizeof(*rec); 728 737 729 - if (rec->start != ':') { 738 + if (fw->data[pos] != ':') { 730 739 dev_err(&client->dev, "Invalid start at record %u\n", 731 740 rec_num); 732 - error = -EINVAL; 733 - break; 741 + return -EINVAL; 734 742 } 735 743 736 - error = hex2bin(rec_hdr, rec->len, sizeof(rec_hdr)); 744 + /* Convert all 3 fields (length, address, and type) in one go */ 745 + error = hex2bin(rec_hdr, &fw->data[pos + 1], sizeof(rec_hdr)); 737 746 if (error) { 738 747 dev_err(&client->dev, "Invalid header at record %u\n", 739 748 rec_num); 740 - break; 749 + return error; 741 750 } 751 + pos += IQS5XX_REC_HDR_LEN_HEX; 742 752 743 753 rec_len = *rec_hdr; 744 754 rec_addr = get_unaligned_be16(rec_hdr + sizeof(rec_len)); 745 755 rec_type = *(rec_hdr + sizeof(rec_len) + sizeof(rec_addr)); 746 756 747 - if (pos + rec_len * 2 > fw->size) { 757 + /* 758 + * Check if we have enough data for the data portion of the 759 + * record, as well as the checksum byte. Everything is doubled 760 + * because data is in ASCII HEX and not binary format. 761 + */ 762 + if (pos + (rec_len + sizeof(rec_chksm)) * 2 > fw->size) { 748 763 dev_err(&client->dev, "Insufficient firmware size\n"); 749 - error = -EINVAL; 750 - break; 764 + return -EINVAL; 751 765 } 752 - pos += (rec_len * 2); 753 766 754 - error = hex2bin(rec_data, rec->data, rec_len); 767 + error = hex2bin(rec_data, &fw->data[pos], rec_len); 755 768 if (error) { 756 769 dev_err(&client->dev, "Invalid data at record %u\n", 757 770 rec_num); 758 - break; 771 + return error; 759 772 } 773 + pos += rec_len * 2; 760 774 761 - error = hex2bin(&rec_chksm, 762 - rec->data + rec_len * 2, sizeof(rec_chksm)); 775 + error = hex2bin(&rec_chksm, &fw->data[pos], sizeof(rec_chksm)); 763 776 if (error) { 764 777 dev_err(&client->dev, "Invalid checksum at record %u\n", 765 778 rec_num); 766 - break; 779 + return error; 767 780 } 781 + pos += 2; 768 782 769 783 chksm = 0; 770 784 for (i = 0; i < sizeof(rec_hdr); i++) ··· 790 800 dev_err(&client->dev, 791 801 "Invalid address at record %u\n", 792 802 rec_num); 793 - error = -EINVAL; 794 - } else { 795 - memcpy(pmap + rec_addr - IQS5XX_CHKSM, 796 - rec_data, rec_len); 803 + return -EINVAL; 797 804 } 805 + 806 + memcpy(pmap + rec_addr - IQS5XX_CHKSM, 807 + rec_data, rec_len); 798 808 break; 809 + 799 810 case IQS5XX_REC_TYPE_EOF: 800 811 break; 812 + 801 813 default: 802 814 dev_err(&client->dev, "Invalid type at record %u\n", 803 815 rec_num); 804 - error = -EINVAL; 816 + return -EINVAL; 805 817 } 806 - 807 - if (error) 808 - break; 809 818 810 819 rec_num++; 811 820 while (pos < fw->size) { ··· 814 825 } 815 826 } while (rec_type != IQS5XX_REC_TYPE_EOF); 816 827 817 - release_firmware(fw); 818 - 819 - return error; 828 + return 0; 820 829 } 821 830 822 - static int iqs5xx_fw_file_write(struct i2c_client *client, const char *fw_file) 831 + static int iqs5xx_update_firmware(struct iqs5xx_private *iqs5xx, const u8 *pmap) 823 832 { 824 - struct iqs5xx_private *iqs5xx = i2c_get_clientdata(client); 825 - int error, error_init = 0; 826 - u8 *pmap; 827 - 828 - pmap = kzalloc(IQS5XX_PMAP_LEN, GFP_KERNEL); 829 - if (!pmap) 830 - return -ENOMEM; 831 - 832 - error = iqs5xx_fw_file_parse(client, fw_file, pmap); 833 - if (error) 834 - goto err_kfree; 835 - 836 - mutex_lock(&iqs5xx->lock); 837 - 838 - /* 839 - * Disable the interrupt line in case the first attempt(s) to enter the 840 - * bootloader don't happen quickly enough, in which case the device may 841 - * assert the RDY output until the next attempt. 842 - */ 843 - disable_irq(client->irq); 833 + struct i2c_client *client = iqs5xx->client; 834 + int error; 844 835 845 836 iqs5xx->dev_id_info.bl_status = 0; 846 837 ··· 828 859 if (error) { 829 860 error = iqs5xx_bl_open(client); 830 861 if (error) 831 - goto err_reset; 862 + return error; 832 863 } 833 864 834 865 error = iqs5xx_bl_write(client, IQS5XX_CHKSM, pmap, IQS5XX_PMAP_LEN); 835 866 if (error) 836 - goto err_reset; 867 + return error; 837 868 838 869 error = iqs5xx_bl_cmd(client, IQS5XX_BL_CMD_CRC, 0); 839 870 if (error) 840 - goto err_reset; 871 + return error; 841 872 842 873 error = iqs5xx_bl_verify(client, IQS5XX_CSTM, 843 874 pmap + IQS5XX_CHKSM_LEN + IQS5XX_APP_LEN, 844 875 IQS5XX_CSTM_LEN); 876 + if (error) 877 + return error; 845 878 846 - err_reset: 879 + return 0; 880 + } 881 + 882 + static int iqs5xx_fw_file_write(struct i2c_client *client, const char *fw_file) 883 + { 884 + struct iqs5xx_private *iqs5xx = i2c_get_clientdata(client); 885 + int error, error_init = 0; 886 + 887 + u8 *pmap __free(kfree) = kzalloc(IQS5XX_PMAP_LEN, GFP_KERNEL); 888 + if (!pmap) 889 + return -ENOMEM; 890 + 891 + error = iqs5xx_fw_file_parse(client, fw_file, pmap); 892 + if (error) 893 + return error; 894 + 895 + guard(mutex)(&iqs5xx->lock); 896 + 897 + /* 898 + * Disable the interrupt line in case the first attempt(s) to enter the 899 + * bootloader don't happen quickly enough, in which case the device may 900 + * assert the RDY output until the next attempt. 901 + */ 902 + guard(disable_irq)(&client->irq); 903 + 904 + error = iqs5xx_update_firmware(iqs5xx, pmap); 905 + 847 906 iqs5xx_reset(client); 848 907 usleep_range(15000, 15100); 849 908 ··· 879 882 if (!iqs5xx->dev_id_info.bl_status) 880 883 error_init = error_init ? : -EINVAL; 881 884 882 - enable_irq(client->irq); 883 - 884 - mutex_unlock(&iqs5xx->lock); 885 - 886 - err_kfree: 887 - kfree(pmap); 888 - 889 - return error ? : error_init; 885 + return error ?: error_init; 890 886 } 891 887 892 888 static ssize_t fw_file_store(struct device *dev, ··· 975 985 { 976 986 struct iqs5xx_private *iqs5xx = dev_get_drvdata(dev); 977 987 struct input_dev *input = iqs5xx->input; 978 - int error = 0; 979 988 980 989 if (!input || device_may_wakeup(dev)) 981 - return error; 990 + return 0; 982 991 983 - mutex_lock(&input->mutex); 984 - 992 + guard(mutex)(&input->mutex); 985 993 if (input_device_enabled(input)) 986 - error = iqs5xx_set_state(iqs5xx->client, IQS5XX_SUSPEND); 994 + return iqs5xx_set_state(iqs5xx->client, IQS5XX_SUSPEND); 987 995 988 - mutex_unlock(&input->mutex); 989 - 990 - return error; 996 + return 0; 991 997 } 992 998 993 999 static int iqs5xx_resume(struct device *dev) 994 1000 { 995 1001 struct iqs5xx_private *iqs5xx = dev_get_drvdata(dev); 996 1002 struct input_dev *input = iqs5xx->input; 997 - int error = 0; 998 1003 999 1004 if (!input || device_may_wakeup(dev)) 1000 - return error; 1005 + return 0; 1001 1006 1002 - mutex_lock(&input->mutex); 1003 - 1007 + guard(mutex)(&input->mutex); 1004 1008 if (input_device_enabled(input)) 1005 - error = iqs5xx_set_state(iqs5xx->client, IQS5XX_RESUME); 1009 + return iqs5xx_set_state(iqs5xx->client, IQS5XX_RESUME); 1006 1010 1007 - mutex_unlock(&input->mutex); 1008 - 1009 - return error; 1011 + return 0; 1010 1012 } 1011 1013 1012 1014 static DEFINE_SIMPLE_DEV_PM_OPS(iqs5xx_pm, iqs5xx_suspend, iqs5xx_resume);
+8 -16
drivers/input/touchscreen/iqs7211.c
··· 2060 2060 2061 2061 for (i = 0; i < dev_desc->num_kp_events; i++) { 2062 2062 const char *event_name = dev_desc->kp_events[i].name; 2063 - struct fwnode_handle *event_node; 2064 2063 2065 2064 if (dev_desc->kp_events[i].reg_grp != reg_grp) 2066 2065 continue; 2067 2066 2068 2067 reg_field.mask |= dev_desc->kp_events[i].enable; 2069 2068 2070 - if (event_name) 2071 - event_node = fwnode_get_named_child_node(reg_grp_node, 2072 - event_name); 2073 - else 2074 - event_node = fwnode_handle_get(reg_grp_node); 2075 - 2069 + struct fwnode_handle *event_node __free(fwnode_handle) = 2070 + event_name ? fwnode_get_named_child_node(reg_grp_node, 2071 + event_name) : 2072 + fwnode_handle_get(reg_grp_node); 2076 2073 if (!event_node) 2077 2074 continue; 2078 2075 ··· 2077 2080 dev_desc->kp_events[i].reg_grp, 2078 2081 dev_desc->kp_events[i].reg_key, 2079 2082 &iqs7211->kp_code[i]); 2080 - fwnode_handle_put(event_node); 2081 2083 if (error) 2082 2084 return error; 2083 2085 ··· 2492 2496 2493 2497 for (reg_grp = 0; reg_grp < IQS7211_NUM_REG_GRPS; reg_grp++) { 2494 2498 const char *reg_grp_name = iqs7211_reg_grp_names[reg_grp]; 2495 - struct fwnode_handle *reg_grp_node; 2496 2499 2497 - if (reg_grp_name) 2498 - reg_grp_node = device_get_named_child_node(&client->dev, 2499 - reg_grp_name); 2500 - else 2501 - reg_grp_node = fwnode_handle_get(dev_fwnode(&client->dev)); 2502 - 2500 + struct fwnode_handle *reg_grp_node __free(fwnode_handle) = 2501 + reg_grp_name ? device_get_named_child_node(&client->dev, 2502 + reg_grp_name) : 2503 + fwnode_handle_get(dev_fwnode(&client->dev)); 2503 2504 if (!reg_grp_node) 2504 2505 continue; 2505 2506 2506 2507 error = iqs7211_parse_reg_grp(iqs7211, reg_grp_node, reg_grp); 2507 - fwnode_handle_put(reg_grp_node); 2508 2508 if (error) 2509 2509 return error; 2510 2510 }
+2 -6
drivers/input/touchscreen/lpc32xx_ts.c
··· 279 279 * avoid calling the TSC stop and start functions as the TSC 280 280 * isn't yet clocked. 281 281 */ 282 - mutex_lock(&input->mutex); 282 + guard(mutex)(&input->mutex); 283 283 284 284 if (input_device_enabled(input)) { 285 285 if (device_may_wakeup(dev)) ··· 287 287 else 288 288 lpc32xx_stop_tsc(tsc); 289 289 } 290 - 291 - mutex_unlock(&input->mutex); 292 290 293 291 return 0; 294 292 } ··· 296 298 struct lpc32xx_tsc *tsc = dev_get_drvdata(dev); 297 299 struct input_dev *input = tsc->dev; 298 300 299 - mutex_lock(&input->mutex); 301 + guard(mutex)(&input->mutex); 300 302 301 303 if (input_device_enabled(input)) { 302 304 if (device_may_wakeup(dev)) ··· 304 306 else 305 307 lpc32xx_setup_tsc(tsc); 306 308 } 307 - 308 - mutex_unlock(&input->mutex); 309 309 310 310 return 0; 311 311 }
+44 -77
drivers/input/touchscreen/melfas_mip4.c
··· 881 881 const u8 *data, int length, u16 buf_addr) 882 882 { 883 883 u8 cmd[6]; 884 - u8 *data_buf; 885 - u16 buf_offset; 886 884 int ret; 887 885 int error; 888 886 ··· 893 895 return -EINVAL; 894 896 } 895 897 896 - data_buf = kmalloc(2 + MIP4_BL_PACKET_SIZE, GFP_KERNEL); 898 + u8 *data_buf __free(kfree) = kmalloc(2 + MIP4_BL_PACKET_SIZE, 899 + GFP_KERNEL); 897 900 if (!data_buf) 898 901 return -ENOMEM; 899 902 ··· 907 908 error = ret < 0 ? ret : -EIO; 908 909 dev_err(&ts->client->dev, 909 910 "Failed to send write page address: %d\n", error); 910 - goto out; 911 + return error; 911 912 } 912 913 913 914 /* Size */ ··· 919 920 error = ret < 0 ? ret : -EIO; 920 921 dev_err(&ts->client->dev, 921 922 "Failed to send write page size: %d\n", error); 922 - goto out; 923 + return error; 923 924 } 924 925 925 926 /* Data */ 926 - for (buf_offset = 0; 927 + for (int buf_offset = 0; 927 928 buf_offset < length; 928 929 buf_offset += MIP4_BL_PACKET_SIZE) { 929 930 dev_dbg(&ts->client->dev, ··· 938 939 dev_err(&ts->client->dev, 939 940 "Failed to read chunk at %#04x (size %d): %d\n", 940 941 buf_offset, MIP4_BL_PACKET_SIZE, error); 941 - goto out; 942 + return error; 942 943 } 943 944 } 944 945 ··· 951 952 error = ret < 0 ? ret : -EIO; 952 953 dev_err(&ts->client->dev, 953 954 "Failed to send 'write' command: %d\n", error); 954 - goto out; 955 + return error; 955 956 } 956 957 957 958 /* Status */ 958 959 error = mip4_bl_read_status(ts); 960 + if (error) 961 + return error; 959 962 960 - out: 961 - kfree(data_buf); 962 - return error ? error : 0; 963 + return 0; 963 964 } 964 965 965 966 static int mip4_bl_verify_page(struct mip4_ts *ts, int offset, 966 967 const u8 *data, int length, int buf_addr) 967 968 { 968 969 u8 cmd[8]; 969 - u8 *read_buf; 970 - int buf_offset; 971 - struct i2c_msg msg[] = { 972 - { 973 - .addr = ts->client->addr, 974 - .flags = 0, 975 - .buf = cmd, 976 - .len = 2, 977 - }, { 978 - .addr = ts->client->addr, 979 - .flags = I2C_M_RD, 980 - .len = MIP4_BL_PACKET_SIZE, 981 - }, 982 - }; 983 970 int ret; 984 971 int error; 985 972 ··· 1014 1029 return error; 1015 1030 1016 1031 /* Read */ 1017 - msg[1].buf = read_buf = kmalloc(MIP4_BL_PACKET_SIZE, GFP_KERNEL); 1032 + u8 *read_buf __free(kfree) = kmalloc(MIP4_BL_PACKET_SIZE, GFP_KERNEL); 1018 1033 if (!read_buf) 1019 1034 return -ENOMEM; 1020 1035 1021 - for (buf_offset = 0; 1036 + struct i2c_msg msg[] = { 1037 + { 1038 + .addr = ts->client->addr, 1039 + .flags = 0, 1040 + .buf = cmd, 1041 + .len = 2, 1042 + }, { 1043 + .addr = ts->client->addr, 1044 + .flags = I2C_M_RD, 1045 + .buf = read_buf, 1046 + .len = MIP4_BL_PACKET_SIZE, 1047 + }, 1048 + }; 1049 + 1050 + for (int buf_offset = 0; 1022 1051 buf_offset < length; 1023 1052 buf_offset += MIP4_BL_PACKET_SIZE) { 1024 1053 dev_dbg(&ts->client->dev, ··· 1045 1046 dev_err(&ts->client->dev, 1046 1047 "Failed to read chunk at %#04x (size %d): %d\n", 1047 1048 buf_offset, MIP4_BL_PACKET_SIZE, error); 1048 - break; 1049 + return error; 1049 1050 } 1050 1051 1051 1052 if (memcmp(&data[buf_offset], read_buf, MIP4_BL_PACKET_SIZE)) { ··· 1063 1064 DUMP_PREFIX_OFFSET, 16, 1, 1064 1065 read_buf, MIP4_BL_PAGE_SIZE, false); 1065 1066 #endif 1066 - error = -EINVAL; 1067 - break; 1067 + return -EINVAL; 1068 1068 } 1069 1069 } 1070 1070 1071 - kfree(read_buf); 1072 - return error ? error : 0; 1071 + return 0; 1073 1072 } 1074 1073 1075 1074 /* ··· 1287 1290 { 1288 1291 struct i2c_client *client = to_i2c_client(dev); 1289 1292 struct mip4_ts *ts = i2c_get_clientdata(client); 1290 - const struct firmware *fw; 1291 1293 int error; 1292 1294 1295 + const struct firmware *fw __free(firmware) = NULL; 1293 1296 error = request_firmware(&fw, ts->fw_name, dev); 1294 1297 if (error) { 1295 1298 dev_err(&ts->client->dev, ··· 1303 1306 * userspace opening and closing the device and also suspend/resume 1304 1307 * transitions. 1305 1308 */ 1306 - mutex_lock(&ts->input->mutex); 1309 + guard(mutex)(&ts->input->mutex); 1307 1310 1308 1311 error = mip4_execute_fw_update(ts, fw); 1309 - 1310 - mutex_unlock(&ts->input->mutex); 1311 - 1312 - release_firmware(fw); 1313 - 1314 1312 if (error) { 1315 1313 dev_err(&ts->client->dev, 1316 1314 "Firmware update failed: %d\n", error); ··· 1323 1331 { 1324 1332 struct i2c_client *client = to_i2c_client(dev); 1325 1333 struct mip4_ts *ts = i2c_get_clientdata(client); 1326 - size_t count; 1327 1334 1328 1335 /* Take lock to prevent racing with firmware update */ 1329 - mutex_lock(&ts->input->mutex); 1336 + guard(mutex)(&ts->input->mutex); 1330 1337 1331 - count = sysfs_emit(buf, "%04X %04X %04X %04X\n", 1332 - ts->fw_version.boot, ts->fw_version.core, 1333 - ts->fw_version.app, ts->fw_version.param); 1334 - 1335 - mutex_unlock(&ts->input->mutex); 1336 - 1337 - return count; 1338 + return sysfs_emit(buf, "%04X %04X %04X %04X\n", 1339 + ts->fw_version.boot, ts->fw_version.core, 1340 + ts->fw_version.app, ts->fw_version.param); 1338 1341 } 1339 1342 1340 1343 static DEVICE_ATTR(fw_version, S_IRUGO, mip4_sysfs_read_fw_version, NULL); ··· 1340 1353 { 1341 1354 struct i2c_client *client = to_i2c_client(dev); 1342 1355 struct mip4_ts *ts = i2c_get_clientdata(client); 1343 - size_t count; 1344 1356 1345 1357 /* Take lock to prevent racing with firmware update */ 1346 - mutex_lock(&ts->input->mutex); 1358 + guard(mutex)(&ts->input->mutex); 1347 1359 1348 1360 /* 1349 1361 * product_name shows the name or version of the hardware 1350 1362 * paired with current firmware in the chip. 1351 1363 */ 1352 - count = sysfs_emit(buf, "%.*s\n", 1353 - (int)sizeof(ts->product_name), ts->product_name); 1354 - 1355 - mutex_unlock(&ts->input->mutex); 1356 - 1357 - return count; 1364 + return sysfs_emit(buf, "%.*s\n", 1365 + (int)sizeof(ts->product_name), ts->product_name); 1358 1366 } 1359 1367 1360 1368 static DEVICE_ATTR(hw_version, S_IRUGO, mip4_sysfs_read_hw_version, NULL); ··· 1360 1378 { 1361 1379 struct i2c_client *client = to_i2c_client(dev); 1362 1380 struct mip4_ts *ts = i2c_get_clientdata(client); 1363 - size_t count; 1364 1381 1365 - mutex_lock(&ts->input->mutex); 1382 + guard(mutex)(&ts->input->mutex); 1366 1383 1367 - count = sysfs_emit(buf, "%04X\n", ts->product_id); 1368 - 1369 - mutex_unlock(&ts->input->mutex); 1370 - 1371 - return count; 1384 + return sysfs_emit(buf, "%04X\n", ts->product_id); 1372 1385 } 1373 1386 1374 1387 static DEVICE_ATTR(product_id, S_IRUGO, mip4_sysfs_read_product_id, NULL); ··· 1374 1397 { 1375 1398 struct i2c_client *client = to_i2c_client(dev); 1376 1399 struct mip4_ts *ts = i2c_get_clientdata(client); 1377 - size_t count; 1378 1400 1379 - mutex_lock(&ts->input->mutex); 1401 + guard(mutex)(&ts->input->mutex); 1380 1402 1381 - count = sysfs_emit(buf, "%.*s\n", 1382 - (int)sizeof(ts->ic_name), ts->ic_name); 1383 - 1384 - mutex_unlock(&ts->input->mutex); 1385 - 1386 - return count; 1403 + return sysfs_emit(buf, "%.*s\n", (int)sizeof(ts->ic_name), ts->ic_name); 1387 1404 } 1388 1405 1389 1406 static DEVICE_ATTR(ic_name, S_IRUGO, mip4_sysfs_read_ic_name, NULL); ··· 1491 1520 struct mip4_ts *ts = i2c_get_clientdata(client); 1492 1521 struct input_dev *input = ts->input; 1493 1522 1494 - mutex_lock(&input->mutex); 1523 + guard(mutex)(&input->mutex); 1495 1524 1496 1525 if (device_may_wakeup(dev)) 1497 1526 ts->wake_irq_enabled = enable_irq_wake(client->irq) == 0; 1498 1527 else if (input_device_enabled(input)) 1499 1528 mip4_disable(ts); 1500 - 1501 - mutex_unlock(&input->mutex); 1502 1529 1503 1530 return 0; 1504 1531 } ··· 1507 1538 struct mip4_ts *ts = i2c_get_clientdata(client); 1508 1539 struct input_dev *input = ts->input; 1509 1540 1510 - mutex_lock(&input->mutex); 1541 + guard(mutex)(&input->mutex); 1511 1542 1512 1543 if (ts->wake_irq_enabled) 1513 1544 disable_irq_wake(client->irq); 1514 1545 else if (input_device_enabled(input)) 1515 1546 mip4_enable(ts); 1516 - 1517 - mutex_unlock(&input->mutex); 1518 1547 1519 1548 return 0; 1520 1549 }
-215
drivers/input/touchscreen/mk712.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * ICS MK712 touchscreen controller driver 4 - * 5 - * Copyright (c) 1999-2002 Transmeta Corporation 6 - * Copyright (c) 2005 Rick Koch <n1gp@hotmail.com> 7 - * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> 8 - */ 9 - 10 - 11 - /* 12 - * This driver supports the ICS MicroClock MK712 TouchScreen controller, 13 - * found in Gateway AOL Connected Touchpad computers. 14 - * 15 - * Documentation for ICS MK712 can be found at: 16 - * https://www.idt.com/general-parts/mk712-touch-screen-controller 17 - */ 18 - 19 - /* 20 - * 1999-12-18: original version, Daniel Quinlan 21 - * 1999-12-19: added anti-jitter code, report pen-up events, fixed mk712_poll 22 - * to use queue_empty, Nathan Laredo 23 - * 1999-12-20: improved random point rejection, Nathan Laredo 24 - * 2000-01-05: checked in new anti-jitter code, changed mouse protocol, fixed 25 - * queue code, added module options, other fixes, Daniel Quinlan 26 - * 2002-03-15: Clean up for kernel merge <alan@redhat.com> 27 - * Fixed multi open race, fixed memory checks, fixed resource 28 - * allocation, fixed close/powerdown bug, switched to new init 29 - * 2005-01-18: Ported to 2.6 from 2.4.28, Rick Koch 30 - * 2005-02-05: Rewritten for the input layer, Vojtech Pavlik 31 - * 32 - */ 33 - 34 - #include <linux/module.h> 35 - #include <linux/kernel.h> 36 - #include <linux/init.h> 37 - #include <linux/errno.h> 38 - #include <linux/delay.h> 39 - #include <linux/ioport.h> 40 - #include <linux/interrupt.h> 41 - #include <linux/input.h> 42 - #include <asm/io.h> 43 - 44 - MODULE_AUTHOR("Daniel Quinlan <quinlan@pathname.com>, Vojtech Pavlik <vojtech@suse.cz>"); 45 - MODULE_DESCRIPTION("ICS MicroClock MK712 TouchScreen driver"); 46 - MODULE_LICENSE("GPL"); 47 - 48 - static unsigned int mk712_io = 0x260; /* Also 0x200, 0x208, 0x300 */ 49 - module_param_hw_named(io, mk712_io, uint, ioport, 0); 50 - MODULE_PARM_DESC(io, "I/O base address of MK712 touchscreen controller"); 51 - 52 - static unsigned int mk712_irq = 10; /* Also 12, 14, 15 */ 53 - module_param_hw_named(irq, mk712_irq, uint, irq, 0); 54 - MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller"); 55 - 56 - /* eight 8-bit registers */ 57 - #define MK712_STATUS 0 58 - #define MK712_X 2 59 - #define MK712_Y 4 60 - #define MK712_CONTROL 6 61 - #define MK712_RATE 7 62 - 63 - /* status */ 64 - #define MK712_STATUS_TOUCH 0x10 65 - #define MK712_CONVERSION_COMPLETE 0x80 66 - 67 - /* control */ 68 - #define MK712_ENABLE_INT 0x01 69 - #define MK712_INT_ON_CONVERSION_COMPLETE 0x02 70 - #define MK712_INT_ON_CHANGE_IN_TOUCH_STATUS 0x04 71 - #define MK712_ENABLE_PERIODIC_CONVERSIONS 0x10 72 - #define MK712_READ_ONE_POINT 0x20 73 - #define MK712_POWERUP 0x40 74 - 75 - static struct input_dev *mk712_dev; 76 - static DEFINE_SPINLOCK(mk712_lock); 77 - 78 - static irqreturn_t mk712_interrupt(int irq, void *dev_id) 79 - { 80 - unsigned char status; 81 - static int debounce = 1; 82 - static unsigned short last_x; 83 - static unsigned short last_y; 84 - 85 - spin_lock(&mk712_lock); 86 - 87 - status = inb(mk712_io + MK712_STATUS); 88 - 89 - if (~status & MK712_CONVERSION_COMPLETE) { 90 - debounce = 1; 91 - goto end; 92 - } 93 - 94 - if (~status & MK712_STATUS_TOUCH) { 95 - debounce = 1; 96 - input_report_key(mk712_dev, BTN_TOUCH, 0); 97 - goto end; 98 - } 99 - 100 - if (debounce) { 101 - debounce = 0; 102 - goto end; 103 - } 104 - 105 - input_report_key(mk712_dev, BTN_TOUCH, 1); 106 - input_report_abs(mk712_dev, ABS_X, last_x); 107 - input_report_abs(mk712_dev, ABS_Y, last_y); 108 - 109 - end: 110 - last_x = inw(mk712_io + MK712_X) & 0x0fff; 111 - last_y = inw(mk712_io + MK712_Y) & 0x0fff; 112 - input_sync(mk712_dev); 113 - spin_unlock(&mk712_lock); 114 - return IRQ_HANDLED; 115 - } 116 - 117 - static int mk712_open(struct input_dev *dev) 118 - { 119 - unsigned long flags; 120 - 121 - spin_lock_irqsave(&mk712_lock, flags); 122 - 123 - outb(0, mk712_io + MK712_CONTROL); /* Reset */ 124 - 125 - outb(MK712_ENABLE_INT | MK712_INT_ON_CONVERSION_COMPLETE | 126 - MK712_INT_ON_CHANGE_IN_TOUCH_STATUS | 127 - MK712_ENABLE_PERIODIC_CONVERSIONS | 128 - MK712_POWERUP, mk712_io + MK712_CONTROL); 129 - 130 - outb(10, mk712_io + MK712_RATE); /* 187 points per second */ 131 - 132 - spin_unlock_irqrestore(&mk712_lock, flags); 133 - 134 - return 0; 135 - } 136 - 137 - static void mk712_close(struct input_dev *dev) 138 - { 139 - unsigned long flags; 140 - 141 - spin_lock_irqsave(&mk712_lock, flags); 142 - 143 - outb(0, mk712_io + MK712_CONTROL); 144 - 145 - spin_unlock_irqrestore(&mk712_lock, flags); 146 - } 147 - 148 - static int __init mk712_init(void) 149 - { 150 - int err; 151 - 152 - if (!request_region(mk712_io, 8, "mk712")) { 153 - printk(KERN_WARNING "mk712: unable to get IO region\n"); 154 - return -ENODEV; 155 - } 156 - 157 - outb(0, mk712_io + MK712_CONTROL); 158 - 159 - if ((inw(mk712_io + MK712_X) & 0xf000) || /* Sanity check */ 160 - (inw(mk712_io + MK712_Y) & 0xf000) || 161 - (inw(mk712_io + MK712_STATUS) & 0xf333)) { 162 - printk(KERN_WARNING "mk712: device not present\n"); 163 - err = -ENODEV; 164 - goto fail1; 165 - } 166 - 167 - mk712_dev = input_allocate_device(); 168 - if (!mk712_dev) { 169 - printk(KERN_ERR "mk712: not enough memory\n"); 170 - err = -ENOMEM; 171 - goto fail1; 172 - } 173 - 174 - mk712_dev->name = "ICS MicroClock MK712 TouchScreen"; 175 - mk712_dev->phys = "isa0260/input0"; 176 - mk712_dev->id.bustype = BUS_ISA; 177 - mk712_dev->id.vendor = 0x0005; 178 - mk712_dev->id.product = 0x0001; 179 - mk712_dev->id.version = 0x0100; 180 - 181 - mk712_dev->open = mk712_open; 182 - mk712_dev->close = mk712_close; 183 - 184 - mk712_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 185 - mk712_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 186 - input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0); 187 - input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0); 188 - 189 - if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) { 190 - printk(KERN_WARNING "mk712: unable to get IRQ\n"); 191 - err = -EBUSY; 192 - goto fail1; 193 - } 194 - 195 - err = input_register_device(mk712_dev); 196 - if (err) 197 - goto fail2; 198 - 199 - return 0; 200 - 201 - fail2: free_irq(mk712_irq, mk712_dev); 202 - fail1: input_free_device(mk712_dev); 203 - release_region(mk712_io, 8); 204 - return err; 205 - } 206 - 207 - static void __exit mk712_exit(void) 208 - { 209 - input_unregister_device(mk712_dev); 210 - free_irq(mk712_irq, mk712_dev); 211 - release_region(mk712_io, 8); 212 - } 213 - 214 - module_init(mk712_init); 215 - module_exit(mk712_exit);
+5 -15
drivers/input/touchscreen/mms114.c
··· 216 216 { 217 217 struct mms114_data *data = dev_id; 218 218 struct i2c_client *client = data->client; 219 - struct input_dev *input_dev = data->input_dev; 220 219 struct mms114_touch touch[MMS114_MAX_TOUCH]; 221 220 int packet_size; 222 221 int touch_size; 223 222 int index; 224 223 int error; 225 - 226 - mutex_lock(&input_dev->mutex); 227 - if (!input_device_enabled(input_dev)) { 228 - mutex_unlock(&input_dev->mutex); 229 - goto out; 230 - } 231 - mutex_unlock(&input_dev->mutex); 232 224 233 225 packet_size = mms114_read_reg(data, MMS114_PACKET_SIZE); 234 226 if (packet_size <= 0) ··· 638 646 input_mt_report_pointer_emulation(input_dev, true); 639 647 input_sync(input_dev); 640 648 641 - mutex_lock(&input_dev->mutex); 649 + guard(mutex)(&input_dev->mutex); 650 + 642 651 if (input_device_enabled(input_dev)) 643 652 mms114_stop(data); 644 - mutex_unlock(&input_dev->mutex); 645 653 646 654 return 0; 647 655 } ··· 653 661 struct input_dev *input_dev = data->input_dev; 654 662 int error; 655 663 656 - mutex_lock(&input_dev->mutex); 664 + guard(mutex)(&input_dev->mutex); 665 + 657 666 if (input_device_enabled(input_dev)) { 658 667 error = mms114_start(data); 659 - if (error < 0) { 660 - mutex_unlock(&input_dev->mutex); 668 + if (error) 661 669 return error; 662 - } 663 670 } 664 - mutex_unlock(&input_dev->mutex); 665 671 666 672 return 0; 667 673 }
+9 -10
drivers/input/touchscreen/msg2638.c
··· 446 446 struct i2c_client *client = to_i2c_client(dev); 447 447 struct msg2638_ts_data *msg2638 = i2c_get_clientdata(client); 448 448 449 - mutex_lock(&msg2638->input_dev->mutex); 449 + guard(mutex)(&msg2638->input_dev->mutex); 450 450 451 451 if (input_device_enabled(msg2638->input_dev)) 452 452 msg2638_stop(msg2638); 453 - 454 - mutex_unlock(&msg2638->input_dev->mutex); 455 453 456 454 return 0; 457 455 } ··· 458 460 { 459 461 struct i2c_client *client = to_i2c_client(dev); 460 462 struct msg2638_ts_data *msg2638 = i2c_get_clientdata(client); 461 - int ret = 0; 463 + int error; 462 464 463 - mutex_lock(&msg2638->input_dev->mutex); 465 + guard(mutex)(&msg2638->input_dev->mutex); 464 466 465 - if (input_device_enabled(msg2638->input_dev)) 466 - ret = msg2638_start(msg2638); 467 + if (input_device_enabled(msg2638->input_dev)) { 468 + error = msg2638_start(msg2638); 469 + if (error) 470 + return error; 471 + } 467 472 468 - mutex_unlock(&msg2638->input_dev->mutex); 469 - 470 - return ret; 473 + return 0; 471 474 } 472 475 473 476 static DEFINE_SIMPLE_DEV_PM_OPS(msg2638_pm_ops, msg2638_suspend, msg2638_resume);
+3 -4
drivers/input/touchscreen/mxs-lradc-ts.c
··· 500 500 LRADC_CTRL1_TOUCH_DETECT_IRQ | 501 501 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) | 502 502 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2); 503 - unsigned long flags; 504 503 505 504 if (!(reg & mxs_lradc_irq_mask(lradc))) 506 505 return IRQ_NONE; 507 506 508 507 if (reg & ts_irq_mask) { 509 - spin_lock_irqsave(&ts->lock, flags); 510 - mxs_lradc_handle_touch(ts); 511 - spin_unlock_irqrestore(&ts->lock, flags); 508 + scoped_guard(spinlock_irqsave, &ts->lock) { 509 + mxs_lradc_handle_touch(ts); 510 + } 512 511 /* Make sure we don't clear the next conversion's interrupt. */ 513 512 clr_irq &= ~(LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) | 514 513 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2));
+4 -4
drivers/input/touchscreen/novatek-nvt-ts.c
··· 170 170 { 171 171 struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev)); 172 172 173 - mutex_lock(&data->input->mutex); 173 + guard(mutex)(&data->input->mutex); 174 + 174 175 if (input_device_enabled(data->input)) 175 176 nvt_ts_stop(data->input); 176 - mutex_unlock(&data->input->mutex); 177 177 178 178 return 0; 179 179 } ··· 182 182 { 183 183 struct nvt_ts_data *data = i2c_get_clientdata(to_i2c_client(dev)); 184 184 185 - mutex_lock(&data->input->mutex); 185 + guard(mutex)(&data->input->mutex); 186 + 186 187 if (input_device_enabled(data->input)) 187 188 nvt_ts_start(data->input); 188 - mutex_unlock(&data->input->mutex); 189 189 190 190 return 0; 191 191 }
+18 -20
drivers/input/touchscreen/pixcir_i2c_ts.c
··· 410 410 struct i2c_client *client = to_i2c_client(dev); 411 411 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client); 412 412 struct input_dev *input = ts->input; 413 - int ret = 0; 413 + int error; 414 414 415 - mutex_lock(&input->mutex); 415 + guard(mutex)(&input->mutex); 416 416 417 417 if (device_may_wakeup(&client->dev)) { 418 418 if (!input_device_enabled(input)) { 419 - ret = pixcir_start(ts); 420 - if (ret) { 419 + error = pixcir_start(ts); 420 + if (error) { 421 421 dev_err(dev, "Failed to start\n"); 422 - goto unlock; 422 + return error; 423 423 } 424 424 } 425 425 } else if (input_device_enabled(input)) { 426 - ret = pixcir_stop(ts); 426 + error = pixcir_stop(ts); 427 + if (error) 428 + return error; 427 429 } 428 430 429 - unlock: 430 - mutex_unlock(&input->mutex); 431 - 432 - return ret; 431 + return 0; 433 432 } 434 433 435 434 static int pixcir_i2c_ts_resume(struct device *dev) ··· 436 437 struct i2c_client *client = to_i2c_client(dev); 437 438 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client); 438 439 struct input_dev *input = ts->input; 439 - int ret = 0; 440 + int error; 440 441 441 - mutex_lock(&input->mutex); 442 + guard(mutex)(&input->mutex); 442 443 443 444 if (device_may_wakeup(&client->dev)) { 444 445 if (!input_device_enabled(input)) { 445 - ret = pixcir_stop(ts); 446 - if (ret) { 446 + error = pixcir_stop(ts); 447 + if (error) { 447 448 dev_err(dev, "Failed to stop\n"); 448 - goto unlock; 449 + return error; 449 450 } 450 451 } 451 452 } else if (input_device_enabled(input)) { 452 - ret = pixcir_start(ts); 453 + error = pixcir_start(ts); 454 + if (error) 455 + return error; 453 456 } 454 457 455 - unlock: 456 - mutex_unlock(&input->mutex); 457 - 458 - return ret; 458 + return 0; 459 459 } 460 460 461 461 static DEFINE_SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,
+24 -32
drivers/input/touchscreen/raydium_i2c_ts.c
··· 169 169 { 170 170 int tries = 0; 171 171 int error; 172 - u8 *tx_buf; 173 172 u8 reg_addr = addr & 0xff; 174 173 175 - tx_buf = kmalloc(len + 1, GFP_KERNEL); 174 + u8 *tx_buf __free(kfree) = kmalloc(len + 1, GFP_KERNEL); 176 175 if (!tx_buf) 177 176 return -ENOMEM; 178 177 ··· 209 210 210 211 error = raydium_i2c_xfer(client, addr, xfer, ARRAY_SIZE(xfer)); 211 212 if (likely(!error)) 212 - goto out; 213 + return 0; 213 214 214 215 msleep(RM_RETRY_DELAY_MS); 215 216 } while (++tries < RM_MAX_RETRIES); 216 217 217 218 dev_err(&client->dev, "%s failed: %d\n", __func__, error); 218 - out: 219 - kfree(tx_buf); 220 219 return error; 221 220 } 222 221 ··· 812 815 static int raydium_i2c_fw_update(struct raydium_data *ts) 813 816 { 814 817 struct i2c_client *client = ts->client; 815 - const struct firmware *fw = NULL; 816 - char *fw_file; 817 818 int error; 818 819 819 - fw_file = kasprintf(GFP_KERNEL, "raydium_%#04x.fw", 820 - le32_to_cpu(ts->info.hw_ver)); 820 + const char *fw_file __free(kfree) = 821 + kasprintf(GFP_KERNEL, "raydium_%#04x.fw", 822 + le32_to_cpu(ts->info.hw_ver)); 821 823 if (!fw_file) 822 824 return -ENOMEM; 823 825 824 826 dev_dbg(&client->dev, "firmware name: %s\n", fw_file); 825 827 828 + const struct firmware *fw __free(firmware) = NULL; 826 829 error = request_firmware(&fw, fw_file, &client->dev); 827 830 if (error) { 828 831 dev_err(&client->dev, "Unable to open firmware %s\n", fw_file); 829 - goto out_free_fw_file; 832 + return error; 830 833 } 831 834 832 835 disable_irq(client->irq); ··· 852 855 out_enable_irq: 853 856 enable_irq(client->irq); 854 857 msleep(100); 855 - 856 - release_firmware(fw); 857 - 858 - out_free_fw_file: 859 - kfree(fw_file); 860 858 861 859 return error; 862 860 } ··· 957 965 struct raydium_data *ts = i2c_get_clientdata(client); 958 966 int error; 959 967 960 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 961 - if (error) 962 - return error; 968 + scoped_guard(mutex_intr, &ts->sysfs_mutex) { 969 + error = raydium_i2c_fw_update(ts); 970 + return error ?: count; 971 + } 963 972 964 - error = raydium_i2c_fw_update(ts); 965 - 966 - mutex_unlock(&ts->sysfs_mutex); 967 - 968 - return error ?: count; 973 + return -EINTR; 969 974 } 970 975 971 976 static ssize_t raydium_i2c_calibrate_store(struct device *dev, ··· 974 985 static const u8 cal_cmd[] = { 0x00, 0x01, 0x9E }; 975 986 int error; 976 987 977 - error = mutex_lock_interruptible(&ts->sysfs_mutex); 978 - if (error) 979 - return error; 988 + scoped_guard(mutex_intr, &ts->sysfs_mutex) { 989 + error = raydium_i2c_write_object(client, 990 + cal_cmd, sizeof(cal_cmd), 991 + RAYDIUM_WAIT_READY); 992 + if (error) { 993 + dev_err(&client->dev, 994 + "calibrate command failed: %d\n", error); 995 + return error; 996 + } 980 997 981 - error = raydium_i2c_write_object(client, cal_cmd, sizeof(cal_cmd), 982 - RAYDIUM_WAIT_READY); 983 - if (error) 984 - dev_err(&client->dev, "calibrate command failed: %d\n", error); 998 + return count; 999 + } 985 1000 986 - mutex_unlock(&ts->sysfs_mutex); 987 - return error ?: count; 1001 + return -EINTR; 988 1002 } 989 1003 990 1004 static DEVICE_ATTR(fw_version, S_IRUGO, raydium_i2c_fw_ver_show, NULL);
+66 -1
drivers/input/touchscreen/st1232.c
··· 15 15 #include <linux/i2c.h> 16 16 #include <linux/input.h> 17 17 #include <linux/input/mt.h> 18 + #include <linux/input/touch-overlay.h> 18 19 #include <linux/input/touchscreen.h> 19 20 #include <linux/interrupt.h> 20 21 #include <linux/module.h> ··· 23 22 #include <linux/pm_qos.h> 24 23 #include <linux/slab.h> 25 24 #include <linux/types.h> 26 - #include <linux/input/touch-overlay.h> 25 + #include <asm/byteorder.h> 27 26 28 27 #define ST1232_TS_NAME "st1232-ts" 29 28 #define ST1633_TS_NAME "st1633-ts" 29 + 30 + #define REG_FIRMWARE_VERSION 0x00 31 + #define REG_FIRMWARE_REVISION_3 0x0C 30 32 31 33 #define REG_STATUS 0x01 /* Device Status | Error Code */ 32 34 ··· 65 61 struct list_head touch_overlay_list; 66 62 int read_buf_len; 67 63 u8 *read_buf; 64 + u8 fw_version; 65 + u32 fw_revision; 68 66 }; 67 + 68 + static ssize_t fw_version_show(struct device *dev, 69 + struct device_attribute *attr, char *buf) 70 + { 71 + struct i2c_client *client = to_i2c_client(dev); 72 + struct st1232_ts_data *st1232_ts = i2c_get_clientdata(client); 73 + 74 + return sysfs_emit(buf, "%u\n", st1232_ts->fw_version); 75 + } 76 + 77 + static ssize_t fw_revision_show(struct device *dev, 78 + struct device_attribute *attr, char *buf) 79 + { 80 + struct i2c_client *client = to_i2c_client(dev); 81 + struct st1232_ts_data *st1232_ts = i2c_get_clientdata(client); 82 + 83 + return sysfs_emit(buf, "%08x\n", st1232_ts->fw_revision); 84 + } 85 + 86 + static DEVICE_ATTR_RO(fw_version); 87 + static DEVICE_ATTR_RO(fw_revision); 88 + 89 + static struct attribute *st1232_attrs[] = { 90 + &dev_attr_fw_version.attr, 91 + &dev_attr_fw_revision.attr, 92 + NULL, 93 + }; 94 + ATTRIBUTE_GROUPS(st1232); 69 95 70 96 static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg, 71 97 unsigned int n) ··· 142 108 } 143 109 144 110 return -ENXIO; 111 + } 112 + 113 + static int st1232_ts_read_fw_version(struct st1232_ts_data *ts, 114 + u8 *fw_version, u32 *fw_revision) 115 + { 116 + int error; 117 + 118 + /* select firmware version register */ 119 + error = st1232_ts_read_data(ts, REG_FIRMWARE_VERSION, 1); 120 + if (error) 121 + return error; 122 + *fw_version = ts->read_buf[0]; 123 + 124 + /* select firmware revision register */ 125 + error = st1232_ts_read_data(ts, REG_FIRMWARE_REVISION_3, 4); 126 + if (error) 127 + return error; 128 + *fw_revision = le32_to_cpup((__le32 *)ts->read_buf); 129 + 130 + return 0; 145 131 } 146 132 147 133 static int st1232_ts_read_resolution(struct st1232_ts_data *ts, u16 *max_x, ··· 353 299 if (error) 354 300 return error; 355 301 302 + /* Read firmware version from the chip */ 303 + error = st1232_ts_read_fw_version(ts, &ts->fw_version, &ts->fw_revision); 304 + if (error) { 305 + dev_err(&client->dev, 306 + "Failed to read firmware version: %d\n", error); 307 + return error; 308 + } 309 + dev_dbg(&client->dev, "Detected firmware version %u, rev %08x\n", 310 + ts->fw_version, ts->fw_revision); 311 + 356 312 if (ts->chip_info->have_z) 357 313 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 358 314 ts->chip_info->max_area, 0, 0); ··· 472 408 .driver = { 473 409 .name = ST1232_TS_NAME, 474 410 .of_match_table = st1232_ts_dt_ids, 411 + .dev_groups = st1232_groups, 475 412 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 476 413 .pm = pm_sleep_ptr(&st1232_ts_pm_ops), 477 414 },
+31 -32
drivers/input/touchscreen/stmfts.c
··· 302 302 struct stmfts_data *sdata = dev; 303 303 int err; 304 304 305 - mutex_lock(&sdata->mutex); 305 + guard(mutex)(&sdata->mutex); 306 306 307 307 err = stmfts_read_events(sdata); 308 308 if (unlikely(err)) ··· 311 311 else 312 312 stmfts_parse_events(sdata); 313 313 314 - mutex_unlock(&sdata->mutex); 315 314 return IRQ_HANDLED; 316 315 } 317 316 ··· 346 347 return err; 347 348 } 348 349 349 - mutex_lock(&sdata->mutex); 350 - sdata->running = true; 350 + scoped_guard(mutex, &sdata->mutex) { 351 + sdata->running = true; 351 352 352 - if (sdata->hover_enabled) { 353 - err = i2c_smbus_write_byte(sdata->client, 354 - STMFTS_SS_HOVER_SENSE_ON); 355 - if (err) 356 - dev_warn(&sdata->client->dev, 357 - "failed to enable hover\n"); 353 + if (sdata->hover_enabled) { 354 + err = i2c_smbus_write_byte(sdata->client, 355 + STMFTS_SS_HOVER_SENSE_ON); 356 + if (err) 357 + dev_warn(&sdata->client->dev, 358 + "failed to enable hover\n"); 359 + } 358 360 } 359 - mutex_unlock(&sdata->mutex); 360 361 361 362 if (sdata->use_key) { 362 363 err = i2c_smbus_write_byte(sdata->client, ··· 380 381 dev_warn(&sdata->client->dev, 381 382 "failed to disable touchscreen: %d\n", err); 382 383 383 - mutex_lock(&sdata->mutex); 384 + scoped_guard(mutex, &sdata->mutex) { 385 + sdata->running = false; 384 386 385 - sdata->running = false; 386 - 387 - if (sdata->hover_enabled) { 388 - err = i2c_smbus_write_byte(sdata->client, 389 - STMFTS_SS_HOVER_SENSE_OFF); 390 - if (err) 391 - dev_warn(&sdata->client->dev, 392 - "failed to disable hover: %d\n", err); 387 + if (sdata->hover_enabled) { 388 + err = i2c_smbus_write_byte(sdata->client, 389 + STMFTS_SS_HOVER_SENSE_OFF); 390 + if (err) 391 + dev_warn(&sdata->client->dev, 392 + "failed to disable hover: %d\n", err); 393 + } 393 394 } 394 - mutex_unlock(&sdata->mutex); 395 395 396 396 if (sdata->use_key) { 397 397 err = i2c_smbus_write_byte(sdata->client, ··· 472 474 { 473 475 struct stmfts_data *sdata = dev_get_drvdata(dev); 474 476 unsigned long value; 475 - int err = 0; 477 + bool hover; 478 + int err; 476 479 477 480 if (kstrtoul(buf, 0, &value)) 478 481 return -EINVAL; 479 482 480 - mutex_lock(&sdata->mutex); 483 + hover = !!value; 481 484 482 - if (value && sdata->hover_enabled) 483 - goto out; 485 + guard(mutex)(&sdata->mutex); 484 486 485 - if (sdata->running) 486 - err = i2c_smbus_write_byte(sdata->client, 487 + if (hover != sdata->hover_enabled) { 488 + if (sdata->running) { 489 + err = i2c_smbus_write_byte(sdata->client, 487 490 value ? STMFTS_SS_HOVER_SENSE_ON : 488 491 STMFTS_SS_HOVER_SENSE_OFF); 492 + if (err) 493 + return err; 494 + } 489 495 490 - if (!err) 491 - sdata->hover_enabled = !!value; 492 - 493 - out: 494 - mutex_unlock(&sdata->mutex); 496 + sdata->hover_enabled = hover; 497 + } 495 498 496 499 return len; 497 500 }
+11 -12
drivers/input/touchscreen/sur40.c
··· 538 538 return; 539 539 540 540 /* get a new buffer from the list */ 541 - spin_lock(&sur40->qlock); 542 - if (list_empty(&sur40->buf_list)) { 543 - dev_dbg(sur40->dev, "buffer queue empty\n"); 544 - spin_unlock(&sur40->qlock); 545 - return; 541 + scoped_guard(spinlock, &sur40->qlock) { 542 + if (list_empty(&sur40->buf_list)) { 543 + dev_dbg(sur40->dev, "buffer queue empty\n"); 544 + return; 545 + } 546 + new_buf = list_first_entry(&sur40->buf_list, 547 + struct sur40_buffer, list); 548 + list_del(&new_buf->list); 546 549 } 547 - new_buf = list_entry(sur40->buf_list.next, struct sur40_buffer, list); 548 - list_del(&new_buf->list); 549 - spin_unlock(&sur40->qlock); 550 550 551 551 dev_dbg(sur40->dev, "buffer acquired\n"); 552 552 ··· 888 888 struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue); 889 889 struct sur40_buffer *buf = (struct sur40_buffer *)vb; 890 890 891 - spin_lock(&sur40->qlock); 891 + guard(spinlock)(&sur40->qlock); 892 892 list_add_tail(&buf->list, &sur40->buf_list); 893 - spin_unlock(&sur40->qlock); 894 893 } 895 894 896 895 static void return_all_buffers(struct sur40_state *sur40, ··· 897 898 { 898 899 struct sur40_buffer *buf, *node; 899 900 900 - spin_lock(&sur40->qlock); 901 + guard(spinlock)(&sur40->qlock); 902 + 901 903 list_for_each_entry_safe(buf, node, &sur40->buf_list, list) { 902 904 vb2_buffer_done(&buf->vb.vb2_buf, state); 903 905 list_del(&buf->list); 904 906 } 905 - spin_unlock(&sur40->qlock); 906 907 } 907 908 908 909 /*
+9 -11
drivers/input/touchscreen/sx8654.c
··· 117 117 static void sx865x_penrelease_timer_handler(struct timer_list *t) 118 118 { 119 119 struct sx8654 *ts = timer_container_of(ts, t, timer); 120 - unsigned long flags; 121 120 122 - spin_lock_irqsave(&ts->lock, flags); 123 - sx865x_penrelease(ts); 124 - spin_unlock_irqrestore(&ts->lock, flags); 125 121 dev_dbg(&ts->client->dev, "penrelease by timer\n"); 122 + 123 + guard(spinlock_irqsave)(&ts->lock); 124 + sx865x_penrelease(ts); 126 125 } 127 126 128 127 static irqreturn_t sx8650_irq(int irq, void *handle) ··· 129 130 struct sx8654 *ts = handle; 130 131 struct device *dev = &ts->client->dev; 131 132 int len, i; 132 - unsigned long flags; 133 133 u8 stat; 134 134 u16 x, y; 135 135 u16 ch; ··· 151 153 return IRQ_HANDLED; 152 154 } 153 155 154 - spin_lock_irqsave(&ts->lock, flags); 156 + guard(spinlock_irqsave)(&ts->lock); 155 157 156 158 x = 0; 157 159 y = 0; ··· 182 184 dev_dbg(dev, "point(%4d,%4d)\n", x, y); 183 185 184 186 mod_timer(&ts->timer, jiffies + SX8650_PENIRQ_TIMEOUT); 185 - spin_unlock_irqrestore(&ts->lock, flags); 186 187 187 188 return IRQ_HANDLED; 188 189 } ··· 391 394 return error; 392 395 } 393 396 397 + /* 398 + * Start with the interrupt disabled, it will be enabled in 399 + * sx8654_open(). 400 + */ 394 401 error = devm_request_threaded_irq(&client->dev, client->irq, 395 402 NULL, sx8654->data->irqh, 396 - IRQF_ONESHOT, 403 + IRQF_ONESHOT | IRQF_NO_AUTOEN, 397 404 client->name, sx8654); 398 405 if (error) { 399 406 dev_err(&client->dev, ··· 405 404 client->irq, error); 406 405 return error; 407 406 } 408 - 409 - /* Disable the IRQ, we'll enable it in sx8654_open() */ 410 - disable_irq(client->irq); 411 407 412 408 error = input_register_device(sx8654->input); 413 409 if (error)
+4 -3
drivers/input/touchscreen/tsc2007_core.c
··· 122 122 123 123 /* pen is down, continue with the measurement */ 124 124 125 - mutex_lock(&ts->mlock); 126 - tsc2007_read_values(ts, &tc); 127 - mutex_unlock(&ts->mlock); 125 + /* Serialize access between the ISR and IIO reads. */ 126 + scoped_guard(mutex, &ts->mlock) { 127 + tsc2007_read_values(ts, &tc); 128 + } 128 129 129 130 rt = tsc2007_calculate_resistance(ts, &tc); 130 131
+2 -7
drivers/input/touchscreen/tsc2007_iio.c
··· 41 41 struct tsc2007_iio *iio = iio_priv(indio_dev); 42 42 struct tsc2007 *tsc = iio->ts; 43 43 int adc_chan = chan->channel; 44 - int ret = 0; 45 44 46 45 if (adc_chan >= ARRAY_SIZE(tsc2007_iio_channel)) 47 46 return -EINVAL; ··· 48 49 if (mask != IIO_CHAN_INFO_RAW) 49 50 return -EINVAL; 50 51 51 - mutex_lock(&tsc->mlock); 52 + guard(mutex)(&tsc->mlock); 52 53 53 54 switch (chan->channel) { 54 55 case 0: ··· 91 92 /* Prepare for next touch reading - power down ADC, enable PENIRQ */ 92 93 tsc2007_xfer(tsc, PWRDOWN); 93 94 94 - mutex_unlock(&tsc->mlock); 95 - 96 - ret = IIO_VAL_INT; 97 - 98 - return ret; 95 + return IIO_VAL_INT; 99 96 } 100 97 101 98 static const struct iio_info tsc2007_iio_info = {
+16 -27
drivers/input/touchscreen/usbtouchscreen.c
··· 969 969 { 970 970 struct usb_device *dev = interface_to_usbdev(usbtouch->interface); 971 971 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting; 972 + struct usb_endpoint_descriptor *ep_in, *ep_out; 972 973 struct nexio_priv *priv = usbtouch->priv; 973 - int ret = -ENOMEM; 974 974 int actual_len, i; 975 975 char *firmware_ver = NULL, *device_name = NULL; 976 - int input_ep = 0, output_ep = 0; 976 + int input_ep, output_ep; 977 + int ret; 977 978 978 979 /* find first input and output endpoint */ 979 - for (i = 0; i < interface->desc.bNumEndpoints; i++) { 980 - if (!input_ep && 981 - usb_endpoint_dir_in(&interface->endpoint[i].desc)) 982 - input_ep = interface->endpoint[i].desc.bEndpointAddress; 983 - if (!output_ep && 984 - usb_endpoint_dir_out(&interface->endpoint[i].desc)) 985 - output_ep = interface->endpoint[i].desc.bEndpointAddress; 986 - } 987 - if (!input_ep || !output_ep) 980 + ret = usb_find_common_endpoints(interface, &ep_in, &ep_out, NULL, NULL); 981 + if (ret) 988 982 return -ENXIO; 983 + 984 + input_ep = usb_endpoint_num(ep_in); 985 + output_ep = usb_endpoint_num(ep_out); 989 986 990 987 u8 *buf __free(kfree) = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); 991 988 if (!buf) ··· 1424 1427 kfree(usbtouch->buffer); 1425 1428 } 1426 1429 1427 - static struct usb_endpoint_descriptor * 1428 - usbtouch_get_input_endpoint(struct usb_host_interface *interface) 1429 - { 1430 - int i; 1431 - 1432 - for (i = 0; i < interface->desc.bNumEndpoints; i++) 1433 - if (usb_endpoint_dir_in(&interface->endpoint[i].desc)) 1434 - return &interface->endpoint[i].desc; 1435 - 1436 - return NULL; 1437 - } 1438 - 1439 1430 static int usbtouch_probe(struct usb_interface *intf, 1440 1431 const struct usb_device_id *id) 1441 1432 { ··· 1432 1447 struct usb_endpoint_descriptor *endpoint; 1433 1448 struct usb_device *udev = interface_to_usbdev(intf); 1434 1449 const struct usbtouch_device_info *type; 1435 - int err = -ENOMEM; 1450 + int err; 1436 1451 1437 1452 /* some devices are ignored */ 1438 1453 type = (const struct usbtouch_device_info *)id->driver_info; 1439 1454 if (!type) 1440 1455 return -ENODEV; 1441 1456 1442 - endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting); 1443 - if (!endpoint) 1444 - return -ENXIO; 1457 + err = usb_find_int_in_endpoint(intf->cur_altsetting, &endpoint); 1458 + if (err) { 1459 + err = usb_find_bulk_in_endpoint(intf->cur_altsetting, &endpoint); 1460 + if (err) 1461 + return -ENXIO; 1462 + } 1445 1463 1464 + err = -ENOMEM; 1446 1465 usbtouch = kzalloc_obj(*usbtouch); 1447 1466 input_dev = input_allocate_device(); 1448 1467 if (!usbtouch || !input_dev)
+21 -23
drivers/input/touchscreen/wdt87xx_i2c.c
··· 813 813 return 0; 814 814 } 815 815 816 - static int wdt87xx_do_update_firmware(struct i2c_client *client, 816 + static int wdt87xx_do_update_firmware(struct wdt87xx_data *wdt, 817 817 const struct firmware *fw, 818 818 unsigned int chunk_id) 819 819 { 820 - struct wdt87xx_data *wdt = i2c_get_clientdata(client); 820 + struct i2c_client *client = wdt->client; 821 821 int error; 822 - 823 - error = wdt87xx_validate_firmware(wdt, fw); 824 - if (error) 825 - return error; 826 - 827 - error = mutex_lock_interruptible(&wdt->fw_mutex); 828 - if (error) 829 - return error; 830 - 831 - disable_irq(client->irq); 832 822 833 823 error = wdt87xx_load_chunk(client, fw, chunk_id); 834 824 if (error) { 835 825 dev_err(&client->dev, 836 826 "firmware load failed (type: %d): %d\n", 837 827 chunk_id, error); 838 - goto out; 828 + return error; 839 829 } 840 830 841 831 error = wdt87xx_sw_reset(client); 842 832 if (error) { 843 833 dev_err(&client->dev, "soft reset failed: %d\n", error); 844 - goto out; 834 + return error; 845 835 } 846 836 847 837 /* Refresh the parameters */ 848 838 error = wdt87xx_get_sysparam(client, &wdt->param); 849 - if (error) 839 + if (error) { 850 840 dev_err(&client->dev, 851 841 "failed to refresh system parameters: %d\n", error); 852 - out: 853 - enable_irq(client->irq); 854 - mutex_unlock(&wdt->fw_mutex); 842 + return error; 843 + } 855 844 856 - return error ? error : 0; 845 + return 0; 857 846 } 858 847 859 848 static int wdt87xx_update_firmware(struct device *dev, 860 849 const char *fw_name, unsigned int chunk_id) 861 850 { 862 851 struct i2c_client *client = to_i2c_client(dev); 863 - const struct firmware *fw; 852 + struct wdt87xx_data *wdt = i2c_get_clientdata(client); 864 853 int error; 865 854 855 + const struct firmware *fw __free(firmware) = NULL; 866 856 error = request_firmware(&fw, fw_name, dev); 867 857 if (error) { 868 858 dev_err(&client->dev, "unable to retrieve firmware %s: %d\n", ··· 860 870 return error; 861 871 } 862 872 863 - error = wdt87xx_do_update_firmware(client, fw, chunk_id); 873 + error = wdt87xx_validate_firmware(wdt, fw); 874 + if (error) 875 + return error; 864 876 865 - release_firmware(fw); 877 + scoped_cond_guard(mutex_intr, return -EINTR, &wdt->fw_mutex) { 878 + guard(disable_irq)(&client->irq); 866 879 867 - return error ? error : 0; 880 + error = wdt87xx_do_update_firmware(wdt, fw, chunk_id); 881 + if (error) 882 + return error; 883 + } 884 + 885 + return 0; 868 886 } 869 887 870 888 static ssize_t config_csum_show(struct device *dev,
+23 -34
drivers/input/touchscreen/wm97xx-core.c
··· 126 126 int timeout = 0; 127 127 128 128 /* get codec */ 129 - mutex_lock(&wm->codec_mutex); 129 + guard(mutex)(&wm->codec_mutex); 130 130 131 131 /* When the touchscreen is not in use, we may have to power up 132 132 * the AUX ADC before we can use sample the AUX inputs-> ··· 160 160 wm->codec->dig_enable(wm, false); 161 161 } 162 162 163 - mutex_unlock(&wm->codec_mutex); 164 163 return (rc == RC_VALID ? auxval & 0xfff : -EBUSY); 165 164 } 166 165 EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc); ··· 175 176 enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio) 176 177 { 177 178 u16 status; 178 - enum wm97xx_gpio_status ret; 179 179 180 - mutex_lock(&wm->codec_mutex); 180 + guard(mutex)(&wm->codec_mutex); 181 + 181 182 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); 182 - 183 - if (status & gpio) 184 - ret = WM97XX_GPIO_HIGH; 185 - else 186 - ret = WM97XX_GPIO_LOW; 187 - 188 - mutex_unlock(&wm->codec_mutex); 189 - return ret; 183 + return (status & gpio) ? WM97XX_GPIO_HIGH : WM97XX_GPIO_LOW; 190 184 } 191 185 EXPORT_SYMBOL_GPL(wm97xx_get_gpio); 192 186 ··· 197 205 { 198 206 u16 reg; 199 207 200 - mutex_lock(&wm->codec_mutex); 208 + guard(mutex)(&wm->codec_mutex); 209 + 201 210 reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS); 202 211 203 212 if (status == WM97XX_GPIO_HIGH) ··· 210 217 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1); 211 218 else 212 219 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg); 213 - mutex_unlock(&wm->codec_mutex); 214 220 } 215 221 EXPORT_SYMBOL_GPL(wm97xx_set_gpio); 216 222 ··· 223 231 { 224 232 u16 reg; 225 233 226 - mutex_lock(&wm->codec_mutex); 234 + guard(mutex)(&wm->codec_mutex); 235 + 227 236 reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); 228 237 229 238 if (pol == WM97XX_GPIO_POL_HIGH) ··· 257 264 reg &= ~gpio; 258 265 259 266 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg); 260 - mutex_unlock(&wm->codec_mutex); 261 267 } 262 268 EXPORT_SYMBOL_GPL(wm97xx_config_gpio); 263 269 ··· 295 303 wm->pen_is_down = 0; 296 304 } else { 297 305 u16 status, pol; 298 - mutex_lock(&wm->codec_mutex); 306 + 307 + guard(mutex)(&wm->codec_mutex); 308 + 299 309 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS); 300 310 pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); 301 311 ··· 317 323 else 318 324 wm97xx_reg_write(wm, AC97_GPIO_STATUS, status & 319 325 ~WM97XX_GPIO_13); 320 - mutex_unlock(&wm->codec_mutex); 321 326 } 322 327 323 328 /* If the system is not using continuous mode or it provides a ··· 375 382 struct wm97xx_data data; 376 383 int rc; 377 384 378 - mutex_lock(&wm->codec_mutex); 385 + guard(mutex)(&wm->codec_mutex); 379 386 380 387 if (wm->mach_ops && wm->mach_ops->acc_enabled) 381 388 rc = wm->mach_ops->acc_pen_down(wm); ··· 415 422 abs_y[0] > (data.y & 0xfff) || 416 423 abs_y[1] < (data.y & 0xfff)) { 417 424 dev_dbg(wm->dev, "Measurement out of range, dropping it\n"); 418 - rc = RC_AGAIN; 419 - goto out; 425 + return RC_AGAIN; 420 426 } 421 427 422 428 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); ··· 431 439 wm->ts_reader_interval = wm->ts_reader_min_interval; 432 440 } 433 441 434 - out: 435 - mutex_unlock(&wm->codec_mutex); 436 442 return rc; 437 443 } 438 444 ··· 763 773 else 764 774 suspend_mode = 0; 765 775 766 - mutex_lock(&wm->input_dev->mutex); 776 + guard(mutex)(&wm->input_dev->mutex); 777 + 767 778 if (input_device_enabled(wm->input_dev)) 768 779 cancel_delayed_work_sync(&wm->ts_reader); 769 780 ··· 782 791 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) | 0x8000; 783 792 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg); 784 793 } 785 - mutex_unlock(&wm->input_dev->mutex); 786 794 787 795 return 0; 788 796 } ··· 790 800 { 791 801 struct wm97xx *wm = dev_get_drvdata(dev); 792 802 793 - mutex_lock(&wm->input_dev->mutex); 803 + guard(mutex)(&wm->input_dev->mutex); 804 + 794 805 /* restore digitiser and gpios */ 795 806 if (wm->id == WM9713_ID2) { 796 807 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]); ··· 818 827 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 819 828 wm->ts_reader_interval); 820 829 } 821 - mutex_unlock(&wm->input_dev->mutex); 822 830 823 831 return 0; 824 832 } ··· 830 840 int wm97xx_register_mach_ops(struct wm97xx *wm, 831 841 struct wm97xx_mach_ops *mach_ops) 832 842 { 833 - mutex_lock(&wm->codec_mutex); 834 - if (wm->mach_ops) { 835 - mutex_unlock(&wm->codec_mutex); 843 + guard(mutex)(&wm->codec_mutex); 844 + 845 + if (wm->mach_ops) 836 846 return -EINVAL; 837 - } 847 + 838 848 wm->mach_ops = mach_ops; 839 - mutex_unlock(&wm->codec_mutex); 840 849 841 850 return 0; 842 851 } ··· 843 854 844 855 void wm97xx_unregister_mach_ops(struct wm97xx *wm) 845 856 { 846 - mutex_lock(&wm->codec_mutex); 857 + guard(mutex)(&wm->codec_mutex); 858 + 847 859 wm->mach_ops = NULL; 848 - mutex_unlock(&wm->codec_mutex); 849 860 } 850 861 EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops); 851 862
+9 -10
drivers/input/touchscreen/zinitix.c
··· 703 703 struct i2c_client *client = to_i2c_client(dev); 704 704 struct bt541_ts_data *bt541 = i2c_get_clientdata(client); 705 705 706 - mutex_lock(&bt541->input_dev->mutex); 706 + guard(mutex)(&bt541->input_dev->mutex); 707 707 708 708 if (input_device_enabled(bt541->input_dev)) 709 709 zinitix_stop(bt541); 710 - 711 - mutex_unlock(&bt541->input_dev->mutex); 712 710 713 711 return 0; 714 712 } ··· 715 717 { 716 718 struct i2c_client *client = to_i2c_client(dev); 717 719 struct bt541_ts_data *bt541 = i2c_get_clientdata(client); 718 - int ret = 0; 720 + int error; 719 721 720 - mutex_lock(&bt541->input_dev->mutex); 722 + guard(mutex)(&bt541->input_dev->mutex); 721 723 722 - if (input_device_enabled(bt541->input_dev)) 723 - ret = zinitix_start(bt541); 724 + if (input_device_enabled(bt541->input_dev)) { 725 + error = zinitix_start(bt541); 726 + if (error) 727 + return error; 728 + } 724 729 725 - mutex_unlock(&bt541->input_dev->mutex); 726 - 727 - return ret; 730 + return 0; 728 731 } 729 732 730 733 static DEFINE_SIMPLE_DEV_PM_OPS(zinitix_pm_ops, zinitix_suspend, zinitix_resume);
+4
include/linux/input.h
··· 517 517 int input_scancode_to_scalar(const struct input_keymap_entry *ke, 518 518 unsigned int *scancode); 519 519 520 + int input_default_setkeycode(struct input_dev *dev, 521 + const struct input_keymap_entry *ke, 522 + unsigned int *old_keycode); 523 + 520 524 int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke); 521 525 int input_set_keycode(struct input_dev *dev, 522 526 const struct input_keymap_entry *ke);