From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 482043B5302 for ; Mon, 27 Apr 2026 10:10:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284658; cv=none; b=FDjh35lM/KX5VG2l5DAzKnpkPcIPsAFqPN5kKexclEhWrQsH82tlqfCf5Bw/wMevJetrQVfzJWPOc5OcPEyLygjjk6T5HEn6mcsVoJTydDXV0CGZbuGqlQpyq/MBBSL30qeFhN0MXQXheDAzQZHYQiRn3n9MKx8mUSLDHmCFRag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777284658; c=relaxed/simple; bh=TZ9Eue8DFtaGA9w2JAdQeWItg1bP/LcCHgtVSaqBLuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kKwAxg4J4PLSVFDlZxz3hd5GMHdi1uKYGBjGBlNzhW0EY+UAtFpUXUlxX6qjUJqjWnXmdowHl6A19izN05IiCVApOMyeGaH8HOTmpfILchA4FFxuSrweQO9Rd7u662A1TlVzCQCClrvEFzPYWTTOVOw2mwc48tbbimDkw2G4N/0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pgZh5i4C; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pgZh5i4C" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-c70ea5e9e9dso4404746a12.1 for ; Mon, 27 Apr 2026 03:10:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777284657; x=1777889457; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bwygt4arcj06fgeRgeONzkm42+D0jSpsT8L72zAuvOY=; b=pgZh5i4CU1iG1mzRYftLj4faa80UuYpeu/87RBdO3kD+41vDcdn0rYeRozanbOIbGg wJBorDsVsHNCdfUOfj/Fd4ywBSYfcp5m/dzyEIgYwpEm/dVQ6Qkr9T0mqHJ3Gmm63Rvy q6bOWt0rR44DKRLeZuokHGWngVw0xgQUaQ8qNuwzXcYePFHdx5yasXGlAxbKprWvwsHB xAuRG4dUNjUTZgT6BGI/jwr+THDJFedQDOZ6j/kdrBKkAA0bGefY9AS570+sfmXeUDao 29b8idY1MxuEKdbkQWcXjyk0TBrwmgt7aefIlBSZ32hTp7XZsjI6oJ8HnT/wD0udbyXH CbOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777284657; x=1777889457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Bwygt4arcj06fgeRgeONzkm42+D0jSpsT8L72zAuvOY=; b=ptKA80oc68A2WyOSOjdZxYnRQVxwFy12ZqXvvGiUp6DVx8HPIjqJ+5N6HmaJU38E1I BnxcNY6+9y0bAgIjbQanwiRtP9IeSe3MkJ9ozo8sywyHUUPbfFEydHYWLDTCaK7ph+jw OMy7ex1/64DRybKI9LcAhyc7i2hC2aKYVCnBhlVPQ6lQyXxBfmtOsp1Ut01LnSvUsy3v WxNJbNAmcV+/ys3uEkv9mSzUQtW6jeIC1q5yszhgfMulOvGPgoAzC9jyi4KVzxgQ8Cwc MICk8r3BHLVZ0FlvOD6QS47qAebTh6cB2x3GJuzPAEGojq8okWO3aXInkMrOdTZ21KAS KTsQ== X-Forwarded-Encrypted: i=1; AFNElJ8ZEQO1BEioHUC2T6bmQ6paPgNAFNth3zZX9POuTbzXFHv5+SgQ/6pql/9/rmppSJJ7TegWCWIXZGBFEp4=@vger.kernel.org X-Gm-Message-State: AOJu0YwnQBC4S86cP1EGgcv+R/mNS+DdvT6M59TZwUaZ1GGNTwxNyEzl rZ0tc4dGo5VGDm6F/Eh51/11IbSOwI41sXOJYPngN0t8ml1t+eW6sA5K X-Gm-Gg: AeBDieuGlynvOUBc/hVYexAIG+/prc3LJ4x2mnwso7O5V1qN5MnmhIJAzcxU6mlLoOR zVKK+XKUQ9p/XeRdv1qDG6t6ZsfIlu2YOX1zGLXlHofWdZm9HqoS1CJ0ePUQg+BepAIdcBWwNDq Zekx49PxyO+xG5eX4j9VOZ1Biwc0EVc58kRYtJ7OOBtMh9E4lfaxBOiYRx5XJHQo4nvL6hSKO4b h/3+CqmN+FTj37aolQdqDQwQaJAQNGNeo6FJsrWQW3uimr/dLAggPgxYJj38zsMiuDQB3IhwKSc Q51jBKvI2NyBZnsO+0m0K/C04uZTC1/5FuS49UZ3nXqrNYTHpb3NNBa+g1d/1nMCjVYaWuxeGyR MqU7b6UneNKves9L/fo+MxKtvHWkikzjh80JCj2/y4VYIAFKRHh2EWVykxJLGuY7tznDIRRzEhT 2rtVNz+zA0fQRFDtHqZITTeBJcK7BVUqs3c2nOv69iXdBLvQ+iMbXaEpLDVU6q4gCEE7oNrWhH2 4kmLwYVH2BGu+hTOGJ4OgeFXtPmGLIj/punhvdetvbtrNeobQ== X-Received: by 2002:a05:6a00:2d81:b0:82f:24e:6a48 with SMTP id d2e1a72fcca58-82f8c83059dmr45501815b3a.5.1777284656648; Mon, 27 Apr 2026 03:10:56 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.. ([2405:201:31:d016:e577:22da:dc9:7f6c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm39534225b3a.38.2026.04.27.03.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:10:56 -0700 (PDT) From: Piyush Patle To: ak@it-klinger.de, jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/7] iio: adc: hx711: pass trailing pulse count into hx711_read() Date: Mon, 27 Apr 2026 15:39:36 +0530 Message-ID: <20260427100950.33936-6-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427100950.33936-1-piyushpatle228@gmail.com> References: <20260427100950.33936-1-piyushpatle228@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move the trailing-pulse computation out of hx711_read() and into the callers. hx711_read() now takes an explicit 'trailing_pulses' parameter so the HX710B support patch can pass the per-channel count stored in chan->address without adding a separate code path in hx711_read(). Use scoped loop variables (for (int i = ...) / for (unsigned int i = ...)) to tighten the scope of the loop counters. No functional change. Signed-off-by: Piyush Patle --- Changes in v4: - New patch. Split out from the v3 refactor patch as requested by Andy Shevchenko. --- drivers/iio/adc/hx711.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 2a6e9645f54d..8e77978f062b 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -155,9 +155,9 @@ static int hx711_cycle(struct hx711_data *hx711_data) return gpiod_get_value(hx711_data->gpiod_dout); } -static int hx711_read(struct hx711_data *hx711_data) +static int hx711_read(struct hx711_data *hx711_data, unsigned int trailing_pulses) { - int i, ret; + int ret; int value = 0; int val = gpiod_get_value(hx711_data->gpiod_dout); @@ -165,7 +165,7 @@ static int hx711_read(struct hx711_data *hx711_data) if (val) return -EIO; - for (i = 0; i < 24; i++) { + for (int i = 0; i < 24; i++) { value <<= 1; ret = hx711_cycle(hx711_data); if (ret) @@ -174,7 +174,7 @@ static int hx711_read(struct hx711_data *hx711_data) value ^= 0x800000; - for (i = 0; i < hx711_get_gain_to_pulse(hx711_data->gain_set); i++) + for (unsigned int i = 0; i < trailing_pulses; i++) hx711_cycle(hx711_data); return value; @@ -237,7 +237,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan) if (hx711_data->gain_set == 32) { hx711_data->gain_set = hx711_data->gain_chan_a; - ret = hx711_read(hx711_data); + ret = hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) return ret; @@ -249,7 +250,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan) if (hx711_data->gain_set != 32) { hx711_data->gain_set = 32; - ret = hx711_read(hx711_data); + ret = hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) return ret; @@ -264,8 +266,8 @@ static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan) static int hx711_reset_read(struct hx711_data *hx711_data, int chan) { + unsigned int trailing_pulses; int ret; - int val; /* * hx711_reset() must be called from here @@ -280,9 +282,8 @@ static int hx711_reset_read(struct hx711_data *hx711_data, int chan) if (ret < 0) return ret; - val = hx711_read(hx711_data); - - return val; + trailing_pulses = hx711_get_gain_to_pulse(hx711_data->gain_set); + return hx711_read(hx711_data, trailing_pulses); } static int hx711_read_raw(struct iio_dev *indio_dev, @@ -349,7 +350,8 @@ static int hx711_write_raw(struct iio_dev *indio_dev, if (gain != 32) hx711_data->gain_chan_a = gain; - ret = hx711_read(hx711_data); + ret = hx711_read(hx711_data, + hx711_get_gain_to_pulse(hx711_data->gain_set)); if (ret < 0) { mutex_unlock(&hx711_data->lock); return ret; -- 2.43.0