mt_ventoux.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (C) 2011
  3. * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
  4. *
  5. * Copyright (C) 2009 TechNexion Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (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.
  20. */
  21. #include <common.h>
  22. #include <netdev.h>
  23. #include <fpga.h>
  24. #include <asm/io.h>
  25. #include <asm/arch/mem.h>
  26. #include <asm/arch/mux.h>
  27. #include <asm/arch/sys_proto.h>
  28. #include <asm/omap_gpio.h>
  29. #include <asm/arch/mmc_host_def.h>
  30. #include <i2c.h>
  31. #include <spartan3.h>
  32. #include <asm/gpio.h>
  33. #ifdef CONFIG_USB_EHCI
  34. #include <usb.h>
  35. #include <asm/ehci-omap.h>
  36. #endif
  37. #include "mt_ventoux.h"
  38. DECLARE_GLOBAL_DATA_PTR;
  39. #ifndef CONFIG_FPGA
  40. #error "The Teejet mt_ventoux must have CONFIG_FPGA enabled"
  41. #endif
  42. #define FPGA_RESET 62
  43. #define FPGA_PROG 116
  44. #define FPGA_CCLK 117
  45. #define FPGA_DIN 118
  46. #define FPGA_INIT 119
  47. #define FPGA_DONE 154
  48. /* Timing definitions for FPGA */
  49. static const u32 gpmc_fpga[] = {
  50. FPGA_GPMC_CONFIG1,
  51. FPGA_GPMC_CONFIG2,
  52. FPGA_GPMC_CONFIG3,
  53. FPGA_GPMC_CONFIG4,
  54. FPGA_GPMC_CONFIG5,
  55. FPGA_GPMC_CONFIG6,
  56. };
  57. #ifdef CONFIG_USB_EHCI
  58. static struct omap_usbhs_board_data usbhs_bdata = {
  59. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  60. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  61. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  62. };
  63. int ehci_hcd_init(void)
  64. {
  65. return omap_ehci_hcd_init(&usbhs_bdata);
  66. }
  67. int ehci_hcd_stop(void)
  68. {
  69. return omap_ehci_hcd_stop();
  70. }
  71. #endif
  72. static inline void fpga_reset(int nassert)
  73. {
  74. gpio_set_value(FPGA_RESET, !nassert);
  75. }
  76. int fpga_pgm_fn(int nassert, int nflush, int cookie)
  77. {
  78. debug("%s:%d: FPGA PROGRAM ", __func__, __LINE__);
  79. gpio_set_value(FPGA_PROG, !nassert);
  80. return nassert;
  81. }
  82. int fpga_init_fn(int cookie)
  83. {
  84. return !gpio_get_value(FPGA_INIT);
  85. }
  86. int fpga_done_fn(int cookie)
  87. {
  88. return gpio_get_value(FPGA_DONE);
  89. }
  90. int fpga_pre_config_fn(int cookie)
  91. {
  92. debug("%s:%d: FPGA pre-configuration\n", __func__, __LINE__);
  93. /* Setting GPIOs for programming Mode */
  94. gpio_request(FPGA_RESET, "FPGA_RESET");
  95. gpio_direction_output(FPGA_RESET, 1);
  96. gpio_request(FPGA_PROG, "FPGA_PROG");
  97. gpio_direction_output(FPGA_PROG, 1);
  98. gpio_request(FPGA_CCLK, "FPGA_CCLK");
  99. gpio_direction_output(FPGA_CCLK, 1);
  100. gpio_request(FPGA_DIN, "FPGA_DIN");
  101. gpio_direction_output(FPGA_DIN, 0);
  102. gpio_request(FPGA_INIT, "FPGA_INIT");
  103. gpio_direction_input(FPGA_INIT);
  104. gpio_request(FPGA_DONE, "FPGA_DONE");
  105. gpio_direction_input(FPGA_DONE);
  106. /* Be sure that signal are deasserted */
  107. gpio_set_value(FPGA_RESET, 1);
  108. gpio_set_value(FPGA_PROG, 1);
  109. return 0;
  110. }
  111. int fpga_post_config_fn(int cookie)
  112. {
  113. debug("%s:%d: FPGA post-configuration\n", __func__, __LINE__);
  114. fpga_reset(TRUE);
  115. udelay(100);
  116. fpga_reset(FALSE);
  117. return 0;
  118. }
  119. /* Write program to the FPGA */
  120. int fpga_wr_fn(int nassert_write, int flush, int cookie)
  121. {
  122. gpio_set_value(FPGA_DIN, nassert_write);
  123. return nassert_write;
  124. }
  125. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  126. {
  127. gpio_set_value(FPGA_CCLK, assert_clk);
  128. return assert_clk;
  129. }
  130. Xilinx_Spartan3_Slave_Serial_fns mt_ventoux_fpga_fns = {
  131. fpga_pre_config_fn,
  132. fpga_pgm_fn,
  133. fpga_clk_fn,
  134. fpga_init_fn,
  135. fpga_done_fn,
  136. fpga_wr_fn,
  137. fpga_post_config_fn,
  138. };
  139. Xilinx_desc fpga = XILINX_XC6SLX4_DESC(slave_serial,
  140. (void *)&mt_ventoux_fpga_fns, 0);
  141. /* Initialize the FPGA */
  142. static void mt_ventoux_init_fpga(void)
  143. {
  144. fpga_pre_config_fn(0);
  145. /* Setting CS1 for FPGA access */
  146. enable_gpmc_cs_config(gpmc_fpga, &gpmc_cfg->cs[1],
  147. FPGA_BASE_ADDR, GPMC_SIZE_128M);
  148. fpga_init();
  149. fpga_add(fpga_xilinx, &fpga);
  150. }
  151. /*
  152. * Routine: board_init
  153. * Description: Early hardware init.
  154. */
  155. int board_init(void)
  156. {
  157. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  158. /* boot param addr */
  159. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  160. mt_ventoux_init_fpga();
  161. return 0;
  162. }
  163. int misc_init_r(void)
  164. {
  165. dieid_num_r();
  166. return 0;
  167. }
  168. /*
  169. * Routine: set_muxconf_regs
  170. * Description: Setting up the configuration Mux registers specific to the
  171. * hardware. Many pins need to be moved from protect to primary
  172. * mode.
  173. */
  174. void set_muxconf_regs(void)
  175. {
  176. MUX_MT_VENTOUX();
  177. }
  178. /*
  179. * Initializes on-chip ethernet controllers.
  180. * to override, implement board_eth_init()
  181. */
  182. int board_eth_init(bd_t *bis)
  183. {
  184. davinci_emac_initialize();
  185. return 0;
  186. }
  187. #if defined(CONFIG_OMAP_HSMMC) && \
  188. !defined(CONFIG_SPL_BUILD)
  189. int board_mmc_init(bd_t *bis)
  190. {
  191. return omap_mmc_init(0);
  192. }
  193. #endif