core.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Freescale STMP37XX/STMP378X core routines
  3. *
  4. * Embedded Alley Solutions, Inc <source@embeddedalley.com>
  5. *
  6. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  7. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  8. */
  9. /*
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/io.h>
  20. #include <mach/stmp3xxx.h>
  21. #include <mach/platform.h>
  22. #include <mach/dma.h>
  23. #include <mach/regs-clkctrl.h>
  24. static int __stmp3xxx_reset_block(void __iomem *hwreg, int just_enable)
  25. {
  26. u32 c;
  27. int timeout;
  28. /* the process of software reset of IP block is done
  29. in several steps:
  30. - clear SFTRST and wait for block is enabled;
  31. - clear clock gating (CLKGATE bit);
  32. - set the SFTRST again and wait for block is in reset;
  33. - clear SFTRST and wait for reset completion.
  34. */
  35. c = __raw_readl(hwreg);
  36. c &= ~(1<<31); /* clear SFTRST */
  37. __raw_writel(c, hwreg);
  38. for (timeout = 1000000; timeout > 0; timeout--)
  39. /* still in SFTRST state ? */
  40. if ((__raw_readl(hwreg) & (1<<31)) == 0)
  41. break;
  42. if (timeout <= 0) {
  43. printk(KERN_ERR"%s(%p): timeout when enabling\n",
  44. __func__, hwreg);
  45. return -ETIME;
  46. }
  47. c = __raw_readl(hwreg);
  48. c &= ~(1<<30); /* clear CLKGATE */
  49. __raw_writel(c, hwreg);
  50. if (!just_enable) {
  51. c = __raw_readl(hwreg);
  52. c |= (1<<31); /* now again set SFTRST */
  53. __raw_writel(c, hwreg);
  54. for (timeout = 1000000; timeout > 0; timeout--)
  55. /* poll until CLKGATE set */
  56. if (__raw_readl(hwreg) & (1<<30))
  57. break;
  58. if (timeout <= 0) {
  59. printk(KERN_ERR"%s(%p): timeout when resetting\n",
  60. __func__, hwreg);
  61. return -ETIME;
  62. }
  63. c = __raw_readl(hwreg);
  64. c &= ~(1<<31); /* clear SFTRST */
  65. __raw_writel(c, hwreg);
  66. for (timeout = 1000000; timeout > 0; timeout--)
  67. /* still in SFTRST state ? */
  68. if ((__raw_readl(hwreg) & (1<<31)) == 0)
  69. break;
  70. if (timeout <= 0) {
  71. printk(KERN_ERR"%s(%p): timeout when enabling "
  72. "after reset\n", __func__, hwreg);
  73. return -ETIME;
  74. }
  75. c = __raw_readl(hwreg);
  76. c &= ~(1<<30); /* clear CLKGATE */
  77. __raw_writel(c, hwreg);
  78. }
  79. for (timeout = 1000000; timeout > 0; timeout--)
  80. /* still in SFTRST state ? */
  81. if ((__raw_readl(hwreg) & (1<<30)) == 0)
  82. break;
  83. if (timeout <= 0) {
  84. printk(KERN_ERR"%s(%p): timeout when unclockgating\n",
  85. __func__, hwreg);
  86. return -ETIME;
  87. }
  88. return 0;
  89. }
  90. int stmp3xxx_reset_block(void __iomem *hwreg, int just_enable)
  91. {
  92. int try = 10;
  93. int r;
  94. while (try--) {
  95. r = __stmp3xxx_reset_block(hwreg, just_enable);
  96. if (!r)
  97. break;
  98. pr_debug("%s: try %d failed\n", __func__, 10 - try);
  99. }
  100. return r;
  101. }
  102. EXPORT_SYMBOL(stmp3xxx_reset_block);
  103. struct platform_device stmp3xxx_dbguart = {
  104. .name = "stmp3xxx-dbguart",
  105. .id = -1,
  106. };
  107. void __init stmp3xxx_init(void)
  108. {
  109. /* Turn off auto-slow and other tricks */
  110. stmp3xxx_clearl(0x7f00000, REGS_CLKCTRL_BASE + HW_CLKCTRL_HBUS);
  111. stmp3xxx_dma_init();
  112. }