linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
@ 2020-03-19  6:07 Rohit Sarkar
  2020-03-19 10:24 ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Rohit Sarkar @ 2020-03-19  6:07 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Jean-Baptiste Maneyrol, Andy Shevchenko,
	Linus Walleij, linux-iio, linux-kernel

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(+)

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
 };
 
 /**
-- 
2.23.0.385.gbc12974a89


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-19  6:07 [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
@ 2020-03-19 10:24 ` Andy Shevchenko
  2020-03-19 11:08   ` Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2020-03-19 10:24 UTC (permalink / raw)
  To: Rohit Sarkar
  Cc: linux-iio, Linux Kernel Mailing List, Jonathan Cameron,
	Hartmut Knaack, Lars-Peter Clausen, Peter Meerwald-Stadler,
	Jean-Baptiste Maneyrol, Andy Shevchenko, Linus Walleij

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.

>  };


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-19 10:24 ` Andy Shevchenko
@ 2020-03-19 11:08   ` Jean-Baptiste Maneyrol
  2020-03-21 18:31     ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-03-19 11:08 UTC (permalink / raw)
  To: Andy Shevchenko, Rohit Sarkar; +Cc: linux-iio

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.



>  };





-- 

With Best Regards,

Andy Shevchenko


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-19 11:08   ` Jean-Baptiste Maneyrol
@ 2020-03-21 18:31     ` Jonathan Cameron
  2020-03-21 19:53       ` Andy Shevchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2020-03-21 18:31 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: Andy Shevchenko, Rohit Sarkar, linux-iio

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-21 18:31     ` Jonathan Cameron
@ 2020-03-21 19:53       ` Andy Shevchenko
  2020-03-27 10:56         ` Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2020-03-21 19:53 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Jean-Baptiste Maneyrol, Rohit Sarkar, linux-iio

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-21 19:53       ` Andy Shevchenko
@ 2020-03-27 10:56         ` Jean-Baptiste Maneyrol
  2020-03-27 12:42           ` Rohit Sarkar
  0 siblings, 1 reply; 7+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-03-27 10:56 UTC (permalink / raw)
  To: Andy Shevchenko, Jonathan Cameron; +Cc: Rohit Sarkar, linux-iio

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



-- 

With Best Regards,

Andy Shevchenko


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-27 10:56         ` Jean-Baptiste Maneyrol
@ 2020-03-27 12:42           ` Rohit Sarkar
  0 siblings, 0 replies; 7+ messages in thread
From: Rohit Sarkar @ 2020-03-27 12:42 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol; +Cc: Andy Shevchenko, Jonathan Cameron, linux-iio

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
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-27 12:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19  6:07 [PATCH] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
2020-03-19 10:24 ` Andy Shevchenko
2020-03-19 11:08   ` Jean-Baptiste Maneyrol
2020-03-21 18:31     ` Jonathan Cameron
2020-03-21 19:53       ` Andy Shevchenko
2020-03-27 10:56         ` Jean-Baptiste Maneyrol
2020-03-27 12:42           ` Rohit Sarkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).