All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] iio: imu: st_lsm6dsx: add read_fifo callback to fifo_ops
@ 2018-08-30 20:52 Lorenzo Bianconi
  2018-09-02 20:28 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Lorenzo Bianconi @ 2018-08-30 20:52 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, devicetree

Remove static qualifier from st_lsm6dsx_read_fifo definition and
introduce read_fifo function pointer in fifo_ops data structure
in order to run the proper read_fifo routine since other compliant
devices will use a different FIFO queueing scheme.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h        | 5 +++++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 6 +++---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 3 +++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index edcd838037cd..a0a6c07aad62 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -41,13 +41,17 @@ struct st_lsm6dsx_reg {
 	u8 mask;
 };
 
+struct st_lsm6dsx_hw;
+
 /**
  * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
+ * @read_fifo: Read FIFO callback.
  * @fifo_th: FIFO threshold register info (addr + mask).
  * @fifo_diff: FIFO diff status register info (addr + mask).
  * @th_wl: FIFO threshold word length.
  */
 struct st_lsm6dsx_fifo_ops {
+	int (*read_fifo)(struct st_lsm6dsx_hw *hw);
 	struct {
 		u8 addr;
 		u16 mask;
@@ -175,5 +179,6 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
 int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
 int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
 			     enum st_lsm6dsx_fifo_mode fifo_mode);
+int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
 
 #endif /* ST_LSM6DSX_H */
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index 2b49d928f4c0..7e02935a4250 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -284,7 +284,7 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data,
  *
  * Return: Number of bytes read from the FIFO
  */
-static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
+int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
 {
 	u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
 	u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
@@ -408,7 +408,7 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
 
 	mutex_lock(&hw->fifo_lock);
 
-	st_lsm6dsx_read_fifo(hw);
+	hw->settings->fifo_ops.read_fifo(hw);
 	err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS);
 
 	mutex_unlock(&hw->fifo_lock);
@@ -480,7 +480,7 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
 	int count;
 
 	mutex_lock(&hw->fifo_lock);
-	count = st_lsm6dsx_read_fifo(hw);
+	count = hw->settings->fifo_ops.read_fifo(hw);
 	mutex_unlock(&hw->fifo_lock);
 
 	return !count ? IRQ_NONE : IRQ_HANDLED;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index aebbe0ddd8d8..394bcd3719e0 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -171,6 +171,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 			},
 		},
 		.fifo_ops = {
+			.read_fifo = st_lsm6dsx_read_fifo,
 			.fifo_th = {
 				.addr = 0x06,
 				.mask = GENMASK(11, 0),
@@ -217,6 +218,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 			},
 		},
 		.fifo_ops = {
+			.read_fifo = st_lsm6dsx_read_fifo,
 			.fifo_th = {
 				.addr = 0x06,
 				.mask = GENMASK(11, 0),
@@ -265,6 +267,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
 			},
 		},
 		.fifo_ops = {
+			.read_fifo = st_lsm6dsx_read_fifo,
 			.fifo_th = {
 				.addr = 0x06,
 				.mask = GENMASK(10, 0),
-- 
2.18.0

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

* Re: [PATCH 1/5] iio: imu: st_lsm6dsx: add read_fifo callback to fifo_ops
  2018-08-30 20:52 [PATCH 1/5] iio: imu: st_lsm6dsx: add read_fifo callback to fifo_ops Lorenzo Bianconi
@ 2018-09-02 20:28 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-09-02 20:28 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-iio, devicetree

On Thu, 30 Aug 2018 22:52:55 +0200
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> Remove static qualifier from st_lsm6dsx_read_fifo definition and
> introduce read_fifo function pointer in fifo_ops data structure
> in order to run the proper read_fifo routine since other compliant
> devices will use a different FIFO queueing scheme.
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.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.h        | 5 +++++
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 6 +++---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 3 +++
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index edcd838037cd..a0a6c07aad62 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -41,13 +41,17 @@ struct st_lsm6dsx_reg {
>  	u8 mask;
>  };
>  
> +struct st_lsm6dsx_hw;
> +
>  /**
>   * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings
> + * @read_fifo: Read FIFO callback.
>   * @fifo_th: FIFO threshold register info (addr + mask).
>   * @fifo_diff: FIFO diff status register info (addr + mask).
>   * @th_wl: FIFO threshold word length.
>   */
>  struct st_lsm6dsx_fifo_ops {
> +	int (*read_fifo)(struct st_lsm6dsx_hw *hw);
>  	struct {
>  		u8 addr;
>  		u16 mask;
> @@ -175,5 +179,6 @@ int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
>  int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw);
>  int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
>  			     enum st_lsm6dsx_fifo_mode fifo_mode);
> +int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
>  
>  #endif /* ST_LSM6DSX_H */
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> index 2b49d928f4c0..7e02935a4250 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
> @@ -284,7 +284,7 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 *data,
>   *
>   * Return: Number of bytes read from the FIFO
>   */
> -static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
> +int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
>  {
>  	u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
>  	u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask;
> @@ -408,7 +408,7 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
>  
>  	mutex_lock(&hw->fifo_lock);
>  
> -	st_lsm6dsx_read_fifo(hw);
> +	hw->settings->fifo_ops.read_fifo(hw);
>  	err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS);
>  
>  	mutex_unlock(&hw->fifo_lock);
> @@ -480,7 +480,7 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
>  	int count;
>  
>  	mutex_lock(&hw->fifo_lock);
> -	count = st_lsm6dsx_read_fifo(hw);
> +	count = hw->settings->fifo_ops.read_fifo(hw);
>  	mutex_unlock(&hw->fifo_lock);
>  
>  	return !count ? IRQ_NONE : IRQ_HANDLED;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index aebbe0ddd8d8..394bcd3719e0 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -171,6 +171,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  			},
>  		},
>  		.fifo_ops = {
> +			.read_fifo = st_lsm6dsx_read_fifo,
>  			.fifo_th = {
>  				.addr = 0x06,
>  				.mask = GENMASK(11, 0),
> @@ -217,6 +218,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  			},
>  		},
>  		.fifo_ops = {
> +			.read_fifo = st_lsm6dsx_read_fifo,
>  			.fifo_th = {
>  				.addr = 0x06,
>  				.mask = GENMASK(11, 0),
> @@ -265,6 +267,7 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
>  			},
>  		},
>  		.fifo_ops = {
> +			.read_fifo = st_lsm6dsx_read_fifo,
>  			.fifo_th = {
>  				.addr = 0x06,
>  				.mask = GENMASK(10, 0),

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

end of thread, other threads:[~2018-09-03  0:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-30 20:52 [PATCH 1/5] iio: imu: st_lsm6dsx: add read_fifo callback to fifo_ops Lorenzo Bianconi
2018-09-02 20:28 ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.