Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 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 |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 8 | #include <config.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 10 | #include <serial.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 11 | #include <time.h> |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 12 | #include <watchdog.h> |
| 13 | #include <command.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 15 | #include <asm/m5329.h> |
| 16 | #include <asm/immap_5329.h> |
| 17 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 18 | #include <linux/delay.h> |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 19 | |
| 20 | /* needed for astro bus: */ |
| 21 | #include <asm/uart.h> |
| 22 | #include "astro.h" |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | extern void uart_port_conf(void); |
| 26 | |
| 27 | int checkboard(void) |
| 28 | { |
| 29 | puts("Board: "); |
| 30 | puts("ASTRO MCF5373L (Urmel) Board\n"); |
| 31 | return 0; |
| 32 | } |
| 33 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 34 | int dram_init(void) |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 35 | { |
| 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 Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 43 | * so use CFG_SYS_SDRAM_BASE as the base address for SDRAM, |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 44 | * and do not care where it is |
| 45 | */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 46 | __raw_writel((CFG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000018, |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 47 | &sdp->cs0); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 48 | __raw_writel((CFG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000000, |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 49 | &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 Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 76 | writel(0, CFG_SYS_SDRAM_BASE); |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 77 | #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 Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 86 | gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE, |
| 87 | 0x80000000 - CFG_SYS_SDRAM_BASE); |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 88 | |
| 89 | return 0; |
Wolfgang Wegner | 406471c | 2010-01-25 11:27:44 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | #define UART_BASE MMAP_UART0 |
| 93 | int 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 | |
| 143 | void 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 | |
| 163 | int 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 | |
| 171 | int 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 | |
| 180 | int 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 | } |