Commit a9c47abb authored by Peter Meerwald-Stadler's avatar Peter Meerwald-Stadler Committed by Jonathan Cameron

iio: health: max30102: Add power enable parameter to get_temp function

Chip must not be in shutdown for reading temperature, so briefly leave
shutdown if buffer is not already running
Signed-off-by: default avatarPeter Meerwald-Stadler <pmeerw@pmeerw.net>
Acked-by: default avatarMatt Ranostay <matt.ranostay@konsulko.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 839a74cd
...@@ -321,20 +321,31 @@ static int max30102_read_temp(struct max30102_data *data, int *val) ...@@ -321,20 +321,31 @@ static int max30102_read_temp(struct max30102_data *data, int *val)
return 0; return 0;
} }
static int max30102_get_temp(struct max30102_data *data, int *val) static int max30102_get_temp(struct max30102_data *data, int *val, bool en)
{ {
int ret; int ret;
if (en) {
ret = max30102_set_powermode(data, true);
if (ret)
return ret;
}
/* start acquisition */ /* start acquisition */
ret = regmap_update_bits(data->regmap, MAX30102_REG_TEMP_CONFIG, ret = regmap_update_bits(data->regmap, MAX30102_REG_TEMP_CONFIG,
MAX30102_REG_TEMP_CONFIG_TEMP_EN, MAX30102_REG_TEMP_CONFIG_TEMP_EN,
MAX30102_REG_TEMP_CONFIG_TEMP_EN); MAX30102_REG_TEMP_CONFIG_TEMP_EN);
if (ret) if (ret)
return ret; goto out;
msleep(35); msleep(35);
ret = max30102_read_temp(data, val);
out:
if (en)
max30102_set_powermode(data, false);
return max30102_read_temp(data, val); return ret;
} }
static int max30102_read_raw(struct iio_dev *indio_dev, static int max30102_read_raw(struct iio_dev *indio_dev,
...@@ -347,20 +358,19 @@ static int max30102_read_raw(struct iio_dev *indio_dev, ...@@ -347,20 +358,19 @@ static int max30102_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
/* /*
* Temperature reading can only be acquired while engine * Temperature reading can only be acquired when not in
* is running * shutdown; leave shutdown briefly when buffer not running
*/ */
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
if (!iio_buffer_enabled(indio_dev)) if (!iio_buffer_enabled(indio_dev))
ret = -EBUSY; ret = max30102_get_temp(data, val, true);
else { else
ret = max30102_get_temp(data, val); ret = max30102_get_temp(data, val, false);
if (!ret)
ret = IIO_VAL_INT;
}
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (ret)
return ret;
ret = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 1; /* 0.0625 */ *val = 1; /* 0.0625 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment