reset.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. static void jz4740_halt(void)
  21. {
  22. while (1) {
  23. __asm__(".set push;\n"
  24. ".set mips3;\n"
  25. "wait;\n"
  26. ".set pop;\n"
  27. );
  28. }
  29. }
  30. #define JZ_REG_WDT_DATA 0x00
  31. #define JZ_REG_WDT_COUNTER_ENABLE 0x04
  32. #define JZ_REG_WDT_COUNTER 0x08
  33. #define JZ_REG_WDT_CTRL 0x0c
  34. static void jz4740_restart(char *command)
  35. {
  36. void __iomem *wdt_base = ioremap(JZ4740_WDT_BASE_ADDR, 0x0f);
  37. jz4740_timer_enable_watchdog();
  38. writeb(0, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
  39. writew(0, wdt_base + JZ_REG_WDT_COUNTER);
  40. writew(0, wdt_base + JZ_REG_WDT_DATA);
  41. writew(BIT(2), wdt_base + JZ_REG_WDT_CTRL);
  42. writeb(1, wdt_base + JZ_REG_WDT_COUNTER_ENABLE);
  43. jz4740_halt();
  44. }
  45. #define JZ_REG_RTC_CTRL 0x00
  46. #define JZ_REG_RTC_HIBERNATE 0x20
  47. #define JZ_RTC_CTRL_WRDY BIT(7)
  48. static void jz4740_power_off(void)
  49. {
  50. void __iomem *rtc_base = ioremap(JZ4740_RTC_BASE_ADDR, 0x24);
  51. uint32_t ctrl;
  52. do {
  53. ctrl = readl(rtc_base + JZ_REG_RTC_CTRL);
  54. } while (!(ctrl & JZ_RTC_CTRL_WRDY));
  55. writel(1, rtc_base + JZ_REG_RTC_HIBERNATE);
  56. jz4740_halt();
  57. }
  58. void jz4740_reset_init(void)
  59. {
  60. _machine_restart = jz4740_restart;
  61. _machine_halt = jz4740_halt;
  62. pm_power_off = jz4740_power_off;
  63. }