core.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/dma.h>
  22. #include <mach/regs-clkctrl.h>
  23. static int __stmp3xxx_reset_block(void __iomem *hwreg, int just_enable)
  24. {
  25. u32 c;
  26. int timeout;
  27. /* the process of software reset of IP block is done
  28. in several steps:
  29. - clear SFTRST and wait for block is enabled;
  30. - clear clock gating (CLKGATE bit);
  31. - set the SFTRST again and wait for block is in reset;
  32. - clear SFTRST and wait for reset completion.
  33. */
  34. c = __raw_readl(hwreg);
  35. c &= ~(1<<31); /* clear SFTRST */
  36. __raw_writel(c, hwreg);
  37. for (timeout = 1000000; timeout > 0; timeout--)
  38. /* still in SFTRST state ? */
  39. if ((__raw_readl(hwreg) & (1<<31)) == 0)
  40. break;
  41. if (timeout <= 0) {
  42. printk(KERN_ERR"%s(%p): timeout when enabling\n",
  43. __func__, hwreg);
  44. return -ETIME;
  45. }
  46. c = __raw_readl(hwreg);
  47. c &= ~(1<<30); /* clear CLKGATE */
  48. __raw_writel(c, hwreg);
  49. if (!just_enable) {
  50. c = __raw_readl(hwreg);
  51. c |= (1<<31); /* now again set SFTRST */
  52. __raw_writel(c, hwreg);
  53. for (timeout = 1000000; timeout > 0; timeout--)
  54. /* poll until CLKGATE set */
  55. if (__raw_readl(hwreg) & (1<<30))
  56. break;
  57. if (timeout <= 0) {
  58. printk(KERN_ERR"%s(%p): timeout when resetting\n",
  59. __func__, hwreg);
  60. return -ETIME;
  61. }
  62. c = __raw_readl(hwreg);
  63. c &= ~(1<<31); /* clear SFTRST */
  64. __raw_writel(c, hwreg);
  65. for (timeout = 1000000; timeout > 0; timeout--)
  66. /* still in SFTRST state ? */
  67. if ((__raw_readl(hwreg) & (1<<31)) == 0)
  68. break;
  69. if (timeout <= 0) {
  70. printk(KERN_ERR"%s(%p): timeout when enabling "
  71. "after reset\n", __func__, hwreg);
  72. return -ETIME;
  73. }
  74. c = __raw_readl(hwreg);
  75. c &= ~(1<<30); /* clear CLKGATE */
  76. __raw_writel(c, hwreg);
  77. }
  78. for (timeout = 1000000; timeout > 0; timeout--)
  79. /* still in SFTRST state ? */
  80. if ((__raw_readl(hwreg) & (1<<30)) == 0)
  81. break;
  82. if (timeout <= 0) {
  83. printk(KERN_ERR"%s(%p): timeout when unclockgating\n",
  84. __func__, hwreg);
  85. return -ETIME;
  86. }
  87. return 0;
  88. }
  89. int stmp3xxx_reset_block(void __iomem *hwreg, int just_enable)
  90. {
  91. int try = 10;
  92. int r;
  93. while (try--) {
  94. r = __stmp3xxx_reset_block(hwreg, just_enable);
  95. if (!r)
  96. break;
  97. pr_debug("%s: try %d failed\n", __func__, 10 - try);
  98. }
  99. return r;
  100. }
  101. EXPORT_SYMBOL(stmp3xxx_reset_block);
  102. struct platform_device stmp3xxx_dbguart = {
  103. .name = "stmp3xxx-dbguart",
  104. .id = -1,
  105. };
  106. void __init stmp3xxx_init(void)
  107. {
  108. /* Turn off auto-slow and other tricks */
  109. HW_CLKCTRL_HBUS_CLR(0x07f00000U);
  110. stmp3xxx_dma_init();
  111. }