iio: adc: Add support for AVIA HX710B ADC
v11 cover iio: adc: Add support for AVIA HX710B ADC
The HX710B is a 24-bit ADC from AVIA Semiconductor, related to the HX711 already supported in this driver. Unlike the HX711 (which has selectable gain and two input channels), the HX710B has a fixed gain of 128 and two operating modes selected by the trailing PD_SCK pulse count after each conversion:
25 pulses (1 trailing): differential input at 10 SPS 26 pulses (2 trailing): DVDD-AVDD supply monitor at 40 SPS 27 pulses (3 trailing): differential input at 40 SPS
This series first extends the existing HX711 binding and driver with preparatory refactoring, then adds HX710B support on top.
The differential input is exposed as a single IIO channel with IIO_CHAN_INFO_SAMP_FREQ, allowing userspace to select 10 or 40 SPS without needing two separate channels for the same physical input. The supply monitor is a second channel at fixed 40 SPS.
This revision is rebased onto current mainline. Note that iio_device_claim_direct_mode() / iio_device_release_direct_mode() were removed from the IIO core since v10, so 11/11 now uses the replacement iio_device_claim_direct() / iio_device_release_direct() API.
Tested on a PocketBeagle2 (TI AM625): the avia,hx710b node probes and the driver registers its two IIO channels.
Changes from v10:
- 02/11: Retitled to "add VSUP and DVDD supply properties"; the commit message now documents both supplies (the patch already added both; only the title/text were out of sync). [Jonathan]
- 04/11: Reworded commit message so DVDD is no longer described as HX710B-specific (it is added for both parts in 02/11). The compatible match now uses "contains: const: avia,hx710b" so the constraints still apply if the compatible is later used as a fallback. dvdd-supply is now required for HX710B (in the HX710B branch only, so existing HX711 device trees are unaffected) and added to the HX710B example. [Jonathan, Conor, Sashiko]
- 11/11: Kconfig title and file header use "similar" instead of "compatible". Simplified the tail of hx711_set_hx710b_channel() to "return hx711_wait_for_ready()". Dropped an unrelated reindentation of the iio_push_to_buffers_with_timestamp() call. Converted hx710b_write_raw() to the new iio_device_claim_direct() API (see above). [Jonathan]
The Reviewed-by (Andy Shevchenko) and Acked-by (Conor Dooley) tags on 02/11 and 04/11 are carried over although those patches changed; please re-confirm if you disagree with the reworked constraints.
Patches 01/11, 03/11, and 05/11 are unchanged from v10.
Piyush Patle (11):
dt-bindings: iio: adc: hx711: clean up existing binding text
dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties
dt-bindings: iio: adc: hx711: add RATE GPIO property
dt-bindings: iio: adc: hx711: add HX710B support
iio: adc: hx711: move scale computation to per-device storage
iio: adc: hx711: introduce hx711_chip_info structure
iio: adc: hx711: pass trailing pulse count into hx711_read
iio: adc: hx711: split variable assignments in hx711_read and
hx711_reset
iio: adc: hx711: localize loop iterators in hx711_read
iio: adc: hx711: pass iio_chan_spec to hx711_reset_read
iio: adc: hx711: add support for HX710B
.../bindings/iio/adc/avia-hx711.yaml | 82 ++++- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 343 +++++++++++++++--- 3 files changed, 359 insertions(+), 74 deletions(-)
Signature · 1 line
2.43.0
PATCH v11 1/11 dt-bindings: iio: adc: hx711: clean up existing binding text
Rewrite the binding description and property text so it describes the existing HX711 hardware behavior directly instead of documenting old driver implementation details.
Also clarify that clock-frequency controls the SCK bit-bang timing.
No functional change.
--- .../bindings/iio/adc/avia-hx711.yaml | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-)
Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +10 -15
@@ -10,14 +10,9 @@ maintainers: - Andreas Klinger <[email protected]> description: | - Bit-banging driver using two GPIOs: - - sck-gpio gives a clock to the sensor with 24 cycles for data retrieval - and up to 3 cycles for selection of the input channel and gain for the - next measurement - - dout-gpio is the sensor data the sensor responds to the clock - - Specifications about the driver can be found at: - http://www.aviaic.com/ENProducts.aspx + The HX711 is a 24-bit ADC with selectable gain (32/64/128) and two + differential input channels. Channel A supports gain 64 and 128; + channel B supports gain 32. properties: compatible:
@@ -26,23 +21,23 @@ properties: sck-gpios: description: - Definition of the GPIO for the clock (output). In the datasheet it is - named PD_SCK + GPIO for the clock output (PD_SCK in the datasheet). maxItems: 1 dout-gpios: description: - Definition of the GPIO for the data-out sent by the sensor in - response to the clock (input). - See Documentation/devicetree/bindings/gpio/gpio.txt for information - on how to specify a consumer gpio. + GPIO for the data output from the sensor (DOUT in the datasheet). maxItems: 1 avdd-supply: description: - Definition of the regulator used as analog supply + Analog supply voltage (AVDD). clock-frequency: + description: + Controls the SCK bit-bang timing. The value is used to derive the + delay between SCK edges; keep the SCK high time below 60 us to + avoid triggering chip power-down mode. minimum: 20000 maximum: 2500000 default: 400000
Signature · 1 line
2.43.0
PATCH v11 2/11 dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties
In reply to Piyush PatleDocument the optional VSUP supply used by the HX711 on-chip regulator.
Also document the DVDD digital supply. DVDD is a board-supplied digital input rail (figure 1 of the datasheet shows it as a separate supply, not merely a bypass capacitor point) that was missing from the original binding.
--- .../devicetree/bindings/iio/adc/avia-hx711.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +13 -0
@@ -33,6 +33,19 @@ properties: description: Analog supply voltage (AVDD). + vsup-supply: + description: + Supply voltage for the on-chip regulator (VSUP). + + dvdd-supply: + description: + Digital supply voltage (DVDD). On the HX711, DVDD is a + board-supplied digital rail; it was missing from the original + binding. On the HX710B, DVDD must be greater than or equal to + AVDD; when DVDD is a battery rail and AVDD is a regulated supply, + one channel monitors the DVDD-AVDD difference for battery level + detection. + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the
Signature · 1 line
2.43.0
PATCH v11 3/11 dt-bindings: iio: adc: hx711: add RATE GPIO property
In reply to Piyush PatleDocument the optional RATE pin GPIO used to select the HX711 output data rate.
Update the example to show the property in use.
--- Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +8 -0
@@ -46,6 +46,13 @@ properties: one channel monitors the DVDD-AVDD difference for battery level detection. + rate-gpios: + description: + GPIO connected to the RATE pin. When driven low the output data + rate is 10 SPS; when driven high it is 80 SPS. If omitted the + RATE pin state is determined by the board wiring. + maxItems: 1 + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the
@@ -70,6 +77,7 @@ examples: compatible = "avia,hx711"; sck-gpios = <&gpio3 10 GPIO_ACTIVE_HIGH>; dout-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; + rate-gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>; avdd-supply = <&avdd>; clock-frequency = <100000>; };
Signature · 1 line
2.43.0
PATCH v11 4/11 dt-bindings: iio: adc: hx711: add HX710B support
In reply to Piyush PatleAdd the avia,hx710b compatible and document the HX710B VREF supply.
Add constraints that forbid HX711-only properties on HX710B nodes and require vref-supply and dvdd-supply for HX710B, then add a separate HX710B example.
--- .../bindings/iio/adc/avia-hx711.yaml | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +37 -1
@@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/iio/adc/avia-hx711.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: AVIA HX711 ADC chip for weight cells +title: AVIA HX711 and HX710B ADCs maintainers: - Andreas Klinger <[email protected]>
@@ -14,9 +14,14 @@ description: | differential input channels. Channel A supports gain 64 and 128; channel B supports gain 32. + The HX710B is a 24-bit ADC with fixed gain of 128. One input measures + the differential voltage between the two input pins; a second measures + the DVDD-AVDD supply voltage difference for battery level detection. + properties: compatible: enum: + - avia,hx710b - avia,hx711 sck-gpios:
@@ -53,6 +58,10 @@ properties: RATE pin state is determined by the board wiring. maxItems: 1 + vref-supply: + description: + Reference voltage input (VREF). + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the
@@ -62,6 +71,23 @@ properties: maximum: 2500000 default: 400000 +allOf: + - if: + properties: + compatible: + contains: + const: avia,hx710b + then: + properties: + vsup-supply: false + rate-gpios: false + required: + - vref-supply + - dvdd-supply + else: + properties: + vref-supply: false + required: - compatible - sck-gpios
@@ -81,3 +107,13 @@ examples: avdd-supply = <&avdd>; clock-frequency = <100000>; }; + - | + #include <dt-bindings/gpio/gpio.h> + weight { + compatible = "avia,hx710b"; + sck-gpios = <&gpio3 10 GPIO_ACTIVE_HIGH>; + dout-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; + avdd-supply = <&avdd>; + dvdd-supply = <&dvdd>; + vref-supply = <&vref>; + };
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 04/11] dt-bindings: iio: adc: hx711: add HX710B support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The HX710B driver fails to request and enable the `avdd-supply` and `dvdd-supply` regulators…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The HX710B driver fails to request and enable the avdd-supply and dvdd-supply regulators, leaving the chip unpowered.
- [Low] The driver uses a non-existent compiler macro __counted_by_ptr, which will cause a build failure. --
commit 4a57ad17002849c3ffed8137401cf0ed7fd81778
Author: Piyush Patle <[email protected]>
iio: adc: hx711: add support for HX710B
This commit adds support for the AVIA HX710B ADC, sharing the GPIO interface with the HX711 but using trailing pulses for mode selection. It introduces variant-specific channel configurations and tracks active channels across conversions. Additionally, it refactors the gain and scale computations to use fixed values for the new variant.
Quoted 5 lines
drivers/iio/adc/hx711.c +0
-0
drivers/iio/adc/hx711.c static int hx711_get_scale_to_gain(const int *gain_scale, int scale) · line 94
Quoted 9 lines
drivers/iio/adc/hx711.c +2
-0@@ -84,12 +86,16 @@ static int hx711_get_scale_to_gain(const int *gain_scale, int scale)* @channels: channel specification array * @num_channels: number of entries in @channels * @iio_info: IIO info ops for this variant +* @fixed_gain_val: fixed PGA gain (used when @has_fixed_gain is true) +* @has_fixed_gain: true if the variant has a fixed ADC gain */ struct hx711_chip_info {const char *name; const struct iio_chan_spec *channels __counted_by_ptr(num_channels);
[Severity: Low]
Will this compile? The __counted_by_ptr macro doesn't appear to be defined anywhere in the kernel, whereas __counted_by is used for flexible array members. Could this result in a syntax error during the build?
Quoted 5 lines
drivers/iio/adc/hx711.c +2
-0unsigned int num_channels;const struct iio_info *iio_info; +unsigned int fixed_gain_val; +bool has_fixed_gain; };
[ ... ]
drivers/iio/adc/hx711.c static int hx711_probe(struct platform_device *pdev) · line 717
Quoted 11 lines
drivers/iio/adc/hx711.c +4
-1@@ -543,32 +709,43 @@ static int hx711_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (hx711_data->gpiod_dout),"failed to get dout-gpiod\n" ); - ret =devm_regulator_get_enable_read_voltage (dev,"avdd" ); +if (chip_info->has_fixed_gain) + ret =devm_regulator_get_enable_read_voltage (dev,"vref" ); +else + ret =devm_regulator_get_enable_read_voltage (dev,"avdd" );if (ret <0 )return ret;
[Severity: High]
Does this leave the HX710B unpowered? The device tree bindings require both avdd-supply and dvdd-supply for the avia,hx710b compatible.
However, when has_fixed_gain is true for the HX710B variant, the driver only requests the vref supply. If avdd and dvdd are controlled by actual regulators on the board, will they remain disabled and cause the hardware to fail?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v11 04/11] dt-bindings: iio: adc: hx711: add HX710B support
Quoted 8 lines · On Wed, Jun 03, 2026 at 07:02:30PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The HX710B driver fails to request and enable theavdd-supplyanddvdd-supplyregulators, leaving the chip unpowered.
- [Low] The driver uses a non-existent compiler macro__counted_by_ptr, which will cause a build failure. --commit
4a57ad17002849c3ffed8137401cf0ed7fd81778
Author: Piyush Patle <[email protected]>
Quoted 7 lines
iio: adc: hx711: add support for HX710B
This commit adds support for the AVIA HX710B ADC, sharing the GPIO interface with the HX711 but using trailing pulses for mode selection. It introduces variant-specific channel configurations and tracks active channels across conversions. Additionally, it refactors the gain and scale computations to use fixed values for the new variant.
Sashiko is replying here to the wrong patch.
Quoted 52 lines
Quoted 6 lines
drivers/iio/adc/hx711.c +0
-0drivers/iio/adc/hx711.c static int hx711_get_scale_to_gain(const int *gain_scale, int scale) · line 94
Quoted 9 lines
drivers/iio/adc/hx711.c +2
-0@@ -84,12 +86,16 @@ static int hx711_get_scale_to_gain(const int *gain_scale, int scale)* @channels: channel specification array * @num_channels: number of entries in @channels * @iio_info: IIO info ops for this variant +* @fixed_gain_val: fixed PGA gain (used when @has_fixed_gain is true) +* @has_fixed_gain: true if the variant has a fixed ADC gain */ struct hx711_chip_info {const char *name; const struct iio_chan_spec *channels __counted_by_ptr(num_channels);[Severity: Low]
Will this compile? The__counted_by_ptrmacro doesn't appear to be defined anywhere in the kernel, whereas__counted_byis used for flexible array members. Could this result in a syntax error during the build?Quoted 5 lines
drivers/iio/adc/hx711.c +2
-0unsigned int num_channels;const struct iio_info *iio_info; +unsigned int fixed_gain_val; +bool has_fixed_gain; };[ ... ]
drivers/iio/adc/hx711.c static int hx711_probe(struct platform_device *pdev) · line 717
Quoted 11 lines
drivers/iio/adc/hx711.c +4
-1@@ -543,32 +709,43 @@ static int hx711_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (hx711_data->gpiod_dout),"failed to get dout-gpiod\n" ); - ret =devm_regulator_get_enable_read_voltage (dev,"avdd" ); +if (chip_info->has_fixed_gain) + ret =devm_regulator_get_enable_read_voltage (dev,"vref" ); +else + ret =devm_regulator_get_enable_read_voltage (dev,"avdd" );if (ret <0 )return ret;[Severity: High]
Does this leave the HX710B unpowered? The device tree bindings require both avdd-supply and dvdd-supply for the avia,hx710b compatible.However, when
has_fixed_gainis true for the HX710B variant, the driver only requests the vref supply. If avdd and dvdd are controlled by actual regulators on the board, will they remain disabled and cause the hardware to fail?Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v11 5/11 iio: adc: hx711: move scale computation to per-device storage
In reply to Piyush PatleThe gain-to-scale table is global today, so probe-time scale updates for one device overwrite the values used by any earlier device instance.
Fix this by making the gain table const and storing the computed scale values per device in hx711_data.
No functional change for single-sensor configurations.
--- drivers/iio/adc/hx711.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/iio/adc/hx711.c +16 -15
@@ -28,22 +28,20 @@struct hx711_gain_to_scale {int gain;int gain_pulse; -int scale;int channel; };/* * .scale depends on AVDD which in turn is known as soon as the regulator -* is available -* therefore we set .scale in hx711_probe() +* is available; it is stored per device in hx711_data.gain_scale[] * * channel A in documentation is channel 0 in source code * channel B in documentation is channel 1 in source code */ -static struct hx711_gain_to_scale hx711_gain_to_scale[HX711_GAIN_MAX ] = { - {128 ,1 ,0 ,0 }, - {32 ,2 ,0 ,1 }, - {64 ,3 ,0 ,0 } +static const struct hx711_gain_to_scale hx711_gain_to_scale[HX711_GAIN_MAX ] = { + {128 ,1 ,0 }, + {32 ,2 ,1 }, + {64 ,3 ,0 }, };static int hx711_get_gain_to_pulse (int gain)
@@ -56,22 +54,22 @@ static int hx711_get_gain_to_pulse(int gain)return 1 ; } -static int hx711_get_gain_to_scale (int gain) +static int hx711_get_gain_to_scale (const int *gain_scale,int gain) {int i;for (i =0 ; i <HX711_GAIN_MAX ; i++)if (hx711_gain_to_scale[i].gain == gain) -return hx711_gain_to_scale[i].scale; +return gain_scale[i];return 0 ; } -static int hx711_get_scale_to_gain (int scale) +static int hx711_get_scale_to_gain (const int *gain_scale,int scale) {int i;for (i =0 ; i <HX711_GAIN_MAX ; i++) -if (hx711_gain_to_scale[i].scale == scale) +if (gain_scale[i] == scale)return hx711_gain_to_scale[i].gain;return -EINVAL ; }
@@ -82,6 +80,7 @@ struct hx711_data {struct gpio_desc *gpiod_dout;int gain_set;/* gain set on device */ int gain_chan_a;/* gain for channel A */ +int gain_scale[HX711_GAIN_MAX ];struct mutex lock;/* * triggered buffer
@@ -290,7 +289,8 @@ static int hx711_read_raw(struct iio_dev *indio_dev, *val =0 ;mutex_lock (&hx711_data->lock); - *val2 =hx711_get_gain_to_scale (hx711_data->gain_set); + *val2 =hx711_get_gain_to_scale (hx711_data->gain_scale, + hx711_data->gain_set);mutex_unlock (&hx711_data->lock);
@@ -321,7 +321,7 @@ static int hx711_write_raw(struct iio_dev *indio_dev,mutex_lock (&hx711_data->lock); - gain =hx711_get_scale_to_gain (val2); + gain =hx711_get_scale_to_gain (hx711_data->gain_scale, val2);if (gain <0 ) {mutex_unlock (&hx711_data->lock);return gain;
@@ -386,6 +386,7 @@ static ssize_t hx711_scale_available_show(struct device *dev,struct device_attribute *attr, char *buf) { + struct hx711_data *hx711_data = iio_priv(dev_to_iio_dev(dev));struct iio_dev_attr *iio_attr =to_iio_dev_attr (attr);int channel = iio_attr->address;int i, len =0 ;
@@ -393,7 +394,7 @@ static ssize_t hx711_scale_available_show(struct device *dev,for (i =0 ; i <HX711_GAIN_MAX ; i++)if (hx711_gain_to_scale[i].channel == channel) len +=sprintf (buf + len,"0.%09d " , - hx711_gain_to_scale[i].scale); + hx711_data->gain_scale[i]); len +=sprintf (buf + len,"\n" );
@@ -511,7 +512,7 @@ static int hx711_probe(struct platform_device *pdev) ret *=100 ;for (i =0 ; i <HX711_GAIN_MAX ; i++) - hx711_gain_to_scale[i].scale = + hx711_data->gain_scale[i] = ret / hx711_gain_to_scale[i].gain /1678 ; hx711_data->gain_set =128 ;
Signature · 1 line
2.43.0
PATCH v11 6/11 iio: adc: hx711: introduce hx711_chip_info structure
In reply to Piyush PatleAdd a per-variant static configuration structure and populate the IIO device fields from it at probe time.
This is a preparatory change for adding support for more HX711-compatible hardware variants without duplicating the probe-time setup.
No functional change for existing HX711 users.
--- drivers/iio/adc/hx711.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-)
drivers/iio/adc/hx711.c +36 -5
@@ -4,6 +4,8 @@* * Copyright (c) 2016 Andreas Klinger <[email protected]> */ +#include <linux/array_size.h> +#include <linux/dev_printk.h> #include <linux/err.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -74,6 +76,20 @@ static int hx711_get_scale_to_gain(const int *gain_scale, int scale)return -EINVAL ; } +/** +* struct hx711_chip_info - per-variant static configuration +* @name: IIO device name +* @channels: channel specification array +* @num_channels: number of entries in @channels +* @iio_info: IIO info ops for this variant +*/ +struct hx711_chip_info { +const char *name; + const struct iio_chan_spec *channels __counted_by_ptr(num_channels); +unsigned int num_channels; +const struct iio_info *iio_info; +}; +struct hx711_data {struct device *dev;struct gpio_desc *gpiod_pd_sck;
@@ -81,6 +97,7 @@ struct hx711_data {int gain_set;/* gain set on device */ int gain_chan_a;/* gain for channel A */ int gain_scale[HX711_GAIN_MAX ]; +const struct hx711_chip_info *chip_info;struct mutex lock;/* * triggered buffer
@@ -456,8 +473,16 @@ static const struct iio_chan_spec hx711_chan_spec[] = { IIO_CHAN_SOFT_TIMESTAMP(2), }; +static const struct hx711_chip_info hx711_chip = { + .name ="hx711" , + .channels = hx711_chan_spec, + .iio_info = &hx711_iio_info, + .num_channels =ARRAY_SIZE (hx711_chan_spec), +}; +static int hx711_probe (struct platform_device *pdev) { +const struct hx711_chip_info *chip_info;struct device *dev = &pdev->dev;struct hx711_data *hx711_data;struct iio_dev *indio_dev;
@@ -473,6 +498,12 @@ static int hx711_probe(struct platform_device *pdev)mutex_init (&hx711_data->lock); + chip_info =device_get_match_data (dev); +if (!chip_info) +return dev_err_probe (dev, -ENODEV ,"missing driver data\n" ); + + hx711_data->chip_info = chip_info; +/* * PD_SCK stands for power down and serial clock input of HX711 * in the driver it is an output
@@ -534,11 +565,11 @@ static int hx711_probe(struct platform_device *pdev) hx711_data->data_ready_delay_ns =1000000000 / hx711_data->clock_frequency; - indio_dev->name ="hx711" ; - indio_dev->info = &hx711_iio_info; + indio_dev->name = chip_info->name; + indio_dev->info = chip_info->iio_info; indio_dev->modes =INDIO_DIRECT_MODE ; - indio_dev->channels = hx711_chan_spec; - indio_dev->num_channels =ARRAY_SIZE (hx711_chan_spec); + indio_dev->channels = chip_info->channels; + indio_dev->num_channels = chip_info->num_channels; ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time,
@@ -555,7 +586,7 @@ static int hx711_probe(struct platform_device *pdev) }static const struct of_device_id of_hx711_match[] = { - { .compatible ="avia,hx711" , }, + { .compatible ="avia,hx711" , .data = &hx711_chip }, { } };
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 06/11] iio: adc: hx711: introduce hx711_chip_info structure
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The driver now unconditionally fails to probe if `device_get_match_data()` returns NULL, which…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The driver now unconditionally fails to probe if device_get_match_data() returns NULL, which breaks legacy platform device instantiation.
- [Low] The patch uses an undefined macro __counted_by_ptr in the definition of struct hx711_chip_info, causing a syntax error and build failure. --
commit 9bf695b7a4a3ec692793615e524f77137dfcf73f
Author: Piyush Patle <[email protected]>
iio: adc: hx711: introduce hx711_chip_info structure
Add a per-variant static configuration structure and populate the IIO device fields from it at probe time. This prepares the driver for supporting more compatible hardware variants.
Quoted 1 line
No functional change for existing HX711 users.
[Severity: High]
Is this description accurate? For legacy platform devices instantiated by name, the newly added match data check prevents the driver from probing.
Quoted 4 lines
drivers/iio/adc/hx711.c +0
-0
[ ... ]
Quoted 4 lines
drivers/iio/adc/hx711.c +0
-0@@ -74,6 +76,20 @@ static int hx711_get_scale_to_gain(const int *gain_scale, int scale)return -EINVAL ; }
drivers/iio/adc/hx711.c static int hx711_get_scale_to_gain(const int *gain_scale, int scale) · line 88
Quoted 10 lines
drivers/iio/adc/hx711.c +10
-0+/** +* struct hx711_chip_info - per-variant static configuration +* @name: IIO device name +* @channels: channel specification array +* @num_channels: number of entries in @channels +* @iio_info: IIO info ops for this variant +*/ +struct hx711_chip_info { +const char *name; + const struct iio_chan_spec *channels __counted_by_ptr(num_channels);
[Severity: Low]
Does this compile? The macro __counted_by_ptr is not defined anywhere in the kernel headers, which causes a syntax error and build failure.
Quoted 3 lines
drivers/iio/adc/hx711.c +3
-0+unsigned int num_channels; +const struct iio_info *iio_info; +};
[ ... ]
drivers/iio/adc/hx711.c static int hx711_probe(struct platform_device *pdev) · line 503
Quoted 7 lines
drivers/iio/adc/hx711.c +3
-0@@ -473,6 +498,12 @@ static int hx711_probe(struct platform_device *pdev)mutex_init (&hx711_data->lock); + chip_info =device_get_match_data (dev); +if (!chip_info) +return dev_err_probe (dev, -ENODEV ,"missing driver data\n" );
[Severity: High]
Will this break legacy platform device instantiation?
For devices instantiated manually via board files matching the driver name hx711-gpio, device_get_match_data() will return NULL because the driver does not provide a platform_device_id table.
Prior to this patch, the probe function ran successfully for these devices. Now it aborts with -ENODEV.
Quoted 4 lines
drivers/iio/adc/hx711.c +3
-0+ + hx711_data->chip_info = chip_info; +/*
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v11 7/11 iio: adc: hx711: pass trailing pulse count into hx711_read
In reply to Piyush PatleMove the trailing-pulse selection out of hx711_read() and into its callers.
This is a preparatory change so later variant-specific code can pass the per-channel pulse count without adding a separate read path.
No functional change.
--- drivers/iio/adc/hx711.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/iio/adc/hx711.c +11 -9
@@ -155,7 +155,7 @@ static int hx711_cycle(struct hx711_data *hx711_data)return gpiod_get_value (hx711_data->gpiod_dout); } -static int hx711_read (struct hx711_data *hx711_data) +static int hx711_read (struct hx711_data *hx711_data,int trailing_pulses) {int i, ret;int value =0 ;
@@ -174,7 +174,7 @@ static int hx711_read(struct hx711_data *hx711_data) value ^=0x800000 ; -for (i =0 ; i <hx711_get_gain_to_pulse (hx711_data->gain_set); i++) +for (i =0 ; i < trailing_pulses; i++)hx711_cycle (hx711_data);return value;
@@ -237,7 +237,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)if (hx711_data->gain_set ==32 ) { hx711_data->gain_set = hx711_data->gain_chan_a; - ret =hx711_read (hx711_data); + ret =hx711_read (hx711_data, +hx711_get_gain_to_pulse (hx711_data->gain_set));if (ret <0 )return ret;
@@ -249,7 +250,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)if (hx711_data->gain_set !=32 ) { hx711_data->gain_set =32 ; - ret =hx711_read (hx711_data); + ret =hx711_read (hx711_data, +hx711_get_gain_to_pulse (hx711_data->gain_set));if (ret <0 )return ret;
@@ -264,8 +266,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)static int hx711_reset_read (struct hx711_data *hx711_data,int chan) { +int trailing_pulses;int ret; -int val;/* * hx711_reset() must be called from here
@@ -280,9 +282,8 @@ static int hx711_reset_read(struct hx711_data *hx711_data, int chan)if (ret <0 )return ret; - val =hx711_read (hx711_data); - -return val; + trailing_pulses =hx711_get_gain_to_pulse (hx711_data->gain_set); +return hx711_read (hx711_data, trailing_pulses); } static int hx711_read_raw(struct iio_dev *indio_dev,
@@ -349,7 +350,8 @@ static int hx711_write_raw(struct iio_dev *indio_dev,if (gain !=32 ) hx711_data->gain_chan_a = gain; - ret =hx711_read (hx711_data); + ret =hx711_read (hx711_data, +hx711_get_gain_to_pulse (hx711_data->gain_set));if (ret <0 ) {mutex_unlock (&hx711_data->lock);return ret;
Signature · 1 line
2.43.0
PATCH v11 8/11 iio: adc: hx711: split variable assignments in hx711_read and hx711_reset
In reply to Piyush PatleSeparate the initial value assignments from the declarations in hx711_read() and hx711_reset().
This is a small preparatory cleanup before the later loop-iterator and variant-specific changes adjust the local variable layout in these functions.
No functional change.
--- drivers/iio/adc/hx711.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/adc/hx711.c +4 -2
@@ -159,9 +159,10 @@ static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses) {int i, ret;int value =0 ; -int val =gpiod_get_value (hx711_data->gpiod_dout); +int val;/* we double check if it's really down */ + val =gpiod_get_value (hx711_data->gpiod_dout);if (val)return -EIO ;
@@ -204,8 +205,9 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)static int hx711_reset (struct hx711_data *hx711_data) { -int val =hx711_wait_for_ready (hx711_data); +int val; + val =hx711_wait_for_ready (hx711_data);if (val) {/* * an examination with the oszilloscope indicated
Signature · 1 line
2.43.0
PATCH v11 9/11 iio: adc: hx711: localize loop iterators in hx711_read
In reply to Piyush PatleTighten the scope of the loop variables in hx711_read() now that trailing-pulse selection is already handled by the callers.
Also replace the 24-bit loop bound with a named constant while touching the same code.
--- drivers/iio/adc/hx711.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iio/adc/hx711.c +5 -3
@@ -23,6 +23,8 @@#include <linux/gpio/consumer.h> #include <linux/regulator/consumer.h> +#define HX711_DATA_BITS 24 +/* gain to pulse and scale conversion */ #define HX711_GAIN_MAX 3#define HX711_RESET_GAIN 128
@@ -157,16 +159,16 @@ static int hx711_cycle(struct hx711_data *hx711_data)static int hx711_read (struct hx711_data *hx711_data,int trailing_pulses) { -int i, ret;int value =0 ;int val; +int ret;/* we double check if it's really down */ val =gpiod_get_value (hx711_data->gpiod_dout);if (val)return -EIO ; -for (i =0 ; i <24 ; i++) { +for (int i =0 ; i <HX711_DATA_BITS ; i++) { value <<=1 ; ret =hx711_cycle (hx711_data);if (ret)
@@ -175,7 +177,7 @@ static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses) value ^=0x800000 ; -for (i =0 ; i < trailing_pulses; i++) +for (int i =0 ; i < trailing_pulses; i++)hx711_cycle (hx711_data);return value;
Signature · 1 line
2.43.0
PATCH v11 10/11 iio: adc: hx711: pass iio_chan_spec to hx711_reset_read
In reply to Piyush PatleChange hx711_reset_read() to accept the channel descriptor directly and update its callers accordingly.
Split the existing HX711 channel-selection work into a small helper so a later variant-specific change can add a matching helper without growing hx711_reset_read() further.
No functional change.
--- drivers/iio/adc/hx711.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
drivers/iio/adc/hx711.c +21 -6
@@ -268,7 +268,23 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)return 0 ; } -static int hx711_reset_read (struct hx711_data *hx711_data,int chan) +static int hx711_set_hx711_channel (struct hx711_data *hx711_data, +const struct iio_chan_spec *chan, +int *trailing_pulses) +{ +int ret; + + ret =hx711_set_gain_for_channel (hx711_data, chan->channel); +if (ret <0 ) +return ret; + + *trailing_pulses =hx711_get_gain_to_pulse (hx711_data->gain_set); + +return 0 ; +} + +static int hx711_reset_read (struct hx711_data *hx711_data, +const struct iio_chan_spec *chan) {int trailing_pulses;int ret;
@@ -282,11 +298,10 @@ static int hx711_reset_read(struct hx711_data *hx711_data, int chan)return -EIO ; } - ret =hx711_set_gain_for_channel (hx711_data, chan); + ret =hx711_set_hx711_channel (hx711_data, chan, &trailing_pulses);if (ret <0 )return ret; - trailing_pulses =hx711_get_gain_to_pulse (hx711_data->gain_set);return hx711_read (hx711_data, trailing_pulses); }
@@ -300,7 +315,7 @@ static int hx711_read_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_RAW :mutex_lock (&hx711_data->lock); - *val =hx711_reset_read (hx711_data, chan->channel); + *val =hx711_reset_read (hx711_data, chan);mutex_unlock (&hx711_data->lock);
@@ -390,8 +405,8 @@ static irqreturn_t hx711_trigger(int irq, void *p)memset (&hx711_data->buffer,0 ,sizeof (hx711_data->buffer));iio_for_each_active_channel (indio_dev, i) { - hx711_data->buffer.channel[j] =hx711_reset_read (hx711_data, - indio_dev->channels[i].channel); + hx711_data->buffer.channel[j] = +hx711_reset_read (hx711_data, &indio_dev->channels[i]); j++; }
Signature · 1 line
2.43.0
PATCH v11 11/11 iio: adc: hx711: add support for HX710B
In reply to Piyush PatleAdd 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.
--- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 222 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 205 insertions(+), 25 deletions(-)
drivers/iio/adc/Kconfig +5 -3
@@ -791,13 +791,15 @@ config HI8435 called hi8435. config HX711 - tristate "AVIA HX711 ADC for weight cells" + tristate "AVIA HX711 and similar ADCs" depends on GPIOLIB select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - If you say yes here you get support for AVIA HX711 ADC which is used - for weigh cells + If you say Y here you get support for the following AVIA ADCs: + - HX710B + - HX711 + which are used for bridge sensors such as weigh cells. This driver uses two GPIOs, one acts as the clock and controls the channel selection and gain, the other one is used for the measurement
drivers/iio/adc/hx711.c +200 -22
351 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 11/11] iio: adc: hx711: add support for HX710B
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The triggered buffer loop unconditionally performs physical hardware reads for all active channels, including the IIO soft timestamp channel. For the HX711, hx711_reset_read() returns -EINVAL for the timestamp channel; this patch introduces a new if (ret < 0) check that catches this error, prints a failure, and aborts the trigger entirely, completely breaking buffer capture when the timestamp is enabled. For the newly added HX710B, the driver incorrectly interprets the timestamp channel as having differential = 0, performing a ~100ms blocking dummy hardware read and then writing the result to hx711_data->buffer.channel[j++] at index 2, which violates the u32 channel[2] array bounds and risks UBSAN kernel panics.
Pre-existing issues:
- [High] The driver allows IIO_CHAN_INFO_RAW sysfs reads to proceed concurrently with triggered buffer captures due to a missing iio_device_claim_direct() call, which causes hardware state machine corruption and data loss. --
commit 4a57ad17002849c3ffed8137401cf0ed7fd81778
Author: Piyush Patle <[email protected]>
iio: adc: hx711: add support for HX710B
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.
Quoted 4 lines
drivers/iio/adc/hx711.c +0
-0
[ ... ]
drivers/iio/adc/hx711.c static int hx711_read_raw(struct iio_dev *indio_dev, · line 381
Quoted 4 lines
drivers/iio/adc/hx711.c +0
-0@@ -322,6 +379,9 @@ static int hx711_read_raw(struct iio_dev *indio_dev,if (*val <0 )return *val;return IIO_VAL_INT ;
[Severity: High]
This is a pre-existing issue, but does hx711_read_raw() allow IIO_CHAN_INFO_RAW sysfs reads to proceed concurrently with triggered buffer captures?
Since there is no iio_device_claim_direct() call to serialize against the active IIO buffer, a concurrent sysfs read might acquire the lock between trigger samples.
Because the hardware relies on the trailing pulses of the previous read to set the channel and gain for the next conversion, could an interleaved sysfs read clock out data intended for the buffer and reset the hardware, corrupting the data stream for userspace?
Quoted 6 lines
drivers/iio/adc/hx711.c +3
-0+case IIO_CHAN_INFO_SAMP_FREQ : + *val = hx711_data->samp_freq; +return IIO_VAL_INT ;case IIO_CHAN_INFO_SCALE : *val =0 ;mutex_lock (&hx711_data->lock);
[ ... ]
Quoted 11 lines
drivers/iio/adc/hx711.c +1
-0@@ -399,20 +459,26 @@ static irqreturn_t hx711_trigger(int irq, void *p)struct iio_dev *indio_dev = pf->indio_dev;struct hx711_data *hx711_data =iio_priv (indio_dev);int i, j =0 ; +int ret;mutex_lock (&hx711_data->lock);memset (&hx711_data->buffer,0 ,sizeof (hx711_data->buffer));iio_for_each_active_channel (indio_dev, i) {
drivers/iio/adc/hx711.c static irqreturn_t hx711_trigger(int irq, void *p) · line 475
Quoted 10 lines
drivers/iio/adc/hx711.c +7
-3- hx711_data->buffer.channel[j] = -hx711_reset_read (hx711_data, &indio_dev->channels[i]); - j++; + ret =hx711_reset_read (hx711_data, &indio_dev->channels[i]); +if (ret <0 ) { +dev_err_ratelimited (hx711_data->dev, +"read failed: %d\n" , ret); + goto out_unlock; + } + hx711_data->buffer.channel[j++] = ret;
[Severity: High]
Does this new error check accidentally cause a regression by aborting the trigger entirely when the IIO soft timestamp channel is enabled?
iio_for_each_active_channel() iterates over the active_scan_mask, which includes the timestamp channel.
For the HX711, it appears hx711_reset_read() will return -EINVAL for the timestamp channel. Would this new check catch that and completely abort the capture without pushing data?
Furthermore, for the newly added HX710B, hx710b_trailing_pulses() seems to evaluate !chan->differential as true for the timestamp channel. Would this result in a hardware read that writes to hx711_data->buffer.channel[2], overflowing the bounds of the u32 channel[2] array?
Quoted 7 lines
drivers/iio/adc/hx711.c +1
-0}iio_push_to_buffers_with_timestamp (indio_dev, &hx711_data->buffer, pf->timestamp); +out_unlock:mutex_unlock (&hx711_data->lock);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Jonathan Cameron
maintainerRe: [PATCH v11 11/11] iio: adc: hx711: add support for HX710B
In reply to Piyush PatleQuoted 7 lines · On Thu, 4 Jun 2026 00:18:59 +0530 Piyush Patle <[email protected]>…
Add support for the AVIA HX710B ADC, which shares the HX711 GPIO interface but uses trailing
PD_SCKpulses 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.
Quoted 5 lines
Also update the adjacent
Kconfigtext, file header, and module description so the driver text matches the newly supported variant.Signed-off-by Piyush Patle <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>
Hi,
One small thing inline which is is kind of a side effect of cleaning up the regulator description in earlier patches
Thanks,
Jonathan
Quoted 10 lines
drivers/iio/adc/hx711.c +0
-0static int hx711_probe (struct platform_device *pdev) {const struct hx711_chip_info *chip_info;
drivers/iio/adc/hx711.c static int hx711_probe(struct platform_device *pdev) · line 717
Quoted 10 lines
drivers/iio/adc/hx711.c +4
-1@@ -543,32 +709,43 @@ static int hx711_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (hx711_data->gpiod_dout),"failed to get dout-gpiod\n" ); - ret =devm_regulator_get_enable_read_voltage (dev,"avdd" ); +if (chip_info->has_fixed_gain) + ret =devm_regulator_get_enable_read_voltage (dev,"vref" ); +else + ret =devm_regulator_get_enable_read_voltage (dev,"avdd" );if (ret <0 )return ret;
https://sashiko.dev/#/patchset/20260603184859.89693-1-piyushpatle228%40gmail.com
Sashiko calls this out (confusingly on patch 4 review). The binding says we need avdd and dvdd as well. So we should be turning those on, even if we don't want to read their voltages - the dvdd one is a bit more arguable, but it is very odd to ignore avdd when the driver is touching it anyway.
I think you need something like:
if (chip_info->has_fixed_gain) {
ret = devm_regulator_get_enable_read_voltage(dev, "vref");
if (ret < 0)
return ret;
ret = devm_regulator_get_enable(dev, "avdd");
if (ret < 0)
return ret;
} else {
ret = devm_regulator_get_enable_read_voltage(dev, "avdd");
if (ret < 0)
return ret;
}
ret = devm_regulator_get_enable(dev, "dvdd");
if (ret < 0)
return ret;For any that aren't provided in DT you'll get stub regulators as long as we don't need to read the voltage.
Other than that the only thing I'd look into is the suggestion read_raw() might clash with buffered reads and corrupt the capture. I haven't checked that.
Thanks,
Jonathan
Jonathan Cameron
maintainerQuoted 44 lines · On Thu, 4 Jun 2026 00:18:48 +0530 Piyush Patle <[email protected]>…
The HX710B is a 24-bit ADC from AVIA Semiconductor, related to the HX711 already supported in this driver. Unlike the HX711 (which has selectable gain and two input channels), the HX710B has a fixed gain of 128 and two operating modes selected by the trailing
PD_SCKpulse count after each conversion:25 pulses (1 trailing): differential input at 10 SPS 26 pulses (2 trailing): DVDD-AVDD supply monitor at 40 SPS 27 pulses (3 trailing): differential input at 40 SPS
This series first extends the existing HX711 binding and driver with preparatory refactoring, then adds HX710B support on top.
The differential input is exposed as a single IIO channel with
IIO_CHAN_INFO_SAMP_FREQ, allowing userspace to select 10 or 40 SPS without needing two separate channels for the same physical input. The supply monitor is a second channel at fixed 40 SPS.This revision is rebased onto current mainline. Note that
iio_device_claim_direct_mode()/iio_device_release_direct_mode()were removed from the IIO core since v10, so 11/11 now uses the replacementiio_device_claim_direct()/iio_device_release_direct()API.Tested on a PocketBeagle2 (TI AM625): the avia,hx710b node probes and the driver registers its two IIO channels.
Changes from v10:
- 02/11: Retitled to "add VSUP and DVDD supply properties"; the commit message now documents both supplies (the patch already added both; only the title/text were out of sync). [Jonathan]
- 04/11: Reworded commit message so DVDD is no longer described as HX710B-specific (it is added for both parts in 02/11). The compatible match now uses "contains: const: avia,hx710b" so the constraints still apply if the compatible is later used as a fallback. dvdd-supply is now required for HX710B (in the HX710B branch only, so existing HX711 device trees are unaffected) and added to the HX710B example. [Jonathan, Conor, Sashiko]
- 11/11:Kconfigtitle and file header use "similar" instead of "compatible". Simplified the tail ofhx711_set_hx710b_channel()to "returnhx711_wait_for_ready()". Dropped an unrelated reindentation of theiio_push_to_buffers_with_timestamp()call. Convertedhx710b_write_raw()to the newiio_device_claim_direct()API (see above). [Jonathan]
Quoted 3 lines
The Reviewed-by (Andy Shevchenko) and Acked-by (Conor Dooley) tags on 02/11 and 04/11 are carried over although those patches changed; please re-confirm if you disagree with the reworked constraints.
As the only comments I had (well mostly sashiko) were on the 710b patch at the end and some patches were queued from previous patches, I now have patches 1-3 and 5-10 applied to the testing branch of iio.git.
Thanks,
Jonathan
Quoted 22 lines
Patches 01/11, 03/11, and 05/11 are unchanged from v10.
Piyush Patle (11):
dt-bindings: iio: adc: hx711: clean up existing binding text
dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties
dt-bindings: iio: adc: hx711: add RATE GPIO property
dt-bindings: iio: adc: hx711: add HX710B support
iio: adc: hx711: move scale computation to per-device storage
iio: adc: hx711: introducehx711_chip_infostructure
iio: adc: hx711: pass trailing pulse count intohx711_read
iio: adc: hx711: split variable assignments inhx711_readandhx711_resetiio: adc: hx711: localize loop iterators in
hx711_read
iio: adc: hx711: passiio_chan_spectohx711_reset_read
iio: adc: hx711: add support for HX710B.../bindings/iio/adc/avia-hx711.yaml | 82 ++++- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 343 +++++++++++++++--- 3 files changed, 359 insertions(+), 74 deletions(-)
Quoted 48 lines · Jonathan Cameron
Quoted 44 lines · On Thu, 4 Jun 2026 00:18:48 +0530 Piyush Patle <[email protected]>…
The HX710B is a 24-bit ADC from AVIA Semiconductor, related to the HX711 already supported in this driver. Unlike the HX711 (which has selectable gain and two input channels), the HX710B has a fixed gain of 128 and two operating modes selected by the trailing
PD_SCKpulse count after each conversion:25 pulses (1 trailing): differential input at 10 SPS 26 pulses (2 trailing): DVDD-AVDD supply monitor at 40 SPS 27 pulses (3 trailing): differential input at 40 SPS
This series first extends the existing HX711 binding and driver with preparatory refactoring, then adds HX710B support on top.
The differential input is exposed as a single IIO channel with
IIO_CHAN_INFO_SAMP_FREQ, allowing userspace to select 10 or 40 SPS without needing two separate channels for the same physical input. The supply monitor is a second channel at fixed 40 SPS.This revision is rebased onto current mainline. Note that
iio_device_claim_direct_mode()/iio_device_release_direct_mode()were removed from the IIO core since v10, so 11/11 now uses the replacementiio_device_claim_direct()/iio_device_release_direct()API.Tested on a PocketBeagle2 (TI AM625): the avia,hx710b node probes and the driver registers its two IIO channels.
Changes from v10:
- 02/11: Retitled to "add VSUP and DVDD supply properties"; the commit message now documents both supplies (the patch already added both; only the title/text were out of sync). [Jonathan]
- 04/11: Reworded commit message so DVDD is no longer described as HX710B-specific (it is added for both parts in 02/11). The compatible match now uses "contains: const: avia,hx710b" so the constraints still apply if the compatible is later used as a fallback. dvdd-supply is now required for HX710B (in the HX710B branch only, so existing HX711 device trees are unaffected) and added to the HX710B example. [Jonathan, Conor, Sashiko]
- 11/11:Kconfigtitle and file header use "similar" instead of "compatible". Simplified the tail ofhx711_set_hx710b_channel()to "returnhx711_wait_for_ready()". Dropped an unrelated reindentation of theiio_push_to_buffers_with_timestamp()call. Convertedhx710b_write_raw()to the newiio_device_claim_direct()API (see above). [Jonathan]
Quoted 6 lines
Quoted 3 lines
The Reviewed-by (Andy Shevchenko) and Acked-by (Conor Dooley) tags on 02/11 and 04/11 are carried over although those patches changed; please re-confirm if you disagree with the reworked constraints.
As the only comments I had (well mostly sashiko) were on the 710b patch at the end and some patches were queued from previous patches, I now have patches 1-3 and 5-10 applied to the testing branch of iio.git.
Thanks a lot for picking those up, and for the reviews through the series.
Two questions, mostly to make sure I do the right thing next:
Looking at mainline I currently only see 01/11 ("dt-bindings: iio: adc:
hx711: clean up existing binding text") and 05/11 ("iio: adc: hx711:
move scale computation to per-device storage") under my name. I assume the rest are still sitting in testing/togreg and will flow in at the next merge window rather than anything having gone missing, is that right? Just checking I'm reading the tree correctly, no rush from my side.
For the two that weren't applied, 04/11 (dt-bindings HX710B) and 11/11 (driver HX710B support): would you prefer I resend just those two as a standalone v12 based on the testing branch, once I've worked through the remaining comments from you and Sashiko? That seemed cleaner than reposting all eleven, but happy to send the full series again if you'd rather have it that way.
If there is anything still outstanding on 04/11 or 11/11 beyond what was raised on v11, please do point me at it and I'll fold it in.
Thanks,
Piyush
Quoted 28 lines
Thanks,
Jonathan
Quoted 22 lines
Patches 01/11, 03/11, and 05/11 are unchanged from v10.
Piyush Patle (11):
dt-bindings: iio: adc: hx711: clean up existing binding text
dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties
dt-bindings: iio: adc: hx711: add RATE GPIO property
dt-bindings: iio: adc: hx711: add HX710B support
iio: adc: hx711: move scale computation to per-device storage
iio: adc: hx711: introducehx711_chip_infostructure
iio: adc: hx711: pass trailing pulse count intohx711_read
iio: adc: hx711: split variable assignments inhx711_readandhx711_resetiio: adc: hx711: localize loop iterators in
hx711_read
iio: adc: hx711: passiio_chan_spectohx711_reset_read
iio: adc: hx711: add support for HX710B.../bindings/iio/adc/avia-hx711.yaml | 82 ++++- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 343 +++++++++++++++--- 3 files changed, 359 insertions(+), 74 deletions(-)
Jonathan Cameron
maintainerQuoted 61 lines · On Fri, 24 Jul 2026 05:51:25 +0530 Piyush Patle <[email protected]>…
Quoted 48 lines · Jonathan Cameron
Quoted 44 lines · On Thu, 4 Jun 2026 00:18:48 +0530 Piyush Patle <[email protected]>…
The HX710B is a 24-bit ADC from AVIA Semiconductor, related to the HX711 already supported in this driver. Unlike the HX711 (which has selectable gain and two input channels), the HX710B has a fixed gain of 128 and two operating modes selected by the trailing
PD_SCKpulse count after each conversion:25 pulses (1 trailing): differential input at 10 SPS 26 pulses (2 trailing): DVDD-AVDD supply monitor at 40 SPS 27 pulses (3 trailing): differential input at 40 SPS
This series first extends the existing HX711 binding and driver with preparatory refactoring, then adds HX710B support on top.
The differential input is exposed as a single IIO channel with
IIO_CHAN_INFO_SAMP_FREQ, allowing userspace to select 10 or 40 SPS without needing two separate channels for the same physical input. The supply monitor is a second channel at fixed 40 SPS.This revision is rebased onto current mainline. Note that
iio_device_claim_direct_mode()/iio_device_release_direct_mode()were removed from the IIO core since v10, so 11/11 now uses the replacementiio_device_claim_direct()/iio_device_release_direct()API.Tested on a PocketBeagle2 (TI AM625): the avia,hx710b node probes and the driver registers its two IIO channels.
Changes from v10:
- 02/11: Retitled to "add VSUP and DVDD supply properties"; the commit message now documents both supplies (the patch already added both; only the title/text were out of sync). [Jonathan]
- 04/11: Reworded commit message so DVDD is no longer described as HX710B-specific (it is added for both parts in 02/11). The compatible match now uses "contains: const: avia,hx710b" so the constraints still apply if the compatible is later used as a fallback. dvdd-supply is now required for HX710B (in the HX710B branch only, so existing HX711 device trees are unaffected) and added to the HX710B example. [Jonathan, Conor, Sashiko]
- 11/11:Kconfigtitle and file header use "similar" instead of "compatible". Simplified the tail ofhx711_set_hx710b_channel()to "returnhx711_wait_for_ready()". Dropped an unrelated reindentation of theiio_push_to_buffers_with_timestamp()call. Convertedhx710b_write_raw()to the newiio_device_claim_direct()API (see above). [Jonathan]Quoted 6 lines
Quoted 3 lines
The Reviewed-by (Andy Shevchenko) and Acked-by (Conor Dooley) tags on 02/11 and 04/11 are carried over although those patches changed; please re-confirm if you disagree with the reworked constraints.
As the only comments I had (well mostly sashiko) were on the 710b patch at the end and some patches were queued from previous patches, I now have patches 1-3 and 5-10 applied to the testing branch of iio.git.
Thanks a lot for picking those up, and for the reviews through the series.
Two questions, mostly to make sure I do the right thing next:
Quoted 7 lines
Looking at mainline I currently only see 01/11 ("dt-bindings: iio: adc:
hx711: clean up existing binding text") and 05/11 ("iio: adc: hx711:
move scale computation to per-device storage") under my name. I assume the rest are still sitting in testing/togreg and will flow in at the next merge window rather than anything having gone missing, is that right? Just checking I'm reading the tree correctly, no rush from my side.
Exactly that - assuming nothing odd happens they should go into mainline in the next merge window.
Quoted 7 lines
For the two that weren't applied, 04/11 (dt-bindings HX710B) and 11/11 (driver HX710B support): would you prefer I resend just those two as a standalone v12 based on the testing branch, once I've worked through the remaining comments from you and Sashiko? That seemed cleaner than reposting all eleven, but happy to send the full series again if you'd rather have it that way.
Go for the togreg branch (it's a little behind but should have all your work on it) and make sure to have a Based-on entry in the cover letter. I'm not sure if Sashiko will find the right thing test on but worth a go.
Quoted 3 lines
If there is anything still outstanding on 04/11 or 11/11 beyond what was raised on v11, please do point me at it and I'll fold it in.
Not that I know of, but we'll see on v11 :)
Jonathan
Quoted 31 lines
Thanks,
PiyushQuoted 28 lines
Thanks,
Jonathan
Quoted 22 lines
Patches 01/11, 03/11, and 05/11 are unchanged from v10.
Piyush Patle (11):
dt-bindings: iio: adc: hx711: clean up existing binding text
dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties
dt-bindings: iio: adc: hx711: add RATE GPIO property
dt-bindings: iio: adc: hx711: add HX710B support
iio: adc: hx711: move scale computation to per-device storage
iio: adc: hx711: introducehx711_chip_infostructure
iio: adc: hx711: pass trailing pulse count intohx711_read
iio: adc: hx711: split variable assignments inhx711_readandhx711_resetiio: adc: hx711: localize loop iterators in
hx711_read
iio: adc: hx711: passiio_chan_spectohx711_reset_read
iio: adc: hx711: add support for HX710B.../bindings/iio/adc/avia-hx711.yaml | 82 ++++- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 343 +++++++++++++++--- 3 files changed, 359 insertions(+), 74 deletions(-)