blob: 339fbeb42929afb5b601ab87a55840face2adf72 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewb859ef12007-08-16 19:23:50 -05002/*
3 *
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
Alison Wangd132fe62012-03-26 21:49:06 +00007 * (C) Copyright 2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewb859ef12007-08-16 19:23:50 -05008 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewb859ef12007-08-16 19:23:50 -05009 */
10
11#include <common.h>
12#include <watchdog.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050013#include <asm/immap.h>
Alison Wangd132fe62012-03-26 21:49:06 +000014#include <asm/io.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050015
TsiChung Liew69b17572008-10-21 13:47:54 +000016#if defined(CONFIG_CMD_NET)
17#include <config.h>
18#include <net.h>
19#include <asm/fec.h>
20#endif
21
Vasili Galka4834c642014-06-30 12:59:41 +030022/* The registers in fbcs_t struct can be 16-bit for CONFIG_M5235 or 32-bit wide otherwise. */
23#ifdef CONFIG_M5235
24#define out_be_fbcs_reg out_be16
25#else
26#define out_be_fbcs_reg out_be32
27#endif
28
TsiChungLiewb859ef12007-08-16 19:23:50 -050029/*
30 * Breath some life into the CPU...
31 *
32 * Set up the memory map,
33 * initialize a bunch of registers,
34 * initialize the UPM's
35 */
36void cpu_init_f(void)
37{
Alison Wangd132fe62012-03-26 21:49:06 +000038 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
39 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
40 wdog_t *wdog = (wdog_t *) MMAP_WDOG;
41 scm_t *scm = (scm_t *) MMAP_SCM;
TsiChungLiewb859ef12007-08-16 19:23:50 -050042
43 /* watchdog is enabled by default - disable the watchdog */
44#ifndef CONFIG_WATCHDOG
Alison Wangd132fe62012-03-26 21:49:06 +000045 out_be16(&wdog->cr, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050046#endif
47
Alison Wangd132fe62012-03-26 21:49:06 +000048 out_be32(&scm->rambar, CONFIG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050049
50 /* Port configuration */
Alison Wangd132fe62012-03-26 21:49:06 +000051 out_8(&gpio->par_cs, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050052
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
Vasili Galka4834c642014-06-30 12:59:41 +030054 out_be_fbcs_reg(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
55 out_be_fbcs_reg(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000056 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050057#endif
58
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000060 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1);
Vasili Galka4834c642014-06-30 12:59:41 +030061 out_be_fbcs_reg(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
62 out_be_fbcs_reg(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000063 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050064#endif
65
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000067 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2);
Vasili Galka4834c642014-06-30 12:59:41 +030068 out_be_fbcs_reg(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
69 out_be_fbcs_reg(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000070 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050071#endif
72
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000074 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3);
Vasili Galka4834c642014-06-30 12:59:41 +030075 out_be_fbcs_reg(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
76 out_be_fbcs_reg(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000077 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050078#endif
79
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020080#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000081 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4);
Vasili Galka4834c642014-06-30 12:59:41 +030082 out_be_fbcs_reg(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
83 out_be_fbcs_reg(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000084 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050085#endif
86
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000088 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5);
Vasili Galka4834c642014-06-30 12:59:41 +030089 out_be_fbcs_reg(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
90 out_be_fbcs_reg(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000091 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050092#endif
93
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020094#if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000095 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6);
Vasili Galka4834c642014-06-30 12:59:41 +030096 out_be_fbcs_reg(&fbcs->csar6, CONFIG_SYS_CS6_BASE);
97 out_be_fbcs_reg(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000098 out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050099#endif
100
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101#if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +0000102 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7);
Vasili Galka4834c642014-06-30 12:59:41 +0300103 out_be_fbcs_reg(&fbcs->csar7, CONFIG_SYS_CS7_BASE);
104 out_be_fbcs_reg(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +0000105 out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500106#endif
107
Heiko Schocherf2850742012-10-24 13:48:22 +0200108#ifdef CONFIG_SYS_I2C_FSL
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109 CONFIG_SYS_I2C_PINMUX_REG &= CONFIG_SYS_I2C_PINMUX_CLR;
110 CONFIG_SYS_I2C_PINMUX_REG |= CONFIG_SYS_I2C_PINMUX_SET;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500111#endif
112
113 icache_enable();
114}
115
116/*
117 * initialize higher level parts of CPU like timers
118 */
119int cpu_init_r(void)
120{
121 return (0);
122}
123
TsiChung Liewf9556a72010-03-09 19:17:52 -0600124void uart_port_conf(int port)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500125{
Alison Wangd132fe62012-03-26 21:49:06 +0000126 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500127
Stefan Roesefe9dae62007-08-18 14:33:02 +0200128 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600129 switch (port) {
Stefan Roesefe9dae62007-08-18 14:33:02 +0200130 case 0:
Alison Wangd132fe62012-03-26 21:49:06 +0000131 clrbits_be16(&gpio->par_uart,
132 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
133 setbits_be16(&gpio->par_uart,
134 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200135 break;
136 case 1:
Alison Wangd132fe62012-03-26 21:49:06 +0000137 clrbits_be16(&gpio->par_uart,
138 GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK);
139 setbits_be16(&gpio->par_uart,
140 GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200141 break;
142 case 2:
TsiChung Liewf9556a72010-03-09 19:17:52 -0600143#ifdef CONFIG_SYS_UART2_PRI_GPIO
Alison Wangd132fe62012-03-26 21:49:06 +0000144 clrbits_be16(&gpio->par_uart,
145 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
146 setbits_be16(&gpio->par_uart,
147 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600148#elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wangd132fe62012-03-26 21:49:06 +0000149 clrbits_8(&gpio->par_feci2c,
150 GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK);
151 setbits_8(&gpio->par_feci2c,
152 GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600153#endif
Stefan Roesefe9dae62007-08-18 14:33:02 +0200154 break;
155 }
TsiChungLiewb859ef12007-08-16 19:23:50 -0500156}
TsiChung Liew69b17572008-10-21 13:47:54 +0000157
158#if defined(CONFIG_CMD_NET)
159int fecpin_setclear(struct eth_device *dev, int setclear)
160{
Alison Wangd132fe62012-03-26 21:49:06 +0000161 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liew69b17572008-10-21 13:47:54 +0000162
163 if (setclear) {
Alison Wangd132fe62012-03-26 21:49:06 +0000164 setbits_8(&gpio->par_feci2c,
165 GPIO_PAR_FECI2C_EMDC_FECEMDC |
166 GPIO_PAR_FECI2C_EMDIO_FECEMDIO);
TsiChung Liew69b17572008-10-21 13:47:54 +0000167 } else {
Alison Wangd132fe62012-03-26 21:49:06 +0000168 clrbits_8(&gpio->par_feci2c,
169 GPIO_PAR_FECI2C_EMDC_MASK |
170 GPIO_PAR_FECI2C_EMDIO_MASK);
TsiChung Liew69b17572008-10-21 13:47:54 +0000171 }
172
173 return 0;
174}
175#endif