Skip to contentSkip to conversation

input: misc: add support for Imagis ISA1200 haptic motor driver

PATCH In review Svyatoslav Ryhel 3 participants 7 messages Jun 17 – Jun 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v6 cover input: misc: add support for Imagis ISA1200 haptic motor driver

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

---
Changes in v6:
- added minItems for gpios
- included changes by Dmitry Torokhov

Changes in v5:
- added supplies to private structure
- clk_on dropped
- ret > err
- added active flag to track status
- all hardware manipulations consolidated in start/stop
- dropped mutex from work
- dropped active check from isa1200_vibrator_close it was moved to stop directly
- dropped hw maniplations from probe
- bustype set to BUS_I2C
- adjusted error strings
- fixed cancel_work_sync in isa1200_suspend

Changes in v4:
- added INPUT_FF_MEMLESS option selection
- fixed missing clock status set
- guard start/stop calls in isa1200_play_work with lock
- clamp ldo voltages to allowed range
- fixed imagis,pll-div parsing
- dropped Tested-by from schema adding commit

Changes in v3:
- added clock state tracking
- dropped level check in vibrator close
- added clkdiv clamping
- added comments regarding registers 5 and 6

Changes in v2:
- imagis,clk-div switched to accept actual divider value
- dropped DT header
- adjusted imagis,period-ns range
- initiated hctrl0 and hctrl1 values in isa1200_start
- fixed situation when PWM might return -EPROBE_DEFER to be treated properly
- added chech a clock or PWM is available
- fixed regulator voltages check being off by 10
- added chech if state.period is not zero
- added action call to disable clock and gpios on error
- used managed version of work init
- added work cancel on suspend
- PW calls are done under mutex lock
---

Linus Walleij (1):
Input: isa1200 - new driver for Imagis ISA1200

Svyatoslav Ryhel (1):
dt-bindings: input: Document Imagis ISA1200 haptic motor driver

 .../bindings/input/imagis,isa1200.yaml        | 141 +++++
 drivers/input/misc/Kconfig                    |  12 +
 drivers/input/misc/Makefile                   |   1 +
 drivers/input/misc/isa1200.c                  | 536 ++++++++++++++++++
 4 files changed, 690 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/imagis,isa1200.yaml
 create mode 100644 drivers/input/misc/isa1200.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v6 1/2 dt-bindings: input: Document Imagis ISA1200 haptic motor driver

Document the Imagis ISA1200 haptic motor driver, used primarily in mobile handheld devices and capable of supporting up to two motors.

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

---
 .../bindings/input/imagis,isa1200.yaml        | 141 ++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/imagis,isa1200.yaml
Documentation/devicetree/bindings/input/imagis,isa1200.yaml new file +141 -0
new file mode 100644
index 000000000000..4bc8630edcdd
@@ -0,0 +1,141 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/imagis,isa1200.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Imagis ISA1200 haptic motor driver
+
+maintainers:
+  - Svyatoslav Ryhel <[email protected]>
+  - Linus Walleij <[email protected]>
+
+description:
+  The ISA1200 is a high-performance enhanced haptic motor driver designed
+  for mobile hand-held devices. It supports various voltages for both ERM
+  (Eccentric Rotating Mass) and LRA (Linear Resonant Actuator) type
+  actuators. Thanks to an embedded LDO, battery power can be used directly
+  in handheld applications.
+
+properties:
+  compatible:
+    const: imagis,isa1200
+
+  reg:
+    maxItems: 1
+
+  control-gpios:
+    description:
+      One or two GPIOs flagged as active high linked to HEN and LEN pins
+    minItems: 1
+    maxItems: 2
+
+  clocks:
+    maxItems: 1
+
+  pwms:
+    maxItems: 1
+
+  vdd-supply:
+    description:
+      Regulator for 2.4V - 5.5V power supply
+
+  vddp-supply:
+    description:
+      Regulator for 2.4V - 3.6V IO power supply
+
+  imagis,clk-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Divider for the external input clock/PWM
+    enum: [128, 256, 512, 1024]
+    default: 128
+
+  imagis,pll-div:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Divider for the internal PLL clock
+    minimum: 1
+    maximum: 15
+    default: 1
+
+  imagis,mode:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Defines the motor type isa1200 drives
+      0 - LRA (Linear Resonant Actuator)
+      1 - ERM (Eccentric Rotating Mass)
+    enum: [0, 1]
+    default: 0
+
+  imagis,period-ns:
+    description:
+      Period of the internal PWM channel in nanoseconds.
+    minimum: 10000
+    maximum: 30000
+
+  imagis,duty-cycle-ns:
+    description:
+      Duty cycle of the external/internal PWM channel in nanoseconds,
+      defaults to 50% of the channel's period
+
+  ldo:
+    $ref: /schemas/regulator/regulator.yaml#
+    type: object
+    description:
+      Embedded LDO regulator with voltage range 2.3V - 3.8V
+    unevaluatedProperties: false
+
+    required:
+      - regulator-min-microvolt
+      - regulator-max-microvolt
+
+required:
+  - compatible
+  - reg
+  - ldo
+
+oneOf:
+  - required:
+      - clocks
+      - imagis,period-ns
+  - required:
+      - pwms
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        haptic-engine@49 {
+            compatible = "imagis,isa1200";
+            reg = <0x49>;
+
+            clocks = <&isa1200_refclk>;
+
+            control-gpios = <&gpio 22 GPIO_ACTIVE_HIGH>,
+                            <&gpio 23 GPIO_ACTIVE_HIGH>;
+
+            vdd-supply = <&vdd_3v3_vbat>;
+            vddp-supply = <&vdd_2v8_vvib>;
+
+            imagis,clk-div = <256>;
+            imagis,pll-div = <2>;
+
+            imagis,mode = <0>; /* LRA_MODE */
+
+            imagis,period-ns = <13400>;
+            imagis,duty-cycle-ns = <100>;
+
+            ldo {
+                regulator-name = "vdd_vib";
+                regulator-min-microvolt = <2300000>;
+                regulator-max-microvolt = <2300000>;
+            };
+        };
+    };
Signature · 1 line
2.53.0
#2 lore raw

PATCH v6 2/2 Input: isa1200 - new driver for Imagis ISA1200

In reply to Svyatoslav Ryhel

From: Linus Walleij <[email protected]>

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

---
 drivers/input/misc/Kconfig   |  12 +
 drivers/input/misc/Makefile  |   1 +
 drivers/input/misc/isa1200.c | 536 +++++++++++++++++++++++++++++++++++
 3 files changed, 549 insertions(+)
 create mode 100644 drivers/input/misc/isa1200.c
drivers/input/misc/Kconfig +12 -0
index 1f6c57dba030..7154eaf5a60b 100644
@@ -842,6 +842,18 @@ config INPUT_IQS7222
 	  To compile this driver as a module, choose M here: the
 	  module will be called iqs7222.
 
+config INPUT_ISA1200_HAPTIC
+	tristate "Imagis ISA1200 haptic feedback unit"
+	depends on I2C
+	select INPUT_FF_MEMLESS
+	select REGMAP_I2C
+	help
+	  Say Y to enable support for the Imagis ISA1200 haptic
+	  feedback unit.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called isa1200.
+
 config INPUT_CMA3000
 	tristate "VTI CMA3000 Tri-axis accelerometer"
 	help
drivers/input/misc/Makefile +1 -0
index 2281d6803fce..e9f85ca20c33 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_INPUT_IMS_PCU)		+= ims-pcu.o
 obj-$(CONFIG_INPUT_IQS269A)		+= iqs269a.o
 obj-$(CONFIG_INPUT_IQS626A)		+= iqs626a.o
 obj-$(CONFIG_INPUT_IQS7222)		+= iqs7222.o
+obj-$(CONFIG_INPUT_ISA1200_HAPTIC)	+= isa1200.o
 obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
 obj-$(CONFIG_INPUT_KXTJ9)		+= kxtj9.o
 obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
drivers/input/misc/isa1200.c new file +536 -0

536 lines not on this page · raw message

Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH v6 2/2] Input: isa1200 - new driver for Imagis ISA1200

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] The `ff-memless` timer and input device can outlive the devres-managed driver state upon…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The ff-memless timer and input device can outlive the devres-managed driver state upon device unbind, leading to a Use-After-Free (UAF).
- [High] The worker isa1200_play_work silently drops force feedback events if it fails to acquire input->mutex, potentially leaving the vibrator stuck.
- [Medium] Concurrent access to isa->level across different locking contexts causes a data race that can schedule work after the device is closed. --

commit 2ea8a9b82f2921004386e7307e4e382941aa5611
Author: Linus Walleij <[email protected]>

Input: isa1200 - new driver for Imagis ISA1200

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

Quoted 5 lines
drivers/input/misc/isa1200.c new file +0 -0
new file mode 100644
index 0000000000000..f8c4da4a0e088

[ ... ]

drivers/input/misc/isa1200.c line 258

Quoted 6 lines
drivers/input/misc/isa1200.c new file +6 -0
+static void isa1200_play_work(struct work_struct *work)
+{
+	struct isa1200 *isa = container_of(work, struct isa1200, play_work);
+	struct input_dev *input = isa->input;
+
+	scoped_guard(mutex_try, &input->mutex) {

[Severity: High]
Can this cause force feedback events to be silently dropped?

The worker uses scoped_guard(mutex_try, &input->mutex) to acquire the lock. However, input->mutex is frequently held by the input core for normal operations like input_open_device, input_close_device, and ioctls (e.g., EVIOCGABS).

If this worker runs concurrently with any of these operations, the mutex_try will fail and the worker will exit without updating the hardware. Because isa->level was already updated locklessly in isa1200_vibrator_play_effect(), future identical effect updates will be skipped, which could leave the vibrator stuck in its current state.

Quoted 8 lines
drivers/input/misc/isa1200.c new file +8 -0
+		if (!isa->suspended) {
+			if (isa->level)
+				isa1200_start(isa);
+			else
+				isa1200_stop(isa);
+		}
+	}
+}

[ ... ]

drivers/input/misc/isa1200.c line 301

Quoted 7 lines
drivers/input/misc/isa1200.c new file +7 -0
+static void isa1200_vibrator_close(struct input_dev *input)
+{
+	struct isa1200 *isa = input_get_drvdata(input);
+
+	cancel_work_sync(&isa->play_work);
+	isa1200_stop(isa);
+	isa->level = 0;

[Severity: Medium]
Does this concurrent modification of isa->level create a data race that can restart the vibrator after the device is closed?

The state variable isa->level is updated in isa1200_vibrator_play_effect() under the input core's event_lock (timer context). Concurrently, it is reset to 0 here in isa1200_vibrator_close() under input->mutex, without acquiring event_lock.

Because the ff-memless timer is not explicitly stopped during close, the timer can fire concurrently with or immediately after close. If it fires after cancel_work_sync(&isa->play_work) completes, it can overwrite isa->level to a non-zero value and re-schedule isa->play_work. This could re-enable the motor indefinitely.

Quoted 1 line

+}

[ ... ]

drivers/input/misc/isa1200.c line 441

Quoted 7 lines
drivers/input/misc/isa1200.c new file +7 -0
+static int isa1200_probe(struct i2c_client *client)
+{
+	struct isa1200 *isa;
+	struct device *dev = &client->dev;
+	int err;
+
+	isa = devm_kzalloc(dev, sizeof(*isa), GFP_KERNEL);

[Severity: Critical]
Is there a use-after-free risk here during device unbind?

The private isa structure is allocated with devm_kzalloc(), meaning it is freed immediately when the device unbinds. However, the input device itself is managed by devm_input_allocate_device(), which keeps the memory alive as long as userspace holds an open file descriptor.

Because the ff-memless timer (ml_effect_timer) is tied to the input_dev lifecycle, the timer can continue to fire even after unbind if an effect was playing. When it fires, isa1200_vibrator_play_effect() retrieves the freed isa structure via input_get_drvdata() and accesses corrupted memory to schedule the workqueue.

Additionally, there doesn't appear to be a devm action added to explicitly cancel isa->play_work on unbind.

Quoted 4 lines
drivers/input/misc/isa1200.c new file +4 -0
+	if (!isa)
+		return -ENOMEM;
+
+	isa->input = devm_input_allocate_device(dev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#4 lore raw

Re: [PATCH v6 2/2] Input: isa1200 - new driver for Imagis ISA1200

In reply to Svyatoslav Ryhel

Hi Svyatoslav,

Quoted 7 lines · Svyatoslav Ryhel

From: Linus Walleij <[email protected]>

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

Quoted 8 lines

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

Sashiko convinced me that using mutex_trylock() in the playback work handler will result in dropping requests and that we are safe not taking the lock there at all. Can you please try the following modification?

drivers/input/misc/isa1200.c +6 -9
index c61adc4b605c..fb7f68fa0a2b 100644
@@ -253,15 +253,12 @@ static void isa1200_stop(struct isa1200 *isa)
 static void isa1200_play_work(struct work_struct *work)
 {
 	struct isa1200 *isa = container_of(work, struct isa1200, play_work);
-	struct input_dev *input = isa->input;
-
-	scoped_guard(mutex_try, &input->mutex) {
-		if (!isa->suspended) {
-			if (isa->level)
-				isa1200_start(isa);
-			else
-				isa1200_stop(isa);
-		}
+
+	if (!READ_ONCE(isa->suspended)) {
+		if (isa->level)
+			isa1200_start(isa);
+		else
+			isa1200_stop(isa);
 	}
 }
 

If this works no need to resend, I'll fold on my side.

Thanks.

Signature · 1 line
Dmitry
#5 lore raw

Re: [PATCH v6 2/2] Input: isa1200 - new driver for Imagis ISA1200

пт, 26 черв. 2026 р. о 02:45 Dmitry Torokhov <[email protected]> пише:

Quoted 52 lines

Hi Svyatoslav,

Quoted 7 lines · Svyatoslav Ryhel

From: Linus Walleij <[email protected]>

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

Quoted 8 lines

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

Sashiko convinced me that using mutex_trylock() in the playback work handler will result in dropping requests and that we are safe not taking the lock there at all. Can you please try the following modification?

drivers/input/misc/isa1200.c +6 -9
index c61adc4b605c..fb7f68fa0a2b 100644
@@ -253,15 +253,12 @@ static void isa1200_stop(struct isa1200 *isa)
 static void isa1200_play_work(struct work_struct *work)
 {
        struct isa1200 *isa = container_of(work, struct isa1200, play_work);
-       struct input_dev *input = isa->input;
-
-       scoped_guard(mutex_try, &input->mutex) {
-               if (!isa->suspended) {
-                       if (isa->level)
-                               isa1200_start(isa);
-                       else
-                               isa1200_stop(isa);
-               }
+
+       if (!READ_ONCE(isa->suspended)) {
+               if (isa->level)
+                       isa1200_start(isa);
+               else
+                       isa1200_stop(isa);
        }
 }
 
Quoted 2 lines

If this works no need to resend, I'll fold on my side.

It does work fine. Thank you.

Quoted 4 lines

Thanks.

--
Dmitry

maintainer
#6 lore raw

Re: [PATCH v6 2/2] Input: isa1200 - new driver for Imagis ISA1200

Quoted 53 lines · Svyatoslav Ryhel

пт, 26 черв. 2026 р. о 02:45 Dmitry Torokhov <[email protected]> пише:

Quoted 52 lines

Hi Svyatoslav,

Quoted 7 lines · Svyatoslav Ryhel

From: Linus Walleij <[email protected]>

The ISA1200 is a haptic feedback unit from Imagis Technology using two motors for haptic feedback in mobile phones. Used in many mobile devices c. 2012 including Samsung Galxy S Advance GT-I9070 (Janice), Samsung Beam GT-I8350 (Gavini), LG Optimus 4X P880 and LG Optimus Vu P895.

Quoted 8 lines

The exact datasheet for the ISA1200 is not available; all data was modeled based on available downstream kernel sources for various devices and fragments of information scattered across the internet.

Sashiko convinced me that using mutex_trylock() in the playback work handler will result in dropping requests and that we are safe not taking the lock there at all. Can you please try the following modification?

drivers/input/misc/isa1200.c +6 -9
index c61adc4b605c..fb7f68fa0a2b 100644
@@ -253,15 +253,12 @@ static void isa1200_stop(struct isa1200 *isa)
 static void isa1200_play_work(struct work_struct *work)
 {
        struct isa1200 *isa = container_of(work, struct isa1200, play_work);
-       struct input_dev *input = isa->input;
-
-       scoped_guard(mutex_try, &input->mutex) {
-               if (!isa->suspended) {
-                       if (isa->level)
-                               isa1200_start(isa);
-                       else
-                               isa1200_stop(isa);
-               }
+
+       if (!READ_ONCE(isa->suspended)) {
+               if (isa->level)
+                       isa1200_start(isa);
+               else
+                       isa1200_stop(isa);
        }
 }
 
Quoted 4 lines
Quoted 2 lines

If this works no need to resend, I'll fold on my side.

It does work fine. Thank you.

Excelled, thank you. Applied both patches.

Signature · 1 line
Dmitry