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

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

Pull input updates from Dmitry Torokhov:

- Conversions to yaml/json schema and fixes for input-related device
tree bindings

- New drivers:
- Awinic AW86927 haptic chip
- Hynitron CST816x series controller
- Himax HX852x(ES) touchscreen controller

- Fix uinput to not leak kernel memory via a gap in
uinput_ff_upload_compat structure

- Prevent overflow in pressure calculation in tsc2007 driver causing
phantom touches

- Make the Atmel maxTouch driver support generic touchscreen
configuration (flip, rotate, etc)

- Drop support for platform data in tca8418_keypad, pxa27x-keypad,
spear-keyboard and twl4030_keypad drivers, they all now rely on
generic device properties for configuration

- Other assorted changes and fixes

* tag 'input-for-v6.18-rc0' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (50 commits)
Input: atmel_mxt_ts - allow reset GPIO to sleep
Input: aw86927 - fix error code in probe()
Input: psxpad-spi - add a check for the return value of spi_setup()
Input: uinput - zero-initialize uinput_ff_upload_compat to avoid info leak
Input: aw86927 - add driver for Awinic AW86927
dt-bindings: input: Add Awinic AW86927
dt-bindings: touchscreen: remove touchscreen.txt
dt-bindings: arm: bcm: raspberrypi,bcm2835-firmware: Add touchscreen child node
dt-bindings: touchscreen: convert eeti bindings to json schema
Input: pm8941-pwrkey - disable wakeup for resin by default
dt-bindings: input: pm8941-pwrkey: Document wakeup-source property
Input: add driver for Hynitron CST816x series
dt-bindings: input: touchscreen: add hynitron cst816x series
Input: imx6ul_tsc - set glitch threshold by DTS property
dt-bindings: touchscreen: fsl,imx6ul-tsc: support glitch thresold
dt-bindings: touchscreen: add debounce-delay-us property
Input: ps2-gpio - fix typo
Input: atmel_mxt_ts - add support for generic touchscreen configurations
dt-bindings: input: maxtouch: add common touchscreen properties
dt-bindings: touchscreen: convert zet6223 bindings to json schema
...

+2754 -1368
+28
Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.yaml
··· 103 103 - compatible 104 104 - "#pwm-cells" 105 105 106 + touchscreen: 107 + type: object 108 + $ref: /schemas/input/touchscreen/touchscreen.yaml# 109 + additionalProperties: false 110 + 111 + properties: 112 + compatible: 113 + const: raspberrypi,firmware-ts 114 + 115 + firmware: 116 + deprecated: true 117 + description: Phandle to RPi's firmware device node. 118 + 119 + touchscreen-size-x: true 120 + touchscreen-size-y: true 121 + touchscreen-inverted-x: true 122 + touchscreen-inverted-y: true 123 + touchscreen-swapped-x-y: true 124 + 125 + required: 126 + - compatible 127 + 106 128 required: 107 129 - compatible 108 130 - mboxes ··· 156 134 pwm: pwm { 157 135 compatible = "raspberrypi,firmware-poe-pwm"; 158 136 #pwm-cells = <2>; 137 + }; 138 + 139 + ts: touchscreen { 140 + compatible = "raspberrypi,firmware-ts"; 141 + touchscreen-size-x = <800>; 142 + touchscreen-size-y = <480>; 159 143 }; 160 144 }; 161 145 ...
+2 -1
Documentation/devicetree/bindings/input/atmel,maxtouch.yaml
··· 16 16 17 17 allOf: 18 18 - $ref: input.yaml# 19 + - $ref: touchscreen/touchscreen.yaml# 19 20 20 21 properties: 21 22 compatible: ··· 96 95 - reg 97 96 - interrupts 98 97 99 - additionalProperties: false 98 + unevaluatedProperties: false 100 99 101 100 examples: 102 101 - |
+48
Documentation/devicetree/bindings/input/awinic,aw86927.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/awinic,aw86927.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Awinic AW86927 LRA Haptic IC 8 + 9 + maintainers: 10 + - Griffin Kroah-Hartman <griffin.kroah@fairphone.com> 11 + 12 + properties: 13 + compatible: 14 + const: awinic,aw86927 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + reset-gpios: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + required: 26 + - compatible 27 + - reg 28 + - reset-gpios 29 + - interrupts 30 + 31 + additionalProperties: false 32 + 33 + examples: 34 + - | 35 + #include <dt-bindings/gpio/gpio.h> 36 + #include <dt-bindings/interrupt-controller/irq.h> 37 + 38 + i2c { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + 42 + vibrator@5a { 43 + compatible = "awinic,aw86927"; 44 + reg = <0x5a>; 45 + interrupts-extended = <&tlmm 101 IRQ_TYPE_EDGE_FALLING>; 46 + reset-gpios = <&tlmm 100 GPIO_ACTIVE_LOW>; 47 + }; 48 + };
-34
Documentation/devicetree/bindings/input/lpc32xx-key.txt
··· 1 - NXP LPC32xx Key Scan Interface 2 - 3 - This binding is based on the matrix-keymap binding with the following 4 - changes: 5 - 6 - Required Properties: 7 - - compatible: Should be "nxp,lpc3220-key" 8 - - reg: Physical base address of the controller and length of memory mapped 9 - region. 10 - - interrupts: The interrupt number to the cpu. 11 - - clocks: phandle to clock controller plus clock-specifier pair 12 - - nxp,debounce-delay-ms: Debounce delay in ms 13 - - nxp,scan-delay-ms: Repeated scan period in ms 14 - - linux,keymap: the key-code to be reported when the key is pressed 15 - and released, see also 16 - Documentation/devicetree/bindings/input/matrix-keymap.txt 17 - 18 - Note: keypad,num-rows and keypad,num-columns are required, and must be equal 19 - since LPC32xx only supports square matrices 20 - 21 - Example: 22 - 23 - key@40050000 { 24 - compatible = "nxp,lpc3220-key"; 25 - reg = <0x40050000 0x1000>; 26 - clocks = <&clk LPC32XX_CLK_KEY>; 27 - interrupt-parent = <&sic1>; 28 - interrupts = <22 IRQ_TYPE_LEVEL_HIGH>; 29 - keypad,num-rows = <1>; 30 - keypad,num-columns = <1>; 31 - nxp,debounce-delay-ms = <3>; 32 - nxp,scan-delay-ms = <34>; 33 - linux,keymap = <0x00000002>; 34 - };
+61
Documentation/devicetree/bindings/input/nxp,lpc3220-key.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/nxp,lpc3220-key.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP LPC32xx Key Scan Interface 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + const: nxp,lpc3220-key 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + maxItems: 1 21 + 22 + clocks: 23 + maxItems: 1 24 + 25 + nxp,debounce-delay-ms: 26 + description: Debounce delay in ms 27 + 28 + nxp,scan-delay-ms: 29 + description: Repeated scan period in ms 30 + 31 + required: 32 + - compatible 33 + - reg 34 + - interrupts 35 + - clocks 36 + - nxp,debounce-delay-ms 37 + - nxp,scan-delay-ms 38 + - linux,keymap 39 + 40 + allOf: 41 + - $ref: matrix-keymap.yaml# 42 + 43 + unevaluatedProperties: false 44 + 45 + examples: 46 + - | 47 + #include <dt-bindings/interrupt-controller/irq.h> 48 + #include <dt-bindings/clock/lpc32xx-clock.h> 49 + 50 + key@40050000 { 51 + compatible = "nxp,lpc3220-key"; 52 + reg = <0x40050000 0x1000>; 53 + clocks = <&clk LPC32XX_CLK_KEY>; 54 + interrupt-parent = <&sic1>; 55 + interrupts = <22 IRQ_TYPE_LEVEL_HIGH>; 56 + keypad,num-rows = <1>; 57 + keypad,num-columns = <1>; 58 + nxp,debounce-delay-ms = <3>; 59 + nxp,scan-delay-ms = <34>; 60 + linux,keymap = <0x00000002>; 61 + };
+28 -14
Documentation/devicetree/bindings/input/qcom,pm8941-pwrkey.yaml
··· 10 10 - Courtney Cavin <courtney.cavin@sonymobile.com> 11 11 - Vinod Koul <vkoul@kernel.org> 12 12 13 - allOf: 14 - - $ref: input.yaml# 15 - 16 13 properties: 17 14 compatible: 18 15 enum: ··· 22 25 maxItems: 1 23 26 24 27 debounce: 25 - description: | 26 - Time in microseconds that key must be pressed or 27 - released for state change interrupt to trigger. 28 + description: 29 + Time in microseconds that key must be pressed or released for state 30 + change interrupt to trigger. 28 31 $ref: /schemas/types.yaml#/definitions/uint32 29 32 30 33 bias-pull-up: 31 - description: | 32 - Presence of this property indicates that the KPDPWR_N 33 - pin should be configured for pull up. 34 + description: 35 + Presence of this property indicates that the KPDPWR_N pin should be 36 + configured for pull up. 34 37 $ref: /schemas/types.yaml#/definitions/flag 35 38 39 + wakeup-source: 40 + description: 41 + Button can wake-up the system. Only applicable for 'resin', 'pwrkey' 42 + always wakes the system by default. 43 + 36 44 linux,code: 37 - description: | 38 - The input key-code associated with the power key. 39 - Use the linux event codes defined in 40 - include/dt-bindings/input/linux-event-codes.h 41 - When property is omitted KEY_POWER is assumed. 45 + description: 46 + The input key-code associated with the power key. Use the linux event 47 + codes defined in include/dt-bindings/input/linux-event-codes.h. 48 + When property is omitted KEY_POWER is assumed. 49 + 50 + allOf: 51 + - $ref: input.yaml# 52 + - if: 53 + properties: 54 + compatible: 55 + contains: 56 + enum: 57 + - qcom,pm8941-pwrkey 58 + - qcom,pmk8350-pwrkey 59 + then: 60 + properties: 61 + wakeup-source: false 42 62 43 63 required: 44 64 - compatible
-10
Documentation/devicetree/bindings/input/tca8418_keypad.txt
··· 1 - This binding is based on the matrix-keymap binding with the following 2 - changes: 3 - 4 - keypad,num-rows and keypad,num-columns are required. 5 - 6 - Required properties: 7 - - compatible: "ti,tca8418" 8 - - reg: the I2C address 9 - - interrupts: IRQ line number, should trigger on falling edge 10 - - linux,keymap: Keys definitions, see keypad-matrix.
+61
Documentation/devicetree/bindings/input/ti,tca8418.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/ti,tca8418.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: TI TCA8418 I2C/SMBus keypad scanner 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - ti,tca8418 16 + 17 + reg: 18 + maxItems: 1 19 + 20 + interrupts: 21 + maxItems: 1 22 + 23 + required: 24 + - compatible 25 + - reg 26 + - interrupts 27 + 28 + allOf: 29 + - $ref: matrix-keymap.yaml# 30 + 31 + unevaluatedProperties: false 32 + 33 + examples: 34 + - | 35 + #include <dt-bindings/input/input.h> 36 + #include <dt-bindings/interrupt-controller/irq.h> 37 + 38 + i2c { 39 + #address-cells = <1>; 40 + #size-cells = <0>; 41 + 42 + keypad@34 { 43 + compatible = "ti,tca8418"; 44 + reg = <0x34>; 45 + interrupt-parent = <&gpio5>; 46 + interrupts = <11 IRQ_TYPE_EDGE_FALLING>; 47 + keypad,num-rows = <4>; 48 + keypad,num-columns = <4>; 49 + linux,keymap = < MATRIX_KEY(0x00, 0x01, BTN_0) 50 + MATRIX_KEY(0x00, 0x00, BTN_1) 51 + MATRIX_KEY(0x01, 0x01, BTN_2) 52 + MATRIX_KEY(0x01, 0x00, BTN_3) 53 + MATRIX_KEY(0x02, 0x00, BTN_4) 54 + MATRIX_KEY(0x00, 0x03, BTN_5) 55 + MATRIX_KEY(0x00, 0x02, BTN_6) 56 + MATRIX_KEY(0x01, 0x03, BTN_7) 57 + MATRIX_KEY(0x01, 0x02, BTN_8) 58 + MATRIX_KEY(0x02, 0x02, BTN_9) 59 + >; 60 + }; 61 + };
-43
Documentation/devicetree/bindings/input/touchscreen/bu21013.txt
··· 1 - * Rohm BU21013 Touch Screen 2 - 3 - Required properties: 4 - - compatible : "rohm,bu21013_tp" 5 - - reg : I2C device address 6 - - reset-gpios : GPIO pin enabling (selecting) chip (CS) 7 - - interrupt-parent : the phandle for the gpio controller 8 - - interrupts : (gpio) interrupt to which the chip is connected 9 - 10 - Optional properties: 11 - - touch-gpios : GPIO pin registering a touch event 12 - - <supply_name>-supply : Phandle to a regulator supply 13 - - touchscreen-size-x : General touchscreen binding, see [1]. 14 - - touchscreen-size-y : General touchscreen binding, see [1]. 15 - - touchscreen-inverted-x : General touchscreen binding, see [1]. 16 - - touchscreen-inverted-y : General touchscreen binding, see [1]. 17 - - touchscreen-swapped-x-y : General touchscreen binding, see [1]. 18 - 19 - [1] All general touchscreen properties are described in 20 - Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt. 21 - 22 - Deprecated properties: 23 - - rohm,touch-max-x : Maximum outward permitted limit in the X axis 24 - - rohm,touch-max-y : Maximum outward permitted limit in the Y axis 25 - - rohm,flip-x : Flip touch coordinates on the X axis 26 - - rohm,flip-y : Flip touch coordinates on the Y axis 27 - 28 - Example: 29 - 30 - i2c@80110000 { 31 - bu21013_tp@5c { 32 - compatible = "rohm,bu21013_tp"; 33 - reg = <0x5c>; 34 - interrupt-parent = <&gpio2>; 35 - interrupts <&20 IRQ_TYPE_LEVEL_LOW>; 36 - touch-gpio = <&gpio2 20 GPIO_ACTIVE_LOW>; 37 - avdd-supply = <&ab8500_ldo_aux1_reg>; 38 - 39 - touchscreen-size-x = <384>; 40 - touchscreen-size-y = <704>; 41 - touchscreen-inverted-y; 42 - }; 43 - };
+36 -6
Documentation/devicetree/bindings/input/touchscreen/eeti,exc3000.yaml
··· 9 9 maintainers: 10 10 - Dmitry Torokhov <dmitry.torokhov@gmail.com> 11 11 12 - allOf: 13 - - $ref: touchscreen.yaml# 14 - 15 12 properties: 16 13 compatible: 17 14 oneOf: 18 15 - const: eeti,exc3000 19 16 - const: eeti,exc80h60 20 17 - const: eeti,exc80h84 18 + - const: eeti,egalax_ts # Do NOT use for new binding 19 + - const: eeti,exc3000-i2c 20 + deprecated: true 21 21 - items: 22 22 - enum: 23 23 - eeti,exc81w32 24 24 - const: eeti,exc80h84 25 25 reg: 26 - const: 0x2a 26 + enum: [0x4, 0xa, 0x2a] 27 27 interrupts: 28 28 maxItems: 1 29 29 reset-gpios: 30 30 maxItems: 1 31 + wakeup-gpios: 32 + maxItems: 1 31 33 vdd-supply: 32 34 description: Power supply regulator for the chip 35 + attn-gpios: 36 + deprecated: true 37 + maxItems: 1 38 + description: Phandle to a GPIO to check whether interrupt is still 39 + latched. This is necessary for platforms that lack 40 + support for level-triggered IRQs. 33 41 touchscreen-size-x: true 34 42 touchscreen-size-y: true 35 43 touchscreen-inverted-x: true ··· 48 40 - compatible 49 41 - reg 50 42 - interrupts 51 - - touchscreen-size-x 52 - - touchscreen-size-y 53 43 54 44 additionalProperties: false 45 + 46 + allOf: 47 + - $ref: touchscreen.yaml# 48 + 49 + - if: 50 + properties: 51 + compatible: 52 + not: 53 + contains: 54 + enum: 55 + - eeti,egalax_ts 56 + - eeti,exc3000-i2c 57 + then: 58 + properties: 59 + reg: 60 + const: 0x2a 61 + 62 + wakeup-gpios: false 63 + 64 + attn-gpios: false 65 + 66 + required: 67 + - touchscreen-size-x 68 + - touchscreen-size-y 55 69 56 70 examples: 57 71 - |
-30
Documentation/devicetree/bindings/input/touchscreen/eeti.txt
··· 1 - Bindings for EETI touchscreen controller 2 - 3 - Required properties: 4 - - compatible: should be "eeti,exc3000-i2c" 5 - - reg: I2C address of the chip. Should be set to <0xa> 6 - - interrupts: interrupt to which the chip is connected 7 - 8 - Optional properties: 9 - - attn-gpios: A handle to a GPIO to check whether interrupt is still 10 - latched. This is necessary for platforms that lack 11 - support for level-triggered IRQs. 12 - 13 - The following optional properties described in touchscreen.txt are 14 - also supported: 15 - 16 - - touchscreen-inverted-x 17 - - touchscreen-inverted-y 18 - - touchscreen-swapped-x-y 19 - 20 - Example: 21 - 22 - i2c-master { 23 - touchscreen@a { 24 - compatible = "eeti,exc3000-i2c"; 25 - reg = <0xa>; 26 - interrupt-parent = <&gpio>; 27 - interrupts = <123 IRQ_TYPE_EDGE_RISING>; 28 - attn-gpios = <&gpio 123 GPIO_ACTIVE_HIGH>; 29 - }; 30 - };
-18
Documentation/devicetree/bindings/input/touchscreen/egalax-ts.txt
··· 1 - * EETI eGalax Multiple Touch Controller 2 - 3 - Required properties: 4 - - compatible: must be "eeti,egalax_ts" 5 - - reg: i2c slave address 6 - - interrupts: touch controller interrupt 7 - - wakeup-gpios: the gpio pin to be used for waking up the controller 8 - and also used as irq pin 9 - 10 - Example: 11 - 12 - touchscreen@4 { 13 - compatible = "eeti,egalax_ts"; 14 - reg = <0x04>; 15 - interrupt-parent = <&gpio1>; 16 - interrupts = <9 IRQ_TYPE_LEVEL_LOW>; 17 - wakeup-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; 18 - };
+14
Documentation/devicetree/bindings/input/touchscreen/fsl,imx6ul-tsc.yaml
··· 62 62 description: Number of data samples which are averaged for each read. 63 63 enum: [ 1, 4, 8, 16, 32 ] 64 64 65 + debounce-delay-us: 66 + description: | 67 + Minimum duration in microseconds a signal must remain stable 68 + to be considered valid. 69 + 70 + Drivers must convert this value to IPG clock cycles and map 71 + it to one of the four discrete thresholds exposed by the 72 + TSC_DEBUG_MODE2 register: 73 + 74 + 0: 8191 IPG cycles 75 + 1: 4095 IPG cycles 76 + 2: 2047 IPG cycles 77 + 3: 1023 IPG cycles 78 + 65 79 required: 66 80 - compatible 67 81 - reg
-1
Documentation/devicetree/bindings/input/touchscreen/goodix.yaml
··· 62 62 required: 63 63 - compatible 64 64 - reg 65 - - interrupts 66 65 67 66 examples: 68 67 - |
+81
Documentation/devicetree/bindings/input/touchscreen/himax,hx852es.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/himax,hx852es.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Himax HX852x(ES) touch panel controller 8 + 9 + maintainers: 10 + - Stephan Gerhold <stephan@gerhold.net> 11 + 12 + allOf: 13 + - $ref: touchscreen.yaml# 14 + 15 + properties: 16 + compatible: 17 + items: 18 + - enum: 19 + - himax,hx8525e 20 + - himax,hx8526e 21 + - himax,hx8527e 22 + - const: himax,hx852es 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + maxItems: 1 29 + description: Touch Screen Interrupt (TSIX), active low 30 + 31 + reset-gpios: 32 + maxItems: 1 33 + description: External Reset (XRES), active low 34 + 35 + vcca-supply: 36 + description: Analog power supply (VCCA) 37 + 38 + vccd-supply: 39 + description: Digital power supply (VCCD) 40 + 41 + touchscreen-inverted-x: true 42 + touchscreen-inverted-y: true 43 + touchscreen-size-x: true 44 + touchscreen-size-y: true 45 + touchscreen-swapped-x-y: true 46 + 47 + linux,keycodes: 48 + minItems: 1 49 + maxItems: 4 50 + 51 + required: 52 + - compatible 53 + - reg 54 + - interrupts 55 + - reset-gpios 56 + 57 + additionalProperties: false 58 + 59 + examples: 60 + - | 61 + #include <dt-bindings/gpio/gpio.h> 62 + #include <dt-bindings/input/input.h> 63 + #include <dt-bindings/interrupt-controller/irq.h> 64 + 65 + i2c { 66 + #address-cells = <1>; 67 + #size-cells = <0>; 68 + 69 + touchscreen@48 { 70 + compatible = "himax,hx8527e", "himax,hx852es"; 71 + reg = <0x48>; 72 + interrupt-parent = <&tlmm>; 73 + interrupts = <13 IRQ_TYPE_LEVEL_LOW>; 74 + reset-gpios = <&tlmm 12 GPIO_ACTIVE_LOW>; 75 + vcca-supply = <&reg_ts_vcca>; 76 + vccd-supply = <&pm8916_l6>; 77 + linux,keycodes = <KEY_BACK KEY_HOMEPAGE KEY_APPSELECT>; 78 + }; 79 + }; 80 + 81 + ...
+65
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.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/hynitron,cst816x.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Hynitron CST816x Series Capacitive Touch controller 8 + 9 + maintainers: 10 + - Oleh Kuzhylnyi <kuzhylol@gmail.com> 11 + 12 + description: | 13 + Bindings for CST816x high performance self-capacitance touch chip series 14 + with single point gesture and real two-point operation. 15 + 16 + properties: 17 + compatible: 18 + enum: 19 + - hynitron,cst816s 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + reset-gpios: 28 + maxItems: 1 29 + 30 + linux,keycodes: 31 + minItems: 1 32 + items: 33 + - description: Slide up gesture 34 + - description: Slide down gesture 35 + - description: Slide left gesture 36 + - description: Slide right gesture 37 + - description: Long press gesture 38 + 39 + required: 40 + - compatible 41 + - reg 42 + - interrupts 43 + 44 + additionalProperties: false 45 + 46 + examples: 47 + - | 48 + #include <dt-bindings/gpio/gpio.h> 49 + #include <dt-bindings/input/linux-event-codes.h> 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + i2c { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + touchscreen@15 { 55 + compatible = "hynitron,cst816s"; 56 + reg = <0x15>; 57 + interrupt-parent = <&gpio0>; 58 + interrupts = <4 IRQ_TYPE_EDGE_RISING>; 59 + reset-gpios = <&gpio 17 GPIO_ACTIVE_LOW>; 60 + linux,keycodes = <KEY_UP>, <KEY_DOWN>, <KEY_LEFT>, <KEY_RIGHT>, 61 + <BTN_TOOL_TRIPLETAP>; 62 + }; 63 + }; 64 + 65 + ...
+18
Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
··· 35 35 36 36 linux,keycodes: 37 37 description: Keycodes for the touch keys 38 + minItems: 2 38 39 maxItems: 5 39 40 40 41 touchscreen-size-x: true ··· 86 85 touchscreen-fuzz-y = <10>; 87 86 touchscreen-inverted-x; 88 87 touchscreen-inverted-y; 88 + }; 89 + }; 90 + - | 91 + #include <dt-bindings/input/linux-event-codes.h> 92 + #include <dt-bindings/interrupt-controller/irq.h> 93 + i2c { 94 + #address-cells = <1>; 95 + #size-cells = <0>; 96 + touchscreen@50 { 97 + compatible = "imagis,ist3032c"; 98 + reg = <0x50>; 99 + interrupt-parent = <&gpio>; 100 + interrupts = <72 IRQ_TYPE_EDGE_FALLING>; 101 + vdd-supply = <&ldo2>; 102 + touchscreen-size-x = <480>; 103 + touchscreen-size-y = <800>; 104 + linux,keycodes = <KEY_APPSELECT>, <KEY_BACK>; 89 105 }; 90 106 }; 91 107
-17
Documentation/devicetree/bindings/input/touchscreen/max11801-ts.txt
··· 1 - * MAXI MAX11801 Resistive touch screen controller with i2c interface 2 - 3 - Required properties: 4 - - compatible: must be "maxim,max11801" 5 - - reg: i2c slave address 6 - - interrupts: touch controller interrupt 7 - 8 - Example: 9 - 10 - &i2c1 { 11 - max11801: touchscreen@48 { 12 - compatible = "maxim,max11801"; 13 - reg = <0x48>; 14 - interrupt-parent = <&gpio3>; 15 - interrupts = <31 IRQ_TYPE_EDGE_FALLING>; 16 - }; 17 - };
+46
Documentation/devicetree/bindings/input/touchscreen/maxim,max11801.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/maxim,max11801.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: MAXI MAX11801 Resistive touch screen controller with i2c interface 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + const: maxim,max11801 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + maxItems: 1 21 + 22 + allOf: 23 + - $ref: touchscreen.yaml 24 + 25 + required: 26 + - compatible 27 + - reg 28 + - interrupts 29 + 30 + unevaluatedProperties: false 31 + 32 + examples: 33 + - | 34 + #include <dt-bindings/interrupt-controller/irq.h> 35 + 36 + i2c { 37 + #address-cells = <1>; 38 + #size-cells = <0>; 39 + 40 + touchscreen@48 { 41 + compatible = "maxim,max11801"; 42 + reg = <0x48>; 43 + interrupt-parent = <&gpio3>; 44 + interrupts = <31 IRQ_TYPE_EDGE_FALLING>; 45 + }; 46 + };
-26
Documentation/devicetree/bindings/input/touchscreen/raspberrypi,firmware-ts.txt
··· 1 - Raspberry Pi firmware based 7" touchscreen 2 - ===================================== 3 - 4 - Required properties: 5 - - compatible: "raspberrypi,firmware-ts" 6 - 7 - Optional properties: 8 - - firmware: Reference to RPi's firmware device node 9 - - touchscreen-size-x: See touchscreen.txt 10 - - touchscreen-size-y: See touchscreen.txt 11 - - touchscreen-inverted-x: See touchscreen.txt 12 - - touchscreen-inverted-y: See touchscreen.txt 13 - - touchscreen-swapped-x-y: See touchscreen.txt 14 - 15 - Example: 16 - 17 - firmware: firmware-rpi { 18 - compatible = "raspberrypi,bcm2835-firmware"; 19 - mboxes = <&mailbox>; 20 - 21 - ts: touchscreen { 22 - compatible = "raspberrypi,firmware-ts"; 23 - touchscreen-size-x = <800>; 24 - touchscreen-size-y = <480>; 25 - }; 26 - };
+1 -1
Documentation/devicetree/bindings/input/touchscreen/resistive-adc-touch.yaml
··· 55 55 touchscreen-min-pressure: true 56 56 touchscreen-x-plate-ohms: true 57 57 58 - additionalProperties: false 58 + unevaluatedProperties: false 59 59 60 60 required: 61 61 - compatible
+95
Documentation/devicetree/bindings/input/touchscreen/rohm,bu21013.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/rohm,bu21013.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Rohm BU21013 touchscreen 8 + 9 + description: 10 + Rohm BU21013 I2C driven touchscreen controller. 11 + 12 + maintainers: 13 + - Dario Binacchi <dario.binacchi@amarulasolutions.com> 14 + 15 + allOf: 16 + - $ref: touchscreen.yaml# 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - rohm,bu21013_tp 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + reset-gpios: 30 + maxItems: 1 31 + 32 + touch-gpios: 33 + maxItems: 1 34 + description: GPIO registering a touch event. 35 + 36 + avdd-supply: 37 + description: Analogic power supply 38 + 39 + rohm,touch-max-x: 40 + deprecated: true 41 + description: Maximum value on the X axis. 42 + $ref: /schemas/types.yaml#/definitions/uint32 43 + 44 + rohm,touch-max-y: 45 + deprecated: true 46 + description: Maximum value on the Y axis. 47 + $ref: /schemas/types.yaml#/definitions/uint32 48 + 49 + rohm,flip-x: 50 + deprecated: true 51 + description: Flip touch coordinates on the X axis 52 + type: boolean 53 + 54 + rohm,flip-y: 55 + deprecated: true 56 + description: Flip touch coordinates on the Y axis 57 + type: boolean 58 + 59 + touchscreen-inverted-x: true 60 + touchscreen-inverted-y: true 61 + touchscreen-size-x: true 62 + touchscreen-size-y: true 63 + touchscreen-swapped-x-y: true 64 + 65 + additionalProperties: false 66 + 67 + required: 68 + - compatible 69 + - reg 70 + - reset-gpios 71 + - interrupts 72 + 73 + examples: 74 + - | 75 + #include <dt-bindings/gpio/gpio.h> 76 + #include <dt-bindings/interrupt-controller/irq.h> 77 + i2c { 78 + #address-cells = <1>; 79 + #size-cells = <0>; 80 + 81 + touchscreen@5c { 82 + compatible = "rohm,bu21013_tp"; 83 + reg = <0x5c>; 84 + 85 + interrupt-parent = <&gpio2>; 86 + interrupts = <0x20 IRQ_TYPE_LEVEL_LOW>; 87 + reset-gpios = <&gpio2 19 GPIO_ACTIVE_LOW>; 88 + touch-gpios = <&gpio2 20 GPIO_ACTIVE_LOW>; 89 + avdd-supply = <&ab8500_ldo_aux1_reg>; 90 + 91 + touchscreen-size-x = <384>; 92 + touchscreen-size-y = <704>; 93 + touchscreen-inverted-y; 94 + }; 95 + };
+52
Documentation/devicetree/bindings/input/touchscreen/semtech,sx8654.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/semtech,sx8654.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Semtech SX8654 I2C Touchscreen Controller 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - semtech,sx8650 16 + - semtech,sx8654 17 + - semtech,sx8655 18 + - semtech,sx8656 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + interrupts: 24 + maxItems: 1 25 + 26 + reset-gpios: 27 + maxItems: 1 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - interrupts 33 + 34 + additionalProperties: false 35 + 36 + examples: 37 + - | 38 + #include <dt-bindings/gpio/gpio.h> 39 + #include <dt-bindings/interrupt-controller/irq.h> 40 + 41 + i2c { 42 + #address-cells = <1>; 43 + #size-cells = <0>; 44 + 45 + touchscreen@48 { 46 + compatible = "semtech,sx8654"; 47 + reg = <0x48>; 48 + interrupt-parent = <&gpio6>; 49 + interrupts = <3 IRQ_TYPE_EDGE_FALLING>; 50 + reset-gpios = <&gpio4 2 GPIO_ACTIVE_LOW>; 51 + }; 52 + };
-23
Documentation/devicetree/bindings/input/touchscreen/sx8654.txt
··· 1 - * Semtech SX8654 I2C Touchscreen Controller 2 - 3 - Required properties: 4 - - compatible: must be one of the following, depending on the model: 5 - "semtech,sx8650" 6 - "semtech,sx8654" 7 - "semtech,sx8655" 8 - "semtech,sx8656" 9 - - reg: i2c slave address 10 - - interrupts: touch controller interrupt 11 - 12 - Optional properties: 13 - - reset-gpios: GPIO specification for the NRST input 14 - 15 - Example: 16 - 17 - sx8654@48 { 18 - compatible = "semtech,sx8654"; 19 - reg = <0x48>; 20 - interrupt-parent = <&gpio6>; 21 - interrupts = <3 IRQ_TYPE_EDGE_FALLING>; 22 - reset-gpios = <&gpio4 2 GPIO_ACTIVE_LOW>; 23 - };
+3 -1
Documentation/devicetree/bindings/input/touchscreen/ti.tsc2007.yaml Documentation/devicetree/bindings/input/touchscreen/ti,tsc2007.yaml
··· 1 1 # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 2 %YAML 1.2 3 3 --- 4 - $id: http://devicetree.org/schemas/input/touchscreen/ti.tsc2007.yaml# 4 + $id: http://devicetree.org/schemas/input/touchscreen/ti,tsc2007.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 7 title: Texas Instruments tsc2007 touchscreen controller ··· 25 25 gpios: true 26 26 27 27 pendown-gpio: true 28 + 29 + wakeup-source: true 28 30 29 31 ti,max-rt: 30 32 $ref: /schemas/types.yaml#/definitions/uint32
-1
Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt
··· 1 - See touchscreen.yaml
+4
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml
··· 206 206 207 207 unevaluatedProperties: false 208 208 209 + debounce-delay-us: 210 + description: Minimum duration in microseconds a signal must remain stable 211 + to be considered valid. 212 + 209 213 dependencies: 210 214 touchscreen-size-x: [ touchscreen-size-y ] 211 215 touchscreen-size-y: [ touchscreen-size-x ]
+62
Documentation/devicetree/bindings/input/touchscreen/zeitec,zet6223.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/zeitec,zet6223.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Zeitec ZET6223 touchscreen controller 8 + 9 + description: 10 + Zeitec ZET6223 I2C driven touchscreen controller. 11 + 12 + maintainers: 13 + - Dario Binacchi <dario.binacchi@amarulasolutions.com> 14 + 15 + allOf: 16 + - $ref: touchscreen.yaml# 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - zeitec,zet6223 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + vio-supply: 30 + description: 1.8V or 3.3V VIO supply. 31 + 32 + vcc-supply: 33 + description: 3.3V VCC supply. 34 + 35 + touchscreen-inverted-x: true 36 + touchscreen-inverted-y: true 37 + touchscreen-size-x: true 38 + touchscreen-size-y: true 39 + touchscreen-swapped-x-y: true 40 + 41 + additionalProperties: false 42 + 43 + required: 44 + - compatible 45 + - reg 46 + - interrupts 47 + 48 + examples: 49 + - | 50 + #include <dt-bindings/gpio/gpio.h> 51 + #include <dt-bindings/interrupt-controller/irq.h> 52 + i2c { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + 56 + touchscreen@76 { 57 + compatible = "zeitec,zet6223"; 58 + reg = <0x76>; 59 + interrupt-parent = <&pio>; 60 + interrupts = <6 11 IRQ_TYPE_EDGE_FALLING>; 61 + }; 62 + };
-30
Documentation/devicetree/bindings/input/touchscreen/zet6223.txt
··· 1 - Zeitec ZET6223 I2C touchscreen controller 2 - 3 - Required properties: 4 - - compatible : "zeitec,zet6223" 5 - - reg : I2C slave address of the chip (0x76) 6 - - interrupts : interrupt specification for the zet6223 interrupt 7 - 8 - Optional properties: 9 - 10 - - vio-supply : Specification for VIO supply (1.8V or 3.3V, 11 - depending on system interface needs). 12 - - vcc-supply : Specification for 3.3V VCC supply. 13 - - touchscreen-size-x : See touchscreen.txt 14 - - touchscreen-size-y : See touchscreen.txt 15 - - touchscreen-inverted-x : See touchscreen.txt 16 - - touchscreen-inverted-y : See touchscreen.txt 17 - - touchscreen-swapped-x-y : See touchscreen.txt 18 - 19 - Example: 20 - 21 - i2c@00000000 { 22 - 23 - zet6223: touchscreen@76 { 24 - compatible = "zeitec,zet6223"; 25 - reg = <0x76>; 26 - interrupt-parent = <&pio>; 27 - interrupts = <6 11 IRQ_TYPE_EDGE_FALLING> 28 - }; 29 - 30 - };
+7
MAINTAINERS
··· 11168 11168 F: Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml 11169 11169 F: drivers/input/touchscreen/himax_hx83112b.c 11170 11170 11171 + HIMAX HX852X TOUCHSCREEN DRIVER 11172 + M: Stephan Gerhold <stephan@gerhold.net> 11173 + L: linux-input@vger.kernel.org 11174 + S: Maintained 11175 + F: Documentation/devicetree/bindings/input/touchscreen/himax,hx852es.yaml 11176 + F: drivers/input/touchscreen/himax_hx852x.c 11177 + 11171 11178 HIPPI 11172 11179 M: Jes Sorensen <jes@trained-monkey.org> 11173 11180 S: Maintained
+1 -1
drivers/input/ff-core.c
··· 8 8 9 9 /* #define DEBUG */ 10 10 11 + #include <linux/export.h> 11 12 #include <linux/input.h> 12 13 #include <linux/limits.h> 13 - #include <linux/module.h> 14 14 #include <linux/mutex.h> 15 15 #include <linux/overflow.h> 16 16 #include <linux/sched.h>
+1
drivers/input/ff-memless.c
··· 10 10 11 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 12 13 + #include <linux/export.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/input.h> 15 16 #include <linux/module.h>
+1
drivers/input/gameport/gameport.c
··· 9 9 10 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 11 12 + #include <linux/export.h> 12 13 #include <linux/stddef.h> 13 14 #include <linux/module.h> 14 15 #include <linux/io.h>
+30
drivers/input/input-compat.c
··· 6 6 */ 7 7 8 8 #include <linux/export.h> 9 + #include <linux/sprintf.h> 9 10 #include <linux/uaccess.h> 10 11 #include "input-compat.h" 11 12 ··· 95 94 return 0; 96 95 } 97 96 97 + int input_bits_to_string(char *buf, int buf_size, unsigned long bits, 98 + bool skip_empty) 99 + { 100 + int len = 0; 101 + 102 + if (in_compat_syscall()) { 103 + u32 dword = bits >> 32; 104 + if (dword || !skip_empty) 105 + len += snprintf(buf, buf_size, "%x ", dword); 106 + 107 + dword = bits & 0xffffffffUL; 108 + if (dword || !skip_empty || len) 109 + len += snprintf(buf + len, max(buf_size - len, 0), 110 + "%x", dword); 111 + } else { 112 + if (bits || !skip_empty) 113 + len += snprintf(buf, buf_size, "%lx", bits); 114 + } 115 + 116 + return len; 117 + } 118 + 98 119 #else 99 120 100 121 int input_event_from_user(const char __user *buffer, ··· 147 124 return -EFAULT; 148 125 149 126 return 0; 127 + } 128 + 129 + int input_bits_to_string(char *buf, int buf_size, unsigned long bits, 130 + bool skip_empty) 131 + { 132 + return bits || !skip_empty ? 133 + snprintf(buf, buf_size, "%lx", bits) : 0; 150 134 } 151 135 152 136 #endif /* CONFIG_COMPAT */
+3
drivers/input/input-compat.h
··· 75 75 int input_ff_effect_from_user(const char __user *buffer, size_t size, 76 76 struct ff_effect *effect); 77 77 78 + int input_bits_to_string(char *buf, int buf_size, unsigned long bits, 79 + bool skip_empty); 80 + 78 81 #endif /* _INPUT_COMPAT_H */
+1
drivers/input/input-poller.c
··· 4 4 */ 5 5 6 6 #include <linux/device.h> 7 + #include <linux/export.h> 7 8 #include <linux/input.h> 8 9 #include <linux/jiffies.h> 9 10 #include <linux/mutex.h>
+1 -35
drivers/input/input.c
··· 8 8 9 9 #define pr_fmt(fmt) KBUILD_BASENAME ": " fmt 10 10 11 + #include <linux/export.h> 11 12 #include <linux/init.h> 12 13 #include <linux/types.h> 13 14 #include <linux/idr.h> ··· 998 997 999 998 return error; 1000 999 } 1001 - 1002 - #ifdef CONFIG_COMPAT 1003 - 1004 - static int input_bits_to_string(char *buf, int buf_size, 1005 - unsigned long bits, bool skip_empty) 1006 - { 1007 - int len = 0; 1008 - 1009 - if (in_compat_syscall()) { 1010 - u32 dword = bits >> 32; 1011 - if (dword || !skip_empty) 1012 - len += snprintf(buf, buf_size, "%x ", dword); 1013 - 1014 - dword = bits & 0xffffffffUL; 1015 - if (dword || !skip_empty || len) 1016 - len += snprintf(buf + len, max(buf_size - len, 0), 1017 - "%x", dword); 1018 - } else { 1019 - if (bits || !skip_empty) 1020 - len += snprintf(buf, buf_size, "%lx", bits); 1021 - } 1022 - 1023 - return len; 1024 - } 1025 - 1026 - #else /* !CONFIG_COMPAT */ 1027 - 1028 - static int input_bits_to_string(char *buf, int buf_size, 1029 - unsigned long bits, bool skip_empty) 1030 - { 1031 - return bits || !skip_empty ? 1032 - snprintf(buf, buf_size, "%lx", bits) : 0; 1033 - } 1034 - 1035 - #endif 1036 1000 1037 1001 #ifdef CONFIG_PROC_FS 1038 1002
+1
drivers/input/joystick/iforce/iforce-main.c
··· 6 6 * USB/RS232 I-Force joysticks and wheels. 7 7 */ 8 8 9 + #include <linux/export.h> 9 10 #include <linux/unaligned.h> 10 11 #include "iforce.h" 11 12
+1
drivers/input/joystick/iforce/iforce-packets.c
··· 6 6 * USB/RS232 I-Force joysticks and wheels. 7 7 */ 8 8 9 + #include <linux/export.h> 9 10 #include <linux/unaligned.h> 10 11 #include "iforce.h" 11 12
+5 -1
drivers/input/joystick/psxpad-spi.c
··· 344 344 /* (PlayStation 1/2 joypad might be possible works 250kHz/500kHz) */ 345 345 spi->controller->min_speed_hz = 125000; 346 346 spi->controller->max_speed_hz = 125000; 347 - spi_setup(spi); 347 + err = spi_setup(spi); 348 + if (err) { 349 + dev_err(&spi->dev, "failed to set up SPI: %d\n", err); 350 + return err; 351 + } 348 352 349 353 /* pad settings */ 350 354 psxpad_set_motor_level(pad, 0, 0);
-18
drivers/input/keyboard/Kconfig
··· 262 262 To compile this driver as a module, choose M here: the 263 263 module will be called gpio_keys_polled. 264 264 265 - config KEYBOARD_TCA6416 266 - tristate "TCA6416/TCA6408A Keypad Support" 267 - depends on I2C 268 - help 269 - This driver implements basic keypad functionality 270 - for keys connected through TCA6416/TCA6408A IO expanders. 271 - 272 - Say Y here if your device has keys connected to 273 - TCA6416/TCA6408A IO expander. Your board-specific setup logic 274 - must also provide pin-mask details(of which TCA6416 pins 275 - are used for keypad). 276 - 277 - If enabled the entire TCA6416 device will be managed through 278 - this driver. 279 - 280 - To compile this driver as a module, choose M here: the 281 - module will be called tca6416_keypad. 282 - 283 265 config KEYBOARD_TCA8418 284 266 tristate "TCA8418 Keypad Support" 285 267 depends on I2C
-1
drivers/input/keyboard/Makefile
··· 23 23 obj-$(CONFIG_KEYBOARD_GOLDFISH_EVENTS) += goldfish_events.o 24 24 obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 25 25 obj-$(CONFIG_KEYBOARD_GPIO_POLLED) += gpio_keys_polled.o 26 - obj-$(CONFIG_KEYBOARD_TCA6416) += tca6416-keypad.o 27 26 obj-$(CONFIG_KEYBOARD_TCA8418) += tca8418_keypad.o 28 27 obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 29 28 obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
+192 -318
drivers/input/keyboard/pxa27x_keypad.c
··· 12 12 * on some suggestions by Nicolas Pitre <nico@fluxnic.net>. 13 13 */ 14 14 15 - 15 + #include <linux/bits.h> 16 + #include <linux/bitfield.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/module.h> 18 19 #include <linux/interrupt.h> ··· 21 20 #include <linux/io.h> 22 21 #include <linux/device.h> 23 22 #include <linux/platform_device.h> 23 + #include <linux/property.h> 24 24 #include <linux/clk.h> 25 25 #include <linux/err.h> 26 26 #include <linux/input/matrix_keypad.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/of.h> 29 29 30 - #include <linux/platform_data/keypad-pxa27x.h> 31 30 /* 32 31 * Keypad Controller registers 33 32 */ 34 - #define KPC 0x0000 /* Keypad Control register */ 35 - #define KPDK 0x0008 /* Keypad Direct Key register */ 36 - #define KPREC 0x0010 /* Keypad Rotary Encoder register */ 37 - #define KPMK 0x0018 /* Keypad Matrix Key register */ 38 - #define KPAS 0x0020 /* Keypad Automatic Scan register */ 33 + #define KPC 0x0000 /* Keypad Control register */ 34 + #define KPDK 0x0008 /* Keypad Direct Key register */ 35 + #define KPREC 0x0010 /* Keypad Rotary Encoder register */ 36 + #define KPMK 0x0018 /* Keypad Matrix Key register */ 37 + #define KPAS 0x0020 /* Keypad Automatic Scan register */ 39 38 40 39 /* Keypad Automatic Scan Multiple Key Presser register 0-3 */ 41 - #define KPASMKP0 0x0028 42 - #define KPASMKP1 0x0030 43 - #define KPASMKP2 0x0038 44 - #define KPASMKP3 0x0040 45 - #define KPKDI 0x0048 40 + #define KPASMKP0 0x0028 41 + #define KPASMKP1 0x0030 42 + #define KPASMKP2 0x0038 43 + #define KPASMKP3 0x0040 44 + #define KPKDI 0x0048 46 45 47 46 /* bit definitions */ 48 - #define KPC_MKRN(n) ((((n) - 1) & 0x7) << 26) /* matrix key row number */ 49 - #define KPC_MKCN(n) ((((n) - 1) & 0x7) << 23) /* matrix key column number */ 50 - #define KPC_DKN(n) ((((n) - 1) & 0x7) << 6) /* direct key number */ 47 + #define KPC_MKRN_MASK GENMASK(28, 26) 48 + #define KPC_MKCN_MASK GENMASK(25, 23) 49 + #define KPC_DKN_MASK GENMASK(8, 6) 50 + #define KPC_MKRN(n) FIELD_PREP(KPC_MKRN_MASK, (n) - 1) 51 + #define KPC_MKCN(n) FIELD_PREP(KPC_MKCN_MASK, (n) - 1) 52 + #define KPC_DKN(n) FIELD_PREP(KPC_DKN_MASK, (n) - 1) 51 53 52 - #define KPC_AS (0x1 << 30) /* Automatic Scan bit */ 53 - #define KPC_ASACT (0x1 << 29) /* Automatic Scan on Activity */ 54 - #define KPC_MI (0x1 << 22) /* Matrix interrupt bit */ 55 - #define KPC_IMKP (0x1 << 21) /* Ignore Multiple Key Press */ 54 + #define KPC_AS BIT(30) /* Automatic Scan bit */ 55 + #define KPC_ASACT BIT(29) /* Automatic Scan on Activity */ 56 + #define KPC_MI BIT(22) /* Matrix interrupt bit */ 57 + #define KPC_IMKP BIT(21) /* Ignore Multiple Key Press */ 56 58 57 - #define KPC_MS(n) (0x1 << (13 + (n))) /* Matrix scan line 'n' */ 58 - #define KPC_MS_ALL (0xff << 13) 59 + #define KPC_MS(n) BIT(13 + (n)) /* Matrix scan line 'n' */ 60 + #define KPC_MS_ALL GENMASK(20, 13) 59 61 60 - #define KPC_ME (0x1 << 12) /* Matrix Keypad Enable */ 61 - #define KPC_MIE (0x1 << 11) /* Matrix Interrupt Enable */ 62 - #define KPC_DK_DEB_SEL (0x1 << 9) /* Direct Keypad Debounce Select */ 63 - #define KPC_DI (0x1 << 5) /* Direct key interrupt bit */ 64 - #define KPC_RE_ZERO_DEB (0x1 << 4) /* Rotary Encoder Zero Debounce */ 65 - #define KPC_REE1 (0x1 << 3) /* Rotary Encoder1 Enable */ 66 - #define KPC_REE0 (0x1 << 2) /* Rotary Encoder0 Enable */ 67 - #define KPC_DE (0x1 << 1) /* Direct Keypad Enable */ 68 - #define KPC_DIE (0x1 << 0) /* Direct Keypad interrupt Enable */ 62 + #define KPC_ME BIT(12) /* Matrix Keypad Enable */ 63 + #define KPC_MIE BIT(11) /* Matrix Interrupt Enable */ 64 + #define KPC_DK_DEB_SEL BIT(9) /* Direct Keypad Debounce Select */ 65 + #define KPC_DI BIT(5) /* Direct key interrupt bit */ 66 + #define KPC_RE_ZERO_DEB BIT(4) /* Rotary Encoder Zero Debounce */ 67 + #define KPC_REE1 BIT(3) /* Rotary Encoder1 Enable */ 68 + #define KPC_REE0 BIT(2) /* Rotary Encoder0 Enable */ 69 + #define KPC_DE BIT(1) /* Direct Keypad Enable */ 70 + #define KPC_DIE BIT(0) /* Direct Keypad interrupt Enable */ 69 71 70 - #define KPDK_DKP (0x1 << 31) 71 - #define KPDK_DK(n) ((n) & 0xff) 72 + #define KPDK_DKP BIT(31) 73 + #define KPDK_DK_MASK GENMASK(7, 0) 74 + #define KPDK_DK(n) FIELD_GET(KPDK_DK_MASK, n) 72 75 73 - #define KPREC_OF1 (0x1 << 31) 74 - #define kPREC_UF1 (0x1 << 30) 75 - #define KPREC_OF0 (0x1 << 15) 76 - #define KPREC_UF0 (0x1 << 14) 76 + #define KPREC_OF1 BIT(31) 77 + #define KPREC_UF1 BIT(30) 78 + #define KPREC_OF0 BIT(15) 79 + #define KPREC_UF0 BIT(14) 77 80 78 - #define KPREC_RECOUNT0(n) ((n) & 0xff) 79 - #define KPREC_RECOUNT1(n) (((n) >> 16) & 0xff) 81 + #define KPREC_RECOUNT0_MASK GENMASK(7, 0) 82 + #define KPREC_RECOUNT1_MASK GENMASK(23, 16) 83 + #define KPREC_RECOUNT0(n) FIELD_GET(KPREC_RECOUNT0_MASK, n) 84 + #define KPREC_RECOUNT1(n) FIELD_GET(KPREC_RECOUNT1_MASK, n) 80 85 81 - #define KPMK_MKP (0x1 << 31) 82 - #define KPAS_SO (0x1 << 31) 83 - #define KPASMKPx_SO (0x1 << 31) 86 + #define KPMK_MKP BIT(31) 87 + #define KPAS_SO BIT(31) 88 + #define KPASMKPx_SO BIT(31) 84 89 85 - #define KPAS_MUKP(n) (((n) >> 26) & 0x1f) 86 - #define KPAS_RP(n) (((n) >> 4) & 0xf) 87 - #define KPAS_CP(n) ((n) & 0xf) 90 + #define KPAS_MUKP_MASK GENMASK(30, 26) 91 + #define KPAS_RP_MASK GENMASK(7, 4) 92 + #define KPAS_CP_MASK GENMASK(3, 0) 93 + #define KPAS_MUKP(n) FIELD_GET(KPAS_MUKP_MASK, n) 94 + #define KPAS_RP(n) FIELD_GET(KPAS_RP_MASK, n) 95 + #define KPAS_CP(n) FIELD_GET(KPAS_CP_MASK, n) 88 96 89 - #define KPASMKP_MKC_MASK (0xff) 97 + #define KPASMKP_MKC_MASK GENMASK(7, 0) 90 98 91 99 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off)) 92 100 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off)) 93 101 102 + #define MAX_MATRIX_KEY_ROWS 8 103 + #define MAX_MATRIX_KEY_COLS 8 104 + #define MAX_DIRECT_KEY_NUM 8 105 + #define MAX_ROTARY_ENCODERS 2 106 + 94 107 #define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS) 95 108 #define MAX_KEYPAD_KEYS (MAX_MATRIX_KEY_NUM + MAX_DIRECT_KEY_NUM) 96 109 97 - struct pxa27x_keypad { 98 - const struct pxa27x_keypad_platform_data *pdata; 110 + struct pxa27x_keypad_rotary { 111 + unsigned short *key_codes; 112 + int rel_code; 113 + bool enabled; 114 + }; 99 115 116 + struct pxa27x_keypad { 100 117 struct clk *clk; 101 118 struct input_dev *input_dev; 102 119 void __iomem *mmio_base; 103 120 104 121 int irq; 105 122 106 - unsigned short keycodes[MAX_KEYPAD_KEYS]; 107 - int rotary_rel_code[2]; 108 - 123 + unsigned int matrix_key_rows; 124 + unsigned int matrix_key_cols; 109 125 unsigned int row_shift; 110 126 111 - /* state row bits of each column scan */ 112 - uint32_t matrix_key_state[MAX_MATRIX_KEY_COLS]; 113 - uint32_t direct_key_state; 114 - 127 + unsigned int direct_key_num; 115 128 unsigned int direct_key_mask; 129 + bool direct_key_low_active; 130 + 131 + /* key debounce interval */ 132 + unsigned int debounce_interval; 133 + 134 + unsigned short keycodes[MAX_KEYPAD_KEYS]; 135 + 136 + /* state row bits of each column scan */ 137 + u32 matrix_key_state[MAX_MATRIX_KEY_COLS]; 138 + u32 direct_key_state; 139 + 140 + struct pxa27x_keypad_rotary rotary[MAX_ROTARY_ENCODERS]; 116 141 }; 117 142 118 - #ifdef CONFIG_OF 119 - static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, 120 - struct pxa27x_keypad_platform_data *pdata) 143 + static int pxa27x_keypad_matrix_key_parse(struct pxa27x_keypad *keypad) 121 144 { 122 145 struct input_dev *input_dev = keypad->input_dev; 123 146 struct device *dev = input_dev->dev.parent; 124 - u32 rows, cols; 125 147 int error; 126 148 127 - error = matrix_keypad_parse_properties(dev, &rows, &cols); 149 + error = matrix_keypad_parse_properties(dev, &keypad->matrix_key_rows, 150 + &keypad->matrix_key_cols); 128 151 if (error) 129 152 return error; 130 153 131 - if (rows > MAX_MATRIX_KEY_ROWS || cols > MAX_MATRIX_KEY_COLS) { 154 + if (keypad->matrix_key_rows > MAX_MATRIX_KEY_ROWS || 155 + keypad->matrix_key_cols > MAX_MATRIX_KEY_COLS) { 132 156 dev_err(dev, "rows or cols exceeds maximum value\n"); 133 157 return -EINVAL; 134 158 } 135 159 136 - pdata->matrix_key_rows = rows; 137 - pdata->matrix_key_cols = cols; 160 + keypad->row_shift = get_count_order(keypad->matrix_key_cols); 138 161 139 162 error = matrix_keypad_build_keymap(NULL, NULL, 140 - pdata->matrix_key_rows, 141 - pdata->matrix_key_cols, 163 + keypad->matrix_key_rows, 164 + keypad->matrix_key_cols, 142 165 keypad->keycodes, input_dev); 143 166 if (error) 144 167 return error; ··· 170 145 return 0; 171 146 } 172 147 173 - static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, 174 - struct pxa27x_keypad_platform_data *pdata) 148 + static int pxa27x_keypad_direct_key_parse(struct pxa27x_keypad *keypad) 175 149 { 176 150 struct input_dev *input_dev = keypad->input_dev; 177 151 struct device *dev = input_dev->dev.parent; 178 - struct device_node *np = dev->of_node; 179 - const __be16 *prop; 180 152 unsigned short code; 181 - unsigned int proplen, size; 153 + int count; 182 154 int i; 183 155 int error; 184 156 185 - error = of_property_read_u32(np, "marvell,direct-key-count", 186 - &pdata->direct_key_num); 157 + error = device_property_read_u32(dev, "marvell,direct-key-count", 158 + &keypad->direct_key_num); 187 159 if (error) { 188 160 /* 189 161 * If do not have marvel,direct-key-count defined, ··· 189 167 return error == -EINVAL ? 0 : error; 190 168 } 191 169 192 - error = of_property_read_u32(np, "marvell,direct-key-mask", 193 - &pdata->direct_key_mask); 170 + error = device_property_read_u32(dev, "marvell,direct-key-mask", 171 + &keypad->direct_key_mask); 194 172 if (error) { 195 173 if (error != -EINVAL) 196 174 return error; 197 175 198 176 /* 199 177 * If marvell,direct-key-mask is not defined, driver will use 200 - * default value. Default value is set when configure the keypad. 178 + * a default value based on number of direct keys set up. 179 + * The default value is calculated in pxa27x_keypad_config(). 201 180 */ 202 - pdata->direct_key_mask = 0; 181 + keypad->direct_key_mask = 0; 203 182 } 204 183 205 - pdata->direct_key_low_active = of_property_read_bool(np, 206 - "marvell,direct-key-low-active"); 184 + keypad->direct_key_low_active = 185 + device_property_read_bool(dev, "marvell,direct-key-low-active"); 207 186 208 - prop = of_get_property(np, "marvell,direct-key-map", &proplen); 209 - if (!prop) 187 + count = device_property_count_u16(dev, "marvell,direct-key-map"); 188 + if (count <= 0 || count > MAX_DIRECT_KEY_NUM) 210 189 return -EINVAL; 211 190 212 - if (proplen % sizeof(u16)) 213 - return -EINVAL; 191 + error = device_property_read_u16_array(dev, "marvell,direct-key-map", 192 + &keypad->keycodes[MAX_MATRIX_KEY_NUM], 193 + count); 214 194 215 - size = proplen / sizeof(u16); 216 - 217 - /* Only MAX_DIRECT_KEY_NUM is accepted.*/ 218 - if (size > MAX_DIRECT_KEY_NUM) 219 - return -EINVAL; 220 - 221 - for (i = 0; i < size; i++) { 222 - code = be16_to_cpup(prop + i); 223 - keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; 195 + for (i = 0; i < count; i++) { 196 + code = keypad->keycodes[MAX_MATRIX_KEY_NUM + i]; 224 197 __set_bit(code, input_dev->keybit); 225 198 } 226 199 227 200 return 0; 228 201 } 229 202 230 - static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad, 231 - struct pxa27x_keypad_platform_data *pdata) 203 + static int pxa27x_keypad_rotary_parse(struct pxa27x_keypad *keypad) 232 204 { 233 - const __be32 *prop; 234 - int i, relkey_ret; 235 - unsigned int code, proplen; 236 - const char *rotaryname[2] = { 237 - "marvell,rotary0", "marvell,rotary1"}; 238 - const char relkeyname[] = {"marvell,rotary-rel-key"}; 205 + static const char * const rotaryname[] = { "marvell,rotary0", "marvell,rotary1" }; 239 206 struct input_dev *input_dev = keypad->input_dev; 240 207 struct device *dev = input_dev->dev.parent; 241 - struct device_node *np = dev->of_node; 208 + struct pxa27x_keypad_rotary *encoder; 209 + unsigned int code; 210 + int i; 211 + int error; 242 212 243 - relkey_ret = of_property_read_u32(np, relkeyname, &code); 244 - /* if can read correct rotary key-code, we do not need this. */ 245 - if (relkey_ret == 0) { 246 - unsigned short relcode; 213 + error = device_property_read_u32(dev, "marvell,rotary-rel-key", &code); 214 + if (!error) { 215 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++, code >>= 16) { 216 + encoder = &keypad->rotary[i]; 217 + encoder->enabled = true; 218 + encoder->rel_code = code & 0xffff; 219 + input_set_capability(input_dev, EV_REL, encoder->rel_code); 220 + } 247 221 248 - /* rotary0 taks lower half, rotary1 taks upper half. */ 249 - relcode = code & 0xffff; 250 - pdata->rotary0_rel_code = (code & 0xffff); 251 - __set_bit(relcode, input_dev->relbit); 252 - 253 - relcode = code >> 16; 254 - pdata->rotary1_rel_code = relcode; 255 - __set_bit(relcode, input_dev->relbit); 222 + return 0; 256 223 } 257 224 258 - for (i = 0; i < 2; i++) { 259 - prop = of_get_property(np, rotaryname[i], &proplen); 225 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { 226 + encoder = &keypad->rotary[i]; 227 + 260 228 /* 261 229 * If the prop is not set, it means keypad does not need 262 230 * initialize the rotaryX. 263 231 */ 264 - if (!prop) 232 + if (!device_property_present(dev, rotaryname[i])) 265 233 continue; 266 234 267 - code = be32_to_cpup(prop); 235 + error = device_property_read_u32(dev, rotaryname[i], &code); 236 + if (error) 237 + return error; 238 + 268 239 /* 269 240 * Not all up/down key code are valid. 270 241 * Now we depends on direct-rel-code. 271 242 */ 272 - if ((!(code & 0xffff) || !(code >> 16)) && relkey_ret) { 273 - return relkey_ret; 274 - } else { 275 - unsigned int n = MAX_MATRIX_KEY_NUM + (i << 1); 276 - unsigned short keycode; 243 + if (!(code & 0xffff) || !(code >> 16)) 244 + return -EINVAL; 277 245 278 - keycode = code & 0xffff; 279 - keypad->keycodes[n] = keycode; 280 - __set_bit(keycode, input_dev->keybit); 246 + encoder->enabled = true; 247 + encoder->rel_code = -1; 248 + encoder->key_codes = &keypad->keycodes[MAX_MATRIX_KEY_NUM + i * 2]; 249 + encoder->key_codes[0] = code & 0xffff; 250 + encoder->key_codes[1] = code >> 16; 281 251 282 - keycode = code >> 16; 283 - keypad->keycodes[n + 1] = keycode; 284 - __set_bit(keycode, input_dev->keybit); 285 - 286 - if (i == 0) 287 - pdata->rotary0_rel_code = -1; 288 - else 289 - pdata->rotary1_rel_code = -1; 290 - } 291 - if (i == 0) 292 - pdata->enable_rotary0 = 1; 293 - else 294 - pdata->enable_rotary1 = 1; 252 + input_set_capability(input_dev, EV_KEY, encoder->key_codes[0]); 253 + input_set_capability(input_dev, EV_KEY, encoder->key_codes[1]); 295 254 } 296 - 297 - keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; 298 - keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; 299 255 300 256 return 0; 301 257 } 302 258 303 - static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 259 + static int pxa27x_keypad_parse_properties(struct pxa27x_keypad *keypad) 304 260 { 305 261 struct input_dev *input_dev = keypad->input_dev; 306 262 struct device *dev = input_dev->dev.parent; 307 - struct device_node *np = dev->of_node; 308 - struct pxa27x_keypad_platform_data *pdata; 309 263 int error; 310 264 311 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 312 - if (!pdata) { 313 - dev_err(dev, "failed to allocate memory for pdata\n"); 314 - return -ENOMEM; 315 - } 316 - 317 - error = pxa27x_keypad_matrix_key_parse_dt(keypad, pdata); 265 + error = pxa27x_keypad_matrix_key_parse(keypad); 318 266 if (error) { 319 267 dev_err(dev, "failed to parse matrix key\n"); 320 268 return error; 321 269 } 322 270 323 - error = pxa27x_keypad_direct_key_parse_dt(keypad, pdata); 271 + error = pxa27x_keypad_direct_key_parse(keypad); 324 272 if (error) { 325 273 dev_err(dev, "failed to parse direct key\n"); 326 274 return error; 327 275 } 328 276 329 - error = pxa27x_keypad_rotary_parse_dt(keypad, pdata); 277 + error = pxa27x_keypad_rotary_parse(keypad); 330 278 if (error) { 331 279 dev_err(dev, "failed to parse rotary key\n"); 332 280 return error; 333 281 } 334 282 335 - error = of_property_read_u32(np, "marvell,debounce-interval", 336 - &pdata->debounce_interval); 283 + error = device_property_read_u32(dev, "marvell,debounce-interval", 284 + &keypad->debounce_interval); 337 285 if (error) { 338 286 dev_err(dev, "failed to parse debounce-interval\n"); 339 287 return error; ··· 315 323 */ 316 324 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 317 325 318 - keypad->pdata = pdata; 319 - return 0; 320 - } 321 - 322 - #else 323 - 324 - static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) 325 - { 326 - dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); 327 - 328 - return -EINVAL; 329 - } 330 - 331 - #endif 332 - 333 - static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) 334 - { 335 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 336 - struct input_dev *input_dev = keypad->input_dev; 337 - unsigned short keycode; 338 - int i; 339 - int error; 340 - 341 - error = matrix_keypad_build_keymap(pdata->matrix_keymap_data, NULL, 342 - pdata->matrix_key_rows, 343 - pdata->matrix_key_cols, 344 - keypad->keycodes, input_dev); 345 - if (error) 346 - return error; 347 - 348 - /* 349 - * The keycodes may not only include matrix keys but also the direct 350 - * or rotary keys. 351 - */ 352 - input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); 353 - 354 - /* For direct keys. */ 355 - for (i = 0; i < pdata->direct_key_num; i++) { 356 - keycode = pdata->direct_key_map[i]; 357 - keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; 358 - __set_bit(keycode, input_dev->keybit); 359 - } 360 - 361 - if (pdata->enable_rotary0) { 362 - if (pdata->rotary0_up_key && pdata->rotary0_down_key) { 363 - keycode = pdata->rotary0_up_key; 364 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; 365 - __set_bit(keycode, input_dev->keybit); 366 - 367 - keycode = pdata->rotary0_down_key; 368 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; 369 - __set_bit(keycode, input_dev->keybit); 370 - 371 - keypad->rotary_rel_code[0] = -1; 372 - } else { 373 - keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; 374 - __set_bit(pdata->rotary0_rel_code, input_dev->relbit); 375 - } 376 - } 377 - 378 - if (pdata->enable_rotary1) { 379 - if (pdata->rotary1_up_key && pdata->rotary1_down_key) { 380 - keycode = pdata->rotary1_up_key; 381 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; 382 - __set_bit(keycode, input_dev->keybit); 383 - 384 - keycode = pdata->rotary1_down_key; 385 - keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; 386 - __set_bit(keycode, input_dev->keybit); 387 - 388 - keypad->rotary_rel_code[1] = -1; 389 - } else { 390 - keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; 391 - __set_bit(pdata->rotary1_rel_code, input_dev->relbit); 392 - } 393 - } 394 - 395 - __clear_bit(KEY_RESERVED, input_dev->keybit); 396 - 397 326 return 0; 398 327 } 399 328 400 329 static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) 401 330 { 402 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 403 331 struct input_dev *input_dev = keypad->input_dev; 404 332 int row, col, num_keys_pressed = 0; 405 - uint32_t new_state[MAX_MATRIX_KEY_COLS]; 406 - uint32_t kpas = keypad_readl(KPAS); 333 + u32 new_state[MAX_MATRIX_KEY_COLS]; 334 + u32 kpas = keypad_readl(KPAS); 407 335 408 336 num_keys_pressed = KPAS_MUKP(kpas); 409 337 ··· 337 425 row = KPAS_RP(kpas); 338 426 339 427 /* if invalid row/col, treat as no key pressed */ 340 - if (col >= pdata->matrix_key_cols || 341 - row >= pdata->matrix_key_rows) 428 + if (col >= keypad->matrix_key_cols || 429 + row >= keypad->matrix_key_rows) 342 430 goto scan; 343 431 344 - new_state[col] = (1 << row); 432 + new_state[col] = BIT(row); 345 433 goto scan; 346 434 } 347 435 348 436 if (num_keys_pressed > 1) { 349 - uint32_t kpasmkp0 = keypad_readl(KPASMKP0); 350 - uint32_t kpasmkp1 = keypad_readl(KPASMKP1); 351 - uint32_t kpasmkp2 = keypad_readl(KPASMKP2); 352 - uint32_t kpasmkp3 = keypad_readl(KPASMKP3); 437 + u32 kpasmkp0 = keypad_readl(KPASMKP0); 438 + u32 kpasmkp1 = keypad_readl(KPASMKP1); 439 + u32 kpasmkp2 = keypad_readl(KPASMKP2); 440 + u32 kpasmkp3 = keypad_readl(KPASMKP3); 353 441 354 442 new_state[0] = kpasmkp0 & KPASMKP_MKC_MASK; 355 443 new_state[1] = (kpasmkp0 >> 16) & KPASMKP_MKC_MASK; ··· 361 449 new_state[7] = (kpasmkp3 >> 16) & KPASMKP_MKC_MASK; 362 450 } 363 451 scan: 364 - for (col = 0; col < pdata->matrix_key_cols; col++) { 365 - uint32_t bits_changed; 452 + for (col = 0; col < keypad->matrix_key_cols; col++) { 453 + u32 bits_changed; 366 454 int code; 367 455 368 456 bits_changed = keypad->matrix_key_state[col] ^ new_state[col]; 369 457 if (bits_changed == 0) 370 458 continue; 371 459 372 - for (row = 0; row < pdata->matrix_key_rows; row++) { 373 - if ((bits_changed & (1 << row)) == 0) 460 + for (row = 0; row < keypad->matrix_key_rows; row++) { 461 + if ((bits_changed & BIT(row)) == 0) 374 462 continue; 375 463 376 464 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); 377 465 378 466 input_event(input_dev, EV_MSC, MSC_SCAN, code); 379 467 input_report_key(input_dev, keypad->keycodes[code], 380 - new_state[col] & (1 << row)); 468 + new_state[col] & BIT(row)); 381 469 } 382 470 } 383 471 input_sync(input_dev); ··· 386 474 387 475 #define DEFAULT_KPREC (0x007f007f) 388 476 389 - static inline int rotary_delta(uint32_t kprec) 477 + static inline int rotary_delta(u32 kprec) 390 478 { 391 479 if (kprec & KPREC_OF0) 392 480 return (kprec & 0xff) + 0x7f; ··· 398 486 399 487 static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) 400 488 { 489 + struct pxa27x_keypad_rotary *encoder = &keypad->rotary[r]; 401 490 struct input_dev *dev = keypad->input_dev; 402 491 403 - if (delta == 0) 492 + if (!encoder->enabled || delta == 0) 404 493 return; 405 494 406 - if (keypad->rotary_rel_code[r] == -1) { 407 - int code = MAX_MATRIX_KEY_NUM + 2 * r + (delta > 0 ? 0 : 1); 408 - unsigned char keycode = keypad->keycodes[code]; 495 + if (encoder->rel_code == -1) { 496 + int idx = delta > 0 ? 0 : 1; 497 + int code = MAX_MATRIX_KEY_NUM + 2 * r + idx; 498 + unsigned char keycode = encoder->key_codes[idx]; 409 499 410 500 /* simulate a press-n-release */ 411 501 input_event(dev, EV_MSC, MSC_SCAN, code); ··· 417 503 input_report_key(dev, keycode, 0); 418 504 input_sync(dev); 419 505 } else { 420 - input_report_rel(dev, keypad->rotary_rel_code[r], delta); 506 + input_report_rel(dev, encoder->rel_code, delta); 421 507 input_sync(dev); 422 508 } 423 509 } 424 510 425 511 static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) 426 512 { 427 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 428 - uint32_t kprec; 513 + u32 kprec; 514 + int i; 429 515 430 516 /* read and reset to default count value */ 431 517 kprec = keypad_readl(KPREC); 432 518 keypad_writel(KPREC, DEFAULT_KPREC); 433 519 434 - if (pdata->enable_rotary0) 520 + for (i = 0; i < MAX_ROTARY_ENCODERS; i++) { 435 521 report_rotary_event(keypad, 0, rotary_delta(kprec)); 436 - 437 - if (pdata->enable_rotary1) 438 - report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); 522 + kprec >>= 16; 523 + } 439 524 } 440 525 441 526 static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) 442 527 { 443 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 444 528 struct input_dev *input_dev = keypad->input_dev; 445 529 unsigned int new_state; 446 - uint32_t kpdk, bits_changed; 530 + u32 kpdk, bits_changed; 447 531 int i; 448 532 449 533 kpdk = keypad_readl(KPDK); 450 534 451 - if (pdata->enable_rotary0 || pdata->enable_rotary1) 535 + if (keypad->rotary[0].enabled || keypad->rotary[1].enabled) 452 536 pxa27x_keypad_scan_rotary(keypad); 453 537 454 538 /* 455 539 * The KPDR_DK only output the key pin level, so it relates to board, 456 540 * and low level may be active. 457 541 */ 458 - if (pdata->direct_key_low_active) 542 + if (keypad->direct_key_low_active) 459 543 new_state = ~KPDK_DK(kpdk) & keypad->direct_key_mask; 460 544 else 461 545 new_state = KPDK_DK(kpdk) & keypad->direct_key_mask; ··· 463 551 if (bits_changed == 0) 464 552 return; 465 553 466 - for (i = 0; i < pdata->direct_key_num; i++) { 467 - if (bits_changed & (1 << i)) { 554 + for (i = 0; i < keypad->direct_key_num; i++) { 555 + if (bits_changed & BIT(i)) { 468 556 int code = MAX_MATRIX_KEY_NUM + i; 469 557 470 558 input_event(input_dev, EV_MSC, MSC_SCAN, code); 471 559 input_report_key(input_dev, keypad->keycodes[code], 472 - new_state & (1 << i)); 560 + new_state & BIT(i)); 473 561 } 474 562 } 475 563 input_sync(input_dev); 476 564 keypad->direct_key_state = new_state; 477 565 } 478 566 479 - static void clear_wakeup_event(struct pxa27x_keypad *keypad) 480 - { 481 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 482 - 483 - if (pdata->clear_wakeup_event) 484 - (pdata->clear_wakeup_event)(); 485 - } 486 - 487 567 static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 488 568 { 489 569 struct pxa27x_keypad *keypad = dev_id; 490 570 unsigned long kpc = keypad_readl(KPC); 491 - 492 - clear_wakeup_event(keypad); 493 571 494 572 if (kpc & KPC_DI) 495 573 pxa27x_keypad_scan_direct(keypad); ··· 492 590 493 591 static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) 494 592 { 495 - const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; 496 593 unsigned int mask = 0, direct_key_num = 0; 497 594 unsigned long kpc = 0; 498 595 ··· 499 598 keypad_readl(KPC); 500 599 501 600 /* enable matrix keys with automatic scan */ 502 - if (pdata->matrix_key_rows && pdata->matrix_key_cols) { 601 + if (keypad->matrix_key_rows && keypad->matrix_key_cols) { 503 602 kpc |= KPC_ASACT | KPC_MIE | KPC_ME | KPC_MS_ALL; 504 - kpc |= KPC_MKRN(pdata->matrix_key_rows) | 505 - KPC_MKCN(pdata->matrix_key_cols); 603 + kpc |= KPC_MKRN(keypad->matrix_key_rows) | 604 + KPC_MKCN(keypad->matrix_key_cols); 506 605 } 507 606 508 607 /* enable rotary key, debounce interval same as direct keys */ 509 - if (pdata->enable_rotary0) { 608 + if (keypad->rotary[0].enabled) { 510 609 mask |= 0x03; 511 610 direct_key_num = 2; 512 611 kpc |= KPC_REE0; 513 612 } 514 613 515 - if (pdata->enable_rotary1) { 614 + if (keypad->rotary[1].enabled) { 516 615 mask |= 0x0c; 517 616 direct_key_num = 4; 518 617 kpc |= KPC_REE1; 519 618 } 520 619 521 - if (pdata->direct_key_num > direct_key_num) 522 - direct_key_num = pdata->direct_key_num; 620 + if (keypad->direct_key_num > direct_key_num) 621 + direct_key_num = keypad->direct_key_num; 523 622 524 623 /* 525 624 * Direct keys usage may not start from KP_DKIN0, check the platfrom 526 625 * mask data to config the specific. 527 626 */ 528 - if (pdata->direct_key_mask) 529 - keypad->direct_key_mask = pdata->direct_key_mask; 530 - else 531 - keypad->direct_key_mask = ((1 << direct_key_num) - 1) & ~mask; 627 + if (!keypad->direct_key_mask) 628 + keypad->direct_key_mask = GENMASK(direct_key_num - 1, 0) & ~mask; 532 629 533 630 /* enable direct key */ 534 631 if (direct_key_num) ··· 534 635 535 636 keypad_writel(KPC, kpc | KPC_RE_ZERO_DEB); 536 637 keypad_writel(KPREC, DEFAULT_KPREC); 537 - keypad_writel(KPKDI, pdata->debounce_interval); 638 + keypad_writel(KPKDI, keypad->debounce_interval); 538 639 } 539 640 540 641 static int pxa27x_keypad_open(struct input_dev *dev) ··· 608 709 static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, 609 710 pxa27x_keypad_suspend, pxa27x_keypad_resume); 610 711 611 - 612 712 static int pxa27x_keypad_probe(struct platform_device *pdev) 613 713 { 614 - const struct pxa27x_keypad_platform_data *pdata = 615 - dev_get_platdata(&pdev->dev); 616 - struct device_node *np = pdev->dev.of_node; 617 714 struct pxa27x_keypad *keypad; 618 715 struct input_dev *input_dev; 619 - int irq, error; 620 - 621 - /* Driver need build keycode from device tree or pdata */ 622 - if (!np && !pdata) 623 - return -EINVAL; 716 + int irq; 717 + int error; 624 718 625 719 irq = platform_get_irq(pdev, 0); 626 720 if (irq < 0) ··· 628 736 if (!input_dev) 629 737 return -ENOMEM; 630 738 631 - keypad->pdata = pdata; 632 739 keypad->input_dev = input_dev; 633 740 keypad->irq = irq; 634 741 ··· 656 765 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 657 766 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 658 767 659 - if (pdata) { 660 - error = pxa27x_keypad_build_keycode(keypad); 661 - } else { 662 - error = pxa27x_keypad_build_keycode_from_dt(keypad); 663 - /* 664 - * Data that we get from DT resides in dynamically 665 - * allocated memory so we need to update our pdata 666 - * pointer. 667 - */ 668 - pdata = keypad->pdata; 669 - } 768 + error = pxa27x_keypad_parse_properties(keypad); 670 769 if (error) { 671 - dev_err(&pdev->dev, "failed to build keycode\n"); 770 + dev_err(&pdev->dev, "failed to parse keypad properties\n"); 672 771 return error; 673 - } 674 - 675 - keypad->row_shift = get_count_order(pdata->matrix_key_cols); 676 - 677 - if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || 678 - (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { 679 - input_dev->evbit[0] |= BIT_MASK(EV_REL); 680 772 } 681 773 682 774 error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler,
+15 -56
drivers/input/keyboard/spear-keyboard.c
··· 14 14 #include <linux/errno.h> 15 15 #include <linux/interrupt.h> 16 16 #include <linux/input.h> 17 + #include <linux/input/matrix_keypad.h> 17 18 #include <linux/io.h> 18 19 #include <linux/irq.h> 19 20 #include <linux/kernel.h> ··· 23 22 #include <linux/platform_device.h> 24 23 #include <linux/slab.h> 25 24 #include <linux/types.h> 26 - #include <linux/platform_data/keyboard-spear.h> 27 25 28 26 /* Keyboard Registers */ 29 27 #define MODE_CTL_REG 0x00 ··· 56 56 void __iomem *io_base; 57 57 struct clk *clk; 58 58 unsigned int irq; 59 - unsigned int mode; 60 - unsigned int suspended_rate; 59 + u32 mode; 60 + u32 suspended_rate; 61 + u32 mode_ctl_reg; 61 62 unsigned short last_key; 62 63 unsigned short keycodes[NUM_ROWS * NUM_COLS]; 63 - bool rep; 64 64 bool irq_wake_enabled; 65 - u32 mode_ctl_reg; 66 65 }; 67 66 68 67 static irqreturn_t spear_kbd_interrupt(int irq, void *dev_id) ··· 142 143 kbd->last_key = KEY_RESERVED; 143 144 } 144 145 145 - #ifdef CONFIG_OF 146 - static int spear_kbd_parse_dt(struct platform_device *pdev, 147 - struct spear_kbd *kbd) 148 - { 149 - struct device_node *np = pdev->dev.of_node; 150 - int error; 151 - u32 val, suspended_rate; 152 - 153 - if (!np) { 154 - dev_err(&pdev->dev, "Missing DT data\n"); 155 - return -EINVAL; 156 - } 157 - 158 - if (of_property_read_bool(np, "autorepeat")) 159 - kbd->rep = true; 160 - 161 - if (of_property_read_u32(np, "suspended_rate", &suspended_rate)) 162 - kbd->suspended_rate = suspended_rate; 163 - 164 - error = of_property_read_u32(np, "st,mode", &val); 165 - if (error) { 166 - dev_err(&pdev->dev, "DT: Invalid or missing mode\n"); 167 - return error; 168 - } 169 - 170 - kbd->mode = val; 171 - return 0; 172 - } 173 - #else 174 - static inline int spear_kbd_parse_dt(struct platform_device *pdev, 175 - struct spear_kbd *kbd) 176 - { 177 - return -ENOSYS; 178 - } 179 - #endif 180 - 181 146 static int spear_kbd_probe(struct platform_device *pdev) 182 147 { 183 - struct kbd_platform_data *pdata = dev_get_platdata(&pdev->dev); 184 - const struct matrix_keymap_data *keymap = pdata ? pdata->keymap : NULL; 185 148 struct spear_kbd *kbd; 186 149 struct input_dev *input_dev; 187 150 int irq; ··· 159 198 return -ENOMEM; 160 199 } 161 200 201 + error = device_property_read_u32(&pdev->dev, "st,mode", &kbd->mode); 202 + if (error) { 203 + dev_err(&pdev->dev, "Invalid or missing mode\n"); 204 + return error; 205 + } 206 + 207 + device_property_read_u32(&pdev->dev, "suspended_rate", &kbd->suspended_rate); 208 + 162 209 input_dev = devm_input_allocate_device(&pdev->dev); 163 210 if (!input_dev) { 164 211 dev_err(&pdev->dev, "unable to allocate input device\n"); ··· 175 206 176 207 kbd->input = input_dev; 177 208 kbd->irq = irq; 178 - 179 - if (!pdata) { 180 - error = spear_kbd_parse_dt(pdev, kbd); 181 - if (error) 182 - return error; 183 - } else { 184 - kbd->mode = pdata->mode; 185 - kbd->rep = pdata->rep; 186 - kbd->suspended_rate = pdata->suspended_rate; 187 - } 188 209 189 210 kbd->io_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); 190 211 if (IS_ERR(kbd->io_base)) ··· 193 234 input_dev->open = spear_kbd_open; 194 235 input_dev->close = spear_kbd_close; 195 236 196 - error = matrix_keypad_build_keymap(keymap, NULL, NUM_ROWS, NUM_COLS, 237 + error = matrix_keypad_build_keymap(NULL, NULL, NUM_ROWS, NUM_COLS, 197 238 kbd->keycodes, input_dev); 198 239 if (error) { 199 240 dev_err(&pdev->dev, "Failed to build keymap\n"); 200 241 return error; 201 242 } 202 243 203 - if (kbd->rep) 244 + if (device_property_read_bool(&pdev->dev, "autorepeat")) 204 245 __set_bit(EV_REP, input_dev->evbit); 205 246 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 206 247 207 248 input_set_drvdata(input_dev, kbd); 208 249 209 250 error = devm_request_irq(&pdev->dev, irq, spear_kbd_interrupt, 0, 210 - "keyboard", kbd); 251 + "keyboard", kbd); 211 252 if (error) { 212 253 dev_err(&pdev->dev, "request_irq failed\n"); 213 254 return error;
-305
drivers/input/keyboard/tca6416-keypad.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Driver for keys on TCA6416 I2C IO expander 4 - * 5 - * Copyright (C) 2010 Texas Instruments 6 - * 7 - * Author : Sriramakrishnan.A.G. <srk@ti.com> 8 - */ 9 - 10 - #include <linux/types.h> 11 - #include <linux/module.h> 12 - #include <linux/init.h> 13 - #include <linux/delay.h> 14 - #include <linux/slab.h> 15 - #include <linux/interrupt.h> 16 - #include <linux/workqueue.h> 17 - #include <linux/i2c.h> 18 - #include <linux/input.h> 19 - #include <linux/tca6416_keypad.h> 20 - 21 - #define TCA6416_INPUT 0 22 - #define TCA6416_OUTPUT 1 23 - #define TCA6416_INVERT 2 24 - #define TCA6416_DIRECTION 3 25 - 26 - #define TCA6416_POLL_INTERVAL 100 /* msec */ 27 - 28 - static const struct i2c_device_id tca6416_id[] = { 29 - { "tca6416-keys", 16, }, 30 - { "tca6408-keys", 8, }, 31 - { } 32 - }; 33 - MODULE_DEVICE_TABLE(i2c, tca6416_id); 34 - 35 - struct tca6416_keypad_chip { 36 - uint16_t reg_output; 37 - uint16_t reg_direction; 38 - uint16_t reg_input; 39 - 40 - struct i2c_client *client; 41 - struct input_dev *input; 42 - int io_size; 43 - u16 pinmask; 44 - bool use_polling; 45 - struct tca6416_button buttons[]; 46 - }; 47 - 48 - static int tca6416_write_reg(struct tca6416_keypad_chip *chip, int reg, u16 val) 49 - { 50 - int error; 51 - 52 - error = chip->io_size > 8 ? 53 - i2c_smbus_write_word_data(chip->client, reg << 1, val) : 54 - i2c_smbus_write_byte_data(chip->client, reg, val); 55 - if (error < 0) { 56 - dev_err(&chip->client->dev, 57 - "%s failed, reg: %d, val: %d, error: %d\n", 58 - __func__, reg, val, error); 59 - return error; 60 - } 61 - 62 - return 0; 63 - } 64 - 65 - static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val) 66 - { 67 - int retval; 68 - 69 - retval = chip->io_size > 8 ? 70 - i2c_smbus_read_word_data(chip->client, reg << 1) : 71 - i2c_smbus_read_byte_data(chip->client, reg); 72 - if (retval < 0) { 73 - dev_err(&chip->client->dev, "%s failed, reg: %d, error: %d\n", 74 - __func__, reg, retval); 75 - return retval; 76 - } 77 - 78 - *val = (u16)retval; 79 - return 0; 80 - } 81 - 82 - static void tca6416_keys_scan(struct input_dev *input) 83 - { 84 - struct tca6416_keypad_chip *chip = input_get_drvdata(input); 85 - u16 reg_val, val; 86 - int error, i, pin_index; 87 - 88 - error = tca6416_read_reg(chip, TCA6416_INPUT, &reg_val); 89 - if (error) 90 - return; 91 - 92 - reg_val &= chip->pinmask; 93 - 94 - /* Figure out which lines have changed */ 95 - val = reg_val ^ chip->reg_input; 96 - chip->reg_input = reg_val; 97 - 98 - for (i = 0, pin_index = 0; i < 16; i++) { 99 - if (val & (1 << i)) { 100 - struct tca6416_button *button = &chip->buttons[pin_index]; 101 - unsigned int type = button->type ?: EV_KEY; 102 - int state = ((reg_val & (1 << i)) ? 1 : 0) 103 - ^ button->active_low; 104 - 105 - input_event(input, type, button->code, !!state); 106 - input_sync(input); 107 - } 108 - 109 - if (chip->pinmask & (1 << i)) 110 - pin_index++; 111 - } 112 - } 113 - 114 - /* 115 - * This is threaded IRQ handler and this can (and will) sleep. 116 - */ 117 - static irqreturn_t tca6416_keys_isr(int irq, void *dev_id) 118 - { 119 - tca6416_keys_scan(dev_id); 120 - 121 - return IRQ_HANDLED; 122 - } 123 - 124 - static int tca6416_keys_open(struct input_dev *dev) 125 - { 126 - struct tca6416_keypad_chip *chip = input_get_drvdata(dev); 127 - 128 - if (!chip->use_polling) { 129 - /* Get initial device state in case it has switches */ 130 - tca6416_keys_scan(dev); 131 - enable_irq(chip->client->irq); 132 - } 133 - 134 - return 0; 135 - } 136 - 137 - static void tca6416_keys_close(struct input_dev *dev) 138 - { 139 - struct tca6416_keypad_chip *chip = input_get_drvdata(dev); 140 - 141 - if (!chip->use_polling) 142 - disable_irq(chip->client->irq); 143 - } 144 - 145 - static int tca6416_setup_registers(struct tca6416_keypad_chip *chip) 146 - { 147 - int error; 148 - 149 - error = tca6416_read_reg(chip, TCA6416_OUTPUT, &chip->reg_output); 150 - if (error) 151 - return error; 152 - 153 - error = tca6416_read_reg(chip, TCA6416_DIRECTION, &chip->reg_direction); 154 - if (error) 155 - return error; 156 - 157 - /* ensure that keypad pins are set to input */ 158 - error = tca6416_write_reg(chip, TCA6416_DIRECTION, 159 - chip->reg_direction | chip->pinmask); 160 - if (error) 161 - return error; 162 - 163 - error = tca6416_read_reg(chip, TCA6416_DIRECTION, &chip->reg_direction); 164 - if (error) 165 - return error; 166 - 167 - error = tca6416_read_reg(chip, TCA6416_INPUT, &chip->reg_input); 168 - if (error) 169 - return error; 170 - 171 - chip->reg_input &= chip->pinmask; 172 - 173 - return 0; 174 - } 175 - 176 - static int tca6416_keypad_probe(struct i2c_client *client) 177 - { 178 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 179 - struct tca6416_keys_platform_data *pdata; 180 - struct tca6416_keypad_chip *chip; 181 - struct input_dev *input; 182 - int error; 183 - int i; 184 - 185 - /* Check functionality */ 186 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { 187 - dev_err(&client->dev, "%s adapter not supported\n", 188 - dev_driver_string(&client->adapter->dev)); 189 - return -ENODEV; 190 - } 191 - 192 - pdata = dev_get_platdata(&client->dev); 193 - if (!pdata) { 194 - dev_dbg(&client->dev, "no platform data\n"); 195 - return -EINVAL; 196 - } 197 - 198 - chip = devm_kzalloc(&client->dev, 199 - struct_size(chip, buttons, pdata->nbuttons), 200 - GFP_KERNEL); 201 - if (!chip) 202 - return -ENOMEM; 203 - 204 - input = devm_input_allocate_device(&client->dev); 205 - if (!input) 206 - return -ENOMEM; 207 - 208 - chip->client = client; 209 - chip->input = input; 210 - chip->io_size = id->driver_data; 211 - chip->pinmask = pdata->pinmask; 212 - chip->use_polling = pdata->use_polling; 213 - 214 - input->phys = "tca6416-keys/input0"; 215 - input->name = client->name; 216 - 217 - input->open = tca6416_keys_open; 218 - input->close = tca6416_keys_close; 219 - 220 - input->id.bustype = BUS_HOST; 221 - input->id.vendor = 0x0001; 222 - input->id.product = 0x0001; 223 - input->id.version = 0x0100; 224 - 225 - /* Enable auto repeat feature of Linux input subsystem */ 226 - if (pdata->rep) 227 - __set_bit(EV_REP, input->evbit); 228 - 229 - for (i = 0; i < pdata->nbuttons; i++) { 230 - unsigned int type; 231 - 232 - chip->buttons[i] = pdata->buttons[i]; 233 - type = (pdata->buttons[i].type) ?: EV_KEY; 234 - input_set_capability(input, type, pdata->buttons[i].code); 235 - } 236 - 237 - input_set_drvdata(input, chip); 238 - 239 - /* 240 - * Initialize cached registers from their original values. 241 - * we can't share this chip with another i2c master. 242 - */ 243 - error = tca6416_setup_registers(chip); 244 - if (error) 245 - return error; 246 - 247 - if (chip->use_polling) { 248 - error = input_setup_polling(input, tca6416_keys_scan); 249 - if (error) { 250 - dev_err(&client->dev, "Failed to setup polling\n"); 251 - return error; 252 - } 253 - 254 - input_set_poll_interval(input, TCA6416_POLL_INTERVAL); 255 - } else { 256 - error = devm_request_threaded_irq(&client->dev, client->irq, 257 - NULL, tca6416_keys_isr, 258 - IRQF_TRIGGER_FALLING | 259 - IRQF_ONESHOT | 260 - IRQF_NO_AUTOEN, 261 - "tca6416-keypad", input); 262 - if (error) { 263 - dev_dbg(&client->dev, 264 - "Unable to claim irq %d; error %d\n", 265 - client->irq, error); 266 - return error; 267 - } 268 - } 269 - 270 - error = input_register_device(input); 271 - if (error) { 272 - dev_dbg(&client->dev, 273 - "Unable to register input device, error: %d\n", error); 274 - return error; 275 - } 276 - 277 - i2c_set_clientdata(client, chip); 278 - 279 - return 0; 280 - } 281 - 282 - static struct i2c_driver tca6416_keypad_driver = { 283 - .driver = { 284 - .name = "tca6416-keypad", 285 - }, 286 - .probe = tca6416_keypad_probe, 287 - .id_table = tca6416_id, 288 - }; 289 - 290 - static int __init tca6416_keypad_init(void) 291 - { 292 - return i2c_add_driver(&tca6416_keypad_driver); 293 - } 294 - 295 - subsys_initcall(tca6416_keypad_init); 296 - 297 - static void __exit tca6416_keypad_exit(void) 298 - { 299 - i2c_del_driver(&tca6416_keypad_driver); 300 - } 301 - module_exit(tca6416_keypad_exit); 302 - 303 - MODULE_AUTHOR("Sriramakrishnan <srk@ti.com>"); 304 - MODULE_DESCRIPTION("Keypad driver over tca6416 IO expander"); 305 - MODULE_LICENSE("GPL");
+1 -12
drivers/input/keyboard/tca8418_keypad.c
··· 373 373 .probe = tca8418_keypad_probe, 374 374 .id_table = tca8418_id, 375 375 }; 376 - 377 - static int __init tca8418_keypad_init(void) 378 - { 379 - return i2c_add_driver(&tca8418_keypad_driver); 380 - } 381 - subsys_initcall(tca8418_keypad_init); 382 - 383 - static void __exit tca8418_keypad_exit(void) 384 - { 385 - i2c_del_driver(&tca8418_keypad_driver); 386 - } 387 - module_exit(tca8418_keypad_exit); 376 + module_i2c_driver(tca8418_keypad_driver); 388 377 389 378 MODULE_AUTHOR("Kyle Manna <kyle.manna@fuel7.com>"); 390 379 MODULE_DESCRIPTION("Keypad driver for TCA8418");
+6 -29
drivers/input/keyboard/twl4030_keypad.c
··· 28 28 * an internal state machine that decodes pressed keys, including 29 29 * multi-key combinations. 30 30 * 31 - * This driver lets boards define what keycodes they wish to report for 32 - * which scancodes, as part of the "struct twl4030_keypad_data" used in 33 - * the probe() routine. 34 - * 35 31 * See the TPS65950 documentation; that's the general availability 36 32 * version of the TWL5030 second generation part. 37 33 */ ··· 43 47 struct twl4030_keypad { 44 48 unsigned short keymap[TWL4030_KEYMAP_SIZE]; 45 49 u16 kp_state[TWL4030_MAX_ROWS]; 46 - bool autorepeat; 47 50 unsigned int n_rows; 48 51 unsigned int n_cols; 49 52 int irq; ··· 317 322 */ 318 323 static int twl4030_kp_probe(struct platform_device *pdev) 319 324 { 320 - struct twl4030_keypad_data *pdata = dev_get_platdata(&pdev->dev); 321 - const struct matrix_keymap_data *keymap_data = NULL; 322 325 struct twl4030_keypad *kp; 323 326 struct input_dev *input; 324 327 u8 reg; ··· 343 350 input->id.product = 0x0001; 344 351 input->id.version = 0x0003; 345 352 346 - if (pdata) { 347 - if (!pdata->rows || !pdata->cols || !pdata->keymap_data) { 348 - dev_err(&pdev->dev, "Missing platform_data\n"); 349 - return -EINVAL; 350 - } 351 - 352 - kp->n_rows = pdata->rows; 353 - kp->n_cols = pdata->cols; 354 - kp->autorepeat = pdata->rep; 355 - keymap_data = pdata->keymap_data; 356 - } else { 357 - error = matrix_keypad_parse_properties(&pdev->dev, &kp->n_rows, 358 - &kp->n_cols); 359 - if (error) 360 - return error; 361 - 362 - kp->autorepeat = true; 363 - } 353 + error = matrix_keypad_parse_properties(&pdev->dev, 354 + &kp->n_rows, &kp->n_cols); 355 + if (error) 356 + return error; 364 357 365 358 if (kp->n_rows > TWL4030_MAX_ROWS || kp->n_cols > TWL4030_MAX_COLS) { 366 359 dev_err(&pdev->dev, ··· 358 379 if (kp->irq < 0) 359 380 return kp->irq; 360 381 361 - error = matrix_keypad_build_keymap(keymap_data, NULL, 382 + error = matrix_keypad_build_keymap(NULL, NULL, 362 383 TWL4030_MAX_ROWS, 363 384 1 << TWL4030_ROW_SHIFT, 364 385 kp->keymap, input); ··· 368 389 } 369 390 370 391 input_set_capability(input, EV_MSC, MSC_SCAN); 371 - /* Enable auto repeat feature of Linux input subsystem */ 372 - if (kp->autorepeat) 373 - __set_bit(EV_REP, input->evbit); 392 + __set_bit(EV_REP, input->evbit); 374 393 375 394 error = input_register_device(input); 376 395 if (error) {
+11
drivers/input/misc/Kconfig
··· 126 126 To compile this driver as a module, choose M here: the 127 127 module will be called atmel_captouch. 128 128 129 + config INPUT_AW86927 130 + tristate "Awinic AW86927 Haptic Driver Support" 131 + depends on I2C && INPUT 132 + select INPUT_FF_MEMLESS 133 + select REGMAP_I2C 134 + help 135 + Say Y here if you have an Awinic AW86927 haptic chip. 136 + 137 + To compile this driver as a module, choose M here: the 138 + module will be called aw86927. 139 + 129 140 config INPUT_BBNSM_PWRKEY 130 141 tristate "NXP BBNSM Power Key Driver" 131 142 depends on ARCH_MXC || COMPILE_TEST
+1
drivers/input/misc/Makefile
··· 22 22 obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 23 23 obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o 24 24 obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH) += atmel_captouch.o 25 + obj-$(CONFIG_INPUT_AW86927) += aw86927.o 25 26 obj-$(CONFIG_INPUT_BBNSM_PWRKEY) += nxp-bbnsm-pwrkey.o 26 27 obj-$(CONFIG_INPUT_BMA150) += bma150.o 27 28 obj-$(CONFIG_INPUT_CM109) += cm109.o
+1
drivers/input/misc/ad714x.c
··· 6 6 */ 7 7 8 8 #include <linux/device.h> 9 + #include <linux/export.h> 9 10 #include <linux/input.h> 10 11 #include <linux/interrupt.h> 11 12 #include <linux/slab.h>
+1
drivers/input/misc/adxl34x.c
··· 9 9 10 10 #include <linux/device.h> 11 11 #include <linux/delay.h> 12 + #include <linux/export.h> 12 13 #include <linux/input.h> 13 14 #include <linux/interrupt.h> 14 15 #include <linux/irq.h>
+846
drivers/input/misc/aw86927.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2025 Griffin Kroah-Hartman <griffin.kroah@fairphone.com> 4 + * 5 + * Partially based on vendor driver: 6 + * Copyright (c) 2021 AWINIC Technology CO., LTD 7 + * 8 + */ 9 + 10 + #include <linux/bitfield.h> 11 + #include <linux/bits.h> 12 + #include <linux/delay.h> 13 + #include <linux/gpio/consumer.h> 14 + #include <linux/i2c.h> 15 + #include <linux/input.h> 16 + #include <linux/module.h> 17 + #include <linux/regmap.h> 18 + #include <linux/regulator/consumer.h> 19 + #include <linux/types.h> 20 + 21 + #define AW86927_RSTCFG_REG 0x00 22 + #define AW86927_RSTCFG_SOFTRST 0xaa 23 + 24 + #define AW86927_SYSINT_REG 0x02 25 + #define AW86927_SYSINT_BST_SCPI BIT(7) 26 + #define AW86927_SYSINT_BST_OVPI BIT(6) 27 + #define AW86927_SYSINT_UVLI BIT(5) 28 + #define AW86927_SYSINT_FF_AEI BIT(4) 29 + #define AW86927_SYSINT_FF_AFI BIT(3) 30 + #define AW86927_SYSINT_OCDI BIT(2) 31 + #define AW86927_SYSINT_OTI BIT(1) 32 + #define AW86927_SYSINT_DONEI BIT(0) 33 + 34 + #define AW86927_SYSINTM_REG 0x03 35 + #define AW86927_SYSINTM_BST_OVPM BIT(6) 36 + #define AW86927_SYSINTM_FF_AEM BIT(4) 37 + #define AW86927_SYSINTM_FF_AFM BIT(3) 38 + #define AW86927_SYSINTM_DONEM BIT(0) 39 + 40 + #define AW86927_PLAYCFG1_REG 0x06 41 + #define AW86927_PLAYCFG1_BST_MODE_MASK GENMASK(7, 7) 42 + #define AW86927_PLAYCFG1_BST_MODE_BYPASS 0 43 + #define AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK GENMASK(6, 0) 44 + #define AW86927_PLAYCFG1_BST_8500MV 0x50 45 + 46 + #define AW86927_PLAYCFG2_REG 0x07 47 + 48 + #define AW86927_PLAYCFG3_REG 0x08 49 + #define AW86927_PLAYCFG3_AUTO_BST_MASK GENMASK(4, 4) 50 + #define AW86927_PLAYCFG3_AUTO_BST_ENABLE 1 51 + #define AW86927_PLAYCFG3_AUTO_BST_DISABLE 0 52 + #define AW86927_PLAYCFG3_PLAY_MODE_MASK GENMASK(1, 0) 53 + #define AW86927_PLAYCFG3_PLAY_MODE_RAM 0 54 + 55 + #define AW86927_PLAYCFG4_REG 0x09 56 + #define AW86927_PLAYCFG4_STOP BIT(1) 57 + #define AW86927_PLAYCFG4_GO BIT(0) 58 + 59 + #define AW86927_WAVCFG1_REG 0x0a 60 + #define AW86927_WAVCFG1_WAVSEQ1_MASK GENMASK(6, 0) 61 + 62 + #define AW86927_WAVCFG2_REG 0x0b 63 + #define AW86927_WAVCFG2_WAVSEQ2_MASK GENMASK(6, 0) 64 + 65 + #define AW86927_WAVCFG9_REG 0x12 66 + #define AW86927_WAVCFG9_SEQ1LOOP_MASK GENMASK(7, 4) 67 + #define AW86927_WAVCFG9_SEQ1LOOP_INFINITELY 0x0f 68 + 69 + #define AW86927_CONTCFG1_REG 0x18 70 + #define AW86927_CONTCFG1_BRK_BST_MD_MASK GENMASK(6, 6) 71 + 72 + #define AW86927_CONTCFG5_REG 0x1c 73 + #define AW86927_CONTCFG5_BST_BRK_GAIN_MASK GENMASK(7, 4) 74 + #define AW86927_CONTCFG5_BRK_GAIN_MASK GENMASK(3, 0) 75 + 76 + #define AW86927_CONTCFG10_REG 0x21 77 + #define AW86927_CONTCFG10_BRK_TIME_MASK GENMASK(7, 0) 78 + #define AW86927_CONTCFG10_BRK_TIME_DEFAULT 8 79 + 80 + #define AW86927_CONTCFG13_REG 0x24 81 + #define AW86927_CONTCFG13_TSET_MASK GENMASK(7, 4) 82 + #define AW86927_CONTCFG13_BEME_SET_MASK GENMASK(3, 0) 83 + 84 + #define AW86927_BASEADDRH_REG 0x2d 85 + #define AW86927_BASEADDRL_REG 0x2e 86 + 87 + #define AW86927_GLBRD5_REG 0x3f 88 + #define AW86927_GLBRD5_STATE_MASK GENMASK(3, 0) 89 + #define AW86927_GLBRD5_STATE_STANDBY 0 90 + 91 + #define AW86927_RAMADDRH_REG 0x40 92 + 93 + #define AW86927_RAMADDRL_REG 0x41 94 + 95 + #define AW86927_RAMDATA_REG 0x42 96 + 97 + #define AW86927_SYSCTRL3_REG 0x45 98 + #define AW86927_SYSCTRL3_STANDBY_MASK GENMASK(5, 5) 99 + #define AW86927_SYSCTRL3_STANDBY_ON 1 100 + #define AW86927_SYSCTRL3_STANDBY_OFF 0 101 + #define AW86927_SYSCTRL3_EN_RAMINIT_MASK GENMASK(2, 2) 102 + #define AW86927_SYSCTRL3_EN_RAMINIT_ON 1 103 + #define AW86927_SYSCTRL3_EN_RAMINIT_OFF 0 104 + 105 + #define AW86927_SYSCTRL4_REG 0x46 106 + #define AW86927_SYSCTRL4_WAVDAT_MODE_MASK GENMASK(6, 5) 107 + #define AW86927_SYSCTRL4_WAVDAT_24K 0 108 + #define AW86927_SYSCTRL4_INT_EDGE_MODE_MASK GENMASK(4, 4) 109 + #define AW86927_SYSCTRL4_INT_EDGE_MODE_POS 0 110 + #define AW86927_SYSCTRL4_INT_MODE_MASK GENMASK(3, 3) 111 + #define AW86927_SYSCTRL4_INT_MODE_EDGE 1 112 + #define AW86927_SYSCTRL4_GAIN_BYPASS_MASK GENMASK(0, 0) 113 + 114 + #define AW86927_PWMCFG1_REG 0x48 115 + #define AW86927_PWMCFG1_PRC_EN_MASK GENMASK(7, 7) 116 + #define AW86927_PWMCFG1_PRC_DISABLE 0 117 + 118 + #define AW86927_PWMCFG3_REG 0x4a 119 + #define AW86927_PWMCFG3_PR_EN_MASK GENMASK(7, 7) 120 + #define AW86927_PWMCFG3_PRCTIME_MASK GENMASK(6, 0) 121 + 122 + #define AW86927_PWMCFG4_REG 0x4b 123 + #define AW86927_PWMCFG4_PRTIME_MASK GENMASK(7, 0) 124 + 125 + #define AW86927_VBATCTRL_REG 0x4c 126 + #define AW86927_VBATCTRL_VBAT_MODE_MASK GENMASK(6, 6) 127 + #define AW86927_VBATCTRL_VBAT_MODE_SW 0 128 + 129 + #define AW86927_DETCFG1_REG 0x4d 130 + #define AW86927_DETCFG1_DET_GO_MASK GENMASK(1, 0) 131 + #define AW86927_DETCFG1_DET_GO_DET_SEQ0 1 132 + #define AW86927_DETCFG1_DET_GO_NA 0 133 + 134 + #define AW86927_DETCFG2_REG 0x4e 135 + #define AW86927_DETCFG2_DET_SEQ0_MASK GENMASK(6, 3) 136 + #define AW86927_DETCFG2_DET_SEQ0_VBAT 0 137 + #define AW86927_DETCFG2_D2S_GAIN_MASK GENMASK(2, 0) 138 + #define AW86927_DETCFG2_D2S_GAIN_10 4 139 + 140 + #define AW86927_CHIPIDH_REG 0x57 141 + #define AW86927_CHIPIDL_REG 0x58 142 + #define AW86927_CHIPID 0x9270 143 + 144 + #define AW86927_TMCFG_REG 0x5b 145 + #define AW86927_TMCFG_UNLOCK 0x7d 146 + #define AW86927_TMCFG_LOCK 0x00 147 + 148 + #define AW86927_ANACFG11_REG 0x70 149 + 150 + #define AW86927_ANACFG12_REG 0x71 151 + #define AW86927_ANACFG12_BST_SKIP_MASK GENMASK(7, 7) 152 + #define AW86927_ANACFG12_BST_SKIP_SHUTDOWN 1 153 + 154 + #define AW86927_ANACFG13_REG 0x72 155 + #define AW86927_ANACFG13_BST_PC_MASK GENMASK(7, 4) 156 + #define AW86927_ANACFG13_BST_PEAKCUR_3P45A 6 157 + 158 + #define AW86927_ANACFG15_REG 0x74 159 + #define AW86927_ANACFG15_BST_PEAK_MODE_MASK GENMASK(7, 7) 160 + #define AW86927_ANACFG15_BST_PEAK_BACK 1 161 + 162 + #define AW86927_ANACFG16_REG 0x75 163 + #define AW86927_ANACFG16_BST_SRC_MASK GENMASK(4, 4) 164 + #define AW86927_ANACFG16_BST_SRC_3NS 0 165 + 166 + /* default value of base addr */ 167 + #define AW86927_RAM_BASE_ADDR 0x800 168 + #define AW86927_BASEADDRH_VAL 0x08 169 + #define AW86927_BASEADDRL_VAL 0x00 170 + 171 + enum aw86927_work_mode { 172 + AW86927_STANDBY_MODE, 173 + AW86927_RAM_MODE, 174 + }; 175 + 176 + struct aw86927_data { 177 + struct work_struct play_work; 178 + struct device *dev; 179 + struct input_dev *input_dev; 180 + struct i2c_client *client; 181 + struct regmap *regmap; 182 + struct gpio_desc *reset_gpio; 183 + bool running; 184 + }; 185 + 186 + static const struct regmap_config aw86927_regmap_config = { 187 + .reg_bits = 8, 188 + .val_bits = 8, 189 + .cache_type = REGCACHE_NONE, 190 + .max_register = 0x80, 191 + }; 192 + 193 + /* 194 + * Sine wave representing the magnitude of the drive to be used. 195 + * Data is encoded in two's complement. 196 + * round(84 * sin(x / 16.25)) 197 + */ 198 + static const u8 aw86927_waveform[] = { 199 + 0x00, 0x05, 0x0a, 0x0f, 0x14, 0x1a, 0x1f, 0x23, 0x28, 0x2d, 0x31, 0x35, 200 + 0x39, 0x3d, 0x41, 0x44, 0x47, 0x4a, 0x4c, 0x4f, 0x51, 0x52, 0x53, 0x54, 201 + 0x55, 0x55, 0x55, 0x55, 0x55, 0x54, 0x52, 0x51, 0x4f, 0x4d, 0x4a, 0x47, 202 + 0x44, 0x41, 0x3d, 0x3a, 0x36, 0x31, 0x2d, 0x28, 0x24, 0x1f, 0x1a, 0x15, 203 + 0x10, 0x0a, 0x05, 0x00, 0xfc, 0xf6, 0xf1, 0xec, 0xe7, 0xe2, 0xdd, 0xd8, 204 + 0xd4, 0xcf, 0xcb, 0xc7, 0xc3, 0xbf, 0xbc, 0xb9, 0xb6, 0xb4, 0xb1, 0xb0, 205 + 0xae, 0xad, 0xac, 0xab, 0xab, 0xab, 0xab, 0xab, 0xac, 0xae, 0xaf, 0xb1, 206 + 0xb3, 0xb6, 0xb8, 0xbc, 0xbf, 0xc2, 0xc6, 0xca, 0xce, 0xd3, 0xd7, 0xdc, 207 + 0xe1, 0xe6, 0xeb, 0xf0, 0xf5, 0xfb 208 + }; 209 + 210 + struct aw86927_sram_waveform_header { 211 + u8 version; 212 + __be16 start_address; 213 + __be16 end_address; 214 + } __packed; 215 + 216 + static const struct aw86927_sram_waveform_header sram_waveform_header = { 217 + .version = 0x01, 218 + .start_address = cpu_to_be16(AW86927_RAM_BASE_ADDR + 219 + sizeof(struct aw86927_sram_waveform_header)), 220 + .end_address = cpu_to_be16(AW86927_RAM_BASE_ADDR + 221 + sizeof(struct aw86927_sram_waveform_header) + 222 + ARRAY_SIZE(aw86927_waveform) - 1), 223 + }; 224 + 225 + static int aw86927_wait_enter_standby(struct aw86927_data *haptics) 226 + { 227 + unsigned int reg_val; 228 + int err; 229 + 230 + err = regmap_read_poll_timeout(haptics->regmap, AW86927_GLBRD5_REG, reg_val, 231 + (FIELD_GET(AW86927_GLBRD5_STATE_MASK, reg_val) == 232 + AW86927_GLBRD5_STATE_STANDBY), 233 + 2500, 2500 * 100); 234 + 235 + if (err) { 236 + dev_err(haptics->dev, "did not enter standby: %d\n", err); 237 + return err; 238 + } 239 + return 0; 240 + } 241 + 242 + static int aw86927_play_mode(struct aw86927_data *haptics, u8 play_mode) 243 + { 244 + int err; 245 + 246 + switch (play_mode) { 247 + case AW86927_STANDBY_MODE: 248 + /* Briefly toggle standby, then toggle back to standby off */ 249 + err = regmap_update_bits(haptics->regmap, 250 + AW86927_SYSCTRL3_REG, 251 + AW86927_SYSCTRL3_STANDBY_MASK, 252 + FIELD_PREP(AW86927_SYSCTRL3_STANDBY_MASK, 253 + AW86927_SYSCTRL3_STANDBY_ON)); 254 + if (err) 255 + return err; 256 + 257 + err = regmap_update_bits(haptics->regmap, 258 + AW86927_SYSCTRL3_REG, 259 + AW86927_SYSCTRL3_STANDBY_MASK, 260 + FIELD_PREP(AW86927_SYSCTRL3_STANDBY_MASK, 261 + AW86927_SYSCTRL3_STANDBY_OFF)); 262 + if (err) 263 + return err; 264 + 265 + break; 266 + 267 + case AW86927_RAM_MODE: 268 + err = regmap_update_bits(haptics->regmap, 269 + AW86927_PLAYCFG3_REG, 270 + AW86927_PLAYCFG3_PLAY_MODE_MASK, 271 + FIELD_PREP(AW86927_PLAYCFG3_PLAY_MODE_MASK, 272 + AW86927_PLAYCFG3_PLAY_MODE_RAM)); 273 + if (err) 274 + return err; 275 + 276 + err = regmap_update_bits(haptics->regmap, 277 + AW86927_PLAYCFG1_REG, 278 + AW86927_PLAYCFG1_BST_MODE_MASK, 279 + FIELD_PREP(AW86927_PLAYCFG1_BST_MODE_MASK, 280 + AW86927_PLAYCFG1_BST_MODE_BYPASS)); 281 + if (err) 282 + return err; 283 + 284 + err = regmap_update_bits(haptics->regmap, 285 + AW86927_VBATCTRL_REG, 286 + AW86927_VBATCTRL_VBAT_MODE_MASK, 287 + FIELD_PREP(AW86927_VBATCTRL_VBAT_MODE_MASK, 288 + AW86927_VBATCTRL_VBAT_MODE_SW)); 289 + if (err) 290 + return err; 291 + 292 + break; 293 + } 294 + 295 + return 0; 296 + } 297 + 298 + static int aw86927_stop(struct aw86927_data *haptics) 299 + { 300 + int err; 301 + 302 + err = regmap_write(haptics->regmap, AW86927_PLAYCFG4_REG, AW86927_PLAYCFG4_STOP); 303 + if (err) { 304 + dev_err(haptics->dev, "Failed to stop playback: %d\n", err); 305 + return err; 306 + } 307 + 308 + err = aw86927_wait_enter_standby(haptics); 309 + if (err) { 310 + dev_err(haptics->dev, "Failed to enter standby, trying to force it\n"); 311 + err = aw86927_play_mode(haptics, AW86927_STANDBY_MODE); 312 + if (err) 313 + return err; 314 + } 315 + 316 + return 0; 317 + } 318 + 319 + static int aw86927_haptics_play(struct input_dev *dev, void *data, struct ff_effect *effect) 320 + { 321 + struct aw86927_data *haptics = input_get_drvdata(dev); 322 + int level; 323 + 324 + level = effect->u.rumble.strong_magnitude; 325 + if (!level) 326 + level = effect->u.rumble.weak_magnitude; 327 + 328 + /* If already running, don't restart playback */ 329 + if (haptics->running && level) 330 + return 0; 331 + 332 + haptics->running = level; 333 + schedule_work(&haptics->play_work); 334 + 335 + return 0; 336 + } 337 + 338 + static int aw86927_play_sine(struct aw86927_data *haptics) 339 + { 340 + int err; 341 + 342 + err = aw86927_stop(haptics); 343 + if (err) 344 + return err; 345 + 346 + err = aw86927_play_mode(haptics, AW86927_RAM_MODE); 347 + if (err) 348 + return err; 349 + 350 + err = regmap_update_bits(haptics->regmap, AW86927_PLAYCFG3_REG, 351 + AW86927_PLAYCFG3_AUTO_BST_MASK, 352 + FIELD_PREP(AW86927_PLAYCFG3_AUTO_BST_MASK, 353 + AW86927_PLAYCFG3_AUTO_BST_ENABLE)); 354 + if (err) 355 + return err; 356 + 357 + /* Set waveseq 1 to the first wave */ 358 + err = regmap_update_bits(haptics->regmap, AW86927_WAVCFG1_REG, 359 + AW86927_WAVCFG1_WAVSEQ1_MASK, 360 + FIELD_PREP(AW86927_WAVCFG1_WAVSEQ1_MASK, 1)); 361 + if (err) 362 + return err; 363 + 364 + /* set wavseq 2 to zero */ 365 + err = regmap_update_bits(haptics->regmap, AW86927_WAVCFG2_REG, 366 + AW86927_WAVCFG2_WAVSEQ2_MASK, 367 + FIELD_PREP(AW86927_WAVCFG2_WAVSEQ2_MASK, 0)); 368 + if (err) 369 + return err; 370 + 371 + err = regmap_update_bits(haptics->regmap, 372 + AW86927_WAVCFG9_REG, 373 + AW86927_WAVCFG9_SEQ1LOOP_MASK, 374 + FIELD_PREP(AW86927_WAVCFG9_SEQ1LOOP_MASK, 375 + AW86927_WAVCFG9_SEQ1LOOP_INFINITELY)); 376 + if (err) 377 + return err; 378 + 379 + /* set gain to value lower than 0x80 to avoid distorted playback */ 380 + err = regmap_write(haptics->regmap, AW86927_PLAYCFG2_REG, 0x7c); 381 + if (err) 382 + return err; 383 + 384 + /* Start playback */ 385 + err = regmap_write(haptics->regmap, AW86927_PLAYCFG4_REG, AW86927_PLAYCFG4_GO); 386 + if (err) 387 + return err; 388 + 389 + return 0; 390 + } 391 + 392 + static void aw86927_close(struct input_dev *input) 393 + { 394 + struct aw86927_data *haptics = input_get_drvdata(input); 395 + struct device *dev = &haptics->client->dev; 396 + int err; 397 + 398 + cancel_work_sync(&haptics->play_work); 399 + 400 + err = aw86927_stop(haptics); 401 + if (err) 402 + dev_err(dev, "Failed to close the Driver: %d\n", err); 403 + } 404 + 405 + static void aw86927_haptics_play_work(struct work_struct *work) 406 + { 407 + struct aw86927_data *haptics = 408 + container_of(work, struct aw86927_data, play_work); 409 + struct device *dev = &haptics->client->dev; 410 + int err; 411 + 412 + if (haptics->running) 413 + err = aw86927_play_sine(haptics); 414 + else 415 + err = aw86927_stop(haptics); 416 + 417 + if (err) 418 + dev_err(dev, "Failed to execute work command: %d\n", err); 419 + } 420 + 421 + static void aw86927_hw_reset(struct aw86927_data *haptics) 422 + { 423 + /* Assert reset */ 424 + gpiod_set_value_cansleep(haptics->reset_gpio, 1); 425 + /* Wait ~1ms */ 426 + usleep_range(1000, 2000); 427 + /* Deassert reset */ 428 + gpiod_set_value_cansleep(haptics->reset_gpio, 0); 429 + /* Wait ~8ms until I2C is accessible */ 430 + usleep_range(8000, 8500); 431 + } 432 + 433 + static int aw86927_haptic_init(struct aw86927_data *haptics) 434 + { 435 + int err; 436 + 437 + err = regmap_update_bits(haptics->regmap, 438 + AW86927_SYSCTRL4_REG, 439 + AW86927_SYSCTRL4_WAVDAT_MODE_MASK, 440 + FIELD_PREP(AW86927_SYSCTRL4_WAVDAT_MODE_MASK, 441 + AW86927_SYSCTRL4_WAVDAT_24K)); 442 + if (err) 443 + return err; 444 + 445 + /* enable gain bypass */ 446 + err = regmap_update_bits(haptics->regmap, 447 + AW86927_SYSCTRL4_REG, 448 + AW86927_SYSCTRL4_GAIN_BYPASS_MASK, 449 + FIELD_PREP(AW86927_SYSCTRL4_GAIN_BYPASS_MASK, 450 + 0x01)); 451 + if (err) 452 + return err; 453 + 454 + err = regmap_write(haptics->regmap, 455 + AW86927_TMCFG_REG, AW86927_TMCFG_UNLOCK); 456 + if (err) 457 + return err; 458 + 459 + err = regmap_write(haptics->regmap, AW86927_ANACFG11_REG, 0x0f); 460 + if (err) 461 + return err; 462 + 463 + err = regmap_update_bits(haptics->regmap, 464 + AW86927_ANACFG12_REG, 465 + AW86927_ANACFG12_BST_SKIP_MASK, 466 + FIELD_PREP(AW86927_ANACFG12_BST_SKIP_MASK, 467 + AW86927_ANACFG12_BST_SKIP_SHUTDOWN)); 468 + if (err) 469 + return err; 470 + 471 + err = regmap_update_bits(haptics->regmap, 472 + AW86927_ANACFG15_REG, 473 + AW86927_ANACFG15_BST_PEAK_MODE_MASK, 474 + FIELD_PREP(AW86927_ANACFG15_BST_PEAK_MODE_MASK, 475 + AW86927_ANACFG15_BST_PEAK_BACK)); 476 + if (err) 477 + return err; 478 + 479 + err = regmap_update_bits(haptics->regmap, 480 + AW86927_ANACFG16_REG, 481 + AW86927_ANACFG16_BST_SRC_MASK, 482 + FIELD_PREP(AW86927_ANACFG16_BST_SRC_MASK, 483 + AW86927_ANACFG16_BST_SRC_3NS)); 484 + if (err) 485 + return err; 486 + 487 + err = regmap_write(haptics->regmap, 488 + AW86927_TMCFG_REG, AW86927_TMCFG_LOCK); 489 + if (err) 490 + return err; 491 + 492 + err = regmap_update_bits(haptics->regmap, 493 + AW86927_CONTCFG1_REG, 494 + AW86927_CONTCFG1_BRK_BST_MD_MASK, 495 + FIELD_PREP(AW86927_CONTCFG1_BRK_BST_MD_MASK, 0x00)); 496 + if (err) 497 + return err; 498 + 499 + err = regmap_write(haptics->regmap, 500 + AW86927_CONTCFG5_REG, 501 + FIELD_PREP(AW86927_CONTCFG5_BST_BRK_GAIN_MASK, 0x05) | 502 + FIELD_PREP(AW86927_CONTCFG5_BRK_GAIN_MASK, 0x08)); 503 + if (err) 504 + return err; 505 + 506 + err = regmap_update_bits(haptics->regmap, AW86927_CONTCFG10_REG, 507 + AW86927_CONTCFG10_BRK_TIME_MASK, 508 + FIELD_PREP(AW86927_CONTCFG10_BRK_TIME_MASK, 509 + AW86927_CONTCFG10_BRK_TIME_DEFAULT)); 510 + if (err) 511 + return err; 512 + 513 + err = regmap_write(haptics->regmap, 514 + AW86927_CONTCFG13_REG, 515 + FIELD_PREP(AW86927_CONTCFG13_TSET_MASK, 0x06) | 516 + FIELD_PREP(AW86927_CONTCFG13_BEME_SET_MASK, 0x02)); 517 + if (err) 518 + return err; 519 + 520 + err = regmap_update_bits(haptics->regmap, 521 + AW86927_DETCFG2_REG, 522 + AW86927_DETCFG2_D2S_GAIN_MASK, 523 + FIELD_PREP(AW86927_DETCFG2_D2S_GAIN_MASK, 524 + AW86927_DETCFG2_D2S_GAIN_10)); 525 + if (err) 526 + return err; 527 + 528 + err = regmap_update_bits(haptics->regmap, 529 + AW86927_PWMCFG1_REG, 530 + AW86927_PWMCFG1_PRC_EN_MASK, 531 + FIELD_PREP(AW86927_PWMCFG1_PRC_EN_MASK, 532 + AW86927_PWMCFG1_PRC_DISABLE)); 533 + if (err) 534 + return err; 535 + 536 + err = regmap_write(haptics->regmap, 537 + AW86927_PWMCFG3_REG, 538 + FIELD_PREP(AW86927_PWMCFG3_PR_EN_MASK, 0x01) | 539 + FIELD_PREP(AW86927_PWMCFG3_PRCTIME_MASK, 0x3f)); 540 + if (err) 541 + return err; 542 + 543 + err = regmap_update_bits(haptics->regmap, 544 + AW86927_PWMCFG4_REG, 545 + AW86927_PWMCFG4_PRTIME_MASK, 546 + FIELD_PREP(AW86927_PWMCFG4_PRTIME_MASK, 0x32)); 547 + if (err) 548 + return err; 549 + 550 + err = regmap_write(haptics->regmap, 551 + AW86927_TMCFG_REG, AW86927_TMCFG_UNLOCK); 552 + if (err) 553 + return err; 554 + 555 + err = regmap_update_bits(haptics->regmap, 556 + AW86927_ANACFG13_REG, 557 + AW86927_ANACFG13_BST_PC_MASK, 558 + FIELD_PREP(AW86927_ANACFG13_BST_PC_MASK, 559 + AW86927_ANACFG13_BST_PEAKCUR_3P45A)); 560 + if (err) 561 + return err; 562 + 563 + err = regmap_write(haptics->regmap, 564 + AW86927_TMCFG_REG, AW86927_TMCFG_LOCK); 565 + if (err) 566 + return err; 567 + 568 + err = regmap_update_bits(haptics->regmap, 569 + AW86927_PLAYCFG1_REG, 570 + AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 571 + FIELD_PREP(AW86927_PLAYCFG1_BST_VOUT_VREFSET_MASK, 572 + AW86927_PLAYCFG1_BST_8500MV)); 573 + if (err) 574 + return err; 575 + 576 + err = regmap_update_bits(haptics->regmap, 577 + AW86927_PLAYCFG3_REG, 578 + AW86927_PLAYCFG3_AUTO_BST_MASK, 579 + FIELD_PREP(AW86927_PLAYCFG3_AUTO_BST_MASK, 580 + AW86927_PLAYCFG3_AUTO_BST_DISABLE)); 581 + if (err) 582 + return err; 583 + 584 + return 0; 585 + } 586 + 587 + static int aw86927_ram_init(struct aw86927_data *haptics) 588 + { 589 + int err; 590 + 591 + err = aw86927_wait_enter_standby(haptics); 592 + if (err) 593 + return err; 594 + 595 + /* Enable SRAM init */ 596 + err = regmap_update_bits(haptics->regmap, 597 + AW86927_SYSCTRL3_REG, 598 + AW86927_SYSCTRL3_EN_RAMINIT_MASK, 599 + FIELD_PREP(AW86927_SYSCTRL3_EN_RAMINIT_MASK, 600 + AW86927_SYSCTRL3_EN_RAMINIT_ON)); 601 + 602 + /* Set base address for the start of the SRAM waveforms */ 603 + err = regmap_write(haptics->regmap, 604 + AW86927_BASEADDRH_REG, AW86927_BASEADDRH_VAL); 605 + if (err) 606 + return err; 607 + 608 + err = regmap_write(haptics->regmap, 609 + AW86927_BASEADDRL_REG, AW86927_BASEADDRL_VAL); 610 + if (err) 611 + return err; 612 + 613 + /* Set start of SRAM, before the data is written it will be the same as the base */ 614 + err = regmap_write(haptics->regmap, 615 + AW86927_RAMADDRH_REG, AW86927_BASEADDRH_VAL); 616 + if (err) 617 + return err; 618 + 619 + err = regmap_write(haptics->regmap, 620 + AW86927_RAMADDRL_REG, AW86927_BASEADDRL_VAL); 621 + if (err) 622 + return err; 623 + 624 + /* Write waveform header to SRAM */ 625 + err = regmap_noinc_write(haptics->regmap, AW86927_RAMDATA_REG, 626 + &sram_waveform_header, sizeof(sram_waveform_header)); 627 + if (err) 628 + return err; 629 + 630 + /* Write waveform to SRAM */ 631 + err = regmap_noinc_write(haptics->regmap, AW86927_RAMDATA_REG, 632 + aw86927_waveform, ARRAY_SIZE(aw86927_waveform)); 633 + if (err) 634 + return err; 635 + 636 + err = regmap_update_bits(haptics->regmap, 637 + AW86927_DETCFG2_REG, 638 + AW86927_DETCFG2_DET_SEQ0_MASK, 639 + FIELD_PREP(AW86927_DETCFG2_DET_SEQ0_MASK, 640 + AW86927_DETCFG2_DET_SEQ0_VBAT)); 641 + if (err) 642 + return err; 643 + 644 + err = regmap_update_bits(haptics->regmap, 645 + AW86927_DETCFG1_REG, 646 + AW86927_DETCFG1_DET_GO_MASK, 647 + FIELD_PREP(AW86927_DETCFG1_DET_GO_MASK, 648 + AW86927_DETCFG1_DET_GO_DET_SEQ0)); 649 + if (err) 650 + return err; 651 + 652 + usleep_range(3000, 3500); 653 + 654 + err = regmap_update_bits(haptics->regmap, 655 + AW86927_DETCFG1_REG, 656 + AW86927_DETCFG1_DET_GO_MASK, 657 + FIELD_PREP(AW86927_DETCFG1_DET_GO_MASK, 658 + AW86927_DETCFG1_DET_GO_NA)); 659 + if (err) 660 + return err; 661 + 662 + /* Disable SRAM init */ 663 + err = regmap_update_bits(haptics->regmap, 664 + AW86927_SYSCTRL3_REG, 665 + AW86927_SYSCTRL3_EN_RAMINIT_MASK, 666 + FIELD_PREP(AW86927_SYSCTRL3_EN_RAMINIT_MASK, 667 + AW86927_SYSCTRL3_EN_RAMINIT_OFF)); 668 + if (err) 669 + return err; 670 + 671 + return 0; 672 + } 673 + 674 + static irqreturn_t aw86927_irq(int irq, void *data) 675 + { 676 + struct aw86927_data *haptics = data; 677 + struct device *dev = &haptics->client->dev; 678 + unsigned int reg_val; 679 + int err; 680 + 681 + err = regmap_read(haptics->regmap, AW86927_SYSINT_REG, &reg_val); 682 + if (err) { 683 + dev_err(dev, "Failed to read SYSINT register: %d\n", err); 684 + return IRQ_NONE; 685 + } 686 + 687 + if (reg_val & AW86927_SYSINT_BST_SCPI) 688 + dev_err(dev, "Received a Short Circuit Protection interrupt\n"); 689 + if (reg_val & AW86927_SYSINT_BST_OVPI) 690 + dev_err(dev, "Received an Over Voltage Protection interrupt\n"); 691 + if (reg_val & AW86927_SYSINT_UVLI) 692 + dev_err(dev, "Received an Under Voltage Lock Out interrupt\n"); 693 + if (reg_val & AW86927_SYSINT_OCDI) 694 + dev_err(dev, "Received an Over Current interrupt\n"); 695 + if (reg_val & AW86927_SYSINT_OTI) 696 + dev_err(dev, "Received an Over Temperature interrupt\n"); 697 + 698 + if (reg_val & AW86927_SYSINT_DONEI) 699 + dev_dbg(dev, "Chip playback done!\n"); 700 + if (reg_val & AW86927_SYSINT_FF_AFI) 701 + dev_dbg(dev, "The RTP mode FIFO is almost full!\n"); 702 + if (reg_val & AW86927_SYSINT_FF_AEI) 703 + dev_dbg(dev, "The RTP mode FIFO is almost empty!\n"); 704 + 705 + return IRQ_HANDLED; 706 + } 707 + 708 + static int aw86927_detect(struct aw86927_data *haptics) 709 + { 710 + __be16 read_buf; 711 + u16 chip_id; 712 + int err; 713 + 714 + err = regmap_bulk_read(haptics->regmap, AW86927_CHIPIDH_REG, &read_buf, 2); 715 + if (err) 716 + return dev_err_probe(haptics->dev, err, "Failed to read CHIPID registers\n"); 717 + 718 + chip_id = be16_to_cpu(read_buf); 719 + 720 + if (chip_id != AW86927_CHIPID) { 721 + dev_err(haptics->dev, "Unexpected CHIPID value 0x%x\n", chip_id); 722 + return -ENODEV; 723 + } 724 + 725 + return 0; 726 + } 727 + 728 + static int aw86927_probe(struct i2c_client *client) 729 + { 730 + struct aw86927_data *haptics; 731 + int err; 732 + 733 + haptics = devm_kzalloc(&client->dev, sizeof(struct aw86927_data), GFP_KERNEL); 734 + if (!haptics) 735 + return -ENOMEM; 736 + 737 + haptics->dev = &client->dev; 738 + haptics->client = client; 739 + 740 + i2c_set_clientdata(client, haptics); 741 + 742 + haptics->regmap = devm_regmap_init_i2c(client, &aw86927_regmap_config); 743 + if (IS_ERR(haptics->regmap)) 744 + return dev_err_probe(haptics->dev, PTR_ERR(haptics->regmap), 745 + "Failed to allocate register map\n"); 746 + 747 + haptics->input_dev = devm_input_allocate_device(haptics->dev); 748 + if (!haptics->input_dev) 749 + return -ENOMEM; 750 + 751 + haptics->reset_gpio = devm_gpiod_get(haptics->dev, "reset", GPIOD_OUT_HIGH); 752 + if (IS_ERR(haptics->reset_gpio)) 753 + return dev_err_probe(haptics->dev, PTR_ERR(haptics->reset_gpio), 754 + "Failed to get reset gpio\n"); 755 + 756 + /* Hardware reset */ 757 + aw86927_hw_reset(haptics); 758 + 759 + /* Software reset */ 760 + err = regmap_write(haptics->regmap, AW86927_RSTCFG_REG, AW86927_RSTCFG_SOFTRST); 761 + if (err) 762 + return dev_err_probe(haptics->dev, err, "Failed Software reset\n"); 763 + 764 + /* Wait ~3ms until I2C is accessible */ 765 + usleep_range(3000, 3500); 766 + 767 + err = aw86927_detect(haptics); 768 + if (err) 769 + return dev_err_probe(haptics->dev, err, "Failed to find chip\n"); 770 + 771 + /* IRQ config */ 772 + err = regmap_write(haptics->regmap, AW86927_SYSCTRL4_REG, 773 + FIELD_PREP(AW86927_SYSCTRL4_INT_MODE_MASK, 774 + AW86927_SYSCTRL4_INT_MODE_EDGE) | 775 + FIELD_PREP(AW86927_SYSCTRL4_INT_EDGE_MODE_MASK, 776 + AW86927_SYSCTRL4_INT_EDGE_MODE_POS)); 777 + if (err) 778 + return dev_err_probe(haptics->dev, err, "Failed to configure interrupt modes\n"); 779 + 780 + err = regmap_write(haptics->regmap, AW86927_SYSINTM_REG, 781 + AW86927_SYSINTM_BST_OVPM | 782 + AW86927_SYSINTM_FF_AEM | 783 + AW86927_SYSINTM_FF_AFM | 784 + AW86927_SYSINTM_DONEM); 785 + if (err) 786 + return dev_err_probe(haptics->dev, err, "Failed to configure interrupt masks\n"); 787 + 788 + err = devm_request_threaded_irq(haptics->dev, client->irq, NULL, 789 + aw86927_irq, IRQF_ONESHOT, NULL, haptics); 790 + if (err) 791 + return dev_err_probe(haptics->dev, err, "Failed to request threaded irq\n"); 792 + 793 + INIT_WORK(&haptics->play_work, aw86927_haptics_play_work); 794 + 795 + haptics->input_dev->name = "aw86927-haptics"; 796 + haptics->input_dev->close = aw86927_close; 797 + 798 + input_set_drvdata(haptics->input_dev, haptics); 799 + input_set_capability(haptics->input_dev, EV_FF, FF_RUMBLE); 800 + 801 + err = input_ff_create_memless(haptics->input_dev, NULL, aw86927_haptics_play); 802 + if (err) 803 + return dev_err_probe(haptics->dev, err, "Failed to create FF dev\n"); 804 + 805 + /* Set up registers */ 806 + err = aw86927_play_mode(haptics, AW86927_STANDBY_MODE); 807 + if (err) 808 + return dev_err_probe(haptics->dev, err, 809 + "Failed to enter standby for Haptic init\n"); 810 + 811 + err = aw86927_haptic_init(haptics); 812 + if (err) 813 + return dev_err_probe(haptics->dev, err, "Haptic init failed\n"); 814 + 815 + /* RAM init, upload the waveform for playback */ 816 + err = aw86927_ram_init(haptics); 817 + if (err) 818 + return dev_err_probe(haptics->dev, err, "Failed to init aw86927 sram\n"); 819 + 820 + err = input_register_device(haptics->input_dev); 821 + if (err) 822 + return dev_err_probe(haptics->dev, err, "Failed to register input device\n"); 823 + 824 + return 0; 825 + } 826 + 827 + static const struct of_device_id aw86927_of_id[] = { 828 + { .compatible = "awinic,aw86927" }, 829 + { /* sentinel */ } 830 + }; 831 + 832 + MODULE_DEVICE_TABLE(of, aw86927_of_id); 833 + 834 + static struct i2c_driver aw86927_driver = { 835 + .driver = { 836 + .name = "aw86927-haptics", 837 + .of_match_table = aw86927_of_id, 838 + }, 839 + .probe = aw86927_probe, 840 + }; 841 + 842 + module_i2c_driver(aw86927_driver); 843 + 844 + MODULE_AUTHOR("Griffin Kroah-Hartman <griffin.kroah@fairphone.com>"); 845 + MODULE_DESCRIPTION("AWINIC AW86927 LRA Haptic Driver"); 846 + MODULE_LICENSE("GPL");
+1
drivers/input/misc/cma3000_d0x.c
··· 6 6 * Author: Hemanth V <hemanthv@ti.com> 7 7 */ 8 8 9 + #include <linux/export.h> 9 10 #include <linux/types.h> 10 11 #include <linux/interrupt.h> 11 12 #include <linux/delay.h>
+10 -2
drivers/input/misc/pm8941-pwrkey.c
··· 60 60 bool supports_ps_hold_poff_config; 61 61 bool supports_debounce_config; 62 62 bool has_pon_pbs; 63 + bool wakeup_source_default; 63 64 const char *name; 64 65 const char *phys; 65 66 }; ··· 246 245 static int pm8941_pwrkey_probe(struct platform_device *pdev) 247 246 { 248 247 struct pm8941_pwrkey *pwrkey; 249 - bool pull_up; 248 + bool pull_up, wakeup; 250 249 struct device *parent; 251 250 struct device_node *regmap_node; 252 251 const __be32 *addr; ··· 403 402 } 404 403 } 405 404 405 + wakeup = pwrkey->data->wakeup_source_default || 406 + of_property_read_bool(pdev->dev.of_node, "wakeup-source"); 407 + 406 408 platform_set_drvdata(pdev, pwrkey); 407 - device_init_wakeup(&pdev->dev, 1); 409 + device_init_wakeup(&pdev->dev, wakeup); 408 410 409 411 return 0; 410 412 } ··· 428 424 .supports_ps_hold_poff_config = true, 429 425 .supports_debounce_config = true, 430 426 .has_pon_pbs = false, 427 + .wakeup_source_default = true, 431 428 }; 432 429 433 430 static const struct pm8941_data resin_data = { ··· 439 434 .supports_ps_hold_poff_config = true, 440 435 .supports_debounce_config = true, 441 436 .has_pon_pbs = false, 437 + .wakeup_source_default = false, 442 438 }; 443 439 444 440 static const struct pm8941_data pon_gen3_pwrkey_data = { ··· 449 443 .supports_ps_hold_poff_config = false, 450 444 .supports_debounce_config = false, 451 445 .has_pon_pbs = true, 446 + .wakeup_source_default = true, 452 447 }; 453 448 454 449 static const struct pm8941_data pon_gen3_resin_data = { ··· 459 452 .supports_ps_hold_poff_config = false, 460 453 .supports_debounce_config = false, 461 454 .has_pon_pbs = true, 455 + .wakeup_source_default = false, 462 456 }; 463 457 464 458 static const struct of_device_id pm8941_pwr_key_id_table[] = {
+1
drivers/input/misc/uinput.c
··· 775 775 if (in_compat_syscall()) { 776 776 struct uinput_ff_upload_compat ff_up_compat; 777 777 778 + memset(&ff_up_compat, 0, sizeof(ff_up_compat)); 778 779 ff_up_compat.request_id = ff_up->request_id; 779 780 ff_up_compat.retval = ff_up->retval; 780 781 /*
+1
drivers/input/rmi4/rmi_2d_sensor.c
··· 4 4 * Copyright (c) 2011 Unixphere 5 5 */ 6 6 7 + #include <linux/export.h> 7 8 #include <linux/kernel.h> 8 9 #include <linux/device.h> 9 10 #include <linux/of.h>
+3
drivers/input/rmi4/rmi_2d_sensor.h
··· 7 7 #ifndef _RMI_2D_SENSOR_H 8 8 #define _RMI_2D_SENSOR_H 9 9 10 + #include <linux/rmi.h> 11 + #include <linux/types.h> 12 + 10 13 enum rmi_2d_sensor_object_type { 11 14 RMI_2D_OBJECT_NONE, 12 15 RMI_2D_OBJECT_FINGER,
+1
drivers/input/rmi4/rmi_bus.c
··· 4 4 * Copyright (c) 2011 Unixphere 5 5 */ 6 6 7 + #include <linux/export.h> 7 8 #include <linux/kernel.h> 8 9 #include <linux/device.h> 9 10 #include <linux/irq.h>
+1
drivers/input/rmi4/rmi_driver.c
··· 21 21 #include <linux/irqdomain.h> 22 22 #include <uapi/linux/input.h> 23 23 #include <linux/rmi.h> 24 + #include <linux/export.h> 24 25 #include "rmi_bus.h" 25 26 #include "rmi_driver.h" 26 27
+1
drivers/input/serio/hil_mlc.c
··· 54 54 55 55 #include <linux/hil_mlc.h> 56 56 #include <linux/errno.h> 57 + #include <linux/export.h> 57 58 #include <linux/kernel.h> 58 59 #include <linux/module.h> 59 60 #include <linux/init.h>
+1
drivers/input/serio/hp_sdc.c
··· 63 63 64 64 #include <linux/hp_sdc.h> 65 65 #include <linux/errno.h> 66 + #include <linux/export.h> 66 67 #include <linux/init.h> 67 68 #include <linux/module.h> 68 69 #include <linux/ioport.h>
+1
drivers/input/serio/i8042.c
··· 10 10 11 11 #include <linux/types.h> 12 12 #include <linux/delay.h> 13 + #include <linux/export.h> 13 14 #include <linux/module.h> 14 15 #include <linux/interrupt.h> 15 16 #include <linux/ioport.h>
+1
drivers/input/serio/libps2.c
··· 8 8 9 9 10 10 #include <linux/delay.h> 11 + #include <linux/export.h> 11 12 #include <linux/module.h> 12 13 #include <linux/sched.h> 13 14 #include <linux/interrupt.h>
+1 -1
drivers/input/serio/ps2-gpio.c
··· 50 50 * interrupt interval should be ~60us. Let's allow +/- 20us for frequency 51 51 * deviations and interrupt latency. 52 52 * 53 - * The data line must be samples after ~30us to 50us after the falling edge, 53 + * The data line must be sampled after ~30us to 50us after the falling edge, 54 54 * since the device updates the data line at the rising edge. 55 55 * 56 56 * ___ ______ ______ ______ ___
+1
drivers/input/serio/serio.c
··· 9 9 10 10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 11 12 + #include <linux/export.h> 12 13 #include <linux/stddef.h> 13 14 #include <linux/module.h> 14 15 #include <linux/serio.h>
+1
drivers/input/sparse-keymap.c
··· 10 10 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> 11 11 */ 12 12 13 + #include <linux/export.h> 13 14 #include <linux/input.h> 14 15 #include <linux/input/sparse-keymap.h> 15 16 #include <linux/module.h>
+1
drivers/input/touch-overlay.c
··· 5 5 * Copyright (c) 2023 Javier Carrasco <javier.carrasco@wolfvision.net> 6 6 */ 7 7 8 + #include <linux/export.h> 8 9 #include <linux/input.h> 9 10 #include <linux/input/mt.h> 10 11 #include <linux/input/touch-overlay.h>
+1
drivers/input/touchscreen.c
··· 6 6 * Copyright (c) 2014 Sebastian Reichel <sre@kernel.org> 7 7 */ 8 8 9 + #include <linux/export.h> 9 10 #include <linux/property.h> 10 11 #include <linux/input.h> 11 12 #include <linux/input/mt.h>
+22
drivers/input/touchscreen/Kconfig
··· 441 441 To compile this driver as a module, choose M here : the 442 442 module will be called hideep_ts. 443 443 444 + config TOUCHSCREEN_HIMAX_HX852X 445 + tristate "Himax HX852x(ES) touchscreen" 446 + depends on I2C 447 + help 448 + Say Y here if you have a Himax HX852x(ES) touchscreen. 449 + If unsure, say N. 450 + 451 + To compile this driver as a module, choose M here: the module 452 + will be called himax_hx852x. 453 + 444 454 config TOUCHSCREEN_HYCON_HY46XX 445 455 tristate "Hycon hy46xx touchscreen support" 446 456 depends on I2C ··· 474 464 475 465 To compile this driver as a module, choose M here: the 476 466 module will be called hynitron-cstxxx. 467 + 468 + config TOUCHSCREEN_HYNITRON_CST816X 469 + tristate "Hynitron CST816x touchscreen" 470 + depends on I2C 471 + help 472 + Say Y here if you have a touchscreen using a Hynitron 473 + CST816x series touchscreen controller. 474 + 475 + If unsure, say N. 476 + 477 + To compile this driver as a module, choose M here: the 478 + module will be called hynitron-cst816x. 477 479 478 480 config TOUCHSCREEN_ILI210X 479 481 tristate "Ilitek ILI210X based touchscreen"
+2
drivers/input/touchscreen/Makefile
··· 49 49 obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_I2C) += goodix_berlin_i2c.o 50 50 obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_SPI) += goodix_berlin_spi.o 51 51 obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o 52 + obj-$(CONFIG_TOUCHSCREEN_HIMAX_HX852X) += himax_hx852x.o 52 53 obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o 54 + obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CST816X) += hynitron-cst816x.o 53 55 obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o 54 56 obj-$(CONFIG_TOUCHSCREEN_ILITEK) += ilitek_ts_i2c.o 55 57 obj-$(CONFIG_TOUCHSCREEN_IMAGIS) += imagis.o
+1
drivers/input/touchscreen/ad7879.c
··· 22 22 23 23 #include <linux/device.h> 24 24 #include <linux/delay.h> 25 + #include <linux/export.h> 25 26 #include <linux/input.h> 26 27 #include <linux/interrupt.h> 27 28 #include <linux/irq.h>
+8 -5
drivers/input/touchscreen/atmel_mxt_ts.c
··· 19 19 #include <linux/firmware.h> 20 20 #include <linux/i2c.h> 21 21 #include <linux/input/mt.h> 22 + #include <linux/input/touchscreen.h> 22 23 #include <linux/interrupt.h> 23 24 #include <linux/irq.h> 24 25 #include <linux/of.h> ··· 356 355 enum mxt_suspend_mode suspend_mode; 357 356 358 357 u32 wakeup_method; 358 + 359 + struct touchscreen_properties prop; 359 360 }; 360 361 361 362 struct mxt_vb2_buffer { ··· 891 888 892 889 /* Touch active */ 893 890 input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 1); 894 - input_report_abs(input_dev, ABS_MT_POSITION_X, x); 895 - input_report_abs(input_dev, ABS_MT_POSITION_Y, y); 891 + touchscreen_report_pos(input_dev, &data->prop, x, y, true); 896 892 input_report_abs(input_dev, ABS_MT_PRESSURE, amplitude); 897 893 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, area); 898 894 } else { ··· 1012 1010 id, type, x, y, major, pressure, orientation); 1013 1011 1014 1012 input_mt_report_slot_state(input_dev, tool, 1); 1015 - input_report_abs(input_dev, ABS_MT_POSITION_X, x); 1016 - input_report_abs(input_dev, ABS_MT_POSITION_Y, y); 1013 + touchscreen_report_pos(input_dev, &data->prop, x, y, true); 1017 1014 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, major); 1018 1015 input_report_abs(input_dev, ABS_MT_PRESSURE, pressure); 1019 1016 input_report_abs(input_dev, ABS_MT_DISTANCE, distance); ··· 2213 2212 0, 255, 0, 0); 2214 2213 } 2215 2214 2215 + touchscreen_parse_properties(input_dev, true, &data->prop); 2216 + 2216 2217 /* For T15 and T97 Key Array */ 2217 2218 if (data->T15_reportid_min || data->T97_reportid_min) { 2218 2219 for (i = 0; i < data->t15_num_keys; i++) ··· 3320 3317 if (data->reset_gpio) { 3321 3318 /* Wait a while and then de-assert the RESET GPIO line */ 3322 3319 msleep(MXT_RESET_GPIO_TIME); 3323 - gpiod_set_value(data->reset_gpio, 0); 3320 + gpiod_set_value_cansleep(data->reset_gpio, 0); 3324 3321 msleep(MXT_RESET_INVALID_CHG); 3325 3322 } 3326 3323
+1
drivers/input/touchscreen/cyttsp_core.c
··· 14 14 */ 15 15 16 16 #include <linux/delay.h> 17 + #include <linux/export.h> 17 18 #include <linux/input.h> 18 19 #include <linux/input/mt.h> 19 20 #include <linux/input/touchscreen.h>
-1
drivers/input/touchscreen/fsl-imx25-tcq.c
··· 39 39 }; 40 40 41 41 static const struct regmap_config mx25_tcq_regconfig = { 42 - .fast_io = true, 43 42 .max_register = 0x5c, 44 43 .reg_bits = 32, 45 44 .val_bits = 32,
+1
drivers/input/touchscreen/goodix_berlin_core.c
··· 24 24 */ 25 25 26 26 #include <linux/bitfield.h> 27 + #include <linux/export.h> 27 28 #include <linux/gpio/consumer.h> 28 29 #include <linux/input.h> 29 30 #include <linux/input/mt.h>
+503
drivers/input/touchscreen/himax_hx852x.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Himax HX852x(ES) Touchscreen Driver 4 + * Copyright (c) 2020-2024 Stephan Gerhold <stephan@gerhold.net> 5 + * Copyright (c) 2020 Jonathan Albrieux <jonathan.albrieux@gmail.com> 6 + * 7 + * Based on the Himax Android Driver Sample Code Ver 0.3 for HMX852xES chipset: 8 + * Copyright (c) 2014 Himax Corporation. 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/gpio/consumer.h> 13 + #include <linux/i2c.h> 14 + #include <linux/input.h> 15 + #include <linux/input/mt.h> 16 + #include <linux/input/touchscreen.h> 17 + #include <linux/interrupt.h> 18 + #include <linux/kernel.h> 19 + #include <linux/mod_devicetable.h> 20 + #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/regulator/consumer.h> 23 + #include <linux/unaligned.h> 24 + 25 + #define HX852X_COORD_SIZE(fingers) ((fingers) * sizeof(struct hx852x_coord)) 26 + #define HX852X_WIDTH_SIZE(fingers) ALIGN(fingers, 4) 27 + #define HX852X_BUF_SIZE(fingers) (HX852X_COORD_SIZE(fingers) + \ 28 + HX852X_WIDTH_SIZE(fingers) + \ 29 + sizeof(struct hx852x_touch_info)) 30 + 31 + #define HX852X_MAX_FINGERS 12 32 + #define HX852X_MAX_KEY_COUNT 4 33 + #define HX852X_MAX_BUF_SIZE HX852X_BUF_SIZE(HX852X_MAX_FINGERS) 34 + 35 + #define HX852X_TS_SLEEP_IN 0x80 36 + #define HX852X_TS_SLEEP_OUT 0x81 37 + #define HX852X_TS_SENSE_OFF 0x82 38 + #define HX852X_TS_SENSE_ON 0x83 39 + #define HX852X_READ_ONE_EVENT 0x85 40 + #define HX852X_READ_ALL_EVENTS 0x86 41 + #define HX852X_READ_LATEST_EVENT 0x87 42 + #define HX852X_CLEAR_EVENT_STACK 0x88 43 + 44 + #define HX852X_REG_SRAM_SWITCH 0x8c 45 + #define HX852X_REG_SRAM_ADDR 0x8b 46 + #define HX852X_REG_FLASH_RPLACE 0x5a 47 + 48 + #define HX852X_SRAM_SWITCH_TEST_MODE 0x14 49 + #define HX852X_SRAM_ADDR_CONFIG 0x7000 50 + 51 + struct hx852x { 52 + struct i2c_client *client; 53 + struct input_dev *input_dev; 54 + struct touchscreen_properties props; 55 + struct gpio_desc *reset_gpiod; 56 + struct regulator_bulk_data supplies[2]; 57 + unsigned int max_fingers; 58 + unsigned int keycount; 59 + unsigned int keycodes[HX852X_MAX_KEY_COUNT]; 60 + }; 61 + 62 + struct hx852x_config { 63 + u8 rx_num; 64 + u8 tx_num; 65 + u8 max_pt; 66 + u8 padding1[3]; 67 + __be16 x_res; 68 + __be16 y_res; 69 + u8 padding2[2]; 70 + } __packed __aligned(4); 71 + 72 + struct hx852x_coord { 73 + __be16 x; 74 + __be16 y; 75 + } __packed __aligned(4); 76 + 77 + struct hx852x_touch_info { 78 + u8 finger_num; 79 + __le16 finger_pressed; 80 + u8 padding; 81 + } __packed __aligned(4); 82 + 83 + static int hx852x_i2c_read(struct hx852x *hx, u8 cmd, void *data, u16 len) 84 + { 85 + struct i2c_client *client = hx->client; 86 + int error; 87 + int ret; 88 + 89 + struct i2c_msg msg[] = { 90 + { 91 + .addr = client->addr, 92 + .flags = 0, 93 + .len = 1, 94 + .buf = &cmd, 95 + }, 96 + { 97 + .addr = client->addr, 98 + .flags = I2C_M_RD, 99 + .len = len, 100 + .buf = data, 101 + }, 102 + }; 103 + 104 + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); 105 + if (ret != ARRAY_SIZE(msg)) { 106 + error = ret < 0 ? ret : -EIO; 107 + dev_err(&client->dev, "failed to read %#x: %d\n", cmd, error); 108 + return error; 109 + } 110 + 111 + return 0; 112 + } 113 + 114 + static int hx852x_power_on(struct hx852x *hx) 115 + { 116 + struct device *dev = &hx->client->dev; 117 + int error; 118 + 119 + error = regulator_bulk_enable(ARRAY_SIZE(hx->supplies), hx->supplies); 120 + if (error) { 121 + dev_err(dev, "failed to enable regulators: %d\n", error); 122 + return error; 123 + } 124 + 125 + gpiod_set_value_cansleep(hx->reset_gpiod, 1); 126 + msleep(20); 127 + gpiod_set_value_cansleep(hx->reset_gpiod, 0); 128 + msleep(50); 129 + 130 + return 0; 131 + } 132 + 133 + static int hx852x_start(struct hx852x *hx) 134 + { 135 + struct device *dev = &hx->client->dev; 136 + int error; 137 + 138 + error = i2c_smbus_write_byte(hx->client, HX852X_TS_SLEEP_OUT); 139 + if (error) { 140 + dev_err(dev, "failed to send TS_SLEEP_OUT: %d\n", error); 141 + return error; 142 + } 143 + msleep(30); 144 + 145 + error = i2c_smbus_write_byte(hx->client, HX852X_TS_SENSE_ON); 146 + if (error) { 147 + dev_err(dev, "failed to send TS_SENSE_ON: %d\n", error); 148 + return error; 149 + } 150 + msleep(20); 151 + 152 + return 0; 153 + } 154 + 155 + static int hx852x_stop(struct hx852x *hx) 156 + { 157 + struct device *dev = &hx->client->dev; 158 + int error; 159 + 160 + error = i2c_smbus_write_byte(hx->client, HX852X_TS_SENSE_OFF); 161 + if (error) { 162 + dev_err(dev, "failed to send TS_SENSE_OFF: %d\n", error); 163 + return error; 164 + } 165 + msleep(20); 166 + 167 + error = i2c_smbus_write_byte(hx->client, HX852X_TS_SLEEP_IN); 168 + if (error) { 169 + dev_err(dev, "failed to send TS_SLEEP_IN: %d\n", error); 170 + return error; 171 + } 172 + msleep(30); 173 + 174 + return 0; 175 + } 176 + 177 + static int hx852x_power_off(struct hx852x *hx) 178 + { 179 + struct device *dev = &hx->client->dev; 180 + int error; 181 + 182 + error = regulator_bulk_disable(ARRAY_SIZE(hx->supplies), hx->supplies); 183 + if (error) { 184 + dev_err(dev, "failed to disable regulators: %d\n", error); 185 + return error; 186 + } 187 + 188 + return 0; 189 + } 190 + 191 + static int hx852x_read_config(struct hx852x *hx) 192 + { 193 + struct device *dev = &hx->client->dev; 194 + struct hx852x_config conf; 195 + int x_res, y_res; 196 + int error, error2; 197 + 198 + error = hx852x_power_on(hx); 199 + if (error) 200 + return error; 201 + 202 + /* Sensing must be turned on briefly to load the config */ 203 + error = hx852x_start(hx); 204 + if (error) 205 + goto err_power_off; 206 + 207 + error = hx852x_stop(hx); 208 + if (error) 209 + goto err_power_off; 210 + 211 + error = i2c_smbus_write_byte_data(hx->client, HX852X_REG_SRAM_SWITCH, 212 + HX852X_SRAM_SWITCH_TEST_MODE); 213 + if (error) 214 + goto err_power_off; 215 + 216 + error = i2c_smbus_write_word_data(hx->client, HX852X_REG_SRAM_ADDR, 217 + HX852X_SRAM_ADDR_CONFIG); 218 + if (error) 219 + goto err_test_mode; 220 + 221 + error = hx852x_i2c_read(hx, HX852X_REG_FLASH_RPLACE, &conf, sizeof(conf)); 222 + if (error) 223 + goto err_test_mode; 224 + 225 + x_res = be16_to_cpu(conf.x_res); 226 + y_res = be16_to_cpu(conf.y_res); 227 + hx->max_fingers = (conf.max_pt & 0xf0) >> 4; 228 + dev_dbg(dev, "x res: %u, y res: %u, max fingers: %u\n", 229 + x_res, y_res, hx->max_fingers); 230 + 231 + if (hx->max_fingers > HX852X_MAX_FINGERS) { 232 + dev_err(dev, "max supported fingers: %u, found: %u\n", 233 + HX852X_MAX_FINGERS, hx->max_fingers); 234 + error = -EINVAL; 235 + goto err_test_mode; 236 + } 237 + 238 + if (x_res && y_res) { 239 + input_set_abs_params(hx->input_dev, ABS_MT_POSITION_X, 0, x_res - 1, 0, 0); 240 + input_set_abs_params(hx->input_dev, ABS_MT_POSITION_Y, 0, y_res - 1, 0, 0); 241 + } 242 + 243 + err_test_mode: 244 + error2 = i2c_smbus_write_byte_data(hx->client, HX852X_REG_SRAM_SWITCH, 0); 245 + error = error ?: error2; 246 + err_power_off: 247 + error2 = hx852x_power_off(hx); 248 + return error ?: error2; 249 + } 250 + 251 + static int hx852x_handle_events(struct hx852x *hx) 252 + { 253 + /* 254 + * The event packets have variable size, depending on the amount of 255 + * supported fingers (hx->max_fingers). They are laid out as follows: 256 + * - struct hx852x_coord[hx->max_fingers]: Coordinates for each finger 257 + * - u8[ALIGN(hx->max_fingers, 4)]: Touch width for each finger 258 + * with padding for 32-bit alignment 259 + * - struct hx852x_touch_info 260 + * 261 + * Load everything into a 32-bit aligned buffer so the coordinates 262 + * can be assigned directly, without using get_unaligned_*(). 263 + */ 264 + u8 buf[HX852X_MAX_BUF_SIZE] __aligned(4); 265 + struct hx852x_coord *coord = (struct hx852x_coord *)buf; 266 + u8 *width = &buf[HX852X_COORD_SIZE(hx->max_fingers)]; 267 + struct hx852x_touch_info *info = (struct hx852x_touch_info *) 268 + &width[HX852X_WIDTH_SIZE(hx->max_fingers)]; 269 + unsigned long finger_pressed, key_pressed; 270 + unsigned int i, x, y, w; 271 + int error; 272 + 273 + error = hx852x_i2c_read(hx, HX852X_READ_ALL_EVENTS, buf, 274 + HX852X_BUF_SIZE(hx->max_fingers)); 275 + if (error) 276 + return error; 277 + 278 + finger_pressed = get_unaligned_le16(&info->finger_pressed); 279 + key_pressed = finger_pressed >> HX852X_MAX_FINGERS; 280 + 281 + /* All bits are set when no touch is detected */ 282 + if (info->finger_num == 0xff || !(info->finger_num & 0x0f)) 283 + finger_pressed = 0; 284 + if (key_pressed == 0xf) 285 + key_pressed = 0; 286 + 287 + for_each_set_bit(i, &finger_pressed, hx->max_fingers) { 288 + x = be16_to_cpu(coord[i].x); 289 + y = be16_to_cpu(coord[i].y); 290 + w = width[i]; 291 + 292 + input_mt_slot(hx->input_dev, i); 293 + input_mt_report_slot_state(hx->input_dev, MT_TOOL_FINGER, 1); 294 + touchscreen_report_pos(hx->input_dev, &hx->props, x, y, true); 295 + input_report_abs(hx->input_dev, ABS_MT_TOUCH_MAJOR, w); 296 + } 297 + input_mt_sync_frame(hx->input_dev); 298 + 299 + for (i = 0; i < hx->keycount; i++) 300 + input_report_key(hx->input_dev, hx->keycodes[i], key_pressed & BIT(i)); 301 + 302 + input_sync(hx->input_dev); 303 + return 0; 304 + } 305 + 306 + static irqreturn_t hx852x_interrupt(int irq, void *ptr) 307 + { 308 + struct hx852x *hx = ptr; 309 + int error; 310 + 311 + error = hx852x_handle_events(hx); 312 + if (error) { 313 + dev_err_ratelimited(&hx->client->dev, 314 + "failed to handle events: %d\n", error); 315 + return IRQ_NONE; 316 + } 317 + 318 + return IRQ_HANDLED; 319 + } 320 + 321 + static int hx852x_input_open(struct input_dev *dev) 322 + { 323 + struct hx852x *hx = input_get_drvdata(dev); 324 + int error; 325 + 326 + error = hx852x_power_on(hx); 327 + if (error) 328 + return error; 329 + 330 + error = hx852x_start(hx); 331 + if (error) { 332 + hx852x_power_off(hx); 333 + return error; 334 + } 335 + 336 + enable_irq(hx->client->irq); 337 + return 0; 338 + } 339 + 340 + static void hx852x_input_close(struct input_dev *dev) 341 + { 342 + struct hx852x *hx = input_get_drvdata(dev); 343 + 344 + hx852x_stop(hx); 345 + disable_irq(hx->client->irq); 346 + hx852x_power_off(hx); 347 + } 348 + 349 + static int hx852x_parse_properties(struct hx852x *hx) 350 + { 351 + struct device *dev = &hx->client->dev; 352 + int error, count; 353 + 354 + count = device_property_count_u32(dev, "linux,keycodes"); 355 + if (count == -EINVAL) { 356 + /* Property does not exist, keycodes are optional */ 357 + return 0; 358 + } else if (count < 0) { 359 + dev_err(dev, "Failed to read linux,keycodes: %d\n", count); 360 + return count; 361 + } else if (count > HX852X_MAX_KEY_COUNT) { 362 + dev_err(dev, "max supported keys: %u, found: %u\n", 363 + HX852X_MAX_KEY_COUNT, hx->keycount); 364 + return -EINVAL; 365 + } 366 + hx->keycount = count; 367 + 368 + error = device_property_read_u32_array(dev, "linux,keycodes", 369 + hx->keycodes, hx->keycount); 370 + if (error) { 371 + dev_err(dev, "failed to read linux,keycodes: %d\n", error); 372 + return error; 373 + } 374 + 375 + return 0; 376 + } 377 + 378 + static int hx852x_probe(struct i2c_client *client) 379 + { 380 + struct device *dev = &client->dev; 381 + struct hx852x *hx; 382 + int error, i; 383 + 384 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 385 + I2C_FUNC_SMBUS_WRITE_BYTE | 386 + I2C_FUNC_SMBUS_WRITE_BYTE_DATA | 387 + I2C_FUNC_SMBUS_WRITE_WORD_DATA)) { 388 + dev_err(dev, "not all required i2c functionality supported\n"); 389 + return -ENXIO; 390 + } 391 + 392 + hx = devm_kzalloc(dev, sizeof(*hx), GFP_KERNEL); 393 + if (!hx) 394 + return -ENOMEM; 395 + 396 + hx->client = client; 397 + hx->input_dev = devm_input_allocate_device(dev); 398 + if (!hx->input_dev) 399 + return -ENOMEM; 400 + 401 + hx->input_dev->name = "Himax HX852x"; 402 + hx->input_dev->id.bustype = BUS_I2C; 403 + hx->input_dev->open = hx852x_input_open; 404 + hx->input_dev->close = hx852x_input_close; 405 + 406 + i2c_set_clientdata(client, hx); 407 + input_set_drvdata(hx->input_dev, hx); 408 + 409 + hx->supplies[0].supply = "vcca"; 410 + hx->supplies[1].supply = "vccd"; 411 + error = devm_regulator_bulk_get(dev, ARRAY_SIZE(hx->supplies), hx->supplies); 412 + if (error) 413 + return dev_err_probe(dev, error, "failed to get regulators\n"); 414 + 415 + hx->reset_gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 416 + if (IS_ERR(hx->reset_gpiod)) 417 + return dev_err_probe(dev, PTR_ERR(hx->reset_gpiod), 418 + "failed to get reset gpio\n"); 419 + 420 + error = devm_request_threaded_irq(dev, client->irq, NULL, hx852x_interrupt, 421 + IRQF_ONESHOT | IRQF_NO_AUTOEN, NULL, hx); 422 + if (error) 423 + return dev_err_probe(dev, error, "failed to request irq %d", client->irq); 424 + 425 + error = hx852x_read_config(hx); 426 + if (error) 427 + return error; 428 + 429 + input_set_capability(hx->input_dev, EV_ABS, ABS_MT_POSITION_X); 430 + input_set_capability(hx->input_dev, EV_ABS, ABS_MT_POSITION_Y); 431 + input_set_abs_params(hx->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); 432 + 433 + touchscreen_parse_properties(hx->input_dev, true, &hx->props); 434 + error = hx852x_parse_properties(hx); 435 + if (error) 436 + return error; 437 + 438 + hx->input_dev->keycode = hx->keycodes; 439 + hx->input_dev->keycodemax = hx->keycount; 440 + hx->input_dev->keycodesize = sizeof(hx->keycodes[0]); 441 + for (i = 0; i < hx->keycount; i++) 442 + input_set_capability(hx->input_dev, EV_KEY, hx->keycodes[i]); 443 + 444 + error = input_mt_init_slots(hx->input_dev, hx->max_fingers, 445 + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); 446 + if (error) 447 + return dev_err_probe(dev, error, "failed to init MT slots\n"); 448 + 449 + error = input_register_device(hx->input_dev); 450 + if (error) 451 + return dev_err_probe(dev, error, "failed to register input device\n"); 452 + 453 + return 0; 454 + } 455 + 456 + static int hx852x_suspend(struct device *dev) 457 + { 458 + struct hx852x *hx = dev_get_drvdata(dev); 459 + 460 + guard(mutex)(&hx->input_dev->mutex); 461 + 462 + if (input_device_enabled(hx->input_dev)) 463 + return hx852x_stop(hx); 464 + 465 + return 0; 466 + } 467 + 468 + static int hx852x_resume(struct device *dev) 469 + { 470 + struct hx852x *hx = dev_get_drvdata(dev); 471 + 472 + guard(mutex)(&hx->input_dev->mutex); 473 + 474 + if (input_device_enabled(hx->input_dev)) 475 + return hx852x_start(hx); 476 + 477 + return 0; 478 + } 479 + 480 + static DEFINE_SIMPLE_DEV_PM_OPS(hx852x_pm_ops, hx852x_suspend, hx852x_resume); 481 + 482 + #ifdef CONFIG_OF 483 + static const struct of_device_id hx852x_of_match[] = { 484 + { .compatible = "himax,hx852es" }, 485 + { } 486 + }; 487 + MODULE_DEVICE_TABLE(of, hx852x_of_match); 488 + #endif 489 + 490 + static struct i2c_driver hx852x_driver = { 491 + .probe = hx852x_probe, 492 + .driver = { 493 + .name = "himax_hx852x", 494 + .pm = pm_sleep_ptr(&hx852x_pm_ops), 495 + .of_match_table = of_match_ptr(hx852x_of_match), 496 + }, 497 + }; 498 + module_i2c_driver(hx852x_driver); 499 + 500 + MODULE_DESCRIPTION("Himax HX852x(ES) Touchscreen Driver"); 501 + MODULE_AUTHOR("Jonathan Albrieux <jonathan.albrieux@gmail.com>"); 502 + MODULE_AUTHOR("Stephan Gerhold <stephan@gerhold.net>"); 503 + MODULE_LICENSE("GPL");
+253
drivers/input/touchscreen/hynitron-cst816x.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Driver for I2C connected Hynitron CST816x Series Touchscreen 4 + * 5 + * Copyright (C) 2025 Oleh Kuzhylnyi <kuzhylol@gmail.com> 6 + */ 7 + 8 + #include <linux/delay.h> 9 + #include <linux/device.h> 10 + #include <linux/err.h> 11 + #include <linux/gpio/consumer.h> 12 + #include <linux/i2c.h> 13 + #include <linux/input.h> 14 + #include <linux/unaligned.h> 15 + #include <linux/interrupt.h> 16 + #include <linux/module.h> 17 + 18 + #define CST816X_RD_REG 0x01 19 + #define CST816X_NUM_KEYS 5 20 + 21 + struct cst816x_touch { 22 + u8 gest; 23 + u8 active; 24 + u16 abs_x; 25 + u16 abs_y; 26 + } __packed; 27 + 28 + struct cst816x_priv { 29 + struct i2c_client *client; 30 + struct gpio_desc *reset; 31 + struct input_dev *input; 32 + unsigned int keycode[CST816X_NUM_KEYS]; 33 + unsigned int keycodemax; 34 + }; 35 + 36 + static int cst816x_parse_keycodes(struct device *dev, struct cst816x_priv *priv) 37 + { 38 + int count; 39 + int error; 40 + 41 + if (device_property_present(dev, "linux,keycodes")) { 42 + count = device_property_count_u32(dev, "linux,keycodes"); 43 + if (count < 0) { 44 + error = count; 45 + dev_err(dev, "failed to count keys: %d\n", error); 46 + return error; 47 + } else if (count > ARRAY_SIZE(priv->keycode)) { 48 + dev_err(dev, "too many keys defined: %d\n", count); 49 + return -EINVAL; 50 + } 51 + priv->keycodemax = count; 52 + 53 + error = device_property_read_u32_array(dev, "linux,keycodes", 54 + priv->keycode, 55 + priv->keycodemax); 56 + if (error) { 57 + dev_err(dev, "failed to read keycodes: %d\n", error); 58 + return error; 59 + } 60 + } 61 + 62 + return 0; 63 + } 64 + 65 + static int cst816x_i2c_read_register(struct cst816x_priv *priv, u8 reg, 66 + void *buf, size_t len) 67 + { 68 + struct i2c_msg xfer[] = { 69 + { 70 + .addr = priv->client->addr, 71 + .flags = 0, 72 + .buf = &reg, 73 + .len = sizeof(reg), 74 + }, 75 + { 76 + .addr = priv->client->addr, 77 + .flags = I2C_M_RD, 78 + .buf = buf, 79 + .len = len, 80 + }, 81 + }; 82 + int error; 83 + int ret; 84 + 85 + ret = i2c_transfer(priv->client->adapter, xfer, ARRAY_SIZE(xfer)); 86 + if (ret != ARRAY_SIZE(xfer)) { 87 + error = ret < 0 ? ret : -EIO; 88 + dev_err(&priv->client->dev, "i2c rx err: %d\n", error); 89 + return error; 90 + } 91 + 92 + return 0; 93 + } 94 + 95 + static u8 cst816x_gest_idx(u8 gest) 96 + { 97 + u8 index; 98 + 99 + switch (gest) { 100 + case 0x01: /* Slide up gesture */ 101 + case 0x02: /* Slide down gesture */ 102 + case 0x03: /* Slide left gesture */ 103 + case 0x04: /* Slide right gesture */ 104 + index = gest; 105 + break; 106 + case 0x0c: /* Long press gesture */ 107 + default: 108 + index = CST816X_NUM_KEYS; 109 + break; 110 + } 111 + 112 + return index - 1; 113 + } 114 + 115 + static bool cst816x_process_touch(struct cst816x_priv *priv, 116 + struct cst816x_touch *tch) 117 + { 118 + if (cst816x_i2c_read_register(priv, CST816X_RD_REG, tch, sizeof(*tch))) 119 + return false; 120 + 121 + tch->abs_x = get_unaligned_be16(&tch->abs_x) & GENMASK(11, 0); 122 + tch->abs_y = get_unaligned_be16(&tch->abs_y) & GENMASK(11, 0); 123 + 124 + dev_dbg(&priv->client->dev, "x: %u, y: %u, t: %u, g: 0x%x\n", 125 + tch->abs_x, tch->abs_y, tch->active, tch->gest); 126 + 127 + return true; 128 + } 129 + 130 + static int cst816x_register_input(struct cst816x_priv *priv) 131 + { 132 + priv->input = devm_input_allocate_device(&priv->client->dev); 133 + if (!priv->input) 134 + return -ENOMEM; 135 + 136 + priv->input->name = "Hynitron CST816x Series Touchscreen"; 137 + priv->input->phys = "input/ts"; 138 + priv->input->id.bustype = BUS_I2C; 139 + 140 + input_set_drvdata(priv->input, priv); 141 + 142 + input_set_abs_params(priv->input, ABS_X, 0, 240, 0, 0); 143 + input_set_abs_params(priv->input, ABS_Y, 0, 240, 0, 0); 144 + input_set_capability(priv->input, EV_KEY, BTN_TOUCH); 145 + 146 + priv->input->keycode = priv->keycode; 147 + priv->input->keycodesize = sizeof(priv->keycode[0]); 148 + priv->input->keycodemax = priv->keycodemax; 149 + 150 + for (int i = 0; i < priv->keycodemax; i++) { 151 + if (priv->keycode[i] == KEY_RESERVED) 152 + continue; 153 + 154 + input_set_capability(priv->input, EV_KEY, priv->keycode[i]); 155 + } 156 + 157 + return input_register_device(priv->input); 158 + } 159 + 160 + static void cst816x_reset(struct cst816x_priv *priv) 161 + { 162 + gpiod_set_value_cansleep(priv->reset, 1); 163 + msleep(50); 164 + gpiod_set_value_cansleep(priv->reset, 0); 165 + msleep(100); 166 + } 167 + 168 + static irqreturn_t cst816x_irq_cb(int irq, void *cookie) 169 + { 170 + struct cst816x_priv *priv = cookie; 171 + struct cst816x_touch tch; 172 + 173 + if (!cst816x_process_touch(priv, &tch)) 174 + return IRQ_HANDLED; 175 + 176 + input_report_abs(priv->input, ABS_X, tch.abs_x); 177 + input_report_abs(priv->input, ABS_Y, tch.abs_y); 178 + 179 + if (tch.gest) 180 + input_report_key(priv->input, 181 + priv->keycode[cst816x_gest_idx(tch.gest)], 182 + tch.active); 183 + 184 + input_report_key(priv->input, BTN_TOUCH, tch.active); 185 + 186 + input_sync(priv->input); 187 + 188 + return IRQ_HANDLED; 189 + } 190 + 191 + static int cst816x_probe(struct i2c_client *client) 192 + { 193 + struct device *dev = &client->dev; 194 + struct cst816x_priv *priv; 195 + int error; 196 + 197 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 198 + if (!priv) 199 + return -ENOMEM; 200 + 201 + priv->client = client; 202 + 203 + priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 204 + if (IS_ERR(priv->reset)) 205 + return dev_err_probe(dev, PTR_ERR(priv->reset), 206 + "gpio reset request failed\n"); 207 + 208 + if (priv->reset) 209 + cst816x_reset(priv); 210 + 211 + error = cst816x_parse_keycodes(dev, priv); 212 + if (error) 213 + dev_warn(dev, "no gestures found in dt\n"); 214 + 215 + error = cst816x_register_input(priv); 216 + if (error) 217 + return dev_err_probe(dev, error, "input register failed\n"); 218 + 219 + error = devm_request_threaded_irq(dev, client->irq, 220 + NULL, cst816x_irq_cb, IRQF_ONESHOT, 221 + dev_driver_string(dev), priv); 222 + if (error) 223 + return dev_err_probe(dev, error, "irq request failed\n"); 224 + 225 + return 0; 226 + } 227 + 228 + static const struct i2c_device_id cst816x_id[] = { 229 + { .name = "cst816s", 0 }, 230 + { } 231 + }; 232 + MODULE_DEVICE_TABLE(i2c, cst816x_id); 233 + 234 + static const struct of_device_id cst816x_of_match[] = { 235 + { .compatible = "hynitron,cst816s", }, 236 + { } 237 + }; 238 + MODULE_DEVICE_TABLE(of, cst816x_of_match); 239 + 240 + static struct i2c_driver cst816x_driver = { 241 + .driver = { 242 + .name = "cst816x", 243 + .of_match_table = cst816x_of_match, 244 + }, 245 + .id_table = cst816x_id, 246 + .probe = cst816x_probe, 247 + }; 248 + 249 + module_i2c_driver(cst816x_driver); 250 + 251 + MODULE_AUTHOR("Oleh Kuzhylnyi <kuzhylol@gmail.com>"); 252 + MODULE_DESCRIPTION("Hynitron CST816x Series Touchscreen Driver"); 253 + MODULE_LICENSE("GPL");
+77 -44
drivers/input/touchscreen/imx6ul_tsc.c
··· 7 7 #include <linux/errno.h> 8 8 #include <linux/kernel.h> 9 9 #include <linux/module.h> 10 + #include <linux/bitfield.h> 10 11 #include <linux/gpio/consumer.h> 11 12 #include <linux/input.h> 12 13 #include <linux/slab.h> ··· 21 20 #include <linux/log2.h> 22 21 23 22 /* ADC configuration registers field define */ 24 - #define ADC_AIEN (0x1 << 7) 23 + #define ADC_AIEN BIT(7) 24 + #define ADC_ADCH_MASK GENMASK(4, 0) 25 25 #define ADC_CONV_DISABLE 0x1F 26 - #define ADC_AVGE (0x1 << 5) 27 - #define ADC_CAL (0x1 << 7) 28 - #define ADC_CALF 0x2 29 - #define ADC_12BIT_MODE (0x2 << 2) 30 - #define ADC_CONV_MODE_MASK (0x3 << 2) 26 + #define ADC_AVGE BIT(5) 27 + #define ADC_CAL BIT(7) 28 + #define ADC_CALF BIT(1) 29 + #define ADC_CONV_MODE_MASK GENMASK(3, 2) 30 + #define ADC_12BIT_MODE 0x2 31 31 #define ADC_IPG_CLK 0x00 32 - #define ADC_INPUT_CLK_MASK 0x3 33 - #define ADC_CLK_DIV_8 (0x03 << 5) 34 - #define ADC_CLK_DIV_MASK (0x3 << 5) 35 - #define ADC_SHORT_SAMPLE_MODE (0x0 << 4) 36 - #define ADC_SAMPLE_MODE_MASK (0x1 << 4) 37 - #define ADC_HARDWARE_TRIGGER (0x1 << 13) 38 - #define ADC_AVGS_SHIFT 14 39 - #define ADC_AVGS_MASK (0x3 << 14) 32 + #define ADC_INPUT_CLK_MASK GENMASK(1, 0) 33 + #define ADC_CLK_DIV_8 0x03 34 + #define ADC_CLK_DIV_MASK GENMASK(6, 5) 35 + #define ADC_SAMPLE_MODE BIT(4) 36 + #define ADC_HARDWARE_TRIGGER BIT(13) 37 + #define ADC_AVGS_MASK GENMASK(15, 14) 40 38 #define SELECT_CHANNEL_4 0x04 41 39 #define SELECT_CHANNEL_1 0x01 42 - #define DISABLE_CONVERSION_INT (0x0 << 7) 43 40 44 41 /* ADC registers */ 45 42 #define REG_ADC_HC0 0x00 ··· 54 55 #define ADC_TIMEOUT msecs_to_jiffies(100) 55 56 56 57 /* TSC registers */ 57 - #define REG_TSC_BASIC_SETING 0x00 58 + #define REG_TSC_BASIC_SETTING 0x00 58 59 #define REG_TSC_PRE_CHARGE_TIME 0x10 59 60 #define REG_TSC_FLOW_CONTROL 0x20 60 61 #define REG_TSC_MEASURE_VALUE 0x30 ··· 64 65 #define REG_TSC_DEBUG_MODE 0x70 65 66 #define REG_TSC_DEBUG_MODE2 0x80 66 67 68 + /* TSC_MEASURE_VALUE register field define */ 69 + #define X_VALUE_MASK GENMASK(27, 16) 70 + #define Y_VALUE_MASK GENMASK(11, 0) 71 + 67 72 /* TSC configuration registers field define */ 68 - #define DETECT_4_WIRE_MODE (0x0 << 4) 69 - #define AUTO_MEASURE 0x1 70 - #define MEASURE_SIGNAL 0x1 71 - #define DETECT_SIGNAL (0x1 << 4) 72 - #define VALID_SIGNAL (0x1 << 8) 73 - #define MEASURE_INT_EN 0x1 74 - #define MEASURE_SIG_EN 0x1 75 - #define VALID_SIG_EN (0x1 << 8) 76 - #define DE_GLITCH_2 (0x2 << 29) 77 - #define START_SENSE (0x1 << 12) 78 - #define TSC_DISABLE (0x1 << 16) 73 + #define MEASURE_DELAY_TIME_MASK GENMASK(31, 8) 74 + #define DETECT_5_WIRE_MODE BIT(4) 75 + #define AUTO_MEASURE BIT(0) 76 + #define MEASURE_SIGNAL BIT(0) 77 + #define DETECT_SIGNAL BIT(4) 78 + #define VALID_SIGNAL BIT(8) 79 + #define MEASURE_INT_EN BIT(0) 80 + #define MEASURE_SIG_EN BIT(0) 81 + #define VALID_SIG_EN BIT(8) 82 + #define DE_GLITCH_MASK GENMASK(30, 29) 83 + #define DE_GLITCH_DEF 0x02 84 + #define START_SENSE BIT(12) 85 + #define TSC_DISABLE BIT(16) 79 86 #define DETECT_MODE 0x2 87 + #define STATE_MACHINE_MASK GENMASK(22, 20) 80 88 81 89 struct imx6ul_tsc { 82 90 struct device *dev; ··· 98 92 u32 pre_charge_time; 99 93 bool average_enable; 100 94 u32 average_select; 95 + u32 de_glitch; 101 96 102 97 struct completion completion; 103 98 }; ··· 119 112 120 113 adc_cfg = readl(tsc->adc_regs + REG_ADC_CFG); 121 114 adc_cfg &= ~(ADC_CONV_MODE_MASK | ADC_INPUT_CLK_MASK); 122 - adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK; 123 - adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK); 124 - adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE; 115 + adc_cfg |= FIELD_PREP(ADC_CONV_MODE_MASK, ADC_12BIT_MODE) | 116 + FIELD_PREP(ADC_INPUT_CLK_MASK, ADC_IPG_CLK); 117 + adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE); 118 + adc_cfg |= FIELD_PREP(ADC_CLK_DIV_MASK, ADC_CLK_DIV_8); 125 119 if (tsc->average_enable) { 126 120 adc_cfg &= ~ADC_AVGS_MASK; 127 - adc_cfg |= (tsc->average_select) << ADC_AVGS_SHIFT; 121 + adc_cfg |= FIELD_PREP(ADC_AVGS_MASK, tsc->average_select); 128 122 } 129 123 adc_cfg &= ~ADC_HARDWARE_TRIGGER; 130 124 writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG); 131 125 132 126 /* enable calibration interrupt */ 133 127 adc_hc |= ADC_AIEN; 134 - adc_hc |= ADC_CONV_DISABLE; 128 + adc_hc |= FIELD_PREP(ADC_ADCH_MASK, ADC_CONV_DISABLE); 135 129 writel(adc_hc, tsc->adc_regs + REG_ADC_HC0); 136 130 137 131 /* start ADC calibration */ ··· 172 164 { 173 165 u32 adc_hc0, adc_hc1, adc_hc2, adc_hc3, adc_hc4; 174 166 175 - adc_hc0 = DISABLE_CONVERSION_INT; 167 + adc_hc0 = FIELD_PREP(ADC_AIEN, 0); 176 168 writel(adc_hc0, tsc->adc_regs + REG_ADC_HC0); 177 169 178 - adc_hc1 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_4; 170 + adc_hc1 = FIELD_PREP(ADC_AIEN, 0) | 171 + FIELD_PREP(ADC_ADCH_MASK, SELECT_CHANNEL_4); 179 172 writel(adc_hc1, tsc->adc_regs + REG_ADC_HC1); 180 173 181 - adc_hc2 = DISABLE_CONVERSION_INT; 174 + adc_hc2 = FIELD_PREP(ADC_AIEN, 0); 182 175 writel(adc_hc2, tsc->adc_regs + REG_ADC_HC2); 183 176 184 - adc_hc3 = DISABLE_CONVERSION_INT | SELECT_CHANNEL_1; 177 + adc_hc3 = FIELD_PREP(ADC_AIEN, 0) | 178 + FIELD_PREP(ADC_ADCH_MASK, SELECT_CHANNEL_1); 185 179 writel(adc_hc3, tsc->adc_regs + REG_ADC_HC3); 186 180 187 - adc_hc4 = DISABLE_CONVERSION_INT; 181 + adc_hc4 = FIELD_PREP(ADC_AIEN, 0); 188 182 writel(adc_hc4, tsc->adc_regs + REG_ADC_HC4); 189 183 } 190 184 ··· 198 188 static void imx6ul_tsc_set(struct imx6ul_tsc *tsc) 199 189 { 200 190 u32 basic_setting = 0; 191 + u32 debug_mode2; 201 192 u32 start; 202 193 203 - basic_setting |= tsc->measure_delay_time << 8; 204 - basic_setting |= DETECT_4_WIRE_MODE | AUTO_MEASURE; 205 - writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETING); 194 + basic_setting |= FIELD_PREP(MEASURE_DELAY_TIME_MASK, 195 + tsc->measure_delay_time); 196 + basic_setting |= AUTO_MEASURE; 197 + writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING); 206 198 207 - writel(DE_GLITCH_2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2); 199 + debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, tsc->de_glitch); 200 + writel(debug_mode2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2); 208 201 209 202 writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME); 210 203 writel(MEASURE_INT_EN, tsc->tsc_regs + REG_TSC_INT_EN); ··· 263 250 264 251 usleep_range(200, 400); 265 252 debug_mode2 = readl(tsc->tsc_regs + REG_TSC_DEBUG_MODE2); 266 - state_machine = (debug_mode2 >> 20) & 0x7; 253 + state_machine = FIELD_GET(STATE_MACHINE_MASK, debug_mode2); 267 254 } while (state_machine != DETECT_MODE); 268 255 269 256 usleep_range(200, 400); ··· 291 278 292 279 if (status & MEASURE_SIGNAL) { 293 280 value = readl(tsc->tsc_regs + REG_TSC_MEASURE_VALUE); 294 - x = (value >> 16) & 0x0fff; 295 - y = value & 0x0fff; 281 + x = FIELD_GET(X_VALUE_MASK, value); 282 + y = FIELD_GET(Y_VALUE_MASK, value); 296 283 297 284 /* 298 285 * In detect mode, we can get the xnur gpio value, ··· 392 379 int tsc_irq; 393 380 int adc_irq; 394 381 u32 average_samples; 382 + u32 de_glitch; 395 383 396 384 tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL); 397 385 if (!tsc) ··· 513 499 "touchscreen-average-samples (%u) must be 1, 4, 8, 16 or 32\n", 514 500 average_samples); 515 501 return -EINVAL; 502 + } 503 + 504 + err = of_property_read_u32(np, "debounce-delay-us", &de_glitch); 505 + if (err) { 506 + tsc->de_glitch = DE_GLITCH_DEF; 507 + } else { 508 + u64 cycles; 509 + unsigned long rate = clk_get_rate(tsc->tsc_clk); 510 + 511 + cycles = DIV64_U64_ROUND_UP((u64)de_glitch * rate, USEC_PER_SEC); 512 + 513 + if (cycles <= 0x3ff) 514 + tsc->de_glitch = 3; 515 + else if (cycles <= 0x7ff) 516 + tsc->de_glitch = 2; 517 + else if (cycles <= 0xfff) 518 + tsc->de_glitch = 1; 519 + else 520 + tsc->de_glitch = 0; 516 521 } 517 522 518 523 err = input_register_device(tsc->input);
+23 -16
drivers/input/touchscreen/tsc2007_core.c
··· 23 23 #include <linux/input.h> 24 24 #include <linux/interrupt.h> 25 25 #include <linux/i2c.h> 26 + #include <linux/math64.h> 26 27 #include <linux/mod_devicetable.h> 27 28 #include <linux/property.h> 28 29 #include <linux/platform_data/tsc2007.h> ··· 69 68 70 69 u32 tsc2007_calculate_resistance(struct tsc2007 *tsc, struct ts_event *tc) 71 70 { 72 - u32 rt = 0; 71 + u64 rt = 0; 73 72 74 73 /* range filtering */ 75 74 if (tc->x == MAX_12BIT) ··· 80 79 rt = tc->z2 - tc->z1; 81 80 rt *= tc->x; 82 81 rt *= tsc->x_plate_ohms; 83 - rt /= tc->z1; 82 + rt = div_u64(rt, tc->z1); 84 83 rt = (rt + 2047) >> 12; 85 84 } 86 85 87 - return rt; 86 + if (rt > U32_MAX) 87 + return U32_MAX; 88 + return (u32) rt; 88 89 } 89 90 90 91 bool tsc2007_is_pen_down(struct tsc2007 *ts) ··· 180 177 mb(); 181 178 wake_up(&ts->wait); 182 179 183 - disable_irq(ts->irq); 180 + if (ts->irq) 181 + disable_irq(ts->irq); 184 182 } 185 183 186 184 static int tsc2007_open(struct input_dev *input_dev) ··· 192 188 ts->stopped = false; 193 189 mb(); 194 190 195 - enable_irq(ts->irq); 191 + if (ts->irq) 192 + enable_irq(ts->irq); 196 193 197 194 /* Prepare for touch readings - power down ADC and enable PENIRQ */ 198 195 err = tsc2007_xfer(ts, PWRDOWN); ··· 258 253 if (ts->gpiod) 259 254 ts->get_pendown_state = tsc2007_get_pendown_state_gpio; 260 255 else 261 - dev_warn(dev, "Pen down GPIO is not specified in properties\n"); 256 + dev_dbg(dev, "Pen down GPIO is not specified in properties\n"); 262 257 263 258 return 0; 264 259 } ··· 366 361 pdata->init_platform_hw(); 367 362 } 368 363 369 - err = devm_request_threaded_irq(&client->dev, ts->irq, 370 - NULL, tsc2007_soft_irq, 371 - IRQF_ONESHOT, 372 - client->dev.driver->name, ts); 373 - if (err) { 374 - dev_err(&client->dev, "Failed to request irq %d: %d\n", 375 - ts->irq, err); 376 - return err; 377 - } 364 + if (ts->irq) { 365 + err = devm_request_threaded_irq(&client->dev, ts->irq, 366 + NULL, tsc2007_soft_irq, 367 + IRQF_ONESHOT, 368 + client->dev.driver->name, ts); 369 + if (err) { 370 + dev_err(&client->dev, "Failed to request irq %d: %d\n", 371 + ts->irq, err); 372 + return err; 373 + } 378 374 379 - tsc2007_stop(ts); 375 + tsc2007_stop(ts); 376 + } 380 377 381 378 /* power down the chip (TSC2007_SETUP does not ACK on I2C) */ 382 379 err = tsc2007_xfer(ts, PWRDOWN);
+1
drivers/input/touchscreen/tsc200x-core.c
··· 10 10 * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com> 11 11 */ 12 12 13 + #include <linux/export.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/module.h> 15 16 #include <linux/input.h>
+1
drivers/input/touchscreen/wm9705.c
··· 9 9 * Russell King <rmk@arm.linux.org.uk> 10 10 */ 11 11 12 + #include <linux/export.h> 12 13 #include <linux/module.h> 13 14 #include <linux/moduleparam.h> 14 15 #include <linux/kernel.h>
+1
drivers/input/touchscreen/wm9712.c
··· 9 9 * Russell King <rmk@arm.linux.org.uk> 10 10 */ 11 11 12 + #include <linux/export.h> 12 13 #include <linux/module.h> 13 14 #include <linux/moduleparam.h> 14 15 #include <linux/kernel.h>
+1
drivers/input/touchscreen/wm9713.c
··· 9 9 * Russell King <rmk@arm.linux.org.uk> 10 10 */ 11 11 12 + #include <linux/export.h> 12 13 #include <linux/module.h> 13 14 #include <linux/moduleparam.h> 14 15 #include <linux/kernel.h>
+1
drivers/input/touchscreen/wm97xx-core.c
··· 29 29 * - Support for async sampling control for noisy LCDs. 30 30 */ 31 31 32 + #include <linux/export.h> 32 33 #include <linux/module.h> 33 34 #include <linux/moduleparam.h> 34 35 #include <linux/kernel.h>
-164
include/linux/platform_data/keyboard-spear.h
··· 1 - /* 2 - * Copyright (C) 2010 ST Microelectronics 3 - * Rajeev Kumar <rajeevkumar.linux@gmail.com> 4 - * 5 - * This file is licensed under the terms of the GNU General Public 6 - * License version 2. This program is licensed "as is" without any 7 - * warranty of any kind, whether express or implied. 8 - */ 9 - 10 - #ifndef __PLAT_KEYBOARD_H 11 - #define __PLAT_KEYBOARD_H 12 - 13 - #include <linux/bitops.h> 14 - #include <linux/input.h> 15 - #include <linux/input/matrix_keypad.h> 16 - #include <linux/types.h> 17 - 18 - #define DECLARE_9x9_KEYMAP(_name) \ 19 - int _name[] = { \ 20 - KEY(0, 0, KEY_ESC), \ 21 - KEY(0, 1, KEY_1), \ 22 - KEY(0, 2, KEY_2), \ 23 - KEY(0, 3, KEY_3), \ 24 - KEY(0, 4, KEY_4), \ 25 - KEY(0, 5, KEY_5), \ 26 - KEY(0, 6, KEY_6), \ 27 - KEY(0, 7, KEY_7), \ 28 - KEY(0, 8, KEY_8), \ 29 - KEY(1, 0, KEY_9), \ 30 - KEY(1, 1, KEY_MINUS), \ 31 - KEY(1, 2, KEY_EQUAL), \ 32 - KEY(1, 3, KEY_BACKSPACE), \ 33 - KEY(1, 4, KEY_TAB), \ 34 - KEY(1, 5, KEY_Q), \ 35 - KEY(1, 6, KEY_W), \ 36 - KEY(1, 7, KEY_E), \ 37 - KEY(1, 8, KEY_R), \ 38 - KEY(2, 0, KEY_T), \ 39 - KEY(2, 1, KEY_Y), \ 40 - KEY(2, 2, KEY_U), \ 41 - KEY(2, 3, KEY_I), \ 42 - KEY(2, 4, KEY_O), \ 43 - KEY(2, 5, KEY_P), \ 44 - KEY(2, 6, KEY_LEFTBRACE), \ 45 - KEY(2, 7, KEY_RIGHTBRACE), \ 46 - KEY(2, 8, KEY_ENTER), \ 47 - KEY(3, 0, KEY_LEFTCTRL), \ 48 - KEY(3, 1, KEY_A), \ 49 - KEY(3, 2, KEY_S), \ 50 - KEY(3, 3, KEY_D), \ 51 - KEY(3, 4, KEY_F), \ 52 - KEY(3, 5, KEY_G), \ 53 - KEY(3, 6, KEY_H), \ 54 - KEY(3, 7, KEY_J), \ 55 - KEY(3, 8, KEY_K), \ 56 - KEY(4, 0, KEY_L), \ 57 - KEY(4, 1, KEY_SEMICOLON), \ 58 - KEY(4, 2, KEY_APOSTROPHE), \ 59 - KEY(4, 3, KEY_GRAVE), \ 60 - KEY(4, 4, KEY_LEFTSHIFT), \ 61 - KEY(4, 5, KEY_BACKSLASH), \ 62 - KEY(4, 6, KEY_Z), \ 63 - KEY(4, 7, KEY_X), \ 64 - KEY(4, 8, KEY_C), \ 65 - KEY(5, 0, KEY_V), \ 66 - KEY(5, 1, KEY_B), \ 67 - KEY(5, 2, KEY_N), \ 68 - KEY(5, 3, KEY_M), \ 69 - KEY(5, 4, KEY_COMMA), \ 70 - KEY(5, 5, KEY_DOT), \ 71 - KEY(5, 6, KEY_SLASH), \ 72 - KEY(5, 7, KEY_RIGHTSHIFT), \ 73 - KEY(5, 8, KEY_KPASTERISK), \ 74 - KEY(6, 0, KEY_LEFTALT), \ 75 - KEY(6, 1, KEY_SPACE), \ 76 - KEY(6, 2, KEY_CAPSLOCK), \ 77 - KEY(6, 3, KEY_F1), \ 78 - KEY(6, 4, KEY_F2), \ 79 - KEY(6, 5, KEY_F3), \ 80 - KEY(6, 6, KEY_F4), \ 81 - KEY(6, 7, KEY_F5), \ 82 - KEY(6, 8, KEY_F6), \ 83 - KEY(7, 0, KEY_F7), \ 84 - KEY(7, 1, KEY_F8), \ 85 - KEY(7, 2, KEY_F9), \ 86 - KEY(7, 3, KEY_F10), \ 87 - KEY(7, 4, KEY_NUMLOCK), \ 88 - KEY(7, 5, KEY_SCROLLLOCK), \ 89 - KEY(7, 6, KEY_KP7), \ 90 - KEY(7, 7, KEY_KP8), \ 91 - KEY(7, 8, KEY_KP9), \ 92 - KEY(8, 0, KEY_KPMINUS), \ 93 - KEY(8, 1, KEY_KP4), \ 94 - KEY(8, 2, KEY_KP5), \ 95 - KEY(8, 3, KEY_KP6), \ 96 - KEY(8, 4, KEY_KPPLUS), \ 97 - KEY(8, 5, KEY_KP1), \ 98 - KEY(8, 6, KEY_KP2), \ 99 - KEY(8, 7, KEY_KP3), \ 100 - KEY(8, 8, KEY_KP0), \ 101 - } 102 - 103 - #define DECLARE_6x6_KEYMAP(_name) \ 104 - int _name[] = { \ 105 - KEY(0, 0, KEY_RESERVED), \ 106 - KEY(0, 1, KEY_1), \ 107 - KEY(0, 2, KEY_2), \ 108 - KEY(0, 3, KEY_3), \ 109 - KEY(0, 4, KEY_4), \ 110 - KEY(0, 5, KEY_5), \ 111 - KEY(1, 0, KEY_Q), \ 112 - KEY(1, 1, KEY_W), \ 113 - KEY(1, 2, KEY_E), \ 114 - KEY(1, 3, KEY_R), \ 115 - KEY(1, 4, KEY_T), \ 116 - KEY(1, 5, KEY_Y), \ 117 - KEY(2, 0, KEY_D), \ 118 - KEY(2, 1, KEY_F), \ 119 - KEY(2, 2, KEY_G), \ 120 - KEY(2, 3, KEY_H), \ 121 - KEY(2, 4, KEY_J), \ 122 - KEY(2, 5, KEY_K), \ 123 - KEY(3, 0, KEY_B), \ 124 - KEY(3, 1, KEY_N), \ 125 - KEY(3, 2, KEY_M), \ 126 - KEY(3, 3, KEY_COMMA), \ 127 - KEY(3, 4, KEY_DOT), \ 128 - KEY(3, 5, KEY_SLASH), \ 129 - KEY(4, 0, KEY_F6), \ 130 - KEY(4, 1, KEY_F7), \ 131 - KEY(4, 2, KEY_F8), \ 132 - KEY(4, 3, KEY_F9), \ 133 - KEY(4, 4, KEY_F10), \ 134 - KEY(4, 5, KEY_NUMLOCK), \ 135 - KEY(5, 0, KEY_KP2), \ 136 - KEY(5, 1, KEY_KP3), \ 137 - KEY(5, 2, KEY_KP0), \ 138 - KEY(5, 3, KEY_KPDOT), \ 139 - KEY(5, 4, KEY_RO), \ 140 - KEY(5, 5, KEY_ZENKAKUHANKAKU), \ 141 - } 142 - 143 - #define KEYPAD_9x9 0 144 - #define KEYPAD_6x6 1 145 - #define KEYPAD_2x2 2 146 - 147 - /** 148 - * struct kbd_platform_data - spear keyboard platform data 149 - * keymap: pointer to keymap data (table and size) 150 - * rep: enables key autorepeat 151 - * mode: choose keyboard support(9x9, 6x6, 2x2) 152 - * suspended_rate: rate at which keyboard would operate in suspended mode 153 - * 154 - * This structure is supposed to be used by platform code to supply 155 - * keymaps to drivers that implement keyboards. 156 - */ 157 - struct kbd_platform_data { 158 - const struct matrix_keymap_data *keymap; 159 - bool rep; 160 - unsigned int mode; 161 - unsigned int suspended_rate; 162 - }; 163 - 164 - #endif /* __PLAT_KEYBOARD_H */
-73
include/linux/platform_data/keypad-pxa27x.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef __ASM_ARCH_PXA27x_KEYPAD_H 3 - #define __ASM_ARCH_PXA27x_KEYPAD_H 4 - 5 - #include <linux/input.h> 6 - #include <linux/input/matrix_keypad.h> 7 - 8 - #define MAX_MATRIX_KEY_ROWS (8) 9 - #define MAX_MATRIX_KEY_COLS (8) 10 - #define MATRIX_ROW_SHIFT (3) 11 - #define MAX_DIRECT_KEY_NUM (8) 12 - 13 - /* pxa3xx keypad platform specific parameters 14 - * 15 - * NOTE: 16 - * 1. direct_key_num indicates the number of keys in the direct keypad 17 - * _plus_ the number of rotary-encoder sensor inputs, this can be 18 - * left as 0 if only rotary encoders are enabled, the driver will 19 - * automatically calculate this 20 - * 21 - * 2. direct_key_map is the key code map for the direct keys, if rotary 22 - * encoder(s) are enabled, direct key 0/1(2/3) will be ignored 23 - * 24 - * 3. rotary can be either interpreted as a relative input event (e.g. 25 - * REL_WHEEL/REL_HWHEEL) or specific keys (e.g. UP/DOWN/LEFT/RIGHT) 26 - * 27 - * 4. matrix key and direct key will use the same debounce_interval by 28 - * default, which should be sufficient in most cases 29 - * 30 - * pxa168 keypad platform specific parameter 31 - * 32 - * NOTE: 33 - * clear_wakeup_event callback is a workaround required to clear the 34 - * keypad interrupt. The keypad wake must be cleared in addition to 35 - * reading the MI/DI bits in the KPC register. 36 - */ 37 - struct pxa27x_keypad_platform_data { 38 - 39 - /* code map for the matrix keys */ 40 - const struct matrix_keymap_data *matrix_keymap_data; 41 - unsigned int matrix_key_rows; 42 - unsigned int matrix_key_cols; 43 - 44 - /* direct keys */ 45 - int direct_key_num; 46 - unsigned int direct_key_map[MAX_DIRECT_KEY_NUM]; 47 - /* the key output may be low active */ 48 - int direct_key_low_active; 49 - /* give board a chance to choose the start direct key */ 50 - unsigned int direct_key_mask; 51 - 52 - /* rotary encoders 0 */ 53 - int enable_rotary0; 54 - int rotary0_rel_code; 55 - int rotary0_up_key; 56 - int rotary0_down_key; 57 - 58 - /* rotary encoders 1 */ 59 - int enable_rotary1; 60 - int rotary1_rel_code; 61 - int rotary1_up_key; 62 - int rotary1_down_key; 63 - 64 - /* key debounce interval */ 65 - unsigned int debounce_interval; 66 - 67 - /* clear wakeup event requirement for pxa168 */ 68 - void (*clear_wakeup_event)(void); 69 - }; 70 - 71 - extern void pxa_set_keypad_info(struct pxa27x_keypad_platform_data *info); 72 - 73 - #endif /* __ASM_ARCH_PXA27x_KEYPAD_H */
-30
include/linux/tca6416_keypad.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * tca6416 keypad platform support 4 - * 5 - * Copyright (C) 2010 Texas Instruments 6 - * 7 - * Author: Sriramakrishnan <srk@ti.com> 8 - */ 9 - 10 - #ifndef _TCA6416_KEYS_H 11 - #define _TCA6416_KEYS_H 12 - 13 - #include <linux/types.h> 14 - 15 - struct tca6416_button { 16 - /* Configuration parameters */ 17 - int code; /* input event code (KEY_*, SW_*) */ 18 - int active_low; 19 - int type; /* input event type (EV_KEY, EV_SW) */ 20 - }; 21 - 22 - struct tca6416_keys_platform_data { 23 - struct tca6416_button *buttons; 24 - int nbuttons; 25 - unsigned int rep:1; /* enable input subsystem auto repeat */ 26 - uint16_t pinmask; 27 - uint16_t invert; 28 - int use_polling; /* use polling if Interrupt is not connected*/ 29 - }; 30 - #endif