From nobody Wed Jun 17 05:13:56 2026 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1F4D1DF256 for ; Wed, 22 Apr 2026 17:59:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880766; cv=none; b=EwoMynUn6YrcIlP9CLR3ZVg0xg9sfyUNDDyocSjg7VQhnS4fAcFp+A8NAarx+i+DDXAIxTKrFTadNjSPwJRecR+ptVJkbhcd/dweJz86va1iX93tnXMsXSGAtTBDmEXHgE5/q7U6RMtxl/qnnO8bRJZWSVA1uUVk4ryjCCeCihY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880766; c=relaxed/simple; bh=0EQVOM5UfQLhGCbzUWEfNLcVwhW6GiAbaiGqT5rlV4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOlH3or12Zir+rt7OIXNxrGG3CMwXGe4fEJc5aVBLx4ZvXIkQbKLTVtGC1XmmKj2pRjo2b0lLmx15knGyWZt943ZxM1J8nyM4g3ILhTqWx/H/L9mFJmvvIsgVL8lJgTqKUbWeUaObmRq5fff5sPnm7IOxJt19yXIxnb7/7vjYqw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c+/KLL9z; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c+/KLL9z" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-c795a47186bso2381927a12.0 for ; Wed, 22 Apr 2026 10:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776880763; x=1777485563; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ftXrLDJi6w7JnF2X+ObW5xlG+z41xv2Ad84lI5gTtk8=; b=c+/KLL9zUiz8CPbAnHPZAgbqFclMUpqYAZsIXo4NbXxwxRZu26pm1p4S9q5AqUy+pv 0ENewM5evP9eHjkvMyk0PE5ZMtCkELXMDSnh0Upgp2+3KmHpT+d1gcz/O9V8kIHAQJ8K iSQmJub5V+BI/5Fc2uvBaFFkn8D/R8qdvxEAAIPG6CRA2gLO8h7iZGR9TmnUYtHDtveg I0sGrN0qdZoXmizi4jC5PP6PSN2APJ5P6lLHB1uddmgqHyZuVApaJkgRYBeNLBWQ/lnz XXyr2LN/NmKvweMZXHE42ZCD5BT0WeFIGo7FZih3HJoyStXMwOGO0JKN8SfmgqZvSoZf UV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776880763; x=1777485563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ftXrLDJi6w7JnF2X+ObW5xlG+z41xv2Ad84lI5gTtk8=; b=REtc2Lly4pRKJc+h6U/fUSyeMGre/SsJzJ7gd2+WQ65h7jyiWR8cMCR9mPJMJfwd0X ZGLDURPbKK8jhnY+mf0NnI1Z5/nMY2ATtKT3j/ZGRCIghbsdChd+iE27J/bhnfeZLGha xEwS2pv338V284b1lrfsidTvFlq/X172IVpfFMtnhzk6lhD4qWWYVXbsKTzeoRWd4x3l qWUOayCqIhqxN9ya123v49sw0O0oM8zsa4/j7ZsX9Vk6fBUowdvplbGlWYh6bXQB1bgf f7Cn9xEdRR+epfKj/fFWVwWW0Gu03VOvOz8vDsWD7Q7Zzzjn9ZiSFj21xNi9NzBQ4TpO cuCw== X-Forwarded-Encrypted: i=1; AFNElJ+ltxi+0IoHUduvEq2rDCOHNV24hiFFzrdXoiH+/0sPnd1R2gx2TiIeLF77XSIkob8lR6N0YcKpl+gJkeo=@vger.kernel.org X-Gm-Message-State: AOJu0YxSu+IaXrwbUB2yDB70VQy9QcRmesKGK3bqyA4hHt0GLA6hITfo K1YaNr9BvgZA39ZWD5wguDIuB6cHUN0hCXtR7UBDpdUHX4XToSPd6cHl X-Gm-Gg: AeBDies9Gr0fRsqSjjxTpSd46b2SY+teqwfjOuzM16vIHguhO8bw3Udhg31IMukiJU0 LSf0QaIc6qKALDs4xkseSasaGNQp7x7JopSSbWwG+tPiJGiKwIK8nzKL6GDKIHLDtspKsEyFzNM 7nGqwY5u32d2H03DXiAvs/FnFuNlIPpsu4/lkzN5Sb9WG57wGtNbVQQ6ACaiE4kTEPTk+boEwSI vtNmKEBzCdFjoVoCiQUY2ORcjaeZHmzsZj7bqfYiErLgD4y40pGvg9TLrEADIYU/pGB7atPIxj5 lFhNcGv0NfI5qeJ6/pVlTQ7xHiNsjmJlKaQqhWNoi0dtgE149da3tr6MyMBnuC3sbo1lmTD/Mkd nagT+E2MCBzyPncjIQ47otfZ22AvcjvqWQsGsV4EQui6khUYfTSMQGtCTGd8MLacAYWnIE8/fvz X6Epujj9fT/a6t+9UgIBxAhywAwmg7Mvs84E2y+IWjBUdrlTVR68+hmY5DoGVhWI+OXreef92OI ioFIZBBVyToFu8qF7+iGWP/eTqnAxZGc8WN8wC/c3Q/Mjhg/GnDQaup8NzUCw== X-Received: by 2002:a05:6a20:3d82:b0:39b:af8e:496f with SMTP id adf61e73a8af0-3a08c910f4dmr20227565637.14.1776880762895; Wed, 22 Apr 2026 10:59:22 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d01f:48f3:f940:b423:53fc]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976f9cacasm15174361a12.8.2026.04.22.10.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 10:59:22 -0700 (PDT) From: Piyush Patle To: Jonathan Cameron , Andreas Klinger Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] dt-bindings: iio: adc: avia-hx711: add avia,hx710b compatible Date: Wed, 22 Apr 2026 23:29:08 +0530 Message-ID: <20260422175910.1258579-2-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260422175910.1258579-1-piyushpatle228@gmail.com> References: <20260422175910.1258579-1-piyushpatle228@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The HX710B shares the same two-wire interface as the HX711 but differs in its channel and gain model: gain is fixed at 128 and the number of trailing PD_SCK pulses selects the input channel rather than the gain. Add avia,hx710b to the compatible enum. Document the chip differences in the description and add chip-specific supply properties (dvdd-supply, vsup-supply) for the HX711, a rate-gpios property for the HX711 RATE pin, and an allOf constraint that forbids HX711-only properties on HX710B nodes. Clarify the clock-frequency description to reflect its actual purpose: controlling the SCK bit-bang timing. Signed-off-by: Piyush Patle Reviewed-by: Krzysztof Kozlowski --- Changes in v3: - Drop the vref-supply mention from avdd-supply; no such binding property exists. - Drop the clock-frequency sentence that repeated the schema default. - Restore the example node name to weight. - Remove the separate HX710B example. Changes in v2: - Remove driver implementation details from the description and describe hardware behaviour only. - Drop unrelated punctuation cleanup. - Add dvdd-supply and vsup-supply optional properties for HX711. - Add rate-gpios optional property for the HX711 RATE pin and forbid it on HX710B. - Add the allOf if/then block forbidding HX711-only properties on HX710B nodes. - Clarify clock-frequency as SCK bit-bang timing, not a crystal or external clock input. - Sort compatible enum alphabetically. - Remove redundant example comments. - Update the HX711 example to exercise rate-gpios. .../bindings/iio/adc/avia-hx711.yaml | 50 +++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml b/Do= cumentation/devicetree/bindings/iio/adc/avia-hx711.yaml index 9c57eb13f892..0c7c5843b8d2 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -4,24 +4,24 @@ $id: http://devicetree.org/schemas/iio/adc/avia-hx711.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: AVIA HX711 ADC chip for weight cells +title: AVIA HX711 and HX710B ADCs =20 maintainers: - Andreas Klinger =20 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 + 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. =20 - Specifications about the driver can be found at: - http://www.aviaic.com/ENProducts.aspx + The HX710B is a 24-bit ADC with fixed gain of 128. Channel 0 is the + differential input and channel 1 measures the DVDD-AVDD supply + voltage difference. =20 properties: compatible: enum: + - avia,hx710b - avia,hx711 =20 sck-gpios: @@ -40,13 +40,44 @@ properties: =20 avdd-supply: description: - Definition of the regulator used as analog supply + Analog supply voltage (AVDD). Also serves as the voltage reference on + both chips. + + dvdd-supply: + description: + Digital supply voltage (DVDD). HX711 only. + + vsup-supply: + description: + Supply voltage for the on-chip regulator (VSUP). HX711 only. + + rate-gpios: + description: + GPIO connected to the RATE pin (HX711 only). 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 =20 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 =20 +allOf: + - if: + properties: + compatible: + const: avia,hx710b + then: + properties: + vsup-supply: false + dvdd-supply: false + rate-gpios: false + required: - compatible - sck-gpios @@ -62,6 +93,7 @@ examples: compatible =3D "avia,hx711"; sck-gpios =3D <&gpio3 10 GPIO_ACTIVE_HIGH>; dout-gpios =3D <&gpio0 7 GPIO_ACTIVE_HIGH>; + rate-gpios =3D <&gpio0 9 GPIO_ACTIVE_HIGH>; avdd-supply =3D <&avdd>; clock-frequency =3D <100000>; }; --=20 2.43.0 From nobody Wed Jun 17 05:13:56 2026 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73E2139B49F for ; Wed, 22 Apr 2026 17:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880770; cv=none; b=L41xmUpDsxvW6z56G09WoUrgzKw29IHTZkkdr9fJHdRmzMh22/FPval4b7sF6oCqbQWb/bGRcCG8tCBBfNQN/XjSAHc7wTj934j3QvERQFbwqZk1C8ce29rruMfjcMCI0ytqC4sQnQzuqf/FGCI3aj/a8hd/acdbKfODFxDvlGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880770; c=relaxed/simple; bh=Jum5PzYDFBM/uD40Ud1r3A5PJoqMkSUn/W06zgsAVXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i77Q2Tid0nQlpt/lRCae3q8AacgBeenAuaPRM51Xxy4k4NZTdqFdlxHpO92T61/RSzO5H/cKCgO7cCBX6IzsvyaJQFaLnpbGJR1SdPIh+W0ZGu6bHeS7EZuHFsFpLCc9UASbGfK8gQzeVt48o9IxONhK7+7hCn79USUoAM14MlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CS/g0Jao; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CS/g0Jao" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c741692db4cso1772463a12.1 for ; Wed, 22 Apr 2026 10:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776880768; x=1777485568; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n37RD+E+6djSJ5KaN5Pz6THH1x0Tdc7Kjmf8WQiqgnA=; b=CS/g0JaoHY2zBndtAJplR31t37LwuQ89/e6HnnrVr+wdq6BYkPjvqELlLc8iXhGNZZ DBGTKkeeJMUw15q9LuG9+ayQtrSo8Q09J0StfkiKAXe9daTEh8PfSmFyz6tXq2U294Vm dVQluun3Lc5rRmpFfY9/MW8+T9eztab1D1u9j8rlZ6Piw2qX3KoTrNwCJtjliB/MMWBf DvDQMNeUhvSGvrzCTd2ZlrfaQBNTppihm2GBJkEMeynCPS0shi5CaAwwwBwfh79VVbc0 X4DO9HNThC0EIDiN6Fx+6nqx/3YN9hBvWOlp2pJuX7g4pKh/2/fbMvYFy8TFSKpA3JJY Q5Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776880768; x=1777485568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=n37RD+E+6djSJ5KaN5Pz6THH1x0Tdc7Kjmf8WQiqgnA=; b=KNCctQcOTkmKQEgF7QL3uYkENrI99ACddfPewOa2IZb/WMPa5exM/usZ1RB9eJ0RXi 5FDWNbgzw5kFxs5simxMc+P1mBLSVYQvciwHhO9KiDp6ofJuTyq9GnZmUZu91Xyy5hKk /bGQHfRqLe4FxT1HbUNP+p81pt94iyKgAL6s/flxsEQtzMgk/poX9cunShqKY/uNKDEz AuaHaByeTHYfZwk9z3ryX7//hb1Q4WyeihY1gS4GHinkUBcmEQlZQlI3X0Omq0tkQIOk YVQRPqHC+bntMqcfQ4u1MWdtfLBIRq2s24DeLg7+bfc0pmjGSadSHL5x/lgdIPH9s6c7 Rzag== X-Forwarded-Encrypted: i=1; AFNElJ92EX9zvLd1mQn941YVPUrnbqdSzHDLsbg0WSJLIhD/18n+iob+/L6Rpv60+pq9mWBagkMZm7TRYlR5D/I=@vger.kernel.org X-Gm-Message-State: AOJu0Yw08z88gcDAZYc8Oc8mN//d2+ELoeKYtvqTX7fNAPvt/CgOXxBV Vg6RvuIbaglFI/qIa/XCmzU48nQNPKtOizOEAkbO1pb8udGEYdIzlQNG X-Gm-Gg: AeBDieu+lGhuksTAFgwmcfeT68O5g1VKWV5wLbf+UhawX65D8NzJu4d77cjcNsDxbXZ nGY7NZ5NQeDg3WGZSuSyNyC7oztYsW7VC+AotTO5XlW2lSDCQu3bx0kDXD9PILWoJpaPvJjoWBE MnaTcVicWsMw8paaMSbhzCHQLZPnswvFYgrAthAY3sRPw9MuSGg/B3qlNQBALz125i2sJ/79cqE FZwptH/xXYOVVbhAXn8se1IpEz6O65/w4CN7xL2mAG5xzKpV/jnqnN71pqvXe82bIdVxV79VbMK YloqrrqYvenybTBvZmcqKnvZI+4SrZpmG8DBdwQxmtOBbqblj6yxOgM7zmdG8X9w76cGY7gBjFP SIq76gVbzs4SXdZBGuOL67n/JIwYMJef4W4by5xZpkfu8EHljmLLMwwwr8s8w5b/Yl8iFrgOtJy /gUs3EaT0OxtNHNeqqZqC6rYapAbel/pRzRCeprdS/NHGidmRXLFAebOWCKTc9ArRYwx1u+1oVO 6+Gwaa8A7qb9IrmAvSf93gC8yjDuuZi18hNP57sXsukaDQgbxQ= X-Received: by 2002:a05:6300:210a:b0:39f:b075:32f with SMTP id adf61e73a8af0-3a08cd4833dmr21613324637.38.1776880767850; Wed, 22 Apr 2026 10:59:27 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d01f:48f3:f940:b423:53fc]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976f9cacasm15174361a12.8.2026.04.22.10.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 10:59:27 -0700 (PDT) From: Piyush Patle To: Jonathan Cameron , Andreas Klinger Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/3] iio: adc: hx711: refactor to per-chip hx711_chip_info structure Date: Wed, 22 Apr 2026 23:29:09 +0530 Message-ID: <20260422175910.1258579-3-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260422175910.1258579-1-piyushpatle228@gmail.com> References: <20260422175910.1258579-1-piyushpatle228@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce hx711_chip_info to hold per-variant static configuration: device name, IIO channel spec, channel count, and iio_info pointer. Store a chip_info pointer in hx711_data and populate indio_dev fields from it at probe instead of hardcoding them. Pass trailing pulse count directly to hx711_read() instead of computing it inside the function, and change hx711_reset_read() to take a const struct iio_chan_spec * instead of an integer channel index so callers can pass the full channel descriptor. Use device_get_match_data() to look up the chip_info from the of_device_id table. No functional change for existing HX711 users. Signed-off-by: Piyush Patle --- Changes in v3: - New patch split out from the HX710B support patch. - Keep this as a standalone refactor for the existing HX711 path. - Use unsigned int for the channel count and trailing pulse count. - Use a loop-local unsigned int for the trailing pulse loop. - Add direct includes for ARRAY_SIZE and basic types. - Align Kconfig, file header, and module description wording with the "HX711 and compatible ADCs" phrasing. Changes in v2: - N/A; this standalone refactor patch is new in v3. drivers/iio/adc/Kconfig | 7 ++-- drivers/iio/adc/hx711.c | 92 +++++++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 60038ae8dfc4..f18692aea795 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -784,13 +784,14 @@ config HI8435 called hi8435. =20 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: + - HX711 + which are used for bridge sensors such as weigh cells. =20 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 1db8b68a8f64..a444a2872257 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -1,12 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * HX711: analog to digital converter for weight sensor module + * HX711 and compatible ADCs driver for weight sensor modules * * Copyright (c) 2016 Andreas Klinger */ +#include #include #include #include +#include #include #include #include @@ -76,12 +78,27 @@ static int hx711_get_scale_to_gain(int scale) return -EINVAL; } =20 +/** + * struct hx711_chip_info - per-variant static configuration + * @name: IIO device name + * @channels: channel specification + * @num_channels: number of channels + * @iio_info: IIO info ops for this variant + */ +struct hx711_chip_info { + const char *name; + const struct iio_chan_spec *channels; + unsigned int num_channels; + const struct iio_info *iio_info; +}; + struct hx711_data { struct device *dev; struct gpio_desc *gpiod_pd_sck; struct gpio_desc *gpiod_dout; int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ + const struct hx711_chip_info *chip_info; struct mutex lock; /* * triggered buffer @@ -92,10 +109,7 @@ struct hx711_data { aligned_s64 timestamp; } buffer; /* - * delay after a rising edge on SCK until the data is ready DOUT - * this is dependent on the hx711 where the datasheet tells a - * maximum value of 100 ns - * but also on potential parasitic capacities on the wiring + * Delay after SCK rising edge before sampling DOUT. */ u32 data_ready_delay_ns; u32 clock_frequency; @@ -139,9 +153,13 @@ static int hx711_cycle(struct hx711_data *hx711_data) return gpiod_get_value(hx711_data->gpiod_dout); } =20 -static int hx711_read(struct hx711_data *hx711_data) +/* + * Clock out 24 data bits and then send trailing pulses to select the + * next channel/gain state. + */ +static int hx711_read(struct hx711_data *hx711_data, unsigned int trailing= _pulses) { - int i, ret; + int ret; int value =3D 0; int val =3D gpiod_get_value(hx711_data->gpiod_dout); =20 @@ -149,7 +167,7 @@ static int hx711_read(struct hx711_data *hx711_data) if (val) return -EIO; =20 - for (i =3D 0; i < 24; i++) { + for (int i =3D 0; i < 24; i++) { value <<=3D 1; ret =3D hx711_cycle(hx711_data); if (ret) @@ -158,7 +176,7 @@ static int hx711_read(struct hx711_data *hx711_data) =20 value ^=3D 0x800000; =20 - for (i =3D 0; i < hx711_get_gain_to_pulse(hx711_data->gain_set); i++) + for (unsigned int i =3D 0; i < trailing_pulses; i++) hx711_cycle(hx711_data); =20 return value; @@ -213,6 +231,7 @@ static int hx711_reset(struct hx711_data *hx711_data) return val; } =20 +/* Select HX711 channel/gain for the next conversion. */ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int c= han) { int ret; @@ -221,7 +240,8 @@ static int hx711_set_gain_for_channel(struct hx711_data= *hx711_data, int chan) if (hx711_data->gain_set =3D=3D 32) { hx711_data->gain_set =3D hx711_data->gain_chan_a; =20 - ret =3D hx711_read(hx711_data); + ret =3D hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) return ret; =20 @@ -233,7 +253,8 @@ static int hx711_set_gain_for_channel(struct hx711_data= *hx711_data, int chan) if (hx711_data->gain_set !=3D 32) { hx711_data->gain_set =3D 32; =20 - ret =3D hx711_read(hx711_data); + ret =3D hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) return ret; =20 @@ -246,27 +267,24 @@ static int hx711_set_gain_for_channel(struct hx711_da= ta *hx711_data, int chan) return 0; } =20 -static int hx711_reset_read(struct hx711_data *hx711_data, int chan) +static int hx711_reset_read(struct hx711_data *hx711_data, + const struct iio_chan_spec *chan) { + unsigned int trailing_pulses; int ret; - int val; =20 - /* - * hx711_reset() must be called from here - * because it could be calling hx711_read() by itself - */ + /* Reset first so the read starts from a known chip state. */ if (hx711_reset(hx711_data)) { dev_err(hx711_data->dev, "reset failed!"); return -EIO; } =20 - ret =3D hx711_set_gain_for_channel(hx711_data, chan); + ret =3D hx711_set_gain_for_channel(hx711_data, chan->channel); if (ret < 0) return ret; =20 - val =3D hx711_read(hx711_data); - - return val; + trailing_pulses =3D hx711_get_gain_to_pulse(hx711_data->gain_set); + return hx711_read(hx711_data, trailing_pulses); } =20 static int hx711_read_raw(struct iio_dev *indio_dev, @@ -279,7 +297,7 @@ static int hx711_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: mutex_lock(&hx711_data->lock); =20 - *val =3D hx711_reset_read(hx711_data, chan->channel); + *val =3D hx711_reset_read(hx711_data, chan); =20 mutex_unlock(&hx711_data->lock); =20 @@ -332,7 +350,8 @@ static int hx711_write_raw(struct iio_dev *indio_dev, if (gain !=3D 32) hx711_data->gain_chan_a =3D gain; =20 - ret =3D hx711_read(hx711_data); + ret =3D hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) { mutex_unlock(&hx711_data->lock); return ret; @@ -368,7 +387,7 @@ static irqreturn_t hx711_trigger(int irq, void *p) =20 iio_for_each_active_channel(indio_dev, i) { hx711_data->buffer.channel[j] =3D hx711_reset_read(hx711_data, - indio_dev->channels[i].channel); + &indio_dev->channels[i]); j++; } =20 @@ -455,10 +474,18 @@ static const struct iio_chan_spec hx711_chan_spec[] = =3D { IIO_CHAN_SOFT_TIMESTAMP(2), }; =20 +static const struct hx711_chip_info hx711_chip =3D { + .name =3D "hx711", + .channels =3D hx711_chan_spec, + .num_channels =3D ARRAY_SIZE(hx711_chan_spec), + .iio_info =3D &hx711_iio_info, +}; + static int hx711_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; struct hx711_data *hx711_data; + const struct hx711_chip_info *chip_info; struct iio_dev *indio_dev; int ret; int i; @@ -472,6 +499,9 @@ static int hx711_probe(struct platform_device *pdev) =20 mutex_init(&hx711_data->lock); =20 + chip_info =3D device_get_match_data(dev); + hx711_data->chip_info =3D chip_info; + /* * PD_SCK stands for power down and serial clock input of HX711 * in the driver it is an output @@ -517,6 +547,8 @@ static int hx711_probe(struct platform_device *pdev) hx711_data->gain_set =3D 128; hx711_data->gain_chan_a =3D 128; =20 + indio_dev->info =3D chip_info->iio_info; + hx711_data->clock_frequency =3D 400000; ret =3D device_property_read_u32(&pdev->dev, "clock-frequency", &hx711_data->clock_frequency); @@ -533,11 +565,10 @@ static int hx711_probe(struct platform_device *pdev) hx711_data->data_ready_delay_ns =3D 1000000000 / hx711_data->clock_frequency; =20 - indio_dev->name =3D "hx711"; - indio_dev->info =3D &hx711_iio_info; + indio_dev->name =3D chip_info->name; indio_dev->modes =3D INDIO_DIRECT_MODE; - indio_dev->channels =3D hx711_chan_spec; - indio_dev->num_channels =3D ARRAY_SIZE(hx711_chan_spec); + indio_dev->channels =3D chip_info->channels; + indio_dev->num_channels =3D chip_info->num_channels; =20 ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, @@ -554,7 +585,7 @@ static int hx711_probe(struct platform_device *pdev) } =20 static const struct of_device_id of_hx711_match[] =3D { - { .compatible =3D "avia,hx711", }, + { .compatible =3D "avia,hx711", .data =3D &hx711_chip }, { } }; =20 @@ -571,7 +602,6 @@ static struct platform_driver hx711_driver =3D { module_platform_driver(hx711_driver); =20 MODULE_AUTHOR("Andreas Klinger "); -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"); - --=20 2.43.0 From nobody Wed Jun 17 05:13:56 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05EC039D6F7 for ; Wed, 22 Apr 2026 17:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880774; cv=none; b=QXi50ZMp4AYUKnnW0iolZL8onqEqjI+MEXaKdV1fKM6gxvcC4tb3JNDXsZnhcFjRhC26OT7+a3QtuOdCnK+yAVsQsL270XRW+N74f61d8FDL/B2g8/49V9s4nH/biHfn163iOj15a9aYqKIY/4MsbZKENPSvTWh6qGDfWbavjtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776880774; c=relaxed/simple; bh=PWslvnIp0PlT6M3bafPFkQXf9mBHZUb6tesc0Bm/FCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A618EDm2QpDm96IFqq+2SLtr/+N9Auk1WgJ7zfCbqOF9A8hQ8UJrZ6ZeOkKJo0j+cEnManHc53gfcR/bi7KjwPm1Kr3bIWYYkMFP6ziIeOmDy2r2i0pjHFmNYewELaVDtZ8ZUiILNj8xBf1A8hwmhuhUfCZEe6Z4pAoy6DdRNbc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=URNEOucW; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="URNEOucW" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-35fb16e56efso3806823a91.2 for ; Wed, 22 Apr 2026 10:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776880772; x=1777485572; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V0Mpiw2CDpaBtsNVKYQKb60LEod4FHSPV4DukqsY4eg=; b=URNEOucWcBJHREiTPO/1S78/wHVj9APS/uwhjpD1zDFxPXxpv+/OV7oEbU0gTgibf8 x3/5gmSI8C0ATWVWMwS/MSHSykBKsUAa96Nx4S+7bkQTDTqGvGEeL+c1XN/T8yUVMSu1 sJ5E7YiyYkIAYYC1zB/aR/ZxQEAGEzyC+wr9RT2Ls+uZ+as5RWMKj25M3W5cGthdlRXX 2UQyf8uzLYeiCMyaxywswX7tNP6F406MCocU19MgCcB1ZnSDBhan59kgLSIA+Nrgk1NJ Mk72A7P76Bh9zRzmdU/sIj9uwDlMzBHkHF8RUKAQ17IZFeaMTvSKmy11Yel0taDtXFUT R1kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776880772; x=1777485572; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=V0Mpiw2CDpaBtsNVKYQKb60LEod4FHSPV4DukqsY4eg=; b=IqBEbWL6yz5WBaD1MmKoAJOMDkuQvz3jk4FHULV796wuy2A7QCap1QV92L+HMmOQ3Q nYwK+x8HZOJj8XSdCGpkRmgRNxZc7I68WyW77l4Dk8lYgOY6Ohl7S58zbnGp6DPw3HvM simpTIj+i8Gt+8ItW/LiRoM9KGNKYjEHaofHGncMj4dPI49V+9BEZnUjOalw/MJAw7iD ZUIueTUbrycS6azMMl6adpg0anRz3hb6NviMktQAIIGrT5WUKN4Ksm8QDH1DH8ACJkOu WJzB3p0VSSJ2u7i7IFHNZ3Go7PQqBaBAmMb+S0VDE8CcvKPYYT+pKM6DVLTYHmRNYKEg XLAA== X-Forwarded-Encrypted: i=1; AFNElJ8e1m9IKvnWXp8EMAnh+rgr2gG2mq/KBMpBBjzreiEOl1YeG4mhw4mBRLMjSc1d/4IaekiGQ/7O5e7R0mg=@vger.kernel.org X-Gm-Message-State: AOJu0YxbFRpWh+v2aLmnG2q0seinuGHkiRP3tM9FhiXHK5GFmxcJtUa9 z+GjxoagpztAcljbUDAqmeS63CPrLysQvWawWneVuBazh28CLpK7MVL4 X-Gm-Gg: AeBDieuNWS3frttyGdmNLD2yYC3pwClxM9d/zDXb7pZ60IjO2SdGI9vyU4exE2N5peZ TWuN/B/yrohcOAOLKLfr7lu/30bpSOvB4pubtYiB67lcWfmFI/BxnlHKIVOf/XmVbp/C5yLptAH CjLz83NPyDRgK3pinytIuJJZqZ52r94ENlVYPd7SQ5d8ZKwo4V7eiKRVDwIEFz19YGB0nG/NOk4 6mhnrwNHeZAhKVQy+g18rKW3PvjTlF8ydrZfajFP64A36N8ui9AxauB3MuwfgQwxhUFBTScUhQT hsVqqNB6xXwlomVUcVJy7hjniB4QsnXVtNBtIfBggFa4bgmGE+TC1cdS9DC6C5vmSc3SyZO8gIO kFGJEM07LdTx1cCTaVxF4tc3Jl8+WSKORChrmFlwy295KuhEil0zMAAXp+8P3hGs8mQCkjajkRE e+2sHXqzq/bsIRP5SrRvepFpw89sAAhSMy2rkDB4HAWBMzEtClSyXkerszoz6fGiYT4ayLjB2Fu UyzolPTugeqffDRetfjYj6tLaBR9na8GDxJBn5iyOcl07c1PnQ= X-Received: by 2002:a05:6a20:3d19:b0:3a2:d838:bfdb with SMTP id adf61e73a8af0-3a2d8393b61mr14140642637.29.1776880772239; Wed, 22 Apr 2026 10:59:32 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d01f:48f3:f940:b423:53fc]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976f9cacasm15174361a12.8.2026.04.22.10.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 10:59:31 -0700 (PDT) From: Piyush Patle To: Jonathan Cameron , Andreas Klinger Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/3] iio: adc: hx711: add support for HX710B Date: Wed, 22 Apr 2026 23:29:10 +0530 Message-ID: <20260422175910.1258579-4-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260422175910.1258579-1-piyushpatle228@gmail.com> References: <20260422175910.1258579-1-piyushpatle228@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for the AVIA HX710B ADC, which shares the HX711 GPIO interface but has a fixed gain of 128 and uses trailing PD_SCK pulses to select between the differential input and the DVDD-AVDD supply monitor. Model the HX710B with its own channel specification and iio_info. Store the HX710B trailing pulse counts in chan->address and add fixed-gain handling so the HX711 selectable-gain path remains separate from the HX710B fixed-gain path. The HX710B datasheet documents a single fixed PGA gain of 128 and does not provide configurable gain selection like the HX711. Order hx711_chip_info as pointers first, then unsigned int fields, then bool. pahole then reports no internal holes in the structure; the remaining padding is tail padding from 8-byte alignment. Signed-off-by: Piyush Patle --- Changes in v3: - Add HX710B support on top of the separate hx711_chip_info refactor. - Update channel_set only after hx711_read() and hx711_wait_for_ready() both succeed. - Keep a single HX710B fixed-gain scale based on the datasheet's fixed PGA gain of 128; do not apply the HX711 channel-B gain of 32 to the HX710B supply monitor path. - Use unsigned int for channel state and fixed-gain scale storage. - Keep HX710B trailing pulse counts in chan->address. - Describe HX710B channel 0 as a differential IIO channel. - Reorder hx711_chip_info fields based on pahole output so the structure has no internal holes. Changes in v2: - Fix pulse count bug: HX710B values were {25, 26} total SCK cycles; corrected to {1, 2} trailing pulses because hx711_read() already clocks the 24 data bits. - Add .differential =3D 1 and .channel2 =3D 1 to HX710B channel 0. - Move trailing pulse counts from a separate array to chan->address. - Replace chan_pulse_count tests with a dedicated fixed_gain flag. - Add fixed_gain_val to hx711_chip_info. - Add the iio_info pointer to hx711_chip_info and assign indio_dev->info from chip_info. - Remove the NULL check after device_get_match_data(). - Remove reset_channel from hx711_chip_info. - Change hx711_reset_read() and hx710b_set_channel() to take const struct iio_chan_spec *. - Revert unrelated hx711_data struct member alignment noise. - Sort of_device_id entries alphabetically. - Expand the commit message to explain HX711 versus HX710B trailing pulse behaviour. - Restore the file header to mention weight sensor modules. drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/hx711.c | 134 +++++++++++++++++++++++++++++++++++----- 2 files changed, 120 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index f18692aea795..09a1b29fbd9c 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -790,6 +790,7 @@ config HX711 select IIO_TRIGGERED_BUFFER help 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. =20 diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index a444a2872257..d7050bec53b4 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -82,14 +82,18 @@ static int hx711_get_scale_to_gain(int scale) * struct hx711_chip_info - per-variant static configuration * @name: IIO device name * @channels: channel specification - * @num_channels: number of channels * @iio_info: IIO info ops for this variant + * @num_channels: number of channels + * @fixed_gain: true if the variant has a fixed ADC gain (e.g. HX710B) + * @fixed_gain_val: the fixed gain value used to compute scale (when fixed= _gain) */ struct hx711_chip_info { const char *name; const struct iio_chan_spec *channels; - unsigned int num_channels; const struct iio_info *iio_info; + unsigned int num_channels; + unsigned int fixed_gain_val; + bool fixed_gain; }; =20 struct hx711_data { @@ -98,6 +102,8 @@ struct hx711_data { struct gpio_desc *gpiod_dout; int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ + unsigned int channel_set; /* HX710B current channel */ + unsigned int scale; /* HX710B fixed scale */ const struct hx711_chip_info *chip_info; struct mutex lock; /* @@ -206,6 +212,7 @@ static int hx711_wait_for_ready(struct hx711_data *hx71= 1_data) =20 static int hx711_reset(struct hx711_data *hx711_data) { + const struct hx711_chip_info *info =3D hx711_data->chip_info; int val =3D hx711_wait_for_ready(hx711_data); =20 if (val) { @@ -224,8 +231,11 @@ static int hx711_reset(struct hx711_data *hx711_data) =20 val =3D hx711_wait_for_ready(hx711_data); =20 - /* after a reset the gain is 128 */ - hx711_data->gain_set =3D HX711_RESET_GAIN; + /* Restore variant default after reset. */ + if (info->fixed_gain) + hx711_data->channel_set =3D 0; + else + hx711_data->gain_set =3D HX711_RESET_GAIN; } =20 return val; @@ -267,9 +277,32 @@ static int hx711_set_gain_for_channel(struct hx711_dat= a *hx711_data, int chan) return 0; } =20 +/* Select HX710B channel for the next conversion. */ +static int hx710b_set_channel(struct hx711_data *hx711_data, + const struct iio_chan_spec *chan) +{ + int ret; + + if (hx711_data->channel_set =3D=3D (unsigned int)chan->channel) + return 0; + + ret =3D hx711_read(hx711_data, chan->address); + if (ret < 0) + return ret; + + ret =3D hx711_wait_for_ready(hx711_data); + if (ret) + return ret; + + hx711_data->channel_set =3D 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 =3D hx711_data->chip_info; unsigned int trailing_pulses; int ret; =20 @@ -279,11 +312,18 @@ static int hx711_reset_read(struct hx711_data *hx711_= data, return -EIO; } =20 - ret =3D hx711_set_gain_for_channel(hx711_data, chan->channel); - if (ret < 0) - return ret; + if (info->fixed_gain) { + ret =3D hx710b_set_channel(hx711_data, chan); + if (ret < 0) + return ret; + trailing_pulses =3D chan->address; + } else { + ret =3D hx711_set_gain_for_channel(hx711_data, chan->channel); + if (ret < 0) + return ret; + trailing_pulses =3D hx711_get_gain_to_pulse(hx711_data->gain_set); + } =20 - trailing_pulses =3D hx711_get_gain_to_pulse(hx711_data->gain_set); return hx711_read(hx711_data, trailing_pulses); } =20 @@ -292,6 +332,7 @@ static int hx711_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct hx711_data *hx711_data =3D iio_priv(indio_dev); + const struct hx711_chip_info *info =3D hx711_data->chip_info; =20 switch (mask) { case IIO_CHAN_INFO_RAW: @@ -308,7 +349,10 @@ static int hx711_read_raw(struct iio_dev *indio_dev, *val =3D 0; mutex_lock(&hx711_data->lock); =20 - *val2 =3D hx711_get_gain_to_scale(hx711_data->gain_set); + if (info->fixed_gain) + *val2 =3D hx711_data->scale; + else + *val2 =3D hx711_get_gain_to_scale(hx711_data->gain_set); =20 mutex_unlock(&hx711_data->lock); =20 @@ -442,6 +486,10 @@ static const struct iio_info hx711_iio_info =3D { .attrs =3D &hx711_attribute_group, }; =20 +static const struct iio_info hx710b_iio_info =3D { + .read_raw =3D hx711_read_raw, +}; + static const struct iio_chan_spec hx711_chan_spec[] =3D { { .type =3D IIO_VOLTAGE, @@ -474,6 +522,48 @@ static const struct iio_chan_spec hx711_chan_spec[] = =3D { IIO_CHAN_SOFT_TIMESTAMP(2), }; =20 +/* + * HX710B channels. + * Channel 0: differential input (IN+ vs IN-), 10 SPS, 1 trailing pulse. + * Channel 1: DVDD-AVDD supply monitor, 40 SPS, 2 trailing pulses. + * .address holds the trailing pulse count used by hx710b_set_channel(). + */ +static const struct iio_chan_spec hx710b_chan_spec[] =3D { + { + .type =3D IIO_VOLTAGE, + .differential =3D 1, + .channel =3D 0, + .channel2 =3D 1, + .indexed =3D 1, + .address =3D 1, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .scan_index =3D 0, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 24, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + }, + { + .type =3D IIO_VOLTAGE, + .channel =3D 1, + .indexed =3D 1, + .address =3D 2, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .scan_index =3D 1, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 24, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + static const struct hx711_chip_info hx711_chip =3D { .name =3D "hx711", .channels =3D hx711_chan_spec, @@ -481,6 +571,15 @@ static const struct hx711_chip_info hx711_chip =3D { .iio_info =3D &hx711_iio_info, }; =20 +static const struct hx711_chip_info hx710b_chip =3D { + .name =3D "hx710b", + .channels =3D hx710b_chan_spec, + .num_channels =3D ARRAY_SIZE(hx710b_chan_spec), + .iio_info =3D &hx710b_iio_info, + .fixed_gain =3D true, + .fixed_gain_val =3D 128, +}; + static int hx711_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -540,12 +639,16 @@ static int hx711_probe(struct platform_device *pdev) /* we need 10^-9 mV */ ret *=3D 100; =20 - for (i =3D 0; i < HX711_GAIN_MAX; i++) - hx711_gain_to_scale[i].scale =3D - ret / hx711_gain_to_scale[i].gain / 1678; + if (chip_info->fixed_gain) { + hx711_data->scale =3D ret / chip_info->fixed_gain_val / 1678; + } else { + for (i =3D 0; i < HX711_GAIN_MAX; i++) + hx711_gain_to_scale[i].scale =3D + ret / hx711_gain_to_scale[i].gain / 1678; =20 - hx711_data->gain_set =3D 128; - hx711_data->gain_chan_a =3D 128; + hx711_data->gain_set =3D 128; + hx711_data->gain_chan_a =3D 128; + } =20 indio_dev->info =3D chip_info->iio_info; =20 @@ -585,7 +688,8 @@ static int hx711_probe(struct platform_device *pdev) } =20 static const struct of_device_id of_hx711_match[] =3D { - { .compatible =3D "avia,hx711", .data =3D &hx711_chip }, + { .compatible =3D "avia,hx710b", .data =3D &hx710b_chip }, + { .compatible =3D "avia,hx711", .data =3D &hx711_chip }, { } }; =20 --=20 2.43.0