psc.c 4.0 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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/arch/hardware.h>
  12. #include <asm/io.h>
  13. /*
  14. * The PSC manages three inputs to a "module" which may be a peripheral or
  15. * CPU. Those inputs are the module's: clock; reset signal; and sometimes
  16. * its power domain. For our purposes, we only care whether clock and power
  17. * are active, and the module is out of reset.
  18. *
  19. * DaVinci chips may include two separate power domains: "Always On" and "DSP".
  20. * Chips without a DSP generally have only one domain.
  21. *
  22. * The "Always On" power domain is always on when the chip is on, and is
  23. * powered by the VDD pins (on DM644X). The majority of DaVinci modules
  24. * lie within the "Always On" power domain.
  25. *
  26. * A separate domain called the "DSP" domain houses the C64x+ and other video
  27. * hardware such as VICP. In some chips, the "DSP" domain is not always on.
  28. * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X).
  29. */
  30. /* Works on Always On power domain only (no PD argument) */
  31. static void lpsc_transition(unsigned int id, unsigned int state)
  32. {
  33. dv_reg_p mdstat, mdctl, ptstat, ptcmd;
  34. #ifdef CONFIG_SOC_DA8XX
  35. struct davinci_psc_regs *psc_regs;
  36. #endif
  37. #ifndef CONFIG_SOC_DA8XX
  38. if (id >= DAVINCI_LPSC_GEM)
  39. return; /* Don't work on DSP Power Domain */
  40. mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
  41. mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
  42. ptstat = REG_P(PSC_PTSTAT);
  43. ptcmd = REG_P(PSC_PTCMD);
  44. #else
  45. if (id < DAVINCI_LPSC_PSC1_BASE) {
  46. if (id >= PSC_PSC0_MODULE_ID_CNT)
  47. return;
  48. psc_regs = davinci_psc0_regs;
  49. mdstat = &psc_regs->psc0.mdstat[id];
  50. mdctl = &psc_regs->psc0.mdctl[id];
  51. } else {
  52. id -= DAVINCI_LPSC_PSC1_BASE;
  53. if (id >= PSC_PSC1_MODULE_ID_CNT)
  54. return;
  55. psc_regs = davinci_psc1_regs;
  56. mdstat = &psc_regs->psc1.mdstat[id];
  57. mdctl = &psc_regs->psc1.mdctl[id];
  58. }
  59. ptstat = &psc_regs->ptstat;
  60. ptcmd = &psc_regs->ptcmd;
  61. #endif
  62. while (readl(ptstat) & 0x01)
  63. continue;
  64. if ((readl(mdstat) & PSC_MDSTAT_STATE) == state)
  65. return; /* Already in that state */
  66. writel((readl(mdctl) & ~PSC_MDCTL_NEXT) | state, mdctl);
  67. switch (id) {
  68. #ifdef CONFIG_SOC_DM644X
  69. /* Special treatment for some modules as for sprue14 p.7.4.2 */
  70. case DAVINCI_LPSC_VPSSSLV:
  71. case DAVINCI_LPSC_EMAC:
  72. case DAVINCI_LPSC_EMAC_WRAPPER:
  73. case DAVINCI_LPSC_MDIO:
  74. case DAVINCI_LPSC_USB:
  75. case DAVINCI_LPSC_ATA:
  76. case DAVINCI_LPSC_VLYNQ:
  77. case DAVINCI_LPSC_UHPI:
  78. case DAVINCI_LPSC_DDR_EMIF:
  79. case DAVINCI_LPSC_AEMIF:
  80. case DAVINCI_LPSC_MMC_SD:
  81. case DAVINCI_LPSC_MEMSTICK:
  82. case DAVINCI_LPSC_McBSP:
  83. case DAVINCI_LPSC_GPIO:
  84. writel(readl(mdctl) | 0x200, mdctl);
  85. break;
  86. #endif
  87. }
  88. writel(0x01, ptcmd);
  89. while (readl(ptstat) & 0x01)
  90. continue;
  91. while ((readl(mdstat) & PSC_MDSTAT_STATE) != state)
  92. continue;
  93. }
  94. void lpsc_on(unsigned int id)
  95. {
  96. lpsc_transition(id, 0x03);
  97. }
  98. void lpsc_syncreset(unsigned int id)
  99. {
  100. lpsc_transition(id, 0x01);
  101. }
  102. void lpsc_disable(unsigned int id)
  103. {
  104. lpsc_transition(id, 0x0);
  105. }
  106. /* Not all DaVinci chips have a DSP power domain. */
  107. #ifdef CONFIG_SOC_DM644X
  108. /* If DSPLINK is used, we don't want U-Boot to power on the DSP. */
  109. #if !defined(CONFIG_SYS_USE_DSPLINK)
  110. void dsp_on(void)
  111. {
  112. int i;
  113. if (REG(PSC_PDSTAT1) & 0x1f)
  114. return; /* Already on */
  115. REG(PSC_GBLCTL) |= 0x01;
  116. REG(PSC_PDCTL1) |= 0x01;
  117. REG(PSC_PDCTL1) &= ~0x100;
  118. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03;
  119. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff;
  120. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03;
  121. REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff;
  122. REG(PSC_PTCMD) = 0x02;
  123. for (i = 0; i < 100; i++) {
  124. if (REG(PSC_EPCPR) & 0x02)
  125. break;
  126. }
  127. REG(PSC_CHP_SHRTSW) = 0x01;
  128. REG(PSC_PDCTL1) |= 0x100;
  129. REG(PSC_EPCCR) = 0x02;
  130. for (i = 0; i < 100; i++) {
  131. if (!(REG(PSC_PTSTAT) & 0x02))
  132. break;
  133. }
  134. REG(PSC_GBLCTL) &= ~0x1f;
  135. }
  136. #endif /* CONFIG_SYS_USE_DSPLINK */
  137. #endif /* have a DSP */