soundwire: bus: add PM/no-PM versions of read/write functions

Add support for pm_runtime with the appropriate error checks for
sdw_write/read functions, e.g. when pm_runtime is not supported.

Also expose internal functions without pm_runtime support, which are
required to perform any sort of suspend/resume operation, as well as
any enumeration tasks.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20200115000844.14695-5-pierre-louis.bossart@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
This commit is contained in:
Pierre-Louis Bossart 2020-01-14 18:08:38 -06:00 committed by Vinod Koul
parent a90def0681
commit 60ee9be255

View File

@ -317,14 +317,15 @@ int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
return 0;
}
/**
* sdw_nread() - Read "n" contiguous SDW Slave registers
* @slave: SDW Slave
* @addr: Register address
* @count: length
* @val: Buffer for values to be read
/*
* Read/Write IO functions.
* no_pm versions can only be called by the bus, e.g. while enumerating or
* handling suspend-resume sequences.
* all clients need to use the pm versions
*/
int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
static int
sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
{
struct sdw_msg msg;
int ret;
@ -334,11 +335,48 @@ int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
if (ret < 0)
return ret;
ret = pm_runtime_get_sync(slave->bus->dev);
return sdw_transfer(slave->bus, &msg);
}
static int
sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
{
struct sdw_msg msg;
int ret;
ret = sdw_fill_msg(&msg, slave, addr, count,
slave->dev_num, SDW_MSG_FLAG_WRITE, val);
if (ret < 0)
return ret;
ret = sdw_transfer(slave->bus, &msg);
return sdw_transfer(slave->bus, &msg);
}
static int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value)
{
return sdw_nwrite_no_pm(slave, addr, 1, &value);
}
/**
* sdw_nread() - Read "n" contiguous SDW Slave registers
* @slave: SDW Slave
* @addr: Register address
* @count: length
* @val: Buffer for values to be read
*/
int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
{
int ret;
ret = pm_runtime_get_sync(slave->bus->dev);
if (ret < 0 && ret != -EACCES) {
pm_runtime_put_noidle(slave->bus->dev);
return ret;
}
ret = sdw_nread_no_pm(slave, addr, count, val);
pm_runtime_mark_last_busy(slave->bus->dev);
pm_runtime_put(slave->bus->dev);
return ret;
@ -354,19 +392,17 @@ EXPORT_SYMBOL(sdw_nread);
*/
int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
{
struct sdw_msg msg;
int ret;
ret = sdw_fill_msg(&msg, slave, addr, count,
slave->dev_num, SDW_MSG_FLAG_WRITE, val);
if (ret < 0)
return ret;
ret = pm_runtime_get_sync(slave->bus->dev);
if (ret < 0)
if (ret < 0 && ret != -EACCES) {
pm_runtime_put_noidle(slave->bus->dev);
return ret;
}
ret = sdw_transfer(slave->bus, &msg);
ret = sdw_nwrite_no_pm(slave, addr, count, val);
pm_runtime_mark_last_busy(slave->bus->dev);
pm_runtime_put(slave->bus->dev);
return ret;