1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * (C) Copyright 2000-2003
4*4882a593Smuzhiyun * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
7*4882a593Smuzhiyun * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include <common.h>
13*4882a593Smuzhiyun #include <watchdog.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <asm/immap.h>
16*4882a593Smuzhiyun #include <asm/io.h>
17*4882a593Smuzhiyun #include <asm/rtc.h>
18*4882a593Smuzhiyun #include <linux/compiler.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun * Breath some life into the CPU...
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * Set up the memory map,
24*4882a593Smuzhiyun * initialize a bunch of registers,
25*4882a593Smuzhiyun * initialize the UPM's
26*4882a593Smuzhiyun */
cpu_init_f(void)27*4882a593Smuzhiyun void cpu_init_f(void)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun gpio_t *gpio = (gpio_t *) MMAP_GPIO;
30*4882a593Smuzhiyun fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #if !defined(CONFIG_CF_SBF)
33*4882a593Smuzhiyun scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
34*4882a593Smuzhiyun pll_t *pll = (pll_t *)MMAP_PLL;
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun /* Workaround, must place before fbcs */
37*4882a593Smuzhiyun out_be32(&pll->psr, 0x12);
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun out_be32(&scm1->mpr, 0x77777777);
40*4882a593Smuzhiyun out_be32(&scm1->pacra, 0);
41*4882a593Smuzhiyun out_be32(&scm1->pacrb, 0);
42*4882a593Smuzhiyun out_be32(&scm1->pacrc, 0);
43*4882a593Smuzhiyun out_be32(&scm1->pacrd, 0);
44*4882a593Smuzhiyun out_be32(&scm1->pacre, 0);
45*4882a593Smuzhiyun out_be32(&scm1->pacrf, 0);
46*4882a593Smuzhiyun out_be32(&scm1->pacrg, 0);
47*4882a593Smuzhiyun out_be32(&scm1->pacri, 0);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
50*4882a593Smuzhiyun && defined(CONFIG_SYS_CS0_CTRL))
51*4882a593Smuzhiyun out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
52*4882a593Smuzhiyun out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
53*4882a593Smuzhiyun out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun #endif /* CONFIG_CF_SBF */
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
58*4882a593Smuzhiyun && defined(CONFIG_SYS_CS1_CTRL))
59*4882a593Smuzhiyun out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
60*4882a593Smuzhiyun out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
61*4882a593Smuzhiyun out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
65*4882a593Smuzhiyun && defined(CONFIG_SYS_CS2_CTRL))
66*4882a593Smuzhiyun out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
67*4882a593Smuzhiyun out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
68*4882a593Smuzhiyun out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
69*4882a593Smuzhiyun #endif
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
72*4882a593Smuzhiyun && defined(CONFIG_SYS_CS3_CTRL))
73*4882a593Smuzhiyun out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
74*4882a593Smuzhiyun out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
75*4882a593Smuzhiyun out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
76*4882a593Smuzhiyun #endif
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
79*4882a593Smuzhiyun && defined(CONFIG_SYS_CS4_CTRL))
80*4882a593Smuzhiyun out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
81*4882a593Smuzhiyun out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
82*4882a593Smuzhiyun out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
83*4882a593Smuzhiyun #endif
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
86*4882a593Smuzhiyun && defined(CONFIG_SYS_CS5_CTRL))
87*4882a593Smuzhiyun out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
88*4882a593Smuzhiyun out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
89*4882a593Smuzhiyun out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
90*4882a593Smuzhiyun #endif
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun #ifdef CONFIG_SYS_I2C_FSL
93*4882a593Smuzhiyun out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
94*4882a593Smuzhiyun #endif
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun icache_enable();
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun * initialize higher level parts of CPU like timers
101*4882a593Smuzhiyun */
cpu_init_r(void)102*4882a593Smuzhiyun int cpu_init_r(void)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun #ifdef CONFIG_MCFRTC
105*4882a593Smuzhiyun rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
106*4882a593Smuzhiyun rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
109*4882a593Smuzhiyun out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun return (0);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
uart_port_conf(int port)115*4882a593Smuzhiyun void uart_port_conf(int port)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun gpio_t *gpio = (gpio_t *) MMAP_GPIO;
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /* Setup Ports: */
120*4882a593Smuzhiyun switch (port) {
121*4882a593Smuzhiyun case 0:
122*4882a593Smuzhiyun clrbits_be16(&gpio->par_uart,
123*4882a593Smuzhiyun ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
124*4882a593Smuzhiyun setbits_be16(&gpio->par_uart,
125*4882a593Smuzhiyun GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
126*4882a593Smuzhiyun break;
127*4882a593Smuzhiyun case 1:
128*4882a593Smuzhiyun clrbits_be16(&gpio->par_uart,
129*4882a593Smuzhiyun ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
130*4882a593Smuzhiyun setbits_be16(&gpio->par_uart,
131*4882a593Smuzhiyun GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
132*4882a593Smuzhiyun break;
133*4882a593Smuzhiyun case 2:
134*4882a593Smuzhiyun clrbits_8(&gpio->par_dspi,
135*4882a593Smuzhiyun ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
136*4882a593Smuzhiyun out_8(&gpio->par_dspi,
137*4882a593Smuzhiyun GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
138*4882a593Smuzhiyun break;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun #ifdef CONFIG_CF_DSPI
cfspi_port_conf(void)143*4882a593Smuzhiyun void cfspi_port_conf(void)
144*4882a593Smuzhiyun {
145*4882a593Smuzhiyun gpio_t *gpio = (gpio_t *) MMAP_GPIO;
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun out_8(&gpio->par_dspi,
148*4882a593Smuzhiyun GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
149*4882a593Smuzhiyun GPIO_PAR_DSPI_SCK_SCK);
150*4882a593Smuzhiyun }
151*4882a593Smuzhiyun
cfspi_claim_bus(uint bus,uint cs)152*4882a593Smuzhiyun int cfspi_claim_bus(uint bus, uint cs)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun dspi_t *dspi = (dspi_t *) MMAP_DSPI;
155*4882a593Smuzhiyun gpio_t *gpio = (gpio_t *) MMAP_GPIO;
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
158*4882a593Smuzhiyun return -1;
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun /* Clear FIFO and resume transfer */
161*4882a593Smuzhiyun clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun switch (cs) {
164*4882a593Smuzhiyun case 0:
165*4882a593Smuzhiyun clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK);
166*4882a593Smuzhiyun setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
167*4882a593Smuzhiyun break;
168*4882a593Smuzhiyun case 2:
169*4882a593Smuzhiyun clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
170*4882a593Smuzhiyun setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2);
171*4882a593Smuzhiyun break;
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun return 0;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
cfspi_release_bus(uint bus,uint cs)177*4882a593Smuzhiyun void cfspi_release_bus(uint bus, uint cs)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun dspi_t *dspi = (dspi_t *) MMAP_DSPI;
180*4882a593Smuzhiyun gpio_t *gpio = (gpio_t *) MMAP_GPIO;
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /* Clear FIFO */
183*4882a593Smuzhiyun clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun switch (cs) {
186*4882a593Smuzhiyun case 0:
187*4882a593Smuzhiyun clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
188*4882a593Smuzhiyun break;
189*4882a593Smuzhiyun case 2:
190*4882a593Smuzhiyun clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
191*4882a593Smuzhiyun break;
192*4882a593Smuzhiyun }
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun #endif
195