From: Piyush Patle <piyushpatle228@gmail.com>
To: Andreas Klinger <ak@it-klinger.de>, Jonathan Cameron <jic23@kernel.org>
Cc: "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>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 11/11] iio: adc: hx711: add support for HX710B
Date: Sun, 3 May 2026 17:39:40 +0530 [thread overview]
Message-ID: <20260503120949.80292-12-piyushpatle228@gmail.com> (raw)
In-Reply-To: <20260503120949.80292-1-piyushpatle228@gmail.com>
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>
---
drivers/iio/adc/Kconfig | 8 +-
drivers/iio/adc/hx711.c | 173 +++++++++++++++++++++++++++++++++++-----
2 files changed, 157 insertions(+), 24 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 60038ae8dfc4..09a1b29fbd9c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -784,13 +784,15 @@ config HI8435
called hi8435.
config HX711
- tristate "AVIA HX711 ADC for weight cells"
+ tristate "AVIA HX711 and compatible 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
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
index 2229df17f350..521244bd6a7b 100644
--- a/drivers/iio/adc/hx711.c
+++ b/drivers/iio/adc/hx711.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * HX711: analog to digital converter for weight sensor module
+ * HX711 and compatible ADCs driver for weigh sensor modules
*
* Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de>
*/
@@ -15,6 +15,7 @@
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/delay.h>
+#include <linux/types.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>
@@ -83,12 +84,16 @@ static int hx711_get_scale_to_gain(const int *gain_scale, int scale)
* @channels: channel specification array
* @iio_info: IIO info ops for this variant
* @num_channels: number of entries in @channels
+ * @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;
const struct iio_info *iio_info;
unsigned int num_channels;
+ unsigned int fixed_gain_val;
+ bool has_fixed_gain;
};
struct hx711_data {
@@ -98,14 +103,16 @@ 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 */
const struct hx711_chip_info *chip_info;
struct mutex lock;
/*
* triggered buffer
- * 2x32-bit channel + 64-bit naturally aligned timestamp
+ * up to 3x32-bit channels + pad + 64-bit naturally aligned timestamp
*/
struct {
- u32 channel[2];
+ u32 channel[3];
+ u32 pad;
aligned_s64 timestamp;
} buffer;
/*
@@ -207,6 +214,7 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
static int hx711_reset(struct hx711_data *hx711_data)
{
+ const struct hx711_chip_info *info = hx711_data->chip_info;
int val;
val = hx711_wait_for_ready(hx711_data);
@@ -227,8 +235,11 @@ static int hx711_reset(struct hx711_data *hx711_data)
val = hx711_wait_for_ready(hx711_data);
- /* after a reset the gain is 128 */
- hx711_data->gain_set = HX711_RESET_GAIN;
+ if (info->has_fixed_gain)
+ hx711_data->channel_set = 0;
+ else
+ /* after a reset the gain is 128 */
+ hx711_data->gain_set = HX711_RESET_GAIN;
}
return val;
@@ -283,9 +294,36 @@ static int hx711_set_hx711_channel(struct hx711_data *hx711_data,
return 0;
}
+/*
+ * Switch the HX710B to the requested channel for the next conversion.
+ * chan->address holds the trailing pulse count (Table 3 in datasheet).
+ * channel_set is updated only after both reads succeed.
+ */
+static int hx711_set_hx710b_channel(struct hx711_data *hx711_data,
+ const struct iio_chan_spec *chan)
+{
+ int ret;
+
+ if (hx711_data->channel_set == chan->channel)
+ return 0;
+
+ ret = hx711_read(hx711_data, chan->address);
+ if (ret < 0)
+ return ret;
+
+ ret = hx711_wait_for_ready(hx711_data);
+ if (ret)
+ return ret;
+
+ hx711_data->channel_set = chan->channel;
+
+ return 0;
+}
+
static int hx711_reset_read(struct hx711_data *hx711_data,
const struct iio_chan_spec *chan)
{
+ const struct hx711_chip_info *info = hx711_data->chip_info;
int trailing_pulses;
int ret;
@@ -298,9 +336,16 @@ static int hx711_reset_read(struct hx711_data *hx711_data,
return -EIO;
}
- ret = hx711_set_hx711_channel(hx711_data, chan, &trailing_pulses);
- if (ret < 0)
- return ret;
+ if (info->has_fixed_gain) {
+ ret = hx711_set_hx710b_channel(hx711_data, chan);
+ if (ret < 0)
+ return ret;
+ trailing_pulses = chan->address;
+ } else {
+ ret = hx711_set_hx711_channel(hx711_data, chan, &trailing_pulses);
+ if (ret < 0)
+ return ret;
+ }
return hx711_read(hx711_data, trailing_pulses);
}
@@ -462,6 +507,10 @@ static const struct iio_info hx711_iio_info = {
.attrs = &hx711_attribute_group,
};
+static const struct iio_info hx710b_iio_info = {
+ .read_raw = hx711_read_raw,
+};
+
static const struct iio_chan_spec hx711_chan_spec[] = {
{
.type = IIO_VOLTAGE,
@@ -494,6 +543,68 @@ static const struct iio_chan_spec hx711_chan_spec[] = {
IIO_CHAN_SOFT_TIMESTAMP(2),
};
+/*
+ * HX710B channels (Table 3 in datasheet).
+ * 25 pulses (1 trailing): differential input, 10 SPS -> channel 0
+ * 26 pulses (2 trailing): DVDD-AVDD supply monitor, 40 SPS -> channel 2
+ * 27 pulses (3 trailing): differential input, 40 SPS -> channel 3
+ * .address stores the trailing pulse count for hx711_set_hx710b_channel().
+ * Channel 2 is used for the supply monitor to avoid aliasing the
+ * channel2 terminal of the first differential pair.
+ */
+static const struct iio_chan_spec hx710b_chan_spec[] = {
+ {
+ .type = IIO_VOLTAGE,
+ .differential = 1,
+ .channel = 0,
+ .channel2 = 1,
+ .indexed = 1,
+ .address = 1,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ .scan_index = 0,
+ .scan_type = {
+ .sign = 'u',
+ .realbits = 24,
+ .storagebits = 32,
+ .endianness = IIO_CPU,
+ },
+ },
+ {
+ .type = IIO_VOLTAGE,
+ .channel = 2,
+ .indexed = 1,
+ .address = 2,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ .scan_index = 1,
+ .scan_type = {
+ .sign = 'u',
+ .realbits = 24,
+ .storagebits = 32,
+ .endianness = IIO_CPU,
+ },
+ },
+ {
+ .type = IIO_VOLTAGE,
+ .differential = 1,
+ .channel = 3,
+ .channel2 = 4,
+ .indexed = 1,
+ .address = 3,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ .scan_index = 2,
+ .scan_type = {
+ .sign = 'u',
+ .realbits = 24,
+ .storagebits = 32,
+ .endianness = IIO_CPU,
+ },
+ },
+ IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
static const struct hx711_chip_info hx711_chip = {
.name = "hx711",
.channels = hx711_chan_spec,
@@ -501,6 +612,15 @@ static const struct hx711_chip_info hx711_chip = {
.num_channels = ARRAY_SIZE(hx711_chan_spec),
};
+static const struct hx711_chip_info hx710b_chip = {
+ .name = "hx710b",
+ .channels = hx710b_chan_spec,
+ .iio_info = &hx710b_iio_info,
+ .num_channels = ARRAY_SIZE(hx710b_chan_spec),
+ .fixed_gain_val = 128,
+ .has_fixed_gain = true,
+};
+
static int hx711_probe(struct platform_device *pdev)
{
const struct hx711_chip_info *chip_info;
@@ -543,32 +663,42 @@ 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;
/*
- * with
- * full scale differential input range: AVDD / GAIN
+ * With
+ * full scale differential input range: reference / GAIN
* full scale output data: 2^24
* we can say:
- * AVDD / GAIN = 2^24
+ * reference / GAIN = 2^24
* therefore:
- * 1 LSB = AVDD / GAIN / 2^24
- * AVDD is in uV, but we need 10^-9 mV
+ * 1 LSB = reference / GAIN / 2^24
+ * reference is in uV, but we need 10^-9 mV
* approximately to fit into a 32 bit number:
- * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV]
+ * 1 LSB = (reference * 100) / GAIN / 1678 [10^-9 mV]
*/
/* we need 10^-9 mV */
ret *= 100;
- for (i = 0; i < HX711_GAIN_MAX; i++)
- hx711_data->gain_scale[i] =
- ret / hx711_gain_to_scale[i].gain / 1678;
+ if (chip_info->has_fixed_gain) {
+ for (i = 0; i < HX711_GAIN_MAX; i++)
+ hx711_data->gain_scale[i] =
+ ret / chip_info->fixed_gain_val / 1678;
+ hx711_data->gain_set = chip_info->fixed_gain_val;
+ } else {
+ for (i = 0; i < HX711_GAIN_MAX; i++)
+ hx711_data->gain_scale[i] =
+ ret / hx711_gain_to_scale[i].gain / 1678;
- hx711_data->gain_set = 128;
- hx711_data->gain_chan_a = 128;
+ hx711_data->gain_set = 128;
+ hx711_data->gain_chan_a = 128;
+ }
hx711_data->clock_frequency = 400000;
ret = device_property_read_u32(&pdev->dev, "clock-frequency",
@@ -607,6 +737,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 },
{ }
};
@@ -624,6 +755,6 @@ 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");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:hx711-gpio");
--
2.43.0
next prev parent reply other threads:[~2026-05-03 12:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 12:09 [PATCH v6 00/11] iio: adc: hx711: add HX710B support Piyush Patle
2026-05-03 12:09 ` [PATCH v6 01/11] dt-bindings: iio: adc: hx711: clean up existing binding text Piyush Patle
2026-05-03 12:09 ` [PATCH v6 02/11] dt-bindings: iio: adc: hx711: add VSUP supply property Piyush Patle
2026-05-04 6:51 ` Krzysztof Kozlowski
2026-05-04 15:58 ` Jonathan Cameron
2026-05-03 12:09 ` [PATCH v6 03/11] dt-bindings: iio: adc: hx711: add RATE GPIO property Piyush Patle
2026-05-04 6:52 ` Krzysztof Kozlowski
2026-05-03 12:09 ` [PATCH v6 04/11] dt-bindings: iio: adc: hx711: add HX710B support Piyush Patle
2026-05-03 12:09 ` [PATCH v6 05/11] iio: adc: hx711: move scale computation to per-device storage Piyush Patle
2026-05-04 14:25 ` Andy Shevchenko
2026-05-04 16:00 ` Jonathan Cameron
2026-05-03 12:09 ` [PATCH v6 06/11] iio: adc: hx711: introduce hx711_chip_info structure Piyush Patle
2026-05-04 14:48 ` Andy Shevchenko
2026-05-03 12:09 ` [PATCH v6 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Piyush Patle
2026-05-03 12:09 ` [PATCH v6 08/11] iio: adc: hx711: split variable assignments in hx711_read and hx711_reset Piyush Patle
2026-05-04 15:46 ` Andy Shevchenko
2026-05-04 16:03 ` Jonathan Cameron
2026-05-03 12:09 ` [PATCH v6 09/11] iio: adc: hx711: localize loop iterators in hx711_read Piyush Patle
2026-05-04 15:48 ` Andy Shevchenko
2026-05-03 12:09 ` [PATCH v6 10/11] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read Piyush Patle
2026-05-04 16:05 ` Jonathan Cameron
2026-05-03 12:09 ` Piyush Patle [this message]
2026-05-04 15:52 ` [PATCH v6 11/11] iio: adc: hx711: add support for HX710B Andy Shevchenko
2026-05-04 16:59 ` Jonathan Cameron
2026-05-04 16:02 ` Jonathan Cameron
2026-05-04 15:54 ` [PATCH v6 00/11] iio: adc: hx711: add HX710B support Andy Shevchenko
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=20260503120949.80292-12-piyushpatle228@gmail.com \
--to=piyushpatle228@gmail.com \
--cc=ak@it-klinger.de \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.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