system.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <linux/module.h>
  25. #include <asm/proc-fns.h>
  26. #include <asm/system.h>
  27. #include <mach/mxs.h>
  28. #include <mach/common.h>
  29. #define MX23_CLKCTRL_RESET_OFFSET 0x120
  30. #define MX28_CLKCTRL_RESET_OFFSET 0x1e0
  31. #define MXS_CLKCTRL_RESET_CHIP (1 << 1)
  32. #define MXS_MODULE_CLKGATE (1 << 30)
  33. #define MXS_MODULE_SFTRST (1 << 31)
  34. static void __iomem *mxs_clkctrl_reset_addr;
  35. /*
  36. * Reset the system. It is called by machine_restart().
  37. */
  38. void arch_reset(char mode, const char *cmd)
  39. {
  40. /* reset the chip */
  41. __mxs_setl(MXS_CLKCTRL_RESET_CHIP, mxs_clkctrl_reset_addr);
  42. pr_err("Failed to assert the chip reset\n");
  43. /* Delay to allow the serial port to show the message */
  44. mdelay(50);
  45. /* We'll take a jump through zero as a poor second */
  46. cpu_reset(0);
  47. }
  48. static int __init mxs_arch_reset_init(void)
  49. {
  50. struct clk *clk;
  51. mxs_clkctrl_reset_addr = MXS_IO_ADDRESS(MXS_CLKCTRL_BASE_ADDR) +
  52. (cpu_is_mx23() ? MX23_CLKCTRL_RESET_OFFSET :
  53. MX28_CLKCTRL_RESET_OFFSET);
  54. clk = clk_get_sys("rtc", NULL);
  55. if (!IS_ERR(clk))
  56. clk_enable(clk);
  57. return 0;
  58. }
  59. core_initcall(mxs_arch_reset_init);
  60. /*
  61. * Clear the bit and poll it cleared. This is usually called with
  62. * a reset address and mask being either SFTRST(bit 31) or CLKGATE
  63. * (bit 30).
  64. */
  65. static int clear_poll_bit(void __iomem *addr, u32 mask)
  66. {
  67. int timeout = 0x400;
  68. /* clear the bit */
  69. __mxs_clrl(mask, addr);
  70. /*
  71. * SFTRST needs 3 GPMI clocks to settle, the reference manual
  72. * recommends to wait 1us.
  73. */
  74. udelay(1);
  75. /* poll the bit becoming clear */
  76. while ((__raw_readl(addr) & mask) && --timeout)
  77. /* nothing */;
  78. return !timeout;
  79. }
  80. int mxs_reset_block(void __iomem *reset_addr)
  81. {
  82. int ret;
  83. int timeout = 0x400;
  84. /* clear and poll SFTRST */
  85. ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
  86. if (unlikely(ret))
  87. goto error;
  88. /* clear CLKGATE */
  89. __mxs_clrl(MXS_MODULE_CLKGATE, reset_addr);
  90. /* set SFTRST to reset the block */
  91. __mxs_setl(MXS_MODULE_SFTRST, reset_addr);
  92. udelay(1);
  93. /* poll CLKGATE becoming set */
  94. while ((!(__raw_readl(reset_addr) & MXS_MODULE_CLKGATE)) && --timeout)
  95. /* nothing */;
  96. if (unlikely(!timeout))
  97. goto error;
  98. /* clear and poll SFTRST */
  99. ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
  100. if (unlikely(ret))
  101. goto error;
  102. /* clear and poll CLKGATE */
  103. ret = clear_poll_bit(reset_addr, MXS_MODULE_CLKGATE);
  104. if (unlikely(ret))
  105. goto error;
  106. return 0;
  107. error:
  108. pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
  109. return -ETIMEDOUT;
  110. }
  111. EXPORT_SYMBOL(mxs_reset_block);