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

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

Pull input updates from Dmitry Torokhov:

- support for PixArt PS/2 touchpad

- updates to tsc2004/5, usbtouchscreen, and zforce_ts drivers

- support for GPIO-only mode for ADP55888 controller

- support for touch keys in Zinitix driver

- support for querying density of Synaptics sensors

- sysfs interface for Goodex "Berlin" devices to read and write touch
IC registers

- more quirks to i8042 to handle various Tuxedo laptops

- a number of drivers have been converted to using "guard" notation
when acquiring various locks, as well as using other cleanup
functions to simplify releasing of resources (with more drivers to
follow)

- evdev will limit amount of data that can be written into an evdev
instance at a given time to 4096 bytes (170 input events) to avoid
holding evdev->mutex for too long and starving other users

- Spitz has been converted to use software nodes/properties to describe
its matrix keypad and GPIO-connected LEDs

- msc5000_ts, msc_touchkey and keypad-nomadik-ske drivers have been
removed since noone in mainline have been using them

- other assorted cleanups and fixes

* tag 'input-for-v6.12-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (98 commits)
ARM: spitz: fix compile error when matrix keypad driver is enabled
Input: hynitron_cstxxx - drop explicit initialization of struct i2c_device_id::driver_data to 0
Input: adp5588-keys - fix check on return code
Input: Convert comma to semicolon
Input: i8042 - add TUXEDO Stellaris 15 Slim Gen6 AMD to i8042 quirk table
Input: i8042 - add another board name for TUXEDO Stellaris Gen5 AMD line
Input: tegra-kbc - use of_property_read_variable_u32_array() and of_property_present()
Input: ps2-gpio - use IRQF_NO_AUTOEN flag in request_irq()
Input: ims-pcu - fix calling interruptible mutex
Input: zforce_ts - switch to using asynchronous probing
Input: zforce_ts - remove assert/deassert wrappers
Input: zforce_ts - do not hardcode interrupt level
Input: zforce_ts - switch to using devm_regulator_get_enable()
Input: zforce_ts - stop treating VDD regulator as optional
Input: zforce_ts - make zforce_idtable constant
Input: zforce_ts - use dev_err_probe() where appropriate
Input: zforce_ts - do not ignore errors when acquiring regulator
Input: zforce_ts - make parsing of contacts less confusing
Input: zforce_ts - switch to using get_unaligned_le16
Input: zforce_ts - use guard notation when acquiring mutexes
...

+2504 -6041
+33 -5
Documentation/devicetree/bindings/input/adi,adp5588.yaml
··· 49 49 interrupt-controller: 50 50 description: 51 51 This property applies if either keypad,num-rows lower than 8 or 52 - keypad,num-columns lower than 10. 52 + keypad,num-columns lower than 10. This property is optional if 53 + keypad,num-rows or keypad,num-columns are not specified as the 54 + device is then configured to be used purely for gpio during which 55 + interrupts may or may not be utilized. 53 56 54 57 '#interrupt-cells': 55 58 const: 2 ··· 68 65 minItems: 1 69 66 maxItems: 2 70 67 68 + dependencies: 69 + keypad,num-rows: 70 + - linux,keymap 71 + - keypad,num-columns 72 + keypad,num-columns: 73 + - linux,keymap 74 + - keypad,num-rows 75 + linux,keymap: 76 + - keypad,num-rows 77 + - keypad,num-columns 78 + - interrupts 79 + interrupt-controller: 80 + - interrupts 81 + 71 82 required: 72 83 - compatible 73 84 - reg 74 - - interrupts 75 - - keypad,num-rows 76 - - keypad,num-columns 77 - - linux,keymap 78 85 79 86 unevaluatedProperties: false 80 87 ··· 121 108 >; 122 109 }; 123 110 }; 111 + 112 + - | 113 + #include <dt-bindings/gpio/gpio.h> 114 + i2c { 115 + #address-cells = <1>; 116 + #size-cells = <0>; 117 + gpio@34 { 118 + compatible = "adi,adp5588"; 119 + reg = <0x34>; 120 + 121 + #gpio-cells = <2>; 122 + gpio-controller; 123 + }; 124 + }; 125 + 124 126 ...
-50
Documentation/devicetree/bindings/input/rotary-encoder.txt
··· 1 - Rotary encoder DT bindings 2 - 3 - Required properties: 4 - - gpios: a spec for at least two GPIOs to be used, most significant first 5 - 6 - Optional properties: 7 - - linux,axis: the input subsystem axis to map to this rotary encoder. 8 - Defaults to 0 (ABS_X / REL_X) 9 - - rotary-encoder,steps: Number of steps in a full turnaround of the 10 - encoder. Only relevant for absolute axis. Defaults to 24 which is a 11 - typical value for such devices. 12 - - rotary-encoder,relative-axis: register a relative axis rather than an 13 - absolute one. Relative axis will only generate +1/-1 events on the input 14 - device, hence no steps need to be passed. 15 - - rotary-encoder,rollover: Automatic rollover when the rotary value becomes 16 - greater than the specified steps or smaller than 0. For absolute axis only. 17 - - rotary-encoder,steps-per-period: Number of steps (stable states) per period. 18 - The values have the following meaning: 19 - 1: Full-period mode (default) 20 - 2: Half-period mode 21 - 4: Quarter-period mode 22 - - wakeup-source: Boolean, rotary encoder can wake up the system. 23 - - rotary-encoder,encoding: String, the method used to encode steps. 24 - Supported are "gray" (the default and more common) and "binary". 25 - 26 - Deprecated properties: 27 - - rotary-encoder,half-period: Makes the driver work on half-period mode. 28 - This property is deprecated. Instead, a 'steps-per-period ' value should 29 - be used, such as "rotary-encoder,steps-per-period = <2>". 30 - 31 - See Documentation/input/devices/rotary-encoder.rst for more information. 32 - 33 - Example: 34 - 35 - rotary@0 { 36 - compatible = "rotary-encoder"; 37 - gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */ 38 - linux,axis = <0>; /* REL_X */ 39 - rotary-encoder,encoding = "gray"; 40 - rotary-encoder,relative-axis; 41 - }; 42 - 43 - rotary@1 { 44 - compatible = "rotary-encoder"; 45 - gpios = <&gpio 21 0>, <&gpio 22 0>; 46 - linux,axis = <1>; /* ABS_Y */ 47 - rotary-encoder,steps = <24>; 48 - rotary-encoder,encoding = "binary"; 49 - rotary-encoder,rollover; 50 - };
+90
Documentation/devicetree/bindings/input/rotary-encoder.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/rotary-encoder.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Rotary encoder 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + description: 13 + See Documentation/input/devices/rotary-encoder.rst for more information. 14 + 15 + properties: 16 + compatible: 17 + const: rotary-encoder 18 + 19 + gpios: 20 + minItems: 2 21 + 22 + linux,axis: 23 + default: 0 24 + description: 25 + the input subsystem axis to map to this rotary encoder. 26 + Defaults to 0 (ABS_X / REL_X) 27 + 28 + rotary-encoder,steps: 29 + $ref: /schemas/types.yaml#/definitions/uint32 30 + default: 24 31 + description: 32 + Number of steps in a full turnaround of the 33 + encoder. Only relevant for absolute axis. Defaults to 24 which is a 34 + typical value for such devices. 35 + 36 + rotary-encoder,relative-axis: 37 + $ref: /schemas/types.yaml#/definitions/flag 38 + description: 39 + register a relative axis rather than an 40 + absolute one. Relative axis will only generate +1/-1 events on the input 41 + device, hence no steps need to be passed. 42 + 43 + rotary-encoder,rollover: 44 + $ref: /schemas/types.yaml#/definitions/int32 45 + description: 46 + Automatic rollover when the rotary value becomes 47 + greater than the specified steps or smaller than 0. For absolute axis only. 48 + 49 + rotary-encoder,steps-per-period: 50 + $ref: /schemas/types.yaml#/definitions/uint32 51 + default: 1 52 + enum: [1, 2, 4] 53 + description: | 54 + Number of steps (stable states) per period. 55 + The values have the following meaning: 56 + 1: Full-period mode (default) 57 + 2: Half-period mode 58 + 4: Quarter-period mode 59 + 60 + wakeup-source: true 61 + 62 + rotary-encoder,encoding: 63 + $ref: /schemas/types.yaml#/definitions/string 64 + description: the method used to encode steps. 65 + enum: [gray, binary] 66 + 67 + rotary-encoder,half-period: 68 + $ref: /schemas/types.yaml#/definitions/flag 69 + deprecated: true 70 + description: 71 + Makes the driver work on half-period mode. 72 + This property is deprecated. Instead, a 'steps-per-period ' value should 73 + be used, such as "rotary-encoder,steps-per-period = <2>". 74 + 75 + required: 76 + - compatible 77 + - gpios 78 + 79 + additionalProperties: false 80 + 81 + examples: 82 + - | 83 + rotary { 84 + compatible = "rotary-encoder"; 85 + gpios = <&gpio 19 1>, <&gpio 20 0>; /* GPIO19 is inverted */ 86 + linux,axis = <0>; /* REL_X */ 87 + rotary-encoder,encoding = "gray"; 88 + rotary-encoder,relative-axis; 89 + }; 90 +
-71
Documentation/devicetree/bindings/input/touchscreen/ad7879.txt
··· 1 - * Analog Devices AD7879(-1)/AD7889(-1) touchscreen interface (SPI/I2C) 2 - 3 - Required properties: 4 - - compatible : for SPI slave, use "adi,ad7879" 5 - for I2C slave, use "adi,ad7879-1" 6 - - reg : SPI chipselect/I2C slave address 7 - See spi-bus.txt for more SPI slave properties 8 - - interrupts : touch controller interrupt 9 - - touchscreen-max-pressure : maximum reported pressure 10 - - adi,resistance-plate-x : total resistance of X-plate (for pressure 11 - calculation) 12 - Optional properties: 13 - - touchscreen-swapped-x-y : X and Y axis are swapped (boolean) 14 - - adi,first-conversion-delay : 0-12: In 128us steps (starting with 128us) 15 - 13 : 2.560ms 16 - 14 : 3.584ms 17 - 15 : 4.096ms 18 - This property has to be a '/bits/ 8' value 19 - - adi,acquisition-time : 0: 2us 20 - 1: 4us 21 - 2: 8us 22 - 3: 16us 23 - This property has to be a '/bits/ 8' value 24 - - adi,median-filter-size : 0: disabled 25 - 1: 4 measurements 26 - 2: 8 measurements 27 - 3: 16 measurements 28 - This property has to be a '/bits/ 8' value 29 - - adi,averaging : 0: 2 middle values (1 if median disabled) 30 - 1: 4 middle values 31 - 2: 8 middle values 32 - 3: 16 values 33 - This property has to be a '/bits/ 8' value 34 - - adi,conversion-interval: : 0 : convert one time only 35 - 1-255: 515us + val * 35us (up to 9.440ms) 36 - This property has to be a '/bits/ 8' value 37 - - gpio-controller : Switch AUX/VBAT/GPIO pin to GPIO mode 38 - 39 - Example: 40 - 41 - touchscreen0@2c { 42 - compatible = "adi,ad7879-1"; 43 - reg = <0x2c>; 44 - interrupt-parent = <&gpio1>; 45 - interrupts = <13 IRQ_TYPE_EDGE_FALLING>; 46 - touchscreen-max-pressure = <4096>; 47 - adi,resistance-plate-x = <120>; 48 - adi,first-conversion-delay = /bits/ 8 <3>; 49 - adi,acquisition-time = /bits/ 8 <1>; 50 - adi,median-filter-size = /bits/ 8 <2>; 51 - adi,averaging = /bits/ 8 <1>; 52 - adi,conversion-interval = /bits/ 8 <255>; 53 - }; 54 - 55 - touchscreen1@1 { 56 - compatible = "adi,ad7879"; 57 - spi-max-frequency = <5000000>; 58 - reg = <1>; 59 - spi-cpol; 60 - spi-cpha; 61 - gpio-controller; 62 - interrupt-parent = <&gpio1>; 63 - interrupts = <13 IRQ_TYPE_EDGE_FALLING>; 64 - touchscreen-max-pressure = <4096>; 65 - adi,resistance-plate-x = <120>; 66 - adi,first-conversion-delay = /bits/ 8 <3>; 67 - adi,acquisition-time = /bits/ 8 <1>; 68 - adi,median-filter-size = /bits/ 8 <2>; 69 - adi,averaging = /bits/ 8 <1>; 70 - adi,conversion-interval = /bits/ 8 <255>; 71 - };
+150
Documentation/devicetree/bindings/input/touchscreen/adi,ad7879.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/adi,ad7879.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Analog Devices AD7879(-1)/AD7889(-1) touchscreen interface (SPI/I2C) 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + description: | 15 + for SPI slave, use "adi,ad7879" 16 + for I2C slave, use "adi,ad7879-1" 17 + enum: 18 + - adi,ad7879 19 + - adi,ad7879-1 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + touchscreen-max-pressure: 28 + $ref: /schemas/types.yaml#/definitions/uint32 29 + description: maximum reported pressure 30 + 31 + adi,resistance-plate-x: 32 + $ref: /schemas/types.yaml#/definitions/uint32 33 + description: total resistance of X-plate (for pressure calculation) 34 + 35 + touchscreen-swapped-x-y: 36 + $ref: /schemas/types.yaml#/definitions/flag 37 + description: X and Y axis are swapped (boolean) 38 + 39 + adi,first-conversion-delay: 40 + $ref: /schemas/types.yaml#/definitions/uint8 41 + default: 0 42 + minimum: 0 43 + maximum: 15 44 + description: | 45 + 0-12: In 128us steps (starting with 128us) 46 + 13 : 2.560ms 47 + 14 : 3.584ms 48 + 15 : 4.096ms 49 + This property has to be a '/bits/ 8' value 50 + 51 + adi,acquisition-time: 52 + $ref: /schemas/types.yaml#/definitions/uint8 53 + default: 0 54 + enum: [0, 1, 2, 3] 55 + description: | 56 + 0: 2us 57 + 1: 4us 58 + 2: 8us 59 + 3: 16us 60 + This property has to be a '/bits/ 8' value 61 + 62 + adi,median-filter-size: 63 + $ref: /schemas/types.yaml#/definitions/uint8 64 + default: 0 65 + enum: [0, 1, 2, 3] 66 + description: | 67 + 0: disabled 68 + 1: 4 measurements 69 + 2: 8 measurements 70 + 3: 16 measurements 71 + This property has to be a '/bits/ 8' value 72 + 73 + adi,averaging: 74 + $ref: /schemas/types.yaml#/definitions/uint8 75 + default: 0 76 + enum: [0, 1, 2, 3] 77 + description: | 78 + 0: 2 middle values (1 if median disabled) 79 + 1: 4 middle values 80 + 2: 8 middle values 81 + 3: 16 values 82 + This property has to be a '/bits/ 8' value 83 + 84 + adi,conversion-interval: 85 + $ref: /schemas/types.yaml#/definitions/uint8 86 + default: 0 87 + description: | 88 + 0 : convert one time only 89 + 1-255: 515us + val * 35us (up to 9.440ms) 90 + This property has to be a '/bits/ 8' value 91 + 92 + gpio-controller: true 93 + 94 + "#gpio-cells": 95 + const: 1 96 + 97 + required: 98 + - compatible 99 + - reg 100 + 101 + allOf: 102 + - $ref: /schemas/spi/spi-peripheral-props.yaml 103 + 104 + unevaluatedProperties: false 105 + 106 + examples: 107 + - | 108 + #include <dt-bindings/interrupt-controller/irq.h> 109 + i2c { 110 + #address-cells = <1>; 111 + #size-cells = <0>; 112 + 113 + touchscreen0@2c { 114 + compatible = "adi,ad7879-1"; 115 + reg = <0x2c>; 116 + interrupt-parent = <&gpio1>; 117 + interrupts = <13 IRQ_TYPE_EDGE_FALLING>; 118 + touchscreen-max-pressure = <4096>; 119 + adi,resistance-plate-x = <120>; 120 + adi,first-conversion-delay = /bits/ 8 <3>; 121 + adi,acquisition-time = /bits/ 8 <1>; 122 + adi,median-filter-size = /bits/ 8 <2>; 123 + adi,averaging = /bits/ 8 <1>; 124 + adi,conversion-interval = /bits/ 8 <255>; 125 + }; 126 + }; 127 + 128 + - | 129 + #include <dt-bindings/interrupt-controller/irq.h> 130 + spi { 131 + #address-cells = <1>; 132 + #size-cells = <0>; 133 + 134 + touchscreen1@1 { 135 + compatible = "adi,ad7879"; 136 + reg = <1>; 137 + spi-max-frequency = <5000000>; 138 + gpio-controller; 139 + #gpio-cells = <1>; 140 + interrupt-parent = <&gpio1>; 141 + interrupts = <13 IRQ_TYPE_EDGE_FALLING>; 142 + touchscreen-max-pressure = <4096>; 143 + adi,resistance-plate-x = <120>; 144 + adi,first-conversion-delay = /bits/ 8 <3>; 145 + adi,acquisition-time = /bits/ 8 <1>; 146 + adi,median-filter-size = /bits/ 8 <2>; 147 + adi,averaging = /bits/ 8 <1>; 148 + adi,conversion-interval = /bits/ 8 <255>; 149 + }; 150 + };
-107
Documentation/devicetree/bindings/input/touchscreen/ads7846.txt
··· 1 - Device tree bindings for TI's ADS7843, ADS7845, ADS7846, ADS7873, TSC2046 2 - SPI driven touch screen controllers. 3 - 4 - The node for this driver must be a child node of a SPI controller, hence 5 - all mandatory properties described in 6 - 7 - Documentation/devicetree/bindings/spi/spi-bus.txt 8 - 9 - must be specified. 10 - 11 - Additional required properties: 12 - 13 - compatible Must be one of the following, depending on the 14 - model: 15 - "ti,tsc2046" 16 - "ti,ads7843" 17 - "ti,ads7845" 18 - "ti,ads7846" 19 - "ti,ads7873" 20 - 21 - interrupts An interrupt node describing the IRQ line the chip's 22 - !PENIRQ pin is connected to. 23 - vcc-supply A regulator node for the supply voltage. 24 - 25 - 26 - Optional properties: 27 - 28 - ti,vref-delay-usecs vref supply delay in usecs, 0 for 29 - external vref (u16). 30 - ti,vref-mv The VREF voltage, in millivolts (u16). 31 - Set to 0 to use internal references 32 - (ADS7846). 33 - ti,keep-vref-on set to keep vref on for differential 34 - measurements as well 35 - ti,settle-delay-usec Settling time of the analog signals; 36 - a function of Vcc and the capacitance 37 - on the X/Y drivers. If set to non-zero, 38 - two samples are taken with settle_delay 39 - us apart, and the second one is used. 40 - ~150 uSec with 0.01uF caps (u16). 41 - ti,penirq-recheck-delay-usecs If set to non-zero, after samples are 42 - taken this delay is applied and penirq 43 - is rechecked, to help avoid false 44 - events. This value is affected by the 45 - material used to build the touch layer 46 - (u16). 47 - ti,x-plate-ohms Resistance of the X-plate, 48 - in Ohms (u16). 49 - ti,y-plate-ohms Resistance of the Y-plate, 50 - in Ohms (u16). 51 - ti,x-min Minimum value on the X axis (u16). 52 - ti,y-min Minimum value on the Y axis (u16). 53 - ti,debounce-tol Tolerance used for filtering (u16). 54 - ti,debounce-rep Additional consecutive good readings 55 - required after the first two (u16). 56 - ti,pendown-gpio-debounce Platform specific debounce time for the 57 - pendown-gpio (u32). 58 - pendown-gpio GPIO handle describing the pin the !PENIRQ 59 - line is connected to. 60 - ti,hsync-gpios GPIO line to poll for hsync 61 - wakeup-source use any event on touchscreen as wakeup event. 62 - (Legacy property support: "linux,wakeup") 63 - touchscreen-size-x General touchscreen binding, see [1]. 64 - touchscreen-size-y General touchscreen binding, see [1]. 65 - touchscreen-max-pressure General touchscreen binding, see [1]. 66 - touchscreen-min-pressure General touchscreen binding, see [1]. 67 - touchscreen-average-samples General touchscreen binding, see [1]. 68 - touchscreen-inverted-x General touchscreen binding, see [1]. 69 - touchscreen-inverted-y General touchscreen binding, see [1]. 70 - touchscreen-swapped-x-y General touchscreen binding, see [1]. 71 - 72 - [1] All general touchscreen properties are described in 73 - Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt. 74 - 75 - Deprecated properties: 76 - 77 - ti,swap-xy swap x and y axis 78 - ti,x-max Maximum value on the X axis (u16). 79 - ti,y-max Maximum value on the Y axis (u16). 80 - ti,pressure-min Minimum reported pressure value 81 - (threshold) - u16. 82 - ti,pressure-max Maximum reported pressure value (u16). 83 - ti,debounce-max Max number of additional readings per 84 - sample (u16). 85 - 86 - Example for a TSC2046 chip connected to an McSPI controller of an OMAP SoC:: 87 - 88 - spi_controller { 89 - tsc2046@0 { 90 - reg = <0>; /* CS0 */ 91 - compatible = "ti,tsc2046"; 92 - interrupt-parent = <&gpio1>; 93 - interrupts = <8 0>; /* BOOT6 / GPIO 8 */ 94 - spi-max-frequency = <1000000>; 95 - pendown-gpio = <&gpio1 8 0>; 96 - vcc-supply = <&reg_vcc3>; 97 - 98 - ti,x-min = /bits/ 16 <0>; 99 - ti,x-max = /bits/ 16 <8000>; 100 - ti,y-min = /bits/ 16 <0>; 101 - ti,y-max = /bits/ 16 <4800>; 102 - ti,x-plate-ohms = /bits/ 16 <40>; 103 - ti,pressure-max = /bits/ 16 <255>; 104 - 105 - wakeup-source; 106 - }; 107 - };
+2 -2
Documentation/devicetree/bindings/input/touchscreen/azoteq,iqs7211.yaml
··· 666 666 #address-cells = <1>; 667 667 #size-cells = <0>; 668 668 669 - touch@56 { 669 + touchscreen@56 { 670 670 compatible = "azoteq,iqs7210a"; 671 671 reg = <0x56>; 672 672 irq-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; ··· 704 704 #address-cells = <1>; 705 705 #size-cells = <0>; 706 706 707 - touch@56 { 707 + touchscreen@56 { 708 708 compatible = "azoteq,iqs7211e"; 709 709 reg = <0x56>; 710 710 irq-gpios = <&gpio 4 (GPIO_ACTIVE_LOW |
-34
Documentation/devicetree/bindings/input/touchscreen/colibri-vf50-ts.txt
··· 1 - * Toradex Colibri VF50 Touchscreen driver 2 - 3 - Required Properties: 4 - - compatible must be toradex,vf50-touchscreen 5 - - io-channels: adc channels being used by the Colibri VF50 module 6 - IIO ADC for Y-, X-, Y+, X+ connections 7 - - xp-gpios: FET gate driver for input of X+ 8 - - xm-gpios: FET gate driver for input of X- 9 - - yp-gpios: FET gate driver for input of Y+ 10 - - ym-gpios: FET gate driver for input of Y- 11 - - interrupts: pen irq interrupt for touch detection, signal from X plate 12 - - pinctrl-names: "idle", "default" 13 - - pinctrl-0: pinctrl node for pen/touch detection, pinctrl must provide 14 - pull-up resistor on X+, X-. 15 - - pinctrl-1: pinctrl node for X/Y and pressure measurement (ADC) state pinmux 16 - - vf50-ts-min-pressure: pressure level at which to stop measuring X/Y values 17 - 18 - Example: 19 - 20 - touchctrl: vf50_touchctrl { 21 - compatible = "toradex,vf50-touchscreen"; 22 - io-channels = <&adc1 0>,<&adc0 0>, 23 - <&adc0 1>,<&adc1 2>; 24 - xp-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; 25 - xm-gpios = <&gpio2 29 GPIO_ACTIVE_HIGH>; 26 - yp-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; 27 - ym-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; 28 - interrupt-parent = <&gpio0>; 29 - interrupts = <8 IRQ_TYPE_LEVEL_LOW>; 30 - pinctrl-names = "idle","default"; 31 - pinctrl-0 = <&pinctrl_touchctrl_idle>, <&pinctrl_touchctrl_gpios>; 32 - pinctrl-1 = <&pinctrl_touchctrl_default>, <&pinctrl_touchctrl_gpios>; 33 - vf50-ts-min-pressure = <200>; 34 - };
+1 -1
Documentation/devicetree/bindings/input/touchscreen/edt-ft5x06.yaml
··· 126 126 i2c { 127 127 #address-cells = <1>; 128 128 #size-cells = <0>; 129 - edt-ft5x06@38 { 129 + touchscreen@38 { 130 130 compatible = "edt,edt-ft5406"; 131 131 reg = <0x38>; 132 132 interrupt-parent = <&gpio2>;
+1 -1
Documentation/devicetree/bindings/input/touchscreen/goodix.yaml
··· 69 69 i2c { 70 70 #address-cells = <1>; 71 71 #size-cells = <0>; 72 - gt928@5d { 72 + touchscreen@5d { 73 73 compatible = "goodix,gt928"; 74 74 reg = <0x5d>; 75 75 interrupt-parent = <&gpio>;
+183
Documentation/devicetree/bindings/input/touchscreen/ti,ads7843.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/ti,ads7843.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: TI's SPI driven touch screen controllers 8 + 9 + maintainers: 10 + - Alexander Stein <alexander.stein@ew.tq-group.com> 11 + - Dmitry Torokhov <dmitry.torokhov@gmail.com> 12 + - Marek Vasut <marex@denx.de> 13 + 14 + description: 15 + TI's ADS7843, ADS7845, ADS7846, ADS7873, TSC2046 SPI driven touch screen 16 + controllers. 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - ti,ads7843 22 + - ti,ads7845 23 + - ti,ads7846 24 + - ti,ads7873 25 + - ti,tsc2046 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + pendown-gpio: 31 + maxItems: 1 32 + description: 33 + GPIO handle describing the pin the !PENIRQ line is connected to. 34 + 35 + vcc-supply: 36 + description: 37 + A regulator node for the supply voltage. 38 + 39 + wakeup-source: true 40 + 41 + ti,debounce-max: 42 + deprecated: true 43 + $ref: /schemas/types.yaml#/definitions/uint16 44 + description: 45 + Max number of additional readings per sample. 46 + 47 + ti,debounce-rep: 48 + $ref: /schemas/types.yaml#/definitions/uint16 49 + description: 50 + Additional consecutive good readings required after the first two. 51 + 52 + ti,debounce-tol: 53 + $ref: /schemas/types.yaml#/definitions/uint16 54 + description: 55 + Tolerance used for filtering. 56 + 57 + ti,hsync-gpios: 58 + maxItems: 1 59 + description: 60 + GPIO line to poll for hsync. 61 + 62 + ti,keep-vref-on: 63 + $ref: /schemas/types.yaml#/definitions/flag 64 + description: 65 + Set to keep Vref on for differential measurements as well. 66 + 67 + ti,pendown-gpio-debounce: 68 + $ref: /schemas/types.yaml#/definitions/uint32 69 + description: 70 + Platform specific debounce time for the pendown-gpio. 71 + 72 + ti,penirq-recheck-delay-usecs: 73 + $ref: /schemas/types.yaml#/definitions/uint16 74 + description: 75 + If set to non-zero, after samples are taken this delay is applied and 76 + penirq is rechecked, to help avoid false events. This value is 77 + affected by the material used to build the touch layer. 78 + 79 + ti,pressure-max: 80 + deprecated: true 81 + $ref: /schemas/types.yaml#/definitions/uint16 82 + description: 83 + Maximum reported pressure value. 84 + 85 + ti,pressure-min: 86 + deprecated: true 87 + $ref: /schemas/types.yaml#/definitions/uint16 88 + description: 89 + Minimum reported pressure value (threshold). 90 + 91 + ti,settle-delay-usec: 92 + $ref: /schemas/types.yaml#/definitions/uint16 93 + description: 94 + Settling time of the analog signals; a function of Vcc and the 95 + capacitance on the X/Y drivers. If set to non-zero, two samples are 96 + taken with settle_delay us apart, and the second one is used. ~150 97 + uSec with 0.01uF caps. 98 + 99 + ti,swap-xy: 100 + deprecated: true 101 + $ref: /schemas/types.yaml#/definitions/flag 102 + description: 103 + Swap x and y axis. 104 + 105 + ti,vref-delay-usecs: 106 + $ref: /schemas/types.yaml#/definitions/uint16 107 + description: 108 + Vref supply delay in usecs, 0 for external Vref. 109 + 110 + ti,vref-mv: 111 + $ref: /schemas/types.yaml#/definitions/uint16 112 + description: 113 + The VREF voltage, in millivolts. 114 + Set to 0 to use internal references (ADS7846). 115 + 116 + ti,x-plate-ohms: 117 + $ref: /schemas/types.yaml#/definitions/uint16 118 + description: 119 + Resistance of the X-plate, in Ohms. 120 + 121 + ti,x-max: 122 + deprecated: true 123 + $ref: /schemas/types.yaml#/definitions/uint16 124 + description: 125 + Maximum value on the X axis. 126 + 127 + ti,x-min: 128 + deprecated: true 129 + $ref: /schemas/types.yaml#/definitions/uint16 130 + description: 131 + Minimum value on the X axis. 132 + 133 + ti,y-plate-ohms: 134 + $ref: /schemas/types.yaml#/definitions/uint16 135 + description: 136 + Resistance of the Y-plate, in Ohms. 137 + 138 + ti,y-max: 139 + deprecated: true 140 + $ref: /schemas/types.yaml#/definitions/uint16 141 + description: 142 + Maximum value on the Y axis. 143 + 144 + ti,y-min: 145 + deprecated: true 146 + $ref: /schemas/types.yaml#/definitions/uint16 147 + description: 148 + Minimum value on the Y axis. 149 + 150 + required: 151 + - compatible 152 + - reg 153 + 154 + allOf: 155 + - $ref: touchscreen.yaml# 156 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 157 + 158 + unevaluatedProperties: false 159 + 160 + examples: 161 + - | 162 + spi{ 163 + #address-cells = <1>; 164 + #size-cells = <0>; 165 + 166 + touchscreen@0 { 167 + compatible = "ti,tsc2046"; 168 + reg = <0>; /* CS0 */ 169 + interrupt-parent = <&gpio1>; 170 + interrupts = <8 0>; /* BOOT6 / GPIO 8 */ 171 + pendown-gpio = <&gpio1 8 0>; 172 + spi-max-frequency = <1000000>; 173 + vcc-supply = <&reg_vcc3>; 174 + wakeup-source; 175 + 176 + ti,pressure-max = /bits/ 16 <255>; 177 + ti,x-max = /bits/ 16 <8000>; 178 + ti,x-min = /bits/ 16 <0>; 179 + ti,x-plate-ohms = /bits/ 16 <40>; 180 + ti,y-max = /bits/ 16 <4800>; 181 + ti,y-min = /bits/ 16 <0>; 182 + }; 183 + };
+77
Documentation/devicetree/bindings/input/touchscreen/toradex,vf50-touchscreen.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/toradex,vf50-touchscreen.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Toradex Colibri VF50 Touchscreen 8 + 9 + maintainers: 10 + - Dmitry Torokhov <dmitry.torokhov@gmail.com> 11 + - Sanchayan Maity <maitysanchayan@gmail.com> 12 + 13 + properties: 14 + compatible: 15 + const: toradex,vf50-touchscreen 16 + 17 + interrupts: 18 + maxItems: 1 19 + 20 + io-channels: 21 + maxItems: 4 22 + description: 23 + adc channels being used by the Colibri VF50 module 24 + IIO ADC for Y-, X-, Y+, X+ connections 25 + 26 + xp-gpios: 27 + description: FET gate driver for input of X+ 28 + 29 + xm-gpios: 30 + description: FET gate driver for input of X- 31 + 32 + yp-gpios: 33 + description: FET gate driver for input of Y+ 34 + 35 + ym-gpios: 36 + description: FET gate driver for input of Y- 37 + 38 + vf50-ts-min-pressure: 39 + $ref: /schemas/types.yaml#/definitions/uint32 40 + minimum: 50 41 + maximum: 2000 42 + description: pressure level at which to stop measuring X/Y values 43 + 44 + required: 45 + - compatible 46 + - io-channels 47 + - xp-gpios 48 + - xm-gpios 49 + - yp-gpios 50 + - ym-gpios 51 + - interrupts 52 + - vf50-ts-min-pressure 53 + 54 + allOf: 55 + - $ref: touchscreen.yaml# 56 + 57 + unevaluatedProperties: false 58 + 59 + examples: 60 + - | 61 + #include <dt-bindings/interrupt-controller/irq.h> 62 + #include <dt-bindings/gpio/gpio.h> 63 + 64 + touchscreen { 65 + compatible = "toradex,vf50-touchscreen"; 66 + interrupt-parent = <&gpio0>; 67 + interrupts = <8 IRQ_TYPE_LEVEL_LOW>; 68 + io-channels = <&adc1 0>, <&adc0 0>, <&adc0 1>, <&adc1 2>; 69 + xp-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; 70 + xm-gpios = <&gpio2 29 GPIO_ACTIVE_HIGH>; 71 + yp-gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; 72 + ym-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; 73 + pinctrl-names = "idle", "default"; 74 + pinctrl-0 = <&pinctrl_touchctrl_idle>, <&pinctrl_touchctrl_gpios>; 75 + pinctrl-1 = <&pinctrl_touchctrl_default>, <&pinctrl_touchctrl_gpios>; 76 + vf50-ts-min-pressure = <200>; 77 + };
+10
Documentation/devicetree/bindings/input/touchscreen/zinitix,bt400.yaml
··· 16 16 17 17 allOf: 18 18 - $ref: touchscreen.yaml# 19 + - $ref: ../input.yaml# 19 20 20 21 properties: 21 22 $nodename: ··· 79 78 1 and 2. Mode 2 is the default and preferred. 80 79 $ref: /schemas/types.yaml#/definitions/uint32 81 80 enum: [1, 2] 81 + 82 + linux,keycodes: 83 + description: 84 + This property specifies an array of keycodes assigned to the 85 + touch-keys that can be present in some touchscreen configurations. 86 + If the touch-keys are enabled, controller firmware will assign some 87 + touch sense lines to those keys. 88 + minItems: 1 89 + maxItems: 8 82 90 83 91 touchscreen-size-x: true 84 92 touchscreen-size-y: true
+1 -1
Documentation/devicetree/bindings/power/wakeup-source.txt
··· 25 25 2. "has-tpo" Documentation/devicetree/bindings/rtc/rtc-opal.txt 26 26 3. "linux,wakeup" Documentation/devicetree/bindings/input/gpio-matrix-keypad.txt 27 27 Documentation/devicetree/bindings/mfd/tc3589x.txt 28 - Documentation/devicetree/bindings/input/touchscreen/ads7846.txt 28 + Documentation/devicetree/bindings/input/touchscreen/ti,ads7843.yaml 29 29 4. "linux,keypad-wakeup" Documentation/devicetree/bindings/input/qcom,pm8921-keypad.yaml 30 30 5. "linux,input-wakeup" Documentation/devicetree/bindings/input/samsung,s3c6410-keypad.yaml 31 31 6. "nvidia,wakeup-source" Documentation/devicetree/bindings/input/nvidia,tegra20-kbc.txt
+7 -1
MAINTAINERS
··· 11198 11198 F: Documentation/input/ 11199 11199 F: drivers/input/ 11200 11200 F: include/dt-bindings/input/ 11201 + F: include/linux/gameport.h 11202 + F: include/linux/i8042.h 11201 11203 F: include/linux/input.h 11202 11204 F: include/linux/input/ 11205 + F: include/linux/libps2.h 11206 + F: include/linux/serio.h 11207 + F: include/uapi/linux/gameport.h 11203 11208 F: include/uapi/linux/input-event-codes.h 11204 11209 F: include/uapi/linux/input.h 11210 + F: include/uapi/linux/serio.h 11211 + F: include/uapi/linux/uinput.h 11205 11212 11206 11213 INPUT MULTITOUCH (MT) PROTOCOL 11207 11214 M: Henrik Rydberg <rydberg@bitmath.org> ··· 25539 25532 25540 25533 YEALINK PHONE DRIVER 25541 25534 M: Henk Vergonet <Henk.Vergonet@gmail.com> 25542 - L: usbb2k-api-dev@nongnu.org 25543 25535 S: Maintained 25544 25536 F: Documentation/input/devices/yealink.rst 25545 25537 F: drivers/input/misc/yealink.*
+109 -54
arch/arm/mach-pxa/spitz.c
··· 378 378 KEY(6, 8, KEY_RIGHT), 379 379 }; 380 380 381 - static const struct matrix_keymap_data spitz_keymap_data = { 382 - .keymap = spitz_keymap, 383 - .keymap_size = ARRAY_SIZE(spitz_keymap), 381 + static const struct software_node_ref_args spitz_mkp_row_gpios[] = { 382 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 12, GPIO_ACTIVE_HIGH), 383 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 17, GPIO_ACTIVE_HIGH), 384 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 91, GPIO_ACTIVE_HIGH), 385 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 34, GPIO_ACTIVE_HIGH), 386 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 36, GPIO_ACTIVE_HIGH), 387 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 38, GPIO_ACTIVE_HIGH), 388 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 39, GPIO_ACTIVE_HIGH), 384 389 }; 385 390 386 - static const uint32_t spitz_row_gpios[] = 387 - { 12, 17, 91, 34, 36, 38, 39 }; 388 - static const uint32_t spitz_col_gpios[] = 389 - { 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 }; 390 - 391 - static struct matrix_keypad_platform_data spitz_mkp_pdata = { 392 - .keymap_data = &spitz_keymap_data, 393 - .row_gpios = spitz_row_gpios, 394 - .col_gpios = spitz_col_gpios, 395 - .num_row_gpios = ARRAY_SIZE(spitz_row_gpios), 396 - .num_col_gpios = ARRAY_SIZE(spitz_col_gpios), 397 - .col_scan_delay_us = 10, 398 - .debounce_ms = 10, 399 - .wakeup = 1, 391 + static const struct software_node_ref_args spitz_mkp_col_gpios[] = { 392 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 88, GPIO_ACTIVE_HIGH), 393 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 23, GPIO_ACTIVE_HIGH), 394 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 24, GPIO_ACTIVE_HIGH), 395 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 25, GPIO_ACTIVE_HIGH), 396 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 26, GPIO_ACTIVE_HIGH), 397 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 27, GPIO_ACTIVE_HIGH), 398 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 52, GPIO_ACTIVE_HIGH), 399 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 103, GPIO_ACTIVE_HIGH), 400 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 107, GPIO_ACTIVE_HIGH), 401 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 108, GPIO_ACTIVE_HIGH), 402 + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 114, GPIO_ACTIVE_HIGH), 400 403 }; 401 404 402 - static struct platform_device spitz_mkp_device = { 405 + static const struct property_entry spitz_mkp_properties[] = { 406 + PROPERTY_ENTRY_U32_ARRAY("linux,keymap", spitz_keymap), 407 + PROPERTY_ENTRY_REF_ARRAY("row-gpios", spitz_mkp_row_gpios), 408 + PROPERTY_ENTRY_REF_ARRAY("col-gpios", spitz_mkp_col_gpios), 409 + PROPERTY_ENTRY_U32("col-scan-delay-us", 10), 410 + PROPERTY_ENTRY_U32("debounce-delay-ms", 10), 411 + PROPERTY_ENTRY_BOOL("wakeup-source"), 412 + { } 413 + }; 414 + 415 + static const struct platform_device_info spitz_mkp_info __initconst = { 403 416 .name = "matrix-keypad", 404 - .id = -1, 405 - .dev = { 406 - .platform_data = &spitz_mkp_pdata, 407 - }, 417 + .id = PLATFORM_DEVID_NONE, 418 + .properties = spitz_mkp_properties, 408 419 }; 420 + 409 421 410 422 static void __init spitz_mkp_init(void) 411 423 { 412 - platform_device_register(&spitz_mkp_device); 424 + struct platform_device *pd; 425 + int err; 426 + 427 + pd = platform_device_register_full(&spitz_mkp_info); 428 + err = PTR_ERR_OR_ZERO(pd); 429 + if (err) 430 + pr_err("failed to create keypad device: %d\n", err); 413 431 } 414 432 #else 415 433 static inline void spitz_mkp_init(void) {} ··· 437 419 * GPIO keys 438 420 ******************************************************************************/ 439 421 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) 440 - static struct gpio_keys_button spitz_gpio_keys[] = { 441 - { 442 - .type = EV_PWR, 443 - .code = KEY_SUSPEND, 444 - .gpio = SPITZ_GPIO_ON_KEY, 445 - .desc = "On Off", 446 - .wakeup = 1, 447 - }, 448 - /* Two buttons detecting the lid state */ 449 - { 450 - .type = EV_SW, 451 - .code = 0, 452 - .gpio = SPITZ_GPIO_SWA, 453 - .desc = "Display Down", 454 - }, 455 - { 456 - .type = EV_SW, 457 - .code = 1, 458 - .gpio = SPITZ_GPIO_SWB, 459 - .desc = "Lid Closed", 460 - }, 422 + static const struct software_node spitz_gpio_keys_node = { 423 + .name = "spitz-gpio-keys", 461 424 }; 462 425 463 - static struct gpio_keys_platform_data spitz_gpio_keys_platform_data = { 464 - .buttons = spitz_gpio_keys, 465 - .nbuttons = ARRAY_SIZE(spitz_gpio_keys), 426 + static const struct property_entry spitz_suspend_key_props[] = { 427 + PROPERTY_ENTRY_U32("linux,input-type", EV_PWR), 428 + PROPERTY_ENTRY_U32("linux,code", KEY_SUSPEND), 429 + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, 430 + SPITZ_GPIO_ON_KEY, GPIO_ACTIVE_HIGH), 431 + PROPERTY_ENTRY_STRING("label", "On Off"), 432 + PROPERTY_ENTRY_BOOL("wakeup-source"), 433 + { } 466 434 }; 467 435 468 - static struct platform_device spitz_gpio_keys_device = { 469 - .name = "gpio-keys", 470 - .id = -1, 471 - .dev = { 472 - .platform_data = &spitz_gpio_keys_platform_data, 473 - }, 436 + static const struct software_node spitz_suspend_key_node = { 437 + .parent = &spitz_gpio_keys_node, 438 + .properties = spitz_suspend_key_props, 439 + }; 440 + 441 + static const struct property_entry spitz_sw1_props[] = { 442 + PROPERTY_ENTRY_U32("linux,input-type", EV_SW), 443 + PROPERTY_ENTRY_U32("linux,code", 0), 444 + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, 445 + SPITZ_GPIO_SWA, GPIO_ACTIVE_HIGH), 446 + PROPERTY_ENTRY_STRING("label", "Display Down"), 447 + { } 448 + }; 449 + 450 + static const struct software_node spitz_sw1_node = { 451 + .parent = &spitz_gpio_keys_node, 452 + .properties = spitz_sw1_props, 453 + }; 454 + 455 + static const struct property_entry spitz_sw2_props[] = { 456 + PROPERTY_ENTRY_U32("linux,input-type", EV_SW), 457 + PROPERTY_ENTRY_U32("linux,code", 1), 458 + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, 459 + SPITZ_GPIO_SWB, GPIO_ACTIVE_HIGH), 460 + PROPERTY_ENTRY_STRING("label", "Lid Closed"), 461 + { } 462 + }; 463 + 464 + static const struct software_node spitz_sw2_node = { 465 + .parent = &spitz_gpio_keys_node, 466 + .properties = spitz_sw2_props, 467 + }; 468 + 469 + static const struct software_node *spitz_gpio_keys_swnodes[] = { 470 + &spitz_gpio_keys_node, 471 + &spitz_suspend_key_node, 472 + &spitz_sw1_node, 473 + &spitz_sw2_node, 474 + NULL 474 475 }; 475 476 476 477 static void __init spitz_keys_init(void) 477 478 { 478 - platform_device_register(&spitz_gpio_keys_device); 479 + struct platform_device_info keys_info = { 480 + .name = "gpio-keys", 481 + .id = PLATFORM_DEVID_NONE, 482 + }; 483 + struct platform_device *pd; 484 + int err; 485 + 486 + err = software_node_register_node_group(spitz_gpio_keys_swnodes); 487 + if (err) { 488 + pr_err("failed to register gpio-keys software nodes: %d\n", err); 489 + return; 490 + } 491 + 492 + keys_info.fwnode = software_node_fwnode(&spitz_gpio_keys_node); 493 + 494 + pd = platform_device_register_full(&keys_info); 495 + err = PTR_ERR_OR_ZERO(pd); 496 + if (err) 497 + pr_err("failed to create gpio-keys device: %d\n", err); 479 498 } 480 499 #else 481 500 static inline void spitz_keys_init(void) {}
+7
drivers/input/evdev.c
··· 498 498 struct input_event event; 499 499 int retval = 0; 500 500 501 + /* 502 + * Limit amount of data we inject into the input subsystem so that 503 + * we do not hold evdev->mutex for too long. 4096 bytes corresponds 504 + * to 170 input events. 505 + */ 506 + count = min(count, 4096); 507 + 501 508 if (count != 0 && count < input_event_size()) 502 509 return -EINVAL; 503 510
+1 -1
drivers/input/input.c
··· 2221 2221 mt_slots = dev->mt->num_slots; 2222 2222 } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { 2223 2223 mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - 2224 - dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, 2224 + dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1; 2225 2225 mt_slots = clamp(mt_slots, 2, 32); 2226 2226 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { 2227 2227 mt_slots = 2;
+5 -11
drivers/input/joystick/adc-joystick.c
··· 132 132 static int adc_joystick_set_axes(struct device *dev, struct adc_joystick *joy) 133 133 { 134 134 struct adc_joystick_axis *axes = joy->axes; 135 - struct fwnode_handle *child; 136 135 s32 range[2], fuzz, flat; 137 136 unsigned int num_axes; 138 137 int error, i; ··· 148 149 return -EINVAL; 149 150 } 150 151 151 - device_for_each_child_node(dev, child) { 152 + device_for_each_child_node_scoped(dev, child) { 152 153 error = fwnode_property_read_u32(child, "reg", &i); 153 154 if (error) { 154 155 dev_err(dev, "reg invalid or missing\n"); 155 - goto err_fwnode_put; 156 + return error; 156 157 } 157 158 158 159 if (i >= num_axes) { 159 - error = -EINVAL; 160 160 dev_err(dev, "No matching axis for reg %d\n", i); 161 - goto err_fwnode_put; 161 + return -EINVAL; 162 162 } 163 163 164 164 error = fwnode_property_read_u32(child, "linux,code", 165 165 &axes[i].code); 166 166 if (error) { 167 167 dev_err(dev, "linux,code invalid or missing\n"); 168 - goto err_fwnode_put; 168 + return error; 169 169 } 170 170 171 171 error = fwnode_property_read_u32_array(child, "abs-range", 172 172 range, 2); 173 173 if (error) { 174 174 dev_err(dev, "abs-range invalid or missing\n"); 175 - goto err_fwnode_put; 175 + return error; 176 176 } 177 177 178 178 if (range[0] > range[1]) { ··· 191 193 } 192 194 193 195 return 0; 194 - 195 - err_fwnode_put: 196 - fwnode_handle_put(child); 197 - return error; 198 196 } 199 197 200 198
-23
drivers/input/keyboard/Kconfig
··· 421 421 To compile this driver as a module, choose M here: the 422 422 module will be called max7359_keypad. 423 423 424 - config KEYBOARD_MCS 425 - tristate "MELFAS MCS Touchkey" 426 - depends on I2C 427 - help 428 - Say Y here if you have the MELFAS MCS5000/5080 touchkey controller 429 - chip in your system. 430 - 431 - If unsure, say N. 432 - 433 - To compile this driver as a module, choose M here: the 434 - module will be called mcs_touchkey. 435 - 436 424 config KEYBOARD_MPR121 437 425 tristate "Freescale MPR121 Touchkey" 438 426 depends on I2C ··· 483 495 484 496 To compile this driver as a module, choose M here: the 485 497 module will be called newtonkbd. 486 - 487 - config KEYBOARD_NOMADIK 488 - tristate "ST-Ericsson Nomadik SKE keyboard" 489 - depends on (ARCH_NOMADIK || ARCH_U8500 || COMPILE_TEST) 490 - select INPUT_MATRIXKMAP 491 - help 492 - Say Y here if you want to use a keypad provided on the SKE controller 493 - used on the Ux500 and Nomadik platforms 494 - 495 - To compile this driver as a module, choose M here: the 496 - module will be called nmk-ske-keypad. 497 498 498 499 config KEYBOARD_NSPIRE 499 500 tristate "TI-NSPIRE built-in keyboard"
-2
drivers/input/keyboard/Makefile
··· 42 42 obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o 43 43 obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o 44 44 obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o 45 - obj-$(CONFIG_KEYBOARD_MCS) += mcs_touchkey.o 46 45 obj-$(CONFIG_KEYBOARD_MPR121) += mpr121_touchkey.o 47 46 obj-$(CONFIG_KEYBOARD_MT6779) += mt6779-keypad.o 48 47 obj-$(CONFIG_KEYBOARD_MTK_PMIC) += mtk-pmic-keys.o 49 48 obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o 50 - obj-$(CONFIG_KEYBOARD_NOMADIK) += nomadik-ske-keypad.o 51 49 obj-$(CONFIG_KEYBOARD_NSPIRE) += nspire-keypad.o 52 50 obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 53 51 obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o
+1 -4
drivers/input/keyboard/adc-keys.c
··· 66 66 static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st) 67 67 { 68 68 struct adc_keys_button *map; 69 - struct fwnode_handle *child; 70 69 int i; 71 70 72 71 st->num_keys = device_get_child_node_count(dev); ··· 79 80 return -ENOMEM; 80 81 81 82 i = 0; 82 - device_for_each_child_node(dev, child) { 83 + device_for_each_child_node_scoped(dev, child) { 83 84 if (fwnode_property_read_u32(child, "press-threshold-microvolt", 84 85 &map[i].voltage)) { 85 86 dev_err(dev, "Key with invalid or missing voltage\n"); 86 - fwnode_handle_put(child); 87 87 return -EINVAL; 88 88 } 89 89 map[i].voltage /= 1000; ··· 90 92 if (fwnode_property_read_u32(child, "linux,code", 91 93 &map[i].keycode)) { 92 94 dev_err(dev, "Key with invalid or missing linux,code\n"); 93 - fwnode_handle_put(child); 94 95 return -EINVAL; 95 96 } 96 97
+53 -46
drivers/input/keyboard/adp5588-keys.c
··· 188 188 u32 cols; 189 189 u32 unlock_keys[2]; 190 190 int nkeys_unlock; 191 + bool gpio_only; 191 192 unsigned short keycode[ADP5588_KEYMAPSIZE]; 192 193 unsigned char gpiomap[ADP5588_MAXGPIO]; 193 194 struct gpio_chip gc; ··· 222 221 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 223 222 int val; 224 223 225 - mutex_lock(&kpad->gpio_lock); 224 + guard(mutex)(&kpad->gpio_lock); 226 225 227 226 if (kpad->dir[bank] & bit) 228 227 val = kpad->dat_out[bank]; 229 228 else 230 229 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank); 231 - 232 - mutex_unlock(&kpad->gpio_lock); 233 230 234 231 return !!(val & bit); 235 232 } ··· 239 240 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 240 241 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 241 242 242 - mutex_lock(&kpad->gpio_lock); 243 + guard(mutex)(&kpad->gpio_lock); 243 244 244 245 if (val) 245 246 kpad->dat_out[bank] |= bit; ··· 247 248 kpad->dat_out[bank] &= ~bit; 248 249 249 250 adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, kpad->dat_out[bank]); 250 - 251 - mutex_unlock(&kpad->gpio_lock); 252 251 } 253 252 254 253 static int adp5588_gpio_set_config(struct gpio_chip *chip, unsigned int off, ··· 256 259 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 257 260 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 258 261 bool pull_disable; 259 - int ret; 260 262 261 263 switch (pinconf_to_config_param(config)) { 262 264 case PIN_CONFIG_BIAS_PULL_UP: ··· 268 272 return -ENOTSUPP; 269 273 } 270 274 271 - mutex_lock(&kpad->gpio_lock); 275 + guard(mutex)(&kpad->gpio_lock); 272 276 273 277 if (pull_disable) 274 278 kpad->pull_dis[bank] |= bit; 275 279 else 276 280 kpad->pull_dis[bank] &= bit; 277 281 278 - ret = adp5588_write(kpad->client, GPIO_PULL1 + bank, 279 - kpad->pull_dis[bank]); 280 - 281 - mutex_unlock(&kpad->gpio_lock); 282 - 283 - return ret; 282 + return adp5588_write(kpad->client, GPIO_PULL1 + bank, 283 + kpad->pull_dis[bank]); 284 284 } 285 285 286 286 static int adp5588_gpio_direction_input(struct gpio_chip *chip, unsigned int off) ··· 284 292 struct adp5588_kpad *kpad = gpiochip_get_data(chip); 285 293 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 286 294 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 287 - int ret; 288 295 289 - mutex_lock(&kpad->gpio_lock); 296 + guard(mutex)(&kpad->gpio_lock); 290 297 291 298 kpad->dir[bank] &= ~bit; 292 - ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 293 - 294 - mutex_unlock(&kpad->gpio_lock); 295 - 296 - return ret; 299 + return adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 297 300 } 298 301 299 302 static int adp5588_gpio_direction_output(struct gpio_chip *chip, ··· 297 310 struct adp5588_kpad *kpad = gpiochip_get_data(chip); 298 311 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 299 312 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 300 - int ret; 313 + int error; 301 314 302 - mutex_lock(&kpad->gpio_lock); 315 + guard(mutex)(&kpad->gpio_lock); 303 316 304 317 kpad->dir[bank] |= bit; 305 318 ··· 308 321 else 309 322 kpad->dat_out[bank] &= ~bit; 310 323 311 - ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, 312 - kpad->dat_out[bank]); 313 - if (ret) 314 - goto out_unlock; 324 + error = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, 325 + kpad->dat_out[bank]); 326 + if (error) 327 + return error; 315 328 316 - ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 329 + error = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); 330 + if (error) 331 + return error; 317 332 318 - out_unlock: 319 - mutex_unlock(&kpad->gpio_lock); 320 - 321 - return ret; 333 + return 0; 322 334 } 323 335 324 336 static int adp5588_build_gpiomap(struct adp5588_kpad *kpad) ··· 432 446 kpad->gc.label = kpad->client->name; 433 447 kpad->gc.owner = THIS_MODULE; 434 448 435 - girq = &kpad->gc.irq; 436 - gpio_irq_chip_set_chip(girq, &adp5588_irq_chip); 437 - girq->handler = handle_bad_irq; 438 - girq->threaded = true; 449 + if (device_property_present(dev, "interrupt-controller")) { 450 + if (!kpad->client->irq) { 451 + dev_err(dev, "Unable to serve as interrupt controller without interrupt"); 452 + return -EINVAL; 453 + } 454 + 455 + girq = &kpad->gc.irq; 456 + gpio_irq_chip_set_chip(girq, &adp5588_irq_chip); 457 + girq->handler = handle_bad_irq; 458 + girq->threaded = true; 459 + } 439 460 440 461 mutex_init(&kpad->gpio_lock); 441 462 ··· 620 627 621 628 for (i = 0; i < KEYP_MAX_EVENT; i++) { 622 629 ret = adp5588_read(client, KEY_EVENTA); 623 - if (ret) 630 + if (ret < 0) 624 631 return ret; 625 632 } 626 633 ··· 639 646 { 640 647 struct i2c_client *client = kpad->client; 641 648 int ret, i; 649 + 650 + /* 651 + * Check if the device is to be operated purely in GPIO mode. To do 652 + * so, check that no keypad rows or columns have been specified, 653 + * since all GPINS should be configured as GPIO. 654 + */ 655 + if (!device_property_present(&client->dev, "keypad,num-rows") && 656 + !device_property_present(&client->dev, "keypad,num-columns")) { 657 + /* If purely GPIO, skip keypad setup */ 658 + kpad->gpio_only = true; 659 + return 0; 660 + } 642 661 643 662 ret = matrix_keypad_parse_properties(&client->dev, &kpad->rows, 644 663 &kpad->cols); ··· 795 790 if (error) 796 791 return error; 797 792 798 - error = devm_request_threaded_irq(&client->dev, client->irq, 799 - adp5588_hard_irq, adp5588_thread_irq, 800 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 801 - client->dev.driver->name, kpad); 802 - if (error) { 803 - dev_err(&client->dev, "failed to request irq %d: %d\n", 804 - client->irq, error); 805 - return error; 793 + if (client->irq) { 794 + error = devm_request_threaded_irq(&client->dev, client->irq, 795 + adp5588_hard_irq, adp5588_thread_irq, 796 + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 797 + client->dev.driver->name, kpad); 798 + if (error) { 799 + dev_err(&client->dev, "failed to request irq %d: %d\n", 800 + client->irq, error); 801 + return error; 802 + } 806 803 } 807 804 808 - dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); 805 + dev_info(&client->dev, "Rev.%d controller\n", revid); 809 806 return 0; 810 807 } 811 808
+15 -22
drivers/input/keyboard/atkbd.c
··· 639 639 { 640 640 struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work); 641 641 642 - mutex_lock(&atkbd->mutex); 642 + guard(mutex)(&atkbd->mutex); 643 643 644 644 if (!atkbd->enabled) { 645 645 /* ··· 657 657 if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) 658 658 atkbd_set_repeat_rate(atkbd); 659 659 } 660 - 661 - mutex_unlock(&atkbd->mutex); 662 660 } 663 661 664 662 /* ··· 1359 1361 { 1360 1362 struct atkbd *atkbd = atkbd_from_serio(serio); 1361 1363 struct serio_driver *drv = serio->drv; 1362 - int retval = -1; 1364 + int error; 1363 1365 1364 1366 if (!atkbd || !drv) { 1365 1367 dev_dbg(&serio->dev, ··· 1367 1369 return -1; 1368 1370 } 1369 1371 1370 - mutex_lock(&atkbd->mutex); 1372 + guard(mutex)(&atkbd->mutex); 1371 1373 1372 1374 atkbd_disable(atkbd); 1373 1375 1374 1376 if (atkbd->write) { 1375 - if (atkbd_probe(atkbd)) 1376 - goto out; 1377 + error = atkbd_probe(atkbd); 1378 + if (error) 1379 + return error; 1377 1380 1378 1381 if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) 1379 - goto out; 1382 + return -EIO; 1380 1383 1381 1384 /* 1382 1385 * Restore LED state and repeat rate. While input core ··· 1403 1404 if (atkbd->write) 1404 1405 atkbd_activate(atkbd); 1405 1406 1406 - retval = 0; 1407 - 1408 - out: 1409 - mutex_unlock(&atkbd->mutex); 1410 - return retval; 1407 + return 0; 1411 1408 } 1412 1409 1413 1410 static const struct serio_device_id atkbd_serio_ids[] = { ··· 1460 1465 struct atkbd *atkbd = atkbd_from_serio(serio); 1461 1466 int retval; 1462 1467 1463 - retval = mutex_lock_interruptible(&atkbd->mutex); 1464 - if (retval) 1468 + scoped_guard(mutex_intr, &atkbd->mutex) { 1469 + atkbd_disable(atkbd); 1470 + retval = handler(atkbd, buf, count); 1471 + atkbd_enable(atkbd); 1472 + 1465 1473 return retval; 1474 + } 1466 1475 1467 - atkbd_disable(atkbd); 1468 - retval = handler(atkbd, buf, count); 1469 - atkbd_enable(atkbd); 1470 - 1471 - mutex_unlock(&atkbd->mutex); 1472 - 1473 - return retval; 1476 + return -EINTR; 1474 1477 } 1475 1478 1476 1479 static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
+19 -31
drivers/input/keyboard/gpio_keys.c
··· 245 245 { 246 246 int n_events = get_n_events_by_type(type); 247 247 const unsigned long *bitmap = get_bm_events_by_type(ddata->input, type); 248 - unsigned long *bits; 249 248 ssize_t error; 250 249 int i; 251 250 252 - bits = bitmap_alloc(n_events, GFP_KERNEL); 251 + unsigned long *bits __free(bitmap) = bitmap_alloc(n_events, GFP_KERNEL); 253 252 if (!bits) 254 253 return -ENOMEM; 255 254 256 255 error = bitmap_parselist(buf, bits, n_events); 257 256 if (error) 258 - goto out; 257 + return error; 259 258 260 259 /* First validate */ 261 - if (!bitmap_subset(bits, bitmap, n_events)) { 262 - error = -EINVAL; 263 - goto out; 264 - } 260 + if (!bitmap_subset(bits, bitmap, n_events)) 261 + return -EINVAL; 265 262 266 263 for (i = 0; i < ddata->pdata->nbuttons; i++) { 267 264 struct gpio_button_data *bdata = &ddata->data[i]; ··· 268 271 269 272 if (test_bit(*bdata->code, bits) && 270 273 !bdata->button->can_disable) { 271 - error = -EINVAL; 272 - goto out; 274 + return -EINVAL; 273 275 } 274 276 } 275 277 276 - mutex_lock(&ddata->disable_lock); 278 + guard(mutex)(&ddata->disable_lock); 277 279 278 280 for (i = 0; i < ddata->pdata->nbuttons; i++) { 279 281 struct gpio_button_data *bdata = &ddata->data[i]; ··· 286 290 gpio_keys_enable_button(bdata); 287 291 } 288 292 289 - mutex_unlock(&ddata->disable_lock); 290 - 291 - out: 292 - bitmap_free(bits); 293 - return error; 293 + return 0; 294 294 } 295 295 296 296 #define ATTR_SHOW_FN(name, type, only_disabled) \ ··· 462 470 { 463 471 struct gpio_button_data *bdata = dev_id; 464 472 struct input_dev *input = bdata->input; 465 - unsigned long flags; 466 473 467 474 BUG_ON(irq != bdata->irq); 468 475 469 - spin_lock_irqsave(&bdata->lock, flags); 476 + guard(spinlock_irqsave)(&bdata->lock); 470 477 471 478 if (!bdata->key_pressed) { 472 479 if (bdata->button->wakeup) ··· 488 497 ms_to_ktime(bdata->release_delay), 489 498 HRTIMER_MODE_REL_HARD); 490 499 out: 491 - spin_unlock_irqrestore(&bdata->lock, flags); 492 500 return IRQ_HANDLED; 493 501 } 494 502 ··· 758 768 { 759 769 struct gpio_keys_platform_data *pdata; 760 770 struct gpio_keys_button *button; 761 - struct fwnode_handle *child; 762 771 int nbuttons, irq; 763 772 764 773 nbuttons = device_get_child_node_count(dev); ··· 779 790 780 791 device_property_read_string(dev, "label", &pdata->name); 781 792 782 - device_for_each_child_node(dev, child) { 793 + device_for_each_child_node_scoped(dev, child) { 783 794 if (is_of_node(child)) { 784 795 irq = of_irq_get_byname(to_of_node(child), "irq"); 785 796 if (irq > 0) ··· 797 808 if (fwnode_property_read_u32(child, "linux,code", 798 809 &button->code)) { 799 810 dev_err(dev, "Button without keycode\n"); 800 - fwnode_handle_put(child); 801 811 return ERR_PTR(-EINVAL); 802 812 } 803 813 ··· 1052 1064 if (error) 1053 1065 return error; 1054 1066 } else { 1055 - mutex_lock(&input->mutex); 1067 + guard(mutex)(&input->mutex); 1068 + 1056 1069 if (input_device_enabled(input)) 1057 1070 gpio_keys_close(input); 1058 - mutex_unlock(&input->mutex); 1059 1071 } 1060 1072 1061 1073 return 0; ··· 1065 1077 { 1066 1078 struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); 1067 1079 struct input_dev *input = ddata->input; 1068 - int error = 0; 1080 + int error; 1069 1081 1070 1082 if (device_may_wakeup(dev)) { 1071 1083 gpio_keys_disable_wakeup(ddata); 1072 1084 } else { 1073 - mutex_lock(&input->mutex); 1074 - if (input_device_enabled(input)) 1075 - error = gpio_keys_open(input); 1076 - mutex_unlock(&input->mutex); 1077 - } 1085 + guard(mutex)(&input->mutex); 1078 1086 1079 - if (error) 1080 - return error; 1087 + if (input_device_enabled(input)) { 1088 + error = gpio_keys_open(input); 1089 + if (error) 1090 + return error; 1091 + } 1092 + } 1081 1093 1082 1094 gpio_keys_report_state(ddata); 1083 1095 return 0;
+1 -3
drivers/input/keyboard/gpio_keys_polled.c
··· 144 144 { 145 145 struct gpio_keys_platform_data *pdata; 146 146 struct gpio_keys_button *button; 147 - struct fwnode_handle *child; 148 147 int nbuttons; 149 148 150 149 nbuttons = device_get_child_node_count(dev); ··· 165 166 166 167 device_property_read_string(dev, "label", &pdata->name); 167 168 168 - device_for_each_child_node(dev, child) { 169 + device_for_each_child_node_scoped(dev, child) { 169 170 if (fwnode_property_read_u32(child, "linux,code", 170 171 &button->code)) { 171 172 dev_err(dev, "button without keycode\n"); 172 - fwnode_handle_put(child); 173 173 return ERR_PTR(-EINVAL); 174 174 } 175 175
+2 -5
drivers/input/keyboard/iqs62x-keys.c
··· 45 45 static int iqs62x_keys_parse_prop(struct platform_device *pdev, 46 46 struct iqs62x_keys_private *iqs62x_keys) 47 47 { 48 - struct fwnode_handle *child; 49 48 unsigned int val; 50 49 int ret, i; 51 50 ··· 67 68 } 68 69 69 70 for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++) { 70 - child = device_get_named_child_node(&pdev->dev, 71 + struct fwnode_handle *child __free(fwnode_handle) = 72 + device_get_named_child_node(&pdev->dev, 71 73 iqs62x_switch_names[i]); 72 74 if (!child) 73 75 continue; ··· 77 77 if (ret) { 78 78 dev_err(&pdev->dev, "Failed to read switch code: %d\n", 79 79 ret); 80 - fwnode_handle_put(child); 81 80 return ret; 82 81 } 83 82 iqs62x_keys->switches[i].code = val; ··· 90 91 iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ? 91 92 IQS62X_EVENT_HALL_N_T : 92 93 IQS62X_EVENT_HALL_S_T); 93 - 94 - fwnode_handle_put(child); 95 94 } 96 95 97 96 return 0;
+140 -196
drivers/input/keyboard/matrix_keypad.c
··· 17 17 #include <linux/jiffies.h> 18 18 #include <linux/module.h> 19 19 #include <linux/gpio.h> 20 + #include <linux/gpio/consumer.h> 20 21 #include <linux/input/matrix_keypad.h> 21 22 #include <linux/slab.h> 22 23 #include <linux/of.h> 23 - #include <linux/of_gpio.h> 24 - #include <linux/of_platform.h> 25 24 26 25 struct matrix_keypad { 27 - const struct matrix_keypad_platform_data *pdata; 28 26 struct input_dev *input_dev; 29 27 unsigned int row_shift; 30 28 29 + unsigned int col_scan_delay_us; 30 + /* key debounce interval in milli-second */ 31 + unsigned int debounce_ms; 32 + bool drive_inactive_cols; 33 + 34 + struct gpio_desc *row_gpios[MATRIX_MAX_ROWS]; 35 + unsigned int num_row_gpios; 36 + 37 + struct gpio_desc *col_gpios[MATRIX_MAX_ROWS]; 38 + unsigned int num_col_gpios; 39 + 31 40 unsigned int row_irqs[MATRIX_MAX_ROWS]; 32 - unsigned int num_row_irqs; 33 41 DECLARE_BITMAP(wakeup_enabled_irqs, MATRIX_MAX_ROWS); 34 42 35 43 uint32_t last_key_state[MATRIX_MAX_COLS]; ··· 53 45 * columns. In that case it is configured here to be input, otherwise it is 54 46 * driven with the inactive value. 55 47 */ 56 - static void __activate_col(const struct matrix_keypad_platform_data *pdata, 57 - int col, bool on) 48 + static void __activate_col(struct matrix_keypad *keypad, int col, bool on) 58 49 { 59 - bool level_on = !pdata->active_low; 60 - 61 50 if (on) { 62 - gpio_direction_output(pdata->col_gpios[col], level_on); 51 + gpiod_direction_output(keypad->col_gpios[col], 1); 63 52 } else { 64 - gpio_set_value_cansleep(pdata->col_gpios[col], !level_on); 65 - if (!pdata->drive_inactive_cols) 66 - gpio_direction_input(pdata->col_gpios[col]); 53 + gpiod_set_value_cansleep(keypad->col_gpios[col], 0); 54 + if (!keypad->drive_inactive_cols) 55 + gpiod_direction_input(keypad->col_gpios[col]); 67 56 } 68 57 } 69 58 70 - static void activate_col(const struct matrix_keypad_platform_data *pdata, 71 - int col, bool on) 59 + static void activate_col(struct matrix_keypad *keypad, int col, bool on) 72 60 { 73 - __activate_col(pdata, col, on); 61 + __activate_col(keypad, col, on); 74 62 75 - if (on && pdata->col_scan_delay_us) 76 - udelay(pdata->col_scan_delay_us); 63 + if (on && keypad->col_scan_delay_us) 64 + udelay(keypad->col_scan_delay_us); 77 65 } 78 66 79 - static void activate_all_cols(const struct matrix_keypad_platform_data *pdata, 80 - bool on) 67 + static void activate_all_cols(struct matrix_keypad *keypad, bool on) 81 68 { 82 69 int col; 83 70 84 - for (col = 0; col < pdata->num_col_gpios; col++) 85 - __activate_col(pdata, col, on); 71 + for (col = 0; col < keypad->num_col_gpios; col++) 72 + __activate_col(keypad, col, on); 86 73 } 87 74 88 - static bool row_asserted(const struct matrix_keypad_platform_data *pdata, 89 - int row) 75 + static bool row_asserted(struct matrix_keypad *keypad, int row) 90 76 { 91 - return gpio_get_value_cansleep(pdata->row_gpios[row]) ? 92 - !pdata->active_low : pdata->active_low; 77 + return gpiod_get_value_cansleep(keypad->row_gpios[row]); 93 78 } 94 79 95 80 static void enable_row_irqs(struct matrix_keypad *keypad) 96 81 { 97 82 int i; 98 83 99 - for (i = 0; i < keypad->num_row_irqs; i++) 84 + for (i = 0; i < keypad->num_row_gpios; i++) 100 85 enable_irq(keypad->row_irqs[i]); 101 86 } 102 87 ··· 97 96 { 98 97 int i; 99 98 100 - for (i = 0; i < keypad->num_row_irqs; i++) 99 + for (i = 0; i < keypad->num_row_gpios; i++) 101 100 disable_irq_nosync(keypad->row_irqs[i]); 102 101 } 103 102 ··· 110 109 container_of(work, struct matrix_keypad, work.work); 111 110 struct input_dev *input_dev = keypad->input_dev; 112 111 const unsigned short *keycodes = input_dev->keycode; 113 - const struct matrix_keypad_platform_data *pdata = keypad->pdata; 114 112 uint32_t new_state[MATRIX_MAX_COLS]; 115 113 int row, col, code; 116 114 117 115 /* de-activate all columns for scanning */ 118 - activate_all_cols(pdata, false); 116 + activate_all_cols(keypad, false); 119 117 120 118 memset(new_state, 0, sizeof(new_state)); 121 119 122 - for (row = 0; row < pdata->num_row_gpios; row++) 123 - gpio_direction_input(pdata->row_gpios[row]); 120 + for (row = 0; row < keypad->num_row_gpios; row++) 121 + gpiod_direction_input(keypad->row_gpios[row]); 124 122 125 123 /* assert each column and read the row status out */ 126 - for (col = 0; col < pdata->num_col_gpios; col++) { 124 + for (col = 0; col < keypad->num_col_gpios; col++) { 127 125 128 - activate_col(pdata, col, true); 126 + activate_col(keypad, col, true); 129 127 130 - for (row = 0; row < pdata->num_row_gpios; row++) 128 + for (row = 0; row < keypad->num_row_gpios; row++) 131 129 new_state[col] |= 132 - row_asserted(pdata, row) ? (1 << row) : 0; 130 + row_asserted(keypad, row) ? BIT(row) : 0; 133 131 134 - activate_col(pdata, col, false); 132 + activate_col(keypad, col, false); 135 133 } 136 134 137 - for (col = 0; col < pdata->num_col_gpios; col++) { 135 + for (col = 0; col < keypad->num_col_gpios; col++) { 138 136 uint32_t bits_changed; 139 137 140 138 bits_changed = keypad->last_key_state[col] ^ new_state[col]; 141 139 if (bits_changed == 0) 142 140 continue; 143 141 144 - for (row = 0; row < pdata->num_row_gpios; row++) { 145 - if ((bits_changed & (1 << row)) == 0) 142 + for (row = 0; row < keypad->num_row_gpios; row++) { 143 + if (!(bits_changed & BIT(row))) 146 144 continue; 147 145 148 146 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); ··· 155 155 156 156 memcpy(keypad->last_key_state, new_state, sizeof(new_state)); 157 157 158 - activate_all_cols(pdata, true); 158 + activate_all_cols(keypad, true); 159 159 160 160 /* Enable IRQs again */ 161 161 spin_lock_irq(&keypad->lock); ··· 182 182 disable_row_irqs(keypad); 183 183 keypad->scan_pending = true; 184 184 schedule_delayed_work(&keypad->work, 185 - msecs_to_jiffies(keypad->pdata->debounce_ms)); 185 + msecs_to_jiffies(keypad->debounce_ms)); 186 186 187 187 out: 188 188 spin_unlock_irqrestore(&keypad->lock, flags); ··· 225 225 { 226 226 int i; 227 227 228 - for_each_clear_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) 228 + for_each_clear_bit(i, keypad->wakeup_enabled_irqs, 229 + keypad->num_row_gpios) 229 230 if (enable_irq_wake(keypad->row_irqs[i]) == 0) 230 231 __set_bit(i, keypad->wakeup_enabled_irqs); 231 232 } ··· 235 234 { 236 235 int i; 237 236 238 - for_each_set_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) { 237 + for_each_set_bit(i, keypad->wakeup_enabled_irqs, 238 + keypad->num_row_gpios) { 239 239 disable_irq_wake(keypad->row_irqs[i]); 240 240 __clear_bit(i, keypad->wakeup_enabled_irqs); 241 241 } ··· 274 272 static int matrix_keypad_init_gpio(struct platform_device *pdev, 275 273 struct matrix_keypad *keypad) 276 274 { 277 - const struct matrix_keypad_platform_data *pdata = keypad->pdata; 278 - int i, irq, err; 275 + bool active_low; 276 + int nrow, ncol; 277 + int err; 278 + int i; 279 279 280 - /* initialized strobe lines as outputs, activated */ 281 - for (i = 0; i < pdata->num_col_gpios; i++) { 282 - err = devm_gpio_request(&pdev->dev, 283 - pdata->col_gpios[i], "matrix_kbd_col"); 280 + nrow = gpiod_count(&pdev->dev, "row"); 281 + ncol = gpiod_count(&pdev->dev, "col"); 282 + if (nrow < 0 || ncol < 0) { 283 + dev_err(&pdev->dev, "missing row or column GPIOs\n"); 284 + return -EINVAL; 285 + } 286 + 287 + keypad->num_row_gpios = nrow; 288 + keypad->num_col_gpios = ncol; 289 + 290 + active_low = device_property_read_bool(&pdev->dev, "gpio-activelow"); 291 + 292 + /* initialize strobe lines as outputs, activated */ 293 + for (i = 0; i < keypad->num_col_gpios; i++) { 294 + keypad->col_gpios[i] = devm_gpiod_get_index(&pdev->dev, "col", 295 + i, GPIOD_ASIS); 296 + err = PTR_ERR_OR_ZERO(keypad->col_gpios[i]); 284 297 if (err) { 285 298 dev_err(&pdev->dev, 286 - "failed to request GPIO%d for COL%d\n", 287 - pdata->col_gpios[i], i); 299 + "failed to request GPIO for COL%d: %d\n", 300 + i, err); 288 301 return err; 289 302 } 290 303 291 - gpio_direction_output(pdata->col_gpios[i], !pdata->active_low); 304 + gpiod_set_consumer_name(keypad->col_gpios[i], "matrix_kbd_col"); 305 + 306 + if (active_low ^ gpiod_is_active_low(keypad->col_gpios[i])) 307 + gpiod_toggle_active_low(keypad->col_gpios[i]); 308 + 309 + gpiod_direction_output(keypad->col_gpios[i], 1); 292 310 } 293 311 294 - for (i = 0; i < pdata->num_row_gpios; i++) { 295 - err = devm_gpio_request(&pdev->dev, 296 - pdata->row_gpios[i], "matrix_kbd_row"); 312 + for (i = 0; i < keypad->num_row_gpios; i++) { 313 + keypad->row_gpios[i] = devm_gpiod_get_index(&pdev->dev, "row", 314 + i, GPIOD_IN); 315 + err = PTR_ERR_OR_ZERO(keypad->row_gpios[i]); 297 316 if (err) { 298 317 dev_err(&pdev->dev, 299 - "failed to request GPIO%d for ROW%d\n", 300 - pdata->row_gpios[i], i); 318 + "failed to request GPIO for ROW%d: %d\n", 319 + i, err); 301 320 return err; 302 321 } 303 322 304 - gpio_direction_input(pdata->row_gpios[i]); 323 + gpiod_set_consumer_name(keypad->row_gpios[i], "matrix_kbd_row"); 324 + 325 + if (active_low ^ gpiod_is_active_low(keypad->row_gpios[i])) 326 + gpiod_toggle_active_low(keypad->row_gpios[i]); 305 327 } 306 328 307 - if (pdata->clustered_irq > 0) { 308 - err = devm_request_any_context_irq(&pdev->dev, 309 - pdata->clustered_irq, 310 - matrix_keypad_interrupt, 311 - pdata->clustered_irq_flags, 312 - "matrix-keypad", keypad); 329 + return 0; 330 + } 331 + 332 + static int matrix_keypad_setup_interrupts(struct platform_device *pdev, 333 + struct matrix_keypad *keypad) 334 + { 335 + int err; 336 + int irq; 337 + int i; 338 + 339 + for (i = 0; i < keypad->num_row_gpios; i++) { 340 + irq = gpiod_to_irq(keypad->row_gpios[i]); 341 + if (irq < 0) { 342 + err = irq; 343 + dev_err(&pdev->dev, 344 + "Unable to convert GPIO line %i to irq: %d\n", 345 + i, err); 346 + return err; 347 + } 348 + 349 + err = devm_request_any_context_irq(&pdev->dev, irq, 350 + matrix_keypad_interrupt, 351 + IRQF_TRIGGER_RISING | 352 + IRQF_TRIGGER_FALLING, 353 + "matrix-keypad", keypad); 313 354 if (err < 0) { 314 355 dev_err(&pdev->dev, 315 - "Unable to acquire clustered interrupt\n"); 356 + "Unable to acquire interrupt for row %i: %d\n", 357 + i, err); 316 358 return err; 317 359 } 318 360 319 - keypad->row_irqs[0] = pdata->clustered_irq; 320 - keypad->num_row_irqs = 1; 321 - } else { 322 - for (i = 0; i < pdata->num_row_gpios; i++) { 323 - irq = gpio_to_irq(pdata->row_gpios[i]); 324 - if (irq < 0) { 325 - err = irq; 326 - dev_err(&pdev->dev, 327 - "Unable to convert GPIO line %i to irq: %d\n", 328 - pdata->row_gpios[i], err); 329 - return err; 330 - } 331 - 332 - err = devm_request_any_context_irq(&pdev->dev, 333 - irq, 334 - matrix_keypad_interrupt, 335 - IRQF_TRIGGER_RISING | 336 - IRQF_TRIGGER_FALLING, 337 - "matrix-keypad", keypad); 338 - if (err < 0) { 339 - dev_err(&pdev->dev, 340 - "Unable to acquire interrupt for GPIO line %i\n", 341 - pdata->row_gpios[i]); 342 - return err; 343 - } 344 - 345 - keypad->row_irqs[i] = irq; 346 - } 347 - 348 - keypad->num_row_irqs = pdata->num_row_gpios; 361 + keypad->row_irqs[i] = irq; 349 362 } 350 363 351 364 /* initialized as disabled - enabled by input->open */ ··· 369 352 return 0; 370 353 } 371 354 372 - #ifdef CONFIG_OF 373 - static struct matrix_keypad_platform_data * 374 - matrix_keypad_parse_dt(struct device *dev) 375 - { 376 - struct matrix_keypad_platform_data *pdata; 377 - struct device_node *np = dev->of_node; 378 - unsigned int *gpios; 379 - int ret, i, nrow, ncol; 380 - 381 - if (!np) { 382 - dev_err(dev, "device lacks DT data\n"); 383 - return ERR_PTR(-ENODEV); 384 - } 385 - 386 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 387 - if (!pdata) { 388 - dev_err(dev, "could not allocate memory for platform data\n"); 389 - return ERR_PTR(-ENOMEM); 390 - } 391 - 392 - pdata->num_row_gpios = nrow = gpiod_count(dev, "row"); 393 - pdata->num_col_gpios = ncol = gpiod_count(dev, "col"); 394 - if (nrow < 0 || ncol < 0) { 395 - dev_err(dev, "number of keypad rows/columns not specified\n"); 396 - return ERR_PTR(-EINVAL); 397 - } 398 - 399 - pdata->no_autorepeat = of_property_read_bool(np, "linux,no-autorepeat"); 400 - 401 - pdata->wakeup = of_property_read_bool(np, "wakeup-source") || 402 - of_property_read_bool(np, "linux,wakeup"); /* legacy */ 403 - 404 - pdata->active_low = of_property_read_bool(np, "gpio-activelow"); 405 - 406 - pdata->drive_inactive_cols = 407 - of_property_read_bool(np, "drive-inactive-cols"); 408 - 409 - of_property_read_u32(np, "debounce-delay-ms", &pdata->debounce_ms); 410 - of_property_read_u32(np, "col-scan-delay-us", 411 - &pdata->col_scan_delay_us); 412 - 413 - gpios = devm_kcalloc(dev, 414 - pdata->num_row_gpios + pdata->num_col_gpios, 415 - sizeof(unsigned int), 416 - GFP_KERNEL); 417 - if (!gpios) { 418 - dev_err(dev, "could not allocate memory for gpios\n"); 419 - return ERR_PTR(-ENOMEM); 420 - } 421 - 422 - for (i = 0; i < nrow; i++) { 423 - ret = of_get_named_gpio(np, "row-gpios", i); 424 - if (ret < 0) 425 - return ERR_PTR(ret); 426 - gpios[i] = ret; 427 - } 428 - 429 - for (i = 0; i < ncol; i++) { 430 - ret = of_get_named_gpio(np, "col-gpios", i); 431 - if (ret < 0) 432 - return ERR_PTR(ret); 433 - gpios[nrow + i] = ret; 434 - } 435 - 436 - pdata->row_gpios = gpios; 437 - pdata->col_gpios = &gpios[pdata->num_row_gpios]; 438 - 439 - return pdata; 440 - } 441 - #else 442 - static inline struct matrix_keypad_platform_data * 443 - matrix_keypad_parse_dt(struct device *dev) 444 - { 445 - dev_err(dev, "no platform data defined\n"); 446 - 447 - return ERR_PTR(-EINVAL); 448 - } 449 - #endif 450 - 451 355 static int matrix_keypad_probe(struct platform_device *pdev) 452 356 { 453 - const struct matrix_keypad_platform_data *pdata; 454 357 struct matrix_keypad *keypad; 455 358 struct input_dev *input_dev; 359 + bool wakeup; 456 360 int err; 457 - 458 - pdata = dev_get_platdata(&pdev->dev); 459 - if (!pdata) { 460 - pdata = matrix_keypad_parse_dt(&pdev->dev); 461 - if (IS_ERR(pdata)) 462 - return PTR_ERR(pdata); 463 - } else if (!pdata->keymap_data) { 464 - dev_err(&pdev->dev, "no keymap data defined\n"); 465 - return -EINVAL; 466 - } 467 361 468 362 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); 469 363 if (!keypad) ··· 385 457 return -ENOMEM; 386 458 387 459 keypad->input_dev = input_dev; 388 - keypad->pdata = pdata; 389 - keypad->row_shift = get_count_order(pdata->num_col_gpios); 390 460 keypad->stopped = true; 391 461 INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); 392 462 spin_lock_init(&keypad->lock); 463 + 464 + keypad->drive_inactive_cols = 465 + device_property_read_bool(&pdev->dev, "drive-inactive-cols"); 466 + device_property_read_u32(&pdev->dev, "debounce-delay-ms", 467 + &keypad->debounce_ms); 468 + device_property_read_u32(&pdev->dev, "col-scan-delay-us", 469 + &keypad->col_scan_delay_us); 470 + 471 + err = matrix_keypad_init_gpio(pdev, keypad); 472 + if (err) 473 + return err; 474 + 475 + keypad->row_shift = get_count_order(keypad->num_col_gpios); 476 + 477 + err = matrix_keypad_setup_interrupts(pdev, keypad); 478 + if (err) 479 + return err; 393 480 394 481 input_dev->name = pdev->name; 395 482 input_dev->id.bustype = BUS_HOST; 396 483 input_dev->open = matrix_keypad_start; 397 484 input_dev->close = matrix_keypad_stop; 398 485 399 - err = matrix_keypad_build_keymap(pdata->keymap_data, NULL, 400 - pdata->num_row_gpios, 401 - pdata->num_col_gpios, 486 + err = matrix_keypad_build_keymap(NULL, NULL, 487 + keypad->num_row_gpios, 488 + keypad->num_col_gpios, 402 489 NULL, input_dev); 403 490 if (err) { 404 491 dev_err(&pdev->dev, "failed to build keymap\n"); 405 492 return -ENOMEM; 406 493 } 407 494 408 - if (!pdata->no_autorepeat) 495 + if (!device_property_read_bool(&pdev->dev, "linux,no-autorepeat")) 409 496 __set_bit(EV_REP, input_dev->evbit); 497 + 410 498 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 411 499 input_set_drvdata(input_dev, keypad); 412 - 413 - err = matrix_keypad_init_gpio(pdev, keypad); 414 - if (err) 415 - return err; 416 500 417 501 err = input_register_device(keypad->input_dev); 418 502 if (err) 419 503 return err; 420 504 421 - device_init_wakeup(&pdev->dev, pdata->wakeup); 505 + wakeup = device_property_read_bool(&pdev->dev, "wakeup-source") || 506 + /* legacy */ 507 + device_property_read_bool(&pdev->dev, "linux,wakeup"); 508 + device_init_wakeup(&pdev->dev, wakeup); 509 + 422 510 platform_set_drvdata(pdev, keypad); 423 511 424 512 return 0;
-268
drivers/input/keyboard/mcs_touchkey.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Touchkey driver for MELFAS MCS5000/5080 controller 4 - * 5 - * Copyright (C) 2010 Samsung Electronics Co.Ltd 6 - * Author: HeungJun Kim <riverful.kim@samsung.com> 7 - * Author: Joonyoung Shim <jy0922.shim@samsung.com> 8 - */ 9 - 10 - #include <linux/module.h> 11 - #include <linux/i2c.h> 12 - #include <linux/interrupt.h> 13 - #include <linux/input.h> 14 - #include <linux/irq.h> 15 - #include <linux/slab.h> 16 - #include <linux/platform_data/mcs.h> 17 - #include <linux/pm.h> 18 - 19 - /* MCS5000 Touchkey */ 20 - #define MCS5000_TOUCHKEY_STATUS 0x04 21 - #define MCS5000_TOUCHKEY_STATUS_PRESS 7 22 - #define MCS5000_TOUCHKEY_FW 0x0a 23 - #define MCS5000_TOUCHKEY_BASE_VAL 0x61 24 - 25 - /* MCS5080 Touchkey */ 26 - #define MCS5080_TOUCHKEY_STATUS 0x00 27 - #define MCS5080_TOUCHKEY_STATUS_PRESS 3 28 - #define MCS5080_TOUCHKEY_FW 0x01 29 - #define MCS5080_TOUCHKEY_BASE_VAL 0x1 30 - 31 - enum mcs_touchkey_type { 32 - MCS5000_TOUCHKEY, 33 - MCS5080_TOUCHKEY, 34 - }; 35 - 36 - struct mcs_touchkey_chip { 37 - unsigned int status_reg; 38 - unsigned int pressbit; 39 - unsigned int press_invert; 40 - unsigned int baseval; 41 - }; 42 - 43 - struct mcs_touchkey_data { 44 - void (*poweron)(bool); 45 - 46 - struct i2c_client *client; 47 - struct input_dev *input_dev; 48 - struct mcs_touchkey_chip chip; 49 - unsigned int key_code; 50 - unsigned int key_val; 51 - unsigned short keycodes[]; 52 - }; 53 - 54 - static irqreturn_t mcs_touchkey_interrupt(int irq, void *dev_id) 55 - { 56 - struct mcs_touchkey_data *data = dev_id; 57 - struct mcs_touchkey_chip *chip = &data->chip; 58 - struct i2c_client *client = data->client; 59 - struct input_dev *input = data->input_dev; 60 - unsigned int key_val; 61 - unsigned int pressed; 62 - int val; 63 - 64 - val = i2c_smbus_read_byte_data(client, chip->status_reg); 65 - if (val < 0) { 66 - dev_err(&client->dev, "i2c read error [%d]\n", val); 67 - goto out; 68 - } 69 - 70 - pressed = (val & (1 << chip->pressbit)) >> chip->pressbit; 71 - if (chip->press_invert) 72 - pressed ^= chip->press_invert; 73 - 74 - /* key_val is 0 when released, so we should use key_val of press. */ 75 - if (pressed) { 76 - key_val = val & (0xff >> (8 - chip->pressbit)); 77 - if (!key_val) 78 - goto out; 79 - key_val -= chip->baseval; 80 - data->key_code = data->keycodes[key_val]; 81 - data->key_val = key_val; 82 - } 83 - 84 - input_event(input, EV_MSC, MSC_SCAN, data->key_val); 85 - input_report_key(input, data->key_code, pressed); 86 - input_sync(input); 87 - 88 - dev_dbg(&client->dev, "key %d %d %s\n", data->key_val, data->key_code, 89 - pressed ? "pressed" : "released"); 90 - 91 - out: 92 - return IRQ_HANDLED; 93 - } 94 - 95 - static void mcs_touchkey_poweroff(void *data) 96 - { 97 - struct mcs_touchkey_data *touchkey = data; 98 - 99 - touchkey->poweron(false); 100 - } 101 - 102 - static int mcs_touchkey_probe(struct i2c_client *client) 103 - { 104 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 105 - const struct mcs_platform_data *pdata; 106 - struct mcs_touchkey_data *data; 107 - struct input_dev *input_dev; 108 - unsigned int fw_reg; 109 - int fw_ver; 110 - int error; 111 - int i; 112 - 113 - pdata = dev_get_platdata(&client->dev); 114 - if (!pdata) { 115 - dev_err(&client->dev, "no platform data defined\n"); 116 - return -EINVAL; 117 - } 118 - 119 - data = devm_kzalloc(&client->dev, 120 - struct_size(data, keycodes, pdata->key_maxval + 1), 121 - GFP_KERNEL); 122 - if (!data) 123 - return -ENOMEM; 124 - 125 - input_dev = devm_input_allocate_device(&client->dev); 126 - if (!input_dev) { 127 - dev_err(&client->dev, "Failed to allocate input device\n"); 128 - return -ENOMEM; 129 - } 130 - 131 - data->client = client; 132 - data->input_dev = input_dev; 133 - 134 - if (id->driver_data == MCS5000_TOUCHKEY) { 135 - data->chip.status_reg = MCS5000_TOUCHKEY_STATUS; 136 - data->chip.pressbit = MCS5000_TOUCHKEY_STATUS_PRESS; 137 - data->chip.baseval = MCS5000_TOUCHKEY_BASE_VAL; 138 - fw_reg = MCS5000_TOUCHKEY_FW; 139 - } else { 140 - data->chip.status_reg = MCS5080_TOUCHKEY_STATUS; 141 - data->chip.pressbit = MCS5080_TOUCHKEY_STATUS_PRESS; 142 - data->chip.press_invert = 1; 143 - data->chip.baseval = MCS5080_TOUCHKEY_BASE_VAL; 144 - fw_reg = MCS5080_TOUCHKEY_FW; 145 - } 146 - 147 - fw_ver = i2c_smbus_read_byte_data(client, fw_reg); 148 - if (fw_ver < 0) { 149 - dev_err(&client->dev, "i2c read error[%d]\n", fw_ver); 150 - return fw_ver; 151 - } 152 - dev_info(&client->dev, "Firmware version: %d\n", fw_ver); 153 - 154 - input_dev->name = "MELFAS MCS Touchkey"; 155 - input_dev->id.bustype = BUS_I2C; 156 - input_dev->evbit[0] = BIT_MASK(EV_KEY); 157 - if (!pdata->no_autorepeat) 158 - input_dev->evbit[0] |= BIT_MASK(EV_REP); 159 - input_dev->keycode = data->keycodes; 160 - input_dev->keycodesize = sizeof(data->keycodes[0]); 161 - input_dev->keycodemax = pdata->key_maxval + 1; 162 - 163 - for (i = 0; i < pdata->keymap_size; i++) { 164 - unsigned int val = MCS_KEY_VAL(pdata->keymap[i]); 165 - unsigned int code = MCS_KEY_CODE(pdata->keymap[i]); 166 - 167 - data->keycodes[val] = code; 168 - __set_bit(code, input_dev->keybit); 169 - } 170 - 171 - input_set_capability(input_dev, EV_MSC, MSC_SCAN); 172 - input_set_drvdata(input_dev, data); 173 - 174 - if (pdata->cfg_pin) 175 - pdata->cfg_pin(); 176 - 177 - if (pdata->poweron) { 178 - data->poweron = pdata->poweron; 179 - data->poweron(true); 180 - 181 - error = devm_add_action_or_reset(&client->dev, 182 - mcs_touchkey_poweroff, data); 183 - if (error) 184 - return error; 185 - } 186 - 187 - error = devm_request_threaded_irq(&client->dev, client->irq, 188 - NULL, mcs_touchkey_interrupt, 189 - IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 190 - client->dev.driver->name, data); 191 - if (error) { 192 - dev_err(&client->dev, "Failed to register interrupt\n"); 193 - return error; 194 - } 195 - 196 - error = input_register_device(input_dev); 197 - if (error) 198 - return error; 199 - 200 - i2c_set_clientdata(client, data); 201 - return 0; 202 - } 203 - 204 - static void mcs_touchkey_shutdown(struct i2c_client *client) 205 - { 206 - struct mcs_touchkey_data *data = i2c_get_clientdata(client); 207 - 208 - if (data->poweron) 209 - data->poweron(false); 210 - } 211 - 212 - static int mcs_touchkey_suspend(struct device *dev) 213 - { 214 - struct mcs_touchkey_data *data = dev_get_drvdata(dev); 215 - struct i2c_client *client = data->client; 216 - 217 - /* Disable the work */ 218 - disable_irq(client->irq); 219 - 220 - /* Finally turn off the power */ 221 - if (data->poweron) 222 - data->poweron(false); 223 - 224 - return 0; 225 - } 226 - 227 - static int mcs_touchkey_resume(struct device *dev) 228 - { 229 - struct mcs_touchkey_data *data = dev_get_drvdata(dev); 230 - struct i2c_client *client = data->client; 231 - 232 - /* Enable the device first */ 233 - if (data->poweron) 234 - data->poweron(true); 235 - 236 - /* Enable irq again */ 237 - enable_irq(client->irq); 238 - 239 - return 0; 240 - } 241 - 242 - static DEFINE_SIMPLE_DEV_PM_OPS(mcs_touchkey_pm_ops, 243 - mcs_touchkey_suspend, mcs_touchkey_resume); 244 - 245 - static const struct i2c_device_id mcs_touchkey_id[] = { 246 - { "mcs5000_touchkey", MCS5000_TOUCHKEY }, 247 - { "mcs5080_touchkey", MCS5080_TOUCHKEY }, 248 - { } 249 - }; 250 - MODULE_DEVICE_TABLE(i2c, mcs_touchkey_id); 251 - 252 - static struct i2c_driver mcs_touchkey_driver = { 253 - .driver = { 254 - .name = "mcs_touchkey", 255 - .pm = pm_sleep_ptr(&mcs_touchkey_pm_ops), 256 - }, 257 - .probe = mcs_touchkey_probe, 258 - .shutdown = mcs_touchkey_shutdown, 259 - .id_table = mcs_touchkey_id, 260 - }; 261 - 262 - module_i2c_driver(mcs_touchkey_driver); 263 - 264 - /* Module information */ 265 - MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); 266 - MODULE_AUTHOR("HeungJun Kim <riverful.kim@samsung.com>"); 267 - MODULE_DESCRIPTION("Touchkey driver for MELFAS MCS5000/5080 controller"); 268 - MODULE_LICENSE("GPL");
+2 -17
drivers/input/keyboard/mt6779-keypad.c
··· 92 92 return IRQ_HANDLED; 93 93 } 94 94 95 - static void mt6779_keypad_clk_disable(void *data) 96 - { 97 - clk_disable_unprepare(data); 98 - } 99 - 100 95 static void mt6779_keypad_calc_row_col_single(unsigned int key, 101 96 unsigned int *row, 102 97 unsigned int *col) ··· 208 213 regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_COL, 209 214 MTK_KPD_SEL_COLMASK(keypad->n_cols)); 210 215 211 - keypad->clk = devm_clk_get(&pdev->dev, "kpd"); 216 + keypad->clk = devm_clk_get_enabled(&pdev->dev, "kpd"); 212 217 if (IS_ERR(keypad->clk)) 213 218 return PTR_ERR(keypad->clk); 214 - 215 - error = clk_prepare_enable(keypad->clk); 216 - if (error) { 217 - dev_err(&pdev->dev, "cannot prepare/enable keypad clock\n"); 218 - return error; 219 - } 220 - 221 - error = devm_add_action_or_reset(&pdev->dev, mt6779_keypad_clk_disable, 222 - keypad->clk); 223 - if (error) 224 - return error; 225 219 226 220 irq = platform_get_irq(pdev, 0); 227 221 if (irq < 0) ··· 244 260 { .compatible = "mediatek,mt6873-keypad" }, 245 261 { /* sentinel */ } 246 262 }; 263 + MODULE_DEVICE_TABLE(of, mt6779_keypad_of_match); 247 264 248 265 static struct platform_driver mt6779_keypad_pdrv = { 249 266 .probe = mt6779_keypad_pdrv_probe,
-378
drivers/input/keyboard/nomadik-ske-keypad.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Copyright (C) ST-Ericsson SA 2010 4 - * 5 - * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson 6 - * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 7 - * 8 - * Keypad controller driver for the SKE (Scroll Key Encoder) module used in 9 - * the Nomadik 8815 and Ux500 platforms. 10 - */ 11 - 12 - #include <linux/platform_device.h> 13 - #include <linux/interrupt.h> 14 - #include <linux/spinlock.h> 15 - #include <linux/io.h> 16 - #include <linux/delay.h> 17 - #include <linux/input.h> 18 - #include <linux/slab.h> 19 - #include <linux/clk.h> 20 - #include <linux/module.h> 21 - 22 - #include <linux/platform_data/keypad-nomadik-ske.h> 23 - 24 - /* SKE_CR bits */ 25 - #define SKE_KPMLT (0x1 << 6) 26 - #define SKE_KPCN (0x7 << 3) 27 - #define SKE_KPASEN (0x1 << 2) 28 - #define SKE_KPASON (0x1 << 7) 29 - 30 - /* SKE_IMSC bits */ 31 - #define SKE_KPIMA (0x1 << 2) 32 - 33 - /* SKE_ICR bits */ 34 - #define SKE_KPICS (0x1 << 3) 35 - #define SKE_KPICA (0x1 << 2) 36 - 37 - /* SKE_RIS bits */ 38 - #define SKE_KPRISA (0x1 << 2) 39 - 40 - #define SKE_KEYPAD_ROW_SHIFT 3 41 - #define SKE_KPD_NUM_ROWS 8 42 - #define SKE_KPD_NUM_COLS 8 43 - 44 - /* keypad auto scan registers */ 45 - #define SKE_ASR0 0x20 46 - #define SKE_ASR1 0x24 47 - #define SKE_ASR2 0x28 48 - #define SKE_ASR3 0x2C 49 - 50 - #define SKE_NUM_ASRX_REGISTERS (4) 51 - #define KEY_PRESSED_DELAY 10 52 - 53 - /** 54 - * struct ske_keypad - data structure used by keypad driver 55 - * @irq: irq no 56 - * @reg_base: ske registers base address 57 - * @input: pointer to input device object 58 - * @board: keypad platform device 59 - * @keymap: matrix scan code table for keycodes 60 - * @clk: clock structure pointer 61 - * @pclk: clock structure pointer 62 - * @ske_keypad_lock: spinlock protecting the keypad read/writes 63 - */ 64 - struct ske_keypad { 65 - int irq; 66 - void __iomem *reg_base; 67 - struct input_dev *input; 68 - const struct ske_keypad_platform_data *board; 69 - unsigned short keymap[SKE_KPD_NUM_ROWS * SKE_KPD_NUM_COLS]; 70 - struct clk *clk; 71 - struct clk *pclk; 72 - spinlock_t ske_keypad_lock; 73 - }; 74 - 75 - static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr, 76 - u8 mask, u8 data) 77 - { 78 - u32 ret; 79 - 80 - spin_lock(&keypad->ske_keypad_lock); 81 - 82 - ret = readl(keypad->reg_base + addr); 83 - ret &= ~mask; 84 - ret |= data; 85 - writel(ret, keypad->reg_base + addr); 86 - 87 - spin_unlock(&keypad->ske_keypad_lock); 88 - } 89 - 90 - /* 91 - * ske_keypad_chip_init: init keypad controller configuration 92 - * 93 - * Enable Multi key press detection, auto scan mode 94 - */ 95 - static int __init ske_keypad_chip_init(struct ske_keypad *keypad) 96 - { 97 - u32 value; 98 - int timeout = keypad->board->debounce_ms; 99 - 100 - /* check SKE_RIS to be 0 */ 101 - while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--) 102 - cpu_relax(); 103 - 104 - if (timeout == -1) 105 - return -EINVAL; 106 - 107 - /* 108 - * set debounce value 109 - * keypad dbounce is configured in DBCR[15:8] 110 - * dbounce value in steps of 32/32.768 ms 111 - */ 112 - spin_lock(&keypad->ske_keypad_lock); 113 - value = readl(keypad->reg_base + SKE_DBCR); 114 - value = value & 0xff; 115 - value |= ((keypad->board->debounce_ms * 32000)/32768) << 8; 116 - writel(value, keypad->reg_base + SKE_DBCR); 117 - spin_unlock(&keypad->ske_keypad_lock); 118 - 119 - /* enable multi key detection */ 120 - ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT); 121 - 122 - /* 123 - * set up the number of columns 124 - * KPCN[5:3] defines no. of keypad columns to be auto scanned 125 - */ 126 - value = (keypad->board->kcol - 1) << 3; 127 - ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value); 128 - 129 - /* clear keypad interrupt for auto(and pending SW) scans */ 130 - ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS); 131 - 132 - /* un-mask keypad interrupts */ 133 - ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 134 - 135 - /* enable automatic scan */ 136 - ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN); 137 - 138 - return 0; 139 - } 140 - 141 - static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col) 142 - { 143 - int row = 0, code, pos; 144 - struct input_dev *input = keypad->input; 145 - u32 ske_ris; 146 - int key_pressed; 147 - int num_of_rows; 148 - 149 - /* find out the row */ 150 - num_of_rows = hweight8(status); 151 - do { 152 - pos = __ffs(status); 153 - row = pos; 154 - status &= ~(1 << pos); 155 - 156 - code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT); 157 - ske_ris = readl(keypad->reg_base + SKE_RIS); 158 - key_pressed = ske_ris & SKE_KPRISA; 159 - 160 - input_event(input, EV_MSC, MSC_SCAN, code); 161 - input_report_key(input, keypad->keymap[code], key_pressed); 162 - input_sync(input); 163 - num_of_rows--; 164 - } while (num_of_rows); 165 - } 166 - 167 - static void ske_keypad_read_data(struct ske_keypad *keypad) 168 - { 169 - u8 status; 170 - int col = 0; 171 - int ske_asr, i; 172 - 173 - /* 174 - * Read the auto scan registers 175 - * 176 - * Each SKE_ASRx (x=0 to x=3) contains two row values. 177 - * lower byte contains row value for column 2*x, 178 - * upper byte contains row value for column 2*x + 1 179 - */ 180 - for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) { 181 - ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i)); 182 - if (!ske_asr) 183 - continue; 184 - 185 - /* now that ASRx is zero, find out the coloumn x and row y */ 186 - status = ske_asr & 0xff; 187 - if (status) { 188 - col = i * 2; 189 - ske_keypad_report(keypad, status, col); 190 - } 191 - status = (ske_asr & 0xff00) >> 8; 192 - if (status) { 193 - col = (i * 2) + 1; 194 - ske_keypad_report(keypad, status, col); 195 - } 196 - } 197 - } 198 - 199 - static irqreturn_t ske_keypad_irq(int irq, void *dev_id) 200 - { 201 - struct ske_keypad *keypad = dev_id; 202 - int timeout = keypad->board->debounce_ms; 203 - 204 - /* disable auto scan interrupt; mask the interrupt generated */ 205 - ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 206 - ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA); 207 - 208 - while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout) 209 - cpu_relax(); 210 - 211 - /* SKEx registers are stable and can be read */ 212 - ske_keypad_read_data(keypad); 213 - 214 - /* wait until raw interrupt is clear */ 215 - while ((readl(keypad->reg_base + SKE_RIS)) && --timeout) 216 - msleep(KEY_PRESSED_DELAY); 217 - 218 - /* enable auto scan interrupts */ 219 - ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 220 - 221 - return IRQ_HANDLED; 222 - } 223 - 224 - static void ske_keypad_board_exit(void *data) 225 - { 226 - struct ske_keypad *keypad = data; 227 - 228 - keypad->board->exit(); 229 - } 230 - 231 - static int __init ske_keypad_probe(struct platform_device *pdev) 232 - { 233 - const struct ske_keypad_platform_data *plat = 234 - dev_get_platdata(&pdev->dev); 235 - struct device *dev = &pdev->dev; 236 - struct ske_keypad *keypad; 237 - struct input_dev *input; 238 - int irq; 239 - int error; 240 - 241 - if (!plat) { 242 - dev_err(&pdev->dev, "invalid keypad platform data\n"); 243 - return -EINVAL; 244 - } 245 - 246 - irq = platform_get_irq(pdev, 0); 247 - if (irq < 0) 248 - return irq; 249 - 250 - keypad = devm_kzalloc(dev, sizeof(struct ske_keypad), 251 - GFP_KERNEL); 252 - input = devm_input_allocate_device(dev); 253 - if (!keypad || !input) { 254 - dev_err(&pdev->dev, "failed to allocate keypad memory\n"); 255 - return -ENOMEM; 256 - } 257 - 258 - keypad->irq = irq; 259 - keypad->board = plat; 260 - keypad->input = input; 261 - spin_lock_init(&keypad->ske_keypad_lock); 262 - 263 - keypad->reg_base = devm_platform_ioremap_resource(pdev, 0); 264 - if (IS_ERR(keypad->reg_base)) 265 - return PTR_ERR(keypad->reg_base); 266 - 267 - keypad->pclk = devm_clk_get_enabled(dev, "apb_pclk"); 268 - if (IS_ERR(keypad->pclk)) { 269 - dev_err(&pdev->dev, "failed to get pclk\n"); 270 - return PTR_ERR(keypad->pclk); 271 - } 272 - 273 - keypad->clk = devm_clk_get_enabled(dev, NULL); 274 - if (IS_ERR(keypad->clk)) { 275 - dev_err(&pdev->dev, "failed to get clk\n"); 276 - return PTR_ERR(keypad->clk); 277 - } 278 - 279 - input->id.bustype = BUS_HOST; 280 - input->name = "ux500-ske-keypad"; 281 - input->dev.parent = &pdev->dev; 282 - 283 - error = matrix_keypad_build_keymap(plat->keymap_data, NULL, 284 - SKE_KPD_NUM_ROWS, SKE_KPD_NUM_COLS, 285 - keypad->keymap, input); 286 - if (error) { 287 - dev_err(&pdev->dev, "Failed to build keymap\n"); 288 - return error; 289 - } 290 - 291 - input_set_capability(input, EV_MSC, MSC_SCAN); 292 - if (!plat->no_autorepeat) 293 - __set_bit(EV_REP, input->evbit); 294 - 295 - /* go through board initialization helpers */ 296 - if (keypad->board->init) 297 - keypad->board->init(); 298 - 299 - if (keypad->board->exit) { 300 - error = devm_add_action_or_reset(dev, ske_keypad_board_exit, 301 - keypad); 302 - if (error) 303 - return error; 304 - } 305 - 306 - error = ske_keypad_chip_init(keypad); 307 - if (error) { 308 - dev_err(&pdev->dev, "unable to init keypad hardware\n"); 309 - return error; 310 - } 311 - 312 - error = devm_request_threaded_irq(dev, keypad->irq, 313 - NULL, ske_keypad_irq, 314 - IRQF_ONESHOT, "ske-keypad", keypad); 315 - if (error) { 316 - dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq); 317 - return error; 318 - } 319 - 320 - error = input_register_device(input); 321 - if (error) { 322 - dev_err(&pdev->dev, 323 - "unable to register input device: %d\n", error); 324 - return error; 325 - } 326 - 327 - if (plat->wakeup_enable) 328 - device_init_wakeup(&pdev->dev, true); 329 - 330 - platform_set_drvdata(pdev, keypad); 331 - 332 - return 0; 333 - } 334 - 335 - static int ske_keypad_suspend(struct device *dev) 336 - { 337 - struct platform_device *pdev = to_platform_device(dev); 338 - struct ske_keypad *keypad = platform_get_drvdata(pdev); 339 - int irq = platform_get_irq(pdev, 0); 340 - 341 - if (device_may_wakeup(dev)) 342 - enable_irq_wake(irq); 343 - else 344 - ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0); 345 - 346 - return 0; 347 - } 348 - 349 - static int ske_keypad_resume(struct device *dev) 350 - { 351 - struct platform_device *pdev = to_platform_device(dev); 352 - struct ske_keypad *keypad = platform_get_drvdata(pdev); 353 - int irq = platform_get_irq(pdev, 0); 354 - 355 - if (device_may_wakeup(dev)) 356 - disable_irq_wake(irq); 357 - else 358 - ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA); 359 - 360 - return 0; 361 - } 362 - 363 - static DEFINE_SIMPLE_DEV_PM_OPS(ske_keypad_dev_pm_ops, 364 - ske_keypad_suspend, ske_keypad_resume); 365 - 366 - static struct platform_driver ske_keypad_driver = { 367 - .driver = { 368 - .name = "nmk-ske-keypad", 369 - .pm = pm_sleep_ptr(&ske_keypad_dev_pm_ops), 370 - }, 371 - }; 372 - 373 - module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe); 374 - 375 - MODULE_LICENSE("GPL v2"); 376 - MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>"); 377 - MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver"); 378 - MODULE_ALIAS("platform:nomadik-ske-keypad");
+5 -10
drivers/input/keyboard/qt1050.c
··· 346 346 static int qt1050_parse_fw(struct qt1050_priv *ts) 347 347 { 348 348 struct device *dev = &ts->client->dev; 349 - struct fwnode_handle *child; 350 349 int nbuttons; 351 350 352 351 nbuttons = device_get_child_node_count(dev); 353 352 if (nbuttons == 0 || nbuttons > QT1050_MAX_KEYS) 354 353 return -ENODEV; 355 354 356 - device_for_each_child_node(dev, child) { 355 + device_for_each_child_node_scoped(dev, child) { 357 356 struct qt1050_key button; 358 357 359 358 /* Required properties */ 360 359 if (fwnode_property_read_u32(child, "linux,code", 361 360 &button.keycode)) { 362 361 dev_err(dev, "Button without keycode\n"); 363 - goto err; 362 + return -EINVAL; 364 363 } 365 364 if (button.keycode >= KEY_MAX) { 366 365 dev_err(dev, "Invalid keycode 0x%x\n", 367 366 button.keycode); 368 - goto err; 367 + return -EINVAL; 369 368 } 370 369 371 370 if (fwnode_property_read_u32(child, "reg", 372 371 &button.num)) { 373 372 dev_err(dev, "Button without pad number\n"); 374 - goto err; 373 + return -EINVAL; 375 374 } 376 375 if (button.num < 0 || button.num > QT1050_MAX_KEYS - 1) 377 - goto err; 376 + return -EINVAL; 378 377 379 378 ts->reg_keys |= BIT(button.num); 380 379 ··· 423 424 } 424 425 425 426 return 0; 426 - 427 - err: 428 - fwnode_handle_put(child); 429 - return -EINVAL; 430 427 } 431 428 432 429 static int qt1050_probe(struct i2c_client *client)
+1 -23
drivers/input/keyboard/snvs_pwrkey.c
··· 100 100 return IRQ_HANDLED; 101 101 } 102 102 103 - static void imx_snvs_pwrkey_disable_clk(void *data) 104 - { 105 - clk_disable_unprepare(data); 106 - } 107 - 108 103 static void imx_snvs_pwrkey_act(void *pdata) 109 104 { 110 105 struct pwrkey_drv_data *pd = pdata; ··· 136 141 dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n"); 137 142 } 138 143 139 - clk = devm_clk_get_optional(&pdev->dev, NULL); 144 + clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); 140 145 if (IS_ERR(clk)) { 141 146 dev_err(&pdev->dev, "Failed to get snvs clock (%pe)\n", clk); 142 147 return PTR_ERR(clk); 143 - } 144 - 145 - error = clk_prepare_enable(clk); 146 - if (error) { 147 - dev_err(&pdev->dev, "Failed to enable snvs clock (%pe)\n", 148 - ERR_PTR(error)); 149 - return error; 150 - } 151 - 152 - error = devm_add_action_or_reset(&pdev->dev, 153 - imx_snvs_pwrkey_disable_clk, clk); 154 - if (error) { 155 - dev_err(&pdev->dev, 156 - "Failed to register clock cleanup handler (%pe)\n", 157 - ERR_PTR(error)); 158 - return error; 159 148 } 160 149 161 150 pdata->wakeup = of_property_read_bool(np, "wakeup-source"); ··· 183 204 error = devm_request_irq(&pdev->dev, pdata->irq, 184 205 imx_snvs_pwrkey_interrupt, 185 206 0, pdev->name, pdev); 186 - 187 207 if (error) { 188 208 dev_err(&pdev->dev, "interrupt not available.\n"); 189 209 return error;
+1 -15
drivers/input/keyboard/spear-keyboard.c
··· 222 222 if (IS_ERR(kbd->io_base)) 223 223 return PTR_ERR(kbd->io_base); 224 224 225 - kbd->clk = devm_clk_get(&pdev->dev, NULL); 225 + kbd->clk = devm_clk_get_prepared(&pdev->dev, NULL); 226 226 if (IS_ERR(kbd->clk)) 227 227 return PTR_ERR(kbd->clk); 228 228 ··· 255 255 return error; 256 256 } 257 257 258 - error = clk_prepare(kbd->clk); 259 - if (error) 260 - return error; 261 - 262 258 error = input_register_device(input_dev); 263 259 if (error) { 264 260 dev_err(&pdev->dev, "Unable to register keyboard device\n"); 265 - clk_unprepare(kbd->clk); 266 261 return error; 267 262 } 268 263 ··· 265 270 platform_set_drvdata(pdev, kbd); 266 271 267 272 return 0; 268 - } 269 - 270 - static void spear_kbd_remove(struct platform_device *pdev) 271 - { 272 - struct spear_kbd *kbd = platform_get_drvdata(pdev); 273 - 274 - input_unregister_device(kbd->input); 275 - clk_unprepare(kbd->clk); 276 273 } 277 274 278 275 static int spear_kbd_suspend(struct device *dev) ··· 360 373 361 374 static struct platform_driver spear_kbd_driver = { 362 375 .probe = spear_kbd_probe, 363 - .remove_new = spear_kbd_remove, 364 376 .driver = { 365 377 .name = "keyboard", 366 378 .pm = pm_sleep_ptr(&spear_kbd_pm_ops),
+1 -2
drivers/input/keyboard/tc3589x-keypad.c
··· 325 325 struct tc3589x_keypad_platform_data *plat; 326 326 u32 cols, rows; 327 327 u32 debounce_ms; 328 - int proplen; 329 328 330 329 if (!np) 331 330 return ERR_PTR(-ENODEV); ··· 345 346 return ERR_PTR(-EINVAL); 346 347 } 347 348 348 - if (!of_get_property(np, "linux,keymap", &proplen)) { 349 + if (!of_property_present(np, "linux,keymap")) { 349 350 dev_err(dev, "property linux,keymap not found\n"); 350 351 return ERR_PTR(-ENOENT); 351 352 }
+46 -71
drivers/input/keyboard/tegra-kbc.c
··· 241 241 static void tegra_kbc_keypress_timer(struct timer_list *t) 242 242 { 243 243 struct tegra_kbc *kbc = from_timer(kbc, t, timer); 244 - unsigned long flags; 245 244 u32 val; 246 245 unsigned int i; 247 246 248 - spin_lock_irqsave(&kbc->lock, flags); 247 + guard(spinlock_irqsave)(&kbc->lock); 249 248 250 249 val = (readl(kbc->mmio + KBC_INT_0) >> 4) & 0xf; 251 250 if (val) { ··· 269 270 /* All keys are released so enable the keypress interrupt */ 270 271 tegra_kbc_set_fifo_interrupt(kbc, true); 271 272 } 272 - 273 - spin_unlock_irqrestore(&kbc->lock, flags); 274 273 } 275 274 276 275 static irqreturn_t tegra_kbc_isr(int irq, void *args) 277 276 { 278 277 struct tegra_kbc *kbc = args; 279 - unsigned long flags; 280 278 u32 val; 281 279 282 - spin_lock_irqsave(&kbc->lock, flags); 280 + guard(spinlock_irqsave)(&kbc->lock); 283 281 284 282 /* 285 283 * Quickly bail out & reenable interrupts if the fifo threshold ··· 296 300 /* We can be here only through system resume path */ 297 301 kbc->keypress_caused_wake = true; 298 302 } 299 - 300 - spin_unlock_irqrestore(&kbc->lock, flags); 301 303 302 304 return IRQ_HANDLED; 303 305 } ··· 407 413 408 414 static void tegra_kbc_stop(struct tegra_kbc *kbc) 409 415 { 410 - unsigned long flags; 411 416 u32 val; 412 417 413 - spin_lock_irqsave(&kbc->lock, flags); 414 - val = readl(kbc->mmio + KBC_CONTROL_0); 415 - val &= ~1; 416 - writel(val, kbc->mmio + KBC_CONTROL_0); 417 - spin_unlock_irqrestore(&kbc->lock, flags); 418 + scoped_guard(spinlock_irqsave, &kbc->lock) { 419 + val = readl(kbc->mmio + KBC_CONTROL_0); 420 + val &= ~1; 421 + writel(val, kbc->mmio + KBC_CONTROL_0); 422 + } 418 423 419 424 disable_irq(kbc->irq); 420 425 del_timer_sync(&kbc->timer); ··· 484 491 struct device_node *np = kbc->dev->of_node; 485 492 u32 prop; 486 493 int i; 487 - u32 num_rows = 0; 488 - u32 num_cols = 0; 494 + int num_rows; 495 + int num_cols; 489 496 u32 cols_cfg[KBC_MAX_GPIO]; 490 497 u32 rows_cfg[KBC_MAX_GPIO]; 491 - int proplen; 492 - int ret; 493 498 494 499 if (!of_property_read_u32(np, "nvidia,debounce-delay-ms", &prop)) 495 500 kbc->debounce_cnt = prop; ··· 501 510 of_property_read_bool(np, "nvidia,wakeup-source")) /* legacy */ 502 511 kbc->wakeup = true; 503 512 504 - if (!of_get_property(np, "nvidia,kbc-row-pins", &proplen)) { 505 - dev_err(kbc->dev, "property nvidia,kbc-row-pins not found\n"); 506 - return -ENOENT; 507 - } 508 - num_rows = proplen / sizeof(u32); 509 - 510 - if (!of_get_property(np, "nvidia,kbc-col-pins", &proplen)) { 511 - dev_err(kbc->dev, "property nvidia,kbc-col-pins not found\n"); 512 - return -ENOENT; 513 - } 514 - num_cols = proplen / sizeof(u32); 515 - 516 - if (num_rows > kbc->hw_support->max_rows) { 517 - dev_err(kbc->dev, 518 - "Number of rows is more than supported by hardware\n"); 519 - return -EINVAL; 520 - } 521 - 522 - if (num_cols > kbc->hw_support->max_columns) { 523 - dev_err(kbc->dev, 524 - "Number of cols is more than supported by hardware\n"); 525 - return -EINVAL; 526 - } 527 - 528 - if (!of_get_property(np, "linux,keymap", &proplen)) { 513 + if (!of_property_present(np, "linux,keymap")) { 529 514 dev_err(kbc->dev, "property linux,keymap not found\n"); 530 515 return -ENOENT; 531 - } 532 - 533 - if (!num_rows || !num_cols || ((num_rows + num_cols) > KBC_MAX_GPIO)) { 534 - dev_err(kbc->dev, 535 - "keypad rows/columns not properly specified\n"); 536 - return -EINVAL; 537 516 } 538 517 539 518 /* Set all pins as non-configured */ 540 519 for (i = 0; i < kbc->num_rows_and_columns; i++) 541 520 kbc->pin_cfg[i].type = PIN_CFG_IGNORE; 542 521 543 - ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins", 544 - rows_cfg, num_rows); 545 - if (ret < 0) { 522 + num_rows = of_property_read_variable_u32_array(np, "nvidia,kbc-row-pins", 523 + rows_cfg, 1, KBC_MAX_GPIO); 524 + if (num_rows < 0) { 546 525 dev_err(kbc->dev, "Rows configurations are not proper\n"); 547 - return -EINVAL; 548 - } 549 - 550 - ret = of_property_read_u32_array(np, "nvidia,kbc-col-pins", 551 - cols_cfg, num_cols); 552 - if (ret < 0) { 553 - dev_err(kbc->dev, "Cols configurations are not proper\n"); 526 + return num_rows; 527 + } else if (num_rows > kbc->hw_support->max_rows) { 528 + dev_err(kbc->dev, 529 + "Number of rows is more than supported by hardware\n"); 554 530 return -EINVAL; 555 531 } 556 532 ··· 526 568 kbc->pin_cfg[rows_cfg[i]].num = i; 527 569 } 528 570 571 + num_cols = of_property_read_variable_u32_array(np, "nvidia,kbc-col-pins", 572 + cols_cfg, 1, KBC_MAX_GPIO); 573 + if (num_cols < 0) { 574 + dev_err(kbc->dev, "Cols configurations are not proper\n"); 575 + return num_cols; 576 + } else if (num_cols > kbc->hw_support->max_columns) { 577 + dev_err(kbc->dev, 578 + "Number of cols is more than supported by hardware\n"); 579 + return -EINVAL; 580 + } 581 + 529 582 for (i = 0; i < num_cols; i++) { 530 583 kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL; 531 584 kbc->pin_cfg[cols_cfg[i]].num = i; 585 + } 586 + 587 + if (!num_rows || !num_cols || ((num_rows + num_cols) > KBC_MAX_GPIO)) { 588 + dev_err(kbc->dev, 589 + "keypad rows/columns not properly specified\n"); 590 + return -EINVAL; 532 591 } 533 592 534 593 return 0; ··· 699 724 struct platform_device *pdev = to_platform_device(dev); 700 725 struct tegra_kbc *kbc = platform_get_drvdata(pdev); 701 726 702 - mutex_lock(&kbc->idev->mutex); 727 + guard(mutex)(&kbc->idev->mutex); 728 + 703 729 if (device_may_wakeup(&pdev->dev)) { 704 730 disable_irq(kbc->irq); 705 731 del_timer_sync(&kbc->timer); ··· 723 747 tegra_kbc_set_keypress_interrupt(kbc, true); 724 748 enable_irq(kbc->irq); 725 749 enable_irq_wake(kbc->irq); 726 - } else { 727 - if (input_device_enabled(kbc->idev)) 728 - tegra_kbc_stop(kbc); 750 + } else if (input_device_enabled(kbc->idev)) { 751 + tegra_kbc_stop(kbc); 729 752 } 730 - mutex_unlock(&kbc->idev->mutex); 731 753 732 754 return 0; 733 755 } ··· 734 760 { 735 761 struct platform_device *pdev = to_platform_device(dev); 736 762 struct tegra_kbc *kbc = platform_get_drvdata(pdev); 737 - int err = 0; 763 + int err; 738 764 739 - mutex_lock(&kbc->idev->mutex); 765 + guard(mutex)(&kbc->idev->mutex); 766 + 740 767 if (device_may_wakeup(&pdev->dev)) { 741 768 disable_irq_wake(kbc->irq); 742 769 tegra_kbc_setup_wakekeys(kbc, false); ··· 762 787 input_report_key(kbc->idev, kbc->wakeup_key, 0); 763 788 input_sync(kbc->idev); 764 789 } 765 - } else { 766 - if (input_device_enabled(kbc->idev)) 767 - err = tegra_kbc_start(kbc); 790 + } else if (input_device_enabled(kbc->idev)) { 791 + err = tegra_kbc_start(kbc); 792 + if (err) 793 + return err; 768 794 } 769 - mutex_unlock(&kbc->idev->mutex); 770 795 771 - return err; 796 + return 0; 772 797 } 773 798 774 799 static DEFINE_SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops,
+9 -16
drivers/input/matrix-keymap.c
··· 73 73 struct device *dev = input_dev->dev.parent; 74 74 unsigned int row_shift = get_count_order(cols); 75 75 unsigned int max_keys = rows << row_shift; 76 - u32 *keys; 77 76 int i; 78 77 int size; 79 - int retval; 78 + int error; 80 79 81 80 if (!propname) 82 81 propname = "linux,keymap"; ··· 93 94 return -EINVAL; 94 95 } 95 96 96 - keys = kmalloc_array(size, sizeof(u32), GFP_KERNEL); 97 + u32 *keys __free(kfree) = kmalloc_array(size, sizeof(*keys), GFP_KERNEL); 97 98 if (!keys) 98 99 return -ENOMEM; 99 100 100 - retval = device_property_read_u32_array(dev, propname, keys, size); 101 - if (retval) { 101 + error = device_property_read_u32_array(dev, propname, keys, size); 102 + if (error) { 102 103 dev_err(dev, "failed to read %s property: %d\n", 103 - propname, retval); 104 - goto out; 104 + propname, error); 105 + return error; 105 106 } 106 107 107 108 for (i = 0; i < size; i++) { 108 109 if (!matrix_keypad_map_key(input_dev, rows, cols, 109 - row_shift, keys[i])) { 110 - retval = -EINVAL; 111 - goto out; 112 - } 110 + row_shift, keys[i])) 111 + return -EINVAL; 113 112 } 114 113 115 - retval = 0; 116 - 117 - out: 118 - kfree(keys); 119 - return retval; 114 + return 0; 120 115 } 121 116 122 117 /**
+1 -1
drivers/input/misc/ims-pcu.c
··· 1067 1067 if (data_len > attr->field_length) 1068 1068 return -EINVAL; 1069 1069 1070 - scoped_cond_guard(mutex, return -EINTR, &pcu->cmd_mutex) { 1070 + scoped_cond_guard(mutex_intr, return -EINTR, &pcu->cmd_mutex) { 1071 1071 memset(field, 0, attr->field_length); 1072 1072 memcpy(field, buf, data_len); 1073 1073
+2 -5
drivers/input/misc/iqs269a.c
··· 811 811 { 812 812 struct iqs269_sys_reg *sys_reg = &iqs269->sys_reg; 813 813 struct i2c_client *client = iqs269->client; 814 - struct fwnode_handle *ch_node; 815 814 u16 general, misc_a, misc_b; 816 815 unsigned int val; 817 816 int error; ··· 1048 1049 1049 1050 sys_reg->event_mask = ~((u8)IQS269_EVENT_MASK_SYS); 1050 1051 1051 - device_for_each_child_node(&client->dev, ch_node) { 1052 + device_for_each_child_node_scoped(&client->dev, ch_node) { 1052 1053 error = iqs269_parse_chan(iqs269, ch_node); 1053 - if (error) { 1054 - fwnode_handle_put(ch_node); 1054 + if (error) 1055 1055 return error; 1056 - } 1057 1056 } 1058 1057 1059 1058 /*
+38
drivers/input/misc/nxp-bbnsm-pwrkey.c
··· 38 38 int irq; 39 39 int keycode; 40 40 int keystate; /* 1:pressed */ 41 + bool suspended; 41 42 struct timer_list check_timer; 42 43 struct input_dev *input; 43 44 }; ··· 71 70 { 72 71 struct platform_device *pdev = dev_id; 73 72 struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev); 73 + struct input_dev *input = bbnsm->input; 74 74 u32 event; 75 75 76 76 regmap_read(bbnsm->regmap, BBNSM_EVENTS, &event); ··· 79 77 return IRQ_NONE; 80 78 81 79 pm_wakeup_event(bbnsm->input->dev.parent, 0); 80 + 81 + /* 82 + * Directly report key event after resume to make sure key press 83 + * event is never missed. 84 + */ 85 + if (bbnsm->suspended) { 86 + bbnsm->keystate = 1; 87 + input_event(input, EV_KEY, bbnsm->keycode, 1); 88 + input_sync(input); 89 + /* Fire at most once per suspend/resume cycle */ 90 + bbnsm->suspended = false; 91 + } 82 92 83 93 mod_timer(&bbnsm->check_timer, 84 94 jiffies + msecs_to_jiffies(DEBOUNCE_TIME)); ··· 187 173 return 0; 188 174 } 189 175 176 + static int __maybe_unused bbnsm_pwrkey_suspend(struct device *dev) 177 + { 178 + struct platform_device *pdev = to_platform_device(dev); 179 + struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev); 180 + 181 + bbnsm->suspended = true; 182 + 183 + return 0; 184 + } 185 + 186 + static int __maybe_unused bbnsm_pwrkey_resume(struct device *dev) 187 + { 188 + struct platform_device *pdev = to_platform_device(dev); 189 + struct bbnsm_pwrkey *bbnsm = platform_get_drvdata(pdev); 190 + 191 + bbnsm->suspended = false; 192 + 193 + return 0; 194 + } 195 + 196 + static SIMPLE_DEV_PM_OPS(bbnsm_pwrkey_pm_ops, bbnsm_pwrkey_suspend, 197 + bbnsm_pwrkey_resume); 198 + 190 199 static const struct of_device_id bbnsm_pwrkey_ids[] = { 191 200 { .compatible = "nxp,imx93-bbnsm-pwrkey" }, 192 201 { /* sentinel */ } ··· 219 182 static struct platform_driver bbnsm_pwrkey_driver = { 220 183 .driver = { 221 184 .name = "bbnsm_pwrkey", 185 + .pm = &bbnsm_pwrkey_pm_ops, 222 186 .of_match_table = bbnsm_pwrkey_ids, 223 187 }, 224 188 .probe = bbnsm_pwrkey_probe,
+2 -2
drivers/input/misc/wistron_btns.c
··· 990 990 for (key = keymap; key->type != KE_END; key++) 991 991 length++; 992 992 993 - new_keymap = kmemdup(keymap, length * sizeof(struct key_entry), 994 - GFP_KERNEL); 993 + new_keymap = kmemdup_array(keymap, length, sizeof(struct key_entry), 994 + GFP_KERNEL); 995 995 if (!new_keymap) 996 996 return -ENOMEM; 997 997
+12
drivers/input/mouse/Kconfig
··· 69 69 70 70 If unsure, say Y. 71 71 72 + config MOUSE_PS2_PIXART 73 + bool "PixArt PS/2 touchpad protocol extension" if EXPERT 74 + default y 75 + depends on MOUSE_PS2 76 + help 77 + This driver supports the PixArt PS/2 touchpad found in some 78 + laptops. 79 + Say Y here if you have a PixArt PS/2 TouchPad connected to 80 + your system. 81 + 82 + If unsure, say Y. 83 + 72 84 config MOUSE_PS2_SYNAPTICS 73 85 bool "Synaptics PS/2 mouse protocol extension" if EXPERT 74 86 default y
+1
drivers/input/mouse/Makefile
··· 32 32 psmouse-$(CONFIG_MOUSE_PS2_OLPC) += hgpk.o 33 33 psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o 34 34 psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o 35 + psmouse-$(CONFIG_MOUSE_PS2_PIXART) += pixart_ps2.o 35 36 psmouse-$(CONFIG_MOUSE_PS2_SENTELIC) += sentelic.o 36 37 psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o 37 38 psmouse-$(CONFIG_MOUSE_PS2_TOUCHKIT) += touchkit_ps2.o
+27 -21
drivers/input/mouse/alps.c
··· 1396 1396 1397 1397 static DEFINE_MUTEX(alps_mutex); 1398 1398 1399 - static void alps_register_bare_ps2_mouse(struct work_struct *work) 1399 + static int alps_do_register_bare_ps2_mouse(struct alps_data *priv) 1400 1400 { 1401 - struct alps_data *priv = 1402 - container_of(work, struct alps_data, dev3_register_work.work); 1403 1401 struct psmouse *psmouse = priv->psmouse; 1404 1402 struct input_dev *dev3; 1405 - int error = 0; 1406 - 1407 - mutex_lock(&alps_mutex); 1408 - 1409 - if (priv->dev3) 1410 - goto out; 1403 + int error; 1411 1404 1412 1405 dev3 = input_allocate_device(); 1413 1406 if (!dev3) { 1414 1407 psmouse_err(psmouse, "failed to allocate secondary device\n"); 1415 - error = -ENOMEM; 1416 - goto out; 1408 + return -ENOMEM; 1417 1409 } 1418 1410 1419 1411 snprintf(priv->phys3, sizeof(priv->phys3), "%s/%s", ··· 1438 1446 psmouse_err(psmouse, 1439 1447 "failed to register secondary device: %d\n", 1440 1448 error); 1441 - input_free_device(dev3); 1442 - goto out; 1449 + goto err_free_input; 1443 1450 } 1444 1451 1445 1452 priv->dev3 = dev3; 1453 + return 0; 1446 1454 1447 - out: 1448 - /* 1449 - * Save the error code so that we can detect that we 1450 - * already tried to create the device. 1451 - */ 1452 - if (error) 1453 - priv->dev3 = ERR_PTR(error); 1455 + err_free_input: 1456 + input_free_device(dev3); 1457 + return error; 1458 + } 1454 1459 1455 - mutex_unlock(&alps_mutex); 1460 + static void alps_register_bare_ps2_mouse(struct work_struct *work) 1461 + { 1462 + struct alps_data *priv = container_of(work, struct alps_data, 1463 + dev3_register_work.work); 1464 + int error; 1465 + 1466 + guard(mutex)(&alps_mutex); 1467 + 1468 + if (!priv->dev3) { 1469 + error = alps_do_register_bare_ps2_mouse(priv); 1470 + if (error) { 1471 + /* 1472 + * Save the error code so that we can detect that we 1473 + * already tried to create the device. 1474 + */ 1475 + priv->dev3 = ERR_PTR(error); 1476 + } 1477 + } 1456 1478 } 1457 1479 1458 1480 static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
+13 -22
drivers/input/mouse/bcm5974.c
··· 834 834 if (error) 835 835 return error; 836 836 837 - mutex_lock(&dev->pm_mutex); 838 - 839 - error = bcm5974_start_traffic(dev); 840 - if (!error) 841 - dev->opened = 1; 842 - 843 - mutex_unlock(&dev->pm_mutex); 837 + scoped_guard(mutex, &dev->pm_mutex) { 838 + error = bcm5974_start_traffic(dev); 839 + if (!error) 840 + dev->opened = 1; 841 + } 844 842 845 843 if (error) 846 844 usb_autopm_put_interface(dev->intf); ··· 850 852 { 851 853 struct bcm5974 *dev = input_get_drvdata(input); 852 854 853 - mutex_lock(&dev->pm_mutex); 854 - 855 - bcm5974_pause_traffic(dev); 856 - dev->opened = 0; 857 - 858 - mutex_unlock(&dev->pm_mutex); 855 + scoped_guard(mutex, &dev->pm_mutex) { 856 + bcm5974_pause_traffic(dev); 857 + dev->opened = 0; 858 + } 859 859 860 860 usb_autopm_put_interface(dev->intf); 861 861 } ··· 862 866 { 863 867 struct bcm5974 *dev = usb_get_intfdata(iface); 864 868 865 - mutex_lock(&dev->pm_mutex); 869 + guard(mutex)(&dev->pm_mutex); 866 870 867 871 if (dev->opened) 868 872 bcm5974_pause_traffic(dev); 869 - 870 - mutex_unlock(&dev->pm_mutex); 871 873 872 874 return 0; 873 875 } ··· 873 879 static int bcm5974_resume(struct usb_interface *iface) 874 880 { 875 881 struct bcm5974 *dev = usb_get_intfdata(iface); 876 - int error = 0; 877 882 878 - mutex_lock(&dev->pm_mutex); 883 + guard(mutex)(&dev->pm_mutex); 879 884 880 885 if (dev->opened) 881 - error = bcm5974_start_traffic(dev); 886 + return bcm5974_start_traffic(dev); 882 887 883 - mutex_unlock(&dev->pm_mutex); 884 - 885 - return error; 888 + return 0; 886 889 } 887 890 888 891 static int bcm5974_probe(struct usb_interface *iface,
+300
drivers/input/mouse/pixart_ps2.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Pixart Touchpad Controller 1336U PS2 driver 4 + * 5 + * Author: Jon Xie <jon_xie@pixart.com> 6 + * Jay Lee <jay_lee@pixart.com> 7 + * Further cleanup and restructuring by: 8 + * Binbin Zhou <zhoubinbin@loongson.cn> 9 + * 10 + * Copyright (C) 2021-2024 Pixart Imaging. 11 + * Copyright (C) 2024 Loongson Technology Corporation Limited. 12 + * 13 + */ 14 + 15 + #include <linux/bitfield.h> 16 + #include <linux/delay.h> 17 + #include <linux/device.h> 18 + #include <linux/input.h> 19 + #include <linux/input/mt.h> 20 + #include <linux/libps2.h> 21 + #include <linux/serio.h> 22 + #include <linux/slab.h> 23 + 24 + #include "pixart_ps2.h" 25 + 26 + static int pixart_read_tp_mode(struct ps2dev *ps2dev, u8 *mode) 27 + { 28 + int error; 29 + u8 param[1] = { 0 }; 30 + 31 + error = ps2_command(ps2dev, param, PIXART_CMD_REPORT_FORMAT); 32 + if (error) 33 + return error; 34 + 35 + *mode = param[0] == 1 ? PIXART_MODE_ABS : PIXART_MODE_REL; 36 + 37 + return 0; 38 + } 39 + 40 + static int pixart_read_tp_type(struct ps2dev *ps2dev, u8 *type) 41 + { 42 + int error; 43 + u8 param[3] = { 0 }; 44 + 45 + param[0] = 0x0a; 46 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); 47 + if (error) 48 + return error; 49 + 50 + param[0] = 0x0; 51 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 52 + if (error) 53 + return error; 54 + 55 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 56 + if (error) 57 + return error; 58 + 59 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 60 + if (error) 61 + return error; 62 + 63 + param[0] = 0x03; 64 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 65 + if (error) 66 + return error; 67 + 68 + error = ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); 69 + if (error) 70 + return error; 71 + 72 + *type = param[0] == 0x0e ? PIXART_TYPE_TOUCHPAD : PIXART_TYPE_CLICKPAD; 73 + 74 + return 0; 75 + } 76 + 77 + static void pixart_reset(struct psmouse *psmouse) 78 + { 79 + ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); 80 + 81 + /* according to PixArt, 100ms is required for the upcoming reset */ 82 + msleep(100); 83 + psmouse_reset(psmouse); 84 + } 85 + 86 + static void pixart_process_packet(struct psmouse *psmouse) 87 + { 88 + struct pixart_data *priv = psmouse->private; 89 + struct input_dev *dev = psmouse->dev; 90 + const u8 *pkt = psmouse->packet; 91 + unsigned int contact_cnt = FIELD_GET(CONTACT_CNT_MASK, pkt[0]); 92 + unsigned int i, id, abs_x, abs_y; 93 + bool tip; 94 + 95 + for (i = 0; i < contact_cnt; i++) { 96 + const u8 *p = &pkt[i * 3]; 97 + 98 + id = FIELD_GET(SLOT_ID_MASK, p[3]); 99 + abs_y = FIELD_GET(ABS_Y_MASK, p[3]) << 8 | p[1]; 100 + abs_x = FIELD_GET(ABS_X_MASK, p[3]) << 8 | p[2]; 101 + 102 + if (i == PIXART_MAX_FINGERS - 1) 103 + tip = pkt[14] & BIT(1); 104 + else 105 + tip = pkt[3 * contact_cnt + 1] & BIT(2 * i + 1); 106 + 107 + input_mt_slot(dev, id); 108 + if (input_mt_report_slot_state(dev, MT_TOOL_FINGER, tip)) { 109 + input_report_abs(dev, ABS_MT_POSITION_Y, abs_y); 110 + input_report_abs(dev, ABS_MT_POSITION_X, abs_x); 111 + } 112 + } 113 + 114 + input_mt_sync_frame(dev); 115 + 116 + if (priv->type == PIXART_TYPE_CLICKPAD) { 117 + input_report_key(dev, BTN_LEFT, pkt[0] & 0x03); 118 + } else { 119 + input_report_key(dev, BTN_LEFT, pkt[0] & BIT(0)); 120 + input_report_key(dev, BTN_RIGHT, pkt[0] & BIT(1)); 121 + } 122 + 123 + input_sync(dev); 124 + } 125 + 126 + static psmouse_ret_t pixart_protocol_handler(struct psmouse *psmouse) 127 + { 128 + u8 *pkt = psmouse->packet; 129 + u8 contact_cnt; 130 + 131 + if ((pkt[0] & 0x8c) != 0x80) 132 + return PSMOUSE_BAD_DATA; 133 + 134 + contact_cnt = FIELD_GET(CONTACT_CNT_MASK, pkt[0]); 135 + if (contact_cnt > PIXART_MAX_FINGERS) 136 + return PSMOUSE_BAD_DATA; 137 + 138 + if (contact_cnt == PIXART_MAX_FINGERS && 139 + psmouse->pktcnt < psmouse->pktsize) { 140 + return PSMOUSE_GOOD_DATA; 141 + } 142 + 143 + if (contact_cnt == 0 && psmouse->pktcnt < 5) 144 + return PSMOUSE_GOOD_DATA; 145 + 146 + if (psmouse->pktcnt < 3 * contact_cnt + 2) 147 + return PSMOUSE_GOOD_DATA; 148 + 149 + pixart_process_packet(psmouse); 150 + 151 + return PSMOUSE_FULL_PACKET; 152 + } 153 + 154 + static void pixart_disconnect(struct psmouse *psmouse) 155 + { 156 + pixart_reset(psmouse); 157 + kfree(psmouse->private); 158 + psmouse->private = NULL; 159 + } 160 + 161 + static int pixart_reconnect(struct psmouse *psmouse) 162 + { 163 + struct ps2dev *ps2dev = &psmouse->ps2dev; 164 + u8 mode; 165 + int error; 166 + 167 + pixart_reset(psmouse); 168 + 169 + error = pixart_read_tp_mode(ps2dev, &mode); 170 + if (error) 171 + return error; 172 + 173 + if (mode != PIXART_MODE_ABS) 174 + return -EIO; 175 + 176 + error = ps2_command(ps2dev, NULL, PIXART_CMD_SWITCH_PROTO); 177 + if (error) 178 + return error; 179 + 180 + return 0; 181 + } 182 + 183 + static int pixart_set_input_params(struct input_dev *dev, 184 + struct pixart_data *priv) 185 + { 186 + /* No relative support */ 187 + __clear_bit(EV_REL, dev->evbit); 188 + __clear_bit(REL_X, dev->relbit); 189 + __clear_bit(REL_Y, dev->relbit); 190 + __clear_bit(BTN_MIDDLE, dev->keybit); 191 + 192 + /* Buttons */ 193 + __set_bit(EV_KEY, dev->evbit); 194 + __set_bit(BTN_LEFT, dev->keybit); 195 + if (priv->type == PIXART_TYPE_CLICKPAD) 196 + __set_bit(INPUT_PROP_BUTTONPAD, dev->propbit); 197 + else 198 + __set_bit(BTN_RIGHT, dev->keybit); 199 + 200 + /* Absolute position */ 201 + input_set_abs_params(dev, ABS_X, 0, PIXART_PAD_WIDTH, 0, 0); 202 + input_set_abs_params(dev, ABS_Y, 0, PIXART_PAD_HEIGHT, 0, 0); 203 + 204 + input_set_abs_params(dev, ABS_MT_POSITION_X, 205 + 0, PIXART_PAD_WIDTH, 0, 0); 206 + input_set_abs_params(dev, ABS_MT_POSITION_Y, 207 + 0, PIXART_PAD_HEIGHT, 0, 0); 208 + 209 + return input_mt_init_slots(dev, PIXART_MAX_FINGERS, INPUT_MT_POINTER); 210 + } 211 + 212 + static int pixart_query_hardware(struct ps2dev *ps2dev, u8 *mode, u8 *type) 213 + { 214 + int error; 215 + 216 + error = pixart_read_tp_type(ps2dev, type); 217 + if (error) 218 + return error; 219 + 220 + error = pixart_read_tp_mode(ps2dev, mode); 221 + if (error) 222 + return error; 223 + 224 + return 0; 225 + } 226 + 227 + int pixart_detect(struct psmouse *psmouse, bool set_properties) 228 + { 229 + u8 type; 230 + int error; 231 + 232 + pixart_reset(psmouse); 233 + 234 + error = pixart_read_tp_type(&psmouse->ps2dev, &type); 235 + if (error) 236 + return error; 237 + 238 + if (set_properties) { 239 + psmouse->vendor = "PixArt"; 240 + psmouse->name = (type == PIXART_TYPE_TOUCHPAD) ? 241 + "touchpad" : "clickpad"; 242 + } 243 + 244 + return 0; 245 + } 246 + 247 + int pixart_init(struct psmouse *psmouse) 248 + { 249 + int error; 250 + struct pixart_data *priv; 251 + 252 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 253 + if (!priv) 254 + return -ENOMEM; 255 + 256 + psmouse->private = priv; 257 + pixart_reset(psmouse); 258 + 259 + error = pixart_query_hardware(&psmouse->ps2dev, 260 + &priv->mode, &priv->type); 261 + if (error) { 262 + psmouse_err(psmouse, "init: Unable to query PixArt touchpad hardware.\n"); 263 + goto err_exit; 264 + } 265 + 266 + /* Relative mode follows standard PS/2 mouse protocol */ 267 + if (priv->mode != PIXART_MODE_ABS) { 268 + error = -EIO; 269 + goto err_exit; 270 + } 271 + 272 + /* Set absolute mode */ 273 + error = ps2_command(&psmouse->ps2dev, NULL, PIXART_CMD_SWITCH_PROTO); 274 + if (error) { 275 + psmouse_err(psmouse, "init: Unable to initialize PixArt absolute mode.\n"); 276 + goto err_exit; 277 + } 278 + 279 + error = pixart_set_input_params(psmouse->dev, priv); 280 + if (error) { 281 + psmouse_err(psmouse, "init: Unable to set input params.\n"); 282 + goto err_exit; 283 + } 284 + 285 + psmouse->pktsize = 15; 286 + psmouse->protocol_handler = pixart_protocol_handler; 287 + psmouse->disconnect = pixart_disconnect; 288 + psmouse->reconnect = pixart_reconnect; 289 + psmouse->cleanup = pixart_reset; 290 + /* resync is not supported yet */ 291 + psmouse->resync_time = 0; 292 + 293 + return 0; 294 + 295 + err_exit: 296 + pixart_reset(psmouse); 297 + kfree(priv); 298 + psmouse->private = NULL; 299 + return error; 300 + }
+36
drivers/input/mouse/pixart_ps2.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + #ifndef _PIXART_PS2_H 3 + #define _PIXART_PS2_H 4 + 5 + #include "psmouse.h" 6 + 7 + #define PIXART_PAD_WIDTH 1023 8 + #define PIXART_PAD_HEIGHT 579 9 + #define PIXART_MAX_FINGERS 4 10 + 11 + #define PIXART_CMD_REPORT_FORMAT 0x01d8 12 + #define PIXART_CMD_SWITCH_PROTO 0x00de 13 + 14 + #define PIXART_MODE_REL 0 15 + #define PIXART_MODE_ABS 1 16 + 17 + #define PIXART_TYPE_CLICKPAD 0 18 + #define PIXART_TYPE_TOUCHPAD 1 19 + 20 + #define CONTACT_CNT_MASK GENMASK(6, 4) 21 + 22 + #define SLOT_ID_MASK GENMASK(2, 0) 23 + #define ABS_Y_MASK GENMASK(5, 4) 24 + #define ABS_X_MASK GENMASK(7, 6) 25 + 26 + struct pixart_data { 27 + u8 mode; 28 + u8 type; 29 + int x_max; 30 + int y_max; 31 + }; 32 + 33 + int pixart_detect(struct psmouse *psmouse, bool set_properties); 34 + int pixart_init(struct psmouse *psmouse); 35 + 36 + #endif /* _PIXART_PS2_H */
+17
drivers/input/mouse/psmouse-base.c
··· 36 36 #include "focaltech.h" 37 37 #include "vmmouse.h" 38 38 #include "byd.h" 39 + #include "pixart_ps2.h" 39 40 40 41 #define DRIVER_DESC "PS/2 mouse driver" 41 42 ··· 907 906 .init = byd_init, 908 907 }, 909 908 #endif 909 + #ifdef CONFIG_MOUSE_PS2_PIXART 910 + { 911 + .type = PSMOUSE_PIXART, 912 + .name = "PixArtPS/2", 913 + .alias = "pixart", 914 + .detect = pixart_detect, 915 + .init = pixart_init, 916 + }, 917 + #endif 910 918 { 911 919 .type = PSMOUSE_AUTO, 912 920 .name = "auto", ··· 1180 1170 ret = elantech_init(psmouse); 1181 1171 if (ret >= 0) 1182 1172 return ret; 1173 + } 1174 + 1175 + /* Try PixArt touchpad */ 1176 + if (max_proto > PSMOUSE_IMEX && 1177 + psmouse_try_protocol(psmouse, PSMOUSE_PIXART, &max_proto, 1178 + set_properties, true)) { 1179 + return PSMOUSE_PIXART; 1183 1180 } 1184 1181 1185 1182 if (max_proto > PSMOUSE_IMEX) {
+2 -1
drivers/input/mouse/psmouse.h
··· 69 69 PSMOUSE_BYD, 70 70 PSMOUSE_SYNAPTICS_SMBUS, 71 71 PSMOUSE_ELANTECH_SMBUS, 72 + PSMOUSE_PIXART, 72 73 PSMOUSE_AUTO /* This one should always be last */ 73 74 }; 74 75 ··· 95 94 const char *vendor; 96 95 const char *name; 97 96 const struct psmouse_protocol *protocol; 98 - unsigned char packet[8]; 97 + unsigned char packet[16]; 99 98 unsigned char badbyte; 100 99 unsigned char pktcnt; 101 100 unsigned char pktsize;
+34 -11
drivers/input/rmi4/rmi_f12.c
··· 24 24 }; 25 25 26 26 #define F12_DATA1_BYTES_PER_OBJ 8 27 + #define RMI_F12_QUERY_RESOLUTION 29 27 28 28 29 struct f12_data { 29 30 struct rmi_2d_sensor sensor; ··· 74 73 int pitch_y = 0; 75 74 int rx_receivers = 0; 76 75 int tx_receivers = 0; 76 + u16 query_dpm_addr = 0; 77 + int dpm_resolution = 0; 77 78 78 79 item = rmi_get_register_desc_item(&f12->control_reg_desc, 8); 79 80 if (!item) { ··· 125 122 offset += 4; 126 123 } 127 124 128 - if (rmi_register_desc_has_subpacket(item, 3)) { 129 - rx_receivers = buf[offset]; 130 - tx_receivers = buf[offset + 1]; 131 - offset += 2; 125 + /* 126 + * Use the Query DPM feature when the resolution query register 127 + * exists. 128 + */ 129 + if (rmi_get_register_desc_item(&f12->query_reg_desc, 130 + RMI_F12_QUERY_RESOLUTION)) { 131 + offset = rmi_register_desc_calc_reg_offset(&f12->query_reg_desc, 132 + RMI_F12_QUERY_RESOLUTION); 133 + query_dpm_addr = fn->fd.query_base_addr + offset; 134 + ret = rmi_read(fn->rmi_dev, query_dpm_addr, buf); 135 + if (ret < 0) { 136 + dev_err(&fn->dev, "Failed to read DPM value: %d\n", ret); 137 + return -ENODEV; 138 + } 139 + dpm_resolution = buf[0]; 140 + 141 + sensor->x_mm = sensor->max_x / dpm_resolution; 142 + sensor->y_mm = sensor->max_y / dpm_resolution; 143 + } else { 144 + if (rmi_register_desc_has_subpacket(item, 3)) { 145 + rx_receivers = buf[offset]; 146 + tx_receivers = buf[offset + 1]; 147 + offset += 2; 148 + } 149 + 150 + /* Skip over sensor flags */ 151 + if (rmi_register_desc_has_subpacket(item, 4)) 152 + offset += 1; 153 + 154 + sensor->x_mm = (pitch_x * rx_receivers) >> 12; 155 + sensor->y_mm = (pitch_y * tx_receivers) >> 12; 132 156 } 133 - 134 - /* Skip over sensor flags */ 135 - if (rmi_register_desc_has_subpacket(item, 4)) 136 - offset += 1; 137 - 138 - sensor->x_mm = (pitch_x * rx_receivers) >> 12; 139 - sensor->y_mm = (pitch_y * tx_receivers) >> 12; 140 157 141 158 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: x_mm: %d y_mm: %d\n", __func__, 142 159 sensor->x_mm, sensor->y_mm);
+37
drivers/input/serio/i8042-acpipnpio.h
··· 1121 1121 .driver_data = (void *)(SERIO_QUIRK_NOLOOP) 1122 1122 }, 1123 1123 /* 1124 + * Some TongFang barebones have touchpad and/or keyboard issues after 1125 + * suspend fixable with nomux + reset + noloop + nopnp. Luckily, none of 1126 + * them have an external PS/2 port so this can safely be set for all of 1127 + * them. 1128 + * TongFang barebones come with board_vendor and/or system_vendor set to 1129 + * a different value for each individual reseller. The only somewhat 1130 + * universal way to identify them is by board_name. 1131 + */ 1132 + { 1133 + .matches = { 1134 + DMI_MATCH(DMI_BOARD_NAME, "GM6XGxX"), 1135 + }, 1136 + .driver_data = (void *)(SERIO_QUIRK_NOMUX | SERIO_QUIRK_RESET_ALWAYS | 1137 + SERIO_QUIRK_NOLOOP | SERIO_QUIRK_NOPNP) 1138 + }, 1139 + { 1140 + .matches = { 1141 + DMI_MATCH(DMI_BOARD_NAME, "GMxXGxx"), 1142 + }, 1143 + .driver_data = (void *)(SERIO_QUIRK_NOMUX | SERIO_QUIRK_RESET_ALWAYS | 1144 + SERIO_QUIRK_NOLOOP | SERIO_QUIRK_NOPNP) 1145 + }, 1146 + { 1147 + .matches = { 1148 + DMI_MATCH(DMI_BOARD_NAME, "GMxXGxX"), 1149 + }, 1150 + .driver_data = (void *)(SERIO_QUIRK_NOMUX | SERIO_QUIRK_RESET_ALWAYS | 1151 + SERIO_QUIRK_NOLOOP | SERIO_QUIRK_NOPNP) 1152 + }, 1153 + { 1154 + .matches = { 1155 + DMI_MATCH(DMI_BOARD_NAME, "GMxHGxx"), 1156 + }, 1157 + .driver_data = (void *)(SERIO_QUIRK_NOMUX | SERIO_QUIRK_RESET_ALWAYS | 1158 + SERIO_QUIRK_NOLOOP | SERIO_QUIRK_NOPNP) 1159 + }, 1160 + /* 1124 1161 * A lot of modern Clevo barebones have touchpad and/or keyboard issues 1125 1162 * after suspend fixable with nomux + reset + noloop + nopnp. Luckily, 1126 1163 * none of them have an external PS/2 port so this can safely be set for
+2 -4
drivers/input/serio/ps2-gpio.c
··· 429 429 } 430 430 431 431 error = devm_request_irq(dev, drvdata->irq, ps2_gpio_irq, 432 - IRQF_NO_THREAD, DRIVER_NAME, drvdata); 432 + IRQF_NO_THREAD | IRQF_NO_AUTOEN, DRIVER_NAME, 433 + drvdata); 433 434 if (error) { 434 435 dev_err(dev, "failed to request irq %d: %d\n", 435 436 drvdata->irq, error); 436 437 goto err_free_serio; 437 438 } 438 - 439 - /* Keep irq disabled until serio->open is called. */ 440 - disable_irq(drvdata->irq); 441 439 442 440 serio->id.type = SERIO_8042; 443 441 serio->open = ps2_gpio_open;
-42
drivers/input/touchscreen/Kconfig
··· 254 254 To compile this driver as a module, choose M here: the 255 255 module will be called cyttsp_spi. 256 256 257 - config TOUCHSCREEN_CYTTSP4_CORE 258 - tristate "Cypress TrueTouch Gen4 Touchscreen Driver" 259 - help 260 - Core driver for Cypress TrueTouch(tm) Standard Product 261 - Generation4 touchscreen controllers. 262 - 263 - Say Y here if you have a Cypress Gen4 touchscreen. 264 - 265 - If unsure, say N. 266 - 267 - To compile this driver as a module, choose M here. 268 - 269 - config TOUCHSCREEN_CYTTSP4_I2C 270 - tristate "support I2C bus connection" 271 - depends on TOUCHSCREEN_CYTTSP4_CORE && I2C 272 - help 273 - Say Y here if the touchscreen is connected via I2C bus. 274 - 275 - To compile this driver as a module, choose M here: the 276 - module will be called cyttsp4_i2c. 277 - 278 - config TOUCHSCREEN_CYTTSP4_SPI 279 - tristate "support SPI bus connection" 280 - depends on TOUCHSCREEN_CYTTSP4_CORE && SPI_MASTER 281 - help 282 - Say Y here if the touchscreen is connected via SPI bus. 283 - 284 - To compile this driver as a module, choose M here: the 285 - module will be called cyttsp4_spi. 286 - 287 257 config TOUCHSCREEN_CYTTSP5 288 258 tristate "Cypress TrueTouch Gen5 Touchscreen Driver" 289 259 depends on I2C ··· 595 625 596 626 To compile this driver as a module, choose M here: the 597 627 module will be called max11801_ts. 598 - 599 - config TOUCHSCREEN_MCS5000 600 - tristate "MELFAS MCS-5000 touchscreen" 601 - depends on I2C 602 - help 603 - Say Y here if you have the MELFAS MCS-5000 touchscreen controller 604 - chip in your system. 605 - 606 - If unsure, say N. 607 - 608 - To compile this driver as a module, choose M here: the 609 - module will be called mcs5000_ts. 610 628 611 629 config TOUCHSCREEN_MMS114 612 630 tristate "MELFAS MMS114 touchscreen"
+1 -5
drivers/input/touchscreen/Makefile
··· 25 25 obj-$(CONFIG_TOUCHSCREEN_CY8CTMA140) += cy8ctma140.o 26 26 obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o 27 27 obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o 28 - obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o cyttsp_i2c_common.o 28 + obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o 29 29 obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI) += cyttsp_spi.o 30 - obj-$(CONFIG_TOUCHSCREEN_CYTTSP4_CORE) += cyttsp4_core.o 31 - obj-$(CONFIG_TOUCHSCREEN_CYTTSP4_I2C) += cyttsp4_i2c.o cyttsp_i2c_common.o 32 - obj-$(CONFIG_TOUCHSCREEN_CYTTSP4_SPI) += cyttsp4_spi.o 33 30 obj-$(CONFIG_TOUCHSCREEN_CYTTSP5) += cyttsp5.o 34 31 obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o 35 32 obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o ··· 60 63 obj-$(CONFIG_TOUCHSCREEN_MXS_LRADC) += mxs-lradc-ts.o 61 64 obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o 62 65 obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o 63 - obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o 64 66 obj-$(CONFIG_TOUCHSCREEN_MELFAS_MIP4) += melfas_mip4.o 65 67 obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o 66 68 obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o
+3 -7
drivers/input/touchscreen/colibri-vf50-ts.c
··· 239 239 static int vf50_ts_get_gpiod(struct device *dev, struct gpio_desc **gpio_d, 240 240 const char *con_id, enum gpiod_flags flags) 241 241 { 242 - int error; 243 - 244 242 *gpio_d = devm_gpiod_get(dev, con_id, flags); 245 - if (IS_ERR(*gpio_d)) { 246 - error = PTR_ERR(*gpio_d); 247 - dev_err(dev, "Could not get gpio_%s %d\n", con_id, error); 248 - return error; 249 - } 243 + if (IS_ERR(*gpio_d)) 244 + return dev_err_probe(dev, PTR_ERR(*gpio_d), 245 + "Could not get gpio_%s\n", con_id); 250 246 251 247 return 0; 252 248 }
-2174
drivers/input/touchscreen/cyttsp4_core.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * cyttsp4_core.c 4 - * Cypress TrueTouch(TM) Standard Product V4 Core driver module. 5 - * For use with Cypress Txx4xx parts. 6 - * Supported parts include: 7 - * TMA4XX 8 - * TMA1036 9 - * 10 - * Copyright (C) 2012 Cypress Semiconductor 11 - * 12 - * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 13 - */ 14 - 15 - #include "cyttsp4_core.h" 16 - #include <linux/delay.h> 17 - #include <linux/gpio.h> 18 - #include <linux/input/mt.h> 19 - #include <linux/interrupt.h> 20 - #include <linux/pm_runtime.h> 21 - #include <linux/sched.h> 22 - #include <linux/slab.h> 23 - 24 - /* Timeout in ms. */ 25 - #define CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT 500 26 - #define CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT 5000 27 - #define CY_CORE_MODE_CHANGE_TIMEOUT 1000 28 - #define CY_CORE_RESET_AND_WAIT_TIMEOUT 500 29 - #define CY_CORE_WAKEUP_TIMEOUT 500 30 - 31 - #define CY_CORE_STARTUP_RETRY_COUNT 3 32 - 33 - static const char * const cyttsp4_tch_abs_string[] = { 34 - [CY_TCH_X] = "X", 35 - [CY_TCH_Y] = "Y", 36 - [CY_TCH_P] = "P", 37 - [CY_TCH_T] = "T", 38 - [CY_TCH_E] = "E", 39 - [CY_TCH_O] = "O", 40 - [CY_TCH_W] = "W", 41 - [CY_TCH_MAJ] = "MAJ", 42 - [CY_TCH_MIN] = "MIN", 43 - [CY_TCH_OR] = "OR", 44 - [CY_TCH_NUM_ABS] = "INVALID" 45 - }; 46 - 47 - static const u8 ldr_exit[] = { 48 - 0xFF, 0x01, 0x3B, 0x00, 0x00, 0x4F, 0x6D, 0x17 49 - }; 50 - 51 - static const u8 ldr_err_app[] = { 52 - 0x01, 0x02, 0x00, 0x00, 0x55, 0xDD, 0x17 53 - }; 54 - 55 - static inline size_t merge_bytes(u8 high, u8 low) 56 - { 57 - return (high << 8) + low; 58 - } 59 - 60 - #ifdef VERBOSE_DEBUG 61 - static void cyttsp4_pr_buf(struct device *dev, u8 *pr_buf, u8 *dptr, int size, 62 - const char *data_name) 63 - { 64 - int i, k; 65 - const char fmt[] = "%02X "; 66 - int max; 67 - 68 - if (!size) 69 - return; 70 - 71 - max = (CY_MAX_PRBUF_SIZE - 1) - sizeof(CY_PR_TRUNCATED); 72 - 73 - pr_buf[0] = 0; 74 - for (i = k = 0; i < size && k < max; i++, k += 3) 75 - scnprintf(pr_buf + k, CY_MAX_PRBUF_SIZE, fmt, dptr[i]); 76 - 77 - dev_vdbg(dev, "%s: %s[0..%d]=%s%s\n", __func__, data_name, size - 1, 78 - pr_buf, size <= max ? "" : CY_PR_TRUNCATED); 79 - } 80 - #else 81 - #define cyttsp4_pr_buf(dev, pr_buf, dptr, size, data_name) do { } while (0) 82 - #endif 83 - 84 - static int cyttsp4_load_status_regs(struct cyttsp4 *cd) 85 - { 86 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 87 - struct device *dev = cd->dev; 88 - int rc; 89 - 90 - rc = cyttsp4_adap_read(cd, CY_REG_BASE, si->si_ofs.mode_size, 91 - si->xy_mode); 92 - if (rc < 0) 93 - dev_err(dev, "%s: fail read mode regs r=%d\n", 94 - __func__, rc); 95 - else 96 - cyttsp4_pr_buf(dev, cd->pr_buf, si->xy_mode, 97 - si->si_ofs.mode_size, "xy_mode"); 98 - 99 - return rc; 100 - } 101 - 102 - static int cyttsp4_handshake(struct cyttsp4 *cd, u8 mode) 103 - { 104 - u8 cmd = mode ^ CY_HST_TOGGLE; 105 - int rc; 106 - 107 - /* 108 - * Mode change issued, handshaking now will cause endless mode change 109 - * requests, for sync mode modechange will do same with handshake 110 - * */ 111 - if (mode & CY_HST_MODE_CHANGE) 112 - return 0; 113 - 114 - rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(cmd), &cmd); 115 - if (rc < 0) 116 - dev_err(cd->dev, "%s: bus write fail on handshake (ret=%d)\n", 117 - __func__, rc); 118 - 119 - return rc; 120 - } 121 - 122 - static int cyttsp4_hw_soft_reset(struct cyttsp4 *cd) 123 - { 124 - u8 cmd = CY_HST_RESET; 125 - int rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(cmd), &cmd); 126 - if (rc < 0) { 127 - dev_err(cd->dev, "%s: FAILED to execute SOFT reset\n", 128 - __func__); 129 - return rc; 130 - } 131 - return 0; 132 - } 133 - 134 - static int cyttsp4_hw_hard_reset(struct cyttsp4 *cd) 135 - { 136 - if (cd->cpdata->xres) { 137 - cd->cpdata->xres(cd->cpdata, cd->dev); 138 - dev_dbg(cd->dev, "%s: execute HARD reset\n", __func__); 139 - return 0; 140 - } 141 - dev_err(cd->dev, "%s: FAILED to execute HARD reset\n", __func__); 142 - return -ENOSYS; 143 - } 144 - 145 - static int cyttsp4_hw_reset(struct cyttsp4 *cd) 146 - { 147 - int rc = cyttsp4_hw_hard_reset(cd); 148 - if (rc == -ENOSYS) 149 - rc = cyttsp4_hw_soft_reset(cd); 150 - return rc; 151 - } 152 - 153 - /* 154 - * Gets number of bits for a touch filed as parameter, 155 - * sets maximum value for field which is used as bit mask 156 - * and returns number of bytes required for that field 157 - */ 158 - static int cyttsp4_bits_2_bytes(unsigned int nbits, size_t *max) 159 - { 160 - *max = 1UL << nbits; 161 - return (nbits + 7) / 8; 162 - } 163 - 164 - static int cyttsp4_si_data_offsets(struct cyttsp4 *cd) 165 - { 166 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 167 - int rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(si->si_data), 168 - &si->si_data); 169 - if (rc < 0) { 170 - dev_err(cd->dev, "%s: fail read sysinfo data offsets r=%d\n", 171 - __func__, rc); 172 - return rc; 173 - } 174 - 175 - /* Print sysinfo data offsets */ 176 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)&si->si_data, 177 - sizeof(si->si_data), "sysinfo_data_offsets"); 178 - 179 - /* convert sysinfo data offset bytes into integers */ 180 - 181 - si->si_ofs.map_sz = merge_bytes(si->si_data.map_szh, 182 - si->si_data.map_szl); 183 - si->si_ofs.map_sz = merge_bytes(si->si_data.map_szh, 184 - si->si_data.map_szl); 185 - si->si_ofs.cydata_ofs = merge_bytes(si->si_data.cydata_ofsh, 186 - si->si_data.cydata_ofsl); 187 - si->si_ofs.test_ofs = merge_bytes(si->si_data.test_ofsh, 188 - si->si_data.test_ofsl); 189 - si->si_ofs.pcfg_ofs = merge_bytes(si->si_data.pcfg_ofsh, 190 - si->si_data.pcfg_ofsl); 191 - si->si_ofs.opcfg_ofs = merge_bytes(si->si_data.opcfg_ofsh, 192 - si->si_data.opcfg_ofsl); 193 - si->si_ofs.ddata_ofs = merge_bytes(si->si_data.ddata_ofsh, 194 - si->si_data.ddata_ofsl); 195 - si->si_ofs.mdata_ofs = merge_bytes(si->si_data.mdata_ofsh, 196 - si->si_data.mdata_ofsl); 197 - return rc; 198 - } 199 - 200 - static int cyttsp4_si_get_cydata(struct cyttsp4 *cd) 201 - { 202 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 203 - int read_offset; 204 - int mfgid_sz, calc_mfgid_sz; 205 - void *p; 206 - int rc; 207 - 208 - if (si->si_ofs.test_ofs <= si->si_ofs.cydata_ofs) { 209 - dev_err(cd->dev, 210 - "%s: invalid offset test_ofs: %zu, cydata_ofs: %zu\n", 211 - __func__, si->si_ofs.test_ofs, si->si_ofs.cydata_ofs); 212 - return -EINVAL; 213 - } 214 - 215 - si->si_ofs.cydata_size = si->si_ofs.test_ofs - si->si_ofs.cydata_ofs; 216 - dev_dbg(cd->dev, "%s: cydata size: %zd\n", __func__, 217 - si->si_ofs.cydata_size); 218 - 219 - p = krealloc(si->si_ptrs.cydata, si->si_ofs.cydata_size, GFP_KERNEL); 220 - if (p == NULL) { 221 - dev_err(cd->dev, "%s: failed to allocate cydata memory\n", 222 - __func__); 223 - return -ENOMEM; 224 - } 225 - si->si_ptrs.cydata = p; 226 - 227 - read_offset = si->si_ofs.cydata_ofs; 228 - 229 - /* Read the CYDA registers up to MFGID field */ 230 - rc = cyttsp4_adap_read(cd, read_offset, 231 - offsetof(struct cyttsp4_cydata, mfgid_sz) 232 - + sizeof(si->si_ptrs.cydata->mfgid_sz), 233 - si->si_ptrs.cydata); 234 - if (rc < 0) { 235 - dev_err(cd->dev, "%s: fail read cydata r=%d\n", 236 - __func__, rc); 237 - return rc; 238 - } 239 - 240 - /* Check MFGID size */ 241 - mfgid_sz = si->si_ptrs.cydata->mfgid_sz; 242 - calc_mfgid_sz = si->si_ofs.cydata_size - sizeof(struct cyttsp4_cydata); 243 - if (mfgid_sz != calc_mfgid_sz) { 244 - dev_err(cd->dev, "%s: mismatch in MFGID size, reported:%d calculated:%d\n", 245 - __func__, mfgid_sz, calc_mfgid_sz); 246 - return -EINVAL; 247 - } 248 - 249 - read_offset += offsetof(struct cyttsp4_cydata, mfgid_sz) 250 - + sizeof(si->si_ptrs.cydata->mfgid_sz); 251 - 252 - /* Read the CYDA registers for MFGID field */ 253 - rc = cyttsp4_adap_read(cd, read_offset, si->si_ptrs.cydata->mfgid_sz, 254 - si->si_ptrs.cydata->mfg_id); 255 - if (rc < 0) { 256 - dev_err(cd->dev, "%s: fail read cydata r=%d\n", 257 - __func__, rc); 258 - return rc; 259 - } 260 - 261 - read_offset += si->si_ptrs.cydata->mfgid_sz; 262 - 263 - /* Read the rest of the CYDA registers */ 264 - rc = cyttsp4_adap_read(cd, read_offset, 265 - sizeof(struct cyttsp4_cydata) 266 - - offsetof(struct cyttsp4_cydata, cyito_idh), 267 - &si->si_ptrs.cydata->cyito_idh); 268 - if (rc < 0) { 269 - dev_err(cd->dev, "%s: fail read cydata r=%d\n", 270 - __func__, rc); 271 - return rc; 272 - } 273 - 274 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)si->si_ptrs.cydata, 275 - si->si_ofs.cydata_size, "sysinfo_cydata"); 276 - return rc; 277 - } 278 - 279 - static int cyttsp4_si_get_test_data(struct cyttsp4 *cd) 280 - { 281 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 282 - void *p; 283 - int rc; 284 - 285 - if (si->si_ofs.pcfg_ofs <= si->si_ofs.test_ofs) { 286 - dev_err(cd->dev, 287 - "%s: invalid offset pcfg_ofs: %zu, test_ofs: %zu\n", 288 - __func__, si->si_ofs.pcfg_ofs, si->si_ofs.test_ofs); 289 - return -EINVAL; 290 - } 291 - 292 - si->si_ofs.test_size = si->si_ofs.pcfg_ofs - si->si_ofs.test_ofs; 293 - 294 - p = krealloc(si->si_ptrs.test, si->si_ofs.test_size, GFP_KERNEL); 295 - if (p == NULL) { 296 - dev_err(cd->dev, "%s: failed to allocate test memory\n", 297 - __func__); 298 - return -ENOMEM; 299 - } 300 - si->si_ptrs.test = p; 301 - 302 - rc = cyttsp4_adap_read(cd, si->si_ofs.test_ofs, si->si_ofs.test_size, 303 - si->si_ptrs.test); 304 - if (rc < 0) { 305 - dev_err(cd->dev, "%s: fail read test data r=%d\n", 306 - __func__, rc); 307 - return rc; 308 - } 309 - 310 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, 311 - (u8 *)si->si_ptrs.test, si->si_ofs.test_size, 312 - "sysinfo_test_data"); 313 - if (si->si_ptrs.test->post_codel & 314 - CY_POST_CODEL_WDG_RST) 315 - dev_info(cd->dev, "%s: %s codel=%02X\n", 316 - __func__, "Reset was a WATCHDOG RESET", 317 - si->si_ptrs.test->post_codel); 318 - 319 - if (!(si->si_ptrs.test->post_codel & 320 - CY_POST_CODEL_CFG_DATA_CRC_FAIL)) 321 - dev_info(cd->dev, "%s: %s codel=%02X\n", __func__, 322 - "Config Data CRC FAIL", 323 - si->si_ptrs.test->post_codel); 324 - 325 - if (!(si->si_ptrs.test->post_codel & 326 - CY_POST_CODEL_PANEL_TEST_FAIL)) 327 - dev_info(cd->dev, "%s: %s codel=%02X\n", 328 - __func__, "PANEL TEST FAIL", 329 - si->si_ptrs.test->post_codel); 330 - 331 - dev_info(cd->dev, "%s: SCANNING is %s codel=%02X\n", 332 - __func__, si->si_ptrs.test->post_codel & 0x08 ? 333 - "ENABLED" : "DISABLED", 334 - si->si_ptrs.test->post_codel); 335 - return rc; 336 - } 337 - 338 - static int cyttsp4_si_get_pcfg_data(struct cyttsp4 *cd) 339 - { 340 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 341 - void *p; 342 - int rc; 343 - 344 - if (si->si_ofs.opcfg_ofs <= si->si_ofs.pcfg_ofs) { 345 - dev_err(cd->dev, 346 - "%s: invalid offset opcfg_ofs: %zu, pcfg_ofs: %zu\n", 347 - __func__, si->si_ofs.opcfg_ofs, si->si_ofs.pcfg_ofs); 348 - return -EINVAL; 349 - } 350 - 351 - si->si_ofs.pcfg_size = si->si_ofs.opcfg_ofs - si->si_ofs.pcfg_ofs; 352 - 353 - p = krealloc(si->si_ptrs.pcfg, si->si_ofs.pcfg_size, GFP_KERNEL); 354 - if (p == NULL) { 355 - dev_err(cd->dev, "%s: failed to allocate pcfg memory\n", 356 - __func__); 357 - return -ENOMEM; 358 - } 359 - si->si_ptrs.pcfg = p; 360 - 361 - rc = cyttsp4_adap_read(cd, si->si_ofs.pcfg_ofs, si->si_ofs.pcfg_size, 362 - si->si_ptrs.pcfg); 363 - if (rc < 0) { 364 - dev_err(cd->dev, "%s: fail read pcfg data r=%d\n", 365 - __func__, rc); 366 - return rc; 367 - } 368 - 369 - si->si_ofs.max_x = merge_bytes((si->si_ptrs.pcfg->res_xh 370 - & CY_PCFG_RESOLUTION_X_MASK), si->si_ptrs.pcfg->res_xl); 371 - si->si_ofs.x_origin = !!(si->si_ptrs.pcfg->res_xh 372 - & CY_PCFG_ORIGIN_X_MASK); 373 - si->si_ofs.max_y = merge_bytes((si->si_ptrs.pcfg->res_yh 374 - & CY_PCFG_RESOLUTION_Y_MASK), si->si_ptrs.pcfg->res_yl); 375 - si->si_ofs.y_origin = !!(si->si_ptrs.pcfg->res_yh 376 - & CY_PCFG_ORIGIN_Y_MASK); 377 - si->si_ofs.max_p = merge_bytes(si->si_ptrs.pcfg->max_zh, 378 - si->si_ptrs.pcfg->max_zl); 379 - 380 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, 381 - (u8 *)si->si_ptrs.pcfg, 382 - si->si_ofs.pcfg_size, "sysinfo_pcfg_data"); 383 - return rc; 384 - } 385 - 386 - static int cyttsp4_si_get_opcfg_data(struct cyttsp4 *cd) 387 - { 388 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 389 - struct cyttsp4_tch_abs_params *tch; 390 - struct cyttsp4_tch_rec_params *tch_old, *tch_new; 391 - enum cyttsp4_tch_abs abs; 392 - int i; 393 - void *p; 394 - int rc; 395 - 396 - if (si->si_ofs.ddata_ofs <= si->si_ofs.opcfg_ofs) { 397 - dev_err(cd->dev, 398 - "%s: invalid offset ddata_ofs: %zu, opcfg_ofs: %zu\n", 399 - __func__, si->si_ofs.ddata_ofs, si->si_ofs.opcfg_ofs); 400 - return -EINVAL; 401 - } 402 - 403 - si->si_ofs.opcfg_size = si->si_ofs.ddata_ofs - si->si_ofs.opcfg_ofs; 404 - 405 - p = krealloc(si->si_ptrs.opcfg, si->si_ofs.opcfg_size, GFP_KERNEL); 406 - if (p == NULL) { 407 - dev_err(cd->dev, "%s: failed to allocate opcfg memory\n", 408 - __func__); 409 - return -ENOMEM; 410 - } 411 - si->si_ptrs.opcfg = p; 412 - 413 - rc = cyttsp4_adap_read(cd, si->si_ofs.opcfg_ofs, si->si_ofs.opcfg_size, 414 - si->si_ptrs.opcfg); 415 - if (rc < 0) { 416 - dev_err(cd->dev, "%s: fail read opcfg data r=%d\n", 417 - __func__, rc); 418 - return rc; 419 - } 420 - si->si_ofs.cmd_ofs = si->si_ptrs.opcfg->cmd_ofs; 421 - si->si_ofs.rep_ofs = si->si_ptrs.opcfg->rep_ofs; 422 - si->si_ofs.rep_sz = (si->si_ptrs.opcfg->rep_szh * 256) + 423 - si->si_ptrs.opcfg->rep_szl; 424 - si->si_ofs.num_btns = si->si_ptrs.opcfg->num_btns; 425 - si->si_ofs.num_btn_regs = (si->si_ofs.num_btns + 426 - CY_NUM_BTN_PER_REG - 1) / CY_NUM_BTN_PER_REG; 427 - si->si_ofs.tt_stat_ofs = si->si_ptrs.opcfg->tt_stat_ofs; 428 - si->si_ofs.obj_cfg0 = si->si_ptrs.opcfg->obj_cfg0; 429 - si->si_ofs.max_tchs = si->si_ptrs.opcfg->max_tchs & 430 - CY_BYTE_OFS_MASK; 431 - si->si_ofs.tch_rec_size = si->si_ptrs.opcfg->tch_rec_size & 432 - CY_BYTE_OFS_MASK; 433 - 434 - /* Get the old touch fields */ 435 - for (abs = CY_TCH_X; abs < CY_NUM_TCH_FIELDS; abs++) { 436 - tch = &si->si_ofs.tch_abs[abs]; 437 - tch_old = &si->si_ptrs.opcfg->tch_rec_old[abs]; 438 - 439 - tch->ofs = tch_old->loc & CY_BYTE_OFS_MASK; 440 - tch->size = cyttsp4_bits_2_bytes(tch_old->size, 441 - &tch->max); 442 - tch->bofs = (tch_old->loc & CY_BOFS_MASK) >> CY_BOFS_SHIFT; 443 - } 444 - 445 - /* button fields */ 446 - si->si_ofs.btn_rec_size = si->si_ptrs.opcfg->btn_rec_size; 447 - si->si_ofs.btn_diff_ofs = si->si_ptrs.opcfg->btn_diff_ofs; 448 - si->si_ofs.btn_diff_size = si->si_ptrs.opcfg->btn_diff_size; 449 - 450 - if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE) { 451 - /* Get the extended touch fields */ 452 - for (i = 0; i < CY_NUM_EXT_TCH_FIELDS; abs++, i++) { 453 - tch = &si->si_ofs.tch_abs[abs]; 454 - tch_new = &si->si_ptrs.opcfg->tch_rec_new[i]; 455 - 456 - tch->ofs = tch_new->loc & CY_BYTE_OFS_MASK; 457 - tch->size = cyttsp4_bits_2_bytes(tch_new->size, 458 - &tch->max); 459 - tch->bofs = (tch_new->loc & CY_BOFS_MASK) >> CY_BOFS_SHIFT; 460 - } 461 - } 462 - 463 - for (abs = 0; abs < CY_TCH_NUM_ABS; abs++) { 464 - dev_dbg(cd->dev, "%s: tch_rec_%s\n", __func__, 465 - cyttsp4_tch_abs_string[abs]); 466 - dev_dbg(cd->dev, "%s: ofs =%2zd\n", __func__, 467 - si->si_ofs.tch_abs[abs].ofs); 468 - dev_dbg(cd->dev, "%s: siz =%2zd\n", __func__, 469 - si->si_ofs.tch_abs[abs].size); 470 - dev_dbg(cd->dev, "%s: max =%2zd\n", __func__, 471 - si->si_ofs.tch_abs[abs].max); 472 - dev_dbg(cd->dev, "%s: bofs=%2zd\n", __func__, 473 - si->si_ofs.tch_abs[abs].bofs); 474 - } 475 - 476 - si->si_ofs.mode_size = si->si_ofs.tt_stat_ofs + 1; 477 - si->si_ofs.data_size = si->si_ofs.max_tchs * 478 - si->si_ptrs.opcfg->tch_rec_size; 479 - 480 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, (u8 *)si->si_ptrs.opcfg, 481 - si->si_ofs.opcfg_size, "sysinfo_opcfg_data"); 482 - 483 - return 0; 484 - } 485 - 486 - static int cyttsp4_si_get_ddata(struct cyttsp4 *cd) 487 - { 488 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 489 - void *p; 490 - int rc; 491 - 492 - si->si_ofs.ddata_size = si->si_ofs.mdata_ofs - si->si_ofs.ddata_ofs; 493 - 494 - p = krealloc(si->si_ptrs.ddata, si->si_ofs.ddata_size, GFP_KERNEL); 495 - if (p == NULL) { 496 - dev_err(cd->dev, "%s: fail alloc ddata memory\n", __func__); 497 - return -ENOMEM; 498 - } 499 - si->si_ptrs.ddata = p; 500 - 501 - rc = cyttsp4_adap_read(cd, si->si_ofs.ddata_ofs, si->si_ofs.ddata_size, 502 - si->si_ptrs.ddata); 503 - if (rc < 0) 504 - dev_err(cd->dev, "%s: fail read ddata data r=%d\n", 505 - __func__, rc); 506 - else 507 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, 508 - (u8 *)si->si_ptrs.ddata, 509 - si->si_ofs.ddata_size, "sysinfo_ddata"); 510 - return rc; 511 - } 512 - 513 - static int cyttsp4_si_get_mdata(struct cyttsp4 *cd) 514 - { 515 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 516 - void *p; 517 - int rc; 518 - 519 - si->si_ofs.mdata_size = si->si_ofs.map_sz - si->si_ofs.mdata_ofs; 520 - 521 - p = krealloc(si->si_ptrs.mdata, si->si_ofs.mdata_size, GFP_KERNEL); 522 - if (p == NULL) { 523 - dev_err(cd->dev, "%s: fail alloc mdata memory\n", __func__); 524 - return -ENOMEM; 525 - } 526 - si->si_ptrs.mdata = p; 527 - 528 - rc = cyttsp4_adap_read(cd, si->si_ofs.mdata_ofs, si->si_ofs.mdata_size, 529 - si->si_ptrs.mdata); 530 - if (rc < 0) 531 - dev_err(cd->dev, "%s: fail read mdata data r=%d\n", 532 - __func__, rc); 533 - else 534 - cyttsp4_pr_buf(cd->dev, cd->pr_buf, 535 - (u8 *)si->si_ptrs.mdata, 536 - si->si_ofs.mdata_size, "sysinfo_mdata"); 537 - return rc; 538 - } 539 - 540 - static int cyttsp4_si_get_btn_data(struct cyttsp4 *cd) 541 - { 542 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 543 - int btn; 544 - int num_defined_keys; 545 - u16 *key_table; 546 - void *p; 547 - int rc = 0; 548 - 549 - if (si->si_ofs.num_btns) { 550 - si->si_ofs.btn_keys_size = si->si_ofs.num_btns * 551 - sizeof(struct cyttsp4_btn); 552 - 553 - p = krealloc(si->btn, si->si_ofs.btn_keys_size, 554 - GFP_KERNEL|__GFP_ZERO); 555 - if (p == NULL) { 556 - dev_err(cd->dev, "%s: %s\n", __func__, 557 - "fail alloc btn_keys memory"); 558 - return -ENOMEM; 559 - } 560 - si->btn = p; 561 - 562 - if (cd->cpdata->sett[CY_IC_GRPNUM_BTN_KEYS] == NULL) 563 - num_defined_keys = 0; 564 - else if (cd->cpdata->sett[CY_IC_GRPNUM_BTN_KEYS]->data == NULL) 565 - num_defined_keys = 0; 566 - else 567 - num_defined_keys = cd->cpdata->sett 568 - [CY_IC_GRPNUM_BTN_KEYS]->size; 569 - 570 - for (btn = 0; btn < si->si_ofs.num_btns && 571 - btn < num_defined_keys; btn++) { 572 - key_table = (u16 *)cd->cpdata->sett 573 - [CY_IC_GRPNUM_BTN_KEYS]->data; 574 - si->btn[btn].key_code = key_table[btn]; 575 - si->btn[btn].state = CY_BTN_RELEASED; 576 - si->btn[btn].enabled = true; 577 - } 578 - for (; btn < si->si_ofs.num_btns; btn++) { 579 - si->btn[btn].key_code = KEY_RESERVED; 580 - si->btn[btn].state = CY_BTN_RELEASED; 581 - si->btn[btn].enabled = true; 582 - } 583 - 584 - return rc; 585 - } 586 - 587 - si->si_ofs.btn_keys_size = 0; 588 - kfree(si->btn); 589 - si->btn = NULL; 590 - return rc; 591 - } 592 - 593 - static int cyttsp4_si_get_op_data_ptrs(struct cyttsp4 *cd) 594 - { 595 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 596 - void *p; 597 - 598 - p = krealloc(si->xy_mode, si->si_ofs.mode_size, GFP_KERNEL|__GFP_ZERO); 599 - if (p == NULL) 600 - return -ENOMEM; 601 - si->xy_mode = p; 602 - 603 - p = krealloc(si->xy_data, si->si_ofs.data_size, GFP_KERNEL|__GFP_ZERO); 604 - if (p == NULL) 605 - return -ENOMEM; 606 - si->xy_data = p; 607 - 608 - p = krealloc(si->btn_rec_data, 609 - si->si_ofs.btn_rec_size * si->si_ofs.num_btns, 610 - GFP_KERNEL|__GFP_ZERO); 611 - if (p == NULL) 612 - return -ENOMEM; 613 - si->btn_rec_data = p; 614 - 615 - return 0; 616 - } 617 - 618 - static void cyttsp4_si_put_log_data(struct cyttsp4 *cd) 619 - { 620 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 621 - dev_dbg(cd->dev, "%s: cydata_ofs =%4zd siz=%4zd\n", __func__, 622 - si->si_ofs.cydata_ofs, si->si_ofs.cydata_size); 623 - dev_dbg(cd->dev, "%s: test_ofs =%4zd siz=%4zd\n", __func__, 624 - si->si_ofs.test_ofs, si->si_ofs.test_size); 625 - dev_dbg(cd->dev, "%s: pcfg_ofs =%4zd siz=%4zd\n", __func__, 626 - si->si_ofs.pcfg_ofs, si->si_ofs.pcfg_size); 627 - dev_dbg(cd->dev, "%s: opcfg_ofs =%4zd siz=%4zd\n", __func__, 628 - si->si_ofs.opcfg_ofs, si->si_ofs.opcfg_size); 629 - dev_dbg(cd->dev, "%s: ddata_ofs =%4zd siz=%4zd\n", __func__, 630 - si->si_ofs.ddata_ofs, si->si_ofs.ddata_size); 631 - dev_dbg(cd->dev, "%s: mdata_ofs =%4zd siz=%4zd\n", __func__, 632 - si->si_ofs.mdata_ofs, si->si_ofs.mdata_size); 633 - 634 - dev_dbg(cd->dev, "%s: cmd_ofs =%4zd\n", __func__, 635 - si->si_ofs.cmd_ofs); 636 - dev_dbg(cd->dev, "%s: rep_ofs =%4zd\n", __func__, 637 - si->si_ofs.rep_ofs); 638 - dev_dbg(cd->dev, "%s: rep_sz =%4zd\n", __func__, 639 - si->si_ofs.rep_sz); 640 - dev_dbg(cd->dev, "%s: num_btns =%4zd\n", __func__, 641 - si->si_ofs.num_btns); 642 - dev_dbg(cd->dev, "%s: num_btn_regs =%4zd\n", __func__, 643 - si->si_ofs.num_btn_regs); 644 - dev_dbg(cd->dev, "%s: tt_stat_ofs =%4zd\n", __func__, 645 - si->si_ofs.tt_stat_ofs); 646 - dev_dbg(cd->dev, "%s: tch_rec_size =%4zd\n", __func__, 647 - si->si_ofs.tch_rec_size); 648 - dev_dbg(cd->dev, "%s: max_tchs =%4zd\n", __func__, 649 - si->si_ofs.max_tchs); 650 - dev_dbg(cd->dev, "%s: mode_size =%4zd\n", __func__, 651 - si->si_ofs.mode_size); 652 - dev_dbg(cd->dev, "%s: data_size =%4zd\n", __func__, 653 - si->si_ofs.data_size); 654 - dev_dbg(cd->dev, "%s: map_sz =%4zd\n", __func__, 655 - si->si_ofs.map_sz); 656 - 657 - dev_dbg(cd->dev, "%s: btn_rec_size =%2zd\n", __func__, 658 - si->si_ofs.btn_rec_size); 659 - dev_dbg(cd->dev, "%s: btn_diff_ofs =%2zd\n", __func__, 660 - si->si_ofs.btn_diff_ofs); 661 - dev_dbg(cd->dev, "%s: btn_diff_size =%2zd\n", __func__, 662 - si->si_ofs.btn_diff_size); 663 - 664 - dev_dbg(cd->dev, "%s: max_x = 0x%04zX (%zd)\n", __func__, 665 - si->si_ofs.max_x, si->si_ofs.max_x); 666 - dev_dbg(cd->dev, "%s: x_origin = %zd (%s)\n", __func__, 667 - si->si_ofs.x_origin, 668 - si->si_ofs.x_origin == CY_NORMAL_ORIGIN ? 669 - "left corner" : "right corner"); 670 - dev_dbg(cd->dev, "%s: max_y = 0x%04zX (%zd)\n", __func__, 671 - si->si_ofs.max_y, si->si_ofs.max_y); 672 - dev_dbg(cd->dev, "%s: y_origin = %zd (%s)\n", __func__, 673 - si->si_ofs.y_origin, 674 - si->si_ofs.y_origin == CY_NORMAL_ORIGIN ? 675 - "upper corner" : "lower corner"); 676 - dev_dbg(cd->dev, "%s: max_p = 0x%04zX (%zd)\n", __func__, 677 - si->si_ofs.max_p, si->si_ofs.max_p); 678 - 679 - dev_dbg(cd->dev, "%s: xy_mode=%p xy_data=%p\n", __func__, 680 - si->xy_mode, si->xy_data); 681 - } 682 - 683 - static int cyttsp4_get_sysinfo_regs(struct cyttsp4 *cd) 684 - { 685 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 686 - int rc; 687 - 688 - rc = cyttsp4_si_data_offsets(cd); 689 - if (rc < 0) 690 - return rc; 691 - 692 - rc = cyttsp4_si_get_cydata(cd); 693 - if (rc < 0) 694 - return rc; 695 - 696 - rc = cyttsp4_si_get_test_data(cd); 697 - if (rc < 0) 698 - return rc; 699 - 700 - rc = cyttsp4_si_get_pcfg_data(cd); 701 - if (rc < 0) 702 - return rc; 703 - 704 - rc = cyttsp4_si_get_opcfg_data(cd); 705 - if (rc < 0) 706 - return rc; 707 - 708 - rc = cyttsp4_si_get_ddata(cd); 709 - if (rc < 0) 710 - return rc; 711 - 712 - rc = cyttsp4_si_get_mdata(cd); 713 - if (rc < 0) 714 - return rc; 715 - 716 - rc = cyttsp4_si_get_btn_data(cd); 717 - if (rc < 0) 718 - return rc; 719 - 720 - rc = cyttsp4_si_get_op_data_ptrs(cd); 721 - if (rc < 0) { 722 - dev_err(cd->dev, "%s: failed to get_op_data\n", 723 - __func__); 724 - return rc; 725 - } 726 - 727 - cyttsp4_si_put_log_data(cd); 728 - 729 - /* provide flow control handshake */ 730 - rc = cyttsp4_handshake(cd, si->si_data.hst_mode); 731 - if (rc < 0) 732 - dev_err(cd->dev, "%s: handshake fail on sysinfo reg\n", 733 - __func__); 734 - 735 - si->ready = true; 736 - return rc; 737 - } 738 - 739 - static void cyttsp4_queue_startup_(struct cyttsp4 *cd) 740 - { 741 - if (cd->startup_state == STARTUP_NONE) { 742 - cd->startup_state = STARTUP_QUEUED; 743 - schedule_work(&cd->startup_work); 744 - dev_dbg(cd->dev, "%s: cyttsp4_startup queued\n", __func__); 745 - } else { 746 - dev_dbg(cd->dev, "%s: startup_state = %d\n", __func__, 747 - cd->startup_state); 748 - } 749 - } 750 - 751 - static void cyttsp4_report_slot_liftoff(struct cyttsp4_mt_data *md, 752 - int max_slots) 753 - { 754 - int t; 755 - 756 - if (md->num_prv_tch == 0) 757 - return; 758 - 759 - for (t = 0; t < max_slots; t++) { 760 - input_mt_slot(md->input, t); 761 - input_mt_report_slot_inactive(md->input); 762 - } 763 - } 764 - 765 - static void cyttsp4_lift_all(struct cyttsp4_mt_data *md) 766 - { 767 - if (!md->si) 768 - return; 769 - 770 - if (md->num_prv_tch != 0) { 771 - cyttsp4_report_slot_liftoff(md, 772 - md->si->si_ofs.tch_abs[CY_TCH_T].max); 773 - input_sync(md->input); 774 - md->num_prv_tch = 0; 775 - } 776 - } 777 - 778 - static void cyttsp4_get_touch_axis(struct cyttsp4_mt_data *md, 779 - int *axis, int size, int max, u8 *xy_data, int bofs) 780 - { 781 - int nbyte; 782 - int next; 783 - 784 - for (nbyte = 0, *axis = 0, next = 0; nbyte < size; nbyte++) { 785 - dev_vdbg(&md->input->dev, 786 - "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p" 787 - " xy_data[%d]=%02X(%d) bofs=%d\n", 788 - __func__, *axis, *axis, size, max, xy_data, next, 789 - xy_data[next], xy_data[next], bofs); 790 - *axis = (*axis * 256) + (xy_data[next] >> bofs); 791 - next++; 792 - } 793 - 794 - *axis &= max - 1; 795 - 796 - dev_vdbg(&md->input->dev, 797 - "%s: *axis=%02X(%d) size=%d max=%08X xy_data=%p" 798 - " xy_data[%d]=%02X(%d)\n", 799 - __func__, *axis, *axis, size, max, xy_data, next, 800 - xy_data[next], xy_data[next]); 801 - } 802 - 803 - static void cyttsp4_get_touch(struct cyttsp4_mt_data *md, 804 - struct cyttsp4_touch *touch, u8 *xy_data) 805 - { 806 - struct device *dev = &md->input->dev; 807 - struct cyttsp4_sysinfo *si = md->si; 808 - enum cyttsp4_tch_abs abs; 809 - bool flipped; 810 - 811 - for (abs = CY_TCH_X; abs < CY_TCH_NUM_ABS; abs++) { 812 - cyttsp4_get_touch_axis(md, &touch->abs[abs], 813 - si->si_ofs.tch_abs[abs].size, 814 - si->si_ofs.tch_abs[abs].max, 815 - xy_data + si->si_ofs.tch_abs[abs].ofs, 816 - si->si_ofs.tch_abs[abs].bofs); 817 - dev_vdbg(dev, "%s: get %s=%04X(%d)\n", __func__, 818 - cyttsp4_tch_abs_string[abs], 819 - touch->abs[abs], touch->abs[abs]); 820 - } 821 - 822 - if (md->pdata->flags & CY_FLAG_FLIP) { 823 - swap(touch->abs[CY_TCH_X], touch->abs[CY_TCH_Y]); 824 - flipped = true; 825 - } else 826 - flipped = false; 827 - 828 - if (md->pdata->flags & CY_FLAG_INV_X) { 829 - if (flipped) 830 - touch->abs[CY_TCH_X] = md->si->si_ofs.max_y - 831 - touch->abs[CY_TCH_X]; 832 - else 833 - touch->abs[CY_TCH_X] = md->si->si_ofs.max_x - 834 - touch->abs[CY_TCH_X]; 835 - } 836 - if (md->pdata->flags & CY_FLAG_INV_Y) { 837 - if (flipped) 838 - touch->abs[CY_TCH_Y] = md->si->si_ofs.max_x - 839 - touch->abs[CY_TCH_Y]; 840 - else 841 - touch->abs[CY_TCH_Y] = md->si->si_ofs.max_y - 842 - touch->abs[CY_TCH_Y]; 843 - } 844 - 845 - dev_vdbg(dev, "%s: flip=%s inv-x=%s inv-y=%s x=%04X(%d) y=%04X(%d)\n", 846 - __func__, flipped ? "true" : "false", 847 - md->pdata->flags & CY_FLAG_INV_X ? "true" : "false", 848 - md->pdata->flags & CY_FLAG_INV_Y ? "true" : "false", 849 - touch->abs[CY_TCH_X], touch->abs[CY_TCH_X], 850 - touch->abs[CY_TCH_Y], touch->abs[CY_TCH_Y]); 851 - } 852 - 853 - static void cyttsp4_final_sync(struct input_dev *input, int max_slots, int *ids) 854 - { 855 - int t; 856 - 857 - for (t = 0; t < max_slots; t++) { 858 - if (ids[t]) 859 - continue; 860 - input_mt_slot(input, t); 861 - input_mt_report_slot_inactive(input); 862 - } 863 - 864 - input_sync(input); 865 - } 866 - 867 - static void cyttsp4_get_mt_touches(struct cyttsp4_mt_data *md, int num_cur_tch) 868 - { 869 - struct device *dev = &md->input->dev; 870 - struct cyttsp4_sysinfo *si = md->si; 871 - struct cyttsp4_touch tch; 872 - int sig; 873 - int i, j, t = 0; 874 - int ids[MAX(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)]; 875 - 876 - memset(ids, 0, si->si_ofs.tch_abs[CY_TCH_T].max * sizeof(int)); 877 - for (i = 0; i < num_cur_tch; i++) { 878 - cyttsp4_get_touch(md, &tch, si->xy_data + 879 - (i * si->si_ofs.tch_rec_size)); 880 - if ((tch.abs[CY_TCH_T] < md->pdata->frmwrk->abs 881 - [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MIN_OST]) || 882 - (tch.abs[CY_TCH_T] > md->pdata->frmwrk->abs 883 - [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MAX_OST])) { 884 - dev_err(dev, "%s: tch=%d -> bad trk_id=%d max_id=%d\n", 885 - __func__, i, tch.abs[CY_TCH_T], 886 - md->pdata->frmwrk->abs[(CY_ABS_ID_OST * 887 - CY_NUM_ABS_SET) + CY_MAX_OST]); 888 - continue; 889 - } 890 - 891 - /* use 0 based track id's */ 892 - sig = md->pdata->frmwrk->abs 893 - [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + 0]; 894 - if (sig != CY_IGNORE_VALUE) { 895 - t = tch.abs[CY_TCH_T] - md->pdata->frmwrk->abs 896 - [(CY_ABS_ID_OST * CY_NUM_ABS_SET) + CY_MIN_OST]; 897 - if (tch.abs[CY_TCH_E] == CY_EV_LIFTOFF) { 898 - dev_dbg(dev, "%s: t=%d e=%d lift-off\n", 899 - __func__, t, tch.abs[CY_TCH_E]); 900 - goto cyttsp4_get_mt_touches_pr_tch; 901 - } 902 - input_mt_slot(md->input, t); 903 - input_mt_report_slot_state(md->input, MT_TOOL_FINGER, 904 - true); 905 - ids[t] = true; 906 - } 907 - 908 - /* all devices: position and pressure fields */ 909 - for (j = 0; j <= CY_ABS_W_OST; j++) { 910 - sig = md->pdata->frmwrk->abs[((CY_ABS_X_OST + j) * 911 - CY_NUM_ABS_SET) + 0]; 912 - if (sig != CY_IGNORE_VALUE) 913 - input_report_abs(md->input, sig, 914 - tch.abs[CY_TCH_X + j]); 915 - } 916 - if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE) { 917 - /* 918 - * TMA400 size and orientation fields: 919 - * if pressure is non-zero and major touch 920 - * signal is zero, then set major and minor touch 921 - * signals to minimum non-zero value 922 - */ 923 - if (tch.abs[CY_TCH_P] > 0 && tch.abs[CY_TCH_MAJ] == 0) 924 - tch.abs[CY_TCH_MAJ] = tch.abs[CY_TCH_MIN] = 1; 925 - 926 - /* Get the extended touch fields */ 927 - for (j = 0; j < CY_NUM_EXT_TCH_FIELDS; j++) { 928 - sig = md->pdata->frmwrk->abs 929 - [((CY_ABS_MAJ_OST + j) * 930 - CY_NUM_ABS_SET) + 0]; 931 - if (sig != CY_IGNORE_VALUE) 932 - input_report_abs(md->input, sig, 933 - tch.abs[CY_TCH_MAJ + j]); 934 - } 935 - } 936 - 937 - cyttsp4_get_mt_touches_pr_tch: 938 - if (si->si_ofs.tch_rec_size > CY_TMA1036_TCH_REC_SIZE) 939 - dev_dbg(dev, 940 - "%s: t=%d x=%d y=%d z=%d M=%d m=%d o=%d e=%d\n", 941 - __func__, t, 942 - tch.abs[CY_TCH_X], 943 - tch.abs[CY_TCH_Y], 944 - tch.abs[CY_TCH_P], 945 - tch.abs[CY_TCH_MAJ], 946 - tch.abs[CY_TCH_MIN], 947 - tch.abs[CY_TCH_OR], 948 - tch.abs[CY_TCH_E]); 949 - else 950 - dev_dbg(dev, 951 - "%s: t=%d x=%d y=%d z=%d e=%d\n", __func__, 952 - t, 953 - tch.abs[CY_TCH_X], 954 - tch.abs[CY_TCH_Y], 955 - tch.abs[CY_TCH_P], 956 - tch.abs[CY_TCH_E]); 957 - } 958 - 959 - cyttsp4_final_sync(md->input, si->si_ofs.tch_abs[CY_TCH_T].max, ids); 960 - 961 - md->num_prv_tch = num_cur_tch; 962 - 963 - return; 964 - } 965 - 966 - /* read xy_data for all current touches */ 967 - static int cyttsp4_xy_worker(struct cyttsp4 *cd) 968 - { 969 - struct cyttsp4_mt_data *md = &cd->md; 970 - struct device *dev = &md->input->dev; 971 - struct cyttsp4_sysinfo *si = md->si; 972 - u8 num_cur_tch; 973 - u8 hst_mode; 974 - u8 rep_len; 975 - u8 rep_stat; 976 - u8 tt_stat; 977 - int rc = 0; 978 - 979 - /* 980 - * Get event data from cyttsp4 device. 981 - * The event data includes all data 982 - * for all active touches. 983 - * Event data also includes button data 984 - */ 985 - /* 986 - * Use 2 reads: 987 - * 1st read to get mode + button bytes + touch count (core) 988 - * 2nd read (optional) to get touch 1 - touch n data 989 - */ 990 - hst_mode = si->xy_mode[CY_REG_BASE]; 991 - rep_len = si->xy_mode[si->si_ofs.rep_ofs]; 992 - rep_stat = si->xy_mode[si->si_ofs.rep_ofs + 1]; 993 - tt_stat = si->xy_mode[si->si_ofs.tt_stat_ofs]; 994 - dev_vdbg(dev, "%s: %s%02X %s%d %s%02X %s%02X\n", __func__, 995 - "hst_mode=", hst_mode, "rep_len=", rep_len, 996 - "rep_stat=", rep_stat, "tt_stat=", tt_stat); 997 - 998 - num_cur_tch = GET_NUM_TOUCHES(tt_stat); 999 - dev_vdbg(dev, "%s: num_cur_tch=%d\n", __func__, num_cur_tch); 1000 - 1001 - if (rep_len == 0 && num_cur_tch > 0) { 1002 - dev_err(dev, "%s: report length error rep_len=%d num_tch=%d\n", 1003 - __func__, rep_len, num_cur_tch); 1004 - goto cyttsp4_xy_worker_exit; 1005 - } 1006 - 1007 - /* read touches */ 1008 - if (num_cur_tch > 0) { 1009 - rc = cyttsp4_adap_read(cd, si->si_ofs.tt_stat_ofs + 1, 1010 - num_cur_tch * si->si_ofs.tch_rec_size, 1011 - si->xy_data); 1012 - if (rc < 0) { 1013 - dev_err(dev, "%s: read fail on touch regs r=%d\n", 1014 - __func__, rc); 1015 - goto cyttsp4_xy_worker_exit; 1016 - } 1017 - } 1018 - 1019 - /* print xy data */ 1020 - cyttsp4_pr_buf(dev, cd->pr_buf, si->xy_data, num_cur_tch * 1021 - si->si_ofs.tch_rec_size, "xy_data"); 1022 - 1023 - /* check any error conditions */ 1024 - if (IS_BAD_PKT(rep_stat)) { 1025 - dev_dbg(dev, "%s: Invalid buffer detected\n", __func__); 1026 - rc = 0; 1027 - goto cyttsp4_xy_worker_exit; 1028 - } 1029 - 1030 - if (IS_LARGE_AREA(tt_stat)) 1031 - dev_dbg(dev, "%s: Large area detected\n", __func__); 1032 - 1033 - if (num_cur_tch > si->si_ofs.max_tchs) { 1034 - dev_err(dev, "%s: too many tch; set to max tch (n=%d c=%zd)\n", 1035 - __func__, num_cur_tch, si->si_ofs.max_tchs); 1036 - num_cur_tch = si->si_ofs.max_tchs; 1037 - } 1038 - 1039 - /* extract xy_data for all currently reported touches */ 1040 - dev_vdbg(dev, "%s: extract data num_cur_tch=%d\n", __func__, 1041 - num_cur_tch); 1042 - if (num_cur_tch) 1043 - cyttsp4_get_mt_touches(md, num_cur_tch); 1044 - else 1045 - cyttsp4_lift_all(md); 1046 - 1047 - rc = 0; 1048 - 1049 - cyttsp4_xy_worker_exit: 1050 - return rc; 1051 - } 1052 - 1053 - static int cyttsp4_mt_attention(struct cyttsp4 *cd) 1054 - { 1055 - struct device *dev = cd->dev; 1056 - struct cyttsp4_mt_data *md = &cd->md; 1057 - int rc = 0; 1058 - 1059 - if (!md->si) 1060 - return 0; 1061 - 1062 - mutex_lock(&md->report_lock); 1063 - if (!md->is_suspended) { 1064 - /* core handles handshake */ 1065 - rc = cyttsp4_xy_worker(cd); 1066 - } else { 1067 - dev_vdbg(dev, "%s: Ignoring report while suspended\n", 1068 - __func__); 1069 - } 1070 - mutex_unlock(&md->report_lock); 1071 - if (rc < 0) 1072 - dev_err(dev, "%s: xy_worker error r=%d\n", __func__, rc); 1073 - 1074 - return rc; 1075 - } 1076 - 1077 - static irqreturn_t cyttsp4_irq(int irq, void *handle) 1078 - { 1079 - struct cyttsp4 *cd = handle; 1080 - struct device *dev = cd->dev; 1081 - enum cyttsp4_mode cur_mode; 1082 - u8 cmd_ofs = cd->sysinfo.si_ofs.cmd_ofs; 1083 - u8 mode[3]; 1084 - int rc; 1085 - 1086 - /* 1087 - * Check whether this IRQ should be ignored (external) 1088 - * This should be the very first thing to check since 1089 - * ignore_irq may be set for a very short period of time 1090 - */ 1091 - if (atomic_read(&cd->ignore_irq)) { 1092 - dev_vdbg(dev, "%s: Ignoring IRQ\n", __func__); 1093 - return IRQ_HANDLED; 1094 - } 1095 - 1096 - dev_dbg(dev, "%s int:0x%x\n", __func__, cd->int_status); 1097 - 1098 - mutex_lock(&cd->system_lock); 1099 - 1100 - /* Just to debug */ 1101 - if (cd->sleep_state == SS_SLEEP_ON || cd->sleep_state == SS_SLEEPING) 1102 - dev_vdbg(dev, "%s: Received IRQ while in sleep\n", __func__); 1103 - 1104 - rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), mode); 1105 - if (rc) { 1106 - dev_err(cd->dev, "%s: Fail read adapter r=%d\n", __func__, rc); 1107 - goto cyttsp4_irq_exit; 1108 - } 1109 - dev_vdbg(dev, "%s mode[0-2]:0x%X 0x%X 0x%X\n", __func__, 1110 - mode[0], mode[1], mode[2]); 1111 - 1112 - if (IS_BOOTLOADER(mode[0], mode[1])) { 1113 - cur_mode = CY_MODE_BOOTLOADER; 1114 - dev_vdbg(dev, "%s: bl running\n", __func__); 1115 - if (cd->mode == CY_MODE_BOOTLOADER) { 1116 - /* Signal bootloader heartbeat heard */ 1117 - wake_up(&cd->wait_q); 1118 - goto cyttsp4_irq_exit; 1119 - } 1120 - 1121 - /* switch to bootloader */ 1122 - dev_dbg(dev, "%s: restart switch to bl m=%d -> m=%d\n", 1123 - __func__, cd->mode, cur_mode); 1124 - 1125 - /* catch operation->bl glitch */ 1126 - if (cd->mode != CY_MODE_UNKNOWN) { 1127 - /* Incase startup_state do not let startup_() */ 1128 - cd->mode = CY_MODE_UNKNOWN; 1129 - cyttsp4_queue_startup_(cd); 1130 - goto cyttsp4_irq_exit; 1131 - } 1132 - 1133 - /* 1134 - * do not wake thread on this switch since 1135 - * it is possible to get an early heartbeat 1136 - * prior to performing the reset 1137 - */ 1138 - cd->mode = cur_mode; 1139 - 1140 - goto cyttsp4_irq_exit; 1141 - } 1142 - 1143 - switch (mode[0] & CY_HST_MODE) { 1144 - case CY_HST_OPERATE: 1145 - cur_mode = CY_MODE_OPERATIONAL; 1146 - dev_vdbg(dev, "%s: operational\n", __func__); 1147 - break; 1148 - case CY_HST_CAT: 1149 - cur_mode = CY_MODE_CAT; 1150 - dev_vdbg(dev, "%s: CaT\n", __func__); 1151 - break; 1152 - case CY_HST_SYSINFO: 1153 - cur_mode = CY_MODE_SYSINFO; 1154 - dev_vdbg(dev, "%s: sysinfo\n", __func__); 1155 - break; 1156 - default: 1157 - cur_mode = CY_MODE_UNKNOWN; 1158 - dev_err(dev, "%s: unknown HST mode 0x%02X\n", __func__, 1159 - mode[0]); 1160 - break; 1161 - } 1162 - 1163 - /* Check whether this IRQ should be ignored (internal) */ 1164 - if (cd->int_status & CY_INT_IGNORE) { 1165 - dev_vdbg(dev, "%s: Ignoring IRQ\n", __func__); 1166 - goto cyttsp4_irq_exit; 1167 - } 1168 - 1169 - /* Check for wake up interrupt */ 1170 - if (cd->int_status & CY_INT_AWAKE) { 1171 - cd->int_status &= ~CY_INT_AWAKE; 1172 - wake_up(&cd->wait_q); 1173 - dev_vdbg(dev, "%s: Received wake up interrupt\n", __func__); 1174 - goto cyttsp4_irq_handshake; 1175 - } 1176 - 1177 - /* Expecting mode change interrupt */ 1178 - if ((cd->int_status & CY_INT_MODE_CHANGE) 1179 - && (mode[0] & CY_HST_MODE_CHANGE) == 0) { 1180 - cd->int_status &= ~CY_INT_MODE_CHANGE; 1181 - dev_dbg(dev, "%s: finish mode switch m=%d -> m=%d\n", 1182 - __func__, cd->mode, cur_mode); 1183 - cd->mode = cur_mode; 1184 - wake_up(&cd->wait_q); 1185 - goto cyttsp4_irq_handshake; 1186 - } 1187 - 1188 - /* compare current core mode to current device mode */ 1189 - dev_vdbg(dev, "%s: cd->mode=%d cur_mode=%d\n", 1190 - __func__, cd->mode, cur_mode); 1191 - if ((mode[0] & CY_HST_MODE_CHANGE) == 0 && cd->mode != cur_mode) { 1192 - /* Unexpected mode change occurred */ 1193 - dev_err(dev, "%s %d->%d 0x%x\n", __func__, cd->mode, 1194 - cur_mode, cd->int_status); 1195 - dev_dbg(dev, "%s: Unexpected mode change, startup\n", 1196 - __func__); 1197 - cyttsp4_queue_startup_(cd); 1198 - goto cyttsp4_irq_exit; 1199 - } 1200 - 1201 - /* Expecting command complete interrupt */ 1202 - dev_vdbg(dev, "%s: command byte:0x%x\n", __func__, mode[cmd_ofs]); 1203 - if ((cd->int_status & CY_INT_EXEC_CMD) 1204 - && mode[cmd_ofs] & CY_CMD_COMPLETE) { 1205 - cd->int_status &= ~CY_INT_EXEC_CMD; 1206 - dev_vdbg(dev, "%s: Received command complete interrupt\n", 1207 - __func__); 1208 - wake_up(&cd->wait_q); 1209 - /* 1210 - * It is possible to receive a single interrupt for 1211 - * command complete and touch/button status report. 1212 - * Continue processing for a possible status report. 1213 - */ 1214 - } 1215 - 1216 - /* This should be status report, read status regs */ 1217 - if (cd->mode == CY_MODE_OPERATIONAL) { 1218 - dev_vdbg(dev, "%s: Read status registers\n", __func__); 1219 - rc = cyttsp4_load_status_regs(cd); 1220 - if (rc < 0) 1221 - dev_err(dev, "%s: fail read mode regs r=%d\n", 1222 - __func__, rc); 1223 - } 1224 - 1225 - cyttsp4_mt_attention(cd); 1226 - 1227 - cyttsp4_irq_handshake: 1228 - /* handshake the event */ 1229 - dev_vdbg(dev, "%s: Handshake mode=0x%02X r=%d\n", 1230 - __func__, mode[0], rc); 1231 - rc = cyttsp4_handshake(cd, mode[0]); 1232 - if (rc < 0) 1233 - dev_err(dev, "%s: Fail handshake mode=0x%02X r=%d\n", 1234 - __func__, mode[0], rc); 1235 - 1236 - /* 1237 - * a non-zero udelay period is required for using 1238 - * IRQF_TRIGGER_LOW in order to delay until the 1239 - * device completes isr deassert 1240 - */ 1241 - udelay(cd->cpdata->level_irq_udelay); 1242 - 1243 - cyttsp4_irq_exit: 1244 - mutex_unlock(&cd->system_lock); 1245 - return IRQ_HANDLED; 1246 - } 1247 - 1248 - static void cyttsp4_start_wd_timer(struct cyttsp4 *cd) 1249 - { 1250 - if (!CY_WATCHDOG_TIMEOUT) 1251 - return; 1252 - 1253 - mod_timer(&cd->watchdog_timer, jiffies + 1254 - msecs_to_jiffies(CY_WATCHDOG_TIMEOUT)); 1255 - } 1256 - 1257 - static void cyttsp4_stop_wd_timer(struct cyttsp4 *cd) 1258 - { 1259 - if (!CY_WATCHDOG_TIMEOUT) 1260 - return; 1261 - 1262 - /* 1263 - * Ensure we wait until the watchdog timer 1264 - * running on a different CPU finishes 1265 - */ 1266 - timer_shutdown_sync(&cd->watchdog_timer); 1267 - cancel_work_sync(&cd->watchdog_work); 1268 - } 1269 - 1270 - static void cyttsp4_watchdog_timer(struct timer_list *t) 1271 - { 1272 - struct cyttsp4 *cd = from_timer(cd, t, watchdog_timer); 1273 - 1274 - dev_vdbg(cd->dev, "%s: Watchdog timer triggered\n", __func__); 1275 - 1276 - schedule_work(&cd->watchdog_work); 1277 - 1278 - return; 1279 - } 1280 - 1281 - static int cyttsp4_request_exclusive(struct cyttsp4 *cd, void *ownptr, 1282 - int timeout_ms) 1283 - { 1284 - int t = msecs_to_jiffies(timeout_ms); 1285 - bool with_timeout = (timeout_ms != 0); 1286 - 1287 - mutex_lock(&cd->system_lock); 1288 - if (!cd->exclusive_dev && cd->exclusive_waits == 0) { 1289 - cd->exclusive_dev = ownptr; 1290 - goto exit; 1291 - } 1292 - 1293 - cd->exclusive_waits++; 1294 - wait: 1295 - mutex_unlock(&cd->system_lock); 1296 - if (with_timeout) { 1297 - t = wait_event_timeout(cd->wait_q, !cd->exclusive_dev, t); 1298 - if (IS_TMO(t)) { 1299 - dev_err(cd->dev, "%s: tmo waiting exclusive access\n", 1300 - __func__); 1301 - mutex_lock(&cd->system_lock); 1302 - cd->exclusive_waits--; 1303 - mutex_unlock(&cd->system_lock); 1304 - return -ETIME; 1305 - } 1306 - } else { 1307 - wait_event(cd->wait_q, !cd->exclusive_dev); 1308 - } 1309 - mutex_lock(&cd->system_lock); 1310 - if (cd->exclusive_dev) 1311 - goto wait; 1312 - cd->exclusive_dev = ownptr; 1313 - cd->exclusive_waits--; 1314 - exit: 1315 - mutex_unlock(&cd->system_lock); 1316 - 1317 - return 0; 1318 - } 1319 - 1320 - /* 1321 - * returns error if was not owned 1322 - */ 1323 - static int cyttsp4_release_exclusive(struct cyttsp4 *cd, void *ownptr) 1324 - { 1325 - mutex_lock(&cd->system_lock); 1326 - if (cd->exclusive_dev != ownptr) { 1327 - mutex_unlock(&cd->system_lock); 1328 - return -EINVAL; 1329 - } 1330 - 1331 - dev_vdbg(cd->dev, "%s: exclusive_dev %p freed\n", 1332 - __func__, cd->exclusive_dev); 1333 - cd->exclusive_dev = NULL; 1334 - wake_up(&cd->wait_q); 1335 - mutex_unlock(&cd->system_lock); 1336 - return 0; 1337 - } 1338 - 1339 - static int cyttsp4_wait_bl_heartbeat(struct cyttsp4 *cd) 1340 - { 1341 - long t; 1342 - int rc = 0; 1343 - 1344 - /* wait heartbeat */ 1345 - dev_vdbg(cd->dev, "%s: wait heartbeat...\n", __func__); 1346 - t = wait_event_timeout(cd->wait_q, cd->mode == CY_MODE_BOOTLOADER, 1347 - msecs_to_jiffies(CY_CORE_RESET_AND_WAIT_TIMEOUT)); 1348 - if (IS_TMO(t)) { 1349 - dev_err(cd->dev, "%s: tmo waiting bl heartbeat cd->mode=%d\n", 1350 - __func__, cd->mode); 1351 - rc = -ETIME; 1352 - } 1353 - 1354 - return rc; 1355 - } 1356 - 1357 - static int cyttsp4_wait_sysinfo_mode(struct cyttsp4 *cd) 1358 - { 1359 - long t; 1360 - 1361 - dev_vdbg(cd->dev, "%s: wait sysinfo...\n", __func__); 1362 - 1363 - t = wait_event_timeout(cd->wait_q, cd->mode == CY_MODE_SYSINFO, 1364 - msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT)); 1365 - if (IS_TMO(t)) { 1366 - dev_err(cd->dev, "%s: tmo waiting exit bl cd->mode=%d\n", 1367 - __func__, cd->mode); 1368 - mutex_lock(&cd->system_lock); 1369 - cd->int_status &= ~CY_INT_MODE_CHANGE; 1370 - mutex_unlock(&cd->system_lock); 1371 - return -ETIME; 1372 - } 1373 - 1374 - return 0; 1375 - } 1376 - 1377 - static int cyttsp4_reset_and_wait(struct cyttsp4 *cd) 1378 - { 1379 - int rc; 1380 - 1381 - /* reset hardware */ 1382 - mutex_lock(&cd->system_lock); 1383 - dev_dbg(cd->dev, "%s: reset hw...\n", __func__); 1384 - rc = cyttsp4_hw_reset(cd); 1385 - cd->mode = CY_MODE_UNKNOWN; 1386 - mutex_unlock(&cd->system_lock); 1387 - if (rc < 0) { 1388 - dev_err(cd->dev, "%s:Fail hw reset r=%d\n", __func__, rc); 1389 - return rc; 1390 - } 1391 - 1392 - return cyttsp4_wait_bl_heartbeat(cd); 1393 - } 1394 - 1395 - /* 1396 - * returns err if refused or timeout; block until mode change complete 1397 - * bit is set (mode change interrupt) 1398 - */ 1399 - static int cyttsp4_set_mode(struct cyttsp4 *cd, int new_mode) 1400 - { 1401 - u8 new_dev_mode; 1402 - u8 mode; 1403 - long t; 1404 - int rc; 1405 - 1406 - switch (new_mode) { 1407 - case CY_MODE_OPERATIONAL: 1408 - new_dev_mode = CY_HST_OPERATE; 1409 - break; 1410 - case CY_MODE_SYSINFO: 1411 - new_dev_mode = CY_HST_SYSINFO; 1412 - break; 1413 - case CY_MODE_CAT: 1414 - new_dev_mode = CY_HST_CAT; 1415 - break; 1416 - default: 1417 - dev_err(cd->dev, "%s: invalid mode: %02X(%d)\n", 1418 - __func__, new_mode, new_mode); 1419 - return -EINVAL; 1420 - } 1421 - 1422 - /* change mode */ 1423 - dev_dbg(cd->dev, "%s: %s=%p new_dev_mode=%02X new_mode=%d\n", 1424 - __func__, "have exclusive", cd->exclusive_dev, 1425 - new_dev_mode, new_mode); 1426 - 1427 - mutex_lock(&cd->system_lock); 1428 - rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode); 1429 - if (rc < 0) { 1430 - mutex_unlock(&cd->system_lock); 1431 - dev_err(cd->dev, "%s: Fail read mode r=%d\n", 1432 - __func__, rc); 1433 - goto exit; 1434 - } 1435 - 1436 - /* Clear device mode bits and set to new mode */ 1437 - mode &= ~CY_HST_MODE; 1438 - mode |= new_dev_mode | CY_HST_MODE_CHANGE; 1439 - 1440 - cd->int_status |= CY_INT_MODE_CHANGE; 1441 - rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(mode), &mode); 1442 - mutex_unlock(&cd->system_lock); 1443 - if (rc < 0) { 1444 - dev_err(cd->dev, "%s: Fail write mode change r=%d\n", 1445 - __func__, rc); 1446 - goto exit; 1447 - } 1448 - 1449 - /* wait for mode change done interrupt */ 1450 - t = wait_event_timeout(cd->wait_q, 1451 - (cd->int_status & CY_INT_MODE_CHANGE) == 0, 1452 - msecs_to_jiffies(CY_CORE_MODE_CHANGE_TIMEOUT)); 1453 - dev_dbg(cd->dev, "%s: back from wait t=%ld cd->mode=%d\n", 1454 - __func__, t, cd->mode); 1455 - 1456 - if (IS_TMO(t)) { 1457 - dev_err(cd->dev, "%s: %s\n", __func__, 1458 - "tmo waiting mode change"); 1459 - mutex_lock(&cd->system_lock); 1460 - cd->int_status &= ~CY_INT_MODE_CHANGE; 1461 - mutex_unlock(&cd->system_lock); 1462 - rc = -EINVAL; 1463 - } 1464 - 1465 - exit: 1466 - return rc; 1467 - } 1468 - 1469 - static void cyttsp4_watchdog_work(struct work_struct *work) 1470 - { 1471 - struct cyttsp4 *cd = 1472 - container_of(work, struct cyttsp4, watchdog_work); 1473 - u8 *mode; 1474 - int retval; 1475 - 1476 - mutex_lock(&cd->system_lock); 1477 - retval = cyttsp4_load_status_regs(cd); 1478 - if (retval < 0) { 1479 - dev_err(cd->dev, 1480 - "%s: failed to access device in watchdog timer r=%d\n", 1481 - __func__, retval); 1482 - cyttsp4_queue_startup_(cd); 1483 - goto cyttsp4_timer_watchdog_exit_error; 1484 - } 1485 - mode = &cd->sysinfo.xy_mode[CY_REG_BASE]; 1486 - if (IS_BOOTLOADER(mode[0], mode[1])) { 1487 - dev_err(cd->dev, 1488 - "%s: device found in bootloader mode when operational mode\n", 1489 - __func__); 1490 - cyttsp4_queue_startup_(cd); 1491 - goto cyttsp4_timer_watchdog_exit_error; 1492 - } 1493 - 1494 - cyttsp4_start_wd_timer(cd); 1495 - cyttsp4_timer_watchdog_exit_error: 1496 - mutex_unlock(&cd->system_lock); 1497 - return; 1498 - } 1499 - 1500 - static int cyttsp4_core_sleep_(struct cyttsp4 *cd) 1501 - { 1502 - enum cyttsp4_sleep_state ss = SS_SLEEP_ON; 1503 - enum cyttsp4_int_state int_status = CY_INT_IGNORE; 1504 - int rc = 0; 1505 - u8 mode[2]; 1506 - 1507 - /* Already in sleep mode? */ 1508 - mutex_lock(&cd->system_lock); 1509 - if (cd->sleep_state == SS_SLEEP_ON) { 1510 - mutex_unlock(&cd->system_lock); 1511 - return 0; 1512 - } 1513 - cd->sleep_state = SS_SLEEPING; 1514 - mutex_unlock(&cd->system_lock); 1515 - 1516 - cyttsp4_stop_wd_timer(cd); 1517 - 1518 - /* Wait until currently running IRQ handler exits and disable IRQ */ 1519 - disable_irq(cd->irq); 1520 - 1521 - dev_vdbg(cd->dev, "%s: write DEEP SLEEP...\n", __func__); 1522 - mutex_lock(&cd->system_lock); 1523 - rc = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode); 1524 - if (rc) { 1525 - mutex_unlock(&cd->system_lock); 1526 - dev_err(cd->dev, "%s: Fail read adapter r=%d\n", __func__, rc); 1527 - goto error; 1528 - } 1529 - 1530 - if (IS_BOOTLOADER(mode[0], mode[1])) { 1531 - mutex_unlock(&cd->system_lock); 1532 - dev_err(cd->dev, "%s: Device in BOOTLOADER mode.\n", __func__); 1533 - rc = -EINVAL; 1534 - goto error; 1535 - } 1536 - 1537 - mode[0] |= CY_HST_SLEEP; 1538 - rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(mode[0]), &mode[0]); 1539 - mutex_unlock(&cd->system_lock); 1540 - if (rc) { 1541 - dev_err(cd->dev, "%s: Fail write adapter r=%d\n", __func__, rc); 1542 - goto error; 1543 - } 1544 - dev_vdbg(cd->dev, "%s: write DEEP SLEEP succeeded\n", __func__); 1545 - 1546 - if (cd->cpdata->power) { 1547 - dev_dbg(cd->dev, "%s: Power down HW\n", __func__); 1548 - rc = cd->cpdata->power(cd->cpdata, 0, cd->dev, &cd->ignore_irq); 1549 - } else { 1550 - dev_dbg(cd->dev, "%s: No power function\n", __func__); 1551 - rc = 0; 1552 - } 1553 - if (rc < 0) { 1554 - dev_err(cd->dev, "%s: HW Power down fails r=%d\n", 1555 - __func__, rc); 1556 - goto error; 1557 - } 1558 - 1559 - /* Give time to FW to sleep */ 1560 - msleep(50); 1561 - 1562 - goto exit; 1563 - 1564 - error: 1565 - ss = SS_SLEEP_OFF; 1566 - int_status = CY_INT_NONE; 1567 - cyttsp4_start_wd_timer(cd); 1568 - 1569 - exit: 1570 - mutex_lock(&cd->system_lock); 1571 - cd->sleep_state = ss; 1572 - cd->int_status |= int_status; 1573 - mutex_unlock(&cd->system_lock); 1574 - enable_irq(cd->irq); 1575 - return rc; 1576 - } 1577 - 1578 - static int cyttsp4_startup_(struct cyttsp4 *cd) 1579 - { 1580 - int retry = CY_CORE_STARTUP_RETRY_COUNT; 1581 - int rc; 1582 - 1583 - cyttsp4_stop_wd_timer(cd); 1584 - 1585 - reset: 1586 - if (retry != CY_CORE_STARTUP_RETRY_COUNT) 1587 - dev_dbg(cd->dev, "%s: Retry %d\n", __func__, 1588 - CY_CORE_STARTUP_RETRY_COUNT - retry); 1589 - 1590 - /* reset hardware and wait for heartbeat */ 1591 - rc = cyttsp4_reset_and_wait(cd); 1592 - if (rc < 0) { 1593 - dev_err(cd->dev, "%s: Error on h/w reset r=%d\n", __func__, rc); 1594 - if (retry--) 1595 - goto reset; 1596 - goto exit; 1597 - } 1598 - 1599 - /* exit bl into sysinfo mode */ 1600 - dev_vdbg(cd->dev, "%s: write exit ldr...\n", __func__); 1601 - mutex_lock(&cd->system_lock); 1602 - cd->int_status &= ~CY_INT_IGNORE; 1603 - cd->int_status |= CY_INT_MODE_CHANGE; 1604 - 1605 - rc = cyttsp4_adap_write(cd, CY_REG_BASE, sizeof(ldr_exit), 1606 - (u8 *)ldr_exit); 1607 - mutex_unlock(&cd->system_lock); 1608 - if (rc < 0) { 1609 - dev_err(cd->dev, "%s: Fail write r=%d\n", __func__, rc); 1610 - if (retry--) 1611 - goto reset; 1612 - goto exit; 1613 - } 1614 - 1615 - rc = cyttsp4_wait_sysinfo_mode(cd); 1616 - if (rc < 0) { 1617 - u8 buf[sizeof(ldr_err_app)]; 1618 - int rc1; 1619 - 1620 - /* Check for invalid/corrupted touch application */ 1621 - rc1 = cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(ldr_err_app), 1622 - buf); 1623 - if (rc1) { 1624 - dev_err(cd->dev, "%s: Fail read r=%d\n", __func__, rc1); 1625 - } else if (!memcmp(buf, ldr_err_app, sizeof(ldr_err_app))) { 1626 - dev_err(cd->dev, "%s: Error launching touch application\n", 1627 - __func__); 1628 - mutex_lock(&cd->system_lock); 1629 - cd->invalid_touch_app = true; 1630 - mutex_unlock(&cd->system_lock); 1631 - goto exit_no_wd; 1632 - } 1633 - 1634 - if (retry--) 1635 - goto reset; 1636 - goto exit; 1637 - } 1638 - 1639 - mutex_lock(&cd->system_lock); 1640 - cd->invalid_touch_app = false; 1641 - mutex_unlock(&cd->system_lock); 1642 - 1643 - /* read sysinfo data */ 1644 - dev_vdbg(cd->dev, "%s: get sysinfo regs..\n", __func__); 1645 - rc = cyttsp4_get_sysinfo_regs(cd); 1646 - if (rc < 0) { 1647 - dev_err(cd->dev, "%s: failed to get sysinfo regs rc=%d\n", 1648 - __func__, rc); 1649 - if (retry--) 1650 - goto reset; 1651 - goto exit; 1652 - } 1653 - 1654 - rc = cyttsp4_set_mode(cd, CY_MODE_OPERATIONAL); 1655 - if (rc < 0) { 1656 - dev_err(cd->dev, "%s: failed to set mode to operational rc=%d\n", 1657 - __func__, rc); 1658 - if (retry--) 1659 - goto reset; 1660 - goto exit; 1661 - } 1662 - 1663 - cyttsp4_lift_all(&cd->md); 1664 - 1665 - /* restore to sleep if was suspended */ 1666 - mutex_lock(&cd->system_lock); 1667 - if (cd->sleep_state == SS_SLEEP_ON) { 1668 - cd->sleep_state = SS_SLEEP_OFF; 1669 - mutex_unlock(&cd->system_lock); 1670 - cyttsp4_core_sleep_(cd); 1671 - goto exit_no_wd; 1672 - } 1673 - mutex_unlock(&cd->system_lock); 1674 - 1675 - exit: 1676 - cyttsp4_start_wd_timer(cd); 1677 - exit_no_wd: 1678 - return rc; 1679 - } 1680 - 1681 - static int cyttsp4_startup(struct cyttsp4 *cd) 1682 - { 1683 - int rc; 1684 - 1685 - mutex_lock(&cd->system_lock); 1686 - cd->startup_state = STARTUP_RUNNING; 1687 - mutex_unlock(&cd->system_lock); 1688 - 1689 - rc = cyttsp4_request_exclusive(cd, cd->dev, 1690 - CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT); 1691 - if (rc < 0) { 1692 - dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n", 1693 - __func__, cd->exclusive_dev, cd->dev); 1694 - goto exit; 1695 - } 1696 - 1697 - rc = cyttsp4_startup_(cd); 1698 - 1699 - if (cyttsp4_release_exclusive(cd, cd->dev) < 0) 1700 - /* Don't return fail code, mode is already changed. */ 1701 - dev_err(cd->dev, "%s: fail to release exclusive\n", __func__); 1702 - else 1703 - dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__); 1704 - 1705 - exit: 1706 - mutex_lock(&cd->system_lock); 1707 - cd->startup_state = STARTUP_NONE; 1708 - mutex_unlock(&cd->system_lock); 1709 - 1710 - /* Wake the waiters for end of startup */ 1711 - wake_up(&cd->wait_q); 1712 - 1713 - return rc; 1714 - } 1715 - 1716 - static void cyttsp4_startup_work_function(struct work_struct *work) 1717 - { 1718 - struct cyttsp4 *cd = container_of(work, struct cyttsp4, startup_work); 1719 - int rc; 1720 - 1721 - rc = cyttsp4_startup(cd); 1722 - if (rc < 0) 1723 - dev_err(cd->dev, "%s: Fail queued startup r=%d\n", 1724 - __func__, rc); 1725 - } 1726 - 1727 - static void cyttsp4_free_si_ptrs(struct cyttsp4 *cd) 1728 - { 1729 - struct cyttsp4_sysinfo *si = &cd->sysinfo; 1730 - 1731 - if (!si) 1732 - return; 1733 - 1734 - kfree(si->si_ptrs.cydata); 1735 - kfree(si->si_ptrs.test); 1736 - kfree(si->si_ptrs.pcfg); 1737 - kfree(si->si_ptrs.opcfg); 1738 - kfree(si->si_ptrs.ddata); 1739 - kfree(si->si_ptrs.mdata); 1740 - kfree(si->btn); 1741 - kfree(si->xy_mode); 1742 - kfree(si->xy_data); 1743 - kfree(si->btn_rec_data); 1744 - } 1745 - 1746 - static int cyttsp4_core_sleep(struct cyttsp4 *cd) 1747 - { 1748 - int rc; 1749 - 1750 - rc = cyttsp4_request_exclusive(cd, cd->dev, 1751 - CY_CORE_SLEEP_REQUEST_EXCLUSIVE_TIMEOUT); 1752 - if (rc < 0) { 1753 - dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n", 1754 - __func__, cd->exclusive_dev, cd->dev); 1755 - return 0; 1756 - } 1757 - 1758 - rc = cyttsp4_core_sleep_(cd); 1759 - 1760 - if (cyttsp4_release_exclusive(cd, cd->dev) < 0) 1761 - dev_err(cd->dev, "%s: fail to release exclusive\n", __func__); 1762 - else 1763 - dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__); 1764 - 1765 - return rc; 1766 - } 1767 - 1768 - static int cyttsp4_core_wake_(struct cyttsp4 *cd) 1769 - { 1770 - struct device *dev = cd->dev; 1771 - int rc; 1772 - u8 mode; 1773 - int t; 1774 - 1775 - /* Already woken? */ 1776 - mutex_lock(&cd->system_lock); 1777 - if (cd->sleep_state == SS_SLEEP_OFF) { 1778 - mutex_unlock(&cd->system_lock); 1779 - return 0; 1780 - } 1781 - cd->int_status &= ~CY_INT_IGNORE; 1782 - cd->int_status |= CY_INT_AWAKE; 1783 - cd->sleep_state = SS_WAKING; 1784 - 1785 - if (cd->cpdata->power) { 1786 - dev_dbg(dev, "%s: Power up HW\n", __func__); 1787 - rc = cd->cpdata->power(cd->cpdata, 1, dev, &cd->ignore_irq); 1788 - } else { 1789 - dev_dbg(dev, "%s: No power function\n", __func__); 1790 - rc = -ENOSYS; 1791 - } 1792 - if (rc < 0) { 1793 - dev_err(dev, "%s: HW Power up fails r=%d\n", 1794 - __func__, rc); 1795 - 1796 - /* Initiate a read transaction to wake up */ 1797 - cyttsp4_adap_read(cd, CY_REG_BASE, sizeof(mode), &mode); 1798 - } else 1799 - dev_vdbg(cd->dev, "%s: HW power up succeeds\n", 1800 - __func__); 1801 - mutex_unlock(&cd->system_lock); 1802 - 1803 - t = wait_event_timeout(cd->wait_q, 1804 - (cd->int_status & CY_INT_AWAKE) == 0, 1805 - msecs_to_jiffies(CY_CORE_WAKEUP_TIMEOUT)); 1806 - if (IS_TMO(t)) { 1807 - dev_err(dev, "%s: TMO waiting for wakeup\n", __func__); 1808 - mutex_lock(&cd->system_lock); 1809 - cd->int_status &= ~CY_INT_AWAKE; 1810 - /* Try starting up */ 1811 - cyttsp4_queue_startup_(cd); 1812 - mutex_unlock(&cd->system_lock); 1813 - } 1814 - 1815 - mutex_lock(&cd->system_lock); 1816 - cd->sleep_state = SS_SLEEP_OFF; 1817 - mutex_unlock(&cd->system_lock); 1818 - 1819 - cyttsp4_start_wd_timer(cd); 1820 - 1821 - return 0; 1822 - } 1823 - 1824 - static int cyttsp4_core_wake(struct cyttsp4 *cd) 1825 - { 1826 - int rc; 1827 - 1828 - rc = cyttsp4_request_exclusive(cd, cd->dev, 1829 - CY_CORE_REQUEST_EXCLUSIVE_TIMEOUT); 1830 - if (rc < 0) { 1831 - dev_err(cd->dev, "%s: fail get exclusive ex=%p own=%p\n", 1832 - __func__, cd->exclusive_dev, cd->dev); 1833 - return 0; 1834 - } 1835 - 1836 - rc = cyttsp4_core_wake_(cd); 1837 - 1838 - if (cyttsp4_release_exclusive(cd, cd->dev) < 0) 1839 - dev_err(cd->dev, "%s: fail to release exclusive\n", __func__); 1840 - else 1841 - dev_vdbg(cd->dev, "%s: pass release exclusive\n", __func__); 1842 - 1843 - return rc; 1844 - } 1845 - 1846 - static int cyttsp4_core_suspend(struct device *dev) 1847 - { 1848 - struct cyttsp4 *cd = dev_get_drvdata(dev); 1849 - struct cyttsp4_mt_data *md = &cd->md; 1850 - int rc; 1851 - 1852 - md->is_suspended = true; 1853 - 1854 - rc = cyttsp4_core_sleep(cd); 1855 - if (rc < 0) { 1856 - dev_err(dev, "%s: Error on sleep\n", __func__); 1857 - return -EAGAIN; 1858 - } 1859 - return 0; 1860 - } 1861 - 1862 - static int cyttsp4_core_resume(struct device *dev) 1863 - { 1864 - struct cyttsp4 *cd = dev_get_drvdata(dev); 1865 - struct cyttsp4_mt_data *md = &cd->md; 1866 - int rc; 1867 - 1868 - md->is_suspended = false; 1869 - 1870 - rc = cyttsp4_core_wake(cd); 1871 - if (rc < 0) { 1872 - dev_err(dev, "%s: Error on wake\n", __func__); 1873 - return -EAGAIN; 1874 - } 1875 - 1876 - return 0; 1877 - } 1878 - 1879 - EXPORT_GPL_RUNTIME_DEV_PM_OPS(cyttsp4_pm_ops, 1880 - cyttsp4_core_suspend, cyttsp4_core_resume, NULL); 1881 - 1882 - static int cyttsp4_mt_open(struct input_dev *input) 1883 - { 1884 - pm_runtime_get(input->dev.parent); 1885 - return 0; 1886 - } 1887 - 1888 - static void cyttsp4_mt_close(struct input_dev *input) 1889 - { 1890 - struct cyttsp4_mt_data *md = input_get_drvdata(input); 1891 - mutex_lock(&md->report_lock); 1892 - if (!md->is_suspended) 1893 - pm_runtime_put(input->dev.parent); 1894 - mutex_unlock(&md->report_lock); 1895 - } 1896 - 1897 - 1898 - static int cyttsp4_setup_input_device(struct cyttsp4 *cd) 1899 - { 1900 - struct device *dev = cd->dev; 1901 - struct cyttsp4_mt_data *md = &cd->md; 1902 - int signal = CY_IGNORE_VALUE; 1903 - int max_x, max_y, max_p, min, max; 1904 - int max_x_tmp, max_y_tmp; 1905 - int i; 1906 - int rc; 1907 - 1908 - dev_vdbg(dev, "%s: Initialize event signals\n", __func__); 1909 - __set_bit(EV_ABS, md->input->evbit); 1910 - __set_bit(EV_REL, md->input->evbit); 1911 - __set_bit(EV_KEY, md->input->evbit); 1912 - 1913 - max_x_tmp = md->si->si_ofs.max_x; 1914 - max_y_tmp = md->si->si_ofs.max_y; 1915 - 1916 - /* get maximum values from the sysinfo data */ 1917 - if (md->pdata->flags & CY_FLAG_FLIP) { 1918 - max_x = max_y_tmp - 1; 1919 - max_y = max_x_tmp - 1; 1920 - } else { 1921 - max_x = max_x_tmp - 1; 1922 - max_y = max_y_tmp - 1; 1923 - } 1924 - max_p = md->si->si_ofs.max_p; 1925 - 1926 - /* set event signal capabilities */ 1927 - for (i = 0; i < (md->pdata->frmwrk->size / CY_NUM_ABS_SET); i++) { 1928 - signal = md->pdata->frmwrk->abs 1929 - [(i * CY_NUM_ABS_SET) + CY_SIGNAL_OST]; 1930 - if (signal != CY_IGNORE_VALUE) { 1931 - __set_bit(signal, md->input->absbit); 1932 - min = md->pdata->frmwrk->abs 1933 - [(i * CY_NUM_ABS_SET) + CY_MIN_OST]; 1934 - max = md->pdata->frmwrk->abs 1935 - [(i * CY_NUM_ABS_SET) + CY_MAX_OST]; 1936 - if (i == CY_ABS_ID_OST) { 1937 - /* shift track ids down to start at 0 */ 1938 - max = max - min; 1939 - min = min - min; 1940 - } else if (i == CY_ABS_X_OST) 1941 - max = max_x; 1942 - else if (i == CY_ABS_Y_OST) 1943 - max = max_y; 1944 - else if (i == CY_ABS_P_OST) 1945 - max = max_p; 1946 - input_set_abs_params(md->input, signal, min, max, 1947 - md->pdata->frmwrk->abs 1948 - [(i * CY_NUM_ABS_SET) + CY_FUZZ_OST], 1949 - md->pdata->frmwrk->abs 1950 - [(i * CY_NUM_ABS_SET) + CY_FLAT_OST]); 1951 - dev_dbg(dev, "%s: register signal=%02X min=%d max=%d\n", 1952 - __func__, signal, min, max); 1953 - if ((i == CY_ABS_ID_OST) && 1954 - (md->si->si_ofs.tch_rec_size < 1955 - CY_TMA4XX_TCH_REC_SIZE)) 1956 - break; 1957 - } 1958 - } 1959 - 1960 - input_mt_init_slots(md->input, md->si->si_ofs.tch_abs[CY_TCH_T].max, 1961 - INPUT_MT_DIRECT); 1962 - rc = input_register_device(md->input); 1963 - if (rc < 0) 1964 - dev_err(dev, "%s: Error, failed register input device r=%d\n", 1965 - __func__, rc); 1966 - return rc; 1967 - } 1968 - 1969 - static int cyttsp4_mt_probe(struct cyttsp4 *cd) 1970 - { 1971 - struct device *dev = cd->dev; 1972 - struct cyttsp4_mt_data *md = &cd->md; 1973 - struct cyttsp4_mt_platform_data *pdata = cd->pdata->mt_pdata; 1974 - int rc = 0; 1975 - 1976 - mutex_init(&md->report_lock); 1977 - md->pdata = pdata; 1978 - /* Create the input device and register it. */ 1979 - dev_vdbg(dev, "%s: Create the input device and register it\n", 1980 - __func__); 1981 - md->input = input_allocate_device(); 1982 - if (md->input == NULL) { 1983 - dev_err(dev, "%s: Error, failed to allocate input device\n", 1984 - __func__); 1985 - rc = -ENOSYS; 1986 - goto error_alloc_failed; 1987 - } 1988 - 1989 - md->input->name = pdata->inp_dev_name; 1990 - scnprintf(md->phys, sizeof(md->phys)-1, "%s", dev_name(dev)); 1991 - md->input->phys = md->phys; 1992 - md->input->id.bustype = cd->bus_ops->bustype; 1993 - md->input->dev.parent = dev; 1994 - md->input->open = cyttsp4_mt_open; 1995 - md->input->close = cyttsp4_mt_close; 1996 - input_set_drvdata(md->input, md); 1997 - 1998 - /* get sysinfo */ 1999 - md->si = &cd->sysinfo; 2000 - 2001 - rc = cyttsp4_setup_input_device(cd); 2002 - if (rc) 2003 - goto error_init_input; 2004 - 2005 - return 0; 2006 - 2007 - error_init_input: 2008 - input_free_device(md->input); 2009 - error_alloc_failed: 2010 - dev_err(dev, "%s failed.\n", __func__); 2011 - return rc; 2012 - } 2013 - 2014 - struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops, 2015 - struct device *dev, u16 irq, size_t xfer_buf_size) 2016 - { 2017 - struct cyttsp4 *cd; 2018 - struct cyttsp4_platform_data *pdata = dev_get_platdata(dev); 2019 - unsigned long irq_flags; 2020 - int rc = 0; 2021 - 2022 - if (!pdata || !pdata->core_pdata || !pdata->mt_pdata) { 2023 - dev_err(dev, "%s: Missing platform data\n", __func__); 2024 - rc = -ENODEV; 2025 - goto error_no_pdata; 2026 - } 2027 - 2028 - cd = kzalloc(sizeof(*cd), GFP_KERNEL); 2029 - if (!cd) { 2030 - dev_err(dev, "%s: Error, kzalloc\n", __func__); 2031 - rc = -ENOMEM; 2032 - goto error_alloc_data; 2033 - } 2034 - 2035 - cd->xfer_buf = kzalloc(xfer_buf_size, GFP_KERNEL); 2036 - if (!cd->xfer_buf) { 2037 - dev_err(dev, "%s: Error, kzalloc\n", __func__); 2038 - rc = -ENOMEM; 2039 - goto error_free_cd; 2040 - } 2041 - 2042 - /* Initialize device info */ 2043 - cd->dev = dev; 2044 - cd->pdata = pdata; 2045 - cd->cpdata = pdata->core_pdata; 2046 - cd->bus_ops = ops; 2047 - 2048 - /* Initialize mutexes and spinlocks */ 2049 - mutex_init(&cd->system_lock); 2050 - mutex_init(&cd->adap_lock); 2051 - 2052 - /* Initialize wait queue */ 2053 - init_waitqueue_head(&cd->wait_q); 2054 - 2055 - /* Initialize works */ 2056 - INIT_WORK(&cd->startup_work, cyttsp4_startup_work_function); 2057 - INIT_WORK(&cd->watchdog_work, cyttsp4_watchdog_work); 2058 - 2059 - /* Initialize IRQ */ 2060 - cd->irq = gpio_to_irq(cd->cpdata->irq_gpio); 2061 - if (cd->irq < 0) { 2062 - rc = -EINVAL; 2063 - goto error_free_xfer; 2064 - } 2065 - 2066 - dev_set_drvdata(dev, cd); 2067 - 2068 - /* Call platform init function */ 2069 - if (cd->cpdata->init) { 2070 - dev_dbg(cd->dev, "%s: Init HW\n", __func__); 2071 - rc = cd->cpdata->init(cd->cpdata, 1, cd->dev); 2072 - } else { 2073 - dev_dbg(cd->dev, "%s: No HW INIT function\n", __func__); 2074 - rc = 0; 2075 - } 2076 - if (rc < 0) 2077 - dev_err(cd->dev, "%s: HW Init fail r=%d\n", __func__, rc); 2078 - 2079 - dev_dbg(dev, "%s: initialize threaded irq=%d\n", __func__, cd->irq); 2080 - if (cd->cpdata->level_irq_udelay > 0) 2081 - /* use level triggered interrupts */ 2082 - irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT; 2083 - else 2084 - /* use edge triggered interrupts */ 2085 - irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; 2086 - 2087 - rc = request_threaded_irq(cd->irq, NULL, cyttsp4_irq, irq_flags, 2088 - dev_name(dev), cd); 2089 - if (rc < 0) { 2090 - dev_err(dev, "%s: Error, could not request irq\n", __func__); 2091 - goto error_request_irq; 2092 - } 2093 - 2094 - /* Setup watchdog timer */ 2095 - timer_setup(&cd->watchdog_timer, cyttsp4_watchdog_timer, 0); 2096 - 2097 - /* 2098 - * call startup directly to ensure that the device 2099 - * is tested before leaving the probe 2100 - */ 2101 - rc = cyttsp4_startup(cd); 2102 - 2103 - /* Do not fail probe if startup fails but the device is detected */ 2104 - if (rc < 0 && cd->mode == CY_MODE_UNKNOWN) { 2105 - dev_err(cd->dev, "%s: Fail initial startup r=%d\n", 2106 - __func__, rc); 2107 - goto error_startup; 2108 - } 2109 - 2110 - rc = cyttsp4_mt_probe(cd); 2111 - if (rc < 0) { 2112 - dev_err(dev, "%s: Error, fail mt probe\n", __func__); 2113 - goto error_startup; 2114 - } 2115 - 2116 - pm_runtime_enable(dev); 2117 - 2118 - return cd; 2119 - 2120 - error_startup: 2121 - cancel_work_sync(&cd->startup_work); 2122 - cyttsp4_stop_wd_timer(cd); 2123 - pm_runtime_disable(dev); 2124 - cyttsp4_free_si_ptrs(cd); 2125 - free_irq(cd->irq, cd); 2126 - error_request_irq: 2127 - if (cd->cpdata->init) 2128 - cd->cpdata->init(cd->cpdata, 0, dev); 2129 - error_free_xfer: 2130 - kfree(cd->xfer_buf); 2131 - error_free_cd: 2132 - kfree(cd); 2133 - error_alloc_data: 2134 - error_no_pdata: 2135 - dev_err(dev, "%s failed.\n", __func__); 2136 - return ERR_PTR(rc); 2137 - } 2138 - EXPORT_SYMBOL_GPL(cyttsp4_probe); 2139 - 2140 - static void cyttsp4_mt_release(struct cyttsp4_mt_data *md) 2141 - { 2142 - input_unregister_device(md->input); 2143 - input_set_drvdata(md->input, NULL); 2144 - } 2145 - 2146 - int cyttsp4_remove(struct cyttsp4 *cd) 2147 - { 2148 - struct device *dev = cd->dev; 2149 - 2150 - cyttsp4_mt_release(&cd->md); 2151 - 2152 - /* 2153 - * Suspend the device before freeing the startup_work and stopping 2154 - * the watchdog since sleep function restarts watchdog on failure 2155 - */ 2156 - pm_runtime_suspend(dev); 2157 - pm_runtime_disable(dev); 2158 - 2159 - cancel_work_sync(&cd->startup_work); 2160 - 2161 - cyttsp4_stop_wd_timer(cd); 2162 - 2163 - free_irq(cd->irq, cd); 2164 - if (cd->cpdata->init) 2165 - cd->cpdata->init(cd->cpdata, 0, dev); 2166 - cyttsp4_free_si_ptrs(cd); 2167 - kfree(cd); 2168 - return 0; 2169 - } 2170 - EXPORT_SYMBOL_GPL(cyttsp4_remove); 2171 - 2172 - MODULE_LICENSE("GPL"); 2173 - MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen core driver"); 2174 - MODULE_AUTHOR("Cypress");
-448
drivers/input/touchscreen/cyttsp4_core.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * cyttsp4_core.h 4 - * Cypress TrueTouch(TM) Standard Product V4 Core driver module. 5 - * For use with Cypress Txx4xx parts. 6 - * Supported parts include: 7 - * TMA4XX 8 - * TMA1036 9 - * 10 - * Copyright (C) 2012 Cypress Semiconductor 11 - * 12 - * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 13 - */ 14 - 15 - #ifndef _LINUX_CYTTSP4_CORE_H 16 - #define _LINUX_CYTTSP4_CORE_H 17 - 18 - #include <linux/device.h> 19 - #include <linux/err.h> 20 - #include <linux/input.h> 21 - #include <linux/kernel.h> 22 - #include <linux/limits.h> 23 - #include <linux/module.h> 24 - #include <linux/stringify.h> 25 - #include <linux/types.h> 26 - #include <linux/platform_data/cyttsp4.h> 27 - 28 - #define CY_REG_BASE 0x00 29 - 30 - #define CY_POST_CODEL_WDG_RST 0x01 31 - #define CY_POST_CODEL_CFG_DATA_CRC_FAIL 0x02 32 - #define CY_POST_CODEL_PANEL_TEST_FAIL 0x04 33 - 34 - #define CY_NUM_BTN_PER_REG 4 35 - 36 - /* touch record system information offset masks and shifts */ 37 - #define CY_BYTE_OFS_MASK 0x1F 38 - #define CY_BOFS_MASK 0xE0 39 - #define CY_BOFS_SHIFT 5 40 - 41 - #define CY_TMA1036_TCH_REC_SIZE 6 42 - #define CY_TMA4XX_TCH_REC_SIZE 9 43 - #define CY_TMA1036_MAX_TCH 0x0E 44 - #define CY_TMA4XX_MAX_TCH 0x1E 45 - 46 - #define CY_NORMAL_ORIGIN 0 /* upper, left corner */ 47 - #define CY_INVERT_ORIGIN 1 /* lower, right corner */ 48 - 49 - /* helpers */ 50 - #define GET_NUM_TOUCHES(x) ((x) & 0x1F) 51 - #define IS_LARGE_AREA(x) ((x) & 0x20) 52 - #define IS_BAD_PKT(x) ((x) & 0x20) 53 - #define IS_BOOTLOADER(hst_mode, reset_detect) \ 54 - ((hst_mode) & 0x01 || (reset_detect) != 0) 55 - #define IS_TMO(t) ((t) == 0) 56 - 57 - 58 - enum cyttsp_cmd_bits { 59 - CY_CMD_COMPLETE = (1 << 6), 60 - }; 61 - 62 - /* Timeout in ms. */ 63 - #define CY_WATCHDOG_TIMEOUT 1000 64 - 65 - #define CY_MAX_PRINT_SIZE 512 66 - #ifdef VERBOSE_DEBUG 67 - #define CY_MAX_PRBUF_SIZE PIPE_BUF 68 - #define CY_PR_TRUNCATED " truncated..." 69 - #endif 70 - 71 - enum cyttsp4_ic_grpnum { 72 - CY_IC_GRPNUM_RESERVED, 73 - CY_IC_GRPNUM_CMD_REGS, 74 - CY_IC_GRPNUM_TCH_REP, 75 - CY_IC_GRPNUM_DATA_REC, 76 - CY_IC_GRPNUM_TEST_REC, 77 - CY_IC_GRPNUM_PCFG_REC, 78 - CY_IC_GRPNUM_TCH_PARM_VAL, 79 - CY_IC_GRPNUM_TCH_PARM_SIZE, 80 - CY_IC_GRPNUM_RESERVED1, 81 - CY_IC_GRPNUM_RESERVED2, 82 - CY_IC_GRPNUM_OPCFG_REC, 83 - CY_IC_GRPNUM_DDATA_REC, 84 - CY_IC_GRPNUM_MDATA_REC, 85 - CY_IC_GRPNUM_TEST_REGS, 86 - CY_IC_GRPNUM_BTN_KEYS, 87 - CY_IC_GRPNUM_TTHE_REGS, 88 - CY_IC_GRPNUM_NUM 89 - }; 90 - 91 - enum cyttsp4_int_state { 92 - CY_INT_NONE, 93 - CY_INT_IGNORE = (1 << 0), 94 - CY_INT_MODE_CHANGE = (1 << 1), 95 - CY_INT_EXEC_CMD = (1 << 2), 96 - CY_INT_AWAKE = (1 << 3), 97 - }; 98 - 99 - enum cyttsp4_mode { 100 - CY_MODE_UNKNOWN, 101 - CY_MODE_BOOTLOADER = (1 << 1), 102 - CY_MODE_OPERATIONAL = (1 << 2), 103 - CY_MODE_SYSINFO = (1 << 3), 104 - CY_MODE_CAT = (1 << 4), 105 - CY_MODE_STARTUP = (1 << 5), 106 - CY_MODE_LOADER = (1 << 6), 107 - CY_MODE_CHANGE_MODE = (1 << 7), 108 - CY_MODE_CHANGED = (1 << 8), 109 - CY_MODE_CMD_COMPLETE = (1 << 9), 110 - }; 111 - 112 - enum cyttsp4_sleep_state { 113 - SS_SLEEP_OFF, 114 - SS_SLEEP_ON, 115 - SS_SLEEPING, 116 - SS_WAKING, 117 - }; 118 - 119 - enum cyttsp4_startup_state { 120 - STARTUP_NONE, 121 - STARTUP_QUEUED, 122 - STARTUP_RUNNING, 123 - }; 124 - 125 - #define CY_NUM_REVCTRL 8 126 - struct cyttsp4_cydata { 127 - u8 ttpidh; 128 - u8 ttpidl; 129 - u8 fw_ver_major; 130 - u8 fw_ver_minor; 131 - u8 revctrl[CY_NUM_REVCTRL]; 132 - u8 blver_major; 133 - u8 blver_minor; 134 - u8 jtag_si_id3; 135 - u8 jtag_si_id2; 136 - u8 jtag_si_id1; 137 - u8 jtag_si_id0; 138 - u8 mfgid_sz; 139 - u8 cyito_idh; 140 - u8 cyito_idl; 141 - u8 cyito_verh; 142 - u8 cyito_verl; 143 - u8 ttsp_ver_major; 144 - u8 ttsp_ver_minor; 145 - u8 device_info; 146 - u8 mfg_id[]; 147 - } __packed; 148 - 149 - struct cyttsp4_test { 150 - u8 post_codeh; 151 - u8 post_codel; 152 - } __packed; 153 - 154 - struct cyttsp4_pcfg { 155 - u8 electrodes_x; 156 - u8 electrodes_y; 157 - u8 len_xh; 158 - u8 len_xl; 159 - u8 len_yh; 160 - u8 len_yl; 161 - u8 res_xh; 162 - u8 res_xl; 163 - u8 res_yh; 164 - u8 res_yl; 165 - u8 max_zh; 166 - u8 max_zl; 167 - u8 panel_info0; 168 - } __packed; 169 - 170 - struct cyttsp4_tch_rec_params { 171 - u8 loc; 172 - u8 size; 173 - } __packed; 174 - 175 - #define CY_NUM_TCH_FIELDS 7 176 - #define CY_NUM_EXT_TCH_FIELDS 3 177 - struct cyttsp4_opcfg { 178 - u8 cmd_ofs; 179 - u8 rep_ofs; 180 - u8 rep_szh; 181 - u8 rep_szl; 182 - u8 num_btns; 183 - u8 tt_stat_ofs; 184 - u8 obj_cfg0; 185 - u8 max_tchs; 186 - u8 tch_rec_size; 187 - struct cyttsp4_tch_rec_params tch_rec_old[CY_NUM_TCH_FIELDS]; 188 - u8 btn_rec_size; /* btn record size (in bytes) */ 189 - u8 btn_diff_ofs; /* btn data loc, diff counts */ 190 - u8 btn_diff_size; /* btn size of diff counts (in bits) */ 191 - struct cyttsp4_tch_rec_params tch_rec_new[CY_NUM_EXT_TCH_FIELDS]; 192 - } __packed; 193 - 194 - struct cyttsp4_sysinfo_ptr { 195 - struct cyttsp4_cydata *cydata; 196 - struct cyttsp4_test *test; 197 - struct cyttsp4_pcfg *pcfg; 198 - struct cyttsp4_opcfg *opcfg; 199 - struct cyttsp4_ddata *ddata; 200 - struct cyttsp4_mdata *mdata; 201 - } __packed; 202 - 203 - struct cyttsp4_sysinfo_data { 204 - u8 hst_mode; 205 - u8 reserved; 206 - u8 map_szh; 207 - u8 map_szl; 208 - u8 cydata_ofsh; 209 - u8 cydata_ofsl; 210 - u8 test_ofsh; 211 - u8 test_ofsl; 212 - u8 pcfg_ofsh; 213 - u8 pcfg_ofsl; 214 - u8 opcfg_ofsh; 215 - u8 opcfg_ofsl; 216 - u8 ddata_ofsh; 217 - u8 ddata_ofsl; 218 - u8 mdata_ofsh; 219 - u8 mdata_ofsl; 220 - } __packed; 221 - 222 - enum cyttsp4_tch_abs { /* for ordering within the extracted touch data array */ 223 - CY_TCH_X, /* X */ 224 - CY_TCH_Y, /* Y */ 225 - CY_TCH_P, /* P (Z) */ 226 - CY_TCH_T, /* TOUCH ID */ 227 - CY_TCH_E, /* EVENT ID */ 228 - CY_TCH_O, /* OBJECT ID */ 229 - CY_TCH_W, /* SIZE */ 230 - CY_TCH_MAJ, /* TOUCH_MAJOR */ 231 - CY_TCH_MIN, /* TOUCH_MINOR */ 232 - CY_TCH_OR, /* ORIENTATION */ 233 - CY_TCH_NUM_ABS 234 - }; 235 - 236 - struct cyttsp4_touch { 237 - int abs[CY_TCH_NUM_ABS]; 238 - }; 239 - 240 - struct cyttsp4_tch_abs_params { 241 - size_t ofs; /* abs byte offset */ 242 - size_t size; /* size in bits */ 243 - size_t max; /* max value */ 244 - size_t bofs; /* bit offset */ 245 - }; 246 - 247 - struct cyttsp4_sysinfo_ofs { 248 - size_t chip_type; 249 - size_t cmd_ofs; 250 - size_t rep_ofs; 251 - size_t rep_sz; 252 - size_t num_btns; 253 - size_t num_btn_regs; /* ceil(num_btns/4) */ 254 - size_t tt_stat_ofs; 255 - size_t tch_rec_size; 256 - size_t obj_cfg0; 257 - size_t max_tchs; 258 - size_t mode_size; 259 - size_t data_size; 260 - size_t map_sz; 261 - size_t max_x; 262 - size_t x_origin; /* left or right corner */ 263 - size_t max_y; 264 - size_t y_origin; /* upper or lower corner */ 265 - size_t max_p; 266 - size_t cydata_ofs; 267 - size_t test_ofs; 268 - size_t pcfg_ofs; 269 - size_t opcfg_ofs; 270 - size_t ddata_ofs; 271 - size_t mdata_ofs; 272 - size_t cydata_size; 273 - size_t test_size; 274 - size_t pcfg_size; 275 - size_t opcfg_size; 276 - size_t ddata_size; 277 - size_t mdata_size; 278 - size_t btn_keys_size; 279 - struct cyttsp4_tch_abs_params tch_abs[CY_TCH_NUM_ABS]; 280 - size_t btn_rec_size; /* btn record size (in bytes) */ 281 - size_t btn_diff_ofs;/* btn data loc ,diff counts, (Op-Mode byte ofs) */ 282 - size_t btn_diff_size;/* btn size of diff counts (in bits) */ 283 - }; 284 - 285 - enum cyttsp4_btn_state { 286 - CY_BTN_RELEASED, 287 - CY_BTN_PRESSED, 288 - CY_BTN_NUM_STATE 289 - }; 290 - 291 - struct cyttsp4_btn { 292 - bool enabled; 293 - int state; /* CY_BTN_PRESSED, CY_BTN_RELEASED */ 294 - int key_code; 295 - }; 296 - 297 - struct cyttsp4_sysinfo { 298 - bool ready; 299 - struct cyttsp4_sysinfo_data si_data; 300 - struct cyttsp4_sysinfo_ptr si_ptrs; 301 - struct cyttsp4_sysinfo_ofs si_ofs; 302 - struct cyttsp4_btn *btn; /* button states */ 303 - u8 *btn_rec_data; /* button diff count data */ 304 - u8 *xy_mode; /* operational mode and status regs */ 305 - u8 *xy_data; /* operational touch regs */ 306 - }; 307 - 308 - struct cyttsp4_mt_data { 309 - struct cyttsp4_mt_platform_data *pdata; 310 - struct cyttsp4_sysinfo *si; 311 - struct input_dev *input; 312 - struct mutex report_lock; 313 - bool is_suspended; 314 - char phys[NAME_MAX]; 315 - int num_prv_tch; 316 - }; 317 - 318 - struct cyttsp4 { 319 - struct device *dev; 320 - struct mutex system_lock; 321 - struct mutex adap_lock; 322 - enum cyttsp4_mode mode; 323 - enum cyttsp4_sleep_state sleep_state; 324 - enum cyttsp4_startup_state startup_state; 325 - int int_status; 326 - wait_queue_head_t wait_q; 327 - int irq; 328 - struct work_struct startup_work; 329 - struct work_struct watchdog_work; 330 - struct timer_list watchdog_timer; 331 - struct cyttsp4_sysinfo sysinfo; 332 - void *exclusive_dev; 333 - int exclusive_waits; 334 - atomic_t ignore_irq; 335 - bool invalid_touch_app; 336 - struct cyttsp4_mt_data md; 337 - struct cyttsp4_platform_data *pdata; 338 - struct cyttsp4_core_platform_data *cpdata; 339 - const struct cyttsp4_bus_ops *bus_ops; 340 - u8 *xfer_buf; 341 - #ifdef VERBOSE_DEBUG 342 - u8 pr_buf[CY_MAX_PRBUF_SIZE]; 343 - #endif 344 - }; 345 - 346 - struct cyttsp4_bus_ops { 347 - u16 bustype; 348 - int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length, 349 - const void *values); 350 - int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length, 351 - void *values); 352 - }; 353 - 354 - enum cyttsp4_hst_mode_bits { 355 - CY_HST_TOGGLE = (1 << 7), 356 - CY_HST_MODE_CHANGE = (1 << 3), 357 - CY_HST_MODE = (7 << 4), 358 - CY_HST_OPERATE = (0 << 4), 359 - CY_HST_SYSINFO = (1 << 4), 360 - CY_HST_CAT = (2 << 4), 361 - CY_HST_LOWPOW = (1 << 2), 362 - CY_HST_SLEEP = (1 << 1), 363 - CY_HST_RESET = (1 << 0), 364 - }; 365 - 366 - /* abs settings */ 367 - #define CY_IGNORE_VALUE 0xFFFF 368 - 369 - /* abs signal capabilities offsets in the frameworks array */ 370 - enum cyttsp4_sig_caps { 371 - CY_SIGNAL_OST, 372 - CY_MIN_OST, 373 - CY_MAX_OST, 374 - CY_FUZZ_OST, 375 - CY_FLAT_OST, 376 - CY_NUM_ABS_SET /* number of signal capability fields */ 377 - }; 378 - 379 - /* abs axis signal offsets in the framworks array */ 380 - enum cyttsp4_sig_ost { 381 - CY_ABS_X_OST, 382 - CY_ABS_Y_OST, 383 - CY_ABS_P_OST, 384 - CY_ABS_W_OST, 385 - CY_ABS_ID_OST, 386 - CY_ABS_MAJ_OST, 387 - CY_ABS_MIN_OST, 388 - CY_ABS_OR_OST, 389 - CY_NUM_ABS_OST /* number of abs signals */ 390 - }; 391 - 392 - enum cyttsp4_flags { 393 - CY_FLAG_NONE = 0x00, 394 - CY_FLAG_HOVER = 0x04, 395 - CY_FLAG_FLIP = 0x08, 396 - CY_FLAG_INV_X = 0x10, 397 - CY_FLAG_INV_Y = 0x20, 398 - CY_FLAG_VKEYS = 0x40, 399 - }; 400 - 401 - enum cyttsp4_object_id { 402 - CY_OBJ_STANDARD_FINGER, 403 - CY_OBJ_LARGE_OBJECT, 404 - CY_OBJ_STYLUS, 405 - CY_OBJ_HOVER, 406 - }; 407 - 408 - enum cyttsp4_event_id { 409 - CY_EV_NO_EVENT, 410 - CY_EV_TOUCHDOWN, 411 - CY_EV_MOVE, /* significant displacement (> act dist) */ 412 - CY_EV_LIFTOFF, /* record reports last position */ 413 - }; 414 - 415 - /* x-axis resolution of panel in pixels */ 416 - #define CY_PCFG_RESOLUTION_X_MASK 0x7F 417 - 418 - /* y-axis resolution of panel in pixels */ 419 - #define CY_PCFG_RESOLUTION_Y_MASK 0x7F 420 - 421 - /* x-axis, 0:origin is on left side of panel, 1: right */ 422 - #define CY_PCFG_ORIGIN_X_MASK 0x80 423 - 424 - /* y-axis, 0:origin is on top side of panel, 1: bottom */ 425 - #define CY_PCFG_ORIGIN_Y_MASK 0x80 426 - 427 - static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size, 428 - void *buf) 429 - { 430 - return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf); 431 - } 432 - 433 - static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size, 434 - const void *buf) 435 - { 436 - return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf); 437 - } 438 - 439 - extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops, 440 - struct device *dev, u16 irq, size_t xfer_buf_size); 441 - extern int cyttsp4_remove(struct cyttsp4 *ts); 442 - int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr, 443 - u8 length, const void *values); 444 - int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr, 445 - u8 length, void *values); 446 - extern const struct dev_pm_ops cyttsp4_pm_ops; 447 - 448 - #endif /* _LINUX_CYTTSP4_CORE_H */
-72
drivers/input/touchscreen/cyttsp4_i2c.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * cyttsp_i2c.c 4 - * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. 5 - * For use with Cypress Txx4xx parts. 6 - * Supported parts include: 7 - * TMA4XX 8 - * TMA1036 9 - * 10 - * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 11 - * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 12 - * Copyright (C) 2013 Cypress Semiconductor 13 - * 14 - * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 15 - */ 16 - 17 - #include "cyttsp4_core.h" 18 - 19 - #include <linux/i2c.h> 20 - #include <linux/input.h> 21 - 22 - #define CYTTSP4_I2C_DATA_SIZE (3 * 256) 23 - 24 - static const struct cyttsp4_bus_ops cyttsp4_i2c_bus_ops = { 25 - .bustype = BUS_I2C, 26 - .write = cyttsp_i2c_write_block_data, 27 - .read = cyttsp_i2c_read_block_data, 28 - }; 29 - 30 - static int cyttsp4_i2c_probe(struct i2c_client *client) 31 - { 32 - struct cyttsp4 *ts; 33 - 34 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 35 - dev_err(&client->dev, "I2C functionality not Supported\n"); 36 - return -EIO; 37 - } 38 - 39 - ts = cyttsp4_probe(&cyttsp4_i2c_bus_ops, &client->dev, client->irq, 40 - CYTTSP4_I2C_DATA_SIZE); 41 - 42 - return PTR_ERR_OR_ZERO(ts); 43 - } 44 - 45 - static void cyttsp4_i2c_remove(struct i2c_client *client) 46 - { 47 - struct cyttsp4 *ts = i2c_get_clientdata(client); 48 - 49 - cyttsp4_remove(ts); 50 - } 51 - 52 - static const struct i2c_device_id cyttsp4_i2c_id[] = { 53 - { CYTTSP4_I2C_NAME }, 54 - { } 55 - }; 56 - MODULE_DEVICE_TABLE(i2c, cyttsp4_i2c_id); 57 - 58 - static struct i2c_driver cyttsp4_i2c_driver = { 59 - .driver = { 60 - .name = CYTTSP4_I2C_NAME, 61 - .pm = pm_ptr(&cyttsp4_pm_ops), 62 - }, 63 - .probe = cyttsp4_i2c_probe, 64 - .remove = cyttsp4_i2c_remove, 65 - .id_table = cyttsp4_i2c_id, 66 - }; 67 - 68 - module_i2c_driver(cyttsp4_i2c_driver); 69 - 70 - MODULE_LICENSE("GPL"); 71 - MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) I2C driver"); 72 - MODULE_AUTHOR("Cypress");
-187
drivers/input/touchscreen/cyttsp4_spi.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Source for: 4 - * Cypress TrueTouch(TM) Standard Product (TTSP) SPI touchscreen driver. 5 - * For use with Cypress Txx4xx parts. 6 - * Supported parts include: 7 - * TMA4XX 8 - * TMA1036 9 - * 10 - * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 11 - * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 12 - * Copyright (C) 2013 Cypress Semiconductor 13 - * 14 - * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 15 - */ 16 - 17 - #include "cyttsp4_core.h" 18 - 19 - #include <linux/delay.h> 20 - #include <linux/input.h> 21 - #include <linux/spi/spi.h> 22 - 23 - #define CY_SPI_WR_OP 0x00 /* r/~w */ 24 - #define CY_SPI_RD_OP 0x01 25 - #define CY_SPI_BITS_PER_WORD 8 26 - #define CY_SPI_A8_BIT 0x02 27 - #define CY_SPI_WR_HEADER_BYTES 2 28 - #define CY_SPI_RD_HEADER_BYTES 1 29 - #define CY_SPI_CMD_BYTES 2 30 - #define CY_SPI_SYNC_BYTE 0 31 - #define CY_SPI_SYNC_ACK 0x62 /* from TRM *A protocol */ 32 - #define CY_SPI_DATA_SIZE (2 * 256) 33 - 34 - #define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE) 35 - 36 - static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf, 37 - u8 op, u16 reg, u8 *buf, int length) 38 - { 39 - struct spi_device *spi = to_spi_device(dev); 40 - struct spi_message msg; 41 - struct spi_transfer xfer[2]; 42 - u8 *wr_buf = &xfer_buf[0]; 43 - u8 rd_buf[CY_SPI_CMD_BYTES]; 44 - int retval; 45 - int i; 46 - 47 - if (length > CY_SPI_DATA_SIZE) { 48 - dev_err(dev, "%s: length %d is too big.\n", 49 - __func__, length); 50 - return -EINVAL; 51 - } 52 - 53 - memset(wr_buf, 0, CY_SPI_DATA_BUF_SIZE); 54 - memset(rd_buf, 0, CY_SPI_CMD_BYTES); 55 - 56 - wr_buf[0] = op + (((reg >> 8) & 0x1) ? CY_SPI_A8_BIT : 0); 57 - if (op == CY_SPI_WR_OP) { 58 - wr_buf[1] = reg & 0xFF; 59 - if (length > 0) 60 - memcpy(wr_buf + CY_SPI_CMD_BYTES, buf, length); 61 - } 62 - 63 - memset(xfer, 0, sizeof(xfer)); 64 - spi_message_init(&msg); 65 - 66 - /* 67 - We set both TX and RX buffers because Cypress TTSP 68 - requires full duplex operation. 69 - */ 70 - xfer[0].tx_buf = wr_buf; 71 - xfer[0].rx_buf = rd_buf; 72 - switch (op) { 73 - case CY_SPI_WR_OP: 74 - xfer[0].len = length + CY_SPI_CMD_BYTES; 75 - spi_message_add_tail(&xfer[0], &msg); 76 - break; 77 - 78 - case CY_SPI_RD_OP: 79 - xfer[0].len = CY_SPI_RD_HEADER_BYTES; 80 - spi_message_add_tail(&xfer[0], &msg); 81 - 82 - xfer[1].rx_buf = buf; 83 - xfer[1].len = length; 84 - spi_message_add_tail(&xfer[1], &msg); 85 - break; 86 - 87 - default: 88 - dev_err(dev, "%s: bad operation code=%d\n", __func__, op); 89 - return -EINVAL; 90 - } 91 - 92 - retval = spi_sync(spi, &msg); 93 - if (retval < 0) { 94 - dev_dbg(dev, "%s: spi_sync() error %d, len=%d, op=%d\n", 95 - __func__, retval, xfer[1].len, op); 96 - 97 - /* 98 - * do not return here since was a bad ACK sequence 99 - * let the following ACK check handle any errors and 100 - * allow silent retries 101 - */ 102 - } 103 - 104 - if (rd_buf[CY_SPI_SYNC_BYTE] != CY_SPI_SYNC_ACK) { 105 - dev_dbg(dev, "%s: operation %d failed\n", __func__, op); 106 - 107 - for (i = 0; i < CY_SPI_CMD_BYTES; i++) 108 - dev_dbg(dev, "%s: test rd_buf[%d]:0x%02x\n", 109 - __func__, i, rd_buf[i]); 110 - for (i = 0; i < length; i++) 111 - dev_dbg(dev, "%s: test buf[%d]:0x%02x\n", 112 - __func__, i, buf[i]); 113 - 114 - return -EIO; 115 - } 116 - 117 - return 0; 118 - } 119 - 120 - static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf, 121 - u16 addr, u8 length, void *data) 122 - { 123 - int rc; 124 - 125 - rc = cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, NULL, 0); 126 - if (rc) 127 - return rc; 128 - else 129 - return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_RD_OP, addr, data, 130 - length); 131 - } 132 - 133 - static int cyttsp_spi_write_block_data(struct device *dev, u8 *xfer_buf, 134 - u16 addr, u8 length, const void *data) 135 - { 136 - return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, (void *)data, 137 - length); 138 - } 139 - 140 - static const struct cyttsp4_bus_ops cyttsp_spi_bus_ops = { 141 - .bustype = BUS_SPI, 142 - .write = cyttsp_spi_write_block_data, 143 - .read = cyttsp_spi_read_block_data, 144 - }; 145 - 146 - static int cyttsp4_spi_probe(struct spi_device *spi) 147 - { 148 - struct cyttsp4 *ts; 149 - int error; 150 - 151 - /* Set up SPI*/ 152 - spi->bits_per_word = CY_SPI_BITS_PER_WORD; 153 - spi->mode = SPI_MODE_0; 154 - error = spi_setup(spi); 155 - if (error < 0) { 156 - dev_err(&spi->dev, "%s: SPI setup error %d\n", 157 - __func__, error); 158 - return error; 159 - } 160 - 161 - ts = cyttsp4_probe(&cyttsp_spi_bus_ops, &spi->dev, spi->irq, 162 - CY_SPI_DATA_BUF_SIZE); 163 - 164 - return PTR_ERR_OR_ZERO(ts); 165 - } 166 - 167 - static void cyttsp4_spi_remove(struct spi_device *spi) 168 - { 169 - struct cyttsp4 *ts = spi_get_drvdata(spi); 170 - cyttsp4_remove(ts); 171 - } 172 - 173 - static struct spi_driver cyttsp4_spi_driver = { 174 - .driver = { 175 - .name = CYTTSP4_SPI_NAME, 176 - .pm = pm_ptr(&cyttsp4_pm_ops), 177 - }, 178 - .probe = cyttsp4_spi_probe, 179 - .remove = cyttsp4_spi_remove, 180 - }; 181 - 182 - module_spi_driver(cyttsp4_spi_driver); 183 - 184 - MODULE_LICENSE("GPL"); 185 - MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) SPI driver"); 186 - MODULE_AUTHOR("Cypress"); 187 - MODULE_ALIAS("spi:cyttsp4");
+8 -31
drivers/input/touchscreen/cyttsp_core.c
··· 17 17 #include <linux/input.h> 18 18 #include <linux/input/mt.h> 19 19 #include <linux/input/touchscreen.h> 20 - #include <linux/gpio.h> 21 20 #include <linux/interrupt.h> 22 21 #include <linux/slab.h> 23 22 #include <linux/property.h> ··· 614 615 return 0; 615 616 } 616 617 617 - static void cyttsp_disable_regulators(void *_ts) 618 - { 619 - struct cyttsp *ts = _ts; 620 - 621 - regulator_bulk_disable(ARRAY_SIZE(ts->regulators), 622 - ts->regulators); 623 - } 624 - 625 618 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, 626 619 struct device *dev, int irq, size_t xfer_buf_size) 627 620 { 621 + /* 622 + * VCPIN is the analog voltage supply 623 + * VDD is the digital voltage supply 624 + */ 625 + static const char * const supplies[] = { "vcpin", "vdd" }; 628 626 struct cyttsp *ts; 629 627 struct input_dev *input_dev; 630 628 int error; ··· 639 643 ts->bus_ops = bus_ops; 640 644 ts->irq = irq; 641 645 642 - /* 643 - * VCPIN is the analog voltage supply 644 - * VDD is the digital voltage supply 645 - */ 646 - ts->regulators[0].supply = "vcpin"; 647 - ts->regulators[1].supply = "vdd"; 648 - error = devm_regulator_bulk_get(dev, ARRAY_SIZE(ts->regulators), 649 - ts->regulators); 646 + error = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(supplies), 647 + supplies); 650 648 if (error) { 651 - dev_err(dev, "Failed to get regulators: %d\n", error); 652 - return ERR_PTR(error); 653 - } 654 - 655 - error = regulator_bulk_enable(ARRAY_SIZE(ts->regulators), 656 - ts->regulators); 657 - if (error) { 658 - dev_err(dev, "Cannot enable regulators: %d\n", error); 659 - return ERR_PTR(error); 660 - } 661 - 662 - error = devm_add_action_or_reset(dev, cyttsp_disable_regulators, ts); 663 - if (error) { 664 - dev_err(dev, "failed to install chip disable handler\n"); 649 + dev_err(dev, "Failed to enable regulators: %d\n", error); 665 650 return ERR_PTR(error); 666 651 } 667 652
-5
drivers/input/touchscreen/cyttsp_core.h
··· 122 122 enum cyttsp_state state; 123 123 bool suspended; 124 124 125 - struct regulator_bulk_data regulators[2]; 126 125 struct gpio_desc *reset_gpio; 127 126 bool use_hndshk; 128 127 u8 act_dist; ··· 136 137 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, 137 138 struct device *dev, int irq, size_t xfer_buf_size); 138 139 139 - int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr, 140 - u8 length, const void *values); 141 - int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr, 142 - u8 length, void *values); 143 140 extern const struct dev_pm_ops cyttsp_pm_ops; 144 141 145 142 #endif /* __CYTTSP_CORE_H__ */
+55
drivers/input/touchscreen/cyttsp_i2c.c
··· 22 22 23 23 #define CY_I2C_DATA_SIZE 128 24 24 25 + static int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, 26 + u16 addr, u8 length, void *values) 27 + { 28 + struct i2c_client *client = to_i2c_client(dev); 29 + u8 client_addr = client->addr | ((addr >> 8) & 0x1); 30 + u8 addr_lo = addr & 0xFF; 31 + struct i2c_msg msgs[] = { 32 + { 33 + .addr = client_addr, 34 + .flags = 0, 35 + .len = 1, 36 + .buf = &addr_lo, 37 + }, 38 + { 39 + .addr = client_addr, 40 + .flags = I2C_M_RD, 41 + .len = length, 42 + .buf = values, 43 + }, 44 + }; 45 + int retval; 46 + 47 + retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 48 + if (retval < 0) 49 + return retval; 50 + 51 + return retval != ARRAY_SIZE(msgs) ? -EIO : 0; 52 + } 53 + 54 + static int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, 55 + u16 addr, u8 length, const void *values) 56 + { 57 + struct i2c_client *client = to_i2c_client(dev); 58 + u8 client_addr = client->addr | ((addr >> 8) & 0x1); 59 + u8 addr_lo = addr & 0xFF; 60 + struct i2c_msg msgs[] = { 61 + { 62 + .addr = client_addr, 63 + .flags = 0, 64 + .len = length + 1, 65 + .buf = xfer_buf, 66 + }, 67 + }; 68 + int retval; 69 + 70 + xfer_buf[0] = addr_lo; 71 + memcpy(&xfer_buf[1], values, length); 72 + 73 + retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 74 + if (retval < 0) 75 + return retval; 76 + 77 + return retval != ARRAY_SIZE(msgs) ? -EIO : 0; 78 + } 79 + 25 80 static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = { 26 81 .bustype = BUS_I2C, 27 82 .write = cyttsp_i2c_write_block_data,
-86
drivers/input/touchscreen/cyttsp_i2c_common.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * cyttsp_i2c_common.c 4 - * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. 5 - * For use with Cypress Txx3xx and Txx4xx parts. 6 - * Supported parts include: 7 - * CY8CTST341 8 - * CY8CTMA340 9 - * TMA4XX 10 - * TMA1036 11 - * 12 - * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 13 - * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 14 - * 15 - * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 16 - */ 17 - 18 - #include <linux/device.h> 19 - #include <linux/export.h> 20 - #include <linux/i2c.h> 21 - #include <linux/module.h> 22 - #include <linux/types.h> 23 - 24 - #include "cyttsp4_core.h" 25 - 26 - int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, 27 - u16 addr, u8 length, void *values) 28 - { 29 - struct i2c_client *client = to_i2c_client(dev); 30 - u8 client_addr = client->addr | ((addr >> 8) & 0x1); 31 - u8 addr_lo = addr & 0xFF; 32 - struct i2c_msg msgs[] = { 33 - { 34 - .addr = client_addr, 35 - .flags = 0, 36 - .len = 1, 37 - .buf = &addr_lo, 38 - }, 39 - { 40 - .addr = client_addr, 41 - .flags = I2C_M_RD, 42 - .len = length, 43 - .buf = values, 44 - }, 45 - }; 46 - int retval; 47 - 48 - retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 49 - if (retval < 0) 50 - return retval; 51 - 52 - return retval != ARRAY_SIZE(msgs) ? -EIO : 0; 53 - } 54 - EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data); 55 - 56 - int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, 57 - u16 addr, u8 length, const void *values) 58 - { 59 - struct i2c_client *client = to_i2c_client(dev); 60 - u8 client_addr = client->addr | ((addr >> 8) & 0x1); 61 - u8 addr_lo = addr & 0xFF; 62 - struct i2c_msg msgs[] = { 63 - { 64 - .addr = client_addr, 65 - .flags = 0, 66 - .len = length + 1, 67 - .buf = xfer_buf, 68 - }, 69 - }; 70 - int retval; 71 - 72 - xfer_buf[0] = addr_lo; 73 - memcpy(&xfer_buf[1], values, length); 74 - 75 - retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 76 - if (retval < 0) 77 - return retval; 78 - 79 - return retval != ARRAY_SIZE(msgs) ? -EIO : 0; 80 - } 81 - EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data); 82 - 83 - 84 - MODULE_DESCRIPTION("Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver"); 85 - MODULE_LICENSE("GPL"); 86 - MODULE_AUTHOR("Cypress");
+1
drivers/input/touchscreen/goodix_berlin.h
··· 20 20 struct regmap *regmap); 21 21 22 22 extern const struct dev_pm_ops goodix_berlin_pm_ops; 23 + extern const struct attribute_group *goodix_berlin_groups[]; 23 24 24 25 #endif
+43
drivers/input/touchscreen/goodix_berlin_core.c
··· 672 672 goodix_berlin_power_off(cd); 673 673 } 674 674 675 + static ssize_t registers_read(struct file *filp, struct kobject *kobj, 676 + struct bin_attribute *bin_attr, 677 + char *buf, loff_t off, size_t count) 678 + { 679 + struct device *dev = kobj_to_dev(kobj); 680 + struct goodix_berlin_core *cd = dev_get_drvdata(dev); 681 + int error; 682 + 683 + error = regmap_raw_read(cd->regmap, off, buf, count); 684 + 685 + return error ? error : count; 686 + } 687 + 688 + static ssize_t registers_write(struct file *filp, struct kobject *kobj, 689 + struct bin_attribute *bin_attr, 690 + char *buf, loff_t off, size_t count) 691 + { 692 + struct device *dev = kobj_to_dev(kobj); 693 + struct goodix_berlin_core *cd = dev_get_drvdata(dev); 694 + int error; 695 + 696 + error = regmap_raw_write(cd->regmap, off, buf, count); 697 + 698 + return error ? error : count; 699 + } 700 + 701 + static BIN_ATTR_ADMIN_RW(registers, 0); 702 + 703 + static struct bin_attribute *goodix_berlin_bin_attrs[] = { 704 + &bin_attr_registers, 705 + NULL, 706 + }; 707 + 708 + static const struct attribute_group goodix_berlin_attr_group = { 709 + .bin_attrs = goodix_berlin_bin_attrs, 710 + }; 711 + 712 + const struct attribute_group *goodix_berlin_groups[] = { 713 + &goodix_berlin_attr_group, 714 + NULL, 715 + }; 716 + EXPORT_SYMBOL_GPL(goodix_berlin_groups); 717 + 675 718 int goodix_berlin_probe(struct device *dev, int irq, const struct input_id *id, 676 719 struct regmap *regmap) 677 720 {
+1
drivers/input/touchscreen/goodix_berlin_i2c.c
··· 64 64 .name = "goodix-berlin-i2c", 65 65 .of_match_table = goodix_berlin_i2c_of_match, 66 66 .pm = pm_sleep_ptr(&goodix_berlin_pm_ops), 67 + .dev_groups = goodix_berlin_groups, 67 68 }, 68 69 .probe = goodix_berlin_i2c_probe, 69 70 .id_table = goodix_berlin_i2c_id,
+1
drivers/input/touchscreen/goodix_berlin_spi.c
··· 169 169 .name = "goodix-berlin-spi", 170 170 .of_match_table = goodix_berlin_spi_of_match, 171 171 .pm = pm_sleep_ptr(&goodix_berlin_pm_ops), 172 + .dev_groups = goodix_berlin_groups, 172 173 }, 173 174 .probe = goodix_berlin_spi_probe, 174 175 .id_table = goodix_berlin_spi_ids,
+1 -1
drivers/input/touchscreen/hynitron_cstxxx.c
··· 470 470 }; 471 471 472 472 static const struct i2c_device_id hyn_tpd_id[] = { 473 - { .name = "hynitron_ts", 0 }, 473 + { .name = "hynitron_ts" }, 474 474 { /* sentinel */ }, 475 475 }; 476 476 MODULE_DEVICE_TABLE(i2c, hyn_tpd_id);
+12 -7
drivers/input/touchscreen/ilitek_ts_i2c.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/delay.h> 17 17 #include <linux/interrupt.h> 18 - #include <linux/gpio.h> 19 18 #include <linux/gpio/consumer.h> 20 19 #include <linux/errno.h> 21 20 #include <linux/acpi.h> ··· 35 36 #define ILITEK_TP_CMD_GET_PRL_VER 0x42 36 37 #define ILITEK_TP_CMD_GET_MCU_VER 0x61 37 38 #define ILITEK_TP_CMD_GET_IC_MODE 0xC0 39 + 40 + #define ILITEK_TP_I2C_REPORT_ID 0x48 38 41 39 42 #define REPORT_COUNT_ADDRESS 61 40 43 #define ILITEK_SUPPORT_MAX_POINT 40 ··· 161 160 error = ilitek_i2c_write_and_read(ts, NULL, 0, 0, buf, 64); 162 161 if (error) { 163 162 dev_err(dev, "get touch info failed, err:%d\n", error); 164 - goto err_sync_frame; 163 + return error; 164 + } 165 + 166 + if (buf[0] != ILITEK_TP_I2C_REPORT_ID) { 167 + dev_err(dev, "get touch info failed. Wrong id: 0x%02X\n", buf[0]); 168 + return -EINVAL; 165 169 } 166 170 167 171 report_max_point = buf[REPORT_COUNT_ADDRESS]; 168 172 if (report_max_point > ts->max_tp) { 169 173 dev_err(dev, "FW report max point:%d > panel info. max:%d\n", 170 174 report_max_point, ts->max_tp); 171 - error = -EINVAL; 172 - goto err_sync_frame; 175 + return -EINVAL; 173 176 } 174 177 175 178 count = DIV_ROUND_UP(report_max_point, packet_max_point); ··· 183 178 if (error) { 184 179 dev_err(dev, "get touch info. failed, cnt:%d, err:%d\n", 185 180 count, error); 186 - goto err_sync_frame; 181 + return error; 187 182 } 188 183 } 189 184 ··· 208 203 ilitek_touch_down(ts, id, x, y); 209 204 } 210 205 211 - err_sync_frame: 212 206 input_mt_sync_frame(input); 213 207 input_sync(input); 214 - return error; 208 + 209 + return 0; 215 210 } 216 211 217 212 /* APIs of cmds for ILITEK Touch IC */
-288
drivers/input/touchscreen/mcs5000_ts.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * mcs5000_ts.c - Touchscreen driver for MELFAS MCS-5000 controller 4 - * 5 - * Copyright (C) 2009 Samsung Electronics Co.Ltd 6 - * Author: Joonyoung Shim <jy0922.shim@samsung.com> 7 - * 8 - * Based on wm97xx-core.c 9 - */ 10 - 11 - #include <linux/module.h> 12 - #include <linux/i2c.h> 13 - #include <linux/interrupt.h> 14 - #include <linux/input.h> 15 - #include <linux/irq.h> 16 - #include <linux/platform_data/mcs.h> 17 - #include <linux/slab.h> 18 - 19 - /* Registers */ 20 - #define MCS5000_TS_STATUS 0x00 21 - #define STATUS_OFFSET 0 22 - #define STATUS_NO (0 << STATUS_OFFSET) 23 - #define STATUS_INIT (1 << STATUS_OFFSET) 24 - #define STATUS_SENSING (2 << STATUS_OFFSET) 25 - #define STATUS_COORD (3 << STATUS_OFFSET) 26 - #define STATUS_GESTURE (4 << STATUS_OFFSET) 27 - #define ERROR_OFFSET 4 28 - #define ERROR_NO (0 << ERROR_OFFSET) 29 - #define ERROR_POWER_ON_RESET (1 << ERROR_OFFSET) 30 - #define ERROR_INT_RESET (2 << ERROR_OFFSET) 31 - #define ERROR_EXT_RESET (3 << ERROR_OFFSET) 32 - #define ERROR_INVALID_REG_ADDRESS (8 << ERROR_OFFSET) 33 - #define ERROR_INVALID_REG_VALUE (9 << ERROR_OFFSET) 34 - 35 - #define MCS5000_TS_OP_MODE 0x01 36 - #define RESET_OFFSET 0 37 - #define RESET_NO (0 << RESET_OFFSET) 38 - #define RESET_EXT_SOFT (1 << RESET_OFFSET) 39 - #define OP_MODE_OFFSET 1 40 - #define OP_MODE_SLEEP (0 << OP_MODE_OFFSET) 41 - #define OP_MODE_ACTIVE (1 << OP_MODE_OFFSET) 42 - #define GESTURE_OFFSET 4 43 - #define GESTURE_DISABLE (0 << GESTURE_OFFSET) 44 - #define GESTURE_ENABLE (1 << GESTURE_OFFSET) 45 - #define PROXIMITY_OFFSET 5 46 - #define PROXIMITY_DISABLE (0 << PROXIMITY_OFFSET) 47 - #define PROXIMITY_ENABLE (1 << PROXIMITY_OFFSET) 48 - #define SCAN_MODE_OFFSET 6 49 - #define SCAN_MODE_INTERRUPT (0 << SCAN_MODE_OFFSET) 50 - #define SCAN_MODE_POLLING (1 << SCAN_MODE_OFFSET) 51 - #define REPORT_RATE_OFFSET 7 52 - #define REPORT_RATE_40 (0 << REPORT_RATE_OFFSET) 53 - #define REPORT_RATE_80 (1 << REPORT_RATE_OFFSET) 54 - 55 - #define MCS5000_TS_SENS_CTL 0x02 56 - #define MCS5000_TS_FILTER_CTL 0x03 57 - #define PRI_FILTER_OFFSET 0 58 - #define SEC_FILTER_OFFSET 4 59 - 60 - #define MCS5000_TS_X_SIZE_UPPER 0x08 61 - #define MCS5000_TS_X_SIZE_LOWER 0x09 62 - #define MCS5000_TS_Y_SIZE_UPPER 0x0A 63 - #define MCS5000_TS_Y_SIZE_LOWER 0x0B 64 - 65 - #define MCS5000_TS_INPUT_INFO 0x10 66 - #define INPUT_TYPE_OFFSET 0 67 - #define INPUT_TYPE_NONTOUCH (0 << INPUT_TYPE_OFFSET) 68 - #define INPUT_TYPE_SINGLE (1 << INPUT_TYPE_OFFSET) 69 - #define INPUT_TYPE_DUAL (2 << INPUT_TYPE_OFFSET) 70 - #define INPUT_TYPE_PALM (3 << INPUT_TYPE_OFFSET) 71 - #define INPUT_TYPE_PROXIMITY (7 << INPUT_TYPE_OFFSET) 72 - #define GESTURE_CODE_OFFSET 3 73 - #define GESTURE_CODE_NO (0 << GESTURE_CODE_OFFSET) 74 - 75 - #define MCS5000_TS_X_POS_UPPER 0x11 76 - #define MCS5000_TS_X_POS_LOWER 0x12 77 - #define MCS5000_TS_Y_POS_UPPER 0x13 78 - #define MCS5000_TS_Y_POS_LOWER 0x14 79 - #define MCS5000_TS_Z_POS 0x15 80 - #define MCS5000_TS_WIDTH 0x16 81 - #define MCS5000_TS_GESTURE_VAL 0x17 82 - #define MCS5000_TS_MODULE_REV 0x20 83 - #define MCS5000_TS_FIRMWARE_VER 0x21 84 - 85 - /* Touchscreen absolute values */ 86 - #define MCS5000_MAX_XC 0x3ff 87 - #define MCS5000_MAX_YC 0x3ff 88 - 89 - enum mcs5000_ts_read_offset { 90 - READ_INPUT_INFO, 91 - READ_X_POS_UPPER, 92 - READ_X_POS_LOWER, 93 - READ_Y_POS_UPPER, 94 - READ_Y_POS_LOWER, 95 - READ_BLOCK_SIZE, 96 - }; 97 - 98 - /* Each client has this additional data */ 99 - struct mcs5000_ts_data { 100 - struct i2c_client *client; 101 - struct input_dev *input_dev; 102 - const struct mcs_platform_data *platform_data; 103 - }; 104 - 105 - static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id) 106 - { 107 - struct mcs5000_ts_data *data = dev_id; 108 - struct i2c_client *client = data->client; 109 - u8 buffer[READ_BLOCK_SIZE]; 110 - int err; 111 - int x; 112 - int y; 113 - 114 - err = i2c_smbus_read_i2c_block_data(client, MCS5000_TS_INPUT_INFO, 115 - READ_BLOCK_SIZE, buffer); 116 - if (err < 0) { 117 - dev_err(&client->dev, "%s, err[%d]\n", __func__, err); 118 - goto out; 119 - } 120 - 121 - switch (buffer[READ_INPUT_INFO]) { 122 - case INPUT_TYPE_NONTOUCH: 123 - input_report_key(data->input_dev, BTN_TOUCH, 0); 124 - input_sync(data->input_dev); 125 - break; 126 - 127 - case INPUT_TYPE_SINGLE: 128 - x = (buffer[READ_X_POS_UPPER] << 8) | buffer[READ_X_POS_LOWER]; 129 - y = (buffer[READ_Y_POS_UPPER] << 8) | buffer[READ_Y_POS_LOWER]; 130 - 131 - input_report_key(data->input_dev, BTN_TOUCH, 1); 132 - input_report_abs(data->input_dev, ABS_X, x); 133 - input_report_abs(data->input_dev, ABS_Y, y); 134 - input_sync(data->input_dev); 135 - break; 136 - 137 - case INPUT_TYPE_DUAL: 138 - /* TODO */ 139 - break; 140 - 141 - case INPUT_TYPE_PALM: 142 - /* TODO */ 143 - break; 144 - 145 - case INPUT_TYPE_PROXIMITY: 146 - /* TODO */ 147 - break; 148 - 149 - default: 150 - dev_err(&client->dev, "Unknown ts input type %d\n", 151 - buffer[READ_INPUT_INFO]); 152 - break; 153 - } 154 - 155 - out: 156 - return IRQ_HANDLED; 157 - } 158 - 159 - static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data, 160 - const struct mcs_platform_data *platform_data) 161 - { 162 - struct i2c_client *client = data->client; 163 - 164 - /* Touch reset & sleep mode */ 165 - i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, 166 - RESET_EXT_SOFT | OP_MODE_SLEEP); 167 - 168 - /* Touch size */ 169 - i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_UPPER, 170 - platform_data->x_size >> 8); 171 - i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_LOWER, 172 - platform_data->x_size & 0xff); 173 - i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_UPPER, 174 - platform_data->y_size >> 8); 175 - i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_LOWER, 176 - platform_data->y_size & 0xff); 177 - 178 - /* Touch active mode & 80 report rate */ 179 - i2c_smbus_write_byte_data(data->client, MCS5000_TS_OP_MODE, 180 - OP_MODE_ACTIVE | REPORT_RATE_80); 181 - } 182 - 183 - static int mcs5000_ts_probe(struct i2c_client *client) 184 - { 185 - const struct mcs_platform_data *pdata; 186 - struct mcs5000_ts_data *data; 187 - struct input_dev *input_dev; 188 - int error; 189 - 190 - pdata = dev_get_platdata(&client->dev); 191 - if (!pdata) 192 - return -EINVAL; 193 - 194 - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); 195 - if (!data) { 196 - dev_err(&client->dev, "Failed to allocate memory\n"); 197 - return -ENOMEM; 198 - } 199 - 200 - data->client = client; 201 - 202 - input_dev = devm_input_allocate_device(&client->dev); 203 - if (!input_dev) { 204 - dev_err(&client->dev, "Failed to allocate input device\n"); 205 - return -ENOMEM; 206 - } 207 - 208 - input_dev->name = "MELFAS MCS-5000 Touchscreen"; 209 - input_dev->id.bustype = BUS_I2C; 210 - input_dev->dev.parent = &client->dev; 211 - 212 - __set_bit(EV_ABS, input_dev->evbit); 213 - __set_bit(EV_KEY, input_dev->evbit); 214 - __set_bit(BTN_TOUCH, input_dev->keybit); 215 - input_set_abs_params(input_dev, ABS_X, 0, MCS5000_MAX_XC, 0, 0); 216 - input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0); 217 - 218 - data->input_dev = input_dev; 219 - 220 - if (pdata->cfg_pin) 221 - pdata->cfg_pin(); 222 - 223 - error = devm_request_threaded_irq(&client->dev, client->irq, 224 - NULL, mcs5000_ts_interrupt, 225 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 226 - "mcs5000_ts", data); 227 - if (error) { 228 - dev_err(&client->dev, "Failed to register interrupt\n"); 229 - return error; 230 - } 231 - 232 - error = input_register_device(data->input_dev); 233 - if (error) { 234 - dev_err(&client->dev, "Failed to register input device\n"); 235 - return error; 236 - } 237 - 238 - mcs5000_ts_phys_init(data, pdata); 239 - i2c_set_clientdata(client, data); 240 - 241 - return 0; 242 - } 243 - 244 - static int mcs5000_ts_suspend(struct device *dev) 245 - { 246 - struct i2c_client *client = to_i2c_client(dev); 247 - 248 - /* Touch sleep mode */ 249 - i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP); 250 - 251 - return 0; 252 - } 253 - 254 - static int mcs5000_ts_resume(struct device *dev) 255 - { 256 - struct i2c_client *client = to_i2c_client(dev); 257 - struct mcs5000_ts_data *data = i2c_get_clientdata(client); 258 - const struct mcs_platform_data *pdata = dev_get_platdata(dev); 259 - 260 - mcs5000_ts_phys_init(data, pdata); 261 - 262 - return 0; 263 - } 264 - 265 - static DEFINE_SIMPLE_DEV_PM_OPS(mcs5000_ts_pm, 266 - mcs5000_ts_suspend, mcs5000_ts_resume); 267 - 268 - static const struct i2c_device_id mcs5000_ts_id[] = { 269 - { "mcs5000_ts" }, 270 - { } 271 - }; 272 - MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id); 273 - 274 - static struct i2c_driver mcs5000_ts_driver = { 275 - .probe = mcs5000_ts_probe, 276 - .driver = { 277 - .name = "mcs5000_ts", 278 - .pm = pm_sleep_ptr(&mcs5000_ts_pm), 279 - }, 280 - .id_table = mcs5000_ts_id, 281 - }; 282 - 283 - module_i2c_driver(mcs5000_ts_driver); 284 - 285 - /* Module information */ 286 - MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); 287 - MODULE_DESCRIPTION("Touchscreen driver for MELFAS MCS-5000 controller"); 288 - MODULE_LICENSE("GPL");
-6
drivers/input/touchscreen/tsc2004.c
··· 42 42 tsc2004_cmd); 43 43 } 44 44 45 - static void tsc2004_remove(struct i2c_client *i2c) 46 - { 47 - tsc200x_remove(&i2c->dev); 48 - } 49 - 50 45 static const struct i2c_device_id tsc2004_idtable[] = { 51 46 { "tsc2004" }, 52 47 { } ··· 65 70 }, 66 71 .id_table = tsc2004_idtable, 67 72 .probe = tsc2004_probe, 68 - .remove = tsc2004_remove, 69 73 }; 70 74 module_i2c_driver(tsc2004_driver); 71 75
-6
drivers/input/touchscreen/tsc2005.c
··· 64 64 tsc2005_cmd); 65 65 } 66 66 67 - static void tsc2005_remove(struct spi_device *spi) 68 - { 69 - tsc200x_remove(&spi->dev); 70 - } 71 - 72 67 #ifdef CONFIG_OF 73 68 static const struct of_device_id tsc2005_of_match[] = { 74 69 { .compatible = "ti,tsc2005" }, ··· 80 85 .pm = pm_sleep_ptr(&tsc200x_pm_ops), 81 86 }, 82 87 .probe = tsc2005_probe, 83 - .remove = tsc2005_remove, 84 88 }; 85 89 module_spi_driver(tsc2005_driver); 86 90
+111 -138
drivers/input/touchscreen/tsc200x-core.c
··· 104 104 105 105 bool pen_down; 106 106 107 - struct regulator *vio; 108 - 109 107 struct gpio_desc *reset_gpio; 110 108 int (*tsc200x_cmd)(struct device *dev, u8 cmd); 109 + 111 110 int irq; 111 + bool wake_irq_enabled; 112 112 }; 113 113 114 114 static void tsc200x_update_pen_state(struct tsc200x *ts, ··· 136 136 static irqreturn_t tsc200x_irq_thread(int irq, void *_ts) 137 137 { 138 138 struct tsc200x *ts = _ts; 139 - unsigned long flags; 140 139 unsigned int pressure; 141 140 struct tsc200x_data tsdata; 142 141 int error; ··· 181 182 if (unlikely(pressure > MAX_12BIT)) 182 183 goto out; 183 184 184 - spin_lock_irqsave(&ts->lock, flags); 185 - 186 - tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); 187 - mod_timer(&ts->penup_timer, 188 - jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS)); 189 - 190 - spin_unlock_irqrestore(&ts->lock, flags); 185 + scoped_guard(spinlock_irqsave, &ts->lock) { 186 + tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); 187 + mod_timer(&ts->penup_timer, 188 + jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS)); 189 + } 191 190 192 191 ts->last_valid_interrupt = jiffies; 193 192 out: ··· 195 198 static void tsc200x_penup_timer(struct timer_list *t) 196 199 { 197 200 struct tsc200x *ts = from_timer(ts, t, penup_timer); 198 - unsigned long flags; 199 201 200 - spin_lock_irqsave(&ts->lock, flags); 202 + guard(spinlock_irqsave)(&ts->lock); 201 203 tsc200x_update_pen_state(ts, 0, 0, 0); 202 - spin_unlock_irqrestore(&ts->lock, flags); 203 204 } 204 205 205 206 static void tsc200x_start_scan(struct tsc200x *ts) ··· 227 232 { 228 233 tsc200x_stop_scan(ts); 229 234 230 - disable_irq(ts->irq); 235 + guard(disable_irq)(&ts->irq); 236 + 231 237 del_timer_sync(&ts->penup_timer); 232 - 233 238 cancel_delayed_work_sync(&ts->esd_work); 234 - 235 - enable_irq(ts->irq); 236 239 } 237 240 238 241 /* must be called with ts->mutex held */ ··· 246 253 } 247 254 } 248 255 249 - static ssize_t tsc200x_selftest_show(struct device *dev, 250 - struct device_attribute *attr, 251 - char *buf) 256 + /* 257 + * Test TSC200X communications via temp high register. 258 + */ 259 + static int tsc200x_do_selftest(struct tsc200x *ts) 252 260 { 253 - struct tsc200x *ts = dev_get_drvdata(dev); 254 - unsigned int temp_high; 255 261 unsigned int temp_high_orig; 256 262 unsigned int temp_high_test; 257 - bool success = true; 263 + unsigned int temp_high; 258 264 int error; 259 - 260 - mutex_lock(&ts->mutex); 261 - 262 - /* 263 - * Test TSC200X communications via temp high register. 264 - */ 265 - __tsc200x_disable(ts); 266 265 267 266 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); 268 267 if (error) { 269 - dev_warn(dev, "selftest failed: read error %d\n", error); 270 - success = false; 271 - goto out; 268 + dev_warn(ts->dev, "selftest failed: read error %d\n", error); 269 + return error; 272 270 } 273 271 274 272 temp_high_test = (temp_high_orig - 1) & MAX_12BIT; 275 273 276 274 error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); 277 275 if (error) { 278 - dev_warn(dev, "selftest failed: write error %d\n", error); 279 - success = false; 280 - goto out; 276 + dev_warn(ts->dev, "selftest failed: write error %d\n", error); 277 + return error; 281 278 } 282 279 283 280 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); 284 281 if (error) { 285 - dev_warn(dev, "selftest failed: read error %d after write\n", 286 - error); 287 - success = false; 288 - goto out; 289 - } 290 - 291 - if (temp_high != temp_high_test) { 292 - dev_warn(dev, "selftest failed: %d != %d\n", 293 - temp_high, temp_high_test); 294 - success = false; 282 + dev_warn(ts->dev, 283 + "selftest failed: read error %d after write\n", error); 284 + return error; 295 285 } 296 286 297 287 /* hardware reset */ 298 288 tsc200x_reset(ts); 299 289 300 - if (!success) 301 - goto out; 290 + if (temp_high != temp_high_test) { 291 + dev_warn(ts->dev, "selftest failed: %d != %d\n", 292 + temp_high, temp_high_test); 293 + return -EINVAL; 294 + } 302 295 303 296 /* test that the reset really happened */ 304 297 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); 305 298 if (error) { 306 - dev_warn(dev, "selftest failed: read error %d after reset\n", 307 - error); 308 - success = false; 309 - goto out; 299 + dev_warn(ts->dev, 300 + "selftest failed: read error %d after reset\n", error); 301 + return error; 310 302 } 311 303 312 304 if (temp_high != temp_high_orig) { 313 - dev_warn(dev, "selftest failed after reset: %d != %d\n", 305 + dev_warn(ts->dev, "selftest failed after reset: %d != %d\n", 314 306 temp_high, temp_high_orig); 315 - success = false; 307 + return -EINVAL; 316 308 } 317 309 318 - out: 319 - __tsc200x_enable(ts); 320 - mutex_unlock(&ts->mutex); 310 + return 0; 311 + } 321 312 322 - return sprintf(buf, "%d\n", success); 313 + static ssize_t tsc200x_selftest_show(struct device *dev, 314 + struct device_attribute *attr, 315 + char *buf) 316 + { 317 + struct tsc200x *ts = dev_get_drvdata(dev); 318 + int error; 319 + 320 + scoped_guard(mutex, &ts->mutex) { 321 + __tsc200x_disable(ts); 322 + 323 + error = tsc200x_do_selftest(ts); 324 + 325 + __tsc200x_enable(ts); 326 + } 327 + 328 + return sprintf(buf, "%d\n", !error); 323 329 } 324 330 325 331 static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL); ··· 360 368 int error; 361 369 unsigned int r; 362 370 363 - if (!mutex_trylock(&ts->mutex)) { 364 - /* 365 - * If the mutex is taken, it means that disable or enable is in 366 - * progress. In that case just reschedule the work. If the work 367 - * is not needed, it will be canceled by disable. 368 - */ 369 - goto reschedule; 370 - } 371 - 372 - if (time_is_after_jiffies(ts->last_valid_interrupt + 373 - msecs_to_jiffies(ts->esd_timeout))) 374 - goto out; 375 - 376 - /* We should be able to read register without disabling interrupts. */ 377 - error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); 378 - if (!error && 379 - !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) { 380 - goto out; 381 - } 382 - 383 371 /* 384 - * If we could not read our known value from configuration register 0 385 - * then we should reset the controller as if from power-up and start 386 - * scanning again. 372 + * If the mutex is taken, it means that disable or enable is in 373 + * progress. In that case just reschedule the work. If the work 374 + * is not needed, it will be canceled by disable. 387 375 */ 388 - dev_info(ts->dev, "TSC200X not responding - resetting\n"); 376 + scoped_guard(mutex_try, &ts->mutex) { 377 + if (time_is_after_jiffies(ts->last_valid_interrupt + 378 + msecs_to_jiffies(ts->esd_timeout))) 379 + break; 389 380 390 - disable_irq(ts->irq); 391 - del_timer_sync(&ts->penup_timer); 381 + /* 382 + * We should be able to read register without disabling 383 + * interrupts. 384 + */ 385 + error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); 386 + if (!error && 387 + !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) { 388 + break; 389 + } 392 390 393 - tsc200x_update_pen_state(ts, 0, 0, 0); 391 + /* 392 + * If we could not read our known value from configuration 393 + * register 0 then we should reset the controller as if from 394 + * power-up and start scanning again. 395 + */ 396 + dev_info(ts->dev, "TSC200X not responding - resetting\n"); 394 397 395 - tsc200x_reset(ts); 398 + scoped_guard(disable_irq, &ts->irq) { 399 + del_timer_sync(&ts->penup_timer); 400 + tsc200x_update_pen_state(ts, 0, 0, 0); 401 + tsc200x_reset(ts); 402 + } 396 403 397 - enable_irq(ts->irq); 398 - tsc200x_start_scan(ts); 404 + tsc200x_start_scan(ts); 405 + } 399 406 400 - out: 401 - mutex_unlock(&ts->mutex); 402 - reschedule: 403 407 /* re-arm the watchdog */ 404 408 schedule_delayed_work(&ts->esd_work, 405 409 round_jiffies_relative( ··· 406 418 { 407 419 struct tsc200x *ts = input_get_drvdata(input); 408 420 409 - mutex_lock(&ts->mutex); 421 + guard(mutex)(&ts->mutex); 410 422 411 423 if (!ts->suspended) 412 424 __tsc200x_enable(ts); 413 425 414 426 ts->opened = true; 415 - 416 - mutex_unlock(&ts->mutex); 417 427 418 428 return 0; 419 429 } ··· 420 434 { 421 435 struct tsc200x *ts = input_get_drvdata(input); 422 436 423 - mutex_lock(&ts->mutex); 437 + guard(mutex)(&ts->mutex); 424 438 425 439 if (!ts->suspended) 426 440 __tsc200x_disable(ts); 427 441 428 442 ts->opened = false; 429 - 430 - mutex_unlock(&ts->mutex); 431 443 } 432 444 433 445 int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, ··· 472 488 &esd_timeout); 473 489 ts->esd_timeout = error ? 0 : esd_timeout; 474 490 475 - ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 476 - if (IS_ERR(ts->reset_gpio)) { 477 - error = PTR_ERR(ts->reset_gpio); 478 - dev_err(dev, "error acquiring reset gpio: %d\n", error); 479 - return error; 480 - } 481 - 482 - ts->vio = devm_regulator_get(dev, "vio"); 483 - if (IS_ERR(ts->vio)) { 484 - error = PTR_ERR(ts->vio); 485 - dev_err(dev, "error acquiring vio regulator: %d", error); 486 - return error; 487 - } 488 - 489 491 mutex_init(&ts->mutex); 490 492 491 493 spin_lock_init(&ts->lock); ··· 512 542 513 543 touchscreen_parse_properties(input_dev, false, &ts->prop); 514 544 545 + ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 546 + error = PTR_ERR_OR_ZERO(ts->reset_gpio); 547 + if (error) { 548 + dev_err(dev, "error acquiring reset gpio: %d\n", error); 549 + return error; 550 + } 551 + 552 + error = devm_regulator_get_enable(dev, "vio"); 553 + if (error) { 554 + dev_err(dev, "error acquiring vio regulator: %d\n", error); 555 + return error; 556 + } 557 + 558 + tsc200x_reset(ts); 559 + 515 560 /* Ensure the touchscreen is off */ 516 561 tsc200x_stop_scan(ts); 517 562 518 - error = devm_request_threaded_irq(dev, irq, NULL, 519 - tsc200x_irq_thread, 520 - IRQF_TRIGGER_RISING | IRQF_ONESHOT, 521 - "tsc200x", ts); 563 + error = devm_request_threaded_irq(dev, irq, NULL, tsc200x_irq_thread, 564 + IRQF_ONESHOT, "tsc200x", ts); 522 565 if (error) { 523 566 dev_err(dev, "Failed to request irq, err: %d\n", error); 524 567 return error; 525 568 } 526 - 527 - error = regulator_enable(ts->vio); 528 - if (error) 529 - return error; 530 569 531 570 dev_set_drvdata(dev, ts); 532 571 ··· 543 564 if (error) { 544 565 dev_err(dev, 545 566 "Failed to register input device, err: %d\n", error); 546 - goto disable_regulator; 567 + return error; 547 568 } 548 569 549 - irq_set_irq_wake(irq, 1); 550 - return 0; 570 + device_init_wakeup(dev, 571 + device_property_read_bool(dev, "wakeup-source")); 551 572 552 - disable_regulator: 553 - regulator_disable(ts->vio); 554 - return error; 573 + return 0; 555 574 } 556 575 EXPORT_SYMBOL_GPL(tsc200x_probe); 557 - 558 - void tsc200x_remove(struct device *dev) 559 - { 560 - struct tsc200x *ts = dev_get_drvdata(dev); 561 - 562 - regulator_disable(ts->vio); 563 - } 564 - EXPORT_SYMBOL_GPL(tsc200x_remove); 565 576 566 577 static int tsc200x_suspend(struct device *dev) 567 578 { 568 579 struct tsc200x *ts = dev_get_drvdata(dev); 569 580 570 - mutex_lock(&ts->mutex); 581 + guard(mutex)(&ts->mutex); 571 582 572 583 if (!ts->suspended && ts->opened) 573 584 __tsc200x_disable(ts); 574 585 575 586 ts->suspended = true; 576 587 577 - mutex_unlock(&ts->mutex); 588 + if (device_may_wakeup(dev)) 589 + ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0; 578 590 579 591 return 0; 580 592 } ··· 574 604 { 575 605 struct tsc200x *ts = dev_get_drvdata(dev); 576 606 577 - mutex_lock(&ts->mutex); 607 + guard(mutex)(&ts->mutex); 608 + 609 + if (ts->wake_irq_enabled) { 610 + disable_irq_wake(ts->irq); 611 + ts->wake_irq_enabled = false; 612 + } 578 613 579 614 if (ts->suspended && ts->opened) 580 615 __tsc200x_enable(ts); 581 616 582 617 ts->suspended = false; 583 - 584 - mutex_unlock(&ts->mutex); 585 618 586 619 return 0; 587 620 }
-1
drivers/input/touchscreen/tsc200x-core.h
··· 75 75 int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, 76 76 struct regmap *regmap, 77 77 int (*tsc200x_cmd)(struct device *dev, u8 cmd)); 78 - void tsc200x_remove(struct device *dev); 79 78 80 79 #endif
+448 -508
drivers/input/touchscreen/usbtouchscreen.c
··· 68 68 */ 69 69 bool irq_always; 70 70 71 - void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); 72 - 73 71 /* 74 72 * used to get the packet len. possible return values: 75 73 * > 0: packet len ··· 92 94 struct urb *irq; 93 95 struct usb_interface *interface; 94 96 struct input_dev *input; 95 - struct usbtouch_device_info *type; 97 + const struct usbtouch_device_info *type; 96 98 struct mutex pm_mutex; /* serialize access to open/suspend */ 97 99 bool is_open; 98 100 char name[128]; ··· 101 103 102 104 int x, y; 103 105 int touch, press; 104 - }; 105 106 106 - 107 - /* device types */ 108 - enum { 109 - DEVTYPE_IGNORE = -1, 110 - DEVTYPE_EGALAX, 111 - DEVTYPE_PANJIT, 112 - DEVTYPE_3M, 113 - DEVTYPE_ITM, 114 - DEVTYPE_ETURBO, 115 - DEVTYPE_GUNZE, 116 - DEVTYPE_DMC_TSC10, 117 - DEVTYPE_IRTOUCH, 118 - DEVTYPE_IRTOUCH_HIRES, 119 - DEVTYPE_IDEALTEK, 120 - DEVTYPE_GENERAL_TOUCH, 121 - DEVTYPE_GOTOP, 122 - DEVTYPE_JASTEC, 123 - DEVTYPE_E2I, 124 - DEVTYPE_ZYTRONIC, 125 - DEVTYPE_TC45USB, 126 - DEVTYPE_NEXIO, 127 - DEVTYPE_ELO, 128 - DEVTYPE_ETOUCH, 129 - }; 130 - 131 - #define USB_DEVICE_HID_CLASS(vend, prod) \ 132 - .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS \ 133 - | USB_DEVICE_ID_MATCH_DEVICE, \ 134 - .idVendor = (vend), \ 135 - .idProduct = (prod), \ 136 - .bInterfaceClass = USB_INTERFACE_CLASS_HID 137 - 138 - static const struct usb_device_id usbtouch_devices[] = { 139 - #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 140 - /* ignore the HID capable devices, handled by usbhid */ 141 - {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, 142 - {USB_DEVICE_HID_CLASS(0x0eef, 0x0002), .driver_info = DEVTYPE_IGNORE}, 143 - 144 - /* normal device IDs */ 145 - {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX}, 146 - {USB_DEVICE(0x3823, 0x0002), .driver_info = DEVTYPE_EGALAX}, 147 - {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX}, 148 - {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX}, 149 - {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX}, 150 - {USB_DEVICE(0x1234, 0x0001), .driver_info = DEVTYPE_EGALAX}, 151 - {USB_DEVICE(0x1234, 0x0002), .driver_info = DEVTYPE_EGALAX}, 152 - #endif 153 - 154 - #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT 155 - {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT}, 156 - {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT}, 157 - {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT}, 158 - {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT}, 159 - #endif 160 - 161 - #ifdef CONFIG_TOUCHSCREEN_USB_3M 162 - {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M}, 163 - #endif 164 - 165 - #ifdef CONFIG_TOUCHSCREEN_USB_ITM 166 - {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM}, 167 - {USB_DEVICE(0x16e3, 0xf9e9), .driver_info = DEVTYPE_ITM}, 168 - #endif 169 - 170 - #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO 171 - {USB_DEVICE(0x1234, 0x5678), .driver_info = DEVTYPE_ETURBO}, 172 - #endif 173 - 174 - #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE 175 - {USB_DEVICE(0x0637, 0x0001), .driver_info = DEVTYPE_GUNZE}, 176 - #endif 177 - 178 - #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 179 - {USB_DEVICE(0x0afa, 0x03e8), .driver_info = DEVTYPE_DMC_TSC10}, 180 - #endif 181 - 182 - #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH 183 - {USB_DEVICE(0x255e, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, 184 - {USB_DEVICE(0x595a, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, 185 - {USB_DEVICE(0x6615, 0x0001), .driver_info = DEVTYPE_IRTOUCH}, 186 - {USB_DEVICE(0x6615, 0x0012), .driver_info = DEVTYPE_IRTOUCH_HIRES}, 187 - #endif 188 - 189 - #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK 190 - {USB_DEVICE(0x1391, 0x1000), .driver_info = DEVTYPE_IDEALTEK}, 191 - #endif 192 - 193 - #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 194 - {USB_DEVICE(0x0dfc, 0x0001), .driver_info = DEVTYPE_GENERAL_TOUCH}, 195 - #endif 196 - 197 - #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP 198 - {USB_DEVICE(0x08f2, 0x007f), .driver_info = DEVTYPE_GOTOP}, 199 - {USB_DEVICE(0x08f2, 0x00ce), .driver_info = DEVTYPE_GOTOP}, 200 - {USB_DEVICE(0x08f2, 0x00f4), .driver_info = DEVTYPE_GOTOP}, 201 - #endif 202 - 203 - #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC 204 - {USB_DEVICE(0x0f92, 0x0001), .driver_info = DEVTYPE_JASTEC}, 205 - #endif 206 - 207 - #ifdef CONFIG_TOUCHSCREEN_USB_E2I 208 - {USB_DEVICE(0x1ac7, 0x0001), .driver_info = DEVTYPE_E2I}, 209 - #endif 210 - 211 - #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC 212 - {USB_DEVICE(0x14c8, 0x0003), .driver_info = DEVTYPE_ZYTRONIC}, 213 - #endif 214 - 215 - #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB 216 - /* TC5UH */ 217 - {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC45USB}, 218 - /* TC4UM */ 219 - {USB_DEVICE(0x0664, 0x0306), .driver_info = DEVTYPE_TC45USB}, 220 - #endif 221 - 222 - #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO 223 - /* data interface only */ 224 - {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00), 225 - .driver_info = DEVTYPE_NEXIO}, 226 - {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00), 227 - .driver_info = DEVTYPE_NEXIO}, 228 - #endif 229 - 230 - #ifdef CONFIG_TOUCHSCREEN_USB_ELO 231 - {USB_DEVICE(0x04e7, 0x0020), .driver_info = DEVTYPE_ELO}, 232 - #endif 233 - 234 - #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH 235 - {USB_DEVICE(0x7374, 0x0001), .driver_info = DEVTYPE_ETOUCH}, 236 - #endif 237 - 238 - {} 107 + void (*process_pkt)(struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); 239 108 }; 240 109 241 110 ··· 138 273 139 274 return 1; 140 275 } 276 + 277 + static const struct usbtouch_device_info e2i_dev_info = { 278 + .min_xc = 0x0, 279 + .max_xc = 0x7fff, 280 + .min_yc = 0x0, 281 + .max_yc = 0x7fff, 282 + .rept_size = 6, 283 + .init = e2i_init, 284 + .read_data = e2i_read_data, 285 + }; 141 286 #endif 142 287 143 288 ··· 167 292 168 293 static int egalax_init(struct usbtouch_usb *usbtouch) 169 294 { 170 - int ret, i; 171 - unsigned char *buf; 172 295 struct usb_device *udev = interface_to_usbdev(usbtouch->interface); 296 + int ret, i; 173 297 174 298 /* 175 299 * An eGalax diagnostic packet kicks the device into using the right ··· 176 302 * read later and ignored. 177 303 */ 178 304 179 - buf = kmalloc(3, GFP_KERNEL); 305 + u8 *buf __free(kfree) = kmalloc(3, GFP_KERNEL); 180 306 if (!buf) 181 307 return -ENOMEM; 182 308 ··· 190 316 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 191 317 0, 0, buf, 3, 192 318 USB_CTRL_SET_TIMEOUT); 193 - if (ret >= 0) { 194 - ret = 0; 195 - break; 196 - } 197 319 if (ret != -EPIPE) 198 320 break; 199 321 } 200 322 201 - kfree(buf); 202 - 203 - return ret; 323 + return ret < 0 ? ret : 0; 204 324 } 205 325 206 326 static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt) ··· 224 356 225 357 return 0; 226 358 } 359 + 360 + static const struct usbtouch_device_info egalax_dev_info = { 361 + .min_xc = 0x0, 362 + .max_xc = 0x07ff, 363 + .min_yc = 0x0, 364 + .max_yc = 0x07ff, 365 + .rept_size = 16, 366 + .get_pkt_len = egalax_get_pkt_len, 367 + .read_data = egalax_read_data, 368 + .init = egalax_init, 369 + }; 227 370 #endif 228 371 229 372 /***************************************************************************** ··· 281 402 282 403 return 0; 283 404 } 405 + 406 + static const struct usbtouch_device_info etouch_dev_info = { 407 + .min_xc = 0x0, 408 + .max_xc = 0x07ff, 409 + .min_yc = 0x0, 410 + .max_yc = 0x07ff, 411 + .rept_size = 16, 412 + .get_pkt_len = etouch_get_pkt_len, 413 + .read_data = etouch_read_data, 414 + }; 284 415 #endif 285 416 286 417 /***************************************************************************** ··· 305 416 306 417 return 1; 307 418 } 419 + 420 + static const struct usbtouch_device_info panjit_dev_info = { 421 + .min_xc = 0x0, 422 + .max_xc = 0x0fff, 423 + .min_yc = 0x0, 424 + .max_yc = 0x0fff, 425 + .rept_size = 8, 426 + .read_data = panjit_read_data, 427 + }; 308 428 #endif 309 429 310 430 ··· 347 449 u8 fw_rev_minor; 348 450 }; 349 451 350 - static ssize_t mtouch_firmware_rev_show(struct device *dev, 351 - struct device_attribute *attr, char *output) 352 - { 353 - struct usb_interface *intf = to_usb_interface(dev); 354 - struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 355 - struct mtouch_priv *priv = usbtouch->priv; 356 - 357 - return sysfs_emit(output, "%1x.%1x\n", 358 - priv->fw_rev_major, priv->fw_rev_minor); 359 - } 360 - static DEVICE_ATTR(firmware_rev, 0444, mtouch_firmware_rev_show, NULL); 361 - 362 - static struct attribute *mtouch_attrs[] = { 363 - &dev_attr_firmware_rev.attr, 364 - NULL 365 - }; 366 - 367 - static const struct attribute_group mtouch_attr_group = { 368 - .attrs = mtouch_attrs, 369 - }; 370 - 371 452 static int mtouch_get_fw_revision(struct usbtouch_usb *usbtouch) 372 453 { 373 454 struct usb_device *udev = interface_to_usbdev(usbtouch->interface); 374 455 struct mtouch_priv *priv = usbtouch->priv; 375 - u8 *buf; 376 456 int ret; 377 457 378 - buf = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO); 458 + u8 *buf __free(kfree) = kzalloc(MTOUCHUSB_REQ_CTRLLR_ID_LEN, GFP_NOIO); 379 459 if (!buf) 380 460 return -ENOMEM; 381 461 ··· 365 489 if (ret != MTOUCHUSB_REQ_CTRLLR_ID_LEN) { 366 490 dev_warn(&usbtouch->interface->dev, 367 491 "Failed to read FW rev: %d\n", ret); 368 - ret = ret < 0 ? ret : -EIO; 369 - goto free; 492 + return ret < 0 ? ret : -EIO; 370 493 } 371 494 372 495 priv->fw_rev_major = buf[3]; 373 496 priv->fw_rev_minor = buf[4]; 374 497 375 - ret = 0; 376 - 377 - free: 378 - kfree(buf); 379 - return ret; 498 + return 0; 380 499 } 381 500 382 501 static int mtouch_alloc(struct usbtouch_usb *usbtouch) 383 502 { 384 503 struct mtouch_priv *priv; 385 - int ret; 386 504 387 505 priv = kmalloc(sizeof(*priv), GFP_KERNEL); 388 506 if (!priv) 389 507 return -ENOMEM; 390 508 391 509 usbtouch->priv = priv; 392 - ret = sysfs_create_group(&usbtouch->interface->dev.kobj, 393 - &mtouch_attr_group); 394 - if (ret) { 395 - kfree(usbtouch->priv); 396 - usbtouch->priv = NULL; 397 - return ret; 398 - } 399 - 400 510 return 0; 401 511 } 402 512 ··· 433 571 { 434 572 struct mtouch_priv *priv = usbtouch->priv; 435 573 436 - sysfs_remove_group(&usbtouch->interface->dev.kobj, &mtouch_attr_group); 437 574 kfree(priv); 438 575 } 576 + 577 + static struct usbtouch_device_info mtouch_dev_info = { 578 + .min_xc = 0x0, 579 + .max_xc = 0x4000, 580 + .min_yc = 0x0, 581 + .max_yc = 0x4000, 582 + .rept_size = 11, 583 + .read_data = mtouch_read_data, 584 + .alloc = mtouch_alloc, 585 + .init = mtouch_init, 586 + .exit = mtouch_exit, 587 + }; 588 + 589 + static ssize_t mtouch_firmware_rev_show(struct device *dev, 590 + struct device_attribute *attr, char *output) 591 + { 592 + struct usb_interface *intf = to_usb_interface(dev); 593 + struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 594 + struct mtouch_priv *priv = usbtouch->priv; 595 + 596 + return sysfs_emit(output, "%1x.%1x\n", 597 + priv->fw_rev_major, priv->fw_rev_minor); 598 + } 599 + static DEVICE_ATTR(firmware_rev, 0444, mtouch_firmware_rev_show, NULL); 600 + 601 + static struct attribute *mtouch_attrs[] = { 602 + &dev_attr_firmware_rev.attr, 603 + NULL 604 + }; 605 + 606 + static bool mtouch_group_visible(struct kobject *kobj) 607 + { 608 + struct device *dev = kobj_to_dev(kobj); 609 + struct usb_interface *intf = to_usb_interface(dev); 610 + struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 611 + 612 + return usbtouch->type == &mtouch_dev_info; 613 + } 614 + 615 + DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(mtouch); 616 + 617 + static const struct attribute_group mtouch_attr_group = { 618 + .is_visible = SYSFS_GROUP_VISIBLE(mtouch), 619 + .attrs = mtouch_attrs, 620 + }; 439 621 #endif 440 622 441 623 ··· 514 608 515 609 return 1; 516 610 } 611 + 612 + static const struct usbtouch_device_info itm_dev_info = { 613 + .min_xc = 0x0, 614 + .max_xc = 0x0fff, 615 + .min_yc = 0x0, 616 + .max_yc = 0x0fff, 617 + .max_press = 0xff, 618 + .rept_size = 8, 619 + .read_data = itm_read_data, 620 + }; 517 621 #endif 518 622 519 623 ··· 558 642 return 3; 559 643 return 0; 560 644 } 645 + 646 + static const struct usbtouch_device_info eturbo_dev_info = { 647 + .min_xc = 0x0, 648 + .max_xc = 0x07ff, 649 + .min_yc = 0x0, 650 + .max_yc = 0x07ff, 651 + .rept_size = 8, 652 + .get_pkt_len = eturbo_get_pkt_len, 653 + .read_data = eturbo_read_data, 654 + }; 561 655 #endif 562 656 563 657 ··· 586 660 587 661 return 1; 588 662 } 663 + 664 + static const struct usbtouch_device_info gunze_dev_info = { 665 + .min_xc = 0x0, 666 + .max_xc = 0x0fff, 667 + .min_yc = 0x0, 668 + .max_yc = 0x0fff, 669 + .rept_size = 4, 670 + .read_data = gunze_read_data, 671 + }; 589 672 #endif 590 673 591 674 /***************************************************************************** ··· 623 688 static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) 624 689 { 625 690 struct usb_device *dev = interface_to_usbdev(usbtouch->interface); 626 - int ret = -ENOMEM; 627 - unsigned char *buf; 691 + int ret; 628 692 629 - buf = kmalloc(2, GFP_NOIO); 693 + u8 *buf __free(kfree) = kmalloc(2, GFP_NOIO); 630 694 if (!buf) 631 - goto err_nobuf; 695 + return -ENOMEM; 696 + 632 697 /* reset */ 633 698 buf[0] = buf[1] = 0xFF; 634 699 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 635 - TSC10_CMD_RESET, 636 - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 637 - 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 700 + TSC10_CMD_RESET, 701 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 702 + 0, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 638 703 if (ret < 0) 639 - goto err_out; 640 - if (buf[0] != 0x06) { 641 - ret = -ENODEV; 642 - goto err_out; 643 - } 704 + return ret; 705 + 706 + if (buf[0] != 0x06) 707 + return -ENODEV; 644 708 645 709 /* TSC-25 data sheet specifies a delay after the RESET command */ 646 710 msleep(150); ··· 647 713 /* set coordinate output rate */ 648 714 buf[0] = buf[1] = 0xFF; 649 715 ret = usb_control_msg(dev, usb_rcvctrlpipe (dev, 0), 650 - TSC10_CMD_RATE, 651 - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 652 - TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 716 + TSC10_CMD_RATE, 717 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 718 + TSC10_RATE_150, 0, buf, 2, USB_CTRL_SET_TIMEOUT); 653 719 if (ret < 0) 654 - goto err_out; 655 - if ((buf[0] != 0x06) && (buf[0] != 0x15 || buf[1] != 0x01)) { 656 - ret = -ENODEV; 657 - goto err_out; 658 - } 720 + return ret; 721 + 722 + if (buf[0] != 0x06 && (buf[0] != 0x15 || buf[1] != 0x01)) 723 + return -ENODEV; 659 724 660 725 /* start sending data */ 661 - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 662 - TSC10_CMD_DATA1, 663 - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 664 - 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 665 - err_out: 666 - kfree(buf); 667 - err_nobuf: 668 - return ret; 726 + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 727 + TSC10_CMD_DATA1, 728 + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 729 + 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 669 730 } 670 - 671 731 672 732 static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt) 673 733 { ··· 671 743 672 744 return 1; 673 745 } 746 + 747 + static const struct usbtouch_device_info dmc_tsc10_dev_info = { 748 + .min_xc = 0x0, 749 + .max_xc = 0x03ff, 750 + .min_yc = 0x0, 751 + .max_yc = 0x03ff, 752 + .rept_size = 5, 753 + .init = dmc_tsc10_init, 754 + .read_data = dmc_tsc10_read_data, 755 + }; 674 756 #endif 675 757 676 758 ··· 696 758 697 759 return 1; 698 760 } 761 + 762 + static const struct usbtouch_device_info irtouch_dev_info = { 763 + .min_xc = 0x0, 764 + .max_xc = 0x0fff, 765 + .min_yc = 0x0, 766 + .max_yc = 0x0fff, 767 + .rept_size = 8, 768 + .read_data = irtouch_read_data, 769 + }; 770 + 771 + static const struct usbtouch_device_info irtouch_hires_dev_info = { 772 + .min_xc = 0x0, 773 + .max_xc = 0x7fff, 774 + .min_yc = 0x0, 775 + .max_yc = 0x7fff, 776 + .rept_size = 8, 777 + .read_data = irtouch_read_data, 778 + }; 699 779 #endif 700 780 701 781 /***************************************************************************** ··· 728 772 729 773 return 1; 730 774 } 775 + 776 + static const struct usbtouch_device_info tc45usb_dev_info = { 777 + .min_xc = 0x0, 778 + .max_xc = 0x0fff, 779 + .min_yc = 0x0, 780 + .max_yc = 0x0fff, 781 + .rept_size = 5, 782 + .read_data = tc45usb_read_data, 783 + }; 731 784 #endif 732 785 733 786 /***************************************************************************** ··· 776 811 return 0; 777 812 } 778 813 } 814 + 815 + static const struct usbtouch_device_info idealtek_dev_info = { 816 + .min_xc = 0x0, 817 + .max_xc = 0x0fff, 818 + .min_yc = 0x0, 819 + .max_yc = 0x0fff, 820 + .rept_size = 8, 821 + .get_pkt_len = idealtek_get_pkt_len, 822 + .read_data = idealtek_read_data, 823 + }; 779 824 #endif 780 825 781 826 /***************************************************************************** ··· 801 826 802 827 return 1; 803 828 } 829 + 830 + static const struct usbtouch_device_info general_touch_dev_info = { 831 + .min_xc = 0x0, 832 + .max_xc = 0x7fff, 833 + .min_yc = 0x0, 834 + .max_yc = 0x7fff, 835 + .rept_size = 7, 836 + .read_data = general_touch_read_data, 837 + }; 804 838 #endif 805 839 806 840 /***************************************************************************** ··· 824 840 825 841 return 1; 826 842 } 843 + 844 + static const struct usbtouch_device_info gotop_dev_info = { 845 + .min_xc = 0x0, 846 + .max_xc = 0x03ff, 847 + .min_yc = 0x0, 848 + .max_yc = 0x03ff, 849 + .rept_size = 4, 850 + .read_data = gotop_read_data, 851 + }; 827 852 #endif 828 853 829 854 /***************************************************************************** ··· 847 854 848 855 return 1; 849 856 } 857 + 858 + static const struct usbtouch_device_info jastec_dev_info = { 859 + .min_xc = 0x0, 860 + .max_xc = 0x0fff, 861 + .min_yc = 0x0, 862 + .max_yc = 0x0fff, 863 + .rept_size = 4, 864 + .read_data = jastec_read_data, 865 + }; 850 866 #endif 851 867 852 868 /***************************************************************************** ··· 892 890 893 891 return 0; 894 892 } 893 + 894 + static const struct usbtouch_device_info zytronic_dev_info = { 895 + .min_xc = 0x0, 896 + .max_xc = 0x03ff, 897 + .min_yc = 0x0, 898 + .max_yc = 0x03ff, 899 + .rept_size = 5, 900 + .read_data = zytronic_read_data, 901 + .irq_always = true, 902 + }; 895 903 #endif 896 904 897 905 /***************************************************************************** ··· 972 960 struct nexio_priv *priv = usbtouch->priv; 973 961 int ret = -ENOMEM; 974 962 int actual_len, i; 975 - unsigned char *buf; 976 963 char *firmware_ver = NULL, *device_name = NULL; 977 964 int input_ep = 0, output_ep = 0; 978 965 ··· 987 976 if (!input_ep || !output_ep) 988 977 return -ENXIO; 989 978 990 - buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); 979 + u8 *buf __free(kfree) = kmalloc(NEXIO_BUFSIZE, GFP_NOIO); 991 980 if (!buf) 992 - goto out_buf; 981 + return -ENOMEM; 993 982 994 983 /* two empty reads */ 995 984 for (i = 0; i < 2; i++) { ··· 997 986 buf, NEXIO_BUFSIZE, &actual_len, 998 987 NEXIO_TIMEOUT); 999 988 if (ret < 0) 1000 - goto out_buf; 989 + return ret; 1001 990 } 1002 991 1003 992 /* send init command */ ··· 1006 995 buf, sizeof(nexio_init_pkt), &actual_len, 1007 996 NEXIO_TIMEOUT); 1008 997 if (ret < 0) 1009 - goto out_buf; 998 + return ret; 1010 999 1011 1000 /* read replies */ 1012 1001 for (i = 0; i < 3; i++) { ··· 1037 1026 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep), 1038 1027 priv->ack_buf, sizeof(nexio_ack_pkt), 1039 1028 nexio_ack_complete, usbtouch); 1040 - ret = 0; 1041 1029 1042 - out_buf: 1043 - kfree(buf); 1044 - return ret; 1030 + return 0; 1045 1031 } 1046 1032 1047 1033 static void nexio_exit(struct usbtouch_usb *usbtouch) ··· 1075 1067 if (ret) 1076 1068 dev_warn(dev, "Failed to submit ACK URB: %d\n", ret); 1077 1069 1078 - if (!usbtouch->type->max_xc) { 1079 - usbtouch->type->max_xc = 2 * x_len; 1070 + if (!input_abs_get_max(usbtouch->input, ABS_X)) { 1080 1071 input_set_abs_params(usbtouch->input, ABS_X, 1081 - 0, usbtouch->type->max_xc, 0, 0); 1082 - usbtouch->type->max_yc = 2 * y_len; 1072 + 0, 2 * x_len, 0, 0); 1083 1073 input_set_abs_params(usbtouch->input, ABS_Y, 1084 - 0, usbtouch->type->max_yc, 0, 0); 1074 + 0, 2 * y_len, 0, 0); 1085 1075 } 1086 1076 /* 1087 1077 * The device reports state of IR sensors on X and Y axes. ··· 1134 1128 } 1135 1129 return 0; 1136 1130 } 1131 + 1132 + static const struct usbtouch_device_info nexio_dev_info = { 1133 + .rept_size = 1024, 1134 + .irq_always = true, 1135 + .read_data = nexio_read_data, 1136 + .alloc = nexio_alloc, 1137 + .init = nexio_init, 1138 + .exit = nexio_exit, 1139 + }; 1137 1140 #endif 1138 1141 1139 1142 ··· 1161 1146 1162 1147 return 1; 1163 1148 } 1164 - #endif 1165 1149 1166 - 1167 - /***************************************************************************** 1168 - * the different device descriptors 1169 - */ 1170 - #ifdef MULTI_PACKET 1171 - static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, 1172 - unsigned char *pkt, int len); 1173 - #endif 1174 - 1175 - static struct usbtouch_device_info usbtouch_dev_info[] = { 1176 - #ifdef CONFIG_TOUCHSCREEN_USB_ELO 1177 - [DEVTYPE_ELO] = { 1178 - .min_xc = 0x0, 1179 - .max_xc = 0x0fff, 1180 - .min_yc = 0x0, 1181 - .max_yc = 0x0fff, 1182 - .max_press = 0xff, 1183 - .rept_size = 8, 1184 - .read_data = elo_read_data, 1185 - }, 1186 - #endif 1187 - 1188 - #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 1189 - [DEVTYPE_EGALAX] = { 1190 - .min_xc = 0x0, 1191 - .max_xc = 0x07ff, 1192 - .min_yc = 0x0, 1193 - .max_yc = 0x07ff, 1194 - .rept_size = 16, 1195 - .process_pkt = usbtouch_process_multi, 1196 - .get_pkt_len = egalax_get_pkt_len, 1197 - .read_data = egalax_read_data, 1198 - .init = egalax_init, 1199 - }, 1200 - #endif 1201 - 1202 - #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT 1203 - [DEVTYPE_PANJIT] = { 1204 - .min_xc = 0x0, 1205 - .max_xc = 0x0fff, 1206 - .min_yc = 0x0, 1207 - .max_yc = 0x0fff, 1208 - .rept_size = 8, 1209 - .read_data = panjit_read_data, 1210 - }, 1211 - #endif 1212 - 1213 - #ifdef CONFIG_TOUCHSCREEN_USB_3M 1214 - [DEVTYPE_3M] = { 1215 - .min_xc = 0x0, 1216 - .max_xc = 0x4000, 1217 - .min_yc = 0x0, 1218 - .max_yc = 0x4000, 1219 - .rept_size = 11, 1220 - .read_data = mtouch_read_data, 1221 - .alloc = mtouch_alloc, 1222 - .init = mtouch_init, 1223 - .exit = mtouch_exit, 1224 - }, 1225 - #endif 1226 - 1227 - #ifdef CONFIG_TOUCHSCREEN_USB_ITM 1228 - [DEVTYPE_ITM] = { 1229 - .min_xc = 0x0, 1230 - .max_xc = 0x0fff, 1231 - .min_yc = 0x0, 1232 - .max_yc = 0x0fff, 1233 - .max_press = 0xff, 1234 - .rept_size = 8, 1235 - .read_data = itm_read_data, 1236 - }, 1237 - #endif 1238 - 1239 - #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO 1240 - [DEVTYPE_ETURBO] = { 1241 - .min_xc = 0x0, 1242 - .max_xc = 0x07ff, 1243 - .min_yc = 0x0, 1244 - .max_yc = 0x07ff, 1245 - .rept_size = 8, 1246 - .process_pkt = usbtouch_process_multi, 1247 - .get_pkt_len = eturbo_get_pkt_len, 1248 - .read_data = eturbo_read_data, 1249 - }, 1250 - #endif 1251 - 1252 - #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE 1253 - [DEVTYPE_GUNZE] = { 1254 - .min_xc = 0x0, 1255 - .max_xc = 0x0fff, 1256 - .min_yc = 0x0, 1257 - .max_yc = 0x0fff, 1258 - .rept_size = 4, 1259 - .read_data = gunze_read_data, 1260 - }, 1261 - #endif 1262 - 1263 - #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 1264 - [DEVTYPE_DMC_TSC10] = { 1265 - .min_xc = 0x0, 1266 - .max_xc = 0x03ff, 1267 - .min_yc = 0x0, 1268 - .max_yc = 0x03ff, 1269 - .rept_size = 5, 1270 - .init = dmc_tsc10_init, 1271 - .read_data = dmc_tsc10_read_data, 1272 - }, 1273 - #endif 1274 - 1275 - #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH 1276 - [DEVTYPE_IRTOUCH] = { 1277 - .min_xc = 0x0, 1278 - .max_xc = 0x0fff, 1279 - .min_yc = 0x0, 1280 - .max_yc = 0x0fff, 1281 - .rept_size = 8, 1282 - .read_data = irtouch_read_data, 1283 - }, 1284 - 1285 - [DEVTYPE_IRTOUCH_HIRES] = { 1286 - .min_xc = 0x0, 1287 - .max_xc = 0x7fff, 1288 - .min_yc = 0x0, 1289 - .max_yc = 0x7fff, 1290 - .rept_size = 8, 1291 - .read_data = irtouch_read_data, 1292 - }, 1293 - #endif 1294 - 1295 - #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK 1296 - [DEVTYPE_IDEALTEK] = { 1297 - .min_xc = 0x0, 1298 - .max_xc = 0x0fff, 1299 - .min_yc = 0x0, 1300 - .max_yc = 0x0fff, 1301 - .rept_size = 8, 1302 - .process_pkt = usbtouch_process_multi, 1303 - .get_pkt_len = idealtek_get_pkt_len, 1304 - .read_data = idealtek_read_data, 1305 - }, 1306 - #endif 1307 - 1308 - #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 1309 - [DEVTYPE_GENERAL_TOUCH] = { 1310 - .min_xc = 0x0, 1311 - .max_xc = 0x7fff, 1312 - .min_yc = 0x0, 1313 - .max_yc = 0x7fff, 1314 - .rept_size = 7, 1315 - .read_data = general_touch_read_data, 1316 - }, 1317 - #endif 1318 - 1319 - #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP 1320 - [DEVTYPE_GOTOP] = { 1321 - .min_xc = 0x0, 1322 - .max_xc = 0x03ff, 1323 - .min_yc = 0x0, 1324 - .max_yc = 0x03ff, 1325 - .rept_size = 4, 1326 - .read_data = gotop_read_data, 1327 - }, 1328 - #endif 1329 - 1330 - #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC 1331 - [DEVTYPE_JASTEC] = { 1332 - .min_xc = 0x0, 1333 - .max_xc = 0x0fff, 1334 - .min_yc = 0x0, 1335 - .max_yc = 0x0fff, 1336 - .rept_size = 4, 1337 - .read_data = jastec_read_data, 1338 - }, 1339 - #endif 1340 - 1341 - #ifdef CONFIG_TOUCHSCREEN_USB_E2I 1342 - [DEVTYPE_E2I] = { 1343 - .min_xc = 0x0, 1344 - .max_xc = 0x7fff, 1345 - .min_yc = 0x0, 1346 - .max_yc = 0x7fff, 1347 - .rept_size = 6, 1348 - .init = e2i_init, 1349 - .read_data = e2i_read_data, 1350 - }, 1351 - #endif 1352 - 1353 - #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC 1354 - [DEVTYPE_ZYTRONIC] = { 1355 - .min_xc = 0x0, 1356 - .max_xc = 0x03ff, 1357 - .min_yc = 0x0, 1358 - .max_yc = 0x03ff, 1359 - .rept_size = 5, 1360 - .read_data = zytronic_read_data, 1361 - .irq_always = true, 1362 - }, 1363 - #endif 1364 - 1365 - #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB 1366 - [DEVTYPE_TC45USB] = { 1367 - .min_xc = 0x0, 1368 - .max_xc = 0x0fff, 1369 - .min_yc = 0x0, 1370 - .max_yc = 0x0fff, 1371 - .rept_size = 5, 1372 - .read_data = tc45usb_read_data, 1373 - }, 1374 - #endif 1375 - 1376 - #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO 1377 - [DEVTYPE_NEXIO] = { 1378 - .rept_size = 1024, 1379 - .irq_always = true, 1380 - .read_data = nexio_read_data, 1381 - .alloc = nexio_alloc, 1382 - .init = nexio_init, 1383 - .exit = nexio_exit, 1384 - }, 1385 - #endif 1386 - #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH 1387 - [DEVTYPE_ETOUCH] = { 1388 - .min_xc = 0x0, 1389 - .max_xc = 0x07ff, 1390 - .min_yc = 0x0, 1391 - .max_yc = 0x07ff, 1392 - .rept_size = 16, 1393 - .process_pkt = usbtouch_process_multi, 1394 - .get_pkt_len = etouch_get_pkt_len, 1395 - .read_data = etouch_read_data, 1396 - }, 1397 - #endif 1150 + static const struct usbtouch_device_info elo_dev_info = { 1151 + .min_xc = 0x0, 1152 + .max_xc = 0x0fff, 1153 + .min_yc = 0x0, 1154 + .max_yc = 0x0fff, 1155 + .max_press = 0xff, 1156 + .rept_size = 8, 1157 + .read_data = elo_read_data, 1398 1158 }; 1159 + #endif 1399 1160 1400 1161 1401 1162 /***************************************************************************** ··· 1180 1389 static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, 1181 1390 unsigned char *pkt, int len) 1182 1391 { 1183 - struct usbtouch_device_info *type = usbtouch->type; 1392 + const struct usbtouch_device_info *type = usbtouch->type; 1184 1393 1185 1394 if (!type->read_data(usbtouch, pkt)) 1186 - return; 1395 + return; 1187 1396 1188 1397 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch); 1189 1398 ··· 1276 1485 usbtouch->buf_len = 0; 1277 1486 return; 1278 1487 } 1488 + #else 1489 + static void usbtouch_process_multi(struct usbtouch_usb *usbtouch, 1490 + unsigned char *pkt, int len) 1491 + { 1492 + dev_WARN_ONCE(&usbtouch->interface->dev, 1, 1493 + "Protocol has ->get_pkt_len() without #define MULTI_PACKET"); 1494 + } 1279 1495 #endif 1280 - 1281 1496 1282 1497 static void usbtouch_irq(struct urb *urb) 1283 1498 { ··· 1315 1518 goto exit; 1316 1519 } 1317 1520 1318 - usbtouch->type->process_pkt(usbtouch, usbtouch->data, urb->actual_length); 1521 + usbtouch->process_pkt(usbtouch, usbtouch->data, urb->actual_length); 1319 1522 1320 1523 exit: 1321 1524 usb_mark_last_busy(interface_to_usbdev(usbtouch->interface)); ··· 1323 1526 if (retval) 1324 1527 dev_err(dev, "%s - usb_submit_urb failed with result: %d\n", 1325 1528 __func__, retval); 1529 + } 1530 + 1531 + static int usbtouch_start_io(struct usbtouch_usb *usbtouch) 1532 + { 1533 + guard(mutex)(&usbtouch->pm_mutex); 1534 + 1535 + if (!usbtouch->type->irq_always) 1536 + if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) 1537 + return -EIO; 1538 + 1539 + usbtouch->interface->needs_remote_wakeup = 1; 1540 + usbtouch->is_open = true; 1541 + 1542 + return 0; 1326 1543 } 1327 1544 1328 1545 static int usbtouch_open(struct input_dev *input) ··· 1347 1536 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface); 1348 1537 1349 1538 r = usb_autopm_get_interface(usbtouch->interface) ? -EIO : 0; 1350 - if (r < 0) 1351 - goto out; 1539 + if (r) 1540 + return r; 1352 1541 1353 - mutex_lock(&usbtouch->pm_mutex); 1354 - if (!usbtouch->type->irq_always) { 1355 - if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) { 1356 - r = -EIO; 1357 - goto out_put; 1358 - } 1359 - } 1542 + r = usbtouch_start_io(usbtouch); 1360 1543 1361 - usbtouch->interface->needs_remote_wakeup = 1; 1362 - usbtouch->is_open = true; 1363 - out_put: 1364 - mutex_unlock(&usbtouch->pm_mutex); 1365 1544 usb_autopm_put_interface(usbtouch->interface); 1366 - out: 1367 1545 return r; 1368 1546 } 1369 1547 ··· 1361 1561 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1362 1562 int r; 1363 1563 1364 - mutex_lock(&usbtouch->pm_mutex); 1365 - if (!usbtouch->type->irq_always) 1366 - usb_kill_urb(usbtouch->irq); 1367 - usbtouch->is_open = false; 1368 - mutex_unlock(&usbtouch->pm_mutex); 1564 + scoped_guard(mutex, &usbtouch->pm_mutex) { 1565 + if (!usbtouch->type->irq_always) 1566 + usb_kill_urb(usbtouch->irq); 1567 + usbtouch->is_open = false; 1568 + } 1369 1569 1370 1570 r = usb_autopm_get_interface(usbtouch->interface); 1371 1571 usbtouch->interface->needs_remote_wakeup = 0; ··· 1373 1573 usb_autopm_put_interface(usbtouch->interface); 1374 1574 } 1375 1575 1376 - static int usbtouch_suspend 1377 - (struct usb_interface *intf, pm_message_t message) 1576 + static int usbtouch_suspend(struct usb_interface *intf, pm_message_t message) 1378 1577 { 1379 1578 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 1380 1579 ··· 1385 1586 static int usbtouch_resume(struct usb_interface *intf) 1386 1587 { 1387 1588 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 1388 - int result = 0; 1389 1589 1390 - mutex_lock(&usbtouch->pm_mutex); 1590 + guard(mutex)(&usbtouch->pm_mutex); 1591 + 1391 1592 if (usbtouch->is_open || usbtouch->type->irq_always) 1392 - result = usb_submit_urb(usbtouch->irq, GFP_NOIO); 1393 - mutex_unlock(&usbtouch->pm_mutex); 1593 + return usb_submit_urb(usbtouch->irq, GFP_NOIO); 1394 1594 1395 - return result; 1595 + return 0; 1396 1596 } 1397 1597 1398 1598 static int usbtouch_reset_resume(struct usb_interface *intf) 1399 1599 { 1400 1600 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf); 1401 - int err = 0; 1601 + int err; 1402 1602 1403 1603 /* reinit the device */ 1404 1604 if (usbtouch->type->init) { ··· 1411 1613 } 1412 1614 1413 1615 /* restart IO if needed */ 1414 - mutex_lock(&usbtouch->pm_mutex); 1415 - if (usbtouch->is_open) 1416 - err = usb_submit_urb(usbtouch->irq, GFP_NOIO); 1417 - mutex_unlock(&usbtouch->pm_mutex); 1616 + guard(mutex)(&usbtouch->pm_mutex); 1418 1617 1419 - return err; 1618 + if (usbtouch->is_open) 1619 + return usb_submit_urb(usbtouch->irq, GFP_NOIO); 1620 + 1621 + return 0; 1420 1622 } 1421 1623 1422 1624 static void usbtouch_free_buffers(struct usb_device *udev, ··· 1446 1648 struct input_dev *input_dev; 1447 1649 struct usb_endpoint_descriptor *endpoint; 1448 1650 struct usb_device *udev = interface_to_usbdev(intf); 1449 - struct usbtouch_device_info *type; 1651 + const struct usbtouch_device_info *type; 1450 1652 int err = -ENOMEM; 1451 1653 1452 1654 /* some devices are ignored */ 1453 - if (id->driver_info == DEVTYPE_IGNORE) 1454 - return -ENODEV; 1455 - 1456 - if (id->driver_info >= ARRAY_SIZE(usbtouch_dev_info)) 1655 + type = (const struct usbtouch_device_info *)id->driver_info; 1656 + if (!type) 1457 1657 return -ENODEV; 1458 1658 1459 1659 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting); ··· 1464 1668 goto out_free; 1465 1669 1466 1670 mutex_init(&usbtouch->pm_mutex); 1467 - 1468 - type = &usbtouch_dev_info[id->driver_info]; 1469 1671 usbtouch->type = type; 1470 - if (!type->process_pkt) 1471 - type->process_pkt = usbtouch_process_pkt; 1472 1672 1473 1673 usbtouch->data_size = type->rept_size; 1474 1674 if (type->get_pkt_len) { ··· 1488 1696 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL); 1489 1697 if (!usbtouch->buffer) 1490 1698 goto out_free_buffers; 1699 + usbtouch->process_pkt = usbtouch_process_multi; 1700 + } else { 1701 + usbtouch->process_pkt = usbtouch_process_pkt; 1491 1702 } 1492 1703 1493 1704 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL); ··· 1637 1842 kfree(usbtouch); 1638 1843 } 1639 1844 1845 + static const struct attribute_group *usbtouch_groups[] = { 1846 + #ifdef CONFIG_TOUCHSCREEN_USB_3M 1847 + &mtouch_attr_group, 1848 + #endif 1849 + NULL 1850 + }; 1851 + 1852 + static const struct usb_device_id usbtouch_devices[] = { 1853 + #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 1854 + /* ignore the HID capable devices, handled by usbhid */ 1855 + { USB_DEVICE_INTERFACE_CLASS(0x0eef, 0x0001, USB_INTERFACE_CLASS_HID), 1856 + .driver_info = 0 }, 1857 + { USB_DEVICE_INTERFACE_CLASS(0x0eef, 0x0002, USB_INTERFACE_CLASS_HID), 1858 + .driver_info = 0 }, 1859 + 1860 + /* normal device IDs */ 1861 + { USB_DEVICE(0x3823, 0x0001), 1862 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1863 + { USB_DEVICE(0x3823, 0x0002), 1864 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1865 + { USB_DEVICE(0x0123, 0x0001), 1866 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1867 + { USB_DEVICE(0x0eef, 0x0001), 1868 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1869 + { USB_DEVICE(0x0eef, 0x0002), 1870 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1871 + { USB_DEVICE(0x1234, 0x0001), 1872 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1873 + { USB_DEVICE(0x1234, 0x0002), 1874 + .driver_info = (kernel_ulong_t)&egalax_dev_info }, 1875 + #endif 1876 + 1877 + #ifdef CONFIG_TOUCHSCREEN_USB_PANJIT 1878 + { USB_DEVICE(0x134c, 0x0001), 1879 + .driver_info = (kernel_ulong_t)&panjit_dev_info }, 1880 + { USB_DEVICE(0x134c, 0x0002), 1881 + .driver_info = (kernel_ulong_t)&panjit_dev_info }, 1882 + { USB_DEVICE(0x134c, 0x0003), 1883 + .driver_info = (kernel_ulong_t)&panjit_dev_info }, 1884 + { USB_DEVICE(0x134c, 0x0004), 1885 + .driver_info = (kernel_ulong_t)&panjit_dev_info }, 1886 + #endif 1887 + 1888 + #ifdef CONFIG_TOUCHSCREEN_USB_3M 1889 + { USB_DEVICE(0x0596, 0x0001), 1890 + .driver_info = (kernel_ulong_t)&mtouch_dev_info }, 1891 + #endif 1892 + 1893 + #ifdef CONFIG_TOUCHSCREEN_USB_ITM 1894 + { USB_DEVICE(0x0403, 0xf9e9), 1895 + .driver_info = (kernel_ulong_t)&itm_dev_info }, 1896 + { USB_DEVICE(0x16e3, 0xf9e9), 1897 + .driver_info = (kernel_ulong_t)&itm_dev_info }, 1898 + #endif 1899 + 1900 + #ifdef CONFIG_TOUCHSCREEN_USB_ETURBO 1901 + { USB_DEVICE(0x1234, 0x5678), 1902 + .driver_info = (kernel_ulong_t)&eturbo_dev_info }, 1903 + #endif 1904 + 1905 + #ifdef CONFIG_TOUCHSCREEN_USB_GUNZE 1906 + { USB_DEVICE(0x0637, 0x0001), 1907 + .driver_info = (kernel_ulong_t)&gunze_dev_info }, 1908 + #endif 1909 + 1910 + #ifdef CONFIG_TOUCHSCREEN_USB_DMC_TSC10 1911 + { USB_DEVICE(0x0afa, 0x03e8), 1912 + .driver_info = (kernel_ulong_t)&dmc_tsc10_dev_info }, 1913 + #endif 1914 + 1915 + #ifdef CONFIG_TOUCHSCREEN_USB_IRTOUCH 1916 + { USB_DEVICE(0x255e, 0x0001), 1917 + .driver_info = (kernel_ulong_t)&irtouch_dev_info }, 1918 + { USB_DEVICE(0x595a, 0x0001), 1919 + .driver_info = (kernel_ulong_t)&irtouch_dev_info }, 1920 + { USB_DEVICE(0x6615, 0x0001), 1921 + .driver_info = (kernel_ulong_t)&irtouch_dev_info }, 1922 + { USB_DEVICE(0x6615, 0x0012), 1923 + .driver_info = (kernel_ulong_t)&irtouch_hires_dev_info }, 1924 + #endif 1925 + 1926 + #ifdef CONFIG_TOUCHSCREEN_USB_IDEALTEK 1927 + { USB_DEVICE(0x1391, 0x1000), 1928 + .driver_info = (kernel_ulong_t)&idealtek_dev_info }, 1929 + #endif 1930 + 1931 + #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 1932 + { USB_DEVICE(0x0dfc, 0x0001), 1933 + .driver_info = (kernel_ulong_t)&general_touch_dev_info }, 1934 + #endif 1935 + 1936 + #ifdef CONFIG_TOUCHSCREEN_USB_GOTOP 1937 + { USB_DEVICE(0x08f2, 0x007f), 1938 + .driver_info = (kernel_ulong_t)&gotop_dev_info }, 1939 + { USB_DEVICE(0x08f2, 0x00ce), 1940 + .driver_info = (kernel_ulong_t)&gotop_dev_info }, 1941 + { USB_DEVICE(0x08f2, 0x00f4), 1942 + .driver_info = (kernel_ulong_t)&gotop_dev_info }, 1943 + #endif 1944 + 1945 + #ifdef CONFIG_TOUCHSCREEN_USB_JASTEC 1946 + { USB_DEVICE(0x0f92, 0x0001), 1947 + .driver_info = (kernel_ulong_t)&jastec_dev_info }, 1948 + #endif 1949 + 1950 + #ifdef CONFIG_TOUCHSCREEN_USB_E2I 1951 + { USB_DEVICE(0x1ac7, 0x0001), 1952 + .driver_info = (kernel_ulong_t)&e2i_dev_info }, 1953 + #endif 1954 + 1955 + #ifdef CONFIG_TOUCHSCREEN_USB_ZYTRONIC 1956 + { USB_DEVICE(0x14c8, 0x0003), 1957 + .driver_info = (kernel_ulong_t)&zytronic_dev_info }, 1958 + #endif 1959 + 1960 + #ifdef CONFIG_TOUCHSCREEN_USB_ETT_TC45USB 1961 + /* TC5UH */ 1962 + { USB_DEVICE(0x0664, 0x0309), 1963 + .driver_info = (kernel_ulong_t)&tc45usb_dev_info }, 1964 + /* TC4UM */ 1965 + { USB_DEVICE(0x0664, 0x0306), 1966 + .driver_info = (kernel_ulong_t)&tc45usb_dev_info }, 1967 + #endif 1968 + 1969 + #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO 1970 + /* data interface only */ 1971 + { USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00), 1972 + .driver_info = (kernel_ulong_t)&nexio_dev_info }, 1973 + { USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00), 1974 + .driver_info = (kernel_ulong_t)&nexio_dev_info }, 1975 + #endif 1976 + 1977 + #ifdef CONFIG_TOUCHSCREEN_USB_ELO 1978 + { USB_DEVICE(0x04e7, 0x0020), 1979 + .driver_info = (kernel_ulong_t)&elo_dev_info }, 1980 + #endif 1981 + 1982 + #ifdef CONFIG_TOUCHSCREEN_USB_EASYTOUCH 1983 + { USB_DEVICE(0x7374, 0x0001), 1984 + .driver_info = (kernel_ulong_t)&etouch_dev_info }, 1985 + #endif 1986 + 1987 + { } 1988 + }; 1640 1989 MODULE_DEVICE_TABLE(usb, usbtouch_devices); 1641 1990 1642 1991 static struct usb_driver usbtouch_driver = { ··· 1791 1852 .resume = usbtouch_resume, 1792 1853 .reset_resume = usbtouch_reset_resume, 1793 1854 .id_table = usbtouch_devices, 1855 + .dev_groups = usbtouch_groups, 1794 1856 .supports_autosuspend = 1, 1795 1857 }; 1796 1858
+192 -282
drivers/input/touchscreen/zforce_ts.c
··· 9 9 * Author: Pieter Truter<ptruter@intrinsyc.com> 10 10 */ 11 11 12 - #include <linux/module.h> 13 - #include <linux/hrtimer.h> 14 - #include <linux/slab.h> 15 - #include <linux/input.h> 16 - #include <linux/interrupt.h> 17 - #include <linux/i2c.h> 18 12 #include <linux/delay.h> 19 - #include <linux/gpio/consumer.h> 20 13 #include <linux/device.h> 21 - #include <linux/sysfs.h> 14 + #include <linux/gpio/consumer.h> 15 + #include <linux/i2c.h> 16 + #include <linux/input.h> 22 17 #include <linux/input/mt.h> 23 18 #include <linux/input/touchscreen.h> 24 - #include <linux/platform_data/zforce_ts.h> 25 - #include <linux/regulator/consumer.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/module.h> 26 21 #include <linux/of.h> 22 + #include <linux/property.h> 23 + #include <linux/regulator/consumer.h> 24 + #include <linux/slab.h> 25 + #include <asm/unaligned.h> 27 26 28 27 #define WAIT_TIMEOUT msecs_to_jiffies(1000) 29 28 ··· 96 97 * @suspending in the process of going to suspend (don't emit wakeup 97 98 * events for commands executed to suspend the device) 98 99 * @suspended device suspended 99 - * @access_mutex serialize i2c-access, to keep multipart reads together 100 100 * @command_done completion to wait for the command result 101 - * @command_mutex serialize commands sent to the ic 102 101 * @command_waiting the id of the command that is currently waiting 103 102 * for a result 104 103 * @command_result returned result of the command ··· 105 108 struct i2c_client *client; 106 109 struct input_dev *input; 107 110 struct touchscreen_properties prop; 108 - const struct zforce_ts_platdata *pdata; 109 111 char phys[32]; 110 - 111 - struct regulator *reg_vdd; 112 112 113 113 struct gpio_desc *gpio_int; 114 114 struct gpio_desc *gpio_rst; ··· 120 126 u16 version_build; 121 127 u16 version_rev; 122 128 123 - struct mutex access_mutex; 124 - 125 129 struct completion command_done; 126 - struct mutex command_mutex; 127 130 int command_waiting; 128 131 int command_result; 129 132 }; ··· 137 146 buf[1] = 1; /* data size, command only */ 138 147 buf[2] = cmd; 139 148 140 - mutex_lock(&ts->access_mutex); 141 149 ret = i2c_master_send(client, &buf[0], ARRAY_SIZE(buf)); 142 - mutex_unlock(&ts->access_mutex); 143 150 if (ret < 0) { 144 151 dev_err(&client->dev, "i2c send data request error: %d\n", ret); 145 152 return ret; ··· 146 157 return 0; 147 158 } 148 159 149 - static void zforce_reset_assert(struct zforce_ts *ts) 150 - { 151 - gpiod_set_value_cansleep(ts->gpio_rst, 1); 152 - } 153 - 154 - static void zforce_reset_deassert(struct zforce_ts *ts) 155 - { 156 - gpiod_set_value_cansleep(ts->gpio_rst, 0); 157 - } 158 - 159 160 static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len) 160 161 { 161 162 struct i2c_client *client = ts->client; 162 163 int ret; 163 - 164 - ret = mutex_trylock(&ts->command_mutex); 165 - if (!ret) { 166 - dev_err(&client->dev, "already waiting for a command\n"); 167 - return -EBUSY; 168 - } 169 164 170 165 dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n", 171 166 buf[1], buf[2]); 172 167 173 168 ts->command_waiting = buf[2]; 174 169 175 - mutex_lock(&ts->access_mutex); 176 170 ret = i2c_master_send(client, buf, len); 177 - mutex_unlock(&ts->access_mutex); 178 171 if (ret < 0) { 179 172 dev_err(&client->dev, "i2c send data request error: %d\n", ret); 180 - goto unlock; 173 + return ret; 181 174 } 182 175 183 176 dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]); 184 177 185 - if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) { 186 - ret = -ETIME; 187 - goto unlock; 188 - } 178 + if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) 179 + return -ETIME; 189 180 190 181 ret = ts->command_result; 191 - 192 - unlock: 193 - mutex_unlock(&ts->command_mutex); 194 - return ret; 182 + return 0; 195 183 } 196 184 197 185 static int zforce_command_wait(struct zforce_ts *ts, u8 cmd) 198 186 { 199 187 struct i2c_client *client = ts->client; 200 188 char buf[3]; 201 - int ret; 189 + int error; 202 190 203 191 dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd); 204 192 ··· 183 217 buf[1] = 1; /* data size, command only */ 184 218 buf[2] = cmd; 185 219 186 - ret = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); 187 - if (ret < 0) { 188 - dev_err(&client->dev, "i2c send data request error: %d\n", ret); 189 - return ret; 220 + error = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf)); 221 + if (error) { 222 + dev_err(&client->dev, "i2c send data request error: %d\n", 223 + error); 224 + return error; 190 225 } 191 226 192 227 return 0; ··· 235 268 static int zforce_start(struct zforce_ts *ts) 236 269 { 237 270 struct i2c_client *client = ts->client; 238 - int ret; 271 + int error; 239 272 240 273 dev_dbg(&client->dev, "starting device\n"); 241 274 242 - ret = zforce_command_wait(ts, COMMAND_INITIALIZE); 243 - if (ret) { 244 - dev_err(&client->dev, "Unable to initialize, %d\n", ret); 245 - return ret; 275 + error = zforce_command_wait(ts, COMMAND_INITIALIZE); 276 + if (error) { 277 + dev_err(&client->dev, "Unable to initialize, %d\n", error); 278 + return error; 246 279 } 247 280 248 - ret = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y); 249 - if (ret) { 250 - dev_err(&client->dev, "Unable to set resolution, %d\n", ret); 251 - goto error; 281 + error = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y); 282 + if (error) { 283 + dev_err(&client->dev, "Unable to set resolution, %d\n", error); 284 + goto err_deactivate; 252 285 } 253 286 254 - ret = zforce_scan_frequency(ts, 10, 50, 50); 255 - if (ret) { 287 + error = zforce_scan_frequency(ts, 10, 50, 50); 288 + if (error) { 256 289 dev_err(&client->dev, "Unable to set scan frequency, %d\n", 257 - ret); 258 - goto error; 290 + error); 291 + goto err_deactivate; 259 292 } 260 293 261 - ret = zforce_setconfig(ts, SETCONFIG_DUALTOUCH); 262 - if (ret) { 294 + error = zforce_setconfig(ts, SETCONFIG_DUALTOUCH); 295 + if (error) { 263 296 dev_err(&client->dev, "Unable to set config\n"); 264 - goto error; 297 + goto err_deactivate; 265 298 } 266 299 267 300 /* start sending touch events */ 268 - ret = zforce_command(ts, COMMAND_DATAREQUEST); 269 - if (ret) { 301 + error = zforce_command(ts, COMMAND_DATAREQUEST); 302 + if (error) { 270 303 dev_err(&client->dev, "Unable to request data\n"); 271 - goto error; 304 + goto err_deactivate; 272 305 } 273 306 274 307 /* ··· 279 312 280 313 return 0; 281 314 282 - error: 315 + err_deactivate: 283 316 zforce_command_wait(ts, COMMAND_DEACTIVATE); 284 - return ret; 317 + return error; 285 318 } 286 319 287 320 static int zforce_stop(struct zforce_ts *ts) 288 321 { 289 322 struct i2c_client *client = ts->client; 290 - int ret; 323 + int error; 291 324 292 325 dev_dbg(&client->dev, "stopping device\n"); 293 326 294 327 /* Deactivates touch sensing and puts the device into sleep. */ 295 - ret = zforce_command_wait(ts, COMMAND_DEACTIVATE); 296 - if (ret != 0) { 328 + error = zforce_command_wait(ts, COMMAND_DEACTIVATE); 329 + if (error) { 297 330 dev_err(&client->dev, "could not deactivate device, %d\n", 298 - ret); 299 - return ret; 331 + error); 332 + return error; 300 333 } 301 334 302 335 return 0; ··· 307 340 struct i2c_client *client = ts->client; 308 341 struct zforce_point point; 309 342 int count, i, num = 0; 343 + u8 *p; 310 344 311 345 count = payload[0]; 312 346 if (count > ZFORCE_REPORT_POINTS) { ··· 318 350 } 319 351 320 352 for (i = 0; i < count; i++) { 321 - point.coord_x = 322 - payload[9 * i + 2] << 8 | payload[9 * i + 1]; 323 - point.coord_y = 324 - payload[9 * i + 4] << 8 | payload[9 * i + 3]; 353 + p = &payload[i * 9 + 1]; 354 + 355 + point.coord_x = get_unaligned_le16(&p[0]); 356 + point.coord_y = get_unaligned_le16(&p[2]); 325 357 326 358 if (point.coord_x > ts->prop.max_x || 327 359 point.coord_y > ts->prop.max_y) { ··· 330 362 point.coord_x = point.coord_y = 0; 331 363 } 332 364 333 - point.state = payload[9 * i + 5] & 0x0f; 334 - point.id = (payload[9 * i + 5] & 0xf0) >> 4; 365 + point.state = p[4] & 0x0f; 366 + point.id = (p[4] & 0xf0) >> 4; 335 367 336 368 /* determine touch major, minor and orientation */ 337 - point.area_major = max(payload[9 * i + 6], 338 - payload[9 * i + 7]); 339 - point.area_minor = min(payload[9 * i + 6], 340 - payload[9 * i + 7]); 341 - point.orientation = payload[9 * i + 6] > payload[9 * i + 7]; 369 + point.area_major = max(p[5], p[6]); 370 + point.area_minor = min(p[5], p[6]); 371 + point.orientation = p[5] > p[6]; 342 372 343 - point.pressure = payload[9 * i + 8]; 344 - point.prblty = payload[9 * i + 9]; 373 + point.pressure = p[7]; 374 + point.prblty = p[8]; 345 375 346 376 dev_dbg(&client->dev, 347 377 "point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n", ··· 352 386 /* the zforce id starts with "1", so needs to be decreased */ 353 387 input_mt_slot(ts->input, point.id - 1); 354 388 355 - input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 356 - point.state != STATE_UP); 357 - 358 - if (point.state != STATE_UP) { 389 + if (input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 390 + point.state != STATE_UP)) { 359 391 touchscreen_report_pos(ts->input, &ts->prop, 360 392 point.coord_x, point.coord_y, 361 393 true); ··· 381 417 struct i2c_client *client = ts->client; 382 418 int ret; 383 419 384 - mutex_lock(&ts->access_mutex); 385 - 386 420 /* read 2 byte message header */ 387 421 ret = i2c_master_recv(client, buf, 2); 388 422 if (ret < 0) { 389 423 dev_err(&client->dev, "error reading header: %d\n", ret); 390 - goto unlock; 424 + return ret; 391 425 } 392 426 393 427 if (buf[PAYLOAD_HEADER] != FRAME_START) { 394 428 dev_err(&client->dev, "invalid frame start: %d\n", buf[0]); 395 - ret = -EIO; 396 - goto unlock; 429 + return -EIO; 397 430 } 398 431 399 432 if (buf[PAYLOAD_LENGTH] == 0) { 400 433 dev_err(&client->dev, "invalid payload length: %d\n", 401 434 buf[PAYLOAD_LENGTH]); 402 - ret = -EIO; 403 - goto unlock; 435 + return -EIO; 404 436 } 405 437 406 438 /* read the message */ 407 439 ret = i2c_master_recv(client, &buf[PAYLOAD_BODY], buf[PAYLOAD_LENGTH]); 408 440 if (ret < 0) { 409 441 dev_err(&client->dev, "error reading payload: %d\n", ret); 410 - goto unlock; 442 + return ret; 411 443 } 412 444 413 445 dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n", 414 446 buf[PAYLOAD_LENGTH], buf[PAYLOAD_BODY]); 415 447 416 - unlock: 417 - mutex_unlock(&ts->access_mutex); 418 - return ret; 448 + return 0; 419 449 } 420 450 421 451 static void zforce_complete(struct zforce_ts *ts, int cmd, int result) ··· 440 482 { 441 483 struct zforce_ts *ts = dev_id; 442 484 struct i2c_client *client = ts->client; 443 - int ret; 485 + int error; 444 486 u8 payload_buffer[FRAME_MAXSIZE]; 445 487 u8 *payload; 488 + bool suspending; 446 489 447 490 /* 448 491 * When still suspended, return. ··· 457 498 dev_dbg(&client->dev, "handling interrupt\n"); 458 499 459 500 /* Don't emit wakeup events from commands run by zforce_suspend */ 460 - if (!ts->suspending && device_may_wakeup(&client->dev)) 501 + suspending = READ_ONCE(ts->suspending); 502 + if (!suspending && device_may_wakeup(&client->dev)) 461 503 pm_stay_awake(&client->dev); 462 504 463 505 /* ··· 471 511 * no IRQ any more) 472 512 */ 473 513 do { 474 - ret = zforce_read_packet(ts, payload_buffer); 475 - if (ret < 0) { 514 + error = zforce_read_packet(ts, payload_buffer); 515 + if (error) { 476 516 dev_err(&client->dev, 477 - "could not read packet, ret: %d\n", ret); 517 + "could not read packet, ret: %d\n", error); 478 518 break; 479 519 } 480 520 ··· 486 526 * Always report touch-events received while 487 527 * suspending, when being a wakeup source 488 528 */ 489 - if (ts->suspending && device_may_wakeup(&client->dev)) 529 + if (suspending && device_may_wakeup(&client->dev)) 490 530 pm_wakeup_event(&client->dev, 500); 491 531 zforce_touch_event(ts, &payload[RESPONSE_DATA]); 492 532 break; ··· 510 550 * Version Payload Results 511 551 * [2:major] [2:minor] [2:build] [2:rev] 512 552 */ 513 - ts->version_major = (payload[RESPONSE_DATA + 1] << 8) | 514 - payload[RESPONSE_DATA]; 515 - ts->version_minor = (payload[RESPONSE_DATA + 3] << 8) | 516 - payload[RESPONSE_DATA + 2]; 517 - ts->version_build = (payload[RESPONSE_DATA + 5] << 8) | 518 - payload[RESPONSE_DATA + 4]; 519 - ts->version_rev = (payload[RESPONSE_DATA + 7] << 8) | 520 - payload[RESPONSE_DATA + 6]; 553 + ts->version_major = 554 + get_unaligned_le16(&payload[RESPONSE_DATA]); 555 + ts->version_minor = 556 + get_unaligned_le16(&payload[RESPONSE_DATA + 2]); 557 + ts->version_build = 558 + get_unaligned_le16(&payload[RESPONSE_DATA + 4]); 559 + ts->version_rev = 560 + get_unaligned_le16(&payload[RESPONSE_DATA + 6]); 561 + 521 562 dev_dbg(&ts->client->dev, 522 563 "Firmware Version %04x:%04x %04x:%04x\n", 523 564 ts->version_major, ts->version_minor, ··· 540 579 } 541 580 } while (gpiod_get_value_cansleep(ts->gpio_int)); 542 581 543 - if (!ts->suspending && device_may_wakeup(&client->dev)) 582 + if (!suspending && device_may_wakeup(&client->dev)) 544 583 pm_relax(&client->dev); 545 584 546 585 dev_dbg(&client->dev, "finished interrupt\n"); ··· 559 598 { 560 599 struct zforce_ts *ts = input_get_drvdata(dev); 561 600 struct i2c_client *client = ts->client; 562 - int ret; 601 + int error; 563 602 564 - ret = zforce_stop(ts); 565 - if (ret) 603 + error = zforce_stop(ts); 604 + if (error) 566 605 dev_warn(&client->dev, "stopping zforce failed\n"); 567 - 568 - return; 569 606 } 570 607 571 - static int zforce_suspend(struct device *dev) 608 + static int __zforce_suspend(struct zforce_ts *ts) 572 609 { 573 - struct i2c_client *client = to_i2c_client(dev); 574 - struct zforce_ts *ts = i2c_get_clientdata(client); 610 + struct i2c_client *client = ts->client; 575 611 struct input_dev *input = ts->input; 576 - int ret = 0; 612 + int error; 577 613 578 - mutex_lock(&input->mutex); 579 - ts->suspending = true; 614 + guard(mutex)(&input->mutex); 580 615 581 616 /* 582 617 * When configured as a wakeup source device should always wake ··· 583 626 584 627 /* Need to start device, if not open, to be a wakeup source. */ 585 628 if (!input_device_enabled(input)) { 586 - ret = zforce_start(ts); 587 - if (ret) 588 - goto unlock; 629 + error = zforce_start(ts); 630 + if (error) 631 + return error; 589 632 } 590 633 591 634 enable_irq_wake(client->irq); ··· 593 636 dev_dbg(&client->dev, 594 637 "suspend without being a wakeup source\n"); 595 638 596 - ret = zforce_stop(ts); 597 - if (ret) 598 - goto unlock; 639 + error = zforce_stop(ts); 640 + if (error) 641 + return error; 599 642 600 643 disable_irq(client->irq); 601 644 } 602 645 603 646 ts->suspended = true; 647 + return 0; 648 + } 604 649 605 - unlock: 606 - ts->suspending = false; 607 - mutex_unlock(&input->mutex); 650 + static int zforce_suspend(struct device *dev) 651 + { 652 + struct i2c_client *client = to_i2c_client(dev); 653 + struct zforce_ts *ts = i2c_get_clientdata(client); 654 + int ret; 655 + 656 + WRITE_ONCE(ts->suspending, true); 657 + smp_mb(); 658 + 659 + ret = __zforce_suspend(ts); 660 + 661 + smp_mb(); 662 + WRITE_ONCE(ts->suspending, false); 608 663 609 664 return ret; 610 665 } ··· 626 657 struct i2c_client *client = to_i2c_client(dev); 627 658 struct zforce_ts *ts = i2c_get_clientdata(client); 628 659 struct input_dev *input = ts->input; 629 - int ret = 0; 660 + int error; 630 661 631 - mutex_lock(&input->mutex); 662 + guard(mutex)(&input->mutex); 632 663 633 664 ts->suspended = false; 634 665 ··· 639 670 640 671 /* need to stop device if it was not open on suspend */ 641 672 if (!input_device_enabled(input)) { 642 - ret = zforce_stop(ts); 643 - if (ret) 644 - goto unlock; 673 + error = zforce_stop(ts); 674 + if (error) 675 + return error; 645 676 } 646 677 } else if (input_device_enabled(input)) { 647 678 dev_dbg(&client->dev, "resume without being a wakeup source\n"); 648 679 649 680 enable_irq(client->irq); 650 681 651 - ret = zforce_start(ts); 652 - if (ret < 0) 653 - goto unlock; 682 + error = zforce_start(ts); 683 + if (error) 684 + return error; 654 685 } 655 686 656 - unlock: 657 - mutex_unlock(&input->mutex); 658 - 659 - return ret; 687 + return 0; 660 688 } 661 689 662 690 static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume); ··· 662 696 { 663 697 struct zforce_ts *ts = data; 664 698 665 - zforce_reset_assert(ts); 666 - 699 + gpiod_set_value_cansleep(ts->gpio_rst, 1); 667 700 udelay(10); 668 - 669 - if (!IS_ERR(ts->reg_vdd)) 670 - regulator_disable(ts->reg_vdd); 671 701 } 672 702 673 - static struct zforce_ts_platdata *zforce_parse_dt(struct device *dev) 703 + static void zforce_ts_parse_legacy_properties(struct zforce_ts *ts) 674 704 { 675 - struct zforce_ts_platdata *pdata; 676 - struct device_node *np = dev->of_node; 705 + u32 x_max = 0; 706 + u32 y_max = 0; 677 707 678 - if (!np) 679 - return ERR_PTR(-ENOENT); 708 + device_property_read_u32(&ts->client->dev, "x-size", &x_max); 709 + input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, x_max, 0, 0); 680 710 681 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 682 - if (!pdata) { 683 - dev_err(dev, "failed to allocate platform data\n"); 684 - return ERR_PTR(-ENOMEM); 685 - } 686 - 687 - of_property_read_u32(np, "x-size", &pdata->x_max); 688 - of_property_read_u32(np, "y-size", &pdata->y_max); 689 - 690 - return pdata; 711 + device_property_read_u32(&ts->client->dev, "y-size", &y_max); 712 + input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, y_max, 0, 0); 691 713 } 692 714 693 715 static int zforce_probe(struct i2c_client *client) 694 716 { 695 - const struct zforce_ts_platdata *pdata = dev_get_platdata(&client->dev); 696 717 struct zforce_ts *ts; 697 718 struct input_dev *input_dev; 698 - int ret; 699 - 700 - if (!pdata) { 701 - pdata = zforce_parse_dt(&client->dev); 702 - if (IS_ERR(pdata)) 703 - return PTR_ERR(pdata); 704 - } 719 + int error; 705 720 706 721 ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL); 707 722 if (!ts) ··· 690 743 691 744 ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset", 692 745 GPIOD_OUT_HIGH); 693 - if (IS_ERR(ts->gpio_rst)) { 694 - ret = PTR_ERR(ts->gpio_rst); 695 - dev_err(&client->dev, 696 - "failed to request reset GPIO: %d\n", ret); 697 - return ret; 698 - } 746 + error = PTR_ERR_OR_ZERO(ts->gpio_rst); 747 + if (error) 748 + return dev_err_probe(&client->dev, error, 749 + "failed to request reset GPIO\n"); 699 750 700 751 if (ts->gpio_rst) { 701 752 ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq", 702 753 GPIOD_IN); 703 - if (IS_ERR(ts->gpio_int)) { 704 - ret = PTR_ERR(ts->gpio_int); 705 - dev_err(&client->dev, 706 - "failed to request interrupt GPIO: %d\n", ret); 707 - return ret; 708 - } 754 + error = PTR_ERR_OR_ZERO(ts->gpio_int); 755 + if (error) 756 + return dev_err_probe(&client->dev, error, 757 + "failed to request interrupt GPIO\n"); 709 758 } else { 710 759 /* 711 760 * Deprecated GPIO handling for compatibility ··· 711 768 /* INT GPIO */ 712 769 ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0, 713 770 GPIOD_IN); 714 - if (IS_ERR(ts->gpio_int)) { 715 - ret = PTR_ERR(ts->gpio_int); 716 - dev_err(&client->dev, 717 - "failed to request interrupt GPIO: %d\n", ret); 718 - return ret; 719 - } 771 + 772 + error = PTR_ERR_OR_ZERO(ts->gpio_int); 773 + if (error) 774 + return dev_err_probe(&client->dev, error, 775 + "failed to request interrupt GPIO\n"); 720 776 721 777 /* RST GPIO */ 722 778 ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1, 723 779 GPIOD_OUT_HIGH); 724 - if (IS_ERR(ts->gpio_rst)) { 725 - ret = PTR_ERR(ts->gpio_rst); 726 - dev_err(&client->dev, 727 - "failed to request reset GPIO: %d\n", ret); 728 - return ret; 729 - } 780 + error = PTR_ERR_OR_ZERO(ts->gpio_rst); 781 + if (error) 782 + return dev_err_probe(&client->dev, error, 783 + "failed to request reset GPIO\n"); 730 784 } 731 785 732 - ts->reg_vdd = devm_regulator_get_optional(&client->dev, "vdd"); 733 - if (IS_ERR(ts->reg_vdd)) { 734 - ret = PTR_ERR(ts->reg_vdd); 735 - if (ret == -EPROBE_DEFER) 736 - return ret; 737 - } else { 738 - ret = regulator_enable(ts->reg_vdd); 739 - if (ret) 740 - return ret; 786 + error = devm_regulator_get_enable(&client->dev, "vdd"); 787 + if (error) 788 + return dev_err_probe(&client->dev, error, 789 + "failed to request vdd supply\n"); 741 790 742 - /* 743 - * according to datasheet add 100us grace time after regular 744 - * regulator enable delay. 745 - */ 746 - udelay(100); 747 - } 791 + /* 792 + * According to datasheet add 100us grace time after regular 793 + * regulator enable delay. 794 + */ 795 + usleep_range(100, 200); 748 796 749 - ret = devm_add_action(&client->dev, zforce_reset, ts); 750 - if (ret) { 751 - dev_err(&client->dev, "failed to register reset action, %d\n", 752 - ret); 753 - 754 - /* hereafter the regulator will be disabled by the action */ 755 - if (!IS_ERR(ts->reg_vdd)) 756 - regulator_disable(ts->reg_vdd); 757 - 758 - return ret; 759 - } 797 + error = devm_add_action_or_reset(&client->dev, zforce_reset, ts); 798 + if (error) 799 + return dev_err_probe(&client->dev, error, 800 + "failed to register reset action\n"); 760 801 761 802 snprintf(ts->phys, sizeof(ts->phys), 762 803 "%s/input0", dev_name(&client->dev)); 763 804 764 805 input_dev = devm_input_allocate_device(&client->dev); 765 - if (!input_dev) { 766 - dev_err(&client->dev, "could not allocate input device\n"); 767 - return -ENOMEM; 768 - } 806 + if (!input_dev) 807 + return dev_err_probe(&client->dev, -ENOMEM, 808 + "could not allocate input device\n"); 769 809 770 - mutex_init(&ts->access_mutex); 771 - mutex_init(&ts->command_mutex); 772 - 773 - ts->pdata = pdata; 774 810 ts->client = client; 775 811 ts->input = input_dev; 776 812 ··· 760 838 input_dev->open = zforce_input_open; 761 839 input_dev->close = zforce_input_close; 762 840 763 - __set_bit(EV_KEY, input_dev->evbit); 764 - __set_bit(EV_SYN, input_dev->evbit); 765 - __set_bit(EV_ABS, input_dev->evbit); 766 - 767 - /* For multi touch */ 768 - input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 769 - pdata->x_max, 0, 0); 770 - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 771 - pdata->y_max, 0, 0); 772 - 841 + zforce_ts_parse_legacy_properties(ts); 773 842 touchscreen_parse_properties(input_dev, true, &ts->prop); 774 - if (ts->prop.max_x == 0 || ts->prop.max_y == 0) { 775 - dev_err(&client->dev, "no size specified\n"); 776 - return -EINVAL; 777 - } 843 + if (ts->prop.max_x == 0 || ts->prop.max_y == 0) 844 + return dev_err_probe(&client->dev, -EINVAL, "no size specified"); 778 845 779 846 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 780 847 ZFORCE_MAX_AREA, 0, 0); 781 848 input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0, 782 849 ZFORCE_MAX_AREA, 0, 0); 783 850 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0); 784 - input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS, INPUT_MT_DIRECT); 851 + 852 + error = input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS, 853 + INPUT_MT_DIRECT); 854 + if (error) 855 + return error; 785 856 786 857 input_set_drvdata(ts->input, ts); 787 858 ··· 787 872 * Therefore we can trigger the interrupt anytime it is low and do 788 873 * not need to limit it to the interrupt edge. 789 874 */ 790 - ret = devm_request_threaded_irq(&client->dev, client->irq, 791 - zforce_irq, zforce_irq_thread, 792 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 793 - input_dev->name, ts); 794 - if (ret) { 795 - dev_err(&client->dev, "irq %d request failed\n", client->irq); 796 - return ret; 797 - } 875 + error = devm_request_threaded_irq(&client->dev, client->irq, 876 + zforce_irq, zforce_irq_thread, 877 + IRQF_ONESHOT, input_dev->name, ts); 878 + if (error) 879 + return dev_err_probe(&client->dev, error, 880 + "irq %d request failed\n", client->irq); 798 881 799 882 i2c_set_clientdata(client, ts); 800 883 801 884 /* let the controller boot */ 802 - zforce_reset_deassert(ts); 885 + gpiod_set_value_cansleep(ts->gpio_rst, 0); 803 886 804 887 ts->command_waiting = NOTIFICATION_BOOTCOMPLETE; 805 888 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0) 806 889 dev_warn(&client->dev, "bootcomplete timed out\n"); 807 890 808 891 /* need to start device to get version information */ 809 - ret = zforce_command_wait(ts, COMMAND_INITIALIZE); 810 - if (ret) { 811 - dev_err(&client->dev, "unable to initialize, %d\n", ret); 812 - return ret; 813 - } 892 + error = zforce_command_wait(ts, COMMAND_INITIALIZE); 893 + if (error) 894 + return dev_err_probe(&client->dev, error, "unable to initialize\n"); 814 895 815 896 /* this gets the firmware version among other information */ 816 - ret = zforce_command_wait(ts, COMMAND_STATUS); 817 - if (ret < 0) { 818 - dev_err(&client->dev, "couldn't get status, %d\n", ret); 897 + error = zforce_command_wait(ts, COMMAND_STATUS); 898 + if (error) { 899 + dev_err_probe(&client->dev, error, "couldn't get status\n"); 819 900 zforce_stop(ts); 820 - return ret; 901 + return error; 821 902 } 822 903 823 904 /* stop device and put it into sleep until it is opened */ 824 - ret = zforce_stop(ts); 825 - if (ret < 0) 826 - return ret; 905 + error = zforce_stop(ts); 906 + if (error) 907 + return error; 827 908 828 909 device_set_wakeup_capable(&client->dev, true); 829 910 830 - ret = input_register_device(input_dev); 831 - if (ret) { 832 - dev_err(&client->dev, "could not register input device, %d\n", 833 - ret); 834 - return ret; 835 - } 911 + error = input_register_device(input_dev); 912 + if (error) 913 + return dev_err_probe(&client->dev, error, 914 + "could not register input device\n"); 836 915 837 916 return 0; 838 917 } 839 918 840 - static struct i2c_device_id zforce_idtable[] = { 919 + static const struct i2c_device_id zforce_idtable[] = { 841 920 { "zforce-ts" }, 842 921 { } 843 922 }; ··· 850 941 .name = "zforce-ts", 851 942 .pm = pm_sleep_ptr(&zforce_pm_ops), 852 943 .of_match_table = of_match_ptr(zforce_dt_idtable), 944 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 853 945 }, 854 946 .probe = zforce_probe, 855 947 .id_table = zforce_idtable,
+130 -4
drivers/input/touchscreen/zinitix.c
··· 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 12 #include <linux/of.h> 13 + #include <linux/property.h> 13 14 #include <linux/regulator/consumer.h> 14 15 #include <linux/slab.h> 15 16 ··· 35 34 #define ZINITIX_DEBUG_REG 0x0115 /* 0~7 */ 36 35 37 36 #define ZINITIX_TOUCH_MODE 0x0010 37 + 38 38 #define ZINITIX_CHIP_REVISION 0x0011 39 + #define ZINITIX_CHIP_BTX0X_MASK 0xF0F0 40 + #define ZINITIX_CHIP_BT4X2 0x4020 41 + #define ZINITIX_CHIP_BT4X3 0x4030 42 + #define ZINITIX_CHIP_BT4X4 0x4040 43 + 39 44 #define ZINITIX_FIRMWARE_VERSION 0x0012 40 45 41 46 #define ZINITIX_USB_DETECT 0x116 ··· 69 62 #define ZINITIX_Y_RESOLUTION 0x00C1 70 63 71 64 #define ZINITIX_POINT_STATUS_REG 0x0080 72 - #define ZINITIX_ICON_STATUS_REG 0x00AA 65 + 66 + #define ZINITIX_BT4X2_ICON_STATUS_REG 0x009A 67 + #define ZINITIX_BT4X3_ICON_STATUS_REG 0x00A0 68 + #define ZINITIX_BT4X4_ICON_STATUS_REG 0x00A0 69 + #define ZINITIX_BT5XX_ICON_STATUS_REG 0x00AA 73 70 74 71 #define ZINITIX_POINT_COORD_REG (ZINITIX_POINT_STATUS_REG + 2) 75 72 ··· 130 119 131 120 #define DEFAULT_TOUCH_POINT_MODE 2 132 121 #define MAX_SUPPORTED_FINGER_NUM 5 122 + #define MAX_SUPPORTED_BUTTON_NUM 8 133 123 134 124 #define CHIP_ON_DELAY 15 // ms 135 125 #define FIRMWARE_ON_DELAY 40 // ms ··· 158 146 struct touchscreen_properties prop; 159 147 struct regulator_bulk_data supplies[2]; 160 148 u32 zinitix_mode; 149 + u32 keycodes[MAX_SUPPORTED_BUTTON_NUM]; 150 + int num_keycodes; 151 + bool have_versioninfo; 152 + u16 chip_revision; 153 + u16 firmware_version; 154 + u16 regdata_version; 155 + u16 icon_status_reg; 161 156 }; 162 157 163 158 static int zinitix_read_data(struct i2c_client *client, ··· 209 190 return 0; 210 191 } 211 192 193 + static u16 zinitix_get_u16_reg(struct bt541_ts_data *bt541, u16 vreg) 194 + { 195 + struct i2c_client *client = bt541->client; 196 + int error; 197 + __le16 val; 198 + 199 + error = zinitix_read_data(client, vreg, (void *)&val, 2); 200 + if (error) 201 + return U8_MAX; 202 + 203 + return le16_to_cpu(val); 204 + } 205 + 212 206 static int zinitix_init_touch(struct bt541_ts_data *bt541) 213 207 { 214 208 struct i2c_client *client = bt541->client; 215 209 int i; 216 210 int error; 211 + u16 int_flags; 217 212 218 213 error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); 219 214 if (error) { 220 215 dev_err(&client->dev, "Failed to write reset command\n"); 221 216 return error; 217 + } 218 + 219 + /* 220 + * Read and cache the chip revision and firmware version the first time 221 + * we get here. 222 + */ 223 + if (!bt541->have_versioninfo) { 224 + bt541->chip_revision = zinitix_get_u16_reg(bt541, 225 + ZINITIX_CHIP_REVISION); 226 + bt541->firmware_version = zinitix_get_u16_reg(bt541, 227 + ZINITIX_FIRMWARE_VERSION); 228 + bt541->regdata_version = zinitix_get_u16_reg(bt541, 229 + ZINITIX_DATA_VERSION_REG); 230 + bt541->have_versioninfo = true; 231 + 232 + dev_dbg(&client->dev, 233 + "chip revision %04x firmware version %04x regdata version %04x\n", 234 + bt541->chip_revision, bt541->firmware_version, 235 + bt541->regdata_version); 236 + 237 + /* 238 + * Determine the "icon" status register which varies by the 239 + * chip. 240 + */ 241 + switch (bt541->chip_revision & ZINITIX_CHIP_BTX0X_MASK) { 242 + case ZINITIX_CHIP_BT4X2: 243 + bt541->icon_status_reg = ZINITIX_BT4X2_ICON_STATUS_REG; 244 + break; 245 + 246 + case ZINITIX_CHIP_BT4X3: 247 + bt541->icon_status_reg = ZINITIX_BT4X3_ICON_STATUS_REG; 248 + break; 249 + 250 + case ZINITIX_CHIP_BT4X4: 251 + bt541->icon_status_reg = ZINITIX_BT4X4_ICON_STATUS_REG; 252 + break; 253 + 254 + default: 255 + bt541->icon_status_reg = ZINITIX_BT5XX_ICON_STATUS_REG; 256 + break; 257 + } 222 258 } 223 259 224 260 error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); ··· 299 225 if (error) 300 226 return error; 301 227 228 + error = zinitix_write_u16(client, ZINITIX_BUTTON_SUPPORTED_NUM, 229 + bt541->num_keycodes); 230 + if (error) 231 + return error; 232 + 302 233 error = zinitix_write_u16(client, ZINITIX_INITIAL_TOUCH_MODE, 303 234 bt541->zinitix_mode); 304 235 if (error) ··· 314 235 if (error) 315 236 return error; 316 237 317 - error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 318 - BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | 319 - BIT_UP); 238 + int_flags = BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | BIT_UP; 239 + if (bt541->num_keycodes) 240 + int_flags |= BIT_ICON_EVENT; 241 + 242 + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, int_flags); 320 243 if (error) 321 244 return error; 322 245 ··· 431 350 } 432 351 } 433 352 353 + static void zinitix_report_keys(struct bt541_ts_data *bt541, u16 icon_events) 354 + { 355 + int i; 356 + 357 + for (i = 0; i < bt541->num_keycodes; i++) 358 + input_report_key(bt541->input_dev, 359 + bt541->keycodes[i], icon_events & BIT(i)); 360 + } 361 + 434 362 static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) 435 363 { 436 364 struct bt541_ts_data *bt541 = bt541_handler; 437 365 struct i2c_client *client = bt541->client; 438 366 struct touch_event touch_event; 439 367 unsigned long finger_mask; 368 + __le16 icon_events; 440 369 int error; 441 370 int i; 442 371 ··· 457 366 if (error) { 458 367 dev_err(&client->dev, "Failed to read in touchpoint struct\n"); 459 368 goto out; 369 + } 370 + 371 + if (le16_to_cpu(touch_event.status) & BIT_ICON_EVENT) { 372 + error = zinitix_read_data(bt541->client, bt541->icon_status_reg, 373 + &icon_events, sizeof(icon_events)); 374 + if (error) { 375 + dev_err(&client->dev, "Failed to read icon events\n"); 376 + goto out; 377 + } 378 + 379 + zinitix_report_keys(bt541, le16_to_cpu(icon_events)); 460 380 } 461 381 462 382 finger_mask = touch_event.finger_mask; ··· 555 453 { 556 454 struct input_dev *input_dev; 557 455 int error; 456 + int i; 558 457 559 458 input_dev = devm_input_allocate_device(&bt541->client->dev); 560 459 if (!input_dev) { ··· 572 469 input_dev->id.bustype = BUS_I2C; 573 470 input_dev->open = zinitix_input_open; 574 471 input_dev->close = zinitix_input_close; 472 + 473 + if (bt541->num_keycodes) { 474 + input_dev->keycode = bt541->keycodes; 475 + input_dev->keycodemax = bt541->num_keycodes; 476 + input_dev->keycodesize = sizeof(bt541->keycodes[0]); 477 + for (i = 0; i < bt541->num_keycodes; i++) 478 + input_set_capability(input_dev, EV_KEY, bt541->keycodes[i]); 479 + } 575 480 576 481 input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); 577 482 input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); ··· 642 531 client->name, bt541); 643 532 if (error) { 644 533 dev_err(&client->dev, "Failed to request IRQ: %d\n", error); 534 + return error; 535 + } 536 + 537 + bt541->num_keycodes = device_property_count_u32(&client->dev, "linux,keycodes"); 538 + if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) { 539 + dev_err(&client->dev, "too many keys defined (%d)\n", bt541->num_keycodes); 540 + return -EINVAL; 541 + } 542 + 543 + error = device_property_read_u32_array(&client->dev, "linux,keycodes", 544 + bt541->keycodes, 545 + bt541->num_keycodes); 546 + if (error) { 547 + dev_err(&client->dev, 548 + "Unable to parse \"linux,keycodes\" property: %d\n", error); 645 549 return error; 646 550 } 647 551
-48
include/linux/input/matrix_keypad.h
··· 34 34 unsigned int keymap_size; 35 35 }; 36 36 37 - /** 38 - * struct matrix_keypad_platform_data - platform-dependent keypad data 39 - * @keymap_data: pointer to &matrix_keymap_data 40 - * @row_gpios: pointer to array of gpio numbers representing rows 41 - * @col_gpios: pointer to array of gpio numbers reporesenting colums 42 - * @num_row_gpios: actual number of row gpios used by device 43 - * @num_col_gpios: actual number of col gpios used by device 44 - * @col_scan_delay_us: delay, measured in microseconds, that is 45 - * needed before we can keypad after activating column gpio 46 - * @debounce_ms: debounce interval in milliseconds 47 - * @clustered_irq: may be specified if interrupts of all row/column GPIOs 48 - * are bundled to one single irq 49 - * @clustered_irq_flags: flags that are needed for the clustered irq 50 - * @active_low: gpio polarity 51 - * @wakeup: controls whether the device should be set up as wakeup 52 - * source 53 - * @no_autorepeat: disable key autorepeat 54 - * @drive_inactive_cols: drive inactive columns during scan, rather than 55 - * making them inputs. 56 - * 57 - * This structure represents platform-specific data that use used by 58 - * matrix_keypad driver to perform proper initialization. 59 - */ 60 - struct matrix_keypad_platform_data { 61 - const struct matrix_keymap_data *keymap_data; 62 - 63 - const unsigned int *row_gpios; 64 - const unsigned int *col_gpios; 65 - 66 - unsigned int num_row_gpios; 67 - unsigned int num_col_gpios; 68 - 69 - unsigned int col_scan_delay_us; 70 - 71 - /* key debounce interval in milli-second */ 72 - unsigned int debounce_ms; 73 - 74 - unsigned int clustered_irq; 75 - unsigned int clustered_irq_flags; 76 - 77 - bool active_low; 78 - bool wakeup; 79 - bool no_autorepeat; 80 - bool drive_inactive_cols; 81 - }; 82 - 83 37 int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, 84 38 const char *keymap_name, 85 39 unsigned int rows, unsigned int cols, ··· 41 87 struct input_dev *input_dev); 42 88 int matrix_keypad_parse_properties(struct device *dev, 43 89 unsigned int *rows, unsigned int *cols); 44 - 45 - #define matrix_keypad_parse_of_params matrix_keypad_parse_properties 46 90 47 91 #endif /* _MATRIX_KEYPAD_H */
-62
include/linux/platform_data/cyttsp4.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Header file for: 4 - * Cypress TrueTouch(TM) Standard Product (TTSP) touchscreen drivers. 5 - * For use with Cypress Txx3xx parts. 6 - * Supported parts include: 7 - * CY8CTST341 8 - * CY8CTMA340 9 - * 10 - * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 11 - * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 12 - * 13 - * Contact Cypress Semiconductor at www.cypress.com (kev@cypress.com) 14 - */ 15 - #ifndef _CYTTSP4_H_ 16 - #define _CYTTSP4_H_ 17 - 18 - #define CYTTSP4_MT_NAME "cyttsp4_mt" 19 - #define CYTTSP4_I2C_NAME "cyttsp4_i2c_adapter" 20 - #define CYTTSP4_SPI_NAME "cyttsp4_spi_adapter" 21 - 22 - #define CY_TOUCH_SETTINGS_MAX 32 23 - 24 - struct touch_framework { 25 - const uint16_t *abs; 26 - uint8_t size; 27 - uint8_t enable_vkeys; 28 - } __packed; 29 - 30 - struct cyttsp4_mt_platform_data { 31 - struct touch_framework *frmwrk; 32 - unsigned short flags; 33 - char const *inp_dev_name; 34 - }; 35 - 36 - struct touch_settings { 37 - const uint8_t *data; 38 - uint32_t size; 39 - uint8_t tag; 40 - } __packed; 41 - 42 - struct cyttsp4_core_platform_data { 43 - int irq_gpio; 44 - int rst_gpio; 45 - int level_irq_udelay; 46 - int (*xres)(struct cyttsp4_core_platform_data *pdata, 47 - struct device *dev); 48 - int (*init)(struct cyttsp4_core_platform_data *pdata, 49 - int on, struct device *dev); 50 - int (*power)(struct cyttsp4_core_platform_data *pdata, 51 - int on, struct device *dev, atomic_t *ignore_irq); 52 - int (*irq_stat)(struct cyttsp4_core_platform_data *pdata, 53 - struct device *dev); 54 - struct touch_settings *sett[CY_TOUCH_SETTINGS_MAX]; 55 - }; 56 - 57 - struct cyttsp4_platform_data { 58 - struct cyttsp4_core_platform_data *core_pdata; 59 - struct cyttsp4_mt_platform_data *mt_pdata; 60 - }; 61 - 62 - #endif /* _CYTTSP4_H_ */
-50
include/linux/platform_data/keypad-nomadik-ske.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) ST-Ericsson SA 2010 4 - * 5 - * Author: Naveen Kumar Gaddipati <naveen.gaddipati@stericsson.com> 6 - * 7 - * ux500 Scroll key and Keypad Encoder (SKE) header 8 - */ 9 - 10 - #ifndef __SKE_H 11 - #define __SKE_H 12 - 13 - #include <linux/input/matrix_keypad.h> 14 - 15 - /* register definitions for SKE peripheral */ 16 - #define SKE_CR 0x00 17 - #define SKE_VAL0 0x04 18 - #define SKE_VAL1 0x08 19 - #define SKE_DBCR 0x0C 20 - #define SKE_IMSC 0x10 21 - #define SKE_RIS 0x14 22 - #define SKE_MIS 0x18 23 - #define SKE_ICR 0x1C 24 - 25 - /* 26 - * Keypad module 27 - */ 28 - 29 - /** 30 - * struct keypad_platform_data - structure for platform specific data 31 - * @init: pointer to keypad init function 32 - * @exit: pointer to keypad deinitialisation function 33 - * @keymap_data: matrix scan code table for keycodes 34 - * @krow: maximum number of rows 35 - * @kcol: maximum number of columns 36 - * @debounce_ms: platform specific debounce time 37 - * @no_autorepeat: flag for auto repetition 38 - * @wakeup_enable: allow waking up the system 39 - */ 40 - struct ske_keypad_platform_data { 41 - int (*init)(void); 42 - int (*exit)(void); 43 - const struct matrix_keymap_data *keymap_data; 44 - u8 krow; 45 - u8 kcol; 46 - u8 debounce_ms; 47 - bool no_autorepeat; 48 - bool wakeup_enable; 49 - }; 50 - #endif /*__SKE_KPD_H*/
-30
include/linux/platform_data/mcs.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 - /* 3 - * Copyright (C) 2009 - 2010 Samsung Electronics Co.Ltd 4 - * Author: Joonyoung Shim <jy0922.shim@samsung.com> 5 - * Author: HeungJun Kim <riverful.kim@samsung.com> 6 - */ 7 - 8 - #ifndef __LINUX_MCS_H 9 - #define __LINUX_MCS_H 10 - 11 - #define MCS_KEY_MAP(v, c) ((((v) & 0xff) << 16) | ((c) & 0xffff)) 12 - #define MCS_KEY_VAL(v) (((v) >> 16) & 0xff) 13 - #define MCS_KEY_CODE(v) ((v) & 0xffff) 14 - 15 - struct mcs_platform_data { 16 - void (*poweron)(bool); 17 - void (*cfg_pin)(void); 18 - 19 - /* touchscreen */ 20 - unsigned int x_size; 21 - unsigned int y_size; 22 - 23 - /* touchkey */ 24 - const u32 *keymap; 25 - unsigned int keymap_size; 26 - unsigned int key_maxval; 27 - bool no_autorepeat; 28 - }; 29 - 30 - #endif /* __LINUX_MCS_H */
-15
include/linux/platform_data/zforce_ts.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* drivers/input/touchscreen/zforce.c 3 - * 4 - * Copyright (C) 2012-2013 MundoReader S.L. 5 - */ 6 - 7 - #ifndef _LINUX_INPUT_ZFORCE_TS_H 8 - #define _LINUX_INPUT_ZFORCE_TS_H 9 - 10 - struct zforce_ts_platdata { 11 - unsigned int x_max; 12 - unsigned int y_max; 13 - }; 14 - 15 - #endif /* _LINUX_INPUT_ZFORCE_TS_H */