mecp5123.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * (C) Copyright 2009 Wolfgang Denk <wd@denx.de>
  3. * (C) Copyright 2009 Dave Srl www.dave.eu
  4. * (C) Copyright 2009 Stefan Roese <sr@denx.de>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. */
  25. #include <common.h>
  26. #include <asm/bitops.h>
  27. #include <command.h>
  28. #include <asm/io.h>
  29. #include <asm/processor.h>
  30. #include <asm/mpc512x.h>
  31. #include <fdt_support.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. /* Clocks in use */
  34. #define SCCR1_CLOCKS_EN (CLOCK_SCCR1_CFG_EN | \
  35. CLOCK_SCCR1_LPC_EN | \
  36. CLOCK_SCCR1_PSC_EN(CONFIG_PSC_CONSOLE) | \
  37. CLOCK_SCCR1_PSCFIFO_EN | \
  38. CLOCK_SCCR1_DDR_EN | \
  39. CLOCK_SCCR1_FEC_EN | \
  40. CLOCK_SCCR1_NFC_EN | \
  41. CLOCK_SCCR1_PCI_EN | \
  42. CLOCK_SCCR1_TPR_EN)
  43. #define SCCR2_CLOCKS_EN (CLOCK_SCCR2_MEM_EN | \
  44. CLOCK_SCCR2_I2C_EN)
  45. int eeprom_write_enable(unsigned dev_addr, int state)
  46. {
  47. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  48. if (dev_addr != CONFIG_SYS_I2C_EEPROM_ADDR)
  49. return -1;
  50. if (state == 0)
  51. setbits_be32(&im->gpio.gpdat, 0x00100000);
  52. else
  53. clrbits_be32(&im->gpio.gpdat, 0x00100000);
  54. return 0;
  55. }
  56. int board_early_init_f(void)
  57. {
  58. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  59. u32 spridr;
  60. int i;
  61. /*
  62. * Initialize Local Window for NOR FLASH access
  63. */
  64. out_be32(&im->sysconf.lpcs0aw,
  65. CSAW_START(CONFIG_SYS_FLASH_BASE) |
  66. CSAW_STOP(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
  67. sync_law(&im->sysconf.lpcs0aw);
  68. /*
  69. * Initialize Local Window for boot access
  70. */
  71. out_be32(&im->sysconf.lpbaw,
  72. CSAW_START(0xffb00000) | CSAW_STOP(0xffb00000, 0x00010000));
  73. sync_law(&im->sysconf.lpbaw);
  74. /*
  75. * Initialize Local Window for VPC3 access
  76. */
  77. out_be32(&im->sysconf.lpcs1aw,
  78. CSAW_START(CONFIG_SYS_VPC3_BASE) |
  79. CSAW_STOP(CONFIG_SYS_VPC3_BASE, CONFIG_SYS_VPC3_SIZE));
  80. sync_law(&im->sysconf.lpcs1aw);
  81. /*
  82. * Configure Flash Speed
  83. */
  84. out_be32(&im->lpc.cs_cfg[0], CONFIG_SYS_CS0_CFG);
  85. /*
  86. * Configure VPC3 Speed
  87. */
  88. out_be32(&im->lpc.cs_cfg[1], CONFIG_SYS_CS1_CFG);
  89. spridr = in_be32(&im->sysconf.spridr);
  90. if (SVR_MJREV(spridr) >= 2)
  91. out_be32(&im->lpc.altr, CONFIG_SYS_CS_ALETIMING);
  92. /*
  93. * Enable clocks
  94. */
  95. out_be32(&im->clk.sccr[0], SCCR1_CLOCKS_EN);
  96. out_be32(&im->clk.sccr[1], SCCR2_CLOCKS_EN);
  97. #if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
  98. setbits_be32(&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
  99. #endif
  100. /*
  101. * Configure MSCAN clocks
  102. */
  103. for (i=0; i<4; ++i) {
  104. out_be32(&im->clk.msccr[i], 0x00300000);
  105. out_be32(&im->clk.msccr[i], 0x00310000);
  106. }
  107. /*
  108. * Configure GPIO's
  109. */
  110. clrbits_be32(&im->gpio.gpodr, 0x000000e0);
  111. clrbits_be32(&im->gpio.gpdir, 0x00ef0000);
  112. setbits_be32(&im->gpio.gpdir, 0x001000e0);
  113. setbits_be32(&im->gpio.gpdat, 0x00100000);
  114. return 0;
  115. }
  116. phys_size_t initdram(int board_type)
  117. {
  118. return get_ram_size(0, fixed_sdram());
  119. }
  120. int misc_init_r(void)
  121. {
  122. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  123. u32 val;
  124. /*
  125. * Optimize access to profibus chip (VPC3) on the local bus
  126. */
  127. /*
  128. * Select 1:1 for LPC_DIV
  129. */
  130. val = in_be32(&im->clk.scfr[0]) & ~SCFR1_LPC_DIV_MASK;
  131. out_be32(&im->clk.scfr[0], val | (0x1 << SCFR1_LPC_DIV_SHIFT));
  132. /*
  133. * Configure LPC Chips Select Deadcycle Control Register
  134. * CS0 - device can drive data 2 clock cycle(s) after CS deassertion
  135. * CS1 - device can drive data 1 clock cycle(s) after CS deassertion
  136. */
  137. clrbits_be32(&im->lpc.cs_dccr, 0x000000ff);
  138. setbits_be32(&im->lpc.cs_dccr, (0x00 << 4) | (0x01 << 0));
  139. /*
  140. * Configure LPC Chips Select Holdcycle Control Register
  141. * CS0 - data is valid 2 clock cycle(s) after CS deassertion
  142. * CS1 - data is valid 1 clock cycle(s) after CS deassertion
  143. */
  144. clrbits_be32(&im->lpc.cs_hccr, 0x000000ff);
  145. setbits_be32(&im->lpc.cs_hccr, (0x00 << 4) | (0x01 << 0));
  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. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  156. {
  157. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  158. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  159. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  160. },
  161. /* FUNC1=SELECT LPC_CS1 */
  162. {
  163. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  164. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  165. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  166. },
  167. /* FUNC3=SELECT PSC5_2 */
  168. {
  169. offsetof(struct ioctrl512x, io_control_psc5_2), 1, 0,
  170. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  171. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  172. },
  173. /* FUNC3=SELECT PSC5_3 */
  174. {
  175. offsetof(struct ioctrl512x, io_control_psc5_3), 1, 0,
  176. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  177. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  178. },
  179. /* FUNC3=SELECT PSC7_3 */
  180. {
  181. offsetof(struct ioctrl512x, io_control_psc7_3), 1, 0,
  182. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  183. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  184. },
  185. /* FUNC3=SELECT PSC9_0 */
  186. {
  187. offsetof(struct ioctrl512x, io_control_psc9_0), 3, 0,
  188. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  189. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  190. },
  191. /* FUNC3=SELECT PSC10_0 */
  192. {
  193. offsetof(struct ioctrl512x, io_control_psc10_0), 3, 0,
  194. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  195. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  196. },
  197. /* FUNC3=SELECT PSC10_3 */
  198. {
  199. offsetof(struct ioctrl512x, io_control_psc10_3), 1, 0,
  200. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  201. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  202. },
  203. /* FUNC3=SELECT PSC11_0 */
  204. {
  205. offsetof(struct ioctrl512x, io_control_psc11_0), 4, 0,
  206. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  207. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  208. },
  209. /* FUNC0=SELECT IRQ0 */
  210. {
  211. offsetof(struct ioctrl512x, io_control_irq0), 4, 0,
  212. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  213. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  214. }
  215. };
  216. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  217. /* FUNC0=PCI Sets next 54 to PCI pads */
  218. {
  219. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  220. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  221. }
  222. };
  223. int checkboard(void)
  224. {
  225. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  226. u32 spridr;
  227. puts("Board: MECP_5123\n");
  228. /*
  229. * Initialize function mux & slew rate IO inter alia on IO
  230. * Pins
  231. */
  232. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  233. spridr = in_be32(&im->sysconf.spridr);
  234. if (SVR_MJREV(spridr) >= 2)
  235. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  236. return 0;
  237. }
  238. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  239. void ft_board_setup(void *blob, bd_t *bd)
  240. {
  241. ft_cpu_setup(blob, bd);
  242. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  243. }
  244. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */