1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a4145534SPeter Tyser /*
3a4145534SPeter Tyser *
4a4145534SPeter Tyser * (C) Copyright 2000-2003
5a4145534SPeter Tyser * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6a4145534SPeter Tyser *
7849fc424SAlison Wang * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
8a4145534SPeter Tyser * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
9a4145534SPeter Tyser */
10a4145534SPeter Tyser
11a4145534SPeter Tyser #include <common.h>
12a4145534SPeter Tyser #include <watchdog.h>
13a4145534SPeter Tyser
14a4145534SPeter Tyser #include <asm/immap.h>
15849fc424SAlison Wang #include <asm/io.h>
16a4145534SPeter Tyser #include <asm/rtc.h>
177adbd11eSAlison Wang #include <linux/compiler.h>
18a4145534SPeter Tyser
19a4145534SPeter Tyser /*
20a4145534SPeter Tyser * Breath some life into the CPU...
21a4145534SPeter Tyser *
22a4145534SPeter Tyser * Set up the memory map,
23a4145534SPeter Tyser * initialize a bunch of registers,
24a4145534SPeter Tyser * initialize the UPM's
25a4145534SPeter Tyser */
cpu_init_f(void)26a4145534SPeter Tyser void cpu_init_f(void)
27a4145534SPeter Tyser {
28849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO;
297adbd11eSAlison Wang fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
30a4145534SPeter Tyser
31a4145534SPeter Tyser #if !defined(CONFIG_CF_SBF)
327adbd11eSAlison Wang scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
337adbd11eSAlison Wang pll_t *pll = (pll_t *)MMAP_PLL;
347adbd11eSAlison Wang
35a4145534SPeter Tyser /* Workaround, must place before fbcs */
36849fc424SAlison Wang out_be32(&pll->psr, 0x12);
37a4145534SPeter Tyser
38849fc424SAlison Wang out_be32(&scm1->mpr, 0x77777777);
39849fc424SAlison Wang out_be32(&scm1->pacra, 0);
40849fc424SAlison Wang out_be32(&scm1->pacrb, 0);
41849fc424SAlison Wang out_be32(&scm1->pacrc, 0);
42849fc424SAlison Wang out_be32(&scm1->pacrd, 0);
43849fc424SAlison Wang out_be32(&scm1->pacre, 0);
44849fc424SAlison Wang out_be32(&scm1->pacrf, 0);
45849fc424SAlison Wang out_be32(&scm1->pacrg, 0);
46849fc424SAlison Wang out_be32(&scm1->pacri, 0);
47a4145534SPeter Tyser
48a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
49a4145534SPeter Tyser && defined(CONFIG_SYS_CS0_CTRL))
50849fc424SAlison Wang out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
51849fc424SAlison Wang out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
52849fc424SAlison Wang out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
53a4145534SPeter Tyser #endif
54a4145534SPeter Tyser #endif /* CONFIG_CF_SBF */
55a4145534SPeter Tyser
56a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
57a4145534SPeter Tyser && defined(CONFIG_SYS_CS1_CTRL))
58849fc424SAlison Wang out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
59849fc424SAlison Wang out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
60849fc424SAlison Wang out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
61a4145534SPeter Tyser #endif
62a4145534SPeter Tyser
63a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
64a4145534SPeter Tyser && defined(CONFIG_SYS_CS2_CTRL))
65849fc424SAlison Wang out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
66849fc424SAlison Wang out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
67849fc424SAlison Wang out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
68a4145534SPeter Tyser #endif
69a4145534SPeter Tyser
70a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
71a4145534SPeter Tyser && defined(CONFIG_SYS_CS3_CTRL))
72849fc424SAlison Wang out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
73849fc424SAlison Wang out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
74849fc424SAlison Wang out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
75a4145534SPeter Tyser #endif
76a4145534SPeter Tyser
77a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
78a4145534SPeter Tyser && defined(CONFIG_SYS_CS4_CTRL))
79849fc424SAlison Wang out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
80849fc424SAlison Wang out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
81849fc424SAlison Wang out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
82a4145534SPeter Tyser #endif
83a4145534SPeter Tyser
84a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
85a4145534SPeter Tyser && defined(CONFIG_SYS_CS5_CTRL))
86849fc424SAlison Wang out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
87849fc424SAlison Wang out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
88849fc424SAlison Wang out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
89a4145534SPeter Tyser #endif
90a4145534SPeter Tyser
9100f792e0SHeiko Schocher #ifdef CONFIG_SYS_I2C_FSL
92849fc424SAlison Wang out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
93a4145534SPeter Tyser #endif
94a4145534SPeter Tyser
95a4145534SPeter Tyser icache_enable();
96a4145534SPeter Tyser }
97a4145534SPeter Tyser
98a4145534SPeter Tyser /*
99a4145534SPeter Tyser * initialize higher level parts of CPU like timers
100a4145534SPeter Tyser */
cpu_init_r(void)101a4145534SPeter Tyser int cpu_init_r(void)
102a4145534SPeter Tyser {
103a4145534SPeter Tyser #ifdef CONFIG_MCFRTC
104849fc424SAlison Wang rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
105849fc424SAlison Wang rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
106a4145534SPeter Tyser
107849fc424SAlison Wang out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
108849fc424SAlison Wang out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
109a4145534SPeter Tyser #endif
110a4145534SPeter Tyser
111a4145534SPeter Tyser return (0);
112a4145534SPeter Tyser }
113a4145534SPeter Tyser
uart_port_conf(int port)114a4145534SPeter Tyser void uart_port_conf(int port)
115a4145534SPeter Tyser {
116849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO;
117a4145534SPeter Tyser
118a4145534SPeter Tyser /* Setup Ports: */
119a4145534SPeter Tyser switch (port) {
120a4145534SPeter Tyser case 0:
121849fc424SAlison Wang clrbits_be16(&gpio->par_uart,
122849fc424SAlison Wang ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
123849fc424SAlison Wang setbits_be16(&gpio->par_uart,
124849fc424SAlison Wang GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
125a4145534SPeter Tyser break;
126a4145534SPeter Tyser case 1:
127849fc424SAlison Wang clrbits_be16(&gpio->par_uart,
128849fc424SAlison Wang ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
129849fc424SAlison Wang setbits_be16(&gpio->par_uart,
130849fc424SAlison Wang GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
131a4145534SPeter Tyser break;
132a4145534SPeter Tyser case 2:
133849fc424SAlison Wang clrbits_8(&gpio->par_dspi,
134849fc424SAlison Wang ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
135849fc424SAlison Wang out_8(&gpio->par_dspi,
136849fc424SAlison Wang GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
137a4145534SPeter Tyser break;
138a4145534SPeter Tyser }
139a4145534SPeter Tyser }
140a4145534SPeter Tyser
141a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI
cfspi_port_conf(void)142a4145534SPeter Tyser void cfspi_port_conf(void)
143a4145534SPeter Tyser {
144849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO;
145a4145534SPeter Tyser
146849fc424SAlison Wang out_8(&gpio->par_dspi,
147a4145534SPeter Tyser GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
148849fc424SAlison Wang GPIO_PAR_DSPI_SCK_SCK);
149a4145534SPeter Tyser }
150a4145534SPeter Tyser
cfspi_claim_bus(uint bus,uint cs)151a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs)
152a4145534SPeter Tyser {
153849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI;
154849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO;
155a4145534SPeter Tyser
156849fc424SAlison Wang if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
157a4145534SPeter Tyser return -1;
158a4145534SPeter Tyser
159a4145534SPeter Tyser /* Clear FIFO and resume transfer */
160849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
161a4145534SPeter Tyser
162a4145534SPeter Tyser switch (cs) {
163a4145534SPeter Tyser case 0:
164849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK);
165849fc424SAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
166a4145534SPeter Tyser break;
167a4145534SPeter Tyser case 2:
168849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
169849fc424SAlison Wang setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2);
170a4145534SPeter Tyser break;
171a4145534SPeter Tyser }
172a4145534SPeter Tyser
173a4145534SPeter Tyser return 0;
174a4145534SPeter Tyser }
175a4145534SPeter Tyser
cfspi_release_bus(uint bus,uint cs)176a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs)
177a4145534SPeter Tyser {
178849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI;
179849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO;
180a4145534SPeter Tyser
181849fc424SAlison Wang /* Clear FIFO */
182849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
183a4145534SPeter Tyser
184a4145534SPeter Tyser switch (cs) {
185a4145534SPeter Tyser case 0:
186849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
187a4145534SPeter Tyser break;
188a4145534SPeter Tyser case 2:
189849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
190a4145534SPeter Tyser break;
191a4145534SPeter Tyser }
192a4145534SPeter Tyser }
193a4145534SPeter Tyser #endif
194