mpc5121ads.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 <linux/mtd/mtd.h>
  34. #include <linux/mtd/nand.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /* Clocks in use */
  37. #define SCCR1_CLOCKS_EN (CLOCK_SCCR1_CFG_EN | \
  38. CLOCK_SCCR1_DDR_EN | \
  39. CLOCK_SCCR1_FEC_EN | \
  40. CLOCK_SCCR1_LPC_EN | \
  41. CLOCK_SCCR1_NFC_EN | \
  42. CLOCK_SCCR1_PATA_EN | \
  43. CLOCK_SCCR1_PCI_EN | \
  44. CLOCK_SCCR1_PSC_EN(CONFIG_PSC_CONSOLE) | \
  45. CLOCK_SCCR1_PSCFIFO_EN | \
  46. CLOCK_SCCR1_TPR_EN)
  47. #define SCCR2_CLOCKS_EN (CLOCK_SCCR2_DIU_EN | \
  48. CLOCK_SCCR2_I2C_EN | \
  49. CLOCK_SCCR2_MEM_EN | \
  50. CLOCK_SCCR2_SPDIF_EN)
  51. void __mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip);
  52. /* Active chip number set in board_nand_select_device() (mpc5121_nfc.c) */
  53. extern int mpc5121_nfc_chip;
  54. /* Control chips select signal on MPC5121ADS board */
  55. void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
  56. {
  57. unsigned char *csreg = (u8 *)CONFIG_SYS_CPLD_BASE + 0x09;
  58. u8 v;
  59. v = in_8(csreg);
  60. v |= 0x0F;
  61. if (chip >= 0) {
  62. __mpc5121_nfc_select_chip(mtd, 0);
  63. v &= ~(1 << mpc5121_nfc_chip);
  64. } else {
  65. __mpc5121_nfc_select_chip(mtd, -1);
  66. }
  67. out_8(csreg, v);
  68. }
  69. int board_early_init_f(void)
  70. {
  71. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  72. u32 spridr;
  73. /*
  74. * Initialize Local Window for the CPLD registers access (CS2 selects
  75. * the CPLD chip)
  76. */
  77. out_be32(&im->sysconf.lpcs2aw,
  78. CSAW_START(CONFIG_SYS_CPLD_BASE) |
  79. CSAW_STOP(CONFIG_SYS_CPLD_BASE, CONFIG_SYS_CPLD_SIZE)
  80. );
  81. out_be32(&im->lpc.cs_cfg[2], CONFIG_SYS_CS2_CFG);
  82. sync_law(&im->sysconf.lpcs2aw);
  83. /*
  84. * Disable Boot NOR FLASH write protect - CPLD Reg 8 NOR FLASH Control
  85. *
  86. * Without this the flash identification routine fails, as it needs to issue
  87. * write commands in order to establish the device ID.
  88. */
  89. #ifdef CONFIG_ADS5121_REV2
  90. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  91. #else
  92. if (in_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08)) & 0x04) {
  93. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
  94. } else {
  95. /* running from Backup flash */
  96. out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0x32);
  97. }
  98. #endif
  99. /*
  100. * Configure Flash Speed
  101. */
  102. out_be32(&im->lpc.cs_cfg[0], CONFIG_SYS_CS0_CFG);
  103. spridr = in_be32(&im->sysconf.spridr);
  104. if (SVR_MJREV (spridr) >= 2)
  105. out_be32 (&im->lpc.altr, CONFIG_SYS_CS_ALETIMING);
  106. /*
  107. * Enable clocks
  108. */
  109. out_be32 (&im->clk.sccr[0], SCCR1_CLOCKS_EN);
  110. out_be32 (&im->clk.sccr[1], SCCR2_CLOCKS_EN);
  111. #if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
  112. setbits_be32 (&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
  113. #endif
  114. return 0;
  115. }
  116. phys_size_t initdram(int board_type)
  117. {
  118. u32 msize = 0;
  119. msize = fixed_sdram();
  120. return msize;
  121. }
  122. int misc_init_r(void)
  123. {
  124. u8 tmp_val;
  125. /* Using this for DIU init before the driver in linux takes over
  126. * Enable the TFP410 Encoder (I2C address 0x38)
  127. */
  128. i2c_set_bus_num(2);
  129. tmp_val = 0xBF;
  130. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  131. /* Verify if enabled */
  132. tmp_val = 0;
  133. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  134. debug("DVI Encoder Read: 0x%02lx\n", tmp_val);
  135. tmp_val = 0x10;
  136. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  137. /* Verify if enabled */
  138. tmp_val = 0;
  139. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  140. debug("DVI Encoder Read: 0x%02lx\n", tmp_val);
  141. #ifdef CONFIG_FSL_DIU_FB
  142. # if !(defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE))
  143. mpc5121_diu_init();
  144. # endif
  145. #endif
  146. return 0;
  147. }
  148. static iopin_t ioregs_init[] = {
  149. /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
  150. {
  151. offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
  152. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  153. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  154. },
  155. /* Set highest Slew on 9 PATA pins */
  156. {
  157. offsetof(struct ioctrl512x, io_control_pata_ce1), 9, 1,
  158. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  159. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  160. },
  161. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  162. {
  163. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  164. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  165. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  166. },
  167. /* FUNC1=SPDIF_TXCLK */
  168. {
  169. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  170. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  171. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  172. },
  173. /* FUNC2=SPDIF_TX and sets Next pin to SPDIF_RX */
  174. {
  175. offsetof(struct ioctrl512x, io_control_i2c1_scl), 2, 0,
  176. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  177. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  178. },
  179. /* FUNC2=DIU CLK */
  180. {
  181. offsetof(struct ioctrl512x, io_control_psc6_0), 1, 0,
  182. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  183. IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
  184. },
  185. /* FUNC2=DIU_HSYNC */
  186. {
  187. offsetof(struct ioctrl512x, io_control_psc6_1), 1, 0,
  188. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  189. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  190. },
  191. /* FUNC2=DIUVSYNC Sets Next 26 to DIU Pads */
  192. {
  193. offsetof(struct ioctrl512x, io_control_psc6_4), 26, 0,
  194. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  195. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  196. }
  197. };
  198. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  199. /* FUNC0=PCI Sets next 54 to PCI pads */
  200. {
  201. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  202. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  203. }
  204. };
  205. int checkboard (void)
  206. {
  207. ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
  208. uchar cpld_rev = *(vu_char *) (CONFIG_SYS_CPLD_BASE + 0x02);
  209. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  210. u32 spridr = in_be32(&im->sysconf.spridr);
  211. printf ("Board: ADS5121 rev. 0x%04x (CPLD rev. 0x%02x)\n",
  212. brd_rev, cpld_rev);
  213. /* initialize function mux & slew rate IO inter alia on IO Pins */
  214. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  215. if (SVR_MJREV (spridr) >= 2)
  216. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  217. return 0;
  218. }
  219. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  220. void ft_board_setup(void *blob, bd_t *bd)
  221. {
  222. ft_cpu_setup(blob, bd);
  223. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  224. }
  225. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */