board.c 9.8 KB

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