mbox series

[RFC,0/2] iio: imu: Add driver and dt-bindings for BMI323

Message ID 20230918080314.11959-1-jagathjog1996@gmail.com
Headers show
Series iio: imu: Add driver and dt-bindings for BMI323 | expand

Message

Jagath Jog J Sept. 18, 2023, 8:03 a.m. UTC
Add dt-bindings and IIO driver for Bosch BMI323 a 6 axis IMU.

Jagath Jog J (2):
  dt-bindings: iio: imu: Add DT binding doc for BMI323
  iio: imu: Add driver for BMI323 IMU

 .../bindings/iio/imu/bosch,bmi323.yaml        |   81 +
 MAINTAINERS                                   |    7 +
 drivers/iio/imu/Kconfig                       |    1 +
 drivers/iio/imu/Makefile                      |    1 +
 drivers/iio/imu/bmi323/Kconfig                |   33 +
 drivers/iio/imu/bmi323/Makefile               |    7 +
 drivers/iio/imu/bmi323/bmi323.h               |  198 ++
 drivers/iio/imu/bmi323/bmi323_core.c          | 2260 +++++++++++++++++
 drivers/iio/imu/bmi323/bmi323_i2c.c           |  115 +
 drivers/iio/imu/bmi323/bmi323_spi.c           |  106 +
 10 files changed, 2809 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
 create mode 100644 drivers/iio/imu/bmi323/Kconfig
 create mode 100644 drivers/iio/imu/bmi323/Makefile
 create mode 100644 drivers/iio/imu/bmi323/bmi323.h
 create mode 100644 drivers/iio/imu/bmi323/bmi323_core.c
 create mode 100644 drivers/iio/imu/bmi323/bmi323_i2c.c
 create mode 100644 drivers/iio/imu/bmi323/bmi323_spi.c

Comments

Jonathan Cameron Sept. 24, 2023, 1:37 p.m. UTC | #1
On Mon, 18 Sep 2023 13:33:13 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> Add devicetree description document for Bosch BMI323, a 6-Axis IMU.
> 
> Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
> ---
>  .../bindings/iio/imu/bosch,bmi323.yaml        | 81 +++++++++++++++++++
>  1 file changed, 81 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> 
> diff --git a/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml b/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> new file mode 100644
> index 000000000000..9c08988103c5
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> @@ -0,0 +1,81 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/imu/bosch,bmi323.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Bosch BMI323 6-Axis IMU
> +
> +maintainers:
> +  - Jagath Jog J <jagathjog1996@gmail.com>
> +
> +description:
> +  BMI323 is a 6-axis inertial measurement unit that supports acceleration and
> +  gyroscopic measurements with hardware fifo buffering. Sensor also provides
> +  events information such as motion, steps, orientation, single and double
> +  tap detection.
> +
> +properties:
> +  compatible:
> +    const: bosch,bmi323
> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  interrupt-names:
> +    enum:
> +      - INT1
> +      - INT2
> +    description: |
> +      set to "INT1" if INT1 pin should be used as interrupt input, set
> +      to "INT2" if INT2 pin should be used instead

Why not both?  Sure driver might elect to use only one, but the binding
describes the hardware not the driver and both might be wired.

Lots of different sources of interrupts so might be advantageous
to split them up across two wires.   A simple case being to route
errors to one and everything 'good' to the other.  No obligation to
support that in the Linux driver though if you don't need to.

> +
> +  drive-open-drain:
> +    description: |
> +      set if the specified interrupt pin should be configured as
> +      open drain. If not set, defaults to push-pull.

Two pins.  Might be different so you need two controls.

> +
> +required:
> +  - compatible
> +  - reg

As mentioned, need power supplies specified and marked as required
(though they may be provided via always on regulators and rely on stubs
being created by the regulator subsystem on a given board).
Looks like there are at least 2 supplies.

> +
> +allOf:
> +  - $ref: /schemas/spi/spi-peripheral-props.yaml#
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    // Example for I2C
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    i2c {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        bmi323@68 {
> +            compatible = "bosch,bmi323";
> +            reg = <0x68>;
> +            interrupt-parent = <&gpio1>;
> +            interrupts = <29 IRQ_TYPE_EDGE_RISING>;
> +            interrupt-names = "INT1";
> +        };
> +    };
> +  - |
> +    // Example for SPI
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    spi {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        bmi323@0 {
> +            compatible = "bosch,bmi323";
> +            reg = <0>;
> +            spi-max-frequency = <10000000>;
> +            interrupt-parent = <&gpio2>;
> +            interrupts = <12 IRQ_TYPE_EDGE_FALLING>;
> +            interrupt-names = "INT2";
> +        };
> +    };
Jonathan Cameron Sept. 30, 2023, 4:05 p.m. UTC | #2
On Thu, 28 Sep 2023 03:07:22 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> HI Jonathan,
> 
> On Sun, Sep 24, 2023 at 7:07 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Mon, 18 Sep 2023 13:33:13 +0530
> > Jagath Jog J <jagathjog1996@gmail.com> wrote:
> >  
> > > Add devicetree description document for Bosch BMI323, a 6-Axis IMU.
> > >
> > > Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
> > > ---
> > >  .../bindings/iio/imu/bosch,bmi323.yaml        | 81 +++++++++++++++++++
> > >  1 file changed, 81 insertions(+)
> > >  create mode 100644 Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> > >
> > > diff --git a/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml b/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> > > new file mode 100644
> > > index 000000000000..9c08988103c5
> > > --- /dev/null
> > > +++ b/Documentation/devicetree/bindings/iio/imu/bosch,bmi323.yaml
> > > @@ -0,0 +1,81 @@
> > > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> > > +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/iio/imu/bosch,bmi323.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: Bosch BMI323 6-Axis IMU
> > > +
> > > +maintainers:
> > > +  - Jagath Jog J <jagathjog1996@gmail.com>
> > > +
> > > +description:
> > > +  BMI323 is a 6-axis inertial measurement unit that supports acceleration and
> > > +  gyroscopic measurements with hardware fifo buffering. Sensor also provides
> > > +  events information such as motion, steps, orientation, single and double
> > > +  tap detection.
> > > +
> > > +properties:
> > > +  compatible:
> > > +    const: bosch,bmi323
> > > +
> > > +  reg:
> > > +    maxItems: 1
> > > +
> > > +  interrupts:
> > > +    maxItems: 1
> > > +
> > > +  interrupt-names:
> > > +    enum:
> > > +      - INT1
> > > +      - INT2
> > > +    description: |
> > > +      set to "INT1" if INT1 pin should be used as interrupt input, set
> > > +      to "INT2" if INT2 pin should be used instead  
> >
> > Why not both?  Sure driver might elect to use only one, but the binding
> > describes the hardware not the driver and both might be wired.  
> 
> If both interrupt pins are wired, should the DTS file need to define
> both of the pins?

Yes it should. + we need the names to know which is which.
You could rely on order, but it's more flexible to not do so, particularly
when you also need to support case where only one is wired.


Jonathan
Jagath Jog J Oct. 8, 2023, 6:24 a.m. UTC | #3
Hi Jonathan,

Few more questions before sending the next series.

On Sat, Sep 30, 2023 at 9:35 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Thu, 28 Sep 2023 03:07:22 +0530
> Jagath Jog J <jagathjog1996@gmail.com> wrote:
>
> > HI Jonathan,
> >
> > On Sun, Sep 24, 2023 at 7:07 PM Jonathan Cameron <jic23@kernel.org> wrote:
> > >
> > > On Mon, 18 Sep 2023 13:33:13 +0530
> > > Jagath Jog J <jagathjog1996@gmail.com> wrote:
> > >
> > > > Add devicetree description document for Bosch BMI323, a 6-Axis IMU.
> > > >
> > > > Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>

> > > > +  interrupts:
> > > > +    maxItems: 1
> > > > +
> > > > +  interrupt-names:
> > > > +    enum:
> > > > +      - INT1
> > > > +      - INT2
> > > > +    description: |
> > > > +      set to "INT1" if INT1 pin should be used as interrupt input, set
> > > > +      to "INT2" if INT2 pin should be used instead
> > >
> > > Why not both?  Sure driver might elect to use only one, but the binding
> > > describes the hardware not the driver and both might be wired.
> >
> > If both interrupt pins are wired, should the DTS file need to define
> > both of the pins?
>
> Yes it should. + we need the names to know which is which.
> You could rely on order, but it's more flexible to not do so, particularly
> when you also need to support case where only one is wired.

In the driver, I currently prioritize INT1 over INT2 when checking
(bmi323_trigger_probe(..)) based on the interrupt-names defined
in the device tree. However, I'm open to suggestions on the best
way to ensure that the order doesn't affect the selection process
when both interrupts are defined in the device tree.

Each feature, such as data-ready, watermark, tap, and others, supports
either INT1 or INT2. Based on the interrupt pin defined in the device tree,
I configure the all the features accordingly.

Regarding your earlier suggestion to have two different controls for
drive-open-drain, do I need to define sensor-specific drive controls
in bindings for both interrupt pins?
for ex: bosch,irq{1,2}-open-drain

Regards
Jagath
>
>
> Jonathan
>
>
Jonathan Cameron Oct. 10, 2023, 9 a.m. UTC | #4
On Sun, 8 Oct 2023 11:54:39 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> Hi Jonathan,
> 
> Few more questions before sending the next series.
> 
> On Sat, Sep 30, 2023 at 9:35 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Thu, 28 Sep 2023 03:07:22 +0530
> > Jagath Jog J <jagathjog1996@gmail.com> wrote:
> >  
> > > HI Jonathan,
> > >
> > > On Sun, Sep 24, 2023 at 7:07 PM Jonathan Cameron <jic23@kernel.org> wrote:  
> > > >
> > > > On Mon, 18 Sep 2023 13:33:13 +0530
> > > > Jagath Jog J <jagathjog1996@gmail.com> wrote:
> > > >  
> > > > > Add devicetree description document for Bosch BMI323, a 6-Axis IMU.
> > > > >
> > > > > Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>  
> 
> > > > > +  interrupts:
> > > > > +    maxItems: 1
> > > > > +
> > > > > +  interrupt-names:
> > > > > +    enum:
> > > > > +      - INT1
> > > > > +      - INT2
> > > > > +    description: |
> > > > > +      set to "INT1" if INT1 pin should be used as interrupt input, set
> > > > > +      to "INT2" if INT2 pin should be used instead  
> > > >
> > > > Why not both?  Sure driver might elect to use only one, but the binding
> > > > describes the hardware not the driver and both might be wired.  
> > >
> > > If both interrupt pins are wired, should the DTS file need to define
> > > both of the pins?  
> >
> > Yes it should. + we need the names to know which is which.
> > You could rely on order, but it's more flexible to not do so, particularly
> > when you also need to support case where only one is wired.  
> 
> In the driver, I currently prioritize INT1 over INT2 when checking
> (bmi323_trigger_probe(..)) based on the interrupt-names defined
> in the device tree. However, I'm open to suggestions on the best
> way to ensure that the order doesn't affect the selection process
> when both interrupts are defined in the device tree.

If they are both present it is absolutely fine to pick one in preference
to the other.

> 
> Each feature, such as data-ready, watermark, tap, and others, supports
> either INT1 or INT2. Based on the interrupt pin defined in the device tree,
> I configure the all the features accordingly.

That's an implementation choice to do them all based on one interrupt
pin so absolutely fine to do that in the Linux driver, but the dt binding
should allow for other choices as there are sometimes efficiency gains
in doing so.

> 
> Regarding your earlier suggestion to have two different controls for
> drive-open-drain, do I need to define sensor-specific drive controls
> in bindings for both interrupt pins?
> for ex: bosch,irq{1,2}-open-drain

Hmm. We do have precedence for a single control e.g.
nxp,fxls8962af.yaml as drive-open-drain.  So perhaps just go with that
and if anyone is needs different values we can figure it out later.
pin control (which is where that binding item comes from) seems to have
examples doing much the same.  Sets of pins with a single drive-open-drain
entry.

Linus, any comments on this as you've dealt with far more similar cases
than me!

Jonathan

> 
> Regards
> Jagath
> >
> >
> > Jonathan
> >
> >
Linus Walleij Oct. 10, 2023, 9:06 a.m. UTC | #5
On Tue, Oct 10, 2023 at 10:59 AM Jonathan Cameron <jic23@kernel.org> wrote:
> Jagath Jog J <jagathjog1996@gmail.com> wrote:

> > Regarding your earlier suggestion to have two different controls for
> > drive-open-drain, do I need to define sensor-specific drive controls
> > in bindings for both interrupt pins?
> > for ex: bosch,irq{1,2}-open-drain
>
> Hmm. We do have precedence for a single control e.g.
> nxp,fxls8962af.yaml as drive-open-drain.  So perhaps just go with that
> and if anyone is needs different values we can figure it out later.
> pin control (which is where that binding item comes from) seems to have
> examples doing much the same.  Sets of pins with a single drive-open-drain
> entry.
>
> Linus, any comments on this as you've dealt with far more similar cases
> than me!

Also st,st-sensors use drive-open-drain.

And that in turn is used because the pin control subsystem use that
exact property. (See
Documentation/devicetree/bindings/pinctrl/pincfg-node.yaml)

So use that.

(I'm so happy to be able to provide a definitive answer for once!)

Yours,
Linus Walleij
Jonathan Cameron Oct. 10, 2023, 2:42 p.m. UTC | #6
On Tue, 10 Oct 2023 11:06:18 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Tue, Oct 10, 2023 at 10:59 AM Jonathan Cameron <jic23@kernel.org> wrote:
> > Jagath Jog J <jagathjog1996@gmail.com> wrote:  
> 
> > > Regarding your earlier suggestion to have two different controls for
> > > drive-open-drain, do I need to define sensor-specific drive controls
> > > in bindings for both interrupt pins?
> > > for ex: bosch,irq{1,2}-open-drain  
> >
> > Hmm. We do have precedence for a single control e.g.
> > nxp,fxls8962af.yaml as drive-open-drain.  So perhaps just go with that
> > and if anyone is needs different values we can figure it out later.
> > pin control (which is where that binding item comes from) seems to have
> > examples doing much the same.  Sets of pins with a single drive-open-drain
> > entry.
> >
> > Linus, any comments on this as you've dealt with far more similar cases
> > than me!  
> 
> Also st,st-sensors use drive-open-drain.
> 
> And that in turn is used because the pin control subsystem use that
> exact property. (See
> Documentation/devicetree/bindings/pinctrl/pincfg-node.yaml)
> 
> So use that.
> 
> (I'm so happy to be able to provide a definitive answer for once!)

We kind of lost the question along the way.  Wasn't so much about whether
there was a generic binding but more about whether it is worth providing
separate controls for the two IRQ pins?  Or just assume no one is crazy
enough to play that level of mix and match.

J
> 
> Yours,
> Linus Walleij
Linus Walleij Oct. 10, 2023, 7:51 p.m. UTC | #7
On Tue, Oct 10, 2023 at 4:42 PM Jonathan Cameron <jic23@kernel.org> wrote:

> We kind of lost the question along the way.  Wasn't so much about whether
> there was a generic binding but more about whether it is worth providing
> separate controls for the two IRQ pins?  Or just assume no one is crazy
> enough to play that level of mix and match.

Ugh no, that's upfront design for a nonexistent use case.

- First, to even consider open drain the designer need to be really
  short of IRQ lines/rails, and, despite knowing it's a bad idea, decide
  to share this line between several peripherals, even though it will
  require I2C traffic to just determine which one even fired the IRQ.

- Second, be interested in using two IRQs to distinguish between
  different events? When we just faced the situation that we had
  too few IRQ lines so we need to start sharing them with open
  drain...?

It's not gonna happen.

Stay with just drive-open-drain; and configure them all as that if
that property is set.

Yours,
Linus Walleij
Jonathan Cameron Oct. 13, 2023, 8:16 a.m. UTC | #8
On Tue, 10 Oct 2023 21:51:17 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Tue, Oct 10, 2023 at 4:42 PM Jonathan Cameron <jic23@kernel.org> wrote:
> 
> > We kind of lost the question along the way.  Wasn't so much about whether
> > there was a generic binding but more about whether it is worth providing
> > separate controls for the two IRQ pins?  Or just assume no one is crazy
> > enough to play that level of mix and match.  
> 
> Ugh no, that's upfront design for a nonexistent use case.
> 
> - First, to even consider open drain the designer need to be really
>   short of IRQ lines/rails, and, despite knowing it's a bad idea, decide
>   to share this line between several peripherals, even though it will
>   require I2C traffic to just determine which one even fired the IRQ.
> 
> - Second, be interested in using two IRQs to distinguish between
>   different events? When we just faced the situation that we had
>   too few IRQ lines so we need to start sharing them with open
>   drain...?
> 
> It's not gonna happen.
> 
> Stay with just drive-open-drain; and configure them all as that if
> that property is set.

Good insights, I'd not really thought about the wider reasons for using
this :)  Not done any circuit design or embedded board bring up in a
long while.

Thanks!

> 
> Yours,
> Linus Walleij
>