All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add IIO support for counter devices
@ 2016-09-07 17:55 William Breathitt Gray
  2016-09-07 17:55 ` [PATCH 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
  2016-09-07 17:55 ` [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray
  0 siblings, 2 replies; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-07 17:55 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: linux-iio, linux-kernel, William Breathitt Gray

This patchset adds new IIO channel type and info constants to facilitate
support for counter devices. In addition, a new "counter" subdirectory
is created to house drivers for these counter devices.

Quadrature encoders, such as rotary encoders and linear encoders, are
devices which are capable of encoding the relative position and
direction of motion of a shaft. The following IIO enumeration constants
are introduced to support quadrature encoder counter devices.

  IIO_COUNT: Current count (main data provided by the counter device)

  IIO_CHAN_INFO_FLAGS: Counter flag states (e.g. underflows, overflows,
                       errors, etc.)
  IIO_CHAN_INFO_DIRECTION: Set high when counting up and reset low when
                           counting down
  IIO_CHAN_INFO_INDEX: Set high when index input is at active level
  IIO_CHAN_INFO_MODE: Count value encoding, counter range setting,
                      quadrature phase mode, etc.
  IIO_CHAN_INFO_PRESET: Counter preset value
  IIO_CHAN_INFO_PRESET_EN: Set high to preset counter on signal (e.g.
                           index input at active level)

Specifically, this patchset introduces a driver to support the ACCES
104-QUAD-8 device, a general purpose quadrature encoder
counter/interface board capable of monitoring the outputs of eight
encoders.

William Breathitt Gray (2):
  iio: Implement counter channel type and info constants
  iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8

 MAINTAINERS                      |   6 +
 drivers/iio/Kconfig              |   1 +
 drivers/iio/Makefile             |   1 +
 drivers/iio/counter/104-quad-8.c | 265 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/counter/Kconfig      |  23 ++++
 drivers/iio/counter/Makefile     |   7 ++
 drivers/iio/industrialio-core.c  |   7 ++
 include/linux/iio/iio.h          |   6 +
 include/uapi/linux/iio/types.h   |   1 +
 9 files changed, 317 insertions(+)
 create mode 100644 drivers/iio/counter/104-quad-8.c
 create mode 100644 drivers/iio/counter/Kconfig
 create mode 100644 drivers/iio/counter/Makefile

-- 
2.7.3

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

* [PATCH 1/2] iio: Implement counter channel type and info constants
  2016-09-07 17:55 [PATCH 0/2] Add IIO support for counter devices William Breathitt Gray
@ 2016-09-07 17:55 ` William Breathitt Gray
  2016-09-10 16:11   ` Jonathan Cameron
  2016-09-07 17:55 ` [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray
  1 sibling, 1 reply; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-07 17:55 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: linux-iio, linux-kernel, William Breathitt Gray

Quadrature encoders, such as rotary encoders and linear encoders, are
devices which are capable of encoding the relative position and
direction of motion of a shaft. This patch introduces several IIO
constants for supporting quadrature encoder counter devices.

  IIO_COUNT: Current count (main data provided by the counter device)

  IIO_CHAN_INFO_FLAGS: Counter flag states (e.g. underflows, overflows,
                       errors, etc.)
  IIO_CHAN_INFO_DIRECTION: Set high when counting up and reset low when
                           counting down
  IIO_CHAN_INFO_INDEX: Set high when index input is at active level
  IIO_CHAN_INFO_MODE: Count value encoding, counter range setting,
                      quadrature phase mode, etc.
  IIO_CHAN_INFO_PRESET: Counter preset value
  IIO_CHAN_INFO_PRESET_EN: Set high to preset counter on signal (e.g.
                           index input at active level)

Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 drivers/iio/industrialio-core.c | 7 +++++++
 include/linux/iio/iio.h         | 6 ++++++
 include/uapi/linux/iio/types.h  | 1 +
 3 files changed, 14 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 0528a0c..bfdb09d 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -81,6 +81,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_PH] = "ph",
 	[IIO_UVINDEX] = "uvindex",
 	[IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
+	[IIO_COUNT] = "count",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -151,6 +152,12 @@ static const char * const iio_chan_info_postfix[] = {
 	[IIO_CHAN_INFO_DEBOUNCE_TIME] = "debounce_time",
 	[IIO_CHAN_INFO_CALIBEMISSIVITY] = "calibemissivity",
 	[IIO_CHAN_INFO_OVERSAMPLING_RATIO] = "oversampling_ratio",
+	[IIO_CHAN_INFO_FLAGS] = "flags",
+	[IIO_CHAN_INFO_DIRECTION] = "direction",
+	[IIO_CHAN_INFO_INDEX] = "index",
+	[IIO_CHAN_INFO_MODE] = "mode",
+	[IIO_CHAN_INFO_PRESET] = "preset",
+	[IIO_CHAN_INFO_PRESET_EN] = "preset_enable",
 };
 
 /**
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index b4a0679..13543fd 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -46,6 +46,12 @@ enum iio_chan_info_enum {
 	IIO_CHAN_INFO_DEBOUNCE_TIME,
 	IIO_CHAN_INFO_CALIBEMISSIVITY,
 	IIO_CHAN_INFO_OVERSAMPLING_RATIO,
+	IIO_CHAN_INFO_FLAGS,
+	IIO_CHAN_INFO_DIRECTION,
+	IIO_CHAN_INFO_INDEX,
+	IIO_CHAN_INFO_MODE,
+	IIO_CHAN_INFO_PRESET,
+	IIO_CHAN_INFO_PRESET_EN,
 };
 
 enum iio_shared_by {
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index 22e5e58..e227039 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -40,6 +40,7 @@ enum iio_chan_type {
 	IIO_PH,
 	IIO_UVINDEX,
 	IIO_ELECTRICALCONDUCTIVITY,
+	IIO_COUNT,
 };
 
 enum iio_modifier {
-- 
2.7.3

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

* [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8
  2016-09-07 17:55 [PATCH 0/2] Add IIO support for counter devices William Breathitt Gray
  2016-09-07 17:55 ` [PATCH 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
@ 2016-09-07 17:55 ` William Breathitt Gray
  2016-09-10 16:16   ` Jonathan Cameron
  1 sibling, 1 reply; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-07 17:55 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: linux-iio, linux-kernel, William Breathitt Gray

The ACCES 104-QUAD-8 is a general purpose quadrature encoder
counter/interface board. The 104-QUAD-8 is capable of monitoring the
outputs of eight encoders via four on-board LSI/CSI LS7266R1 24-bit
dual-axis quadrature counter chips. Core functions handled by the
LS7266R1, such as direction and total count, are available.

Index interrupts (FLG1) are not supported by this driver. Furthermore,
the index function is disabled; non-synchorous mode is enabled for
non-quadrature and quadrature count modes. Performing a write of 0 to
a counter's IIO_CHAN_INFO_FLAGS clears the respective clearable flags.

This driver adds IIO support for the ACCES 104-QUAD-8 and ACCES
104-QUAD-4. The base port addresses for the devices may be configured
via the base array module parameter.

Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 MAINTAINERS                      |   6 +
 drivers/iio/Kconfig              |   1 +
 drivers/iio/Makefile             |   1 +
 drivers/iio/counter/104-quad-8.c | 265 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/counter/Kconfig      |  23 ++++
 drivers/iio/counter/Makefile     |   7 ++
 6 files changed, 303 insertions(+)
 create mode 100644 drivers/iio/counter/104-quad-8.c
 create mode 100644 drivers/iio/counter/Kconfig
 create mode 100644 drivers/iio/counter/Makefile

diff --git a/MAINTAINERS b/MAINTAINERS
index 6f0ff72..759a2ea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -255,6 +255,12 @@ L:	linux-gpio@vger.kernel.org
 S:	Maintained
 F:	drivers/gpio/gpio-104-idio-16.c
 
+ACCES 104-QUAD-8 IIO DRIVER
+M:	William Breathitt Gray <vilhelm.gray@gmail.com>
+L:	linux-iio@vger.kernel.org
+S:	Maintained
+F:	drivers/iio/counter/104-quad-8.c
+
 ACENIC DRIVER
 M:	Jes Sorensen <jes@trained-monkey.org>
 L:	linux-acenic@sunsite.dk
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 6743b18..574d1fb 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -73,6 +73,7 @@ source "drivers/iio/adc/Kconfig"
 source "drivers/iio/amplifiers/Kconfig"
 source "drivers/iio/chemical/Kconfig"
 source "drivers/iio/common/Kconfig"
+source "drivers/iio/counter/Kconfig"
 source "drivers/iio/dac/Kconfig"
 source "drivers/iio/dummy/Kconfig"
 source "drivers/iio/frequency/Kconfig"
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 87e4c43..77b2000 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -18,6 +18,7 @@ obj-y += amplifiers/
 obj-y += buffer/
 obj-y += chemical/
 obj-y += common/
+obj-y += counter/
 obj-y += dac/
 obj-y += dummy/
 obj-y += gyro/
diff --git a/drivers/iio/counter/104-quad-8.c b/drivers/iio/counter/104-quad-8.c
new file mode 100644
index 0000000..37ad382
--- /dev/null
+++ b/drivers/iio/counter/104-quad-8.c
@@ -0,0 +1,265 @@
+/*
+ * IIO driver for the ACCES 104-QUAD-8
+ * Copyright (C) 2016 William Breathitt Gray
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * This driver supports the ACCES 104-QUAD-8 and ACCES 104-QUAD-4.
+ */
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/types.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/isa.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+
+#define QUAD8_CHAN(chan) {						\
+	.type = IIO_COUNT,						\
+	.channel = chan,						\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
+		BIT(IIO_CHAN_INFO_FLAGS) |				\
+		BIT(IIO_CHAN_INFO_DIRECTION) |				\
+		BIT(IIO_CHAN_INFO_INDEX) | BIT(IIO_CHAN_INFO_MODE) |	\
+		BIT(IIO_CHAN_INFO_PRESET) |				\
+		BIT(IIO_CHAN_INFO_PRESET_EN),				\
+	.indexed = 1							\
+}
+
+#define QUAD8_NUM_CHAN 8
+
+#define QUAD8_EXTENT 32
+
+static unsigned int base[max_num_isa_dev(QUAD8_EXTENT)];
+static unsigned int num_quad8;
+module_param_array(base, uint, &num_quad8, 0);
+MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
+
+/**
+ * struct quad8_iio - IIO device private data structure
+ * @mode:	array of counter mode configurations
+ * @preset:	array of preset values
+ * @preset_en:	array of preset enable configurations
+ * @base:	base port address of the IIO device
+ */
+struct quad8_iio {
+	unsigned int mode[QUAD8_NUM_CHAN];
+	unsigned int preset[QUAD8_NUM_CHAN];
+	unsigned int preset_en[QUAD8_NUM_CHAN];
+	unsigned int base;
+};
+
+static int quad8_read_raw(struct iio_dev *indio_dev,
+	struct iio_chan_spec const *chan, int *val, int *val2, long mask)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel;
+	int i;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		/* Reset Byte Pointer; transfer Counter to Output Latch */
+		outb(0x11, base_offset + 1);
+
+		*val = 0;
+		for (i = 0; i < 3; i++)
+			*val |= (unsigned int)inb(base_offset) << (8 * i);
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_FLAGS:
+		*val = inb(base_offset + 1);
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_DIRECTION:
+		*val = !!(inb(base_offset + 1) & BIT(5));
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_INDEX:
+		*val = !!(inb(base_offset + 1) & BIT(6));
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_MODE:
+		*val = priv->mode[chan->channel];
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_PRESET:
+		*val = priv->preset[chan->channel];
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_PRESET_EN:
+		*val = priv->preset_en[chan->channel];
+		return IIO_VAL_INT;
+	}
+
+	return -EINVAL;
+}
+
+static int quad8_write_raw(struct iio_dev *indio_dev,
+	struct iio_chan_spec const *chan, int val, int val2, long mask)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel;
+	int i;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		/* Only 24-bit values are supported */
+		if ((unsigned int)val > 0xFFFFFF)
+			return -EINVAL;
+
+		/* Reset Byte Pointer */
+		outb(0x01, base_offset + 1);
+
+		/* Set Preset Register */
+		for (i = 0; i < 3; i++)
+			outb(val >> (8 * i), base_offset);
+
+		/* Transfer Preset Register to Counter */
+		outb(0x08, base_offset + 1);
+
+		/* Reset Byte Pointer */
+		outb(0x01, base_offset + 1);
+
+		/* Set Preset Register back to original value */
+		val = priv->preset[chan->channel];
+		for (i = 0; i < 3; i++)
+			outb(val >> (8 * i), base_offset);
+
+		return 0;
+	case IIO_CHAN_INFO_FLAGS:
+		/* Only clear operation is supported */
+		if (val)
+			return -EINVAL;
+
+		/* Reset Borrow, Carry, Compare, and Sign flags */
+		outb(0x02, base_offset + 1);
+		/* Reset Error flag */
+		outb(0x06, base_offset + 1);
+
+		return 0;
+	case IIO_CHAN_INFO_MODE:
+		/* Counter Mode Register exposes 5 configuration bits */
+		if ((unsigned int)val > 0x1F)
+			return -EINVAL;
+
+		priv->mode[chan->channel] = val;
+
+		/* Load mode configuration to Counter Mode Register */
+		outb(0x20 | val, base_offset + 1);
+
+		return 0;
+	case IIO_CHAN_INFO_PRESET:
+		/* Only 24-bit values are supported */
+		if ((unsigned int)val > 0xFFFFFF)
+			return -EINVAL;
+
+		priv->preset[chan->channel] = val;
+
+		/* Reset Byte Pointer */
+		outb(0x01, base_offset + 1);
+
+		/* Set Preset Register */
+		for (i = 0; i < 3; i++)
+			outb(val >> (8 * i), base_offset);
+
+		return 0;
+	case IIO_CHAN_INFO_PRESET_EN:
+		if (val && val != 1)
+			return -EINVAL;
+
+		priv->preset_en[chan->channel] = val;
+
+		/* Enable/disable preset counter function */
+		if (val)
+			outb(0x41, base_offset + 1);
+		else
+			outb(0x43, base_offset + 1);
+
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
+static const struct iio_info quad8_info = {
+	.driver_module = THIS_MODULE,
+	.read_raw = quad8_read_raw,
+	.write_raw = quad8_write_raw
+};
+
+static const struct iio_chan_spec quad8_channels[QUAD8_NUM_CHAN] = {
+	QUAD8_CHAN(0), QUAD8_CHAN(1), QUAD8_CHAN(2), QUAD8_CHAN(3),
+	QUAD8_CHAN(4), QUAD8_CHAN(5), QUAD8_CHAN(6), QUAD8_CHAN(7)
+};
+
+static int quad8_probe(struct device *dev, unsigned int id)
+{
+	struct iio_dev *indio_dev;
+	struct quad8_iio *priv;
+	int i, j;
+	unsigned int base_offset;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	if (!devm_request_region(dev, base[id], QUAD8_EXTENT,
+		dev_name(dev))) {
+		dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
+			base[id], base[id] + QUAD8_EXTENT);
+		return -EBUSY;
+	}
+
+	indio_dev->info = &quad8_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->num_channels = QUAD8_NUM_CHAN;
+	indio_dev->channels = quad8_channels;
+	indio_dev->name = dev_name(dev);
+
+	priv = iio_priv(indio_dev);
+	priv->base = base[id];
+
+	/* Reset all counters and disable interrupt function */
+	outb(0x01, base[id] + 0x11);
+	/* Set initial configuration for all channels */
+	for (i = 0; i < QUAD8_NUM_CHAN; i++) {
+		base_offset = base[id] + 2 * i;
+		/* Reset Byte Pointer */
+		outb(0x01, base_offset + 1);
+		/* Reset Preset Register */
+		for (j = 0; j < 3; j++)
+			outb(0x00, base_offset);
+		/* Reset Borrow, Carry, Compare, and Sign flags */
+		outb(0x04, base_offset + 1);
+		/* Reset Error flag */
+		outb(0x06, base_offset + 1);
+		/* Binary encoding; Normal count; non-quadrature mode */
+		outb(0x20, base_offset + 1);
+		/* Enable A and B inputs; continuously count; FLG1 as Carry */
+		outb(0x43, base_offset + 1);
+		/* Disable index function */
+		outb(0x60, base_offset + 1);
+	}
+	/* Enable all counters */
+	outb(0x00, base[id] + 0x11);
+
+	return devm_iio_device_register(dev, indio_dev);
+}
+
+static struct isa_driver quad8_driver = {
+	.probe = quad8_probe,
+	.driver = {
+		.name = "104-quad-8"
+	}
+};
+
+module_isa_driver(quad8_driver, num_quad8);
+
+MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
+MODULE_DESCRIPTION("ACCES 104-QUAD-8 IIO driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/counter/Kconfig b/drivers/iio/counter/Kconfig
new file mode 100644
index 0000000..71402b5
--- /dev/null
+++ b/drivers/iio/counter/Kconfig
@@ -0,0 +1,23 @@
+#
+# Counter devices
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Counters"
+
+config 104_QUAD_8
+	tristate "ACCES 104-QUAD-8 driver"
+	depends on X86 && ISA_BUS_API
+	help
+	  Say yes here to build support for the ACCES 104-QUAD-8 quadrature
+	  encoder counter/interface device family (104-QUAD-8, 104-QUAD-4).
+
+	  Index interrupts (FLG1) are not supported by this driver. Furthermore,
+	  the index function is disabled; non-synchorous mode is enabled for
+	  non-quadrature and quadrature count modes. Performing a write of 0 to
+	  a counter's flags interface clears the respective clearable flags.
+
+	  The base port addresses for the devices may be configured via the base
+	  array module parameter.
+
+endmenu
diff --git a/drivers/iio/counter/Makefile b/drivers/iio/counter/Makefile
new file mode 100644
index 0000000..007e884
--- /dev/null
+++ b/drivers/iio/counter/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for IIO counter devices
+#
+
+# When adding new entries keep the list in alphabetical order
+
+obj-$(CONFIG_104_QUAD_8)	+= 104-quad-8.o
-- 
2.7.3

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

* Re: [PATCH 1/2] iio: Implement counter channel type and info constants
  2016-09-07 17:55 ` [PATCH 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
@ 2016-09-10 16:11   ` Jonathan Cameron
  2016-09-12 13:33     ` William Breathitt Gray
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2016-09-10 16:11 UTC (permalink / raw)
  To: William Breathitt Gray, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

On 07/09/16 18:55, William Breathitt Gray wrote:
> Quadrature encoders, such as rotary encoders and linear encoders, are
> devices which are capable of encoding the relative position and
> direction of motion of a shaft. This patch introduces several IIO
> constants for supporting quadrature encoder counter devices.
This is interesting.  There is clearly an overlap in functionality with
the resolver drivers (which are all still hiding in staging
<gives Lars a gentle reminder>)
but the very nature of them is that we know the correspondence between
their output and a physical angle.

Here we have no way of knowing that.  The very nature of such systems
is they aren't always hardwired to a particular encoder so even in
embedded systems that translation probably isn't something we can
directly push into the device tree.

I wonder if ultimately we might want a consumer driver taking the
'counts' of a raw quadrature encoder interface and converting that
(with additional information provided either from DT or configfs)
to an angle etc. 

Job for another day ;)

I did wonder if we could 'abuse' the steps channel type to
avoid adding a new one (particularly as I've been eyeing up
some ST powerstep01 all in one stepper driver chips at work
and thinking they really should have a kernel driver ;)

Probably not though...

I think we need to think long and hard about the ABI for this
and try and make it a bit clearer / more generic in some ways
from the start.
> 
>   IIO_COUNT: Current count (main data provided by the counter device)
> 
>   IIO_CHAN_INFO_FLAGS: Counter flag states (e.g. underflows, overflows,
>                        errors, etc.)
Probably not suitable for an IIO_CHAN_INFO element.  There are lots
of things that hide in here that should be broken out separately
(and probably via ext_info elements at that).
>   IIO_CHAN_INFO_DIRECTION: Set high when counting up and reset low when
>                            counting down
Should indicate this in it's name.
IIO_CHAN_INFO_INCREASING perhaps?
>   IIO_CHAN_INFO_INDEX: Set high when index input is at active level
Hmm. might be something we want to do in a buffer at somepoint so
might want to be a channel type in it's own right..
>   IIO_CHAN_INFO_MODE: Count value encoding, counter range setting,
>                       quadrature phase mode, etc.
Another one where we are throwing lots of things into one hole.
Have separate ext_info elements instead breaking these out.

>   IIO_CHAN_INFO_PRESET: Counter preset value
Fair enough on this one.

>   IIO_CHAN_INFO_PRESET_EN: Set high to preset counter on signal (e.g.
>                            index input at active level)
Hmm. This needs more care as we probably want one ext_info element
that has values 'disabled', 'index high' etc.

> 
> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
> ---
>  drivers/iio/industrialio-core.c | 7 +++++++
>  include/linux/iio/iio.h         | 6 ++++++
>  include/uapi/linux/iio/types.h  | 1 +
>  3 files changed, 14 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 0528a0c..bfdb09d 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -81,6 +81,7 @@ static const char * const iio_chan_type_name_spec[] = {
>  	[IIO_PH] = "ph",
>  	[IIO_UVINDEX] = "uvindex",
>  	[IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
> +	[IIO_COUNT] = "count",
>  };
>  
>  static const char * const iio_modifier_names[] = {
> @@ -151,6 +152,12 @@ static const char * const iio_chan_info_postfix[] = {
>  	[IIO_CHAN_INFO_DEBOUNCE_TIME] = "debounce_time",
>  	[IIO_CHAN_INFO_CALIBEMISSIVITY] = "calibemissivity",
>  	[IIO_CHAN_INFO_OVERSAMPLING_RATIO] = "oversampling_ratio",
> +	[IIO_CHAN_INFO_FLAGS] = "flags",
> +	[IIO_CHAN_INFO_DIRECTION] = "direction",
> +	[IIO_CHAN_INFO_INDEX] = "index",
> +	[IIO_CHAN_INFO_MODE] = "mode",
> +	[IIO_CHAN_INFO_PRESET] = "preset",
> +	[IIO_CHAN_INFO_PRESET_EN] = "preset_enable",
>  };
>  
>  /**
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index b4a0679..13543fd 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -46,6 +46,12 @@ enum iio_chan_info_enum {
>  	IIO_CHAN_INFO_DEBOUNCE_TIME,
>  	IIO_CHAN_INFO_CALIBEMISSIVITY,
>  	IIO_CHAN_INFO_OVERSAMPLING_RATIO,
> +	IIO_CHAN_INFO_FLAGS,
> +	IIO_CHAN_INFO_DIRECTION,
> +	IIO_CHAN_INFO_INDEX,
> +	IIO_CHAN_INFO_MODE,
> +	IIO_CHAN_INFO_PRESET,
> +	IIO_CHAN_INFO_PRESET_EN,
>  };
>  
>  enum iio_shared_by {
> diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
> index 22e5e58..e227039 100644
> --- a/include/uapi/linux/iio/types.h
> +++ b/include/uapi/linux/iio/types.h
> @@ -40,6 +40,7 @@ enum iio_chan_type {
>  	IIO_PH,
>  	IIO_UVINDEX,
>  	IIO_ELECTRICALCONDUCTIVITY,
> +	IIO_COUNT,
>  };
>  
>  enum iio_modifier {
> 

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

* Re: [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8
  2016-09-07 17:55 ` [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray
@ 2016-09-10 16:16   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2016-09-10 16:16 UTC (permalink / raw)
  To: William Breathitt Gray, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

On 07/09/16 18:55, William Breathitt Gray wrote:
> The ACCES 104-QUAD-8 is a general purpose quadrature encoder
> counter/interface board. The 104-QUAD-8 is capable of monitoring the
> outputs of eight encoders via four on-board LSI/CSI LS7266R1 24-bit
> dual-axis quadrature counter chips. Core functions handled by the
> LS7266R1, such as direction and total count, are available.
> 
> Index interrupts (FLG1) are not supported by this driver. Furthermore,
> the index function is disabled; non-synchorous mode is enabled for
> non-quadrature and quadrature count modes. Performing a write of 0 to
> a counter's IIO_CHAN_INFO_FLAGS clears the respective clearable flags.
> 
> This driver adds IIO support for the ACCES 104-QUAD-8 and ACCES
> 104-QUAD-4. The base port addresses for the devices may be configured
> via the base array module parameter.
> 
> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Driver looks fine.  It's the interface we need to pin down.
A few more comments inline.
> ---
>  MAINTAINERS                      |   6 +
>  drivers/iio/Kconfig              |   1 +
>  drivers/iio/Makefile             |   1 +
>  drivers/iio/counter/104-quad-8.c | 265 +++++++++++++++++++++++++++++++++++++++
>  drivers/iio/counter/Kconfig      |  23 ++++
>  drivers/iio/counter/Makefile     |   7 ++
>  6 files changed, 303 insertions(+)
>  create mode 100644 drivers/iio/counter/104-quad-8.c
>  create mode 100644 drivers/iio/counter/Kconfig
>  create mode 100644 drivers/iio/counter/Makefile
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 6f0ff72..759a2ea 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -255,6 +255,12 @@ L:	linux-gpio@vger.kernel.org
>  S:	Maintained
>  F:	drivers/gpio/gpio-104-idio-16.c
>  
> +ACCES 104-QUAD-8 IIO DRIVER
> +M:	William Breathitt Gray <vilhelm.gray@gmail.com>
> +L:	linux-iio@vger.kernel.org
> +S:	Maintained
> +F:	drivers/iio/counter/104-quad-8.c
> +
>  ACENIC DRIVER
>  M:	Jes Sorensen <jes@trained-monkey.org>
>  L:	linux-acenic@sunsite.dk
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index 6743b18..574d1fb 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -73,6 +73,7 @@ source "drivers/iio/adc/Kconfig"
>  source "drivers/iio/amplifiers/Kconfig"
>  source "drivers/iio/chemical/Kconfig"
>  source "drivers/iio/common/Kconfig"
> +source "drivers/iio/counter/Kconfig"
>  source "drivers/iio/dac/Kconfig"
>  source "drivers/iio/dummy/Kconfig"
>  source "drivers/iio/frequency/Kconfig"
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index 87e4c43..77b2000 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -18,6 +18,7 @@ obj-y += amplifiers/
>  obj-y += buffer/
>  obj-y += chemical/
>  obj-y += common/
> +obj-y += counter/
>  obj-y += dac/
>  obj-y += dummy/
>  obj-y += gyro/
> diff --git a/drivers/iio/counter/104-quad-8.c b/drivers/iio/counter/104-quad-8.c
> new file mode 100644
> index 0000000..37ad382
> --- /dev/null
> +++ b/drivers/iio/counter/104-quad-8.c
> @@ -0,0 +1,265 @@
> +/*
> + * IIO driver for the ACCES 104-QUAD-8
> + * Copyright (C) 2016 William Breathitt Gray
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * This driver supports the ACCES 104-QUAD-8 and ACCES 104-QUAD-4.
> + */
> +#include <linux/bitops.h>
> +#include <linux/device.h>
> +#include <linux/errno.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/types.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/isa.h>
> +#include <linux/module.h>
> +#include <linux/moduleparam.h>
> +
> +#define QUAD8_CHAN(chan) {						\
> +	.type = IIO_COUNT,						\
> +	.channel = chan,						\
> +	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
> +		BIT(IIO_CHAN_INFO_FLAGS) |				\
> +		BIT(IIO_CHAN_INFO_DIRECTION) |				\
> +		BIT(IIO_CHAN_INFO_INDEX) | BIT(IIO_CHAN_INFO_MODE) |	\
> +		BIT(IIO_CHAN_INFO_PRESET) |				\
> +		BIT(IIO_CHAN_INFO_PRESET_EN),				\
> +	.indexed = 1							\
> +}
> +
> +#define QUAD8_NUM_CHAN 8
> +
> +#define QUAD8_EXTENT 32
> +
> +static unsigned int base[max_num_isa_dev(QUAD8_EXTENT)];
> +static unsigned int num_quad8;
> +module_param_array(base, uint, &num_quad8, 0);
> +MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
> +
> +/**
> + * struct quad8_iio - IIO device private data structure
> + * @mode:	array of counter mode configurations
> + * @preset:	array of preset values
> + * @preset_en:	array of preset enable configurations
> + * @base:	base port address of the IIO device
> + */
> +struct quad8_iio {
> +	unsigned int mode[QUAD8_NUM_CHAN];
> +	unsigned int preset[QUAD8_NUM_CHAN];
> +	unsigned int preset_en[QUAD8_NUM_CHAN];
> +	unsigned int base;
> +};
> +
> +static int quad8_read_raw(struct iio_dev *indio_dev,
> +	struct iio_chan_spec const *chan, int *val, int *val2, long mask)
> +{
> +	struct quad8_iio *const priv = iio_priv(indio_dev);
> +	const int base_offset = priv->base + 2 * chan->channel;
> +	int i;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		/* Reset Byte Pointer; transfer Counter to Output Latch */
> +		outb(0x11, base_offset + 1);
> +
> +		*val = 0;
> +		for (i = 0; i < 3; i++)
> +			*val |= (unsigned int)inb(base_offset) << (8 * i);
> +
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_FLAGS:
> +		*val = inb(base_offset + 1);
> +		return IIO_VAL_INT;
'magic' value read.  An absolute no in IIO interfaces.  This needs breaking
up and properly descriing.
> +	case IIO_CHAN_INFO_DIRECTION:
> +		*val = !!(inb(base_offset + 1) & BIT(5));
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_INDEX:
> +		*val = !!(inb(base_offset + 1) & BIT(6));
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_MODE:
> +		*val = priv->mode[chan->channel];
Another magic value.  use and info_ext enum element to give the options
nice string names.
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_PRESET:
> +		*val = priv->preset[chan->channel];
> +		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_PRESET_EN:
> +		*val = priv->preset_en[chan->channel];
> +		return IIO_VAL_INT;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +static int quad8_write_raw(struct iio_dev *indio_dev,
> +	struct iio_chan_spec const *chan, int val, int val2, long mask)
> +{
> +	struct quad8_iio *const priv = iio_priv(indio_dev);
> +	const int base_offset = priv->base + 2 * chan->channel;
> +	int i;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		/* Only 24-bit values are supported */
> +		if ((unsigned int)val > 0xFFFFFF)
> +			return -EINVAL;
> +
> +		/* Reset Byte Pointer */
> +		outb(0x01, base_offset + 1);
> +
> +		/* Set Preset Register */
> +		for (i = 0; i < 3; i++)
> +			outb(val >> (8 * i), base_offset);
> +
> +		/* Transfer Preset Register to Counter */
> +		outb(0x08, base_offset + 1);
> +
> +		/* Reset Byte Pointer */
> +		outb(0x01, base_offset + 1);
> +
> +		/* Set Preset Register back to original value */
> +		val = priv->preset[chan->channel];
> +		for (i = 0; i < 3; i++)
> +			outb(val >> (8 * i), base_offset);
> +
> +		return 0;
> +	case IIO_CHAN_INFO_FLAGS:
> +		/* Only clear operation is supported */
> +		if (val)
> +			return -EINVAL;
> +
> +		/* Reset Borrow, Carry, Compare, and Sign flags */
> +		outb(0x02, base_offset + 1);
> +		/* Reset Error flag */
> +		outb(0x06, base_offset + 1);
> +
> +		return 0;
> +	case IIO_CHAN_INFO_MODE:
> +		/* Counter Mode Register exposes 5 configuration bits */
> +		if ((unsigned int)val > 0x1F)
> +			return -EINVAL;
> +
> +		priv->mode[chan->channel] = val;
> +
> +		/* Load mode configuration to Counter Mode Register */
> +		outb(0x20 | val, base_offset + 1);
> +
> +		return 0;
> +	case IIO_CHAN_INFO_PRESET:
> +		/* Only 24-bit values are supported */
> +		if ((unsigned int)val > 0xFFFFFF)
> +			return -EINVAL;
> +
> +		priv->preset[chan->channel] = val;
> +
> +		/* Reset Byte Pointer */
> +		outb(0x01, base_offset + 1);
> +
> +		/* Set Preset Register */
> +		for (i = 0; i < 3; i++)
> +			outb(val >> (8 * i), base_offset);
> +
> +		return 0;
> +	case IIO_CHAN_INFO_PRESET_EN:
> +		if (val && val != 1)
> +			return -EINVAL;
> +
> +		priv->preset_en[chan->channel] = val;
> +
> +		/* Enable/disable preset counter function */
> +		if (val)
> +			outb(0x41, base_offset + 1);
> +		else
> +			outb(0x43, base_offset + 1);
> +
> +		return 0;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +static const struct iio_info quad8_info = {
> +	.driver_module = THIS_MODULE,
> +	.read_raw = quad8_read_raw,
> +	.write_raw = quad8_write_raw
> +};
> +
> +static const struct iio_chan_spec quad8_channels[QUAD8_NUM_CHAN] = {
> +	QUAD8_CHAN(0), QUAD8_CHAN(1), QUAD8_CHAN(2), QUAD8_CHAN(3),
> +	QUAD8_CHAN(4), QUAD8_CHAN(5), QUAD8_CHAN(6), QUAD8_CHAN(7)
> +};
> +
> +static int quad8_probe(struct device *dev, unsigned int id)
> +{
> +	struct iio_dev *indio_dev;
> +	struct quad8_iio *priv;
> +	int i, j;
> +	unsigned int base_offset;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	if (!devm_request_region(dev, base[id], QUAD8_EXTENT,
> +		dev_name(dev))) {
> +		dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
> +			base[id], base[id] + QUAD8_EXTENT);
> +		return -EBUSY;
> +	}
> +
> +	indio_dev->info = &quad8_info;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->num_channels = QUAD8_NUM_CHAN;
> +	indio_dev->channels = quad8_channels;
> +	indio_dev->name = dev_name(dev);
> +
> +	priv = iio_priv(indio_dev);
> +	priv->base = base[id];
> +
> +	/* Reset all counters and disable interrupt function */
> +	outb(0x01, base[id] + 0x11);
> +	/* Set initial configuration for all channels */
> +	for (i = 0; i < QUAD8_NUM_CHAN; i++) {
> +		base_offset = base[id] + 2 * i;
> +		/* Reset Byte Pointer */
> +		outb(0x01, base_offset + 1);
> +		/* Reset Preset Register */
> +		for (j = 0; j < 3; j++)
> +			outb(0x00, base_offset);
> +		/* Reset Borrow, Carry, Compare, and Sign flags */
> +		outb(0x04, base_offset + 1);
> +		/* Reset Error flag */
> +		outb(0x06, base_offset + 1);
> +		/* Binary encoding; Normal count; non-quadrature mode */
> +		outb(0x20, base_offset + 1);
> +		/* Enable A and B inputs; continuously count; FLG1 as Carry */
> +		outb(0x43, base_offset + 1);
> +		/* Disable index function */
> +		outb(0x60, base_offset + 1);
> +	}
> +	/* Enable all counters */
> +	outb(0x00, base[id] + 0x11);
> +
> +	return devm_iio_device_register(dev, indio_dev);
> +}
> +
> +static struct isa_driver quad8_driver = {
> +	.probe = quad8_probe,
> +	.driver = {
> +		.name = "104-quad-8"
> +	}
> +};
> +
> +module_isa_driver(quad8_driver, num_quad8);
> +
> +MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
> +MODULE_DESCRIPTION("ACCES 104-QUAD-8 IIO driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/counter/Kconfig b/drivers/iio/counter/Kconfig
> new file mode 100644
> index 0000000..71402b5
> --- /dev/null
> +++ b/drivers/iio/counter/Kconfig
> @@ -0,0 +1,23 @@
> +#
> +# Counter devices
> +#
> +# When adding new entries keep the list in alphabetical order
> +
> +menu "Counters"
> +
> +config 104_QUAD_8
> +	tristate "ACCES 104-QUAD-8 driver"
> +	depends on X86 && ISA_BUS_API
> +	help
> +	  Say yes here to build support for the ACCES 104-QUAD-8 quadrature
> +	  encoder counter/interface device family (104-QUAD-8, 104-QUAD-4).
> +
> +	  Index interrupts (FLG1) are not supported by this driver. Furthermore,
> +	  the index function is disabled; non-synchorous mode is enabled for
> +	  non-quadrature and quadrature count modes. Performing a write of 0 to
> +	  a counter's flags interface clears the respective clearable flags.
> +
> +	  The base port addresses for the devices may be configured via the base
> +	  array module parameter.
> +
> +endmenu
> diff --git a/drivers/iio/counter/Makefile b/drivers/iio/counter/Makefile
> new file mode 100644
> index 0000000..007e884
> --- /dev/null
> +++ b/drivers/iio/counter/Makefile
> @@ -0,0 +1,7 @@
> +#
> +# Makefile for IIO counter devices
> +#
> +
> +# When adding new entries keep the list in alphabetical order
> +
> +obj-$(CONFIG_104_QUAD_8)	+= 104-quad-8.o
> 

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

* Re: [PATCH 1/2] iio: Implement counter channel type and info constants
  2016-09-10 16:11   ` Jonathan Cameron
@ 2016-09-12 13:33     ` William Breathitt Gray
  0 siblings, 0 replies; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-12 13:33 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel

On Sat, Sep 10, 2016 at 05:11:56PM +0100, Jonathan Cameron wrote:
>On 07/09/16 18:55, William Breathitt Gray wrote:
>> Quadrature encoders, such as rotary encoders and linear encoders, are
>> devices which are capable of encoding the relative position and
>> direction of motion of a shaft. This patch introduces several IIO
>> constants for supporting quadrature encoder counter devices.
>This is interesting.  There is clearly an overlap in functionality with
>the resolver drivers (which are all still hiding in staging
><gives Lars a gentle reminder>)
>but the very nature of them is that we know the correspondence between
>their output and a physical angle.
>
>Here we have no way of knowing that.  The very nature of such systems
>is they aren't always hardwired to a particular encoder so even in
>embedded systems that translation probably isn't something we can
>directly push into the device tree.
>
>I wonder if ultimately we might want a consumer driver taking the
>'counts' of a raw quadrature encoder interface and converting that
>(with additional information provided either from DT or configfs)
>to an angle etc. 
>
>Job for another day ;)

Ultimately, some sort consumer driver would be quite useful I would
imagine. Afterall, quadrature encoder counters are rarely used for the
sole sake of counting rising edges. Rather, maintaining counts is simply
one step of the ultimate process of encoding/decoding some real world
data (position, distance, angle, etc.), be it for a conveyor belt, 3-D
printer, CNC mill, or any other sort of industrial automation or robotic
system.

Providing an interface to access the ultimate real world data directly
would be very apt. Though of course, there would be a variety of common
real world values for which would need to be accounted (e.g. distance
versus angle).

>
>I did wonder if we could 'abuse' the steps channel type to
>avoid adding a new one (particularly as I've been eyeing up
>some ST powerstep01 all in one stepper driver chips at work
>and thinking they really should have a kernel driver ;)
>
>Probably not though...
>
>I think we need to think long and hard about the ABI for this
>and try and make it a bit clearer / more generic in some ways
>from the start.

With this I very much agree. While encoders are ubiquitous in the
industrial sector, their uses are quite diverse. The ABI should be clear
and generic enough to interface with the majority of these types of
devices and expose their data without restricting their use cases. Be
quick to point out any possible problem paths early on lest we
unintentionally restrict this ABI to only a subset of devices.

>> 
>>   IIO_COUNT: Current count (main data provided by the counter device)
>> 
>>   IIO_CHAN_INFO_FLAGS: Counter flag states (e.g. underflows, overflows,
>>                        errors, etc.)
>Probably not suitable for an IIO_CHAN_INFO element.  There are lots
>of things that hide in here that should be broken out separately
>(and probably via ext_info elements at that).
>>   IIO_CHAN_INFO_DIRECTION: Set high when counting up and reset low when
>>                            counting down
>Should indicate this in it's name.
>IIO_CHAN_INFO_INCREASING perhaps?
>>   IIO_CHAN_INFO_INDEX: Set high when index input is at active level
>Hmm. might be something we want to do in a buffer at somepoint so
>might want to be a channel type in it's own right..
>>   IIO_CHAN_INFO_MODE: Count value encoding, counter range setting,
>>                       quadrature phase mode, etc.
>Another one where we are throwing lots of things into one hole.
>Have separate ext_info elements instead breaking these out.
>
>>   IIO_CHAN_INFO_PRESET: Counter preset value
>Fair enough on this one.
>
>>   IIO_CHAN_INFO_PRESET_EN: Set high to preset counter on signal (e.g.
>>                            index input at active level)
>Hmm. This needs more care as we probably want one ext_info element
>that has values 'disabled', 'index high' etc.

I'll submit a second version of this patch with the changes you
suggested. Using ext_info elements should break out the flags, mode, and
other indicated data more suitably.

William Breathitt Gray

>
>> 
>> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
>> ---
>>  drivers/iio/industrialio-core.c | 7 +++++++
>>  include/linux/iio/iio.h         | 6 ++++++
>>  include/uapi/linux/iio/types.h  | 1 +
>>  3 files changed, 14 insertions(+)
>> 
>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>> index 0528a0c..bfdb09d 100644
>> --- a/drivers/iio/industrialio-core.c
>> +++ b/drivers/iio/industrialio-core.c
>> @@ -81,6 +81,7 @@ static const char * const iio_chan_type_name_spec[] = {
>>  	[IIO_PH] = "ph",
>>  	[IIO_UVINDEX] = "uvindex",
>>  	[IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
>> +	[IIO_COUNT] = "count",
>>  };
>>  
>>  static const char * const iio_modifier_names[] = {
>> @@ -151,6 +152,12 @@ static const char * const iio_chan_info_postfix[] = {
>>  	[IIO_CHAN_INFO_DEBOUNCE_TIME] = "debounce_time",
>>  	[IIO_CHAN_INFO_CALIBEMISSIVITY] = "calibemissivity",
>>  	[IIO_CHAN_INFO_OVERSAMPLING_RATIO] = "oversampling_ratio",
>> +	[IIO_CHAN_INFO_FLAGS] = "flags",
>> +	[IIO_CHAN_INFO_DIRECTION] = "direction",
>> +	[IIO_CHAN_INFO_INDEX] = "index",
>> +	[IIO_CHAN_INFO_MODE] = "mode",
>> +	[IIO_CHAN_INFO_PRESET] = "preset",
>> +	[IIO_CHAN_INFO_PRESET_EN] = "preset_enable",
>>  };
>>  
>>  /**
>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>> index b4a0679..13543fd 100644
>> --- a/include/linux/iio/iio.h
>> +++ b/include/linux/iio/iio.h
>> @@ -46,6 +46,12 @@ enum iio_chan_info_enum {
>>  	IIO_CHAN_INFO_DEBOUNCE_TIME,
>>  	IIO_CHAN_INFO_CALIBEMISSIVITY,
>>  	IIO_CHAN_INFO_OVERSAMPLING_RATIO,
>> +	IIO_CHAN_INFO_FLAGS,
>> +	IIO_CHAN_INFO_DIRECTION,
>> +	IIO_CHAN_INFO_INDEX,
>> +	IIO_CHAN_INFO_MODE,
>> +	IIO_CHAN_INFO_PRESET,
>> +	IIO_CHAN_INFO_PRESET_EN,
>>  };
>>  
>>  enum iio_shared_by {
>> diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
>> index 22e5e58..e227039 100644
>> --- a/include/uapi/linux/iio/types.h
>> +++ b/include/uapi/linux/iio/types.h
>> @@ -40,6 +40,7 @@ enum iio_chan_type {
>>  	IIO_PH,
>>  	IIO_UVINDEX,
>>  	IIO_ELECTRICALCONDUCTIVITY,
>> +	IIO_COUNT,
>>  };
>>  
>>  enum iio_modifier {
>> 
>

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

end of thread, other threads:[~2016-09-12 13:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-07 17:55 [PATCH 0/2] Add IIO support for counter devices William Breathitt Gray
2016-09-07 17:55 ` [PATCH 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
2016-09-10 16:11   ` Jonathan Cameron
2016-09-12 13:33     ` William Breathitt Gray
2016-09-07 17:55 ` [PATCH 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray
2016-09-10 16:16   ` 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.