diff mbox series

soundwire: qcom: allow multi-link on newer devices

Message ID 20231128150049.412236-1-krzysztof.kozlowski@linaro.org
State Superseded
Headers show
Series soundwire: qcom: allow multi-link on newer devices | expand

Commit Message

Krzysztof Kozlowski Nov. 28, 2023, 3 p.m. UTC
Newer Qualcomm SoCs like X1E80100 might come with four speakers spread
over two Soundwire controllers, thus they need a multi-link Soundwire
stream runtime.

Cc: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

---

This is an entirely different approach than my previous try here:
https://lore.kernel.org/all/20231025144601.268645-1-krzysztof.kozlowski@linaro.org/
---
 drivers/soundwire/qcom.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Pierre-Louis Bossart Nov. 29, 2023, 5:07 p.m. UTC | #1
On 11/29/23 10:43, Krzysztof Kozlowski wrote:
> On 28/11/2023 16:35, Pierre-Louis Bossart wrote:
>>>  static enum sdw_command_response qcom_swrm_xfer_msg(struct sdw_bus *bus,
>>>  						    struct sdw_msg *msg)
>>>  {
>>> @@ -1078,6 +1090,7 @@ static const struct sdw_master_port_ops qcom_swrm_port_ops = {
>>>  };
>>>  
>>>  static const struct sdw_master_ops qcom_swrm_ops = {
>>> +	.read_prop = qcom_swrm_read_prop,
>>
>> nit-pick: read_prop() literally means "read platform properties".
>>
>> The functionality implemented in this callback looks more like an
>> initialization done in a probe, no?
> 
> Yes, but multi_link is being set by sdw_bus_master_add() just before
> calling read_prop(). It looks a bit odd, because "bus" comes from the
> caller and is probably zero-ed already. Therefore I assumed the code did
> it on purpose - ignored multi_link set before sdw_bus_master_add(),

On the Intel side, there's a bit of luck here.

The caller intel_link_probe() does not set the multi-link property, but
it's set in intel_link_startup() *AFTER* reading the properties - but we
don't have any properties related to multi-link, only the ability to
discard specific links.

>>>  	.xfer_msg = qcom_swrm_xfer_msg,
>>>  	.pre_bank_switch = qcom_swrm_pre_bank_switch,
>>>  	.post_bank_switch = qcom_swrm_post_bank_switch,
>>> @@ -1196,6 +1209,15 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
>>>  
>>>  	mutex_lock(&ctrl->port_lock);
>>>  	list_for_each_entry(m_rt, &stream->master_list, stream_node) {
>>
>> just realizing this now, are you sure the 'port_lock' is the proper
>> means to protecting the stream->master_list? I don't see this used
>> anywhere else in stream.c. I think you need to use bus_lock.
> 
> This is from ctrl, internal driver structure:
> 
> struct qcom_swrm_ctrl *ctrl

My point what that all other instances where list_for_each_entry() is
used on stream->master list rely on the bus_lock.

You may be fine in this specific case with a QCOM-specific lock, not
sure if there's any risk. At any rate that is not introduced by this
patch, so for now

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index 412b8e663a0a..57943724f0eb 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -920,6 +920,18 @@  static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl)
 	return 0;
 }
 
+static int qcom_swrm_read_prop(struct sdw_bus *bus)
+{
+	struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus);
+
+	if (ctrl->version >= SWRM_VERSION_2_0_0) {
+		bus->multi_link = true;
+		bus->hw_sync_min_links = 3;
+	}
+
+	return 0;
+}
+
 static enum sdw_command_response qcom_swrm_xfer_msg(struct sdw_bus *bus,
 						    struct sdw_msg *msg)
 {
@@ -1078,6 +1090,7 @@  static const struct sdw_master_port_ops qcom_swrm_port_ops = {
 };
 
 static const struct sdw_master_ops qcom_swrm_ops = {
+	.read_prop = qcom_swrm_read_prop,
 	.xfer_msg = qcom_swrm_xfer_msg,
 	.pre_bank_switch = qcom_swrm_pre_bank_switch,
 	.post_bank_switch = qcom_swrm_post_bank_switch,
@@ -1196,6 +1209,15 @@  static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
 
 	mutex_lock(&ctrl->port_lock);
 	list_for_each_entry(m_rt, &stream->master_list, stream_node) {
+		/*
+		 * For streams with multiple masters:
+		 * Allocate ports only for devices connected to this master.
+		 * Such devices will have ports allocated by their own master
+		 * and its qcom_swrm_stream_alloc_ports() call.
+		 */
+		if (ctrl->bus.id != m_rt->bus->id)
+			continue;
+
 		if (m_rt->direction == SDW_DATA_DIR_RX) {
 			maxport = ctrl->num_dout_ports;
 			port_mask = &ctrl->dout_port_mask;