]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/samsung/universal_c210/universal.c
Merge remote-tracking branch 'u-boot/master' into u-boot-arm-merged
[karo-tx-uboot.git] / board / samsung / universal_c210 / universal.c
1 /*
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 <spi.h>
27 #include <lcd.h>
28 #include <asm/io.h>
29 #include <asm/gpio.h>
30 #include <asm/arch/adc.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/mmc.h>
33 #include <asm/arch/pinmux.h>
34 #include <pmic.h>
35 #include <usb/s3c_udc.h>
36 #include <asm/arch/cpu.h>
37 #include <max8998_pmic.h>
38 #include <asm/arch/watchdog.h>
39 #include <libtizen.h>
40 #include <ld9040.h>
41 #include <power/pmic.h>
42 #include <usb/s3c_udc.h>
43 #include <asm/arch/cpu.h>
44 #include <power/max8998_pmic.h>
45
46 DECLARE_GLOBAL_DATA_PTR;
47
48 struct exynos4_gpio_part1 *gpio1;
49 struct exynos4_gpio_part2 *gpio2;
50 unsigned int board_rev;
51
52 u32 get_board_rev(void)
53 {
54         return board_rev;
55 }
56
57 static int get_hwrev(void)
58 {
59         return board_rev & 0xFF;
60 }
61
62 static void check_hw_revision(void);
63
64 int board_init(void)
65 {
66         gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
67         gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
68
69         gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
70         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
71
72         check_hw_revision();
73         printf("HW Revision:\t0x%x\n", board_rev);
74
75         return 0;
76 }
77
78 int power_init_board(void)
79 {
80         int ret;
81
82         ret = pmic_init(I2C_5);
83         if (ret)
84                 return ret;
85
86         return 0;
87 }
88
89 int dram_init(void)
90 {
91         gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE) +
92                 get_ram_size((long *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
93
94         return 0;
95 }
96
97 void dram_init_banksize(void)
98 {
99         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
100         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
101         gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
102         gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
103 }
104
105 static unsigned short get_adc_value(int channel)
106 {
107         struct s5p_adc *adc = (struct s5p_adc *)samsung_get_base_adc();
108         unsigned short ret = 0;
109         unsigned int reg;
110         unsigned int loop = 0;
111
112         writel(channel & 0xF, &adc->adcmux);
113         writel((1 << 14) | (49 << 6), &adc->adccon);
114         writel(1000 & 0xffff, &adc->adcdly);
115         writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
116         udelay(10);
117         writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
118         udelay(10);
119
120         do {
121                 udelay(1);
122                 reg = readl(&adc->adccon);
123         } while (!(reg & (1 << 15)) && (loop++ < 1000));
124
125         ret = readl(&adc->adcdat0) & 0xFFF;
126
127         return ret;
128 }
129
130 static int adc_power_control(int on)
131 {
132         int ret;
133         struct pmic *p = pmic_get("MAX8998_PMIC");
134         if (!p)
135                 return -ENODEV;
136
137         if (pmic_probe(p))
138                 return -1;
139
140         ret = pmic_set_output(p,
141                               MAX8998_REG_ONOFF1,
142                               MAX8998_LDO4, !!on);
143
144         return ret;
145 }
146
147 static unsigned int get_hw_revision(void)
148 {
149         int hwrev, mode0, mode1;
150
151         adc_power_control(1);
152
153         mode0 = get_adc_value(1);               /* HWREV_MODE0 */
154         mode1 = get_adc_value(2);               /* HWREV_MODE1 */
155
156         /*
157          * XXX Always set the default hwrev as the latest board
158          * ADC = (voltage) / 3.3 * 4096
159          */
160         hwrev = 3;
161
162 #define IS_RANGE(x, min, max)   ((x) > (min) && (x) < (max))
163         if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
164                 hwrev = 0x0;            /* 0.01V        0.01V */
165         if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
166                 hwrev = 0x1;            /* 610mV        0.01V */
167         if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
168                 hwrev = 0x2;            /* 1.16V        0.01V */
169         if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
170                 hwrev = 0x3;            /* 1.79V        0.01V */
171 #undef IS_RANGE
172
173         debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
174
175         adc_power_control(0);
176
177         return hwrev;
178 }
179
180 static void check_hw_revision(void)
181 {
182         int hwrev;
183
184         hwrev = get_hw_revision();
185
186         board_rev |= hwrev;
187 }
188
189 #ifdef CONFIG_DISPLAY_BOARDINFO
190 int checkboard(void)
191 {
192         puts("Board:\tUniversal C210\n");
193         return 0;
194 }
195 #endif
196
197 #ifdef CONFIG_GENERIC_MMC
198 int board_mmc_init(bd_t *bis)
199 {
200         int err;
201
202         switch (get_hwrev()) {
203         case 0:
204                 /*
205                  * Set the low to enable LDO_EN
206                  * But when you use the test board for eMMC booting
207                  * you should set it HIGH since it removes the inverter
208                  */
209                 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
210                 s5p_gpio_direction_output(&gpio1->e3, 6, 0);
211                 break;
212         default:
213                 /*
214                  * Default reset state is High and there's no inverter
215                  * But set it as HIGH to ensure
216                  */
217                 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
218                 s5p_gpio_direction_output(&gpio1->e1, 3, 1);
219                 break;
220         }
221
222         /*
223          * MMC device init
224          * mmc0  : eMMC (8-bit buswidth)
225          * mmc2  : SD card (4-bit buswidth)
226          */
227         err = exynos_pinmux_config(PERIPH_ID_SDMMC0, PINMUX_FLAG_8BIT_MODE);
228         if (err)
229                 debug("SDMMC0 not configured\n");
230         else
231                 err = s5p_mmc_init(0, 8);
232
233         /* T-flash detect */
234         s5p_gpio_cfg_pin(&gpio2->x3, 4, 0xf);
235         s5p_gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
236
237         /*
238          * Check the T-flash  detect pin
239          * GPX3[4] T-flash detect pin
240          */
241         if (!s5p_gpio_get_value(&gpio2->x3, 4)) {
242                 err = exynos_pinmux_config(PERIPH_ID_SDMMC2, PINMUX_FLAG_NONE);
243                 if (err)
244                         debug("SDMMC2 not configured\n");
245                 else
246                         err = s5p_mmc_init(2, 4);
247         }
248
249         return err;
250
251 }
252 #endif
253
254 #ifdef CONFIG_USB_GADGET
255 static int s5pc210_phy_control(int on)
256 {
257         int ret = 0;
258         struct pmic *p = pmic_get("MAX8998_PMIC");
259         if (!p)
260                 return -ENODEV;
261
262         if (pmic_probe(p))
263                 return -1;
264
265         if (on) {
266                 ret |= pmic_set_output(p,
267                                        MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
268                                        MAX8998_SAFEOUT1, LDO_ON);
269                 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
270                                       MAX8998_LDO3, LDO_ON);
271                 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
272                                       MAX8998_LDO8, LDO_ON);
273
274         } else {
275                 ret |= pmic_set_output(p, MAX8998_REG_ONOFF2,
276                                       MAX8998_LDO8, LDO_OFF);
277                 ret |= pmic_set_output(p, MAX8998_REG_ONOFF1,
278                                       MAX8998_LDO3, LDO_OFF);
279                 ret |= pmic_set_output(p,
280                                        MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
281                                        MAX8998_SAFEOUT1, LDO_OFF);
282         }
283
284         if (ret) {
285                 puts("MAX8998 LDO setting error!\n");
286                 return -1;
287         }
288
289         return 0;
290 }
291
292 struct s3c_plat_otg_data s5pc210_otg_data = {
293         .phy_control = s5pc210_phy_control,
294         .regs_phy = EXYNOS4_USBPHY_BASE,
295         .regs_otg = EXYNOS4_USBOTG_BASE,
296         .usb_phy_ctrl = EXYNOS4_USBPHY_CONTROL,
297         .usb_flags = PHY0_SLEEP,
298 };
299 #endif
300
301 int board_early_init_f(void)
302 {
303         wdt_stop();
304
305         return 0;
306 }
307
308 #ifdef CONFIG_SOFT_SPI
309 static void soft_spi_init(void)
310 {
311         gpio_direction_output(CONFIG_SOFT_SPI_GPIO_SCLK,
312                 CONFIG_SOFT_SPI_MODE & SPI_CPOL);
313         gpio_direction_output(CONFIG_SOFT_SPI_GPIO_MOSI, 1);
314         gpio_direction_input(CONFIG_SOFT_SPI_GPIO_MISO);
315         gpio_direction_output(CONFIG_SOFT_SPI_GPIO_CS,
316                 !(CONFIG_SOFT_SPI_MODE & SPI_CS_HIGH));
317 }
318
319 void spi_cs_activate(struct spi_slave *slave)
320 {
321         gpio_set_value(CONFIG_SOFT_SPI_GPIO_CS,
322                 !(CONFIG_SOFT_SPI_MODE & SPI_CS_HIGH));
323         SPI_SCL(1);
324         gpio_set_value(CONFIG_SOFT_SPI_GPIO_CS,
325                 CONFIG_SOFT_SPI_MODE & SPI_CS_HIGH);
326 }
327
328 void spi_cs_deactivate(struct spi_slave *slave)
329 {
330         gpio_set_value(CONFIG_SOFT_SPI_GPIO_CS,
331                 !(CONFIG_SOFT_SPI_MODE & SPI_CS_HIGH));
332 }
333
334 int  spi_cs_is_valid(unsigned int bus, unsigned int cs)
335 {
336         return bus == 0 && cs == 0;
337 }
338
339 void universal_spi_scl(int bit)
340 {
341         gpio_set_value(CONFIG_SOFT_SPI_GPIO_SCLK, bit);
342 }
343
344 void universal_spi_sda(int bit)
345 {
346         gpio_set_value(CONFIG_SOFT_SPI_GPIO_MOSI, bit);
347 }
348
349 int universal_spi_read(void)
350 {
351         return gpio_get_value(CONFIG_SOFT_SPI_GPIO_MISO);
352 }
353 #endif
354
355 static void init_pmic_lcd(void)
356 {
357         unsigned char val;
358         int ret = 0;
359
360         struct pmic *p = get_pmic();
361
362         if (pmic_probe(p))
363                 return;
364
365         /* LDO7 1.8V */
366         val = 0x02; /* (1800 - 1600) / 100; */
367         ret |= pmic_reg_write(p,  MAX8998_REG_LDO7, val);
368
369         /* LDO17 3.0V */
370         val = 0xe; /* (3000 - 1600) / 100; */
371         ret |= pmic_reg_write(p,  MAX8998_REG_LDO17, val);
372
373         /* Disable unneeded regulators */
374         /*
375          * ONOFF1
376          * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
377          * LDO2 ON, LDO3 OFF, LDO4 OFF, LDO5 ON
378          */
379         val = 0xB9;
380         ret |= pmic_reg_write(p,  MAX8998_REG_ONOFF1, val);
381
382         /* ONOFF2
383          * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
384          * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
385          */
386         val = 0x50;
387         ret |= pmic_reg_write(p,  MAX8998_REG_ONOFF2, val);
388
389         /* ONOFF3
390          * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 OFF
391          * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
392          */
393         val = 0x00;
394         ret |= pmic_reg_write(p,  MAX8998_REG_ONOFF3, val);
395
396         if (ret)
397                 puts("LCD pmic initialisation error!\n");
398 }
399
400 static void lcd_cfg_gpio(void)
401 {
402         unsigned int i, f3_end = 4;
403
404         for (i = 0; i < 8; i++) {
405                 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
406                 s5p_gpio_cfg_pin(&gpio1->f0, i, GPIO_FUNC(2));
407                 s5p_gpio_cfg_pin(&gpio1->f1, i, GPIO_FUNC(2));
408                 s5p_gpio_cfg_pin(&gpio1->f2, i, GPIO_FUNC(2));
409                 /* pull-up/down disable */
410                 s5p_gpio_set_pull(&gpio1->f0, i, GPIO_PULL_NONE);
411                 s5p_gpio_set_pull(&gpio1->f1, i, GPIO_PULL_NONE);
412                 s5p_gpio_set_pull(&gpio1->f2, i, GPIO_PULL_NONE);
413
414                 /* drive strength to max (24bit) */
415                 s5p_gpio_set_drv(&gpio1->f0, i, GPIO_DRV_4X);
416                 s5p_gpio_set_rate(&gpio1->f0, i, GPIO_DRV_SLOW);
417                 s5p_gpio_set_drv(&gpio1->f1, i, GPIO_DRV_4X);
418                 s5p_gpio_set_rate(&gpio1->f1, i, GPIO_DRV_SLOW);
419                 s5p_gpio_set_drv(&gpio1->f2, i, GPIO_DRV_4X);
420                 s5p_gpio_set_rate(&gpio1->f0, i, GPIO_DRV_SLOW);
421         }
422
423         for (i = 0; i < f3_end; i++) {
424                 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
425                 s5p_gpio_cfg_pin(&gpio1->f3, i, GPIO_FUNC(2));
426                 /* pull-up/down disable */
427                 s5p_gpio_set_pull(&gpio1->f3, i, GPIO_PULL_NONE);
428                 /* drive strength to max (24bit) */
429                 s5p_gpio_set_drv(&gpio1->f3, i, GPIO_DRV_4X);
430                 s5p_gpio_set_rate(&gpio1->f3, i, GPIO_DRV_SLOW);
431         }
432
433         /* gpio pad configuration for LCD reset. */
434         s5p_gpio_cfg_pin(&gpio2->y4, 5, GPIO_OUTPUT);
435
436         spi_init();
437 }
438
439 static void reset_lcd(void)
440 {
441         s5p_gpio_set_value(&gpio2->y4, 5, 1);
442         udelay(10000);
443         s5p_gpio_set_value(&gpio2->y4, 5, 0);
444         udelay(10000);
445         s5p_gpio_set_value(&gpio2->y4, 5, 1);
446         udelay(100);
447 }
448
449 static void lcd_power_on(void)
450 {
451         struct pmic *p = get_pmic();
452
453         if (pmic_probe(p))
454                 return;
455
456         pmic_set_output(p, MAX8998_REG_ONOFF3, MAX8998_LDO17, LDO_ON);
457         pmic_set_output(p, MAX8998_REG_ONOFF2, MAX8998_LDO7, LDO_ON);
458 }
459
460 vidinfo_t panel_info = {
461         .vl_freq        = 60,
462         .vl_col         = 480,
463         .vl_row         = 800,
464         .vl_width       = 480,
465         .vl_height      = 800,
466         .vl_clkp        = CONFIG_SYS_HIGH,
467         .vl_hsp         = CONFIG_SYS_HIGH,
468         .vl_vsp         = CONFIG_SYS_HIGH,
469         .vl_dp          = CONFIG_SYS_HIGH,
470
471         .vl_bpix        = 5,    /* Bits per pixel */
472
473         /* LD9040 LCD Panel */
474         .vl_hspw        = 2,
475         .vl_hbpd        = 16,
476         .vl_hfpd        = 16,
477
478         .vl_vspw        = 2,
479         .vl_vbpd        = 8,
480         .vl_vfpd        = 8,
481         .vl_cmd_allow_len = 0xf,
482
483         .win_id         = 0,
484         .cfg_gpio       = lcd_cfg_gpio,
485         .backlight_on   = NULL,
486         .lcd_power_on   = lcd_power_on,
487         .reset_lcd      = reset_lcd,
488         .dual_lcd_enabled = 0,
489
490         .init_delay     = 0,
491         .power_on_delay = 10000,
492         .reset_delay    = 10000,
493         .interface_mode = FIMD_RGB_INTERFACE,
494         .mipi_enabled   = 0,
495 };
496
497 void init_panel_info(vidinfo_t *vid)
498 {
499         vid->logo_on    = 1;
500         vid->resolution = HD_RESOLUTION;
501         vid->rgb_mode   = MODE_RGB_P;
502
503 #ifdef CONFIG_TIZEN
504         get_tizen_logo_info(vid);
505 #endif
506
507         /* for LD9040. */
508         vid->pclk_name = 1;     /* MPLL */
509         vid->sclk_div = 1;
510
511         vid->cfg_ldo = ld9040_cfg_ldo;
512         vid->enable_ldo = ld9040_enable_ldo;
513
514         setenv("lcdinfo", "lcd=ld9040");
515 }
516
517 int board_init(void)
518 {
519         gpio1 = (struct exynos4_gpio_part1 *) EXYNOS4_GPIO_PART1_BASE;
520         gpio2 = (struct exynos4_gpio_part2 *) EXYNOS4_GPIO_PART2_BASE;
521
522         gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
523         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
524
525 #if defined(CONFIG_PMIC)
526         pmic_init();
527         init_pmic_lcd();
528 #endif
529 #ifdef CONFIG_SOFT_SPI
530         soft_spi_init();
531 #endif
532         check_hw_revision();
533         printf("HW Revision:\t0x%x\n", board_rev);
534
535         return 0;
536 }