xref: /openbmc/u-boot/arch/m68k/cpu/mcf5445x/cpu_init.c (revision 198cafbf2cab9851ee5dd8d24d268d0ccc0fe3bd)
1a4145534SPeter Tyser /*
2a4145534SPeter Tyser  *
3a4145534SPeter Tyser  * (C) Copyright 2000-2003
4a4145534SPeter Tyser  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5a4145534SPeter Tyser  *
6*198cafbfSAlison Wang  * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
7a4145534SPeter Tyser  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8a4145534SPeter Tyser  *
9a4145534SPeter Tyser  * See file CREDITS for list of people who contributed to this
10a4145534SPeter Tyser  * project.
11a4145534SPeter Tyser  *
12a4145534SPeter Tyser  * This program is free software; you can redistribute it and/or
13a4145534SPeter Tyser  * modify it under the terms of the GNU General Public License as
14a4145534SPeter Tyser  * published by the Free Software Foundation; either version 2 of
15a4145534SPeter Tyser  * the License, or (at your option) any later version.
16a4145534SPeter Tyser  *
17a4145534SPeter Tyser  * This program is distributed in the hope that it will be useful,
18a4145534SPeter Tyser  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19a4145534SPeter Tyser  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20a4145534SPeter Tyser  * GNU General Public License for more details.
21a4145534SPeter Tyser  *
22a4145534SPeter Tyser  * You should have received a copy of the GNU General Public License
23a4145534SPeter Tyser  * along with this program; if not, write to the Free Software
24a4145534SPeter Tyser  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25a4145534SPeter Tyser  * MA 02111-1307 USA
26a4145534SPeter Tyser  */
27a4145534SPeter Tyser 
28a4145534SPeter Tyser #include <common.h>
29a4145534SPeter Tyser #include <watchdog.h>
30a4145534SPeter Tyser #include <asm/immap.h>
31a4145534SPeter Tyser #include <asm/processor.h>
32a4145534SPeter Tyser #include <asm/rtc.h>
33*198cafbfSAlison Wang #include <asm/io.h>
34a4145534SPeter Tyser 
35a4145534SPeter Tyser #if defined(CONFIG_CMD_NET)
36a4145534SPeter Tyser #include <config.h>
37a4145534SPeter Tyser #include <net.h>
38a4145534SPeter Tyser #include <asm/fec.h>
39a4145534SPeter Tyser #endif
40a4145534SPeter Tyser 
41a4145534SPeter Tyser /*
42a4145534SPeter Tyser  * Breath some life into the CPU...
43a4145534SPeter Tyser  *
44a4145534SPeter Tyser  * Set up the memory map,
45a4145534SPeter Tyser  * initialize a bunch of registers,
46a4145534SPeter Tyser  * initialize the UPM's
47a4145534SPeter Tyser  */
48a4145534SPeter Tyser void cpu_init_f(void)
49a4145534SPeter Tyser {
50*198cafbfSAlison Wang 	scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
51*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
52*198cafbfSAlison Wang 	fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
53a4145534SPeter Tyser 
54*198cafbfSAlison Wang 	out_be32(&scm1->mpr, 0x77777777);
55*198cafbfSAlison Wang 	out_be32(&scm1->pacra, 0);
56*198cafbfSAlison Wang 	out_be32(&scm1->pacrb, 0);
57*198cafbfSAlison Wang 	out_be32(&scm1->pacrc, 0);
58*198cafbfSAlison Wang 	out_be32(&scm1->pacrd, 0);
59*198cafbfSAlison Wang 	out_be32(&scm1->pacre, 0);
60*198cafbfSAlison Wang 	out_be32(&scm1->pacrf, 0);
61*198cafbfSAlison Wang 	out_be32(&scm1->pacrg, 0);
62a4145534SPeter Tyser 
63a4145534SPeter Tyser 	/* FlexBus */
64*198cafbfSAlison Wang 	out_8(&gpio->par_be,
65*198cafbfSAlison Wang 		GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
66*198cafbfSAlison Wang 		GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
67*198cafbfSAlison Wang 	out_8(&gpio->par_fbctl,
68*198cafbfSAlison Wang 		GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
69*198cafbfSAlison Wang 		GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
70a4145534SPeter Tyser 
71a4145534SPeter Tyser #if !defined(CONFIG_CF_SBF)
72a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
73*198cafbfSAlison Wang 	out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
74*198cafbfSAlison Wang 	out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
75*198cafbfSAlison Wang 	out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
76a4145534SPeter Tyser #endif
77a4145534SPeter Tyser #endif
78a4145534SPeter Tyser 
79a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
80a4145534SPeter Tyser 	/* Latch chipselect */
81*198cafbfSAlison Wang 	out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
82*198cafbfSAlison Wang 	out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
83*198cafbfSAlison Wang 	out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
84a4145534SPeter Tyser #endif
85a4145534SPeter Tyser 
86a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
87*198cafbfSAlison Wang 	out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
88*198cafbfSAlison Wang 	out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
89*198cafbfSAlison Wang 	out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
90a4145534SPeter Tyser #endif
91a4145534SPeter Tyser 
92a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
93*198cafbfSAlison Wang 	out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
94*198cafbfSAlison Wang 	out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
95*198cafbfSAlison Wang 	out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
96a4145534SPeter Tyser #endif
97a4145534SPeter Tyser 
98a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
99*198cafbfSAlison Wang 	out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
100*198cafbfSAlison Wang 	out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
101*198cafbfSAlison Wang 	out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
102a4145534SPeter Tyser #endif
103a4145534SPeter Tyser 
104a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
105*198cafbfSAlison Wang 	out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
106*198cafbfSAlison Wang 	out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
107*198cafbfSAlison Wang 	out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
108a4145534SPeter Tyser #endif
109a4145534SPeter Tyser 
110a4145534SPeter Tyser 	/*
111a4145534SPeter Tyser 	 * now the flash base address is no longer at 0 (Newer ColdFire family
112a4145534SPeter Tyser 	 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
113a4145534SPeter Tyser 	 * also move to the new location.
114a4145534SPeter Tyser 	 */
115a4145534SPeter Tyser 	if (CONFIG_SYS_CS0_BASE != 0)
116a4145534SPeter Tyser 		setvbr(CONFIG_SYS_CS0_BASE);
117a4145534SPeter Tyser 
118a4145534SPeter Tyser #ifdef CONFIG_FSL_I2C
119*198cafbfSAlison Wang 	out_be16(&gpio->par_feci2c,
120*198cafbfSAlison Wang 		GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
121a4145534SPeter Tyser #endif
122a4145534SPeter Tyser 
123a4145534SPeter Tyser 	icache_enable();
124a4145534SPeter Tyser }
125a4145534SPeter Tyser 
126a4145534SPeter Tyser /*
127a4145534SPeter Tyser  * initialize higher level parts of CPU like timers
128a4145534SPeter Tyser  */
129a4145534SPeter Tyser int cpu_init_r(void)
130a4145534SPeter Tyser {
131a4145534SPeter Tyser #ifdef CONFIG_MCFRTC
132*198cafbfSAlison Wang 	rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
133*198cafbfSAlison Wang 	rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
134a4145534SPeter Tyser 
135*198cafbfSAlison Wang 	out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
136*198cafbfSAlison Wang 	out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
137a4145534SPeter Tyser #endif
138a4145534SPeter Tyser 
139a4145534SPeter Tyser 	return (0);
140a4145534SPeter Tyser }
141a4145534SPeter Tyser 
142a4145534SPeter Tyser void uart_port_conf(int port)
143a4145534SPeter Tyser {
144*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
145a4145534SPeter Tyser 
146a4145534SPeter Tyser 	/* Setup Ports: */
147a4145534SPeter Tyser 	switch (port) {
148a4145534SPeter Tyser 	case 0:
149*198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
150*198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
151*198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
152*198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
153a4145534SPeter Tyser 		break;
154a4145534SPeter Tyser 	case 1:
155a4145534SPeter Tyser #ifdef CONFIG_SYS_UART1_PRI_GPIO
156*198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
157*198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
158*198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
159*198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
160a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
161*198cafbfSAlison Wang 		clrbits_be16(&gpio->par_ssi,
162*198cafbfSAlison Wang 			~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
163*198cafbfSAlison Wang 		setbits_be16(&gpio->par_ssi,
164*198cafbfSAlison Wang 			GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
165a4145534SPeter Tyser #endif
166a4145534SPeter Tyser 		break;
167a4145534SPeter Tyser 	case 2:
168a4145534SPeter Tyser #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
169*198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
170*198cafbfSAlison Wang 			~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
171*198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
172*198cafbfSAlison Wang 			GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
173a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
174*198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
175*198cafbfSAlison Wang 			~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
176*198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
177*198cafbfSAlison Wang 			GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
178a4145534SPeter Tyser #endif
179a4145534SPeter Tyser 		break;
180a4145534SPeter Tyser 	}
181a4145534SPeter Tyser }
182a4145534SPeter Tyser 
183a4145534SPeter Tyser #if defined(CONFIG_CMD_NET)
184a4145534SPeter Tyser int fecpin_setclear(struct eth_device *dev, int setclear)
185a4145534SPeter Tyser {
186*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
187a4145534SPeter Tyser 	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
188a4145534SPeter Tyser 
189a4145534SPeter Tyser 	if (setclear) {
190ae490997SWolfgang Wegner #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
191ae490997SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
192*198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
193*198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC0_MDC0 |
194ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO0_MDIO0);
195ae490997SWolfgang Wegner 		else
196*198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
197*198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC1_MDC1 |
198ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO1_MDIO1);
199ae490997SWolfgang Wegner #else
200*198cafbfSAlison Wang 		setbits_be16(&gpio->par_feci2c,
201*198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
202ae490997SWolfgang Wegner #endif
203a4145534SPeter Tyser 
204a4145534SPeter Tyser 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
205*198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
206a4145534SPeter Tyser 		else
207*198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
208a4145534SPeter Tyser 	} else {
209*198cafbfSAlison Wang 		clrbits_be16(&gpio->par_feci2c,
210*198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
211a4145534SPeter Tyser 
212adf55679SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
213adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
214*198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
215adf55679SWolfgang Wegner #else
216*198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
217adf55679SWolfgang Wegner #endif
218adf55679SWolfgang Wegner 		} else {
219adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
220*198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
221adf55679SWolfgang Wegner #else
222*198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
223adf55679SWolfgang Wegner #endif
224adf55679SWolfgang Wegner 		}
225a4145534SPeter Tyser 	}
226a4145534SPeter Tyser 	return 0;
227a4145534SPeter Tyser }
228a4145534SPeter Tyser #endif
229a4145534SPeter Tyser 
230a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI
231a4145534SPeter Tyser void cfspi_port_conf(void)
232a4145534SPeter Tyser {
233*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
234a4145534SPeter Tyser 
235*198cafbfSAlison Wang 	out_8(&gpio->par_dspi,
236*198cafbfSAlison Wang 		GPIO_PAR_DSPI_SIN_SIN |
237*198cafbfSAlison Wang 		GPIO_PAR_DSPI_SOUT_SOUT |
238*198cafbfSAlison Wang 		GPIO_PAR_DSPI_SCK_SCK);
239a4145534SPeter Tyser }
240a4145534SPeter Tyser 
241a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs)
242a4145534SPeter Tyser {
243*198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
244*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
245a4145534SPeter Tyser 
246*198cafbfSAlison Wang 	if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
247a4145534SPeter Tyser 		return -1;
248a4145534SPeter Tyser 
249a4145534SPeter Tyser 	/* Clear FIFO and resume transfer */
250*198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
251a4145534SPeter Tyser 
252a4145534SPeter Tyser 	switch (cs) {
253a4145534SPeter Tyser 	case 0:
254*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
255*198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
256a4145534SPeter Tyser 		break;
257a4145534SPeter Tyser 	case 1:
258*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
259*198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
260a4145534SPeter Tyser 		break;
261a4145534SPeter Tyser 	case 2:
262*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
263*198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
264a4145534SPeter Tyser 		break;
265e9b43caeSWolfgang Wegner 	case 3:
266*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
267*198cafbfSAlison Wang 		setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
268e9b43caeSWolfgang Wegner 		break;
269a4145534SPeter Tyser 	case 5:
270*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
271*198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
272a4145534SPeter Tyser 		break;
273a4145534SPeter Tyser 	}
274a4145534SPeter Tyser 
275a4145534SPeter Tyser 	return 0;
276a4145534SPeter Tyser }
277a4145534SPeter Tyser 
278a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs)
279a4145534SPeter Tyser {
280*198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
281*198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
282a4145534SPeter Tyser 
283*198cafbfSAlison Wang 	/* Clear FIFO */
284*198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
285a4145534SPeter Tyser 
286a4145534SPeter Tyser 	switch (cs) {
287a4145534SPeter Tyser 	case 0:
288*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
289a4145534SPeter Tyser 		break;
290a4145534SPeter Tyser 	case 1:
291*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
292a4145534SPeter Tyser 		break;
293a4145534SPeter Tyser 	case 2:
294*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
295a4145534SPeter Tyser 		break;
296e9b43caeSWolfgang Wegner 	case 3:
297*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
298e9b43caeSWolfgang Wegner 		break;
299a4145534SPeter Tyser 	case 5:
300*198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
301a4145534SPeter Tyser 		break;
302a4145534SPeter Tyser 	}
303a4145534SPeter Tyser }
304a4145534SPeter Tyser #endif
305