From: Vinod Koul <vkoul@kernel.org>
To: alsa-devel@alsa-project.org
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Sanyog Kale <sanyog.r.kale@intel.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
Vinod Koul <vkoul@kernel.org>
Subject: [PATCH] soundwire: add slave status as a sysfs file
Date: Thu, 10 Sep 2020 19:33:49 +0530 [thread overview]
Message-ID: <20200910140349.681739-1-vkoul@kernel.org> (raw)
SoundWire Slave status is not reported in the sysfs, so add this file
with string values for status to userspace. Users can look into this
file to see the Slave status at that point of time.
Signed-off-by: Vinod Koul <vkoul@kernel.org>
---
On RB3 it shows as:
root@linaro-alip:/sys/bus/soundwire/devices# cat sdw:0:217:2010:0:1/status
Attached
root@linaro-alip:/sys/bus/soundwire/devices# cat sdw:0:217:2010:0:2/status
Attached
.../ABI/testing/sysfs-bus-soundwire-slave | 7 +++++++
drivers/soundwire/sysfs_slave.c | 17 +++++++++++++++++
include/linux/soundwire/sdw.h | 2 ++
3 files changed, 26 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-soundwire-slave b/Documentation/ABI/testing/sysfs-bus-soundwire-slave
index db4c9511d1aa..8a64f8e9079a 100644
--- a/Documentation/ABI/testing/sysfs-bus-soundwire-slave
+++ b/Documentation/ABI/testing/sysfs-bus-soundwire-slave
@@ -89,3 +89,10 @@ Description: SoundWire Slave Data Source/Sink Port-N DisCo properties.
for SoundWire. They define various properties of the
Source/Sink Data port N and are used by the bus to configure
the Data Port N.
+
+What: /sys/bus/soundwire/devices/sdw:.../status
+Date: September 2020
+Contact: Vinod Koul <vkoul@kernel.org>
+Description: Soundwire Slave status
+ This reports the current status of the slave, e.g if it is
+ UNATTACHED, Attached, Alert or Reserved
diff --git a/drivers/soundwire/sysfs_slave.c b/drivers/soundwire/sysfs_slave.c
index f510071b0add..3d2cc7612d0d 100644
--- a/drivers/soundwire/sysfs_slave.c
+++ b/drivers/soundwire/sysfs_slave.c
@@ -97,8 +97,25 @@ static ssize_t modalias_show(struct device *dev,
}
static DEVICE_ATTR_RO(modalias);
+static const char *const slave_status[SDW_SLAVE_MAX] = {
+ [SDW_SLAVE_UNATTACHED] = "UNATTACHED",
+ [SDW_SLAVE_ATTACHED] = "Attached",
+ [SDW_SLAVE_ALERT] = "Alert",
+ [SDW_SLAVE_RESERVED] = "Reserved",
+};
+
+static ssize_t status_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct sdw_slave *slave = dev_to_sdw_dev(dev);
+
+ return sprintf(buf, "%s\n", slave_status[slave->status]);
+}
+static DEVICE_ATTR_RO(status);
+
static struct attribute *slave_attrs[] = {
&dev_attr_modalias.attr,
+ &dev_attr_status.attr,
NULL,
};
ATTRIBUTE_GROUPS(slave);
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 790823d2d33b..e8c9c20d38b0 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -73,12 +73,14 @@ enum {
* @SDW_SLAVE_ATTACHED: Slave is attached with bus.
* @SDW_SLAVE_ALERT: Some alert condition on the Slave
* @SDW_SLAVE_RESERVED: Reserved for future use
+ * @SDW_SLAVE_MAX: Last status value
*/
enum sdw_slave_status {
SDW_SLAVE_UNATTACHED = 0,
SDW_SLAVE_ATTACHED = 1,
SDW_SLAVE_ALERT = 2,
SDW_SLAVE_RESERVED = 3,
+ SDW_SLAVE_MAX,
};
/**
--
2.26.2
next reply other threads:[~2020-09-10 14:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 14:03 Vinod Koul [this message]
2020-09-10 14:06 ` [PATCH] soundwire: add slave status as a sysfs file Pierre-Louis Bossart
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=20200910140349.681739-1-vkoul@kernel.org \
--to=vkoul@kernel.org \
--cc=alsa-devel@alsa-project.org \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=sanyog.r.kale@intel.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=yung-chuan.liao@linux.intel.com \
/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