reset.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /*
  54. * It needs a wait loop here, but mips/kernel/reset.c already calls
  55. * a generic delay loop, machine_hang(), so simply return.
  56. */
  57. return;
  58. #else
  59. void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
  60. fw_poweroff();
  61. while (1) {
  62. if (cpu_wait)
  63. cpu_wait();
  64. }
  65. #endif
  66. }
  67. static void loongson_halt(void)
  68. {
  69. pr_notice("\n\n** You can safely turn off the power now **\n\n");
  70. while (1) {
  71. if (cpu_wait)
  72. cpu_wait();
  73. }
  74. }
  75. static int __init mips_reboot_setup(void)
  76. {
  77. _machine_restart = loongson_restart;
  78. _machine_halt = loongson_halt;
  79. pm_power_off = loongson_poweroff;
  80. return 0;
  81. }
  82. arch_initcall(mips_reboot_setup);