linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add IIO support for counter devices
@ 2016-09-14 19:24 William Breathitt Gray
  2016-09-14 19:24 ` [PATCH v2 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
  2016-09-14 19:24 ` [PATCH v2 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-14 19:24 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: linux-iio, linux-kernel, William Breathitt Gray

Changes in v2:
  - New IIO constants have been reduced to three: IIO_COUNT, IIO_INDEX,
    and IIO_CHAN_INFO_PRESET
  - 104-QUAD-8 specific flags, modes, and configurations have been
    broken out and exposed via ext_info elements

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. This patch introduces the counter
subdirectory and several IIO constants for supporting quadrature encoder
counter devices.

  IIO_COUNT: Current count (main data provided by the counter device)
  IIO_INDEX: Set high when index input is at active level
  IIO_CHAN_INFO_PRESET: Counter preset value

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 | 697 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/counter/Kconfig      |  22 ++
 drivers/iio/counter/Makefile     |   7 +
 drivers/iio/industrialio-core.c  |   3 +
 include/linux/iio/iio.h          |   1 +
 include/uapi/linux/iio/types.h   |   2 +
 9 files changed, 740 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 v2 1/2] iio: Implement counter channel type and info constants
  2016-09-14 19:24 [PATCH v2 0/2] Add IIO support for counter devices William Breathitt Gray
@ 2016-09-14 19:24 ` William Breathitt Gray
  2016-09-15 13:35   ` kbuild test robot
  2016-09-15 22:30   ` kbuild test robot
  2016-09-14 19:24 ` [PATCH v2 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray
  1 sibling, 2 replies; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-14 19:24 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 the counter
subdirectory and several IIO constants for supporting quadrature encoder
counter devices.

  IIO_COUNT: Current count (main data provided by the counter device)
  IIO_INDEX: Set high when index input is at active level
  IIO_CHAN_INFO_PRESET: Counter preset value

Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 drivers/iio/Kconfig             | 1 +
 drivers/iio/Makefile            | 1 +
 drivers/iio/counter/Kconfig     | 8 ++++++++
 drivers/iio/counter/Makefile    | 6 ++++++
 drivers/iio/industrialio-core.c | 3 +++
 include/linux/iio/iio.h         | 1 +
 include/uapi/linux/iio/types.h  | 2 ++
 7 files changed, 22 insertions(+)
 create mode 100644 drivers/iio/counter/Kconfig
 create mode 100644 drivers/iio/counter/Makefile

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/Kconfig b/drivers/iio/counter/Kconfig
new file mode 100644
index 0000000..95a7a0df
--- /dev/null
+++ b/drivers/iio/counter/Kconfig
@@ -0,0 +1,8 @@
+#
+# Counter devices
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Counters"
+
+endmenu
diff --git a/drivers/iio/counter/Makefile b/drivers/iio/counter/Makefile
new file mode 100644
index 0000000..c4dfa50
--- /dev/null
+++ b/drivers/iio/counter/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for IIO counter devices
+#
+
+# When adding new entries keep the list in alphabetical order
+
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 0528a0c..42d8c8b 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -81,6 +81,8 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_PH] = "ph",
 	[IIO_UVINDEX] = "uvindex",
 	[IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
+	[IIO_COUNT] = "count",
+	[IIO_INDEX] = "index",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -151,6 +153,7 @@ 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_PRESET] = "preset",
 };
 
 /**
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index b4a0679..7dc86d1 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -46,6 +46,7 @@ enum iio_chan_info_enum {
 	IIO_CHAN_INFO_DEBOUNCE_TIME,
 	IIO_CHAN_INFO_CALIBEMISSIVITY,
 	IIO_CHAN_INFO_OVERSAMPLING_RATIO,
+	IIO_CHAN_INFO_PRESET,
 };
 
 enum iio_shared_by {
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index 22e5e58..e54d14a 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -40,6 +40,8 @@ enum iio_chan_type {
 	IIO_PH,
 	IIO_UVINDEX,
 	IIO_ELECTRICALCONDUCTIVITY,
+	IIO_COUNT,
+	IIO_INDEX,
 };
 
 enum iio_modifier {
-- 
2.7.3

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

* [PATCH v2 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8
  2016-09-14 19:24 [PATCH v2 0/2] Add IIO support for counter devices William Breathitt Gray
  2016-09-14 19:24 ` [PATCH v2 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
@ 2016-09-14 19:24 ` William Breathitt Gray
  1 sibling, 0 replies; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-14 19:24 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.

Performing a write to a counter's IIO_CHAN_INFO_RAW sets the counter and
also clears the counter's respective clearable flags (BORROW, CARRY,
COMPARE, SIGN, and ERROR). Interrupts are not supported by this driver.

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/counter/104-quad-8.c | 697 +++++++++++++++++++++++++++++++++++++++
 drivers/iio/counter/Kconfig      |  14 +
 drivers/iio/counter/Makefile     |   1 +
 4 files changed, 718 insertions(+)
 create mode 100644 drivers/iio/counter/104-quad-8.c

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/counter/104-quad-8.c b/drivers/iio/counter/104-quad-8.c
new file mode 100644
index 0000000..f156f50
--- /dev/null
+++ b/drivers/iio/counter/104-quad-8.c
@@ -0,0 +1,697 @@
+/*
+ * 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/kernel.h>
+#include <linux/isa.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+
+#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");
+
+#define QUAD8_NUM_COUNTERS 8
+
+/**
+ * struct quad8_iio - IIO device private data structure
+ * @preset:		array of preset values
+ * @encoding:		array of encoding configurations
+ * @counter_mode:	array of counter_mode configurations
+ * @quadrature_mode:	array of quadrature_mode configurations
+ * @ab_enable:		array of A and B inputs enable configurations
+ * @preset_enable:	array of preset enable configurations
+ * @flg1:		array of FLG1 configurations
+ * @index_function:	array of index function enable configurations
+ * @index_polarity:	array of index polarity configurations
+ * @base:		base port address of the IIO device
+ */
+struct quad8_iio {
+	unsigned int preset[QUAD8_NUM_COUNTERS];
+	unsigned int encoding[QUAD8_NUM_COUNTERS];
+	unsigned int counter_mode[QUAD8_NUM_COUNTERS];
+	unsigned int quadrature_mode[QUAD8_NUM_COUNTERS];
+	unsigned int ab_enable[QUAD8_NUM_COUNTERS];
+	unsigned int preset_enable[QUAD8_NUM_COUNTERS];
+	unsigned int flg1[QUAD8_NUM_COUNTERS];
+	unsigned int index_function[QUAD8_NUM_COUNTERS];
+	unsigned int index_polarity[QUAD8_NUM_COUNTERS];
+	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:
+		if (chan->type == IIO_INDEX) {
+			*val = !!(inb(base_offset + 1) & BIT(6));
+			return IIO_VAL_INT;
+		}
+
+		/* 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_PRESET:
+		*val = priv->preset[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:
+		if (chan->type == IIO_INDEX)
+			return -EINVAL;
+
+		/* 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);
+
+		/* 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_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;
+	}
+
+	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 char *const quad8_toggle_states[] = {
+	"0",
+	"1"
+};
+
+static int quad8_get_borrow(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return inb(base_offset) & BIT(0);
+}
+
+static const struct iio_enum quad8_borrow_enum = {
+	.items = quad8_toggle_states,
+	.num_items = ARRAY_SIZE(quad8_toggle_states),
+	.get = quad8_get_borrow
+};
+
+static int quad8_get_carry(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return !!(inb(base_offset) & BIT(1));
+}
+
+static const struct iio_enum quad8_carry_enum = {
+	.items = quad8_toggle_states,
+	.num_items = ARRAY_SIZE(quad8_toggle_states),
+	.get = quad8_get_carry
+};
+
+static int quad8_get_compare(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return !!(inb(base_offset) & BIT(2));
+}
+
+static const struct iio_enum quad8_compare_enum = {
+	.items = quad8_toggle_states,
+	.num_items = ARRAY_SIZE(quad8_toggle_states),
+	.get = quad8_get_compare
+};
+
+static const char *const quad8_sign_states[] = {
+	"+",
+	"-"
+};
+
+static int quad8_get_sign(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return !!(inb(base_offset) & BIT(3));
+}
+
+static const struct iio_enum quad8_sign_enum = {
+	.items = quad8_sign_states,
+	.num_items = ARRAY_SIZE(quad8_sign_states),
+	.get = quad8_get_sign
+};
+
+static const char *const quad8_error_states[] = {
+	"No errors detected",
+	"Excessive noise detected at the count inputs"
+};
+
+static int quad8_get_error(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return !!(inb(base_offset) & BIT(4));
+}
+
+static const struct iio_enum quad8_error_enum = {
+	.items = quad8_error_states,
+	.num_items = ARRAY_SIZE(quad8_error_states),
+	.get = quad8_get_error
+};
+
+static const char *const quad8_count_direction_states[] = {
+	"down",
+	"up"
+};
+
+static int quad8_get_count_direction(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	return !!(inb(base_offset) & BIT(5));
+}
+
+static const struct iio_enum quad8_count_direction_enum = {
+	.items = quad8_count_direction_states,
+	.num_items = ARRAY_SIZE(quad8_count_direction_states),
+	.get = quad8_get_count_direction
+};
+
+static const char *const quad8_encoding_modes[] = {
+	"binary",
+	"binary-coded decimal"
+};
+
+static int quad8_set_encoding(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int encoding)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int mode_cfg = encoding |
+		priv->counter_mode[chan->channel] << 1 |
+		priv->quadrature_mode[chan->channel] << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->encoding[chan->channel] = encoding;
+
+	/* Load mode configuration to Counter Mode Register */
+	outb(0x20 | mode_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_encoding(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->encoding[chan->channel];
+}
+
+static const struct iio_enum quad8_encoding_enum = {
+	.items = quad8_encoding_modes,
+	.num_items = ARRAY_SIZE(quad8_encoding_modes),
+	.set = quad8_set_encoding,
+	.get = quad8_get_encoding
+};
+
+static const char *const quad8_counter_modes[] = {
+	"normal",
+	"range limit",
+	"non-recycle",
+	"modulo-n"
+};
+
+static int quad8_set_counter_mode(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int counter_mode)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int mode_cfg = priv->encoding[chan->channel] |
+		counter_mode << 1 | priv->quadrature_mode[chan->channel] << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->counter_mode[chan->channel] = counter_mode;
+
+	/* Load mode configuration to Counter Mode Register */
+	outb(0x20 | mode_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_counter_mode(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->counter_mode[chan->channel];
+}
+
+static const struct iio_enum quad8_counter_mode_enum = {
+	.items = quad8_counter_modes,
+	.num_items = ARRAY_SIZE(quad8_counter_modes),
+	.set = quad8_set_counter_mode,
+	.get = quad8_get_counter_mode
+};
+
+static const char *const quad8_enable_modes[] = {
+	"disabled",
+	"enabled"
+};
+
+static int quad8_set_index_function(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int index_function)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int idr_cfg = index_function |
+		priv->index_polarity[chan->channel] << 1;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	/* Index function must be disabled in non-quadrature mode */
+	if (index_function && !priv->quadrature_mode[chan->channel])
+		return -EINVAL;
+
+	priv->index_function[chan->channel] = index_function;
+
+	/* Load Index Control configuration to Index Control Register */
+	outb(0x60 | idr_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_index_function(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->index_function[chan->channel];
+}
+
+static const struct iio_enum quad8_index_function_enum = {
+	.items = quad8_enable_modes,
+	.num_items = ARRAY_SIZE(quad8_enable_modes),
+	.set = quad8_set_index_function,
+	.get = quad8_get_index_function
+};
+
+static const char *const quad8_quadrature_modes[] = {
+	"non-quadrature",
+	"quadrature x1",
+	"quadrature x2",
+	"quadrature x4"
+};
+
+static int quad8_set_quadrature_mode(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int quadrature_mode)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int mode_cfg = priv->encoding[chan->channel] |
+		priv->counter_mode[chan->channel] << 1 | quadrature_mode << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->quadrature_mode[chan->channel] = quadrature_mode;
+
+	/* Index function must be disabled in non-quadrature mode */
+	if (!quadrature_mode && priv->index_function[chan->channel])
+		quad8_set_index_function(indio_dev, chan, 0);
+
+	/* Load mode configuration to Counter Mode Register */
+	outb(0x20 | mode_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_quadrature_mode(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->quadrature_mode[chan->channel];
+}
+
+static const struct iio_enum quad8_quadrature_mode_enum = {
+	.items = quad8_quadrature_modes,
+	.num_items = ARRAY_SIZE(quad8_quadrature_modes),
+	.set = quad8_set_quadrature_mode,
+	.get = quad8_get_quadrature_mode
+};
+
+static int quad8_set_ab_enable(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int ab_enable)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int ioc_cfg = ab_enable |
+		priv->preset_enable[chan->channel] << 1 |
+		priv->flg1[chan->channel] << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->ab_enable[chan->channel] = ab_enable;
+
+	/* Load I/O control configuration to Input / Output Control Register */
+	outb(0x40 | ioc_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_ab_enable(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->ab_enable[chan->channel];
+}
+
+static const struct iio_enum quad8_ab_enable_enum = {
+	.items = quad8_enable_modes,
+	.num_items = ARRAY_SIZE(quad8_enable_modes),
+	.set = quad8_set_ab_enable,
+	.get = quad8_get_ab_enable
+};
+
+static const char *const quad8_preset_enable_modes[] = {
+	"index active",
+	"disabled"
+};
+
+static int quad8_set_preset_enable(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int preset_enable)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int ioc_cfg = priv->ab_enable[chan->channel] |
+		preset_enable << 1 | priv->flg1[chan->channel] << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->preset_enable[chan->channel] = preset_enable;
+
+	/* Load I/O control configuration to Input / Output Control Register */
+	outb(0x40 | ioc_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_preset_enable(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->preset_enable[chan->channel];
+}
+
+static const struct iio_enum quad8_preset_enable_enum = {
+	.items = quad8_preset_enable_modes,
+	.num_items = ARRAY_SIZE(quad8_preset_enable_modes),
+	.set = quad8_set_preset_enable,
+	.get = quad8_get_preset_enable
+};
+
+static const char *const quad8_flg1_modes[] = {
+	"/Carry (active low)",
+	"/Compare (active low)",
+	"/Carry/Borrow (active low)",
+	"Index (active high)"
+};
+
+static int quad8_set_flg1(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int flg1)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int ioc_cfg = priv->ab_enable[chan->channel] |
+		priv->preset_enable[chan->channel] << 1 | flg1 << 3;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->flg1[chan->channel] = flg1;
+
+	/* Load I/O control configuration to Input / Output Control Register */
+	outb(0x40 | ioc_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_flg1(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->flg1[chan->channel];
+}
+
+static const struct iio_enum quad8_flg1_enum = {
+	.items = quad8_flg1_modes,
+	.num_items = ARRAY_SIZE(quad8_flg1_modes),
+	.set = quad8_set_flg1,
+	.get = quad8_get_flg1
+};
+
+static const char *const quad8_index_polarity_modes[] = {
+	"negative",
+	"positive"
+};
+
+static int quad8_set_index_polarity(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan, unsigned int index_polarity)
+{
+	struct quad8_iio *const priv = iio_priv(indio_dev);
+	const unsigned int idr_cfg = priv->index_function[chan->channel] |
+		index_polarity << 1;
+	const int base_offset = priv->base + 2 * chan->channel + 1;
+
+	priv->index_polarity[chan->channel] = index_polarity;
+
+	/* Load Index Control configuration to Index Control Register */
+	outb(0x60 | idr_cfg, base_offset);
+
+	return 0;
+}
+
+static int quad8_get_index_polarity(struct iio_dev *indio_dev,
+	const struct iio_chan_spec *chan)
+{
+	const struct quad8_iio *const priv = iio_priv(indio_dev);
+
+	return priv->index_polarity[chan->channel];
+}
+
+static const struct iio_enum quad8_index_polarity_enum = {
+	.items = quad8_index_polarity_modes,
+	.num_items = ARRAY_SIZE(quad8_index_polarity_modes),
+	.set = quad8_set_index_polarity,
+	.get = quad8_get_index_polarity
+};
+
+static const struct iio_chan_spec_ext_info quad8_count_ext_info[] = {
+	IIO_ENUM("borrow", IIO_SEPARATE, &quad8_borrow_enum),
+	IIO_ENUM_AVAILABLE("borrow", &quad8_borrow_enum),
+	IIO_ENUM("carry", IIO_SEPARATE, &quad8_carry_enum),
+	IIO_ENUM_AVAILABLE("carry", &quad8_carry_enum),
+	IIO_ENUM("compare", IIO_SEPARATE, &quad8_compare_enum),
+	IIO_ENUM_AVAILABLE("compare", &quad8_compare_enum),
+	IIO_ENUM("sign", IIO_SEPARATE, &quad8_sign_enum),
+	IIO_ENUM_AVAILABLE("sign", &quad8_sign_enum),
+	IIO_ENUM("error", IIO_SEPARATE, &quad8_error_enum),
+	IIO_ENUM_AVAILABLE("error", &quad8_error_enum),
+	IIO_ENUM("count_direction", IIO_SEPARATE, &quad8_count_direction_enum),
+	IIO_ENUM_AVAILABLE("count_direction", &quad8_count_direction_enum),
+	IIO_ENUM("encoding", IIO_SEPARATE, &quad8_encoding_enum),
+	IIO_ENUM_AVAILABLE("encoding", &quad8_encoding_enum),
+	IIO_ENUM("counter_mode", IIO_SEPARATE, &quad8_counter_mode_enum),
+	IIO_ENUM_AVAILABLE("counter_mode", &quad8_counter_mode_enum),
+	IIO_ENUM("quadrature_mode", IIO_SEPARATE, &quad8_quadrature_mode_enum),
+	IIO_ENUM_AVAILABLE("quadrature_mode", &quad8_quadrature_mode_enum),
+	IIO_ENUM("ab_enable", IIO_SEPARATE, &quad8_ab_enable_enum),
+	IIO_ENUM_AVAILABLE("ab_enable", &quad8_ab_enable_enum),
+	IIO_ENUM("preset_enable", IIO_SEPARATE, &quad8_preset_enable_enum),
+	IIO_ENUM_AVAILABLE("preset_enable", &quad8_preset_enable_enum),
+	IIO_ENUM("flg1", IIO_SEPARATE, &quad8_flg1_enum),
+	IIO_ENUM_AVAILABLE("flg1", &quad8_flg1_enum),
+	{}
+};
+
+static const struct iio_chan_spec_ext_info quad8_index_ext_info[] = {
+	IIO_ENUM("index_function", IIO_SEPARATE, &quad8_index_function_enum),
+	IIO_ENUM_AVAILABLE("index_function", &quad8_index_function_enum),
+	IIO_ENUM("index_polarity", IIO_SEPARATE, &quad8_index_polarity_enum),
+	IIO_ENUM_AVAILABLE("index_polarity", &quad8_index_polarity_enum),
+	{}
+};
+
+#define QUAD8_COUNT_CHAN(_chan) {			\
+	.type = IIO_COUNT,				\
+	.channel = (_chan),				\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |	\
+		BIT(IIO_CHAN_INFO_PRESET),		\
+	.ext_info = quad8_count_ext_info,		\
+	.indexed = 1					\
+}
+
+#define QUAD8_INDEX_CHAN(_chan) {			\
+	.type = IIO_INDEX,				\
+	.channel = (_chan),				\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+	.ext_info = quad8_index_ext_info,		\
+	.indexed = 1					\
+}
+
+static const struct iio_chan_spec quad8_channels[] = {
+	QUAD8_COUNT_CHAN(0), QUAD8_INDEX_CHAN(0),
+	QUAD8_COUNT_CHAN(1), QUAD8_INDEX_CHAN(1),
+	QUAD8_COUNT_CHAN(2), QUAD8_INDEX_CHAN(2),
+	QUAD8_COUNT_CHAN(3), QUAD8_INDEX_CHAN(3),
+	QUAD8_COUNT_CHAN(4), QUAD8_INDEX_CHAN(4),
+	QUAD8_COUNT_CHAN(5), QUAD8_INDEX_CHAN(5),
+	QUAD8_COUNT_CHAN(6), QUAD8_INDEX_CHAN(6),
+	QUAD8_COUNT_CHAN(7), QUAD8_INDEX_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 = ARRAY_SIZE(quad8_channels);
+	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 counters */
+	for (i = 0; i < QUAD8_NUM_COUNTERS; 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);
+		/* Disable A and B inputs; preset on index; FLG1 as Carry */
+		outb(0x40, 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
index 95a7a0df..887021e 100644
--- a/drivers/iio/counter/Kconfig
+++ b/drivers/iio/counter/Kconfig
@@ -5,4 +5,18 @@
 
 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).
+
+	  Performing a write to a counter's IIO_CHAN_INFO_RAW sets the counter and
+	  also clears the counter's respective clearable flags (BORROW, CARRY,
+	  COMPARE, SIGN, and ERROR). Interrupts are not supported by this driver.
+
+	  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
index c4dfa50..007e884 100644
--- a/drivers/iio/counter/Makefile
+++ b/drivers/iio/counter/Makefile
@@ -4,3 +4,4 @@
 
 # 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 v2 1/2] iio: Implement counter channel type and info constants
  2016-09-14 19:24 ` [PATCH v2 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
@ 2016-09-15 13:35   ` kbuild test robot
  2016-09-15 14:03     ` William Breathitt Gray
  2016-09-15 22:30   ` kbuild test robot
  1 sibling, 1 reply; 6+ messages in thread
From: kbuild test robot @ 2016-09-15 13:35 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: kbuild-all, jic23, knaack.h, lars, pmeerw, linux-iio,
	linux-kernel, William Breathitt Gray

[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]

Hi William,

[auto build test ERROR on iio/togreg]
[also build test ERROR on v4.8-rc6 next-20160915]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: x86_64-randconfig-s1-09151924 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

Note: the linux-review/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651 HEAD 9dfaeb5dd7e5fffaedaaaa34c80c7790ed346b72 builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>):

>> ld: cannot find drivers/iio/counter/built-in.o: No such file or directory

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 20525 bytes --]

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

* Re: [PATCH v2 1/2] iio: Implement counter channel type and info constants
  2016-09-15 13:35   ` kbuild test robot
@ 2016-09-15 14:03     ` William Breathitt Gray
  0 siblings, 0 replies; 6+ messages in thread
From: William Breathitt Gray @ 2016-09-15 14:03 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw; +Cc: linux-iio, linux-kernel

On Thu, Sep 15, 2016 at 09:35:57PM +0800, kbuild test robot wrote:
>Hi William,
>
>[auto build test ERROR on iio/togreg]
>[also build test ERROR on v4.8-rc6 next-20160915]
>[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
>[Check https://git-scm.com/docs/git-format-patch for more information]
>
>url:    https://github.com/0day-ci/linux/commits/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651
>base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
>config: x86_64-randconfig-s1-09151924 (attached as .config)
>compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
>reproduce:
>        # save the attached .config to linux build tree
>        make ARCH=x86_64 
>
>Note: the linux-review/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651 HEAD 9dfaeb5dd7e5fffaedaaaa34c80c7790ed346b72 builds fine.
>      It only hurts bisectibility.
>
>All errors (new ones prefixed by >>):
>
>>> ld: cannot find drivers/iio/counter/built-in.o: No such file or directory
>
>---
>0-DAY kernel test infrastructure                Open Source Technology Center
>https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

I moved the creation of the "counter" subdirectory to this first patch,
but the 104-QUAD-8 driver is only added in the subsequent patch;
effectively, the non-populated Makefile in this patch leads to the
error.

I'll submit version 3 of this patchset with the "counter" subdirectory
introduced in the same patch as the 104-QUAD-8 driver. That should
resolve this issue.

William Breathitt Gray

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

* Re: [PATCH v2 1/2] iio: Implement counter channel type and info constants
  2016-09-14 19:24 ` [PATCH v2 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
  2016-09-15 13:35   ` kbuild test robot
@ 2016-09-15 22:30   ` kbuild test robot
  1 sibling, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2016-09-15 22:30 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: kbuild-all, jic23, knaack.h, lars, pmeerw, linux-iio,
	linux-kernel, William Breathitt Gray

[-- Attachment #1: Type: text/plain, Size: 1487 bytes --]

Hi William,

[auto build test ERROR on iio/togreg]
[also build test ERROR on v4.8-rc6 next-20160915]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

Note: the linux-review/William-Breathitt-Gray/Add-IIO-support-for-counter-devices/20160915-032651 HEAD 9dfaeb5dd7e5fffaedaaaa34c80c7790ed346b72 builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>):

>> arm-linux-gnueabi-ld: cannot find drivers/iio/counter/built-in.o: No such file or directory

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 58621 bytes --]

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

end of thread, other threads:[~2016-09-15 22:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 19:24 [PATCH v2 0/2] Add IIO support for counter devices William Breathitt Gray
2016-09-14 19:24 ` [PATCH v2 1/2] iio: Implement counter channel type and info constants William Breathitt Gray
2016-09-15 13:35   ` kbuild test robot
2016-09-15 14:03     ` William Breathitt Gray
2016-09-15 22:30   ` kbuild test robot
2016-09-14 19:24 ` [PATCH v2 2/2] iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8 William Breathitt Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).