2 * Copyright (C) 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 * Kyungmin Park <kyungmin.park@samsung.com>
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 #include <asm/arch/adc.h>
31 #include <asm/arch/clock.h>
32 #include <asm/arch/gpio.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/power.h>
35 #include <asm/arch/clk.h>
38 DECLARE_GLOBAL_DATA_PTR;
40 static struct s5pc210_gpio_part1 *gpio1;
41 static struct s5pc210_gpio_part2 *gpio2;
43 static unsigned int battery_soc;
44 static unsigned int board_rev;
45 extern vidinfo_t panel_info;
47 u32 get_board_rev(void)
52 static int get_hwrev(void)
54 return board_rev & 0xFF;
58 I2C_0, I2C_1, I2C_2, I2C_3,
59 I2C_4, I2C_5, I2C_6, I2C_7,
60 I2C_8, I2C_9, I2C_10, I2C_11,
64 /* i2c0 (CAM) SDA: GPD1[0] SCL: GPD1[1] */
65 static struct i2c_gpio_bus_data i2c_0 = {
70 /* i2c1 (Gryo) SDA: GPD1[2] SCL: GPD1[3] */
71 static struct i2c_gpio_bus_data i2c_1 = {
76 /* i2c3 (TSP) SDA: GPA1[2] SCL: GPA1[3] */
77 static struct i2c_gpio_bus_data i2c_3 = {
82 /* i2c4 SDA: GPB[2] SCL: GPB[3] */
83 static struct i2c_gpio_bus_data i2c_4 = {
88 /* i2c5 (PMIC) SDA: GPB[6] SCL: GPB[7] */
89 static struct i2c_gpio_bus_data i2c_5 = {
94 /* i2c6 (CODEC) SDA: GPC1[3] SCL: GPC1[4] */
95 static struct i2c_gpio_bus_data i2c_6 = {
100 /* i2c7 SDA: GPD0[2] SCL: GPD0[3] */
101 static struct i2c_gpio_bus_data i2c_7 = {
106 /* i2c9 SDA: SPY4[0] SCL: SPY4[1] */
107 static struct i2c_gpio_bus_data i2c_9 = {
112 /* i2c10 SDA: SPE1[0] SCL: SPE1[1] */
113 static struct i2c_gpio_bus_data i2c_10 = {
118 /* i2c12 SDA: SPE4[0] SCL: SPE4[1] */
119 static struct i2c_gpio_bus_data i2c_12 = {
124 /* i2c13 SDA: SPE4[2] SCL: SPE4[3] */
125 static struct i2c_gpio_bus_data i2c_13 = {
130 static struct i2c_gpio_bus i2c_gpio[] = {
133 { .bus = NULL, }, /* Not used */
139 { .bus = NULL, }, /* For dedicated HDMI */
142 { .bus = NULL, }, /* Not used */
147 static void check_battery(int mode);
148 static void check_micro_usb(int intr);
149 static void init_pmic_lp3974(void);
150 static void init_pmic_max8952(void);
151 static int pmic_ldo_control(int buck, int ldo, int safeout, int on);
153 void i2c_init_board(void)
157 gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
158 gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
160 num_bus = ARRAY_SIZE(i2c_gpio);
162 i2c_gpio[I2C_0].bus->gpio_base = (unsigned int)&gpio1->d1;
163 i2c_gpio[I2C_1].bus->gpio_base = (unsigned int)&gpio1->d1;
164 i2c_gpio[I2C_3].bus->gpio_base = (unsigned int)&gpio1->a1;
165 i2c_gpio[I2C_4].bus->gpio_base = (unsigned int)&gpio1->b;
166 i2c_gpio[I2C_5].bus->gpio_base = (unsigned int)&gpio1->b;
167 i2c_gpio[I2C_6].bus->gpio_base = (unsigned int)&gpio1->c1;
168 i2c_gpio[I2C_7].bus->gpio_base = (unsigned int)&gpio1->d0;
169 i2c_gpio[I2C_9].bus->gpio_base = (unsigned int)&gpio2->y4;
170 i2c_gpio[I2C_10].bus->gpio_base = (unsigned int)&gpio1->e1;
171 i2c_gpio[I2C_12].bus->gpio_base = (unsigned int)&gpio1->e4;
172 i2c_gpio[I2C_13].bus->gpio_base = (unsigned int)&gpio1->e4;
174 i2c_gpio_init(i2c_gpio, num_bus, I2C_5);
179 gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
180 gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
182 gd->bd->bi_arch_number = MACH_TYPE;
183 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
187 * set reserved memory region for framebuffer.
189 * this region wouldn't be rewrited by kernel so
190 * could avoid nosie screen filled by garbages
191 * after hibernation resume has been completed.
193 gd->fb_base = CONFIG_FB_RESERVED_MEM;
201 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE;
203 /* Early init for i2c devices - Where these funcions should go?? */
205 /* Reset on max17040 */
212 /* Reset on fsa9480 */
215 /* Initialize the panel info */
216 memset(&panel_info, 0x0, sizeof(panel_info));
221 void dram_init_banksize(void)
223 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
224 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
225 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
226 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
228 gd->ram_size = gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size;
231 static void check_auto_burn(void)
233 unsigned int magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
234 unsigned int count = 0;
237 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
238 puts("Auto buring bootloader\n");
239 count += sprintf(buf + count, "run updateb; ");
241 if (readl(magic_base + 0x4) == 0x4b65726e) { /* ASICC: Kern */
242 puts("Auto buring kernel\n");
243 count += sprintf(buf + count, "run updatek; ");
247 count += sprintf(buf + count, "reset");
248 setenv("bootcmd", buf);
251 /* Clear the magic value */
252 memset((void *)magic_base, 0, 2);
255 static int power_key_check(void)
257 unsigned char addr, val[2];
260 i2c_set_bus_num(I2C_5);
262 if (i2c_probe(addr)) {
263 puts("Can't found lp3974\n");
267 /* power_key check */
268 i2c_read(addr, 0x00, 1, val, 1);
269 return (~val[0] & (1 << 6)) >> 6;
272 static void check_keypad(void)
274 unsigned int val = 0;
275 unsigned int power_key, auto_download = 0;
277 val = ~(gpio_get_value(&gpio2->x2, 1));
279 power_key = power_key_check();
281 if (power_key && (val & 0x1))
285 setenv("bootcmd", "usbdown");
288 static void check_battery(int mode)
290 unsigned char val[2];
291 unsigned char addr = 0x36; /* max17040 fuel gauge */
293 i2c_set_bus_num(I2C_9);
295 if (i2c_probe(addr)) {
296 puts("Can't found max17040 fuel gauge\n");
300 /* mode 0: check mode / 1: enable mode */
304 i2c_write(addr, 0xfe, 1, val, 2);
306 i2c_read(addr, 0x04, 1, val, 1);
307 printf("battery:\t%d%%\n", val[0]);
308 battery_soc = val[0];
312 static int fsa9480_probe(void)
314 unsigned char addr = 0x25;
316 i2c_set_bus_num(I2C_10);
318 if (i2c_probe(addr)) {
319 puts("Can't found fsa9480\n");
326 static void charger_en(int enable);
327 static void into_charge_mode(int charger_speed);
328 static void check_micro_usb(int intr)
331 unsigned char val[2];
332 static int started_charging_once = 0;
338 addr = 0x25; /* fsa9480 */
340 /* Clear Interrupt */
342 i2c_read(addr, 0x03, 1, val, 2);
346 /* Read Device Type 1 */
347 i2c_read(addr, 0x0a, 1, val, 1);
349 #define FSA_DEV1_CHARGER (1 << 6)
350 #define FSA_DEV1_UART (1 << 3)
351 #define FSA_DEV1_USB (1 << 2)
352 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
353 #define FSA_DEV2_JIG_USB_ON (1 << 0)
355 /* disable the charger related feature */
357 * If USB, use default 475mA
358 * If Charger, use 600mA and go to charge mode
360 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
361 started_charging_once = 1;
363 /* If it's full, do not charge. */
364 if (battery_soc < 100) {
366 into_charge_mode(600);
370 } else if (val[0] & FSA_DEV1_USB) {
371 if (battery_soc < 100)
372 charger_en(500); /* enable charger and keep booting */
377 /* If reset status is watchdog reset then skip it */
378 if (get_reset_status() != SWRESET) {
379 /* If Factory Mode is Boot ON-USB, go to download mode */
380 i2c_read(addr, 0x07, 1, val, 1);
382 #define FSA_ADC_FAC_USB_OFF 0x18
383 #define FSA_ADC_FAC_USB_ON 0x19
384 #define FSA_ADC_FAC_UART 0x1d
386 if (val[0] == FSA_ADC_FAC_USB_ON ||
387 val[0] == FSA_ADC_FAC_USB_OFF)
388 setenv("bootcmd", "usbdown");
391 path = getenv("usb");
393 if (!strncmp(path, "cp", 2))
394 run_command("microusb cp", 0);
397 static void micro_usb_switch(int path)
400 unsigned char val[2];
405 addr = 0x25; /* fsa9480 */
408 val[0] = 0x90; /* VAUDIO */
410 val[0] = (1 << 5) | (1 << 2); /* DHOST */
412 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
414 i2c_read(addr, 0x2, 1, val, 1);
415 val[0] &= ~(1 << 2); /* Manual switching */
416 i2c_write(addr, 0x2, 1, val, 1);
419 #define LP3974_REG_ONOFF1 0x11
420 #define LP3974_REG_ONOFF2 0x12
421 #define LP3974_REG_ONOFF3 0x13
422 #define LP3974_REG_ONOFF4 0x14
423 #define LP3974_REG_LDO7 0x21
424 #define LP3974_REG_LDO17 0x29
426 #define LP3974_LDO3 (1 << 2)
428 #define LP3974_LDO6 (1 << 7)
429 #define LP3974_LDO7 (1 << 6)
430 #define LP3974_LDO8 (1 << 5)
431 #define LP3974_LDO9 (1 << 4)
432 #define LP3974_LDO10 (1 << 3)
433 #define LP3974_LDO11 (1 << 2)
434 #define LP3974_LDO12 (1 << 1)
435 #define LP3974_LDO13 (1 << 0)
437 #define LP3974_LDO14 (1 << 7)
438 #define LP3974_LDO15 (1 << 6)
439 #define LP3974_LDO16 (1 << 5)
440 #define LP3974_LDO17 (1 << 4)
442 static int lp3974_probe(void)
444 unsigned char addr = 0xCC >> 1;
446 i2c_set_bus_num(I2C_5);
448 if (i2c_probe(addr)) {
449 puts("Can't found lp3974\n");
456 static int max8952_probe(void)
458 unsigned char addr = 0xC0 >> 1;
460 i2c_set_bus_num(I2C_5);
462 if (i2c_probe(addr)) {
463 puts("Cannot find MAX8952\n");
470 static void init_pmic_lp3974(void)
473 unsigned char val[2];
475 addr = 0xCC >> 1; /* LP3974 */
479 /* LDO2 1.2V LDO3 1.1V */
480 val[0] = 0x86; /* (((1200 - 800) / 50) << 4) | (((1100 - 800) / 50)) */
481 i2c_write(addr, 0x1D, 1, val, 1);
484 val[0] = 0x11; /* (3300 - 1600) / 100; */
485 i2c_write(addr, 0x1E, 1, val, 1);
488 val[0] = 0x0c; /* (2800 - 1600) / 100; */
489 i2c_write(addr, 0x1F, 1, val, 1);
491 /* LDO6 not used: minimum */
493 i2c_write(addr, 0x20, 1, val, 1);
496 val[0] = 0x02; /* (1800 - 1600) / 100; */
497 i2c_write(addr, 0x21, 1, val, 1);
499 /* LDO8 3.3V LDO9 2.8V*/
500 val[0] = 0x30; /* (((3300 - 3000) / 100) << 4) | (((2800 - 2800) / 100) << 0); */
501 i2c_write(addr, 0x22, 1, val, 1);
503 /* LDO10 1.1V LDO11 3.3V */
504 val[0] = 0x71; /* (((1100 - 950) / 50) << 5) | (((3300 - 1600) / 100) << 0); */
505 i2c_write(addr, 0x23, 1, val, 1);
508 val[0] = 0x14; /* (2800 - 1200) / 100 + 4; */
509 i2c_write(addr, 0x24, 1, val, 1);
512 val[0] = 0x4; /* (1200 - 1200) / 100 + 4; */
513 i2c_write(addr, 0x25, 1, val, 1);
516 val[0] = 0x6; /* (1800 - 1200) / 100; */
517 i2c_write(addr, 0x26, 1, val, 1);
520 val[0] = 0; /* (1200 - 1200) / 100; */
521 i2c_write(addr, 0x27, 1, val, 1);
524 val[0] = 0xc; /* (2800 - 1600) / 100; */
525 i2c_write(addr, 0x28, 1, val, 1);
528 val[0] = 0xe; /* (3000 - 1600) / 100; */
529 i2c_write(addr, 0x29, 1, val, 1);
532 * Because the data sheet of LP3974 does NOT mention default
533 * register values of ONOFF1~4 (ENABLE1~4), we ignore the given
534 * default values and set as we want
537 /* Note: To remove USB detect warning, Turn off LDO 8 first */
541 * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
542 * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
545 i2c_write(addr, LP3974_REG_ONOFF2, 1, val, 1);
549 * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
550 * LDO2 ON, LDO3 OFF, LDO4 ON, LDO5 ON
553 i2c_write(addr, LP3974_REG_ONOFF1, 1, val, 1);
557 * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 ON,
558 * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
561 i2c_write(addr, LP3974_REG_ONOFF3, 1, val, 1);
565 * EN32kAP ON, EN32kCP ON, ENVICHG ON, ENRAMP ON,
566 * RAMP 12mV/us (fastest)
569 i2c_write(addr, LP3974_REG_ONOFF4, 1, val, 1);
573 * ICHG: 500mA (0x3) / 600mA (0x5)
574 * RESTART LEVEL: 100mA (0x1)
575 * EOC LEVEL: 30% (0x4) / 25% (0x3) : both 150mA of ICHG
576 * Let's start with slower charging mode and let micro usb driver
577 * determine whether we can do it fast or not. Thus, using the slower
581 i2c_write(addr, 0xC, 1, val, 1);
585 * CHARGER DISABLE: Enable (0x0)
586 * TEMP CONTROL: 105C (0x0)
587 * BATT SEL: 4.2V (0x0)
588 * FULL TIMEOUT: 5hr (0x0)
589 * ESAFEOUT2: ON (0x1)
590 * ESAFEOUT1: OFF (0x0)
593 i2c_write(addr, 0xD, 1, val, 1);
595 val[0] = 0x0E; /* 1.1V @ DVSARM1(VINT) */
596 i2c_write(addr, 0x15, 1, val, 1);
597 val[0] = 0x0E; /* 1.1V @ DVSARM2(VINT) */
598 i2c_write(addr, 0x16, 1, val, 1);
599 val[0] = 0x0E; /* 1.1V @ DVSARM3(VINT) */
600 i2c_write(addr, 0x17, 1, val, 1);
601 val[0] = 0x0A; /* 1.0V @ DVSARM4(VINT) */
602 i2c_write(addr, 0x18, 1, val, 1);
603 val[0] = 0x12; /* 1.2V @ DVSINT1(VG3D) */
604 i2c_write(addr, 0x19, 1, val, 1);
605 val[0] = 0x0E; /* 1.1V @ DVSINT2(VG3D) */
606 i2c_write(addr, 0x1A, 1, val, 1);
608 val[0] = 0x2; /* 1.8V for BUCK3 VCC 1.8V PDA */
609 i2c_write(addr, 0x1B, 1, val, 1);
610 val[0] = 0x4; /* 1.2V for BUCK4 VMEM 1.2V C210 */
611 i2c_write(addr, 0x1C, 1, val, 1);
613 /* Use DVSARM1 for VINT */
614 gpio_direction_output(&gpio2->x0, 5, 0);
615 gpio_direction_output(&gpio2->x0, 6, 0);
616 /* Use DVSINT2 for VG3D */
617 gpio_direction_output(&gpio1->e2, 0, 1);
620 /* charger_en(): set lp3974 pmic's charger mode
621 * enable 0: disable charger
625 static void charger_en(int enable)
627 unsigned char addr = 0xCC >> 1; /* LP3974 */
628 unsigned char val[2];
635 puts("Disable the charger.\n");
636 i2c_read(addr, 0x0D, 1, val, 1);
638 i2c_write(addr, 0xD, 1, val, 1);
641 puts("Enable the charger @ 500mA\n");
644 * ICHG: 500mA (0x3) / 600mA (0x5)
645 * RESTART LEVEL: 100mA (0x1)
646 * EOC LEVEL: 30% (0x4) / 25% (0x3) : both 150mA of ICHG
647 * Let's start with slower charging mode and let micro usb driver
648 * determine whether we can do it fast or not. Thus, using the slower
652 i2c_write(addr, 0x0C, 1, val, 1);
653 i2c_read(addr, 0x0D, 1, val, 1);
655 i2c_write(addr, 0x0D, 1, val, 1);
658 puts("Enable the charger @ 600mA\n");
660 i2c_write(addr, 0x0C, 1, val, 1);
661 i2c_read(addr, 0x0D, 1, val, 1);
663 i2c_write(addr, 0x0D, 1, val, 1);
666 puts("Incorrect charger setting.\n");
670 struct thermister_stat {
675 static struct thermister_stat adc_to_temperature_data[] = {
676 { .centigrade = -20, .adc = 1856, },
677 { .centigrade = -15, .adc = 1799, },
678 { .centigrade = -10, .adc = 1730, },
679 { .centigrade = -5, .adc = 1649, },
680 { .centigrade = 0, .adc = 1556, },
681 { .centigrade = 5, .adc = 1454, },
682 { .centigrade = 10, .adc = 1343, },
683 { .centigrade = 15, .adc = 1227, },
684 { .centigrade = 20, .adc = 1109, },
685 { .centigrade = 25, .adc = 992, },
686 { .centigrade = 30, .adc = 880, },
687 { .centigrade = 35, .adc = 773, },
688 { .centigrade = 40, .adc = 675, },
689 { .centigrade = 45, .adc = 586, },
690 { .centigrade = 50, .adc = 507, },
691 { .centigrade = 55, .adc = 436, },
692 { .centigrade = 58, .adc = 399, },
693 { .centigrade = 63, .adc = 343, },
694 { .centigrade = 65, .adc = 322, },
698 #define USHRT_MAX 0xFFFFU
701 static int adc_to_temperature_centigrade(unsigned short adc)
705 /* low_*: Greatest Lower Bound,
706 * * * * high_*: Smallest Upper Bound */
707 int low_temp = 0, high_temp = 0;
708 unsigned short low_adc = 0, high_adc = USHRT_MAX;
709 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
710 if (adc_to_temperature_data[i].adc <= adc &&
711 adc_to_temperature_data[i].adc >= low_adc) {
712 low_temp = adc_to_temperature_data[i].centigrade;
713 low_adc = adc_to_temperature_data[i].adc;
715 if (adc_to_temperature_data[i].adc >= adc &&
716 adc_to_temperature_data[i].adc <= high_adc) {
717 high_temp = adc_to_temperature_data[i].centigrade;
718 high_adc = adc_to_temperature_data[i].adc;
722 /* Linear approximation between cloest low and high,
723 * which is the weighted average of the two. */
725 /* The following equation is correct only when the two are different */
726 if (low_adc == high_adc)
728 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
729 return 20; /* The room temperature */
732 if (high_adc == USHRT_MAX)
735 approximation = low_temp * (adc - low_adc) +
736 high_temp * (high_adc - adc);
737 approximation /= high_adc - low_adc;
739 return approximation;
742 static unsigned short get_adc_value(int channel);
743 static int adc_get_average_ambient_temperature(void)
745 unsigned short min = USHRT_MAX;
746 unsigned short max = 0;
747 unsigned int sum = 0;
748 unsigned int measured = 0;
751 for (i = 0; i < 7; i++) {
753 unsigned short measurement = get_adc_value(6);
756 if (min > measurement)
758 if (max < measurement)
767 printf("Average Ambient Temperature = %d(ADC=%d)\n",
768 adc_to_temperature_centigrade(sum), sum);
769 return adc_to_temperature_centigrade(sum);
772 enum temperature_level {
780 static enum temperature_level temperature_check(void)
782 int temp = adc_get_average_ambient_temperature();
784 return _TEMP_TOO_LOW;
788 return _TEMP_TOO_HIGH;
790 return _TEMP_OK_HIGH;
796 * Run a charge loop with animation and temperature check with sleep
798 static void into_charge_mode(int charger_speed)
802 enum temperature_level previous_state = _TEMP_OK;
803 unsigned int wakeup_stat;
805 /* 1. Show Animation */
806 for (i = 0; i < 5; i++) {
807 for (j = 0; j < 5; j++) {
809 for (delay = 0; delay < 1000; delay++)
815 /* 2. Loop with temperature check and sleep */
817 /* TODO: 2.A. Setup wakeup source and rtc tick */
819 /* TODO: 2.B. Go to sleep */
820 for (delay = 0; delay < 4000; delay++)
823 /* 2.C. Check the temperature */
824 switch (temperature_check()) {
826 charger_en(charger_speed);
827 previous_state = _TEMP_OK;
831 previous_state = _TEMP_TOO_LOW;
835 previous_state = _TEMP_TOO_HIGH;
838 if (previous_state == _TEMP_TOO_LOW) {
841 charger_en(charger_speed);
842 previous_state = _TEMP_OK;
846 if (previous_state == _TEMP_TOO_HIGH) {
849 charger_en(charger_speed);
850 previous_state = _TEMP_OK;
854 } while (wakeup_stat == 0x04);
857 static void init_pmic_max8952(void)
860 unsigned char val[2];
862 addr = 0xC0 >> 1; /* MAX8952 */
866 /* MODE0: 1.10V: Default */
868 i2c_write(addr, 0x00, 1, val, 1);
871 i2c_write(addr, 0x01, 1, val, 1);
874 i2c_write(addr, 0x02, 1, val, 1);
877 i2c_write(addr, 0x03, 1, val, 1);
880 * Note: use the default setting and configure pins high
881 * to generate the 1.1V
883 /* VARM_OUTPUT_SEL_A / VID_0 / XEINT_3 (GPX0[3]) = default 0 */
884 gpio_direction_output(&gpio2->x0, 3, 0);
885 /* VARM_OUTPUT_SEL_B / VID_1 / XEINT_4 (GPX0[4]) = default 0 */
886 gpio_direction_output(&gpio2->x0, 4, 0);
888 /* CONTROL: Disable PULL_DOWN */
890 i2c_write(addr, 0x04, 1, val, 1);
892 /* SYNC: Do Nothing */
893 /* RAMP: As Fast As Possible: Default: Do Nothing */
898 void fimd_clk_set(void)
900 struct s5pc210_clock *clk =
901 (struct s5pc210_clock *)samsung_get_base_clock();
904 unsigned long display_ctrl = 0x10010210;
905 unsigned int cfg = 0;
907 /* LCD0_BLK FIFO S/W reset */
908 cfg = readl(display_ctrl);
910 writel(cfg, display_ctrl);
914 /* FIMD of LBLK0 Bypass Selection */
915 cfg = readl(display_ctrl);
918 writel(cfg, display_ctrl);
920 /* set lcd src clock */
921 cfg = readl(&clk->src_lcd0);
924 writel(cfg, &clk->src_lcd0);
927 cfg = readl(&clk->div_lcd0);
930 writel(cfg, &clk->div_lcd0);
933 extern void ld9040_set_platform_data(struct spi_platform_data *pd);
935 struct spi_platform_data spi_pd;
937 static void lcd_cfg_gpio(void)
939 unsigned int i, f3_end = 4;
941 for (i = 0; i < 8; i++) {
942 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
943 gpio_cfg_pin(&gpio1->f0, i, GPIO_FUNC(2));
944 gpio_cfg_pin(&gpio1->f1, i, GPIO_FUNC(2));
945 gpio_cfg_pin(&gpio1->f2, i, GPIO_FUNC(2));
946 /* pull-up/down disable */
947 gpio_set_pull(&gpio1->f0, i, GPIO_PULL_NONE);
948 gpio_set_pull(&gpio1->f1, i, GPIO_PULL_NONE);
949 gpio_set_pull(&gpio1->f2, i, GPIO_PULL_NONE);
951 /* drive strength to max (24bit) */
952 gpio_set_drv(&gpio1->f0, i, GPIO_DRV_4X);
953 gpio_set_rate(&gpio1->f0, i, GPIO_DRV_SLOW);
954 gpio_set_drv(&gpio1->f1, i, GPIO_DRV_4X);
955 gpio_set_rate(&gpio1->f1, i, GPIO_DRV_SLOW);
956 gpio_set_drv(&gpio1->f2, i, GPIO_DRV_4X);
957 gpio_set_rate(&gpio1->f2, i, GPIO_DRV_SLOW);
960 for (i = 0; i < f3_end; i++) {
961 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
962 gpio_cfg_pin(&gpio1->f3, i, GPIO_PULL_UP);
963 /* pull-up/down disable */
964 gpio_set_pull(&gpio1->f3, i, GPIO_PULL_NONE);
965 /* drive strength to max (24bit) */
966 gpio_set_drv(&gpio1->f3, i, GPIO_DRV_4X);
967 gpio_set_rate(&gpio1->f3, i, GPIO_DRV_SLOW);
969 /* display output path selection (only [1:0] valid) */
970 //writel(0x2, 0xE0107008);
972 /* gpio pad configuration for LCD reset. */
973 gpio_direction_output(&gpio2->y4, 5, 1);
976 * gpio pad configuration for
977 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
980 gpio_cfg_pin(&gpio2->y4, 3, GPIO_OUTPUT);
981 gpio_cfg_pin(&gpio2->y3, 1, GPIO_OUTPUT);
982 gpio_cfg_pin(&gpio2->y3, 3, GPIO_OUTPUT);
984 spi_pd.cs_bank = &gpio2->y4;
986 spi_pd.clk_bank = &gpio2->y3;
988 spi_pd.si_bank = &gpio2->y3;
991 spi_pd.mode = SPI_MODE_3;
993 spi_pd.cs_active = ACTIVE_LOW;
996 ld9040_set_platform_data(&spi_pd);
1002 static void reset_lcd(void)
1004 gpio_set_value(&gpio2->y4, 5, 1);
1006 gpio_set_value(&gpio2->y4, 5, 0);
1008 gpio_set_value(&gpio2->y4, 5, 1);
1012 static void lcd_power_on(unsigned int onoff)
1015 unsigned char val[2];
1017 addr = 0xCC >> 1; /* lp3974 */
1022 i2c_read_r(addr, LP3974_REG_ONOFF3, 1, val, 1);
1023 val[0] &= ~(LP3974_LDO17);
1024 i2c_write(addr, LP3974_REG_ONOFF3, 1, val, 1);
1026 i2c_read_r(addr, LP3974_REG_ONOFF3, 1, val, 1);
1027 val[0] |= LP3974_LDO17;
1028 i2c_write(addr, LP3974_REG_ONOFF3, 1, val, 1);
1030 i2c_read_r(addr, LP3974_REG_ONOFF2, 1, val, 1);
1031 val[0] &= ~(LP3974_LDO7);
1032 i2c_write(addr, LP3974_REG_ONOFF2, 1, val, 1);
1034 i2c_read_r(addr, LP3974_REG_ONOFF2, 1, val, 1);
1035 val[0] |= LP3974_LDO7;
1036 i2c_write(addr, LP3974_REG_ONOFF2, 1, val, 1);
1038 i2c_read_r(addr, LP3974_REG_ONOFF3, 1, val, 1);
1039 val[0] &= ~(LP3974_LDO17);
1040 i2c_write(addr, LP3974_REG_ONOFF3, 1, val, 1);
1042 i2c_read_r(addr, LP3974_REG_ONOFF2, 1, val, 1);
1043 val[0] &= ~(LP3974_LDO7);
1044 i2c_write(addr, LP3974_REG_ONOFF2, 1, val, 1);
1049 extern void ld9040_cfg_ldo(void);
1050 extern void ld9040_enable_ldo(unsigned int onoff);
1052 int s5p_no_lcd_support(void)
1058 void init_panel_info(vidinfo_t *vid)
1063 vid->vl_width = 480;
1064 vid->vl_height = 800;
1065 vid->vl_clkp = CONFIG_SYS_HIGH;
1066 vid->vl_hsp = CONFIG_SYS_HIGH;
1067 vid->vl_vsp = CONFIG_SYS_HIGH;
1068 vid->vl_dp = CONFIG_SYS_HIGH;
1071 /* disable dual lcd mode. */
1072 vid->dual_lcd_enabled = 0;
1074 /* LD9040 LCD Panel */
1083 vid->cfg_gpio = lcd_cfg_gpio;
1084 vid->backlight_on = NULL;
1085 vid->lcd_power_on = NULL; /* Don't need the poweron squence */
1086 vid->reset_lcd = NULL; /* Don't need the reset squence */
1088 vid->cfg_ldo = ld9040_cfg_ldo;
1089 vid->enable_ldo = ld9040_enable_ldo;
1091 vid->init_delay = 0;
1092 vid->power_on_delay = 0;
1093 vid->reset_delay = 0;
1094 vid->interface_mode = FIMD_RGB_INTERFACE;
1096 /* board should be detected at here. */
1099 vid->pclk_name = MPLL;
1104 static unsigned short get_adc_value(int channel)
1106 struct s5p_adc *adc = (struct s5p_adc *)S5PC210_ADC_BASE;
1107 unsigned short ret = 0;
1109 unsigned int loop = 0;
1111 writel(channel & 0xF, &adc->adcmux);
1112 writel((1 << 14) | (49 << 6), &adc->adccon);
1113 writel(1000 & 0xffff, &adc->adcdly);
1114 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1116 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1121 reg = readl(&adc->adccon);
1122 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1124 ret = readl(&adc->adcdat0) & 0xFFF;
1129 static unsigned int get_hw_revision(void)
1131 int hwrev, mode0, mode1;
1133 mode0 = get_adc_value(1); /* HWREV_MODE0 */
1134 mode1 = get_adc_value(2); /* HWREV_MODE1 */
1136 pmic_ldo_control(0, 4, 0, 0);
1139 * XXX Always set the default hwrev as the latest board
1140 * ADC = (voltage) / 3.3 * 4096
1144 #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
1145 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
1146 hwrev = 0x0; /* 0.01V 0.01V */
1147 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
1148 hwrev = 0x1; /* 610mV 0.01V */
1149 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
1150 hwrev = 0x2; /* 1.16V 0.01V */
1153 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
1158 static const char *pcb_rev[] = {
1164 static void check_hw_revision(void)
1168 hwrev = get_hw_revision();
1172 printf("HW Revision:\t0x%x\n", board_rev);
1173 printf("PCB Revision:\t%s\n", pcb_rev[board_rev & 0xf]);
1176 static void check_reset_status(void)
1178 int status = get_reset_status();
1180 puts("Reset Status: ");
1184 puts("Pin(Ext) Reset\n");
1187 puts("Warm Reset\n");
1190 puts("Watchdog Reset\n");
1193 puts("S/W Reset\n");
1196 printf("Unknown (0x%x)\n", status);
1200 #ifdef CONFIG_CMD_RAMOOPS
1201 static void show_dump_msg(void)
1205 ret = ramoops_init(samsung_get_base_modem());
1208 setenv("bootdelay", "-1");
1212 #ifdef CONFIG_MISC_INIT_R
1213 int misc_init_r(void)
1215 check_reset_status();
1216 #ifdef CONFIG_CMD_RAMOOPS
1221 setenv("lcdinfo", "lcd=ld9040");
1225 check_hw_revision();
1228 /* check max17040 */
1238 #ifdef CONFIG_CMD_USBDOWN
1239 int usb_board_init(void)
1241 #ifdef CONFIG_CMD_PMIC
1242 run_command("pmic ldo 8 on", 0);
1243 run_command("pmic ldo 3 on", 0);
1244 run_command("pmic safeout 1 on", 0);
1250 #ifdef CONFIG_GENERIC_MMC
1251 int s5p_no_mmc_support(void)
1256 int board_mmc_init(bd_t *bis)
1260 switch (get_hwrev()) {
1263 * Set the low to enable LDO_EN
1264 * But when you use the test board for eMMC booting
1265 * you should set it HIGH since it removes the inverter
1267 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
1268 gpio_direction_output(&gpio1->e3, 6, 0);
1273 * Default reset state is High and there's no inverter
1274 * But set it as HIGH to ensure
1276 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
1277 gpio_direction_output(&gpio1->e1, 3, 1);
1283 * SDR 8-bit@48MHz at MMC0
1284 * GPK0[0] SD_0_CLK(2)
1285 * GPK0[1] SD_0_CMD(2)
1286 * GPK0[2] SD_0_CDn -> Not used
1287 * GPK0[3:6] SD_0_DATA[0:3](2)
1288 * GPK1[3:6] SD_0_DATA[0:3](3)
1290 * DDR 4-bit@26MHz at MMC4
1291 * GPK0[0] SD_4_CLK(3)
1292 * GPK0[1] SD_4_CMD(3)
1293 * GPK0[2] SD_4_CDn -> Not used
1294 * GPK0[3:6] SD_4_DATA[0:3](3)
1295 * GPK1[3:6] SD_4_DATA[4:7](4)
1297 for (i = 0; i < 7; i++) {
1300 /* GPK0[0:6] special function 2 */
1301 gpio_cfg_pin(&gpio2->k0, i, 0x2);
1302 /* GPK0[0:6] pull disable */
1303 gpio_set_pull(&gpio2->k0, i, GPIO_PULL_NONE);
1304 /* GPK0[0:6] drv 4x */
1305 gpio_set_drv(&gpio2->k0, i, GPIO_DRV_4X);
1308 for (i = 3; i < 7; i++) {
1309 /* GPK1[3:6] special function 3 */
1310 gpio_cfg_pin(&gpio2->k1, i, 0x3);
1311 /* GPK1[3:6] pull disable */
1312 gpio_set_pull(&gpio2->k1, i, GPIO_PULL_NONE);
1313 /* GPK1[3:6] drv 4x */
1314 gpio_set_drv(&gpio2->k1, i, GPIO_DRV_4X);
1317 /* T-flash detect */
1318 gpio_cfg_pin(&gpio2->x3, 4, 0xf);
1319 gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
1323 * mmc0 : eMMC (8-bit buswidth)
1324 * mmc2 : SD card (4-bit buswidth)
1326 err = s5p_mmc_init(0, 8);
1328 if (!gpio_get_value(&gpio2->x3, 4)) {
1331 * GPK2[0] SD_2_CLK(2)
1332 * GPK2[1] SD_2_CMD(2)
1333 * GPK2[2] SD_2_CDn -> Not used
1334 * GPK2[3:6] SD_2_DATA[0:3](2)
1336 for (i = 0; i < 7; i++) {
1339 /* GPK2[0:6] special function 2 */
1340 gpio_cfg_pin(&gpio2->k2, i, 0x2);
1341 /* GPK2[0:6] pull disable */
1342 gpio_set_pull(&gpio2->k2, i, GPIO_PULL_NONE);
1343 /* GPK2[0:6] drv 4x */
1344 gpio_set_drv(&gpio2->k2, i, GPIO_DRV_4X);
1346 err = s5p_mmc_init(2, 4);
1354 #ifdef CONFIG_CMD_PMIC
1355 static int pmic_status(void)
1357 unsigned char addr, val[2];
1366 i2c_read_r(addr, reg, 1, val, 1);
1367 for (i = 7; i >= 4; i--)
1368 printf("BUCK%d %s\n", 7 - i + 1,
1369 val[0] & (1 << i) ? "on" : "off");
1371 printf("LDO%d %s\n", 5 - i,
1372 val[0] & (1 << i) ? "on" : "off");
1374 i2c_read_r(addr, reg, 1, val, 1);
1375 for (i = 7; i >= 0; i--)
1376 printf("LDO%d %s\n", 7 - i + 6,
1377 val[0] & (1 << i) ? "on" : "off");
1379 i2c_read_r(addr, reg, 1, val, 1);
1380 for (i = 7; i >= 4; i--)
1381 printf("LDO%d %s\n", 7 - i + 14,
1382 val[0] & (1 << i) ? "on" : "off");
1385 i2c_read_r(addr, reg, 1, val, 1);
1386 for (i = 7; i >= 6; i--)
1387 printf("SAFEOUT%d %s\n", 7 - i + 1,
1388 val[0] & (1 << i) ? "on" : "off");
1392 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
1394 unsigned char addr, val[2];
1395 unsigned int reg, shift;
1403 } else if (ldo <= 13) {
1406 } else if (ldo <= 17) {
1408 shift = 17 - ldo + 4;
1415 shift = 4 - buck + 4;
1416 } else if (safeout) {
1420 shift = 8 - safeout;
1429 i2c_read_r(addr, reg, 1, val, 1);
1431 val[0] |= (1 << shift);
1433 val[0] &= ~(1 << shift);
1434 i2c_write(addr, reg, 1, val, 1);
1435 i2c_read_r(addr, reg, 1, val, 1);
1440 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1442 int buck = 0, ldo = 0, safeout = 0, on = -1;
1447 if (strncmp(argv[1], "status", 6) == 0)
1448 return pmic_status();
1451 if (strncmp(argv[1], "ldo", 3) == 0)
1452 ldo = simple_strtoul(argv[2], NULL, 10);
1453 else if (strncmp(argv[1], "buck", 4) == 0)
1454 buck = simple_strtoul(argv[2], NULL, 10);
1455 else if (strncmp(argv[1], "safeout", 7) == 0)
1456 safeout = simple_strtoul(argv[2], NULL, 10);
1460 if (strncmp(argv[3], "on", 2) == 0)
1462 else if (strncmp(argv[3], "off", 3) == 0)
1467 ret = pmic_ldo_control(buck, ldo, safeout, on);
1470 printf("%s %s %s\n", argv[1], argv[2], argv[3]);
1482 pmic, 4, 1, do_pmic,
1483 "PMIC LDO & BUCK control",
1484 "status - Display PMIC LDO & BUCK status\n"
1485 "pmic ldo num on/off - Turn on/off the LDO\n"
1486 "pmic buck num on/off - Turn on/off the BUCK\n"
1487 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
1491 #ifdef CONFIG_CMD_DEVICE_POWER
1492 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
1496 if (strncmp(argv[1], "cp", 2) == 0) {
1497 micro_usb_switch(1);
1498 run_command("pmic safeout 2 on", 0);
1499 setenv("usb", "cp");
1500 } else if (strncmp(argv[1], "ap", 2) == 0) {
1501 micro_usb_switch(0);
1502 run_command("pmic safeout 2 off", 0);
1503 setenv("usb", "ap");
1513 printf("USB Path is set to %s\n", getenv("usb"));
1519 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
1521 "cp - switch to CP\n"
1522 "microusb ap - switch to AP\n"