board.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * Board functions for TI AM335X based rut board
  3. * (C) Copyright 2013 Siemens Schweiz AG
  4. * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de.
  5. *
  6. * Based on:
  7. * u-boot:/board/ti/am335x/board.c
  8. *
  9. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <errno.h>
  15. #include <spi.h>
  16. #include <spl.h>
  17. #include <asm/arch/cpu.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/omap.h>
  20. #include <asm/arch/ddr_defs.h>
  21. #include <asm/arch/clock.h>
  22. #include <asm/arch/gpio.h>
  23. #include <asm/arch/mmc_host_def.h>
  24. #include <asm/arch/sys_proto.h>
  25. #include <asm/io.h>
  26. #include <asm/emif.h>
  27. #include <asm/gpio.h>
  28. #include <i2c.h>
  29. #include <miiphy.h>
  30. #include <cpsw.h>
  31. #include <video.h>
  32. #include <watchdog.h>
  33. #include "board.h"
  34. #include "../common/factoryset.h"
  35. #include "../../../drivers/video/da8xx-fb.h"
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /*
  38. * Read header information from EEPROM into global structure.
  39. */
  40. static int read_eeprom(void)
  41. {
  42. return 0;
  43. }
  44. #ifdef CONFIG_SPL_BUILD
  45. static void board_init_ddr(void)
  46. {
  47. struct emif_regs rut_ddr3_emif_reg_data = {
  48. .sdram_config = 0x61C04AB2,
  49. .sdram_tim1 = 0x0888A39B,
  50. .sdram_tim2 = 0x26337FDA,
  51. .sdram_tim3 = 0x501F830F,
  52. .emif_ddr_phy_ctlr_1 = 0x6,
  53. .zq_config = 0x50074BE4,
  54. .ref_ctrl = 0x93B,
  55. };
  56. struct ddr_data rut_ddr3_data = {
  57. .datardsratio0 = 0x3b,
  58. .datawdsratio0 = 0x85,
  59. .datafwsratio0 = 0x100,
  60. .datawrsratio0 = 0xc1,
  61. };
  62. struct cmd_control rut_ddr3_cmd_ctrl_data = {
  63. .cmd0csratio = 0x40,
  64. .cmd0iclkout = 1,
  65. .cmd1csratio = 0x40,
  66. .cmd1iclkout = 1,
  67. .cmd2csratio = 0x40,
  68. .cmd2iclkout = 1,
  69. };
  70. config_ddr(DDR_PLL_FREQ, RUT_IOCTRL_VAL, &rut_ddr3_data,
  71. &rut_ddr3_cmd_ctrl_data, &rut_ddr3_emif_reg_data, 0);
  72. }
  73. static int request_and_pulse_reset(int gpio, const char *name)
  74. {
  75. int ret;
  76. const int delay_us = 2000; /* 2ms */
  77. ret = gpio_request(gpio, name);
  78. if (ret < 0) {
  79. printf("%s: Unable to request %s\n", __func__, name);
  80. goto err;
  81. }
  82. ret = gpio_direction_output(gpio, 0);
  83. if (ret < 0) {
  84. printf("%s: Unable to set %s as output\n", __func__, name);
  85. goto err_free_gpio;
  86. }
  87. udelay(delay_us);
  88. gpio_set_value(gpio, 1);
  89. return 0;
  90. err_free_gpio:
  91. gpio_free(gpio);
  92. err:
  93. return ret;
  94. }
  95. #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
  96. #define ETH_PHY_RESET_GPIO GPIO_TO_PIN(2, 18)
  97. #define MAXTOUCH_RESET_GPIO GPIO_TO_PIN(3, 18)
  98. #define DISPLAY_RESET_GPIO GPIO_TO_PIN(3, 19)
  99. #define REQUEST_AND_PULSE_RESET(N) \
  100. request_and_pulse_reset(N, #N);
  101. static void spl_siemens_board_init(void)
  102. {
  103. REQUEST_AND_PULSE_RESET(ETH_PHY_RESET_GPIO);
  104. REQUEST_AND_PULSE_RESET(MAXTOUCH_RESET_GPIO);
  105. REQUEST_AND_PULSE_RESET(DISPLAY_RESET_GPIO);
  106. }
  107. #endif /* if def CONFIG_SPL_BUILD */
  108. #if defined(CONFIG_DRIVER_TI_CPSW)
  109. static void cpsw_control(int enabled)
  110. {
  111. /* VTP can be added here */
  112. return;
  113. }
  114. static struct cpsw_slave_data cpsw_slaves[] = {
  115. {
  116. .slave_reg_ofs = 0x208,
  117. .sliver_reg_ofs = 0xd80,
  118. .phy_id = 1,
  119. .phy_if = PHY_INTERFACE_MODE_RMII,
  120. },
  121. {
  122. .slave_reg_ofs = 0x308,
  123. .sliver_reg_ofs = 0xdc0,
  124. .phy_id = 0,
  125. .phy_if = PHY_INTERFACE_MODE_RMII,
  126. },
  127. };
  128. static struct cpsw_platform_data cpsw_data = {
  129. .mdio_base = CPSW_MDIO_BASE,
  130. .cpsw_base = CPSW_BASE,
  131. .mdio_div = 0xff,
  132. .channels = 8,
  133. .cpdma_reg_ofs = 0x800,
  134. .slaves = 1,
  135. .slave_data = cpsw_slaves,
  136. .ale_reg_ofs = 0xd00,
  137. .ale_entries = 1024,
  138. .host_port_reg_ofs = 0x108,
  139. .hw_stats_reg_ofs = 0x900,
  140. .bd_ram_ofs = 0x2000,
  141. .mac_control = (1 << 5),
  142. .control = cpsw_control,
  143. .host_port_num = 0,
  144. .version = CPSW_CTRL_VERSION_2,
  145. };
  146. #if defined(CONFIG_DRIVER_TI_CPSW) || \
  147. (defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET))
  148. int board_eth_init(bd_t *bis)
  149. {
  150. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  151. int n = 0;
  152. int rv;
  153. #ifndef CONFIG_SPL_BUILD
  154. factoryset_setenv();
  155. #endif
  156. /* Set rgmii mode and enable rmii clock to be sourced from chip */
  157. writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel);
  158. rv = cpsw_register(&cpsw_data);
  159. if (rv < 0)
  160. printf("Error %d registering CPSW switch\n", rv);
  161. else
  162. n += rv;
  163. return n;
  164. }
  165. #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
  166. #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
  167. #if defined(CONFIG_HW_WATCHDOG)
  168. static bool hw_watchdog_init_done;
  169. static int hw_watchdog_trigger_level;
  170. void hw_watchdog_reset(void)
  171. {
  172. if (!hw_watchdog_init_done)
  173. return;
  174. hw_watchdog_trigger_level = hw_watchdog_trigger_level ? 0 : 1;
  175. gpio_set_value(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
  176. }
  177. void hw_watchdog_init(void)
  178. {
  179. gpio_request(WATCHDOG_TRIGGER_GPIO, "watchdog_trigger");
  180. gpio_direction_output(WATCHDOG_TRIGGER_GPIO, hw_watchdog_trigger_level);
  181. hw_watchdog_reset();
  182. hw_watchdog_init_done = 1;
  183. }
  184. #endif /* defined(CONFIG_HW_WATCHDOG) */
  185. #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
  186. static struct da8xx_panel lcd_panels[] = {
  187. /* FORMIKE, 4.3", 480x800, KWH043MC17-F01 */
  188. [0] = {
  189. .name = "KWH043MC17-F01",
  190. .width = 480,
  191. .height = 800,
  192. .hfp = 50, /* no spec, "don't care" values */
  193. .hbp = 50,
  194. .hsw = 50,
  195. .vfp = 50,
  196. .vbp = 50,
  197. .vsw = 50,
  198. .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
  199. .invert_pxl_clk = 1,
  200. },
  201. /* FORMIKE, 4.3", 480x800, KWH043ST20-F01 */
  202. [1] = {
  203. .name = "KWH043ST20-F01",
  204. .width = 480,
  205. .height = 800,
  206. .hfp = 50, /* no spec, "don't care" values */
  207. .hbp = 50,
  208. .hsw = 50,
  209. .vfp = 50,
  210. .vbp = 50,
  211. .vsw = 50,
  212. .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
  213. .invert_pxl_clk = 1,
  214. },
  215. /* Multi-Inno, 4.3", 480x800, MI0430VT-1 */
  216. [2] = {
  217. .name = "MI0430VT-1",
  218. .width = 480,
  219. .height = 800,
  220. .hfp = 50, /* no spec, "don't care" values */
  221. .hbp = 50,
  222. .hsw = 50,
  223. .vfp = 50,
  224. .vbp = 50,
  225. .vsw = 50,
  226. .pxl_clk = 35910000, /* tCYCD=20ns, max 50MHz, 60fps */
  227. .invert_pxl_clk = 1,
  228. },
  229. };
  230. static const struct display_panel disp_panels[] = {
  231. [0] = {
  232. WVGA,
  233. 16, /* RGB 888 */
  234. 16,
  235. COLOR_ACTIVE,
  236. },
  237. [1] = {
  238. WVGA,
  239. 16, /* RGB 888 */
  240. 16,
  241. COLOR_ACTIVE,
  242. },
  243. [2] = {
  244. WVGA,
  245. 24, /* RGB 888 */
  246. 16,
  247. COLOR_ACTIVE,
  248. },
  249. };
  250. static const struct lcd_ctrl_config lcd_cfgs[] = {
  251. [0] = {
  252. &disp_panels[0],
  253. .ac_bias = 255,
  254. .ac_bias_intrpt = 0,
  255. .dma_burst_sz = 16,
  256. .bpp = 16,
  257. .fdd = 0x80,
  258. .tft_alt_mode = 0,
  259. .stn_565_mode = 0,
  260. .mono_8bit_mode = 0,
  261. .invert_line_clock = 1,
  262. .invert_frm_clock = 1,
  263. .sync_edge = 0,
  264. .sync_ctrl = 1,
  265. .raster_order = 0,
  266. },
  267. [1] = {
  268. &disp_panels[1],
  269. .ac_bias = 255,
  270. .ac_bias_intrpt = 0,
  271. .dma_burst_sz = 16,
  272. .bpp = 16,
  273. .fdd = 0x80,
  274. .tft_alt_mode = 0,
  275. .stn_565_mode = 0,
  276. .mono_8bit_mode = 0,
  277. .invert_line_clock = 1,
  278. .invert_frm_clock = 1,
  279. .sync_edge = 0,
  280. .sync_ctrl = 1,
  281. .raster_order = 0,
  282. },
  283. [2] = {
  284. &disp_panels[2],
  285. .ac_bias = 255,
  286. .ac_bias_intrpt = 0,
  287. .dma_burst_sz = 16,
  288. .bpp = 24,
  289. .fdd = 0x80,
  290. .tft_alt_mode = 0,
  291. .stn_565_mode = 0,
  292. .mono_8bit_mode = 0,
  293. .invert_line_clock = 1,
  294. .invert_frm_clock = 1,
  295. .sync_edge = 0,
  296. .sync_ctrl = 1,
  297. .raster_order = 0,
  298. },
  299. };
  300. /* no console on this board */
  301. int board_cfb_skip(void)
  302. {
  303. return 1;
  304. }
  305. #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
  306. #define PLL_GET_N(v) (v & 0x7f)
  307. static struct dpll_regs dpll_lcd_regs = {
  308. .cm_clkmode_dpll = CM_WKUP + 0x98,
  309. .cm_idlest_dpll = CM_WKUP + 0x48,
  310. .cm_clksel_dpll = CM_WKUP + 0x54,
  311. };
  312. static int get_clk(struct dpll_regs *dpll_regs)
  313. {
  314. unsigned int val;
  315. unsigned int m, n;
  316. int f = 0;
  317. val = readl(dpll_regs->cm_clksel_dpll);
  318. m = PLL_GET_M(val);
  319. n = PLL_GET_N(val);
  320. f = (m * V_OSCK) / n;
  321. return f;
  322. };
  323. int clk_get(int clk)
  324. {
  325. return get_clk(&dpll_lcd_regs);
  326. };
  327. static int conf_disp_pll(int m, int n)
  328. {
  329. struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
  330. struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
  331. #if defined(DISPL_PLL_SPREAD_SPECTRUM)
  332. struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP;
  333. #endif
  334. u32 *const clk_domains[] = {
  335. &cmper->lcdclkctrl,
  336. 0
  337. };
  338. u32 *const clk_modules_explicit_en[] = {
  339. &cmper->lcdclkctrl,
  340. &cmper->lcdcclkstctrl,
  341. &cmper->spi1clkctrl,
  342. 0
  343. };
  344. do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
  345. do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
  346. #if defined(DISPL_PLL_SPREAD_SPECTRUM)
  347. writel(0x64, &cmwkup->resv6[3]); /* 0x50 */
  348. writel(0x800, &cmwkup->resv6[2]); /* 0x4c */
  349. writel(readl(&cmwkup->clkmoddplldisp) | (1 << 12),
  350. &cmwkup->clkmoddplldisp); /* 0x98 */
  351. #endif
  352. return 0;
  353. }
  354. static int set_gpio(int gpio, int state)
  355. {
  356. gpio_request(gpio, "temp");
  357. gpio_direction_output(gpio, state);
  358. gpio_set_value(gpio, state);
  359. gpio_free(gpio);
  360. return 0;
  361. }
  362. static int enable_lcd(void)
  363. {
  364. unsigned char buf[1];
  365. set_gpio(BOARD_LCD_RESET, 0);
  366. mdelay(1);
  367. set_gpio(BOARD_LCD_RESET, 1);
  368. mdelay(1);
  369. /* spi lcd init */
  370. kwh043st20_f01_spi_startup(1, 0, 5000000, SPI_MODE_0);
  371. /* backlight on */
  372. buf[0] = 0xf;
  373. i2c_write(0x24, 0x7, 1, buf, 1);
  374. buf[0] = 0x3f;
  375. i2c_write(0x24, 0x8, 1, buf, 1);
  376. return 0;
  377. }
  378. int arch_early_init_r(void)
  379. {
  380. enable_lcd();
  381. return 0;
  382. }
  383. static int board_video_init(void)
  384. {
  385. int i;
  386. int anzdisp = ARRAY_SIZE(lcd_panels);
  387. int display = 1;
  388. for (i = 0; i < anzdisp; i++) {
  389. if (strncmp((const char *)factory_dat.disp_name,
  390. lcd_panels[i].name,
  391. strlen((const char *)factory_dat.disp_name)) == 0) {
  392. printf("DISPLAY: %s\n", factory_dat.disp_name);
  393. break;
  394. }
  395. }
  396. if (i == anzdisp) {
  397. i = 1;
  398. printf("%s: %s not found, using default %s\n", __func__,
  399. factory_dat.disp_name, lcd_panels[i].name);
  400. }
  401. conf_disp_pll(24, 1);
  402. da8xx_video_init(&lcd_panels[display], &lcd_cfgs[display],
  403. lcd_cfgs[display].bpp);
  404. return 0;
  405. }
  406. #endif /* ifdef CONFIG_VIDEO */
  407. #include "../common/board.c"