motionpro.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * (C) Copyright 2003-2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * modified for Promess PRO - by Andy Joseph, andy@promessdev.com
  6. * modified for Promess PRO-Motion - by Robert McCullough, rob@promessdev.com
  7. * modified by Chris M. Tumas 6/20/06 Change CAS latency to 2 from 3
  8. * Also changed the refresh for 100Mhz operation
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <mpc5xxx.h>
  30. #if defined(CONFIG_OF_FLAT_TREE)
  31. #include <ft_build.h>
  32. #endif
  33. #if defined(CONFIG_STATUS_LED)
  34. #include <status_led.h>
  35. #endif /* CONFIG_STATUS_LED */
  36. /* Kollmorgen DPR initialization data */
  37. struct init_elem {
  38. unsigned long addr;
  39. unsigned len;
  40. char *data;
  41. } init_seq[] = {
  42. {0x500003F2, 2, "\x86\x00"}, /* HW parameter */
  43. {0x500003F0, 2, "\x00\x00"},
  44. {0x500003EC, 4, "\x00\x80\xc1\x52"}, /* Magic word */
  45. };
  46. /*
  47. * Initialize Kollmorgen DPR
  48. */
  49. static void kollmorgen_init(void)
  50. {
  51. unsigned i, j;
  52. vu_char *p;
  53. for (i = 0; i < sizeof(init_seq) / sizeof(struct init_elem); ++i) {
  54. p = (vu_char *)init_seq[i].addr;
  55. for (j = 0; j < init_seq[i].len; ++j)
  56. *(p + j) = *(init_seq[i].data + j);
  57. }
  58. printf("DPR: Kollmorgen DPR initialized\n");
  59. }
  60. /*
  61. * Early board initalization.
  62. */
  63. int board_early_init_r(void)
  64. {
  65. /* Now, when we are in RAM, disable Boot Chipselect and enable CS0 */
  66. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25);
  67. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16);
  68. /* Initialize Kollmorgen DPR */
  69. kollmorgen_init();
  70. return 0;
  71. }
  72. #ifndef CFG_RAMBOOT
  73. /*
  74. * Helper function to initialize SDRAM controller.
  75. */
  76. static void sdram_start (int hi_addr)
  77. {
  78. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  79. /* unlock mode register */
  80. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  81. hi_addr_bit;
  82. /* precharge all banks */
  83. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  84. hi_addr_bit;
  85. /* auto refresh */
  86. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  87. hi_addr_bit;
  88. /* auto refresh, second time */
  89. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  90. hi_addr_bit;
  91. /* set mode register */
  92. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  93. /* normal operation */
  94. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  95. }
  96. #endif /* !CFG_RAMBOOT */
  97. /*
  98. * Initalize SDRAM - configure SDRAM controller, detect memory size.
  99. */
  100. long int initdram (int board_type)
  101. {
  102. ulong dramsize = 0;
  103. #ifndef CFG_RAMBOOT
  104. ulong test1, test2;
  105. /* configure SDRAM start/end for detection */
  106. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
  107. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
  108. /* setup config registers */
  109. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  110. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  111. sdram_start(0);
  112. test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  113. sdram_start(1);
  114. test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  115. if (test1 > test2) {
  116. sdram_start(0);
  117. dramsize = test1;
  118. } else {
  119. dramsize = test2;
  120. }
  121. /* memory smaller than 1MB is impossible */
  122. if (dramsize < (1 << 20))
  123. dramsize = 0;
  124. /* set SDRAM CS0 size according to the amount of RAM found */
  125. if (dramsize > 0)
  126. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  127. __builtin_ffs(dramsize >> 20) - 1;
  128. else
  129. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  130. /* let SDRAM CS1 start right after CS0 and disable it */
  131. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize;
  132. #else /* !CFG_RAMBOOT */
  133. /* retrieve size of memory connected to SDRAM CS0 */
  134. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  135. if (dramsize >= 0x13)
  136. dramsize = (1 << (dramsize - 0x13)) << 20;
  137. else
  138. dramsize = 0;
  139. #endif /* CFG_RAMBOOT */
  140. /* return total ram size */
  141. return dramsize;
  142. }
  143. int checkboard (void)
  144. {
  145. uchar rev = *(vu_char *)CPLD_REV_REGISTER;
  146. printf("Board: Promess Motion-PRO board (CPLD rev. 0x%02x)\n", rev);
  147. return 0;
  148. }
  149. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  150. void ft_board_setup(void *blob, bd_t *bd)
  151. {
  152. ft_cpu_setup(blob, bd);
  153. }
  154. #endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */
  155. #if defined(CONFIG_STATUS_LED)
  156. void __led_init (led_id_t regaddr, int state)
  157. {
  158. *((vu_long *) regaddr) |= ENABLE_GPIO_OUT;
  159. if (state == STATUS_LED_ON)
  160. *((vu_long *) regaddr) |= LED_ON;
  161. else
  162. *((vu_long *) regaddr) &= ~LED_ON;
  163. }
  164. void __led_set (led_id_t regaddr, int state)
  165. {
  166. if (state == STATUS_LED_ON)
  167. *((vu_long *) regaddr) |= LED_ON;
  168. else
  169. *((vu_long *) regaddr) &= ~LED_ON;
  170. }
  171. void __led_toggle (led_id_t regaddr)
  172. {
  173. *((vu_long *) regaddr) ^= LED_ON;
  174. }
  175. #endif /* CONFIG_STATUS_LED */