Commit caeac374 authored by Peter Meerwald's avatar Peter Meerwald Committed by Jonathan Cameron

iio: adjd_s311: Use INT_TIME channel info

Signed-off-by: default avatarPeter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 899d90bd
...@@ -114,43 +114,6 @@ static int adjd_s311_read_data(struct iio_dev *indio_dev, u8 reg, int *val) ...@@ -114,43 +114,6 @@ static int adjd_s311_read_data(struct iio_dev *indio_dev, u8 reg, int *val)
return 0; return 0;
} }
static ssize_t adjd_s311_read_int_time(struct iio_dev *indio_dev,
uintptr_t private, const struct iio_chan_spec *chan, char *buf)
{
struct adjd_s311_data *data = iio_priv(indio_dev);
s32 ret;
ret = i2c_smbus_read_word_data(data->client,
ADJD_S311_INT_REG(chan->address));
if (ret < 0)
return ret;
return sprintf(buf, "%d\n", ret & ADJD_S311_INT_MASK);
}
static ssize_t adjd_s311_write_int_time(struct iio_dev *indio_dev,
uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
size_t len)
{
struct adjd_s311_data *data = iio_priv(indio_dev);
unsigned long int_time;
int ret;
ret = kstrtoul(buf, 10, &int_time);
if (ret)
return ret;
if (int_time > ADJD_S311_INT_MASK)
return -EINVAL;
ret = i2c_smbus_write_word_data(data->client,
ADJD_S311_INT_REG(chan->address), int_time);
if (ret < 0)
return ret;
return len;
}
static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
{ {
struct iio_poll_func *pf = p; struct iio_poll_func *pf = p;
...@@ -186,25 +149,16 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) ...@@ -186,25 +149,16 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static const struct iio_chan_spec_ext_info adjd_s311_ext_info[] = {
{
.name = "integration_time",
.read = adjd_s311_read_int_time,
.write = adjd_s311_write_int_time,
},
{ }
};
#define ADJD_S311_CHANNEL(_color, _scan_idx) { \ #define ADJD_S311_CHANNEL(_color, _scan_idx) { \
.type = IIO_INTENSITY, \ .type = IIO_INTENSITY, \
.modified = 1, \ .modified = 1, \
.address = (IDX_##_color), \ .address = (IDX_##_color), \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_HARDWAREGAIN), \ BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
BIT(IIO_CHAN_INFO_INT_TIME), \
.channel2 = (IIO_MOD_LIGHT_##_color), \ .channel2 = (IIO_MOD_LIGHT_##_color), \
.scan_index = (_scan_idx), \ .scan_index = (_scan_idx), \
.scan_type = IIO_ST('u', 10, 16, 0), \ .scan_type = IIO_ST('u', 10, 16, 0), \
.ext_info = adjd_s311_ext_info, \
} }
static const struct iio_chan_spec adjd_s311_channels[] = { static const struct iio_chan_spec adjd_s311_channels[] = {
...@@ -235,6 +189,18 @@ static int adjd_s311_read_raw(struct iio_dev *indio_dev, ...@@ -235,6 +189,18 @@ static int adjd_s311_read_raw(struct iio_dev *indio_dev,
return ret; return ret;
*val = ret & ADJD_S311_CAP_MASK; *val = ret & ADJD_S311_CAP_MASK;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_INT_TIME:
ret = i2c_smbus_read_word_data(data->client,
ADJD_S311_INT_REG(chan->address));
if (ret < 0)
return ret;
*val = 0;
/*
* not documented, based on measurement:
* 4095 LSBs correspond to roughly 4 ms
*/
*val2 = ret & ADJD_S311_INT_MASK;
return IIO_VAL_INT_PLUS_MICRO;
} }
return -EINVAL; return -EINVAL;
} }
...@@ -244,16 +210,20 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev, ...@@ -244,16 +210,20 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev,
int val, int val2, long mask) int val, int val2, long mask)
{ {
struct adjd_s311_data *data = iio_priv(indio_dev); struct adjd_s311_data *data = iio_priv(indio_dev);
int ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_HARDWAREGAIN: case IIO_CHAN_INFO_HARDWAREGAIN:
if (val < 0 || val > ADJD_S311_CAP_MASK) if (val < 0 || val > ADJD_S311_CAP_MASK)
return -EINVAL; return -EINVAL;
ret = i2c_smbus_write_byte_data(data->client, return i2c_smbus_write_byte_data(data->client,
ADJD_S311_CAP_REG(chan->address), val); ADJD_S311_CAP_REG(chan->address), val);
return ret; case IIO_CHAN_INFO_INT_TIME:
if (val != 0 || val2 < 0 || val2 > ADJD_S311_INT_MASK)
return -EINVAL;
return i2c_smbus_write_word_data(data->client,
ADJD_S311_INT_REG(chan->address), val2);
} }
return -EINVAL; return -EINVAL;
} }
......
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