blob: 5d2b116be1d9f2477787ff0f0ce8013fd6396457 [file] [log] [blame]
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -05001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang8d8dac92012-03-26 21:49:08 +00006 * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050010 */
11
12#include <common.h>
13#include <watchdog.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050014#include <asm/immap.h>
TsiChung Liew4d5414d2010-03-11 15:04:21 -060015#include <asm/processor.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050016#include <asm/rtc.h>
Alison Wang8d8dac92012-03-26 21:49:08 +000017#include <asm/io.h>
Marek Vasuta334ec92012-10-03 13:28:44 +000018#include <linux/compiler.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050019
TsiChung Liew69b17572008-10-21 13:47:54 +000020#if defined(CONFIG_CMD_NET)
21#include <config.h>
22#include <net.h>
23#include <asm/fec.h>
24#endif
25
Alison Wangfdc2fb12012-10-18 19:25:51 +000026void init_fbcs(void)
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050027{
Marek Vasuta334ec92012-10-03 13:28:44 +000028 fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050029
Alison Wangfdc2fb12012-10-18 19:25:51 +000030#if !defined(CONFIG_SERIAL_BOOT)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020031#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
Alison Wang8d8dac92012-03-26 21:49:08 +000032 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
33 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
34 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050035#endif
TsiChung Liew23cf8fd2008-07-23 20:38:53 -050036#endif
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050037
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020038#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050039 /* Latch chipselect */
Alison Wang8d8dac92012-03-26 21:49:08 +000040 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
41 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
42 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050043#endif
44
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
Alison Wang8d8dac92012-03-26 21:49:08 +000046 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
47 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
48 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050049#endif
50
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
Alison Wang8d8dac92012-03-26 21:49:08 +000052 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
53 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
54 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050055#endif
56
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wang8d8dac92012-03-26 21:49:08 +000058 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
59 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
60 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050061#endif
62
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wang8d8dac92012-03-26 21:49:08 +000064 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
65 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
66 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050067#endif
Alison Wangfdc2fb12012-10-18 19:25:51 +000068}
69
70/*
71 * Breath some life into the CPU...
72 *
73 * Set up the memory map,
74 * initialize a bunch of registers,
75 * initialize the UPM's
76 */
77void cpu_init_f(void)
78{
79 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
80
81#ifdef CONFIG_MCF5441x
82 scm_t *scm = (scm_t *) MMAP_SCM;
83 pm_t *pm = (pm_t *) MMAP_PM;
84
85 /* Disable Switch */
86 *(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0;
87
88 /* Disable core watchdog */
89 out_be16(&scm->cwcr, 0);
90 out_8(&gpio->par_fbctl,
91 GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE |
92 GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW |
93 GPIO_PAR_FBCTL_TA_TA);
94 out_8(&gpio->par_be,
95 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
96 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
97
98 /* eDMA */
99 out_8(&pm->pmcr0, 17);
100
101 /* INTR0 - INTR2 */
102 out_8(&pm->pmcr0, 18);
103 out_8(&pm->pmcr0, 19);
104 out_8(&pm->pmcr0, 20);
105
106 /* I2C */
107 out_8(&pm->pmcr0, 22);
108 out_8(&pm->pmcr1, 4);
109 out_8(&pm->pmcr1, 7);
110
111 /* DTMR0 - DTMR3*/
112 out_8(&pm->pmcr0, 28);
113 out_8(&pm->pmcr0, 29);
114 out_8(&pm->pmcr0, 30);
115 out_8(&pm->pmcr0, 31);
116
117 /* PIT0 - PIT3 */
118 out_8(&pm->pmcr0, 32);
119 out_8(&pm->pmcr0, 33);
120 out_8(&pm->pmcr0, 34);
121 out_8(&pm->pmcr0, 35);
122
123 /* Edge Port */
124 out_8(&pm->pmcr0, 36);
125 out_8(&pm->pmcr0, 37);
126
127 /* USB OTG */
128 out_8(&pm->pmcr0, 44);
129 /* USB Host */
130 out_8(&pm->pmcr0, 45);
131
132 /* ESDHC */
133 out_8(&pm->pmcr0, 51);
134
135 /* ENET0 - ENET1 */
136 out_8(&pm->pmcr0, 53);
137 out_8(&pm->pmcr0, 54);
138
139 /* NAND */
140 out_8(&pm->pmcr0, 63);
141
142#ifdef CONFIG_SYS_I2C_0
143 out_8(&gpio->par_cani2c, 0xF0);
144 /* I2C0 pull up */
145 out_be16(&gpio->pcr_b, 0x003C);
146 /* I2C0 max speed */
147 out_8(&gpio->srcr_cani2c, 0x03);
148#endif
149#ifdef CONFIG_SYS_I2C_2
150 /* I2C2 */
151 out_8(&gpio->par_ssi0h, 0xA0);
152 /* I2C2, UART7 */
153 out_8(&gpio->par_ssi0h, 0xA8);
154 /* UART7 */
155 out_8(&gpio->par_ssi0l, 0x2);
156 /* UART8, UART9 */
157 out_8(&gpio->par_cani2c, 0xAA);
158 /* UART4, UART0 */
159 out_8(&gpio->par_uart0, 0xAF);
160 /* UART5, UART1 */
161 out_8(&gpio->par_uart1, 0xAF);
162 /* UART6, UART2 */
163 out_8(&gpio->par_uart2, 0xAF);
164 /* I2C2 pull up */
165 out_be16(&gpio->pcr_h, 0xF000);
166#endif
167#ifdef CONFIG_SYS_I2C_5
168 /* I2C5 */
169 out_8(&gpio->par_uart1, 0x0A);
170 /* I2C5 pull up */
171 out_be16(&gpio->pcr_e, 0x0003);
172 out_be16(&gpio->pcr_f, 0xC000);
173#endif
174
175 /* Lowest slew rate for UART0,1,2 */
176 out_8(&gpio->srcr_uart, 0x00);
177#endif /* CONFIG_MCF5441x */
178
179#ifdef CONFIG_MCF5445x
180 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
181
182 out_be32(&scm1->mpr, 0x77777777);
183 out_be32(&scm1->pacra, 0);
184 out_be32(&scm1->pacrb, 0);
185 out_be32(&scm1->pacrc, 0);
186 out_be32(&scm1->pacrd, 0);
187 out_be32(&scm1->pacre, 0);
188 out_be32(&scm1->pacrf, 0);
189 out_be32(&scm1->pacrg, 0);
190
191 /* FlexBus */
192 out_8(&gpio->par_be,
193 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
194 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
195 out_8(&gpio->par_fbctl,
196 GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
197 GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
198
Heiko Schocherf2850742012-10-24 13:48:22 +0200199#ifdef CONFIG_SYS_FSL_I2C
Alison Wangfdc2fb12012-10-18 19:25:51 +0000200 out_be16(&gpio->par_feci2c,
201 GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
202#endif
203#endif /* CONFIG_MCF5445x */
204
205 /* FlexBus Chipselect */
206 init_fbcs();
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500207
Angelo Dureghello7211b922017-05-15 00:17:48 +0200208#ifdef CONFIG_SYS_CS0_BASE
TsiChung Liew4d5414d2010-03-11 15:04:21 -0600209 /*
210 * now the flash base address is no longer at 0 (Newer ColdFire family
211 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
212 * also move to the new location.
213 */
214 if (CONFIG_SYS_CS0_BASE != 0)
215 setvbr(CONFIG_SYS_CS0_BASE);
Angelo Dureghello7211b922017-05-15 00:17:48 +0200216#endif
TsiChung Liew4d5414d2010-03-11 15:04:21 -0600217
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500218 icache_enable();
219}
220
221/*
222 * initialize higher level parts of CPU like timers
223 */
224int cpu_init_r(void)
225{
TsiChung Liew1be9e092008-07-09 15:47:27 -0500226#ifdef CONFIG_MCFRTC
Alison Wang8d8dac92012-03-26 21:49:08 +0000227 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
228 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500229
Alison Wang8d8dac92012-03-26 21:49:08 +0000230 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
231 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500232#endif
233
234 return (0);
235}
236
TsiChung Liewf9556a72010-03-09 19:17:52 -0600237void uart_port_conf(int port)
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500238{
Alison Wang8d8dac92012-03-26 21:49:08 +0000239 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
Alison Wangfdc2fb12012-10-18 19:25:51 +0000240#ifdef CONFIG_MCF5441x
241 pm_t *pm = (pm_t *) MMAP_PM;
242#endif
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500243
244 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600245 switch (port) {
Alison Wangfdc2fb12012-10-18 19:25:51 +0000246#ifdef CONFIG_MCF5441x
247 case 0:
248 /* UART0 */
249 out_8(&pm->pmcr0, 24);
250 clrbits_8(&gpio->par_uart0,
251 ~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
252 setbits_8(&gpio->par_uart0,
253 GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
254 break;
255 case 1:
256 /* UART1 */
257 out_8(&pm->pmcr0, 25);
258 clrbits_8(&gpio->par_uart1,
259 ~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
260 setbits_8(&gpio->par_uart1,
261 GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
262 break;
263 case 2:
264 /* UART2 */
265 out_8(&pm->pmcr0, 26);
266 clrbits_8(&gpio->par_uart2,
267 ~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
268 setbits_8(&gpio->par_uart2,
269 GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
270 break;
271 case 3:
272 /* UART3 */
273 out_8(&pm->pmcr0, 27);
274 clrbits_8(&gpio->par_dspi0,
275 ~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
276 setbits_8(&gpio->par_dspi0,
277 GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
278 break;
279 case 4:
280 /* UART4 */
281 out_8(&pm->pmcr1, 24);
282 clrbits_8(&gpio->par_uart0,
283 ~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
284 setbits_8(&gpio->par_uart0,
285 GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
286 break;
287 case 5:
288 /* UART5 */
289 out_8(&pm->pmcr1, 25);
290 clrbits_8(&gpio->par_uart1,
291 ~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
292 setbits_8(&gpio->par_uart1,
293 GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
294 break;
295 case 6:
296 /* UART6 */
297 out_8(&pm->pmcr1, 26);
298 clrbits_8(&gpio->par_uart2,
299 ~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
300 setbits_8(&gpio->par_uart2,
301 GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
302 break;
303 case 7:
304 /* UART7 */
305 out_8(&pm->pmcr1, 27);
306 clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
307 clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
308 setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
309 setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
310 break;
311 case 8:
312 /* UART8 */
313 out_8(&pm->pmcr0, 28);
314 clrbits_8(&gpio->par_cani2c,
315 ~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
316 setbits_8(&gpio->par_cani2c,
317 GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
318 break;
319 case 9:
320 /* UART9 */
321 out_8(&pm->pmcr1, 29);
322 clrbits_8(&gpio->par_cani2c,
323 ~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
324 setbits_8(&gpio->par_cani2c,
325 GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
326 break;
327#endif
328#ifdef CONFIG_MCF5445x
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500329 case 0:
Alison Wang8d8dac92012-03-26 21:49:08 +0000330 clrbits_8(&gpio->par_uart,
331 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
332 setbits_8(&gpio->par_uart,
333 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500334 break;
335 case 1:
TsiChung Liewf9556a72010-03-09 19:17:52 -0600336#ifdef CONFIG_SYS_UART1_PRI_GPIO
Alison Wang8d8dac92012-03-26 21:49:08 +0000337 clrbits_8(&gpio->par_uart,
338 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
339 setbits_8(&gpio->par_uart,
340 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600341#elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
Alison Wang8d8dac92012-03-26 21:49:08 +0000342 clrbits_be16(&gpio->par_ssi,
343 ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
344 setbits_be16(&gpio->par_ssi,
345 GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600346#endif
347 break;
348 case 2:
349#if defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wang8d8dac92012-03-26 21:49:08 +0000350 clrbits_8(&gpio->par_timer,
351 ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
352 setbits_8(&gpio->par_timer,
353 GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600354#elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
Alison Wang8d8dac92012-03-26 21:49:08 +0000355 clrbits_8(&gpio->par_timer,
356 ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
357 setbits_8(&gpio->par_timer,
358 GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600359#endif
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500360 break;
Alison Wangfdc2fb12012-10-18 19:25:51 +0000361#endif /* CONFIG_MCF5445x */
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500362 }
TsiChung Liew69b17572008-10-21 13:47:54 +0000363}
364
365#if defined(CONFIG_CMD_NET)
366int fecpin_setclear(struct eth_device *dev, int setclear)
367{
Alison Wang8d8dac92012-03-26 21:49:08 +0000368 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
Masahiro Yamada35b2eb72013-10-16 13:53:04 +0900369#ifdef CONFIG_MCF5445x
TsiChung Liew69b17572008-10-21 13:47:54 +0000370 struct fec_info_s *info = (struct fec_info_s *)dev->priv;
371
372 if (setclear) {
Wolfgang Wegner5fe66d72010-03-30 19:19:50 +0100373#ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
374 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
Alison Wang8d8dac92012-03-26 21:49:08 +0000375 setbits_be16(&gpio->par_feci2c,
376 GPIO_PAR_FECI2C_MDC0_MDC0 |
377 GPIO_PAR_FECI2C_MDIO0_MDIO0);
Wolfgang Wegner5fe66d72010-03-30 19:19:50 +0100378 else
Alison Wang8d8dac92012-03-26 21:49:08 +0000379 setbits_be16(&gpio->par_feci2c,
380 GPIO_PAR_FECI2C_MDC1_MDC1 |
381 GPIO_PAR_FECI2C_MDIO1_MDIO1);
Wolfgang Wegner5fe66d72010-03-30 19:19:50 +0100382#else
Alison Wang8d8dac92012-03-26 21:49:08 +0000383 setbits_be16(&gpio->par_feci2c,
384 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
Wolfgang Wegner5fe66d72010-03-30 19:19:50 +0100385#endif
TsiChung Liew69b17572008-10-21 13:47:54 +0000386
387 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
Alison Wang8d8dac92012-03-26 21:49:08 +0000388 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
TsiChung Liew69b17572008-10-21 13:47:54 +0000389 else
Alison Wang8d8dac92012-03-26 21:49:08 +0000390 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
TsiChung Liew69b17572008-10-21 13:47:54 +0000391 } else {
Alison Wang8d8dac92012-03-26 21:49:08 +0000392 clrbits_be16(&gpio->par_feci2c,
393 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
TsiChung Liew69b17572008-10-21 13:47:54 +0000394
Wolfgang Wegnera19e62d2010-03-30 19:19:51 +0100395 if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
396#ifdef CONFIG_SYS_FEC_FULL_MII
Alison Wang8d8dac92012-03-26 21:49:08 +0000397 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
Wolfgang Wegnera19e62d2010-03-30 19:19:51 +0100398#else
Alison Wang8d8dac92012-03-26 21:49:08 +0000399 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
Wolfgang Wegnera19e62d2010-03-30 19:19:51 +0100400#endif
401 } else {
402#ifdef CONFIG_SYS_FEC_FULL_MII
Alison Wang8d8dac92012-03-26 21:49:08 +0000403 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
Wolfgang Wegnera19e62d2010-03-30 19:19:51 +0100404#else
Alison Wang8d8dac92012-03-26 21:49:08 +0000405 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
Wolfgang Wegnera19e62d2010-03-30 19:19:51 +0100406#endif
407 }
TsiChung Liew69b17572008-10-21 13:47:54 +0000408 }
Alison Wangfdc2fb12012-10-18 19:25:51 +0000409#endif /* CONFIG_MCF5445x */
410
411#ifdef CONFIG_MCF5441x
412 if (setclear) {
413 out_8(&gpio->par_fec, 0x03);
414 out_8(&gpio->srcr_fec, 0x0F);
415 clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
416 GPIO_PAR_SIMP0H_DAT_GPIO);
417 clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
418 GPIO_PDDR_G4_OUTPUT);
419 clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
420
421 } else
422 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
423#endif
TsiChung Liew69b17572008-10-21 13:47:54 +0000424 return 0;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500425}
TsiChung Liew69b17572008-10-21 13:47:54 +0000426#endif
TsiChung Liewa424ba22009-06-30 14:18:29 +0000427
428#ifdef CONFIG_CF_DSPI
429void cfspi_port_conf(void)
430{
Alison Wang8d8dac92012-03-26 21:49:08 +0000431 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000432
Alison Wangfdc2fb12012-10-18 19:25:51 +0000433#ifdef CONFIG_MCF5445x
Alison Wang8d8dac92012-03-26 21:49:08 +0000434 out_8(&gpio->par_dspi,
435 GPIO_PAR_DSPI_SIN_SIN |
436 GPIO_PAR_DSPI_SOUT_SOUT |
437 GPIO_PAR_DSPI_SCK_SCK);
Alison Wangfdc2fb12012-10-18 19:25:51 +0000438#endif
439
440#ifdef CONFIG_MCF5441x
441 pm_t *pm = (pm_t *) MMAP_PM;
442
443 out_8(&gpio->par_dspi0,
444 GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
445 GPIO_PAR_DSPI0_SCK_DSPI0SCK);
446 out_8(&gpio->srcr_dspiow, 3);
447
448 /* DSPI0 */
449 out_8(&pm->pmcr0, 23);
450#endif
TsiChung Liewa424ba22009-06-30 14:18:29 +0000451}
452
453int cfspi_claim_bus(uint bus, uint cs)
454{
Alison Wang8d8dac92012-03-26 21:49:08 +0000455 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
456 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000457
Alison Wang8d8dac92012-03-26 21:49:08 +0000458 if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
TsiChung Liewa424ba22009-06-30 14:18:29 +0000459 return -1;
460
461 /* Clear FIFO and resume transfer */
Alison Wang8d8dac92012-03-26 21:49:08 +0000462 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000463
Alison Wangfdc2fb12012-10-18 19:25:51 +0000464#ifdef CONFIG_MCF5445x
TsiChung Liewa424ba22009-06-30 14:18:29 +0000465 switch (cs) {
466 case 0:
Alison Wang8d8dac92012-03-26 21:49:08 +0000467 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
468 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000469 break;
470 case 1:
Alison Wang8d8dac92012-03-26 21:49:08 +0000471 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
472 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000473 break;
474 case 2:
Alison Wang8d8dac92012-03-26 21:49:08 +0000475 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
476 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000477 break;
Wolfgang Wegneracf782f2010-03-30 19:20:31 +0100478 case 3:
Alison Wang8d8dac92012-03-26 21:49:08 +0000479 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
480 setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
Wolfgang Wegneracf782f2010-03-30 19:20:31 +0100481 break;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000482 case 5:
Alison Wang8d8dac92012-03-26 21:49:08 +0000483 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
484 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000485 break;
486 }
Alison Wangfdc2fb12012-10-18 19:25:51 +0000487#endif
488
489#ifdef CONFIG_MCF5441x
490 switch (cs) {
491 case 0:
492 clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK);
493 setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0);
494 break;
495 case 1:
496 clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
497 setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
498 break;
499 }
500#endif
TsiChung Liewa424ba22009-06-30 14:18:29 +0000501
502 return 0;
503}
504
505void cfspi_release_bus(uint bus, uint cs)
506{
Alison Wang8d8dac92012-03-26 21:49:08 +0000507 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
508 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000509
Alison Wang8d8dac92012-03-26 21:49:08 +0000510 /* Clear FIFO */
511 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000512
Alison Wangfdc2fb12012-10-18 19:25:51 +0000513#ifdef CONFIG_MCF5445x
TsiChung Liewa424ba22009-06-30 14:18:29 +0000514 switch (cs) {
515 case 0:
Alison Wang8d8dac92012-03-26 21:49:08 +0000516 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000517 break;
518 case 1:
Alison Wang8d8dac92012-03-26 21:49:08 +0000519 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000520 break;
521 case 2:
Alison Wang8d8dac92012-03-26 21:49:08 +0000522 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000523 break;
Wolfgang Wegneracf782f2010-03-30 19:20:31 +0100524 case 3:
Alison Wang8d8dac92012-03-26 21:49:08 +0000525 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
Wolfgang Wegneracf782f2010-03-30 19:20:31 +0100526 break;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000527 case 5:
Alison Wang8d8dac92012-03-26 21:49:08 +0000528 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000529 break;
530 }
Alison Wangfdc2fb12012-10-18 19:25:51 +0000531#endif
532
533#ifdef CONFIG_MCF5441x
534 if (cs == 1)
535 clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
536#endif
TsiChung Liewa424ba22009-06-30 14:18:29 +0000537}
538#endif