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

Initial WM8960 Support #2126

Open
wants to merge 12 commits into
base: buster/dev
Choose a base branch
from
Open

Initial WM8960 Support #2126

wants to merge 12 commits into from

Conversation

hftsai256
Copy link

Initial Waveshare WM8960 Audio HAT support. Requires a separated archive:
/lib/modules/5.4.83+/kernel/sound/soc/codecs/snd-soc-wm8960.ko
/lib/modules/5.4.83+/kernel/sound/soc/bcm/snd-soc-wm8960-soundcard.ko
/boot/overlays/wm8960-soundcard.dtbo

Can those kernel modules be built under qemu-static environment?

@@ -56,7 +56,8 @@
{"id":"st400-dac-amp","name":"ST400 Dac (PCM5122) - Amp","overlay":"iqaudio-dacplus","alsanum":"2","mixer":"Digital","modules":"","script":"","needsreboot":"yes"},
{"id":"taudac","name":"TauDAC - DM101","overlay":"taudac","alsanum":"2","mixer":"","modules":"","script":"","eeprom_name":"TauDAC-DM101","needsreboot":"yes"},
{"id":"terraberry-dac2","name":"Terra-Berry DAC 2/3","overlay":"i-sabre-q2m","alsanum":"2","alsacard":"DAC","mixer":"","modules":"","script":"","needsreboot":"yes"},
{"id":"es90x8q2m-dac","name":"Volumio ESS 9028QM","overlay":"es90x8q2m-dac","alsanum":"2","mixer":"Digital","modules":"","script":"","i2c_address":"48","needsreboot":"no"}
{"id":"es90x8q2m-dac","name":"Volumio ESS 9028QM","overlay":"es90x8q2m-dac","alsanum":"2","mixer":"Digital","modules":"","script":"","i2c_address":"48","needsreboot":"no"},
{"id":"wm8960-soundcard","name":"Waveshare - WM8960","overlay":"wm8960-soundcard,i2s-mmap","alsanum":"1","alsacard":"wm8960soundcard","mixer":"Playback","modules":["i2c-dev","snd-soc-wm8960","snd-soc-wm8960-soundcard"],"script":"","i2c_address":"1a","needsreboot":"yes"}
Copy link
Author

@hftsai256 hftsai256 Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alsanum varies across different SBC (1 on pi zero, 2 on pi 3B+/4). I think it is used for collecting amixer from console, but amixer can also take alsacard as an argument, e.g.:

volumio@voluzero:~$ amixer -c wm8960soundcard
Simple mixer control 'Headphone',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 109 [86%] [-12.00dB]
  Front Right: Playback 109 [86%] [-12.00dB]
...

I believe we could deprecate alsanum field?

@ashthespy
Copy link
Collaborator

ashthespy commented Jul 13, 2021

Small request for clarity down the line - could you move your changes to i2s_dacs/index.js into a new commit and force push?

Out of curiosity, why does this DAC require both modules and the overlay? The device tree should technically load the modules right?

@hftsai256
Copy link
Author

Out of curiosity, why does this DAC it require both modules and the overlay? The device tree should technically load the modules right?

Well... Yes and no. I reached this thread and checked the default kernel configuration. Turns out CONFIG_SND_SOC_WM8960 is not set by default and I believe the majority of Volumio users wouldn't bother (or don't know how) to build their own kernel for the device.

@ashthespy
Copy link
Collaborator

Out of curiosity, why does this DAC it require both modules and the overlay? The device tree should technically load the modules right?

Well... Yes and no. I reached this thread and checked the default kernel configuration. Turns out CONFIG_SND_SOC_WM8960 is not set by default

Correct, but that is to compile the kernel module, which thanks to your other PR in the build repo will bake the required modules into the image.

The overlay normally should then be able to pick the compiled modules up, without having to additionally manually load them right?

@hftsai256
Copy link
Author

hftsai256 commented Jul 14, 2021

The overlay normally should then be able to pick the compiled modules up, without having to additionally manually load them right?

Just confirmed simply loading the overlay will also pull in the related kernel module, which is snd_soc_wm8960. I guess I was missing i2c-dev so the device won't talk.

volumio@voluzero:~$ cat /etc/modules
i2c-dev
volumio@voluzero:~$ lsmod | grep wm8960
snd_soc_wm8960         40960  1
regmap_i2c             16384  1 snd_soc_wm8960
snd_soc_core          200704  4 snd_soc_simple_card_utils,snd_soc_bcm2835_i2s,snd_soc_wm8960,snd_soc_simple_card
snd_pcm                94208  5 snd_pcm_dmaengine,snd_soc_bcm2835_i2s,snd_bcm2835,snd_soc_core,snd_soc_wm8960
snd                    73728  12 snd_compress,snd_seq,snd_timer,snd_seq_device,snd_bcm2835,snd_soc_core,snd_soc_wm8960,snd_pcm

This kernel option is kinda likely being overlooked, because CONFIG_SND_SOC_WM8960 option doesn't show up in any of bcm{2709|2711|2835|rpi}_defconfig. We could:

  1. Host the kernel module separately as this PR is doing
  2. Build our own flavored kernel
  3. File an issue to raspberrypi/linux and request a fix upstream (here)

@ashthespy
Copy link
Collaborator

ashthespy commented Jul 14, 2021

Great work, sorry if my comments have led you down the rabbit hole ;-)

Ideally, option 3 would be best, as CONFIG_SND_SOC_WM8960 should also have a depend that should ensure i2c-dev gets loaded as well. Then you'd only have to load the device tree overlay.

Until it's fixed upstream, we could use the modules that you have built.

I would really like to avoid custom kernels for the pi, will be less maintenance effort, we (well @gkkpch) already has multiple platforms that use special kernels.

@hftsai256
Copy link
Author

hftsai256 commented Jul 16, 2021

I poked around and was trying to figure out the "no sound" problem on my board while waiting reposes from the issue filed upstream. Turns out in addition to kernel modules (which the two PRs mentioned above have it implemented properly), wm8960_asound.state from official repo has to be applied with a refresh (alsactl nrestore) in order to get the sound out. I'm a bit surprised about it because tuning those volumes in alsamixer won't help, and am curious about what's the magic under the hood to make it work.

I've figured out the actual config that mutes both output channels by default, and worked out a new commit to unmute those channels in the init script.

@hftsai256 hftsai256 force-pushed the WM8960 branch 3 times, most recently from 0f19e97 to 7ba6a57 Compare July 18, 2021 03:53
@hftsai256
Copy link
Author

hftsai256 commented Jul 18, 2021

Finally this works OOB after initial setup wizard + reboot

[EDIT] Kernel v5.4.y received this patch. At this moment I made an automated build/package script to deploy kernel modules across multiple platforms to work with another PR.

@ashthespy ashthespy changed the base branch from buster/master to buster/dev July 29, 2021 12:01
@ashthespy
Copy link
Collaborator

@hftsai256 Don't have hardware to test this -- but it looks good to me!
See my comments over at volumio/Build#513 (comment) we should be fine using the modules from wm8960-rpi-modules until we switch to 5.10.yy that has everything baked in.

@ashthespy ashthespy requested a review from volumio July 29, 2021 12:45
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