From: David Lechner <dlechner@baylibre.com>
To: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Mark Brown" <broonie@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-spi@vger.kernel.org,
David Lechner <dlechner@baylibre.com>
Subject: [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro
Date: Fri, 27 Jun 2025 18:40:00 -0500 [thread overview]
Message-ID: <20250627-iio-adc-ad7173-add-spi-offload-support-v2-4-f49c55599113@baylibre.com> (raw)
In-Reply-To: <20250627-iio-adc-ad7173-add-spi-offload-support-v2-0-f49c55599113@baylibre.com>
Use the BITS_TO_BYTES() macro instead of dividing by 8 to convert bits
to bytes.
This makes it more obvious what unit conversion is taking place.
In one instance, we also avoid the temporary assignment to a variable
as it was confusing that reg_size was being used with two different
units (bits and bytes).
scan_type is factored out to reduce line wrapping.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
drivers/iio/adc/ad_sigma_delta.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 5362157966d89cbf0e602716aaaf0b78f3921b11..64ed8aeb71f7c6ca19fff0438fa5ccce0c1d8f8f 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -7,6 +7,7 @@
*/
#include <linux/align.h>
+#include <linux/bitops.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/interrupt.h>
@@ -190,7 +191,7 @@ int ad_sd_reset(struct ad_sigma_delta *sigma_delta)
u8 *buf;
int ret;
- size = DIV_ROUND_UP(reset_length, 8);
+ size = BITS_TO_BYTES(reset_length);
buf = kcalloc(size, sizeof(*buf), GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -419,7 +420,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
data_reg = AD_SD_REG_DATA;
ret = ad_sd_read_reg(sigma_delta, data_reg,
- DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8),
+ BITS_TO_BYTES(chan->scan_type.realbits + chan->scan_type.shift),
&raw_sample);
out:
@@ -453,6 +454,7 @@ EXPORT_SYMBOL_NS_GPL(ad_sigma_delta_single_conversion, "IIO_AD_SIGMA_DELTA");
static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
{
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
+ const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
unsigned int i, slot, samples_buf_size;
unsigned int channel;
u8 *samples_buf;
@@ -488,7 +490,7 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
return ret;
}
- samples_buf_size = ALIGN(slot * indio_dev->channels[0].scan_type.storagebits / 8, 8);
+ samples_buf_size = ALIGN(slot * BITS_TO_BYTES(scan_type->storagebits), 8);
samples_buf_size += sizeof(s64);
samples_buf = devm_krealloc(&sigma_delta->spi->dev, sigma_delta->samples_buf,
samples_buf_size, GFP_KERNEL);
@@ -543,6 +545,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
+ const struct iio_scan_type *scan_type = &indio_dev->channels[0].scan_type;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
u8 *data = sigma_delta->rx_buf;
unsigned int transfer_size;
@@ -552,9 +555,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
unsigned int reg_size;
unsigned int data_reg;
- reg_size = indio_dev->channels[0].scan_type.realbits +
- indio_dev->channels[0].scan_type.shift;
- reg_size = DIV_ROUND_UP(reg_size, 8);
+ reg_size = BITS_TO_BYTES(scan_type->realbits + scan_type->shift);
if (sigma_delta->info->data_reg != 0)
data_reg = sigma_delta->info->data_reg;
@@ -616,7 +617,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
}
}
- sample_size = indio_dev->channels[0].scan_type.storagebits / 8;
+ sample_size = BITS_TO_BYTES(scan_type->storagebits);
sample_pos = sample_size * sigma_delta->current_slot;
memcpy(&sigma_delta->samples_buf[sample_pos], data, sample_size);
sigma_delta->current_slot++;
--
2.43.0
next prev parent reply other threads:[~2025-06-27 23:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 23:39 [PATCH v2 00/11] iio: adc: ad7173: add SPI offload support David Lechner
2025-06-27 23:39 ` [PATCH v2 01/11] iio: adc: ad_sigma_delta: don't overallocate scan buffer David Lechner
2025-06-28 14:55 ` Jonathan Cameron
2025-06-28 15:04 ` Jonathan Cameron
2025-06-27 23:39 ` [PATCH v2 02/11] iio: adc: ad_sigma_delta: sort includes David Lechner
2025-06-27 23:39 ` [PATCH v2 03/11] iio: adc: ad_sigma_delta: use u8 instead of uint8_t David Lechner
2025-06-27 23:40 ` David Lechner [this message]
2025-06-28 14:56 ` [PATCH v2 04/11] iio: adc: ad_sigma_delta: use BITS_TO_BYTES() macro Jonathan Cameron
2025-06-30 8:59 ` Andy Shevchenko
2025-06-30 13:33 ` David Lechner
2025-07-01 13:47 ` Andy Shevchenko
2025-07-01 17:36 ` Jonathan Cameron
2025-06-27 23:40 ` [PATCH v2 05/11] iio: adc: ad_sigma_delta: audit included headers David Lechner
2025-06-30 9:02 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 06/11] iio: adc: ad_sigma_delta: refactor setting read address David Lechner
2025-06-27 23:40 ` [PATCH v2 07/11] iio: adc: ad_sigma_delta: use spi_optimize_message() David Lechner
2025-06-27 23:40 ` [PATCH v2 08/11] dt-bindings: trigger-source: add ADI Util Sigma-Delta SPI David Lechner
2025-06-27 23:40 ` [PATCH v2 09/11] spi: offload trigger: add ADI Util Sigma-Delta SPI driver David Lechner
2025-06-28 15:02 ` Jonathan Cameron
2025-07-01 20:57 ` David Lechner
2025-06-30 9:05 ` Andy Shevchenko
2025-06-27 23:40 ` [PATCH v2 10/11] iio: adc: ad_sigma_delta: add SPI offload support David Lechner
2025-06-27 23:40 ` [PATCH v2 11/11] iio: adc: ad7173: " David Lechner
2025-07-02 13:27 ` (subset) [PATCH v2 00/11] " Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250627-iio-adc-ad7173-add-spi-offload-support-v2-4-f49c55599113@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).