system.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 1999 ARM Limited
  3. * Copyright (C) 2000 Deep Blue Solutions Ltd
  4. * Copyright 2006-2007,2010 Freescale Semiconductor, Inc. All Rights Reserved.
  5. * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
  6. * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/err.h>
  22. #include <linux/delay.h>
  23. #include <linux/init.h>
  24. #include <asm/proc-fns.h>
  25. #include <asm/system.h>
  26. #include <mach/mxs.h>
  27. #include <mach/common.h>
  28. #define MX23_CLKCTRL_RESET_OFFSET 0x120
  29. #define MX28_CLKCTRL_RESET_OFFSET 0x1e0
  30. #define MXS_CLKCTRL_RESET_CHIP (1 << 1)
  31. #define MXS_MODULE_CLKGATE (1 << 30)
  32. #define MXS_MODULE_SFTRST (1 << 31)
  33. static void __iomem *mxs_clkctrl_reset_addr;
  34. /*
  35. * Reset the system. It is called by machine_restart().
  36. */
  37. void arch_reset(char mode, const char *cmd)
  38. {
  39. /* reset the chip */
  40. __mxs_setl(MXS_CLKCTRL_RESET_CHIP, mxs_clkctrl_reset_addr);
  41. pr_err("Failed to assert the chip reset\n");
  42. /* Delay to allow the serial port to show the message */
  43. mdelay(50);
  44. /* We'll take a jump through zero as a poor second */
  45. cpu_reset(0);
  46. }
  47. static int __init mxs_arch_reset_init(void)
  48. {
  49. struct clk *clk;
  50. mxs_clkctrl_reset_addr = MXS_IO_ADDRESS(MXS_CLKCTRL_BASE_ADDR) +
  51. (cpu_is_mx23() ? MX23_CLKCTRL_RESET_OFFSET :
  52. MX28_CLKCTRL_RESET_OFFSET);
  53. clk = clk_get_sys("rtc", NULL);
  54. if (!IS_ERR(clk))
  55. clk_enable(clk);
  56. return 0;
  57. }
  58. core_initcall(mxs_arch_reset_init);
  59. /*
  60. * Clear the bit and poll it cleared. This is usually called with
  61. * a reset address and mask being either SFTRST(bit 31) or CLKGATE
  62. * (bit 30).
  63. */
  64. static int clear_poll_bit(void __iomem *addr, u32 mask)
  65. {
  66. int timeout = 0x400;
  67. /* clear the bit */
  68. __mxs_clrl(mask, addr);
  69. /*
  70. * SFTRST needs 3 GPMI clocks to settle, the reference manual
  71. * recommends to wait 1us.
  72. */
  73. udelay(1);
  74. /* poll the bit becoming clear */
  75. while ((__raw_readl(addr) & mask) && --timeout)
  76. /* nothing */;
  77. return !timeout;
  78. }
  79. int mxs_reset_block(void __iomem *reset_addr)
  80. {
  81. int ret;
  82. int timeout = 0x400;
  83. /* clear and poll SFTRST */
  84. ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
  85. if (unlikely(ret))
  86. goto error;
  87. /* clear CLKGATE */
  88. __mxs_clrl(MXS_MODULE_CLKGATE, reset_addr);
  89. /* set SFTRST to reset the block */
  90. __mxs_setl(MXS_MODULE_SFTRST, reset_addr);
  91. udelay(1);
  92. /* poll CLKGATE becoming set */
  93. while ((!(__raw_readl(reset_addr) & MXS_MODULE_CLKGATE)) && --timeout)
  94. /* nothing */;
  95. if (unlikely(!timeout))
  96. goto error;
  97. /* clear and poll SFTRST */
  98. ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
  99. if (unlikely(ret))
  100. goto error;
  101. /* clear and poll CLKGATE */
  102. ret = clear_poll_bit(reset_addr, MXS_MODULE_CLKGATE);
  103. if (unlikely(ret))
  104. goto error;
  105. return 0;
  106. error:
  107. pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
  108. return -ETIMEDOUT;
  109. }