mvsmr.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * (C) Copyright 2005-2010
  9. * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <mpc5xxx.h>
  31. #include <malloc.h>
  32. #include <pci.h>
  33. #include <i2c.h>
  34. #include <fpga.h>
  35. #include <environment.h>
  36. #include <netdev.h>
  37. #include <asm/io.h>
  38. #include "fpga.h"
  39. #include "mvsmr.h"
  40. #include "../common/mv_common.h"
  41. #define SDRAM_DDR 1
  42. #define SDRAM_MODE 0x018D0000
  43. #define SDRAM_EMODE 0x40090000
  44. #define SDRAM_CONTROL 0x715f0f00
  45. #define SDRAM_CONFIG1 0xd3722930
  46. #define SDRAM_CONFIG2 0x46770000
  47. DECLARE_GLOBAL_DATA_PTR;
  48. static void sdram_start(int hi_addr)
  49. {
  50. long hi_bit = hi_addr ? 0x01000000 : 0;
  51. /* unlock mode register */
  52. out_be32((u32 *)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 |
  53. hi_bit);
  54. /* precharge all banks */
  55. out_be32((u32 *)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 |
  56. hi_bit);
  57. /* set mode register: extended mode */
  58. out_be32((u32 *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE);
  59. /* set mode register: reset DLL */
  60. out_be32((u32 *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000);
  61. /* precharge all banks */
  62. out_be32((u32 *)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 |
  63. hi_bit);
  64. /* auto refresh */
  65. out_be32((u32 *)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 |
  66. hi_bit);
  67. /* set mode register */
  68. out_be32((u32 *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  69. /* normal operation */
  70. out_be32((u32 *)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit);
  71. }
  72. phys_addr_t initdram(int board_type)
  73. {
  74. ulong dramsize = 0;
  75. ulong test1,
  76. test2;
  77. /* setup SDRAM chip selects */
  78. out_be32((u32 *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
  79. /* setup config registers */
  80. out_be32((u32 *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  81. out_be32((u32 *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  82. /* find RAM size using SDRAM CS0 only */
  83. sdram_start(0);
  84. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  85. sdram_start(1);
  86. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  87. if (test1 > test2) {
  88. sdram_start(0);
  89. dramsize = test1;
  90. } else
  91. dramsize = test2;
  92. if (dramsize < (1 << 20))
  93. dramsize = 0;
  94. if (dramsize > 0)
  95. out_be32((u32 *)MPC5XXX_SDRAM_CS0CFG, 0x13 +
  96. __builtin_ffs(dramsize >> 20) - 1);
  97. else
  98. out_be32((u32 *)MPC5XXX_SDRAM_CS0CFG, 0);
  99. return dramsize;
  100. }
  101. void mvsmr_init_gpio(void)
  102. {
  103. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  104. struct mpc5xxx_wu_gpio *wu_gpio =
  105. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  106. struct mpc5xxx_gpt_0_7 *timers = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
  107. printf("Ports : 0x%08x\n", gpio->port_config);
  108. printf("PORCFG: 0x%08x\n", in_be32((unsigned *)MPC5XXX_CDM_PORCFG));
  109. out_be32(&gpio->simple_ddr, SIMPLE_DDR);
  110. out_be32(&gpio->simple_dvo, SIMPLE_DVO);
  111. out_be32(&gpio->simple_ode, SIMPLE_ODE);
  112. out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN);
  113. out_8(&gpio->sint_ode, SINT_ODE);
  114. out_8(&gpio->sint_ddr, SINT_DDR);
  115. out_8(&gpio->sint_dvo, SINT_DVO);
  116. out_8(&gpio->sint_inten, SINT_INTEN);
  117. out_be16(&gpio->sint_itype, SINT_ITYPE);
  118. out_8(&gpio->sint_gpioe, SINT_GPIOEN);
  119. out_8(&wu_gpio->ode, WKUP_ODE);
  120. out_8(&wu_gpio->ddr, WKUP_DIR);
  121. out_8(&wu_gpio->dvo, WKUP_DO);
  122. out_8(&wu_gpio->enable, WKUP_EN);
  123. out_be32(&timers->gpt0.emsr, 0x00000234); /* OD output high */
  124. out_be32(&timers->gpt1.emsr, 0x00000234);
  125. out_be32(&timers->gpt2.emsr, 0x00000234);
  126. out_be32(&timers->gpt3.emsr, 0x00000234);
  127. out_be32(&timers->gpt4.emsr, 0x00000234);
  128. out_be32(&timers->gpt5.emsr, 0x00000234);
  129. out_be32(&timers->gpt6.emsr, 0x00000024); /* push-pull output low */
  130. out_be32(&timers->gpt7.emsr, 0x00000024);
  131. }
  132. int misc_init_r(void)
  133. {
  134. char *s = getenv("reset_env");
  135. if (s) {
  136. printf(" === FACTORY RESET ===\n");
  137. mv_reset_environment();
  138. saveenv();
  139. }
  140. return -1;
  141. }
  142. void mvsmr_get_dbg_present(void)
  143. {
  144. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  145. struct mpc5xxx_psc *psc = (struct mpc5xxx_psc *)MPC5XXX_PSC1;
  146. if (in_be32(&gpio->simple_ival) & COP_PRESENT) {
  147. setenv("dbg_present", "no\0");
  148. setenv("bootstopkey", "abcdefghijklmnopqrstuvwxyz\0");
  149. } else {
  150. setenv("dbg_present", "yes\0");
  151. setenv("bootstopkey", "s\0");
  152. setbits_8(&psc->command, PSC_RX_ENABLE);
  153. }
  154. }
  155. void mvsmr_get_service_mode(void)
  156. {
  157. struct mpc5xxx_wu_gpio *wu_gpio =
  158. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  159. if (in_8(&wu_gpio->ival) & SERVICE_MODE)
  160. setenv("servicemode", "no\0");
  161. else
  162. setenv("servicemode", "yes\0");
  163. }
  164. int mvsmr_get_mac(void)
  165. {
  166. unsigned char mac[6];
  167. struct mpc5xxx_wu_gpio *wu_gpio =
  168. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  169. if (in_8(&wu_gpio->ival) & LAN_PRSNT) {
  170. setenv("lan_present", "no\0");
  171. return -1;
  172. } else
  173. setenv("lan_present", "yes\0");
  174. i2c_read(0x50, 0, 1, mac, 6);
  175. eth_setenv_enetaddr("ethaddr", mac);
  176. return 0;
  177. }
  178. int checkboard(void)
  179. {
  180. mvsmr_init_gpio();
  181. printf("Board: Matrix Vision mvSMR\n");
  182. return 0;
  183. }
  184. void flash_preinit(void)
  185. {
  186. /*
  187. * Now, when we are in RAM, enable flash write
  188. * access for detection process.
  189. * Note that CS_BOOT cannot be cleared when
  190. * executing in flash.
  191. */
  192. clrbits_be32((u32 *)MPC5XXX_BOOTCS_CFG, 0x1);
  193. }
  194. void flash_afterinit(ulong size)
  195. {
  196. out_be32((u32 *)MPC5XXX_BOOTCS_START,
  197. START_REG(CONFIG_SYS_BOOTCS_START | size));
  198. out_be32((u32 *)MPC5XXX_CS0_START,
  199. START_REG(CONFIG_SYS_BOOTCS_START | size));
  200. out_be32((u32 *)MPC5XXX_BOOTCS_STOP,
  201. STOP_REG(CONFIG_SYS_BOOTCS_START | size, size));
  202. out_be32((u32 *)MPC5XXX_CS0_STOP,
  203. STOP_REG(CONFIG_SYS_BOOTCS_START | size, size));
  204. }
  205. struct pci_controller hose;
  206. void pci_init_board(void)
  207. {
  208. mvsmr_get_dbg_present();
  209. mvsmr_get_service_mode();
  210. mvsmr_init_fpga();
  211. mv_load_fpga();
  212. pci_mpc5xxx_init(&hose);
  213. }
  214. int board_eth_init(bd_t *bis)
  215. {
  216. if (!mvsmr_get_mac())
  217. return cpu_eth_init(bis);
  218. return pci_eth_init(bis);
  219. }