board.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * Board functions for TI AM335X based pxm2 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. * Board functions for TI AM335X based boards
  10. *
  11. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <errno.h>
  17. #include <spl.h>
  18. #include <asm/arch/cpu.h>
  19. #include <asm/arch/hardware.h>
  20. #include <asm/arch/omap.h>
  21. #include <asm/arch/ddr_defs.h>
  22. #include <asm/arch/clock.h>
  23. #include <asm/arch/gpio.h>
  24. #include <asm/arch/mmc_host_def.h>
  25. #include <asm/arch/sys_proto.h>
  26. #include "../../../drivers/video/da8xx-fb.h"
  27. #include <asm/io.h>
  28. #include <asm/emif.h>
  29. #include <asm/gpio.h>
  30. #include <i2c.h>
  31. #include <miiphy.h>
  32. #include <cpsw.h>
  33. #include <watchdog.h>
  34. #include "board.h"
  35. #include "../common/factoryset.h"
  36. #include "pmic.h"
  37. #include <nand.h>
  38. #include <bmp_layout.h>
  39. DECLARE_GLOBAL_DATA_PTR;
  40. #ifdef CONFIG_SPL_BUILD
  41. static void board_init_ddr(void)
  42. {
  43. struct emif_regs pxm2_ddr3_emif_reg_data = {
  44. .sdram_config = 0x41805332,
  45. .sdram_tim1 = 0x666b3c9,
  46. .sdram_tim2 = 0x243631ca,
  47. .sdram_tim3 = 0x33f,
  48. .emif_ddr_phy_ctlr_1 = 0x100005,
  49. .zq_config = 0,
  50. .ref_ctrl = 0x81a,
  51. };
  52. struct ddr_data pxm2_ddr3_data = {
  53. .datardsratio0 = 0x81204812,
  54. .datawdsratio0 = 0,
  55. .datafwsratio0 = 0x8020080,
  56. .datawrsratio0 = 0x4010040,
  57. };
  58. struct cmd_control pxm2_ddr3_cmd_ctrl_data = {
  59. .cmd0csratio = 0x80,
  60. .cmd0iclkout = 0,
  61. .cmd1csratio = 0x80,
  62. .cmd1iclkout = 0,
  63. .cmd2csratio = 0x80,
  64. .cmd2iclkout = 0,
  65. };
  66. const struct ctrl_ioregs ioregs = {
  67. .cm0ioctl = DDR_IOCTRL_VAL,
  68. .cm1ioctl = DDR_IOCTRL_VAL,
  69. .cm2ioctl = DDR_IOCTRL_VAL,
  70. .dt0ioctl = DDR_IOCTRL_VAL,
  71. .dt1ioctl = DDR_IOCTRL_VAL,
  72. };
  73. config_ddr(DDR_PLL_FREQ, &ioregs, &pxm2_ddr3_data,
  74. &pxm2_ddr3_cmd_ctrl_data, &pxm2_ddr3_emif_reg_data, 0);
  75. }
  76. /*
  77. * voltage switching for MPU frequency switching.
  78. * @module = mpu - 0, core - 1
  79. * @vddx_op_vol_sel = vdd voltage to set
  80. */
  81. #define MPU 0
  82. #define CORE 1
  83. int voltage_update(unsigned int module, unsigned char vddx_op_vol_sel)
  84. {
  85. uchar buf[4];
  86. unsigned int reg_offset;
  87. if (module == MPU)
  88. reg_offset = PMIC_VDD1_OP_REG;
  89. else
  90. reg_offset = PMIC_VDD2_OP_REG;
  91. /* Select VDDx OP */
  92. if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
  93. return 1;
  94. buf[0] &= ~PMIC_OP_REG_CMD_MASK;
  95. if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
  96. return 1;
  97. /* Configure VDDx OP Voltage */
  98. if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
  99. return 1;
  100. buf[0] &= ~PMIC_OP_REG_SEL_MASK;
  101. buf[0] |= vddx_op_vol_sel;
  102. if (i2c_write(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
  103. return 1;
  104. if (i2c_read(PMIC_CTRL_I2C_ADDR, reg_offset, 1, buf, 1))
  105. return 1;
  106. if ((buf[0] & PMIC_OP_REG_SEL_MASK) != vddx_op_vol_sel)
  107. return 1;
  108. return 0;
  109. }
  110. #define OSC (V_OSCK/1000000)
  111. const struct dpll_params dpll_mpu_pxm2 = {
  112. 720, OSC-1, 1, -1, -1, -1, -1};
  113. void spl_siemens_board_init(void)
  114. {
  115. uchar buf[4];
  116. /*
  117. * pxm2 PMIC code. All boards currently want an MPU voltage
  118. * of 1.2625V and CORE voltage of 1.1375V to operate at
  119. * 720MHz.
  120. */
  121. if (i2c_probe(PMIC_CTRL_I2C_ADDR))
  122. return;
  123. /* VDD1/2 voltage selection register access by control i/f */
  124. if (i2c_read(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
  125. return;
  126. buf[0] |= PMIC_DEVCTRL_REG_SR_CTL_I2C_SEL_CTL_I2C;
  127. if (i2c_write(PMIC_CTRL_I2C_ADDR, PMIC_DEVCTRL_REG, 1, buf, 1))
  128. return;
  129. /* Frequency switching for OPP 120 */
  130. if (voltage_update(MPU, PMIC_OP_REG_SEL_1_2_6) ||
  131. voltage_update(CORE, PMIC_OP_REG_SEL_1_1_3)) {
  132. printf("voltage update failed\n");
  133. }
  134. }
  135. #endif /* if def CONFIG_SPL_BUILD */
  136. int read_eeprom(void)
  137. {
  138. /* nothing ToDo here for this board */
  139. return 0;
  140. }
  141. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  142. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  143. static void cpsw_control(int enabled)
  144. {
  145. /* VTP can be added here */
  146. return;
  147. }
  148. static struct cpsw_slave_data cpsw_slaves[] = {
  149. {
  150. .slave_reg_ofs = 0x208,
  151. .sliver_reg_ofs = 0xd80,
  152. .phy_addr = 0,
  153. .phy_if = PHY_INTERFACE_MODE_RMII,
  154. },
  155. {
  156. .slave_reg_ofs = 0x308,
  157. .sliver_reg_ofs = 0xdc0,
  158. .phy_addr = 1,
  159. .phy_if = PHY_INTERFACE_MODE_RMII,
  160. },
  161. };
  162. static struct cpsw_platform_data cpsw_data = {
  163. .mdio_base = CPSW_MDIO_BASE,
  164. .cpsw_base = CPSW_BASE,
  165. .mdio_div = 0xff,
  166. .channels = 4,
  167. .cpdma_reg_ofs = 0x800,
  168. .slaves = 1,
  169. .slave_data = cpsw_slaves,
  170. .ale_reg_ofs = 0xd00,
  171. .ale_entries = 1024,
  172. .host_port_reg_ofs = 0x108,
  173. .hw_stats_reg_ofs = 0x900,
  174. .bd_ram_ofs = 0x2000,
  175. .mac_control = (1 << 5),
  176. .control = cpsw_control,
  177. .host_port_num = 0,
  178. .version = CPSW_CTRL_VERSION_2,
  179. };
  180. #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */
  181. #if defined(CONFIG_DRIVER_TI_CPSW) || \
  182. (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET))
  183. int board_eth_init(bd_t *bis)
  184. {
  185. int n = 0;
  186. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  187. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  188. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  189. #ifdef CONFIG_FACTORYSET
  190. int rv;
  191. if (!is_valid_ethaddr(factory_dat.mac))
  192. printf("Error: no valid mac address\n");
  193. else
  194. eth_setenv_enetaddr("ethaddr", factory_dat.mac);
  195. #endif /* #ifdef CONFIG_FACTORYSET */
  196. /* Set rgmii mode and enable rmii clock to be sourced from chip */
  197. writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
  198. rv = cpsw_register(&cpsw_data);
  199. if (rv < 0)
  200. printf("Error %d registering CPSW switch\n", rv);
  201. else
  202. n += rv;
  203. #endif
  204. return n;
  205. }
  206. #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */
  207. #if defined(CONFIG_VIDEO) && !defined(CONFIG_SPL_BUILD)
  208. static struct da8xx_panel lcd_panels[] = {
  209. /* AUO G156XW01 V1 */
  210. [0] = {
  211. .name = "AUO_G156XW01_V1",
  212. .width = 1376,
  213. .height = 768,
  214. .hfp = 14,
  215. .hbp = 64,
  216. .hsw = 56,
  217. .vfp = 1,
  218. .vbp = 28,
  219. .vsw = 3,
  220. .pxl_clk = 60000000,
  221. .invert_pxl_clk = 0,
  222. },
  223. /* AUO B101EVN06 V0 */
  224. [1] = {
  225. .name = "AUO_B101EVN06_V0",
  226. .width = 1280,
  227. .height = 800,
  228. .hfp = 52,
  229. .hbp = 84,
  230. .hsw = 36,
  231. .vfp = 3,
  232. .vbp = 14,
  233. .vsw = 6,
  234. .pxl_clk = 60000000,
  235. .invert_pxl_clk = 0,
  236. },
  237. /*
  238. * Settings from factoryset
  239. * stored in EEPROM
  240. */
  241. [2] = {
  242. .name = "factoryset",
  243. .width = 0,
  244. .height = 0,
  245. .hfp = 0,
  246. .hbp = 0,
  247. .hsw = 0,
  248. .vfp = 0,
  249. .vbp = 0,
  250. .vsw = 0,
  251. .pxl_clk = 60000000,
  252. .invert_pxl_clk = 0,
  253. },
  254. };
  255. static const struct display_panel disp_panel = {
  256. WVGA,
  257. 32,
  258. 16,
  259. COLOR_ACTIVE,
  260. };
  261. static const struct lcd_ctrl_config lcd_cfg = {
  262. &disp_panel,
  263. .ac_bias = 255,
  264. .ac_bias_intrpt = 0,
  265. .dma_burst_sz = 16,
  266. .bpp = 32,
  267. .fdd = 0x80,
  268. .tft_alt_mode = 0,
  269. .stn_565_mode = 0,
  270. .mono_8bit_mode = 0,
  271. .invert_line_clock = 1,
  272. .invert_frm_clock = 1,
  273. .sync_edge = 0,
  274. .sync_ctrl = 1,
  275. .raster_order = 0,
  276. };
  277. static int set_gpio(int gpio, int state)
  278. {
  279. gpio_request(gpio, "temp");
  280. gpio_direction_output(gpio, state);
  281. gpio_set_value(gpio, state);
  282. gpio_free(gpio);
  283. return 0;
  284. }
  285. static int enable_backlight(void)
  286. {
  287. set_gpio(BOARD_LCD_POWER, 1);
  288. set_gpio(BOARD_BACK_LIGHT, 1);
  289. set_gpio(BOARD_TOUCH_POWER, 1);
  290. return 0;
  291. }
  292. static int enable_pwm(void)
  293. {
  294. struct pwmss_regs *pwmss = (struct pwmss_regs *)PWMSS0_BASE;
  295. struct pwmss_ecap_regs *ecap;
  296. int ticks = PWM_TICKS;
  297. int duty = PWM_DUTY;
  298. ecap = (struct pwmss_ecap_regs *)AM33XX_ECAP0_BASE;
  299. /* enable clock */
  300. setbits_le32(&pwmss->clkconfig, ECAP_CLK_EN);
  301. /* TimeStam Counter register */
  302. writel(0xdb9, &ecap->tsctr);
  303. /* config period */
  304. writel(ticks - 1, &ecap->cap3);
  305. writel(ticks - 1, &ecap->cap1);
  306. setbits_le16(&ecap->ecctl2,
  307. (ECTRL2_MDSL_ECAP | ECTRL2_SYNCOSEL_MASK | 0xd0));
  308. /* config duty */
  309. writel(duty, &ecap->cap2);
  310. writel(duty, &ecap->cap4);
  311. /* start */
  312. setbits_le16(&ecap->ecctl2, ECTRL2_CTRSTP_FREERUN);
  313. return 0;
  314. }
  315. static struct dpll_regs dpll_lcd_regs = {
  316. .cm_clkmode_dpll = CM_WKUP + 0x98,
  317. .cm_idlest_dpll = CM_WKUP + 0x48,
  318. .cm_clksel_dpll = CM_WKUP + 0x54,
  319. };
  320. /* no console on this board */
  321. int board_cfb_skip(void)
  322. {
  323. return 1;
  324. }
  325. #define PLL_GET_M(v) ((v >> 8) & 0x7ff)
  326. #define PLL_GET_N(v) (v & 0x7f)
  327. static int get_clk(struct dpll_regs *dpll_regs)
  328. {
  329. unsigned int val;
  330. unsigned int m, n;
  331. int f = 0;
  332. val = readl(dpll_regs->cm_clksel_dpll);
  333. m = PLL_GET_M(val);
  334. n = PLL_GET_N(val);
  335. f = (m * V_OSCK) / n;
  336. return f;
  337. };
  338. int clk_get(int clk)
  339. {
  340. return get_clk(&dpll_lcd_regs);
  341. };
  342. static int conf_disp_pll(int m, int n)
  343. {
  344. struct cm_perpll *cmper = (struct cm_perpll *)CM_PER;
  345. struct cm_dpll *cmdpll = (struct cm_dpll *)CM_DPLL;
  346. struct dpll_params dpll_lcd = {m, n, -1, -1, -1, -1, -1};
  347. u32 *const clk_domains[] = {
  348. &cmper->lcdclkctrl,
  349. 0
  350. };
  351. u32 *const clk_modules_explicit_en[] = {
  352. &cmper->lcdclkctrl,
  353. &cmper->lcdcclkstctrl,
  354. &cmper->epwmss0clkctrl,
  355. 0
  356. };
  357. do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
  358. writel(0x0, &cmdpll->clklcdcpixelclk);
  359. do_setup_dpll(&dpll_lcd_regs, &dpll_lcd);
  360. return 0;
  361. }
  362. static int board_video_init(void)
  363. {
  364. conf_disp_pll(24, 1);
  365. if (factory_dat.pxm50)
  366. da8xx_video_init(&lcd_panels[0], &lcd_cfg, lcd_cfg.bpp);
  367. else
  368. da8xx_video_init(&lcd_panels[1], &lcd_cfg, lcd_cfg.bpp);
  369. enable_pwm();
  370. enable_backlight();
  371. return 0;
  372. }
  373. #endif
  374. #ifdef CONFIG_BOARD_LATE_INIT
  375. int board_late_init(void)
  376. {
  377. int ret;
  378. omap_nand_switch_ecc(1, 8);
  379. #ifdef CONFIG_FACTORYSET
  380. if (factory_dat.asn[0] != 0) {
  381. char tmp[2 * MAX_STRING_LENGTH + 2];
  382. if (strncmp((const char *)factory_dat.asn, "PXM50", 5) == 0)
  383. factory_dat.pxm50 = 1;
  384. else
  385. factory_dat.pxm50 = 0;
  386. sprintf(tmp, "%s_%s", factory_dat.asn,
  387. factory_dat.comp_version);
  388. ret = setenv("boardid", tmp);
  389. if (ret)
  390. printf("error setting board id\n");
  391. } else {
  392. factory_dat.pxm50 = 1;
  393. ret = setenv("boardid", "PXM50_1.0");
  394. if (ret)
  395. printf("error setting board id\n");
  396. }
  397. debug("PXM50: %d\n", factory_dat.pxm50);
  398. #endif
  399. return 0;
  400. }
  401. #endif
  402. #include "../common/board.c"