2 * Copyright (C) 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
6 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/arch/adc.h>
15 #include <asm/arch/pinmux.h>
16 #include <asm/arch/watchdog.h>
18 #include <power/pmic.h>
20 #include <usb/dwc2_udc.h>
21 #include <asm/arch/cpu.h>
22 #include <power/max8998_pmic.h>
24 #include <samsung/misc.h>
25 #include <usb_mass_storage.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 unsigned int board_rev;
30 static int init_pmic_lcd(void);
32 u32 get_board_rev(void)
37 int exynos_power_init(void)
39 return init_pmic_lcd();
42 static int get_hwrev(void)
44 return board_rev & 0xFF;
47 static unsigned short get_adc_value(int channel)
49 struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
50 unsigned short ret = 0;
52 unsigned int loop = 0;
54 writel(channel & 0xF, &adc->adcmux);
55 writel((1 << 14) | (49 << 6), &adc->adccon);
56 writel(1000 & 0xffff, &adc->adcdly);
57 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
59 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
64 reg = readl(&adc->adccon);
65 } while (!(reg & (1 << 15)) && (loop++ < 1000));
67 ret = readl(&adc->adcdat0) & 0xFFF;
72 static int adc_power_control(int on)
78 ret = pmic_get("max8998-pmic", &dev);
80 puts("Failed to get MAX8998!\n");
84 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
90 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
92 puts("MAX8998 LDO setting error\n");
99 static unsigned int get_hw_revision(void)
101 int hwrev, mode0, mode1;
103 adc_power_control(1);
105 mode0 = get_adc_value(1); /* HWREV_MODE0 */
106 mode1 = get_adc_value(2); /* HWREV_MODE1 */
109 * XXX Always set the default hwrev as the latest board
110 * ADC = (voltage) / 3.3 * 4096
114 #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
115 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
116 hwrev = 0x0; /* 0.01V 0.01V */
117 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
118 hwrev = 0x1; /* 610mV 0.01V */
119 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
120 hwrev = 0x2; /* 1.16V 0.01V */
121 if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
122 hwrev = 0x3; /* 1.79V 0.01V */
125 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
127 adc_power_control(0);
132 static void check_hw_revision(void)
136 hwrev = get_hw_revision();
141 #ifdef CONFIG_USB_GADGET
142 static int s5pc210_phy_control(int on)
148 ret = pmic_get("max8998-pmic", &dev);
150 puts("Failed to get MAX8998!\n");
155 reg = pmic_reg_read(dev, MAX8998_REG_BUCK_ACTIVE_DISCHARGE3);
156 reg |= MAX8998_SAFEOUT1;
157 ret |= pmic_reg_write(dev,
158 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3, reg);
160 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
162 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
164 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
166 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
169 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
170 reg &= ~MAX8998_LDO8;
171 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
173 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
174 reg &= ~MAX8998_LDO3;
175 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
177 reg = pmic_reg_read(dev, MAX8998_REG_BUCK_ACTIVE_DISCHARGE3);
178 reg &= ~MAX8998_SAFEOUT1;
179 ret |= pmic_reg_write(dev,
180 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3, reg);
184 puts("MAX8998 LDO setting error!\n");
191 struct dwc2_plat_otg_data s5pc210_otg_data = {
192 .phy_control = s5pc210_phy_control,
193 .regs_phy = EXYNOS4_USBPHY_BASE,
194 .regs_otg = EXYNOS4_USBOTG_BASE,
195 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
196 .usb_flags = PHY0_SLEEP,
200 int board_usb_init(int index, enum usb_init_type init)
202 debug("USB_udc_probe\n");
203 return dwc2_udc_probe(&s5pc210_otg_data);
206 int exynos_early_init_f(void)
213 static int init_pmic_lcd(void)
219 ret = pmic_get("max8998-pmic", &dev);
221 puts("Failed to get MAX8998 for init_pmic_lcd()!\n");
226 val = 0x02; /* (1800 - 1600) / 100; */
227 ret |= pmic_reg_write(dev, MAX8998_REG_LDO7, val);
230 val = 0xe; /* (3000 - 1600) / 100; */
231 ret |= pmic_reg_write(dev, MAX8998_REG_LDO17, val);
233 /* Disable unneeded regulators */
236 * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
237 * LDO2 ON, LDO3 OFF, LDO4 OFF, LDO5 ON
240 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF1, val);
243 * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
244 * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
247 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF2, val);
250 * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 OFF
251 * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
254 ret |= pmic_reg_write(dev, MAX8998_REG_ONOFF3, val);
257 puts("LCD pmic initialisation error!\n");
264 void exynos_cfg_lcd_gpio(void)
266 unsigned int i, f3_end = 4;
268 for (i = 0; i < 8; i++) {
269 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
270 gpio_cfg_pin(EXYNOS4_GPIO_F00 + i, S5P_GPIO_FUNC(2));
271 gpio_cfg_pin(EXYNOS4_GPIO_F10 + i, S5P_GPIO_FUNC(2));
272 gpio_cfg_pin(EXYNOS4_GPIO_F20 + i, S5P_GPIO_FUNC(2));
273 /* pull-up/down disable */
274 gpio_set_pull(EXYNOS4_GPIO_F00 + i, S5P_GPIO_PULL_NONE);
275 gpio_set_pull(EXYNOS4_GPIO_F10 + i, S5P_GPIO_PULL_NONE);
276 gpio_set_pull(EXYNOS4_GPIO_F20 + i, S5P_GPIO_PULL_NONE);
278 /* drive strength to max (24bit) */
279 gpio_set_drv(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_4X);
280 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
281 gpio_set_drv(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_4X);
282 gpio_set_rate(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_SLOW);
283 gpio_set_drv(EXYNOS4_GPIO_F20 + i, S5P_GPIO_DRV_4X);
284 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
287 for (i = EXYNOS4_GPIO_F30; i < (EXYNOS4_GPIO_F30 + f3_end); i++) {
288 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
289 gpio_cfg_pin(i, S5P_GPIO_FUNC(2));
290 /* pull-up/down disable */
291 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
292 /* drive strength to max (24bit) */
293 gpio_set_drv(i, S5P_GPIO_DRV_4X);
294 gpio_set_rate(i, S5P_GPIO_DRV_SLOW);
297 /* gpio pad configuration for LCD reset. */
298 gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset");
299 gpio_cfg_pin(EXYNOS4_GPIO_Y45, S5P_GPIO_OUTPUT);
307 void exynos_reset_lcd(void)
309 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
311 gpio_set_value(EXYNOS4_GPIO_Y45, 0);
313 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
317 void exynos_lcd_power_on(void)
323 ret = pmic_get("max8998-pmic", &dev);
325 puts("Failed to get MAX8998!\n");
329 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF3);
330 reg |= MAX8998_LDO17;
331 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF3, reg);
333 puts("MAX8998 LDO setting error\n");
337 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
339 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
341 puts("MAX8998 LDO setting error\n");
346 void exynos_cfg_ldo(void)
351 void exynos_enable_ldo(unsigned int onoff)
353 ld9040_enable_ldo(onoff);
356 int exynos_init(void)
358 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
361 gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
363 switch (get_hwrev()) {
366 * Set the low to enable LDO_EN
367 * But when you use the test board for eMMC booting
368 * you should set it HIGH since it removes the inverter
370 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
371 gpio_request(EXYNOS4_GPIO_E36, "ldo_en");
372 gpio_direction_output(EXYNOS4_GPIO_E36, 0);
376 * Default reset state is High and there's no inverter
377 * But set it as HIGH to ensure
379 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
380 gpio_request(EXYNOS4_GPIO_E13, "massmemory_en");
381 gpio_direction_output(EXYNOS4_GPIO_E13, 1);
385 #ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
386 /* Request soft I2C gpios */
387 strcpy(buf, "soft_i2c_scl");
388 gpio_request(CONFIG_SOFT_I2C_GPIO_SCL, buf);
390 strcpy(buf, "soft_i2c_sda");
391 gpio_request(CONFIG_SOFT_I2C_GPIO_SDA, buf);
394 printf("HW Revision:\t0x%x\n", board_rev);
400 void exynos_lcd_misc_init(vidinfo_t *vid)
403 get_tizen_logo_info(vid);
407 vid->pclk_name = 1; /* MPLL */
410 setenv("lcdinfo", "lcd=ld9040");