No need to wait before the first read, as the operation is likely
completed already. For timeout 50 milliseconds is an overkill, poll the
register for the duration of 5 milliseconds at maximum.
Also, clear the active flag in case of timeout.
Signed-off-by: Aaro Koskinen <Aaro.Koskinen@nokia.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
-static void twl4030_madc_wait_conversion_ready_ms(
+static int twl4030_madc_wait_conversion_ready(
struct twl4030_madc_data *madc,
struct twl4030_madc_data *madc,
- u8 *time, u8 status_reg)
+ unsigned int timeout_ms, u8 status_reg)
+ timeout = jiffies + msecs_to_jiffies(timeout_ms);
- msleep(1);
- (*time)--;
reg = twl4030_madc_read(madc, status_reg);
reg = twl4030_madc_read(madc, status_reg);
- } while (((reg & TWL4030_MADC_BUSY) && !(reg & TWL4030_MADC_EOC_SW)) &&
- (*time != 0));
+ if (!(reg & TWL4030_MADC_BUSY) && (reg & TWL4030_MADC_EOC_SW))
+ return 0;
+ } while (!time_after(jiffies, timeout));
+
+ return -EAGAIN;
}
int twl4030_madc_conversion(struct twl4030_madc_request *req)
{
const struct twl4030_madc_conversion_method *method;
}
int twl4030_madc_conversion(struct twl4030_madc_request *req)
{
const struct twl4030_madc_conversion_method *method;
- u8 wait_time, ch_msb, ch_lsb;
int ret;
if (unlikely(!req))
int ret;
if (unlikely(!req))
the_madc->requests[req->method].active = 1;
/* Wait until conversion is ready (ctrl register returns EOC) */
the_madc->requests[req->method].active = 1;
/* Wait until conversion is ready (ctrl register returns EOC) */
- wait_time = 50;
- twl4030_madc_wait_conversion_ready_ms(the_madc,
- &wait_time, method->ctrl);
- if (wait_time == 0) {
+ ret = twl4030_madc_wait_conversion_ready(the_madc, 5, method->ctrl);
+ if (ret) {
dev_dbg(the_madc->dev, "conversion timeout!\n");
dev_dbg(the_madc->dev, "conversion timeout!\n");
+ the_madc->requests[req->method].active = 0;