2 * Copyright (C) 2011 Samsung Electronics
3 * Heungjun Kim <riverful.kim@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
5 * Donghwa Lee <dh09.lee@samsung.com>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/cpu.h>
14 #include <asm/arch/gpio.h>
15 #include <asm/arch/pinmux.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/mipi_dsim.h>
18 #include <asm/arch/watchdog.h>
19 #include <asm/arch/power.h>
20 #include <power/pmic.h>
21 #include <usb/s3c_udc.h>
22 #include <power/max8997_pmic.h>
23 #include <power/max8997_muic.h>
24 #include <power/battery.h>
25 #include <power/max17042_fg.h>
28 #include <usb_mass_storage.h>
32 DECLARE_GLOBAL_DATA_PTR;
34 unsigned int board_rev;
36 #ifdef CONFIG_REVISION_TAG
37 u32 get_board_rev(void)
43 static void check_hw_revision(void);
44 struct s3c_plat_otg_data s5pc210_otg_data;
49 printf("HW Revision:\t0x%x\n", board_rev);
54 void i2c_init_board(void)
59 err = exynos_pinmux_config(PERIPH_ID_I2C5, PINMUX_FLAG_NONE);
61 debug("I2C%d not configured\n", (I2C_5));
66 gpio_direction_output(EXYNOS4_GPIO_Y40, 1);
67 gpio_direction_output(EXYNOS4_GPIO_Y41, 1);
70 static void trats_low_power_mode(void)
72 struct exynos4_clock *clk =
73 (struct exynos4_clock *)samsung_get_base_clock();
74 struct exynos4_power *pwr =
75 (struct exynos4_power *)samsung_get_base_power();
77 /* Power down CORE1 */
78 /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
79 writel(0x0, &pwr->arm_core1_configuration);
81 /* Change the APLL frequency */
82 /* ENABLE (1 enable) | LOCKED (1 locked) */
84 /* FSEL | MDIV | PDIV | SDIV */
85 /* [27] | [25:16] | [13:8] | [2:0] */
86 writel(0xa0c80604, &clk->apll_con0);
88 /* Change CPU0 clock divider */
89 /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */
90 /* [30:28] | [26:24] | [22:20] | [18:16] */
91 /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */
92 /* [14:12] | [10:8] | [6:4] | [2:0] */
93 writel(0x00000100, &clk->div_cpu0);
95 /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
96 while (readl(&clk->div_stat_cpu0) & 0x1111111)
99 /* Change clock divider ratio for DMC */
100 /* DMCP_RATIO | DMCD_RATIO */
101 /* [22:20] | [18:16] */
102 /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */
103 /* [14:12] | [10:8] | [6:4] | [2:0] */
104 writel(0x13113117, &clk->div_dmc0);
106 /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
107 while (readl(&clk->div_stat_dmc0) & 0x11111111)
110 /* Turn off unnecessary power domains */
111 writel(0x0, &pwr->xxti_configuration); /* XXTI */
112 writel(0x0, &pwr->cam_configuration); /* CAM */
113 writel(0x0, &pwr->tv_configuration); /* TV */
114 writel(0x0, &pwr->mfc_configuration); /* MFC */
115 writel(0x0, &pwr->g3d_configuration); /* G3D */
116 writel(0x0, &pwr->gps_configuration); /* GPS */
117 writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */
119 /* Turn off unnecessary clocks */
120 writel(0x0, &clk->gate_ip_cam); /* CAM */
121 writel(0x0, &clk->gate_ip_tv); /* TV */
122 writel(0x0, &clk->gate_ip_mfc); /* MFC */
123 writel(0x0, &clk->gate_ip_g3d); /* G3D */
124 writel(0x0, &clk->gate_ip_image); /* IMAGE */
125 writel(0x0, &clk->gate_ip_gps); /* GPS */
128 static int pmic_init_max8997(void)
130 struct pmic *p = pmic_get("MAX8997_PMIC");
137 /* BUCK1 VARM: 1.2V */
138 val = (1200000 - 650000) / 25000;
139 ret |= pmic_reg_write(p, MAX8997_REG_BUCK1DVS1, val);
140 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
141 ret |= pmic_reg_write(p, MAX8997_REG_BUCK1CTRL, val);
143 /* BUCK2 VINT: 1.1V */
144 val = (1100000 - 650000) / 25000;
145 ret |= pmic_reg_write(p, MAX8997_REG_BUCK2DVS1, val);
146 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
147 ret |= pmic_reg_write(p, MAX8997_REG_BUCK2CTRL, val);
150 /* BUCK3 G3D: 1.1V - OFF */
151 ret |= pmic_reg_read(p, MAX8997_REG_BUCK3CTRL, &val);
153 ret |= pmic_reg_write(p, MAX8997_REG_BUCK3CTRL, val);
155 val = (1100000 - 750000) / 50000;
156 ret |= pmic_reg_write(p, MAX8997_REG_BUCK3DVS, val);
158 /* BUCK4 CAMISP: 1.2V - OFF */
159 ret |= pmic_reg_read(p, MAX8997_REG_BUCK4CTRL, &val);
161 ret |= pmic_reg_write(p, MAX8997_REG_BUCK4CTRL, val);
163 val = (1200000 - 650000) / 25000;
164 ret |= pmic_reg_write(p, MAX8997_REG_BUCK4DVS, val);
166 /* BUCK5 VMEM: 1.2V */
167 val = (1200000 - 650000) / 25000;
168 for (i = 0; i < 8; i++)
169 ret |= pmic_reg_write(p, MAX8997_REG_BUCK5DVS1 + i, val);
171 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
172 ret |= pmic_reg_write(p, MAX8997_REG_BUCK5CTRL, val);
174 /* BUCK6 CAM AF: 2.8V */
175 /* No Voltage Setting Register */
178 ret |= pmic_reg_write(p, MAX8997_REG_BUCK6CTRL, val);
180 /* BUCK7 VCC_SUB: 2.0V */
181 val = (2000000 - 750000) / 50000;
182 ret |= pmic_reg_write(p, MAX8997_REG_BUCK7DVS, val);
184 /* LDO1 VADC: 3.3V */
185 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
186 ret |= pmic_reg_write(p, MAX8997_REG_LDO1CTRL, val);
188 /* LDO1 Disable active discharging */
189 ret |= pmic_reg_read(p, MAX8997_REG_LDO1CONFIG, &val);
191 ret |= pmic_reg_write(p, MAX8997_REG_LDO1CONFIG, val);
193 /* LDO2 VALIVE: 1.1V */
194 val = max8997_reg_ldo(1100000) | EN_LDO;
195 ret |= pmic_reg_write(p, MAX8997_REG_LDO2CTRL, val);
197 /* LDO3 VUSB/MIPI: 1.1V */
198 val = max8997_reg_ldo(1100000) | DIS_LDO; /* OFF */
199 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, val);
201 /* LDO4 VMIPI: 1.8V */
202 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
203 ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, val);
205 /* LDO5 VHSIC: 1.2V */
206 val = max8997_reg_ldo(1200000) | DIS_LDO; /* OFF */
207 ret |= pmic_reg_write(p, MAX8997_REG_LDO5CTRL, val);
209 /* LDO6 VCC_1.8V_PDA: 1.8V */
210 val = max8997_reg_ldo(1800000) | EN_LDO;
211 ret |= pmic_reg_write(p, MAX8997_REG_LDO6CTRL, val);
213 /* LDO7 CAM_ISP: 1.8V */
214 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
215 ret |= pmic_reg_write(p, MAX8997_REG_LDO7CTRL, val);
217 /* LDO8 VDAC/VUSB: 3.3V */
218 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
219 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, val);
221 /* LDO9 VCC_2.8V_PDA: 2.8V */
222 val = max8997_reg_ldo(2800000) | EN_LDO;
223 ret |= pmic_reg_write(p, MAX8997_REG_LDO9CTRL, val);
225 /* LDO10 VPLL: 1.1V */
226 val = max8997_reg_ldo(1100000) | EN_LDO;
227 ret |= pmic_reg_write(p, MAX8997_REG_LDO10CTRL, val);
229 /* LDO11 TOUCH: 2.8V */
230 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
231 ret |= pmic_reg_write(p, MAX8997_REG_LDO11CTRL, val);
233 /* LDO12 VTCAM: 1.8V */
234 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
235 ret |= pmic_reg_write(p, MAX8997_REG_LDO12CTRL, val);
237 /* LDO13 VCC_3.0_LCD: 3.0V */
238 val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
239 ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, val);
241 /* LDO14 MOTOR: 3.0V */
242 val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
243 ret |= pmic_reg_write(p, MAX8997_REG_LDO14CTRL, val);
245 /* LDO15 LED_A: 2.8V */
246 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
247 ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, val);
249 /* LDO16 CAM_SENSOR: 1.8V */
250 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
251 ret |= pmic_reg_write(p, MAX8997_REG_LDO16CTRL, val);
253 /* LDO17 VTF: 2.8V */
254 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
255 ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
257 /* LDO18 TOUCH_LED 3.3V */
258 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
259 ret |= pmic_reg_write(p, MAX8997_REG_LDO18CTRL, val);
261 /* LDO21 VDDQ: 1.2V */
262 val = max8997_reg_ldo(1200000) | EN_LDO;
263 ret |= pmic_reg_write(p, MAX8997_REG_LDO21CTRL, val);
265 /* SAFEOUT for both 1 and 2: 4.9V, Active discharge, Enable */
266 val = (SAFEOUT_4_90V << 0) | (SAFEOUT_4_90V << 2) |
267 ACTDISSAFEO1 | ACTDISSAFEO2 | ENSAFEOUT1 | ENSAFEOUT2;
268 ret |= pmic_reg_write(p, MAX8997_REG_SAFEOUTCTRL, val);
271 puts("MAX8997 PMIC setting error!\n");
277 int exynos_power_init(void)
280 struct power_battery *pb;
281 struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
284 * For PMIC/MUIC the I2C bus is named as I2C5, but it is connected
285 * to logical I2C adapter 0
287 * The FUEL_GAUGE is marked as I2C9 on the schematic, but connected
288 * to logical I2C adapter 1
290 ret = pmic_init(I2C_5);
291 ret |= pmic_init_max8997();
292 ret |= power_fg_init(I2C_9);
293 ret |= power_muic_init(I2C_5);
294 ret |= power_bat_init(0);
298 p_fg = pmic_get("MAX17042_FG");
300 puts("MAX17042_FG: Not found\n");
304 p_chrg = pmic_get("MAX8997_PMIC");
306 puts("MAX8997_PMIC: Not found\n");
310 p_muic = pmic_get("MAX8997_MUIC");
312 puts("MAX8997_MUIC: Not found\n");
316 p_bat = pmic_get("BAT_TRATS");
318 puts("BAT_TRATS: Not found\n");
322 p_fg->parent = p_bat;
323 p_chrg->parent = p_bat;
324 p_muic->parent = p_bat;
326 p_bat->low_power_mode = trats_low_power_mode;
327 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
330 chrg = p_muic->chrg->chrg_type(p_muic);
331 debug("CHARGER TYPE: %d\n", chrg);
333 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
334 puts("No battery detected\n");
338 p_fg->fg->fg_battery_check(p_fg, p_bat);
340 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
341 puts("CHARGE Battery !\n");
346 static unsigned int get_hw_revision(void)
351 /* hw_rev[3:0] == GPE1[3:0] */
352 for (i = EXYNOS4_GPIO_E10; i < EXYNOS4_GPIO_E14; i++) {
353 gpio_cfg_pin(i, S5P_GPIO_INPUT);
354 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
359 for (i = 0; i < 4; i++)
360 hwrev |= (gpio_get_value(EXYNOS4_GPIO_E10 + i) << i);
362 debug("hwrev 0x%x\n", hwrev);
367 static void check_hw_revision(void)
371 hwrev = get_hw_revision();
377 #ifdef CONFIG_USB_GADGET
378 static int s5pc210_phy_control(int on)
382 struct pmic *p = pmic_get("MAX8997_PMIC");
390 ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
392 ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
393 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, EN_LDO | val);
395 ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
396 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, EN_LDO | val);
398 ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
399 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, DIS_LDO | val);
401 ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
402 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, DIS_LDO | val);
403 ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
404 ENSAFEOUT1, LDO_OFF);
408 puts("MAX8997 LDO setting error!\n");
415 struct s3c_plat_otg_data s5pc210_otg_data = {
416 .phy_control = s5pc210_phy_control,
417 .regs_phy = EXYNOS4_USBPHY_BASE,
418 .regs_otg = EXYNOS4_USBOTG_BASE,
419 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
420 .usb_flags = PHY0_SLEEP,
423 int board_usb_init(int index, enum usb_init_type init)
425 debug("USB_udc_probe\n");
426 return s3c_udc_probe(&s5pc210_otg_data);
429 int g_dnl_board_usb_cable_connected(void)
431 struct pmic *muic = pmic_get("MAX8997_MUIC");
435 return !!muic->chrg->chrg_type(muic);
439 static void pmic_reset(void)
441 gpio_direction_output(EXYNOS4_GPIO_X07, 1);
442 gpio_set_pull(EXYNOS4_GPIO_X27, S5P_GPIO_PULL_NONE);
445 static void board_clock_init(void)
447 struct exynos4_clock *clk =
448 (struct exynos4_clock *)samsung_get_base_clock();
450 writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
451 writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
452 writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
453 writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
455 writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
456 writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
457 writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
458 writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
459 writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
460 writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
461 writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
462 writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
463 writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
464 writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
465 writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
466 writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
468 writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
469 writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
470 writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
471 writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
472 writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
473 writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
474 writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
475 writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
476 writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
477 writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
478 writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
479 writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
481 writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
482 writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
483 writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
484 writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
485 writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
486 writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
487 writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
488 writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
489 writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
490 writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
491 writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
492 writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
495 static void board_power_init(void)
497 struct exynos4_power *pwr =
498 (struct exynos4_power *)samsung_get_base_power();
501 writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
504 writel(0, (unsigned int)&pwr->cam_configuration);
505 writel(0, (unsigned int)&pwr->tv_configuration);
506 writel(0, (unsigned int)&pwr->mfc_configuration);
507 writel(0, (unsigned int)&pwr->g3d_configuration);
508 writel(0, (unsigned int)&pwr->lcd1_configuration);
509 writel(0, (unsigned int)&pwr->gps_configuration);
510 writel(0, (unsigned int)&pwr->gps_alive_configuration);
512 /* It is necessary to power down core 1 */
513 /* to successfully boot CPU1 in kernel */
514 writel(0, (unsigned int)&pwr->arm_core1_configuration);
517 static void exynos_uart_init(void)
519 /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
520 gpio_set_pull(EXYNOS4_GPIO_Y47, S5P_GPIO_PULL_UP);
521 gpio_direction_output(EXYNOS4_GPIO_Y47, 1);
524 int exynos_early_init_f(void)
535 void exynos_reset_lcd(void)
537 gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
539 gpio_direction_output(EXYNOS4_GPIO_Y45, 0);
541 gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
547 struct pmic *p = pmic_get("MAX8997_PMIC");
554 /* LDO15 voltage: 2.2v */
555 ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO);
556 /* LDO13 voltage: 3.0v */
557 ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO);
560 puts("MAX8997 LDO setting error!\n");
570 struct pmic *p = pmic_get("MAX8997_PMIC");
577 /* LDO3 voltage: 1.1v */
578 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO);
579 /* LDO4 voltage: 1.8v */
580 ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO);
583 puts("MAX8997 LDO setting error!\n");
590 void exynos_lcd_misc_init(vidinfo_t *vid)
593 get_tizen_logo_info(vid);
595 #ifdef CONFIG_S6E8AX0
597 setenv("lcdinfo", "lcd=s6e8ax0");