Suspend / resume support?

Hi,
has anyone tested if sleep/suspend & resume works ? Could not find /sys/power ( I am using default buildroot). Only info that exists is that 8051 is able to resume the main C906 core but again no any examples … And if I remember right I had read a comment that suspend/resume functionality would be available by the end of April; are there any news regarding that?

The board has low power consumption (~ 500mW idle) but without suspend support it’s use in mobile applications (eg wearables) would be very limited …

2 Likes

Found out that suspend/resume may be enabled in kernel (buildroot)
*> cat /proc/cvitek/power *
suspend resume
but not sure how to enable it. There is no /sys/power/state or any similar file.
Have not checked if default buildroot has PM enabled & have not checked if distros for duo256 have PM enabled. If anyone knows please share !

1 Like

Yeah I was curious about this too, but have no tried it yet!

1 Like

I went through the datasheet for SG2000/SG2002, and looking at the RTC channel I tried directly setting register values, to check if suspend works, like :
devmem 0x050260F0 32 0x0 # set RTC_PG_REG to 0 (from 0xF)
devmem 0x050260E4 32 0x1 # set RTC_EN_SUSPEND_REQ to 1
devmem 0x05025004 32 0xAB18 # UNLOCK WRITING TO RTC_CTRL0
devmem 0x05025008 32 0x8C0 # set RTC_CTRL0, so that req_suspend = 1
Problem is in the 1st statement seems to FAIL (vs 3 others). Maybe a HW bug or bad documentation or I should do that from RTC domain (8051). Will try again …

3 Likes

I am very interested in this as well. Suspend/resume looks to be supported according to the datasheet:

I suspect you’d need to send the signal from the 8051 core and maybe a heads up to linux kernel that system is about to go down?

I’ve never worked with the 8051 or any embedded stuff really but I have devmem and sdcc set up. I’ll try writing a program to load into 8051 sram that sleeps the main core for a few seconds and then wakes it.

I’d be happy to work with someone over IRC/Matrix figuring out how to implement this.

1 Like

Any progress?

I’ve been playing around with some of the registers for shutdown/reboot/suspend. RTC_CTRL0 is set to 0xAB18, can’t seem to trigger any of the desired outcomes.

devmem 0x05025008 32 0x8C0

How did you arrive at the value 0x8C0?

2 Likes

It looks like that procfs entry is generated by the kernel module cv181x_base.ko. In the Buildroot repo, that is a binary middleware/v2/cv181x/ko/cv181x_base.ko, not a source file unfortunately.

1 Like

Linux suspend-to-RAM is working on the MilkV Duo with CV1800B. It is not working with the MilkV Duo S SG2000. On Duo, suspend and resume are working, with normal idle around .08A and suspend-to-RAM at .013A. SG2000 should be similar.

Suspending the Duo with CV1800B:

[root@milkv-duo]~# insmod /mnt/system/ko/cv180x_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
# Resumes in 30 seconds

Most of the sleep implementation is shared between the two chips, only differing by a few addresses. I have opened an issue on their Github: Duo S: Suspend-to-RAM failure · Issue #18 · milkv-duo/duo-buildroot-sdk-v2 · GitHub

Building SG2000 Duo S image with suspend enabled:

Add to build/boards/cv181x/sg2000_milkv_duos_musl_riscv64_sd/sg2000_milkv_duos_musl_riscv64_sd_defconfig:

CONFIG_KERNEL_SUSPEND=y

Add to build/boards/cv181x/sg2000_milkv_duos_musl_riscv64_sd/linux/cvitek_sg2000_milkv_duos_musl_riscv64_sd_defconfig:

CONFIG_SUSPEND=y
CONFIG_SUSPEND_FREEZER=y
CONFIG_PM_SLEEP=y

This will update the kernel defconfig linux_5.10/build/sg2000_milkv_duos_musl_riscv64_sd/.config.

Build the image:

./build.sh milkv-duos-musl-riscv64-sd

On-device:

[root@milkv-duo]~# insmod /mnt/system/ko/cv181x_rtc.ko
[root@milkv-duo]~# hwclock -w
[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

The shared suspend implementation is at opensbi/platform/generic/cvitek_riscv.c. It sets sleep / resume settings, then loads a prebuilt binary into SRAM and jumps to it to perform the actual suspend. The binary is platform-specific. CV1800B uses opensbi/pm_default_cv180x.bin and SG2000 uses opensbi/pm_default_cv181x.bin. Its contents can be examined after building using /opt/toolchain/Xuantie-900-gcc-linux-6.6.0-glibc-x86_64-V2.10.1/bin/riscv64-unknown-linux-gnu-objdump -D opensbi/build/platform/generic/cvitek_riscv.o.

2 Likes

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

[  143.639888] dwc2 4340000.usb: dwc2_hsotg_ep_disable: called for ep0
[  143.655662] dwc2 4340000.usb: dwc2_hsotg_ep_disable: called for ep0
[  143.667863] dwa_suspend:571(): dwa thread stopped
[  143.679669] dwa_suspend:578(): dwa suspended!
[  143.687672] base_mod_jobs_exit:326(): mod(VO) job exit fail, not inited yet
[  143.703745] vpss_suspend:5615(): vpss suspended
... Suspended
[  143.719712] vpss_resume:5632(): vpss resumed
[  143.743370] dwa_resume:597(): gdc thread restarted
[  143.748434] dwa_resume:604(): dwa resume!

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
2 Likes