blob: 28e2a4b5b6cf8aa690d05a1daf787c4cc06eab29 [file] [log] [blame]
Hugo Villeneuve264bbdd2008-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>
28
Hugo Villeneuve0cd18fa2008-11-21 14:35:56 -050029#define PINMUX0_EMACEN (1 << 31)
30#define PINMUX0_AECS5 (1 << 11)
31#define PINMUX0_AECS4 (1 << 10)
32
33#define PINMUX1_I2C (1 << 7)
34#define PINMUX1_UART1 (1 << 1)
35#define PINMUX1_UART0 (1 << 0)
36
Hugo Villeneuve264bbdd2008-07-11 15:10:13 -040037/*
38 * The DM6446 includes two separate power domains: "Always On" and "DSP". The
39 * "Always On" power domain is always on when the chip is on. The "Always On"
40 * domain is powered by the VDD pins of the DM6446. The majority of the
41 * DM6446's modules lie within the "Always On" power domain. A separate
42 * domain called the "DSP" domain houses the C64x+ and VICP. The "DSP" domain
43 * is not always on. The "DSP" power domain is powered by the CVDDDSP pins of
44 * the DM6446.
45 */
46
47/* Works on Always On power domain only (no PD argument) */
48void lpsc_on(unsigned int id)
49{
50 dv_reg_p mdstat, mdctl;
51
52 if (id >= DAVINCI_LPSC_GEM)
53 return; /* Don't work on DSP Power Domain */
54
55 mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
56 mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
57
58 while (REG(PSC_PTSTAT) & 0x01);
59
60 if ((*mdstat & 0x1f) == 0x03)
61 return; /* Already on and enabled */
62
63 *mdctl |= 0x03;
64
65 /* Special treatment for some modules as for sprue14 p.7.4.2 */
66 switch (id) {
67 case DAVINCI_LPSC_VPSSSLV:
68 case DAVINCI_LPSC_EMAC:
69 case DAVINCI_LPSC_EMAC_WRAPPER:
70 case DAVINCI_LPSC_MDIO:
71 case DAVINCI_LPSC_USB:
72 case DAVINCI_LPSC_ATA:
73 case DAVINCI_LPSC_VLYNQ:
74 case DAVINCI_LPSC_UHPI:
75 case DAVINCI_LPSC_DDR_EMIF:
76 case DAVINCI_LPSC_AEMIF:
77 case DAVINCI_LPSC_MMC_SD:
78 case DAVINCI_LPSC_MEMSTICK:
79 case DAVINCI_LPSC_McBSP:
80 case DAVINCI_LPSC_GPIO:
81 *mdctl |= 0x200;
82 break;
83 }
84
85 REG(PSC_PTCMD) = 0x01;
86
87 while (REG(PSC_PTSTAT) & 0x03);
88 while ((*mdstat & 0x1f) != 0x03); /* Probably an overkill... */
89}
90
91/* If DSPLINK is used, we don't want U-Boot to power on the DSP. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092#if !defined(CONFIG_SYS_USE_DSPLINK)
Hugo Villeneuve264bbdd2008-07-11 15:10:13 -040093void dsp_on(void)
94{
95 int i;
96
97 if (REG(PSC_PDSTAT1) & 0x1f)
98 return; /* Already on */
99
100 REG(PSC_GBLCTL) |= 0x01;
101 REG(PSC_PDCTL1) |= 0x01;
102 REG(PSC_PDCTL1) &= ~0x100;
103 REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03;
104 REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff;
105 REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03;
106 REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff;
107 REG(PSC_PTCMD) = 0x02;
108
109 for (i = 0; i < 100; i++) {
110 if (REG(PSC_EPCPR) & 0x02)
111 break;
112 }
113
114 REG(PSC_CHP_SHRTSW) = 0x01;
115 REG(PSC_PDCTL1) |= 0x100;
116 REG(PSC_EPCCR) = 0x02;
117
118 for (i = 0; i < 100; i++) {
119 if (!(REG(PSC_PTSTAT) & 0x02))
120 break;
121 }
122
123 REG(PSC_GBLCTL) &= ~0x1f;
124}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125#endif /* CONFIG_SYS_USE_DSPLINK */
Hugo Villeneuve0cd18fa2008-11-21 14:35:56 -0500126
127void davinci_enable_uart0(void)
128{
129 lpsc_on(DAVINCI_LPSC_UART0);
130
131 /* Bringup UART0 out of reset */
132 REG(UART0_PWREMU_MGMT) = 0x0000e003;
133
134 /* Enable UART0 MUX lines */
135 REG(PINMUX1) |= PINMUX1_UART0;
136}
137
138#ifdef CONFIG_DRIVER_TI_EMAC
139void davinci_enable_emac(void)
140{
141 lpsc_on(DAVINCI_LPSC_EMAC);
142 lpsc_on(DAVINCI_LPSC_EMAC_WRAPPER);
143 lpsc_on(DAVINCI_LPSC_MDIO);
144
145 /* Enable GIO3.3V cells used for EMAC */
146 REG(VDD3P3V_PWDN) = 0;
147
148 /* Enable EMAC. */
149 REG(PINMUX0) |= PINMUX0_EMACEN;
150}
151#endif
152
153void davinci_enable_i2c(void)
154{
155 lpsc_on(DAVINCI_LPSC_I2C);
156
157 /* Enable I2C pin Mux */
158 REG(PINMUX1) |= PINMUX1_I2C;
159}
160
161void davinci_errata_workarounds(void)
162{
163 /*
164 * Workaround for TMS320DM6446 errata 1.3.22:
165 * PSC: PTSTAT Register Does Not Clear After Warm/Maximum Reset
166 * Revision(s) Affected: 1.3 and earlier
167 */
168 REG(PSC_SILVER_BULLET) = 0;
169
170 /*
171 * Set the PR_OLD_COUNT bits in the Bus Burst Priority Register (PBBPR)
172 * as suggested in TMS320DM6446 errata 2.1.2:
173 *
174 * On DM6446 Silicon Revision 2.1 and earlier, under certain conditions
175 * low priority modules can occupy the bus and prevent high priority
176 * modules like the VPSS from getting the required DDR2 throughput.
177 * A hex value of 0x20 should provide a good ARM (cache enabled)
178 * performance and still allow good utilization by the VPSS or other
179 * modules.
180 */
181 REG(VBPR) = 0x20;
182}