Skip to contentSkip to conversation

iio: imu: inv_mpu6050: add debugfs register r/w interface

PATCH Superseded Rohit Sarkar 4 participants 7 messages Mar 19, 2020 – Mar 27, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: imu: inv_mpu6050: add debugfs register r/w interface

The iio debugfs interface provides direct access to read and write device registers if debugfs is enabled.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +14 -0
index 7cb9ff3d3e94..3f40db8ea9e2 100644
@@ -1248,12 +1248,26 @@ static const struct attribute_group inv_attribute_group = {
 	.attrs = inv_attributes
 };
 
+static int inv_mpu6050_reg_access(struct iio_dev *indio_dev,
+				  unsigned int reg,
+				  unsigned int writeval,
+				  unsigned int *readval)
+{
+	struct inv_mpu6050_state *st = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read(st->map, reg, readval);
+	else
+		return regmap_write(st->map, reg, writeval);
+}
+
 static const struct iio_info mpu_info = {
 	.read_raw = &inv_mpu6050_read_raw,
 	.write_raw = &inv_mpu6050_write_raw,
 	.write_raw_get_fmt = &inv_write_raw_get_fmt,
 	.attrs = &inv_attribute_group,
 	.validate_trigger = inv_mpu6050_validate_trigger,
+	.debugfs_reg_access = &inv_mpu6050_reg_access
 };
 
 /**
Signature · 1 line
2.23.0.385.gbc12974a89
#1 lore raw
Quoted 3 lines · Rohit Sarkar

The iio debugfs interface provides direct access to read and write device registers if debugfs is enabled.

But regmap API provides at least reading facility. Isn't it enough?

...

Quoted 8 lines

static const struct iio_info mpu_info = {
.read_raw = &inv_mpu6050_read_raw, .write_raw = &inv_mpu6050_write_raw, .write_raw_get_fmt = &inv_write_raw_get_fmt, .attrs = &inv_attribute_group, .validate_trigger = inv_mpu6050_validate_trigger,

+ .debugfs_reg_access = &inv_mpu6050_reg_access

Leaving comma is helpful for future development.

Quoted 1 line

};

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

Hello,

iio debugfs register interface is quite handy because we can read a single register and write a value.

regmap debugfs is only a dump of all registers, as far as I know (may have missed something).

Thanks.
JB

From: Andy Shevchenko <[email protected]>

Sent: Thursday, March 19, 2020 11:24

To: Rohit Sarkar <[email protected]>

Cc: linux-iio <[email protected]>; Linux Kernel Mailing List <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>;
Jean-Baptiste Maneyrol <[email protected]>; Andy Shevchenko <[email protected]>; Linus Walleij <[email protected]>

Subject: Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface

 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 5 lines · Rohit Sarkar

The iio debugfs interface provides direct access to read and write device

registers if debugfs is enabled.

But regmap API provides at least reading facility. Isn't it enough?

...

Quoted 8 lines

  static const struct iio_info mpu_info = {

         .read_raw = &inv_mpu6050_read_raw,

         .write_raw = &inv_mpu6050_write_raw,

         .write_raw_get_fmt = &inv_write_raw_get_fmt,

Quoted 7 lines

         .attrs = &inv_attribute_group,

         .validate_trigger = inv_mpu6050_validate_trigger,

+       .debugfs_reg_access = &inv_mpu6050_reg_access

Leaving comma is helpful for future development.

Quoted 1 line

  };

Signature · 3 lines
With Best Regards,

Andy Shevchenko
#3 lore raw
Quoted 5 lines · On Thu, 19 Mar 2020 11:08:44 +0000 Jean-Baptiste Maneyrol…

Hello,

iio debugfs register interface is quite handy because we can read a single register and write a value.

regmap debugfs is only a dump of all registers, as far as I know (may have missed something).

So this is something Mark has discussed before around regmap and more generally IIRC. The issue is that a write interface does make it somewhat easy to do really nasty things in some drivers that use regmap (to the extent of setting boards on fire etc). For IIO we are much safer - the worst you can do is break the IIO driver.

I've never been that fussed myself about the debugfs interfaces as it's easy to hack them in when needed for actual debugging, but have taken the view that if someone has enough of a usecase to want to add them to a particular driver, then it's up to them.

Jonathan

Quoted 68 lines

Thanks.
JB

From: Andy Shevchenko <[email protected]>

Sent: Thursday, March 19, 2020 11:24

To: Rohit Sarkar <[email protected]>

Cc: linux-iio <[email protected]>; Linux Kernel Mailing List <[email protected]>; Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>;
Jean-Baptiste Maneyrol <[email protected]>; Andy Shevchenko <[email protected]>; Linus Walleij <[email protected]>

Subject: Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface

 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 5 lines · Rohit Sarkar

The iio debugfs interface provides direct access to read and write device

registers if debugfs is enabled.

But regmap API provides at least reading facility. Isn't it enough?

...

Quoted 8 lines

  static const struct iio_info mpu_info = {

         .read_raw = &inv_mpu6050_read_raw,

         .write_raw = &inv_mpu6050_write_raw,

         .write_raw_get_fmt = &inv_write_raw_get_fmt,

Quoted 7 lines

         .attrs = &inv_attribute_group,

         .validate_trigger = inv_mpu6050_validate_trigger,

+       .debugfs_reg_access = &inv_mpu6050_reg_access

Leaving comma is helpful for future development.

Quoted 1 line

  };

#4 lore raw
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Thu, 19 Mar 2020 11:08:44 +0000 Jean-Baptiste Maneyrol…

iio debugfs register interface is quite handy because we can read a single register and write a value.

Quoted 8 lines
Quoted 1 line

regmap debugfs is only a dump of all registers, as far as I know (may have missed something).

So this is something Mark has discussed before around regmap and more generally IIRC. The issue is that a write interface does make it somewhat easy to do really nasty things in some drivers that use regmap (to the extent of setting boards on fire etc). For IIO we are much safer - the worst you can do is break the IIO driver.

Sometimes IIO driver provides a sensor data about platform facilities, such as temperature of the die / chip or battery voltage threshold.

Quoted 4 lines

I've never been that fussed myself about the debugfs interfaces as it's easy to hack them in when needed for actual debugging, but have taken the view that if someone has enough of a usecase to want to add them to a particular driver, then it's up to them.

Good to know your p.o.v.!

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

Hello,

this is quite useful for me for debugging and testing. So I am in favor.

Just one comment, I think it is safer here to lock the mutex to ensure this doesn't happen in the middle of an interrupt or anything else. I am waiting for V2.

Thanks for the patch,
JB

From: Andy Shevchenko <[email protected]>

Sent: Saturday, March 21, 2020 20:53

To: Jonathan Cameron <[email protected]>

Cc Jean-Baptiste Maneyrol <[email protected]>; Rohit Sarkar <[email protected]>; linux-iio <[email protected]>

Subject: Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface

 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.

On Sat, Mar 21, 2020 at 8:31 PM Jonathan Cameron

Quoted 18 lines · <[email protected]> wrote:

On Thu, 19 Mar 2020 11:08:44 +0000

Quoted 5 lines · Jean-Baptiste Maneyrol

iio debugfs register interface is quite handy because we can read a single register and write a value.

regmap debugfs is only a dump of all registers, as far as I know (may have missed something).

So this is something Mark has discussed before around regmap

and more generally IIRC.  The issue is that a write

Quoted 7 lines

interface does make it somewhat easy to do really nasty things

in some drivers that use regmap (to the extent of setting boards

on fire etc).  For IIO we are much safer - the worst you can do

is break the IIO driver.

Sometimes IIO driver provides a sensor data about platform facilities,

such as temperature of the die / chip or battery voltage threshold.

Quoted 7 lines

I've never been that fussed myself about the debugfs interfaces

as it's easy to hack them in when needed for actual debugging, but

have taken the view that if someone has enough of a usecase to

want to add them to a particular driver, then it's up to them.

Good to know your p.o.v.!

Signature · 3 lines
With Best Regards,

Andy Shevchenko
#6 lore raw
Quoted 5 lines · Jean-Baptiste Maneyrol

Hello,

this is quite useful for me for debugging and testing. So I am in favor.

Just one comment, I think it is safer here to lock the mutex to ensure this doesn't happen in the middle of an interrupt or anything else.

Sure

Quoted 1 line

I am waiting for V2.

Will send it asap, was waiting for your ack.

Quoted 80 lines

Thanks for the patch,
JB

From: Andy Shevchenko <[email protected]>

Sent: Saturday, March 21, 2020 20:53

To: Jonathan Cameron <[email protected]>

Cc Jean-Baptiste Maneyrol <[email protected]>; Rohit Sarkar <[email protected]>; linux-iio <[email protected]>

Subject: Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface

 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.

On Sat, Mar 21, 2020 at 8:31 PM Jonathan Cameron

Quoted 18 lines · <[email protected]> wrote:

On Thu, 19 Mar 2020 11:08:44 +0000

Quoted 5 lines · Jean-Baptiste Maneyrol

iio debugfs register interface is quite handy because we can read a single register and write a value.

regmap debugfs is only a dump of all registers, as far as I know (may have missed something).

So this is something Mark has discussed before around regmap

and more generally IIRC.  The issue is that a write

Quoted 7 lines

interface does make it somewhat easy to do really nasty things

in some drivers that use regmap (to the extent of setting boards

on fire etc).  For IIO we are much safer - the worst you can do

is break the IIO driver.

Sometimes IIO driver provides a sensor data about platform facilities,

such as temperature of the die / chip or battery voltage threshold.

Quoted 7 lines

I've never been that fussed myself about the debugfs interfaces

as it's easy to hack them in when needed for actual debugging, but

have taken the view that if someone has enough of a usecase to

want to add them to a particular driver, then it's up to them.

Good to know your p.o.v.!

Signature · 3 lines
With Best Regards,

Andy Shevchenko