reset.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
  8. * Author: Fuxin Zhang, zhangfx@lemote.com
  9. * Copyright (C) 2009 Lemote, Inc.
  10. * Author: Zhangjin Wu, wuzhangjin@gmail.com
  11. */
  12. #include <linux/init.h>
  13. #include <linux/pm.h>
  14. #include <asm/reboot.h>
  15. #include <loongson.h>
  16. static inline void loongson_reboot(void)
  17. {
  18. #ifndef CONFIG_CPU_JUMP_WORKAROUNDS
  19. ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
  20. #else
  21. void (*func)(void);
  22. func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4);
  23. __asm__ __volatile__(
  24. " .set noat \n"
  25. " jr %[func] \n"
  26. " .set at \n"
  27. : /* No outputs */
  28. : [func] "r" (func));
  29. #endif
  30. }
  31. static void loongson_restart(char *command)
  32. {
  33. /* do preparation for reboot */
  34. mach_prepare_reboot();
  35. /* reboot via jumping to boot base address */
  36. loongson_reboot();
  37. }
  38. static void loongson_poweroff(void)
  39. {
  40. mach_prepare_shutdown();
  41. unreachable();
  42. }
  43. static void loongson_halt(void)
  44. {
  45. pr_notice("\n\n** You can safely turn off the power now **\n\n");
  46. while (1) {
  47. if (cpu_wait)
  48. cpu_wait();
  49. }
  50. }
  51. static int __init mips_reboot_setup(void)
  52. {
  53. _machine_restart = loongson_restart;
  54. _machine_halt = loongson_halt;
  55. pm_power_off = loongson_poweroff;
  56. return 0;
  57. }
  58. arch_initcall(mips_reboot_setup);