mt_ventoux.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 <malloc.h>
  24. #include <fpga.h>
  25. #include <video_fb.h>
  26. #include <asm/io.h>
  27. #include <asm/arch/mem.h>
  28. #include <asm/arch/mux.h>
  29. #include <asm/arch/sys_proto.h>
  30. #include <asm/omap_gpio.h>
  31. #include <asm/arch/mmc_host_def.h>
  32. #include <asm/arch/dss.h>
  33. #include <asm/arch/clocks.h>
  34. #include <i2c.h>
  35. #include <spartan3.h>
  36. #include <asm/gpio.h>
  37. #ifdef CONFIG_USB_EHCI
  38. #include <usb.h>
  39. #include <asm/ehci-omap.h>
  40. #endif
  41. #include "mt_ventoux.h"
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #define BUZZER 140
  44. #define SPEAKER 141
  45. #define USB1_PWR 127
  46. #define USB2_PWR 149
  47. #ifndef CONFIG_FPGA
  48. #error "The Teejet mt_ventoux must have CONFIG_FPGA enabled"
  49. #endif
  50. #define FPGA_RESET 62
  51. #define FPGA_PROG 116
  52. #define FPGA_CCLK 117
  53. #define FPGA_DIN 118
  54. #define FPGA_INIT 119
  55. #define FPGA_DONE 154
  56. #define LCD_PWR 138
  57. #define LCD_PON_PIN 139
  58. #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
  59. static struct {
  60. u32 xres;
  61. u32 yres;
  62. } panel_resolution[] = {
  63. { 480, 272 },
  64. { 800, 480 }
  65. };
  66. static struct panel_config lcd_cfg[] = {
  67. {
  68. .timing_h = PANEL_TIMING_H(40, 5, 2),
  69. .timing_v = PANEL_TIMING_V(8, 8, 2),
  70. .pol_freq = 0x00003000, /* Pol Freq */
  71. .divisor = 0x00010033, /* 9 Mhz Pixel Clock */
  72. .panel_type = 0x01, /* TFT */
  73. .data_lines = 0x03, /* 24 Bit RGB */
  74. .load_mode = 0x02, /* Frame Mode */
  75. .panel_color = 0,
  76. },
  77. {
  78. .timing_h = PANEL_TIMING_H(20, 192, 4),
  79. .timing_v = PANEL_TIMING_V(2, 20, 10),
  80. .pol_freq = 0x00004000, /* Pol Freq */
  81. .divisor = 0x0001000E, /* 36Mhz Pixel Clock */
  82. .panel_type = 0x01, /* TFT */
  83. .data_lines = 0x03, /* 24 Bit RGB */
  84. .load_mode = 0x02, /* Frame Mode */
  85. .panel_color = 0,
  86. }
  87. };
  88. #endif
  89. /* Timing definitions for FPGA */
  90. static const u32 gpmc_fpga[] = {
  91. FPGA_GPMC_CONFIG1,
  92. FPGA_GPMC_CONFIG2,
  93. FPGA_GPMC_CONFIG3,
  94. FPGA_GPMC_CONFIG4,
  95. FPGA_GPMC_CONFIG5,
  96. FPGA_GPMC_CONFIG6,
  97. };
  98. #ifdef CONFIG_USB_EHCI
  99. static struct omap_usbhs_board_data usbhs_bdata = {
  100. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  101. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  102. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  103. };
  104. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  105. {
  106. return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
  107. }
  108. int ehci_hcd_stop(int index)
  109. {
  110. return omap_ehci_hcd_stop();
  111. }
  112. #endif
  113. static inline void fpga_reset(int nassert)
  114. {
  115. gpio_set_value(FPGA_RESET, !nassert);
  116. }
  117. int fpga_pgm_fn(int nassert, int nflush, int cookie)
  118. {
  119. debug("%s:%d: FPGA PROGRAM ", __func__, __LINE__);
  120. gpio_set_value(FPGA_PROG, !nassert);
  121. return nassert;
  122. }
  123. int fpga_init_fn(int cookie)
  124. {
  125. return !gpio_get_value(FPGA_INIT);
  126. }
  127. int fpga_done_fn(int cookie)
  128. {
  129. return gpio_get_value(FPGA_DONE);
  130. }
  131. int fpga_pre_config_fn(int cookie)
  132. {
  133. debug("%s:%d: FPGA pre-configuration\n", __func__, __LINE__);
  134. /* Setting GPIOs for programming Mode */
  135. gpio_request(FPGA_RESET, "FPGA_RESET");
  136. gpio_direction_output(FPGA_RESET, 1);
  137. gpio_request(FPGA_PROG, "FPGA_PROG");
  138. gpio_direction_output(FPGA_PROG, 1);
  139. gpio_request(FPGA_CCLK, "FPGA_CCLK");
  140. gpio_direction_output(FPGA_CCLK, 1);
  141. gpio_request(FPGA_DIN, "FPGA_DIN");
  142. gpio_direction_output(FPGA_DIN, 0);
  143. gpio_request(FPGA_INIT, "FPGA_INIT");
  144. gpio_direction_input(FPGA_INIT);
  145. gpio_request(FPGA_DONE, "FPGA_DONE");
  146. gpio_direction_input(FPGA_DONE);
  147. /* Be sure that signal are deasserted */
  148. gpio_set_value(FPGA_RESET, 1);
  149. gpio_set_value(FPGA_PROG, 1);
  150. return 0;
  151. }
  152. int fpga_post_config_fn(int cookie)
  153. {
  154. debug("%s:%d: FPGA post-configuration\n", __func__, __LINE__);
  155. fpga_reset(TRUE);
  156. udelay(100);
  157. fpga_reset(FALSE);
  158. return 0;
  159. }
  160. /* Write program to the FPGA */
  161. int fpga_wr_fn(int nassert_write, int flush, int cookie)
  162. {
  163. gpio_set_value(FPGA_DIN, nassert_write);
  164. return nassert_write;
  165. }
  166. int fpga_clk_fn(int assert_clk, int flush, int cookie)
  167. {
  168. gpio_set_value(FPGA_CCLK, assert_clk);
  169. return assert_clk;
  170. }
  171. Xilinx_Spartan3_Slave_Serial_fns mt_ventoux_fpga_fns = {
  172. fpga_pre_config_fn,
  173. fpga_pgm_fn,
  174. fpga_clk_fn,
  175. fpga_init_fn,
  176. fpga_done_fn,
  177. fpga_wr_fn,
  178. fpga_post_config_fn,
  179. };
  180. Xilinx_desc fpga = XILINX_XC6SLX4_DESC(slave_serial,
  181. (void *)&mt_ventoux_fpga_fns, 0);
  182. /* Initialize the FPGA */
  183. static void mt_ventoux_init_fpga(void)
  184. {
  185. fpga_pre_config_fn(0);
  186. /* Setting CS1 for FPGA access */
  187. enable_gpmc_cs_config(gpmc_fpga, &gpmc_cfg->cs[1],
  188. FPGA_BASE_ADDR, GPMC_SIZE_128M);
  189. fpga_init();
  190. fpga_add(fpga_xilinx, &fpga);
  191. }
  192. /*
  193. * Routine: board_init
  194. * Description: Early hardware init.
  195. */
  196. int board_init(void)
  197. {
  198. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  199. /* boot param addr */
  200. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  201. mt_ventoux_init_fpga();
  202. /* GPIO_140: speaker #mute */
  203. MUX_VAL(CP(MCBSP3_DX), (IEN | PTU | EN | M4))
  204. /* GPIO_141: Buzz Hi */
  205. MUX_VAL(CP(MCBSP3_DR), (IEN | PTU | EN | M4))
  206. /* Turning off the buzzer */
  207. gpio_request(BUZZER, "BUZZER_MUTE");
  208. gpio_request(SPEAKER, "SPEAKER");
  209. gpio_direction_output(BUZZER, 0);
  210. gpio_direction_output(SPEAKER, 0);
  211. /* Activate USB power */
  212. gpio_request(USB1_PWR, "USB1_PWR");
  213. gpio_request(USB2_PWR, "USB2_PWR");
  214. gpio_direction_output(USB1_PWR, 1);
  215. gpio_direction_output(USB2_PWR, 1);
  216. return 0;
  217. }
  218. #ifndef CONFIG_SPL_BUILD
  219. int misc_init_r(void)
  220. {
  221. char *eth_addr;
  222. struct tam3517_module_info info;
  223. int ret;
  224. TAM3517_READ_EEPROM(&info, ret);
  225. dieid_num_r();
  226. if (ret)
  227. return 0;
  228. eth_addr = getenv("ethaddr");
  229. if (!eth_addr)
  230. TAM3517_READ_MAC_FROM_EEPROM(&info);
  231. TAM3517_PRINT_SOM_INFO(&info);
  232. return 0;
  233. }
  234. #endif
  235. /*
  236. * Routine: set_muxconf_regs
  237. * Description: Setting up the configuration Mux registers specific to the
  238. * hardware. Many pins need to be moved from protect to primary
  239. * mode.
  240. */
  241. void set_muxconf_regs(void)
  242. {
  243. MUX_MT_VENTOUX();
  244. }
  245. /*
  246. * Initializes on-chip ethernet controllers.
  247. * to override, implement board_eth_init()
  248. */
  249. int board_eth_init(bd_t *bis)
  250. {
  251. davinci_emac_initialize();
  252. return 0;
  253. }
  254. #if defined(CONFIG_OMAP_HSMMC) && \
  255. !defined(CONFIG_SPL_BUILD)
  256. int board_mmc_init(bd_t *bis)
  257. {
  258. return omap_mmc_init(0, 0, 0, -1, -1);
  259. }
  260. #endif
  261. #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
  262. int board_video_init(void)
  263. {
  264. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  265. struct panel_config *panel = &lcd_cfg[0];
  266. char *s;
  267. u32 index = 0;
  268. void *fb;
  269. fb = (void *)0x88000000;
  270. s = getenv("panel");
  271. if (s) {
  272. index = simple_strtoul(s, NULL, 10);
  273. if (index < ARRAY_SIZE(lcd_cfg))
  274. panel = &lcd_cfg[index];
  275. else
  276. return 0;
  277. }
  278. panel->frame_buffer = fb;
  279. printf("Panel: %dx%d\n", panel_resolution[index].xres,
  280. panel_resolution[index].yres);
  281. panel->lcd_size = (panel_resolution[index].yres - 1) << 16 |
  282. (panel_resolution[index].xres - 1);
  283. gpio_request(LCD_PWR, "LCD Power");
  284. gpio_request(LCD_PON_PIN, "LCD Pon");
  285. gpio_direction_output(LCD_PWR, 0);
  286. gpio_direction_output(LCD_PON_PIN, 1);
  287. setbits_le32(&prcm_base->fclken_dss, FCK_DSS_ON);
  288. setbits_le32(&prcm_base->iclken_dss, ICK_DSS_ON);
  289. omap3_dss_panel_config(panel);
  290. omap3_dss_enable();
  291. return 0;
  292. }
  293. #endif