blob: 91b5fadc8809493d3a97b232d8cea9247fdf7139 [file] [log] [blame]
TsiChungLiewc8758102008-01-14 17:46:19 -06001/*
2 *
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang849fc422012-03-26 21:49:03 +00006 * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewc8758102008-01-14 17:46:19 -06007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
TsiChungLiewc8758102008-01-14 17:46:19 -060010 */
11
12#include <common.h>
13#include <watchdog.h>
14
15#include <asm/immap.h>
Alison Wang849fc422012-03-26 21:49:03 +000016#include <asm/io.h>
TsiChungLiewc8758102008-01-14 17:46:19 -060017#include <asm/rtc.h>
Alison Wang7adbd11e2012-10-21 21:27:48 +000018#include <linux/compiler.h>
TsiChungLiewc8758102008-01-14 17:46:19 -060019
20/*
21 * Breath some life into the CPU...
22 *
23 * Set up the memory map,
24 * initialize a bunch of registers,
25 * initialize the UPM's
26 */
27void cpu_init_f(void)
28{
Alison Wang849fc422012-03-26 21:49:03 +000029 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
Alison Wang7adbd11e2012-10-21 21:27:48 +000030 fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
TsiChungLiewc8758102008-01-14 17:46:19 -060031
TsiChung Liewa21d0c22008-10-21 15:37:02 +000032#if !defined(CONFIG_CF_SBF)
Alison Wang7adbd11e2012-10-21 21:27:48 +000033 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
34 pll_t *pll = (pll_t *)MMAP_PLL;
35
TsiChungLiewc8758102008-01-14 17:46:19 -060036 /* Workaround, must place before fbcs */
Alison Wang849fc422012-03-26 21:49:03 +000037 out_be32(&pll->psr, 0x12);
TsiChungLiewc8758102008-01-14 17:46:19 -060038
Alison Wang849fc422012-03-26 21:49:03 +000039 out_be32(&scm1->mpr, 0x77777777);
40 out_be32(&scm1->pacra, 0);
41 out_be32(&scm1->pacrb, 0);
42 out_be32(&scm1->pacrc, 0);
43 out_be32(&scm1->pacrd, 0);
44 out_be32(&scm1->pacre, 0);
45 out_be32(&scm1->pacrf, 0);
46 out_be32(&scm1->pacrg, 0);
47 out_be32(&scm1->pacri, 0);
TsiChungLiewc8758102008-01-14 17:46:19 -060048
TsiChung Liewa21d0c22008-10-21 15:37:02 +000049#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
50 && defined(CONFIG_SYS_CS0_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000051 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
52 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
53 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060054#endif
TsiChung Liewa21d0c22008-10-21 15:37:02 +000055#endif /* CONFIG_CF_SBF */
TsiChungLiewc8758102008-01-14 17:46:19 -060056
TsiChung Liewa21d0c22008-10-21 15:37:02 +000057#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
58 && defined(CONFIG_SYS_CS1_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000059 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
60 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
61 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060062#endif
63
TsiChung Liewa21d0c22008-10-21 15:37:02 +000064#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
65 && defined(CONFIG_SYS_CS2_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000066 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
67 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
68 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060069#endif
70
TsiChung Liewa21d0c22008-10-21 15:37:02 +000071#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
72 && defined(CONFIG_SYS_CS3_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000073 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
74 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
75 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060076#endif
77
TsiChung Liewa21d0c22008-10-21 15:37:02 +000078#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
79 && defined(CONFIG_SYS_CS4_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000080 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
81 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
82 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060083#endif
84
TsiChung Liewa21d0c22008-10-21 15:37:02 +000085#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
86 && defined(CONFIG_SYS_CS5_CTRL))
Alison Wang849fc422012-03-26 21:49:03 +000087 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
88 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
89 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewc8758102008-01-14 17:46:19 -060090#endif
91
Heiko Schocher00f792e2012-10-24 13:48:22 +020092#ifdef CONFIG_SYS_I2C_FSL
Alison Wang849fc422012-03-26 21:49:03 +000093 out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
TsiChungLiewc8758102008-01-14 17:46:19 -060094#endif
95
96 icache_enable();
97}
98
99/*
100 * initialize higher level parts of CPU like timers
101 */
102int cpu_init_r(void)
103{
TsiChung Liewbc3ccb12008-07-09 15:47:27 -0500104#ifdef CONFIG_MCFRTC
Alison Wang849fc422012-03-26 21:49:03 +0000105 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
106 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
TsiChungLiewc8758102008-01-14 17:46:19 -0600107
Alison Wang849fc422012-03-26 21:49:03 +0000108 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
109 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
TsiChungLiewc8758102008-01-14 17:46:19 -0600110#endif
111
112 return (0);
113}
114
TsiChung Liew52affe02010-03-09 19:17:52 -0600115void uart_port_conf(int port)
TsiChungLiewc8758102008-01-14 17:46:19 -0600116{
Alison Wang849fc422012-03-26 21:49:03 +0000117 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewc8758102008-01-14 17:46:19 -0600118
119 /* Setup Ports: */
TsiChung Liew52affe02010-03-09 19:17:52 -0600120 switch (port) {
TsiChungLiewc8758102008-01-14 17:46:19 -0600121 case 0:
Alison Wang849fc422012-03-26 21:49:03 +0000122 clrbits_be16(&gpio->par_uart,
123 ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
124 setbits_be16(&gpio->par_uart,
125 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
TsiChungLiewc8758102008-01-14 17:46:19 -0600126 break;
127 case 1:
Alison Wang849fc422012-03-26 21:49:03 +0000128 clrbits_be16(&gpio->par_uart,
129 ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
130 setbits_be16(&gpio->par_uart,
131 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChungLiewc8758102008-01-14 17:46:19 -0600132 break;
133 case 2:
Alison Wang849fc422012-03-26 21:49:03 +0000134 clrbits_8(&gpio->par_dspi,
135 ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
136 out_8(&gpio->par_dspi,
137 GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
TsiChungLiewc8758102008-01-14 17:46:19 -0600138 break;
139 }
140}
TsiChung Liewee0a8462009-06-30 14:18:29 +0000141
142#ifdef CONFIG_CF_DSPI
143void cfspi_port_conf(void)
144{
Alison Wang849fc422012-03-26 21:49:03 +0000145 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000146
Alison Wang849fc422012-03-26 21:49:03 +0000147 out_8(&gpio->par_dspi,
148 GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
149 GPIO_PAR_DSPI_SCK_SCK);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000150}
151
152int cfspi_claim_bus(uint bus, uint cs)
153{
Alison Wang849fc422012-03-26 21:49:03 +0000154 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
155 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000156
Alison Wang849fc422012-03-26 21:49:03 +0000157 if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
TsiChung Liewee0a8462009-06-30 14:18:29 +0000158 return -1;
159
160 /* Clear FIFO and resume transfer */
Alison Wang849fc422012-03-26 21:49:03 +0000161 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000162
163 switch (cs) {
164 case 0:
Alison Wang849fc422012-03-26 21:49:03 +0000165 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK);
166 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000167 break;
168 case 2:
Alison Wang849fc422012-03-26 21:49:03 +0000169 clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
170 setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000171 break;
172 }
173
174 return 0;
175}
176
177void cfspi_release_bus(uint bus, uint cs)
178{
Alison Wang849fc422012-03-26 21:49:03 +0000179 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
180 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewee0a8462009-06-30 14:18:29 +0000181
Alison Wang849fc422012-03-26 21:49:03 +0000182 /* Clear FIFO */
183 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000184
185 switch (cs) {
186 case 0:
Alison Wang849fc422012-03-26 21:49:03 +0000187 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000188 break;
189 case 2:
Alison Wang849fc422012-03-26 21:49:03 +0000190 clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
TsiChung Liewee0a8462009-06-30 14:18:29 +0000191 break;
192 }
193}
194#endif