mpc5121ads.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. /* Clocks in use */
  38. #define SCCR1_CLOCKS_EN (CLOCK_SCCR1_CFG_EN | \
  39. CLOCK_SCCR1_DDR_EN | \
  40. CLOCK_SCCR1_FEC_EN | \
  41. CLOCK_SCCR1_LPC_EN | \
  42. CLOCK_SCCR1_NFC_EN | \
  43. CLOCK_SCCR1_PATA_EN | \
  44. CLOCK_SCCR1_PCI_EN | \
  45. CLOCK_SCCR1_PSC_EN(CONFIG_PSC_CONSOLE) | \
  46. CLOCK_SCCR1_PSCFIFO_EN | \
  47. CLOCK_SCCR1_TPR_EN)
  48. #define SCCR2_CLOCKS_EN (CLOCK_SCCR2_DIU_EN | \
  49. CLOCK_SCCR2_I2C_EN | \
  50. CLOCK_SCCR2_MEM_EN | \
  51. CLOCK_SCCR2_SPDIF_EN | \
  52. CLOCK_SCCR2_USB1_EN | \
  53. CLOCK_SCCR2_USB2_EN)
  54. void __mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip);
  55. /* Active chip number set in board_nand_select_device() (mpc5121_nfc.c) */
  56. extern int mpc5121_nfc_chip;
  57. /* Control chips select signal on MPC5121ADS board */
  58. void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
  59. {
  60. unsigned char *csreg = (u8 *)CONFIG_SYS_CPLD_BASE + 0x09;
  61. u8 v;
  62. v = in_8(csreg);
  63. v |= 0x0F;
  64. if (chip >= 0) {
  65. __mpc5121_nfc_select_chip(mtd, 0);
  66. v &= ~(1 << mpc5121_nfc_chip);
  67. } else {
  68. __mpc5121_nfc_select_chip(mtd, -1);
  69. }
  70. out_8(csreg, v);
  71. }
  72. int board_early_init_f(void)
  73. {
  74. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  75. /*
  76. * Disable Boot NOR FLASH write protect - CPLD Reg 8 NOR FLASH Control
  77. *
  78. * Without this the flash identification routine fails, as it needs to issue
  79. * write commands in order to establish the device ID.
  80. */
  81. #ifdef CONFIG_MPC5121ADS_REV2
  82. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  83. #else
  84. if (in_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08)) & 0x04) {
  85. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  86. } else {
  87. /* running from Backup flash */
  88. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0x32);
  89. }
  90. #endif
  91. /*
  92. * Enable clocks
  93. */
  94. out_be32 (&im->clk.sccr[0], SCCR1_CLOCKS_EN);
  95. out_be32 (&im->clk.sccr[1], SCCR2_CLOCKS_EN);
  96. #if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
  97. setbits_be32 (&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
  98. #endif
  99. return 0;
  100. }
  101. int is_micron(void){
  102. ushort brd_rev = *(vu_short *)(CONFIG_SYS_CPLD_BASE + 0x00);
  103. uchar macaddr[6];
  104. u32 brddate, macchk, ismicron;
  105. /*
  106. * MAC address has serial number with date of manufacture
  107. * Boards made before Nov-08 #1180 use Micron memory;
  108. * 001e59 is the STx vendor #
  109. * Default is Elpida since it works for both but is slightly slower
  110. */
  111. ismicron = 0;
  112. if (brd_rev >= 0x0400 && eth_getenv_enetaddr("ethaddr", macaddr)) {
  113. brddate = (macaddr[3] << 16) + (macaddr[4] << 8) + macaddr[5];
  114. macchk = (macaddr[0] << 16) + (macaddr[1] << 8) + macaddr[2];
  115. debug("brddate = %d\n\t", brddate);
  116. if (macchk == 0x001e59 && brddate <= 8111180)
  117. ismicron = 1;
  118. } else if (brd_rev < 0x400) {
  119. ismicron = 1;
  120. }
  121. debug("Using %s Memory settings\n\t",
  122. ismicron ? "Micron" : "Elpida");
  123. return(ismicron);
  124. }
  125. phys_size_t initdram(int board_type)
  126. {
  127. u32 msize = 0;
  128. /*
  129. * Elpida MDDRC and initialization settings are an alternative
  130. * to the Default Micron ones for all but the earliest Rev 4 boards
  131. */
  132. ddr512x_config_t elpida_mddrc_config = {
  133. .ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA,
  134. .ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0,
  135. .ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA,
  136. .ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA,
  137. };
  138. u32 elpida_init_sequence[] = {
  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_NOP,
  149. CONFIG_SYS_DDRCMD_PCHG_ALL,
  150. CONFIG_SYS_DDRCMD_NOP,
  151. CONFIG_SYS_DDRCMD_RFSH,
  152. CONFIG_SYS_DDRCMD_NOP,
  153. CONFIG_SYS_DDRCMD_RFSH,
  154. CONFIG_SYS_DDRCMD_NOP,
  155. CONFIG_SYS_DDRCMD_EM2,
  156. CONFIG_SYS_DDRCMD_EM3,
  157. CONFIG_SYS_DDRCMD_EN_DLL,
  158. CONFIG_SYS_ELPIDA_RES_DLL,
  159. CONFIG_SYS_DDRCMD_PCHG_ALL,
  160. CONFIG_SYS_DDRCMD_RFSH,
  161. CONFIG_SYS_DDRCMD_RFSH,
  162. CONFIG_SYS_DDRCMD_RFSH,
  163. CONFIG_SYS_ELPIDA_INIT_DEV_OP,
  164. CONFIG_SYS_DDRCMD_NOP,
  165. CONFIG_SYS_DDRCMD_NOP,
  166. CONFIG_SYS_DDRCMD_NOP,
  167. CONFIG_SYS_DDRCMD_NOP,
  168. CONFIG_SYS_DDRCMD_NOP,
  169. CONFIG_SYS_DDRCMD_NOP,
  170. CONFIG_SYS_DDRCMD_NOP,
  171. CONFIG_SYS_DDRCMD_NOP,
  172. CONFIG_SYS_DDRCMD_NOP,
  173. CONFIG_SYS_DDRCMD_NOP,
  174. CONFIG_SYS_DDRCMD_OCD_DEFAULT,
  175. CONFIG_SYS_ELPIDA_OCD_EXIT,
  176. CONFIG_SYS_DDRCMD_NOP,
  177. CONFIG_SYS_DDRCMD_NOP,
  178. CONFIG_SYS_DDRCMD_NOP,
  179. CONFIG_SYS_DDRCMD_NOP,
  180. CONFIG_SYS_DDRCMD_NOP,
  181. CONFIG_SYS_DDRCMD_NOP,
  182. CONFIG_SYS_DDRCMD_NOP,
  183. CONFIG_SYS_DDRCMD_NOP,
  184. CONFIG_SYS_DDRCMD_NOP,
  185. CONFIG_SYS_DDRCMD_NOP
  186. };
  187. if (is_micron()) {
  188. msize = fixed_sdram(NULL, NULL, 0);
  189. } else {
  190. msize = fixed_sdram(&elpida_mddrc_config,
  191. elpida_init_sequence,
  192. sizeof(elpida_init_sequence)/sizeof(u32));
  193. }
  194. return msize;
  195. }
  196. int misc_init_r(void)
  197. {
  198. u8 tmp_val;
  199. /* Using this for DIU init before the driver in linux takes over
  200. * Enable the TFP410 Encoder (I2C address 0x38)
  201. */
  202. i2c_set_bus_num(2);
  203. tmp_val = 0xBF;
  204. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  205. /* Verify if enabled */
  206. tmp_val = 0;
  207. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  208. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  209. tmp_val = 0x10;
  210. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  211. /* Verify if enabled */
  212. tmp_val = 0;
  213. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  214. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  215. return 0;
  216. }
  217. static iopin_t ioregs_init[] = {
  218. /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
  219. {
  220. offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
  221. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  222. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  223. },
  224. /* Set highest Slew on 9 PATA pins */
  225. {
  226. offsetof(struct ioctrl512x, io_control_pata_ce1), 9, 1,
  227. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  228. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  229. },
  230. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  231. {
  232. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  233. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  234. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  235. },
  236. /* FUNC1=SPDIF_TXCLK */
  237. {
  238. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  239. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  240. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  241. },
  242. /* FUNC2=SPDIF_TX and sets Next pin to SPDIF_RX */
  243. {
  244. offsetof(struct ioctrl512x, io_control_i2c1_scl), 2, 0,
  245. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  246. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  247. },
  248. /* FUNC2=DIU CLK */
  249. {
  250. offsetof(struct ioctrl512x, io_control_psc6_0), 1, 0,
  251. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  252. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  253. },
  254. /* FUNC2=DIU_HSYNC */
  255. {
  256. offsetof(struct ioctrl512x, io_control_psc6_1), 1, 0,
  257. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  258. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  259. },
  260. /* FUNC2=DIUVSYNC Sets Next 26 to DIU Pads */
  261. {
  262. offsetof(struct ioctrl512x, io_control_psc6_4), 26, 0,
  263. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  264. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  265. }
  266. };
  267. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  268. /* FUNC0=PCI Sets next 54 to PCI pads */
  269. {
  270. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  271. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  272. }
  273. };
  274. int checkboard (void)
  275. {
  276. ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
  277. uchar cpld_rev = *(vu_char *) (CONFIG_SYS_CPLD_BASE + 0x02);
  278. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  279. u32 spridr = in_be32(&im->sysconf.spridr);
  280. printf ("Board: MPC5121ADS rev. 0x%04x (CPLD rev. 0x%02x)\n",
  281. brd_rev, cpld_rev);
  282. /* initialize function mux & slew rate IO inter alia on IO Pins */
  283. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  284. if (SVR_MJREV (spridr) >= 2)
  285. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  286. return 0;
  287. }
  288. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  289. void ft_board_setup(void *blob, bd_t *bd)
  290. {
  291. ft_cpu_setup(blob, bd);
  292. }
  293. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */