mt_ventoux.c 7.2 KB

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