pmu.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * pmu.c, Power Management Unit routines for NEC VR4100 series.
  3. *
  4. * Copyright (C) 2003-2007 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/ioport.h>
  23. #include <linux/kernel.h>
  24. #include <linux/pm.h>
  25. #include <linux/sched.h>
  26. #include <linux/types.h>
  27. #include <asm/cacheflush.h>
  28. #include <asm/cpu.h>
  29. #include <asm/idle.h>
  30. #include <asm/io.h>
  31. #include <asm/processor.h>
  32. #include <asm/reboot.h>
  33. #define PMU_TYPE1_BASE 0x0b0000a0UL
  34. #define PMU_TYPE1_SIZE 0x0eUL
  35. #define PMU_TYPE2_BASE 0x0f0000c0UL
  36. #define PMU_TYPE2_SIZE 0x10UL
  37. #define PMUCNT2REG 0x06
  38. #define SOFTRST 0x0010
  39. static void __iomem *pmu_base;
  40. #define pmu_read(offset) readw(pmu_base + (offset))
  41. #define pmu_write(offset, value) writew((value), pmu_base + (offset))
  42. static void vr41xx_cpu_wait(void)
  43. {
  44. local_irq_disable();
  45. if (!need_resched())
  46. /*
  47. * "standby" sets IE bit of the CP0_STATUS to 1.
  48. */
  49. __asm__("standby;\n");
  50. else
  51. local_irq_enable();
  52. }
  53. static inline void software_reset(void)
  54. {
  55. uint16_t pmucnt2;
  56. switch (current_cpu_type()) {
  57. case CPU_VR4122:
  58. case CPU_VR4131:
  59. case CPU_VR4133:
  60. pmucnt2 = pmu_read(PMUCNT2REG);
  61. pmucnt2 |= SOFTRST;
  62. pmu_write(PMUCNT2REG, pmucnt2);
  63. break;
  64. default:
  65. set_c0_status(ST0_BEV | ST0_ERL);
  66. change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
  67. __flush_cache_all();
  68. write_c0_wired(0);
  69. __asm__("jr %0"::"r"(0xbfc00000));
  70. break;
  71. }
  72. }
  73. static void vr41xx_restart(char *command)
  74. {
  75. local_irq_disable();
  76. software_reset();
  77. while (1) ;
  78. }
  79. static void vr41xx_halt(void)
  80. {
  81. local_irq_disable();
  82. printk(KERN_NOTICE "\nYou can turn off the power supply\n");
  83. __asm__("hibernate;\n");
  84. }
  85. static int __init vr41xx_pmu_init(void)
  86. {
  87. unsigned long start, size;
  88. switch (current_cpu_type()) {
  89. case CPU_VR4111:
  90. case CPU_VR4121:
  91. start = PMU_TYPE1_BASE;
  92. size = PMU_TYPE1_SIZE;
  93. break;
  94. case CPU_VR4122:
  95. case CPU_VR4131:
  96. case CPU_VR4133:
  97. start = PMU_TYPE2_BASE;
  98. size = PMU_TYPE2_SIZE;
  99. break;
  100. default:
  101. printk("Unexpected CPU of NEC VR4100 series\n");
  102. return -ENODEV;
  103. }
  104. if (request_mem_region(start, size, "PMU") == NULL)
  105. return -EBUSY;
  106. pmu_base = ioremap(start, size);
  107. if (pmu_base == NULL) {
  108. release_mem_region(start, size);
  109. return -EBUSY;
  110. }
  111. cpu_wait = vr41xx_cpu_wait;
  112. _machine_restart = vr41xx_restart;
  113. _machine_halt = vr41xx_halt;
  114. pm_power_off = vr41xx_halt;
  115. return 0;
  116. }
  117. core_initcall(vr41xx_pmu_init);