mpc5121ads.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. u32 spridr;
  76. /*
  77. * Initialize Local Window for the CPLD registers access (CS2 selects
  78. * the CPLD chip)
  79. */
  80. out_be32(&im->sysconf.lpcs2aw,
  81. CSAW_START(CONFIG_SYS_CPLD_BASE) |
  82. CSAW_STOP(CONFIG_SYS_CPLD_BASE, CONFIG_SYS_CPLD_SIZE)
  83. );
  84. out_be32(&im->lpc.cs_cfg[2], CONFIG_SYS_CS2_CFG);
  85. sync_law(&im->sysconf.lpcs2aw);
  86. /*
  87. * Disable Boot NOR FLASH write protect - CPLD Reg 8 NOR FLASH Control
  88. *
  89. * Without this the flash identification routine fails, as it needs to issue
  90. * write commands in order to establish the device ID.
  91. */
  92. #ifdef CONFIG_MPC5121ADS_REV2
  93. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  94. #else
  95. if (in_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08)) & 0x04) {
  96. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  97. } else {
  98. /* running from Backup flash */
  99. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0x32);
  100. }
  101. #endif
  102. /*
  103. * Configure Flash Speed
  104. */
  105. out_be32(&im->lpc.cs_cfg[0], CONFIG_SYS_CS0_CFG);
  106. spridr = in_be32(&im->sysconf.spridr);
  107. if (SVR_MJREV (spridr) >= 2)
  108. out_be32 (&im->lpc.altr, CONFIG_SYS_CS_ALETIMING);
  109. /*
  110. * Enable clocks
  111. */
  112. out_be32 (&im->clk.sccr[0], SCCR1_CLOCKS_EN);
  113. out_be32 (&im->clk.sccr[1], SCCR2_CLOCKS_EN);
  114. #if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
  115. setbits_be32 (&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
  116. #endif
  117. return 0;
  118. }
  119. int is_micron(void){
  120. ushort brd_rev = *(vu_short *)(CONFIG_SYS_CPLD_BASE + 0x00);
  121. uchar macaddr[6];
  122. u32 brddate, macchk, ismicron;
  123. /*
  124. * MAC address has serial number with date of manufacture
  125. * Boards made before Nov-08 #1180 use Micron memory;
  126. * 001e59 is the STx vendor #
  127. * Default is Elpida since it works for both but is slightly slower
  128. */
  129. ismicron = 0;
  130. if (brd_rev >= 0x0400 && eth_getenv_enetaddr("ethaddr", macaddr)) {
  131. brddate = (macaddr[3] << 16) + (macaddr[4] << 8) + macaddr[5];
  132. macchk = (macaddr[0] << 16) + (macaddr[1] << 8) + macaddr[2];
  133. debug("brddate = %d\n\t", brddate);
  134. if (macchk == 0x001e59 && brddate <= 8111180)
  135. ismicron = 1;
  136. } else if (brd_rev < 0x400) {
  137. ismicron = 1;
  138. }
  139. debug("Using %s Memory settings\n\t",
  140. ismicron ? "Micron" : "Elpida");
  141. return(ismicron);
  142. }
  143. phys_size_t initdram(int board_type)
  144. {
  145. u32 msize = 0;
  146. /*
  147. * Elpida MDDRC and initialization settings are an alternative
  148. * to the Default Micron ones for all but the earliest Rev 4 boards
  149. */
  150. ddr512x_config_t elpida_mddrc_config = {
  151. .ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA,
  152. .ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0,
  153. .ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA,
  154. .ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA,
  155. };
  156. u32 elpida_init_sequence[] = {
  157. CONFIG_SYS_DDRCMD_NOP,
  158. CONFIG_SYS_DDRCMD_NOP,
  159. CONFIG_SYS_DDRCMD_NOP,
  160. CONFIG_SYS_DDRCMD_NOP,
  161. CONFIG_SYS_DDRCMD_NOP,
  162. CONFIG_SYS_DDRCMD_NOP,
  163. CONFIG_SYS_DDRCMD_NOP,
  164. CONFIG_SYS_DDRCMD_NOP,
  165. CONFIG_SYS_DDRCMD_NOP,
  166. CONFIG_SYS_DDRCMD_NOP,
  167. CONFIG_SYS_DDRCMD_PCHG_ALL,
  168. CONFIG_SYS_DDRCMD_NOP,
  169. CONFIG_SYS_DDRCMD_RFSH,
  170. CONFIG_SYS_DDRCMD_NOP,
  171. CONFIG_SYS_DDRCMD_RFSH,
  172. CONFIG_SYS_DDRCMD_NOP,
  173. CONFIG_SYS_DDRCMD_EM2,
  174. CONFIG_SYS_DDRCMD_EM3,
  175. CONFIG_SYS_DDRCMD_EN_DLL,
  176. CONFIG_SYS_ELPIDA_RES_DLL,
  177. CONFIG_SYS_DDRCMD_PCHG_ALL,
  178. CONFIG_SYS_DDRCMD_RFSH,
  179. CONFIG_SYS_DDRCMD_RFSH,
  180. CONFIG_SYS_DDRCMD_RFSH,
  181. CONFIG_SYS_ELPIDA_INIT_DEV_OP,
  182. CONFIG_SYS_DDRCMD_NOP,
  183. CONFIG_SYS_DDRCMD_NOP,
  184. CONFIG_SYS_DDRCMD_NOP,
  185. CONFIG_SYS_DDRCMD_NOP,
  186. CONFIG_SYS_DDRCMD_NOP,
  187. CONFIG_SYS_DDRCMD_NOP,
  188. CONFIG_SYS_DDRCMD_NOP,
  189. CONFIG_SYS_DDRCMD_NOP,
  190. CONFIG_SYS_DDRCMD_NOP,
  191. CONFIG_SYS_DDRCMD_NOP,
  192. CONFIG_SYS_DDRCMD_OCD_DEFAULT,
  193. CONFIG_SYS_ELPIDA_OCD_EXIT,
  194. CONFIG_SYS_DDRCMD_NOP,
  195. CONFIG_SYS_DDRCMD_NOP,
  196. CONFIG_SYS_DDRCMD_NOP,
  197. CONFIG_SYS_DDRCMD_NOP,
  198. CONFIG_SYS_DDRCMD_NOP,
  199. CONFIG_SYS_DDRCMD_NOP,
  200. CONFIG_SYS_DDRCMD_NOP,
  201. CONFIG_SYS_DDRCMD_NOP,
  202. CONFIG_SYS_DDRCMD_NOP,
  203. CONFIG_SYS_DDRCMD_NOP
  204. };
  205. if (is_micron()) {
  206. msize = fixed_sdram(NULL, NULL, 0);
  207. } else {
  208. msize = fixed_sdram(&elpida_mddrc_config,
  209. elpida_init_sequence,
  210. sizeof(elpida_init_sequence)/sizeof(u32));
  211. }
  212. return msize;
  213. }
  214. int misc_init_r(void)
  215. {
  216. u8 tmp_val;
  217. /* Using this for DIU init before the driver in linux takes over
  218. * Enable the TFP410 Encoder (I2C address 0x38)
  219. */
  220. i2c_set_bus_num(2);
  221. tmp_val = 0xBF;
  222. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  223. /* Verify if enabled */
  224. tmp_val = 0;
  225. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  226. debug("DVI Encoder Read: 0x%02lx\n", tmp_val);
  227. tmp_val = 0x10;
  228. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  229. /* Verify if enabled */
  230. tmp_val = 0;
  231. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  232. debug("DVI Encoder Read: 0x%02lx\n", tmp_val);
  233. return 0;
  234. }
  235. static iopin_t ioregs_init[] = {
  236. /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
  237. {
  238. offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
  239. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  240. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  241. },
  242. /* Set highest Slew on 9 PATA pins */
  243. {
  244. offsetof(struct ioctrl512x, io_control_pata_ce1), 9, 1,
  245. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  246. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  247. },
  248. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  249. {
  250. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  251. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  252. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  253. },
  254. /* FUNC1=SPDIF_TXCLK */
  255. {
  256. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  257. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  258. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  259. },
  260. /* FUNC2=SPDIF_TX and sets Next pin to SPDIF_RX */
  261. {
  262. offsetof(struct ioctrl512x, io_control_i2c1_scl), 2, 0,
  263. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  264. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  265. },
  266. /* FUNC2=DIU CLK */
  267. {
  268. offsetof(struct ioctrl512x, io_control_psc6_0), 1, 0,
  269. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  270. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  271. },
  272. /* FUNC2=DIU_HSYNC */
  273. {
  274. offsetof(struct ioctrl512x, io_control_psc6_1), 1, 0,
  275. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  276. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  277. },
  278. /* FUNC2=DIUVSYNC Sets Next 26 to DIU Pads */
  279. {
  280. offsetof(struct ioctrl512x, io_control_psc6_4), 26, 0,
  281. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  282. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  283. }
  284. };
  285. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  286. /* FUNC0=PCI Sets next 54 to PCI pads */
  287. {
  288. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  289. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  290. }
  291. };
  292. int checkboard (void)
  293. {
  294. ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
  295. uchar cpld_rev = *(vu_char *) (CONFIG_SYS_CPLD_BASE + 0x02);
  296. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  297. u32 spridr = in_be32(&im->sysconf.spridr);
  298. printf ("Board: MPC5121ADS rev. 0x%04x (CPLD rev. 0x%02x)\n",
  299. brd_rev, cpld_rev);
  300. /* initialize function mux & slew rate IO inter alia on IO Pins */
  301. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  302. if (SVR_MJREV (spridr) >= 2)
  303. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  304. return 0;
  305. }
  306. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  307. void ft_board_setup(void *blob, bd_t *bd)
  308. {
  309. ft_cpu_setup(blob, bd);
  310. }
  311. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */