Re: [PATCH v4 3/4] iio: magnetometer: add a driver for Voltafield AF8133J magnetometer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 22 Feb 2024 02:13:37 +0100
Ondřej Jirman <megi@xxxxxx> wrote:

> From: Icenowy Zheng <icenowy@xxxxxxx>
> 
> AF8133J is a simple I2C-connected magnetometer, without interrupts.
> 
> Add a simple IIO driver for it.
> 
> Co-developed-by: Icenowy Zheng <icenowy@xxxxxxx>
> Signed-off-by: Icenowy Zheng <icenowy@xxxxxxx>
Check patch correct moaned that Icenowy is the author (from:)
so doesn't need a co-developed.

> Signed-off-by: Dalton Durst <dalton@xxxxxxxxxxx>
> Signed-off-by: Shoji Keita <awaittrot@xxxxxxx>
> Co-developed-by: Ondrej Jirman <megi@xxxxxx>
> Signed-off-by: Ondrej Jirman <megi@xxxxxx>
> Reviewed-by: Andrey Skvortsov <andrej.skvortzov@xxxxxxxxx>
> Tested-by: Andrey Skvortsov <andrej.skvortzov@xxxxxxxxx>

Hi.

A few really minor things noticed during a final review.
I'll tweak them whilst applying.  Diff is

diff --git a/drivers/iio/magnetometer/af8133j.c b/drivers/iio/magnetometer/af8133j.c
index c75d545e152b..40657a08ce37 100644
--- a/drivers/iio/magnetometer/af8133j.c
+++ b/drivers/iio/magnetometer/af8133j.c
@@ -40,6 +40,10 @@ static const char * const af8133j_supply_names[] = {
 struct af8133j_data {
        struct i2c_client *client;
        struct regmap *regmap;
+       /*
+        * Protect device internal state between starting a measurement
+        * and reading the result.
+        */
        struct mutex mutex;
        struct iio_mount_matrix orientation;
 
@@ -107,8 +111,8 @@ static int af8133j_product_check(struct af8133j_data *data)
        }
 
        if (val != AF8133J_REG_PCODE_VAL) {
-               dev_err(dev, "Invalid product code (0x%02x)\n", val);
-               return -EINVAL;
+               dev_warn(dev, "Invalid product code (0x%02x)\n", val);
+               return 0; /* Allow unknown ID so fallback compatibles work */
        }
 
        return 0;
@@ -237,8 +241,8 @@ static int af8133j_read_measurement(struct af8133j_data *data, __le16 buf[3])
 }
 
 static const int af8133j_scales[][2] = {
-       [0] = { 0, 366210 }, // 12 gauss
-       [1] = { 0, 671386 }, // 22 gauss
+       [0] = { 0, 366210 }, /* 12 gauss */
+       [1] = { 0, 671386 }, /* 22 gauss */
 };


> diff --git a/drivers/iio/magnetometer/af8133j.c b/drivers/iio/magnetometer/af8133j.c
> new file mode 100644
> index 000000000000..c75d545e152b
> --- /dev/null
> +++ b/drivers/iio/magnetometer/af8133j.c

> +
> +struct af8133j_data {
> +	struct i2c_client *client;
> +	struct regmap *regmap;
> +	struct mutex mutex;

I thought checkpatch still moaned that every lock should have documentation.
I guess not.  However it's still a nice to have.

Here it seems this is about protecting device state between triggering a
measurement and getting the reading.

> +	struct iio_mount_matrix orientation;
> +
> +	struct gpio_desc *reset_gpiod;
> +	struct regulator_bulk_data supplies[ARRAY_SIZE(af8133j_supply_names)];
> +
> +	u8 range;
> +};

> +
> +static int af8133j_product_check(struct af8133j_data *data)
> +{
> +	struct device *dev = &data->client->dev;
> +	unsigned int val;
> +	int ret;
> +
> +	ret = regmap_read(data->regmap, AF8133J_REG_PCODE, &val);
> +	if (ret) {
> +		dev_err(dev, "Error reading product code (%d)\n", ret);
> +		return ret;
> +	}
> +
> +	if (val != AF8133J_REG_PCODE_VAL) {
> +		dev_err(dev, "Invalid product code (0x%02x)\n", val);
> +		return -EINVAL;

This should be warn only and we should carry on regardless.  The reason
behind this is to support fallback compatible values in DT to potentially enable
a newer device to be supported on an older kernel.

Many IIO drivers do this wrong as my understanding on what counted on
'compatible' used to be different.  Long discussions on this with the DT
maintainers led me to accept that letting ID checks fail was fine, but
that a message was appropriate.   Often a fail here actually means no device.
We have some exceptions to this rule for devices where we know the same
FW ids are in use in the wild for devices supported by different Linux
drivers - but those are thankfully rare!

> +	}
> +
> +	return 0;
> +}
> +
}

> +static const int af8133j_scales[][2] = {
> +	[0] = { 0, 366210 }, // 12 gauss
> +	[1] = { 0, 671386 }, // 22 gauss
Trivial so I'll fix it up: IIO comments are /* */
not C++ style (with exception of the SPDX stuff that needs to be).
> +};








[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux