mcf5373l.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <watchdog.h>
  26. #include <command.h>
  27. #include <asm/m5329.h>
  28. #include <asm/immap_5329.h>
  29. #include <asm/io.h>
  30. /* needed for astro bus: */
  31. #include <asm/uart.h>
  32. #include "astro.h"
  33. DECLARE_GLOBAL_DATA_PTR;
  34. extern void uart_port_conf(void);
  35. int checkboard(void)
  36. {
  37. puts("Board: ");
  38. puts("ASTRO MCF5373L (Urmel) Board\n");
  39. return 0;
  40. }
  41. phys_size_t initdram(int board_type)
  42. {
  43. #if !defined(CONFIG_MONITOR_IS_IN_RAM)
  44. sdram_t *sdp = (sdram_t *)(MMAP_SDRAM);
  45. /*
  46. * GPIO configuration for bus should be set correctly from reset,
  47. * so we do not care! First, set up address space: at this point,
  48. * we should be running from internal SRAM;
  49. * so use CONFIG_SYS_SDRAM_BASE as the base address for SDRAM,
  50. * and do not care where it is
  51. */
  52. __raw_writel((CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000018,
  53. &sdp->cs0);
  54. __raw_writel((CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | 0x00000000,
  55. &sdp->cs1);
  56. /*
  57. * I am not sure from the data sheet, but it seems burst length
  58. * has to be 8 for the 16 bit data bus we use;
  59. * so these values are for BL = 8
  60. */
  61. __raw_writel(0x33211530, &sdp->cfg1);
  62. __raw_writel(0x56570000, &sdp->cfg2);
  63. /* send PrechargeALL, REF and IREF remain cleared! */
  64. __raw_writel(0xE1462C02, &sdp->ctrl);
  65. udelay(1);
  66. /* refresh SDRAM twice */
  67. __raw_writel(0xE1462C04, &sdp->ctrl);
  68. udelay(1);
  69. __raw_writel(0xE1462C04, &sdp->ctrl);
  70. /* init MR */
  71. __raw_writel(0x008D0000, &sdp->mode);
  72. /* initialize EMR */
  73. __raw_writel(0x80010000, &sdp->mode);
  74. /* wait until DLL is locked */
  75. udelay(1);
  76. /*
  77. * enable automatic refresh, lock mode register,
  78. * clear iref and ipall
  79. */
  80. __raw_writel(0x71462C00, &sdp->ctrl);
  81. /* Dummy write to start SDRAM */
  82. writel(0, CONFIG_SYS_SDRAM_BASE);
  83. #endif
  84. /*
  85. * for get_ram_size() to work, both CS areas have to be
  86. * configured, i.e. CS1 has to be explicitely disabled, else
  87. * probing for memory will cause the SDRAM bus to hang!
  88. * (Do not rely on the SDCS register(s) being set to 0x00000000
  89. * during reset as stated in the data sheet.)
  90. */
  91. return get_ram_size((unsigned long *)CONFIG_SYS_SDRAM_BASE,
  92. 0x80000000 - CONFIG_SYS_SDRAM_BASE);
  93. }
  94. #define UART_BASE MMAP_UART0
  95. int rs_serial_init(int port, int baud)
  96. {
  97. uart_t *uart;
  98. u32 counter;
  99. switch (port) {
  100. case 0:
  101. uart = (uart_t *)(MMAP_UART0);
  102. break;
  103. case 1:
  104. uart = (uart_t *)(MMAP_UART1);
  105. break;
  106. case 2:
  107. uart = (uart_t *)(MMAP_UART2);
  108. break;
  109. default:
  110. uart = (uart_t *)(MMAP_UART0);
  111. }
  112. uart_port_conf();
  113. /* write to SICR: SIM2 = uart mode,dcd does not affect rx */
  114. writeb(UART_UCR_RESET_RX, &uart->ucr);
  115. writeb(UART_UCR_RESET_TX, &uart->ucr);
  116. writeb(UART_UCR_RESET_ERROR, &uart->ucr);
  117. writeb(UART_UCR_RESET_MR, &uart->ucr);
  118. __asm__ ("nop");
  119. writeb(0, &uart->uimr);
  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. writeb(UART_UMR_BC_8 | UART_UMR_PM_NONE, &uart->umr);
  123. writeb(UART_UMR_SB_STOP_BITS_1, &uart->umr);
  124. /* Setting up BaudRate */
  125. counter = (u32) (gd->bus_clk / (baud));
  126. counter >>= 5;
  127. /* write to CTUR: divide counter upper byte */
  128. writeb((u8) ((counter & 0xff00) >> 8), &uart->ubg1);
  129. /* write to CTLR: divide counter lower byte */
  130. writeb((u8) (counter & 0x00ff), &uart->ubg2);
  131. writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
  132. return 0;
  133. }
  134. void astro_put_char(char ch)
  135. {
  136. uart_t *uart;
  137. unsigned long timer;
  138. uart = (uart_t *)(MMAP_UART0);
  139. /*
  140. * Wait for last character to go. Timeout of 6ms should
  141. * be enough for our lowest baud rate of 2400.
  142. */
  143. timer = get_timer(0);
  144. while (get_timer(timer) < 6) {
  145. if (readb(&uart->usr) & UART_USR_TXRDY)
  146. break;
  147. }
  148. writeb(ch, &uart->utb);
  149. return;
  150. }
  151. int astro_is_char(void)
  152. {
  153. uart_t *uart;
  154. uart = (uart_t *)(MMAP_UART0);
  155. return readb(&uart->usr) & UART_USR_RXRDY;
  156. }
  157. int astro_get_char(void)
  158. {
  159. uart_t *uart;
  160. uart = (uart_t *)(MMAP_UART0);
  161. while (!(readb(&uart->usr) & UART_USR_RXRDY)) ;
  162. return readb(&uart->urb);
  163. }
  164. int misc_init_r(void)
  165. {
  166. int retval = 0;
  167. puts("Configure Xilinx FPGA...");
  168. retval = astro5373l_xilinx_load();
  169. if (!retval) {
  170. puts("failed!\n");
  171. return retval;
  172. }
  173. puts("done\n");
  174. puts("Configure Altera FPGA...");
  175. retval = astro5373l_altera_load();
  176. if (!retval) {
  177. puts("failed!\n");
  178. return retval;
  179. }
  180. puts("done\n");
  181. return retval;
  182. }