Skip to contentSkip to conversation

Issues bringing up WCD9385 codec on SC7280/QCM6490

PATCH Luca Weiss 2 participants 4 messages Dec 1, 2023

Subsystems (7)
lore
Share & tools
lore

Luca Weiss

author
#0 lore raw

Hi all,

I'm trying to get audio working on qcm6490-fairphone-fp5 (the SoC is sc7280.dtsi-based).
Unfortunately the current sc7280.dtsi only supports directly interfacing with the hw blocks (lpass_aon/lpass_hm/lpass_audiocc) and not using q6afecc, but I think I've done this "conversion" correctly, based on other mainline SoCs and downstream dts.

So, to the problem: I've added the nodes for the WCD9385 codec found on this device which is handling the microphones (and analog audio over USB-C). But I can't get it to work. I believe the first problem I saw was the error "soundwire device init timeout" where I saw that the wcd tx & rx devices (on the soundwire bus) only appeared after the timeout of 2 seconds expired and wcd938x driver probe failed. After bumping this to something higher (20 seconds) this was resolved.

But now I'm having these errors in the initialization of the wcd devices.

[   45.651156] qcom-soundwire 3230000.soundwire: swrm_wait_for_rd_fifo_avail err read underflow
[   45.651173] soundwire sdw-master-1: trf on Slave 1 failed:-5 read addr 41 count 1
[   45.651182] wcd9380-codec sdw:0:0217:010d:00:3: SDW_SCP_INTMASK1 write failed:-5
[   45.651186] wcd9380-codec sdw:0:0217:010d:00:3: Slave 1 initialization failed: -5

After some more debugging and changing some timeouts I'm noticing that the swr devices appear immediately after pm_runtime puts the driver to sleep, qcom_swrm_irq_handler is called and then we get this:

[   45.531863] qcom-soundwire 3230000.soundwire: SWR new slave attached

The same also happens for the other soundwire controller

[   47.581067] qcom-soundwire 3210000.soundwire: SWR new slave attached

And this is currently where I'm stuck and can't really think of why this is happening.. I've double checked nearly all of the properties I've added/modified incl. wcd reset GPIO, wcd *-supply, lpi pinctrl settings. I believe the "read underflow" error here is because the whole driver stack is already trying to suspend so then communication fails. The real question for me is why the swr 'slaves' only appear exactly when pm_runtime is suspending everything.

The only thing I've not really checked yet is qcom,rx-port-mapping & qcom,tx-port-mapping, there I've just tried the two different values found on the various devices but I don't think this is causing these issues. I will try to look further into this property at some point but with msm-5.4 downstream it's quite tricky to find where these values are represented (I got some hints from Krzysztof though where to look so I'll try to do that soon)

I'm attaching my current diff to the email, just note that it's based on one of my dev branches and is manually edited to remove some debug prints etc so it will probably not apply anywhere. I can also push the git tree somewhere in case that's helpful.

Regards
Luca

arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts +106 -0
index 6e03715073ec..1c56f5c85571 100644
@@ -337,6 +337,38 @@ fake-reg-mclk3 {
 		clocks = <&camcc CAM_CC_MCLK3_CLK>;
 		regulator-always-on;
 	};
+
+	wcd9385: audio-codec-1 {
+		compatible = "qcom,wcd9385-codec";
+
+		pinctrl-0 = <&wcd_default>;
+		pinctrl-names = "default";
+
+		reset-gpios = <&tlmm 83 GPIO_ACTIVE_LOW>;
+
+		qcom,rx-device = <&wcd_rx>;
+		qcom,tx-device = <&wcd_tx>;
+
+		vdd-rxtx-supply = <&vreg_l18b>;
+		vdd-io-supply = <&vreg_l18b>; // ???
+		vdd-buck-supply = <&vreg_l17b>;
+		vdd-mic-bias-supply = <&vreg_bob>;
+
+		qcom,micbias1-microvolt = <1800000>;
+		qcom,micbias2-microvolt = <1800000>;
+		qcom,micbias3-microvolt = <1800000>;
+		qcom,micbias4-microvolt = <1800000>;
+
+		// FIXME validate those
+		qcom,mbhc-buttons-vthreshold-microvolt = <75000 150000 237000 500000 500000
+							  500000 500000 500000>;
+		qcom,mbhc-headset-vthreshold-microvolt = <1700000>;
+		qcom,mbhc-headphone-vthreshold-microvolt = <50000>;
+		#sound-dai-cells = <1>;
+	};
 };
 
 &apps_rsc {
@@ -713,6 +794,43 @@ &ipa {
 	status = "okay";
 };
 
+&lpass_rx_macro {
+	status = "okay";
+};
+
+&lpass_tx_macro {
+	status = "okay";
+};
+
+&lpass_va_macro {
+	status = "okay";
+};
+
+&lpass_rx_swr_clk {
+	drive-strength = <2>;
+	slew-rate = <1>;
+	bias-disable;
+};
+
+&lpass_rx_swr_data {
+	drive-strength = <2>;
+	slew-rate = <1>;
+	bias-bus-hold;
+};
+
+&lpass_tx_swr_clk {
+	drive-strength = <2>;
+	slew-rate = <1>;
+	bias-disable;
+};
+
+&lpass_tx_swr_data {
+	drive-strength = <2>;
+	slew-rate = <1>;
+	bias-bus-hold;
+};
+
 &mdss {
 	status = "okay";
 };
@@ -1083,6 +1215,35 @@ cpu {
 		};
 	};
 
+	wcd-capture-dai-link {
+		link-name = "WCD Capture";
+
+		cpu {
+			sound-dai = <&q6afedai TX_CODEC_DMA_TX_3>;
+		};
+
+		codec {
+			sound-dai = <&wcd9385 1>, <&swr1 0>, <&lpass_tx_macro 0>;
+		};
+	};
+
 	displayport-rx-dai-link {
 		link-name = "DisplayPort Playback";
 
@@ -1130,6 +1291,27 @@ goodix-berlin@0 {
 	};
 };
 
+&swr0 {
+	status = "okay";
+
+	wcd_rx: codec@0,4 {
+		compatible = "sdw20217010d00";
+		reg = <0 4>;
+		qcom,rx-port-mapping = <1 2 3 4 5>; // TODO no clue if correct
+	};
+};
+
+&swr1 {
+	status = "okay";
+
+	wcd_tx: codec@0,3 {
+		compatible = "sdw20217010d00";
+		reg = <0 3>;
+		qcom,tx-port-mapping = <1 2 3 4>; // TODO no clue if correct
+		//qcom,tx-port-mapping = <1 1 2 3>; // TODO no clue if correct
+	};
+};
+
 &tlmm {
 	/*
 	 * 32-33: SMB1394 (SPMI)
@@ -1252,6 +1434,27 @@ usb_redrive_1v8_en_default: usb-redrive-1v8-en-default-state {
 		bias-disable;
 		output-high;
 	};
+
+	wcd_default: wcd-reset-n-active-state {
+		pins = "gpio83";
+		function = "gpio";
+		drive-strength = <16>;
+		bias-disable;
+		output-low;
+	};
 };
 
 &uart5 {
arch/arm64/boot/dts/qcom/sc7280.dtsi +33 -26

112 lines not on this page · raw message

sound/soc/codecs/lpass-tx-macro.c +13 -13
index 82f9873ffada..0d861c056462 100644
@@ -1998,18 +1998,18 @@ static int tx_macro_probe(struct platform_device *pdev)
 	}
 
 	/* Update defaults for lpass sc7280 */
-	if (of_device_is_compatible(np, "qcom,sc7280-lpass-tx-macro")) {
-		for (reg = 0; reg < ARRAY_SIZE(tx_defaults); reg++) {
-			switch (tx_defaults[reg].reg) {
-			case CDC_TX_TOP_CSR_SWR_AMIC0_CTL:
-			case CDC_TX_TOP_CSR_SWR_AMIC1_CTL:
-				tx_defaults[reg].def = 0x0E;
-				break;
-			default:
-				break;
-			}
-		}
-	}
+	//if (of_device_is_compatible(np, "qcom,sc7280-lpass-tx-macro")) {
+	//	for (reg = 0; reg < ARRAY_SIZE(tx_defaults); reg++) {
+	//		switch (tx_defaults[reg].reg) {
+	//		case CDC_TX_TOP_CSR_SWR_AMIC0_CTL:
+	//		case CDC_TX_TOP_CSR_SWR_AMIC1_CTL:
+	//			tx_defaults[reg].def = 0x0E;
+	//			break;
+	//		default:
+	//			break;
+	//		}
+	//	}
+	//}
 
 	tx->regmap = devm_regmap_init_mmio(dev, base, &tx_regmap_config);
 	if (IS_ERR(tx->regmap)) {
@@ -2162,7 +2162,7 @@ static const struct dev_pm_ops tx_macro_pm_ops = {
 static const struct of_device_id tx_macro_dt_match[] = {
 	{
 		.compatible = "qcom,sc7280-lpass-tx-macro",
-		.data = (void *)(LPASS_MACRO_FLAG_HAS_NPL_CLOCK | LPASS_MACRO_FLAG_RESET_SWR),
+		.data = (void *)LPASS_MACRO_FLAG_HAS_NPL_CLOCK,
 	}, {
 		.compatible = "qcom,sm6115-lpass-tx-macro",
 		.data = (void *)LPASS_MACRO_FLAG_HAS_NPL_CLOCK,
sound/soc/codecs/wcd938x-sdw.c +1 -1
index a1f04010da95..24cb95a6affd 100644
@@ -1272,11 +1272,12 @@ static int wcd9380_probe(struct sdw_slave *pdev,
 		regcache_cache_only(wcd->regmap, true);
 	}
 
-	pm_runtime_set_autosuspend_delay(dev, 3000);
+	pm_runtime_set_autosuspend_delay(dev, 10000);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
 
 	ret = component_add(dev, &wcd938x_sdw_component_ops);
 	if (ret)
sound/soc/codecs/wcd938x.c +1 -1
index faf8d3f9b3c5..104b7ab160fc 100644
@@ -3096,12 +3096,14 @@ static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
 	unsigned long time_left;
 	int ret, i;
 
 	time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete,
-						msecs_to_jiffies(2000));
+						msecs_to_jiffies(20000));
 	if (!time_left) {
 		dev_err(dev, "soundwire device init timeout\n");
 		return -ETIMEDOUT;
 	}
 
 	snd_soc_component_init_regmap(component, wcd938x->regmap);
 
#1 lore raw
Quoted 8 lines · Luca Weiss

Hi all,

I'm trying to get audio working on qcm6490-fairphone-fp5 (the SoC is sc7280.dtsi-based).
Unfortunately the current sc7280.dtsi only supports directly interfacing with the hw blocks (lpass_aon/lpass_hm/lpass_audiocc) and not using q6afecc, but I think I've done this "conversion" correctly, based on other mainline SoCs and downstream dts.

Eh, you probably duplicated a lot of existing work. Here it is:
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines

So, to the problem: I've added the nodes for the WCD9385 codec found on this device which is handling the microphones (and analog audio over USB-C). But I can't get it to work. I believe the first problem I saw was the error "soundwire device init timeout" where I saw that the wcd tx & rx devices (on the soundwire bus) only appeared after the timeout of 2 seconds expired and wcd938x driver probe failed. After bumping this to something higher (20 seconds) this was resolved.

Please describe the tree you are working on. This was fixed some time ago.

Quoted 13 lines

But now I'm having these errors in the initialization of the wcd devices.

[   45.651156] qcom-soundwire 3230000.soundwire: swrm_wait_for_rd_fifo_avail err read underflow
[   45.651173] soundwire sdw-master-1: trf on Slave 1 failed:-5 read addr 41 count 1
[   45.651182] wcd9380-codec sdw:0:0217:010d:00:3: SDW_SCP_INTMASK1 write failed:-5
[   45.651186] wcd9380-codec sdw:0:0217:010d:00:3: Slave 1 initialization failed: -5

After some more debugging and changing some timeouts I'm noticing that the swr devices appear immediately after pm_runtime puts the driver to sleep, qcom_swrm_irq_handler is called and then we get this:

Quoted 5 lines
[   45.531863] qcom-soundwire 3230000.soundwire: SWR new slave attached

The same also happens for the other soundwire controller

[   47.581067] qcom-soundwire 3210000.soundwire: SWR new slave attached

There were similar reports on the IRC, so I wonder if this is the same issue?

Maybe wrong interrupt flag (like falling instead of rising)? I collected over time also several ideas of fixes from Srini, not always ready to upstream, but maybe they fix your issue? Did you try some of my audio branches like n/audio-sm8450-sm8550-on-next?

Or maybe sc7280 needs to toggle the same CSR reset/clock bits as sc8280xp (lpass-csr-sc8280xp.c)?

Quoted 8 lines

And this is currently where I'm stuck and can't really think of why this is happening.. I've double checked nearly all of the properties I've added/modified incl. wcd reset GPIO, wcd *-supply, lpi pinctrl settings. I believe the "read underflow" error here is because the whole driver stack is already trying to suspend so then communication fails. The real question for me is why the swr 'slaves' only appear exactly when pm_runtime is suspending everything.

Yeah, good question.

Quoted 9 lines

The only thing I've not really checked yet is qcom,rx-port-mapping & qcom,tx-port-mapping, there I've just tried the two different values found on the various devices but I don't think this is causing these issues. I will try to look further into this property at some point but with msm-5.4 downstream it's quite tricky to find where these values are represented (I got some hints from Krzysztof though where to look so I'll try to do that soon)

Quoted 8 lines

I'm attaching my current diff to the email, just note that it's based on one of my dev branches and is manually edited to remove some debug prints etc so it will probably not apply anywhere. I can also push the git tree somewhere in case that's helpful.

Regards
Luca

Best regards,
Krzysztof

author
#2 lore raw
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Luca Weiss

Hi all,

I'm trying to get audio working on qcm6490-fairphone-fp5 (the SoC is sc7280.dtsi-based).
Unfortunately the current sc7280.dtsi only supports directly interfacing with the hw blocks (lpass_aon/lpass_hm/lpass_audiocc) and not using q6afecc, but I think I've done this "conversion" correctly, based on other mainline SoCs and downstream dts.

Quoted 2 lines

Eh, you probably duplicated a lot of existing work. Here it is:
https://lore.kernel.org/all/[email protected]/

Well, at least this patch[0] seems to be reasonably helpful, but even this one uses q6prmcc and not q6afecc but apart from that I will double check if it matches what I have, but looks rather similar.

[0] https://lore.kernel.org/all/[email protected]/

Quoted 11 lines
Quoted 9 lines

So, to the problem: I've added the nodes for the WCD9385 codec found on this device which is handling the microphones (and analog audio over USB-C). But I can't get it to work. I believe the first problem I saw was the error "soundwire device init timeout" where I saw that the wcd tx & rx devices (on the soundwire bus) only appeared after the timeout of 2 seconds expired and wcd938x driver probe failed. After bumping this to something higher (20 seconds) this was resolved.

Please describe the tree you are working on. This was fixed some time ago.

Currently v6.7-rc2 plus some patches for general device support. Unfortunately the fix you had for v6.6 or something and mentioned on IRC is already in there..

Quoted 20 lines
Quoted 14 lines

But now I'm having these errors in the initialization of the wcd devices.

[   45.651156] qcom-soundwire 3230000.soundwire: swrm_wait_for_rd_fifo_avail err read underflow
[   45.651173] soundwire sdw-master-1: trf on Slave 1 failed:-5 read addr 41 count 1
[   45.651182] wcd9380-codec sdw:0:0217:010d:00:3: SDW_SCP_INTMASK1 write failed:-5
[   45.651186] wcd9380-codec sdw:0:0217:010d:00:3: Slave 1 initialization failed: -5

After some more debugging and changing some timeouts I'm noticing that the swr devices appear immediately after pm_runtime puts the driver to sleep, qcom_swrm_irq_handler is called and then we get this:

Quoted 5 lines
[   45.531863] qcom-soundwire 3230000.soundwire: SWR new slave attached

The same also happens for the other soundwire controller

[   47.581067] qcom-soundwire 3210000.soundwire: SWR new slave attached
Quoted 7 lines

There were similar reports on the IRC, so I wonder if this is the same issue?

Maybe wrong interrupt flag (like falling instead of rising)? I collected over time also several ideas of fixes from Srini, not always ready to upstream, but maybe they fix your issue? Did you try some of my audio branches like n/audio-sm8450-sm8550-on-next?

I didn't yet. I'll check out[1] then and dig around if I see anything else.

[1] https://github.com/krzk/linux/commits/n/audio-sm8450-sm8550-on-next

Quoted 3 lines

Or maybe sc7280 needs to toggle the same CSR reset/clock bits as sc8280xp (lpass-csr-sc8280xp.c)?

Assuming you mean lpasscc-sc8280xp.c the resets defined in [2] do seem to be represented in my downstream yupik-audio-overlay.dtsi. There's
* qcom,swrm-hctl-reg = <0x032a90a8>; for TX macro SWR
* qcom,swrm-hctl-reg = <0x032a90a0>; for RX macro SWR
* qcom,swrm-hctl-reg = <0x032a90b0>; for WSA macro SWR

And the latter two have the same value as in the sc8280xp patch. And the property is used in techpack/audio in some runtime_resume code under a lot of if's but also with "SW workaround to gate hw_ctl for SWR version >=1.6" and this SoC has controller v1.6.0.

This might be promising, I think?

[2] https://lore.kernel.org/linux-arm-msm/[email protected]/

Quoted 11 lines
Quoted 9 lines

And this is currently where I'm stuck and can't really think of why this is happening.. I've double checked nearly all of the properties I've added/modified incl. wcd reset GPIO, wcd *-supply, lpi pinctrl settings. I believe the "read underflow" error here is because the whole driver stack is already trying to suspend so then communication fails. The real question for me is why the swr 'slaves' only appear exactly when pm_runtime is suspending everything.

Yeah, good question.

Too bad you don't have an amazing idea why this is happening ;)

Thanks for your advise, let's see if it gets me any further!

Regards
Luca

Quoted 22 lines
Quoted 10 lines

The only thing I've not really checked yet is qcom,rx-port-mapping & qcom,tx-port-mapping, there I've just tried the two different values found on the various devices but I don't think this is causing these issues. I will try to look further into this property at some point but with msm-5.4 downstream it's quite tricky to find where these values are represented (I got some hints from Krzysztof though where to look so I'll try to do that soon)

Quoted 8 lines

I'm attaching my current diff to the email, just note that it's based on one of my dev branches and is manually edited to remove some debug prints etc so it will probably not apply anywhere. I can also push the git tree somewhere in case that's helpful.

Regards
Luca

Best regards,
Krzysztof

author
#3 lore raw
Quoted 79 lines · Luca Weiss
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Luca Weiss

Hi all,

I'm trying to get audio working on qcm6490-fairphone-fp5 (the SoC is sc7280.dtsi-based).
Unfortunately the current sc7280.dtsi only supports directly interfacing with the hw blocks (lpass_aon/lpass_hm/lpass_audiocc) and not using q6afecc, but I think I've done this "conversion" correctly, based on other mainline SoCs and downstream dts.

Quoted 2 lines

Eh, you probably duplicated a lot of existing work. Here it is:
https://lore.kernel.org/all/[email protected]/

Well, at least this patch[0] seems to be reasonably helpful, but even this one uses q6prmcc and not q6afecc but apart from that I will double check if it matches what I have, but looks rather similar.

[0] https://lore.kernel.org/all/[email protected]/

Quoted 11 lines
Quoted 9 lines

So, to the problem: I've added the nodes for the WCD9385 codec found on this device which is handling the microphones (and analog audio over USB-C). But I can't get it to work. I believe the first problem I saw was the error "soundwire device init timeout" where I saw that the wcd tx & rx devices (on the soundwire bus) only appeared after the timeout of 2 seconds expired and wcd938x driver probe failed. After bumping this to something higher (20 seconds) this was resolved.

Please describe the tree you are working on. This was fixed some time ago.

Currently v6.7-rc2 plus some patches for general device support. Unfortunately the fix you had for v6.6 or something and mentioned on IRC is already in there..

Quoted 20 lines
Quoted 14 lines

But now I'm having these errors in the initialization of the wcd devices.

[   45.651156] qcom-soundwire 3230000.soundwire: swrm_wait_for_rd_fifo_avail err read underflow
[   45.651173] soundwire sdw-master-1: trf on Slave 1 failed:-5 read addr 41 count 1
[   45.651182] wcd9380-codec sdw:0:0217:010d:00:3: SDW_SCP_INTMASK1 write failed:-5
[   45.651186] wcd9380-codec sdw:0:0217:010d:00:3: Slave 1 initialization failed: -5

After some more debugging and changing some timeouts I'm noticing that the swr devices appear immediately after pm_runtime puts the driver to sleep, qcom_swrm_irq_handler is called and then we get this:

Quoted 5 lines
[   45.531863] qcom-soundwire 3230000.soundwire: SWR new slave attached

The same also happens for the other soundwire controller

[   47.581067] qcom-soundwire 3210000.soundwire: SWR new slave attached
Quoted 7 lines

There were similar reports on the IRC, so I wonder if this is the same issue?

Maybe wrong interrupt flag (like falling instead of rising)? I collected over time also several ideas of fixes from Srini, not always ready to upstream, but maybe they fix your issue? Did you try some of my audio branches like n/audio-sm8450-sm8550-on-next?

I didn't yet. I'll check out[1] then and dig around if I see anything else.

[1] https://github.com/krzk/linux/commits/n/audio-sm8450-sm8550-on-next

Quoted 3 lines

Or maybe sc7280 needs to toggle the same CSR reset/clock bits as sc8280xp (lpass-csr-sc8280xp.c)?

Assuming you mean lpasscc-sc8280xp.c the resets defined in [2] do seem to be represented in my downstream yupik-audio-overlay.dtsi. There's
* qcom,swrm-hctl-reg = <0x032a90a8>; for TX macro SWR
* qcom,swrm-hctl-reg = <0x032a90a0>; for RX macro SWR
* qcom,swrm-hctl-reg = <0x032a90b0>; for WSA macro SWR

Quoted 8 lines

And the latter two have the same value as in the sc8280xp patch. And the property is used in techpack/audio in some runtime_resume code under a lot of if's but also with "SW workaround to gate hw_ctl for SWR version >=1.6" and this SoC has controller v1.6.0.

This might be promising, I think?

[2] https://lore.kernel.org/linux-arm-msm/[email protected]/

Hi,

Quick update. Re-adding qcom,sc7280-lpassaudiocc (and hacking out all the non-reset bits from that driver) seems to make things quite a bit better. I'll check more in the coming week(s). But I haven't gotten actual audio out of the microphone yet.

Looking back, I shouldn've just discarded these resets, but I wasn't aware that this driver was touching both forbidden registers but also some registers that were still needed.

Regards
Luca

Quoted 42 lines
Quoted 11 lines
Quoted 10 lines

And this is currently where I'm stuck and can't really think of why this is happening.. I've double checked nearly all of the properties I've added/modified incl. wcd reset GPIO, wcd *-supply, lpi pinctrl settings. I believe the "read underflow" error here is because the whole driver stack is already trying to suspend so then communication fails. The real question for me is why the swr 'slaves' only appear exactly when pm_runtime is suspending everything.

Quoted 1 line

Yeah, good question.

Too bad you don't have an amazing idea why this is happening ;)

Thanks for your advise, let's see if it gets me any further!

Regards
Luca

Quoted 22 lines
Quoted 10 lines

The only thing I've not really checked yet is qcom,rx-port-mapping & qcom,tx-port-mapping, there I've just tried the two different values found on the various devices but I don't think this is causing these issues. I will try to look further into this property at some point but with msm-5.4 downstream it's quite tricky to find where these values are represented (I got some hints from Krzysztof though where to look so I'll try to do that soon)

Quoted 8 lines

I'm attaching my current diff to the email, just note that it's based on one of my dev branches and is manually edited to remove some debug prints etc so it will probably not apply anywhere. I can also push the git tree somewhere in case that's helpful.

Regards
Luca

Best regards,
Krzysztof