From: Jonathan Cameron <jic23@kernel.org>
To: Piyush Patle <piyushpatle228@gmail.com>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, Andreas Klinger <ak@it-klinger.de>,
Andy Shevchenko <andy@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Rob Herring <robh@kernel.org>
Subject: Re: [PATCH v9 11/11] iio: adc: hx711: add support for HX710B
Date: Wed, 20 May 2026 11:31:53 +0100 [thread overview]
Message-ID: <20260520113153.3e663a7c@jic23-huawei> (raw)
In-Reply-To: <20260518220228.63322-12-piyushpatle228@gmail.com>
On Tue, 19 May 2026 03:32:27 +0530
Piyush Patle <piyushpatle228@gmail.com> wrote:
> Add support for the AVIA HX710B ADC, which shares the HX711 GPIO
> interface but uses trailing PD_SCK pulses to select the active mode.
>
> Model the HX710B with variant-specific channel tables and IIO info,
> track the active channel across conversions, and use the fixed gain
> value when computing scale.
>
> Also update the adjacent Kconfig text, file header, and module
> description so the driver text matches the newly supported variant.
>
> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
The vast majority of sashiko feedback on this version is incorrect
or already something we've ruled out as needing handling.
However, very last point looks valid to me so I've highlighted that.
Otherwise, the main thing is it is better to keep the structure
for the buffer now we don't have variable numbers of channels between
the two devices. That is the preferred route except when it becomes
misleading (which it did with 2 vs 3 channels).
> diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
> index 183568196d52..d5c977b4669b 100644
> --- a/drivers/iio/adc/hx711.c
> +++ b/drivers/iio/adc/hx711.c
>
> struct hx711_data {
> @@ -99,16 +105,12 @@ struct hx711_data {
> int gain_set; /* gain set on device */
> int gain_chan_a; /* gain for channel A */
> int gain_scale[HX711_GAIN_MAX];
> + int channel_set; /* HX710B active channel */
> + unsigned int samp_freq; /* HX710B differential channel sample rate */
> const struct hx711_chip_info *chip_info;
> struct mutex lock;
> - /*
> - * triggered buffer
> - * 2x32-bit channel + 64-bit naturally aligned timestamp
> - */
> - struct {
> - u32 channel[2];
> - aligned_s64 timestamp;
> - } buffer;
> + /* 2x32-bit channels + 64-bit naturally aligned timestamp */
> + IIO_DECLARE_BUFFER_WITH_TS(u32, buffer, 2);
Now we are back to fixed 2 channels, don't need this change. The structure
is easier to interpret so please go back to that.
> /*
> * delay after a rising edge on SCK until the data is ready DOUT
> * this is dependent on the hx711 where the datasheet tells a
> @@ -463,6 +527,50 @@ static const struct iio_info hx711_iio_info = {
> .attrs = &hx711_attribute_group,
> };
>
> +static const int hx710b_samp_freq_avail[] = { 10, 40 };
> +
> +static int hx710b_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals, int *type, int *length,
> + long mask)
> +{
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + *vals = hx710b_samp_freq_avail;
> + *type = IIO_VAL_INT;
> + *length = ARRAY_SIZE(hx710b_samp_freq_avail);
> + return IIO_AVAIL_LIST;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static int hx710b_write_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int val, int val2, long mask)
> +{
> + struct hx711_data *hx711_data = iio_priv(indio_dev);
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + if (val != 10 && val != 40)
> + return -EINVAL;
> + mutex_lock(&hx711_data->lock);
> + hx711_data->samp_freq = val;
> + hx711_data->channel_set = 0;
> + mutex_unlock(&hx711_data->lock);
From Sahiko:
Does this implementation need to use iio_device_claim_direct_mode() to
prevent concurrent hardware changes while a buffered capture is active?
If userspace modifies the sampling frequency during an active IIO triggered
buffer capture, it resets channel_set to 0. This could alter the hardware
configuration (changing the trailing pulses) out from under the IIO capture
thread, which violates IIO concurrency semantics.
Two possible fixes:
- The one sashiko suggests around claiming direct mode.
- Maybe not set channel_set = 0? Then it becomes a simple race for
whether the value of samp_freq is updated or not. Either is harmless.
I'd be tempted to go with direct mode claiming but also consider if you can
drop that channel_set = 0 - or add a comment on why it's there perhaps.
> + return 0;
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info hx710b_iio_info = {
> + .read_raw = hx711_read_raw,
> + .write_raw = hx710b_write_raw,
> + .read_avail = hx710b_read_avail,
> +};
> static const struct hx711_chip_info hx711_chip = {
> .name = "hx711",
> .channels = hx711_chan_spec,
> @@ -502,6 +655,15 @@ static const struct hx711_chip_info hx711_chip = {
> .num_channels = ARRAY_SIZE(hx711_chan_spec),
> };
> @@ -608,6 +781,7 @@ static int hx711_probe(struct platform_device *pdev)
> }
>
> static const struct of_device_id of_hx711_match[] = {
> + { .compatible = "avia,hx710b", .data = &hx710b_chip },
> { .compatible = "avia,hx711", .data = &hx711_chip },
> { }
> };
> @@ -625,7 +799,7 @@ static struct platform_driver hx711_driver = {
> module_platform_driver(hx711_driver);
>
> MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
> -MODULE_DESCRIPTION("HX711 bitbanging driver - ADC for weight cells");
> +MODULE_DESCRIPTION("HX711 and compatible bitbanging ADC driver");
Trivial but switch that to 'and similar' as they aren't quite compatible.
Sometimes vagueness is helpful :)
Anyhow, looking in pretty good shape so hopefully v10 is the lucky version.
If you have time, it would be nice to get rid of the custom available attributes
for the hx711 as well - similar approach to you have done for the new part.
Jonathan
> MODULE_LICENSE("GPL");
> MODULE_ALIAS("platform:hx711-gpio");
>
prev parent reply other threads:[~2026-05-20 10:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-18 22:02 [PATCH v9 00/11] iio: adc: Add support for AVIA HX710B ADC Piyush Patle
2026-05-18 22:02 ` [PATCH v9 01/11] dt-bindings: iio: adc: hx711: clean up existing binding text Piyush Patle
2026-05-18 22:02 ` [PATCH v9 02/11] dt-bindings: iio: adc: hx711: add VSUP supply property Piyush Patle
2026-05-20 10:09 ` Jonathan Cameron
2026-05-18 22:02 ` [PATCH v9 03/11] dt-bindings: iio: adc: hx711: add RATE GPIO property Piyush Patle
2026-05-18 22:02 ` [PATCH v9 04/11] dt-bindings: iio: adc: hx711: add HX710B support Piyush Patle
2026-05-18 22:10 ` sashiko-bot
2026-05-19 17:21 ` Conor Dooley
2026-05-20 10:19 ` Jonathan Cameron
2026-05-18 22:02 ` [PATCH v9 05/11] iio: adc: hx711: move scale computation to per-device storage Piyush Patle
2026-05-18 22:02 ` [PATCH v9 06/11] iio: adc: hx711: introduce hx711_chip_info structure Piyush Patle
2026-05-18 22:30 ` sashiko-bot
2026-05-20 10:23 ` Jonathan Cameron
2026-05-18 22:02 ` [PATCH v9 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Piyush Patle
2026-05-18 22:02 ` [PATCH v9 08/11] iio: adc: hx711: split variable assignments in hx711_read and hx711_reset Piyush Patle
2026-05-20 10:24 ` Jonathan Cameron
2026-05-18 22:02 ` [PATCH v9 09/11] iio: adc: hx711: localize loop iterators in hx711_read Piyush Patle
2026-05-18 22:02 ` [PATCH v9 10/11] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read Piyush Patle
2026-05-18 22:41 ` sashiko-bot
2026-05-18 22:02 ` [PATCH v9 11/11] iio: adc: hx711: add support for HX710B Piyush Patle
2026-05-18 22:39 ` sashiko-bot
2026-05-20 10:31 ` 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=20260520113153.3e663a7c@jic23-huawei \
--to=jic23@kernel.org \
--cc=ak@it-klinger.de \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=piyushpatle228@gmail.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