milkv-duo / duo-buildroot-sdk-v2

Milk-V Duo Official buildroot SDK V2
33 stars 27 forks source link

Duo S: Suspend-to-RAM failure when `aic8800` Wi-Fi driver is loaded #18

Open ardangelo opened 6 days ago

ardangelo commented 6 days ago

Build of edb9ca4 for MilkV Duo S, configuration sg2000_milkv_duos_musl_riscv64_sd_defconfig. Following the steps on https://github.com/milkv-duo/duo-buildroot-sdk-v2/commit/f11eb52dd744ebc0fd57da7f71bb06ff94ad74e6 , I enabled CONFIG_KERNEL_SUSPEND in the defconfig file. Additionally, I added CONFIG_SUSPEND=y, CONFIG_SUSPEND_FREEZER=y, CONFIG_PM_SLEEP=y to the kernel configuration. Attempting suspend results in an error.

[root@milkv-duo]~# insmod /mnt/system/ko/cv181x_rtc.ko
[root@milkv-duo]~# hwclock -w
[root@milkv-duo]~# cat /sys/power/state
freeze mem
[root@milkv-duo]~# echo +30 >/sys/class/rtc/rtc0/wakealarm
[root@milkv-duo]~# echo mem > /sys/power/state
[   87.494847] PM: dpm_run_callback(): pm_generic_suspend+0x0/0x12 returns -22
[   87.494856] PM: Device mmc1:390b:2 failed to suspend async: error -22
[   87.494882] PM: Some devices failed to suspend, or early wake event detected
sh: write error: Invalid argument
ardangelo commented 6 days ago

AIC driver is causing the suspend failure. Unloading the AIC driver allows suspend to succeed.

rmmod aic8800_fdrv
rmmod aic8800_bsp
insmod /mnt/system/ko/cv181x_rtc.ko
date -s 2024-11-23
hwclock -w
hwclock -w
echo +30 >/sys/class/rtc/rtc0/wakealarm
echo mem > /sys/power/state

no_console_suspend will show more detail on the suspend failure when driver is loaded.

echo N | tee /sys/module/printk/parameters/console_suspend
echo mem > /sys/power/state
[  328.663206] PM: suspend entry (deep)
[  328.683683] Filesystems sync: 0.020 seconds
[  328.683941] Freezing user space processes ... (elapsed 0.001 seconds) done.
[  328.685555] OOM killer disabled.
[  328.685562] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) do
ne.
[  328.687340] aicbsp: aicbsp_sdio_suspend, func->num = 2
[  328.687351] aicbsp: aicbsp_sdio_suspend: can't keep power while host is suspe
nded
[  328.687374] PM: dpm_run_callback(): pm_generic_suspend+0x0/0x12 returns -22
[  328.694637] aicsdio: aicwf_sdio_suspend enter
[  328.694655] PM: dpm_run_callback(): pm_generic_suspend+0x0/0x12 returns -22
[  328.701889] PM: Device mmc1:390b:2 failed to suspend async: error -22
[  328.708582] PM: Device mmc1:390b:1 failed to suspend: error -22
[  328.714748] PM: Some devices failed to suspend, or early wake event detected
[  328.722663] OOM killer enabled.
[  328.722671] Restarting tasks ... done.
[  328.725157] PM: suspend exit
ardangelo commented 5 days ago

In drivers/net/wireless/aicsemi/aic8800/aic8800_fdrv/aicwf_sdio.c, there is a check for the MMC_PM_KEEP_POWER flag in PM capabilities, it is not enabled, so suspend fails.

    sdio_flags = sdio_get_host_pm_caps(sdiodev->func);
    if (!(sdio_flags & MMC_PM_KEEP_POWER))
        return -EINVAL;