blob: ae1f077c4c0e2d4387fec1a98a683858f4a47abb [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
335#ifdef CONFIG_BOARD_EARLY_INIT_F
336int board_early_init_f(void)
337{
Rajeshwari Shindec82b0502012-07-23 21:23:55 +0000338 int err;
339 err = board_uart_init();
340 if (err) {
341 debug("UART init failed\n");
342 return err;
343 }
344#ifdef CONFIG_SYS_I2C_INIT_BOARD
Amar752f4c42013-04-27 11:42:57 +0530345 board_i2c_init(NULL);
Rajeshwari Shindec82b0502012-07-23 21:23:55 +0000346#endif
347 return err;
Chander Kashyap0aee53b2012-02-05 23:01:47 +0000348}
349#endif
Ajay Kumar9b572852013-01-08 20:42:26 +0000350
Ajay Kumar99e51622013-01-10 21:06:10 +0000351#ifdef CONFIG_LCD
Ajay Kumar29fd5702013-02-21 23:52:57 +0000352void exynos_cfg_lcd_gpio(void)
Ajay Kumar9b572852013-01-08 20:42:26 +0000353{
354 struct exynos5_gpio_part1 *gpio1 =
355 (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
356
357 /* For Backlight */
358 s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT);
359 s5p_gpio_set_value(&gpio1->b2, 0, 1);
360
361 /* LCD power on */
362 s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT);
363 s5p_gpio_set_value(&gpio1->x1, 5, 1);
364
365 /* Set Hotplug detect for DP */
366 s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3));
367}
368
Ajay Kumar18637812013-02-21 23:53:09 +0000369void exynos_set_dp_phy(unsigned int onoff)
370{
371 set_dp_phy_ctrl(onoff);
372}
373
Ajay Kumar9b572852013-01-08 20:42:26 +0000374vidinfo_t panel_info = {
375 .vl_freq = 60,
376 .vl_col = 2560,
377 .vl_row = 1600,
378 .vl_width = 2560,
379 .vl_height = 1600,
380 .vl_clkp = CONFIG_SYS_LOW,
381 .vl_hsp = CONFIG_SYS_LOW,
382 .vl_vsp = CONFIG_SYS_LOW,
383 .vl_dp = CONFIG_SYS_LOW,
384 .vl_bpix = 4, /* LCD_BPP = 2^4, for output conosle on LCD */
385
386 /* wDP panel timing infomation */
387 .vl_hspw = 32,
388 .vl_hbpd = 80,
389 .vl_hfpd = 48,
390
391 .vl_vspw = 6,
392 .vl_vbpd = 37,
393 .vl_vfpd = 3,
394 .vl_cmd_allow_len = 0xf,
395
396 .win_id = 3,
Ajay Kumar9b572852013-01-08 20:42:26 +0000397 .dual_lcd_enabled = 0,
398
399 .init_delay = 0,
400 .power_on_delay = 0,
401 .reset_delay = 0,
402 .interface_mode = FIMD_RGB_INTERFACE,
403 .dp_enabled = 1,
404};
405
406static struct edp_device_info edp_info = {
407 .disp_info = {
408 .h_res = 2560,
409 .h_sync_width = 32,
410 .h_back_porch = 80,
411 .h_front_porch = 48,
412 .v_res = 1600,
413 .v_sync_width = 6,
414 .v_back_porch = 37,
415 .v_front_porch = 3,
416 .v_sync_rate = 60,
417 },
418 .lt_info = {
419 .lt_status = DP_LT_NONE,
420 },
421 .video_info = {
422 .master_mode = 0,
423 .bist_mode = DP_DISABLE,
424 .bist_pattern = NO_PATTERN,
425 .h_sync_polarity = 0,
426 .v_sync_polarity = 0,
427 .interlaced = 0,
428 .color_space = COLOR_RGB,
429 .dynamic_range = VESA,
430 .ycbcr_coeff = COLOR_YCBCR601,
431 .color_depth = COLOR_8,
432 },
433};
434
435static struct exynos_dp_platform_data dp_platform_data = {
Ajay Kumar9b572852013-01-08 20:42:26 +0000436 .edp_dev_info = &edp_info,
437};
438
439void init_panel_info(vidinfo_t *vid)
440{
Amar752f4c42013-04-27 11:42:57 +0530441 vid->rgb_mode = MODE_RGB_P;
Ajay Kumar9b572852013-01-08 20:42:26 +0000442 exynos_set_dp_platform_data(&dp_platform_data);
443}
Ajay Kumar99e51622013-01-10 21:06:10 +0000444#endif