From: Jonathan Cameron <jic23@kernel.org>
To: Hugo Villeneuve <hugo@hugovil.com>
Cc: hvilleneuve@dimonoff.com, lars@metafoo.de, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] iio: adc: ti-ads7924: add Texas Instruments ADS7924 driver
Date: Sat, 14 Jan 2023 16:28:41 +0000 [thread overview]
Message-ID: <20230114162841.41358640@jic23-huawei> (raw)
In-Reply-To: <20230113194959.3276433-2-hugo@hugovil.com>
On Fri, 13 Jan 2023 14:49:58 -0500
Hugo Villeneuve <hugo@hugovil.com> wrote:
> From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
>
> The Texas Instruments ADS7924 is a 4 channels, 12-bit analog to
> digital converter (ADC) with an I2C interface.
>
> Datasheet: https://www.ti.com/lit/gpn/ads7924
This counts as a normal tag, so there shouldn't be blank line between
it and the SOB.
A few other small things inline noticed on this read through.
I can fix these up whilst applying if nothing else comes up for v3
and DT binding reviewers are happy. If you are doing a v4 for
other reasons, please address these comments in that.
Jonathan
>
> Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
...
> diff --git a/drivers/iio/adc/ti-ads7924.c b/drivers/iio/adc/ti-ads7924.c
> new file mode 100644
> index 000000000000..c24fae4ef8e0
> --- /dev/null
> +++ b/drivers/iio/adc/ti-ads7924.c
> @@ -0,0 +1,474 @@
...
> +static int ads7924_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
> +{
> + int ret, vref_uv;
> + struct ads7924_data *data = iio_priv(indio_dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> + mutex_lock(&data->lock);
> + ret = ads7924_get_adc_result(data, chan, val);
> + mutex_unlock(&data->lock);
> + if (ret < 0)
> + return ret;
> +
> + return IIO_VAL_INT;
> + case IIO_CHAN_INFO_SCALE:
> + vref_uv = regulator_get_voltage(data->vref_reg);
> + if (vref_uv < 0)
> + return -EINVAL;
Better to return the error value from regulator_get_voltage() rather
than replace it with -EINVAL.
> +
> + *val = vref_uv / 1000; /* Convert reg voltage to mV */
> + *val2 = ADS7924_BITS;
> + return IIO_VAL_FRACTIONAL_LOG2;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info ads7924_info = {
> + .read_raw = ads7924_read_raw,
> +};
> +
> +static int ads7924_get_channels_config(struct i2c_client *client,
> + struct iio_dev *indio_dev)
> +{
> + struct ads7924_data *priv = iio_priv(indio_dev);
> + struct device *dev = priv->dev;
> + struct fwnode_handle *node;
> + int num_channels = 0;
> +
> + device_for_each_child_node(dev, node) {
> + u32 pval;
> + unsigned int channel;
> +
> + if (fwnode_property_read_u32(node, "reg", &pval)) {
> + dev_err(dev, "invalid reg on %pfw\n", node);
> + continue;
> + }
> +
> + channel = pval;
> + if (channel >= ADS7924_CHANNELS) {
> + dev_err(dev, "invalid channel index %d on %pfw\n",
> + channel, node);
> + continue;
> + }
> +
> + num_channels++;
> + }
> +
> + if (num_channels <= 0)
How would it be less than 0? if (!num_channels) works fine I think.
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> +static int ads7924_set_conv_mode(struct ads7924_data *data, int mode)
> +{
> + int ret;
> + unsigned int mode_field;
> + struct device *dev = data->dev;
> +
> + /*
> + * When switching between modes, be sure to first select the Awake mode
> + * and then switch to the desired mode. This procedure ensures the
> + * internal control logic is properly synchronized.
> + */
> + if (mode != ADS7924_MODECNTRL_IDLE) {
> + mode_field = FIELD_PREP(ADS7924_MODECNTRL_MODE_MASK,
> + ADS7924_MODECNTRL_AWAKE);
> +
> + ret = regmap_update_bits(data->regmap, ADS7924_MODECNTRL_REG,
> + ADS7924_MODECNTRL_MODE_MASK,
> + mode_field);
> + if (ret) {
> + dev_warn(dev, "failed to set awake mode (%pe)\n",
> + ERR_PTR(ret));
As below.
> + return ret;
> + }
> + }
> +
> + mode_field = FIELD_PREP(ADS7924_MODECNTRL_MODE_MASK, mode);
> +
> + ret = regmap_update_bits(data->regmap, ADS7924_MODECNTRL_REG,
> + ADS7924_MODECNTRL_MODE_MASK, mode_field);
> + if (ret)
> + dev_warn(dev, "failed to set mode %d (%pe)\n", mode,
> + ERR_PTR(ret));
Why warning? Seems like a fairly critical error to me.
dev_err() more appropriate perhaps.
> +
> + return ret;
> +}
> +
next prev parent reply other threads:[~2023-01-14 16:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 19:49 [PATCH v3 0/2] " Hugo Villeneuve
2023-01-13 19:49 ` [PATCH v3 1/2] " Hugo Villeneuve
2023-01-14 16:28 ` Jonathan Cameron [this message]
2023-01-14 17:53 ` Hugo Villeneuve
2023-01-13 19:49 ` [PATCH v3 2/2] dt-bindings: iio: adc: add Texas Instruments ADS7924 Hugo Villeneuve
2023-01-15 14:57 ` Krzysztof Kozlowski
2023-01-15 16:22 ` Hugo Villeneuve
2023-01-15 16:43 ` Jonathan Cameron
2023-01-15 16:32 ` Hugo Villeneuve
2023-01-15 19:17 ` Krzysztof Kozlowski
2023-01-15 20:11 ` Hugo Villeneuve
2023-01-16 15:21 ` Jonathan Cameron
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=20230114162841.41358640@jic23-huawei \
--to=jic23@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hugo@hugovil.com \
--cc=hvilleneuve@dimonoff.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
all inboxes | Powered by JetHome®