sc520.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 write_mmcr_byte(u16 mmcr, u8 data)
  33. * void write_mmcr_word(u16 mmcr, u16 data)
  34. * void write_mmcr_long(u16 mmcr, u32 data)
  35. *
  36. * u8 read_mmcr_byte(u16 mmcr)
  37. * u16 read_mmcr_word(u16 mmcr)
  38. * u32 read_mmcr_long(u16 mmcr)
  39. *
  40. * void init_sc520(void)
  41. * unsigned long init_sc520_dram(void)
  42. */
  43. static u32 mmcr_base= 0xfffef000;
  44. void write_mmcr_byte(u16 mmcr, u8 data)
  45. {
  46. writeb(data, mmcr+mmcr_base);
  47. }
  48. void write_mmcr_word(u16 mmcr, u16 data)
  49. {
  50. writew(data, mmcr+mmcr_base);
  51. }
  52. void write_mmcr_long(u16 mmcr, u32 data)
  53. {
  54. writel(data, mmcr+mmcr_base);
  55. }
  56. u8 read_mmcr_byte(u16 mmcr)
  57. {
  58. return readb(mmcr+mmcr_base);
  59. }
  60. u16 read_mmcr_word(u16 mmcr)
  61. {
  62. return readw(mmcr+mmcr_base);
  63. }
  64. u32 read_mmcr_long(u16 mmcr)
  65. {
  66. return readl(mmcr+mmcr_base);
  67. }
  68. void init_sc520(void)
  69. {
  70. /* Set the UARTxCTL register at it's slower,
  71. * baud clock giving us a 1.8432 MHz reference
  72. */
  73. write_mmcr_byte(SC520_UART1CTL, 7);
  74. write_mmcr_byte(SC520_UART2CTL, 7);
  75. /* first set the timer pin mapping */
  76. write_mmcr_byte(SC520_CLKSEL, 0x72); /* no clock frequency selected, use 1.1892MHz */
  77. /* enable PCI bus arbitrer */
  78. write_mmcr_byte(SC520_SYSARBCTL,0x02); /* enable concurrent mode */
  79. write_mmcr_word(SC520_SYSARBMENB,0x1f); /* enable external grants */
  80. write_mmcr_word(SC520_HBCTL,0x04); /* enable posted-writes */
  81. if (CONFIG_SYS_SC520_HIGH_SPEED) {
  82. write_mmcr_byte(SC520_CPUCTL, 0x2); /* set it to 133 MHz and write back */
  83. gd->cpu_clk = 133000000;
  84. printf("## CPU Speed set to 133MHz\n");
  85. } else {
  86. write_mmcr_byte(SC520_CPUCTL, 1); /* set CPU to 100 MHz and write back cache */
  87. printf("## CPU Speed set to 100MHz\n");
  88. gd->cpu_clk = 100000000;
  89. }
  90. /* wait at least one millisecond */
  91. asm("movl $0x2000,%%ecx\n"
  92. "wait_loop: pushl %%ecx\n"
  93. "popl %%ecx\n"
  94. "loop wait_loop\n": : : "ecx");
  95. /* turn on the SDRAM write buffer */
  96. write_mmcr_byte(SC520_DBCTL, 0x11);
  97. /* turn on the cache and disable write through */
  98. asm("movl %%cr0, %%eax\n"
  99. "andl $0x9fffffff, %%eax\n"
  100. "movl %%eax, %%cr0\n" : : : "eax");
  101. }
  102. unsigned long init_sc520_dram(void)
  103. {
  104. bd_t *bd = gd->bd;
  105. u32 dram_present=0;
  106. u32 dram_ctrl;
  107. #ifdef CONFIG_SYS_SDRAM_DRCTMCTL
  108. /* these memory control registers are set up in the assember part,
  109. * in sc520_asm.S, during 'mem_init'. If we muck with them here,
  110. * after we are running a stack in RAM, we have troubles. Besides,
  111. * these refresh and delay values are better ? simply specified
  112. * outright in the include/configs/{cfg} file since the HW designer
  113. * simply dictates it.
  114. */
  115. #else
  116. int val;
  117. int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
  118. int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
  119. int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
  120. /* set SDRAM speed here */
  121. refresh_rate/=78;
  122. if (refresh_rate<=1) {
  123. val = 0; /* 7.8us */
  124. } else if (refresh_rate==2) {
  125. val = 1; /* 15.6us */
  126. } else if (refresh_rate==3 || refresh_rate==4) {
  127. val = 2; /* 31.2us */
  128. } else {
  129. val = 3; /* 62.4us */
  130. }
  131. write_mmcr_byte(SC520_DRCCTL, (read_mmcr_byte(SC520_DRCCTL) & 0xcf) | (val<<4));
  132. val = read_mmcr_byte(SC520_DRCTMCTL);
  133. val &= 0xf0;
  134. if (cas_precharge_delay==3) {
  135. val |= 0x04; /* 3T */
  136. } else if (cas_precharge_delay==4) {
  137. val |= 0x08; /* 4T */
  138. } else if (cas_precharge_delay>4) {
  139. val |= 0x0c;
  140. }
  141. if (ras_cas_delay > 3) {
  142. val |= 2;
  143. } else {
  144. val |= 1;
  145. }
  146. write_mmcr_byte(SC520_DRCTMCTL, val);
  147. #endif
  148. /* We read-back the configuration of the dram
  149. * controller that the assembly code wrote */
  150. dram_ctrl = read_mmcr_long(SC520_DRCBENDADR);
  151. bd->bi_dram[0].start = 0;
  152. if (dram_ctrl & 0x80) {
  153. /* bank 0 enabled */
  154. dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
  155. bd->bi_dram[0].size = bd->bi_dram[1].start;
  156. } else {
  157. bd->bi_dram[0].size = 0;
  158. bd->bi_dram[1].start = bd->bi_dram[0].start;
  159. }
  160. if (dram_ctrl & 0x8000) {
  161. /* bank 1 enabled */
  162. dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
  163. bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
  164. } else {
  165. bd->bi_dram[1].size = 0;
  166. bd->bi_dram[2].start = bd->bi_dram[1].start;
  167. }
  168. if (dram_ctrl & 0x800000) {
  169. /* bank 2 enabled */
  170. dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
  171. bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
  172. } else {
  173. bd->bi_dram[2].size = 0;
  174. bd->bi_dram[3].start = bd->bi_dram[2].start;
  175. }
  176. if (dram_ctrl & 0x80000000) {
  177. /* bank 3 enabled */
  178. dram_present = (dram_ctrl & 0x7f000000) >> 2;
  179. bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
  180. } else {
  181. bd->bi_dram[3].size = 0;
  182. }
  183. #if 0
  184. printf("Configured %d bytes of dram\n", dram_present);
  185. #endif
  186. gd->ram_size = dram_present;
  187. return dram_present;
  188. }
  189. #ifdef CONFIG_SYS_SC520_RESET
  190. void reset_cpu(ulong addr)
  191. {
  192. printf("Resetting using SC520 MMCR\n");
  193. /* Write a '1' to the SYS_RST of the RESCFG MMCR */
  194. write_mmcr_word(SC520_RESCFG, 0x0001);
  195. /* NOTREACHED */
  196. }
  197. #endif