Skip to contentSkip to conversation

iio: accel: bmc150: Add support for INT2 and BMC156

PATCH Superseded Stephan Gerhold 5 participants 27 messages Jul 19, 2021 – Jul 31, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover iio: accel: bmc150: Add support for INT2 and BMC156

This series makes it possible to set up interrupts with the BMC150 driver on boards where only the INT2 pin is connected (and not INT1). This is particularly always the case for BMC156 since for some reason it only has the INT2 pin and not the INT1 pin.

These changes were already partially discussed here:
https://lore.kernel.org/linux-iio/[email protected]/

Stephan Gerhold (4):
dt-bindings: iio: accel: bma255: Add interrupt-names
dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel
iio: accel: bmc150: Make it possible to configure INT2 instead of INT1
iio: accel: bmc150: Add support for BMC156

 .../bindings/iio/accel/bosch,bma255.yaml      | 27 +++++++
 drivers/iio/accel/Kconfig                     |  5 +-
 drivers/iio/accel/bmc150-accel-core.c         | 77 +++++++++++++++----
 drivers/iio/accel/bmc150-accel-i2c.c          | 10 ++-
 drivers/iio/accel/bmc150-accel-spi.c          | 10 ++-
 drivers/iio/accel/bmc150-accel.h              |  9 ++-
 6 files changed, 118 insertions(+), 20 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/4 dt-bindings: iio: accel: bma255: Add interrupt-names

The binding already allows specifying both interrupt pins, but there is currently no way to describe a board where (for whatever reason) only INT2 is connected. Make it possible to use "interrupt-names" to make it explicit which interrupt pin is meant in the interrupts.

---
 .../devicetree/bindings/iio/accel/bosch,bma255.yaml      | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +9 -0
index 5b35856b1942..897a1d808ef5 100644
@@ -49,6 +49,14 @@ properties:
       the second (optional) interrupt listed must be the one connected to the
       INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING.
 
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      enum:
+        - INT1
+        - INT2
+
   mount-matrix:
     description: an optional 3x3 mounting rotation matrix.
 
@@ -73,6 +81,7 @@ examples:
             vddio-supply = <&vddio>;
             vdd-supply = <&vdd>;
             interrupts = <57 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT1";
         };
     };
   - |
Signature · 1 line
2.32.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] dt-bindings: iio: accel: bma255: Add interrupt-names

Quoted 6 lines · Stephan Gerhold

The binding already allows specifying both interrupt pins, but there is currently no way to describe a board where (for whatever reason) only INT2 is connected. Make it possible to use "interrupt-names" to make it explicit which interrupt pin is meant in the interrupts.

Yours,
Linus Walleij

maintainer
#3 lore raw

Re: [PATCH 1/4] dt-bindings: iio: accel: bma255: Add interrupt-names

In reply to Stephan Gerhold
Quoted 15 lines · On Mon, 19 Jul 2021 13:21:53 +0200 Stephan Gerhold <[email protected]> wrote:

The binding already allows specifying both interrupt pins, but there is currently no way to describe a board where (for whatever reason) only INT2 is connected. Make it possible to use "interrupt-names" to make it explicit which interrupt pin is meant in the interrupts.

---
 .../devicetree/bindings/iio/accel/bosch,bma255.yaml      | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +0 -0
index 5b35856b1942..897a1d808ef5 100644

Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml properties: · line 50

Quoted 2 lines
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +0 -0
@@ -49,6 +49,14 @@ properties:
       the second (optional) interrupt listed must be the one connected to the
       INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING.

Looks like this comment needs updating to say the ordering is only true if interrupt-names is not present.

Jonathan

Quoted 20 lines
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +9 -0
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      enum:
+        - INT1
+        - INT2
+
   mount-matrix:
     description: an optional 3x3 mounting rotation matrix.
 
@@ -73,6 +81,7 @@ examples:
             vddio-supply = <&vddio>;
             vdd-supply = <&vdd>;
             interrupts = <57 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT1";
         };
     };
   - |
#4 lore raw

PATCH 2/4 dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel

In reply to Stephan Gerhold

BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156.

---
 .../bindings/iio/accel/bosch,bma255.yaml       | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +18 -0
index 897a1d808ef5..f7848e4a7b29 100644
@@ -26,6 +26,7 @@ properties:
       - bosch,bma255
       - bosch,bma280
       - bosch,bmc150_accel
+      - bosch,bmc156_accel
       - bosch,bmi055_accel
 
       # bma180 driver in Linux
@@ -49,6 +50,9 @@ properties:
       the second (optional) interrupt listed must be the one connected to the
       INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING.
 
+      BMC156 does not have an INT1 pin, therefore the first interrupt pin is
+      always treated as INT2.
+
   interrupt-names:
     minItems: 1
     maxItems: 2
@@ -84,6 +88,20 @@ examples:
             interrupt-names = "INT1";
         };
     };
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        accelerometer@10 {
+            compatible = "bosch,bmc156_accel";
+            reg = <0x10>;
+            vddio-supply = <&vddio>;
+            vdd-supply = <&vdd>;
+            interrupts = <116 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT2";
+        };
+    };
   - |
     # include <dt-bindings/interrupt-controller/irq.h>
     spi {
Signature · 1 line
2.32.0
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel

Quoted 9 lines · Stephan Gerhold

BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156.

Yours,
Linus Walleij

maintainer
#6 lore raw

Re: [PATCH 2/4] dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel

In reply to Stephan Gerhold
Quoted 26 lines · On Mon, 19 Jul 2021 13:21:54 +0200 Stephan Gerhold <[email protected]> wrote:

BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156.

---
 .../bindings/iio/accel/bosch,bma255.yaml       | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +1 -0
index 897a1d808ef5..f7848e4a7b29 100644
@@ -26,6 +26,7 @@ properties:
       - bosch,bma255
       - bosch,bma280
       - bosch,bmc150_accel
+      - bosch,bmc156_accel
       - bosch,bmi055_accel
 
       # bma180 driver in Linux

Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml properties: · line 54

Quoted 5 lines
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +2 -0
@@ -49,6 +50,9 @@ properties:
       the second (optional) interrupt listed must be the one connected to the
       INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING.
 
+      BMC156 does not have an INT1 pin, therefore the first interrupt pin is
+      always treated as INT2.

We 'could' enforce any name present for the bmc156 to be INT2, but we probably still want the fallback you have in the driver to handle the case of not interrupt-name provided.

Rob, do you think it's worth the complexity for this corner case?

Jonathan

Quoted 25 lines
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +15 -0
+
   interrupt-names:
     minItems: 1
     maxItems: 2
@@ -84,6 +88,20 @@ examples:
             interrupt-names = "INT1";
         };
     };
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        accelerometer@10 {
+            compatible = "bosch,bmc156_accel";
+            reg = <0x10>;
+            vddio-supply = <&vddio>;
+            vdd-supply = <&vdd>;
+            interrupts = <116 IRQ_TYPE_EDGE_RISING>;
+            interrupt-names = "INT2";
+        };
+    };
   - |
     # include <dt-bindings/interrupt-controller/irq.h>
     spi {
maintainer
#7 lore raw

Re: [PATCH 2/4] dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel

Quoted 32 lines · Jonathan Cameron
Quoted 29 lines · On Mon, 19 Jul 2021 13:21:54 +0200 Stephan Gerhold <[email protected]> wrote:

BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156.

---
 .../bindings/iio/accel/bosch,bma255.yaml       | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +1 -0
index 897a1d808ef5..f7848e4a7b29 100644
@@ -26,6 +26,7 @@ properties:
       - bosch,bma255
       - bosch,bma280
       - bosch,bmc150_accel
+      - bosch,bmc156_accel
       - bosch,bmi055_accel
 
       # bma180 driver in Linux
@@ -49,6 +50,9 @@ properties:
       the second (optional) interrupt listed must be the one connected to the
       INT2 pin (if available). The type should be IRQ_TYPE_EDGE_RISING.
 
Quoted 8 lines

Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml properties: · line 54

Quoted 2 lines
Documentation/devicetree/bindings/iio/accel/bosch,bma255.yaml +2 -0
+      BMC156 does not have an INT1 pin, therefore the first interrupt pin is
+      always treated as INT2.

We 'could' enforce any name present for the bmc156 to be INT2, but we probably still want the fallback you have in the driver to handle the case of not interrupt-name provided.

Rob, do you think it's worth the complexity for this corner case?

No.

Rob

maintainer Reviewed-by on v1 2/4
#8 lore raw

Re: [PATCH 2/4] dt-bindings: iio: accel: bma255: Add bosch,bmc156_accel

In reply to Stephan Gerhold
Quoted 4 lines · Stephan Gerhold

BMC156 is very smilar to BMC150, but it has only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Quoted 9 lines

In this case, it does not make sense if the first interrupt pin is treated as INT1 (since that pin does not exist). Add a note to the bindings that the first interrupt pin is treated as INT2 for BMC156.

---
 .../bindings/iio/accel/bosch,bma255.yaml       | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
#9 lore raw

PATCH 3/4 iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

In reply to Stephan Gerhold

Some Bosch accelerometers have two interrupt pins (INT1 and INT2). At the moment, the driver uses only the first one, which is fine for most situations. However, some boards might only have INT2 connected for some reason.

Add the necessary bits and configuration to set up INT2. Then try to detect this situation at least for device tree setups by checking if the first interrupt (the one picked by the I2C/SPI core) is actually named "INT2" using the interrupt-names property.

of_irq_get_byname() returns either 0 or some error code in case the driver probed without device tree, so in all other cases we fall back to configuring INT1 as before.

---
 drivers/iio/accel/bmc150-accel-core.c | 71 ++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 12 deletions(-)
drivers/iio/accel/bmc150-accel-core.c +59 -12
index 5ce384ebe6c7..8d3dd3c2bcc2 100644
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
+#include <linux/of_irq.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/iio/iio.h>
@@ -57,12 +58,18 @@
 #define BMC150_ACCEL_RESET_VAL			0xB6
 
 #define BMC150_ACCEL_REG_INT_MAP_0		0x19
-#define BMC150_ACCEL_INT_MAP_0_BIT_SLOPE	BIT(2)
+#define BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE	BIT(2)
 
 #define BMC150_ACCEL_REG_INT_MAP_1		0x1A
-#define BMC150_ACCEL_INT_MAP_1_BIT_DATA		BIT(0)
-#define BMC150_ACCEL_INT_MAP_1_BIT_FWM		BIT(1)
-#define BMC150_ACCEL_INT_MAP_1_BIT_FFULL	BIT(2)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA	BIT(0)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM	BIT(1)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT1_FFULL	BIT(2)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FFULL	BIT(5)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM	BIT(6)
+#define BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA	BIT(7)
+
+#define BMC150_ACCEL_REG_INT_MAP_2		0x1B
+#define BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE	BIT(2)
 
 #define BMC150_ACCEL_REG_INT_RST_LATCH		0x21
 #define BMC150_ACCEL_INT_MODE_LATCH_RESET	0x80
@@ -81,6 +88,7 @@
 
 #define BMC150_ACCEL_REG_INT_OUT_CTRL		0x20
 #define BMC150_ACCEL_INT_OUT_CTRL_INT1_LVL	BIT(0)
+#define BMC150_ACCEL_INT_OUT_CTRL_INT2_LVL	BIT(2)
 
 #define BMC150_ACCEL_REG_INT_5			0x27
 #define BMC150_ACCEL_SLOPE_DUR_MASK		0x03
@@ -476,21 +484,24 @@ static bool bmc150_apply_acpi_orientation(struct device *dev,
 }
 #endif
 
-static const struct bmc150_accel_interrupt_info {
+struct bmc150_accel_interrupt_info {
 	u8 map_reg;
 	u8 map_bitmask;
 	u8 en_reg;
 	u8 en_bitmask;
-} bmc150_accel_interrupts[BMC150_ACCEL_INTERRUPTS] = {
+};
+
+static const struct bmc150_accel_interrupt_info
+bmc150_accel_interrupts_int1[BMC150_ACCEL_INTERRUPTS] = {
 	{ /* data ready interrupt */
 		.map_reg = BMC150_ACCEL_REG_INT_MAP_1,
-		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_DATA,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_DATA,
 		.en_reg = BMC150_ACCEL_REG_INT_EN_1,
 		.en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN,
 	},
 	{  /* motion interrupt */
 		.map_reg = BMC150_ACCEL_REG_INT_MAP_0,
-		.map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_SLOPE,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_0_BIT_INT1_SLOPE,
 		.en_reg = BMC150_ACCEL_REG_INT_EN_0,
 		.en_bitmask =  BMC150_ACCEL_INT_EN_BIT_SLP_X |
 			BMC150_ACCEL_INT_EN_BIT_SLP_Y |
@@ -498,19 +509,55 @@ static const struct bmc150_accel_interrupt_info {
 	},
 	{ /* fifo watermark interrupt */
 		.map_reg = BMC150_ACCEL_REG_INT_MAP_1,
-		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_FWM,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT1_FWM,
+		.en_reg = BMC150_ACCEL_REG_INT_EN_1,
+		.en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN,
+	},
+};
+
+static const struct bmc150_accel_interrupt_info
+bmc150_accel_interrupts_int2[BMC150_ACCEL_INTERRUPTS] = {
+	{ /* data ready interrupt */
+		.map_reg = BMC150_ACCEL_REG_INT_MAP_1,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_DATA,
+		.en_reg = BMC150_ACCEL_REG_INT_EN_1,
+		.en_bitmask = BMC150_ACCEL_INT_EN_BIT_DATA_EN,
+	},
+	{  /* motion interrupt */
+		.map_reg = BMC150_ACCEL_REG_INT_MAP_2,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_2_BIT_INT2_SLOPE,
+		.en_reg = BMC150_ACCEL_REG_INT_EN_0,
+		.en_bitmask =  BMC150_ACCEL_INT_EN_BIT_SLP_X |
+			BMC150_ACCEL_INT_EN_BIT_SLP_Y |
+			BMC150_ACCEL_INT_EN_BIT_SLP_Z
+	},
+	{ /* fifo watermark interrupt */
+		.map_reg = BMC150_ACCEL_REG_INT_MAP_1,
+		.map_bitmask = BMC150_ACCEL_INT_MAP_1_BIT_INT2_FWM,
 		.en_reg = BMC150_ACCEL_REG_INT_EN_1,
 		.en_bitmask = BMC150_ACCEL_INT_EN_BIT_FWM_EN,
 	},
 };
 
 static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
-					  struct bmc150_accel_data *data)
+					  struct bmc150_accel_data *data, int irq)
 {
+	const struct bmc150_accel_interrupt_info *irq_info = NULL;
+	struct device *dev = regmap_get_device(data->regmap);
 	int i;
 
+	/*
+	 * For now we map all interrupts to the same output pin.
+	 * However, some boards may have just INT2 (and not INT1) connected,
+	 * so we try to detect which IRQ it is based on the interrupt-names.
+	 * Without interrupt-names, we assume the irq belongs to INT1.
+	 */
+	irq_info = bmc150_accel_interrupts_int1;
+	if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+		irq_info = bmc150_accel_interrupts_int2;
+
 	for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
-		data->interrupts[i].info = &bmc150_accel_interrupts[i];
+		data->interrupts[i].info = &irq_info[i];
 }
 
 static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
@@ -1714,7 +1761,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 			goto err_buffer_cleanup;
 		}
 
-		bmc150_accel_interrupts_setup(indio_dev, data);
+		bmc150_accel_interrupts_setup(indio_dev, data, irq);
 
 		ret = bmc150_accel_triggers_setup(indio_dev, data);
 		if (ret)
Signature · 1 line
2.32.0
#10 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 18 lines · Stephan Gerhold

Some Bosch accelerometers have two interrupt pins (INT1 and INT2). At the moment, the driver uses only the first one, which is fine for most situations. However, some boards might only have INT2 connected for some reason.

Add the necessary bits and configuration to set up INT2. Then try to detect this situation at least for device tree setups by checking if the first interrupt (the one picked by the I2C/SPI core) is actually named "INT2" using the interrupt-names property.

of_irq_get_byname() returns either 0 or some error code in case the driver probed without device tree, so in all other cases we fall back to configuring INT1 as before.

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either. What does platform_get_irq_byname() do on ACPI systems?

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

Yours,
Linus Walleij

#11 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 20 lines · Linus Walleij
Quoted 10 lines · Stephan Gerhold

Some Bosch accelerometers have two interrupt pins (INT1 and INT2). At the moment, the driver uses only the first one, which is fine for most situations. However, some boards might only have INT2 connected for some reason.

Add the necessary bits and configuration to set up INT2. Then try to detect this situation at least for device tree setups by checking if the first interrupt (the one picked by the I2C/SPI core) is actually named "INT2" using the interrupt-names property.

Quoted 8 lines

of_irq_get_byname() returns either 0 or some error code in case the driver probed without device tree, so in all other cases we fall back to configuring INT1 as before.

#include <linux/acpi.h>
+#include <linux/of_irq.h>

Quoted 7 lines

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 36 lines · Andy Shevchenko
Quoted 20 lines · Linus Walleij
Quoted 10 lines · Stephan Gerhold

Some Bosch accelerometers have two interrupt pins (INT1 and INT2). At the moment, the driver uses only the first one, which is fine for most situations. However, some boards might only have INT2 connected for some reason.

Add the necessary bits and configuration to set up INT2. Then try to detect this situation at least for device tree setups by checking if the first interrupt (the one picked by the I2C/SPI core) is actually named "INT2" using the interrupt-names property.

Quoted 8 lines

of_irq_get_byname() returns either 0 or some error code in case the driver probed without device tree, so in all other cases we fall back to configuring INT1 as before.

#include <linux/acpi.h>
+#include <linux/of_irq.h>

Quoted 7 lines

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 9 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Thanks!
Stephan

#13 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 26 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 42 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 26 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

Stephan

#15 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 6 lines · Stephan Gerhold
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 44 lines
Quoted 35 lines
Quoted 26 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

drivers/iio/accel/bmc150-accel-core.c static const struct bmc150_accel_interrupt_info { · line 557

Quoted 3 lines
drivers/iio/accel/bmc150-accel-core.c +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Quoted 7 lines

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

I see in today's Linux Next snapshot:

drivers/iio/accel/fxls8962af-core.c:774: irq =
of_irq_get_byname(of_node, "INT2");
drivers/iio/accel/mma8452.c:1616: irq2 =
of_irq_get_byname(client->dev.of_node, "INT2"); drivers/iio/gyro/fxas21002c_core.c:834: irq1 = of_irq_get_byname(np, "INT1");
drivers/iio/imu/adis16480.c:1265: irq =
of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
drivers/iio/imu/bmi160/bmi160_core.c:655: irq =
of_irq_get_byname(of_node, "INT1");
drivers/iio/imu/bmi160/bmi160_core.c:661: irq =
of_irq_get_byname(of_node, "INT2");

I believe we may stop distributing this and actually start using a common API. I don't want this to be spread again over all IIO. Btw, I have LSM9DS0, which supports two INT pins for IMU and currently it uses hard coded pin mapping.

Side note to Jonathan, I believe the below may be (lazily) converted to fwnode / device properties APIs.

drivers/iio/adc/ab8500-gpadc.c:1041: nchans =
of_get_available_child_count(np);
drivers/iio/adc/ad7124.c:747: st->num_channels =
of_get_available_child_count(np);
drivers/iio/adc/berlin2-adc.c:287: struct device_node *parent_np
= of_get_parent(pdev->dev.of_node);
drivers/iio/adc/qcom-pm8xxx-xoadc.c:830: adc->nchans =
of_get_available_child_count(np);
drivers/iio/adc/qcom-spmi-adc5.c:650: channel_name = of_get_property(node,
drivers/iio/adc/qcom-spmi-adc5.c:813: adc->nchannels =
of_get_available_child_count(node);
drivers/iio/adc/qcom-spmi-vadc.c:743: vadc->nchannels =
of_get_available_child_count(node); drivers/iio/adc/stm32-adc.c:1630:static int stm32_adc_of_get_resolution(struct iio_dev *indio_dev)
drivers/iio/adc/stm32-adc.c:1935: ret =
stm32_adc_of_get_resolution(indio_dev);
drivers/iio/adc/xilinx-xadc-core.c:1248: chan_node =
of_get_child_by_name(np, "xlnx,channels"); drivers/iio/imu/adis16480.c:1293:static int adis16480_of_get_ext_clk_pin(struct adis16480 *st,
drivers/iio/imu/adis16480.c:1328: pin =
adis16480_of_get_ext_clk_pin(st, of_node);
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c:68: mux_node =
of_get_child_by_name(dev->of_node, "i2c-gate")
;
drivers/iio/industrialio-core.c:1877: label =
of_get_property(indio_dev->dev.of_node, "label", NULL);
drivers/iio/inkern.c:228: if (np && !of_get_property(np,
"io-channel-ranges", NULL)) drivers/iio/temperature/ltc2983.c:1275: st->num_channels = of_get_available_child_count(dev->of_node);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 76 lines · Andy Shevchenko
Quoted 6 lines · Stephan Gerhold
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 44 lines
Quoted 35 lines
Quoted 26 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

Review

Quoted 3 lines
(quoted diff) +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Quoted 7 lines

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

I see in today's Linux Next snapshot:

drivers/iio/accel/fxls8962af-core.c:774: irq =
of_irq_get_byname(of_node, "INT2");
drivers/iio/accel/mma8452.c:1616: irq2 =
of_irq_get_byname(client->dev.of_node, "INT2"); drivers/iio/gyro/fxas21002c_core.c:834: irq1 = of_irq_get_byname(np, "INT1");
drivers/iio/imu/adis16480.c:1265: irq =
of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
drivers/iio/imu/bmi160/bmi160_core.c:655: irq =
of_irq_get_byname(of_node, "INT1");
drivers/iio/imu/bmi160/bmi160_core.c:661: irq =
of_irq_get_byname(of_node, "INT2");

Quoted 5 lines

I believe we may stop distributing this and actually start using a common API. I don't want this to be spread again over all IIO. Btw, I have LSM9DS0, which supports two INT pins for IMU and currently it uses hard coded pin mapping.

Hm, I'm not quite sure how to implement this. Could you prepare a patch that would implement such a common API? I would be happy to test it for the device tree and make use of it in this patch.

To be honest, I mainly implemented support for the interrupt-names because Jonathan mentioned this would be nice to have [1] and it kind of fit well together with the BMC156 patch that needs the INT2 support. I actually just use the if (data->type == BOSCH_BMC156) part from PATCH 4/4 which does not depend on of_irq_get_byname().

Thanks,
Stephan

[1]: https://lore.kernel.org/linux-iio/20210611185941.3487efc6@jic23-huawei/

#17 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 7 lines · Stephan Gerhold
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Stephan Gerhold
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 69 lines
Quoted 63 lines
Quoted 41 lines
Quoted 32 lines
Quoted 23 lines
Quoted 14 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Quoted 7 lines

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

I see in today's Linux Next snapshot:

drivers/iio/accel/fxls8962af-core.c:774: irq =
of_irq_get_byname(of_node, "INT2");
drivers/iio/accel/mma8452.c:1616: irq2 =
of_irq_get_byname(client->dev.of_node, "INT2"); drivers/iio/gyro/fxas21002c_core.c:834: irq1 = of_irq_get_byname(np, "INT1");
drivers/iio/imu/adis16480.c:1265: irq =
of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
drivers/iio/imu/bmi160/bmi160_core.c:655: irq =
of_irq_get_byname(of_node, "INT1");
drivers/iio/imu/bmi160/bmi160_core.c:661: irq =
of_irq_get_byname(of_node, "INT2");

Quoted 5 lines

I believe we may stop distributing this and actually start using a common API. I don't want this to be spread again over all IIO. Btw, I have LSM9DS0, which supports two INT pins for IMU and currently it uses hard coded pin mapping.

Quoted 3 lines

Hm, I'm not quite sure how to implement this. Could you prepare a patch that would implement such a common API? I would be happy to test it for the device tree and make use of it in this patch.

Unfortunately I have no time to fulfil the required process. The idea in general is like this:

if (is_of_node(...))
return of_irq_get_byname(...);
if (is_acpi_node(...))
return acpi_gpio_irq_get_byname(...);

Everything else is quite similar to fwnode_irq_get().

Quoted 5 lines

To be honest, I mainly implemented support for the interrupt-names because Jonathan mentioned this would be nice to have [1] and it kind of fit well together with the BMC156 patch that needs the INT2 support. I actually just use the if (data->type == BOSCH_BMC156) part from PATCH 4/4 which does not depend on of_irq_get_byname().

Then I leave it to Jonathan and other maintainers.

Quoted 1 line

[1]: https://lore.kernel.org/linux-iio/20210611185941.3487efc6@jic23-huawei/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#18 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

Quoted 94 lines · On Tue, 20 Jul 2021 18:04:22 +0300 Andy Shevchenko <[email protected]>…
Quoted 7 lines · Stephan Gerhold
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Stephan Gerhold
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 69 lines
Quoted 63 lines
Quoted 41 lines
Quoted 32 lines
Quoted 23 lines
Quoted 14 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;  

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Quoted 7 lines

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

I see in today's Linux Next snapshot:

drivers/iio/accel/fxls8962af-core.c:774: irq =
of_irq_get_byname(of_node, "INT2");
drivers/iio/accel/mma8452.c:1616: irq2 =
of_irq_get_byname(client->dev.of_node, "INT2"); drivers/iio/gyro/fxas21002c_core.c:834: irq1 = of_irq_get_byname(np, "INT1");
drivers/iio/imu/adis16480.c:1265: irq =
of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
drivers/iio/imu/bmi160/bmi160_core.c:655: irq =
of_irq_get_byname(of_node, "INT1");
drivers/iio/imu/bmi160/bmi160_core.c:661: irq =
of_irq_get_byname(of_node, "INT2");

Quoted 5 lines

I believe we may stop distributing this and actually start using a common API. I don't want this to be spread again over all IIO. Btw, I have LSM9DS0, which supports two INT pins for IMU and currently it uses hard coded pin mapping.

Quoted 3 lines

Hm, I'm not quite sure how to implement this. Could you prepare a patch that would implement such a common API? I would be happy to test it for the device tree and make use of it in this patch.

Unfortunately I have no time to fulfil the required process. The idea in general is like this:

if (is_of_node(...))
return of_irq_get_byname(...);
if (is_acpi_node(...))
return acpi_gpio_irq_get_byname(...);

Everything else is quite similar to fwnode_irq_get().

Quoted 7 lines
Quoted 5 lines

To be honest, I mainly implemented support for the interrupt-names because Jonathan mentioned this would be nice to have [1] and it kind of fit well together with the BMC156 patch that needs the INT2 support. I actually just use the if (data->type == BOSCH_BMC156) part from PATCH 4/4 which does not depend on of_irq_get_byname().

Then I leave it to Jonathan and other maintainers.

I'd be rather nervous about this one myself unless I have a test setup where I can poke all the paths.

My current qemu hack setup doesn't do full enough ACPI so whilst I'd take a look at this myself it might take me a little while to hack in the ACPI tables needed to bring up a suitable bus on that device.

I'll get to it if no one else does, but I'm not keen to block any drivers that just use the of route in the meantime. Should be easier to do a sweep of the ones Andy has highlighted + this one when we have the support ready.

The patch looks fine to me otherwise.

Thanks,

Jonathan

Quoted 3 lines
Quoted 2 lines

[1]: https://lore.kernel.org/linux-iio/20210611185941.3487efc6@jic23-huawei/

maintainer
#19 lore raw

Re: [PATCH 3/4] iio: accel: bmc150: Make it possible to configure INT2 instead of INT1

In reply to Andy Shevchenko
Quoted 76 lines · On Mon, 19 Jul 2021 21:05:48 +0300 Andy Shevchenko <[email protected]>…
Quoted 6 lines · Stephan Gerhold
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Stephan Gerhold
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Linus Walleij

On Mon, Jul 19, 2021 at 1:26 PM Stephan Gerhold <[email protected]> wrote:

...

Quoted 44 lines
Quoted 35 lines
Quoted 26 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

#include <linux/acpi.h>
+#include <linux/of_irq.h>

(...)

Review

Quoted 3 lines
(quoted diff) +3 -0
+       irq_info = bmc150_accel_interrupts_int1;
+       if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+               irq_info = bmc150_accel_interrupts_int2;  

This looks a bit DT-specific, but I don't see that ACPI has named IRQs so I don't know what to do about it either.

Yeah, we only have so far the (de facto) established way of naming GPIO based IRQs, and not IOxAPIC ones.

Quoted 1 line

What does platform_get_irq_byname() do on ACPI systems?

See above.

Quoted 8 lines
Quoted 3 lines

If there is no obvious fix I would leave it like this until the first ACPI used needing this comes along, but I think maybe Andy has suggestions.

The platform_get_irq_byname() should do something similar that has been done in platform_get_irq() WRT ACPI.
Here for sure the platform_get_irq_byname() or its optional variant should be used.

Quoted 5 lines

I don't think there is a platform device here, we only have the i2c_client or spi_device. That's why I didn't use platform_get_irq_byname(). :)

Is there something equivalent for I2C/SPI drivers?

Not yet. You probably need to supply some code there to allow multi-IRQ devices (in resource provider agnostic way).

Quoted 8 lines

You need to provide fwnode_get_irq_byname() to be similar with
https://elixir.bootlin.com/linux/latest/source/drivers/base/property.c#L1010

Then use it in the drivers.

And/or integrate into frameworks somehow (something in between the
lines: https://elixir.bootlin.com/linux/latest/source/drivers/i2c/i2c-core-base.c#L461).

Quoted 7 lines

Well, I don't think anyone has an ACPI use case for this right now so it's probably better if this is done by someone who actually needs this and can test it somewhere. :)

I actually just "copied" this approach from some other IIO drivers where this is done similarly (and additionally checked the source code to make sure this won't break anything for ACPI platforms).

I see in today's Linux Next snapshot:

drivers/iio/accel/fxls8962af-core.c:774: irq =
of_irq_get_byname(of_node, "INT2");
drivers/iio/accel/mma8452.c:1616: irq2 =
of_irq_get_byname(client->dev.of_node, "INT2"); drivers/iio/gyro/fxas21002c_core.c:834: irq1 = of_irq_get_byname(np, "INT1");
drivers/iio/imu/adis16480.c:1265: irq =
of_irq_get_byname(of_node, adis16480_int_pin_names[i]);
drivers/iio/imu/bmi160/bmi160_core.c:655: irq =
of_irq_get_byname(of_node, "INT1");
drivers/iio/imu/bmi160/bmi160_core.c:661: irq =
of_irq_get_byname(of_node, "INT2");

Quoted 4 lines

I believe we may stop distributing this and actually start using a common API. I don't want this to be spread again over all IIO. Btw, I have LSM9DS0, which supports two INT pins for IMU and currently it uses hard coded pin mapping.

I'm definitely keen to tidy this up, though I'd also rather not tie it to this particular series.

Quoted 3 lines

Side note to Jonathan, I believe the below may be (lazily) converted to fwnode / device properties APIs.

Yup. I know we still have a bunch of these to tidy up. Might take a while to get to them though!

Quoted 35 lines

drivers/iio/adc/ab8500-gpadc.c:1041: nchans =
of_get_available_child_count(np);
drivers/iio/adc/ad7124.c:747: st->num_channels =
of_get_available_child_count(np);
drivers/iio/adc/berlin2-adc.c:287: struct device_node *parent_np
= of_get_parent(pdev->dev.of_node);
drivers/iio/adc/qcom-pm8xxx-xoadc.c:830: adc->nchans =
of_get_available_child_count(np);
drivers/iio/adc/qcom-spmi-adc5.c:650: channel_name = of_get_property(node,
drivers/iio/adc/qcom-spmi-adc5.c:813: adc->nchannels =
of_get_available_child_count(node);
drivers/iio/adc/qcom-spmi-vadc.c:743: vadc->nchannels =
of_get_available_child_count(node); drivers/iio/adc/stm32-adc.c:1630:static int stm32_adc_of_get_resolution(struct iio_dev *indio_dev)
drivers/iio/adc/stm32-adc.c:1935: ret =
stm32_adc_of_get_resolution(indio_dev);
drivers/iio/adc/xilinx-xadc-core.c:1248: chan_node =
of_get_child_by_name(np, "xlnx,channels"); drivers/iio/imu/adis16480.c:1293:static int adis16480_of_get_ext_clk_pin(struct adis16480 *st,
drivers/iio/imu/adis16480.c:1328: pin =
adis16480_of_get_ext_clk_pin(st, of_node);
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c:68: mux_node =
of_get_child_by_name(dev->of_node, "i2c-gate")
;
drivers/iio/industrialio-core.c:1877: label =
of_get_property(indio_dev->dev.of_node, "label", NULL);
drivers/iio/inkern.c:228: if (np && !of_get_property(np,
"io-channel-ranges", NULL)) drivers/iio/temperature/ltc2983.c:1275: st->num_channels = of_get_available_child_count(dev->of_node);

#20 lore raw

PATCH 4/4 iio: accel: bmc150: Add support for BMC156

In reply to Stephan Gerhold

BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer+magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs.

Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables.

---
 drivers/iio/accel/Kconfig             |  5 +++--
 drivers/iio/accel/bmc150-accel-core.c |  8 +++++---
 drivers/iio/accel/bmc150-accel-i2c.c  | 10 ++++++++--
 drivers/iio/accel/bmc150-accel-spi.c  | 10 +++++++++-
 drivers/iio/accel/bmc150-accel.h      |  9 ++++++++-
 5 files changed, 33 insertions(+), 9 deletions(-)
drivers/iio/accel/Kconfig +3 -2
index 0e56ace61103..2f0c0d512ae7 100644
@@ -143,10 +143,11 @@ config BMC150_ACCEL
 	select BMC150_ACCEL_SPI if SPI
 	help
 	  Say yes here to build support for the following Bosch accelerometers:
-	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055.
+	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156
+	  BMI055.
 
 	  Note that some of these are combo modules:
-	    - BMC150: accelerometer and magnetometer
+	    - BMC150/BMC156: accelerometer and magnetometer
 	    - BMI055: accelerometer and gyroscope
 
 	  This driver is only implementing accelerometer part, which has
drivers/iio/accel/bmc150-accel-core.c +5 -3
index 8d3dd3c2bcc2..a5d321e878ef 100644
@@ -553,7 +553,7 @@ static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
 	 * Without interrupt-names, we assume the irq belongs to INT1.
 	 */
 	irq_info = bmc150_accel_interrupts_int1;
-	if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+	if (data->type == BOSCH_BMC156 || irq == of_irq_get_byname(dev->of_node, "INT2"))
 		irq_info = bmc150_accel_interrupts_int2;
 
 	for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
@@ -1174,7 +1174,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
 				 {306458, BMC150_ACCEL_DEF_RANGE_16G} },
 	},
 	{
-		.name = "BMA253/BMA254/BMA255/BMC150/BMI055",
+		.name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055",
 		.chip_id = 0xFA,
 		.channels = bmc150_accel_channels,
 		.num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1661,7 +1661,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 }
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported)
+			    enum bmc150_type type, const char *name,
+			    bool block_supported)
 {
 	const struct attribute **fifo_attrs;
 	struct bmc150_accel_data *data;
@@ -1676,6 +1677,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	dev_set_drvdata(dev, indio_dev);
 
 	data->regmap = regmap;
+	data->type = type;
 
 	if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) {
 		ret = iio_read_mount_matrix(dev, &data->orientation);
drivers/iio/accel/bmc150-accel-i2c.c +8 -2
index 999495f0669d..88bd8a25f142 100644
@@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
 {
 	struct regmap *regmap;
 	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	bool block_supported =
 		i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
 		i2c_check_functionality(client->adapter,
@@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client,
 		return PTR_ERR(regmap);
 	}
 
-	if (id)
+	if (id) {
 		name = id->name;
+		type = id->driver_data;
+	}
 
-	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
+	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq,
+				      type, name, block_supported);
 	if (ret)
 		return ret;
 
@@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
@@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
 	{ .compatible = "bosch,bma255" },
 	{ .compatible = "bosch,bma280" },
 	{ .compatible = "bosch,bmc150_accel" },
+	{ .compatible = "bosch,bmc156_accel" },
 	{ .compatible = "bosch,bmi055_accel" },
 	{ },
 };
drivers/iio/accel/bmc150-accel-spi.c +9 -1
index 54b8c9c8068b..191e312dc91a 100644
@@ -16,6 +16,8 @@
 static int bmc150_accel_probe(struct spi_device *spi)
 {
 	struct regmap *regmap;
+	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 
 	regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
@@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+	if (id) {
+		name = id->name;
+		type = id->driver_data;
+	}
+
+	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
 				       true);
 }
 
@@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
drivers/iio/accel/bmc150-accel.h +8 -1
index 47121f070fe9..a3f4905e48a3 100644
@@ -13,6 +13,11 @@ struct i2c_client;
 struct bmc150_accel_chip_info;
 struct bmc150_accel_interrupt_info;
 
+enum bmc150_type {
+	BOSCH_UNKNOWN,
+	BOSCH_BMC156,
+};
+
 struct bmc150_accel_interrupt {
 	const struct bmc150_accel_interrupt_info *info;
 	atomic_t users;
@@ -62,6 +67,7 @@ struct bmc150_accel_data {
 	int ev_enable_state;
 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
 	const struct bmc150_accel_chip_info *chip_info;
+	enum bmc150_type type;
 	struct i2c_client *second_device;
 	void (*resume_callback)(struct device *dev);
 	struct delayed_work resume_work;
@@ -69,7 +75,8 @@ struct bmc150_accel_data {
 };
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported);
+			    enum bmc150_type type, const char *name,
+			    bool block_supported);
 int bmc150_accel_core_remove(struct device *dev);
 extern const struct dev_pm_ops bmc150_accel_pm_ops;
 extern const struct regmap_config bmc150_regmap_conf;
Signature · 1 line
2.32.0
Reviewed-by on v1 4/4
#21 lore raw

Re: [PATCH 4/4] iio: accel: bmc150: Add support for BMC156

Quoted 10 lines · Stephan Gerhold

BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer+magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs.

Quoted 8 lines

Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables.

Yours,
Linus Walleij

maintainer
#22 lore raw

Re: [PATCH 4/4] iio: accel: bmc150: Add support for BMC156

In reply to Stephan Gerhold
Quoted 10 lines · On Mon, 19 Jul 2021 13:21:56 +0200 Stephan Gerhold <[email protected]> wrote:

BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer+magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs.

Quoted 8 lines

Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables.

A few really minor things inline.

Thanks,

Jonathan

Quoted 31 lines
---
 drivers/iio/accel/Kconfig             |  5 +++--
 drivers/iio/accel/bmc150-accel-core.c |  8 +++++---
 drivers/iio/accel/bmc150-accel-i2c.c  | 10 ++++++++--
 drivers/iio/accel/bmc150-accel-spi.c  | 10 +++++++++-
 drivers/iio/accel/bmc150-accel.h      |  9 ++++++++-
 5 files changed, 33 insertions(+), 9 deletions(-)
drivers/iio/accel/Kconfig +3 -2
index 0e56ace61103..2f0c0d512ae7 100644
@@ -143,10 +143,11 @@ config BMC150_ACCEL
 	select BMC150_ACCEL_SPI if SPI
 	help
 	  Say yes here to build support for the following Bosch accelerometers:
-	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055.
+	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156
+	  BMI055.
 
 	  Note that some of these are combo modules:
-	    - BMC150: accelerometer and magnetometer
+	    - BMC150/BMC156: accelerometer and magnetometer
 	    - BMI055: accelerometer and gyroscope
 
 	  This driver is only implementing accelerometer part, which has
drivers/iio/accel/bmc150-accel-core.c +0 -0
index 8d3dd3c2bcc2..a5d321e878ef 100644

drivers/iio/accel/bmc150-accel-core.c static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, · line 556

Quoted 5 lines
drivers/iio/accel/bmc150-accel-core.c +1 -1
@@ -553,7 +553,7 @@ static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
 	 * Without interrupt-names, we assume the irq belongs to INT1.
 	 */
 	irq_info = bmc150_accel_interrupts_int1;
-	if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+	if (data->type == BOSCH_BMC156 || irq == of_irq_get_byname(dev->of_node, "INT2"))

It is still preferred to keep line lengths under 80 chars unless it hurts readability to do so. So please wrap this one.

Quoted 114 lines
drivers/iio/accel/bmc150-accel-core.c +4 -2
 		irq_info = bmc150_accel_interrupts_int2;
 
 	for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
@@ -1174,7 +1174,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
 				 {306458, BMC150_ACCEL_DEF_RANGE_16G} },
 	},
 	{
-		.name = "BMA253/BMA254/BMA255/BMC150/BMI055",
+		.name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055",
 		.chip_id = 0xFA,
 		.channels = bmc150_accel_channels,
 		.num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1661,7 +1661,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 }
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported)
+			    enum bmc150_type type, const char *name,
+			    bool block_supported)
 {
 	const struct attribute **fifo_attrs;
 	struct bmc150_accel_data *data;
@@ -1676,6 +1677,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	dev_set_drvdata(dev, indio_dev);
 
 	data->regmap = regmap;
+	data->type = type;
 
 	if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) {
 		ret = iio_read_mount_matrix(dev, &data->orientation);
drivers/iio/accel/bmc150-accel-i2c.c +8 -2
index 999495f0669d..88bd8a25f142 100644
@@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
 {
 	struct regmap *regmap;
 	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	bool block_supported =
 		i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
 		i2c_check_functionality(client->adapter,
@@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client,
 		return PTR_ERR(regmap);
 	}
 
-	if (id)
+	if (id) {
 		name = id->name;
+		type = id->driver_data;
+	}
 
-	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
+	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq,
+				      type, name, block_supported);
 	if (ret)
 		return ret;
 
@@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
@@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
 	{ .compatible = "bosch,bma255" },
 	{ .compatible = "bosch,bma280" },
 	{ .compatible = "bosch,bmc150_accel" },
+	{ .compatible = "bosch,bmc156_accel" },
 	{ .compatible = "bosch,bmi055_accel" },
 	{ },
 };
drivers/iio/accel/bmc150-accel-spi.c +9 -1
index 54b8c9c8068b..191e312dc91a 100644
@@ -16,6 +16,8 @@
 static int bmc150_accel_probe(struct spi_device *spi)
 {
 	struct regmap *regmap;
+	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 
 	regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
@@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+	if (id) {
+		name = id->name;
+		type = id->driver_data;
+	}
+
+	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
 				       true);
 }
 
@@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
drivers/iio/accel/bmc150-accel.h +0 -0
index 47121f070fe9..a3f4905e48a3 100644

drivers/iio/accel/bmc150-accel.h struct i2c_client; · line 18

Quoted 6 lines
drivers/iio/accel/bmc150-accel.h +3 -0
@@ -13,6 +13,11 @@ struct i2c_client;
 struct bmc150_accel_chip_info;
 struct bmc150_accel_interrupt_info;
 
+enum bmc150_type {
+	BOSCH_UNKNOWN,
+	BOSCH_BMC156,

Whilst we only need to distinguish this one at the moment, the unknown naming implies we don't know the type when often we actually do.

Probably better to just have all the known device types in the enum and set in the id table.

Quoted 23 lines
drivers/iio/accel/bmc150-accel.h +5 -1
+};
+
 struct bmc150_accel_interrupt {
 	const struct bmc150_accel_interrupt_info *info;
 	atomic_t users;
@@ -62,6 +67,7 @@ struct bmc150_accel_data {
 	int ev_enable_state;
 	int64_t timestamp, old_timestamp; /* Only used in hw fifo mode. */
 	const struct bmc150_accel_chip_info *chip_info;
+	enum bmc150_type type;
 	struct i2c_client *second_device;
 	void (*resume_callback)(struct device *dev);
 	struct delayed_work resume_work;
@@ -69,7 +75,8 @@ struct bmc150_accel_data {
 };
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported);
+			    enum bmc150_type type, const char *name,
+			    bool block_supported);
 int bmc150_accel_core_remove(struct device *dev);
 extern const struct dev_pm_ops bmc150_accel_pm_ops;
 extern const struct regmap_config bmc150_regmap_conf;
#23 lore raw

Re: [PATCH 4/4] iio: accel: bmc150: Add support for BMC156

Hi Jonathan!

Quoted 52 lines · Jonathan Cameron
Quoted 10 lines · On Mon, 19 Jul 2021 13:21:56 +0200 Stephan Gerhold <[email protected]> wrote:

BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer+magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs.

Quoted 8 lines

Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables.

A few really minor things inline.

Thanks,

Jonathan

Quoted 25 lines
---
 drivers/iio/accel/Kconfig             |  5 +++--
 drivers/iio/accel/bmc150-accel-core.c |  8 +++++---
 drivers/iio/accel/bmc150-accel-i2c.c  | 10 ++++++++--
 drivers/iio/accel/bmc150-accel-spi.c  | 10 +++++++++-
 drivers/iio/accel/bmc150-accel.h      |  9 ++++++++-
 5 files changed, 33 insertions(+), 9 deletions(-)
drivers/iio/accel/Kconfig +3 -2
index 0e56ace61103..2f0c0d512ae7 100644
@@ -143,10 +143,11 @@ config BMC150_ACCEL
 	select BMC150_ACCEL_SPI if SPI
 	help
 	  Say yes here to build support for the following Bosch accelerometers:
-	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055.
+	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156
+	  BMI055.
 
 	  Note that some of these are combo modules:
-	    - BMC150: accelerometer and magnetometer
+	    - BMC150/BMC156: accelerometer and magnetometer
 	    - BMI055: accelerometer and gyroscope
 
Quoted 15 lines

drivers/iio/accel/bmc150-accel-core.c static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, · line 556

Quoted 11 lines
drivers/iio/accel/Kconfig +0 -0
 	  This driver is only implementing accelerometer part, which has
drivers/iio/accel/bmc150-accel-core.c +1 -1
index 8d3dd3c2bcc2..a5d321e878ef 100644
@@ -553,7 +553,7 @@ static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
 	 * Without interrupt-names, we assume the irq belongs to INT1.
 	 */
 	irq_info = bmc150_accel_interrupts_int1;
-	if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+	if (data->type == BOSCH_BMC156 || irq == of_irq_get_byname(dev->of_node, "INT2"))

It is still preferred to keep line lengths under 80 chars unless it hurts readability to do so. So please wrap this one.

OK, will fix this in v2. :)

Quoted 117 lines
Quoted 117 lines
drivers/iio/accel/bmc150-accel-core.c +4 -2
 		irq_info = bmc150_accel_interrupts_int2;
 
 	for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
@@ -1174,7 +1174,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
 				 {306458, BMC150_ACCEL_DEF_RANGE_16G} },
 	},
 	{
-		.name = "BMA253/BMA254/BMA255/BMC150/BMI055",
+		.name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055",
 		.chip_id = 0xFA,
 		.channels = bmc150_accel_channels,
 		.num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1661,7 +1661,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 }
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported)
+			    enum bmc150_type type, const char *name,
+			    bool block_supported)
 {
 	const struct attribute **fifo_attrs;
 	struct bmc150_accel_data *data;
@@ -1676,6 +1677,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	dev_set_drvdata(dev, indio_dev);
 
 	data->regmap = regmap;
+	data->type = type;
 
 	if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) {
 		ret = iio_read_mount_matrix(dev, &data->orientation);
drivers/iio/accel/bmc150-accel-i2c.c +8 -2
index 999495f0669d..88bd8a25f142 100644
@@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
 {
 	struct regmap *regmap;
 	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	bool block_supported =
 		i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
 		i2c_check_functionality(client->adapter,
@@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client,
 		return PTR_ERR(regmap);
 	}
 
-	if (id)
+	if (id) {
 		name = id->name;
+		type = id->driver_data;
+	}
 
-	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
+	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq,
+				      type, name, block_supported);
 	if (ret)
 		return ret;
 
@@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
@@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
 	{ .compatible = "bosch,bma255" },
 	{ .compatible = "bosch,bma280" },
 	{ .compatible = "bosch,bmc150_accel" },
+	{ .compatible = "bosch,bmc156_accel" },
 	{ .compatible = "bosch,bmi055_accel" },
 	{ },
 };
drivers/iio/accel/bmc150-accel-spi.c +9 -1
index 54b8c9c8068b..191e312dc91a 100644
@@ -16,6 +16,8 @@
 static int bmc150_accel_probe(struct spi_device *spi)
 {
 	struct regmap *regmap;
+	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 
 	regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
@@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+	if (id) {
+		name = id->name;
+		type = id->driver_data;
+	}
+
+	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
 				       true);
 }
 
@@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
drivers/iio/accel/bmc150-accel.h +0 -0
index 47121f070fe9..a3f4905e48a3 100644
@@ -13,6 +13,11 @@ struct i2c_client;
 struct bmc150_accel_chip_info;
 struct bmc150_accel_interrupt_info;
 
Quoted 6 lines

drivers/iio/accel/bmc150-accel.h struct i2c_client; · line 18

Quoted 3 lines
drivers/iio/accel/bmc150-accel.h +3 -0
+enum bmc150_type {
+	BOSCH_UNKNOWN,
+	BOSCH_BMC156,

Whilst we only need to distinguish this one at the moment, the unknown naming implies we don't know the type when often we actually do.

Hm, actually this is exactly what I want to imply! We do have seemingly obvious names listed in the ID tables, but unfortunately I don't think we can assume them to be accurate.

The original reason why we no longer rely on the type implied by the ID is that there are some ACPI devices that specify an ID like "BMA250E" when they actually have a BMA222E, see commit 0ad4bf37017 [1] ("iio:accel:bmc150-accel: Use the chip ID to detect sensor variant").

And this was the motivation for my commit c06a6aba6835 [2] ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers"). I removed them because they were not used. Also, we cannot make use of them in the general case because they are not reliable thanks to those ACPI devices.

We could perhaps add it only for the of_device_ids. However, even there it's easy to specify some similar compatible only because Bosch has so many compatible parts. For example, the device where these BMC156 changes were tested on was using "bosch,bmc150_accel" so far simply because this was working fine (without interrupts) and we weren't actually aware that it has a BMC156 instead of BMC150.

Im my opinion, adding type information to all of them would imply that it can be used reliably, which is not the case unfortunately. Perhaps I should instead add a comment to this enum to make this more clear?

What do you think?

Thanks!
Stephan

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0ad4bf37017621e25fe157fa095fd8849779a873
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c06a6aba6835946bcccb9909c98ec110949ea630

maintainer
#24 lore raw

Re: [PATCH 4/4] iio: accel: bmc150: Add support for BMC156

Quoted 206 lines · On Tue, 27 Jul 2021 20:32:12 +0200 Stephan Gerhold <[email protected]> wrote:

Hi Jonathan!

Quoted 52 lines · Jonathan Cameron
Quoted 10 lines · On Mon, 19 Jul 2021 13:21:56 +0200 Stephan Gerhold <[email protected]> wrote:

BMC156 is another accelerometer that works just fine with the bmc150-accel driver. It's very similar to BMC150 (also a accelerometer+magnetometer combo) but with only one accelerometer interrupt pin. It would make sense if only INT1 was exposed but someone at Bosch was crazy and decided to only have an INT2 pin.

Try to deal with this by making use of the INT2 support introduced in the previous commit and force using INT2 for BMC156. To detect that we need to bring up a simplified version of the previous type IDs.

Quoted 8 lines

Note that unlike the type IDs removed in commit c06a6aba6835 ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers") here I only add one for the special case of BMC156. Everything else still happens by reading the CHIP_ID register since the chip type information often is not accurate in ACPI tables.

A few really minor things inline.

Thanks,

Jonathan

Quoted 25 lines
---
 drivers/iio/accel/Kconfig             |  5 +++--
 drivers/iio/accel/bmc150-accel-core.c |  8 +++++---
 drivers/iio/accel/bmc150-accel-i2c.c  | 10 ++++++++--
 drivers/iio/accel/bmc150-accel-spi.c  | 10 +++++++++-
 drivers/iio/accel/bmc150-accel.h      |  9 ++++++++-
 5 files changed, 33 insertions(+), 9 deletions(-)
drivers/iio/accel/Kconfig +3 -2
index 0e56ace61103..2f0c0d512ae7 100644
@@ -143,10 +143,11 @@ config BMC150_ACCEL
 	select BMC150_ACCEL_SPI if SPI
 	help
 	  Say yes here to build support for the following Bosch accelerometers:
-	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMI055.
+	  BMA222, BMA222E, BMA250E, BMA253, BMA254, BMA255, BMA280, BMC150, BMC156
+	  BMI055.
 
 	  Note that some of these are combo modules:
-	    - BMC150: accelerometer and magnetometer
+	    - BMC150/BMC156: accelerometer and magnetometer
 	    - BMI055: accelerometer and gyroscope
 
Quoted 15 lines

drivers/iio/accel/bmc150-accel-core.c static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev, · line 556

Quoted 11 lines
drivers/iio/accel/Kconfig +0 -0
 	  This driver is only implementing accelerometer part, which has
drivers/iio/accel/bmc150-accel-core.c +1 -1
index 8d3dd3c2bcc2..a5d321e878ef 100644
@@ -553,7 +553,7 @@ static void bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
 	 * Without interrupt-names, we assume the irq belongs to INT1.
 	 */
 	irq_info = bmc150_accel_interrupts_int1;
-	if (irq == of_irq_get_byname(dev->of_node, "INT2"))
+	if (data->type == BOSCH_BMC156 || irq == of_irq_get_byname(dev->of_node, "INT2"))  

It is still preferred to keep line lengths under 80 chars unless it hurts readability to do so. So please wrap this one.

OK, will fix this in v2. :)

Quoted 117 lines
Quoted 117 lines
drivers/iio/accel/bmc150-accel-core.c +4 -2
 		irq_info = bmc150_accel_interrupts_int2;
 
 	for (i = 0; i < BMC150_ACCEL_INTERRUPTS; i++)
@@ -1174,7 +1174,7 @@ static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
 				 {306458, BMC150_ACCEL_DEF_RANGE_16G} },
 	},
 	{
-		.name = "BMA253/BMA254/BMA255/BMC150/BMI055",
+		.name = "BMA253/BMA254/BMA255/BMC150/BMC156/BMI055",
 		.chip_id = 0xFA,
 		.channels = bmc150_accel_channels,
 		.num_channels = ARRAY_SIZE(bmc150_accel_channels),
@@ -1661,7 +1661,8 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 }
 
 int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
-			    const char *name, bool block_supported)
+			    enum bmc150_type type, const char *name,
+			    bool block_supported)
 {
 	const struct attribute **fifo_attrs;
 	struct bmc150_accel_data *data;
@@ -1676,6 +1677,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
 	dev_set_drvdata(dev, indio_dev);
 
 	data->regmap = regmap;
+	data->type = type;
 
 	if (!bmc150_apply_acpi_orientation(dev, &data->orientation)) {
 		ret = iio_read_mount_matrix(dev, &data->orientation);
drivers/iio/accel/bmc150-accel-i2c.c +8 -2
index 999495f0669d..88bd8a25f142 100644
@@ -176,6 +176,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
 {
 	struct regmap *regmap;
 	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	bool block_supported =
 		i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
 		i2c_check_functionality(client->adapter,
@@ -188,10 +189,13 @@ static int bmc150_accel_probe(struct i2c_client *client,
 		return PTR_ERR(regmap);
 	}
 
-	if (id)
+	if (id) {
 		name = id->name;
+		type = id->driver_data;
+	}
 
-	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq, name, block_supported);
+	ret = bmc150_accel_core_probe(&client->dev, regmap, client->irq,
+				      type, name, block_supported);
 	if (ret)
 		return ret;
 
@@ -236,6 +240,7 @@ static const struct i2c_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
@@ -251,6 +256,7 @@ static const struct of_device_id bmc150_accel_of_match[] = {
 	{ .compatible = "bosch,bma255" },
 	{ .compatible = "bosch,bma280" },
 	{ .compatible = "bosch,bmc150_accel" },
+	{ .compatible = "bosch,bmc156_accel" },
 	{ .compatible = "bosch,bmi055_accel" },
 	{ },
 };
drivers/iio/accel/bmc150-accel-spi.c +9 -1
index 54b8c9c8068b..191e312dc91a 100644
@@ -16,6 +16,8 @@
 static int bmc150_accel_probe(struct spi_device *spi)
 {
 	struct regmap *regmap;
+	const char *name = NULL;
+	enum bmc150_type type = BOSCH_UNKNOWN;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 
 	regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
@@ -24,7 +26,12 @@ static int bmc150_accel_probe(struct spi_device *spi)
 		return PTR_ERR(regmap);
 	}
 
-	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+	if (id) {
+		name = id->name;
+		type = id->driver_data;
+	}
+
+	return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, type, name,
 				       true);
 }
 
@@ -54,6 +61,7 @@ static const struct spi_device_id bmc150_accel_id[] = {
 	{"bma255"},
 	{"bma280"},
 	{"bmc150_accel"},
+	{"bmc156_accel", BOSCH_BMC156},
 	{"bmi055_accel"},
 	{}
 };
drivers/iio/accel/bmc150-accel.h +0 -0
index 47121f070fe9..a3f4905e48a3 100644
@@ -13,6 +13,11 @@ struct i2c_client;
 struct bmc150_accel_chip_info;
 struct bmc150_accel_interrupt_info;
 
Quoted 6 lines

drivers/iio/accel/bmc150-accel.h struct i2c_client; · line 18

Quoted 3 lines
drivers/iio/accel/bmc150-accel.h +3 -0
+enum bmc150_type {
+	BOSCH_UNKNOWN,
+	BOSCH_BMC156,  

Whilst we only need to distinguish this one at the moment, the unknown naming implies we don't know the type when often we actually do.

Hm, actually this is exactly what I want to imply! We do have seemingly obvious names listed in the ID tables, but unfortunately I don't think we can assume them to be accurate.

The original reason why we no longer rely on the type implied by the ID is that there are some ACPI devices that specify an ID like "BMA250E" when they actually have a BMA222E, see commit 0ad4bf37017 [1] ("iio:accel:bmc150-accel: Use the chip ID to detect sensor variant").

Quoted 5 lines

And this was the motivation for my commit c06a6aba6835 [2] ("iio: accel: bmc150: Drop misleading/duplicate chip identifiers"). I removed them because they were not used. Also, we cannot make use of them in the general case because they are not reliable thanks to those ACPI devices.

Gah!

Quoted 8 lines

We could perhaps add it only for the of_device_ids. However, even there it's easy to specify some similar compatible only because Bosch has so many compatible parts. For example, the device where these BMC156 changes were tested on was using "bosch,bmc150_accel" so far simply because this was working fine (without interrupts) and we weren't actually aware that it has a BMC156 instead of BMC150.

Quoted 5 lines

Im my opinion, adding type information to all of them would imply that it can be used reliably, which is not the case unfortunately. Perhaps I should instead add a comment to this enum to make this more clear?

What do you think?

A comment seems a good solution given the situation.

Thanks,

Jonathan

Quoted 6 lines

Thanks!
Stephan

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0ad4bf37017621e25fe157fa095fd8849779a873
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c06a6aba6835946bcccb9909c98ec110949ea630

#25 lore raw
In reply to Stephan Gerhold
Quoted 8 lines · Stephan Gerhold

This series makes it possible to set up interrupts with the BMC150 driver on boards where only the INT2 pin is connected (and not INT1). This is particularly always the case for BMC156 since for some reason it only has the INT2 pin and not the INT1 pin.

These changes were already partially discussed here:
https://lore.kernel.org/linux-iio/[email protected]/

I forgot the story, but the series sounds to me like déjà-vu. Please, remind me if it was sent once before? If yes, then this one misses version bumping and/or changelog.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#26 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Stephan Gerhold

This series makes it possible to set up interrupts with the BMC150 driver on boards where only the INT2 pin is connected (and not INT1). This is particularly always the case for BMC156 since for some reason it only has the INT2 pin and not the INT1 pin.

Quoted 7 lines
Quoted 2 lines

These changes were already partially discussed here:
https://lore.kernel.org/linux-iio/[email protected]/

I forgot the story, but the series sounds to me like déjà-vu. Please, remind me if it was sent once before? If yes, then this one misses version bumping and/or changelog.

Hm, no I didn't send this one before. :)

Perhaps you are confusing it with the patch series I sent for BMA253 support recently [1] which is where I mentioned I would work on BMC156 support as well as follow-up series (see link above). :)

Thanks!
Stephan

[1]: https://lore.kernel.org/linux-iio/[email protected]/