]> git.sur5r.net Git - u-boot/blob - board/prodrive/pmdra/pmdra.c
42f7770e4402cddab1d8120165a9f5136b115d2b
[u-boot] / board / prodrive / pmdra / pmdra.c
1 /*
2  * Copyright (C) 2008 Prodrive BV <pv@prodrive.nl>
3  *
4  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
5  *
6  * Parts are shamelessly stolen from various TI sources, original copyright
7  * follows:
8  * ---------------------------------------------------------------------------
9  *
10  * Copyright (C) 2004 Texas Instruments.
11  *
12  * ---------------------------------------------------------------------------
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with this program; if not, write to the Free Software
25  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  * ---------------------------------------------------------------------------
27  */
28
29 #include <common.h>
30 #include <i2c.h>
31 #include <asm/arch/hardware.h>
32 #include <asm/arch/emac_defs.h>
33
34 #define MACH_TYPE_DAVINCI_EVM           901
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 extern void     timer_init(void);
39 extern int      eth_hw_init(void);
40 extern phy_t    phy;
41
42 /* Works on Always On power domain only (no PD argument) */
43 void lpsc_on(unsigned int id)
44 {
45         dv_reg_p        mdstat, mdctl;
46
47         if (id >= DAVINCI_LPSC_GEM)
48                 return;                 /* Don't work on DSP Power Domain */
49
50         mdstat = REG_P(PSC_MDSTAT_BASE + (id * 4));
51         mdctl = REG_P(PSC_MDCTL_BASE + (id * 4));
52
53         while (REG(PSC_PTSTAT) & 0x01) {; }
54
55         if ((*mdstat & 0x1f) == 0x03)
56                 return;                 /* Already on and enabled */
57
58         *mdctl |= 0x03;
59
60         /* Special treatment for some modules as for sprue14 p.7.4.2 */
61         if ((id == DAVINCI_LPSC_VPSSSLV) ||
62             (id == DAVINCI_LPSC_EMAC) ||
63             (id == DAVINCI_LPSC_EMAC_WRAPPER) ||
64             (id == DAVINCI_LPSC_MDIO) ||
65             (id == DAVINCI_LPSC_USB) ||
66             (id == DAVINCI_LPSC_ATA) ||
67             (id == DAVINCI_LPSC_VLYNQ) ||
68             (id == DAVINCI_LPSC_UHPI) ||
69             (id == DAVINCI_LPSC_DDR_EMIF) ||
70             (id == DAVINCI_LPSC_AEMIF) ||
71             (id == DAVINCI_LPSC_MMC_SD) ||
72             (id == DAVINCI_LPSC_MEMSTICK) ||
73             (id == DAVINCI_LPSC_McBSP) ||
74             (id == DAVINCI_LPSC_GPIO))
75                 *mdctl |= 0x200;
76
77         REG(PSC_PTCMD) = 0x01;
78
79         while (REG(PSC_PTSTAT) & 0x03) {; }
80         while ((*mdstat & 0x1f) != 0x03) {; }   /* Probably an overkill... */
81 }
82
83 void dsp_on(void)
84 {
85         int     i;
86
87         if (REG(PSC_PDSTAT1) & 0x1f)
88                 return;                 /* Already on */
89
90         REG(PSC_GBLCTL) |= 0x01;
91         REG(PSC_PDCTL1) |= 0x01;
92         REG(PSC_PDCTL1) &= ~0x100;
93         REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) |= 0x03;
94         REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_GEM * 4)) &= 0xfffffeff;
95         REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) |= 0x03;
96         REG(PSC_MDCTL_BASE + (DAVINCI_LPSC_IMCOP * 4)) &= 0xfffffeff;
97         REG(PSC_PTCMD) = 0x02;
98
99         for (i = 0; i < 100; i++) {
100                 if (REG(PSC_EPCPR) & 0x02)
101                         break;
102         }
103
104         REG(PSC_CHP_SHRTSW) = 0x01;
105         REG(PSC_PDCTL1) |= 0x100;
106         REG(PSC_EPCCR) = 0x02;
107
108         for (i = 0; i < 100; i++) {
109                 if (!(REG(PSC_PTSTAT) & 0x02))
110                         break;
111         }
112
113         REG(PSC_GBLCTL) &= ~0x1f;
114 }
115
116
117 int board_init(void)
118 {
119         /* arch number of the board */
120         gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_EVM;
121
122         /* address of boot parameters */
123         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
124
125         /* Workaround for TMS320DM6446 errata 1.3.22 */
126         REG(PSC_SILVER_BULLET) = 0;
127
128         /* Power on required peripherals */
129         lpsc_on(DAVINCI_LPSC_EMAC);
130         lpsc_on(DAVINCI_LPSC_EMAC_WRAPPER);
131         lpsc_on(DAVINCI_LPSC_MDIO);
132         lpsc_on(DAVINCI_LPSC_I2C);
133         lpsc_on(DAVINCI_LPSC_UART0);
134         lpsc_on(DAVINCI_LPSC_UART2);
135         lpsc_on(DAVINCI_LPSC_TIMER1);
136         lpsc_on(DAVINCI_LPSC_GPIO);
137
138         /* Powerup the DSP */
139         dsp_on();
140
141         /* Bringup UART0 and 2 out of reset */
142         REG(UART0_PWREMU_MGMT) = 0x00006001;
143         REG(UART2_PWREMU_MGMT) = 0x00006001;
144
145         /* Enable GIO3.3V cells used for EMAC */
146         REG(VDD3P3V_PWDN) = 0;
147
148         /* Enable UART0 and 2 MUX lines */
149         REG(PINMUX1) |= 1;
150         REG(PINMUX1) |= 4;
151
152         /* Enable EMAC and AEMIF pins */
153         REG(PINMUX0) = 0x80000c1f;
154
155         /* Enable I2C pin Mux */
156         REG(PINMUX1) |= (1 << 7);
157
158         /* Set the Bus Priority Register to appropriate value */
159         REG(VBPR) = 0x20;
160
161         timer_init();
162
163         return(0);
164 }
165
166 int misc_init_r(void)
167 {
168         int             clk = 0;
169
170         clk = ((REG(PLL2_PLLM) + 1) * 27) / ((REG(PLL2_DIV2) & 0x1f) + 1);
171
172         printf("ARM Clock : %dMHz\n", ((REG(PLL1_PLLM) + 1) * 27)/2);
173         printf("DDR Clock : %dMHz\n", (clk / 2));
174
175         if (!eth_hw_init())
176                 printf("ethernet init failed!\n");
177         else
178                 printf("ETH PHY   : %s\n", phy.name);
179
180         return(0);
181 }
182
183 int dram_init(void)
184 {
185         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
186         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
187
188         return(0);
189 }