/**
* struct aht10_data - All the data required to operate an AHT10/AHT20 chip
* @client: the i2c client associated with the AHT10/AHT20
- * @lock: a mutex that is used to prevent parallel access to the
- * i2c client
* @min_poll_interval: the minimum poll interval
* While the poll rate limit is not 100% necessary,
* the datasheet recommends that a measurement
struct aht10_data {
struct i2c_client *client;
- /*
- * Prevent simultaneous access to the i2c
- * client and previous_poll_time
- */
- struct mutex lock;
ktime_t min_poll_interval;
ktime_t previous_poll_time;
int temperature;
u8 raw_data[AHT20_MEAS_SIZE];
struct i2c_client *client = data->client;
- mutex_lock(&data->lock);
- if (!aht10_polltime_expired(data)) {
- mutex_unlock(&data->lock);
+ if (!aht10_polltime_expired(data))
return 0;
- }
res = i2c_master_send(client, cmd_meas, sizeof(cmd_meas));
- if (res < 0) {
- mutex_unlock(&data->lock);
+ if (res < 0)
return res;
- }
usleep_range(AHT10_MEAS_DELAY, AHT10_MEAS_DELAY + AHT10_DELAY_EXTRA);
res = i2c_master_recv(client, raw_data, data->meas_size);
if (res != data->meas_size) {
- mutex_unlock(&data->lock);
if (res >= 0)
return -ENODATA;
return res;
}
- if (data->crc8 && crc8_check(raw_data, data->meas_size)) {
- mutex_unlock(&data->lock);
+ if (data->crc8 && crc8_check(raw_data, data->meas_size))
return -EIO;
- }
hum = ((u32)raw_data[1] << 12u) |
((u32)raw_data[2] << 4u) |
data->humidity = hum;
data->previous_poll_time = ktime_get_boottime();
- mutex_unlock(&data->lock);
return 0;
}
break;
}
- mutex_init(&data->lock);
-
res = aht10_init(data);
if (res < 0)
return res;