blob: 6bd106ed502d6eb4d7d923ebc37d7bd38c9c7f0b [file] [log] [blame]
HeungJun, Kim89f95492012-01-16 21:13:05 +00001/*
2 * Copyright (C) 2011 Samsung Electronics
3 * Heungjun Kim <riverful.kim@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
Donghwa Lee51b1cd62012-04-05 19:36:27 +00005 * Donghwa Lee <dh09.lee@samsung.com>
HeungJun, Kim89f95492012-01-16 21:13:05 +00006 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
HeungJun, Kim89f95492012-01-16 21:13:05 +00008 */
9
10#include <common.h>
Donghwa Lee51b1cd62012-04-05 19:36:27 +000011#include <lcd.h>
HeungJun, Kim89f95492012-01-16 21:13:05 +000012#include <asm/io.h>
13#include <asm/arch/cpu.h>
14#include <asm/arch/gpio.h>
15#include <asm/arch/mmc.h>
Piotr Wilczekd651e882012-09-20 00:19:58 +000016#include <asm/arch/pinmux.h>
HeungJun, Kim89f95492012-01-16 21:13:05 +000017#include <asm/arch/clock.h>
Donghwa Lee51b1cd62012-04-05 19:36:27 +000018#include <asm/arch/clk.h>
19#include <asm/arch/mipi_dsim.h>
HeungJun, Kim89f95492012-01-16 21:13:05 +000020#include <asm/arch/watchdog.h>
21#include <asm/arch/power.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000022#include <power/pmic.h>
HeungJun, Kim89f95492012-01-16 21:13:05 +000023#include <usb/s3c_udc.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000024#include <power/max8997_pmic.h>
Donghwa Lee90464972012-05-09 19:23:46 +000025#include <libtizen.h>
Łukasz Majewski7dcda992012-11-13 03:22:06 +000026#include <power/max8997_muic.h>
Łukasz Majewski61365ff2012-11-13 03:22:08 +000027#include <power/battery.h>
Łukasz Majewski5a773582012-11-13 03:22:07 +000028#include <power/max17042_fg.h>
Mateusz Zalega16297cf2013-10-04 19:22:26 +020029#include <usb.h>
Lukasz Majewski83301b42013-03-05 12:10:18 +010030#include <usb_mass_storage.h>
HeungJun, Kim89f95492012-01-16 21:13:05 +000031
32#include "setup.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
36unsigned int board_rev;
37
38#ifdef CONFIG_REVISION_TAG
39u32 get_board_rev(void)
40{
41 return board_rev;
42}
43#endif
44
45static void check_hw_revision(void);
Lukasz Majewskia241d6e2012-08-06 14:41:10 +020046struct s3c_plat_otg_data s5pc210_otg_data;
47
HeungJun, Kim89f95492012-01-16 21:13:05 +000048int board_init(void)
49{
Łukasz Majewski35777e22013-01-02 06:06:02 +000050 gd->bd->bi_boot_params = CONFIG_SYS_SPL_ARGS_ADDR;
HeungJun, Kim89f95492012-01-16 21:13:05 +000051
52 check_hw_revision();
53 printf("HW Revision:\t0x%x\n", board_rev);
54
HeungJun, Kim89f95492012-01-16 21:13:05 +000055 return 0;
56}
57
Łukasz Majewskifd8dca82012-09-04 23:15:21 +000058void i2c_init_board(void)
59{
60 struct exynos4_gpio_part1 *gpio1 =
61 (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
62 struct exynos4_gpio_part2 *gpio2 =
63 (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
64
Łukasz Majewski2936df12013-08-16 15:33:33 +020065 /* I2C_5 -> PMIC -> Adapter 0 */
Łukasz Majewskifd8dca82012-09-04 23:15:21 +000066 s5p_gpio_direction_output(&gpio1->b, 7, 1);
67 s5p_gpio_direction_output(&gpio1->b, 6, 1);
Łukasz Majewski2936df12013-08-16 15:33:33 +020068 /* I2C_9 -> FG -> Adapter 1 */
Łukasz Majewskifd8dca82012-09-04 23:15:21 +000069 s5p_gpio_direction_output(&gpio2->y4, 0, 1);
70 s5p_gpio_direction_output(&gpio2->y4, 1, 1);
71}
72
Łukasz Majewski69ad72a2012-11-13 03:22:10 +000073static void trats_low_power_mode(void)
74{
75 struct exynos4_clock *clk =
76 (struct exynos4_clock *)samsung_get_base_clock();
77 struct exynos4_power *pwr =
78 (struct exynos4_power *)samsung_get_base_power();
79
80 /* Power down CORE1 */
81 /* LOCAL_PWR_CFG [1:0] 0x3 EN, 0x0 DIS */
82 writel(0x0, &pwr->arm_core1_configuration);
83
84 /* Change the APLL frequency */
85 /* ENABLE (1 enable) | LOCKED (1 locked) */
86 /* [31] | [29] */
87 /* FSEL | MDIV | PDIV | SDIV */
88 /* [27] | [25:16] | [13:8] | [2:0] */
89 writel(0xa0c80604, &clk->apll_con0);
90
91 /* Change CPU0 clock divider */
92 /* CORE2_RATIO | APLL_RATIO | PCLK_DBG_RATIO | ATB_RATIO */
93 /* [30:28] | [26:24] | [22:20] | [18:16] */
94 /* PERIPH_RATIO | COREM1_RATIO | COREM0_RATIO | CORE_RATIO */
95 /* [14:12] | [10:8] | [6:4] | [2:0] */
96 writel(0x00000100, &clk->div_cpu0);
97
98 /* CLK_DIV_STAT_CPU0 - wait until clock gets stable (0 = stable) */
99 while (readl(&clk->div_stat_cpu0) & 0x1111111)
100 continue;
101
102 /* Change clock divider ratio for DMC */
103 /* DMCP_RATIO | DMCD_RATIO */
104 /* [22:20] | [18:16] */
105 /* DMC_RATIO | DPHY_RATIO | ACP_PCLK_RATIO | ACP_RATIO */
106 /* [14:12] | [10:8] | [6:4] | [2:0] */
107 writel(0x13113117, &clk->div_dmc0);
108
109 /* CLK_DIV_STAT_DMC0 - wait until clock gets stable (0 = stable) */
110 while (readl(&clk->div_stat_dmc0) & 0x11111111)
111 continue;
112
113 /* Turn off unnecessary power domains */
114 writel(0x0, &pwr->xxti_configuration); /* XXTI */
115 writel(0x0, &pwr->cam_configuration); /* CAM */
116 writel(0x0, &pwr->tv_configuration); /* TV */
117 writel(0x0, &pwr->mfc_configuration); /* MFC */
118 writel(0x0, &pwr->g3d_configuration); /* G3D */
119 writel(0x0, &pwr->gps_configuration); /* GPS */
120 writel(0x0, &pwr->gps_alive_configuration); /* GPS_ALIVE */
121
122 /* Turn off unnecessary clocks */
123 writel(0x0, &clk->gate_ip_cam); /* CAM */
124 writel(0x0, &clk->gate_ip_tv); /* TV */
125 writel(0x0, &clk->gate_ip_mfc); /* MFC */
126 writel(0x0, &clk->gate_ip_g3d); /* G3D */
127 writel(0x0, &clk->gate_ip_image); /* IMAGE */
128 writel(0x0, &clk->gate_ip_gps); /* GPS */
129}
130
Łukasz Majewskia52a7b12012-11-13 03:22:05 +0000131static int pmic_init_max8997(void)
132{
133 struct pmic *p = pmic_get("MAX8997_PMIC");
134 int i = 0, ret = 0;
135 u32 val;
136
137 if (pmic_probe(p))
138 return -1;
139
140 /* BUCK1 VARM: 1.2V */
141 val = (1200000 - 650000) / 25000;
142 ret |= pmic_reg_write(p, MAX8997_REG_BUCK1DVS1, val);
143 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
144 ret |= pmic_reg_write(p, MAX8997_REG_BUCK1CTRL, val);
145
146 /* BUCK2 VINT: 1.1V */
147 val = (1100000 - 650000) / 25000;
148 ret |= pmic_reg_write(p, MAX8997_REG_BUCK2DVS1, val);
149 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
150 ret |= pmic_reg_write(p, MAX8997_REG_BUCK2CTRL, val);
151
152
153 /* BUCK3 G3D: 1.1V - OFF */
154 ret |= pmic_reg_read(p, MAX8997_REG_BUCK3CTRL, &val);
155 val &= ~ENBUCK;
156 ret |= pmic_reg_write(p, MAX8997_REG_BUCK3CTRL, val);
157
158 val = (1100000 - 750000) / 50000;
159 ret |= pmic_reg_write(p, MAX8997_REG_BUCK3DVS, val);
160
161 /* BUCK4 CAMISP: 1.2V - OFF */
162 ret |= pmic_reg_read(p, MAX8997_REG_BUCK4CTRL, &val);
163 val &= ~ENBUCK;
164 ret |= pmic_reg_write(p, MAX8997_REG_BUCK4CTRL, val);
165
166 val = (1200000 - 650000) / 25000;
167 ret |= pmic_reg_write(p, MAX8997_REG_BUCK4DVS, val);
168
169 /* BUCK5 VMEM: 1.2V */
170 val = (1200000 - 650000) / 25000;
171 for (i = 0; i < 8; i++)
172 ret |= pmic_reg_write(p, MAX8997_REG_BUCK5DVS1 + i, val);
173
174 val = ENBUCK | ACTIVE_DISCHARGE; /* DVS OFF */
175 ret |= pmic_reg_write(p, MAX8997_REG_BUCK5CTRL, val);
176
177 /* BUCK6 CAM AF: 2.8V */
178 /* No Voltage Setting Register */
179 /* GNSLCT 3.0X */
180 val = GNSLCT;
181 ret |= pmic_reg_write(p, MAX8997_REG_BUCK6CTRL, val);
182
183 /* BUCK7 VCC_SUB: 2.0V */
184 val = (2000000 - 750000) / 50000;
185 ret |= pmic_reg_write(p, MAX8997_REG_BUCK7DVS, val);
186
187 /* LDO1 VADC: 3.3V */
188 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
189 ret |= pmic_reg_write(p, MAX8997_REG_LDO1CTRL, val);
190
191 /* LDO1 Disable active discharging */
192 ret |= pmic_reg_read(p, MAX8997_REG_LDO1CONFIG, &val);
193 val &= ~LDO_ADE;
194 ret |= pmic_reg_write(p, MAX8997_REG_LDO1CONFIG, val);
195
196 /* LDO2 VALIVE: 1.1V */
197 val = max8997_reg_ldo(1100000) | EN_LDO;
198 ret |= pmic_reg_write(p, MAX8997_REG_LDO2CTRL, val);
199
200 /* LDO3 VUSB/MIPI: 1.1V */
201 val = max8997_reg_ldo(1100000) | DIS_LDO; /* OFF */
202 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, val);
203
204 /* LDO4 VMIPI: 1.8V */
205 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
206 ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, val);
207
208 /* LDO5 VHSIC: 1.2V */
209 val = max8997_reg_ldo(1200000) | DIS_LDO; /* OFF */
210 ret |= pmic_reg_write(p, MAX8997_REG_LDO5CTRL, val);
211
212 /* LDO6 VCC_1.8V_PDA: 1.8V */
213 val = max8997_reg_ldo(1800000) | EN_LDO;
214 ret |= pmic_reg_write(p, MAX8997_REG_LDO6CTRL, val);
215
216 /* LDO7 CAM_ISP: 1.8V */
217 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
218 ret |= pmic_reg_write(p, MAX8997_REG_LDO7CTRL, val);
219
220 /* LDO8 VDAC/VUSB: 3.3V */
221 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
222 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, val);
223
224 /* LDO9 VCC_2.8V_PDA: 2.8V */
225 val = max8997_reg_ldo(2800000) | EN_LDO;
226 ret |= pmic_reg_write(p, MAX8997_REG_LDO9CTRL, val);
227
228 /* LDO10 VPLL: 1.1V */
229 val = max8997_reg_ldo(1100000) | EN_LDO;
230 ret |= pmic_reg_write(p, MAX8997_REG_LDO10CTRL, val);
231
232 /* LDO11 TOUCH: 2.8V */
233 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
234 ret |= pmic_reg_write(p, MAX8997_REG_LDO11CTRL, val);
235
236 /* LDO12 VTCAM: 1.8V */
237 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
238 ret |= pmic_reg_write(p, MAX8997_REG_LDO12CTRL, val);
239
240 /* LDO13 VCC_3.0_LCD: 3.0V */
241 val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
242 ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, val);
243
244 /* LDO14 MOTOR: 3.0V */
245 val = max8997_reg_ldo(3000000) | DIS_LDO; /* OFF */
246 ret |= pmic_reg_write(p, MAX8997_REG_LDO14CTRL, val);
247
248 /* LDO15 LED_A: 2.8V */
249 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
250 ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, val);
251
252 /* LDO16 CAM_SENSOR: 1.8V */
253 val = max8997_reg_ldo(1800000) | DIS_LDO; /* OFF */
254 ret |= pmic_reg_write(p, MAX8997_REG_LDO16CTRL, val);
255
256 /* LDO17 VTF: 2.8V */
257 val = max8997_reg_ldo(2800000) | DIS_LDO; /* OFF */
258 ret |= pmic_reg_write(p, MAX8997_REG_LDO17CTRL, val);
259
260 /* LDO18 TOUCH_LED 3.3V */
261 val = max8997_reg_ldo(3300000) | DIS_LDO; /* OFF */
262 ret |= pmic_reg_write(p, MAX8997_REG_LDO18CTRL, val);
263
264 /* LDO21 VDDQ: 1.2V */
265 val = max8997_reg_ldo(1200000) | EN_LDO;
266 ret |= pmic_reg_write(p, MAX8997_REG_LDO21CTRL, val);
267
268 /* SAFEOUT for both 1 and 2: 4.9V, Active discharge, Enable */
269 val = (SAFEOUT_4_90V << 0) | (SAFEOUT_4_90V << 2) |
270 ACTDISSAFEO1 | ACTDISSAFEO2 | ENSAFEOUT1 | ENSAFEOUT2;
271 ret |= pmic_reg_write(p, MAX8997_REG_SAFEOUTCTRL, val);
272
273 if (ret) {
274 puts("MAX8997 PMIC setting error!\n");
275 return -1;
276 }
277 return 0;
278}
279
Łukasz Majewskid47ab982012-11-13 03:21:57 +0000280int power_init_board(void)
281{
Łukasz Majewskibdee9c82012-11-13 03:22:11 +0000282 int chrg, ret;
283 struct power_battery *pb;
284 struct pmic *p_fg, *p_chrg, *p_muic, *p_bat;
Łukasz Majewskid47ab982012-11-13 03:21:57 +0000285
Łukasz Majewski2936df12013-08-16 15:33:33 +0200286 /*
287 * For PMIC/MUIC the I2C bus is named as I2C5, but it is connected
288 * to logical I2C adapter 0
289 *
290 * The FUEL_GAUGE is marked as I2C9 on the schematic, but connected
291 * to logical I2C adapter 1
292 */
293 ret = pmic_init(I2C_0);
Łukasz Majewskia52a7b12012-11-13 03:22:05 +0000294 ret |= pmic_init_max8997();
Łukasz Majewski2936df12013-08-16 15:33:33 +0200295 ret |= power_fg_init(I2C_1);
296 ret |= power_muic_init(I2C_0);
Łukasz Majewski61365ff2012-11-13 03:22:08 +0000297 ret |= power_bat_init(0);
Łukasz Majewskid47ab982012-11-13 03:21:57 +0000298 if (ret)
299 return ret;
300
Łukasz Majewskibdee9c82012-11-13 03:22:11 +0000301 p_fg = pmic_get("MAX17042_FG");
302 if (!p_fg) {
303 puts("MAX17042_FG: Not found\n");
304 return -ENODEV;
305 }
306
307 p_chrg = pmic_get("MAX8997_PMIC");
308 if (!p_chrg) {
309 puts("MAX8997_PMIC: Not found\n");
310 return -ENODEV;
311 }
312
313 p_muic = pmic_get("MAX8997_MUIC");
314 if (!p_muic) {
315 puts("MAX8997_MUIC: Not found\n");
316 return -ENODEV;
317 }
318
319 p_bat = pmic_get("BAT_TRATS");
320 if (!p_bat) {
321 puts("BAT_TRATS: Not found\n");
322 return -ENODEV;
323 }
324
325 p_fg->parent = p_bat;
326 p_chrg->parent = p_bat;
327 p_muic->parent = p_bat;
328
329 p_bat->low_power_mode = trats_low_power_mode;
330 p_bat->pbat->battery_init(p_bat, p_fg, p_chrg, p_muic);
331
332 pb = p_bat->pbat;
333 chrg = p_muic->chrg->chrg_type(p_muic);
334 debug("CHARGER TYPE: %d\n", chrg);
335
336 if (!p_chrg->chrg->chrg_bat_present(p_chrg)) {
337 puts("No battery detected\n");
338 return -1;
339 }
340
341 p_fg->fg->fg_battery_check(p_fg, p_bat);
342
343 if (pb->bat->state == CHARGE && chrg == CHARGER_USB)
344 puts("CHARGE Battery !\n");
345
Łukasz Majewskid47ab982012-11-13 03:21:57 +0000346 return 0;
347}
348
HeungJun, Kim89f95492012-01-16 21:13:05 +0000349int dram_init(void)
350{
351 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
Piotr Wilczek11c5bc02012-09-20 00:19:56 +0000352 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE) +
353 get_ram_size((long *)PHYS_SDRAM_3, PHYS_SDRAM_3_SIZE) +
354 get_ram_size((long *)PHYS_SDRAM_4, PHYS_SDRAM_4_SIZE);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000355
356 return 0;
357}
358
359void dram_init_banksize(void)
360{
361 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
362 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
363 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
364 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Piotr Wilczek11c5bc02012-09-20 00:19:56 +0000365 gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
366 gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
367 gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
368 gd->bd->bi_dram[3].size = PHYS_SDRAM_4_SIZE;
HeungJun, Kim89f95492012-01-16 21:13:05 +0000369}
370
371static unsigned int get_hw_revision(void)
372{
373 struct exynos4_gpio_part1 *gpio =
374 (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
375 int hwrev = 0;
376 int i;
377
378 /* hw_rev[3:0] == GPE1[3:0] */
379 for (i = 0; i < 4; i++) {
380 s5p_gpio_cfg_pin(&gpio->e1, i, GPIO_INPUT);
381 s5p_gpio_set_pull(&gpio->e1, i, GPIO_PULL_NONE);
382 }
383
384 udelay(1);
385
386 for (i = 0; i < 4; i++)
387 hwrev |= (s5p_gpio_get_value(&gpio->e1, i) << i);
388
389 debug("hwrev 0x%x\n", hwrev);
390
391 return hwrev;
392}
393
394static void check_hw_revision(void)
395{
396 int hwrev;
397
398 hwrev = get_hw_revision();
399
400 board_rev |= hwrev;
401}
402
403#ifdef CONFIG_DISPLAY_BOARDINFO
404int checkboard(void)
405{
406 puts("Board:\tTRATS\n");
407 return 0;
408}
409#endif
410
411#ifdef CONFIG_GENERIC_MMC
412int board_mmc_init(bd_t *bis)
413{
414 struct exynos4_gpio_part2 *gpio =
415 (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
Piotr Wilczekd651e882012-09-20 00:19:58 +0000416 int err;
HeungJun, Kim89f95492012-01-16 21:13:05 +0000417
418 /* eMMC_EN: SD_0_CDn: GPK0[2] Output High */
419 s5p_gpio_direction_output(&gpio->k0, 2, 1);
420 s5p_gpio_set_pull(&gpio->k0, 2, GPIO_PULL_NONE);
421
422 /*
HeungJun, Kim89f95492012-01-16 21:13:05 +0000423 * MMC device init
424 * mmc0 : eMMC (8-bit buswidth)
425 * mmc2 : SD card (4-bit buswidth)
426 */
Piotr Wilczekd651e882012-09-20 00:19:58 +0000427 err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
428 if (err)
429 debug("SDMMC0 not configured\n");
430 else
431 err = s5p_mmc_init(0, 8);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000432
433 /* T-flash detect */
434 s5p_gpio_cfg_pin(&gpio->x3, 4, 0xf);
435 s5p_gpio_set_pull(&gpio->x3, 4, GPIO_PULL_UP);
436
437 /*
438 * Check the T-flash detect pin
439 * GPX3[4] T-flash detect pin
440 */
441 if (!s5p_gpio_get_value(&gpio->x3, 4)) {
Piotr Wilczekd651e882012-09-20 00:19:58 +0000442 err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
443 if (err)
444 debug("SDMMC2 not configured\n");
445 else
446 err = s5p_mmc_init(2, 4);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000447 }
448
449 return err;
450}
451#endif
452
453#ifdef CONFIG_USB_GADGET
454static int s5pc210_phy_control(int on)
455{
456 int ret = 0;
Łukasz Majewskia0f5b5a2012-04-25 23:30:18 +0000457 u32 val = 0;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000458 struct pmic *p = pmic_get("MAX8997_PMIC");
459 if (!p)
460 return -ENODEV;
HeungJun, Kim89f95492012-01-16 21:13:05 +0000461
462 if (pmic_probe(p))
463 return -1;
464
465 if (on) {
Łukasz Majewski04ce68e2012-03-29 01:29:18 +0000466 ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
467 ENSAFEOUT1, LDO_ON);
Łukasz Majewskia0f5b5a2012-04-25 23:30:18 +0000468 ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
469 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, EN_LDO | val);
470
471 ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
472 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, EN_LDO | val);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000473 } else {
Łukasz Majewskia0f5b5a2012-04-25 23:30:18 +0000474 ret |= pmic_reg_read(p, MAX8997_REG_LDO8CTRL, &val);
475 ret |= pmic_reg_write(p, MAX8997_REG_LDO8CTRL, DIS_LDO | val);
476
477 ret |= pmic_reg_read(p, MAX8997_REG_LDO3CTRL, &val);
478 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, DIS_LDO | val);
Łukasz Majewski04ce68e2012-03-29 01:29:18 +0000479 ret |= pmic_set_output(p, MAX8997_REG_SAFEOUTCTRL,
480 ENSAFEOUT1, LDO_OFF);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000481 }
482
483 if (ret) {
Łukasz Majewski04ce68e2012-03-29 01:29:18 +0000484 puts("MAX8997 LDO setting error!\n");
HeungJun, Kim89f95492012-01-16 21:13:05 +0000485 return -1;
486 }
487
488 return 0;
489}
490
491struct s3c_plat_otg_data s5pc210_otg_data = {
492 .phy_control = s5pc210_phy_control,
493 .regs_phy = EXYNOS4_USBPHY_BASE,
494 .regs_otg = EXYNOS4_USBOTG_BASE,
495 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
496 .usb_flags = PHY0_SLEEP,
497};
Lukasz Majewskia241d6e2012-08-06 14:41:10 +0200498
Troy Kiskybba67912013-10-10 15:27:55 -0700499int board_usb_init(int index, enum usb_init_type init)
Lukasz Majewskia241d6e2012-08-06 14:41:10 +0200500{
501 debug("USB_udc_probe\n");
Mateusz Zalega16297cf2013-10-04 19:22:26 +0200502 return s3c_udc_probe(&s5pc210_otg_data);
Lukasz Majewskia241d6e2012-08-06 14:41:10 +0200503}
Przemyslaw Marczak0938f5b2013-12-02 13:54:01 +0100504
505#ifdef CONFIG_USB_CABLE_CHECK
506int usb_cable_connected(void)
507{
508 struct pmic *muic = pmic_get("MAX8997_MUIC");
509 if (!muic)
510 return 0;
511
512 return !!muic->chrg->chrg_type(muic);
513}
514#endif
HeungJun, Kim89f95492012-01-16 21:13:05 +0000515#endif
516
517static void pmic_reset(void)
518{
519 struct exynos4_gpio_part2 *gpio =
520 (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
521
522 s5p_gpio_direction_output(&gpio->x0, 7, 1);
523 s5p_gpio_set_pull(&gpio->x2, 7, GPIO_PULL_NONE);
524}
525
526static void board_clock_init(void)
527{
528 struct exynos4_clock *clk =
529 (struct exynos4_clock *)samsung_get_base_clock();
530
531 writel(CLK_SRC_CPU_VAL, (unsigned int)&clk->src_cpu);
532 writel(CLK_SRC_TOP0_VAL, (unsigned int)&clk->src_top0);
533 writel(CLK_SRC_FSYS_VAL, (unsigned int)&clk->src_fsys);
534 writel(CLK_SRC_PERIL0_VAL, (unsigned int)&clk->src_peril0);
535
536 writel(CLK_DIV_CPU0_VAL, (unsigned int)&clk->div_cpu0);
537 writel(CLK_DIV_CPU1_VAL, (unsigned int)&clk->div_cpu1);
538 writel(CLK_DIV_DMC0_VAL, (unsigned int)&clk->div_dmc0);
539 writel(CLK_DIV_DMC1_VAL, (unsigned int)&clk->div_dmc1);
540 writel(CLK_DIV_LEFTBUS_VAL, (unsigned int)&clk->div_leftbus);
541 writel(CLK_DIV_RIGHTBUS_VAL, (unsigned int)&clk->div_rightbus);
542 writel(CLK_DIV_TOP_VAL, (unsigned int)&clk->div_top);
543 writel(CLK_DIV_FSYS1_VAL, (unsigned int)&clk->div_fsys1);
544 writel(CLK_DIV_FSYS2_VAL, (unsigned int)&clk->div_fsys2);
545 writel(CLK_DIV_FSYS3_VAL, (unsigned int)&clk->div_fsys3);
546 writel(CLK_DIV_PERIL0_VAL, (unsigned int)&clk->div_peril0);
547 writel(CLK_DIV_PERIL3_VAL, (unsigned int)&clk->div_peril3);
548
549 writel(PLL_LOCKTIME, (unsigned int)&clk->apll_lock);
550 writel(PLL_LOCKTIME, (unsigned int)&clk->mpll_lock);
551 writel(PLL_LOCKTIME, (unsigned int)&clk->epll_lock);
552 writel(PLL_LOCKTIME, (unsigned int)&clk->vpll_lock);
553 writel(APLL_CON1_VAL, (unsigned int)&clk->apll_con1);
554 writel(APLL_CON0_VAL, (unsigned int)&clk->apll_con0);
555 writel(MPLL_CON1_VAL, (unsigned int)&clk->mpll_con1);
556 writel(MPLL_CON0_VAL, (unsigned int)&clk->mpll_con0);
557 writel(EPLL_CON1_VAL, (unsigned int)&clk->epll_con1);
558 writel(EPLL_CON0_VAL, (unsigned int)&clk->epll_con0);
559 writel(VPLL_CON1_VAL, (unsigned int)&clk->vpll_con1);
560 writel(VPLL_CON0_VAL, (unsigned int)&clk->vpll_con0);
561
562 writel(CLK_GATE_IP_CAM_VAL, (unsigned int)&clk->gate_ip_cam);
563 writel(CLK_GATE_IP_VP_VAL, (unsigned int)&clk->gate_ip_tv);
564 writel(CLK_GATE_IP_MFC_VAL, (unsigned int)&clk->gate_ip_mfc);
565 writel(CLK_GATE_IP_G3D_VAL, (unsigned int)&clk->gate_ip_g3d);
566 writel(CLK_GATE_IP_IMAGE_VAL, (unsigned int)&clk->gate_ip_image);
567 writel(CLK_GATE_IP_LCD0_VAL, (unsigned int)&clk->gate_ip_lcd0);
568 writel(CLK_GATE_IP_LCD1_VAL, (unsigned int)&clk->gate_ip_lcd1);
569 writel(CLK_GATE_IP_FSYS_VAL, (unsigned int)&clk->gate_ip_fsys);
570 writel(CLK_GATE_IP_GPS_VAL, (unsigned int)&clk->gate_ip_gps);
571 writel(CLK_GATE_IP_PERIL_VAL, (unsigned int)&clk->gate_ip_peril);
572 writel(CLK_GATE_IP_PERIR_VAL, (unsigned int)&clk->gate_ip_perir);
573 writel(CLK_GATE_BLOCK_VAL, (unsigned int)&clk->gate_block);
574}
575
HeungJun, Kim89f95492012-01-16 21:13:05 +0000576static void board_power_init(void)
577{
578 struct exynos4_power *pwr =
579 (struct exynos4_power *)samsung_get_base_power();
580
581 /* PS HOLD */
582 writel(EXYNOS4_PS_HOLD_CON_VAL, (unsigned int)&pwr->ps_hold_control);
583
584 /* Set power down */
585 writel(0, (unsigned int)&pwr->cam_configuration);
586 writel(0, (unsigned int)&pwr->tv_configuration);
587 writel(0, (unsigned int)&pwr->mfc_configuration);
588 writel(0, (unsigned int)&pwr->g3d_configuration);
589 writel(0, (unsigned int)&pwr->lcd1_configuration);
590 writel(0, (unsigned int)&pwr->gps_configuration);
591 writel(0, (unsigned int)&pwr->gps_alive_configuration);
Piotr Wilczekab233042012-10-08 20:45:42 +0000592
593 /* It is necessary to power down core 1 */
594 /* to successfully boot CPU1 in kernel */
595 writel(0, (unsigned int)&pwr->arm_core1_configuration);
HeungJun, Kim89f95492012-01-16 21:13:05 +0000596}
597
598static void board_uart_init(void)
599{
600 struct exynos4_gpio_part1 *gpio1 =
601 (struct exynos4_gpio_part1 *)samsung_get_base_gpio_part1();
602 struct exynos4_gpio_part2 *gpio2 =
603 (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
604 int i;
605
HeungJun, Kim89f95492012-01-16 21:13:05 +0000606 /*
Minkyu Kang8aca4d62012-01-26 19:51:54 +0900607 * UART2 GPIOs
608 * GPA1CON[0] = UART_2_RXD(2)
609 * GPA1CON[1] = UART_2_TXD(2)
HeungJun, Kim89f95492012-01-16 21:13:05 +0000610 * GPA1CON[2] = I2C_3_SDA (3)
Minkyu Kang8aca4d62012-01-26 19:51:54 +0900611 * GPA1CON[3] = I2C_3_SCL (3)
HeungJun, Kim89f95492012-01-16 21:13:05 +0000612 */
Minkyu Kang8aca4d62012-01-26 19:51:54 +0900613
614 for (i = 0; i < 4; i++) {
HeungJun, Kim89f95492012-01-16 21:13:05 +0000615 s5p_gpio_set_pull(&gpio1->a1, i, GPIO_PULL_NONE);
Minkyu Kang8aca4d62012-01-26 19:51:54 +0900616 s5p_gpio_cfg_pin(&gpio1->a1, i, GPIO_FUNC((i > 1) ? 0x3 : 0x2));
HeungJun, Kim89f95492012-01-16 21:13:05 +0000617 }
618
619 /* UART_SEL GPY4[7] (part2) at EXYNOS4 */
620 s5p_gpio_set_pull(&gpio2->y4, 7, GPIO_PULL_UP);
621 s5p_gpio_direction_output(&gpio2->y4, 7, 1);
622}
623
624int board_early_init_f(void)
625{
Minkyu Kang85948a82012-01-18 15:56:47 +0900626 wdt_stop();
HeungJun, Kim89f95492012-01-16 21:13:05 +0000627 pmic_reset();
628 board_clock_init();
629 board_uart_init();
630 board_power_init();
631
632 return 0;
633}
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000634
Ajay Kumar29fd5702013-02-21 23:52:57 +0000635void exynos_reset_lcd(void)
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000636{
637 struct exynos4_gpio_part2 *gpio2 =
638 (struct exynos4_gpio_part2 *)samsung_get_base_gpio_part2();
639
640 s5p_gpio_direction_output(&gpio2->y4, 5, 1);
641 udelay(10000);
642 s5p_gpio_direction_output(&gpio2->y4, 5, 0);
643 udelay(10000);
644 s5p_gpio_direction_output(&gpio2->y4, 5, 1);
645}
646
647static int lcd_power(void)
648{
649 int ret = 0;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000650 struct pmic *p = pmic_get("MAX8997_PMIC");
651 if (!p)
652 return -ENODEV;
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000653
654 if (pmic_probe(p))
655 return 0;
656
657 /* LDO15 voltage: 2.2v */
658 ret |= pmic_reg_write(p, MAX8997_REG_LDO15CTRL, 0x1c | EN_LDO);
659 /* LDO13 voltage: 3.0v */
660 ret |= pmic_reg_write(p, MAX8997_REG_LDO13CTRL, 0x2c | EN_LDO);
661
662 if (ret) {
663 puts("MAX8997 LDO setting error!\n");
664 return -1;
665 }
666
667 return 0;
668}
669
670static struct mipi_dsim_config dsim_config = {
671 .e_interface = DSIM_VIDEO,
672 .e_virtual_ch = DSIM_VIRTUAL_CH_0,
673 .e_pixel_format = DSIM_24BPP_888,
674 .e_burst_mode = DSIM_BURST_SYNC_EVENT,
675 .e_no_data_lane = DSIM_DATA_LANE_4,
676 .e_byte_clk = DSIM_PLL_OUT_DIV8,
677 .hfp = 1,
678
679 .p = 3,
680 .m = 120,
681 .s = 1,
682
683 /* D-PHY PLL stable time spec :min = 200usec ~ max 400usec */
684 .pll_stable_time = 500,
685
686 /* escape clk : 10MHz */
687 .esc_clk = 20 * 1000000,
688
689 /* stop state holding counter after bta change count 0 ~ 0xfff */
690 .stop_holding_cnt = 0x7ff,
691 /* bta timeout 0 ~ 0xff */
692 .bta_timeout = 0xff,
693 /* lp rx timeout 0 ~ 0xffff */
694 .rx_timeout = 0xffff,
695};
696
697static struct exynos_platform_mipi_dsim s6e8ax0_platform_data = {
698 .lcd_panel_info = NULL,
699 .dsim_config = &dsim_config,
700};
701
702static struct mipi_dsim_lcd_device mipi_lcd_device = {
703 .name = "s6e8ax0",
704 .id = -1,
705 .bus_id = 0,
706 .platform_data = (void *)&s6e8ax0_platform_data,
707};
708
709static int mipi_power(void)
710{
711 int ret = 0;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000712 struct pmic *p = pmic_get("MAX8997_PMIC");
713 if (!p)
714 return -ENODEV;
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000715
716 if (pmic_probe(p))
717 return 0;
718
719 /* LDO3 voltage: 1.1v */
720 ret |= pmic_reg_write(p, MAX8997_REG_LDO3CTRL, 0x6 | EN_LDO);
721 /* LDO4 voltage: 1.8v */
722 ret |= pmic_reg_write(p, MAX8997_REG_LDO4CTRL, 0x14 | EN_LDO);
723
724 if (ret) {
725 puts("MAX8997 LDO setting error!\n");
726 return -1;
727 }
728
729 return 0;
730}
731
Donghwa Leec2054562012-04-25 13:29:39 +0000732vidinfo_t panel_info = {
733 .vl_freq = 60,
734 .vl_col = 720,
735 .vl_row = 1280,
736 .vl_width = 720,
737 .vl_height = 1280,
738 .vl_clkp = CONFIG_SYS_HIGH,
739 .vl_hsp = CONFIG_SYS_LOW,
740 .vl_vsp = CONFIG_SYS_LOW,
741 .vl_dp = CONFIG_SYS_LOW,
742 .vl_bpix = 5, /* Bits per pixel, 2^5 = 32 */
743
744 /* s6e8ax0 Panel infomation */
745 .vl_hspw = 5,
746 .vl_hbpd = 10,
747 .vl_hfpd = 10,
748
749 .vl_vspw = 2,
750 .vl_vbpd = 1,
751 .vl_vfpd = 13,
752 .vl_cmd_allow_len = 0xf,
753
754 .win_id = 3,
Donghwa Leec2054562012-04-25 13:29:39 +0000755 .dual_lcd_enabled = 0,
756
757 .init_delay = 0,
758 .power_on_delay = 0,
759 .reset_delay = 0,
760 .interface_mode = FIMD_RGB_INTERFACE,
761 .mipi_enabled = 1,
762};
763
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000764void init_panel_info(vidinfo_t *vid)
765{
Donghwa Lee90464972012-05-09 19:23:46 +0000766 vid->logo_on = 1,
767 vid->resolution = HD_RESOLUTION,
768 vid->rgb_mode = MODE_RGB_P,
769
770#ifdef CONFIG_TIZEN
771 get_tizen_logo_info(vid);
772#endif
Łukasz Majewskibaa88412013-07-15 16:09:50 +0200773 mipi_lcd_device.reverse_panel = 1;
Donghwa Lee3d024082012-04-26 18:52:26 +0000774
Donghwa Lee51b1cd62012-04-05 19:36:27 +0000775 strcpy(s6e8ax0_platform_data.lcd_panel_name, mipi_lcd_device.name);
776 s6e8ax0_platform_data.lcd_power = lcd_power;
777 s6e8ax0_platform_data.mipi_power = mipi_power;
778 s6e8ax0_platform_data.phy_enable = set_mipi_phy_ctrl;
779 s6e8ax0_platform_data.lcd_panel_info = (void *)vid;
780 exynos_mipi_dsi_register_lcd_device(&mipi_lcd_device);
781 s6e8ax0_init();
782 exynos_set_dsim_platform_data(&s6e8ax0_platform_data);
783
784 setenv("lcdinfo", "lcd=s6e8ax0");
785}