blob: c8f5a153bb47f8f8ba91b7ce19f0b356afadf58b [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>
Simon Glassbdd5f812023-09-14 18:21:46 -060016#include <linux/printk.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000017#include <power/pmic.h>
Marek Vasutf1be9cb2015-12-04 02:51:20 +010018#include <usb/dwc2_udc.h>
Lukasz Majewski35be8502011-10-27 10:36:47 +020019#include <asm/arch/cpu.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000020#include <power/max8998_pmic.h>
Piotr Wilczekc88b89e2014-01-22 15:54:33 +010021#include <samsung/misc.h>
Mateusz Zalega381709a2014-04-28 21:13:30 +020022#include <usb.h>
23#include <usb_mass_storage.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060024#include <asm/mach-types.h>
Piotr Wilczekc88b89e2014-01-22 15:54:33 +010025
Minkyu Kang194cbce2010-05-31 22:02:42 +090026DECLARE_GLOBAL_DATA_PTR;
27
28int board_init(void)
29{
Minkyu Kang2111b2d2010-07-06 20:58:41 +090030 /* Set Initial global variables */
Minkyu Kang194cbce2010-05-31 22:02:42 +090031 gd->bd->bi_arch_number = MACH_TYPE_GONI;
32 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
33
Łukasz Majewski0fcc9a52012-11-13 03:22:16 +000034 return 0;
35}
36
Minkyu Kang194cbce2010-05-31 22:02:42 +090037int dram_init(void)
38{
Minkyu Kang00ab1762010-11-22 20:27:44 +090039 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
40 PHYS_SDRAM_3_SIZE;
41
42 return 0;
43}
44
Simon Glass2f949c32017-03-31 08:40:32 -060045int dram_init_banksize(void)
Minkyu Kang00ab1762010-11-22 20:27:44 +090046{
Minkyu Kang194cbce2010-05-31 22:02:42 +090047 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
48 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
49 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
50 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
51 gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
52 gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060053
54 return 0;
Minkyu Kang194cbce2010-05-31 22:02:42 +090055}
56
57#ifdef CONFIG_DISPLAY_BOARDINFO
58int checkboard(void)
59{
60 puts("Board:\tGoni\n");
61 return 0;
62}
63#endif
Minkyu Kang2111b2d2010-07-06 20:58:41 +090064
Masahiro Yamada0a780172017-05-09 20:31:39 +090065#ifdef CONFIG_MMC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090066int board_mmc_init(struct bd_info *bis)
Minkyu Kang2111b2d2010-07-06 20:58:41 +090067{
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +020068 int i, ret, ret_sd = 0;
Minkyu Kang2111b2d2010-07-06 20:58:41 +090069
70 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
Simon Glass4f83d3d2014-10-20 19:48:39 -060071 gpio_request(S5PC110_GPIO_J27, "massmemory_en");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053072 gpio_direction_output(S5PC110_GPIO_J27, 1);
Minkyu Kang2111b2d2010-07-06 20:58:41 +090073
74 /*
75 * MMC0 GPIO
76 * GPG0[0] SD_0_CLK
77 * GPG0[1] SD_0_CMD
78 * GPG0[2] SD_0_CDn -> Not used
79 * GPG0[3:6] SD_0_DATA[0:3]
80 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053081 for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) {
82 if (i == S5PC110_GPIO_G02)
Minkyu Kang2111b2d2010-07-06 20:58:41 +090083 continue;
84 /* GPG0[0:6] special function 2 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053085 gpio_cfg_pin(i, 0x2);
Minkyu Kang2111b2d2010-07-06 20:58:41 +090086 /* GPG0[0:6] pull disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053087 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Minkyu Kang2111b2d2010-07-06 20:58:41 +090088 /* GPG0[0:6] drv 4x */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053089 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Minkyu Kang2111b2d2010-07-06 20:58:41 +090090 }
91
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +020092 ret = s5p_mmc_init(0, 4);
93 if (ret)
Masahiro Yamada81e10422017-09-16 14:10:41 +090094 pr_err("MMC: Failed to init MMC:0.\n");
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +020095
96 /*
97 * SD card (T_FLASH) detect and init
98 * T_FLASH_DETECT: EINT28: GPH3[4] input mode
99 */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600100 gpio_request(S5PC110_GPIO_H34, "t_flash_detect");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530101 gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT);
102 gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200103
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530104 if (!gpio_get_value(S5PC110_GPIO_H34)) {
105 for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) {
106 if (i == S5PC110_GPIO_G22)
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200107 continue;
108
109 /* GPG2[0:6] special function 2 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530110 gpio_cfg_pin(i, 0x2);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200111 /* GPG2[0:6] pull disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530112 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200113 /* GPG2[0:6] drv 4x */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530114 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200115 }
116
117 ret_sd = s5p_mmc_init(2, 4);
118 if (ret_sd)
Masahiro Yamada81e10422017-09-16 14:10:41 +0900119 pr_err("MMC: Failed to init SD card (MMC:2).\n");
Przemyslaw Marczak151d23f2013-09-10 11:34:49 +0200120 }
121
122 return ret & ret_sd;
Minkyu Kang2111b2d2010-07-06 20:58:41 +0900123}
124#endif
Lukasz Majewski35be8502011-10-27 10:36:47 +0200125
126#ifdef CONFIG_USB_GADGET
127static int s5pc1xx_phy_control(int on)
128{
Jaehoon Chunge892d602017-01-03 09:43:28 +0900129 struct udevice *dev;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200130 static int status;
Jaehoon Chunge892d602017-01-03 09:43:28 +0900131 int reg, ret;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200132
Jaehoon Chung5026af62017-01-05 16:55:14 +0900133 ret = pmic_get("max8998-pmic", &dev);
Jaehoon Chunge892d602017-01-03 09:43:28 +0900134 if (ret)
135 return ret;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200136
137 if (on && !status) {
Jaehoon Chunge892d602017-01-03 09:43:28 +0900138 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
139 reg |= MAX8998_LDO3;
140 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200141 if (ret) {
142 puts("MAX8998 LDO setting error!\n");
Jaehoon Chunge892d602017-01-03 09:43:28 +0900143 return -EINVAL;
144 }
145
146 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
147 reg |= MAX8998_LDO8;
148 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
149 if (ret) {
150 puts("MAX8998 LDO setting error!\n");
151 return -EINVAL;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200152 }
153 status = 1;
154 } else if (!on && status) {
Jaehoon Chunge892d602017-01-03 09:43:28 +0900155 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1);
156 reg &= ~MAX8998_LDO3;
157 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg);
158 if (ret) {
159 puts("MAX8998 LDO setting error!\n");
160 return -EINVAL;
161 }
162
163 reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2);
164 reg &= ~MAX8998_LDO8;
165 ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200166 if (ret) {
167 puts("MAX8998 LDO setting error!\n");
Jaehoon Chunge892d602017-01-03 09:43:28 +0900168 return -EINVAL;
Lukasz Majewski35be8502011-10-27 10:36:47 +0200169 }
170 status = 0;
171 }
172 udelay(10000);
Lukasz Majewski35be8502011-10-27 10:36:47 +0200173 return 0;
174}
175
Marek Vasut6939aca2015-12-04 02:23:29 +0100176struct dwc2_plat_otg_data s5pc110_otg_data = {
Lukasz Majewski35be8502011-10-27 10:36:47 +0200177 .phy_control = s5pc1xx_phy_control,
178 .regs_phy = S5PC110_PHY_BASE,
179 .regs_otg = S5PC110_OTG_BASE,
180 .usb_phy_ctrl = S5PC110_USB_PHY_CONTROL,
181};
Mateusz Zalega381709a2014-04-28 21:13:30 +0200182
183int board_usb_init(int index, enum usb_init_type init)
184{
185 debug("USB_udc_probe\n");
Marek Vasut01b61fa2015-12-04 02:26:33 +0100186 return dwc2_udc_probe(&s5pc110_otg_data);
Mateusz Zalega381709a2014-04-28 21:13:30 +0200187}
Lukasz Majewski35be8502011-10-27 10:36:47 +0200188#endif
Piotr Wilczekc88b89e2014-01-22 15:54:33 +0100189
190#ifdef CONFIG_MISC_INIT_R
191int misc_init_r(void)
192{
193#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
194 set_board_info();
195#endif
196 return 0;
197}
198#endif
Lukasz Majewski3de25702015-03-03 17:32:04 +0100199
200int board_usb_cleanup(int index, enum usb_init_type init)
201{
202 return 0;
203}