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>
11 #include <asm/arch/pinmux.h>
12 #include <asm/arch/power.h>
13 #include <asm/arch/mipi_dsim.h>
14 #include <power/pmic.h>
15 #include <power/max77686_pmic.h>
16 #include <power/battery.h>
17 #include <power/max77693_pmic.h>
18 #include <power/max77693_muic.h>
19 #include <power/max77693_fg.h>
23 #include <usb/dwc2_udc.h>
24 #include <usb_mass_storage.h>
26 static unsigned int board_rev = -1;
28 static inline u32 get_model_rev(void);
30 static void check_hw_revision(void)
37 * GPM1[1:0]: MODEL_REV[1:0]
38 * Don't set as pull-none for these N/C pin.
39 * TRM say that it may cause unexcepted state and leakage current.
40 * and pull-none is only for output function.
42 for (i = 0; i < 2; i++) {
43 int pin = i + EXYNOS4X12_GPIO_M10;
45 sprintf(str, "model_rev%d", i);
46 gpio_request(pin, str);
47 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
50 /* GPM1[5:2]: HW_REV[3:0] */
51 for (i = 0; i < 4; i++) {
52 int pin = i + EXYNOS4X12_GPIO_M12;
54 sprintf(str, "hw_rev%d", i);
55 gpio_request(pin, str);
56 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
57 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
60 /* GPM1[1:0]: MODEL_REV[1:0] */
61 for (i = 0; i < 2; i++)
62 modelrev |= (gpio_get_value(EXYNOS4X12_GPIO_M10 + i) << i);
64 /* board_rev[15:8] = model */
65 board_rev = modelrev << 8;
68 u32 get_board_rev(void)
73 static inline u32 get_model_rev(void)
75 return (board_rev >> 8) & 0xff;
78 static void board_external_gpio_init(void)
81 * some pins which in alive block are connected with external pull-up
82 * but it's default setting is pull-down.
83 * if that pin set as input then that floated
86 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE); /* PS_ALS_INT */
87 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE); /* TSP_nINT */
88 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE); /* AP_PMIC_IRQ*/
89 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE); /* IF_PMIC_IRQ*/
90 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE); /* VOL_UP */
91 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE); /* VOL_DOWN */
92 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE); /* FUEL_ALERT */
93 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE); /* ADC_INT */
94 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE); /* nPOWER */
95 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE); /* WPC_INT */
96 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE); /* OK_KEY */
97 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE); /* HDMI_HPD */
100 int exynos_early_init_f(void)
102 board_external_gpio_init();
107 int exynos_init(void)
109 struct exynos4_power *pwr =
110 (struct exynos4_power *)samsung_get_base_power();
113 printf("HW Revision:\t0x%04x\n", board_rev);
116 * First bootloader on the TRATS2 platform uses
117 * INFORM4 and INFORM5 registers for recovery
119 * To indicate correct boot chain - those two
120 * registers must be cleared out
122 writel(0, &pwr->inform4);
123 writel(0, &pwr->inform5);
128 int exynos_power_init(void)
130 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
132 struct power_battery *pb;
133 struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
135 pmic_init_max77693(I2C_10); /* I2C adapter 10 - bus name soft1 */
136 power_muic_init(I2C_10); /* I2C adapter 10 - bus name soft1 */
137 power_fg_init(I2C_9); /* I2C adapter 9 - bus name soft0 */
140 p_chrg = pmic_get("MAX77693_PMIC");
142 puts("MAX77693_PMIC: Not found\n");
146 p_muic = pmic_get("MAX77693_MUIC");
148 puts("MAX77693_MUIC: Not found\n");
152 p_fg = pmic_get("MAX77693_FG");
154 puts("MAX17042_FG: Not found\n");
158 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
159 puts("No battery detected\n");
161 p_bat = pmic_get("BAT_TRATS2");
163 puts("BAT_TRATS2: Not found\n");
167 p_fg->parent = p_bat;
168 p_chrg->parent = p_bat;
169 p_muic->parent = p_bat;
171 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
174 chrg = p_muic->chrg->chrg_type(p_muic);
175 debug("CHARGER TYPE: %d\n", chrg);
177 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
178 puts("No battery detected\n");
182 p_fg->fg->fg_battery_check(p_fg, p_bat);
184 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
185 puts("CHARGE Battery !\n");
190 #ifdef CONFIG_USB_GADGET
191 static int s5pc210_phy_control(int on)
193 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
196 struct pmic *p, *p_pmic, *p_muic;
198 p_pmic = pmic_get("MAX77686_PMIC");
202 if (pmic_probe(p_pmic))
205 p_muic = pmic_get("MAX77693_MUIC");
209 if (pmic_probe(p_muic))
213 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
217 p = pmic_get("MAX77693_PMIC");
225 ret = pmic_reg_read(p, MAX77693_SAFEOUT, &val);
229 val |= MAX77693_ENSAFEOUT1;
230 ret = pmic_reg_write(p, MAX77693_SAFEOUT, val);
235 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
236 MAX77693_MUIC_CTRL1_DN1DP2);
239 ret = max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
244 ret = pmic_reg_write(p_muic, MAX77693_MUIC_CONTROL1,
245 MAX77693_MUIC_CTRL1_UT1UR2);
254 struct dwc2_plat_otg_data s5pc210_otg_data = {
255 .phy_control = s5pc210_phy_control,
256 .regs_phy = EXYNOS4X12_USBPHY_BASE,
257 .regs_otg = EXYNOS4X12_USBOTG_BASE,
258 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
259 .usb_flags = PHY0_SLEEP,
262 int board_usb_init(int index, enum usb_init_type init)
264 debug("USB_udc_probe\n");
265 return dwc2_udc_probe(&s5pc210_otg_data);
268 int g_dnl_board_usb_cable_connected(void)
270 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
271 struct pmic *muic = pmic_get("MAX77693_MUIC");
275 return !!muic->chrg->chrg_type(muic);
289 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
290 struct pmic *p = pmic_get("MAX77686_PMIC");
292 /* LDO8 VMIPI_1.0V_AP */
293 max77686_set_ldo_mode(p, 8, OPMODE_ON);
294 /* LDO10 VMIPI_1.8V_AP */
295 max77686_set_ldo_mode(p, 10, OPMODE_ON);
301 void exynos_lcd_power_on(void)
303 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
304 struct pmic *p = pmic_get("MAX77686_PMIC");
306 /* LCD_2.2V_EN: GPC0[1] */
307 gpio_request(EXYNOS4X12_GPIO_C01, "lcd_2v2_en");
308 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
309 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
311 /* LDO25 VCC_3.1V_LCD */
313 max77686_set_ldo_voltage(p, 25, 3100000);
314 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
318 void exynos_reset_lcd(void)
321 gpio_request(EXYNOS4X12_GPIO_F21, "lcd_reset");
322 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
324 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
327 void exynos_lcd_misc_init(vidinfo_t *vid)
330 get_tizen_logo_info(vid);
332 #ifdef CONFIG_S6E8AX0