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>
37 #include <info_action.h>
40 DECLARE_GLOBAL_DATA_PTR;
42 static struct s5pc210_gpio_part1 *gpio1;
43 static struct s5pc210_gpio_part2 *gpio2;
45 static unsigned int battery_soc;
46 static unsigned int board_rev;
48 u32 get_board_rev(void)
53 static int get_hwrev(void)
55 return board_rev & 0xFF;
59 I2C_0, I2C_1, I2C_2, I2C_3,
60 I2C_4, I2C_5, I2C_6, I2C_7,
61 I2C_8, I2C_9, I2C_10, I2C_11,
62 I2C_12, I2C_13, I2C_NUM,
65 /* i2c0 (CAM) SDA: GPD1[0] SCL: GPD1[1] */
66 static struct i2c_gpio_bus_data i2c_0 = {
71 /* i2c1 (Gryo) SDA: GPD1[2] SCL: GPD1[3] */
72 static struct i2c_gpio_bus_data i2c_1 = {
77 /* i2c3 (TSP) SDA: GPA1[2] SCL: GPA1[3] */
78 static struct i2c_gpio_bus_data i2c_3 = {
83 /* i2c4 SDA: GPB[2] SCL: GPB[3] */
84 static struct i2c_gpio_bus_data i2c_4 = {
89 /* i2c5 (PMIC) SDA: GPB[6] SCL: GPB[7] */
90 static struct i2c_gpio_bus_data i2c_5 = {
95 /* i2c6 (CODEC) SDA: GPC1[3] SCL: GPC1[4] */
96 static struct i2c_gpio_bus_data i2c_6 = {
101 /* i2c7 SDA: GPD0[2] SCL: GPD0[3] */
102 static struct i2c_gpio_bus_data i2c_7 = {
107 /* i2c9 SDA: SPY4[0] SCL: SPY4[1] */
108 static struct i2c_gpio_bus_data i2c_9 = {
113 /* i2c10 SDA: SPE1[0] SCL: SPE1[1] */
114 static struct i2c_gpio_bus_data i2c_10 = {
119 /* i2c12 SDA: SPE4[0] SCL: SPE4[1] */
120 static struct i2c_gpio_bus_data i2c_12 = {
125 /* i2c13 SDA: SPE4[2] SCL: SPE4[3] */
126 static struct i2c_gpio_bus_data i2c_13 = {
131 static struct i2c_gpio_bus i2c_gpio[I2C_NUM];
133 static void check_battery(int mode);
134 static void check_micro_usb(int intr);
135 static void init_pmic_lp3974(void);
136 static void init_pmic_max8952(void);
138 void i2c_init_board(void)
140 gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
141 gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
143 i2c_gpio[I2C_0].bus = &i2c_0;
144 i2c_gpio[I2C_1].bus = &i2c_1;
145 i2c_gpio[I2C_2].bus = NULL;
146 i2c_gpio[I2C_3].bus = &i2c_3;
147 i2c_gpio[I2C_4].bus = &i2c_4;
148 i2c_gpio[I2C_5].bus = &i2c_5;
149 i2c_gpio[I2C_6].bus = &i2c_6;
150 i2c_gpio[I2C_7].bus = &i2c_7;
151 i2c_gpio[I2C_8].bus = NULL;
152 i2c_gpio[I2C_9].bus = &i2c_9;
153 i2c_gpio[I2C_10].bus = &i2c_10;
154 i2c_gpio[I2C_11].bus = NULL;
155 i2c_gpio[I2C_12].bus = &i2c_12;
156 i2c_gpio[I2C_13].bus = &i2c_13;
158 i2c_gpio[I2C_0].bus->gpio_base = (unsigned int)&gpio1->d1;
159 i2c_gpio[I2C_1].bus->gpio_base = (unsigned int)&gpio1->d1;
160 i2c_gpio[I2C_3].bus->gpio_base = (unsigned int)&gpio1->a1;
161 i2c_gpio[I2C_4].bus->gpio_base = (unsigned int)&gpio1->b;
162 i2c_gpio[I2C_5].bus->gpio_base = (unsigned int)&gpio1->b;
163 i2c_gpio[I2C_6].bus->gpio_base = (unsigned int)&gpio1->c1;
164 i2c_gpio[I2C_7].bus->gpio_base = (unsigned int)&gpio1->d0;
165 i2c_gpio[I2C_9].bus->gpio_base = (unsigned int)&gpio2->y4;
166 i2c_gpio[I2C_10].bus->gpio_base = (unsigned int)&gpio1->e1;
167 i2c_gpio[I2C_12].bus->gpio_base = (unsigned int)&gpio1->e4;
168 i2c_gpio[I2C_13].bus->gpio_base = (unsigned int)&gpio1->e4;
170 i2c_gpio_init(i2c_gpio, I2C_NUM, I2C_5);
173 static void check_hw_revision(void);
177 gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
178 gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
180 gd->bd->bi_arch_number = MACH_TYPE;
181 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
190 gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE;
192 /* Early init for i2c devices - Where these funcions should go?? */
194 /* Reset on max17040 */
201 /* Reset on fsa9480 */
207 void dram_init_banksize(void)
209 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
210 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
211 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
212 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
214 gd->ram_size = gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size;
217 static void check_auto_burn(void)
219 unsigned int magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
220 unsigned int count = 0;
224 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
225 puts("Auto buring bootloader\n");
226 count += sprintf(buf + count, "run updateb; ");
229 if (readl(magic_base) == 0x654D4D43) { /* ASICC: eMMC */
230 puts("Auto buring bootloader (eMMC)\n");
231 count += sprintf(buf + count, "run updatemmc; ");
233 if (readl(magic_base + 0x4) == 0x4b65726e) { /* ASICC: Kern */
234 puts("Auto buring kernel\n");
235 count += sprintf(buf + count, "run updatek; ");
237 /* Backup u-boot in eMMC */
238 if (readl(magic_base + 0x8) == 0x4261636B) { /* ASICC: Back */
239 puts("Auto buring u-boot image (boot partition2 in eMMC)\n");
240 count += sprintf(buf + count, "run updatebackup; ");
244 count += sprintf(buf + count, "reset");
245 setenv("bootcmd", buf);
248 /* Clear the magic value */
249 memset((void *)magic_base, 0, 2);
252 static void check_battery(int mode)
254 unsigned char val[2];
255 unsigned char addr = 0x36; /* max17040 fuel gauge */
257 i2c_set_bus_num(I2C_9);
259 if (i2c_probe(addr)) {
260 puts("Can't found max17040 fuel gauge\n");
264 /* mode 0: check mode / 1: enable mode */
268 i2c_write(addr, 0xfe, 1, val, 2);
270 i2c_read(addr, 0x04, 1, val, 1);
271 printf("battery:\t%d%%\n", val[0]);
272 battery_soc = val[0];
276 static int fsa9480_probe(void)
278 unsigned char addr = 0x25;
280 i2c_set_bus_num(I2C_10);
282 if (i2c_probe(addr)) {
283 puts("Can't found fsa9480\n");
290 static void charger_en(int enable);
291 static void into_charge_mode(int charger_speed);
292 static void check_micro_usb(int intr)
295 unsigned char val[2];
296 static int started_charging_once = 0;
302 addr = 0x25; /* fsa9480 */
304 /* Clear Interrupt */
306 i2c_read(addr, 0x03, 1, val, 2);
310 /* Read Device Type 1 */
311 i2c_read(addr, 0x0a, 1, val, 1);
313 #define FSA_DEV1_CHARGER (1 << 6)
314 #define FSA_DEV1_UART (1 << 3)
315 #define FSA_DEV1_USB (1 << 2)
316 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
317 #define FSA_DEV2_JIG_USB_ON (1 << 0)
319 /* disable the charger related feature */
321 * If USB, use default 475mA
322 * If Charger, use 600mA and go to charge mode
324 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
325 started_charging_once = 1;
327 /* If it's full, do not charge. */
328 if (battery_soc < 100) {
330 into_charge_mode(600);
333 } else if (val[0] & FSA_DEV1_USB) {
334 if (battery_soc < 100)
335 charger_en(500); /* enable charger and keep booting */
340 /* If reset status is watchdog reset then skip it */
341 if (get_reset_status() != SWRESET) {
342 /* If Factory Mode is Boot ON-USB, go to download mode */
343 i2c_read(addr, 0x07, 1, val, 1);
345 #define FSA_ADC_FAC_USB_OFF 0x18
346 #define FSA_ADC_FAC_USB_ON 0x19
347 #define FSA_ADC_FAC_UART 0x1d
349 if (val[0] == FSA_ADC_FAC_USB_ON ||
350 val[0] == FSA_ADC_FAC_USB_OFF)
351 setenv("bootcmd", "usbdown");
354 path = getenv("usb");
356 if (!strncmp(path, "cp", 2))
357 run_command("microusb cp", 0);
360 static void micro_usb_switch(int path)
363 unsigned char val[2];
368 addr = 0x25; /* fsa9480 */
371 val[0] = 0x90; /* VAUDIO */
373 val[0] = (1 << 5) | (1 << 2); /* DHOST */
375 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
377 i2c_read(addr, 0x2, 1, val, 1);
378 val[0] &= ~(1 << 2); /* Manual switching */
379 i2c_write(addr, 0x2, 1, val, 1);
382 #define LP3974_REG_IRQ1 0x00
383 #define LP3974_REG_IRQ2 0x01
384 #define LP3974_REG_IRQ3 0x02
385 #define LP3974_REG_ONOFF1 0x11
386 #define LP3974_REG_ONOFF2 0x12
387 #define LP3974_REG_ONOFF3 0x13
388 #define LP3974_REG_ONOFF4 0x14
389 #define LP3974_REG_LDO7 0x21
390 #define LP3974_REG_LDO17 0x29
391 #define LP3974_REG_UVLO 0xB9
392 #define LP3974_REG_MODCHG 0xEF
394 #define LP3974_LDO3 (1 << 2)
396 #define LP3974_LDO6 (1 << 7)
397 #define LP3974_LDO7 (1 << 6)
398 #define LP3974_LDO8 (1 << 5)
399 #define LP3974_LDO9 (1 << 4)
400 #define LP3974_LDO10 (1 << 3)
401 #define LP3974_LDO11 (1 << 2)
402 #define LP3974_LDO12 (1 << 1)
403 #define LP3974_LDO13 (1 << 0)
405 #define LP3974_LDO14 (1 << 7)
406 #define LP3974_LDO15 (1 << 6)
407 #define LP3974_LDO16 (1 << 5)
408 #define LP3974_LDO17 (1 << 4)
410 static int lp3974_probe(void)
412 unsigned char addr = 0xCC >> 1;
414 i2c_set_bus_num(I2C_5);
416 if (i2c_probe(addr)) {
417 puts("Can't found lp3974\n");
424 static int max8952_probe(void)
426 unsigned char addr = 0xC0 >> 1;
428 i2c_set_bus_num(I2C_5);
430 if (i2c_probe(addr)) {
431 puts("Cannot find MAX8952\n");
438 static void init_pmic_lp3974(void)
441 unsigned char val[2];
443 addr = 0xCC >> 1; /* LP3974 */
447 /* LDO2 1.2V LDO3 1.1V */
448 val[0] = 0x86; /* (((1200 - 800) / 50) << 4) | (((1100 - 800) / 50)) */
449 i2c_write(addr, 0x1D, 1, val, 1);
452 val[0] = 0x11; /* (3300 - 1600) / 100; */
453 i2c_write(addr, 0x1E, 1, val, 1);
456 val[0] = 0x0c; /* (2800 - 1600) / 100; */
457 i2c_write(addr, 0x1F, 1, val, 1);
459 /* LDO6 not used: minimum */
461 i2c_write(addr, 0x20, 1, val, 1);
464 val[0] = 0x02; /* (1800 - 1600) / 100; */
465 i2c_write(addr, 0x21, 1, val, 1);
467 /* LDO8 3.3V LDO9 2.8V*/
468 val[0] = 0x30; /* (((3300 - 3000) / 100) << 4) | (((2800 - 2800) / 100) << 0); */
469 i2c_write(addr, 0x22, 1, val, 1);
471 /* LDO10 1.1V LDO11 3.3V */
472 val[0] = 0x71; /* (((1100 - 950) / 50) << 5) | (((3300 - 1600) / 100) << 0); */
473 i2c_write(addr, 0x23, 1, val, 1);
476 val[0] = 0x14; /* (2800 - 1200) / 100 + 4; */
477 i2c_write(addr, 0x24, 1, val, 1);
480 val[0] = 0x4; /* (1200 - 1200) / 100 + 4; */
481 i2c_write(addr, 0x25, 1, val, 1);
484 val[0] = 0x6; /* (1800 - 1200) / 100; */
485 i2c_write(addr, 0x26, 1, val, 1);
488 val[0] = 0; /* (1200 - 1200) / 100; */
489 i2c_write(addr, 0x27, 1, val, 1);
492 val[0] = 0xc; /* (2800 - 1600) / 100; */
493 i2c_write(addr, 0x28, 1, val, 1);
496 val[0] = 0xe; /* (3000 - 1600) / 100; */
497 i2c_write(addr, 0x29, 1, val, 1);
500 * Because the data sheet of LP3974 does NOT mention default
501 * register values of ONOFF1~4 (ENABLE1~4), we ignore the given
502 * default values and set as we want
505 /* Note: To remove USB detect warning, Turn off LDO 8 first */
509 * LDO6 OFF, LDO7 ON, LDO8 OFF, LDO9 ON,
510 * LDO10 OFF, LDO11 OFF, LDO12 OFF, LDO13 OFF
513 i2c_write(addr, LP3974_REG_ONOFF2, 1, val, 1);
517 * Buck1 ON, Buck2 OFF, Buck3 ON, Buck4 ON
518 * LDO2 ON, LDO3 OFF, LDO4 ON, LDO5 ON
521 i2c_write(addr, LP3974_REG_ONOFF1, 1, val, 1);
525 * LDO14 OFF, LDO15 OFF, LGO16 OFF, LDO17 ON,
526 * EPWRHOLD OFF, EBATTMON OFF, ELBCNFG2 OFF, ELBCNFG1 OFF
529 i2c_write(addr, LP3974_REG_ONOFF3, 1, val, 1);
533 * EN32kAP ON, EN32kCP ON, ENVICHG ON, ENRAMP ON,
534 * RAMP 12mV/us (fastest)
537 i2c_write(addr, LP3974_REG_ONOFF4, 1, val, 1);
541 * ICHG: 500mA (0x3) / 600mA (0x5)
542 * RESTART LEVEL: 100mA (0x1)
543 * EOC LEVEL: 30% (0x4) / 25% (0x3) : both 150mA of ICHG
544 * Let's start with slower charging mode and let micro usb driver
545 * determine whether we can do it fast or not. Thus, using the slower
549 i2c_write(addr, 0xC, 1, val, 1);
553 * CHARGER DISABLE: Enable (0x0)
554 * TEMP CONTROL: 105C (0x0)
555 * BATT SEL: 4.2V (0x0)
556 * FULL TIMEOUT: 5hr (0x0)
557 * ESAFEOUT2: ON (0x1)
558 * ESAFEOUT1: OFF (0x0)
561 i2c_write(addr, 0xD, 1, val, 1);
563 val[0] = 0x0E; /* 1.1V @ DVSARM1(VINT) */
564 i2c_write(addr, 0x15, 1, val, 1);
565 val[0] = 0x0E; /* 1.1V @ DVSARM2(VINT) */
566 i2c_write(addr, 0x16, 1, val, 1);
567 val[0] = 0x0E; /* 1.1V @ DVSARM3(VINT) */
568 i2c_write(addr, 0x17, 1, val, 1);
569 val[0] = 0x0A; /* 1.0V @ DVSARM4(VINT) */
570 i2c_write(addr, 0x18, 1, val, 1);
571 val[0] = 0x12; /* 1.2V @ DVSINT1(VG3D) */
572 i2c_write(addr, 0x19, 1, val, 1);
573 val[0] = 0x0E; /* 1.1V @ DVSINT2(VG3D) */
574 i2c_write(addr, 0x1A, 1, val, 1);
576 val[0] = 0x2; /* 1.8V for BUCK3 VCC 1.8V PDA */
577 i2c_write(addr, 0x1B, 1, val, 1);
578 val[0] = 0x4; /* 1.2V for BUCK4 VMEM 1.2V C210 */
579 i2c_write(addr, 0x1C, 1, val, 1);
581 /* Use DVSARM1 for VINT */
582 gpio_direction_output(&gpio2->x0, 5, 0);
583 gpio_direction_output(&gpio2->x0, 6, 0);
584 /* Use DVSINT2 for VG3D */
585 gpio_direction_output(&gpio1->e2, 0, 1);
588 * Default level of UVLO.
589 * UVLOf = 2.7V (0x3 << 4), UVLOr = 3.1V (0xB)
590 * set UVLOf to 2.55V (0 << 4).
593 i2c_write(addr, LP3974_REG_MODCHG, 1, val, 1);
595 i2c_write(addr, LP3974_REG_MODCHG, 1, val, 1);
597 i2c_write(addr, LP3974_REG_MODCHG, 1, val, 1);
599 i2c_read_r(addr, LP3974_REG_UVLO, 1, val, 1);
600 val[0] = (val[0] & 0xf) | (0 << 4);
601 i2c_write(addr, LP3974_REG_UVLO, 1, val, 1);
604 i2c_write(addr, LP3974_REG_MODCHG, 1, val, 1);
607 static int poweron_key_check(void)
609 unsigned char addr, val[2];
615 i2c_read_r(addr, LP3974_REG_IRQ3, 1, val, 1);
619 int check_exit_key(void)
621 return poweron_key_check();
624 static int power_key_check(void)
626 unsigned char addr, val[4];
633 /* power_key check */
634 i2c_read_r(addr, LP3974_REG_IRQ1, 1, val, 4);
636 tmp = ((val[0] & (1 << 7)) >> 7);
641 static void check_keypad(void)
643 unsigned int val = 0;
644 unsigned int power_key, auto_download = 0;
646 val = ~(gpio_get_value(&gpio2->x2, 1));
648 power_key = power_key_check();
650 if (power_key && (val & 0x1))
654 setenv("bootcmd", "usbdown");
658 * charger_en(): set lp3974 pmic's charger mode
659 * enable 0: disable charger
663 static void charger_en(int enable)
665 unsigned char addr = 0xCC >> 1; /* LP3974 */
666 unsigned char val[2];
673 puts("Disable the charger.\n");
674 i2c_read(addr, 0x0D, 1, val, 1);
676 i2c_write(addr, 0xD, 1, val, 1);
679 puts("Enable the charger @ 500mA\n");
682 * ICHG: 500mA (0x3) / 600mA (0x5)
683 * RESTART LEVEL: 100mA (0x1)
684 * EOC LEVEL: 30% (0x4) / 25% (0x3) : both 150mA of ICHG
685 * Let's start with slower charging mode and
686 * let micro usb driver determine whether we can do it
687 * fast or not. Thus, using the slower setting...
690 i2c_write(addr, 0x0C, 1, val, 1);
691 i2c_read(addr, 0x0D, 1, val, 1);
693 i2c_write(addr, 0x0D, 1, val, 1);
696 puts("Enable the charger @ 600mA\n");
698 i2c_write(addr, 0x0C, 1, val, 1);
699 i2c_read(addr, 0x0D, 1, val, 1);
701 i2c_write(addr, 0x0D, 1, val, 1);
704 puts("Incorrect charger setting.\n");
708 struct thermister_stat {
713 static struct thermister_stat adc_to_temperature_data[] = {
714 { .centigrade = -20, .adc = 1856, },
715 { .centigrade = -15, .adc = 1799, },
716 { .centigrade = -10, .adc = 1730, },
717 { .centigrade = -5, .adc = 1649, },
718 { .centigrade = 0, .adc = 1556, },
719 { .centigrade = 5, .adc = 1454, },
720 { .centigrade = 10, .adc = 1343, },
721 { .centigrade = 15, .adc = 1227, },
722 { .centigrade = 20, .adc = 1109, },
723 { .centigrade = 25, .adc = 992, },
724 { .centigrade = 30, .adc = 880, },
725 { .centigrade = 35, .adc = 773, },
726 { .centigrade = 40, .adc = 675, },
727 { .centigrade = 45, .adc = 586, },
728 { .centigrade = 50, .adc = 507, },
729 { .centigrade = 55, .adc = 436, },
730 { .centigrade = 58, .adc = 399, },
731 { .centigrade = 63, .adc = 343, },
732 { .centigrade = 65, .adc = 322, },
736 #define USHRT_MAX 0xFFFFU
739 static int adc_to_temperature_centigrade(unsigned short adc)
743 /* low_*: Greatest Lower Bound,
744 * * * * high_*: Smallest Upper Bound */
745 int low_temp = 0, high_temp = 0;
746 unsigned short low_adc = 0, high_adc = USHRT_MAX;
747 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
748 if (adc_to_temperature_data[i].adc <= adc &&
749 adc_to_temperature_data[i].adc >= low_adc) {
750 low_temp = adc_to_temperature_data[i].centigrade;
751 low_adc = adc_to_temperature_data[i].adc;
753 if (adc_to_temperature_data[i].adc >= adc &&
754 adc_to_temperature_data[i].adc <= high_adc) {
755 high_temp = adc_to_temperature_data[i].centigrade;
756 high_adc = adc_to_temperature_data[i].adc;
760 /* Linear approximation between cloest low and high,
761 * which is the weighted average of the two. */
763 /* The following equation is correct only when the two are different */
764 if (low_adc == high_adc)
766 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
767 return 20; /* The room temperature */
770 if (high_adc == USHRT_MAX)
773 approximation = low_temp * (adc - low_adc) +
774 high_temp * (high_adc - adc);
775 approximation /= high_adc - low_adc;
777 return approximation;
780 static int adc_get_average_ambient_temperature(void)
782 unsigned short min = USHRT_MAX;
783 unsigned short max = 0;
784 unsigned int sum = 0;
785 unsigned int measured = 0;
788 for (i = 0; i < 7; i++) {
790 unsigned short measurement = get_adc_value(6);
793 if (min > measurement)
795 if (max < measurement)
804 printf("Average Ambient Temperature = %d(ADC=%d)\n",
805 adc_to_temperature_centigrade(sum), sum);
806 return adc_to_temperature_centigrade(sum);
809 enum temperature_level {
817 static enum temperature_level temperature_check(void)
819 int temp = adc_get_average_ambient_temperature();
821 return _TEMP_TOO_LOW;
825 return _TEMP_TOO_HIGH;
827 return _TEMP_OK_HIGH;
833 * Run a charge loop with animation and temperature check with sleep
835 static void into_charge_mode(int charger_speed)
838 enum temperature_level previous_state = _TEMP_OK;
839 unsigned int wakeup_stat = 0;
841 /* 1. Show Animation */
842 for (i = 0; i < 5; i++) {
843 for (j = 0; j < 5; j++) {
845 for (delay = 0; delay < 1000; delay++)
851 /* 2. Loop with temperature check and sleep */
853 /* TODO: 2.A. Setup wakeup source and rtc tick */
855 /* TODO: 2.B. Go to sleep */
856 for (delay = 0; delay < 4000; delay++)
859 /* 2.C. Check the temperature */
860 switch (temperature_check()) {
862 charger_en(charger_speed);
863 previous_state = _TEMP_OK;
867 previous_state = _TEMP_TOO_LOW;
871 previous_state = _TEMP_TOO_HIGH;
874 if (previous_state == _TEMP_TOO_LOW) {
877 charger_en(charger_speed);
878 previous_state = _TEMP_OK;
882 if (previous_state == _TEMP_TOO_HIGH) {
885 charger_en(charger_speed);
886 previous_state = _TEMP_OK;
890 } while (wakeup_stat == 0x04);
893 static void init_pmic_max8952(void)
896 unsigned char val[2];
898 addr = 0xC0 >> 1; /* MAX8952 */
902 /* MODE0: 1.10V: Default */
904 i2c_write(addr, 0x00, 1, val, 1);
907 i2c_write(addr, 0x01, 1, val, 1);
910 i2c_write(addr, 0x02, 1, val, 1);
913 i2c_write(addr, 0x03, 1, val, 1);
916 * Note: use the default setting and configure pins high
917 * to generate the 1.1V
919 /* VARM_OUTPUT_SEL_A / VID_0 / XEINT_3 (GPX0[3]) = default 0 */
920 gpio_direction_output(&gpio2->x0, 3, 0);
921 /* VARM_OUTPUT_SEL_B / VID_1 / XEINT_4 (GPX0[4]) = default 0 */
922 gpio_direction_output(&gpio2->x0, 4, 0);
924 /* CONTROL: Disable PULL_DOWN */
926 i2c_write(addr, 0x04, 1, val, 1);
928 /* SYNC: Do Nothing */
929 /* RAMP: As Fast As Possible: Default: Do Nothing */
934 void fimd_clk_set(void)
936 struct s5pc210_clock *clk =
937 (struct s5pc210_clock *)samsung_get_base_clock();
940 unsigned long display_ctrl = 0x10010210;
941 unsigned int cfg = 0;
943 /* LCD0_BLK FIFO S/W reset */
944 cfg = readl(display_ctrl);
946 writel(cfg, display_ctrl);
950 /* FIMD of LBLK0 Bypass Selection */
951 cfg = readl(display_ctrl);
954 writel(cfg, display_ctrl);
956 /* set lcd src clock */
957 cfg = readl(&clk->src_lcd0);
960 writel(cfg, &clk->src_lcd0);
963 cfg = readl(&clk->div_lcd0);
966 writel(cfg, &clk->div_lcd0);
969 extern void ld9040_set_platform_data(struct spi_platform_data *pd);
971 struct spi_platform_data spi_pd;
973 static void lcd_cfg_gpio(void)
977 for (i = 0; i < 8; i++) {
978 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
979 gpio_cfg_pin(&gpio1->f0, i, GPIO_FUNC(2));
980 gpio_cfg_pin(&gpio1->f1, i, GPIO_FUNC(2));
981 gpio_cfg_pin(&gpio1->f2, i, GPIO_FUNC(2));
982 /* pull-up/down disable */
983 gpio_set_pull(&gpio1->f0, i, GPIO_PULL_NONE);
984 gpio_set_pull(&gpio1->f1, i, GPIO_PULL_NONE);
985 gpio_set_pull(&gpio1->f2, i, GPIO_PULL_NONE);
987 /* drive strength to max (24bit) */
988 gpio_set_drv(&gpio1->f0, i, GPIO_DRV_4X);
989 gpio_set_rate(&gpio1->f0, i, GPIO_DRV_SLOW);
990 gpio_set_drv(&gpio1->f1, i, GPIO_DRV_4X);
991 gpio_set_rate(&gpio1->f1, i, GPIO_DRV_SLOW);
992 gpio_set_drv(&gpio1->f2, i, GPIO_DRV_4X);
993 gpio_set_rate(&gpio1->f2, i, GPIO_DRV_SLOW);
996 for (i = 0; i < 4; i++) {
997 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
998 gpio_cfg_pin(&gpio1->f3, i, GPIO_PULL_UP);
999 /* pull-up/down disable */
1000 gpio_set_pull(&gpio1->f3, i, GPIO_PULL_NONE);
1001 /* drive strength to max (24bit) */
1002 gpio_set_drv(&gpio1->f3, i, GPIO_DRV_4X);
1003 gpio_set_rate(&gpio1->f3, i, GPIO_DRV_SLOW);
1006 /* gpio pad configuration for LCD reset. */
1007 gpio_direction_output(&gpio2->y4, 5, 1);
1010 * gpio pad configuration for
1011 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1013 gpio_cfg_pin(&gpio2->y4, 3, GPIO_OUTPUT);
1014 gpio_cfg_pin(&gpio2->y3, 1, GPIO_OUTPUT);
1015 gpio_cfg_pin(&gpio2->y3, 3, GPIO_OUTPUT);
1017 spi_pd.cs_bank = &gpio2->y4;
1019 spi_pd.clk_bank = &gpio2->y3;
1021 spi_pd.si_bank = &gpio2->y3;
1024 spi_pd.mode = SPI_MODE_3;
1026 spi_pd.cs_active = ACTIVE_LOW;
1027 spi_pd.word_len = 8;
1029 ld9040_set_platform_data(&spi_pd);
1034 extern void ld9040_cfg_ldo(void);
1035 extern void ld9040_enable_ldo(unsigned int onoff);
1037 int s5p_no_lcd_support(void)
1042 void init_panel_info(vidinfo_t *vid)
1047 vid->vl_width = 480;
1048 vid->vl_height = 800;
1049 vid->vl_clkp = CONFIG_SYS_HIGH;
1050 vid->vl_hsp = CONFIG_SYS_HIGH;
1051 vid->vl_vsp = CONFIG_SYS_HIGH;
1052 vid->vl_dp = CONFIG_SYS_HIGH;
1055 /* disable dual lcd mode. */
1056 vid->dual_lcd_enabled = 0;
1058 /* LD9040 LCD Panel */
1067 vid->cfg_gpio = lcd_cfg_gpio;
1068 vid->backlight_on = NULL;
1069 vid->lcd_power_on = NULL; /* Don't need the poweron squence */
1070 vid->reset_lcd = NULL; /* Don't need the reset squence */
1072 vid->cfg_ldo = ld9040_cfg_ldo;
1073 vid->enable_ldo = ld9040_enable_ldo;
1075 vid->init_delay = 0;
1076 vid->power_on_delay = 0;
1077 vid->reset_delay = 0;
1078 vid->interface_mode = FIMD_RGB_INTERFACE;
1080 /* board should be detected at here. */
1083 vid->pclk_name = MPLL;
1086 setenv("lcdinfo", "lcd=ld9040");
1090 static unsigned int get_hw_revision(void)
1092 int hwrev, mode0, mode1;
1094 mode0 = get_adc_value(1); /* HWREV_MODE0 */
1095 mode1 = get_adc_value(2); /* HWREV_MODE1 */
1098 * XXX Always set the default hwrev as the latest board
1099 * ADC = (voltage) / 3.3 * 4096
1103 #define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
1104 if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
1105 hwrev = 0x0; /* 0.01V 0.01V */
1106 if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
1107 hwrev = 0x1; /* 610mV 0.01V */
1108 if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
1109 hwrev = 0x2; /* 1.16V 0.01V */
1110 if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
1111 hwrev = 0x3; /* 1.79V 0.01V */
1114 debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);
1119 static const char * const pcb_rev[] = {
1126 static void check_hw_revision(void)
1130 hwrev = get_hw_revision();
1135 static void show_hw_revision(void)
1137 printf("HW Revision:\t0x%x\n", board_rev);
1138 printf("PCB Revision:\t%s\n", pcb_rev[board_rev & 0xf]);
1141 void get_rev_info(char *rev_info)
1143 sprintf(rev_info, "HW Revision: 0x%x (%s)\n",
1144 board_rev, pcb_rev[board_rev & 0xf]);
1147 static void check_reset_status(void)
1149 int status = get_reset_status();
1151 puts("Reset Status: ");
1155 puts("Pin(Ext) Reset\n");
1158 puts("Warm Reset\n");
1161 puts("Watchdog Reset\n");
1164 puts("S/W Reset\n");
1167 printf("Unknown (0x%x)\n", status);
1171 #ifdef CONFIG_CMD_RAMOOPS
1172 static void show_dump_msg(void)
1176 ret = ramoops_init(samsung_get_base_modem());
1179 setenv("bootdelay", "-1");
1183 #ifdef CONFIG_MISC_INIT_R
1184 int misc_init_r(void)
1186 check_reset_status();
1187 #ifdef CONFIG_CMD_RAMOOPS
1196 /* check max17040 */
1202 #ifdef CONFIG_INFO_ACTION
1203 info_action_check();
1206 #ifdef CONFIG_CMD_PMIC
1207 pmic_bus_init(I2C_5);
1208 run_command("pmic ldo 4 off", 0); /* adc off */
1215 #ifdef CONFIG_CMD_USBDOWN
1216 int usb_board_init(void)
1218 /* interrupt clear */
1219 poweron_key_check();
1221 #ifdef CONFIG_CMD_PMIC
1222 run_command("pmic ldo 8 on", 0);
1223 run_command("pmic ldo 3 on", 0);
1224 run_command("pmic safeout 1 on", 0);
1230 #ifdef CONFIG_GENERIC_MMC
1231 int s5p_no_mmc_support(void)
1236 int board_mmc_init(bd_t *bis)
1240 switch (get_hwrev()) {
1243 * Set the low to enable LDO_EN
1244 * But when you use the test board for eMMC booting
1245 * you should set it HIGH since it removes the inverter
1247 /* MASSMEMORY_EN: XMDMDATA_6: GPE3[6] */
1248 gpio_direction_output(&gpio1->e3, 6, 0);
1252 * Default reset state is High and there's no inverter
1253 * But set it as HIGH to ensure
1255 /* MASSMEMORY_EN: XMDMADDR_3: GPE1[3] */
1256 gpio_direction_output(&gpio1->e1, 3, 1);
1260 #ifdef CONFIG_MMC_BOOT_EVT0
1262 * In MMC boot test board don't have inverter
1264 gpio_direction_output(&gpio1->e3, 6, 1);
1269 * SDR 8-bit@48MHz at MMC0
1270 * GPK0[0] SD_0_CLK(2)
1271 * GPK0[1] SD_0_CMD(2)
1272 * GPK0[2] SD_0_CDn -> Not used
1273 * GPK0[3:6] SD_0_DATA[0:3](2)
1274 * GPK1[3:6] SD_0_DATA[0:3](3)
1276 * DDR 4-bit@26MHz at MMC4
1277 * GPK0[0] SD_4_CLK(3)
1278 * GPK0[1] SD_4_CMD(3)
1279 * GPK0[2] SD_4_CDn -> Not used
1280 * GPK0[3:6] SD_4_DATA[0:3](3)
1281 * GPK1[3:6] SD_4_DATA[4:7](4)
1283 for (i = 0; i < 7; i++) {
1286 /* GPK0[0:6] special function 2 */
1287 gpio_cfg_pin(&gpio2->k0, i, 0x2);
1288 /* GPK0[0:6] pull disable */
1289 gpio_set_pull(&gpio2->k0, i, GPIO_PULL_NONE);
1290 /* GPK0[0:6] drv 4x */
1291 gpio_set_drv(&gpio2->k0, i, GPIO_DRV_4X);
1294 for (i = 3; i < 7; i++) {
1295 /* GPK1[3:6] special function 3 */
1296 gpio_cfg_pin(&gpio2->k1, i, 0x3);
1297 /* GPK1[3:6] pull disable */
1298 gpio_set_pull(&gpio2->k1, i, GPIO_PULL_NONE);
1299 /* GPK1[3:6] drv 4x */
1300 gpio_set_drv(&gpio2->k1, i, GPIO_DRV_4X);
1303 /* T-flash detect */
1304 gpio_cfg_pin(&gpio2->x3, 4, 0xf);
1305 gpio_set_pull(&gpio2->x3, 4, GPIO_PULL_UP);
1309 * mmc0 : eMMC (8-bit buswidth)
1310 * mmc2 : SD card (4-bit buswidth)
1312 err = s5p_mmc_init(0, 8);
1315 * Check the T-flash detect pin
1316 * GPX3[4] T-flash detect pin
1318 if (!gpio_get_value(&gpio2->x3, 4)) {
1321 * GPK2[0] SD_2_CLK(2)
1322 * GPK2[1] SD_2_CMD(2)
1323 * GPK2[2] SD_2_CDn -> Not used
1324 * GPK2[3:6] SD_2_DATA[0:3](2)
1326 for (i = 0; i < 7; i++) {
1329 /* GPK2[0:6] special function 2 */
1330 gpio_cfg_pin(&gpio2->k2, i, 0x2);
1331 /* GPK2[0:6] pull disable */
1332 gpio_set_pull(&gpio2->k2, i, GPIO_PULL_NONE);
1333 /* GPK2[0:6] drv 4x */
1334 gpio_set_drv(&gpio2->k2, i, GPIO_DRV_4X);
1336 err = s5p_mmc_init(2, 4);
1344 #ifdef CONFIG_CMD_DEVICE_POWER
1345 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
1349 if (strncmp(argv[1], "cp", 2) == 0) {
1350 micro_usb_switch(1);
1351 run_command("pmic safeout 2 on", 0);
1352 setenv("usb", "cp");
1353 } else if (strncmp(argv[1], "ap", 2) == 0) {
1354 micro_usb_switch(0);
1355 run_command("pmic safeout 2 off", 0);
1356 setenv("usb", "ap");
1366 printf("USB Path is set to %s\n", getenv("usb"));
1372 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
1374 "cp - switch to CP\n"
1375 "microusb ap - switch to AP\n"