trats2.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
  4. * Sanghee Kim <sh0130.kim@samsung.com>
  5. * Piotr Wilczek <p.wilczek@samsung.com>
  6. */
  7. #include <common.h>
  8. #include <lcd.h>
  9. #include <asm/gpio.h>
  10. #include <asm/arch/pinmux.h>
  11. #include <asm/arch/power.h>
  12. #include <asm/arch/mipi_dsim.h>
  13. #include <power/pmic.h>
  14. #include <power/max77686_pmic.h>
  15. #include <power/battery.h>
  16. #include <power/max77693_pmic.h>
  17. #include <power/max77693_muic.h>
  18. #include <power/max77693_fg.h>
  19. #include <libtizen.h>
  20. #include <errno.h>
  21. #include <usb.h>
  22. #include <usb/dwc2_udc.h>
  23. #include <usb_mass_storage.h>
  24. static unsigned int board_rev = -1;
  25. static inline u32 get_model_rev(void);
  26. static void check_hw_revision(void)
  27. {
  28. int modelrev = 0;
  29. char str[12];
  30. int i;
  31. /*
  32. * GPM1[1:0]: MODEL_REV[1:0]
  33. * Don't set as pull-none for these N/C pin.
  34. * TRM say that it may cause unexcepted state and leakage current.
  35. * and pull-none is only for output function.
  36. */
  37. for (i = 0; i < 2; i++) {
  38. int pin = i + EXYNOS4X12_GPIO_M10;
  39. sprintf(str, "model_rev%d", i);
  40. gpio_request(pin, str);
  41. gpio_cfg_pin(pin, S5P_GPIO_INPUT);
  42. }
  43. /* GPM1[5:2]: HW_REV[3:0] */
  44. for (i = 0; i < 4; i++) {
  45. int pin = i + EXYNOS4X12_GPIO_M12;
  46. sprintf(str, "hw_rev%d", i);
  47. gpio_request(pin, str);
  48. gpio_cfg_pin(pin, S5P_GPIO_INPUT);
  49. gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
  50. }
  51. /* GPM1[1:0]: MODEL_REV[1:0] */
  52. for (i = 0; i < 2; i++)
  53. modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
  54. /* board_rev[15:8] = model */
  55. board_rev = modelrev << 8;
  56. }
  57. u32 get_board_rev(void)
  58. {
  59. return board_rev;
  60. }
  61. static inline u32 get_model_rev(void)
  62. {
  63. return (board_rev >> 8) & 0xff;
  64. }
  65. static void board_external_gpio_init(void)
  66. {
  67. /*
  68. * some pins which in alive block are connected with external pull-up
  69. * but it's default setting is pull-down.
  70. * if that pin set as input then that floated
  71. */
  72. gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */
  73. gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */
  74. gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/
  75. gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/
  76. gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */
  77. gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */
  78. gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */
  79. gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */
  80. gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */
  81. gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */
  82. gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */
  83. gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */
  84. }
  85. int exynos_early_init_f(void)
  86. {
  87. board_external_gpio_init();
  88. return 0;
  89. }
  90. int exynos_init(void)
  91. {
  92. struct exynos4_power *pwr =
  93. (struct exynos4_power *)samsung_get_base_power();
  94. check_hw_revision();
  95. printf("HW Revision:\t0x%04x\n", board_rev);
  96. /*
  97. * First bootloader on the TRATS2 platform uses
  98. * INFORM4 and INFORM5 registers for recovery
  99. *
  100. * To indicate correct boot chain - those two
  101. * registers must be cleared out
  102. */
  103. writel(0, &pwr->inform4);
  104. writel(0, &pwr->inform5);
  105. return 0;
  106. }
  107. int exynos_power_init(void)
  108. {
  109. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  110. int chrg;
  111. struct power_battery *pb;
  112. struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
  113. pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */
  114. power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */
  115. power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */
  116. power_bat_init(0);
  117. p_chrg = pmic_get("MAX77693_PMIC");
  118. if (!p_chrg) {
  119. puts("MAX77693_PMIC: Not found\n");
  120. return -ENODEV;
  121. }
  122. p_muic = pmic_get("MAX77693_MUIC");
  123. if (!p_muic) {
  124. puts("MAX77693_MUIC: Not found\n");
  125. return -ENODEV;
  126. }
  127. p_fg = pmic_get("MAX77693_FG");
  128. if (!p_fg) {
  129. puts("MAX17042_FG: Not found\n");
  130. return -ENODEV;
  131. }
  132. if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
  133. puts("No battery detected\n");
  134. p_bat = pmic_get("BAT_TRATS2");
  135. if (!p_bat) {
  136. puts("BAT_TRATS2: Not found\n");
  137. return -ENODEV;
  138. }
  139. p_fg->parent = p_bat;
  140. p_chrg->parent = p_bat;
  141. p_muic->parent = p_bat;
  142. p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
  143. pb = p_bat->pbat;
  144. chrg = p_muic->chrg->chrg_type(p_muic);
  145. debug("CHARGER TYPE: %d\n", chrg);
  146. if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
  147. puts("No battery detected\n");
  148. return 0;
  149. }
  150. p_fg->fg->fg_battery_check(p_fg, p_bat);
  151. if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
  152. puts("CHARGE Battery !\n");
  153. #endif
  154. return 0;
  155. }
  156. #ifdef CONFIG_USB_GADGET
  157. static int s5pc210_phy_control(int on)
  158. {
  159. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  160. int ret = 0;
  161. unsigned int val;
  162. struct pmic *p, *p_pmic, *p_muic;
  163. p_pmic = pmic_get("MAX77686_PMIC");
  164. if (!p_pmic)
  165. return -ENODEV;
  166. if (pmic_probe(p_pmic))
  167. return -1;
  168. p_muic = pmic_get("MAX77693_MUIC");
  169. if (!p_muic)
  170. return -ENODEV;
  171. if (pmic_probe(p_muic))
  172. return -1;
  173. if (on) {
  174. ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
  175. if (ret)
  176. return -1;
  177. p = pmic_get("MAX77693_PMIC");
  178. if (!p)
  179. return -ENODEV;
  180. if (pmic_probe(p))
  181. return -1;
  182. /* SAFEOUT */
  183. ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
  184. if (ret)
  185. return -1;
  186. val |= MAX77693_ENSAFEOUT1;
  187. ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
  188. if (ret)
  189. return -1;
  190. /* PATH: USB */
  191. ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
  192. MAX77693_MUIC_CTRL1_DN1DP2);
  193. } else {
  194. ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
  195. if (ret)
  196. return -1;
  197. /* PATH: UART */
  198. ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
  199. MAX77693_MUIC_CTRL1_UT1UR2);
  200. }
  201. if (ret)
  202. return -1;
  203. #endif
  204. return 0;
  205. }
  206. struct dwc2_plat_otg_data s5pc210_otg_data = {
  207. .phy_control = s5pc210_phy_control,
  208. .regs_phy = EXYNOS4X12_USBPHY_BASE,
  209. .regs_otg = EXYNOS4X12_USBOTG_BASE,
  210. .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
  211. .usb_flags = PHY0_SLEEP,
  212. };
  213. int board_usb_init(int index, enum usb_init_type init)
  214. {
  215. debug("USB_udc_probe\n");
  216. return dwc2_udc_probe(&s5pc210_otg_data);
  217. }
  218. int g_dnl_board_usb_cable_connected(void)
  219. {
  220. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  221. struct pmic *muic = pmic_get("MAX77693_MUIC");
  222. if (!muic)
  223. return 0;
  224. return !!muic->chrg->chrg_type(muic);
  225. #else
  226. return false;
  227. #endif
  228. }
  229. #endif
  230. /*
  231. * LCD
  232. */
  233. #ifdef CONFIG_LCD
  234. int mipi_power(void)
  235. {
  236. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  237. struct pmic *p = pmic_get("MAX77686_PMIC");
  238. /* LDO8 VMIPI_1.0V_AP */
  239. max77686_set_ldo_mode(p, 8, OPMODE_ON);
  240. /* LDO10 VMIPI_1.8V_AP */
  241. max77686_set_ldo_mode(p, 10, OPMODE_ON);
  242. #endif
  243. return 0;
  244. }
  245. void exynos_lcd_power_on(void)
  246. {
  247. #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
  248. struct pmic *p = pmic_get("MAX77686_PMIC");
  249. /* LCD_2.2V_EN: GPC0[1] */
  250. gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
  251. gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
  252. gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
  253. /* LDO25 VCC_3.1V_LCD */
  254. pmic_probe(p);
  255. max77686_set_ldo_voltage(p, 25, 3100000);
  256. max77686_set_ldo_mode(p, 25, OPMODE_LPM);
  257. #endif
  258. }
  259. void exynos_reset_lcd(void)
  260. {
  261. /* reset lcd */
  262. gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
  263. gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
  264. udelay(10);
  265. gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
  266. }
  267. void exynos_lcd_misc_init(vidinfo_t *vid)
  268. {
  269. #ifdef CONFIG_TIZEN
  270. get_tizen_logo_info(vid);
  271. #endif
  272. #ifdef CONFIG_S6E8AX0
  273. s6e8ax0_init();
  274. #endif
  275. }
  276. #endif /* LCD */