sc520.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. /*
  40. * Set the UARTxCTL register at it's slower,
  41. * baud clock giving us a 1.8432 MHz reference
  42. */
  43. writeb(0x07, &sc520_mmcr->uart1ctl);
  44. writeb(0x07, &sc520_mmcr->uart2ctl);
  45. /* first set the timer pin mapping */
  46. writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */
  47. /* enable PCI bus arbiter (concurrent mode) */
  48. writeb(0x02, &sc520_mmcr->sysarbctl);
  49. /* enable external grants */
  50. writeb(0x1f, &sc520_mmcr->sysarbmenb);
  51. /* enable posted-writes */
  52. writeb(0x04, &sc520_mmcr->hbctl);
  53. if (CONFIG_SYS_SC520_HIGH_SPEED) {
  54. /* set it to 133 MHz and write back */
  55. writeb(0x02, &sc520_mmcr->cpuctl);
  56. gd->cpu_clk = 133000000;
  57. printf("## CPU Speed set to 133MHz\n");
  58. } else {
  59. /* set it to 100 MHz and write back */
  60. writeb(0x01, &sc520_mmcr->cpuctl);
  61. printf("## CPU Speed set to 100MHz\n");
  62. gd->cpu_clk = 100000000;
  63. }
  64. /* wait at least one millisecond */
  65. asm("movl $0x2000, %%ecx\n"
  66. "0: pushl %%ecx\n"
  67. "popl %%ecx\n"
  68. "loop 0b\n": : : "ecx");
  69. /* turn on the SDRAM write buffer */
  70. writeb(0x11, &sc520_mmcr->dbctl);
  71. return x86_cpu_init_f();
  72. }
  73. unsigned long init_sc520_dram(void)
  74. {
  75. bd_t *bd = gd->bd;
  76. u32 dram_present=0;
  77. u32 dram_ctrl;
  78. #ifdef CONFIG_SYS_SDRAM_DRCTMCTL
  79. /* these memory control registers are set up in the assember part,
  80. * in sc520_asm.S, during 'mem_init'. If we muck with them here,
  81. * after we are running a stack in RAM, we have troubles. Besides,
  82. * these refresh and delay values are better ? simply specified
  83. * outright in the include/configs/{cfg} file since the HW designer
  84. * simply dictates it.
  85. */
  86. #else
  87. u8 tmp;
  88. u8 val;
  89. int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
  90. int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
  91. int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
  92. /* set SDRAM speed here */
  93. refresh_rate /= 78;
  94. if (refresh_rate <= 1) {
  95. val = 0; /* 7.8us */
  96. } else if (refresh_rate == 2) {
  97. val = 1; /* 15.6us */
  98. } else if (refresh_rate == 3 || refresh_rate == 4) {
  99. val = 2; /* 31.2us */
  100. } else {
  101. val = 3; /* 62.4us */
  102. }
  103. tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
  104. writeb(tmp, &sc520_mmcr->drcctl);
  105. val = readb(&sc520_mmcr->drctmctl) & 0xf0;
  106. if (cas_precharge_delay==3) {
  107. val |= 0x04; /* 3T */
  108. } else if (cas_precharge_delay==4) {
  109. val |= 0x08; /* 4T */
  110. } else if (cas_precharge_delay>4) {
  111. val |= 0x0c;
  112. }
  113. if (ras_cas_delay > 3) {
  114. val |= 2;
  115. } else {
  116. val |= 1;
  117. }
  118. writeb(val, &c520_mmcr->drctmctl);
  119. #endif
  120. /*
  121. * We read-back the configuration of the dram
  122. * controller that the assembly code wrote
  123. */
  124. dram_ctrl = readl(&sc520_mmcr->drcbendadr);
  125. bd->bi_dram[0].start = 0;
  126. if (dram_ctrl & 0x80) {
  127. /* bank 0 enabled */
  128. dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
  129. bd->bi_dram[0].size = bd->bi_dram[1].start;
  130. } else {
  131. bd->bi_dram[0].size = 0;
  132. bd->bi_dram[1].start = bd->bi_dram[0].start;
  133. }
  134. if (dram_ctrl & 0x8000) {
  135. /* bank 1 enabled */
  136. dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
  137. bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
  138. } else {
  139. bd->bi_dram[1].size = 0;
  140. bd->bi_dram[2].start = bd->bi_dram[1].start;
  141. }
  142. if (dram_ctrl & 0x800000) {
  143. /* bank 2 enabled */
  144. dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
  145. bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
  146. } else {
  147. bd->bi_dram[2].size = 0;
  148. bd->bi_dram[3].start = bd->bi_dram[2].start;
  149. }
  150. if (dram_ctrl & 0x80000000) {
  151. /* bank 3 enabled */
  152. dram_present = (dram_ctrl & 0x7f000000) >> 2;
  153. bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
  154. } else {
  155. bd->bi_dram[3].size = 0;
  156. }
  157. gd->ram_size = dram_present;
  158. return dram_present;
  159. }
  160. #ifdef CONFIG_SYS_SC520_RESET
  161. void reset_cpu(ulong addr)
  162. {
  163. printf("Resetting using SC520 MMCR\n");
  164. /* Write a '1' to the SYS_RST of the RESCFG MMCR */
  165. writeb(0x01, &sc520_mmcr->rescfg);
  166. /* NOTREACHED */
  167. }
  168. #endif