blob: 3f9209ff196ed8ff93887c84f33f9bfe3b84d05c [file] [log] [blame]
TsiChungLiew8ae158c2007-08-16 15:05:11 -05001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang198cafb2012-03-26 21:49:08 +00006 * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew8ae158c2007-08-16 15:05:11 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <watchdog.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050030#include <asm/immap.h>
TsiChung Liew68e4e762010-03-11 15:04:21 -060031#include <asm/processor.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050032#include <asm/rtc.h>
Alison Wang198cafb2012-03-26 21:49:08 +000033#include <asm/io.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050034
TsiChung Liewf3962d32008-10-21 13:47:54 +000035#if defined(CONFIG_CMD_NET)
36#include <config.h>
37#include <net.h>
38#include <asm/fec.h>
39#endif
40
TsiChungLiew8ae158c2007-08-16 15:05:11 -050041/*
42 * Breath some life into the CPU...
43 *
44 * Set up the memory map,
45 * initialize a bunch of registers,
46 * initialize the UPM's
47 */
48void cpu_init_f(void)
49{
Alison Wang198cafb2012-03-26 21:49:08 +000050 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
51 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
52 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050053
Alison Wang198cafb2012-03-26 21:49:08 +000054 out_be32(&scm1->mpr, 0x77777777);
55 out_be32(&scm1->pacra, 0);
56 out_be32(&scm1->pacrb, 0);
57 out_be32(&scm1->pacrc, 0);
58 out_be32(&scm1->pacrd, 0);
59 out_be32(&scm1->pacre, 0);
60 out_be32(&scm1->pacrf, 0);
61 out_be32(&scm1->pacrg, 0);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050062
63 /* FlexBus */
Alison Wang198cafb2012-03-26 21:49:08 +000064 out_8(&gpio->par_be,
65 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
66 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
67 out_8(&gpio->par_fbctl,
68 GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
69 GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050070
TsiChung Liew9f751552008-07-23 20:38:53 -050071#if !defined(CONFIG_CF_SBF)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
Alison Wang198cafb2012-03-26 21:49:08 +000073 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
74 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
75 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050076#endif
TsiChung Liew9f751552008-07-23 20:38:53 -050077#endif
TsiChungLiew8ae158c2007-08-16 15:05:11 -050078
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
TsiChungLiew8ae158c2007-08-16 15:05:11 -050080 /* Latch chipselect */
Alison Wang198cafb2012-03-26 21:49:08 +000081 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
82 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
83 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050084#endif
85
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020086#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
Alison Wang198cafb2012-03-26 21:49:08 +000087 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
88 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
89 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050090#endif
91
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
Alison Wang198cafb2012-03-26 21:49:08 +000093 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
94 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
95 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050096#endif
97
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wang198cafb2012-03-26 21:49:08 +000099 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
100 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
101 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500102#endif
103
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wang198cafb2012-03-26 21:49:08 +0000105 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
106 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
107 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500108#endif
109
TsiChung Liew68e4e762010-03-11 15:04:21 -0600110 /*
111 * now the flash base address is no longer at 0 (Newer ColdFire family
112 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
113 * also move to the new location.
114 */
115 if (CONFIG_SYS_CS0_BASE != 0)
116 setvbr(CONFIG_SYS_CS0_BASE);
117
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500118#ifdef CONFIG_FSL_I2C
Alison Wang198cafb2012-03-26 21:49:08 +0000119 out_be16(&gpio->par_feci2c,
120 GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500121#endif
122
123 icache_enable();
124}
125
126/*
127 * initialize higher level parts of CPU like timers
128 */
129int cpu_init_r(void)
130{
TsiChung Liewbc3ccb12008-07-09 15:47:27 -0500131#ifdef CONFIG_MCFRTC
Alison Wang198cafb2012-03-26 21:49:08 +0000132 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
133 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500134
Alison Wang198cafb2012-03-26 21:49:08 +0000135 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
136 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500137#endif
138
139 return (0);
140}
141
TsiChung Liew52affe02010-03-09 19:17:52 -0600142void uart_port_conf(int port)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500143{
Alison Wang198cafb2012-03-26 21:49:08 +0000144 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500145
146 /* Setup Ports: */
TsiChung Liew52affe02010-03-09 19:17:52 -0600147 switch (port) {
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500148 case 0:
Alison Wang198cafb2012-03-26 21:49:08 +0000149 clrbits_8(&gpio->par_uart,
150 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
151 setbits_8(&gpio->par_uart,
152 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500153 break;
154 case 1:
TsiChung Liew52affe02010-03-09 19:17:52 -0600155#ifdef CONFIG_SYS_UART1_PRI_GPIO
Alison Wang198cafb2012-03-26 21:49:08 +0000156 clrbits_8(&gpio->par_uart,
157 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
158 setbits_8(&gpio->par_uart,
159 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600160#elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
Alison Wang198cafb2012-03-26 21:49:08 +0000161 clrbits_be16(&gpio->par_ssi,
162 ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
163 setbits_be16(&gpio->par_ssi,
164 GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600165#endif
166 break;
167 case 2:
168#if defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wang198cafb2012-03-26 21:49:08 +0000169 clrbits_8(&gpio->par_timer,
170 ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
171 setbits_8(&gpio->par_timer,
172 GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600173#elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
Alison Wang198cafb2012-03-26 21:49:08 +0000174 clrbits_8(&gpio->par_timer,
175 ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
176 setbits_8(&gpio->par_timer,
177 GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600178#endif
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500179 break;
180 }
181}
TsiChung Liewf3962d32008-10-21 13:47:54 +0000182
183#if defined(CONFIG_CMD_NET)
184int fecpin_setclear(struct eth_device *dev, int setclear)
185{
Alison Wang198cafb2012-03-26 21:49:08 +0000186 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewf3962d32008-10-21 13:47:54 +0000187 struct fec_info_s *info = (struct fec_info_s *)dev->priv;
188
189 if (setclear) {
Wolfgang Wegnerae490992010-03-30 19:19:50 +0100190#ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
191 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
Alison Wang198cafb2012-03-26 21:49:08 +0000192 setbits_be16(&gpio->par_feci2c,
193 GPIO_PAR_FECI2C_MDC0_MDC0 |
194 GPIO_PAR_FECI2C_MDIO0_MDIO0);
Wolfgang Wegnerae490992010-03-30 19:19:50 +0100195 else
Alison Wang198cafb2012-03-26 21:49:08 +0000196 setbits_be16(&gpio->par_feci2c,
197 GPIO_PAR_FECI2C_MDC1_MDC1 |
198 GPIO_PAR_FECI2C_MDIO1_MDIO1);
Wolfgang Wegnerae490992010-03-30 19:19:50 +0100199#else
Alison Wang198cafb2012-03-26 21:49:08 +0000200 setbits_be16(&gpio->par_feci2c,
201 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
Wolfgang Wegnerae490992010-03-30 19:19:50 +0100202#endif
TsiChung Liewf3962d32008-10-21 13:47:54 +0000203
204 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
Alison Wang198cafb2012-03-26 21:49:08 +0000205 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
TsiChung Liewf3962d32008-10-21 13:47:54 +0000206 else
Alison Wang198cafb2012-03-26 21:49:08 +0000207 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
TsiChung Liewf3962d32008-10-21 13:47:54 +0000208 } else {
Alison Wang198cafb2012-03-26 21:49:08 +0000209 clrbits_be16(&gpio->par_feci2c,
210 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
TsiChung Liewf3962d32008-10-21 13:47:54 +0000211
Wolfgang Wegneradf55672010-03-30 19:19:51 +0100212 if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
213#ifdef CONFIG_SYS_FEC_FULL_MII
Alison Wang198cafb2012-03-26 21:49:08 +0000214 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
Wolfgang Wegneradf55672010-03-30 19:19:51 +0100215#else
Alison Wang198cafb2012-03-26 21:49:08 +0000216 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
Wolfgang Wegneradf55672010-03-30 19:19:51 +0100217#endif
218 } else {
219#ifdef CONFIG_SYS_FEC_FULL_MII
Alison Wang198cafb2012-03-26 21:49:08 +0000220 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
Wolfgang Wegneradf55672010-03-30 19:19:51 +0100221#else
Alison Wang198cafb2012-03-26 21:49:08 +0000222 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
Wolfgang Wegneradf55672010-03-30 19:19:51 +0100223#endif
224 }
TsiChung Liewf3962d32008-10-21 13:47:54 +0000225 }
226 return 0;
227}
228#endif
TsiChung Liewee0a8462009-06-30 14:18:29 +0000229
230#ifdef CONFIG_CF_DSPI
231void cfspi_port_conf(void)
232{
Alison Wang198cafb2012-03-26 21:49:08 +0000233 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000234
Alison Wang198cafb2012-03-26 21:49:08 +0000235 out_8(&gpio->par_dspi,
236 GPIO_PAR_DSPI_SIN_SIN |
237 GPIO_PAR_DSPI_SOUT_SOUT |
238 GPIO_PAR_DSPI_SCK_SCK);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000239}
240
241int cfspi_claim_bus(uint bus, uint cs)
242{
Alison Wang198cafb2012-03-26 21:49:08 +0000243 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
244 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000245
Alison Wang198cafb2012-03-26 21:49:08 +0000246 if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
TsiChung Liewee0a8462009-06-30 14:18:29 +0000247 return -1;
248
249 /* Clear FIFO and resume transfer */
Alison Wang198cafb2012-03-26 21:49:08 +0000250 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000251
252 switch (cs) {
253 case 0:
Alison Wang198cafb2012-03-26 21:49:08 +0000254 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
255 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000256 break;
257 case 1:
Alison Wang198cafb2012-03-26 21:49:08 +0000258 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
259 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000260 break;
261 case 2:
Alison Wang198cafb2012-03-26 21:49:08 +0000262 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
263 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000264 break;
Wolfgang Wegnere9b43ca2010-03-30 19:20:31 +0100265 case 3:
Alison Wang198cafb2012-03-26 21:49:08 +0000266 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
267 setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
Wolfgang Wegnere9b43ca2010-03-30 19:20:31 +0100268 break;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000269 case 5:
Alison Wang198cafb2012-03-26 21:49:08 +0000270 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
271 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000272 break;
273 }
274
275 return 0;
276}
277
278void cfspi_release_bus(uint bus, uint cs)
279{
Alison Wang198cafb2012-03-26 21:49:08 +0000280 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
281 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000282
Alison Wang198cafb2012-03-26 21:49:08 +0000283 /* Clear FIFO */
284 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000285
286 switch (cs) {
287 case 0:
Alison Wang198cafb2012-03-26 21:49:08 +0000288 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000289 break;
290 case 1:
Alison Wang198cafb2012-03-26 21:49:08 +0000291 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000292 break;
293 case 2:
Alison Wang198cafb2012-03-26 21:49:08 +0000294 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000295 break;
Wolfgang Wegnere9b43ca2010-03-30 19:20:31 +0100296 case 3:
Alison Wang198cafb2012-03-26 21:49:08 +0000297 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
Wolfgang Wegnere9b43ca2010-03-30 19:20:31 +0100298 break;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000299 case 5:
Alison Wang198cafb2012-03-26 21:49:08 +0000300 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000301 break;
302 }
303}
304#endif