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