blob: a05cbdcb3852c248af3d0289354b958d33c92bee [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
Simon Glass1d91ba72019-11-14 12:57:37 -070011#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050013#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
Vasili Galka4834c642014-06-30 12:59:41 +030023/* The registers in fbcs_t struct can be 16-bit for CONFIG_M5235 or 32-bit wide otherwise. */
24#ifdef CONFIG_M5235
25#define out_be_fbcs_reg out_be16
26#else
27#define out_be_fbcs_reg out_be32
28#endif
29
TsiChungLiewb859ef12007-08-16 19:23:50 -050030/*
31 * Breath some life into the CPU...
32 *
33 * Set up the memory map,
34 * initialize a bunch of registers,
35 * initialize the UPM's
36 */
37void cpu_init_f(void)
38{
Alison Wangd132fe62012-03-26 21:49:06 +000039 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
40 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
41 wdog_t *wdog = (wdog_t *) MMAP_WDOG;
42 scm_t *scm = (scm_t *) MMAP_SCM;
TsiChungLiewb859ef12007-08-16 19:23:50 -050043
44 /* watchdog is enabled by default - disable the watchdog */
45#ifndef CONFIG_WATCHDOG
Alison Wangd132fe62012-03-26 21:49:06 +000046 out_be16(&wdog->cr, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050047#endif
48
Tom Rini6a5dccc2022-11-16 13:10:41 -050049 out_be32(&scm->rambar, CFG_SYS_INIT_RAM_ADDR | SCM_RAMBAR_BDE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050050
51 /* Port configuration */
Alison Wangd132fe62012-03-26 21:49:06 +000052 out_8(&gpio->par_cs, 0);
TsiChungLiewb859ef12007-08-16 19:23:50 -050053
Tom Rini6a5dccc2022-11-16 13:10:41 -050054#if (defined(CFG_SYS_CS0_BASE) && defined(CFG_SYS_CS0_MASK) && defined(CFG_SYS_CS0_CTRL))
55 out_be_fbcs_reg(&fbcs->csar0, CFG_SYS_CS0_BASE);
56 out_be_fbcs_reg(&fbcs->cscr0, CFG_SYS_CS0_CTRL);
57 out_be32(&fbcs->csmr0, CFG_SYS_CS0_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050058#endif
59
Tom Rini6a5dccc2022-11-16 13:10:41 -050060#if (defined(CFG_SYS_CS1_BASE) && defined(CFG_SYS_CS1_MASK) && defined(CFG_SYS_CS1_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000061 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS1);
Tom Rini6a5dccc2022-11-16 13:10:41 -050062 out_be_fbcs_reg(&fbcs->csar1, CFG_SYS_CS1_BASE);
63 out_be_fbcs_reg(&fbcs->cscr1, CFG_SYS_CS1_CTRL);
64 out_be32(&fbcs->csmr1, CFG_SYS_CS1_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050065#endif
66
Tom Rini6a5dccc2022-11-16 13:10:41 -050067#if (defined(CFG_SYS_CS2_BASE) && defined(CFG_SYS_CS2_MASK) && defined(CFG_SYS_CS2_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000068 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS2);
Tom Rini6a5dccc2022-11-16 13:10:41 -050069 out_be_fbcs_reg(&fbcs->csar2, CFG_SYS_CS2_BASE);
70 out_be_fbcs_reg(&fbcs->cscr2, CFG_SYS_CS2_CTRL);
71 out_be32(&fbcs->csmr2, CFG_SYS_CS2_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050072#endif
73
Tom Rini6a5dccc2022-11-16 13:10:41 -050074#if (defined(CFG_SYS_CS3_BASE) && defined(CFG_SYS_CS3_MASK) && defined(CFG_SYS_CS3_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000075 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS3);
Tom Rini6a5dccc2022-11-16 13:10:41 -050076 out_be_fbcs_reg(&fbcs->csar3, CFG_SYS_CS3_BASE);
77 out_be_fbcs_reg(&fbcs->cscr3, CFG_SYS_CS3_CTRL);
78 out_be32(&fbcs->csmr3, CFG_SYS_CS3_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050079#endif
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000082 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS4);
Vasili Galka4834c642014-06-30 12:59:41 +030083 out_be_fbcs_reg(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
84 out_be_fbcs_reg(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000085 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050086#endif
87
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000089 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS5);
Vasili Galka4834c642014-06-30 12:59:41 +030090 out_be_fbcs_reg(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
91 out_be_fbcs_reg(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000092 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -050093#endif
94
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095#if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && defined(CONFIG_SYS_CS6_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +000096 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS6);
Vasili Galka4834c642014-06-30 12:59:41 +030097 out_be_fbcs_reg(&fbcs->csar6, CONFIG_SYS_CS6_BASE);
98 out_be_fbcs_reg(&fbcs->cscr6, CONFIG_SYS_CS6_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +000099 out_be32(&fbcs->csmr6, CONFIG_SYS_CS6_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500100#endif
101
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102#if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && defined(CONFIG_SYS_CS7_CTRL))
Alison Wangd132fe62012-03-26 21:49:06 +0000103 setbits_8(&gpio->par_cs, GPIO_PAR_CS_CS7);
Vasili Galka4834c642014-06-30 12:59:41 +0300104 out_be_fbcs_reg(&fbcs->csar7, CONFIG_SYS_CS7_BASE);
105 out_be_fbcs_reg(&fbcs->cscr7, CONFIG_SYS_CS7_CTRL);
Alison Wangd132fe62012-03-26 21:49:06 +0000106 out_be32(&fbcs->csmr7, CONFIG_SYS_CS7_MASK);
TsiChungLiewb859ef12007-08-16 19:23:50 -0500107#endif
108
Heiko Schocherf2850742012-10-24 13:48:22 +0200109#ifdef CONFIG_SYS_I2C_FSL
Tom Rini6a5dccc2022-11-16 13:10:41 -0500110 CFG_SYS_I2C_PINMUX_REG &= CFG_SYS_I2C_PINMUX_CLR;
111 CFG_SYS_I2C_PINMUX_REG |= CFG_SYS_I2C_PINMUX_SET;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500112#endif
113
114 icache_enable();
115}
116
117/*
118 * initialize higher level parts of CPU like timers
119 */
120int cpu_init_r(void)
121{
122 return (0);
123}
124
TsiChung Liewf9556a72010-03-09 19:17:52 -0600125void uart_port_conf(int port)
TsiChungLiewb859ef12007-08-16 19:23:50 -0500126{
Alison Wangd132fe62012-03-26 21:49:06 +0000127 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500128
Stefan Roesefe9dae62007-08-18 14:33:02 +0200129 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600130 switch (port) {
Stefan Roesefe9dae62007-08-18 14:33:02 +0200131 case 0:
Alison Wangd132fe62012-03-26 21:49:06 +0000132 clrbits_be16(&gpio->par_uart,
133 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
134 setbits_be16(&gpio->par_uart,
135 GPIO_PAR_UART_U0RXD | GPIO_PAR_UART_U0TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200136 break;
137 case 1:
Alison Wangd132fe62012-03-26 21:49:06 +0000138 clrbits_be16(&gpio->par_uart,
139 GPIO_PAR_UART_U1RXD_MASK | GPIO_PAR_UART_U1TXD_MASK);
140 setbits_be16(&gpio->par_uart,
141 GPIO_PAR_UART_U1RXD_U1RXD | GPIO_PAR_UART_U1TXD_U1TXD);
Stefan Roesefe9dae62007-08-18 14:33:02 +0200142 break;
143 case 2:
TsiChung Liewf9556a72010-03-09 19:17:52 -0600144#ifdef CONFIG_SYS_UART2_PRI_GPIO
Alison Wangd132fe62012-03-26 21:49:06 +0000145 clrbits_be16(&gpio->par_uart,
146 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
147 setbits_be16(&gpio->par_uart,
148 GPIO_PAR_UART_U2RXD | GPIO_PAR_UART_U2TXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600149#elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
Alison Wangd132fe62012-03-26 21:49:06 +0000150 clrbits_8(&gpio->par_feci2c,
151 GPIO_PAR_FECI2C_EMDC_MASK | GPIO_PAR_FECI2C_EMDIO_MASK);
152 setbits_8(&gpio->par_feci2c,
153 GPIO_PAR_FECI2C_EMDC_U2TXD | GPIO_PAR_FECI2C_EMDIO_U2RXD);
TsiChung Liewf9556a72010-03-09 19:17:52 -0600154#endif
Stefan Roesefe9dae62007-08-18 14:33:02 +0200155 break;
156 }
TsiChungLiewb859ef12007-08-16 19:23:50 -0500157}
TsiChung Liew69b17572008-10-21 13:47:54 +0000158
159#if defined(CONFIG_CMD_NET)
Angelo Durgehello8ff47f72019-11-15 23:54:16 +0100160int fecpin_setclear(fec_info_t *info, int setclear)
TsiChung Liew69b17572008-10-21 13:47:54 +0000161{
Alison Wangd132fe62012-03-26 21:49:06 +0000162 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liew69b17572008-10-21 13:47:54 +0000163
164 if (setclear) {
Alison Wangd132fe62012-03-26 21:49:06 +0000165 setbits_8(&gpio->par_feci2c,
166 GPIO_PAR_FECI2C_EMDC_FECEMDC |
167 GPIO_PAR_FECI2C_EMDIO_FECEMDIO);
TsiChung Liew69b17572008-10-21 13:47:54 +0000168 } else {
Alison Wangd132fe62012-03-26 21:49:06 +0000169 clrbits_8(&gpio->par_feci2c,
170 GPIO_PAR_FECI2C_EMDC_MASK |
171 GPIO_PAR_FECI2C_EMDIO_MASK);
TsiChung Liew69b17572008-10-21 13:47:54 +0000172 }
173
174 return 0;
175}
176#endif