pm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * hp6x0 Power Management Routines
  3. *
  4. * Copyright (c) 2006 Andriy Skulysh <askulsyh@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/suspend.h>
  11. #include <linux/errno.h>
  12. #include <linux/time.h>
  13. #include <linux/delay.h>
  14. #include <linux/gfp.h>
  15. #include <asm/io.h>
  16. #include <asm/hd64461.h>
  17. #include <asm/bl_bit.h>
  18. #include <mach/hp6xx.h>
  19. #include <cpu/dac.h>
  20. #include <asm/freq.h>
  21. #include <asm/watchdog.h>
  22. #define INTR_OFFSET 0x600
  23. #define STBCR 0xffffff82
  24. #define STBCR2 0xffffff88
  25. #define STBCR_STBY 0x80
  26. #define STBCR_MSTP2 0x04
  27. #define MCR 0xffffff68
  28. #define RTCNT 0xffffff70
  29. #define MCR_RMODE 2
  30. #define MCR_RFSH 4
  31. extern u8 wakeup_start;
  32. extern u8 wakeup_end;
  33. static void pm_enter(void)
  34. {
  35. u8 stbcr, csr;
  36. u16 frqcr, mcr;
  37. u32 vbr_new, vbr_old;
  38. set_bl_bit();
  39. /* set wdt */
  40. csr = sh_wdt_read_csr();
  41. csr &= ~WTCSR_TME;
  42. csr |= WTCSR_CKS_4096;
  43. sh_wdt_write_csr(csr);
  44. csr = sh_wdt_read_csr();
  45. sh_wdt_write_cnt(0);
  46. /* disable PLL1 */
  47. frqcr = __raw_readw(FRQCR);
  48. frqcr &= ~(FRQCR_PLLEN | FRQCR_PSTBY);
  49. __raw_writew(frqcr, FRQCR);
  50. /* enable standby */
  51. stbcr = __raw_readb(STBCR);
  52. __raw_writeb(stbcr | STBCR_STBY | STBCR_MSTP2, STBCR);
  53. /* set self-refresh */
  54. mcr = __raw_readw(MCR);
  55. __raw_writew(mcr & ~MCR_RFSH, MCR);
  56. /* set interrupt handler */
  57. asm volatile("stc vbr, %0" : "=r" (vbr_old));
  58. vbr_new = get_zeroed_page(GFP_ATOMIC);
  59. udelay(50);
  60. memcpy((void*)(vbr_new + INTR_OFFSET),
  61. &wakeup_start, &wakeup_end - &wakeup_start);
  62. asm volatile("ldc %0, vbr" : : "r" (vbr_new));
  63. __raw_writew(0, RTCNT);
  64. __raw_writew(mcr | MCR_RFSH | MCR_RMODE, MCR);
  65. cpu_sleep();
  66. asm volatile("ldc %0, vbr" : : "r" (vbr_old));
  67. free_page(vbr_new);
  68. /* enable PLL1 */
  69. frqcr = __raw_readw(FRQCR);
  70. frqcr |= FRQCR_PSTBY;
  71. __raw_writew(frqcr, FRQCR);
  72. udelay(50);
  73. frqcr |= FRQCR_PLLEN;
  74. __raw_writew(frqcr, FRQCR);
  75. __raw_writeb(stbcr, STBCR);
  76. clear_bl_bit();
  77. }
  78. static int hp6x0_pm_enter(suspend_state_t state)
  79. {
  80. u8 stbcr, stbcr2;
  81. #ifdef CONFIG_HD64461_ENABLER
  82. u8 scr;
  83. u16 hd64461_stbcr;
  84. #endif
  85. #ifdef CONFIG_HD64461_ENABLER
  86. outb(0, HD64461_PCC1CSCIER);
  87. scr = inb(HD64461_PCC1SCR);
  88. scr |= HD64461_PCCSCR_VCC1;
  89. outb(scr, HD64461_PCC1SCR);
  90. hd64461_stbcr = inw(HD64461_STBCR);
  91. hd64461_stbcr |= HD64461_STBCR_SPC1ST;
  92. outw(hd64461_stbcr, HD64461_STBCR);
  93. #endif
  94. __raw_writeb(0x1f, DACR);
  95. stbcr = __raw_readb(STBCR);
  96. __raw_writeb(0x01, STBCR);
  97. stbcr2 = __raw_readb(STBCR2);
  98. __raw_writeb(0x7f , STBCR2);
  99. outw(0xf07f, HD64461_SCPUCR);
  100. pm_enter();
  101. outw(0, HD64461_SCPUCR);
  102. __raw_writeb(stbcr, STBCR);
  103. __raw_writeb(stbcr2, STBCR2);
  104. #ifdef CONFIG_HD64461_ENABLER
  105. hd64461_stbcr = inw(HD64461_STBCR);
  106. hd64461_stbcr &= ~HD64461_STBCR_SPC1ST;
  107. outw(hd64461_stbcr, HD64461_STBCR);
  108. outb(0x4c, HD64461_PCC1CSCIER);
  109. outb(0x00, HD64461_PCC1CSCR);
  110. #endif
  111. return 0;
  112. }
  113. static const struct platform_suspend_ops hp6x0_pm_ops = {
  114. .enter = hp6x0_pm_enter,
  115. .valid = suspend_valid_only_mem,
  116. };
  117. static int __init hp6x0_pm_init(void)
  118. {
  119. suspend_set_ops(&hp6x0_pm_ops);
  120. return 0;
  121. }
  122. late_initcall(hp6x0_pm_init);