Skip to contentSkip to conversation

iio: mma8452: support either of the available interrupt pins

PATCH Superseded Martin Kepplinger 3 participants 5 messages Oct 14, 2015 – Oct 15, 2015

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iio: mma8452: support either of the available interrupt pins

This change is important in order for everyone to be easily able to use the driver for one of the supported accelerometer chips!

Until now, the driver blindly assumed that the INT1 interrupt line is wired on a user's board. But these devices have 2 interrupt lines and can route their different interrupt sources to one of them. Since only their motion detection interrupt source is implemented as IIO events, users just use either one of the pins.

Of course, this also falls back to assuming INT1, so for existing users nothing will break. The new functionality is described in the bindings doc.

---
changelog:
v3: correctly assign irq if both pins are described in DT. thanks again
v2: don't warn but normally handle if both pins are described in dts
thanks Mark Rutland
v1: initial post

 .../devicetree/bindings/iio/accel/mma8452.txt      |  6 +++++
 drivers/iio/accel/mma8452.c                        | 26 +++++++++++++++++-----
 2 files changed, 26 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/iio/accel/mma8452.txt +6 -0
index e3c3746..3c10e85 100644
@@ -7,13 +7,18 @@ Required properties:
     * "fsl,mma8453"
     * "fsl,mma8652"
     * "fsl,mma8653"
+
   - reg: the I2C address of the chip
 
 Optional properties:
 
   - interrupt-parent: should be the phandle for the interrupt controller
+
   - interrupts: interrupt mapping for GPIO IRQ
 
+  - interrupt-names: should contain "INT1" and/or "INT2", the accelerometer's
+		     interrupt line in use.
+
 Example:
 
 	mma8453fc@1d {
@@ -21,4 +26,5 @@ Example:
 		reg = <0x1d>;
 		interrupt-parent = <&gpio1>;
 		interrupts = <5 0>;
+		interrupt-names = "INT2";
 	};
drivers/iio/accel/mma8452.c +20 -6
index 1eccc2d..6b9b360 100644
@@ -29,6 +29,7 @@
 #include <linux/iio/events.h>
 #include <linux/delay.h>
 #include <linux/of_device.h>
+#include <linux/of_irq.h>
 
 #define MMA8452_STATUS				0x00
 #define  MMA8452_STATUS_DRDY			(BIT(2) | BIT(1) | BIT(0))
@@ -1130,13 +1131,26 @@ static int mma8452_probe(struct i2c_client *client,
 					   MMA8452_INT_FF_MT;
 		int enabled_interrupts = MMA8452_INT_TRANS |
 					 MMA8452_INT_FF_MT;
+		int irq1, irq2;
 
-		/* Assume wired to INT1 pin */
-		ret = i2c_smbus_write_byte_data(client,
-						MMA8452_CTRL_REG5,
-						supported_interrupts);
-		if (ret < 0)
-			return ret;
+		irq1 = of_irq_get_byname(client->dev.of_node, "INT1");
+		irq2 = of_irq_get_byname(client->dev.of_node, "INT2");
+
+		/* if INT2 is found, use it. Otherwise INT1 */
+		if (!(irq2 > 0 && irq1 < 0)) {
+			ret = i2c_smbus_write_byte_data(client,
+							MMA8452_CTRL_REG5,
+							supported_interrupts);
+			if (ret < 0)
+				return ret;
+
+			if (irq1 > 0)
+				client->irq = irq1;
+			dev_info(&client->dev, "using interrupt line INT1\n");
+		} else {
+			client->irq = irq2;
+			dev_info(&client->dev, "using interrupt line INT2\n");
+		}
 
 		ret = i2c_smbus_write_byte_data(client,
 						MMA8452_CTRL_REG4,
Signature · 1 line
2.1.4
#1 lore raw

On 10/14/2015 03:15 PM, Martin Kepplinger wrote:
[...]

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1148

Quoted 2 lines
drivers/iio/accel/mma8452.c +2 -0
+			if (irq1 > 0)
+				client->irq = irq1;

You must not overwrite client->irq, that field is manged by the I2C core and is supposed to be read only for device drivers.

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1149

Quoted 1 line
drivers/iio/accel/mma8452.c +1 -0
+			dev_info(&client->dev, "using interrupt line INT1\n");

This should probably be a dev_dbg()

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1152

Quoted 3 lines
drivers/iio/accel/mma8452.c +3 -0
+		} else {
+			client->irq = irq2;
+			dev_info(&client->dev, "using interrupt line INT2\n");

Same here

Quoted 1 line
drivers/iio/accel/mma8452.c +1 -0
+		}
#2 lore raw

Am 2015-10-14 um 17:12 schrieb Lars-Peter Clausen:

Quoted 8 lines · Martin Kepplinger

[...]

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1148

Quoted 2 lines
drivers/iio/accel/mma8452.c +2 -0
+			if (irq1 > 0)
+				client->irq = irq1;

You must not overwrite client->irq, that field is manged by the I2C core and is supposed to be read only for device drivers.

I thought about it again and before I implement it, let me show you:

since interrupt-names would be "invented" anyways ("INT1", "INT2"), here's an idea for the bindings doc that would be a more long-term solution to implement:

- interrupts: interrupt mapping for GPIO IRQ

These devices have two interrupt pins called INT1 and INT2 they can route their different interrupt sources to:

IRQ Name Interrupt Source Wired Pin
-------- ---------------- ---------
DATA_READY_1 data ready INT1
DATA_READY_2 INT2
MOTION_1 motion events INT1
MOTION_2 INT2
INT1 all INT1
INT2 INT2

- interrupt-names: should contain IRQ Names in the order in which they were supplied in the interrupts property.

Depending on how your chip is wired and what interrupt sources should be handled by the driver, choose one IRQ Name per Interrupt source, or INT1/INT2 for all sources to one pin here.

Example 1:

        mma8453fc@1d {
                compatible = "fsl,mma8453";
                reg = <0x1d>;
                interrupt-parent = <&gpio1>;
                interrupts = <5 0>;
                interrupt-names = "INT2"; // interrupt pin wired to INT2
        };

Example 2:

        mma8453fc@1d {
                compatible = "fsl,mma8453";
                reg = <0x1d>;
                interrupt-parent = <&gpio1>;
                interrupts = <4 0>, <5 0>;
                /* data ready comes from INT2, motion events from INT1 */
                interrupt-names = "DATA_READY_2", "MOTION_1";
        };

What do you think?

thanks
martin

#3 lore raw
Quoted 12 lines · Martin Kepplinger

Am 2015-10-14 um 17:12 schrieb Lars-Peter Clausen:

Quoted 8 lines · Martin Kepplinger

[...]

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1148

Quoted 2 lines
drivers/iio/accel/mma8452.c +2 -0
+			if (irq1 > 0)
+				client->irq = irq1;

You must not overwrite client->irq, that field is manged by the I2C core and is supposed to be read only for device drivers.

I thought about it again and before I implement it, let me show you:

Quoted 8 lines

since interrupt-names would be "invented" anyways ("INT1", "INT2"), here's an idea for the bindings doc that would be a more long-term solution to implement:

- interrupts: interrupt mapping for GPIO IRQ

These devices have two interrupt pins called INT1 and INT2 they can route their different interrupt sources to:

This being the case, the binding should only talk about INT1 and INT2. The names might be "invented", but they describe the physical pins on the device, and thus describe a physical property of the device.

Quoted 9 lines
        IRQ Name        Interrupt Source        Wired Pin
        --------        ----------------        ---------
        DATA_READY_1    data ready              INT1
        DATA_READY_2                            INT2
        MOTION_1        motion events           INT1
        MOTION_2                                INT2
        INT1            all                     INT1
        INT2                                    INT2
Quoted 7 lines

- interrupt-names: should contain IRQ Names in the order in which they were supplied in the interrupts property.

Depending on how your chip is wired and what interrupt sources should be handled by the driver, choose one IRQ Name per Interrupt source, or INT1/INT2 for all sources to one pin here.

The configuration of logical interrupts to those physical pins is a choice that can be made at runtime, and should not live in the DT. It is not a property of the hardware.

Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Lars-Peter Clausen
Quoted 7 lines · Lars-Peter Clausen

On 10/14/2015 03:15 PM, Martin Kepplinger wrote:
[...]

drivers/iio/accel/mma8452.c static int mma8452_probe(struct i2c_client *client, · line 1148

Quoted 2 lines
drivers/iio/accel/mma8452.c +2 -0
+			if (irq1 > 0)
+				client->irq = irq1;

You must not overwrite client->irq, that field is manged by the I2C core and is supposed to be read only for device drivers.

Ok.

I think for the moment the simlpest thing to do would be to check which of INT1 and INT2 match client->irq, and use that.

Thanks,
Mark.