From mboxrd@z Thu Jan 1 00:00:00 1970 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 3D8F2472798 for ; Mon, 11 May 2026 17:45:04 +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=1778521505; cv=none; b=WQ1QwrJ8QJLntJhLTfeNiLwdeFwT/MR6931LTJsSr64csHLVpV2mxKo5SyW9oFNpMqVbiY9IcQhaF4/SF+uHu2OAgnO/BDgN+u19XL9AuNDQ8+NNqBf81VYvNEQ3ju8JiSE1U3+e6o7XC/vgfl0rPdx9lNpleSNjHZUM5xBfzQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778521505; c=relaxed/simple; bh=aTUwaw1cZjKNO7pd1qP0S4T7HG4+2wRyJbUWydgN08M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GKbBT3R8RkXIX9jhialW1XC4v9lcN12xE3l3qUr8xwbPWOfqXdRR7MS9CRNO/4Efj21uScFjQ83Xui+6eiHvj510RtJmweEaFMoW4b+TVZY0MLLnE+239e01Fk07Nl4XAJqLmKf9BXdpyKxTt8NqLISerzVzL4gitKz5PuZx1mM= 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=iugoT4zO; 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="iugoT4zO" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2b4583f0a1aso29684105ad.3 for ; Mon, 11 May 2026 10:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778521503; x=1779126303; 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=iugoT4zOwhqoOslTvEWq6jSQPZdUlKnjUWLn9zojPyzSJM2BNwOEP0W2MTmzeGayzr qPt32qxJLKwU/pal7vstzTQBbnnPcDGqne8n9L83xHWl+535q+Xedj99DQdApNHTCB1/ 127+JD+ottbZmY+NvNYbjBM3y4XMkXZMOT4L7doO0ea8+NI/DjNYCFQ7PIpabgifRHpb GyzS66UbupAcBu5OuK/AKiR+yHOf0DEXk7L6ARN0IkC46iaO93LX0GbJM3Cn3w3cf43v zHkCEF6QUW/72hm4irBWn+zGU7hYZTH4W2WU/s3bwusC15cG4dWTfYvYOsO/ytMHjlr1 BSiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778521503; x=1779126303; 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=dmmaeRDztq8Z/cLpJ8Q20teOKbU3HvLGqJvJE4qjh76lbm0OoujrIvJTqmCbmahmFq 58SG6MjJ3EErkAPoNFi5MHq/LDMOKZ/ScGKnd+RrWYjppSyGsHRAk3uxJ3OVOPYO6Hrk TXSvsGmVFXZaiEXgYat3pJ4sC+y1Noj2H2yH3Ioq6YhE1s+zoObgsB0LGnPyYlb/xuuk HrmxBB5mvHmN043ucymdKVu1yAJ9mR8ryAp8mL2YZcji2iFS3dAm1qYNgB5abw2ojTyO 1urgfPlamkcVqSN+fhQc7VRHNDCnEw5UTd+hbV9A7Ku/oCcJ7Aa8H1b45I1A+PIo5FA/ zzqw== X-Forwarded-Encrypted: i=1; AFNElJ+ZcvIyj5EP2uJeKBoqGC4nJvQoAOmjCpbPE45Q6b+jG1DEoN4EBnRX04d/N0mt2bx++Lz2Nafx65igJYQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwhodOSWoe3lKZ/QJsQKhk2rOVKiSMMx3KW1LKhXC0xRywIWiHc fvwHSYZZHvhR0x8VEog/jvohNpeE8Sb93Y2cAiLVibUYzQpXFNRjJvVw X-Gm-Gg: Acq92OGwtx/fiNE5td+f8PoZB+QzT50TEtbr4hrXzWtd1gZ2+/o80IqwliTNj/FWoIh XceGbUKArkRP1wFoORU+n8bmZiq5bZOa4ji7+InUhgreRFGYU0YYyk06IU/tFYmI3rrltKGen6h Y3jNJDmQ0sPv/qoktF/jFqZMN64AefZohMBWulcG0yqZ5ynWe66WEcCbGWNHsWhh56kLufAWZnQ ztNGGOHYuY+MQkGHqo9ge888UCoFVdP3Ug+HvVjgM5U81dwGUrn+Ggl5xigp9H/McyJkgTlsKXI xxcJfSs5Oht7kbzbjGtaSbVcr3w8+bqqy2ZEI8PwT9Ig62fgKbvryoTE97YWBTogITkr7khOP9Z EI836+DNgHQlF/NjzrGySWLVzGbs7wHxra7dHQFtZEacekmSBTS18stajHPJiSwk7oLWlSg1YPq TbT5nfrdS4omdJvDuHP8mJ3B5xIZcBUsx1QoQJTt6vNoovJFxyHpgUIpDwjV2+h3kOMpC64oZT7 p8SI1rOeEyeAxpYEQWmfbSxb0Yh3diydd1yYOF8Bm/HR35WLBEll7+FHAW4hwYokcoaJTc= X-Received: by 2002:a17:902:c946:b0:2ba:d97b:4baa with SMTP id d9443c01a7336-2bc7aa202dbmr97909805ad.20.1778521503394; Mon, 11 May 2026 10:45:03 -0700 (PDT) Received: from lord-daniel-VivoBook-ASUSLaptop-K3502ZA-S3502ZA.www.tendawifi.com ([14.139.108.62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e365a1sm106838425ad.44.2026.05.11.10.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 10:45:02 -0700 (PDT) From: Piyush Patle To: jic23@kernel.org Cc: ak@it-klinger.de, andriy.shevchenko@linux.intel.com, dlechner@baylibre.com, nuno.sa@analog.com, 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 v8 v8 07/11] iio: adc: hx711: pass trailing pulse count into hx711_read Date: Mon, 11 May 2026 23:13:32 +0530 Message-ID: <20260511174342.123820-8-piyushpatle228@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260511174342.123820-1-piyushpatle228@gmail.com> References: <20260511174342.123820-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