blob: 4ab13b4d8eabcbaca3f6edbdf7f385cf0b79c617 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewae831cd2008-01-14 17:46:19 -06002/*
3 *
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
Alison Wang8bce3ec2012-03-26 21:49:03 +00007 * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewae831cd2008-01-14 17:46:19 -06008 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewae831cd2008-01-14 17:46:19 -06009 */
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>
TsiChungLiewae831cd2008-01-14 17:46:19 -060014#include <watchdog.h>
15
16#include <asm/immap.h>
Alison Wang8bce3ec2012-03-26 21:49:03 +000017#include <asm/io.h>
TsiChungLiewae831cd2008-01-14 17:46:19 -060018#include <asm/rtc.h>
Alison Wang0c6c4442012-10-21 21:27:48 +000019#include <linux/compiler.h>
TsiChungLiewae831cd2008-01-14 17:46:19 -060020
Angelo Dureghello71abddd2019-03-13 21:46:52 +010021void cfspi_port_conf(void)
22{
23 gpio_t *gpio = (gpio_t *)MMAP_GPIO;
24
25 out_8(&gpio->par_dspi,
26 GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
27 GPIO_PAR_DSPI_SCK_SCK);
28}
29
TsiChungLiewae831cd2008-01-14 17:46:19 -060030/*
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 Wang8bce3ec2012-03-26 21:49:03 +000039 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
Alison Wang0c6c4442012-10-21 21:27:48 +000040 fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
TsiChungLiewae831cd2008-01-14 17:46:19 -060041
TsiChung Liew39966e32008-10-21 15:37:02 +000042#if !defined(CONFIG_CF_SBF)
Alison Wang0c6c4442012-10-21 21:27:48 +000043 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
44 pll_t *pll = (pll_t *)MMAP_PLL;
45
TsiChungLiewae831cd2008-01-14 17:46:19 -060046 /* Workaround, must place before fbcs */
Alison Wang8bce3ec2012-03-26 21:49:03 +000047 out_be32(&pll->psr, 0x12);
TsiChungLiewae831cd2008-01-14 17:46:19 -060048
Alison Wang8bce3ec2012-03-26 21:49:03 +000049 out_be32(&scm1->mpr, 0x77777777);
50 out_be32(&scm1->pacra, 0);
51 out_be32(&scm1->pacrb, 0);
52 out_be32(&scm1->pacrc, 0);
53 out_be32(&scm1->pacrd, 0);
54 out_be32(&scm1->pacre, 0);
55 out_be32(&scm1->pacrf, 0);
56 out_be32(&scm1->pacrg, 0);
57 out_be32(&scm1->pacri, 0);
TsiChungLiewae831cd2008-01-14 17:46:19 -060058
TsiChung Liew39966e32008-10-21 15:37:02 +000059#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
60 && defined(CONFIG_SYS_CS0_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000061 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
62 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
63 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060064#endif
TsiChung Liew39966e32008-10-21 15:37:02 +000065#endif /* CONFIG_CF_SBF */
TsiChungLiewae831cd2008-01-14 17:46:19 -060066
TsiChung Liew39966e32008-10-21 15:37:02 +000067#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
68 && defined(CONFIG_SYS_CS1_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000069 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
70 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
71 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060072#endif
73
TsiChung Liew39966e32008-10-21 15:37:02 +000074#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
75 && defined(CONFIG_SYS_CS2_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000076 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
77 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
78 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060079#endif
80
TsiChung Liew39966e32008-10-21 15:37:02 +000081#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
82 && defined(CONFIG_SYS_CS3_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000083 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
84 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
85 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060086#endif
87
TsiChung Liew39966e32008-10-21 15:37:02 +000088#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
89 && defined(CONFIG_SYS_CS4_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000090 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
91 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
92 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060093#endif
94
TsiChung Liew39966e32008-10-21 15:37:02 +000095#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
96 && defined(CONFIG_SYS_CS5_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000097 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
98 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
99 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600100#endif
101
Heiko Schocherf2850742012-10-24 13:48:22 +0200102#ifdef CONFIG_SYS_I2C_FSL
Alison Wang8bce3ec2012-03-26 21:49:03 +0000103 out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600104#endif
105
106 icache_enable();
Angelo Dureghello71abddd2019-03-13 21:46:52 +0100107
108 cfspi_port_conf();
TsiChungLiewae831cd2008-01-14 17:46:19 -0600109}
110
111/*
112 * initialize higher level parts of CPU like timers
113 */
114int cpu_init_r(void)
115{
TsiChung Liew1be9e092008-07-09 15:47:27 -0500116#ifdef CONFIG_MCFRTC
Alison Wang8bce3ec2012-03-26 21:49:03 +0000117 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
118 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
TsiChungLiewae831cd2008-01-14 17:46:19 -0600119
Alison Wang8bce3ec2012-03-26 21:49:03 +0000120 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
121 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600122#endif
123
124 return (0);
125}
126
TsiChung Liewf9556a72010-03-09 19:17:52 -0600127void uart_port_conf(int port)
TsiChungLiewae831cd2008-01-14 17:46:19 -0600128{
Alison Wang8bce3ec2012-03-26 21:49:03 +0000129 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewae831cd2008-01-14 17:46:19 -0600130
131 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600132 switch (port) {
TsiChungLiewae831cd2008-01-14 17:46:19 -0600133 case 0:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000134 clrbits_be16(&gpio->par_uart,
135 ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
136 setbits_be16(&gpio->par_uart,
137 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600138 break;
139 case 1:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000140 clrbits_be16(&gpio->par_uart,
141 ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
142 setbits_be16(&gpio->par_uart,
143 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600144 break;
145 case 2:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000146 clrbits_8(&gpio->par_dspi,
147 ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
148 out_8(&gpio->par_dspi,
149 GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600150 break;
151 }
152}