From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 BD5E344E042 for ; Wed, 3 Jun 2026 18:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512555; cv=none; b=IqKWoPmc5bKthZZ4bjXeY30PENiMzoWEcZ9C7GLjD4GqNA1SDw1UDgWors7jAvBQF+cw1mCPddQozedcHdNlq569lkCLd2ZVY4eoSEXtFGv3nVKvy7mEFVw/VCVgfXXVOCX3jV2iDkVlH2UlzMHKK9JIdqKFE8Ognm0YA8uVs9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512555; c=relaxed/simple; bh=fGN8QACq5acyX3/tm53OfWk81sTlEN73wII2m7as1Oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sF6NiLCZ5siWUXVdQe5oL1WX7UUq/YlGW24dq1qjdJmgbeyMUmYAzHFuuvlcVX0/9zDepKF7O4YZfeKLucczZDoWRzfqOOgpRgjhM4FOoOJ5jqQPQ2syYYMyuSv33XwzDDGhDhpTXqUVZuaVchC3pWOxPNAe031+u2yxa2/VLgo= 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=Z2LfR414; arc=none smtp.client-ip=209.85.214.176 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="Z2LfR414" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2c0c3543590so29628585ad.2 for ; Wed, 03 Jun 2026 11:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512554; x=1781117354; 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=Yf9rYDctPN9NDbaPR2RYs1zVFeB2pT+PMnoNRzcUIUM=; b=Z2LfR4145JMTATunS7NAGFCT4P/81X6vTim35taRggW3hfGB8i/QwDpeSj7yPLStmt GjE/OTMt8LFHl8LypTPtlVazbNRblCcMXmvbkkoRHQkm1IuFTLab+EN/qgDoLrON5d6b kEra20z5xnL9tSE4PHqsUiDB+5AbwaTMgI2tOaoyTakppd4gup+q6+WL/399c0Wk9Zr7 ffYQ6Sitd6kI0UKp4Q98T32Cxgyv/vF6XFhwXWi4enSrZ531w1ff6rhwCi0QQ8lwO3RT f+cfazEmJI7ZCklNL2L/jc5PYiWsqFV/CsgPsy1QiB1V1Uz1msLdaUW/fVIZ256lLFfN yQiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512554; x=1781117354; 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=Yf9rYDctPN9NDbaPR2RYs1zVFeB2pT+PMnoNRzcUIUM=; b=FNs6JQI2kgmP5+swdjwD9R+/g8kRAAZh3XPt9m6/zdvTSR5oogIL2QGeVV85hGCHif tU2eLfoUeBACKnQhY5n86ygVOx476ZKeZXln/8ibDy0kW1+sUPSPNJbIMJWIQjU1pMEG D8UB436CuO0ZG9JJWf8ygAnStT3p25XvdZZ4P/cp+/WlylpYK8goF5DW2DOmAZd16nMP hlCHT4xogTOov80msc9tLepmHkAeq9hk0aXT2OobXulOENUb4cyFFMWuUE5lek4Efu7q F8HXU9DaRnJKKwyzdjH61+3dxJRdcvgBGSP9dUL+goF67dwHyQqR7yM/GF8psyjcExBa UnPw== X-Forwarded-Encrypted: i=1; AFNElJ9WPBYRPAjtvQC9W9ydBf7CQMk+wkguUvSOzzKIuamnTgj7ezAX7QQfg3twtfEhHOS0IQJL5EUrWNPl0m0=@vger.kernel.org X-Gm-Message-State: AOJu0Yyc8eEcOABnV9wZnCH49xpORDnPNjal6EBLt39o5ri8825aSRKm 0CzG2yQiX6KZKxfTjwjgbuaH/JpAxkwx9Me/g8kw9GyS1kA2zI9BO5bO X-Gm-Gg: Acq92OFnu+T+Zjzh/OCsA4Pg6toof1h1iDXtaNXBbh3ydjnJwP5p4R1Gennfbw6s6fp ZV9KBLNfrX2OvVRljV7mn+3cobcktYqIuyr1rYn2/f2D7Qu7I/W9sVZcNfXbjkkbZwr7QFEVpUu OOkUNSA0LRhpyX5rqF965RH9ps0D0ICsZtJVjEc5UjSmG1gdMLWh2OafcxG4C5A068OsJNa1TKg ZXXOIE09/oIBUyJgP2uOQ18EjCgmtnXh9frjVe3baNgMJSgyN5DEsuSKa9AKtXFhfGlTTKAHiee HACAbPn/VYLVHAEykuqrSkJ3s2geGRS0bLJ2uYEsMNdmUHJuHkPwaX0xpurA2AmeHT51aHCVkzo v3BLn4WxxTTE6Z7w2/Fipc7pgR3pOHib7raChfDby4XdQYb4g2frtFyH/MsiwX126Y1qYXUflo1 ObS6P5w/rp3DbbGPUfU+AIV9Na796gwZVZluUBQin3ksq5F2UuwrjlOuTN6cobg6IX2EmTQEePc ObdqNxuI/h5bqYKH8wmma4yr0dZP9grDNQGDemH++eUr7kFkCpYZaNexi/yAbcs X-Received: by 2002:a17:903:3c6c:b0:2bf:800:19f8 with SMTP id d9443c01a7336-2c163a3f9cbmr57906695ad.17.1780512553868; Wed, 03 Jun 2026 11:49:13 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:13 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 01/11] dt-bindings: iio: adc: hx711: clean up existing binding text Date: Thu, 4 Jun 2026 00:18:49 +0530 Message-ID: <20260603184859.89693-2-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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" Rewrite the binding description and property text so it describes the existing HX711 hardware behavior directly instead of documenting old driver implementation details. Also clarify that clock-frequency controls the SCK bit-bang timing. No functional change. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko Acked-by: Conor Dooley --- .../bindings/iio/adc/avia-hx711.yaml | 25 ++++++++----------- 1 file changed, 10 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..1ea60dff98d5 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -10,14 +10,9 @@ 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 - - Specifications about the driver can be found at: - http://www.aviaic.com/ENProducts.aspx + The HX711 is a 24-bit ADC with selectable gain (32/64/128) and two + differential input channels. Channel A supports gain 64 and 128; + channel B supports gain 32. =20 properties: compatible: @@ -26,23 +21,23 @@ properties: =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). =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 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 33F7A3F6616 for ; Wed, 3 Jun 2026 18:49:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512561; cv=none; b=hnfCJaFYcrgxXo1flQwlDncwE4kuNJ4NUZRpvK3OYjXhRe+r9BqswT43mRbr3tRRhakVURyw1soyjwaBCz9gtZmcUsQsxt9Nw4lRCpIs/6/jhEajGkimRd8OEe8vWJ0SHpvtjeblZTYleDHEO/qnuKKoYjaDpnggcrSHzed0CEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512561; c=relaxed/simple; bh=EcLRSHqnqB5L5pYI7tjNeUMf/1YsZCqijICND5QflsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PqjhsuQrTeu0gRpdbJoabqJkOvXhsfO/i64yNwnXniEeSTyaYje7RM6m9E2dkuj/bQjbDYepeRMeQgAgIApx0vqWr7pv7tMfoXaaUJTsGAdqai+T0hCA+G3SVmzuyRTib91twMSkfA8+ZaXRQ3x0VxZt7+HcJcl9eYBfYb5pPZc= 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=MjYhcOtX; arc=none smtp.client-ip=209.85.214.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="MjYhcOtX" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2bf36a6905cso34204295ad.3 for ; Wed, 03 Jun 2026 11:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512559; x=1781117359; 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=JP2oeys3gnF+eZfS4uTCq9ZgL+QAQ6O5vvj9ayK0/ME=; b=MjYhcOtXYatsxzcap5Qthf0sq/rvQp7/QRtu94Xx6B4Ahyi1KV84W9Sx5h7UrbubcP DQG8P+a3/1ZmlKq2LGdjubCUcS3RJsdvdJKp7rRWxsv+6v3FOi7gCaSLtAlwLNs4eJG6 /QD1+LkDsS9VKMp1Uw6+nPkcSkl5m1TccQNoLc7ckUdhpYuyKeNz9jxP8c+l3wN1DyVN eFjuoFu+BmAC0DO3ogvy5nuvw8cWV7H46A0oX0mwkXIuJ2Wb3NJhfc1MpyNuOMV/wxWH k6aUDt+gIbyqdFBiwArfzh9hMyz6EZls9FGzkFcRfNJk2RORblHv0g8uNYjWN7ZFqJx6 hgAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512559; x=1781117359; 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=JP2oeys3gnF+eZfS4uTCq9ZgL+QAQ6O5vvj9ayK0/ME=; b=alJoiLUiZBD2zaltUKVs0jF2Vu+Hg0/s202SAfLB8ru7nEtZDBSb1S/Uej2h1GPG8q jWbTIutQaqId5yp1sAxO1qt9wfy1V8g+ns3R5xGjZlHBOcXIozQDKXftRkBHUZjBX+aL yQY+rcrbSRt62cljvbM4SwPVmd/RWN3oVz8+PoBmWz+h1tG8CzZgdskPIDbTIxbWH7xd +DcnjutEoAEf/DzVQ9e0hr+5KhiNEBUpkZsTlJdqoc2Qn4ItnlpQyrKfFQQb8SfNTtyp bymaOCfePMZnsYUmof8n2WFeDyqGfesALrjI20hum0rz6QOPthpXmYytdpgFZc+DeVFd Pt8w== X-Forwarded-Encrypted: i=1; AFNElJ839P6q2KwgUjm9rj2X4hDPMAGHizXNSN2CAnnJKznDFdoigJ0Wr4L5wLdPhu3/X6oyr4L5oLuAI7cq/QQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzsYtPhJio8zF+wqBo5hoE6+ieCL1jUva9MBR/Et1B+BWs53/Jl VDFPuYgffzRn92T3iaxQieZ08ZLZYbp4F9ehQg38lRnC8u5bCSEJVyol+C0kOQ== X-Gm-Gg: Acq92OHG3hzX1Y6EeEBIndVf7c4mD2L2SzkacTnEJQ0QxnctrC3fN+7naDgk+qn0Bto deIaBdhKZo44usBD2tRZe139/ZebOvYDmOBFWJ/yy8LqPAewXsTIUZrCihiKNP1OmwnMiNDxHj7 L9C9/cDxhauKpN8lbMugo+dC1oqLlwfJSCcCXhFyLbkggBsmoz17SR9kr45sU60rHO61AqOjcki vtqdz72QL/4a+Cjfd+m4We8SzFUo/jAvjzCD657uwwYNVvf+a6ufNkBMggLyLoSeDBcGNFG0qjz TNo4xSecUHgQVXT2/t+qcB3OP17L/FAF6QRH1WM/r4nPITc+t8HqKZCptBJwEi5s+Ep6VOEZjyG d4kN4hPrKElqXIjcEVRTnN55JtmJISUacIqzjH5C1XhBBhH1ZuP/o2+pqXKM5M6iBaQHs/jfMoq OLdrmHRqGre4wyFf3DcUFPSFfDrcJgGTol9HGTgougi2+0qOMdaNWCO/LB50QtcEw8t4pKW8wHO ET0DNQjlVW4Nm0mKVNvhjKFqyguosD/h9m3xLbRVPcI6x41RkfEBA== X-Received: by 2002:a17:902:e14c:b0:2b9:ec37:2977 with SMTP id d9443c01a7336-2c1644dbfd2mr28650865ad.38.1780512559486; Wed, 03 Jun 2026 11:49:19 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:19 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 02/11] dt-bindings: iio: adc: hx711: add VSUP and DVDD supply properties Date: Thu, 4 Jun 2026 00:18:50 +0530 Message-ID: <20260603184859.89693-3-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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" Document the optional VSUP supply used by the HX711 on-chip regulator. Also document the DVDD digital supply. DVDD is a board-supplied digital input rail (figure 1 of the datasheet shows it as a separate supply, not merely a bypass capacitor point) that was missing from the original binding. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko Acked-by: Conor Dooley --- .../devicetree/bindings/iio/adc/avia-hx711.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml b/Do= cumentation/devicetree/bindings/iio/adc/avia-hx711.yaml index 1ea60dff98d5..0baf620e9057 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -33,6 +33,19 @@ properties: description: Analog supply voltage (AVDD). =20 + vsup-supply: + description: + Supply voltage for the on-chip regulator (VSUP). + + dvdd-supply: + description: + Digital supply voltage (DVDD). On the HX711, DVDD is a + board-supplied digital rail; it was missing from the original + binding. On the HX710B, DVDD must be greater than or equal to + AVDD; when DVDD is a battery rail and AVDD is a regulated supply, + one channel monitors the DVDD-AVDD difference for battery level + detection. + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the --=20 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 6CC1D4657C0 for ; Wed, 3 Jun 2026 18:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512567; cv=none; b=k5t0ao5UQ2SJQBJs3ld7RkaGAPUdJgcHphW4H20zKE/USG8zcBDLaLGLEIzw2zmlo4/+vsig55zeg0Zl/sjZQjm80AEdD2r6EZletYAy4yoVHXCgLrrKURz+VUgcHfhmo2l+U2JGzyv19ogkArw9EaHVkQWG6gGbhiPvy1y6Pdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512567; c=relaxed/simple; bh=EoAF4YHy3iYTq0qtbpAuxEpwDtw0CacTgV3exikXeKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAJK9y8Dp1gu+4PD6ib4GUi/sWn0IeTRVKUHUiaSPW9AF6Z2RFTehW/rtS3Dzo5c6ayEIKr4ppd+Wlvsdd0tyWBuDm7InVXvbMLfC30Yny8q/YFH0ZPiY5DHYBh2nwCt1EoYxm3hL2EwJHzy3f7LPIpljIFMslql/4oCPEDZHEU= 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=By5iYhgM; arc=none smtp.client-ip=209.85.214.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="By5iYhgM" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2c0c1e0d00bso40478105ad.0 for ; Wed, 03 Jun 2026 11:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512565; x=1781117365; 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=ygX2OtS8jtfRsEiUpxVA4rgdEOhC6dRMuJ3m7A2/544=; b=By5iYhgMccAyHP0G3AmAW8m1JxG/irSmUEA2V38OpJhdE1IJ8XjDZb4eo6+akZhqkC klqDUb7QT4HmcG+2ymEEg4O+ywLDwe7Bt1fP6u97Qo5MtCwYEvJwm/ZB8N8WFbswVnVV b4x28BsgqZocg4Sc9MNDAe7IkHhHgZFr0zMAk7KpY09GOQKYWRJ5SQLjdMeOKvB41JsT D+3+XJOupsjz475itgT1INKdsDKOcoPftPeeGECZr/0vYRLQffynkiunKmZjjt3GcC/D yPJ3fILGC+StIv8VGVwQfVrxq+SngbFTMXKmghWV+AHlT6yT9xPiEWdJAaFvRQvoA7Ne KjRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512565; x=1781117365; 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=ygX2OtS8jtfRsEiUpxVA4rgdEOhC6dRMuJ3m7A2/544=; b=rwc/Wtbq0jEnbN+kuU7wyvFLKlM6Fn1RpjW99DUT9roTDc31j4MTzoIVB8C3LJUeDj tUBf6MdJwphgJXMnYYkdQIJg28h9JYOktY2/7wST7ZHxwH/WK33VbJhAZx5ehytd1Eb2 Zzs4YCTYlccgkDXA8DpENsmYoO2OeCv4ZZ8WptvpDx9OoCa6EaQP2DVKf0l8IybRxKMJ 7Dn1u9adWJRjhu52FWt6LO1QaH29eeiqnQDa1pd0XyJu648L/VFC4YlGc8XR22UuIHOK ynUTckyxKdMJXo73gkdrr36dnFwKNttjL7QbthOPsGvls7qJ/TAcT/z9SjxeKFI1EFRd Qk/A== X-Forwarded-Encrypted: i=1; AFNElJ/i09HhESBW49AsJEdz2uhr5UlOL+Bz54uCijVk/xXQNiNzA7clup71MfanWj7flUTfJgM4cT5Wu116jyk=@vger.kernel.org X-Gm-Message-State: AOJu0YyG/FlhX7o6rr2aV66o4Isflz8gCW4rzNqu6CJVUaLediKmj7jj ofe2JjFVG4pQ/U5q4eveFI80WqkTsPbVVej3OVKQya0BN1UPA8BR+SJF X-Gm-Gg: Acq92OEskBF6L2FqGo4Qk+Z1sOkxQ93eyNRPDJvx62itQ3CR7QO7LxWphw1fbOh8ozD e8cpcZ+XKSCnrA5fE2zM7Uy+8PoVw+MC3kF4NztIq+8jP/4QEt5kLqWtYesP+p1gK6YrO58FE93 5ST4oQjAdgRPaOh1kABWqSHzVL30FgmdVkhgDujFGtjgLkXTvRc6tZgoV4TCw6gjDiWK7j8Il/Z 54m9oWx+Tni+cv77xA8BJsd+waheU2J8gPLOgr6df1ctjnW19oGl2m8es86LHYXR+3hlKmG2DIK 0dffeXvcBAXTHZQgwxDEVhp2SQUSh/VW1BH3MkZGu2hs06Q5u+L7xh3a4ALxc+kMJ/pnWGDh7DZ xfr6xu83lPpLIvp52Zt64uykKG5RSSYL0FIHhZ3NwXfWpiZb3FJ3N91KwU481cM5zWZcDOX9ftE pBALAdXB/Tk0RFr1axVZhtQq3QAcmXWMha19rdIpLQqiUyZc42b1/zvLOaGdTCIKW0tplvQLuUl H3tQG2MgNfGWVfwG7koZ5whIFlIS18ZWHJ44Uauhx6SRQ3RmhpEsw== X-Received: by 2002:a17:903:2b0d:b0:2c0:cf44:3b3b with SMTP id d9443c01a7336-2c163fa3a7fmr55072575ad.24.1780512564599; Wed, 03 Jun 2026 11:49:24 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:24 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 03/11] dt-bindings: iio: adc: hx711: add RATE GPIO property Date: Thu, 4 Jun 2026 00:18:51 +0530 Message-ID: <20260603184859.89693-4-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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" Document the optional RATE pin GPIO used to select the HX711 output data rate. Update the example to show the property in use. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko Acked-by: Conor Dooley --- Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml b/Do= cumentation/devicetree/bindings/iio/adc/avia-hx711.yaml index 0baf620e9057..099235b5fd54 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -46,6 +46,13 @@ properties: one channel monitors the DVDD-AVDD difference for battery level detection. =20 + rate-gpios: + description: + GPIO connected to the RATE pin. When driven low the output data + rate is 10 SPS; when driven high it is 80 SPS. If omitted the + RATE pin state is determined by the board wiring. + maxItems: 1 + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the @@ -70,6 +77,7 @@ examples: compatible =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 Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 94E6F4657C0 for ; Wed, 3 Jun 2026 18:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512571; cv=none; b=WeuTgBAXi2pHHDPliY/cZhPP9KYS5UAC4Q0Wl+n4ACWM3j3gLr9qQ+X0c17hQlIJE590Qr0UaFVSNKJ3FL8MDP1Wxv41JsVQcz8vQBg96lMjpVZ3blYmaiczgC5LZNc8nesk5rbQXRCqT3kFn4SftR5xMfyvduPuD2I38YHfeTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512571; c=relaxed/simple; bh=40M2sV1ViupapFAfo9CoPrRZTe8sv4vv6buoDystY7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WBWaIhBt1d9cFHKkXYOp0BIuqqgaVKMfqmtlf+s8kNnu1MLDE7ZA91OuC7oRcd58LVh/+mLLUttvM2QGHbButf5GwuriPyWhE54bvKWBUSlwNRo/q6QMZMFZ/G/BdxR48wKW77kifGdQ87Vm2gszh7ym2CdvUZx3K7EufI9zCgM= 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=N32nZj4P; arc=none smtp.client-ip=209.85.214.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="N32nZj4P" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2c0aa420401so33152095ad.3 for ; Wed, 03 Jun 2026 11:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512570; x=1781117370; 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=n6ML9c7gULfSe+6SlEf0Y7kEnMjS6nVo8dQzv+8WvZE=; b=N32nZj4PgsJB/OXiijJtRx7Amw03+WqvYCBEmYTk9bSLmEItvMtOuN5OSUsL/e2CL2 y6dkHOcsVRcXsFTvHKZ/R4rs42/nSxDaZYKV5PAJoM3Utr8+PKiAJM+SmnK5jdYaANIB +hhHG/r61ny0fx79CL95oyl68t6+vgD3Qh5jQ4QuSd0E3ty7ajMIQhtqW3hEmgEew5nd nH6Xkui9lRf/OWX3v+In5e4CMsPup6YxXHnu+jVJcCIOMF/YVrzpe+ZJVTfhdSfJeoXs HOfsNAGcydzAGEJNLCh9Gco5kM1AWy9n3TZsF62WFqdkpbzu7+Mhd94YSzDDAMfsg1AU UjmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512570; x=1781117370; 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=n6ML9c7gULfSe+6SlEf0Y7kEnMjS6nVo8dQzv+8WvZE=; b=UfIdKUEXf1niwdjY/+t99QsfKwt81oalJX/teOyVJtSV/4aBoE0qrCJC6rZeV63SyN tBaIooeg4dXc57SfSdhKT1FOlL4ppNVHgTwv0wY44CwV3zjBLXlUot5jrDiHIG1D88zz c/yEPfbX1Ql5mrl40ogACypieYToCVulDEGAoiauQIJQKdPiH1Nz57VT3zAF/D01gcua M7EoGLyz8zQmoF29OQvQarKYqlcTNvxUHyqf5vEg/d6LAreOS4W8WLJOsUhNtsQHaN9z 9CdK88wKGTPm4Pa65a38bIjDeNuAHgqkyFws1FCRHY11T7L1nFMkbSsFs1F2ohAwViRs bqUw== X-Forwarded-Encrypted: i=1; AFNElJ8yk7v7y3lsHUrSCOskQZWNeMKIB5PMxzD8Fza+xOFtxDLwgngQk5uIurUDUDoSCX+RRCQWbxEzIo0K3Rk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0hzrj2QuFvXk8b7GE5r4xTIozpCPsBBLQJHIZ2q5S6GfvnOXy 2PH/yxrTvsUaGWlGW6ZKXHUxUKZlbnbjjguUoNLXUbMQtgge5nkot4IZ X-Gm-Gg: Acq92OFJKpjukaCyV/0Us+spZ9yahaCxQ53CvhlR+gGMSY3MtI1d9ZGnoJO+iK+b9vE SrQ15w99mjWnROJnkXdVojrYkDM1wgRJQBeoYo0XWb9/V47ztaB1cy/f/8A4jnXGb5y3teG0LrM ZbhZDmDcCXHRXgX7bcP+l5HPtKXwYOxwXQL7+KgDatwvzmBAv2Hx0L6d32aD4Vk/taCKGAJg/pS qmd3mhX3aeV4pF1PeM8W0iclo6DAt976wrYTww8TVvq+y1PNqdjq3flSsFO33DbVBDkCPrIg1d/ Vy57oQTJhbuVXxZCzAoI3WiI9Y2Hntj8RrbvaEKazNjAdXUBVITnJsBHY0i3m+3DeMFGp/xisNE k/RP/Yr+h2wUNiBNsd3XO3nIdV15cNveggzXMdDSblAcdlfIpuQvYf+AZTOZQ9O6p1FECM939l4 +7hhF/p9NrfQWM/YtFEVshF2l2W/SqXkpfWWeKyxyLArO8BUZOmF9ZT8QXZp+Ms8RQFjJ3OUfm6 wKc0Qlov4tfxELk0v39wY0+lcYOhr4o+uPMI+1Cr/vyE19qpx3plw== X-Received: by 2002:a17:902:e54f:b0:2c0:d097:51ba with SMTP id d9443c01a7336-2c163fadb2cmr48915475ad.26.1780512569723; Wed, 03 Jun 2026 11:49:29 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:29 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 04/11] dt-bindings: iio: adc: hx711: add HX710B support Date: Thu, 4 Jun 2026 00:18:52 +0530 Message-ID: <20260603184859.89693-5-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 the avia,hx710b compatible and document the HX710B VREF supply. Add constraints that forbid HX711-only properties on HX710B nodes and require vref-supply and dvdd-supply for HX710B, then add a separate HX710B example. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko Acked-by: Conor Dooley --- .../bindings/iio/adc/avia-hx711.yaml | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml b/Do= cumentation/devicetree/bindings/iio/adc/avia-hx711.yaml index 099235b5fd54..13a3a8b007e2 100644 --- a/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml +++ b/Documentation/devicetree/bindings/iio/adc/avia-hx711.yaml @@ -4,7 +4,7 @@ $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 @@ -14,9 +14,14 @@ description: | differential input channels. Channel A supports gain 64 and 128; channel B supports gain 32. =20 + The HX710B is a 24-bit ADC with fixed gain of 128. One input measures + the differential voltage between the two input pins; a second measures + the DVDD-AVDD supply voltage difference for battery level detection. + properties: compatible: enum: + - avia,hx710b - avia,hx711 =20 sck-gpios: @@ -53,6 +58,10 @@ properties: RATE pin state is determined by the board wiring. maxItems: 1 =20 + vref-supply: + description: + Reference voltage input (VREF). + clock-frequency: description: Controls the SCK bit-bang timing. The value is used to derive the @@ -62,6 +71,23 @@ properties: maximum: 2500000 default: 400000 =20 +allOf: + - if: + properties: + compatible: + contains: + const: avia,hx710b + then: + properties: + vsup-supply: false + rate-gpios: false + required: + - vref-supply + - dvdd-supply + else: + properties: + vref-supply: false + required: - compatible - sck-gpios @@ -81,3 +107,13 @@ examples: avdd-supply =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>; + dvdd-supply =3D <&dvdd>; + vref-supply =3D <&vref>; + }; --=20 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 B077F47CC61 for ; Wed, 3 Jun 2026 18:49:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512576; cv=none; b=AY2cQnrkhdpVf+UgXhXQby09TizUBmzB0AIf9IoH5fP68jnnkvbL97E7REGNBJg/bfRVyy/ycZ7Us01Zo2N6W6ahEDVMcreF30iAcflJxUl0S+nR04wvNL/8n81QFokL847BzR1vXYnMmCGKvDxZYVyzP7Gr0LL1kQl5fwlDgz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512576; c=relaxed/simple; bh=jqPYoYhLKYYlSYtUJdzENTM/X/PaYeN8NKoJ7tNg6Wc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7eP27Qws3m057aYx9V5zN5kHUF9KJtHnffYQ8c38IUVeA/aM2j6PCfiBXrbDMx28vJr+/UjOLKVbYqfiC7GEJ3yDSJuXEAcxrBzcINq/bCMFer22idHf0qbbfJZ6S+rIzRFYZODcA/eugP9hs15CKfl8aRGOUcZwSyoLKRF6Cc= 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=Yzy3Q5S7; arc=none smtp.client-ip=209.85.214.180 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="Yzy3Q5S7" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2c0bd02d97eso48683575ad.2 for ; Wed, 03 Jun 2026 11:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512575; x=1781117375; 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=wkXrBYxTI0izj6VrJvaEKI7ARZ6dKBgJhCCnnbAo+Vg=; b=Yzy3Q5S7xRpSvgKbXL2m//3ISfmDZzQyuEqhDXZ7zCKdMyYQ/UtTQcyDF/uwjBGc8p VrQsOY34uncrrVojK7OWMQ0ePx6vWaer2+WMDU7ElW1lgiNqyQpkZJvKy/pRpNgg6a32 Rz/4SWDqlo03Jofz51ZGCE79J4Iae3JyhHoaV9JAi0AgFTVsTAndAmOLe+e3Vx1l5zIh CyzIf0LR4xy5UE/ju+SHrv0W8R89G0zXYGAYx7SKJM31sX0yNz8KCna0Xn/CFJgTPXhm 5k68CCWnyWBB1rDZdMWIL4gJJVThOaIH/RNiABsxGY0Tsskp3KItHNdB9EyR9uAr3Cob cWZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512575; x=1781117375; 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=wkXrBYxTI0izj6VrJvaEKI7ARZ6dKBgJhCCnnbAo+Vg=; b=c+QaqRxcmkuSNEwFSHR34Gi9rBMe6HZPFYQGoMaMIBWQyIhyqwoMSSJP2moxtGmaQP /aNI+nr8WgGWLopa/pztB8+87dEZENDUSiEbQ18i5duLq3vEhJNdMuG19ds4evSYdk3R F05tbOWxDFb7xL8wkYLJQSkqLJo8NZbrw5mQ2zu+zinRNuqF1MWJ9xpTFr3t8oWP4JnK hclgDTLeMwRI0ZZ2WoPfZPtSEKEFMTbxHsbuRZaIeKT2stXAQ71ZsSf9WE6DOAmsEP/M dKsiqmFG3wkjd/z1keg9luvBIpvdMcG9Muk9w1Dn777RjTJyjOAE0GPmRRH/PAnZU0ep EBww== X-Forwarded-Encrypted: i=1; AFNElJ8x1krJl1QJ4XJoDPaMnZOBKYrsPVBfe88lXtiHZ+y6XBKQztLqme9047g0cHxz5MMYv29CbXVTlZEp/58=@vger.kernel.org X-Gm-Message-State: AOJu0YwSuAXMTUyhcMSdoKLLKER4JU3bCf2ae8vx5iATiawKqZnvA8bT 0I0SdMWC+IxXXK6eYZ8zQiFzvydODViItNHf3G6b3udPPs6QOTGbfOac X-Gm-Gg: Acq92OGsLizwkRRuDm9l/X+PQtbaXkRTP9+PI7XbPCPiMNxrSUd+qOVmMgTKg4yqkp2 G16YovOTLXOOzAZAHqPzvb1iklNxkJpfqi4fGqOoR22t8/YG7NK6F9hqAXzXippUwjC7i6MbdPN wuzgoP2SFQZk7Bky/zlpnLiQ5C/sJaQk/ra69OtEGk7BTLKBt1i+MSEsu3oqa5MZ0LU/u7IsgHS abX1DXVfCKSEQ3Ton5ZV4qu2zDZbf72EPLWkojx/QluqoAFC5IKZUMGQ1Sx0es63ZzihUaxMDwl XDiRklKiNLUph1h7xYS8u/kHvM2vYMB5oqDiJebeLPr145BAciBOT3/HphqNYlrfeUw9IDjLj65 LxxZHXbXV9YjUSXo38d1fbItG3lQCgO2AuPuELxR1ppIGWkmLxeR2Mz7husxQqs5rQJAZ0khxf7 BEu7C+XD9dqyYNgGnqbkPTa90/wBgDBCHfJ8hk1ZY9AxY+uS41gkTWvIdzwp0ZA4qDaazErzTGw SfeIQ+1exgRgKK9/mttERo4HCoHINSixh9wpUGOee9QxbKYdtYKJA== X-Received: by 2002:a17:902:e5cf:b0:2b9:6458:1a2c with SMTP id d9443c01a7336-2c163a49fa1mr51737065ad.13.1780512574915; Wed, 03 Jun 2026 11:49:34 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:34 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 05/11] iio: adc: hx711: move scale computation to per-device storage Date: Thu, 4 Jun 2026 00:18:53 +0530 Message-ID: <20260603184859.89693-6-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 is global today, so probe-time scale updates for one device overwrite the values used by any earlier device instance. Fix this by making the gain table const and storing the computed scale values per device in hx711_data. No functional change for single-sensor configurations. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 1db8b68a8f64..86d2a70dd3de 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; @@ -386,6 +386,7 @@ static ssize_t hx711_scale_available_show(struct device= *dev, struct device_attribute *attr, char *buf) { + struct hx711_data *hx711_data =3D iio_priv(dev_to_iio_dev(dev)); struct iio_dev_attr *iio_attr =3D to_iio_dev_attr(attr); int channel =3D iio_attr->address; int i, len =3D 0; @@ -393,7 +394,7 @@ static ssize_t hx711_scale_available_show(struct device= *dev, 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 +512,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 Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 4BA594657C0 for ; Wed, 3 Jun 2026 18:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512582; cv=none; b=J7qm9o2hCOJi9OiC8O9ActdpN0lg8uo71bUS5ybEcogKggTK67f/vloMPl+uXOkbzTWS6e31Bi3U1BBBnYvHQvVOnskSrHRACJehOut47NLdsVN4U1Vqw+ybEYxkRbPHxfCem+70u3tqsEWXST9MziGrc4vxkasfidRabvpsvo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512582; c=relaxed/simple; bh=GP/zXsIk7W/qQ+UNS2wJhazgPEjZIr5oEO/HNA2gsAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iLuLIlguPZ6mYQoyn4NrFXN59BDhmBZNAROnWq8UyQ7aNmh2Z2AR2g8OuaXtXn9f9OgbVZg/WmYc/HJi9DGRL/tVOvmZpaeKcrwfn+F22x/L+6UwAIepkxA1PDcWWezjo1U2GQUYjLA2FfX9O+MeI+RRB/WLgiS0E63TrF5WPVI= 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=omYHZ2SM; arc=none smtp.client-ip=209.85.214.171 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="omYHZ2SM" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2bf20f6be6bso36031695ad.3 for ; Wed, 03 Jun 2026 11:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512580; x=1781117380; 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=2d3GApoepHVx+uh3La4WWn+PmYLbQZlFvom3bYXI8VQ=; b=omYHZ2SM0ACQiBUEAzyuKr44yVdvGKcTl848iXfq5dZvKywtqVHm43wdA6qwjWRDE3 aTVb+w5bMg8UjaJ93wkwQ0tTXKOqzxcLNqDc3GBugBfMqBnLNtNRMcsUx4DUgAIRiu4F hTPWiW0PiSxaj4tB9hlSOJ9YhWu2f/QXc7wl+RR8vGCB5BzNN8fCE8ofmeh/fxItfkY1 b+Wrt0WBkWfZNSlvZX4SfJTCgjU23rw5Kvaqttw4M2qtRB/i5vIk95Al6+NFJnjQoagr TaaBpwQKoZIbxWKbyh/Umfcx3cQI5kwexPktagUuS342MNyRM8VaHnY7hAXR2xeoMOOL PjYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512580; x=1781117380; 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=2d3GApoepHVx+uh3La4WWn+PmYLbQZlFvom3bYXI8VQ=; b=IsYbDSSPHRLTspuoA8dko+MMlbEGHBaK7IqCAYLr+huut1MCQJoSBc5jLd6r+C6zt0 6dYcqCsdcd7KiXpY97HPKGm7B8A8B4Kwz/NiSVd1trvQhiMnxS4gDL14zpON+IXMI7l0 Ti21odxmIXuyHFj1/orOwAQn3mZQ5iPGzsBJdiDLDJqzzy7PWUxekkUiW8mvCmgakTwc 9FjmsCV27Q1v+u+IaJAyTcx/sbzGP+KlUrWkxWyLBAopGjOtuBYdEpmwl79Ka4jBKk4X VULR8qL7vr+BfswrLc2MMs+WEoKqx3Wx50EWFplzn3bL8WYbkMTY24l4wnMvQgO0VdFj zgWQ== X-Forwarded-Encrypted: i=1; AFNElJ+Y1mJAMtwQ/2KeyJ6OZxjqx9XrIDJznu+l+4sHVmmcO2XVLf9fxLczoep39bBGIuKFoAsTuhi9lbtNnoQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5qZG3ffUNRRyiQm8LqjOQBOHOtJ6gMLT3ViZ48bELF373pT7w wLfkvuIGGU0lscfjQo/0+Mw7BHD2bL2J7rfk3ZGUyju4hTeuVwKjVgSH X-Gm-Gg: Acq92OHybzkXLIkh6PIvXORHS6IgJLhc+p+9NgXGaNiCmV8DpBVCogqjH8vsK9cYkfk 3RLZVW2SYvjUiRyxz9aVaGyYGRITs7xSbaAyQFl6sbrn0J0O04LoNE3aE9MtZKGPySqGkQau5mI 5gTNPLy2JFa1qdeAM5ooeT79QWcR5Bx935mWgm3EWQrN/XK7xTSU4PDOBGthTnrwAKZJfd2izc6 i3FubwWTSCUx4/ve/6u2ukhyFuzxncNUuLJConbZOxWvXaD8H+h6vq2UuaQLY/Hm49DA/CuQriI b7dYw8qxK2sAmGy/8pH/JcAsSdAkM7am7byTFAjG9c+VcH3ROcCZxqXWHd1bLDxJHcOv+xYW50N FWpYqs2hmYZmgMsOBd2gfBSZlvihoHHWSmOPKN3HGi9YbiNlPNquPvNczSAbHBx65XLwan02DsK TZq3rcVn70J9FQRlK5gLTNY0YFLOmTT1GReA4tU1BNp3oUp7QCTpa2iVnWyi2gyNPVvNe+zIe76 Ow90X3FUUt38JRMdyQZhlmw5UB7qKWvZ4Hb1A+eTQDsmy5LvpERyw== X-Received: by 2002:a17:903:acd:b0:2c0:ab82:6b99 with SMTP id d9443c01a7336-2c1644ec5cemr45165205ad.33.1780512580507; Wed, 03 Jun 2026 11:49:40 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:40 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 06/11] iio: adc: hx711: introduce hx711_chip_info structure Date: Thu, 4 Jun 2026 00:18:54 +0530 Message-ID: <20260603184859.89693-7-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 a per-variant static configuration structure and populate the IIO device fields from it at probe time. This is a preparatory change for adding support for more HX711-compatible hardware variants without duplicating the probe-time setup. No functional change for existing HX711 users. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 86d2a70dd3de..10ccc69f209b 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -4,6 +4,8 @@ * * Copyright (c) 2016 Andreas Klinger */ +#include +#include #include #include #include @@ -74,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 + * @num_channels: number of entries in @channels + * @iio_info: IIO info ops for this variant + */ +struct hx711_chip_info { + const char *name; + const struct iio_chan_spec *channels __counted_by_ptr(num_channels); + unsigned int num_channels; + const struct iio_info *iio_info; +}; + struct hx711_data { struct device *dev; struct gpio_desc *gpiod_pd_sck; @@ -81,6 +97,7 @@ struct hx711_data { int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ int gain_scale[HX711_GAIN_MAX]; + const struct hx711_chip_info *chip_info; struct mutex lock; /* * triggered buffer @@ -456,8 +473,16 @@ static const struct iio_chan_spec hx711_chan_spec[] = =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) { + const struct hx711_chip_info *chip_info; struct device *dev =3D &pdev->dev; struct hx711_data *hx711_data; struct iio_dev *indio_dev; @@ -473,6 +498,12 @@ 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 driver 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 @@ -534,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, @@ -555,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 Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 E304847887A for ; Wed, 3 Jun 2026 18:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512588; cv=none; b=l9/8vvA+yzi5r1F+silgLVaEYvsS8twfbNxPzRFjETuEJ1w91HLy2PekNyDO1NjmpG4gaTwcFuIf6QJVGRrdSLJYEPEfJJxgfoQem/a31+PXJXP2JaxUsxkW/AnaBixdzpYH5tbJP6Zdryxwg3w1sO5ryHNWPiBw7znJDY/Pdic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512588; c=relaxed/simple; bh=aTUwaw1cZjKNO7pd1qP0S4T7HG4+2wRyJbUWydgN08M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XhJ3sC0QkZ/0UlXPds9u8kInD3jYX9wQq9sO0l3fMXbZKfqKN5D6j7Qf9IDs4iwShn4ke+Z/zqYZHS7o7VNmfBNxfsL5lhJU7gkysBIfYicx7Xfbz7LUrXZT7fcObEpn/YPSpX7V7y+6rNOB3n2oi8qiO8JxWxl4ax7jECYQy9Y= 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=nSiEW8bd; arc=none smtp.client-ip=209.85.214.171 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="nSiEW8bd" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2bf30d530bdso57773105ad.3 for ; Wed, 03 Jun 2026 11:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512586; x=1781117386; 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=J4zRyyXIwuf/G23ISEa4BernDl6SyQJXsQmJd0MnDOM=; b=nSiEW8bd/+kurQ9McRdcCxFT/fu+6tyHdX8n4y5o6yesGCFGLNsRgGzxNR6QVqeYdX BLR1/UJvGtn2UxC3Ne4rnHM7l9aUgB0iMVepd+cUPDK2Fpe8GFjsHUBbje128eTlbBnz 3C+tKnehPc1AH8JYOGG+gDCSiY0WI+0K5xXEBX0n22tPG9QQ8H954/O1dHtqi088zYu8 kz+3xN+F1D/xKEehWIRA78gPIACW2sVOE+juei0PoIyVmPcmKH88SwrcUOUhVxTjrwah AH8hY29FGdkh+aJEXkfng1jfG0PENceoUVa3oXC8hZ0V1DgfW0oilsct8MT+eIUN/Y8Z LWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512586; x=1781117386; 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=J4zRyyXIwuf/G23ISEa4BernDl6SyQJXsQmJd0MnDOM=; b=FvHJCqg5BoT+1y9YZqDqPa/hEotLwSb7hQUMxoG8Gk2WLX33Y9xUVFoAohRy4ruN2+ VGI0ZKoMDYg3Pi1ptXiiftupVVdGH4KGsqSMThrohK8NERfNYvV79xn6rtp3ffI96Nh6 zuXKoqavKu7r4b7Rd7gqojcdHIlZGjKw71PCW1Y8d+aik8L1j7o9xa2OsE4POJ2mjdoF jSZvCpBQApEDNx4AjvW3DWo3WKw0KSTBGHba0GIqjvIOWH7NlORYwjyglEXKq+0ZJMG2 u6E0VKYhWKGLAows9nl/MfPWWki8ctKAvYkDzYW2umXmttWDsSLkDu8hzOKgRCsMbt81 kZWw== X-Forwarded-Encrypted: i=1; AFNElJ91h63BSCuYqOTn5QvwWmoGJoxdBzHrZrPFXPH27Es1Apl/Dn2EDCCKeLaMBvdaT/iF/V9zX+yOos6kklU=@vger.kernel.org X-Gm-Message-State: AOJu0YwQZyHXQyN7UCGwjG3FduYsLYJUkjrVtJefP18scs5MOKysX6iq LOfkxtPIT2z6b2ZtWmPPt5YTcgQq0niUlh0rMgPjPc8Upsto6T+p+D1S X-Gm-Gg: Acq92OFsKUt0RIhs+OrH8rced6GYBuIhbnv23jenoNpdLVhEMULpyi07vBnZsJHGT/z S3NUcjOb27/U6BDV/pxMPQOw5FQpHRu54aIBTN6hGQ8ihudW0jKQBEZJOoGfQxsqrUchtaeGssj acKq+FOeFPOKuMTZRcnBcLzhQM3dzmi3Qta6ZD7DB5uf3i+xP1KzDuQ1QeNUl1uRkGLKM7h3mYO VuTLGzZRTUSZSD5SN/Tdsy4fBxhlry4Q6VBt5UCziziWlsgNx5lwsJZU5dxIJxGfhOuKpSziSuU fPUtACPGL6yKRme0N8sKDexwmZ1TGVBWXR8TDgKpkymY7zoTLEyWwNM5BxvZaNMxSYWAjS+nUbR D2+afmZiJqNSRwwVmUyxxLVbmn0o2maJmsN5Q65CfyL2Kp515ySZd/m7CYr2hYCm4sbh+Vp/iIy CWoB7XhugdOq9qjD3SVx3ytzO6kc0jD8fpcmPVLUL57IC7zsmKFkH9EbUbyL81VlIijvl6UzfRH n52yOy/W83/iWqVCpsSYYYg/VybZZ3X5GEezIjc9cvcm2Gzej9e9Q== X-Received: by 2002:a17:903:7c7:b0:2c0:b35d:ed49 with SMTP id d9443c01a7336-2c163a16197mr33072265ad.2.1780512586078; Wed, 03 Jun 2026 11:49:46 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:45 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Date: Thu, 4 Jun 2026 00:18:55 +0530 Message-ID: <20260603184859.89693-8-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 selection out of hx711_read() and into its callers. This is a preparatory change so later variant-specific code can pass the per-channel pulse count without adding a separate read path. No functional change. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 10ccc69f209b..30e1ce321747 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -155,7 +155,7 @@ 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, int trailing_pulses) { int i, ret; int value =3D 0; @@ -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 (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) { + 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 Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 D9CF346AF32 for ; Wed, 3 Jun 2026 18:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512594; cv=none; b=mM3A68TZFD23f+w6jd4mpJKEeVxVMw4Il6GY50t9kL24FJuo2JKndpyz/KV4XpprGdCHXg7sbJ4H+Cl/QYsEXcjSwLmvsYWF4esoxz3rL6AOJztv4AxWy4TbeulG7d+oIeTSUmquLiuDkT2fSIQxAZUqEi3hQQEj2AmKWxxqNCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512594; c=relaxed/simple; bh=IyYb8UgF/AKA8+P9d730SEMTu3OzJGnh9mo/jac4tKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DbpHlJkFvT7k7w0ajSDtqN08/BF5Cr8zPCkjFSf9WvcU3wxo4RVubNhOzkE9rEy9LcCmjezyyBuvZtX7HYLCtgyXaMAx6BrmbmZZT7Jc6l8pI6RbL8FGYtp4Ezsl7ujBd7x7ROLopRWBzNHX+gi6CcXaB1VOPO0+52T3+PCZUf4= 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=rS1o4ZGI; arc=none smtp.client-ip=209.85.214.171 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="rS1o4ZGI" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2c0c1e0d00bso40482825ad.0 for ; Wed, 03 Jun 2026 11:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512592; x=1781117392; 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=O1zPHIbDPv87v1NJ8/Wn8nmreCkN/BzTtCRIc6PgU/s=; b=rS1o4ZGIIa1cXEa/YK+hV+m4TLWhWt42DUfvU2pmVxDQ9L3gia4i+kh8z3VKDMLqsZ xX1TqL+aw+ybwc0rHhcMZSVge0aBzHXfaRRQXFgozRYSKp7IqNLZP2iSpWM4ceKoU4Yg 9am5Xm5Xee0lPt2dB5DroebWr7+N0LrQAFOvSQt4emHup4vtKQXlG7IRoIKCB37I6LEH GVylcIUVVSiwld2nr2OdNxZ7q6J6R+9sUVKWFfgySJHk+83rE12RsIPxL+KkgdVo2J74 pk89/z3GWBN7VtA0VZaF39iQ+FDp+xaqJHGVFdab+EOjSG95EE3834YQtS0IUpJtvnq7 maZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512592; x=1781117392; 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=O1zPHIbDPv87v1NJ8/Wn8nmreCkN/BzTtCRIc6PgU/s=; b=RwqY4krm5xyHC7lnw1yksgWS16l6hZM83jp5F9/c464pTJK1j1a1qIg+4o9RodpRZH OiCsiuPVsmz/nw7Q4C/vwQMmB8JkcIJjnn/Hf8VrPXPUm/I7cjG5TavHLgB17AgxOTn2 6AaJKeOb3BGPQXfmuY+zTWBSF+o3CusibAnkKBla8JC733bTH1uzTslc4KpohfPOOLlR HnzFSkmk4j7zc6spitLP7ck9pJY+iVBRZVXjJ4Ww//3aUSQXmwVmbRwIwTvNhEaBFQv1 StwI7UxZMf3snUKzFGewDVLHdzHmtW9v7/iE8LYYbdW/K18pOqgGPzU41le3DcX4cD5O q77g== X-Forwarded-Encrypted: i=1; AFNElJ+/PAiEWFVd+J8IfNgHQnJYd5xzlr4OKFzcYhKdSSOF2x9BhLXMfQnf1+08+7LtmUq/Cm41NeaDs3Oku0M=@vger.kernel.org X-Gm-Message-State: AOJu0YzxQjVIJAx560B5TMBUS+kYHYoNrpr1B0c+Gc+vmlqBu0YvXvvX HV7vE41NNRwOnyekMn/acU75JjQ8gum/NJnGr4UljWcDDNLd6vxI73/E X-Gm-Gg: Acq92OGyouJ0UQ9o1RVNYf4BxCh8gX8v+tsiH3GSzjgNLIo39SVRB5Qob7YtQCM1WJp Jil2cxYFC1XE7qbCHb4C2WXn//vqyow4149TWn/JgPPMgfayRkoeM/+Tnwkg1lYkSUlcLH5CEPB VCDGzEbipPeX44VRuBu/amdYLTRSG5gZkKGfBXNYfhtMV2M/yA+PSTcJpT1dVofdd25JrMMcT3x CWMp36mJy9QOSFSylVRPCcshs5cMRjh1drsQsCv8gikgtEBoF0HaJ83GFX+8XI6aTu3WZNiufpw Nn8PHd8rBLh3o7Z58GtKCzVSFLJ6rgLwwE0zSCVyPtlDS19IAspT9PfHqw1QV0GH99kPLx6T7Oc 3pnkz5ZGOBdq1/7clH7FUdtWaee7gIAWYJfYbJycWBeCCmCR3ik6NrtwcfpyUt9B/QIlblWKrc7 UbPmzpiRY+8Hrfm2o74eV0OtBm/bkmDV6aoF8sfe+mWueVaciX0TzKAlpqf2yIhnFPMl+y2PBEv mtw17TpxuTm5CrUl++12RsVFnnXa/RZfKUHgB7qJ660olulEmDnNA== X-Received: by 2002:a17:903:2443:b0:2bc:8f62:990b with SMTP id d9443c01a7336-2c1644dd3a8mr46147885ad.41.1780512592203; Wed, 03 Jun 2026 11:49:52 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:51 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 08/11] iio: adc: hx711: split variable assignments in hx711_read and hx711_reset Date: Thu, 4 Jun 2026 00:18:56 +0530 Message-ID: <20260603184859.89693-9-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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" Separate the initial value assignments from the declarations in hx711_read() and hx711_reset(). This is a small preparatory cleanup before the later loop-iterator and variant-specific changes adjust the local variable layout in these functions. No functional change. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 30e1ce321747..4ccb0bf2d71f 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -159,9 +159,10 @@ static int hx711_read(struct hx711_data *hx711_data, i= nt trailing_pulses) { int i, ret; int value =3D 0; - int val =3D gpiod_get_value(hx711_data->gpiod_dout); + int val; =20 /* we double check if it's really down */ + val =3D gpiod_get_value(hx711_data->gpiod_dout); if (val) return -EIO; =20 @@ -204,8 +205,9 @@ static int hx711_wait_for_ready(struct hx711_data *hx71= 1_data) =20 static int hx711_reset(struct hx711_data *hx711_data) { - int val =3D hx711_wait_for_ready(hx711_data); + int val; =20 + val =3D hx711_wait_for_ready(hx711_data); if (val) { /* * an examination with the oszilloscope indicated --=20 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 66A2A47D92C for ; Wed, 3 Jun 2026 18:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512600; cv=none; b=V5I19EkvLFyanshhUt+LQYwaRK1mBcOMgD7zub2dIxpxZhVKHK/UWEIbAnIM1Hh89+HkbHB231QgzW8UJahxA2Br3ZYfr6lPYK8l8q9Fq/bEGkUnXZM6U2iAKI8EDdk/yGT2zEDW+foYBiir4KqQM08Uwm5LAfeopiPQdBFkNIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512600; c=relaxed/simple; bh=8sTc3ePfTO1HkNzwXZekmT2AeOdDHgPOdpy0VtjDF3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhUayETMDOCiZdHVErlnDIPQT8x+iGsLakY/2Va1RLL2rDGoNfeH+L5ZcI3eabR/j3D0mdj0T/H/FcXlnIrNVlxsq/2lCsU3Sat4jD/kWi9UAo7heTOqXEUtd5jv3fTAQDn0rdsz7jnusVLqKWSL5jTw2Mx7Y+DBr+tAZ1FrSAA= 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=UMWK9FZG; arc=none smtp.client-ip=209.85.214.176 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="UMWK9FZG" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2bf2e8ccca1so35458755ad.0 for ; Wed, 03 Jun 2026 11:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512598; x=1781117398; 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=RTBVI1ML053TliZ0TwngU1Pm81C+cTmh1wKJVMjMXjs=; b=UMWK9FZGyn5aqZNwbAriEO048QBwpmTtpVSEIcQK/YtIKZZF25FfJusNJSweiQMBlC d9KjJfHlSewLHTMjNC5+KTtZT1wtzXCSauqu1anBXBqtmz/nqli1QwexzikRP89TEnEe 84RYhjEu7eAKa6AGupUCPSDPaEBK6jOBDmbre5fRjsIJevQfecbfEJ1NuglswXEm8tgb Ca/mZubmlAL4DGTQaaGkrEUeTQG0dRyhDTmjJhHpIRJpeFZUegUJf2/MjGBphEKaPtsn xytxdjmm+87Jldjd7L23YpDpR6UWJTfgLVtwq3WV4nuhLM4lpbJwD3TmX2ca9fMsRjiM eVow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512598; x=1781117398; 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=RTBVI1ML053TliZ0TwngU1Pm81C+cTmh1wKJVMjMXjs=; b=l8zapeE+NvlKIhq1YwJxQOeOtCGd9t+0G8HoPlIjfS4dnIaaTLrZ9a0Px2C6C/kiqJ ACzwaR3Tzzami+g3r4EQu1r/FTys66EkeUNEEkctGThjQmTOk9HJ0nrsSq4ba/OHTt86 2mWKE6NqjuW8//AfrGbNjxRM6tTGB82a6A3Jj9D0BvmETNdyZMy+sgOxixrEGqhXsy6H 3+w4P6vyG5QIolUxqhQv4RGJ73FGh7wMLv0sGBWye8ToqngPnxPS2kB3/JqGQpC4xuQB ijtAOwYIE8IDe8vRgC2rwnN8l3Y8p2+Ow8kW0bceMaH9SVZNfodsK2B1vtWrqwYrPNrf Vhbw== X-Forwarded-Encrypted: i=1; AFNElJ9E3rIOxw5fVXx8Ik6bgoQvFQK1PkumZENldoA7jXXzSY/TJYpp5Y45MjQrs8AjyOX9ZbCEuysgRmosPsc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5vfVeSAvgsKZiS76NARynhAYTQeWPGOYT6cdo/TtaWQnp2/Iz 0K4H7fM+UcilG0B05yabYWXfqR0aoy9g1eYmts4/QiekzdgxY3g57YLz X-Gm-Gg: Acq92OHJHUwiwW0MzoGhcqgwIwOEcarUMeVQuvwKuSLGZ/uhp8rpG6agA9sg9HQt4qh gjDpPsGQxjtf/hm7VICeP89MRLnIV2Mx9PqhD1P75lqDwJErVMr3hx4IsvlJCaJ2x+R5Z4ori5v wMpTYYBZkRDn6+C7iRiR7ciRcOzX//rjNaNZypyrcMhhiTRLl3ZuIhw7wGRRqIGVauMoXGum7oJ IscvX1WcnGB3Je8a/caFMIDDdsgmnuP4OTClloJFgz4Kb7Lqd9IiSqiKyCte9sk/QhdfWVjkso2 MXZHlEFV31mrBpRLki/egz6vDagIyyH8q55uGR8AjaLkYUjeIz46F1dDctf7EIvOj6N2hWje2Hn Dv1WFzqp54QrXNMylFWcxC4+oEEH0URnlL/4pw9e/s48wE/HrMXv/R6kn/fUfsZPTfFOcCPgMSy xFhb3ei53Oa0LmLRnt0kGeBSXTykopieeQcqpwaB+Kd1EBOpRU14IEfKBOnfD6oYqld5RiJFq0H 7N4xPpt9FNrR6FGUflnB0wevWhu7V16W1W2YyquLzRvrBsY/H/AKA== X-Received: by 2002:a17:903:4b50:b0:2c0:a373:89b9 with SMTP id d9443c01a7336-2c163a24bf2mr49596335ad.6.1780512597506; Wed, 03 Jun 2026 11:49:57 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:49:57 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 09/11] iio: adc: hx711: localize loop iterators in hx711_read Date: Thu, 4 Jun 2026 00:18:57 +0530 Message-ID: <20260603184859.89693-10-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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" Tighten the scope of the loop variables in hx711_read() now that trailing-pulse selection is already handled by the callers. Also replace the 24-bit loop bound with a named constant while touching the same code. Suggested-by: Andy Shevchenko Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 4ccb0bf2d71f..e5d842853b71 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -23,6 +23,8 @@ #include #include =20 +#define HX711_DATA_BITS 24 + /* gain to pulse and scale conversion */ #define HX711_GAIN_MAX 3 #define HX711_RESET_GAIN 128 @@ -157,16 +159,16 @@ static int hx711_cycle(struct hx711_data *hx711_data) =20 static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses) { - int i, ret; int value =3D 0; int val; + int ret; =20 /* we double check if it's really down */ val =3D gpiod_get_value(hx711_data->gpiod_dout); if (val) return -EIO; =20 - for (i =3D 0; i < 24; i++) { + for (int i =3D 0; i < HX711_DATA_BITS; i++) { value <<=3D 1; ret =3D hx711_cycle(hx711_data); if (ret) @@ -175,7 +177,7 @@ static int hx711_read(struct hx711_data *hx711_data, in= t trailing_pulses) =20 value ^=3D 0x800000; =20 - for (i =3D 0; i < trailing_pulses; i++) + for (int i =3D 0; i < trailing_pulses; i++) hx711_cycle(hx711_data); =20 return value; --=20 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 8A79C480335 for ; Wed, 3 Jun 2026 18:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512604; cv=none; b=l1lXn2362T4CRzaS6sBRWuV3gAKwwDscpyoq3c3OtWsWcm5MVrWpnObnw/R17KpPO1XE5ITVXznsglvq5C1wywQoLKTz2fN6IITakrXC1Irf70Eq/yOlsBDKoojEBR1M/7AuX9PkCthKYO9fJzjBzqYrZXkfy9GyfC4pOFNmMcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512604; c=relaxed/simple; bh=3FrcsQlVziUdeKI/N9eYaCs4RJmRsrcZLsIz3cZSFq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cqQFIywJAloywKUxrnAvsKtCRc7l+erECqAK8CPvvAMdRg/Af3GWrgTgTifbo3w97UFmIZWtUlfZIt6QY0FvtxnTHVkqF/8vpjRcVkhqXwJIu8ono9+Kq344MBifgqeDvRt3Nf4DW6Nur1W4Z8RMgQvMyLW5ie23uEpDptQ64kI= 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=cAtM4dH+; arc=none smtp.client-ip=209.85.215.180 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="cAtM4dH+" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c8587427468so1885057a12.1 for ; Wed, 03 Jun 2026 11:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512603; x=1781117403; 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=uk0PkavUtmrtR763X7Xl8KGOaAn01gQsV9JDZDG7T1A=; b=cAtM4dH+jUXGOCPp8gH4t2OYkCT6gxfYFDuquYsvqFzbRonXuYyiGLx35PxuRsfo9e HCdfQBS4iLF0IsNsViisHqeiM8QyCpHDqWeJ8lBu29tUF9a7ttel3uHF2YfhKb3l9Wq4 QJMjGR11dnyUGyRdceWLQu8rWn/rk80x+mWXDjLjpJqKKOrwvJPlFmuD9eULMiXHsvV6 wABNdebnVnE2pV0fhOkjGsoj0+nSARU1Jn16PEzsYxIVtzGNSt7bZd87YIWiDLWLNMkl XArZ+Tf9snr+ahJtxOlYq8iHTzIyqHc1McxnKFIG6Lwg0l7QiRXQ++t/CYnD3DS3r97J 1Pig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512603; x=1781117403; 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=uk0PkavUtmrtR763X7Xl8KGOaAn01gQsV9JDZDG7T1A=; b=Dgrq702Kr9I0Yv44Xr5p33mF8cUzoyfEnPc1Nd1enOfyBbJDQtiYn83pXGbt1/2azV tmP3HVnJWnr+UwvEgCUwdSAvpecWN9NJyW4m3NESoxpLqADYvDuTm49ilibqL/oZ2Xe0 ixeTcjYLR+XRn7jn3DRRE7GneDr4AmrmZSdN3ryzOkgBvifdXss7iV2h5vldgIUctYk0 3YFpjG7uOBp8H0W533s1l+m5uflQyiEpom8s9YZgrki/LHsg0EzgbePXpbeayq8If9l8 XWA7D7/5D8F+TVlAeM+Mrac9ecAbTksTcoT4xK2nUtS6owd9YyveMIOTE0a3miYMXACx P2yQ== X-Forwarded-Encrypted: i=1; AFNElJ85VZpUbk+Tv87FC5sZ7RLk6Pq17X5FqHv0m8UN1fJ/7rV/VKPqkIeJV6lzBRRspHTqv/tbB9/xUjmuGSA=@vger.kernel.org X-Gm-Message-State: AOJu0YxNdLTOjWzhJ5y2VmteSb1AYFqE906UzOQ8bFPCdHxYBtIt4yz4 TVN5MZM8DNjVwtczNjr2Qx10C/gB9HpsGQI08ekTKUO/O+y05b1AFumK X-Gm-Gg: Acq92OExO24ZqTQKn4GCY2d0JYsn+ilsxTpbvta2AkvZKpoKyCHWezPgrKw2spDeoNG ZjT0QO40ZeGLxZhdHQ1qVkixX3jpzuetSXAvDfN+c+wTCfbXL71o6I/Xty+VTSPmbQcSkexuQqU mV4hZaRMnJxtki4qkqlaGx7mdw0SLSYqUYof/X4PUXGATYrAhCfPAB9jKZUS5RO9A3RKPYm+cOh KyIUihlXOdV+iG+J6UELrrbT3IemjtOhV6CPTmlRpz5KKX2lXtKqTAiCMOSL0OvG7xt+bvBJHLZ t9Tijbb0C35uUbM2KSaIzP5bHWFKCzMNgM4l3m9mQNJK9ir8nvYyH7fWtWsMPXf/SdVxrAEp0qa G0wAo9eHasP9pTS6O/AiSRi2L3RHc2AECbMX7iFcmpdf6tnXXyYPua1+CHPWThJcn1mTSY2C6Vg D9kECqfeFUc0V2pII8FNjYd4Z/bCZ4QTKsIpOp6hbaNsmVFsI/CWVq/kd5FghtqDu9ra6N+Nkgr 96flNttWR/Pee+SkKTtSLOX8oXXHovYDKWtbZ84ZW2fPTWZeVnkrg== X-Received: by 2002:a17:902:cccd:b0:2c0:a746:7aff with SMTP id d9443c01a7336-2c1644ab4dcmr44586685ad.24.1780512602733; Wed, 03 Jun 2026 11:50:02 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:50:02 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 10/11] iio: adc: hx711: pass iio_chan_spec to hx711_reset_read Date: Thu, 4 Jun 2026 00:18:58 +0530 Message-ID: <20260603184859.89693-11-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 the channel descriptor directly and update its callers accordingly. Split the existing HX711 channel-selection work into a small helper so a later variant-specific change can add a matching helper without growing hx711_reset_read() further. No functional change. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/hx711.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index e5d842853b71..fde95758b9a0 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -268,7 +268,23 @@ static int hx711_set_gain_for_channel(struct hx711_dat= a *hx711_data, int chan) return 0; } =20 -static int hx711_reset_read(struct hx711_data *hx711_data, int chan) +static int hx711_set_hx711_channel(struct hx711_data *hx711_data, + const struct iio_chan_spec *chan, + int *trailing_pulses) +{ + int ret; + + ret =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); + + return 0; +} + +static int hx711_reset_read(struct hx711_data *hx711_data, + const struct iio_chan_spec *chan) { int trailing_pulses; int ret; @@ -282,11 +298,10 @@ static int hx711_reset_read(struct hx711_data *hx711_= data, int chan) return -EIO; } =20 - ret =3D hx711_set_gain_for_channel(hx711_data, chan); + ret =3D hx711_set_hx711_channel(hx711_data, chan, &trailing_pulses); if (ret < 0) return ret; =20 - trailing_pulses =3D hx711_get_gain_to_pulse(hx711_data->gain_set); return hx711_read(hx711_data, trailing_pulses); } =20 @@ -300,7 +315,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 @@ -390,8 +405,8 @@ static irqreturn_t hx711_trigger(int irq, void *p) memset(&hx711_data->buffer, 0, sizeof(hx711_data->buffer)); =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); + hx711_data->buffer.channel[j] =3D + hx711_reset_read(hx711_data, &indio_dev->channels[i]); j++; } =20 --=20 2.43.0 From nobody Mon Jun 8 23:56:40 2026 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 4FA384657C0 for ; Wed, 3 Jun 2026 18:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512610; cv=none; b=EgVnJuzf/BV9nH4wXToC5IicxVaU0xFctLHjn1aDch0PM5wyGqOa9fxjipznuodNzuRNqF6FM2ZS4M2M+yOEtjLOzmkzA86S2+TnhG4LFjk70vptBBqHV4TE4KwPj2octtunYYXRYV77ExRIGa+m1BTRx1dkZ1oM64MHVieX7jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780512610; c=relaxed/simple; bh=2XzAFqP+F9LBNe4wyGe5OHtr4H/2Un2MTuKDGABcjGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ST7NbsPgnxDV5sSL8Ly0O2/6DaWXehALOE8DjUWNVxToYp3mcVuQg4ZxT9IOI+XKrpOUzoQpYr3eHoBcQz2pREPNLaRLb0Z4NNpr4IXvWdVE4mgcfFwfNosdJVzIo13Jd13cdXnfDLnVlwAQasx9cq3zceCUUyS6i7abrBbv6zU= 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=USLLoCIm; arc=none smtp.client-ip=209.85.214.172 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="USLLoCIm" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2bf2247e38eso50385645ad.3 for ; Wed, 03 Jun 2026 11:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780512607; x=1781117407; 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=t0IjEvXa+CVvSjjrjYndhh9V8PozPogd5A6kdrYh1uA=; b=USLLoCImjEvKAKBYnKW3I539h5tPPGNW9iXwKKFwp3ay05s+YhC2Ghvk8vh1noF3GG BmWnqngpw/ArRoq990Niav+dRHNjkFNFxsqdu1Sag9Mca/hccqOGbPEO5Gp3lKHlKve1 BOeNu0mcJVWju4LTNVkGH2zkQd0pT2kIuTFtoRdHOJd2O7A9rQXkBoNGC9eXrPsd5y7o lp0VG0Zh+Yu00Xd/mINmP6B+B2+Q7f2Kdy8iIZGVAjbnYoJ5ii6RNOQU484G0ZOe4Jvh oNg84Z4ZifuGg9AmAwfpmPSWoVuAfjlBCU+xX/RjBqCHGsqaaJga1c9BDVZty/RlnBee 7cjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780512607; x=1781117407; 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=t0IjEvXa+CVvSjjrjYndhh9V8PozPogd5A6kdrYh1uA=; b=V2F6Al76LFlijyczc7XE64xWmCk+4S2fNZ5wJ9l6zv6sWiPRMtadISB944zS9T4OdV Wt9R0tg+R8/MN5VjoVjGW1op+ApgcVIMPvR1OJ4ZpCbxFg2Oht9MYFH8bn4R7+JyvyNr Bq8+zrs0wGHtvH9+czIssfZmas7uE2utmvcJd0vcJ3tYapIT4ihZxIfZ/ut0p44NPQDN kqQt738kc3k1MSXq4NH5SJNXYR+DTBN3oa0lBEraDrIKbQ2f5Lg8qWbQpBsjSfbR6xEX tDLCI4Ybv4dbOv/P53n18EL9airZBJhDgUNkUFh3RkPRkhyk8DnwzhPJJiiuGBUGco9r x63A== X-Forwarded-Encrypted: i=1; AFNElJ+iMposBBNuWWMPHo/yyiQjbD1PvApwbBeNYc2o1sZEPzj17E6GQgi7iPRvRm0Nin9eZWYnSzWMYqNwJVw=@vger.kernel.org X-Gm-Message-State: AOJu0YxfHLP84QwoKoVQNtPsX8wGRsiZNf5a1L5p9Ta/i7zDP9b5zx/O Tbzs0UGq5Xq7y1HYq0x0T+1tZM9CG06iMhcGj44MNaUN2mdWKWoUlSmq X-Gm-Gg: Acq92OG3OWAfLMx45/yz5rwH48hoio6b14JPG1Mcx/F9RTScNwjjTmbClyQmhRS9XhL OoXnw/g5ornQEwRAfarUiuo5LvRsuOHMGaws98lRq8GPtelh05CpEmdfeEVqxL2HCXiIhYknuY8 7K6ct0lbA7GseUI44scQoDv6wNX2v+Piuhtz52+y9hC+EfukMYakGvsja2AFnMe8ZKoqzLSIRnB F11vqW9YDSwf+WcKqP4c9GpYlbPJHJa6l/d/Y5EmXsDuAktWa723dA8u61dlIaXvXb28J7PAhho kIATBfgT3+COxFoOgFlbAoxd9nM7zbxianvS5KR66MpznkvHol3jlU4FVdTJx3gfjs9MdBu0M4Y WwlPo4fPOR8o1WL3uBbGOItCiPP3hA8KuaLs7QOmrXyTHChWmVo7Uxxh/M1pxDtca72sXIU51OD MuG1mbUpnN1UY/3O95jbJdINpP1qq0ilRNtEFKu6oEJYUZVUr07P1Qfa86RHC8HiASGY+uvoMX6 /8E/o+JKQyCxeiHuJeTYAPeW3gkdPK8kqk2mue5myS9x2CcJim4mw== X-Received: by 2002:a17:902:e5ce:b0:2bf:356f:4e17 with SMTP id d9443c01a7336-2c163a23f94mr49372175ad.13.1780512607502; Wed, 03 Jun 2026 11:50:07 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2409:40c1:4015:6e6f:ee79:7998:9a6f:65e3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c164f6d59csm32139675ad.4.2026.06.03.11.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 11:50:07 -0700 (PDT) From: Piyush Patle To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, ak@it-klinger.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andy@kernel.org, nuno.sa@analog.com, dlechner@baylibre.com Subject: [PATCH v11 11/11] iio: adc: hx711: add support for HX710B Date: Thu, 4 Jun 2026 00:18:59 +0530 Message-ID: <20260603184859.89693-12-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603184859.89693-1-piyushpatle228@gmail.com> References: <20260603184859.89693-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 uses trailing PD_SCK pulses to select the active mode. Model the HX710B with variant-specific channel tables and IIO info, track the active channel across conversions, and use the fixed gain value when computing scale. Also update the adjacent Kconfig text, file header, and module description so the driver text matches the newly supported variant. Signed-off-by: Piyush Patle Reviewed-by: Andy Shevchenko --- drivers/iio/adc/Kconfig | 8 +- drivers/iio/adc/hx711.c | 222 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 205 insertions(+), 25 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index a9dedbb8eb46..28188c97030f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -791,13 +791,15 @@ config HI8435 called hi8435. =20 config HX711 - tristate "AVIA HX711 ADC for weight cells" + tristate "AVIA HX711 and similar ADCs" depends on GPIOLIB select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - If you say yes here you get support for AVIA HX711 ADC which is used - for weigh cells + If you say Y here you get support for the following AVIA ADCs: + - HX710B + - HX711 + which are used for bridge sensors such as weigh cells. =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 fde95758b9a0..447699e1d60b 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * HX711: analog to digital converter for weight sensor module + * HX711 and similar ADCs driver for weigh sensor modules * * Copyright (c) 2016 Andreas Klinger */ @@ -15,6 +15,8 @@ #include #include #include +#include + #include #include #include @@ -84,12 +86,16 @@ static int hx711_get_scale_to_gain(const int *gain_scal= e, int scale) * @channels: channel specification array * @num_channels: number of entries in @channels * @iio_info: IIO info ops for this variant + * @fixed_gain_val: fixed PGA gain (used when @has_fixed_gain is true) + * @has_fixed_gain: true if the variant has a fixed ADC gain */ struct hx711_chip_info { const char *name; const struct iio_chan_spec *channels __counted_by_ptr(num_channels); unsigned int num_channels; const struct iio_info *iio_info; + unsigned int fixed_gain_val; + bool has_fixed_gain; }; =20 struct hx711_data { @@ -99,6 +105,8 @@ struct hx711_data { int gain_set; /* gain set on device */ int gain_chan_a; /* gain for channel A */ int gain_scale[HX711_GAIN_MAX]; + int channel_set; /* HX710B active channel */ + unsigned int samp_freq; /* HX710B differential channel sample rate */ const struct hx711_chip_info *chip_info; struct mutex lock; /* @@ -207,6 +215,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; =20 val =3D hx711_wait_for_ready(hx711_data); @@ -226,8 +235,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->has_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; @@ -283,9 +295,47 @@ static int hx711_set_hx711_channel(struct hx711_data *= hx711_data, return 0; } =20 +/* + * Return the trailing pulse count for an HX710B channel (Table 3 in + * the datasheet). The supply-monitor channel always uses 2 trailing + * pulses; the differential channel uses 1 (10 SPS) or 3 (40 SPS). + */ +static int hx710b_trailing_pulses(const struct hx711_data *hx711_data, + const struct iio_chan_spec *chan) +{ + if (!chan->differential) + return 2; + return hx711_data->samp_freq =3D=3D 10 ? 1 : 3; +} + +/* + * Switch the HX710B to the requested channel for the next conversion. + * channel_set tracks the trailing pulse count that was last sent to the + * chip; it is updated immediately after hx711_read() commits the new + * mode in hardware, before waiting for the chip to be ready again. + */ +static int hx711_set_hx710b_channel(struct hx711_data *hx711_data, + const struct iio_chan_spec *chan) +{ + int trailing_pulses =3D hx710b_trailing_pulses(hx711_data, chan); + int ret; + + if (hx711_data->channel_set =3D=3D trailing_pulses) + return 0; + + ret =3D hx711_read(hx711_data, trailing_pulses); + if (ret < 0) + return ret; + + hx711_data->channel_set =3D trailing_pulses; + + return hx711_wait_for_ready(hx711_data); +} + 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; int trailing_pulses; int ret; =20 @@ -298,9 +348,16 @@ static int hx711_reset_read(struct hx711_data *hx711_d= ata, return -EIO; } =20 - ret =3D hx711_set_hx711_channel(hx711_data, chan, &trailing_pulses); - if (ret < 0) - return ret; + if (info->has_fixed_gain) { + ret =3D hx711_set_hx710b_channel(hx711_data, chan); + if (ret < 0) + return ret; + trailing_pulses =3D hx710b_trailing_pulses(hx711_data, chan); + } else { + ret =3D hx711_set_hx711_channel(hx711_data, chan, &trailing_pulses); + if (ret < 0) + return ret; + } =20 return hx711_read(hx711_data, trailing_pulses); } @@ -322,6 +379,9 @@ static int hx711_read_raw(struct iio_dev *indio_dev, if (*val < 0) return *val; return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + *val =3D hx711_data->samp_freq; + return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: *val =3D 0; mutex_lock(&hx711_data->lock); @@ -399,20 +459,26 @@ static irqreturn_t hx711_trigger(int irq, void *p) struct iio_dev *indio_dev =3D pf->indio_dev; struct hx711_data *hx711_data =3D iio_priv(indio_dev); int i, j =3D 0; + int ret; =20 mutex_lock(&hx711_data->lock); =20 memset(&hx711_data->buffer, 0, sizeof(hx711_data->buffer)); =20 iio_for_each_active_channel(indio_dev, i) { - hx711_data->buffer.channel[j] =3D - hx711_reset_read(hx711_data, &indio_dev->channels[i]); - j++; + ret =3D hx711_reset_read(hx711_data, &indio_dev->channels[i]); + if (ret < 0) { + dev_err_ratelimited(hx711_data->dev, + "read failed: %d\n", ret); + goto out_unlock; + } + hx711_data->buffer.channel[j++] =3D ret; } =20 iio_push_to_buffers_with_timestamp(indio_dev, &hx711_data->buffer, pf->timestamp); =20 +out_unlock: mutex_unlock(&hx711_data->lock); =20 iio_trigger_notify_done(indio_dev->trig); @@ -462,6 +528,52 @@ static const struct iio_info hx711_iio_info =3D { .attrs =3D &hx711_attribute_group, }; =20 +static const int hx710b_samp_freq_avail[] =3D { 10, 40 }; + +static int hx710b_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + *vals =3D hx710b_samp_freq_avail; + *type =3D IIO_VAL_INT; + *length =3D ARRAY_SIZE(hx710b_samp_freq_avail); + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + +static int hx710b_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct hx711_data *hx711_data =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + if (val !=3D 10 && val !=3D 40) + return -EINVAL; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + mutex_lock(&hx711_data->lock); + hx711_data->samp_freq =3D val; + mutex_unlock(&hx711_data->lock); + iio_device_release_direct(indio_dev); + return 0; + default: + return -EINVAL; + } +} + +static const struct iio_info hx710b_iio_info =3D { + .read_raw =3D hx711_read_raw, + .write_raw =3D hx710b_write_raw, + .read_avail =3D hx710b_read_avail, +}; + static const struct iio_chan_spec hx711_chan_spec[] =3D { { .type =3D IIO_VOLTAGE, @@ -494,6 +606,51 @@ 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 + * 26 pulses (2 trailing): DVDD-AVDD supply monitor, 40 SPS + * 27 pulses (3 trailing): differential input, 40 SPS + * Channel 0 exposes both differential rates via IIO_CHAN_INFO_SAMP_FREQ. + * Channel 2 is used for the supply monitor to avoid aliasing the + * channel2 terminal 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, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_separate_available =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), + .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, + .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, @@ -501,6 +658,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_val =3D 128, + .has_fixed_gain =3D true, +}; + static int hx711_probe(struct platform_device *pdev) { const struct hx711_chip_info *chip_info; @@ -543,32 +709,43 @@ static int hx711_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(hx711_data->gpiod_dout), "failed to get dout-gpiod\n"); =20 - ret =3D devm_regulator_get_enable_read_voltage(dev, "avdd"); + if (chip_info->has_fixed_gain) + ret =3D devm_regulator_get_enable_read_voltage(dev, "vref"); + else + ret =3D devm_regulator_get_enable_read_voltage(dev, "avdd"); if (ret < 0) return ret; =20 /* - * with - * full scale differential input range: AVDD / GAIN + * With + * full scale differential input range: reference / GAIN * full scale output data: 2^24 * we can say: - * AVDD / GAIN =3D 2^24 + * reference / 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 reference / GAIN / 2^24 + * reference 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 (reference * 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->has_fixed_gain) { + for (i =3D 0; i < HX711_GAIN_MAX; i++) + hx711_data->gain_scale[i] =3D + ret / chip_info->fixed_gain_val / 1678; + hx711_data->gain_set =3D chip_info->fixed_gain_val; + hx711_data->samp_freq =3D 10; + } 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", @@ -607,6 +784,7 @@ static int hx711_probe(struct platform_device *pdev) } =20 static const struct of_device_id of_hx711_match[] =3D { + { .compatible =3D "avia,hx710b", .data =3D &hx710b_chip }, { .compatible =3D "avia,hx711", .data =3D &hx711_chip }, { } }; @@ -624,7 +802,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 similar bitbanging ADC driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:hx711-gpio"); =20 --=20 2.43.0