blob: b32b82fc2dadbee80e5dcb590f6e98a6ca393353 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Minkyu Kang194cbce2010-05-31 22:02:42 +09002/*
3 * Copyright (C) 2008-2009 Samsung Electronics
4 * Minkyu Kang <mk7.kang@samsung.com>
5 * Kyungmin Park <kyungmin.park@samsung.com>
Minkyu Kang194cbce2010-05-31 22:02:42 +09006 */
7
8#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glass37f11622014-10-20 19:48:37 -060012#include <asm/gpio.h>
Minkyu Kang2111b2d2010-07-06 20:58:41 +090013#include <asm/arch/mmc.h>
Jaehoon Chunge892d602017-01-03 09:43:28 +090014#include <dm.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000016#include <power/pmic.h>
Marek Vasutf1be9cb2015-12-04 02:51:20 +010017#include <usb/dwc2_udc.h>
Lukasz Majewski35be8502011-10-27 10:36:47 +020018#include <asm/arch/cpu.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000019#include <power/max8998_pmic.h>
Piotr Wilczekc88b89e2014-01-22 15:54:33 +010020#include <samsung/misc.h>
Mateusz Zalega381709a2014-04-28 21:13:30 +020021#include <usb.h>
22#include <usb_mass_storage.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060023#include <asm/mach-types.h>
Piotr Wilczekc88b89e2014-01-22 15:54:33 +010024
Minkyu Kang194cbce2010-05-31 22:02:42 +090025DECLARE_GLOBAL_DATA_PTR;
26
Piotr Wilczekc88b89e2014-01-22 15:54:33 +010027u32 get_board_rev(void)
28{
29 return 0;
30}
31
Minkyu Kang194cbce2010-05-31 22:02:42 +090032int board_init(void)
33{
Minkyu Kang2111b2d2010-07-06 20:58:41 +090034 /* Set Initial global variables */
Minkyu Kang194cbce2010-05-31 22:02:42 +090035 gd->bd->bi_arch_number = MACH_TYPE_GONI;
36 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
37
Łukasz Majewski0fcc9a52012-11-13 03:22:16 +000038 return 0;
39}
40
Robert Baldyga20f67cf2014-10-06 14:33:11 +020041#ifdef CONFIG_SYS_I2C_INIT_BOARD
42void i2c_init_board(void)
43{
44 gpio_request(S5PC110_GPIO_J43, "i2c_clk");
45 gpio_request(S5PC110_GPIO_J40, "i2c_data");
46 gpio_direction_output(S5PC110_GPIO_J43, 1);
47 gpio_direction_output(S5PC110_GPIO_J40, 1);
48}
49#endif
50
Minkyu Kang194cbce2010-05-31 22:02:42 +090051int dram_init(void)
52{
Minkyu Kang00ab1762010-11-22 20:27:44 +090053 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
54 PHYS_SDRAM_3_SIZE;
55
56 return 0;
57}
58
Simon Glass2f949c32017-03-31 08:40:32 -060059int dram_init_banksize(void)
Minkyu Kang00ab1762010-11-22 20:27:44 +090060{
Minkyu Kang194cbce2010-05-31 22:02:42 +090061 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
62 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
63 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
64 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
65 gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
66 gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060067
68 return 0;
Minkyu Kang194cbce2010-05-31 22:02:42 +090069}
70
71#ifdef CONFIG_DISPLAY_BOARDINFO
72int checkboard(void)
73{
74 puts("Board:\tGoni\n");
75 return 0;
76}
77#endif
Minkyu Kang2111b2d2010-07-06 20:58:41 +090078
Masahiro Yamada0a780172017-05-09 20:31:39 +090079#ifdef CONFIG_MMC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090080int board_mmc_init(struct bd_info *bis)
Minkyu Kang2111b2d2010-07-06 20:58:41 +090081{
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +020082 int i, ret, ret_sd = 0;
Minkyu Kang2111b2d2010-07-06 20:58:41 +090083
84 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
Simon Glass4f83d3d2014-10-20 19:48:39 -060085 gpio_request(S5PC110_GPIO_J27, "massmemory_en");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053086 gpio_direction_output(S5PC110_GPIO_J27, 1);
Minkyu Kang2111b2d2010-07-06 20:58:41 +090087
88 /*
89 * MMC0 GPIO
90 * GPG0[0] SD_0_CLK
91 * GPG0[1] SD_0_CMD
92 * GPG0[2] SD_0_CDn -> Not used
93 * GPG0[3:6] SD_0_DATA[0:3]
94 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053095 for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) {
96 if (i == S5PC110_GPIO_G02)
Minkyu Kang2111b2d2010-07-06 20:58:41 +090097 continue;
98 /* GPG0[0:6] special function 2 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053099 gpio_cfg_pin(i, 0x2);
Minkyu Kang2111b2d2010-07-06 20:58:41 +0900100 /* GPG0[0:6] pull disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530101 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Minkyu Kang2111b2d2010-07-06 20:58:41 +0900102 /* GPG0[0:6] drv 4x */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530103 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Minkyu Kang2111b2d2010-07-06 20:58:41 +0900104 }
105
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200106 ret = s5p_mmc_init(0, 4);
107 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +0900108 pr_err("MMC: Failed to init MMC:0.\n");
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200109
110 /*
111 * SD card (T_FLASH) detect and init
112 * T_FLASH_DETECT: EINT28: GPH3[4] input mode
113 */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600114 gpio_request(S5PC110_GPIO_H34, "t_flash_detect");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530115 gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT);
116 gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200117
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530118 if (!gpio_get_value(S5PC110_GPIO_H34)) {
119 for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) {
120 if (i == S5PC110_GPIO_G22)
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200121 continue;
122
123 /* GPG2[0:6] special function 2 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530124 gpio_cfg_pin(i, 0x2);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200125 /* GPG2[0:6] pull disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530126 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200127 /* GPG2[0:6] drv 4x */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530128 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200129 }
130
131 ret_sd = s5p_mmc_init(2, 4);
132 if (ret_sd)
Masahiro Yamada81e10422017-09-16 14:10:41 +0900133 pr_err("MMC: Failed to init SD card (MMC:2).\n");
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200134 }
135
136 return ret & ret_sd;
Minkyu Kang2111b2d2010-07-06 20:58:41 +0900137}
138#endif
Lukasz Majewski35be8502011-10-27 10:36:47 +0200139
140#ifdef CONFIG_USB_GADGET
141static int s5pc1xx_phy_control(int on)
142{
Jaehoon Chunge892d602017-01-03 09:43:28 +0900143 struct udevice *dev;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200144 static int status;
Jaehoon Chunge892d602017-01-03 09:43:28 +0900145 int reg, ret;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200146
Jaehoon Chung5026af62017-01-05 16:55:14 +0900147 ret = pmic_get("max8998-pmic", &dev);
Jaehoon Chunge892d602017-01-03 09:43:28 +0900148 if (ret)
149 return ret;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200150
151 if (on && !status) {
Jaehoon Chunge892d602017-01-03 09:43:28 +0900152 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
153 reg |= MAX8998_LDO3;
154 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200155 if (ret) {
156 puts("MAX8998 LDO setting error!\n");
Jaehoon Chunge892d602017-01-03 09:43:28 +0900157 return -EINVAL;
158 }
159
160 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
161 reg |= MAX8998_LDO8;
162 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
163 if (ret) {
164 puts("MAX8998 LDO setting error!\n");
165 return -EINVAL;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200166 }
167 status = 1;
168 } else if (!on && status) {
Jaehoon Chunge892d602017-01-03 09:43:28 +0900169 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
170 reg &= ~MAX8998_LDO3;
171 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
172 if (ret) {
173 puts("MAX8998 LDO setting error!\n");
174 return -EINVAL;
175 }
176
177 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
178 reg &= ~MAX8998_LDO8;
179 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200180 if (ret) {
181 puts("MAX8998 LDO setting error!\n");
Jaehoon Chunge892d602017-01-03 09:43:28 +0900182 return -EINVAL;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200183 }
184 status = 0;
185 }
186 udelay(10000);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200187 return 0;
188}
189
Marek Vasut6939aca2015-12-04 02:23:29 +0100190struct dwc2_plat_otg_data s5pc110_otg_data = {
Lukasz Majewski35be8502011-10-27 10:36:47 +0200191 .phy_control = s5pc1xx_phy_control,
192 .regs_phy = S5PC110_PHY_BASE,
193 .regs_otg = S5PC110_OTG_BASE,
194 .usb_phy_ctrl = S5PC110_USB_PHY_CONTROL,
195};
Mateusz Zalega381709a2014-04-28 21:13:30 +0200196
197int board_usb_init(int index, enum usb_init_type init)
198{
199 debug("USB_udc_probe\n");
Marek Vasut01b61fa2015-12-04 02:26:33 +0100200 return dwc2_udc_probe(&s5pc110_otg_data);
Mateusz Zalega381709a2014-04-28 21:13:30 +0200201}
Lukasz Majewski35be8502011-10-27 10:36:47 +0200202#endif
Piotr Wilczekc88b89e2014-01-22 15:54:33 +0100203
204#ifdef CONFIG_MISC_INIT_R
205int misc_init_r(void)
206{
207#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
208 set_board_info();
209#endif
210 return 0;
211}
212#endif
Lukasz Majewski3de25702015-03-03 17:32:04 +0100213
214int board_usb_cleanup(int index, enum usb_init_type init)
215{
216 return 0;
217}