blob: 8273a7fae4e96273cb5cade22f53d5db40a1da41 [file] [log] [blame]
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -04001/*
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
26#include <common.h>
27#include <asm/arch/hardware.h>
Sekhar Nori302fc2f2009-11-12 11:07:22 -050028#include <asm/io.h>
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040029
30/*
David Brownell5f02add2009-05-15 23:44:08 +020031 * The PSC manages three inputs to a "module" which may be a peripheral or
32 * CPU. Those inputs are the module's: clock; reset signal; and sometimes
33 * its power domain. For our purposes, we only care whether clock and power
34 * are active, and the module is out of reset.
35 *
36 * DaVinci chips may include two separate power domains: "Always On" and "DSP".
37 * Chips without a DSP generally have only one domain.
38 *
39 * The "Always On" power domain is always on when the chip is on, and is
40 * powered by the VDD pins (on DM644X). The majority of DaVinci modules
41 * lie within the "Always On" power domain.
42 *
43 * A separate domain called the "DSP" domain houses the C64x+ and other video
44 * hardware such as VICP. In some chips, the "DSP" domain is not always on.
45 * The "DSP" power domain is powered by the CVDDDSP pins (on DM644X).
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040046 */
47
48/* Works on Always On power domain only (no PD argument) */
49void lpsc_on(unsigned int id)
50{
Sekhar Nori302fc2f2009-11-12 11:07:22 -050051 dv_reg_p mdstat, mdctl, ptstat, ptcmd;
52#ifdef CONFIG_SOC_DA8XX
53 struct davinci_psc_regs *psc_regs;
54#endif
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040055
Sekhar Nori302fc2f2009-11-12 11:07:22 -050056#ifndef CONFIG_SOC_DA8XX
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040057 if (id >= DAVINCI_LPSC_GEM)
58 return; /* Don't work on DSP Power Domain */
59
60 mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
61 mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
Sekhar Nori302fc2f2009-11-12 11:07:22 -050062 ptstat = REG_P(PSC_PTSTAT);
63 ptcmd = REG_P(PSC_PTCMD);
64#else
65 if (id < DAVINCI_LPSC_PSC1_BASE) {
66 if (id >= PSC_PSC0_MODULE_ID_CNT)
67 return;
68 psc_regs = davinci_psc0_regs;
69 mdstat = &psc_regs->psc0.mdstat[id];
70 mdctl = &psc_regs->psc0.mdctl[id];
71 } else {
72 id -= DAVINCI_LPSC_PSC1_BASE;
73 if (id >= PSC_PSC1_MODULE_ID_CNT)
74 return;
75 psc_regs = davinci_psc1_regs;
76 mdstat = &psc_regs->psc1.mdstat[id];
77 mdctl = &psc_regs->psc1.mdctl[id];
78 }
79 ptstat = &psc_regs->ptstat;
80 ptcmd = &psc_regs->ptcmd;
81#endif
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040082
Sekhar Nori302fc2f2009-11-12 11:07:22 -050083 while (readl(ptstat) & 0x01)
David Brownell5f02add2009-05-15 23:44:08 +020084 continue;
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040085
Sekhar Nori302fc2f2009-11-12 11:07:22 -050086 if ((readl(mdstat) & 0x1f) == 0x03)
87 return; /* Already on and enabled */
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040088
Sekhar Nori302fc2f2009-11-12 11:07:22 -050089 writel(readl(mdctl) | 0x03, mdctl);
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040090
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040091 switch (id) {
David Brownell5f02add2009-05-15 23:44:08 +020092#ifdef CONFIG_SOC_DM644X
93 /* Special treatment for some modules as for sprue14 p.7.4.2 */
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040094 case DAVINCI_LPSC_VPSSSLV:
95 case DAVINCI_LPSC_EMAC:
96 case DAVINCI_LPSC_EMAC_WRAPPER:
97 case DAVINCI_LPSC_MDIO:
98 case DAVINCI_LPSC_USB:
99 case DAVINCI_LPSC_ATA:
100 case DAVINCI_LPSC_VLYNQ:
101 case DAVINCI_LPSC_UHPI:
102 case DAVINCI_LPSC_DDR_EMIF:
103 case DAVINCI_LPSC_AEMIF:
104 case DAVINCI_LPSC_MMC_SD:
105 case DAVINCI_LPSC_MEMSTICK:
106 case DAVINCI_LPSC_McBSP:
107 case DAVINCI_LPSC_GPIO:
Sekhar Nori302fc2f2009-11-12 11:07:22 -0500108 writel(readl(mdctl) | 0x200, mdctl);
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400109 break;
David Brownell5f02add2009-05-15 23:44:08 +0200110#endif
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400111 }
112
Sekhar Nori302fc2f2009-11-12 11:07:22 -0500113 writel(0x01, ptcmd);
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400114
Sekhar Nori302fc2f2009-11-12 11:07:22 -0500115 while (readl(ptstat) & 0x01)
David Brownell5f02add2009-05-15 23:44:08 +0200116 continue;
Sekhar Nori302fc2f2009-11-12 11:07:22 -0500117 while ((readl(mdstat) & 0x1f) != 0x03)
David Brownell5f02add2009-05-15 23:44:08 +0200118 continue;
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400119}
120
David Brownell5f02add2009-05-15 23:44:08 +0200121/* Not all DaVinci chips have a DSP power domain. */
122#ifdef CONFIG_SOC_DM644X
123
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400124/* If DSPLINK is used, we don't want U-Boot to power on the DSP. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200125#if !defined(CONFIG_SYS_USE_DSPLINK)
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400126void dsp_on(void)
127{
128 int i;
129
130 if (REG(PSC_PDSTAT1) & 0x1f)
131 return; /* Already on */
132
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;
141
142 for (i = 0; i < 100; i++) {
143 if (REG(PSC_EPCPR) & 0x02)
144 break;
145 }
146
147 REG(PSC_CHP_SHRTSW) = 0x01;
148 REG(PSC_PDCTL1) |= 0x100;
149 REG(PSC_EPCCR) = 0x02;
150
151 for (i = 0; i < 100; i++) {
152 if (!(REG(PSC_PTSTAT) & 0x02))
153 break;
154 }
155
156 REG(PSC_GBLCTL) &= ~0x1f;
157}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158#endif /* CONFIG_SYS_USE_DSPLINK */
Hugo Villeneuvec9a21372008-11-21 14:35:56 -0500159
David Brownell5f02add2009-05-15 23:44:08 +0200160#endif /* have a DSP */