All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/13] Staging: IIO: ABI changes round 1, V1
@ 2010-03-28 20:41 Jonathan Cameron
  2010-03-28 20:41 ` [PATCH 01/13] staging:iio: Add new in_raw definitions for adc channels Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Dear All,

This is the first set of patches related to the new abi as discussed on
lkml http://lkml.org/lkml/2010/2/5/205  I will post them more generally
(i.e. lkml) in a week ammended as appropriate.  Note these will cause
extensive breakage in any drivers not currently in the mainline tree
(so most of them :) but hopefully the changes required are fairly minimal.

Practical issues lead to a few minor changes.  Firstly the 'scan_elements'
directory still exists in the main device directory. This is mainly
because moving it into the buffer0 directory will add complexity
to handling the addition of multiple choices of buffer type.

One other question that came up during this, was how to name triggers
that are associated closely with a device.  Those trigger not associated
with a device should be named trigger0 etc with their own idr to handle
numbering.  But for those cases where there is a device, should they
be device[n]:trigger0 or device[n]:trigger[m] where m is based on the
the trigger idr?  At the moment they are still all as trigger[m]
in /sys/bus/iio/devices but this obviously doesn't give quite as much
info as is available for all the other elements associated with a given
physical device?

I'm afraid the ordering of these patches is a little random but as they
are here they shouldn't cause any breakage and I'd rather not waste time
putting them in a more sensible order.

Note the changes to max1363 are large. This is mainly because the driver
previously used a completely different means of controlling scan elements
to all others and hence that code needed a thorough rewrite.  This probably
still needs more work, but is informative to others in its current
state.

Note these patches are against 2.6.34-rc2 and as such do not include a
number of fixes that people have set out and which are in Greg's
and Andrew's trees at the moment.

Thanks,

Jonathan

Jonathan Cameron (13):
  staging:iio: Add new in_raw definitions for adc channels.
  staging:iio: Add new attrs for sampling frequency available and
    temp_raw
  iio:staging:accelerometers move towards the new abi
  staging:iio: Support functions for scan mask matching
  staging: iio: Move from class to bus
  staging:iio: Move event attributes into the event[n] device in sysfs
  staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C
  staging:iio:max1363 move to new abi.
  staging:iio: Documentation, update iio_utils.h for the move to a bus
  staging:iio: ABI documentation (partial)
  staging:iio: Directory name changes to match new ABI.
  staging:iio:tsl2563: change lux to illuminanc0_input to match new abi
  staging:iio: Remove naming via IDR's where no longer necessary under
    new abi.

 drivers/staging/iio/Documentation/iio_utils.h     |   31 +-
 drivers/staging/iio/Documentation/sysfs-class-iio |  265 +++++++
 drivers/staging/iio/accel/accel.h                 |    8 +-
 drivers/staging/iio/accel/kxsd9.c                 |   88 ++-
 drivers/staging/iio/accel/lis3l02dq.h             |    4 -
 drivers/staging/iio/accel/lis3l02dq_core.c        |  175 +++---
 drivers/staging/iio/accel/lis3l02dq_ring.c        |   10 +-
 drivers/staging/iio/accel/sca3000.h               |    2 +
 drivers/staging/iio/accel/sca3000_core.c          |  174 +++---
 drivers/staging/iio/accel/sca3000_ring.c          |   33 +-
 drivers/staging/iio/adc/Kconfig                   |    1 +
 drivers/staging/iio/adc/Makefile                  |    2 +-
 drivers/staging/iio/adc/adc.h                     |   12 +
 drivers/staging/iio/adc/max1363.h                 |  122 ++--
 drivers/staging/iio/adc/max1363_core.c            |  762 ++++++++++++---------
 drivers/staging/iio/adc/max1363_ring.c            |   67 ++-
 drivers/staging/iio/chrdev.h                      |    2 +-
 drivers/staging/iio/iio.h                         |   46 ++-
 drivers/staging/iio/industrialio-core.c           |   58 +-
 drivers/staging/iio/industrialio-ring.c           |   63 +--
 drivers/staging/iio/industrialio-trigger.c        |    2 +-
 drivers/staging/iio/light/tsl2563.c               |    4 +-
 drivers/staging/iio/ring_generic.h                |   42 +-
 drivers/staging/iio/ring_sw.c                     |    2 +-
 drivers/staging/iio/sysfs.h                       |   15 +-
 25 files changed, 1244 insertions(+), 746 deletions(-)
 create mode 100644 drivers/staging/iio/Documentation/sysfs-class-iio

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

* [PATCH 01/13] staging:iio: Add new in_raw definitions for adc channels.
  2010-03-28 20:41 [PATCH 00/13] Staging: IIO: ABI changes round 1, V1 Jonathan Cameron
@ 2010-03-28 20:41 ` Jonathan Cameron
  2010-03-28 20:41   ` [PATCH 02/13] staging:iio: Add new attrs for sampling frequency available and temp_raw Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/adc/adc.h |   12 ++++++++++++
 drivers/staging/iio/sysfs.h   |    3 +++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/iio/adc/adc.h b/drivers/staging/iio/adc/adc.h
index d925b2c..46f0d08 100644
--- a/drivers/staging/iio/adc/adc.h
+++ b/drivers/staging/iio/adc/adc.h
@@ -9,5 +9,17 @@
  *
  */
 
+/* Deprecated */
 #define IIO_DEV_ATTR_ADC(_num, _show, _addr)			\
   IIO_DEVICE_ATTR(adc_##_num, S_IRUGO, _show, NULL, _addr)
+
+#define IIO_DEV_ATTR_IN_RAW(_num, _show, _addr)				\
+	IIO_DEVICE_ATTR(in##_num##_raw, S_IRUGO, _show, NULL, _addr)
+
+#define IIO_DEV_ATTR_IN_DIFF_RAW(_nump, _numn, _show, _addr)		\
+	IIO_DEVICE_ATTR_NAMED(in##_nump##min##_numn##_raw,		\
+			      in##_nump-in##_numn##_raw,		\
+			      S_IRUGO,					\
+			      _show,					\
+			      NULL,					\
+			      _addr)
diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
index e501e13..d8fe0e2 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/drivers/staging/iio/sysfs.h
@@ -98,6 +98,9 @@ struct iio_const_attr {
 	struct iio_dev_attr iio_dev_attr_##_name		\
 	= IIO_ATTR(_name, _mode, _show, _store, _addr)
 
+#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
+	struct iio_dev_attr iio_dev_attr_##_vname			\
+	= IIO_ATTR(_name, _mode, _show, _store, _addr)
 
 #define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2)	\
 	struct iio_dev_attr iio_dev_attr_##_name			\
-- 
1.6.4.4


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

* [PATCH 02/13] staging:iio: Add new attrs for sampling frequency available and temp_raw
  2010-03-28 20:41 ` [PATCH 01/13] staging:iio: Add new in_raw definitions for adc channels Jonathan Cameron
@ 2010-03-28 20:41   ` Jonathan Cameron
  2010-03-28 20:41     ` [PATCH 03/13] iio:staging:accelerometers move towards the new abi Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/sysfs.h |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
index d8fe0e2..afcf5ab 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/drivers/staging/iio/sysfs.h
@@ -144,18 +144,25 @@ struct iio_const_attr {
  *
  * May be mode dependent on some devices
  **/
+/* Deprecated */
 #define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show)				\
 	IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
 
+#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show)				\
+	IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
 /**
  * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
  * @_string: frequency string for the attribute
  *
  * Constant version
  **/
-#define IIO_CONST_ATTR_AVAIL_SAMP_FREQ(_string)	\
+/* Deprecated */
+#define IIO_CONST_ATTR_AVAIL_SAMP_FREQ(_string)			\
 	IIO_CONST_ATTR(available_sampling_frequency, _string)
 
+#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string)			\
+	IIO_CONST_ATTR(sampling_frequency_available, _string)
+
 /**
  * IIO_DEV_ATTR_SCAN_MODE - select a scan mode
  * @_mode: sysfs file mode/permissions
@@ -234,6 +241,9 @@ struct iio_const_attr {
 #define IIO_DEV_ATTR_TEMP(_show)			\
 	IIO_DEVICE_ATTR(temp, S_IRUGO, _show, NULL, 0)
 
+#define IIO_DEV_ATTR_TEMP_RAW(_show)			\
+	IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
+
 /**
  * IIO_EVENT_SH - generic shared event handler
  * @_name: event name
-- 
1.6.4.4

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

* [PATCH 03/13] iio:staging:accelerometers move towards the new abi
  2010-03-28 20:41   ` [PATCH 02/13] staging:iio: Add new attrs for sampling frequency available and temp_raw Jonathan Cameron
@ 2010-03-28 20:41     ` Jonathan Cameron
  2010-03-28 20:41       ` [PATCH 04/13] staging:iio: Support functions for scan mask matching Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/accel/accel.h          |    8 +-
 drivers/staging/iio/accel/kxsd9.c          |   88 ++++++++------
 drivers/staging/iio/accel/lis3l02dq.h      |    4 -
 drivers/staging/iio/accel/lis3l02dq_core.c |  175 ++++++++++++++-------------
 drivers/staging/iio/accel/lis3l02dq_ring.c |    8 +-
 drivers/staging/iio/accel/sca3000.h        |    2 +
 drivers/staging/iio/accel/sca3000_core.c   |  172 +++++++++++++--------------
 drivers/staging/iio/accel/sca3000_ring.c   |   33 ++++--
 drivers/staging/iio/ring_generic.h         |    4 +-
 9 files changed, 262 insertions(+), 232 deletions(-)

diff --git a/drivers/staging/iio/accel/accel.h b/drivers/staging/iio/accel/accel.h
index d7fc7f9..059209c 100644
--- a/drivers/staging/iio/accel/accel.h
+++ b/drivers/staging/iio/accel/accel.h
@@ -2,7 +2,6 @@
 #include "../sysfs.h"
 
 /* Accelerometer types of attribute */
-
 #define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)	\
 	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
 
@@ -22,13 +21,13 @@
 	IIO_DEVICE_ATTR(accel_z_gain, _mode, _show, _store, _addr)
 
 #define IIO_DEV_ATTR_ACCEL_X(_show, _addr)			\
-	IIO_DEVICE_ATTR(accel_x, S_IRUGO, _show, NULL, _addr)
+	IIO_DEVICE_ATTR(accel_x_raw, S_IRUGO, _show, NULL, _addr)
 
 #define IIO_DEV_ATTR_ACCEL_Y(_show, _addr)			\
-	IIO_DEVICE_ATTR(accel_y, S_IRUGO, _show, NULL, _addr)
+	IIO_DEVICE_ATTR(accel_y_raw, S_IRUGO, _show, NULL, _addr)
 
 #define IIO_DEV_ATTR_ACCEL_Z(_show, _addr)			\
-	IIO_DEVICE_ATTR(accel_z, S_IRUGO, _show, NULL, _addr)
+	IIO_DEVICE_ATTR(accel_z_raw, S_IRUGO, _show, NULL, _addr)
 
 /* Thresholds are somewhat chip dependent - may need quite a few defs here */
 /* For unified thresholds (shared across all directions */
@@ -61,7 +60,6 @@
 #define IIO_DEV_ATTR_ACCEL_THRESH_Z(_mode, _show, _store, _addr)	\
 	IIO_DEVICE_ATTR(thresh_accel_z, _mode, _show, _store, _addr)
 
-
 /**
  * IIO_EVENT_ATTR_ACCEL_X_HIGH: threshold event, x acceleration
  * @_show: read x acceleration high threshold
diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c
index 33d16b6..65824e3 100644
--- a/drivers/staging/iio/accel/kxsd9.c
+++ b/drivers/staging/iio/accel/kxsd9.c
@@ -25,6 +25,7 @@
 #include <linux/sysfs.h>
 #include <linux/rtc.h>
 #include <linux/delay.h>
+#include <linux/string.h>
 
 #include "../iio.h"
 #include "../sysfs.h"
@@ -50,8 +51,10 @@
 #define KXSD9_READ(a) (0x80 | (a))
 #define KXSD9_WRITE(a) (a)
 
-#define IIO_DEV_ATTR_ACCEL_SET_RANGE(_mode, _show, _store)	\
-	IIO_DEVICE_ATTR(accel_range, _mode, _show, _store, 0)
+#define KXSD9_SCALE_2G "0.011978"
+#define KXSD9_SCALE_4G "0.023927"
+#define KXSD9_SCALE_6G "0.035934"
+#define KXSD9_SCALE_8G "0.047853"
 
 #define KXSD9_STATE_RX_SIZE 2
 #define KXSD9_STATE_TX_SIZE 4
@@ -72,9 +75,9 @@ struct kxsd9_state {
 };
 
 /* This may want to move to mili g to allow for non integer ranges */
-static ssize_t kxsd9_read_accel_range(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
+static ssize_t kxsd9_read_scale(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
 {
 	int ret;
 	ssize_t len = 0;
@@ -100,16 +103,16 @@ static ssize_t kxsd9_read_accel_range(struct device *dev,
 
 	switch (st->rx[1] & KXSD9_FS_MASK) {
 	case KXSD9_FS_8:
-		len += sprintf(buf, "8\n");
+		len += sprintf(buf, "%s\n", KXSD9_SCALE_8G);
 		break;
 	case KXSD9_FS_6:
-		len += sprintf(buf, "6\n");
+		len += sprintf(buf, "%s\n", KXSD9_SCALE_6G);
 		break;
 	case KXSD9_FS_4:
-		len += sprintf(buf, "4\n");
+		len += sprintf(buf, "%s\n", KXSD9_SCALE_4G);
 		break;
 	case KXSD9_FS_2:
-		len += sprintf(buf, "2\n");
+		len += sprintf(buf, "%s\n", KXSD9_SCALE_2G);
 		break;
 	}
 
@@ -118,12 +121,12 @@ error_ret:
 
 	return ret ? ret : len;
 }
-static ssize_t kxsd9_write_accel_range(struct device *dev,
-				      struct device_attribute *attr,
-				      const char *buf,
-				      size_t len)
+static ssize_t kxsd9_write_scale(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf,
+				 size_t len)
 {
-	long readin;
+
 	struct spi_message msg;
 	int ret;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
@@ -144,25 +147,25 @@ static ssize_t kxsd9_write_accel_range(struct device *dev,
 		},
 	};
 
-	ret = strict_strtol(buf, 10, &readin);
-	if (ret)
-		return ret;
-	switch (readin) {
-	case 8:
+	if (!strncmp(buf, KXSD9_SCALE_8G,
+		     strlen(buf) < strlen(KXSD9_SCALE_8G)
+		     ? strlen(buf) : strlen(KXSD9_SCALE_8G)))
 		val = KXSD9_FS_8;
-		break;
-	case 6:
+	else if (!strncmp(buf, KXSD9_SCALE_6G,
+			  strlen(buf) < strlen(KXSD9_SCALE_6G)
+			  ? strlen(buf) : strlen(KXSD9_SCALE_6G)))
 		val = KXSD9_FS_6;
-		break;
-	case 4:
+	else if (!strncmp(buf, KXSD9_SCALE_4G,
+			  strlen(buf) < strlen(KXSD9_SCALE_4G)
+			  ? strlen(buf) : strlen(KXSD9_SCALE_4G)))
 		val = KXSD9_FS_4;
-		break;
-	case 2:
+	else if (!strncmp(buf, KXSD9_SCALE_2G,
+			  strlen(buf) < strlen(KXSD9_SCALE_2G)
+			  ? strlen(buf) : strlen(KXSD9_SCALE_2G)))
 		val = KXSD9_FS_2;
-		break;
-	default:
+	else
 		return -EINVAL;
-	}
+
 	mutex_lock(&st->buf_lock);
 	st->tx[0] = KXSD9_READ(KXSD9_REG_CTRL_C);
 	st->tx[1] = 0;
@@ -181,6 +184,7 @@ error_ret:
 	mutex_unlock(&st->buf_lock);
 	return ret ? ret : len;
 }
+
 static ssize_t kxsd9_read_accel(struct device *dev,
 				struct device_attribute *attr,
 				char *buf)
@@ -226,17 +230,27 @@ error_ret:
 static IIO_DEV_ATTR_ACCEL_X(kxsd9_read_accel, KXSD9_REG_X);
 static IIO_DEV_ATTR_ACCEL_Y(kxsd9_read_accel, KXSD9_REG_Y);
 static IIO_DEV_ATTR_ACCEL_Z(kxsd9_read_accel, KXSD9_REG_Z);
-static IIO_DEV_ATTR_ADC(0, kxsd9_read_accel, KXSD9_REG_AUX);
-static IIO_DEV_ATTR_ACCEL_SET_RANGE(S_IRUGO | S_IWUSR,
-				    kxsd9_read_accel_range,
-				    kxsd9_write_accel_range);
+static IIO_DEV_ATTR_IN_RAW(0, kxsd9_read_accel, KXSD9_REG_AUX);
+
+static IIO_DEVICE_ATTR(accel_scale,
+		S_IRUGO | S_IWUSR,
+		kxsd9_read_scale,
+		kxsd9_write_scale,
+		0);
+
+static IIO_CONST_ATTR(accel_scale_available,
+		KXSD9_SCALE_2G " "
+		KXSD9_SCALE_4G " "
+		KXSD9_SCALE_6G " "
+		KXSD9_SCALE_8G);
 
 static struct attribute *kxsd9_attributes[] = {
-	&iio_dev_attr_accel_x.dev_attr.attr,
-	&iio_dev_attr_accel_y.dev_attr.attr,
-	&iio_dev_attr_accel_z.dev_attr.attr,
-	&iio_dev_attr_adc_0.dev_attr.attr,
-	&iio_dev_attr_accel_range.dev_attr.attr,
+	&iio_dev_attr_accel_x_raw.dev_attr.attr,
+	&iio_dev_attr_accel_y_raw.dev_attr.attr,
+	&iio_dev_attr_accel_z_raw.dev_attr.attr,
+	&iio_dev_attr_in0_raw.dev_attr.attr,
+	&iio_dev_attr_accel_scale.dev_attr.attr,
+	&iio_const_attr_accel_scale_available.dev_attr.attr,
 	NULL,
 };
 
diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
index 91a5375..e76a979 100644
--- a/drivers/staging/iio/accel/lis3l02dq.h
+++ b/drivers/staging/iio/accel/lis3l02dq.h
@@ -179,10 +179,6 @@ int lis3l02dq_spi_read_reg_8(struct device *dev,
 int lis3l02dq_spi_write_reg_8(struct device *dev,
 			      u8 reg_address,
 			      u8 *val);
-#define LIS3L02DQ_SCAN_ACC_X 0
-#define LIS3L02DQ_SCAN_ACC_Y 1
-#define LIS3L02DQ_SCAN_ACC_Z 2
-
 
 #ifdef CONFIG_IIO_RING_BUFFER
 /* At the moment triggers are only used for ring buffer
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index f008837..4e9debc 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -457,41 +457,39 @@ err_ret:
 	return ret;
 }
 
-static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
-				   lis3l02dq_read_signed,
-				   lis3l02dq_write_signed,
-				   LIS3L02DQ_REG_OFFSET_X_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
-				   lis3l02dq_read_signed,
-				   lis3l02dq_write_signed,
-				   LIS3L02DQ_REG_OFFSET_Y_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
-				   lis3l02dq_read_signed,
-				   lis3l02dq_write_signed,
-				   LIS3L02DQ_REG_OFFSET_Z_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_X_GAIN(S_IWUSR | S_IRUGO,
-				 lis3l02dq_read_unsigned,
-				 lis3l02dq_write_unsigned,
-				 LIS3L02DQ_REG_GAIN_X_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_Y_GAIN(S_IWUSR | S_IRUGO,
-				 lis3l02dq_read_unsigned,
-				 lis3l02dq_write_unsigned,
-				 LIS3L02DQ_REG_GAIN_Y_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_Z_GAIN(S_IWUSR | S_IRUGO,
-				 lis3l02dq_read_unsigned,
-				 lis3l02dq_write_unsigned,
-				 LIS3L02DQ_REG_GAIN_Z_ADDR);
-
-static IIO_DEV_ATTR_ACCEL_THRESH(S_IWUSR | S_IRUGO,
-				 lis3l02dq_read_16bit_signed,
-				 lis3l02dq_write_16bit_signed,
-				 LIS3L02DQ_REG_THS_L_ADDR);
-
+#define LIS3L02DQ_SIGNED_ATTR(name, reg)	\
+	IIO_DEVICE_ATTR(name,			\
+			S_IWUSR | S_IRUGO,	\
+			lis3l02dq_read_signed,	\
+			lis3l02dq_write_signed, \
+			reg);
+
+#define LIS3L02DQ_UNSIGNED_ATTR(name, reg)		\
+	IIO_DEVICE_ATTR(name,				\
+			S_IWUSR | S_IRUGO,		\
+			lis3l02dq_read_unsigned,	\
+			lis3l02dq_write_unsigned,	\
+			reg);
+
+static LIS3L02DQ_SIGNED_ATTR(accel_x_calibbias,
+			     LIS3L02DQ_REG_OFFSET_X_ADDR);
+static LIS3L02DQ_SIGNED_ATTR(accel_y_calibbias,
+			     LIS3L02DQ_REG_OFFSET_Y_ADDR);
+static LIS3L02DQ_SIGNED_ATTR(accel_z_calibbias,
+			     LIS3L02DQ_REG_OFFSET_Z_ADDR);
+
+static LIS3L02DQ_UNSIGNED_ATTR(accel_x_calibscale,
+			       LIS3L02DQ_REG_GAIN_X_ADDR);
+static LIS3L02DQ_UNSIGNED_ATTR(accel_y_calibscale,
+			       LIS3L02DQ_REG_GAIN_Y_ADDR);
+static LIS3L02DQ_UNSIGNED_ATTR(accel_z_calibscale,
+			       LIS3L02DQ_REG_GAIN_Z_ADDR);
+
+static IIO_DEVICE_ATTR(accel_mag_either_rising,
+		       S_IWUSR | S_IRUGO,
+		       lis3l02dq_read_16bit_signed,
+		       lis3l02dq_write_16bit_signed,
+		       LIS3L02DQ_REG_THS_L_ADDR);
 /* RFC The reading method for these will change depending on whether
  * ring buffer capture is in use. Is it worth making these take two
  * functions and let the core handle which to call, or leave as in this
@@ -511,7 +509,7 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
 			      lis3l02dq_read_frequency,
 			      lis3l02dq_write_frequency);
 
-static IIO_CONST_ATTR_AVAIL_SAMP_FREQ("280 560 1120 4480");
+static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("280 560 1120 4480");
 
 static ssize_t lis3l02dq_read_interrupt_config(struct device *dev,
 					       struct device_attribute *attr,
@@ -521,7 +519,7 @@ static ssize_t lis3l02dq_read_interrupt_config(struct device *dev,
 	s8 val;
 	struct iio_event_attr *this_attr = to_iio_event_attr(attr);
 
-	ret = lis3l02dq_spi_read_reg_8(dev,
+	ret = lis3l02dq_spi_read_reg_8(dev->parent,
 				       LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
 				       (u8 *)&val);
 
@@ -544,7 +542,7 @@ static ssize_t lis3l02dq_write_interrupt_config(struct device *dev,
 
 	mutex_lock(&indio_dev->mlock);
 	/* read current value */
-	ret = lis3l02dq_spi_read_reg_8(dev,
+	ret = lis3l02dq_spi_read_reg_8(dev->parent,
 				       LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
 				       &valold);
 	if (ret)
@@ -617,7 +615,7 @@ static int lis3l02dq_thresh_handler_th(struct iio_dev *dev_info,
 static void lis3l02dq_thresh_handler_bh_no_check(struct work_struct *work_s)
 {
 	struct iio_work_cont *wc
-		= container_of(work_s, struct iio_work_cont, ws_nocheck);
+		= container_of(work_s, struct iio_work_cont, ws);
 	struct lis3l02dq_state *st = wc->st;
 	u8 t;
 
@@ -667,43 +665,51 @@ static void lis3l02dq_thresh_handler_bh_no_check(struct work_struct *work_s)
 /* A shared handler for a number of threshold types */
 IIO_EVENT_SH(threshold, &lis3l02dq_thresh_handler_th);
 
-IIO_EVENT_ATTR_ACCEL_X_HIGH_SH(iio_event_threshold,
-			       lis3l02dq_read_interrupt_config,
-			       lis3l02dq_write_interrupt_config,
-			       LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_HIGH);
-
-IIO_EVENT_ATTR_ACCEL_Y_HIGH_SH(iio_event_threshold,
-			       lis3l02dq_read_interrupt_config,
-			       lis3l02dq_write_interrupt_config,
-			       LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_HIGH);
-
-IIO_EVENT_ATTR_ACCEL_Z_HIGH_SH(iio_event_threshold,
-			       lis3l02dq_read_interrupt_config,
-			       lis3l02dq_write_interrupt_config,
-			       LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_HIGH);
-
-IIO_EVENT_ATTR_ACCEL_X_LOW_SH(iio_event_threshold,
-			      lis3l02dq_read_interrupt_config,
-			      lis3l02dq_write_interrupt_config,
-			      LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_LOW);
-
-IIO_EVENT_ATTR_ACCEL_Y_LOW_SH(iio_event_threshold,
-			      lis3l02dq_read_interrupt_config,
-			      lis3l02dq_write_interrupt_config,
-			      LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_LOW);
+IIO_EVENT_ATTR_SH(accel_x_mag_pos_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_HIGH);
+
+IIO_EVENT_ATTR_SH(accel_y_mag_pos_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_HIGH);
+
+IIO_EVENT_ATTR_SH(accel_z_mag_pos_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_HIGH);
+
+IIO_EVENT_ATTR_SH(accel_x_mag_neg_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_X_LOW);
+
+IIO_EVENT_ATTR_SH(accel_y_mag_neg_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Y_LOW);
+
+IIO_EVENT_ATTR_SH(accel_z_mag_neg_rising,
+		  iio_event_threshold,
+		  lis3l02dq_read_interrupt_config,
+		  lis3l02dq_write_interrupt_config,
+		  LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_LOW);
 
-IIO_EVENT_ATTR_ACCEL_Z_LOW_SH(iio_event_threshold,
-			      lis3l02dq_read_interrupt_config,
-			      lis3l02dq_write_interrupt_config,
-			      LIS3L02DQ_REG_WAKE_UP_CFG_INTERRUPT_Z_LOW);
 
 static struct attribute *lis3l02dq_event_attributes[] = {
-	&iio_event_attr_accel_x_high.dev_attr.attr,
-	&iio_event_attr_accel_y_high.dev_attr.attr,
-	&iio_event_attr_accel_z_high.dev_attr.attr,
-	&iio_event_attr_accel_x_low.dev_attr.attr,
-	&iio_event_attr_accel_y_low.dev_attr.attr,
-	&iio_event_attr_accel_z_low.dev_attr.attr,
+	&iio_event_attr_accel_x_mag_pos_rising.dev_attr.attr,
+	&iio_event_attr_accel_y_mag_pos_rising.dev_attr.attr,
+	&iio_event_attr_accel_z_mag_pos_rising.dev_attr.attr,
+	&iio_event_attr_accel_x_mag_neg_rising.dev_attr.attr,
+	&iio_event_attr_accel_y_mag_neg_rising.dev_attr.attr,
+	&iio_event_attr_accel_z_mag_neg_rising.dev_attr.attr,
+	&iio_dev_attr_accel_mag_either_rising.dev_attr.attr,
 	NULL
 };
 
@@ -712,20 +718,21 @@ static struct attribute_group lis3l02dq_event_attribute_group = {
 };
 
 static IIO_CONST_ATTR(name, "lis3l02dq");
+static IIO_CONST_ATTR(accel_scale, "0.00958");
 
 static struct attribute *lis3l02dq_attributes[] = {
-	&iio_dev_attr_accel_x_offset.dev_attr.attr,
-	&iio_dev_attr_accel_y_offset.dev_attr.attr,
-	&iio_dev_attr_accel_z_offset.dev_attr.attr,
-	&iio_dev_attr_accel_x_gain.dev_attr.attr,
-	&iio_dev_attr_accel_y_gain.dev_attr.attr,
-	&iio_dev_attr_accel_z_gain.dev_attr.attr,
-	&iio_dev_attr_thresh.dev_attr.attr,
-	&iio_dev_attr_accel_x.dev_attr.attr,
-	&iio_dev_attr_accel_y.dev_attr.attr,
-	&iio_dev_attr_accel_z.dev_attr.attr,
+	&iio_dev_attr_accel_x_calibbias.dev_attr.attr,
+	&iio_dev_attr_accel_y_calibbias.dev_attr.attr,
+	&iio_dev_attr_accel_z_calibbias.dev_attr.attr,
+	&iio_dev_attr_accel_x_calibscale.dev_attr.attr,
+	&iio_dev_attr_accel_y_calibscale.dev_attr.attr,
+	&iio_dev_attr_accel_z_calibscale.dev_attr.attr,
+	&iio_const_attr_accel_scale.dev_attr.attr,
+	&iio_dev_attr_accel_x_raw.dev_attr.attr,
+	&iio_dev_attr_accel_y_raw.dev_attr.attr,
+	&iio_dev_attr_accel_z_raw.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency.dev_attr.attr,
-	&iio_const_attr_available_sampling_frequency.dev_attr.attr,
+	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
 	&iio_const_attr_name.dev_attr.attr,
 	NULL
 };
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index a6b7c72..bfd0cda 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -74,16 +74,16 @@ error_ret:
 	return ret;
 
 }
-static IIO_SCAN_EL_C(accel_x, LIS3L02DQ_SCAN_ACC_X, IIO_SIGNED(16),
+static IIO_SCAN_EL_C(accel_x, 0, IIO_SIGNED(16),
 		     LIS3L02DQ_REG_OUT_X_L_ADDR,
 		     &lis3l02dq_scan_el_set_state);
-static IIO_SCAN_EL_C(accel_y, LIS3L02DQ_SCAN_ACC_Y, IIO_SIGNED(16),
+static IIO_SCAN_EL_C(accel_y, 1, IIO_SIGNED(16),
 		     LIS3L02DQ_REG_OUT_Y_L_ADDR,
 		     &lis3l02dq_scan_el_set_state);
-static IIO_SCAN_EL_C(accel_z, LIS3L02DQ_SCAN_ACC_Z, IIO_SIGNED(16),
+static IIO_SCAN_EL_C(accel_z, 2, IIO_SIGNED(16),
 		     LIS3L02DQ_REG_OUT_Z_L_ADDR,
 		     &lis3l02dq_scan_el_set_state);
-static IIO_SCAN_EL_TIMESTAMP;
+static IIO_SCAN_EL_TIMESTAMP(3);
 
 static struct attribute *lis3l02dq_scan_el_attrs[] = {
 	&iio_scan_el_accel_x.dev_attr.attr,
diff --git a/drivers/staging/iio/accel/sca3000.h b/drivers/staging/iio/accel/sca3000.h
index da7d3cb..e532199 100644
--- a/drivers/staging/iio/accel/sca3000.h
+++ b/drivers/staging/iio/accel/sca3000.h
@@ -187,6 +187,7 @@ struct sca3000_state {
 /**
  * struct sca3000_chip_info - model dependant parameters
  * @name: 			model identification
+ * @scale:			string containing floating point scale factor
  * @temp_output:		some devices have temperature sensors.
  * @measurement_mode_freq:	normal mode sampling frequency
  * @option_mode_1:		first optional mode. Not all models have one
@@ -199,6 +200,7 @@ struct sca3000_state {
  **/
 struct sca3000_chip_info {
 	const char		*name;
+	const char		*scale;
 	bool			temp_output;
 	int			measurement_mode_freq;
 	int			option_mode_1;
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index cedcaa2..f0f7e80 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -26,11 +26,9 @@
 
 enum sca3000_variant {
 	d01,
-	d03,
 	e02,
 	e04,
 	e05,
-	l01,
 };
 
 /* Note where option modes are not defined, the chip simply does not
@@ -43,21 +41,20 @@ enum sca3000_variant {
 static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
 	{
 		.name = "sca3000-d01",
+		.scale = " 0.0073575",
 		.temp_output = true,
 		.measurement_mode_freq = 250,
 		.option_mode_1 = SCA3000_OP_MODE_BYPASS,
 		.option_mode_1_freq = 250,
 	}, {
-		/* No data sheet available - may be the same as the 3100-d03?*/
-		.name = "sca3000-d03",
-		.temp_output = true,
-	}, {
 		.name = "sca3000-e02",
+		.scale = "0.00981",
 		.measurement_mode_freq = 125,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 63,
 	}, {
 		.name = "sca3000-e04",
+		.scale = "0.01962",
 		.measurement_mode_freq = 100,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 50,
@@ -65,18 +62,12 @@ static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
 		.option_mode_2_freq = 400,
 	}, {
 		.name = "sca3000-e05",
+		.scale = "0.0613125",
 		.measurement_mode_freq = 200,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 50,
 		.option_mode_2 = SCA3000_OP_MODE_WIDE,
 		.option_mode_2_freq = 400,
-	}, {
-		/* No data sheet available.
-		 * Frequencies are unknown.
-		 */
-		.name = "sca3000-l01",
-		.temp_output = true,
-		.option_mode_1 = SCA3000_OP_MODE_BYPASS,
 	},
 };
 
@@ -326,6 +317,14 @@ error_ret:
 	return ret ? ret : len;
 }
 
+static ssize_t sca3000_show_scale(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct sca3000_state *st = dev_info->dev_data;
+	return sprintf(buf, "%s\n", st->info->scale);
+}
 
 static ssize_t sca3000_show_name(struct device *dev,
 				 struct device_attribute *attr,
@@ -494,7 +493,7 @@ error_ret:
 /* Not even vaguely standard attributes so defined here rather than
  * in the relevant IIO core headers
  */
-static IIO_DEVICE_ATTR(available_measurement_modes, S_IRUGO,
+static IIO_DEVICE_ATTR(measurement_mode_available, S_IRUGO,
 		       sca3000_show_available_measurement_modes,
 		       NULL, 0);
 
@@ -507,6 +506,8 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
 
 static IIO_DEV_ATTR_NAME(sca3000_show_name);
 static IIO_DEV_ATTR_REV(sca3000_show_rev);
+static IIO_DEVICE_ATTR(accel_scale, S_IRUGO, sca3000_show_scale,
+		       NULL, 0);
 
 static IIO_DEV_ATTR_ACCEL_X(sca3000_read_13bit_signed,
 			    SCA3000_REG_ADDR_X_MSB);
@@ -682,7 +683,7 @@ error_free_lock:
 /* Should only really be registered if ring buffer support is compiled in.
  * Does no harm however and doing it right would add a fair bit of complexity
  */
-static IIO_DEV_ATTR_AVAIL_SAMP_FREQ(sca3000_read_av_freq);
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sca3000_read_av_freq);
 
 static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
 			      sca3000_read_frequency,
@@ -717,7 +718,10 @@ static ssize_t sca3000_read_temp(struct device *dev,
 error_ret:
 	return ret;
 }
-static IIO_DEV_ATTR_TEMP(sca3000_read_temp);
+static IIO_DEV_ATTR_TEMP_RAW(sca3000_read_temp);
+
+static IIO_CONST_ATTR(temp_scale, "0.555556");
+static IIO_CONST_ATTR(temp_offset, "-214.6");
 
 /**
  * sca3000_show_thresh() sysfs query of a threshold
@@ -769,31 +773,34 @@ static ssize_t sca3000_write_thresh(struct device *dev,
 	return ret ? ret : len;
 }
 
-static IIO_DEV_ATTR_ACCEL_THRESH_X(S_IRUGO | S_IWUSR,
-				   sca3000_show_thresh,
-				   sca3000_write_thresh,
-				   SCA3000_REG_CTRL_SEL_MD_X_TH);
-static IIO_DEV_ATTR_ACCEL_THRESH_Y(S_IRUGO | S_IWUSR,
-				   sca3000_show_thresh,
-				   sca3000_write_thresh,
-				   SCA3000_REG_CTRL_SEL_MD_Y_TH);
-static IIO_DEV_ATTR_ACCEL_THRESH_Z(S_IRUGO | S_IWUSR,
-				   sca3000_show_thresh,
-				   sca3000_write_thresh,
-				   SCA3000_REG_CTRL_SEL_MD_Z_TH);
+static IIO_DEVICE_ATTR(accel_x_mag_either_rising_value,
+		S_IRUGO | S_IWUSR,
+		sca3000_show_thresh,
+		sca3000_write_thresh,
+		SCA3000_REG_CTRL_SEL_MD_X_TH);
+
+static IIO_DEVICE_ATTR(accel_y_mag_either_rising_value,
+		S_IRUGO | S_IWUSR,
+		sca3000_show_thresh,
+		sca3000_write_thresh,
+		SCA3000_REG_CTRL_SEL_MD_Y_TH);
+
+static IIO_DEVICE_ATTR(accel_z_mag_either_rising_value,
+		S_IRUGO | S_IWUSR,
+		sca3000_show_thresh,
+		sca3000_write_thresh,
+		SCA3000_REG_CTRL_SEL_MD_Z_TH);
 
 static struct attribute *sca3000_attributes[] = {
 	&iio_dev_attr_name.dev_attr.attr,
 	&iio_dev_attr_revision.dev_attr.attr,
-	&iio_dev_attr_accel_x.dev_attr.attr,
-	&iio_dev_attr_accel_y.dev_attr.attr,
-	&iio_dev_attr_accel_z.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_x.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_y.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_z.dev_attr.attr,
-	&iio_dev_attr_available_measurement_modes.dev_attr.attr,
+	&iio_dev_attr_accel_scale.dev_attr.attr,
+	&iio_dev_attr_accel_x_raw.dev_attr.attr,
+	&iio_dev_attr_accel_y_raw.dev_attr.attr,
+	&iio_dev_attr_accel_z_raw.dev_attr.attr,
+	&iio_dev_attr_measurement_mode_available.dev_attr.attr,
 	&iio_dev_attr_measurement_mode.dev_attr.attr,
-	&iio_dev_attr_available_sampling_frequency.dev_attr.attr,
+	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency.dev_attr.attr,
 	NULL,
 };
@@ -801,18 +808,18 @@ static struct attribute *sca3000_attributes[] = {
 static struct attribute *sca3000_attributes_with_temp[] = {
 	&iio_dev_attr_name.dev_attr.attr,
 	&iio_dev_attr_revision.dev_attr.attr,
-	&iio_dev_attr_accel_x.dev_attr.attr,
-	&iio_dev_attr_accel_y.dev_attr.attr,
-	&iio_dev_attr_accel_z.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_x.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_y.dev_attr.attr,
-	&iio_dev_attr_thresh_accel_z.dev_attr.attr,
-	&iio_dev_attr_available_measurement_modes.dev_attr.attr,
+	&iio_dev_attr_accel_scale.dev_attr.attr,
+	&iio_dev_attr_accel_x_raw.dev_attr.attr,
+	&iio_dev_attr_accel_y_raw.dev_attr.attr,
+	&iio_dev_attr_accel_z_raw.dev_attr.attr,
+	&iio_dev_attr_measurement_mode_available.dev_attr.attr,
 	&iio_dev_attr_measurement_mode.dev_attr.attr,
-	&iio_dev_attr_available_sampling_frequency.dev_attr.attr,
+	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency.dev_attr.attr,
 	/* Only present if temp sensor is */
-	&iio_dev_attr_temp.dev_attr.attr,
+	&iio_dev_attr_temp_raw.dev_attr.attr,
+	&iio_const_attr_temp_offset.dev_attr.attr,
+	&iio_const_attr_temp_scale.dev_attr.attr,
 	NULL,
 };
 
@@ -909,7 +916,7 @@ static ssize_t sca3000_query_mo_det(struct device *dev,
 				    struct device_attribute *attr,
 				    char *buf)
 {
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
 	struct sca3000_state *st = indio_dev->dev_data;
 	struct iio_event_attr *this_attr = to_iio_event_attr(attr);
 	int ret, len = 0;
@@ -974,7 +981,7 @@ static ssize_t sca3000_query_ring_int(struct device *dev,
 	struct iio_event_attr *this_attr = to_iio_event_attr(attr);
 	int ret, len;
 	u8 *rx;
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
 	struct sca3000_state *st = indio_dev->dev_data;
 	mutex_lock(&st->lock);
 	ret = sca3000_read_data(st, SCA3000_REG_ADDR_INT_MASK, &rx, 1);
@@ -994,7 +1001,7 @@ static ssize_t sca3000_set_ring_int(struct device *dev,
 				      const char *buf,
 				      size_t len)
 {
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
 	struct sca3000_state *st = indio_dev->dev_data;
 	struct iio_event_attr *this_attr = to_iio_event_attr(attr);
 
@@ -1084,7 +1091,7 @@ static ssize_t sca3000_set_mo_det(struct device *dev,
 				  const char *buf,
 				  size_t len)
 {
-	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
 	struct sca3000_state *st = indio_dev->dev_data;
 	struct iio_event_attr *this_attr = to_iio_event_attr(attr);
 	long val;
@@ -1154,20 +1161,23 @@ IIO_EVENT_ATTR_FREE_FALL_DETECT_SH(iio_event_all,
 				   0)
 
 /* Motion detector related event attributes */
-IIO_EVENT_ATTR_ACCEL_X_HIGH_SH(iio_event_all,
-			       sca3000_query_mo_det,
-			       sca3000_set_mo_det,
-			       SCA3000_MD_CTRL_OR_X);
-
-IIO_EVENT_ATTR_ACCEL_Y_HIGH_SH(iio_event_all,
-			       sca3000_query_mo_det,
-			       sca3000_set_mo_det,
-			       SCA3000_MD_CTRL_OR_Y);
-
-IIO_EVENT_ATTR_ACCEL_Z_HIGH_SH(iio_event_all,
-			       sca3000_query_mo_det,
-			       sca3000_set_mo_det,
-			       SCA3000_MD_CTRL_OR_Z);
+IIO_EVENT_ATTR_SH(accel_x_mag_either_rising,
+		  iio_event_all,
+		  sca3000_query_mo_det,
+		  sca3000_set_mo_det,
+		  SCA3000_MD_CTRL_OR_X);
+
+IIO_EVENT_ATTR_SH(accel_y_mag_either_rising,
+		  iio_event_all,
+		  sca3000_query_mo_det,
+		  sca3000_set_mo_det,
+		  SCA3000_MD_CTRL_OR_Y);
+
+IIO_EVENT_ATTR_SH(accel_z_mag_either_rising,
+		  iio_event_all,
+		  sca3000_query_mo_det,
+		  sca3000_set_mo_det,
+		  SCA3000_MD_CTRL_OR_Z);
 
 /* Hardware ring buffer related event attributes */
 IIO_EVENT_ATTR_RING_50_FULL_SH(iio_event_all,
@@ -1182,11 +1192,14 @@ IIO_EVENT_ATTR_RING_75_FULL_SH(iio_event_all,
 
 static struct attribute *sca3000_event_attributes[] = {
 	&iio_event_attr_free_fall.dev_attr.attr,
-	&iio_event_attr_accel_x_high.dev_attr.attr,
-	&iio_event_attr_accel_y_high.dev_attr.attr,
-	&iio_event_attr_accel_z_high.dev_attr.attr,
+	&iio_event_attr_accel_x_mag_either_rising.dev_attr.attr,
+	&iio_event_attr_accel_y_mag_either_rising.dev_attr.attr,
+	&iio_event_attr_accel_z_mag_either_rising.dev_attr.attr,
 	&iio_event_attr_ring_50_full.dev_attr.attr,
 	&iio_event_attr_ring_75_full.dev_attr.attr,
+	&iio_dev_attr_accel_x_mag_either_rising_value.dev_attr.attr,
+	&iio_dev_attr_accel_y_mag_either_rising_value.dev_attr.attr,
+	&iio_dev_attr_accel_z_mag_either_rising_value.dev_attr.attr,
 	NULL,
 };
 
@@ -1343,9 +1356,10 @@ static int __devinit __sca3000_probe(struct spi_device *spi,
 		 * is overkill.  At very least a simpler registration method
 		 * might be worthwhile.
 		 */
-		iio_add_event_to_list(iio_event_attr_accel_z_high.listel,
-					    &st->indio_dev
-					    ->interrupts[0]->ev_list);
+		iio_add_event_to_list(
+			iio_event_attr_accel_z_mag_either_rising.listel,
+			&st->indio_dev
+			->interrupts[0]->ev_list);
 	}
 	sca3000_register_ring_funcs(st->indio_dev);
 	ret = sca3000_clean_setup(st);
@@ -1436,9 +1450,6 @@ static int sca3000_remove(struct spi_device *spi)
 SCA3000_VARIANT_PROBE(d01);
 static SCA3000_VARIANT_SPI_DRIVER(d01);
 
-SCA3000_VARIANT_PROBE(d03);
-static SCA3000_VARIANT_SPI_DRIVER(d03);
-
 SCA3000_VARIANT_PROBE(e02);
 static SCA3000_VARIANT_SPI_DRIVER(e02);
 
@@ -1448,9 +1459,6 @@ static SCA3000_VARIANT_SPI_DRIVER(e04);
 SCA3000_VARIANT_PROBE(e05);
 static SCA3000_VARIANT_SPI_DRIVER(e05);
 
-SCA3000_VARIANT_PROBE(l01);
-static SCA3000_VARIANT_SPI_DRIVER(l01);
-
 static __init int sca3000_init(void)
 {
 	int ret;
@@ -1458,32 +1466,22 @@ static __init int sca3000_init(void)
 	ret = spi_register_driver(&sca3000_d01_driver);
 	if (ret)
 		goto error_ret;
-	ret = spi_register_driver(&sca3000_d03_driver);
-	if (ret)
-		goto error_unreg_d01;
 	ret = spi_register_driver(&sca3000_e02_driver);
 	if (ret)
-		goto error_unreg_d03;
+		goto error_unreg_d01;
 	ret = spi_register_driver(&sca3000_e04_driver);
 	if (ret)
 		goto error_unreg_e02;
 	ret = spi_register_driver(&sca3000_e05_driver);
 	if (ret)
 		goto error_unreg_e04;
-	ret = spi_register_driver(&sca3000_l01_driver);
-	if (ret)
-		goto error_unreg_e05;
 
 	return 0;
 
-error_unreg_e05:
-	spi_unregister_driver(&sca3000_e05_driver);
 error_unreg_e04:
 	spi_unregister_driver(&sca3000_e04_driver);
 error_unreg_e02:
 	spi_unregister_driver(&sca3000_e02_driver);
-error_unreg_d03:
-	spi_unregister_driver(&sca3000_d03_driver);
 error_unreg_d01:
 	spi_unregister_driver(&sca3000_d01_driver);
 error_ret:
@@ -1493,11 +1491,9 @@ error_ret:
 
 static __exit void sca3000_exit(void)
 {
-	spi_unregister_driver(&sca3000_l01_driver);
 	spi_unregister_driver(&sca3000_e05_driver);
 	spi_unregister_driver(&sca3000_e04_driver);
 	spi_unregister_driver(&sca3000_e02_driver);
-	spi_unregister_driver(&sca3000_d03_driver);
 	spi_unregister_driver(&sca3000_d01_driver);
 }
 
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
index d5ea237..ac9914d 100644
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ b/drivers/staging/iio/accel/sca3000_ring.c
@@ -185,11 +185,29 @@ static ssize_t sca3000_store_ring_bpse(struct device *dev,
 	return ret ? ret : len;
 }
 
-static IIO_CONST_ATTR(bpse_available, "8 11");
+static IIO_SCAN_EL_C(accel_x, 0, 0, 0, 0);
+static IIO_SCAN_EL_C(accel_y, 1, 0, 0, 0);
+static IIO_SCAN_EL_C(accel_z, 2, 0, 0, 0);
+static IIO_CONST_ATTR(accel_precision_available, "8 11");
+static IIO_DEVICE_ATTR(accel_precision,
+		       S_IRUGO | S_IWUSR,
+		       sca3000_show_ring_bpse,
+		       sca3000_store_ring_bpse,
+		       0);
+
+static struct attribute *sca3000_scan_el_attrs[] = {
+	&iio_scan_el_accel_x.dev_attr.attr,
+	&iio_scan_el_accel_y.dev_attr.attr,
+	&iio_scan_el_accel_z.dev_attr.attr,
+	&iio_const_attr_accel_precision_available.dev_attr.attr,
+	&iio_dev_attr_accel_precision.dev_attr.attr,
+	NULL
+};
 
-static IIO_DEV_ATTR_BPSE(S_IRUGO | S_IWUSR,
-			      sca3000_show_ring_bpse,
-			      sca3000_store_ring_bpse);
+static struct attribute_group sca3000_scan_el_group = {
+	.attrs = sca3000_scan_el_attrs,
+	.name = "scan_elements",
+};
 
 /*
  * Ring buffer attributes
@@ -197,17 +215,15 @@ static IIO_DEV_ATTR_BPSE(S_IRUGO | S_IWUSR,
  * only apply to the ring buffer.  At all times full rate and accuracy
  * is available via direct reading from registers.
  */
-static struct attribute *iio_ring_attributes[] = {
+static struct attribute *sca3000_ring_attributes[] = {
 	&dev_attr_length.attr,
 	&dev_attr_bps.attr,
 	&dev_attr_ring_enable.attr,
-	&iio_dev_attr_bpse.dev_attr.attr,
-	&iio_const_attr_bpse_available.dev_attr.attr,
 	NULL,
 };
 
 static struct attribute_group sca3000_ring_attr = {
-	.attrs = iio_ring_attributes,
+	.attrs = sca3000_ring_attributes,
 };
 
 static const struct attribute_group *sca3000_ring_attr_groups[] = {
@@ -247,6 +263,7 @@ static inline void sca3000_rb_free(struct iio_ring_buffer *r)
 
 int sca3000_configure_ring(struct iio_dev *indio_dev)
 {
+	indio_dev->scan_el_attrs = &sca3000_scan_el_group;
 	indio_dev->ring = sca3000_rb_allocate(indio_dev);
 	if (indio_dev->ring == NULL)
 		return -ENOMEM;
diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
index 09044ad..efd385f 100644
--- a/drivers/staging/iio/ring_generic.h
+++ b/drivers/staging/iio/ring_generic.h
@@ -250,9 +250,9 @@ ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
  *
  * Odd one out. Handled slightly differently from other scan elements.
  **/
-#define IIO_SCAN_EL_TIMESTAMP					\
+#define IIO_SCAN_EL_TIMESTAMP(number)				\
 	struct iio_scan_el iio_scan_el_timestamp = {		\
-		.dev_attr = __ATTR(scan_en_timestamp,		\
+		.dev_attr = __ATTR(number##_timestamp_en,	\
 				   S_IRUGO | S_IWUSR,		\
 				   iio_scan_el_ts_show,		\
 				   iio_scan_el_ts_store),	\
-- 
1.6.4.4

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

* [PATCH 04/13] staging:iio: Support functions for scan mask matching
  2010-03-28 20:41     ` [PATCH 03/13] iio:staging:accelerometers move towards the new abi Jonathan Cameron
@ 2010-03-28 20:41       ` Jonathan Cameron
  2010-03-28 20:41         ` [PATCH 05/13] staging: iio: Move from class to bus Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/iio.h |   44 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 71dbfe1..6b2f480 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -96,6 +96,7 @@ void iio_remove_event_from_list(struct iio_event_handler_list *el,
  *			control method is used
  * @scan_count:	[INTERN] the number of elements in the current scan mode
  * @scan_mask:		[INTERN] bitmask used in masking scan mode elements
+ * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
  * @scan_timestamp:	[INTERN] does the scan mode include a timestamp
  * @trig:		[INTERN] current device trigger (ring buffer modes)
  * @pollfunc:		[DRIVER] function run on trigger being recieved
@@ -122,7 +123,8 @@ struct iio_dev {
 	struct attribute_group		*scan_el_attrs;
 	int				scan_count;
 
-	u16				scan_mask;
+	u32				scan_mask;
+	u32				*available_scan_masks;
 	bool				scan_timestamp;
 	struct iio_trigger		*trig;
 	struct iio_poll_func		*pollfunc;
@@ -132,22 +134,56 @@ struct iio_dev {
  * These are mainly provided to allow for a change of implementation if a device
  * has a large number of scan elements
  */
-#define IIO_MAX_SCAN_LENGTH 15
+#define IIO_MAX_SCAN_LENGTH 31
+
+/* note 0 used as error indicator as it doesn't make sense. */
+static inline u32 iio_scan_mask_match(u32 *av_masks, u32 mask)
+{
+	while (*av_masks) {
+		if (!(~*av_masks & mask))
+			return *av_masks;
+		av_masks++;
+	}
+	return 0;
+}
 
 static inline int iio_scan_mask_query(struct iio_dev *dev_info, int bit)
 {
+	u32 mask;
+
 	if (bit > IIO_MAX_SCAN_LENGTH)
 		return -EINVAL;
+
+	if (!dev_info->scan_mask)
+		return 0;
+
+	if (dev_info->available_scan_masks)
+		mask = iio_scan_mask_match(dev_info->available_scan_masks,
+					dev_info->scan_mask);
 	else
-		return !!(dev_info->scan_mask & (1 << bit));
+		mask = dev_info->scan_mask;
+
+	if (!mask)
+		return -EINVAL;
+
+	return !!(mask & (1 << bit));
 };
 
 static inline int iio_scan_mask_set(struct iio_dev *dev_info, int bit)
 {
+	u32 mask;
+	u32 trialmask = dev_info->scan_mask | (1 << bit);
+
 	if (bit > IIO_MAX_SCAN_LENGTH)
 		return -EINVAL;
-	dev_info->scan_mask |= (1 << bit);
+	if (dev_info->available_scan_masks)
+		mask = iio_scan_mask_match(dev_info->available_scan_masks,
+					trialmask);
+	if (!mask)
+		return -EINVAL;
+	dev_info->scan_mask = trialmask;
 	dev_info->scan_count++;
+
 	return 0;
 };
 
-- 
1.6.4.4

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

* [PATCH 05/13] staging: iio: Move from class to bus
  2010-03-28 20:41       ` [PATCH 04/13] staging:iio: Support functions for scan mask matching Jonathan Cameron
@ 2010-03-28 20:41         ` Jonathan Cameron
  2010-03-28 20:41           ` [PATCH 06/13] staging:iio: Move event attributes into the event[n] device in sysfs Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/iio.h                  |    2 +-
 drivers/staging/iio/industrialio-core.c    |   28 +++++++++++-----------------
 drivers/staging/iio/industrialio-ring.c    |    2 +-
 drivers/staging/iio/industrialio-trigger.c |    2 +-
 drivers/staging/iio/ring_sw.c              |    2 +-
 5 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 6b2f480..9ad8b3c 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -376,7 +376,7 @@ void iio_deallocate_chrdev(struct iio_handler *handler);
 #define IIO_UNSIGNED(a) (a)
 
 extern dev_t iio_devt;
-extern struct class iio_class;
+extern struct bus_type iio_bus_type;
 
 /**
  * iio_put_device() - reference counted deallocation of struct device
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index b456dfc..3312d9a 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -41,16 +41,10 @@ dev_t iio_devt;
 EXPORT_SYMBOL(iio_devt);
 
 #define IIO_DEV_MAX 256
-static char *iio_devnode(struct device *dev, mode_t *mode)
-{
-	return kasprintf(GFP_KERNEL, "iio/%s", dev_name(dev));
-}
-
-struct class iio_class = {
+struct bus_type iio_bus_type = {
 	.name = "iio",
-	.devnode = iio_devnode,
 };
-EXPORT_SYMBOL(iio_class);
+EXPORT_SYMBOL(iio_bus_type);
 
 void __iio_change_event(struct iio_detected_event_list *ev,
 			int ev_code,
@@ -404,7 +398,7 @@ int iio_setup_ev_int(struct iio_event_interface *ev_int,
 {
 	int ret, minor;
 
-	ev_int->dev.class = &iio_class;
+	ev_int->dev.bus = &iio_bus_type;
 	ev_int->dev.parent = dev;
 	ev_int->dev.type = &iio_event_type;
 	device_initialize(&ev_int->dev);
@@ -477,23 +471,23 @@ static int __init iio_init(void)
 {
 	int ret;
 
-	/* Create sysfs class */
-	ret  = class_register(&iio_class);
+	/* Register sysfs bus */
+	ret  = bus_register(&iio_bus_type);
 	if (ret < 0) {
 		printk(KERN_ERR
-		       "%s could not create sysfs class\n",
+		       "%s could not register bus type\n",
 			__FILE__);
 		goto error_nothing;
 	}
 
 	ret = iio_dev_init();
 	if (ret < 0)
-		goto error_unregister_class;
+		goto error_unregister_bus_type;
 
 	return 0;
 
-error_unregister_class:
-	class_unregister(&iio_class);
+error_unregister_bus_type:
+	bus_unregister(&iio_bus_type);
 error_nothing:
 	return ret;
 }
@@ -501,7 +495,7 @@ error_nothing:
 static void __exit iio_exit(void)
 {
 	iio_dev_exit();
-	class_unregister(&iio_class);
+	bus_unregister(&iio_bus_type);
 }
 
 static int iio_device_register_sysfs(struct iio_dev *dev_info)
@@ -767,7 +761,7 @@ struct iio_dev *iio_allocate_device(void)
 
 	if (dev) {
 		dev->dev.type = &iio_dev_type;
-		dev->dev.class = &iio_class;
+		dev->dev.bus = &iio_bus_type;
 		device_initialize(&dev->dev);
 		dev_set_drvdata(&dev->dev, (void *)dev);
 		mutex_init(&dev->mlock);
diff --git a/drivers/staging/iio/industrialio-ring.c b/drivers/staging/iio/industrialio-ring.c
index ebe5ccc..81ea226 100644
--- a/drivers/staging/iio/industrialio-ring.c
+++ b/drivers/staging/iio/industrialio-ring.c
@@ -209,7 +209,7 @@ __iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf,
 	buf->access_handler.flags = 0;
 
 	buf->access_dev.parent = &buf->dev;
-	buf->access_dev.class = &iio_class;
+	buf->access_dev.bus = &iio_bus_type;
 	buf->access_dev.type = &iio_ring_access_type;
 	device_initialize(&buf->access_dev);
 
diff --git a/drivers/staging/iio/industrialio-trigger.c b/drivers/staging/iio/industrialio-trigger.c
index 693ebc4..10a1dc3 100644
--- a/drivers/staging/iio/industrialio-trigger.c
+++ b/drivers/staging/iio/industrialio-trigger.c
@@ -361,7 +361,7 @@ struct iio_trigger *iio_allocate_trigger(void)
 	trig = kzalloc(sizeof *trig, GFP_KERNEL);
 	if (trig) {
 		trig->dev.type = &iio_trig_type;
-		trig->dev.class = &iio_class;
+		trig->dev.bus = &iio_bus_type;
 		device_initialize(&trig->dev);
 		dev_set_drvdata(&trig->dev, (void *)trig);
 		spin_lock_init(&trig->pollfunc_list_lock);
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index 6f7f4d5..d903ff2 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -415,7 +415,7 @@ struct iio_ring_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
 	buf->dev.type = &iio_sw_ring_type;
 	device_initialize(&buf->dev);
 	buf->dev.parent = &indio_dev->dev;
-	buf->dev.class = &iio_class;
+	buf->dev.bus = &iio_bus_type;
 	dev_set_drvdata(&buf->dev, (void *)buf);
 
 	return buf;
-- 
1.6.4.4

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

* [PATCH 06/13] staging:iio: Move event attributes into the event[n] device in sysfs
  2010-03-28 20:41         ` [PATCH 05/13] staging: iio: Move from class to bus Jonathan Cameron
@ 2010-03-28 20:41           ` Jonathan Cameron
  2010-03-28 20:41             ` [PATCH 07/13] staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/industrialio-core.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 3312d9a..1f49f09 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -675,16 +675,14 @@ static int iio_device_register_eventset(struct iio_dev *dev_info)
 					 dev_info->event_interfaces[i].id);
 			goto error_free_setup_ev_ints;
 		}
-	}
 
-	for (i = 0; i < dev_info->num_interrupt_lines; i++) {
-		snprintf(dev_info->event_interfaces[i]._attrname, 20,
-			"event_line%d_sources", i);
-		dev_info->event_attrs[i].name
-			= (const char *)
-			(dev_info->event_interfaces[i]._attrname);
-		ret = sysfs_create_group(&dev_info->dev.kobj,
-					 &dev_info->event_attrs[i]);
+		dev_set_drvdata(&dev_info->event_interfaces[i].dev,
+				(void *)dev_info);
+		ret = sysfs_create_group(&dev_info
+					->event_interfaces[i]
+					.dev.kobj,
+					&dev_info->event_attrs[i]);
+
 		if (ret) {
 			dev_err(&dev_info->dev,
 				"Failed to register sysfs for event attrs");
@@ -706,13 +704,13 @@ error_unregister_config_attrs:
 	i = dev_info->num_interrupt_lines - 1;
 error_remove_sysfs_interfaces:
 	for (j = 0; j < i; j++)
-		sysfs_remove_group(&dev_info->dev.kobj,
+		sysfs_remove_group(&dev_info
+				   ->event_interfaces[j].dev.kobj,
 				   &dev_info->event_attrs[j]);
-	i = dev_info->num_interrupt_lines - 1;
 error_free_setup_ev_ints:
 	for (j = 0; j < i; j++) {
 		iio_free_idr_val(&iio_event_idr,
-				 dev_info->event_interfaces[i].id);
+				 dev_info->event_interfaces[j].id);
 		iio_free_ev_int(&dev_info->event_interfaces[j]);
 	}
 	kfree(dev_info->interrupts);
@@ -730,7 +728,8 @@ static void iio_device_unregister_eventset(struct iio_dev *dev_info)
 	if (dev_info->num_interrupt_lines == 0)
 		return;
 	for (i = 0; i < dev_info->num_interrupt_lines; i++)
-		sysfs_remove_group(&dev_info->dev.kobj,
+		sysfs_remove_group(&dev_info
+				   ->event_interfaces[i].dev.kobj,
 				   &dev_info->event_attrs[i]);
 
 	for (i = 0; i < dev_info->num_interrupt_lines; i++) {
-- 
1.6.4.4

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

* [PATCH 07/13] staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C
  2010-03-28 20:41           ` [PATCH 06/13] staging:iio: Move event attributes into the event[n] device in sysfs Jonathan Cameron
@ 2010-03-28 20:41             ` Jonathan Cameron
  2010-03-28 20:41               ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/ring_generic.h |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
index efd385f..c649b6d 100644
--- a/drivers/staging/iio/ring_generic.h
+++ b/drivers/staging/iio/ring_generic.h
@@ -198,25 +198,6 @@ ssize_t iio_scan_el_store(struct device *dev, struct device_attribute *attr,
  **/
 ssize_t iio_scan_el_show(struct device *dev, struct device_attribute *attr,
 			 char *buf);
-/**
- * IIO_SCAN_EL - declare and initialize a scan element without control func
- * @_name:	identifying name. Resulting struct is iio_scan_el_##_name,
- *		sysfs element, scan_en_##_name.
- * @_number:	unique id number for the scan element.
- * @_bits:	number of bits in the scan element result (used in mixed bit
- *		length devices).
- * @_label:	indentification variable used by drivers.  Often a reg address.
- **/
-#define IIO_SCAN_EL(_name, _number, _bits, _label)			\
-	struct iio_scan_el iio_scan_el_##_name = {			\
-		.dev_attr = __ATTR(scan_en_##_name,			\
-				   S_IRUGO | S_IWUSR,			\
-				   iio_scan_el_show,			\
-				   iio_scan_el_store),			\
-		.mask = (1 << _number),					\
-		.bit_count = _bits,					\
-		.label = _label,					\
-	}
 
 ssize_t iio_scan_el_ts_store(struct device *dev, struct device_attribute *attr,
 			     const char *buf, size_t len);
@@ -227,7 +208,7 @@ ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
  * IIO_SCAN_EL_C - declare and initialize a scan element with a control func
  *
  * @_name:	identifying name. Resulting struct is iio_scan_el_##_name,
- *		sysfs element, scan_en_##_name.
+ *		sysfs element, _name##_en.
  * @_number:	unique id number for the scan element.
  * @_bits:	number of bits in the scan element result (used in mixed bit
  *		length devices).
@@ -236,7 +217,7 @@ ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
  **/
 #define IIO_SCAN_EL_C(_name, _number, _bits, _label, _controlfunc)	\
 	struct iio_scan_el iio_scan_el_##_name = {			\
-		.dev_attr = __ATTR(scan_en_##_name,			\
+		.dev_attr = __ATTR(_number##_##_name##_en,		\
 				   S_IRUGO | S_IWUSR,			\
 				   iio_scan_el_show,			\
 				   iio_scan_el_store),			\
@@ -245,6 +226,19 @@ ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
 		.label = _label,					\
 		.set_state = _controlfunc,				\
 	}
+
+#define IIO_SCAN_NAMED_EL_C(_name, _string, _number, _bits, _label, _cf) \
+	struct iio_scan_el iio_scan_el_##_name = {			\
+		.dev_attr = __ATTR(_number##_##_string##_en,		\
+				   S_IRUGO | S_IWUSR,			\
+				   iio_scan_el_show,			\
+				   iio_scan_el_store),			\
+		.number =  _number,					\
+		.bit_count = _bits,					\
+		.label = _label,					\
+		.set_state = _cf,					\
+	}
+
 /**
  * IIO_SCAN_EL_TIMESTAMP - declare a special scan element for timestamps
  *
-- 
1.6.4.4

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

* [PATCH 08/13] staging:iio:max1363 move to new abi.
  2010-03-28 20:41             ` [PATCH 07/13] staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C Jonathan Cameron
@ 2010-03-28 20:41               ` Jonathan Cameron
  2010-03-28 20:41                 ` [PATCH 09/13] staging:iio: Documentation, update iio_utils.h for the move to a bus Jonathan Cameron
  2010-03-30 14:31                 ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
  0 siblings, 2 replies; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/adc/Kconfig        |    1 +
 drivers/staging/iio/adc/Makefile       |    2 +-
 drivers/staging/iio/adc/max1363.h      |  122 +++---
 drivers/staging/iio/adc/max1363_core.c |  762 +++++++++++++++++++-------------
 drivers/staging/iio/adc/max1363_ring.c |   65 ++-
 5 files changed, 548 insertions(+), 404 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 3989c0c..101ea4b 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -7,6 +7,7 @@ config MAX1363
 	tristate "MAXIM max1363 ADC driver"
 	depends on I2C
 	select IIO_TRIGGER if IIO_RING_BUFFER
+	select MAX1363_RING_BUFFER
 	help
 	  Say yes here to build support for many MAXIM i2c analog to digital
 	  convertors (ADC). (max1361, max1362, max1363, max1364, max1136,
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 08cee5c..18c9376 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -3,6 +3,6 @@
 #
 
 max1363-y := max1363_core.o
-max1363-$(CONFIG_MAX1363_RING_BUFFER) += max1363_ring.o
+max1363-y += max1363_ring.o
 
 obj-$(CONFIG_MAX1363) += max1363.o
diff --git a/drivers/staging/iio/adc/max1363.h b/drivers/staging/iio/adc/max1363.h
index c112fbe..72cf367 100644
--- a/drivers/staging/iio/adc/max1363.h
+++ b/drivers/staging/iio/adc/max1363.h
@@ -72,77 +72,54 @@
  * @numvals:	The number of values returned by a single scan
  */
 struct max1363_mode {
-	const char	*name;
 	int8_t		conf;
-	int		numvals;
+	long		modemask;
 };
 
-#define MAX1363_MODE_SINGLE(_num) {					\
-		.name = #_num,						\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
+#define MAX1363_MODE_SINGLE(_num, _mask) {				\
+		.conf = MAX1363_CHANNEL_SEL(_num)			\
 			| MAX1363_CONFIG_SCAN_SINGLE_1			\
 			| MAX1363_CONFIG_SE,				\
-			.numvals = 1,					\
+			.modemask = _mask,				\
 			}
 
-#define MAX1363_MODE_SINGLE_TIMES_8(_num) {				\
-		.name = #_num"x8",					\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
-			| MAX1363_CONFIG_SCAN_SINGLE_8			\
-			| MAX1363_CONFIG_SE,				\
-			.numvals = 8,					\
-			}
-
-#define MAX1363_MODE_SCAN_TO_CHANNEL(_num) {				\
-		.name = "0..."#_num,					\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
+#define MAX1363_MODE_SCAN_TO_CHANNEL(_num, _mask) {			\
+		.conf = MAX1363_CHANNEL_SEL(_num)			\
 			| MAX1363_CONFIG_SCAN_TO_CS			\
 			| MAX1363_CONFIG_SE,				\
-			.numvals = _num + 1,				\
+			.modemask = _mask,				\
 			}
 
 
 /* note not available for max1363 hence naming */
-#define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num) {			\
-		.name = #_mid"..."#_num,				\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
+#define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num, _mask) {		\
+		.conf = MAX1363_CHANNEL_SEL(_num)			\
 			| MAX1236_SCAN_MID_TO_CHANNEL			\
 			| MAX1363_CONFIG_SE,				\
-			.numvals = _num - _mid + 1			\
+			.modemask = _mask				\
 }
 
-#define MAX1363_MODE_DIFF_SINGLE(_nump, _numm) {			\
-		.name = #_nump"-"#_numm,				\
-			.conf = MAX1363_CHANNEL_SEL(_nump)		\
+#define MAX1363_MODE_DIFF_SINGLE(_nump, _numm, _mask) {			\
+		.conf = MAX1363_CHANNEL_SEL(_nump)			\
 			| MAX1363_CONFIG_SCAN_SINGLE_1			\
 			| MAX1363_CONFIG_DE,				\
-			.numvals = 1,					\
-			}
-
-#define MAX1363_MODE_DIFF_SINGLE_TIMES_8(_nump, _numm) {		\
-		.name = #_nump"-"#_numm,				\
-			.conf = MAX1363_CHANNEL_SEL(_nump)		\
-			| MAX1363_CONFIG_SCAN_SINGLE_8			\
-			| MAX1363_CONFIG_DE,				\
-			.numvals = 1,					\
+			.modemask = _mask				\
 			}
 
 /* Can't think how to automate naming so specify for now */
-#define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(_name, _num, _numvals) { \
-		.name = #_name,						\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
+#define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(_num, _numvals, _mask) { \
+		.conf = MAX1363_CHANNEL_SEL(_num)			\
 			| MAX1363_CONFIG_SCAN_TO_CS			\
 			| MAX1363_CONFIG_DE,				\
-			.numvals = _numvals,				\
+			.modemask = _mask				\
 			}
 
 /* note only available for max1363 hence naming */
-#define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(_name, _num, _numvals) { \
-    .name = #_name,							\
-			.conf = MAX1363_CHANNEL_SEL(_num)		\
+#define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(_num, _numvals, _mask) { \
+		.conf = MAX1363_CHANNEL_SEL(_num)			\
 			| MAX1236_SCAN_MID_TO_CHANNEL			\
 			| MAX1363_CONFIG_SE,				\
-			.numvals = _numvals,				\
+			.modemask = _mask				\
 }
 
 /* Not currently handled */
@@ -158,35 +135,43 @@ struct max1363_mode {
  * clear what all the various options actually do. Alternative suggestions
  * that don't require user to have intimate knowledge of the chip welcomed.
  */
+enum max1363_channels {
+	max1363_in0, max1363_in1, max1363_in2, max1363_in3,
+	max1363_in4, max1363_in5, max1363_in6, max1363_in7,
+	max1363_in8, max1363_in9, max1363_in10, max1363_in11,
+
+	max1363_in0min1, max1363_in2min3,
+	max1363_in4min5, max1363_in6min7,
+	max1363_in8min9, max1363_in10min11,
+
+	max1363_in1min0, max1363_in3min2,
+	max1363_in5min4, max1363_in7min6,
+	max1363_in9min8, max1363_in11min10,
+	};
 
 /* This must be maintained along side the max1363_mode_table in max1363_core */
 enum max1363_modes {
 	/* Single read of a single channel */
 	_s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
-	/* Eight reads of a single channel */
-	se0, se1, se2, se3, se4, se5, se6, se7, se8, se9, se10, se11,
-	/* Scan to channel */
-	s0to1, s0to2, s0to3, s0to4, s0to5, s0to6,
-	s0to7, s0to8, s0to9, s0to10, s0to11,
 	/* Differential single read */
 	d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
 	d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
-	/* Differential single read 8 times */
-	de0m1, de2m3, de4m5, de6m7, de8m9, de10m11,
-	de1m0, de3m2, de5m4, de7m6, de9m8, de11m10,
-	/* Differential scan to channel */
-	d0m1to2m3, d0m1to4m5, d0m1to6m7, d0m1to8m9, d0m1to10m11,
-	d1m0to3m2, d1m0to5m4, d1m0to7m6, d1m0to9m8, d1m0to11m10,
-	/* Scan mid to channel max123{6-9} only */
-	s2to3, s6to7, s6to8, s6to9, s6to10, s6to11,
-	/* Differential scan mid to channel */
-	s6m7to8m9, s6m7to10m11, s7m6to9m8, s7m6to11m10,
+	/* Scan to channel and mid to channel where overlapping */
+	s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6,
+	s6to7, s0to7, s6to8, s0to8, s6to9,
+	s0to9, s6to10, s0to10, s6to11, s0to11,
+	/* Differential scan to channel and mid to channel where overlapping */
+	d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9,
+	d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2,
+	d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8,
+	d7m6to11m10, d1m0to11m10,
 };
 
 /**
  * struct max1363_chip_info - chip specifc information
  * @name:		indentification string for chip
  * @num_inputs:		number of physical inputs on chip
+ * @bits:		accuracy of the adc in bits
  * @int_vref_mv:	the internal reference voltage
  * @monitor_mode:	whether the chip supports monitor interrupts
  * @mode_list:		array of available scan modes
@@ -196,11 +181,14 @@ enum max1363_modes {
 struct max1363_chip_info {
 	const char			*name;
 	u8				num_inputs;
+	u8				bits;
 	u16				int_vref_mv;
 	bool				monitor_mode;
 	const enum max1363_modes	*mode_list;
 	int				num_modes;
 	enum max1363_modes		default_mode;
+	struct attribute_group		*dev_attrs;
+	struct attribute_group		*scan_attrs;
 };
 
 
@@ -212,6 +200,7 @@ struct max1363_chip_info {
  * @configbyte:		cache of current device config byte
  * @chip_info:		chip model specific constants, available modes etc
  * @current_mode:	the scan mode of this chip
+ * @requestedmask:	a valid requested set of channels
  * @poll_work:		bottom half of polling interrupt handler
  * @protect_ring:	used to ensure only one polling bh running at a time
  * @reg:		supply regulator
@@ -223,16 +212,21 @@ struct max1363_state {
 	char				configbyte;
 	const struct max1363_chip_info	*chip_info;
 	const struct max1363_mode	*current_mode;
+	u32				requestedmask;
 	struct work_struct		poll_work;
 	atomic_t			protect_ring;
 	struct iio_trigger		*trig;
 	struct regulator		*reg;
 };
+
+const struct max1363_mode
+*max1363_match_mode(u32 mask, const struct max1363_chip_info *ci);
+
+int max1363_set_scan_mode(struct max1363_state *st);
+
 #ifdef CONFIG_MAX1363_RING_BUFFER
 
-ssize_t max1363_scan_from_ring(struct device *dev,
-			       struct device_attribute *attr,
-			       char *buf);
+int max1363_single_channel_from_ring(long mask, struct max1363_state *st);
 int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev);
 void max1363_ring_cleanup(struct iio_dev *indio_dev);
 
@@ -250,14 +244,12 @@ static inline int max1363_initialize_ring(struct iio_ring_buffer *ring)
 	return 0;
 };
 
-
-static inline ssize_t max1363_scan_from_ring(struct device *dev,
-					     struct device_attribute *attr,
-					     char *buf)
+int max1363_single_channel_from_ring(long mask, struct max1363_state *st)
 {
-	return 0;
+	return -EINVAL;
 };
 
+
 static inline int
 max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c
index 9703881..bdce450 100644
--- a/drivers/staging/iio/adc/max1363_core.c
+++ b/drivers/staging/iio/adc/max1363_core.c
@@ -1,27 +1,26 @@
  /*
- * linux/drivers/industrialio/adc/max1363.c
- * Copyright (C) 2008 Jonathan Cameron
- *
- * based on linux/drivers/i2c/chips/max123x
- * Copyright (C) 2002-2004 Stefan Eletzhofer
- *
- * based on linux/drivers/acron/char/pcf8583.c
- * Copyright (C) 2000 Russell King
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * max1363.c
- *
- * Partial support for max1363 and similar chips.
- *
- * Not currently implemented.
- *
- * - Monitor interrrupt generation.
- * - Control of internal reference.
- * - Sysfs scan interface currently assumes unipolar mode.
- */
+  * iio/adc/max1363.c
+  * Copyright (C) 2008-2010 Jonathan Cameron
+  *
+  * based on linux/drivers/i2c/chips/max123x
+  * Copyright (C) 2002-2004 Stefan Eletzhofer
+  *
+  * based on linux/drivers/acron/char/pcf8583.c
+  * Copyright (C) 2000 Russell King
+  *
+  * This program is free software; you can redistribute it and/or modify
+  * it under the terms of the GNU General Public License version 2 as
+  * published by the Free Software Foundation.
+  *
+  * max1363.c
+  *
+  * Partial support for max1363 and similar chips.
+  *
+  * Not currently implemented.
+  *
+  * - Monitor interrrupt generation.
+  * - Control of internal reference.
+  */
 
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
@@ -37,118 +36,318 @@
 #include "../iio.h"
 #include "../sysfs.h"
 
+#include "../ring_generic.h"
+#include "adc.h"
 #include "max1363.h"
 
-/* Available scan modes.
- * Awkwardly the associated enum is in the header so it is available to
- * the ring buffer code.
- */
-static const struct  max1363_mode max1363_mode_table[] = {
-	MAX1363_MODE_SINGLE(0),
-	MAX1363_MODE_SINGLE(1),
-	MAX1363_MODE_SINGLE(2),
-	MAX1363_MODE_SINGLE(3),
-	MAX1363_MODE_SINGLE(4),
-	MAX1363_MODE_SINGLE(5),
-	MAX1363_MODE_SINGLE(6),
-	MAX1363_MODE_SINGLE(7),
-	MAX1363_MODE_SINGLE(8),
-	MAX1363_MODE_SINGLE(9),
-	MAX1363_MODE_SINGLE(10),
-	MAX1363_MODE_SINGLE(11),
-
-	MAX1363_MODE_SINGLE_TIMES_8(0),
-	MAX1363_MODE_SINGLE_TIMES_8(1),
-	MAX1363_MODE_SINGLE_TIMES_8(2),
-	MAX1363_MODE_SINGLE_TIMES_8(3),
-	MAX1363_MODE_SINGLE_TIMES_8(4),
-	MAX1363_MODE_SINGLE_TIMES_8(5),
-	MAX1363_MODE_SINGLE_TIMES_8(6),
-	MAX1363_MODE_SINGLE_TIMES_8(7),
-	MAX1363_MODE_SINGLE_TIMES_8(8),
-	MAX1363_MODE_SINGLE_TIMES_8(9),
-	MAX1363_MODE_SINGLE_TIMES_8(10),
-	MAX1363_MODE_SINGLE_TIMES_8(11),
-
-	MAX1363_MODE_SCAN_TO_CHANNEL(1),
-	MAX1363_MODE_SCAN_TO_CHANNEL(2),
-	MAX1363_MODE_SCAN_TO_CHANNEL(3),
-	MAX1363_MODE_SCAN_TO_CHANNEL(4),
-	MAX1363_MODE_SCAN_TO_CHANNEL(5),
-	MAX1363_MODE_SCAN_TO_CHANNEL(6),
-	MAX1363_MODE_SCAN_TO_CHANNEL(7),
-	MAX1363_MODE_SCAN_TO_CHANNEL(8),
-	MAX1363_MODE_SCAN_TO_CHANNEL(9),
-	MAX1363_MODE_SCAN_TO_CHANNEL(10),
-	MAX1363_MODE_SCAN_TO_CHANNEL(11),
-
-	MAX1363_MODE_DIFF_SINGLE(0, 1),
-	MAX1363_MODE_DIFF_SINGLE(2, 3),
-	MAX1363_MODE_DIFF_SINGLE(4, 5),
-	MAX1363_MODE_DIFF_SINGLE(6, 7),
-	MAX1363_MODE_DIFF_SINGLE(8, 9),
-	MAX1363_MODE_DIFF_SINGLE(10, 11),
-	MAX1363_MODE_DIFF_SINGLE(1, 0),
-	MAX1363_MODE_DIFF_SINGLE(3, 2),
-	MAX1363_MODE_DIFF_SINGLE(5, 4),
-	MAX1363_MODE_DIFF_SINGLE(7, 6),
-	MAX1363_MODE_DIFF_SINGLE(9, 8),
-	MAX1363_MODE_DIFF_SINGLE(11, 10),
-
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(0, 1),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(2, 3),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(4, 5),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(6, 7),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(8, 9),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(10, 11),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(1, 0),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(3, 2),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(5, 4),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(7, 6),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(9, 8),
-	MAX1363_MODE_DIFF_SINGLE_TIMES_8(11, 10),
-
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(0-1...2-3, 2, 2),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(0-1...4-5, 4, 3),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(0-1...6-7, 6, 4),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(0-1...8-9, 8, 5),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(0-1...10-11, 10, 6),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(1-0...3-2, 3, 2),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(1-0...5-4, 5, 3),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(1-0...7-6, 7, 4),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(1-0...9-8, 9, 5),
-	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(1-0...11-10, 11, 6),
-
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(2, 3),
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 7),
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 8),
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 9),
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 10),
-	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 11),
-
-	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(6-7...8-9, 8, 2),
-	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(6-7...10-11, 10, 3),
-	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(7-6...9-8, 9, 2),
-	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(7-6...11-10, 11, 3),
+/* Here we claim all are 16 bits. This currently does no harm and saves
+ * us a lot of scan element listings */
+
+#define MAX1363_SCAN_EL(number)						\
+	IIO_SCAN_EL_C(in##number, number, IIO_UNSIGNED(16), 0, NULL);
+#define MAX1363_SCAN_EL_D(p, n, number)					\
+	IIO_SCAN_NAMED_EL_C(in##p##m##in##n, in##p-in##n,		\
+			number, IIO_SIGNED(16), 0 , NULL);
+
+static MAX1363_SCAN_EL(0);
+static MAX1363_SCAN_EL(1);
+static MAX1363_SCAN_EL(2);
+static MAX1363_SCAN_EL(3);
+static MAX1363_SCAN_EL(4);
+static MAX1363_SCAN_EL(5);
+static MAX1363_SCAN_EL(6);
+static MAX1363_SCAN_EL(7);
+static MAX1363_SCAN_EL(8);
+static MAX1363_SCAN_EL(9);
+static MAX1363_SCAN_EL(10);
+static MAX1363_SCAN_EL(11);
+static MAX1363_SCAN_EL_D(0, 1, 12);
+static MAX1363_SCAN_EL_D(2, 3, 13);
+static MAX1363_SCAN_EL_D(4, 5, 14);
+static MAX1363_SCAN_EL_D(6, 7, 15);
+static MAX1363_SCAN_EL_D(8, 9, 16);
+static MAX1363_SCAN_EL_D(10, 11, 17);
+static MAX1363_SCAN_EL_D(1, 0, 18);
+static MAX1363_SCAN_EL_D(3, 2, 19);
+static MAX1363_SCAN_EL_D(5, 4, 20);
+static MAX1363_SCAN_EL_D(7, 6, 21);
+static MAX1363_SCAN_EL_D(9, 8, 22);
+static MAX1363_SCAN_EL_D(11, 10, 23);
+
+static const struct max1363_mode max1363_mode_table[] = {
+	/* All of the single channel options first */
+	MAX1363_MODE_SINGLE(0, 1 << 0),
+	MAX1363_MODE_SINGLE(1, 1 << 1),
+	MAX1363_MODE_SINGLE(2, 1 << 2),
+	MAX1363_MODE_SINGLE(3, 1 << 3),
+	MAX1363_MODE_SINGLE(4, 1 << 4),
+	MAX1363_MODE_SINGLE(5, 1 << 5),
+	MAX1363_MODE_SINGLE(6, 1 << 6),
+	MAX1363_MODE_SINGLE(7, 1 << 7),
+	MAX1363_MODE_SINGLE(8, 1 << 8),
+	MAX1363_MODE_SINGLE(9, 1 << 9),
+	MAX1363_MODE_SINGLE(10, 1 << 10),
+	MAX1363_MODE_SINGLE(11, 1 << 11),
+
+	MAX1363_MODE_DIFF_SINGLE(0, 1, 1 << 12),
+	MAX1363_MODE_DIFF_SINGLE(2, 3, 1 << 13),
+	MAX1363_MODE_DIFF_SINGLE(4, 5, 1 << 14),
+	MAX1363_MODE_DIFF_SINGLE(6, 7, 1 << 15),
+	MAX1363_MODE_DIFF_SINGLE(8, 9, 1 << 16),
+	MAX1363_MODE_DIFF_SINGLE(10, 11, 1 << 17),
+	MAX1363_MODE_DIFF_SINGLE(1, 0, 1 << 18),
+	MAX1363_MODE_DIFF_SINGLE(3, 2, 1 << 19),
+	MAX1363_MODE_DIFF_SINGLE(5, 4, 1 << 20),
+	MAX1363_MODE_DIFF_SINGLE(7, 6, 1 << 21),
+	MAX1363_MODE_DIFF_SINGLE(9, 8, 1 << 22),
+	MAX1363_MODE_DIFF_SINGLE(11, 10, 1 << 23),
+
+	/* The multichannel scans next */
+	MAX1363_MODE_SCAN_TO_CHANNEL(1, 0x003),
+	MAX1363_MODE_SCAN_TO_CHANNEL(2, 0x007),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(2, 3, 0x00C),
+	MAX1363_MODE_SCAN_TO_CHANNEL(3, 0x00F),
+	MAX1363_MODE_SCAN_TO_CHANNEL(4, 0x01F),
+	MAX1363_MODE_SCAN_TO_CHANNEL(5, 0x03F),
+	MAX1363_MODE_SCAN_TO_CHANNEL(6, 0x07F),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 7, 0x0C0),
+	MAX1363_MODE_SCAN_TO_CHANNEL(7, 0x0FF),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 8, 0x1C0),
+	MAX1363_MODE_SCAN_TO_CHANNEL(8, 0x1FF),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 9, 0x3C0),
+	MAX1363_MODE_SCAN_TO_CHANNEL(9, 0x3FF),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 10, 0x7C0),
+	MAX1363_MODE_SCAN_TO_CHANNEL(10, 0x7FF),
+	MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 11, 0xFC0),
+	MAX1363_MODE_SCAN_TO_CHANNEL(11, 0xFFF),
+
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(2, 2, 0x003000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(4, 3, 0x007000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(6, 4, 0x00F000),
+	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(8, 2, 0x018000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(8, 5, 0x01F000),
+	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(10, 3, 0x038000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(10, 6, 0x3F000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(3, 2, 0x0C0000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(5, 3, 0x1C0000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(7, 4, 0x3C0000),
+	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(9, 2, 0x600000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(9, 5, 0x7C0000),
+	MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(11, 3, 0xE00000),
+	MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(11, 6, 0xFC0000),
 };
 
+const struct max1363_mode
+*max1363_match_mode(u32 mask, const struct max1363_chip_info *ci) {
+	int i;
+	if (mask)
+		for (i = 0; i < ci->num_modes; i++)
+			if (!((~max1363_mode_table[ci->mode_list[i]]
+			       .modemask) &
+			      mask))
+				return &max1363_mode_table[ci
+							   ->mode_list[i]];
+	return 0;
+};
+
+static ssize_t max1363_show_precision(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct max1363_state *st = iio_dev_get_devdata(dev_info);
+	return sprintf(buf, "%d\n", st->chip_info->bits);
+}
+
+static IIO_DEVICE_ATTR(in_precision, S_IRUGO, max1363_show_precision,
+		       NULL, 0);
+
+static int max1363_write_basic_config(struct i2c_client *client,
+				      unsigned char d1,
+				      unsigned char d2)
+{
+	int ret;
+	u8 *tx_buf = kmalloc(2 , GFP_KERNEL);
+
+	if (!tx_buf)
+		return -ENOMEM;
+	tx_buf[0] = d1;
+	tx_buf[1] = d2;
+
+	ret = i2c_master_send(client, tx_buf, 2);
+	kfree(tx_buf);
+
+	return (ret > 0) ? 0 : ret;
+}
+
+int max1363_set_scan_mode(struct max1363_state *st)
+{
+	st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK
+			    | MAX1363_SCAN_MASK
+			    | MAX1363_SE_DE_MASK);
+	st->configbyte |= st->current_mode->conf;
+
+	return max1363_write_basic_config(st->client,
+					  st->setupbyte,
+					  st->configbyte);
+}
+
+static ssize_t max1363_read_single_channel(struct device *dev,
+				   struct device_attribute *attr,
+				   char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct max1363_state *st = iio_dev_get_devdata(dev_info);
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	struct i2c_client *client = st->client;
+	int ret = 0, len = 0;
+	s32 data ;
+	char rxbuf[2];
+	long mask;
+
+	mutex_lock(&dev_info->mlock);
+	/* If ring buffer capture is occuring, query the buffer */
+	if (iio_ring_enabled(dev_info)) {
+		mask = max1363_mode_table[this_attr->address].modemask;
+		data = max1363_single_channel_from_ring(mask, st);
+		if (data < 0) {
+			ret = data;
+			goto error_ret;
+		}
+	} else {
+		/* Check to see if current scan mode is correct */
+		if (st->current_mode !=
+		    &max1363_mode_table[this_attr->address]) {
+			/* Update scan mode if needed */
+			st->current_mode
+				= &max1363_mode_table[this_attr->address];
+			ret = max1363_set_scan_mode(st);
+			if (ret)
+				goto error_ret;
+		}
+		/* Get reading */
+		data = i2c_master_recv(client, rxbuf, 2);
+		if (data < 0) {
+			ret = data;
+			goto error_ret;
+		}
+		data = rxbuf[1];
+	}
+	/* Pretty print the result */
+	len = sprintf(buf, "%u\n", data);
+
+error_ret:
+	mutex_unlock(&dev_info->mlock);
+	return ret ? ret : len;
+}
+
+/* Direct read attribtues */
+static IIO_DEV_ATTR_IN_RAW(0, max1363_read_single_channel, _s0);
+static IIO_DEV_ATTR_IN_RAW(1, max1363_read_single_channel, _s1);
+static IIO_DEV_ATTR_IN_RAW(2, max1363_read_single_channel, _s2);
+static IIO_DEV_ATTR_IN_RAW(3, max1363_read_single_channel, _s3);
+static IIO_DEV_ATTR_IN_RAW(4, max1363_read_single_channel, _s4);
+static IIO_DEV_ATTR_IN_RAW(5, max1363_read_single_channel, _s5);
+static IIO_DEV_ATTR_IN_RAW(6, max1363_read_single_channel, _s6);
+static IIO_DEV_ATTR_IN_RAW(7, max1363_read_single_channel, _s7);
+static IIO_DEV_ATTR_IN_RAW(8, max1363_read_single_channel, _s8);
+static IIO_DEV_ATTR_IN_RAW(9, max1363_read_single_channel, _s9);
+static IIO_DEV_ATTR_IN_RAW(10, max1363_read_single_channel, _s10);
+static IIO_DEV_ATTR_IN_RAW(11, max1363_read_single_channel, _s11);
+
+static IIO_DEV_ATTR_IN_DIFF_RAW(0, 1, max1363_read_single_channel, d0m1);
+static IIO_DEV_ATTR_IN_DIFF_RAW(2, 3, max1363_read_single_channel, d2m3);
+static IIO_DEV_ATTR_IN_DIFF_RAW(4, 5, max1363_read_single_channel, d4m5);
+static IIO_DEV_ATTR_IN_DIFF_RAW(6, 7, max1363_read_single_channel, d6m7);
+static IIO_DEV_ATTR_IN_DIFF_RAW(8, 9, max1363_read_single_channel, d8m9);
+static IIO_DEV_ATTR_IN_DIFF_RAW(10, 11, max1363_read_single_channel, d10m11);
+static IIO_DEV_ATTR_IN_DIFF_RAW(1, 0, max1363_read_single_channel, d1m0);
+static IIO_DEV_ATTR_IN_DIFF_RAW(3, 2, max1363_read_single_channel, d3m2);
+static IIO_DEV_ATTR_IN_DIFF_RAW(5, 4, max1363_read_single_channel, d5m4);
+static IIO_DEV_ATTR_IN_DIFF_RAW(7, 6, max1363_read_single_channel, d7m6);
+static IIO_DEV_ATTR_IN_DIFF_RAW(9, 8, max1363_read_single_channel, d9m8);
+static IIO_DEV_ATTR_IN_DIFF_RAW(11, 10, max1363_read_single_channel, d11m10);
+
+
+static ssize_t max1363_show_scale(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	/* Driver currently only support internal vref */
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct max1363_state *st = iio_dev_get_devdata(dev_info);
+	/* Corresponds to Vref / 2^(bits) */
+
+	if ((1 << (st->chip_info->bits + 1))
+	    > st->chip_info->int_vref_mv)
+		return sprintf(buf, "0.5\n");
+	else
+		return sprintf(buf, "%d\n",
+			st->chip_info->int_vref_mv >> st->chip_info->bits);
+}
+
+IIO_DEVICE_ATTR(in_scale, S_IRUGO, max1363_show_scale, NULL, 0);
+
+static ssize_t max1363_show_name(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	struct iio_dev *dev_info = dev_get_drvdata(dev);
+	struct max1363_state *st = iio_dev_get_devdata(dev_info);
+	return sprintf(buf, "%s\n", st->chip_info->name);
+}
+
+IIO_DEVICE_ATTR(name, S_IRUGO, max1363_show_name, NULL, 0);
+
 /* Applies to max1363 */
 static const enum max1363_modes max1363_mode_list[] = {
 	_s0, _s1, _s2, _s3,
-	se0, se1, se2, se3,
 	s0to1, s0to2, s0to3,
 	d0m1, d2m3, d1m0, d3m2,
-	de0m1, de2m3, de1m0, de3m2,
 	d0m1to2m3, d1m0to3m2,
 };
 
+static struct attribute *max1363_device_attrs[] = {
+	&iio_dev_attr_in0_raw.dev_attr.attr,
+	&iio_dev_attr_in1_raw.dev_attr.attr,
+	&iio_dev_attr_in2_raw.dev_attr.attr,
+	&iio_dev_attr_in3_raw.dev_attr.attr,
+	&iio_dev_attr_in0min1_raw.dev_attr.attr,
+	&iio_dev_attr_in2min3_raw.dev_attr.attr,
+	&iio_dev_attr_in1min0_raw.dev_attr.attr,
+	&iio_dev_attr_in3min2_raw.dev_attr.attr,
+	&iio_dev_attr_name.dev_attr.attr,
+	&iio_dev_attr_in_scale.dev_attr.attr,
+	NULL
+};
+
+static struct attribute_group max1363_dev_attr_group = {
+	.attrs = max1363_device_attrs,
+};
+
+static struct attribute *max1363_scan_el_attrs[] = {
+	&iio_scan_el_in0.dev_attr.attr,
+	&iio_scan_el_in1.dev_attr.attr,
+	&iio_scan_el_in2.dev_attr.attr,
+	&iio_scan_el_in3.dev_attr.attr,
+	&iio_scan_el_in0min1.dev_attr.attr,
+	&iio_scan_el_in2min3.dev_attr.attr,
+	&iio_scan_el_in1min0.dev_attr.attr,
+	&iio_scan_el_in3min2.dev_attr.attr,
+	&iio_dev_attr_in_precision.dev_attr.attr,
+	NULL,
+};
+
+static struct attribute_group max1363_scan_el_group = {
+	.name = "scan_elements",
+	.attrs = max1363_scan_el_attrs,
+};
+
 /* Appies to max1236, max1237 */
 static const enum max1363_modes max1236_mode_list[] = {
 	_s0, _s1, _s2, _s3,
-	se0, se1, se2, se3,
 	s0to1, s0to2, s0to3,
 	d0m1, d2m3, d1m0, d3m2,
-	de0m1, de2m3, de1m0, de3m2,
 	d0m1to2m3, d1m0to3m2,
 	s2to3,
 };
@@ -156,19 +355,83 @@ static const enum max1363_modes max1236_mode_list[] = {
 /* Applies to max1238, max1239 */
 static const enum max1363_modes max1238_mode_list[] = {
 	_s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
-	se0, se1, se2, se3, se4, se5, se6, se7, se8, se9, se10, se11,
 	s0to1, s0to2, s0to3, s0to4, s0to5, s0to6,
 	s0to7, s0to8, s0to9, s0to10, s0to11,
 	d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
 	d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
-	de0m1, de2m3, de4m5, de6m7, de8m9, de10m11,
-	de1m0, de3m2, de5m4, de7m6, de9m8, de11m10,
 	d0m1to2m3, d0m1to4m5, d0m1to6m7, d0m1to8m9, d0m1to10m11,
 	d1m0to3m2, d1m0to5m4, d1m0to7m6, d1m0to9m8, d1m0to11m10,
 	s6to7, s6to8, s6to9, s6to10, s6to11,
-	s6m7to8m9, s6m7to10m11, s7m6to9m8, s7m6to11m10,
+	d6m7to8m9, d6m7to10m11, d7m6to9m8, d7m6to11m10,
 };
 
+static struct attribute *max1238_device_attrs[] = {
+	&iio_dev_attr_in0_raw.dev_attr.attr,
+	&iio_dev_attr_in1_raw.dev_attr.attr,
+	&iio_dev_attr_in2_raw.dev_attr.attr,
+	&iio_dev_attr_in3_raw.dev_attr.attr,
+	&iio_dev_attr_in4_raw.dev_attr.attr,
+	&iio_dev_attr_in5_raw.dev_attr.attr,
+	&iio_dev_attr_in6_raw.dev_attr.attr,
+	&iio_dev_attr_in7_raw.dev_attr.attr,
+	&iio_dev_attr_in8_raw.dev_attr.attr,
+	&iio_dev_attr_in9_raw.dev_attr.attr,
+	&iio_dev_attr_in10_raw.dev_attr.attr,
+	&iio_dev_attr_in11_raw.dev_attr.attr,
+	&iio_dev_attr_in0min1_raw.dev_attr.attr,
+	&iio_dev_attr_in2min3_raw.dev_attr.attr,
+	&iio_dev_attr_in4min5_raw.dev_attr.attr,
+	&iio_dev_attr_in6min7_raw.dev_attr.attr,
+	&iio_dev_attr_in8min9_raw.dev_attr.attr,
+	&iio_dev_attr_in10min11_raw.dev_attr.attr,
+	&iio_dev_attr_in1min0_raw.dev_attr.attr,
+	&iio_dev_attr_in3min2_raw.dev_attr.attr,
+	&iio_dev_attr_in5min4_raw.dev_attr.attr,
+	&iio_dev_attr_in7min6_raw.dev_attr.attr,
+	&iio_dev_attr_in9min8_raw.dev_attr.attr,
+	&iio_dev_attr_in11min10_raw.dev_attr.attr,
+	&iio_dev_attr_name.dev_attr.attr,
+	&iio_dev_attr_in_scale.dev_attr.attr,
+	NULL
+};
+
+static struct attribute_group max1238_dev_attr_group = {
+	.attrs = max1238_device_attrs,
+};
+
+static struct attribute *max1238_scan_el_attrs[] = {
+	&iio_scan_el_in0.dev_attr.attr,
+	&iio_scan_el_in1.dev_attr.attr,
+	&iio_scan_el_in2.dev_attr.attr,
+	&iio_scan_el_in3.dev_attr.attr,
+	&iio_scan_el_in4.dev_attr.attr,
+	&iio_scan_el_in5.dev_attr.attr,
+	&iio_scan_el_in6.dev_attr.attr,
+	&iio_scan_el_in7.dev_attr.attr,
+	&iio_scan_el_in8.dev_attr.attr,
+	&iio_scan_el_in9.dev_attr.attr,
+	&iio_scan_el_in10.dev_attr.attr,
+	&iio_scan_el_in11.dev_attr.attr,
+	&iio_scan_el_in0min1.dev_attr.attr,
+	&iio_scan_el_in2min3.dev_attr.attr,
+	&iio_scan_el_in4min5.dev_attr.attr,
+	&iio_scan_el_in6min7.dev_attr.attr,
+	&iio_scan_el_in8min9.dev_attr.attr,
+	&iio_scan_el_in10min11.dev_attr.attr,
+	&iio_scan_el_in1min0.dev_attr.attr,
+	&iio_scan_el_in3min2.dev_attr.attr,
+	&iio_scan_el_in5min4.dev_attr.attr,
+	&iio_scan_el_in7min6.dev_attr.attr,
+	&iio_scan_el_in9min8.dev_attr.attr,
+	&iio_scan_el_in11min10.dev_attr.attr,
+	&iio_dev_attr_in_precision.dev_attr.attr,
+	NULL,
+};
+
+static struct attribute_group max1238_scan_el_group = {
+	.name = "scan_elements",
+	.attrs = max1238_scan_el_attrs,
+};
 
 enum { max1361,
        max1362,
@@ -189,118 +452,130 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {
 	{
 		.name = "max1361",
 		.num_inputs = 4,
+		.bits = 10,
+		.int_vref_mv = 2048,
 		.monitor_mode = 1,
 		.mode_list = max1363_mode_list,
 		.num_modes = ARRAY_SIZE(max1363_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1362",
 		.num_inputs = 4,
+		.bits = 10,
+		.int_vref_mv = 4096,
 		.monitor_mode = 1,
 		.mode_list = max1363_mode_list,
 		.num_modes = ARRAY_SIZE(max1363_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1363",
 		.num_inputs = 4,
+		.bits = 12,
+		.int_vref_mv = 2048,
 		.monitor_mode = 1,
 		.mode_list = max1363_mode_list,
 		.num_modes = ARRAY_SIZE(max1363_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1364",
 		.num_inputs = 4,
+		.bits = 12,
+		.int_vref_mv = 4096,
 		.monitor_mode = 1,
 		.mode_list = max1363_mode_list,
 		.num_modes = ARRAY_SIZE(max1363_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1136",
 		.num_inputs = 4,
+		.bits = 10,
 		.int_vref_mv = 4096,
 		.mode_list = max1236_mode_list,
 		.num_modes = ARRAY_SIZE(max1236_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1137",
 		.num_inputs = 4,
+		.bits = 10,
 		.int_vref_mv = 2048,
 		.mode_list = max1236_mode_list,
 		.num_modes = ARRAY_SIZE(max1236_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1138",
 		.num_inputs = 12,
+		.bits = 10,
 		.int_vref_mv = 4096,
 		.mode_list = max1238_mode_list,
 		.num_modes = ARRAY_SIZE(max1238_mode_list),
 		.default_mode = s0to11,
+		.dev_attrs = &max1238_dev_attr_group,
+		.scan_attrs = &max1238_scan_el_group,
 	}, {
 		.name = "max1139",
 		.num_inputs = 12,
+		.bits = 10,
 		.int_vref_mv = 2048,
 		.mode_list = max1238_mode_list,
 		.num_modes = ARRAY_SIZE(max1238_mode_list),
 		.default_mode = s0to11,
+		.dev_attrs = &max1238_dev_attr_group,
+		.scan_attrs = &max1238_scan_el_group,
 	}, {
 		.name = "max1236",
 		.num_inputs = 4,
+		.bits = 12,
 		.int_vref_mv = 4096,
 		.mode_list = max1236_mode_list,
 		.num_modes = ARRAY_SIZE(max1236_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1237",
 		.num_inputs = 4,
+		.bits = 12,
 		.int_vref_mv = 2048,
 		.mode_list = max1236_mode_list,
 		.num_modes = ARRAY_SIZE(max1236_mode_list),
 		.default_mode = s0to3,
+		.dev_attrs = &max1363_dev_attr_group,
+		.scan_attrs = &max1363_scan_el_group,
 	}, {
 		.name = "max1238",
 		.num_inputs = 12,
+		.bits = 12,
 		.int_vref_mv = 4096,
 		.mode_list = max1238_mode_list,
 		.num_modes = ARRAY_SIZE(max1238_mode_list),
 		.default_mode = s0to11,
+		.dev_attrs = &max1238_dev_attr_group,
+		.scan_attrs = &max1238_scan_el_group,
 	}, {
 		.name = "max1239",
 		.num_inputs = 12,
+		.bits = 12,
 		.int_vref_mv = 2048,
 		.mode_list = max1238_mode_list,
 		.num_modes = ARRAY_SIZE(max1238_mode_list),
 		.default_mode = s0to11,
+		.dev_attrs = &max1238_dev_attr_group,
+		.scan_attrs = &max1238_scan_el_group,
 	},
 };
 
-static int max1363_write_basic_config(struct i2c_client *client,
-				      unsigned char d1,
-				      unsigned char d2)
-{
-	int ret;
-	u8 *tx_buf = kmalloc(2 , GFP_KERNEL);
-	if (!tx_buf)
-		return -ENOMEM;
-	tx_buf[0] = d1;
-	tx_buf[1] = d2;
-
-	ret = i2c_master_send(client, tx_buf, 2);
-	kfree(tx_buf);
-	return (ret > 0) ? 0 : ret;
-}
-
-static int max1363_set_scan_mode(struct max1363_state *st)
-{
-	st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK
-			    | MAX1363_SCAN_MASK
-			    | MAX1363_SE_DE_MASK);
-	st->configbyte |= st->current_mode->conf;
-
-	return max1363_write_basic_config(st->client,
-					  st->setupbyte,
-					  st->configbyte);
-}
-
 static int max1363_initial_setup(struct max1363_state *st)
 {
 	st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD
@@ -317,167 +592,6 @@ static int max1363_initial_setup(struct max1363_state *st)
 	return max1363_set_scan_mode(st);
 }
 
-static ssize_t max1363_show_av_scan_modes(struct device *dev,
-					  struct device_attribute *attr,
-					  char *buf)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *st = dev_info->dev_data;
-	int i, len = 0;
-
-	for (i = 0; i < st->chip_info->num_modes; i++)
-		len += sprintf(buf + len, "%s ",
-			       max1363_mode_table[st->chip_info
-						  ->mode_list[i]].name);
-	len += sprintf(buf + len, "\n");
-
-	return len;
-}
-
-
-/* The dev here is the sysfs related one, not the underlying i2c one */
-static ssize_t max1363_scan_direct(struct device *dev,
-				   struct device_attribute *attr,
-				   char *buf)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *st = dev_info->dev_data;
-	int len = 0, ret, i;
-	struct i2c_client *client = st->client;
-	char *rxbuf;
-
-	if (st->current_mode->numvals == 0)
-		return 0;
-	rxbuf = kmalloc(st->current_mode->numvals*2, GFP_KERNEL);
-	if (rxbuf == NULL)
-		return -ENOMEM;
-
-	/* Interpretation depends on whether these are signed or not!*/
-	/* Assume not for now */
-	ret = i2c_master_recv(client, rxbuf, st->current_mode->numvals*2);
-
-	if (ret < 0)
-		return ret;
-	for (i = 0; i < st->current_mode->numvals; i++)
-		len += sprintf(buf+len, "%d ",
-			       ((int)(rxbuf[i*2+0]&0x0F) << 8)
-			       + ((int)(rxbuf[i*2+1])));
-	kfree(rxbuf);
-	len += sprintf(buf + len, "\n");
-
-	return len;
-}
-
-static ssize_t max1363_scan(struct device *dev,
-			    struct device_attribute *attr,
-			    char *buf)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	int ret;
-
-	mutex_lock(&dev_info->mlock);
-	if (dev_info->currentmode == INDIO_RING_TRIGGERED)
-		ret = max1363_scan_from_ring(dev, attr, buf);
-	else
-		ret = max1363_scan_direct(dev, attr, buf);
-	mutex_unlock(&dev_info->mlock);
-
-	return ret;
-}
-
-/* Cannot query the device, so use local copy of state */
-static ssize_t max1363_show_scan_mode(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *st = dev_info->dev_data;
-
-	return sprintf(buf, "%s\n", st->current_mode->name);
-}
-
-static const struct max1363_mode
-*__max1363_find_mode_in_ci(const struct max1363_chip_info *info,
-				  const char *buf)
-{
-	int i;
-	for (i = 0; i <  info->num_modes; i++)
-		if (strcmp(max1363_mode_table[info->mode_list[i]].name, buf)
-		    == 0)
-			return &max1363_mode_table[info->mode_list[i]];
-	return NULL;
-}
-
-static ssize_t max1363_store_scan_mode(struct device *dev,
-				       struct device_attribute *attr,
-				       const char *buf,
-				       size_t len)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *st = dev_info->dev_data;
-	const struct max1363_mode *new_mode;
-	int ret;
-
-	mutex_lock(&dev_info->mlock);
-	new_mode = NULL;
-	/* Avoid state changes if a ring buffer is enabled */
-	if (!iio_ring_enabled(dev_info)) {
-		new_mode
-			= __max1363_find_mode_in_ci(st->chip_info, buf);
-		if (!new_mode) {
-			ret = -EINVAL;
-			goto error_ret;
-		}
-		st->current_mode = new_mode;
-		ret =  max1363_set_scan_mode(st);
-		if (ret)
-			goto error_ret;
-	} else {
-		ret = -EBUSY;
-		goto error_ret;
-	}
-	mutex_unlock(&dev_info->mlock);
-
-	return len;
-
-error_ret:
-	mutex_unlock(&dev_info->mlock);
-
-	return ret;
-}
-
-IIO_DEV_ATTR_AVAIL_SCAN_MODES(max1363_show_av_scan_modes);
-IIO_DEV_ATTR_SCAN_MODE(S_IRUGO | S_IWUSR,
-		       max1363_show_scan_mode,
-		       max1363_store_scan_mode);
-
-IIO_DEV_ATTR_SCAN(max1363_scan);
-
-static ssize_t max1363_show_name(struct device *dev,
-				 struct device_attribute *attr,
-				 char *buf)
-{
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *st = dev_info->dev_data;
-	return sprintf(buf, "%s\n", st->chip_info->name);
-}
-
-IIO_DEVICE_ATTR(name, S_IRUGO, max1363_show_name, NULL, 0);
-
-/*name export */
-
-static struct attribute *max1363_attributes[] = {
-	&iio_dev_attr_available_scan_modes.dev_attr.attr,
-	&iio_dev_attr_scan_mode.dev_attr.attr,
-	&iio_dev_attr_scan.dev_attr.attr,
-	&iio_dev_attr_name.dev_attr.attr,
-	NULL,
-};
-
-static const struct attribute_group max1363_attribute_group = {
-	.attrs = max1363_attributes,
-};
-
 static int __devinit max1363_probe(struct i2c_client *client,
 				   const struct i2c_device_id *id)
 {
@@ -505,6 +619,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
 		ret = -ENODEV;
 		goto error_free_st;
 	}
+
 	st->reg = regulator_get(&client->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
@@ -519,20 +634,36 @@ static int __devinit max1363_probe(struct i2c_client *client,
 		goto error_disable_reg;
 	}
 
+	st->indio_dev->available_scan_masks
+		= kzalloc(GFP_KERNEL,
+			sizeof(*st->indio_dev->available_scan_masks)*
+			(st->chip_info->num_modes + 1));
+	if (!st->indio_dev->available_scan_masks) {
+		ret = -ENOMEM;
+		goto error_free_device;
+	}
+
+	for (i = 0; i < st->chip_info->num_modes; i++)
+		st->indio_dev->available_scan_masks[i] =
+			max1363_mode_table[st->chip_info->mode_list[i]]
+			.modemask;
 	/* Estabilish that the iio_dev is a child of the i2c device */
 	st->indio_dev->dev.parent = &client->dev;
-	st->indio_dev->attrs = &max1363_attribute_group;
+	st->indio_dev->attrs = st->chip_info->dev_attrs;
+
+	/* Todo: this shouldn't be here. */
+	st->indio_dev->scan_el_attrs = st->chip_info->scan_attrs;
 	st->indio_dev->dev_data = (void *)(st);
 	st->indio_dev->driver_module = THIS_MODULE;
 	st->indio_dev->modes = INDIO_DIRECT_MODE;
 
 	ret = max1363_initial_setup(st);
 	if (ret)
-		goto error_free_device;
+		goto error_free_available_scan_masks;
 
 	ret = max1363_register_ring_funcs_and_init(st->indio_dev);
 	if (ret)
-		goto error_free_device;
+		goto error_free_available_scan_masks;
 
 	ret = iio_device_register(st->indio_dev);
 	if (ret)
@@ -544,6 +675,8 @@ static int __devinit max1363_probe(struct i2c_client *client,
 	return 0;
 error_cleanup_ring:
 	max1363_ring_cleanup(st->indio_dev);
+error_free_available_scan_masks:
+	kfree(st->indio_dev->available_scan_masks);
 error_free_device:
 	if (!regdone)
 		iio_free_device(st->indio_dev);
@@ -568,6 +701,7 @@ static int max1363_remove(struct i2c_client *client)
 	struct iio_dev *indio_dev = st->indio_dev;
 	max1363_uninitialize_ring(indio_dev->ring);
 	max1363_ring_cleanup(indio_dev);
+	kfree(st->indio_dev->available_scan_masks);
 	iio_device_unregister(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index a953eac..0de3e87 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -16,6 +16,7 @@
 #include <linux/sysfs.h>
 #include <linux/list.h>
 #include <linux/i2c.h>
+#include <linux/bitops.h>
 
 #include "../iio.h"
 #include "../ring_generic.h"
@@ -25,32 +26,36 @@
 
 #include "max1363.h"
 
-ssize_t max1363_scan_from_ring(struct device *dev,
-			       struct device_attribute *attr,
-			       char *buf)
+/* Todo: test this */
+int max1363_single_channel_from_ring(long mask, struct max1363_state *st)
 {
-	struct iio_dev *dev_info = dev_get_drvdata(dev);
-	struct max1363_state *info = dev_info->dev_data;
-	int i, ret, len = 0;
-	char *ring_data;
+	unsigned long numvals;
+	int count = 0, ret;
+	u8 *ring_data;
+	if (!(st->current_mode->modemask & mask)) {
+		ret = -EBUSY;
+		goto error_ret;
+	}
+	numvals = hweight_long(st->current_mode->modemask);
 
-	ring_data = kmalloc(info->current_mode->numvals*2, GFP_KERNEL);
+	ring_data = kmalloc(numvals*2, GFP_KERNEL);
 	if (ring_data == NULL) {
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	ret = dev_info->ring->access.read_last(dev_info->ring, ring_data);
+	ret = st->indio_dev->ring->access.read_last(st->indio_dev->ring,
+						ring_data);
 	if (ret)
 		goto error_free_ring_data;
-	len += sprintf(buf+len, "ring ");
-	for (i = 0; i < info->current_mode->numvals; i++)
-		len += sprintf(buf + len, "%d ",
-			       ((int)(ring_data[i*2 + 0] & 0x0F) << 8)
-			       + ((int)(ring_data[i*2 + 1])));
-	len += sprintf(buf + len, "\n");
-	kfree(ring_data);
-
-	return len;
+	/* Need a count of channels prior to this one */
+	mask >>= 1;
+	while (mask) {
+		if (mask && st->current_mode->modemask)
+			count++;
+		mask >>= 1;
+	}
+	return ((int)(ring_data[count*2 + 0] & 0x0F) << 8)
+		+ (int)(ring_data[count*2 + 1]);
 
 error_free_ring_data:
 	kfree(ring_data);
@@ -69,9 +74,22 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct max1363_state *st = indio_dev->dev_data;
 	size_t d_size;
+	unsigned long numvals;
+
+	/*
+	 * Need to figure out the current mode based upon the requested
+	 * scan mask in iio_dev
+	 */
+	st->current_mode = max1363_match_mode(st->indio_dev->scan_mask,
+					st->chip_info);
+	if (!st->current_mode)
+		return -EINVAL;
+
+	max1363_set_scan_mode(st);
 
+	numvals = hweight_long(st->current_mode->modemask);
 	if (indio_dev->ring->access.set_bpd) {
-		d_size = st->current_mode->numvals*2 + sizeof(s64);
+		d_size = numvals*2 + sizeof(s64);
 		if (d_size % 8)
 			d_size += 8 - (d_size % 8);
 		indio_dev->ring->access.set_bpd(indio_dev->ring, d_size);
@@ -144,9 +162,10 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
 	__u8 *rxbuf;
 	int b_sent;
 	size_t d_size;
+	unsigned long numvals = hweight_long(st->current_mode->modemask);
 
 	/* Ensure the timestamp is 8 byte aligned */
-	d_size = st->current_mode->numvals*2 + sizeof(s64);
+	d_size = numvals*2 + sizeof(s64);
 	if (d_size % sizeof(s64))
 		d_size += sizeof(s64) - (d_size % sizeof(s64));
 
@@ -158,16 +177,14 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
 	 * might as well have this test in here in the meantime as it does
 	 * no harm.
 	 */
-	if (st->current_mode->numvals == 0)
+	if (numvals == 0)
 		return;
 
 	rxbuf = kmalloc(d_size,	GFP_KERNEL);
 	if (rxbuf == NULL)
 		return;
 
-	b_sent = i2c_master_recv(st->client,
-				 rxbuf,
-				 st->current_mode->numvals*2);
+	b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
 	if (b_sent < 0)
 		goto done;
 
-- 
1.6.4.4

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

* [PATCH 09/13] staging:iio: Documentation, update iio_utils.h for the move to a bus
  2010-03-28 20:41               ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
@ 2010-03-28 20:41                 ` Jonathan Cameron
  2010-03-28 20:41                   ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
  2010-03-30 14:31                 ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
  1 sibling, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/Documentation/iio_utils.h |   31 ++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/Documentation/iio_utils.h b/drivers/staging/iio/Documentation/iio_utils.h
index 74d3124..d24006a 100644
--- a/drivers/staging/iio/Documentation/iio_utils.h
+++ b/drivers/staging/iio/Documentation/iio_utils.h
@@ -47,7 +47,7 @@ inline char *find_ring_subelement(const char *directory, const char *subelement)
 
 char *find_type_by_name(const char *name, const char *type)
 {
-	const char *iio_dir = "/sys/class/iio/";
+	const char *iio_dir = "/sys/bus/iio/devices/";
 	const struct dirent *ent;
 	int cnt, pos, pos2;
 
@@ -112,6 +112,35 @@ int write_sysfs_int(char *filename, char *basedir, int val)
 	return 0;
 }
 
+int write_sysfs_int_and_verify(char *filename, char *basedir, int val)
+{
+	int ret;
+	FILE  *sysfsfp;
+	char temp[100];
+	int test;
+
+	sprintf(temp, "%s%s", basedir, filename);
+	sysfsfp = fopen(temp, "w");
+	if (sysfsfp == NULL)
+		return -1;
+	fprintf(sysfsfp, "%d", val);
+	fclose(sysfsfp);
+
+	sysfsfp = fopen(temp, "r");
+	if (sysfsfp == NULL)
+		return -1;
+	fscanf(sysfsfp, "%d", &test);
+	if (test != val) {
+		printf("Possible failure in int write %d to %s%s\n",
+		       val,
+		       basedir,
+		       filename);
+		return -1;
+	}
+
+	return 0;
+}
+
 /**
  * write_sysfs_string_and_verify() - string write, readback and verify
  * @filename: name of file to write to
-- 
1.6.4.4

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

* [PATCH 10/13] staging:iio: ABI documentation (partial)
  2010-03-28 20:41                 ` [PATCH 09/13] staging:iio: Documentation, update iio_utils.h for the move to a bus Jonathan Cameron
@ 2010-03-28 20:41                   ` Jonathan Cameron
  2010-03-28 20:41                     ` [PATCH 11/13] staging:iio: Directory name changes to match new ABI Jonathan Cameron
  2010-03-29 13:55                     ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
  0 siblings, 2 replies; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/Documentation/sysfs-class-iio |  265 +++++++++++++++++++++
 1 files changed, 265 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/iio/Documentation/sysfs-class-iio b/drivers/staging/iio/Documentation/sysfs-class-iio
new file mode 100644
index 0000000..0da560d
--- /dev/null
+++ b/drivers/staging/iio/Documentation/sysfs-class-iio
@@ -0,0 +1,265 @@
+
+What:		/sys/bus/iio/devices/device[n]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Hardware chip or device accessed by on communication port.
+		Corresponds to a grouping of sensor channels.
+
+What:		/sys/bus/iio/devices/trigger[n]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		An event driven driver of data capture to an in kernel buffer.
+		May be provided by a device driver that also has an IIO device
+		based on hardware generated events (e.g. data ready) or
+		provided by a separate driver for other hardware (e.g.
+		periodic timer, gpio or high resolution timer).
+		Contains trigger type specific elements. These do not
+		generalize well and hence are not documented in this file.
+
+What:		/sys/bus/iio/devices/device[n]:buffer
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+	        Link to /sys/class/iio/device[n]/device[n]:buffer. n indicates the
+		device with which this buffer buffer is associated.
+
+What:		/sys/.../device[n]/name
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Description of the physical chip / device. Typically a part
+		number.
+
+What:		/sys/.../device[n]/in[_name][m]_raw
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Raw (unscaled no bias removal etc) voltage measurement from
+		channel m. name is used in special cases where this does
+		not correspond to externally available input (e.g. supply
+		voltage monitoring in which case the file is in_supply_raw).
+
+What:		/sys/.../device[n]/in[_name][m]_offset
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		If known for a device, offset to be added to in[m]_raw prior
+		to scaling by volt[m]_scale in order to obtain voltage in
+		millivolts.  Not present if the offset is always 0 or unknown.
+		If m is not present, then voltage offset applies to all in
+		channels. May be writable if a variable offset is controlled
+		by the device. Note that this is different to calibbias which
+		is for devices that apply offsets to compensate for variation
+		between different instances of the part, typically adjusted by
+		using some hardware supported calibration procedure.
+
+What:		/sys/.../device[n]/in[_name][m]_offset_available
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		If a small number of discrete offset values are available, this
+		will be a space separated list.  If these are independant (but
+		options the same) for individual offsets then m should not be
+		present.
+
+What:		/sys/.../device[n]/in[_name][m]_offset_[min|max]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		If a more or less continuous range of voltage offsets are supported
+		then these specify the minimum and maximum.  If shared by all
+		in channels then m is not present.
+
+What:		/sys/.../device[n]/in[_name][m]_calibbias
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Hardware applied calibration offset. (assumed to fix production
+		inaccuracies)
+
+What		/sys/.../device[n]/in[_name][m]_calibscale
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Hardware applied calibration scale factor. (assumed to fix production
+		inaccuracies)
+
+What:		/sys/.../device[n]/in[_name][m]_scale
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		If known for a device, scale to be applied to volt[m]_raw post
+		addition of volt[m]_offset in order to obtain the measured voltage
+		in millivolts.  If shared across all in channels then m is not present.
+
+What:		/sys/.../device[n]/in[m]-in[o]_raw
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Raw (unscaled) differential voltage measurement equivalent to
+		channel m - channel o where these channel numbers apply to the physically
+		equivalent inputs when non differential readings are separately available.
+		In differential only parts, then all that is required is a consistent
+		labelling.
+
+What:		/sys/.../device[n]/accel[_x|_y|_z][m]_raw
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Acceleration in direction x, y or z (may be arbitrarily assigned
+		but should match other such assignments on device)
+		channel m (not present if only one accelerometer channel at
+		this orientation). Has all of the equivalent parameters as per in[m].
+		Units after application of scale and offset are m/s^2.
+
+What:		/sys/.../device[n]/gyro[_x|_y|_z][m]_raw
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Angular velocity about axis x, y or z (may be arbitrarily assigned)
+		channel m (not present if only one gyroscope at this orientation).
+		Data converted by application of offset then scale to
+		radians per second. Has all the equivalent parameters as per in[m].
+
+What:		/sys/.../device[n]/mag[_x|_y|_z][m]_raw
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Magnetic field along axis x, y or z (may be arbitrarily assigned)
+		channel m (not present if only one magnetometer at this orientation).
+		Data converted by application of offset then scale to Gauss
+		Has all the equivalent modifiers as per in[m].
+
+What:		/sys/.../device[n]/device[n]:event[m]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Configuration of which hardware generated events are passed up to
+		userspace. Some of these are a bit complex to generalize so this
+		section is a work in progress.
+
+What:		/sys/.../device[n]:event[m]/dev
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		major:minor character device numbers for the event line.
+
+Taking accel_x0 as an example
+
+What:		/sys/.../device[n]:event[m]/accel_x0_thresh[_high|_low]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Event generated when accel_x0 passes a threshold in correction direction
+		(or stays beyond one). If direction isn't specified, either triggers it.
+		Note driver will assume last p events requested are enabled where p is
+		however many it supports.  So if you want to be sure you have
+		set what you think you have, check the contents of these. Drivers
+		may have to buffer any parameters so that they are consistent when a
+		given event type is enabled a future point (and not those for whatever
+		alarm was previously enabled).
+
+What:		/sys/.../device[n]:event[m]/accel_x0_roc[_high|_low]
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Same as above but based on the first differential of the value.
+
+
+What:		/sys/.../device[n]:event[m]/accel_x0[_thresh|_roc][_high|_low]_period
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		A period of time (microsecs) for which the condition must be broken
+		before an interrupt is triggered. Applies to all alarms if type is not
+		specified.
+
+What:		/sys/.../device[n]:event[m]/accel_x0[_thresh|_roc][_high|_low]_value
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		The actual value of the threshold in raw device units obtained by
+		 reverse application of scale and offfset to the acceleration in m/s^2.
+
+What:		/sys/.../device[n]/scan_elements
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Directory containing interfaces for elements that will be captured
+		for a single triggered sample set in the buffer.
+
+What:		/sys/.../device[n]/scan_elements/[m]_accel_x0_en
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Scan element control for triggered data capture. m implies the
+		ordering within the buffer. Next the type is specified with
+		modifier and channel number as per the sysfs single channel
+		access above.
+
+What:		/sys/.../device[n]/scan_elements/accel[_x0]_precision
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Scan element precision within the buffer. Note that the
+		data alignment must restrictions must be read from within
+		buffer to work out full data alignment for data read
+		via buffer_access chrdev. _x0 dropped if shared across all
+		acceleration channels.
+
+What:		/sys/.../device[n]/scan_elements/accel[_x0]_shift
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		A bit shift (to right) that must be applied prior to
+		extracting the bits specified by accel[_x0]_precision.
+
+What:		/sys/.../device[n]/device[n]:buffer:event/dev
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Buffer for device n event character device major:minor numbers.
+
+What:		/sys/.../device[n]/device[n]:buffer:access/dev
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Buffer for device n access character device o major:minor numbers.
+
+What:		/sys/.../device[n]:buffer/trigger
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		The name of the trigger source being used, as per string given
+		in /sys/class/iio/trigger[n]/name.
+
+What:		/sys/.../device[n]:buffer/length
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Number of scans contained by the buffer.
+
+What:		/sys/.../device[n]:buffer/bps
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Bytes per scan.  Due to alignment fun, the scan may be larger
+		than implied directly by the scan_element parameters.
+
+What:		/sys/.../device[n]:buffer/enable
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Actually start the buffer capture up.  Will start trigger
+		if first device and appropriate.
+
+What:		/sys/.../device[n]:buffer/alignment
+KernelVersion:	2.6.35
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Minimum data alignment.  Scan elements larger than this are aligned
+		to the nearest power of 2 times this.  (may not be true in weird
+		hardware buffers that pack data well)
+
-- 
1.6.4.4

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

* [PATCH 11/13] staging:iio: Directory name changes to match new ABI.
  2010-03-28 20:41                   ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
@ 2010-03-28 20:41                     ` Jonathan Cameron
  2010-03-28 20:41                       ` [PATCH 12/13] staging:iio:tsl2563: change lux to illuminance0_input to match new abi Jonathan Cameron
  2010-03-29 13:55                     ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
  1 sibling, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/chrdev.h            |    2 +-
 drivers/staging/iio/industrialio-core.c |    5 +++--
 drivers/staging/iio/industrialio-ring.c |   13 +++++++++----
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/iio/chrdev.h b/drivers/staging/iio/chrdev.h
index f42bafb..3f96f86 100644
--- a/drivers/staging/iio/chrdev.h
+++ b/drivers/staging/iio/chrdev.h
@@ -94,7 +94,7 @@ struct iio_event_interface {
 	struct iio_chrdev_minor_attr		attr;
 	struct module				*owner;
 	void					*private;
-	char					_name[20];
+	char					_name[35];
 	char					_attrname[20];
 };
 
diff --git a/drivers/staging/iio/industrialio-core.c b/drivers/staging/iio/industrialio-core.c
index 1f49f09..a0838c2 100644
--- a/drivers/staging/iio/industrialio-core.c
+++ b/drivers/staging/iio/industrialio-core.c
@@ -659,8 +659,9 @@ static int iio_device_register_eventset(struct iio_dev *dev_info)
 			dev_info->event_interfaces[i].id = ret;
 
 		snprintf(dev_info->event_interfaces[i]._name, 20,
-			 "event_line%d",
-			dev_info->event_interfaces[i].id);
+			 "%s:event%d",
+			 dev_name(&dev_info->dev),
+			 dev_info->event_interfaces[i].id);
 
 		ret = iio_setup_ev_int(&dev_info->event_interfaces[i],
 				       (const char *)(dev_info
diff --git a/drivers/staging/iio/industrialio-ring.c b/drivers/staging/iio/industrialio-ring.c
index 81ea226..3bbd57d 100644
--- a/drivers/staging/iio/industrialio-ring.c
+++ b/drivers/staging/iio/industrialio-ring.c
@@ -163,8 +163,9 @@ __iio_request_ring_buffer_event_chrdev(struct iio_ring_buffer *buf,
 	else
 		buf->ev_int.id = ret;
 
-	snprintf(buf->ev_int._name, 20,
-		 "ring_event_line%d",
+	snprintf(buf->ev_int._name, sizeof(buf->ev_int._name),
+		 "%s:event%d",
+		 dev_name(&buf->dev),
 		 buf->ev_int.id);
 	ret = iio_setup_ev_int(&(buf->ev_int),
 			       buf->ev_int._name,
@@ -225,7 +226,9 @@ __iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf,
 		goto error_device_put;
 	else
 		buf->access_id = ret;
-	dev_set_name(&buf->access_dev, "ring_access%d", buf->access_id);
+	dev_set_name(&buf->access_dev, "%s:access%d",
+		     dev_name(&buf->dev),
+		     buf->access_id);
 	ret = device_add(&buf->access_dev);
 	if (ret < 0) {
 		printk(KERN_ERR "failed to add the ring access dev\n");
@@ -277,7 +280,9 @@ int iio_ring_buffer_register(struct iio_ring_buffer *ring)
 	else
 		ring->id = ret;
 
-	dev_set_name(&ring->dev, "ring_buffer%d", ring->id);
+	dev_set_name(&ring->dev, "%s:buffer%d",
+		     dev_name(ring->dev.parent),
+		     ring->id);
 	ret = device_add(&ring->dev);
 	if (ret)
 		goto error_free_id;
-- 
1.6.4.4

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

* [PATCH 12/13] staging:iio:tsl2563: change lux to illuminance0_input to match new abi
  2010-03-28 20:41                     ` [PATCH 11/13] staging:iio: Directory name changes to match new ABI Jonathan Cameron
@ 2010-03-28 20:41                       ` Jonathan Cameron
  2010-03-28 20:41                         ` [PATCH 13/13] staging:iio: Remove naming via IDR's where no longer necessary under " Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
This isn't technically part of the new abi as we didn't allow for
_input type values.  This syntax is lifted from hwmon to allow
for slow devices with complex conversion functions where it
actually makes sense to convert to standard units in kernel.

The other tsl2563 parameters still needs updating appropriately
but this requires some thought about the abi for light sensors

 drivers/staging/iio/light/tsl2563.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/staging/iio/light/tsl2563.c
index 78b9432..ca7364b 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/staging/iio/light/tsl2563.c
@@ -591,7 +591,7 @@ static ssize_t tsl2563_calib1_store(struct device *dev,
  * once I understand what they mean */
 static DEVICE_ATTR(adc0, S_IRUGO, tsl2563_adc0_show, NULL);
 static DEVICE_ATTR(adc1, S_IRUGO, tsl2563_adc1_show, NULL);
-static DEVICE_ATTR(lux, S_IRUGO, tsl2563_lux_show, NULL);
+static DEVICE_ATTR(illuminance0_input, S_IRUGO, tsl2563_lux_show, NULL);
 static DEVICE_ATTR(calib0, S_IRUGO | S_IWUSR,
 		   tsl2563_calib0_show, tsl2563_calib0_store);
 static DEVICE_ATTR(calib1, S_IRUGO | S_IWUSR,
@@ -600,7 +600,7 @@ static DEVICE_ATTR(calib1, S_IRUGO | S_IWUSR,
 static struct attribute *tsl2563_attributes[] = {
 	&dev_attr_adc0.attr,
 	&dev_attr_adc1.attr,
-	&dev_attr_lux.attr,
+	&dev_attr_illuminance0_input.attr,
 	&dev_attr_calib0.attr,
 	&dev_attr_calib1.attr,
 	NULL
-- 
1.6.4.4

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

* [PATCH 13/13] staging:iio: Remove naming via IDR's where no longer necessary under new abi.
  2010-03-28 20:41                       ` [PATCH 12/13] staging:iio:tsl2563: change lux to illuminance0_input to match new abi Jonathan Cameron
@ 2010-03-28 20:41                         ` Jonathan Cameron
  0 siblings, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-28 20:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/accel/lis3l02dq_ring.c |    2 +-
 drivers/staging/iio/accel/sca3000_core.c   |    2 +-
 drivers/staging/iio/adc/max1363_ring.c     |    2 +-
 drivers/staging/iio/industrialio-ring.c    |   48 +++++++---------------------
 drivers/staging/iio/ring_generic.h         |    2 +-
 5 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index bfd0cda..bc2a5ee 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -580,7 +580,7 @@ error_iio_sw_rb_free:
 
 int lis3l02dq_initialize_ring(struct iio_ring_buffer *ring)
 {
-	return iio_ring_buffer_register(ring);
+	return iio_ring_buffer_register(ring, 0);
 }
 
 void lis3l02dq_uninitialize_ring(struct iio_ring_buffer *ring)
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index f0f7e80..942e05e 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -1337,7 +1337,7 @@ static int __devinit __sca3000_probe(struct spi_device *spi,
 	if (ret < 0)
 		goto error_free_dev;
 	regdone = 1;
-	ret = iio_ring_buffer_register(st->indio_dev->ring);
+	ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
 	if (ret < 0)
 		goto error_unregister_dev;
 	if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index 0de3e87..f4414b0 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -254,5 +254,5 @@ void max1363_uninitialize_ring(struct iio_ring_buffer *ring)
 
 int max1363_initialize_ring(struct iio_ring_buffer *ring)
 {
-	return iio_ring_buffer_register(ring);
+	return iio_ring_buffer_register(ring, 0);
 };
diff --git a/drivers/staging/iio/industrialio-ring.c b/drivers/staging/iio/industrialio-ring.c
index 3bbd57d..a720126 100644
--- a/drivers/staging/iio/industrialio-ring.c
+++ b/drivers/staging/iio/industrialio-ring.c
@@ -20,18 +20,10 @@
 #include <linux/poll.h>
 #include <linux/module.h>
 #include <linux/cdev.h>
-#include <linux/idr.h>
 
 #include "iio.h"
 #include "ring_generic.h"
 
-/* IDR for ring buffer identifier */
-static DEFINE_IDR(iio_ring_idr);
-/* IDR for ring event identifier */
-static DEFINE_IDR(iio_ring_event_idr);
-/* IDR for ring access identifier */
-static DEFINE_IDR(iio_ring_access_idr);
-
 int iio_push_ring_event(struct iio_ring_buffer *ring_buf,
 		       int event_code,
 		       s64 timestamp)
@@ -157,11 +149,8 @@ __iio_request_ring_buffer_event_chrdev(struct iio_ring_buffer *buf,
 				       struct device *dev)
 {
 	int ret;
-	ret = iio_get_new_idr_val(&iio_ring_event_idr);
-	if (ret < 0)
-		goto error_ret;
-	else
-		buf->ev_int.id = ret;
+
+	buf->ev_int.id = id;
 
 	snprintf(buf->ev_int._name, sizeof(buf->ev_int._name),
 		 "%s:event%d",
@@ -172,11 +161,9 @@ __iio_request_ring_buffer_event_chrdev(struct iio_ring_buffer *buf,
 			       owner,
 			       dev);
 	if (ret)
-		goto error_free_id;
+		goto error_ret;
 	return 0;
 
-error_free_id:
-	iio_free_idr_val(&iio_ring_event_idr, buf->ev_int.id);
 error_ret:
 	return ret;
 }
@@ -185,7 +172,6 @@ static inline void
 __iio_free_ring_buffer_event_chrdev(struct iio_ring_buffer *buf)
 {
 	iio_free_ev_int(&(buf->ev_int));
-	iio_free_idr_val(&iio_ring_event_idr, buf->ev_int.id);
 }
 
 static void iio_ring_access_release(struct device *dev)
@@ -221,18 +207,16 @@ __iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf,
 	}
 	buf->access_dev.devt = MKDEV(MAJOR(iio_devt), minor);
 
-	ret = iio_get_new_idr_val(&iio_ring_access_idr);
-	if (ret < 0)
-		goto error_device_put;
-	else
-		buf->access_id = ret;
+
+	buf->access_id = id;
+
 	dev_set_name(&buf->access_dev, "%s:access%d",
 		     dev_name(&buf->dev),
 		     buf->access_id);
 	ret = device_add(&buf->access_dev);
 	if (ret < 0) {
 		printk(KERN_ERR "failed to add the ring access dev\n");
-		goto error_free_idr;
+		goto error_device_put;
 	}
 
 	cdev_init(&buf->access_handler.chrdev, &iio_ring_fileops);
@@ -244,10 +228,9 @@ __iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf,
 		goto error_device_unregister;
 	}
 	return 0;
+
 error_device_unregister:
 	device_unregister(&buf->access_dev);
-error_free_idr:
-	iio_free_idr_val(&iio_ring_access_idr, buf->access_id);
 error_device_put:
 	put_device(&buf->access_dev);
 
@@ -256,7 +239,6 @@ error_device_put:
 
 static void __iio_free_ring_buffer_access_chrdev(struct iio_ring_buffer *buf)
 {
-	iio_free_idr_val(&iio_ring_access_idr, buf->access_id);
 	device_unregister(&buf->access_dev);
 }
 
@@ -271,21 +253,18 @@ void iio_ring_buffer_init(struct iio_ring_buffer *ring,
 }
 EXPORT_SYMBOL(iio_ring_buffer_init);
 
-int iio_ring_buffer_register(struct iio_ring_buffer *ring)
+int iio_ring_buffer_register(struct iio_ring_buffer *ring, int id)
 {
 	int ret;
-	ret = iio_get_new_idr_val(&iio_ring_idr);
-	if (ret < 0)
-		goto error_ret;
-	else
-		ring->id = ret;
+
+	ring->id = id;
 
 	dev_set_name(&ring->dev, "%s:buffer%d",
 		     dev_name(ring->dev.parent),
 		     ring->id);
 	ret = device_add(&ring->dev);
 	if (ret)
-		goto error_free_id;
+		goto error_ret;
 
 	ret = __iio_request_ring_buffer_event_chrdev(ring,
 						     0,
@@ -306,8 +285,6 @@ error_free_ring_buffer_event_chrdev:
 	__iio_free_ring_buffer_event_chrdev(ring);
 error_remove_device:
 	device_del(&ring->dev);
-error_free_id:
-	iio_free_idr_val(&iio_ring_idr, ring->id);
 error_ret:
 	return ret;
 }
@@ -318,7 +295,6 @@ void iio_ring_buffer_unregister(struct iio_ring_buffer *ring)
 	__iio_free_ring_buffer_access_chrdev(ring);
 	__iio_free_ring_buffer_event_chrdev(ring);
 	device_del(&ring->dev);
-	iio_free_idr_val(&iio_ring_idr, ring->id);
 }
 EXPORT_SYMBOL(iio_ring_buffer_unregister);
 
diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
index c649b6d..ea5727a 100644
--- a/drivers/staging/iio/ring_generic.h
+++ b/drivers/staging/iio/ring_generic.h
@@ -261,7 +261,7 @@ static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring)
 	container_of(d, struct iio_ring_buffer, dev)
 #define access_dev_to_iio_ring_buffer(d)			\
 	container_of(d, struct iio_ring_buffer, access_dev)
-int iio_ring_buffer_register(struct iio_ring_buffer *ring);
+int iio_ring_buffer_register(struct iio_ring_buffer *ring, int id);
 void iio_ring_buffer_unregister(struct iio_ring_buffer *ring);
 
 ssize_t iio_read_ring_length(struct device *dev,
-- 
1.6.4.4

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

* Re: [PATCH 10/13] staging:iio: ABI documentation (partial)
  2010-03-28 20:41                   ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
  2010-03-28 20:41                     ` [PATCH 11/13] staging:iio: Directory name changes to match new ABI Jonathan Cameron
@ 2010-03-29 13:55                     ` Jonathan Cameron
  1 sibling, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-29 13:55 UTC (permalink / raw)
  To: linux-iio

In the great tradition of replying to ones own patches...
...
> +
> +What:		/sys/.../device[n]/device[n]:event[m]
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Configuration of which hardware generated events are passed up to
> +		userspace. Some of these are a bit complex to generalize so this
> +		section is a work in progress.
> +
> +What:		/sys/.../device[n]:event[m]/dev
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		major:minor character device numbers for the event line.
> +
> +Taking accel_x0 as an example
> +
> +What:		/sys/.../device[n]:event[m]/accel_x0_thresh[_high|_low]
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Event generated when accel_x0 passes a threshold in correction direction
> +		(or stays beyond one). If direction isn't specified, either triggers it.
> +		Note driver will assume last p events requested are enabled where p is
> +		however many it supports.  So if you want to be sure you have
> +		set what you think you have, check the contents of these. Drivers
> +		may have to buffer any parameters so that they are consistent when a
> +		given event type is enabled a future point (and not those for whatever
> +		alarm was previously enabled).
> +
> +What:		/sys/.../device[n]:event[m]/accel_x0_roc[_high|_low]
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Same as above but based on the first differential of the value.
> +
> +
> +What:		/sys/.../device[n]:event[m]/accel_x0[_thresh|_roc][_high|_low]_period
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		A period of time (microsecs) for which the condition must be broken
> +		before an interrupt is triggered. Applies to all alarms if type is not
> +		specified.
> +
> +What:		/sys/.../device[n]:event[m]/accel_x0[_thresh|_roc][_high|_low]_value
> +KernelVersion:	2.6.35
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		The actual value of the threshold in raw device units obtained by
> +		 reverse application of scale and offfset to the acceleration in m/s^2.
> +

These names don't actually conform to those I sent out out in the RFC following the the main
ABI posting and just for a complete inconsistency the naming in lis3l02dq doesn't conform
to either version.  I haven't yet checked the other drivers, but I would guess they are a random
mix of the various options as well.

Oops.

I'll fix this up for V2.

Jonathan

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

* Re: [PATCH 08/13] staging:iio:max1363 move to new abi.
  2010-03-28 20:41               ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
  2010-03-28 20:41                 ` [PATCH 09/13] staging:iio: Documentation, update iio_utils.h for the move to a bus Jonathan Cameron
@ 2010-03-30 14:31                 ` Jonathan Cameron
  1 sibling, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2010-03-30 14:31 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

...
> +static ssize_t max1363_read_single_channel(struct device *dev,
> +				   struct device_attribute *attr,
> +				   char *buf)
> +{
> +	struct iio_dev *dev_info = dev_get_drvdata(dev);
> +	struct max1363_state *st = iio_dev_get_devdata(dev_info);
> +	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> +	struct i2c_client *client = st->client;
> +	int ret = 0, len = 0;
> +	s32 data ;
> +	char rxbuf[2];
> +	long mask;
> +
> +	mutex_lock(&dev_info->mlock);
> +	/* If ring buffer capture is occuring, query the buffer */
> +	if (iio_ring_enabled(dev_info)) {
> +		mask = max1363_mode_table[this_attr->address].modemask;
> +		data = max1363_single_channel_from_ring(mask, st);
> +		if (data < 0) {
> +			ret = data;
> +			goto error_ret;
> +		}
> +	} else {
> +		/* Check to see if current scan mode is correct */
> +		if (st->current_mode !=
> +		    &max1363_mode_table[this_attr->address]) {
> +			/* Update scan mode if needed */
> +			st->current_mode
> +				= &max1363_mode_table[this_attr->address];
> +			ret = max1363_set_scan_mode(st);
> +			if (ret)
> +				goto error_ret;
> +		}
> +		/* Get reading */
> +		data = i2c_master_recv(client, rxbuf, 2);
> +		if (data < 0) {
> +			ret = data;
> +			goto error_ret;
> +		}
> +		data = rxbuf[1];

This is clearly wrong.  I'm only reading the lower 8 bits of the relevant channel.
Trivial fix, so I'll roll it into next version.  For reference that series will also have
patches add the remaining devices listed to be added to this driver on the iioutils wiki.


Jonathan

....

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

end of thread, other threads:[~2010-03-30 14:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-28 20:41 [PATCH 00/13] Staging: IIO: ABI changes round 1, V1 Jonathan Cameron
2010-03-28 20:41 ` [PATCH 01/13] staging:iio: Add new in_raw definitions for adc channels Jonathan Cameron
2010-03-28 20:41   ` [PATCH 02/13] staging:iio: Add new attrs for sampling frequency available and temp_raw Jonathan Cameron
2010-03-28 20:41     ` [PATCH 03/13] iio:staging:accelerometers move towards the new abi Jonathan Cameron
2010-03-28 20:41       ` [PATCH 04/13] staging:iio: Support functions for scan mask matching Jonathan Cameron
2010-03-28 20:41         ` [PATCH 05/13] staging: iio: Move from class to bus Jonathan Cameron
2010-03-28 20:41           ` [PATCH 06/13] staging:iio: Move event attributes into the event[n] device in sysfs Jonathan Cameron
2010-03-28 20:41             ` [PATCH 07/13] staging:iio: Clean out unused IIO_SCAN_EL and add IIO_SCAN_NAMED_EL_C Jonathan Cameron
2010-03-28 20:41               ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron
2010-03-28 20:41                 ` [PATCH 09/13] staging:iio: Documentation, update iio_utils.h for the move to a bus Jonathan Cameron
2010-03-28 20:41                   ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
2010-03-28 20:41                     ` [PATCH 11/13] staging:iio: Directory name changes to match new ABI Jonathan Cameron
2010-03-28 20:41                       ` [PATCH 12/13] staging:iio:tsl2563: change lux to illuminance0_input to match new abi Jonathan Cameron
2010-03-28 20:41                         ` [PATCH 13/13] staging:iio: Remove naming via IDR's where no longer necessary under " Jonathan Cameron
2010-03-29 13:55                     ` [PATCH 10/13] staging:iio: ABI documentation (partial) Jonathan Cameron
2010-03-30 14:31                 ` [PATCH 08/13] staging:iio:max1363 move to new abi Jonathan Cameron

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.