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

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

Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
---
Changelog v1->v2
* grab a lock to protect driver state
* add a comma at the end of structure member initialisation

 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 +++++++++++++++++++
 1 file changed, 19 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..381a3fb09858 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1248,12 +1248,31 @@ 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);
+	int ret = 0;
+
+	mutex_lock(&st->lock);
+	if (readval)
+		ret = regmap_read(st->map, reg, readval);
+	else
+		ret = regmap_write(st->map, reg, writeval);
+	mutex_unlock(&st->lock);
+
+	return ret;
+}
+
 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] 5+ messages in thread

* Re: [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-27 13:10 [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
@ 2020-03-27 13:19 ` Andy Shevchenko
  2020-03-28 17:45   ` Jonathan Cameron
  2020-03-27 13:19 ` Andy Shevchenko
  2020-03-27 14:08 ` Jean-Baptiste Maneyrol
  2 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2020-03-27 13:19 UTC (permalink / raw)
  To: Rohit Sarkar
  Cc: linux-iio, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Jean-Baptiste Maneyrol, Linus Walleij,
	linux-kernel

On Fri, Mar 27, 2020 at 06:40:23PM +0530, Rohit Sarkar wrote:
> The debugfs interface provides direct access to read and write device
> registers if debugfs is enabled.
> 
> Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> ---
> Changelog v1->v2
> * grab a lock to protect driver state
> * add a comma at the end of structure member initialisation
> 
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 +++++++++++++++++++
>  1 file changed, 19 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..381a3fb09858 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1248,12 +1248,31 @@ 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);

> +	int ret = 0;

Assignment is redundant, but I think maintainers may update this when applying.

> +
> +	mutex_lock(&st->lock);
> +	if (readval)
> +		ret = regmap_read(st->map, reg, readval);
> +	else
> +		ret = regmap_write(st->map, reg, writeval);
> +	mutex_unlock(&st->lock);
> +
> +	return ret;
> +}
> +
>  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
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-27 13:10 [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
  2020-03-27 13:19 ` Andy Shevchenko
@ 2020-03-27 13:19 ` Andy Shevchenko
  2020-03-27 14:08 ` Jean-Baptiste Maneyrol
  2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2020-03-27 13:19 UTC (permalink / raw)
  To: Rohit Sarkar
  Cc: linux-iio, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Jean-Baptiste Maneyrol, Linus Walleij,
	linux-kernel

On Fri, Mar 27, 2020 at 06:40:23PM +0530, Rohit Sarkar wrote:
> The debugfs interface provides direct access to read and write device
> registers if debugfs is enabled.

FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> ---
> Changelog v1->v2
> * grab a lock to protect driver state
> * add a comma at the end of structure member initialisation
> 
>  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 +++++++++++++++++++
>  1 file changed, 19 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..381a3fb09858 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1248,12 +1248,31 @@ 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);
> +	int ret = 0;
> +
> +	mutex_lock(&st->lock);
> +	if (readval)
> +		ret = regmap_read(st->map, reg, readval);
> +	else
> +		ret = regmap_write(st->map, reg, writeval);
> +	mutex_unlock(&st->lock);
> +
> +	return ret;
> +}
> +
>  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
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-27 13:10 [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
  2020-03-27 13:19 ` Andy Shevchenko
  2020-03-27 13:19 ` Andy Shevchenko
@ 2020-03-27 14:08 ` Jean-Baptiste Maneyrol
  2 siblings, 0 replies; 5+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-03-27 14:08 UTC (permalink / raw)
  To: Rohit Sarkar, linux-iio
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Linus Walleij, Andy Shevchenko,
	linux-kernel

Hello,

thanks, it's OK for me.

Acked-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>

Best regards,
JB



From: Rohit Sarkar <rohitsarkar5398@gmail.com>

Sent: Friday, March 27, 2020 14:10

To: linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>

Cc: 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>; Linus Walleij <linus.walleij@linaro.org>;
 Andy Shevchenko <andriy.shevchenko@linux.intel.com>; linux-iio@vger.kernel.org <linux-iio@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>

Subject: [PATCH v2] 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.



The debugfs interface provides direct access to read and write device

registers if debugfs is enabled.



Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>

---

Changelog v1->v2

* grab a lock to protect driver state

* add a comma at the end of structure member initialisation



 drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 +++++++++++++++++++

 1 file changed, 19 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..381a3fb09858 100644

--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

@@ -1248,12 +1248,31 @@ 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);

+       int ret = 0;

+

+       mutex_lock(&st->lock);

+       if (readval)

+               ret = regmap_read(st->map, reg, readval);

+       else

+               ret = regmap_write(st->map, reg, writeval);

+       mutex_unlock(&st->lock);

+

+       return ret;

+}

+

 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	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface
  2020-03-27 13:19 ` Andy Shevchenko
@ 2020-03-28 17:45   ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2020-03-28 17:45 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rohit Sarkar, linux-iio, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Jean-Baptiste Maneyrol, Linus Walleij,
	linux-kernel

On Fri, 27 Mar 2020 15:19:01 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Fri, Mar 27, 2020 at 06:40:23PM +0530, Rohit Sarkar wrote:
> > The debugfs interface provides direct access to read and write device
> > registers if debugfs is enabled.
> > 
> > Signed-off-by: Rohit Sarkar <rohitsarkar5398@gmail.com>
> > ---
> > Changelog v1->v2
> > * grab a lock to protect driver state
> > * add a comma at the end of structure member initialisation
> > 
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 19 +++++++++++++++++++
> >  1 file changed, 19 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..381a3fb09858 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> > @@ -1248,12 +1248,31 @@ 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);  
> 
> > +	int ret = 0;  
> 
> Assignment is redundant, but I think maintainers may update this when applying.

Fixed up and applied to the togreg branch of iio.git and pushed
out as testing for the autobuilders to play with it.

Jonathan

> 
> > +
> > +	mutex_lock(&st->lock);
> > +	if (readval)
> > +		ret = regmap_read(st->map, reg, readval);
> > +	else
> > +		ret = regmap_write(st->map, reg, writeval);
> > +	mutex_unlock(&st->lock);
> > +
> > +	return ret;
> > +}
> > +
> >  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	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-03-28 17:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27 13:10 [PATCH v2] iio: imu: inv_mpu6050: add debugfs register r/w interface Rohit Sarkar
2020-03-27 13:19 ` Andy Shevchenko
2020-03-28 17:45   ` Jonathan Cameron
2020-03-27 13:19 ` Andy Shevchenko
2020-03-27 14:08 ` Jean-Baptiste Maneyrol

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