motionpro.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #include <miiphy.h>
  31. #if defined(CONFIG_OF_FLAT_TREE)
  32. #include <ft_build.h>
  33. #endif
  34. #if defined(CONFIG_STATUS_LED)
  35. #include <status_led.h>
  36. #endif /* CONFIG_STATUS_LED */
  37. /* Kollmorgen DPR initialization data */
  38. struct init_elem {
  39. unsigned long addr;
  40. unsigned len;
  41. char *data;
  42. } init_seq[] = {
  43. {0x500003F2, 2, "\x86\x00"}, /* HW parameter */
  44. {0x500003F0, 2, "\x00\x00"},
  45. {0x500003EC, 4, "\x00\x80\xc1\x52"}, /* Magic word */
  46. };
  47. /*
  48. * Initialize Kollmorgen DPR
  49. */
  50. static void kollmorgen_init(void)
  51. {
  52. unsigned i, j;
  53. vu_char *p;
  54. for (i = 0; i < sizeof(init_seq) / sizeof(struct init_elem); ++i) {
  55. p = (vu_char *)init_seq[i].addr;
  56. for (j = 0; j < init_seq[i].len; ++j)
  57. *(p + j) = *(init_seq[i].data + j);
  58. }
  59. printf("DPR: Kollmorgen DPR initialized\n");
  60. }
  61. /*
  62. * Early board initalization.
  63. */
  64. int board_early_init_r(void)
  65. {
  66. /* Now, when we are in RAM, disable Boot Chipselect and enable CS0 */
  67. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25);
  68. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16);
  69. /* Initialize Kollmorgen DPR */
  70. kollmorgen_init();
  71. return 0;
  72. }
  73. /*
  74. * Additional PHY intialization. After being reset in mpc5xxx_fec_init_phy(),
  75. * PHY goes into FX mode. To take it out of the FX mode and switch into
  76. * desired TX operation, one needs to clear the FX_SEL bit of Mode Control
  77. * Register.
  78. */
  79. void reset_phy(void)
  80. {
  81. unsigned short mode_control;
  82. miiphy_read("FEC ETHERNET", CONFIG_PHY_ADDR, 0x15, &mode_control);
  83. miiphy_write("FEC ETHERNET", CONFIG_PHY_ADDR, 0x15,
  84. mode_control & 0xfffe);
  85. return;
  86. }
  87. #ifndef CFG_RAMBOOT
  88. /*
  89. * Helper function to initialize SDRAM controller.
  90. */
  91. static void sdram_start(int hi_addr)
  92. {
  93. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  94. /* unlock mode register */
  95. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
  96. hi_addr_bit;
  97. /* precharge all banks */
  98. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
  99. hi_addr_bit;
  100. /* auto refresh */
  101. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  102. hi_addr_bit;
  103. /* auto refresh, second time */
  104. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
  105. hi_addr_bit;
  106. /* set mode register */
  107. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  108. /* normal operation */
  109. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  110. }
  111. #endif /* !CFG_RAMBOOT */
  112. /*
  113. * Initalize SDRAM - configure SDRAM controller, detect memory size.
  114. */
  115. long int initdram(int board_type)
  116. {
  117. ulong dramsize = 0;
  118. #ifndef CFG_RAMBOOT
  119. ulong test1, test2;
  120. /* configure SDRAM start/end for detection */
  121. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
  122. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
  123. /* setup config registers */
  124. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  125. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  126. sdram_start(0);
  127. test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  128. sdram_start(1);
  129. test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  130. if (test1 > test2) {
  131. sdram_start(0);
  132. dramsize = test1;
  133. } else {
  134. dramsize = test2;
  135. }
  136. /* memory smaller than 1MB is impossible */
  137. if (dramsize < (1 << 20))
  138. dramsize = 0;
  139. /* set SDRAM CS0 size according to the amount of RAM found */
  140. if (dramsize > 0) {
  141. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  142. __builtin_ffs(dramsize >> 20) - 1;
  143. } else {
  144. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  145. }
  146. /* let SDRAM CS1 start right after CS0 and disable it */
  147. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize;
  148. #else /* !CFG_RAMBOOT */
  149. /* retrieve size of memory connected to SDRAM CS0 */
  150. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  151. if (dramsize >= 0x13)
  152. dramsize = (1 << (dramsize - 0x13)) << 20;
  153. else
  154. dramsize = 0;
  155. #endif /* CFG_RAMBOOT */
  156. /* return total ram size */
  157. return dramsize;
  158. }
  159. int checkboard(void)
  160. {
  161. uchar rev = *(vu_char *)CPLD_REV_REGISTER;
  162. printf("Board: Promess Motion-PRO board (CPLD rev. 0x%02x)\n", rev);
  163. return 0;
  164. }
  165. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  166. void ft_board_setup(void *blob, bd_t *bd)
  167. {
  168. ft_cpu_setup(blob, bd);
  169. }
  170. #endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */
  171. #if defined(CONFIG_STATUS_LED)
  172. void __led_init(led_id_t regaddr, int state)
  173. {
  174. *((vu_long *) regaddr) |= ENABLE_GPIO_OUT;
  175. if (state == STATUS_LED_ON)
  176. *((vu_long *) regaddr) |= LED_ON;
  177. else
  178. *((vu_long *) regaddr) &= ~LED_ON;
  179. }
  180. void __led_set(led_id_t regaddr, int state)
  181. {
  182. if (state == STATUS_LED_ON)
  183. *((vu_long *) regaddr) |= LED_ON;
  184. else
  185. *((vu_long *) regaddr) &= ~LED_ON;
  186. }
  187. void __led_toggle(led_id_t regaddr)
  188. {
  189. *((vu_long *) regaddr) ^= LED_ON;
  190. }
  191. #endif /* CONFIG_STATUS_LED */