iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer
Subsystems (3)
v7 cover iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer
Hello everyone,
Version 7 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 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 | 8 +- drivers/iio/accel/kionix-kx022a-i2c.c | 24 +- drivers/iio/accel/kionix-kx022a-spi.c | 15 +- drivers/iio/accel/kionix-kx022a.c | 314 ++++++++++++++---- drivers/iio/accel/kionix-kx022a.h | 110 +++++- 6 files changed, 408 insertions(+), 75 deletions(-)
Signature · 1 line
2.30.2
PATCH v7 1/7 dt-bindings: iio: Add KX132-1211 accelerometer
Extend the kionix,kx022a.yaml file to support the kx132-1211 device
---
v7:
v6:
v5:
v4:
v3:
- no changes
v2:
- made the device name more specific from "kx132" to "kx132-1211"
- removed the output data-rates mentioned and replaced them with "variable output data-rates"
.../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml +7 -5
@@ -4,19 +4,21 @@ $id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM/Kionix KX022A Accelerometer +title: ROHM/Kionix KX022A and KX132-1211 Accelerometers maintainers: - Matti Vaittinen <[email protected]> description: | - KX022A is a 3-axis accelerometer supporting +/- 2G, 4G, 8G and 16G ranges, - output data-rates from 0.78Hz to 1600Hz and a hardware-fifo buffering. - KX022A can be accessed either via I2C or SPI. + KX022A and KX132-1211 are 3-axis accelerometers supporting +/- 2G, 4G, 8G and + 16G ranges, variable output data-rates and a hardware-fifo buffering. + KX022A and KX132-1211 can be accessed either via I2C or SPI. properties: compatible: - const: kionix,kx022a + enum: + - kionix,kx022a + - kionix,kx132-1211 reg: maxItems: 1
Signature · 1 line
2.30.2
PATCH v7 2/7 iio: accel: kionix-kx022a: Remove blank lines
In reply to Mehdi DjaitRemove blank lines pointed out by the checkpatch script
---
v7:
v6:
v5:
v4:
- no changes
v3:
- no changes, this patch is introduced in the v2
drivers/iio/accel/kionix-kx022a.c | 2 -- 1 file changed, 2 deletions(-)
drivers/iio/accel/kionix-kx022a.c +0 -2
@@ -341,7 +341,6 @@ static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on)dev_err (data->dev,"Turn %s fail %d\n" ,str_on_off (on), ret);return ret; - }static int kx022a_turn_off_lock (struct kx022a_data *data)
@@ -1121,7 +1120,6 @@ int kx022a_probe_internal(struct device *dev)if (ret)return dev_err_probe (data->dev, ret,"Could not request IRQ\n" ); - ret =devm_iio_trigger_register (dev, indio_trig);if (ret) return dev_err_probe(data->dev, ret,
Signature · 1 line
2.30.2
PATCH v7 3/7 iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility
In reply to Mehdi DjaitAvoid error returns on a failure to match and instead just warn with assumption that we have a correct dt-binding telling us that some new device with a different ID is backwards compatible.
---
v7:
v6:
v5:
v4:
- no changes
v3:
- changed from 'unsupported' to 'unknown'
- removed the opening bracket
v2:
- no changes, this patch is introduced in the v2
drivers/iio/accel/kionix-kx022a.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/accel/kionix-kx022a.c +2 -4
@@ -1036,10 +1036,8 @@ int kx022a_probe_internal(struct device *dev)if (ret)return dev_err_probe (dev, ret,"Failed to access sensor\n" ); -if (chip_id !=KX022A_ID ) { -dev_err (dev,"unsupported device 0x%x\n" , chip_id); -return -EINVAL ; - } +if (chip_id !=KX022A_ID ) +dev_warn (dev,"unknown device 0x%x\n" , chip_id); irq =fwnode_irq_get_byname (fwnode,"INT1" );if (irq >0 ) {
Signature · 1 line
2.30.2
PATCH v7 4/7 iio: accel: kionix-kx022a: Add an i2c_device_id table
In reply to Mehdi DjaitAdd the missing i2c device id.
---
v7:
v6:
v5:
v4:
- no changes
v3:
- no changes, this patch is introduced in the v2
drivers/iio/accel/kionix-kx022a-i2c.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/iio/accel/kionix-kx022a-i2c.c +7 -0
@@ -30,6 +30,12 @@ static int kx022a_i2c_probe(struct i2c_client *i2c)return kx022a_probe_internal (dev); } +static const struct i2c_device_id kx022a_i2c_id[] = { + { .name ="kx022a" }, + { } +}; +MODULE_DEVICE_TABLE (i2c, kx022a_i2c_id); +static const struct of_device_id kx022a_of_match[] = { { .compatible ="kionix,kx022a" , }, { }
@@ -42,6 +48,7 @@ static struct i2c_driver kx022a_i2c_driver = { .of_match_table = kx022a_of_match, }, .probe_new = kx022a_i2c_probe, + .id_table = kx022a_i2c_id, };module_i2c_driver (kx022a_i2c_driver);
Signature · 1 line
2.30.2
PATCH v7 5/7 iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
In reply to Mehdi DjaitAdd the chip_info structure to the driver's private data to hold all the device specific infos.
Refactor the kx022a driver implementation to make it more generic and extensible.
---
v7:
- no changes
v6:
- placed chip_info after the regmap elemnt in kx022a_data struct to save memory as suggested by Andy
- added a check for the availability of chip_info for the SPI case as suggested by Andy
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 as suggested by Andy
v4:
- allocating and freeing the buffer moved to the kx022a_fifo{enable, disable} functions
- used the spi_get_device_match_data helper function
v3:
- added the change of the buffer's allocation in the __kx022a_fifo_flush to this patch
- added the chip_info to the struct kx022a_data
drivers/iio/accel/kionix-kx022a-i2c.c | 17 +++- drivers/iio/accel/kionix-kx022a-spi.c | 13 ++- drivers/iio/accel/kionix-kx022a.c | 116 ++++++++++++++++---------- drivers/iio/accel/kionix-kx022a.h | 52 +++++++++++- 4 files changed, 146 insertions(+), 52 deletions(-)
drivers/iio/accel/kionix-kx022a-i2c.c +13 -4
@@ -15,6 +15,7 @@static int kx022a_i2c_probe (struct i2c_client *i2c) {struct device *dev = &i2c->dev; +const struct kx022a_chip_info *chip_info;struct regmap *regmap;if (!i2c->irq) {
@@ -22,22 +23,30 @@ static int kx022a_i2c_probe(struct i2c_client *i2c)return -EINVAL ; } - regmap =devm_regmap_init_i2c (i2c, &kx022a_regmap); + chip_info =device_get_match_data (&i2c->dev); +if (!chip_info) { +const struct i2c_device_id *id =i2c_client_get_device_id (i2c); + chip_info = (const struct kx022a_chip_info *)id->driver_data; +if (!chip_info) +return -EINVAL ; + } + + regmap =devm_regmap_init_i2c (i2c, chip_info->regmap_config);if (IS_ERR (regmap))return dev_err_probe (dev,PTR_ERR (regmap),"Failed to initialize Regmap\n" ); -return kx022a_probe_internal (dev); +return kx022a_probe_internal (dev, chip_info); }static const struct i2c_device_id kx022a_i2c_id[] = { - { .name ="kx022a" }, + { .name ="kx022a" , .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { } };MODULE_DEVICE_TABLE (i2c, kx022a_i2c_id);static const struct of_device_id kx022a_of_match[] = { - { .compatible ="kionix,kx022a" , }, + { .compatible ="kionix,kx022a" , .data = &kx022a_chip_info }, { } };MODULE_DEVICE_TABLE (of, kx022a_of_match);
drivers/iio/accel/kionix-kx022a-spi.c +9 -4
@@ -15,6 +15,7 @@static int kx022a_spi_probe (struct spi_device *spi) {struct device *dev = &spi->dev; +const struct kx022a_chip_info *chip_info;struct regmap *regmap;if (!spi->irq) {
@@ -22,22 +23,26 @@ static int kx022a_spi_probe(struct spi_device *spi)return -EINVAL ; } - regmap =devm_regmap_init_spi (spi, &kx022a_regmap); + chip_info =spi_get_device_match_data (spi); +if (!chip_info) +return -EINVAL ; + + regmap =devm_regmap_init_spi (spi, chip_info->regmap_config);if (IS_ERR (regmap))return dev_err_probe (dev,PTR_ERR (regmap),"Failed to initialize Regmap\n" ); -return kx022a_probe_internal (dev); +return kx022a_probe_internal (dev, chip_info); }static const struct spi_device_id kx022a_id[] = { - {"kx022a" }, + { .name ="kx022a" , .driver_data = (kernel_ulong_t)&kx022a_chip_info }, { } };MODULE_DEVICE_TABLE (spi, kx022a_id);static const struct of_device_id kx022a_of_match[] = { - { .compatible ="kionix,kx022a" , }, + { .compatible ="kionix,kx022a" , .data = &kx022a_chip_info }, { } };MODULE_DEVICE_TABLE (of, kx022a_of_match);
drivers/iio/accel/kionix-kx022a.c +74 -42
331 lines not on this page · raw message
drivers/iio/accel/kionix-kx022a.h +50 -2
57 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v7 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Quoted 4 lines · Mehdi Djait
Add the
chip_infostructure to the driver's private data to hold all the device specific infos.
Refactor the kx022a driver implementation to make it more generic and extensible.
...
drivers/iio/accel/kionix-kx022a-i2c.c static int kx022a_i2c_probe(struct i2c_client *i2c) · line 28
Quoted 3 lines
drivers/iio/accel/kionix-kx022a-i2c.c +3
-0+ chip_info =device_get_match_data (&i2c->dev); +if (!chip_info) { +const struct i2c_device_id *id =i2c_client_get_device_id (i2c);
Missing blank line.
Quoted 4 lines
drivers/iio/accel/kionix-kx022a-i2c.c +4
-0+ chip_info = (const struct kx022a_chip_info *)id->driver_data; +if (!chip_info) +return -EINVAL ; + }
...
drivers/iio/accel/kionix-kx022a.c static int kx022a_set_watermark(struct iio_dev *idev, unsigned int val) · line 535
Quoted 3 lines
drivers/iio/accel/kionix-kx022a.c +1
-2-if (val >KX022A_FIFO_LENGTH ) - val =KX022A_FIFO_LENGTH ; + val = min_t(unsigned int, data->chip_info->fifo_length, val);
min_t() is a beast. Please, use min() if no special requirement for min_t() here, otherwise explain why.
...
drivers/iio/accel/kionix-kx022a.c static int kx022a_fifo_enable(struct kx022a_data *data) · line 807
Quoted 2 lines
drivers/iio/accel/kionix-kx022a.c +2
-0+ data->fifo_buffer =kmalloc (data->chip_info->fifo_length * +KX022A_FIFO_SAMPLES_SIZE_BYTES ,GFP_KERNEL );
kmalloc_array()
Quoted 2 lines
drivers/iio/accel/kionix-kx022a.c +2
-0+if (!data->fifo_buffer) +return -ENOMEM ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Hello Andy,
Thank you for the review.
Quoted 20 lines · Andy Shevchenko
Quoted 4 lines · Mehdi Djait
Add the
chip_infostructure to the driver's private data to hold all the device specific infos.
Refactor the kx022a driver implementation to make it more generic and extensible....
drivers/iio/accel/kionix-kx022a-i2c.c static int kx022a_i2c_probe(struct i2c_client *i2c) · line 28
Quoted 3 lines
drivers/iio/accel/kionix-kx022a-i2c.c +3
-0+ chip_info =device_get_match_data (&i2c->dev); +if (!chip_info) { +const struct i2c_device_id *id =i2c_client_get_device_id (i2c);Missing blank line.
drivers/iio/accel/kionix-kx022a-i2c.c static int kx022a_i2c_probe(struct i2c_client *i2c) · line 32
Quoted 4 lines
drivers/iio/accel/kionix-kx022a-i2c.c +4
-0+ chip_info = (const struct kx022a_chip_info *)id->driver_data; +if (!chip_info) +return -EINVAL ; + }
Quoted 8 lines
...
drivers/iio/accel/kionix-kx022a.c static int kx022a_set_watermark(struct iio_dev *idev, unsigned int val) · line 535
Quoted 3 lines
drivers/iio/accel/kionix-kx022a.c +1
-2-if (val >KX022A_FIFO_LENGTH ) - val =KX022A_FIFO_LENGTH ; + val = min_t(unsigned int, data->chip_info->fifo_length, val);
min_t()is a beast. Please, usemin()if no special requirement formin_t()here, otherwise explain why.
No actual reason, you suggested min_t or min for a previous version
Quoted 7 lines
...
drivers/iio/accel/kionix-kx022a.c static int kx022a_fifo_enable(struct kx022a_data *data) · line 807
Quoted 2 lines
drivers/iio/accel/kionix-kx022a.c +2
-0+ data->fifo_buffer =kmalloc (data->chip_info->fifo_length * +KX022A_FIFO_SAMPLES_SIZE_BYTES ,GFP_KERNEL );
kmalloc_array()
Should I send another version for this ?
The usage of kmalloc is quite straightforward and easy to understand here.
--
Kind Regard
Mehdi Djait
Re: [PATCH v7 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Quoted 3 lines · Mehdi Djait
Quoted 1 line · Andy Shevchenko
On Wed, Aug 09, 2023 at 09:11:36PM +0200, Mehdi Djait wrote:
...
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ val =
min_t(unsigned int, data->chip_info->fifo_length, val);
min_t()is a beast. Please, usemin()if no special requirement formin_t()here, otherwise explain why.No actual reason, you suggested
min_tor min for a previous version
After the minmax series (see discussion in LKML) I am pretty sure min_t() shouldn't be used at all or with very minimum cases where people know what they are doing.
...
Quoted 6 lines
Quoted 4 lines
drivers/iio/accel/kionix-kx022a.c static int kx022a_fifo_enable(struct kx022a_data *data) · line 807
Quoted 2 lines
drivers/iio/accel/kionix-kx022a.c +2
-0+ data->fifo_buffer =kmalloc (data->chip_info->fifo_length * +KX022A_FIFO_SAMPLES_SIZE_BYTES ,GFP_KERNEL );
kmalloc_array()Should I send another version for this ?
Sure.
Quoted 1 line
The usage of kmalloc is quite straightforward and easy to understand here.
Yes, and prone to errors. Multiplication theoretically may overflow and your code doesn't aware of that, kmalloc_array() does it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v7 6/7 iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer
In reply to Mehdi DjaitSince 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
---
v7:
- no changes
v6:
- directly return KX022A_FIFO_MAX_BYTES as suggested by Andy
v5:
- no changes
v4:
- removed the comment about "bogus value from i2c"
- removed regmap_get_device(data->regmap); dev is present in the driver's private data
v3:
- no changes
v2:
- separated this change from the chip_info introduction and made it a patch in v2
- changed the function from generic implementation for to device-specific one
- removed blank lines pointed out by checkpatch
- changed the allocation of the "buffer" array in __kx022a_fifo_flush
drivers/iio/accel/kionix-kx022a.c | 28 ++++++++++++++++++---------- drivers/iio/accel/kionix-kx022a.h | 4 ++++ 2 files changed, 22 insertions(+), 10 deletions(-)
drivers/iio/accel/kionix-kx022a.c +18 -10
@@ -596,26 +596,33 @@ static int kx022a_drop_fifo_contents(struct kx022a_data *data)return regmap_write (data->regmap, data->chip_info->buf_clear,0x0 ); } +static int kx022a_get_fifo_bytes (struct kx022a_data *data) +{ +int ret, fifo_bytes; + + ret =regmap_read (data->regmap,KX022A_REG_BUF_STATUS_1 , &fifo_bytes); +if (ret) { +dev_err (data->dev,"Error reading buffer status\n" ); +return ret; + } + +if (fifo_bytes ==KX022A_FIFO_FULL_VALUE ) +return KX022A_FIFO_MAX_BYTES ; + +return fifo_bytes; +} +static int __kx022a_fifo_flush (struct iio_dev *idev,unsigned int samples,bool irq) {struct kx022a_data *data =iio_priv (idev); -struct device *dev =regmap_get_device (data->regmap);uint64_t sample_period;int count, fifo_bytes;bool renable = false;int64_t tstamp;int ret, i; - ret =regmap_read (data->regmap,KX022A_REG_BUF_STATUS_1 , &fifo_bytes); -if (ret) { -dev_err (dev,"Error reading buffer status\n" ); -return ret; - } - -/* Let's not overflow if we for some reason get bogus value from i2c */ -if (fifo_bytes ==KX022A_FIFO_FULL_VALUE ) - fifo_bytes =KX022A_FIFO_MAX_BYTES ; + fifo_bytes = data->chip_info->get_fifo_bytes (data);if (fifo_bytes %KX022A_FIFO_SAMPLES_SIZE_BYTES )dev_warn (data->dev,"Bad FIFO alignment. Data may be corrupt\n" );
@@ -1023,6 +1030,7 @@ const struct kx022a_chip_info kx022a_chip_info = { .inc5 = KX022A_REG_INC5, .inc6 = KX022A_REG_INC6, .xout_l = KX022A_REG_XOUT_L, + .get_fifo_bytes = kx022a_get_fifo_bytes, };EXPORT_SYMBOL_NS_GPL (kx022a_chip_info,IIO_KX022A );
drivers/iio/accel/kionix-kx022a.h +4 -0
@@ -76,6 +76,8 @@struct device ; +struct kx022a_data ; +/** * struct kx022a_chip_info - Kionix accelerometer chip specific information *
@@ -99,6 +101,7 @@ struct device;* @inc5: interrupt control register 5 * @inc6: interrupt control register 6 * @xout_l: x-axis output least significant byte +* @get_fifo_bytes: function pointer to get number of bytes in the FIFO buffer */ struct kx022a_chip_info {const char *name;
@@ -121,6 +124,7 @@ struct kx022a_chip_info {u8 inc5;u8 inc6;u8 xout_l; +int (*get_fifo_bytes)(struct kx022a_data *); };int kx022a_probe_internal (struct device *dev,const struct kx022a_chip_info *chip_info);
Signature · 1 line
2.30.2
PATCH v7 7/7 iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer
In reply to Mehdi DjaitKionix KX132-1211 is a tri-axis 16-bit accelerometer that can support ranges from ±2G to ±16G, digital output through I²C/SPI.
Add support for basic accelerometer features such as reading acceleration via IIO using raw reads, triggered buffer (data-ready), or the WMI IRQ.
Datasheet: https://kionixfs.azureedge.net/en/document/KX132-1211-Technical-Reference-Manual-Rev-5.0.pdf
---
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
v6:
- no changes
v5:
- 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
v4:
- added KX132_REG_CNTL5 to the volatile ranges
- added the kionix reserved regs to the read_only ranges
- removed KX132_REG_MAN_WAKEUP from the write_only ranges
v3:
- fixed the warning of the kernel test robot in kx132_get_fifo_bytes (invalid assignment: &=, left side has type restricted __le16 right side has type unsigned short)
v2:
- mentioned the kx132-1211 in the Kconfig
- added a kx132-specific get_fifo_bytes function
- changed the device name from "kx132" to "kx132-1211
drivers/iio/accel/Kconfig | 8 +- drivers/iio/accel/kionix-kx022a-i2c.c | 2 + drivers/iio/accel/kionix-kx022a-spi.c | 2 + drivers/iio/accel/kionix-kx022a.c | 164 ++++++++++++++++++++++++++ drivers/iio/accel/kionix-kx022a.h | 54 +++++++++ 5 files changed, 226 insertions(+), 4 deletions(-)
drivers/iio/accel/Kconfig +4 -4
@@ -418,8 +418,8 @@ config IIO_KX022A_SPI select IIO_KX022A select REGMAP_SPI help - Enable support for the Kionix KX022A digital tri-axis - accelerometer connected to I2C interface. + Enable support for the Kionix KX022A, KX132-1211 digital tri-axis + accelerometers connected to SPI interface. config IIO_KX022A_I2C tristate "Kionix KX022A tri-axis digital accelerometer I2C interface"
@@ -427,8 +427,8 @@ config IIO_KX022A_I2C select IIO_KX022A select REGMAP_I2C help - Enable support for the Kionix KX022A digital tri-axis - accelerometer connected to I2C interface. + Enable support for the Kionix KX022A, KX132-1211 digital tri-axis + accelerometers connected to I2C interface. config KXSD9 tristate "Kionix KXSD9 Accelerometer Driver"
drivers/iio/accel/kionix-kx022a-i2c.c +2 -0
@@ -41,12 +41,14 @@ static int kx022a_i2c_probe(struct i2c_client *i2c)static const struct i2c_device_id kx022a_i2c_id[] = { { .name ="kx022a" , .driver_data = (kernel_ulong_t)&kx022a_chip_info }, + { .name ="kx132-1211" , .driver_data = (kernel_ulong_t)&kx132_chip_info }, { } };MODULE_DEVICE_TABLE (i2c, kx022a_i2c_id);static const struct of_device_id kx022a_of_match[] = { { .compatible ="kionix,kx022a" , .data = &kx022a_chip_info }, + { .compatible ="kionix,kx132-1211" , .data = &kx132_chip_info }, { } };MODULE_DEVICE_TABLE (of, kx022a_of_match);
drivers/iio/accel/kionix-kx022a-spi.c +2 -0
@@ -37,12 +37,14 @@ static int kx022a_spi_probe(struct spi_device *spi)static const struct spi_device_id kx022a_id[] = { { .name ="kx022a" , .driver_data = (kernel_ulong_t)&kx022a_chip_info }, + { .name ="kx132-1211" , .driver_data = (kernel_ulong_t)&kx132_chip_info }, { } };MODULE_DEVICE_TABLE (spi, kx022a_id);static const struct of_device_id kx022a_of_match[] = { { .compatible ="kionix,kx022a" , .data = &kx022a_chip_info }, + { .compatible ="kionix,kx132-1211" , .data = &kx132_chip_info }, { } };MODULE_DEVICE_TABLE (of, kx022a_of_match);
drivers/iio/accel/kionix-kx022a.c +164 -0
188 lines not on this page · raw message
drivers/iio/accel/kionix-kx022a.h +54 -0
77 lines not on this page · raw message
Signature · 1 line
2.30.2
Matti Vaittinen
maintainerQuoted 9 lines · Mehdi Djait
Kionix KX132-1211 is a tri-axis 16-bit accelerometer that can support ranges from ±2G to ±16G, digital output through I²C/SPI.
Add support for basic accelerometer features such as reading acceleration via IIO using raw reads, triggered buffer (data-ready), or the WMI IRQ.Datasheet: https://kionixfs.azureedge.net/en/document/KX132-1211-Technical-Reference-Manual-Rev-5.0.pdf
Acked-by Matti Vaittinen <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Mehdi Djait <[email protected]>
Quoted 6 lines
---
v7:
- added amin_tinkx132_get_fifo_bytesto ensure that we don't that thefifo_bytesis never bigger than the
fifo_length*KX022A_FIFO_SAMPLES_SIZE_BYTES- no matter what we read from I2C as suggested by Matti
Thanks a lot Mehdi! Looks good to me :)
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~