From: Bard Liao <yung-chuan.liao@linux.intel.com>
To: alsa-devel@alsa-project.org, vkoul@kernel.org
Cc: vinod.koul@linaro.org, gregkh@linuxfoundation.org,
pierre-louis.bossart@linux.intel.com,
linux-kernel@vger.kernel.org, srinivas.kandagatla@linaro.org,
sanyog.r.kale@intel.com, bard.liao@intel.com
Subject: [PATCH 08/19] soundwire: stream: group sdw_port and sdw_master/slave_port functions
Date: Wed, 26 Jan 2022 09:17:04 +0800 [thread overview]
Message-ID: <20220126011715.28204-9-yung-chuan.liao@linux.intel.com> (raw)
In-Reply-To: <20220126011715.28204-1-yung-chuan.liao@linux.intel.com>
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
re-group all the helpers in one location with a code move. For
consistency the 'slave' helpers are placed before the 'master'
helpers.
Also remove unused arguments and rename the 'release' function to
'free' for consistency.
No functional change in this patch.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
---
drivers/soundwire/stream.c | 242 ++++++++++++++++++-------------------
1 file changed, 120 insertions(+), 122 deletions(-)
diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index c326298a0fe2..5e2d29448aaf 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -898,6 +898,123 @@ static void sdw_port_free(struct sdw_port_runtime *p_rt)
kfree(p_rt);
}
+static void sdw_slave_port_free(struct sdw_slave *slave,
+ struct sdw_stream_runtime *stream)
+{
+ struct sdw_port_runtime *p_rt, *_p_rt;
+ struct sdw_master_runtime *m_rt;
+ struct sdw_slave_runtime *s_rt;
+
+ list_for_each_entry(m_rt, &stream->master_list, stream_node) {
+ list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
+ if (s_rt->slave != slave)
+ continue;
+
+ list_for_each_entry_safe(p_rt, _p_rt,
+ &s_rt->port_list, port_node) {
+ sdw_port_free(p_rt);
+ }
+ }
+ }
+}
+
+static int sdw_slave_port_alloc(struct sdw_slave *slave,
+ struct sdw_slave_runtime *s_rt,
+ unsigned int num_config)
+{
+ struct sdw_port_runtime *p_rt;
+ int i;
+
+ /* Iterate for number of ports to perform initialization */
+ for (i = 0; i < num_config; i++) {
+ p_rt = sdw_port_alloc(&s_rt->port_list);
+ if (!p_rt)
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+static int sdw_slave_port_is_valid_range(struct device *dev, int num)
+{
+ if (!SDW_VALID_PORT_RANGE(num)) {
+ dev_err(dev, "SoundWire: Invalid port number :%d\n", num);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int sdw_slave_port_config(struct sdw_slave *slave,
+ struct sdw_slave_runtime *s_rt,
+ struct sdw_port_config *port_config)
+{
+ struct sdw_port_runtime *p_rt;
+ int ret;
+ int i;
+
+ i = 0;
+ list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
+ /*
+ * TODO: Check valid port range as defined by DisCo/
+ * slave
+ */
+ ret = sdw_slave_port_is_valid_range(&slave->dev, port_config[i].num);
+ if (ret < 0)
+ return ret;
+
+ ret = sdw_port_config(p_rt, port_config, i);
+ if (ret < 0)
+ return ret;
+ i++;
+ }
+
+ return 0;
+}
+
+static void sdw_master_port_free(struct sdw_master_runtime *m_rt)
+{
+ struct sdw_port_runtime *p_rt, *_p_rt;
+
+ list_for_each_entry_safe(p_rt, _p_rt, &m_rt->port_list, port_node) {
+ sdw_port_free(p_rt);
+ }
+}
+
+static int sdw_master_port_alloc(struct sdw_master_runtime *m_rt,
+ unsigned int num_ports)
+{
+ struct sdw_port_runtime *p_rt;
+ int i;
+
+ /* Iterate for number of ports to perform initialization */
+ for (i = 0; i < num_ports; i++) {
+ p_rt = sdw_port_alloc(&m_rt->port_list);
+ if (!p_rt)
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+static int sdw_master_port_config(struct sdw_master_runtime *m_rt,
+ struct sdw_port_config *port_config)
+{
+ struct sdw_port_runtime *p_rt;
+ int ret;
+ int i;
+
+ i = 0;
+ list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
+ ret = sdw_port_config(p_rt, port_config, i);
+ if (ret < 0)
+ return ret;
+ i++;
+ }
+
+ return 0;
+}
+
/**
* sdw_release_stream() - Free the assigned stream runtime
*
@@ -1022,37 +1139,6 @@ static struct sdw_slave_runtime
return s_rt;
}
-static void sdw_master_port_release(struct sdw_bus *bus,
- struct sdw_master_runtime *m_rt)
-{
- struct sdw_port_runtime *p_rt, *_p_rt;
-
- list_for_each_entry_safe(p_rt, _p_rt, &m_rt->port_list, port_node) {
- sdw_port_free(p_rt);
- }
-}
-
-static void sdw_slave_port_release(struct sdw_bus *bus,
- struct sdw_slave *slave,
- struct sdw_stream_runtime *stream)
-{
- struct sdw_port_runtime *p_rt, *_p_rt;
- struct sdw_master_runtime *m_rt;
- struct sdw_slave_runtime *s_rt;
-
- list_for_each_entry(m_rt, &stream->master_list, stream_node) {
- list_for_each_entry(s_rt, &m_rt->slave_rt_list, m_rt_node) {
- if (s_rt->slave != slave)
- continue;
-
- list_for_each_entry_safe(p_rt, _p_rt,
- &s_rt->port_list, port_node) {
- sdw_port_free(p_rt);
- }
- }
- }
-}
-
/**
* sdw_release_slave_stream() - Free Slave(s) runtime handle
*
@@ -1097,7 +1183,7 @@ static void sdw_release_master_stream(struct sdw_master_runtime *m_rt,
struct sdw_slave_runtime *s_rt, *_s_rt;
list_for_each_entry_safe(s_rt, _s_rt, &m_rt->slave_rt_list, m_rt_node) {
- sdw_slave_port_release(s_rt->slave->bus, s_rt->slave, stream);
+ sdw_slave_port_free(s_rt->slave, stream);
sdw_release_slave_stream(s_rt->slave, stream);
}
@@ -1126,7 +1212,7 @@ int sdw_stream_remove_master(struct sdw_bus *bus,
if (m_rt->bus != bus)
continue;
- sdw_master_port_release(bus, m_rt);
+ sdw_master_port_free(m_rt);
sdw_release_master_stream(m_rt, stream);
stream->m_rt_count--;
}
@@ -1153,7 +1239,7 @@ int sdw_stream_remove_slave(struct sdw_slave *slave,
{
mutex_lock(&slave->bus->bus_lock);
- sdw_slave_port_release(slave->bus, slave, stream);
+ sdw_slave_port_free(slave, stream);
sdw_release_slave_stream(slave, stream);
mutex_unlock(&slave->bus->bus_lock);
@@ -1208,94 +1294,6 @@ static int sdw_config_stream(struct device *dev,
return 0;
}
-static int sdw_master_port_alloc(struct sdw_master_runtime *m_rt,
- unsigned int num_ports)
-{
- struct sdw_port_runtime *p_rt;
- int i;
-
- /* Iterate for number of ports to perform initialization */
- for (i = 0; i < num_ports; i++) {
- p_rt = sdw_port_alloc(&m_rt->port_list);
- if (!p_rt)
- return -ENOMEM;
- }
-
- return 0;
-}
-
-static int sdw_master_port_config(struct sdw_master_runtime *m_rt,
- struct sdw_port_config *port_config)
-{
- struct sdw_port_runtime *p_rt;
- int ret;
- int i;
-
- i = 0;
- list_for_each_entry(p_rt, &m_rt->port_list, port_node) {
- ret = sdw_port_config(p_rt, port_config, i);
- if (ret < 0)
- return ret;
- i++;
- }
-
- return 0;
-}
-
-static int sdw_slave_port_alloc(struct sdw_slave *slave,
- struct sdw_slave_runtime *s_rt,
- unsigned int num_config)
-{
- struct sdw_port_runtime *p_rt;
- int i;
-
- /* Iterate for number of ports to perform initialization */
- for (i = 0; i < num_config; i++) {
- p_rt = sdw_port_alloc(&s_rt->port_list);
- if (!p_rt)
- return -ENOMEM;
- }
-
- return 0;
-}
-
-static int sdw_slave_port_is_valid_range(struct device *dev, int num)
-{
- if (!SDW_VALID_PORT_RANGE(num)) {
- dev_err(dev, "SoundWire: Invalid port number :%d\n", num);
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int sdw_slave_port_config(struct sdw_slave *slave,
- struct sdw_slave_runtime *s_rt,
- struct sdw_port_config *port_config)
-{
- struct sdw_port_runtime *p_rt;
- int ret;
- int i;
-
- i = 0;
- list_for_each_entry(p_rt, &s_rt->port_list, port_node) {
- /*
- * TODO: Check valid port range as defined by DisCo/
- * slave
- */
- ret = sdw_slave_port_is_valid_range(&slave->dev, port_config[i].num);
- if (ret < 0)
- return ret;
-
- ret = sdw_port_config(p_rt, port_config, i);
- if (ret < 0)
- return ret;
- i++;
- }
-
- return 0;
-}
-
/**
* sdw_stream_add_master() - Allocate and add master runtime to a stream
*
--
2.17.1
next prev parent reply other threads:[~2022-01-26 1:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 1:16 [PATCH 00/19] soundwire: stream: cleanup of 'stream' support Bard Liao
2022-01-26 1:16 ` [PATCH 01/19] soundwire: stream: remove unused parameter in sdw_stream_add_slave Bard Liao
2022-01-26 1:16 ` [PATCH 02/19] soundwire: stream: add slave runtime to list earlier Bard Liao
2022-01-26 1:16 ` [PATCH 03/19] soundwire: stream: simplify check on port range Bard Liao
2022-01-26 1:17 ` [PATCH 04/19] soundwire: stream: add alloc/config/free helpers for ports Bard Liao
2022-01-26 1:17 ` [PATCH 05/19] soundwire: stream: split port allocation and configuration loops Bard Liao
2022-01-26 1:17 ` [PATCH 06/19] soundwire: stream: split alloc and config in two functions Bard Liao
2022-01-26 1:17 ` [PATCH 07/19] soundwire: stream: add 'slave' prefix for port range checks Bard Liao
2022-01-26 1:17 ` Bard Liao [this message]
2022-01-26 1:17 ` [PATCH 09/19] soundwire: stream: simplify sdw_alloc_master_rt() Bard Liao
2022-01-26 1:17 ` [PATCH 10/19] soundwire: stream: split sdw_alloc_master_rt() in alloc and config Bard Liao
2022-01-26 1:17 ` [PATCH 11/19] soundwire: stream: move sdw_alloc_slave_rt() before 'master' helpers Bard Liao
2022-01-26 1:17 ` [PATCH 12/19] soundwire: stream: split sdw_alloc_slave_rt() in alloc and config Bard Liao
2022-01-26 1:17 ` [PATCH 13/19] soundwire: stream: group sdw_stream_ functions Bard Liao
2022-01-26 1:17 ` [PATCH 14/19] soundwire: stream: rename and move master/slave_rt_free routines Bard Liao
2022-01-26 1:17 ` [PATCH 15/19] soundwire: stream: move list addition to sdw_slave_alloc_rt() Bard Liao
2022-01-26 1:17 ` [PATCH 16/19] soundwire: stream: separate alloc and config within sdw_stream_add_xxx() Bard Liao
2022-01-26 1:17 ` [PATCH 17/19] soundwire: stream: introduce sdw_slave_rt_find() helper Bard Liao
2022-01-26 1:17 ` [PATCH 18/19] soundwire: stream: sdw_stream_add_ functions can be called multiple times Bard Liao
2022-01-26 1:17 ` [PATCH 19/19] soundwire: stream: make enable/disable/deprepare idempotent Bard Liao
2022-02-11 6:48 ` [PATCH 00/19] soundwire: stream: cleanup of 'stream' support Vinod Koul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220126011715.28204-9-yung-chuan.liao@linux.intel.com \
--to=yung-chuan.liao@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=bard.liao@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=sanyog.r.kale@intel.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=vinod.koul@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox