Here is a way to get the onboard audio working on NanoPC T4 (and probably M4 too). It kind-of works with pulseaudio, but I think more work is needed for a good solution for pulseaudio (need to develop a UCM profile). The attached asound.state file will configure the rt5651 codec mixer with sane settings. To use it:
Download the attached asound.state.draft.201902018
Run the following command from a terminal (in whatever directory you downloaded the file):
alsactl --file ./asound.state.draft.201902018 restore
After that you should have working headphone audio and microphone capture.
WARNING: this command may make a loud audible thump. Do not wear the headphones when running it.
Note that in the absence of a ucm profile, pulseaudio might make its own changes to the codec mixer settings at login, so you should run the above alsactl restore command *after* logging into the desktop. You can try using alsactl globally to save the settings for use after reboot, but personally I have not yet found a good solution -- please let me know if you have any thoughts on permanent save/restore and pulseaudio interop. There is some general discussion about asound.state management here.
If you run alsamixer from the command line you can adjust output level using "DAC1" and "HP". Hit F4 for capture, then the gain settings that appear to work for the internal microphone are "ADC", "ADC Boost Gain" and "IN2 Boost".
...
So far I developed this configuration with the help of the following resources:
plbossart's configuration for baytrail boards using the same ALC5651 codec:
https://github.com/plbossart/UCM
ALC5651 codec data sheet v0.92
https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/6/ALC5651-DataSheet_5F00_V0.92.pdf
(Audio routing diagrams are on pages 4 and 5. Page 4 is the analog routing, page 6 is the digital routing.)
NOTE: Beyond the codec mixer settings I think there are some things that can be tweaked with the device tree and drivers that may improve the microphone noise floor, but I haven't gone too far into that yet.
If anyone is interested I'm happy to share my notes or discuss details of the routings I chose.
asound.state.draft.201902018