Skip to contentSkip to conversation

Input: add support for OnePlus/OPPO Pad pogo-pin keyboards

PATCH Superseded [email protected] 4 participants 8 messages Nov 28 – Dec 2

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover Input: add support for OnePlus/OPPO Pad pogo-pin keyboards

From: Yibo Wang <[email protected]>

This series adds support for the magnetic pogo-pin smart keyboards of the OnePlus Pad 3 Pro / Pad 4 and the OPPO Pad 5 Pro. The keyboard is built around a Tinno MCU attached to a tablet UART. Both sides share a single data wire, so the host gates its transmission onto the bus with a PMIC GPIO for the duration of a frame, and every host frame is echoed back on RX.

The MCU speaks a framed "one wire bus" protocol over the half-duplex 921600 8N1 UART: 8x 0x55 preamble, 0xF1, src/dst addresses, command, length, payload, CRC16-IBM (poly 0x8005, init 0xC596), 0xFE and 4x 0xAA. The protocol was reverse engineered from the vendor kernel driver; this is a clean-room serdev reimplementation that replaces the downstream platform driver, which depends on a private msm_geni_serial callback and a user-space held tty fd.

The core protocol (framing, keys, touchpad, sync/heartbeat) has been carried unchanged across four SoC generations of these keyboards, from the sm8550 era to the sm8850 ones covered here; only the 0x3A general sub-commands grew over time. Patch 1 adds the DT binding, patch 2 the driver.

Changes in v7, addressing Krzysztof Kozlowski's comments:

- dropped the touchscreen size/mm properties from the binding as
agreed: the touchpad geometry is per-project driver data and neither the binding documents it nor the driver parses it from DT;

- moved the MAINTAINERS entry to its alphabetical place, after ONENAND;

- the disclosure prose now says LLM.

Changes in v6:

- disclose the AI assistance in preparing the binding documentation with an Assisted-by trailer; no functional change.

Changes in v5, addressing Rob Herring's comments on the binding:

- dropped the block scalar from the top-level description;

- rewrapped the descriptions to stay within 75 columns;

- restored the serial parent node in the example.

Changes in v4, after Krzysztof Kozlowski's comment that the binding describes the keyboard rather than the MCU (wording only, no functional change):

- the binding description and the commit messages now describe the keyboard (built around the Tinno MCU) instead of the MCU itself, and spell out that a keyboard is a fixed physical device, so the touchpad geometry and the product names are per-compatible constants in the driver.

Changes in v3:

- the compatible names the tablet project the pogo port belongs to (oneplus,caihong- / erhai- / iceland-pogo-keyboard, the codenames used by the vendor trees), and the driver carries a per-project description in the OF match data: feature flags gate each 0x3A general sub-command (caihong, sm8650 era, has no wake notification and no backlight; erhai, sm8750 era, adds the wake notification; iceland, sm8850 era, adds the keyboard backlight), while the touchpad geometry and the per-brand product names are per-project constants - the wake notification is skipped and the backlight LED only registered where supported;

- the touchpad geometry and product names are no longer DT properties:
they are fixed per project and live in the driver; the common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm) remain as an optional override, parsed with touchscreen_parse_properties(), for the unlikely case of a variant.

Changes in v2:

- dropped the redundant "binding" from the dt-bindings subject;

- replaced the custom oneplus,touchpad-xy-max/-resolution properties with the common touchscreen properties;

- dropped the serial wrapper node from the binding example;

- the MAINTAINERS entry added with the binding references only the binding file; the driver F: line is added together with the driver patch.

Tested on the OnePlus Pad 4 (iceland) running Linux 7.2.0-sm8850 (v7.2-based iceland tree).

The binding documentation was prepared with the assistance of an LLM; the technical content was reviewed, adjusted and validated by the author.

Assisted-by Z.ai:GLM-5.3

Yibo Wang (2):
dt-bindings: input: add OnePlus pogo-pin keyboard
Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver

 .../bindings/input/oneplus,pogo-keyboard.yaml |   70 ++
 MAINTAINERS                                   |    7 +
 drivers/input/keyboard/Kconfig                |   13 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1251 ++++++++++++++++++++
 5 files changed, 1342 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
 create mode 100644 drivers/input/keyboard/oneplus-pogo-kbd.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v7 1/2 dt-bindings: input: add OnePlus pogo-pin keyboard

From: Yibo Wang <[email protected]>

Binding for the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart keyboards, built around a Tinno keyboard MCU and attached to a tablet UART. Describes the supply, TX-gate and wake GPIOs, with a MAINTAINERS entry.

The compatible names the tablet project the pogo port belongs to (caihong, erhai or iceland), which pins the keyboard generation and with it the protocol extensions the host may use: the 0x3A general sub-commands grew over time, from the caihong (sm8650 era) keyboards with neither wake notification nor backlight, through erhai (sm8750 era, wake notification) to iceland (sm8850 era, keyboard backlight).

The keyboard is a fixed physical device, so the touchpad geometry and the product names are per-project constants and live in the driver.

The binding documentation was prepared with the assistance of an LLM; the technical content was reviewed, adjusted and validated by the author.

Assisted-by Z.ai:GLM-5.3
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 70 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +70 -0
new file mode 100644
index 0000000000..e76e82ea6a
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2026 Yibo Wang <[email protected]>
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/oneplus,pogo-keyboard.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OnePlus / OPPO Pad pogo-pin smart keyboard
+
+maintainers:
+  - Yibo Wang <[email protected]>
+
+description:
+  The OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart
+  keyboards, built around a Tinno keyboard MCU.  The keyboard is
+  attached to a tablet UART and speaks a framed half-duplex protocol
+  over a shared single wire; host transmission is gated onto the wire
+  by a PMIC GPIO for the duration of a frame.  It provides a keyboard
+  matrix, a touchpad and a keyboard backlight.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    description: |
+      Names the tablet project the pogo port belongs to, which pins the
+      keyboard generation and the protocol extensions the host may
+      use: caihong (sm8650 era) supports neither the wake notification
+      nor a backlight, erhai (sm8750 era) adds the wake notification,
+      iceland (sm8850 era) adds the keyboard backlight.
+    enum:
+      - oneplus,caihong-pogo-keyboard
+      - oneplus,erhai-pogo-keyboard
+      - oneplus,iceland-pogo-keyboard
+
+  power-gpios:
+    description:
+      GPIO enabling the keyboard supply, held high while attached.
+    maxItems: 1
+
+  tx-enable-gpios:
+    description: GPIO gating host TX onto the shared one-wire bus.
+    maxItems: 1
+
+  wake-gpios:
+    description: GPIO signalling attach/detach, also used as the wake line.
+    maxItems: 1
+
+required:
+  - compatible
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    serial {
+        keyboard {
+            compatible = "oneplus,iceland-pogo-keyboard";
+            power-gpios = <&pmic_gpios 12 GPIO_ACTIVE_HIGH>;
+            tx-enable-gpios = <&pmic2_gpios 6 GPIO_ACTIVE_HIGH>;
+            wake-gpios = <&tlmm 151 GPIO_ACTIVE_LOW>;
+        };
+    };
+...
MAINTAINERS +6 -0
index 8014b9f825..7730128d6c 100644
@@ -20163,6 +20163,12 @@ S:	Maintained
 F:	drivers/mtd/nand/onenand/
 F:	include/linux/mtd/onenand*.h
 
+ONEPLUS POGO-PIN KEYBOARD DRIVER
+M:	Yibo Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
+
 ONEXPLAYER HID DRIVER
 M:	Derek J. Clark <[email protected]>
 L:	[email protected]
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v7 1/2] dt-bindings: input: add OnePlus pogo-pin keyboard

Quoted 14 lines · On Sat, Nov 28, 2026 at 02:18:34AM -0600, [email protected] wrote:

From: Yibo Wang <[email protected]>

Binding for the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart keyboards, built around a Tinno keyboard MCU and attached to a tablet UART. Describes the supply, TX-gate and wake GPIOs, with a MAINTAINERS entry.

The compatible names the tablet project the pogo port belongs to (caihong, erhai or iceland), which pins the keyboard generation and with it the protocol extensions the host may use: the 0x3A general sub-commands grew over time, from the caihong (sm8650 era) keyboards with neither wake notification nor backlight, through erhai (sm8750 era, wake notification) to iceland (sm8850 era, keyboard backlight).

Quoted 6 lines

The keyboard is a fixed physical device, so the touchpad geometry and the product names are per-project constants and live in the driver.

The binding documentation was prepared with the assistance of an LLM; the technical content was reviewed, adjusted and validated by the author.

This goes to the changelog

Quoted 2 lines
Assisted-by Z.ai:GLM-5.3

Drop

Quoted 29 lines
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 70 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +16 -0
new file mode 100644
index 0000000000..e76e82ea6a
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2026 Yibo Wang <[email protected]>
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/oneplus,pogo-keyboard.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OnePlus / OPPO Pad pogo-pin smart keyboard
+
+maintainers:
+  - Yibo Wang <[email protected]>
+
+description:
+  The OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart
+  keyboards, built around a Tinno keyboard MCU.  The keyboard is
+  attached to a tablet UART and speaks a framed half-duplex protocol

Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+  over a shared single wire; host transmission is gated onto the wire
+  by a PMIC GPIO for the duration of a frame.  It provides a keyboard
+  matrix, a touchpad and a keyboard backlight.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml line 39

Quoted 13 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +13 -0
+      Names the tablet project the pogo port belongs to, which pins the
+      keyboard generation and the protocol extensions the host may
+      use: caihong (sm8650 era) supports neither the wake notification
+      nor a backlight, erhai (sm8750 era) adds the wake notification,
+      iceland (sm8850 era) adds the keyboard backlight.
+    enum:
+      - oneplus,caihong-pogo-keyboard
+      - oneplus,erhai-pogo-keyboard
+      - oneplus,iceland-pogo-keyboard
+
+  power-gpios:
+    description:
+      GPIO enabling the keyboard supply, held high while attached.

powerdown-gpios, I guess

Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml line 41

Quoted 2 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +2 -0
+    maxItems: 1
+

Best regards,
Krzysztof

maintainer
#3 lore raw

Re: [PATCH v7 1/2] dt-bindings: input: add OnePlus pogo-pin keyboard

Quoted 86 lines · Krzysztof Kozlowski
Quoted 14 lines · On Sat, Nov 28, 2026 at 02:18:34AM -0600, [email protected] wrote:

From: Yibo Wang <[email protected]>

Binding for the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart keyboards, built around a Tinno keyboard MCU and attached to a tablet UART. Describes the supply, TX-gate and wake GPIOs, with a MAINTAINERS entry.

The compatible names the tablet project the pogo port belongs to (caihong, erhai or iceland), which pins the keyboard generation and with it the protocol extensions the host may use: the 0x3A general sub-commands grew over time, from the caihong (sm8650 era) keyboards with neither wake notification nor backlight, through erhai (sm8750 era, wake notification) to iceland (sm8850 era, keyboard backlight).

Quoted 6 lines

The keyboard is a fixed physical device, so the touchpad geometry and the product names are per-project constants and live in the driver.

The binding documentation was prepared with the assistance of an LLM; the technical content was reviewed, adjusted and validated by the author.

This goes to the changelog

Quoted 2 lines
Assisted-by Z.ai:GLM-5.3

Drop

Quoted 29 lines
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 70 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +16 -0
new file mode 100644
index 0000000000..e76e82ea6a
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2026 Yibo Wang <[email protected]>
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/oneplus,pogo-keyboard.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: OnePlus / OPPO Pad pogo-pin smart keyboard
+
+maintainers:
+  - Yibo Wang <[email protected]>
+
+description:
+  The OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart
+  keyboards, built around a Tinno keyboard MCU.  The keyboard is
+  attached to a tablet UART and speaks a framed half-duplex protocol

Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+  over a shared single wire; host transmission is gated onto the wire
+  by a PMIC GPIO for the duration of a frame.  It provides a keyboard
+  matrix, a touchpad and a keyboard backlight.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml line 39

Quoted 13 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +13 -0
+      Names the tablet project the pogo port belongs to, which pins the
+      keyboard generation and the protocol extensions the host may
+      use: caihong (sm8650 era) supports neither the wake notification
+      nor a backlight, erhai (sm8750 era) adds the wake notification,
+      iceland (sm8850 era) adds the keyboard backlight.
+    enum:
+      - oneplus,caihong-pogo-keyboard
+      - oneplus,erhai-pogo-keyboard
+      - oneplus,iceland-pogo-keyboard
+
+  power-gpios:
+    description:
+      GPIO enabling the keyboard supply, held high while attached.
Quoted 1 line

powerdown-gpios, I guess

Should it be a supply instead of GPIO? And then use "regulator-gpio".

Thanks.

Signature · 1 line
Dmitry
#4 lore raw

Re: [PATCH v7 1/2] dt-bindings: input: add OnePlus pogo-pin keyboard

Quoted 15 lines · Dmitry Torokhov
Quoted 14 lines · Krzysztof Kozlowski
Quoted 13 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +13 -0
+      Names the tablet project the pogo port belongs to, which pins the
+      keyboard generation and the protocol extensions the host may
+      use: caihong (sm8650 era) supports neither the wake notification
+      nor a backlight, erhai (sm8750 era) adds the wake notification,
+      iceland (sm8850 era) adds the keyboard backlight.
+    enum:
+      - oneplus,caihong-pogo-keyboard
+      - oneplus,erhai-pogo-keyboard
+      - oneplus,iceland-pogo-keyboard
+
+  power-gpios:
+    description:
+      GPIO enabling the keyboard supply, held high while attached.
Quoted 3 lines
Quoted 1 line

powerdown-gpios, I guess

Should it be a supply instead of GPIO? And then use "regulator-gpio".

Indeed, wording is quite confusing. I assumed this is some internal XPWRDN pin, but supply suggests, well, supply.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v7 1/2] dt-bindings: input: add OnePlus pogo-pin keyboard

From: Yibo Wang <[email protected]>

Hi Krzysztof, Dmitry,

Quoted 4 lines · Krzysztof Kozlowski
Quoted 1 line

Should it be a supply instead of GPIO? And then use "regulator-gpio".

Indeed, wording is quite confusing. I assumed this is some internal XPWRDN pin, but supply suggests, well, supply.

The vendor driver shows it depends on the board: it keys its power handling on the presence of a pogopin-power-supply property (feeding the connector from an LDO) and otherwise drives a pinctrl power enable, see setup_power_config() in
https://github.com/OnePlusOSS/android_kernel_modules_and_devicetree_oneplus_sm8850/tree/oneplus/sm8850_b_16.0.0_oneplus_15/vendor/oplus/kernel/device_info/pogo_keyboard

So v8 describes both, each optional:

- vdd-supply for boards that feed the connector through an LDO;

- enable-gpios for the enable pin, active high, driven high while the keyboard is attached. It is an enable and not a powerdown input:
the vendor pinctrl states it replaces are named pogo_power_enable / pogo_power_disable.

Power-up enables the regulator first and then raises the enable pin; power-down lowers the enable pin first and then disables the regulator. A board that provides neither keeps both always-on.

v8 follows as a new thread.

Best regards,
Yibo

#6 lore raw

PATCH v7 2/2 Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver

In reply to [email protected]

From: Yibo Wang <[email protected]>

Clean-room serdev driver for the Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro smart keyboards, replacing the vendor platform driver that depends on a downstream msm_geni_serial callback and a user-space held tty fd.

The MCU speaks a framed "one wire bus" protocol over a half-duplex 921600 8N1 UART: 8x 0x55 preamble, 0xF1, src/dst address, cmd, len, payload, CRC16-IBM (poly 0x8005, init 0xC596), 0xFE, 4x 0xAA. Host TX is gated onto the shared wire by a PMIC GPIO for the duration of a frame (450us before, 300us after) and every host frame is echoed back on RX.

Supported: attach detection via the wake GPIO + 100ms heartbeat timeout, touchpad, function/URL keys and the keyboard backlight exposed as a "pogo-keyboard::kbd_backlight" LED class device (max 100, the range the MCU accepts) so UPower and the desktop keyboard-backlight controls drive it through the standard interface. The backlight level is cached while detached and restored on re-attach.

Two robustness fixes are folded in from bring-up:

1. The MCU keeps sending the plug-in sync frame (0x2F/0x01) every 100 ms until the host reports its wake state (0x3A/0x02); only then does it switch to regular heartbeats (0x2F/0x05). Treat a repeated plug-in frame as a re-plug only once heartbeats have been seen, and send the wake notification on attach, otherwise the LED re-send loop at 10 Hz collides with the MCU and drops the link a few minutes after boot.

2. After a heartbeat timeout the detect path sampled the wake line once; it now re-arms detection properly so a working keyboard is picked up again without a re-plug.

The driver covers all three keyboard generations, selected by the compatible (caihong, erhai, iceland - the tablet projects): per-project feature flags decide which 0x3A general sub-commands are used, so the caihong era keyboards skip the wake notification and only iceland registers the backlight LED. The touchpad geometry and the product names are per-project constants carried in the match data. The MAINTAINERS entry from the binding patch gains the driver file.

---
 MAINTAINERS                               |    1 +
 drivers/input/keyboard/Kconfig            |   13 +
 drivers/input/keyboard/Makefile           |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c | 1251 +++++++++++++++++++++
 4 files changed, 1266 insertions(+)
 create mode 100644 drivers/input/keyboard/oneplus-pogo-kbd.c
MAINTAINERS +1 -0
index 7730128d6c..849b5e3228 100644
@@ -20168,6 +20168,7 @@ M:	Yibo Wang <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
+F:	drivers/input/keyboard/oneplus-pogo-kbd.c
 
 ONEXPLAYER HID DRIVER
 M:	Derek J. Clark <[email protected]>
drivers/input/keyboard/Kconfig +13 -0
index 9d1019ba02..011b9248b9 100644
@@ -806,4 +806,17 @@ config KEYBOARD_CYPRESS_SF
 	  To compile this driver as a module, choose M here: the
 	  module will be called cypress-sf.
 
+config KEYBOARD_ONEPLUS_POGO
+	tristate "OnePlus/OPPO Pad pogo-pin keyboard"
+	depends on SERIAL_DEV_BUS && GPIOLIB
+	depends on LEDS_CLASS
+	select INPUT_MT
+	help
+	  Say Y here to enable the magnetic pogo-pin keyboard with touchpad
+	  used by OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro.  The keyboard
+	  MCU talks a framed protocol over a half-duplex UART.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called oneplus-pogo-kbd.
+
 endif
drivers/input/keyboard/Makefile +1 -0
index 60bb7baf80..3554c50118 100644
@@ -50,6 +50,7 @@ obj-$(CONFIG_KEYBOARD_NEWTON)		+= newtonkbd.o
 obj-$(CONFIG_KEYBOARD_NSPIRE)		+= nspire-keypad.o
 obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
 obj-$(CONFIG_KEYBOARD_OMAP4)		+= omap4-keypad.o
+obj-$(CONFIG_KEYBOARD_ONEPLUS_POGO)	+= oneplus-pogo-kbd.o
 obj-$(CONFIG_KEYBOARD_OPENCORES)	+= opencores-kbd.o
 obj-$(CONFIG_KEYBOARD_PINEPHONE)	+= pinephone-keyboard.o
 obj-$(CONFIG_KEYBOARD_PMIC8XXX)		+= pmic8xxx-keypad.o
drivers/input/keyboard/oneplus-pogo-kbd.c new file +1251 -0

1,251 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH v7 2/2] Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver

Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] Input: oneplus-pogo-kbd - wake_irq left enabled in pogo_detect_work() - [High] Input…

Thank you for your contribution! Sashiko AI review found 11 potential issues to consider:
- [High] Input: oneplus-pogo-kbd - wake_irq left enabled in pogo_detect_work()
- [High] Input: oneplus-pogo-kbd - race on wake_irq_enabled in pogo_remove()
- [High] Input: oneplus-pogo-kbd - work cancellation order race in pogo_remove()
- [Medium] Input: oneplus-pogo-kbd - unlocked state updates in pogo_handle_sync()
- [Medium] Input: oneplus-pogo-kbd - battery status frames hijack pogo_set_general()
- [Medium] Input: oneplus-pogo-kbd - data race on kb->resp in pogo_xfer()
- [Medium] Input: oneplus-pogo-kbd: missing ABS_MT_TOOL_TYPE in pogo_register_inputs()
- [Medium] Input: oneplus-pogo-kbd: stuck keys and touches on replug in pogo_plug_work()
- [Low] Input: oneplus-pogo-kbd - 2-byte truncation of max-length replies in resp
- [Low] Input: oneplus-pogo-kbd - Kconfig selects non-existent INPUT_MT symbol
- [Low] Input: oneplus-pogo-kbd: unhandled GPIO error in pogo_detect_work()
--

commit 1c97b620e512d00923891630f226277057c54866
Author: Yibo Wang <[email protected]>

Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver

This commit adds a serdev input and LED class driver for the Tinno keyboard MCU used by OnePlus and OPPO Pad magnetic pogo-pin keyboards.

drivers/input/keyboard/Kconfig config KEYBOARD_CYPRESS_SF · line 764

Quoted 13 lines
drivers/input/keyboard/Kconfig +5 -0
index 07790614e27fc..3cf1928f85057 100644
@@ -757,4 +757,17 @@ config KEYBOARD_CYPRESS_SF
 	  To compile this driver as a module, choose M here: the
 	  module will be called cypress-sf.
 
+config KEYBOARD_ONEPLUS_POGO
+	tristate "OnePlus/OPPO Pad pogo-pin keyboard"
+	depends on SERIAL_DEV_BUS && GPIOLIB
+	depends on LEDS_CLASS
+	select INPUT_MT

[Severity: Low]
Does INPUT_MT exist as a Kconfig symbol? input-mt.o is built into input-core.o unconditionally under CONFIG_INPUT, so selecting INPUT_MT here is a no-op that triggers a Kconfig warning on an undefined symbol.

[ ... ]

Quoted 5 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
new file mode 100644
index 0000000000000..e7ead8e7ca4fb

[ ... ]

drivers/input/keyboard/oneplus-pogo-kbd.c line 195

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+	/* host -> keyboard transfers */
+	struct mutex io_lock;
+	struct mutex state_lock;
+	struct completion echo_done;
+	struct completion resp_done;
+	u8 tx_cmd;
+	bool tx_pending;
+	bool quitting;
+	u8 resp[OWB_MAX_PAYLOAD];
+	unsigned int resp_len;

[Severity: Low]
Should resp be sized to OWB_MAX_PAYLOAD + 2? pogo_handle_frame() copies the 2-byte cmd and len header together with the payload (len + 2 bytes) into kb->resp and clamps resp_len to sizeof(kb->resp), which truncates the last 2 bytes of a maximum-length reply.

[ ... ]

Quoted 63 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +63 -0
+static int pogo_xfer(struct pogo_kbd *kb, u8 cmd, const u8 *payload, u8 len,
+		     u8 *resp, unsigned int resp_size)
+{
+	u8 frame[OWB_TX_BUF_LEN];
+	unsigned int frame_len;
+	int attempt, ret = -ETIMEDOUT;
+
+	if (len > OWB_MAX_PAYLOAD)
+		return -EINVAL;
+
+	frame_len = owb_build_frame(frame, cmd, payload, len);
+	print_hex_dump_debug("pogo tx: ", DUMP_PREFIX_NONE, 32, 1, frame, frame_len, false);
+
+	mutex_lock(&kb->io_lock);
+	for (attempt = 0; attempt < POGO_XFER_RETRIES; attempt++) {
+		bool echoed;
+
+		/*
+		 * Drop any late echo/reply of the previous attempt: with
+		 * tx_pending cleared the RX path ignores frames until the
+		 * transfer below re-arms, so a delayed reply cannot complete
+		 * the fresh iteration or race the resp buffer.
+		 */
+		WRITE_ONCE(kb->tx_pending, false);
+		reinit_completion(&kb->echo_done);
+		reinit_completion(&kb->resp_done);
+		kb->tx_cmd = cmd;
+		WRITE_ONCE(kb->tx_pending, true);
+
+		gpiod_set_value_cansleep(kb->tx_en_gpio, 1);
+		usleep_range(POGO_TX_GATE_ON_US, POGO_TX_GATE_ON_US + 50);
+
+		ret = serdev_device_write(kb->serdev, frame, frame_len,
+					  msecs_to_jiffies(POGO_RESP_TIMEOUT_MS));
+		if (ret >= 0)
+			serdev_device_wait_until_sent(kb->serdev,
+						      msecs_to_jiffies(20));
+
+		/*
+		 * Release the wire as soon as the last bit is out: the MCU
+		 * answers within a few hundred microseconds and would collide
+		 * with our idle-high TX driver otherwise.  The echo is only
+		 * checked afterwards, it is already queued in the tty buffer.
+		 */
+		usleep_range(POGO_TX_GATE_OFF_US, POGO_TX_GATE_OFF_US + 50);
+		gpiod_set_value_cansleep(kb->tx_en_gpio, 0);
+
+		echoed = wait_for_completion_timeout(&kb->echo_done,
+				msecs_to_jiffies(POGO_ECHO_TIMEOUT_MS)) != 0;
+
+		if (ret < 0) {
+			dev_warn(kb->dev, "cmd 0x%02x write failed: %d\n", cmd, ret);
+			continue;
+		}
+		if (!echoed) {
+			dev_dbg(kb->dev, "cmd 0x%02x: no echo\n", cmd);
+			ret = -EIO;
+			continue;
+		}
+		if (!resp) {
+			ret = 0;
+			break;
+		}

drivers/input/keyboard/oneplus-pogo-kbd.c line 402

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+		if (wait_for_completion_timeout(&kb->resp_done,
+				msecs_to_jiffies(POGO_RESP_TIMEOUT_MS))) {
+			unsigned int n = min(kb->resp_len, resp_size);
+
+			/* stop the RX path before copying the reply out */
+			WRITE_ONCE(kb->tx_pending, false);
+			memcpy(resp, kb->resp, n);
+			ret = n;
+			break;
+		}

[Severity: Medium]
Can pogo_handle_frame() race with pogo_xfer() on kb->resp and kb->resp_len?

CPU0 CPU1 (serdev RX)
pogo_xfer()
/* attempt 0 times out on resp_done */
/* attempt 1 */
WRITE_ONCE(kb->tx_pending, false)
reinit_completion(&kb->resp_done)
WRITE_ONCE(kb->tx_pending, true)
/* late reply from attempt 0 arrives */

                                        pogo_handle_frame()
                                          kb->resp_len = ...
                                          memcpy(kb->resp, ...)
                                          complete(&kb->resp_done)
  wait_for_completion_timeout(&kb->resp_done)
  n = min(kb->resp_len, resp_size)
                                        /* reply to attempt 1 arrives */
                                        pogo_handle_frame()
                                          if (READ_ONCE(kb->tx_pending))
                                            kb->resp_len = ...
                                            memcpy(kb->resp, ...) <-- data race

WRITE_ONCE(kb->tx_pending, false)
memcpy(resp, kb->resp, n) <-- torn read

Because no lock serializes pogo_handle_frame() with pogo_xfer() and pogo_handle_frame() does not clear kb->tx_pending, a second matching frame can overwrite kb->resp and kb->resp_len while pogo_xfer() is reading them. Also, re-arming kb->tx_pending before writing the retry frame allows a late echo or reply from the previous attempt to complete echo_done or resp_done during the 450 us TX gate delay or UART write.

[ ... ]

drivers/input/keyboard/oneplus-pogo-kbd.c line 638

Quoted 6 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +6 -0
+	input_set_abs_params(tp, ABS_MT_POSITION_X, 0, kb->hw->tp_max_x, 0, 0);
+	input_set_abs_params(tp, ABS_MT_POSITION_Y, 0, kb->hw->tp_max_y, 0, 0);
+	input_abs_set_res(tp, ABS_MT_POSITION_X, kb->hw->tp_res_x);
+	input_abs_set_res(tp, ABS_MT_POSITION_Y, kb->hw->tp_res_y);
+	ret = input_mt_init_slots(tp, POGO_TOUCH_FINGERS,
+				  INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED);

[Severity: Medium]
Does pogo_register_inputs() need to register ABS_MT_TOOL_TYPE on tp?

pogo_report_touchpad() decodes MT_TOOL_PALM vs MT_TOOL_FINGER and passes it to input_mt_report_slot_state(), which emits EV_ABS / ABS_MT_TOOL_TYPE. Because input_set_abs_params(tp, ABS_MT_TOOL_TYPE, 0, MT_TOOL_PALM, 0, 0) is not called here, ABS_MT_TOOL_TYPE is not set in tp->absbit and the input core drops all tool type events, disabling palm rejection.

[ ... ]

Quoted 19 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +19 -0
+static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len)
+{
+	bool replug = false;
+
+	if (len < 2)
+		return;
+
+	if (p[0] == OWB_SYNC_PLUG_IN && p[1] == 0x02 && len >= 9) {
+		kb->brand = p[2];
+		memcpy(kb->mac, &p[3], POGO_MAC_LEN);
+		/*
+		 * The MCU repeats this frame until the host has talked to it;
+		 * only a plug-in frame after regular heartbeats is a re-plug.
+		 */
+		replug = kb->connected && kb->hb_seen;
+	} else if (p[0] == OWB_SYNC_HEARTBEAT && p[1] == 0x02 && len >= 10) {
+		kb->brand = p[3];
+		memcpy(kb->mac, &p[4], POGO_MAC_LEN);
+		kb->hb_seen = true;

drivers/input/keyboard/oneplus-pogo-kbd.c line 715

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+	}
+
+	if (!kb->connected || replug) {
+		kb->connected = true;
+		kb->hb_seen = false;
+		kb->retry_ms = POGO_RETRY_MIN_MS;
+		if (!READ_ONCE(kb->quitting))
+			schedule_work(&kb->plug_work);
+	}
+}

[Severity: Medium]
Can a queued sync frame arriving during pogo_power_off() leave kb->connected stuck at true while the keyboard is powered off?

CPU0 (hb_work) CPU1 (serdev RX)
pogo_power_off()
mutex_lock(&kb->state_lock)
kb->connected = false
kb->powered = false
mutex_unlock(&kb->state_lock)

                                        pogo_handle_sync()
                                          if (!kb->connected)
                                            kb->connected = true
                                            schedule_work(&kb->plug_work)
pogo_plug_work()
  if (!kb->powered)
    return;  <-- kb->connected remains true while powered off

pogo_handle_sync() mutates kb->connected and kb->hb_seen without holding kb->state_lock or checking kb->powered, so sysfs connected_show() stays 1 and pogo_backlight_set() / pogo_led_work() issue timing-out UART transfers to an unpowered device.

In addition, if a 0x2F frame does not match either the OWB_SYNC_PLUG_IN or OWB_SYNC_HEARTBEAT branch, pogo_handle_sync() falls through and marks kb->connected = true with uninitialized brand and MAC. Finally, neither pogo_power_off() nor pogo_power_on() resets kb->in_frame or kb->sync_cnt, so powering off mid-frame corrupts the first frame after re-attach.

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +3 -0
+
+static void pogo_handle_frame(struct pogo_kbd *kb, const u8 *f, unsigned int n)
+{

[ ... ]

Quoted 7 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +7 -0
+	default:
+		if (cmd == OWB_CMD_GENERAL_ACK && len >= 4 &&
+		    payload[0] == OWB_GEN_BATTERY_STATUS)
+			kb->battery_level = payload[2];
+
+		if (READ_ONCE(kb->tx_pending) && cmd == kb->tx_cmd + 1) {
+			/* reply layout for callers: cmd, len, payload */

drivers/input/keyboard/oneplus-pogo-kbd.c line 775

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+			kb->resp_len = min_t(unsigned int, len + 2, sizeof(kb->resp));
+			memcpy(kb->resp, &f[3], kb->resp_len);
+			complete(&kb->resp_done);
+		} else {
+			dev_dbg(kb->dev, "unhandled frame cmd 0x%02x len %u\n",
+				cmd, len);
+		}
+		break;
+	}
+}

[Severity: Medium]
Should unsolicited OWB_GEN_BATTERY_STATUS frames break out of the switch instead of falling through to the command reply completion?

When pogo_set_general() sends OWB_CMD_GENERAL (0x3A), kb->tx_cmd + 1 is OWB_CMD_GENERAL_ACK (0x3B). If the MCU pushes an unsolicited 0x3B / 0x0E battery status frame while pogo_set_general() is waiting for its 0x3B ACK, falling through copies the battery frame into kb->resp and completes kb->resp_done, causing pogo_set_general() to see resp[2] != sub and abort with -EPROTO.

[ ... ]

Quoted 18 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +18 -0
+static void pogo_detect_work(struct work_struct *work)
+{
+	struct pogo_kbd *kb = container_of(work, struct pogo_kbd,
+					   detect_work.work);
+
+	int i;
+
+	if (READ_ONCE(kb->quitting) || kb->powered)
+		return;
+
+	/* the unpowered keyboard holds the wire low; require a stable level */
+	for (i = 0; i < POGO_DETECT_SAMPLES; i++) {
+		if (!gpiod_get_value_cansleep(kb->wake_gpio))
+			break;
+		msleep(POGO_DETECT_SAMPLE_MS);
+	}
+	if (i == POGO_DETECT_SAMPLES) {
+		pogo_power_on(kb);

drivers/input/keyboard/oneplus-pogo-kbd.c line 939

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+		return;
+	}
+
+	kb->retry_ms = POGO_RETRY_MIN_MS;
+	pogo_wake_irq_enable(kb, true);
+	/* the edge may have happened before the irq was armed */
+	if (!READ_ONCE(kb->quitting) && gpiod_get_value_cansleep(kb->wake_gpio))
+		mod_delayed_work(system_dfl_wq, &kb->detect_work,
+				 msecs_to_jiffies(POGO_DETECT_DEBOUNCE_MS));
+}

[Severity: High]
Does the reschedule path after pogo_wake_irq_enable(kb, true) leave wake_irq enabled when the keyboard powers on?

If the initial sampling loop exits early because the attach edge arrives just before the loop finishes, pogo_detect_work() enables wake_irq, sees wake_gpio active, and reschedules detect_work without disabling wake_irq. Because the attached keyboard holds wake_gpio steadily active, no new falling edge fires pogo_wake_isr(), and the next run of pogo_detect_work() reaches i == POGO_DETECT_SAMPLES and calls pogo_power_on() with wake_irq still enabled on the shared 921600-baud UART wire.

[Severity: Low]
Also in pogo_detect_work(), gpiod_get_value_cansleep() can return a negative errno, which both boolean checks treat as an active wake line and use to power on the keyboard or reschedule detect_work.

[ ... ]

drivers/input/keyboard/oneplus-pogo-kbd.c line 977

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+static void pogo_plug_work(struct work_struct *work)
+{
+	struct pogo_kbd *kb = container_of(work, struct pogo_kbd, plug_work);
+	int ret;
+
+	if (READ_ONCE(kb->quitting) || !kb->powered || !kb->connected)
+		return;
+
+	if (!kb->kbd) {
+		ret = pogo_register_inputs(kb);

[Severity: Medium]
When a re-plug sync frame arrives while kb->kbd is already registered, should pogo_plug_work() release active keys and touchpad contacts?

If the MCU resets or the pogo pins bounce briefly and send a new OWB_SYNC_PLUG_IN frame before the 500 ms heartbeat timeout expires, pogo_plug_work() skips pogo_register_inputs() and keeps the existing input devices without calling pogo_release_all(kb), leaving any key or touch held across the reset stuck down.

[ ... ]

Quoted 5 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +5 -0
+static void pogo_remove(struct serdev_device *serdev)
+{
+	struct pogo_kbd *kb = serdev_device_get_drvdata(serdev);
+
+	/*

drivers/input/keyboard/oneplus-pogo-kbd.c line 1222

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+	 * Stop the world first: with quitting set, the RX path and the
+	 * works stop queueing each other, so the cancels below cannot be
+	 * undone again.  The wake IRQ is disabled (and any in-flight ISR
+	 * finished) before detect_work is cancelled.
+	 */
+	WRITE_ONCE(kb->quitting, true);
+	pogo_wake_irq_enable(kb, false);
+	cancel_delayed_work_sync(&kb->detect_work);
+	cancel_delayed_work_sync(&kb->hb_work);
+	cancel_work_sync(&kb->plug_work);

[Severity: High]
Can pogo_wake_isr() race with pogo_remove() on kb->wake_irq_enabled and re-queue detect_work after cancel_delayed_work_sync()?

CPU0 CPU1 (<hardirq>)

                                        pogo_wake_isr()
                                          disable_irq_nosync(irq)
                                          kb->wake_irq_enabled = false
                                          if (!READ_ONCE(kb->quitting))

pogo_remove()
WRITE_ONCE(kb->quitting, true)
pogo_wake_irq_enable(kb, false)
if (enable == kb->wake_irq_enabled)
return; /* skips disable_irq() */
cancel_delayed_work_sync(&kb->detect_work)

                                            mod_delayed_work(..., &kb->detect_work, ...)

/* devres frees kb */
pogo_detect_work() <-- use-after-free

Because pogo_wake_isr() clears kb->wake_irq_enabled without locking before checking kb->quitting, pogo_wake_irq_enable(kb, false) sees kb->wake_irq_enabled == false and returns without calling disable_irq() or synchronize_irq(). Conversely, if pogo_wake_irq_enable(kb, false) passes its check just as pogo_wake_isr() fires, both disable_irq_nosync() and disable_irq() run and increment the IRQ disable depth to 2.

In addition, if pogo_detect_work() is already inside its 120 ms sampling loop when pogo_remove() runs, pogo_wake_irq_enable(kb, false) runs before cancel_delayed_work_sync(&kb->detect_work), and pogo_detect_work() does not re-check kb->quitting after the loop before calling pogo_power_on() or pogo_wake_irq_enable(kb, true).

[Severity: High]
Can pogo_hb_work() or pogo_receive_buf() also re-queue work after the cancel_*_work_sync() calls in pogo_remove() and pogo_probe()'s err_shutdown path?

CPU0 CPU1 (kworker)

                                        pogo_hb_work()
                                          pogo_power_off(kb)
                                          if (!READ_ONCE(kb->quitting))

pogo_remove()
WRITE_ONCE(kb->quitting, true)
...
cancel_delayed_work_sync(&kb->detect_work)

                                            schedule_delayed_work(&kb->detect_work, ...)

cancel_delayed_work_sync(&kb->hb_work)
/* devres frees kb */
pogo_detect_work() <-- use-after-free

pogo_hb_work() schedules kb->detect_work, so cancelling detect_work before hb_work allows an in-flight pogo_hb_work() that just passed its quitting check to re-arm detect_work. Similarly, because serdev is opened via devm_serdev_device_open() and stays open until devres teardown runs after pogo_remove() returns, an in-flight pogo_receive_buf() -> pogo_handle_sync() that just passed its quitting check can call schedule_work(&kb->plug_work) after cancel_work_sync(&kb->plug_work) completes; using disable_delayed_work_sync() and disable_work_sync() would prevent post-cancel queueing.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2