1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2008-2009 Samsung Electronics
4  *  Minkyu Kang <mk7.kang@samsung.com>
5  *  Kyungmin Park <kyungmin.park@samsung.com>
6  */
7 
8 #include <common.h>
9 #include <init.h>
10 #include <log.h>
11 #include <asm/global_data.h>
12 #include <asm/gpio.h>
13 #include <asm/arch/mmc.h>
14 #include <dm.h>
15 #include <linux/delay.h>
16 #include <power/pmic.h>
17 #include <usb/dwc2_udc.h>
18 #include <asm/arch/cpu.h>
19 #include <power/max8998_pmic.h>
20 #include <samsung/misc.h>
21 #include <usb.h>
22 #include <usb_mass_storage.h>
23 #include <asm/mach-types.h>
24 
25 DECLARE_GLOBAL_DATA_PTR;
26 
get_board_rev(void)27 u32 get_board_rev(void)
28 {
29 	return 0;
30 }
31 
board_init(void)32 int board_init(void)
33 {
34 	/* Set Initial global variables */
35 	gd->bd->bi_arch_number = MACH_TYPE_GONI;
36 	gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
37 
38 	return 0;
39 }
40 
41 #ifdef CONFIG_SYS_I2C_INIT_BOARD
i2c_init_board(void)42 void i2c_init_board(void)
43 {
44 	gpio_request(S5PC110_GPIO_J43, "i2c_clk");
45 	gpio_request(S5PC110_GPIO_J40, "i2c_data");
46 	gpio_direction_output(S5PC110_GPIO_J43, 1);
47 	gpio_direction_output(S5PC110_GPIO_J40, 1);
48 }
49 #endif
50 
dram_init(void)51 int dram_init(void)
52 {
53 	gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
54 			PHYS_SDRAM_3_SIZE;
55 
56 	return 0;
57 }
58 
dram_init_banksize(void)59 int dram_init_banksize(void)
60 {
61 	gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
62 	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
63 	gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
64 	gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
65 	gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
66 	gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
67 
68 	return 0;
69 }
70 
71 #ifdef CONFIG_DISPLAY_BOARDINFO
checkboard(void)72 int checkboard(void)
73 {
74 	puts("Board:\tGoni\n");
75 	return 0;
76 }
77 #endif
78 
79 #ifdef CONFIG_MMC
board_mmc_init(struct bd_info * bis)80 int board_mmc_init(struct bd_info *bis)
81 {
82 	int i, ret, ret_sd = 0;
83 
84 	/* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
85 	gpio_request(S5PC110_GPIO_J27, "massmemory_en");
86 	gpio_direction_output(S5PC110_GPIO_J27, 1);
87 
88 	/*
89 	 * MMC0 GPIO
90 	 * GPG0[0]	SD_0_CLK
91 	 * GPG0[1]	SD_0_CMD
92 	 * GPG0[2]	SD_0_CDn	-> Not used
93 	 * GPG0[3:6]	SD_0_DATA[0:3]
94 	 */
95 	for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) {
96 		if (i == S5PC110_GPIO_G02)
97 			continue;
98 		/* GPG0[0:6] special function 2 */
99 		gpio_cfg_pin(i, 0x2);
100 		/* GPG0[0:6] pull disable */
101 		gpio_set_pull(i, S5P_GPIO_PULL_NONE);
102 		/* GPG0[0:6] drv 4x */
103 		gpio_set_drv(i, S5P_GPIO_DRV_4X);
104 	}
105 
106 	ret = s5p_mmc_init(0, 4);
107 	if (ret)
108 		pr_err("MMC: Failed to init MMC:0.\n");
109 
110 	/*
111 	 * SD card (T_FLASH) detect and init
112 	 * T_FLASH_DETECT: EINT28: GPH3[4] input mode
113 	 */
114 	gpio_request(S5PC110_GPIO_H34, "t_flash_detect");
115 	gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT);
116 	gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP);
117 
118 	if (!gpio_get_value(S5PC110_GPIO_H34)) {
119 		for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) {
120 			if (i == S5PC110_GPIO_G22)
121 				continue;
122 
123 			/* GPG2[0:6] special function 2 */
124 			gpio_cfg_pin(i, 0x2);
125 			/* GPG2[0:6] pull disable */
126 			gpio_set_pull(i, S5P_GPIO_PULL_NONE);
127 			/* GPG2[0:6] drv 4x */
128 			gpio_set_drv(i, S5P_GPIO_DRV_4X);
129 		}
130 
131 		ret_sd = s5p_mmc_init(2, 4);
132 		if (ret_sd)
133 			pr_err("MMC: Failed to init SD card (MMC:2).\n");
134 	}
135 
136 	return ret & ret_sd;
137 }
138 #endif
139 
140 #ifdef CONFIG_USB_GADGET
s5pc1xx_phy_control(int on)141 static int s5pc1xx_phy_control(int on)
142 {
143 	struct udevice *dev;
144 	static int status;
145 	int reg, ret;
146 
147 	ret = pmic_get("max8998-pmic", &dev);
148 	if (ret)
149 		return ret;
150 
151 	if (on && !status) {
152 		reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
153 		reg |= MAX8998_LDO3;
154 		ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
155 		if (ret) {
156 			puts("MAX8998 LDO setting error!\n");
157 			return -EINVAL;
158 		}
159 
160 		reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
161 		reg |= MAX8998_LDO8;
162 		ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
163 		if (ret) {
164 			puts("MAX8998 LDO setting error!\n");
165 			return -EINVAL;
166 		}
167 		status = 1;
168 	} else if (!on && status) {
169 		reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
170 		reg &= ~MAX8998_LDO3;
171 		ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
172 		if (ret) {
173 			puts("MAX8998 LDO setting error!\n");
174 			return -EINVAL;
175 		}
176 
177 		reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
178 		reg &= ~MAX8998_LDO8;
179 		ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
180 		if (ret) {
181 			puts("MAX8998 LDO setting error!\n");
182 			return -EINVAL;
183 		}
184 		status = 0;
185 	}
186 	udelay(10000);
187 	return 0;
188 }
189 
190 struct dwc2_plat_otg_data s5pc110_otg_data = {
191 	.phy_control = s5pc1xx_phy_control,
192 	.regs_phy = S5PC110_PHY_BASE,
193 	.regs_otg = S5PC110_OTG_BASE,
194 	.usb_phy_ctrl = S5PC110_USB_PHY_CONTROL,
195 };
196 
board_usb_init(int index,enum usb_init_type init)197 int board_usb_init(int index, enum usb_init_type init)
198 {
199 	debug("USB_udc_probe\n");
200 	return dwc2_udc_probe(&s5pc110_otg_data);
201 }
202 #endif
203 
204 #ifdef CONFIG_MISC_INIT_R
misc_init_r(void)205 int misc_init_r(void)
206 {
207 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
208 	set_board_info();
209 #endif
210 	return 0;
211 }
212 #endif
213 
board_usb_cleanup(int index,enum usb_init_type init)214 int board_usb_cleanup(int index, enum usb_init_type init)
215 {
216 	return 0;
217 }
218