mt_ventoux.c 7.2 KB

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