2 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
3 * Sanghee Kim <sh0130.kim@samsung.com>
4 * Piotr Wilczek <p.wilczek@samsung.com>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/arch/pinmux.h>
13 #include <asm/arch/power.h>
14 #include <asm/arch/mipi_dsim.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>
24 #include <usb/dwc2_udc.h>
25 #include <usb_mass_storage.h>
27 static unsigned int board_rev = -1;
29 static inline u32 get_model_rev(void);
31 static void check_hw_revision(void)
38 * GPM1[1:0]: MODEL_REV[1:0]
39 * Don't set as pull-none for these N/C pin.
40 * TRM say that it may cause unexcepted state and leakage current.
41 * and pull-none is only for output function.
43 for (i = 0; i < 2; i++) {
44 int pin = i + EXYNOS4X12_GPIO_M10;
46 sprintf(str, "model_rev%d", i);
47 gpio_request(pin, str);
48 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
51 /* GPM1[5:2]: HW_REV[3:0] */
52 for (i = 0; i < 4; i++) {
53 int pin = i + EXYNOS4X12_GPIO_M12;
55 sprintf(str, "hw_rev%d", i);
56 gpio_request(pin, str);
57 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
58 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
61 /* GPM1[1:0]: MODEL_REV[1:0] */
62 for (i = 0; i < 2; i++)
63 modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
65 /* board_rev[15:8] = model */
66 board_rev = modelrev << 8;
69 u32 get_board_rev(void)
74 static inline u32 get_model_rev(void)
76 return (board_rev >> 8) & 0xff;
79 static void board_external_gpio_init(void)
82 * some pins which in alive block are connected with external pull-up
83 * but it's default setting is pull-down.
84 * if that pin set as input then that floated
87 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */
88 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */
89 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/
90 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/
91 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */
92 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */
93 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */
94 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */
95 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */
96 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */
97 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */
98 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */
101 int exynos_early_init_f(void)
103 board_external_gpio_init();
108 int exynos_init(void)
110 struct exynos4_power *pwr =
111 (struct exynos4_power *)samsung_get_base_power();
114 printf("HW Revision:\t0x%04x\n", board_rev);
117 * First bootloader on the TRATS2 platform uses
118 * INFORM4 and INFORM5 registers for recovery
120 * To indicate correct boot chain - those two
121 * registers must be cleared out
123 writel(0, &pwr->inform4);
124 writel(0, &pwr->inform5);
129 int exynos_power_init(void)
131 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
133 struct power_battery *pb;
134 struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
136 pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */
137 power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */
138 power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */
141 p_chrg = pmic_get("MAX77693_PMIC");
143 puts("MAX77693_PMIC: Not found\n");
147 p_muic = pmic_get("MAX77693_MUIC");
149 puts("MAX77693_MUIC: Not found\n");
153 p_fg = pmic_get("MAX77693_FG");
155 puts("MAX17042_FG: Not found\n");
159 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
160 puts("No battery detected\n");
162 p_bat = pmic_get("BAT_TRATS2");
164 puts("BAT_TRATS2: Not found\n");
168 p_fg->parent = p_bat;
169 p_chrg->parent = p_bat;
170 p_muic->parent = p_bat;
172 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
175 chrg = p_muic->chrg->chrg_type(p_muic);
176 debug("CHARGER TYPE: %d\n", chrg);
178 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
179 puts("No battery detected\n");
183 p_fg->fg->fg_battery_check(p_fg, p_bat);
185 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
186 puts("CHARGE Battery !\n");
191 #ifdef CONFIG_USB_GADGET
192 static int s5pc210_phy_control(int on)
194 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
197 struct pmic *p, *p_pmic, *p_muic;
199 p_pmic = pmic_get("MAX77686_PMIC");
203 if (pmic_probe(p_pmic))
206 p_muic = pmic_get("MAX77693_MUIC");
210 if (pmic_probe(p_muic))
214 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
218 p = pmic_get("MAX77693_PMIC");
226 ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
230 val |= MAX77693_ENSAFEOUT1;
231 ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
236 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
237 MAX77693_MUIC_CTRL1_DN1DP2);
240 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
245 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
246 MAX77693_MUIC_CTRL1_UT1UR2);
255 struct dwc2_plat_otg_data s5pc210_otg_data = {
256 .phy_control = s5pc210_phy_control,
257 .regs_phy = EXYNOS4X12_USBPHY_BASE,
258 .regs_otg = EXYNOS4X12_USBOTG_BASE,
259 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
260 .usb_flags = PHY0_SLEEP,
263 int board_usb_init(int index, enum usb_init_type init)
265 debug("USB_udc_probe\n");
266 return dwc2_udc_probe(&s5pc210_otg_data);
269 int g_dnl_board_usb_cable_connected(void)
271 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
272 struct pmic *muic = pmic_get("MAX77693_MUIC");
276 return !!muic->chrg->chrg_type(muic);
290 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
291 struct pmic *p = pmic_get("MAX77686_PMIC");
293 /* LDO8 VMIPI_1.0V_AP */
294 max77686_set_ldo_mode(p, 8, OPMODE_ON);
295 /* LDO10 VMIPI_1.8V_AP */
296 max77686_set_ldo_mode(p, 10, OPMODE_ON);
302 void exynos_lcd_power_on(void)
304 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
305 struct pmic *p = pmic_get("MAX77686_PMIC");
307 /* LCD_2.2V_EN: GPC0[1] */
308 gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
309 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
310 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
312 /* LDO25 VCC_3.1V_LCD */
314 max77686_set_ldo_voltage(p, 25, 3100000);
315 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
319 void exynos_reset_lcd(void)
322 gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
323 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
325 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
328 void exynos_lcd_misc_init(vidinfo_t *vid)
331 get_tizen_logo_info(vid);
333 #ifdef CONFIG_S6E8AX0