Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 4 participants 33 messages Oct 9 – Oct 16

Subsystems (3)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

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.

Patch 1 adds the DT binding for the "oneplus,pogo-keyboard" device, describing the supply, TX-gate and wake GPIOs and the touchpad geometry, with a MAINTAINERS entry.

Patch 2 adds the driver: keyboard matrix, touchpad, function and URL keys, caps-lock LED, attach detection through the wake GPIO plus a 100 ms heartbeat timeout, and the keyboard backlight as a "pogo-keyboard::kbd_backlight" LED class device so UPower and the desktop keyboard-backlight controls drive it through the standard interface (the level is cached while detached and restored on re-attach). A sysfs battery level is exported for the keyboards that carry a battery.

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

---

 .../bindings/input/oneplus,pogo-keyboard.yaml |   81 ++
 MAINTAINERS                                   |    7 +
 drivers/input/keyboard/Kconfig                |   11 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1109 +++++++++++++++++
 5 files changed, 1209 insertions(+)
Signature · 1 line
2.53.0
#1 lore raw

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

From: Yibo Wang <[email protected]>

Binding for the Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro smart keyboards, attached to a tablet UART. Describes the supply, TX-gate and wake GPIOs and the touchpad geometry properties, with a MAINTAINERS entry.

---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 81 +++++++++++++++++++
 MAINTAINERS                                   |  7 ++
 2 files changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +81 -0
new file mode 100644
index 000000000..849558458
@@ -0,0 +1,81 @@
+# 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 Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO
+  Pad 5 Pro smart keyboards.  It 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.  The device provides a keyboard matrix, a touchpad and a
+  keyboard backlight.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: oneplus,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
+
+  touchpad-xy-max:
+    description: Touchpad maximum X and Y coordinates in units.
+    items:
+      - description: maximum X
+      - description: maximum Y
+    minItems: 2
+    maxItems: 2
+
+  touchpad-xy-resolution:
+    description: Touchpad X and Y resolution in units per millimetre.
+    items:
+      - description: X resolution
+      - description: Y resolution
+    minItems: 2
+    maxItems: 2
+
+required:
+  - compatible
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    serial {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        keyboard {
+            compatible = "oneplus,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>;
+            touchpad-xy-max = <2560 1440>;
+            touchpad-xy-resolution = <24 25>;
+        };
+    };
+...
MAINTAINERS +7 -0
index 8014b9f82..e978a26c1 100644
@@ -20149,6 +20149,13 @@ S:	Maintained
 T:	git git://linuxtv.org/media.git
 F:	drivers/media/i2c/ov9734.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
+F:	drivers/input/keyboard/oneplus-pogo-kbd.c
+
 ONBOARD USB HUB DRIVER
 M:	Matthias Kaehlcke <[email protected]>
 L:	[email protected]
Signature · 1 line
2.53.0
#2 lore raw

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

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Low] dt-bindings: missing vendor prefix and reuse of standard touchscreen properties - [Low]…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Low] dt-bindings: missing vendor prefix and reuse of standard touchscreen properties
- [Low] dt-bindings: custom array properties missing type $ref
- [Low] dt-bindings: additionalProperties: false incorrectly used with allOf $ref
- [Low] dt-bindings: unnecessary #address-cells and #size-cells in example
- [Low] MAINTAINERS: alphabetical ordering violation
--

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

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

Binding for the Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro smart keyboards, attached to a tablet UART.

Quoted 7 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +1 -0
new file mode 100644
index 0000000000000..3086a2c4e2895
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

[ ... ]

Quoted 6 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +6 -0
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+
+properties:
+  compatible:
+    const: oneplus,pogo-keyboard

[ ... ]

Quoted 5 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +5 -0
+  touchpad-xy-max:
+    description: Touchpad maximum X and Y coordinates in units.
+    items:
+      - description: maximum X
+      - description: maximum Y

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
+    minItems: 2
+    maxItems: 2
+
+  touchpad-xy-resolution:
+    description: Touchpad X and Y resolution in units per millimetre.
+    items:
+      - description: X resolution
+      - description: Y resolution
+    minItems: 2
+    maxItems: 2

[Severity: Low]
Does this bypass the standard touchscreen properties? The binding could reuse properties from touchscreen.yaml, such as touchscreen-size-x, touchscreen-size-y, touchscreen-x-mm, and touchscreen-y-mm, rather than introducing custom variations.

If custom properties are strictly necessary here, should they include a vendor prefix like oneplus,touchpad-xy-max?

Additionally, since these custom properties define an items array, do they also need an explicit type reference (such as
$ref: /schemas/types.yaml#/definitions/uint32-array)? Without a standard suffix, device tree schema tools might fail meta-schema validation because they cannot automatically infer the type.

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

Quoted 8 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +8 -0
+
+required:
+  - compatible
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios
+
+additionalProperties: false

[Severity: Low]
Does this strict constraint incorrectly override the referenced schema?

Because the schema imports serial-peripheral-props.yaml via the allOf block, JSON schema evaluation will not account for those imported properties under additionalProperties. Does this cause valid serial properties (like max-speed) to be incorrectly rejected?

Could this be resolved by using unevaluatedProperties: false instead?

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    serial {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        keyboard {

[Severity: Low]
Since the child keyboard node omits a reg property because it is a simple point-to-point UART peripheral, are #address-cells and #size-cells needed on the parent node?

Could this trigger the avoid_unnecessary_addr_size dtc warning during make dt_binding_check?

Quoted 16 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +9 -0
+            compatible = "oneplus,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>;
+            touchpad-xy-max = <2560 1440>;
+            touchpad-xy-resolution = <24 25>;
+        };
+    };
+...
MAINTAINERS +0 -0
index b8c4e1080af94..d0adba45c8f0b 100644
@@ -20147,6 +20147,13 @@ S:	Maintained
 T:	git git://linuxtv.org/media.git

MAINTAINERS S: Maintained · line 20157

Quoted 10 lines
MAINTAINERS +7 -0
 F:	drivers/media/i2c/ov9734.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
+F:	drivers/input/keyboard/oneplus-pogo-kbd.c
+
 ONBOARD USB HUB DRIVER

[Severity: Low]
Should ONEPLUS POGO-PIN KEYBOARD DRIVER be placed after ONBOARD USB HUB DRIVER?

Alphabetically, ONEPLUS comes after ONBOARD, so inserting it here appears to break the alphabetical ordering requested by the MAINTAINERS file.

Quoted 2 lines
MAINTAINERS +0 -0
 M:	Matthias Kaehlcke <[email protected]>
 L:	[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

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

In reply to [email protected]

On 09/10/2026 14:20, [email protected] wrote:

A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings.
See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

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

Quoted 7 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +7 -0
+  touchpad-xy-max:
+    description: Touchpad maximum X and Y coordinates in units.
+    items:
+      - description: maximum X
+      - description: maximum Y
+    minItems: 2
+    maxItems: 2

None of this was tested. Anyway, use existing properties from touchscreen schema for example or actually better explain why this is not deducible from the compatible.

Quoted 14 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +14 -0
+
+  touchpad-xy-resolution:
+    description: Touchpad X and Y resolution in units per millimetre.
+    items:
+      - description: X resolution
+      - description: Y resolution
+    minItems: 2
+    maxItems: 2
+
+required:
+  - compatible
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    serial {
+        #address-cells = <1>;
+        #size-cells = <0>;

Drop node

Quoted 16 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +11 -0
+
+        keyboard {
+            compatible = "oneplus,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>;
+            touchpad-xy-max = <2560 1440>;
+            touchpad-xy-resolution = <24 25>;
+        };
+    };
+...
MAINTAINERS +0 -0
index 8014b9f82..e978a26c1 100644

MAINTAINERS S: Maintained · line 20157

Quoted 9 lines
MAINTAINERS +6 -0
@@ -20149,6 +20149,13 @@ S:	Maintained
 T:	git git://linuxtv.org/media.git
 F:	drivers/media/i2c/ov9734.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
+F:	drivers/input/keyboard/oneplus-pogo-kbd.c

There is no such file.

MAINTAINERS S: Maintained · line 20161

Quoted 4 lines
MAINTAINERS +1 -0
+
 ONBOARD USB HUB DRIVER
 M:	Matthias Kaehlcke <[email protected]>
 L:	[email protected]

Best regards,
Krzysztof

#4 lore raw

PATCH 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.

DT binding for the "oneplus,pogo-keyboard" device is added along with a MAINTAINERS entry.

---
 drivers/input/keyboard/Kconfig            |   11 +
 drivers/input/keyboard/Makefile           |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c | 1109 +++++++++++++++++++++
 3 files changed, 1121 insertions(+)
 create mode 100644 drivers/input/keyboard/oneplus-pogo-kbd.c
drivers/input/keyboard/Kconfig +11 -0
index 9d1019ba0..ced2a2174 100644
@@ -806,4 +806,15 @@ 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
+	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 +1109 -0

1,109 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

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

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] input: UAF in led_work due to teardown ordering - [High] serdev: UAF in plug_work due to active…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] input: UAF in led_work due to teardown ordering
- [High] serdev: UAF in plug_work due to active port during devres teardown
- [High] workqueue: UAF due to detect_work and hb_work cyclic dependency
- [High] workqueue: UAF due to pogo_wake_irq_enable missing synchronize_irq
- [High] input: Race between plug_work and power_off leaks input devices
- [Low] leds: Success logging in probe violates guidelines
--

commit 0ce1872d7cb39e14970c678cd47393649379aea8
Author: Yibo Wang <[email protected]>

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

Adds a serdev driver for the Tinno keyboard MCU used by OnePlus and OPPO Pad smart keyboards. Communication happens over a half-duplex UART using a custom framed protocol. The driver exposes touchpad, keys, and backlight controls to userspace.

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

Quoted 9 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
index 0000000000000..589f31ecef848
@@ -778,7 +778,7 @@
 static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable)
 {
 	if (enable == kb->wake_irq_enabled)
 		return;

[Severity: High]
If pogo_wake_isr() fires concurrently, sets kb->wake_irq_enabled = false, and then pogo_remove() calls pogo_wake_irq_enable(kb, false), will this return early and bypass disable_irq()?

Since disable_irq() also acts as a synchronize_irq(), missing it might allow the preempted ISR to resume and queue detect_work after it has already been cancelled in pogo_remove().

[ ... ]

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

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

[Severity: High]
Can a race between pogo_plug_work() and pogo_power_off() leak input devices?

If pogo_plug_work() evaluates kb->connected as true, and concurrently pogo_power_off() sets kb->connected = false (unregistering nothing since kb->kbd is still NULL):

- pogo_plug_work() would then allocate and register the input devices.
- The state becomes desynchronized: kb->connected is false, but devices are registered.

When the driver unbinds, pogo_remove() calls pogo_power_off(), which will skip unregistering the devices because kb->connected is false. Will this leave the input devices leaked and pointing to freed memory?

[ ... ]

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

Quoted 6 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -1074,6 +1074,6 @@
 	/* evaluate the current attach state; enables the irq when idle */
 	schedule_delayed_work(&kb->detect_work,
 			      msecs_to_jiffies(POGO_DETECT_DEBOUNCE_MS));
 
 	dev_info(dev, "pogo keyboard link ready (wake irq %d)\n", kb->wake_irq);

[Severity: Low]
This isn't a bug, but does this success log violate the LED subsystem guidelines? The guidelines suggest only logging errors or warnings during probe, to avoid cluttering the kernel log with success messages.

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
 	return 0;

}

[ ... ]

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

Quoted 8 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -1084,7 +1084,7 @@
 static void pogo_remove(struct serdev_device *serdev)
 {
 	struct pogo_kbd *kb = serdev_device_get_drvdata(serdev);
 
 	pogo_wake_irq_enable(kb, false);
 	cancel_delayed_work_sync(&kb->detect_work);
 	cancel_delayed_work_sync(&kb->hb_work);

[Severity: High]
Because detect_work and hb_work can queue each other, and neither checks a shared teardown flag (like kb->going_away), could hb_work re-arm detect_work after detect_work was cancelled?

If hb_work is running concurrently during pogo_remove():
1. cancel_delayed_work_sync() for detect_work returns.
2. hb_work calls schedule_delayed_work() for detect_work.
3. cancel_delayed_work_sync() for hb_work waits for hb_work to finish.

This leaves detect_work pending after pogo_remove() returns, which would lead to a use-after-free when devres frees the kb structure.

Quoted 1 line

cancel_work_sync(&kb->plug_work);

[Severity: High]
Since the serdev port is managed by devm_serdev_device_open(), the UART receiver remains active until devres cleanup, which executes after pogo_remove() returns.

Could an incoming UART frame trigger pogo_handle_sync() and re-queue plug_work after this cancellation? If the work remains queued after devres frees the kb memory, it would cause a use-after-free.

Similarly, if pogo_probe() fails after devm_serdev_device_open(), could an incoming frame schedule the work on the error path where it is never cancelled? Does the UART receiver need to be closed or the callback disabled prior to work cancellation?

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

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
 	cancel_work_sync(&kb->led_work);
 	pogo_power_off(kb);

[Severity: High]
Because pogo_power_off(kb) is called after cancelling led_work, the input devices are still fully registered and active during cancellation.

Can a concurrent EV_LED event routed by the input core trigger pogo_kbd_event(), which unconditionally calls schedule_work() for led_work? If led_work is re-armed after it was cancelled, it will execute on freed memory once devres cleans up. Should the input devices be unregistered before cancelling led_work?

Quoted 1 line

}

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

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

In reply to [email protected]

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.

Patch 1 adds the DT binding for the "oneplus,pogo-keyboard" device, describing the supply, TX-gate and wake GPIOs, with a MAINTAINERS entry.

Patch 2 adds the driver: keyboard matrix, touchpad, function and URL keys, caps-lock LED, attach detection through the wake GPIO plus a 100 ms heartbeat timeout, and the keyboard backlight as a "pogo-keyboard::kbd_backlight" LED class device so UPower and the desktop keyboard-backlight controls drive it through the standard interface (the level is cached while detached and restored on re-attach). A sysfs battery level is exported for the keyboards that carry a battery.

Changes in v2, addressing Krzysztof Kozlowski's review of the binding:

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

- replaced the custom oneplus,touchpad-xy-max/-resolution properties with the common touchscreen properties touchscreen-size-x/y and touchscreen-x-mm/y-mm, parsed with touchscreen_parse_properties() in the driver: the MCU protocol has no way to query the touchpad geometry and the same MCU is shipped in keyboards with different touchpad matrices, so the geometry stays in DT but uses the common schema instead of vendor 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).

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 |   66 +
 MAINTAINERS                                   |    7 +
 drivers/input/keyboard/Kconfig                |   13 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1196 +++++++++++++++++
 5 files changed, 1283 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
#7 lore raw

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

From: Yibo Wang <[email protected]>

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

The touchpad is described through the common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm): the MCU protocol has no way to query the touchpad geometry and the same MCU is shipped in keyboards with different touchpad matrices.

---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 66 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +66 -0
new file mode 100644
index 000000000..9055ececc
@@ -0,0 +1,66 @@
+# 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 Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO
+  Pad 5 Pro smart keyboards.  It 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.  The device 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:
+    const: oneplus,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>
+
+    keyboard {
+        compatible = "oneplus,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>;
+        touchscreen-size-x = <2561>;
+        touchscreen-size-y = <1441>;
+    };
+...
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
#8 lore raw

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] dt-bindings: missing required touchscreen geometry properties - [Low] dt-bindings: MAINTAINERS…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] dt-bindings: missing required touchscreen geometry properties
- [Low] dt-bindings: MAINTAINERS entry is not sorted alphabetically
--

commit 6f38b36d3e9ba3bf27f192d07af31696c6e0fdc1
Author: Yibo Wang <[email protected]>

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

This commit introduces a device tree binding for the Tinno keyboard MCU used by OnePlus and OPPO smart keyboards. It specifies the properties for power, transmit gating, and wake GPIOs, along with common touchscreen attributes.

Quoted 4 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +0 -0
index 0000000000000..9055ececc04cb

[ ... ]

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

Quoted 5 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +5 -0
+required:
+  - compatible
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios

[Severity: Medium]
The commit message states that the MCU protocol has no way to query the touchpad geometry, meaning the driver strictly requires the touchscreen-size-x and touchscreen-size-y properties to function properly.

Should these properties be added to the required array?

Leaving them out might allow incomplete device tree nodes missing the dimensions to silently pass schema validation, which could then lead to runtime failures or misconfigured touchpad coordinates when the driver probes.

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

[ ... ]

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

[ ... ]

MAINTAINERS S: Maintained · line 20163

Quoted 11 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 ONEPLUS POGO-PIN KEYBOARD DRIVER be placed after ONENAND FLASH DRIVER?

Alphabetically, P comes after N. Breaking alphabetical sorting in the MAINTAINERS file can cause script warnings with parse-maintainers.pl and may lead to future merge conflicts.

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

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

In reply to [email protected]
Quoted 10 lines · On Sat, Oct 10, 2026 at 09:38:35AM -0500, [email protected] wrote:

From: Yibo Wang <[email protected]>

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

The touchpad is described through the common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm): the MCU protocol has no way to query the touchpad geometry and the same MCU is shipped in keyboards with different touchpad matrices.

How is that possible? Same OnePlus Pad 3 Pro has different matrices?

Best regards,
Krzysztof

#10 lore raw

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

From: Yibo Wang <[email protected]>

Hi Krzysztof,

Quoted 1 line · Krzysztof Kozlowski

How is that possible? Same OnePlus Pad 3 Pro has different matrices?

No, and sorry for the wording - within one tablet project the keyboard is fixed. What I meant is that the matrices differ *between* the tablet projects that ship this MCU, not within one: the vendor trees carry per-project geometry (caihong, the sm8650 era project: 2764x1630; erhai, the sm8750 era project: 2764x1630; iceland, the sm8850 era project the tested OnePlus Pad 4 belongs to: 2560x1440), while the MCU protocol has no command to query them.

Which also means your question from v1 is answered the other way
around: the geometry *is* deducible from the compatible once the compatible names the project. v3 therefore drops the DT geometry entirely:

- the compatible names the tablet project (oneplus,caihong-/erhai-/iceland-pogo-keyboard, the codenames from the vendor trees) and the driver carries a per-project description in its match data: feature flags for the 0x3A sub-commands that grew over the generations, the touchpad geometry and the per-brand product names;

- the common touchscreen properties (touchscreen-size-x/y, touchscreen-x-mm/y-mm) are kept only as an optional override, in case a variant ever needs one, and are no longer used by the example.

v3 will follow as a reply to the cover letter.

Best regards,
Yibo

#11 lore raw

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

Quoted 15 lines · On Wed, Oct 14, 2026 at 08:47:54AM -0500, [email protected] wrote:

From: Yibo Wang <[email protected]>

Hi Krzysztof,

Quoted 1 line · Krzysztof Kozlowski

How is that possible? Same OnePlus Pad 3 Pro has different matrices?

No, and sorry for the wording - within one tablet project the keyboard is fixed. What I meant is that the matrices differ *between* the tablet projects that ship this MCU, not within one: the vendor trees carry per-project geometry (caihong, the sm8650 era project: 2764x1630; erhai, the sm8750 era project: 2764x1630; iceland, the sm8850 era project the tested OnePlus Pad 4 belongs to: 2560x1440), while the MCU protocol has no command to query them.

Quoted 4 lines

Which also means your question from v1 is answered the other way
around: the geometry *is* deducible from the compatible once the compatible names the project. v3 therefore drops the DT geometry entirely:

I don't think we are describing here the MCU, but the keyboard, thus it''s physical geometry is fixed.

Best regards,
Krzysztof

#12 lore raw

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

From: Yibo Wang <[email protected]>

Hi Krzysztof,

Quoted 2 lines · On Wed, Oct 14, 2026 at ... Krzysztof Kozlowski wrote:

I don't think we are describing here the MCU, but the keyboard, thus it's physical geometry is fixed.

Agreed - the node binds the keyboard, and a keyboard's geometry is fixed with the hardware. That is exactly why v3 does not describe it in DT at all: the touchpad geometry and the product names are per-compatible constants in the driver's match data. I also reworded the binding to describe the keyboard (built around the Tinno MCU) rather than the MCU itself, and the touchscreen properties remain only as an optional override for the unlikely case of a variant.

The rewording will be folded into v4, which follows as a reply to the v3 cover letter.

Best regards,
Yibo

#13 lore raw

PATCH v2 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 touchpad geometry defaults to the tested OnePlus Pad 4 keyboard and can be overridden with the standard touchscreen DT properties parsed by touchscreen_parse_properties(). 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 | 1196 +++++++++++++++++++++
 4 files changed, 1211 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 +1196 -0

1,196 lines not on this page · raw message

Signature · 1 line
2.53.0
#14 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] input: UAF due to lockless quitting checks and incorrect work cancellation order - [Medium] input…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] input: UAF due to lockless quitting checks and incorrect work cancellation order
- [Medium] input: Data race on link state variables due to missing state_lock in RX path
- [Medium] input: Race condition and missing memory barriers in TX/RX completion logic --

commit 6e3d28332505730268c90370cf0f07792b89214b
Author: Yibo Wang <[email protected]>

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

This adds a serdev driver for the Tinno keyboard MCU used by OnePlus/OPPO Pad smart keyboards. It implements a framed protocol over a half-duplex UART for input events, heartbeat, and backlight control.

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
index 0000000000000..298f0eff52116

[ ... ]

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)
+{

[ ... ]

Quoted 5 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +5 -0
+	mutex_lock(&kb->io_lock);
+	for (attempt = 0; attempt < POGO_XFER_RETRIES; attempt++) {
+		bool echoed;
+
+		/*

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

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+		 * 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);

[Severity: Medium]
Since WRITE_ONCE does not emit a hardware memory barrier, could the CPU reorder these stores on weakly-ordered architectures?

This might allow the RX thread to see tx_pending == true while still reading the old tx_cmd, opening a race condition.

[ ... ]

Quoted 15 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +15 -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;

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

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +10 -0
+	} 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;
+	}
+
+	if (!kb->connected || replug) {
+		kb->connected = true;
+		kb->hb_seen = false;
+		kb->retry_ms = POGO_RETRY_MIN_MS;

[Severity: Medium]
Are these link state variables modified without holding kb->state_lock here?

Because pogo_handle_sync() runs in the RX worker context, it can execute concurrently with workqueues running pogo_power_off() or pogo_power_on(). This data race could corrupt the driver's state machine logic.

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

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +2 -0
+		if (!READ_ONCE(kb->quitting))
+			schedule_work(&kb->plug_work);

[Severity: High]
Does this lockless quitting check allow a use-after-free?

If the RX thread evaluates !READ_ONCE(kb->quitting) as true but is preempted before calling schedule_work(), pogo_remove() might finish cancelling plug_work and return.

The RX thread would then resume and queue plug_work after it has been cancelled, leading to a use-after-free when devres frees kb.

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

[ ... ]

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +2 -0
+	switch (cmd) {
+	case OWB_CMD_KEYS:

[ ... ]

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

Quoted 9 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +9 -0
+	case OWB_CMD_SYNC_UPLOAD:
+		pogo_handle_sync(kb, payload, len);
+		break;
+	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) {

[Severity: Medium]
Is there a missing acquire barrier (smp_load_acquire) when reading tx_pending and tx_cmd here?

Furthermore, since the RX thread's check is not protected by a lock, it could be preempted between evaluating tx_pending and reading tx_cmd, which might result in erroneously completing a new transfer using an old response.

Quoted 11 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +11 -0
+			/* 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);
+			complete(&kb->resp_done);
+		} else {
+			dev_dbg(kb->dev, "unhandled frame cmd 0x%02x len %u\n",
+				cmd, len);
+		}
+		break;
+	}
+}

[ ... ]

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +2 -0
+static void pogo_hb_work(struct work_struct *work)
+{

[ ... ]

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

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +4 -0
+	/* re-arm: retry while the wake line still reports a keyboard */
+	if (!READ_ONCE(kb->quitting))
+		schedule_delayed_work(&kb->detect_work,
+				      msecs_to_jiffies(kb->retry_ms));

[Severity: High]
Could hb_work queue detect_work after it has been cancelled?

Since pogo_remove() cancels detect_work before hb_work, if hb_work executes concurrently with teardown, this lockless check allows schedule_delayed_work() to run after cancel_delayed_work_sync(&kb->detect_work) has completed.

This leaves detect_work permanently queued, leading to another use-after-free when kb is freed.

Quoted 2 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +2 -0
+	kb->retry_ms = min(kb->retry_ms * 2, POGO_RETRY_MAX_MS);
+}

[ ... ]

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 1169

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]
Does this cancellation order correctly prevent works from being queued?

As noted above, cancelling detect_work before hb_work permits hb_work to re-queue detect_work during teardown.

Additionally, the RX path's lockless check against kb->quitting means plug_work can be queued after cancel_work_sync() completes, due to delayed devres serdev closure.

Quoted 7 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +7 -0
+
+	/* unregisters the input devices, the last possible led_work queuer */
+	pogo_power_off(kb);
+
+	/* flush a led_work queued before the inputs went away */
+	cancel_work_sync(&kb->led_work);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#15 lore raw

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

In reply to [email protected]

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 this MCU, from the sm8550 era keyboards 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 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) instead of a DT property, 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().

Changes in v2, addressing Krzysztof Kozlowski's review of the binding:

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

- replaced the custom oneplus,touchpad-xy-max/-resolution properties with the common touchscreen properties: the MCU protocol has no way to query the touchpad geometry and the same MCU is shipped in keyboards with different touchpad matrices;

- 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).

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 |   73 +
 MAINTAINERS                                   |    7 +
 drivers/input/keyboard/Kconfig                |   13 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1263 +++++++++++++++++
 5 files changed, 1357 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
#16 lore raw

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

From: Yibo Wang <[email protected]>

Binding for the Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro smart keyboards, 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 MCU generation and with it the protocol extensions the host may use: the 0x3A general sub-commands grew over time, from the caihong (sm8650 era) MCUs with neither wake notification nor backlight, through erhai (sm8750 era, wake notification) to iceland (sm8850 era, keyboard backlight).

The touchpad geometry and the product names 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 if a variant ever needs one.

---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 73 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +73 -0
new file mode 100644
index 000000000..fa1579ed5
@@ -0,0 +1,73 @@
+# 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 Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO
+  Pad 5 Pro smart keyboards.  It 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.  The device 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 MCU 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>
+
+    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
#17 lore raw

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

Quoted 13 lines · On Wed, Oct 14, 2026 at 08:52:50AM -0500, [email protected] wrote:

From: Yibo Wang <[email protected]>

Binding for the Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro smart keyboards, 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 MCU generation and with it the protocol extensions the host may use: the 0x3A general sub-commands grew over time, from the caihong (sm8650 era) MCUs with neither wake notification nor backlight, through erhai (sm8750 era, wake notification) to iceland (sm8850 era, keyboard backlight).

Quoted 4 lines

The touchpad geometry and the product names 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 if a variant ever needs one.

Why? It's fixed. It cannot be overridden. Your example DTS even shows that.

Quoted 27 lines
---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 73 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +13 -0
new file mode 100644
index 000000000..fa1579ed5
@@ -0,0 +1,73 @@
+# 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: |

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+  The Tinno keyboard MCU used by the OnePlus Pad 3 Pro / Pad 4 and OPPO
+  Pad 5 Pro smart keyboards.  It 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.  The device provides a keyboard matrix, a touchpad and a
+  keyboard backlight.
+
+allOf:
+  - $ref: /schemas/serial/serial-peripheral-props.yaml#
+  - $ref: /schemas/input/touchscreen/touchscreen.yaml#

So this is not really needed, drop

Quoted 20 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +20 -0
+
+properties:
+  compatible:
+    description: |
+      Names the tablet project the pogo port belongs to, which pins the
+      keyboard MCU 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 53

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

Drop all four.

Best regards,
Krzysztof

#18 lore raw

PATCH v3 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
#19 lore raw

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

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] input: incorrect work cancellation order and UART teardown sequence cause UAF - [High] input…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] input: incorrect work cancellation order and UART teardown sequence cause UAF
- [High] input: early return in pogo_wake_irq_enable bypasses teardown synchronization causing UAF
- [Medium] input: data race on link state variables kb->connected and kb->hb_seen
- [Medium] input: spontaneous battery status frames break protocol by masquerading as command replies
- [Low] input: lockless tx_pending synchronization allows late echoes to falsely complete retries --

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

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

This commit adds a serdev driver for the Tinno keyboard MCU used by OnePlus and OPPO smart keyboards. The MCU communicates over a half-duplex UART using a framed protocol. It supports touchpad, function keys, and backlight control.

--- a/drivers/input/keyboard/oneplus-pogo-kbd.c
+++ b/drivers/input/keyboard/oneplus-pogo-kbd.c
[ ... ]

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 358

Quoted 11 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +11 -0
+		/*
+		 * 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);

[Severity: Low]
Does this lockless synchronization for tx_pending allow late echoes to falsely complete retries?

If the UART RX path (pogo_handle_frame) observes tx_pending == true and matches the command, but then stalls just before calling complete(&kb->echo_done), pogo_xfer() could time out and start a new retry. When the RX thread resumes and calls complete(), it would satisfy the new retry's completion with the old echo, potentially masking a real transmission failure.

[ ... ]

Quoted 2 lines
(quoted diff) +2 -0
+static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len)
+{

[ ... ]

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

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +3 -0
+	if (!kb->connected || replug) {
+		kb->connected = true;
+		kb->hb_seen = false;

[Severity: Medium]
Could this modify the link state variables concurrently with pogo_power_off()?

Since pogo_power_off() modifies kb->connected and kb->powered while holding kb->state_lock, but pogo_handle_sync() updates kb->connected and kb->hb_seen here locklessly, the RX thread might clobber the teardown state. This could leave kb->connected = true after the hardware is unpowered, bypassing checks in sysfs interfaces and potentially backfeeding power through the UART pins.

Quoted 8 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +8 -0
+		kb->retry_ms = POGO_RETRY_MIN_MS;
+		if (!READ_ONCE(kb->quitting))
+			schedule_work(&kb->plug_work);
+	}
+}
+
+static void pogo_handle_frame(struct pogo_kbd *kb, const u8 *f, unsigned int n)
+{

[ ... ]

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

Quoted 6 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +6 -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) {

[Severity: Medium]
Should there be an 'else' block for the battery status check?

The MCU can spontaneously transmit battery status frames (cmd 0x3B, payload[0] 0x0E). If the host is currently waiting for a general command reply (kb->tx_cmd == 0x3A), the condition cmd == kb->tx_cmd + 1 will match. This causes the battery frame to be falsely accepted as the command reply, which could cause pogo_set_general() to fail with -EPROTO and drop the real reply that arrives later.

Quoted 5 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +5 -0
+			/* 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);
+			complete(&kb->resp_done);
+		} else {

[ ... ]

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

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +4 -0
+static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable)
+{
+	if (enable == kb->wake_irq_enabled)
+		return;

[Severity: High]
Does this early return bypass the synchronization barrier during teardown?

In pogo_wake_isr(), the hardware interrupt calls disable_irq_nosync() and sets kb->wake_irq_enabled = false. If pogo_remove() calls pogo_wake_irq_enable(kb, false) while the ISR is executing after the flag has been updated, this early return will skip the disable_irq() call entirely.

This allows pogo_remove() to proceed with teardown and free the memory while the ISR is still running and about to queue detect_work, leading to a use-after-free.

Quoted 1 line
drivers/input/keyboard/oneplus-pogo-kbd.c new file +1 -0
+	if (enable) {

[ ... ]

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]
Could the cancellation order and serdev teardown sequence cause a use-after-free?

Because detect_work is cancelled before hb_work, if hb_work is running concurrently, it can re-queue detect_work after it has been cancelled. The lockless check !READ_ONCE(kb->quitting) allows a thread to read false, stall, and queue the work after these cancellations are finished.

Additionally, since the serdev port remains open during pogo_remove() (it closes later via devres), the UART RX callback can still execute, evaluate the lockless quitting flag as false, and queue plug_work after cancel_work_sync(&kb->plug_work) has already returned.

This sequence can leave works queued while devres frees the kb memory.

Quoted 7 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +7 -0
+
+	/* unregisters the input devices, the last possible led_work queuer */
+	pogo_power_off(kb);
+
+	/* flush a led_work queued before the inputs went away */
+	cancel_work_sync(&kb->led_work);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#20 lore raw

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

In reply to [email protected]

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 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).

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

 MAINTAINERS                                   |    7 +
 .../bindings/input/oneplus,pogo-keyboard.yaml |   73 +
 drivers/input/keyboard/Kconfig                |   13 +
 drivers/input/keyboard/Makefile               |    1 +
 drivers/input/keyboard/oneplus-pogo-kbd.c     | 1263 +++++++++++++++++
 5 files changed, 1357 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
#21 lore raw

PATCH v4 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.

---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 73 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +73 -0
new file mode 100644
index 000000000..bab9ff3d3
@@ -0,0 +1,73 @@
+# 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>
+
+    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
maintainer
#22 lore raw

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

Quoted 36 lines · On Thu, Oct 15, 2026 at 06:08: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.

---
 .../bindings/input/oneplus,pogo-keyboard.yaml | 73 +++++++++++++++++++
 MAINTAINERS                                   |  6 ++
 2 files changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +3 -0
new file mode 100644
index 000000000..bab9ff3d3
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (c) 2026 Yibo Wang <[email protected]>
+%YAML 1.2

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+---
+$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: |

Don't need '|'.

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

Quoted 6 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +6 -0
+  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.

Wrap lines at 80 char.

Quoted 37 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +37 -0
+
+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

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

Quoted 10 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +10 -0
+  - power-gpios
+  - tx-enable-gpios
+  - wake-gpios
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+

As this goes under 'serial' nodes:

serial {

Quoted 27 lines
Documentation/devicetree/bindings/input/oneplus,pogo-keyboard.yaml new file +7 -0
+    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
#23 lore raw

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

From: Yibo Wang <[email protected]>

Hi Rob,

thanks for the review.

Quoted 1 line · Rob Herring

Don't need '|'.

Dropped.

Quoted 1 line

Wrap lines at 80 char.

Rewrapped, everything now stays within 75 columns.

Quoted 3 lines

As this goes under 'serial' nodes:

serial {

Restored.

v5 follows as a reply to the v4 cover letter.

Best regards,
Yibo

maintainer
#24 lore raw

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

Quoted 15 lines · On Fri, Oct 16, 2026 at 07:32:46AM -0500, [email protected] wrote:

From: Yibo Wang <[email protected]>

Hi Rob,

thanks for the review.

Quoted 1 line · Rob Herring

Don't need '|'.

Dropped.

Quoted 1 line

Wrap lines at 80 char.

Rewrapped, everything now stays within 75 columns.

Quoted 7 lines
Quoted 3 lines

As this goes under 'serial' nodes:

serial {

Restored.

v5 follows as a reply to the v4 cover letter.

Please don't send new versions as replies.

Rob

#25 lore raw

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

From: Yibo Wang <[email protected]>

Hi Rob,

Quoted 1 line · Rob Herring

Please don't send new versions as replies.

Understood, thanks - new versions go out as fresh threads from now on.

On the same note of getting the process right: the binding documentation in this series was prepared with the assistance of an AI agent; I reviewed, adjusted and validated the technical content myself. v6, going out as a new top-level thread, adds an

    Assisted-by: Z.ai:GLM-5.3

trailer to the binding patch and the cover letter to disclose that.

Best regards,
Yibo

#26 lore raw

PATCH v4 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
#27 lore raw

Re: [PATCH v4 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: pogo: Use-After-Free in async paths due to lockless TOCTOU and broken synchronization…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] input: pogo: Use-After-Free in async paths due to lockless TOCTOU and broken synchronization
- [Medium] serdev: data race and buffer overwrite in pogo_xfer() due to lockless completion handling
- [Medium] serdev: unprotected link state modifications in RX thread cause software/hardware state desync
- [Low] sysfs: custom battery_level attribute bypasses power_supply subsystem UAPI
--

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

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

This commit adds a 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. It introduces a custom protocol implementation over a half-duplex UART to support touch, keys, backlight, and power management.

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0

[ ... ]

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

Quoted 11 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 		/*
 		 * 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);

[Severity: Medium]
Is it possible for a delayed response from the previous timeout to trigger a spurious completion here?

When the retry happens, the same cmd is set. If the RX thread was preempted just before copying the payload, could it wake up and call complete(&kb->resp_done) using the stale payload for this new iteration? Explicit lock synchronization between the timeout path and the RX thread might be needed.

[ ... ]

Quoted 2 lines

static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len) {

[ ... ]

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

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 	if (!kb->connected || replug) {
 		kb->connected = true;
 		kb->hb_seen = false;
 		kb->retry_ms = POGO_RETRY_MIN_MS;

[Severity: Medium]
Does this locklessly update the link state variables while they are also managed by pogo_power_off() under state_lock?

If a delayed heartbeat frame is processed exactly as pogo_hb_work() determines a timeout and calls pogo_power_off(), could pogo_power_off() clear the state just before this unsynchronized block unconditionally sets kb->connected = true again?

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

Quoted 3 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 		if (!READ_ONCE(kb->quitting))
 			schedule_work(&kb->plug_work);
 	}

[Severity: High]
Can this lockless check of kb->quitting lead to a use-after-free during driver removal?

The serdev RX path is devres-managed and can run concurrently with pogo_remove(). If the RX thread evaluates quitting as false just before pogo_remove() sets it to true, it could queue plug_work after cancel_work_sync(&kb->plug_work) has already finished, causing the work to run on freed memory.

[ ... ]

Quoted 2 lines

static void pogo_handle_frame(struct pogo_kbd *kb, const u8 *f, unsigned int n) {

[ ... ]

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

Quoted 6 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -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);
 			complete(&kb->resp_done);
 		}

[Severity: Medium]
Since the check for tx_pending and tx_cmd is lockless, could the RX thread be preempted right after this condition evaluates to true?

If pogo_xfer() times out, resets tx_pending, and starts a retry with the same command, the stalled RX thread could resume, overwrite kb->resp with the old payload, and signal completion for the new transfer.

[ ... ]

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

Quoted 4 lines

static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable) {

drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 	if (enable == kb->wake_irq_enabled)
 		return;

[Severity: High]
Could this optimization skip synchronizing with a running ISR?

If pogo_wake_isr() sets kb->wake_irq_enabled = false, this check will return immediately without calling disable_irq(). During pogo_remove(), this allows the teardown to proceed without waiting for the ISR, which might then queue detect_work after it has been cancelled.

[ ... ]

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

Quoted 9 lines

static void pogo_power_off(struct pogo_kbd *kb)
{

drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 	bool was_connected;
 
 	mutex_lock(&kb->state_lock);
 	was_connected = kb->connected;
 	kb->connected = false;
 	kb->powered = false;
 	mutex_unlock(&kb->state_lock);

[Severity: Medium]
As mentioned above, if this safe transition runs concurrently with a delayed frame processed by pogo_handle_sync(), could the hardware state become desynchronized?

The software might incorrectly reflect a connected device while the hardware is unpowered, causing subsequent sysfs accesses (like setting the backlight) to time out waiting for the MCU.

[ ... ]

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

Quoted 13 lines

static ssize_t battery_level_show(struct device *dev,

drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 				  struct device_attribute *attr, char *buf)
 {
 	struct pogo_kbd *kb = dev_get_drvdata(dev);
 
 	if (!kb->connected)
 		return -ENODEV;
 	/* only keyboards with a battery push 0x0E status frames */
 	if (kb->battery_level < 0)
 		return -ENODATA;
 	return sysfs_emit(buf, "%d\n", kb->battery_level);
 }
 static DEVICE_ATTR_RO(battery_level);

[Severity: Low]
Does exposing battery_level as a custom sysfs attribute bypass the standard power_supply subsystem?

Standard Linux userspace battery monitors (like UPower) only scan for devices registered under the standard power_supply class. Would it be better to register a POWER_SUPPLY_TYPE_BATTERY device using the power supply API so desktop environments can seamlessly read the keyboard's battery status?

[ ... ]

Quoted 5 lines

static void pogo_remove(struct serdev_device *serdev) {

drivers/input/keyboard/oneplus-pogo-kbd.c +0 -0
 	struct pogo_kbd *kb = serdev_device_get_drvdata(serdev);
 
 	/*

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

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c +0 -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]
Are these sequential cancellations safe against background works queuing each other?

Since detect_work is cancelled before hb_work, if hb_work evaluates !quitting right before it is set to true here, it could queue detect_work again after cancel_delayed_work_sync(&kb->detect_work) has already completed. This would leave a timer active on the device structure after it is freed.

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

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

In reply to [email protected]

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 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).

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
#29 lore raw

PATCH v5 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.

---
 .../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
#30 lore raw

Re: [PATCH v5 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: alphabetical sorting error for ONEPLUS entry --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MAINTAINERS: alphabetical sorting error for ONEPLUS entry
--

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

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

This patch adds the device tree binding for the OnePlus Pad 3 Pro / Pad 4 and OPPO Pad 5 Pro pogo-pin smart keyboards. It defines the compatible strings, required GPIO properties, and adds a MAINTAINERS entry.

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

[ ... ]

MAINTAINERS S: Maintained · line 20163

Quoted 11 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 the ONEPLUS entry be placed after the ONENAND entry? The MAINTAINERS file is expected to be kept in strict alphabetical order, and ONEP... follows ONEN... alphabetically.

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

PATCH v5 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
#32 lore raw

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

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] input: missing irq synchronization in teardown causes UAF - [High] input: TOCTOU race in work…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] input: missing irq synchronization in teardown causes UAF
- [High] input: TOCTOU race in work scheduling during remove causes UAF
- [Medium] input: data race on rx response buffer during concurrent replies
- [Medium] input: missing select TOUCHSCREEN_PROPERTIES in Kconfig
- [Medium] input: data race on link state variables between rx and workqueue --

commit cfd6c4eb0ba7d1e7dd71a926b7629e2bc8db3a2e
Author: Yibo Wang <[email protected]>
Subject: Input: add OnePlus/OPPO Pad pogo-pin keyboard serdev driver

This patch introduces a clean-room serdev driver for the Tinno keyboard MCU used by OnePlus and OPPO smart keyboards. The driver communicates via a framed one-wire bus protocol over a half-duplex UART and exposes standard input and LED interfaces.

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

Quoted 13 lines
drivers/input/keyboard/Kconfig +5 -0
index d8c64f333462c..f3931b7fbe748 100644
@@ -768,4 +768,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: Medium]
Is a select TOUCHSCREEN_PROPERTIES dependency missing here?

The driver relies on touchscreen_parse_properties() to parse standard Device Tree touchscreen overrides. Without this select statement, if the config is not enabled elsewhere in the kernel build, the stub version from the header is compiled instead. This silently ignores the DT properties intended for the touchpad.

[ ... ]

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

drivers/input/keyboard/oneplus-pogo-kbd.c static int pogo_xfer(struct pogo_kbd *kb, u8 cmd, const u8 *payload, u8 len, · line 391

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -382,10 +382,10 @@ static int pogo_xfer(struct pogo_kbd *kb, u8 cmd, const u8 *payload, u8 len,
 		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]
Could this cause a data race on the kb->resp buffer during concurrent replies?

Because kb->tx_pending is cleared after wait_for_completion_timeout() returns, if the MCU sends a duplicate reply frame or if the TX thread wakes up due to a timeout just as a delayed frame is received, the serdev RX thread will enter pogo_handle_frame().

The RX thread would evaluate kb->tx_pending as true, since the TX thread hasn't cleared it yet, and start copying data into kb->resp. If the TX thread executes memcpy(resp, kb->resp, n) concurrently, it will read corrupted data.

Should kb->tx_pending be cleared atomically inside the RX handler when the first valid reply is consumed instead?

[ ... ]

drivers/input/keyboard/oneplus-pogo-kbd.c static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len) · line 722

Quoted 10 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -714,10 +714,10 @@ static void pogo_handle_sync(struct pogo_kbd *kb, const u8 *p, unsigned int len)
 		kb->brand = p[3];
 		memcpy(kb->mac, &p[4], POGO_MAC_LEN);
 		kb->hb_seen = true;
 	}
 
 	if (!kb->connected || replug) {
 		kb->connected = true;
 		kb->hb_seen = false;
 		kb->retry_ms = POGO_RETRY_MIN_MS;

[Severity: Medium]
Does this mutate the link state variables without holding kb->state_lock?

pogo_power_off() and pogo_power_on() safely modify kb->connected and kb->powered while holding the mutex. However, the RX path here modifies these variables directly. If this runs simultaneously with pogo_power_off(), a race condition occurs. This can leave the driver state machine inconsistent (for example, kb->connected is true while kb->powered is false).

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

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
 		if (!READ_ONCE(kb->quitting))
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
 			schedule_work(&kb->plug_work);
 	}
 }

[Severity: High]
Can this lockless check lead to a use-after-free during device removal?

The serdev port remains open until devres cleanup, which happens after pogo_remove() returns. An active RX thread could evaluate !READ_ONCE(kb->quitting) as true, and then stall or get preempted before actually calling schedule_work().

Concurrently, pogo_remove() would set kb->quitting to true and run cancel_work_sync(&kb->plug_work). Because the work isn't queued yet, the cancellation returns immediately. When the preempted RX thread resumes, it queues the work. Devres then frees the kb struct, leaving the queued work item to execute on freed memory.

[ ... ]

drivers/input/keyboard/oneplus-pogo-kbd.c static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable) · line 863

Quoted 4 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -861,7 +861,7 @@ static void pogo_wake_irq_enable(struct pogo_kbd *kb, bool enable)
 {
 	if (enable == kb->wake_irq_enabled)
 		return;

[Severity: High]
Does this optimization incorrectly bypass the disable_irq() synchronization barrier during teardown?

If the hardware IRQ fires concurrently, pogo_wake_isr() immediately calls disable_irq_nosync() and sets kb->wake_irq_enabled to false. When pogo_remove() subsequently calls pogo_wake_irq_enable(kb, false), it sees the flag is already false and returns early.

This completely bypasses the standard disable_irq() call that would otherwise wait for the executing ISR to finish. pogo_remove() will proceed to cancel the delayed works, but the still-running ISR can afterward queue detect_work using its own bypassed lockless checks, leading to a use-after-free once devres cleans up the kb struct.

[ ... ]

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

Quoted 12 lines
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
@@ -1181,9 +1181,9 @@ static void pogo_remove(struct serdev_device *serdev)
 	/*
 	 * 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);
drivers/input/keyboard/oneplus-pogo-kbd.c new file +0 -0
 	cancel_delayed_work_sync(&kb->hb_work);
 	cancel_work_sync(&kb->plug_work);

(The teardown code above is the other side of the high-severity races identified in pogo_wake_irq_enable() and pogo_handle_sync() where background threads queue work on freed memory).

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