PabloPL / linux

Linux kernel source tree
Other
17 stars 0 forks source link

Shutdown/restart support #10

Closed PabloPL closed 5 years ago

xc-racer99 commented 6 years ago

I was thinking something like

diff --git a/arch/arm/boot/dts/s5pv210-aries.dtsi b/arch/arm/boot/dts/s5pv210-aries.dtsi
index 1a8ccd86c893..213d5baf2b90 100644
--- a/arch/arm/boot/dts/s5pv210-aries.dtsi
+++ b/arch/arm/boot/dts/s5pv210-aries.dtsi
@@ -415,3 +415,25 @@
 &pwm {
        samsung,pwm-outputs = <1>;
 };
+
+&pmu_syscon {
+       compatible = "samsung-s5pv210-pmu", "simple-mfd", "syscon";
+
+       /* Write magic to INFORM5 to prevent charger on reboot */
+       reboot-mode {
+               compatible = "syscon-reboot-mode";
+               offset = <0x7014 /* INFORM5 */>;
+               mode-normal = <0x12345678>;
+               mode-recovery = <0x12345678>;
+               mode-bootloader = <0x12345678>;
+       };
+
+       /* Writes actual reboot code to INFORM6 */
+       reboot-mode {
+               compatible = "syscon-reboot-mode";
+               offset = <0x7018 /* INFORM6 */>;
+               mode-normal = <0x0>;
+               mode-recovery = <0x2>;
+               mode-bootloader = <0x4>;
+       };
+};

for the reboot mode notifier (don't know if you can stack up the reboot modes or not... this is totally untested)

xc-racer99 commented 6 years ago

Rebooting functions by using https://github.com/xc-racer99/linux/commit/e94d34cfff38ba4f42db7f2a20eaf49e38da4ad9

Still struggling with syscon-reboot-mode and syscon-poweroff to get parameters written to the INFORM registers/regular shutdown

xc-racer99 commented 6 years ago

https://github.com/xc-racer99/linux/commit/b245a366cbf101e073a47314f9eb3e220ca29284 is functional for syscon poweroff support. Needs the following added to the defconfig

CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON_POWEROFF=y

I cannot seem to get syscon-reboot-mode to even probe, so I can't test if my code above works (yes, I have modified the defconfig for it)

PabloPL commented 5 years ago

About syscon poweroff, i've applied it to for-upstream/aries-patches-v2 branch and when invoking shutdown, device is still showing logs on screen (last entry is "reboot: System halted"). Shouldn't power be turned off?

xc-racer99 commented 5 years ago

Umm, what command are you using to shutdown? Running "shutdown now" on Debian gives the following

[  OK  ] Reached target Shutdown.
systemd-shutdow: 19 output lines suppressed due to ratelimiting
systemd-shutdown[1]: Sending SIGTERM to remaining processes...
systemd-journald[1179]: Received SIGTERM from PID 1 (systemd-shutdow).
systemd-shutdown[1]: Sending SIGKILL to remaining processes...
systemd-shutdown[1]: Unmounting file systems.
systemd-shutdown[1]: Remounting '/' read-only with options ''.
EXT4-fs (mmcblk1p1): re-mounted. Opts: 
systemd-shutdown[1]: Remounting '/' read-only with options ''.
EXT4-fs (mmcblk1p1): re-mounted. Opts: 
systemd-shutdown[1]: All filesystems unmounted.
systemd-shutdown[1]: Deactivating swaps.
systemd-shutdown[1]: All swaps deactivated.
systemd-shutdown[1]: Detaching loop devices.
systemd-shutdown[1]: All loop devices detached.
rebo

when building from the for-upstream/aries-patches-v2 branch

PabloPL commented 5 years ago

By just running shutdown. I can see in log message that board is halted, but screen is still working.

xc-racer99 commented 5 years ago

Weird. Does just pushing the power button turn it on again?

Vendor kernel read from PS_HOLD_CONTROL and then writes it back, see https://github.com/xc-racer99/android_kernel_samsung_aries/blob/aosp-7.1/arch/arm/mach-s5pv210/mach-aries.c#L4326

For my variant, reading from PS_HOLD_CONTROL gave a value of 0x5301, but I used 0x5200 as that is what is in arch/arm/boot/dts/exynos-syscon-restart.dtsi - using the value of 0x5301 didn't work as the syscon driver won't write something to the register if it's already there.

You can play around with different values in u-boot using the command

mw.b 0xe010e81c 0x5301 1
PabloPL commented 5 years ago

Without cable attached it's working fine (device/screen is powered off and booted by pressing button again after shutdown. Maybe it's related to unbrickable mod? Sorry for problems.

xc-racer99 commented 5 years ago

syscon poweroff was merged as part of Aries v2 patches; we still need to figure out why the S5P_SW_RESET doesn't work or else make adjusts to the watchdog driver so we can use it to reset as in the vendor kernel (and ported upstream in https://github.com/xc-racer99/linux/commit/e94d34cfff38ba4f42db7f2a20eaf49e38da4ad9)

xc-racer99 commented 5 years ago

It should be noted that when using the SD card SPL in u-boot, then S5P_SW_RESET works as one would expect.

xc-racer99 commented 5 years ago

I think we can close this, the reason that the SW_RESET doesn't work is due to a mistake in the stock bootloader. For some reason it assumes that the memory will already be setup, while in fact it isn't.

PabloPL commented 5 years ago

No dts changes needed? Till now only poweroff was merged.

xc-racer99 commented 5 years ago

Yep, no DTS changes needed, it works as expected when using the WIP SPL branch of u-boot.

The SW_RESET hook is hard-coded in the s5pv210 common support at https://github.com/PabloPL/linux/blob/master/arch/arm/mach-s5pv210/s5pv210.c#L71

I suppose we could set the reboot-mode entries for configuring the bootloader, but there's no standard about this. We could either match the stock bootloader or else the midas config.