sc520.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/processor-flags.h>
  28. #include <asm/ic/sc520.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. /*
  31. * utility functions for boards based on the AMD sc520
  32. *
  33. * void init_sc520(void)
  34. * unsigned long init_sc520_dram(void)
  35. */
  36. sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)SC520_MMCR_BASE;
  37. int cpu_init_f(void)
  38. {
  39. if (CONFIG_SYS_SC520_HIGH_SPEED) {
  40. /* set it to 133 MHz and write back */
  41. writeb(0x02, &sc520_mmcr->cpuctl);
  42. gd->cpu_clk = 133000000;
  43. printf("## CPU Speed set to 133MHz\n");
  44. } else {
  45. /* set it to 100 MHz and write back */
  46. writeb(0x01, &sc520_mmcr->cpuctl);
  47. printf("## CPU Speed set to 100MHz\n");
  48. gd->cpu_clk = 100000000;
  49. }
  50. /* wait at least one millisecond */
  51. asm("movl $0x2000, %%ecx\n"
  52. "0: pushl %%ecx\n"
  53. "popl %%ecx\n"
  54. "loop 0b\n": : : "ecx");
  55. /* turn on the SDRAM write buffer */
  56. writeb(0x11, &sc520_mmcr->dbctl);
  57. return x86_cpu_init_f();
  58. }
  59. unsigned long init_sc520_dram(void)
  60. {
  61. bd_t *bd = gd->bd;
  62. u32 dram_present=0;
  63. u32 dram_ctrl;
  64. #ifdef CONFIG_SYS_SDRAM_DRCTMCTL
  65. /* these memory control registers are set up in the assember part,
  66. * in sc520_asm.S, during 'mem_init'. If we muck with them here,
  67. * after we are running a stack in RAM, we have troubles. Besides,
  68. * these refresh and delay values are better ? simply specified
  69. * outright in the include/configs/{cfg} file since the HW designer
  70. * simply dictates it.
  71. */
  72. #else
  73. u8 tmp;
  74. u8 val;
  75. int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
  76. int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
  77. int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
  78. /* set SDRAM speed here */
  79. refresh_rate /= 78;
  80. if (refresh_rate <= 1) {
  81. val = 0; /* 7.8us */
  82. } else if (refresh_rate == 2) {
  83. val = 1; /* 15.6us */
  84. } else if (refresh_rate == 3 || refresh_rate == 4) {
  85. val = 2; /* 31.2us */
  86. } else {
  87. val = 3; /* 62.4us */
  88. }
  89. tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
  90. writeb(tmp, &sc520_mmcr->drcctl);
  91. val = readb(&sc520_mmcr->drctmctl) & 0xf0;
  92. if (cas_precharge_delay==3) {
  93. val |= 0x04; /* 3T */
  94. } else if (cas_precharge_delay==4) {
  95. val |= 0x08; /* 4T */
  96. } else if (cas_precharge_delay>4) {
  97. val |= 0x0c;
  98. }
  99. if (ras_cas_delay > 3) {
  100. val |= 2;
  101. } else {
  102. val |= 1;
  103. }
  104. writeb(val, &c520_mmcr->drctmctl);
  105. #endif
  106. /*
  107. * We read-back the configuration of the dram
  108. * controller that the assembly code wrote
  109. */
  110. dram_ctrl = readl(&sc520_mmcr->drcbendadr);
  111. bd->bi_dram[0].start = 0;
  112. if (dram_ctrl & 0x80) {
  113. /* bank 0 enabled */
  114. dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
  115. bd->bi_dram[0].size = bd->bi_dram[1].start;
  116. } else {
  117. bd->bi_dram[0].size = 0;
  118. bd->bi_dram[1].start = bd->bi_dram[0].start;
  119. }
  120. if (dram_ctrl & 0x8000) {
  121. /* bank 1 enabled */
  122. dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
  123. bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
  124. } else {
  125. bd->bi_dram[1].size = 0;
  126. bd->bi_dram[2].start = bd->bi_dram[1].start;
  127. }
  128. if (dram_ctrl & 0x800000) {
  129. /* bank 2 enabled */
  130. dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
  131. bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
  132. } else {
  133. bd->bi_dram[2].size = 0;
  134. bd->bi_dram[3].start = bd->bi_dram[2].start;
  135. }
  136. if (dram_ctrl & 0x80000000) {
  137. /* bank 3 enabled */
  138. dram_present = (dram_ctrl & 0x7f000000) >> 2;
  139. bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
  140. } else {
  141. bd->bi_dram[3].size = 0;
  142. }
  143. gd->ram_size = dram_present;
  144. return dram_present;
  145. }
  146. #ifdef CONFIG_SYS_SC520_RESET
  147. void reset_cpu(ulong addr)
  148. {
  149. printf("Resetting using SC520 MMCR\n");
  150. /* Write a '1' to the SYS_RST of the RESCFG MMCR */
  151. writeb(0x01, &sc520_mmcr->rescfg);
  152. /* NOTREACHED */
  153. }
  154. #endif