blob: 10be73822fa5f28a4d08029467a0e5585d22f433 [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>
Simon Glass1d91ba72019-11-14 12:57:37 -070012#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060013#include <init.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050014#include <watchdog.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050015#include <asm/immap.h>
Alison Wangd132fe62012-03-26 21:49:06 +000016#include <asm/io.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050017
TsiChung Liew69b17572008-10-21 13:47:54 +000018#if defined(CONFIG_CMD_NET)
19#include <config.h>
20#include <net.h>
21#include <asm/fec.h>
22#endif
23
Vasili Galka4834c642014-06-30 12:59:41 +030024/* The registers in fbcs_t struct can be 16-bit for CONFIG_M5235 or 32-bit wide otherwise. */
25#ifdef CONFIG_M5235
26#define out_be_fbcs_reg out_be16
27#else
28#define out_be_fbcs_reg out_be32
29#endif
30
TsiChungLiewb859ef12007-08-16 19:23:50 -050031/*
32 * Breath some life into the CPU...
33 *
34 * Set up the memory map,
35 * initialize a bunch of registers,
36 * initialize the UPM's
37 */
38void cpu_init_f(void)
39{
Alison Wangd132fe62012-03-26 21:49:06 +000040 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
41 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
42 wdog_t *wdog = (wdog_t *) MMAP_WDOG;
43 scm_t *scm = (scm_t *) MMAP_SCM;
TsiChungLiewb859ef12007-08-16 19:23:50 -050044
45 /* watchdog is enabled by default - disable the watchdog */
46#ifndef CONFIG_WATCHDOG
Alison Wangd132fe62012-03-26 21:49:06 +000047 out_be16(&wdog->cr, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050048#endif
49
Tom Rini6a5dccc2022-11-16 13:10:41 -050050 out_be32(&scm->rambar, CFG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050051
52 /* Port configuration */
Alison Wangd132fe62012-03-26 21:49:06 +000053 out_8(&gpio->par_cs, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050054
Tom Rini6a5dccc2022-11-16 13:10:41 -050055#if (defined(CFG_SYS_CS0_BASE) && defined(CFG_SYS_CS0_MASK) && defined(CFG_SYS_CS0_CTRL))
56 out_be_fbcs_reg(&fbcs->csar0, CFG_SYS_CS0_BASE);
57 out_be_fbcs_reg(&fbcs->cscr0, CFG_SYS_CS0_CTRL);
58 out_be32(&fbcs->csmr0, CFG_SYS_CS0_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050059#endif
60
Tom Rini6a5dccc2022-11-16 13:10:41 -050061#if (defined(CFG_SYS_CS1_BASE) && defined(CFG_SYS_CS1_MASK) && defined(CFG_SYS_CS1_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000062 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1);
Tom Rini6a5dccc2022-11-16 13:10:41 -050063 out_be_fbcs_reg(&fbcs->csar1, CFG_SYS_CS1_BASE);
64 out_be_fbcs_reg(&fbcs->cscr1, CFG_SYS_CS1_CTRL);
65 out_be32(&fbcs->csmr1, CFG_SYS_CS1_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050066#endif
67
Tom Rini6a5dccc2022-11-16 13:10:41 -050068#if (defined(CFG_SYS_CS2_BASE) && defined(CFG_SYS_CS2_MASK) && defined(CFG_SYS_CS2_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000069 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2);
Tom Rini6a5dccc2022-11-16 13:10:41 -050070 out_be_fbcs_reg(&fbcs->csar2, CFG_SYS_CS2_BASE);
71 out_be_fbcs_reg(&fbcs->cscr2, CFG_SYS_CS2_CTRL);
72 out_be32(&fbcs->csmr2, CFG_SYS_CS2_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050073#endif
74
Tom Rini6a5dccc2022-11-16 13:10:41 -050075#if (defined(CFG_SYS_CS3_BASE) && defined(CFG_SYS_CS3_MASK) && defined(CFG_SYS_CS3_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000076 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3);
Tom Rini6a5dccc2022-11-16 13:10:41 -050077 out_be_fbcs_reg(&fbcs->csar3, CFG_SYS_CS3_BASE);
78 out_be_fbcs_reg(&fbcs->cscr3, CFG_SYS_CS3_CTRL);
79 out_be32(&fbcs->csmr3, CFG_SYS_CS3_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050080#endif
81
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000083 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4);
Vasili Galka4834c642014-06-30 12:59:41 +030084 out_be_fbcs_reg(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
85 out_be_fbcs_reg(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000086 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050087#endif
88
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000090 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5);
Vasili Galka4834c642014-06-30 12:59:41 +030091 out_be_fbcs_reg(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
92 out_be_fbcs_reg(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000093 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050094#endif
95
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020096#if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000097 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6);
Vasili Galka4834c642014-06-30 12:59:41 +030098 out_be_fbcs_reg(&fbcs->csar6, CONFIG_SYS_CS6_BASE);
99 out_be_fbcs_reg(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +0000100 out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500101#endif
102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103#if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +0000104 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7);
Vasili Galka4834c642014-06-30 12:59:41 +0300105 out_be_fbcs_reg(&fbcs->csar7, CONFIG_SYS_CS7_BASE);
106 out_be_fbcs_reg(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +0000107 out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500108#endif
109
Heiko Schocherf2850742012-10-24 13:48:22 +0200110#ifdef CONFIG_SYS_I2C_FSL
Tom Rini6a5dccc2022-11-16 13:10:41 -0500111 CFG_SYS_I2C_PINMUX_REG &= CFG_SYS_I2C_PINMUX_CLR;
112 CFG_SYS_I2C_PINMUX_REG |= CFG_SYS_I2C_PINMUX_SET;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500113#endif
114
115 icache_enable();
116}
117
118/*
119 * initialize higher level parts of CPU like timers
120 */
121int cpu_init_r(void)
122{
123 return (0);
124}
125
TsiChung Liewf9556a72010-03-09 19:17:52 -0600126void uart_port_conf(int port)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500127{
Alison Wangd132fe62012-03-26 21:49:06 +0000128 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500129
Stefan Roesefe9dae62007-08-18 14:33:02 +0200130 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600131 switch (port) {
Stefan Roesefe9dae62007-08-18 14:33:02 +0200132 case 0:
Alison Wangd132fe62012-03-26 21:49:06 +0000133 clrbits_be16(&gpio->par_uart,
134 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
135 setbits_be16(&gpio->par_uart,
136 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200137 break;
138 case 1:
Alison Wangd132fe62012-03-26 21:49:06 +0000139 clrbits_be16(&gpio->par_uart,
140 GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK);
141 setbits_be16(&gpio->par_uart,
142 GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200143 break;
144 case 2:
TsiChung Liewf9556a72010-03-09 19:17:52 -0600145#ifdef CONFIG_SYS_UART2_PRI_GPIO
Alison Wangd132fe62012-03-26 21:49:06 +0000146 clrbits_be16(&gpio->par_uart,
147 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
148 setbits_be16(&gpio->par_uart,
149 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600150#elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wangd132fe62012-03-26 21:49:06 +0000151 clrbits_8(&gpio->par_feci2c,
152 GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK);
153 setbits_8(&gpio->par_feci2c,
154 GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600155#endif
Stefan Roesefe9dae62007-08-18 14:33:02 +0200156 break;
157 }
TsiChungLiewb859ef12007-08-16 19:23:50 -0500158}
TsiChung Liew69b17572008-10-21 13:47:54 +0000159
160#if defined(CONFIG_CMD_NET)
Angelo Durgehello8ff47f72019-11-15 23:54:16 +0100161int fecpin_setclear(fec_info_t *info, int setclear)
TsiChung Liew69b17572008-10-21 13:47:54 +0000162{
Alison Wangd132fe62012-03-26 21:49:06 +0000163 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liew69b17572008-10-21 13:47:54 +0000164
165 if (setclear) {
Alison Wangd132fe62012-03-26 21:49:06 +0000166 setbits_8(&gpio->par_feci2c,
167 GPIO_PAR_FECI2C_EMDC_FECEMDC |
168 GPIO_PAR_FECI2C_EMDIO_FECEMDIO);
TsiChung Liew69b17572008-10-21 13:47:54 +0000169 } else {
Alison Wangd132fe62012-03-26 21:49:06 +0000170 clrbits_8(&gpio->par_feci2c,
171 GPIO_PAR_FECI2C_EMDC_MASK |
172 GPIO_PAR_FECI2C_EMDIO_MASK);
TsiChung Liew69b17572008-10-21 13:47:54 +0000173 }
174
175 return 0;
176}
177#endif