Re: [PATCH] soundwire: stream: only change state if needed

From: Pierre-Louis Bossart
Date: Tue Mar 17 2020 - 08:23:03 EST


Hi Srinivas,

This patch did not work for me as it is as wsa881x codec does prepare and enable in one function, which breaks some of the assumptions in this patch.

Ah yes, if two transitions happen in the same DAI callback that wouldn't work indeed. We should probably add this restriction to the state machine documentation, the suggested mapping from ASoC DAI states to stream states did not account for compound cases.

However with below change I could get it working without moving stream handling to machine driver.

The change below would be an error case for Intel, so it's probably better if we go with your suggestion. You have a very specific state handling due to your power amps and it's probably better to keep it platform-specific.

Can you confirm though that this patch works fine if you move all the stream transitions to the machine driver? That should be a no-op but better make sure there's no misunderstanding.

Thanks
-Pierre

---------------------------->cut<-------------------------------
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index be71af4671a4..4a94ea64c1c5 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1574,7 +1574,8 @@ int sdw_prepare_stream(struct sdw_stream_runtime *stream)

ÂÂÂÂÂÂÂ sdw_acquire_bus_lock(stream);

-ÂÂÂÂÂÂ if (stream->state == SDW_STREAM_PREPARED) {
+ÂÂÂÂÂÂ if (stream->state == SDW_STREAM_PREPARED ||
+ÂÂÂÂÂÂÂÂÂÂ stream->state == SDW_STREAM_ENABLED) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* nothing to do */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = 0;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto state_err;
@@ -1754,7 +1755,8 @@ int sdw_disable_stream(struct sdw_stream_runtime *stream)

ÂÂÂÂÂÂÂ sdw_acquire_bus_lock(stream);

-ÂÂÂÂÂÂ if (stream->state == SDW_STREAM_DISABLED) {
+ÂÂÂÂÂÂ if (stream->state == SDW_STREAM_DISABLED ||
+ÂÂÂÂÂÂÂÂÂÂ stream->state == SDW_STREAM_DEPREPARED) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* nothing to do */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = 0;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto state_err;
---------------------------->cut<-------------------------------

--srini

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 1b43d03c79ea..3319121cd706 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1572,6 +1572,7 @@ int sdw_prepare_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂ sdw_acquire_bus_lock(stream);
ÂÂÂÂÂ if (stream->state == SDW_STREAM_PREPARED) {
+ÂÂÂÂÂÂÂ /* nothing to do */
ÂÂÂÂÂÂÂÂÂ ret = 0;
ÂÂÂÂÂÂÂÂÂ goto state_err;
ÂÂÂÂÂ }
@@ -1661,6 +1662,12 @@ int sdw_enable_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂ sdw_acquire_bus_lock(stream);
+ÂÂÂ if (stream->state == SDW_STREAM_ENABLED) {
+ÂÂÂÂÂÂÂ /* nothing to do */
+ÂÂÂÂÂÂÂ ret = 0;
+ÂÂÂÂÂÂÂ goto state_err;
+ÂÂÂ }
+
ÂÂÂÂÂ if (stream->state != SDW_STREAM_PREPARED &&
ÂÂÂÂÂÂÂÂÂ stream->state != SDW_STREAM_DISABLED) {
ÂÂÂÂÂÂÂÂÂ pr_err("%s: %s: inconsistent state state %d\n",
@@ -1744,6 +1751,12 @@ int sdw_disable_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂ sdw_acquire_bus_lock(stream);
+ÂÂÂ if (stream->state == SDW_STREAM_DISABLED) {
+ÂÂÂÂÂÂÂ /* nothing to do */
+ÂÂÂÂÂÂÂ ret = 0;
+ÂÂÂÂÂÂÂ goto state_err;
+ÂÂÂ }
+
ÂÂÂÂÂ if (stream->state != SDW_STREAM_ENABLED) {
ÂÂÂÂÂÂÂÂÂ pr_err("%s: %s: inconsistent state state %d\n",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __func__, stream->name, stream->state);
@@ -1809,6 +1822,12 @@ int sdw_deprepare_stream(struct sdw_stream_runtime *stream)
ÂÂÂÂÂ sdw_acquire_bus_lock(stream);
+ÂÂÂ if (stream->state == SDW_STREAM_DEPREPARED) {
+ÂÂÂÂÂÂÂ /* nothing to do */
+ÂÂÂÂÂÂÂ ret = 0;
+ÂÂÂÂÂÂÂ goto state_err;
+ÂÂÂ }
+
ÂÂÂÂÂ if (stream->state != SDW_STREAM_PREPARED &&
ÂÂÂÂÂÂÂÂÂ stream->state != SDW_STREAM_DISABLED) {
ÂÂÂÂÂÂÂÂÂ pr_err("%s: %s: inconsistent state state %d\n",