diff mbox series

[4/4] iio: imu: fxos8700: fix magnetometer scale getting error

Message ID 20221202103538.2218925-5-carlos.song@nxp.com (mailing list archive)
State Changes Requested
Headers show
Series iio: imu: fxos8700: fix few bug in reading raw data and configuring register | expand

Commit Message

Carlos Song Dec. 2, 2022, 10:35 a.m. UTC
Incorrect iio channel type cause a magnetometer scale getting
error. Meanwhile magnetometer scale and available magnetometer
scale should be locked as 0.1uT according to the datasheet.

Set magn sensor type "IIO_MAGN" and modify magn_scale fixed "0.1uT".

Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
Signed-off-by: Carlos Song <carlos.song@nxp.com>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/iio/imu/fxos8700_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Jonathan Cameron Dec. 4, 2022, 3:27 p.m. UTC | #1
On Fri,  2 Dec 2022 18:35:38 +0800
Carlos Song <carlos.song@nxp.com> wrote:

> Incorrect iio channel type cause a magnetometer scale getting
> error. Meanwhile magnetometer scale and available magnetometer
> scale should be locked as 0.1uT according to the datasheet.
> 
> Set magn sensor type "IIO_MAGN" and modify magn_scale fixed "0.1uT".
> 
> Fixes: 84e5ddd5c46e ("iio: imu: Add support for the FXOS8700 IMU")
> Signed-off-by: Carlos Song <carlos.song@nxp.com>
> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> ---
>  drivers/iio/imu/fxos8700_core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
> index 27e3bd61d054..8d46462dca76 100644
> --- a/drivers/iio/imu/fxos8700_core.c
> +++ b/drivers/iio/imu/fxos8700_core.c
> @@ -319,7 +319,7 @@ static enum fxos8700_sensor fxos8700_to_sensor(enum iio_chan_type iio_type)
>  	switch (iio_type) {
>  	case IIO_ACCEL:
>  		return FXOS8700_ACCEL;
> -	case IIO_ANGL_VEL:
> +	case IIO_MAGN:

Ahah. This had me confused on looking at earlier patch ;)

Amusingly much of the code 'worked' because it was use as a boolean return
so -EINVAL had same affect as FXOS8700_MAGN.

This fix stands on it's own as a separate fix, so I'd rather see it in a
trivial patch of it's own before this one.


>  		return FXOS8700_MAGN;
>  	default:
>  		return -EINVAL;
> @@ -350,7 +350,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.1uT\n");
>  		return -EINVAL;
>  	}
>  
> @@ -393,7 +393,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 = 100000; /* Magnetometer scale is locked at 0.1 uT */
See Documentation/ABI/testing/sysfs-bus-iio
magnetometer channel units are Gauss. 
0.1ut = 0.001g so uscale should be 1000 I think with available changed to match.

>  		return 0;
>  	}
>  
> @@ -563,7 +563,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.100000")
>  
>  static struct attribute *fxos8700_attrs[] = {
>  	&iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,
diff mbox series

Patch

diff --git a/drivers/iio/imu/fxos8700_core.c b/drivers/iio/imu/fxos8700_core.c
index 27e3bd61d054..8d46462dca76 100644
--- a/drivers/iio/imu/fxos8700_core.c
+++ b/drivers/iio/imu/fxos8700_core.c
@@ -319,7 +319,7 @@  static enum fxos8700_sensor fxos8700_to_sensor(enum iio_chan_type iio_type)
 	switch (iio_type) {
 	case IIO_ACCEL:
 		return FXOS8700_ACCEL;
-	case IIO_ANGL_VEL:
+	case IIO_MAGN:
 		return FXOS8700_MAGN;
 	default:
 		return -EINVAL;
@@ -350,7 +350,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.1uT\n");
 		return -EINVAL;
 	}
 
@@ -393,7 +393,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 = 100000; /* Magnetometer scale is locked at 0.1 uT */
 		return 0;
 	}
 
@@ -563,7 +563,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.100000");
 
 static struct attribute *fxos8700_attrs[] = {
 	&iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,