Commit dbb50c7a authored by Bard Liao's avatar Bard Liao Committed by Vinod Koul

soundwire: bus: add unique bus id

Adding an unique id for each bus.
Suggested-by: default avatarVinod Koul <vkoul@kernel.org>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Acked-by: default avatarJaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20200518174322.31561-4-yung-chuan.liao@linux.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 90acca1d
...@@ -9,6 +9,19 @@ ...@@ -9,6 +9,19 @@
#include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw.h>
#include "bus.h" #include "bus.h"
static DEFINE_IDA(sdw_ida);
static int sdw_get_id(struct sdw_bus *bus)
{
int rc = ida_alloc(&sdw_ida, GFP_KERNEL);
if (rc < 0)
return rc;
bus->id = rc;
return 0;
}
/** /**
* sdw_bus_master_add() - add a bus Master instance * sdw_bus_master_add() - add a bus Master instance
* @bus: bus instance * @bus: bus instance
...@@ -29,6 +42,12 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent, ...@@ -29,6 +42,12 @@ int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
return -ENODEV; return -ENODEV;
} }
ret = sdw_get_id(bus);
if (ret) {
dev_err(bus->dev, "Failed to get bus id\n");
return ret;
}
if (!bus->ops) { if (!bus->ops) {
dev_err(bus->dev, "SoundWire Bus ops are not set\n"); dev_err(bus->dev, "SoundWire Bus ops are not set\n");
return -EINVAL; return -EINVAL;
...@@ -144,6 +163,7 @@ void sdw_bus_master_delete(struct sdw_bus *bus) ...@@ -144,6 +163,7 @@ void sdw_bus_master_delete(struct sdw_bus *bus)
device_for_each_child(bus->dev, NULL, sdw_delete_slave); device_for_each_child(bus->dev, NULL, sdw_delete_slave);
sdw_bus_debugfs_exit(bus); sdw_bus_debugfs_exit(bus);
ida_free(&sdw_ida, bus->id);
} }
EXPORT_SYMBOL(sdw_bus_master_delete); EXPORT_SYMBOL(sdw_bus_master_delete);
......
...@@ -789,6 +789,7 @@ struct sdw_master_ops { ...@@ -789,6 +789,7 @@ struct sdw_master_ops {
* struct sdw_bus - SoundWire bus * struct sdw_bus - SoundWire bus
* @dev: Master linux device * @dev: Master linux device
* @link_id: Link id number, can be 0 to N, unique for each Master * @link_id: Link id number, can be 0 to N, unique for each Master
* @id: bus system-wide unique id
* @slaves: list of Slaves on this bus * @slaves: list of Slaves on this bus
* @assigned: Bitmap for Slave device numbers. * @assigned: Bitmap for Slave device numbers.
* Bit set implies used number, bit clear implies unused number. * Bit set implies used number, bit clear implies unused number.
...@@ -813,6 +814,7 @@ struct sdw_master_ops { ...@@ -813,6 +814,7 @@ struct sdw_master_ops {
struct sdw_bus { struct sdw_bus {
struct device *dev; struct device *dev;
unsigned int link_id; unsigned int link_id;
int id;
struct list_head slaves; struct list_head slaves;
DECLARE_BITMAP(assigned, SDW_MAX_DEVICES); DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
struct mutex bus_lock; struct mutex bus_lock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment