trats2.c 7.6 KB

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