From mboxrd@z Thu Jan 1 00:00:00 1970 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: 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 --- 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