From: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
To: <broonie@kernel.org>
Cc: <gregkh@linuxfoundation.org>, <stefan@agner.ch>,
<linux-kernel@vger.kernel.org>, <linux-spi@vger.kernel.org>,
Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>,
Stefan Agner <stefan.agner@toradex.com>
Subject: [RFC 2/2] spi core: Add new sysfs 'num_chipselect' file
Date: Mon, 18 Apr 2016 16:48:28 +0530 [thread overview]
Message-ID: <1460978308-8062-3-git-send-email-bhuvanchandra.dv@toradex.com> (raw)
In-Reply-To: <1460978308-8062-1-git-send-email-bhuvanchandra.dv@toradex.com>
Add new sysfs 'num_chipselect' file to expose the maximum number
of chipselects a SPI master can support.
This allows to create a script in user space which automatically
creates a new spidev instance for every chipselect on a bus.
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
---
Documentation/spi/spi-summary | 3 +++
drivers/spi/spi.c | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
index d1824b3..b4d15e4 100644
--- a/Documentation/spi/spi-summary
+++ b/Documentation/spi/spi-summary
@@ -181,6 +181,9 @@ shows up in sysfs in several locations:
controller managing bus "B". All spiB.* devices share one
physical SPI bus segment, with SCLK, MOSI, and MISO.
+ /sys/class/spi_master/spiB/num_chipselect ... exposes the maximum
+ number of chipselects a SPI master can support.
+
Note that the actual location of the controller's class state depends
on whether you enabled CONFIG_SYSFS_DEPRECATED or not. At this time,
the only class-specific state is the bus number ("B" in "spiB"), so
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index de2f2f9..c3eb29f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -67,6 +67,19 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
}
static DEVICE_ATTR_RO(modalias);
+static ssize_t
+num_chipselect_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+ struct spi_master *master = container_of(dev,
+ struct spi_master, dev);
+
+ return sprintf(buf, "%d\n", master->num_chipselect);
+}
+static struct device_attribute dev_attr_num_chipselect = {
+ .attr = { .name = "num_chipselect", .mode = S_IRUGO },
+ .show = num_chipselect_show,
+};
+
#define SPI_STATISTICS_ATTRS(field, file) \
static ssize_t spi_master_##field##_show(struct device *dev, \
struct device_attribute *attr, \
@@ -155,6 +168,15 @@ static const struct attribute_group spi_dev_group = {
.attrs = spi_dev_attrs,
};
+static struct attribute *spi_master_attrs[] = {
+ &dev_attr_num_chipselect.attr,
+ NULL,
+};
+
+static const struct attribute_group spi_master_group = {
+ .attrs = spi_master_attrs,
+};
+
static struct attribute *spi_device_statistics_attrs[] = {
&dev_attr_spi_device_messages.attr,
&dev_attr_spi_device_transfers.attr,
@@ -236,6 +258,7 @@ static const struct attribute_group spi_master_statistics_group = {
};
static const struct attribute_group *spi_master_groups[] = {
+ &spi_master_group,
&spi_master_statistics_group,
NULL,
};
--
2.7.3
next prev parent reply other threads:[~2016-04-18 11:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-18 11:18 [RFC 0/2] sysfs new_id file support for spidev Bhuvanchandra DV
2016-04-18 11:18 ` [RFC 1/2] spi: spidev: Use 'new_id' sysfs file for enabling spidev Bhuvanchandra DV
2016-04-18 13:01 ` Mark Brown
2016-04-20 12:13 ` Bhuvanchandra DV
2016-04-20 12:17 ` Mark Brown
2016-04-20 13:11 ` Bhuvanchandra DV
2016-04-20 13:52 ` Mark Brown
2016-04-18 11:18 ` Bhuvanchandra DV [this message]
2016-04-18 12:14 ` [RFC 2/2] spi core: Add new sysfs 'num_chipselect' file Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460978308-8062-3-git-send-email-bhuvanchandra.dv@toradex.com \
--to=bhuvanchandra.dv@toradex.com \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=stefan.agner@toradex.com \
--cc=stefan@agner.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®