blob: 0d6a484a4538ed0bcc99774be3bce58a6dee6519 [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>
12#include <watchdog.h>
13
14#include <asm/immap.h>
Alison Wang8bce3ec2012-03-26 21:49:03 +000015#include <asm/io.h>
TsiChungLiewae831cd2008-01-14 17:46:19 -060016#include <asm/rtc.h>
Alison Wang0c6c4442012-10-21 21:27:48 +000017#include <linux/compiler.h>
TsiChungLiewae831cd2008-01-14 17:46:19 -060018
19/*
20 * Breath some life into the CPU...
21 *
22 * Set up the memory map,
23 * initialize a bunch of registers,
24 * initialize the UPM's
25 */
26void cpu_init_f(void)
27{
Alison Wang8bce3ec2012-03-26 21:49:03 +000028 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
Alison Wang0c6c4442012-10-21 21:27:48 +000029 fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
TsiChungLiewae831cd2008-01-14 17:46:19 -060030
TsiChung Liew39966e32008-10-21 15:37:02 +000031#if !defined(CONFIG_CF_SBF)
Alison Wang0c6c4442012-10-21 21:27:48 +000032 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
33 pll_t *pll = (pll_t *)MMAP_PLL;
34
TsiChungLiewae831cd2008-01-14 17:46:19 -060035 /* Workaround, must place before fbcs */
Alison Wang8bce3ec2012-03-26 21:49:03 +000036 out_be32(&pll->psr, 0x12);
TsiChungLiewae831cd2008-01-14 17:46:19 -060037
Alison Wang8bce3ec2012-03-26 21:49:03 +000038 out_be32(&scm1->mpr, 0x77777777);
39 out_be32(&scm1->pacra, 0);
40 out_be32(&scm1->pacrb, 0);
41 out_be32(&scm1->pacrc, 0);
42 out_be32(&scm1->pacrd, 0);
43 out_be32(&scm1->pacre, 0);
44 out_be32(&scm1->pacrf, 0);
45 out_be32(&scm1->pacrg, 0);
46 out_be32(&scm1->pacri, 0);
TsiChungLiewae831cd2008-01-14 17:46:19 -060047
TsiChung Liew39966e32008-10-21 15:37:02 +000048#if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
49 && defined(CONFIG_SYS_CS0_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000050 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
51 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
52 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060053#endif
TsiChung Liew39966e32008-10-21 15:37:02 +000054#endif /* CONFIG_CF_SBF */
TsiChungLiewae831cd2008-01-14 17:46:19 -060055
TsiChung Liew39966e32008-10-21 15:37:02 +000056#if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
57 && defined(CONFIG_SYS_CS1_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000058 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
59 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
60 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060061#endif
62
TsiChung Liew39966e32008-10-21 15:37:02 +000063#if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
64 && defined(CONFIG_SYS_CS2_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000065 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
66 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
67 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060068#endif
69
TsiChung Liew39966e32008-10-21 15:37:02 +000070#if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
71 && defined(CONFIG_SYS_CS3_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000072 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
73 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
74 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060075#endif
76
TsiChung Liew39966e32008-10-21 15:37:02 +000077#if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
78 && defined(CONFIG_SYS_CS4_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000079 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
80 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
81 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060082#endif
83
TsiChung Liew39966e32008-10-21 15:37:02 +000084#if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
85 && defined(CONFIG_SYS_CS5_CTRL))
Alison Wang8bce3ec2012-03-26 21:49:03 +000086 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
87 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
88 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
TsiChungLiewae831cd2008-01-14 17:46:19 -060089#endif
90
Heiko Schocherf2850742012-10-24 13:48:22 +020091#ifdef CONFIG_SYS_I2C_FSL
Alison Wang8bce3ec2012-03-26 21:49:03 +000092 out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
TsiChungLiewae831cd2008-01-14 17:46:19 -060093#endif
94
95 icache_enable();
96}
97
98/*
99 * initialize higher level parts of CPU like timers
100 */
101int cpu_init_r(void)
102{
TsiChung Liew1be9e092008-07-09 15:47:27 -0500103#ifdef CONFIG_MCFRTC
Alison Wang8bce3ec2012-03-26 21:49:03 +0000104 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
105 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
TsiChungLiewae831cd2008-01-14 17:46:19 -0600106
Alison Wang8bce3ec2012-03-26 21:49:03 +0000107 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
108 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600109#endif
110
111 return (0);
112}
113
TsiChung Liewf9556a72010-03-09 19:17:52 -0600114void uart_port_conf(int port)
TsiChungLiewae831cd2008-01-14 17:46:19 -0600115{
Alison Wang8bce3ec2012-03-26 21:49:03 +0000116 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewae831cd2008-01-14 17:46:19 -0600117
118 /* Setup Ports: */
TsiChung Liewf9556a72010-03-09 19:17:52 -0600119 switch (port) {
TsiChungLiewae831cd2008-01-14 17:46:19 -0600120 case 0:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000121 clrbits_be16(&gpio->par_uart,
122 ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
123 setbits_be16(&gpio->par_uart,
124 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600125 break;
126 case 1:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000127 clrbits_be16(&gpio->par_uart,
128 ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
129 setbits_be16(&gpio->par_uart,
130 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600131 break;
132 case 2:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000133 clrbits_8(&gpio->par_dspi,
134 ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
135 out_8(&gpio->par_dspi,
136 GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
TsiChungLiewae831cd2008-01-14 17:46:19 -0600137 break;
138 }
139}
TsiChung Liewa424ba22009-06-30 14:18:29 +0000140
141#ifdef CONFIG_CF_DSPI
142void cfspi_port_conf(void)
143{
Alison Wang8bce3ec2012-03-26 21:49:03 +0000144 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000145
Alison Wang8bce3ec2012-03-26 21:49:03 +0000146 out_8(&gpio->par_dspi,
147 GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
148 GPIO_PAR_DSPI_SCK_SCK);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000149}
150
151int cfspi_claim_bus(uint bus, uint cs)
152{
Alison Wang8bce3ec2012-03-26 21:49:03 +0000153 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
154 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000155
Alison Wang8bce3ec2012-03-26 21:49:03 +0000156 if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
TsiChung Liewa424ba22009-06-30 14:18:29 +0000157 return -1;
158
159 /* Clear FIFO and resume transfer */
Alison Wang8bce3ec2012-03-26 21:49:03 +0000160 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000161
162 switch (cs) {
163 case 0:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000164 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK);
165 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000166 break;
167 case 2:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000168 clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
169 setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000170 break;
171 }
172
173 return 0;
174}
175
176void cfspi_release_bus(uint bus, uint cs)
177{
Alison Wang8bce3ec2012-03-26 21:49:03 +0000178 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
179 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChung Liewa424ba22009-06-30 14:18:29 +0000180
Alison Wang8bce3ec2012-03-26 21:49:03 +0000181 /* Clear FIFO */
182 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000183
184 switch (cs) {
185 case 0:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000186 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000187 break;
188 case 2:
Alison Wang8bce3ec2012-03-26 21:49:03 +0000189 clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
TsiChung Liewa424ba22009-06-30 14:18:29 +0000190 break;
191 }
192}
193#endif