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