Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1559890ybf; Sun, 1 Mar 2020 12:15:30 -0800 (PST) X-Google-Smtp-Source: APXvYqz2G5szXQ8j92wEVfIFRRK1OfN5VKCKkZYEc9H0STSNynSrCIMn3RuPjOQgDxlYDtSLVc6e X-Received: by 2002:a54:4f16:: with SMTP id e22mr9845914oiy.170.1583093730228; Sun, 01 Mar 2020 12:15:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583093730; cv=none; d=google.com; s=arc-20160816; b=YMcZsfUayet74xbBpSi7TbiyH+8jOai16RL4V+aKPEYvmb+MF0VA/2Zv3ArhRhTHVD LqAEuDwJXbPwQ282FN5M+lSc6QK6cJi+kW9ljoqioQTbU1zKGrZT4mt1kx+ccooQeVWU wUgDxyB4sCYdgLonzmBRkQA+4ZqHDXPgYU9SNiFbgOyzwEO2WZUDhO4OYZK4xWIZ+jqk Oo5Z2iKbnTsYuKaSDAOC8qRz1FFfJioi8pDppE3PPygFxyX8mGc6HqvP0jzxPf9du+0A qRh8fufySVurMLgKtoIMoR9XV2xtzeH1hjGjG8TW+iwom+VY7jikyNgtwRyHRXRABrte /UAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9D6dYdUoKcRC2LxdHm7jbKe8s+RJn8X7q+E9035wsNA=; b=YJscVOd6o879LlZ6TsWnyE4m82H8SbGOTbzSuu7QzifDuW4vtlCC0ittkTbkrUYAJG dLEqpFm6RS2YIsuI58v+8YgVFaIEesluPf+gNnyRiLvKFVy23S+SEhuVsshOhEIR51yW yp7mdD2ow51mGRA0WvbgRq7sqWSuBc55c2cZjQRqd8XKjhs2ssTbVQBjJ2jgfwOueA2H GKu7akZ9ntbHavbauNYN4+THyuiATiNYh0Y3am1n7ThqQidXBlGmeS7r9zndEwAnt2eM xv31uiLqe47MPRRixry65bTEv/KwzyI1m90Fz9J8oUelo019pfXa/zwSOlZnsq0rdUWf RvLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gxakopvh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si3652341oth.163.2020.03.01.12.15.17; Sun, 01 Mar 2020 12:15:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gxakopvh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbgCAUPI (ORCPT + 99 others); Sun, 1 Mar 2020 15:15:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:37664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAUPI (ORCPT ); Sun, 1 Mar 2020 15:15:08 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A80C21744; Sun, 1 Mar 2020 20:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583093707; bh=xtHhfpQG1yNXRNMNT7O6zsFDLkfakTVUMH4y2fI2GJA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gxakopvh+tUV+Eu06cPEBz16rMeAWxtnUb2ghQOQszKvCG8FWytrO8Ix8JVJOJj3m 0gSKhdnXZWAxm3fqosod1nis+1uEwyiGyFBXiGcuS7koocNlsuV7RFAKQVbZS952J0 CqChhPwbbOMQO8THcMqqGo4ILvG15zZIECN74I7E= Date: Sun, 1 Mar 2020 20:14:58 +0000 From: Jonathan Cameron To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] counter: 104-quad-8: Support Differential Encoder Cable Status Message-ID: <20200301201458.4dcce64c@archlinux> In-Reply-To: <20200222154340.89464-1-vilhelm.gray@gmail.com> References: <20200222154340.89464-1-vilhelm.gray@gmail.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 22 Feb 2020 10:43:40 -0500 William Breathitt Gray 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 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]; >