From: Jonathan Cameron <jic23@kernel.org>
To: "Ondřej Jirman" <megi@xff.cz>
Cc: linux-kernel@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Andrey Skvortsov <andrej.skvortzov@gmail.com>,
Icenowy Zheng <icenowy@aosc.io>,
Dalton Durst <dalton@ubports.com>,
Shoji Keita <awaittrot@shjk.jp>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 3/4] iio: magnetometer: add a driver for Voltafield AF8133J magnetometer
Date: Sun, 25 Feb 2024 12:07:00 +0000 [thread overview]
Message-ID: <20240225120700.2a0da3f6@jic23-huawei> (raw)
In-Reply-To: <20240222011341.3232645-4-megi@xff.cz>
On Thu, 22 Feb 2024 02:13:37 +0100
Ondřej Jirman <megi@xff.cz> wrote:
> From: Icenowy Zheng <icenowy@aosc.io>
>
> AF8133J is a simple I2C-connected magnetometer, without interrupts.
>
> Add a simple IIO driver for it.
>
> Co-developed-by: Icenowy Zheng <icenowy@aosc.io>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Check patch correct moaned that Icenowy is the author (from:)
so doesn't need a co-developed.
> Signed-off-by: Dalton Durst <dalton@ubports.com>
> Signed-off-by: Shoji Keita <awaittrot@shjk.jp>
> Co-developed-by: Ondrej Jirman <megi@xff.cz>
> Signed-off-by: Ondrej Jirman <megi@xff.cz>
> Reviewed-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
> Tested-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
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).
> +};
next prev parent reply other threads:[~2024-02-25 12:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 1:13 [PATCH v4 0/4] Add support for AF8133J magnetometer Ondřej Jirman
2024-02-22 1:13 ` [PATCH v4 1/4] dt-bindings: vendor-prefix: Add prefix for Voltafield Ondřej Jirman
2024-02-22 1:13 ` [PATCH v4 2/4] dt-bindings: iio: magnetometer: Add Voltafield AF8133J Ondřej Jirman
2024-02-22 1:13 ` [PATCH v4 3/4] iio: magnetometer: add a driver for Voltafield AF8133J magnetometer Ondřej Jirman
2024-02-23 12:48 ` Andrey Skvortsov
2024-02-25 12:07 ` Jonathan Cameron [this message]
2024-02-25 21:52 ` Ondřej Jirman
2024-02-25 12:08 ` Jonathan Cameron
2024-02-22 1:13 ` [PATCH v4 4/4] MAINTAINERS: Add an entry for AF8133J driver Ondřej Jirman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240225120700.2a0da3f6@jic23-huawei \
--to=jic23@kernel.org \
--cc=andrej.skvortzov@gmail.com \
--cc=awaittrot@shjk.jp \
--cc=conor+dt@kernel.org \
--cc=dalton@ubports.com \
--cc=devicetree@vger.kernel.org \
--cc=icenowy@aosc.io \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=megi@xff.cz \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox