blob: 43fcbc65513dc4bf515e8907b4f34ca1b5e414cc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wolfgang Wegner406471c2010-01-25 11:27:44 +01002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * modified by Wolfgang Wegner <w.wegner@astro-kom.de> for ASTRO 5373l
Wolfgang Wegner406471c2010-01-25 11:27:44 +01006 */
7
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <config.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -07009#include <init.h>
Simon Glass36736182019-11-14 12:57:24 -070010#include <serial.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060011#include <time.h>
Wolfgang Wegner406471c2010-01-25 11:27:44 +010012#include <watchdog.h>
13#include <command.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Wolfgang Wegner406471c2010-01-25 11:27:44 +010015#include <asm/m5329.h>
16#include <asm/immap_5329.h>
17#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Wolfgang Wegner406471c2010-01-25 11:27:44 +010019
20/* needed for astro bus: */
21#include <asm/uart.h>
22#include "astro.h"
23
24DECLARE_GLOBAL_DATA_PTR;
25extern void uart_port_conf(void);
26
27int checkboard(void)
28{
29 puts("Board: ");
30 puts("ASTRO MCF5373L (Urmel) Board\n");
31 return 0;
32}
33
Simon Glassd35f3382017-04-06 12:47:05 -060034int dram_init(void)
Wolfgang Wegner406471c2010-01-25 11:27:44 +010035{
36#if !defined(CONFIG_MONITOR_IS_IN_RAM)
37 sdram_t *sdp = (sdram_t *)(MMAP_SDRAM);
38
39 /*
40 * GPIO configuration for bus should be set correctly from reset,
41 * so we do not care! First, set up address space: at this point,
42 * we should be running from internal SRAM;
Tom Rinibb4dd962022-11-16 13:10:37 -050043 * so use CFG_SYS_SDRAM_BASE as the base address for SDRAM,
Wolfgang Wegner406471c2010-01-25 11:27:44 +010044 * and do not care where it is
45 */
Tom Rinibb4dd962022-11-16 13:10:37 -050046 __raw_writel((CFG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000018,
Wolfgang Wegner406471c2010-01-25 11:27:44 +010047 &sdp->cs0);
Tom Rinibb4dd962022-11-16 13:10:37 -050048 __raw_writel((CFG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000000,
Wolfgang Wegner406471c2010-01-25 11:27:44 +010049 &sdp->cs1);
50 /*
51 * I am not sure from the data sheet, but it seems burst length
52 * has to be 8 for the 16 bit data bus we use;
53 * so these values are for BL = 8
54 */
55 __raw_writel(0x33211530, &sdp->cfg1);
56 __raw_writel(0x56570000, &sdp->cfg2);
57 /* send PrechargeALL, REF and IREF remain cleared! */
58 __raw_writel(0xE1462C02, &sdp->ctrl);
59 udelay(1);
60 /* refresh SDRAM twice */
61 __raw_writel(0xE1462C04, &sdp->ctrl);
62 udelay(1);
63 __raw_writel(0xE1462C04, &sdp->ctrl);
64 /* init MR */
65 __raw_writel(0x008D0000, &sdp->mode);
66 /* initialize EMR */
67 __raw_writel(0x80010000, &sdp->mode);
68 /* wait until DLL is locked */
69 udelay(1);
70 /*
71 * enable automatic refresh, lock mode register,
72 * clear iref and ipall
73 */
74 __raw_writel(0x71462C00, &sdp->ctrl);
75 /* Dummy write to start SDRAM */
Tom Rinibb4dd962022-11-16 13:10:37 -050076 writel(0, CFG_SYS_SDRAM_BASE);
Wolfgang Wegner406471c2010-01-25 11:27:44 +010077#endif
78
79 /*
80 * for get_ram_size() to work, both CS areas have to be
81 * configured, i.e. CS1 has to be explicitely disabled, else
82 * probing for memory will cause the SDRAM bus to hang!
83 * (Do not rely on the SDCS register(s) being set to 0x00000000
84 * during reset as stated in the data sheet.)
85 */
Tom Rinibb4dd962022-11-16 13:10:37 -050086 gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE,
87 0x80000000 - CFG_SYS_SDRAM_BASE);
Simon Glass39f90ba2017-03-31 08:40:25 -060088
89 return 0;
Wolfgang Wegner406471c2010-01-25 11:27:44 +010090}
91
92#define UART_BASE MMAP_UART0
93int rs_serial_init(int port, int baud)
94{
95 uart_t *uart;
96 u32 counter;
97
98 switch (port) {
99 case 0:
100 uart = (uart_t *)(MMAP_UART0);
101 break;
102 case 1:
103 uart = (uart_t *)(MMAP_UART1);
104 break;
105 case 2:
106 uart = (uart_t *)(MMAP_UART2);
107 break;
108 default:
109 uart = (uart_t *)(MMAP_UART0);
110 }
111
112 uart_port_conf();
113
114 /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
115 writeb(UART_UCR_RESET_RX, &uart->ucr);
116 writeb(UART_UCR_RESET_TX, &uart->ucr);
117 writeb(UART_UCR_RESET_ERROR, &uart->ucr);
118 writeb(UART_UCR_RESET_MR, &uart->ucr);
119 __asm__ ("nop");
120
121 writeb(0, &uart->uimr);
122
123 /* write to CSR: RX/TX baud rate from timers */
124 writeb(UART_UCSR_RCS_SYS_CLK | UART_UCSR_TCS_SYS_CLK, &uart->ucsr);
125
126 writeb(UART_UMR_BC_8 | UART_UMR_PM_NONE, &uart->umr);
127 writeb(UART_UMR_SB_STOP_BITS_1, &uart->umr);
128
129 /* Setting up BaudRate */
130 counter = (u32) (gd->bus_clk / (baud));
131 counter >>= 5;
132
133 /* write to CTUR: divide counter upper byte */
134 writeb((u8) ((counter & 0xff00) >> 8), &uart->ubg1);
135 /* write to CTLR: divide counter lower byte */
136 writeb((u8) (counter & 0x00ff), &uart->ubg2);
137
138 writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
139
140 return 0;
141}
142
143void astro_put_char(char ch)
144{
145 uart_t *uart;
146 unsigned long timer;
147
148 uart = (uart_t *)(MMAP_UART0);
149 /*
150 * Wait for last character to go. Timeout of 6ms should
151 * be enough for our lowest baud rate of 2400.
152 */
153 timer = get_timer(0);
154 while (get_timer(timer) < 6) {
155 if (readb(&uart->usr) & UART_USR_TXRDY)
156 break;
157 }
158 writeb(ch, &uart->utb);
159
160 return;
161}
162
163int astro_is_char(void)
164{
165 uart_t *uart;
166
167 uart = (uart_t *)(MMAP_UART0);
168 return readb(&uart->usr) & UART_USR_RXRDY;
169}
170
171int astro_get_char(void)
172{
173 uart_t *uart;
174
175 uart = (uart_t *)(MMAP_UART0);
176 while (!(readb(&uart->usr) & UART_USR_RXRDY)) ;
177 return readb(&uart->urb);
178}
179
180int misc_init_r(void)
181{
182 int retval = 0;
183
184 puts("Configure Xilinx FPGA...");
185 retval = astro5373l_xilinx_load();
186 if (!retval) {
187 puts("failed!\n");
188 return retval;
189 }
190 puts("done\n");
191
192 puts("Configure Altera FPGA...");
193 retval = astro5373l_altera_load();
194 if (!retval) {
195 puts("failed!\n");
196 return retval;
197 }
198 puts("done\n");
199
200 return retval;
201}