#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
+#include <linux/jiffies.h>
#include <linux/minmax.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#define AK09912_MAX_REGS AK09912_REG_ASAZ
-/*
- * Miscellaneous values.
- */
-#define AK8975_MAX_CONVERSION_TIMEOUT 500
-#define AK8975_CONVERSION_DONE_POLL_TIME 10
-#define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000)
-
/*
* Precalculate scale factor (in Gauss units) for each axis and
* store in the device data.
return 0;
}
-static int wait_conversion_complete_gpio(struct ak8975_data *data)
+static int wait_conversion_complete_gpio(struct ak8975_data *data,
+ unsigned int poll_ms,
+ unsigned int timeout_ms)
{
struct i2c_client *client = data->client;
- u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
int ret;
/* Wait for the conversion to complete. */
while (timeout_ms) {
- msleep(AK8975_CONVERSION_DONE_POLL_TIME);
+ msleep(poll_ms);
if (gpiod_get_value(data->eoc_gpiod))
break;
- timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
+ timeout_ms -= poll_ms;
}
if (!timeout_ms)
return -ETIMEDOUT;
return ret;
}
-static int wait_conversion_complete_polled(struct ak8975_data *data)
+static int wait_conversion_complete_polled(struct ak8975_data *data,
+ unsigned int poll_ms,
+ unsigned int timeout_ms)
{
struct i2c_client *client = data->client;
u8 read_status;
- u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
int ret;
/* Wait for the conversion to complete. */
while (timeout_ms) {
- msleep(AK8975_CONVERSION_DONE_POLL_TIME);
+ msleep(poll_ms);
ret = i2c_smbus_read_byte_data(client,
data->def->ctrl_regs[ST1]);
if (ret < 0) {
read_status = ret;
if (read_status)
break;
- timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
+ timeout_ms -= poll_ms;
}
if (!timeout_ms)
return -ETIMEDOUT;
}
/* Returns 0 if the end of conversion interrupt occurred or -ETIMEDOUT otherwise */
-static int wait_conversion_complete_interrupt(struct ak8975_data *data)
+static int wait_conversion_complete_interrupt(struct ak8975_data *data,
+ unsigned int timeout_ms)
{
int ret;
ret = wait_event_timeout(data->data_ready_queue,
test_bit(0, &data->flags),
- AK8975_DATA_READY_TIMEOUT);
+ msecs_to_jiffies(timeout_ms));
clear_bit(0, &data->flags);
return ret > 0 ? 0 : -ETIMEDOUT;
/* Wait for the conversion to complete. */
if (data->eoc_irq)
- ret = wait_conversion_complete_interrupt(data);
+ ret = wait_conversion_complete_interrupt(data, 100);
else if (data->eoc_gpiod)
- ret = wait_conversion_complete_gpio(data);
+ ret = wait_conversion_complete_gpio(data, 10, 500);
else
- ret = wait_conversion_complete_polled(data);
+ ret = wait_conversion_complete_polled(data, 10, 500);
if (ret < 0)
return ret;