All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability
@ 2023-01-18  7:42 carlos.song
  2023-01-18  7:42 ` [PATCH v5 1/4] iio: imu: fxos8700: fix incorrect ODR mode readback carlos.song
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: carlos.song @ 2023-01-18  7:42 UTC (permalink / raw)
  To: jic23, lars
  Cc: rjones, Jonathan.Cameron, haibo.chen, carlos.song, linux-imx, linux-iio

From: Carlos Song <carlos.song@nxp.com>

Hi, Jonathan. Thank you for the suggestion. In patch 1, I use
regmap_write to modify the value of the register. And in patch 2,
I use regmap_update_bits instead of regmap_get and regmap_write
for a good readability. Other patches have not been changed.

Carlos Song (4):
  iio: imu: fxos8700: fix incorrect ODR mode readback
  iio: imu: fxos8700: fix failed initialization ODR mode assignment
  iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN
  iio: imu: fxos8700: fix MAGN sensor scale and unit

 drivers/iio/imu/fxos8700_core.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

-- 
2.34.1


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

* [PATCH v5 1/4] iio: imu: fxos8700: fix incorrect ODR mode readback
  2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
@ 2023-01-18  7:42 ` carlos.song
  2023-01-18  7:42 ` [PATCH v5 2/4] iio: imu: fxos8700: fix failed initialization ODR mode assignment carlos.song
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: carlos.song @ 2023-01-18  7:42 UTC (permalink / raw)
  To: jic23, lars
  Cc: rjones, Jonathan.Cameron, haibo.chen, carlos.song, linux-imx, linux-iio

From: Carlos Song <carlos.song@nxp.com>

The absence of a correct offset leads an incorrect ODR mode
readback after use a hexadecimal number to mark the value from
FXOS8700_CTRL_REG1.

Get ODR mode by field mask and FIELD_GET clearly and conveniently.
And attach other additional fix for keeping the original code logic
and a good readability.

Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
---
Changes for V5:
- Correctly use regmap_write and FIELD_PREP to modify ODR value and
  activate device in FXOS8700_CTRL_REG1.
Changes for V4:
- Use ODR_MSK in the first place that merged the first two patches
  in V3 into this patch.
- Rework commit log
Changes for V3:
- Remove FXOS8700_CTRL_ODR_GENMSK and set FXOS8700_CTRL_ODR_MSK a
  field mask
- Legal use of filed mask and FIELD_PREP() to select ODR mode
- Rework commit log
---
 drivers/iio/imu/fxos8700_core.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
index 773f62203bf0..419039d3fe86 100644
--- a/drivers/iio/imu/fxos8700_core.c
+++ b/drivers/iio/imu/fxos8700_core.c
@@ -10,6 +10,7 @@
 #include <linux/regmap.h>
 #include <linux/acpi.h>
 #include <linux/bitops.h>
+#include <linux/bitfield.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -144,9 +145,9 @@
 #define FXOS8700_NVM_DATA_BNK0      0xa7
 
 /* Bit definitions for FXOS8700_CTRL_REG1 */
-#define FXOS8700_CTRL_ODR_MSK       0x38
 #define FXOS8700_CTRL_ODR_MAX       0x00
 #define FXOS8700_CTRL_ODR_MIN       GENMASK(4, 3)
+#define FXOS8700_CTRL_ODR_MSK       GENMASK(5, 3)
 
 /* Bit definitions for FXOS8700_M_CTRL_REG1 */
 #define FXOS8700_HMS_MASK           GENMASK(1, 0)
@@ -508,10 +509,9 @@ static int fxos8700_set_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
 	if (i >= odr_num)
 		return -EINVAL;
 
-	return regmap_update_bits(data->regmap,
-				  FXOS8700_CTRL_REG1,
-				  FXOS8700_CTRL_ODR_MSK + FXOS8700_ACTIVE,
-				  fxos8700_odr[i].bits << 3 | active_mode);
+	val &= ~FXOS8700_CTRL_ODR_MSK;
+	val |= FIELD_PREP(FXOS8700_CTRL_ODR_MSK, fxos8700_odr[i].bits) | FXOS8700_ACTIVE;
+	return regmap_write(data->regmap, FXOS8700_CTRL_REG1, val);
 }
 
 static int fxos8700_get_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
@@ -524,7 +524,7 @@ static int fxos8700_get_odr(struct fxos8700_data *data, enum fxos8700_sensor t,
 	if (ret)
 		return ret;
 
-	val &= FXOS8700_CTRL_ODR_MSK;
+	val = FIELD_GET(FXOS8700_CTRL_ODR_MSK, val);
 
 	for (i = 0; i < odr_num; i++)
 		if (val == fxos8700_odr[i].bits)
-- 
2.34.1


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

* [PATCH v5 2/4] iio: imu: fxos8700: fix failed initialization ODR mode assignment
  2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
  2023-01-18  7:42 ` [PATCH v5 1/4] iio: imu: fxos8700: fix incorrect ODR mode readback carlos.song
@ 2023-01-18  7:42 ` carlos.song
  2023-01-18  7:42 ` [PATCH v5 3/4] iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN carlos.song
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: carlos.song @ 2023-01-18  7:42 UTC (permalink / raw)
  To: jic23, lars
  Cc: rjones, Jonathan.Cameron, haibo.chen, carlos.song, linux-imx, linux-iio

From: Carlos Song <carlos.song@nxp.com>

The absence of correct offset leads a failed initialization ODR mode
assignment.

Select MAX ODR mode as the initialization ODR mode by field mask and
FIELD_PREP.

Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
---
Changes for V5:
- Use regmap_update_bits instead of regmap_get and regmap_write for
  a good readability.
Changes for V4:
- None
Changes for V3:
- Legal use of FIELD_PREP() and field mask to select initialization
  ODR mode
- Rework commit log
---
 drivers/iio/imu/fxos8700_core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
index 419039d3fe86..12433343807a 100644
--- a/drivers/iio/imu/fxos8700_core.c
+++ b/drivers/iio/imu/fxos8700_core.c
@@ -664,8 +664,10 @@ static int fxos8700_chip_init(struct fxos8700_data *data, bool use_spi)
 		return ret;
 
 	/* Max ODR (800Hz individual or 400Hz hybrid), active mode */
-	return regmap_write(data->regmap, FXOS8700_CTRL_REG1,
-			   FXOS8700_CTRL_ODR_MAX | FXOS8700_ACTIVE);
+	return regmap_update_bits(data->regmap, FXOS8700_CTRL_REG1,
+				FXOS8700_CTRL_ODR_MSK | FXOS8700_ACTIVE,
+				FIELD_PREP(FXOS8700_CTRL_ODR_MSK, FXOS8700_CTRL_ODR_MAX) |
+				FXOS8700_ACTIVE);
 }
 
 static void fxos8700_chip_uninit(void *data)
-- 
2.34.1


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

* [PATCH v5 3/4] iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN
  2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
  2023-01-18  7:42 ` [PATCH v5 1/4] iio: imu: fxos8700: fix incorrect ODR mode readback carlos.song
  2023-01-18  7:42 ` [PATCH v5 2/4] iio: imu: fxos8700: fix failed initialization ODR mode assignment carlos.song
@ 2023-01-18  7:42 ` carlos.song
  2023-01-18  7:42 ` [PATCH v5 4/4] iio: imu: fxos8700: fix MAGN sensor scale and unit carlos.song
  2023-01-21 18:15 ` [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability Jonathan Cameron
  4 siblings, 0 replies; 6+ messages in thread
From: carlos.song @ 2023-01-18  7:42 UTC (permalink / raw)
  To: jic23, lars
  Cc: rjones, Jonathan.Cameron, haibo.chen, carlos.song, linux-imx, linux-iio

From: Carlos Song <carlos.song@nxp.com>

FXOS8700_CTRL_ODR_MIN is not used but value is probably wrong.

Remove it for a good readability.

Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
---
Changes for V5:
- None
Changes for V4:
- None
Changes for V3:
- Proposed a separate clean fix
---
 drivers/iio/imu/fxos8700_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
index 12433343807a..44e4befcf3f0 100644
--- a/drivers/iio/imu/fxos8700_core.c
+++ b/drivers/iio/imu/fxos8700_core.c
@@ -146,7 +146,6 @@
 
 /* Bit definitions for FXOS8700_CTRL_REG1 */
 #define FXOS8700_CTRL_ODR_MAX       0x00
-#define FXOS8700_CTRL_ODR_MIN       GENMASK(4, 3)
 #define FXOS8700_CTRL_ODR_MSK       GENMASK(5, 3)
 
 /* Bit definitions for FXOS8700_M_CTRL_REG1 */
-- 
2.34.1


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

* [PATCH v5 4/4] iio: imu: fxos8700: fix MAGN sensor scale and unit
  2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
                   ` (2 preceding siblings ...)
  2023-01-18  7:42 ` [PATCH v5 3/4] iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN carlos.song
@ 2023-01-18  7:42 ` carlos.song
  2023-01-21 18:15 ` [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability Jonathan Cameron
  4 siblings, 0 replies; 6+ messages in thread
From: carlos.song @ 2023-01-18  7:42 UTC (permalink / raw)
  To: jic23, lars
  Cc: rjones, Jonathan.Cameron, haibo.chen, carlos.song, linux-imx, linux-iio

From: Carlos Song <carlos.song@nxp.com>

+/-1200uT is a MAGN sensor full measurement range. Magnetometer scale
is the magnetic sensitivity parameter. It is referenced as 0.1uT
according to datasheet and magnetometer channel unit is Gauss in
sysfs-bus-iio documentation. Gauss and uTesla unit conversion
relationship as follows: 0.1uT = 0.001Gs.

Set magnetometer scale and available magnetometer scale as fixed 0.001Gs.

Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
---
Changes for V5:
- None
Changes for V4:
- None
Changes for V3:
- Modify the magnetometer sensitivity unit "g" to standard unit "Gs"
- Check and confirm uscale value is correct. The readback of
  MAGN scale is 0.001 Gs
- Rework commit log
Changes for V2:
- Modify the magnetometer sensitivity unit to be consistent with the
  documentation as 0.001g
- Rework commit log
---
 drivers/iio/imu/fxos8700_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
index 44e4befcf3f0..939f6069ef4c 100644
--- a/drivers/iio/imu/fxos8700_core.c
+++ b/drivers/iio/imu/fxos8700_core.c
@@ -351,7 +351,7 @@ static int fxos8700_set_scale(struct fxos8700_data *data,
 	struct device *dev = regmap_get_device(data->regmap);
 
 	if (t == FXOS8700_MAGN) {
-		dev_err(dev, "Magnetometer scale is locked at 1200uT\n");
+		dev_err(dev, "Magnetometer scale is locked at 0.001Gs\n");
 		return -EINVAL;
 	}
 
@@ -396,7 +396,7 @@ static int fxos8700_get_scale(struct fxos8700_data *data,
 	static const int scale_num = ARRAY_SIZE(fxos8700_accel_scale);
 
 	if (t == FXOS8700_MAGN) {
-		*uscale = 1200; /* Magnetometer is locked at 1200uT */
+		*uscale = 1000; /* Magnetometer is locked at 0.001Gs */
 		return 0;
 	}
 
@@ -588,7 +588,7 @@ static IIO_CONST_ATTR(in_accel_sampling_frequency_available,
 static IIO_CONST_ATTR(in_magn_sampling_frequency_available,
 		      "1.5625 6.25 12.5 50 100 200 400 800");
 static IIO_CONST_ATTR(in_accel_scale_available, "0.000244 0.000488 0.000976");
-static IIO_CONST_ATTR(in_magn_scale_available, "0.000001200");
+static IIO_CONST_ATTR(in_magn_scale_available, "0.001000");
 
 static struct attribute *fxos8700_attrs[] = {
 	&iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,
-- 
2.34.1


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

* Re: [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability
  2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
                   ` (3 preceding siblings ...)
  2023-01-18  7:42 ` [PATCH v5 4/4] iio: imu: fxos8700: fix MAGN sensor scale and unit carlos.song
@ 2023-01-21 18:15 ` Jonathan Cameron
  4 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2023-01-21 18:15 UTC (permalink / raw)
  To: carlos.song
  Cc: lars, rjones, Jonathan.Cameron, haibo.chen, linux-imx, linux-iio

On Wed, 18 Jan 2023 15:42:23 +0800
carlos.song@nxp.com wrote:

> From: Carlos Song <carlos.song@nxp.com>
> 
> Hi, Jonathan. Thank you for the suggestion. In patch 1, I use
> regmap_write to modify the value of the register. And in patch 2,
> I use regmap_update_bits instead of regmap_get and regmap_write
> for a good readability. Other patches have not been changed.
> 
> Carlos Song (4):
>   iio: imu: fxos8700: fix incorrect ODR mode readback
>   iio: imu: fxos8700: fix failed initialization ODR mode assignment
>   iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN
>   iio: imu: fxos8700: fix MAGN sensor scale and unit
> 
>  drivers/iio/imu/fxos8700_core.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 

Series applied to the fixes-togreg branch of iio.git and marked
for stable inclusion.

Thanks,

Jonathan

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

end of thread, other threads:[~2023-01-21 18:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18  7:42 [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability carlos.song
2023-01-18  7:42 ` [PATCH v5 1/4] iio: imu: fxos8700: fix incorrect ODR mode readback carlos.song
2023-01-18  7:42 ` [PATCH v5 2/4] iio: imu: fxos8700: fix failed initialization ODR mode assignment carlos.song
2023-01-18  7:42 ` [PATCH v5 3/4] iio: imu: fxos8700: remove definition FXOS8700_CTRL_ODR_MIN carlos.song
2023-01-18  7:42 ` [PATCH v5 4/4] iio: imu: fxos8700: fix MAGN sensor scale and unit carlos.song
2023-01-21 18:15 ` [PATCH v5 0/4] iio: imu: fxos8700: fix bugs about ODR and changes for a good readability Jonathan Cameron

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