linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] counter: 104-quad-8: Support Differential Encoder Cable Status
@ 2020-02-22 15:43 William Breathitt Gray
  2020-03-01 20:14 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: William Breathitt Gray @ 2020-02-22 15:43 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, linux-kernel, William Breathitt Gray

The ACCES 104-QUAD-8 series provides status information about the
connection state of the differential encoder cable inputs. This patch
implements support to expose such information from these devices.

Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 .../ABI/testing/sysfs-bus-counter-104-quad-8  | 12 ++++++
 drivers/counter/104-quad-8.c                  | 38 +++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 b/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
index 46b1f33b2fce..492b3e98f369 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
+++ b/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
@@ -1,3 +1,15 @@
+What:		/sys/bus/counter/devices/counterX/cable_status
+KernelVersion:	5.7
+Contact:	linux-iio@vger.kernel.org
+Description:
+		Differential encoder cable status; bits 0 through 7
+		correspond to channels 1 through 8. Writing a 0 to the
+		corresponding bit will enable the status of the
+		respective channel.
+
+		Logic 0 = cable fault (not connected or loose wires)
+		Logic 1 = cable connection good or cable fault disabled
+
 What:		/sys/bus/counter/devices/counterX/signalY/index_polarity
 KernelVersion:	5.2
 Contact:	linux-iio@vger.kernel.org
diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 17e67a84777d..1cbaf7e100a3 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -56,6 +56,7 @@ struct quad8_iio {
 
 #define QUAD8_REG_CHAN_OP 0x11
 #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16
+#define QUAD8_DIFF_ENCODER_CABLE_STATUS 0x17
 /* Borrow Toggle flip-flop */
 #define QUAD8_FLAG_BT BIT(0)
 /* Carry Toggle flip-flop */
@@ -1268,6 +1269,42 @@ static struct counter_count quad8_counts[] = {
 	QUAD8_COUNT(7, "Channel 8 Count")
 };
 
+static ssize_t quad8_cable_status_read(struct counter_device *counter,
+				       void *private, char *buf)
+{
+	const struct quad8_iio *const priv = counter->priv;
+	unsigned int status;
+
+	status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
+
+	return sprintf(buf, "0x%X\n", status);
+}
+
+static ssize_t quad8_cable_status_write(struct counter_device *counter,
+					void *private, const char *buf,
+					size_t len)
+{
+	struct quad8_iio *const priv = counter->priv;
+	u8 enable;
+	int ret;
+
+	ret = kstrtou8(buf, 0, &enable);
+	if (ret)
+		return ret;
+
+	outb(enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
+
+	return len;
+}
+
+static const struct counter_device_ext quad8_device_ext[] = {
+	{
+		.name = "cable_status",
+		.read = quad8_cable_status_read,
+		.write = quad8_cable_status_write
+	}
+};
+
 static int quad8_probe(struct device *dev, unsigned int id)
 {
 	struct iio_dev *indio_dev;
@@ -1304,6 +1341,7 @@ static int quad8_probe(struct device *dev, unsigned int id)
 	quad8iio->counter.num_counts = ARRAY_SIZE(quad8_counts);
 	quad8iio->counter.signals = quad8_signals;
 	quad8iio->counter.num_signals = ARRAY_SIZE(quad8_signals);
+	quad8iio->counter.ext = quad8_device_ext;
 	quad8iio->counter.priv = quad8iio;
 	quad8iio->base = base[id];
 
-- 
2.24.1


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

* Re: [PATCH] counter: 104-quad-8: Support Differential Encoder Cable Status
  2020-02-22 15:43 [PATCH] counter: 104-quad-8: Support Differential Encoder Cable Status William Breathitt Gray
@ 2020-03-01 20:14 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-03-01 20:14 UTC (permalink / raw)
  To: William Breathitt Gray; +Cc: linux-iio, linux-kernel

On Sat, 22 Feb 2020 10:43:40 -0500
William Breathitt Gray <vilhelm.gray@gmail.com> wrote:

> The ACCES 104-QUAD-8 series provides status information about the
> connection state of the differential encoder cable inputs. This patch
> implements support to expose such information from these devices.
> 
> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>

Hi William,  Couple of things on the interface...

> ---
>  .../ABI/testing/sysfs-bus-counter-104-quad-8  | 12 ++++++
>  drivers/counter/104-quad-8.c                  | 38 +++++++++++++++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8 b/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
> index 46b1f33b2fce..492b3e98f369 100644
> --- a/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
> +++ b/Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
> @@ -1,3 +1,15 @@
> +What:		/sys/bus/counter/devices/counterX/cable_status
> +KernelVersion:	5.7
> +Contact:	linux-iio@vger.kernel.org
> +Description:
> +		Differential encoder cable status; bits 0 through 7
> +		correspond to channels 1 through 8. Writing a 0 to the
> +		corresponding bit will enable the status of the
> +		respective channel.
I'm never personally that keen on cases where a sysfs file doesn't have
inherent 'obviousness'.  In this case we have a bitmap that doesn't make that
clear and that also that doesn't have particularly obviously meaning either
on the write or read.

Hmm.  So if you wanted to keep it as a bitmap perhaps something like...

cable_test_bitmap

So a 1 (or true) would be a successful cable test on read.  However that is
still not obviously something that needs an enable.  It think you need to
split it.

*_enable
*_status 

Next question is whether it should be a map like this?  sysfs rules are usually
one value to one sysfs file.    It might seem wasteful but I'd like to see something
like

cable0_test_enable
cable0_test_status
cable7_test_enable
cable7_test_status

I haven't thought about whether this could be fit better with the counter ABI
but something along those lines!

> +
> +		Logic 0 = cable fault (not connected or loose wires)
> +		Logic 1 = cable connection good or cable fault disabled
> +
>  What:		/sys/bus/counter/devices/counterX/signalY/index_polarity
>  KernelVersion:	5.2
>  Contact:	linux-iio@vger.kernel.org
> diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
> index 17e67a84777d..1cbaf7e100a3 100644
> --- a/drivers/counter/104-quad-8.c
> +++ b/drivers/counter/104-quad-8.c
> @@ -56,6 +56,7 @@ struct quad8_iio {
>  
>  #define QUAD8_REG_CHAN_OP 0x11
>  #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16
> +#define QUAD8_DIFF_ENCODER_CABLE_STATUS 0x17
>  /* Borrow Toggle flip-flop */
>  #define QUAD8_FLAG_BT BIT(0)
>  /* Carry Toggle flip-flop */
> @@ -1268,6 +1269,42 @@ static struct counter_count quad8_counts[] = {
>  	QUAD8_COUNT(7, "Channel 8 Count")
>  };
>  
> +static ssize_t quad8_cable_status_read(struct counter_device *counter,
> +				       void *private, char *buf)
> +{
> +	const struct quad8_iio *const priv = counter->priv;
> +	unsigned int status;
> +
> +	status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
> +
> +	return sprintf(buf, "0x%X\n", status);
> +}
> +
> +static ssize_t quad8_cable_status_write(struct counter_device *counter,
> +					void *private, const char *buf,
> +					size_t len)
> +{
> +	struct quad8_iio *const priv = counter->priv;
> +	u8 enable;
> +	int ret;
> +
> +	ret = kstrtou8(buf, 0, &enable);
> +	if (ret)
> +		return ret;
> +
> +	outb(enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
> +
> +	return len;
> +}
> +
> +static const struct counter_device_ext quad8_device_ext[] = {
> +	{
> +		.name = "cable_status",
> +		.read = quad8_cable_status_read,
> +		.write = quad8_cable_status_write
> +	}
> +};
> +
>  static int quad8_probe(struct device *dev, unsigned int id)
>  {
>  	struct iio_dev *indio_dev;
> @@ -1304,6 +1341,7 @@ static int quad8_probe(struct device *dev, unsigned int id)
>  	quad8iio->counter.num_counts = ARRAY_SIZE(quad8_counts);
>  	quad8iio->counter.signals = quad8_signals;
>  	quad8iio->counter.num_signals = ARRAY_SIZE(quad8_signals);
> +	quad8iio->counter.ext = quad8_device_ext;
>  	quad8iio->counter.priv = quad8iio;
>  	quad8iio->base = base[id];
>  


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

end of thread, other threads:[~2020-03-01 20:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-22 15:43 [PATCH] counter: 104-quad-8: Support Differential Encoder Cable Status William Breathitt Gray
2020-03-01 20:14 ` Jonathan Cameron

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).