All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/18] iio: Extend the event config interface
@ 2013-09-26 12:58 Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 02/18] iio:max1363: Switch to new " Lars-Peter Clausen
                   ` (17 more replies)
  0 siblings, 18 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

The event configuration interface of the IIO framework has not been getting the
same attention as other parts. As a result it has not seen the same improvements
as e.g. the channel interface has seen with the introduction of the channel spec
struct. Currently all the event config callbacks take a u64 (the so called event
code) to pass all the different information about for which event the callback
is invoked. The callback function then has to extract the information it is
interested in using some macros with rather long names. Most information encoded
in the event code comes straight from the iio_chan_spec struct the event was
registered for. Since we always have a handle to the channel spec when we call
the event callbacks the first step is to add the channel spec as a parameter to
the event callbacks. The two remaining things encoded in the event code are the
type and direction of the event. Instead of passing them in one parameter, add
one parameter for each of them and remove the eventcode from the event
callbacks. The patch also adds a new iio_event_info parameter to the
{read,write}_event_value callbacks. This makes it possible, similar to the
iio_chan_info_enum for channels, to specify additional properties other than
just the value for an event. Furthermore the new interface will allow to
register shared events. This is e.g. useful if a device allows configuring a
threshold event, but the threshold setting is the same for all channels.

To implement this the patch adds a new iio_event_spec struct which is similar to
the iio_chan_spec struct. It as two field to specify the type and the direction
of the event. Furthermore it has a mask field for each one of the different
iio_shared_by types. These mask fields holds which kind of attributes should be
registered for the event. Creation of the attributes follows the same rules as
the for the channel attributes. E.g. for the separate_mask there will be a
attribute for each channel with this event, for the shared_by_type there will
only be one attribute per channel type. The iio_chan_spec struct gets two new
fields, 'event_spec' and 'num_event_specs', which is used to specify which the
events for this channel. These two fields are going to replace the channel's
event_mask field.

For now both the old and the new event config interface coexist, but over the
few patches all drivers will be converted from the old to the new interface.
Once that is done all code for supporting the old interface will be removed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/industrialio-event.c | 169 ++++++++++++++++++++++++++++++++++++---
 include/linux/iio/events.h       |  14 ----
 include/linux/iio/iio.h          |  58 ++++++++++++++
 include/linux/iio/types.h        |  19 +++++
 4 files changed, 234 insertions(+), 26 deletions(-)

diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 2390e3d..d426781 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -182,6 +182,26 @@ static const char * const iio_ev_dir_text[] = {
 	[IIO_EV_DIR_FALLING] = "falling"
 };
 
+static const char * const iio_ev_info_text[] = {
+	[IIO_EV_INFO_ENABLE] = "en",
+	[IIO_EV_INFO_VALUE] = "value",
+};
+
+static enum iio_event_direction iio_ev_attr_dir(struct iio_dev_attr *attr)
+{
+	return attr->c->event_spec[attr->address & 0xffff].dir;
+}
+
+static enum iio_event_type iio_ev_attr_type(struct iio_dev_attr *attr)
+{
+	return attr->c->event_spec[attr->address & 0xffff].type;
+}
+
+static enum iio_event_info iio_ev_attr_info(struct iio_dev_attr *attr)
+{
+	return (attr->address >> 16) & 0xffff;
+}
+
 static ssize_t iio_ev_state_store(struct device *dev,
 				  struct device_attribute *attr,
 				  const char *buf,
@@ -196,9 +216,14 @@ static ssize_t iio_ev_state_store(struct device *dev,
 	if (ret < 0)
 		return ret;
 
-	ret = indio_dev->info->write_event_config(indio_dev,
-						  this_attr->address,
-						  val);
+	if (indio_dev->info->write_event_config)
+		ret = indio_dev->info->write_event_config(indio_dev,
+			this_attr->address, val);
+	else
+		ret = indio_dev->info->write_event_config_new(indio_dev,
+			this_attr->c, iio_ev_attr_type(this_attr),
+			iio_ev_attr_dir(this_attr), val);
+
 	return (ret < 0) ? ret : len;
 }
 
@@ -208,9 +233,15 @@ static ssize_t iio_ev_state_show(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int val = indio_dev->info->read_event_config(indio_dev,
-						     this_attr->address);
+	int val;
 
+	if (indio_dev->info->read_event_config)
+		val = indio_dev->info->read_event_config(indio_dev,
+			this_attr->address);
+	else
+		val = indio_dev->info->read_event_config_new(indio_dev,
+			this_attr->c, iio_ev_attr_type(this_attr),
+			iio_ev_attr_dir(this_attr));
 	if (val < 0)
 		return val;
 	else
@@ -225,8 +256,14 @@ static ssize_t iio_ev_value_show(struct device *dev,
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 	int val, ret;
 
-	ret = indio_dev->info->read_event_value(indio_dev,
-						this_attr->address, &val);
+	if (indio_dev->info->read_event_value)
+		ret = indio_dev->info->read_event_value(indio_dev,
+			this_attr->address, &val);
+	else
+		ret = indio_dev->info->read_event_value_new(indio_dev,
+			this_attr->c, iio_ev_attr_type(this_attr),
+			iio_ev_attr_dir(this_attr),
+			iio_ev_attr_info(this_attr), &val);
 	if (ret < 0)
 		return ret;
 
@@ -243,22 +280,118 @@ static ssize_t iio_ev_value_store(struct device *dev,
 	int val;
 	int ret;
 
-	if (!indio_dev->info->write_event_value)
+	if (!indio_dev->info->write_event_value &&
+		!indio_dev->info->write_event_value_new)
 		return -EINVAL;
 
 	ret = kstrtoint(buf, 10, &val);
 	if (ret)
 		return ret;
 
-	ret = indio_dev->info->write_event_value(indio_dev, this_attr->address,
-						 val);
+	if (indio_dev->info->write_event_value)
+		ret = indio_dev->info->write_event_value(indio_dev,
+			this_attr->address, val);
+	else
+		ret = indio_dev->info->write_event_value_new(indio_dev,
+			this_attr->c, iio_ev_attr_type(this_attr),
+			iio_ev_attr_dir(this_attr),
+			iio_ev_attr_info(this_attr), val);
 	if (ret < 0)
 		return ret;
 
 	return len;
 }
 
-static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
+static int iio_device_add_event(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int spec_offset,
+	enum iio_event_type type, enum iio_event_direction dir,
+	enum iio_shared_by shared_by, const unsigned long *mask)
+{
+	ssize_t (*show)(struct device *, struct device_attribute *, char *);
+	ssize_t (*store)(struct device *, struct device_attribute *,
+		const char *, size_t);
+	unsigned int attrcount = 0;
+	unsigned int i;
+	char *postfix;
+	int ret;
+
+	for_each_set_bit(i, mask, sizeof(*mask)) {
+		postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
+				    iio_ev_type_text[type],
+				    iio_ev_dir_text[dir],
+					iio_ev_info_text[i]);
+		if (postfix == NULL)
+			return -ENOMEM;
+
+		if (i == IIO_EV_INFO_ENABLE) {
+			show = iio_ev_state_show;
+			store = iio_ev_state_store;
+		} else {
+			show = iio_ev_value_show;
+			store = iio_ev_value_store;
+		}
+
+		ret = __iio_add_chan_devattr(postfix, chan,
+					     show,
+					     store,
+					     (i << 16) | spec_offset,
+					     shared_by,
+					     &indio_dev->dev,
+					     &indio_dev->event_interface->
+					     dev_attr_list);
+		kfree(postfix);
+		if (ret)
+			return ret;
+		attrcount++;
+	}
+
+	return attrcount;
+}
+
+static int iio_device_add_event_sysfs_new(struct iio_dev *indio_dev,
+				      struct iio_chan_spec const *chan)
+{
+	int ret = 0, i, attrcount = 0;
+	enum iio_event_direction dir;
+	enum iio_event_type type;
+
+	for (i = 0; i < chan->num_event_specs; i++) {
+		type = chan->event_spec[i].type;
+		dir = chan->event_spec[i].dir;
+
+		ret = iio_device_add_event(indio_dev, chan, i, type, dir,
+			IIO_SEPARATE, &chan->event_spec[i].mask_separate);
+		if (ret < 0)
+			goto error_ret;
+		attrcount += ret;
+
+		ret = iio_device_add_event(indio_dev, chan, i, type, dir,
+			IIO_SHARED_BY_TYPE,
+			&chan->event_spec[i].mask_shared_by_type);
+		if (ret < 0)
+			goto error_ret;
+		attrcount += ret;
+
+		ret = iio_device_add_event(indio_dev, chan, i, type, dir,
+			IIO_SHARED_BY_DIR,
+			&chan->event_spec[i].mask_shared_by_dir);
+		if (ret < 0)
+			goto error_ret;
+		attrcount += ret;
+
+		ret = iio_device_add_event(indio_dev, chan, i, type, dir,
+			IIO_SHARED_BY_ALL,
+			&chan->event_spec[i].mask_shared_by_all);
+		if (ret < 0)
+			goto error_ret;
+		attrcount += ret;
+	}
+	ret = attrcount;
+error_ret:
+	return ret;
+}
+
+static int iio_device_add_event_sysfs_old(struct iio_dev *indio_dev,
 				      struct iio_chan_spec const *chan)
 {
 	int ret = 0, i, attrcount = 0;
@@ -331,6 +464,15 @@ error_ret:
 	return ret;
 }
 
+static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
+				      struct iio_chan_spec const *chan)
+{
+	if (chan->event_mask)
+		return iio_device_add_event_sysfs_old(indio_dev, chan);
+	else
+		return iio_device_add_event_sysfs_new(indio_dev, chan);
+}
+
 static inline void __iio_remove_event_config_attrs(struct iio_dev *indio_dev)
 {
 	struct iio_dev_attr *p, *n;
@@ -361,9 +503,12 @@ static bool iio_check_for_dynamic_events(struct iio_dev *indio_dev)
 {
 	int j;
 
-	for (j = 0; j < indio_dev->num_channels; j++)
+	for (j = 0; j < indio_dev->num_channels; j++) {
 		if (indio_dev->channels[j].event_mask != 0)
 			return true;
+		if (indio_dev->channels[j].num_event_specs != 0)
+			return true;
+	}
 	return false;
 }
 
diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
index 13ce220..5dab2c4 100644
--- a/include/linux/iio/events.h
+++ b/include/linux/iio/events.h
@@ -26,20 +26,6 @@ struct iio_event_data {
 
 #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
 
-enum iio_event_type {
-	IIO_EV_TYPE_THRESH,
-	IIO_EV_TYPE_MAG,
-	IIO_EV_TYPE_ROC,
-	IIO_EV_TYPE_THRESH_ADAPTIVE,
-	IIO_EV_TYPE_MAG_ADAPTIVE,
-};
-
-enum iio_event_direction {
-	IIO_EV_DIR_EITHER,
-	IIO_EV_DIR_RISING,
-	IIO_EV_DIR_FALLING,
-};
-
 /**
  * IIO_EVENT_CODE() - create event identifier
  * @chan_type:	Type of the channel. Should be one of enum iio_chan_type.
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index ac1cb8f..5a9fefe 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -139,6 +139,29 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
 }
 
 /**
+ * struct iio_event_spec - specification for a channel event
+ * @type:		    Type of the event
+ * @dir:		    Direction of the event
+ * @mask_separate:	    Bit mask of enum iio_event_info values. Attributes
+ *			    set in this mask will be registered per channel.
+ * @mask_shared_by_type:    Bit mask of enum iio_event_info values. Attributes
+ *			    set in this mask will be shared by channel type.
+ * @mask_shared_by_dir:	    Bit mask of enum iio_event_info values. Attributes
+ *			    set in this mask will be shared by channel type and
+ *			    direction.
+ * @mask_shared_by_all:	    Bit mask of enum iio_event_info values. Attributes
+ *			    set in this mask will be shared by all channels.
+ */
+struct iio_event_spec {
+	enum iio_event_type type;
+	enum iio_event_direction dir;
+	unsigned long mask_separate;
+	unsigned long mask_shared_by_type;
+	unsigned long mask_shared_by_dir;
+	unsigned long mask_shared_by_all;
+};
+
+/**
  * struct iio_chan_spec - specification of a single channel
  * @type:		What type of measurement is the channel making.
  * @channel:		What number do we wish to assign the channel.
@@ -163,6 +186,9 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
  * @info_mask_shared_by_all: What information is to be exported that is shared
  *			by all channels.
  * @event_mask:		What events can this channel produce.
+ * @event_spec:		Array of events which should be registered for this
+ *			channel.
+ * @num_event_specs:	Size of the event_spec array.
  * @ext_info:		Array of extended info attributes for this channel.
  *			The array is NULL terminated, the last element should
  *			have its name field set to NULL.
@@ -201,6 +227,8 @@ struct iio_chan_spec {
 	long			info_mask_shared_by_dir;
 	long			info_mask_shared_by_all;
 	long			event_mask;
+	const struct iio_event_spec *event_spec;
+	unsigned int		num_event_specs;
 	const struct iio_chan_spec_ext_info *ext_info;
 	const char		*extend_name;
 	const char		*datasheet_name;
@@ -283,6 +311,12 @@ struct iio_dev;
  *			is event dependant. event_code specifies which event.
  * @write_event_value:	write the value associated with the event.
  *			Meaning is event dependent.
+ * @read_event_config_new: find out if the event is enabled. New style interface.
+ * @write_event_config_new: set if the event is enabled. New style interface.
+ * @read_event_value_new: read a configuration value associated with the event.
+ *                         New style interface.
+ * @write_event_value_new: write a configuration value for the event. New style
+ *			   interface.
  * @validate_trigger:	function to validate the trigger when the
  *			current trigger gets changed.
  * @update_scan_mode:	function to configure device and scan buffer when
@@ -323,6 +357,30 @@ struct iio_info {
 	int (*write_event_value)(struct iio_dev *indio_dev,
 				 u64 event_code,
 				 int val);
+
+	int (*read_event_config_new)(struct iio_dev *indio_dev,
+				 const struct iio_chan_spec *chan,
+				 enum iio_event_type type,
+				 enum iio_event_direction dir);
+
+	int (*write_event_config_new)(struct iio_dev *indio_dev,
+				  const struct iio_chan_spec *chan,
+				  enum iio_event_type type,
+				  enum iio_event_direction dir,
+				  int state);
+
+	int (*read_event_value_new)(struct iio_dev *indio_dev,
+				const struct iio_chan_spec *chan,
+				enum iio_event_type type,
+				enum iio_event_direction dir,
+				enum iio_event_info info, int *val);
+
+	int (*write_event_value_new)(struct iio_dev *indio_dev,
+				 const struct iio_chan_spec *chan,
+				 enum iio_event_type type,
+				 enum iio_event_direction dir,
+				 enum iio_event_info info, int val);
+
 	int (*validate_trigger)(struct iio_dev *indio_dev,
 				struct iio_trigger *trig);
 	int (*update_scan_mode)(struct iio_dev *indio_dev,
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 88bf0f0..18339ef 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -54,6 +54,25 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_BLUE,
 };
 
+enum iio_event_type {
+	IIO_EV_TYPE_THRESH,
+	IIO_EV_TYPE_MAG,
+	IIO_EV_TYPE_ROC,
+	IIO_EV_TYPE_THRESH_ADAPTIVE,
+	IIO_EV_TYPE_MAG_ADAPTIVE,
+};
+
+enum iio_event_info {
+	IIO_EV_INFO_ENABLE,
+	IIO_EV_INFO_VALUE,
+};
+
+enum iio_event_direction {
+	IIO_EV_DIR_EITHER,
+	IIO_EV_DIR_RISING,
+	IIO_EV_DIR_FALLING,
+};
+
 #define IIO_VAL_INT 1
 #define IIO_VAL_INT_PLUS_MICRO 2
 #define IIO_VAL_INT_PLUS_NANO 3
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 02/18] iio:max1363: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 03/18] iio:ad5421: " Lars-Peter Clausen
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the max1363 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>
---
 drivers/iio/adc/max1363.c | 196 +++++++++++++++++++++++++---------------------
 1 file changed, 107 insertions(+), 89 deletions(-)

diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index b4bc166..44343dc 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -424,11 +424,21 @@ static const enum max1363_modes max1363_mode_list[] = {
 	d0m1to2m3, d1m0to3m2,
 };
 
-#define MAX1363_EV_M						\
-	(IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)	\
-	 | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
+static const struct iio_event_spec max1363_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),
+	},
+};
 
-#define MAX1363_CHAN_U(num, addr, si, bits, evmask)			\
+#define MAX1363_CHAN_U(num, addr, si, bits, ev_spec, num_ev_spec)	\
 	{								\
 		.type = IIO_VOLTAGE,					\
 		.indexed = 1,						\
@@ -444,11 +454,12 @@ static const enum max1363_modes max1363_mode_list[] = {
 			.endianness = IIO_BE,				\
 		},							\
 		.scan_index = si,					\
-		.event_mask = evmask,					\
+		.event_spec = ev_spec,					\
+		.num_event_specs = num_ev_spec,				\
 	}
 
 /* bipolar channel */
-#define MAX1363_CHAN_B(num, num2, addr, si, bits, evmask)		\
+#define MAX1363_CHAN_B(num, num2, addr, si, bits, ev_spec, num_ev_spec)	\
 	{								\
 		.type = IIO_VOLTAGE,					\
 		.differential = 1,					\
@@ -466,28 +477,32 @@ static const enum max1363_modes max1363_mode_list[] = {
 			.endianness = IIO_BE,				\
 		},							\
 		.scan_index = si,					\
-		.event_mask = evmask,					\
+		.event_spec = ev_spec,					\
+		.num_event_specs = num_ev_spec,				\
 	}
 
-#define MAX1363_4X_CHANS(bits, em) {			\
-	MAX1363_CHAN_U(0, _s0, 0, bits, em),		\
-	MAX1363_CHAN_U(1, _s1, 1, bits, em),		\
-	MAX1363_CHAN_U(2, _s2, 2, bits, em),		\
-	MAX1363_CHAN_U(3, _s3, 3, bits, em),		\
-	MAX1363_CHAN_B(0, 1, d0m1, 4, bits, em),	\
-	MAX1363_CHAN_B(2, 3, d2m3, 5, bits, em),	\
-	MAX1363_CHAN_B(1, 0, d1m0, 6, bits, em),	\
-	MAX1363_CHAN_B(3, 2, d3m2, 7, bits, em),	\
-	IIO_CHAN_SOFT_TIMESTAMP(8)			\
+#define MAX1363_4X_CHANS(bits, ev_spec, num_ev_spec) {			\
+	MAX1363_CHAN_U(0, _s0, 0, bits, ev_spec, num_ev_spec),		\
+	MAX1363_CHAN_U(1, _s1, 1, bits, ev_spec, num_ev_spec),		\
+	MAX1363_CHAN_U(2, _s2, 2, bits, ev_spec, num_ev_spec),		\
+	MAX1363_CHAN_U(3, _s3, 3, bits, ev_spec, num_ev_spec),		\
+	MAX1363_CHAN_B(0, 1, d0m1, 4, bits, ev_spec, num_ev_spec),	\
+	MAX1363_CHAN_B(2, 3, d2m3, 5, bits, ev_spec, num_ev_spec),	\
+	MAX1363_CHAN_B(1, 0, d1m0, 6, bits, ev_spec, num_ev_spec),	\
+	MAX1363_CHAN_B(3, 2, d3m2, 7, bits, ev_spec, num_ev_spec),	\
+	IIO_CHAN_SOFT_TIMESTAMP(8)					\
 	}
 
-static const struct iio_chan_spec max1036_channels[] = MAX1363_4X_CHANS(8, 0);
-static const struct iio_chan_spec max1136_channels[] = MAX1363_4X_CHANS(10, 0);
-static const struct iio_chan_spec max1236_channels[] = MAX1363_4X_CHANS(12, 0);
+static const struct iio_chan_spec max1036_channels[] =
+	MAX1363_4X_CHANS(8, NULL, 0);
+static const struct iio_chan_spec max1136_channels[] =
+	MAX1363_4X_CHANS(10, NULL, 0);
+static const struct iio_chan_spec max1236_channels[] =
+	MAX1363_4X_CHANS(12, NULL, 0);
 static const struct iio_chan_spec max1361_channels[] =
-	MAX1363_4X_CHANS(10, MAX1363_EV_M);
+	MAX1363_4X_CHANS(10, max1363_events, ARRAY_SIZE(max1363_events));
 static const struct iio_chan_spec max1363_channels[] =
-	MAX1363_4X_CHANS(12, MAX1363_EV_M);
+	MAX1363_4X_CHANS(12, max1363_events, ARRAY_SIZE(max1363_events));
 
 /* Applies to max1236, max1237 */
 static const enum max1363_modes max1236_mode_list[] = {
@@ -511,32 +526,32 @@ static const enum max1363_modes max1238_mode_list[] = {
 	d6m7to8m9, d6m7to10m11, d7m6to9m8, d7m6to11m10,
 };
 
-#define MAX1363_12X_CHANS(bits) {			\
-	MAX1363_CHAN_U(0, _s0, 0, bits, 0),		\
-	MAX1363_CHAN_U(1, _s1, 1, bits, 0),		\
-	MAX1363_CHAN_U(2, _s2, 2, bits, 0),		\
-	MAX1363_CHAN_U(3, _s3, 3, bits, 0),		\
-	MAX1363_CHAN_U(4, _s4, 4, bits, 0),		\
-	MAX1363_CHAN_U(5, _s5, 5, bits, 0),		\
-	MAX1363_CHAN_U(6, _s6, 6, bits, 0),		\
-	MAX1363_CHAN_U(7, _s7, 7, bits, 0),		\
-	MAX1363_CHAN_U(8, _s8, 8, bits, 0),		\
-	MAX1363_CHAN_U(9, _s9, 9, bits, 0),		\
-	MAX1363_CHAN_U(10, _s10, 10, bits, 0),		\
-	MAX1363_CHAN_U(11, _s11, 11, bits, 0),		\
-	MAX1363_CHAN_B(0, 1, d0m1, 12, bits, 0),	\
-	MAX1363_CHAN_B(2, 3, d2m3, 13, bits, 0),	\
-	MAX1363_CHAN_B(4, 5, d4m5, 14, bits, 0),	\
-	MAX1363_CHAN_B(6, 7, d6m7, 15, bits, 0),	\
-	MAX1363_CHAN_B(8, 9, d8m9, 16, bits, 0),	\
-	MAX1363_CHAN_B(10, 11, d10m11, 17, bits, 0),	\
-	MAX1363_CHAN_B(1, 0, d1m0, 18, bits, 0),	\
-	MAX1363_CHAN_B(3, 2, d3m2, 19, bits, 0),	\
-	MAX1363_CHAN_B(5, 4, d5m4, 20, bits, 0),	\
-	MAX1363_CHAN_B(7, 6, d7m6, 21, bits, 0),	\
-	MAX1363_CHAN_B(9, 8, d9m8, 22, bits, 0),	\
-	MAX1363_CHAN_B(11, 10, d11m10, 23, bits, 0),	\
-	IIO_CHAN_SOFT_TIMESTAMP(24)			\
+#define MAX1363_12X_CHANS(bits) {				\
+	MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0),		\
+	MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0),		\
+	MAX1363_CHAN_U(2, _s2, 2, bits, NULL, 0),		\
+	MAX1363_CHAN_U(3, _s3, 3, bits, NULL, 0),		\
+	MAX1363_CHAN_U(4, _s4, 4, bits, NULL, 0),		\
+	MAX1363_CHAN_U(5, _s5, 5, bits, NULL, 0),		\
+	MAX1363_CHAN_U(6, _s6, 6, bits, NULL, 0),		\
+	MAX1363_CHAN_U(7, _s7, 7, bits, NULL, 0),		\
+	MAX1363_CHAN_U(8, _s8, 8, bits, NULL, 0),		\
+	MAX1363_CHAN_U(9, _s9, 9, bits, NULL, 0),		\
+	MAX1363_CHAN_U(10, _s10, 10, bits, NULL, 0),		\
+	MAX1363_CHAN_U(11, _s11, 11, bits, NULL, 0),		\
+	MAX1363_CHAN_B(0, 1, d0m1, 12, bits, NULL, 0),		\
+	MAX1363_CHAN_B(2, 3, d2m3, 13, bits, NULL, 0),		\
+	MAX1363_CHAN_B(4, 5, d4m5, 14, bits, NULL, 0),		\
+	MAX1363_CHAN_B(6, 7, d6m7, 15, bits, NULL, 0),		\
+	MAX1363_CHAN_B(8, 9, d8m9, 16, bits, NULL, 0),		\
+	MAX1363_CHAN_B(10, 11, d10m11, 17, bits, NULL, 0),	\
+	MAX1363_CHAN_B(1, 0, d1m0, 18, bits, NULL, 0),		\
+	MAX1363_CHAN_B(3, 2, d3m2, 19, bits, NULL, 0),		\
+	MAX1363_CHAN_B(5, 4, d5m4, 20, bits, NULL, 0),		\
+	MAX1363_CHAN_B(7, 6, d7m6, 21, bits, NULL, 0),		\
+	MAX1363_CHAN_B(9, 8, d9m8, 22, bits, NULL, 0),		\
+	MAX1363_CHAN_B(11, 10, d11m10, 23, bits, NULL, 0),	\
+	IIO_CHAN_SOFT_TIMESTAMP(24)				\
 	}
 static const struct iio_chan_spec max1038_channels[] = MAX1363_12X_CHANS(8);
 static const struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10);
@@ -561,22 +576,22 @@ static const enum max1363_modes max11608_mode_list[] = {
 };
 
 #define MAX1363_8X_CHANS(bits) {			\
-	MAX1363_CHAN_U(0, _s0, 0, bits, 0),		\
-	MAX1363_CHAN_U(1, _s1, 1, bits, 0),		\
-	MAX1363_CHAN_U(2, _s2, 2, bits, 0),		\
-	MAX1363_CHAN_U(3, _s3, 3, bits, 0),		\
-	MAX1363_CHAN_U(4, _s4, 4, bits, 0),		\
-	MAX1363_CHAN_U(5, _s5, 5, bits, 0),		\
-	MAX1363_CHAN_U(6, _s6, 6, bits, 0),		\
-	MAX1363_CHAN_U(7, _s7, 7, bits, 0),		\
-	MAX1363_CHAN_B(0, 1, d0m1, 8, bits, 0),	\
-	MAX1363_CHAN_B(2, 3, d2m3, 9, bits, 0),	\
-	MAX1363_CHAN_B(4, 5, d4m5, 10, bits, 0),	\
-	MAX1363_CHAN_B(6, 7, d6m7, 11, bits, 0),	\
-	MAX1363_CHAN_B(1, 0, d1m0, 12, bits, 0),	\
-	MAX1363_CHAN_B(3, 2, d3m2, 13, bits, 0),	\
-	MAX1363_CHAN_B(5, 4, d5m4, 14, bits, 0),	\
-	MAX1363_CHAN_B(7, 6, d7m6, 15, bits, 0),	\
+	MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0),	\
+	MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0),	\
+	MAX1363_CHAN_U(2, _s2, 2, bits, NULL, 0),	\
+	MAX1363_CHAN_U(3, _s3, 3, bits, NULL, 0),	\
+	MAX1363_CHAN_U(4, _s4, 4, bits, NULL, 0),	\
+	MAX1363_CHAN_U(5, _s5, 5, bits, NULL, 0),	\
+	MAX1363_CHAN_U(6, _s6, 6, bits, NULL, 0),	\
+	MAX1363_CHAN_U(7, _s7, 7, bits, NULL, 0),	\
+	MAX1363_CHAN_B(0, 1, d0m1, 8, bits, NULL, 0),	\
+	MAX1363_CHAN_B(2, 3, d2m3, 9, bits, NULL, 0),	\
+	MAX1363_CHAN_B(4, 5, d4m5, 10, bits, NULL, 0),	\
+	MAX1363_CHAN_B(6, 7, d6m7, 11, bits, NULL, 0),	\
+	MAX1363_CHAN_B(1, 0, d1m0, 12, bits, NULL, 0),	\
+	MAX1363_CHAN_B(3, 2, d3m2, 13, bits, NULL, 0),	\
+	MAX1363_CHAN_B(5, 4, d5m4, 14, bits, NULL, 0),	\
+	MAX1363_CHAN_B(7, 6, d7m6, 15, bits, NULL, 0),	\
 	IIO_CHAN_SOFT_TIMESTAMP(16)			\
 }
 static const struct iio_chan_spec max11602_channels[] = MAX1363_8X_CHANS(8);
@@ -588,10 +603,10 @@ static const enum max1363_modes max11644_mode_list[] = {
 };
 
 #define MAX1363_2X_CHANS(bits) {			\
-	MAX1363_CHAN_U(0, _s0, 0, bits, 0),		\
-	MAX1363_CHAN_U(1, _s1, 1, bits, 0),		\
-	MAX1363_CHAN_B(0, 1, d0m1, 2, bits, 0),	\
-	MAX1363_CHAN_B(1, 0, d1m0, 3, bits, 0),	\
+	MAX1363_CHAN_U(0, _s0, 0, bits, NULL, 0),	\
+	MAX1363_CHAN_U(1, _s1, 1, bits, NULL, 0),	\
+	MAX1363_CHAN_B(0, 1, d0m1, 2, bits, NULL, 0),	\
+	MAX1363_CHAN_B(1, 0, d1m0, 3, bits, NULL, 0),	\
 	IIO_CHAN_SOFT_TIMESTAMP(4)			\
 	}
 
@@ -686,20 +701,20 @@ static IIO_CONST_ATTR(sampling_frequency_available,
 		"133000 665000 33300 16600 8300 4200 2000 1000");
 
 static int max1363_read_thresh(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 max1363_state *st = iio_priv(indio_dev);
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
-		*val = st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)];
+	if (dir == IIO_EV_DIR_FALLING)
+		*val = st->thresh_low[chan->channel];
 	else
-		*val = st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)];
+		*val = st->thresh_high[chan->channel];
 	return 0;
 }
 
 static int max1363_write_thresh(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 max1363_state *st = iio_priv(indio_dev);
 	/* make it handle signed correctly as well */
@@ -714,13 +729,15 @@ static int max1363_write_thresh(struct iio_dev *indio_dev,
 		break;
 	}
 
-	switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+	switch (dir) {
 	case IIO_EV_DIR_FALLING:
-		st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val;
+		st->thresh_low[chan->channel] = val;
 		break;
 	case IIO_EV_DIR_RISING:
-		st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val;
+		st->thresh_high[chan->channel] = val;
 		break;
+	default:
+		return -EINVAL;
 	}
 
 	return 0;
@@ -765,14 +782,15 @@ static irqreturn_t max1363_event_handler(int irq, void *private)
 }
 
 static int max1363_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 max1363_state *st = iio_priv(indio_dev);
 	int val;
-	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
+	int number = chan->channel;
 
 	mutex_lock(&indio_dev->mlock);
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
+	if (dir == IIO_EV_DIR_FALLING)
 		val = (1 << number) & st->mask_low;
 	else
 		val = (1 << number) & st->mask_high;
@@ -917,17 +935,17 @@ error_ret:
 }
 
 static int max1363_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)
 {
 	int ret = 0;
 	struct max1363_state *st = iio_priv(indio_dev);
 	u16 unifiedmask;
-	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
+	int number = chan->channel;
 
 	mutex_lock(&indio_dev->mlock);
 	unifiedmask = st->mask_low | st->mask_high;
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) {
+	if (dir == IIO_EV_DIR_FALLING) {
 
 		if (state == 0)
 			st->mask_low &= ~(1 << number);
@@ -995,10 +1013,10 @@ static const struct iio_info max1238_info = {
 };
 
 static const struct iio_info max1363_info = {
-	.read_event_value = &max1363_read_thresh,
-	.write_event_value = &max1363_write_thresh,
-	.read_event_config = &max1363_read_event_config,
-	.write_event_config = &max1363_write_event_config,
+	.read_event_value_new = &max1363_read_thresh,
+	.write_event_value_new = &max1363_write_thresh,
+	.read_event_config_new = &max1363_read_event_config,
+	.write_event_config_new = &max1363_write_event_config,
 	.read_raw = &max1363_read_raw,
 	.update_scan_mode = &max1363_update_scan_mode,
 	.driver_module = THIS_MODULE,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 03/18] iio:ad5421: Switch to new event config interface
  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 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 04/18] iio:gp2ap020a00f: " Lars-Peter Clausen
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the ad5421 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>
---
 drivers/iio/dac/ad5421.c | 59 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index 1f78b14..eefc708 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -80,6 +80,29 @@ struct ad5421_state {
 	} data[2] ____cacheline_aligned;
 };
 
+static const struct iio_event_spec ad5421_current_event[] = {
+	{
+		.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 ad5421_temp_event[] = {
+	{
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_RISING,
+		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
+			BIT(IIO_EV_INFO_ENABLE),
+	},
+};
+
 static const struct iio_chan_spec ad5421_channels[] = {
 	{
 		.type = IIO_CURRENT,
@@ -92,13 +115,14 @@ static const struct iio_chan_spec ad5421_channels[] = {
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
 			BIT(IIO_CHAN_INFO_OFFSET),
 		.scan_type = IIO_ST('u', 16, 16, 0),
-		.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 = ad5421_current_event,
+		.num_event_specs = ARRAY_SIZE(ad5421_current_event),
 	},
 	{
 		.type = IIO_TEMP,
 		.channel = -1,
-		.event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING),
+		.event_spec = ad5421_temp_event,
+		.num_event_specs = ARRAY_SIZE(ad5421_temp_event),
 	},
 };
 
@@ -359,15 +383,15 @@ static int ad5421_write_raw(struct iio_dev *indio_dev,
 }
 
 static int ad5421_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 ad5421_state *st = iio_priv(indio_dev);
 	unsigned int mask;
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_CURRENT:
-		if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING)
+		if (dir == IIO_EV_DIR_RISING)
 			mask = AD5421_FAULT_OVER_CURRENT;
 		else
 			mask = AD5421_FAULT_UNDER_CURRENT;
@@ -390,15 +414,15 @@ static int ad5421_write_event_config(struct iio_dev *indio_dev,
 }
 
 static int ad5421_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 ad5421_state *st = iio_priv(indio_dev);
 	unsigned int mask;
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_CURRENT:
-		if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING)
+		if (dir == IIO_EV_DIR_RISING)
 			mask = AD5421_FAULT_OVER_CURRENT;
 		else
 			mask = AD5421_FAULT_UNDER_CURRENT;
@@ -413,12 +437,13 @@ static int ad5421_read_event_config(struct iio_dev *indio_dev,
 	return (bool)(st->fault_mask & mask);
 }
 
-static int ad5421_read_event_value(struct iio_dev *indio_dev, u64 event_code,
-	int *val)
+static int ad5421_read_event_value(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, enum iio_event_type type,
+	enum iio_event_direction dir, enum iio_event_info info, int *val)
 {
 	int ret;
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_CURRENT:
 		ret = ad5421_read(indio_dev, AD5421_REG_DAC_DATA);
 		if (ret < 0)
@@ -438,9 +463,9 @@ static int ad5421_read_event_value(struct iio_dev *indio_dev, u64 event_code,
 static const struct iio_info ad5421_info = {
 	.read_raw =		ad5421_read_raw,
 	.write_raw =		ad5421_write_raw,
-	.read_event_config =	ad5421_read_event_config,
-	.write_event_config =	ad5421_write_event_config,
-	.read_event_value =	ad5421_read_event_value,
+	.read_event_config_new = ad5421_read_event_config,
+	.write_event_config_new = ad5421_write_event_config,
+	.read_event_value_new =	ad5421_read_event_value,
 	.driver_module =	THIS_MODULE,
 };
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 04/18] iio:gp2ap020a00f: Switch to new event config interface
  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
  2013-09-26 12:58 ` [PATCH 05/18] iio:tsl2563: " Lars-Peter Clausen
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Jacek Anaszewski

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

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 05/18] iio:tsl2563: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 04/18] iio:gp2ap020a00f: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 06/18] iio:apds9300: Use " Lars-Peter Clausen
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the tsl2563 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>
---
 drivers/iio/light/tsl2563.c | 49 ++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index ebb962c..28c9953 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -526,6 +526,20 @@ error_ret:
 	return ret;
 }
 
+static const struct iio_event_spec tsl2563_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),
+	},
+};
+
 static const struct iio_chan_spec tsl2563_channels[] = {
 	{
 		.type = IIO_LIGHT,
@@ -538,10 +552,8 @@ static const struct iio_chan_spec tsl2563_channels[] = {
 		.channel2 = IIO_MOD_LIGHT_BOTH,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 		BIT(IIO_CHAN_INFO_CALIBSCALE),
-		.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 = tsl2563_events,
+		.num_event_specs = ARRAY_SIZE(tsl2563_events),
 	}, {
 		.type = IIO_INTENSITY,
 		.modified = 1,
@@ -552,12 +564,12 @@ static const struct iio_chan_spec tsl2563_channels[] = {
 };
 
 static int tsl2563_read_thresh(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 tsl2563_chip *chip = iio_priv(indio_dev);
 
-	switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+	switch (dir) {
 	case IIO_EV_DIR_RISING:
 		*val = chip->high_thres;
 		break;
@@ -572,14 +584,14 @@ static int tsl2563_read_thresh(struct iio_dev *indio_dev,
 }
 
 static int tsl2563_write_thresh(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 tsl2563_chip *chip = iio_priv(indio_dev);
 	int ret;
 	u8 address;
 
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
+	if (dir == IIO_EV_DIR_RISING)
 		address = TSL2563_REG_HIGHLOW;
 	else
 		address = TSL2563_REG_LOWLOW;
@@ -591,7 +603,7 @@ static int tsl2563_write_thresh(struct iio_dev *indio_dev,
 	ret = i2c_smbus_write_byte_data(chip->client,
 					TSL2563_CMD | (address + 1),
 					(val >> 8) & 0xFF);
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
+	if (dir == IIO_EV_DIR_RISING)
 		chip->high_thres = val;
 	else
 		chip->low_thres = val;
@@ -620,8 +632,8 @@ static irqreturn_t tsl2563_event_handler(int irq, void *private)
 }
 
 static int tsl2563_write_interrupt_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 tsl2563_chip *chip = iio_priv(indio_dev);
 	int ret = 0;
@@ -662,7 +674,8 @@ out:
 }
 
 static int tsl2563_read_interrupt_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 tsl2563_chip *chip = iio_priv(indio_dev);
 	int ret;
@@ -687,10 +700,10 @@ static const struct iio_info tsl2563_info = {
 	.driver_module = THIS_MODULE,
 	.read_raw = &tsl2563_read_raw,
 	.write_raw = &tsl2563_write_raw,
-	.read_event_value = &tsl2563_read_thresh,
-	.write_event_value = &tsl2563_write_thresh,
-	.read_event_config = &tsl2563_read_interrupt_config,
-	.write_event_config = &tsl2563_write_interrupt_config,
+	.read_event_value_new = &tsl2563_read_thresh,
+	.write_event_value_new = &tsl2563_write_thresh,
+	.read_event_config_new = &tsl2563_read_interrupt_config,
+	.write_event_config_new = &tsl2563_write_interrupt_config,
 };
 
 static int tsl2563_probe(struct i2c_client *client,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 06/18] iio:apds9300: Use new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 05/18] iio:tsl2563: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 07/18] staging:iio:lis3l02dq: Switch to " Lars-Peter Clausen
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Oleksandr Kravchenko

Switch the apds9300 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: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
---
 drivers/iio/light/apds9300.c | 48 ++++++++++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c
index 66a58bd..3f395f5 100644
--- a/drivers/iio/light/apds9300.c
+++ b/drivers/iio/light/apds9300.c
@@ -273,12 +273,14 @@ static int apds9300_read_raw(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int apds9300_read_thresh(struct iio_dev *indio_dev, u64 event_code,
+static int apds9300_read_thresh(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan, enum iio_event_type type,
+		enum iio_event_direction dir, enum iio_event_info info,
 		int *val)
 {
 	struct apds9300_data *data = iio_priv(indio_dev);
 
-	switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+	switch (dir) {
 	case IIO_EV_DIR_RISING:
 		*val = data->thresh_hi;
 		break;
@@ -292,14 +294,15 @@ static int apds9300_read_thresh(struct iio_dev *indio_dev, u64 event_code,
 	return 0;
 }
 
-static int apds9300_write_thresh(struct iio_dev *indio_dev, u64 event_code,
-		int val)
+static int apds9300_write_thresh(struct iio_dev *indio_dev,
+		const struct iio_chan_spec *chan, enum iio_event_type type,
+		enum iio_event_direction dir, enum iio_event_info info, int val)
 {
 	struct apds9300_data *data = iio_priv(indio_dev);
 	int ret;
 
 	mutex_lock(&data->mutex);
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_RISING)
+	if (dir == IIO_EV_DIR_RISING)
 		ret = apds9300_set_thresh_hi(data, val);
 	else
 		ret = apds9300_set_thresh_low(data, val);
@@ -309,7 +312,9 @@ static int apds9300_write_thresh(struct iio_dev *indio_dev, u64 event_code,
 }
 
 static int apds9300_read_interrupt_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 apds9300_data *data = iio_priv(indio_dev);
 
@@ -317,7 +322,8 @@ static int apds9300_read_interrupt_config(struct iio_dev *indio_dev,
 }
 
 static int apds9300_write_interrupt_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 apds9300_data *data = iio_priv(indio_dev);
 	int ret;
@@ -337,10 +343,24 @@ static const struct iio_info apds9300_info_no_irq = {
 static const struct iio_info apds9300_info = {
 	.driver_module		= THIS_MODULE,
 	.read_raw		= apds9300_read_raw,
-	.read_event_value	= apds9300_read_thresh,
-	.write_event_value	= apds9300_write_thresh,
-	.read_event_config	= apds9300_read_interrupt_config,
-	.write_event_config	= apds9300_write_interrupt_config,
+	.read_event_value_new	= apds9300_read_thresh,
+	.write_event_value_new	= apds9300_write_thresh,
+	.read_event_config_new	= apds9300_read_interrupt_config,
+	.write_event_config_new	= apds9300_write_interrupt_config,
+};
+
+static const struct iio_event_spec apds9300_event_spec[] = {
+	{
+		.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_chan_spec apds9300_channels[] = {
@@ -355,10 +375,8 @@ static const struct iio_chan_spec apds9300_channels[] = {
 		.channel2 = IIO_MOD_LIGHT_BOTH,
 		.indexed = true,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-		.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 = apds9300_event_spec,
+		.num_event_specs = ARRAY_SIZE(apds9300_event_spec),
 	}, {
 		.type = IIO_INTENSITY,
 		.channel = 1,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 07/18] staging:iio:lis3l02dq: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 06/18] iio:apds9300: Use " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-30 20:55   ` Jonathan Cameron
  2013-09-26 12:58 ` [PATCH 08/18] staging:iio:sca3000: Switch to new " Lars-Peter Clausen
                   ` (11 subsequent siblings)
  17 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the lis3l02dq 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>
---
 drivers/staging/iio/accel/lis3l02dq_core.c | 53 ++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index bb852dc..5cd9c45 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -190,14 +190,20 @@ static u8 lis3l02dq_axis_map[3][3] = {
 };
 
 static int lis3l02dq_read_thresh(struct iio_dev *indio_dev,
-				 u64 e,
+				 const struct iio_chan_spec *chan,
+				 enum iio_event_type type,
+				 enum iio_event_direction dir,
+				 enum iio_event_info info,
 				 int *val)
 {
 	return lis3l02dq_read_reg_s16(indio_dev, LIS3L02DQ_REG_THS_L_ADDR, val);
 }
 
 static int lis3l02dq_write_thresh(struct iio_dev *indio_dev,
-				  u64 event_code,
+				  const struct iio_chan_spec *chan,
+				  enum iio_event_type type,
+				  enum iio_event_direction dir,
+				  enum iio_event_info info,
 				  int val)
 {
 	u16 value = val;
@@ -503,9 +509,19 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
-#define LIS3L02DQ_EVENT_MASK					\
-	(IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |	\
-	 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
+static const struct iio_event_spec lis3l02dq_event[] = {
+	{
+		.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),
+	}
+};
 
 #define LIS3L02DQ_CHAN(index, mod)				\
 	{							\
@@ -523,7 +539,8 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
 			.realbits = 12,				\
 			.storagebits = 16,			\
 		},						\
-		.event_mask = LIS3L02DQ_EVENT_MASK,		\
+		.event_spec = lis3l02dq_event,			\
+		.num_event_specs = ARRAY_SIZE(lis3l02dq_event),	\
 	 }
 
 static const struct iio_chan_spec lis3l02dq_channels[] = {
@@ -535,14 +552,14 @@ static const struct iio_chan_spec lis3l02dq_channels[] = {
 
 
 static int lis3l02dq_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)
 {
 
 	u8 val;
 	int ret;
-	u8 mask = (1 << (IIO_EVENT_CODE_EXTRACT_MODIFIER(event_code)*2 +
-			 (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			  IIO_EV_DIR_RISING)));
+	u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
 	ret = lis3l02dq_spi_read_reg_8(indio_dev,
 				       LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
 				       &val);
@@ -587,16 +604,16 @@ error_ret:
 }
 
 static int lis3l02dq_write_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,
 					int state)
 {
 	int ret = 0;
 	u8 val, control;
 	u8 currentlyset;
 	bool changed = false;
-	u8 mask = (1 << (IIO_EVENT_CODE_EXTRACT_MODIFIER(event_code)*2 +
-			 (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			  IIO_EV_DIR_RISING)));
+	u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
 
 	mutex_lock(&indio_dev->mlock);
 	/* read current control */
@@ -654,10 +671,10 @@ static const struct attribute_group lis3l02dq_attribute_group = {
 static const struct iio_info lis3l02dq_info = {
 	.read_raw = &lis3l02dq_read_raw,
 	.write_raw = &lis3l02dq_write_raw,
-	.read_event_value = &lis3l02dq_read_thresh,
-	.write_event_value = &lis3l02dq_write_thresh,
-	.write_event_config = &lis3l02dq_write_event_config,
-	.read_event_config = &lis3l02dq_read_event_config,
+	.read_event_value_new = &lis3l02dq_read_thresh,
+	.write_event_value_new = &lis3l02dq_write_thresh,
+	.write_event_config_new = &lis3l02dq_write_event_config,
+	.read_event_config_new = &lis3l02dq_read_event_config,
 	.driver_module = THIS_MODULE,
 	.attrs = &lis3l02dq_attribute_group,
 };
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 08/18] staging:iio:sca3000: Switch to new config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 07/18] staging:iio:lis3l02dq: Switch to " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 09/18] staging:iio:ad7291: Switch to new event " Lars-Peter Clausen
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the sca3000 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>
---
 drivers/staging/iio/accel/sca3000_core.c | 52 ++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index 6a9ca20..7eb60a8 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -419,8 +419,11 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
 
 static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
 
-#define SCA3000_EVENT_MASK					\
-	(IIO_EV_BIT(IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING))
+static const struct iio_event_spec sca3000_event = {
+	.type = IIO_EV_TYPE_MAG,
+	.dir = IIO_EV_DIR_RISING,
+	.mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
+};
 
 #define SCA3000_CHAN(index, mod)				\
 	{							\
@@ -437,7 +440,8 @@ static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
 			.storagebits = 16,			\
 			.shift = 5,				\
 		},						\
-		.event_mask = SCA3000_EVENT_MASK,		\
+		.event_spec = &sca3000_event,			\
+		.num_event_specs = 1,				\
 	 }
 
 static const struct iio_chan_spec sca3000_channels[] = {
@@ -703,12 +707,15 @@ static IIO_CONST_ATTR_TEMP_OFFSET("-214.6");
  * sca3000_read_thresh() - query of a threshold
  **/
 static int sca3000_read_thresh(struct iio_dev *indio_dev,
-			       u64 e,
+			       const struct iio_chan_spec *chan,
+			       enum iio_event_type type,
+			       enum iio_event_direction dir,
+			       enum iio_event_info info,
 			       int *val)
 {
 	int ret, i;
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
+	int num = chan->channel2;
 	mutex_lock(&st->lock);
 	ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
 	mutex_unlock(&st->lock);
@@ -731,11 +738,14 @@ static int sca3000_read_thresh(struct iio_dev *indio_dev,
  * sca3000_write_thresh() control of threshold
  **/
 static int sca3000_write_thresh(struct iio_dev *indio_dev,
-				u64 e,
+				const struct iio_chan_spec *chan,
+				enum iio_event_type type,
+				enum iio_event_direction dir,
+				enum iio_event_info info,
 				int val)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
+	int num = chan->channel2;
 	int ret;
 	int i;
 	u8 nonlinear = 0;
@@ -866,12 +876,14 @@ done:
  * sca3000_read_event_config() what events are enabled
  **/
 static int sca3000_read_event_config(struct iio_dev *indio_dev,
-				     u64 e)
+				     const struct iio_chan_spec *chan,
+				     enum iio_event_type type,
+				     enum iio_event_direction dir)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
 	u8 protect_mask = 0x03;
-	int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
+	int num = chan->channel2;
 
 	/* read current value of mode register */
 	mutex_lock(&st->lock);
@@ -969,13 +981,15 @@ error_ret:
  * this mode is disabled.  Currently normal mode is assumed.
  **/
 static int sca3000_write_event_config(struct iio_dev *indio_dev,
-				      u64 e,
+				      const struct iio_chan_spec *chan,
+				      enum iio_event_type type,
+				      enum iio_event_direction dir,
 				      int state)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret, ctrlval;
 	u8 protect_mask = 0x03;
-	int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
+	int num = chan->channel2;
 
 	mutex_lock(&st->lock);
 	/* First read the motion detector config to find out if
@@ -1112,20 +1126,20 @@ static const struct iio_info sca3000_info = {
 	.attrs = &sca3000_attribute_group,
 	.read_raw = &sca3000_read_raw,
 	.event_attrs = &sca3000_event_attribute_group,
-	.read_event_value = &sca3000_read_thresh,
-	.write_event_value = &sca3000_write_thresh,
-	.read_event_config = &sca3000_read_event_config,
-	.write_event_config = &sca3000_write_event_config,
+	.read_event_value_new = &sca3000_read_thresh,
+	.write_event_value_new = &sca3000_write_thresh,
+	.read_event_config_new = &sca3000_read_event_config,
+	.write_event_config_new = &sca3000_write_event_config,
 	.driver_module = THIS_MODULE,
 };
 
 static const struct iio_info sca3000_info_with_temp = {
 	.attrs = &sca3000_attribute_group_with_temp,
 	.read_raw = &sca3000_read_raw,
-	.read_event_value = &sca3000_read_thresh,
-	.write_event_value = &sca3000_write_thresh,
-	.read_event_config = &sca3000_read_event_config,
-	.write_event_config = &sca3000_write_event_config,
+	.read_event_value_new = &sca3000_read_thresh,
+	.write_event_value_new = &sca3000_write_thresh,
+	.read_event_config_new = &sca3000_read_event_config,
+	.write_event_config_new = &sca3000_write_event_config,
 	.driver_module = THIS_MODULE,
 };
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 09/18] staging:iio:ad7291: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 08/18] staging:iio:sca3000: Switch to new " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 10/18] staging:iio:ad799x: " Lars-Peter Clausen
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the ad7291 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>
---
 drivers/staging/iio/adc/ad7291.c | 88 +++++++++++++++++++++++++---------------
 1 file changed, 55 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index 1dae1ef..fa60764 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -248,13 +248,14 @@ static struct attribute *ad7291_event_attributes[] = {
 	NULL,
 };
 
-static unsigned int ad7291_threshold_reg(u64 event_code)
+static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
+	enum iio_event_direction dir)
 {
 	unsigned int offset;
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_VOLTAGE:
-		offset = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
+		offset = chan->channel;
 		break;
 	case IIO_TEMP:
 		offset = 8;
@@ -263,25 +264,28 @@ static unsigned int ad7291_threshold_reg(u64 event_code)
 	    return 0;
 	}
 
-	if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING)
+	if (dir == IIO_EV_DIR_FALLING)
 		return AD7291_DATA_LOW(offset);
 	else
 		return AD7291_DATA_HIGH(offset);
 }
 
 static int ad7291_read_event_value(struct iio_dev *indio_dev,
-				   u64 event_code,
+				   const struct iio_chan_spec *chan,
+				   enum iio_event_type type,
+				   enum iio_event_direction dir,
+				   enum iio_event_info info,
 				   int *val)
 {
 	struct ad7291_chip_info *chip = iio_priv(indio_dev);
 	int ret;
 	u16 uval;
 
-	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(event_code), &uval);
+	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir), &uval);
 	if (ret < 0)
 		return ret;
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_VOLTAGE:
 		*val = uval & AD7291_VALUE_MASK;
 		return 0;
@@ -294,12 +298,15 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
 }
 
 static int ad7291_write_event_value(struct iio_dev *indio_dev,
-				    u64 event_code,
+				    const struct iio_chan_spec *chan,
+				    enum iio_event_type type,
+				    enum iio_event_direction dir,
+				    enum iio_event_info info,
 				    int val)
 {
 	struct ad7291_chip_info *chip = iio_priv(indio_dev);
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_VOLTAGE:
 		if (val > AD7291_VALUE_MASK || val < 0)
 			return -EINVAL;
@@ -312,20 +319,21 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
 		return -EINVAL;
 	}
 
-	return ad7291_i2c_write(chip, ad7291_threshold_reg(event_code), val);
+	return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir), val);
 }
 
 static int ad7291_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 ad7291_chip_info *chip = iio_priv(indio_dev);
 	/* To be enabled the channel must simply be on. If any are enabled
 	   we are in continuous sampling mode */
 
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_VOLTAGE:
-		if (chip->c_mask &
-		    (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))
+		if (chip->c_mask & (1 << (15 - chan->channel)))
 			return 1;
 		else
 			return 0;
@@ -339,11 +347,14 @@ static int ad7291_read_event_config(struct iio_dev *indio_dev,
 }
 
 static int ad7291_write_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,
 				     int state)
 {
 	int ret = 0;
 	struct ad7291_chip_info *chip = iio_priv(indio_dev);
+	unsigned int mask;
 	u16 regval;
 
 	mutex_lock(&chip->state_lock);
@@ -354,16 +365,14 @@ static int ad7291_write_event_config(struct iio_dev *indio_dev,
 	 * Possible to disable temp as well but that makes single read tricky.
 	 */
 
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	mask = BIT(15 - chan->channel);
+
+	switch (chan->type) {
 	case IIO_VOLTAGE:
-		if ((!state) && (chip->c_mask & (1 << (15 -
-				IIO_EVENT_CODE_EXTRACT_CHAN(event_code)))))
-			chip->c_mask &= ~(1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
-							(event_code)));
-		else if (state && (!(chip->c_mask & (1 << (15 -
-				IIO_EVENT_CODE_EXTRACT_CHAN(event_code))))))
-			chip->c_mask |= (1 << (15 - IIO_EVENT_CODE_EXTRACT_CHAN
-							(event_code)));
+		if ((!state) && (chip->c_mask & mask))
+			chip->c_mask &= ~mask;
+		else if (state && (!(chip->c_mask & mask)))
+			chip->c_mask |= mask;
 		else
 			break;
 
@@ -473,6 +482,20 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
 	}
 }
 
+static const struct iio_event_spec ad7291_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),
+	},
+};
+
 #define AD7291_VOLTAGE_CHAN(_chan)					\
 {									\
 	.type = IIO_VOLTAGE,						\
@@ -480,8 +503,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
 	.indexed = 1,							\
 	.channel = _chan,						\
-	.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 = ad7291_events,					\
+	.num_event_specs = ARRAY_SIZE(ad7291_events),			\
 }
 
 static const struct iio_chan_spec ad7291_channels[] = {
@@ -500,9 +523,8 @@ static const struct iio_chan_spec ad7291_channels[] = {
 				BIT(IIO_CHAN_INFO_SCALE),
 		.indexed = 1,
 		.channel = 0,
-		.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 = ad7291_events,
+		.num_event_specs = ARRAY_SIZE(ad7291_events),
 	}
 };
 
@@ -512,10 +534,10 @@ static struct attribute_group ad7291_event_attribute_group = {
 
 static const struct iio_info ad7291_info = {
 	.read_raw = &ad7291_read_raw,
-	.read_event_config = &ad7291_read_event_config,
-	.write_event_config = &ad7291_write_event_config,
-	.read_event_value = &ad7291_read_event_value,
-	.write_event_value = &ad7291_write_event_value,
+	.read_event_config_new = &ad7291_read_event_config,
+	.write_event_config_new = &ad7291_write_event_config,
+	.read_event_value_new = &ad7291_read_event_value,
+	.write_event_value_new = &ad7291_write_event_value,
 	.event_attrs = &ad7291_event_attribute_group,
 	.driver_module = THIS_MODULE,
 };
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 10/18] staging:iio:ad799x: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 09/18] staging:iio:ad7291: Switch to new event " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-30 20:59   ` Jonathan Cameron
  2013-09-26 12:58 ` [PATCH 11/18] staging:iio:ad7150: " Lars-Peter Clausen
                   ` (8 subsequent siblings)
  17 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the ad799x 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>
---
 drivers/staging/iio/adc/ad799x_core.c | 139 ++++++++++++++++++++--------------
 1 file changed, 82 insertions(+), 57 deletions(-)

diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 3f5142b..2b51cb4 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -254,7 +254,9 @@ error_ret_mutex:
 }
 
 static int ad799x_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)
 {
 	return 1;
 }
@@ -267,14 +269,16 @@ static const u8 ad799x_threshold_addresses[][2] = {
 };
 
 static int ad799x_write_event_value(struct iio_dev *indio_dev,
-				    u64 event_code,
+				    const struct iio_chan_spec *chan,
+				    enum iio_event_type type,
+				    enum iio_event_direction dir,
+					enum iio_event_info info,
 				    int val)
 {
 	int ret;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			   IIO_EV_DIR_FALLING);
-	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
+	int direction = dir == IIO_EV_DIR_FALLING;
+	int number = chan->channel;
 
 	mutex_lock(&indio_dev->mlock);
 	ret = ad799x_i2c_write16(st,
@@ -286,14 +290,16 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
 }
 
 static int ad799x_read_event_value(struct iio_dev *indio_dev,
-				    u64 event_code,
+				    const struct iio_chan_spec *chan,
+				    enum iio_event_type type,
+				    enum iio_event_direction dir,
+					enum iio_event_info info,
 				    int *val)
 {
 	int ret;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			   IIO_EV_DIR_FALLING);
-	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
+	int direction = dir == IIO_EV_DIR_FALLING;
+	int number = chan->channel;
 	u16 valin;
 
 	mutex_lock(&indio_dev->mlock);
@@ -448,26 +454,37 @@ static const struct iio_info ad7991_info = {
 static const struct iio_info ad7992_info = {
 	.read_raw = &ad799x_read_raw,
 	.event_attrs = &ad7992_event_attrs_group,
-	.read_event_config = &ad799x_read_event_config,
-	.read_event_value = &ad799x_read_event_value,
-	.write_event_value = &ad799x_write_event_value,
+	.read_event_config_new = &ad799x_read_event_config,
+	.read_event_value_new = &ad799x_read_event_value,
+	.write_event_value_new = &ad799x_write_event_value,
 	.driver_module = THIS_MODULE,
 };
 
 static const struct iio_info ad7993_4_7_8_info = {
 	.read_raw = &ad799x_read_raw,
 	.event_attrs = &ad7993_4_7_8_event_attrs_group,
-	.read_event_config = &ad799x_read_event_config,
-	.read_event_value = &ad799x_read_event_value,
-	.write_event_value = &ad799x_write_event_value,
+	.read_event_config_new = &ad799x_read_event_config,
+	.read_event_value_new = &ad799x_read_event_value,
+	.write_event_value_new = &ad799x_write_event_value,
 	.driver_module = THIS_MODULE,
 	.update_scan_mode = ad7997_8_update_scan_mode,
 };
 
-#define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
-			IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
+static const struct iio_event_spec ad799x_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),
+	},
+};
 
-#define AD799X_CHANNEL(_index, _realbits, _evmask) { \
+#define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
 	.type = IIO_VOLTAGE, \
 	.indexed = 1, \
 	.channel = (_index), \
@@ -475,16 +492,24 @@ static const struct iio_info ad7993_4_7_8_info = {
 	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
 	.scan_index = (_index), \
 	.scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
-	.event_mask = (_evmask), \
+	.event_spec = _ev_spec, \
+	.num_event_specs = _num_ev_spec, \
 }
 
+#define AD799X_CHANNEL(_index, _realbits) \
+	_AD799X_CHANNEL(_index, _realbits, NULL, 0)
+
+#define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
+	_AD799X_CHANNEL(_index, _realbits, ad799x_events, \
+		ARRAY_SIZE(ad799x_events))
+
 static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	[ad7991] = {
 		.channel = {
-			AD799X_CHANNEL(0, 12, 0),
-			AD799X_CHANNEL(1, 12, 0),
-			AD799X_CHANNEL(2, 12, 0),
-			AD799X_CHANNEL(3, 12, 0),
+			AD799X_CHANNEL(0, 12),
+			AD799X_CHANNEL(1, 12),
+			AD799X_CHANNEL(2, 12),
+			AD799X_CHANNEL(3, 12),
 			IIO_CHAN_SOFT_TIMESTAMP(4),
 		},
 		.num_channels = 5,
@@ -492,10 +517,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7995] = {
 		.channel = {
-			AD799X_CHANNEL(0, 10, 0),
-			AD799X_CHANNEL(1, 10, 0),
-			AD799X_CHANNEL(2, 10, 0),
-			AD799X_CHANNEL(3, 10, 0),
+			AD799X_CHANNEL(0, 10),
+			AD799X_CHANNEL(1, 10),
+			AD799X_CHANNEL(2, 10),
+			AD799X_CHANNEL(3, 10),
 			IIO_CHAN_SOFT_TIMESTAMP(4),
 		},
 		.num_channels = 5,
@@ -503,10 +528,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7999] = {
 		.channel = {
-			AD799X_CHANNEL(0, 8, 0),
-			AD799X_CHANNEL(1, 8, 0),
-			AD799X_CHANNEL(2, 8, 0),
-			AD799X_CHANNEL(3, 8, 0),
+			AD799X_CHANNEL(0, 8),
+			AD799X_CHANNEL(1, 8),
+			AD799X_CHANNEL(2, 8),
+			AD799X_CHANNEL(3, 8),
 			IIO_CHAN_SOFT_TIMESTAMP(4),
 		},
 		.num_channels = 5,
@@ -514,8 +539,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7992] = {
 		.channel = {
-			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
+			AD799X_CHANNEL_WITH_EVENTS(0, 12),
+			AD799X_CHANNEL_WITH_EVENTS(1, 12),
 			IIO_CHAN_SOFT_TIMESTAMP(3),
 		},
 		.num_channels = 3,
@@ -524,10 +549,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7993] = {
 		.channel = {
-			AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
+			AD799X_CHANNEL_WITH_EVENTS(0, 10),
+			AD799X_CHANNEL_WITH_EVENTS(1, 10),
+			AD799X_CHANNEL_WITH_EVENTS(2, 10),
+			AD799X_CHANNEL_WITH_EVENTS(3, 10),
 			IIO_CHAN_SOFT_TIMESTAMP(4),
 		},
 		.num_channels = 5,
@@ -536,10 +561,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7994] = {
 		.channel = {
-			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
+			AD799X_CHANNEL_WITH_EVENTS(0, 12),
+			AD799X_CHANNEL_WITH_EVENTS(1, 12),
+			AD799X_CHANNEL_WITH_EVENTS(2, 12),
+			AD799X_CHANNEL_WITH_EVENTS(3, 12),
 			IIO_CHAN_SOFT_TIMESTAMP(4),
 		},
 		.num_channels = 5,
@@ -548,14 +573,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7997] = {
 		.channel = {
-			AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
-			AD799X_CHANNEL(4, 10, 0),
-			AD799X_CHANNEL(5, 10, 0),
-			AD799X_CHANNEL(6, 10, 0),
-			AD799X_CHANNEL(7, 10, 0),
+			AD799X_CHANNEL_WITH_EVENTS(0, 10),
+			AD799X_CHANNEL_WITH_EVENTS(1, 10),
+			AD799X_CHANNEL_WITH_EVENTS(2, 10),
+			AD799X_CHANNEL_WITH_EVENTS(3, 10),
+			AD799X_CHANNEL(4, 10),
+			AD799X_CHANNEL(5, 10),
+			AD799X_CHANNEL(6, 10),
+			AD799X_CHANNEL(7, 10),
 			IIO_CHAN_SOFT_TIMESTAMP(8),
 		},
 		.num_channels = 9,
@@ -564,14 +589,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 	},
 	[ad7998] = {
 		.channel = {
-			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
-			AD799X_CHANNEL(4, 12, 0),
-			AD799X_CHANNEL(5, 12, 0),
-			AD799X_CHANNEL(6, 12, 0),
-			AD799X_CHANNEL(7, 12, 0),
+			AD799X_CHANNEL_WITH_EVENTS(0, 12),
+			AD799X_CHANNEL_WITH_EVENTS(1, 12),
+			AD799X_CHANNEL_WITH_EVENTS(2, 12),
+			AD799X_CHANNEL_WITH_EVENTS(3, 12),
+			AD799X_CHANNEL(4, 12),
+			AD799X_CHANNEL(5, 12),
+			AD799X_CHANNEL(6, 12),
+			AD799X_CHANNEL(7, 12),
 			IIO_CHAN_SOFT_TIMESTAMP(8),
 		},
 		.num_channels = 9,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 11/18] staging:iio:ad7150: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 10/18] staging:iio:ad799x: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 12/18] staging:iio:simple_dummy: " Lars-Peter Clausen
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

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>
---
 drivers/staging/iio/cdc/ad7150.c | 150 ++++++++++++++++++++++++---------------
 1 file changed, 94 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index f4a0341..ec2cf6e 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -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;
 	u8 threshtype;
 	bool adaptive;
 	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);
 	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;
 	adaptive = !!(ret & 0x80);
 
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	switch (type) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
-		if (rising)
+		if (dir == IIO_EV_DIR_RISING)
 			return adaptive && (threshtype == 0x1);
 		else
 			return adaptive && (threshtype == 0x0);
 	case IIO_EV_TYPE_THRESH_ADAPTIVE:
-		if (rising)
+		if (dir == IIO_EV_DIR_RISING)
 			return adaptive && (threshtype == 0x3);
 		else
 			return adaptive && (threshtype == 0x2);
 
 	case IIO_EV_TYPE_THRESH:
-		if (rising)
+		if (dir == IIO_EV_DIR_RISING)
 			return !adaptive && (threshtype == 0x1);
 		else
 			return !adaptive && (threshtype == 0x0);
+	default:
+		break;
 	}
 	return -EINVAL;
 }
 
 /* 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;
 	u16 value;
 	u8 sens, timeout;
 	struct ad7150_chip_info *chip = iio_priv(indio_dev);
-	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING);
+	int rising = (dir == IIO_EV_DIR_RISING);
+	u64 event_code;
+
+	event_code = IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, chan, type, dir);
 
 	if (event_code != chip->current_event)
 		return 0;
 
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	switch (type) {
 		/* Note completely different from the adaptive versions */
 	case IIO_EV_TYPE_THRESH:
 		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,
-				     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;
 	int ret;
 	struct ad7150_chip_info *chip = iio_priv(indio_dev);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING);
+	int rising = (dir == IIO_EV_DIR_RISING);
+	u64 event_code;
 
 	/* Something must always be turned on */
 	if (state == 0)
 		return -EINVAL;
 
+	event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir);
 	if (event_code == chip->current_event)
 		return 0;
 	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));
 
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	switch (type) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
 		adaptive = 1;
 		if (rising)
@@ -268,7 +275,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
 	chip->current_event = event_code;
 
 	/* 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:
 	mutex_unlock(&chip->state_lock);
 
@@ -276,26 +283,27 @@ error_ret:
 }
 
 static int ad7150_read_event_value(struct iio_dev *indio_dev,
-				   u64 event_code,
+				   const struct iio_chan_spec *chan,
+				   enum iio_event_type type,
+				   enum iio_event_direction dir,
+				   enum iio_event_info info,
 				   int *val)
 {
-	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
 	struct ad7150_chip_info *chip = iio_priv(indio_dev);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING);
+	int rising = (dir == IIO_EV_DIR_RISING);
 
 	/* Complex register sharing going on here */
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	switch (type) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
-		*val = chip->mag_sensitivity[rising][chan];
+		*val = chip->mag_sensitivity[rising][chan->channel];
 		return 0;
 
 	case IIO_EV_TYPE_THRESH_ADAPTIVE:
-		*val = chip->thresh_sensitivity[rising][chan];
+		*val = chip->thresh_sensitivity[rising][chan->channel];
 		return 0;
 
 	case IIO_EV_TYPE_THRESH:
-		*val = chip->threshold[rising][chan];
+		*val = chip->threshold[rising][chan->channel];
 		return 0;
 
 	default:
@@ -304,25 +312,26 @@ static int ad7150_read_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,
+				   enum iio_event_type type,
+				   enum iio_event_direction dir,
+				   enum iio_event_info info,
 				   int val)
 {
 	int ret;
 	struct ad7150_chip_info *chip = iio_priv(indio_dev);
-	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			IIO_EV_DIR_RISING);
+	int rising = (dir == IIO_EV_DIR_RISING);
 
 	mutex_lock(&chip->state_lock);
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+	switch (type) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
-		chip->mag_sensitivity[rising][chan] = val;
+		chip->mag_sensitivity[rising][chan->channel] = val;
 		break;
 	case IIO_EV_TYPE_THRESH_ADAPTIVE:
-		chip->thresh_sensitivity[rising][chan] = val;
+		chip->thresh_sensitivity[rising][chan->channel] = val;
 		break;
 	case IIO_EV_TYPE_THRESH:
-		chip->threshold[rising][chan] = val;
+		chip->threshold[rising][chan->channel] = val;
 		break;
 	default:
 		ret = -EINVAL;
@@ -330,7 +339,7 @@ static int ad7150_write_event_value(struct iio_dev *indio_dev,
 	}
 
 	/* 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:
 	mutex_unlock(&chip->state_lock);
@@ -374,17 +383,22 @@ static ssize_t ad7150_store_timeout(struct device *dev,
 	struct ad7150_chip_info *chip = iio_priv(indio_dev);
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 	int chan = IIO_EVENT_CODE_EXTRACT_CHAN(this_attr->address);
-	int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR(this_attr->address) ==
-			IIO_EV_DIR_RISING);
+	enum iio_event_direction dir;
+	enum iio_event_type type;
+	int rising;
 	u8 data;
 	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);
 	if (ret < 0)
 		return ret;
 
 	mutex_lock(&chip->state_lock);
-	switch (IIO_EVENT_CODE_EXTRACT_TYPE(this_attr->address)) {
+	switch (type) {
 	case IIO_EV_TYPE_MAG_ADAPTIVE:
 		chip->mag_timeout[rising][chan] = data;
 		break;
@@ -396,7 +410,7 @@ static ssize_t ad7150_store_timeout(struct device *dev,
 		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:
 	mutex_unlock(&chip->state_lock);
 
@@ -424,6 +438,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, 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[] = {
 	{
 		.type = IIO_CAPACITANCE,
@@ -431,26 +479,16 @@ static const struct iio_chan_spec ad7150_channels[] = {
 		.channel = 0,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 		BIT(IIO_CHAN_INFO_AVERAGE_RAW),
-		.event_mask =
-		IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
-		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)
+		.event_spec = ad7150_events,
+		.num_event_specs = ARRAY_SIZE(ad7150_events),
 	}, {
 		.type = IIO_CAPACITANCE,
 		.indexed = 1,
 		.channel = 1,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 		BIT(IIO_CHAN_INFO_AVERAGE_RAW),
-		.event_mask =
-		IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
-		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)
+		.event_spec = ad7150_events,
+		.num_event_specs = ARRAY_SIZE(ad7150_events),
 	},
 };
 
@@ -541,10 +579,10 @@ static const struct iio_info ad7150_info = {
 	.event_attrs = &ad7150_event_attribute_group,
 	.driver_module = THIS_MODULE,
 	.read_raw = &ad7150_read_raw,
-	.read_event_config = &ad7150_read_event_config,
-	.write_event_config = &ad7150_write_event_config,
-	.read_event_value = &ad7150_read_event_value,
-	.write_event_value = &ad7150_write_event_value,
+	.read_event_config_new = &ad7150_read_event_config,
+	.write_event_config_new = &ad7150_write_event_config,
+	.read_event_value_new = &ad7150_read_event_value,
+	.write_event_value_new = &ad7150_write_event_value,
 };
 
 /*
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 12/18] staging:iio:simple_dummy: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (9 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 11/18] staging:iio:ad7150: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 13/18] staging:iio:tsl2x7x: " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Switch the simple_dummy 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>
---
 drivers/staging/iio/iio_simple_dummy.c        | 30 ++++++++++++-------
 drivers/staging/iio/iio_simple_dummy.h        | 20 +++++++++----
 drivers/staging/iio/iio_simple_dummy_events.c | 43 +++++++++++++++++++--------
 3 files changed, 65 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index 141ec61..cdb8898 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -57,6 +57,20 @@ static const struct iio_dummy_accel_calibscale dummy_scales[] = {
 	{ 733, 13, 0x9 }, /* 733.000013 */
 };
 
+#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
+
+/*
+ * simple event - triggered when value rises above
+ * a threshold
+ */
+static const struct iio_event_spec iio_dummy_event = {
+	.type = IIO_EV_TYPE_THRESH,
+	.dir = IIO_EV_DIR_RISING,
+	.mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
+};
+
+#endif
+
 /*
  * iio_dummy_channels - Description of available channels
  *
@@ -104,12 +118,8 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
 			.shift = 0, /* zero shift */
 		},
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
-		/*
-		 * simple event - triggered when value rises above
-		 * a threshold
-		 */
-		.event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH,
-					 IIO_EV_DIR_RISING),
+		.event_spec = &iio_dummy_event,
+		.num_event_specs = 1,
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 	},
 	/* Differential ADC channel in_voltage1-voltage2_raw etc*/
@@ -360,10 +370,10 @@ static const struct iio_info iio_dummy_info = {
 	.read_raw = &iio_dummy_read_raw,
 	.write_raw = &iio_dummy_write_raw,
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
-	.read_event_config = &iio_simple_dummy_read_event_config,
-	.write_event_config = &iio_simple_dummy_write_event_config,
-	.read_event_value = &iio_simple_dummy_read_event_value,
-	.write_event_value = &iio_simple_dummy_write_event_value,
+	.read_event_config_new = &iio_simple_dummy_read_event_config,
+	.write_event_config_new = &iio_simple_dummy_write_event_config,
+	.read_event_value_new = &iio_simple_dummy_read_event_value,
+	.write_event_value_new = &iio_simple_dummy_write_event_value,
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 };
 
diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
index c9e8702..341a2af 100644
--- a/drivers/staging/iio/iio_simple_dummy.h
+++ b/drivers/staging/iio/iio_simple_dummy.h
@@ -45,19 +45,27 @@ struct iio_dummy_state {
 struct iio_dev;
 
 int iio_simple_dummy_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);
 
 int iio_simple_dummy_write_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,
 					int state);
 
 int iio_simple_dummy_read_event_value(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);
 
 int iio_simple_dummy_write_event_value(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);
 
 int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
 int iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
index 317b774..7448e483 100644
--- a/drivers/staging/iio/iio_simple_dummy_events.c
+++ b/drivers/staging/iio/iio_simple_dummy_events.c
@@ -23,13 +23,17 @@
 /**
  * iio_simple_dummy_read_event_config() - is event enabled?
  * @indio_dev: the device instance data
- * @event_code: event code of the event being queried
+ * @chan: channel for the event whose state is being queried
+ * @type: type of the event whose state is being queried
+ * @dir: direction of the vent whose state is being queried
  *
  * This function would normally query the relevant registers or a cache to
  * discover if the event generation is enabled on the device.
  */
 int iio_simple_dummy_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 iio_dummy_state *st = iio_priv(indio_dev);
 
@@ -39,7 +43,9 @@ int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
 /**
  * iio_simple_dummy_write_event_config() - set whether event is enabled
  * @indio_dev: the device instance data
- * @event_code: event code of event being enabled/disabled
+ * @chan: channel for the event whose state is being set
+ * @type: type of the event whose state is being set
+ * @dir: direction of the vent whose state is being set
  * @state: whether to enable or disable the device.
  *
  * This function would normally set the relevant registers on the devices
@@ -47,7 +53,9 @@ int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
  * value.
  */
 int iio_simple_dummy_write_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,
 					int state)
 {
 	struct iio_dummy_state *st = iio_priv(indio_dev);
@@ -56,12 +64,11 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
 	 *  Deliberately over the top code splitting to illustrate
 	 * how this is done when multiple events exist.
 	 */
-	switch (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code)) {
+	switch (chan->type) {
 	case IIO_VOLTAGE:
-		switch (IIO_EVENT_CODE_EXTRACT_TYPE(event_code)) {
+		switch (type) {
 		case IIO_EV_TYPE_THRESH:
-			if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
-			    IIO_EV_DIR_RISING)
+			if (dir == IIO_EV_DIR_RISING)
 				st->event_en = state;
 			else
 				return -EINVAL;
@@ -79,7 +86,10 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
 /**
  * iio_simple_dummy_read_event_value() - get value associated with event
  * @indio_dev: device instance specific data
- * @event_code: event code for the event whose value is being queried
+ * @chan: channel for the event whose value is being read
+ * @type: type of the event whose value is being read
+ * @dir: direction of the vent whose value is being read
+ * @info: info type of the event whose value is being read
  * @val: value for the event code.
  *
  * Many devices provide a large set of events of which only a subset may
@@ -89,7 +99,10 @@ int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
  * the enabled event is changed.
  */
 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
-				      u64 event_code,
+				      const struct iio_chan_spec *chan,
+				      enum iio_event_type type,
+				      enum iio_event_direction dir,
+					  enum iio_event_info info,
 				      int *val)
 {
 	struct iio_dummy_state *st = iio_priv(indio_dev);
@@ -102,11 +115,17 @@ int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
 /**
  * iio_simple_dummy_write_event_value() - set value associate with event
  * @indio_dev: device instance specific data
- * @event_code: event code for the event whose value is being set
+ * @chan: channel for the event whose value is being set
+ * @type: type of the event whose value is being set
+ * @dir: direction of the vent whose value is being set
+ * @info: info type of the event whose value is being set
  * @val: the value to be set.
  */
 int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
-				       u64 event_code,
+				       const struct iio_chan_spec *chan,
+				       enum iio_event_type type,
+				       enum iio_event_direction dir,
+					   enum iio_event_info info,
 				       int val)
 {
 	struct iio_dummy_state *st = iio_priv(indio_dev);
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 13/18] staging:iio:tsl2x7x: Switch to new event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (10 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 12/18] staging:iio:simple_dummy: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 14/18] iio: Remove support for the legacy " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Jon Brenner

Switch the tsl2x7x 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: Jon Brenner <jbrenner@taosinc.com>
---
 drivers/staging/iio/light/tsl2x7x_core.c | 116 +++++++++++++++++++------------
 1 file changed, 71 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
index 9c43dcf..1466f47 100644
--- a/drivers/staging/iio/light/tsl2x7x_core.c
+++ b/drivers/staging/iio/light/tsl2x7x_core.c
@@ -124,11 +124,6 @@
 #define TSL2X7X_mA13                   0xD0
 #define TSL2X7X_MAX_TIMER_CNT          (0xFF)
 
-/*Common device IIO EventMask */
-#define TSL2X7X_EVENT_MASK \
-		(IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
-		IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)),
-
 #define TSL2X7X_MIN_ITIME 3
 
 /* TAOS txx2x7x Device family members */
@@ -1222,12 +1217,14 @@ static ssize_t tsl2x7x_do_prox_calibrate(struct device *dev,
 }
 
 static int tsl2x7x_read_interrupt_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 tsl2X7X_chip *chip = iio_priv(indio_dev);
 	int ret;
 
-	if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY)
+	if (chan->type == IIO_INTENSITY)
 		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x10);
 	else
 		ret = !!(chip->tsl2x7x_settings.interrupts_en & 0x20);
@@ -1236,12 +1233,14 @@ static int tsl2x7x_read_interrupt_config(struct iio_dev *indio_dev,
 }
 
 static int tsl2x7x_write_interrupt_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,
 					  int val)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
 
-	if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
+	if (chan->type == IIO_INTENSITY) {
 		if (val)
 			chip->tsl2x7x_settings.interrupts_en |= 0x10;
 		else
@@ -1259,13 +1258,16 @@ static int tsl2x7x_write_interrupt_config(struct iio_dev *indio_dev,
 }
 
 static int tsl2x7x_write_thresh(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 tsl2X7X_chip *chip = iio_priv(indio_dev);
 
-	if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
-		switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+	if (chan->type == IIO_INTENSITY) {
+		switch (dir) {
 		case IIO_EV_DIR_RISING:
 			chip->tsl2x7x_settings.als_thresh_high = val;
 			break;
@@ -1276,7 +1278,7 @@ static int tsl2x7x_write_thresh(struct iio_dev *indio_dev,
 			return -EINVAL;
 		}
 	} else {
-		switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+		switch (dir) {
 		case IIO_EV_DIR_RISING:
 			chip->tsl2x7x_settings.prox_thres_high = val;
 			break;
@@ -1294,13 +1296,16 @@ static int tsl2x7x_write_thresh(struct iio_dev *indio_dev,
 }
 
 static int tsl2x7x_read_thresh(struct iio_dev *indio_dev,
-			       u64 event_code,
+			       const struct iio_chan_spec *chan,
+			       enum iio_event_type type,
+			       enum iio_event_direction dir,
+				   enum iio_event_info info,
 			       int *val)
 {
 	struct tsl2X7X_chip *chip = iio_priv(indio_dev);
 
-	if (IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(event_code) == IIO_INTENSITY) {
-		switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+	if (chan->type == IIO_INTENSITY) {
+		switch (dir) {
 		case IIO_EV_DIR_RISING:
 			*val = chip->tsl2x7x_settings.als_thresh_high;
 			break;
@@ -1311,7 +1316,7 @@ static int tsl2x7x_read_thresh(struct iio_dev *indio_dev,
 			return -EINVAL;
 		}
 	} else {
-		switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) {
+		switch (dir) {
 		case IIO_EV_DIR_RISING:
 			*val = chip->tsl2x7x_settings.prox_thres_high;
 			break;
@@ -1667,10 +1672,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_thresh,
-		.write_event_value = &tsl2x7x_write_thresh,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.read_event_value_new = &tsl2x7x_read_thresh,
+		.write_event_value_new = &tsl2x7x_write_thresh,
+		.read_event_config_new = &tsl2x7x_read_interrupt_config,
+		.write_event_config_new = &tsl2x7x_write_interrupt_config,
 	},
 	[PRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
@@ -1678,10 +1683,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_thresh,
-		.write_event_value = &tsl2x7x_write_thresh,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.read_event_value_new = &tsl2x7x_read_thresh,
+		.write_event_value_new = &tsl2x7x_write_thresh,
+		.read_event_config_new = &tsl2x7x_read_interrupt_config,
+		.write_event_config_new = &tsl2x7x_write_interrupt_config,
 	},
 	[ALSPRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
@@ -1689,10 +1694,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_thresh,
-		.write_event_value = &tsl2x7x_write_thresh,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.read_event_value_new = &tsl2x7x_read_thresh,
+		.write_event_value_new = &tsl2x7x_write_thresh,
+		.read_event_config_new = &tsl2x7x_read_interrupt_config,
+		.write_event_config_new = &tsl2x7x_write_interrupt_config,
 	},
 	[PRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
@@ -1700,10 +1705,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_thresh,
-		.write_event_value = &tsl2x7x_write_thresh,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.read_event_value_new = &tsl2x7x_read_thresh,
+		.write_event_value_new = &tsl2x7x_write_thresh,
+		.read_event_config_new = &tsl2x7x_read_interrupt_config,
+		.write_event_config_new = &tsl2x7x_write_interrupt_config,
 	},
 	[ALSPRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
@@ -1711,10 +1716,24 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value = &tsl2x7x_read_thresh,
-		.write_event_value = &tsl2x7x_write_thresh,
-		.read_event_config = &tsl2x7x_read_interrupt_config,
-		.write_event_config = &tsl2x7x_write_interrupt_config,
+		.read_event_value_new = &tsl2x7x_read_thresh,
+		.write_event_value_new = &tsl2x7x_write_thresh,
+		.read_event_config_new = &tsl2x7x_read_interrupt_config,
+		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+	},
+};
+
+static const struct iio_event_spec tsl2x7x_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),
 	},
 };
 
@@ -1733,7 +1752,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1750,7 +1770,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.indexed = 1,
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
 	.chan_table_elements = 1,
@@ -1770,7 +1791,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1781,7 +1803,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.indexed = 1,
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
 	.chan_table_elements = 4,
@@ -1795,7 +1818,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
 	.chan_table_elements = 1,
@@ -1815,7 +1839,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE) |
 				BIT(IIO_CHAN_INFO_CALIBBIAS),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			}, {
 			.type = IIO_INTENSITY,
 			.indexed = 1,
@@ -1827,7 +1852,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
 			.channel = 0,
 			.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
 				BIT(IIO_CHAN_INFO_CALIBSCALE),
-			.event_mask = TSL2X7X_EVENT_MASK
+			.event_spec = tsl2x7x_events,
+			.num_event_specs = ARRAY_SIZE(tsl2x7x_events),
 			},
 		},
 	.chan_table_elements = 4,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 14/18] iio: Remove support for the legacy event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (11 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 13/18] staging:iio:tsl2x7x: " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-30 21:05   ` Jonathan Cameron
  2013-09-26 12:58 ` [PATCH 15/18] iio: Add a hysteresis event info attribute Lars-Peter Clausen
                   ` (4 subsequent siblings)
  17 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Now that all drivers have been converted to the new event config interface we
can remove for the legacy event config interface. Also drop the '_new' suffix
for the event config interface callbacks, since those are the only callbacks
now.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/max1363.c                  |   8 +-
 drivers/iio/dac/ad5421.c                   |   6 +-
 drivers/iio/industrialio-event.c           | 133 ++++-------------------------
 drivers/iio/light/apds9300.c               |   8 +-
 drivers/iio/light/gp2ap020a00f.c           |   8 +-
 drivers/iio/light/tsl2563.c                |   8 +-
 drivers/staging/iio/accel/lis3l02dq_core.c |   8 +-
 drivers/staging/iio/accel/sca3000_core.c   |  16 ++--
 drivers/staging/iio/adc/ad7291.c           |   8 +-
 drivers/staging/iio/adc/ad799x_core.c      |  12 +--
 drivers/staging/iio/cdc/ad7150.c           |   8 +-
 drivers/staging/iio/iio_simple_dummy.c     |   8 +-
 drivers/staging/iio/light/tsl2x7x_core.c   |  40 ++++-----
 include/linux/iio/events.h                 |   4 -
 include/linux/iio/iio.h                    |  34 ++------
 15 files changed, 90 insertions(+), 219 deletions(-)

diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 44343dc..6722b4e 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1013,10 +1013,10 @@ static const struct iio_info max1238_info = {
 };
 
 static const struct iio_info max1363_info = {
-	.read_event_value_new = &max1363_read_thresh,
-	.write_event_value_new = &max1363_write_thresh,
-	.read_event_config_new = &max1363_read_event_config,
-	.write_event_config_new = &max1363_write_event_config,
+	.read_event_value = &max1363_read_thresh,
+	.write_event_value = &max1363_write_thresh,
+	.read_event_config = &max1363_read_event_config,
+	.write_event_config = &max1363_write_event_config,
 	.read_raw = &max1363_read_raw,
 	.update_scan_mode = &max1363_update_scan_mode,
 	.driver_module = THIS_MODULE,
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index eefc708..4847037 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -463,9 +463,9 @@ static int ad5421_read_event_value(struct iio_dev *indio_dev,
 static const struct iio_info ad5421_info = {
 	.read_raw =		ad5421_read_raw,
 	.write_raw =		ad5421_write_raw,
-	.read_event_config_new = ad5421_read_event_config,
-	.write_event_config_new = ad5421_write_event_config,
-	.read_event_value_new =	ad5421_read_event_value,
+	.read_event_config =	ad5421_read_event_config,
+	.write_event_config =	ad5421_write_event_config,
+	.read_event_value =	ad5421_read_event_value,
 	.driver_module =	THIS_MODULE,
 };
 
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index d426781..f4fa690 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -216,13 +216,9 @@ static ssize_t iio_ev_state_store(struct device *dev,
 	if (ret < 0)
 		return ret;
 
-	if (indio_dev->info->write_event_config)
-		ret = indio_dev->info->write_event_config(indio_dev,
-			this_attr->address, val);
-	else
-		ret = indio_dev->info->write_event_config_new(indio_dev,
-			this_attr->c, iio_ev_attr_type(this_attr),
-			iio_ev_attr_dir(this_attr), val);
+	ret = indio_dev->info->write_event_config(indio_dev,
+		this_attr->c, iio_ev_attr_type(this_attr),
+		iio_ev_attr_dir(this_attr), val);
 
 	return (ret < 0) ? ret : len;
 }
@@ -235,13 +231,9 @@ static ssize_t iio_ev_state_show(struct device *dev,
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 	int val;
 
-	if (indio_dev->info->read_event_config)
-		val = indio_dev->info->read_event_config(indio_dev,
-			this_attr->address);
-	else
-		val = indio_dev->info->read_event_config_new(indio_dev,
-			this_attr->c, iio_ev_attr_type(this_attr),
-			iio_ev_attr_dir(this_attr));
+	val = indio_dev->info->read_event_config(indio_dev,
+		this_attr->c, iio_ev_attr_type(this_attr),
+		iio_ev_attr_dir(this_attr));
 	if (val < 0)
 		return val;
 	else
@@ -256,14 +248,10 @@ static ssize_t iio_ev_value_show(struct device *dev,
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 	int val, ret;
 
-	if (indio_dev->info->read_event_value)
-		ret = indio_dev->info->read_event_value(indio_dev,
-			this_attr->address, &val);
-	else
-		ret = indio_dev->info->read_event_value_new(indio_dev,
-			this_attr->c, iio_ev_attr_type(this_attr),
-			iio_ev_attr_dir(this_attr),
-			iio_ev_attr_info(this_attr), &val);
+	ret = indio_dev->info->read_event_value(indio_dev,
+		this_attr->c, iio_ev_attr_type(this_attr),
+		iio_ev_attr_dir(this_attr),
+		iio_ev_attr_info(this_attr), &val);
 	if (ret < 0)
 		return ret;
 
@@ -280,22 +268,17 @@ static ssize_t iio_ev_value_store(struct device *dev,
 	int val;
 	int ret;
 
-	if (!indio_dev->info->write_event_value &&
-		!indio_dev->info->write_event_value_new)
+	if (!indio_dev->info->write_event_value)
 		return -EINVAL;
 
 	ret = kstrtoint(buf, 10, &val);
 	if (ret)
 		return ret;
 
-	if (indio_dev->info->write_event_value)
-		ret = indio_dev->info->write_event_value(indio_dev,
-			this_attr->address, val);
-	else
-		ret = indio_dev->info->write_event_value_new(indio_dev,
-			this_attr->c, iio_ev_attr_type(this_attr),
-			iio_ev_attr_dir(this_attr),
-			iio_ev_attr_info(this_attr), val);
+	ret = indio_dev->info->write_event_value(indio_dev,
+		this_attr->c, iio_ev_attr_type(this_attr),
+		iio_ev_attr_dir(this_attr),
+		iio_ev_attr_info(this_attr), val);
 	if (ret < 0)
 		return ret;
 
@@ -348,7 +331,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
 	return attrcount;
 }
 
-static int iio_device_add_event_sysfs_new(struct iio_dev *indio_dev,
+static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
 				      struct iio_chan_spec const *chan)
 {
 	int ret = 0, i, attrcount = 0;
@@ -391,88 +374,6 @@ error_ret:
 	return ret;
 }
 
-static int iio_device_add_event_sysfs_old(struct iio_dev *indio_dev,
-				      struct iio_chan_spec const *chan)
-{
-	int ret = 0, i, attrcount = 0;
-	u64 mask = 0;
-	char *postfix;
-	if (!chan->event_mask)
-		return 0;
-
-	for_each_set_bit(i, &chan->event_mask, sizeof(chan->event_mask)*8) {
-		postfix = kasprintf(GFP_KERNEL, "%s_%s_en",
-				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
-				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
-		if (postfix == NULL) {
-			ret = -ENOMEM;
-			goto error_ret;
-		}
-		if (chan->modified)
-			mask = IIO_MOD_EVENT_CODE(chan->type, 0, chan->channel,
-						  i/IIO_EV_DIR_MAX,
-						  i%IIO_EV_DIR_MAX);
-		else if (chan->differential)
-			mask = IIO_EVENT_CODE(chan->type,
-					      0, 0,
-					      i%IIO_EV_DIR_MAX,
-					      i/IIO_EV_DIR_MAX,
-					      0,
-					      chan->channel,
-					      chan->channel2);
-		else
-			mask = IIO_UNMOD_EVENT_CODE(chan->type,
-						    chan->channel,
-						    i/IIO_EV_DIR_MAX,
-						    i%IIO_EV_DIR_MAX);
-
-		ret = __iio_add_chan_devattr(postfix,
-					     chan,
-					     &iio_ev_state_show,
-					     iio_ev_state_store,
-					     mask,
-					     0,
-					     &indio_dev->dev,
-					     &indio_dev->event_interface->
-					     dev_attr_list);
-		kfree(postfix);
-		if (ret)
-			goto error_ret;
-		attrcount++;
-		postfix = kasprintf(GFP_KERNEL, "%s_%s_value",
-				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
-				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
-		if (postfix == NULL) {
-			ret = -ENOMEM;
-			goto error_ret;
-		}
-		ret = __iio_add_chan_devattr(postfix, chan,
-					     iio_ev_value_show,
-					     iio_ev_value_store,
-					     mask,
-					     0,
-					     &indio_dev->dev,
-					     &indio_dev->event_interface->
-					     dev_attr_list);
-		kfree(postfix);
-		if (ret)
-			goto error_ret;
-		attrcount++;
-	}
-	ret = attrcount;
-error_ret:
-	return ret;
-}
-
-static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
-				      struct iio_chan_spec const *chan)
-{
-	if (chan->event_mask)
-		return iio_device_add_event_sysfs_old(indio_dev, chan);
-	else
-		return iio_device_add_event_sysfs_new(indio_dev, chan);
-}
-
 static inline void __iio_remove_event_config_attrs(struct iio_dev *indio_dev)
 {
 	struct iio_dev_attr *p, *n;
@@ -504,8 +405,6 @@ static bool iio_check_for_dynamic_events(struct iio_dev *indio_dev)
 	int j;
 
 	for (j = 0; j < indio_dev->num_channels; j++) {
-		if (indio_dev->channels[j].event_mask != 0)
-			return true;
 		if (indio_dev->channels[j].num_event_specs != 0)
 			return true;
 	}
diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c
index 3f395f5..8601d76 100644
--- a/drivers/iio/light/apds9300.c
+++ b/drivers/iio/light/apds9300.c
@@ -343,10 +343,10 @@ static const struct iio_info apds9300_info_no_irq = {
 static const struct iio_info apds9300_info = {
 	.driver_module		= THIS_MODULE,
 	.read_raw		= apds9300_read_raw,
-	.read_event_value_new	= apds9300_read_thresh,
-	.write_event_value_new	= apds9300_write_thresh,
-	.read_event_config_new	= apds9300_read_interrupt_config,
-	.write_event_config_new	= apds9300_write_interrupt_config,
+	.read_event_value	= apds9300_read_thresh,
+	.write_event_value	= apds9300_write_thresh,
+	.read_event_config	= apds9300_read_interrupt_config,
+	.write_event_config	= apds9300_write_interrupt_config,
 };
 
 static const struct iio_event_spec apds9300_event_spec[] = {
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index 43f47f7..20b27af 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1387,10 +1387,10 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
 
 static const struct iio_info gp2ap020a00f_info = {
 	.read_raw = &gp2ap020a00f_read_raw,
-	.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,
+	.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,
 	.driver_module = THIS_MODULE,
 };
 
diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index 28c9953..89aa50a 100644
--- a/drivers/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -700,10 +700,10 @@ static const struct iio_info tsl2563_info = {
 	.driver_module = THIS_MODULE,
 	.read_raw = &tsl2563_read_raw,
 	.write_raw = &tsl2563_write_raw,
-	.read_event_value_new = &tsl2563_read_thresh,
-	.write_event_value_new = &tsl2563_write_thresh,
-	.read_event_config_new = &tsl2563_read_interrupt_config,
-	.write_event_config_new = &tsl2563_write_interrupt_config,
+	.read_event_value = &tsl2563_read_thresh,
+	.write_event_value = &tsl2563_write_thresh,
+	.read_event_config = &tsl2563_read_interrupt_config,
+	.write_event_config = &tsl2563_write_interrupt_config,
 };
 
 static int tsl2563_probe(struct i2c_client *client,
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index 5cd9c45..387efcc 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -671,10 +671,10 @@ static const struct attribute_group lis3l02dq_attribute_group = {
 static const struct iio_info lis3l02dq_info = {
 	.read_raw = &lis3l02dq_read_raw,
 	.write_raw = &lis3l02dq_write_raw,
-	.read_event_value_new = &lis3l02dq_read_thresh,
-	.write_event_value_new = &lis3l02dq_write_thresh,
-	.write_event_config_new = &lis3l02dq_write_event_config,
-	.read_event_config_new = &lis3l02dq_read_event_config,
+	.read_event_value = &lis3l02dq_read_thresh,
+	.write_event_value = &lis3l02dq_write_thresh,
+	.write_event_config = &lis3l02dq_write_event_config,
+	.read_event_config = &lis3l02dq_read_event_config,
 	.driver_module = THIS_MODULE,
 	.attrs = &lis3l02dq_attribute_group,
 };
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index 7eb60a8..3c8ac8e 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -1126,20 +1126,20 @@ static const struct iio_info sca3000_info = {
 	.attrs = &sca3000_attribute_group,
 	.read_raw = &sca3000_read_raw,
 	.event_attrs = &sca3000_event_attribute_group,
-	.read_event_value_new = &sca3000_read_thresh,
-	.write_event_value_new = &sca3000_write_thresh,
-	.read_event_config_new = &sca3000_read_event_config,
-	.write_event_config_new = &sca3000_write_event_config,
+	.read_event_value = &sca3000_read_thresh,
+	.write_event_value = &sca3000_write_thresh,
+	.read_event_config = &sca3000_read_event_config,
+	.write_event_config = &sca3000_write_event_config,
 	.driver_module = THIS_MODULE,
 };
 
 static const struct iio_info sca3000_info_with_temp = {
 	.attrs = &sca3000_attribute_group_with_temp,
 	.read_raw = &sca3000_read_raw,
-	.read_event_value_new = &sca3000_read_thresh,
-	.write_event_value_new = &sca3000_write_thresh,
-	.read_event_config_new = &sca3000_read_event_config,
-	.write_event_config_new = &sca3000_write_event_config,
+	.read_event_value = &sca3000_read_thresh,
+	.write_event_value = &sca3000_write_thresh,
+	.read_event_config = &sca3000_read_event_config,
+	.write_event_config = &sca3000_write_event_config,
 	.driver_module = THIS_MODULE,
 };
 
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index fa60764..dcd24ab 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -534,10 +534,10 @@ static struct attribute_group ad7291_event_attribute_group = {
 
 static const struct iio_info ad7291_info = {
 	.read_raw = &ad7291_read_raw,
-	.read_event_config_new = &ad7291_read_event_config,
-	.write_event_config_new = &ad7291_write_event_config,
-	.read_event_value_new = &ad7291_read_event_value,
-	.write_event_value_new = &ad7291_write_event_value,
+	.read_event_config = &ad7291_read_event_config,
+	.write_event_config = &ad7291_write_event_config,
+	.read_event_value = &ad7291_read_event_value,
+	.write_event_value = &ad7291_write_event_value,
 	.event_attrs = &ad7291_event_attribute_group,
 	.driver_module = THIS_MODULE,
 };
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 2b51cb4..73f7604 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -454,18 +454,18 @@ static const struct iio_info ad7991_info = {
 static const struct iio_info ad7992_info = {
 	.read_raw = &ad799x_read_raw,
 	.event_attrs = &ad7992_event_attrs_group,
-	.read_event_config_new = &ad799x_read_event_config,
-	.read_event_value_new = &ad799x_read_event_value,
-	.write_event_value_new = &ad799x_write_event_value,
+	.read_event_config = &ad799x_read_event_config,
+	.read_event_value = &ad799x_read_event_value,
+	.write_event_value = &ad799x_write_event_value,
 	.driver_module = THIS_MODULE,
 };
 
 static const struct iio_info ad7993_4_7_8_info = {
 	.read_raw = &ad799x_read_raw,
 	.event_attrs = &ad7993_4_7_8_event_attrs_group,
-	.read_event_config_new = &ad799x_read_event_config,
-	.read_event_value_new = &ad799x_read_event_value,
-	.write_event_value_new = &ad799x_write_event_value,
+	.read_event_config = &ad799x_read_event_config,
+	.read_event_value = &ad799x_read_event_value,
+	.write_event_value = &ad799x_write_event_value,
 	.driver_module = THIS_MODULE,
 	.update_scan_mode = ad7997_8_update_scan_mode,
 };
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index ec2cf6e..bb37bed 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -579,10 +579,10 @@ static const struct iio_info ad7150_info = {
 	.event_attrs = &ad7150_event_attribute_group,
 	.driver_module = THIS_MODULE,
 	.read_raw = &ad7150_read_raw,
-	.read_event_config_new = &ad7150_read_event_config,
-	.write_event_config_new = &ad7150_write_event_config,
-	.read_event_value_new = &ad7150_read_event_value,
-	.write_event_value_new = &ad7150_write_event_value,
+	.read_event_config = &ad7150_read_event_config,
+	.write_event_config = &ad7150_write_event_config,
+	.read_event_value = &ad7150_read_event_value,
+	.write_event_value = &ad7150_write_event_value,
 };
 
 /*
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index cdb8898..d3847fc 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -370,10 +370,10 @@ static const struct iio_info iio_dummy_info = {
 	.read_raw = &iio_dummy_read_raw,
 	.write_raw = &iio_dummy_write_raw,
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
-	.read_event_config_new = &iio_simple_dummy_read_event_config,
-	.write_event_config_new = &iio_simple_dummy_write_event_config,
-	.read_event_value_new = &iio_simple_dummy_read_event_value,
-	.write_event_value_new = &iio_simple_dummy_write_event_value,
+	.read_event_config = &iio_simple_dummy_read_event_config,
+	.write_event_config = &iio_simple_dummy_write_event_config,
+	.read_event_value = &iio_simple_dummy_read_event_value,
+	.write_event_value = &iio_simple_dummy_write_event_value,
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 };
 
diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
index 1466f47..a429148 100644
--- a/drivers/staging/iio/light/tsl2x7x_core.c
+++ b/drivers/staging/iio/light/tsl2x7x_core.c
@@ -1672,10 +1672,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value_new = &tsl2x7x_read_thresh,
-		.write_event_value_new = &tsl2x7x_write_thresh,
-		.read_event_config_new = &tsl2x7x_read_interrupt_config,
-		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+		.read_event_value = &tsl2x7x_read_thresh,
+		.write_event_value = &tsl2x7x_write_thresh,
+		.read_event_config = &tsl2x7x_read_interrupt_config,
+		.write_event_config = &tsl2x7x_write_interrupt_config,
 	},
 	[PRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
@@ -1683,10 +1683,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value_new = &tsl2x7x_read_thresh,
-		.write_event_value_new = &tsl2x7x_write_thresh,
-		.read_event_config_new = &tsl2x7x_read_interrupt_config,
-		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+		.read_event_value = &tsl2x7x_read_thresh,
+		.write_event_value = &tsl2x7x_write_thresh,
+		.read_event_config = &tsl2x7x_read_interrupt_config,
+		.write_event_config = &tsl2x7x_write_interrupt_config,
 	},
 	[ALSPRX] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
@@ -1694,10 +1694,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value_new = &tsl2x7x_read_thresh,
-		.write_event_value_new = &tsl2x7x_write_thresh,
-		.read_event_config_new = &tsl2x7x_read_interrupt_config,
-		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+		.read_event_value = &tsl2x7x_read_thresh,
+		.write_event_value = &tsl2x7x_write_thresh,
+		.read_event_config = &tsl2x7x_read_interrupt_config,
+		.write_event_config = &tsl2x7x_write_interrupt_config,
 	},
 	[PRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
@@ -1705,10 +1705,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value_new = &tsl2x7x_read_thresh,
-		.write_event_value_new = &tsl2x7x_write_thresh,
-		.read_event_config_new = &tsl2x7x_read_interrupt_config,
-		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+		.read_event_value = &tsl2x7x_read_thresh,
+		.write_event_value = &tsl2x7x_write_thresh,
+		.read_event_config = &tsl2x7x_read_interrupt_config,
+		.write_event_config = &tsl2x7x_write_interrupt_config,
 	},
 	[ALSPRX2] = {
 		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
@@ -1716,10 +1716,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
 		.driver_module = THIS_MODULE,
 		.read_raw = &tsl2x7x_read_raw,
 		.write_raw = &tsl2x7x_write_raw,
-		.read_event_value_new = &tsl2x7x_read_thresh,
-		.write_event_value_new = &tsl2x7x_write_thresh,
-		.read_event_config_new = &tsl2x7x_read_interrupt_config,
-		.write_event_config_new = &tsl2x7x_write_interrupt_config,
+		.read_event_value = &tsl2x7x_read_thresh,
+		.write_event_value = &tsl2x7x_write_thresh,
+		.read_event_config = &tsl2x7x_read_interrupt_config,
+		.write_event_config = &tsl2x7x_write_interrupt_config,
 	},
 };
 
diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
index 5dab2c4..8bbd7bc 100644
--- a/include/linux/iio/events.h
+++ b/include/linux/iio/events.h
@@ -46,10 +46,6 @@ struct iio_event_data {
 	 ((u16)chan))
 
 
-#define IIO_EV_DIR_MAX 4
-#define IIO_EV_BIT(type, direction)			\
-	(1 << (type*IIO_EV_DIR_MAX + direction))
-
 /**
  * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
  * @chan_type:	Type of the channel. Should be one of enum iio_chan_type.
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 5a9fefe..2b783df 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -185,7 +185,6 @@ struct iio_event_spec {
  *			by all channels of the same direction.
  * @info_mask_shared_by_all: What information is to be exported that is shared
  *			by all channels.
- * @event_mask:		What events can this channel produce.
  * @event_spec:		Array of events which should be registered for this
  *			channel.
  * @num_event_specs:	Size of the event_spec array.
@@ -226,7 +225,6 @@ struct iio_chan_spec {
 	long			info_mask_shared_by_type;
 	long			info_mask_shared_by_dir;
 	long			info_mask_shared_by_all;
-	long			event_mask;
 	const struct iio_event_spec *event_spec;
 	unsigned int		num_event_specs;
 	const struct iio_chan_spec_ext_info *ext_info;
@@ -307,16 +305,8 @@ struct iio_dev;
  *			returns IIO_VAL_INT_PLUS_MICRO.
  * @read_event_config:	find out if the event is enabled.
  * @write_event_config:	set if the event is enabled.
- * @read_event_value:	read a value associated with the event. Meaning
- *			is event dependant. event_code specifies which event.
- * @write_event_value:	write the value associated with the event.
- *			Meaning is event dependent.
- * @read_event_config_new: find out if the event is enabled. New style interface.
- * @write_event_config_new: set if the event is enabled. New style interface.
- * @read_event_value_new: read a configuration value associated with the event.
- *                         New style interface.
- * @write_event_value_new: write a configuration value for the event. New style
- *			   interface.
+ * @read_event_value:	read a configuration value associated with the event.
+ * @write_event_value:	write a configuration value for the event.
  * @validate_trigger:	function to validate the trigger when the
  *			current trigger gets changed.
  * @update_scan_mode:	function to configure device and scan buffer when
@@ -345,37 +335,23 @@ struct iio_info {
 			 long mask);
 
 	int (*read_event_config)(struct iio_dev *indio_dev,
-				 u64 event_code);
-
-	int (*write_event_config)(struct iio_dev *indio_dev,
-				  u64 event_code,
-				  int state);
-
-	int (*read_event_value)(struct iio_dev *indio_dev,
-				u64 event_code,
-				int *val);
-	int (*write_event_value)(struct iio_dev *indio_dev,
-				 u64 event_code,
-				 int val);
-
-	int (*read_event_config_new)(struct iio_dev *indio_dev,
 				 const struct iio_chan_spec *chan,
 				 enum iio_event_type type,
 				 enum iio_event_direction dir);
 
-	int (*write_event_config_new)(struct iio_dev *indio_dev,
+	int (*write_event_config)(struct iio_dev *indio_dev,
 				  const struct iio_chan_spec *chan,
 				  enum iio_event_type type,
 				  enum iio_event_direction dir,
 				  int state);
 
-	int (*read_event_value_new)(struct iio_dev *indio_dev,
+	int (*read_event_value)(struct iio_dev *indio_dev,
 				const struct iio_chan_spec *chan,
 				enum iio_event_type type,
 				enum iio_event_direction dir,
 				enum iio_event_info info, int *val);
 
-	int (*write_event_value_new)(struct iio_dev *indio_dev,
+	int (*write_event_value)(struct iio_dev *indio_dev,
 				 const struct iio_chan_spec *chan,
 				 enum iio_event_type type,
 				 enum iio_event_direction dir,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 15/18] iio: Add a hysteresis event info attribute
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (12 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 14/18] iio: Remove support for the legacy " Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 16/18] staging:iio:ad799x: Simplify threshold register look-up Lars-Peter Clausen
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

For some devices it is possible to configure a hysteresis for threshold (or
similar) events. This patch adds a new hysteresis event info type which allows
for easy creation and read/write handling of the sysfs attribute.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 Documentation/ABI/testing/sysfs-bus-iio | 56 +++++++++++++++++++++++++++++++++
 drivers/iio/industrialio-event.c        |  1 +
 include/linux/iio/types.h               |  1 +
 3 files changed, 58 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index ab1047c..bdc6f3b 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -537,6 +537,62 @@ Description:
 		value is in raw device units or in processed units (as _raw
 		and _input do on sysfs direct channel read attributes).
 
+What:		/sys/.../events/in_accel_x_thresh_rising_hysteresis
+What:		/sys/.../events/in_accel_x_thresh_falling_hysteresis
+What:		/sys/.../events/in_accel_x_thresh_hysteresis
+What:		/sys/.../events/in_accel_y_thresh_rising_hysteresis
+What:		/sys/.../events/in_accel_y_thresh_falling_hysteresis
+What:		/sys/.../events/in_accel_y_thresh_hysteresis
+What:		/sys/.../events/in_accel_z_thresh_rising_hysteresis
+What:		/sys/.../events/in_accel_z_thresh_falling_hysteresis
+What:		/sys/.../events/in_accel_z_thresh_hysteresis
+What:		/sys/.../events/in_anglvel_x_thresh_rising_hysteresis
+What:		/sys/.../events/in_anglvel_x_thresh_falling_hysteresis
+What:		/sys/.../events/in_anglvel_x_thresh_hysteresis
+What:		/sys/.../events/in_anglvel_y_thresh_rising_hysteresis
+What:		/sys/.../events/in_anglvel_y_thresh_falling_hysteresis
+What:		/sys/.../events/in_anglvel_y_thresh_hysteresis
+What:		/sys/.../events/in_anglvel_z_thresh_rising_hysteresis
+What:		/sys/.../events/in_anglvel_z_thresh_falling_hysteresis
+What:		/sys/.../events/in_anglvel_z_thresh_hysteresis
+What:		/sys/.../events/in_magn_x_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_x_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_x_thresh_hysteresis
+What:		/sys/.../events/in_magn_y_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_y_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_y_thresh_hysteresis
+What:		/sys/.../events/in_magn_z_thresh_rising_hysteresis
+What:		/sys/.../events/in_magn_z_thresh_falling_hysteresis
+What:		/sys/.../events/in_magn_z_thresh_hysteresis
+What:		/sys/.../events/in_voltageY_thresh_rising_hysteresis
+What:		/sys/.../events/in_voltageY_thresh_falling_hysteresis
+What:		/sys/.../events/in_voltageY_thresh_hysteresis
+What:		/sys/.../events/in_tempY_thresh_rising_hysteresis
+What:		/sys/.../events/in_tempY_thresh_falling_hysteresis
+What:		/sys/.../events/in_tempY_thresh_hysteresis
+What:		/sys/.../events/in_illuminance0_thresh_falling_hysteresis
+what:		/sys/.../events/in_illuminance0_thresh_rising_hysteresis
+what:		/sys/.../events/in_illuminance0_thresh_hysteresis
+what:		/sys/.../events/in_proximity0_thresh_falling_hysteresis
+what:		/sys/.../events/in_proximity0_thresh_rising_hysteresis
+what:		/sys/.../events/in_proximity0_thresh_hysteresis
+KernelVersion:	3.13
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Specifies the hysteresis of threshold that the device is comparing
+		against for the events enabled by
+		<type>Y[_name]_thresh[_(rising|falling)]_hysteresis.
+		If separate attributes exist for the two directions, but
+		direction is not specified for this attribute, then a single
+		hysteresis value applies to both directions.
+		For falling events the hysteresis is added to the _value attribute for
+		this event to get the upper threshold for when the event goes back to
+		normal, for rising events the hysteresis is subtracted from the _value
+		attribute. E.g. if in_voltage0_raw_thresh_rising_value is set to 1200
+		and in_voltage0_raw_thresh_rising_hysteresis is set to 50. The event
+		will get activated once in_voltage0_raw goes above 1200 and will become
+		deactived again once the value falls below 1150.
+
 What:		/sys/.../events/in_accel_x_raw_roc_rising_value
 What:		/sys/.../events/in_accel_x_raw_roc_falling_value
 What:		/sys/.../events/in_accel_y_raw_roc_rising_value
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index f4fa690..a3bf5bb 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -185,6 +185,7 @@ static const char * const iio_ev_dir_text[] = {
 static const char * const iio_ev_info_text[] = {
 	[IIO_EV_INFO_ENABLE] = "en",
 	[IIO_EV_INFO_VALUE] = "value",
+	[IIO_EV_INFO_HYSTERESIS] = "hysteresis",
 };
 
 static enum iio_event_direction iio_ev_attr_dir(struct iio_dev_attr *attr)
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 18339ef..4ac928e 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -65,6 +65,7 @@ enum iio_event_type {
 enum iio_event_info {
 	IIO_EV_INFO_ENABLE,
 	IIO_EV_INFO_VALUE,
+	IIO_EV_INFO_HYSTERESIS,
 };
 
 enum iio_event_direction {
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 16/18] staging:iio:ad799x: Simplify threshold register look-up
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (13 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 15/18] iio: Add a hysteresis event info attribute Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-26 12:58 ` [PATCH 17/18] staging:iio:ad799x: Use event spec for threshold hysteresis Lars-Peter Clausen
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Given a channel number the corresponding threshold and hysteresis registers can
easily be calculated. No need to use a look-up table.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/ad799x.h      | 16 ++++------------
 drivers/staging/iio/adc/ad799x_core.c | 34 ++++++++++++++--------------------
 2 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index b51680c..a591aa6 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -36,18 +36,10 @@
 #define AD7998_ALERT_STAT_REG			0x1
 #define AD7998_CONF_REG				0x2
 #define AD7998_CYCLE_TMR_REG			0x3
-#define AD7998_DATALOW_CH1_REG			0x4
-#define AD7998_DATAHIGH_CH1_REG			0x5
-#define AD7998_HYST_CH1_REG			0x6
-#define AD7998_DATALOW_CH2_REG			0x7
-#define AD7998_DATAHIGH_CH2_REG			0x8
-#define AD7998_HYST_CH2_REG			0x9
-#define AD7998_DATALOW_CH3_REG			0xA
-#define AD7998_DATAHIGH_CH3_REG			0xB
-#define AD7998_HYST_CH3_REG			0xC
-#define AD7998_DATALOW_CH4_REG			0xD
-#define AD7998_DATAHIGH_CH4_REG			0xE
-#define AD7998_HYST_CH4_REG			0xF
+
+#define AD7998_DATALOW_REG(x)			((x) * 3 + 0x4)
+#define AD7998_DATAHIGH_REG(x)			((x) * 3 + 0x5)
+#define AD7998_HYST_REG(x)			((x) * 3 + 0x6)
 
 #define AD7998_CYC_MASK				0x7
 #define AD7998_CYC_DIS				0x0
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 73f7604..24e0749 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -261,12 +261,14 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
 	return 1;
 }
 
-static const u8 ad799x_threshold_addresses[][2] = {
-	{ AD7998_DATALOW_CH1_REG, AD7998_DATAHIGH_CH1_REG },
-	{ AD7998_DATALOW_CH2_REG, AD7998_DATAHIGH_CH2_REG },
-	{ AD7998_DATALOW_CH3_REG, AD7998_DATAHIGH_CH3_REG },
-	{ AD7998_DATALOW_CH4_REG, AD7998_DATAHIGH_CH4_REG },
-};
+static int ad799x_threshold_reg(const struct iio_chan_spec *chan,
+					enum iio_event_direction dir)
+{
+	if (dir == IIO_EV_DIR_FALLING)
+		return AD7998_DATALOW_REG(chan->channel);
+	else
+		return AD7998_DATAHIGH_REG(chan->channel);
+}
 
 static int ad799x_write_event_value(struct iio_dev *indio_dev,
 				    const struct iio_chan_spec *chan,
@@ -277,13 +279,9 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
 {
 	int ret;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	int direction = dir == IIO_EV_DIR_FALLING;
-	int number = chan->channel;
 
 	mutex_lock(&indio_dev->mlock);
-	ret = ad799x_i2c_write16(st,
-				 ad799x_threshold_addresses[number][direction],
-				 val);
+	ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir), val);
 	mutex_unlock(&indio_dev->mlock);
 
 	return ret;
@@ -298,14 +296,10 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
 {
 	int ret;
 	struct ad799x_state *st = iio_priv(indio_dev);
-	int direction = dir == IIO_EV_DIR_FALLING;
-	int number = chan->channel;
 	u16 valin;
 
 	mutex_lock(&indio_dev->mlock);
-	ret = ad799x_i2c_read16(st,
-				ad799x_threshold_addresses[number][direction],
-				&valin);
+	ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir), &valin);
 	mutex_unlock(&indio_dev->mlock);
 	if (ret < 0)
 		return ret;
@@ -393,25 +387,25 @@ static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
 		       S_IRUGO | S_IWUSR,
 		       ad799x_read_channel_config,
 		       ad799x_write_channel_config,
-		       AD7998_HYST_CH1_REG);
+		       AD7998_HYST_REG(0));
 
 static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
 		       S_IRUGO | S_IWUSR,
 		       ad799x_read_channel_config,
 		       ad799x_write_channel_config,
-		       AD7998_HYST_CH2_REG);
+		       AD7998_HYST_REG(1));
 
 static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
 		       S_IRUGO | S_IWUSR,
 		       ad799x_read_channel_config,
 		       ad799x_write_channel_config,
-		       AD7998_HYST_CH3_REG);
+		       AD7998_HYST_REG(2));
 
 static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
 		       S_IRUGO | S_IWUSR,
 		       ad799x_read_channel_config,
 		       ad799x_write_channel_config,
-		       AD7998_HYST_CH4_REG);
+		       AD7998_HYST_REG(3));
 
 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
 			      ad799x_read_frequency,
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 17/18] staging:iio:ad799x: Use event spec for threshold hysteresis
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (14 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 16/18] staging:iio:ad799x: Simplify threshold register look-up Lars-Peter Clausen
@ 2013-09-26 12:58 ` 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
  17 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Register the event threshold hysteresis attributes by using the new
IIO_EV_INFO_HYSTERESIS event spec type. This allows us to throw away a good
portion of boiler-plate code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/ad799x_core.c | 132 ++++++++--------------------------
 1 file changed, 29 insertions(+), 103 deletions(-)

diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 24e0749..05641f0 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -261,13 +261,23 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
 	return 1;
 }
 
-static int ad799x_threshold_reg(const struct iio_chan_spec *chan,
-					enum iio_event_direction dir)
+static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
+					 enum iio_event_direction dir,
+					 enum iio_event_info info)
 {
-	if (dir == IIO_EV_DIR_FALLING)
-		return AD7998_DATALOW_REG(chan->channel);
-	else
-		return AD7998_DATAHIGH_REG(chan->channel);
+	switch (info) {
+	case IIO_EV_INFO_VALUE:
+		if (dir == IIO_EV_DIR_FALLING)
+			return AD7998_DATALOW_REG(chan->channel);
+		else
+			return AD7998_DATAHIGH_REG(chan->channel);
+	case IIO_EV_INFO_HYSTERESIS:
+		return AD7998_HYST_REG(chan->channel);
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static int ad799x_write_event_value(struct iio_dev *indio_dev,
@@ -281,7 +291,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
 	struct ad799x_state *st = iio_priv(indio_dev);
 
 	mutex_lock(&indio_dev->mlock);
-	ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir), val);
+	ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
+		val);
 	mutex_unlock(&indio_dev->mlock);
 
 	return ret;
@@ -299,7 +310,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
 	u16 valin;
 
 	mutex_lock(&indio_dev->mlock);
-	ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir), &valin);
+	ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
+		&valin);
 	mutex_unlock(&indio_dev->mlock);
 	if (ret < 0)
 		return ret;
@@ -308,46 +320,6 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
 	return 0;
 }
 
-static ssize_t ad799x_read_channel_config(struct device *dev,
-					struct device_attribute *attr,
-					char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad799x_state *st = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-
-	int ret;
-	u16 val;
-	ret = ad799x_i2c_read16(st, this_attr->address, &val);
-	if (ret)
-		return ret;
-
-	return sprintf(buf, "%d\n", val);
-}
-
-static ssize_t ad799x_write_channel_config(struct device *dev,
-					 struct device_attribute *attr,
-					 const char *buf,
-					 size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad799x_state *st = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-
-	long val;
-	int ret;
-
-	ret = kstrtol(buf, 10, &val);
-	if (ret)
-		return ret;
-
-	mutex_lock(&indio_dev->mlock);
-	ret = ad799x_i2c_write16(st, this_attr->address, val);
-	mutex_unlock(&indio_dev->mlock);
-
-	return ret ? ret : len;
-}
-
 static irqreturn_t ad799x_event_handler(int irq, void *private)
 {
 	struct iio_dev *indio_dev = private;
@@ -383,60 +355,19 @@ done:
 	return IRQ_HANDLED;
 }
 
-static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad799x_read_channel_config,
-		       ad799x_write_channel_config,
-		       AD7998_HYST_REG(0));
-
-static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad799x_read_channel_config,
-		       ad799x_write_channel_config,
-		       AD7998_HYST_REG(1));
-
-static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad799x_read_channel_config,
-		       ad799x_write_channel_config,
-		       AD7998_HYST_REG(2));
-
-static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad799x_read_channel_config,
-		       ad799x_write_channel_config,
-		       AD7998_HYST_REG(3));
-
 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
 			      ad799x_read_frequency,
 			      ad799x_write_frequency);
 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
 
-static struct attribute *ad7993_4_7_8_event_attributes[] = {
-	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_sampling_frequency.dev_attr.attr,
-	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
-	NULL,
-};
-
-static struct attribute_group ad7993_4_7_8_event_attrs_group = {
-	.attrs = ad7993_4_7_8_event_attributes,
-	.name = "events",
-};
-
-static struct attribute *ad7992_event_attributes[] = {
-	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
+static struct attribute *ad799x_event_attributes[] = {
 	&iio_dev_attr_sampling_frequency.dev_attr.attr,
 	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
 	NULL,
 };
 
-static struct attribute_group ad7992_event_attrs_group = {
-	.attrs = ad7992_event_attributes,
+static struct attribute_group ad799x_event_attrs_group = {
+	.attrs = ad799x_event_attributes,
 	.name = "events",
 };
 
@@ -445,18 +376,9 @@ static const struct iio_info ad7991_info = {
 	.driver_module = THIS_MODULE,
 };
 
-static const struct iio_info ad7992_info = {
-	.read_raw = &ad799x_read_raw,
-	.event_attrs = &ad7992_event_attrs_group,
-	.read_event_config = &ad799x_read_event_config,
-	.read_event_value = &ad799x_read_event_value,
-	.write_event_value = &ad799x_write_event_value,
-	.driver_module = THIS_MODULE,
-};
-
 static const struct iio_info ad7993_4_7_8_info = {
 	.read_raw = &ad799x_read_raw,
-	.event_attrs = &ad7993_4_7_8_event_attrs_group,
+	.event_attrs = &ad799x_event_attrs_group,
 	.read_event_config = &ad799x_read_event_config,
 	.read_event_value = &ad799x_read_event_value,
 	.write_event_value = &ad799x_write_event_value,
@@ -475,6 +397,10 @@ static const struct iio_event_spec ad799x_events[] = {
 		.dir = IIO_EV_DIR_FALLING,
 		.mask_separate = BIT(IIO_EV_INFO_VALUE),
 			BIT(IIO_EV_INFO_ENABLE),
+	}, {
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_EITHER,
+		.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
 	},
 };
 
@@ -539,7 +465,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
 		},
 		.num_channels = 3,
 		.default_config = AD7998_ALERT_EN,
-		.info = &ad7992_info,
+		.info = &ad7993_4_7_8_info,
 	},
 	[ad7993] = {
 		.channel = {
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 18/18] staging:iio:ad7291: Use event spec for threshold hysteresis
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (15 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 17/18] staging:iio:ad799x: Use event spec for threshold hysteresis Lars-Peter Clausen
@ 2013-09-26 12:58 ` Lars-Peter Clausen
  2013-09-29 18:44 ` [PATCH 01/18] iio: Extend the event config interface Jonathan Cameron
  17 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-26 12:58 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Register the event threshold hysteresis attributes by using the new
IIO_EV_INFO_HYSTERESIS event spec type. This allows us to throw away a good
portion of boiler-plate code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/ad7291.c | 138 ++++++++-------------------------------
 1 file changed, 27 insertions(+), 111 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index dcd24ab..6fac246 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -164,92 +164,8 @@ static irqreturn_t ad7291_event_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
-static inline ssize_t ad7291_show_hyst(struct device *dev,
-		struct device_attribute *attr,
-		char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad7291_chip_info *chip = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u16 data;
-	int ret;
-
-	ret = ad7291_i2c_read(chip, this_attr->address, &data);
-	if (ret < 0)
-		return ret;
-
-	return sprintf(buf, "%d\n", data & AD7291_VALUE_MASK);
-}
-
-static inline ssize_t ad7291_set_hyst(struct device *dev,
-				      struct device_attribute *attr,
-				      const char *buf,
-				      size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad7291_chip_info *chip = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u16 data;
-	int ret;
-
-	ret = kstrtou16(buf, 10, &data);
-
-	if (ret < 0)
-		return ret;
-	if (data > AD7291_VALUE_MASK)
-		return -EINVAL;
-
-	ret = ad7291_i2c_write(chip, this_attr->address, data);
-	if (ret < 0)
-		return ret;
-
-	return len;
-}
-
-static IIO_DEVICE_ATTR(in_temp0_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst,
-		       AD7291_HYST(8));
-static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(0));
-static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(1));
-static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(2));
-static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(3));
-static IIO_DEVICE_ATTR(in_voltage4_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(4));
-static IIO_DEVICE_ATTR(in_voltage5_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(5));
-static IIO_DEVICE_ATTR(in_voltage6_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(6));
-static IIO_DEVICE_ATTR(in_voltage7_thresh_both_hyst_raw,
-		       S_IRUGO | S_IWUSR,
-		       ad7291_show_hyst, ad7291_set_hyst, AD7291_HYST(7));
-
-static struct attribute *ad7291_event_attributes[] = {
-	&iio_dev_attr_in_temp0_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage4_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage5_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage6_thresh_both_hyst_raw.dev_attr.attr,
-	&iio_dev_attr_in_voltage7_thresh_both_hyst_raw.dev_attr.attr,
-	NULL,
-};
-
 static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
-	enum iio_event_direction dir)
+	enum iio_event_direction dir, enum iio_event_info info)
 {
 	unsigned int offset;
 
@@ -264,10 +180,18 @@ static unsigned int ad7291_threshold_reg(const struct iio_chan_spec *chan,
 	    return 0;
 	}
 
-	if (dir == IIO_EV_DIR_FALLING)
-		return AD7291_DATA_LOW(offset);
-	else
-		return AD7291_DATA_HIGH(offset);
+	switch (info) {
+	case IIO_EV_INFO_VALUE:
+			if (dir == IIO_EV_DIR_FALLING)
+					return AD7291_DATA_HIGH(offset);
+			else
+					return AD7291_DATA_LOW(offset);
+	case IIO_EV_INFO_HYSTERESIS:
+			return AD7291_HYST(offset);
+	default:
+			break;
+	}
+	return 0;
 }
 
 static int ad7291_read_event_value(struct iio_dev *indio_dev,
@@ -281,20 +205,17 @@ static int ad7291_read_event_value(struct iio_dev *indio_dev,
 	int ret;
 	u16 uval;
 
-	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir), &uval);
+	ret = ad7291_i2c_read(chip, ad7291_threshold_reg(chan, dir, info),
+		&uval);
 	if (ret < 0)
 		return ret;
 
-	switch (chan->type) {
-	case IIO_VOLTAGE:
+	if (info == IIO_EV_INFO_HYSTERESIS || chan->type == IIO_VOLTAGE)
 		*val = uval & AD7291_VALUE_MASK;
-		return 0;
-	case IIO_TEMP:
+	else
 		*val = sign_extend32(uval, 11);
-		return 0;
-	default:
-		return -EINVAL;
-	};
+
+	return 0;
 }
 
 static int ad7291_write_event_value(struct iio_dev *indio_dev,
@@ -306,20 +227,16 @@ static int ad7291_write_event_value(struct iio_dev *indio_dev,
 {
 	struct ad7291_chip_info *chip = iio_priv(indio_dev);
 
-	switch (chan->type) {
-	case IIO_VOLTAGE:
+	if (info == IIO_EV_INFO_HYSTERESIS || chan->type == IIO_VOLTAGE) {
 		if (val > AD7291_VALUE_MASK || val < 0)
 			return -EINVAL;
-		break;
-	case IIO_TEMP:
+	} else {
 		if (val > 2047 || val < -2048)
 			return -EINVAL;
-		break;
-	default:
-		return -EINVAL;
 	}
 
-	return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir), val);
+	return ad7291_i2c_write(chip, ad7291_threshold_reg(chan, dir, info),
+		val);
 }
 
 static int ad7291_read_event_config(struct iio_dev *indio_dev,
@@ -493,6 +410,10 @@ static const struct iio_event_spec ad7291_events[] = {
 		.dir = IIO_EV_DIR_FALLING,
 		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
 			BIT(IIO_EV_INFO_ENABLE),
+	}, {
+		.type = IIO_EV_TYPE_THRESH,
+		.dir = IIO_EV_DIR_EITHER,
+		.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
 	},
 };
 
@@ -528,17 +449,12 @@ static const struct iio_chan_spec ad7291_channels[] = {
 	}
 };
 
-static struct attribute_group ad7291_event_attribute_group = {
-	.attrs = ad7291_event_attributes,
-};
-
 static const struct iio_info ad7291_info = {
 	.read_raw = &ad7291_read_raw,
 	.read_event_config = &ad7291_read_event_config,
 	.write_event_config = &ad7291_write_event_config,
 	.read_event_value = &ad7291_read_event_value,
 	.write_event_value = &ad7291_write_event_value,
-	.event_attrs = &ad7291_event_attribute_group,
 	.driver_module = THIS_MODULE,
 };
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  2013-09-26 12:58 [PATCH 01/18] iio: Extend the event config interface Lars-Peter Clausen
                   ` (16 preceding siblings ...)
  2013-09-26 12:58 ` [PATCH 18/18] staging:iio:ad7291: " Lars-Peter Clausen
@ 2013-09-29 18:44 ` Jonathan Cameron
  2013-09-29 18:56   ` Lars-Peter Clausen
  17 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-29 18:44 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/26/13 13:58, Lars-Peter Clausen wrote:
> The event configuration interface of the IIO framework has not been getting the
> same attention as other parts. As a result it has not seen the same improvements
> as e.g. the channel interface has seen with the introduction of the channel spec
> struct. Currently all the event config callbacks take a u64 (the so called event
> code) to pass all the different information about for which event the callback
> is invoked. The callback function then has to extract the information it is
> interested in using some macros with rather long names. Most information encoded
> in the event code comes straight from the iio_chan_spec struct the event was
> registered for. Since we always have a handle to the channel spec when we call
> the event callbacks the first step is to add the channel spec as a parameter to
> the event callbacks. The two remaining things encoded in the event code are the
> type and direction of the event. Instead of passing them in one parameter, add
> one parameter for each of them and remove the eventcode from the event
> callbacks. The patch also adds a new iio_event_info parameter to the
> {read,write}_event_value callbacks. This makes it possible, similar to the
> iio_chan_info_enum for channels, to specify additional properties other than
> just the value for an event. Furthermore the new interface will allow to
> register shared events. This is e.g. useful if a device allows configuring a
> threshold event, but the threshold setting is the same for all channels.
>
> To implement this the patch adds a new iio_event_spec struct which is similar to
> the iio_chan_spec struct. It as two field to specify the type and the direction
> of the event. Furthermore it has a mask field for each one of the different
> iio_shared_by types. These mask fields holds which kind of attributes should be
> registered for the event. Creation of the attributes follows the same rules as
> the for the channel attributes. E.g. for the separate_mask there will be a
> attribute for each channel with this event, for the shared_by_type there will
> only be one attribute per channel type. The iio_chan_spec struct gets two new
> fields, 'event_spec' and 'num_event_specs', which is used to specify which the
> events for this channel. These two fields are going to replace the channel's
> event_mask field.
>
> For now both the old and the new event config interface coexist, but over the
> few patches all drivers will be converted from the old to the new interface.
> Once that is done all code for supporting the old interface will be removed.
>

A nice bit of work.

Only one thing really came to mind. Is it worth us adding another field to the
struct iio_device_attribute to avoid the dance to cram the event index and the
offset into the one value?  If we want to avoid adding memory usage, small though
it would be, perhaps drop an appropriate union in there to make this code easier
to follow?  Obviously the attribute creation functions might get fiddlier though.

Although it would cause a fair bit of churn to change it, the name of 'address'
in there is rather misleading now as it very rarely actually contains an address!

One trivial naming question otherwise.

...
> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
> +static int iio_device_add_event(struct iio_dev *indio_dev,
> +	const struct iio_chan_spec *chan, unsigned int spec_offset,
spec_offset vs spec_index?
Unless some fairly nefarous games are played in a driver, this value
will always be an index into an array.  Offset made me wonder, wrt to
which base position...
> +	enum iio_event_type type, enum iio_event_direction dir,
> +	enum iio_shared_by shared_by, const unsigned long *mask)
> +{
> +	ssize_t (*show)(struct device *, struct device_attribute *, char *);
...

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  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
  0 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-29 18:56 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 09/29/2013 08:44 PM, Jonathan Cameron wrote:
> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>> The event configuration interface of the IIO framework has not been getting the
>> same attention as other parts. As a result it has not seen the same improvements
>> as e.g. the channel interface has seen with the introduction of the channel spec
>> struct. Currently all the event config callbacks take a u64 (the so called event
>> code) to pass all the different information about for which event the callback
>> is invoked. The callback function then has to extract the information it is
>> interested in using some macros with rather long names. Most information encoded
>> in the event code comes straight from the iio_chan_spec struct the event was
>> registered for. Since we always have a handle to the channel spec when we call
>> the event callbacks the first step is to add the channel spec as a parameter to
>> the event callbacks. The two remaining things encoded in the event code are the
>> type and direction of the event. Instead of passing them in one parameter, add
>> one parameter for each of them and remove the eventcode from the event
>> callbacks. The patch also adds a new iio_event_info parameter to the
>> {read,write}_event_value callbacks. This makes it possible, similar to the
>> iio_chan_info_enum for channels, to specify additional properties other than
>> just the value for an event. Furthermore the new interface will allow to
>> register shared events. This is e.g. useful if a device allows configuring a
>> threshold event, but the threshold setting is the same for all channels.
>>
>> To implement this the patch adds a new iio_event_spec struct which is similar to
>> the iio_chan_spec struct. It as two field to specify the type and the direction
>> of the event. Furthermore it has a mask field for each one of the different
>> iio_shared_by types. These mask fields holds which kind of attributes should be
>> registered for the event. Creation of the attributes follows the same rules as
>> the for the channel attributes. E.g. for the separate_mask there will be a
>> attribute for each channel with this event, for the shared_by_type there will
>> only be one attribute per channel type. The iio_chan_spec struct gets two new
>> fields, 'event_spec' and 'num_event_specs', which is used to specify which the
>> events for this channel. These two fields are going to replace the channel's
>> event_mask field.
>>
>> For now both the old and the new event config interface coexist, but over the
>> few patches all drivers will be converted from the old to the new interface.
>> Once that is done all code for supporting the old interface will be removed.
>>
> 
> A nice bit of work.
> 
> Only one thing really came to mind. Is it worth us adding another field to the
> struct iio_device_attribute to avoid the dance to cram the event index and the
> offset into the one value?  If we want to avoid adding memory usage, small though
> it would be, perhaps drop an appropriate union in there to make this code easier
> to follow?  Obviously the attribute creation functions might get fiddlier though.
> 
> Although it would cause a fair bit of churn to change it, the name of 'address'
> in there is rather misleading now as it very rarely actually contains an address!
> 

I think a transparent union should work nicely and doesn't cause any code
churn. Maybe even with a direct pointer to the event_spec.

Something like:

struct iio_dev_attr {
	...
	union {
		u64 address;
		struct {
			struct iio_event_spec *spec;
			enum iio_event_info info;
		} event;
	};
	...
};


> One trivial naming question otherwise.
> 
> ...
>> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>> +static int iio_device_add_event(struct iio_dev *indio_dev,
>> +	const struct iio_chan_spec *chan, unsigned int spec_offset,
> spec_offset vs spec_index?
> Unless some fairly nefarous games are played in a driver, this value
> will always be an index into an array.  Offset made me wonder, wrt to
> which base position...

spec_index is fine as well.

>> +	enum iio_event_type type, enum iio_event_direction dir,
>> +	enum iio_shared_by shared_by, const unsigned long *mask)
>> +{
>> +	ssize_t (*show)(struct device *, struct device_attribute *, char *);
> ...
> 

Thanks for the review,
- Lars

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  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
  1 sibling, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-09-29 19:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 09/29/2013 10:17 PM, Jonathan Cameron wrote:
> On 09/29/13 19:56, Lars-Peter Clausen wrote:
>> On 09/29/2013 08:44 PM, Jonathan Cameron wrote:
>>> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>>>> The event configuration interface of the IIO framework has not been getting the
>>>> same attention as other parts. As a result it has not seen the same improvements
>>>> as e.g. the channel interface has seen with the introduction of the channel spec
>>>> struct. Currently all the event config callbacks take a u64 (the so called event
>>>> code) to pass all the different information about for which event the callback
>>>> is invoked. The callback function then has to extract the information it is
>>>> interested in using some macros with rather long names. Most information encoded
>>>> in the event code comes straight from the iio_chan_spec struct the event was
>>>> registered for. Since we always have a handle to the channel spec when we call
>>>> the event callbacks the first step is to add the channel spec as a parameter to
>>>> the event callbacks. The two remaining things encoded in the event code are the
>>>> type and direction of the event. Instead of passing them in one parameter, add
>>>> one parameter for each of them and remove the eventcode from the event
>>>> callbacks. The patch also adds a new iio_event_info parameter to the
>>>> {read,write}_event_value callbacks. This makes it possible, similar to the
>>>> iio_chan_info_enum for channels, to specify additional properties other than
>>>> just the value for an event. Furthermore the new interface will allow to
>>>> register shared events. This is e.g. useful if a device allows configuring a
>>>> threshold event, but the threshold setting is the same for all channels.
>>>>
>>>> To implement this the patch adds a new iio_event_spec struct which is similar to
>>>> the iio_chan_spec struct. It as two field to specify the type and the direction
>>>> of the event. Furthermore it has a mask field for each one of the different
>>>> iio_shared_by types. These mask fields holds which kind of attributes should be
>>>> registered for the event. Creation of the attributes follows the same rules as
>>>> the for the channel attributes. E.g. for the separate_mask there will be a
>>>> attribute for each channel with this event, for the shared_by_type there will
>>>> only be one attribute per channel type. The iio_chan_spec struct gets two new
>>>> fields, 'event_spec' and 'num_event_specs', which is used to specify which the
>>>> events for this channel. These two fields are going to replace the channel's
>>>> event_mask field.
>>>>
>>>> For now both the old and the new event config interface coexist, but over the
>>>> few patches all drivers will be converted from the old to the new interface.
>>>> Once that is done all code for supporting the old interface will be removed.
>>>>
>>>
>>> A nice bit of work.
>>>
>>> Only one thing really came to mind. Is it worth us adding another field to the
>>> struct iio_device_attribute to avoid the dance to cram the event index and the
>>> offset into the one value?  If we want to avoid adding memory usage, small though
>>> it would be, perhaps drop an appropriate union in there to make this code easier
>>> to follow?  Obviously the attribute creation functions might get fiddlier though.
>>>
>>> Although it would cause a fair bit of churn to change it, the name of 'address'
>>> in there is rather misleading now as it very rarely actually contains an address!
>>>
>>
>> I think a transparent union should work nicely and doesn't cause any code
>> churn. Maybe even with a direct pointer to the event_spec.
>>
>> Something like:
>>
>> struct iio_dev_attr {
>> 	...
>> 	union {
>> 		u64 address;
>> 		struct {
>> 			struct iio_event_spec *spec;
>> 			enum iio_event_info info;
>> 		} event;
>> 	};
>> 	...
>> };
> Looks good to me.
> 

Ok, reset of the series looks good as well?

>>
>>
>>> One trivial naming question otherwise.
>>>
>>> ...
>>>> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>>>> +static int iio_device_add_event(struct iio_dev *indio_dev,
>>>> +	const struct iio_chan_spec *chan, unsigned int spec_offset,
>>> spec_offset vs spec_index?
>>> Unless some fairly nefarous games are played in a driver, this value
>>> will always be an index into an array.  Offset made me wonder, wrt to
>>> which base position...
>>
>> spec_index is fine as well.
>>
>>>> +	enum iio_event_type type, enum iio_event_direction dir,
>>>> +	enum iio_shared_by shared_by, const unsigned long *mask)
>>>> +{
>>>> +	ssize_t (*show)(struct device *, struct device_attribute *, char *);
>>> ...
>>>
>>
>> Thanks for the review,
>> - Lars
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  2013-09-29 18:56   ` Lars-Peter Clausen
@ 2013-09-29 20:17     ` Jonathan Cameron
  2013-09-29 19:35       ` Lars-Peter Clausen
  2013-10-04  8:38       ` Lars-Peter Clausen
  0 siblings, 2 replies; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-29 20:17 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/29/13 19:56, Lars-Peter Clausen wrote:
> On 09/29/2013 08:44 PM, Jonathan Cameron wrote:
>> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>>> The event configuration interface of the IIO framework has not been getting the
>>> same attention as other parts. As a result it has not seen the same improvements
>>> as e.g. the channel interface has seen with the introduction of the channel spec
>>> struct. Currently all the event config callbacks take a u64 (the so called event
>>> code) to pass all the different information about for which event the callback
>>> is invoked. The callback function then has to extract the information it is
>>> interested in using some macros with rather long names. Most information encoded
>>> in the event code comes straight from the iio_chan_spec struct the event was
>>> registered for. Since we always have a handle to the channel spec when we call
>>> the event callbacks the first step is to add the channel spec as a parameter to
>>> the event callbacks. The two remaining things encoded in the event code are the
>>> type and direction of the event. Instead of passing them in one parameter, add
>>> one parameter for each of them and remove the eventcode from the event
>>> callbacks. The patch also adds a new iio_event_info parameter to the
>>> {read,write}_event_value callbacks. This makes it possible, similar to the
>>> iio_chan_info_enum for channels, to specify additional properties other than
>>> just the value for an event. Furthermore the new interface will allow to
>>> register shared events. This is e.g. useful if a device allows configuring a
>>> threshold event, but the threshold setting is the same for all channels.
>>>
>>> To implement this the patch adds a new iio_event_spec struct which is similar to
>>> the iio_chan_spec struct. It as two field to specify the type and the direction
>>> of the event. Furthermore it has a mask field for each one of the different
>>> iio_shared_by types. These mask fields holds which kind of attributes should be
>>> registered for the event. Creation of the attributes follows the same rules as
>>> the for the channel attributes. E.g. for the separate_mask there will be a
>>> attribute for each channel with this event, for the shared_by_type there will
>>> only be one attribute per channel type. The iio_chan_spec struct gets two new
>>> fields, 'event_spec' and 'num_event_specs', which is used to specify which the
>>> events for this channel. These two fields are going to replace the channel's
>>> event_mask field.
>>>
>>> For now both the old and the new event config interface coexist, but over the
>>> few patches all drivers will be converted from the old to the new interface.
>>> Once that is done all code for supporting the old interface will be removed.
>>>
>>
>> A nice bit of work.
>>
>> Only one thing really came to mind. Is it worth us adding another field to the
>> struct iio_device_attribute to avoid the dance to cram the event index and the
>> offset into the one value?  If we want to avoid adding memory usage, small though
>> it would be, perhaps drop an appropriate union in there to make this code easier
>> to follow?  Obviously the attribute creation functions might get fiddlier though.
>>
>> Although it would cause a fair bit of churn to change it, the name of 'address'
>> in there is rather misleading now as it very rarely actually contains an address!
>>
> 
> I think a transparent union should work nicely and doesn't cause any code
> churn. Maybe even with a direct pointer to the event_spec.
> 
> Something like:
> 
> struct iio_dev_attr {
> 	...
> 	union {
> 		u64 address;
> 		struct {
> 			struct iio_event_spec *spec;
> 			enum iio_event_info info;
> 		} event;
> 	};
> 	...
> };
Looks good to me.

> 
> 
>> One trivial naming question otherwise.
>>
>> ...
>>> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>>> +static int iio_device_add_event(struct iio_dev *indio_dev,
>>> +	const struct iio_chan_spec *chan, unsigned int spec_offset,
>> spec_offset vs spec_index?
>> Unless some fairly nefarous games are played in a driver, this value
>> will always be an index into an array.  Offset made me wonder, wrt to
>> which base position...
> 
> spec_index is fine as well.
> 
>>> +	enum iio_event_type type, enum iio_event_direction dir,
>>> +	enum iio_shared_by shared_by, const unsigned long *mask)
>>> +{
>>> +	ssize_t (*show)(struct device *, struct device_attribute *, char *);
>> ...
>>
> 
> Thanks for the review,
> - Lars
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  2013-09-29 19:35       ` Lars-Peter Clausen
@ 2013-09-30 20:54         ` Jonathan Cameron
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-30 20:54 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/29/13 20:35, Lars-Peter Clausen wrote:
> On 09/29/2013 10:17 PM, Jonathan Cameron wrote:
>> On 09/29/13 19:56, Lars-Peter Clausen wrote:
>>> On 09/29/2013 08:44 PM, Jonathan Cameron wrote:
>>>> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>>>>> The event configuration interface of the IIO framework has not been getting the
>>>>> same attention as other parts. As a result it has not seen the same improvements
>>>>> as e.g. the channel interface has seen with the introduction of the channel spec
>>>>> struct. Currently all the event config callbacks take a u64 (the so called event
>>>>> code) to pass all the different information about for which event the callback
>>>>> is invoked. The callback function then has to extract the information it is
>>>>> interested in using some macros with rather long names. Most information encoded
>>>>> in the event code comes straight from the iio_chan_spec struct the event was
>>>>> registered for. Since we always have a handle to the channel spec when we call
>>>>> the event callbacks the first step is to add the channel spec as a parameter to
>>>>> the event callbacks. The two remaining things encoded in the event code are the
>>>>> type and direction of the event. Instead of passing them in one parameter, add
>>>>> one parameter for each of them and remove the eventcode from the event
>>>>> callbacks. The patch also adds a new iio_event_info parameter to the
>>>>> {read,write}_event_value callbacks. This makes it possible, similar to the
>>>>> iio_chan_info_enum for channels, to specify additional properties other than
>>>>> just the value for an event. Furthermore the new interface will allow to
>>>>> register shared events. This is e.g. useful if a device allows configuring a
>>>>> threshold event, but the threshold setting is the same for all channels.
>>>>>
>>>>> To implement this the patch adds a new iio_event_spec struct which is similar to
>>>>> the iio_chan_spec struct. It as two field to specify the type and the direction
>>>>> of the event. Furthermore it has a mask field for each one of the different
>>>>> iio_shared_by types. These mask fields holds which kind of attributes should be
>>>>> registered for the event. Creation of the attributes follows the same rules as
>>>>> the for the channel attributes. E.g. for the separate_mask there will be a
>>>>> attribute for each channel with this event, for the shared_by_type there will
>>>>> only be one attribute per channel type. The iio_chan_spec struct gets two new
>>>>> fields, 'event_spec' and 'num_event_specs', which is used to specify which the
>>>>> events for this channel. These two fields are going to replace the channel's
>>>>> event_mask field.
>>>>>
>>>>> For now both the old and the new event config interface coexist, but over the
>>>>> few patches all drivers will be converted from the old to the new interface.
>>>>> Once that is done all code for supporting the old interface will be removed.
>>>>>
>>>>
>>>> A nice bit of work.
>>>>
>>>> Only one thing really came to mind. Is it worth us adding another field to the
>>>> struct iio_device_attribute to avoid the dance to cram the event index and the
>>>> offset into the one value?  If we want to avoid adding memory usage, small though
>>>> it would be, perhaps drop an appropriate union in there to make this code easier
>>>> to follow?  Obviously the attribute creation functions might get fiddlier though.
>>>>
>>>> Although it would cause a fair bit of churn to change it, the name of 'address'
>>>> in there is rather misleading now as it very rarely actually contains an address!
>>>>
>>>
>>> I think a transparent union should work nicely and doesn't cause any code
>>> churn. Maybe even with a direct pointer to the event_spec.
>>>
>>> Something like:
>>>
>>> struct iio_dev_attr {
>>> 	...
>>> 	union {
>>> 		u64 address;
>>> 		struct {
>>> 			struct iio_event_spec *spec;
>>> 			enum iio_event_info info;
>>> 		} event;
>>> 	};
>>> 	...
>>> };
>> Looks good to me.
>>
> 
> Ok, reset of the series looks good as well?
In general yes. Only gotten as far as 7 so far though ;)
The introduction of hystersis is fine as well.

One remaining thought.  Do we want to allow new callbacks to return
the various decimal and fractional types from the start?
Seems likely that at somepoint this will occur.

Note there are some drivers under review that are using the old
eventmask stuff so we may need to hold the removal patch for now,
fix them up and apply that in a few weeks time.

Jonathan
> 
>>>
>>>
>>>> One trivial naming question otherwise.
>>>>
>>>> ...
>>>>> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>>>>> +static int iio_device_add_event(struct iio_dev *indio_dev,
>>>>> +	const struct iio_chan_spec *chan, unsigned int spec_offset,
>>>> spec_offset vs spec_index?
>>>> Unless some fairly nefarous games are played in a driver, this value
>>>> will always be an index into an array.  Offset made me wonder, wrt to
>>>> which base position...
>>>
>>> spec_index is fine as well.
>>>
>>>>> +	enum iio_event_type type, enum iio_event_direction dir,
>>>>> +	enum iio_shared_by shared_by, const unsigned long *mask)
>>>>> +{
>>>>> +	ssize_t (*show)(struct device *, struct device_attribute *, char *);
>>>> ...
>>>>
>>>
>>> Thanks for the review,
>>> - Lars
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 07/18] staging:iio:lis3l02dq: Switch to new event config interface
  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
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-30 20:55 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/26/13 13:58, Lars-Peter Clausen wrote:
> Switch the lis3l02dq 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>
Hi Lars,

As this one is in staging, lets take advantage of the fact that we now
have the ability to have shared elements.  It's an ABI change so I wouldn't
suggest this for drivers outside staging.

The threshold value is shared by all channels (only one address to write) for each
of the two types.


> ---
>  drivers/staging/iio/accel/lis3l02dq_core.c | 53 ++++++++++++++++++++----------
>  1 file changed, 35 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
> index bb852dc..5cd9c45 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_core.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_core.c
> @@ -190,14 +190,20 @@ static u8 lis3l02dq_axis_map[3][3] = {
>  };
>  
>  static int lis3l02dq_read_thresh(struct iio_dev *indio_dev,
> -				 u64 e,
> +				 const struct iio_chan_spec *chan,
> +				 enum iio_event_type type,
> +				 enum iio_event_direction dir,
> +				 enum iio_event_info info,
>  				 int *val)
>  {
>  	return lis3l02dq_read_reg_s16(indio_dev, LIS3L02DQ_REG_THS_L_ADDR, val);
>  }
>  
>  static int lis3l02dq_write_thresh(struct iio_dev *indio_dev,
> -				  u64 event_code,
> +				  const struct iio_chan_spec *chan,
> +				  enum iio_event_type type,
> +				  enum iio_event_direction dir,
> +				  enum iio_event_info info,
>  				  int val)
>  {
>  	u16 value = val;
> @@ -503,9 +509,19 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
>  	return IRQ_HANDLED;
>  }
>  
> -#define LIS3L02DQ_EVENT_MASK					\
> -	(IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |	\
> -	 IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
> +static const struct iio_event_spec lis3l02dq_event[] = {
> +	{
> +		.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),
> +	}
> +};
>  
>  #define LIS3L02DQ_CHAN(index, mod)				\
>  	{							\
> @@ -523,7 +539,8 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
>  			.realbits = 12,				\
>  			.storagebits = 16,			\
>  		},						\
> -		.event_mask = LIS3L02DQ_EVENT_MASK,		\
> +		.event_spec = lis3l02dq_event,			\
> +		.num_event_specs = ARRAY_SIZE(lis3l02dq_event),	\
>  	 }
>  
>  static const struct iio_chan_spec lis3l02dq_channels[] = {
> @@ -535,14 +552,14 @@ static const struct iio_chan_spec lis3l02dq_channels[] = {
>  
>  
>  static int lis3l02dq_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)
>  {
>  
>  	u8 val;
>  	int ret;
> -	u8 mask = (1 << (IIO_EVENT_CODE_EXTRACT_MODIFIER(event_code)*2 +
> -			 (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> -			  IIO_EV_DIR_RISING)));
> +	u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
>  	ret = lis3l02dq_spi_read_reg_8(indio_dev,
>  				       LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
>  				       &val);
> @@ -587,16 +604,16 @@ error_ret:
>  }
>  
>  static int lis3l02dq_write_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,
>  					int state)
>  {
>  	int ret = 0;
>  	u8 val, control;
>  	u8 currentlyset;
>  	bool changed = false;
> -	u8 mask = (1 << (IIO_EVENT_CODE_EXTRACT_MODIFIER(event_code)*2 +
> -			 (IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> -			  IIO_EV_DIR_RISING)));
> +	u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
>  
>  	mutex_lock(&indio_dev->mlock);
>  	/* read current control */
> @@ -654,10 +671,10 @@ static const struct attribute_group lis3l02dq_attribute_group = {
>  static const struct iio_info lis3l02dq_info = {
>  	.read_raw = &lis3l02dq_read_raw,
>  	.write_raw = &lis3l02dq_write_raw,
> -	.read_event_value = &lis3l02dq_read_thresh,
> -	.write_event_value = &lis3l02dq_write_thresh,
> -	.write_event_config = &lis3l02dq_write_event_config,
> -	.read_event_config = &lis3l02dq_read_event_config,
> +	.read_event_value_new = &lis3l02dq_read_thresh,
> +	.write_event_value_new = &lis3l02dq_write_thresh,
> +	.write_event_config_new = &lis3l02dq_write_event_config,
> +	.read_event_config_new = &lis3l02dq_read_event_config,
>  	.driver_module = THIS_MODULE,
>  	.attrs = &lis3l02dq_attribute_group,
>  };
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 10/18] staging:iio:ad799x: Switch to new event config interface
  2013-09-26 12:58 ` [PATCH 10/18] staging:iio:ad799x: " Lars-Peter Clausen
@ 2013-09-30 20:59   ` Jonathan Cameron
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-30 20:59 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/26/13 13:58, Lars-Peter Clausen wrote:
> Switch the ad799x 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>
> ---
>  drivers/staging/iio/adc/ad799x_core.c | 139 ++++++++++++++++++++--------------
>  1 file changed, 82 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 3f5142b..2b51cb4 100644
> --- a/drivers/staging/iio/adc/ad799x_core.c
> +++ b/drivers/staging/iio/adc/ad799x_core.c
> @@ -254,7 +254,9 @@ error_ret_mutex:
>  }
>  
>  static int ad799x_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)
>  {
>  	return 1;
>  }
> @@ -267,14 +269,16 @@ static const u8 ad799x_threshold_addresses[][2] = {
>  };
>  
>  static int ad799x_write_event_value(struct iio_dev *indio_dev,
> -				    u64 event_code,
> +				    const struct iio_chan_spec *chan,
> +				    enum iio_event_type type,
> +				    enum iio_event_direction dir,
> +					enum iio_event_info info,
Slightly odd white space here.
>  				    int val)
>  {
>  	int ret;
>  	struct ad799x_state *st = iio_priv(indio_dev);
> -	int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> -			   IIO_EV_DIR_FALLING);
> -	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
> +	int direction = dir == IIO_EV_DIR_FALLING;
> +	int number = chan->channel;
>  
>  	mutex_lock(&indio_dev->mlock);
>  	ret = ad799x_i2c_write16(st,
> @@ -286,14 +290,16 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>  }
>  
>  static int ad799x_read_event_value(struct iio_dev *indio_dev,
> -				    u64 event_code,
> +				    const struct iio_chan_spec *chan,
> +				    enum iio_event_type type,
> +				    enum iio_event_direction dir,
> +					enum iio_event_info info,
Also here for some reason.
>  				    int *val)
>  {
>  	int ret;
>  	struct ad799x_state *st = iio_priv(indio_dev);
> -	int direction = !!(IIO_EVENT_CODE_EXTRACT_DIR(event_code) ==
> -			   IIO_EV_DIR_FALLING);
> -	int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code);
> +	int direction = dir == IIO_EV_DIR_FALLING;
> +	int number = chan->channel;
>  	u16 valin;
>  
>  	mutex_lock(&indio_dev->mlock);
> @@ -448,26 +454,37 @@ static const struct iio_info ad7991_info = {
>  static const struct iio_info ad7992_info = {
>  	.read_raw = &ad799x_read_raw,
>  	.event_attrs = &ad7992_event_attrs_group,
> -	.read_event_config = &ad799x_read_event_config,
> -	.read_event_value = &ad799x_read_event_value,
> -	.write_event_value = &ad799x_write_event_value,
> +	.read_event_config_new = &ad799x_read_event_config,
> +	.read_event_value_new = &ad799x_read_event_value,
> +	.write_event_value_new = &ad799x_write_event_value,
>  	.driver_module = THIS_MODULE,
>  };
>  
>  static const struct iio_info ad7993_4_7_8_info = {
>  	.read_raw = &ad799x_read_raw,
>  	.event_attrs = &ad7993_4_7_8_event_attrs_group,
> -	.read_event_config = &ad799x_read_event_config,
> -	.read_event_value = &ad799x_read_event_value,
> -	.write_event_value = &ad799x_write_event_value,
> +	.read_event_config_new = &ad799x_read_event_config,
> +	.read_event_value_new = &ad799x_read_event_value,
> +	.write_event_value_new = &ad799x_write_event_value,
>  	.driver_module = THIS_MODULE,
>  	.update_scan_mode = ad7997_8_update_scan_mode,
>  };
>  
> -#define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
> -			IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
> +static const struct iio_event_spec ad799x_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),
> +	},
> +};
>  
> -#define AD799X_CHANNEL(_index, _realbits, _evmask) { \
> +#define _AD799X_CHANNEL(_index, _realbits, _ev_spec, _num_ev_spec) { \
>  	.type = IIO_VOLTAGE, \
>  	.indexed = 1, \
>  	.channel = (_index), \
> @@ -475,16 +492,24 @@ static const struct iio_info ad7993_4_7_8_info = {
>  	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
>  	.scan_index = (_index), \
>  	.scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
> -	.event_mask = (_evmask), \
> +	.event_spec = _ev_spec, \
> +	.num_event_specs = _num_ev_spec, \
>  }
>  
> +#define AD799X_CHANNEL(_index, _realbits) \
> +	_AD799X_CHANNEL(_index, _realbits, NULL, 0)
> +
> +#define AD799X_CHANNEL_WITH_EVENTS(_index, _realbits) \
> +	_AD799X_CHANNEL(_index, _realbits, ad799x_events, \
> +		ARRAY_SIZE(ad799x_events))
> +
>  static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	[ad7991] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 12, 0),
> -			AD799X_CHANNEL(1, 12, 0),
> -			AD799X_CHANNEL(2, 12, 0),
> -			AD799X_CHANNEL(3, 12, 0),
> +			AD799X_CHANNEL(0, 12),
> +			AD799X_CHANNEL(1, 12),
> +			AD799X_CHANNEL(2, 12),
> +			AD799X_CHANNEL(3, 12),
>  			IIO_CHAN_SOFT_TIMESTAMP(4),
>  		},
>  		.num_channels = 5,
> @@ -492,10 +517,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7995] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 10, 0),
> -			AD799X_CHANNEL(1, 10, 0),
> -			AD799X_CHANNEL(2, 10, 0),
> -			AD799X_CHANNEL(3, 10, 0),
> +			AD799X_CHANNEL(0, 10),
> +			AD799X_CHANNEL(1, 10),
> +			AD799X_CHANNEL(2, 10),
> +			AD799X_CHANNEL(3, 10),
>  			IIO_CHAN_SOFT_TIMESTAMP(4),
>  		},
>  		.num_channels = 5,
> @@ -503,10 +528,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7999] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 8, 0),
> -			AD799X_CHANNEL(1, 8, 0),
> -			AD799X_CHANNEL(2, 8, 0),
> -			AD799X_CHANNEL(3, 8, 0),
> +			AD799X_CHANNEL(0, 8),
> +			AD799X_CHANNEL(1, 8),
> +			AD799X_CHANNEL(2, 8),
> +			AD799X_CHANNEL(3, 8),
>  			IIO_CHAN_SOFT_TIMESTAMP(4),
>  		},
>  		.num_channels = 5,
> @@ -514,8 +539,8 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7992] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
> +			AD799X_CHANNEL_WITH_EVENTS(0, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(1, 12),
>  			IIO_CHAN_SOFT_TIMESTAMP(3),
>  		},
>  		.num_channels = 3,
> @@ -524,10 +549,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7993] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
> +			AD799X_CHANNEL_WITH_EVENTS(0, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(1, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(2, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(3, 10),
>  			IIO_CHAN_SOFT_TIMESTAMP(4),
>  		},
>  		.num_channels = 5,
> @@ -536,10 +561,10 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7994] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
> +			AD799X_CHANNEL_WITH_EVENTS(0, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(1, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(2, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(3, 12),
>  			IIO_CHAN_SOFT_TIMESTAMP(4),
>  		},
>  		.num_channels = 5,
> @@ -548,14 +573,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7997] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
> -			AD799X_CHANNEL(4, 10, 0),
> -			AD799X_CHANNEL(5, 10, 0),
> -			AD799X_CHANNEL(6, 10, 0),
> -			AD799X_CHANNEL(7, 10, 0),
> +			AD799X_CHANNEL_WITH_EVENTS(0, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(1, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(2, 10),
> +			AD799X_CHANNEL_WITH_EVENTS(3, 10),
> +			AD799X_CHANNEL(4, 10),
> +			AD799X_CHANNEL(5, 10),
> +			AD799X_CHANNEL(6, 10),
> +			AD799X_CHANNEL(7, 10),
>  			IIO_CHAN_SOFT_TIMESTAMP(8),
>  		},
>  		.num_channels = 9,
> @@ -564,14 +589,14 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  	},
>  	[ad7998] = {
>  		.channel = {
> -			AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
> -			AD799X_CHANNEL(4, 12, 0),
> -			AD799X_CHANNEL(5, 12, 0),
> -			AD799X_CHANNEL(6, 12, 0),
> -			AD799X_CHANNEL(7, 12, 0),
> +			AD799X_CHANNEL_WITH_EVENTS(0, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(1, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(2, 12),
> +			AD799X_CHANNEL_WITH_EVENTS(3, 12),
> +			AD799X_CHANNEL(4, 12),
> +			AD799X_CHANNEL(5, 12),
> +			AD799X_CHANNEL(6, 12),
> +			AD799X_CHANNEL(7, 12),
>  			IIO_CHAN_SOFT_TIMESTAMP(8),
>  		},
>  		.num_channels = 9,
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 14/18] iio: Remove support for the legacy event config interface
  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
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-30 21:05 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/26/13 13:58, Lars-Peter Clausen wrote:
> Now that all drivers have been converted to the new event config interface we
> can remove for the legacy event config interface. Also drop the '_new' suffix
> for the event config interface callbacks, since those are the only callbacks
> now.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

It is going to be a little while before I can apply this, as it would be
unreasonable to ask those with drivers already under review to switch
to the new interface.  Hence, would you mind reordering the series
to put this right at the end?

> ---
>  drivers/iio/adc/max1363.c                  |   8 +-
>  drivers/iio/dac/ad5421.c                   |   6 +-
>  drivers/iio/industrialio-event.c           | 133 ++++-------------------------
>  drivers/iio/light/apds9300.c               |   8 +-
>  drivers/iio/light/gp2ap020a00f.c           |   8 +-
>  drivers/iio/light/tsl2563.c                |   8 +-
>  drivers/staging/iio/accel/lis3l02dq_core.c |   8 +-
>  drivers/staging/iio/accel/sca3000_core.c   |  16 ++--
>  drivers/staging/iio/adc/ad7291.c           |   8 +-
>  drivers/staging/iio/adc/ad799x_core.c      |  12 +--
>  drivers/staging/iio/cdc/ad7150.c           |   8 +-
>  drivers/staging/iio/iio_simple_dummy.c     |   8 +-
>  drivers/staging/iio/light/tsl2x7x_core.c   |  40 ++++-----
>  include/linux/iio/events.h                 |   4 -
>  include/linux/iio/iio.h                    |  34 ++------
>  15 files changed, 90 insertions(+), 219 deletions(-)
> 
> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> index 44343dc..6722b4e 100644
> --- a/drivers/iio/adc/max1363.c
> +++ b/drivers/iio/adc/max1363.c
> @@ -1013,10 +1013,10 @@ static const struct iio_info max1238_info = {
>  };
>  
>  static const struct iio_info max1363_info = {
> -	.read_event_value_new = &max1363_read_thresh,
> -	.write_event_value_new = &max1363_write_thresh,
> -	.read_event_config_new = &max1363_read_event_config,
> -	.write_event_config_new = &max1363_write_event_config,
> +	.read_event_value = &max1363_read_thresh,
> +	.write_event_value = &max1363_write_thresh,
> +	.read_event_config = &max1363_read_event_config,
> +	.write_event_config = &max1363_write_event_config,
>  	.read_raw = &max1363_read_raw,
>  	.update_scan_mode = &max1363_update_scan_mode,
>  	.driver_module = THIS_MODULE,
> diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
> index eefc708..4847037 100644
> --- a/drivers/iio/dac/ad5421.c
> +++ b/drivers/iio/dac/ad5421.c
> @@ -463,9 +463,9 @@ static int ad5421_read_event_value(struct iio_dev *indio_dev,
>  static const struct iio_info ad5421_info = {
>  	.read_raw =		ad5421_read_raw,
>  	.write_raw =		ad5421_write_raw,
> -	.read_event_config_new = ad5421_read_event_config,
> -	.write_event_config_new = ad5421_write_event_config,
> -	.read_event_value_new =	ad5421_read_event_value,
> +	.read_event_config =	ad5421_read_event_config,
> +	.write_event_config =	ad5421_write_event_config,
> +	.read_event_value =	ad5421_read_event_value,
>  	.driver_module =	THIS_MODULE,
>  };
>  
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index d426781..f4fa690 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -216,13 +216,9 @@ static ssize_t iio_ev_state_store(struct device *dev,
>  	if (ret < 0)
>  		return ret;
>  
> -	if (indio_dev->info->write_event_config)
> -		ret = indio_dev->info->write_event_config(indio_dev,
> -			this_attr->address, val);
> -	else
> -		ret = indio_dev->info->write_event_config_new(indio_dev,
> -			this_attr->c, iio_ev_attr_type(this_attr),
> -			iio_ev_attr_dir(this_attr), val);
> +	ret = indio_dev->info->write_event_config(indio_dev,
> +		this_attr->c, iio_ev_attr_type(this_attr),
> +		iio_ev_attr_dir(this_attr), val);
>  
>  	return (ret < 0) ? ret : len;
>  }
> @@ -235,13 +231,9 @@ static ssize_t iio_ev_state_show(struct device *dev,
>  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>  	int val;
>  
> -	if (indio_dev->info->read_event_config)
> -		val = indio_dev->info->read_event_config(indio_dev,
> -			this_attr->address);
> -	else
> -		val = indio_dev->info->read_event_config_new(indio_dev,
> -			this_attr->c, iio_ev_attr_type(this_attr),
> -			iio_ev_attr_dir(this_attr));
> +	val = indio_dev->info->read_event_config(indio_dev,
> +		this_attr->c, iio_ev_attr_type(this_attr),
> +		iio_ev_attr_dir(this_attr));
>  	if (val < 0)
>  		return val;
>  	else
> @@ -256,14 +248,10 @@ static ssize_t iio_ev_value_show(struct device *dev,
>  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>  	int val, ret;
>  
> -	if (indio_dev->info->read_event_value)
> -		ret = indio_dev->info->read_event_value(indio_dev,
> -			this_attr->address, &val);
> -	else
> -		ret = indio_dev->info->read_event_value_new(indio_dev,
> -			this_attr->c, iio_ev_attr_type(this_attr),
> -			iio_ev_attr_dir(this_attr),
> -			iio_ev_attr_info(this_attr), &val);
> +	ret = indio_dev->info->read_event_value(indio_dev,
> +		this_attr->c, iio_ev_attr_type(this_attr),
> +		iio_ev_attr_dir(this_attr),
> +		iio_ev_attr_info(this_attr), &val);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -280,22 +268,17 @@ static ssize_t iio_ev_value_store(struct device *dev,
>  	int val;
>  	int ret;
>  
> -	if (!indio_dev->info->write_event_value &&
> -		!indio_dev->info->write_event_value_new)
> +	if (!indio_dev->info->write_event_value)
>  		return -EINVAL;
>  
>  	ret = kstrtoint(buf, 10, &val);
>  	if (ret)
>  		return ret;
>  
> -	if (indio_dev->info->write_event_value)
> -		ret = indio_dev->info->write_event_value(indio_dev,
> -			this_attr->address, val);
> -	else
> -		ret = indio_dev->info->write_event_value_new(indio_dev,
> -			this_attr->c, iio_ev_attr_type(this_attr),
> -			iio_ev_attr_dir(this_attr),
> -			iio_ev_attr_info(this_attr), val);
> +	ret = indio_dev->info->write_event_value(indio_dev,
> +		this_attr->c, iio_ev_attr_type(this_attr),
> +		iio_ev_attr_dir(this_attr),
> +		iio_ev_attr_info(this_attr), val);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -348,7 +331,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
>  	return attrcount;
>  }
>  
> -static int iio_device_add_event_sysfs_new(struct iio_dev *indio_dev,
> +static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>  				      struct iio_chan_spec const *chan)
>  {
>  	int ret = 0, i, attrcount = 0;
> @@ -391,88 +374,6 @@ error_ret:
>  	return ret;
>  }
>  
> -static int iio_device_add_event_sysfs_old(struct iio_dev *indio_dev,
> -				      struct iio_chan_spec const *chan)
> -{
> -	int ret = 0, i, attrcount = 0;
> -	u64 mask = 0;
> -	char *postfix;
> -	if (!chan->event_mask)
> -		return 0;
> -
> -	for_each_set_bit(i, &chan->event_mask, sizeof(chan->event_mask)*8) {
> -		postfix = kasprintf(GFP_KERNEL, "%s_%s_en",
> -				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
> -				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
> -		if (postfix == NULL) {
> -			ret = -ENOMEM;
> -			goto error_ret;
> -		}
> -		if (chan->modified)
> -			mask = IIO_MOD_EVENT_CODE(chan->type, 0, chan->channel,
> -						  i/IIO_EV_DIR_MAX,
> -						  i%IIO_EV_DIR_MAX);
> -		else if (chan->differential)
> -			mask = IIO_EVENT_CODE(chan->type,
> -					      0, 0,
> -					      i%IIO_EV_DIR_MAX,
> -					      i/IIO_EV_DIR_MAX,
> -					      0,
> -					      chan->channel,
> -					      chan->channel2);
> -		else
> -			mask = IIO_UNMOD_EVENT_CODE(chan->type,
> -						    chan->channel,
> -						    i/IIO_EV_DIR_MAX,
> -						    i%IIO_EV_DIR_MAX);
> -
> -		ret = __iio_add_chan_devattr(postfix,
> -					     chan,
> -					     &iio_ev_state_show,
> -					     iio_ev_state_store,
> -					     mask,
> -					     0,
> -					     &indio_dev->dev,
> -					     &indio_dev->event_interface->
> -					     dev_attr_list);
> -		kfree(postfix);
> -		if (ret)
> -			goto error_ret;
> -		attrcount++;
> -		postfix = kasprintf(GFP_KERNEL, "%s_%s_value",
> -				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
> -				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
> -		if (postfix == NULL) {
> -			ret = -ENOMEM;
> -			goto error_ret;
> -		}
> -		ret = __iio_add_chan_devattr(postfix, chan,
> -					     iio_ev_value_show,
> -					     iio_ev_value_store,
> -					     mask,
> -					     0,
> -					     &indio_dev->dev,
> -					     &indio_dev->event_interface->
> -					     dev_attr_list);
> -		kfree(postfix);
> -		if (ret)
> -			goto error_ret;
> -		attrcount++;
> -	}
> -	ret = attrcount;
> -error_ret:
> -	return ret;
> -}
> -
> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
> -				      struct iio_chan_spec const *chan)
> -{
> -	if (chan->event_mask)
> -		return iio_device_add_event_sysfs_old(indio_dev, chan);
> -	else
> -		return iio_device_add_event_sysfs_new(indio_dev, chan);
> -}
> -
>  static inline void __iio_remove_event_config_attrs(struct iio_dev *indio_dev)
>  {
>  	struct iio_dev_attr *p, *n;
> @@ -504,8 +405,6 @@ static bool iio_check_for_dynamic_events(struct iio_dev *indio_dev)
>  	int j;
>  
>  	for (j = 0; j < indio_dev->num_channels; j++) {
> -		if (indio_dev->channels[j].event_mask != 0)
> -			return true;
>  		if (indio_dev->channels[j].num_event_specs != 0)
>  			return true;
>  	}
> diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c
> index 3f395f5..8601d76 100644
> --- a/drivers/iio/light/apds9300.c
> +++ b/drivers/iio/light/apds9300.c
> @@ -343,10 +343,10 @@ static const struct iio_info apds9300_info_no_irq = {
>  static const struct iio_info apds9300_info = {
>  	.driver_module		= THIS_MODULE,
>  	.read_raw		= apds9300_read_raw,
> -	.read_event_value_new	= apds9300_read_thresh,
> -	.write_event_value_new	= apds9300_write_thresh,
> -	.read_event_config_new	= apds9300_read_interrupt_config,
> -	.write_event_config_new	= apds9300_write_interrupt_config,
> +	.read_event_value	= apds9300_read_thresh,
> +	.write_event_value	= apds9300_write_thresh,
> +	.read_event_config	= apds9300_read_interrupt_config,
> +	.write_event_config	= apds9300_write_interrupt_config,
>  };
>  
>  static const struct iio_event_spec apds9300_event_spec[] = {
> diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
> index 43f47f7..20b27af 100644
> --- a/drivers/iio/light/gp2ap020a00f.c
> +++ b/drivers/iio/light/gp2ap020a00f.c
> @@ -1387,10 +1387,10 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
>  
>  static const struct iio_info gp2ap020a00f_info = {
>  	.read_raw = &gp2ap020a00f_read_raw,
> -	.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,
> +	.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,
>  	.driver_module = THIS_MODULE,
>  };
>  
> diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
> index 28c9953..89aa50a 100644
> --- a/drivers/iio/light/tsl2563.c
> +++ b/drivers/iio/light/tsl2563.c
> @@ -700,10 +700,10 @@ static const struct iio_info tsl2563_info = {
>  	.driver_module = THIS_MODULE,
>  	.read_raw = &tsl2563_read_raw,
>  	.write_raw = &tsl2563_write_raw,
> -	.read_event_value_new = &tsl2563_read_thresh,
> -	.write_event_value_new = &tsl2563_write_thresh,
> -	.read_event_config_new = &tsl2563_read_interrupt_config,
> -	.write_event_config_new = &tsl2563_write_interrupt_config,
> +	.read_event_value = &tsl2563_read_thresh,
> +	.write_event_value = &tsl2563_write_thresh,
> +	.read_event_config = &tsl2563_read_interrupt_config,
> +	.write_event_config = &tsl2563_write_interrupt_config,
>  };
>  
>  static int tsl2563_probe(struct i2c_client *client,
> diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
> index 5cd9c45..387efcc 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_core.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_core.c
> @@ -671,10 +671,10 @@ static const struct attribute_group lis3l02dq_attribute_group = {
>  static const struct iio_info lis3l02dq_info = {
>  	.read_raw = &lis3l02dq_read_raw,
>  	.write_raw = &lis3l02dq_write_raw,
> -	.read_event_value_new = &lis3l02dq_read_thresh,
> -	.write_event_value_new = &lis3l02dq_write_thresh,
> -	.write_event_config_new = &lis3l02dq_write_event_config,
> -	.read_event_config_new = &lis3l02dq_read_event_config,
> +	.read_event_value = &lis3l02dq_read_thresh,
> +	.write_event_value = &lis3l02dq_write_thresh,
> +	.write_event_config = &lis3l02dq_write_event_config,
> +	.read_event_config = &lis3l02dq_read_event_config,
>  	.driver_module = THIS_MODULE,
>  	.attrs = &lis3l02dq_attribute_group,
>  };
> diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
> index 7eb60a8..3c8ac8e 100644
> --- a/drivers/staging/iio/accel/sca3000_core.c
> +++ b/drivers/staging/iio/accel/sca3000_core.c
> @@ -1126,20 +1126,20 @@ static const struct iio_info sca3000_info = {
>  	.attrs = &sca3000_attribute_group,
>  	.read_raw = &sca3000_read_raw,
>  	.event_attrs = &sca3000_event_attribute_group,
> -	.read_event_value_new = &sca3000_read_thresh,
> -	.write_event_value_new = &sca3000_write_thresh,
> -	.read_event_config_new = &sca3000_read_event_config,
> -	.write_event_config_new = &sca3000_write_event_config,
> +	.read_event_value = &sca3000_read_thresh,
> +	.write_event_value = &sca3000_write_thresh,
> +	.read_event_config = &sca3000_read_event_config,
> +	.write_event_config = &sca3000_write_event_config,
>  	.driver_module = THIS_MODULE,
>  };
>  
>  static const struct iio_info sca3000_info_with_temp = {
>  	.attrs = &sca3000_attribute_group_with_temp,
>  	.read_raw = &sca3000_read_raw,
> -	.read_event_value_new = &sca3000_read_thresh,
> -	.write_event_value_new = &sca3000_write_thresh,
> -	.read_event_config_new = &sca3000_read_event_config,
> -	.write_event_config_new = &sca3000_write_event_config,
> +	.read_event_value = &sca3000_read_thresh,
> +	.write_event_value = &sca3000_write_thresh,
> +	.read_event_config = &sca3000_read_event_config,
> +	.write_event_config = &sca3000_write_event_config,
>  	.driver_module = THIS_MODULE,
>  };
>  
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index fa60764..dcd24ab 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -534,10 +534,10 @@ static struct attribute_group ad7291_event_attribute_group = {
>  
>  static const struct iio_info ad7291_info = {
>  	.read_raw = &ad7291_read_raw,
> -	.read_event_config_new = &ad7291_read_event_config,
> -	.write_event_config_new = &ad7291_write_event_config,
> -	.read_event_value_new = &ad7291_read_event_value,
> -	.write_event_value_new = &ad7291_write_event_value,
> +	.read_event_config = &ad7291_read_event_config,
> +	.write_event_config = &ad7291_write_event_config,
> +	.read_event_value = &ad7291_read_event_value,
> +	.write_event_value = &ad7291_write_event_value,
>  	.event_attrs = &ad7291_event_attribute_group,
>  	.driver_module = THIS_MODULE,
>  };
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 2b51cb4..73f7604 100644
> --- a/drivers/staging/iio/adc/ad799x_core.c
> +++ b/drivers/staging/iio/adc/ad799x_core.c
> @@ -454,18 +454,18 @@ static const struct iio_info ad7991_info = {
>  static const struct iio_info ad7992_info = {
>  	.read_raw = &ad799x_read_raw,
>  	.event_attrs = &ad7992_event_attrs_group,
> -	.read_event_config_new = &ad799x_read_event_config,
> -	.read_event_value_new = &ad799x_read_event_value,
> -	.write_event_value_new = &ad799x_write_event_value,
> +	.read_event_config = &ad799x_read_event_config,
> +	.read_event_value = &ad799x_read_event_value,
> +	.write_event_value = &ad799x_write_event_value,
>  	.driver_module = THIS_MODULE,
>  };
>  
>  static const struct iio_info ad7993_4_7_8_info = {
>  	.read_raw = &ad799x_read_raw,
>  	.event_attrs = &ad7993_4_7_8_event_attrs_group,
> -	.read_event_config_new = &ad799x_read_event_config,
> -	.read_event_value_new = &ad799x_read_event_value,
> -	.write_event_value_new = &ad799x_write_event_value,
> +	.read_event_config = &ad799x_read_event_config,
> +	.read_event_value = &ad799x_read_event_value,
> +	.write_event_value = &ad799x_write_event_value,
>  	.driver_module = THIS_MODULE,
>  	.update_scan_mode = ad7997_8_update_scan_mode,
>  };
> diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
> index ec2cf6e..bb37bed 100644
> --- a/drivers/staging/iio/cdc/ad7150.c
> +++ b/drivers/staging/iio/cdc/ad7150.c
> @@ -579,10 +579,10 @@ static const struct iio_info ad7150_info = {
>  	.event_attrs = &ad7150_event_attribute_group,
>  	.driver_module = THIS_MODULE,
>  	.read_raw = &ad7150_read_raw,
> -	.read_event_config_new = &ad7150_read_event_config,
> -	.write_event_config_new = &ad7150_write_event_config,
> -	.read_event_value_new = &ad7150_read_event_value,
> -	.write_event_value_new = &ad7150_write_event_value,
> +	.read_event_config = &ad7150_read_event_config,
> +	.write_event_config = &ad7150_write_event_config,
> +	.read_event_value = &ad7150_read_event_value,
> +	.write_event_value = &ad7150_write_event_value,
>  };
>  
>  /*
> diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
> index cdb8898..d3847fc 100644
> --- a/drivers/staging/iio/iio_simple_dummy.c
> +++ b/drivers/staging/iio/iio_simple_dummy.c
> @@ -370,10 +370,10 @@ static const struct iio_info iio_dummy_info = {
>  	.read_raw = &iio_dummy_read_raw,
>  	.write_raw = &iio_dummy_write_raw,
>  #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> -	.read_event_config_new = &iio_simple_dummy_read_event_config,
> -	.write_event_config_new = &iio_simple_dummy_write_event_config,
> -	.read_event_value_new = &iio_simple_dummy_read_event_value,
> -	.write_event_value_new = &iio_simple_dummy_write_event_value,
> +	.read_event_config = &iio_simple_dummy_read_event_config,
> +	.write_event_config = &iio_simple_dummy_write_event_config,
> +	.read_event_value = &iio_simple_dummy_read_event_value,
> +	.write_event_value = &iio_simple_dummy_write_event_value,
>  #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
>  };
>  
> diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
> index 1466f47..a429148 100644
> --- a/drivers/staging/iio/light/tsl2x7x_core.c
> +++ b/drivers/staging/iio/light/tsl2x7x_core.c
> @@ -1672,10 +1672,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  		.driver_module = THIS_MODULE,
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value_new = &tsl2x7x_read_thresh,
> -		.write_event_value_new = &tsl2x7x_write_thresh,
> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
> +		.read_event_value = &tsl2x7x_read_thresh,
> +		.write_event_value = &tsl2x7x_write_thresh,
> +		.read_event_config = &tsl2x7x_read_interrupt_config,
> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>  	},
>  	[PRX] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
> @@ -1683,10 +1683,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  		.driver_module = THIS_MODULE,
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value_new = &tsl2x7x_read_thresh,
> -		.write_event_value_new = &tsl2x7x_write_thresh,
> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
> +		.read_event_value = &tsl2x7x_read_thresh,
> +		.write_event_value = &tsl2x7x_write_thresh,
> +		.read_event_config = &tsl2x7x_read_interrupt_config,
> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>  	},
>  	[ALSPRX] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
> @@ -1694,10 +1694,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  		.driver_module = THIS_MODULE,
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value_new = &tsl2x7x_read_thresh,
> -		.write_event_value_new = &tsl2x7x_write_thresh,
> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
> +		.read_event_value = &tsl2x7x_read_thresh,
> +		.write_event_value = &tsl2x7x_write_thresh,
> +		.read_event_config = &tsl2x7x_read_interrupt_config,
> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>  	},
>  	[PRX2] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
> @@ -1705,10 +1705,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  		.driver_module = THIS_MODULE,
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value_new = &tsl2x7x_read_thresh,
> -		.write_event_value_new = &tsl2x7x_write_thresh,
> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
> +		.read_event_value = &tsl2x7x_read_thresh,
> +		.write_event_value = &tsl2x7x_write_thresh,
> +		.read_event_config = &tsl2x7x_read_interrupt_config,
> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>  	},
>  	[ALSPRX2] = {
>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
> @@ -1716,10 +1716,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>  		.driver_module = THIS_MODULE,
>  		.read_raw = &tsl2x7x_read_raw,
>  		.write_raw = &tsl2x7x_write_raw,
> -		.read_event_value_new = &tsl2x7x_read_thresh,
> -		.write_event_value_new = &tsl2x7x_write_thresh,
> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
> +		.read_event_value = &tsl2x7x_read_thresh,
> +		.write_event_value = &tsl2x7x_write_thresh,
> +		.read_event_config = &tsl2x7x_read_interrupt_config,
> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>  	},
>  };
>  
> diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
> index 5dab2c4..8bbd7bc 100644
> --- a/include/linux/iio/events.h
> +++ b/include/linux/iio/events.h
> @@ -46,10 +46,6 @@ struct iio_event_data {
>  	 ((u16)chan))
>  
>  
> -#define IIO_EV_DIR_MAX 4
> -#define IIO_EV_BIT(type, direction)			\
> -	(1 << (type*IIO_EV_DIR_MAX + direction))
> -
>  /**
>   * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
>   * @chan_type:	Type of the channel. Should be one of enum iio_chan_type.
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 5a9fefe..2b783df 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -185,7 +185,6 @@ struct iio_event_spec {
>   *			by all channels of the same direction.
>   * @info_mask_shared_by_all: What information is to be exported that is shared
>   *			by all channels.
> - * @event_mask:		What events can this channel produce.
>   * @event_spec:		Array of events which should be registered for this
>   *			channel.
>   * @num_event_specs:	Size of the event_spec array.
> @@ -226,7 +225,6 @@ struct iio_chan_spec {
>  	long			info_mask_shared_by_type;
>  	long			info_mask_shared_by_dir;
>  	long			info_mask_shared_by_all;
> -	long			event_mask;
>  	const struct iio_event_spec *event_spec;
>  	unsigned int		num_event_specs;
>  	const struct iio_chan_spec_ext_info *ext_info;
> @@ -307,16 +305,8 @@ struct iio_dev;
>   *			returns IIO_VAL_INT_PLUS_MICRO.
>   * @read_event_config:	find out if the event is enabled.
>   * @write_event_config:	set if the event is enabled.
> - * @read_event_value:	read a value associated with the event. Meaning
> - *			is event dependant. event_code specifies which event.
> - * @write_event_value:	write the value associated with the event.
> - *			Meaning is event dependent.
> - * @read_event_config_new: find out if the event is enabled. New style interface.
> - * @write_event_config_new: set if the event is enabled. New style interface.
> - * @read_event_value_new: read a configuration value associated with the event.
> - *                         New style interface.
> - * @write_event_value_new: write a configuration value for the event. New style
> - *			   interface.
> + * @read_event_value:	read a configuration value associated with the event.
> + * @write_event_value:	write a configuration value for the event.
>   * @validate_trigger:	function to validate the trigger when the
>   *			current trigger gets changed.
>   * @update_scan_mode:	function to configure device and scan buffer when
> @@ -345,37 +335,23 @@ struct iio_info {
>  			 long mask);
>  
>  	int (*read_event_config)(struct iio_dev *indio_dev,
> -				 u64 event_code);
> -
> -	int (*write_event_config)(struct iio_dev *indio_dev,
> -				  u64 event_code,
> -				  int state);
> -
> -	int (*read_event_value)(struct iio_dev *indio_dev,
> -				u64 event_code,
> -				int *val);
> -	int (*write_event_value)(struct iio_dev *indio_dev,
> -				 u64 event_code,
> -				 int val);
> -
> -	int (*read_event_config_new)(struct iio_dev *indio_dev,
>  				 const struct iio_chan_spec *chan,
>  				 enum iio_event_type type,
>  				 enum iio_event_direction dir);
>  
> -	int (*write_event_config_new)(struct iio_dev *indio_dev,
> +	int (*write_event_config)(struct iio_dev *indio_dev,
>  				  const struct iio_chan_spec *chan,
>  				  enum iio_event_type type,
>  				  enum iio_event_direction dir,
>  				  int state);
>  
> -	int (*read_event_value_new)(struct iio_dev *indio_dev,
> +	int (*read_event_value)(struct iio_dev *indio_dev,
>  				const struct iio_chan_spec *chan,
>  				enum iio_event_type type,
>  				enum iio_event_direction dir,
>  				enum iio_event_info info, int *val);
>  
> -	int (*write_event_value_new)(struct iio_dev *indio_dev,
> +	int (*write_event_value)(struct iio_dev *indio_dev,
>  				 const struct iio_chan_spec *chan,
>  				 enum iio_event_type type,
>  				 enum iio_event_direction dir,
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 17/18] staging:iio:ad799x: Use event spec for threshold hysteresis
  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
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2013-09-30 21:10 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 09/26/13 13:58, Lars-Peter Clausen wrote:
> Register the event threshold hysteresis attributes by using the new
> IIO_EV_INFO_HYSTERESIS event spec type. This allows us to throw away a good
> portion of boiler-plate code.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This is fine.  Given we have a couple of drivers where the sampling_frequency
element only applies to events (this and max1363 that I can think of), howabout
adding another element for that one as well?  Drops another chunk of boilerplate
from both drivers.  Would perhaps require non integer values though and the callbacks
to handle querying what form is required as we have for the write_raw callback.

> ---
>  drivers/staging/iio/adc/ad799x_core.c | 132 ++++++++--------------------------
>  1 file changed, 29 insertions(+), 103 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 24e0749..05641f0 100644
> --- a/drivers/staging/iio/adc/ad799x_core.c
> +++ b/drivers/staging/iio/adc/ad799x_core.c
> @@ -261,13 +261,23 @@ static int ad799x_read_event_config(struct iio_dev *indio_dev,
>  	return 1;
>  }
>  
> -static int ad799x_threshold_reg(const struct iio_chan_spec *chan,
> -					enum iio_event_direction dir)
> +static unsigned int ad799x_threshold_reg(const struct iio_chan_spec *chan,
> +					 enum iio_event_direction dir,
> +					 enum iio_event_info info)
>  {
> -	if (dir == IIO_EV_DIR_FALLING)
> -		return AD7998_DATALOW_REG(chan->channel);
> -	else
> -		return AD7998_DATAHIGH_REG(chan->channel);
> +	switch (info) {
> +	case IIO_EV_INFO_VALUE:
> +		if (dir == IIO_EV_DIR_FALLING)
> +			return AD7998_DATALOW_REG(chan->channel);
> +		else
> +			return AD7998_DATAHIGH_REG(chan->channel);
> +	case IIO_EV_INFO_HYSTERESIS:
> +		return AD7998_HYST_REG(chan->channel);
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
>  }
>  
>  static int ad799x_write_event_value(struct iio_dev *indio_dev,
> @@ -281,7 +291,8 @@ static int ad799x_write_event_value(struct iio_dev *indio_dev,
>  	struct ad799x_state *st = iio_priv(indio_dev);
>  
>  	mutex_lock(&indio_dev->mlock);
> -	ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir), val);
> +	ret = ad799x_i2c_write16(st, ad799x_threshold_reg(chan, dir, info),
> +		val);
>  	mutex_unlock(&indio_dev->mlock);
>  
>  	return ret;
> @@ -299,7 +310,8 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>  	u16 valin;
>  
>  	mutex_lock(&indio_dev->mlock);
> -	ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir), &valin);
> +	ret = ad799x_i2c_read16(st, ad799x_threshold_reg(chan, dir, info),
> +		&valin);
>  	mutex_unlock(&indio_dev->mlock);
>  	if (ret < 0)
>  		return ret;
> @@ -308,46 +320,6 @@ static int ad799x_read_event_value(struct iio_dev *indio_dev,
>  	return 0;
>  }
>  
> -static ssize_t ad799x_read_channel_config(struct device *dev,
> -					struct device_attribute *attr,
> -					char *buf)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct ad799x_state *st = iio_priv(indio_dev);
> -	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> -
> -	int ret;
> -	u16 val;
> -	ret = ad799x_i2c_read16(st, this_attr->address, &val);
> -	if (ret)
> -		return ret;
> -
> -	return sprintf(buf, "%d\n", val);
> -}
> -
> -static ssize_t ad799x_write_channel_config(struct device *dev,
> -					 struct device_attribute *attr,
> -					 const char *buf,
> -					 size_t len)
> -{
> -	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> -	struct ad799x_state *st = iio_priv(indio_dev);
> -	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> -
> -	long val;
> -	int ret;
> -
> -	ret = kstrtol(buf, 10, &val);
> -	if (ret)
> -		return ret;
> -
> -	mutex_lock(&indio_dev->mlock);
> -	ret = ad799x_i2c_write16(st, this_attr->address, val);
> -	mutex_unlock(&indio_dev->mlock);
> -
> -	return ret ? ret : len;
> -}
> -
>  static irqreturn_t ad799x_event_handler(int irq, void *private)
>  {
>  	struct iio_dev *indio_dev = private;
> @@ -383,60 +355,19 @@ done:
>  	return IRQ_HANDLED;
>  }
>  
> -static IIO_DEVICE_ATTR(in_voltage0_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad799x_read_channel_config,
> -		       ad799x_write_channel_config,
> -		       AD7998_HYST_REG(0));
> -
> -static IIO_DEVICE_ATTR(in_voltage1_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad799x_read_channel_config,
> -		       ad799x_write_channel_config,
> -		       AD7998_HYST_REG(1));
> -
> -static IIO_DEVICE_ATTR(in_voltage2_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad799x_read_channel_config,
> -		       ad799x_write_channel_config,
> -		       AD7998_HYST_REG(2));
> -
> -static IIO_DEVICE_ATTR(in_voltage3_thresh_both_hyst_raw,
> -		       S_IRUGO | S_IWUSR,
> -		       ad799x_read_channel_config,
> -		       ad799x_write_channel_config,
> -		       AD7998_HYST_REG(3));
> -
>  static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
>  			      ad799x_read_frequency,
>  			      ad799x_write_frequency);
>  static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("15625 7812 3906 1953 976 488 244 0");
>  
> -static struct attribute *ad7993_4_7_8_event_attributes[] = {
> -	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage2_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage3_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_sampling_frequency.dev_attr.attr,
> -	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
> -	NULL,
> -};
> -
> -static struct attribute_group ad7993_4_7_8_event_attrs_group = {
> -	.attrs = ad7993_4_7_8_event_attributes,
> -	.name = "events",
> -};
> -
> -static struct attribute *ad7992_event_attributes[] = {
> -	&iio_dev_attr_in_voltage0_thresh_both_hyst_raw.dev_attr.attr,
> -	&iio_dev_attr_in_voltage1_thresh_both_hyst_raw.dev_attr.attr,
> +static struct attribute *ad799x_event_attributes[] = {
>  	&iio_dev_attr_sampling_frequency.dev_attr.attr,
>  	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
>  	NULL,
>  };
>  
> -static struct attribute_group ad7992_event_attrs_group = {
> -	.attrs = ad7992_event_attributes,
> +static struct attribute_group ad799x_event_attrs_group = {
> +	.attrs = ad799x_event_attributes,
>  	.name = "events",
>  };
>  
> @@ -445,18 +376,9 @@ static const struct iio_info ad7991_info = {
>  	.driver_module = THIS_MODULE,
>  };
>  
> -static const struct iio_info ad7992_info = {
> -	.read_raw = &ad799x_read_raw,
> -	.event_attrs = &ad7992_event_attrs_group,
> -	.read_event_config = &ad799x_read_event_config,
> -	.read_event_value = &ad799x_read_event_value,
> -	.write_event_value = &ad799x_write_event_value,
> -	.driver_module = THIS_MODULE,
> -};
> -
>  static const struct iio_info ad7993_4_7_8_info = {
>  	.read_raw = &ad799x_read_raw,
> -	.event_attrs = &ad7993_4_7_8_event_attrs_group,
> +	.event_attrs = &ad799x_event_attrs_group,
>  	.read_event_config = &ad799x_read_event_config,
>  	.read_event_value = &ad799x_read_event_value,
>  	.write_event_value = &ad799x_write_event_value,
> @@ -475,6 +397,10 @@ static const struct iio_event_spec ad799x_events[] = {
>  		.dir = IIO_EV_DIR_FALLING,
>  		.mask_separate = BIT(IIO_EV_INFO_VALUE),
>  			BIT(IIO_EV_INFO_ENABLE),
> +	}, {
> +		.type = IIO_EV_TYPE_THRESH,
> +		.dir = IIO_EV_DIR_EITHER,
> +		.mask_separate = BIT(IIO_EV_INFO_HYSTERESIS),
>  	},
>  };
>  
> @@ -539,7 +465,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
>  		},
>  		.num_channels = 3,
>  		.default_config = AD7998_ALERT_EN,
> -		.info = &ad7992_info,
> +		.info = &ad7993_4_7_8_info,
>  	},
>  	[ad7993] = {
>  		.channel = {
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 07/18] staging:iio:lis3l02dq: Switch to new event config interface
  2013-09-30 20:55   ` Jonathan Cameron
@ 2013-10-01  7:51     ` Lars-Peter Clausen
  2013-10-01  9:14       ` Jonathan Cameron
  0 siblings, 1 reply; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-10-01  7:51 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 09/30/2013 10:55 PM, Jonathan Cameron wrote:
> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>> Switch the lis3l02dq 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>
> Hi Lars,
> 
> As this one is in staging, lets take advantage of the fact that we now
> have the ability to have shared elements.  It's an ABI change so I wouldn't
> suggest this for drivers outside staging.
> 
> The threshold value is shared by all channels (only one address to write) for each
> of the two types.

Ok, I'll add that to the series, but as a separate patch. One patch for
changing to the new API, one patch for changing the behavior.

- Lars

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 14/18] iio: Remove support for the legacy event config interface
  2013-09-30 21:05   ` Jonathan Cameron
@ 2013-10-01  7:52     ` Lars-Peter Clausen
  0 siblings, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-10-01  7:52 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 09/30/2013 11:05 PM, Jonathan Cameron wrote:
> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>> Now that all drivers have been converted to the new event config interface we
>> can remove for the legacy event config interface. Also drop the '_new' suffix
>> for the event config interface callbacks, since those are the only callbacks
>> now.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> 
> It is going to be a little while before I can apply this, as it would be
> unreasonable to ask those with drivers already under review to switch
> to the new interface.  Hence, would you mind reordering the series
> to put this right at the end?
> 

No problem, I think we can wait with applying this patch until the next release.

>> ---
>>  drivers/iio/adc/max1363.c                  |   8 +-
>>  drivers/iio/dac/ad5421.c                   |   6 +-
>>  drivers/iio/industrialio-event.c           | 133 ++++-------------------------
>>  drivers/iio/light/apds9300.c               |   8 +-
>>  drivers/iio/light/gp2ap020a00f.c           |   8 +-
>>  drivers/iio/light/tsl2563.c                |   8 +-
>>  drivers/staging/iio/accel/lis3l02dq_core.c |   8 +-
>>  drivers/staging/iio/accel/sca3000_core.c   |  16 ++--
>>  drivers/staging/iio/adc/ad7291.c           |   8 +-
>>  drivers/staging/iio/adc/ad799x_core.c      |  12 +--
>>  drivers/staging/iio/cdc/ad7150.c           |   8 +-
>>  drivers/staging/iio/iio_simple_dummy.c     |   8 +-
>>  drivers/staging/iio/light/tsl2x7x_core.c   |  40 ++++-----
>>  include/linux/iio/events.h                 |   4 -
>>  include/linux/iio/iio.h                    |  34 ++------
>>  15 files changed, 90 insertions(+), 219 deletions(-)
>>
>> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
>> index 44343dc..6722b4e 100644
>> --- a/drivers/iio/adc/max1363.c
>> +++ b/drivers/iio/adc/max1363.c
>> @@ -1013,10 +1013,10 @@ static const struct iio_info max1238_info = {
>>  };
>>  
>>  static const struct iio_info max1363_info = {
>> -	.read_event_value_new = &max1363_read_thresh,
>> -	.write_event_value_new = &max1363_write_thresh,
>> -	.read_event_config_new = &max1363_read_event_config,
>> -	.write_event_config_new = &max1363_write_event_config,
>> +	.read_event_value = &max1363_read_thresh,
>> +	.write_event_value = &max1363_write_thresh,
>> +	.read_event_config = &max1363_read_event_config,
>> +	.write_event_config = &max1363_write_event_config,
>>  	.read_raw = &max1363_read_raw,
>>  	.update_scan_mode = &max1363_update_scan_mode,
>>  	.driver_module = THIS_MODULE,
>> diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
>> index eefc708..4847037 100644
>> --- a/drivers/iio/dac/ad5421.c
>> +++ b/drivers/iio/dac/ad5421.c
>> @@ -463,9 +463,9 @@ static int ad5421_read_event_value(struct iio_dev *indio_dev,
>>  static const struct iio_info ad5421_info = {
>>  	.read_raw =		ad5421_read_raw,
>>  	.write_raw =		ad5421_write_raw,
>> -	.read_event_config_new = ad5421_read_event_config,
>> -	.write_event_config_new = ad5421_write_event_config,
>> -	.read_event_value_new =	ad5421_read_event_value,
>> +	.read_event_config =	ad5421_read_event_config,
>> +	.write_event_config =	ad5421_write_event_config,
>> +	.read_event_value =	ad5421_read_event_value,
>>  	.driver_module =	THIS_MODULE,
>>  };
>>  
>> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
>> index d426781..f4fa690 100644
>> --- a/drivers/iio/industrialio-event.c
>> +++ b/drivers/iio/industrialio-event.c
>> @@ -216,13 +216,9 @@ static ssize_t iio_ev_state_store(struct device *dev,
>>  	if (ret < 0)
>>  		return ret;
>>  
>> -	if (indio_dev->info->write_event_config)
>> -		ret = indio_dev->info->write_event_config(indio_dev,
>> -			this_attr->address, val);
>> -	else
>> -		ret = indio_dev->info->write_event_config_new(indio_dev,
>> -			this_attr->c, iio_ev_attr_type(this_attr),
>> -			iio_ev_attr_dir(this_attr), val);
>> +	ret = indio_dev->info->write_event_config(indio_dev,
>> +		this_attr->c, iio_ev_attr_type(this_attr),
>> +		iio_ev_attr_dir(this_attr), val);
>>  
>>  	return (ret < 0) ? ret : len;
>>  }
>> @@ -235,13 +231,9 @@ static ssize_t iio_ev_state_show(struct device *dev,
>>  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>>  	int val;
>>  
>> -	if (indio_dev->info->read_event_config)
>> -		val = indio_dev->info->read_event_config(indio_dev,
>> -			this_attr->address);
>> -	else
>> -		val = indio_dev->info->read_event_config_new(indio_dev,
>> -			this_attr->c, iio_ev_attr_type(this_attr),
>> -			iio_ev_attr_dir(this_attr));
>> +	val = indio_dev->info->read_event_config(indio_dev,
>> +		this_attr->c, iio_ev_attr_type(this_attr),
>> +		iio_ev_attr_dir(this_attr));
>>  	if (val < 0)
>>  		return val;
>>  	else
>> @@ -256,14 +248,10 @@ static ssize_t iio_ev_value_show(struct device *dev,
>>  	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>>  	int val, ret;
>>  
>> -	if (indio_dev->info->read_event_value)
>> -		ret = indio_dev->info->read_event_value(indio_dev,
>> -			this_attr->address, &val);
>> -	else
>> -		ret = indio_dev->info->read_event_value_new(indio_dev,
>> -			this_attr->c, iio_ev_attr_type(this_attr),
>> -			iio_ev_attr_dir(this_attr),
>> -			iio_ev_attr_info(this_attr), &val);
>> +	ret = indio_dev->info->read_event_value(indio_dev,
>> +		this_attr->c, iio_ev_attr_type(this_attr),
>> +		iio_ev_attr_dir(this_attr),
>> +		iio_ev_attr_info(this_attr), &val);
>>  	if (ret < 0)
>>  		return ret;
>>  
>> @@ -280,22 +268,17 @@ static ssize_t iio_ev_value_store(struct device *dev,
>>  	int val;
>>  	int ret;
>>  
>> -	if (!indio_dev->info->write_event_value &&
>> -		!indio_dev->info->write_event_value_new)
>> +	if (!indio_dev->info->write_event_value)
>>  		return -EINVAL;
>>  
>>  	ret = kstrtoint(buf, 10, &val);
>>  	if (ret)
>>  		return ret;
>>  
>> -	if (indio_dev->info->write_event_value)
>> -		ret = indio_dev->info->write_event_value(indio_dev,
>> -			this_attr->address, val);
>> -	else
>> -		ret = indio_dev->info->write_event_value_new(indio_dev,
>> -			this_attr->c, iio_ev_attr_type(this_attr),
>> -			iio_ev_attr_dir(this_attr),
>> -			iio_ev_attr_info(this_attr), val);
>> +	ret = indio_dev->info->write_event_value(indio_dev,
>> +		this_attr->c, iio_ev_attr_type(this_attr),
>> +		iio_ev_attr_dir(this_attr),
>> +		iio_ev_attr_info(this_attr), val);
>>  	if (ret < 0)
>>  		return ret;
>>  
>> @@ -348,7 +331,7 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
>>  	return attrcount;
>>  }
>>  
>> -static int iio_device_add_event_sysfs_new(struct iio_dev *indio_dev,
>> +static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>>  				      struct iio_chan_spec const *chan)
>>  {
>>  	int ret = 0, i, attrcount = 0;
>> @@ -391,88 +374,6 @@ error_ret:
>>  	return ret;
>>  }
>>  
>> -static int iio_device_add_event_sysfs_old(struct iio_dev *indio_dev,
>> -				      struct iio_chan_spec const *chan)
>> -{
>> -	int ret = 0, i, attrcount = 0;
>> -	u64 mask = 0;
>> -	char *postfix;
>> -	if (!chan->event_mask)
>> -		return 0;
>> -
>> -	for_each_set_bit(i, &chan->event_mask, sizeof(chan->event_mask)*8) {
>> -		postfix = kasprintf(GFP_KERNEL, "%s_%s_en",
>> -				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
>> -				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
>> -		if (postfix == NULL) {
>> -			ret = -ENOMEM;
>> -			goto error_ret;
>> -		}
>> -		if (chan->modified)
>> -			mask = IIO_MOD_EVENT_CODE(chan->type, 0, chan->channel,
>> -						  i/IIO_EV_DIR_MAX,
>> -						  i%IIO_EV_DIR_MAX);
>> -		else if (chan->differential)
>> -			mask = IIO_EVENT_CODE(chan->type,
>> -					      0, 0,
>> -					      i%IIO_EV_DIR_MAX,
>> -					      i/IIO_EV_DIR_MAX,
>> -					      0,
>> -					      chan->channel,
>> -					      chan->channel2);
>> -		else
>> -			mask = IIO_UNMOD_EVENT_CODE(chan->type,
>> -						    chan->channel,
>> -						    i/IIO_EV_DIR_MAX,
>> -						    i%IIO_EV_DIR_MAX);
>> -
>> -		ret = __iio_add_chan_devattr(postfix,
>> -					     chan,
>> -					     &iio_ev_state_show,
>> -					     iio_ev_state_store,
>> -					     mask,
>> -					     0,
>> -					     &indio_dev->dev,
>> -					     &indio_dev->event_interface->
>> -					     dev_attr_list);
>> -		kfree(postfix);
>> -		if (ret)
>> -			goto error_ret;
>> -		attrcount++;
>> -		postfix = kasprintf(GFP_KERNEL, "%s_%s_value",
>> -				    iio_ev_type_text[i/IIO_EV_DIR_MAX],
>> -				    iio_ev_dir_text[i%IIO_EV_DIR_MAX]);
>> -		if (postfix == NULL) {
>> -			ret = -ENOMEM;
>> -			goto error_ret;
>> -		}
>> -		ret = __iio_add_chan_devattr(postfix, chan,
>> -					     iio_ev_value_show,
>> -					     iio_ev_value_store,
>> -					     mask,
>> -					     0,
>> -					     &indio_dev->dev,
>> -					     &indio_dev->event_interface->
>> -					     dev_attr_list);
>> -		kfree(postfix);
>> -		if (ret)
>> -			goto error_ret;
>> -		attrcount++;
>> -	}
>> -	ret = attrcount;
>> -error_ret:
>> -	return ret;
>> -}
>> -
>> -static int iio_device_add_event_sysfs(struct iio_dev *indio_dev,
>> -				      struct iio_chan_spec const *chan)
>> -{
>> -	if (chan->event_mask)
>> -		return iio_device_add_event_sysfs_old(indio_dev, chan);
>> -	else
>> -		return iio_device_add_event_sysfs_new(indio_dev, chan);
>> -}
>> -
>>  static inline void __iio_remove_event_config_attrs(struct iio_dev *indio_dev)
>>  {
>>  	struct iio_dev_attr *p, *n;
>> @@ -504,8 +405,6 @@ static bool iio_check_for_dynamic_events(struct iio_dev *indio_dev)
>>  	int j;
>>  
>>  	for (j = 0; j < indio_dev->num_channels; j++) {
>> -		if (indio_dev->channels[j].event_mask != 0)
>> -			return true;
>>  		if (indio_dev->channels[j].num_event_specs != 0)
>>  			return true;
>>  	}
>> diff --git a/drivers/iio/light/apds9300.c b/drivers/iio/light/apds9300.c
>> index 3f395f5..8601d76 100644
>> --- a/drivers/iio/light/apds9300.c
>> +++ b/drivers/iio/light/apds9300.c
>> @@ -343,10 +343,10 @@ static const struct iio_info apds9300_info_no_irq = {
>>  static const struct iio_info apds9300_info = {
>>  	.driver_module		= THIS_MODULE,
>>  	.read_raw		= apds9300_read_raw,
>> -	.read_event_value_new	= apds9300_read_thresh,
>> -	.write_event_value_new	= apds9300_write_thresh,
>> -	.read_event_config_new	= apds9300_read_interrupt_config,
>> -	.write_event_config_new	= apds9300_write_interrupt_config,
>> +	.read_event_value	= apds9300_read_thresh,
>> +	.write_event_value	= apds9300_write_thresh,
>> +	.read_event_config	= apds9300_read_interrupt_config,
>> +	.write_event_config	= apds9300_write_interrupt_config,
>>  };
>>  
>>  static const struct iio_event_spec apds9300_event_spec[] = {
>> diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
>> index 43f47f7..20b27af 100644
>> --- a/drivers/iio/light/gp2ap020a00f.c
>> +++ b/drivers/iio/light/gp2ap020a00f.c
>> @@ -1387,10 +1387,10 @@ static const struct iio_chan_spec gp2ap020a00f_channels[] = {
>>  
>>  static const struct iio_info gp2ap020a00f_info = {
>>  	.read_raw = &gp2ap020a00f_read_raw,
>> -	.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,
>> +	.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,
>>  	.driver_module = THIS_MODULE,
>>  };
>>  
>> diff --git a/drivers/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
>> index 28c9953..89aa50a 100644
>> --- a/drivers/iio/light/tsl2563.c
>> +++ b/drivers/iio/light/tsl2563.c
>> @@ -700,10 +700,10 @@ static const struct iio_info tsl2563_info = {
>>  	.driver_module = THIS_MODULE,
>>  	.read_raw = &tsl2563_read_raw,
>>  	.write_raw = &tsl2563_write_raw,
>> -	.read_event_value_new = &tsl2563_read_thresh,
>> -	.write_event_value_new = &tsl2563_write_thresh,
>> -	.read_event_config_new = &tsl2563_read_interrupt_config,
>> -	.write_event_config_new = &tsl2563_write_interrupt_config,
>> +	.read_event_value = &tsl2563_read_thresh,
>> +	.write_event_value = &tsl2563_write_thresh,
>> +	.read_event_config = &tsl2563_read_interrupt_config,
>> +	.write_event_config = &tsl2563_write_interrupt_config,
>>  };
>>  
>>  static int tsl2563_probe(struct i2c_client *client,
>> diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
>> index 5cd9c45..387efcc 100644
>> --- a/drivers/staging/iio/accel/lis3l02dq_core.c
>> +++ b/drivers/staging/iio/accel/lis3l02dq_core.c
>> @@ -671,10 +671,10 @@ static const struct attribute_group lis3l02dq_attribute_group = {
>>  static const struct iio_info lis3l02dq_info = {
>>  	.read_raw = &lis3l02dq_read_raw,
>>  	.write_raw = &lis3l02dq_write_raw,
>> -	.read_event_value_new = &lis3l02dq_read_thresh,
>> -	.write_event_value_new = &lis3l02dq_write_thresh,
>> -	.write_event_config_new = &lis3l02dq_write_event_config,
>> -	.read_event_config_new = &lis3l02dq_read_event_config,
>> +	.read_event_value = &lis3l02dq_read_thresh,
>> +	.write_event_value = &lis3l02dq_write_thresh,
>> +	.write_event_config = &lis3l02dq_write_event_config,
>> +	.read_event_config = &lis3l02dq_read_event_config,
>>  	.driver_module = THIS_MODULE,
>>  	.attrs = &lis3l02dq_attribute_group,
>>  };
>> diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
>> index 7eb60a8..3c8ac8e 100644
>> --- a/drivers/staging/iio/accel/sca3000_core.c
>> +++ b/drivers/staging/iio/accel/sca3000_core.c
>> @@ -1126,20 +1126,20 @@ static const struct iio_info sca3000_info = {
>>  	.attrs = &sca3000_attribute_group,
>>  	.read_raw = &sca3000_read_raw,
>>  	.event_attrs = &sca3000_event_attribute_group,
>> -	.read_event_value_new = &sca3000_read_thresh,
>> -	.write_event_value_new = &sca3000_write_thresh,
>> -	.read_event_config_new = &sca3000_read_event_config,
>> -	.write_event_config_new = &sca3000_write_event_config,
>> +	.read_event_value = &sca3000_read_thresh,
>> +	.write_event_value = &sca3000_write_thresh,
>> +	.read_event_config = &sca3000_read_event_config,
>> +	.write_event_config = &sca3000_write_event_config,
>>  	.driver_module = THIS_MODULE,
>>  };
>>  
>>  static const struct iio_info sca3000_info_with_temp = {
>>  	.attrs = &sca3000_attribute_group_with_temp,
>>  	.read_raw = &sca3000_read_raw,
>> -	.read_event_value_new = &sca3000_read_thresh,
>> -	.write_event_value_new = &sca3000_write_thresh,
>> -	.read_event_config_new = &sca3000_read_event_config,
>> -	.write_event_config_new = &sca3000_write_event_config,
>> +	.read_event_value = &sca3000_read_thresh,
>> +	.write_event_value = &sca3000_write_thresh,
>> +	.read_event_config = &sca3000_read_event_config,
>> +	.write_event_config = &sca3000_write_event_config,
>>  	.driver_module = THIS_MODULE,
>>  };
>>  
>> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
>> index fa60764..dcd24ab 100644
>> --- a/drivers/staging/iio/adc/ad7291.c
>> +++ b/drivers/staging/iio/adc/ad7291.c
>> @@ -534,10 +534,10 @@ static struct attribute_group ad7291_event_attribute_group = {
>>  
>>  static const struct iio_info ad7291_info = {
>>  	.read_raw = &ad7291_read_raw,
>> -	.read_event_config_new = &ad7291_read_event_config,
>> -	.write_event_config_new = &ad7291_write_event_config,
>> -	.read_event_value_new = &ad7291_read_event_value,
>> -	.write_event_value_new = &ad7291_write_event_value,
>> +	.read_event_config = &ad7291_read_event_config,
>> +	.write_event_config = &ad7291_write_event_config,
>> +	.read_event_value = &ad7291_read_event_value,
>> +	.write_event_value = &ad7291_write_event_value,
>>  	.event_attrs = &ad7291_event_attribute_group,
>>  	.driver_module = THIS_MODULE,
>>  };
>> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
>> index 2b51cb4..73f7604 100644
>> --- a/drivers/staging/iio/adc/ad799x_core.c
>> +++ b/drivers/staging/iio/adc/ad799x_core.c
>> @@ -454,18 +454,18 @@ static const struct iio_info ad7991_info = {
>>  static const struct iio_info ad7992_info = {
>>  	.read_raw = &ad799x_read_raw,
>>  	.event_attrs = &ad7992_event_attrs_group,
>> -	.read_event_config_new = &ad799x_read_event_config,
>> -	.read_event_value_new = &ad799x_read_event_value,
>> -	.write_event_value_new = &ad799x_write_event_value,
>> +	.read_event_config = &ad799x_read_event_config,
>> +	.read_event_value = &ad799x_read_event_value,
>> +	.write_event_value = &ad799x_write_event_value,
>>  	.driver_module = THIS_MODULE,
>>  };
>>  
>>  static const struct iio_info ad7993_4_7_8_info = {
>>  	.read_raw = &ad799x_read_raw,
>>  	.event_attrs = &ad7993_4_7_8_event_attrs_group,
>> -	.read_event_config_new = &ad799x_read_event_config,
>> -	.read_event_value_new = &ad799x_read_event_value,
>> -	.write_event_value_new = &ad799x_write_event_value,
>> +	.read_event_config = &ad799x_read_event_config,
>> +	.read_event_value = &ad799x_read_event_value,
>> +	.write_event_value = &ad799x_write_event_value,
>>  	.driver_module = THIS_MODULE,
>>  	.update_scan_mode = ad7997_8_update_scan_mode,
>>  };
>> diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
>> index ec2cf6e..bb37bed 100644
>> --- a/drivers/staging/iio/cdc/ad7150.c
>> +++ b/drivers/staging/iio/cdc/ad7150.c
>> @@ -579,10 +579,10 @@ static const struct iio_info ad7150_info = {
>>  	.event_attrs = &ad7150_event_attribute_group,
>>  	.driver_module = THIS_MODULE,
>>  	.read_raw = &ad7150_read_raw,
>> -	.read_event_config_new = &ad7150_read_event_config,
>> -	.write_event_config_new = &ad7150_write_event_config,
>> -	.read_event_value_new = &ad7150_read_event_value,
>> -	.write_event_value_new = &ad7150_write_event_value,
>> +	.read_event_config = &ad7150_read_event_config,
>> +	.write_event_config = &ad7150_write_event_config,
>> +	.read_event_value = &ad7150_read_event_value,
>> +	.write_event_value = &ad7150_write_event_value,
>>  };
>>  
>>  /*
>> diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
>> index cdb8898..d3847fc 100644
>> --- a/drivers/staging/iio/iio_simple_dummy.c
>> +++ b/drivers/staging/iio/iio_simple_dummy.c
>> @@ -370,10 +370,10 @@ static const struct iio_info iio_dummy_info = {
>>  	.read_raw = &iio_dummy_read_raw,
>>  	.write_raw = &iio_dummy_write_raw,
>>  #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
>> -	.read_event_config_new = &iio_simple_dummy_read_event_config,
>> -	.write_event_config_new = &iio_simple_dummy_write_event_config,
>> -	.read_event_value_new = &iio_simple_dummy_read_event_value,
>> -	.write_event_value_new = &iio_simple_dummy_write_event_value,
>> +	.read_event_config = &iio_simple_dummy_read_event_config,
>> +	.write_event_config = &iio_simple_dummy_write_event_config,
>> +	.read_event_value = &iio_simple_dummy_read_event_value,
>> +	.write_event_value = &iio_simple_dummy_write_event_value,
>>  #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
>>  };
>>  
>> diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
>> index 1466f47..a429148 100644
>> --- a/drivers/staging/iio/light/tsl2x7x_core.c
>> +++ b/drivers/staging/iio/light/tsl2x7x_core.c
>> @@ -1672,10 +1672,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>>  		.driver_module = THIS_MODULE,
>>  		.read_raw = &tsl2x7x_read_raw,
>>  		.write_raw = &tsl2x7x_write_raw,
>> -		.read_event_value_new = &tsl2x7x_read_thresh,
>> -		.write_event_value_new = &tsl2x7x_write_thresh,
>> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
>> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
>> +		.read_event_value = &tsl2x7x_read_thresh,
>> +		.write_event_value = &tsl2x7x_write_thresh,
>> +		.read_event_config = &tsl2x7x_read_interrupt_config,
>> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>>  	},
>>  	[PRX] = {
>>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX],
>> @@ -1683,10 +1683,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>>  		.driver_module = THIS_MODULE,
>>  		.read_raw = &tsl2x7x_read_raw,
>>  		.write_raw = &tsl2x7x_write_raw,
>> -		.read_event_value_new = &tsl2x7x_read_thresh,
>> -		.write_event_value_new = &tsl2x7x_write_thresh,
>> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
>> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
>> +		.read_event_value = &tsl2x7x_read_thresh,
>> +		.write_event_value = &tsl2x7x_write_thresh,
>> +		.read_event_config = &tsl2x7x_read_interrupt_config,
>> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>>  	},
>>  	[ALSPRX] = {
>>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX],
>> @@ -1694,10 +1694,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>>  		.driver_module = THIS_MODULE,
>>  		.read_raw = &tsl2x7x_read_raw,
>>  		.write_raw = &tsl2x7x_write_raw,
>> -		.read_event_value_new = &tsl2x7x_read_thresh,
>> -		.write_event_value_new = &tsl2x7x_write_thresh,
>> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
>> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
>> +		.read_event_value = &tsl2x7x_read_thresh,
>> +		.write_event_value = &tsl2x7x_write_thresh,
>> +		.read_event_config = &tsl2x7x_read_interrupt_config,
>> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>>  	},
>>  	[PRX2] = {
>>  		.attrs = &tsl2X7X_device_attr_group_tbl[PRX2],
>> @@ -1705,10 +1705,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>>  		.driver_module = THIS_MODULE,
>>  		.read_raw = &tsl2x7x_read_raw,
>>  		.write_raw = &tsl2x7x_write_raw,
>> -		.read_event_value_new = &tsl2x7x_read_thresh,
>> -		.write_event_value_new = &tsl2x7x_write_thresh,
>> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
>> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
>> +		.read_event_value = &tsl2x7x_read_thresh,
>> +		.write_event_value = &tsl2x7x_write_thresh,
>> +		.read_event_config = &tsl2x7x_read_interrupt_config,
>> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>>  	},
>>  	[ALSPRX2] = {
>>  		.attrs = &tsl2X7X_device_attr_group_tbl[ALSPRX2],
>> @@ -1716,10 +1716,10 @@ static const struct iio_info tsl2X7X_device_info[] = {
>>  		.driver_module = THIS_MODULE,
>>  		.read_raw = &tsl2x7x_read_raw,
>>  		.write_raw = &tsl2x7x_write_raw,
>> -		.read_event_value_new = &tsl2x7x_read_thresh,
>> -		.write_event_value_new = &tsl2x7x_write_thresh,
>> -		.read_event_config_new = &tsl2x7x_read_interrupt_config,
>> -		.write_event_config_new = &tsl2x7x_write_interrupt_config,
>> +		.read_event_value = &tsl2x7x_read_thresh,
>> +		.write_event_value = &tsl2x7x_write_thresh,
>> +		.read_event_config = &tsl2x7x_read_interrupt_config,
>> +		.write_event_config = &tsl2x7x_write_interrupt_config,
>>  	},
>>  };
>>  
>> diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
>> index 5dab2c4..8bbd7bc 100644
>> --- a/include/linux/iio/events.h
>> +++ b/include/linux/iio/events.h
>> @@ -46,10 +46,6 @@ struct iio_event_data {
>>  	 ((u16)chan))
>>  
>>  
>> -#define IIO_EV_DIR_MAX 4
>> -#define IIO_EV_BIT(type, direction)			\
>> -	(1 << (type*IIO_EV_DIR_MAX + direction))
>> -
>>  /**
>>   * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
>>   * @chan_type:	Type of the channel. Should be one of enum iio_chan_type.
>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>> index 5a9fefe..2b783df 100644
>> --- a/include/linux/iio/iio.h
>> +++ b/include/linux/iio/iio.h
>> @@ -185,7 +185,6 @@ struct iio_event_spec {
>>   *			by all channels of the same direction.
>>   * @info_mask_shared_by_all: What information is to be exported that is shared
>>   *			by all channels.
>> - * @event_mask:		What events can this channel produce.
>>   * @event_spec:		Array of events which should be registered for this
>>   *			channel.
>>   * @num_event_specs:	Size of the event_spec array.
>> @@ -226,7 +225,6 @@ struct iio_chan_spec {
>>  	long			info_mask_shared_by_type;
>>  	long			info_mask_shared_by_dir;
>>  	long			info_mask_shared_by_all;
>> -	long			event_mask;
>>  	const struct iio_event_spec *event_spec;
>>  	unsigned int		num_event_specs;
>>  	const struct iio_chan_spec_ext_info *ext_info;
>> @@ -307,16 +305,8 @@ struct iio_dev;
>>   *			returns IIO_VAL_INT_PLUS_MICRO.
>>   * @read_event_config:	find out if the event is enabled.
>>   * @write_event_config:	set if the event is enabled.
>> - * @read_event_value:	read a value associated with the event. Meaning
>> - *			is event dependant. event_code specifies which event.
>> - * @write_event_value:	write the value associated with the event.
>> - *			Meaning is event dependent.
>> - * @read_event_config_new: find out if the event is enabled. New style interface.
>> - * @write_event_config_new: set if the event is enabled. New style interface.
>> - * @read_event_value_new: read a configuration value associated with the event.
>> - *                         New style interface.
>> - * @write_event_value_new: write a configuration value for the event. New style
>> - *			   interface.
>> + * @read_event_value:	read a configuration value associated with the event.
>> + * @write_event_value:	write a configuration value for the event.
>>   * @validate_trigger:	function to validate the trigger when the
>>   *			current trigger gets changed.
>>   * @update_scan_mode:	function to configure device and scan buffer when
>> @@ -345,37 +335,23 @@ struct iio_info {
>>  			 long mask);
>>  
>>  	int (*read_event_config)(struct iio_dev *indio_dev,
>> -				 u64 event_code);
>> -
>> -	int (*write_event_config)(struct iio_dev *indio_dev,
>> -				  u64 event_code,
>> -				  int state);
>> -
>> -	int (*read_event_value)(struct iio_dev *indio_dev,
>> -				u64 event_code,
>> -				int *val);
>> -	int (*write_event_value)(struct iio_dev *indio_dev,
>> -				 u64 event_code,
>> -				 int val);
>> -
>> -	int (*read_event_config_new)(struct iio_dev *indio_dev,
>>  				 const struct iio_chan_spec *chan,
>>  				 enum iio_event_type type,
>>  				 enum iio_event_direction dir);
>>  
>> -	int (*write_event_config_new)(struct iio_dev *indio_dev,
>> +	int (*write_event_config)(struct iio_dev *indio_dev,
>>  				  const struct iio_chan_spec *chan,
>>  				  enum iio_event_type type,
>>  				  enum iio_event_direction dir,
>>  				  int state);
>>  
>> -	int (*read_event_value_new)(struct iio_dev *indio_dev,
>> +	int (*read_event_value)(struct iio_dev *indio_dev,
>>  				const struct iio_chan_spec *chan,
>>  				enum iio_event_type type,
>>  				enum iio_event_direction dir,
>>  				enum iio_event_info info, int *val);
>>  
>> -	int (*write_event_value_new)(struct iio_dev *indio_dev,
>> +	int (*write_event_value)(struct iio_dev *indio_dev,
>>  				 const struct iio_chan_spec *chan,
>>  				 enum iio_event_type type,
>>  				 enum iio_event_direction dir,
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 07/18] staging:iio:lis3l02dq: Switch to new event config interface
  2013-10-01  7:51     ` Lars-Peter Clausen
@ 2013-10-01  9:14       ` Jonathan Cameron
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Cameron @ 2013-10-01  9:14 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 10/01/13 08:51, Lars-Peter Clausen wrote:
> On 09/30/2013 10:55 PM, Jonathan Cameron wrote:
>> On 09/26/13 13:58, Lars-Peter Clausen wrote:
>>> Switch the lis3l02dq 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>
>> Hi Lars,
>>
>> As this one is in staging, lets take advantage of the fact that we now
>> have the ability to have shared elements.  It's an ABI change so I wouldn't
>> suggest this for drivers outside staging.
>>
>> The threshold value is shared by all channels (only one address to write) for each
>> of the two types.
> 
> Ok, I'll add that to the series, but as a separate patch. One patch for
> changing to the new API, one patch for changing the behavior.
> 
> - Lars
Great, thanks for doing this.
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 01/18] iio: Extend the event config interface
  2013-09-29 20:17     ` Jonathan Cameron
  2013-09-29 19:35       ` Lars-Peter Clausen
@ 2013-10-04  8:38       ` Lars-Peter Clausen
  1 sibling, 0 replies; 31+ messages in thread
From: Lars-Peter Clausen @ 2013-10-04  8:38 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 09/29/2013 10:17 PM, Jonathan Cameron wrote:
> On 09/29/13 19:56, Lars-Peter Clausen wrote:
>> I think a transparent union should work nicely and doesn't cause any code
>> churn. Maybe even with a direct pointer to the event_spec.
>>
>> Something like:
>>
>> struct iio_dev_attr {
>> 	...
>> 	union {
>> 		u64 address;
>> 		struct {
>> 			struct iio_event_spec *spec;
>> 			enum iio_event_info info;
>> 		} event;
>> 	};
>> 	...
>> };
> Looks good to me.

There is a bug[1] in gcc < 4.6 that breaks this for static struct
initializers. E.g.

static struct iio_dev_attr attr = {
	...
	.address = 123,
	...
};

wont work. So I guess this means we can't use it for now.

- Lars

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2013-10-04  8:38 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 04/18] iio:gp2ap020a00f: " Lars-Peter Clausen
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.