blob: f1d3d97fd685d3020ca5adec1cc7227b961cf5b4 [file] [log] [blame]
Chander Kashyap0aee53b2012-02-05 23:01:47 +00001/*
2 * Copyright (C) 2012 Samsung Electronics
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
Hatim RV3ea93942012-12-11 00:52:47 +000024#include <fdtdec.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000025#include <asm/io.h>
Rajeshwari Shindeb278c402013-02-12 20:40:02 +000026#include <errno.h>
Rajeshwari Shindec82b0502012-07-23 21:23:55 +000027#include <i2c.h>
Ajay Kumar9b572852013-01-08 20:42:26 +000028#include <lcd.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000029#include <netdev.h>
Hatim RV3a8a7002012-11-02 01:15:37 +000030#include <spi.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000031#include <asm/arch/cpu.h>
Amar752f4c42013-04-27 11:42:57 +053032#include <asm/arch/dwmmc.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000033#include <asm/arch/gpio.h>
34#include <asm/arch/mmc.h>
Rajeshwari Shindec6baaa62012-06-06 19:54:30 +000035#include <asm/arch/pinmux.h>
Ajay Kumar9b572852013-01-08 20:42:26 +000036#include <asm/arch/power.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000037#include <asm/arch/sromc.h>
Ajay Kumar9b572852013-01-08 20:42:26 +000038#include <asm/arch/dp_info.h>
Rajeshwari Shinde211e8432012-12-10 01:55:48 +000039#include <power/pmic.h>
Rajeshwari Shindeb278c402013-02-12 20:40:02 +000040#include <power/max77686_pmic.h>
Chander Kashyap0aee53b2012-02-05 23:01:47 +000041
42DECLARE_GLOBAL_DATA_PTR;
Chander Kashyap0aee53b2012-02-05 23:01:47 +000043
Vivek Gautam9a0c4f92013-01-07 23:37:18 +000044#ifdef CONFIG_USB_EHCI_EXYNOS
45int board_usb_vbus_init(void)
46{
47 struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
48 samsung_get_base_gpio_part1();
49
50 /* Enable VBUS power switch */
51 s5p_gpio_direction_output(&gpio1->x2, 6, 1);
52
53 /* VBUS turn ON time */
54 mdelay(3);
55
56 return 0;
57}
58#endif
59
Rajeshwari Shindece073802013-02-14 19:46:14 +000060#ifdef CONFIG_SOUND_MAX98095
61static void board_enable_audio_codec(void)
62{
63 struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
64 samsung_get_base_gpio_part1();
65
66 /* Enable MAX98095 Codec */
67 s5p_gpio_direction_output(&gpio1->x1, 7, 1);
68 s5p_gpio_set_pull(&gpio1->x1, 7, GPIO_PULL_NONE);
69}
70#endif
71
Chander Kashyap0aee53b2012-02-05 23:01:47 +000072int board_init(void)
73{
Chander Kashyap0aee53b2012-02-05 23:01:47 +000074 gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
Akshay Saraswat7e30ad82013-02-25 01:13:02 +000075
Hatim RV3a8a7002012-11-02 01:15:37 +000076#ifdef CONFIG_EXYNOS_SPI
77 spi_init();
78#endif
Vivek Gautam9a0c4f92013-01-07 23:37:18 +000079#ifdef CONFIG_USB_EHCI_EXYNOS
80 board_usb_vbus_init();
81#endif
Rajeshwari Shindece073802013-02-14 19:46:14 +000082#ifdef CONFIG_SOUND_MAX98095
83 board_enable_audio_codec();
84#endif
Chander Kashyap0aee53b2012-02-05 23:01:47 +000085 return 0;
86}
87
88int dram_init(void)
89{
Amar752f4c42013-04-27 11:42:57 +053090 int i;
91 u32 addr;
92
93 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
94 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
95 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
96 }
Chander Kashyap0aee53b2012-02-05 23:01:47 +000097 return 0;
98}
99
Rajeshwari Shinde211e8432012-12-10 01:55:48 +0000100#if defined(CONFIG_POWER)
Rajeshwari Shindeb278c402013-02-12 20:40:02 +0000101static int pmic_reg_update(struct pmic *p, int reg, uint regval)
102{
103 u32 val;
104 int ret = 0;
105
106 ret = pmic_reg_read(p, reg, &val);
107 if (ret) {
108 debug("%s: PMIC %d register read failed\n", __func__, reg);
109 return -1;
110 }
111 val |= regval;
112 ret = pmic_reg_write(p, reg, val);
113 if (ret) {
114 debug("%s: PMIC %d register write failed\n", __func__, reg);
115 return -1;
116 }
117 return 0;
118}
119
Rajeshwari Shinde211e8432012-12-10 01:55:48 +0000120int power_init_board(void)
121{
Rajeshwari Shindeb278c402013-02-12 20:40:02 +0000122 struct pmic *p;
123
124 set_ps_hold_ctrl();
125
126 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
127
Rajeshwari Shinde211e8432012-12-10 01:55:48 +0000128 if (pmic_init(I2C_PMIC))
129 return -1;
Rajeshwari Shindeb278c402013-02-12 20:40:02 +0000130
131 p = pmic_get("MAX77686_PMIC");
132 if (!p)
133 return -ENODEV;
134
135 if (pmic_probe(p))
136 return -1;
137
138 if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
139 return -1;
140
141 if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
142 MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
143 return -1;
144
145 /* VDD_MIF */
146 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
Bernie Thompson2955d602013-04-15 10:34:34 -0700147 MAX77686_BUCK1OUT_1_05V)) {
Rajeshwari Shindeb278c402013-02-12 20:40:02 +0000148 debug("%s: PMIC %d register write failed\n", __func__,
149 MAX77686_REG_PMIC_BUCK1OUT);
150 return -1;
151 }
152
153 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
154 MAX77686_BUCK1CTRL_EN))
155 return -1;
156
157 /* VDD_ARM */
158 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
159 MAX77686_BUCK2DVS1_1_3V)) {
160 debug("%s: PMIC %d register write failed\n", __func__,
161 MAX77686_REG_PMIC_BUCK2DVS1);
162 return -1;
163 }
164
165 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
166 MAX77686_BUCK2CTRL_ON))
167 return -1;
168
169 /* VDD_INT */
170 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
171 MAX77686_BUCK3DVS1_1_0125V)) {
172 debug("%s: PMIC %d register write failed\n", __func__,
173 MAX77686_REG_PMIC_BUCK3DVS1);
174 return -1;
175 }
176
177 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
178 MAX77686_BUCK3CTRL_ON))
179 return -1;
180
181 /* VDD_G3D */
182 if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
183 MAX77686_BUCK4DVS1_1_2V)) {
184 debug("%s: PMIC %d register write failed\n", __func__,
185 MAX77686_REG_PMIC_BUCK4DVS1);
186 return -1;
187 }
188
189 if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
190 MAX77686_BUCK3CTRL_ON))
191 return -1;
192
193 /* VDD_LDO2 */
194 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
195 MAX77686_LD02CTRL1_1_5V | EN_LDO))
196 return -1;
197
198 /* VDD_LDO3 */
199 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
200 MAX77686_LD03CTRL1_1_8V | EN_LDO))
201 return -1;
202
203 /* VDD_LDO5 */
204 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
205 MAX77686_LD05CTRL1_1_8V | EN_LDO))
206 return -1;
207
208 /* VDD_LDO10 */
209 if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
210 MAX77686_LD10CTRL1_1_8V | EN_LDO))
211 return -1;
212
213 return 0;
Rajeshwari Shinde211e8432012-12-10 01:55:48 +0000214}
215#endif
216
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000217void dram_init_banksize(void)
218{
Amar752f4c42013-04-27 11:42:57 +0530219 int i;
220 u32 addr, size;
221 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
222 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
223 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
224 gd->bd->bi_dram[i].start = addr;
225 gd->bd->bi_dram[i].size = size;
Hatim RV3ea93942012-12-11 00:52:47 +0000226 }
Hatim RV3ea93942012-12-11 00:52:47 +0000227}
Hatim RV3ea93942012-12-11 00:52:47 +0000228
Chander Kashyapbf936212012-02-09 01:26:19 +0000229int board_eth_init(bd_t *bis)
230{
231#ifdef CONFIG_SMC911X
Hatim RV3ea93942012-12-11 00:52:47 +0000232 u32 smc_bw_conf, smc_bc_conf;
233 struct fdt_sromc config;
234 fdt_addr_t base_addr;
Hatim RV3ea93942012-12-11 00:52:47 +0000235
Hatim RV3ea93942012-12-11 00:52:47 +0000236 /* Non-FDT configuration - bank number and timing parameters*/
237 config.bank = CONFIG_ENV_SROM_BANK;
238 config.width = 2;
239
240 config.timing[FDT_SROM_TACS] = 0x01;
241 config.timing[FDT_SROM_TCOS] = 0x01;
242 config.timing[FDT_SROM_TACC] = 0x06;
243 config.timing[FDT_SROM_TCOH] = 0x01;
244 config.timing[FDT_SROM_TAH] = 0x0C;
245 config.timing[FDT_SROM_TACP] = 0x09;
246 config.timing[FDT_SROM_PMC] = 0x01;
247 base_addr = CONFIG_SMC911X_BASE;
Hatim RV3ea93942012-12-11 00:52:47 +0000248
249 /* Ethernet needs data bus width of 16 bits */
250 if (config.width != 2) {
251 debug("%s: Unsupported bus width %d\n", __func__,
252 config.width);
253 return -1;
254 }
255 smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
256 | SROMC_BYTE_ENABLE(config.bank);
257
258 smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS]) |\
259 SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |\
260 SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |\
261 SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |\
262 SROMC_BC_TAH(config.timing[FDT_SROM_TAH]) |\
263 SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |\
264 SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
265
266 /* Select and configure the SROMC bank */
267 exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
268 s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
269 return smc911x_initialize(0, base_addr);
Chander Kashyapbf936212012-02-09 01:26:19 +0000270#endif
271 return 0;
272}
273
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000274#ifdef CONFIG_DISPLAY_BOARDINFO
275int checkboard(void)
276{
Rajeshwari Shinde07f17502013-02-18 02:51:49 +0000277 printf("\nBoard: SMDK5250\n");
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000278 return 0;
279}
280#endif
281
282#ifdef CONFIG_GENERIC_MMC
283int board_mmc_init(bd_t *bis)
284{
Amar752f4c42013-04-27 11:42:57 +0530285 int err, ret = 0, index, bus_width;
286 u32 base;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000287
Rajeshwari Shinde41222c22012-07-03 20:03:00 +0000288 err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
Amar752f4c42013-04-27 11:42:57 +0530289 if (err)
Rajeshwari Shinde41222c22012-07-03 20:03:00 +0000290 debug("SDMMC0 not configured\n");
Amar752f4c42013-04-27 11:42:57 +0530291 ret |= err;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000292
Amar752f4c42013-04-27 11:42:57 +0530293 /*EMMC: dwmmc Channel-0 with 8 bit bus width */
294 index = 0;
295 base = samsung_get_base_mmc() + (0x10000 * index);
296 bus_width = 8;
297 err = exynos_dwmci_add_port(index, base, bus_width, (u32)NULL);
298 if (err)
299 debug("dwmmc Channel-0 init failed\n");
300 ret |= err;
301
302 err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
303 if (err)
304 debug("SDMMC2 not configured\n");
305 ret |= err;
306
307 /*SD: dwmmc Channel-2 with 4 bit bus width */
308 index = 2;
309 base = samsung_get_base_mmc() + (0x10000 * index);
310 bus_width = 4;
311 err = exynos_dwmci_add_port(index, base, bus_width, (u32)NULL);
312 if (err)
313 debug("dwmmc Channel-2 init failed\n");
314 ret |= err;
315
316 return ret;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000317}
318#endif
319
Rajeshwari Shindec6baaa62012-06-06 19:54:30 +0000320static int board_uart_init(void)
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000321{
Amar752f4c42013-04-27 11:42:57 +0530322 int err, uart_id, ret = 0;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000323
Amar752f4c42013-04-27 11:42:57 +0530324 for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
325 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
326 if (err) {
327 debug("UART%d not configured\n",
328 (uart_id - PERIPH_ID_UART0));
329 ret |= err;
330 }
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000331 }
Amar752f4c42013-04-27 11:42:57 +0530332 return ret;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000333}
334
Amar1ae76d42013-07-10 10:42:29 +0530335void board_i2c_init(const void *blob)
336{
337 int i;
338
339 for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) {
340 exynos_pinmux_config((PERIPH_ID_I2C0 + i),
341 PINMUX_FLAG_NONE);
342 }
343}
344
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000345#ifdef CONFIG_BOARD_EARLY_INIT_F
346int board_early_init_f(void)
347{
Rajeshwari Shindec82b0502012-07-23 21:23:55 +0000348 int err;
349 err = board_uart_init();
350 if (err) {
351 debug("UART init failed\n");
352 return err;
353 }
354#ifdef CONFIG_SYS_I2C_INIT_BOARD
Amar752f4c42013-04-27 11:42:57 +0530355 board_i2c_init(NULL);
Rajeshwari Shindec82b0502012-07-23 21:23:55 +0000356#endif
357 return err;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000358}
359#endif
Ajay Kumar9b572852013-01-08 20:42:26 +0000360
Ajay Kumar99e51622013-01-10 21:06:10 +0000361#ifdef CONFIG_LCD
Ajay Kumar29fd5702013-02-21 23:52:57 +0000362void exynos_cfg_lcd_gpio(void)
Ajay Kumar9b572852013-01-08 20:42:26 +0000363{
364 struct exynos5_gpio_part1 *gpio1 =
365 (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
366
367 /* For Backlight */
368 s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT);
369 s5p_gpio_set_value(&gpio1->b2, 0, 1);
370
371 /* LCD power on */
372 s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT);
373 s5p_gpio_set_value(&gpio1->x1, 5, 1);
374
375 /* Set Hotplug detect for DP */
376 s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3));
377}
378
Ajay Kumar18637812013-02-21 23:53:09 +0000379void exynos_set_dp_phy(unsigned int onoff)
380{
381 set_dp_phy_ctrl(onoff);
382}
383
Ajay Kumar9b572852013-01-08 20:42:26 +0000384vidinfo_t panel_info = {
385 .vl_freq = 60,
386 .vl_col = 2560,
387 .vl_row = 1600,
388 .vl_width = 2560,
389 .vl_height = 1600,
390 .vl_clkp = CONFIG_SYS_LOW,
391 .vl_hsp = CONFIG_SYS_LOW,
392 .vl_vsp = CONFIG_SYS_LOW,
393 .vl_dp = CONFIG_SYS_LOW,
394 .vl_bpix = 4, /* LCD_BPP = 2^4, for output conosle on LCD */
395
396 /* wDP panel timing infomation */
397 .vl_hspw = 32,
398 .vl_hbpd = 80,
399 .vl_hfpd = 48,
400
401 .vl_vspw = 6,
402 .vl_vbpd = 37,
403 .vl_vfpd = 3,
404 .vl_cmd_allow_len = 0xf,
405
406 .win_id = 3,
Ajay Kumar9b572852013-01-08 20:42:26 +0000407 .dual_lcd_enabled = 0,
408
409 .init_delay = 0,
410 .power_on_delay = 0,
411 .reset_delay = 0,
412 .interface_mode = FIMD_RGB_INTERFACE,
413 .dp_enabled = 1,
414};
415
416static struct edp_device_info edp_info = {
417 .disp_info = {
418 .h_res = 2560,
419 .h_sync_width = 32,
420 .h_back_porch = 80,
421 .h_front_porch = 48,
422 .v_res = 1600,
423 .v_sync_width = 6,
424 .v_back_porch = 37,
425 .v_front_porch = 3,
426 .v_sync_rate = 60,
427 },
428 .lt_info = {
429 .lt_status = DP_LT_NONE,
430 },
431 .video_info = {
432 .master_mode = 0,
433 .bist_mode = DP_DISABLE,
434 .bist_pattern = NO_PATTERN,
435 .h_sync_polarity = 0,
436 .v_sync_polarity = 0,
437 .interlaced = 0,
438 .color_space = COLOR_RGB,
439 .dynamic_range = VESA,
440 .ycbcr_coeff = COLOR_YCBCR601,
441 .color_depth = COLOR_8,
442 },
443};
444
445static struct exynos_dp_platform_data dp_platform_data = {
Ajay Kumar9b572852013-01-08 20:42:26 +0000446 .edp_dev_info = &edp_info,
447};
448
449void init_panel_info(vidinfo_t *vid)
450{
Amar752f4c42013-04-27 11:42:57 +0530451 vid->rgb_mode = MODE_RGB_P;
Ajay Kumar9b572852013-01-08 20:42:26 +0000452 exynos_set_dp_platform_data(&dp_platform_data);
453}
Ajay Kumar99e51622013-01-10 21:06:10 +0000454#endif