1e21185baSChander Kashyap /*
2e21185baSChander Kashyap  * Copyright (C) 2011 Samsung Electronics
3e21185baSChander Kashyap  *
4*1a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5e21185baSChander Kashyap  */
6e21185baSChander Kashyap 
7e21185baSChander Kashyap #include <common.h>
8e21185baSChander Kashyap #include <asm/io.h>
9e21185baSChander Kashyap #include <netdev.h>
10e21185baSChander Kashyap #include <asm/arch/cpu.h>
11e21185baSChander Kashyap #include <asm/arch/gpio.h>
12e21185baSChander Kashyap #include <asm/arch/mmc.h>
13198a40b9SRajeshwari Shinde #include <asm/arch/periph.h>
14198a40b9SRajeshwari Shinde #include <asm/arch/pinmux.h>
15e21185baSChander Kashyap #include <asm/arch/sromc.h>
16e21185baSChander Kashyap 
17e21185baSChander Kashyap DECLARE_GLOBAL_DATA_PTR;
18393cb361SChander Kashyap struct exynos4_gpio_part1 *gpio1;
19393cb361SChander Kashyap struct exynos4_gpio_part2 *gpio2;
20e21185baSChander Kashyap 
21e21185baSChander Kashyap static void smc9115_pre_init(void)
22e21185baSChander Kashyap {
23e21185baSChander Kashyap 	u32 smc_bw_conf, smc_bc_conf;
24e21185baSChander Kashyap 
25e21185baSChander Kashyap 	/* gpio configuration GPK0CON */
26ef5d9eb9SŁukasz Majewski 	s5p_gpio_cfg_pin(&gpio2->y0, CONFIG_ENV_SROM_BANK, GPIO_FUNC(2));
27e21185baSChander Kashyap 
28e21185baSChander Kashyap 	/* Ethernet needs bus width of 16 bits */
29e21185baSChander Kashyap 	smc_bw_conf = SROMC_DATA16_WIDTH(CONFIG_ENV_SROM_BANK);
30e21185baSChander Kashyap 	smc_bc_conf = SROMC_BC_TACS(0x0F) | SROMC_BC_TCOS(0x0F)
31e21185baSChander Kashyap 			| SROMC_BC_TACC(0x0F) | SROMC_BC_TCOH(0x0F)
32e21185baSChander Kashyap 			| SROMC_BC_TAH(0x0F)  | SROMC_BC_TACP(0x0F)
33e21185baSChander Kashyap 			| SROMC_BC_PMC(0x0F);
34e21185baSChander Kashyap 
35e21185baSChander Kashyap 	/* Select and configure the SROMC bank */
36e21185baSChander Kashyap 	s5p_config_sromc(CONFIG_ENV_SROM_BANK, smc_bw_conf, smc_bc_conf);
37e21185baSChander Kashyap }
38e21185baSChander Kashyap 
39e21185baSChander Kashyap int board_init(void)
40e21185baSChander Kashyap {
41393cb361SChander Kashyap 	gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
42393cb361SChander Kashyap 	gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
43e21185baSChander Kashyap 
44e21185baSChander Kashyap 	smc9115_pre_init();
45e21185baSChander Kashyap 
46e21185baSChander Kashyap 	gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
47e21185baSChander Kashyap 	return 0;
48e21185baSChander Kashyap }
49e21185baSChander Kashyap 
50e21185baSChander Kashyap int dram_init(void)
51e21185baSChander Kashyap {
52e21185baSChander Kashyap 	gd->ram_size	= get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE)
53e21185baSChander Kashyap 			+ get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE)
54e21185baSChander Kashyap 			+ get_ram_size((long *)PHYS_SDRAM_3, PHYS_SDRAM_3_SIZE)
55e21185baSChander Kashyap 			+ get_ram_size((long *)PHYS_SDRAM_4, PHYS_SDRAM_4_SIZE);
56e21185baSChander Kashyap 
57e21185baSChander Kashyap 	return 0;
58e21185baSChander Kashyap }
59e21185baSChander Kashyap 
60e21185baSChander Kashyap void dram_init_banksize(void)
61e21185baSChander Kashyap {
62e21185baSChander Kashyap 	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
639436a0c9SChander Kashyap 	gd->bd->bi_dram[0].size = get_ram_size((long *)PHYS_SDRAM_1, \
649436a0c9SChander Kashyap 							PHYS_SDRAM_1_SIZE);
65e21185baSChander Kashyap 	gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
669436a0c9SChander Kashyap 	gd->bd->bi_dram[1].size = get_ram_size((long *)PHYS_SDRAM_2, \
679436a0c9SChander Kashyap 							PHYS_SDRAM_2_SIZE);
68e21185baSChander Kashyap 	gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
699436a0c9SChander Kashyap 	gd->bd->bi_dram[2].size = get_ram_size((long *)PHYS_SDRAM_3, \
709436a0c9SChander Kashyap 							PHYS_SDRAM_3_SIZE);
71e21185baSChander Kashyap 	gd->bd->bi_dram[3].start = PHYS_SDRAM_4;
729436a0c9SChander Kashyap 	gd->bd->bi_dram[3].size = get_ram_size((long *)PHYS_SDRAM_4, \
739436a0c9SChander Kashyap 							PHYS_SDRAM_4_SIZE);
74e21185baSChander Kashyap }
75e21185baSChander Kashyap 
76e21185baSChander Kashyap int board_eth_init(bd_t *bis)
77e21185baSChander Kashyap {
78e21185baSChander Kashyap 	int rc = 0;
79e21185baSChander Kashyap #ifdef CONFIG_SMC911X
80e21185baSChander Kashyap 	rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
81e21185baSChander Kashyap #endif
82e21185baSChander Kashyap 	return rc;
83e21185baSChander Kashyap }
84e21185baSChander Kashyap 
85e21185baSChander Kashyap #ifdef CONFIG_DISPLAY_BOARDINFO
86e21185baSChander Kashyap int checkboard(void)
87e21185baSChander Kashyap {
88e21185baSChander Kashyap 	printf("\nBoard: SMDKV310\n");
89e21185baSChander Kashyap 	return 0;
90e21185baSChander Kashyap }
91e21185baSChander Kashyap #endif
92e21185baSChander Kashyap 
93e21185baSChander Kashyap #ifdef CONFIG_GENERIC_MMC
94e21185baSChander Kashyap int board_mmc_init(bd_t *bis)
95e21185baSChander Kashyap {
96e21185baSChander Kashyap 	int i, err;
97e21185baSChander Kashyap 
98e21185baSChander Kashyap 	/*
99e21185baSChander Kashyap 	 * MMC2 SD card GPIO:
100e21185baSChander Kashyap 	 *
101e21185baSChander Kashyap 	 * GPK2[0]	SD_2_CLK(2)
102e21185baSChander Kashyap 	 * GPK2[1]	SD_2_CMD(2)
103e21185baSChander Kashyap 	 * GPK2[2]	SD_2_CDn
104e21185baSChander Kashyap 	 * GPK2[3:6]	SD_2_DATA[0:3](2)
105e21185baSChander Kashyap 	 */
106e21185baSChander Kashyap 	for (i = 0; i < 7; i++) {
107e21185baSChander Kashyap 		/* GPK2[0:6] special function 2 */
108ef5d9eb9SŁukasz Majewski 		s5p_gpio_cfg_pin(&gpio2->k2, i, GPIO_FUNC(0x2));
109e21185baSChander Kashyap 
110e21185baSChander Kashyap 		/* GPK2[0:6] drv 4x */
111ef5d9eb9SŁukasz Majewski 		s5p_gpio_set_drv(&gpio2->k2, i, GPIO_DRV_4X);
112e21185baSChander Kashyap 
113e21185baSChander Kashyap 		/* GPK2[0:1] pull disable */
114e21185baSChander Kashyap 		if (i == 0 || i == 1) {
1150e74b565SChander Kashyap 			s5p_gpio_set_pull(&gpio2->k2, i, GPIO_PULL_NONE);
116e21185baSChander Kashyap 			continue;
117e21185baSChander Kashyap 		}
118e21185baSChander Kashyap 
119e21185baSChander Kashyap 		/* GPK2[2:6] pull up */
120ef5d9eb9SŁukasz Majewski 		s5p_gpio_set_pull(&gpio2->k2, i, GPIO_PULL_UP);
121e21185baSChander Kashyap 	}
122e21185baSChander Kashyap 	err = s5p_mmc_init(2, 4);
123e21185baSChander Kashyap 	return err;
124e21185baSChander Kashyap }
125e21185baSChander Kashyap #endif
126198a40b9SRajeshwari Shinde 
127198a40b9SRajeshwari Shinde static int board_uart_init(void)
128198a40b9SRajeshwari Shinde {
129198a40b9SRajeshwari Shinde 	int err;
130198a40b9SRajeshwari Shinde 
131198a40b9SRajeshwari Shinde 	err = exynos_pinmux_config(PERIPH_ID_UART0, PINMUX_FLAG_NONE);
132198a40b9SRajeshwari Shinde 	if (err) {
133198a40b9SRajeshwari Shinde 		debug("UART0 not configured\n");
134198a40b9SRajeshwari Shinde 		return err;
135198a40b9SRajeshwari Shinde 	}
136198a40b9SRajeshwari Shinde 
137198a40b9SRajeshwari Shinde 	err = exynos_pinmux_config(PERIPH_ID_UART1, PINMUX_FLAG_NONE);
138198a40b9SRajeshwari Shinde 	if (err) {
139198a40b9SRajeshwari Shinde 		debug("UART1 not configured\n");
140198a40b9SRajeshwari Shinde 		return err;
141198a40b9SRajeshwari Shinde 	}
142198a40b9SRajeshwari Shinde 
143198a40b9SRajeshwari Shinde 	err = exynos_pinmux_config(PERIPH_ID_UART2, PINMUX_FLAG_NONE);
144198a40b9SRajeshwari Shinde 	if (err) {
145198a40b9SRajeshwari Shinde 		debug("UART2 not configured\n");
146198a40b9SRajeshwari Shinde 		return err;
147198a40b9SRajeshwari Shinde 	}
148198a40b9SRajeshwari Shinde 
149198a40b9SRajeshwari Shinde 	err = exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);
150198a40b9SRajeshwari Shinde 	if (err) {
151198a40b9SRajeshwari Shinde 		debug("UART3 not configured\n");
152198a40b9SRajeshwari Shinde 		return err;
153198a40b9SRajeshwari Shinde 	}
154198a40b9SRajeshwari Shinde 
155198a40b9SRajeshwari Shinde 	return 0;
156198a40b9SRajeshwari Shinde }
157198a40b9SRajeshwari Shinde 
158198a40b9SRajeshwari Shinde #ifdef CONFIG_BOARD_EARLY_INIT_F
159198a40b9SRajeshwari Shinde int board_early_init_f(void)
160198a40b9SRajeshwari Shinde {
161198a40b9SRajeshwari Shinde 	int err;
162198a40b9SRajeshwari Shinde 	err = board_uart_init();
163198a40b9SRajeshwari Shinde 	if (err) {
164198a40b9SRajeshwari Shinde 		debug("UART init failed\n");
165198a40b9SRajeshwari Shinde 		return err;
166198a40b9SRajeshwari Shinde 	}
167198a40b9SRajeshwari Shinde 	return err;
168198a40b9SRajeshwari Shinde }
169198a40b9SRajeshwari Shinde #endif
170