From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
Jacek Anaszewski <j.anaszewski@samsung.com>
Subject: [PATCH 04/18] iio:gp2ap020a00f: Switch to new event config interface
Date: Thu, 26 Sep 2013 14:58:23 +0200 [thread overview]
Message-ID: <1380200317-19355-4-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1380200317-19355-1-git-send-email-lars@metafoo.de>
Switch the gp2ap020a00f 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>
Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
---
drivers/iio/light/gp2ap020a00f.c | 103 ++++++++++++++++++++++++++-------------
1 file changed, 70 insertions(+), 33 deletions(-)
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index b1e4615..43f47f7 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -996,11 +996,10 @@ done:
return IRQ_HANDLED;
}
-static u8 gp2ap020a00f_get_reg_by_event_code(u64 event_code)
+static u8 gp2ap020a00f_get_thresh_reg(const struct iio_chan_spec *chan,
+ enum iio_event_direction event_dir)
{
- int event_dir = IIO_EVENT_CODE_EXTRACT_DIR(event_code);
-
- switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+ switch (chan->type) {
case IIO_PROXIMITY:
if (event_dir == IIO_EV_DIR_RISING)
return GP2AP020A00F_PH_L_REG;
@@ -1011,13 +1010,19 @@ static u8 gp2ap020a00f_get_reg_by_event_code(u64 event_code)
return GP2AP020A00F_TH_L_REG;
else
return GP2AP020A00F_TL_L_REG;
+ default:
+ break;
}
return -EINVAL;
}
static int gp2ap020a00f_write_event_val(struct iio_dev *indio_dev,
- u64 event_code, int val)
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir,
+ enum iio_event_info info,
+ int val)
{
struct gp2ap020a00f_data *data = iio_priv(indio_dev);
bool event_en = false;
@@ -1027,7 +1032,7 @@ static int gp2ap020a00f_write_event_val(struct iio_dev *indio_dev,
mutex_lock(&data->lock);
- thresh_reg_l = gp2ap020a00f_get_reg_by_event_code(event_code);
+ thresh_reg_l = gp2ap020a00f_get_thresh_reg(chan, dir);
thresh_val_id = GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l);
if (thresh_val_id > GP2AP020A00F_THRESH_PH) {
@@ -1072,7 +1077,11 @@ error_unlock:
}
static int gp2ap020a00f_read_event_val(struct iio_dev *indio_dev,
- u64 event_code, int *val)
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir,
+ enum iio_event_info info,
+ int *val)
{
struct gp2ap020a00f_data *data = iio_priv(indio_dev);
u8 thresh_reg_l;
@@ -1080,7 +1089,7 @@ static int gp2ap020a00f_read_event_val(struct iio_dev *indio_dev,
mutex_lock(&data->lock);
- thresh_reg_l = gp2ap020a00f_get_reg_by_event_code(event_code);
+ thresh_reg_l = gp2ap020a00f_get_thresh_reg(chan, dir);
if (thresh_reg_l > GP2AP020A00F_PH_L_REG) {
err = -EINVAL;
@@ -1096,7 +1105,7 @@ error_unlock:
}
static int gp2ap020a00f_write_prox_event_config(struct iio_dev *indio_dev,
- u64 event_code, int state)
+ int state)
{
struct gp2ap020a00f_data *data = iio_priv(indio_dev);
enum gp2ap020a00f_cmd cmd_high_ev, cmd_low_ev;
@@ -1151,7 +1160,10 @@ static int gp2ap020a00f_write_prox_event_config(struct iio_dev *indio_dev,
}
static int gp2ap020a00f_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)
{
struct gp2ap020a00f_data *data = iio_priv(indio_dev);
enum gp2ap020a00f_cmd cmd;
@@ -1159,14 +1171,12 @@ static int gp2ap020a00f_write_event_config(struct iio_dev *indio_dev,
mutex_lock(&data->lock);
- switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+ switch (chan->type) {
case IIO_PROXIMITY:
- err = gp2ap020a00f_write_prox_event_config(indio_dev,
- event_code, state);
+ err = gp2ap020a00f_write_prox_event_config(indio_dev, state);
break;
case IIO_LIGHT:
- if (IIO_EVENT_CODE_EXTRACT_DIR(event_code)
- == IIO_EV_DIR_RISING) {
+ if (dir == IIO_EV_DIR_RISING) {
cmd = state ? GP2AP020A00F_CMD_ALS_HIGH_EV_EN :
GP2AP020A00F_CMD_ALS_HIGH_EV_DIS;
err = gp2ap020a00f_exec_cmd(data, cmd);
@@ -1186,17 +1196,18 @@ static int gp2ap020a00f_write_event_config(struct iio_dev *indio_dev,
}
static int gp2ap020a00f_read_event_config(struct iio_dev *indio_dev,
- u64 event_code)
+ const struct iio_chan_spec *chan,
+ enum iio_event_type type,
+ enum iio_event_direction dir)
{
struct gp2ap020a00f_data *data = iio_priv(indio_dev);
int event_en = 0;
mutex_lock(&data->lock);
- switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+ switch (chan->type) {
case IIO_PROXIMITY:
- if (IIO_EVENT_CODE_EXTRACT_DIR(event_code)
- == IIO_EV_DIR_RISING)
+ if (dir == IIO_EV_DIR_RISING)
event_en = test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV,
&data->flags);
else
@@ -1204,14 +1215,16 @@ static int gp2ap020a00f_read_event_config(struct iio_dev *indio_dev,
&data->flags);
break;
case IIO_LIGHT:
- if (IIO_EVENT_CODE_EXTRACT_DIR(event_code)
- == IIO_EV_DIR_RISING)
+ if (dir == IIO_EV_DIR_RISING)
event_en = test_bit(GP2AP020A00F_FLAG_ALS_RISING_EV,
&data->flags);
else
event_en = test_bit(GP2AP020A00F_FLAG_ALS_FALLING_EV,
&data->flags);
break;
+ default:
+ event_en = -EINVAL;
+ break;
}
mutex_unlock(&data->lock);
@@ -1292,6 +1305,34 @@ error_unlock:
return err < 0 ? err : IIO_VAL_INT;
}
+static const struct iio_event_spec gp2ap020a00f_event_spec_light[] = {
+ {
+ .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),
+ },
+};
+
+static const struct iio_event_spec gp2ap020a00f_event_spec_prox[] = {
+ {
+ .type = IIO_EV_TYPE_ROC,
+ .dir = IIO_EV_DIR_RISING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+ BIT(IIO_EV_INFO_ENABLE),
+ }, {
+ .type = IIO_EV_TYPE_ROC,
+ .dir = IIO_EV_DIR_FALLING,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+ BIT(IIO_EV_INFO_ENABLE),
+ },
+};
+
static const struct iio_chan_spec gp2ap020a00f_channels[] = {
{
.type = IIO_LIGHT,
@@ -1307,10 +1348,8 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
},
.scan_index = GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR,
.address = GP2AP020A00F_D0_L_REG,
- .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH,
- IIO_EV_DIR_RISING) |
- IIO_EV_BIT(IIO_EV_TYPE_THRESH,
- IIO_EV_DIR_FALLING),
+ .event_spec = gp2ap020a00f_event_spec_light,
+ .num_event_specs = ARRAY_SIZE(gp2ap020a00f_event_spec_light),
},
{
.type = IIO_LIGHT,
@@ -1340,20 +1379,18 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
},
.scan_index = GP2AP020A00F_SCAN_MODE_PROXIMITY,
.address = GP2AP020A00F_D2_L_REG,
- .event_mask = IIO_EV_BIT(IIO_EV_TYPE_ROC,
- IIO_EV_DIR_RISING) |
- IIO_EV_BIT(IIO_EV_TYPE_ROC,
- IIO_EV_DIR_FALLING),
+ .event_spec = gp2ap020a00f_event_spec_prox,
+ .num_event_specs = ARRAY_SIZE(gp2ap020a00f_event_spec_prox),
},
IIO_CHAN_SOFT_TIMESTAMP(GP2AP020A00F_CHAN_TIMESTAMP),
};
static const struct iio_info gp2ap020a00f_info = {
.read_raw = &gp2ap020a00f_read_raw,
- .read_event_value = &gp2ap020a00f_read_event_val,
- .read_event_config = &gp2ap020a00f_read_event_config,
- .write_event_value = &gp2ap020a00f_write_event_val,
- .write_event_config = &gp2ap020a00f_write_event_config,
+ .read_event_value_new = &gp2ap020a00f_read_event_val,
+ .read_event_config_new = &gp2ap020a00f_read_event_config,
+ .write_event_value_new = &gp2ap020a00f_write_event_val,
+ .write_event_config_new = &gp2ap020a00f_write_event_config,
.driver_module = THIS_MODULE,
};
--
1.8.0
next prev parent reply other threads:[~2013-09-26 12:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 02/18] iio:max1363: Switch to new " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 03/18] iio:ad5421: " Lars-Peter Clausen
2013-09-26 12:58 ` Lars-Peter Clausen [this message]
2013-09-26 12:58 ` [PATCH 05/18] iio:tsl2563: " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 06/18] iio:apds9300: Use " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 07/18] staging:iio:lis3l02dq: Switch to " Lars-Peter Clausen
2013-09-30 20:55 ` Jonathan Cameron
2013-10-01 7:51 ` Lars-Peter Clausen
2013-10-01 9:14 ` Jonathan Cameron
2013-09-26 12:58 ` [PATCH 08/18] staging:iio:sca3000: Switch to new " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 09/18] staging:iio:ad7291: Switch to new event " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 10/18] staging:iio:ad799x: " Lars-Peter Clausen
2013-09-30 20:59 ` Jonathan Cameron
2013-09-26 12:58 ` [PATCH 11/18] staging:iio:ad7150: " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 12/18] staging:iio:simple_dummy: " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 13/18] staging:iio:tsl2x7x: " Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 14/18] iio: Remove support for the legacy " Lars-Peter Clausen
2013-09-30 21:05 ` Jonathan Cameron
2013-10-01 7:52 ` Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 15/18] iio: Add a hysteresis event info attribute Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 16/18] staging:iio:ad799x: Simplify threshold register look-up Lars-Peter Clausen
2013-09-26 12:58 ` [PATCH 17/18] staging:iio:ad799x: Use event spec for threshold hysteresis Lars-Peter Clausen
2013-09-30 21:10 ` Jonathan Cameron
2013-09-26 12:58 ` [PATCH 18/18] staging:iio:ad7291: " Lars-Peter Clausen
2013-09-29 18:44 ` [PATCH 01/18] iio: Extend the event config interface Jonathan Cameron
2013-09-29 18:56 ` Lars-Peter Clausen
2013-09-29 20:17 ` Jonathan Cameron
2013-09-29 19:35 ` Lars-Peter Clausen
2013-09-30 20:54 ` Jonathan Cameron
2013-10-04 8:38 ` Lars-Peter Clausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380200317-19355-4-git-send-email-lars@metafoo.de \
--to=lars@metafoo.de \
--cc=j.anaszewski@samsung.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).