mpc5121ads.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * (C) Copyright 2007-2009 DENX Software Engineering
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/bitops.h>
  8. #include <command.h>
  9. #include <asm/io.h>
  10. #include <asm/processor.h>
  11. #include <asm/mpc512x.h>
  12. #include <fdt_support.h>
  13. #ifdef CONFIG_MISC_INIT_R
  14. #include <i2c.h>
  15. #endif
  16. #include <net.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/nand.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. void __mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip);
  21. /* Active chip number set in board_nand_select_device() (mpc5121_nfc.c) */
  22. extern int mpc5121_nfc_chip;
  23. /* Control chips select signal on MPC5121ADS board */
  24. void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
  25. {
  26. unsigned char *csreg = (u8 *)CONFIG_SYS_CPLD_BASE + 0x09;
  27. u8 v;
  28. v = in_8(csreg);
  29. v |= 0x0F;
  30. if (chip >= 0) {
  31. __mpc5121_nfc_select_chip(mtd, 0);
  32. v &= ~(1 << mpc5121_nfc_chip);
  33. } else {
  34. __mpc5121_nfc_select_chip(mtd, -1);
  35. }
  36. out_8(csreg, v);
  37. }
  38. int board_early_init_f(void)
  39. {
  40. /*
  41. * Disable Boot NOR FLASH write protect - CPLD Reg 8 NOR FLASH Control
  42. *
  43. * Without this the flash identification routine fails, as it needs to issue
  44. * write commands in order to establish the device ID.
  45. */
  46. #ifdef CONFIG_MPC5121ADS_REV2
  47. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  48. #else
  49. if (in_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08)) & 0x04) {
  50. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  51. } else {
  52. /* running from Backup flash */
  53. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0x32);
  54. }
  55. #endif
  56. return 0;
  57. }
  58. int is_micron(void){
  59. ushort brd_rev = *(vu_short *)(CONFIG_SYS_CPLD_BASE + 0x00);
  60. uchar macaddr[6];
  61. u32 brddate, macchk, ismicron;
  62. /*
  63. * MAC address has serial number with date of manufacture
  64. * Boards made before Nov-08 #1180 use Micron memory;
  65. * 001e59 is the STx vendor #
  66. * Default is Elpida since it works for both but is slightly slower
  67. */
  68. ismicron = 0;
  69. if (brd_rev >= 0x0400 && eth_getenv_enetaddr("ethaddr", macaddr)) {
  70. brddate = (macaddr[3] << 16) + (macaddr[4] << 8) + macaddr[5];
  71. macchk = (macaddr[0] << 16) + (macaddr[1] << 8) + macaddr[2];
  72. debug("brddate = %d\n\t", brddate);
  73. if (macchk == 0x001e59 && brddate <= 8111180)
  74. ismicron = 1;
  75. } else if (brd_rev < 0x400) {
  76. ismicron = 1;
  77. }
  78. debug("Using %s Memory settings\n\t",
  79. ismicron ? "Micron" : "Elpida");
  80. return(ismicron);
  81. }
  82. phys_size_t initdram(int board_type)
  83. {
  84. u32 msize = 0;
  85. /*
  86. * Elpida MDDRC and initialization settings are an alternative
  87. * to the Default Micron ones for all but the earliest Rev 4 boards
  88. */
  89. ddr512x_config_t elpida_mddrc_config = {
  90. .ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA,
  91. .ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0,
  92. .ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA,
  93. .ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA,
  94. };
  95. u32 elpida_init_sequence[] = {
  96. CONFIG_SYS_DDRCMD_NOP,
  97. CONFIG_SYS_DDRCMD_NOP,
  98. CONFIG_SYS_DDRCMD_NOP,
  99. CONFIG_SYS_DDRCMD_NOP,
  100. CONFIG_SYS_DDRCMD_NOP,
  101. CONFIG_SYS_DDRCMD_NOP,
  102. CONFIG_SYS_DDRCMD_NOP,
  103. CONFIG_SYS_DDRCMD_NOP,
  104. CONFIG_SYS_DDRCMD_NOP,
  105. CONFIG_SYS_DDRCMD_NOP,
  106. CONFIG_SYS_DDRCMD_PCHG_ALL,
  107. CONFIG_SYS_DDRCMD_NOP,
  108. CONFIG_SYS_DDRCMD_RFSH,
  109. CONFIG_SYS_DDRCMD_NOP,
  110. CONFIG_SYS_DDRCMD_RFSH,
  111. CONFIG_SYS_DDRCMD_NOP,
  112. CONFIG_SYS_DDRCMD_EM2,
  113. CONFIG_SYS_DDRCMD_EM3,
  114. CONFIG_SYS_DDRCMD_EN_DLL,
  115. CONFIG_SYS_ELPIDA_RES_DLL,
  116. CONFIG_SYS_DDRCMD_PCHG_ALL,
  117. CONFIG_SYS_DDRCMD_RFSH,
  118. CONFIG_SYS_DDRCMD_RFSH,
  119. CONFIG_SYS_DDRCMD_RFSH,
  120. CONFIG_SYS_ELPIDA_INIT_DEV_OP,
  121. CONFIG_SYS_DDRCMD_NOP,
  122. CONFIG_SYS_DDRCMD_NOP,
  123. CONFIG_SYS_DDRCMD_NOP,
  124. CONFIG_SYS_DDRCMD_NOP,
  125. CONFIG_SYS_DDRCMD_NOP,
  126. CONFIG_SYS_DDRCMD_NOP,
  127. CONFIG_SYS_DDRCMD_NOP,
  128. CONFIG_SYS_DDRCMD_NOP,
  129. CONFIG_SYS_DDRCMD_NOP,
  130. CONFIG_SYS_DDRCMD_NOP,
  131. CONFIG_SYS_DDRCMD_OCD_DEFAULT,
  132. CONFIG_SYS_ELPIDA_OCD_EXIT,
  133. CONFIG_SYS_DDRCMD_NOP,
  134. CONFIG_SYS_DDRCMD_NOP,
  135. CONFIG_SYS_DDRCMD_NOP,
  136. CONFIG_SYS_DDRCMD_NOP,
  137. CONFIG_SYS_DDRCMD_NOP,
  138. CONFIG_SYS_DDRCMD_NOP,
  139. CONFIG_SYS_DDRCMD_NOP,
  140. CONFIG_SYS_DDRCMD_NOP,
  141. CONFIG_SYS_DDRCMD_NOP,
  142. CONFIG_SYS_DDRCMD_NOP
  143. };
  144. if (is_micron()) {
  145. msize = fixed_sdram(NULL, NULL, 0);
  146. } else {
  147. msize = fixed_sdram(&elpida_mddrc_config,
  148. elpida_init_sequence,
  149. sizeof(elpida_init_sequence)/sizeof(u32));
  150. }
  151. return msize;
  152. }
  153. int misc_init_r(void)
  154. {
  155. u8 tmp_val;
  156. /* Using this for DIU init before the driver in linux takes over
  157. * Enable the TFP410 Encoder (I2C address 0x38)
  158. */
  159. i2c_set_bus_num(2);
  160. tmp_val = 0xBF;
  161. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  162. /* Verify if enabled */
  163. tmp_val = 0;
  164. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  165. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  166. tmp_val = 0x10;
  167. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  168. /* Verify if enabled */
  169. tmp_val = 0;
  170. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  171. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  172. return 0;
  173. }
  174. static iopin_t ioregs_init[] = {
  175. /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
  176. {
  177. offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
  178. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  179. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  180. },
  181. /* Set highest Slew on 9 PATA pins */
  182. {
  183. offsetof(struct ioctrl512x, io_control_pata_ce1), 9, 1,
  184. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  185. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  186. },
  187. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  188. {
  189. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  190. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  191. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  192. },
  193. /* FUNC1=SPDIF_TXCLK */
  194. {
  195. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  196. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  197. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  198. },
  199. /* FUNC2=SPDIF_TX and sets Next pin to SPDIF_RX */
  200. {
  201. offsetof(struct ioctrl512x, io_control_i2c1_scl), 2, 0,
  202. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  203. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  204. },
  205. /* FUNC2=DIU CLK */
  206. {
  207. offsetof(struct ioctrl512x, io_control_psc6_0), 1, 0,
  208. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  209. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  210. },
  211. /* FUNC2=DIU_HSYNC */
  212. {
  213. offsetof(struct ioctrl512x, io_control_psc6_1), 1, 0,
  214. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  215. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  216. },
  217. /* FUNC2=DIUVSYNC Sets Next 26 to DIU Pads */
  218. {
  219. offsetof(struct ioctrl512x, io_control_psc6_4), 26, 0,
  220. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  221. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  222. }
  223. };
  224. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  225. /* FUNC0=PCI Sets next 54 to PCI pads */
  226. {
  227. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  228. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  229. }
  230. };
  231. int checkboard (void)
  232. {
  233. ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
  234. uchar cpld_rev = *(vu_char *) (CONFIG_SYS_CPLD_BASE + 0x02);
  235. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  236. u32 spridr = in_be32(&im->sysconf.spridr);
  237. printf ("Board: MPC5121ADS rev. 0x%04x (CPLD rev. 0x%02x)\n",
  238. brd_rev, cpld_rev);
  239. /* initialize function mux & slew rate IO inter alia on IO Pins */
  240. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  241. if (SVR_MJREV (spridr) >= 2)
  242. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  243. return 0;
  244. }
  245. #ifdef CONFIG_OF_BOARD_SETUP
  246. int ft_board_setup(void *blob, bd_t *bd)
  247. {
  248. ft_cpu_setup(blob, bd);
  249. return 0;
  250. }
  251. #endif /* CONFIG_OF_BOARD_SETUP */