From: Joshua Crofts <joshua.crofts1@gmail.com>
To: Chang Yu <marcus.yu.56@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, "Shi Hao" <i.shihao.999@gmail.com>,
"Jose A. Perez de Azpillaga" <azpijr@gmail.com>
Subject: Re: [PATCH v2 2/2] iio: light: add AS7343 multi-spectral sensor driver
Date: Tue, 8 Sep 2026 10:01:23 +0200 [thread overview]
Message-ID: <20260908100123.00005af7@gmail.com> (raw)
In-Reply-To: <20260907210042.32552-3-marcus.yu.56@gmail.com>
Hi Chang,
Please check out Sashiko's review, there are some PM runtime things that
should be resolved + some comments inline.
https://sashiko.dev/#/patchset/20260907210042.32552-1-marcus.yu.56%40gmail.com
Thanks!
Josh
On Mon, 7 Sep 2026 14:00:42 -0700
Chang Yu <marcus.yu.56@gmail.com> wrote:
...
> +#include <linux/array_size.h>
> +#include <linux/bitfield.h>
> +#include <linux/dev_printk.h>
> +#include <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/pm.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/sysfs.h>
+ bits.h, types.h, <asm/byteorder.h> (asm headers go separately, as IIO headers).
> +
> +#include <linux/iio/iio.h>
> +
...
> +struct as7343_data {
> + struct regmap *regmap;
> +};
> +
> +static int as7343_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
> +{
> + struct as7343_data *data = iio_priv(indio_dev);
> + int ret;
> + unsigned int unused;
> + u16 result;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW: {
The device should resume here, otherwise you'll be reading while suspended.
> + /*
> + * Reading ASTATUS latches all data registers to this read.
> + * We don't care about the returned saturation/gain status for
> + * now.
> + */
Sashiko points out that a mutex here would come in handy. If you're going to add
a mutex, use the guard(mutex) macro for automatic unlocking on scope exit.
> + ret = regmap_read(data->regmap, AS7343_ASTATUS, &unused);
> + if (ret)
> + return ret;
> +
> + ret = regmap_bulk_read(data->regmap, chan->address, &result, 2);
> + if (ret)
> + return ret;
> +
> + *val = le16_to_cpu(result);
> + return IIO_VAL_INT;
> + }
> +
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const char *as7343_channel_label(struct iio_chan_spec const *chan)
> +{
> + switch (chan->channel) {
> + case AS7343_CHAN_IDX_FZ:
> + return "FZ";
> + case AS7343_CHAN_IDX_FY:
> + return "FY";
> + case AS7343_CHAN_IDX_FXL:
> + return "FXL";
> + case AS7343_CHAN_IDX_NIR:
> + return "NIR";
> + case AS7343_CHAN_IDX_F2:
> + return "F2";
> + case AS7343_CHAN_IDX_F3:
> + return "F3";
> + case AS7343_CHAN_IDX_F4:
> + return "F4";
> + case AS7343_CHAN_IDX_F6:
> + return "F6";
> + case AS7343_CHAN_IDX_F1:
> + return "F1";
> + case AS7343_CHAN_IDX_F7:
> + return "F7";
> + case AS7343_CHAN_IDX_F8:
> + return "F8";
> + case AS7343_CHAN_IDX_F5:
> + return "F5";
> + default:
> + return NULL;
> + }
> +}
> +
> +static int as7343_read_label(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, char *label)
> +{
> + const char *name;
> +
> + name = as7343_channel_label(chan);
> + if (!name)
> + return -EINVAL;
A blank line here would be better.
> + return sysfs_emit(label, "%s\n", name);
> +}
> +
> +static const struct iio_info as7343_info = {
> + .read_raw = as7343_read_raw,
> + .read_label = as7343_read_label,
> +};
> +
> +static const struct regmap_config as7343_regmap_config = {
> + .name = "as7343",
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = AS7343_MAX,
> + .reg_format_endian = REGMAP_ENDIAN_LITTLE,
> + .val_format_endian = REGMAP_ENDIAN_LITTLE,
> + .cache_type = REGCACHE_NONE,
> +};
> +
> +static int as7343_setup_device(struct device *dev, struct as7343_data *data)
> +{
> + unsigned int val;
> + u16 step;
__le16 instead of u16.
> + int ret;
> +
> + /* Power on */
> + ret = regmap_set_bits(data->regmap, AS7343_ENABLE, AS7343_ENABLE_PON);
> + if (ret)
> + return ret;
> +
> + /* Need to set REG_BANK to 1 before we can access ID */
> + ret = regmap_set_bits(data->regmap, AS7343_CFG0, AS7343_CFG0_REG_BANK);
> + if (ret)
> + return ret;
> +
> + ret = regmap_read(data->regmap, AS7343_ID, &val);
You should check the value of ret as well in case of a regmap failure.
--
Kind regards,
Joshua Crofts
prev parent reply other threads:[~2026-09-08 8:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 21:00 [PATCH v2 0/2] Add support for AS7343 multi-spectral sensor Chang Yu
2026-09-07 21:00 ` [PATCH v2 1/2] dt-bindings: iio: light: add as7343 Chang Yu
2026-09-07 21:06 ` sashiko-bot
2026-09-08 18:13 ` Conor Dooley
2026-09-13 0:42 ` Jonathan Cameron
2026-09-07 21:00 ` [PATCH v2 2/2] iio: light: add AS7343 multi-spectral sensor driver Chang Yu
2026-09-07 21:10 ` sashiko-bot
2026-09-08 8:01 ` Joshua Crofts [this message]
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=20260908100123.00005af7@gmail.com \
--to=joshua.crofts1@gmail.com \
--cc=andy@kernel.org \
--cc=azpijr@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=i.shihao.999@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.yu.56@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh@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 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.