+What:          /sys/bus/soundwire/devices/sdw:.../status
+               /sys/bus/soundwire/devices/sdw:.../device_number
+
+Date:          September 2020
+
+Contact:       Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
+               Bard Liao <yung-chuan.liao@linux.intel.com>
+               Vinod Koul <vkoul@kernel.org>
+
+Description:   SoundWire Slave status
+
+               These properties report the Slave status, e.g. if it
+               is UNATTACHED or not, and in the latter case show the
+               device_number. This status information is useful to
+               detect devices exposed by platform firmware but not
+               physically present on the bus, and conversely devices
+               not exposed in platform firmware but enumerated.
+
 What:          /sys/bus/soundwire/devices/sdw:.../dev-properties/mipi_revision
                /sys/bus/soundwire/devices/sdw:.../dev-properties/wake_capable
                /sys/bus/soundwire/devices/sdw:.../dev-properties/test_mode_capable
 
 #include <linux/soundwire/sdw.h>
 #include <linux/soundwire/sdw_type.h>
 #include "bus.h"
+#include "sysfs_local.h"
 
 static void sdw_slave_release(struct device *dev)
 {
        slave->dev.bus = &sdw_bus_type;
        slave->dev.of_node = of_node_get(to_of_node(fwnode));
        slave->dev.type = &sdw_slave_type;
+       slave->dev.groups = sdw_slave_status_attr_groups;
        slave->bus = bus;
        slave->status = SDW_SLAVE_UNATTACHED;
        init_completion(&slave->enumeration_complete);
 
 
 /*
  * The sysfs for Slave reflects the MIPI description as given
- * in the MIPI DisCo spec
+ * in the MIPI DisCo spec.
+ * status and device_number come directly from the MIPI SoundWire
+ * 1.x specification.
  *
  * Base file is device
+ *     |---- status
+ *     |---- device_number
  *     |---- modalias
  *     |---- dev-properties
  *             |---- mipi_revision
 
        return 0;
 }
+
+/*
+ * the status is shown in capital letters for UNATTACHED and RESERVED
+ * on purpose, to highligh users to the fact that these status values
+ * are not expected.
+ */
+static const char *const slave_status[] = {
+       [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 ssize_t device_number_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct sdw_slave *slave = dev_to_sdw_dev(dev);
+
+       if (slave->status == SDW_SLAVE_UNATTACHED)
+               return sprintf(buf, "%s", "N/A");
+       else
+               return sprintf(buf, "%d", slave->dev_num);
+}
+static DEVICE_ATTR_RO(device_number);
+
+static struct attribute *slave_status_attrs[] = {
+       &dev_attr_status.attr,
+       &dev_attr_device_number.attr,
+       NULL,
+};
+
+/*
+ * we don't use ATTRIBUTES_GROUP here since the group is used in a
+ * separate file and can't be handled as a static.
+ */
+static const struct attribute_group sdw_slave_status_attr_group = {
+       .attrs  = slave_status_attrs,
+};
+
+const struct attribute_group *sdw_slave_status_attr_groups[] = {
+       &sdw_slave_status_attr_group,
+       NULL
+};