blob: 5a789540fc93bb4aaf069f2a55fa7689e827f7d1 [file] [log] [blame]
TsiChungLiewb859ef12007-08-16 19:23:50 -05001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangd132fe62012-03-26 21:49:06 +00006 * (C) Copyright 2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewb859ef12007-08-16 19:23:50 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiewb859ef12007-08-16 19:23:50 -050010 */
11
12#include <common.h>
13#include <watchdog.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050014#include <asm/immap.h>
Alison Wangd132fe62012-03-26 21:49:06 +000015#include <asm/io.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050016
TsiChung Liew69b17572008-10-21 13:47:54 +000017#if defined(CONFIG_CMD_NET)
18#include <config.h>
19#include <net.h>
20#include <asm/fec.h>
21#endif
22
TsiChungLiewb859ef12007-08-16 19:23:50 -050023/*
24 * Breath some life into the CPU...
25 *
26 * Set up the memory map,
27 * initialize a bunch of registers,
28 * initialize the UPM's
29 */
30void cpu_init_f(void)
31{
Alison Wangd132fe62012-03-26 21:49:06 +000032 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
33 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
34 wdog_t *wdog = (wdog_t *) MMAP_WDOG;
35 scm_t *scm = (scm_t *) MMAP_SCM;
TsiChungLiewb859ef12007-08-16 19:23:50 -050036
37 /* watchdog is enabled by default - disable the watchdog */
38#ifndef CONFIG_WATCHDOG
Alison Wangd132fe62012-03-26 21:49:06 +000039 out_be16(&wdog->cr, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050040#endif
41
Alison Wangd132fe62012-03-26 21:49:06 +000042 out_be32(&scm->rambar, CONFIG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050043
44 /* Port configuration */
Alison Wangd132fe62012-03-26 21:49:06 +000045 out_8(&gpio->par_cs, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050046
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000048 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
49 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
50 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050051#endif
52
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000054 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1);
55 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
56 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
57 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050058#endif
59
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000061 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2);
62 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
63 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
64 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050065#endif
66
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000068 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3);
69 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
70 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
71 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050072#endif
73
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000075 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4);
76 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
77 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
78 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050079#endif
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000082 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5);
83 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
84 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
85 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050086#endif
87
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088#if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000089 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6);
90 out_be32(&fbcs->csar6, CONFIG_SYS_CS6_BASE);
91 out_be32(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL);
92 out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050093#endif
94
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095#if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000096 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7);
97 out_be32(&fbcs->csar7, CONFIG_SYS_CS7_BASE);
98 out_be32(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL);
99 out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500100#endif
101
Heiko Schocherf2850742012-10-24 13:48:22 +0200102#ifdef CONFIG_SYS_I2C_FSL
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 CONFIG_SYS_I2C_PINMUX_REG &= CONFIG_SYS_I2C_PINMUX_CLR;
104 CONFIG_SYS_I2C_PINMUX_REG |= CONFIG_SYS_I2C_PINMUX_SET;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500105#endif
106
107 icache_enable();
108}
109
110/*
111 * initialize higher level parts of CPU like timers
112 */
113int cpu_init_r(void)
114{
115 return (0);
116}
117
TsiChung Liewf9556a72010-03-09 19:17:52 -0600118void uart_port_conf(int port)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500119{
Alison Wangd132fe62012-03-26 21:49:06 +0000120 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500121
Stefan Roesefe9dae62007-08-18 14:33:02 +0200122 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600123 switch (port) {
Stefan Roesefe9dae62007-08-18 14:33:02 +0200124 case 0:
Alison Wangd132fe62012-03-26 21:49:06 +0000125 clrbits_be16(&gpio->par_uart,
126 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
127 setbits_be16(&gpio->par_uart,
128 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200129 break;
130 case 1:
Alison Wangd132fe62012-03-26 21:49:06 +0000131 clrbits_be16(&gpio->par_uart,
132 GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK);
133 setbits_be16(&gpio->par_uart,
134 GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200135 break;
136 case 2:
TsiChung Liewf9556a72010-03-09 19:17:52 -0600137#ifdef CONFIG_SYS_UART2_PRI_GPIO
Alison Wangd132fe62012-03-26 21:49:06 +0000138 clrbits_be16(&gpio->par_uart,
139 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
140 setbits_be16(&gpio->par_uart,
141 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600142#elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wangd132fe62012-03-26 21:49:06 +0000143 clrbits_8(&gpio->par_feci2c,
144 GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK);
145 setbits_8(&gpio->par_feci2c,
146 GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600147#endif
Stefan Roesefe9dae62007-08-18 14:33:02 +0200148 break;
149 }
TsiChungLiewb859ef12007-08-16 19:23:50 -0500150}
TsiChung Liew69b17572008-10-21 13:47:54 +0000151
152#if defined(CONFIG_CMD_NET)
153int fecpin_setclear(struct eth_device *dev, int setclear)
154{
Alison Wangd132fe62012-03-26 21:49:06 +0000155 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liew69b17572008-10-21 13:47:54 +0000156
157 if (setclear) {
Alison Wangd132fe62012-03-26 21:49:06 +0000158 setbits_8(&gpio->par_feci2c,
159 GPIO_PAR_FECI2C_EMDC_FECEMDC |
160 GPIO_PAR_FECI2C_EMDIO_FECEMDIO);
TsiChung Liew69b17572008-10-21 13:47:54 +0000161 } else {
Alison Wangd132fe62012-03-26 21:49:06 +0000162 clrbits_8(&gpio->par_feci2c,
163 GPIO_PAR_FECI2C_EMDC_MASK |
164 GPIO_PAR_FECI2C_EMDIO_MASK);
TsiChung Liew69b17572008-10-21 13:47:54 +0000165 }
166
167 return 0;
168}
169#endif