The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration
@ 2026-07-15 12:33 Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 1/3] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Esben Haabendal @ 2026-07-15 12:33 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
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel

Extend the mma8452 driver with support for configuration of the
interrupt line in open-drain mode, which is needed for hardware designs
where the interrupt line is shared with other chips.

Adding drive-open-drain property to mma8452 device-tree node for such
designs to enable switching pin configuration to open-drain mode.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Changes in v2:
- Commit message of patch 2 updated.
- Operator precedence bug fixed in flags argument to
  request_threaded_irq().
- Always check return value of mma8452_set_interrupt_pin_mode(), and just
  check for non-zero value.
- Added new patch with optimization of struct mma8452_data ordering.
- Link to v1: https://patch.msgid.link/20260715-mma8452-open-drain-v1-0-b1dd2a440c60@geanix.com

To: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Martin Kepplinger <martink@posteo.de>
To: Sean Nyekjaer <sean@geanix.com>
To: David Lechner <dlechner@baylibre.com>
To: Nuno Sá <nuno.sa@analog.com>
To: Andy Shevchenko <andy@kernel.org>
To: Martin Kepplinger <martin.kepplinger@theobroma-systems.com>
Cc: linux-iio@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

---
Esben Haabendal (3):
      dt-bindings: iio: accel: mma8452: Add drive-open-drain
      iio: accel: mma8452: Allow open drain interrupt pin configuration
      iio: accel: mma8452: Optimize struct mm8452_data member orders

 .../devicetree/bindings/iio/accel/fsl,mma8452.yaml |  6 ++++
 drivers/iio/accel/mma8452.c                        | 38 +++++++++++++++++++---
 2 files changed, 40 insertions(+), 4 deletions(-)
---
base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
change-id: 20250401-mma8452-open-drain-81577c41375c

Best regards,
--  
Esben Haabendal <esben@geanix.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] dt-bindings: iio: accel: mma8452: Add drive-open-drain
  2026-07-15 12:33 [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-07-15 12:33 ` Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 2/3] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Esben Haabendal @ 2026-07-15 12:33 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
  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.

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 related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] iio: accel: mma8452: Allow open drain interrupt pin configuration
  2026-07-15 12:33 [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 1/3] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
@ 2026-07-15 12:33 ` Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders Esben Haabendal
  2026-07-15 13:55 ` [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Andy Shevchenko
  3 siblings, 0 replies; 7+ messages in thread
From: Esben Haabendal @ 2026-07-15 12:33 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
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel

When sharing interrupt line with other chips, the interrupt pin most
likely needs to be configured in open-drain mode instead of push-pull.

The PP_OD bit in CTRL_REG3 is set when open-drain mode is configured,
allowing sharing the interrupt line with other devices (with same interrupt
polarity).
The IRQF_SHARED flag is added to request_threaded_irq() flags, indicating
that the interrupt line can be shared with other devices.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/accel/mma8452.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 7d683686dd9d..fdf7364d7fed 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -81,6 +81,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
@@ -108,6 +110,7 @@ struct mma8452_data {
 	struct iio_mount_matrix orientation;
 	u8 ctrl_reg1;
 	u8 data_cfg;
+	bool open_drain;
 	const struct mma_chip_info *chip_info;
 	int sleep_val;
 	struct regulator *vdd_reg;
@@ -646,6 +649,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)
 {
@@ -1666,6 +1685,11 @@ static int mma8452_probe(struct i2c_client *client)
 			goto disable_regulators;
 	}
 
+	data->open_drain = device_property_read_bool(&client->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);
 
@@ -1683,7 +1707,8 @@ static int mma8452_probe(struct i2c_client *client)
 
 	if (client->irq) {
 		ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
-					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					   IRQF_TRIGGER_LOW | IRQF_ONESHOT |
+					   (data->open_drain ? IRQF_SHARED : 0),
 					   client->name, indio_dev);
 		if (ret)
 			goto buffer_cleanup;
@@ -1800,6 +1825,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 related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders
  2026-07-15 12:33 [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 1/3] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
  2026-07-15 12:33 ` [PATCH v2 2/3] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
@ 2026-07-15 12:33 ` Esben Haabendal
  2026-07-15 13:02   ` Joshua Crofts
  2026-07-15 13:08   ` Joshua Crofts
  2026-07-15 13:55 ` [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Andy Shevchenko
  3 siblings, 2 replies; 7+ messages in thread
From: Esben Haabendal @ 2026-07-15 12:33 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
  Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel

Reorder struct mma8452_data members to avoid holes.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 drivers/iio/accel/mma8452.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index fdf7364d7fed..537263085215 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -108,11 +108,7 @@ struct mma8452_data {
 	struct i2c_client *client;
 	struct mutex lock;
 	struct iio_mount_matrix orientation;
-	u8 ctrl_reg1;
-	u8 data_cfg;
-	bool open_drain;
 	const struct mma_chip_info *chip_info;
-	int sleep_val;
 	struct regulator *vdd_reg;
 	struct regulator *vddio_reg;
 
@@ -121,6 +117,11 @@ struct mma8452_data {
 		__be16 channels[3];
 		aligned_s64 ts;
 	} buffer;
+
+	int sleep_val;
+	u8 ctrl_reg1;
+	u8 data_cfg;
+	bool open_drain;
 };
 
  /**

-- 
2.55.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders
  2026-07-15 12:33 ` [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders Esben Haabendal
@ 2026-07-15 13:02   ` Joshua Crofts
  2026-07-15 13:08   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-07-15 13:02 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, linux-iio, devicetree, linux-kernel

On Wed, 15 Jul 2026 14:33:29 +0200
Esben Haabendal <esben@geanix.com> wrote:

> Reorder struct mma8452_data members to avoid holes.
> 
> Signed-off-by: Esben Haabendal <esben@geanix.com>
> ---
>  drivers/iio/accel/mma8452.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index fdf7364d7fed..537263085215 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -108,11 +108,7 @@ struct mma8452_data {
>  	struct i2c_client *client;
>  	struct mutex lock;
>  	struct iio_mount_matrix orientation;
> -	u8 ctrl_reg1;
> -	u8 data_cfg;
> -	bool open_drain;
>  	const struct mma_chip_info *chip_info;
> -	int sleep_val;
>  	struct regulator *vdd_reg;
>  	struct regulator *vddio_reg;
>  
> @@ -121,6 +117,11 @@ struct mma8452_data {
>  		__be16 channels[3];
>  		aligned_s64 ts;
>  	} buffer;
> +
> +	int sleep_val;
> +	u8 ctrl_reg1;
> +	u8 data_cfg;
> +	bool open_drain;
>  };
>  
>   /**
> 

LGTM.

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders
  2026-07-15 12:33 ` [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders Esben Haabendal
  2026-07-15 13:02   ` Joshua Crofts
@ 2026-07-15 13:08   ` Joshua Crofts
  1 sibling, 0 replies; 7+ messages in thread
From: Joshua Crofts @ 2026-07-15 13:08 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, linux-iio, devicetree, linux-kernel

On Wed, 15 Jul 2026 14:33:29 +0200
Esben Haabendal <esben@geanix.com> wrote:

> Reorder struct mma8452_data members to avoid holes.
> 
> Signed-off-by: Esben Haabendal <esben@geanix.com>
> ---
>  drivers/iio/accel/mma8452.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index fdf7364d7fed..537263085215 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -108,11 +108,7 @@ struct mma8452_data {
>  	struct i2c_client *client;
>  	struct mutex lock;
>  	struct iio_mount_matrix orientation;
> -	u8 ctrl_reg1;
> -	u8 data_cfg;
> -	bool open_drain;
>  	const struct mma_chip_info *chip_info;
> -	int sleep_val;
>  	struct regulator *vdd_reg;
>  	struct regulator *vddio_reg;
>  
> @@ -121,6 +117,11 @@ struct mma8452_data {
>  		__be16 channels[3];
>  		aligned_s64 ts;
>  	} buffer;
> +
> +	int sleep_val;
> +	u8 ctrl_reg1;
> +	u8 data_cfg;
> +	bool open_drain;
>  };

Also quick thing, in order to prevent too much cruft, could you
please move this patch before patch 2? You introduce the bool in
2 and then move it to the end in 3, better for you to reorder it
first and add the bool after, otherwise you get these "ping-pong"
style changes (Andy's words). My reviewed-by still stands either way,
so feel free to add it once reordered.

-- 
Kind regards

CJD

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration
  2026-07-15 12:33 [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
                   ` (2 preceding siblings ...)
  2026-07-15 12:33 ` [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders Esben Haabendal
@ 2026-07-15 13:55 ` Andy Shevchenko
  3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-07-15 13:55 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, linux-iio, devicetree, linux-kernel

On Wed, Jul 15, 2026 at 02:33:26PM +0200, Esben Haabendal wrote:
> Extend the mma8452 driver with support for configuration of the
> interrupt line in open-drain mode, which is needed for hardware designs
> where the interrupt line is shared with other chips.
> 
> Adding drive-open-drain property to mma8452 device-tree node for such
> designs to enable switching pin configuration to open-drain mode.

NAK.

Please, do not send a new version until everything is settled down in the
previous round. Let's continue discussion in v1.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-15 13:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 12:33 [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-07-15 12:33 ` [PATCH v2 1/3] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-07-15 12:33 ` [PATCH v2 2/3] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-07-15 12:33 ` [PATCH v2 3/3] iio: accel: mma8452: Optimize struct mm8452_data member orders Esben Haabendal
2026-07-15 13:02   ` Joshua Crofts
2026-07-15 13:08   ` Joshua Crofts
2026-07-15 13:55 ` [PATCH v2 0/3] io: accel: mma8452: Allow open drain interrupt pin configuration Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox