PabloPL / linux

Linux kernel source tree
Other
17 stars 0 forks source link

Audio driver #11

Closed xc-racer99 closed 2 years ago

xc-racer99 commented 6 years ago

There is a 3.3-based wm8994 driver for one of the CDMA Galaxy S variants (Verizon Fascinate/SCH-i500) at https://github.com/syndtr/android-kernel/blob/qss-next/sound/soc/samsung/qss_wm8994.c

The modem part would need to change and it would need to be brought up to date (eg DT), but the rest is likely functional. Android userspace part at https://github.com/syndtr/android_device_samsung_qss/tree/master/audio

Alternatively, we could resurrect the goni driver.

PabloPL commented 6 years ago

For modem part, maybe we could base on this https://github.com/fourkbomb/linux/tree/modem.

Edit 1: Also this could be usefull https://github.com/tom3q/linux/commit/dd9af275b9e0407bfb0d1063a089afe567308c17.

xc-racer99 commented 6 years ago

Thanks for the second part, I'd missed the fact that a simple wm8994 driver had been implemented there.

PabloPL commented 6 years ago

@xc-racer99 Could You push branch with audio changes and describe what problems are with it?

xc-racer99 commented 6 years ago

Created branch https://github.com/PabloPL/linux/tree/wip-audio

Current state: probes, detects chip properly (without interrupts as I can't find an interrupt connected to it from the stock kernel). Broken: Playing a wav file with sox/play command plays extremely quickly then hangs (with pulseaudio) or just hangs (without pulseaudio). Notes: -The pinctrl (audio_pwr) should theoretically be moved into wm8994 node under the gpio ldo property. -Might want to move the clock node (MCLK) to the wm8994 node, but it is the responsibility of the machine-specific driver to adjust it (see commit 087ee0934e23c8dce0f6a0f237f919efdbbb4285) -Based on stock kernel line

    MUX(MOUT_CLKOUT, "mout_clkout", mout_clkout_p, MISC, 8, 2),

in drivers/clk/clk-s5pv210.c should be

    MUX(MOUT_CLKOUT, "mout_clkout", mout_clkout_p, MISC, 8, 3),

-Prior to DT, idma address for i2s0 was 0xc0000000 but is now listed as 0xc0001000 in the s5pv210 dtsi

Currently, I'm working on booting a stock-ish non-DT kernel to test with.

PabloPL commented 6 years ago

Looking at s5pv210.dtsi, i2s0 is using clk_audss (compatible = "samsung,s5pv210-audss-clock") which is not enabled in defconfig ? (EXYNOS_AUDSS_CLK_CON).

Also according to documentation at Documentation/devicetree/bindings/sound/samsung-i2s.txt

#sound-dai-cells = <0>;

should be

#sound-dai-cells = <1>;

Edit 1:

without interrupts as I can't find an interrupt connected to it from the stock kernel

I hope that You have schematics for Your device ;). Looking at it, i don't see anything which could be irq line.

xc-racer99 commented 6 years ago

EXYNOS_AUDSS_CLK_CON != s5pv210 - s5pv210 audss clk is built whenever CONFIG_ARCH_S5PV210 is defined.

I've managed to get playback working (except sound routing issues, but that can come later) in a 3.3 based kernel so I now know more or less what to look for.

Edit: Documentation for exynos audss clock is a bit misleading in that it mentions s5pv210 - there's a separate driver for s5pv210

xc-racer99 commented 6 years ago

Turns out I didn't really have anything majorly wrong, simply pulseaudio won't run properly as the root user. Creating a non-root user and running pulseaudio as it causes playback to work at the correct speed, albeit without no sound. Will need to check into the routing and make sure I've done it correctly.

xc-racer99 commented 6 years ago

Alright, turns out when I thought I had things working via pulseaudio it was actually using a dummy output - not the wm8994. I've turned things on it's head a little and started implementing the mainline wm8994 and Samsung I2S drivers on the 3.0 kernel and with Android 4.4 - that work is at https://github.com/xc-racer99/android_kernel_samsung_aries/tree/mainline-wm8994 and https://github.com/xc-racer99/android_device_samsung_aries-common/tree/mainline-wm8994

Currently, the headphones and speaker are confirmed working.

TODO: 1) Test the microphone 2) Test calling (may need someone else to test this on the i9000 as well - I think the input clock from my modem is at 32khz while the i9000 comes in at 24khz - but I'm guessing as I don't have schematics for the i9000 - there might even be some master/slave changes) 3) Convert the Android audio HAL into ALSA UCM 4) Forward-port the 3.0 mainline machine driver changes to 4.19

WISHLIST: 1) Add support for Bluetooth audio (uses AIF3, and might be able to do it) 2) Add support for FM radio (I can't test this as my variant doesn't have an FM radio) 3) Add support for USB dock audio (I don't have an audio dock, but could probably cobble one together from spare parts)

PabloPL commented 6 years ago

About modem clock - i have schematic for i9000 (can check), but we will need first to port https://github.com/fourkbomb/linux/tree/modem for i9000.

xc-racer99 commented 6 years ago

For modem, since I have Android set up, I can test it on the 3.0 kernel and assume it works on 4.19.

I don't think we want to port that modem driver - it likely won't work for our devices. AP-CP communication is done via interrupts and onedram (16MB of shared RAM with control being passed between CP and AP) - see https://github.com/xc-racer99/android_kernel_samsung_aries/tree/aosp-7.1/drivers/misc/samsung_modemctl - the folders are used by the S1 series, the individual files are used by crespo (Nexus S) and might actually be a better, cleaner implementation to port - but I have yet to get them working with Replicant's libsamsung-ipc on my variant (however, I expect the i9000 to work out of the box with correct userspace as it shares the xmm6160 modem with crespo - mine uses a different manufacturer and has a few quirks)

USB dock can be made based off instructions at https://forum.xda-developers.com/showthread.php?t=1321491

xc-racer99 commented 6 years ago

Using amixer, the following commands make functional audio on 3.0 kernel:

amixer sset 'SPKR DAC1' on
amixer sset 'SPKL DAC1' on
amixer sset 'DAC2' 96
amixer sset 'DAC1R Mixer AIF1.1' on
amixer sset 'DAC1L Mixer AIF1.1' on
amixer sset 'DAC1' on
amixer sset 'Speaker Mixer' 3
amixer sset 'Speaker' 63
amixer sset 'Speaker Boost' 6
amixer sset 'Speaker' on
amixer sset 'Headphone' off

Note that only the left-hand part of 'Speaker' actually needs to be enabled - the right hand part does nothing. We may need to implement something like https://github.com/fourkbomb/linux/blob/master/sound/soc/samsung/midas_wm1811.c#L160

xc-racer99 commented 6 years ago

Ok, Audio for non-DT S5PV210 worked up until d37bdf736d9b7a198d35aaaf611e96ddc2e00ddf but then stopped working (well between 3.13 and d37bdf736d9b7a198d35aaaf611e96ddc2e00ddf there was a bunch of DMA issues as well).

Edit: 0baf8f6a2ac86c2c40ed0cacab8ea3d17371a1bb supposed fixed the DMA issues... Edit 2: Can confirm above commit fixed the DMA issues, but still don't have anything working... Edit 3: DMA channel finding issues: the following diff fixes audio after d37bdf736d9b7a198d35aaaf611e96ddc2e00ddf

diff --git a/sound/soc/samsung/dmaengine.c b/sound/soc/samsung/dmaengine.c
index 750ce5808d9f..4a71b94ae2be 100644
--- a/sound/soc/samsung/dmaengine.c
+++ b/sound/soc/samsung/dmaengine.c
@@ -17,6 +17,7 @@

 #include <linux/module.h>
 #include <linux/amba/pl08x.h>
+#include <linux/amba/pl330.h>

 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -30,7 +31,7 @@
 #ifdef CONFIG_ARCH_S3C64XX
 #define filter_fn pl08x_filter_id
 #else
-#define filter_fn NULL
+#define filter_fn pl330_filter
 #endif

 static const struct snd_dmaengine_pcm_config samsung_dmaengine_pcm_config = {
PabloPL commented 6 years ago

Offtopic: We need to enable CONFIG_DMADEVICES which will enable CONFIG_PL330_DMA (which is used on s5pv210 according to https://patchwork.kernel.org/patch/981252/).

xc-racer99 commented 6 years ago

Offtopic: We need to enable CONFIG_DMADEVICES which will enable CONFIG_PL330_DMA (which is used on s5pv210 according to https://patchwork.kernel.org/patch/981252/).

Yep, I got that, even confirmed that DMA is working via dmatest.

Currently, I've confirmed that audio works just before the removal of board files (with the above pl330_filter patch - but with the new clock driver) and with the DT just after it was added (without needing the pl330_filter patch). Diff as of d78c16ccde96eddf42942c093b241b5e5135b777:

diff --git a/arch/arm/boot/dts/s5pv210-goni.dts b/arch/arm/boot/dts/s5pv210-goni.dts
index 6387c77a6f7b..c3ba8900fc59 100644
--- a/arch/arm/boot/dts/s5pv210-goni.dts
+++ b/arch/arm/boot/dts/s5pv210-goni.dts
@@ -14,6 +14,7 @@
  */

 /dts-v1/;
+#include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/input/input.h>
 #include "s5pv210.dtsi"

@@ -26,7 +27,11 @@
    };

    chosen {
-       bootargs = "console=ttySAC0,115200n8 root=/dev/mmcblk0p5 rw rootwait ignore_loglevel earlyprintk";
+/*
+       stdout-path = &uart2;
+       bootargs = "root=/dev/mmcblk1p2 rw rootwait ignore_loglevel earlyprintk init=/bin/bash";
+*/
+       bootargs = "root=/dev/mmcblk0p2 rootwait rw console=ttySAC2,115200n8 mem=80M mem=256M@0x40000000 mem=128M@0x50000000 ignore_loglevel earlyprintk mtdparts=b0600000.onenand:256k@25856k(uboot-env),10240k(boot),10240k(recovery),980480k(ubi) ubi.mtd=ubi init=/bin/bash";
    };

    memory {
@@ -242,6 +247,57 @@
            gpio-key,wakeup;
        };
    };
+
+
+   sound {
+       compatible = "samsung,smdk-wm8994";
+
+       samsung,i2s-controller = <&i2s0>;
+       samsung,audio-codec = <&wm8994>;
+   };
+
+   i2c_sound: i2c-gpio-2 {
+       compatible = "i2c-gpio";
+       gpios = <&mp05 3 (GPIO_ACTIVE_HIGH)>, <&mp05 2 (GPIO_ACTIVE_HIGH)>;
+       i2c-gpio,delay-us = <2>;
+       #address-cells = <1>;
+       #size-cells = <0>;
+
+       wm8994: wm8994@1a {
+           compatible = "wlf,wm8994";
+           reg = <0x1a>;
+
+           gpio-controller;
+           #gpio-cells = <2>;
+
+           clocks = <&xusbxti>;
+           clock-names = "MCLK1";
+
+           AVDD2-supply = <&bat_reg>;
+           CPVDD-supply = <&bat_reg>;
+           DBVDD-supply = <&bat_reg>;
+           /* DCVDD-supply = <&bat_reg>; */
+           SPKVDD1-supply = <&bat_reg>;
+           SPKVDD2-supply = <&bat_reg>;
+
+           wlf,gpio-cfg = <0x0001 0xa101 0x8100 0x8100 0x8100 0xa101
+               0x0100 0x8100 0x0100 0x0100 0x0100>;
+
+           wlf,ldo1ena = <&gpf3 4 GPIO_ACTIVE_HIGH>;
+           wlf,ldo2ena = <&gpf3 4 GPIO_ACTIVE_HIGH>;
+
+           lineout1-se;
+           lineout2-se;
+
+           assigned-clocks = <&clocks MOUT_CLKOUT>;
+           assigned-clock-rates = <0>;
+           assigned-clock-parents = <&xusbxti>;
+       };
+   };
+};
+
+&i2s0 {
+   status = "okay";
 };

 &xusbxti {
@@ -322,7 +378,10 @@

 &sdhci2 {
    bus-width = <4>;
+/*
    cd-gpios = <&gph3 4 1>;
+*/
+   non-removable;
    vmmc-supply = <&vtf_reg>;
    cd-inverted;
    pinctrl-0 = <&sd2_clk &sd2_cmd &sd2_bus4>;
diff --git a/arch/arm/configs/s5pv210_defconfig b/arch/arm/configs/s5pv210_defconfig
index fa989902236d..7748b4c9d792 100644
--- a/arch/arm/configs/s5pv210_defconfig
+++ b/arch/arm/configs/s5pv210_defconfig
@@ -1,31 +1,31 @@
-CONFIG_EXPERIMENTAL=y
-CONFIG_SYSFS_DEPRECATED_V2=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_MODULES=y
 CONFIG_MODULE_UNLOAD=y
 # CONFIG_BLK_DEV_BSG is not set
+CONFIG_PARTITION_ADVANCED=y
+CONFIG_BSD_DISKLABEL=y
+CONFIG_SOLARIS_X86_PARTITION=y
 CONFIG_ARCH_S5PV210=y
-CONFIG_S3C_LOWLEVEL_UART_PORT=1
-CONFIG_S3C_DEV_FB=y
-CONFIG_S5PV210_SETUP_FB_24BPP=y
-CONFIG_MACH_AQUILA=y
-CONFIG_MACH_GONI=y
-CONFIG_MACH_SMDKC110=y
-CONFIG_MACH_SMDKV210=y
-CONFIG_NO_HZ=y
-CONFIG_HIGH_RES_TIMERS=y
+# CONFIG_CACHE_L2X0 is not set
 CONFIG_VMSPLIT_2G=y
 CONFIG_PREEMPT=y
 CONFIG_AEABI=y
-CONFIG_CMDLINE="root=/dev/ram0 rw ramdisk=8192 initrd=0x20800000,8M console=ttySAC1,115200 init=/linuxrc"
+CONFIG_ARM_APPENDED_DTB=y
+CONFIG_CMDLINE="console=ttySAC2,115200n8"
 CONFIG_VFP=y
 CONFIG_NEON=y
+CONFIG_NET=y
+CONFIG_UNIX=y
+CONFIG_INET=y
 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_SIZE=8192
-# CONFIG_MISC_DEVICES is not set
 CONFIG_SCSI=y
 CONFIG_BLK_DEV_SD=y
 CONFIG_CHR_DEV_SG=y
@@ -33,41 +33,48 @@ CONFIG_INPUT_EVDEV=y
 # CONFIG_INPUT_KEYBOARD is not set
 # CONFIG_INPUT_MOUSE is not set
 CONFIG_INPUT_TOUCHSCREEN=y
-CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_SAMSUNG=y
 CONFIG_SERIAL_SAMSUNG_CONSOLE=y
 CONFIG_HW_RANDOM=y
+CONFIG_I2C=y
+CONFIG_I2C_GPIO=y
+CONFIG_GPIO_WM8994=y
 # CONFIG_HWMON is not set
-# CONFIG_VGA_CONSOLE is not set
-# CONFIG_HID_SUPPORT is not set
+CONFIG_REGULATOR=y
+CONFIG_REGULATOR_FIXED_VOLTAGE=y
+CONFIG_REGULATOR_GPIO=y
+CONFIG_REGULATOR_WM8994=y
+CONFIG_SOUND=y
+CONFIG_SND=y
+CONFIG_SND_SOC=y
+CONFIG_SND_SOC_SAMSUNG=y
+CONFIG_SND_SOC_SAMSUNG_SMDK_WM8994=y
 # CONFIG_USB_SUPPORT is not set
-CONFIG_EXT2_FS=y
-CONFIG_INOTIFY=y
+CONFIG_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_S3C=y
+CONFIG_DMADEVICES=y
+CONFIG_EXT4_FS=y
 CONFIG_MSDOS_FS=y
 CONFIG_VFAT_FS=y
 CONFIG_TMPFS=y
 CONFIG_TMPFS_POSIX_ACL=y
 CONFIG_CRAMFS=y
 CONFIG_ROMFS_FS=y
-CONFIG_PARTITION_ADVANCED=y
-CONFIG_BSD_DISKLABEL=y
-CONFIG_SOLARIS_X86_PARTITION=y
 CONFIG_NLS_CODEPAGE_437=y
 CONFIG_NLS_ASCII=y
 CONFIG_NLS_ISO8859_1=y
+CONFIG_NLS_UTF8=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_FS=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_PREEMPT is not set
 CONFIG_DEBUG_RT_MUTEXES=y
 CONFIG_DEBUG_SPINLOCK=y
 CONFIG_DEBUG_MUTEXES=y
-CONFIG_DEBUG_SPINLOCK_SLEEP=y
-CONFIG_DEBUG_INFO=y
-# CONFIG_RCU_CPU_STALL_DETECTOR is not set
-CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_DEBUG_USER=y
-CONFIG_DEBUG_ERRORS=y
 CONFIG_DEBUG_LL=y
+CONFIG_DEBUG_S3C_UART2=y
 CONFIG_EARLY_PRINTK=y
-CONFIG_DEBUG_S3C_UART=1
 CONFIG_CRC_CCITT=y
diff --git a/sound/soc/samsung/smdk_wm8994.c b/sound/soc/samsung/smdk_wm8994.c
index 3d6272a8cad2..e7ea4d82deb7 100644
--- a/sound/soc/samsung/smdk_wm8994.c
+++ b/sound/soc/samsung/smdk_wm8994.c
@@ -37,7 +37,7 @@
   */

 /* SMDK has a 16.934MHZ crystal attached to WM8994 */
-#define SMDK_WM8994_FREQ 16934000
+#define SMDK_WM8994_FREQ 24000000

 struct smdk_wm8994_data {
    int mclk1_rate;
@@ -90,20 +90,20 @@ static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
    struct snd_soc_dapm_context *dapm = &codec->dapm;

    /* Other pins NC */
-   snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
-   snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
-   snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
-   snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
-   snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
-   snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
-   snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
-   snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
-   snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
-   snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
-   snd_soc_dapm_nc_pin(dapm, "IN1LP");
-   snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
-   snd_soc_dapm_nc_pin(dapm, "IN1RP");
-   snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
+   snd_soc_dapm_enable_pin(dapm, "HPOUT2P");
+   snd_soc_dapm_enable_pin(dapm, "HPOUT2N");
+   snd_soc_dapm_enable_pin(dapm, "SPKOUTLN");
+   snd_soc_dapm_enable_pin(dapm, "SPKOUTLP");
+   snd_soc_dapm_enable_pin(dapm, "SPKOUTRP");
+   snd_soc_dapm_enable_pin(dapm, "SPKOUTRN");
+   snd_soc_dapm_enable_pin(dapm, "LINEOUT1N");
+   snd_soc_dapm_enable_pin(dapm, "LINEOUT1P");
+   snd_soc_dapm_enable_pin(dapm, "LINEOUT2N");
+   snd_soc_dapm_enable_pin(dapm, "LINEOUT2P");
+   snd_soc_dapm_enable_pin(dapm, "IN1LP");
+   snd_soc_dapm_enable_pin(dapm, "IN2LP:VXRN");
+   snd_soc_dapm_enable_pin(dapm, "IN1RP");
+   snd_soc_dapm_enable_pin(dapm, "IN2RP:VXRP");

    return 0;
 }
@@ -120,6 +120,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
        .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
            SND_SOC_DAIFMT_CBM_CFM,
        .ops = &smdk_ops,
+#if 0
    }, { /* Sec_Fifo Playback i/f */
        .name = "Sec_FIFO TX",
        .stream_name = "Sec_Dai",
@@ -130,6 +131,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
        .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
            SND_SOC_DAIFMT_CBM_CFM,
        .ops = &smdk_ops,
+#endif
    },
 };
xc-racer99 commented 6 years ago

Created branch https://github.com/PabloPL/linux/tree/v4.19-rc7-audio with minimal working audio support after running the commands in https://github.com/PabloPL/linux/issues/11#issuecomment-420137700

Turns out it was a clock issue with PDMA1 needing PDMA0's clock enabled as well.

I will be creating a new machine driver that is designed for aries that will support things such as the microphone, FM radio, modem, etc

xc-racer99 commented 5 years ago

Branch at https://github.com/xc-racer99/linux/tree/modem-audio contains a machine driver along with modem drivers.

Currently known that (with HiFi verb) earpiece, speaker, headphone, mic, and headset mic work with the master branch from https://github.com/xc-racer99/aries_ucm while the tizen_wm1811 also should work (not as fully tested).

Note that the above is with manually running alsaucm (alsaucm set _verb HiFi set _enadev Speaker); pulseaudio works if you remove any input paths from the UCM files but as soon as you add an input path nothing plays or records. I don't know why this issue occurs.

xc-racer99 commented 5 years ago

@PabloPL Would you mind testing the above ucm files (put the folders in /usr/share/alsa/ucm) with pulseaudio on Ubuntu? I'm wondering if it's a debian pulseaudio issue as there is similar issue described at https://github.com/maemo-leste/bugtracker/issues/77 which also appears using the debian stretch packages as far as I can tell.

PabloPL commented 5 years ago

@xc-racer99 Sure, i'll do testing tomorrow (since today it's too late) and leave response here.

PabloPL commented 5 years ago
[    1.860448] exynos-adc e1700000.adc: e1700000.adc supply vdd not found, using dummy regulator
[    1.877589] exynos-adc e1700000.adc: Linked as a consumer to regulator.0
[    1.894461] wm8994-codec wm8994-codec: Failed to request Mic1 detect IRQ: -22
[    1.911013] wm8994-codec wm8994-codec: Failed to request Mic1 short IRQ: -22
[    1.926933] wm8994-codec wm8994-codec: Failed to request Mic2 detect IRQ: -22
[    1.943177] wm8994-codec wm8994-codec: Failed to request Mic2 short IRQ: -22
[    2.052407] aries-audio-wm8994 sound: wm8994-aif1 <-> samsung-i2s mapping ok
[    2.069144] aries-audio-wm8994 sound: wm8994-aif2 <-> Voice call mapping ok
[    2.085523] aries-audio-wm8994 sound: wm8994-aif3 <-> Bluetooth mapping ok
[    2.109140] wm8994 10-001a: Failed to write 102 = 3: -6
[    2.117647] wm8994 10-001a: Failed to restore register map: -6                                                                                                                                                                                  
[    2.129738] input: Aries Dock as /devices/platform/sound/sound/card0/input0
[    2.146734] input: Aries Headset as /devices/platform/sound/sound/card0/input1
xc-racer99 commented 5 years ago

The adc supply is normal, the missing IRQ is normal (irq line isn't wired up).

The "Failed to write 102"/"Failed to restore register map" messages are something that isn't present on my variant... Looks like I might have messed up something on the galaxys dts

xc-racer99 commented 5 years ago

Can confirm that on Debian Jessie pulseaudio (v5.0-13) works just fine. jessie-backports pulseaudio of v7.1-2~bpo8+1 also works just fine.

Next up is Buster (pulseaudio v12.2-3) to see if it works, unlike stretch (v10.0-1+deb9u1).

xc-racer99 commented 5 years ago

Ok, I'm very confused now :)

Buster didn't work either. However, I have now discovered that audio will work on Stretch+ for 5s after the pulseaudio daemon is started (probably until module-suspend-on-idle kicks in).

So I figured no problem, I'll just bisect the issue in pulseaudio on jessie. I started with installing the pulseaudio and alsa packages from stretch on jessie, and they work.

I have posted a comparison of the pulseaudio output and the pactl list between stretch and jessie with stretch audio packages at https://gist.github.com/xc-racer99/ee7181c3f21a97f8cc321e3bc71c1d86 and I see no appreciable difference.

At this point, I'm going to assume that I'm missing some other package on stretch+ and just debug the UCM files on jessie (I'm still working a bit on getting all jacks to work and having all outputs working). If anyone has any ideas, let me know!

PabloPL commented 5 years ago

Any progress on this (which is final branch)? I want to check why it was failing for me on galaxys (those errors on boot).

xc-racer99 commented 5 years ago

I haven't really cleaned things up yet; my wip branch is at https://github.com/xc-racer99/linux/tree/modem-audio

https://github.com/xc-racer99/aries-hw-files/tree/older-ucm contains some very messy WIP UCM files that may or may not be updated for Aries...

Note that I'm unable to reproduce the the galaxys failing on my device, I rechecked some GPIOs and everything looked good...

PabloPL commented 5 years ago

Ok, do You want me to check this on galaxys or i should wait till it get finished (and i'll just look at different thing now - that's no problem)?

xc-racer99 commented 5 years ago

Up to you. If you could try and see if it probes correctly now that would be great. UCM files will need some work and some testing on fm radio.

xc-racer99 commented 5 years ago

@PabloPL I figured out where

[    2.109140] wm8994 10-001a: Failed to write 102 = 3: -6
[    2.117647] wm8994 10-001a: Failed to restore register map: -6 

is coming from. It appears the regmap patch (https://github.com/PabloPL/linux/blob/master/drivers/mfd/wm8994-core.c#L245) appears to not apply. What revision is on your i9000? There should be some lines like

[    1.006871] wm8994 10-001a: Linked as a consumer to regulator.23
[    1.010877] wm8994 10-001a: Linked as a consumer to regulator.2
[    1.020334] wm8994 10-001a: WM8994 revision D CUST_ID 00
[    1.030088] wm8994 10-001a: No interrupt specified, no interrupts

where you can see that I have a rev D wm8994. It's possible the i9000 has an earlier rev and/or customer id and that's why there's issues.

If you could please try https://github.com/xc-racer99/linux/tree/30d147f1833fd7eea946b30103d45a66c3d97dce along with https://github.com/xc-racer99/aries-hw-files/tree/ucm-wip when you have a chance that would be great! Notably the FM radio hasn't been tested; I don't even know if its connected to in2r and in2l or just in2r (UCM files treat it as if its just in2r but based on vendor kernel driver it should be both in2r and in2l).

I'm currently still working on the modem audio part of things, slowly working my way towards being able to test but it's a lot longer process than I thought.

Note that if you do start playing around with UCM files and/or routing; make sure to disable the alsa-restore service - note that it is very difficult to disable, I ended up skipping disabling it and simply renamed /usr/sbin/alsactl. Disabling the systemd service doesn't work (see https://bbs.archlinux.org/viewtopic.php?id=152049 for why) and masking it didn't appear to work for me either.

Turns out that the wm1811 UCM files didn't really work (and hence why audio would stop after 5s) but it was sort of working due to remnants of a previous test that alsa-restore had thoughtfully restored for me...

PabloPL commented 5 years ago

It looks like radio is connected to both in2r and in2l. Will do testing of audio.

PabloPL commented 5 years ago
[    0.993796] wm8994 10-001a: Linked as a consumer to regulator.22
[    0.997225] wm8994 10-001a: Linked as a consumer to regulator.2
[    1.007341] wm8994 10-001a: Failed to read ID register
[    1.010082] wm8994 10-001a: Dropping the link to regulator.2

And later, multiple times

[    1.877918] aries-audio-wm8994 sound: ASoC: CODEC DAI wm8994-aif1 not registered
[    1.894113] aries-audio-wm8994 sound: Failed to register card: -517 
PabloPL commented 5 years ago

I've tried to reset wm8994 before reading device id (like it's done in original sources), but then i'm getting error

wm8994 10-001a: Failed to reset device before reading ID register: -6

Where -6 errno means "No such device or address"...It's strange, checked and all looks good (dts etc).

xc-racer99 commented 5 years ago

[ 0.993796] wm8994 10-001a: Linked as a consumer to regulator.22 [ 0.997225] wm8994 10-001a: Linked as a consumer to regulator.2 [ 1.007341] wm8994 10-001a: Failed to read ID register [ 1.010082] wm8994 10-001a: Dropping the link to regulator.2

That's the same error I had initially before I'd set wlf,ldo1ena = <&gpf3 4 GPIO_ACTIVE_HIGH>; - it means the chip isn't powered on properly (as in no such i2c address). Funny that you're getting that error now as I haven't changed anything from the previous dts for galaxys that would affect that.

You could try using pinctrl to force gpf3-4 to high

PabloPL commented 5 years ago

Solved this issue. This was caused because in s5pv210-aries.dtsi we have

i2c_sound: i2c-gpio-2

and s5pv210-galaxys.dts there is

i2c_fmradio: i2c-gpio-2

After changing it to

i2c_fmradio: i2c-gpio-3

I got

wm8994 10-001a: Linked as a consumer to regulator.22
wm8994 10-001a: Linked as a consumer to regulator.2
wm8994 10-001a: WM8994 revision D CUST_ID 00
wm8994 10-001a: No interrupt specified, no interrupts

And later i got

[    1.915587] aries-audio-wm8994 sound: Linked as a consumer to regulator.3
[    1.932307] wm8994-codec wm8994-codec: Failed to request Mic1 detect IRQ: -22
[    1.948289] wm8994-codec wm8994-codec: Failed to request Mic1 short IRQ: -22
[    1.964483] wm8994-codec wm8994-codec: Failed to request Mic2 detect IRQ: -22
[    1.981035] wm8994-codec wm8994-codec: Failed to request Mic2 short IRQ: -22
[    2.085987] aries-audio-wm8994 sound: wm8994-aif1 <-> samsung-i2s mapping ok
[    2.106700] aries-audio-wm8994 sound: wm8994-aif2 <-> sound mapping ok
[    2.124174] wm8994 10-001a: Failed to write 102 = 3: -6
[    2.132880] wm8994 10-001a: Failed to restore register map: -6
[    2.144705] input: Aries Dock as /devices/platform/sound/sound/card0/input0
[    2.161753] input: Aries Headset as /devices/platform/sound/sound/card0/input1
xc-racer99 commented 5 years ago

Yet it's still failing to write the register map despite being the same revision as mine. (IRQ errors can be ignored as we don't have the interrupt line hooked up).

I'm not really sure what to try, to be honest. It seems really odd to me that its not working on the galaxys while its working just fine on the fascinate4g. I suppose it might be worthwhile testing the wlf,gpio-cfg from https://github.com/xc-racer99/linux/blob/30d147f1833fd7eea946b30103d45a66c3d97dce/arch/arm/boot/dts/s5pv210-fascinate4g.dts although I wouldn't think that would affect things...

Could also try removing the regmap patch from drivers/mfd/wm8994-core.c

xc-racer99 commented 5 years ago

Ok, I have managed to reproduce the error on my device. It looks as if it is related to a clocking issue as it happens when I start messing around with the FLL clocking. I strongly suspect that if you change https://github.com/xc-racer99/linux/blob/30d147f1833fd7eea946b30103d45a66c3d97dce/sound/soc/samsung/aries_wm8994.c#L280 to

pll_out = params_rate(params) * 512;

then it will work properly.

Edit: Maybe not, this might be too late. Might need to create a bias_enable/original init and/or just fll2 to on all the time.

On the vendor kernel for non-STE modem devices, it always uses AIF1's clock for sysclk whereas the mainline driver must do things differently. I wonder if this is a bug upstream (checking the aifclk input rate as opposed to output rate perhaps), I will try and debug this when I have a chance and my battery recharges.

xc-racer99 commented 5 years ago

Ok, I've been playing around a lot with the modem audio lately. Here's the status: Using the UCM files at https://github.com/xc-racer99/aries-hw-files/tree/ucm-voice-calls and my WIP tree at https://github.com/xc-racer99/linux/tree/modem-audio (as of writing at revision https://github.com/xc-racer99/linux/tree/03c1c5b9c6d8def44834168d5b6a6a9d43b5b5bb) - all HiFi functions work, outgoing voice works but no incoming voice (need to figure out why). Bluetooth profiles haven't been created and no preliminary testing has been done.

The restore register map error was due to improper clocking of the device, it should be fixed now.

Still TODO:

xc-racer99 commented 5 years ago

See also https://github.com/PabloPL/aries-hw-files/pull/1

Current state (https://github.com/xc-racer99/linux/commit/d8ab33d87fe11314b24f982d4bafb0ac89d57675) is that call audio and hifi works. BT untested. Still need some cleanups in aries_wm8994 wrt the fully_routed property and whether we should bother with it or not. Additionally need to write down the binding documentation.

xc-racer99 commented 5 years ago

Ok, so the

[    2.124174] wm8994 10-001a: Failed to write 102 = 3: -6
[    2.132880] wm8994 10-001a: Failed to restore register map: -6

bug has come back to bit me :) Digging into it again, it appears that it is related to the fact that we're not waiting long enough after enabling gpf3-4. I'm guessing based on what registers are on in which power map, that gpf3-4 is not connected to the LDO1 pin on the wm8994, but rather is connected to DBVDD. Regardless, I've updated the DTS to show it this way, as then we can set a startup-delay-us of 80000 (80ms) which is long enough for everything to be powered properly.

Edit: Maybe this isn't even the issue, as it has shown up again. I wish I could figure out why...

Branch at https://github.com/xc-racer99/linux/tree/modem-audio updated.

Note that I've decided to drop the fully_route property from the ASoC driver. This means that the userspace UCM files will need some adjusting as all of the (virtual) modem controls aren't needed.

PabloPL commented 5 years ago

GPF3-4 is connected to LDO1ENA and LDO2ENA pins of wm8994. DBVDD is connected to VCC_1.8V_PDA which goes from max8998 (LX3 pin).

xc-racer99 commented 5 years ago

DBVDD is connected to VCC_1.8V_PDA which goes from max8998 (LX3 pin).

I'm guessing LX3 pin is buck3 in DTS? Where are other regulators supplied from? We have

PabloPL commented 5 years ago

AVDD1 - GND AVDD2/CPVDD/DBVDD/LDO2VDD - buck3 DCVDD - GND LDO1VDD/SPKVDD1/SPKVDD2 - V_BAT (could not find what is value for this)

Edit 1: On goni V_BAT is set to 3700000 microvolts.

Edit 2: Hm... tom3q had it set to 4200000 https://github.com/tom3q/linux/commit/dd9af275b9e0407bfb0d1063a089afe567308c17

xc-racer99 commented 5 years ago

Edit 1: On goni V_BAT is set to 3700000 microvolts.

Edit 2: Hm... tom3q had it set to 4200000 tom3q@dd9af27

Yep, I noticed those too. However, tom3q also has GPH1(0) as controlling V_BAT, while we appear to have no such pin.

It could be that V_BAT is directly connected from the battery itself. That would explain the 3.7V

PabloPL commented 5 years ago

@xc-racer99 Did You tried to do something like this

wm8994_codec_en: wm8994-codec-en {
    samsung,pins = "gpf3-4";
    samsung,pin-function = <EXYNOS_PIN_FUNC_OUTPUT>;
    samsung,pin-pud = <S3C64XX_PIN_PULL_NONE>;
    samsung,pin-drv = <EXYNOS4_PIN_DRV_LV1>;
    samsung,pin-val = <1>;
};

And then in wm8994 node reference it in

pinctrl-names = "default";
pinctrl-0 = <&wm8994_codec_en>;

Just a idea

xc-racer99 commented 5 years ago

Yeah, I have tried something like that - it didn't work. There is something really off in the power management of the entire wm8994 code, because about 10s into playing via pulseaudio, pulseaudio detects things as not in use and tries to suspend them...

I should really hook into kgdb and find out exactly when things are being called.

xc-racer99 commented 5 years ago

Ugh, finally figured out why I was having some many issues with jack detection - the GPIO on my main testing device must be partially broken as it doesn't work properly in Android either. Means I can now firm up jack detection.

Still haven't figured out why we sometimes have errors writing to the i2c and sometimes don't. Still need to connect KGDB to figure this one out.

PabloPL commented 5 years ago

@xc-racer99 Could You try

alsactl store -f alsa_state.txt

And later restore

alsactl restore -f alsa_state.txt

On first one i'm getting

alsactl: get_control:256: Cannot read control '2,0,0,IN1L Volume,0': No such device or address

I wonder from where it got that IN1L...

xc-racer99 commented 5 years ago

IN1L is connected to the main microphone. alsactl is probably having issues reading the control because when we get the Failed to write 102 = 3: -6 it essentially has brought the device to its knees and then controls stop working either (really all i2c communication).

I have figured out a workaround for this error though - it appears that we need a bit of a timeout after disabling the regulators before enabling them again. A patch like https://github.com/xc-racer99/linux/commit/e1b619db5634a47ef5d472ecece41ef580177f45 works, although you can also add an "off_on_delay" to the wm8994 regulators to get the same effect. I've uploaded a newer branch at https://github.com/xc-racer99/linux/tree/v5.3-rc1-audio that appears to be mostly functional, but is still somewhat a WIP (I don't have the i9000 dts updated there, but it's quite similar to the fascinate one).

PabloPL commented 5 years ago

UCM files stays the same?

xc-racer99 commented 5 years ago

UCM files stays the same?

Modem has changed slightly, but the main HiFi should be the same (I haven't changed the one's I'm using)

xc-racer99 commented 4 years ago

Audio machine driver upstream, but no DTS yet.

xc-racer99 commented 2 years ago

All audio patches are now merged. UCM2 files at https://github.com/xc-racer99/aries-hw-files/tree/ucm2