Input: cyapa - use time based retry loop

Using counter based retry loops for peripherals results in the delay
being significantly overrun during high-load situations where delay
functions tend to be vary imprecise and overrun there timeouts. So
condition the termination on the actual condition of 2s for the
re-calibration to have been successful.

As this is a very long delay there is no advantage in using
high-resolution timers thus switching this to msleep().

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
Nicholas Mc Guire 2017-01-15 15:18:03 -08:00 committed by Dmitry Torokhov
parent de901cc31d
commit cd4c1b412d

View file

@ -789,7 +789,7 @@ static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct cyapa *cyapa = dev_get_drvdata(dev); struct cyapa *cyapa = dev_get_drvdata(dev);
int tries; unsigned long timeout;
int ret; int ret;
ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
@ -812,31 +812,28 @@ static ssize_t cyapa_gen3_do_calibrate(struct device *dev,
goto out; goto out;
} }
tries = 20; /* max recalibration timeout 2s. */ /* max recalibration timeout 2s. */
timeout = jiffies + 2 * HZ;
do { do {
/* /*
* For this recalibration, the max time will not exceed 2s. * For this recalibration, the max time will not exceed 2s.
* The average time is approximately 500 - 700 ms, and we * The average time is approximately 500 - 700 ms, and we
* will check the status every 100 - 200ms. * will check the status every 100 - 200ms.
*/ */
usleep_range(100000, 200000); msleep(100);
ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS); ret = cyapa_read_byte(cyapa, CYAPA_CMD_DEV_STATUS);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Error reading dev status: %d\n", dev_err(dev, "Error reading dev status: %d\n", ret);
ret);
goto out; goto out;
} }
if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL) if ((ret & CYAPA_DEV_NORMAL) == CYAPA_DEV_NORMAL) {
break; dev_dbg(dev, "Calibration successful.\n");
} while (--tries); goto out;
}
} while (time_is_after_jiffies(timeout));
if (tries == 0) { dev_err(dev, "Failed to calibrate. Timeout.\n");
dev_err(dev, "Failed to calibrate. Timeout.\n"); ret = -ETIMEDOUT;
ret = -ETIMEDOUT;
goto out;
}
dev_dbg(dev, "Calibration successful.\n");
out: out:
return ret < 0 ? ret : count; return ret < 0 ? ret : count;