lkml.org 
[lkml]   [2022]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/4] iio: adc: mcp3422: reduce sleep for fast sampling rates
Date
- reduced sleep time for 240 & 60 sps rates
- minor roundup fix for sleep times

Signed-off-by: Mitja Spes <mitja@lxnav.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
\
 
 \ /
  Last update: 2022-11-11 12:29    [W:0.078 / U:0.612 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site