mpc5121ads.c 9.3 KB

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