2 * Power and Sleep Controller (PSC) functions.
4 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
5 * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
6 * Copyright (C) 2004 Texas Instruments.
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/arch/hardware.h>
16 * The PSC manages three inputs to a "module" which may be a peripheral or
17 * CPU. Those inputs are the module's: clock; reset signal; and sometimes
18 * its power domain. For our purposes, we only care whether clock and power
19 * are active, and the module is out of reset.
21 * DaVinci chips may include two separate power domains: "Always On" and "DSP".
22 * Chips without a DSP generally have only one domain.
24 * The "Always On" power domain is always on when the chip is on, and is
25 * powered by the VDD pins (on DM644X). The majority of DaVinci modules
26 * lie within the "Always On" power domain.
28 * A separate domain called the "DSP" domain houses the C64x+ and other video
29 * hardware such as VICP. In some chips, the "DSP" domain is not always on.
30 * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X).
33 /* Works on Always On power domain only (no PD argument) */
34 static void lpsc_transition(unsigned int id
, unsigned int state
)
36 dv_reg_p mdstat
, mdctl
, ptstat
, ptcmd
;
37 #ifdef CONFIG_SOC_DA8XX
38 struct davinci_psc_regs
*psc_regs
;
41 #ifndef CONFIG_SOC_DA8XX
42 if (id
>= DAVINCI_LPSC_GEM
)
43 return; /* Don't work on DSP Power Domain */
45 mdstat
= REG_P(PSC_MDSTAT_BASE
+ (id
* 4));
46 mdctl
= REG_P(PSC_MDCTL_BASE
+ (id
* 4));
47 ptstat
= REG_P(PSC_PTSTAT
);
48 ptcmd
= REG_P(PSC_PTCMD
);
50 if (id
< DAVINCI_LPSC_PSC1_BASE
) {
51 if (id
>= PSC_PSC0_MODULE_ID_CNT
)
53 psc_regs
= davinci_psc0_regs
;
54 mdstat
= &psc_regs
->psc0
.mdstat
[id
];
55 mdctl
= &psc_regs
->psc0
.mdctl
[id
];
57 id
-= DAVINCI_LPSC_PSC1_BASE
;
58 if (id
>= PSC_PSC1_MODULE_ID_CNT
)
60 psc_regs
= davinci_psc1_regs
;
61 mdstat
= &psc_regs
->psc1
.mdstat
[id
];
62 mdctl
= &psc_regs
->psc1
.mdctl
[id
];
64 ptstat
= &psc_regs
->ptstat
;
65 ptcmd
= &psc_regs
->ptcmd
;
68 while (readl(ptstat
) & 0x01)
71 if ((readl(mdstat
) & PSC_MDSTAT_STATE
) == state
)
72 return; /* Already in that state */
74 writel((readl(mdctl
) & ~PSC_MDCTL_NEXT
) | state
, mdctl
);
77 #ifdef CONFIG_SOC_DM644X
78 /* Special treatment for some modules as for sprue14 p.7.4.2 */
79 case DAVINCI_LPSC_VPSSSLV
:
80 case DAVINCI_LPSC_EMAC
:
81 case DAVINCI_LPSC_EMAC_WRAPPER
:
82 case DAVINCI_LPSC_MDIO
:
83 case DAVINCI_LPSC_USB
:
84 case DAVINCI_LPSC_ATA
:
85 case DAVINCI_LPSC_VLYNQ
:
86 case DAVINCI_LPSC_UHPI
:
87 case DAVINCI_LPSC_DDR_EMIF
:
88 case DAVINCI_LPSC_AEMIF
:
89 case DAVINCI_LPSC_MMC_SD
:
90 case DAVINCI_LPSC_MEMSTICK
:
91 case DAVINCI_LPSC_McBSP
:
92 case DAVINCI_LPSC_GPIO
:
93 writel(readl(mdctl
) | 0x200, mdctl
);
100 while (readl(ptstat
) & 0x01)
102 while ((readl(mdstat
) & PSC_MDSTAT_STATE
) != state
)
106 void lpsc_on(unsigned int id
)
108 lpsc_transition(id
, 0x03);
111 void lpsc_syncreset(unsigned int id
)
113 lpsc_transition(id
, 0x01);
116 void lpsc_disable(unsigned int id
)
118 lpsc_transition(id
, 0x0);
121 /* Not all DaVinci chips have a DSP power domain. */
122 #ifdef CONFIG_SOC_DM644X
124 /* If DSPLINK is used, we don't want U-Boot to power on the DSP. */
125 #if !defined(CONFIG_SYS_USE_DSPLINK)
130 if (REG(PSC_PDSTAT1
) & 0x1f)
131 return; /* Already on */
133 REG(PSC_GBLCTL
) |= 0x01;
134 REG(PSC_PDCTL1
) |= 0x01;
135 REG(PSC_PDCTL1
) &= ~0x100;
136 REG(PSC_MDCTL_BASE
+ (DAVINCI_LPSC_GEM
* 4)) |= 0x03;
137 REG(PSC_MDCTL_BASE
+ (DAVINCI_LPSC_GEM
* 4)) &= 0xfffffeff;
138 REG(PSC_MDCTL_BASE
+ (DAVINCI_LPSC_IMCOP
* 4)) |= 0x03;
139 REG(PSC_MDCTL_BASE
+ (DAVINCI_LPSC_IMCOP
* 4)) &= 0xfffffeff;
140 REG(PSC_PTCMD
) = 0x02;
142 for (i
= 0; i
< 100; i
++) {
143 if (REG(PSC_EPCPR
) & 0x02)
147 REG(PSC_CHP_SHRTSW
) = 0x01;
148 REG(PSC_PDCTL1
) |= 0x100;
149 REG(PSC_EPCCR
) = 0x02;
151 for (i
= 0; i
< 100; i
++) {
152 if (!(REG(PSC_PTSTAT
) & 0x02))
156 REG(PSC_GBLCTL
) &= ~0x1f;
158 #endif /* CONFIG_SYS_USE_DSPLINK */
160 #endif /* have a DSP */