blob: b066832e5fa0425191d47744392c43f505d30f00 [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>
Łukasz Majewskic7336812012-11-13 03:21:55 +000012#include <power/pmic.h>
Marek Vasut5d5716e2015-12-04 02:51:20 +010013#include <usb/dwc2_udc.h>
Lukasz Majewskia954da22011-10-27 10:36:47 +020014#include <asm/arch/cpu.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000015#include <power/max8998_pmic.h>
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010016#include <samsung/misc.h>
Mateusz Zalega2d281b32014-04-28 21:13:30 +020017#include <usb.h>
18#include <usb_mass_storage.h>
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010019
Minkyu Kang72b81d32010-05-31 22:02:42 +090020DECLARE_GLOBAL_DATA_PTR;
21
Piotr Wilczek2ac9a352014-01-22 15:54:33 +010022u32 get_board_rev(void)
23{
24 return 0;
25}
26
Minkyu Kang72b81d32010-05-31 22:02:42 +090027int board_init(void)
28{
Minkyu Kang87f314e2010-07-06 20:58:41 +090029 /* Set Initial global variables */
Minkyu Kang72b81d32010-05-31 22:02:42 +090030 gd->bd->bi_arch_number = MACH_TYPE_GONI;
31 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
32
Łukasz Majewski0ecdab62012-11-13 03:22:16 +000033 return 0;
34}
35
Robert Baldyga4d383952014-10-06 14:33:11 +020036#ifdef CONFIG_SYS_I2C_INIT_BOARD
37void i2c_init_board(void)
38{
39 gpio_request(S5PC110_GPIO_J43, "i2c_clk");
40 gpio_request(S5PC110_GPIO_J40, "i2c_data");
41 gpio_direction_output(S5PC110_GPIO_J43, 1);
42 gpio_direction_output(S5PC110_GPIO_J40, 1);
43}
44#endif
45
Łukasz Majewski0ecdab62012-11-13 03:22:16 +000046int power_init_board(void)
47{
Simon Glass08848e92016-11-23 06:34:41 -070048#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Łukasz Majewski2936df12013-08-16 15:33:33 +020049 /*
50 * For PMIC the I2C bus is named as I2C5, but it is connected
51 * to logical I2C adapter 0
52 */
Masahiro Yamada63a75782016-09-06 22:17:38 +090053 return pmic_init(I2C_0);
Simon Glass08848e92016-11-23 06:34:41 -070054#else
55 return 0;
56#endif
Minkyu Kang72b81d32010-05-31 22:02:42 +090057}
58
59int dram_init(void)
60{
Minkyu Kang177feff2010-11-22 20:27:44 +090061 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
62 PHYS_SDRAM_3_SIZE;
63
64 return 0;
65}
66
67void dram_init_banksize(void)
68{
Minkyu Kang72b81d32010-05-31 22:02:42 +090069 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
70 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
71 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
72 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
73 gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
74 gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
Minkyu Kang72b81d32010-05-31 22:02:42 +090075}
76
77#ifdef CONFIG_DISPLAY_BOARDINFO
78int checkboard(void)
79{
80 puts("Board:\tGoni\n");
81 return 0;
82}
83#endif
Minkyu Kang87f314e2010-07-06 20:58:41 +090084
85#ifdef CONFIG_GENERIC_MMC
86int board_mmc_init(bd_t *bis)
87{
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +020088 int i, ret, ret_sd = 0;
Minkyu Kang87f314e2010-07-06 20:58:41 +090089
90 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
Simon Glass7f196102014-10-20 19:48:39 -060091 gpio_request(S5PC110_GPIO_J27, "massmemory_en");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053092 gpio_direction_output(S5PC110_GPIO_J27, 1);
Minkyu Kang87f314e2010-07-06 20:58:41 +090093
94 /*
95 * MMC0 GPIO
96 * GPG0[0] SD_0_CLK
97 * GPG0[1] SD_0_CMD
98 * GPG0[2] SD_0_CDn -> Not used
99 * GPG0[3:6] SD_0_DATA[0:3]
100 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530101 for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) {
102 if (i == S5PC110_GPIO_G02)
Minkyu Kang87f314e2010-07-06 20:58:41 +0900103 continue;
104 /* GPG0[0:6] special function 2 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530105 gpio_cfg_pin(i, 0x2);
Minkyu Kang87f314e2010-07-06 20:58:41 +0900106 /* GPG0[0:6] pull disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530107 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Minkyu Kang87f314e2010-07-06 20:58:41 +0900108 /* GPG0[0:6] drv 4x */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530109 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Minkyu Kang87f314e2010-07-06 20:58:41 +0900110 }
111
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200112 ret = s5p_mmc_init(0, 4);
113 if (ret)
114 error("MMC: Failed to init MMC:0.\n");
115
116 /*
117 * SD card (T_FLASH) detect and init
118 * T_FLASH_DETECT: EINT28: GPH3[4] input mode
119 */
Simon Glass7f196102014-10-20 19:48:39 -0600120 gpio_request(S5PC110_GPIO_H34, "t_flash_detect");
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530121 gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT);
122 gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200123
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530124 if (!gpio_get_value(S5PC110_GPIO_H34)) {
125 for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) {
126 if (i == S5PC110_GPIO_G22)
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200127 continue;
128
129 /* GPG2[0:6] special function 2 */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530130 gpio_cfg_pin(i, 0x2);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200131 /* GPG2[0:6] pull disable */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530132 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200133 /* GPG2[0:6] drv 4x */
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530134 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Przemyslaw Marczak5c18a1c2013-09-10 11:34:49 +0200135 }
136
137 ret_sd = s5p_mmc_init(2, 4);
138 if (ret_sd)
139 error("MMC: Failed to init SD card (MMC:2).\n");
140 }
141
142 return ret & ret_sd;
Minkyu Kang87f314e2010-07-06 20:58:41 +0900143}
144#endif
Lukasz Majewskia954da22011-10-27 10:36:47 +0200145
146#ifdef CONFIG_USB_GADGET
147static int s5pc1xx_phy_control(int on)
148{
Simon Glass08848e92016-11-23 06:34:41 -0700149#ifndef CONFIG_DM_I2C /* TODO(maintainer): Convert to driver model */
Lukasz Majewskia954da22011-10-27 10:36:47 +0200150 int ret;
151 static int status;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000152 struct pmic *p = pmic_get("MAX8998_PMIC");
153 if (!p)
154 return -ENODEV;
Lukasz Majewskia954da22011-10-27 10:36:47 +0200155
156 if (pmic_probe(p))
157 return -1;
158
159 if (on && !status) {
160 ret = pmic_set_output(p, MAX8998_REG_ONOFF1,
161 MAX8998_LDO3, LDO_ON);
162 ret = pmic_set_output(p, MAX8998_REG_ONOFF2,
163 MAX8998_LDO8, LDO_ON);
164 if (ret) {
165 puts("MAX8998 LDO setting error!\n");
166 return -1;
167 }
168 status = 1;
169 } else if (!on && status) {
170 ret = pmic_set_output(p, MAX8998_REG_ONOFF1,
171 MAX8998_LDO3, LDO_OFF);
172 ret = pmic_set_output(p, MAX8998_REG_ONOFF2,
173 MAX8998_LDO8, LDO_OFF);
174 if (ret) {
175 puts("MAX8998 LDO setting error!\n");
176 return -1;
177 }
178 status = 0;
179 }
180 udelay(10000);
Simon Glass08848e92016-11-23 06:34:41 -0700181#endif
Lukasz Majewskia954da22011-10-27 10:36:47 +0200182 return 0;
183}
184
Marek Vasutc0982872015-12-04 02:23:29 +0100185struct dwc2_plat_otg_data s5pc110_otg_data = {
Lukasz Majewskia954da22011-10-27 10:36:47 +0200186 .phy_control = s5pc1xx_phy_control,
187 .regs_phy = S5PC110_PHY_BASE,
188 .regs_otg = S5PC110_OTG_BASE,
189 .usb_phy_ctrl = S5PC110_USB_PHY_CONTROL,
190};
Mateusz Zalega2d281b32014-04-28 21:13:30 +0200191
192int board_usb_init(int index, enum usb_init_type init)
193{
194 debug("USB_udc_probe\n");
Marek Vasuta4bb9b32015-12-04 02:26:33 +0100195 return dwc2_udc_probe(&s5pc110_otg_data);
Mateusz Zalega2d281b32014-04-28 21:13:30 +0200196}
Lukasz Majewskia954da22011-10-27 10:36:47 +0200197#endif
Piotr Wilczek2ac9a352014-01-22 15:54:33 +0100198
199#ifdef CONFIG_MISC_INIT_R
200int misc_init_r(void)
201{
202#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
203 set_board_info();
204#endif
205 return 0;
206}
207#endif
Lukasz Majewski1118ecd2015-03-03 17:32:04 +0100208
209int board_usb_cleanup(int index, enum usb_init_type init)
210{
211 return 0;
212}