Skip to contentSkip to conversation

Input: Add Awinic AW8697 haptics driver

PATCH Superseded Armandas Kvietkus 4 participants 6 messages Sep 30 – Oct 12

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Input: Add Awinic AW8697 haptics driver

This series adds a driver for the Awinic AW8697 LRA haptic driver IC. It is the vibrator in the Xiaomi POCO F3.

The AW8697 is an older generation than the AW86927. The register map is different, so it gets its own driver. The binding reuses awinic,aw86927.yaml.

Tested on the phone: rumble at several strengths, 72 effects in a row, stop on close, driver rebind and module reload.

---
Changes in v2:
- Do not queue I2C work from the ff-memless timer during system
suspend. A suspended flag is set and cleared under the input event lock, as in da7280. Tested with delayed effects across suspend.
- Use explicit error checks instead of returning the last regmap call.
- The NULL IRQ name finding is not changed. devm_request_threaded_irq() uses dev_name() when the name is NULL. /proc/interrupts shows 11-005a.
- Link to v1: https://patch.msgid.link/[email protected]

v2 only fixes findings from the automated AI review. I will not send another revision for automated review findings alone, because that can go on forever. I will wait for human review.

---
Armandas Kvietkus (2):
dt-bindings: input: awinic,aw86927: Add Awinic AW8697
Input: aw8697 - Add Awinic AW8697 haptics driver

 .../devicetree/bindings/input/awinic,aw86927.yaml  |   4 +-
 MAINTAINERS                                        |   6 +
 drivers/input/misc/Kconfig                         |  14 +
 drivers/input/misc/Makefile                        |   1 +
 drivers/input/misc/aw8697.c                        | 761 +++++++++++++++++++++
 5 files changed, 785 insertions(+), 1 deletion(-)

---
base-commit: 165768bb70265b5c38cf0b73fafd75be235f8b14
change-id: 20260930-mainlining-0bd8b7b5ca6c

Best regards,

Signature · 1 line
Armandas Kvietkus <[email protected]>
#1 lore raw

PATCH v2 1/2 dt-bindings: input: awinic,aw86927: Add Awinic AW8697

The AW8697 uses the same bus, interrupt and reset lines as the AW86927. The register map is different, so there is no fallback compatible.

---
 Documentation/devicetree/bindings/input/awinic,aw86927.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/input/awinic,aw86927.yaml +3 -1
index bd74b81488f6..f0e26664e3e4 100644
@@ -12,7 +12,9 @@ maintainers:
 properties:
   compatible:
     oneOf:
-      - const: awinic,aw86927
+      - enum:
+          - awinic,aw8697
+          - awinic,aw86927
       - items:
           - enum:
               - awinic,aw86938
Signature · 1 line
2.55.0
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: input: awinic,aw86927: Add Awinic AW8697

Quoted 7 lines · Armandas Kvietkus

The AW8697 uses the same bus, interrupt and reset lines as the AW86927. The register map is different, so there is no fallback compatible.

---
 Documentation/devicetree/bindings/input/awinic,aw86927.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Best regards,
Krzysztof

#3 lore raw

PATCH v2 2/2 Input: aw8697 - Add Awinic AW8697 haptics driver

In reply to Armandas Kvietkus

Add a driver for the Awinic AW8697 LRA haptic driver IC. It supports FF_RUMBLE and calibrates the LRA resonance at probe.

Based on the aw86927 driver.

Tested on a Xiaomi POCO F3.

---
 MAINTAINERS                 |   6 +
 drivers/input/misc/Kconfig  |  14 +
 drivers/input/misc/Makefile |   1 +
 drivers/input/misc/aw8697.c | 761 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 782 insertions(+)
MAINTAINERS +6 -0
index c52ec2d7d3c1..b00217bdca20 100644
@@ -4419,6 +4419,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/media/pci/hws/
 
+AWINIC AW8697 HAPTICS DRIVER
+M:	Armandas Kvietkus <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/input/misc/aw8697.c
+
 AWINIC AW99706 WLED BACKLIGHT DRIVER
 M:	Junjie Cao <[email protected]>
 S:	Maintained
drivers/input/misc/Kconfig +14 -0
index 169768e3d5bb..d2b71a0f9aee 100644
@@ -126,6 +126,20 @@ config INPUT_ATMEL_CAPTOUCH
 	  To compile this driver as a module, choose M here: the
 	  module will be called atmel_captouch.
 
+config INPUT_AW8697
+	tristate "Awinic AW8697 Haptic Driver Support"
+	depends on I2C && INPUT
+	select INPUT_FF_MEMLESS
+	select REGMAP_I2C
+	help
+	  Say Y here if you have an Awinic AW8697 haptic chip. The
+	  AW8697 drives a linear resonant actuator and is found in
+	  phones such as the Xiaomi POCO F3. The driver exposes a
+	  force feedback input device with rumble support.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called aw8697.
+
 config INPUT_AW86927
 	tristate "Awinic AW86927 Haptic Driver Support"
 	depends on I2C && INPUT
drivers/input/misc/Makefile +1 -0
index 1339619f0769..171d3ff1f167 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_INPUT_ATC260X_ONKEY)	+= atc260x-onkey.o
 obj-$(CONFIG_INPUT_ATI_REMOTE2)		+= ati_remote2.o
 obj-$(CONFIG_INPUT_ATLAS_BTNS)		+= atlas_btns.o
 obj-$(CONFIG_INPUT_ATMEL_CAPTOUCH)	+= atmel_captouch.o
+obj-$(CONFIG_INPUT_AW8697)		+= aw8697.o
 obj-$(CONFIG_INPUT_AW86927)		+= aw86927.o
 obj-$(CONFIG_INPUT_BBNSM_PWRKEY)	+= nxp-bbnsm-pwrkey.o
 obj-$(CONFIG_INPUT_BMA150)		+= bma150.o
drivers/input/misc/aw8697.c new file +761 -0

761 lines not on this page · raw message

Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH v2 2/2] Input: aw8697 - Add Awinic AW8697 haptics driver

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] input: UAF in aw8697_play_work due to missing devm cancellation action - [Low] i2c: missing named…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] input: UAF in aw8697_play_work due to missing devm cancellation action
- [Low] i2c: missing named initializer for i2c_device_id array
--

commit 78f66ce5a94c007171954aaef47a26794e665c94
Author: Armandas Kvietkus <[email protected]>

Input: aw8697 - Add Awinic AW8697 haptics driver

Adds a driver for the Awinic AW8697 LRA haptic driver IC. It supports force feedback rumble and calibrates the LRA resonance at probe.

Quoted 5 lines
drivers/input/misc/aw8697.c new file +0 -0
new file mode 100644
index 0000000000000..96c0205089fd0

[ ... ]

Quoted 2 lines
drivers/input/misc/aw8697.c new file +2 -0
+static int aw8697_probe(struct i2c_client *client)
+{

[ ... ]

drivers/input/misc/aw8697.c line 687

Quoted 8 lines
drivers/input/misc/aw8697.c new file +8 -0
+	err = devm_request_threaded_irq(dev, client->irq, NULL, aw8697_irq,
+					IRQF_ONESHOT, NULL, haptics);
+	if (err)
+		return dev_err_probe(dev, err, "Failed to request irq\n");
+
+	INIT_WORK(&haptics->play_work, aw8697_play_work);
+
+	haptics->input_dev = devm_input_allocate_device(dev);

[Severity: High]
Could this lead to a use-after-free of the haptics structure if the driver is unbound while an effect is active?

The workqueue is initialized here, but no devm action is registered to guarantee cancellation after the input device is fully unregistered.

If the driver is unbound, devm automatically calls input_unregister_device(), which triggers aw8697_close() and cancels the work. However, the force-feedback memless timer is only stopped later in input_unregister_device() when it calls the destroy callback.

In this narrow window, the timer can still fire and call aw8697_play_effect(), which reschedules haptics->play_work. Because there is no devm action to cancel the work queue after the input device is fully unregistered, the rescheduled work persists after devm frees the haptics structure, causing a use-after-free when the work executes.

Quoted 2 lines
drivers/input/misc/aw8697.c new file +2 -0
+	if (!haptics->input_dev)
+		return -ENOMEM;

[ ... ]

drivers/input/misc/aw8697.c line 737

Quoted 4 lines
drivers/input/misc/aw8697.c new file +4 -0
+static DEFINE_SIMPLE_DEV_PM_OPS(aw8697_pm_ops, aw8697_suspend, aw8697_resume);
+
+static const struct i2c_device_id aw8697_id[] = {
+	{ "aw8697" },

[Severity: Low]
Does this array violate the I2C subsystem rule mandating named initializers? It seems this should be written as { .name = "aw8697" }.

Quoted 3 lines
drivers/input/misc/aw8697.c new file +3 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, aw8697_id);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH v2 2/2] Input: aw8697 - Add Awinic AW8697 haptics driver

In reply to Armandas Kvietkus
Quoted 1 line · On Wed, Sep 30, 2026 at 07:18:51PM +0200, Armandas Kvietkus via B4 Relay wrote:

+#include <linux/mod_devicetable.h>

You can (and should) rely on <linux/i2c.h> to provide i2c_device_id and of_device_id. Please don't use <linux/mod_devicetable.h> which mostly only adds unneeded build dependencies.

drivers/input/misc/aw8697.c line 737

Quoted 2 lines
drivers/input/misc/aw8697.c new file +2 -0
+static const struct i2c_device_id aw8697_id[] = {
+	{ "aw8697" },

Please use a named initializer, i.e.:

	{ .name = "aw8697" },

Review

Quoted 2 lines
(quoted diff) +2 -0
+	{ }
+};

Best regards
Uwe