* [PATCH v9 01/10] dt-bindings: iio: accel: mma8452: Add drive-open-drain
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-09-16 8:07 ` Esben Haabendal
2026-09-16 8:07 ` [PATCH v9 02/10] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
` (8 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:07 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel
Add new boolean to configure selected interrupt pin to open drain instead
of the default push-pull mode.
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml b/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
index b0dd2b4e116a..20701aa725d0 100644
--- a/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
+++ b/Documentation/devicetree/bindings/iio/accel/fsl,mma8452.yaml
@@ -39,6 +39,12 @@ properties:
minItems: 1
maxItems: 2
+ drive-open-drain:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description: the interrupt line will be configured as open drain, which is
+ useful if several sensors share the same interrupt line. (This binding is
+ taken from pinctrl.)
+
vdd-supply: true
vddio-supply: true
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 02/10] iio: accel: mma8452: Fix use-after-free bug in error error path
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-16 8:07 ` [PATCH v9 01/10] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
@ 2026-09-16 8:07 ` Esben Haabendal
2026-09-16 8:07 ` [PATCH v9 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read() Esben Haabendal
` (7 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:07 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, stable,
Joshua Crofts
If mma8452_probe() fails in iio_device_register() or later, we could end up
with runtime suspend callback being called with a now freed device pointer.
Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
Cc: stable@vger.kernel.org
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index fe62a903f0e2..a937cbd84f30 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1681,7 +1681,7 @@ static int mma8452_probe(struct i2c_client *client)
ret = iio_device_register(indio_dev);
if (ret < 0)
- goto free_irq;
+ goto runtime_suspend;
ret = mma8452_set_freefall_mode(data, false);
if (ret < 0)
@@ -1692,6 +1692,10 @@ static int mma8452_probe(struct i2c_client *client)
unregister_device:
iio_device_unregister(indio_dev);
+runtime_suspend:
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+
free_irq:
if (client->irq)
free_irq(client->irq, indio_dev);
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read()
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-16 8:07 ` [PATCH v9 01/10] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-09-16 8:07 ` [PATCH v9 02/10] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
@ 2026-09-16 8:07 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 04/10] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
` (6 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:07 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, stable
When runtime PM support was added [1], the implementation in mma8452_read()
was done incorrectly, as it calls mma8452_drdy() before ensuring runtime pm
has set the device active, so it can cause read from STATUS register while
device is suspended/off. At the same time, the return value from
i2c_smbus_read_i2c_block_data() was discarded, and the function would
return the value returned from pm_runtime_put_autosuspend() instead.
When the latter bug described above was fixed [2], another bug was
introduced, as mma8452_read() would now leak the runtime PM reference
counter when i2c_smbus_read_i2c_block_data() failed.
This commit corrects this mess.
[1] commit 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
[2] commit 5bdff291d20c ("iio: accel: mma8452: handle I2C read error(s) in mma8452_read()")
Fixes: 96c0cb2bbfe0 ("iio: mma8452: add support for runtime power management")
Cc: stable@vger.kernel.org
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index a937cbd84f30..a77c4b88b61d 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -242,21 +242,25 @@ static int mma8452_set_runtime_pm_state(struct i2c_client *client, bool on)
static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
{
- int ret = mma8452_drdy(data);
-
- if (ret < 0)
- return ret;
+ int ret;
ret = mma8452_set_runtime_pm_state(data->client, true);
if (ret)
return ret;
+ ret = mma8452_drdy(data);
+ if (ret < 0)
+ goto out_runtime_put;
+
ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
3 * sizeof(__be16), (u8 *)buf);
if (ret < 0)
- return ret;
+ goto out_runtime_put;
+
+ return mma8452_set_runtime_pm_state(data->client, false);
- ret = mma8452_set_runtime_pm_state(data->client, false);
+out_runtime_put:
+ mma8452_set_runtime_pm_state(data->client, false);
return ret;
}
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 04/10] iio: accel: mma8452: Optimize struct mma8452_data member orders
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (2 preceding siblings ...)
2026-09-16 8:07 ` [PATCH v9 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read() Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 05/10] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
` (5 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Joshua Crofts, Andy Shevchenko
Reorder struct mma8452_data members to avoid holes.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index a77c4b88b61d..8d70fe89110c 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -108,10 +108,7 @@ struct mma8452_data {
struct i2c_client *client;
struct mutex lock;
struct iio_mount_matrix orientation;
- u8 ctrl_reg1;
- u8 data_cfg;
const struct mma_chip_info *chip_info;
- int sleep_val;
struct regulator_bulk_data regs[2];
/* Ensure correct alignment of time stamp when present */
@@ -119,6 +116,10 @@ struct mma8452_data {
__be16 channels[3];
aligned_s64 ts;
} buffer;
+
+ int sleep_val;
+ u8 ctrl_reg1;
+ u8 data_cfg;
};
/**
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 05/10] iio: accel: mma8452: Only apply trigger type when not set by firmware
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (3 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 04/10] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 06/10] iio: accel: mma8452: Fix unintended comment indent Esben Haabendal
` (4 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, Andy Shevchenko
Instead of unconditionally overriding the trigger type, it is better to
only apply a default when no trigger type is set by firmware. This should
be reasonably backward compatible, and should only potentially cause
problems if systems exist where firmware specifies an incorrect trigger
type. With a bit of luck, there are no such systems.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 8d70fe89110c..72b4ab32775a 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1669,9 +1669,16 @@ static int mma8452_probe(struct i2c_client *client)
goto trigger_cleanup;
if (client->irq) {
+ unsigned long irq_flags;
+
+ irq_flags = irq_get_trigger_type(client->irq);
+ if (irq_flags == IRQ_TYPE_NONE) {
+ dev_info(dev, "invalid irq type, setting default active low\n");
+ irq_flags = IRQF_TRIGGER_LOW;
+ }
+ irq_flags |= IRQF_ONESHOT;
ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT,
- client->name, indio_dev);
+ irq_flags, client->name, indio_dev);
if (ret)
goto buffer_cleanup;
}
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 06/10] iio: accel: mma8452: Fix unintended comment indent
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (4 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 05/10] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data Esben Haabendal
` (3 subsequent siblings)
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, Joshua Crofts
The extra space this block was indented with looks quite untraditional, and
does not align with the common style used in the kernel.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 72b4ab32775a..b70bc8638128 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -122,21 +122,21 @@ struct mma8452_data {
u8 data_cfg;
};
- /**
- * struct mma8452_event_regs - chip specific data related to events
- * @ev_cfg: event config register address
- * @ev_cfg_ele: latch bit in event config register
- * @ev_cfg_chan_shift: number of the bit to enable events in X
- * direction; in event config register
- * @ev_src: event source register address
- * @ev_ths: event threshold register address
- * @ev_ths_mask: mask for the threshold value
- * @ev_count: event count (period) register address
- *
- * Since not all chips supported by the driver support comparing high pass
- * filtered data for events (interrupts), different interrupt sources are
- * used for different chips and the relevant registers are included here.
- */
+/**
+ * struct mma8452_event_regs - chip specific data related to events
+ * @ev_cfg: event config register address
+ * @ev_cfg_ele: latch bit in event config register
+ * @ev_cfg_chan_shift: number of the bit to enable events in X
+ * direction; in event config register
+ * @ev_src: event source register address
+ * @ev_ths: event threshold register address
+ * @ev_ths_mask: mask for the threshold value
+ * @ev_count: event count (period) register address
+ *
+ * Since not all chips supported by the driver support comparing high pass
+ * filtered data for events (interrupts), different interrupt sources are
+ * used for different chips and the relevant registers are included here.
+ */
struct mma8452_event_regs {
u8 ev_cfg;
u8 ev_cfg_ele;
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (5 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 06/10] iio: accel: mma8452: Fix unintended comment indent Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-21 0:52 ` Jonathan Cameron
2026-09-16 8:08 ` [PATCH v9 08/10] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (2 subsequent siblings)
9 siblings, 1 reply; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, Joshua Crofts
The struct mma8452_data is central for this driver, and it makes sense to
have a description of the fields in it to make it easier to work with the
driver.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index b70bc8638128..223bef4f7baf 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -104,6 +104,21 @@
#define MMA8452_AUTO_SUSPEND_DELAY_MS 2000
+/**
+ * struct mma8452_data - IIO device private data structure
+ * @client: the I2C client object
+ * @lock: mutex for synchronziation of register
+ * read-modify-write sequences and holding chip in
+ * STANDBY mode while writing to registers
+ * @orientation: mounting matrix, flipped axis etc.
+ * @chip_info: chip specific data
+ * @regs: reference to voltage regulators
+ * @buffer: triggered buffer
+ * @sleep_val: time in ms to sleep while waiting for drdy
+ * @ctrl_reg1: CTRL_REG1 register shadow value
+ * @data_cfg: DATA_CFG register shadow value
+ * @open_drain: true for irq pin in open-drain mode
+ */
struct mma8452_data {
struct i2c_client *client;
struct mutex lock;
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data
2026-09-16 8:08 ` [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data Esben Haabendal
@ 2026-09-21 0:52 ` Jonathan Cameron
2026-09-21 5:30 ` Esben Haabendal
0 siblings, 1 reply; 13+ messages in thread
From: Jonathan Cameron @ 2026-09-21 0:52 UTC (permalink / raw)
To: Esben Haabendal
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner,
linux-iio, devicetree, linux-kernel, Joshua Crofts
> The struct mma8452_data is central for this driver, and it makes sense to
> have a description of the fields in it to make it easier to work with the
> driver.
>
> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
> Signed-off-by: Esben Haabendal <esben@geanix.com>
>
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index b70bc8638128..223bef4f7baf 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -104,6 +104,21 @@
>
> #define MMA8452_AUTO_SUSPEND_DELAY_MS 2000
>
> +/**
> + * struct mma8452_data - IIO device private data structure
> + * @client: the I2C client object
> + * @lock: mutex for synchronziation of register
From sashiko.
[Severity: Low]
This isn't a bug, but there's a typo here (synchronziation).
-
If nothing else shows up I'll fix it up whilst applying.
--
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data
2026-09-21 0:52 ` Jonathan Cameron
@ 2026-09-21 5:30 ` Esben Haabendal
0 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-21 5:30 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Martin Kepplinger, Sean Nyekjaer, David Lechner,
Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner,
linux-iio, devicetree, linux-kernel, Joshua Crofts
"Jonathan Cameron" <jic23@kernel.org> writes:
>> The struct mma8452_data is central for this driver, and it makes sense to
>> have a description of the fields in it to make it easier to work with the
>> driver.
>>
>> Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
>> Signed-off-by: Esben Haabendal <esben@geanix.com>
>>
>> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
>> index b70bc8638128..223bef4f7baf 100644
>> --- a/drivers/iio/accel/mma8452.c
>> +++ b/drivers/iio/accel/mma8452.c
>> @@ -104,6 +104,21 @@
>>
>> #define MMA8452_AUTO_SUSPEND_DELAY_MS 2000
>>
>> +/**
>> + * struct mma8452_data - IIO device private data structure
>> + * @client: the I2C client object
>> + * @lock: mutex for synchronziation of register
>
> From sashiko.
> [Severity: Low]
> This isn't a bug, but there's a typo here (synchronziation).
> -
> If nothing else shows up I'll fix it up whilst applying.
I will fix it in v10.
/Esben
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v9 08/10] iio: accel: mma8452: Allow open drain interrupt pin configuration
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (6 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 09/10] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 10/10] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel, Andy Shevchenko
When designing systems sharing the interrupt for mma8452 chips, it is
helpful to be able to configure the irq pin in open-drain mode (default is
push-pull).
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 223bef4f7baf..5d44f0066b1e 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -83,6 +83,8 @@
#define MMA8452_CTRL_REG2_RST BIT(6)
#define MMA8452_CTRL_REG2_MODS_SHIFT 3
#define MMA8452_CTRL_REG2_MODS_MASK 0x1b
+#define MMA8452_CTRL_REG3 0x2c
+#define MMA8452_CTRL_REG3_PP_OD BIT(0)
#define MMA8452_CTRL_REG4 0x2d
#define MMA8452_CTRL_REG5 0x2e
#define MMA8452_OFF_X 0x2f
@@ -135,6 +137,7 @@ struct mma8452_data {
int sleep_val;
u8 ctrl_reg1;
u8 data_cfg;
+ bool open_drain;
};
/**
@@ -662,6 +665,22 @@ static int mma8452_set_power_mode(struct mma8452_data *data, u8 mode)
return mma8452_change_config(data, MMA8452_CTRL_REG2, reg);
}
+static int mma8452_set_interrupt_pin_mode(struct mma8452_data *data)
+{
+ int reg;
+
+ reg = i2c_smbus_read_byte_data(data->client, MMA8452_CTRL_REG3);
+ if (reg < 0)
+ return reg;
+
+ if (data->open_drain)
+ reg |= MMA8452_CTRL_REG3_PP_OD;
+ else
+ reg &= ~MMA8452_CTRL_REG3_PP_OD;
+
+ return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG3, reg);
+}
+
/* returns >0 if in freefall mode, 0 if not or <0 if an error occurred */
static int mma8452_freefall_mode_enabled(struct mma8452_data *data)
{
@@ -1668,6 +1687,11 @@ static int mma8452_probe(struct i2c_client *client)
goto disable_regulators;
}
+ data->open_drain = device_property_read_bool(dev, "drive-open-drain");
+ ret = mma8452_set_interrupt_pin_mode(data);
+ if (ret)
+ goto trigger_cleanup;
+
data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
(MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
@@ -1795,6 +1819,10 @@ static int mma8452_runtime_resume(struct device *dev)
return ret;
}
+ ret = mma8452_set_interrupt_pin_mode(data);
+ if (ret)
+ goto runtime_resume_failed;
+
ret = mma8452_active(data);
if (ret < 0)
goto runtime_resume_failed;
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 09/10] iio: accel: mma8452: Use proper error code when missing device model
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (7 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 08/10] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
2026-09-16 8:08 ` [PATCH v9 10/10] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Joshua Crofts, Andy Shevchenko
Switch -ENODEV error on i2c_get_match_data() failure to -ENODATA to
satisfy the IIO coding style.
Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 5d44f0066b1e..5aea6bf3312a 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1594,7 +1594,7 @@ static int mma8452_probe(struct i2c_client *client)
data->chip_info = i2c_get_match_data(client);
if (!data->chip_info)
- return dev_err_probe(dev, -ENODEV, "unknown device model\n");
+ return dev_err_probe(dev, -ENODATA, "unknown device model\n");
ret = iio_read_mount_matrix(dev, &data->orientation);
if (ret)
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v9 10/10] iio: accel: mma8452: Support interrupt sharing
2026-09-16 8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
` (8 preceding siblings ...)
2026-09-16 8:08 ` [PATCH v9 09/10] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
@ 2026-09-16 8:08 ` Esben Haabendal
9 siblings, 0 replies; 13+ messages in thread
From: Esben Haabendal @ 2026-09-16 8:08 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Martin Kepplinger,
Sean Nyekjaer, David Lechner, Nuno Sá,
Andy Shevchenko, Martin Kepplinger, Christoph Muellner
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel
Adding support for sharing interrupt line with other device requires the
interrupt handler to handle runtime PM suspension properly, ignoring the
irq if the device is suspended (maybe even off). And while at it, we use
the PM reference to ensure we do not get suspended while processing an irq.
In order to prevent the chip from raising irq while suspended (that is when
using fixed regulator, where suspend just means setting the device in
STANDBY mode), we disable all interrupt sources by clearing CTRL_REG4, and
then restores the value again when resuming.
The scoped_guard in mma8452_runtime_suspend() is changed to a plain
mutex_lock() instead, both to prevent mixing guards and goto, but also to
ensure that we stay in STANDBY mode while writing to CTRL_REG4 and all the
way up to disabling the device as much as possible.
With that in place, it is safe to add the IRQF_SHARED flag.
Keep in mind that the device by default is using push-pull for the irq pin,
which might require additional hardware design to allow interrupt sharing.
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/accel/mma8452.c | 88 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 75 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 5aea6bf3312a..2a980c0c2e03 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -119,6 +119,7 @@
* @sleep_val: time in ms to sleep while waiting for drdy
* @ctrl_reg1: CTRL_REG1 register shadow value
* @data_cfg: DATA_CFG register shadow value
+ * @ctrl_reg4: CTRL_REG4 register value to restore on resume
* @open_drain: true for irq pin in open-drain mode
*/
struct mma8452_data {
@@ -137,6 +138,7 @@ struct mma8452_data {
int sleep_val;
u8 ctrl_reg1;
u8 data_cfg;
+ u8 ctrl_reg4;
bool open_drain;
};
@@ -1086,15 +1088,28 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
{
struct iio_dev *indio_dev = p;
struct mma8452_data *data = iio_priv(indio_dev);
+ struct device *dev = &data->client->dev;
irqreturn_t ret = IRQ_NONE;
+ int pm_status;
int src;
+ pm_status = pm_runtime_get_if_active(dev);
+ if (pm_status == 0)
+ return IRQ_NONE; /* device is powered down */
+
+ /*
+ * pm_status is now 1 or -EINVAL. If pm_status==1, runtime PM is enabled
+ * and device is RPM_ACTIVE. If pm_status==-EINVAL, runtime PM is
+ * disabled (e.g. CONFIG_PM not enabled), and we can/must assume device
+ * is active.
+ */
+
src = i2c_smbus_read_byte_data(data->client, MMA8452_INT_SRC);
if (src < 0)
- return IRQ_NONE;
+ goto out_runtime_put;
if (!(src & (data->chip_info->enabled_events | MMA8452_INT_DRDY)))
- return IRQ_NONE;
+ goto out_runtime_put;
if (src & MMA8452_INT_DRDY) {
iio_trigger_poll_nested(indio_dev->trig);
@@ -1120,6 +1135,10 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
ret = IRQ_HANDLED;
}
+out_runtime_put:
+ if (pm_status > 0)
+ pm_runtime_put_autosuspend(dev);
+
return ret;
}
@@ -1715,7 +1734,7 @@ static int mma8452_probe(struct i2c_client *client)
dev_info(dev, "invalid irq type, setting default active low\n");
irq_flags = IRQF_TRIGGER_LOW;
}
- irq_flags |= IRQF_ONESHOT;
+ irq_flags |= IRQF_ONESHOT | IRQF_SHARED;
ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
irq_flags, client->name, indio_dev);
if (ret)
@@ -1771,11 +1790,12 @@ static void mma8452_remove(struct i2c_client *client)
iio_device_unregister(indio_dev);
- pm_runtime_disable(dev);
- pm_runtime_set_suspended(dev);
-
if (client->irq)
free_irq(client->irq, indio_dev);
+ /* No irq will fire beyond this point */
+
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
iio_triggered_buffer_cleanup(indio_dev);
mma8452_trigger_cleanup(indio_dev);
@@ -1787,29 +1807,67 @@ static void mma8452_remove(struct i2c_client *client)
#ifdef CONFIG_PM
static int mma8452_runtime_suspend(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct i2c_client *client = to_i2c_client(dev);
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct mma8452_data *data = iio_priv(indio_dev);
int ret;
- scoped_guard(mutex, &data->lock)
- ret = mma8452_standby(data);
+ mutex_lock(&data->lock);
+
+ ret = mma8452_standby(data);
if (ret < 0) {
- dev_err(dev, "powering off device failed\n");
- return -EAGAIN;
+ dev_err(dev, "transition to STANDBY mode failed\n");
+ ret = -EAGAIN;
+ goto out_unlock;
}
+ ret = i2c_smbus_read_byte_data(client, MMA8452_CTRL_REG4);
+ if (ret < 0) {
+ dev_warn(dev, "backing up CTRL_REG4 failed\n");
+ ret = -EAGAIN;
+ goto out_active;
+ } else
+ data->ctrl_reg4 = ret;
+
+ ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG4, 0);
+ if (ret) {
+ dev_warn(dev, "disabling interrupt sources (CTRL_REG4) failed\n");
+ ret = -EAGAIN;
+ goto out_active;
+ }
+
+ /*
+ * Interrupt line should be deasserted now, so we just need ensure any
+ * mid-flight irq is completed (will return IRQ_NONE due to
+ * pm_status==0).
+ */
+ if (client->irq)
+ synchronize_irq(client->irq);
+
ret = regulator_bulk_disable(ARRAY_SIZE(data->regs), data->regs);
if (ret) {
dev_err(dev, "failed to disable regulators\n");
- return ret;
+ goto out_restore_ctrl_reg4;
}
+ mutex_unlock(&data->lock);
return 0;
+
+out_restore_ctrl_reg4:
+ if (i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG4, data->ctrl_reg4))
+ dev_warn(dev, "restoring CTRL_REG4 failed\n");
+out_active:
+ if (mma8452_active(data))
+ dev_warn(dev, "failed to switch back to ACTIVE mode\n");
+out_unlock:
+ mutex_unlock(&data->lock);
+ return ret;
}
static int mma8452_runtime_resume(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct i2c_client *client = to_i2c_client(dev);
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct mma8452_data *data = iio_priv(indio_dev);
int ret, sleep_val;
@@ -1823,6 +1881,10 @@ static int mma8452_runtime_resume(struct device *dev)
if (ret)
goto runtime_resume_failed;
+ ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG4, data->ctrl_reg4);
+ if (ret)
+ goto runtime_resume_failed;
+
ret = mma8452_active(data);
if (ret < 0)
goto runtime_resume_failed;
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread