[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221111112657.1521307-5-mitja@lxnav.com>
Date: Fri, 11 Nov 2022 12:26:56 +0100
From: Mitja Spes <mitja@...av.com>
To: Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Mitja Spes <mitja@...av.com>,
Angelo Compagnucci <angelo.compagnucci@...il.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 4/4] iio: adc: mcp3422: reduce sleep for fast sampling rates
- reduced sleep time for 240 & 60 sps rates
- minor roundup fix for sleep times
Signed-off-by: Mitja Spes <mitja@...av.com>
---
drivers/iio/adc/mcp3422.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c
index eef35fb2fc22..dbcc8fe91aaa 100644
--- a/drivers/iio/adc/mcp3422.c
+++ b/drivers/iio/adc/mcp3422.c
@@ -70,10 +70,11 @@ static const int mcp3422_scales[MCP3422_SRATE_COUNT][MCP3422_PGA_COUNT] = {
/* Constant msleep times for data acquisitions */
static const int mcp3422_read_times[MCP3422_SRATE_COUNT] = {
- [MCP3422_SRATE_240] = 1000 / 240,
- [MCP3422_SRATE_60] = 1000 / 60,
- [MCP3422_SRATE_15] = 1000 / 15,
- [MCP3422_SRATE_3] = 1000 / 3 };
+ [MCP3422_SRATE_240] = DIV_ROUND_UP(1000, 240),
+ [MCP3422_SRATE_60] = DIV_ROUND_UP(1000, 60),
+ [MCP3422_SRATE_15] = DIV_ROUND_UP(1000, 15),
+ [MCP3422_SRATE_3] = (100000 + 375 - 100) / 375 /* real rate is 3.75 sps */
+};
/* sample rates to integer conversion table */
static const int mcp3422_sample_rates[MCP3422_SRATE_COUNT] = {
@@ -137,6 +138,7 @@ static int mcp3422_read_channel(struct mcp3422 *adc,
struct iio_chan_spec const *channel, int *value)
{
int ret;
+ int sleep_duration;
u8 config;
u8 req_channel = channel->channel;
@@ -148,7 +150,11 @@ static int mcp3422_read_channel(struct mcp3422 *adc,
mutex_unlock(&adc->lock);
return ret;
}
- msleep(mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->active_config)]);
+ sleep_duration = mcp3422_read_times[MCP3422_SAMPLE_RATE(adc->active_config)];
+ if (sleep_duration < 20)
+ usleep_range(sleep_duration * 1000, sleep_duration * 1300);
+ else
+ msleep(sleep_duration);
}
ret = mcp3422_read(adc, value, &config);
--
2.34.1
Powered by blists - more mailing lists