* [PATCH v2 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin @ 2017-01-22 18:32 Lorenzo Bianconi 2017-01-22 18:32 ` [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi 2017-01-22 18:32 ` [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi 0 siblings, 2 replies; 6+ messages in thread From: Lorenzo Bianconi @ 2017-01-22 18:32 UTC (permalink / raw) To: jic23; +Cc: linux-iio, devicetree, lorenzo.bianconi Changes since v1: - rely on the -ENOSYS return value from of_property_read_u32 to check if OF has been enabled 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 | 59 +++++++++++++++++++--- 2 files changed, 55 insertions(+), 6 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin 2017-01-22 18:32 [PATCH v2 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin Lorenzo Bianconi @ 2017-01-22 18:32 ` Lorenzo Bianconi 2017-01-28 12:42 ` Jonathan Cameron 2017-01-22 18:32 ` [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Bianconi @ 2017-01-22 18:32 UTC (permalink / raw) To: jic23; +Cc: linux-iio, devicetree, lorenzo.bianconi Add capability to route data ready signal on pin 1 or pin 2 of the package Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 59 +++++++++++++++++++++++++--- 1 file changed, 53 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..c92ddcc 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,56 @@ static const struct iio_info st_lsm6dsx_gyro_info = { static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0}; +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; +} + +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 +612,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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin 2017-01-22 18:32 ` [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi @ 2017-01-28 12:42 ` Jonathan Cameron 0 siblings, 0 replies; 6+ messages in thread From: Jonathan Cameron @ 2017-01-28 12:42 UTC (permalink / raw) To: Lorenzo Bianconi; +Cc: linux-iio, devicetree, lorenzo.bianconi On 22/01/17 18:32, 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@st.com> Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 59 +++++++++++++++++++++++++--- > 1 file changed, 53 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..c92ddcc 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,56 @@ static const struct iio_info st_lsm6dsx_gyro_info = { > > static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0}; > > +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; > +} > + > +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 +612,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, > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property 2017-01-22 18:32 [PATCH v2 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin Lorenzo Bianconi 2017-01-22 18:32 ` [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi @ 2017-01-22 18:32 ` Lorenzo Bianconi 2017-01-23 20:45 ` Rob Herring 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Bianconi @ 2017-01-22 18:32 UTC (permalink / raw) To: jic23; +Cc: linux-iio, devicetree, lorenzo.bianconi Add st,drdy-int-pin property to select interrupt pin of the package Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> --- 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property 2017-01-22 18:32 ` [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi @ 2017-01-23 20:45 ` Rob Herring 2017-01-28 12:43 ` Jonathan Cameron 0 siblings, 1 reply; 6+ messages in thread From: Rob Herring @ 2017-01-23 20:45 UTC (permalink / raw) To: Lorenzo Bianconi; +Cc: jic23, linux-iio, devicetree, lorenzo.bianconi On Sun, Jan 22, 2017 at 07:32:25PM +0100, Lorenzo Bianconi wrote: > Add st,drdy-int-pin property to select interrupt pin of the package > > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> > --- > Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 2 ++ > 1 file changed, 2 insertions(+) Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property 2017-01-23 20:45 ` Rob Herring @ 2017-01-28 12:43 ` Jonathan Cameron 0 siblings, 0 replies; 6+ messages in thread From: Jonathan Cameron @ 2017-01-28 12:43 UTC (permalink / raw) To: Rob Herring, Lorenzo Bianconi; +Cc: linux-iio, devicetree, lorenzo.bianconi On 23/01/17 20:45, Rob Herring wrote: > On Sun, Jan 22, 2017 at 07:32:25PM +0100, Lorenzo Bianconi wrote: >> Add st,drdy-int-pin property to select interrupt pin of the package >> >> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> >> --- >> Documentation/devicetree/bindings/iio/imu/st_lsm6dsx.txt | 2 ++ >> 1 file changed, 2 insertions(+) > > Acked-by: Rob Herring <robh@kernel.org> > Applied Thanks, Jonathan ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-01-28 12:49 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-01-22 18:32 [PATCH v2 0/2] iio: imu: st_lsm6dsx: add capability to select interrupt pin Lorenzo Bianconi 2017-01-22 18:32 ` [PATCH v2 1/2] iio: imu: st_lsm6dsx: add possibility to select drdy pin Lorenzo Bianconi 2017-01-28 12:42 ` Jonathan Cameron 2017-01-22 18:32 ` [PATCH v2 2/2] Documentation: dt: iio: imu: st_lsm6dsx: add st,drdy-int-pin property Lorenzo Bianconi 2017-01-23 20:45 ` Rob Herring 2017-01-28 12:43 ` 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).