motionpro.c 5.7 KB

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