Re: [PATCH v2 2/2] iio: light: add AS7343 multi-spectral sensor driver

From: Joshua Crofts

Date: Tue Sep 08 2026 - 04:12:15 EST


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@xxxxxxxxx> 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