From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 1A01C3B47D5 for ; Mon, 27 Apr 2026 10:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284611; cv=none; b=DNAxIskBU6Umq1HC8crPVh6kI4VOgDcBUqQmOviAUmQLFX49eKHc2egdLIzrsPpmKzzA92VfgsUhoqp08n81EFqSlyzQUz8vZkawqUq5ZDiqC5S8griuO6O2jXSTJCwypPUuCgxxkw9NW5sCOw8TSeFB+ZszQXIOygIm1Y2aGFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284611; c=relaxed/simple; bh=0PUkoXhMDarNP9t/5JZNDvxydLZwYMiP1Clat9658yU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HYDH2ZepWWQi0d28OE48WEgzgR4/KoQx1pWX10a86J+fsKE45XKtZDydk3G0pZmSeDT0deNdUcA9IVStSP+Tb393YoupbmBX9tZ8rCexbmdCQe48rLrpcsI2WyLvQ6tmmQ1PLUV9gHNpvc671UCAjhPeK8aI1S7jmiaYJKGaufc= 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=ePDfWqKX; arc=none smtp.client-ip=209.85.215.182 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="ePDfWqKX" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c795eacbeb0so4366697a12.2 for ; Mon, 27 Apr 2026 03:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284609; x=1777889409; 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=DbGHpgdnNrh8VCIxoCiZ35IAkxAnxOipEdRQVtqttRY=; b=ePDfWqKXToKssoSJRTXpp1zcC2bjUAo9g8FIpp81kqamB4B76sZaDU3zh3QD0fEH4m fRKDDcghcwhCgZzx6MOIujFEvUD537CGDVHPgZZv4Jr+ij8jRNQTRlLX61z8zq3/F6bu 5mcgJUXmpAeeve4T/vtxITbxxZQKTuWvGK2BWpsQFCO2gstVENR46My9Ux5GJZI9y/cf f8HHRA8D9LgnJNwvkgcfYXR5ad+yer/I1p7dYNr1bgHUlFovUSVZ/imRjvPFEYBUHnvk g8Ypomiji/SISgzonPgmUIsHZNn2A92BJZpR3LjtV0PUNAVWj2XLSkiX82W1fbUidlTq 2sbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284609; x=1777889409; 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=DbGHpgdnNrh8VCIxoCiZ35IAkxAnxOipEdRQVtqttRY=; b=Dz6QMYtXuTk/VbEbHt5SJSstcGnFv7ALqA+zRT1lCugg/OGI36DxUD3fFfwaqWv3JA fRfQdNqLo5iChHZxYNqqJ46Qm10YLi6Bd/NGPOYbUBOf96Vxf2HumHaFqBT6ye6/eawD 2LTWHk3TD21M0LR1NSH/1cE7tjb9f7eKxtomEs5N6k467HeR3b0vfk7kIam7qSKGsFdL tuDSURuqH/HIWNRJo78cI2GObN+eQK05IdqmaZ8+2IWRWkt1/Q7/G3lyWsoFW1nSoIIs leJaQZyVPwVp0uocZWXggzgbrqDNzONe2GdVVEIe9DXpwKFPbsCunHQMx2aMXfxPUyDU 9omQ== X-Forwarded-Encrypted: i=1; AFNElJ+kN2LzSipu16PafIelNYM7cRso54RS7q6N4G3BMmJqekb4SnwM0gPCKxT3uQnNYoyVVzywfHTDTpD4OGY=@vger.kernel.org X-Gm-Message-State: AOJu0Yyn3ZHpkztJXidGaCCosX4nEVB1Znm9bdMgErJNWmgVwGDORBDX P/BbHTf3gKoyQnPpUzkHYmlrCTY4e4U8KJCMOm479ZKTfhPmwzuBepJc X-Gm-Gg: AeBDieumhww8YSc97RCNpclj273S51MTPgRhlWK00FljJ0ZIo4qrxgDSDStXmudHfcN Y4xFV7mwmESAzosCUxKxuzcWCJm5BZrvREUuiRtj4y97TMCwBhtdOI2glHthqwwW5asStpGCkRg ql0iUCIByTSA3x0c2fDBRtWPMSFGwzAXVNUhS9yswrohPlaXw13px9f5SCkBPpWCqiA9ESM9XmD H5964TjS/BljpCYYEtiR04KUrrX6QkBgUTdnn/lZguwcBV52XIpvm1H3iVDdMbzt8zpfmADN6Ju UBsd8gki7U+8mwiWsVX98W23CqpWLIG23R82q+QsDmB54wzx/Hdzzugyr6Ke0ad+oNsXROnRaSG LqUOPaT2303ttjRGsaiQUoQLUg/FfO5lSCNUkre6YtpFdqXxZrrFDTy8C3lf0jvD907+cGt5zcy A11FZuBLSM36qdXRLgcg09pt19kij+30EJFFFnWsiMasl/ECzX7GgPGDX3pxTcOJxMJJRoTwfyj 8hzHn+uMe6x3FGeQipBvWmQPGSEdPj0hd02z2GFYRoxm2p82Q== X-Received: by 2002:a05:6a00:3397:b0:82f:6c31:51f5 with SMTP id d2e1a72fcca58-82f8c830364mr47167373b3a.3.1777284609395; Mon, 27 Apr 2026 03:10:09 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:08 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/7] dt-bindings: iio: adc: avia-hx711: add avia,hx710b compatible Date: Mon, 27 Apr 2026 15:39:32 +0530 Message-ID: <20260427100950.33936-2-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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, vref-supply) and a rate-gpios property for the HX711 RATE pin. Add allOf constraints that forbid HX711-only properties on HX710B nodes and vice versa. Clarify the clock-frequency description to reflect its actual purpose: controlling the SCK bit-bang timing. Signed-off-by: Piyush Patle --- Changes in v4: - Add vref-supply for the HX710B VREF reference voltage pin. - Remove dvdd-supply from the HX710B forbidden properties list; the HX710B has a DVDD supply and the DVDD-AVDD channel relies on it. - Add allOf block forbidding vref-supply on HX711 nodes. - Add an HX710B example showing vref-supply. - Update description: avoid specific channel-number references in hardware text. 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 | 82 +++++++++++++++---- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml b/Do= cumentation/devicetree/bindings/iio/adc/avia-hx711.yaml index 9c57eb13f892..fddd296bfaca 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -4,49 +4,91 @@ $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. One input measures + the differential voltage between the two input pins; a second measures + the DVDD-AVDD supply voltage difference for battery level detection. =20 properties: compatible: enum: + - avia,hx710b - avia,hx711 =20 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 =20 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 =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). For 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. + + vsup-supply: + description: + Supply voltage for the on-chip regulator (VSUP). HX711 only. + + vref-supply: + description: + Reference voltage input (VREF). HX710B only. When omitted, the driver + assumes VREF is tied to AVDD on the board. + + 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 + rate-gpios: false + + - if: + properties: + compatible: + const: avia,hx711 + then: + properties: + vref-supply: false + required: - compatible - sck-gpios @@ -62,6 +104,16 @@ 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>; }; + - | + #include + weight { + compatible =3D "avia,hx710b"; + sck-gpios =3D <&gpio3 10 GPIO_ACTIVE_HIGH>; + dout-gpios =3D <&gpio0 7 GPIO_ACTIVE_HIGH>; + avdd-supply =3D <&avdd>; + vref-supply =3D <&vref>; + }; --=20 2.43.0 From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 5B33C27603C for ; Mon, 27 Apr 2026 10:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284623; cv=none; b=LzyEpXyf2MWZKF6EFJQouIM6tApR3xUUFFO/V9cnQBrBQJA3Da9KGcg5pN8md5lGFkrbDEf/ToqXMFa+h8cyR7GQkn/nU+4H2pALY7+7JcbqNFm4ekt3l6MN6oCfflRHNdmd5vj58BJ05P8IY/LYdlM3FKW7z6k5hetkF5RQPsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284623; c=relaxed/simple; bh=blwxWP3h9amTde2/60twniELsnmcE0y3nMKAe9J7CRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qX0VjCyWcThEoJ10BjNOWPljEGnNiblW9sqYFPTHshrOl0tlhIc/PaCuE1qSl3EHD4pzcQQKLLIvIdXo7dcNVrxcanUPi4IHjLpsRINf8C+oQXkgv0anO1cilGS93OClWHOby0Xlb7YVEV51o3ckgDUA5B6KmpQDQlE9gcItuwI= 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=dHFi/5vs; arc=none smtp.client-ip=209.85.210.173 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="dHFi/5vs" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82f8cebc935so4263050b3a.0 for ; Mon, 27 Apr 2026 03:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284622; x=1777889422; 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=ErQtAdu2cnmpY8o88AkDpSJug3ccvxHHCZ8c7OJd9d0=; b=dHFi/5vs8j1aCm7U98CaBkzf5T87T+290C7/cQyTrNNwIQke+1qohmAjOeXjJu9KCN uOmj6xXTxj98LjcloaoaXpwTcdFWxPzcZuluu2jA3zbTKzarhCSjoIrL99Kv6ZIcsrRu a9baiqHm46shnl3HSTM3gOKMmU9f6vWL0SJZ6B3YEmbfTKJSZUlLMoCJWBSmIJ7vID5H oKKOUJL0DjwLrGa7QXJQlG12I7uS5P491Zs+463GRdedqPsFpad35dl4XBZ3u4CWqE/+ kXznIyv0/TMLBoDxy3pPvhwbenZpqMCL68UFcxMqac78qOHXq97P3eesvNubPz0uGFPj apgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284622; x=1777889422; 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=ErQtAdu2cnmpY8o88AkDpSJug3ccvxHHCZ8c7OJd9d0=; b=Uxy1qXwk/WOxlDNEPg7EFwmYZtKFc0fi9IFZXhPEc9iJk+yA1lUoJZ5dp6t87nftUe fTISL3NSmsoO0oX9eZ/UVxnX3A97i8ylFGZla8i/7CE5otnzPZitkI4b7PNp5rGfXmkU aBNMhQ6QvvKGzB8MQIX9ySVV2sK5GBNeRCiK4+oRxWFU1/hXktWDkFhrKozqgkV4x8Id sOW7KPo0+MTRu+Lm+qalKsWgOTJpU6ZEvYDNCLzGpe82fE+kixOP6U91wvd6phr/Lvp9 wRSm9F/iyI+fgQwpqn4CSdKarGi6L5EF1yF7miKMVWdK4GrPto9kF873L0V8Oo22Jtcq tVKw== X-Forwarded-Encrypted: i=1; AFNElJ8C1EC1S9MUD4Py8C3QSXp0WLcfOjVPFioatUXRGVzeslhHFPLjIaVsbKp7Iu9Y99KolxWXi60mJxflG/c=@vger.kernel.org X-Gm-Message-State: AOJu0YwF1+ZkPW/jp+CGfv5UWF1EaPz4JZoDTBMBx3VO2qVCu1ZwCI+h 4xDBomQTo7KSrjpe0iLLtH9LpCSZe1n0LcyNlw02Gg3NzkC64DFLHyY5 X-Gm-Gg: AeBDieutw2BZ1gFQRXa5LijM+861+wN3CCsDjr4rbZ8E0JXpUS1r2vAEJmTRrJ486Nb PAW0LSvPCTBcox1P8Lot8kX1BMm/2MV81NddaFoZdNGyj3F3AbBg5OiJkSJNFChwdK4cNKSwBkK mgehgavJQG4kgWTs9+7PrQSckLshfiGNY0/EZdkdZdy8mQa8wGpaZipPr72CC7MeA94u1VvQoiu b9NqIG/bJOcglSD/hUN6t4YDlZ5pMcU908OY13Auz1c52gJ2m8xFst/GvAKBZSufhO9h4jxnFkT 9MeUc5BIkbrksD90eo5bUVU+7EN5RrAhV0H9f/jsbCnWlkhC4M8dpNZPAP5/PZBlwhPnOY3/E74 4hzxiefZNBAsKnE9+5N7JCQSmqJ7ylb3Mx8N54PCcRxEUcVrml/1iF1Av2ZzRtzjd9HCbT4QAlU 6V03ggr9Y7Pu+4iLpJ6X+2eEVSWJfsrGEczGUGyTSVeYSRCkBI8B2fPZwz3hv6q2dEC1qpL59XS 9PaG8oziCgsq8K0djkzRP9donIoO80c/tyARm+YA6TdOgRo7dXrkdC6afVK X-Received: by 2002:a05:6a00:439b:b0:82f:8696:5a75 with SMTP id d2e1a72fcca58-82f8c8bb700mr44837198b3a.28.1777284621666; Mon, 27 Apr 2026 03:10:21 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:20 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/7] iio: adc: hx711: move scale computation to per-device storage Date: Mon, 27 Apr 2026 15:39:33 +0530 Message-ID: <20260427100950.33936-3-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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 gain-to-scale table hx711_gain_to_scale[] is a global array whose .scale fields are overwritten in hx711_probe() using the AVDD voltage read at probe time. When two HX711 sensors are connected to supplies at different voltages, the second probe call overwrites the scale values computed for the first sensor, silently corrupting its readings. Fix this by removing the .scale field from the global table, making the table const, and adding a per-instance gain_scale[] array to hx711_data. Populate gain_scale[] in hx711_probe() using the device's own AVDD regulator voltage. Update hx711_get_gain_to_scale() and hx711_get_scale_to_gain() to take the per-instance array as a parameter, and update hx711_scale_available_show() to retrieve it via iio_priv(). No functional change for single-sensor configurations. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Fixes a pre-existing bug reported during v3 review: the global hx711_gain_to_scale[].scale is overwritten on each probe call, breaking multiple sensor instances with different AVDD supplies. --- drivers/iio/adc/hx711.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 1db8b68a8f64..0776a23bf59b 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -28,22 +28,20 @@ struct hx711_gain_to_scale { int gain; int gain_pulse; - int scale; int channel; }; =20 /* * .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] =3D { - { 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= ] =3D { + { 128, 1, 0 }, + { 32, 2, 1 }, + { 64, 3, 0 } }; =20 static int hx711_get_gain_to_pulse(int gain) @@ -56,22 +54,22 @@ static int hx711_get_gain_to_pulse(int gain) return 1; } =20 -static int hx711_get_gain_to_scale(int gain) +static int hx711_get_gain_to_scale(const int *gain_scale, int gain) { int i; =20 for (i =3D 0; i < HX711_GAIN_MAX; i++) if (hx711_gain_to_scale[i].gain =3D=3D gain) - return hx711_gain_to_scale[i].scale; + return gain_scale[i]; return 0; } =20 -static int hx711_get_scale_to_gain(int scale) +static int hx711_get_scale_to_gain(const int *gain_scale, int scale) { int i; =20 for (i =3D 0; i < HX711_GAIN_MAX; i++) - if (hx711_gain_to_scale[i].scale =3D=3D scale) + if (gain_scale[i] =3D=3D 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 =3D 0; mutex_lock(&hx711_data->lock); =20 - *val2 =3D hx711_get_gain_to_scale(hx711_data->gain_set); + *val2 =3D hx711_get_gain_to_scale(hx711_data->gain_scale, + hx711_data->gain_set); =20 mutex_unlock(&hx711_data->lock); =20 @@ -321,7 +321,7 @@ static int hx711_write_raw(struct iio_dev *indio_dev, =20 mutex_lock(&hx711_data->lock); =20 - gain =3D hx711_get_scale_to_gain(val2); + gain =3D hx711_get_scale_to_gain(hx711_data->gain_scale, val2); if (gain < 0) { mutex_unlock(&hx711_data->lock); return gain; @@ -388,12 +388,14 @@ static ssize_t hx711_scale_available_show(struct devi= ce *dev, { struct iio_dev_attr *iio_attr =3D to_iio_dev_attr(attr); int channel =3D iio_attr->address; + struct hx711_data *hx711_data =3D + iio_priv(dev_to_iio_dev(dev)); int i, len =3D 0; =20 for (i =3D 0; i < HX711_GAIN_MAX; i++) if (hx711_gain_to_scale[i].channel =3D=3D channel) len +=3D sprintf(buf + len, "0.%09d ", - hx711_gain_to_scale[i].scale); + hx711_data->gain_scale[i]); =20 len +=3D sprintf(buf + len, "\n"); =20 @@ -511,7 +513,7 @@ static int hx711_probe(struct platform_device *pdev) ret *=3D 100; =20 for (i =3D 0; i < HX711_GAIN_MAX; i++) - hx711_gain_to_scale[i].scale =3D + hx711_data->gain_scale[i] =3D ret / hx711_gain_to_scale[i].gain / 1678; =20 hx711_data->gain_set =3D 128; --=20 2.43.0 From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 67DFC3B47DE for ; Mon, 27 Apr 2026 10:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284631; cv=none; b=p3/R1MpF1FBi441yJeOTtnB/E/C3/h2LuTvw8iAS8JH804suiiDgfq2CWA061ZK2pSzGtckgNu9y6vTv3u0Od+Z7I17odJwPME5DVntmPCk/sKtqamewnyNChYrzvRTc9psNFWf8z3tiE7Uy45xUmEaWgEs0k1UW6xYNQ3v/h8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284631; c=relaxed/simple; bh=pbq+haMBXJjpodXoD7EdAGSmOaszrbzilDvwBg0HaV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NeEMixNo7pB+fp5+qKr5d7nJIEMYQHRZ1UWOTgWyRfd7HOMDVtWykpyoIclX67lt49RTuwmNPqVm8LYxMu1ZBuy6KiEjdlp/bypJdpVCIFpuYLsEmpywSvuIj+gteJ7iOj6gmX2CucBNHu5bXnBUS9fVEt/qGMNkD6rKqBoh0KI= 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=i/UeYZcz; arc=none smtp.client-ip=209.85.210.173 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="i/UeYZcz" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82cebbdbdccso6178242b3a.1 for ; Mon, 27 Apr 2026 03:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284630; x=1777889430; 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=MPviO7yWOPeiGXaSIG7x52NERDN2fjLGfup6ZZml7C0=; b=i/UeYZczC6CFOHZgeJTctRZholWCQ0f3V5KYAIHlJK/TEwN0UP38QCTGu76ceENp9+ XU53pMayqN+C8PtOccz3JrZ4XPjKgTISsjmUgZcx2zdjPp7ujAh0tLz2mWhd64g3oOlp wT68GzcdqpwWPATf5/lmrCwDhJkmNIo3pIIzw5W9aj2JBDYIjBPwvUN6MHdbrjOobGew 7fkin2ALcIaGQ5hpKb1Z39RrqUh98P8Wy3EdQwIj96svr1u6ZBAp7cp71HSfBE8xFwRw HatsFSLoLPEJeoLc7w3SkIgvxHg68zLWgYDm/gbttEQ7aHPWQDbDYgco3hl6SgxZliFE PCNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284630; x=1777889430; 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=MPviO7yWOPeiGXaSIG7x52NERDN2fjLGfup6ZZml7C0=; b=F/seOgOaDZPpBGATUiaVhwu5QrecqFjSHWtmOvCzH7oqtMlNKVBUvf0RVFtr/3UjN+ X08bGN420OKiUbWabbSCsa3e9FvDtu3NnYZxHp/uD03LYngNXgX4jy8T0S+mvX9aSsEr 5X6i6WLezTnykr5B4SlctU+IkRZG5BeSTHnAjKUJSHQT7OOhjKFgpKYk3h4BtHGckvVY BPS1wZuweKIJSdg0RmBVudcEdolMGiT5Gh7MdoPKtJhFkJ7mv3s47YIyimDtTEXwCQ55 qE8/fI/y7oJb1MwBJmupx1HVDuTR8LQs9vEmvTi5oH7Ap4UoznbP3593sDRNyLIsokql k/ug== X-Forwarded-Encrypted: i=1; AFNElJ9Q7xijlC8MR03yOjn41KsrCZrCsaI491Si7J0p52m8FeL5ZADYjVzRH7rIR4A3CEeU9UV9NAOfd+4axRM=@vger.kernel.org X-Gm-Message-State: AOJu0Yym4O2BOyqpJWBAKC6EOzBOBUnmarkrCBMlRL+vCvCZ398UTNfi StdEKD2n9ny8FCuIrKmJ0ZjsPL3H+FxhmEM/Cg8fyBHtBQXUMLcJzEZNAZk9QdLn X-Gm-Gg: AeBDiessaChSkZ7anx/iMiIHfXnlSRbXruRSMHstpoYgmj9tAHU+jKA8IfaThzfvjp+ ODU9PZQ/T/5Cey3WiNYqFAnU6QVixTVVJ+TIdzLujf1H3HD4cAwJ/57h/SM2Cb6GCjbpv5o6t23 ldiTw2EnKcNOtQf6qcZ3orlbow3b41p9O21fDRPFKqHavjrnAnzAYnsxZ4SAFLr45EwIWpKBwti bXzS7GLHX5XelRMdM+zumKL6+hKoLzQnuaftq3ZZ4EFTE2mOPNplJeh35mgAEqKlFvng+C5FoeX SUV8U20nbEATakPNqZ6kbDk0wstYY54oO/GV3PMN6Jjr+VOtNfvvSjm7dotQG/1zwVluLJmrIb6 iaxuo5p9qixVPd46lva1Rviq+bjH2qPW+it+3S472cyiaG5XekXBQI4rwqcFV25L1pUHNFxZ88Q /awVohWuvazpBSHWV5JyYRSKMzZtXI2oQ7T5Hr0mXiXjupI1snSDDgns6tXOxCDUBCejuhWMvvW 0LwFzSNDNSdZmopQr6bQRleMv+dO4ruDIiqx8kji9YiqPDYO8VHyiOWWr1o X-Received: by 2002:a05:6a00:3e1c:b0:82a:146d:36a3 with SMTP id d2e1a72fcca58-82f8b55a221mr35827753b3a.21.1777284629796; Mon, 27 Apr 2026 03:10:29 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:28 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/7] iio: adc: hx711: update Kconfig, module description and file header Date: Mon, 27 Apr 2026 15:39:34 +0530 Message-ID: <20260427100950.33936-4-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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" Update the Kconfig entry to "AVIA HX711 and compatible ADCs" and list supported chips one per line to make it easy to extend when new variants are added. Change the module description and file header to match. Add direct includes for linux/array_size.h and linux/types.h rather than relying on transitive includes pulled in by other headers. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Split out from the v3 refactor patch as requested by Andy Shevchenko so that text/description changes are separate from code refactoring. - Add direct linux/array_size.h and linux/types.h includes. --- drivers/iio/adc/Kconfig | 7 ++++--- drivers/iio/adc/hx711.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 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 0776a23bf59b..32362771cfc8 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 @@ -573,7 +575,7 @@ 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 --=20 2.43.0 From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 A22103B47DE for ; Mon, 27 Apr 2026 10:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284651; cv=none; b=ojpbGJFfhFyFyc0uk+YqoUcprh0I+a7YzGPEq788vdmsFkptkZMq/YMDK67pf6+2EXgzKO5csRHBGf72dQHR+LXlvDOnHm/Zy6uE/xI0XlczAashwV7e8qIjUICya/hXLZDCsKjtb1l9NZeGPwXZk6LgP2a//gF6w4vLhaz+dcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284651; c=relaxed/simple; bh=Sl/Z8A9CH0hwBYW/4R15ug+b331jMcEoqL6KKcM+CBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1JypHteHsa3UCZK6YrmN4vrRziHyAtyRjFGOLRzp6YWqTywq/kOG+x71pr5CCPG3QD1mLoqN10+q5nYUfgHCUFWimv8s4oWX73r8ZjowiQjYJe+Y6yPWQqrVccapIt6CsXPocdD+LxQgmqy3y5X3sdlNr4FHKdwbyWpV6Xd7Ow= 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=WtC3cCPJ; arc=none smtp.client-ip=209.85.210.181 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="WtC3cCPJ" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-82f8bf96b46so4761041b3a.2 for ; Mon, 27 Apr 2026 03:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284648; x=1777889448; 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=8iW96GUGG0VeP8kNBbycKsFQZuoW+cNCY8i/cQua94o=; b=WtC3cCPJlhpr7Cp0rRk4zHLUIBva5lPmiYNGG4922V3SNRsuOd5nmQVs7LD3o8EeIV wcVv2fRUpWCskuB3RcjayqkC8iNqIA0qzY4xoYG1eyQq3gfgiB7iP0LE0JPCvqunmVxk 62rer+Ku1qntRKK8QhlOMEzuIDc/1BBAU3feC6WHTVokvoggifmm0bf8TL6yJ3xCI70a d1tM0Andv+C8fqoBwvtQhbx98YqjGfiAAQ/88PTyRIiGEw1/S7NgfZhaADZU5voV8NRd DGtljcQw/P18Vo4oVUF+/pOGVcHpNyDRxy0Bmgy1lzg+K3wGFt5Cu5ESnXq2NMlX7SMY 7BvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284648; x=1777889448; 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=8iW96GUGG0VeP8kNBbycKsFQZuoW+cNCY8i/cQua94o=; b=NFWSMVIk4Tb7lo2My7zCjnUpRAhY3Ox1qBwEJnI7s6XoAXxMz0PwQuSFzGPJDd46aU LL3EBnY7tnG9Mn9vO7dxpdoCm0gOGafe1JoK1ajPNc+QopN4N3vxNxLPgP5890pMN1uW VcM0EN1tSELDNYn+fvBK5VrHtzp1PncVG8rzj3BiybUM5nU2iNhOt2olYgzTlOI7Wgtl 3c89e2d5KVIuYJUefJUeCCNBGNzuMysJw9xVgnUbdwwT57DhEbwZinom6FVbbGFH2l8g /s8++srqHjStJ4DA7M5RsD4BfPULmvklRJCUp5BK0tDst3s/DR7Q8Rh+aFHhwmMXYVX3 n46w== X-Forwarded-Encrypted: i=1; AFNElJ/TYf8gaa4/+HhyYhzFqYk9Sj4bSD8gkBmr+RGkbuXD+cys3zOUK72YOV++KQ3oSmYMuBMzyQuROVcWf3g=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/DJxssp3AmflEZsr/B8MdJg6MDdtrf6/RBacmnSXJMxIQaD7s mxPlrhAKQu8PHHVXBZdGNYzf4v37MYNrRAl4agQJFHG9BjG4bKN8WMCy X-Gm-Gg: AeBDietmJ9B9FadVO5qUx7YmC8jB539aKXE911cmLXuBq8lBIQ9P4vEHMlU2BoCrg8e cPRnhrefaqyBAnJo92qKIFLiDPSgwI/8J/ZaHKHPyCYGzzW8iNHEZj8Jo0FABz8jYwC3d8pnnS7 LdDXGeNU8tNbxn2ae41ybiiFoiLc+bLk6YtIiQb+QTpOp6vFiiEtXV1ruWtN4y0156qNIqEODVd BjPjQvCK3WDyNqBpofn+cvXrmxxpUGLsLf/eqwc60vFRGDrALOcZJxPuXpyTsyqA5mbttMge+2B qV/Hpu/l1jVLIEZTp6qOojYJ+1/m+JbQTyBKh1kZvjB/Q9DUf2NLamPR4RGXU39+5UGTKhrKBuz XG7A/XeQ5NyPEEk6ozBSi9IOTb/ARaOciMYavEzNfDDiO0TgxEe9fREUNLSdwhSLsdg9MvzXN8l 31CyaZeSHzeU0TtnatCYTVUCQbex8ZkxMzY4o9cW9+p3nlP8JLnHkHcSLr6n+FezW2kRoKBDtlW 2wnR3Dqiq+yGrUQMne4B+Np65y5qGEfKBKKHR3JPZmRc27Asg== X-Received: by 2002:a05:6a00:3e09:b0:82f:3828:a01d with SMTP id d2e1a72fcca58-82f8c8befa5mr42875610b3a.29.1777284648045; Mon, 27 Apr 2026 03:10:48 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:47 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] iio: adc: hx711: introduce hx711_chip_info per-variant structure Date: Mon, 27 Apr 2026 15:39:35 +0530 Message-ID: <20260427100950.33936-5-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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 struct hx711_chip_info to hold per-variant static configuration: device name, IIO channel spec array, IIO info ops pointer, and channel count. Store a chip_info pointer in hx711_data and populate indio_dev fields from it at probe time instead of hardcoding them. Use device_get_match_data() to look up the chip_info pointer from the of_device_id table. Guard against a NULL return so that the driver fails cleanly if probed via the platform name match path without associated match data. No functional change for existing HX711 users. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Split out from the v3 refactor patch as requested by Andy Shevchenko. - Place hx711_chip_info fields in their final order from the start so that the HX710B support patch (which adds fixed_gain/fixed_gain_val) appends new fields without reordering existing ones. - Add NULL guard on device_get_match_data() return value to handle the platform alias match path that can bind without match data. --- drivers/iio/adc/hx711.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 32362771cfc8..2a6e9645f54d 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -76,6 +76,20 @@ static int hx711_get_scale_to_gain(const int *gain_scale= , int scale) return -EINVAL; } =20 +/** + * struct hx711_chip_info - per-variant static configuration + * @name: IIO device name + * @channels: channel specification array + * @iio_info: IIO info ops for this variant + * @num_channels: number of entries in @channels + */ +struct hx711_chip_info { + const char *name; + const struct iio_chan_spec *channels; + const struct iio_info *iio_info; + unsigned int num_channels; +}; + struct hx711_data { struct device *dev; struct gpio_desc *gpiod_pd_sck; @@ -83,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 @@ -459,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, + .iio_info =3D &hx711_iio_info, + .num_channels =3D ARRAY_SIZE(hx711_chan_spec), +}; + 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; @@ -476,6 +499,11 @@ static int hx711_probe(struct platform_device *pdev) =20 mutex_init(&hx711_data->lock); =20 + chip_info =3D device_get_match_data(dev); + if (!chip_info) + return dev_err_probe(dev, -ENODEV, "missing match data\n"); + 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 @@ -537,11 +565,11 @@ 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->info =3D chip_info->iio_info; 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, @@ -558,7 +586,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 --=20 2.43.0 From nobody Wed Jun 17 07:15:41 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 482043B5302 for ; Mon, 27 Apr 2026 10:10:57 +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=1777284658; cv=none; b=FDjh35lM/KX5VG2l5DAzKnpkPcIPsAFqPN5kKexclEhWrQsH82tlqfCf5Bw/wMevJetrQVfzJWPOc5OcPEyLygjjk6T5HEn6mcsVoJTydDXV0CGZbuGqlQpyq/MBBSL30qeFhN0MXQXheDAzQZHYQiRn3n9MKx8mUSLDHmCFRag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284658; c=relaxed/simple; bh=TZ9Eue8DFtaGA9w2JAdQeWItg1bP/LcCHgtVSaqBLuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kKwAxg4J4PLSVFDlZxz3hd5GMHdi1uKYGBjGBlNzhW0EY+UAtFpUXUlxX6qjUJqjWnXmdowHl6A19izN05IiCVApOMyeGaH8HOTmpfILchA4FFxuSrweQO9Rd7u662A1TlVzCQCClrvEFzPYWTTOVOw2mwc48tbbimDkw2G4N/0= 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=pgZh5i4C; 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="pgZh5i4C" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c70ea5e9e9dso4404746a12.1 for ; Mon, 27 Apr 2026 03:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284657; x=1777889457; 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=Bwygt4arcj06fgeRgeONzkm42+D0jSpsT8L72zAuvOY=; b=pgZh5i4CU1iG1mzRYftLj4faa80UuYpeu/87RBdO3kD+41vDcdn0rYeRozanbOIbGg wJBorDsVsHNCdfUOfj/Fd4ywBSYfcp5m/dzyEIgYwpEm/dVQ6Qkr9T0mqHJ3Gmm63Rvy q6bOWt0rR44DKRLeZuokHGWngVw0xgQUaQ8qNuwzXcYePFHdx5yasXGlAxbKprWvwsHB xAuRG4dUNjUTZgT6BGI/jwr+THDJFedQDOZ6j/kdrBKkAA0bGefY9AS570+sfmXeUDao 29b8idY1MxuEKdbkQWcXjyk0TBrwmgt7aefIlBSZ32hTp7XZsjI6oJ8HnT/wD0udbyXH CbOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284657; x=1777889457; 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=Bwygt4arcj06fgeRgeONzkm42+D0jSpsT8L72zAuvOY=; b=ptKA80oc68A2WyOSOjdZxYnRQVxwFy12ZqXvvGiUp6DVx8HPIjqJ+5N6HmaJU38E1I BnxcNY6+9y0bAgIjbQanwiRtP9IeSe3MkJ9ozo8sywyHUUPbfFEydHYWLDTCaK7ph+jw OMy7ex1/64DRybKI9LcAhyc7i2hC2aKYVCnBhlVPQ6lQyXxBfmtOsp1Ut01LnSvUsy3v WxNJbNAmcV+/ys3uEkv9mSzUQtW6jeIC1q5yszhgfMulOvGPgoAzC9jyi4KVzxgQ8Cwc MICk8r3BHLVZ0FlvOD6QS47qAebTh6cB2x3GJuzPAEGojq8okWO3aXInkMrOdTZ21KAS KTsQ== X-Forwarded-Encrypted: i=1; AFNElJ8ZEQO1BEioHUC2T6bmQ6paPgNAFNth3zZX9POuTbzXFHv5+SgQ/6pql/9/rmppSJJ7TegWCWIXZGBFEp4=@vger.kernel.org X-Gm-Message-State: AOJu0YwnQBC4S86cP1EGgcv+R/mNS+DdvT6M59TZwUaZ1GGNTwxNyEzl rZ0tc4dGo5VGDm6F/Eh51/11IbSOwI41sXOJYPngN0t8ml1t+eW6sA5K X-Gm-Gg: AeBDieuGlynvOUBc/hVYexAIG+/prc3LJ4x2mnwso7O5V1qN5MnmhIJAzcxU6mlLoOR zVKK+XKUQ9p/XeRdv1qDG6t6ZsfIlu2YOX1zGLXlHofWdZm9HqoS1CJ0ePUQg+BepAIdcBWwNDq Zekx49PxyO+xG5eX4j9VOZ1Biwc0EVc58kRYtJ7OOBtMh9E4lfaxBOiYRx5XJHQo4nvL6hSKO4b h/3+CqmN+FTj37aolQdqDQwQaJAQNGNeo6FJsrWQW3uimr/dLAggPgxYJj38zsMiuDQB3IhwKSc Q51jBKvI2NyBZnsO+0m0K/C04uZTC1/5FuS49UZ3nXqrNYTHpb3NNBa+g1d/1nMCjVYaWuxeGyR MqU7b6UneNKves9L/fo+MxKtvHWkikzjh80JCj2/y4VYIAFKRHh2EWVykxJLGuY7tznDIRRzEhT 2rtVNz+zA0fQRFDtHqZITTeBJcK7BVUqs3c2nOv69iXdBLvQ+iMbXaEpLDVU6q4gCEE7oNrWhH2 4kmLwYVH2BGu+hTOGJ4OgeFXtPmGLIj/punhvdetvbtrNeobQ== X-Received: by 2002:a05:6a00:2d81:b0:82f:24e:6a48 with SMTP id d2e1a72fcca58-82f8c83059dmr45501815b3a.5.1777284656648; Mon, 27 Apr 2026 03:10:56 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:56 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/7] iio: adc: hx711: pass trailing pulse count into hx711_read() Date: Mon, 27 Apr 2026 15:39:36 +0530 Message-ID: <20260427100950.33936-6-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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" Move the trailing-pulse computation out of hx711_read() and into the callers. hx711_read() now takes an explicit 'trailing_pulses' parameter so the HX710B support patch can pass the per-channel count stored in chan->address without adding a separate code path in hx711_read(). Use scoped loop variables (for (int i =3D ...) / for (unsigned int i =3D ..= .)) to tighten the scope of the loop counters. No functional change. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Split out from the v3 refactor patch as requested by Andy Shevchenko. --- drivers/iio/adc/hx711.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 2a6e9645f54d..8e77978f062b 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -155,9 +155,9 @@ 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) +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 @@ -165,7 +165,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) @@ -174,7 +174,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; @@ -237,7 +237,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 @@ -249,7 +250,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 @@ -264,8 +266,8 @@ static int hx711_set_gain_for_channel(struct hx711_data= *hx711_data, int chan) =20 static int hx711_reset_read(struct hx711_data *hx711_data, int chan) { + unsigned int trailing_pulses; int ret; - int val; =20 /* * hx711_reset() must be called from here @@ -280,9 +282,8 @@ static int hx711_reset_read(struct hx711_data *hx711_da= ta, int chan) 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, @@ -349,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; --=20 2.43.0 From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 23CDA3B47FA for ; Mon, 27 Apr 2026 10:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284668; cv=none; b=RJ/2d/aoLak2RfvPK8YxHBHHfJORxfWYE4omLDp3Hw86ft992KQXgrzXV2O2b4gYmMTCmyjo/woYiAKbrozqwmfcAIPUhrVYdSEYMp8uY9v1eT6gl7uMapdPiJaaxte+ywJP4zsMgdgvq9jNcdhRTJWFHlT+XOt5qSE12pKhXz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284668; c=relaxed/simple; bh=Wtp2ady5cPGsHqy7Hzx2YKsIfwDLlHsBk3WZ6ydRqls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q0aJJEyubbmYTqGCcDQiHyw5ZZrNSMefofP/3lCtSt6DiJphZFo//68A3qcVMjTa39cqWAGXH7nNtPTmY99KsJUAIrGYqZoLGnHTII/CcdWcj5KG2fQ4nYznF+pwsd+csomnPaSWXRwX93wyF7waUZLAH6pkisebRVnS2LcE1HI= 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=BQZ/JFJO; arc=none smtp.client-ip=209.85.210.170 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="BQZ/JFJO" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-82748257f5fso5703225b3a.1 for ; Mon, 27 Apr 2026 03:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284665; x=1777889465; 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=Aa/YrVOe4CujixvUEtBo8c3EyfQIvCG6YasI2Sa6Euc=; b=BQZ/JFJOuLYKGxLbT6CiDCTDKk2Hm3KDcwoXBRfQWiFFXIDy28YZOts4C6Ese1YDWM jrgOHixHB+E5NgoKd6kagv3pXEGLrh5Vgq7xzQtbdymqM6XxB+tDWMWap2kuryyL4Mhq 8PneYxyqMi7xgcfTCEqhb3/KKIxTYlQ1bwM9/hYbV+tUzCXjNyqA16n3e3B8+54OxIsg RXTyFoYj01gMoCRgMRhBZKnG1D/wqOPyATicSWwdL9oXFcf0frdjxn48guO5WK+ZKRJi e9HSvX9IM5ZCjrhkpt2vcDBZvUF/S7yQg2Y+uRQCB3E4qB6ASGKN5+Ze6l0vwPkn7zrB kHYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284665; x=1777889465; 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=Aa/YrVOe4CujixvUEtBo8c3EyfQIvCG6YasI2Sa6Euc=; b=KbhLylTwyyrv5DmFpBKmD6abpm3tvJDx71z6zcgTbfdQPHRsRKNJmw+4F0nCkRRX35 rUx9/fX3KQFV0wIEiBtBDY8VXgJZrUrHlZCNtZC1wxDHSZ3qKFJ8FQPA1u/0MVqFB6g8 f1NJCSJLzQeha0H4zXqM04jCcC2eMvnr6esBHeSh19ZWB9yKmyeSQtkhcPBtkISq8YoM RG8AFRvpuSETi/G5h1md47SG7xcj3J7V5pYLBY6qeKUwC/SdWhftAzVTicdtdIZP/ZE+ rdalLv9Msv5KHAvmODRIt4zAtUgbNgtcQRYRwW6coNugTY5PsHtKZQ90kMnaIhybvwAS knzA== X-Forwarded-Encrypted: i=1; AFNElJ/3eduVnPhbjLlzc09fWVR0LkESHNY5ULF/23sSTfQTkUEaYT/mLv5Hga9UOyfESrC/zueHN7zBhbYx7Ec=@vger.kernel.org X-Gm-Message-State: AOJu0YyReUKX84kW0De3DwLsk+3//4PrsaLH6Or16UW83Wb9srcr/UHp 7e7/xKB//r8vhFwPw4M6yUcfBJA+TLFo8WB2Cv5eeyUEy+ixiXf3DODD X-Gm-Gg: AeBDieuLJTFDJLTFrmAxsvlSdRagCEb8F3T5l29Qybx8vZxJFQBCZDWy/7g1FyRWrGV 8RuldlAmc4nCG+m3TD29iN3b9xLqPcJoVFm8MBpxCAb9uWU1VyVhv5IIohWGJKcHnI2uNARF9de KKRy4RfnWXoef/7Du2dPJEF5PuyhsJCBI1bMmDYvZlbk5IMHHW/TjQ9dPmhE0Or2mNAHWpACiiA WH95/Yey/xkY48noEzDT5Q+iAWz8N8s456lAsDAqTgVKtrdU3d7SEKtvOYcYfzb7tDNeMGIKQSg KaWdIFowfRi/O7XAsm+BzGA7Jywfun3MMEGwxpGOEiWZoUD1Hg0fCmWoqR8Q+wFX1JMfS+iIxDr 4/LG/0onDUB6jby1wAhJtlr/AsHxpE7qKbwomMDmvqW6/sQJiHMZ9WWfl0c4d7iPOtrI3kSMN+X vrvgxkMiemoIjOOjhCOJzZmfBZqUFm2SNEcg3vv4BEaXGZJvbDYjcW6S6J1RBaMbraI0ClbD+65 pSWyeUsQXMJ9sQX3/ubG9Fe6VAl+wb0wWxJc4wq1u+OYZixWz9Tb4Yan3UG X-Received: by 2002:a05:6a00:1bc6:b0:82f:684a:84ea with SMTP id d2e1a72fcca58-82f8b50fb97mr33817544b3a.13.1777284665432; Mon, 27 Apr 2026 03:11:05 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:11:04 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 6/7] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read() Date: Mon, 27 Apr 2026 15:39:37 +0530 Message-ID: <20260427100950.33936-7-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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" Change hx711_reset_read() to accept a const struct iio_chan_spec * instead of a plain integer channel index. This lets the HX710B support patch pass the full channel descriptor (including chan->address for the trailing pulse count) without adding a wrapper or a separate code path for each call site. Update the two callers: hx711_read_raw() already has the iio_chan_spec * from its own parameter, and hx711_trigger() passes &indio_dev->channels[i]. No functional change. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Split out from the v3 refactor patch as requested by Andy Shevchenko. --- drivers/iio/adc/hx711.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 8e77978f062b..dc6703ead8a0 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -264,7 +264,8 @@ static int hx711_set_gain_for_channel(struct hx711_data= *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; @@ -278,7 +279,7 @@ static int hx711_reset_read(struct hx711_data *hx711_da= ta, int chan) 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 @@ -296,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 @@ -387,7 +388,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 --=20 2.43.0 From nobody Wed Jun 17 07:15:41 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 CC3263B4E95 for ; Mon, 27 Apr 2026 10:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284676; cv=none; b=DRxuOGLZdOTjLEF+KgmURWL+6ChNtd9WNNkUn3oENvvNWA37BxIxgtPX9+U0IVaHTRJPJDMZAzmtoUQHdLXROGYj3zwt6PL1HqbZJtdAruPwQd04wIsaAtUrr8udwywzyptR9zRKbIsl6PSXyAkyAlWOTkT4CvcZruNqrot/RHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284676; c=relaxed/simple; bh=Vq16/WUDJf9Q3aD6g2FZKj7xBHFR28TTRlkMvr4p9ZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9hXjxWOoZeN8CejDhk97j3tZQJshajMDsNDLNSTI7epdOf8KrqAdY9Y7jQW//zQSOXa3xsbi1+2NalWeIZxxg3/lcRD/Ar6RnXgCHfzHCrxUTnpJLLU72fE/O/8OStFo8izqXFQGexOFlNWbK0MXBJqkgLv19feng6oW56JnWQ= 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=clPx8DDo; arc=none smtp.client-ip=209.85.210.178 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="clPx8DDo" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-8296d553142so5490268b3a.3 for ; Mon, 27 Apr 2026 03:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284674; x=1777889474; 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=6Z8BUX9VRr6axcG7TGELb+TV5DxSfrOFBihk/7IlPKE=; b=clPx8DDoWUoxUHekezSx3IGtYhrEr5Yn76/W5kqdJTG0Yz6oQ/kzaoa9erZmN2zY4v jB2XsUJ3Df8dsfRDJV0Li8SaEyDGRA0bjBCc2me1aYOgu3Elsp82yCYT1yEazknIE3J7 sOWNdWyNVl3E41Si/BwQHYCYYp6l8JyjdrtQFjFIoQR7o3AjQzRHn8VWHv43OyX6IQQP 5otf5eCo2tpLXvmmeQ5UeXGXHkMonzKB/xT3rwLeKsMpySwEtaa2gQAEBv8M/7BIgN8i EEbE6ywRN7yUVSujpJ+1JSnsFMc3zuPE1JTl6pkMpsvbHDy92vvdVpj44bw9/HxlIPfM LdNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284674; x=1777889474; 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=6Z8BUX9VRr6axcG7TGELb+TV5DxSfrOFBihk/7IlPKE=; b=XKLrCu5fSAxqEmV5ElxghzWYjK5fBSu7xOXvKf2TrlkxtjcqclnYgWCA25S5t/I7T6 oejHD6hh0dWhRoOc9yWPGEIWsSHp0EqlSc/TQhcEfCsYpPyPL3AvGQvWkeHchK6hSHbU ZZWKoOIqAaD0WngGFSYST7BvOrbs+gOMNIlxv3wVdWvdsYPvtBe64BxDwsuRoaGvBw8P /Y06BjM/JTvZt1WSReFV8l3rsnVinP6G3z6SErKOpd28KEHZakCU6eazOOMQA7vj0I74 j2TDPJTIEjbXjNCa9DECbS3Z8fzu8zMK1Gm7IPRxJ5Mo2m8UxFsjHYOK6lDxaPQCXxSJ 77aA== X-Forwarded-Encrypted: i=1; AFNElJ/2BcVRdJvGPzKXTzdRB/bswn9TDxvwMFixYxnkXT+WJWvvwGOiPuTX0a72ri5GRJfUDbfY+q4Vz4FDs68=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2UDoXAR7Oe6h54XCzxc5TT9pNVeqnwVxHbmMUByK/grkG0+Ex wv2RIEiGaKqYUD4f2my8TO7S4jeb/EHjSCInmi1C0qA3ni9woCMoK0SJTApKS75r X-Gm-Gg: AeBDieti01imR7Qt7+cJdAgYaBwzlbhDD2MLhMCKrZP+YeNqLK5QfgXSs7J+ORF5Nau BkJdzT8Q4gSz9sgZmVQBjFDFsnNsxU0HE56xyfmasgAY9WzZ7xsdRGCu3KC5x9nqwOetKjC/bhj uU/VCDaFCEizDVBWATfsdPY+ZU1AHuR7/Umtly+NylmithYaaGYs1tpyG3WJTGYdBmVfNCYPXab qcv9HTukXYeIICyDFdbdVQfS/FwWChvI37xoUcE15B83nmUKAmfzfgMPmuT0mCRbH9VarKxOJKT FDVTgjigg7WAiMH8sOg57fnRDoUxsqC7PR8qZTPCW32cCjqSvUwWmIbstmSyeEwWVSAi1uho9b0 fTOzDeoFKPmYYENDVRQzaaHUNSugcyq+zHcLTR4FwYaBeGbNpWsRIzChcfCgk1+1fzS2ZKLoZ2N DDIttGX04sJ5/MUOyYPN/y51S86NG9szOmKhBdSktVbcVcKBT9hX3BSBjLnZjaXJqnQ+8+gV0EE X11EicV66wSqbhIHl9fGMV/DQSFSCo2lhTj+vXds8BwtnMefQ== X-Received: by 2002:a05:6a00:27a8:b0:81a:b602:daf6 with SMTP id d2e1a72fcca58-82f8c9213a4mr42442600b3a.48.1777284674086; Mon, 27 Apr 2026 03:11:14 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:11:13 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 7/7] iio: adc: hx711: add support for HX710B Date: Mon, 27 Apr 2026 15:39:38 +0530 Message-ID: <20260427100950.33936-8-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-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 the active channel rather than the gain. The HX710B has three operating modes controlled by the trailing pulse count after the 24 data bits (Table 3 in the HX710B datasheet): 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 Model the HX710B with its own hx710b_chan_spec[] and hx710b_iio_info. Store the trailing pulse count in chan->address so hx710b_set_channel() can switch channels without a separate lookup table. The supply monitor uses .channel =3D 2 to avoid aliasing the channel2 terminal (index 1) of the differential pair. The HX710B has a dedicated VREF pin for the ADC reference voltage. The driver tries vref-supply first; if absent it falls back to avdd-supply (for boards where VREF is tied to AVDD). The HX711 uses AVDD as its reference and is unaffected. Add fixed_gain and fixed_gain_val fields to hx711_chip_info to carry the gain into the scale calculation. Store a per-instance scale in hx711_data for HX710B and use it in hx711_read_raw() when fixed_gain is set. Update hx711_reset() to reset channel_set on HX710B after a power-down cycle. Enlarge the trigger buffer from 2 to 3 channels plus a pad word to keep the timestamp naturally aligned; HX711 continues to use only the first two slots. Signed-off-by: Piyush Patle --- Changes in v4: - Add a third HX710B channel (27 pulses, differential 40 SPS) based on Table 3 of the HX710B datasheet. - Use .channel =3D 2 for the supply monitor channel to avoid aliasing the .channel2 =3D 1 terminal of the first differential pair. - Add vref-supply probe path for the HX710B VREF reference pin; fall back to avdd-supply when vref-supply is absent. - Add NULL guard on device_get_match_data() in the chip_info introduction patch; kept here as documentation that the guard exists. - Keep hx711_chip_info fields in the final order introduced by the chip_info patch; this patch appends fixed_gain_val and fixed_gain without reordering existing fields. - Move channel_set and scale fields to hx711_data (per-instance). - Update channel_set only after both hx711_read() and hx711_wait_for_ready() succeed. - Keep a single HX710B scale derived from the fixed gain of 128. 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 | 189 ++++++++++++++++++++++++++++++++++------ 2 files changed, 164 insertions(+), 26 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 dc6703ead8a0..41b9beb6d787 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -78,16 +78,20 @@ static int hx711_get_scale_to_gain(const int *gain_scal= e, int scale) =20 /** * struct hx711_chip_info - per-variant static configuration - * @name: IIO device name - * @channels: channel specification array - * @iio_info: IIO info ops for this variant - * @num_channels: number of entries in @channels + * @name: IIO device name + * @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 @fixed_gain is true) + * @fixed_gain: true if the variant has a fixed ADC gain (e.g. HX710B) */ 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 fixed_gain; }; =20 struct hx711_data { @@ -97,14 +101,17 @@ struct hx711_data { int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ int gain_scale[HX711_GAIN_MAX]; + unsigned int channel_set; /* HX710B active channel */ const struct hx711_chip_info *chip_info; + unsigned int scale; /* HX710B fixed-gain scale */ 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; /* @@ -204,6 +211,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) { @@ -222,8 +230,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; + if (info->fixed_gain) + hx711_data->channel_set =3D 0; + else + /* after a reset the gain is 128 */ + hx711_data->gain_set =3D HX711_RESET_GAIN; } =20 return val; @@ -264,9 +275,36 @@ static int hx711_set_gain_for_channel(struct hx711_dat= a *hx711_data, int chan) return 0; } =20 +/* + * 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 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 +317,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 +337,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,8 +354,11 @@ 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_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_scale, + hx711_data->gain_set); =20 mutex_unlock(&hx711_data->lock); =20 @@ -445,6 +494,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, @@ -477,6 +530,68 @@ static const struct iio_chan_spec hx711_chan_spec[] = =3D { IIO_CHAN_SOFT_TIMESTAMP(2), }; =20 +/* + * 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 hx710b_set_channel(). + * Channel 2 is used for the supply monitor to avoid aliasing the + * channel2 terminal (index 1) of the differential pair. + */ +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 2, + .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, + }, + }, + { + .type =3D IIO_VOLTAGE, + .differential =3D 1, + .channel =3D 3, + .channel2 =3D 4, + .indexed =3D 1, + .address =3D 3, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .scan_index =3D 2, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 24, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + static const struct hx711_chip_info hx711_chip =3D { .name =3D "hx711", .channels =3D hx711_chan_spec, @@ -484,6 +599,15 @@ static const struct hx711_chip_info hx711_chip =3D { .num_channels =3D ARRAY_SIZE(hx711_chan_spec), }; =20 +static const struct hx711_chip_info hx710b_chip =3D { + .name =3D "hx710b", + .channels =3D hx710b_chan_spec, + .iio_info =3D &hx710b_iio_info, + .num_channels =3D ARRAY_SIZE(hx710b_chan_spec), + .fixed_gain =3D true, + .fixed_gain_val =3D 128, +}; + static int hx711_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -525,32 +649,44 @@ 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"); =20 - ret =3D devm_regulator_get_enable_read_voltage(dev, "avdd"); + /* + * The HX710B uses the VREF pin as the ADC reference; try vref-supply + * first and fall back to avdd-supply when VREF is tied to AVDD on the + * board. The HX711 uses AVDD as its reference. + */ + if (chip_info->fixed_gain) + ret =3D devm_regulator_get_enable_read_voltage(dev, "vref"); + if (!chip_info->fixed_gain || ret =3D=3D -ENODEV) + ret =3D devm_regulator_get_enable_read_voltage(dev, "avdd"); if (ret < 0) return ret; =20 /* * with - * full scale differential input range: AVDD / GAIN + * full scale differential input range: VREF / GAIN * full scale output data: 2^24 * we can say: - * AVDD / GAIN =3D 2^24 + * VREF / GAIN =3D 2^24 * therefore: - * 1 LSB =3D AVDD / GAIN / 2^24 - * AVDD is in uV, but we need 10^-9 mV + * 1 LSB =3D VREF / GAIN / 2^24 + * VREF is in uV, but we need 10^-9 mV * approximately to fit into a 32 bit number: - * 1 LSB =3D (AVDD * 100) / GAIN / 1678 [10^-9 mV] + * 1 LSB =3D (VREF * 100) / GAIN / 1678 [10^-9 mV] */ =20 /* we need 10^-9 mV */ ret *=3D 100; =20 - for (i =3D 0; i < HX711_GAIN_MAX; i++) - hx711_data->gain_scale[i] =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_data->gain_scale[i] =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 hx711_data->clock_frequency =3D 400000; ret =3D device_property_read_u32(&pdev->dev, "clock-frequency", @@ -589,7 +725,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