mbox series

[v9,0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer

Message ID cover.1694867379.git.mehdi.djait.k@gmail.com
Headers show
Series iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer | expand

Message

Mehdi Djait Sept. 16, 2023, 12:38 p.m. UTC
Hello everyone,

Version 9 for adding support for the kx132-1211 accelerometer

KX132-1211 accelerometer is a sensor which:
	- supports G-ranges of (+/-) 2, 4, 8, and 16G
	- can be connected to I2C or SPI
	- has internal HW FIFO buffer
	- supports various ODRs (output data rates)

The KX132-1211 accelerometer is very similar to the KX022A. 
One key difference is number of bits to report the number of data bytes that 
have been stored in the buffer: 8 bits for KX022A vs 10 bits for
KX132-1211.

Changes in v9:
- used i2c_get_match_data
- changed the name and description of the function to get available data
  in HW fifo buffer
- changed the description in the Kconfig file

Changes in v8:
- replaced min_t by min and kmalloc by kmalloc_array as suggested by Andy

Changes in v7:
- added a min_t in kx132_get_fifo_bytes to ensure that we don't that the
  fifo_bytes is never bigger than the 
  fifo_length * KX022A_FIFO_SAMPLES_SIZE_BYTES - no matter what we read from I2C
  as suggested by Matti

Changes in v6:
- check for availability of chip_info for the SPI case
- changed the order of elements in the kx022a_data struct to save memory

Changes in v5:
- moved the "kfree" call to match the reverse of what happens in 
  kx022a_fifo_enable() as suggested by Matti and Jonathan
- used min_t, checked for availability of chip_info and moved the
  position of u16 buf_smp_lvl_mask as suggested by Andy
- introduced buf_smp_lvl_mask in Patch 7 as suggested by Jonathan

Changes in v4:
- moved the allocation of the fifo_buffer to kx022a_fifo_enable and
  kx022a_fifo_disable
- some fixes to the regmap ranges of kx132-1211 

Changes in v3:
- added two new patches by separating the addition of the 
  i2c_device_id table and the removal of blank lines from other
  unrelated changes
- fixes a warning detected by the kernel test robot
- made all the changes related the chip_info in one patch

Changes in v2:
- added a new patch for warning when the device_id match fails in the
  probe function
- added a new patch for the function that retrieves the number of bytes
  in the buffer
- added a change to the Kconfig file in the patch adding the support
  for the kx132-1211
- various fixes and modifications listed under each patch

Mehdi Djait (7):
  dt-bindings: iio: Add KX132-1211 accelerometer
  iio: accel: kionix-kx022a: Remove blank lines
  iio: accel: kionix-kx022a: Warn on failed matches and assume
    compatibility
  iio: accel: kionix-kx022a: Add an i2c_device_id table
  iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
  iio: accel: kionix-kx022a: Add a function to retrieve number of bytes
    in buffer
  iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer

 .../bindings/iio/accel/kionix,kx022a.yaml     |  12 +-
 drivers/iio/accel/Kconfig                     |  10 +-
 drivers/iio/accel/kionix-kx022a-i2c.c         |  20 +-
 drivers/iio/accel/kionix-kx022a-spi.c         |  15 +-
 drivers/iio/accel/kionix-kx022a.c             | 315 ++++++++++++++----
 drivers/iio/accel/kionix-kx022a.h             | 112 ++++++-
 6 files changed, 409 insertions(+), 75 deletions(-)

Comments

Jonathan Cameron Sept. 17, 2023, 9:45 a.m. UTC | #1
On Sat, 16 Sep 2023 14:38:52 +0200
Mehdi Djait <mehdi.djait.k@gmail.com> wrote:

> Since Kionix accelerometers use various numbers of bits to report data, a
> device-specific function is required.
> Implement the function as a callback in the device-specific chip_info structure
> 
> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
> Signed-off-by: Mehdi Djait <mehdi.djait.k@gmail.com>


>  const struct kx022a_chip_info kx022a_chip_info = {
> -	.name		  = "kx022-accel",
> -	.regmap_config	  = &kx022a_regmap_config,
> -	.channels	  = kx022a_channels,
> -	.num_channels	  = ARRAY_SIZE(kx022a_channels),
> -	.fifo_length	  = KX022A_FIFO_LENGTH,
> -	.who		  = KX022A_REG_WHO,
> -	.id		  = KX022A_ID,
> -	.cntl		  = KX022A_REG_CNTL,
> -	.cntl2		  = KX022A_REG_CNTL2,
> -	.odcntl		  = KX022A_REG_ODCNTL,
> -	.buf_cntl1	  = KX022A_REG_BUF_CNTL1,
> -	.buf_cntl2	  = KX022A_REG_BUF_CNTL2,
> -	.buf_clear	  = KX022A_REG_BUF_CLEAR,
> -	.buf_status1	  = KX022A_REG_BUF_STATUS_1,
> -	.buf_read	  = KX022A_REG_BUF_READ,
> -	.inc1		  = KX022A_REG_INC1,
> -	.inc4		  = KX022A_REG_INC4,
> -	.inc5		  = KX022A_REG_INC5,
> -	.inc6		  = KX022A_REG_INC6,
> -	.xout_l		  = KX022A_REG_XOUT_L,
This is a very good illustration of why aligning value assignments is not
(in my opinion) a good idea. I'll tweak the earlier patch whilst
applying to add the extra indent.

However, in future look through your complete series for cases where
code added in an earlier patch is simply reformatted in a later one.

Same applies to the structure kdoc below.


> +	.name				= "kx022-accel",
> +	.regmap_config			= &kx022a_regmap_config,
> +	.channels			= kx022a_channels,
> +	.num_channels			= ARRAY_SIZE(kx022a_channels),
> +	.fifo_length			= KX022A_FIFO_LENGTH,
> +	.who				= KX022A_REG_WHO,
> +	.id				= KX022A_ID,
> +	.cntl				= KX022A_REG_CNTL,
> +	.cntl2				= KX022A_REG_CNTL2,
> +	.odcntl				= KX022A_REG_ODCNTL,
> +	.buf_cntl1			= KX022A_REG_BUF_CNTL1,
> +	.buf_cntl2			= KX022A_REG_BUF_CNTL2,
> +	.buf_clear			= KX022A_REG_BUF_CLEAR,
> +	.buf_status1			= KX022A_REG_BUF_STATUS_1,
> +	.buf_read			= KX022A_REG_BUF_READ,
> +	.inc1				= KX022A_REG_INC1,
> +	.inc4				= KX022A_REG_INC4,
> +	.inc5				= KX022A_REG_INC5,
> +	.inc6				= KX022A_REG_INC6,
> +	.xout_l				= KX022A_REG_XOUT_L,
> +	.get_fifo_bytes_available	= kx022a_get_fifo_bytes_available,
>  };
>  EXPORT_SYMBOL_NS_GPL(kx022a_chip_info, IIO_KX022A);
>  
> diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
> index 0e5026019213..7ca48e6f2c49 100644
> --- a/drivers/iio/accel/kionix-kx022a.h
> +++ b/drivers/iio/accel/kionix-kx022a.h
> @@ -76,29 +76,34 @@
>  
>  struct device;
>  
> +struct kx022a_data;
> +
>  /**
>   * struct kx022a_chip_info - Kionix accelerometer chip specific information
>   *
> - * @name:		name of the device
> - * @regmap_config:	pointer to register map configuration
> - * @channels:		pointer to iio_chan_spec array
> - * @num_channels:	number of iio_chan_spec channels
> - * @fifo_length:	number of 16-bit samples in a full buffer
> - * @who:		WHO_AM_I register
> - * @id:			WHO_AM_I register value
> - * @cntl:		control register 1
> - * @cntl2:		control register 2
> - * @odcntl:		output data control register
> - * @buf_cntl1:		buffer control register 1
> - * @buf_cntl2:		buffer control register 2
> - * @buf_clear:		buffer clear register
> - * @buf_status1:	buffer status register 1
> - * @buf_read:		buffer read register
> - * @inc1:		interrupt control register 1
> - * @inc4:		interrupt control register 4
> - * @inc5:		interrupt control register 5
> - * @inc6:		interrupt control register 6
> - * @xout_l:		x-axis output least significant byte
> + * @name:			name of the device
> + * @regmap_config:		pointer to register map configuration
> + * @channels:			pointer to iio_chan_spec array
> + * @num_channels:		number of iio_chan_spec channels
> + * @fifo_length:		number of 16-bit samples in a full buffer
> + * @who:			WHO_AM_I register
> + * @id:				WHO_AM_I register value
> + * @cntl:			control register 1
> + * @cntl2:			control register 2
> + * @odcntl:			output data control register
> + * @buf_cntl1:			buffer control register 1
> + * @buf_cntl2:			buffer control register 2
> + * @buf_clear:			buffer clear register
> + * @buf_status1:		buffer status register 1
> + * @buf_read:			buffer read register
> + * @inc1:			interrupt control register 1
> + * @inc4:			interrupt control register 4
> + * @inc5:			interrupt control register 5
> + * @inc6:			interrupt control register 6
> + * @xout_l:			x-axis output least significant byte
> + * @get_fifo_bytes_available:	function pointer to get amount of acceleration
> + *				data bytes currently stored in the sensor's FIFO
> + *				buffer
>   */
>  struct kx022a_chip_info {
>  	const char *name;
> @@ -121,6 +126,7 @@ struct kx022a_chip_info {
>  	u8 inc5;
>  	u8 inc6;
>  	u8 xout_l;
> +	int (*get_fifo_bytes_available)(struct kx022a_data *);
>  };
>  
>  int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info);
Jonathan Cameron Sept. 17, 2023, 9:47 a.m. UTC | #2
On Sat, 16 Sep 2023 14:38:46 +0200
Mehdi Djait <mehdi.djait.k@gmail.com> wrote:

> Hello everyone,
> 
> Version 9 for adding support for the kx132-1211 accelerometer
> 
> KX132-1211 accelerometer is a sensor which:
> 	- supports G-ranges of (+/-) 2, 4, 8, and 16G
> 	- can be connected to I2C or SPI
> 	- has internal HW FIFO buffer
> 	- supports various ODRs (output data rates)
> 
> The KX132-1211 accelerometer is very similar to the KX022A. 
> One key difference is number of bits to report the number of data bytes that 
> have been stored in the buffer: 8 bits for KX022A vs 10 bits for
> KX132-1211.

Series applied with some minor white space tweaks as called out for individual
patches.

Applied to the togreg branch of iio.git and initially pushed out as testing for
the autobuilders to poke at it and see what we've missed.

Thanks,

Jonathan

> 
> Changes in v9:
> - used i2c_get_match_data
> - changed the name and description of the function to get available data
>   in HW fifo buffer
> - changed the description in the Kconfig file
> 
> Changes in v8:
> - replaced min_t by min and kmalloc by kmalloc_array as suggested by Andy
> 
> Changes in v7:
> - added a min_t in kx132_get_fifo_bytes to ensure that we don't that the
>   fifo_bytes is never bigger than the 
>   fifo_length * KX022A_FIFO_SAMPLES_SIZE_BYTES - no matter what we read from I2C
>   as suggested by Matti
> 
> Changes in v6:
> - check for availability of chip_info for the SPI case
> - changed the order of elements in the kx022a_data struct to save memory
> 
> Changes in v5:
> - moved the "kfree" call to match the reverse of what happens in 
>   kx022a_fifo_enable() as suggested by Matti and Jonathan
> - used min_t, checked for availability of chip_info and moved the
>   position of u16 buf_smp_lvl_mask as suggested by Andy
> - introduced buf_smp_lvl_mask in Patch 7 as suggested by Jonathan
> 
> Changes in v4:
> - moved the allocation of the fifo_buffer to kx022a_fifo_enable and
>   kx022a_fifo_disable
> - some fixes to the regmap ranges of kx132-1211 
> 
> Changes in v3:
> - added two new patches by separating the addition of the 
>   i2c_device_id table and the removal of blank lines from other
>   unrelated changes
> - fixes a warning detected by the kernel test robot
> - made all the changes related the chip_info in one patch
> 
> Changes in v2:
> - added a new patch for warning when the device_id match fails in the
>   probe function
> - added a new patch for the function that retrieves the number of bytes
>   in the buffer
> - added a change to the Kconfig file in the patch adding the support
>   for the kx132-1211
> - various fixes and modifications listed under each patch
> 
> Mehdi Djait (7):
>   dt-bindings: iio: Add KX132-1211 accelerometer
>   iio: accel: kionix-kx022a: Remove blank lines
>   iio: accel: kionix-kx022a: Warn on failed matches and assume
>     compatibility
>   iio: accel: kionix-kx022a: Add an i2c_device_id table
>   iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
>   iio: accel: kionix-kx022a: Add a function to retrieve number of bytes
>     in buffer
>   iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer
> 
>  .../bindings/iio/accel/kionix,kx022a.yaml     |  12 +-
>  drivers/iio/accel/Kconfig                     |  10 +-
>  drivers/iio/accel/kionix-kx022a-i2c.c         |  20 +-
>  drivers/iio/accel/kionix-kx022a-spi.c         |  15 +-
>  drivers/iio/accel/kionix-kx022a.c             | 315 ++++++++++++++----
>  drivers/iio/accel/kionix-kx022a.h             | 112 ++++++-
>  6 files changed, 409 insertions(+), 75 deletions(-)
>