devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Ivan Mikhaylov <fr0st61te@gmail.com>
Cc: 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>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v5 2/2] iio: adc: Add driver support for MAX34408/9
Date: Tue, 10 Oct 2023 16:24:05 +0100	[thread overview]
Message-ID: <20231010162405.6d6f3c48@jic23-huawei> (raw)
In-Reply-To: <20231007234838.8748-3-fr0st61te@gmail.com>

On Sun,  8 Oct 2023 02:48:38 +0300
Ivan Mikhaylov <fr0st61te@gmail.com> wrote:

> The MAX34408/MAX34409 are two- and four-channel current monitors that are
> configured and monitored with a standard I2C/SMBus serial interface. Each
> unidirectional current sensor offers precision high-side operation with a
> low full-scale sense voltage. The devices automatically sequence through
> two or four channels and collect the current-sense samples and average them
> to reduce the effect of impulse noise. The raw ADC samples are compared to
> user-programmable digital thresholds to indicate overcurrent conditions.
> Overcurrent conditions trigger a hardware output to provide an immediate
> indication to shut down any necessary external circuitry.
> 
> Add as ADC driver which only supports current monitoring for now.
> 
> Link: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX34408-MAX34409.pdf
> 
Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX34408-MAX34409.pdf
> Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>

A few other comments inline.

Jonathan


> diff --git a/drivers/iio/adc/max34408.c b/drivers/iio/adc/max34408.c
> new file mode 100644
> index 000000000000..85cd7b1ec186
> --- /dev/null
> +++ b/drivers/iio/adc/max34408.c
> @@ -0,0 +1,278 @@


> +static const struct of_device_id max34408_of_match[] = {
> +	{
> +		.compatible = "maxim,max34408",
> +		.data = &max34408_model_data,
> +	},
> +	{
> +		.compatible = "maxim,max34409",
> +		.data = &max34409_model_data,
> +	},
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, max34408_of_match);

Having dropped the unnecessary check in probe, move this to next to the
other tables.

> +
> +static int max34408_probe(struct i2c_client *client)
> +{
> +	const struct max34408_adc_model_data *model_data;
> +	struct device *dev = &client->dev;
> +	const struct of_device_id *match;
> +	struct max34408_data *max34408;
> +	struct fwnode_handle *node;
> +	struct iio_dev *indio_dev;
> +	struct regmap *regmap;
> +	int rc, i;
> +
> +	match = i2c_of_match_device(max34408_of_match, client);

Why check this?  This prevents any other firmware binding being used for no
obvious purpose.  Just check...

> +	if (!match)
> +		return -EINVAL;
> +	model_data = i2c_get_match_data(client);
.. 	if (!model_data)
		return -EINVAL;

instead.

> +
> +	regmap = devm_regmap_init_i2c(client, &max34408_regmap_config);
> +	if (IS_ERR(regmap)) {
> +		dev_err_probe(dev, PTR_ERR(regmap),
> +			      "regmap_init failed\n");
> +		return PTR_ERR(regmap);
> +	}
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*max34408));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	max34408 = iio_priv(indio_dev);
> +	max34408->regmap = regmap;
> +	max34408->dev = dev;
> +	mutex_init(&max34408->lock);
> +
> +	device_for_each_child_node(dev, node) {
> +		fwnode_property_read_u32(node, "maxim,rsense-val-micro-ohms",
> +					 &max34408->input_rsense[i]);
> +		i++;
As 0-day pointed out, i isn't initialized.

> +	}
> +
> +	/* disable ALERT and averaging */
> +	rc = regmap_write(max34408->regmap, MAX34408_CONTROL_REG, 0x0);
> +	if (rc)
> +		return rc;
> +
> +	indio_dev->channels = model_data->channels;
> +	indio_dev->num_channels = model_data->num_channels;
> +	indio_dev->name = model_data->model_name;
> +
> +	indio_dev->info = &max34408_info;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}


      parent reply	other threads:[~2023-10-10 15:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-07 23:48 [PATCH v5 0/2] Add maxim max34408/34409 ADC driver and yaml Ivan Mikhaylov
2023-10-07 23:48 ` [PATCH v5 1/2] dt-bindings: adc: provide max34408/9 device tree binding document Ivan Mikhaylov
2023-10-10 14:33   ` Rob Herring
2023-10-10 14:40   ` Jonathan Cameron
2023-10-10 20:22     ` Ivan Mikhaylov
2023-10-12  7:40       ` Jonathan Cameron
2023-10-12 16:27         ` Ivan Mikhaylov
2023-10-13  8:19           ` Jonathan Cameron
2023-10-13  8:35             ` Krzysztof Kozlowski
2023-10-13  9:09               ` Jonathan Cameron
2023-10-13  9:53                 ` Krzysztof Kozlowski
2023-10-13 18:12                   ` Jonathan Cameron
2023-10-07 23:48 ` [PATCH v5 2/2] iio: adc: Add driver support for MAX34408/9 Ivan Mikhaylov
2023-10-09 10:08   ` kernel test robot
2023-10-10 15:24   ` Jonathan Cameron [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=20231010162405.6d6f3c48@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fr0st61te@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).