board.c 10 KB

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