blob: c3946ee89105ccab933c09c7417bae2047b32038 [file] [log] [blame]
Minkyu Kang9e408082011-01-24 15:33:50 +09001/*
2 * Copyright (C) 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Minkyu Kang9e408082011-01-24 15:33:50 +09007 */
8
9#include <common.h>
Piotr Wilczekff0fedd2012-10-19 05:34:03 +000010#include <spi.h>
Piotr Wilczekd984b9f2012-10-19 05:34:07 +000011#include <lcd.h>
Minkyu Kang9e408082011-01-24 15:33:50 +090012#include <asm/io.h>
Piotr Wilczekff0fedd2012-10-19 05:34:03 +000013#include <asm/gpio.h>
Minkyu Kang9e408082011-01-24 15:33:50 +090014#include <asm/arch/adc.h>
Piotr Wilczekea7991b2012-09-20 00:19:59 +000015#include <asm/arch/pinmux.h>
Piotr Wilczek11a44792012-09-20 00:20:00 +000016#include <asm/arch/watchdog.h>
Piotr Wilczekd984b9f2012-10-19 05:34:07 +000017#include <ld9040.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000018#include <power/pmic.h>
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +010019#include <usb.h>
Marek Vasut5d5716e2015-12-04 02:51:20 +010020#include <usb/dwc2_udc.h>
Lukasz Majewskiddc7e542011-12-15 10:32:12 +010021#include <asm/arch/cpu.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000022#include <power/max8998_pmic.h>
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +010023#include <libtizen.h>
Przemyslaw Marczak82b0a0552014-01-22 11:24:20 +010024#include <samsung/misc.h>
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +010025#include <usb_mass_storage.h>
Minkyu Kang9e408082011-01-24 15:33:50 +090026
27DECLARE_GLOBAL_DATA_PTR;
28
Minkyu Kang9e408082011-01-24 15:33:50 +090029unsigned int board_rev;
30
31u32 get_board_rev(void)
32{
33 return board_rev;
34}
35
36static int get_hwrev(void)
37{
38 return board_rev & 0xFF;
39}
40
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +010041int exynos_power_init(void)
Łukasz Majewskif5a70042012-11-13 03:22:17 +000042{
Simon Glassfc47cf92016-11-23 06:34:40 -070043#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Łukasz Majewskif5a70042012-11-13 03:22:17 +000044 int ret;
45
Łukasz Majewski2936df12013-08-16 15:33:33 +020046 /*
47 * For PMIC the I2C bus is named as I2C5, but it is connected
48 * to logical I2C adapter 0
49 */
Piotr Wilczekc47817b2014-01-14 08:15:07 +010050 ret = pmic_init(I2C_0);
Łukasz Majewskif5a70042012-11-13 03:22:17 +000051 if (ret)
52 return ret;
53
Minkyu Kang48e91ca2012-12-09 20:50:11 +000054 init_pmic_lcd();
Simon Glassfc47cf92016-11-23 06:34:40 -070055#endif
Łukasz Majewskif5a70042012-11-13 03:22:17 +000056 return 0;
57}
Minkyu Kang9e408082011-01-24 15:33:50 +090058
Minkyu Kang9e408082011-01-24 15:33:50 +090059static unsigned short get_adc_value(int channel)
60{
61 struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
62 unsigned short ret = 0;
63 unsigned int reg;
64 unsigned int loop = 0;
65
66 writel(channel & 0xF, &adc->adcmux);
67 writel((1 << 14) | (49 << 6), &adc->adccon);
68 writel(1000 & 0xffff, &adc->adcdly);
69 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
70 udelay(10);
71 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
72 udelay(10);
73
74 do {
75 udelay(1);
76 reg = readl(&adc->adccon);
77 } while (!(reg & (1 << 15)) && (loop++ < 1000));
78
79 ret = readl(&adc->adcdat0) & 0xFFF;
80
81 return ret;
82}
83
Łukasz Majewski4d86bf02012-03-26 21:53:48 +000084static int adc_power_control(int on)
85{
Simon Glassfc47cf92016-11-23 06:34:40 -070086#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Łukasz Majewski4d86bf02012-03-26 21:53:48 +000087 int ret;
Łukasz Majewskic7336812012-11-13 03:21:55 +000088 struct pmic *p = pmic_get("MAX8998_PMIC");
89 if (!p)
90 return -ENODEV;
Łukasz Majewski4d86bf02012-03-26 21:53:48 +000091
92 if (pmic_probe(p))
93 return -1;
94
95 ret = pmic_set_output(p,
96 MAX8998_REG_ONOFF1,
97 MAX8998_LDO4, !!on);
98
99 return ret;
Simon Glassfc47cf92016-11-23 06:34:40 -0700100#else
101 return 0;
102#endif
Łukasz Majewski4d86bf02012-03-26 21:53:48 +0000103}
104
Minkyu Kang9e408082011-01-24 15:33:50 +0900105static unsigned int get_hw_revision(void)
106{
107 int hwrev, mode0, mode1;
108
Łukasz Majewski4d86bf02012-03-26 21:53:48 +0000109 adc_power_control(1);
110
Minkyu Kang9e408082011-01-24 15:33:50 +0900111 mode0 = get_adc_value(1); /* HWREV_MODE0 */
112 mode1 = get_adc_value(2); /* HWREV_MODE1 */
113
114 /*
115 * XXX Always set the default hwrev as the latest board
116 * ADC = (voltage) / 3.3 * 4096
117 */
118 hwrev = 3;
119
120#define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
121 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
122 hwrev = 0x0; /* 0.01V 0.01V */
123 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
124 hwrev = 0x1; /* 610mV 0.01V */
125 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
126 hwrev = 0x2; /* 1.16V 0.01V */
127 if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
128 hwrev = 0x3; /* 1.79V 0.01V */
129#undef IS_RANGE
130
131 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
132
Łukasz Majewski4d86bf02012-03-26 21:53:48 +0000133 adc_power_control(0);
134
Minkyu Kang9e408082011-01-24 15:33:50 +0900135 return hwrev;
136}
137
138static void check_hw_revision(void)
139{
140 int hwrev;
141
142 hwrev = get_hw_revision();
143
144 board_rev |= hwrev;
145}
146
Lukasz Majewskiddc7e542011-12-15 10:32:12 +0100147#ifdef CONFIG_USB_GADGET
148static int s5pc210_phy_control(int on)
149{
Simon Glassfc47cf92016-11-23 06:34:40 -0700150#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Anatolij Gustschine03492c2011-12-19 04:20:04 +0000151 int ret = 0;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000152 struct pmic *p = pmic_get("MAX8998_PMIC");
153 if (!p)
154 return -ENODEV;
Lukasz Majewskiddc7e542011-12-15 10:32:12 +0100155
156 if (pmic_probe(p))
157 return -1;
158
159 if (on) {
160 ret |= pmic_set_output(p,
161 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
162 MAX8998_SAFEOUT1, LDO_ON);
163 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
164 MAX8998_LDO3, LDO_ON);
165 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
166 MAX8998_LDO8, LDO_ON);
167
168 } else {
169 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
170 MAX8998_LDO8, LDO_OFF);
171 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
172 MAX8998_LDO3, LDO_OFF);
173 ret |= pmic_set_output(p,
174 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
175 MAX8998_SAFEOUT1, LDO_OFF);
176 }
177
178 if (ret) {
179 puts("MAX8998 LDO setting error!\n");
180 return -1;
181 }
Simon Glassfc47cf92016-11-23 06:34:40 -0700182#endif
Lukasz Majewskiddc7e542011-12-15 10:32:12 +0100183 return 0;
184}
185
Marek Vasutc0982872015-12-04 02:23:29 +0100186struct dwc2_plat_otg_data s5pc210_otg_data = {
Lukasz Majewskiddc7e542011-12-15 10:32:12 +0100187 .phy_control = s5pc210_phy_control,
188 .regs_phy = EXYNOS4_USBPHY_BASE,
189 .regs_otg = EXYNOS4_USBOTG_BASE,
190 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
191 .usb_flags = PHY0_SLEEP,
192};
193#endif
Piotr Wilczek11a44792012-09-20 00:20:00 +0000194
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100195int board_usb_init(int index, enum usb_init_type init)
196{
197 debug("USB_udc_probe\n");
Marek Vasuta4bb9b32015-12-04 02:26:33 +0100198 return dwc2_udc_probe(&s5pc210_otg_data);
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100199}
200
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100201int exynos_early_init_f(void)
Piotr Wilczek11a44792012-09-20 00:20:00 +0000202{
203 wdt_stop();
204
205 return 0;
206}
Piotr Wilczekff0fedd2012-10-19 05:34:03 +0000207
Simon Glassfc47cf92016-11-23 06:34:40 -0700208#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000209static void init_pmic_lcd(void)
210{
211 unsigned char val;
212 int ret = 0;
213
Minkyu Kang48e91ca2012-12-09 20:50:11 +0000214 struct pmic *p = pmic_get("MAX8998_PMIC");
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000215
Minkyu Kangfbef8e62012-12-10 22:43:57 +0900216 if (!p)
217 return;
218
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000219 if (pmic_probe(p))
220 return;
221
222 /* LDO7 1.8V */
223 val = 0x02; /* (1800 - 1600) / 100; */
224 ret |= pmic_reg_write(p, MAX8998_REG_LDO7, val);
225
226 /* LDO17 3.0V */
227 val = 0xe; /* (3000 - 1600) / 100; */
228 ret |= pmic_reg_write(p, MAX8998_REG_LDO17, val);
229
230 /* Disable unneeded regulators */
231 /*
232 * ONOFF1
233 * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
234 * LDO2 ON, LDO3 OFF, LDO4 OFF, LDO5 ON
235 */
236 val = 0xB9;
237 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF1, val);
238
239 /* ONOFF2
240 * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
241 * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
242 */
243 val = 0x50;
244 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF2, val);
245
246 /* ONOFF3
247 * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 OFF
248 * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
249 */
250 val = 0x00;
251 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF3, val);
252
253 if (ret)
254 puts("LCD pmic initialisation error!\n");
255}
Simon Glassfc47cf92016-11-23 06:34:40 -0700256#endif
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000257
Ajay Kumar29fd5702013-02-21 23:52:57 +0000258void exynos_cfg_lcd_gpio(void)
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000259{
260 unsigned int i, f3_end = 4;
261
262 for (i = 0; i < 8; i++) {
263 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530264 gpio_cfg_pin(EXYNOS4_GPIO_F00 + i, S5P_GPIO_FUNC(2));
265 gpio_cfg_pin(EXYNOS4_GPIO_F10 + i, S5P_GPIO_FUNC(2));
266 gpio_cfg_pin(EXYNOS4_GPIO_F20 + i, S5P_GPIO_FUNC(2));
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000267 /* pull-up/down disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530268 gpio_set_pull(EXYNOS4_GPIO_F00 + i, S5P_GPIO_PULL_NONE);
269 gpio_set_pull(EXYNOS4_GPIO_F10 + i, S5P_GPIO_PULL_NONE);
270 gpio_set_pull(EXYNOS4_GPIO_F20 + i, S5P_GPIO_PULL_NONE);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000271
272 /* drive strength to max (24bit) */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530273 gpio_set_drv(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_4X);
274 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
275 gpio_set_drv(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_4X);
276 gpio_set_rate(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_SLOW);
277 gpio_set_drv(EXYNOS4_GPIO_F20 + i, S5P_GPIO_DRV_4X);
278 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000279 }
280
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530281 for (i = EXYNOS4_GPIO_F30; i < (EXYNOS4_GPIO_F30 + f3_end); i++) {
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000282 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530283 gpio_cfg_pin(i, S5P_GPIO_FUNC(2));
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000284 /* pull-up/down disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530285 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000286 /* drive strength to max (24bit) */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530287 gpio_set_drv(i, S5P_GPIO_DRV_4X);
288 gpio_set_rate(i, S5P_GPIO_DRV_SLOW);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000289 }
290
291 /* gpio pad configuration for LCD reset. */
Simon Glass7f196102014-10-20 19:48:39 -0600292 gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530293 gpio_cfg_pin(EXYNOS4_GPIO_Y45, S5P_GPIO_OUTPUT);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000294}
295
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100296int mipi_power(void)
297{
298 return 0;
299}
300
Ajay Kumar29fd5702013-02-21 23:52:57 +0000301void exynos_reset_lcd(void)
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000302{
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530303 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000304 udelay(10000);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530305 gpio_set_value(EXYNOS4_GPIO_Y45, 0);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000306 udelay(10000);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530307 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000308 udelay(100);
309}
310
Ajay Kumar29fd5702013-02-21 23:52:57 +0000311void exynos_lcd_power_on(void)
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000312{
Simon Glassfc47cf92016-11-23 06:34:40 -0700313#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Minkyu Kang48e91ca2012-12-09 20:50:11 +0000314 struct pmic *p = pmic_get("MAX8998_PMIC");
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000315
Minkyu Kangfbef8e62012-12-10 22:43:57 +0900316 if (!p)
317 return;
318
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000319 if (pmic_probe(p))
320 return;
321
322 pmic_set_output(p, MAX8998_REG_ONOFF3, MAX8998_LDO17, LDO_ON);
323 pmic_set_output(p, MAX8998_REG_ONOFF2, MAX8998_LDO7, LDO_ON);
Simon Glassfc47cf92016-11-23 06:34:40 -0700324#endif
Piotr Wilczekd984b9f2012-10-19 05:34:07 +0000325}
326
Ajay Kumar29fd5702013-02-21 23:52:57 +0000327void exynos_cfg_ldo(void)
328{
329 ld9040_cfg_ldo();
330}
331
332void exynos_enable_ldo(unsigned int onoff)
333{
334 ld9040_enable_ldo(onoff);
335}
336
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100337int exynos_init(void)
Piotr Wilczekff0fedd2012-10-19 05:34:03 +0000338{
Simon Glassfc47cf92016-11-23 06:34:40 -0700339#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Przemyslaw Marczak4381aad2014-10-24 17:45:03 +0200340 char buf[16];
Simon Glassfc47cf92016-11-23 06:34:40 -0700341#endif
Piotr Wilczekff0fedd2012-10-19 05:34:03 +0000342 gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100343
344 switch (get_hwrev()) {
345 case 0:
346 /*
347 * Set the low to enable LDO_EN
348 * But when you use the test board for eMMC booting
349 * you should set it HIGH since it removes the inverter
350 */
351 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
Simon Glass7f196102014-10-20 19:48:39 -0600352 gpio_request(EXYNOS4_GPIO_E36, "ldo_en");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530353 gpio_direction_output(EXYNOS4_GPIO_E36, 0);
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100354 break;
355 default:
356 /*
357 * Default reset state is High and there's no inverter
358 * But set it as HIGH to ensure
359 */
360 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
Simon Glass7f196102014-10-20 19:48:39 -0600361 gpio_request(EXYNOS4_GPIO_E13, "massmemory_en");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530362 gpio_direction_output(EXYNOS4_GPIO_E13, 1);
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100363 break;
364 }
Piotr Wilczekff0fedd2012-10-19 05:34:03 +0000365
Simon Glassfc47cf92016-11-23 06:34:40 -0700366#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Przemyslaw Marczak4381aad2014-10-24 17:45:03 +0200367 /* Request soft I2C gpios */
Ben Whitten192bc692015-12-30 13:05:58 +0000368 strcpy(buf, "soft_i2c_scl");
Przemyslaw Marczak4381aad2014-10-24 17:45:03 +0200369 gpio_request(CONFIG_SOFT_I2C_GPIO_SCL, buf);
370
Ben Whitten192bc692015-12-30 13:05:58 +0000371 strcpy(buf, "soft_i2c_sda");
Przemyslaw Marczak4381aad2014-10-24 17:45:03 +0200372 gpio_request(CONFIG_SOFT_I2C_GPIO_SDA, buf);
Simon Glassfc47cf92016-11-23 06:34:40 -0700373#endif
Piotr Wilczekff0fedd2012-10-19 05:34:03 +0000374 check_hw_revision();
375 printf("HW Revision:\t0x%x\n", board_rev);
376
377 return 0;
378}
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100379
Simon Glassea743e62016-02-21 21:08:54 -0700380#ifdef CONFIG_LCD
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100381void exynos_lcd_misc_init(vidinfo_t *vid)
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100382{
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100383#ifdef CONFIG_TIZEN
384 get_tizen_logo_info(vid);
Piotr Wilczek815a6072014-01-22 15:54:34 +0100385#endif
Piotr Wilczek3f41ffe2014-03-07 14:59:47 +0100386
387 /* for LD9040. */
388 vid->pclk_name = 1; /* MPLL */
389 vid->sclk_div = 1;
390
391 setenv("lcdinfo", "lcd=ld9040");
Przemyslaw Marczak679549d2014-01-22 11:24:12 +0100392}
Simon Glassea743e62016-02-21 21:08:54 -0700393#endif