psc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Power and Sleep Controller (PSC) functions.
  3. *
  4. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  5. * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
  6. * Copyright (C) 2004 Texas Instruments.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <common.h>
  26. #include <asm/arch/hardware.h>
  27. #include <asm/io.h>
  28. /*
  29. * The PSC manages three inputs to a "module" which may be a peripheral or
  30. * CPU. Those inputs are the module's: clock; reset signal; and sometimes
  31. * its power domain. For our purposes, we only care whether clock and power
  32. * are active, and the module is out of reset.
  33. *
  34. * DaVinci chips may include two separate power domains: "Always On" and "DSP".
  35. * Chips without a DSP generally have only one domain.
  36. *
  37. * The "Always On" power domain is always on when the chip is on, and is
  38. * powered by the VDD pins (on DM644X). The majority of DaVinci modules
  39. * lie within the "Always On" power domain.
  40. *
  41. * A separate domain called the "DSP" domain houses the C64x+ and other video
  42. * hardware such as VICP. In some chips, the "DSP" domain is not always on.
  43. * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X).
  44. */
  45. /* Works on Always On power domain only (no PD argument) */
  46. void lpsc_on(unsigned int id)
  47. {
  48. dv_reg_p mdstat, mdctl, ptstat, ptcmd;
  49. #ifdef CONFIG_SOC_DA8XX
  50. struct davinci_psc_regs *psc_regs;
  51. #endif
  52. #ifndef CONFIG_SOC_DA8XX
  53. if (id >= DAVINCI_LPSC_GEM)
  54. return; /* Don't work on DSP Power Domain */
  55. mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
  56. mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
  57. ptstat = REG_P(PSC_PTSTAT);
  58. ptcmd = REG_P(PSC_PTCMD);
  59. #else
  60. if (id < DAVINCI_LPSC_PSC1_BASE) {
  61. if (id >= PSC_PSC0_MODULE_ID_CNT)
  62. return;
  63. psc_regs = davinci_psc0_regs;
  64. mdstat = &psc_regs->psc0.mdstat[id];
  65. mdctl = &psc_regs->psc0.mdctl[id];
  66. } else {
  67. id -= DAVINCI_LPSC_PSC1_BASE;
  68. if (id >= PSC_PSC1_MODULE_ID_CNT)
  69. return;
  70. psc_regs = davinci_psc1_regs;
  71. mdstat = &psc_regs->psc1.mdstat[id];
  72. mdctl = &psc_regs->psc1.mdctl[id];
  73. }
  74. ptstat = &psc_regs->ptstat;
  75. ptcmd = &psc_regs->ptcmd;
  76. #endif
  77. while (readl(ptstat) & 0x01)
  78. continue;
  79. if ((readl(mdstat) & 0x1f) == 0x03)
  80. return; /* Already on and enabled */
  81. writel(readl(mdctl) | 0x03, mdctl);
  82. switch (id) {
  83. #ifdef CONFIG_SOC_DM644X
  84. /* Special treatment for some modules as for sprue14 p.7.4.2 */
  85. case DAVINCI_LPSC_VPSSSLV:
  86. case DAVINCI_LPSC_EMAC:
  87. case DAVINCI_LPSC_EMAC_WRAPPER:
  88. case DAVINCI_LPSC_MDIO:
  89. case DAVINCI_LPSC_USB:
  90. case DAVINCI_LPSC_ATA:
  91. case DAVINCI_LPSC_VLYNQ:
  92. case DAVINCI_LPSC_UHPI:
  93. case DAVINCI_LPSC_DDR_EMIF:
  94. case DAVINCI_LPSC_AEMIF:
  95. case DAVINCI_LPSC_MMC_SD:
  96. case DAVINCI_LPSC_MEMSTICK:
  97. case DAVINCI_LPSC_McBSP:
  98. case DAVINCI_LPSC_GPIO:
  99. writel(readl(mdctl) | 0x200, mdctl);
  100. break;
  101. #endif
  102. }
  103. writel(0x01, ptcmd);
  104. while (readl(ptstat) & 0x01)
  105. continue;
  106. while ((readl(mdstat) & 0x1f) != 0x03)
  107. continue;
  108. }
  109. /* Not all DaVinci chips have a DSP power domain. */
  110. #ifdef CONFIG_SOC_DM644X
  111. /* If DSPLINK is used, we don't want U-Boot to power on the DSP. */
  112. #if !defined(CONFIG_SYS_USE_DSPLINK)
  113. void dsp_on(void)
  114. {
  115. int i;
  116. if (REG(PSC_PDSTAT1) & 0x1f)
  117. return; /* Already on */
  118. REG(PSC_GBLCTL) |= 0x01;
  119. REG(PSC_PDCTL1) |= 0x01;
  120. REG(PSC_PDCTL1) &= ~0x100;
  121. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03;
  122. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff;
  123. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03;
  124. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff;
  125. REG(PSC_PTCMD) = 0x02;
  126. for (i = 0; i < 100; i++) {
  127. if (REG(PSC_EPCPR) & 0x02)
  128. break;
  129. }
  130. REG(PSC_CHP_SHRTSW) = 0x01;
  131. REG(PSC_PDCTL1) |= 0x100;
  132. REG(PSC_EPCCR) = 0x02;
  133. for (i = 0; i < 100; i++) {
  134. if (!(REG(PSC_PTSTAT) & 0x02))
  135. break;
  136. }
  137. REG(PSC_GBLCTL) &= ~0x1f;
  138. }
  139. #endif /* CONFIG_SYS_USE_DSPLINK */
  140. #endif /* have a DSP */