1 // SPDX-License-Identifier: GPL-2.0+
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>
12 #include <asm/arch/pinmux.h>
13 #include <asm/arch/power.h>
14 #include <asm/arch/mipi_dsim.h>
15 #include <linux/delay.h>
16 #include <power/pmic.h>
17 #include <power/max77686_pmic.h>
18 #include <power/battery.h>
19 #include <power/max77693_pmic.h>
20 #include <power/max77693_muic.h>
21 #include <power/max77693_fg.h>
25 #include <usb/dwc2_udc.h>
26 #include <usb_mass_storage.h>
28 static unsigned int board_rev = -1;
30 static inline u32 get_model_rev(void);
32 static void check_hw_revision(void)
39 * GPM1[1:0]: MODEL_REV[1:0]
40 * Don't set as pull-none for these N/C pin.
41 * TRM say that it may cause unexcepted state and leakage current.
42 * and pull-none is only for output function.
44 for (i = 0; i < 2; i++) {
45 int pin = i + EXYNOS4X12_GPIO_M10;
47 sprintf(str, "model_rev%d", i);
48 gpio_request(pin, str);
49 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
52 /* GPM1[5:2]: HW_REV[3:0] */
53 for (i = 0; i < 4; i++) {
54 int pin = i + EXYNOS4X12_GPIO_M12;
56 sprintf(str, "hw_rev%d", i);
57 gpio_request(pin, str);
58 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
59 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
62 /* GPM1[1:0]: MODEL_REV[1:0] */
63 for (i = 0; i < 2; i++)
64 modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
66 /* board_rev[15:8] = model */
67 board_rev = modelrev << 8;
70 u32 get_board_rev(void)
75 static inline u32 get_model_rev(void)
77 return (board_rev >> 8) & 0xff;
80 static void board_external_gpio_init(void)
83 * some pins which in alive block are connected with external pull-up
84 * but it's default setting is pull-down.
85 * if that pin set as input then that floated
88 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */
89 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */
90 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/
91 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/
92 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */
93 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */
94 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */
95 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */
96 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */
97 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */
98 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */
99 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */
102 int exynos_early_init_f(void)
104 board_external_gpio_init();
109 int exynos_init(void)
111 struct exynos4_power *pwr =
112 (struct exynos4_power *)samsung_get_base_power();
115 printf("HW Revision:\t0x%04x\n", board_rev);
118 * First bootloader on the TRATS2 platform uses
119 * INFORM4 and INFORM5 registers for recovery
121 * To indicate correct boot chain - those two
122 * registers must be cleared out
124 writel(0, &pwr->inform4);
125 writel(0, &pwr->inform5);
130 int exynos_power_init(void)
132 #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
134 struct power_battery *pb;
135 struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
137 pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */
138 power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */
139 power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */
142 p_chrg = pmic_get("MAX77693_PMIC");
144 puts("MAX77693_PMIC: Not found\n");
148 p_muic = pmic_get("MAX77693_MUIC");
150 puts("MAX77693_MUIC: Not found\n");
154 p_fg = pmic_get("MAX77693_FG");
156 puts("MAX17042_FG: Not found\n");
160 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
161 puts("No battery detected\n");
163 p_bat = pmic_get("BAT_TRATS2");
165 puts("BAT_TRATS2: Not found\n");
169 p_fg->parent = p_bat;
170 p_chrg->parent = p_bat;
171 p_muic->parent = p_bat;
173 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
176 chrg = p_muic->chrg->chrg_type(p_muic);
177 debug("CHARGER TYPE: %d\n", chrg);
179 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
180 puts("No battery detected\n");
184 p_fg->fg->fg_battery_check(p_fg, p_bat);
186 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
187 puts("CHARGE Battery !\n");
192 #ifdef CONFIG_USB_GADGET
193 static int s5pc210_phy_control(int on)
195 #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
198 struct pmic *p, *p_pmic, *p_muic;
200 p_pmic = pmic_get("MAX77686_PMIC");
204 if (pmic_probe(p_pmic))
207 p_muic = pmic_get("MAX77693_MUIC");
211 if (pmic_probe(p_muic))
215 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
219 p = pmic_get("MAX77693_PMIC");
227 ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
231 val |= MAX77693_ENSAFEOUT1;
232 ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
237 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
238 MAX77693_MUIC_CTRL1_DN1DP2);
241 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
246 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
247 MAX77693_MUIC_CTRL1_UT1UR2);
256 struct dwc2_plat_otg_data s5pc210_otg_data = {
257 .phy_control = s5pc210_phy_control,
258 .regs_phy = EXYNOS4X12_USBPHY_BASE,
259 .regs_otg = EXYNOS4X12_USBOTG_BASE,
260 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
261 .usb_flags = PHY0_SLEEP,
264 int board_usb_init(int index, enum usb_init_type init)
266 debug("USB_udc_probe\n");
267 return dwc2_udc_probe(&s5pc210_otg_data);
270 int g_dnl_board_usb_cable_connected(void)
272 #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
273 struct pmic *muic = pmic_get("MAX77693_MUIC");
277 return !!muic->chrg->chrg_type(muic);
291 #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
292 struct pmic *p = pmic_get("MAX77686_PMIC");
294 /* LDO8 VMIPI_1.0V_AP */
295 max77686_set_ldo_mode(p, 8, OPMODE_ON);
296 /* LDO10 VMIPI_1.8V_AP */
297 max77686_set_ldo_mode(p, 10, OPMODE_ON);
303 void exynos_lcd_power_on(void)
305 #if !CONFIG_IS_ENABLED(DM_I2C) /* TODO(maintainer): Convert to driver model */
306 struct pmic *p = pmic_get("MAX77686_PMIC");
308 /* LCD_2.2V_EN: GPC0[1] */
309 gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
310 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
311 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
313 /* LDO25 VCC_3.1V_LCD */
315 max77686_set_ldo_voltage(p, 25, 3100000);
316 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
320 void exynos_reset_lcd(void)
323 gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
324 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
326 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
329 void exynos_lcd_misc_init(vidinfo_t *vid)
332 get_tizen_logo_info(vid);
334 #ifdef CONFIG_S6E8AX0