Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 3 participants 8 messages Oct 16 – Nov 29

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 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 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 AI agent; 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 |   76 +
 MAINTAINERS                                   |    7 +
 drivers/input/keyboard/Kconfig                |   13 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1263 +++++++++++++++++
 5 files changed, 1360 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 v6 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 common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm) remain as an optional override if a variant ever needs one.

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

Assisted-by Z.ai:GLM-5.3
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 76 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +76 -0
new file mode 100644
index 000000000..78d398912
@@ -0,0 +1,76 @@
+# 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#
+  - $ref: /schemas/input/touchscreen/touchscreen.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
+
+  touchscreen-size-x: true
+  touchscreen-size-y: true
+  touchscreen-x-mm: true
+  touchscreen-y-mm: true
+
+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 8014b9f82..9c29eb961 100644
@@ -20156,6 +20156,12 @@ S:	Maintained
 F:	Documentation/ABI/testing/sysfs-bus-platform-onboard-usb-dev
 F:	drivers/usb/misc/onboard_usb_dev.c
 
+ONEPLUS POGO-PIN KEYBOARD DRIVER
+M:	Yibo Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
+
 ONENAND FLASH DRIVER
 M:	Kyungmin Park <[email protected]>
 L:	[email protected]
Signature · 1 line
2.53.0
#2 lore raw

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] MAINTAINERS: new ONEPLUS entry is inserted out of alphabetical order --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MAINTAINERS: new ONEPLUS entry is inserted out of alphabetical order --

commit a3b7a3bdc211b0789ad103d539fa35e6dcf0f689
Author: Yibo Wang <[email protected]>

dt-bindings: input: add OnePlus pogo-pin keyboard

This commit adds device tree bindings for the OnePlus Pad and OPPO Pad pogo-pin smart keyboards. It defines the required properties for the keyboard MCU attached via UART, and adds the corresponding maintainer entry.

Quoted 5 lines
MAINTAINERS +0 -0
index b8c4e1080af94..d81e400059ced 100644

MAINTAINERS S: Maintained · line 20163

Quoted 10 lines
MAINTAINERS +6 -0
@@ -20154,6 +20154,12 @@ S:	Maintained
 F:	Documentation/ABI/testing/sysfs-bus-platform-onboard-usb-dev
 F:	drivers/usb/misc/onboard_usb_dev.c
 
+ONEPLUS POGO-PIN KEYBOARD DRIVER
+M:	Yibo Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
+
 ONENAND FLASH DRIVER

[Severity: Low]
This isn't a bug, but should this new maintainer entry be placed further down to preserve alphabetical sorting? Since P in ONEPLUS comes after N in ONENAND, inserting it here places it out of alphabetical order, which might trigger warnings from automated sorting checks or checkpatch.

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

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

In reply to [email protected]
Quoted 20 lines · On Fri, Oct 16, 2026 at 11:38:58AM -0500, [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).

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 common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm) remain as an optional override if a variant ever needs one.

Quoted 5 lines

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

Assisted-by Z.ai:GLM-5.3

LLM

Quoted 57 lines
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 76 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +44 -0
new file mode 100644
index 000000000..78d398912
@@ -0,0 +1,76 @@
+# 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#
+  - $ref: /schemas/input/touchscreen/touchscreen.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.

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+    maxItems: 1
+
+  wake-gpios:
+    description: GPIO signalling attach/detach, also used as the wake line.
+    maxItems: 1
+
+  touchscreen-size-x: true
+  touchscreen-size-y: true
+  touchscreen-x-mm: true
+  touchscreen-y-mm: true

We agreed to drop all these.

Quoted 27 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +22 -0
+
+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 +0 -0
index 8014b9f82..9c29eb961 100644

MAINTAINERS S: Maintained · line 20159

Quoted 4 lines
MAINTAINERS +1 -0
@@ -20156,6 +20156,12 @@ S:	Maintained
 F:	Documentation/ABI/testing/sysfs-bus-platform-onboard-usb-dev
 F:	drivers/usb/misc/onboard_usb_dev.c
 
+ONEPLUS POGO-PIN KEYBOARD DRIVER

P > N

MAINTAINERS S: Maintained · line 20165

Quoted 6 lines
MAINTAINERS +5 -0
+M:	Yibo Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
+
 ONENAND FLASH DRIVER

Best regards,
Krzysztof

#4 lore raw

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

From: Yibo Wang <[email protected]>

Hi Krzysztof,

Quoted 1 line · Krzysztof Kozlowski

LLM

Done, the prose now says LLM.

Quoted 1 line

We agreed to drop all these.

Dropped, together with the touchscreen.yaml reference; the driver does not parse them from DT either, the geometry is pure per-project match data now.

Quoted 1 line

P > N

Moved after ONENAND.

v7 sent as a new thread.

Best regards,
Yibo

#5 lore raw

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

Quoted 8 lines · On 28/11/2026 09:18, [email protected] wrote:

From: Yibo Wang <[email protected]>

Hi Krzysztof,

Quoted 1 line · Krzysztof Kozlowski

LLM

Done, the prose now says LLM.

That was a month ago.

Drop the tag completely now.

Best regards,
Krzysztof

#6 lore raw

PATCH v6 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 common touchscreen DT properties parsed by touchscreen_parse_properties() remain as an optional override. 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 | 1263 +++++++++++++++++++++
 4 files changed, 1278 insertions(+)
 create mode 100644 drivers/input/keyboard/oneplus-pogo-kbd.c
MAINTAINERS +1 -0
index 9c29eb961..d2b83a637 100644
@@ -20161,6 +20161,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
 
 ONENAND FLASH DRIVER
 M:	Kyungmin Park <[email protected]>
drivers/input/keyboard/Kconfig +13 -0
index 9d1019ba0..011b9248b 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 60bb7baf8..3554c5011 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 +1263 -0

1,263 lines not on this page · raw message

Signature · 1 line
2.53.0
#7 lore raw

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

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] input: use-after-free in work queues due to lockless removal races - [Medium] input: silent…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] input: use-after-free in work queues due to lockless removal races
- [Medium] input: silent truncation of maximum-length responses in kb->resp
- [Medium] input: oneplus-pogo: data race on kb->resp buffer in pogo_xfer
- [Medium] input: oneplus-pogo-kbd: Data race on kb->connected state variables --

commit 55459b7da977a6dfb82c08f24907cc60a6e32cd0
Author: Yibo Wang <[email protected]>

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

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.

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

[ ... ]

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +3 -0
+static int pogo_xfer(struct pogo_kbd *kb, u8 cmd, const u8 *payload, u8 len,
+		     u8 *resp, unsigned int resp_size)
+{

[ ... ]

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

Quoted 11 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +11 -0
+		if (!resp) {
+			ret = 0;
+			break;
+		}
+		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);

[Severity: Medium]
Can this lead to a data race on the kb->resp buffer?

If a delayed reply from a previous attempt completes kb->resp_done early, pogo_xfer() wakes up, sets tx_pending to false, and starts reading kb->resp. Concurrently, the RX thread in pogo_handle_frame() may receive the reply for the current attempt, evaluate tx_pending as true, and overwrite kb->resp via memcpy() while pogo_xfer() is reading it.

This torn read could cause spurious -EPROTO initialization failures.

[ ... ]

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +3 -0
+static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len)
+{
+	bool replug = false;

[ ... ]

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

Quoted 7 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +7 -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]
Is it safe to modify kb->connected here without holding kb->state_lock?

In pogo_power_off(), kb->connected and kb->powered are cleared under kb->state_lock. If pogo_power_off() races with this RX path, this lockless modification can leave the driver permanently desynchronized.

If pogo_power_off() sets powered = false and connected = false, and a delayed UART sync frame is processed here concurrently, this path will locklessly set connected = true. The subsequent schedule_work(&kb->plug_work) will exit early because powered is false, leaving connected = true while powered is false.

[ ... ]

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

[ ... ]

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

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +4 -0
+		if (READ_ONCE(kb->tx_pending) && cmd == kb->tx_cmd + 1) {
+			/* reply layout for callers: cmd, len, payload */
+			kb->resp_len = min_t(unsigned int, len + 2, sizeof(kb->resp));
+			memcpy(kb->resp, &f[3], kb->resp_len);

[Severity: Medium]
Does this truncate maximum-length responses?

The kb->resp buffer is sized to OWB_MAX_PAYLOAD (128 bytes). By adding 2 to len (for cmd and len), a maximum payload of 128 bytes yields len + 2 = 130. The min_t() will cap this at sizeof(kb->resp) (128), which silently truncates the last 2 bytes of the payload.

[ ... ]

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 1234

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 this teardown sequence lead to a use-after-free of the work queues?

If pogo_wake_isr() is currently executing and has already called disable_irq_nosync(), kb->wake_irq_enabled will be false.

When pogo_remove() calls pogo_wake_irq_enable(kb, false), it will hit the early return:

    if (enable == kb->wake_irq_enabled)
        return;

This bypasses the disable_irq() synchronization barrier. Because pogo_wake_isr() checks kb->quitting without a lock, the ISR could observe quitting == false before pogo_remove() sets it, but queue the delayed work after pogo_remove() has already completed the cancellations, resulting in a use-after-free.

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