Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairphone 3 speaker support #137

Draft
wants to merge 4 commits into
base: 6.4.7/main
Choose a base branch
from

Conversation

z3ntu
Copy link

@z3ntu z3ntu commented Sep 23, 2023

Imports downstream amplifier driver (which isn't pretty of course, but works...).

Not quite sure how to handle the required #if 0 in msm8953.dtsi I added (which are necessary because FP3 doesn't use wcd_codec). Should we just move this out of msm8953.dtsi into the device dts which do use wcd_codec?

If that's resolved, I'll of course rework the commits and make them prettier.

FP3 doesn't use wcd_codec, remove bits from msm8953.dtsi

Commands:
echo start | sudo tee /sys/class/remoteproc/remoteproc0/state
amixer -c0 cset name='QUIN_MI2S_RX Audio Mixer MultiMedia1' 1
amixer -c0 cset name='aw8898_speaker_switch' 1
aplay -D plughw:0,0 testfiles/03.wav
@barni2000
Copy link
Member

barni2000 commented Nov 27, 2023

Imports downstream amplifier driver (which isn't pretty of course, but works...).

Not quite sure how to handle the required #if 0 in msm8953.dtsi I added (which are necessary because FP3 doesn't use wcd_codec). Should we just move this out of msm8953.dtsi into the device dts which do use wcd_codec?

If that's resolved, I'll of course rework the commits and make them prettier.

You could override audio-routing and maybe we could add a label for dai-link and than you can delete it with /delete-node/.

@z3ntu
Copy link
Author

z3ntu commented Nov 27, 2023

I'd mostly say non-common stuff (like the stuff I commented out) just shouldn't be in msm8953.dtsi but should be in device dts or so.

@barni2000
Copy link
Member

I'd mostly say non-common stuff (like the stuff I commented out) just shouldn't be in msm8953.dtsi but should be in device dts or so.

I understand audio-routing could be moved out because it is different on almost every device, but what about the dai-link many device uses the wcd_codec, i don't really like the approach duplicating stuffs. With a label you could override the sound-dai property. Or other solution define sound_card node from scratch for FP3.

@spasswolf
Copy link

Just pulled this in on v6.11.1. It needs this patch to compile if drivers are compiled as modules:

commit f0b28192c7cf4623b27d5f955ec239d2888076ac
Author: Bert Karwatzki <[email protected]>
Date:   Sun Nov 10 13:40:27 2024 +0100

    sound: soc: codecs: fix compilation of aw8898
    
    Signed-off-by: Bert Karwatzki <[email protected]>

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 11e062e4d689..3411a1e16854 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -59,6 +59,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_AW88395
 	imply SND_SOC_AW88261
 	imply SND_SOC_AW88399
+	imply SND_SOC_AW8898
 	imply SND_SOC_BT_SCO
 	imply SND_SOC_BD28623
 	imply SND_SOC_CHV3_CODEC
@@ -708,6 +709,13 @@ config SND_SOC_AW88399
 	  digital Smart K audio amplifier and SKTune speaker
 	  protection algorithms.
 
+config SND_SOC_AW8898
+	tristate "Soc Audio for awinic aw8898"
+	depends on I2C
+	help
+	  This option enables support for aw8898 Smart PA found
+	  on the fairphone-fp3
+
 config SND_SOC_BD28623
 	tristate "ROHM BD28623 CODEC"
 	help
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 1e45a938111c..48da6a6d5d18 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -821,4 +821,4 @@ obj-$(CONFIG_SND_SOC_LPASS_TX_MACRO)	+= snd-soc-lpass-tx-macro.o
 # Mux
 obj-$(CONFIG_SND_SOC_SIMPLE_MUX)	+= snd-soc-simple-mux.o
 
-obj-y += aw/aw8898.o
+obj-$(CONFIG_SND_SOC_AW8898) += aw/aw8898.o

And gives a few compile warnings:

sound/soc/codecs/aw/aw8898.c:892:6: warning: no previous prototype for ‘aw8898_writeable_register’ [-Wmissing-prototypes]
  892 | bool aw8898_writeable_register(struct device *dev, unsigned int reg)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/aw/aw8898.c:898:6: warning: no previous prototype for ‘aw8898_readable_register’ [-Wmissing-prototypes]
  898 | bool aw8898_readable_register(struct device *dev, unsigned int reg)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/aw/aw8898.c:904:6: warning: no previous prototype for ‘aw8898_volatile_register’ [-Wmissing-prototypes]
  904 | bool aw8898_volatile_register(struct device *dev, unsigned int reg)
      |      ^~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/codecs/aw/aw8898.c:993:5: warning: no previous prototype for ‘aw8898_hw_reset’ [-Wmissing-prototypes]
  993 | int aw8898_hw_reset(struct aw8898 *aw8898)
      |     ^~~~~~~~~~~~~~~
sound/soc/codecs/aw/aw8898.c:1013:5: warning: no previous prototype for ‘aw8898_read_chipid’ [-Wmissing-prototypes]
 1013 | int aw8898_read_chipid(struct aw8898 *aw8898)
      |     ^~~~~~~~~~~~~~~~~~

@spasswolf
Copy link

spasswolf commented Nov 10, 2024

Also no sound yet, in qpwgraph I only get dummy input and output devices

$ dmesg
[   21.547992] EXT4-fs (mmcblk1p2): mounted filesystem da892b2b-2267-44d1-b4db-d5ae096e02e6 r/w with ordered data mode. Quota mode: disabled.
[   41.949797] aw8898 driver version v1.1.3
[   41.949933] aw8898_i2c_probe enter
[   41.953662] aw8898_smartpa 2-0034: aw8898_parse_dt: reset gpio provided ok
[   41.957455] aw8898_smartpa 2-0034: aw8898_parse_dt: irq gpio provided ok.
[   41.965041] aw8898_hw_reset enter
[   41.979904] aw8898_read_chipid aw8898 detected
[   41.979969] aw8898_read_chipid aw8898->flags=0x3
[   41.984202] aw8898_i2c_probe dai->name(aw8898-aif)
[   41.989510] aw8898_smartpa aw8898_smartpa: aw8898_i2c_probe skipping IRQ registration
[   41.994801] aw8898_i2c_probe probe completed successfully!
[   42.008323] aw8898_probe enter
[   42.009430] aw8898_add_codec_controls enter
[   42.013274] aw8898_probe exit
[   42.062945] input: fairphone-fp3 Headset Jack as /devices/platform/soc@0/c051000.sound-card/sound/card0/input5
[   42.227191]  MultiMedia1: ASoC: no backend DAIs enabled for MultiMedia1, possibly missing ALSA mixer-based routing or UCM profile
[  232.564171] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  232.909056] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  232.948663] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  232.990755] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  233.009461] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  233.048660] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  233.088411] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  233.109336] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[...]

Edit: Probably I'm missing an important CONFIG_ option.

Edit2: I also have a sound card error in dmesg:

[   18.915155] platform c051000.sound-card: deferred probe pending: qcom-apq8016-sbc: Quinary MI2S: codec dai not found

@z3ntu
Copy link
Author

z3ntu commented Nov 10, 2024

Didn't try lately, but did you have adsp booted in your testing? Also the commands you need to run in user space are in the last commit message, but I guess you've also seen them.

@spasswolf
Copy link

The adsp is reported as running in sysfs when I boot into debian. I've compiled every sound option and the remoteprocs with CONFIG_*=y, at least the deferred probe error is gone, but still only dummy devices in qpwgraph.

@spasswolf
Copy link

When I try to adjust the aw8898_rx_volume in alsamixer, I always get these messages in dmesg:

[14678.961013] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[14678.979097] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[14679.018666] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[14679.059877] aw8898_volume_put: NO I2S CLK ,cat not write reg 

Perhaps a missing clock CONFIG option?

@z3ntu
Copy link
Author

z3ntu commented Nov 11, 2024

@spasswolf Did you try the exact branch of this PR? Might be worth to compare if there's something else wrong in your stack.

@spasswolf
Copy link

spasswolf commented Nov 11, 2024

Just tried your branch (6.4.7/main/fp3-audio, commit 012f14b), and got the same error again and a new one

[    8.441805] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[...]
[   15.982948]  MultiMedia2: ASoC: no backend DAIs enabled for MultiMedia2
[   15.982962]  MultiMedia2: ASoC: error at dpcm_fe_dai_prepare on MultiMedia2: -22
[   15.983115]  MultiMedia2: ASoC: no backend DAIs enabled for MultiMedia2
[   15.983121]  MultiMedia2: ASoC: error at dpcm_fe_dai_prepare on MultiMedia2: -22

Here's the full dmesg after booting:
dmesg_fp3_6.4.7.txt

Here's the .config I used:
config_fp3_6.4.7.txt

Edit: If you have a .config that works for you, that would be interesting, too.

@spasswolf
Copy link

Ubuntu touch running in Slot A of my fairphone-fp3 seems to use this as the sound card:

$ cat /sys/class/sound/card0/device/of_node/compatible 
qcom,msm8952-audio-slim-codec

I've found something similar in the msm8996-xiaomi-common.dtsi devicetree:

&slim_msm {
	status = "okay";

	slim@1 {
		reg = <1>;
		#address-cells = <2>;
		#size-cells = <0>;

		tasha_ifd: tas-ifd@0,0 {
			compatible = "slim217,1a0";
			reg = <0 0>;
		};

		wcd9335: codec@1,0 {
			compatible = "slim217,1a0";
			reg = <1 0>;

			clock-names = "mclk", "slimbus";
			clocks = <&divclk1_cdc>,
				 <&rpmcc RPM_SMD_BB_CLK1>;
			interrupt-parent = <&tlmm>;
			interrupts = <54 IRQ_TYPE_LEVEL_HIGH>,
				     <53 IRQ_TYPE_LEVEL_HIGH>;
			interrupt-names = "intr1", "intr2";
			interrupt-controller;
			#interrupt-cells = <1>;

			pinctrl-0 = <&cdc_reset_active &wcd_intr_default>;
			pinctrl-names = "default";

			reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>;
			slim-ifc-dev = <&tasha_ifd>;

			#sound-dai-cells = <1>;

			vdd-buck-supply = <&vreg_s4a_1p8>;
			vdd-buck-sido-supply = <&vreg_s4a_1p8>;
			vdd-rx-supply = <&vreg_s4a_1p8>;
			vdd-tx-supply = <&vreg_s4a_1p8>;
			vdd-vbat-supply = <&vph_pwr>;
			vdd-micbias-supply = <&vph_pwr_bbyp>;
			vdd-io-supply = <&vreg_s4a_1p8>;
		};
	};
};

The relevant devicenodes in the downstream (4.9) FP3 kernel are in msm8953-audio.dtsi:

&slim_msm {
	status = "okay";

	dai_slim: msm_dai_slim {
		status = "okay";
		compatible = "qcom,msm-dai-slim";
		elemental-addr = [ff ff ff fe 17 02];
	};

	wcd9335: tasha_codec {
		status = "okay";
		compatible = "qcom,tasha-slim-pgd";
		elemental-addr = [00 01 A0 01 17 02];

		qcom,cdc-slim-ifd = "tasha-slim-ifd";
		qcom,cdc-slim-ifd-elemental-addr = [00 00 A0 01 17 02];

		interrupt-parent = <&wcd9xxx_intc>;
		interrupts = <0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
				17 18 19 20 21 22 23 24 25 26 27 28 29 30>;

		qcom,wcd-rst-gpio-node = <&wcd_rst_gpio>;

		clock-names = "wcd_clk", "wcd_native_clk";
		clocks = <&clock_audio clk_audio_pmi_clk>,
			<&clock_audio clk_audio_ap_clk2>;

		qcom,cdc-static-supplies =
				"cdc-vdd-buck",
				"cdc-buck-sido",
				"cdc-vdd-tx-h",
				"cdc-vdd-rx-h",
				"cdc-vdd-px";

		qcom,cdc-on-demand-supplies = "cdc-vdd-mic-bias";
		qcom,cdc-micbias1-mv = <1800>;
		qcom,cdc-micbias2-mv = <2800>;
		qcom,cdc-micbias3-mv = <1800>;
		qcom,cdc-micbias4-mv = <1800>;

		qcom,cdc-dmic-sample-rate = <2400000>;
		qcom,cdc-mclk-clk-rate = <9600000>;

		cdc-vdd-buck-supply = <&eldo2_8953>;
		qcom,cdc-vdd-buck-voltage = <1800000 1800000>;
		qcom,cdc-vdd-buck-current = <650000>;

		cdc-buck-sido-supply = <&eldo2_8953>;
		qcom,cdc-buck-sido-voltage = <1800000 1800000>;
		qcom,cdc-buck-sido-current = <150000>;

		cdc-vdd-tx-h-supply = <&eldo2_8953>;
		qcom,cdc-vdd-tx-h-voltage = <1800000 1800000>;
		qcom,cdc-vdd-tx-h-current = <25000>;

		cdc-vdd-rx-h-supply = <&eldo2_8953>;
		qcom,cdc-vdd-rx-h-voltage = <1800000 1800000>;
		qcom,cdc-vdd-rx-h-current = <25000>;

		cdc-vdd-px-supply = <&eldo2_8953>;
		qcom,cdc-vdd-px-voltage = <1800000 1800000>;
		qcom,cdc-vdd-px-current = <10000>;

		cdc-vdd-mic-bias-supply = <&pm8953_l13>;
		qcom,cdc-vdd-mic-bias-voltage = <3125000 3125000>;
		qcom,cdc-vdd-mic-bias-current = <15000>;
	};
};

@z3ntu
Copy link
Author

z3ntu commented Nov 12, 2024

For defconfig, normally I push them to the same branch. Weird I forgot.

In an older branch z3ntu@e49f019#diff-51e9ac942cbedfdaf79995df045cabed9d28c14dc6a166cb2f33f9b252fb70bc I see CONFIG_SND_SOC_WCD9335, CONFIG_SLIMBUS and CONFIG_SLIM_QCOM_NGD_CTRL getting enabled.

@z3ntu
Copy link
Author

z3ntu commented Nov 12, 2024

Also important question which I just remembered, do you have a FP3 or FP3+? The audio amplifier chip is different in the two. FP3 has AW8898 while FP3+ has TAS2557.

@spasswolf
Copy link

I have the normal FP3, in ubuntu touch I get messages from aw8898 in dmesg, too.

In branch (6.4.7/main/fp3-audio, commit 012f14b), there are no slim nodes (and no wcd9335) in the devicetree, perhaps I need to those to get working audio.

@z3ntu
Copy link
Author

z3ntu commented Nov 12, 2024

Just confirmed this branch works still with this .config and the commands in the last commit message.

It's basically make defconfig pmos.config msm8953.config fp3.config with only touchscreen driver also enabled extra.

@spasswolf
Copy link

spasswolf commented Nov 13, 2024

I used your .config and have working sound with aplay now and have "Built-in Audio Stereo" devices in qpwgraph (instead of dummy_devices as before), but still cannot change the volume with alsamixer (same error as before), music plays at the same volume even thought aw8898 volume is 0 in alsamixer.

[  474.662704] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  474.704089] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  474.746164] aw8898_volume_put: NO I2S CLK ,cat not write reg 
[  474.766456] aw8898_volume_put: NO I2S CLK ,cat not write reg 

In 6.11.1 I also have working sound with aplay, but no sound devices are detected in gnome (and gnome sound settings do nothing).

@z3ntu
Copy link
Author

z3ntu commented Nov 13, 2024

but still cannot change the volume with alsamixer (same error as before), music plays at the same volume even thought aw8898 volume is 0 in alsamixer.

I think generally only e.g. pulseaudio reduces the volume and sends that audio stream, and no hardware controls are used to change the volume.

but no sound devices are detected in gnome (and gnome sound settings do nothing).

You need ALSA UCM for pulseaudio to properly detect the audio device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants