Skip to contentSkip to conversation

iio: inv_mpu6050: Remove superfluous indio_dev->modes assignment

PATCH In review Lars-Peter Clausen 5 participants 10 messages Mar 25, 2021 – Mar 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iio: inv_mpu6050: Remove superfluous indio_dev->modes assignment

The inv_mpu6050 driver manually assigns the indio_dev->modes property. But this is not necessary since it will be setup in iio_trigger_buffer_setup().

Remove the manual assignment.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -1
index 453c51c79655..99ee0a218875 100644
@@ -1591,7 +1591,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	}
 
 	indio_dev->info = &mpu_info;
-	indio_dev->modes = INDIO_BUFFER_TRIGGERED;
 
 	result = devm_iio_triggered_buffer_setup(dev, indio_dev,
 						 iio_pollfunc_store_time,
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 iio: inv_mpu6050: Make interrupt optional

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 51 ++++++++++++++--------
 1 file changed, 32 insertions(+), 19 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +32 -19
index 99ee0a218875..cda7b48981c9 100644
@@ -1458,15 +1458,21 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 		st->plat_data = *pdata;
 	}
 
-	desc = irq_get_irq_data(irq);
-	if (!desc) {
-		dev_err(dev, "Could not find IRQ %d\n", irq);
-		return -EINVAL;
-	}
+	if (irq > 0) {
+		desc = irq_get_irq_data(irq);
+		if (!desc) {
+			dev_err(dev, "Could not find IRQ %d\n", irq);
+			return -EINVAL;
+		}
 
-	irq_type = irqd_get_trigger_type(desc);
-	if (!irq_type)
+		irq_type = irqd_get_trigger_type(desc);
+		if (!irq_type)
+			irq_type = IRQF_TRIGGER_RISING;
+	} else {
+		/* Doesn't really matter, use the default */
 		irq_type = IRQF_TRIGGER_RISING;
+	}
+
 	if (irq_type & IRQF_TRIGGER_RISING)	// rising or both-edge
 		st->irq_mask = INV_MPU6050_ACTIVE_HIGH;
 	else if (irq_type == IRQF_TRIGGER_FALLING)
@@ -1592,18 +1598,25 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 
 	indio_dev->info = &mpu_info;
 
-	result = devm_iio_triggered_buffer_setup(dev, indio_dev,
-						 iio_pollfunc_store_time,
-						 inv_mpu6050_read_fifo,
-						 NULL);
-	if (result) {
-		dev_err(dev, "configure buffer fail %d\n", result);
-		return result;
-	}
-	result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
-	if (result) {
-		dev_err(dev, "trigger probe fail %d\n", result);
-		return result;
+	if (irq > 0) {
+		/*
+		 * The driver currently only supports buffered capture with its
+		 * own trigger. So no IRQ, no trigger, no buffer
+		 */
+		result = devm_iio_triggered_buffer_setup(dev, indio_dev,
+							 iio_pollfunc_store_time,
+							 inv_mpu6050_read_fifo,
+							 NULL);
+		if (result) {
+			dev_err(dev, "configure buffer fail %d\n", result);
+			return result;
+		}
+
+		result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
+		if (result) {
+			dev_err(dev, "trigger probe fail %d\n", result);
+			return result;
+		}
 	}
 
 	result = devm_iio_device_register(dev, indio_dev);
Signature · 1 line
2.20.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

Quoted 7 lines · Lars-Peter Clausen

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

Makes sense.

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -4
-       result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
-       if (result) {
-               dev_err(dev, "trigger probe fail %d\n", result);
-               return result;

(...)

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · line 1605

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +4 -0
+               /*
+                * The driver currently only supports buffered capture with its
+                * own trigger. So no IRQ, no trigger, no buffer
+                */

I bet it can be made to work with e.g. a hrtimer trigger quite easily since we support raw reading?

Yours,
Linus Walleij

#3 lore raw

Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

Quoted 16 lines · Linus Walleij
Quoted 7 lines · Lars-Peter Clausen

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

Makes sense.

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · line 1606

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -4
-       result = inv_mpu6050_probe_trigger(indio_dev, irq_type);
-       if (result) {
-               dev_err(dev, "trigger probe fail %d\n", result);
-               return result;
Quoted 7 lines

(...)

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · line 1605

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +4 -0
+               /*
+                * The driver currently only supports buffered capture with its
+                * own trigger. So no IRQ, no trigger, no buffer
+                */

I bet it can be made to work with e.g. a hrtimer trigger quite easily since we support raw reading?

I looked into that. With the current implementation it will not work since the trigger enable callback enables the channels.

IIO has dedicated enable/disable callbacks for the buffer where this should usually happen. So this could be added to the driver if somebody wants it.

- Lars

#4 lore raw

Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

In reply to Lars-Peter Clausen

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · line 1469

Quoted 12 lines · Lars-Peter Clausen

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +2 -2
-       irq_type = irqd_get_trigger_type(desc);
-       if (!irq_type)
+               irq_type = irqd_get_trigger_type(desc);
+               if (!irq_type)

A side note: perhaps change this to comparison with IRQ_TYPE_NONE (as a separate change)?

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

Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Lars-Peter Clausen

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

Quoted 7 lines

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name, · line 1469

Quoted 4 lines
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +2 -2
-       irq_type = irqd_get_trigger_type(desc);
-       if (!irq_type)
+               irq_type = irqd_get_trigger_type(desc);
+               if (!irq_type)

A side note: perhaps change this to comparison with IRQ_TYPE_NONE (as a separate change)?

And use actually IRQ_TYPE and not IRQF (the values are the same but semantics is different). I have seen that in many drivers :-(

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

Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

Hello,

looks good, thanks for the patch.

With this patch, we can only use polling when there is no interrupt. If we want to use another trigger (like a timer, it would be interesting), we would need to keep the buffer in the device.

But this would be better in a separate patch.

Thanks,
JB

From: Andy Shevchenko <[email protected]>
Sent: Friday, March 26, 2021 11:57
To: Lars-Peter Clausen <[email protected]>
Cc: Jonathan Cameron <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Linus Walleij <[email protected]>; linux-iio <[email protected]>
Subject: Re: [PATCH 2/2] iio: inv_mpu6050: Make interrupt optional

 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Lars-Peter Clausen

The inv_mpu6050 driver requires an interrupt for buffered capture. But non buffered reading for measurements works just fine without an interrupt connected.

Make the interrupt optional to support this case.

Quoted 7 lines
Quoted 4 lines

-       irq_type = irqd_get_trigger_type(desc); -       if (!irq_type)
+               irq_type = irqd_get_trigger_type(desc); +               if (!irq_type)

A side note: perhaps change this to comparison with IRQ_TYPE_NONE (as a separate change)?

And use actually IRQ_TYPE and not IRQF (the values are the same but semantics is different). I have seen that in many drivers :-(

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v1 1/2
#7 lore raw
In reply to Lars-Peter Clausen
Quoted 6 lines · Lars-Peter Clausen

The inv_mpu6050 driver manually assigns the indio_dev->modes property. But this is not necessary since it will be setup in iio_trigger_buffer_setup().

Remove the manual assignment.

The word "manual" confuse me as much as usual when it comes to a computer program and makes me look for the man doing the manual work, but I guess you mean "imperatively" which is a word noone uses.

Yours,
Linus Walleij

Acked-by on v1 1/2
#8 lore raw
In reply to Lars-Peter Clausen

Hello,

thanks for the patch,
JB

From: Lars-Peter Clausen <[email protected]>
Sent: Thursday, March 25, 2021 14:10
To: Jonathan Cameron <[email protected]>
Cc: Jean-Baptiste Maneyrol <[email protected]>; Linus Walleij <[email protected]>; [email protected] <[email protected]>; Lars-Peter Clausen <[email protected]>
Subject: [PATCH 1/2] iio: inv_mpu6050: Remove superfluous indio_dev->modes assignment

 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

The inv_mpu6050 driver manually assigns the indio_dev->modes property. But this is not necessary since it will be setup in iio_trigger_buffer_setup().

Remove the manual assignment.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 1 -

 1 file changed, 1 deletion(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -0
index 453c51c79655..99ee0a218875 100644
@@ -1591,7 +1591,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,

         }

         indio_dev->info = &mpu_info;
-       indio_dev->modes = INDIO_BUFFER_TRIGGERED;

         result = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time,

Signature · 1 line
2.20.1
maintainer
#9 lore raw
In reply to Lars-Peter Clausen
Quoted 6 lines · On Thu, 25 Mar 2021 14:10:45 +0100 Lars-Peter Clausen <[email protected]> wrote:

The inv_mpu6050 driver manually assigns the indio_dev->modes property. But this is not necessary since it will be setup in iio_trigger_buffer_setup().

Remove the manual assignment.

Both applied to the togreg branch of iio.git and pushed out as testing fo the autobuilders to poke at it.

Thanks,

Jonathan

Quoted 16 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +0 -1
index 453c51c79655..99ee0a218875 100644
@@ -1591,7 +1591,6 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
 	}
 
 	indio_dev->info = &mpu_info;
-	indio_dev->modes = INDIO_BUFFER_TRIGGERED;
 
 	result = devm_iio_triggered_buffer_setup(dev, indio_dev,
 						 iio_pollfunc_store_time,