From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Petar Stepanovic <pstepanovic@axiado.com>
Cc: "Akhila Kavi" <akavi@axiado.com>,
"Prasad Bolisetty" <pbolisetty@axiado.com>,
"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>,
"Harshit Shah" <hshah@axiado.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] iio: adc: add Axiado SARADC driver
Date: Fri, 17 Jul 2026 11:34:56 +0300 [thread overview]
Message-ID: <alnpMFK6_ZkdWlLi@ashevche-desk.local> (raw)
In-Reply-To: <20260716-axiado-ax3000-ax3005-saradc-v4-2-810527a9d27f@axiado.com>
On Thu, Jul 16, 2026 at 10:53:02PM -0700, Petar Stepanovic wrote:
> Add support for the SARADC controller found on Axiado AX3000 and
> AX3005 SoCs.
>
> The driver supports single-shot voltage reads through the IIO
> subsystem. The number of available input channels is selected from
> the SoC match data, allowing AX3000 and AX3005 variants to use the
> same driver.
...
Please, follow IWYU principle.
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/clk.h>
> +#include <linux/cleanup.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
You can omit this since you have platform_device.h.
> +#include <linux/err.h>
> +#include <linux/io.h>
+ math.h
> +#include <linux/mod_devicetable.h>
No to this header in a new code, Uwe did some rework recently.
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
+ types.h // uXX
> +#include <linux/units.h>
...
> +/* Register offsets */
> +#define AX_SARADC_GLOBAL_CTRL_REG 0x0004
> +#define AX_SARADC_MANUAL_CTRL_REG 0x0008
> +#define AX_SARADC_DOUT_REG 0x001C
Be consistent, use tabs to indent values of the offsets.
...
> +/* GLOBAL_CTRL register values */
> +#define AX_SARADC_GLOBAL_CTRL_SAMPLE_16 \
> + FIELD_PREP(AX_SARADC_GLOBAL_CTRL_SAMPLE_MASK, 0)
> +
> +#define AX_SARADC_GLOBAL_CTRL_MODE_MANUAL \
> + FIELD_PREP(AX_SARADC_GLOBAL_CTRL_MODE_MASK, 1)
FIELD_PREP_CONST() in both cases.
...
> +#define AX_SARADC_MANUAL_CTRL_EN(ch) \
> + (AX_SARADC_MANUAL_CTRL_ENABLE | \
> + FIELD_PREP(AX_SARADC_MANUAL_CTRL_CH_SEL_MASK, ch))
Missing parentheses for ch. Also wrong indentation of the second line, missing
one space.
...
> +#define AX_RESOLUTION_BITS 10
> +#define AX_SARADC_CONV_CYCLES 13
> +#define AX_SARADC_CONV_DELAY_MARGIN_US 10
Again, be consistent, use tabs to indent values.
...
> +struct axiado_saradc {
> + struct regmap *regmap;
> + struct clk *clk;
Makes no sense to keep it here, your code takes the rate and uses that,
I do not see how clk is being used right now. Perhaps you have plans
for power management? But then add it when it's needed and being used.
> + struct mutex lock; /* Serializes ADC conversions. */
> + unsigned long clk_rate;
> + int vref_uV;
> +};
> +
> +static const struct regmap_config axiado_saradc_regmap_config = {
> + .reg_bits = 32,
> + .val_bits = 32,
> + .reg_stride = 4,
> + .max_register = AX_SARADC_DOUT_REG,
No cache?
> +};
> +
> +
Single blank line is enough.
...
> +static int axiado_saradc_conversion(struct axiado_saradc *info,
> + struct iio_chan_spec const *chan, int *val)
> +{
> + unsigned long usecs;
> + unsigned int regval;
> + int stop_ret;
> + int ret;
> +
> + guard(mutex)(&info->lock);
> +
> + /* Select the channel to be used and trigger conversion */
> + ret = regmap_write(info->regmap, AX_SARADC_MANUAL_CTRL_REG,
> + AX_SARADC_MANUAL_CTRL_EN(chan->channel));
> + if (ret)
> + return ret;
> +
> +
Ditto.
> + /* Hardware requires 13 conversion cycles at clk_rate */
> + usecs = DIV_ROUND_UP(AX_SARADC_CONV_CYCLES * USEC_PER_SEC,
> + info->clk_rate);
> + fsleep(usecs + AX_SARADC_CONV_DELAY_MARGIN_US);
> + ret = regmap_read(info->regmap, AX_SARADC_DOUT_REG, ®val);
> +
> + /* Stop manual conversion */
> + stop_ret = regmap_write(info->regmap, AX_SARADC_MANUAL_CTRL_REG, 0);
> +
> + if (ret)
> + return ret;
> + if (stop_ret)
> + return stop_ret;
Why do we care about stop error? Isn't it the best effort we can do?
> + *val = regval & GENMASK(AX_RESOLUTION_BITS - 1, 0);
Is device responding always in native endianess?
> + return 0;
> +}
...
> +static int axiado_saradc_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val,
> + int *val2, long mask)
Split logically:
static int axiado_saradc_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
...
> +static void axiado_saradc_disable(void *data)
> +{
> + struct axiado_saradc *info = data;
> +
> + regmap_write(info->regmap, AX_SARADC_GLOBAL_CTRL_REG,
> + AX_SARADC_GLOBAL_CTRL_PD);
> +}
Supply regmap instead of info and make this simpler
static void axiado_saradc_disable(void *map)
{
regmap_write(map, AX_SARADC_GLOBAL_CTRL_REG, AX_SARADC_GLOBAL_CTRL_PD);
}
...
> + regval = FIELD_PREP(AX_SARADC_GLOBAL_CTRL_CH_EN_MASK,
> + GENMASK(soc_data->num_channels - 1, 0)) |
> + AX_SARADC_GLOBAL_CTRL_SAMPLE_16 |
> + AX_SARADC_GLOBAL_CTRL_MODE_MANUAL |
> + AX_SARADC_GLOBAL_CTRL_ENABLE;
This is not used in the below call, move it closer to its user.
> + ret = regmap_write(info->regmap, AX_SARADC_GLOBAL_CTRL_REG,
> + AX_SARADC_GLOBAL_CTRL_PD);
With
struct regmap *map;
at the top, this and other will be shorter and easier to follow.
And I would dare to use a single line:
ret = regmap_write(map, AX_SARADC_GLOBAL_CTRL_REG, AX_SARADC_GLOBAL_CTRL_PD);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(info->regmap, AX_SARADC_GLOBAL_CTRL_REG, regval);
> + if (ret)
> + return ret;
> + ret = devm_add_action_or_reset(dev, axiado_saradc_disable, info);
ret = devm_add_action_or_reset(dev, axiado_saradc_disable, map);
> + if (ret)
> + return ret;
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-07-17 8:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 5:53 [PATCH v4 0/2] iio: adc: Add Axiado SARADC driver Petar Stepanovic
2026-07-17 5:53 ` [PATCH v4 1/2] dt-bindings: iio: adc: add Axiado AX3000/AX3005 SARADC Petar Stepanovic
2026-07-17 5:53 ` [PATCH v4 2/2] iio: adc: add Axiado SARADC driver Petar Stepanovic
2026-07-17 8:34 ` Andy Shevchenko [this message]
2026-07-17 8:38 ` Andy Shevchenko
2026-07-18 1:40 ` Jonathan Cameron
2026-07-18 13:51 ` Uwe Kleine-König
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=alnpMFK6_ZkdWlLi@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=akavi@axiado.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=hshah@axiado.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=pbolisetty@axiado.com \
--cc=pstepanovic@axiado.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox