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