diff mbox series

[2/6] iio: imu: st_lsm6dsx: check if master_enable is located in primary page

Message ID 9301949c51a78df2c818619c3be634274f13a790.1576341963.git.lorenzo@kernel.org (mailing list archive)
State New, archived
Headers show
Series introduce i2c master controller support for LSM6DSM | expand

Commit Message

Lorenzo Bianconi Dec. 14, 2019, 4:52 p.m. UTC
Check if the master enable register is located in the primary or in the
secondary memory page. This is a preliminary patch to support i2c master
controller on lsm6dsm devices

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  6 +++++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c |  2 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 11 +++++++----
 3 files changed, 14 insertions(+), 5 deletions(-)

Comments

Jonathan Cameron Dec. 23, 2019, 4:51 p.m. UTC | #1
On Sat, 14 Dec 2019 17:52:55 +0100
Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Check if the master enable register is located in the primary or in the
> secondary memory page. This is a preliminary patch to support i2c master
> controller on lsm6dsm devices
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied.

Thanks,

Jonathan

> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  6 +++++-
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c |  2 ++
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c | 11 +++++++----
>  3 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index fb76e0d6770d..0f8f3fbde67a 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -184,7 +184,11 @@ struct st_lsm6dsx_hw_ts_settings {
>   */
>  struct st_lsm6dsx_shub_settings {
>  	struct st_lsm6dsx_reg page_mux;
> -	struct st_lsm6dsx_reg master_en;
> +	struct {
> +		bool sec_page;
> +		u8 addr;
> +		u8 mask;
> +	} master_en;
>  	struct st_lsm6dsx_reg pullup_en;
>  	struct st_lsm6dsx_reg aux_sens;
>  	struct st_lsm6dsx_reg wr_once;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index bf995b58c333..fe1aaaf68a9b 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -867,6 +867,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.mask = BIT(6),
>  			},
>  			.master_en = {
> +				.sec_page = true,
>  				.addr = 0x14,
>  				.mask = BIT(2),
>  			},
> @@ -1242,6 +1243,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  				.mask = BIT(6),
>  			},
>  			.master_en = {
> +				.sec_page = true,
>  				.addr = 0x14,
>  				.mask = BIT(2),
>  			},
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> index 5684e663d0aa..767482e61a1e 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
> @@ -185,15 +185,18 @@ static int st_lsm6dsx_shub_master_enable(struct st_lsm6dsx_sensor *sensor,
>  	mutex_lock(&hw->page_lock);
>  
>  	hub_settings = &hw->settings->shub_settings;
> -	err = st_lsm6dsx_set_page(hw, true);
> -	if (err < 0)
> -		goto out;
> +	if (hub_settings->master_en.sec_page) {
> +		err = st_lsm6dsx_set_page(hw, true);
> +		if (err < 0)
> +			goto out;
> +	}
>  
>  	data = ST_LSM6DSX_SHIFT_VAL(enable, hub_settings->master_en.mask);
>  	err = regmap_update_bits(hw->regmap, hub_settings->master_en.addr,
>  				 hub_settings->master_en.mask, data);
>  
> -	st_lsm6dsx_set_page(hw, false);
> +	if (hub_settings->master_en.sec_page)
> +		st_lsm6dsx_set_page(hw, false);
>  out:
>  	mutex_unlock(&hw->page_lock);
>
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index fb76e0d6770d..0f8f3fbde67a 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -184,7 +184,11 @@  struct st_lsm6dsx_hw_ts_settings {
  */
 struct st_lsm6dsx_shub_settings {
 	struct st_lsm6dsx_reg page_mux;
-	struct st_lsm6dsx_reg master_en;
+	struct {
+		bool sec_page;
+		u8 addr;
+		u8 mask;
+	} master_en;
 	struct st_lsm6dsx_reg pullup_en;
 	struct st_lsm6dsx_reg aux_sens;
 	struct st_lsm6dsx_reg wr_once;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index bf995b58c333..fe1aaaf68a9b 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -867,6 +867,7 @@  static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = BIT(6),
 			},
 			.master_en = {
+				.sec_page = true,
 				.addr = 0x14,
 				.mask = BIT(2),
 			},
@@ -1242,6 +1243,7 @@  static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 				.mask = BIT(6),
 			},
 			.master_en = {
+				.sec_page = true,
 				.addr = 0x14,
 				.mask = BIT(2),
 			},
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
index 5684e663d0aa..767482e61a1e 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_shub.c
@@ -185,15 +185,18 @@  static int st_lsm6dsx_shub_master_enable(struct st_lsm6dsx_sensor *sensor,
 	mutex_lock(&hw->page_lock);
 
 	hub_settings = &hw->settings->shub_settings;
-	err = st_lsm6dsx_set_page(hw, true);
-	if (err < 0)
-		goto out;
+	if (hub_settings->master_en.sec_page) {
+		err = st_lsm6dsx_set_page(hw, true);
+		if (err < 0)
+			goto out;
+	}
 
 	data = ST_LSM6DSX_SHIFT_VAL(enable, hub_settings->master_en.mask);
 	err = regmap_update_bits(hw->regmap, hub_settings->master_en.addr,
 				 hub_settings->master_en.mask, data);
 
-	st_lsm6dsx_set_page(hw, false);
+	if (hub_settings->master_en.sec_page)
+		st_lsm6dsx_set_page(hw, false);
 out:
 	mutex_unlock(&hw->page_lock);