blob: debc4c57ffa068c14b3f2f2b7047942895b10f63 [file] [log] [blame]
Minkyu Kang72b81d32010-05-31 22:02:42 +09001/*
2 * Copyright (C) 2008-2009 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Minkyu Kang72b81d32010-05-31 22:02:42 +09007 */
8
9#include <common.h>
Simon Glass903fd792014-10-20 19:48:37 -060010#include <asm/gpio.h>
Minkyu Kang87f314e2010-07-06 20:58:41 +090011#include <asm/arch/mmc.h>
Jaehoon Chungcf2a6932017-01-03 09:43:28 +090012#include <dm.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000013#include <power/pmic.h>
Marek Vasut5d5716e2015-12-04 02:51:20 +010014#include <usb/dwc2_udc.h>
Lukasz Majewskia954da22011-10-27 10:36:47 +020015#include <asm/arch/cpu.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000016#include <power/max8998_pmic.h>
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010017#include <samsung/misc.h>
Mateusz Zalega2d281b32014-04-28 21:13:30 +020018#include <usb.h>
19#include <usb_mass_storage.h>
Simon Glassc62db352017-05-31 19:47:48 -060020#include <asm/mach-types.h>
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010021
Minkyu Kang72b81d32010-05-31 22:02:42 +090022DECLARE_GLOBAL_DATA_PTR;
23
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010024u32 get_board_rev(void)
25{
26 return 0;
27}
28
Minkyu Kang72b81d32010-05-31 22:02:42 +090029int board_init(void)
30{
Minkyu Kang87f314e2010-07-06 20:58:41 +090031 /* Set Initial global variables */
Minkyu Kang72b81d32010-05-31 22:02:42 +090032 gd->bd->bi_arch_number = MACH_TYPE_GONI;
33 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
34
Łukasz Majewski0ecdab62012-11-13 03:22:16 +000035 return 0;
36}
37
Robert Baldyga4d383952014-10-06 14:33:11 +020038#ifdef CONFIG_SYS_I2C_INIT_BOARD
39void 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
Minkyu Kang72b81d32010-05-31 22:02:42 +090048int dram_init(void)
49{
Minkyu Kang177feff2010-11-22 20:27:44 +090050 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
51 PHYS_SDRAM_3_SIZE;
52
53 return 0;
54}
55
Simon Glass76b00ac2017-03-31 08:40:32 -060056int dram_init_banksize(void)
Minkyu Kang177feff2010-11-22 20:27:44 +090057{
Minkyu Kang72b81d32010-05-31 22:02:42 +090058 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;
Simon Glass76b00ac2017-03-31 08:40:32 -060064
65 return 0;
Minkyu Kang72b81d32010-05-31 22:02:42 +090066}
67
68#ifdef CONFIG_DISPLAY_BOARDINFO
69int checkboard(void)
70{
71 puts("Board:\tGoni\n");
72 return 0;
73}
74#endif
Minkyu Kang87f314e2010-07-06 20:58:41 +090075
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +090076#ifdef CONFIG_MMC
Minkyu Kang87f314e2010-07-06 20:58:41 +090077int board_mmc_init(bd_t *bis)
78{
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +020079 int i, ret, ret_sd = 0;
Minkyu Kang87f314e2010-07-06 20:58:41 +090080
81 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
Simon Glass7f196102014-10-20 19:48:39 -060082 gpio_request(S5PC110_GPIO_J27, "massmemory_en");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053083 gpio_direction_output(S5PC110_GPIO_J27, 1);
Minkyu Kang87f314e2010-07-06 20:58:41 +090084
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 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053092 for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) {
93 if (i == S5PC110_GPIO_G02)
Minkyu Kang87f314e2010-07-06 20:58:41 +090094 continue;
95 /* GPG0[0:6] special function 2 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053096 gpio_cfg_pin(i, 0x2);
Minkyu Kang87f314e2010-07-06 20:58:41 +090097 /* GPG0[0:6] pull disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053098 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Minkyu Kang87f314e2010-07-06 20:58:41 +090099 /* GPG0[0:6] drv 4x */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530100 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Minkyu Kang87f314e2010-07-06 20:58:41 +0900101 }
102
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200103 ret = s5p_mmc_init(0, 4);
104 if (ret)
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900105 pr_err("MMC: Failed to init MMC:0.\n");
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200106
107 /*
108 * SD card (T_FLASH) detect and init
109 * T_FLASH_DETECT: EINT28: GPH3[4] input mode
110 */
Simon Glass7f196102014-10-20 19:48:39 -0600111 gpio_request(S5PC110_GPIO_H34, "t_flash_detect");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530112 gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT);
113 gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200114
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530115 if (!gpio_get_value(S5PC110_GPIO_H34)) {
116 for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) {
117 if (i == S5PC110_GPIO_G22)
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200118 continue;
119
120 /* GPG2[0:6] special function 2 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530121 gpio_cfg_pin(i, 0x2);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200122 /* GPG2[0:6] pull disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530123 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200124 /* GPG2[0:6] drv 4x */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530125 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200126 }
127
128 ret_sd = s5p_mmc_init(2, 4);
129 if (ret_sd)
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900130 pr_err("MMC: Failed to init SD card (MMC:2).\n");
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200131 }
132
133 return ret & ret_sd;
Minkyu Kang87f314e2010-07-06 20:58:41 +0900134}
135#endif
Lukasz Majewskia954da22011-10-27 10:36:47 +0200136
137#ifdef CONFIG_USB_GADGET
138static int s5pc1xx_phy_control(int on)
139{
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900140 struct udevice *dev;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200141 static int status;
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900142 int reg, ret;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200143
Jaehoon Chungfd3b7102017-01-05 16:55:14 +0900144 ret = pmic_get("max8998-pmic", &dev);
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900145 if (ret)
146 return ret;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200147
148 if (on && !status) {
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900149 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
150 reg |= MAX8998_LDO3;
151 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
Lukasz Majewskia954da22011-10-27 10:36:47 +0200152 if (ret) {
153 puts("MAX8998 LDO setting error!\n");
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900154 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;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200163 }
164 status = 1;
165 } else if (!on && status) {
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900166 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
167 reg &= ~MAX8998_LDO3;
168 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
Lukasz Majewskia954da22011-10-27 10:36:47 +0200169 if (ret) {
170 puts("MAX8998 LDO setting error!\n");
Jaehoon Chungcf2a6932017-01-03 09:43:28 +0900171 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;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200180 }
181 status = 0;
182 }
183 udelay(10000);
Lukasz Majewskia954da22011-10-27 10:36:47 +0200184 return 0;
185}
186
Marek Vasutc0982872015-12-04 02:23:29 +0100187struct dwc2_plat_otg_data s5pc110_otg_data = {
Lukasz Majewskia954da22011-10-27 10:36:47 +0200188 .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};
Mateusz Zalega2d281b32014-04-28 21:13:30 +0200193
194int board_usb_init(int index, enum usb_init_type init)
195{
196 debug("USB_udc_probe\n");
Marek Vasuta4bb9b32015-12-04 02:26:33 +0100197 return dwc2_udc_probe(&s5pc110_otg_data);
Mateusz Zalega2d281b32014-04-28 21:13:30 +0200198}
Lukasz Majewskia954da22011-10-27 10:36:47 +0200199#endif
Piotr Wilczek2ac9a352014-01-22 15:54:33 +0100200
201#ifdef CONFIG_MISC_INIT_R
202int 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
Lukasz Majewski1118ecd2015-03-03 17:32:04 +0100210
211int board_usb_cleanup(int index, enum usb_init_type init)
212{
213 return 0;
214}