From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3BA73A0B1D for ; Mon, 18 May 2026 22:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779141788; cv=none; b=C6elu0VEoQrXsy1YN/m5U4GZ+gxPqcS0DHVO3jWAQ/r9iwB5Z/21azBz13RxZIwa14frnW+rxwyqPLLE0xFpRPTsFLWKHt1Pcbi3q6/BFe3qiLoN4QD1zIW3fRhC6ARCiUls16dP2MPmgJL+u15yhLzDHGKxJp5iQTGRifczvo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779141788; c=relaxed/simple; bh=LSkPnfPS7dcFx2Ts93fh7yYVwcsinXFO6Unbb7I42hk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H33qI9xEcFp7vlH7d7a1bD+skzEKCFEU33eBnB5AAGGZKiwB0r0OMXmWIEnKIPLR4PaB1SZj1P1fYTjK39AkpDhYClBzRnjmoyU/w5KlZA6ojU510ooDYTBFl6JbLziCt7zmHyCrihjDYM2uUig1GKdZ9PD2GWyrtC48YoauosA= 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=cjTnV4E1; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cjTnV4E1" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8353ca0f1f1so1221174b3a.1 for ; Mon, 18 May 2026 15:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779141786; x=1779746586; 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=8Y4Byz56kRE8Cxdx3gujtJfcSGY+V3XNAqSrgerlsus=; b=cjTnV4E1FN94UzbG+w/64LLNGLfXWozksBIEsF5e0eHzwVpuCPSHm1qSndQcoS7SJX m4PBiwqcj+N2b7A1HjzUYNKJvIZDfo6ZENg930fLAZ5OqMOZ4mqC88YkDQyOSnFo5JSg J9rwW431ZqwJ2cKTxA4EUoy8QCnvw4K+XDuGNLsk3h17Lfx2RFmxn3RDPmjuqZusPhYM r8bEo+bM1WW25pm0sht0hKGCADBwaL6Qg71XRi2x4aTjjpQphdcGU8cOCpIKEc4OKFs2 10/2GOSDYX/Qm+FAmBylg+WKgVn9FgTMxBzPAx8XRCticFfPgThkxEUQr5/XUEx6Td6I 5wyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779141786; x=1779746586; 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=8Y4Byz56kRE8Cxdx3gujtJfcSGY+V3XNAqSrgerlsus=; b=SOgGoEEqgZUYtEbbDrNgYqg/i8YfBiHQDMILSAlfvcqI7rCC/Gss6BOnXbePJ5n4zn SV027GWjF6sByqp+XCHDoZCya/AArystx3X+YZ84yFUkQFr3Q6esP/HWQAMIFH7eFHAg DVLqEyw9K2VjmCK0NKmcV78fQjJU/puwURFydbX504pOtIHFmM2/Krz0GlyhvmckNTEQ s/JqluyhwazzaWl/gtk1IZFr0aveCxkATdbuFO2L07+agK7kLt7XyjwUJN/KZujYFzce HT3Iyc4Y4GsyfWd/2vcImimvOLKf9d5lkVLQmgN1Md58FFjuxuVyxL7WmSbHD1kD5z8A gmbw== X-Forwarded-Encrypted: i=1; AFNElJ83SpODIqcNVm+iMLNBDnZz3ZyVpGa7XWH5+VrsKz/yPumviZ6xAhLx7rlU3M2S4VG0LdSedRqmser53ro=@vger.kernel.org X-Gm-Message-State: AOJu0YxAgfvKY0iDk76EAhucGg9E3cVr9maQtB5pyOcxVazEPsxCZ2wi hjKnV2crjgH36wPCaXsT3DKLTKLN+AbTMJZz8c4UH/zWV9DU5y8feA/Z X-Gm-Gg: Acq92OEEiyDsNyfAx8q299An4epCZeBXzP49ifrwuWXiVSTKhGLoeH9zas6r4qqVrFP 5qVMsO8Zv76zYP0kwN7o/08J3BOP+lelfZZRPMTs/lwjk3xiJhz6KjZJ2DTlJA+9KwhDBNemMJ/ 30jV7PQPqrBqieDyckvO1q+O96mAlFyFtG24SpN1lCHYh9UsEYoGETBFIoC+czIiLglE0rf0C32 MIX0xsVQiJv43D43Qs2y1YM/Oq+BP+cKH52n1h4/0iwg6ePl4ICbcUGnSn2lxd234w3y0E6a7Iy +AzUdGz32xNuAvXoX1auFvId5epeH36nUvZB/8lhY9yYxYUFBHmQNMjFUBD5iqvdlZO2mP5CE1J Iir7+mdNnAses1CF3b/7MbldW12hVFQfwKrtok4os6nIJJxOmKjY/ca/0S014jWGOBUSDRVcrTi ybI9mxWIoXxCPDv+zeztUJIKk+ovF56isFaJy3nnExZ5Qe30H3Q28tzQHNUXmRYcJwuReYZ0VpP 9Fd1fBXCYWUpzoNEyt6i10l+KO+cBL2/aC9i6vq3d4jRTgRBg/k7hT2TVYjtNklVyWbXz8= X-Received: by 2002:a05:6a00:124f:b0:82f:1f43:7190 with SMTP id d2e1a72fcca58-83f18d5bf1fmr16153852b3a.3.1779141786230; Mon, 18 May 2026 15:03:06 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.www.tendawifi.com ([14.139.108.62]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f1977b128sm15772960b3a.22.2026.05.18.15.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 15:03:05 -0700 (PDT) From: Piyush Patle To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Klinger , Andy Shevchenko , Conor Dooley , Krzysztof Kozlowski , Rob Herring Subject: [PATCH v9 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Date: Tue, 19 May 2026 03:32:23 +0530 Message-ID: <20260518220228.63322-8-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260518220228.63322-1-piyushpatle228@gmail.com> References: <20260518220228.63322-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 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 --- No change from v8. 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); } -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 = 0; @@ -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 (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) { + 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