reset.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Board-specific reboot/shutdown routines
  2. *
  3. * Copyright (c) 2009 Philippe Vachon <philippe@cowpig.ca>
  4. *
  5. * Copyright (C) 2009 Lemote Inc.
  6. * Author: Wu Zhangjin, wuzhangjin@gmail.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/io.h>
  14. #include <linux/delay.h>
  15. #include <linux/types.h>
  16. #include <asm/bootinfo.h>
  17. #include <loongson.h>
  18. #include <cs5536/cs5536.h>
  19. #include "ec_kb3310b.h"
  20. static void reset_cpu(void)
  21. {
  22. /*
  23. * reset cpu to full speed, this is needed when enabling cpu frequency
  24. * scalling
  25. */
  26. LOONGSON_CHIPCFG(0) |= 0x7;
  27. }
  28. /* reset support for fuloong2f */
  29. static void fl2f_reboot(void)
  30. {
  31. reset_cpu();
  32. /* send a reset signal to south bridge.
  33. *
  34. * NOTE: if enable "Power Management" in kernel, rtl8169 will not reset
  35. * normally with this reset operation and it will not work in PMON, but
  36. * you can type halt command and then reboot, seems the hardware reset
  37. * logic not work normally.
  38. */
  39. {
  40. u32 hi, lo;
  41. _rdmsr(DIVIL_MSR_REG(DIVIL_SOFT_RESET), &hi, &lo);
  42. lo |= 0x00000001;
  43. _wrmsr(DIVIL_MSR_REG(DIVIL_SOFT_RESET), hi, lo);
  44. }
  45. }
  46. static void fl2f_shutdown(void)
  47. {
  48. u32 hi, lo, val;
  49. int gpio_base;
  50. /* get gpio base */
  51. _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &lo);
  52. gpio_base = lo & 0xff00;
  53. /* make cs5536 gpio13 output enable */
  54. val = inl(gpio_base + GPIOL_OUT_EN);
  55. val &= ~(1 << (16 + 13));
  56. val |= (1 << 13);
  57. outl(val, gpio_base + GPIOL_OUT_EN);
  58. mmiowb();
  59. /* make cs5536 gpio13 output low level voltage. */
  60. val = inl(gpio_base + GPIOL_OUT_VAL) & ~(1 << (13));
  61. val |= (1 << (16 + 13));
  62. outl(val, gpio_base + GPIOL_OUT_VAL);
  63. mmiowb();
  64. }
  65. /* reset support for yeeloong2f and mengloong2f notebook */
  66. static void ml2f_reboot(void)
  67. {
  68. reset_cpu();
  69. /* sending an reset signal to EC(embedded controller) */
  70. ec_write(REG_RESET, BIT_RESET_ON);
  71. }
  72. #define yl2f89_reboot ml2f_reboot
  73. /* menglong(7inches) laptop has different shutdown logic from 8.9inches */
  74. #define EC_SHUTDOWN_IO_PORT_HIGH 0xff2d
  75. #define EC_SHUTDOWN_IO_PORT_LOW 0xff2e
  76. #define EC_SHUTDOWN_IO_PORT_DATA 0xff2f
  77. #define REG_SHUTDOWN_HIGH 0xFC
  78. #define REG_SHUTDOWN_LOW 0x29
  79. #define BIT_SHUTDOWN_ON (1 << 1)
  80. static void ml2f_shutdown(void)
  81. {
  82. u8 val;
  83. u64 i;
  84. outb(REG_SHUTDOWN_HIGH, EC_SHUTDOWN_IO_PORT_HIGH);
  85. outb(REG_SHUTDOWN_LOW, EC_SHUTDOWN_IO_PORT_LOW);
  86. mmiowb();
  87. val = inb(EC_SHUTDOWN_IO_PORT_DATA);
  88. outb(val & (~BIT_SHUTDOWN_ON), EC_SHUTDOWN_IO_PORT_DATA);
  89. mmiowb();
  90. /* need enough wait here... how many microseconds needs? */
  91. for (i = 0; i < 0x10000; i++)
  92. delay();
  93. outb(val | BIT_SHUTDOWN_ON, EC_SHUTDOWN_IO_PORT_DATA);
  94. mmiowb();
  95. }
  96. static void yl2f89_shutdown(void)
  97. {
  98. /* cpu-gpio0 output low */
  99. LOONGSON_GPIODATA &= ~0x00000001;
  100. /* cpu-gpio0 as output */
  101. LOONGSON_GPIOIE &= ~0x00000001;
  102. }
  103. void mach_prepare_reboot(void)
  104. {
  105. switch (mips_machtype) {
  106. case MACH_LEMOTE_FL2F:
  107. case MACH_LEMOTE_NAS:
  108. case MACH_LEMOTE_LL2F:
  109. fl2f_reboot();
  110. break;
  111. case MACH_LEMOTE_ML2F7:
  112. ml2f_reboot();
  113. break;
  114. case MACH_LEMOTE_YL2F89:
  115. yl2f89_reboot();
  116. break;
  117. default:
  118. break;
  119. }
  120. }
  121. void mach_prepare_shutdown(void)
  122. {
  123. switch (mips_machtype) {
  124. case MACH_LEMOTE_FL2F:
  125. case MACH_LEMOTE_NAS:
  126. case MACH_LEMOTE_LL2F:
  127. fl2f_shutdown();
  128. break;
  129. case MACH_LEMOTE_ML2F7:
  130. ml2f_shutdown();
  131. break;
  132. case MACH_LEMOTE_YL2F89:
  133. yl2f89_shutdown();
  134. break;
  135. default:
  136. break;
  137. }
  138. }