1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2011 Samsung Electronics
4 * Heungjun Kim <riverful.kim@samsung.com>
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Donghwa Lee <dh09.lee@samsung.com>
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/pinmux.h>
17 #include <asm/arch/clock.h>
18 #include <asm/arch/mipi_dsim.h>
19 #include <asm/arch/watchdog.h>
20 #include <asm/arch/power.h>
21 #include <power/pmic.h>
22 #include <usb/dwc2_udc.h>
23 #include <power/max8997_pmic.h>
24 #include <power/max8997_muic.h>
25 #include <power/battery.h>
26 #include <power/max17042_fg.h>
27 #include <power/pmic.h>
30 #include <usb_mass_storage.h>
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 dwc2_plat_otg_data s5pc210_otg_data;
49 printf("HW Revision:\t0x%x\n", board_rev);
54 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
55 static void trats_low_power_mode(void)
57 struct exynos4_clock *clk =
58 (struct exynos4_clock *)samsung_get_base_clock();
59 struct exynos4_power *pwr =
60 (struct exynos4_power *)samsung_get_base_power();
62 /* Power down CORE1 */
63 /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
64 writel(0x0, &pwr->arm_core1_configuration);
66 /* Change the APLL frequency */
67 /* ENABLE (1 enable) | LOCKED (1 locked) */
69 /* FSEL | MDIV | PDIV | SDIV */
70 /* [27] | [25:16] | [13:8] | [2:0] */
71 writel(0xa0c80604, &clk->apll_con0);
73 /* Change CPU0 clock divider */
74 /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */
75 /* [30:28] | [26:24] | [22:20] | [18:16] */
76 /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */
77 /* [14:12] | [10:8] | [6:4] | [2:0] */
78 writel(0x00000100, &clk->div_cpu0);
80 /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
81 while (readl(&clk->div_stat_cpu0) & 0x1111111)
84 /* Change clock divider ratio for DMC */
85 /* DMCP_RATIO | DMCD_RATIO */
86 /* [22:20] | [18:16] */
87 /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */
88 /* [14:12] | [10:8] | [6:4] | [2:0] */
89 writel(0x13113117, &clk->div_dmc0);
91 /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
92 while (readl(&clk->div_stat_dmc0) & 0x11111111)
95 /* Turn off unnecessary power domains */
96 writel(0x0, &pwr->xxti_configuration); /* XXTI */
97 writel(0x0, &pwr->cam_configuration); /* CAM */
98 writel(0x0, &pwr->tv_configuration); /* TV */
99 writel(0x0, &pwr->mfc_configuration); /* MFC */
100 writel(0x0, &pwr->g3d_configuration); /* G3D */
101 writel(0x0, &pwr->gps_configuration); /* GPS */
102 writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */
104 /* Turn off unnecessary clocks */
105 writel(0x0, &clk->gate_ip_cam); /* CAM */
106 writel(0x0, &clk->gate_ip_tv); /* TV */
107 writel(0x0, &clk->gate_ip_mfc); /* MFC */
108 writel(0x0, &clk->gate_ip_g3d); /* G3D */
109 writel(0x0, &clk->gate_ip_image); /* IMAGE */
110 writel(0x0, &clk->gate_ip_gps); /* GPS */
114 int exynos_power_init(void)
116 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
118 struct power_battery *pb;
119 struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
122 * For PMIC/MUIC the I2C bus is named as I2C5, but it is connected
123 * to logical I2C adapter 0
125 * The FUEL_GAUGE is marked as I2C9 on the schematic, but connected
126 * to logical I2C adapter 1
128 ret = power_fg_init(I2C_9);
129 ret |= power_muic_init(I2C_5);
130 ret |= power_bat_init(0);
134 p_fg = pmic_get("MAX17042_FG");
136 puts("MAX17042_FG: Not found\n");
140 p_chrg = pmic_get("MAX8997_PMIC");
142 puts("MAX8997_PMIC: Not found\n");
146 p_muic = pmic_get("MAX8997_MUIC");
148 puts("MAX8997_MUIC: Not found\n");
152 p_bat = pmic_get("BAT_TRATS");
154 puts("BAT_TRATS: Not found\n");
158 p_fg->parent = p_bat;
159 p_chrg->parent = p_bat;
160 p_muic->parent = p_bat;
162 p_bat->low_power_mode = trats_low_power_mode;
163 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
166 chrg = p_muic->chrg->chrg_type(p_muic);
167 debug("CHARGER TYPE: %d\n", chrg);
169 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
170 puts("No battery detected\n");
174 p_fg->fg->fg_battery_check(p_fg, p_bat);
176 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
177 puts("CHARGE Battery !\n");
183 static unsigned int get_hw_revision(void)
189 /* hw_rev[3:0] == GPE1[3:0] */
190 for (i = 0; i < 4; i++) {
191 int pin = i + EXYNOS4_GPIO_E10;
193 sprintf(str, "hw_rev%d", i);
194 gpio_request(pin, str);
195 gpio_cfg_pin(pin, S5P_GPIO_INPUT);
196 gpio_set_pull(pin, S5P_GPIO_PULL_NONE);
201 for (i = 0; i < 4; i++)
202 hwrev |= (gpio_get_value(EXYNOS4_GPIO_E10 + i) << i);
204 debug("hwrev 0x%x\n", hwrev);
209 static void check_hw_revision(void)
213 hwrev = get_hw_revision();
219 #ifdef CONFIG_USB_GADGET
220 static int s5pc210_phy_control(int on)
225 ret = pmic_get("max8997-pmic", &dev);
230 reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
232 ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
234 puts("MAX8997 setting error!\n");
237 reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
239 ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
241 puts("MAX8997 setting error!\n");
244 reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
246 ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
248 puts("MAX8997 setting error!\n");
252 reg = pmic_reg_read(dev, MAX8997_REG_LDO8CTRL);
254 ret = pmic_reg_write(dev, MAX8997_REG_LDO8CTRL, reg);
256 puts("MAX8997 setting error!\n");
259 reg = pmic_reg_read(dev, MAX8997_REG_LDO3CTRL);
261 ret = pmic_reg_write(dev, MAX8997_REG_LDO3CTRL, reg);
263 puts("MAX8997 setting error!\n");
266 reg = pmic_reg_read(dev, MAX8997_REG_SAFEOUTCTRL);
268 ret = pmic_reg_write(dev, MAX8997_REG_SAFEOUTCTRL, reg);
270 puts("MAX8997 setting error!\n");
279 struct dwc2_plat_otg_data s5pc210_otg_data = {
280 .phy_control = s5pc210_phy_control,
281 .regs_phy = EXYNOS4_USBPHY_BASE,
282 .regs_otg = EXYNOS4_USBOTG_BASE,
283 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
284 .usb_flags = PHY0_SLEEP,
287 int board_usb_init(int index, enum usb_init_type init)
289 debug("USB_udc_probe\n");
290 return dwc2_udc_probe(&s5pc210_otg_data);
293 int g_dnl_board_usb_cable_connected(void)
295 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
296 struct pmic *muic = pmic_get("MAX8997_MUIC");
300 return !!muic->chrg->chrg_type(muic);
308 static void pmic_reset(void)
310 gpio_direction_output(EXYNOS4_GPIO_X07, 1);
311 gpio_set_pull(EXYNOS4_GPIO_X27, S5P_GPIO_PULL_NONE);
314 static void board_clock_init(void)
316 struct exynos4_clock *clk =
317 (struct exynos4_clock *)samsung_get_base_clock();
319 writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
320 writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
321 writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
322 writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
324 writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
325 writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
326 writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
327 writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
328 writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
329 writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
330 writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
331 writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
332 writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
333 writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
334 writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
335 writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
337 writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
338 writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
339 writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
340 writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
341 writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
342 writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
343 writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
344 writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
345 writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
346 writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
347 writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
348 writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
350 writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
351 writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
352 writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
353 writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
354 writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
355 writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
356 writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
357 writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
358 writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
359 writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
360 writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
361 writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
364 static void board_power_init(void)
366 struct exynos4_power *pwr =
367 (struct exynos4_power *)samsung_get_base_power();
370 writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
373 writel(0, (unsigned int)&pwr->cam_configuration);
374 writel(0, (unsigned int)&pwr->tv_configuration);
375 writel(0, (unsigned int)&pwr->mfc_configuration);
376 writel(0, (unsigned int)&pwr->g3d_configuration);
377 writel(0, (unsigned int)&pwr->lcd1_configuration);
378 writel(0, (unsigned int)&pwr->gps_configuration);
379 writel(0, (unsigned int)&pwr->gps_alive_configuration);
381 /* It is necessary to power down core 1 */
382 /* to successfully boot CPU1 in kernel */
383 writel(0, (unsigned int)&pwr->arm_core1_configuration);
386 static void exynos_uart_init(void)
388 /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
389 gpio_request(EXYNOS4_GPIO_Y47, "uart_sel");
390 gpio_set_pull(EXYNOS4_GPIO_Y47, S5P_GPIO_PULL_UP);
391 gpio_direction_output(EXYNOS4_GPIO_Y47, 1);
394 int exynos_early_init_f(void)
405 void exynos_reset_lcd(void)
407 gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset");
408 gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
410 gpio_direction_output(EXYNOS4_GPIO_Y45, 0);
412 gpio_direction_output(EXYNOS4_GPIO_Y45, 1);
417 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
419 struct pmic *p = pmic_get("MAX8997_PMIC");
426 /* LDO15 voltage: 2.2v */
427 ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO);
428 /* LDO13 voltage: 3.0v */
429 ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO);
432 puts("MAX8997 LDO setting error!\n");
441 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
443 struct pmic *p = pmic_get("MAX8997_PMIC");
450 /* LDO3 voltage: 1.1v */
451 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO);
452 /* LDO4 voltage: 1.8v */
453 ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO);
456 puts("MAX8997 LDO setting error!\n");
464 void exynos_lcd_misc_init(vidinfo_t *vid)
467 get_tizen_logo_info(vid);
469 #ifdef CONFIG_S6E8AX0
471 env_set("lcdinfo", "lcd=s6e8ax0");