mecp5123.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. int i;
  60. /*
  61. * Initialize Local Window for boot access
  62. */
  63. out_be32(&im->sysconf.lpbaw,
  64. CSAW_START(0xffb00000) | CSAW_STOP(0xffb00000, 0x00010000));
  65. sync_law(&im->sysconf.lpbaw);
  66. /*
  67. * Enable clocks
  68. */
  69. out_be32(&im->clk.sccr[0], SCCR1_CLOCKS_EN);
  70. out_be32(&im->clk.sccr[1], SCCR2_CLOCKS_EN);
  71. #if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
  72. setbits_be32(&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
  73. #endif
  74. /*
  75. * Configure MSCAN clocks
  76. */
  77. for (i=0; i<4; ++i) {
  78. out_be32(&im->clk.msccr[i], 0x00300000);
  79. out_be32(&im->clk.msccr[i], 0x00310000);
  80. }
  81. /*
  82. * Configure GPIO's
  83. */
  84. clrbits_be32(&im->gpio.gpodr, 0x000000e0);
  85. clrbits_be32(&im->gpio.gpdir, 0x00ef0000);
  86. setbits_be32(&im->gpio.gpdir, 0x001000e0);
  87. setbits_be32(&im->gpio.gpdat, 0x00100000);
  88. return 0;
  89. }
  90. phys_size_t initdram(int board_type)
  91. {
  92. return get_ram_size(0, fixed_sdram(NULL, NULL, 0));
  93. }
  94. int misc_init_r(void)
  95. {
  96. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  97. u32 val;
  98. /*
  99. * Optimize access to profibus chip (VPC3) on the local bus
  100. */
  101. /*
  102. * Select 1:1 for LPC_DIV
  103. */
  104. val = in_be32(&im->clk.scfr[0]) & ~SCFR1_LPC_DIV_MASK;
  105. out_be32(&im->clk.scfr[0], val | (0x1 << SCFR1_LPC_DIV_SHIFT));
  106. /*
  107. * Configure LPC Chips Select Deadcycle Control Register
  108. * CS0 - device can drive data 2 clock cycle(s) after CS deassertion
  109. * CS1 - device can drive data 1 clock cycle(s) after CS deassertion
  110. */
  111. clrbits_be32(&im->lpc.cs_dccr, 0x000000ff);
  112. setbits_be32(&im->lpc.cs_dccr, (0x00 << 4) | (0x01 << 0));
  113. /*
  114. * Configure LPC Chips Select Holdcycle Control Register
  115. * CS0 - data is valid 2 clock cycle(s) after CS deassertion
  116. * CS1 - data is valid 1 clock cycle(s) after CS deassertion
  117. */
  118. clrbits_be32(&im->lpc.cs_hccr, 0x000000ff);
  119. setbits_be32(&im->lpc.cs_hccr, (0x00 << 4) | (0x01 << 0));
  120. return 0;
  121. }
  122. static iopin_t ioregs_init[] = {
  123. /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
  124. {
  125. offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
  126. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  127. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  128. },
  129. /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
  130. {
  131. offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
  132. IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  133. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  134. },
  135. /* FUNC1=SELECT LPC_CS1 */
  136. {
  137. offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
  138. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  139. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  140. },
  141. /* FUNC3=SELECT PSC5_2 */
  142. {
  143. offsetof(struct ioctrl512x, io_control_psc5_2), 1, 0,
  144. IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  145. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  146. },
  147. /* FUNC3=SELECT PSC5_3 */
  148. {
  149. offsetof(struct ioctrl512x, io_control_psc5_3), 1, 0,
  150. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  151. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  152. },
  153. /* FUNC3=SELECT PSC7_3 */
  154. {
  155. offsetof(struct ioctrl512x, io_control_psc7_3), 1, 0,
  156. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  157. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  158. },
  159. /* FUNC3=SELECT PSC9_0 */
  160. {
  161. offsetof(struct ioctrl512x, io_control_psc9_0), 3, 0,
  162. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  163. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  164. },
  165. /* FUNC3=SELECT PSC10_0 */
  166. {
  167. offsetof(struct ioctrl512x, io_control_psc10_0), 3, 0,
  168. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  169. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  170. },
  171. /* FUNC3=SELECT PSC10_3 */
  172. {
  173. offsetof(struct ioctrl512x, io_control_psc10_3), 1, 0,
  174. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  175. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  176. },
  177. /* FUNC3=SELECT PSC11_0 */
  178. {
  179. offsetof(struct ioctrl512x, io_control_psc11_0), 4, 0,
  180. IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  181. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  182. },
  183. /* FUNC0=SELECT IRQ0 */
  184. {
  185. offsetof(struct ioctrl512x, io_control_irq0), 4, 0,
  186. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
  187. IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
  188. }
  189. };
  190. static iopin_t rev2_silicon_pci_ioregs_init[] = {
  191. /* FUNC0=PCI Sets next 54 to PCI pads */
  192. {
  193. offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
  194. IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
  195. }
  196. };
  197. int checkboard(void)
  198. {
  199. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  200. u32 spridr;
  201. puts("Board: MECP_5123\n");
  202. /*
  203. * Initialize function mux & slew rate IO inter alia on IO
  204. * Pins
  205. */
  206. iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
  207. spridr = in_be32(&im->sysconf.spridr);
  208. if (SVR_MJREV(spridr) >= 2)
  209. iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
  210. return 0;
  211. }
  212. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  213. void ft_board_setup(void *blob, bd_t *bd)
  214. {
  215. ft_cpu_setup(blob, bd);
  216. }
  217. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */