All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] staging:iio:accel rework driver and move out of staging.
@ 2016-10-03 19:26 Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
                   ` (17 more replies)
  0 siblings, 18 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

This was around about the 4th IIO driver dating back to the days when I was
sticking these on sprinters and seeing if we could learn anything useful
about how they ran.

It was a device way ahead of it's time.  Back then this was pretty much
the only relatively high G / low cost sensor and it had a hardware fifo.

Anyhow, it has languished in staging primarily because of the complexity
around working out how we handle hardware buffers.  However, that trail has
long since been blaized by the likes of the am335x driver and now lots of
of newer devices are coming with fifos to smooth the flow of data between
these realtime chips and non realtime operating sytems, so it just became
a question of getting around to sorting it out.  I suspect there are very
few of these still out there, but I have an sca3000-e05 so that's no excuse :)

Anyhow, please review the whole series, but in particular the final move
patch (i.e. the resulting code).  The only odd corner I know of now is
the interaction of the watermark with the software controlled watermarks.
That may take some thought, but in the meantime I don't think that is
sufficient reason to keep it in staging.

Some wacky corners in this hardware (like the crazy number representations
for the motion detection thresholds).  It's a good datasheet but you
do have to wonder what the designers were thinking at times ;)

Jonathan

p.s. The best bit about this series is now I can moan at everyone else
about not cleaning up their staging drivers as this is the last one
of mine ;)


Jonathan Cameron (18):
  staging:iio:accel:sca3000 Fix a use before setting of the
    indio_dev->buffer pointer.
  staging:iio:accel:sca3000 merge files into one.
  staging:iio:accel:sca3000 drop sca3000_register_ring_funcs
  staging:iio:accel:sca3000 Fix clearing of flag + setting of size of
    scan.
  staging:iio:accel:sca3000 Drop custom ABI for watersheds.
  staging:iio:accel:sca3000 move to hybrid hard / soft buffer design.
  staging:iio:accel:sca3000 drop some unused variables.
  staging:iio:accel:sca3000 use a 'fake' channel to handle freefall
    event registration.
  staging:iio:accel:sca3000 Clean up register defines.
  staging:iio:accel:sca3000 add readback of the 3db low pass filter
    frequency
  staging:iio:accel:sca3000: Fix off by one error in axis due to
    IIO_NO_MOD
  staging:iio:accel:sca3000 Add write support to the low pass filter
    control
  staging:iio:accel:sca3000 Drop custom measurement mode attributes
  staging:iio:accel:sca3000 replace non standard revision attr with
    dev_info on probe
  staging:iio:accel:sca3000 Tidy up probe order to avoid a race.
  staging:iio:accel:sca3000 small checkpatch fixes (alignment etc)
  staging:iio:accel:sca3000 kernel docify comments that were nearly
    kernel doc.
  staging:iio:accel:sca3000 Move out of staging.

 drivers/iio/accel/Kconfig                |   12 +
 drivers/iio/accel/Makefile               |    2 +
 drivers/iio/accel/sca3000.c              | 1588 ++++++++++++++++++++++++++++++
 drivers/staging/iio/accel/Kconfig        |   10 -
 drivers/staging/iio/accel/Makefile       |    2 -
 drivers/staging/iio/accel/sca3000.h      |  279 ------
 drivers/staging/iio/accel/sca3000_core.c | 1210 -----------------------
 drivers/staging/iio/accel/sca3000_ring.c |  350 -------
 drivers/staging/iio/ring_hw.h            |   27 -
 9 files changed, 1602 insertions(+), 1878 deletions(-)
 create mode 100644 drivers/iio/accel/sca3000.c
 delete mode 100644 drivers/staging/iio/accel/sca3000.h
 delete mode 100644 drivers/staging/iio/accel/sca3000_core.c
 delete mode 100644 drivers/staging/iio/accel/sca3000_ring.c
 delete mode 100644 drivers/staging/iio/ring_hw.h

-- 
2.10.0


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

* [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
index d1cb9b9cf22b..e5de52d05a5c 100644
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ b/drivers/staging/iio/accel/sca3000_ring.c
@@ -270,8 +270,8 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)
 		return -ENOMEM;
 	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
 
-	indio_dev->buffer->access = &sca3000_ring_access_funcs;
 
+	buffer->access = &sca3000_ring_access_funcs;
 	iio_device_attach_buffer(indio_dev, buffer);
 
 	return 0;
-- 
2.10.0


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

* [PATCH 02/18] staging:iio:accel:sca3000 merge files into one.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-04  8:46   ` Lars-Peter Clausen
  2016-10-03 19:26 ` [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs Jonathan Cameron
                   ` (15 subsequent siblings)
  17 siblings, 1 reply; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

In the early days of IIO we were much more inclined to keep the impact
of the core IIO elements to the minimum.  As time has moved on it has
become clear that hardly any builds are done without buffer support
and that it adds considerable complexity to the drivers.

Hence merge down the buffer and non buffer elements of the sca3000 driver
also allowing us to drop the header file used for the interfaces between
the two.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/Makefile                 |   3 +-
 .../iio/accel/{sca3000_core.c => sca3000.c}        | 498 ++++++++++++++++++++-
 drivers/staging/iio/accel/sca3000.h                | 279 ------------
 drivers/staging/iio/accel/sca3000_ring.c           | 350 ---------------
 4 files changed, 496 insertions(+), 634 deletions(-)

diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
index 1810a434a755..6ab95708e696 100644
--- a/drivers/staging/iio/accel/Makefile
+++ b/drivers/staging/iio/accel/Makefile
@@ -14,5 +14,4 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
 adis16240-y             := adis16240_core.o
 obj-$(CONFIG_ADIS16240) += adis16240.o
 
-sca3000-y		:= sca3000_core.o sca3000_ring.o
-obj-$(CONFIG_SCA3000)	+= sca3000.o
+obj-$(CONFIG_SCA3000)	:= sca3000.o
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000.c
similarity index 69%
rename from drivers/staging/iio/accel/sca3000_core.c
rename to drivers/staging/iio/accel/sca3000.c
index 564b36d4f648..62ab1aef2528 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -18,12 +18,189 @@
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
+#include <linux/uaccess.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/events.h>
 #include <linux/iio/buffer.h>
+#include "../ring_hw.h"
 
-#include "sca3000.h"
+#define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
+#define SCA3000_READ_REG(a) ((a) << 2)
+
+#define SCA3000_REG_ADDR_REVID			0x00
+#define SCA3000_REVID_MAJOR_MASK		0xf0
+#define SCA3000_REVID_MINOR_MASK		0x0f
+
+#define SCA3000_REG_ADDR_STATUS			0x02
+#define SCA3000_LOCKED				0x20
+#define SCA3000_EEPROM_CS_ERROR			0x02
+#define SCA3000_SPI_FRAME_ERROR			0x01
+
+/* All reads done using register decrement so no need to directly access LSBs */
+#define SCA3000_REG_ADDR_X_MSB			0x05
+#define SCA3000_REG_ADDR_Y_MSB			0x07
+#define SCA3000_REG_ADDR_Z_MSB			0x09
+
+#define SCA3000_REG_ADDR_RING_OUT		0x0f
+
+/* Temp read untested - the e05 doesn't have the sensor */
+#define SCA3000_REG_ADDR_TEMP_MSB		0x13
+
+#define SCA3000_REG_ADDR_MODE			0x14
+#define SCA3000_MODE_PROT_MASK			0x28
+
+#define SCA3000_RING_BUF_ENABLE			0x80
+#define SCA3000_RING_BUF_8BIT			0x40
+/*
+ * Free fall detection triggers an interrupt if the acceleration
+ * is below a threshold for equivalent of 25cm drop
+ */
+#define SCA3000_FREE_FALL_DETECT		0x10
+#define SCA3000_MEAS_MODE_NORMAL		0x00
+#define SCA3000_MEAS_MODE_OP_1			0x01
+#define SCA3000_MEAS_MODE_OP_2			0x02
+
+/*
+ * In motion detection mode the accelerations are band pass filtered
+ * (approx 1 - 25Hz) and then a programmable threshold used to trigger
+ * and interrupt.
+ */
+#define SCA3000_MEAS_MODE_MOT_DET		0x03
+
+#define SCA3000_REG_ADDR_BUF_COUNT		0x15
+
+#define SCA3000_REG_ADDR_INT_STATUS		0x16
+
+#define SCA3000_INT_STATUS_THREE_QUARTERS	0x80
+#define SCA3000_INT_STATUS_HALF			0x40
+
+#define SCA3000_INT_STATUS_FREE_FALL		0x08
+#define SCA3000_INT_STATUS_Y_TRIGGER		0x04
+#define SCA3000_INT_STATUS_X_TRIGGER		0x02
+#define SCA3000_INT_STATUS_Z_TRIGGER		0x01
+
+/* Used to allow access to multiplexed registers */
+#define SCA3000_REG_ADDR_CTRL_SEL		0x18
+/* Only available for SCA3000-D03 and SCA3000-D01 */
+#define SCA3000_REG_CTRL_SEL_I2C_DISABLE	0x01
+#define SCA3000_REG_CTRL_SEL_MD_CTRL		0x02
+#define SCA3000_REG_CTRL_SEL_MD_Y_TH		0x03
+#define SCA3000_REG_CTRL_SEL_MD_X_TH		0x04
+#define SCA3000_REG_CTRL_SEL_MD_Z_TH		0x05
+/*
+ * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device
+ * will not function
+ */
+#define SCA3000_REG_CTRL_SEL_OUT_CTRL		0x0B
+#define SCA3000_OUT_CTRL_PROT_MASK		0xE0
+#define SCA3000_OUT_CTRL_BUF_X_EN		0x10
+#define SCA3000_OUT_CTRL_BUF_Y_EN		0x08
+#define SCA3000_OUT_CTRL_BUF_Z_EN		0x04
+#define SCA3000_OUT_CTRL_BUF_DIV_MASK		0x03
+#define SCA3000_OUT_CTRL_BUF_DIV_4		0x02
+#define SCA3000_OUT_CTRL_BUF_DIV_2		0x01
+
+/*
+ * Control which motion detector interrupts are on.
+ * For now only OR combinations are supported.
+ */
+#define SCA3000_MD_CTRL_PROT_MASK		0xC0
+#define SCA3000_MD_CTRL_OR_Y			0x01
+#define SCA3000_MD_CTRL_OR_X			0x02
+#define SCA3000_MD_CTRL_OR_Z			0x04
+/* Currently unsupported */
+#define SCA3000_MD_CTRL_AND_Y			0x08
+#define SCA3000_MD_CTRL_AND_X			0x10
+#define SAC3000_MD_CTRL_AND_Z			0x20
+
+/*
+ * Some control registers of complex access methods requiring this register to
+ * be used to remove a lock.
+ */
+#define SCA3000_REG_ADDR_UNLOCK			0x1e
+
+#define SCA3000_REG_ADDR_INT_MASK		0x21
+#define SCA3000_INT_MASK_PROT_MASK		0x1C
+
+#define SCA3000_INT_MASK_RING_THREE_QUARTER	0x80
+#define SCA3000_INT_MASK_RING_HALF		0x40
+
+#define SCA3000_INT_MASK_ALL_INTS		0x02
+#define SCA3000_INT_MASK_ACTIVE_HIGH		0x01
+#define SCA3000_INT_MASK_ACTIVE_LOW		0x00
+
+/* Values of multiplexed registers (write to ctrl_data after select) */
+#define SCA3000_REG_ADDR_CTRL_DATA		0x22
+
+/*
+ * Measurement modes available on some sca3000 series chips. Code assumes others
+ * may become available in the future.
+ *
+ * Bypass - Bypass the low-pass filter in the signal channel so as to increase
+ *          signal bandwidth.
+ *
+ * Narrow - Narrow low-pass filtering of the signal channel and half output
+ *          data rate by decimation.
+ *
+ * Wide - Widen low-pass filtering of signal channel to increase bandwidth
+ */
+#define SCA3000_OP_MODE_BYPASS			0x01
+#define SCA3000_OP_MODE_NARROW			0x02
+#define SCA3000_OP_MODE_WIDE			0x04
+#define SCA3000_MAX_TX 6
+#define SCA3000_MAX_RX 2
+
+/**
+ * struct sca3000_state - device instance state information
+ * @us:			the associated spi device
+ * @info:			chip variant information
+ * @interrupt_handler_ws:	event interrupt handler for all events
+ * @last_timestamp:		the timestamp of the last event
+ * @mo_det_use_count:		reference counter for the motion detection unit
+ * @lock:			lock used to protect elements of sca3000_state
+ *				and the underlying device state.
+ * @bpse:			number of bits per scan element
+ * @tx:			dma-able transmit buffer
+ * @rx:			dma-able receive buffer
+ **/
+struct sca3000_state {
+	struct spi_device		*us;
+	const struct sca3000_chip_info	*info;
+	struct work_struct		interrupt_handler_ws;
+	s64				last_timestamp;
+	int				mo_det_use_count;
+	struct mutex			lock;
+	int				bpse;
+	/* Can these share a cacheline ? */
+	u8				rx[2] ____cacheline_aligned;
+	u8				tx[6] ____cacheline_aligned;
+};
+
+/**
+ * struct sca3000_chip_info - model dependent parameters
+ * @scale:			scale * 10^-6
+ * @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
+ * @option_mode_1_freq:		option mode 1 sampling frequency
+ * @option_mode_2:		second optional mode. Not all chips have one
+ * @option_mode_2_freq:		option mode 2 sampling frequency
+ *
+ * This structure is used to hold information about the functionality of a given
+ * sca3000 variant.
+ **/
+struct sca3000_chip_info {
+	unsigned int		scale;
+	bool			temp_output;
+	int			measurement_mode_freq;
+	int			option_mode_1;
+	int			option_mode_1_freq;
+	int			option_mode_2;
+	int			option_mode_2_freq;
+	int			mot_det_mult_xz[6];
+	int			mot_det_mult_y[7];
+};
 
 enum sca3000_variant {
 	d01,
@@ -80,14 +257,14 @@ static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
 	},
 };
 
-int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
+static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
 {
 	st->tx[0] = SCA3000_WRITE_REG(address);
 	st->tx[1] = val;
 	return spi_write(st->us, st->tx, 2);
 }
 
-int sca3000_read_data_short(struct sca3000_state *st,
+static int sca3000_read_data_short(struct sca3000_state *st,
 			    u8 reg_address_high,
 			    int len)
 {
@@ -759,6 +936,21 @@ static const struct attribute_group sca3000_attribute_group = {
 };
 
 /**
+ * sca3000_ring_int_process() ring specific interrupt handling.
+ *
+ * This is only split from the main interrupt handler so as to
+ * reduce the amount of code if the ring buffer is not enabled.
+ **/
+static void sca3000_ring_int_process(u8 val, struct iio_buffer *ring)
+{
+	if (val & (SCA3000_INT_STATUS_THREE_QUARTERS |
+		   SCA3000_INT_STATUS_HALF)) {
+		ring->stufftoread = true;
+		wake_up_interruptible(&ring->pollq);
+	}
+}
+
+/**
  * sca3000_event_handler() - handling ring and non ring events
  *
  * Ring related interrupt handler. Depending on event, push to
@@ -1017,6 +1209,306 @@ static struct attribute_group sca3000_event_attribute_group = {
 	.name = "events",
 };
 
+static int sca3000_read_data(struct sca3000_state *st,
+			     u8 reg_address_high,
+			     u8 **rx_p,
+			     int len)
+{
+	int ret;
+	struct spi_transfer xfer[2] = {
+		{
+			.len = 1,
+			.tx_buf = st->tx,
+		}, {
+			.len = len,
+		}
+	};
+	*rx_p = kmalloc(len, GFP_KERNEL);
+	if (!*rx_p) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+	xfer[1].rx_buf = *rx_p;
+	st->tx[0] = SCA3000_READ_REG(reg_address_high);
+	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
+	if (ret) {
+		dev_err(get_device(&st->us->dev), "problem reading register");
+		goto error_free_rx;
+	}
+
+	return 0;
+error_free_rx:
+	kfree(*rx_p);
+error_ret:
+	return ret;
+}
+
+/**
+ * sca3000_read_first_n_hw_rb() - main ring access, pulls data from ring
+ * @r:			the ring
+ * @count:		number of samples to try and pull
+ * @data:		output the actual samples pulled from the hw ring
+ *
+ * Currently does not provide timestamps.  As the hardware doesn't add them they
+ * can only be inferred approximately from ring buffer events such as 50% full
+ * and knowledge of when buffer was last emptied.  This is left to userspace.
+ **/
+static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
+				      size_t count, char __user *buf)
+{
+	struct iio_hw_buffer *hw_ring = iio_to_hw_buf(r);
+	struct iio_dev *indio_dev = hw_ring->private;
+	struct sca3000_state *st = iio_priv(indio_dev);
+	u8 *rx;
+	int ret, i, num_available, num_read = 0;
+	int bytes_per_sample = 1;
+
+	if (st->bpse == 11)
+		bytes_per_sample = 2;
+
+	mutex_lock(&st->lock);
+	if (count % bytes_per_sample) {
+		ret = -EINVAL;
+		goto error_ret;
+	}
+
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT, 1);
+	if (ret)
+		goto error_ret;
+	num_available = st->rx[0];
+	/*
+	 * num_available is the total number of samples available
+	 * i.e. number of time points * number of channels.
+	 */
+	if (count > num_available * bytes_per_sample)
+		num_read = num_available * bytes_per_sample;
+	else
+		num_read = count;
+
+	ret = sca3000_read_data(st,
+				SCA3000_REG_ADDR_RING_OUT,
+				&rx, num_read);
+	if (ret)
+		goto error_ret;
+
+	for (i = 0; i < num_read / sizeof(u16); i++)
+		*(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
+
+	if (copy_to_user(buf, rx, num_read))
+		ret = -EFAULT;
+	kfree(rx);
+	r->stufftoread = 0;
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret ? ret : num_read;
+}
+
+static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
+{
+	return r->stufftoread ? r->watermark : 0;
+}
+
+/**
+ * sca3000_query_ring_int() is the hardware ring status interrupt enabled
+ **/
+static ssize_t sca3000_query_ring_int(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int ret, val;
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+
+	mutex_lock(&st->lock);
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	val = st->rx[0];
+	mutex_unlock(&st->lock);
+	if (ret)
+		return ret;
+
+	return sprintf(buf, "%d\n", !!(val & this_attr->address));
+}
+
+/**
+ * sca3000_set_ring_int() set state of ring status interrupt
+ **/
+static ssize_t sca3000_set_ring_int(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf,
+				    size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	u8 val;
+	int ret;
+
+	mutex_lock(&st->lock);
+	ret = kstrtou8(buf, 10, &val);
+	if (ret)
+		goto error_ret;
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	if (ret)
+		goto error_ret;
+	if (val)
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_INT_MASK,
+					st->rx[0] | this_attr->address);
+	else
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_INT_MASK,
+					st->rx[0] & ~this_attr->address);
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret ? ret : len;
+}
+
+static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR,
+		       sca3000_query_ring_int,
+		       sca3000_set_ring_int,
+		       SCA3000_INT_MASK_RING_HALF);
+
+static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR,
+		       sca3000_query_ring_int,
+		       sca3000_set_ring_int,
+		       SCA3000_INT_MASK_RING_THREE_QUARTER);
+
+static ssize_t sca3000_show_buffer_scale(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+
+	return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
+}
+
+static IIO_DEVICE_ATTR(in_accel_scale,
+		       S_IRUGO,
+		       sca3000_show_buffer_scale,
+		       NULL,
+		       0);
+
+/*
+ * Ring buffer attributes
+ * This device is a bit unusual in that the sampling frequency and bpse
+ * only apply to the ring buffer.  At all times full rate and accuracy
+ * is available via direct reading from registers.
+ */
+static const struct attribute *sca3000_ring_attributes[] = {
+	&iio_dev_attr_50_percent.dev_attr.attr,
+	&iio_dev_attr_75_percent.dev_attr.attr,
+	&iio_dev_attr_in_accel_scale.dev_attr.attr,
+	NULL,
+};
+
+static struct iio_buffer *sca3000_rb_allocate(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buf;
+	struct iio_hw_buffer *ring;
+
+	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
+	if (!ring)
+		return NULL;
+
+	ring->private = indio_dev;
+	buf = &ring->buf;
+	buf->stufftoread = 0;
+	buf->length = 64;
+	buf->attrs = sca3000_ring_attributes;
+	iio_buffer_init(buf);
+
+	return buf;
+}
+
+static void sca3000_ring_release(struct iio_buffer *r)
+{
+	kfree(iio_to_hw_buf(r));
+}
+
+static const struct iio_buffer_access_funcs sca3000_ring_access_funcs = {
+	.read_first_n = &sca3000_read_first_n_hw_rb,
+	.data_available = sca3000_ring_buf_data_available,
+	.release = sca3000_ring_release,
+
+	.modes = INDIO_BUFFER_HARDWARE,
+};
+
+static int sca3000_configure_ring(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer;
+
+	buffer = sca3000_rb_allocate(indio_dev);
+	if (!buffer)
+		return -ENOMEM;
+	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
+
+	buffer->access = &sca3000_ring_access_funcs;
+	iio_device_attach_buffer(indio_dev, buffer);
+
+	return 0;
+}
+
+static void sca3000_unconfigure_ring(struct iio_dev *indio_dev)
+{
+	iio_buffer_put(indio_dev->buffer);
+}
+
+static inline
+int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
+{
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&st->lock);
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	if (ret)
+		goto error_ret;
+	if (state) {
+		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_MODE,
+					(st->rx[0] | SCA3000_RING_BUF_ENABLE));
+	} else
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_MODE,
+					(st->rx[0] & ~SCA3000_RING_BUF_ENABLE));
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret;
+}
+
+/**
+ * sca3000_hw_ring_preenable() hw ring buffer preenable function
+ *
+ * Very simple enable function as the chip will allows normal reads
+ * during ring buffer operation so as long as it is indeed running
+ * before we notify the core, the precise ordering does not matter.
+ **/
+static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
+{
+	return __sca3000_hw_ring_state_set(indio_dev, 1);
+}
+
+static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
+{
+	return __sca3000_hw_ring_state_set(indio_dev, 0);
+}
+
+static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
+	.preenable = &sca3000_hw_ring_preenable,
+	.postdisable = &sca3000_hw_ring_postdisable,
+};
+
+static void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
+{
+	indio_dev->setup_ops = &sca3000_ring_setup_ops;
+}
+
 /**
  * sca3000_clean_setup() get the device into a predictable state
  *
diff --git a/drivers/staging/iio/accel/sca3000.h b/drivers/staging/iio/accel/sca3000.h
deleted file mode 100644
index 4dcc8575cbe3..000000000000
--- a/drivers/staging/iio/accel/sca3000.h
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * sca3000.c -- support VTI sca3000 series accelerometers
- *              via SPI
- *
- * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org>
- *
- * Partly based upon tle62x0.c
- *
- * 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.
- *
- * Initial mode is direct measurement.
- *
- * Untested things
- *
- * Temperature reading (the e05 I'm testing with doesn't have a sensor)
- *
- * Free fall detection mode - supported but untested as I'm not droping my
- * dubious wire rig far enough to test it.
- *
- * Unsupported as yet
- *
- * Time stamping of data from ring. Various ideas on how to do this but none
- * are remotely simple. Suggestions welcome.
- *
- * Individual enabling disabling of channels going into ring buffer
- *
- * Overflow handling (this is signaled for all but 8 bit ring buffer mode.)
- *
- * Motion detector using AND combinations of signals.
- *
- * Note: Be very careful about not touching an register bytes marked
- * as reserved on the data sheet. They really mean it as changing convents of
- * some will cause the device to lock up.
- *
- * Known issues - on rare occasions the interrupts lock up. Not sure why as yet.
- * Can probably alleviate this by reading the interrupt register on start, but
- * that is really just brushing the problem under the carpet.
- */
-#ifndef _SCA3000
-#define _SCA3000
-
-#define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
-#define SCA3000_READ_REG(a) ((a) << 2)
-
-#define SCA3000_REG_ADDR_REVID			0x00
-#define SCA3000_REVID_MAJOR_MASK		0xf0
-#define SCA3000_REVID_MINOR_MASK		0x0f
-
-#define SCA3000_REG_ADDR_STATUS			0x02
-#define SCA3000_LOCKED				0x20
-#define SCA3000_EEPROM_CS_ERROR			0x02
-#define SCA3000_SPI_FRAME_ERROR			0x01
-
-/* All reads done using register decrement so no need to directly access LSBs */
-#define SCA3000_REG_ADDR_X_MSB			0x05
-#define SCA3000_REG_ADDR_Y_MSB			0x07
-#define SCA3000_REG_ADDR_Z_MSB			0x09
-
-#define SCA3000_REG_ADDR_RING_OUT		0x0f
-
-/* Temp read untested - the e05 doesn't have the sensor */
-#define SCA3000_REG_ADDR_TEMP_MSB		0x13
-
-#define SCA3000_REG_ADDR_MODE			0x14
-#define SCA3000_MODE_PROT_MASK			0x28
-
-#define SCA3000_RING_BUF_ENABLE			0x80
-#define SCA3000_RING_BUF_8BIT			0x40
-/*
- * Free fall detection triggers an interrupt if the acceleration
- * is below a threshold for equivalent of 25cm drop
- */
-#define SCA3000_FREE_FALL_DETECT		0x10
-#define SCA3000_MEAS_MODE_NORMAL		0x00
-#define SCA3000_MEAS_MODE_OP_1			0x01
-#define SCA3000_MEAS_MODE_OP_2			0x02
-
-/*
- * In motion detection mode the accelerations are band pass filtered
- * (approx 1 - 25Hz) and then a programmable threshold used to trigger
- * and interrupt.
- */
-#define SCA3000_MEAS_MODE_MOT_DET		0x03
-
-#define SCA3000_REG_ADDR_BUF_COUNT		0x15
-
-#define SCA3000_REG_ADDR_INT_STATUS		0x16
-
-#define SCA3000_INT_STATUS_THREE_QUARTERS	0x80
-#define SCA3000_INT_STATUS_HALF			0x40
-
-#define SCA3000_INT_STATUS_FREE_FALL		0x08
-#define SCA3000_INT_STATUS_Y_TRIGGER		0x04
-#define SCA3000_INT_STATUS_X_TRIGGER		0x02
-#define SCA3000_INT_STATUS_Z_TRIGGER		0x01
-
-/* Used to allow access to multiplexed registers */
-#define SCA3000_REG_ADDR_CTRL_SEL		0x18
-/* Only available for SCA3000-D03 and SCA3000-D01 */
-#define SCA3000_REG_CTRL_SEL_I2C_DISABLE	0x01
-#define SCA3000_REG_CTRL_SEL_MD_CTRL		0x02
-#define SCA3000_REG_CTRL_SEL_MD_Y_TH		0x03
-#define SCA3000_REG_CTRL_SEL_MD_X_TH		0x04
-#define SCA3000_REG_CTRL_SEL_MD_Z_TH		0x05
-/*
- * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device
- * will not function
- */
-#define SCA3000_REG_CTRL_SEL_OUT_CTRL		0x0B
-#define SCA3000_OUT_CTRL_PROT_MASK		0xE0
-#define SCA3000_OUT_CTRL_BUF_X_EN		0x10
-#define SCA3000_OUT_CTRL_BUF_Y_EN		0x08
-#define SCA3000_OUT_CTRL_BUF_Z_EN		0x04
-#define SCA3000_OUT_CTRL_BUF_DIV_MASK		0x03
-#define SCA3000_OUT_CTRL_BUF_DIV_4		0x02
-#define SCA3000_OUT_CTRL_BUF_DIV_2		0x01
-
-/*
- * Control which motion detector interrupts are on.
- * For now only OR combinations are supported.
- */
-#define SCA3000_MD_CTRL_PROT_MASK		0xC0
-#define SCA3000_MD_CTRL_OR_Y			0x01
-#define SCA3000_MD_CTRL_OR_X			0x02
-#define SCA3000_MD_CTRL_OR_Z			0x04
-/* Currently unsupported */
-#define SCA3000_MD_CTRL_AND_Y			0x08
-#define SCA3000_MD_CTRL_AND_X			0x10
-#define SAC3000_MD_CTRL_AND_Z			0x20
-
-/*
- * Some control registers of complex access methods requiring this register to
- * be used to remove a lock.
- */
-#define SCA3000_REG_ADDR_UNLOCK			0x1e
-
-#define SCA3000_REG_ADDR_INT_MASK		0x21
-#define SCA3000_INT_MASK_PROT_MASK		0x1C
-
-#define SCA3000_INT_MASK_RING_THREE_QUARTER	0x80
-#define SCA3000_INT_MASK_RING_HALF		0x40
-
-#define SCA3000_INT_MASK_ALL_INTS		0x02
-#define SCA3000_INT_MASK_ACTIVE_HIGH		0x01
-#define SCA3000_INT_MASK_ACTIVE_LOW		0x00
-
-/* Values of multiplexed registers (write to ctrl_data after select) */
-#define SCA3000_REG_ADDR_CTRL_DATA		0x22
-
-/*
- * Measurement modes available on some sca3000 series chips. Code assumes others
- * may become available in the future.
- *
- * Bypass - Bypass the low-pass filter in the signal channel so as to increase
- *          signal bandwidth.
- *
- * Narrow - Narrow low-pass filtering of the signal channel and half output
- *          data rate by decimation.
- *
- * Wide - Widen low-pass filtering of signal channel to increase bandwidth
- */
-#define SCA3000_OP_MODE_BYPASS			0x01
-#define SCA3000_OP_MODE_NARROW			0x02
-#define SCA3000_OP_MODE_WIDE			0x04
-#define SCA3000_MAX_TX 6
-#define SCA3000_MAX_RX 2
-
-/**
- * struct sca3000_state - device instance state information
- * @us:			the associated spi device
- * @info:			chip variant information
- * @interrupt_handler_ws:	event interrupt handler for all events
- * @last_timestamp:		the timestamp of the last event
- * @mo_det_use_count:		reference counter for the motion detection unit
- * @lock:			lock used to protect elements of sca3000_state
- *				and the underlying device state.
- * @bpse:			number of bits per scan element
- * @tx:			dma-able transmit buffer
- * @rx:			dma-able receive buffer
- **/
-struct sca3000_state {
-	struct spi_device		*us;
-	const struct sca3000_chip_info	*info;
-	struct work_struct		interrupt_handler_ws;
-	s64				last_timestamp;
-	int				mo_det_use_count;
-	struct mutex			lock;
-	int				bpse;
-	/* Can these share a cacheline ? */
-	u8				rx[2] ____cacheline_aligned;
-	u8				tx[6] ____cacheline_aligned;
-};
-
-/**
- * struct sca3000_chip_info - model dependent parameters
- * @scale:			scale * 10^-6
- * @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
- * @option_mode_1_freq:		option mode 1 sampling frequency
- * @option_mode_2:		second optional mode. Not all chips have one
- * @option_mode_2_freq:		option mode 2 sampling frequency
- *
- * This structure is used to hold information about the functionality of a given
- * sca3000 variant.
- **/
-struct sca3000_chip_info {
-	unsigned int		scale;
-	bool			temp_output;
-	int			measurement_mode_freq;
-	int			option_mode_1;
-	int			option_mode_1_freq;
-	int			option_mode_2;
-	int			option_mode_2_freq;
-	int			mot_det_mult_xz[6];
-	int			mot_det_mult_y[7];
-};
-
-int sca3000_read_data_short(struct sca3000_state *st,
-			    u8 reg_address_high,
-			    int len);
-
-/**
- * sca3000_write_reg() write a single register
- * @address:	address of register on chip
- * @val:	value to be written to register
- *
- * The main lock must be held.
- **/
-int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val);
-
-#ifdef CONFIG_IIO_BUFFER
-/**
- * sca3000_register_ring_funcs() setup the ring state change functions
- **/
-void sca3000_register_ring_funcs(struct iio_dev *indio_dev);
-
-/**
- * sca3000_configure_ring() - allocate and configure ring buffer
- * @indio_dev: iio-core device whose ring is to be configured
- *
- * The hardware ring buffer needs far fewer ring buffer functions than
- * a software one as a lot of things are handled automatically.
- * This function also tells the iio core that our device supports a
- * hardware ring buffer mode.
- **/
-int sca3000_configure_ring(struct iio_dev *indio_dev);
-
-/**
- * sca3000_unconfigure_ring() - deallocate the ring buffer
- * @indio_dev: iio-core device whose ring we are freeing
- **/
-void sca3000_unconfigure_ring(struct iio_dev *indio_dev);
-
-/**
- * sca3000_ring_int_process() handles ring related event pushing and escalation
- * @val:	the event code
- **/
-void sca3000_ring_int_process(u8 val, struct iio_buffer *ring);
-
-#else
-static inline void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
-{
-}
-
-static inline
-int sca3000_register_ring_access_and_init(struct iio_dev *indio_dev)
-{
-	return 0;
-}
-
-static inline void sca3000_ring_int_process(u8 val, void *ring)
-{
-}
-
-#endif
-#endif /* _SCA3000 */
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
deleted file mode 100644
index e5de52d05a5c..000000000000
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * sca3000_ring.c -- support VTI sca3000 series accelerometers via SPI
- *
- * 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.
- *
- * Copyright (c) 2009 Jonathan Cameron <jic23@kernel.org>
- *
- */
-
-#include <linux/interrupt.h>
-#include <linux/fs.h>
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/spi/spi.h>
-#include <linux/sysfs.h>
-#include <linux/sched.h>
-#include <linux/poll.h>
-
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/buffer.h>
-#include "../ring_hw.h"
-#include "sca3000.h"
-
-/* RFC / future work
- *
- * The internal ring buffer doesn't actually change what it holds depending
- * on which signals are enabled etc, merely whether you can read them.
- * As such the scan mode selection is somewhat different than for a software
- * ring buffer and changing it actually covers any data already in the buffer.
- * Currently scan elements aren't configured so it doesn't matter.
- */
-
-static int sca3000_read_data(struct sca3000_state *st,
-			     u8 reg_address_high,
-			     u8 **rx_p,
-			     int len)
-{
-	int ret;
-	struct spi_transfer xfer[2] = {
-		{
-			.len = 1,
-			.tx_buf = st->tx,
-		}, {
-			.len = len,
-		}
-	};
-	*rx_p = kmalloc(len, GFP_KERNEL);
-	if (!*rx_p) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	xfer[1].rx_buf = *rx_p;
-	st->tx[0] = SCA3000_READ_REG(reg_address_high);
-	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
-	if (ret) {
-		dev_err(get_device(&st->us->dev), "problem reading register");
-		goto error_free_rx;
-	}
-
-	return 0;
-error_free_rx:
-	kfree(*rx_p);
-error_ret:
-	return ret;
-}
-
-/**
- * sca3000_read_first_n_hw_rb() - main ring access, pulls data from ring
- * @r:			the ring
- * @count:		number of samples to try and pull
- * @data:		output the actual samples pulled from the hw ring
- *
- * Currently does not provide timestamps.  As the hardware doesn't add them they
- * can only be inferred approximately from ring buffer events such as 50% full
- * and knowledge of when buffer was last emptied.  This is left to userspace.
- **/
-static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
-				      size_t count, char __user *buf)
-{
-	struct iio_hw_buffer *hw_ring = iio_to_hw_buf(r);
-	struct iio_dev *indio_dev = hw_ring->private;
-	struct sca3000_state *st = iio_priv(indio_dev);
-	u8 *rx;
-	int ret, i, num_available, num_read = 0;
-	int bytes_per_sample = 1;
-
-	if (st->bpse == 11)
-		bytes_per_sample = 2;
-
-	mutex_lock(&st->lock);
-	if (count % bytes_per_sample) {
-		ret = -EINVAL;
-		goto error_ret;
-	}
-
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT, 1);
-	if (ret)
-		goto error_ret;
-	num_available = st->rx[0];
-	/*
-	 * num_available is the total number of samples available
-	 * i.e. number of time points * number of channels.
-	 */
-	if (count > num_available * bytes_per_sample)
-		num_read = num_available * bytes_per_sample;
-	else
-		num_read = count;
-
-	ret = sca3000_read_data(st,
-				SCA3000_REG_ADDR_RING_OUT,
-				&rx, num_read);
-	if (ret)
-		goto error_ret;
-
-	for (i = 0; i < num_read / sizeof(u16); i++)
-		*(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
-
-	if (copy_to_user(buf, rx, num_read))
-		ret = -EFAULT;
-	kfree(rx);
-	r->stufftoread = 0;
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : num_read;
-}
-
-static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
-{
-	return r->stufftoread ? r->watermark : 0;
-}
-
-/**
- * sca3000_query_ring_int() is the hardware ring status interrupt enabled
- **/
-static ssize_t sca3000_query_ring_int(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int ret, val;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	val = st->rx[0];
-	mutex_unlock(&st->lock);
-	if (ret)
-		return ret;
-
-	return sprintf(buf, "%d\n", !!(val & this_attr->address));
-}
-
-/**
- * sca3000_set_ring_int() set state of ring status interrupt
- **/
-static ssize_t sca3000_set_ring_int(struct device *dev,
-				    struct device_attribute *attr,
-				    const char *buf,
-				    size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u8 val;
-	int ret;
-
-	mutex_lock(&st->lock);
-	ret = kstrtou8(buf, 10, &val);
-	if (ret)
-		goto error_ret;
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	if (ret)
-		goto error_ret;
-	if (val)
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] | this_attr->address);
-	else
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] & ~this_attr->address);
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : len;
-}
-
-static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_HALF);
-
-static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_THREE_QUARTER);
-
-static ssize_t sca3000_show_buffer_scale(struct device *dev,
-					 struct device_attribute *attr,
-					 char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
-}
-
-static IIO_DEVICE_ATTR(in_accel_scale,
-		       S_IRUGO,
-		       sca3000_show_buffer_scale,
-		       NULL,
-		       0);
-
-/*
- * Ring buffer attributes
- * This device is a bit unusual in that the sampling frequency and bpse
- * only apply to the ring buffer.  At all times full rate and accuracy
- * is available via direct reading from registers.
- */
-static const struct attribute *sca3000_ring_attributes[] = {
-	&iio_dev_attr_50_percent.dev_attr.attr,
-	&iio_dev_attr_75_percent.dev_attr.attr,
-	&iio_dev_attr_in_accel_scale.dev_attr.attr,
-	NULL,
-};
-
-static struct iio_buffer *sca3000_rb_allocate(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buf;
-	struct iio_hw_buffer *ring;
-
-	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
-	if (!ring)
-		return NULL;
-
-	ring->private = indio_dev;
-	buf = &ring->buf;
-	buf->stufftoread = 0;
-	buf->length = 64;
-	buf->attrs = sca3000_ring_attributes;
-	iio_buffer_init(buf);
-
-	return buf;
-}
-
-static void sca3000_ring_release(struct iio_buffer *r)
-{
-	kfree(iio_to_hw_buf(r));
-}
-
-static const struct iio_buffer_access_funcs sca3000_ring_access_funcs = {
-	.read_first_n = &sca3000_read_first_n_hw_rb,
-	.data_available = sca3000_ring_buf_data_available,
-	.release = sca3000_ring_release,
-
-	.modes = INDIO_BUFFER_HARDWARE,
-};
-
-int sca3000_configure_ring(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buffer;
-
-	buffer = sca3000_rb_allocate(indio_dev);
-	if (!buffer)
-		return -ENOMEM;
-	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
-
-
-	buffer->access = &sca3000_ring_access_funcs;
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	return 0;
-}
-
-void sca3000_unconfigure_ring(struct iio_dev *indio_dev)
-{
-	iio_buffer_put(indio_dev->buffer);
-}
-
-static inline
-int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
-{
-	struct sca3000_state *st = iio_priv(indio_dev);
-	int ret;
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
-	if (ret)
-		goto error_ret;
-	if (state) {
-		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] | SCA3000_RING_BUF_ENABLE));
-	} else
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~SCA3000_RING_BUF_ENABLE));
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret;
-}
-
-/**
- * sca3000_hw_ring_preenable() hw ring buffer preenable function
- *
- * Very simple enable function as the chip will allows normal reads
- * during ring buffer operation so as long as it is indeed running
- * before we notify the core, the precise ordering does not matter.
- **/
-static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
-{
-	return __sca3000_hw_ring_state_set(indio_dev, 1);
-}
-
-static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
-{
-	return __sca3000_hw_ring_state_set(indio_dev, 0);
-}
-
-static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
-	.preenable = &sca3000_hw_ring_preenable,
-	.postdisable = &sca3000_hw_ring_postdisable,
-};
-
-void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
-{
-	indio_dev->setup_ops = &sca3000_ring_setup_ops;
-}
-
-/**
- * sca3000_ring_int_process() ring specific interrupt handling.
- *
- * This is only split from the main interrupt handler so as to
- * reduce the amount of code if the ring buffer is not enabled.
- **/
-void sca3000_ring_int_process(u8 val, struct iio_buffer *ring)
-{
-	if (val & (SCA3000_INT_STATUS_THREE_QUARTERS |
-		   SCA3000_INT_STATUS_HALF)) {
-		ring->stufftoread = true;
-		wake_up_interruptible(&ring->pollq);
-	}
-}
-- 
2.10.0


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

* [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

This was needed when the buffer support was optional. Pointless wrapper
now so drop it.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 62ab1aef2528..36a52d02ee0e 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -1504,11 +1504,6 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
 	.postdisable = &sca3000_hw_ring_postdisable,
 };
 
-static void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
-{
-	indio_dev->setup_ops = &sca3000_ring_setup_ops;
-}
-
 /**
  * sca3000_clean_setup() get the device into a predictable state
  *
@@ -1631,7 +1626,7 @@ static int sca3000_probe(struct spi_device *spi)
 		if (ret)
 			goto error_unregister_dev;
 	}
-	sca3000_register_ring_funcs(indio_dev);
+	indio_dev->setup_ops = &sca3000_ring_setup_ops;
 	ret = sca3000_clean_setup(st);
 	if (ret)
 		goto error_free_irq;
-- 
2.10.0


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

* [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (2 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-04  8:59   ` Lars-Peter Clausen
  2016-10-03 19:26 ` [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds Jonathan Cameron
                   ` (13 subsequent siblings)
  17 siblings, 1 reply; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Not clearing the stuff_to_read flag can lead to a false flag being set
on restarting the buffer if the data was not all read the previous time.

The size of the scan is needed to ensure the function
iio_buffer_read_first_n_outer actually tries to read the data.

This stuff has been broken for some time so not stable material.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 36a52d02ee0e..8af7d83e658d 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -1491,6 +1491,19 @@ error_ret:
  **/
 static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 {
+	/*
+	 * Set stuff to read to indicate no data present.
+	 * Need for cases where the interrupt had fired at the
+	 * end of a cycle, but the data was never read.
+	 */
+	indio_dev->buffer->stufftoread = 0;
+	/*
+	 * Needed to ensure the core will actually read data
+	 * from the device rather than assuming no channels
+	 * are enabled.
+	 */
+	indio_dev->buffer->bytes_per_datum = 6;
+
 	return __sca3000_hw_ring_state_set(indio_dev, 1);
 }
 
-- 
2.10.0


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

* [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (3 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design Jonathan Cameron
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

For now we support only the 50% watershed interrupt and start and stop it
as part of the buffer bring up.  The 75% case may come back in future.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 111 +++++++++++++-----------------------
 1 file changed, 41 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 8af7d83e658d..173e9a69d44f 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -1309,73 +1309,6 @@ static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
 	return r->stufftoread ? r->watermark : 0;
 }
 
-/**
- * sca3000_query_ring_int() is the hardware ring status interrupt enabled
- **/
-static ssize_t sca3000_query_ring_int(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int ret, val;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	val = st->rx[0];
-	mutex_unlock(&st->lock);
-	if (ret)
-		return ret;
-
-	return sprintf(buf, "%d\n", !!(val & this_attr->address));
-}
-
-/**
- * sca3000_set_ring_int() set state of ring status interrupt
- **/
-static ssize_t sca3000_set_ring_int(struct device *dev,
-				    struct device_attribute *attr,
-				    const char *buf,
-				    size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u8 val;
-	int ret;
-
-	mutex_lock(&st->lock);
-	ret = kstrtou8(buf, 10, &val);
-	if (ret)
-		goto error_ret;
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	if (ret)
-		goto error_ret;
-	if (val)
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] | this_attr->address);
-	else
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] & ~this_attr->address);
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : len;
-}
-
-static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_HALF);
-
-static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_THREE_QUARTER);
-
 static ssize_t sca3000_show_buffer_scale(struct device *dev,
 					 struct device_attribute *attr,
 					 char *buf)
@@ -1399,8 +1332,6 @@ static IIO_DEVICE_ATTR(in_accel_scale,
  * is available via direct reading from registers.
  */
 static const struct attribute *sca3000_ring_attributes[] = {
-	&iio_dev_attr_50_percent.dev_attr.attr,
-	&iio_dev_attr_75_percent.dev_attr.attr,
 	&iio_dev_attr_in_accel_scale.dev_attr.attr,
 	NULL,
 };
@@ -1491,6 +1422,9 @@ error_ret:
  **/
 static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 {
+	int ret;
+	struct sca3000_state *st = iio_priv(indio_dev);
+
 	/*
 	 * Set stuff to read to indicate no data present.
 	 * Need for cases where the interrupt had fired at the
@@ -1504,12 +1438,49 @@ static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 	 */
 	indio_dev->buffer->bytes_per_datum = 6;
 
+	mutex_lock(&st->lock);
+
+	/* Enable the 50% full interrupt */
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	if (ret)
+		goto error_unlock;
+	ret = sca3000_write_reg(st,
+				SCA3000_REG_ADDR_INT_MASK,
+				st->rx[0] | SCA3000_INT_MASK_RING_HALF);
+	if (ret)
+		goto error_unlock;
+
+	mutex_unlock(&st->lock);
+
 	return __sca3000_hw_ring_state_set(indio_dev, 1);
+
+error_unlock:
+	mutex_unlock(&st->lock);
+
+	return ret;
 }
 
 static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
 {
-	return __sca3000_hw_ring_state_set(indio_dev, 0);
+	int ret;
+	struct sca3000_state *st = iio_priv(indio_dev);
+
+	ret = __sca3000_hw_ring_state_set(indio_dev, 0);
+	if (ret)
+		return ret;
+
+	/* Disable the 50% full interrupt */
+	mutex_lock(&st->lock);
+
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	if (ret)
+		goto unlock;
+	ret = sca3000_write_reg(st,
+				SCA3000_REG_ADDR_INT_MASK,
+				st->rx[0] & ~SCA3000_INT_MASK_RING_HALF);
+unlock:
+	mutex_unlock(&st->lock);
+	return ret;
 }
 
 static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
-- 
2.10.0


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

* [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (4 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables Jonathan Cameron
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

In a similar fashion to other newer drivers (e.g. ti_am335x), instead
of using the hardware buffer support in IIO to directly access the hardware
fifo, insert a software fifo and feed that from the hardware one when
interrupts occur.  This gives a simpler structure to the data flows and
allows more flexibility over how often data is shipped to userspace etc.

This was also the only direct user of the simplistic generalization found
in ring_hw.h so that header is removed.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/Kconfig   |   3 +-
 drivers/staging/iio/accel/sca3000.c | 243 +++++++++++-------------------------
 drivers/staging/iio/ring_hw.h       |  27 ----
 3 files changed, 72 insertions(+), 201 deletions(-)

diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig
index 1c994b57c7d2..53389bfdd100 100644
--- a/drivers/staging/iio/accel/Kconfig
+++ b/drivers/staging/iio/accel/Kconfig
@@ -52,7 +52,8 @@ config ADIS16240
 	  called adis16240.
 
 config SCA3000
-	depends on IIO_BUFFER
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
 	depends on SPI
 	tristate "VTI SCA3000 series accelerometers"
 	help
diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 173e9a69d44f..57ae5584d146 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -23,7 +23,7 @@
 #include <linux/iio/sysfs.h>
 #include <linux/iio/events.h>
 #include <linux/iio/buffer.h>
-#include "../ring_hw.h"
+#include <linux/iio/kfifo_buf.h>
 
 #define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
 #define SCA3000_READ_REG(a) ((a) << 2)
@@ -173,7 +173,7 @@ struct sca3000_state {
 	struct mutex			lock;
 	int				bpse;
 	/* Can these share a cacheline ? */
-	u8				rx[2] ____cacheline_aligned;
+	u8				rx[384] ____cacheline_aligned;
 	u8				tx[6] ____cacheline_aligned;
 };
 
@@ -572,6 +572,10 @@ static const struct iio_event_spec sca3000_event = {
 	.mask_separate = BIT(IIO_EV_INFO_VALUE) | BIT(IIO_EV_INFO_ENABLE),
 };
 
+/*
+ * Note the hack in the number of bits to pretend we have 2 more than
+ * we do in the fifo.
+ */
 #define SCA3000_CHAN(index, mod)				\
 	{							\
 		.type = IIO_ACCEL,				\
@@ -584,9 +588,10 @@ static const struct iio_event_spec sca3000_event = {
 		.scan_index = index,				\
 		.scan_type = {					\
 			.sign = 's',				\
-			.realbits = 11,				\
+			.realbits = 13,				\
 			.storagebits = 16,			\
-			.shift = 5,				\
+			.shift = 3,				\
+			.endianness = IIO_BE,			\
 		},						\
 		.event_spec = &sca3000_event,			\
 		.num_event_specs = 1,				\
@@ -935,19 +940,71 @@ static const struct attribute_group sca3000_attribute_group = {
 	.attrs = sca3000_attributes,
 };
 
+static int sca3000_read_data(struct sca3000_state *st,
+			     u8 reg_address_high,
+			     u8 *rx,
+			     int len)
+{
+	int ret;
+	struct spi_transfer xfer[2] = {
+		{
+			.len = 1,
+			.tx_buf = st->tx,
+		}, {
+			.len = len,
+			.rx_buf = rx,
+		}
+	};
+
+	st->tx[0] = SCA3000_READ_REG(reg_address_high);
+	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
+	if (ret) {
+		dev_err(get_device(&st->us->dev), "problem reading register");
+		return ret;
+	}
+
+	return 0;
+}
+
 /**
  * sca3000_ring_int_process() ring specific interrupt handling.
  *
  * This is only split from the main interrupt handler so as to
  * reduce the amount of code if the ring buffer is not enabled.
  **/
-static void sca3000_ring_int_process(u8 val, struct iio_buffer *ring)
+static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 {
-	if (val & (SCA3000_INT_STATUS_THREE_QUARTERS |
-		   SCA3000_INT_STATUS_HALF)) {
-		ring->stufftoread = true;
-		wake_up_interruptible(&ring->pollq);
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int ret, i, num_available;
+
+	mutex_lock(&st->lock);
+	if (val & SCA3000_INT_STATUS_HALF) {
+		ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT,
+					      1);
+		if (ret)
+			goto error_ret;
+		num_available = st->rx[0];
+		/*
+		 * num_available is the total number of samples available
+		 * i.e. number of time points * number of channels.
+		 */
+		ret = sca3000_read_data(st, SCA3000_REG_ADDR_RING_OUT, st->rx,
+					num_available * 2);
+		if (ret)
+			goto error_ret;
+		for (i = 0; i < num_available / 3; i++) {
+			/*
+			 * Dirty hack to cover for 11 bit in fifo, 13 bit
+			 * direct reading.
+			 *
+			 * In theory the bottom two bits are undefined.
+			 * In reality they appear to always be 0.
+			 */
+			iio_push_to_buffers(indio_dev, st->rx + i * 3 * 2);
+		}
 	}
+error_ret:
+	mutex_unlock(&st->lock);
 }
 
 /**
@@ -978,7 +1035,7 @@ static irqreturn_t sca3000_event_handler(int irq, void *private)
 	if (ret)
 		goto done;
 
-	sca3000_ring_int_process(val, indio_dev->buffer);
+	sca3000_ring_int_process(val, indio_dev);
 
 	if (val & SCA3000_INT_STATUS_FREE_FALL)
 		iio_push_event(indio_dev,
@@ -1209,183 +1266,23 @@ static struct attribute_group sca3000_event_attribute_group = {
 	.name = "events",
 };
 
-static int sca3000_read_data(struct sca3000_state *st,
-			     u8 reg_address_high,
-			     u8 **rx_p,
-			     int len)
-{
-	int ret;
-	struct spi_transfer xfer[2] = {
-		{
-			.len = 1,
-			.tx_buf = st->tx,
-		}, {
-			.len = len,
-		}
-	};
-	*rx_p = kmalloc(len, GFP_KERNEL);
-	if (!*rx_p) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	xfer[1].rx_buf = *rx_p;
-	st->tx[0] = SCA3000_READ_REG(reg_address_high);
-	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
-	if (ret) {
-		dev_err(get_device(&st->us->dev), "problem reading register");
-		goto error_free_rx;
-	}
-
-	return 0;
-error_free_rx:
-	kfree(*rx_p);
-error_ret:
-	return ret;
-}
-
-/**
- * sca3000_read_first_n_hw_rb() - main ring access, pulls data from ring
- * @r:			the ring
- * @count:		number of samples to try and pull
- * @data:		output the actual samples pulled from the hw ring
- *
- * Currently does not provide timestamps.  As the hardware doesn't add them they
- * can only be inferred approximately from ring buffer events such as 50% full
- * and knowledge of when buffer was last emptied.  This is left to userspace.
- **/
-static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
-				      size_t count, char __user *buf)
-{
-	struct iio_hw_buffer *hw_ring = iio_to_hw_buf(r);
-	struct iio_dev *indio_dev = hw_ring->private;
-	struct sca3000_state *st = iio_priv(indio_dev);
-	u8 *rx;
-	int ret, i, num_available, num_read = 0;
-	int bytes_per_sample = 1;
-
-	if (st->bpse == 11)
-		bytes_per_sample = 2;
-
-	mutex_lock(&st->lock);
-	if (count % bytes_per_sample) {
-		ret = -EINVAL;
-		goto error_ret;
-	}
-
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT, 1);
-	if (ret)
-		goto error_ret;
-	num_available = st->rx[0];
-	/*
-	 * num_available is the total number of samples available
-	 * i.e. number of time points * number of channels.
-	 */
-	if (count > num_available * bytes_per_sample)
-		num_read = num_available * bytes_per_sample;
-	else
-		num_read = count;
-
-	ret = sca3000_read_data(st,
-				SCA3000_REG_ADDR_RING_OUT,
-				&rx, num_read);
-	if (ret)
-		goto error_ret;
-
-	for (i = 0; i < num_read / sizeof(u16); i++)
-		*(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
-
-	if (copy_to_user(buf, rx, num_read))
-		ret = -EFAULT;
-	kfree(rx);
-	r->stufftoread = 0;
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : num_read;
-}
-
-static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
-{
-	return r->stufftoread ? r->watermark : 0;
-}
-
-static ssize_t sca3000_show_buffer_scale(struct device *dev,
-					 struct device_attribute *attr,
-					 char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
-}
-
-static IIO_DEVICE_ATTR(in_accel_scale,
-		       S_IRUGO,
-		       sca3000_show_buffer_scale,
-		       NULL,
-		       0);
-
-/*
- * Ring buffer attributes
- * This device is a bit unusual in that the sampling frequency and bpse
- * only apply to the ring buffer.  At all times full rate and accuracy
- * is available via direct reading from registers.
- */
-static const struct attribute *sca3000_ring_attributes[] = {
-	&iio_dev_attr_in_accel_scale.dev_attr.attr,
-	NULL,
-};
-
-static struct iio_buffer *sca3000_rb_allocate(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buf;
-	struct iio_hw_buffer *ring;
-
-	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
-	if (!ring)
-		return NULL;
-
-	ring->private = indio_dev;
-	buf = &ring->buf;
-	buf->stufftoread = 0;
-	buf->length = 64;
-	buf->attrs = sca3000_ring_attributes;
-	iio_buffer_init(buf);
-
-	return buf;
-}
-
-static void sca3000_ring_release(struct iio_buffer *r)
-{
-	kfree(iio_to_hw_buf(r));
-}
-
-static const struct iio_buffer_access_funcs sca3000_ring_access_funcs = {
-	.read_first_n = &sca3000_read_first_n_hw_rb,
-	.data_available = sca3000_ring_buf_data_available,
-	.release = sca3000_ring_release,
-
-	.modes = INDIO_BUFFER_HARDWARE,
-};
-
 static int sca3000_configure_ring(struct iio_dev *indio_dev)
 {
 	struct iio_buffer *buffer;
 
-	buffer = sca3000_rb_allocate(indio_dev);
+	buffer = iio_kfifo_allocate();
 	if (!buffer)
 		return -ENOMEM;
-	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
 
-	buffer->access = &sca3000_ring_access_funcs;
 	iio_device_attach_buffer(indio_dev, buffer);
+	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
 
 	return 0;
 }
 
 static void sca3000_unconfigure_ring(struct iio_dev *indio_dev)
 {
-	iio_buffer_put(indio_dev->buffer);
+	iio_kfifo_free(indio_dev->buffer);
 }
 
 static inline
diff --git a/drivers/staging/iio/ring_hw.h b/drivers/staging/iio/ring_hw.h
deleted file mode 100644
index 75bf47bfee78..000000000000
--- a/drivers/staging/iio/ring_hw.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * ring_hw.h - common functionality for iio hardware ring buffers
- *
- * 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.
- *
- * Copyright (c) 2009 Jonathan Cameron <jic23@kernel.org>
- *
- */
-
-#ifndef _RING_HW_H_
-#define _RING_HW_H_
-
-/**
- * struct iio_hw_ring_buffer- hardware ring buffer
- * @buf:	generic ring buffer elements
- * @private:	device specific data
- */
-struct iio_hw_buffer {
-	struct iio_buffer buf;
-	void *private;
-};
-
-#define iio_to_hw_buf(r) container_of(r, struct iio_hw_buffer, buf)
-
-#endif /* _RING_HW_H_ */
-- 
2.10.0


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

* [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (5 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration Jonathan Cameron
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 57ae5584d146..39da74008786 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -155,23 +155,19 @@
  * struct sca3000_state - device instance state information
  * @us:			the associated spi device
  * @info:			chip variant information
- * @interrupt_handler_ws:	event interrupt handler for all events
  * @last_timestamp:		the timestamp of the last event
  * @mo_det_use_count:		reference counter for the motion detection unit
  * @lock:			lock used to protect elements of sca3000_state
  *				and the underlying device state.
- * @bpse:			number of bits per scan element
  * @tx:			dma-able transmit buffer
  * @rx:			dma-able receive buffer
  **/
 struct sca3000_state {
 	struct spi_device		*us;
 	const struct sca3000_chip_info	*info;
-	struct work_struct		interrupt_handler_ws;
 	s64				last_timestamp;
 	int				mo_det_use_count;
 	struct mutex			lock;
-	int				bpse;
 	/* Can these share a cacheline ? */
 	u8				rx[384] ____cacheline_aligned;
 	u8				tx[6] ____cacheline_aligned;
@@ -1443,7 +1439,6 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 		goto error_ret;
 	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
 				(st->rx[0] & SCA3000_MODE_PROT_MASK));
-	st->bpse = 11;
 
 error_ret:
 	mutex_unlock(&st->lock);
-- 
2.10.0


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

* [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (6 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines Jonathan Cameron
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

This is an approach used in some newer drivers as it exposes the
compound channel events to the core rather than hiding their control
in sysfs attributes entirely via the driver.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 302 ++++++++++++++++++------------------
 1 file changed, 154 insertions(+), 148 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 39da74008786..8337d5f05c20 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -593,10 +593,25 @@ static const struct iio_event_spec sca3000_event = {
 		.num_event_specs = 1,				\
 	}
 
+static const struct iio_event_spec sca3000_freefall_event_spec = {
+	.type = IIO_EV_TYPE_MAG,
+	.dir = IIO_EV_DIR_FALLING,
+	.mask_separate = BIT(IIO_EV_INFO_ENABLE) |
+		BIT(IIO_EV_INFO_PERIOD),
+};
+
 static const struct iio_chan_spec sca3000_channels[] = {
 	SCA3000_CHAN(0, IIO_MOD_X),
 	SCA3000_CHAN(1, IIO_MOD_Y),
 	SCA3000_CHAN(2, IIO_MOD_Z),
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_X_AND_Y_AND_Z,
+		.scan_index = -1, /* Fake channel */
+		.event_spec = &sca3000_freefall_event_spec,
+		.num_event_specs = 1,
+	},
 };
 
 static const struct iio_chan_spec sca3000_channels_with_temp[] = {
@@ -611,6 +626,14 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = {
 		/* No buffer support */
 		.scan_index = -1,
 	},
+	{
+		.type = IIO_ACCEL,
+		.modified = 1,
+		.channel2 = IIO_MOD_X_AND_Y_AND_Z,
+		.scan_index = -1, /* Fake channel */
+		.event_spec = &sca3000_freefall_event_spec,
+		.num_event_specs = 1,
+	},
 };
 
 static u8 sca3000_addresses[3][3] = {
@@ -854,46 +877,54 @@ error_ret:
 static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(sca3000_read_av_freq);
 
 /**
- * sca3000_read_thresh() - query of a threshold
+ * sca3000_read_event_value() - query of a threshold or period
  **/
-static int sca3000_read_thresh(struct iio_dev *indio_dev,
-			       const struct iio_chan_spec *chan,
-			       enum iio_event_type type,
-			       enum iio_event_direction dir,
-			       enum iio_event_info info,
-			       int *val, int *val2)
+static int sca3000_read_event_value(struct iio_dev *indio_dev,
+				    const struct iio_chan_spec *chan,
+				    enum iio_event_type type,
+				    enum iio_event_direction dir,
+				    enum iio_event_info info,
+				    int *val, int *val2)
 {
 	int ret, i;
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int num = chan->channel2;
+	switch (info) {
+	case IIO_EV_INFO_VALUE:
+		mutex_lock(&st->lock);
+		ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
+		mutex_unlock(&st->lock);
+		if (ret < 0)
+			return ret;
+		*val = 0;
+		if (num == 1)
+			for_each_set_bit(i, (unsigned long *)&ret,
+					 ARRAY_SIZE(st->info->mot_det_mult_y))
+				*val += st->info->mot_det_mult_y[i];
+		else
+			for_each_set_bit(i, (unsigned long *)&ret,
+					 ARRAY_SIZE(st->info->mot_det_mult_xz))
+				*val += st->info->mot_det_mult_xz[i];
 
-	mutex_lock(&st->lock);
-	ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
-	mutex_unlock(&st->lock);
-	if (ret < 0)
-		return ret;
-	*val = 0;
-	if (num == 1)
-		for_each_set_bit(i, (unsigned long *)&ret,
-				 ARRAY_SIZE(st->info->mot_det_mult_y))
-			*val += st->info->mot_det_mult_y[i];
-	else
-		for_each_set_bit(i, (unsigned long *)&ret,
-				 ARRAY_SIZE(st->info->mot_det_mult_xz))
-			*val += st->info->mot_det_mult_xz[i];
-
-	return IIO_VAL_INT;
+		return IIO_VAL_INT;
+	case IIO_EV_INFO_PERIOD:
+		*val = 0;
+		*val2 = 226000;
+		return IIO_VAL_INT_PLUS_MICRO;
+	default:
+		return -EINVAL;
+	}
 }
 
 /**
- * sca3000_write_thresh() control of threshold
+ * sca3000_write_value() control of threshold and period
  **/
-static int sca3000_write_thresh(struct iio_dev *indio_dev,
-				const struct iio_chan_spec *chan,
-				enum iio_event_type type,
-				enum iio_event_direction dir,
-				enum iio_event_info info,
-				int val, int val2)
+static int sca3000_write_event_value(struct iio_dev *indio_dev,
+				     const struct iio_chan_spec *chan,
+				     enum iio_event_type type,
+				     enum iio_event_direction dir,
+				     enum iio_event_info info,
+				     int val, int val2)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int num = chan->channel2;
@@ -901,7 +932,7 @@ static int sca3000_write_thresh(struct iio_dev *indio_dev,
 	int i;
 	u8 nonlinear = 0;
 
-	if (num == 1) {
+	if (num == IIO_MOD_Y) {
 		i = ARRAY_SIZE(st->info->mot_det_mult_y);
 		while (i > 0)
 			if (val >= st->info->mot_det_mult_y[--i]) {
@@ -1088,180 +1119,156 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 
 	/* read current value of mode register */
 	mutex_lock(&st->lock);
+
 	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
 	if (ret)
 		goto error_ret;
 
-	if ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET) {
-		ret = 0;
-	} else {
-		ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL);
-		if (ret < 0)
-			goto error_ret;
-		/* only supporting logical or's for now */
-		ret = !!(ret & sca3000_addresses[num][2]);
+	switch (chan->channel2) {
+	case IIO_MOD_X_AND_Y_AND_Z:
+		ret = !!(st->rx[0] & SCA3000_FREE_FALL_DETECT);
+		break;
+	case IIO_MOD_X:
+	case IIO_MOD_Y:
+	case IIO_MOD_Z:
+		/*
+		 * Motion detection mode cannot run at the same time as
+		 * acceleration data being read.
+		 */
+		if ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET) {
+			ret = 0;
+		} else {
+			ret = sca3000_read_ctrl_reg(st,
+						SCA3000_REG_CTRL_SEL_MD_CTRL);
+			if (ret < 0)
+				goto error_ret;
+			/* only supporting logical or's for now */
+			ret = !!(ret & sca3000_addresses[num][2]);
+		}
+		break;
+	default:
+		ret = -EINVAL;
 	}
+
 error_ret:
 	mutex_unlock(&st->lock);
 
 	return ret;
 }
 
-/**
- * sca3000_query_free_fall_mode() is free fall mode enabled
- **/
-static ssize_t sca3000_query_free_fall_mode(struct device *dev,
-					    struct device_attribute *attr,
-					    char *buf)
+static int sca3000_freefall_set_state(struct iio_dev *indio_dev, int state)
 {
-	int ret;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int val;
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
-	val = st->rx[0];
-	mutex_unlock(&st->lock);
-	if (ret < 0)
-		return ret;
-	return sprintf(buf, "%d\n", !!(val & SCA3000_FREE_FALL_DETECT));
-}
-
-/**
- * sca3000_set_free_fall_mode() simple on off control for free fall int
- *
- * In these chips the free fall detector should send an interrupt if
- * the device falls more than 25cm.  This has not been tested due
- * to fragile wiring.
- **/
-static ssize_t sca3000_set_free_fall_mode(struct device *dev,
-					  struct device_attribute *attr,
-					  const char *buf,
-					  size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	u8 val;
 	int ret;
-	u8 protect_mask = SCA3000_FREE_FALL_DETECT;
-
-	mutex_lock(&st->lock);
-	ret = kstrtou8(buf, 10, &val);
-	if (ret)
-		goto error_ret;
 
 	/* read current value of mode register */
 	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
 	if (ret)
-		goto error_ret;
+		return ret;
 
 	/* if off and should be on */
-	if (val && !(st->rx[0] & protect_mask))
-		ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					(st->rx[0] | SCA3000_FREE_FALL_DETECT));
+	if (state && !(st->rx[0] & SCA3000_FREE_FALL_DETECT))
+		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
+					 st->rx[0] | SCA3000_FREE_FALL_DETECT);
 	/* if on and should be off */
-	else if (!val && (st->rx[0] & protect_mask))
-		ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~protect_mask));
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : len;
+	else if (!state && (st->rx[0] & SCA3000_FREE_FALL_DETECT))
+		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
+					 st->rx[0] & ~SCA3000_FREE_FALL_DETECT);
+	else
+		return 0;
 }
 
-/**
- * sca3000_write_event_config() simple on off control for motion detector
- *
- * This is a per axis control, but enabling any will result in the
- * motion detector unit being enabled.
- * N.B. enabling motion detector stops normal data acquisition.
- * There is a complexity in knowing which mode to return to when
- * this mode is disabled.  Currently normal mode is assumed.
- **/
-static int sca3000_write_event_config(struct iio_dev *indio_dev,
-				      const struct iio_chan_spec *chan,
-				      enum iio_event_type type,
-				      enum iio_event_direction dir,
-				      int state)
+static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis,
+					   int state)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret, ctrlval;
-	u8 protect_mask = 0x03;
-	int num = chan->channel2;
 
-	mutex_lock(&st->lock);
 	/*
 	 * First read the motion detector config to find out if
 	 * this axis is on
 	 */
 	ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL);
 	if (ret < 0)
-		goto exit_point;
+		return ret;
 	ctrlval = ret;
 	/* if off and should be on */
-	if (state && !(ctrlval & sca3000_addresses[num][2])) {
+	if (state && !(ctrlval & sca3000_addresses[axis][2])) {
 		ret = sca3000_write_ctrl_reg(st,
 					     SCA3000_REG_CTRL_SEL_MD_CTRL,
 					     ctrlval |
-					     sca3000_addresses[num][2]);
+					     sca3000_addresses[axis][2]);
 		if (ret)
-			goto exit_point;
+			return ret;
 		st->mo_det_use_count++;
-	} else if (!state && (ctrlval & sca3000_addresses[num][2])) {
+	} else if (!state && (ctrlval & sca3000_addresses[axis][2])) {
 		ret = sca3000_write_ctrl_reg(st,
 					     SCA3000_REG_CTRL_SEL_MD_CTRL,
 					     ctrlval &
-					     ~(sca3000_addresses[num][2]));
+					     ~(sca3000_addresses[axis][2]));
 		if (ret)
-			goto exit_point;
+			return ret;
 		st->mo_det_use_count--;
 	}
 
 	/* read current value of mode register */
 	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
 	if (ret)
-		goto exit_point;
+		return ret;
 	/* if off and should be on */
 	if ((st->mo_det_use_count) &&
-	    ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET))
-		ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~protect_mask)
+	    ((st->rx[0] & SCA3000_MODE_MASK) != SCA3000_MEAS_MODE_MOT_DET))
+		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
+					(st->rx[0] & ~SCA3000_MODE_MASK)
 					| SCA3000_MEAS_MODE_MOT_DET);
 	/* if on and should be off */
 	else if (!(st->mo_det_use_count) &&
-		 ((st->rx[0] & protect_mask) == SCA3000_MEAS_MODE_MOT_DET))
-		ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~protect_mask));
-exit_point:
+		 ((st->rx[0] & SCA3000_MODE_MASK) == SCA3000_MEAS_MODE_MOT_DET))
+		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
+					st->rx[0] & SCA3000_MODE_MASK);
+	else
+		return 0;
+}
+
+/**
+ * sca3000_write_event_config() simple on off control for motion detector
+ *
+ * This is a per axis control, but enabling any will result in the
+ * motion detector unit being enabled.
+ * N.B. enabling motion detector stops normal data acquisition.
+ * There is a complexity in knowing which mode to return to when
+ * this mode is disabled.  Currently normal mode is assumed.
+ **/
+static int sca3000_write_event_config(struct iio_dev *indio_dev,
+				      const struct iio_chan_spec *chan,
+				      enum iio_event_type type,
+				      enum iio_event_direction dir,
+				      int state)
+{
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&st->lock);
+	switch (chan->channel2) {
+	case IIO_MOD_X_AND_Y_AND_Z:
+		ret = sca3000_freefall_set_state(indio_dev, state);
+		break;
+
+	case IIO_MOD_X:
+	case IIO_MOD_Y:
+	case IIO_MOD_Z:
+		ret = sca3000_motion_detect_set_state(indio_dev, chan->channel2,
+						      state);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
 	mutex_unlock(&st->lock);
 
 	return ret;
 }
 
-/* Free fall detector related event attribute */
-static IIO_DEVICE_ATTR_NAMED(accel_xayaz_mag_falling_en,
-			     in_accel_x & y & z_mag_falling_en,
-			     S_IRUGO | S_IWUSR,
-			     sca3000_query_free_fall_mode,
-			     sca3000_set_free_fall_mode,
-			     0);
-
-static IIO_CONST_ATTR_NAMED(accel_xayaz_mag_falling_period,
-			    in_accel_x & y & z_mag_falling_period,
-			    "0.226");
-
-static struct attribute *sca3000_event_attributes[] = {
-	&iio_dev_attr_accel_xayaz_mag_falling_en.dev_attr.attr,
-	&iio_const_attr_accel_xayaz_mag_falling_period.dev_attr.attr,
-	NULL,
-};
-
-static struct attribute_group sca3000_event_attribute_group = {
-	.attrs = sca3000_event_attributes,
-	.name = "events",
-};
-
 static int sca3000_configure_ring(struct iio_dev *indio_dev)
 {
 	struct iio_buffer *buffer;
@@ -1449,9 +1456,8 @@ static const struct iio_info sca3000_info = {
 	.attrs = &sca3000_attribute_group,
 	.read_raw = &sca3000_read_raw,
 	.write_raw = &sca3000_write_raw,
-	.event_attrs = &sca3000_event_attribute_group,
-	.read_event_value = &sca3000_read_thresh,
-	.write_event_value = &sca3000_write_thresh,
+	.read_event_value = &sca3000_read_event_value,
+	.write_event_value = &sca3000_write_event_value,
 	.read_event_config = &sca3000_read_event_config,
 	.write_event_config = &sca3000_write_event_config,
 	.driver_module = THIS_MODULE,
-- 
2.10.0


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

* [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (7 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency Jonathan Cameron
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Introduce some more masks and generally drive towards consistent naming.
Note the small indents used to indicate parts of registers + parts of
multiplexed registers.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 318 ++++++++++++++++++------------------
 1 file changed, 160 insertions(+), 158 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 8337d5f05c20..cd08330e79b8 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -28,110 +28,110 @@
 #define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
 #define SCA3000_READ_REG(a) ((a) << 2)
 
-#define SCA3000_REG_ADDR_REVID			0x00
-#define SCA3000_REVID_MAJOR_MASK		0xf0
-#define SCA3000_REVID_MINOR_MASK		0x0f
+#define SCA3000_REG_REVID_ADDR				0x00
+#define   SCA3000_REG_REVID_MAJOR_MASK			GENMASK(8, 4)
+#define   SCA3000_REG_REVID_MINOR_MASK			GENMASK(3, 0)
 
-#define SCA3000_REG_ADDR_STATUS			0x02
-#define SCA3000_LOCKED				0x20
-#define SCA3000_EEPROM_CS_ERROR			0x02
-#define SCA3000_SPI_FRAME_ERROR			0x01
+#define SCA3000_REG_STATUS_ADDR				0x02
+#define   SCA3000_LOCKED				BIT(5)
+#define   SCA3000_EEPROM_CS_ERROR			BIT(1)
+#define   SCA3000_SPI_FRAME_ERROR			BIT(0)
 
 /* All reads done using register decrement so no need to directly access LSBs */
-#define SCA3000_REG_ADDR_X_MSB			0x05
-#define SCA3000_REG_ADDR_Y_MSB			0x07
-#define SCA3000_REG_ADDR_Z_MSB			0x09
+#define SCA3000_REG_X_MSB_ADDR				0x05
+#define SCA3000_REG_Y_MSB_ADDR				0x07
+#define SCA3000_REG_Z_MSB_ADDR				0x09
 
-#define SCA3000_REG_ADDR_RING_OUT		0x0f
+#define SCA3000_REG_RING_OUT_ADDR			0x0f
 
 /* Temp read untested - the e05 doesn't have the sensor */
-#define SCA3000_REG_ADDR_TEMP_MSB		0x13
+#define SCA3000_REG_TEMP_MSB_ADDR			0x13
 
-#define SCA3000_REG_ADDR_MODE			0x14
-#define SCA3000_MODE_PROT_MASK			0x28
-
-#define SCA3000_RING_BUF_ENABLE			0x80
-#define SCA3000_RING_BUF_8BIT			0x40
+#define SCA3000_REG_MODE_ADDR				0x14
+#define SCA3000_MODE_PROT_MASK				0x28
+#define   SCA3000_REG_MODE_RING_BUF_ENABLE		BIT(7)
+#define   SCA3000_REG_MODE_RING_BUF_8BIT		BIT(6)
 /*
  * Free fall detection triggers an interrupt if the acceleration
  * is below a threshold for equivalent of 25cm drop
  */
-#define SCA3000_FREE_FALL_DETECT		0x10
-#define SCA3000_MEAS_MODE_NORMAL		0x00
-#define SCA3000_MEAS_MODE_OP_1			0x01
-#define SCA3000_MEAS_MODE_OP_2			0x02
+#define   SCA3000_REG_MODE_FREE_FALL_DETECT		BIT(4)
+#define   SCA3000_REG_MODE_MEAS_MODE_NORMAL		0x00
+#define   SCA3000_REG_MODE_MEAS_MODE_OP_1		0x01
+#define   SCA3000_REG_MODE_MEAS_MODE_OP_2		0x02
 
 /*
  * In motion detection mode the accelerations are band pass filtered
  * (approx 1 - 25Hz) and then a programmable threshold used to trigger
  * and interrupt.
  */
-#define SCA3000_MEAS_MODE_MOT_DET		0x03
-
-#define SCA3000_REG_ADDR_BUF_COUNT		0x15
+#define   SCA3000_REG_MODE_MEAS_MODE_MOT_DET		0x03
+#define   SCA3000_REG_MODE_MODE_MASK			0x03
 
-#define SCA3000_REG_ADDR_INT_STATUS		0x16
+#define SCA3000_REG_BUF_COUNT_ADDR			0x15
 
-#define SCA3000_INT_STATUS_THREE_QUARTERS	0x80
-#define SCA3000_INT_STATUS_HALF			0x40
+#define SCA3000_REG_INT_STATUS_ADDR			0x16
+#define   SCA3000_REG_INT_STATUS_THREE_QUARTERS		BIT(7)
+#define   SCA3000_REG_INT_STATUS_HALF			BIT(6)
 
-#define SCA3000_INT_STATUS_FREE_FALL		0x08
-#define SCA3000_INT_STATUS_Y_TRIGGER		0x04
-#define SCA3000_INT_STATUS_X_TRIGGER		0x02
-#define SCA3000_INT_STATUS_Z_TRIGGER		0x01
+#define SCA3000_INT_STATUS_FREE_FALL			BIT(3)
+#define SCA3000_INT_STATUS_Y_TRIGGER			BIT(2)
+#define SCA3000_INT_STATUS_X_TRIGGER			BIT(1)
+#define SCA3000_INT_STATUS_Z_TRIGGER			BIT(0)
 
 /* Used to allow access to multiplexed registers */
-#define SCA3000_REG_ADDR_CTRL_SEL		0x18
+#define SCA3000_REG_CTRL_SEL_ADDR			0x18
 /* Only available for SCA3000-D03 and SCA3000-D01 */
-#define SCA3000_REG_CTRL_SEL_I2C_DISABLE	0x01
-#define SCA3000_REG_CTRL_SEL_MD_CTRL		0x02
-#define SCA3000_REG_CTRL_SEL_MD_Y_TH		0x03
-#define SCA3000_REG_CTRL_SEL_MD_X_TH		0x04
-#define SCA3000_REG_CTRL_SEL_MD_Z_TH		0x05
+#define   SCA3000_REG_CTRL_SEL_I2C_DISABLE		0x01
+#define   SCA3000_REG_CTRL_SEL_MD_CTRL			0x02
+#define   SCA3000_REG_CTRL_SEL_MD_Y_TH			0x03
+#define   SCA3000_REG_CTRL_SEL_MD_X_TH			0x04
+#define   SCA3000_REG_CTRL_SEL_MD_Z_TH			0x05
 /*
  * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device
  * will not function
  */
-#define SCA3000_REG_CTRL_SEL_OUT_CTRL		0x0B
-#define SCA3000_OUT_CTRL_PROT_MASK		0xE0
-#define SCA3000_OUT_CTRL_BUF_X_EN		0x10
-#define SCA3000_OUT_CTRL_BUF_Y_EN		0x08
-#define SCA3000_OUT_CTRL_BUF_Z_EN		0x04
-#define SCA3000_OUT_CTRL_BUF_DIV_MASK		0x03
-#define SCA3000_OUT_CTRL_BUF_DIV_4		0x02
-#define SCA3000_OUT_CTRL_BUF_DIV_2		0x01
+#define   SCA3000_REG_CTRL_SEL_OUT_CTRL			0x0B
+
+#define     SCA3000_REG_OUT_CTRL_PROT_MASK		0xE0
+#define     SCA3000_REG_OUT_CTRL_BUF_X_EN		0x10
+#define     SCA3000_REG_OUT_CTRL_BUF_Y_EN		0x08
+#define     SCA3000_REG_OUT_CTRL_BUF_Z_EN		0x04
+#define     SCA3000_REG_OUT_CTRL_BUF_DIV_MASK		0x03
+#define     SCA3000_REG_OUT_CTRL_BUF_DIV_4		0x02
+#define     SCA3000_REG_OUT_CTRL_BUF_DIV_2		0x01
 
 /*
  * Control which motion detector interrupts are on.
  * For now only OR combinations are supported.
  */
-#define SCA3000_MD_CTRL_PROT_MASK		0xC0
-#define SCA3000_MD_CTRL_OR_Y			0x01
-#define SCA3000_MD_CTRL_OR_X			0x02
-#define SCA3000_MD_CTRL_OR_Z			0x04
+#define SCA3000_MD_CTRL_PROT_MASK			0xC0
+#define SCA3000_MD_CTRL_OR_Y				BIT(0)
+#define SCA3000_MD_CTRL_OR_X				BIT(1)
+#define SCA3000_MD_CTRL_OR_Z				BIT(2)
 /* Currently unsupported */
-#define SCA3000_MD_CTRL_AND_Y			0x08
-#define SCA3000_MD_CTRL_AND_X			0x10
-#define SAC3000_MD_CTRL_AND_Z			0x20
+#define SCA3000_MD_CTRL_AND_Y				BIT(3)
+#define SCA3000_MD_CTRL_AND_X				BIT(4)
+#define SAC3000_MD_CTRL_AND_Z				BIT(5)
 
 /*
  * Some control registers of complex access methods requiring this register to
  * be used to remove a lock.
  */
-#define SCA3000_REG_ADDR_UNLOCK			0x1e
+#define SCA3000_REG_UNLOCK_ADDR				0x1e
 
-#define SCA3000_REG_ADDR_INT_MASK		0x21
-#define SCA3000_INT_MASK_PROT_MASK		0x1C
+#define SCA3000_REG_INT_MASK_ADDR			0x21
+#define   SCA3000_REG_INT_MASK_PROT_MASK		0x1C
 
-#define SCA3000_INT_MASK_RING_THREE_QUARTER	0x80
-#define SCA3000_INT_MASK_RING_HALF		0x40
+#define   SCA3000_REG_INT_MASK_RING_THREE_QUARTER	BIT(7)
+#define   SCA3000_REG_INT_MASK_RING_HALF		BIT(6)
 
-#define SCA3000_INT_MASK_ALL_INTS		0x02
-#define SCA3000_INT_MASK_ACTIVE_HIGH		0x01
-#define SCA3000_INT_MASK_ACTIVE_LOW		0x00
+#define SCA3000_REG_INT_MASK_ALL_INTS			0x02
+#define SCA3000_REG_INT_MASK_ACTIVE_HIGH		0x01
+#define SCA3000_REG_INT_MASK_ACTIVE_LOW			0x00
 
 /* Values of multiplexed registers (write to ctrl_data after select) */
-#define SCA3000_REG_ADDR_CTRL_DATA		0x22
+#define SCA3000_REG_CTRL_DATA_ADDR			0x22
 
 /*
  * Measurement modes available on some sca3000 series chips. Code assumes others
@@ -145,9 +145,9 @@
  *
  * Wide - Widen low-pass filtering of signal channel to increase bandwidth
  */
-#define SCA3000_OP_MODE_BYPASS			0x01
-#define SCA3000_OP_MODE_NARROW			0x02
-#define SCA3000_OP_MODE_WIDE			0x04
+#define SCA3000_OP_MODE_BYPASS				0x01
+#define SCA3000_OP_MODE_NARROW				0x02
+#define SCA3000_OP_MODE_WIDE				0x04
 #define SCA3000_MAX_TX 6
 #define SCA3000_MAX_RX 2
 
@@ -287,7 +287,7 @@ static int sca3000_reg_lock_on(struct sca3000_state *st)
 {
 	int ret;
 
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_STATUS, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_STATUS_ADDR, 1);
 	if (ret < 0)
 		return ret;
 
@@ -317,11 +317,11 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
 			.tx_buf = st->tx + 4,
 		},
 	};
-	st->tx[0] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK);
+	st->tx[0] = SCA3000_WRITE_REG(SCA3000_REG_UNLOCK_ADDR);
 	st->tx[1] = 0x00;
-	st->tx[2] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK);
+	st->tx[2] = SCA3000_WRITE_REG(SCA3000_REG_UNLOCK_ADDR);
 	st->tx[3] = 0x50;
-	st->tx[4] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK);
+	st->tx[4] = SCA3000_WRITE_REG(SCA3000_REG_UNLOCK_ADDR);
 	st->tx[5] = 0xA0;
 
 	return spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
@@ -353,12 +353,12 @@ static int sca3000_write_ctrl_reg(struct sca3000_state *st,
 	}
 
 	/* Set the control select register */
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_CTRL_SEL, sel);
+	ret = sca3000_write_reg(st, SCA3000_REG_CTRL_SEL_ADDR, sel);
 	if (ret)
 		goto error_ret;
 
 	/* Write the actual value into the register */
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_CTRL_DATA, val);
+	ret = sca3000_write_reg(st, SCA3000_REG_CTRL_DATA_ADDR, val);
 
 error_ret:
 	return ret;
@@ -383,10 +383,10 @@ static int sca3000_read_ctrl_reg(struct sca3000_state *st,
 			goto error_ret;
 	}
 	/* Set the control select register */
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_CTRL_SEL, ctrl_reg);
+	ret = sca3000_write_reg(st, SCA3000_REG_CTRL_SEL_ADDR, ctrl_reg);
 	if (ret)
 		goto error_ret;
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_CTRL_DATA, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_CTRL_DATA_ADDR, 1);
 	if (ret)
 		goto error_ret;
 	return st->rx[0];
@@ -406,13 +406,13 @@ static ssize_t sca3000_show_rev(struct device *dev,
 	struct sca3000_state *st = iio_priv(indio_dev);
 
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_REVID, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_REVID_ADDR, 1);
 	if (ret < 0)
 		goto error_ret;
 	len += sprintf(buf + len,
-		       "major=%d, minor=%d\n",
-		       st->rx[0] & SCA3000_REVID_MAJOR_MASK,
-		       st->rx[0] & SCA3000_REVID_MINOR_MASK);
+		       "major=%lu, minor=%lu\n",
+		       st->rx[0] & SCA3000_REG_REVID_MAJOR_MASK,
+		       st->rx[0] & SCA3000_REG_REVID_MINOR_MASK);
 error_ret:
 	mutex_unlock(&st->lock);
 
@@ -467,19 +467,19 @@ sca3000_show_measurement_mode(struct device *dev,
 	int len = 0, ret;
 
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
 	/* mask bottom 2 bits - only ones that are relevant */
-	st->rx[0] &= 0x03;
+	st->rx[0] &= SCA3000_REG_MODE_MODE_MASK;
 	switch (st->rx[0]) {
-	case SCA3000_MEAS_MODE_NORMAL:
+	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
 		len += sprintf(buf + len, "0 - normal mode\n");
 		break;
-	case SCA3000_MEAS_MODE_MOT_DET:
+	case SCA3000_REG_MODE_MEAS_MODE_MOT_DET:
 		len += sprintf(buf + len, "3 - motion detection\n");
 		break;
-	case SCA3000_MEAS_MODE_OP_1:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
 		switch (st->info->option_mode_1) {
 		case SCA3000_OP_MODE_NARROW:
 			len += sprintf(buf + len, "1 - narrow mode\n");
@@ -489,7 +489,7 @@ sca3000_show_measurement_mode(struct device *dev,
 			break;
 		}
 		break;
-	case SCA3000_MEAS_MODE_OP_2:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
 		switch (st->info->option_mode_2) {
 		case SCA3000_OP_MODE_WIDE:
 			len += sprintf(buf + len, "2 - wide mode\n");
@@ -516,7 +516,6 @@ sca3000_store_measurement_mode(struct device *dev,
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
-	u8 mask = 0x03;
 	u8 val;
 
 	mutex_lock(&st->lock);
@@ -527,12 +526,12 @@ sca3000_store_measurement_mode(struct device *dev,
 		ret = -EINVAL;
 		goto error_ret;
 	}
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
-	st->rx[0] &= ~mask;
-	st->rx[0] |= (val & mask);
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE, st->rx[0]);
+	st->rx[0] &= ~SCA3000_REG_MODE_MODE_MASK;
+	st->rx[0] |= (val & SCA3000_REG_MODE_MODE_MASK);
+	ret = sca3000_write_reg(st, SCA3000_REG_MODE_ADDR, st->rx[0]);
 	if (ret)
 		goto error_ret;
 	mutex_unlock(&st->lock);
@@ -637,11 +636,11 @@ static const struct iio_chan_spec sca3000_channels_with_temp[] = {
 };
 
 static u8 sca3000_addresses[3][3] = {
-	[0] = {SCA3000_REG_ADDR_X_MSB, SCA3000_REG_CTRL_SEL_MD_X_TH,
+	[0] = {SCA3000_REG_X_MSB_ADDR, SCA3000_REG_CTRL_SEL_MD_X_TH,
 	       SCA3000_MD_CTRL_OR_X},
-	[1] = {SCA3000_REG_ADDR_Y_MSB, SCA3000_REG_CTRL_SEL_MD_Y_TH,
+	[1] = {SCA3000_REG_Y_MSB_ADDR, SCA3000_REG_CTRL_SEL_MD_Y_TH,
 	       SCA3000_MD_CTRL_OR_Y},
-	[2] = {SCA3000_REG_ADDR_Z_MSB, SCA3000_REG_CTRL_SEL_MD_Z_TH,
+	[2] = {SCA3000_REG_Z_MSB_ADDR, SCA3000_REG_CTRL_SEL_MD_Z_TH,
 	       SCA3000_MD_CTRL_OR_Z},
 };
 
@@ -656,17 +655,17 @@ static inline int __sca3000_get_base_freq(struct sca3000_state *st,
 {
 	int ret;
 
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
-	switch (0x03 & st->rx[0]) {
-	case SCA3000_MEAS_MODE_NORMAL:
+	switch (SCA3000_REG_MODE_MODE_MASK & st->rx[0]) {
+	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
 		*base_freq = info->measurement_mode_freq;
 		break;
-	case SCA3000_MEAS_MODE_OP_1:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
 		*base_freq = info->option_mode_1_freq;
 		break;
-	case SCA3000_MEAS_MODE_OP_2:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
 		*base_freq = info->option_mode_2_freq;
 		break;
 	default:
@@ -694,12 +693,12 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val)
 		return ret;
 
 	if (*val > 0) {
-		ret &= SCA3000_OUT_CTRL_BUF_DIV_MASK;
+		ret &= SCA3000_REG_OUT_CTRL_BUF_DIV_MASK;
 		switch (ret) {
-		case SCA3000_OUT_CTRL_BUF_DIV_2:
+		case SCA3000_REG_OUT_CTRL_BUF_DIV_2:
 			*val /= 2;
 			break;
-		case SCA3000_OUT_CTRL_BUF_DIV_4:
+		case SCA3000_REG_OUT_CTRL_BUF_DIV_4:
 			*val /= 4;
 			break;
 		}
@@ -725,12 +724,12 @@ static int write_raw_samp_freq(struct sca3000_state *st, int val)
 	if (ret < 0)
 		return ret;
 
-	ctrlval = ret & ~SCA3000_OUT_CTRL_BUF_DIV_MASK;
+	ctrlval = ret & ~SCA3000_REG_OUT_CTRL_BUF_DIV_MASK;
 
 	if (val == base_freq / 2)
-		ctrlval |= SCA3000_OUT_CTRL_BUF_DIV_2;
+		ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_2;
 	if (val == base_freq / 4)
-		ctrlval |= SCA3000_OUT_CTRL_BUF_DIV_4;
+		ctrlval |= SCA3000_REG_OUT_CTRL_BUF_DIV_4;
 	else if (val != base_freq)
 		return -EINVAL;
 
@@ -768,7 +767,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
 		} else {
 			/* get the temperature when available */
 			ret = sca3000_read_data_short(st,
-						      SCA3000_REG_ADDR_TEMP_MSB,
+						      SCA3000_REG_TEMP_MSB_ADDR,
 						      2);
 			if (ret < 0) {
 				mutex_unlock(&st->lock);
@@ -839,26 +838,26 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
 	int len = 0, ret, val;
 
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	val = st->rx[0];
 	mutex_unlock(&st->lock);
 	if (ret)
 		goto error_ret;
 
-	switch (val & 0x03) {
-	case SCA3000_MEAS_MODE_NORMAL:
+	switch (val & SCA3000_REG_MODE_MODE_MASK) {
+	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
 		len += sprintf(buf + len, "%d %d %d\n",
 			       st->info->measurement_mode_freq,
 			       st->info->measurement_mode_freq / 2,
 			       st->info->measurement_mode_freq / 4);
 		break;
-	case SCA3000_MEAS_MODE_OP_1:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
 		len += sprintf(buf + len, "%d %d %d\n",
 			       st->info->option_mode_1_freq,
 			       st->info->option_mode_1_freq / 2,
 			       st->info->option_mode_1_freq / 4);
 		break;
-	case SCA3000_MEAS_MODE_OP_2:
+	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
 		len += sprintf(buf + len, "%d %d %d\n",
 			       st->info->option_mode_2_freq,
 			       st->info->option_mode_2_freq / 2,
@@ -1005,8 +1004,9 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 	int ret, i, num_available;
 
 	mutex_lock(&st->lock);
-	if (val & SCA3000_INT_STATUS_HALF) {
-		ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT,
+
+	if (val & SCA3000_REG_INT_STATUS_HALF) {
+		ret = sca3000_read_data_short(st, SCA3000_REG_BUF_COUNT_ADDR,
 					      1);
 		if (ret)
 			goto error_ret;
@@ -1015,7 +1015,7 @@ static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 		 * num_available is the total number of samples available
 		 * i.e. number of time points * number of channels.
 		 */
-		ret = sca3000_read_data(st, SCA3000_REG_ADDR_RING_OUT, st->rx,
+		ret = sca3000_read_data(st, SCA3000_REG_RING_OUT_ADDR, st->rx,
 					num_available * 2);
 		if (ret)
 			goto error_ret;
@@ -1056,7 +1056,7 @@ static irqreturn_t sca3000_event_handler(int irq, void *private)
 	 * but ensures no interrupt is missed.
 	 */
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_STATUS, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_STATUS_ADDR, 1);
 	val = st->rx[0];
 	mutex_unlock(&st->lock);
 	if (ret)
@@ -1114,19 +1114,18 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
-	u8 protect_mask = 0x03;
 	int num = chan->channel2;
 
 	/* read current value of mode register */
 	mutex_lock(&st->lock);
 
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
 
 	switch (chan->channel2) {
 	case IIO_MOD_X_AND_Y_AND_Z:
-		ret = !!(st->rx[0] & SCA3000_FREE_FALL_DETECT);
+		ret = !!(st->rx[0] & SCA3000_REG_MODE_FREE_FALL_DETECT);
 		break;
 	case IIO_MOD_X:
 	case IIO_MOD_Y:
@@ -1135,7 +1134,8 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 		 * Motion detection mode cannot run at the same time as
 		 * acceleration data being read.
 		 */
-		if ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET) {
+		if ((st->rx[0] & SCA3000_REG_MODE_MODE_MASK)
+		    != SCA3000_REG_MODE_MEAS_MODE_MOT_DET) {
 			ret = 0;
 		} else {
 			ret = sca3000_read_ctrl_reg(st,
@@ -1162,18 +1162,18 @@ static int sca3000_freefall_set_state(struct iio_dev *indio_dev, int state)
 	int ret;
 
 	/* read current value of mode register */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		return ret;
 
 	/* if off and should be on */
-	if (state && !(st->rx[0] & SCA3000_FREE_FALL_DETECT))
-		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					 st->rx[0] | SCA3000_FREE_FALL_DETECT);
+	if (state && !(st->rx[0] & SCA3000_REG_MODE_FREE_FALL_DETECT))
+		return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
+					 st->rx[0] | SCA3000_REG_MODE_FREE_FALL_DETECT);
 	/* if on and should be off */
-	else if (!state && (st->rx[0] & SCA3000_FREE_FALL_DETECT))
-		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					 st->rx[0] & ~SCA3000_FREE_FALL_DETECT);
+	else if (!state && (st->rx[0] & SCA3000_REG_MODE_FREE_FALL_DETECT))
+		return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
+					 st->rx[0] & ~SCA3000_REG_MODE_FREE_FALL_DETECT);
 	else
 		return 0;
 }
@@ -1212,20 +1212,22 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis,
 	}
 
 	/* read current value of mode register */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		return ret;
 	/* if off and should be on */
 	if ((st->mo_det_use_count) &&
-	    ((st->rx[0] & SCA3000_MODE_MASK) != SCA3000_MEAS_MODE_MOT_DET))
-		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~SCA3000_MODE_MASK)
-					| SCA3000_MEAS_MODE_MOT_DET);
+	    ((st->rx[0] & SCA3000_REG_MODE_MODE_MASK)
+	     != SCA3000_REG_MODE_MEAS_MODE_MOT_DET))
+		return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
+			(st->rx[0] & ~SCA3000_REG_MODE_MODE_MASK)
+			| SCA3000_REG_MODE_MEAS_MODE_MOT_DET);
 	/* if on and should be off */
 	else if (!(st->mo_det_use_count) &&
-		 ((st->rx[0] & SCA3000_MODE_MASK) == SCA3000_MEAS_MODE_MOT_DET))
-		return sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
-					st->rx[0] & SCA3000_MODE_MASK);
+		 ((st->rx[0] & SCA3000_REG_MODE_MODE_MASK)
+		  == SCA3000_REG_MODE_MEAS_MODE_MOT_DET))
+		return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
+			st->rx[0] & SCA3000_REG_MODE_MODE_MASK);
 	else
 		return 0;
 }
@@ -1295,18 +1297,18 @@ int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
 	int ret;
 
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
 	if (state) {
 		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
 		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] | SCA3000_RING_BUF_ENABLE));
+			SCA3000_REG_MODE_ADDR,
+			(st->rx[0] | SCA3000_REG_MODE_RING_BUF_ENABLE));
 	} else
 		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~SCA3000_RING_BUF_ENABLE));
+			SCA3000_REG_MODE_ADDR,
+			(st->rx[0] & ~SCA3000_REG_MODE_RING_BUF_ENABLE));
 error_ret:
 	mutex_unlock(&st->lock);
 
@@ -1341,12 +1343,12 @@ static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 	mutex_lock(&st->lock);
 
 	/* Enable the 50% full interrupt */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
 		goto error_unlock;
 	ret = sca3000_write_reg(st,
-				SCA3000_REG_ADDR_INT_MASK,
-				st->rx[0] | SCA3000_INT_MASK_RING_HALF);
+				SCA3000_REG_INT_MASK_ADDR,
+				st->rx[0] | SCA3000_REG_INT_MASK_RING_HALF);
 	if (ret)
 		goto error_unlock;
 
@@ -1372,12 +1374,12 @@ static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
 	/* Disable the 50% full interrupt */
 	mutex_lock(&st->lock);
 
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
 		goto unlock;
 	ret = sca3000_write_reg(st,
-				SCA3000_REG_ADDR_INT_MASK,
-				st->rx[0] & ~SCA3000_INT_MASK_RING_HALF);
+				SCA3000_REG_INT_MASK_ADDR,
+				st->rx[0] & ~SCA3000_REG_INT_MASK_RING_HALF);
 unlock:
 	mutex_unlock(&st->lock);
 	return ret;
@@ -1401,7 +1403,7 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 
 	mutex_lock(&st->lock);
 	/* Ensure all interrupts have been acknowledged */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_STATUS, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_STATUS_ADDR, 1);
 	if (ret)
 		goto error_ret;
 
@@ -1419,21 +1421,21 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 	if (ret < 0)
 		goto error_ret;
 	ret = sca3000_write_ctrl_reg(st, SCA3000_REG_CTRL_SEL_OUT_CTRL,
-				     (ret & SCA3000_OUT_CTRL_PROT_MASK)
-				     | SCA3000_OUT_CTRL_BUF_X_EN
-				     | SCA3000_OUT_CTRL_BUF_Y_EN
-				     | SCA3000_OUT_CTRL_BUF_Z_EN
-				     | SCA3000_OUT_CTRL_BUF_DIV_4);
+				     (ret & SCA3000_REG_OUT_CTRL_PROT_MASK)
+				     | SCA3000_REG_OUT_CTRL_BUF_X_EN
+				     | SCA3000_REG_OUT_CTRL_BUF_Y_EN
+				     | SCA3000_REG_OUT_CTRL_BUF_Z_EN
+				     | SCA3000_REG_OUT_CTRL_BUF_DIV_4);
 	if (ret)
 		goto error_ret;
 	/* Enable interrupts, relevant to mode and set up as active low */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
 		goto error_ret;
 	ret = sca3000_write_reg(st,
-				SCA3000_REG_ADDR_INT_MASK,
-				(ret & SCA3000_INT_MASK_PROT_MASK)
-				| SCA3000_INT_MASK_ACTIVE_LOW);
+				SCA3000_REG_INT_MASK_ADDR,
+				(ret & SCA3000_REG_INT_MASK_PROT_MASK)
+				| SCA3000_REG_INT_MASK_ACTIVE_LOW);
 	if (ret)
 		goto error_ret;
 	/*
@@ -1441,10 +1443,10 @@ static int sca3000_clean_setup(struct sca3000_state *st)
 	 * Ring in 12 bit mode - it is fine to overwrite reserved bits 3,5
 	 * as that occurs in one of the example on the datasheet
 	 */
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
 	if (ret)
 		goto error_ret;
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
+	ret = sca3000_write_reg(st, SCA3000_REG_MODE_ADDR,
 				(st->rx[0] & SCA3000_MODE_PROT_MASK));
 
 error_ret:
@@ -1527,14 +1529,14 @@ static int sca3000_stop_all_interrupts(struct sca3000_state *st)
 	int ret;
 
 	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	ret = sca3000_read_data_short(st, SCA3000_REG_INT_MASK_ADDR, 1);
 	if (ret)
 		goto error_ret;
-	ret = sca3000_write_reg(st, SCA3000_REG_ADDR_INT_MASK,
+	ret = sca3000_write_reg(st, SCA3000_REG_INT_MASK_ADDR,
 				(st->rx[0] &
-				 ~(SCA3000_INT_MASK_RING_THREE_QUARTER |
-				   SCA3000_INT_MASK_RING_HALF |
-				   SCA3000_INT_MASK_ALL_INTS)));
+				 ~(SCA3000_REG_INT_MASK_RING_THREE_QUARTER |
+				   SCA3000_REG_INT_MASK_RING_HALF |
+				   SCA3000_REG_INT_MASK_ALL_INTS)));
 error_ret:
 	mutex_unlock(&st->lock);
 	return ret;
-- 
2.10.0


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

* [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (8 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Jonathan Cameron
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Driving towards getting rid of the non standard mode control interface.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 48 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index cd08330e79b8..24685a2f224e 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -190,10 +190,13 @@ struct sca3000_chip_info {
 	unsigned int		scale;
 	bool			temp_output;
 	int			measurement_mode_freq;
+	int			measurement_mode_3db_freq;
 	int			option_mode_1;
 	int			option_mode_1_freq;
+	int			option_mode_1_3db_freq;
 	int			option_mode_2;
 	int			option_mode_2_freq;
+	int			option_mode_2_3db_freq;
 	int			mot_det_mult_xz[6];
 	int			mot_det_mult_y[7];
 };
@@ -218,36 +221,46 @@ static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
 		.scale = 7357,
 		.temp_output = true,
 		.measurement_mode_freq = 250,
+		.measurement_mode_3db_freq = 45,
 		.option_mode_1 = SCA3000_OP_MODE_BYPASS,
 		.option_mode_1_freq = 250,
+		.option_mode_1_3db_freq = 70,
 		.mot_det_mult_xz = {50, 100, 200, 350, 650, 1300},
 		.mot_det_mult_y = {50, 100, 150, 250, 450, 850, 1750},
 	},
 	[e02] = {
 		.scale = 9810,
 		.measurement_mode_freq = 125,
+		.measurement_mode_3db_freq = 40,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 63,
+		.option_mode_1_3db_freq = 11,
 		.mot_det_mult_xz = {100, 150, 300, 550, 1050, 2050},
 		.mot_det_mult_y = {50, 100, 200, 350, 700, 1350, 2700},
 	},
 	[e04] = {
 		.scale = 19620,
 		.measurement_mode_freq = 100,
+		.measurement_mode_3db_freq = 38,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 50,
+		.option_mode_1_3db_freq = 9,
 		.option_mode_2 = SCA3000_OP_MODE_WIDE,
 		.option_mode_2_freq = 400,
+		.option_mode_2_3db_freq = 70,
 		.mot_det_mult_xz = {200, 300, 600, 1100, 2100, 4100},
 		.mot_det_mult_y = {100, 200, 400, 7000, 1400, 2700, 54000},
 	},
 	[e05] = {
 		.scale = 61313,
 		.measurement_mode_freq = 200,
+		.measurement_mode_3db_freq = 60,
 		.option_mode_1 = SCA3000_OP_MODE_NARROW,
 		.option_mode_1_freq = 50,
+		.option_mode_1_3db_freq = 9,
 		.option_mode_2 = SCA3000_OP_MODE_WIDE,
 		.option_mode_2_freq = 400,
+		.option_mode_2_3db_freq = 75,
 		.mot_det_mult_xz = {600, 900, 1700, 3200, 6100, 11900},
 		.mot_det_mult_y = {300, 600, 1200, 2000, 4100, 7800, 15600},
 	},
@@ -577,7 +590,8 @@ static const struct iio_event_spec sca3000_event = {
 		.modified = 1,					\
 		.channel2 = mod,				\
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
-		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |\
+			BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),\
 		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
 		.address = index,				\
 		.scan_index = index,				\
@@ -737,6 +751,33 @@ static int write_raw_samp_freq(struct sca3000_state *st, int val)
 				     ctrlval);
 }
 
+static int sca3000_read_3db_freq(struct sca3000_state *st, int *val)
+{
+	int ret;
+
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
+	if (ret)
+		return ret;
+
+	/* mask bottom 2 bits - only ones that are relevant */
+	st->rx[0] &= SCA3000_REG_MODE_MODE_MASK;
+	switch (st->rx[0]) {
+	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
+		*val = st->info->measurement_mode_3db_freq;
+		return IIO_VAL_INT;
+	case SCA3000_REG_MODE_MEAS_MODE_MOT_DET:
+		return -EBUSY;
+	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
+		*val = st->info->option_mode_1_3db_freq;
+		return IIO_VAL_INT;
+	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
+		*val = st->info->option_mode_2_3db_freq;
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int sca3000_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val,
@@ -794,6 +835,11 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
 		ret = read_raw_samp_freq(st, val);
 		mutex_unlock(&st->lock);
 		return ret ? ret : IIO_VAL_INT;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		mutex_lock(&st->lock);
+		ret = sca3000_read_3db_freq(st, val);
+		mutex_unlock(&st->lock);
+		return ret;
 	default:
 		return -EINVAL;
 	}
-- 
2.10.0


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

* [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (9 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-04  8:52   ` Lars-Peter Clausen
  2016-10-03 19:26 ` [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control Jonathan Cameron
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Given the introduction of IIO_NO_MOD was prior to the first submission
prior to IIO entering staging this has been broken for a while.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 24685a2f224e..e8f43df65142 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -933,16 +933,17 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
 {
 	int ret, i;
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = chan->channel2;
+
 	switch (info) {
 	case IIO_EV_INFO_VALUE:
 		mutex_lock(&st->lock);
-		ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
+		ret = sca3000_read_ctrl_reg(st,
+					    sca3000_addresses[chan->channel2 - IIO_MOD_X][1]);
 		mutex_unlock(&st->lock);
 		if (ret < 0)
 			return ret;
 		*val = 0;
-		if (num == 1)
+		if (chan->channel2 == IIO_MOD_Y)
 			for_each_set_bit(i, (unsigned long *)&ret,
 					 ARRAY_SIZE(st->info->mot_det_mult_y))
 				*val += st->info->mot_det_mult_y[i];
@@ -972,12 +973,11 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 				     int val, int val2)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
-	int num = chan->channel2;
 	int ret;
 	int i;
 	u8 nonlinear = 0;
 
-	if (num == IIO_MOD_Y) {
+	if (chan->channel2 == IIO_MOD_Y) {
 		i = ARRAY_SIZE(st->info->mot_det_mult_y);
 		while (i > 0)
 			if (val >= st->info->mot_det_mult_y[--i]) {
@@ -994,7 +994,9 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 	}
 
 	mutex_lock(&st->lock);
-	ret = sca3000_write_ctrl_reg(st, sca3000_addresses[num][1], nonlinear);
+	ret = sca3000_write_ctrl_reg(st,
+				     sca3000_addresses[chan->channel2 - IIO_MOD_X][1],
+				     nonlinear);
 	mutex_unlock(&st->lock);
 
 	return ret;
@@ -1160,8 +1162,6 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
 	int ret;
-	int num = chan->channel2;
-
 	/* read current value of mode register */
 	mutex_lock(&st->lock);
 
@@ -1189,7 +1189,7 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
 			if (ret < 0)
 				goto error_ret;
 			/* only supporting logical or's for now */
-			ret = !!(ret & sca3000_addresses[num][2]);
+			ret = !!(ret & sca3000_addresses[chan->channel2 - IIO_MOD_X][2]);
 		}
 		break;
 	default:
@@ -1305,7 +1305,8 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev,
 	case IIO_MOD_X:
 	case IIO_MOD_Y:
 	case IIO_MOD_Z:
-		ret = sca3000_motion_detect_set_state(indio_dev, chan->channel2,
+		ret = sca3000_motion_detect_set_state(indio_dev,
+						      chan->channel2 - IIO_MOD_X,
 						      state);
 		break;
 	default:
-- 
2.10.0


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

* [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (10 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes Jonathan Cameron
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Also includes an available attribute.  The ordering of values appears
a bit random, but as the ABI doesn't specify this and we already have
both rising and falling lists I think this is fine.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 55 +++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index e8f43df65142..7f03f916c9ec 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -432,6 +432,26 @@ error_ret:
 	return ret ? ret : len;
 }
 
+static ssize_t
+sca3000_show_available_3db_freqs(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int len;
+
+	len = sprintf(buf, "%d", st->info->measurement_mode_3db_freq);
+	if (st->info->option_mode_1)
+		len += sprintf(buf + len, " %d",
+			       st->info->option_mode_1_3db_freq);
+	if (st->info->option_mode_2)
+		len += sprintf(buf + len, " %d",
+			       st->info->option_mode_2_3db_freq);
+	len += sprintf(buf + len, "\n");
+
+	return len;
+}
 /**
  * sca3000_show_available_measurement_modes() display available modes
  *
@@ -570,6 +590,9 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
 		       sca3000_store_measurement_mode,
 		       0);
 
+static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
+		       S_IRUGO, sca3000_show_available_3db_freqs,
+		       NULL, 0);
 /* More standard attributes */
 
 static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
@@ -778,6 +801,31 @@ static int sca3000_read_3db_freq(struct sca3000_state *st, int *val)
 	}
 }
 
+static int sca3000_write_3db_freq(struct sca3000_state *st, int val)
+{
+	int ret;
+	int mode;
+
+	if (val == st->info->measurement_mode_3db_freq)
+		mode = SCA3000_REG_MODE_MEAS_MODE_NORMAL;
+	else if (st->info->option_mode_1 &&
+		 (val == st->info->option_mode_1_3db_freq))
+		mode = SCA3000_REG_MODE_MEAS_MODE_OP_1;
+	else if (st->info->option_mode_2 &&
+		 (val == st->info->option_mode_2_3db_freq))
+		mode = SCA3000_REG_MODE_MEAS_MODE_OP_2;
+	else
+		return -EINVAL;
+	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
+	if (ret)
+		return ret;
+
+	st->rx[0] &= ~SCA3000_REG_MODE_MODE_MASK;
+	st->rx[0] |= (mode & SCA3000_REG_MODE_MODE_MASK);
+
+	return sca3000_write_reg(st, SCA3000_REG_MODE_ADDR, st->rx[0]);
+}
+
 static int sca3000_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
 			    int *val,
@@ -860,6 +908,12 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
 		ret = write_raw_samp_freq(st, val);
 		mutex_unlock(&st->lock);
 		return ret;
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		if (val2)
+			return -EINVAL;
+		mutex_lock(&st->lock);
+		ret = sca3000_write_3db_freq(st, val);
+		mutex_unlock(&st->lock);
 	default:
 		return -EINVAL;
 	}
@@ -1006,6 +1060,7 @@ static struct attribute *sca3000_attributes[] = {
 	&iio_dev_attr_revision.dev_attr.attr,
 	&iio_dev_attr_measurement_mode_available.dev_attr.attr,
 	&iio_dev_attr_measurement_mode.dev_attr.attr,
+	&iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
 	NULL,
 };
-- 
2.10.0


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

* [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (11 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe Jonathan Cameron
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

This is now represented by the standard 3db filter frequency controls.
Things get complex wrt to the sampling frequency as these modes change
but that is fine under the IIO ABI where any value is allowed to effect
any other.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 139 ------------------------------------
 1 file changed, 139 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 7f03f916c9ec..e5cacd263f6d 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -452,143 +452,6 @@ sca3000_show_available_3db_freqs(struct device *dev,
 
 	return len;
 }
-/**
- * sca3000_show_available_measurement_modes() display available modes
- *
- * This is all read from chip specific data in the driver. Not all
- * of the sca3000 series support modes other than normal.
- **/
-static ssize_t
-sca3000_show_available_measurement_modes(struct device *dev,
-					 struct device_attribute *attr,
-					 char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	int len = 0;
-
-	len += sprintf(buf + len, "0 - normal mode");
-	switch (st->info->option_mode_1) {
-	case SCA3000_OP_MODE_NARROW:
-		len += sprintf(buf + len, ", 1 - narrow mode");
-		break;
-	case SCA3000_OP_MODE_BYPASS:
-		len += sprintf(buf + len, ", 1 - bypass mode");
-		break;
-	}
-	switch (st->info->option_mode_2) {
-	case SCA3000_OP_MODE_WIDE:
-		len += sprintf(buf + len, ", 2 - wide mode");
-		break;
-	}
-	/* always supported */
-	len += sprintf(buf + len, " 3 - motion detection\n");
-
-	return len;
-}
-
-/**
- * sca3000_show_measurement_mode() sysfs read of current mode
- **/
-static ssize_t
-sca3000_show_measurement_mode(struct device *dev,
-			      struct device_attribute *attr,
-			      char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	int len = 0, ret;
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
-	if (ret)
-		goto error_ret;
-	/* mask bottom 2 bits - only ones that are relevant */
-	st->rx[0] &= SCA3000_REG_MODE_MODE_MASK;
-	switch (st->rx[0]) {
-	case SCA3000_REG_MODE_MEAS_MODE_NORMAL:
-		len += sprintf(buf + len, "0 - normal mode\n");
-		break;
-	case SCA3000_REG_MODE_MEAS_MODE_MOT_DET:
-		len += sprintf(buf + len, "3 - motion detection\n");
-		break;
-	case SCA3000_REG_MODE_MEAS_MODE_OP_1:
-		switch (st->info->option_mode_1) {
-		case SCA3000_OP_MODE_NARROW:
-			len += sprintf(buf + len, "1 - narrow mode\n");
-			break;
-		case SCA3000_OP_MODE_BYPASS:
-			len += sprintf(buf + len, "1 - bypass mode\n");
-			break;
-		}
-		break;
-	case SCA3000_REG_MODE_MEAS_MODE_OP_2:
-		switch (st->info->option_mode_2) {
-		case SCA3000_OP_MODE_WIDE:
-			len += sprintf(buf + len, "2 - wide mode\n");
-			break;
-		}
-		break;
-	}
-
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : len;
-}
-
-/**
- * sca3000_store_measurement_mode() set the current mode
- **/
-static ssize_t
-sca3000_store_measurement_mode(struct device *dev,
-			       struct device_attribute *attr,
-			       const char *buf,
-			       size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	int ret;
-	u8 val;
-
-	mutex_lock(&st->lock);
-	ret = kstrtou8(buf, 10, &val);
-	if (ret)
-		goto error_ret;
-	if (val > 3) {
-		ret = -EINVAL;
-		goto error_ret;
-	}
-	ret = sca3000_read_data_short(st, SCA3000_REG_MODE_ADDR, 1);
-	if (ret)
-		goto error_ret;
-	st->rx[0] &= ~SCA3000_REG_MODE_MODE_MASK;
-	st->rx[0] |= (val & SCA3000_REG_MODE_MODE_MASK);
-	ret = sca3000_write_reg(st, SCA3000_REG_MODE_ADDR, st->rx[0]);
-	if (ret)
-		goto error_ret;
-	mutex_unlock(&st->lock);
-
-	return len;
-
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret;
-}
-
-/*
- * Not even vaguely standard attributes so defined here rather than
- * in the relevant IIO core headers
- */
-static IIO_DEVICE_ATTR(measurement_mode_available, S_IRUGO,
-		       sca3000_show_available_measurement_modes,
-		       NULL, 0);
-
-static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
-		       sca3000_show_measurement_mode,
-		       sca3000_store_measurement_mode,
-		       0);
 
 static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
 		       S_IRUGO, sca3000_show_available_3db_freqs,
@@ -1058,8 +921,6 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 
 static struct attribute *sca3000_attributes[] = {
 	&iio_dev_attr_revision.dev_attr.attr,
-	&iio_dev_attr_measurement_mode_available.dev_attr.attr,
-	&iio_dev_attr_measurement_mode.dev_attr.attr,
 	&iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
 	NULL,
-- 
2.10.0


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

* [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (12 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:26 ` [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race Jonathan Cameron
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

There seems little point in being able to query the part revision number
via sysfs.  Hence just put it in the kernel logs during probe incase
anyone ever wants to know.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index e5cacd263f6d..2a911843fdf0 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -410,26 +410,23 @@ error_ret:
 /**
  * sca3000_show_rev() - sysfs interface to read the chip revision number
  **/
-static ssize_t sca3000_show_rev(struct device *dev,
-				struct device_attribute *attr,
-				char *buf)
+static int sca3000_print_rev(struct iio_dev *indio_dev)
 {
-	int len = 0, ret;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	int ret;
 	struct sca3000_state *st = iio_priv(indio_dev);
 
 	mutex_lock(&st->lock);
 	ret = sca3000_read_data_short(st, SCA3000_REG_REVID_ADDR, 1);
 	if (ret < 0)
 		goto error_ret;
-	len += sprintf(buf + len,
-		       "major=%lu, minor=%lu\n",
-		       st->rx[0] & SCA3000_REG_REVID_MAJOR_MASK,
-		       st->rx[0] & SCA3000_REG_REVID_MINOR_MASK);
+	dev_info(&indio_dev->dev,
+		 "sca3000 revision major=%lu, minor=%lu\n",
+		 st->rx[0] & SCA3000_REG_REVID_MAJOR_MASK,
+		 st->rx[0] & SCA3000_REG_REVID_MINOR_MASK);
 error_ret:
 	mutex_unlock(&st->lock);
 
-	return ret ? ret : len;
+	return ret;
 }
 
 static ssize_t
@@ -456,9 +453,6 @@ sca3000_show_available_3db_freqs(struct device *dev,
 static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
 		       S_IRUGO, sca3000_show_available_3db_freqs,
 		       NULL, 0);
-/* More standard attributes */
-
-static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
 
 static const struct iio_event_spec sca3000_event = {
 	.type = IIO_EV_TYPE_MAG,
@@ -920,7 +914,6 @@ static int sca3000_write_event_value(struct iio_dev *indio_dev,
 }
 
 static struct attribute *sca3000_attributes[] = {
-	&iio_dev_attr_revision.dev_attr.attr,
 	&iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
 	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
 	NULL,
@@ -1477,6 +1470,11 @@ static int sca3000_probe(struct spi_device *spi)
 	ret = sca3000_clean_setup(st);
 	if (ret)
 		goto error_free_irq;
+
+	ret = sca3000_print_rev(indio_dev);
+	if (ret)
+		goto error_free_irq;
+
 	return 0;
 
 error_free_irq:
-- 
2.10.0


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

* [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (13 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe Jonathan Cameron
@ 2016-10-03 19:26 ` Jonathan Cameron
  2016-10-03 19:27 ` [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) Jonathan Cameron
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:26 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Previously the device was exposed to userspace and in kernel consumers
before the interrupts had been configured. As nothing stopped them being
enabled in the interval this could cause unhandled interrupts.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 2a911843fdf0..bb184eade558 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -1452,9 +1452,6 @@ static int sca3000_probe(struct spi_device *spi)
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	sca3000_configure_ring(indio_dev);
-	ret = iio_device_register(indio_dev);
-	if (ret < 0)
-		return ret;
 
 	if (spi->irq) {
 		ret = request_threaded_irq(spi->irq,
@@ -1464,7 +1461,7 @@ static int sca3000_probe(struct spi_device *spi)
 					   "sca3000",
 					   indio_dev);
 		if (ret)
-			goto error_unregister_dev;
+			return ret;
 	}
 	indio_dev->setup_ops = &sca3000_ring_setup_ops;
 	ret = sca3000_clean_setup(st);
@@ -1475,13 +1472,12 @@ static int sca3000_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_irq;
 
-	return 0;
+	return iio_device_register(indio_dev);
 
 error_free_irq:
 	if (spi->irq)
 		free_irq(spi->irq, indio_dev);
-error_unregister_dev:
-	iio_device_unregister(indio_dev);
+
 	return ret;
 }
 
@@ -1508,11 +1504,13 @@ static int sca3000_remove(struct spi_device *spi)
 	struct iio_dev *indio_dev = spi_get_drvdata(spi);
 	struct sca3000_state *st = iio_priv(indio_dev);
 
+	iio_device_unregister(indio_dev);
+
 	/* Must ensure no interrupts can be generated after this! */
 	sca3000_stop_all_interrupts(st);
 	if (spi->irq)
 		free_irq(spi->irq, indio_dev);
-	iio_device_unregister(indio_dev);
+
 	sca3000_unconfigure_ring(indio_dev);
 
 	return 0;
-- 
2.10.0


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

* [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc)
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (14 preceding siblings ...)
  2016-10-03 19:26 ` [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race Jonathan Cameron
@ 2016-10-03 19:27 ` Jonathan Cameron
  2016-10-03 19:27 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
  2016-10-03 19:27 ` [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging Jonathan Cameron
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:27 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Tidied up where checkpatch warning suppressions doesn't effect the
readability of the code.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index bb184eade558..58ec02fba3bd 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -274,8 +274,8 @@ static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
 }
 
 static int sca3000_read_data_short(struct sca3000_state *st,
-			    u8 reg_address_high,
-			    int len)
+				   u8 reg_address_high,
+				   int len)
 {
 	struct spi_transfer xfer[2] = {
 		{
-- 
2.10.0


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

* [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (15 preceding siblings ...)
  2016-10-03 19:27 ` [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) Jonathan Cameron
@ 2016-10-03 19:27 ` Jonathan Cameron
  2016-10-03 20:07   ` Peter Meerwald-Stadler
  2016-10-03 19:27 ` [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging Jonathan Cameron
  17 siblings, 1 reply; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:27 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Basic tidy up of comments to bring them into a standard style.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/sca3000.c | 106 ++++++++++++++++++++++++++----------
 1 file changed, 77 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
index 58ec02fba3bd..fbbd8defa50d 100644
--- a/drivers/staging/iio/accel/sca3000.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -178,10 +178,20 @@ struct sca3000_state {
  * @scale:			scale * 10^-6
  * @temp_output:		some devices have temperature sensors.
  * @measurement_mode_freq:	normal mode sampling frequency
+ * @measurement_mode_3db_freq:	3db cutoff frequency of the low pass filter for
+ * the normal measurement mode.
  * @option_mode_1:		first optional mode. Not all models have one
  * @option_mode_1_freq:		option mode 1 sampling frequency
+ * @option_mode_1_3db_freq:	3db cutoff frequency of the low pass fitler for
+ * the first option mode.
  * @option_mode_2:		second optional mode. Not all chips have one
  * @option_mode_2_freq:		option mode 2 sampling frequency
+ * @option_mode_2_3db_freq:	3db cutoff frequency of the low pass fitler for
+ * the second option mode.
+ * @mod_det_mult_xz:		Bit wise multipliers to calculate the threshold
+ * for motion detection in the x and z axis.
+ * @mod_det_mult_y:		Bit wise multipliers to calculate the threshold
+ * for motion detection in the y axis.
  *
  * This structure is used to hold information about the functionality of a given
  * sca3000 variant.
@@ -292,7 +302,8 @@ static int sca3000_read_data_short(struct sca3000_state *st,
 }
 
 /**
- * sca3000_reg_lock_on() test if the ctrl register lock is on
+ * sca3000_reg_lock_on() - test if the ctrl register lock is on
+ * @st: Driver specific device instance data.
  *
  * Lock must be held.
  **/
@@ -308,12 +319,13 @@ static int sca3000_reg_lock_on(struct sca3000_state *st)
 }
 
 /**
- * __sca3000_unlock_reg_lock() unlock the control registers
+ * __sca3000_unlock_reg_lock() - unlock the control registers
+ * @st: Driver specific device instance data.
  *
  * Note the device does not appear to support doing this in a single transfer.
  * This should only ever be used as part of ctrl reg read.
  * Lock must be held before calling this
- **/
+ */
 static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
 {
 	struct spi_transfer xfer[3] = {
@@ -342,6 +354,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
 
 /**
  * sca3000_write_ctrl_reg() write to a lock protect ctrl register
+ * @st: Driver specific device instance data.
  * @sel: selects which registers we wish to write to
  * @val: the value to be written
  *
@@ -349,7 +362,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
  * register and use a shared write address. This function allows writing of
  * these registers.
  * Lock must be held.
- **/
+ */
 static int sca3000_write_ctrl_reg(struct sca3000_state *st,
 				  u8 sel,
 				  uint8_t val)
@@ -379,9 +392,11 @@ error_ret:
 
 /**
  * sca3000_read_ctrl_reg() read from lock protected control register.
+ * @st: Driver specific device instance data.
+ * @ctrl_reg: Which ctrl register do we want to read.
  *
  * Lock must be held.
- **/
+ */
 static int sca3000_read_ctrl_reg(struct sca3000_state *st,
 				 u8 ctrl_reg)
 {
@@ -409,7 +424,10 @@ error_ret:
 
 /**
  * sca3000_show_rev() - sysfs interface to read the chip revision number
- **/
+ * @indio_dev: Device instance specific generic IIO data.
+ * Driver specific device instance data can be obtained via
+ * via iio_priv(indio_dev)
+ */
 static int sca3000_print_rev(struct iio_dev *indio_dev)
 {
 	int ret;
@@ -539,10 +557,13 @@ static u8 sca3000_addresses[3][3] = {
 };
 
 /**
- * __sca3000_get_base_freq() obtain mode specific base frequency
+ * __sca3000_get_base_freq() - obtain mode specific base frequency
+ * @st: Private driver specific device instance specific state.
+ * @info: chip type specific information.
+ * @base_freq: Base frequency for the current measurement mode.
  *
  * lock must be held
- **/
+ */
 static inline int __sca3000_get_base_freq(struct sca3000_state *st,
 					  const struct sca3000_chip_info *info,
 					  int *base_freq)
@@ -570,11 +591,13 @@ error_ret:
 }
 
 /**
- * read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
+ * sca3000_read_raw_samp_freq() - read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
+ * @st: Private driver specific device instance specific state.
+ * @val: The frequency read back.
  *
  * lock must be held
  **/
-static int read_raw_samp_freq(struct sca3000_state *st, int *val)
+static int sca3000_read_raw_samp_freq(struct sca3000_state *st, int *val)
 {
 	int ret;
 
@@ -602,11 +625,13 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val)
 }
 
 /**
- * write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
+ * sca3000_write_raw_samp_freq() - write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
+ * @st: Private driver specific device instance specific state.
+ * @val: The frequency desired.
  *
  * lock must be held
- **/
-static int write_raw_samp_freq(struct sca3000_state *st, int val)
+ */
+static int sca3000_write_raw_samp_freq(struct sca3000_state *st, int val)
 {
 	int ret, base_freq, ctrlval;
 
@@ -737,7 +762,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
 		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		mutex_lock(&st->lock);
-		ret = read_raw_samp_freq(st, val);
+		ret = sca3000_read_raw_samp_freq(st, val);
 		mutex_unlock(&st->lock);
 		return ret ? ret : IIO_VAL_INT;
 	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
@@ -762,7 +787,7 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
 		if (val2)
 			return -EINVAL;
 		mutex_lock(&st->lock);
-		ret = write_raw_samp_freq(st, val);
+		ret = sca3000_write_raw_samp_freq(st, val);
 		mutex_unlock(&st->lock);
 		return ret;
 	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
@@ -779,7 +804,10 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
 }
 
 /**
- * sca3000_read_av_freq() sysfs function to get available frequencies
+ * sca3000_read_av_freq() - sysfs function to get available frequencies
+ * @dev: Device structure for this device.
+ * @attr: Description of the attribute.
+ * @buf: Incoming string
  *
  * The later modes are only relevant to the ring buffer - and depend on current
  * mode. Note that data sheet gives rather wide tolerances for these so integer
@@ -874,8 +902,18 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
 }
 
 /**
- * sca3000_write_value() control of threshold and period
- **/
+ * sca3000_write_value() - control of threshold and period
+ * @indio_dev: Device instance specific IIO information.
+ * @chan: Description of the channel for which the event is being
+ * configured.
+ * @type: The type of event being configured, here magnitude rising
+ * as everything else is read only.
+ * @dir: Direction of the event (here rising)
+ * @info: What information about the event are we configuring.
+ * Here the threshold only.
+ * @val: Integer part of the value being written..
+ * @val2: Non integer part of the value being written. Here always 0.
+ */
 static int sca3000_write_event_value(struct iio_dev *indio_dev,
 				     const struct iio_chan_spec *chan,
 				     enum iio_event_type type,
@@ -950,11 +988,10 @@ static int sca3000_read_data(struct sca3000_state *st,
 }
 
 /**
- * sca3000_ring_int_process() ring specific interrupt handling.
- *
- * This is only split from the main interrupt handler so as to
- * reduce the amount of code if the ring buffer is not enabled.
- **/
+ * sca3000_ring_int_process() - ring specific interrupt handling.
+ * @val: Value of the interrupt status register.
+ * @indio_dev: Device instance specific IIO device structure.
+ */
 static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
 {
 	struct sca3000_state *st = iio_priv(indio_dev);
@@ -993,6 +1030,8 @@ error_ret:
 
 /**
  * sca3000_event_handler() - handling ring and non ring events
+ * @irq: The irq being handled.
+ * @private: struct iio_device pointer for the device.
  *
  * Ring related interrupt handler. Depending on event, push to
  * the ring buffer event chrdev or the event one.
@@ -1000,7 +1039,7 @@ error_ret:
  * This function is complicated by the fact that the devices can signify ring
  * and non ring events via the same interrupt line and they can only
  * be distinguished via a read of the relevant status register.
- **/
+ */
 static irqreturn_t sca3000_event_handler(int irq, void *private)
 {
 	struct iio_dev *indio_dev = private;
@@ -1188,7 +1227,13 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis,
 }
 
 /**
- * sca3000_write_event_config() simple on off control for motion detector
+ * sca3000_write_event_config() - simple on off control for motion detector
+ * @indio_dev: IIO device instance specific structure. Data specific to this
+ * particular driver may be accessed via iio_priv(indio_dev).
+ * @chan: Description of the channel whoes event we are configuring.
+ * @type: The type of event.
+ * @dir: The direction of the event.
+ * @state: Desired state of event being configured.
  *
  * This is a per axis control, but enabling any will result in the
  * motion detector unit being enabled.
@@ -1272,12 +1317,14 @@ error_ret:
 }
 
 /**
- * sca3000_hw_ring_preenable() hw ring buffer preenable function
+ * sca3000_hw_ring_preenable() - hw ring buffer preenable function
+ * @indio_dev: structure representing the IIO device. Device instance
+ * specific state can be accessed via iio_priv(indio_dev).
  *
  * Very simple enable function as the chip will allows normal reads
  * during ring buffer operation so as long as it is indeed running
  * before we notify the core, the precise ordering does not matter.
- **/
+ */
 static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
 {
 	int ret;
@@ -1347,12 +1394,13 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
 };
 
 /**
- * sca3000_clean_setup() get the device into a predictable state
+ * sca3000_clean_setup() - get the device into a predictable state
+ * @st: Device instance specific private data structure
  *
  * Devices use flash memory to store many of the register values
  * and hence can come up in somewhat unpredictable states.
  * Hence reset everything on driver load.
- **/
+ */
 static int sca3000_clean_setup(struct sca3000_state *st)
 {
 	int ret;
-- 
2.10.0


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

* [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging.
  2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
                   ` (16 preceding siblings ...)
  2016-10-03 19:27 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
@ 2016-10-03 19:27 ` Jonathan Cameron
  17 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 19:27 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

Now the driver is in a reasonable state, lets get it (finally) out
of staging.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/iio/accel/Kconfig                 | 12 ++++++++++++
 drivers/iio/accel/Makefile                |  2 ++
 drivers/{staging => }/iio/accel/sca3000.c |  0
 drivers/staging/iio/accel/Kconfig         | 11 -----------
 drivers/staging/iio/accel/Makefile        |  1 -
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index ac56e0add42e..946e99a1a818 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -283,6 +283,18 @@ config MXC6255
 	  To compile this driver as a module, choose M here: the module will be
 	  called mxc6255.
 
+config SCA3000
+	select IIO_BUFFER
+	select IIO_KFIFO_BUF
+	depends on SPI
+	tristate "VTI SCA3000 series accelerometers"
+	help
+	  Say Y here to build support for the VTI SCA3000 series of SPI
+	  accelerometers. These devices use a hardware ring buffer.
+
+	  To compile this driver as a module, say M here: the module will be
+	  called sca3000.
+
 config STK8312
 	tristate "Sensortek STK8312 3-Axis Accelerometer Driver"
 	depends on I2C
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 03848148ad4b..c0bdc984793b 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -33,6 +33,8 @@ obj-$(CONFIG_MMA9553)		+= mma9553.o
 obj-$(CONFIG_MXC4005)		+= mxc4005.o
 obj-$(CONFIG_MXC6255)		+= mxc6255.o
 
+obj-$(CONFIG_SCA3000)		+= sca3000.o
+
 obj-$(CONFIG_STK8312)		+= stk8312.o
 obj-$(CONFIG_STK8BA50)		+= stk8ba50.o
 
diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
similarity index 100%
rename from drivers/staging/iio/accel/sca3000.c
rename to drivers/iio/accel/sca3000.c
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig
index 53389bfdd100..c6b0f5eae7ab 100644
--- a/drivers/staging/iio/accel/Kconfig
+++ b/drivers/staging/iio/accel/Kconfig
@@ -51,15 +51,4 @@ config ADIS16240
 	  To compile this driver as a module, say M here: the module will be
 	  called adis16240.
 
-config SCA3000
-	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	depends on SPI
-	tristate "VTI SCA3000 series accelerometers"
-	help
-	  Say Y here to build support for the VTI SCA3000 series of SPI
-	  accelerometers. These devices use a hardware ring buffer.
-
-	  To compile this driver as a module, say M here: the module will be
-	  called sca3000.
 endmenu
diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
index 6ab95708e696..1939829622fd 100644
--- a/drivers/staging/iio/accel/Makefile
+++ b/drivers/staging/iio/accel/Makefile
@@ -14,4 +14,3 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
 adis16240-y             := adis16240_core.o
 obj-$(CONFIG_ADIS16240) += adis16240.o
 
-obj-$(CONFIG_SCA3000)	:= sca3000.o
-- 
2.10.0


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

* Re: [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc.
  2016-10-03 19:27 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
@ 2016-10-03 20:07   ` Peter Meerwald-Stadler
  2016-10-03 20:27     ` Jonathan Cameron
  0 siblings, 1 reply; 28+ messages in thread
From: Peter Meerwald-Stadler @ 2016-10-03 20:07 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, knaack.h, lars


> Basic tidy up of comments to bring them into a standard style.

nitpicking on 3 typos below
 
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/accel/sca3000.c | 106 ++++++++++++++++++++++++++----------
>  1 file changed, 77 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
> index 58ec02fba3bd..fbbd8defa50d 100644
> --- a/drivers/staging/iio/accel/sca3000.c
> +++ b/drivers/staging/iio/accel/sca3000.c
> @@ -178,10 +178,20 @@ struct sca3000_state {
>   * @scale:			scale * 10^-6
>   * @temp_output:		some devices have temperature sensors.
>   * @measurement_mode_freq:	normal mode sampling frequency
> + * @measurement_mode_3db_freq:	3db cutoff frequency of the low pass filter for
> + * the normal measurement mode.
>   * @option_mode_1:		first optional mode. Not all models have one
>   * @option_mode_1_freq:		option mode 1 sampling frequency
> + * @option_mode_1_3db_freq:	3db cutoff frequency of the low pass fitler for

filter

> + * the first option mode.
>   * @option_mode_2:		second optional mode. Not all chips have one
>   * @option_mode_2_freq:		option mode 2 sampling frequency
> + * @option_mode_2_3db_freq:	3db cutoff frequency of the low pass fitler for

filter

> + * the second option mode.
> + * @mod_det_mult_xz:		Bit wise multipliers to calculate the threshold
> + * for motion detection in the x and z axis.
> + * @mod_det_mult_y:		Bit wise multipliers to calculate the threshold
> + * for motion detection in the y axis.
>   *
>   * This structure is used to hold information about the functionality of a given
>   * sca3000 variant.
> @@ -292,7 +302,8 @@ static int sca3000_read_data_short(struct sca3000_state *st,
>  }
>  
>  /**
> - * sca3000_reg_lock_on() test if the ctrl register lock is on
> + * sca3000_reg_lock_on() - test if the ctrl register lock is on
> + * @st: Driver specific device instance data.
>   *
>   * Lock must be held.
>   **/
> @@ -308,12 +319,13 @@ static int sca3000_reg_lock_on(struct sca3000_state *st)
>  }
>  
>  /**
> - * __sca3000_unlock_reg_lock() unlock the control registers
> + * __sca3000_unlock_reg_lock() - unlock the control registers
> + * @st: Driver specific device instance data.
>   *
>   * Note the device does not appear to support doing this in a single transfer.
>   * This should only ever be used as part of ctrl reg read.
>   * Lock must be held before calling this
> - **/
> + */
>  static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>  {
>  	struct spi_transfer xfer[3] = {
> @@ -342,6 +354,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>  
>  /**
>   * sca3000_write_ctrl_reg() write to a lock protect ctrl register
> + * @st: Driver specific device instance data.
>   * @sel: selects which registers we wish to write to
>   * @val: the value to be written
>   *
> @@ -349,7 +362,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>   * register and use a shared write address. This function allows writing of
>   * these registers.
>   * Lock must be held.
> - **/
> + */
>  static int sca3000_write_ctrl_reg(struct sca3000_state *st,
>  				  u8 sel,
>  				  uint8_t val)
> @@ -379,9 +392,11 @@ error_ret:
>  
>  /**
>   * sca3000_read_ctrl_reg() read from lock protected control register.
> + * @st: Driver specific device instance data.
> + * @ctrl_reg: Which ctrl register do we want to read.
>   *
>   * Lock must be held.
> - **/
> + */
>  static int sca3000_read_ctrl_reg(struct sca3000_state *st,
>  				 u8 ctrl_reg)
>  {
> @@ -409,7 +424,10 @@ error_ret:
>  
>  /**
>   * sca3000_show_rev() - sysfs interface to read the chip revision number
> - **/
> + * @indio_dev: Device instance specific generic IIO data.
> + * Driver specific device instance data can be obtained via
> + * via iio_priv(indio_dev)
> + */
>  static int sca3000_print_rev(struct iio_dev *indio_dev)
>  {
>  	int ret;
> @@ -539,10 +557,13 @@ static u8 sca3000_addresses[3][3] = {
>  };
>  
>  /**
> - * __sca3000_get_base_freq() obtain mode specific base frequency
> + * __sca3000_get_base_freq() - obtain mode specific base frequency
> + * @st: Private driver specific device instance specific state.
> + * @info: chip type specific information.
> + * @base_freq: Base frequency for the current measurement mode.
>   *
>   * lock must be held
> - **/
> + */
>  static inline int __sca3000_get_base_freq(struct sca3000_state *st,
>  					  const struct sca3000_chip_info *info,
>  					  int *base_freq)
> @@ -570,11 +591,13 @@ error_ret:
>  }
>  
>  /**
> - * read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
> + * sca3000_read_raw_samp_freq() - read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
> + * @st: Private driver specific device instance specific state.
> + * @val: The frequency read back.
>   *
>   * lock must be held
>   **/
> -static int read_raw_samp_freq(struct sca3000_state *st, int *val)
> +static int sca3000_read_raw_samp_freq(struct sca3000_state *st, int *val)
>  {
>  	int ret;
>  
> @@ -602,11 +625,13 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val)
>  }
>  
>  /**
> - * write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
> + * sca3000_write_raw_samp_freq() - write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
> + * @st: Private driver specific device instance specific state.
> + * @val: The frequency desired.
>   *
>   * lock must be held
> - **/
> -static int write_raw_samp_freq(struct sca3000_state *st, int val)
> + */
> +static int sca3000_write_raw_samp_freq(struct sca3000_state *st, int val)
>  {
>  	int ret, base_freq, ctrlval;
>  
> @@ -737,7 +762,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	case IIO_CHAN_INFO_SAMP_FREQ:
>  		mutex_lock(&st->lock);
> -		ret = read_raw_samp_freq(st, val);
> +		ret = sca3000_read_raw_samp_freq(st, val);
>  		mutex_unlock(&st->lock);
>  		return ret ? ret : IIO_VAL_INT;
>  	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> @@ -762,7 +787,7 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
>  		if (val2)
>  			return -EINVAL;
>  		mutex_lock(&st->lock);
> -		ret = write_raw_samp_freq(st, val);
> +		ret = sca3000_write_raw_samp_freq(st, val);
>  		mutex_unlock(&st->lock);
>  		return ret;
>  	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> @@ -779,7 +804,10 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
>  }
>  
>  /**
> - * sca3000_read_av_freq() sysfs function to get available frequencies
> + * sca3000_read_av_freq() - sysfs function to get available frequencies
> + * @dev: Device structure for this device.
> + * @attr: Description of the attribute.
> + * @buf: Incoming string
>   *
>   * The later modes are only relevant to the ring buffer - and depend on current
>   * mode. Note that data sheet gives rather wide tolerances for these so integer
> @@ -874,8 +902,18 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
>  }
>  
>  /**
> - * sca3000_write_value() control of threshold and period
> - **/
> + * sca3000_write_value() - control of threshold and period
> + * @indio_dev: Device instance specific IIO information.
> + * @chan: Description of the channel for which the event is being
> + * configured.
> + * @type: The type of event being configured, here magnitude rising
> + * as everything else is read only.
> + * @dir: Direction of the event (here rising)
> + * @info: What information about the event are we configuring.
> + * Here the threshold only.
> + * @val: Integer part of the value being written..
> + * @val2: Non integer part of the value being written. Here always 0.
> + */
>  static int sca3000_write_event_value(struct iio_dev *indio_dev,
>  				     const struct iio_chan_spec *chan,
>  				     enum iio_event_type type,
> @@ -950,11 +988,10 @@ static int sca3000_read_data(struct sca3000_state *st,
>  }
>  
>  /**
> - * sca3000_ring_int_process() ring specific interrupt handling.
> - *
> - * This is only split from the main interrupt handler so as to
> - * reduce the amount of code if the ring buffer is not enabled.
> - **/
> + * sca3000_ring_int_process() - ring specific interrupt handling.
> + * @val: Value of the interrupt status register.
> + * @indio_dev: Device instance specific IIO device structure.
> + */
>  static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
>  {
>  	struct sca3000_state *st = iio_priv(indio_dev);
> @@ -993,6 +1030,8 @@ error_ret:
>  
>  /**
>   * sca3000_event_handler() - handling ring and non ring events
> + * @irq: The irq being handled.
> + * @private: struct iio_device pointer for the device.
>   *
>   * Ring related interrupt handler. Depending on event, push to
>   * the ring buffer event chrdev or the event one.
> @@ -1000,7 +1039,7 @@ error_ret:
>   * This function is complicated by the fact that the devices can signify ring
>   * and non ring events via the same interrupt line and they can only
>   * be distinguished via a read of the relevant status register.
> - **/
> + */
>  static irqreturn_t sca3000_event_handler(int irq, void *private)
>  {
>  	struct iio_dev *indio_dev = private;
> @@ -1188,7 +1227,13 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis,
>  }
>  
>  /**
> - * sca3000_write_event_config() simple on off control for motion detector
> + * sca3000_write_event_config() - simple on off control for motion detector
> + * @indio_dev: IIO device instance specific structure. Data specific to this
> + * particular driver may be accessed via iio_priv(indio_dev).
> + * @chan: Description of the channel whoes event we are configuring.

whose

> + * @type: The type of event.
> + * @dir: The direction of the event.
> + * @state: Desired state of event being configured.
>   *
>   * This is a per axis control, but enabling any will result in the
>   * motion detector unit being enabled.
> @@ -1272,12 +1317,14 @@ error_ret:
>  }
>  
>  /**
> - * sca3000_hw_ring_preenable() hw ring buffer preenable function
> + * sca3000_hw_ring_preenable() - hw ring buffer preenable function
> + * @indio_dev: structure representing the IIO device. Device instance
> + * specific state can be accessed via iio_priv(indio_dev).
>   *
>   * Very simple enable function as the chip will allows normal reads
>   * during ring buffer operation so as long as it is indeed running
>   * before we notify the core, the precise ordering does not matter.
> - **/
> + */
>  static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
>  {
>  	int ret;
> @@ -1347,12 +1394,13 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
>  };
>  
>  /**
> - * sca3000_clean_setup() get the device into a predictable state
> + * sca3000_clean_setup() - get the device into a predictable state
> + * @st: Device instance specific private data structure
>   *
>   * Devices use flash memory to store many of the register values
>   * and hence can come up in somewhat unpredictable states.
>   * Hence reset everything on driver load.
> - **/
> + */
>  static int sca3000_clean_setup(struct sca3000_state *st)
>  {
>  	int ret;
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)

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

* Re: [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc.
  2016-10-03 20:07   ` Peter Meerwald-Stadler
@ 2016-10-03 20:27     ` Jonathan Cameron
  0 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-03 20:27 UTC (permalink / raw)
  To: Peter Meerwald-Stadler; +Cc: linux-iio, knaack.h, lars

On 03/10/16 21:07, Peter Meerwald-Stadler wrote:
> 
>> Basic tidy up of comments to bring them into a standard style.
> 
> nitpicking on 3 typos below
>  
Thanks.

Jonathan
>> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
>> ---
>>  drivers/staging/iio/accel/sca3000.c | 106 ++++++++++++++++++++++++++----------
>>  1 file changed, 77 insertions(+), 29 deletions(-)
>>
>> diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
>> index 58ec02fba3bd..fbbd8defa50d 100644
>> --- a/drivers/staging/iio/accel/sca3000.c
>> +++ b/drivers/staging/iio/accel/sca3000.c
>> @@ -178,10 +178,20 @@ struct sca3000_state {
>>   * @scale:			scale * 10^-6
>>   * @temp_output:		some devices have temperature sensors.
>>   * @measurement_mode_freq:	normal mode sampling frequency
>> + * @measurement_mode_3db_freq:	3db cutoff frequency of the low pass filter for
>> + * the normal measurement mode.
>>   * @option_mode_1:		first optional mode. Not all models have one
>>   * @option_mode_1_freq:		option mode 1 sampling frequency
>> + * @option_mode_1_3db_freq:	3db cutoff frequency of the low pass fitler for
> 
> filter
> 
>> + * the first option mode.
>>   * @option_mode_2:		second optional mode. Not all chips have one
>>   * @option_mode_2_freq:		option mode 2 sampling frequency
>> + * @option_mode_2_3db_freq:	3db cutoff frequency of the low pass fitler for
> 
> filter
> 
>> + * the second option mode.
>> + * @mod_det_mult_xz:		Bit wise multipliers to calculate the threshold
>> + * for motion detection in the x and z axis.
>> + * @mod_det_mult_y:		Bit wise multipliers to calculate the threshold
>> + * for motion detection in the y axis.
>>   *
>>   * This structure is used to hold information about the functionality of a given
>>   * sca3000 variant.
>> @@ -292,7 +302,8 @@ static int sca3000_read_data_short(struct sca3000_state *st,
>>  }
>>  
>>  /**
>> - * sca3000_reg_lock_on() test if the ctrl register lock is on
>> + * sca3000_reg_lock_on() - test if the ctrl register lock is on
>> + * @st: Driver specific device instance data.
>>   *
>>   * Lock must be held.
>>   **/
>> @@ -308,12 +319,13 @@ static int sca3000_reg_lock_on(struct sca3000_state *st)
>>  }
>>  
>>  /**
>> - * __sca3000_unlock_reg_lock() unlock the control registers
>> + * __sca3000_unlock_reg_lock() - unlock the control registers
>> + * @st: Driver specific device instance data.
>>   *
>>   * Note the device does not appear to support doing this in a single transfer.
>>   * This should only ever be used as part of ctrl reg read.
>>   * Lock must be held before calling this
>> - **/
>> + */
>>  static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>>  {
>>  	struct spi_transfer xfer[3] = {
>> @@ -342,6 +354,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>>  
>>  /**
>>   * sca3000_write_ctrl_reg() write to a lock protect ctrl register
>> + * @st: Driver specific device instance data.
>>   * @sel: selects which registers we wish to write to
>>   * @val: the value to be written
>>   *
>> @@ -349,7 +362,7 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
>>   * register and use a shared write address. This function allows writing of
>>   * these registers.
>>   * Lock must be held.
>> - **/
>> + */
>>  static int sca3000_write_ctrl_reg(struct sca3000_state *st,
>>  				  u8 sel,
>>  				  uint8_t val)
>> @@ -379,9 +392,11 @@ error_ret:
>>  
>>  /**
>>   * sca3000_read_ctrl_reg() read from lock protected control register.
>> + * @st: Driver specific device instance data.
>> + * @ctrl_reg: Which ctrl register do we want to read.
>>   *
>>   * Lock must be held.
>> - **/
>> + */
>>  static int sca3000_read_ctrl_reg(struct sca3000_state *st,
>>  				 u8 ctrl_reg)
>>  {
>> @@ -409,7 +424,10 @@ error_ret:
>>  
>>  /**
>>   * sca3000_show_rev() - sysfs interface to read the chip revision number
>> - **/
>> + * @indio_dev: Device instance specific generic IIO data.
>> + * Driver specific device instance data can be obtained via
>> + * via iio_priv(indio_dev)
>> + */
>>  static int sca3000_print_rev(struct iio_dev *indio_dev)
>>  {
>>  	int ret;
>> @@ -539,10 +557,13 @@ static u8 sca3000_addresses[3][3] = {
>>  };
>>  
>>  /**
>> - * __sca3000_get_base_freq() obtain mode specific base frequency
>> + * __sca3000_get_base_freq() - obtain mode specific base frequency
>> + * @st: Private driver specific device instance specific state.
>> + * @info: chip type specific information.
>> + * @base_freq: Base frequency for the current measurement mode.
>>   *
>>   * lock must be held
>> - **/
>> + */
>>  static inline int __sca3000_get_base_freq(struct sca3000_state *st,
>>  					  const struct sca3000_chip_info *info,
>>  					  int *base_freq)
>> @@ -570,11 +591,13 @@ error_ret:
>>  }
>>  
>>  /**
>> - * read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
>> + * sca3000_read_raw_samp_freq() - read_raw handler for IIO_CHAN_INFO_SAMP_FREQ
>> + * @st: Private driver specific device instance specific state.
>> + * @val: The frequency read back.
>>   *
>>   * lock must be held
>>   **/
>> -static int read_raw_samp_freq(struct sca3000_state *st, int *val)
>> +static int sca3000_read_raw_samp_freq(struct sca3000_state *st, int *val)
>>  {
>>  	int ret;
>>  
>> @@ -602,11 +625,13 @@ static int read_raw_samp_freq(struct sca3000_state *st, int *val)
>>  }
>>  
>>  /**
>> - * write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
>> + * sca3000_write_raw_samp_freq() - write_raw handler for IIO_CHAN_INFO_SAMP_FREQ
>> + * @st: Private driver specific device instance specific state.
>> + * @val: The frequency desired.
>>   *
>>   * lock must be held
>> - **/
>> -static int write_raw_samp_freq(struct sca3000_state *st, int val)
>> + */
>> +static int sca3000_write_raw_samp_freq(struct sca3000_state *st, int val)
>>  {
>>  	int ret, base_freq, ctrlval;
>>  
>> @@ -737,7 +762,7 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
>>  		return IIO_VAL_INT_PLUS_MICRO;
>>  	case IIO_CHAN_INFO_SAMP_FREQ:
>>  		mutex_lock(&st->lock);
>> -		ret = read_raw_samp_freq(st, val);
>> +		ret = sca3000_read_raw_samp_freq(st, val);
>>  		mutex_unlock(&st->lock);
>>  		return ret ? ret : IIO_VAL_INT;
>>  	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
>> @@ -762,7 +787,7 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
>>  		if (val2)
>>  			return -EINVAL;
>>  		mutex_lock(&st->lock);
>> -		ret = write_raw_samp_freq(st, val);
>> +		ret = sca3000_write_raw_samp_freq(st, val);
>>  		mutex_unlock(&st->lock);
>>  		return ret;
>>  	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
>> @@ -779,7 +804,10 @@ static int sca3000_write_raw(struct iio_dev *indio_dev,
>>  }
>>  
>>  /**
>> - * sca3000_read_av_freq() sysfs function to get available frequencies
>> + * sca3000_read_av_freq() - sysfs function to get available frequencies
>> + * @dev: Device structure for this device.
>> + * @attr: Description of the attribute.
>> + * @buf: Incoming string
>>   *
>>   * The later modes are only relevant to the ring buffer - and depend on current
>>   * mode. Note that data sheet gives rather wide tolerances for these so integer
>> @@ -874,8 +902,18 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
>>  }
>>  
>>  /**
>> - * sca3000_write_value() control of threshold and period
>> - **/
>> + * sca3000_write_value() - control of threshold and period
>> + * @indio_dev: Device instance specific IIO information.
>> + * @chan: Description of the channel for which the event is being
>> + * configured.
>> + * @type: The type of event being configured, here magnitude rising
>> + * as everything else is read only.
>> + * @dir: Direction of the event (here rising)
>> + * @info: What information about the event are we configuring.
>> + * Here the threshold only.
>> + * @val: Integer part of the value being written..
>> + * @val2: Non integer part of the value being written. Here always 0.
>> + */
>>  static int sca3000_write_event_value(struct iio_dev *indio_dev,
>>  				     const struct iio_chan_spec *chan,
>>  				     enum iio_event_type type,
>> @@ -950,11 +988,10 @@ static int sca3000_read_data(struct sca3000_state *st,
>>  }
>>  
>>  /**
>> - * sca3000_ring_int_process() ring specific interrupt handling.
>> - *
>> - * This is only split from the main interrupt handler so as to
>> - * reduce the amount of code if the ring buffer is not enabled.
>> - **/
>> + * sca3000_ring_int_process() - ring specific interrupt handling.
>> + * @val: Value of the interrupt status register.
>> + * @indio_dev: Device instance specific IIO device structure.
>> + */
>>  static void sca3000_ring_int_process(u8 val, struct iio_dev *indio_dev)
>>  {
>>  	struct sca3000_state *st = iio_priv(indio_dev);
>> @@ -993,6 +1030,8 @@ error_ret:
>>  
>>  /**
>>   * sca3000_event_handler() - handling ring and non ring events
>> + * @irq: The irq being handled.
>> + * @private: struct iio_device pointer for the device.
>>   *
>>   * Ring related interrupt handler. Depending on event, push to
>>   * the ring buffer event chrdev or the event one.
>> @@ -1000,7 +1039,7 @@ error_ret:
>>   * This function is complicated by the fact that the devices can signify ring
>>   * and non ring events via the same interrupt line and they can only
>>   * be distinguished via a read of the relevant status register.
>> - **/
>> + */
>>  static irqreturn_t sca3000_event_handler(int irq, void *private)
>>  {
>>  	struct iio_dev *indio_dev = private;
>> @@ -1188,7 +1227,13 @@ static int sca3000_motion_detect_set_state(struct iio_dev *indio_dev, int axis,
>>  }
>>  
>>  /**
>> - * sca3000_write_event_config() simple on off control for motion detector
>> + * sca3000_write_event_config() - simple on off control for motion detector
>> + * @indio_dev: IIO device instance specific structure. Data specific to this
>> + * particular driver may be accessed via iio_priv(indio_dev).
>> + * @chan: Description of the channel whoes event we are configuring.
> 
> whose
> 
>> + * @type: The type of event.
>> + * @dir: The direction of the event.
>> + * @state: Desired state of event being configured.
>>   *
>>   * This is a per axis control, but enabling any will result in the
>>   * motion detector unit being enabled.
>> @@ -1272,12 +1317,14 @@ error_ret:
>>  }
>>  
>>  /**
>> - * sca3000_hw_ring_preenable() hw ring buffer preenable function
>> + * sca3000_hw_ring_preenable() - hw ring buffer preenable function
>> + * @indio_dev: structure representing the IIO device. Device instance
>> + * specific state can be accessed via iio_priv(indio_dev).
>>   *
>>   * Very simple enable function as the chip will allows normal reads
>>   * during ring buffer operation so as long as it is indeed running
>>   * before we notify the core, the precise ordering does not matter.
>> - **/
>> + */
>>  static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
>>  {
>>  	int ret;
>> @@ -1347,12 +1394,13 @@ static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
>>  };
>>  
>>  /**
>> - * sca3000_clean_setup() get the device into a predictable state
>> + * sca3000_clean_setup() - get the device into a predictable state
>> + * @st: Device instance specific private data structure
>>   *
>>   * Devices use flash memory to store many of the register values
>>   * and hence can come up in somewhat unpredictable states.
>>   * Hence reset everything on driver load.
>> - **/
>> + */
>>  static int sca3000_clean_setup(struct sca3000_state *st)
>>  {
>>  	int ret;
>>
> 


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

* Re: [PATCH 02/18] staging:iio:accel:sca3000 merge files into one.
  2016-10-03 19:26 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
@ 2016-10-04  8:46   ` Lars-Peter Clausen
  2016-10-04 12:29     ` Jonathan Cameron
  0 siblings, 1 reply; 28+ messages in thread
From: Lars-Peter Clausen @ 2016-10-04  8:46 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: knaack.h, pmeerw

On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
> In the early days of IIO we were much more inclined to keep the impact
> of the core IIO elements to the minimum.  As time has moved on it has
> become clear that hardly any builds are done without buffer support
> and that it adds considerable complexity to the drivers.
> 
> Hence merge down the buffer and non buffer elements of the sca3000 driver
> also allowing us to drop the header file used for the interfaces between
> the two.
> 
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/accel/Makefile                 |   3 +-
>  .../iio/accel/{sca3000_core.c => sca3000.c}        | 498 ++++++++++++++++++++-
>  drivers/staging/iio/accel/sca3000.h                | 279 ------------
>  drivers/staging/iio/accel/sca3000_ring.c           | 350 ---------------
>  4 files changed, 496 insertions(+), 634 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
> index 1810a434a755..6ab95708e696 100644
> --- a/drivers/staging/iio/accel/Makefile
> +++ b/drivers/staging/iio/accel/Makefile
> @@ -14,5 +14,4 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
>  adis16240-y             := adis16240_core.o
>  obj-$(CONFIG_ADIS16240) += adis16240.o
>  
> -sca3000-y		:= sca3000_core.o sca3000_ring.o
> -obj-$(CONFIG_SCA3000)	+= sca3000.o
> +obj-$(CONFIG_SCA3000)	:= sca3000.o

This is fixed when moving the driver out of staging, but using := instead of
+= here disables all other drivers that came before this one.

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

* Re: [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD
  2016-10-03 19:26 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Jonathan Cameron
@ 2016-10-04  8:52   ` Lars-Peter Clausen
  2016-10-08 16:59     ` Jonathan Cameron
  0 siblings, 1 reply; 28+ messages in thread
From: Lars-Peter Clausen @ 2016-10-04  8:52 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: knaack.h, pmeerw

On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
> Given the introduction of IIO_NO_MOD was prior to the first submission
> prior to IIO entering staging this has been broken for a while.
> 
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/accel/sca3000.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
> index 24685a2f224e..e8f43df65142 100644
> --- a/drivers/staging/iio/accel/sca3000.c
> +++ b/drivers/staging/iio/accel/sca3000.c
> @@ -933,16 +933,17 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
>  {
>  	int ret, i;
>  	struct sca3000_state *st = iio_priv(indio_dev);
> -	int num = chan->channel2;
> +
>  	switch (info) {
>  	case IIO_EV_INFO_VALUE:
>  		mutex_lock(&st->lock);
> -		ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
> +		ret = sca3000_read_ctrl_reg(st,
> +					    sca3000_addresses[chan->channel2 - IIO_MOD_X][1]);

How about using channel address? Same comment for similar cases later on.


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

* Re: [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan.
  2016-10-03 19:26 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
@ 2016-10-04  8:59   ` Lars-Peter Clausen
  2016-10-04 12:28     ` Jonathan Cameron
  0 siblings, 1 reply; 28+ messages in thread
From: Lars-Peter Clausen @ 2016-10-04  8:59 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio; +Cc: knaack.h, pmeerw

On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
> diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
> index 36a52d02ee0e..8af7d83e658d 100644
> --- a/drivers/staging/iio/accel/sca3000.c
> +++ b/drivers/staging/iio/accel/sca3000.c
> @@ -1491,6 +1491,19 @@ error_ret:
>   **/
>  static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
>  {
> +	/*
> +	 * Set stuff to read to indicate no data present.
> +	 * Need for cases where the interrupt had fired at the
> +	 * end of a cycle, but the data was never read.
> +	 */
> +	indio_dev->buffer->stufftoread = 0;
> +	/*
> +	 * Needed to ensure the core will actually read data
> +	 * from the device rather than assuming no channels
> +	 * are enabled.
> +	 */
> +	indio_dev->buffer->bytes_per_datum = 6;
> +

Shouldn't this be dropped again when switching to kfifo for the buffer?


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

* Re: [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan.
  2016-10-04  8:59   ` Lars-Peter Clausen
@ 2016-10-04 12:28     ` Jonathan Cameron
  0 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-04 12:28 UTC (permalink / raw)
  To: Lars-Peter Clausen, Jonathan Cameron, linux-iio; +Cc: knaack.h, pmeerw



On 4 October 2016 09:59:51 BST, Lars-Peter Clausen <lars@metafoo.de> wrote:
>On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
>> diff --git a/drivers/staging/iio/accel/sca3000.c
>b/drivers/staging/iio/accel/sca3000.c
>> index 36a52d02ee0e..8af7d83e658d 100644
>> --- a/drivers/staging/iio/accel/sca3000.c
>> +++ b/drivers/staging/iio/accel/sca3000.c
>> @@ -1491,6 +1491,19 @@ error_ret:
>>   **/
>>  static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
>>  {
>> +	/*
>> +	 * Set stuff to read to indicate no data present.
>> +	 * Need for cases where the interrupt had fired at the
>> +	 * end of a cycle, but the data was never read.
>> +	 */
>> +	indio_dev->buffer->stufftoread = 0;
>> +	/*
>> +	 * Needed to ensure the core will actually read data
>> +	 * from the device rather than assuming no channels
>> +	 * are enabled.
>> +	 */
>> +	indio_dev->buffer->bytes_per_datum = 6;
>> +
>
>Shouldn't this be dropped again when switching to kfifo for the buffer?
Good point...

J
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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

* Re: [PATCH 02/18] staging:iio:accel:sca3000 merge files into one.
  2016-10-04  8:46   ` Lars-Peter Clausen
@ 2016-10-04 12:29     ` Jonathan Cameron
  0 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-04 12:29 UTC (permalink / raw)
  To: Lars-Peter Clausen, Jonathan Cameron, linux-iio; +Cc: knaack.h, pmeerw



On 4 October 2016 09:46:02 BST, Lars-Peter Clausen <lars@metafoo.de> wrote:
>On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
>> In the early days of IIO we were much more inclined to keep the
>impact
>> of the core IIO elements to the minimum.  As time has moved on it has
>> become clear that hardly any builds are done without buffer support
>> and that it adds considerable complexity to the drivers.
>> 
>> Hence merge down the buffer and non buffer elements of the sca3000
>driver
>> also allowing us to drop the header file used for the interfaces
>between
>> the two.
>> 
>> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
>> ---
>>  drivers/staging/iio/accel/Makefile                 |   3 +-
>>  .../iio/accel/{sca3000_core.c => sca3000.c}        | 498
>++++++++++++++++++++-
>>  drivers/staging/iio/accel/sca3000.h                | 279
>------------
>>  drivers/staging/iio/accel/sca3000_ring.c           | 350
>---------------
>>  4 files changed, 496 insertions(+), 634 deletions(-)
>> 
>> diff --git a/drivers/staging/iio/accel/Makefile
>b/drivers/staging/iio/accel/Makefile
>> index 1810a434a755..6ab95708e696 100644
>> --- a/drivers/staging/iio/accel/Makefile
>> +++ b/drivers/staging/iio/accel/Makefile
>> @@ -14,5 +14,4 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
>>  adis16240-y             := adis16240_core.o
>>  obj-$(CONFIG_ADIS16240) += adis16240.o
>>  
>> -sca3000-y		:= sca3000_core.o sca3000_ring.o
>> -obj-$(CONFIG_SCA3000)	+= sca3000.o
>> +obj-$(CONFIG_SCA3000)	:= sca3000.o
>
>This is fixed when moving the driver out of staging, but using :=
>instead of
>+= here disables all other drivers that came before this one.
Gah. Will fix

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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

* Re: [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD
  2016-10-04  8:52   ` Lars-Peter Clausen
@ 2016-10-08 16:59     ` Jonathan Cameron
  0 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-08 16:59 UTC (permalink / raw)
  To: Lars-Peter Clausen, linux-iio; +Cc: knaack.h, pmeerw

On 04/10/16 09:52, Lars-Peter Clausen wrote:
> On 10/03/2016 09:26 PM, Jonathan Cameron wrote:
>> Given the introduction of IIO_NO_MOD was prior to the first submission
>> prior to IIO entering staging this has been broken for a while.
>>
>> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
>> ---
>>  drivers/staging/iio/accel/sca3000.c | 21 +++++++++++----------
>>  1 file changed, 11 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/staging/iio/accel/sca3000.c b/drivers/staging/iio/accel/sca3000.c
>> index 24685a2f224e..e8f43df65142 100644
>> --- a/drivers/staging/iio/accel/sca3000.c
>> +++ b/drivers/staging/iio/accel/sca3000.c
>> @@ -933,16 +933,17 @@ static int sca3000_read_event_value(struct iio_dev *indio_dev,
>>  {
>>  	int ret, i;
>>  	struct sca3000_state *st = iio_priv(indio_dev);
>> -	int num = chan->channel2;
>> +
>>  	switch (info) {
>>  	case IIO_EV_INFO_VALUE:
>>  		mutex_lock(&st->lock);
>> -		ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
>> +		ret = sca3000_read_ctrl_reg(st,
>> +					    sca3000_addresses[chan->channel2 - IIO_MOD_X][1]);
> 
> How about using channel address? Same comment for similar cases later on.
Good idea. done.
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

* [PATCH 02/18] staging:iio:accel:sca3000 merge files into one.
  2016-10-08 16:39 [PATCH 00/18 V2] staging:iio:accel rework driver and move " Jonathan Cameron
@ 2016-10-08 16:39 ` Jonathan Cameron
  0 siblings, 0 replies; 28+ messages in thread
From: Jonathan Cameron @ 2016-10-08 16:39 UTC (permalink / raw)
  To: linux-iio; +Cc: knaack.h, lars, pmeerw, Jonathan Cameron

In the early days of IIO we were much more inclined to keep the impact
of the core IIO elements to the minimum.  As time has moved on it has
become clear that hardly any builds are done without buffer support
and that it adds considerable complexity to the drivers.

Hence merge down the buffer and non buffer elements of the sca3000 driver
also allowing us to drop the header file used for the interfaces between
the two.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/Makefile                 |   1 -
 .../iio/accel/{sca3000_core.c => sca3000.c}        | 498 ++++++++++++++++++++-
 drivers/staging/iio/accel/sca3000.h                | 279 ------------
 drivers/staging/iio/accel/sca3000_ring.c           | 350 ---------------
 4 files changed, 495 insertions(+), 633 deletions(-)

diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
index 1810a434a755..1d49b6ab87ab 100644
--- a/drivers/staging/iio/accel/Makefile
+++ b/drivers/staging/iio/accel/Makefile
@@ -14,5 +14,4 @@ obj-$(CONFIG_ADIS16209) += adis16209.o
 adis16240-y             := adis16240_core.o
 obj-$(CONFIG_ADIS16240) += adis16240.o
 
-sca3000-y		:= sca3000_core.o sca3000_ring.o
 obj-$(CONFIG_SCA3000)	+= sca3000.o
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000.c
similarity index 69%
rename from drivers/staging/iio/accel/sca3000_core.c
rename to drivers/staging/iio/accel/sca3000.c
index 564b36d4f648..62ab1aef2528 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000.c
@@ -18,12 +18,189 @@
 #include <linux/spi/spi.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
+#include <linux/uaccess.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/events.h>
 #include <linux/iio/buffer.h>
+#include "../ring_hw.h"
 
-#include "sca3000.h"
+#define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
+#define SCA3000_READ_REG(a) ((a) << 2)
+
+#define SCA3000_REG_ADDR_REVID			0x00
+#define SCA3000_REVID_MAJOR_MASK		0xf0
+#define SCA3000_REVID_MINOR_MASK		0x0f
+
+#define SCA3000_REG_ADDR_STATUS			0x02
+#define SCA3000_LOCKED				0x20
+#define SCA3000_EEPROM_CS_ERROR			0x02
+#define SCA3000_SPI_FRAME_ERROR			0x01
+
+/* All reads done using register decrement so no need to directly access LSBs */
+#define SCA3000_REG_ADDR_X_MSB			0x05
+#define SCA3000_REG_ADDR_Y_MSB			0x07
+#define SCA3000_REG_ADDR_Z_MSB			0x09
+
+#define SCA3000_REG_ADDR_RING_OUT		0x0f
+
+/* Temp read untested - the e05 doesn't have the sensor */
+#define SCA3000_REG_ADDR_TEMP_MSB		0x13
+
+#define SCA3000_REG_ADDR_MODE			0x14
+#define SCA3000_MODE_PROT_MASK			0x28
+
+#define SCA3000_RING_BUF_ENABLE			0x80
+#define SCA3000_RING_BUF_8BIT			0x40
+/*
+ * Free fall detection triggers an interrupt if the acceleration
+ * is below a threshold for equivalent of 25cm drop
+ */
+#define SCA3000_FREE_FALL_DETECT		0x10
+#define SCA3000_MEAS_MODE_NORMAL		0x00
+#define SCA3000_MEAS_MODE_OP_1			0x01
+#define SCA3000_MEAS_MODE_OP_2			0x02
+
+/*
+ * In motion detection mode the accelerations are band pass filtered
+ * (approx 1 - 25Hz) and then a programmable threshold used to trigger
+ * and interrupt.
+ */
+#define SCA3000_MEAS_MODE_MOT_DET		0x03
+
+#define SCA3000_REG_ADDR_BUF_COUNT		0x15
+
+#define SCA3000_REG_ADDR_INT_STATUS		0x16
+
+#define SCA3000_INT_STATUS_THREE_QUARTERS	0x80
+#define SCA3000_INT_STATUS_HALF			0x40
+
+#define SCA3000_INT_STATUS_FREE_FALL		0x08
+#define SCA3000_INT_STATUS_Y_TRIGGER		0x04
+#define SCA3000_INT_STATUS_X_TRIGGER		0x02
+#define SCA3000_INT_STATUS_Z_TRIGGER		0x01
+
+/* Used to allow access to multiplexed registers */
+#define SCA3000_REG_ADDR_CTRL_SEL		0x18
+/* Only available for SCA3000-D03 and SCA3000-D01 */
+#define SCA3000_REG_CTRL_SEL_I2C_DISABLE	0x01
+#define SCA3000_REG_CTRL_SEL_MD_CTRL		0x02
+#define SCA3000_REG_CTRL_SEL_MD_Y_TH		0x03
+#define SCA3000_REG_CTRL_SEL_MD_X_TH		0x04
+#define SCA3000_REG_CTRL_SEL_MD_Z_TH		0x05
+/*
+ * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device
+ * will not function
+ */
+#define SCA3000_REG_CTRL_SEL_OUT_CTRL		0x0B
+#define SCA3000_OUT_CTRL_PROT_MASK		0xE0
+#define SCA3000_OUT_CTRL_BUF_X_EN		0x10
+#define SCA3000_OUT_CTRL_BUF_Y_EN		0x08
+#define SCA3000_OUT_CTRL_BUF_Z_EN		0x04
+#define SCA3000_OUT_CTRL_BUF_DIV_MASK		0x03
+#define SCA3000_OUT_CTRL_BUF_DIV_4		0x02
+#define SCA3000_OUT_CTRL_BUF_DIV_2		0x01
+
+/*
+ * Control which motion detector interrupts are on.
+ * For now only OR combinations are supported.
+ */
+#define SCA3000_MD_CTRL_PROT_MASK		0xC0
+#define SCA3000_MD_CTRL_OR_Y			0x01
+#define SCA3000_MD_CTRL_OR_X			0x02
+#define SCA3000_MD_CTRL_OR_Z			0x04
+/* Currently unsupported */
+#define SCA3000_MD_CTRL_AND_Y			0x08
+#define SCA3000_MD_CTRL_AND_X			0x10
+#define SAC3000_MD_CTRL_AND_Z			0x20
+
+/*
+ * Some control registers of complex access methods requiring this register to
+ * be used to remove a lock.
+ */
+#define SCA3000_REG_ADDR_UNLOCK			0x1e
+
+#define SCA3000_REG_ADDR_INT_MASK		0x21
+#define SCA3000_INT_MASK_PROT_MASK		0x1C
+
+#define SCA3000_INT_MASK_RING_THREE_QUARTER	0x80
+#define SCA3000_INT_MASK_RING_HALF		0x40
+
+#define SCA3000_INT_MASK_ALL_INTS		0x02
+#define SCA3000_INT_MASK_ACTIVE_HIGH		0x01
+#define SCA3000_INT_MASK_ACTIVE_LOW		0x00
+
+/* Values of multiplexed registers (write to ctrl_data after select) */
+#define SCA3000_REG_ADDR_CTRL_DATA		0x22
+
+/*
+ * Measurement modes available on some sca3000 series chips. Code assumes others
+ * may become available in the future.
+ *
+ * Bypass - Bypass the low-pass filter in the signal channel so as to increase
+ *          signal bandwidth.
+ *
+ * Narrow - Narrow low-pass filtering of the signal channel and half output
+ *          data rate by decimation.
+ *
+ * Wide - Widen low-pass filtering of signal channel to increase bandwidth
+ */
+#define SCA3000_OP_MODE_BYPASS			0x01
+#define SCA3000_OP_MODE_NARROW			0x02
+#define SCA3000_OP_MODE_WIDE			0x04
+#define SCA3000_MAX_TX 6
+#define SCA3000_MAX_RX 2
+
+/**
+ * struct sca3000_state - device instance state information
+ * @us:			the associated spi device
+ * @info:			chip variant information
+ * @interrupt_handler_ws:	event interrupt handler for all events
+ * @last_timestamp:		the timestamp of the last event
+ * @mo_det_use_count:		reference counter for the motion detection unit
+ * @lock:			lock used to protect elements of sca3000_state
+ *				and the underlying device state.
+ * @bpse:			number of bits per scan element
+ * @tx:			dma-able transmit buffer
+ * @rx:			dma-able receive buffer
+ **/
+struct sca3000_state {
+	struct spi_device		*us;
+	const struct sca3000_chip_info	*info;
+	struct work_struct		interrupt_handler_ws;
+	s64				last_timestamp;
+	int				mo_det_use_count;
+	struct mutex			lock;
+	int				bpse;
+	/* Can these share a cacheline ? */
+	u8				rx[2] ____cacheline_aligned;
+	u8				tx[6] ____cacheline_aligned;
+};
+
+/**
+ * struct sca3000_chip_info - model dependent parameters
+ * @scale:			scale * 10^-6
+ * @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
+ * @option_mode_1_freq:		option mode 1 sampling frequency
+ * @option_mode_2:		second optional mode. Not all chips have one
+ * @option_mode_2_freq:		option mode 2 sampling frequency
+ *
+ * This structure is used to hold information about the functionality of a given
+ * sca3000 variant.
+ **/
+struct sca3000_chip_info {
+	unsigned int		scale;
+	bool			temp_output;
+	int			measurement_mode_freq;
+	int			option_mode_1;
+	int			option_mode_1_freq;
+	int			option_mode_2;
+	int			option_mode_2_freq;
+	int			mot_det_mult_xz[6];
+	int			mot_det_mult_y[7];
+};
 
 enum sca3000_variant {
 	d01,
@@ -80,14 +257,14 @@ static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = {
 	},
 };
 
-int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
+static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
 {
 	st->tx[0] = SCA3000_WRITE_REG(address);
 	st->tx[1] = val;
 	return spi_write(st->us, st->tx, 2);
 }
 
-int sca3000_read_data_short(struct sca3000_state *st,
+static int sca3000_read_data_short(struct sca3000_state *st,
 			    u8 reg_address_high,
 			    int len)
 {
@@ -759,6 +936,21 @@ static const struct attribute_group sca3000_attribute_group = {
 };
 
 /**
+ * sca3000_ring_int_process() ring specific interrupt handling.
+ *
+ * This is only split from the main interrupt handler so as to
+ * reduce the amount of code if the ring buffer is not enabled.
+ **/
+static void sca3000_ring_int_process(u8 val, struct iio_buffer *ring)
+{
+	if (val & (SCA3000_INT_STATUS_THREE_QUARTERS |
+		   SCA3000_INT_STATUS_HALF)) {
+		ring->stufftoread = true;
+		wake_up_interruptible(&ring->pollq);
+	}
+}
+
+/**
  * sca3000_event_handler() - handling ring and non ring events
  *
  * Ring related interrupt handler. Depending on event, push to
@@ -1017,6 +1209,306 @@ static struct attribute_group sca3000_event_attribute_group = {
 	.name = "events",
 };
 
+static int sca3000_read_data(struct sca3000_state *st,
+			     u8 reg_address_high,
+			     u8 **rx_p,
+			     int len)
+{
+	int ret;
+	struct spi_transfer xfer[2] = {
+		{
+			.len = 1,
+			.tx_buf = st->tx,
+		}, {
+			.len = len,
+		}
+	};
+	*rx_p = kmalloc(len, GFP_KERNEL);
+	if (!*rx_p) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+	xfer[1].rx_buf = *rx_p;
+	st->tx[0] = SCA3000_READ_REG(reg_address_high);
+	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
+	if (ret) {
+		dev_err(get_device(&st->us->dev), "problem reading register");
+		goto error_free_rx;
+	}
+
+	return 0;
+error_free_rx:
+	kfree(*rx_p);
+error_ret:
+	return ret;
+}
+
+/**
+ * sca3000_read_first_n_hw_rb() - main ring access, pulls data from ring
+ * @r:			the ring
+ * @count:		number of samples to try and pull
+ * @data:		output the actual samples pulled from the hw ring
+ *
+ * Currently does not provide timestamps.  As the hardware doesn't add them they
+ * can only be inferred approximately from ring buffer events such as 50% full
+ * and knowledge of when buffer was last emptied.  This is left to userspace.
+ **/
+static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
+				      size_t count, char __user *buf)
+{
+	struct iio_hw_buffer *hw_ring = iio_to_hw_buf(r);
+	struct iio_dev *indio_dev = hw_ring->private;
+	struct sca3000_state *st = iio_priv(indio_dev);
+	u8 *rx;
+	int ret, i, num_available, num_read = 0;
+	int bytes_per_sample = 1;
+
+	if (st->bpse == 11)
+		bytes_per_sample = 2;
+
+	mutex_lock(&st->lock);
+	if (count % bytes_per_sample) {
+		ret = -EINVAL;
+		goto error_ret;
+	}
+
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT, 1);
+	if (ret)
+		goto error_ret;
+	num_available = st->rx[0];
+	/*
+	 * num_available is the total number of samples available
+	 * i.e. number of time points * number of channels.
+	 */
+	if (count > num_available * bytes_per_sample)
+		num_read = num_available * bytes_per_sample;
+	else
+		num_read = count;
+
+	ret = sca3000_read_data(st,
+				SCA3000_REG_ADDR_RING_OUT,
+				&rx, num_read);
+	if (ret)
+		goto error_ret;
+
+	for (i = 0; i < num_read / sizeof(u16); i++)
+		*(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
+
+	if (copy_to_user(buf, rx, num_read))
+		ret = -EFAULT;
+	kfree(rx);
+	r->stufftoread = 0;
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret ? ret : num_read;
+}
+
+static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
+{
+	return r->stufftoread ? r->watermark : 0;
+}
+
+/**
+ * sca3000_query_ring_int() is the hardware ring status interrupt enabled
+ **/
+static ssize_t sca3000_query_ring_int(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int ret, val;
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+
+	mutex_lock(&st->lock);
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	val = st->rx[0];
+	mutex_unlock(&st->lock);
+	if (ret)
+		return ret;
+
+	return sprintf(buf, "%d\n", !!(val & this_attr->address));
+}
+
+/**
+ * sca3000_set_ring_int() set state of ring status interrupt
+ **/
+static ssize_t sca3000_set_ring_int(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf,
+				    size_t len)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	u8 val;
+	int ret;
+
+	mutex_lock(&st->lock);
+	ret = kstrtou8(buf, 10, &val);
+	if (ret)
+		goto error_ret;
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
+	if (ret)
+		goto error_ret;
+	if (val)
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_INT_MASK,
+					st->rx[0] | this_attr->address);
+	else
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_INT_MASK,
+					st->rx[0] & ~this_attr->address);
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret ? ret : len;
+}
+
+static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR,
+		       sca3000_query_ring_int,
+		       sca3000_set_ring_int,
+		       SCA3000_INT_MASK_RING_HALF);
+
+static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR,
+		       sca3000_query_ring_int,
+		       sca3000_set_ring_int,
+		       SCA3000_INT_MASK_RING_THREE_QUARTER);
+
+static ssize_t sca3000_show_buffer_scale(struct device *dev,
+					 struct device_attribute *attr,
+					 char *buf)
+{
+	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct sca3000_state *st = iio_priv(indio_dev);
+
+	return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
+}
+
+static IIO_DEVICE_ATTR(in_accel_scale,
+		       S_IRUGO,
+		       sca3000_show_buffer_scale,
+		       NULL,
+		       0);
+
+/*
+ * Ring buffer attributes
+ * This device is a bit unusual in that the sampling frequency and bpse
+ * only apply to the ring buffer.  At all times full rate and accuracy
+ * is available via direct reading from registers.
+ */
+static const struct attribute *sca3000_ring_attributes[] = {
+	&iio_dev_attr_50_percent.dev_attr.attr,
+	&iio_dev_attr_75_percent.dev_attr.attr,
+	&iio_dev_attr_in_accel_scale.dev_attr.attr,
+	NULL,
+};
+
+static struct iio_buffer *sca3000_rb_allocate(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buf;
+	struct iio_hw_buffer *ring;
+
+	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
+	if (!ring)
+		return NULL;
+
+	ring->private = indio_dev;
+	buf = &ring->buf;
+	buf->stufftoread = 0;
+	buf->length = 64;
+	buf->attrs = sca3000_ring_attributes;
+	iio_buffer_init(buf);
+
+	return buf;
+}
+
+static void sca3000_ring_release(struct iio_buffer *r)
+{
+	kfree(iio_to_hw_buf(r));
+}
+
+static const struct iio_buffer_access_funcs sca3000_ring_access_funcs = {
+	.read_first_n = &sca3000_read_first_n_hw_rb,
+	.data_available = sca3000_ring_buf_data_available,
+	.release = sca3000_ring_release,
+
+	.modes = INDIO_BUFFER_HARDWARE,
+};
+
+static int sca3000_configure_ring(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer;
+
+	buffer = sca3000_rb_allocate(indio_dev);
+	if (!buffer)
+		return -ENOMEM;
+	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
+
+	buffer->access = &sca3000_ring_access_funcs;
+	iio_device_attach_buffer(indio_dev, buffer);
+
+	return 0;
+}
+
+static void sca3000_unconfigure_ring(struct iio_dev *indio_dev)
+{
+	iio_buffer_put(indio_dev->buffer);
+}
+
+static inline
+int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
+{
+	struct sca3000_state *st = iio_priv(indio_dev);
+	int ret;
+
+	mutex_lock(&st->lock);
+	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
+	if (ret)
+		goto error_ret;
+	if (state) {
+		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_MODE,
+					(st->rx[0] | SCA3000_RING_BUF_ENABLE));
+	} else
+		ret = sca3000_write_reg(st,
+					SCA3000_REG_ADDR_MODE,
+					(st->rx[0] & ~SCA3000_RING_BUF_ENABLE));
+error_ret:
+	mutex_unlock(&st->lock);
+
+	return ret;
+}
+
+/**
+ * sca3000_hw_ring_preenable() hw ring buffer preenable function
+ *
+ * Very simple enable function as the chip will allows normal reads
+ * during ring buffer operation so as long as it is indeed running
+ * before we notify the core, the precise ordering does not matter.
+ **/
+static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
+{
+	return __sca3000_hw_ring_state_set(indio_dev, 1);
+}
+
+static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
+{
+	return __sca3000_hw_ring_state_set(indio_dev, 0);
+}
+
+static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
+	.preenable = &sca3000_hw_ring_preenable,
+	.postdisable = &sca3000_hw_ring_postdisable,
+};
+
+static void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
+{
+	indio_dev->setup_ops = &sca3000_ring_setup_ops;
+}
+
 /**
  * sca3000_clean_setup() get the device into a predictable state
  *
diff --git a/drivers/staging/iio/accel/sca3000.h b/drivers/staging/iio/accel/sca3000.h
deleted file mode 100644
index 4dcc8575cbe3..000000000000
--- a/drivers/staging/iio/accel/sca3000.h
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * sca3000.c -- support VTI sca3000 series accelerometers
- *              via SPI
- *
- * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org>
- *
- * Partly based upon tle62x0.c
- *
- * 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.
- *
- * Initial mode is direct measurement.
- *
- * Untested things
- *
- * Temperature reading (the e05 I'm testing with doesn't have a sensor)
- *
- * Free fall detection mode - supported but untested as I'm not droping my
- * dubious wire rig far enough to test it.
- *
- * Unsupported as yet
- *
- * Time stamping of data from ring. Various ideas on how to do this but none
- * are remotely simple. Suggestions welcome.
- *
- * Individual enabling disabling of channels going into ring buffer
- *
- * Overflow handling (this is signaled for all but 8 bit ring buffer mode.)
- *
- * Motion detector using AND combinations of signals.
- *
- * Note: Be very careful about not touching an register bytes marked
- * as reserved on the data sheet. They really mean it as changing convents of
- * some will cause the device to lock up.
- *
- * Known issues - on rare occasions the interrupts lock up. Not sure why as yet.
- * Can probably alleviate this by reading the interrupt register on start, but
- * that is really just brushing the problem under the carpet.
- */
-#ifndef _SCA3000
-#define _SCA3000
-
-#define SCA3000_WRITE_REG(a) (((a) << 2) | 0x02)
-#define SCA3000_READ_REG(a) ((a) << 2)
-
-#define SCA3000_REG_ADDR_REVID			0x00
-#define SCA3000_REVID_MAJOR_MASK		0xf0
-#define SCA3000_REVID_MINOR_MASK		0x0f
-
-#define SCA3000_REG_ADDR_STATUS			0x02
-#define SCA3000_LOCKED				0x20
-#define SCA3000_EEPROM_CS_ERROR			0x02
-#define SCA3000_SPI_FRAME_ERROR			0x01
-
-/* All reads done using register decrement so no need to directly access LSBs */
-#define SCA3000_REG_ADDR_X_MSB			0x05
-#define SCA3000_REG_ADDR_Y_MSB			0x07
-#define SCA3000_REG_ADDR_Z_MSB			0x09
-
-#define SCA3000_REG_ADDR_RING_OUT		0x0f
-
-/* Temp read untested - the e05 doesn't have the sensor */
-#define SCA3000_REG_ADDR_TEMP_MSB		0x13
-
-#define SCA3000_REG_ADDR_MODE			0x14
-#define SCA3000_MODE_PROT_MASK			0x28
-
-#define SCA3000_RING_BUF_ENABLE			0x80
-#define SCA3000_RING_BUF_8BIT			0x40
-/*
- * Free fall detection triggers an interrupt if the acceleration
- * is below a threshold for equivalent of 25cm drop
- */
-#define SCA3000_FREE_FALL_DETECT		0x10
-#define SCA3000_MEAS_MODE_NORMAL		0x00
-#define SCA3000_MEAS_MODE_OP_1			0x01
-#define SCA3000_MEAS_MODE_OP_2			0x02
-
-/*
- * In motion detection mode the accelerations are band pass filtered
- * (approx 1 - 25Hz) and then a programmable threshold used to trigger
- * and interrupt.
- */
-#define SCA3000_MEAS_MODE_MOT_DET		0x03
-
-#define SCA3000_REG_ADDR_BUF_COUNT		0x15
-
-#define SCA3000_REG_ADDR_INT_STATUS		0x16
-
-#define SCA3000_INT_STATUS_THREE_QUARTERS	0x80
-#define SCA3000_INT_STATUS_HALF			0x40
-
-#define SCA3000_INT_STATUS_FREE_FALL		0x08
-#define SCA3000_INT_STATUS_Y_TRIGGER		0x04
-#define SCA3000_INT_STATUS_X_TRIGGER		0x02
-#define SCA3000_INT_STATUS_Z_TRIGGER		0x01
-
-/* Used to allow access to multiplexed registers */
-#define SCA3000_REG_ADDR_CTRL_SEL		0x18
-/* Only available for SCA3000-D03 and SCA3000-D01 */
-#define SCA3000_REG_CTRL_SEL_I2C_DISABLE	0x01
-#define SCA3000_REG_CTRL_SEL_MD_CTRL		0x02
-#define SCA3000_REG_CTRL_SEL_MD_Y_TH		0x03
-#define SCA3000_REG_CTRL_SEL_MD_X_TH		0x04
-#define SCA3000_REG_CTRL_SEL_MD_Z_TH		0x05
-/*
- * BE VERY CAREFUL WITH THIS, IF 3 BITS ARE NOT SET the device
- * will not function
- */
-#define SCA3000_REG_CTRL_SEL_OUT_CTRL		0x0B
-#define SCA3000_OUT_CTRL_PROT_MASK		0xE0
-#define SCA3000_OUT_CTRL_BUF_X_EN		0x10
-#define SCA3000_OUT_CTRL_BUF_Y_EN		0x08
-#define SCA3000_OUT_CTRL_BUF_Z_EN		0x04
-#define SCA3000_OUT_CTRL_BUF_DIV_MASK		0x03
-#define SCA3000_OUT_CTRL_BUF_DIV_4		0x02
-#define SCA3000_OUT_CTRL_BUF_DIV_2		0x01
-
-/*
- * Control which motion detector interrupts are on.
- * For now only OR combinations are supported.
- */
-#define SCA3000_MD_CTRL_PROT_MASK		0xC0
-#define SCA3000_MD_CTRL_OR_Y			0x01
-#define SCA3000_MD_CTRL_OR_X			0x02
-#define SCA3000_MD_CTRL_OR_Z			0x04
-/* Currently unsupported */
-#define SCA3000_MD_CTRL_AND_Y			0x08
-#define SCA3000_MD_CTRL_AND_X			0x10
-#define SAC3000_MD_CTRL_AND_Z			0x20
-
-/*
- * Some control registers of complex access methods requiring this register to
- * be used to remove a lock.
- */
-#define SCA3000_REG_ADDR_UNLOCK			0x1e
-
-#define SCA3000_REG_ADDR_INT_MASK		0x21
-#define SCA3000_INT_MASK_PROT_MASK		0x1C
-
-#define SCA3000_INT_MASK_RING_THREE_QUARTER	0x80
-#define SCA3000_INT_MASK_RING_HALF		0x40
-
-#define SCA3000_INT_MASK_ALL_INTS		0x02
-#define SCA3000_INT_MASK_ACTIVE_HIGH		0x01
-#define SCA3000_INT_MASK_ACTIVE_LOW		0x00
-
-/* Values of multiplexed registers (write to ctrl_data after select) */
-#define SCA3000_REG_ADDR_CTRL_DATA		0x22
-
-/*
- * Measurement modes available on some sca3000 series chips. Code assumes others
- * may become available in the future.
- *
- * Bypass - Bypass the low-pass filter in the signal channel so as to increase
- *          signal bandwidth.
- *
- * Narrow - Narrow low-pass filtering of the signal channel and half output
- *          data rate by decimation.
- *
- * Wide - Widen low-pass filtering of signal channel to increase bandwidth
- */
-#define SCA3000_OP_MODE_BYPASS			0x01
-#define SCA3000_OP_MODE_NARROW			0x02
-#define SCA3000_OP_MODE_WIDE			0x04
-#define SCA3000_MAX_TX 6
-#define SCA3000_MAX_RX 2
-
-/**
- * struct sca3000_state - device instance state information
- * @us:			the associated spi device
- * @info:			chip variant information
- * @interrupt_handler_ws:	event interrupt handler for all events
- * @last_timestamp:		the timestamp of the last event
- * @mo_det_use_count:		reference counter for the motion detection unit
- * @lock:			lock used to protect elements of sca3000_state
- *				and the underlying device state.
- * @bpse:			number of bits per scan element
- * @tx:			dma-able transmit buffer
- * @rx:			dma-able receive buffer
- **/
-struct sca3000_state {
-	struct spi_device		*us;
-	const struct sca3000_chip_info	*info;
-	struct work_struct		interrupt_handler_ws;
-	s64				last_timestamp;
-	int				mo_det_use_count;
-	struct mutex			lock;
-	int				bpse;
-	/* Can these share a cacheline ? */
-	u8				rx[2] ____cacheline_aligned;
-	u8				tx[6] ____cacheline_aligned;
-};
-
-/**
- * struct sca3000_chip_info - model dependent parameters
- * @scale:			scale * 10^-6
- * @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
- * @option_mode_1_freq:		option mode 1 sampling frequency
- * @option_mode_2:		second optional mode. Not all chips have one
- * @option_mode_2_freq:		option mode 2 sampling frequency
- *
- * This structure is used to hold information about the functionality of a given
- * sca3000 variant.
- **/
-struct sca3000_chip_info {
-	unsigned int		scale;
-	bool			temp_output;
-	int			measurement_mode_freq;
-	int			option_mode_1;
-	int			option_mode_1_freq;
-	int			option_mode_2;
-	int			option_mode_2_freq;
-	int			mot_det_mult_xz[6];
-	int			mot_det_mult_y[7];
-};
-
-int sca3000_read_data_short(struct sca3000_state *st,
-			    u8 reg_address_high,
-			    int len);
-
-/**
- * sca3000_write_reg() write a single register
- * @address:	address of register on chip
- * @val:	value to be written to register
- *
- * The main lock must be held.
- **/
-int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val);
-
-#ifdef CONFIG_IIO_BUFFER
-/**
- * sca3000_register_ring_funcs() setup the ring state change functions
- **/
-void sca3000_register_ring_funcs(struct iio_dev *indio_dev);
-
-/**
- * sca3000_configure_ring() - allocate and configure ring buffer
- * @indio_dev: iio-core device whose ring is to be configured
- *
- * The hardware ring buffer needs far fewer ring buffer functions than
- * a software one as a lot of things are handled automatically.
- * This function also tells the iio core that our device supports a
- * hardware ring buffer mode.
- **/
-int sca3000_configure_ring(struct iio_dev *indio_dev);
-
-/**
- * sca3000_unconfigure_ring() - deallocate the ring buffer
- * @indio_dev: iio-core device whose ring we are freeing
- **/
-void sca3000_unconfigure_ring(struct iio_dev *indio_dev);
-
-/**
- * sca3000_ring_int_process() handles ring related event pushing and escalation
- * @val:	the event code
- **/
-void sca3000_ring_int_process(u8 val, struct iio_buffer *ring);
-
-#else
-static inline void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
-{
-}
-
-static inline
-int sca3000_register_ring_access_and_init(struct iio_dev *indio_dev)
-{
-	return 0;
-}
-
-static inline void sca3000_ring_int_process(u8 val, void *ring)
-{
-}
-
-#endif
-#endif /* _SCA3000 */
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
deleted file mode 100644
index e5de52d05a5c..000000000000
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * sca3000_ring.c -- support VTI sca3000 series accelerometers via SPI
- *
- * 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.
- *
- * Copyright (c) 2009 Jonathan Cameron <jic23@kernel.org>
- *
- */
-
-#include <linux/interrupt.h>
-#include <linux/fs.h>
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/spi/spi.h>
-#include <linux/sysfs.h>
-#include <linux/sched.h>
-#include <linux/poll.h>
-
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/buffer.h>
-#include "../ring_hw.h"
-#include "sca3000.h"
-
-/* RFC / future work
- *
- * The internal ring buffer doesn't actually change what it holds depending
- * on which signals are enabled etc, merely whether you can read them.
- * As such the scan mode selection is somewhat different than for a software
- * ring buffer and changing it actually covers any data already in the buffer.
- * Currently scan elements aren't configured so it doesn't matter.
- */
-
-static int sca3000_read_data(struct sca3000_state *st,
-			     u8 reg_address_high,
-			     u8 **rx_p,
-			     int len)
-{
-	int ret;
-	struct spi_transfer xfer[2] = {
-		{
-			.len = 1,
-			.tx_buf = st->tx,
-		}, {
-			.len = len,
-		}
-	};
-	*rx_p = kmalloc(len, GFP_KERNEL);
-	if (!*rx_p) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	xfer[1].rx_buf = *rx_p;
-	st->tx[0] = SCA3000_READ_REG(reg_address_high);
-	ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
-	if (ret) {
-		dev_err(get_device(&st->us->dev), "problem reading register");
-		goto error_free_rx;
-	}
-
-	return 0;
-error_free_rx:
-	kfree(*rx_p);
-error_ret:
-	return ret;
-}
-
-/**
- * sca3000_read_first_n_hw_rb() - main ring access, pulls data from ring
- * @r:			the ring
- * @count:		number of samples to try and pull
- * @data:		output the actual samples pulled from the hw ring
- *
- * Currently does not provide timestamps.  As the hardware doesn't add them they
- * can only be inferred approximately from ring buffer events such as 50% full
- * and knowledge of when buffer was last emptied.  This is left to userspace.
- **/
-static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
-				      size_t count, char __user *buf)
-{
-	struct iio_hw_buffer *hw_ring = iio_to_hw_buf(r);
-	struct iio_dev *indio_dev = hw_ring->private;
-	struct sca3000_state *st = iio_priv(indio_dev);
-	u8 *rx;
-	int ret, i, num_available, num_read = 0;
-	int bytes_per_sample = 1;
-
-	if (st->bpse == 11)
-		bytes_per_sample = 2;
-
-	mutex_lock(&st->lock);
-	if (count % bytes_per_sample) {
-		ret = -EINVAL;
-		goto error_ret;
-	}
-
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_BUF_COUNT, 1);
-	if (ret)
-		goto error_ret;
-	num_available = st->rx[0];
-	/*
-	 * num_available is the total number of samples available
-	 * i.e. number of time points * number of channels.
-	 */
-	if (count > num_available * bytes_per_sample)
-		num_read = num_available * bytes_per_sample;
-	else
-		num_read = count;
-
-	ret = sca3000_read_data(st,
-				SCA3000_REG_ADDR_RING_OUT,
-				&rx, num_read);
-	if (ret)
-		goto error_ret;
-
-	for (i = 0; i < num_read / sizeof(u16); i++)
-		*(((u16 *)rx) + i) = be16_to_cpup((__be16 *)rx + i);
-
-	if (copy_to_user(buf, rx, num_read))
-		ret = -EFAULT;
-	kfree(rx);
-	r->stufftoread = 0;
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : num_read;
-}
-
-static size_t sca3000_ring_buf_data_available(struct iio_buffer *r)
-{
-	return r->stufftoread ? r->watermark : 0;
-}
-
-/**
- * sca3000_query_ring_int() is the hardware ring status interrupt enabled
- **/
-static ssize_t sca3000_query_ring_int(struct device *dev,
-				      struct device_attribute *attr,
-				      char *buf)
-{
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	int ret, val;
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	val = st->rx[0];
-	mutex_unlock(&st->lock);
-	if (ret)
-		return ret;
-
-	return sprintf(buf, "%d\n", !!(val & this_attr->address));
-}
-
-/**
- * sca3000_set_ring_int() set state of ring status interrupt
- **/
-static ssize_t sca3000_set_ring_int(struct device *dev,
-				    struct device_attribute *attr,
-				    const char *buf,
-				    size_t len)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
-	u8 val;
-	int ret;
-
-	mutex_lock(&st->lock);
-	ret = kstrtou8(buf, 10, &val);
-	if (ret)
-		goto error_ret;
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
-	if (ret)
-		goto error_ret;
-	if (val)
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] | this_attr->address);
-	else
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_INT_MASK,
-					st->rx[0] & ~this_attr->address);
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret ? ret : len;
-}
-
-static IIO_DEVICE_ATTR(50_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_HALF);
-
-static IIO_DEVICE_ATTR(75_percent, S_IRUGO | S_IWUSR,
-		       sca3000_query_ring_int,
-		       sca3000_set_ring_int,
-		       SCA3000_INT_MASK_RING_THREE_QUARTER);
-
-static ssize_t sca3000_show_buffer_scale(struct device *dev,
-					 struct device_attribute *attr,
-					 char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct sca3000_state *st = iio_priv(indio_dev);
-
-	return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
-}
-
-static IIO_DEVICE_ATTR(in_accel_scale,
-		       S_IRUGO,
-		       sca3000_show_buffer_scale,
-		       NULL,
-		       0);
-
-/*
- * Ring buffer attributes
- * This device is a bit unusual in that the sampling frequency and bpse
- * only apply to the ring buffer.  At all times full rate and accuracy
- * is available via direct reading from registers.
- */
-static const struct attribute *sca3000_ring_attributes[] = {
-	&iio_dev_attr_50_percent.dev_attr.attr,
-	&iio_dev_attr_75_percent.dev_attr.attr,
-	&iio_dev_attr_in_accel_scale.dev_attr.attr,
-	NULL,
-};
-
-static struct iio_buffer *sca3000_rb_allocate(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buf;
-	struct iio_hw_buffer *ring;
-
-	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
-	if (!ring)
-		return NULL;
-
-	ring->private = indio_dev;
-	buf = &ring->buf;
-	buf->stufftoread = 0;
-	buf->length = 64;
-	buf->attrs = sca3000_ring_attributes;
-	iio_buffer_init(buf);
-
-	return buf;
-}
-
-static void sca3000_ring_release(struct iio_buffer *r)
-{
-	kfree(iio_to_hw_buf(r));
-}
-
-static const struct iio_buffer_access_funcs sca3000_ring_access_funcs = {
-	.read_first_n = &sca3000_read_first_n_hw_rb,
-	.data_available = sca3000_ring_buf_data_available,
-	.release = sca3000_ring_release,
-
-	.modes = INDIO_BUFFER_HARDWARE,
-};
-
-int sca3000_configure_ring(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buffer;
-
-	buffer = sca3000_rb_allocate(indio_dev);
-	if (!buffer)
-		return -ENOMEM;
-	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
-
-
-	buffer->access = &sca3000_ring_access_funcs;
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	return 0;
-}
-
-void sca3000_unconfigure_ring(struct iio_dev *indio_dev)
-{
-	iio_buffer_put(indio_dev->buffer);
-}
-
-static inline
-int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
-{
-	struct sca3000_state *st = iio_priv(indio_dev);
-	int ret;
-
-	mutex_lock(&st->lock);
-	ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
-	if (ret)
-		goto error_ret;
-	if (state) {
-		dev_info(&indio_dev->dev, "supposedly enabling ring buffer\n");
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] | SCA3000_RING_BUF_ENABLE));
-	} else
-		ret = sca3000_write_reg(st,
-					SCA3000_REG_ADDR_MODE,
-					(st->rx[0] & ~SCA3000_RING_BUF_ENABLE));
-error_ret:
-	mutex_unlock(&st->lock);
-
-	return ret;
-}
-
-/**
- * sca3000_hw_ring_preenable() hw ring buffer preenable function
- *
- * Very simple enable function as the chip will allows normal reads
- * during ring buffer operation so as long as it is indeed running
- * before we notify the core, the precise ordering does not matter.
- **/
-static int sca3000_hw_ring_preenable(struct iio_dev *indio_dev)
-{
-	return __sca3000_hw_ring_state_set(indio_dev, 1);
-}
-
-static int sca3000_hw_ring_postdisable(struct iio_dev *indio_dev)
-{
-	return __sca3000_hw_ring_state_set(indio_dev, 0);
-}
-
-static const struct iio_buffer_setup_ops sca3000_ring_setup_ops = {
-	.preenable = &sca3000_hw_ring_preenable,
-	.postdisable = &sca3000_hw_ring_postdisable,
-};
-
-void sca3000_register_ring_funcs(struct iio_dev *indio_dev)
-{
-	indio_dev->setup_ops = &sca3000_ring_setup_ops;
-}
-
-/**
- * sca3000_ring_int_process() ring specific interrupt handling.
- *
- * This is only split from the main interrupt handler so as to
- * reduce the amount of code if the ring buffer is not enabled.
- **/
-void sca3000_ring_int_process(u8 val, struct iio_buffer *ring)
-{
-	if (val & (SCA3000_INT_STATUS_THREE_QUARTERS |
-		   SCA3000_INT_STATUS_HALF)) {
-		ring->stufftoread = true;
-		wake_up_interruptible(&ring->pollq);
-	}
-}
-- 
2.10.0


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

end of thread, other threads:[~2016-10-08 17:06 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-03 19:26 [PATCH 00/18] staging:iio:accel rework driver and move out of staging Jonathan Cameron
2016-10-03 19:26 ` [PATCH 01/18] staging:iio:accel:sca3000 Fix a use before setting of the indio_dev->buffer pointer Jonathan Cameron
2016-10-03 19:26 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one Jonathan Cameron
2016-10-04  8:46   ` Lars-Peter Clausen
2016-10-04 12:29     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 03/18] staging:iio:accel:sca3000 drop sca3000_register_ring_funcs Jonathan Cameron
2016-10-03 19:26 ` [PATCH 04/18] staging:iio:accel:sca3000 Fix clearing of flag + setting of size of scan Jonathan Cameron
2016-10-04  8:59   ` Lars-Peter Clausen
2016-10-04 12:28     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 05/18] staging:iio:accel:sca3000 Drop custom ABI for watersheds Jonathan Cameron
2016-10-03 19:26 ` [PATCH 06/18] staging:iio:accel:sca3000 move to hybrid hard / soft buffer design Jonathan Cameron
2016-10-03 19:26 ` [PATCH 07/18] staging:iio:accel:sca3000 drop some unused variables Jonathan Cameron
2016-10-03 19:26 ` [PATCH 08/18] staging:iio:accel:sca3000 use a 'fake' channel to handle freefall event registration Jonathan Cameron
2016-10-03 19:26 ` [PATCH 09/18] staging:iio:accel:sca3000 Clean up register defines Jonathan Cameron
2016-10-03 19:26 ` [PATCH 10/18] staging:iio:accel:sca3000 add readback of the 3db low pass filter frequency Jonathan Cameron
2016-10-03 19:26 ` [PATCH 11/18] staging:iio:accel:sca3000: Fix off by one error in axis due to IIO_NO_MOD Jonathan Cameron
2016-10-04  8:52   ` Lars-Peter Clausen
2016-10-08 16:59     ` Jonathan Cameron
2016-10-03 19:26 ` [PATCH 12/18] staging:iio:accel:sca3000 Add write support to the low pass filter control Jonathan Cameron
2016-10-03 19:26 ` [PATCH 13/18] staging:iio:accel:sca3000 Drop custom measurement mode attributes Jonathan Cameron
2016-10-03 19:26 ` [PATCH 14/18] staging:iio:accel:sca3000 replace non standard revision attr with dev_info on probe Jonathan Cameron
2016-10-03 19:26 ` [PATCH 15/18] staging:iio:accel:sca3000 Tidy up probe order to avoid a race Jonathan Cameron
2016-10-03 19:27 ` [PATCH 16/18] staging:iio:accel:sca3000 small checkpatch fixes (alignment etc) Jonathan Cameron
2016-10-03 19:27 ` [PATCH 17/18] staging:iio:accel:sca3000 kernel docify comments that were nearly kernel doc Jonathan Cameron
2016-10-03 20:07   ` Peter Meerwald-Stadler
2016-10-03 20:27     ` Jonathan Cameron
2016-10-03 19:27 ` [PATCH 18/18] staging:iio:accel:sca3000 Move out of staging Jonathan Cameron
2016-10-08 16:39 [PATCH 00/18 V2] staging:iio:accel rework driver and move " Jonathan Cameron
2016-10-08 16:39 ` [PATCH 02/18] staging:iio:accel:sca3000 merge files into one 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.