mt_ventoux.c 7.1 KB

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