diff mbox

[v4,03/15] soundwire: Add Master registration

Message ID 1512122177-2889-4-git-send-email-vinod.koul@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vinod Koul Dec. 1, 2017, 9:56 a.m. UTC
A Master registers with SoundWire bus and scans the firmware provided
for device description. In this patch we scan the ACPI namespaces and
create the SoundWire Slave devices based on the ACPI description

Signed-off-by: Sanyog Kale <sanyog.r.kale@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
---
 drivers/soundwire/Makefile    |   2 +-
 drivers/soundwire/bus.c       | 119 ++++++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/bus.h       |  19 +++++++
 drivers/soundwire/slave.c     | 114 ++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  11 ++++
 5 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/bus.c
 create mode 100644 drivers/soundwire/bus.h
 create mode 100644 drivers/soundwire/slave.c

Comments

Pierre-Louis Bossart Dec. 1, 2017, 10:10 p.m. UTC | #1
On 12/1/17 3:56 AM, Vinod Koul wrote:
> A Master registers with SoundWire bus and scans the firmware provided

nitpick: is the 'register' correct? You create a bus instance for each 
hardware master interface. Or is my brain fried?

> for device description. In this patch we scan the ACPI namespaces and
> create the SoundWire Slave devices based on the ACPI description
> 
> Signed-off-by: Sanyog Kale <sanyog.r.kale@intel.com>
> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
> ---
>   drivers/soundwire/Makefile    |   2 +-
>   drivers/soundwire/bus.c       | 119 ++++++++++++++++++++++++++++++++++++++++++
>   drivers/soundwire/bus.h       |  19 +++++++
>   drivers/soundwire/slave.c     | 114 ++++++++++++++++++++++++++++++++++++++++
>   include/linux/soundwire/sdw.h |  11 ++++
>   5 files changed, 264 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/soundwire/bus.c
>   create mode 100644 drivers/soundwire/bus.h
>   create mode 100644 drivers/soundwire/slave.c
> 
> diff --git a/drivers/soundwire/Makefile b/drivers/soundwire/Makefile
> index d1281def7662..c875e434f8b3 100644
> --- a/drivers/soundwire/Makefile
> +++ b/drivers/soundwire/Makefile
> @@ -3,5 +3,5 @@
>   #
>   
>   #Bus Objs
> -soundwire-bus-objs := bus_type.o
> +soundwire-bus-objs := bus_type.o bus.o slave.o
>   obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
> diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
> new file mode 100644
> index 000000000000..0f89b2f36938
> --- /dev/null
> +++ b/drivers/soundwire/bus.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
> +// Copyright(c) 2015-17 Intel Corporation.
> +
> +#include <linux/acpi.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/soundwire/sdw.h>
> +#include "bus.h"
> +
> +/**
> + * sdw_add_bus_master() - add a bus Master instance
> + * @bus: bus instance
> + *
> + * Initializes the bus instance, read properties and create child
> + * devices.
> + */
> +int sdw_add_bus_master(struct sdw_bus *bus)
> +{
> +	int ret;
> +
> +	if (!bus->dev) {
> +		pr_err("SoundWire bus has no device");
> +		return -ENODEV;
> +	}
> +
> +	mutex_init(&bus->bus_lock);
> +	INIT_LIST_HEAD(&bus->slaves);
> +
> +	/*
> +	 * Device numbers in SoundWire are 0 thru 15 with 0 being
> +	 * Enumeration device number and 15 broadcast device number. So
> +	 * they are not used for assignment so mask these and other
> +	 * higher bits

device 14 is used for the master and is not supported by these patches.
While allowed, if you use device 12 and 13 (groups) you can't get the 
status information in a PING command so the recommendation is to avoid them.
Those device numbers should never be used really (on top of 0 and 15 as 
explained above)

> +	 */
> +
> +	/* Set higher order bits */
> +	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);
> +
> +	/* Set device number and broadcast device number */
> +	set_bit(SDW_ENUM_DEV_NUM, bus->assigned);
> +	set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned);
> +
> +	/*
> +	 * SDW is an enumerable bus, but devices can be powered off. So,
> +	 * they won't be able to report as present.
> +	 *
> +	 * Create Slave devices based on Slaves described in
> +	 * the respective firmware (ACPI/DT)
> +	 */
> +	if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(bus->dev))
> +		ret = sdw_acpi_find_slaves(bus);
> +	else
> +		ret = -ENOTSUPP; /* No ACPI/DT so error out */
> +
> +	if (ret) {
> +		dev_err(bus->dev, "Finding slaves failed:%d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(sdw_add_bus_master);
> +
> +static int sdw_delete_slave(struct device *dev, void *data)
> +{
> +	struct sdw_slave *slave = dev_to_sdw_dev(dev);
> +	struct sdw_bus *bus = slave->bus;
> +
> +	mutex_lock(&bus->bus_lock);
> +
> +	if (slave->dev_num) /* clear dev_num if assigned */
> +		clear_bit(slave->dev_num, bus->assigned);
> +
> +	list_del_init(&slave->node);
> +	mutex_unlock(&bus->bus_lock);
> +
> +	device_unregister(dev);
> +	return 0;
> +}
> +
> +/**
> + * sdw_delete_bus_master() - delete the bus master instance
> + * @bus: bus to be deleted
> + *
> + * Remove the instance, delete the child devices.
> + */
> +void sdw_delete_bus_master(struct sdw_bus *bus)
> +{
> +	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
> +}
> +EXPORT_SYMBOL(sdw_delete_bus_master);
> +
> +void sdw_extract_slave_id(struct sdw_bus *bus,
> +			u64 addr, struct sdw_slave_id *id)
> +{
> +	dev_dbg(bus->dev, "SDW Slave Addr: %llx", addr);
> +
> +	/*
> +	 * Spec definition
> +	 *   Register		Bit	Contents
> +	 *   DevId_0 [7:4]	47:44	sdw_version
> +	 *   DevId_0 [3:0]	43:40	unique_id
> +	 *   DevId_1		39:32	mfg_id [15:8]
> +	 *   DevId_2		31:24	mfg_id [7:0]

Add a reference to mid.mipi.org (here or in the summary) ?

> +	 *   DevId_3		23:16	part_id [15:8]
> +	 *   DevId_4		15:08	part_id [7:0]
> +	 *   DevId_5		07:00	class_id
> +	 */
> +	id->sdw_version = (addr >> 44) & GENMASK(3, 0);
> +	id->unique_id = (addr >> 40) & GENMASK(3, 0);
> +	id->mfg_id = (addr >> 24) & GENMASK(15, 0);
> +	id->part_id = (addr >> 8) & GENMASK(15, 0);
> +	id->class_id = addr & GENMASK(7, 0);
> +
> +	dev_dbg(bus->dev,
> +		"SDW Slave class_id %x, part_id %x, mfg_id %x, unique_id %x, version %x",
> +				id->class_id, id->part_id, id->mfg_id,
> +				id->unique_id, id->sdw_version);
> +
> +}
> diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h
> new file mode 100644
> index 000000000000..a54921825ce0
> --- /dev/null
> +++ b/drivers/soundwire/bus.h
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
> +// Copyright(c) 2015-17 Intel Corporation.
> +
> +#ifndef __SDW_BUS_H
> +#define __SDW_BUS_H
> +
> +#if IS_ENABLED(CONFIG_ACPI)
> +int sdw_acpi_find_slaves(struct sdw_bus *bus);
> +#else
> +static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
> +{
> +	return -ENOTSUPP;
> +}
> +#endif
> +
> +void sdw_extract_slave_id(struct sdw_bus *bus,
> +			u64 addr, struct sdw_slave_id *id);
> +
> +#endif /* __SDW_BUS_H */
> diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
> new file mode 100644
> index 000000000000..397e100d66e3
> --- /dev/null
> +++ b/drivers/soundwire/slave.c
> @@ -0,0 +1,114 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
> +// Copyright(c) 2015-17 Intel Corporation.
> +
> +#include <linux/acpi.h>
> +#include <linux/soundwire/sdw.h>
> +#include <linux/soundwire/sdw_type.h>
> +#include "bus.h"
> +
> +static void sdw_slave_release(struct device *dev)
> +{
> +	struct sdw_slave *slave = dev_to_sdw_dev(dev);
> +
> +	kfree(slave);
> +}
> +
> +static int sdw_slave_add(struct sdw_bus *bus,
> +		struct sdw_slave_id *id, struct fwnode_handle *fwnode)
> +{
> +	struct sdw_slave *slave;
> +	int ret;
> +
> +	slave = kzalloc(sizeof(*slave), GFP_KERNEL);
> +	if (!slave)
> +		return -ENOMEM;
> +
> +	/* Initialize data structure */
> +	memcpy(&slave->id, id, sizeof(*id));
> +	slave->dev.parent = bus->dev;
> +	slave->dev.fwnode = fwnode;
> +
> +	/* name shall be sdw:link:mfg:part:class:unique */
> +	dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
> +			bus->link_id, id->mfg_id, id->part_id,
> +			id->class_id, id->unique_id);
> +
> +	slave->dev.release = sdw_slave_release;
> +	slave->dev.bus = &sdw_bus_type;
> +	slave->bus = bus;
> +	slave->status = SDW_SLAVE_UNATTACHED;
> +	slave->dev_num = 0;
> +
> +	mutex_lock(&bus->bus_lock);
> +	list_add_tail(&slave->node, &bus->slaves);
> +	mutex_unlock(&bus->bus_lock);
> +
> +	ret = device_register(&slave->dev);
> +	if (ret) {
> +		dev_err(bus->dev, "Failed to add slave: ret %d\n", ret);
> +
> +		/*
> +		 * On err, don't free but drop ref as this will be freed
> +		 * when release method is invoked.
> +		 */
> +		mutex_lock(&bus->bus_lock);
> +		list_del(&slave->node);
> +		mutex_unlock(&bus->bus_lock);
> +		put_device(&slave->dev);
> +	}
> +
> +	return ret;
> +}
> +
> +#if IS_ENABLED(CONFIG_ACPI)
> +/*
> + * sdw_acpi_find_slaves() - Find Slave devices in Master ACPI node
> + * @bus: SDW bus instance
> + *
> + * Scans Master ACPI node for SDW child Slave devices and registers it.
> + */
> +int sdw_acpi_find_slaves(struct sdw_bus *bus)
> +{
> +	struct acpi_device *adev, *parent;
> +
> +	parent = ACPI_COMPANION(bus->dev);
> +	if (!parent) {
> +		dev_err(bus->dev, "Can't find parent for acpi bind\n");
> +		return -ENODEV;
> +	}
> +
> +	list_for_each_entry(adev, &parent->children, node) {
> +		unsigned long long addr;
> +		struct sdw_slave_id id;
> +		unsigned int link_id;
> +		acpi_status status;
> +
> +		status = acpi_evaluate_integer(adev->handle,
> +					METHOD_NAME__ADR, NULL, &addr);
> +
> +		if (ACPI_FAILURE(status)) {
> +			dev_err(bus->dev, "_ADR resolution failed: %x\n",
> +							status);
> +			return status;
> +		}
> +
> +		/* Extract link id from ADR, it is from 48 to 51 bits */

nitpick: in bits 51..48 as defined in the MIPI SoundWire DisCo spec.

> +		link_id = (addr >> 48) & GENMASK(3, 0);
> +
> +		/* Check for link_id match */
> +		if (link_id != bus->link_id)
> +			continue;
> +
> +		sdw_extract_slave_id(bus, addr, &id);
> +
> +		/*
> +		 * don't error check for sdw_slave_add as we want to continue
> +		 * adding Slaves
> +		 */
> +		sdw_slave_add(bus, &id, acpi_fwnode_handle(adev));
> +	}
> +
> +	return 0;
> +}
> +
> +#endif
> diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
> index 4a7503781602..7e9579941c66 100644
> --- a/include/linux/soundwire/sdw.h
> +++ b/include/linux/soundwire/sdw.h
> @@ -7,6 +7,14 @@
>   struct sdw_bus;
>   struct sdw_slave;
>   
> +/* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
> +
> +/* SDW Broadcast Device Number */
> +#define SDW_BROADCAST_DEV_NUM		15
> +
> +/* SDW Enumeration Device Number */
> +#define SDW_ENUM_DEV_NUM		0

add
SDW_GROUP12_DEV_NUM		12
SDW_GROUP12_DEV_NUM		13
SDW_MASTER_DEV_NUM		14 /* not supported in these patches */

> +
>   #define SDW_MAX_DEVICES			11
>   
>   /**
> @@ -108,4 +116,7 @@ struct sdw_bus {
>   	struct mutex bus_lock;
>   };
>   
> +int sdw_add_bus_master(struct sdw_bus *bus);
> +void sdw_delete_bus_master(struct sdw_bus *bus);
> +
>   #endif /* __SOUNDWIRE_H */
>
Vinod Koul Dec. 3, 2017, 4:41 p.m. UTC | #2
On Fri, Dec 01, 2017 at 04:10:55PM -0600, Pierre-Louis Bossart wrote:
> On 12/1/17 3:56 AM, Vinod Koul wrote:
> >A Master registers with SoundWire bus and scans the firmware provided
> 
> nitpick: is the 'register' correct? You create a bus instance for each
> hardware master interface. Or is my brain fried?

naah, thankfully it is not :)

I will reword this, I see it can cause ambguity :)

> >+int sdw_add_bus_master(struct sdw_bus *bus)
> >+{
> >+	int ret;
> >+
> >+	if (!bus->dev) {
> >+		pr_err("SoundWire bus has no device");
> >+		return -ENODEV;
> >+	}
> >+
> >+	mutex_init(&bus->bus_lock);
> >+	INIT_LIST_HEAD(&bus->slaves);
> >+
> >+	/*
> >+	 * Device numbers in SoundWire are 0 thru 15 with 0 being
> >+	 * Enumeration device number and 15 broadcast device number. So
> >+	 * they are not used for assignment so mask these and other
> >+	 * higher bits
> 
> device 14 is used for the master and is not supported by these patches.
> While allowed, if you use device 12 and 13 (groups) you can't get the status
> information in a PING command so the recommendation is to avoid them.
> Those device numbers should never be used really (on top of 0 and 15 as
> explained above)

Yeah we should also exclude 12 thru 14 here. The group alllocation when done
need to do differently that this one, so will mask those too.

> >+void sdw_extract_slave_id(struct sdw_bus *bus,
> >+			u64 addr, struct sdw_slave_id *id)
> >+{
> >+	dev_dbg(bus->dev, "SDW Slave Addr: %llx", addr);
> >+
> >+	/*
> >+	 * Spec definition
> >+	 *   Register		Bit	Contents
> >+	 *   DevId_0 [7:4]	47:44	sdw_version
> >+	 *   DevId_0 [3:0]	43:40	unique_id
> >+	 *   DevId_1		39:32	mfg_id [15:8]
> >+	 *   DevId_2		31:24	mfg_id [7:0]
> 
> Add a reference to mid.mipi.org (here or in the summary) ?

Will add in summary, makes sense on that page

> >+int sdw_acpi_find_slaves(struct sdw_bus *bus)
> >+{
> >+	struct acpi_device *adev, *parent;
> >+
> >+	parent = ACPI_COMPANION(bus->dev);
> >+	if (!parent) {
> >+		dev_err(bus->dev, "Can't find parent for acpi bind\n");
> >+		return -ENODEV;
> >+	}
> >+
> >+	list_for_each_entry(adev, &parent->children, node) {
> >+		unsigned long long addr;
> >+		struct sdw_slave_id id;
> >+		unsigned int link_id;
> >+		acpi_status status;
> >+
> >+		status = acpi_evaluate_integer(adev->handle,
> >+					METHOD_NAME__ADR, NULL, &addr);
> >+
> >+		if (ACPI_FAILURE(status)) {
> >+			dev_err(bus->dev, "_ADR resolution failed: %x\n",
> >+							status);
> >+			return status;
> >+		}
> >+
> >+		/* Extract link id from ADR, it is from 48 to 51 bits */
> 
> nitpick: in bits 51..48 as defined in the MIPI SoundWire DisCo spec.

ok

> >+/* SDW Enumeration Device Number */
> >+#define SDW_ENUM_DEV_NUM		0
> 
> add
> SDW_GROUP12_DEV_NUM		12
> SDW_GROUP12_DEV_NUM		13

you mean SDW_GROUP13_DEV_NUM :D

> SDW_MASTER_DEV_NUM		14 /* not supported in these patches */

These dont help now as we dont support, so kind of dead code.
Lets add them when we really support it
Pierre-Louis Bossart Dec. 4, 2017, 2:44 a.m. UTC | #3
>>> +/* SDW Enumeration Device Number */
>>> +#define SDW_ENUM_DEV_NUM		0
>>
>> add
>> SDW_GROUP12_DEV_NUM		12
>> SDW_GROUP12_DEV_NUM		13
> 
> you mean SDW_GROUP13_DEV_NUM :D
> 
>> SDW_MASTER_DEV_NUM		14 /* not supported in these patches */
> 
> These dont help now as we dont support, so kind of dead code.
> Lets add them when we really support it

It was a way to explain why device 14 is never allocated.
Vinod Koul Dec. 4, 2017, 2:59 a.m. UTC | #4
On Sun, Dec 03, 2017 at 08:44:58PM -0600, Pierre-Louis Bossart wrote:
> 
> >>>+/* SDW Enumeration Device Number */
> >>>+#define SDW_ENUM_DEV_NUM		0
> >>
> >>add
> >>SDW_GROUP12_DEV_NUM		12
> >>SDW_GROUP12_DEV_NUM		13
> >
> >you mean SDW_GROUP13_DEV_NUM :D
> >
> >>SDW_MASTER_DEV_NUM		14 /* not supported in these patches */
> >
> >These dont help now as we dont support, so kind of dead code.
> >Lets add them when we really support it
> 
> It was a way to explain why device 14 is never allocated.

Rethinking about it, i need these defines anyway for masking them
out now, so will add
diff mbox

Patch

diff --git a/drivers/soundwire/Makefile b/drivers/soundwire/Makefile
index d1281def7662..c875e434f8b3 100644
--- a/drivers/soundwire/Makefile
+++ b/drivers/soundwire/Makefile
@@ -3,5 +3,5 @@ 
 #
 
 #Bus Objs
-soundwire-bus-objs := bus_type.o
+soundwire-bus-objs := bus_type.o bus.o slave.o
 obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
new file mode 100644
index 000000000000..0f89b2f36938
--- /dev/null
+++ b/drivers/soundwire/bus.c
@@ -0,0 +1,119 @@ 
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+// Copyright(c) 2015-17 Intel Corporation.
+
+#include <linux/acpi.h>
+#include <linux/mod_devicetable.h>
+#include <linux/soundwire/sdw.h>
+#include "bus.h"
+
+/**
+ * sdw_add_bus_master() - add a bus Master instance
+ * @bus: bus instance
+ *
+ * Initializes the bus instance, read properties and create child
+ * devices.
+ */
+int sdw_add_bus_master(struct sdw_bus *bus)
+{
+	int ret;
+
+	if (!bus->dev) {
+		pr_err("SoundWire bus has no device");
+		return -ENODEV;
+	}
+
+	mutex_init(&bus->bus_lock);
+	INIT_LIST_HEAD(&bus->slaves);
+
+	/*
+	 * Device numbers in SoundWire are 0 thru 15 with 0 being
+	 * Enumeration device number and 15 broadcast device number. So
+	 * they are not used for assignment so mask these and other
+	 * higher bits
+	 */
+
+	/* Set higher order bits */
+	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);
+
+	/* Set device number and broadcast device number */
+	set_bit(SDW_ENUM_DEV_NUM, bus->assigned);
+	set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned);
+
+	/*
+	 * SDW is an enumerable bus, but devices can be powered off. So,
+	 * they won't be able to report as present.
+	 *
+	 * Create Slave devices based on Slaves described in
+	 * the respective firmware (ACPI/DT)
+	 */
+	if (IS_ENABLED(CONFIG_ACPI) && ACPI_HANDLE(bus->dev))
+		ret = sdw_acpi_find_slaves(bus);
+	else
+		ret = -ENOTSUPP; /* No ACPI/DT so error out */
+
+	if (ret) {
+		dev_err(bus->dev, "Finding slaves failed:%d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(sdw_add_bus_master);
+
+static int sdw_delete_slave(struct device *dev, void *data)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+	struct sdw_bus *bus = slave->bus;
+
+	mutex_lock(&bus->bus_lock);
+
+	if (slave->dev_num) /* clear dev_num if assigned */
+		clear_bit(slave->dev_num, bus->assigned);
+
+	list_del_init(&slave->node);
+	mutex_unlock(&bus->bus_lock);
+
+	device_unregister(dev);
+	return 0;
+}
+
+/**
+ * sdw_delete_bus_master() - delete the bus master instance
+ * @bus: bus to be deleted
+ *
+ * Remove the instance, delete the child devices.
+ */
+void sdw_delete_bus_master(struct sdw_bus *bus)
+{
+	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
+}
+EXPORT_SYMBOL(sdw_delete_bus_master);
+
+void sdw_extract_slave_id(struct sdw_bus *bus,
+			u64 addr, struct sdw_slave_id *id)
+{
+	dev_dbg(bus->dev, "SDW Slave Addr: %llx", addr);
+
+	/*
+	 * Spec definition
+	 *   Register		Bit	Contents
+	 *   DevId_0 [7:4]	47:44	sdw_version
+	 *   DevId_0 [3:0]	43:40	unique_id
+	 *   DevId_1		39:32	mfg_id [15:8]
+	 *   DevId_2		31:24	mfg_id [7:0]
+	 *   DevId_3		23:16	part_id [15:8]
+	 *   DevId_4		15:08	part_id [7:0]
+	 *   DevId_5		07:00	class_id
+	 */
+	id->sdw_version = (addr >> 44) & GENMASK(3, 0);
+	id->unique_id = (addr >> 40) & GENMASK(3, 0);
+	id->mfg_id = (addr >> 24) & GENMASK(15, 0);
+	id->part_id = (addr >> 8) & GENMASK(15, 0);
+	id->class_id = addr & GENMASK(7, 0);
+
+	dev_dbg(bus->dev,
+		"SDW Slave class_id %x, part_id %x, mfg_id %x, unique_id %x, version %x",
+				id->class_id, id->part_id, id->mfg_id,
+				id->unique_id, id->sdw_version);
+
+}
diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h
new file mode 100644
index 000000000000..a54921825ce0
--- /dev/null
+++ b/drivers/soundwire/bus.h
@@ -0,0 +1,19 @@ 
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+// Copyright(c) 2015-17 Intel Corporation.
+
+#ifndef __SDW_BUS_H
+#define __SDW_BUS_H
+
+#if IS_ENABLED(CONFIG_ACPI)
+int sdw_acpi_find_slaves(struct sdw_bus *bus);
+#else
+static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
+{
+	return -ENOTSUPP;
+}
+#endif
+
+void sdw_extract_slave_id(struct sdw_bus *bus,
+			u64 addr, struct sdw_slave_id *id);
+
+#endif /* __SDW_BUS_H */
diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
new file mode 100644
index 000000000000..397e100d66e3
--- /dev/null
+++ b/drivers/soundwire/slave.c
@@ -0,0 +1,114 @@ 
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+// Copyright(c) 2015-17 Intel Corporation.
+
+#include <linux/acpi.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_type.h>
+#include "bus.h"
+
+static void sdw_slave_release(struct device *dev)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+
+	kfree(slave);
+}
+
+static int sdw_slave_add(struct sdw_bus *bus,
+		struct sdw_slave_id *id, struct fwnode_handle *fwnode)
+{
+	struct sdw_slave *slave;
+	int ret;
+
+	slave = kzalloc(sizeof(*slave), GFP_KERNEL);
+	if (!slave)
+		return -ENOMEM;
+
+	/* Initialize data structure */
+	memcpy(&slave->id, id, sizeof(*id));
+	slave->dev.parent = bus->dev;
+	slave->dev.fwnode = fwnode;
+
+	/* name shall be sdw:link:mfg:part:class:unique */
+	dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
+			bus->link_id, id->mfg_id, id->part_id,
+			id->class_id, id->unique_id);
+
+	slave->dev.release = sdw_slave_release;
+	slave->dev.bus = &sdw_bus_type;
+	slave->bus = bus;
+	slave->status = SDW_SLAVE_UNATTACHED;
+	slave->dev_num = 0;
+
+	mutex_lock(&bus->bus_lock);
+	list_add_tail(&slave->node, &bus->slaves);
+	mutex_unlock(&bus->bus_lock);
+
+	ret = device_register(&slave->dev);
+	if (ret) {
+		dev_err(bus->dev, "Failed to add slave: ret %d\n", ret);
+
+		/*
+		 * On err, don't free but drop ref as this will be freed
+		 * when release method is invoked.
+		 */
+		mutex_lock(&bus->bus_lock);
+		list_del(&slave->node);
+		mutex_unlock(&bus->bus_lock);
+		put_device(&slave->dev);
+	}
+
+	return ret;
+}
+
+#if IS_ENABLED(CONFIG_ACPI)
+/*
+ * sdw_acpi_find_slaves() - Find Slave devices in Master ACPI node
+ * @bus: SDW bus instance
+ *
+ * Scans Master ACPI node for SDW child Slave devices and registers it.
+ */
+int sdw_acpi_find_slaves(struct sdw_bus *bus)
+{
+	struct acpi_device *adev, *parent;
+
+	parent = ACPI_COMPANION(bus->dev);
+	if (!parent) {
+		dev_err(bus->dev, "Can't find parent for acpi bind\n");
+		return -ENODEV;
+	}
+
+	list_for_each_entry(adev, &parent->children, node) {
+		unsigned long long addr;
+		struct sdw_slave_id id;
+		unsigned int link_id;
+		acpi_status status;
+
+		status = acpi_evaluate_integer(adev->handle,
+					METHOD_NAME__ADR, NULL, &addr);
+
+		if (ACPI_FAILURE(status)) {
+			dev_err(bus->dev, "_ADR resolution failed: %x\n",
+							status);
+			return status;
+		}
+
+		/* Extract link id from ADR, it is from 48 to 51 bits */
+		link_id = (addr >> 48) & GENMASK(3, 0);
+
+		/* Check for link_id match */
+		if (link_id != bus->link_id)
+			continue;
+
+		sdw_extract_slave_id(bus, addr, &id);
+
+		/*
+		 * don't error check for sdw_slave_add as we want to continue
+		 * adding Slaves
+		 */
+		sdw_slave_add(bus, &id, acpi_fwnode_handle(adev));
+	}
+
+	return 0;
+}
+
+#endif
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 4a7503781602..7e9579941c66 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -7,6 +7,14 @@ 
 struct sdw_bus;
 struct sdw_slave;
 
+/* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
+
+/* SDW Broadcast Device Number */
+#define SDW_BROADCAST_DEV_NUM		15
+
+/* SDW Enumeration Device Number */
+#define SDW_ENUM_DEV_NUM		0
+
 #define SDW_MAX_DEVICES			11
 
 /**
@@ -108,4 +116,7 @@  struct sdw_bus {
 	struct mutex bus_lock;
 };
 
+int sdw_add_bus_master(struct sdw_bus *bus);
+void sdw_delete_bus_master(struct sdw_bus *bus);
+
 #endif /* __SOUNDWIRE_H */