2 * Copyright (C) 2009 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Minkyu Kang <mk7.kang@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,
29 #include <asm/arch/clk.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/keypad.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/power.h>
35 #include <asm/arch/mem.h>
36 #include <asm/errno.h>
39 #include <bmp_layout.h>
41 #include "animation_frames.h"
42 #include "gpio_setting.h"
44 DECLARE_GLOBAL_DATA_PTR;
46 #define C100_MACH_START 3000
47 #define C110_MACH_START 3100
49 /* FIXME Neptune workaround */
50 #define USE_NEPTUNE_BOARD
51 #undef USE_NEPTUNE_BOARD
53 static unsigned int board_rev;
54 static unsigned int battery_soc;
55 static struct s5pc110_gpio *s5pc110_gpio;
72 static struct i2c_gpio_bus_data i2c_2 = {
82 static struct i2c_gpio_bus_data i2c_gpio3 = {
92 static struct i2c_gpio_bus_data i2c_pmic = {
102 static struct i2c_gpio_bus_data i2c_gpio5 = {
112 static struct i2c_gpio_bus_data i2c_gpio6 = {
122 static struct i2c_gpio_bus_data i2c_gpio7 = {
128 * i2c gpio7 - cypress
132 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
142 static struct i2c_gpio_bus_data i2c_gpio10 = {
148 static struct i2c_gpio_bus i2c_gpio[] = {
166 u32 get_board_rev(void)
171 static int hwrevision(int rev)
173 return (board_rev & 0xf) == rev;
180 MACH_P1P2, /* Don't remove it */
187 #define SPLIT_SCREEN_FEATURE 0x100
189 /* board is MACH_AQUILA and board is like below. */
190 #define J1_B2_BOARD 0x0200
191 #define LIMO_UNIVERSAL_BOARD 0x0400
192 #define LIMO_REAL_BOARD 0x0800
193 #define MEDIA_BOARD 0x1000
194 #define BAMBOO_BOARD 0x2000
195 #define ARIES_BOARD 0x4000
196 #define NEPTUNE_BOARD 0x8000
198 #define BOARD_MASK 0xFF00
200 static int c110_machine_id(void)
202 return gd->bd->bi_arch_number - C110_MACH_START;
205 static int machine_is_aquila(void)
207 return c110_machine_id() == MACH_AQUILA;
210 static int machine_is_tickertape(void)
212 return c110_machine_id() == MACH_TICKERTAPE;
215 static int machine_is_geminus(void)
217 return c110_machine_id() == MACH_GEMINUS;
220 static int machine_is_cypress(void)
222 return c110_machine_id() == MACH_CYPRESS;
225 static int board_is_limo_universal(void)
227 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
230 static int board_is_limo_real(void)
232 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
235 static int board_is_media(void)
237 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
240 static int board_is_bamboo(void)
242 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
245 static int board_is_j1b2(void)
247 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
250 static int board_is_aries(void)
252 return machine_is_aquila() && (board_rev & ARIES_BOARD);
255 static int board_is_neptune(void)
257 return machine_is_aquila() && (board_rev & NEPTUNE_BOARD);
261 static int machine_is_wmg160(void)
263 return c110_machine_id() == MACH_WMG160;
266 static void enable_battery(void);
268 void i2c_init_board(void)
270 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
273 if (cpu_is_s5pc100())
276 num_bus = ARRAY_SIZE(i2c_gpio);
278 if (machine_is_aquila()) {
279 if (board_is_aries()) {
280 i2c_gpio[I2C_GPIO7].bus->gpio_base =
281 (unsigned int)&gpio->gpio_mp0_5;
283 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
284 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
286 } else if (machine_is_cypress()) {
287 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
288 i2c_gpio[I2C_GPIO7].bus->gpio_base =
289 (unsigned int)&gpio->gpio_mp0_5;
291 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
294 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
295 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
296 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
297 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
298 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
300 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
302 /* Reset on max17040 early */
303 if (battery_soc == 0)
307 #ifdef CONFIG_MISC_INIT_R
308 #define DEV_INFO_LEN 512
309 static char device_info[DEV_INFO_LEN];
310 static int display_info;
312 static void dprintf(const char *fmt, ...)
319 i = vsprintf(buf, fmt, args);
324 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
325 puts("Flushing device info...\n");
329 strcat(device_info, buf);
333 #ifdef CONFIG_S5PC1XXFB
334 static void display_device_info(void)
341 set_font_color(FONT_WHITE);
342 fb_printf(device_info);
345 memset(device_info, 0x0, DEV_INFO_LEN);
347 udelay(5 * 1000 * 1000);
351 static const char *board_name[] = {
355 "P1P2", /* Don't remove it */
368 static char feature_buffer[32];
370 static char *display_features(int board, int board_rev)
373 char *buf = feature_buffer;
376 if (board == MACH_AQUILA) {
377 if (board_rev & SPLIT_SCREEN_FEATURE)
378 name = "SplitScreen";
379 if (board_rev & J1_B2_BOARD)
381 /* Limo Real or Universal */
382 if (board_rev & LIMO_REAL_BOARD)
384 else if (board_rev & LIMO_UNIVERSAL_BOARD)
385 name = "Limo Universal";
386 if (board_rev & MEDIA_BOARD)
388 if (board_rev & BAMBOO_BOARD)
390 if (board_rev & ARIES_BOARD)
392 if (board_rev & NEPTUNE_BOARD)
396 count += sprintf(buf + count, " - %s", name);
402 static char *get_board_name(int board)
404 if (board == MACH_WMG160)
406 return (char *) board_name[board];
409 static void check_board_revision(int board, int rev)
413 /* Limo Real or Universal */
414 if (rev & LIMO_UNIVERSAL_BOARD)
415 board_rev &= ~J1_B2_BOARD;
416 if (rev & LIMO_REAL_BOARD)
417 board_rev &= ~(J1_B2_BOARD |
418 LIMO_UNIVERSAL_BOARD);
419 if (rev & MEDIA_BOARD)
420 board_rev &= ~(J1_B2_BOARD |
421 LIMO_UNIVERSAL_BOARD);
422 if (rev & BAMBOO_BOARD)
423 board_rev &= ~(J1_B2_BOARD |
424 LIMO_UNIVERSAL_BOARD |
427 if (rev & ARIES_BOARD)
428 board_rev &= ~(J1_B2_BOARD |
429 LIMO_UNIVERSAL_BOARD);
430 if (rev & NEPTUNE_BOARD)
431 board_rev &= ~(J1_B2_BOARD |
432 LIMO_UNIVERSAL_BOARD);
435 case MACH_TICKERTAPE:
438 board_rev &= ~BOARD_MASK;
445 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
453 gpio_direction_input(bank, 2);
454 gpio_direction_input(bank, 3);
455 gpio_direction_input(bank, 4);
456 gpio_direction_input(bank, mode3);
458 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
459 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
460 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
461 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
463 rev = gpio_get_value(bank, 2);
464 rev |= (gpio_get_value(bank, 3) << 1);
465 rev |= (gpio_get_value(bank, 4) << 2);
466 rev |= (gpio_get_value(bank, mode3) << 3);
471 static void check_hw_revision(void)
473 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
475 if (cpu_is_s5pc100()) {
476 struct s5pc100_gpio *gpio =
477 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
479 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
481 /* C100 TickerTape */
483 board = MACH_TICKERTAPE;
485 struct s5pc110_gpio *gpio =
486 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
492 * Note Check 'Aquila' board first
496 * LRA: Limo Real Aquila
497 * LUA: Limo Universal Aquila
502 * ADDR = 0xE0200000 + OFF
504 * OFF Universal BB LRA LUA OA TT SS CYP
505 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
506 * J2: 0x0284 0x01 0x10 0x00
507 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
508 * H3: 0x0C64 0x03 0x07 0x0F
509 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
510 * I: 0x0224 0x02 0x00 0x08
511 * MP03: 0x0324 0x9x 0xbx 0x9x
512 * MP05: 0x0364 0x80 0x88
516 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
518 board_rev |= J1_B2_BOARD;
520 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
521 gpio_direction_input(&gpio->gpio_j2, 6);
524 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
525 board_rev |= LIMO_UNIVERSAL_BOARD;
527 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
528 board_rev |= LIMO_REAL_BOARD;
530 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
531 board_rev |= MEDIA_BOARD;
533 /* set gpio to default value. */
534 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
535 gpio_direction_output(&gpio->gpio_j2, 6, 0);
538 /* Workaround: C110 Aquila Rev0.6 */
539 if (board_rev == 6) {
541 board_rev |= LIMO_REAL_BOARD;
544 /* C110 Aquila Bamboo */
545 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
547 board_rev |= BAMBOO_BOARD;
550 /* C110 TickerTape */
551 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
552 gpio_get_value(&gpio->gpio_d1, 1) == 0)
553 board = MACH_TICKERTAPE;
555 /* C110 Geminus for rev0.0 */
556 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
557 gpio_direction_input(&gpio->gpio_j1, 2);
558 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
559 board = MACH_GEMINUS;
560 if ((board_rev & ~BOARD_MASK) == 3)
563 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
564 gpio_direction_output(&gpio->gpio_j1, 2, 0);
566 /* C110 Geminus for rev0.1 ~ */
567 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
568 gpio_direction_input(&gpio->gpio_j0, 6);
569 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
570 board = MACH_GEMINUS;
573 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
575 /* Aquila - Aries MP0_5[6] == 1 */
576 gpio_direction_input(&gpio->gpio_mp0_5, 6);
577 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
578 /* Cypress: Do this for cypress */
579 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
580 gpio_direction_input(&gpio->gpio_j2, 2);
581 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
582 board = MACH_CYPRESS;
583 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
586 board_rev |= ARIES_BOARD;
587 #ifdef USE_NEPTUNE_BOARD
588 board_rev &= ~ARIES_BOARD;
589 board_rev |= NEPTUNE_BOARD;
592 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
595 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
597 /* WMG160 - GPB[0:7] == 0x00000000 */
601 for (i = 0; i < 8; i++) {
602 if (gpio_get_value(&gpio->gpio_b, i) == 0)
612 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
616 if (cpu_is_s5pc110())
617 gd->bd->bi_arch_number = C110_MACH_START + board;
619 gd->bd->bi_arch_number = C100_MACH_START + board;
621 /* Architecture Common settings */
622 if (cpu_is_s5pc110()) {
623 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
625 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
627 setenv("updatek", "onenand erase 0x60000 0x300000; "
628 "onenand write 0x31008000 0x60000 0x300000");
632 static void show_hw_revision(void)
637 * Workaround for Rev 0.3 + CP Ver ES 3.1
640 if (board_is_limo_real()) {
642 /* default is Rev 0.4 */
648 if (cpu_is_s5pc110())
649 board = gd->bd->bi_arch_number - C110_MACH_START;
651 board = gd->bd->bi_arch_number - C100_MACH_START;
653 check_board_revision(board, board_rev);
655 /* Set CPU Revision */
656 if (machine_is_aquila()) {
657 if (board_is_limo_real()) {
658 if ((board_rev & 0xf) < 8)
659 s5pc1xx_set_cpu_rev(0);
661 } else if (machine_is_geminus()) {
662 if ((board_rev & 0xf) < 1)
663 s5pc1xx_set_cpu_rev(0);
665 s5pc1xx_set_cpu_rev(0);
668 dprintf("HW Revision:\t%x (%s%s) %s\n",
669 board_rev, get_board_name(board),
670 display_features(board, board_rev),
671 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
674 static void check_auto_burn(void)
676 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
677 unsigned int count = 0;
680 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
681 printf("Auto burning bootloader\n");
682 count += sprintf(buf + count, "run updateb; ");
684 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
685 printf("Auto burning kernel\n");
686 count += sprintf(buf + count, "run updatek; ");
690 count += sprintf(buf + count, "reset");
691 setenv("bootcmd", buf);
694 /* Clear the magic value */
695 writel(0xa5a55a5a, magic_base);
696 writel(0xa5a55a5a, magic_base + 0x4);
699 static void pmic_pin_init(void)
701 unsigned int reg, value;
703 if (cpu_is_s5pc100())
706 /* AP_PS_HOLD: XEINT_0: GPH0[0]
707 * Note: Don't use GPIO PS_HOLD it doesn't work
709 reg = S5PC110_PS_HOLD_CONTROL;
711 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
712 S5PC110_PS_HOLD_DATA_HIGH |
713 S5PC110_PS_HOLD_OUT_EN;
716 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
717 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
718 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
721 static void enable_ldos(void)
723 if (cpu_is_s5pc100())
726 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
727 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
730 static void enable_t_flash(void)
732 if (!(board_is_limo_universal() || board_is_limo_real()))
735 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
736 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
739 static void setup_limo_real_gpios(void)
741 if (!board_is_limo_real())
745 * Note: Please write GPIO alphabet order
747 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
748 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
751 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
752 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
754 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
755 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
757 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
758 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
759 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
762 static void setup_media_gpios(void)
764 if (!board_is_media())
768 * Note: Please write GPIO alphabet order
770 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
771 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
773 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
774 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
775 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
778 #define KBR3 (1 << 3)
779 #define KBR2 (1 << 2)
780 #define KBR1 (1 << 1)
781 #define KBR0 (1 << 0)
783 static void check_keypad(void)
785 unsigned int reg, value;
786 unsigned int col_mask, row_mask;
787 unsigned int auto_download = 0;
788 unsigned int col_value[4], i;
789 if (cpu_is_s5pc100()) {
790 struct s5pc100_gpio *gpio =
791 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
793 /* Set GPH2[2:0] to KP_COL[2:0] */
794 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
795 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
796 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
798 /* Set GPH3[2:0] to KP_ROW[2:0] */
799 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
800 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
801 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
803 reg = S5PC100_KEYPAD_BASE;
805 if (board_is_limo_real() || board_is_limo_universal()) {
813 for (i = 0; i < 4; i++) {
814 /* Set GPH3[3:0] to KP_ROW[3:0] */
815 if (row_mask & (0xF << (i << 2))) {
816 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
817 gpio_set_pull(&s5pc110_gpio->gpio_h3, i,
821 /* Set GPH2[3:0] to KP_COL[3:0] */
822 if (col_mask & (0xF << (i << 2)))
823 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
826 reg = S5PC110_KEYPAD_BASE;
830 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
831 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
832 /* VOLUMEDOWN and CAM(Half shot) Button */
833 if ((value & KBR1) == 0) {
836 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
839 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
841 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
843 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
845 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
847 if (col_value[1] == 0xd && col_value[2] == 0xe && machine_is_geminus())
850 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
853 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
858 setenv("bootcmd", "usbdown");
861 static void enable_battery(void)
863 unsigned char val[2];
864 unsigned char addr = 0x36; /* max17040 fuel gauge */
866 i2c_set_bus_num(I2C_GPIO3);
868 if (machine_is_aquila()) {
869 if (board_is_aries() || board_is_neptune())
870 i2c_set_bus_num(I2C_GPIO7);
871 else if (board_is_j1b2())
873 } else if (machine_is_tickertape()) {
875 } else if (machine_is_cypress()) {
876 i2c_set_bus_num(I2C_GPIO7);
877 } else if (machine_is_geminus()) {
879 i2c_set_bus_num(I2C_GPIO7);
882 if (i2c_probe(addr)) {
883 printf("Can't found max17040 fuel gauge\n");
889 i2c_write(addr, 0xfe, 1, val, 2);
892 static void check_battery(void)
894 unsigned char val[2];
895 unsigned char addr = 0x36; /* max17040 fuel gauge */
897 i2c_set_bus_num(I2C_GPIO3);
899 if (machine_is_aquila()) {
900 if (board_is_aries() || board_is_neptune())
901 i2c_set_bus_num(I2C_GPIO7);
902 else if (board_is_j1b2())
904 } else if (machine_is_tickertape()) {
906 } else if (machine_is_cypress()) {
907 i2c_set_bus_num(I2C_GPIO7);
908 } else if (machine_is_geminus()) {
910 i2c_set_bus_num(I2C_GPIO7);
913 if (i2c_probe(addr)) {
914 printf("Can't found max17040 fuel gauge\n");
918 i2c_read(addr, 0x04, 1, val, 1);
920 dprintf("battery:\t%d%%\n", val[0]);
922 battery_soc = val[0];
925 static void check_mhl(void)
927 unsigned char val[2];
928 unsigned char addr = 0x39; /* SIL9230 */
930 /* MHL Power enable */
931 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
932 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
934 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
935 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
937 /* 10ms required after reset */
941 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
943 i2c_set_bus_num(I2C_GPIO5);
946 if (i2c_probe(addr)) {
947 printf("Can't found MHL Chip\n");
953 * set to Normal operation
956 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
957 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
962 * 00 = MHL termination ON
963 * 11 = MHL termination OFF
966 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
967 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
970 #define CHARGER_ANIMATION_FRAME 6
971 static int max8998_power_key(void)
973 unsigned char addr, val[2];
974 i2c_set_bus_num(I2C_PMIC);
976 if (i2c_probe(addr)) {
977 printf("Can't found max8998\n");
981 /* Accessing IRQ1 register */
982 i2c_read(addr, 0x00, 1, val, 1);
983 if (val[0] & (1 << 6))
989 extern void lcd_display_clear(void);
990 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
992 static void into_charge_mode(void)
994 unsigned char addr = 0xCC >> 1; /* max8998 */;
995 unsigned char val[2];
1000 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1002 i2c_set_bus_num(I2C_PMIC);
1004 if (i2c_probe(addr)) {
1005 printf("Can't found max8998\n");
1009 printf("Charge Mode\n");
1011 i2c_read(addr, 0x0C, 1, val, 1);
1012 val[0] &= ~(0x7 << 0);
1013 val[0] |= 5; /* 600mA */
1014 i2c_write(addr, 0x0C, 1, val, 1);
1016 #ifdef CONFIG_S5PC1XXFB
1019 /* TODO: write the image-text for the charger */
1021 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1022 if (level >= CHARGER_ANIMATION_FRAME)
1023 level = CHARGER_ANIMATION_FRAME - 1;
1025 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1026 bmp_addr[i] = (ulong)battery_charging_animation[i];
1028 lcd_display_clear();
1029 for (i = 0; i < 3; i++) {
1030 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1033 bmp = gunzip_bmp(bmp_addr[j], &len);
1034 lcd_display_bitmap((ulong) bmp, 140, 202);
1037 for (k = 0; k < 10; k++)
1038 if (max8998_power_key()) {
1039 lcd_display_clear();
1040 /* FIXME don't use static function */
1041 /* draw_samsung_logo(lcd_base); */
1050 /* EVT0: sleep 1, EVT1: sleep */
1051 if (s5pc1xx_get_cpu_rev() == 0) {
1052 run_command("sleep 1", 0);
1056 run_command("sleep", 0);
1059 static void check_micro_usb(int intr)
1062 unsigned char val[2];
1063 static int started_charging_once = 0;
1066 if (cpu_is_s5pc100())
1069 if (board_is_limo_real()) {
1070 if (hwrevision(0) || hwrevision(1))
1074 i2c_set_bus_num(I2C_PMIC);
1076 if (machine_is_aquila()) {
1077 if (board_is_aries() || board_is_neptune())
1078 i2c_set_bus_num(I2C_GPIO6);
1079 } else if (machine_is_cypress()) {
1080 i2c_set_bus_num(I2C_GPIO6);
1081 } else if (machine_is_geminus()) {
1083 i2c_set_bus_num(I2C_GPIO6);
1086 addr = 0x25; /* fsa9480 */
1087 if (i2c_probe(addr)) {
1088 printf("Can't found fsa9480\n");
1092 /* Clear Interrupt */
1094 i2c_read(addr, 0x03, 1, val, 2);
1098 /* Read Device Type 1 */
1099 i2c_read(addr, 0x0a, 1, val, 1);
1101 #define FSA_DEDICATED_CHARGER (1 << 6)
1102 #define FSA_UART (1 << 3)
1103 #define FSA_USB (1 << 2)
1106 * If USB, use default 475mA
1107 * If Charger, use 600mA and go to charge mode
1109 if ((val[0] & FSA_DEDICATED_CHARGER) && !started_charging_once) {
1110 started_charging_once = 1;
1114 /* If Factory Mode is Boot ON-USB, go to download mode */
1115 i2c_read(addr, 0x07, 1, val, 1);
1117 #define FSA_ADC_FAC_USB 0x19
1118 #define FSA_ADC_FAC_UART 0x1d
1120 if (val[0] == FSA_ADC_FAC_USB)
1121 setenv("bootcmd", "usbdown");
1123 path = getenv("usb");
1125 if (!strncmp(path, "cp", 2))
1126 run_command("microusb cp", 0);
1129 static void micro_usb_switch(int path)
1132 unsigned char val[2];
1134 i2c_set_bus_num(I2C_PMIC);
1136 if (machine_is_aquila()) {
1137 if (board_is_aries() || board_is_neptune())
1138 i2c_set_bus_num(I2C_GPIO6);
1139 } else if (machine_is_cypress()) {
1140 i2c_set_bus_num(I2C_GPIO6);
1141 } else if (machine_is_geminus()) {
1143 i2c_set_bus_num(I2C_GPIO6);
1146 addr = 0x25; /* fsa9480 */
1147 if (i2c_probe(addr)) {
1148 printf("Can't found fsa9480\n");
1153 val[0] = 0x90; /* VAUDIO */
1155 val[0] = 0x24; /* DHOST */
1157 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1159 i2c_read(addr, 0x2, 1, val, 1);
1160 val[0] &= ~(1 << 2);
1161 i2c_write(addr, 0x2, 1, val, 1);
1164 #define MAX8998_REG_ONOFF1 0x11
1165 #define MAX8998_REG_ONOFF2 0x12
1166 #define MAX8998_REG_ONOFF3 0x13
1167 #define MAX8998_REG_LDO7 0x21
1168 #define MAX8998_REG_LDO17 0x29
1170 #define MAX8998_LDO3 (1 << 2)
1172 #define MAX8998_LDO6 (1 << 7)
1173 #define MAX8998_LDO7 (1 << 6)
1174 #define MAX8998_LDO8 (1 << 5)
1175 #define MAX8998_LDO9 (1 << 4)
1176 #define MAX8998_LDO10 (1 << 3)
1177 #define MAX8998_LDO11 (1 << 2)
1178 #define MAX8998_LDO12 (1 << 1)
1179 #define MAX8998_LDO13 (1 << 0)
1181 #define MAX8998_LDO14 (1 << 7)
1182 #define MAX8998_LDO15 (1 << 6)
1183 #define MAX8998_LDO16 (1 << 5)
1184 #define MAX8998_LDO17 (1 << 4)
1187 static void init_pmic(void)
1190 unsigned char val[2];
1192 if (cpu_is_s5pc100())
1195 i2c_set_bus_num(I2C_PMIC);
1197 addr = 0xCC >> 1; /* max8998 */
1198 if (i2c_probe(addr)) {
1199 printf("Can't found max8998\n");
1204 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1205 val[0] &= ~MAX8998_LDO3;
1206 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1209 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1211 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1212 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1214 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1215 MAX8998_LDO12 | MAX8998_LDO13);
1217 if (board_is_aries() || board_is_neptune())
1218 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1220 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1221 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1223 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1225 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1226 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1228 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1229 MAX8998_LDO16 | MAX8998_LDO17);
1231 if (board_is_aries() || board_is_neptune())
1232 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1234 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1235 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1238 static void setup_power_down_mode_registers(void)
1240 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1241 struct s5pc1xx_gpio_bank *bank;
1242 struct gpio_powermode *p;
1244 struct gpio_external *ge;
1246 struct s5pc1xx_gpio_item *mr;
1250 if (cpu_is_s5pc100())
1253 /* Only Limo real and aries supports worked for sleep currnet */
1254 if (machine_is_aquila()) {
1255 if (board_is_limo_real())
1257 else if (board_is_aries() || board_is_neptune())
1261 } else if (machine_is_geminus()) {
1266 if (machine_is_aquila()) {
1267 if (board_is_aries() || board_is_neptune()) {
1268 /* Aquila rev 0.9 */
1269 p = aries_powerdown_modes;
1270 ge = aries_external_powerdown_modes;
1271 mr = aries_mirror_powerdown_mode;
1272 n_p = ARRAY_SIZE(aries_powerdown_modes);
1273 n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1274 n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1276 /* Aquila rev 0.8 or lower */
1277 p = aquila_powerdown_modes;
1278 ge = aquila_external_powerdown_modes;
1279 mr = aquila_mirror_powerdown_mode;
1280 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1281 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1282 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1284 } else if (machine_is_geminus()) {
1285 if (hwrevision(1)) {
1286 /* Same as Aquila rev 0.9 */
1288 p = aries_powerdown_modes;
1289 ge = aries_external_powerdown_modes;
1290 mr = aries_mirror_powerdown_mode;
1291 n_p = ARRAY_SIZE(aries_powerdown_modes);
1292 n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1293 n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1295 p = aquila_powerdown_modes;
1296 ge = aquila_external_powerdown_modes;
1297 mr = aquila_mirror_powerdown_mode;
1298 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1299 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1300 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1302 } else if (hwrevision(0)) {
1303 /* Same as Aquila rev 0.8 or lower */
1304 p = aquila_powerdown_modes;
1305 ge = aquila_external_powerdown_modes;
1306 mr = aquila_mirror_powerdown_mode;
1307 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1308 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1309 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1311 return; /* Not supported */
1315 bank = &gpio->gpio_a0;
1317 for (i = 0; i < n_p; i++, p++, bank++) {
1318 writel(p->conpdn, &bank->pdn_con);
1319 writel(p->pudpdn, &bank->pdn_pull);
1322 writel(0xff0022b0, (unsigned int *)0xF0000000);
1323 writel(0xff0022b0, (unsigned int *)0xF1400000);
1325 bank = &gpio->gpio_h0;
1327 for (i = 0; i < n_ge; i++) {
1328 writel(ge->con, &bank->con);
1329 writel(ge->dat, &bank->dat);
1330 writel(ge->pud, &bank->pull);
1336 for (i = 0; i < n_mr; i++) {
1337 unsigned int reg = readl(&mr->bank->pdn_con);
1338 reg &= ~(1 << mr->number);
1339 if (readl(&mr->bank->dat) & (1 << mr->number))
1340 reg |= 1 << mr->number;
1341 writel(reg, &mr->bank->pdn_con);
1343 printf("[%8.8X] = %8.8X\n", (unsigned int) (&mr->bank->pdn_con), reg);
1350 struct spi_platform_data {
1351 struct s5pc1xx_gpio_bank *cs_bank;
1352 struct s5pc1xx_gpio_bank *clk_bank;
1353 struct s5pc1xx_gpio_bank *si_bank;
1354 struct s5pc1xx_gpio_bank *so_bank;
1356 unsigned int cs_num;
1357 unsigned int clk_num;
1358 unsigned int si_num;
1359 unsigned int so_num;
1361 unsigned int board_is_media;
1364 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1365 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1367 struct spi_platform_data spi_pd;
1369 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1371 void lcd_cfg_gpio(void)
1373 unsigned int i, f3_end = 4;
1375 for (i = 0; i < 8; i++) {
1376 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1377 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1378 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1379 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1380 /* pull-up/down disable */
1381 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1382 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1383 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1385 /* drive strength to max (24bit) */
1386 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1387 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1388 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1389 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1390 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1391 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1394 /* set DISPLAY_DE_B pin for dual rgb mode. */
1395 if (board_is_media())
1398 for (i = 0; i < f3_end; i++) {
1399 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1400 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1401 /* pull-up/down disable */
1402 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1403 /* drive strength to max (24bit) */
1404 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1405 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1407 /* display output path selection (only [1:0] valid) */
1408 writel(0x2, 0xE0107008);
1410 /* gpio pad configuration for LCD reset. */
1411 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1413 /* gpio pad configuration for LCD ON. */
1414 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1416 /* LCD_BACKLIGHT_EN */
1417 if (machine_is_geminus())
1418 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1421 * gpio pad configuration for
1422 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1424 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1425 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1426 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1427 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1429 if (machine_is_aquila()) {
1430 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1432 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1434 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1436 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1439 if (board_is_neptune())
1440 s6d16a0x_set_platform_data(&spi_pd);
1442 s6e63m0_set_platform_data(&spi_pd);
1443 if (board_is_media())
1444 spi_pd.board_is_media = 1;
1448 if (machine_is_cypress()) {
1449 #if 0 /* universal cypress */
1451 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1454 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1456 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1458 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1460 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1462 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1463 #if 0 /* universal cypress */
1464 pd_cs.bank = &gpio_base->gpio_mp0_1;
1467 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1469 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1471 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1474 /* these data would be sent to s6e63m0 lcd panel driver. */
1475 s6e63m0_set_platform_data(&spi_pd);
1481 void backlight_on(unsigned int onoff)
1483 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1486 if (machine_is_geminus())
1487 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1489 if (machine_is_geminus())
1490 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1494 void reset_lcd(void)
1496 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1498 if (machine_is_aquila() || machine_is_geminus())
1499 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1500 if (machine_is_cypress())
1501 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1504 void lcd_power_on(unsigned int onoff)
1506 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1509 if (machine_is_aquila() || machine_is_geminus())
1510 gpio_set_value(&gpio->gpio_j1, 3, 1);
1512 if (machine_is_cypress())
1513 gpio_set_value(&gpio->gpio_g2, 2, 1);
1515 if (board_is_aries() || board_is_neptune()) {
1517 unsigned char val[2];
1518 unsigned char val2[2];
1520 i2c_set_bus_num(I2C_PMIC);
1521 addr = 0xCC >> 1; /* max8998 */
1522 if (i2c_probe(addr)) {
1523 printf("Can't found max8998\n");
1526 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1527 val[0] &= ~(MAX8998_LDO17);
1528 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1529 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1531 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1532 val[0] |= MAX8998_LDO17;
1534 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1535 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1537 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1538 val[0] |= MAX8998_LDO7;
1540 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1541 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1544 if (machine_is_aquila() || machine_is_geminus())
1545 gpio_set_value(&gpio->gpio_j1, 3, 0);
1547 if (machine_is_cypress())
1548 gpio_set_value(&gpio->gpio_g2, 2, 0);
1550 if (board_is_aries() || board_is_neptune()) {
1552 unsigned char val[2];
1554 i2c_set_bus_num(I2C_PMIC);
1555 addr = 0xCC >> 1; /* max8998 */
1556 if (i2c_probe(addr)) {
1557 printf("Can't found max8998\n");
1561 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1562 val[0] &= ~(1 << 7);
1563 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1564 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1566 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1567 val[0] &= ~MAX8998_LDO17;
1568 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1569 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1574 extern void s6e63m0_cfg_ldo(void);
1575 extern void s6e63m0_enable_ldo(unsigned int onoff);
1576 extern void s6d16a0x_cfg_ldo(void);
1577 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1579 void init_panel_info(vidinfo_t *vid)
1581 vid->cfg_gpio = NULL;
1582 vid->reset_lcd = NULL;
1583 vid->backlight_on = NULL;
1584 vid->lcd_power_on = NULL;
1586 vid->cfg_ldo = NULL;
1587 vid->enable_ldo = NULL;
1589 vid->init_delay = 0;
1590 vid->reset_delay = 0;
1591 vid->power_on_delay = 0;
1596 vid->vl_width = 480;
1597 vid->vl_height = 800;
1599 vid->dual_lcd_enabled = 0;
1601 if (board_is_media()) {
1604 vid->vl_width = 960;
1605 vid->vl_height = 800;
1607 /* enable dual lcd mode. */
1608 vid->dual_lcd_enabled = 1;
1611 vid->vl_clkp = CONFIG_SYS_HIGH;
1612 vid->vl_hsp = CONFIG_SYS_LOW;
1613 vid->vl_vsp = CONFIG_SYS_LOW;
1614 vid->vl_dp = CONFIG_SYS_HIGH;
1617 /* S6E63M0 LCD Panel */
1626 if (machine_is_aquila() || machine_is_cypress()) {
1627 vid->cfg_gpio = lcd_cfg_gpio;
1628 vid->reset_lcd = reset_lcd;
1629 vid->backlight_on = backlight_on;
1630 vid->lcd_power_on = lcd_power_on;
1631 vid->cfg_ldo = s6e63m0_cfg_ldo;
1632 vid->enable_ldo = s6e63m0_enable_ldo;
1634 vid->init_delay = 25000;
1635 vid->reset_delay = 120000;
1638 if (board_is_neptune()) {
1642 vid->vl_width = 320;
1643 vid->vl_height = 480;
1645 vid->vl_clkp = CONFIG_SYS_HIGH;
1646 vid->vl_hsp = CONFIG_SYS_HIGH;
1647 vid->vl_vsp = CONFIG_SYS_HIGH;
1648 vid->vl_dp = CONFIG_SYS_LOW;
1651 /* disable dual lcd mode. */
1652 vid->dual_lcd_enabled = 0;
1654 /* S6D16A0X LCD Panel */
1663 vid->cfg_gpio = lcd_cfg_gpio;
1664 vid->backlight_on = NULL;
1665 vid->lcd_power_on = lcd_power_on;
1666 vid->reset_lcd = reset_lcd;
1667 vid->cfg_ldo = s6d16a0x_cfg_ldo;
1668 vid->enable_ldo = s6d16a0x_enable_ldo;
1670 vid->init_delay = 10000;
1671 vid->power_on_delay = 10000;
1672 vid->reset_delay = 1000;
1676 if (machine_is_geminus()) {
1680 vid->vl_width = 1024,
1681 vid->vl_height = 600,
1682 vid->vl_clkp = CONFIG_SYS_LOW,
1683 vid->vl_hsp = CONFIG_SYS_HIGH,
1684 vid->vl_vsp = CONFIG_SYS_HIGH,
1685 vid->vl_dp = CONFIG_SYS_LOW,
1696 vid->cfg_gpio = lcd_cfg_gpio;
1697 vid->reset_lcd = reset_lcd;
1698 vid->backlight_on = backlight_on;
1699 vid->lcd_power_on = lcd_power_on;
1705 vid->vl_width = 480,
1706 vid->vl_height = 800,
1707 vid->vl_clkp = CONFIG_SYS_HIGH,
1708 vid->vl_hsp = CONFIG_SYS_LOW,
1709 vid->vl_vsp = CONFIG_SYS_LOW,
1710 vid->vl_dp = CONFIG_SYS_HIGH,
1726 vid->vl_width = 1024,
1727 vid->vl_height = 600,
1728 vid->vl_clkp = CONFIG_SYS_HIGH,
1729 vid->vl_hsp = CONFIG_SYS_HIGH,
1730 vid->vl_vsp = CONFIG_SYS_HIGH,
1731 vid->vl_dp = CONFIG_SYS_LOW,
1734 /* AMS701KA AMOLED Panel. */
1746 static void setup_meminfo(void)
1748 char meminfo[64] = {0, };
1749 int count = 0, size, real;
1751 size = gd->bd->bi_dram[0].size >> 20;
1752 count += sprintf(meminfo + count, "mem=%dM", size);
1754 /* Each Chip Select can't exceed the 256MiB */
1755 size = gd->bd->bi_dram[1].size >> 20;
1756 real = min(size, 256);
1757 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1758 real, (unsigned int)gd->bd->bi_dram[1].start);
1762 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1763 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1766 setenv("meminfo", meminfo);
1770 * CSA partition Migration
1771 * It will be deleted
1773 static void csa_migration(void)
1775 unsigned int *ubi_id;
1778 run_command("onenand read 0x40000000 0x400000 0x400000", 0);
1780 for (i = 0; i < 10; i++) {
1781 ubi_id = (void *) (0x40000000 + 0x40000 * i);
1782 if (*ubi_id == 0x23494255) /* 0x23494255 = UBI */ {
1783 printf("CSA Migration is already done....\n");
1787 run_command("onenand erase 0x400000 0x800000", 0);
1790 int misc_init_r(void)
1793 /* It should be located at first */
1796 if (board_is_neptune())
1797 setenv("lcdinfo", "lcd=s6d16a0x");
1798 else if ((board_is_limo_real() ||
1799 board_is_limo_universal() ||
1801 setenv("lcdinfo", "lcd=s6e63m0");
1802 /* it can't classify tl2796 with single-lcd and dual-lcd.
1804 setenv("lcdinfo", "lcd=tl2796-dual");
1808 * env values below should be added in case that lcd panel of geminus.
1809 * setenv means that lcd panel has been turned on at u-boot.
1811 if (machine_is_geminus())
1812 setenv("lcdinfo", "lcd=lms480jc01");
1813 if (board_is_media())
1814 setenv("lcdinfo", "lcd=media");
1820 /* Set proper PMIC pins */
1823 /* Check auto burning */
1826 /* To power up I2C2 */
1829 /* Enable T-Flash at Limo Real or Limo Universal */
1832 /* Setup Limo Real board GPIOs */
1833 setup_limo_real_gpios();
1835 /* Setup Media board GPIOs */
1836 setup_media_gpios();
1838 /* To usbdown automatically */
1844 #ifdef CONFIG_S5PC1XXFB
1845 display_device_info();
1848 setup_power_down_mode_registers();
1850 /* check max17040 */
1856 /* csa migration (temporary) */
1863 int board_init(void)
1865 /* Set Initial global variables */
1866 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1868 gd->bd->bi_arch_number = MACH_TYPE;
1869 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1871 /* Check H/W Revision */
1872 check_hw_revision();
1879 unsigned int base, memconfig0, size;
1880 unsigned int memconfig1, sz = 0;
1882 if (cpu_is_s5pc100()) {
1883 /* In mem setup, we swap the bank. So below size is correct */
1884 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1885 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1886 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1889 /* In S5PC110, we can't swap the DMC0/1 */
1890 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1891 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1893 base = S5PC110_DMC1_BASE;
1894 /* DMC configuration */
1895 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1896 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1898 size = (memconfig0 >> 16) & 0xFF;
1899 size = ((unsigned char) ~size) + 1;
1902 * (0x07 + 1) * 16 = 128 MiB
1903 * (0x0f + 1) * 16 = 256 MiB
1908 * Aquila Rev0.5 4G3G1G
1909 * Aquila Rev0.8 4G3G1G
1910 * Aquila Rev0.9 4G3G1G
1912 if (machine_is_aquila() &&
1913 (hwrevision(5) || hwrevision(8) || hwrevision(9))) {
1914 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
1916 sz = (memconfig1 >> 16) & 0xFF;
1917 sz = ((unsigned char) ~sz) + 1;
1923 * bi_dram[1].size contains all DMC1 memory size
1925 gd->bd->bi_dram[1].size = (size + sz) << 20;
1930 /* Used for sleep test */
1931 static unsigned char saved_val[4][2];
1932 void board_sleep_init_late(void)
1934 /* CODEC_LDO_EN: GPF3[4] */
1935 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
1936 /* CODEC_XTAL_EN: GPH3[2] */
1937 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
1939 /* MMC T_FLASH off */
1940 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
1942 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
1943 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
1944 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
1948 void board_sleep_init(void)
1951 unsigned char val[2];
1953 i2c_set_bus_num(I2C_PMIC);
1955 if (i2c_probe(addr)) {
1956 printf("Can't find max8998\n");
1961 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1962 saved_val[0][0] = val[0];
1963 saved_val[0][1] = val[1];
1964 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
1965 (1 << 1) | (1 << 0));
1966 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1967 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1969 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1970 saved_val[1][0] = val[0];
1971 saved_val[1][1] = val[1];
1972 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
1973 (1 << 2) | (1 << 1) | (1 << 0));
1975 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1976 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1978 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1979 saved_val[2][0] = val[0];
1980 saved_val[2][1] = val[1];
1981 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
1982 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1983 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1985 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1986 saved_val[3][0] = val[0];
1987 saved_val[3][1] = val[1];
1988 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
1989 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1990 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1991 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
1992 __FILE__, __LINE__);
1995 void board_sleep_resume(void)
1998 unsigned char val[2];
2002 i2c_set_bus_num(I2C_PMIC);
2004 if (i2c_probe(addr)) {
2005 printf("Can't find max8998\n");
2010 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2011 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2013 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2014 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2016 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2017 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2019 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2020 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2021 printf("Waked up.\n");
2023 /* check max17040 */
2030 #ifdef CONFIG_CMD_USBDOWN
2031 int usb_board_init(void)
2033 #ifdef CONFIG_CMD_PMIC
2034 run_command("pmic ldo 3 on", 0);
2037 if (cpu_is_s5pc100()) {
2038 #ifdef CONFIG_HARD_I2C
2039 uchar val[2] = {0,};
2042 if (i2c_read(0x66, 0, 1, val, 2)) {
2043 printf("i2c_read error\n");
2050 if (i2c_write(0x66, 0, 1, val, 2)) {
2051 printf("i2c_write error\n");
2054 i2c_read(0x66, 0, 1, val, 2);
2060 if (board_is_limo_universal() ||
2061 board_is_limo_real() ||
2063 /* check usb path */
2064 if (board_is_limo_real() && !hwrevision(6))
2068 if (machine_is_tickertape())
2069 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2070 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2072 /* USB Path to AP */
2073 micro_usb_switch(0);
2079 #ifdef CONFIG_GENERIC_MMC
2080 int board_mmc_init(bd_t *bis)
2084 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2087 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2088 if (machine_is_aquila() && (board_is_aries() || board_is_neptune()))
2089 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2091 /* MMC0 Clock source = SCLKMPLL */
2092 reg = readl(&clk->src4);
2095 writel(reg, &clk->src4);
2097 reg = readl(&clk->div4);
2100 /* set div value near 50MHz */
2101 clock = get_pll_clk(MPLL) / 1000000;
2102 for (i = 0; i < 0xf; i++) {
2103 if ((clock / (i + 1)) <= 50) {
2109 writel(reg, &clk->div4);
2115 * GPG0[2] SD_0_CDn -> Not used
2116 * GPG0[3:6] SD_0_DATA[0:3]
2118 for (i = 0; i < 7; i++) {
2121 /* GPG0[0:6] special function 2 */
2122 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2123 /* GPG0[0:6] pull disable */
2124 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2125 /* GPG0[0:6] drv 4x */
2126 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2129 return s5pc1xx_mmc_init(0);
2133 #ifdef CONFIG_CMD_PMIC
2134 static int pmic_status(void)
2136 unsigned char addr, val[2];
2139 i2c_set_bus_num(I2C_PMIC);
2141 if (i2c_probe(addr)) {
2142 printf("Can't found max8998\n");
2147 i2c_read(addr, reg, 1, val, 1);
2148 for (i = 7; i >= 4; i--)
2149 printf("BUCK%d %s\n", 7 - i + 1,
2150 val[0] & (1 << i) ? "on" : "off");
2152 printf("LDO%d %s\n", 5 - i,
2153 val[0] & (1 << i) ? "on" : "off");
2155 i2c_read(addr, reg, 1, val, 1);
2156 for (i = 7; i >= 0; i--)
2157 printf("LDO%d %s\n", 7 - i + 6,
2158 val[0] & (1 << i) ? "on" : "off");
2160 i2c_read(addr, reg, 1, val, 1);
2161 for (i = 7; i >= 4; i--)
2162 printf("LDO%d %s\n", 7 - i + 14,
2163 val[0] & (1 << i) ? "on" : "off");
2166 i2c_read(addr, reg, 1, val, 1);
2167 for (i = 7; i >= 6; i--)
2168 printf("SAFEOUT%d %s\n", 7 - i + 1,
2169 val[0] & (1 << i) ? "on" : "off");
2173 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2175 unsigned char addr, val[2];
2176 unsigned int reg, shift;
2184 } else if (ldo <= 13) {
2187 } else if (ldo <= 17) {
2189 shift = 17 - ldo + 4;
2196 shift = 4 - buck + 4;
2197 } else if (safeout) {
2201 shift = 8 - safeout;
2205 i2c_set_bus_num(I2C_PMIC);
2207 if (i2c_probe(addr)) {
2208 printf("Can't found max8998\n");
2212 i2c_read(addr, reg, 1, val, 1);
2214 val[0] |= (1 << shift);
2216 val[0] &= ~(1 << shift);
2217 i2c_write(addr, reg, 1, val, 1);
2218 i2c_read(addr, reg, 1, val, 1);
2221 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2222 val[0] & (1 << shift) ? "on" : "off");
2224 printf("buck %d value 0x%x, %s\n", buck, val[0],
2225 val[0] & (1 << shift) ? "on" : "off");
2227 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2228 val[0] & (1 << shift) ? "on" : "off");
2233 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2235 int buck = 0, ldo = 0, safeout = 0, on = -1;
2239 if (strncmp(argv[1], "status", 6) == 0)
2240 return pmic_status();
2243 if (strncmp(argv[1], "ldo", 3) == 0)
2244 ldo = simple_strtoul(argv[2], NULL, 10);
2245 else if (strncmp(argv[1], "buck", 4) == 0)
2246 buck = simple_strtoul(argv[2], NULL, 10);
2247 else if (strncmp(argv[1], "safeout", 7) == 0)
2248 safeout = simple_strtoul(argv[2], NULL, 10);
2252 if (strncmp(argv[3], "on", 2) == 0)
2254 else if (strncmp(argv[3], "off", 3) == 0)
2259 return pmic_ldo_control(buck, ldo, safeout, on);
2270 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2271 "PMIC LDO & BUCK control",
2272 "status - Display PMIC LDO & BUCK status\n"
2273 "pmic ldo num on/off - Turn on/off the LDO\n"
2274 "pmic buck num on/off - Turn on/off the BUCK\n"
2275 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2279 #ifdef CONFIG_CMD_DEVICE_POWER
2293 static void power_display_devices(void)
2295 printf("devices:\n");
2296 printf("\t%d - touch\n", POWER_TOUCH);
2297 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2298 printf("\t%d - LCD\n", POWER_LCD);
2299 printf("\t%d - Haptic\n", POWER_HAPTIC);
2300 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2301 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2302 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2303 printf("\t%d - HDMI\n", POWER_HDMI);
2306 static int power_hdmi(int on)
2308 /* HDMI_EN1: GPJ2[2] */
2309 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2310 /* MHL_ON: GPJ2[3] */
2311 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2315 static int power_bt_wifi(int on)
2317 /* WLAN_BT_EN: GPB[5] */
2318 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2322 static int power_fm_radio(int on)
2324 /* FM_BUS_nRST: GPJ2[5] */
2325 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2329 static int power_audio_codec(int on)
2331 /* CODEC_LDO_EN: GPF3[4] */
2332 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2333 /* CODEC_XTAL_EN: GPH3[2] */
2334 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2338 static int power_haptic(int on)
2340 /* HAPTIC_ON: GPJ1[1] */
2341 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2345 static int power_lcd(int on)
2347 /* MLCD_ON: GPJ1[3] */
2348 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2352 static int power_touch(int on)
2354 /* TOUCH_EN: GPG3[6] */
2355 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2359 static int power_3_touchkey(int on)
2362 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2363 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2364 if (board_rev & J1_B2_BOARD)
2365 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2367 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2369 /* 3_TOUCH_CE - GPJ2[6] */
2370 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2372 /* 3_TOUCH_CE - GPJ2[6] */
2373 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2378 unsigned char val[2];
2379 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2385 i2c_set_bus_num(I2C_GPIO10);
2387 /* Workaround to probe */
2388 if (i2c_probe(addr)) {
2389 if (i2c_probe(addr)) {
2390 printf("Can't found 3 touchkey\n");
2395 #define MCS5000_TK_HW_VERSION 0x06
2396 #define MCS5000_TK_FW_VERSION 0x0A
2397 #define MCS5000_TK_MI_VERSION 0x0B
2399 reg = MCS5000_TK_MI_VERSION;
2400 i2c_read(addr, reg, 1, val, 1);
2401 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2402 reg = MCS5000_TK_HW_VERSION;
2403 i2c_read(addr, reg, 1, val, 1);
2404 printf("H/W 0x%x, ", val[0]);
2405 reg = MCS5000_TK_FW_VERSION;
2406 i2c_read(addr, reg, 1, val, 1);
2407 printf("F/W 0x%x\n", val[0]);
2412 static int power_control(int device, int on)
2416 return power_touch(on);
2417 case POWER_3_TOUCHKEY:
2418 return power_3_touchkey(on);
2420 return power_lcd(on);
2422 return power_haptic(on);
2423 case POWER_AUDIO_CODEC:
2424 return power_audio_codec(on);
2425 case POWER_FM_RADIO:
2426 return power_fm_radio(on);
2428 return power_bt_wifi(on);
2430 return power_hdmi(on);
2432 printf("I don't know device %d\n", device);
2438 static int power_on(int on)
2441 power_3_touchkey(on);
2444 power_audio_codec(on);
2452 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2456 if (!machine_is_aquila())
2461 if (strncmp(argv[1], "on", 2) == 0)
2463 if (strncmp(argv[1], "off", 3) == 0)
2467 device = simple_strtoul(argv[1], NULL, 10);
2471 if (strncmp(argv[2], "on", 2) == 0)
2473 else if (strncmp(argv[2], "off", 3) == 0)
2477 return power_control(device, on);
2483 power_display_devices();
2488 power, CONFIG_SYS_MAXARGS, 1, do_power,
2489 "Device Power Management control",
2490 "device on/off - Turn on/off the device\n"
2493 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2497 if (strncmp(argv[1], "cp", 2) == 0) {
2498 micro_usb_switch(1);
2499 pmic_ldo_control(0, 0, 2, 1);
2500 setenv("usb", "cp");
2501 } else if (strncmp(argv[1], "ap", 2) == 0) {
2502 micro_usb_switch(0);
2503 pmic_ldo_control(0, 0, 2, 0);
2504 setenv("usb", "ap");
2514 printf("USB Path is set to %s\n", getenv("usb"));
2520 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2522 "cp - switch to CP\n"
2523 "microusb ap - switch to AP\n"