soundwire: bus: Simplify sdw_assign_device_num()
Simplify the code in sdw_assign_device_num(). Remove the new_device flag which can be simply handled inline and do a bit less shuffling of dev_num in and out of various variables. This patch should cause no functional changes. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev> Link: https://lore.kernel.org/r/20250429101808.348462-2-ckeepax@opensource.cirrus.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
committed by
Vinod Koul
parent
0af2f6be1b
commit
5b1a2927c4
+12
-17
@@ -750,41 +750,36 @@ err:
|
||||
static int sdw_assign_device_num(struct sdw_slave *slave)
|
||||
{
|
||||
struct sdw_bus *bus = slave->bus;
|
||||
int ret, dev_num;
|
||||
bool new_device = false;
|
||||
struct device *dev = bus->dev;
|
||||
int ret;
|
||||
|
||||
/* check first if device number is assigned, if so reuse that */
|
||||
if (!slave->dev_num) {
|
||||
if (!slave->dev_num_sticky) {
|
||||
int dev_num;
|
||||
|
||||
mutex_lock(&slave->bus->bus_lock);
|
||||
dev_num = sdw_get_device_num(slave);
|
||||
mutex_unlock(&slave->bus->bus_lock);
|
||||
if (dev_num < 0) {
|
||||
dev_err(bus->dev, "Get dev_num failed: %d\n",
|
||||
dev_num);
|
||||
dev_err(dev, "Get dev_num failed: %d\n", dev_num);
|
||||
return dev_num;
|
||||
}
|
||||
slave->dev_num = dev_num;
|
||||
|
||||
slave->dev_num_sticky = dev_num;
|
||||
new_device = true;
|
||||
} else {
|
||||
slave->dev_num = slave->dev_num_sticky;
|
||||
dev_dbg(dev, "Slave already registered, reusing dev_num: %d\n",
|
||||
slave->dev_num_sticky);
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_device)
|
||||
dev_dbg(bus->dev,
|
||||
"Slave already registered, reusing dev_num:%d\n",
|
||||
slave->dev_num);
|
||||
|
||||
/* Clear the slave->dev_num to transfer message on device 0 */
|
||||
dev_num = slave->dev_num;
|
||||
slave->dev_num = 0;
|
||||
|
||||
ret = sdw_write_no_pm(slave, SDW_SCP_DEVNUMBER, dev_num);
|
||||
ret = sdw_write_no_pm(slave, SDW_SCP_DEVNUMBER, slave->dev_num_sticky);
|
||||
if (ret < 0) {
|
||||
dev_err(bus->dev, "Program device_num %d failed: %d\n",
|
||||
dev_num, ret);
|
||||
dev_err(dev, "Program device_num %d failed: %d\n",
|
||||
slave->dev_num_sticky, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -792,7 +787,7 @@ static int sdw_assign_device_num(struct sdw_slave *slave)
|
||||
slave->dev_num = slave->dev_num_sticky;
|
||||
|
||||
if (bus->ops && bus->ops->new_peripheral_assigned)
|
||||
bus->ops->new_peripheral_assigned(bus, slave, dev_num);
|
||||
bus->ops->new_peripheral_assigned(bus, slave, slave->dev_num);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user