sc520.c 5.2 KB

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