Merge branch 'master' of git://git.denx.de/u-boot-tegra
[oweals/u-boot.git] / arch / m68k / cpu / mcf5227x / cpu_init.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *
4  * (C) Copyright 2000-2003
5  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6  *
7  * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
8  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
9  */
10
11 #include <common.h>
12 #include <watchdog.h>
13
14 #include <asm/immap.h>
15 #include <asm/io.h>
16 #include <asm/rtc.h>
17 #include <linux/compiler.h>
18
19 void cfspi_port_conf(void)
20 {
21         gpio_t *gpio = (gpio_t *)MMAP_GPIO;
22
23         out_8(&gpio->par_dspi,
24               GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
25               GPIO_PAR_DSPI_SCK_SCK);
26 }
27
28 /*
29  * Breath some life into the CPU...
30  *
31  * Set up the memory map,
32  * initialize a bunch of registers,
33  * initialize the UPM's
34  */
35 void cpu_init_f(void)
36 {
37         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
38         fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
39
40 #if !defined(CONFIG_CF_SBF)
41         scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
42         pll_t *pll = (pll_t *)MMAP_PLL;
43
44         /* Workaround, must place before fbcs */
45         out_be32(&pll->psr, 0x12);
46
47         out_be32(&scm1->mpr, 0x77777777);
48         out_be32(&scm1->pacra, 0);
49         out_be32(&scm1->pacrb, 0);
50         out_be32(&scm1->pacrc, 0);
51         out_be32(&scm1->pacrd, 0);
52         out_be32(&scm1->pacre, 0);
53         out_be32(&scm1->pacrf, 0);
54         out_be32(&scm1->pacrg, 0);
55         out_be32(&scm1->pacri, 0);
56
57 #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
58      && defined(CONFIG_SYS_CS0_CTRL))
59         out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
60         out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
61         out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
62 #endif
63 #endif                          /* CONFIG_CF_SBF */
64
65 #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
66      && defined(CONFIG_SYS_CS1_CTRL))
67         out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
68         out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
69         out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
70 #endif
71
72 #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
73      && defined(CONFIG_SYS_CS2_CTRL))
74         out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
75         out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
76         out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
77 #endif
78
79 #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
80      && defined(CONFIG_SYS_CS3_CTRL))
81         out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
82         out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
83         out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
84 #endif
85
86 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
87      && defined(CONFIG_SYS_CS4_CTRL))
88         out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
89         out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
90         out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
91 #endif
92
93 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
94      && defined(CONFIG_SYS_CS5_CTRL))
95         out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
96         out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
97         out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
98 #endif
99
100 #ifdef CONFIG_SYS_I2C_FSL
101         out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
102 #endif
103
104         icache_enable();
105
106         cfspi_port_conf();
107 }
108
109 /*
110  * initialize higher level parts of CPU like timers
111  */
112 int cpu_init_r(void)
113 {
114 #ifdef CONFIG_MCFRTC
115         rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
116         rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
117
118         out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
119         out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
120 #endif
121
122         return (0);
123 }
124
125 void uart_port_conf(int port)
126 {
127         gpio_t *gpio = (gpio_t *) MMAP_GPIO;
128
129         /* Setup Ports: */
130         switch (port) {
131         case 0:
132                 clrbits_be16(&gpio->par_uart,
133                         ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
134                 setbits_be16(&gpio->par_uart,
135                         GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
136                 break;
137         case 1:
138                 clrbits_be16(&gpio->par_uart,
139                         ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
140                 setbits_be16(&gpio->par_uart,
141                         GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
142                 break;
143         case 2:
144                 clrbits_8(&gpio->par_dspi,
145                         ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
146                 out_8(&gpio->par_dspi,
147                         GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
148                 break;
149         }
150 }