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