blob: 7a4941c0521dce0409ca37cb3da7ab32268215f9 [file] [log] [blame]
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +09001/*
2 * Copyright (C) 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <asm/io.h>
27#include <asm/arch/adc.h>
28#include <asm/arch/gpio.h>
29#include <asm/arch/mmc.h>
Piotr Wilczek3b179142012-09-20 00:19:59 +000030#include <asm/arch/pinmux.h>
Łukasz Majewskia3f38a82011-10-26 22:33:17 +000031#include <pmic.h>
Lukasz Majewskibf731262011-12-15 10:32:12 +010032#include <usb/s3c_udc.h>
33#include <asm/arch/cpu.h>
34#include <max8998_pmic.h>
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090035
36DECLARE_GLOBAL_DATA_PTR;
37
Chander Kashyap4131a772011-12-06 23:34:12 +000038struct exynos4_gpio_part1 *gpio1;
39struct exynos4_gpio_part2 *gpio2;
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090040unsigned int board_rev;
41
42u32 get_board_rev(void)
43{
44 return board_rev;
45}
46
47static int get_hwrev(void)
48{
49 return board_rev & 0xFF;
50}
51
52static void check_hw_revision(void);
53
54int board_init(void)
55{
Chander Kashyap4131a772011-12-06 23:34:12 +000056 gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
57 gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090058
59 gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
60 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
61
Łukasz Majewskia3f38a82011-10-26 22:33:17 +000062#if defined(CONFIG_PMIC)
63 pmic_init();
64#endif
65
Łukasz Majewski61f8b402012-03-26 21:53:48 +000066 check_hw_revision();
67 printf("HW Revision:\t0x%x\n", board_rev);
68
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090069 return 0;
70}
71
72int dram_init(void)
73{
74 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
75 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
76
77 return 0;
78}
79
80void dram_init_banksize(void)
81{
82 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
83 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
84 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
85 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
86}
87
88static unsigned short get_adc_value(int channel)
89{
90 struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
91 unsigned short ret = 0;
92 unsigned int reg;
93 unsigned int loop = 0;
94
95 writel(channel & 0xF, &adc->adcmux);
96 writel((1 << 14) | (49 << 6), &adc->adccon);
97 writel(1000 & 0xffff, &adc->adcdly);
98 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
99 udelay(10);
100 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
101 udelay(10);
102
103 do {
104 udelay(1);
105 reg = readl(&adc->adccon);
106 } while (!(reg & (1 << 15)) && (loop++ < 1000));
107
108 ret = readl(&adc->adcdat0) & 0xFFF;
109
110 return ret;
111}
112
Łukasz Majewski61f8b402012-03-26 21:53:48 +0000113static int adc_power_control(int on)
114{
115 int ret;
116 struct pmic *p = get_pmic();
117
118 if (pmic_probe(p))
119 return -1;
120
121 ret = pmic_set_output(p,
122 MAX8998_REG_ONOFF1,
123 MAX8998_LDO4, !!on);
124
125 return ret;
126}
127
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900128static unsigned int get_hw_revision(void)
129{
130 int hwrev, mode0, mode1;
131
Łukasz Majewski61f8b402012-03-26 21:53:48 +0000132 adc_power_control(1);
133
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900134 mode0 = get_adc_value(1); /* HWREV_MODE0 */
135 mode1 = get_adc_value(2); /* HWREV_MODE1 */
136
137 /*
138 * XXX Always set the default hwrev as the latest board
139 * ADC = (voltage) / 3.3 * 4096
140 */
141 hwrev = 3;
142
143#define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
144 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
145 hwrev = 0x0; /* 0.01V 0.01V */
146 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
147 hwrev = 0x1; /* 610mV 0.01V */
148 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
149 hwrev = 0x2; /* 1.16V 0.01V */
150 if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
151 hwrev = 0x3; /* 1.79V 0.01V */
152#undef IS_RANGE
153
154 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
155
Łukasz Majewski61f8b402012-03-26 21:53:48 +0000156 adc_power_control(0);
157
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900158 return hwrev;
159}
160
161static void check_hw_revision(void)
162{
163 int hwrev;
164
165 hwrev = get_hw_revision();
166
167 board_rev |= hwrev;
168}
169
170#ifdef CONFIG_DISPLAY_BOARDINFO
171int checkboard(void)
172{
173 puts("Board:\tUniversal C210\n");
174 return 0;
175}
176#endif
177
178#ifdef CONFIG_GENERIC_MMC
179int board_mmc_init(bd_t *bis)
180{
Piotr Wilczek3b179142012-09-20 00:19:59 +0000181 int err;
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900182
183 switch (get_hwrev()) {
184 case 0:
185 /*
186 * Set the low to enable LDO_EN
187 * But when you use the test board for eMMC booting
188 * you should set it HIGH since it removes the inverter
189 */
190 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
Łukasz Majewski4ff84e22011-08-09 23:18:54 +0000191 s5p_gpio_direction_output(&gpio1->e3, 6, 0);
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900192 break;
193 default:
194 /*
195 * Default reset state is High and there's no inverter
196 * But set it as HIGH to ensure
197 */
198 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
Łukasz Majewski4ff84e22011-08-09 23:18:54 +0000199 s5p_gpio_direction_output(&gpio1->e1, 3, 1);
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900200 break;
201 }
202
203 /*
Piotr Wilczek3b179142012-09-20 00:19:59 +0000204 * MMC device init
205 * mmc0 : eMMC (8-bit buswidth)
206 * mmc2 : SD card (4-bit buswidth)
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900207 */
Piotr Wilczek3b179142012-09-20 00:19:59 +0000208 err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
209 if (err)
210 debug("SDMMC0 not configured\n");
211 else
212 err = s5p_mmc_init(0, 8);
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900213
214 /* T-flash detect */
Łukasz Majewski4ff84e22011-08-09 23:18:54 +0000215 s5p_gpio_cfg_pin(&gpio2->x3, 4, 0xf);
216 s5p_gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900217
218 /*
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900219 * Check the T-flash detect pin
220 * GPX3[4] T-flash detect pin
221 */
Łukasz Majewski4ff84e22011-08-09 23:18:54 +0000222 if (!s5p_gpio_get_value(&gpio2->x3, 4)) {
Piotr Wilczek3b179142012-09-20 00:19:59 +0000223 err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
224 if (err)
225 debug("SDMMC2 not configured\n");
226 else
227 err = s5p_mmc_init(2, 4);
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900228 }
229
230 return err;
231
232}
233#endif
Lukasz Majewskibf731262011-12-15 10:32:12 +0100234
235#ifdef CONFIG_USB_GADGET
236static int s5pc210_phy_control(int on)
237{
Anatolij Gustschinba166612011-12-19 04:20:04 +0000238 int ret = 0;
Lukasz Majewskibf731262011-12-15 10:32:12 +0100239 struct pmic *p = get_pmic();
240
241 if (pmic_probe(p))
242 return -1;
243
244 if (on) {
245 ret |= pmic_set_output(p,
246 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
247 MAX8998_SAFEOUT1, LDO_ON);
248 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
249 MAX8998_LDO3, LDO_ON);
250 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
251 MAX8998_LDO8, LDO_ON);
252
253 } else {
254 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
255 MAX8998_LDO8, LDO_OFF);
256 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
257 MAX8998_LDO3, LDO_OFF);
258 ret |= pmic_set_output(p,
259 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
260 MAX8998_SAFEOUT1, LDO_OFF);
261 }
262
263 if (ret) {
264 puts("MAX8998 LDO setting error!\n");
265 return -1;
266 }
267
268 return 0;
269}
270
271struct s3c_plat_otg_data s5pc210_otg_data = {
272 .phy_control = s5pc210_phy_control,
273 .regs_phy = EXYNOS4_USBPHY_BASE,
274 .regs_otg = EXYNOS4_USBOTG_BASE,
275 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
276 .usb_flags = PHY0_SLEEP,
277};
278#endif