Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Gustavo Silva <gustavograzs@gmail.com>, jic23@kernel.org
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	lars@metafoo.de, gerald.loacker@wolfvision.net,
	devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/6] iio: chemical: add driver for ENS160 sensor
Date: Mon, 13 May 2024 21:12:55 +0200	[thread overview]
Message-ID: <205163e0-e2bd-4ed9-9f51-e20468f77655@wanadoo.fr> (raw)
In-Reply-To: <20240512210444.30824-4-gustavograzs@gmail.com>

Le 12/05/2024 à 23:04, Gustavo Silva a écrit :
> ScioSense ENS160 is a digital metal oxide multi-gas sensor, designed
> for indoor air quality monitoring. The driver supports readings of
> CO2 and VOC, and can be accessed via both SPI and I2C.
> 
> Signed-off-by: Gustavo Silva <gustavograzs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---

Hi,
a few comments below, for what it worth.

BTW, why I'm in copy of the mail?
I'm not a maintainer, and not active on drivers/iio/chemical/
Slightly proud, but curious as well.

...

> +#define ENS160_REG_TEMP_IN		0x13
> +#define ENS160_REG_RH_IN		0x15
> +#define ENS160_REG_DEVICE_STATUS	0x20

If defining everything, maybe:
#define ENS160_REG_DATA_AQI	0x21

> +#define ENS160_REG_DATA_TVOC		0x22
> +#define ENS160_REG_DATA_ECO2		0x24
> +#define ENS160_REG_DATA_T		0x30
> +#define ENS160_REG_DATA_RH		0x32
> +#define ENS160_REG_GPR_READ4		0x4C

...

> +static int ens160_chip_init(struct ens160_data *data)
> +{
> +	struct device *dev = regmap_get_device(data->regmap);
> +	u8 fw_version[3];
> +	__le16 part_id;
> +	unsigned int status;
> +	int ret;
> +
> +	ret = ens160_set_mode(data, ENS160_REG_MODE_RESET);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_bulk_read(data->regmap, ENS160_REG_PART_ID, &part_id,
> +			       sizeof(part_id));
> +	if (ret)
> +		return ret;
> +
> +	if (le16_to_cpu(part_id) != ENS160_PART_ID)
> +		return -ENODEV;
> +
> +	ret = ens160_set_mode(data, ENS160_REG_MODE_IDLE);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(data->regmap, ENS160_REG_COMMAND,
> +			   ENS160_REG_COMMAND_CLRGPR);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(data->regmap, ENS160_REG_COMMAND,
> +			   ENS160_REG_COMMAND_GET_APPVER);
> +	if (ret)
> +		return ret;
> +
> +	msleep(ENS160_BOOTING_TIME_MS);
> +
> +	ret = regmap_bulk_read(data->regmap, ENS160_REG_GPR_READ4,
> +			       fw_version, sizeof(fw_version));
> +	if (ret)
> +		return ret;
> +
> +	msleep(ENS160_BOOTING_TIME_MS);
> +
> +	dev_info(dev, "firmware version: %u.%u.%u\n", fw_version[2],
> +		 fw_version[1], fw_version[0]);
> +
> +	ret = ens160_set_mode(data, ENS160_REG_MODE_STANDARD);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_read(data->regmap, ENS160_REG_DEVICE_STATUS, &status);
> +	if (ret)
> +		return ret;
> +
> +	if (FIELD_GET(ENS160_STATUS_VALIDITY_FLAG, status)
> +	    != ENS160_STATUS_NORMAL)
> +		return -EINVAL;

Just wondering how it works with the Warm-up and initial Start-up times.
If the probe is executed and the corresponding duration has not elpased, 
then the probe fails.

Is it what is expected?

> +
> +	return 0;
> +}
> +
> +static const struct iio_info ens160_info = {
> +	.read_raw = ens160_read_raw,
> +};
> +
> +int ens160_core_probe(struct device *dev, struct regmap *regmap,
> +		      const char *name)
> +{
> +	struct ens160_data *data;
> +	struct iio_dev *indio_dev;
> +	int ret;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	data = iio_priv(indio_dev);
> +	dev_set_drvdata(dev, indio_dev);
> +	data->regmap = regmap;
> +
> +	indio_dev->name = name;
> +	indio_dev->info = &ens160_info;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->channels = ens160_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(ens160_channels);
> +
> +	ret = ens160_chip_init(data);
> +	if (ret) {
> +		dev_err_probe(dev, ret, "chip initialization failed\n");

Nitpick: return dev_err_probe()

> +		return ret;
> +	}
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}

...

> +static int ens160_i2c_probe(struct i2c_client *client)
> +{
> +	struct regmap *regmap;
> +
> +	regmap = devm_regmap_init_i2c(client, &ens160_regmap_i2c_conf);
> +	if (IS_ERR(regmap)) {
> +		dev_err(&client->dev, "Failed to register i2c regmap %ld\n",
> +			PTR_ERR(regmap));

Nitpick: dev_err_probe()

> +		return PTR_ERR(regmap);
> +	}

...

> +static int ens160_spi_probe(struct spi_device *spi)
> +{
> +	struct regmap *regmap;
> +	const struct spi_device_id *id = spi_get_device_id(spi);
> +
> +	regmap = devm_regmap_init_spi(spi, &ens160_regmap_spi_conf);
> +	if (IS_ERR(regmap)) {
> +		dev_err(&spi->dev, "Failed to register spi regmap: %pe\n",
> +			regmap);

Nitpick: dev_err_probe()

CJ

> +		return PTR_ERR(regmap);
> +	}
> +
> +	return ens160_core_probe(&spi->dev, regmap, id->name);
> +}



  reply	other threads:[~2024-05-13 19:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-12 21:04 [PATCH 0/6] Add driver for ENS160 sensor Gustavo Silva
2024-05-12 21:04 ` [PATCH 1/6] dt-bindings: vendor-prefixes: add ScioSense Gustavo Silva
2024-05-13 16:02   ` Conor Dooley
2024-05-12 21:04 ` [PATCH 2/6] dt-bindings: Add ENS160 as trivial device Gustavo Silva
2024-05-13 16:09   ` Conor Dooley
2024-05-19 12:33     ` Jonathan Cameron
2024-05-12 21:04 ` [PATCH 3/6] iio: chemical: add driver for ENS160 sensor Gustavo Silva
2024-05-13 19:12   ` Christophe JAILLET [this message]
2024-05-19 13:24     ` Jonathan Cameron
2024-05-22 23:41     ` Gustavo Silva
2024-05-19 14:01   ` Jonathan Cameron
2024-05-26  0:29     ` Gustavo Silva
2024-05-26 12:20       ` Jonathan Cameron
2024-05-12 21:04 ` [PATCH 4/6] iio: chemical: ens160: add triggered buffer support Gustavo Silva
2024-05-13 19:13   ` Christophe JAILLET
2024-05-19 14:03     ` Jonathan Cameron
2024-05-20  6:50       ` Christophe JAILLET
2024-05-13 23:50   ` kernel test robot
2024-05-19 14:18   ` Jonathan Cameron
2024-05-12 21:04 ` [PATCH 5/6] iio: chemical: ens160: add power management support Gustavo Silva
2024-05-19 14:18   ` Jonathan Cameron
2024-05-12 21:04 ` [PATCH 6/6] MAINTAINERS: Add ScioSense ENS160 Gustavo Silva

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=205163e0-e2bd-4ed9-9f51-e20468f77655@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gerald.loacker@wolfvision.net \
    --cc=gustavograzs@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).