1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
29d79e575SWolfgang Wegner /*
39d79e575SWolfgang Wegner * (C) Copyright 2000-2003
49d79e575SWolfgang Wegner * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
59d79e575SWolfgang Wegner * modified by Wolfgang Wegner <w.wegner@astro-kom.de> for ASTRO 5373l
69d79e575SWolfgang Wegner */
79d79e575SWolfgang Wegner
89d79e575SWolfgang Wegner #include <common.h>
99d79e575SWolfgang Wegner #include <watchdog.h>
109d79e575SWolfgang Wegner #include <command.h>
119d79e575SWolfgang Wegner #include <asm/m5329.h>
129d79e575SWolfgang Wegner #include <asm/immap_5329.h>
139d79e575SWolfgang Wegner #include <asm/io.h>
149d79e575SWolfgang Wegner
159d79e575SWolfgang Wegner /* needed for astro bus: */
169d79e575SWolfgang Wegner #include <asm/uart.h>
179d79e575SWolfgang Wegner #include "astro.h"
189d79e575SWolfgang Wegner
199d79e575SWolfgang Wegner DECLARE_GLOBAL_DATA_PTR;
209d79e575SWolfgang Wegner extern void uart_port_conf(void);
219d79e575SWolfgang Wegner
checkboard(void)229d79e575SWolfgang Wegner int checkboard(void)
239d79e575SWolfgang Wegner {
249d79e575SWolfgang Wegner puts("Board: ");
259d79e575SWolfgang Wegner puts("ASTRO MCF5373L (Urmel) Board\n");
269d79e575SWolfgang Wegner return 0;
279d79e575SWolfgang Wegner }
289d79e575SWolfgang Wegner
dram_init(void)29f1683aa7SSimon Glass int dram_init(void)
309d79e575SWolfgang Wegner {
319d79e575SWolfgang Wegner #if !defined(CONFIG_MONITOR_IS_IN_RAM)
329d79e575SWolfgang Wegner sdram_t *sdp = (sdram_t *)(MMAP_SDRAM);
339d79e575SWolfgang Wegner
349d79e575SWolfgang Wegner /*
359d79e575SWolfgang Wegner * GPIO configuration for bus should be set correctly from reset,
369d79e575SWolfgang Wegner * so we do not care! First, set up address space: at this point,
379d79e575SWolfgang Wegner * we should be running from internal SRAM;
389d79e575SWolfgang Wegner * so use CONFIG_SYS_SDRAM_BASE as the base address for SDRAM,
399d79e575SWolfgang Wegner * and do not care where it is
409d79e575SWolfgang Wegner */
419d79e575SWolfgang Wegner __raw_writel((CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000018,
429d79e575SWolfgang Wegner &sdp->cs0);
439d79e575SWolfgang Wegner __raw_writel((CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000000,
449d79e575SWolfgang Wegner &sdp->cs1);
459d79e575SWolfgang Wegner /*
469d79e575SWolfgang Wegner * I am not sure from the data sheet, but it seems burst length
479d79e575SWolfgang Wegner * has to be 8 for the 16 bit data bus we use;
489d79e575SWolfgang Wegner * so these values are for BL = 8
499d79e575SWolfgang Wegner */
509d79e575SWolfgang Wegner __raw_writel(0x33211530, &sdp->cfg1);
519d79e575SWolfgang Wegner __raw_writel(0x56570000, &sdp->cfg2);
529d79e575SWolfgang Wegner /* send PrechargeALL, REF and IREF remain cleared! */
539d79e575SWolfgang Wegner __raw_writel(0xE1462C02, &sdp->ctrl);
549d79e575SWolfgang Wegner udelay(1);
559d79e575SWolfgang Wegner /* refresh SDRAM twice */
569d79e575SWolfgang Wegner __raw_writel(0xE1462C04, &sdp->ctrl);
579d79e575SWolfgang Wegner udelay(1);
589d79e575SWolfgang Wegner __raw_writel(0xE1462C04, &sdp->ctrl);
599d79e575SWolfgang Wegner /* init MR */
609d79e575SWolfgang Wegner __raw_writel(0x008D0000, &sdp->mode);
619d79e575SWolfgang Wegner /* initialize EMR */
629d79e575SWolfgang Wegner __raw_writel(0x80010000, &sdp->mode);
639d79e575SWolfgang Wegner /* wait until DLL is locked */
649d79e575SWolfgang Wegner udelay(1);
659d79e575SWolfgang Wegner /*
669d79e575SWolfgang Wegner * enable automatic refresh, lock mode register,
679d79e575SWolfgang Wegner * clear iref and ipall
689d79e575SWolfgang Wegner */
699d79e575SWolfgang Wegner __raw_writel(0x71462C00, &sdp->ctrl);
709d79e575SWolfgang Wegner /* Dummy write to start SDRAM */
719d79e575SWolfgang Wegner writel(0, CONFIG_SYS_SDRAM_BASE);
729d79e575SWolfgang Wegner #endif
739d79e575SWolfgang Wegner
749d79e575SWolfgang Wegner /*
759d79e575SWolfgang Wegner * for get_ram_size() to work, both CS areas have to be
769d79e575SWolfgang Wegner * configured, i.e. CS1 has to be explicitely disabled, else
779d79e575SWolfgang Wegner * probing for memory will cause the SDRAM bus to hang!
789d79e575SWolfgang Wegner * (Do not rely on the SDCS register(s) being set to 0x00000000
799d79e575SWolfgang Wegner * during reset as stated in the data sheet.)
809d79e575SWolfgang Wegner */
81088454cdSSimon Glass gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
829d79e575SWolfgang Wegner 0x80000000 - CONFIG_SYS_SDRAM_BASE);
83088454cdSSimon Glass
84088454cdSSimon Glass return 0;
859d79e575SWolfgang Wegner }
869d79e575SWolfgang Wegner
879d79e575SWolfgang Wegner #define UART_BASE MMAP_UART0
rs_serial_init(int port,int baud)889d79e575SWolfgang Wegner int rs_serial_init(int port, int baud)
899d79e575SWolfgang Wegner {
909d79e575SWolfgang Wegner uart_t *uart;
919d79e575SWolfgang Wegner u32 counter;
929d79e575SWolfgang Wegner
939d79e575SWolfgang Wegner switch (port) {
949d79e575SWolfgang Wegner case 0:
959d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART0);
969d79e575SWolfgang Wegner break;
979d79e575SWolfgang Wegner case 1:
989d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART1);
999d79e575SWolfgang Wegner break;
1009d79e575SWolfgang Wegner case 2:
1019d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART2);
1029d79e575SWolfgang Wegner break;
1039d79e575SWolfgang Wegner default:
1049d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART0);
1059d79e575SWolfgang Wegner }
1069d79e575SWolfgang Wegner
1079d79e575SWolfgang Wegner uart_port_conf();
1089d79e575SWolfgang Wegner
1099d79e575SWolfgang Wegner /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
1109d79e575SWolfgang Wegner writeb(UART_UCR_RESET_RX, &uart->ucr);
1119d79e575SWolfgang Wegner writeb(UART_UCR_RESET_TX, &uart->ucr);
1129d79e575SWolfgang Wegner writeb(UART_UCR_RESET_ERROR, &uart->ucr);
1139d79e575SWolfgang Wegner writeb(UART_UCR_RESET_MR, &uart->ucr);
1149d79e575SWolfgang Wegner __asm__ ("nop");
1159d79e575SWolfgang Wegner
1169d79e575SWolfgang Wegner writeb(0, &uart->uimr);
1179d79e575SWolfgang Wegner
1189d79e575SWolfgang Wegner /* write to CSR: RX/TX baud rate from timers */
1199d79e575SWolfgang Wegner writeb(UART_UCSR_RCS_SYS_CLK | UART_UCSR_TCS_SYS_CLK, &uart->ucsr);
1209d79e575SWolfgang Wegner
1219d79e575SWolfgang Wegner writeb(UART_UMR_BC_8 | UART_UMR_PM_NONE, &uart->umr);
1229d79e575SWolfgang Wegner writeb(UART_UMR_SB_STOP_BITS_1, &uart->umr);
1239d79e575SWolfgang Wegner
1249d79e575SWolfgang Wegner /* Setting up BaudRate */
1259d79e575SWolfgang Wegner counter = (u32) (gd->bus_clk / (baud));
1269d79e575SWolfgang Wegner counter >>= 5;
1279d79e575SWolfgang Wegner
1289d79e575SWolfgang Wegner /* write to CTUR: divide counter upper byte */
1299d79e575SWolfgang Wegner writeb((u8) ((counter & 0xff00) >> 8), &uart->ubg1);
1309d79e575SWolfgang Wegner /* write to CTLR: divide counter lower byte */
1319d79e575SWolfgang Wegner writeb((u8) (counter & 0x00ff), &uart->ubg2);
1329d79e575SWolfgang Wegner
1339d79e575SWolfgang Wegner writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
1349d79e575SWolfgang Wegner
1359d79e575SWolfgang Wegner return 0;
1369d79e575SWolfgang Wegner }
1379d79e575SWolfgang Wegner
astro_put_char(char ch)1389d79e575SWolfgang Wegner void astro_put_char(char ch)
1399d79e575SWolfgang Wegner {
1409d79e575SWolfgang Wegner uart_t *uart;
1419d79e575SWolfgang Wegner unsigned long timer;
1429d79e575SWolfgang Wegner
1439d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART0);
1449d79e575SWolfgang Wegner /*
1459d79e575SWolfgang Wegner * Wait for last character to go. Timeout of 6ms should
1469d79e575SWolfgang Wegner * be enough for our lowest baud rate of 2400.
1479d79e575SWolfgang Wegner */
1489d79e575SWolfgang Wegner timer = get_timer(0);
1499d79e575SWolfgang Wegner while (get_timer(timer) < 6) {
1509d79e575SWolfgang Wegner if (readb(&uart->usr) & UART_USR_TXRDY)
1519d79e575SWolfgang Wegner break;
1529d79e575SWolfgang Wegner }
1539d79e575SWolfgang Wegner writeb(ch, &uart->utb);
1549d79e575SWolfgang Wegner
1559d79e575SWolfgang Wegner return;
1569d79e575SWolfgang Wegner }
1579d79e575SWolfgang Wegner
astro_is_char(void)1589d79e575SWolfgang Wegner int astro_is_char(void)
1599d79e575SWolfgang Wegner {
1609d79e575SWolfgang Wegner uart_t *uart;
1619d79e575SWolfgang Wegner
1629d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART0);
1639d79e575SWolfgang Wegner return readb(&uart->usr) & UART_USR_RXRDY;
1649d79e575SWolfgang Wegner }
1659d79e575SWolfgang Wegner
astro_get_char(void)1669d79e575SWolfgang Wegner int astro_get_char(void)
1679d79e575SWolfgang Wegner {
1689d79e575SWolfgang Wegner uart_t *uart;
1699d79e575SWolfgang Wegner
1709d79e575SWolfgang Wegner uart = (uart_t *)(MMAP_UART0);
1719d79e575SWolfgang Wegner while (!(readb(&uart->usr) & UART_USR_RXRDY)) ;
1729d79e575SWolfgang Wegner return readb(&uart->urb);
1739d79e575SWolfgang Wegner }
1749d79e575SWolfgang Wegner
misc_init_r(void)1759d79e575SWolfgang Wegner int misc_init_r(void)
1769d79e575SWolfgang Wegner {
1779d79e575SWolfgang Wegner int retval = 0;
1789d79e575SWolfgang Wegner
1799d79e575SWolfgang Wegner puts("Configure Xilinx FPGA...");
1809d79e575SWolfgang Wegner retval = astro5373l_xilinx_load();
1819d79e575SWolfgang Wegner if (!retval) {
1829d79e575SWolfgang Wegner puts("failed!\n");
1839d79e575SWolfgang Wegner return retval;
1849d79e575SWolfgang Wegner }
1859d79e575SWolfgang Wegner puts("done\n");
1869d79e575SWolfgang Wegner
1879d79e575SWolfgang Wegner puts("Configure Altera FPGA...");
1889d79e575SWolfgang Wegner retval = astro5373l_altera_load();
1899d79e575SWolfgang Wegner if (!retval) {
1909d79e575SWolfgang Wegner puts("failed!\n");
1919d79e575SWolfgang Wegner return retval;
1929d79e575SWolfgang Wegner }
1939d79e575SWolfgang Wegner puts("done\n");
1949d79e575SWolfgang Wegner
1959d79e575SWolfgang Wegner return retval;
1969d79e575SWolfgang Wegner }
197