trats.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011 Samsung Electronics
  4. * Heungjun Kim <riverful.kim@samsung.com>
  5. * Kyungmin Park <kyungmin.park@samsung.com>
  6. * Donghwa Lee <dh09.lee@samsung.com>
  7. */
  8. #include <common.h>
  9. #include <lcd.h>
  10. #include <asm/io.h>
  11. #include <asm/gpio.h>
  12. #include <asm/arch/cpu.h>
  13. #include <asm/arch/pinmux.h>
  14. #include <asm/arch/clock.h>
  15. #include <asm/arch/mipi_dsim.h>
  16. #include <asm/arch/watchdog.h>
  17. #include <asm/arch/power.h>
  18. #include <power/pmic.h>
  19. #include <usb/dwc2_udc.h>
  20. #include <power/max8997_pmic.h>
  21. #include <power/max8997_muic.h>
  22. #include <power/battery.h>
  23. #include <power/max17042_fg.h>
  24. #include <power/pmic.h>
  25. #include <libtizen.h>
  26. #include <usb.h>
  27. #include <usb_mass_storage.h>
  28. #include "setup.h"
  29. unsigned int board_rev;
  30. #ifdef CONFIG_REVISION_TAG
  31. u32 get_board_rev(void)
  32. {
  33. return board_rev;
  34. }
  35. #endif
  36. static void check_hw_revision(void);
  37. struct dwc2_plat_otg_data s5pc210_otg_data;
  38. int exynos_init(void)
  39. {
  40. check_hw_revision();
  41. printf("HW Revision:\t0x%x\n", board_rev);
  42. return 0;
  43. }
  44. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  45. static void trats_low_power_mode(void)
  46. {
  47. struct exynos4_clock *clk =
  48. (struct exynos4_clock *)samsung_get_base_clock();
  49. struct exynos4_power *pwr =
  50. (struct exynos4_power *)samsung_get_base_power();
  51. /* Power down CORE1 */
  52. /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
  53. writel(0x0, &pwr->arm_core1_configuration);
  54. /* Change the APLL frequency */
  55. /* ENABLE (1 enable) | LOCKED (1 locked) */
  56. /* [31] | [29] */
  57. /* FSEL | MDIV | PDIV | SDIV */
  58. /* [27] | [25:16] | [13:8] | [2:0] */
  59. writel(0xa0c80604, &clk->apll_con0);
  60. /* Change CPU0 clock divider */
  61. /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */
  62. /* [30:28] | [26:24] | [22:20] | [18:16] */
  63. /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */
  64. /* [14:12] | [10:8] | [6:4] | [2:0] */
  65. writel(0x00000100, &clk->div_cpu0);
  66. /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
  67. while (readl(&clk->div_stat_cpu0) & 0x1111111)
  68. continue;
  69. /* Change clock divider ratio for DMC */
  70. /* DMCP_RATIO | DMCD_RATIO */
  71. /* [22:20] | [18:16] */
  72. /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */
  73. /* [14:12] | [10:8] | [6:4] | [2:0] */
  74. writel(0x13113117, &clk->div_dmc0);
  75. /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
  76. while (readl(&clk->div_stat_dmc0) & 0x11111111)
  77. continue;
  78. /* Turn off unnecessary power domains */
  79. writel(0x0, &pwr->xxti_configuration); /* XXTI */
  80. writel(0x0, &pwr->cam_configuration); /* CAM */
  81. writel(0x0, &pwr->tv_configuration); /* TV */
  82. writel(0x0, &pwr->mfc_configuration); /* MFC */
  83. writel(0x0, &pwr->g3d_configuration); /* G3D */
  84. writel(0x0, &pwr->gps_configuration); /* GPS */
  85. writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */
  86. /* Turn off unnecessary clocks */
  87. writel(0x0, &clk->gate_ip_cam); /* CAM */
  88. writel(0x0, &clk->gate_ip_tv); /* TV */
  89. writel(0x0, &clk->gate_ip_mfc); /* MFC */
  90. writel(0x0, &clk->gate_ip_g3d); /* G3D */
  91. writel(0x0, &clk->gate_ip_image); /* IMAGE */
  92. writel(0x0, &clk->gate_ip_gps); /* GPS */
  93. }
  94. #endif
  95. int exynos_power_init(void)
  96. {
  97. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  98. int chrg, ret;
  99. struct power_battery *pb;
  100. struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
  101. /*
  102. * For PMIC/MUIC the I2C bus is named as I2C5, but it is connected
  103. * to logical I2C adapter 0
  104. *
  105. * The FUEL_GAUGE is marked as I2C9 on the schematic, but connected
  106. * to logical I2C adapter 1
  107. */
  108. ret = power_fg_init(I2C_9);
  109. ret |= power_muic_init(I2C_5);
  110. ret |= power_bat_init(0);
  111. if (ret)
  112. return ret;
  113. p_fg = pmic_get("MAX17042_FG");
  114. if (!p_fg) {
  115. puts("MAX17042_FG: Not found\n");
  116. return -ENODEV;
  117. }
  118. p_chrg = pmic_get("MAX8997_PMIC");
  119. if (!p_chrg) {
  120. puts("MAX8997_PMIC: Not found\n");
  121. return -ENODEV;
  122. }
  123. p_muic = pmic_get("MAX8997_MUIC");
  124. if (!p_muic) {
  125. puts("MAX8997_MUIC: Not found\n");
  126. return -ENODEV;
  127. }
  128. p_bat = pmic_get("BAT_TRATS");
  129. if (!p_bat) {
  130. puts("BAT_TRATS: Not found\n");
  131. return -ENODEV;
  132. }
  133. p_fg->parent = p_bat;
  134. p_chrg->parent = p_bat;
  135. p_muic->parent = p_bat;
  136. p_bat->low_power_mode = trats_low_power_mode;
  137. p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
  138. pb = p_bat->pbat;
  139. chrg = p_muic->chrg->chrg_type(p_muic);
  140. debug("CHARGER TYPE: %d\n", chrg);
  141. if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
  142. puts("No battery detected\n");
  143. return 0;
  144. }
  145. p_fg->fg->fg_battery_check(p_fg, p_bat);
  146. if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
  147. puts("CHARGE Battery !\n");
  148. #endif
  149. return 0;
  150. }
  151. static unsigned int get_hw_revision(void)
  152. {
  153. int hwrev = 0;
  154. char str[10];
  155. int i;
  156. /* hw_rev[3:0] == GPE1[3:0] */
  157. for (i = 0; i < 4; i++) {
  158. int pin = i + EXYNOS4_GPIO_E10;
  159. sprintf(str, "hw_rev%d", i);
  160. gpio_request(pin, str);
  161. gpio_cfg_pin(pin, S5P_GPIO_INPUT);
  162. gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
  163. }
  164. udelay(1);
  165. for (i = 0; i < 4; i++)
  166. hwrev |= (gpio_get_value(EXYNOS4_GPIO_E10 + i) << i);
  167. debug("hwrev 0x%x\n", hwrev);
  168. return hwrev;
  169. }
  170. static void check_hw_revision(void)
  171. {
  172. int hwrev;
  173. hwrev = get_hw_revision();
  174. board_rev |= hwrev;
  175. }
  176. #ifdef CONFIG_USB_GADGET
  177. static int s5pc210_phy_control(int on)
  178. {
  179. struct udevice *dev;
  180. int reg, ret;
  181. ret = pmic_get("max8997-pmic", &dev);
  182. if (ret)
  183. return ret;
  184. if (on) {
  185. reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
  186. reg |= ENSAFEOUT1;
  187. ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
  188. if (ret) {
  189. puts("MAX8997 setting error!\n");
  190. return ret;
  191. }
  192. reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
  193. reg |= EN_LDO;
  194. ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
  195. if (ret) {
  196. puts("MAX8997 setting error!\n");
  197. return ret;
  198. }
  199. reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
  200. reg |= EN_LDO;
  201. ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
  202. if (ret) {
  203. puts("MAX8997 setting error!\n");
  204. return ret;
  205. }
  206. } else {
  207. reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
  208. reg &= DIS_LDO;
  209. ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
  210. if (ret) {
  211. puts("MAX8997 setting error!\n");
  212. return ret;
  213. }
  214. reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
  215. reg &= DIS_LDO;
  216. ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
  217. if (ret) {
  218. puts("MAX8997 setting error!\n");
  219. return ret;
  220. }
  221. reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
  222. reg &= ~ENSAFEOUT1;
  223. ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
  224. if (ret) {
  225. puts("MAX8997 setting error!\n");
  226. return ret;
  227. }
  228. }
  229. return 0;
  230. }
  231. struct dwc2_plat_otg_data s5pc210_otg_data = {
  232. .phy_control = s5pc210_phy_control,
  233. .regs_phy = EXYNOS4_USBPHY_BASE,
  234. .regs_otg = EXYNOS4_USBOTG_BASE,
  235. .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
  236. .usb_flags = PHY0_SLEEP,
  237. };
  238. int board_usb_init(int index, enum usb_init_type init)
  239. {
  240. debug("USB_udc_probe\n");
  241. return dwc2_udc_probe(&s5pc210_otg_data);
  242. }
  243. int g_dnl_board_usb_cable_connected(void)
  244. {
  245. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  246. struct pmic *muic = pmic_get("MAX8997_MUIC");
  247. if (!muic)
  248. return 0;
  249. return !!muic->chrg->chrg_type(muic);
  250. #else
  251. return false;
  252. #endif
  253. }
  254. #endif
  255. static void pmic_reset(void)
  256. {
  257. gpio_direction_output(EXYNOS4_GPIO_X07, 1);
  258. gpio_set_pull(EXYNOS4_GPIO_X27, S5P_GPIO_PULL_NONE);
  259. }
  260. static void board_clock_init(void)
  261. {
  262. struct exynos4_clock *clk =
  263. (struct exynos4_clock *)samsung_get_base_clock();
  264. writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
  265. writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
  266. writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
  267. writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
  268. writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
  269. writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
  270. writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
  271. writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
  272. writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
  273. writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
  274. writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
  275. writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
  276. writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
  277. writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
  278. writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
  279. writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
  280. writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
  281. writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
  282. writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
  283. writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
  284. writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
  285. writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
  286. writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
  287. writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
  288. writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
  289. writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
  290. writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
  291. writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
  292. writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
  293. writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
  294. writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
  295. writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
  296. writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
  297. writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
  298. writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
  299. writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
  300. writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
  301. writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
  302. writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
  303. writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
  304. }
  305. static void board_power_init(void)
  306. {
  307. struct exynos4_power *pwr =
  308. (struct exynos4_power *)samsung_get_base_power();
  309. /* PS HOLD */
  310. writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
  311. /* Set power down */
  312. writel(0, (unsigned int)&pwr->cam_configuration);
  313. writel(0, (unsigned int)&pwr->tv_configuration);
  314. writel(0, (unsigned int)&pwr->mfc_configuration);
  315. writel(0, (unsigned int)&pwr->g3d_configuration);
  316. writel(0, (unsigned int)&pwr->lcd1_configuration);
  317. writel(0, (unsigned int)&pwr->gps_configuration);
  318. writel(0, (unsigned int)&pwr->gps_alive_configuration);
  319. /* It is necessary to power down core 1 */
  320. /* to successfully boot CPU1 in kernel */
  321. writel(0, (unsigned int)&pwr->arm_core1_configuration);
  322. }
  323. static void exynos_uart_init(void)
  324. {
  325. /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
  326. gpio_request(EXYNOS4_GPIO_Y47, "uart_sel");
  327. gpio_set_pull(EXYNOS4_GPIO_Y47, S5P_GPIO_PULL_UP);
  328. gpio_direction_output(EXYNOS4_GPIO_Y47, 1);
  329. }
  330. int exynos_early_init_f(void)
  331. {
  332. wdt_stop();
  333. pmic_reset();
  334. board_clock_init();
  335. exynos_uart_init();
  336. board_power_init();
  337. return 0;
  338. }
  339. void exynos_reset_lcd(void)
  340. {
  341. gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset");
  342. gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
  343. udelay(10000);
  344. gpio_direction_output(EXYNOS4_GPIO_Y45, 0);
  345. udelay(10000);
  346. gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
  347. }
  348. int lcd_power(void)
  349. {
  350. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  351. int ret = 0;
  352. struct pmic *p = pmic_get("MAX8997_PMIC");
  353. if (!p)
  354. return -ENODEV;
  355. if (pmic_probe(p))
  356. return 0;
  357. /* LDO15 voltage: 2.2v */
  358. ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO);
  359. /* LDO13 voltage: 3.0v */
  360. ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO);
  361. if (ret) {
  362. puts("MAX8997 LDO setting error!\n");
  363. return -1;
  364. }
  365. #endif
  366. return 0;
  367. }
  368. int mipi_power(void)
  369. {
  370. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  371. int ret = 0;
  372. struct pmic *p = pmic_get("MAX8997_PMIC");
  373. if (!p)
  374. return -ENODEV;
  375. if (pmic_probe(p))
  376. return 0;
  377. /* LDO3 voltage: 1.1v */
  378. ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO);
  379. /* LDO4 voltage: 1.8v */
  380. ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO);
  381. if (ret) {
  382. puts("MAX8997 LDO setting error!\n");
  383. return -1;
  384. }
  385. #endif
  386. return 0;
  387. }
  388. #ifdef CONFIG_LCD
  389. void exynos_lcd_misc_init(vidinfo_t *vid)
  390. {
  391. #ifdef CONFIG_TIZEN
  392. get_tizen_logo_info(vid);
  393. #endif
  394. #ifdef CONFIG_S6E8AX0
  395. s6e8ax0_init();
  396. env_set("lcdinfo", "lcd=s6e8ax0");
  397. #endif
  398. }
  399. #endif