blob: 747d556dd3e03c2b235f20fc0da13384c0aac231 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +09007 */
8
9#include <common.h>
Piotr Wilczeke372b552012-10-19 05:34:03 +000010#include <spi.h>
Piotr Wilczek461c5e52012-10-19 05:34:07 +000011#include <lcd.h>
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090012#include <asm/io.h>
Piotr Wilczeke372b552012-10-19 05:34:03 +000013#include <asm/gpio.h>
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090014#include <asm/arch/adc.h>
Piotr Wilczek3b179142012-09-20 00:19:59 +000015#include <asm/arch/pinmux.h>
Piotr Wilczek6ce94c32012-09-20 00:20:00 +000016#include <asm/arch/watchdog.h>
Piotr Wilczek461c5e52012-10-19 05:34:07 +000017#include <ld9040.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000018#include <power/pmic.h>
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +010019#include <usb.h>
Lukasz Majewskibf731262011-12-15 10:32:12 +010020#include <usb/s3c_udc.h>
21#include <asm/arch/cpu.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000022#include <power/max8998_pmic.h>
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +010023#include <libtizen.h>
Przemyslaw Marczak94df8012014-01-22 11:24:20 +010024#include <samsung/misc.h>
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +010025#include <usb_mass_storage.h>
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090026
27DECLARE_GLOBAL_DATA_PTR;
28
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090029unsigned int board_rev;
30
31u32 get_board_rev(void)
32{
33 return board_rev;
34}
35
36static int get_hwrev(void)
37{
38 return board_rev & 0xFF;
39}
40
Minkyu Kang1d4f9ca2012-12-09 20:50:11 +000041static void init_pmic_lcd(void);
42
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +010043int exynos_power_init(void)
Łukasz Majewski11be2832012-11-13 03:22:17 +000044{
45 int ret;
46
Łukasz Majewskide55e752013-08-16 15:33:33 +020047 /*
48 * For PMIC the I2C bus is named as I2C5, but it is connected
49 * to logical I2C adapter 0
50 */
Piotr Wilczek11d22e02014-01-14 08:15:07 +010051 ret = pmic_init(I2C_0);
Łukasz Majewski11be2832012-11-13 03:22:17 +000052 if (ret)
53 return ret;
54
Minkyu Kang1d4f9ca2012-12-09 20:50:11 +000055 init_pmic_lcd();
56
Łukasz Majewski11be2832012-11-13 03:22:17 +000057 return 0;
58}
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090059
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +090060static unsigned short get_adc_value(int channel)
61{
62 struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
63 unsigned short ret = 0;
64 unsigned int reg;
65 unsigned int loop = 0;
66
67 writel(channel & 0xF, &adc->adcmux);
68 writel((1 << 14) | (49 << 6), &adc->adccon);
69 writel(1000 & 0xffff, &adc->adcdly);
70 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
71 udelay(10);
72 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
73 udelay(10);
74
75 do {
76 udelay(1);
77 reg = readl(&adc->adccon);
78 } while (!(reg & (1 << 15)) && (loop++ < 1000));
79
80 ret = readl(&adc->adcdat0) & 0xFFF;
81
82 return ret;
83}
84
Łukasz Majewski61f8b402012-03-26 21:53:48 +000085static int adc_power_control(int on)
86{
87 int ret;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000088 struct pmic *p = pmic_get("MAX8998_PMIC");
89 if (!p)
90 return -ENODEV;
Łukasz Majewski61f8b402012-03-26 21:53:48 +000091
92 if (pmic_probe(p))
93 return -1;
94
95 ret = pmic_set_output(p,
96 MAX8998_REG_ONOFF1,
97 MAX8998_LDO4, !!on);
98
99 return ret;
100}
101
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900102static unsigned int get_hw_revision(void)
103{
104 int hwrev, mode0, mode1;
105
Łukasz Majewski61f8b402012-03-26 21:53:48 +0000106 adc_power_control(1);
107
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900108 mode0 = get_adc_value(1); /* HWREV_MODE0 */
109 mode1 = get_adc_value(2); /* HWREV_MODE1 */
110
111 /*
112 * XXX Always set the default hwrev as the latest board
113 * ADC = (voltage) / 3.3 * 4096
114 */
115 hwrev = 3;
116
117#define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
118 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
119 hwrev = 0x0; /* 0.01V 0.01V */
120 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
121 hwrev = 0x1; /* 610mV 0.01V */
122 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
123 hwrev = 0x2; /* 1.16V 0.01V */
124 if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
125 hwrev = 0x3; /* 1.79V 0.01V */
126#undef IS_RANGE
127
128 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
129
Łukasz Majewski61f8b402012-03-26 21:53:48 +0000130 adc_power_control(0);
131
Minkyu Kang0aa1a6b2011-01-24 15:33:50 +0900132 return hwrev;
133}
134
135static void check_hw_revision(void)
136{
137 int hwrev;
138
139 hwrev = get_hw_revision();
140
141 board_rev |= hwrev;
142}
143
Lukasz Majewskibf731262011-12-15 10:32:12 +0100144#ifdef CONFIG_USB_GADGET
145static int s5pc210_phy_control(int on)
146{
Anatolij Gustschinba166612011-12-19 04:20:04 +0000147 int ret = 0;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000148 struct pmic *p = pmic_get("MAX8998_PMIC");
149 if (!p)
150 return -ENODEV;
Lukasz Majewskibf731262011-12-15 10:32:12 +0100151
152 if (pmic_probe(p))
153 return -1;
154
155 if (on) {
156 ret |= pmic_set_output(p,
157 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
158 MAX8998_SAFEOUT1, LDO_ON);
159 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
160 MAX8998_LDO3, LDO_ON);
161 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
162 MAX8998_LDO8, LDO_ON);
163
164 } else {
165 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
166 MAX8998_LDO8, LDO_OFF);
167 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
168 MAX8998_LDO3, LDO_OFF);
169 ret |= pmic_set_output(p,
170 MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
171 MAX8998_SAFEOUT1, LDO_OFF);
172 }
173
174 if (ret) {
175 puts("MAX8998 LDO setting error!\n");
176 return -1;
177 }
178
179 return 0;
180}
181
Marek Vasut6939aca2015-12-04 02:23:29 +0100182struct dwc2_plat_otg_data s5pc210_otg_data = {
Lukasz Majewskibf731262011-12-15 10:32:12 +0100183 .phy_control = s5pc210_phy_control,
184 .regs_phy = EXYNOS4_USBPHY_BASE,
185 .regs_otg = EXYNOS4_USBOTG_BASE,
186 .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
187 .usb_flags = PHY0_SLEEP,
188};
189#endif
Piotr Wilczek6ce94c32012-09-20 00:20:00 +0000190
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100191int board_usb_init(int index, enum usb_init_type init)
192{
193 debug("USB_udc_probe\n");
194 return s3c_udc_probe(&s5pc210_otg_data);
195}
196
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100197int exynos_early_init_f(void)
Piotr Wilczek6ce94c32012-09-20 00:20:00 +0000198{
199 wdt_stop();
200
201 return 0;
202}
Piotr Wilczeke372b552012-10-19 05:34:03 +0000203
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000204static void init_pmic_lcd(void)
205{
206 unsigned char val;
207 int ret = 0;
208
Minkyu Kang1d4f9ca2012-12-09 20:50:11 +0000209 struct pmic *p = pmic_get("MAX8998_PMIC");
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000210
Minkyu Kang538f26b2012-12-10 22:43:57 +0900211 if (!p)
212 return;
213
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000214 if (pmic_probe(p))
215 return;
216
217 /* LDO7 1.8V */
218 val = 0x02; /* (1800 - 1600) / 100; */
219 ret |= pmic_reg_write(p, MAX8998_REG_LDO7, val);
220
221 /* LDO17 3.0V */
222 val = 0xe; /* (3000 - 1600) / 100; */
223 ret |= pmic_reg_write(p, MAX8998_REG_LDO17, val);
224
225 /* Disable unneeded regulators */
226 /*
227 * ONOFF1
228 * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
229 * LDO2 ON, LDO3 OFF, LDO4 OFF, LDO5 ON
230 */
231 val = 0xB9;
232 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF1, val);
233
234 /* ONOFF2
235 * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
236 * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
237 */
238 val = 0x50;
239 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF2, val);
240
241 /* ONOFF3
242 * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 OFF
243 * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
244 */
245 val = 0x00;
246 ret |= pmic_reg_write(p, MAX8998_REG_ONOFF3, val);
247
248 if (ret)
249 puts("LCD pmic initialisation error!\n");
250}
251
Ajay Kumar41022a12013-02-21 23:52:57 +0000252void exynos_cfg_lcd_gpio(void)
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000253{
254 unsigned int i, f3_end = 4;
255
256 for (i = 0; i < 8; i++) {
257 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530258 gpio_cfg_pin(EXYNOS4_GPIO_F00 + i, S5P_GPIO_FUNC(2));
259 gpio_cfg_pin(EXYNOS4_GPIO_F10 + i, S5P_GPIO_FUNC(2));
260 gpio_cfg_pin(EXYNOS4_GPIO_F20 + i, S5P_GPIO_FUNC(2));
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000261 /* pull-up/down disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530262 gpio_set_pull(EXYNOS4_GPIO_F00 + i, S5P_GPIO_PULL_NONE);
263 gpio_set_pull(EXYNOS4_GPIO_F10 + i, S5P_GPIO_PULL_NONE);
264 gpio_set_pull(EXYNOS4_GPIO_F20 + i, S5P_GPIO_PULL_NONE);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000265
266 /* drive strength to max (24bit) */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530267 gpio_set_drv(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_4X);
268 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
269 gpio_set_drv(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_4X);
270 gpio_set_rate(EXYNOS4_GPIO_F10 + i, S5P_GPIO_DRV_SLOW);
271 gpio_set_drv(EXYNOS4_GPIO_F20 + i, S5P_GPIO_DRV_4X);
272 gpio_set_rate(EXYNOS4_GPIO_F00 + i, S5P_GPIO_DRV_SLOW);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000273 }
274
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530275 for (i = EXYNOS4_GPIO_F30; i < (EXYNOS4_GPIO_F30 + f3_end); i++) {
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000276 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530277 gpio_cfg_pin(i, S5P_GPIO_FUNC(2));
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000278 /* pull-up/down disable */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530279 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000280 /* drive strength to max (24bit) */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530281 gpio_set_drv(i, S5P_GPIO_DRV_4X);
282 gpio_set_rate(i, S5P_GPIO_DRV_SLOW);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000283 }
284
285 /* gpio pad configuration for LCD reset. */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600286 gpio_request(EXYNOS4_GPIO_Y45, "lcd_reset");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530287 gpio_cfg_pin(EXYNOS4_GPIO_Y45, S5P_GPIO_OUTPUT);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000288}
289
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100290int mipi_power(void)
291{
292 return 0;
293}
294
Ajay Kumar41022a12013-02-21 23:52:57 +0000295void exynos_reset_lcd(void)
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000296{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530297 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000298 udelay(10000);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530299 gpio_set_value(EXYNOS4_GPIO_Y45, 0);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000300 udelay(10000);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530301 gpio_set_value(EXYNOS4_GPIO_Y45, 1);
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000302 udelay(100);
303}
304
Ajay Kumar41022a12013-02-21 23:52:57 +0000305void exynos_lcd_power_on(void)
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000306{
Minkyu Kang1d4f9ca2012-12-09 20:50:11 +0000307 struct pmic *p = pmic_get("MAX8998_PMIC");
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000308
Minkyu Kang538f26b2012-12-10 22:43:57 +0900309 if (!p)
310 return;
311
Piotr Wilczek461c5e52012-10-19 05:34:07 +0000312 if (pmic_probe(p))
313 return;
314
315 pmic_set_output(p, MAX8998_REG_ONOFF3, MAX8998_LDO17, LDO_ON);
316 pmic_set_output(p, MAX8998_REG_ONOFF2, MAX8998_LDO7, LDO_ON);
317}
318
Ajay Kumar41022a12013-02-21 23:52:57 +0000319void exynos_cfg_ldo(void)
320{
321 ld9040_cfg_ldo();
322}
323
324void exynos_enable_ldo(unsigned int onoff)
325{
326 ld9040_enable_ldo(onoff);
327}
328
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100329int exynos_init(void)
Piotr Wilczeke372b552012-10-19 05:34:03 +0000330{
Przemyslaw Marczak3e02e6a2014-10-24 17:45:03 +0200331 char buf[16];
332
Piotr Wilczeke372b552012-10-19 05:34:03 +0000333 gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100334
335 switch (get_hwrev()) {
336 case 0:
337 /*
338 * Set the low to enable LDO_EN
339 * But when you use the test board for eMMC booting
340 * you should set it HIGH since it removes the inverter
341 */
342 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600343 gpio_request(EXYNOS4_GPIO_E36, "ldo_en");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530344 gpio_direction_output(EXYNOS4_GPIO_E36, 0);
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100345 break;
346 default:
347 /*
348 * Default reset state is High and there's no inverter
349 * But set it as HIGH to ensure
350 */
351 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
Simon Glass4f83d3d2014-10-20 19:48:39 -0600352 gpio_request(EXYNOS4_GPIO_E13, "massmemory_en");
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530353 gpio_direction_output(EXYNOS4_GPIO_E13, 1);
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100354 break;
355 }
Piotr Wilczeke372b552012-10-19 05:34:03 +0000356
Przemyslaw Marczak3e02e6a2014-10-24 17:45:03 +0200357 /* Request soft I2C gpios */
358 sprintf(buf, "soft_i2c_scl");
359 gpio_request(CONFIG_SOFT_I2C_GPIO_SCL, buf);
360
361 sprintf(buf, "soft_i2c_sda");
362 gpio_request(CONFIG_SOFT_I2C_GPIO_SDA, buf);
363
Piotr Wilczeke372b552012-10-19 05:34:03 +0000364 check_hw_revision();
365 printf("HW Revision:\t0x%x\n", board_rev);
366
367 return 0;
368}
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100369
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100370void exynos_lcd_misc_init(vidinfo_t *vid)
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100371{
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100372#ifdef CONFIG_TIZEN
373 get_tizen_logo_info(vid);
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100374#endif
Piotr Wilczek0ada4ad2014-03-07 14:59:47 +0100375
376 /* for LD9040. */
377 vid->pclk_name = 1; /* MPLL */
378 vid->sclk_div = 1;
379
380 setenv("lcdinfo", "lcd=ld9040");
Przemyslaw Marczak283a3202014-01-22 11:24:12 +0100381}