Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions drivers/soundwire/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,8 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
}
EXPORT_SYMBOL(sdw_extract_slave_id);

static int sdw_program_device_num(struct sdw_bus *bus)
static int sdw_program_device_num(struct sdw_bus *bus,
enum sdw_slave_status status[])
{
u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
struct sdw_slave *slave, *_s;
Expand Down Expand Up @@ -820,6 +821,12 @@ static int sdw_program_device_num(struct sdw_bus *bus)
return ret;
}

/*
* It could have dropped off the bus since the
* PING response so update the status array.
*/
status[slave->dev_num] = SDW_SLAVE_UNATTACHED;

break;
}
}
Expand Down Expand Up @@ -1779,10 +1786,21 @@ int sdw_handle_slave_status(struct sdw_bus *bus,
{
enum sdw_slave_status prev_status;
struct sdw_slave *slave;
bool programmed_dev_num = false;
bool attached_initializing;
int i, ret = 0;

/* first check if any Slaves fell off the bus */
/* Handle any unenumerated peripherals */
if (status[0] == SDW_SLAVE_ATTACHED) {
dev_dbg(bus->dev, "Slave attached, programming device number\n");
ret = sdw_program_device_num(bus, status);
if (ret < 0)
dev_warn(bus->dev, "Slave attach failed: %d\n", ret);

programmed_dev_num = true;
}

/* Check if any fell off the bus */
for (i = 1; i <= SDW_MAX_DEVICES; i++) {
mutex_lock(&bus->bus_lock);
if (test_bit(i, bus->assigned) == false) {
Expand All @@ -1797,42 +1815,23 @@ int sdw_handle_slave_status(struct sdw_bus *bus,

if (status[i] == SDW_SLAVE_UNATTACHED &&
slave->status != SDW_SLAVE_UNATTACHED) {
dev_err(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d\n",
i, slave->status);

if (bus->recheck_unattached && bus->ops->read_ping_status) {
u32 ping_status;

mutex_lock(&bus->msg_lock);

ping_status = bus->ops->read_ping_status(bus);

mutex_unlock(&bus->msg_lock);

ping_status >>= (i * 2);
ping_status &= 0x3;

if (ping_status != 0) {
dev_err(&slave->dev, "Slave %d state in PING frame is %d, ignoring earlier detection\n",
i, ping_status);
continue;
}
}
dev_warn(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d\n",
i, slave->status);
sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED);

/* Ensure driver knows that peripheral unattached */
ret = sdw_update_slave_status(slave, status[i]);
if (ret < 0)
dev_warn(&slave->dev, "Update Slave status failed:%d\n", ret);
}
}

if (status[0] == SDW_SLAVE_ATTACHED) {
dev_dbg(bus->dev, "Slave attached, programming device number\n");
ret = sdw_program_device_num(bus);
if (ret < 0)
dev_err(bus->dev, "Slave attach failed: %d\n", ret);
/*
* programming a device number will have side effects,
* so we deal with other devices at a later time
*/
return ret;
}
/*
* programming a device number will have side effects,
* so we deal with other devices at a later time
*/
if (programmed_dev_num)
return 0;

/* Continue to check other slave statuses */
for (i = 1; i <= SDW_MAX_DEVICES; i++) {
Expand Down
57 changes: 25 additions & 32 deletions drivers/soundwire/cadence_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,48 +790,46 @@ static int cdns_update_slave_status(struct sdw_cdns *cdns,
enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
bool is_slave = false;
u32 mask;
u32 val;
int i, set_status;

memset(status, 0, sizeof(status));

for (i = 0; i <= SDW_MAX_DEVICES; i++) {
mask = (slave_intstat >> (i * CDNS_MCP_SLAVE_STATUS_NUM)) &
CDNS_MCP_SLAVE_STATUS_BITS;
if (!mask)
continue;

is_slave = true;
set_status = 0;

if (mask & CDNS_MCP_SLAVE_INTSTAT_RESERVED) {
status[i] = SDW_SLAVE_RESERVED;
set_status++;
}
if (mask) {
is_slave = true;

if (mask & CDNS_MCP_SLAVE_INTSTAT_ATTACHED) {
status[i] = SDW_SLAVE_ATTACHED;
set_status++;
}

if (mask & CDNS_MCP_SLAVE_INTSTAT_ALERT) {
status[i] = SDW_SLAVE_ALERT;
set_status++;
}
if (mask & CDNS_MCP_SLAVE_INTSTAT_RESERVED) {
status[i] = SDW_SLAVE_RESERVED;
set_status++;
}

if (mask & CDNS_MCP_SLAVE_INTSTAT_NPRESENT) {
status[i] = SDW_SLAVE_UNATTACHED;
set_status++;
}
if (mask & CDNS_MCP_SLAVE_INTSTAT_ATTACHED) {
status[i] = SDW_SLAVE_ATTACHED;
set_status++;
}

/* first check if Slave reported multiple status */
if (set_status > 1) {
u32 val;
if (mask & CDNS_MCP_SLAVE_INTSTAT_ALERT) {
status[i] = SDW_SLAVE_ALERT;
set_status++;
}

dev_warn_ratelimited(cdns->dev,
"Slave %d reported multiple Status: %d\n",
i, mask);
if (mask & CDNS_MCP_SLAVE_INTSTAT_NPRESENT) {
status[i] = SDW_SLAVE_UNATTACHED;
set_status++;
}
}

/* check latest status extracted from PING commands */
/*
* check that there was a single reported Slave status and when
* there is not use the latest status extracted from PING commands
*/
if (set_status != 1) {
val = cdns_readl(cdns, CDNS_MCP_SLAVE_STAT);
val >>= (i * 2);

Expand All @@ -850,11 +848,6 @@ static int cdns_update_slave_status(struct sdw_cdns *cdns,
status[i] = SDW_SLAVE_RESERVED;
break;
}

dev_warn_ratelimited(cdns->dev,
"Slave %d status updated to %d\n",
i, status[i]);

}
}

Expand Down
1 change: 0 additions & 1 deletion drivers/soundwire/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,6 @@ static int intel_link_probe(struct auxiliary_device *auxdev,

bus->link_id = auxdev->id;
bus->dev_num_ida_min = INTEL_DEV_NUM_IDA_MIN;
bus->recheck_unattached = true;

sdw_cdns_probe(cdns);

Expand Down
3 changes: 0 additions & 3 deletions include/linux/soundwire/sdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,6 @@ struct sdw_master_ops {
* @dev_num_ida_min: if set, defines the minimum values for the IDA
* used to allocate system-unique device numbers. This value needs to be
* identical across all SoundWire bus in the system.
* @recheck_unattached: if set, double-check UNATTACHED status changes
* by reading PING frame status.
*/
struct sdw_bus {
struct device *dev;
Expand All @@ -922,7 +920,6 @@ struct sdw_bus {
bool multi_link;
int hw_sync_min_links;
int dev_num_ida_min;
bool recheck_unattached;
};

int sdw_bus_master_add(struct sdw_bus *bus, struct device *parent,
Expand Down