reset.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, wuzj@lemote.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. static void reset_cpu(void)
  20. {
  21. /*
  22. * reset cpu to full speed, this is needed when enabling cpu frequency
  23. * scalling
  24. */
  25. LOONGSON_CHIPCFG0 |= 0x7;
  26. }
  27. /* reset support for fuloong2f */
  28. static void fl2f_reboot(void)
  29. {
  30. reset_cpu();
  31. /* send a reset signal to south bridge.
  32. *
  33. * NOTE: if enable "Power Management" in kernel, rtl8169 will not reset
  34. * normally with this reset operation and it will not work in PMON, but
  35. * you can type halt command and then reboot, seems the hardware reset
  36. * logic not work normally.
  37. */
  38. {
  39. u32 hi, lo;
  40. _rdmsr(DIVIL_MSR_REG(DIVIL_SOFT_RESET), &hi, &lo);
  41. lo |= 0x00000001;
  42. _wrmsr(DIVIL_MSR_REG(DIVIL_SOFT_RESET), hi, lo);
  43. }
  44. }
  45. static void fl2f_shutdown(void)
  46. {
  47. u32 hi, lo, val;
  48. int gpio_base;
  49. /* get gpio base */
  50. _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &lo);
  51. gpio_base = lo & 0xff00;
  52. /* make cs5536 gpio13 output enable */
  53. val = inl(gpio_base + GPIOL_OUT_EN);
  54. val &= ~(1 << (16 + 13));
  55. val |= (1 << 13);
  56. outl(val, gpio_base + GPIOL_OUT_EN);
  57. mmiowb();
  58. /* make cs5536 gpio13 output low level voltage. */
  59. val = inl(gpio_base + GPIOL_OUT_VAL) & ~(1 << (13));
  60. val |= (1 << (16 + 13));
  61. outl(val, gpio_base + GPIOL_OUT_VAL);
  62. mmiowb();
  63. }
  64. /* reset support for yeeloong2f and mengloong2f notebook */
  65. /*
  66. * The following registers are determined by the EC index configuration.
  67. * 1. fill the PORT_HIGH as EC register high part.
  68. * 2. fill the PORT_LOW as EC register low part.
  69. * 3. fill the PORT_DATA as EC register write data or get the data from it.
  70. */
  71. #define EC_IO_PORT_HIGH 0x0381
  72. #define EC_IO_PORT_LOW 0x0382
  73. #define EC_IO_PORT_DATA 0x0383
  74. #define REG_RESET_HIGH 0xF4 /* reset the machine auto-clear : rd/wr */
  75. #define REG_RESET_LOW 0xEC
  76. #define BIT_RESET_ON (1 << 0)
  77. void ml2f_reboot(void)
  78. {
  79. reset_cpu();
  80. /* sending an reset signal to EC(embedded controller) */
  81. outb(REG_RESET_HIGH, EC_IO_PORT_HIGH);
  82. outb(REG_RESET_LOW, EC_IO_PORT_LOW);
  83. mmiowb();
  84. outb(BIT_RESET_ON, EC_IO_PORT_DATA);
  85. mmiowb();
  86. }
  87. #define yl2f89_reboot ml2f_reboot
  88. /* menglong(7inches) laptop has different shutdown logic from 8.9inches */
  89. #define EC_SHUTDOWN_IO_PORT_HIGH 0xff2d
  90. #define EC_SHUTDOWN_IO_PORT_LOW 0xff2e
  91. #define EC_SHUTDOWN_IO_PORT_DATA 0xff2f
  92. #define REG_SHUTDOWN_HIGH 0xFC
  93. #define REG_SHUTDOWN_LOW 0x29
  94. #define BIT_SHUTDOWN_ON (1 << 1)
  95. static void ml2f_shutdown(void)
  96. {
  97. u8 val;
  98. u64 i;
  99. outb(REG_SHUTDOWN_HIGH, EC_SHUTDOWN_IO_PORT_HIGH);
  100. outb(REG_SHUTDOWN_LOW, EC_SHUTDOWN_IO_PORT_LOW);
  101. mmiowb();
  102. val = inb(EC_SHUTDOWN_IO_PORT_DATA);
  103. outb(val & (~BIT_SHUTDOWN_ON), EC_SHUTDOWN_IO_PORT_DATA);
  104. mmiowb();
  105. /* need enough wait here... how many microseconds needs? */
  106. for (i = 0; i < 0x10000; i++)
  107. delay();
  108. outb(val | BIT_SHUTDOWN_ON, EC_SHUTDOWN_IO_PORT_DATA);
  109. mmiowb();
  110. }
  111. static void yl2f89_shutdown(void)
  112. {
  113. /* cpu-gpio0 output low */
  114. LOONGSON_GPIODATA &= ~0x00000001;
  115. /* cpu-gpio0 as output */
  116. LOONGSON_GPIOIE &= ~0x00000001;
  117. }
  118. void mach_prepare_reboot(void)
  119. {
  120. switch (mips_machtype) {
  121. case MACH_LEMOTE_FL2F:
  122. fl2f_reboot();
  123. break;
  124. case MACH_LEMOTE_ML2F7:
  125. ml2f_reboot();
  126. break;
  127. case MACH_LEMOTE_YL2F89:
  128. yl2f89_reboot();
  129. break;
  130. default:
  131. break;
  132. }
  133. }
  134. void mach_prepare_shutdown(void)
  135. {
  136. switch (mips_machtype) {
  137. case MACH_LEMOTE_FL2F:
  138. fl2f_shutdown();
  139. break;
  140. case MACH_LEMOTE_ML2F7:
  141. ml2f_shutdown();
  142. break;
  143. case MACH_LEMOTE_YL2F89:
  144. yl2f89_shutdown();
  145. break;
  146. default:
  147. break;
  148. }
  149. }