reset.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * You should have received a copy of the GNU General Public License along
  10. * with this program; if not, write to the Free Software Foundation, Inc.,
  11. * 675 Mass Ave, Cambridge, MA 02139, USA.
  12. *
  13. */
  14. #include <linux/io.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pm.h>
  17. #include <asm/reboot.h>
  18. #include <asm/mach-jz4740/base.h>
  19. #include <asm/mach-jz4740/timer.h>
  20. #include "reset.h"
  21. #include "clock.h"
  22. static void jz4740_halt(void)
  23. {
  24. while (1) {
  25. __asm__(".set push;\n"
  26. ".set mips3;\n"
  27. "wait;\n"
  28. ".set pop;\n"
  29. );
  30. }
  31. }
  32. #define JZ_REG_WDT_DATA 0x00
  33. #define JZ_REG_WDT_COUNTER_ENABLE 0x04
  34. #define JZ_REG_WDT_COUNTER 0x08
  35. #define JZ_REG_WDT_CTRL 0x0c
  36. static void jz4740_restart(char *command)
  37. {
  38. void __iomem *wdt_base = ioremap(JZ4740_WDT_BASE_ADDR, 0x0f);
  39. jz4740_timer_enable_watchdog();
  40. writeb(0, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
  41. writew(0, wdt_base + JZ_REG_WDT_COUNTER);
  42. writew(0, wdt_base + JZ_REG_WDT_DATA);
  43. writew(BIT(2), wdt_base + JZ_REG_WDT_CTRL);
  44. writeb(1, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
  45. jz4740_halt();
  46. }
  47. #define JZ_REG_RTC_CTRL 0x00
  48. #define JZ_REG_RTC_HIBERNATE 0x20
  49. #define JZ_REG_RTC_WAKEUP_FILTER 0x24
  50. #define JZ_REG_RTC_RESET_COUNTER 0x28
  51. #define JZ_RTC_CTRL_WRDY BIT(7)
  52. #define JZ_RTC_WAKEUP_FILTER_MASK 0x0000FFE0
  53. #define JZ_RTC_RESET_COUNTER_MASK 0x00000FE0
  54. static inline void jz4740_rtc_wait_ready(void __iomem *rtc_base)
  55. {
  56. uint32_t ctrl;
  57. do {
  58. ctrl = readl(rtc_base + JZ_REG_RTC_CTRL);
  59. } while (!(ctrl & JZ_RTC_CTRL_WRDY));
  60. }
  61. static void jz4740_power_off(void)
  62. {
  63. void __iomem *rtc_base = ioremap(JZ4740_RTC_BASE_ADDR, 0x38);
  64. unsigned long wakeup_filter_ticks;
  65. unsigned long reset_counter_ticks;
  66. /*
  67. * Set minimum wakeup pin assertion time: 100 ms.
  68. * Range is 0 to 2 sec if RTC is clocked at 32 kHz.
  69. */
  70. wakeup_filter_ticks = (100 * jz4740_clock_bdata.rtc_rate) / 1000;
  71. if (wakeup_filter_ticks < JZ_RTC_WAKEUP_FILTER_MASK)
  72. wakeup_filter_ticks &= JZ_RTC_WAKEUP_FILTER_MASK;
  73. else
  74. wakeup_filter_ticks = JZ_RTC_WAKEUP_FILTER_MASK;
  75. jz4740_rtc_wait_ready(rtc_base);
  76. writel(wakeup_filter_ticks, rtc_base + JZ_REG_RTC_WAKEUP_FILTER);
  77. /*
  78. * Set reset pin low-level assertion time after wakeup: 60 ms.
  79. * Range is 0 to 125 ms if RTC is clocked at 32 kHz.
  80. */
  81. reset_counter_ticks = (60 * jz4740_clock_bdata.rtc_rate) / 1000;
  82. if (reset_counter_ticks < JZ_RTC_RESET_COUNTER_MASK)
  83. reset_counter_ticks &= JZ_RTC_RESET_COUNTER_MASK;
  84. else
  85. reset_counter_ticks = JZ_RTC_RESET_COUNTER_MASK;
  86. jz4740_rtc_wait_ready(rtc_base);
  87. writel(reset_counter_ticks, rtc_base + JZ_REG_RTC_RESET_COUNTER);
  88. jz4740_rtc_wait_ready(rtc_base);
  89. writel(1, rtc_base + JZ_REG_RTC_HIBERNATE);
  90. jz4740_halt();
  91. }
  92. void jz4740_reset_init(void)
  93. {
  94. _machine_restart = jz4740_restart;
  95. _machine_halt = jz4740_halt;
  96. pm_power_off = jz4740_power_off;
  97. }