iio: accell: mma8452: Reduce sleep time when data not ready

Modified the sleep method when data is not ready to allow for sampling > 50sps to work.

Signed-off-by: Richard Tresidder <rtresidd@electromag.com.au>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Richard Tresidder 2018-05-11 16:54:59 +08:00 committed by Jonathan Cameron
parent 2a86487786
commit a45d123887

View File

@ -106,6 +106,7 @@ struct mma8452_data {
u8 ctrl_reg1; u8 ctrl_reg1;
u8 data_cfg; u8 data_cfg;
const struct mma_chip_info *chip_info; const struct mma_chip_info *chip_info;
int sleep_val;
}; };
/** /**
@ -193,7 +194,11 @@ static int mma8452_drdy(struct mma8452_data *data)
if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
return 0; return 0;
msleep(20); if (data->sleep_val <= 20)
usleep_range(data->sleep_val * 250,
data->sleep_val * 500);
else
msleep(20);
} }
dev_err(&data->client->dev, "data not ready\n"); dev_err(&data->client->dev, "data not ready\n");
@ -544,6 +549,18 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
return -EINVAL; return -EINVAL;
} }
static int mma8452_calculate_sleep(struct mma8452_data *data)
{
int ret, i = mma8452_get_odr_index(data);
if (mma8452_samp_freq[i][0] > 0)
ret = 1000 / mma8452_samp_freq[i][0];
else
ret = 1000;
return ret == 0 ? 1 : ret;
}
static int mma8452_standby(struct mma8452_data *data) static int mma8452_standby(struct mma8452_data *data)
{ {
return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1, return i2c_smbus_write_byte_data(data->client, MMA8452_CTRL_REG1,
@ -700,6 +717,8 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
data->sleep_val = mma8452_calculate_sleep(data);
ret = mma8452_change_config(data, MMA8452_CTRL_REG1, ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
break; break;
@ -1593,6 +1612,9 @@ static int mma8452_probe(struct i2c_client *client,
data->ctrl_reg1 = MMA8452_CTRL_ACTIVE | data->ctrl_reg1 = MMA8452_CTRL_ACTIVE |
(MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT); (MMA8452_CTRL_DR_DEFAULT << MMA8452_CTRL_DR_SHIFT);
data->sleep_val = mma8452_calculate_sleep(data);
ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1, ret = i2c_smbus_write_byte_data(client, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
if (ret < 0) if (ret < 0)