devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin
@ 2017-01-22 10:30 Lorenzo Bianconi
       [not found] ` <20170122103052.8769-1-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2017-01-22 10:30 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

Lorenzo Bianconi (2):
  iio: imu: st_lsm6dsx: add possibility to select drdy pin
  Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property

 .../devicetree/bindings/iio/imu/st_lsm6dsx.txt     |  2 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c       | 66 ++++++++++++++++++++--
 2 files changed, 62 insertions(+), 6 deletions(-)

-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin
       [not found] ` <20170122103052.8769-1-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
@ 2017-01-22 10:30   ` Lorenzo Bianconi
       [not found]     ` <20170122103052.8769-2-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
  2017-01-22 10:30   ` [PATCH 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi
  1 sibling, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2017-01-22 10:30 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

Add capability to route data ready signal on pin 1 or pin 2 of the package

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 66 +++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index f869dfa..bc50164 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -37,11 +37,14 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 
+#include <linux/platform_data/st_sensors_pdata.h>
+
 #include "st_lsm6dsx.h"
 
 #define ST_LSM6DSX_REG_ACC_DEC_MASK		GENMASK(2, 0)
 #define ST_LSM6DSX_REG_GYRO_DEC_MASK		GENMASK(5, 3)
 #define ST_LSM6DSX_REG_INT1_ADDR		0x0d
+#define ST_LSM6DSX_REG_INT2_ADDR		0x0e
 #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
 #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
 #define ST_LSM6DSX_REG_RESET_ADDR		0x12
@@ -532,10 +535,63 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
 
 static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
 
+#ifdef CONFIG_OF
+static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
+{
+	struct device_node *np = hw->dev->of_node;
+	int err;
+
+	if (!np)
+		return -EINVAL;
+
+	err = of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
+	if (err == -ENODATA) {
+		/* if the property has not been specified use default value */
+		*drdy_pin = 1;
+		err = 0;
+	}
+
+	return err;
+}
+#else
+static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
+{
+	return -EINVAL;
+}
+#endif /* CONFIG_OF */
+
+static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
+{
+	int err = 0, drdy_pin;
+
+	if (st_lsm6dsx_of_get_drdy_pin(hw, &drdy_pin) < 0) {
+		struct st_sensors_platform_data *pdata;
+		struct device *dev = hw->dev;
+
+		pdata = (struct st_sensors_platform_data *)dev->platform_data;
+		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
+	}
+
+	switch (drdy_pin) {
+	case 1:
+		*drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
+		break;
+	case 2:
+		*drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
+		break;
+	default:
+		dev_err(hw->dev, "unsupported data ready pin\n");
+		err = -EINVAL;
+		break;
+	}
+
+	return err;
+}
+
 static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 {
+	u8 data, drdy_int_reg;
 	int err;
-	u8 data;
 
 	data = ST_LSM6DSX_REG_RESET_MASK;
 	err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data),
@@ -563,14 +619,12 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
 		return err;
 
 	/* enable FIFO watermak interrupt */
-	err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT1_ADDR,
-					 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
+	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
 	if (err < 0)
 		return err;
 
-	/* redirect INT2 on INT1 */
-	return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT2_ON_INT1_ADDR,
-					  ST_LSM6DSX_REG_INT2_ON_INT1_MASK, 1);
+	return st_lsm6dsx_write_with_mask(hw, drdy_int_reg,
+					  ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
 }
 
 static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property
       [not found] ` <20170122103052.8769-1-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
  2017-01-22 10:30   ` [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi
@ 2017-01-22 10:30   ` Lorenzo Bianconi
       [not found]     ` <20170122103052.8769-3-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
  1 sibling, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2017-01-22 10:30 UTC (permalink / raw)
  To: jic23-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

Add st,drdy-int-pin property to select interrupt pin of the package

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
---
 Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
index ed3cdac..cf81afd 100644
--- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
+++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
@@ -7,6 +7,8 @@ Required properties:
 - reg: i2c address of the sensor / spi cs line
 
 Optional properties:
+- st,drdy-int-pin: the pin on the package that will be used to signal
+  "data ready" (valid values: 1 or 2).
 - interrupt-parent: should be the phandle for the interrupt controller
 - interrupts: interrupt mapping for IRQ. It should be configured with
   flags IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING.
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin
       [not found]     ` <20170122103052.8769-2-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
@ 2017-01-22 14:34       ` Jonathan Cameron
       [not found]         ` <3ca71ff6-fa9e-449a-8a21-7607ca2c2c55-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2017-01-22 14:34 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

On 22/01/17 10:30, Lorenzo Bianconi wrote:
> Add capability to route data ready signal on pin 1 or pin 2 of the package
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 66 +++++++++++++++++++++++++---
>  1 file changed, 60 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index f869dfa..bc50164 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -37,11 +37,14 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  
> +#include <linux/platform_data/st_sensors_pdata.h>
> +
>  #include "st_lsm6dsx.h"
>  
>  #define ST_LSM6DSX_REG_ACC_DEC_MASK		GENMASK(2, 0)
>  #define ST_LSM6DSX_REG_GYRO_DEC_MASK		GENMASK(5, 3)
>  #define ST_LSM6DSX_REG_INT1_ADDR		0x0d
> +#define ST_LSM6DSX_REG_INT2_ADDR		0x0e
>  #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
>  #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
>  #define ST_LSM6DSX_REG_RESET_ADDR		0x12
> @@ -532,10 +535,63 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
>  
>  static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
>  
> +#ifdef CONFIG_OF
Perhaps rely on the -ENOSYS return from
of_property_read_u32 stub instead of having the ifdefs around something so
simple.

> +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
> +{
> +	struct device_node *np = hw->dev->of_node;
> +	int err;
> +
> +	if (!np)
> +		return -EINVAL;
> +
> +	err = of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
> +	if (err == -ENODATA) {
> +		/* if the property has not been specified use default value */
> +		*drdy_pin = 1;
> +		err = 0;
> +	}
> +
> +	return err;
> +}
> +#else
> +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
> +{
> +	return -EINVAL;
> +}
> +#endif /* CONFIG_OF */
> +
> +static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
> +{
> +	int err = 0, drdy_pin;
> +
> +	if (st_lsm6dsx_of_get_drdy_pin(hw, &drdy_pin) < 0) {
> +		struct st_sensors_platform_data *pdata;
> +		struct device *dev = hw->dev;
> +
> +		pdata = (struct st_sensors_platform_data *)dev->platform_data;
> +		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
> +	}
> +
> +	switch (drdy_pin) {
> +	case 1:
> +		*drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
> +		break;
> +	case 2:
> +		*drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
> +		break;
> +	default:
> +		dev_err(hw->dev, "unsupported data ready pin\n");
> +		err = -EINVAL;
> +		break;
> +	}
> +
> +	return err;
> +}
> +
>  static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>  {
> +	u8 data, drdy_int_reg;
>  	int err;
> -	u8 data;
>  
>  	data = ST_LSM6DSX_REG_RESET_MASK;
>  	err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data),
> @@ -563,14 +619,12 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>  		return err;
>  
>  	/* enable FIFO watermak interrupt */
> -	err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT1_ADDR,
> -					 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
> +	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
>  	if (err < 0)
>  		return err;
>  
> -	/* redirect INT2 on INT1 */
> -	return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT2_ON_INT1_ADDR,
> -					  ST_LSM6DSX_REG_INT2_ON_INT1_MASK, 1);
Does removing this potentially break existing setups?

> +	return st_lsm6dsx_write_with_mask(hw, drdy_int_reg,
> +					  ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
>  }
>  
>  static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property
       [not found]     ` <20170122103052.8769-3-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
@ 2017-01-22 14:35       ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2017-01-22 14:35 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

On 22/01/17 10:30, Lorenzo Bianconi wrote:
> Add st,drdy-int-pin property to select interrupt pin of the package
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
Looks good and lines up with existing st-sensors binding.
> ---
>  Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> index ed3cdac..cf81afd 100644
> --- a/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> +++ b/Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt
> @@ -7,6 +7,8 @@ Required properties:
>  - reg: i2c address of the sensor / spi cs line
>  
>  Optional properties:
> +- st,drdy-int-pin: the pin on the package that will be used to signal
> +  "data ready" (valid values: 1 or 2).
>  - interrupt-parent: should be the phandle for the interrupt controller
>  - interrupts: interrupt mapping for IRQ. It should be configured with
>    flags IRQ_TYPE_LEVEL_HIGH or IRQ_TYPE_EDGE_RISING.
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin
       [not found]         ` <3ca71ff6-fa9e-449a-8a21-7607ca2c2c55-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
@ 2017-01-22 15:20           ` Lorenzo Bianconi
       [not found]             ` <20170122152033.o5crgdbsemdmv6rk-iOgT3W1YzDsjz3NcCDvlmNHuzzzSOjJt@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2017-01-22 15:20 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

Hi Jonathan,

thanks for the review :)

> On 22/01/17 10:30, Lorenzo Bianconi wrote:
> > Add capability to route data ready signal on pin 1 or pin 2 of the package
> > 
> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
> > ---
> >  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 66 +++++++++++++++++++++++++---
> >  1 file changed, 60 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index f869dfa..bc50164 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -37,11 +37,14 @@
> >  #include <linux/iio/iio.h>
> >  #include <linux/iio/sysfs.h>
> >  
> > +#include <linux/platform_data/st_sensors_pdata.h>
> > +
> >  #include "st_lsm6dsx.h"
> >  
> >  #define ST_LSM6DSX_REG_ACC_DEC_MASK		GENMASK(2, 0)
> >  #define ST_LSM6DSX_REG_GYRO_DEC_MASK		GENMASK(5, 3)
> >  #define ST_LSM6DSX_REG_INT1_ADDR		0x0d
> > +#define ST_LSM6DSX_REG_INT2_ADDR		0x0e
> >  #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
> >  #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
> >  #define ST_LSM6DSX_REG_RESET_ADDR		0x12
> > @@ -532,10 +535,63 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
> >  
> >  static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
> >  
> > +#ifdef CONFIG_OF
> Perhaps rely on the -ENOSYS return from
> of_property_read_u32 stub instead of having the ifdefs around something so
> simple.

ack, will do in v2

> 
> > +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
> > +{
> > +	struct device_node *np = hw->dev->of_node;
> > +	int err;
> > +
> > +	if (!np)
> > +		return -EINVAL;
> > +
> > +	err = of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
> > +	if (err == -ENODATA) {
> > +		/* if the property has not been specified use default value */
> > +		*drdy_pin = 1;
> > +		err = 0;
> > +	}
> > +
> > +	return err;
> > +}
> > +#else
> > +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
> > +{
> > +	return -EINVAL;
> > +}
> > +#endif /* CONFIG_OF */
> > +
> > +static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
> > +{
> > +	int err = 0, drdy_pin;
> > +
> > +	if (st_lsm6dsx_of_get_drdy_pin(hw, &drdy_pin) < 0) {
> > +		struct st_sensors_platform_data *pdata;
> > +		struct device *dev = hw->dev;
> > +
> > +		pdata = (struct st_sensors_platform_data *)dev->platform_data;
> > +		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
> > +	}
> > +
> > +	switch (drdy_pin) {
> > +	case 1:
> > +		*drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
> > +		break;
> > +	case 2:
> > +		*drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
> > +		break;
> > +	default:
> > +		dev_err(hw->dev, "unsupported data ready pin\n");
> > +		err = -EINVAL;
> > +		break;
> > +	}
> > +
> > +	return err;
> > +}
> > +
> >  static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> >  {
> > +	u8 data, drdy_int_reg;
> >  	int err;
> > -	u8 data;
> >  
> >  	data = ST_LSM6DSX_REG_RESET_MASK;
> >  	err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data),
> > @@ -563,14 +619,12 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> >  		return err;
> >  
> >  	/* enable FIFO watermak interrupt */
> > -	err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT1_ADDR,
> > -					 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
> > +	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
> >  	if (err < 0)
> >  		return err;
> >  
> > -	/* redirect INT2 on INT1 */
> > -	return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT2_ON_INT1_ADDR,
> > -					  ST_LSM6DSX_REG_INT2_ON_INT1_MASK, 1);
> Does removing this potentially break existing setups?
> 

No, it doesn't since INT2 was not configured yet

> > +	return st_lsm6dsx_write_with_mask(hw, drdy_int_reg,
> > +					  ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
> >  }
> >  
> >  static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
> > 
> 

Regards,
Lorenzo

-- 
UNIX is Sexy: who | grep -i blonde | talk; cd ~; wine; talk; touch; unzip; touch; strip; gasp; finger; gasp; mount; fsck; more; yes; gasp; umount; make clean; sleep

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

* Re: [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin
       [not found]             ` <20170122152033.o5crgdbsemdmv6rk-iOgT3W1YzDsjz3NcCDvlmNHuzzzSOjJt@public.gmane.org>
@ 2017-01-22 15:54               ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2017-01-22 15:54 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, lorenzo.bianconi-qxv4g6HH51o

On 22/01/17 15:20, Lorenzo Bianconi wrote:
> Hi Jonathan,
> 
> thanks for the review :)
> 
>> On 22/01/17 10:30, Lorenzo Bianconi wrote:
>>> Add capability to route data ready signal on pin 1 or pin 2 of the package
>>>
>>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
>>> ---
>>>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 66 +++++++++++++++++++++++++---
>>>  1 file changed, 60 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> index f869dfa..bc50164 100644
>>> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
>>> @@ -37,11 +37,14 @@
>>>  #include <linux/iio/iio.h>
>>>  #include <linux/iio/sysfs.h>
>>>  
>>> +#include <linux/platform_data/st_sensors_pdata.h>
>>> +
>>>  #include "st_lsm6dsx.h"
>>>  
>>>  #define ST_LSM6DSX_REG_ACC_DEC_MASK		GENMASK(2, 0)
>>>  #define ST_LSM6DSX_REG_GYRO_DEC_MASK		GENMASK(5, 3)
>>>  #define ST_LSM6DSX_REG_INT1_ADDR		0x0d
>>> +#define ST_LSM6DSX_REG_INT2_ADDR		0x0e
>>>  #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK	BIT(3)
>>>  #define ST_LSM6DSX_REG_WHOAMI_ADDR		0x0f
>>>  #define ST_LSM6DSX_REG_RESET_ADDR		0x12
>>> @@ -532,10 +535,63 @@ static const struct iio_info st_lsm6dsx_gyro_info = {
>>>  
>>>  static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
>>>  
>>> +#ifdef CONFIG_OF
>> Perhaps rely on the -ENOSYS return from
>> of_property_read_u32 stub instead of having the ifdefs around something so
>> simple.
> 
> ack, will do in v2
> 
>>
>>> +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
>>> +{
>>> +	struct device_node *np = hw->dev->of_node;
>>> +	int err;
>>> +
>>> +	if (!np)
>>> +		return -EINVAL;
>>> +
>>> +	err = of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
>>> +	if (err == -ENODATA) {
>>> +		/* if the property has not been specified use default value */
>>> +		*drdy_pin = 1;
>>> +		err = 0;
>>> +	}
>>> +
>>> +	return err;
>>> +}
>>> +#else
>>> +static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
>>> +{
>>> +	return -EINVAL;
>>> +}
>>> +#endif /* CONFIG_OF */
>>> +
>>> +static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
>>> +{
>>> +	int err = 0, drdy_pin;
>>> +
>>> +	if (st_lsm6dsx_of_get_drdy_pin(hw, &drdy_pin) < 0) {
>>> +		struct st_sensors_platform_data *pdata;
>>> +		struct device *dev = hw->dev;
>>> +
>>> +		pdata = (struct st_sensors_platform_data *)dev->platform_data;
>>> +		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
>>> +	}
>>> +
>>> +	switch (drdy_pin) {
>>> +	case 1:
>>> +		*drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
>>> +		break;
>>> +	case 2:
>>> +		*drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
>>> +		break;
>>> +	default:
>>> +		dev_err(hw->dev, "unsupported data ready pin\n");
>>> +		err = -EINVAL;
>>> +		break;
>>> +	}
>>> +
>>> +	return err;
>>> +}
>>> +
>>>  static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>>>  {
>>> +	u8 data, drdy_int_reg;
>>>  	int err;
>>> -	u8 data;
>>>  
>>>  	data = ST_LSM6DSX_REG_RESET_MASK;
>>>  	err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data),
>>> @@ -563,14 +619,12 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
>>>  		return err;
>>>  
>>>  	/* enable FIFO watermak interrupt */
>>> -	err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT1_ADDR,
>>> -					 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
>>> +	err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
>>>  	if (err < 0)
>>>  		return err;
>>>  
>>> -	/* redirect INT2 on INT1 */
>>> -	return st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_INT2_ON_INT1_ADDR,
>>> -					  ST_LSM6DSX_REG_INT2_ON_INT1_MASK, 1);
>> Does removing this potentially break existing setups?
>>
> 
> No, it doesn't since INT2 was not configured yet
ah. So this was previously effectively a noop. 
Thanks.
> 
>>> +	return st_lsm6dsx_write_with_mask(hw, drdy_int_reg,
>>> +					  ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
>>>  }
>>>  
>>>  static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
>>>
>>
> 
> Regards,
> Lorenzo
> 

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-01-22 15:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-22 10:30 [PATCH 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin Lorenzo Bianconi
     [not found] ` <20170122103052.8769-1-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
2017-01-22 10:30   ` [PATCH 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi
     [not found]     ` <20170122103052.8769-2-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
2017-01-22 14:34       ` Jonathan Cameron
     [not found]         ` <3ca71ff6-fa9e-449a-8a21-7607ca2c2c55-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-01-22 15:20           ` Lorenzo Bianconi
     [not found]             ` <20170122152033.o5crgdbsemdmv6rk-iOgT3W1YzDsjz3NcCDvlmNHuzzzSOjJt@public.gmane.org>
2017-01-22 15:54               ` Jonathan Cameron
2017-01-22 10:30   ` [PATCH 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi
     [not found]     ` <20170122103052.8769-3-lorenzo.bianconi-qxv4g6HH51o@public.gmane.org>
2017-01-22 14:35       ` Jonathan Cameron

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