2 * Copyright (C) 2014 Samsung Electronics
3 * Przemyslaw Marczak <p.marczak@samsung.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/sections.h>
10 #include <asm/arch/pinmux.h>
11 #include <asm/arch/power.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/gpio.h>
15 #include <asm/arch/cpu.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>
24 #include <usb/s3c_udc.h>
25 #include <usb_mass_storage.h>
28 #include <asm/arch/mipi_dsim.h>
29 #include <samsung/misc.h>
33 DECLARE_GLOBAL_DATA_PTR;
35 #define HWREV_TRATS2_CFG_REG 0x11000280
36 #define HWREV_TRATS2_CFG 0x0
37 #define HWREV_TRATS2_PULL_REG 0x11000288
38 #define HWREV_TRATS2_PULL 0x33000033
39 #define HWREV_TRATS2_DAT_REG 0x11000284
40 #define HWREV_TRATS2_DAT_MASK 0xf0
42 #define CPU_MAIN_REV_MASK 0xf0
43 #define CPU_MAIN_REV_SHIFT 0x4
44 #define CPU_MAIN_REV(x) ((x >> CPU_MAIN_REV_SHIFT) & CPU_MAIN_REV_MASK)
46 #define DTB_PADDING 0x4
48 /* For global battery and charger functions */
49 static struct power_battery *pbat;
50 static struct pmic *p_chrg, *p_muic, *p_fg, *p_bat;
51 static int power_init_done;
53 #ifdef CONFIG_BOARD_TYPES
54 /* Supported Exynos4 boards */
62 static const int board_arch_num[] = {
68 static const char *board_compat[] = {
74 static const char *board_name[] = {
80 static const char *board_model[] = {
86 extern void sdelay(unsigned long);
88 void set_board_type(void)
93 /* GPM1[5:2] as input */
94 writel(HWREV_TRATS2_CFG, HWREV_TRATS2_CFG_REG);
95 writel(HWREV_TRATS2_PULL, HWREV_TRATS2_PULL_REG);
96 hwrev = readl(HWREV_TRATS2_DAT_REG) & HWREV_TRATS2_DAT_MASK;
98 /* Any Trats2 revision is valid */
100 gd->board_type = BOARD_TYPE_TRATS2;
104 /* Set GPA1 pin 1 to HI - enable XCL205 output */
105 /* GPA1CON 0x11400020 */
109 /* GPA1DAT 0x11400024 */
113 /* GPA1PUD 0x11400028 */
117 /* GPA1DRV 0x1140002c */
121 /* Check GPC1 pin 2 input */
122 /* GPC1CON 0x11400020 */
126 /* GPC1PUD 0x11400028 */
130 /* XCL205 - needs some latch time */
133 /* GPC1DAT 0x11400024 */
136 /* Check GPC1 pin2 - LED supplied by XCL205 - X2 only */
137 if (readl(addr) & 0x4)
138 gd->board_type = BOARD_TYPE_ODROID_X2;
140 gd->board_type = BOARD_TYPE_ODROID_U3;
143 int board_is_trats2(void)
145 if (gd->board_type == BOARD_TYPE_TRATS2)
151 int board_is_odroid_x2(void)
153 if (gd->board_type == BOARD_TYPE_ODROID_X2)
159 int board_is_odroid_u3(void)
161 if (gd->board_type == BOARD_TYPE_ODROID_U3)
167 const char *get_board_name(void)
169 return board_name[gd->board_type];
172 const char *get_board_type(void)
174 return board_model[gd->board_type];
178 #ifdef CONFIG_OF_MULTI
179 unsigned long *get_board_fdt(void)
181 unsigned long *fdt = (unsigned long *)&_end;
188 for (i = 0; i < BOARD_TYPES_NUM; i++) {
189 if (!fdt || fdt_magic(fdt) != FDT_MAGIC)
192 compat = (char *) fdt_getprop(fdt, 0, "compatible", NULL);
193 if (compat && !strcmp(board_compat[gd->board_type], compat))
197 size = fdt_totalsize(fdt);
199 fdt += (unsigned long)(roundup(size, DTB_PADDING) >> 2);
206 #ifdef CONFIG_SET_DFU_ALT_INFO
207 char *get_dfu_alt_system(void)
211 if (board_is_trats2())
212 alt_system = DFU_ALT_SYSTEM_TRATS2;
214 alt_system = DFU_ALT_SYSTEM_ODROID;
219 char *get_dfu_alt_boot(void)
223 switch (get_boot_mode()) {
225 if (board_is_trats2())
226 alt_boot = DFU_ALT_BOOT_SD_TRATS2;
228 alt_boot = DFU_ALT_BOOT_SD_ODROID;
231 case BOOT_MODE_EMMC_SD:
232 if (board_is_trats2())
233 alt_boot = DFU_ALT_BOOT_EMMC_TRATS2;
235 alt_boot = DFU_ALT_BOOT_EMMC_ODROID;
249 static void board_clock_init(void)
251 unsigned int set, clr, clr_src_cpu, clr_pll_con0, clr_src_dmc;
252 struct exynos4x12_clock *clk = (struct exynos4x12_clock *)
253 samsung_get_base_clock();
256 * CMU_CPU clocks src to MPLL
258 * MUX_APLL_SEL: FIN_PLL ; FOUT_APLL
259 * MUX_CORE_SEL: MOUT_APLL ; SCLK_MPLL
260 * MUX_HPM_SEL: MOUT_APLL ; SCLK_MPLL_USER_C
261 * MUX_MPLL_USER_SEL_C: FIN_PLL ; SCLK_MPLL
263 clr_src_cpu = MUX_APLL_SEL(0x1) | MUX_CORE_SEL(0x1) |
264 MUX_HPM_SEL(0x1) | MUX_MPLL_USER_SEL_C(0x1);
265 set = MUX_APLL_SEL(0) | MUX_CORE_SEL(1) | MUX_HPM_SEL(1) |
266 MUX_MPLL_USER_SEL_C(1);
268 clrsetbits_le32(&clk->src_cpu, clr_src_cpu, set);
270 /* Wait for mux change */
271 while (readl(&clk->mux_stat_cpu) & MUX_STAT_CPU_CHANGING)
274 /* Set APLL to 1000MHz */
275 clr_pll_con0 = SDIV(0x7) | PDIV(0x3f) | MDIV(0x3ff) | FSEL(0x1);
276 set = SDIV(0) | PDIV(3) | MDIV(125) | FSEL(1);
278 clrsetbits_le32(&clk->apll_con0, clr_pll_con0, set);
280 /* Wait for PLL to be locked */
281 while (!(readl(&clk->apll_con0) & PLL_LOCKED_BIT))
284 /* Set CMU_CPU clocks src to APLL */
285 set = MUX_APLL_SEL(1) | MUX_CORE_SEL(0) | MUX_HPM_SEL(0) |
286 MUX_MPLL_USER_SEL_C(1);
287 clrsetbits_le32(&clk->src_cpu, clr_src_cpu, set);
289 /* Wait for mux change */
290 while (readl(&clk->mux_stat_cpu) & MUX_STAT_CPU_CHANGING)
293 set = CORE_RATIO(0) | COREM0_RATIO(2) | COREM1_RATIO(5) |
294 PERIPH_RATIO(0) | ATB_RATIO(4) | PCLK_DBG_RATIO(1) |
295 APLL_RATIO(0) | CORE2_RATIO(0);
297 * Set dividers for MOUTcore = 1000 MHz
298 * coreout = MOUT / (ratio + 1) = 1000 MHz (0)
299 * corem0 = armclk / (ratio + 1) = 333 MHz (2)
300 * corem1 = armclk / (ratio + 1) = 166 MHz (5)
301 * periph = armclk / (ratio + 1) = 1000 MHz (0)
302 * atbout = MOUT / (ratio + 1) = 200 MHz (4)
303 * pclkdbgout = atbout / (ratio + 1) = 100 MHz (1)
304 * sclkapll = MOUTapll / (ratio + 1) = 1000 MHz (0)
305 * core2out = core_out / (ratio + 1) = 1000 MHz (0) (armclk)
307 clr = CORE_RATIO(0x7) | COREM0_RATIO(0x7) | COREM1_RATIO(0x7) |
308 PERIPH_RATIO(0x7) | ATB_RATIO(0x7) | PCLK_DBG_RATIO(0x7) |
309 APLL_RATIO(0x7) | CORE2_RATIO(0x7);
311 clrsetbits_le32(&clk->div_cpu0, clr, set);
313 /* Wait for divider ready status */
314 while (readl(&clk->div_stat_cpu0) & DIV_STAT_CPU0_CHANGING)
318 * For MOUThpm = 1000 MHz (MOUTapll)
319 * doutcopy = MOUThpm / (ratio + 1) = 200 (4)
320 * sclkhpm = doutcopy / (ratio + 1) = 200 (4)
321 * cores_out = armclk / (ratio + 1) = 1000 (0)
323 clr = COPY_RATIO(0x7) | HPM_RATIO(0x7) | CORES_RATIO(0x7);
324 set = COPY_RATIO(4) | HPM_RATIO(4) | CORES_RATIO(0);
326 clrsetbits_le32(&clk->div_cpu1, clr, set);
328 /* Wait for divider ready status */
329 while (readl(&clk->div_stat_cpu1) & DIV_STAT_CPU1_CHANGING)
333 * Set CMU_DMC clocks src to APLL
335 * MUX_C2C_SEL: SCLKMPLL ; SCLKAPLL
336 * MUX_DMC_BUS_SEL: SCLKMPLL ; SCLKAPLL
337 * MUX_DPHY_SEL: SCLKMPLL ; SCLKAPLL
338 * MUX_MPLL_SEL: FINPLL ; MOUT_MPLL_FOUT
339 * MUX_PWI_SEL: 0110 (MPLL); 0111 (EPLL); 1000 (VPLL); 0(XXTI)
340 * MUX_G2D_ACP0_SEL: SCLKMPLL ; SCLKAPLL
341 * MUX_G2D_ACP1_SEL: SCLKEPLL ; SCLKVPLL
342 * MUX_G2D_ACP_SEL: OUT_ACP0 ; OUT_ACP1
344 clr_src_dmc = MUX_C2C_SEL(0x1) | MUX_DMC_BUS_SEL(0x1) |
345 MUX_DPHY_SEL(0x1) | MUX_MPLL_SEL(0x1) |
346 MUX_PWI_SEL(0xf) | MUX_G2D_ACP0_SEL(0x1) |
347 MUX_G2D_ACP1_SEL(0x1) | MUX_G2D_ACP_SEL(0x1);
348 set = MUX_C2C_SEL(1) | MUX_DMC_BUS_SEL(1) | MUX_DPHY_SEL(1) |
349 MUX_MPLL_SEL(0) | MUX_PWI_SEL(0) | MUX_G2D_ACP0_SEL(1) |
350 MUX_G2D_ACP1_SEL(1) | MUX_G2D_ACP_SEL(1);
352 clrsetbits_le32(&clk->src_dmc, clr_src_dmc, set);
354 /* Wait for mux change */
355 while (readl(&clk->mux_stat_dmc) & MUX_STAT_DMC_CHANGING)
358 /* Set MPLL to 800MHz */
359 set = SDIV(0) | PDIV(3) | MDIV(100) | FSEL(0) | PLL_ENABLE(1);
361 clrsetbits_le32(&clk->mpll_con0, clr_pll_con0, set);
363 /* Wait for PLL to be locked */
364 while (!(readl(&clk->mpll_con0) & PLL_LOCKED_BIT))
367 /* Switch back CMU_DMC mux */
368 set = MUX_C2C_SEL(0) | MUX_DMC_BUS_SEL(0) | MUX_DPHY_SEL(0) |
369 MUX_MPLL_SEL(1) | MUX_PWI_SEL(8) | MUX_G2D_ACP0_SEL(0) |
370 MUX_G2D_ACP1_SEL(0) | MUX_G2D_ACP_SEL(0);
372 clrsetbits_le32(&clk->src_dmc, clr_src_dmc, set);
374 /* Wait for mux change */
375 while (readl(&clk->mux_stat_dmc) & MUX_STAT_DMC_CHANGING)
379 clr = ACP_RATIO(0x7) | ACP_PCLK_RATIO(0x7) | DPHY_RATIO(0x7) |
380 DMC_RATIO(0x7) | DMCD_RATIO(0x7) | DMCP_RATIO(0x7);
386 * aclk_acp = MOUTdmc / (ratio + 1) = 200 (3)
387 * pclk_acp = aclk_acp / (ratio + 1) = 100 (1)
388 * sclk_dphy = MOUTdphy / (ratio + 1) = 400 (1)
389 * sclk_dmc = MOUTdmc / (ratio + 1) = 400 (1)
390 * aclk_dmcd = sclk_dmc / (ratio + 1) = 200 (1)
391 * aclk_dmcp = aclk_dmcd / (ratio + 1) = 100 (1)
393 set = ACP_RATIO(3) | ACP_PCLK_RATIO(1) | DPHY_RATIO(1) |
394 DMC_RATIO(1) | DMCD_RATIO(1) | DMCP_RATIO(1);
396 clrsetbits_le32(&clk->div_dmc0, clr, set);
398 /* Wait for divider ready status */
399 while (readl(&clk->div_stat_dmc0) & DIV_STAT_DMC0_CHANGING)
403 clr = G2D_ACP_RATIO(0xf) | C2C_RATIO(0x7) | PWI_RATIO(0xf) |
404 C2C_ACLK_RATIO(0x7) | DVSEM_RATIO(0x7f) | DPM_RATIO(0x7f);
411 * sclk_g2d_acp = MOUTg2d / (ratio + 1) = 200 (3)
412 * sclk_c2c = MOUTc2c / (ratio + 1) = 400 (1)
413 * aclk_c2c = sclk_c2c / (ratio + 1) = 200 (1)
414 * sclk_pwi = MOUTpwi / (ratio + 1) = 18 (5)
416 set = G2D_ACP_RATIO(3) | C2C_RATIO(1) | PWI_RATIO(5) |
417 C2C_ACLK_RATIO(1) | DVSEM_RATIO(1) | DPM_RATIO(1);
419 clrsetbits_le32(&clk->div_dmc1, clr, set);
421 /* Wait for divider ready status */
422 while (readl(&clk->div_stat_dmc1) & DIV_STAT_DMC1_CHANGING)
426 clr = UART0_SEL(0xf) | UART1_SEL(0xf) | UART2_SEL(0xf) |
427 UART3_SEL(0xf) | UART4_SEL(0xf);
429 * Set CLK_SRC_PERIL0 clocks src to MPLL
430 * src values: 0(XXTI); 1(XusbXTI); 2(SCLK_HDMI24M); 3(SCLK_USBPHY0);
431 * 5(SCLK_HDMIPHY); 6(SCLK_MPLL_USER_T); 7(SCLK_EPLL);
434 * Set all to SCLK_MPLL_USER_T
436 set = UART0_SEL(6) | UART1_SEL(6) | UART2_SEL(6) | UART3_SEL(6) |
439 clrsetbits_le32(&clk->src_peril0, clr, set);
442 clr = UART0_RATIO(0xf) | UART1_RATIO(0xf) | UART2_RATIO(0xf) |
443 UART3_RATIO(0xf) | UART4_RATIO(0xf);
445 * For MOUTuart0-4: 800MHz
447 * SCLK_UARTx = MOUTuartX / (ratio + 1) = 100 (7)
449 set = UART0_RATIO(7) | UART1_RATIO(7) | UART2_RATIO(7) |
450 UART3_RATIO(7) | UART4_RATIO(7);
452 clrsetbits_le32(&clk->div_peril0, clr, set);
454 while (readl(&clk->div_stat_peril0) & DIV_STAT_PERIL0_CHANGING)
458 clr = MMC0_RATIO(0xf) | MMC0_PRE_RATIO(0xff) | MMC1_RATIO(0xf) |
459 MMC1_PRE_RATIO(0xff);
461 * For MOUTmmc0-3 = 800 MHz (MPLL)
463 * DOUTmmc1 = MOUTmmc1 / (ratio + 1) = 100 (7)
464 * sclk_mmc1 = DOUTmmc1 / (ratio + 1) = 50 (1)
465 * DOUTmmc0 = MOUTmmc0 / (ratio + 1) = 100 (7)
466 * sclk_mmc0 = DOUTmmc0 / (ratio + 1) = 50 (1)
468 set = MMC0_RATIO(7) | MMC0_PRE_RATIO(1) | MMC1_RATIO(7) |
471 clrsetbits_le32(&clk->div_fsys1, clr, set);
473 /* Wait for divider ready status */
474 while (readl(&clk->div_stat_fsys1) & DIV_STAT_FSYS1_CHANGING)
478 clr = MMC2_RATIO(0xf) | MMC2_PRE_RATIO(0xff) | MMC3_RATIO(0xf) |
479 MMC3_PRE_RATIO(0xff);
481 * For MOUTmmc0-3 = 800 MHz (MPLL)
483 * DOUTmmc3 = MOUTmmc3 / (ratio + 1) = 100 (7)
484 * sclk_mmc3 = DOUTmmc3 / (ratio + 1) = 50 (1)
485 * DOUTmmc2 = MOUTmmc2 / (ratio + 1) = 100 (7)
486 * sclk_mmc2 = DOUTmmc2 / (ratio + 1) = 50 (1)
488 set = MMC2_RATIO(7) | MMC2_PRE_RATIO(1) | MMC3_RATIO(7) |
491 clrsetbits_le32(&clk->div_fsys2, clr, set);
493 /* Wait for divider ready status */
494 while (readl(&clk->div_stat_fsys2) & DIV_STAT_FSYS2_CHANGING)
498 clr = MMC4_RATIO(0xf) | MMC4_PRE_RATIO(0xff);
500 * For MOUTmmc4 = 800 MHz (MPLL)
502 * DOUTmmc4 = MOUTmmc4 / (ratio + 1) = 100 (7)
503 * sclk_mmc4 = DOUTmmc4 / (ratio + 1) = 100 (0)
505 set = MMC4_RATIO(7) | MMC4_PRE_RATIO(0);
507 clrsetbits_le32(&clk->div_fsys3, clr, set);
509 /* Wait for divider ready status */
510 while (readl(&clk->div_stat_fsys3) & DIV_STAT_FSYS3_CHANGING)
516 static void board_gpio_init(void)
518 if (board_is_trats2()) {
520 gpio_set_pull(EXYNOS4X12_GPIO_X02, S5P_GPIO_PULL_NONE);
522 gpio_set_pull(EXYNOS4X12_GPIO_X04, S5P_GPIO_PULL_NONE);
524 gpio_set_pull(EXYNOS4X12_GPIO_X07, S5P_GPIO_PULL_NONE);
526 gpio_set_pull(EXYNOS4X12_GPIO_X15, S5P_GPIO_PULL_NONE);
528 gpio_set_pull(EXYNOS4X12_GPIO_X20, S5P_GPIO_PULL_NONE);
530 gpio_set_pull(EXYNOS4X12_GPIO_X21, S5P_GPIO_PULL_NONE);
532 gpio_set_pull(EXYNOS4X12_GPIO_X23, S5P_GPIO_PULL_NONE);
534 gpio_set_pull(EXYNOS4X12_GPIO_X24, S5P_GPIO_PULL_NONE);
536 gpio_set_pull(EXYNOS4X12_GPIO_X27, S5P_GPIO_PULL_NONE);
538 gpio_set_pull(EXYNOS4X12_GPIO_X30, S5P_GPIO_PULL_NONE);
540 gpio_set_pull(EXYNOS4X12_GPIO_X35, S5P_GPIO_PULL_NONE);
542 gpio_set_pull(EXYNOS4X12_GPIO_X37, S5P_GPIO_PULL_NONE);
545 gpio_cfg_pin(EXYNOS4X12_GPIO_K12, S5P_GPIO_FUNC(0x1));
546 gpio_set_pull(EXYNOS4X12_GPIO_K12, S5P_GPIO_PULL_NONE);
547 gpio_set_drv(EXYNOS4X12_GPIO_K12, S5P_GPIO_DRV_4X);
549 /* Enable FAN (Odroid U3) */
550 gpio_set_pull(EXYNOS4X12_GPIO_D00, S5P_GPIO_PULL_UP);
551 gpio_set_drv(EXYNOS4X12_GPIO_D00, S5P_GPIO_DRV_4X);
552 gpio_direction_output(EXYNOS4X12_GPIO_D00, 1);
554 /* OTG Vbus output (Odroid U3+) */
555 gpio_set_pull(EXYNOS4X12_GPIO_L20, S5P_GPIO_PULL_NONE);
556 gpio_set_drv(EXYNOS4X12_GPIO_L20, S5P_GPIO_DRV_4X);
557 gpio_direction_output(EXYNOS4X12_GPIO_L20, 0);
559 /* OTG INT (Odroid U3+) */
560 gpio_set_pull(EXYNOS4X12_GPIO_X31, S5P_GPIO_PULL_UP);
561 gpio_set_drv(EXYNOS4X12_GPIO_X31, S5P_GPIO_DRV_4X);
562 gpio_direction_input(EXYNOS4X12_GPIO_X31);
566 static int pmic_init_max77686(void)
568 struct pmic *p = pmic_get("MAX77686_PMIC");
573 if (board_is_trats2()) {
574 /* BUCK/LDO Output Voltage */
575 max77686_set_ldo_voltage(p, 21, 2800000); /* LDO21 VTF_2.8V */
576 max77686_set_ldo_voltage(p, 23, 3300000); /* LDO23 TSP_AVDD_3.3V*/
577 max77686_set_ldo_voltage(p, 24, 1800000); /* LDO24 TSP_VDD_1.8V */
579 /* BUCK/LDO Output Mode */
580 max77686_set_buck_mode(p, 1, OPMODE_STANDBY); /* BUCK1 VMIF_1.1V_AP */
581 max77686_set_buck_mode(p, 2, OPMODE_ON); /* BUCK2 VARM_1.0V_AP */
582 max77686_set_buck_mode(p, 3, OPMODE_ON); /* BUCK3 VINT_1.0V_AP */
583 max77686_set_buck_mode(p, 4, OPMODE_ON); /* BUCK4 VG3D_1.0V_AP */
584 max77686_set_buck_mode(p, 5, OPMODE_ON); /* BUCK5 VMEM_1.2V_AP */
585 max77686_set_buck_mode(p, 6, OPMODE_ON); /* BUCK6 VCC_SUB_1.35V*/
586 max77686_set_buck_mode(p, 7, OPMODE_ON); /* BUCK7 VCC_SUB_2.0V */
587 max77686_set_buck_mode(p, 8, OPMODE_OFF); /* VMEM_VDDF_2.85V */
588 max77686_set_buck_mode(p, 9, OPMODE_OFF); /* CAM_ISP_CORE_1.2V*/
590 max77686_set_ldo_mode(p, 1, OPMODE_LPM); /* LDO1 VALIVE_1.0V_AP*/
591 max77686_set_ldo_mode(p, 2, OPMODE_STANDBY); /* LDO2 VM1M2_1.2V_AP */
592 max77686_set_ldo_mode(p, 3, OPMODE_LPM); /* LDO3 VCC_1.8V_AP */
593 max77686_set_ldo_mode(p, 4, OPMODE_LPM); /* LDO4 VCC_2.8V_AP */
594 max77686_set_ldo_mode(p, 5, OPMODE_OFF); /* LDO5_VCC_1.8V_IO */
595 max77686_set_ldo_mode(p, 6, OPMODE_STANDBY); /* LDO6 VMPLL_1.0V_AP */
596 max77686_set_ldo_mode(p, 7, OPMODE_STANDBY); /* LDO7 VPLL_1.0V_AP */
597 max77686_set_ldo_mode(p, 8, OPMODE_LPM); /* LDO8 VMIPI_1.0V_AP */
598 max77686_set_ldo_mode(p, 9, OPMODE_OFF); /* CAM_ISP_MIPI_1.2*/
599 max77686_set_ldo_mode(p, 10, OPMODE_LPM); /* LDO10 VMIPI_1.8V_AP*/
600 max77686_set_ldo_mode(p, 11, OPMODE_STANDBY); /* LDO11 VABB1_1.8V_AP*/
601 max77686_set_ldo_mode(p, 12, OPMODE_LPM); /* LDO12 VUOTG_3.0V_AP*/
602 max77686_set_ldo_mode(p, 13, OPMODE_OFF); /* LDO13 VC2C_1.8V_AP */
603 max77686_set_ldo_mode(p, 14, OPMODE_STANDBY); /* VABB02_1.8V_AP */
604 max77686_set_ldo_mode(p, 15, OPMODE_STANDBY); /* LDO15 VHSIC_1.0V_AP*/
605 max77686_set_ldo_mode(p, 16, OPMODE_STANDBY); /* LDO16 VHSIC_1.8V_AP*/
606 max77686_set_ldo_mode(p, 17, OPMODE_OFF); /* CAM_SENSOR_CORE_1.2*/
607 max77686_set_ldo_mode(p, 18, OPMODE_OFF); /* CAM_ISP_SEN_IO_1.8V*/
608 max77686_set_ldo_mode(p, 19, OPMODE_OFF); /* LDO19 VT_CAM_1.8V */
609 max77686_set_ldo_mode(p, 20, OPMODE_ON); /* LDO20 VDDQ_PRE_1.8V*/
610 max77686_set_ldo_mode(p, 21, OPMODE_OFF); /* LDO21 VTF_2.8V */
611 max77686_set_ldo_mode(p, 22, OPMODE_OFF); /* LDO22 VMEM_VDD_2.8V*/
612 max77686_set_ldo_mode(p, 23, OPMODE_OFF); /* LDO23 TSP_AVDD_3.3V*/
613 max77686_set_ldo_mode(p, 24, OPMODE_OFF); /* LDO24 TSP_VDD_1.8V */
614 max77686_set_ldo_mode(p, 25, OPMODE_OFF); /* LDO25 VCC_3.3V_LCD */
615 max77686_set_ldo_mode(p, 26, OPMODE_OFF); /*LDO26 VCC_3.0V_MOTOR*/
617 /* Set LDO Voltage */
618 max77686_set_ldo_voltage(p, 20, 1800000); /* LDO20 eMMC */
619 max77686_set_ldo_voltage(p, 21, 2800000); /* LDO21 SD */
620 max77686_set_ldo_voltage(p, 22, 2800000); /* LDO22 eMMC */
626 #ifdef CONFIG_SYS_I2C_INIT_BOARD
627 static void board_init_i2c(void)
631 if (board_is_trats2()) {
632 i2c_id = PERIPH_ID_I2C7;
635 gpio_direction_output(EXYNOS4X12_GPIO_F14, 1);
636 gpio_direction_output(EXYNOS4X12_GPIO_F15, 1);
639 gpio_direction_output(EXYNOS4X12_GPIO_M21, 1);
640 gpio_direction_output(EXYNOS4X12_GPIO_M20, 1);
642 i2c_id = PERIPH_ID_I2C0;
645 if (exynos_pinmux_config(i2c_id, PINMUX_FLAG_NONE))
646 debug("I2C%d not configured\n", i2c_id - PERIPH_ID_I2C0);
650 #ifdef CONFIG_SYS_I2C_SOFT
651 int get_soft_i2c_scl_pin(void)
654 return EXYNOS4X12_GPIO_M21; /* I2C9 */
656 return EXYNOS4X12_GPIO_F14; /* I2C8 */
659 int get_soft_i2c_sda_pin(void)
662 return EXYNOS4X12_GPIO_M20; /* I2C9 */
664 return EXYNOS4X12_GPIO_F15; /* I2C8 */
668 int exynos_early_init_f(void)
676 int exynos_init(void)
678 struct exynos4_power *pwr =
679 (struct exynos4_power *)samsung_get_base_power();
681 gd->bd->bi_arch_number = board_arch_num[gd->board_type];
683 if (!board_is_trats2())
686 writel(0, &pwr->inform4);
687 writel(0, &pwr->inform5);
692 int exynos_power_init(void)
694 #ifdef CONFIG_SYS_I2C_INIT_BOARD
697 /* bus number taken from FDT */
699 pmic_init_max77686();
701 if (!board_is_trats2())
704 /* I2C adapter 10 - bus name soft1 */
705 pmic_init_max77693(I2C_10);
706 /* I2C adapter 10 - bus name soft1 */
707 power_muic_init(I2C_10);
708 /* I2C adapter 9 - bus name soft0 */
709 power_fg_init(I2C_9);
712 p_chrg = pmic_get("MAX77693_PMIC");
714 puts("MAX77693_PMIC: Not found\n");
718 p_muic = pmic_get("MAX77693_MUIC");
720 puts("MAX77693_MUIC: Not found\n");
724 p_fg = pmic_get("MAX77693_FG");
726 puts("MAX17042_FG: Not found\n");
730 if (p_chrg->chrg->chrg_bat_present(p_chrg) == 0)
731 puts("No battery detected\n");
733 p_bat = pmic_get("BAT_TRATS2");
735 puts("BAT_TRATS2: Not found\n");
739 p_fg->parent = p_bat;
740 p_chrg->parent = p_bat;
741 p_muic->parent = p_bat;
743 #ifdef CONFIG_INTERACTIVE_CHARGER
744 p_bat->low_power_mode = board_low_power_mode;
746 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
756 #ifdef CONFIG_USB_GADGET
757 static int s5pc210_phy_control(int on)
761 p_pmic = pmic_get("MAX77686_PMIC");
765 if (pmic_probe(p_pmic))
769 return max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
771 return max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
774 struct s3c_plat_otg_data s5pc210_otg_data = {
775 .phy_control = s5pc210_phy_control,
776 .regs_phy = EXYNOS4X12_USBPHY_BASE,
777 .regs_otg = EXYNOS4X12_USBOTG_BASE,
778 .usb_phy_ctrl = EXYNOS4X12_USBPHY_CONTROL,
779 .usb_flags = PHY0_SLEEP,
782 int board_usb_init(int index, enum usb_init_type init)
784 debug("USB_udc_probe\n");
785 return s3c_udc_probe(&s5pc210_otg_data);
789 void reset_misc(void)
791 if (board_is_trats2())
795 gpio_set_value(EXYNOS4X12_GPIO_K12, 0);
797 gpio_set_value(EXYNOS4X12_GPIO_K12, 1);
808 if (!board_is_trats2())
811 p = pmic_get("MAX77686_PMIC");
813 /* LDO8 VMIPI_1.0V_AP */
814 max77686_set_ldo_mode(p, 8, OPMODE_ON);
815 /* LDO10 VMIPI_1.8V_AP */
816 max77686_set_ldo_mode(p, 10, OPMODE_ON);
821 void exynos_lcd_power_on(void)
825 if (!board_is_trats2())
828 p = pmic_get("MAX77686_PMIC");
830 /* LCD_2.2V_EN: GPC0[1] */
831 gpio_set_pull(EXYNOS4X12_GPIO_C01, S5P_GPIO_PULL_UP);
832 gpio_direction_output(EXYNOS4X12_GPIO_C01, 1);
834 /* LDO25 VCC_3.1V_LCD */
836 max77686_set_ldo_voltage(p, 25, 3100000);
837 max77686_set_ldo_mode(p, 25, OPMODE_LPM);
840 void exynos_reset_lcd(void)
842 if (!board_is_trats2())
846 gpio_direction_output(EXYNOS4X12_GPIO_F21, 0);
848 gpio_set_value(EXYNOS4X12_GPIO_F21, 1);
851 void exynos_lcd_misc_init(vidinfo_t *vid)
853 if (!board_is_trats2())
856 get_tizen_logo_info(vid);
858 #ifdef CONFIG_S6E8AX0
864 void low_clock_mode(void)
866 struct exynos4x12_clock *clk = (struct exynos4x12_clock *)
867 samsung_get_base_clock();
869 unsigned int cfg_apll_con0;
870 unsigned int cfg_src_cpu;
871 unsigned int cfg_div_cpu0;
872 unsigned int cfg_div_cpu1;
873 unsigned int clk_gate_cfg;
875 /* Turn off unnecessary clocks */
877 writel(clk_gate_cfg, &clk->gate_ip_image); /* IMAGE */
878 writel(clk_gate_cfg, &clk->gate_ip_cam); /* CAM */
879 writel(clk_gate_cfg, &clk->gate_ip_tv); /* TV */
880 writel(clk_gate_cfg, &clk->gate_ip_mfc); /* MFC */
881 writel(clk_gate_cfg, &clk->gate_ip_g3d); /* G3D */
882 writel(clk_gate_cfg, &clk->gate_ip_gps); /* GPS */
883 writel(clk_gate_cfg, &clk->gate_ip_isp1); /* ISP1 */
886 * Set CMU_CPU clocks src to MPLL
888 * MUX_APLL_SEL: FIN_PLL; FOUT_APLL
889 * MUX_CORE_SEL: MOUT_APLL; SCLK_MPLL
890 * MUX_HPM_SEL: MOUT_APLL; SCLK_MPLL_USER_C
891 * MUX_MPLL_USER_SEL_C: FIN_PLL; SCLK_MPLL
893 cfg_src_cpu = MUX_APLL_SEL(1) | MUX_CORE_SEL(1) | MUX_HPM_SEL(1) |
894 MUX_MPLL_USER_SEL_C(1);
895 writel(cfg_src_cpu, &clk->src_cpu);
898 cfg_apll_con0 = readl(&clk->apll_con0);
899 writel(cfg_apll_con0 & ~PLL_ENABLE(1), &clk->apll_con0);
901 /* Set APLL to 200MHz */
902 cfg_apll_con0 = SDIV(2) | PDIV(3) | MDIV(100) | FSEL(1) | PLL_ENABLE(1);
903 writel(cfg_apll_con0, &clk->apll_con0);
905 /* Wait for PLL to be locked */
906 while (!(readl(&clk->apll_con0) & PLL_LOCKED_BIT))
909 /* Set CMU_CPU clock src to APLL */
910 cfg_src_cpu = MUX_APLL_SEL(1) | MUX_CORE_SEL(0) | MUX_HPM_SEL(0) |
911 MUX_MPLL_USER_SEL_C(0);
912 writel(cfg_src_cpu, &clk->src_cpu);
914 /* Wait for MUX ready status */
915 while (readl(&clk->src_cpu) & MUX_STAT_CPU_CHANGING)
919 * Set dividers for MOUTcore = 200 MHz
920 * coreout = MOUT / (ratio + 1) = 200 MHz
921 * corem0 = armclk / (ratio + 1) = 200 MHz
922 * corem1 = armclk / (ratio + 1) = 200 MHz
923 * periph = armclk / (ratio + 1) = 200 MHz
924 * atbout = MOUT / (ratio + 1) = 200 MHz
925 * pclkdbgout = atbout / (ratio + 1) = 200 MHz
926 * sclkapll = MOUTapll / (ratio + 1) = 50 MHz
927 * armclk = core_out / (ratio + 1) = 200 MHz
929 cfg_div_cpu0 = CORE_RATIO(0) | COREM0_RATIO(0) | COREM1_RATIO(0) |
930 PERIPH_RATIO(0) | ATB_RATIO(0) | PCLK_DBG_RATIO(1) |
931 APLL_RATIO(3) | CORE2_RATIO(0);
932 writel(cfg_div_cpu0, &clk->div_cpu0);
934 /* Wait for divider ready status */
935 while (readl(&clk->div_stat_cpu0) & DIV_STAT_CPU0_CHANGING)
939 * For MOUThpm = 200 MHz (MOUTapll)
940 * doutcopy = MOUThpm / (ratio + 1) = 100
941 * sclkhpm = doutcopy / (ratio + 1) = 100
942 * cores_out = armclk / (ratio + 1) = 200
944 cfg_div_cpu1 = COPY_RATIO(1) | HPM_RATIO(0) | CORES_RATIO(0);
945 writel(cfg_div_cpu1, &clk->div_cpu1); /* DIV_CPU1 */
947 /* Wait for divider ready status */
948 while (readl(&clk->div_stat_cpu1) & DIV_STAT_CPU1_CHANGING)
952 #ifdef CONFIG_INTERACTIVE_CHARGER
953 static int low_power_mode_set;
955 void board_low_power_mode(void)
957 struct exynos4x12_power *pwr = (struct exynos4x12_power *)
958 samsung_get_base_power();
960 unsigned int pwr_core_cfg = 0x0;
961 unsigned int pwr_cfg = 0x0;
963 /* Set low power mode only once */
964 if (low_power_mode_set)
967 /* Power down CORES: 1, 2, 3 */
968 /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
969 writel(pwr_core_cfg, &pwr->arm_core1_configuration);
970 writel(pwr_core_cfg, &pwr->arm_core2_configuration);
971 writel(pwr_core_cfg, &pwr->arm_core3_configuration);
973 /* Turn off unnecessary power domains */
974 writel(pwr_cfg, &pwr->xxti_configuration); /* XXTI */
975 writel(pwr_cfg, &pwr->cam_configuration); /* CAM */
976 writel(pwr_cfg, &pwr->tv_configuration); /* TV */
977 writel(pwr_cfg, &pwr->mfc_configuration); /* MFC */
978 writel(pwr_cfg, &pwr->g3d_configuration); /* G3D */
979 writel(pwr_cfg, &pwr->gps_configuration); /* GPS */
980 writel(pwr_cfg, &pwr->gps_alive_configuration); /* GPS_ALIVE */
982 /* Set CPU clock to 200MHz */
985 low_power_mode_set = 1;
989 #ifdef CONFIG_CMD_POWEROFF
990 void board_poweroff(void)
993 struct exynos4x12_power *power =
994 (struct exynos4x12_power *)samsung_get_base_power();
996 val = readl(&power->ps_hold_control);
997 val |= EXYNOS_PS_HOLD_CONTROL_EN_OUTPUT; /* set to output */
998 val &= ~EXYNOS_PS_HOLD_CONTROL_DATA_HIGH; /* set state to low */
999 writel(val, &power->ps_hold_control);
1002 /* Should not reach here */
1006 /* Functions for interactive charger in board/samsung/common/misc.c */
1007 #ifdef CONFIG_INTERACTIVE_CHARGER
1008 int charger_enable(void)
1010 if (!power_init_done) {
1011 if (exynos_power_init()) {
1012 puts("Can't init board power subsystem");
1018 puts("No such device!\n");
1022 if (!pbat->battery_charge) {
1023 puts("Can't enable charger\n");
1027 /* Enable charger */
1028 if (pbat->battery_charge(p_bat)) {
1029 puts("Charger enable error\n");
1036 int charger_type(void)
1038 if (!power_init_done) {
1039 if (exynos_power_init()) {
1040 puts("Can't init board power subsystem");
1046 puts("No such device!\n");
1050 if (!p_muic->chrg->chrg_type) {
1051 puts("Can't get charger type\n");
1055 return p_muic->chrg->chrg_type(p_muic);
1058 int battery_present(void)
1060 if (!power_init_done) {
1061 if (exynos_power_init()) {
1062 puts("Can't init board power subsystem");
1068 puts("No such device!\n");
1072 if (!p_chrg->chrg->chrg_bat_present) {
1073 puts("Can't get battery state\n");
1077 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
1078 puts("Battery not present.\n");
1085 int battery_state(unsigned int *soc)
1087 struct battery *bat = pbat->bat;
1089 if (!power_init_done) {
1090 if (exynos_power_init()) {
1091 printf("Can't init board power subsystem");
1097 puts("No such device!\n");
1101 if (!p_fg->fg->fg_battery_update) {
1102 puts("Can't update battery state\n");
1106 /* Check battery state */
1107 if (p_fg->fg->fg_battery_update(p_fg, p_bat)) {
1108 puts("Battery update error\n");
1112 debug("[BAT]:\n#state:%u\n#soc:%3.1u\n#vcell:%u\n", bat->state,
1116 *soc = bat->state_of_chrg;