mpc5121ads.c 8.1 KB

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