Skip to content

Commit

Permalink
soundwire: stream: make sure peripheral is initialized before program it
Browse files Browse the repository at this point in the history
A peripheral may experience an unexpected unattach and attach cycle
before a stream is prepared. It will fail to program registers if we try
to program them before the peripheral is attached.

Signed-off-by: Bard Liao <[email protected]>
  • Loading branch information
bardliao committed Sep 6, 2023
1 parent 9ac8ea5 commit 1b9b5c5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/soundwire/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static int sdw_program_slave_port_params(struct sdw_bus *bus,
struct sdw_slave_prop *slave_prop = &s_rt->slave->prop;
u32 addr1, addr2, addr3, addr4, addr5, addr6;
struct sdw_dpn_prop *dpn_prop;
unsigned long time;
int ret;
u8 wbuf;

Expand All @@ -143,6 +144,21 @@ static int sdw_program_slave_port_params(struct sdw_bus *bus,
if (!dpn_prop)
return -EINVAL;

/*
* bus_lock was locked by each stream operation, and sdw_handle_slave_status will wait for
* the lock to check if the bus is assigned. We should unlock the lock to allow other
* function to access the lock while we are waiting for initialization_complete.
*/
mutex_unlock(&bus->bus_lock);
time = wait_for_completion_timeout(&s_rt->slave->initialization_complete,
msecs_to_jiffies(3000));
if (!time) {
dev_err(&s_rt->slave->dev, "%s Initialization not complete, timed out\n", __func__);

return -ETIMEDOUT;
}
mutex_lock(&bus->bus_lock);

addr1 = SDW_DPN_PORTCTRL(t_params->port_num);
addr2 = SDW_DPN_BLOCKCTRL1(t_params->port_num);

Expand Down

0 comments on commit 1b9b5c5

Please sign in to comment.