diff mbox series

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

Message ID 5e730c2f.1c69fb81.9eda3.5c70@mx.google.com (mailing list archive)
State Superseded
Headers show
Series iio: imu: inv_mpu6050: add debugfs register r/w interface | expand

Commit Message

Rohit Sarkar March 19, 2020, 6:07 a.m. UTC
The iio debugfs interface provides direct access to read and write device
registers if debugfs is enabled.

Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Andy Shevchenko March 19, 2020, 10:24 a.m. UTC | #1
On Thu, Mar 19, 2020 at 8:10 AM Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
>
> 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?

...

>  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.

>  };
Jean-Baptiste Maneyrol March 19, 2020, 11:08 a.m. UTC | #2
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 <andy.shevchenko@gmail.com>

Sent: Thursday, March 19, 2020 11:24

To: Rohit Sarkar <rohitsarkar5398@gmail.com>

Cc: linux-iio <linux-iio@vger.kernel.org>; Linux Kernel Mailing List <linux-kernel@vger.kernel.org>; Jonathan Cameron <jic23@kernel.org>; Hartmut Knaack <knaack.h@gmx.de>; Lars-Peter Clausen <lars@metafoo.de>; Peter Meerwald-Stadler <pmeerw@pmeerw.net>;
 Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Andy Shevchenko <andriy.shevchenko@linux.intel.com>; Linus Walleij <linus.walleij@linaro.org>

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 Thu, Mar 19, 2020 at 8:10 AM Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:

>

> 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?



...



>  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.



>  };
Jonathan Cameron March 21, 2020, 6:31 p.m. UTC | #3
On Thu, 19 Mar 2020 11:08:44 +0000
Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:

> 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

> 
> Thanks.
> JB
> 
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> Sent: Thursday, March 19, 2020 11:24
> 
> To: Rohit Sarkar <rohitsarkar5398@gmail.com>
> 
> Cc: linux-iio <linux-iio@vger.kernel.org>; Linux Kernel Mailing List <linux-kernel@vger.kernel.org>; Jonathan Cameron <jic23@kernel.org>; Hartmut Knaack <knaack.h@gmx.de>; Lars-Peter Clausen <lars@metafoo.de>; Peter Meerwald-Stadler <pmeerw@pmeerw.net>;
>  Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Andy Shevchenko <andriy.shevchenko@linux.intel.com>; Linus Walleij <linus.walleij@linaro.org>
> 
> 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 Thu, Mar 19, 2020 at 8:10 AM Rohit Sarkar <rohitsarkar5398@gmail.com> wrote:
> 
> >  
> 
> > 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?
> 
> 
> 
> ...
> 
> 
> 
> >  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.
> 
> 
> 
> >  };  
> 
> 
> 
> 
>
Andy Shevchenko March 21, 2020, 7:53 p.m. UTC | #4
On Sat, Mar 21, 2020 at 8:31 PM Jonathan Cameron
<jic23@jic23.retrosnub.co.uk> wrote:
> On Thu, 19 Mar 2020 11:08:44 +0000
> Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:

> > 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.

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

> 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.!
Jean-Baptiste Maneyrol March 27, 2020, 10:56 a.m. UTC | #5
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 <andy.shevchenko@gmail.com>

Sent: Saturday, March 21, 2020 20:53

To: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>

Cc: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Rohit Sarkar <rohitsarkar5398@gmail.com>; linux-iio <linux-iio@vger.kernel.org>

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

<jic23@jic23.retrosnub.co.uk> wrote:

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

> Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:



> > 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.



Sometimes IIO driver provides a sensor data about platform facilities,

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



> 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.!
Rohit Sarkar March 27, 2020, 12:42 p.m. UTC | #6
On Fri, Mar 27, 2020 at 10:56:33AM +0000, Jean-Baptiste Maneyrol wrote:
> 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
> I am waiting for V2.
Will send it asap, was waiting for your ack.
> Thanks for the patch,
> JB
> 
> 
> 
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> Sent: Saturday, March 21, 2020 20:53
> 
> To: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>
> 
> Cc: Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Rohit Sarkar <rohitsarkar5398@gmail.com>; linux-iio <linux-iio@vger.kernel.org>
> 
> 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
> 
> <jic23@jic23.retrosnub.co.uk> wrote:
> 
> > On Thu, 19 Mar 2020 11:08:44 +0000
> 
> > Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:
> 
> 
> 
> > > 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.
> 
> 
> 
> Sometimes IIO driver provides a sensor data about platform facilities,
> 
> such as temperature of the die / chip or battery voltage threshold.
> 
> 
> 
> > 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.!
> 
> 
> 
> -- 
> 
> With Best Regards,
> 
> Andy Shevchenko
>
diff mbox series

Patch

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 7cb9ff3d3e94..3f40db8ea9e2 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -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
 };
 
 /**