sc520.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* stuff specific for the sc520,
  24. * but idependent of implementation */
  25. #include <common.h>
  26. #include <asm/io.h>
  27. #include <asm/ic/sc520.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. /*
  30. * utility functions for boards based on the AMD sc520
  31. *
  32. * void init_sc520(void)
  33. * unsigned long init_sc520_dram(void)
  34. */
  35. volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
  36. void init_sc520(void)
  37. {
  38. /* Set the UARTxCTL register at it's slower,
  39. * baud clock giving us a 1.8432 MHz reference
  40. */
  41. sc520_mmcr->uart1ctl = 0x07;
  42. sc520_mmcr->uart2ctl = 0x07;
  43. /* first set the timer pin mapping */
  44. sc520_mmcr->clksel = 0x72; /* no clock frequency selected, use 1.1892MHz */
  45. /* enable PCI bus arbitrer */
  46. sc520_mmcr->sysarbctl = 0x02; /* enable concurrent mode */
  47. sc520_mmcr->sysarbmenb = 0x1f; /* enable external grants */
  48. sc520_mmcr->hbctl = 0x04; /* enable posted-writes */
  49. if (CONFIG_SYS_SC520_HIGH_SPEED) {
  50. sc520_mmcr->cpuctl = 0x02; /* set it to 133 MHz and write back */
  51. gd->cpu_clk = 133000000;
  52. printf("## CPU Speed set to 133MHz\n");
  53. } else {
  54. sc520_mmcr->cpuctl = 0x01; /* set it to 100 MHz and write back */
  55. printf("## CPU Speed set to 100MHz\n");
  56. gd->cpu_clk = 100000000;
  57. }
  58. /* wait at least one millisecond */
  59. asm("movl $0x2000,%%ecx\n"
  60. "0: pushl %%ecx\n"
  61. "popl %%ecx\n"
  62. "loop 0b\n": : : "ecx");
  63. /* turn on the SDRAM write buffer */
  64. sc520_mmcr->dbctl = 0x11;
  65. /* turn on the cache and disable write through */
  66. asm("movl %%cr0, %%eax\n"
  67. "andl $0x9fffffff, %%eax\n"
  68. "movl %%eax, %%cr0\n" : : : "eax");
  69. }
  70. unsigned long init_sc520_dram(void)
  71. {
  72. bd_t *bd = gd->bd;
  73. u32 dram_present=0;
  74. u32 dram_ctrl;
  75. #ifdef CONFIG_SYS_SDRAM_DRCTMCTL
  76. /* these memory control registers are set up in the assember part,
  77. * in sc520_asm.S, during 'mem_init'. If we muck with them here,
  78. * after we are running a stack in RAM, we have troubles. Besides,
  79. * these refresh and delay values are better ? simply specified
  80. * outright in the include/configs/{cfg} file since the HW designer
  81. * simply dictates it.
  82. */
  83. #else
  84. int val;
  85. int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
  86. int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
  87. int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
  88. /* set SDRAM speed here */
  89. refresh_rate/=78;
  90. if (refresh_rate<=1) {
  91. val = 0; /* 7.8us */
  92. } else if (refresh_rate==2) {
  93. val = 1; /* 15.6us */
  94. } else if (refresh_rate==3 || refresh_rate==4) {
  95. val = 2; /* 31.2us */
  96. } else {
  97. val = 3; /* 62.4us */
  98. }
  99. sc520_mmcr->drcctl = (sc520_mmcr->drcctl & 0xcf) | (val<<4);
  100. val = sc520_mmcr->drctmctl & 0xf0;
  101. if (cas_precharge_delay==3) {
  102. val |= 0x04; /* 3T */
  103. } else if (cas_precharge_delay==4) {
  104. val |= 0x08; /* 4T */
  105. } else if (cas_precharge_delay>4) {
  106. val |= 0x0c;
  107. }
  108. if (ras_cas_delay > 3) {
  109. val |= 2;
  110. } else {
  111. val |= 1;
  112. }
  113. sc520_mmcr->drctmctl = val;
  114. #endif
  115. /* We read-back the configuration of the dram
  116. * controller that the assembly code wrote */
  117. dram_ctrl = sc520_mmcr->drcbendadr;
  118. bd->bi_dram[0].start = 0;
  119. if (dram_ctrl & 0x80) {
  120. /* bank 0 enabled */
  121. dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
  122. bd->bi_dram[0].size = bd->bi_dram[1].start;
  123. } else {
  124. bd->bi_dram[0].size = 0;
  125. bd->bi_dram[1].start = bd->bi_dram[0].start;
  126. }
  127. if (dram_ctrl & 0x8000) {
  128. /* bank 1 enabled */
  129. dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
  130. bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
  131. } else {
  132. bd->bi_dram[1].size = 0;
  133. bd->bi_dram[2].start = bd->bi_dram[1].start;
  134. }
  135. if (dram_ctrl & 0x800000) {
  136. /* bank 2 enabled */
  137. dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
  138. bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
  139. } else {
  140. bd->bi_dram[2].size = 0;
  141. bd->bi_dram[3].start = bd->bi_dram[2].start;
  142. }
  143. if (dram_ctrl & 0x80000000) {
  144. /* bank 3 enabled */
  145. dram_present = (dram_ctrl & 0x7f000000) >> 2;
  146. bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
  147. } else {
  148. bd->bi_dram[3].size = 0;
  149. }
  150. #if 0
  151. printf("Configured %d bytes of dram\n", dram_present);
  152. #endif
  153. gd->ram_size = dram_present;
  154. return dram_present;
  155. }
  156. #ifdef CONFIG_SYS_SC520_RESET
  157. void reset_cpu(ulong addr)
  158. {
  159. printf("Resetting using SC520 MMCR\n");
  160. /* Write a '1' to the SYS_RST of the RESCFG MMCR */
  161. sc520_mmcr->rescfg = 0x01;
  162. /* NOTREACHED */
  163. }
  164. #endif