* [PATCH v3 1/7] iio: accel: kx022a: Use cleanup.h helpers
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
@ 2024-11-28 9:01 ` Matti Vaittinen
2024-11-30 18:05 ` Jonathan Cameron
2024-11-28 9:02 ` [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges Matti Vaittinen
` (5 subsequent siblings)
6 siblings, 1 reply; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:01 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 5301 bytes --]
A few functions in KX022A need to use mutex for protecting the
enabling/disabling of the measurement while configurations are being
made. Some of the functions can be slightly simplified by using the
__cleanup based scoped mutexes, which allows dropping the goto based
unlocking at error path.
Simplify error paths using guard(mutex).
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- patch number changed because a change was added to the series.
- rebased on iio/testing to avoid conflicts with queued fixes.
---
drivers/iio/accel/kionix-kx022a.c | 61 ++++++++++++-------------------
1 file changed, 23 insertions(+), 38 deletions(-)
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index b6664299e0d5..98953178a580 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -5,6 +5,7 @@
* ROHM/KIONIX accelerometer driver
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/interrupt.h>
@@ -448,7 +449,7 @@ static void kx022a_reg2scale(unsigned int val, unsigned int *val1,
*val2 = kx022a_scale_table[val][1];
}
-static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on)
+static int __kx022a_turn_on_off(struct kx022a_data *data, bool on)
{
int ret;
@@ -469,7 +470,7 @@ static int kx022a_turn_off_lock(struct kx022a_data *data)
int ret;
mutex_lock(&data->mutex);
- ret = kx022a_turn_on_off_unlocked(data, false);
+ ret = __kx022a_turn_on_off(data, false);
if (ret)
mutex_unlock(&data->mutex);
@@ -480,7 +481,7 @@ static int kx022a_turn_on_unlock(struct kx022a_data *data)
{
int ret;
- ret = kx022a_turn_on_off_unlocked(data, true);
+ ret = __kx022a_turn_on_off(data, true);
mutex_unlock(&data->mutex);
return ret;
@@ -912,18 +913,19 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
{
int ret = 0;
- ret = kx022a_turn_off_lock(data);
+ guard(mutex)(&data->mutex);
+ ret = __kx022a_turn_on_off(data, false);
if (ret)
return ret;
ret = regmap_clear_bits(data->regmap, data->ien_reg, KX022A_MASK_WMI);
if (ret)
- goto unlock_out;
+ return ret;
ret = regmap_clear_bits(data->regmap, data->chip_info->buf_cntl2,
KX022A_MASK_BUF_EN);
if (ret)
- goto unlock_out;
+ return ret;
data->state &= ~KX022A_STATE_FIFO;
@@ -931,12 +933,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
kfree(data->fifo_buffer);
- return kx022a_turn_on_unlock(data);
-
-unlock_out:
- mutex_unlock(&data->mutex);
-
- return ret;
+ return __kx022a_turn_on_off(data, true);
}
static int kx022a_buffer_predisable(struct iio_dev *idev)
@@ -959,33 +956,29 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
if (!data->fifo_buffer)
return -ENOMEM;
- ret = kx022a_turn_off_lock(data);
+ guard(mutex)(&data->mutex);
+ ret = __kx022a_turn_on_off(data, false);
if (ret)
return ret;
/* Update watermark to HW */
ret = kx022a_fifo_set_wmi(data);
if (ret)
- goto unlock_out;
+ return ret;
/* Enable buffer */
ret = regmap_set_bits(data->regmap, data->chip_info->buf_cntl2,
KX022A_MASK_BUF_EN);
if (ret)
- goto unlock_out;
+ return ret;
data->state |= KX022A_STATE_FIFO;
ret = regmap_set_bits(data->regmap, data->ien_reg,
KX022A_MASK_WMI);
if (ret)
- goto unlock_out;
-
- return kx022a_turn_on_unlock(data);
-
-unlock_out:
- mutex_unlock(&data->mutex);
+ return ret;
- return ret;
+ return __kx022a_turn_on_off(data, true);
}
static int kx022a_buffer_postenable(struct iio_dev *idev)
@@ -1053,7 +1046,7 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private)
struct kx022a_data *data = iio_priv(idev);
irqreturn_t ret = IRQ_NONE;
- mutex_lock(&data->mutex);
+ guard(mutex)(&data->mutex);
if (data->trigger_enabled) {
iio_trigger_poll_nested(data->trig);
@@ -1068,8 +1061,6 @@ static irqreturn_t kx022a_irq_thread_handler(int irq, void *private)
ret = IRQ_HANDLED;
}
- mutex_unlock(&data->mutex);
-
return ret;
}
@@ -1079,32 +1070,26 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig,
struct kx022a_data *data = iio_trigger_get_drvdata(trig);
int ret = 0;
- mutex_lock(&data->mutex);
+ guard(mutex)(&data->mutex);
if (data->trigger_enabled == state)
- goto unlock_out;
+ return 0;
if (data->state & KX022A_STATE_FIFO) {
dev_warn(data->dev, "Can't set trigger when FIFO enabled\n");
- ret = -EBUSY;
- goto unlock_out;
+ return -EBUSY;
}
- ret = kx022a_turn_on_off_unlocked(data, false);
+ ret = __kx022a_turn_on_off(data, false);
if (ret)
- goto unlock_out;
+ return ret;
data->trigger_enabled = state;
ret = kx022a_set_drdy_irq(data, state);
if (ret)
- goto unlock_out;
-
- ret = kx022a_turn_on_off_unlocked(data, true);
-
-unlock_out:
- mutex_unlock(&data->mutex);
+ return ret;
- return ret;
+ return __kx022a_turn_on_off(data, true);
}
static const struct iio_trigger_ops kx022a_trigger_ops = {
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 1/7] iio: accel: kx022a: Use cleanup.h helpers
2024-11-28 9:01 ` [PATCH v3 1/7] iio: accel: kx022a: Use cleanup.h helpers Matti Vaittinen
@ 2024-11-30 18:05 ` Jonathan Cameron
0 siblings, 0 replies; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:05 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On Thu, 28 Nov 2024 11:01:48 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> A few functions in KX022A need to use mutex for protecting the
> enabling/disabling of the measurement while configurations are being
> made. Some of the functions can be slightly simplified by using the
> __cleanup based scoped mutexes, which allows dropping the goto based
> unlocking at error path.
>
> Simplify error paths using guard(mutex).
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Applied this patch to the testing branch of iio.git.
I'll rebase on rc1 in a couple of days before pushing out as togreg.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
2024-11-28 9:01 ` [PATCH v3 1/7] iio: accel: kx022a: Use cleanup.h helpers Matti Vaittinen
@ 2024-11-28 9:02 ` Matti Vaittinen
2024-12-02 10:25 ` Mehdi Djait
2024-11-28 9:02 ` [PATCH v3 3/7] dt-bindings: ROHM KX134ACR-LBZ Matti Vaittinen
` (4 subsequent siblings)
6 siblings, 1 reply; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:02 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 5199 bytes --]
The register interface of the ROHM KX134ACR-LBZ accelerometer is almost
identical to the KX132ACR-LBZ. Main difference between these
accelerometers is that the KX134ACR-LBZ supports G-ranges +/- 8, 16,
32 and 64G. All the other sensors supported by the kx022a driver can
measure +/- 2, 4, 8 and 16G.
Prepare supporting the KX134ACR-LBZ with different G-ranges by storing
a pointer to the scale tables in IC specific structure.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- patch number changed because a change was added to the series.
- rebased on iio/testing to avoid conflicts with queued fixes.
---
drivers/iio/accel/kionix-kx022a.c | 32 ++++++++++++++++++++-----------
drivers/iio/accel/kionix-kx022a.h | 2 ++
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 98953178a580..b23a27623a46 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -413,6 +413,8 @@ static int kx022a_read_avail(struct iio_dev *indio_dev,
const int **vals, int *type, int *length,
long mask)
{
+ struct kx022a_data *data = iio_priv(indio_dev);
+
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
*vals = (const int *)kx022a_accel_samp_freq_table;
@@ -421,9 +423,8 @@ static int kx022a_read_avail(struct iio_dev *indio_dev,
*type = IIO_VAL_INT_PLUS_MICRO;
return IIO_AVAIL_LIST;
case IIO_CHAN_INFO_SCALE:
- *vals = (const int *)kx022a_scale_table;
- *length = ARRAY_SIZE(kx022a_scale_table) *
- ARRAY_SIZE(kx022a_scale_table[0]);
+ *vals = (const int *)data->chip_info->scale_table;
+ *length = data->chip_info->scale_table_size;
*type = IIO_VAL_INT_PLUS_NANO;
return IIO_AVAIL_LIST;
default:
@@ -439,14 +440,14 @@ static void kx022a_reg2freq(unsigned int val, int *val1, int *val2)
*val2 = kx022a_accel_samp_freq_table[val & KX022A_MASK_ODR][1];
}
-static void kx022a_reg2scale(unsigned int val, unsigned int *val1,
- unsigned int *val2)
+static void kx022a_reg2scale(struct kx022a_data *data, unsigned int val,
+ unsigned int *val1, unsigned int *val2)
{
val &= KX022A_MASK_GSEL;
val >>= KX022A_GSEL_SHIFT;
- *val1 = kx022a_scale_table[val][0];
- *val2 = kx022a_scale_table[val][1];
+ *val1 = data->chip_info->scale_table[val][0];
+ *val2 = data->chip_info->scale_table[val][1];
}
static int __kx022a_turn_on_off(struct kx022a_data *data, bool on)
@@ -544,11 +545,11 @@ static int kx022a_write_raw(struct iio_dev *idev,
kx022a_turn_on_unlock(data);
break;
case IIO_CHAN_INFO_SCALE:
- n = ARRAY_SIZE(kx022a_scale_table);
+ n = data->chip_info->scale_table_size / 2;
while (n-- > 0)
- if (val == kx022a_scale_table[n][0] &&
- val2 == kx022a_scale_table[n][1])
+ if (val == data->chip_info->scale_table[n][0] &&
+ val2 == data->chip_info->scale_table[n][1])
break;
if (n < 0) {
ret = -EINVAL;
@@ -643,7 +644,7 @@ static int kx022a_read_raw(struct iio_dev *idev,
if (ret < 0)
return ret;
- kx022a_reg2scale(regval, val, val2);
+ kx022a_reg2scale(data, regval, val, val2);
return IIO_VAL_INT_PLUS_NANO;
}
@@ -1148,6 +1149,9 @@ const struct kx022a_chip_info kx022a_chip_info = {
.regmap_config = &kx022a_regmap_config,
.channels = kx022a_channels,
.num_channels = ARRAY_SIZE(kx022a_channels),
+ .scale_table = kx022a_scale_table,
+ .scale_table_size = ARRAY_SIZE(kx022a_scale_table) *
+ ARRAY_SIZE(kx022a_scale_table[0]),
.fifo_length = KX022A_FIFO_LENGTH,
.who = KX022A_REG_WHO,
.id = KX022A_ID,
@@ -1173,6 +1177,9 @@ const struct kx022a_chip_info kx132_chip_info = {
.regmap_config = &kx132_regmap_config,
.channels = kx132_channels,
.num_channels = ARRAY_SIZE(kx132_channels),
+ .scale_table = kx022a_scale_table,
+ .scale_table_size = ARRAY_SIZE(kx022a_scale_table) *
+ ARRAY_SIZE(kx022a_scale_table[0]),
.fifo_length = KX132_FIFO_LENGTH,
.who = KX132_REG_WHO,
.id = KX132_ID,
@@ -1206,6 +1213,9 @@ const struct kx022a_chip_info kx132acr_chip_info = {
.regmap_config = &kx022a_regmap_config,
.channels = kx022a_channels,
.num_channels = ARRAY_SIZE(kx022a_channels),
+ .scale_table = kx022a_scale_table,
+ .scale_table_size = ARRAY_SIZE(kx022a_scale_table) *
+ ARRAY_SIZE(kx022a_scale_table[0]),
.fifo_length = KX022A_FIFO_LENGTH,
.who = KX022A_REG_WHO,
.id = KX132ACR_LBZ_ID,
diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
index 7060438ad88c..36e9d9de8c13 100644
--- a/drivers/iio/accel/kionix-kx022a.h
+++ b/drivers/iio/accel/kionix-kx022a.h
@@ -161,6 +161,8 @@ struct kx022a_data;
struct kx022a_chip_info {
const char *name;
const struct regmap_config *regmap_config;
+ const int (*scale_table)[2];
+ const int scale_table_size;
const struct iio_chan_spec *channels;
unsigned int num_channels;
unsigned int fifo_length;
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges
2024-11-28 9:02 ` [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges Matti Vaittinen
@ 2024-12-02 10:25 ` Mehdi Djait
2024-12-02 11:05 ` Matti Vaittinen
0 siblings, 1 reply; 20+ messages in thread
From: Mehdi Djait @ 2024-12-02 10:25 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Jonathan Cameron, Lars-Peter Clausen,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio,
devicetree, linux-kernel
Hi Matti,
Sorry for the late answer. I know that this was already applied so maybe
you can post a really small follow-up patch ?
> diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
> index 7060438ad88c..36e9d9de8c13 100644
> --- a/drivers/iio/accel/kionix-kx022a.h
> +++ b/drivers/iio/accel/kionix-kx022a.h
> @@ -161,6 +161,8 @@ struct kx022a_data;
> struct kx022a_chip_info {
> const char *name;
> const struct regmap_config *regmap_config;
> + const int (*scale_table)[2];
> + const int scale_table_size;
Could you please add kernel-doc for these two new elements like the others already
have ?
> const struct iio_chan_spec *channels;
> unsigned int num_channels;
> unsigned int fifo_length;
> --
> 2.47.0
>
--
Kind Regards
Mehdi Djait
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges
2024-12-02 10:25 ` Mehdi Djait
@ 2024-12-02 11:05 ` Matti Vaittinen
0 siblings, 0 replies; 20+ messages in thread
From: Matti Vaittinen @ 2024-12-02 11:05 UTC (permalink / raw)
To: Mehdi Djait
Cc: Matti Vaittinen, Jonathan Cameron, Lars-Peter Clausen,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio,
devicetree, linux-kernel
On 02/12/2024 12:25, Mehdi Djait wrote:
> Hi Matti,
>
> Sorry for the late answer. I know that this was already applied so maybe
> you can post a really small follow-up patch ?
>
>> diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
>> index 7060438ad88c..36e9d9de8c13 100644
>> --- a/drivers/iio/accel/kionix-kx022a.h
>> +++ b/drivers/iio/accel/kionix-kx022a.h
>> @@ -161,6 +161,8 @@ struct kx022a_data;
>> struct kx022a_chip_info {
>> const char *name;
>> const struct regmap_config *regmap_config;
>> + const int (*scale_table)[2];
>> + const int scale_table_size;
>
> Could you please add kernel-doc for these two new elements like the others already
> have ?
Thanks Mehdi. I think this makes sense :)
Yours,
-- Matti
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 3/7] dt-bindings: ROHM KX134ACR-LBZ
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
2024-11-28 9:01 ` [PATCH v3 1/7] iio: accel: kx022a: Use cleanup.h helpers Matti Vaittinen
2024-11-28 9:02 ` [PATCH v3 2/7] iio: accel: kx022a: Support ICs with different G-ranges Matti Vaittinen
@ 2024-11-28 9:02 ` Matti Vaittinen
2024-11-28 9:02 ` [PATCH v3 4/7] iio: kx022a: Support " Matti Vaittinen
` (3 subsequent siblings)
6 siblings, 0 replies; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:02 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1761 bytes --]
From the software point of view, the KX134ACR-LBZ is almost identical to
the KX132ACR-LBZ. They, however, have different g ranges and ID register
values which makes them incompatible.
Add compatible and information for ROHM KX134ACR-LBZ accelerometer.
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- Improve commit message by explaining why compatible is needed.
- patch number changed because a change was added to the series.
- rebased on iio/testing to avoid conflicts with queued fixes.
---
.../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
index 66ea894dbe55..c973f4941a6d 100644
--- a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
+++ b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
@@ -11,7 +11,8 @@ maintainers:
description: |
KX022A, KX132ACR-LBZ and KX132-1211 are 3-axis accelerometers supporting
- +/- 2G, 4G, 8G and 16G ranges, variable output data-rates and a
+ +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ supports +/- 8G, 16G,
+ 32G and 64G. All the sensors also have variable output data-rates and a
hardware-fifo buffering. These accelerometers can be accessed either
via I2C or SPI.
@@ -21,6 +22,7 @@ properties:
- kionix,kx022a
- kionix,kx132-1211
- rohm,kx132acr-lbz
+ - rohm,kx134acr-lbz
reg:
maxItems: 1
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 4/7] iio: kx022a: Support ROHM KX134ACR-LBZ
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
` (2 preceding siblings ...)
2024-11-28 9:02 ` [PATCH v3 3/7] dt-bindings: ROHM KX134ACR-LBZ Matti Vaittinen
@ 2024-11-28 9:02 ` Matti Vaittinen
2024-11-30 18:06 ` Jonathan Cameron
2024-11-28 9:03 ` [PATCH v3 5/7] dt-bindings: iio: kx022a: Support KX134-1211 Matti Vaittinen
` (2 subsequent siblings)
6 siblings, 1 reply; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:02 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 5872 bytes --]
The register interface of the ROHM KX134ACR-LBZ accelerometer is
almost identical to the KX132ACR-LBZ. The main difference between these
accelerometers is that the KX134ACR-LBZ supports different G-ranges. The
driver can model this by informing different scale to users. Also, the
content of the "who_am_I" register is different.
Add an ID and scales for the KX134ACR-LBZ.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- patch number changed because a change was added to the series.
- rebased on iio/testing to avoid conflicts with queued fixes.
---
drivers/iio/accel/kionix-kx022a-i2c.c | 2 ++
drivers/iio/accel/kionix-kx022a-spi.c | 2 ++
drivers/iio/accel/kionix-kx022a.c | 36 +++++++++++++++++++++++++++
drivers/iio/accel/kionix-kx022a.h | 2 ++
4 files changed, 42 insertions(+)
diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c
index 8a1d4fc28ddd..9fd049c2b62e 100644
--- a/drivers/iio/accel/kionix-kx022a-i2c.c
+++ b/drivers/iio/accel/kionix-kx022a-i2c.c
@@ -39,6 +39,7 @@ 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 },
{ .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
+ { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
{ }
};
MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id);
@@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = {
{ .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
{ .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },
{ .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
+ { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
{ }
};
MODULE_DEVICE_TABLE(of, kx022a_of_match);
diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c
index f798b964d0b5..b20978afc565 100644
--- a/drivers/iio/accel/kionix-kx022a-spi.c
+++ b/drivers/iio/accel/kionix-kx022a-spi.c
@@ -39,6 +39,7 @@ 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 },
{ .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
+ { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
{ }
};
MODULE_DEVICE_TABLE(spi, kx022a_id);
@@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = {
{ .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
{ .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },
{ .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
+ { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
{ }
};
MODULE_DEVICE_TABLE(of, kx022a_of_match);
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index b23a27623a46..9fe16802c125 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -408,6 +408,14 @@ static const int kx022a_scale_table[][2] = {
{ 0, 4788403 },
};
+/* KX134ACR-LBZ ranges are (+/-) 8, 16, 32, 64 G */
+static const int kx134acr_lbz_scale_table[][2] = {
+ { 0, 2394202 },
+ { 0, 4788403 },
+ { 0, 9576807 },
+ { 0, 19153613 },
+};
+
static int kx022a_read_avail(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
const int **vals, int *type, int *length,
@@ -1236,6 +1244,34 @@ const struct kx022a_chip_info kx132acr_chip_info = {
};
EXPORT_SYMBOL_NS_GPL(kx132acr_chip_info, IIO_KX022A);
+const struct kx022a_chip_info kx134acr_chip_info = {
+ .name = "kx134acr-lbz",
+ .regmap_config = &kx022a_regmap_config,
+ .channels = kx022a_channels,
+ .num_channels = ARRAY_SIZE(kx022a_channels),
+ .scale_table = kx134acr_lbz_scale_table,
+ .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) *
+ ARRAY_SIZE(kx134acr_lbz_scale_table[0]),
+ .fifo_length = KX022A_FIFO_LENGTH,
+ .who = KX022A_REG_WHO,
+ .id = KX134ACR_LBZ_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(kx134acr_chip_info, IIO_KX022A);
+
int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info)
{
static const char * const regulator_names[] = {"io-vdd", "vdd"};
diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
index 36e9d9de8c13..ea32fd252a38 100644
--- a/drivers/iio/accel/kionix-kx022a.h
+++ b/drivers/iio/accel/kionix-kx022a.h
@@ -14,6 +14,7 @@
#define KX022A_REG_WHO 0x0f
#define KX022A_ID 0xc8
#define KX132ACR_LBZ_ID 0xd8
+#define KX134ACR_LBZ_ID 0xcc
#define KX022A_REG_CNTL2 0x19
#define KX022A_MASK_SRST BIT(7)
@@ -190,5 +191,6 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi
extern const struct kx022a_chip_info kx022a_chip_info;
extern const struct kx022a_chip_info kx132_chip_info;
extern const struct kx022a_chip_info kx132acr_chip_info;
+extern const struct kx022a_chip_info kx134acr_chip_info;
#endif
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 4/7] iio: kx022a: Support ROHM KX134ACR-LBZ
2024-11-28 9:02 ` [PATCH v3 4/7] iio: kx022a: Support " Matti Vaittinen
@ 2024-11-30 18:06 ` Jonathan Cameron
0 siblings, 0 replies; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:06 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On Thu, 28 Nov 2024 11:02:45 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> The register interface of the ROHM KX134ACR-LBZ accelerometer is
> almost identical to the KX132ACR-LBZ. The main difference between these
> accelerometers is that the KX134ACR-LBZ supports different G-ranges. The
> driver can model this by informing different scale to users. Also, the
> content of the "who_am_I" register is different.
>
> Add an ID and scales for the KX134ACR-LBZ.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Applied 2-4
Thanks,
Jonathan
>
> ---
> Revision history:
> v2 => v3:
> - patch number changed because patches were dropped.
> v1 => v2:
> - patch number changed because a change was added to the series.
> - rebased on iio/testing to avoid conflicts with queued fixes.
> ---
> drivers/iio/accel/kionix-kx022a-i2c.c | 2 ++
> drivers/iio/accel/kionix-kx022a-spi.c | 2 ++
> drivers/iio/accel/kionix-kx022a.c | 36 +++++++++++++++++++++++++++
> drivers/iio/accel/kionix-kx022a.h | 2 ++
> 4 files changed, 42 insertions(+)
>
> diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c
> index 8a1d4fc28ddd..9fd049c2b62e 100644
> --- a/drivers/iio/accel/kionix-kx022a-i2c.c
> +++ b/drivers/iio/accel/kionix-kx022a-i2c.c
> @@ -39,6 +39,7 @@ 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 },
> { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
> + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, kx022a_i2c_id);
> @@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = {
> { .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
> { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },
> { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
> + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
> { }
> };
> MODULE_DEVICE_TABLE(of, kx022a_of_match);
> diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c
> index f798b964d0b5..b20978afc565 100644
> --- a/drivers/iio/accel/kionix-kx022a-spi.c
> +++ b/drivers/iio/accel/kionix-kx022a-spi.c
> @@ -39,6 +39,7 @@ 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 },
> { .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
> + { .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
> { }
> };
> MODULE_DEVICE_TABLE(spi, kx022a_id);
> @@ -47,6 +48,7 @@ static const struct of_device_id kx022a_of_match[] = {
> { .compatible = "kionix,kx022a", .data = &kx022a_chip_info },
> { .compatible = "kionix,kx132-1211", .data = &kx132_chip_info },
> { .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
> + { .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
> { }
> };
> MODULE_DEVICE_TABLE(of, kx022a_of_match);
> diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
> index b23a27623a46..9fe16802c125 100644
> --- a/drivers/iio/accel/kionix-kx022a.c
> +++ b/drivers/iio/accel/kionix-kx022a.c
> @@ -408,6 +408,14 @@ static const int kx022a_scale_table[][2] = {
> { 0, 4788403 },
> };
>
> +/* KX134ACR-LBZ ranges are (+/-) 8, 16, 32, 64 G */
> +static const int kx134acr_lbz_scale_table[][2] = {
> + { 0, 2394202 },
> + { 0, 4788403 },
> + { 0, 9576807 },
> + { 0, 19153613 },
> +};
> +
> static int kx022a_read_avail(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> const int **vals, int *type, int *length,
> @@ -1236,6 +1244,34 @@ const struct kx022a_chip_info kx132acr_chip_info = {
> };
> EXPORT_SYMBOL_NS_GPL(kx132acr_chip_info, IIO_KX022A);
>
> +const struct kx022a_chip_info kx134acr_chip_info = {
> + .name = "kx134acr-lbz",
> + .regmap_config = &kx022a_regmap_config,
> + .channels = kx022a_channels,
> + .num_channels = ARRAY_SIZE(kx022a_channels),
> + .scale_table = kx134acr_lbz_scale_table,
> + .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) *
> + ARRAY_SIZE(kx134acr_lbz_scale_table[0]),
> + .fifo_length = KX022A_FIFO_LENGTH,
> + .who = KX022A_REG_WHO,
> + .id = KX134ACR_LBZ_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(kx134acr_chip_info, IIO_KX022A);
> +
> int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info)
> {
> static const char * const regulator_names[] = {"io-vdd", "vdd"};
> diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
> index 36e9d9de8c13..ea32fd252a38 100644
> --- a/drivers/iio/accel/kionix-kx022a.h
> +++ b/drivers/iio/accel/kionix-kx022a.h
> @@ -14,6 +14,7 @@
> #define KX022A_REG_WHO 0x0f
> #define KX022A_ID 0xc8
> #define KX132ACR_LBZ_ID 0xd8
> +#define KX134ACR_LBZ_ID 0xcc
>
> #define KX022A_REG_CNTL2 0x19
> #define KX022A_MASK_SRST BIT(7)
> @@ -190,5 +191,6 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi
> extern const struct kx022a_chip_info kx022a_chip_info;
> extern const struct kx022a_chip_info kx132_chip_info;
> extern const struct kx022a_chip_info kx132acr_chip_info;
> +extern const struct kx022a_chip_info kx134acr_chip_info;
>
> #endif
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 5/7] dt-bindings: iio: kx022a: Support KX134-1211
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
` (3 preceding siblings ...)
2024-11-28 9:02 ` [PATCH v3 4/7] iio: kx022a: Support " Matti Vaittinen
@ 2024-11-28 9:03 ` Matti Vaittinen
2024-11-28 9:03 ` [PATCH v3 6/7] iio: accel: " Matti Vaittinen
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
6 siblings, 0 replies; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:03 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2103 bytes --]
The ROHM KX134-1211 is very similar to KX132-1211. The main difference is
supported g-ranges. The KX132-1211 can measure ranges from +/- 2g to
+/-16g where the KX134-1211 supports measuring ranges +/- 8g to +/- 64g.
Support the ROHM KX134-1211.
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- new patch.
---
.../devicetree/bindings/iio/accel/kionix,kx022a.yaml | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
index c973f4941a6d..f07c70e51c45 100644
--- a/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
+++ b/Documentation/devicetree/bindings/iio/accel/kionix,kx022a.yaml
@@ -4,23 +4,24 @@
$id: http://devicetree.org/schemas/iio/accel/kionix,kx022a.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
-title: ROHM/Kionix KX022A, KX132-1211 and KX132ACR-LBZ Accelerometers
+title: ROHM/Kionix KX022A, KX132/134-1211 and KX132/134ACR-LBZ Accelerometers
maintainers:
- Matti Vaittinen <mazziesaccount@gmail.com>
description: |
KX022A, KX132ACR-LBZ and KX132-1211 are 3-axis accelerometers supporting
- +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ supports +/- 8G, 16G,
- 32G and 64G. All the sensors also have variable output data-rates and a
- hardware-fifo buffering. These accelerometers can be accessed either
- via I2C or SPI.
+ +/- 2G, 4G, 8G and 16G ranges. The KX134ACR-LBZ and KX134-1211 support
+ +/- 8G, 16G, 32G and 64G. All the sensors also have variable output
+ data-rates and a hardware-fifo buffering. These accelerometers can be
+ accessed either via I2C or SPI.
properties:
compatible:
enum:
- kionix,kx022a
- kionix,kx132-1211
+ - kionix,kx134-1211
- rohm,kx132acr-lbz
- rohm,kx134acr-lbz
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v3 6/7] iio: accel: kx022a: Support KX134-1211
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
` (4 preceding siblings ...)
2024-11-28 9:03 ` [PATCH v3 5/7] dt-bindings: iio: kx022a: Support KX134-1211 Matti Vaittinen
@ 2024-11-28 9:03 ` Matti Vaittinen
2024-11-30 18:07 ` Jonathan Cameron
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
6 siblings, 1 reply; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:03 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 5583 bytes --]
The ROHM KX134-1211 has very similar register interface as KX132-1211
does. The main differencies are the content of the "Who am I"
identification register and different g-ranges. The KX132-1211 can
measure ranges from +/- 2g to +/-16g where the KX134-1211 supports
measuring ranges +/- 8g to +/- 64g.
Support the ROHM KX134-1211.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- patch number changed because patches were dropped.
v1 => v2:
- new patch.
---
drivers/iio/accel/kionix-kx022a-i2c.c | 2 ++
drivers/iio/accel/kionix-kx022a-spi.c | 2 ++
drivers/iio/accel/kionix-kx022a.c | 30 +++++++++++++++++++++++++++
drivers/iio/accel/kionix-kx022a.h | 2 ++
4 files changed, 36 insertions(+)
diff --git a/drivers/iio/accel/kionix-kx022a-i2c.c b/drivers/iio/accel/kionix-kx022a-i2c.c
index 9fd049c2b62e..7359073ae0c0 100644
--- a/drivers/iio/accel/kionix-kx022a-i2c.c
+++ b/drivers/iio/accel/kionix-kx022a-i2c.c
@@ -38,6 +38,7 @@ 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 },
+ { .name = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info },
{ .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
{ .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
{ }
@@ -47,6 +48,7 @@ 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 },
+ { .compatible = "kionix,kx134-1211", .data = &kx134_chip_info },
{ .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
{ .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
{ }
diff --git a/drivers/iio/accel/kionix-kx022a-spi.c b/drivers/iio/accel/kionix-kx022a-spi.c
index b20978afc565..50aeaafc56ec 100644
--- a/drivers/iio/accel/kionix-kx022a-spi.c
+++ b/drivers/iio/accel/kionix-kx022a-spi.c
@@ -38,6 +38,7 @@ 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 },
+ { .name = "kx134-1211", .driver_data = (kernel_ulong_t)&kx134_chip_info },
{ .name = "kx132acr-lbz", .driver_data = (kernel_ulong_t)&kx132acr_chip_info },
{ .name = "kx134acr-lbz", .driver_data = (kernel_ulong_t)&kx134acr_chip_info },
{ }
@@ -47,6 +48,7 @@ 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 },
+ { .compatible = "kionix,kx134-1211", .data = &kx134_chip_info },
{ .compatible = "rohm,kx132acr-lbz", .data = &kx132acr_chip_info },
{ .compatible = "rohm,kx134acr-lbz", .data = &kx134acr_chip_info },
{ }
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 9fe16802c125..e3986dd65337 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -1209,6 +1209,36 @@ const struct kx022a_chip_info kx132_chip_info = {
};
EXPORT_SYMBOL_NS_GPL(kx132_chip_info, IIO_KX022A);
+const struct kx022a_chip_info kx134_chip_info = {
+ .name = "kx134-1211",
+ .regmap_config = &kx132_regmap_config,
+ .channels = kx132_channels,
+ .num_channels = ARRAY_SIZE(kx132_channels),
+ .scale_table = kx134acr_lbz_scale_table,
+ .scale_table_size = ARRAY_SIZE(kx134acr_lbz_scale_table) *
+ ARRAY_SIZE(kx134acr_lbz_scale_table[0]),
+ .fifo_length = KX132_FIFO_LENGTH,
+ .who = KX132_REG_WHO,
+ .id = KX134_1211_ID,
+ .cntl = KX132_REG_CNTL,
+ .cntl2 = KX132_REG_CNTL2,
+ .odcntl = KX132_REG_ODCNTL,
+ .buf_cntl1 = KX132_REG_BUF_CNTL1,
+ .buf_cntl2 = KX132_REG_BUF_CNTL2,
+ .buf_clear = KX132_REG_BUF_CLEAR,
+ .buf_status1 = KX132_REG_BUF_STATUS_1,
+ .buf_smp_lvl_mask = KX132_MASK_BUF_SMP_LVL,
+ .buf_read = KX132_REG_BUF_READ,
+ .inc1 = KX132_REG_INC1,
+ .inc4 = KX132_REG_INC4,
+ .inc5 = KX132_REG_INC5,
+ .inc6 = KX132_REG_INC6,
+ .xout_l = KX132_REG_XOUT_L,
+ .get_fifo_bytes_available = kx132_get_fifo_bytes_available,
+};
+EXPORT_SYMBOL_NS_GPL(kx134_chip_info, IIO_KX022A);
+
+
/*
* Despite the naming, KX132ACR-LBZ is not similar to KX132-1211 but it is
* exact subset of KX022A. KX132ACR-LBZ is meant to be used for industrial
diff --git a/drivers/iio/accel/kionix-kx022a.h b/drivers/iio/accel/kionix-kx022a.h
index ea32fd252a38..142652ff4b22 100644
--- a/drivers/iio/accel/kionix-kx022a.h
+++ b/drivers/iio/accel/kionix-kx022a.h
@@ -78,6 +78,7 @@
#define KX132_REG_WHO 0x13
#define KX132_ID 0x3d
+#define KX134_1211_ID 0x46
#define KX132_FIFO_LENGTH 86
@@ -190,6 +191,7 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi
extern const struct kx022a_chip_info kx022a_chip_info;
extern const struct kx022a_chip_info kx132_chip_info;
+extern const struct kx022a_chip_info kx134_chip_info;
extern const struct kx022a_chip_info kx132acr_chip_info;
extern const struct kx022a_chip_info kx134acr_chip_info;
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 6/7] iio: accel: kx022a: Support KX134-1211
2024-11-28 9:03 ` [PATCH v3 6/7] iio: accel: " Matti Vaittinen
@ 2024-11-30 18:07 ` Jonathan Cameron
0 siblings, 0 replies; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:07 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On Thu, 28 Nov 2024 11:03:18 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> The ROHM KX134-1211 has very similar register interface as KX132-1211
> does. The main differencies are the content of the "Who am I"
> identification register and different g-ranges. The KX132-1211 can
> measure ranges from +/- 2g to +/-16g where the KX134-1211 supports
> measuring ranges +/- 8g to +/- 64g.
>
> Support the ROHM KX134-1211.
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Applied 5-6 to the testing branch of iio.git.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 9:01 [PATCH v3 0/7] Support ROHM KX134ACR-LBZ Matti Vaittinen
` (5 preceding siblings ...)
2024-11-28 9:03 ` [PATCH v3 6/7] iio: accel: " Matti Vaittinen
@ 2024-11-28 9:03 ` Matti Vaittinen
2024-11-28 17:20 ` kernel test robot
` (3 more replies)
6 siblings, 4 replies; 20+ messages in thread
From: Matti Vaittinen @ 2024-11-28 9:03 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Matti Vaittinen, linux-iio,
devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 7264 bytes --]
Many of the Kionix/ROHM accelerometers have a "PC1 - bit" which enables
the accelerometer. While a sensor configuration like ODR, g-range, FIFO
status etc. are changed, the PC1 bit must be cleared (sensor must be
disabled). (See the description for different CNTL registers [1])
In order to ensure this the kx022a driver uses a mutex, which is locked
when the PC1 bit is cleared, and held for the duration of the
configuration, and released after PC1 bit is set again (enabling the
sensor).
The locking and PC1 bit toggling was implemented using functions:
kx022a_turn_off_lock() and kx022a_turn_on_unlock().
Based on a discussions [2], the IIO subsystem prefers open-coding the
locking with scoped_guard() over these functions.
Drop the kx022a_turn_off_lock() and kx022a_turn_on_unlock() and use
scoped_guard() instead.
[1]: https://fscdn.rohm.com/kionix/en/datasheet/kx022acr-z-e.pdf
[2]: https://lore.kernel.org/all/20241126175550.4a8bedf3@jic23-huawei/
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision history:
v2 => v3:
- New patch
NOTE: This patch uses the if_not_cond_guard() which is currently missing
the iio_testing.
https://lore.kernel.org/all/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com/T/#m69982b23da9f71e72d84855b34e9b142cb3a1920
---
drivers/iio/accel/kionix-kx022a.c | 121 ++++++++++++------------------
1 file changed, 48 insertions(+), 73 deletions(-)
diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index e3986dd65337..a34cf8da2860 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -458,7 +458,7 @@ static void kx022a_reg2scale(struct kx022a_data *data, unsigned int val,
*val2 = data->chip_info->scale_table[val][1];
}
-static int __kx022a_turn_on_off(struct kx022a_data *data, bool on)
+static int kx022a_turn_on_off(struct kx022a_data *data, bool on)
{
int ret;
@@ -474,28 +474,6 @@ static int __kx022a_turn_on_off(struct kx022a_data *data, bool on)
return ret;
}
-static int kx022a_turn_off_lock(struct kx022a_data *data)
-{
- int ret;
-
- mutex_lock(&data->mutex);
- ret = __kx022a_turn_on_off(data, false);
- if (ret)
- mutex_unlock(&data->mutex);
-
- return ret;
-}
-
-static int kx022a_turn_on_unlock(struct kx022a_data *data)
-{
- int ret;
-
- ret = __kx022a_turn_on_off(data, true);
- mutex_unlock(&data->mutex);
-
- return ret;
-}
-
static int kx022a_write_raw_get_fmt(struct iio_dev *idev,
struct iio_chan_spec const *chan,
long mask)
@@ -526,9 +504,8 @@ static int kx022a_write_raw(struct iio_dev *idev,
* issues if users trust the watermark to be reached within known
* time-limit).
*/
- ret = iio_device_claim_direct_mode(idev);
- if (ret)
- return ret;
+ if_not_cond_guard(iio_claim_direct_try, idev)
+ return -EBUSY;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
@@ -538,20 +515,20 @@ static int kx022a_write_raw(struct iio_dev *idev,
if (val == kx022a_accel_samp_freq_table[n][0] &&
val2 == kx022a_accel_samp_freq_table[n][1])
break;
- if (n < 0) {
- ret = -EINVAL;
- goto unlock_out;
- }
- ret = kx022a_turn_off_lock(data);
- if (ret)
- break;
+ if (n < 0)
+ return -EINVAL;
- ret = regmap_update_bits(data->regmap,
- data->chip_info->odcntl,
- KX022A_MASK_ODR, n);
- data->odr_ns = kx022a_odrs[n];
- kx022a_turn_on_unlock(data);
- break;
+ scoped_guard(mutex, &data->mutex) {
+ ret = kx022a_turn_on_off(data, false);
+ if (ret)
+ return ret;
+
+ ret = regmap_update_bits(data->regmap,
+ data->chip_info->odcntl,
+ KX022A_MASK_ODR, n);
+ data->odr_ns = kx022a_odrs[n];
+ return kx022a_turn_on_off(data, true);
+ }
case IIO_CHAN_INFO_SCALE:
n = data->chip_info->scale_table_size / 2;
@@ -559,29 +536,27 @@ static int kx022a_write_raw(struct iio_dev *idev,
if (val == data->chip_info->scale_table[n][0] &&
val2 == data->chip_info->scale_table[n][1])
break;
- if (n < 0) {
- ret = -EINVAL;
- goto unlock_out;
- }
+ if (n < 0)
+ return -EINVAL;
- ret = kx022a_turn_off_lock(data);
- if (ret)
- break;
+ scoped_guard(mutex, &data->mutex) {
+ ret = kx022a_turn_on_off(data, false);
+ if (ret)
+ return ret;
- ret = regmap_update_bits(data->regmap, data->chip_info->cntl,
- KX022A_MASK_GSEL,
- n << KX022A_GSEL_SHIFT);
- kx022a_turn_on_unlock(data);
- break;
+ ret = regmap_update_bits(data->regmap,
+ data->chip_info->cntl,
+ KX022A_MASK_GSEL,
+ n << KX022A_GSEL_SHIFT);
+ kx022a_turn_on_off(data, true);
+
+ return ret;
+ }
default:
- ret = -EINVAL;
break;
}
-unlock_out:
- iio_device_release_direct_mode(idev);
-
- return ret;
+ return -EINVAL;
}
static int kx022a_fifo_set_wmi(struct kx022a_data *data)
@@ -923,7 +898,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
int ret = 0;
guard(mutex)(&data->mutex);
- ret = __kx022a_turn_on_off(data, false);
+ ret = kx022a_turn_on_off(data, false);
if (ret)
return ret;
@@ -942,7 +917,7 @@ static int kx022a_fifo_disable(struct kx022a_data *data)
kfree(data->fifo_buffer);
- return __kx022a_turn_on_off(data, true);
+ return kx022a_turn_on_off(data, true);
}
static int kx022a_buffer_predisable(struct iio_dev *idev)
@@ -966,7 +941,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
return -ENOMEM;
guard(mutex)(&data->mutex);
- ret = __kx022a_turn_on_off(data, false);
+ ret = kx022a_turn_on_off(data, false);
if (ret)
return ret;
@@ -987,7 +962,7 @@ static int kx022a_fifo_enable(struct kx022a_data *data)
if (ret)
return ret;
- return __kx022a_turn_on_off(data, true);
+ return kx022a_turn_on_off(data, true);
}
static int kx022a_buffer_postenable(struct iio_dev *idev)
@@ -1089,7 +1064,7 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig,
return -EBUSY;
}
- ret = __kx022a_turn_on_off(data, false);
+ ret = kx022a_turn_on_off(data, false);
if (ret)
return ret;
@@ -1098,7 +1073,7 @@ static int kx022a_trigger_set_state(struct iio_trigger *trig,
if (ret)
return ret;
- return __kx022a_turn_on_off(data, true);
+ return kx022a_turn_on_off(data, true);
}
static const struct iio_trigger_ops kx022a_trigger_ops = {
@@ -1379,19 +1354,19 @@ int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chi
return ret;
/* The sensor must be turned off for configuration */
- ret = kx022a_turn_off_lock(data);
- if (ret)
- return ret;
+ scoped_guard(mutex, &data->mutex) {
+ ret = kx022a_turn_on_off(data, false);
+ if (ret)
+ return ret;
- ret = kx022a_chip_init(data);
- if (ret) {
- mutex_unlock(&data->mutex);
- return ret;
- }
+ ret = kx022a_chip_init(data);
+ if (ret)
+ return ret;
- ret = kx022a_turn_on_unlock(data);
- if (ret)
- return ret;
+ ret = kx022a_turn_on_off(data, true);
+ if (ret)
+ return ret;
+ }
ret = devm_iio_triggered_buffer_setup_ext(dev, idev,
&iio_pollfunc_store_time,
--
2.47.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
@ 2024-11-28 17:20 ` kernel test robot
2024-11-30 18:08 ` Jonathan Cameron
2024-11-28 17:31 ` kernel test robot
` (2 subsequent siblings)
3 siblings, 1 reply; 20+ messages in thread
From: kernel test robot @ 2024-11-28 17:20 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: oe-kbuild-all, Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
Hi Matti,
kernel test robot noticed the following build warnings:
[auto build test WARNING on a61ff7eac77e86de828fe28c4e42b8ae9ec2b195]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-accel-kx022a-Use-cleanup-h-helpers/20241128-170626
base: a61ff7eac77e86de828fe28c4e42b8ae9ec2b195
patch link: https://lore.kernel.org/r/9b63813ecf10b1cd0126cb950bc09514c4287b9a.1732783834.git.mazziesaccount%40gmail.com
patch subject: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20241129/202411290107.KXHPQXRf-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241129/202411290107.KXHPQXRf-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411290107.KXHPQXRf-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/iio/accel/kionix-kx022a.c: In function 'kx022a_write_raw':
drivers/iio/accel/kionix-kx022a.c:507:9: error: implicit declaration of function 'if_not_cond_guard' [-Wimplicit-function-declaration]
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^~~~~~~~~~~~~~~~~
drivers/iio/accel/kionix-kx022a.c:507:27: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^~~~~~~~~~~~~~~~~~~~
| class_iio_claim_direct_try_t
drivers/iio/accel/kionix-kx022a.c:507:27: note: each undeclared identifier is reported only once for each function it appears in
drivers/iio/accel/kionix-kx022a.c:507:54: error: expected ';' before 'return'
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^
| ;
508 | return -EBUSY;
| ~~~~~~
In file included from drivers/iio/accel/kionix-kx022a.c:8:
>> include/linux/cleanup.h:308:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
308 | for (CLASS(_name, scope)(args), \
| ^~~
drivers/iio/accel/kionix-kx022a.c:521:17: note: in expansion of macro 'scoped_guard'
521 | scoped_guard(mutex, &data->mutex) {
| ^~~~~~~~~~~~
drivers/iio/accel/kionix-kx022a.c:532:9: note: here
532 | case IIO_CHAN_INFO_SCALE:
| ^~~~
vim +308 include/linux/cleanup.h
e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 306
54da6a0924311c Peter Zijlstra 2023-05-26 307 #define scoped_guard(_name, args...) \
54da6a0924311c Peter Zijlstra 2023-05-26 @308 for (CLASS(_name, scope)(args), \
e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 309 *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1)
e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 310
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 17:20 ` kernel test robot
@ 2024-11-30 18:08 ` Jonathan Cameron
0 siblings, 0 replies; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:08 UTC (permalink / raw)
To: kernel test robot
Cc: Matti Vaittinen, Matti Vaittinen, oe-kbuild-all,
Lars-Peter Clausen, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-iio, devicetree, linux-kernel
On Fri, 29 Nov 2024 01:20:41 +0800
kernel test robot <lkp@intel.com> wrote:
> Hi Matti,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on a61ff7eac77e86de828fe28c4e42b8ae9ec2b195]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-accel-kx022a-Use-cleanup-h-helpers/20241128-170626
> base: a61ff7eac77e86de828fe28c4e42b8ae9ec2b195
> patch link: https://lore.kernel.org/r/9b63813ecf10b1cd0126cb950bc09514c4287b9a.1732783834.git.mazziesaccount%40gmail.com
> patch subject: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
> config: loongarch-allyesconfig (https://download.01.org/0day-ci/archive/20241129/202411290107.KXHPQXRf-lkp@intel.com/config)
> compiler: loongarch64-linux-gcc (GCC) 14.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241129/202411290107.KXHPQXRf-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202411290107.KXHPQXRf-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
> drivers/iio/accel/kionix-kx022a.c: In function 'kx022a_write_raw':
> drivers/iio/accel/kionix-kx022a.c:507:9: error: implicit declaration of function 'if_not_cond_guard' [-Wimplicit-function-declaration]
> 507 | if_not_cond_guard(iio_claim_direct_try, idev)
> | ^~~~~~~~~~~~~~~~~
> drivers/iio/accel/kionix-kx022a.c:507:27: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
> 507 | if_not_cond_guard(iio_claim_direct_try, idev)
> | ^~~~~~~~~~~~~~~~~~~~
> | class_iio_claim_direct_try_t
> drivers/iio/accel/kionix-kx022a.c:507:27: note: each undeclared identifier is reported only once for each function it appears in
> drivers/iio/accel/kionix-kx022a.c:507:54: error: expected ';' before 'return'
> 507 | if_not_cond_guard(iio_claim_direct_try, idev)
> | ^
> | ;
> 508 | return -EBUSY;
> | ~~~~~~
> In file included from drivers/iio/accel/kionix-kx022a.c:8:
> >> include/linux/cleanup.h:308:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
> 308 | for (CLASS(_name, scope)(args), \
> | ^~~
> drivers/iio/accel/kionix-kx022a.c:521:17: note: in expansion of macro 'scoped_guard'
> 521 | scoped_guard(mutex, &data->mutex) {
> | ^~~~~~~~~~~~
> drivers/iio/accel/kionix-kx022a.c:532:9: note: here
> 532 | case IIO_CHAN_INFO_SCALE:
> | ^~~~
>
The precursor is coming through tip as I understand it.
I'll have to hold off on applying this until after rc1.
>
> vim +308 include/linux/cleanup.h
>
> e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 306
> 54da6a0924311c Peter Zijlstra 2023-05-26 307 #define scoped_guard(_name, args...) \
> 54da6a0924311c Peter Zijlstra 2023-05-26 @308 for (CLASS(_name, scope)(args), \
> e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 309 *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1)
> e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 310
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
2024-11-28 17:20 ` kernel test robot
@ 2024-11-28 17:31 ` kernel test robot
2024-11-28 17:52 ` kernel test robot
2024-11-30 18:15 ` Jonathan Cameron
3 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2024-11-28 17:31 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: llvm, oe-kbuild-all, Jonathan Cameron, Lars-Peter Clausen,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-iio,
devicetree, linux-kernel
Hi Matti,
kernel test robot noticed the following build errors:
[auto build test ERROR on a61ff7eac77e86de828fe28c4e42b8ae9ec2b195]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-accel-kx022a-Use-cleanup-h-helpers/20241128-170626
base: a61ff7eac77e86de828fe28c4e42b8ae9ec2b195
patch link: https://lore.kernel.org/r/9b63813ecf10b1cd0126cb950bc09514c4287b9a.1732783834.git.mazziesaccount%40gmail.com
patch subject: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
config: i386-buildonly-randconfig-003-20241128 (https://download.01.org/0day-ci/archive/20241129/202411290140.7k2Z9JSi-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241129/202411290140.7k2Z9JSi-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411290140.7k2Z9JSi-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/iio/accel/kionix-kx022a.c:17:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:21:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> drivers/iio/accel/kionix-kx022a.c:507:2: error: call to undeclared function 'if_not_cond_guard'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^
>> drivers/iio/accel/kionix-kx022a.c:507:47: error: expected ';' after expression
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^
| ;
>> drivers/iio/accel/kionix-kx022a.c:507:20: error: use of undeclared identifier 'iio_claim_direct_try'
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^
1 warning and 3 errors generated.
vim +/if_not_cond_guard +507 drivers/iio/accel/kionix-kx022a.c
490
491 static int kx022a_write_raw(struct iio_dev *idev,
492 struct iio_chan_spec const *chan,
493 int val, int val2, long mask)
494 {
495 struct kx022a_data *data = iio_priv(idev);
496 int ret, n;
497
498 /*
499 * We should not allow changing scale or frequency when FIFO is running
500 * as it will mess the timestamp/scale for samples existing in the
501 * buffer. If this turns out to be an issue we can later change logic
502 * to internally flush the fifo before reconfiguring so the samples in
503 * fifo keep matching the freq/scale settings. (Such setup could cause
504 * issues if users trust the watermark to be reached within known
505 * time-limit).
506 */
> 507 if_not_cond_guard(iio_claim_direct_try, idev)
508 return -EBUSY;
509
510 switch (mask) {
511 case IIO_CHAN_INFO_SAMP_FREQ:
512 n = ARRAY_SIZE(kx022a_accel_samp_freq_table);
513
514 while (n--)
515 if (val == kx022a_accel_samp_freq_table[n][0] &&
516 val2 == kx022a_accel_samp_freq_table[n][1])
517 break;
518 if (n < 0)
519 return -EINVAL;
520
521 scoped_guard(mutex, &data->mutex) {
522 ret = kx022a_turn_on_off(data, false);
523 if (ret)
524 return ret;
525
526 ret = regmap_update_bits(data->regmap,
527 data->chip_info->odcntl,
528 KX022A_MASK_ODR, n);
529 data->odr_ns = kx022a_odrs[n];
530 return kx022a_turn_on_off(data, true);
531 }
532 case IIO_CHAN_INFO_SCALE:
533 n = data->chip_info->scale_table_size / 2;
534
535 while (n-- > 0)
536 if (val == data->chip_info->scale_table[n][0] &&
537 val2 == data->chip_info->scale_table[n][1])
538 break;
539 if (n < 0)
540 return -EINVAL;
541
542 scoped_guard(mutex, &data->mutex) {
543 ret = kx022a_turn_on_off(data, false);
544 if (ret)
545 return ret;
546
547 ret = regmap_update_bits(data->regmap,
548 data->chip_info->cntl,
549 KX022A_MASK_GSEL,
550 n << KX022A_GSEL_SHIFT);
551 kx022a_turn_on_off(data, true);
552
553 return ret;
554 }
555 default:
556 break;
557 }
558
559 return -EINVAL;
560 }
561
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
2024-11-28 17:20 ` kernel test robot
2024-11-28 17:31 ` kernel test robot
@ 2024-11-28 17:52 ` kernel test robot
2024-11-30 18:15 ` Jonathan Cameron
3 siblings, 0 replies; 20+ messages in thread
From: kernel test robot @ 2024-11-28 17:52 UTC (permalink / raw)
To: Matti Vaittinen, Matti Vaittinen
Cc: oe-kbuild-all, Jonathan Cameron, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
Hi Matti,
kernel test robot noticed the following build errors:
[auto build test ERROR on a61ff7eac77e86de828fe28c4e42b8ae9ec2b195]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-accel-kx022a-Use-cleanup-h-helpers/20241128-170626
base: a61ff7eac77e86de828fe28c4e42b8ae9ec2b195
patch link: https://lore.kernel.org/r/9b63813ecf10b1cd0126cb950bc09514c4287b9a.1732783834.git.mazziesaccount%40gmail.com
patch subject: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
config: x86_64-buildonly-randconfig-004-20241128 (https://download.01.org/0day-ci/archive/20241129/202411290148.Jdoj8IqZ-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241129/202411290148.Jdoj8IqZ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411290148.Jdoj8IqZ-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/iio/accel/kionix-kx022a.c: In function 'kx022a_write_raw':
>> drivers/iio/accel/kionix-kx022a.c:507:9: error: implicit declaration of function 'if_not_cond_guard' [-Werror=implicit-function-declaration]
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^~~~~~~~~~~~~~~~~
>> drivers/iio/accel/kionix-kx022a.c:507:27: error: 'iio_claim_direct_try' undeclared (first use in this function); did you mean 'class_iio_claim_direct_try_t'?
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^~~~~~~~~~~~~~~~~~~~
| class_iio_claim_direct_try_t
drivers/iio/accel/kionix-kx022a.c:507:27: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/iio/accel/kionix-kx022a.c:507:54: error: expected ';' before 'return'
507 | if_not_cond_guard(iio_claim_direct_try, idev)
| ^
| ;
508 | return -EBUSY;
| ~~~~~~
In file included from drivers/iio/accel/kionix-kx022a.c:8:
include/linux/cleanup.h:308:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
308 | for (CLASS(_name, scope)(args), \
| ^~~
drivers/iio/accel/kionix-kx022a.c:521:17: note: in expansion of macro 'scoped_guard'
521 | scoped_guard(mutex, &data->mutex) {
| ^~~~~~~~~~~~
drivers/iio/accel/kionix-kx022a.c:532:9: note: here
532 | case IIO_CHAN_INFO_SCALE:
| ^~~~
cc1: some warnings being treated as errors
vim +/if_not_cond_guard +507 drivers/iio/accel/kionix-kx022a.c
490
491 static int kx022a_write_raw(struct iio_dev *idev,
492 struct iio_chan_spec const *chan,
493 int val, int val2, long mask)
494 {
495 struct kx022a_data *data = iio_priv(idev);
496 int ret, n;
497
498 /*
499 * We should not allow changing scale or frequency when FIFO is running
500 * as it will mess the timestamp/scale for samples existing in the
501 * buffer. If this turns out to be an issue we can later change logic
502 * to internally flush the fifo before reconfiguring so the samples in
503 * fifo keep matching the freq/scale settings. (Such setup could cause
504 * issues if users trust the watermark to be reached within known
505 * time-limit).
506 */
> 507 if_not_cond_guard(iio_claim_direct_try, idev)
508 return -EBUSY;
509
510 switch (mask) {
511 case IIO_CHAN_INFO_SAMP_FREQ:
512 n = ARRAY_SIZE(kx022a_accel_samp_freq_table);
513
514 while (n--)
515 if (val == kx022a_accel_samp_freq_table[n][0] &&
516 val2 == kx022a_accel_samp_freq_table[n][1])
517 break;
518 if (n < 0)
519 return -EINVAL;
520
521 scoped_guard(mutex, &data->mutex) {
522 ret = kx022a_turn_on_off(data, false);
523 if (ret)
524 return ret;
525
526 ret = regmap_update_bits(data->regmap,
527 data->chip_info->odcntl,
528 KX022A_MASK_ODR, n);
529 data->odr_ns = kx022a_odrs[n];
530 return kx022a_turn_on_off(data, true);
531 }
532 case IIO_CHAN_INFO_SCALE:
533 n = data->chip_info->scale_table_size / 2;
534
535 while (n-- > 0)
536 if (val == data->chip_info->scale_table[n][0] &&
537 val2 == data->chip_info->scale_table[n][1])
538 break;
539 if (n < 0)
540 return -EINVAL;
541
542 scoped_guard(mutex, &data->mutex) {
543 ret = kx022a_turn_on_off(data, false);
544 if (ret)
545 return ret;
546
547 ret = regmap_update_bits(data->regmap,
548 data->chip_info->cntl,
549 KX022A_MASK_GSEL,
550 n << KX022A_GSEL_SHIFT);
551 kx022a_turn_on_off(data, true);
552
553 return ret;
554 }
555 default:
556 break;
557 }
558
559 return -EINVAL;
560 }
561
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-28 9:03 ` [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way Matti Vaittinen
` (2 preceding siblings ...)
2024-11-28 17:52 ` kernel test robot
@ 2024-11-30 18:15 ` Jonathan Cameron
2024-11-30 18:26 ` Jonathan Cameron
3 siblings, 1 reply; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:15 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On Thu, 28 Nov 2024 11:03:40 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> Many of the Kionix/ROHM accelerometers have a "PC1 - bit" which enables
> the accelerometer. While a sensor configuration like ODR, g-range, FIFO
> status etc. are changed, the PC1 bit must be cleared (sensor must be
> disabled). (See the description for different CNTL registers [1])
>
> In order to ensure this the kx022a driver uses a mutex, which is locked
> when the PC1 bit is cleared, and held for the duration of the
> configuration, and released after PC1 bit is set again (enabling the
> sensor).
>
> The locking and PC1 bit toggling was implemented using functions:
> kx022a_turn_off_lock() and kx022a_turn_on_unlock().
>
> Based on a discussions [2], the IIO subsystem prefers open-coding the
> locking with scoped_guard() over these functions.
>
> Drop the kx022a_turn_off_lock() and kx022a_turn_on_unlock() and use
> scoped_guard() instead.
>
> [1]: https://fscdn.rohm.com/kionix/en/datasheet/kx022acr-z-e.pdf
> [2]: https://lore.kernel.org/all/20241126175550.4a8bedf3@jic23-huawei/
>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
> ---
> Revision history:
> v2 => v3:
> - New patch
>
> NOTE: This patch uses the if_not_cond_guard() which is currently missing
> the iio_testing.
> https://lore.kernel.org/all/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com/T/#m69982b23da9f71e72d84855b34e9b142cb3a1920
Looks good to me. If no one else comments, I'll pick this up when
I have the precursor available (so hopefully just after rc1)
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-30 18:15 ` Jonathan Cameron
@ 2024-11-30 18:26 ` Jonathan Cameron
2024-12-02 6:46 ` Matti Vaittinen
0 siblings, 1 reply; 20+ messages in thread
From: Jonathan Cameron @ 2024-11-30 18:26 UTC (permalink / raw)
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On Sat, 30 Nov 2024 18:15:06 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> On Thu, 28 Nov 2024 11:03:40 +0200
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
> > Many of the Kionix/ROHM accelerometers have a "PC1 - bit" which enables
> > the accelerometer. While a sensor configuration like ODR, g-range, FIFO
> > status etc. are changed, the PC1 bit must be cleared (sensor must be
> > disabled). (See the description for different CNTL registers [1])
> >
> > In order to ensure this the kx022a driver uses a mutex, which is locked
> > when the PC1 bit is cleared, and held for the duration of the
> > configuration, and released after PC1 bit is set again (enabling the
> > sensor).
> >
> > The locking and PC1 bit toggling was implemented using functions:
> > kx022a_turn_off_lock() and kx022a_turn_on_unlock().
> >
> > Based on a discussions [2], the IIO subsystem prefers open-coding the
> > locking with scoped_guard() over these functions.
> >
> > Drop the kx022a_turn_off_lock() and kx022a_turn_on_unlock() and use
> > scoped_guard() instead.
> >
> > [1]: https://fscdn.rohm.com/kionix/en/datasheet/kx022acr-z-e.pdf
> > [2]: https://lore.kernel.org/all/20241126175550.4a8bedf3@jic23-huawei/
> >
> > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> >
> > ---
> > Revision history:
> > v2 => v3:
> > - New patch
> >
> > NOTE: This patch uses the if_not_cond_guard() which is currently missing
> > the iio_testing.
> > https://lore.kernel.org/all/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com/T/#m69982b23da9f71e72d84855b34e9b142cb3a1920
>
> Looks good to me. If no one else comments, I'll pick this up when
> I have the precursor available (so hopefully just after rc1)
or maybe not.
https://lore.kernel.org/all/CAHk-=whn07tnDosPfn+UcAtWHBcLg=KqA16SHVv0GV4t8P1fHw@mail.gmail.com/
Seems Linus is unconvinced.
Hmmm. We might have to roll back the uses of cond_guard() entirely.
Which will be a pain. Ah well. Sometimes an idea turns out to not be as useful
as it initially seemed.
46 instances to get rid of in the tree today...
Jonathan
>
> Thanks,
>
> Jonathan
>
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v3 7/7] iio: accel: kx022a: align with subsystem way
2024-11-30 18:26 ` Jonathan Cameron
@ 2024-12-02 6:46 ` Matti Vaittinen
0 siblings, 0 replies; 20+ messages in thread
From: Matti Vaittinen @ 2024-12-02 6:46 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Matti Vaittinen, Lars-Peter Clausen, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-iio, devicetree,
linux-kernel
On 30/11/2024 20:26, Jonathan Cameron wrote:
> On Sat, 30 Nov 2024 18:15:06 +0000
> Jonathan Cameron <jic23@kernel.org> wrote:
>
>> On Thu, 28 Nov 2024 11:03:40 +0200
>> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>>
>>> Many of the Kionix/ROHM accelerometers have a "PC1 - bit" which enables
>>> the accelerometer. While a sensor configuration like ODR, g-range, FIFO
>>> status etc. are changed, the PC1 bit must be cleared (sensor must be
>>> disabled). (See the description for different CNTL registers [1])
>>>
>>> In order to ensure this the kx022a driver uses a mutex, which is locked
>>> when the PC1 bit is cleared, and held for the duration of the
>>> configuration, and released after PC1 bit is set again (enabling the
>>> sensor).
>>>
>>> The locking and PC1 bit toggling was implemented using functions:
>>> kx022a_turn_off_lock() and kx022a_turn_on_unlock().
>>>
>>> Based on a discussions [2], the IIO subsystem prefers open-coding the
>>> locking with scoped_guard() over these functions.
>>>
>>> Drop the kx022a_turn_off_lock() and kx022a_turn_on_unlock() and use
>>> scoped_guard() instead.
>>>
>>> [1]: https://fscdn.rohm.com/kionix/en/datasheet/kx022acr-z-e.pdf
>>> [2]: https://lore.kernel.org/all/20241126175550.4a8bedf3@jic23-huawei/
>>>
>>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>>>
>>> ---
>>> Revision history:
>>> v2 => v3:
>>> - New patch
>>>
>>> NOTE: This patch uses the if_not_cond_guard() which is currently missing
>>> the iio_testing.
>>> https://lore.kernel.org/all/20241001-cleanup-if_not_cond_guard-v1-1-7753810b0f7a@baylibre.com/T/#m69982b23da9f71e72d84855b34e9b142cb3a1920
>>
>> Looks good to me. If no one else comments, I'll pick this up when
>> I have the precursor available (so hopefully just after rc1)
> or maybe not.
> https://lore.kernel.org/all/CAHk-=whn07tnDosPfn+UcAtWHBcLg=KqA16SHVv0GV4t8P1fHw@mail.gmail.com/
>
> Seems Linus is unconvinced.
> Hmmm. We might have to roll back the uses of cond_guard() entirely.
> Which will be a pain. Ah well. Sometimes an idea turns out to not be as useful
> as it initially seemed.
> 46 instances to get rid of in the tree today...
Ouch! :( Sorry to hear Jonathan.
Yours,
-- Matti
^ permalink raw reply [flat|nested] 20+ messages in thread