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