motionpro.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 CONFIG_SYS_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 /* !CONFIG_SYS_RAMBOOT */
  110. /*
  111. * Initalize SDRAM - configure SDRAM controller, detect memory size.
  112. */
  113. phys_size_t initdram(int board_type)
  114. {
  115. ulong dramsize = 0;
  116. #ifndef CONFIG_SYS_RAMBOOT
  117. ulong test1, test2;
  118. /* According to AN3221 (MPC5200B SDRAM Initialization and
  119. * Configuration), the SDelay register must be written a value of
  120. * 0x00000004 as the first step of the SDRAM contorller configuration.
  121. */
  122. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  123. /* configure SDRAM start/end for detection */
  124. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
  125. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
  126. /* setup config registers */
  127. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  128. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  129. sdram_start(0);
  130. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  131. sdram_start(1);
  132. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  133. if (test1 > test2) {
  134. sdram_start(0);
  135. dramsize = test1;
  136. } else {
  137. dramsize = test2;
  138. }
  139. /* memory smaller than 1MB is impossible */
  140. if (dramsize < (1 << 20))
  141. dramsize = 0;
  142. /* set SDRAM CS0 size according to the amount of RAM found */
  143. if (dramsize > 0) {
  144. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  145. __builtin_ffs(dramsize >> 20) - 1;
  146. } else {
  147. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  148. }
  149. /* let SDRAM CS1 start right after CS0 and disable it */
  150. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize;
  151. #else /* !CONFIG_SYS_RAMBOOT */
  152. /* retrieve size of memory connected to SDRAM CS0 */
  153. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  154. if (dramsize >= 0x13)
  155. dramsize = (1 << (dramsize - 0x13)) << 20;
  156. else
  157. dramsize = 0;
  158. #endif /* CONFIG_SYS_RAMBOOT */
  159. /* return total ram size */
  160. return dramsize;
  161. }
  162. int checkboard(void)
  163. {
  164. uchar rev = *(vu_char *)CPLD_REV_REGISTER;
  165. printf("Board: Promess Motion-PRO board (CPLD rev. 0x%02x)\n", rev);
  166. return 0;
  167. }
  168. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  169. void ft_board_setup(void *blob, bd_t *bd)
  170. {
  171. ft_cpu_setup(blob, bd);
  172. }
  173. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  174. #if defined(CONFIG_STATUS_LED)
  175. void __led_init(led_id_t regaddr, int state)
  176. {
  177. *((vu_long *) regaddr) |= ENABLE_GPIO_OUT;
  178. if (state == STATUS_LED_ON)
  179. *((vu_long *) regaddr) |= LED_ON;
  180. else
  181. *((vu_long *) regaddr) &= ~LED_ON;
  182. }
  183. void __led_set(led_id_t regaddr, int state)
  184. {
  185. if (state == STATUS_LED_ON)
  186. *((vu_long *) regaddr) |= LED_ON;
  187. else
  188. *((vu_long *) regaddr) &= ~LED_ON;
  189. }
  190. void __led_toggle(led_id_t regaddr)
  191. {
  192. *((vu_long *) regaddr) ^= LED_ON;
  193. }
  194. #endif /* CONFIG_STATUS_LED */