reset.c 927 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2011 Zhang, Keguang <[email protected]>
  4. */
  5. #include <linux/io.h>
  6. #include <linux/pm.h>
  7. #include <linux/sizes.h>
  8. #include <asm/idle.h>
  9. #include <asm/reboot.h>
  10. #include <loongson1.h>
  11. static void __iomem *wdt_reg_base;
  12. static void ls1x_halt(void)
  13. {
  14. while (1) {
  15. if (cpu_wait)
  16. cpu_wait();
  17. }
  18. }
  19. static void ls1x_restart(char *command)
  20. {
  21. __raw_writel(0x1, wdt_reg_base + WDT_EN);
  22. __raw_writel(0x1, wdt_reg_base + WDT_TIMER);
  23. __raw_writel(0x1, wdt_reg_base + WDT_SET);
  24. ls1x_halt();
  25. }
  26. static void ls1x_power_off(void)
  27. {
  28. ls1x_halt();
  29. }
  30. static int __init ls1x_reboot_setup(void)
  31. {
  32. wdt_reg_base = ioremap(LS1X_WDT_BASE, (SZ_4 + SZ_8));
  33. if (!wdt_reg_base)
  34. panic("Failed to remap watchdog registers");
  35. _machine_restart = ls1x_restart;
  36. _machine_halt = ls1x_halt;
  37. pm_power_off = ls1x_power_off;
  38. return 0;
  39. }
  40. arch_initcall(ls1x_reboot_setup);