xref: /openbmc/u-boot/arch/m68k/cpu/mcf5227x/cpu_init.c (revision a4145534)
1*a4145534SPeter Tyser /*
2*a4145534SPeter Tyser  *
3*a4145534SPeter Tyser  * (C) Copyright 2000-2003
4*a4145534SPeter Tyser  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5*a4145534SPeter Tyser  *
6*a4145534SPeter Tyser  * (C) Copyright 2004-2007 Freescale Semiconductor, Inc.
7*a4145534SPeter Tyser  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8*a4145534SPeter Tyser  *
9*a4145534SPeter Tyser  * See file CREDITS for list of people who contributed to this
10*a4145534SPeter Tyser  * project.
11*a4145534SPeter Tyser  *
12*a4145534SPeter Tyser  * This program is free software; you can redistribute it and/or
13*a4145534SPeter Tyser  * modify it under the terms of the GNU General Public License as
14*a4145534SPeter Tyser  * published by the Free Software Foundation; either version 2 of
15*a4145534SPeter Tyser  * the License, or (at your option) any later version.
16*a4145534SPeter Tyser  *
17*a4145534SPeter Tyser  * This program is distributed in the hope that it will be useful,
18*a4145534SPeter Tyser  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19*a4145534SPeter Tyser  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20*a4145534SPeter Tyser  * GNU General Public License for more details.
21*a4145534SPeter Tyser  *
22*a4145534SPeter Tyser  * You should have received a copy of the GNU General Public License
23*a4145534SPeter Tyser  * along with this program; if not, write to the Free Software
24*a4145534SPeter Tyser  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25*a4145534SPeter Tyser  * MA 02111-1307 USA
26*a4145534SPeter Tyser  */
27*a4145534SPeter Tyser 
28*a4145534SPeter Tyser #include <common.h>
29*a4145534SPeter Tyser #include <watchdog.h>
30*a4145534SPeter Tyser 
31*a4145534SPeter Tyser #include <asm/immap.h>
32*a4145534SPeter Tyser #include <asm/rtc.h>
33*a4145534SPeter Tyser 
34*a4145534SPeter Tyser /*
35*a4145534SPeter Tyser  * Breath some life into the CPU...
36*a4145534SPeter Tyser  *
37*a4145534SPeter Tyser  * Set up the memory map,
38*a4145534SPeter Tyser  * initialize a bunch of registers,
39*a4145534SPeter Tyser  * initialize the UPM's
40*a4145534SPeter Tyser  */
41*a4145534SPeter Tyser void cpu_init_f(void)
42*a4145534SPeter Tyser {
43*a4145534SPeter Tyser 	volatile scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
44*a4145534SPeter Tyser 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
45*a4145534SPeter Tyser 	volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
46*a4145534SPeter Tyser 	volatile pll_t *pll = (volatile pll_t *)MMAP_PLL;
47*a4145534SPeter Tyser 
48*a4145534SPeter Tyser #if !defined(CONFIG_CF_SBF)
49*a4145534SPeter Tyser 	/* Workaround, must place before fbcs */
50*a4145534SPeter Tyser 	pll->psr = 0x12;
51*a4145534SPeter Tyser 
52*a4145534SPeter Tyser 	scm1->mpr = 0x77777777;
53*a4145534SPeter Tyser 	scm1->pacra = 0;
54*a4145534SPeter Tyser 	scm1->pacrb = 0;
55*a4145534SPeter Tyser 	scm1->pacrc = 0;
56*a4145534SPeter Tyser 	scm1->pacrd = 0;
57*a4145534SPeter Tyser 	scm1->pacre = 0;
58*a4145534SPeter Tyser 	scm1->pacrf = 0;
59*a4145534SPeter Tyser 	scm1->pacrg = 0;
60*a4145534SPeter Tyser 	scm1->pacri = 0;
61*a4145534SPeter Tyser 
62*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
63*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS0_CTRL))
64*a4145534SPeter Tyser 	fbcs->csar0 = CONFIG_SYS_CS0_BASE;
65*a4145534SPeter Tyser 	fbcs->cscr0 = CONFIG_SYS_CS0_CTRL;
66*a4145534SPeter Tyser 	fbcs->csmr0 = CONFIG_SYS_CS0_MASK;
67*a4145534SPeter Tyser #endif
68*a4145534SPeter Tyser #endif				/* CONFIG_CF_SBF */
69*a4145534SPeter Tyser 
70*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
71*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS1_CTRL))
72*a4145534SPeter Tyser 	fbcs->csar1 = CONFIG_SYS_CS1_BASE;
73*a4145534SPeter Tyser 	fbcs->cscr1 = CONFIG_SYS_CS1_CTRL;
74*a4145534SPeter Tyser 	fbcs->csmr1 = CONFIG_SYS_CS1_MASK;
75*a4145534SPeter Tyser #endif
76*a4145534SPeter Tyser 
77*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
78*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS2_CTRL))
79*a4145534SPeter Tyser 	fbcs->csar2 = CONFIG_SYS_CS2_BASE;
80*a4145534SPeter Tyser 	fbcs->cscr2 = CONFIG_SYS_CS2_CTRL;
81*a4145534SPeter Tyser 	fbcs->csmr2 = CONFIG_SYS_CS2_MASK;
82*a4145534SPeter Tyser #endif
83*a4145534SPeter Tyser 
84*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
85*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS3_CTRL))
86*a4145534SPeter Tyser 	fbcs->csar3 = CONFIG_SYS_CS3_BASE;
87*a4145534SPeter Tyser 	fbcs->cscr3 = CONFIG_SYS_CS3_CTRL;
88*a4145534SPeter Tyser 	fbcs->csmr3 = CONFIG_SYS_CS3_MASK;
89*a4145534SPeter Tyser #endif
90*a4145534SPeter Tyser 
91*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
92*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS4_CTRL))
93*a4145534SPeter Tyser 	fbcs->csar4 = CONFIG_SYS_CS4_BASE;
94*a4145534SPeter Tyser 	fbcs->cscr4 = CONFIG_SYS_CS4_CTRL;
95*a4145534SPeter Tyser 	fbcs->csmr4 = CONFIG_SYS_CS4_MASK;
96*a4145534SPeter Tyser #endif
97*a4145534SPeter Tyser 
98*a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
99*a4145534SPeter Tyser      && defined(CONFIG_SYS_CS5_CTRL))
100*a4145534SPeter Tyser 	fbcs->csar5 = CONFIG_SYS_CS5_BASE;
101*a4145534SPeter Tyser 	fbcs->cscr5 = CONFIG_SYS_CS5_CTRL;
102*a4145534SPeter Tyser 	fbcs->csmr5 = CONFIG_SYS_CS5_MASK;
103*a4145534SPeter Tyser #endif
104*a4145534SPeter Tyser 
105*a4145534SPeter Tyser #ifdef CONFIG_FSL_I2C
106*a4145534SPeter Tyser 	gpio->par_i2c = GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA;
107*a4145534SPeter Tyser #endif
108*a4145534SPeter Tyser 
109*a4145534SPeter Tyser 	icache_enable();
110*a4145534SPeter Tyser }
111*a4145534SPeter Tyser 
112*a4145534SPeter Tyser /*
113*a4145534SPeter Tyser  * initialize higher level parts of CPU like timers
114*a4145534SPeter Tyser  */
115*a4145534SPeter Tyser int cpu_init_r(void)
116*a4145534SPeter Tyser {
117*a4145534SPeter Tyser #ifdef CONFIG_MCFRTC
118*a4145534SPeter Tyser 	volatile rtc_t *rtc = (volatile rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
119*a4145534SPeter Tyser 	volatile rtcex_t *rtcex = (volatile rtcex_t *)&rtc->extended;
120*a4145534SPeter Tyser 
121*a4145534SPeter Tyser 	rtcex->gocu = (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xFFFF;
122*a4145534SPeter Tyser 	rtcex->gocl = CONFIG_SYS_RTC_OSCILLATOR & 0xFFFF;
123*a4145534SPeter Tyser #endif
124*a4145534SPeter Tyser 
125*a4145534SPeter Tyser 	return (0);
126*a4145534SPeter Tyser }
127*a4145534SPeter Tyser 
128*a4145534SPeter Tyser void uart_port_conf(int port)
129*a4145534SPeter Tyser {
130*a4145534SPeter Tyser 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
131*a4145534SPeter Tyser 
132*a4145534SPeter Tyser 	/* Setup Ports: */
133*a4145534SPeter Tyser 	switch (port) {
134*a4145534SPeter Tyser 	case 0:
135*a4145534SPeter Tyser 		gpio->par_uart &=
136*a4145534SPeter Tyser 		    (GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK);
137*a4145534SPeter Tyser 		gpio->par_uart |=
138*a4145534SPeter Tyser 		    (GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
139*a4145534SPeter Tyser 		break;
140*a4145534SPeter Tyser 	case 1:
141*a4145534SPeter Tyser 		gpio->par_uart &=
142*a4145534SPeter Tyser 		    (GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK);
143*a4145534SPeter Tyser 		gpio->par_uart |=
144*a4145534SPeter Tyser 		    (GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
145*a4145534SPeter Tyser 		break;
146*a4145534SPeter Tyser 	case 2:
147*a4145534SPeter Tyser 		gpio->par_dspi &=
148*a4145534SPeter Tyser 		    (GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK);
149*a4145534SPeter Tyser 		gpio->par_dspi =
150*a4145534SPeter Tyser 		    (GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
151*a4145534SPeter Tyser 		break;
152*a4145534SPeter Tyser 	}
153*a4145534SPeter Tyser }
154*a4145534SPeter Tyser 
155*a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI
156*a4145534SPeter Tyser void cfspi_port_conf(void)
157*a4145534SPeter Tyser {
158*a4145534SPeter Tyser 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
159*a4145534SPeter Tyser 
160*a4145534SPeter Tyser 	gpio->par_dspi =
161*a4145534SPeter Tyser 	    GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
162*a4145534SPeter Tyser 	    GPIO_PAR_DSPI_SCK_SCK;
163*a4145534SPeter Tyser }
164*a4145534SPeter Tyser 
165*a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs)
166*a4145534SPeter Tyser {
167*a4145534SPeter Tyser 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
168*a4145534SPeter Tyser 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
169*a4145534SPeter Tyser 
170*a4145534SPeter Tyser 	if ((dspi->sr & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
171*a4145534SPeter Tyser 		return -1;
172*a4145534SPeter Tyser 
173*a4145534SPeter Tyser 	/* Clear FIFO and resume transfer */
174*a4145534SPeter Tyser 	dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF);
175*a4145534SPeter Tyser 
176*a4145534SPeter Tyser 	switch (cs) {
177*a4145534SPeter Tyser 	case 0:
178*a4145534SPeter Tyser 		gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_UNMASK;
179*a4145534SPeter Tyser 		gpio->par_dspi |= GPIO_PAR_DSPI_PCS0_PCS0;
180*a4145534SPeter Tyser 		break;
181*a4145534SPeter Tyser 	case 2:
182*a4145534SPeter Tyser 		gpio->par_timer &= GPIO_PAR_TIMER_T2IN_UNMASK;
183*a4145534SPeter Tyser 		gpio->par_timer |= GPIO_PAR_TIMER_T2IN_DSPIPCS2;
184*a4145534SPeter Tyser 		break;
185*a4145534SPeter Tyser 	}
186*a4145534SPeter Tyser 
187*a4145534SPeter Tyser 	return 0;
188*a4145534SPeter Tyser }
189*a4145534SPeter Tyser 
190*a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs)
191*a4145534SPeter Tyser {
192*a4145534SPeter Tyser 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
193*a4145534SPeter Tyser 	volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
194*a4145534SPeter Tyser 
195*a4145534SPeter Tyser 	dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF);	/* Clear FIFO */
196*a4145534SPeter Tyser 
197*a4145534SPeter Tyser 	switch (cs) {
198*a4145534SPeter Tyser 	case 0:
199*a4145534SPeter Tyser 		gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
200*a4145534SPeter Tyser 		break;
201*a4145534SPeter Tyser 	case 2:
202*a4145534SPeter Tyser 		gpio->par_timer &= GPIO_PAR_TIMER_T2IN_UNMASK;
203*a4145534SPeter Tyser 		break;
204*a4145534SPeter Tyser 	}
205*a4145534SPeter Tyser }
206*a4145534SPeter Tyser #endif
207