reset.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/idle.h>
  15. #include <asm/reboot.h>
  16. #include <loongson.h>
  17. #include <boot_param.h>
  18. static inline void loongson_reboot(void)
  19. {
  20. #ifndef CONFIG_CPU_JUMP_WORKAROUNDS
  21. ((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
  22. #else
  23. void (*func)(void);
  24. func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4);
  25. __asm__ __volatile__(
  26. " .set noat \n"
  27. " jr %[func] \n"
  28. " .set at \n"
  29. : /* No outputs */
  30. : [func] "r" (func));
  31. #endif
  32. }
  33. static void loongson_restart(char *command)
  34. {
  35. #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
  36. /* do preparation for reboot */
  37. mach_prepare_reboot();
  38. /* reboot via jumping to boot base address */
  39. loongson_reboot();
  40. #else
  41. void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
  42. fw_restart();
  43. while (1) {
  44. if (cpu_wait)
  45. cpu_wait();
  46. }
  47. #endif
  48. }
  49. static void loongson_poweroff(void)
  50. {
  51. #ifndef CONFIG_LEFI_FIRMWARE_INTERFACE
  52. mach_prepare_shutdown();
  53. unreachable();
  54. #else
  55. void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
  56. fw_poweroff();
  57. while (1) {
  58. if (cpu_wait)
  59. cpu_wait();
  60. }
  61. #endif
  62. }
  63. static void loongson_halt(void)
  64. {
  65. pr_notice("\n\n** You can safely turn off the power now **\n\n");
  66. while (1) {
  67. if (cpu_wait)
  68. cpu_wait();
  69. }
  70. }
  71. static int __init mips_reboot_setup(void)
  72. {
  73. _machine_restart = loongson_restart;
  74. _machine_halt = loongson_halt;
  75. pm_power_off = loongson_poweroff;
  76. return 0;
  77. }
  78. arch_initcall(mips_reboot_setup);