blob: d1c0b401c1ed4eca51b86fb9e810792366f3092c [file] [log] [blame]
TsiChungLiew4a442d32007-08-16 19:23:50 -05001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangc6d88632012-03-26 21:49:06 +00006 * (C) Copyright 2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew4a442d32007-08-16 19:23:50 -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>
TsiChungLiew4a442d32007-08-16 19:23:50 -050030#include <asm/immap.h>
Alison Wangc6d88632012-03-26 21:49:06 +000031#include <asm/io.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050032
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
TsiChungLiew4a442d32007-08-16 19:23:50 -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{
Alison Wangc6d88632012-03-26 21:49:06 +000048 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
49 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
50 wdog_t *wdog = (wdog_t *) MMAP_WDOG;
51 scm_t *scm = (scm_t *) MMAP_SCM;
TsiChungLiew4a442d32007-08-16 19:23:50 -050052
53 /* watchdog is enabled by default - disable the watchdog */
54#ifndef CONFIG_WATCHDOG
Alison Wangc6d88632012-03-26 21:49:06 +000055 out_be16(&wdog->cr, 0);
TsiChungLiew4a442d32007-08-16 19:23:50 -050056#endif
57
Alison Wangc6d88632012-03-26 21:49:06 +000058 out_be32(&scm->rambar, CONFIG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE);
TsiChungLiew4a442d32007-08-16 19:23:50 -050059
60 /* Port configuration */
Alison Wangc6d88632012-03-26 21:49:06 +000061 out_8(&gpio->par_cs, 0);
TsiChungLiew4a442d32007-08-16 19:23:50 -050062
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020063#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000064 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
65 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
66 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -050067#endif
68
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000070 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1);
71 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
72 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
73 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -050074#endif
75
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000077 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2);
78 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
79 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
80 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -050081#endif
82
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020083#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000084 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3);
85 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
86 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
87 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -050088#endif
89
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000091 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4);
92 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
93 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
94 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -050095#endif
96
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +000098 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5);
99 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
100 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
101 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -0500102#endif
103
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104#if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +0000105 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6);
106 out_be32(&fbcs->csar6, CONFIG_SYS_CS6_BASE);
107 out_be32(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL);
108 out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -0500109#endif
110
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200111#if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL))
Alison Wangc6d88632012-03-26 21:49:06 +0000112 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7);
113 out_be32(&fbcs->csar7, CONFIG_SYS_CS7_BASE);
114 out_be32(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL);
115 out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK);
TsiChungLiew4a442d32007-08-16 19:23:50 -0500116#endif
117
118#ifdef CONFIG_FSL_I2C
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200119 CONFIG_SYS_I2C_PINMUX_REG &= CONFIG_SYS_I2C_PINMUX_CLR;
120 CONFIG_SYS_I2C_PINMUX_REG |= CONFIG_SYS_I2C_PINMUX_SET;
TsiChungLiew4a442d32007-08-16 19:23:50 -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{
131 return (0);
132}
133
TsiChung Liew52affe02010-03-09 19:17:52 -0600134void uart_port_conf(int port)
TsiChungLiew4a442d32007-08-16 19:23:50 -0500135{
Alison Wangc6d88632012-03-26 21:49:06 +0000136 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiew4a442d32007-08-16 19:23:50 -0500137
Stefan Roese8280f6a2007-08-18 14:33:02 +0200138 /* Setup Ports: */
TsiChung Liew52affe02010-03-09 19:17:52 -0600139 switch (port) {
Stefan Roese8280f6a2007-08-18 14:33:02 +0200140 case 0:
Alison Wangc6d88632012-03-26 21:49:06 +0000141 clrbits_be16(&gpio->par_uart,
142 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
143 setbits_be16(&gpio->par_uart,
144 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
Stefan Roese8280f6a2007-08-18 14:33:02 +0200145 break;
146 case 1:
Alison Wangc6d88632012-03-26 21:49:06 +0000147 clrbits_be16(&gpio->par_uart,
148 GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK);
149 setbits_be16(&gpio->par_uart,
150 GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD);
Stefan Roese8280f6a2007-08-18 14:33:02 +0200151 break;
152 case 2:
TsiChung Liew52affe02010-03-09 19:17:52 -0600153#ifdef CONFIG_SYS_UART2_PRI_GPIO
Alison Wangc6d88632012-03-26 21:49:06 +0000154 clrbits_be16(&gpio->par_uart,
155 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
156 setbits_be16(&gpio->par_uart,
157 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600158#elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wangc6d88632012-03-26 21:49:06 +0000159 clrbits_8(&gpio->par_feci2c,
160 GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK);
161 setbits_8(&gpio->par_feci2c,
162 GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD);
TsiChung Liew52affe02010-03-09 19:17:52 -0600163#endif
Stefan Roese8280f6a2007-08-18 14:33:02 +0200164 break;
165 }
TsiChungLiew4a442d32007-08-16 19:23:50 -0500166}
TsiChung Liewf3962d32008-10-21 13:47:54 +0000167
168#if defined(CONFIG_CMD_NET)
169int fecpin_setclear(struct eth_device *dev, int setclear)
170{
Alison Wangc6d88632012-03-26 21:49:06 +0000171 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewf3962d32008-10-21 13:47:54 +0000172
173 if (setclear) {
Alison Wangc6d88632012-03-26 21:49:06 +0000174 setbits_8(&gpio->par_feci2c,
175 GPIO_PAR_FECI2C_EMDC_FECEMDC |
176 GPIO_PAR_FECI2C_EMDIO_FECEMDIO);
TsiChung Liewf3962d32008-10-21 13:47:54 +0000177 } else {
Alison Wangc6d88632012-03-26 21:49:06 +0000178 clrbits_8(&gpio->par_feci2c,
179 GPIO_PAR_FECI2C_EMDC_MASK |
180 GPIO_PAR_FECI2C_EMDIO_MASK);
TsiChung Liewf3962d32008-10-21 13:47:54 +0000181 }
182
183 return 0;
184}
185#endif