sc520.c 5.3 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/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. writeb(0x07, &sc520_mmcr->uart1ctl);
  42. writeb(0x07, &sc520_mmcr->uart2ctl);
  43. /* first set the timer pin mapping */
  44. writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */
  45. /* enable PCI bus arbitrer */
  46. writeb(0x02, &sc520_mmcr->sysarbctl); /* enable concurrent mode */
  47. writeb(0x1f, &sc520_mmcr->sysarbmenb); /* enable external grants */
  48. writeb(0x04, &sc520_mmcr->hbctl); /* enable posted-writes */
  49. if (CONFIG_SYS_SC520_HIGH_SPEED) {
  50. writeb(0x02, &sc520_mmcr->cpuctl); /* set it to 133 MHz and write back */
  51. gd->cpu_clk = 133000000;
  52. printf("## CPU Speed set to 133MHz\n");
  53. } else {
  54. writeb(0x01, &sc520_mmcr->cpuctl); /* 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. writeb(0x11, &sc520_mmcr->dbctl);
  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. u8 tmp;
  85. u8 val;
  86. int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
  87. int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
  88. int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
  89. /* set SDRAM speed here */
  90. refresh_rate/=78;
  91. if (refresh_rate<=1) {
  92. val = 0; /* 7.8us */
  93. } else if (refresh_rate==2) {
  94. val = 1; /* 15.6us */
  95. } else if (refresh_rate==3 || refresh_rate==4) {
  96. val = 2; /* 31.2us */
  97. } else {
  98. val = 3; /* 62.4us */
  99. }
  100. tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
  101. writeb(tmp, &sc520_mmcr->drcctl);
  102. val = readb(&sc520_mmcr->drctmctl) & 0xf0;
  103. if (cas_precharge_delay==3) {
  104. val |= 0x04; /* 3T */
  105. } else if (cas_precharge_delay==4) {
  106. val |= 0x08; /* 4T */
  107. } else if (cas_precharge_delay>4) {
  108. val |= 0x0c;
  109. }
  110. if (ras_cas_delay > 3) {
  111. val |= 2;
  112. } else {
  113. val |= 1;
  114. }
  115. writeb(val, &c520_mmcr->drctmctl);
  116. #endif
  117. /* We read-back the configuration of the dram
  118. * controller that the assembly code wrote */
  119. dram_ctrl = readl(&sc520_mmcr->drcbendadr);
  120. bd->bi_dram[0].start = 0;
  121. if (dram_ctrl & 0x80) {
  122. /* bank 0 enabled */
  123. dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
  124. bd->bi_dram[0].size = bd->bi_dram[1].start;
  125. } else {
  126. bd->bi_dram[0].size = 0;
  127. bd->bi_dram[1].start = bd->bi_dram[0].start;
  128. }
  129. if (dram_ctrl & 0x8000) {
  130. /* bank 1 enabled */
  131. dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
  132. bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
  133. } else {
  134. bd->bi_dram[1].size = 0;
  135. bd->bi_dram[2].start = bd->bi_dram[1].start;
  136. }
  137. if (dram_ctrl & 0x800000) {
  138. /* bank 2 enabled */
  139. dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
  140. bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
  141. } else {
  142. bd->bi_dram[2].size = 0;
  143. bd->bi_dram[3].start = bd->bi_dram[2].start;
  144. }
  145. if (dram_ctrl & 0x80000000) {
  146. /* bank 3 enabled */
  147. dram_present = (dram_ctrl & 0x7f000000) >> 2;
  148. bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
  149. } else {
  150. bd->bi_dram[3].size = 0;
  151. }
  152. #if 0
  153. printf("Configured %d bytes of dram\n", dram_present);
  154. #endif
  155. gd->ram_size = dram_present;
  156. return dram_present;
  157. }
  158. #ifdef CONFIG_SYS_SC520_RESET
  159. void reset_cpu(ulong addr)
  160. {
  161. printf("Resetting using SC520 MMCR\n");
  162. /* Write a '1' to the SYS_RST of the RESCFG MMCR */
  163. writeb(0x01, &sc520_mmcr->rescfg);
  164. /* NOTREACHED */
  165. }
  166. #endif