blob: 00e0ca6da92892d9abbc3fa11bb22979e711a233 [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 *
6 * (C) Copyright 2004-2007 Freescale Semiconductor, Inc.
7 * 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>
31#include <asm/rtc.h>
32
TsiChung Liewf3962d32008-10-21 13:47:54 +000033#if defined(CONFIG_CMD_NET)
34#include <config.h>
35#include <net.h>
36#include <asm/fec.h>
37#endif
38
TsiChungLiew8ae158c2007-08-16 15:05:11 -050039/*
40 * Breath some life into the CPU...
41 *
42 * Set up the memory map,
43 * initialize a bunch of registers,
44 * initialize the UPM's
45 */
46void cpu_init_f(void)
47{
48 volatile scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
49 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
50 volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
51
52 scm1->mpr = 0x77777777;
53 scm1->pacra = 0;
54 scm1->pacrb = 0;
55 scm1->pacrc = 0;
56 scm1->pacrd = 0;
57 scm1->pacre = 0;
58 scm1->pacrf = 0;
59 scm1->pacrg = 0;
60
61 /* FlexBus */
62 gpio->par_be =
63 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 | GPIO_PAR_BE_BE1_BE1 |
64 GPIO_PAR_BE_BE0_BE0;
65 gpio->par_fbctl =
66 GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA | GPIO_PAR_FBCTL_RW_RW |
67 GPIO_PAR_FBCTL_TS_TS;
68
TsiChung Liew9f751552008-07-23 20:38:53 -050069#if !defined(CONFIG_CF_SBF)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020070#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
71 fbcs->csar0 = CONFIG_SYS_CS0_BASE;
72 fbcs->cscr0 = CONFIG_SYS_CS0_CTRL;
73 fbcs->csmr0 = CONFIG_SYS_CS0_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050074#endif
TsiChung Liew9f751552008-07-23 20:38:53 -050075#endif
TsiChungLiew8ae158c2007-08-16 15:05:11 -050076
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020077#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
TsiChungLiew8ae158c2007-08-16 15:05:11 -050078 /* Latch chipselect */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079 fbcs->csar1 = CONFIG_SYS_CS1_BASE;
80 fbcs->cscr1 = CONFIG_SYS_CS1_CTRL;
81 fbcs->csmr1 = CONFIG_SYS_CS1_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050082#endif
83
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
85 fbcs->csar2 = CONFIG_SYS_CS2_BASE;
86 fbcs->cscr2 = CONFIG_SYS_CS2_CTRL;
87 fbcs->csmr2 = CONFIG_SYS_CS2_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050088#endif
89
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
91 fbcs->csar3 = CONFIG_SYS_CS3_BASE;
92 fbcs->cscr3 = CONFIG_SYS_CS3_CTRL;
93 fbcs->csmr3 = CONFIG_SYS_CS3_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050094#endif
95
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
97 fbcs->csar4 = CONFIG_SYS_CS4_BASE;
98 fbcs->cscr4 = CONFIG_SYS_CS4_CTRL;
99 fbcs->csmr4 = CONFIG_SYS_CS4_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500100#endif
101
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
103 fbcs->csar5 = CONFIG_SYS_CS5_BASE;
104 fbcs->cscr5 = CONFIG_SYS_CS5_CTRL;
105 fbcs->csmr5 = CONFIG_SYS_CS5_MASK;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500106#endif
107
108#ifdef CONFIG_FSL_I2C
109 gpio->par_feci2c = GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA;
110#endif
111
112 icache_enable();
113}
114
115/*
116 * initialize higher level parts of CPU like timers
117 */
118int cpu_init_r(void)
119{
TsiChung Liewbc3ccb12008-07-09 15:47:27 -0500120#ifdef CONFIG_MCFRTC
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200121 volatile rtc_t *rtc = (volatile rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500122 volatile rtcex_t *rtcex = (volatile rtcex_t *)&rtc->extended;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500123
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200124 rtcex->gocu = (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xFFFF;
125 rtcex->gocl = CONFIG_SYS_RTC_OSCILLATOR & 0xFFFF;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500126#endif
127
128 return (0);
129}
130
TsiChung Liew52affe02010-03-09 19:17:52 -0600131void uart_port_conf(int port)
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500132{
133 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
134
135 /* Setup Ports: */
TsiChung Liew52affe02010-03-09 19:17:52 -0600136 switch (port) {
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500137 case 0:
TsiChung Liew52affe02010-03-09 19:17:52 -0600138 gpio->par_uart &=
139 ~(GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
140 gpio->par_uart |=
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500141 (GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
142 break;
143 case 1:
TsiChung Liew52affe02010-03-09 19:17:52 -0600144#ifdef CONFIG_SYS_UART1_PRI_GPIO
145 gpio->par_uart &=
146 ~(GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
147 gpio->par_uart |=
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500148 (GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600149#elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
150 gpio->par_ssi &=
151 (GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK);
152 gpio->par_ssi |=
153 (GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
154#endif
155 break;
156 case 2:
157#if defined(CONFIG_SYS_UART2_ALT1_GPIO)
158 gpio->par_timer &=
159 (GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK);
160 gpio->par_timer |=
161 (GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
162#elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
163 gpio->par_timer &=
164 (GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK);
165 gpio->par_timer |=
166 (GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
167#endif
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500168 break;
169 }
170}
TsiChung Liewf3962d32008-10-21 13:47:54 +0000171
172#if defined(CONFIG_CMD_NET)
173int fecpin_setclear(struct eth_device *dev, int setclear)
174{
175 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
176 struct fec_info_s *info = (struct fec_info_s *)dev->priv;
177
178 if (setclear) {
179 gpio->par_feci2c |=
180 (GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
181
182 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
183 gpio->par_fec |= GPIO_PAR_FEC_FEC0_RMII_GPIO;
184 else
185 gpio->par_fec |= GPIO_PAR_FEC_FEC1_RMII_ATA;
186 } else {
187 gpio->par_feci2c &=
188 ~(GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
189
190 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
TsiChung Liewd04c1ef2010-03-09 18:32:16 -0600191 gpio->par_fec &= GPIO_PAR_FEC_FEC0_UNMASK;
TsiChung Liewf3962d32008-10-21 13:47:54 +0000192 else
TsiChung Liewd04c1ef2010-03-09 18:32:16 -0600193 gpio->par_fec &= GPIO_PAR_FEC_FEC1_UNMASK;
TsiChung Liewf3962d32008-10-21 13:47:54 +0000194 }
195 return 0;
196}
197#endif
TsiChung Liewee0a8462009-06-30 14:18:29 +0000198
199#ifdef CONFIG_CF_DSPI
200void cfspi_port_conf(void)
201{
202 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
203
204 gpio->par_dspi = GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
205 GPIO_PAR_DSPI_SCK_SCK;
206}
207
208int cfspi_claim_bus(uint bus, uint cs)
209{
210 volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
211 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
212
213 if ((dspi->sr & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
214 return -1;
215
216 /* Clear FIFO and resume transfer */
217 dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF);
218
219 switch (cs) {
220 case 0:
221 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
222 gpio->par_dspi |= GPIO_PAR_DSPI_PCS0_PCS0;
223 break;
224 case 1:
225 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
226 gpio->par_dspi |= GPIO_PAR_DSPI_PCS1_PCS1;
227 break;
228 case 2:
229 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
230 gpio->par_dspi |= GPIO_PAR_DSPI_PCS2_PCS2;
231 break;
232 case 5:
233 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
234 gpio->par_dspi |= GPIO_PAR_DSPI_PCS5_PCS5;
235 break;
236 }
237
238 return 0;
239}
240
241void cfspi_release_bus(uint bus, uint cs)
242{
243 volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
244 volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
245
246 dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF); /* Clear FIFO */
247
248 switch (cs) {
249 case 0:
250 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
251 break;
252 case 1:
253 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
254 break;
255 case 2:
256 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
257 break;
258 case 5:
259 gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
260 break;
261 }
262}
263#endif