forked from Minki/linux
staging:iio:ad7150: Switch to new event config interface
Switch the ad7150 driver to the new IIO event config interface as the old one is going to be removed. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
5b9e048a80
commit
1489d629a4
@ -123,14 +123,14 @@ static int ad7150_read_raw(struct iio_dev *indio_dev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ad7150_read_event_config(struct iio_dev *indio_dev, u64 event_code)
|
static int ad7150_read_event_config(struct iio_dev *indio_dev,
|
||||||
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
||||||
|
enum iio_event_direction dir)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
u8 threshtype;
|
u8 threshtype;
|
||||||
bool adaptive;
|
bool adaptive;
|
||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
|
||||||
IIO_EV_DIR_RISING);
|
|
||||||
|
|
||||||
ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG);
|
ret = i2c_smbus_read_byte_data(chip->client, AD7150_CFG);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -139,42 +139,47 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, u64 event_code)
|
|||||||
threshtype = (ret >> 5) & 0x03;
|
threshtype = (ret >> 5) & 0x03;
|
||||||
adaptive = !!(ret & 0x80);
|
adaptive = !!(ret & 0x80);
|
||||||
|
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
|
switch (type) {
|
||||||
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
||||||
if (rising)
|
if (dir == IIO_EV_DIR_RISING)
|
||||||
return adaptive && (threshtype == 0x1);
|
return adaptive && (threshtype == 0x1);
|
||||||
else
|
else
|
||||||
return adaptive && (threshtype == 0x0);
|
return adaptive && (threshtype == 0x0);
|
||||||
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
||||||
if (rising)
|
if (dir == IIO_EV_DIR_RISING)
|
||||||
return adaptive && (threshtype == 0x3);
|
return adaptive && (threshtype == 0x3);
|
||||||
else
|
else
|
||||||
return adaptive && (threshtype == 0x2);
|
return adaptive && (threshtype == 0x2);
|
||||||
|
|
||||||
case IIO_EV_TYPE_THRESH:
|
case IIO_EV_TYPE_THRESH:
|
||||||
if (rising)
|
if (dir == IIO_EV_DIR_RISING)
|
||||||
return !adaptive && (threshtype == 0x1);
|
return !adaptive && (threshtype == 0x1);
|
||||||
else
|
else
|
||||||
return !adaptive && (threshtype == 0x0);
|
return !adaptive && (threshtype == 0x0);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lock should be held */
|
/* lock should be held */
|
||||||
static int ad7150_write_event_params(struct iio_dev *indio_dev, u64 event_code)
|
static int ad7150_write_event_params(struct iio_dev *indio_dev,
|
||||||
|
unsigned int chan, enum iio_event_type type,
|
||||||
|
enum iio_event_direction dir)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
u16 value;
|
u16 value;
|
||||||
u8 sens, timeout;
|
u8 sens, timeout;
|
||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
|
int rising = (dir == IIO_EV_DIR_RISING);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
u64 event_code;
|
||||||
IIO_EV_DIR_RISING);
|
|
||||||
|
event_code = IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, chan, type, dir);
|
||||||
|
|
||||||
if (event_code != chip->current_event)
|
if (event_code != chip->current_event)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
|
switch (type) {
|
||||||
/* Note completely different from the adaptive versions */
|
/* Note completely different from the adaptive versions */
|
||||||
case IIO_EV_TYPE_THRESH:
|
case IIO_EV_TYPE_THRESH:
|
||||||
value = chip->threshold[rising][chan];
|
value = chip->threshold[rising][chan];
|
||||||
@ -211,18 +216,20 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, u64 event_code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int ad7150_write_event_config(struct iio_dev *indio_dev,
|
static int ad7150_write_event_config(struct iio_dev *indio_dev,
|
||||||
u64 event_code, int state)
|
const struct iio_chan_spec *chan, enum iio_event_type type,
|
||||||
|
enum iio_event_direction dir, int state)
|
||||||
{
|
{
|
||||||
u8 thresh_type, cfg, adaptive;
|
u8 thresh_type, cfg, adaptive;
|
||||||
int ret;
|
int ret;
|
||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
int rising = (dir == IIO_EV_DIR_RISING);
|
||||||
IIO_EV_DIR_RISING);
|
u64 event_code;
|
||||||
|
|
||||||
/* Something must always be turned on */
|
/* Something must always be turned on */
|
||||||
if (state == 0)
|
if (state == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir);
|
||||||
if (event_code == chip->current_event)
|
if (event_code == chip->current_event)
|
||||||
return 0;
|
return 0;
|
||||||
mutex_lock(&chip->state_lock);
|
mutex_lock(&chip->state_lock);
|
||||||
@ -232,7 +239,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
|
|||||||
|
|
||||||
cfg = ret & ~((0x03 << 5) | (0x1 << 7));
|
cfg = ret & ~((0x03 << 5) | (0x1 << 7));
|
||||||
|
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
|
switch (type) {
|
||||||
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
||||||
adaptive = 1;
|
adaptive = 1;
|
||||||
if (rising)
|
if (rising)
|
||||||
@ -268,7 +275,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
|
|||||||
chip->current_event = event_code;
|
chip->current_event = event_code;
|
||||||
|
|
||||||
/* update control attributes */
|
/* update control attributes */
|
||||||
ret = ad7150_write_event_params(indio_dev, event_code);
|
ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir);
|
||||||
error_ret:
|
error_ret:
|
||||||
mutex_unlock(&chip->state_lock);
|
mutex_unlock(&chip->state_lock);
|
||||||
|
|
||||||
@ -276,53 +283,52 @@ error_ret:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int ad7150_read_event_value(struct iio_dev *indio_dev,
|
static int ad7150_read_event_value(struct iio_dev *indio_dev,
|
||||||
u64 event_code,
|
const struct iio_chan_spec *chan,
|
||||||
int *val)
|
enum iio_event_type type,
|
||||||
|
enum iio_event_direction dir,
|
||||||
|
enum iio_event_info info,
|
||||||
|
int *val, int *val2)
|
||||||
{
|
{
|
||||||
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
|
|
||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
int rising = (dir == IIO_EV_DIR_RISING);
|
||||||
IIO_EV_DIR_RISING);
|
|
||||||
|
|
||||||
/* Complex register sharing going on here */
|
/* Complex register sharing going on here */
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
|
switch (type) {
|
||||||
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
||||||
*val = chip->mag_sensitivity[rising][chan];
|
*val = chip->mag_sensitivity[rising][chan->channel];
|
||||||
return 0;
|
return IIO_VAL_INT;
|
||||||
|
|
||||||
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
||||||
*val = chip->thresh_sensitivity[rising][chan];
|
*val = chip->thresh_sensitivity[rising][chan->channel];
|
||||||
return 0;
|
return IIO_VAL_INT;
|
||||||
|
|
||||||
case IIO_EV_TYPE_THRESH:
|
case IIO_EV_TYPE_THRESH:
|
||||||
*val = chip->threshold[rising][chan];
|
*val = chip->threshold[rising][chan->channel];
|
||||||
return 0;
|
return IIO_VAL_INT;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ad7150_write_event_value(struct iio_dev *indio_dev,
|
static int ad7150_write_event_value(struct iio_dev *indio_dev,
|
||||||
u64 event_code,
|
const struct iio_chan_spec *chan,
|
||||||
int val)
|
enum iio_event_type type,
|
||||||
|
enum iio_event_direction dir,
|
||||||
|
enum iio_event_info info,
|
||||||
|
int val, int val2)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
|
int rising = (dir == IIO_EV_DIR_RISING);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
|
|
||||||
IIO_EV_DIR_RISING);
|
|
||||||
|
|
||||||
mutex_lock(&chip->state_lock);
|
mutex_lock(&chip->state_lock);
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
|
switch (type) {
|
||||||
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
||||||
chip->mag_sensitivity[rising][chan] = val;
|
chip->mag_sensitivity[rising][chan->channel] = val;
|
||||||
break;
|
break;
|
||||||
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
case IIO_EV_TYPE_THRESH_ADAPTIVE:
|
||||||
chip->thresh_sensitivity[rising][chan] = val;
|
chip->thresh_sensitivity[rising][chan->channel] = val;
|
||||||
break;
|
break;
|
||||||
case IIO_EV_TYPE_THRESH:
|
case IIO_EV_TYPE_THRESH:
|
||||||
chip->threshold[rising][chan] = val;
|
chip->threshold[rising][chan->channel] = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
@ -330,7 +336,7 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* write back if active */
|
/* write back if active */
|
||||||
ret = ad7150_write_event_params(indio_dev, event_code);
|
ret = ad7150_write_event_params(indio_dev, chan->channel, type, dir);
|
||||||
|
|
||||||
error_ret:
|
error_ret:
|
||||||
mutex_unlock(&chip->state_lock);
|
mutex_unlock(&chip->state_lock);
|
||||||
@ -374,17 +380,22 @@ static ssize_t ad7150_store_timeout(struct device *dev,
|
|||||||
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
struct ad7150_chip_info *chip = iio_priv(indio_dev);
|
||||||
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
||||||
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
|
int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
|
||||||
int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) ==
|
enum iio_event_direction dir;
|
||||||
IIO_EV_DIR_RISING);
|
enum iio_event_type type;
|
||||||
|
int rising;
|
||||||
u8 data;
|
u8 data;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
type = IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address);
|
||||||
|
dir = IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address);
|
||||||
|
rising = (dir == IIO_EV_DIR_RISING);
|
||||||
|
|
||||||
ret = kstrtou8(buf, 10, &data);
|
ret = kstrtou8(buf, 10, &data);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
mutex_lock(&chip->state_lock);
|
mutex_lock(&chip->state_lock);
|
||||||
switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) {
|
switch (type) {
|
||||||
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
case IIO_EV_TYPE_MAG_ADAPTIVE:
|
||||||
chip->mag_timeout[rising][chan] = data;
|
chip->mag_timeout[rising][chan] = data;
|
||||||
break;
|
break;
|
||||||
@ -396,7 +407,7 @@ static ssize_t ad7150_store_timeout(struct device *dev,
|
|||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ad7150_write_event_params(indio_dev, this_attr->address);
|
ret = ad7150_write_event_params(indio_dev, chan, type, dir);
|
||||||
error_ret:
|
error_ret:
|
||||||
mutex_unlock(&chip->state_lock);
|
mutex_unlock(&chip->state_lock);
|
||||||
|
|
||||||
@ -424,6 +435,40 @@ static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING);
|
|||||||
static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING);
|
static AD7150_TIMEOUT(1, thresh_adaptive, rising, THRESH_ADAPTIVE, RISING);
|
||||||
static AD7150_TIMEOUT(1, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING);
|
static AD7150_TIMEOUT(1, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING);
|
||||||
|
|
||||||
|
static const struct iio_event_spec ad7150_events[] = {
|
||||||
|
{
|
||||||
|
.type = IIO_EV_TYPE_THRESH,
|
||||||
|
.dir = IIO_EV_DIR_RISING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
}, {
|
||||||
|
.type = IIO_EV_TYPE_THRESH,
|
||||||
|
.dir = IIO_EV_DIR_FALLING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
}, {
|
||||||
|
.type = IIO_EV_TYPE_THRESH_ADAPTIVE,
|
||||||
|
.dir = IIO_EV_DIR_RISING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
}, {
|
||||||
|
.type = IIO_EV_TYPE_THRESH_ADAPTIVE,
|
||||||
|
.dir = IIO_EV_DIR_FALLING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
}, {
|
||||||
|
.type = IIO_EV_TYPE_MAG_ADAPTIVE,
|
||||||
|
.dir = IIO_EV_DIR_RISING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
}, {
|
||||||
|
.type = IIO_EV_TYPE_MAG_ADAPTIVE,
|
||||||
|
.dir = IIO_EV_DIR_FALLING,
|
||||||
|
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
|
||||||
|
BIT(IIO_EV_INFO_ENABLE),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
static const struct iio_chan_spec ad7150_channels[] = {
|
static const struct iio_chan_spec ad7150_channels[] = {
|
||||||
{
|
{
|
||||||
.type = IIO_CAPACITANCE,
|
.type = IIO_CAPACITANCE,
|
||||||
@ -431,26 +476,16 @@ static const struct iio_chan_spec ad7150_channels[] = {
|
|||||||
.channel = 0,
|
.channel = 0,
|
||||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
|
||||||
BIT(IIO_CHAN_INFO_AVERAGE_RAW),
|
BIT(IIO_CHAN_INFO_AVERAGE_RAW),
|
||||||
.event_mask =
|
.event_spec = ad7150_events,
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
|
.num_event_specs = ARRAY_SIZE(ad7150_events),
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_RISING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_FALLING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_RISING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_FALLING)
|
|
||||||
}, {
|
}, {
|
||||||
.type = IIO_CAPACITANCE,
|
.type = IIO_CAPACITANCE,
|
||||||
.indexed = 1,
|
.indexed = 1,
|
||||||
.channel = 1,
|
.channel = 1,
|
||||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
|
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
|
||||||
BIT(IIO_CHAN_INFO_AVERAGE_RAW),
|
BIT(IIO_CHAN_INFO_AVERAGE_RAW),
|
||||||
.event_mask =
|
.event_spec = ad7150_events,
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
|
.num_event_specs = ARRAY_SIZE(ad7150_events),
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_RISING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_THRESH_ADAPTIVE, IIO_EV_DIR_FALLING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_RISING) |
|
|
||||||
IIO_EV_BIT(IIO_EV_TYPE_MAG_ADAPTIVE, IIO_EV_DIR_FALLING)
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -541,10 +576,10 @@ static const struct iio_info ad7150_info = {
|
|||||||
.event_attrs = &ad7150_event_attribute_group,
|
.event_attrs = &ad7150_event_attribute_group,
|
||||||
.driver_module = THIS_MODULE,
|
.driver_module = THIS_MODULE,
|
||||||
.read_raw = &ad7150_read_raw,
|
.read_raw = &ad7150_read_raw,
|
||||||
.read_event_config = &ad7150_read_event_config,
|
.read_event_config_new = &ad7150_read_event_config,
|
||||||
.write_event_config = &ad7150_write_event_config,
|
.write_event_config_new = &ad7150_write_event_config,
|
||||||
.read_event_value = &ad7150_read_event_value,
|
.read_event_value_new = &ad7150_read_event_value,
|
||||||
.write_event_value = &ad7150_write_event_value,
|
.write_event_value_new = &ad7150_write_event_value,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user