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