mcf5373l.c 4.4 KB

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