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 */
185 #define SPLIT_SCREEN_FEATURE 0x100
187 /* board is MACH_AQUILA and board is like below. */
188 #define J1_B2_BOARD 0x200
189 #define LIMO_UNIVERSAL_BOARD 0x400
190 #define LIMO_REAL_BOARD 0x800
191 #define MEDIA_BOARD 0x1000
192 #define BAMBOO_BOARD 0x2000
193 #define ARIES_BOARD 0x4000
194 #define NEPTUNE_BOARD 0x8000
196 #define BOARD_MASK 0xF00
198 static int c110_machine_id(void)
200 return gd->bd->bi_arch_number - C110_MACH_START;
203 static int machine_is_aquila(void)
205 return c110_machine_id() == MACH_AQUILA;
208 static int machine_is_tickertape(void)
210 return c110_machine_id() == MACH_TICKERTAPE;
213 static int machine_is_geminus(void)
215 return c110_machine_id() == MACH_GEMINUS;
218 static int machine_is_cypress(void)
220 return c110_machine_id() == MACH_CYPRESS;
223 static int board_is_limo_universal(void)
225 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
228 static int board_is_limo_real(void)
230 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
233 static int board_is_media(void)
235 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
238 static int board_is_bamboo(void)
240 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
243 static int board_is_j1b2(void)
245 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
248 static int board_is_aries(void)
250 return machine_is_aquila() && (board_rev & ARIES_BOARD);
253 static int board_is_neptune(void)
255 return machine_is_aquila() && (board_rev & NEPTUNE_BOARD);
258 static void enable_battery(void);
260 void i2c_init_board(void)
262 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
265 if (cpu_is_s5pc100())
268 num_bus = ARRAY_SIZE(i2c_gpio);
270 if (machine_is_aquila()) {
271 if (board_is_aries()) {
272 i2c_gpio[I2C_GPIO7].bus->gpio_base =
273 (unsigned int)&gpio->gpio_mp0_5;
275 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
276 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
278 } else if (machine_is_cypress()) {
279 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
280 i2c_gpio[I2C_GPIO7].bus->gpio_base =
281 (unsigned int)&gpio->gpio_mp0_5;
283 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
286 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
287 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
288 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
289 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
290 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
292 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
294 /* Reset on max17040 early */
295 if (battery_soc == 0)
299 #ifdef CONFIG_MISC_INIT_R
300 #define DEV_INFO_LEN 512
301 static char device_info[DEV_INFO_LEN];
302 static int display_info;
304 static void dprintf(const char *fmt, ...)
311 i = vsprintf(buf, fmt, args);
316 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
317 puts("Flushing device info...\n");
321 strcat(device_info, buf);
325 #ifdef CONFIG_S5PC1XXFB
326 static void display_device_info(void)
333 set_font_color(FONT_WHITE);
334 fb_printf(device_info);
337 memset(device_info, 0x0, DEV_INFO_LEN);
339 udelay(5 * 1000 * 1000);
343 static const char *board_name[] = {
347 "P1P2", /* Don't remove it */
360 static char feature_buffer[32];
362 static char *display_features(int board, int board_rev)
365 char *buf = feature_buffer;
368 if (board == MACH_AQUILA) {
369 if (board_rev & SPLIT_SCREEN_FEATURE)
370 name = "SplitScreen";
371 if (board_rev & J1_B2_BOARD)
373 /* Limo Real or Universal */
374 if (board_rev & LIMO_REAL_BOARD)
376 else if (board_rev & LIMO_UNIVERSAL_BOARD)
377 name = "Limo Universal";
378 if (board_rev & MEDIA_BOARD)
380 if (board_rev & BAMBOO_BOARD)
382 if (board_rev & ARIES_BOARD)
384 if (board_rev & NEPTUNE_BOARD)
388 count += sprintf(buf + count, " - %s", name);
394 static void check_board_revision(int board, int rev)
398 /* Limo Real or Universal */
399 if (rev & LIMO_UNIVERSAL_BOARD)
400 board_rev &= ~J1_B2_BOARD;
401 if (rev & LIMO_REAL_BOARD)
402 board_rev &= ~(J1_B2_BOARD |
403 LIMO_UNIVERSAL_BOARD);
404 if (rev & MEDIA_BOARD)
405 board_rev &= ~(J1_B2_BOARD |
406 LIMO_UNIVERSAL_BOARD);
407 if (rev & BAMBOO_BOARD)
408 board_rev &= ~(J1_B2_BOARD |
409 LIMO_UNIVERSAL_BOARD |
412 if (rev & ARIES_BOARD)
413 board_rev &= ~(J1_B2_BOARD |
414 LIMO_UNIVERSAL_BOARD);
415 if (rev & NEPTUNE_BOARD)
416 board_rev &= ~(J1_B2_BOARD |
417 LIMO_UNIVERSAL_BOARD);
420 case MACH_TICKERTAPE:
422 board_rev &= ~BOARD_MASK;
429 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
437 gpio_direction_input(bank, 2);
438 gpio_direction_input(bank, 3);
439 gpio_direction_input(bank, 4);
440 gpio_direction_input(bank, mode3);
442 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
443 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
444 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
445 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
447 rev = gpio_get_value(bank, 2);
448 rev |= (gpio_get_value(bank, 3) << 1);
449 rev |= (gpio_get_value(bank, 4) << 2);
450 rev |= (gpio_get_value(bank, mode3) << 3);
455 static void check_hw_revision(void)
457 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
459 if (cpu_is_s5pc100()) {
460 struct s5pc100_gpio *gpio =
461 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
463 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
465 /* C100 TickerTape */
467 board = MACH_TICKERTAPE;
469 struct s5pc110_gpio *gpio =
470 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
476 * Note Check 'Aquila' board first
480 * LRA: Limo Real Aquila
481 * LUA: Limo Universal Aquila
486 * ADDR = 0xE0200000 + OFF
488 * OFF Universal BB LRA LUA OA TT SS CYP
489 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
490 * J2: 0x0284 0x01 0x10 0x00
491 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
492 * H3: 0x0C64 0x03 0x07 0x0F
493 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
494 * I: 0x0224 0x02 0x00 0x08
495 * MP03: 0x0324 0x9x 0xbx 0x9x
496 * MP05: 0x0364 0x80 0x88
500 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
502 board_rev |= J1_B2_BOARD;
504 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
505 gpio_direction_input(&gpio->gpio_j2, 6);
508 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
509 board_rev |= LIMO_UNIVERSAL_BOARD;
511 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
512 board_rev |= LIMO_REAL_BOARD;
514 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
515 board_rev |= MEDIA_BOARD;
517 /* set gpio to default value. */
518 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
519 gpio_direction_output(&gpio->gpio_j2, 6, 0);
522 /* Workaround: C110 Aquila Rev0.6 */
523 if (board_rev == 6) {
525 board_rev |= LIMO_REAL_BOARD;
528 /* C110 Aquila Bamboo */
529 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
531 board_rev |= BAMBOO_BOARD;
534 /* C110 TickerTape */
535 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
536 gpio_get_value(&gpio->gpio_d1, 1) == 0)
537 board = MACH_TICKERTAPE;
539 /* C110 Geminus for rev0.0 */
540 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
541 gpio_direction_input(&gpio->gpio_j1, 2);
542 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
543 board = MACH_GEMINUS;
544 if ((board_rev & ~BOARD_MASK) == 3)
547 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
548 gpio_direction_output(&gpio->gpio_j1, 2, 0);
550 /* C110 Geminus for rev0.1 ~ */
551 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
552 gpio_direction_input(&gpio->gpio_j0, 6);
553 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
554 board = MACH_GEMINUS;
557 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
559 /* Aquila - Aries MP0_5[6] == 1 */
560 gpio_direction_input(&gpio->gpio_mp0_5, 6);
561 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
562 /* Cypress: Do this for cypress */
563 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
564 gpio_direction_input(&gpio->gpio_j2, 2);
565 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
566 board = MACH_CYPRESS;
567 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
570 board_rev |= ARIES_BOARD;
571 #ifdef USE_NEPTUNE_BOARD
572 board_rev &= ~ARIES_BOARD;
573 board_rev |= NEPTUNE_BOARD;
576 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
579 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
581 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
585 if (cpu_is_s5pc110())
586 gd->bd->bi_arch_number = C110_MACH_START + board;
588 gd->bd->bi_arch_number = C100_MACH_START + board;
590 /* Architecture Common settings */
591 if (cpu_is_s5pc110()) {
592 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
594 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
596 setenv("updatek", "onenand erase 0x60000 0x300000; "
597 "onenand write 0x31008000 0x60000 0x300000");
601 static void show_hw_revision(void)
606 * Workaround for Rev 0.3 + CP Ver ES 3.1
609 if (board_is_limo_real()) {
611 /* default is Rev 0.4 */
617 if (cpu_is_s5pc110())
618 board = gd->bd->bi_arch_number - C110_MACH_START;
620 board = gd->bd->bi_arch_number - C100_MACH_START;
622 check_board_revision(board, board_rev);
624 /* Set CPU Revision */
625 if (machine_is_aquila()) {
626 if (board_is_limo_real()) {
627 if ((board_rev & 0xf) < 8)
628 s5pc1xx_set_cpu_rev(0);
630 } else if (machine_is_geminus()) {
631 if ((board_rev & 0xf) < 1)
632 s5pc1xx_set_cpu_rev(0);
634 s5pc1xx_set_cpu_rev(0);
637 dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
638 display_features(board, board_rev));
641 static void check_auto_burn(void)
643 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
644 unsigned int count = 0;
647 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
648 printf("Auto burning bootloader\n");
649 count += sprintf(buf + count, "run updateb; ");
651 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
652 printf("Auto burning kernel\n");
653 count += sprintf(buf + count, "run updatek; ");
657 count += sprintf(buf + count, "reset");
658 setenv("bootcmd", buf);
661 /* Clear the magic value */
662 writel(0xa5a55a5a, magic_base);
663 writel(0xa5a55a5a, magic_base + 0x4);
666 static void pmic_pin_init(void)
668 unsigned int reg, value;
670 if (cpu_is_s5pc100())
673 /* AP_PS_HOLD: XEINT_0: GPH0[0]
674 * Note: Don't use GPIO PS_HOLD it doesn't work
676 reg = S5PC110_PS_HOLD_CONTROL;
678 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
679 S5PC110_PS_HOLD_DATA_HIGH |
680 S5PC110_PS_HOLD_OUT_EN;
683 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
684 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
685 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
688 static void enable_ldos(void)
690 if (cpu_is_s5pc100())
693 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
694 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
697 static void enable_t_flash(void)
699 if (!(board_is_limo_universal() || board_is_limo_real()))
702 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
703 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
706 static void setup_limo_real_gpios(void)
708 if (!board_is_limo_real())
712 * Note: Please write GPIO alphabet order
714 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
715 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
718 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
719 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
721 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
722 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
724 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
725 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
726 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
729 static void setup_media_gpios(void)
731 if (!board_is_media())
735 * Note: Please write GPIO alphabet order
737 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
738 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
740 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
741 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
742 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
745 #define KBR3 (1 << 3)
746 #define KBR2 (1 << 2)
747 #define KBR1 (1 << 1)
748 #define KBR0 (1 << 0)
750 static void check_keypad(void)
752 unsigned int reg, value;
753 unsigned int col_mask, row_mask;
754 unsigned int auto_download = 0;
755 unsigned int col_value[4], i;
756 if (cpu_is_s5pc100()) {
757 struct s5pc100_gpio *gpio =
758 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
760 /* Set GPH2[2:0] to KP_COL[2:0] */
761 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
762 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
763 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
765 /* Set GPH3[2:0] to KP_ROW[2:0] */
766 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
767 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
768 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
770 reg = S5PC100_KEYPAD_BASE;
772 if (board_is_limo_real() || board_is_limo_universal()) {
780 for (i = 0; i < 4; i++) {
781 /* Set GPH3[3:0] to KP_ROW[3:0] */
782 if (row_mask & (0xF << (i << 2))) {
783 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
784 gpio_set_pull(&s5pc110_gpio->gpio_h3, i,
788 /* Set GPH2[3:0] to KP_COL[3:0] */
789 if (col_mask & (0xF << (i << 2)))
790 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
793 reg = S5PC110_KEYPAD_BASE;
797 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
798 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
799 /* VOLUMEDOWN and CAM(Half shot) Button */
800 if ((value & KBR1) == 0) {
803 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
806 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
808 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
810 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
812 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
814 if (col_value[1] == 0xd && col_value[2] == 0xe && machine_is_geminus())
817 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
820 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
825 setenv("bootcmd", "usbdown");
828 static void enable_battery(void)
830 unsigned char val[2];
831 unsigned char addr = 0x36; /* max17040 fuel gauge */
833 i2c_set_bus_num(I2C_GPIO3);
835 if (machine_is_aquila()) {
836 if (board_is_aries() || board_is_neptune())
837 i2c_set_bus_num(I2C_GPIO7);
838 else if (board_is_j1b2())
840 } else if (machine_is_tickertape()) {
842 } else if (machine_is_cypress()) {
843 i2c_set_bus_num(I2C_GPIO7);
844 } else if (machine_is_geminus()) {
846 i2c_set_bus_num(I2C_GPIO7);
849 if (i2c_probe(addr)) {
850 printf("Can't found max17040 fuel gauge\n");
856 i2c_write(addr, 0xfe, 1, val, 2);
859 static void check_battery(void)
861 unsigned char val[2];
862 unsigned char addr = 0x36; /* max17040 fuel gauge */
864 i2c_set_bus_num(I2C_GPIO3);
866 if (machine_is_aquila()) {
867 if (board_is_aries() || board_is_neptune())
868 i2c_set_bus_num(I2C_GPIO7);
869 else if (board_is_j1b2())
871 } else if (machine_is_tickertape()) {
873 } else if (machine_is_cypress()) {
874 i2c_set_bus_num(I2C_GPIO7);
875 } else if (machine_is_geminus()) {
877 i2c_set_bus_num(I2C_GPIO7);
880 if (i2c_probe(addr)) {
881 printf("Can't found max17040 fuel gauge\n");
885 i2c_read(addr, 0x04, 1, val, 1);
887 dprintf("battery:\t%d%%\n", val[0]);
889 battery_soc = val[0];
892 static void check_mhl(void)
894 unsigned char val[2];
895 unsigned char addr = 0x39; /* SIL9230 */
897 /* MHL Power enable */
898 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
899 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
901 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
902 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
904 /* 10ms required after reset */
908 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
910 i2c_set_bus_num(I2C_GPIO5);
913 if (i2c_probe(addr)) {
914 printf("Can't found MHL Chip\n");
920 * set to Normal operation
923 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
924 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
929 * 00 = MHL termination ON
930 * 11 = MHL termination OFF
933 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
934 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
937 #define CHARGER_ANIMATION_FRAME 6
938 static int max8998_power_key(void)
940 unsigned char addr, val[2];
941 i2c_set_bus_num(I2C_PMIC);
943 if (i2c_probe(addr)) {
944 printf("Can't found max8998\n");
948 /* Accessing IRQ1 register */
949 i2c_read(addr, 0x00, 1, val, 1);
950 if (val[0] & (1 << 6))
956 extern void lcd_display_clear(void);
957 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
959 static void into_charge_mode(void)
961 unsigned char addr = 0xCC >> 1; /* max8998 */;
962 unsigned char val[2];
967 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
969 i2c_set_bus_num(I2C_PMIC);
971 if (i2c_probe(addr)) {
972 printf("Can't found max8998\n");
976 printf("Charge Mode\n");
978 i2c_read(addr, 0x0C, 1, val, 1);
979 val[0] &= ~(0x7 << 0);
980 val[0] |= 5; /* 600mA */
981 i2c_write(addr, 0x0C, 1, val, 1);
983 #ifdef CONFIG_S5PC1XXFB
986 /* TODO: write the image-text for the charger */
988 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
989 if (level >= CHARGER_ANIMATION_FRAME)
990 level = CHARGER_ANIMATION_FRAME - 1;
992 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
993 bmp_addr[i] = (ulong)battery_charging_animation[i];
996 for (i = 0; i < 3; i++) {
997 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1000 bmp = gunzip_bmp(bmp_addr[j], &len);
1001 lcd_display_bitmap((ulong) bmp, 140, 202);
1004 for (k = 0; k < 10; k++)
1005 if (max8998_power_key()) {
1006 lcd_display_clear();
1007 /* FIXME don't use static function */
1008 /* draw_samsung_logo(lcd_base); */
1017 /* EVT0: sleep 1, EVT1: sleep */
1018 if (s5pc1xx_get_cpu_rev() == 0) {
1019 run_command("sleep 1", 0);
1023 run_command("sleep", 0);
1026 static void check_micro_usb(int intr)
1029 unsigned char val[2];
1030 static int started_charging_once = 0;
1033 if (cpu_is_s5pc100())
1036 if (board_is_limo_real()) {
1037 if (hwrevision(0) || hwrevision(1))
1041 i2c_set_bus_num(I2C_PMIC);
1043 if (machine_is_aquila()) {
1044 if (board_is_aries() || board_is_neptune())
1045 i2c_set_bus_num(I2C_GPIO6);
1046 } else if (machine_is_cypress()) {
1047 i2c_set_bus_num(I2C_GPIO6);
1048 } else if (machine_is_geminus()) {
1050 i2c_set_bus_num(I2C_GPIO6);
1053 addr = 0x25; /* fsa9480 */
1054 if (i2c_probe(addr)) {
1055 printf("Can't found fsa9480\n");
1059 /* Clear Interrupt */
1061 i2c_read(addr, 0x03, 1, val, 2);
1065 /* Read Device Type 1 */
1066 i2c_read(addr, 0x0a, 1, val, 1);
1068 #define FSA_DEDICATED_CHARGER (1 << 6)
1069 #define FSA_UART (1 << 3)
1070 #define FSA_USB (1 << 2)
1073 * If USB, use default 475mA
1074 * If Charger, use 600mA and go to charge mode
1076 if ((val[0] & FSA_DEDICATED_CHARGER) && !started_charging_once) {
1077 started_charging_once = 1;
1081 /* If Factory Mode is Boot ON-USB, go to download mode */
1082 i2c_read(addr, 0x07, 1, val, 1);
1084 #define FSA_ADC_FAC_USB 0x19
1085 #define FSA_ADC_FAC_UART 0x1d
1087 if (val[0] == FSA_ADC_FAC_USB)
1088 setenv("bootcmd", "usbdown");
1090 path = getenv("usb");
1092 if (!strncmp(path, "cp", 2))
1093 run_command("microusb cp", 0);
1096 static void micro_usb_switch(int path)
1099 unsigned char val[2];
1101 i2c_set_bus_num(I2C_PMIC);
1103 if (machine_is_aquila()) {
1104 if (board_is_aries() || board_is_neptune())
1105 i2c_set_bus_num(I2C_GPIO6);
1106 } else if (machine_is_cypress()) {
1107 i2c_set_bus_num(I2C_GPIO6);
1108 } else if (machine_is_geminus()) {
1110 i2c_set_bus_num(I2C_GPIO6);
1113 addr = 0x25; /* fsa9480 */
1114 if (i2c_probe(addr)) {
1115 printf("Can't found fsa9480\n");
1120 val[0] = 0x90; /* VAUDIO */
1122 val[0] = 0x24; /* DHOST */
1124 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1126 i2c_read(addr, 0x2, 1, val, 1);
1127 val[0] &= ~(1 << 2);
1128 i2c_write(addr, 0x2, 1, val, 1);
1131 #define MAX8998_REG_ONOFF1 0x11
1132 #define MAX8998_REG_ONOFF2 0x12
1133 #define MAX8998_REG_ONOFF3 0x13
1134 #define MAX8998_REG_LDO7 0x21
1135 #define MAX8998_REG_LDO17 0x29
1137 #define MAX8998_LDO3 (1 << 2)
1139 #define MAX8998_LDO6 (1 << 7)
1140 #define MAX8998_LDO7 (1 << 6)
1141 #define MAX8998_LDO8 (1 << 5)
1142 #define MAX8998_LDO9 (1 << 4)
1143 #define MAX8998_LDO10 (1 << 3)
1144 #define MAX8998_LDO11 (1 << 2)
1145 #define MAX8998_LDO12 (1 << 1)
1146 #define MAX8998_LDO13 (1 << 0)
1148 #define MAX8998_LDO14 (1 << 7)
1149 #define MAX8998_LDO15 (1 << 6)
1150 #define MAX8998_LDO16 (1 << 5)
1151 #define MAX8998_LDO17 (1 << 4)
1154 static void init_pmic(void)
1157 unsigned char val[2];
1159 if (cpu_is_s5pc100())
1162 i2c_set_bus_num(I2C_PMIC);
1164 addr = 0xCC >> 1; /* max8998 */
1165 if (i2c_probe(addr)) {
1166 printf("Can't found max8998\n");
1171 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1172 val[0] &= ~MAX8998_LDO3;
1173 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1176 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1178 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1179 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1181 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1182 MAX8998_LDO12 | MAX8998_LDO13);
1184 if (board_is_aries() || board_is_neptune())
1185 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1187 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1188 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1190 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1192 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1193 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1195 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1196 MAX8998_LDO16 | MAX8998_LDO17);
1198 if (board_is_aries() || board_is_neptune())
1199 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1201 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1202 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1205 static void setup_power_down_mode_registers(void)
1207 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1208 struct s5pc1xx_gpio_bank *bank;
1209 struct gpio_powermode *p;
1211 struct gpio_external *ge;
1213 struct s5pc1xx_gpio_item *mr;
1217 if (cpu_is_s5pc100())
1220 /* Only Limo real and aries supports worked for sleep currnet */
1221 if (machine_is_aquila()) {
1222 if (board_is_limo_real())
1224 else if (board_is_aries() || board_is_neptune())
1228 } else if (machine_is_geminus()) {
1233 if (machine_is_aquila()) {
1234 if (board_is_aries() || board_is_neptune()) {
1235 /* Aquila rev 0.9 */
1236 p = aries_powerdown_modes;
1237 ge = aries_external_powerdown_modes;
1238 mr = aries_mirror_powerdown_mode;
1239 n_p = ARRAY_SIZE(aries_powerdown_modes);
1240 n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1241 n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1243 /* Aquila rev 0.8 or lower */
1244 p = aquila_powerdown_modes;
1245 ge = aquila_external_powerdown_modes;
1246 mr = aquila_mirror_powerdown_mode;
1247 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1248 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1249 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1251 } else if (machine_is_geminus()) {
1252 if (hwrevision(1)) {
1253 /* Same as Aquila rev 0.9 */
1255 p = aries_powerdown_modes;
1256 ge = aries_external_powerdown_modes;
1257 mr = aries_mirror_powerdown_mode;
1258 n_p = ARRAY_SIZE(aries_powerdown_modes);
1259 n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1260 n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1262 p = aquila_powerdown_modes;
1263 ge = aquila_external_powerdown_modes;
1264 mr = aquila_mirror_powerdown_mode;
1265 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1266 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1267 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1269 } else if (hwrevision(0)) {
1270 /* Same as Aquila rev 0.8 or lower */
1271 p = aquila_powerdown_modes;
1272 ge = aquila_external_powerdown_modes;
1273 mr = aquila_mirror_powerdown_mode;
1274 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1275 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1276 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1278 return; /* Not supported */
1282 bank = &gpio->gpio_a0;
1284 for (i = 0; i < n_p; i++, p++, bank++) {
1285 writel(p->conpdn, &bank->pdn_con);
1286 writel(p->pudpdn, &bank->pdn_pull);
1289 writel(0xff0022b0, (unsigned int *)0xF0000000);
1290 writel(0xff0022b0, (unsigned int *)0xF1400000);
1292 bank = &gpio->gpio_h0;
1294 for (i = 0; i < n_ge; i++) {
1295 writel(ge->con, &bank->con);
1296 writel(ge->dat, &bank->dat);
1297 writel(ge->pud, &bank->pull);
1303 for (i = 0; i < n_mr; i++) {
1304 unsigned int reg = readl(&mr->bank->pdn_con);
1305 reg &= ~(1 << mr->number);
1306 if (readl(&mr->bank->dat) & (1 << mr->number))
1307 reg |= 1 << mr->number;
1308 writel(reg, &mr->bank->pdn_con);
1310 printf("[%8.8X] = %8.8X\n", (unsigned int) (&mr->bank->pdn_con), reg);
1317 struct spi_platform_data {
1318 struct s5pc1xx_gpio_bank *cs_bank;
1319 struct s5pc1xx_gpio_bank *clk_bank;
1320 struct s5pc1xx_gpio_bank *si_bank;
1321 struct s5pc1xx_gpio_bank *so_bank;
1323 unsigned int cs_num;
1324 unsigned int clk_num;
1325 unsigned int si_num;
1326 unsigned int so_num;
1328 unsigned int board_is_media;
1331 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1332 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1334 struct spi_platform_data spi_pd;
1336 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1338 void lcd_cfg_gpio(void)
1340 unsigned int i, f3_end = 4;
1342 for (i = 0; i < 8; i++) {
1343 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1344 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1345 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1346 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1347 /* pull-up/down disable */
1348 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1349 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1350 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1352 /* drive strength to max (24bit) */
1353 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1354 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1355 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1356 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1357 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1358 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1361 /* set DISPLAY_DE_B pin for dual rgb mode. */
1362 if (board_is_media())
1365 for (i = 0; i < f3_end; i++) {
1366 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1367 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1368 /* pull-up/down disable */
1369 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1370 /* drive strength to max (24bit) */
1371 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1372 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1374 /* display output path selection (only [1:0] valid) */
1375 writel(0x2, 0xE0107008);
1377 /* gpio pad configuration for LCD reset. */
1378 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1380 /* gpio pad configuration for LCD ON. */
1381 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1383 /* LCD_BACKLIGHT_EN */
1384 if (machine_is_geminus())
1385 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1388 * gpio pad configuration for
1389 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1391 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1392 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1393 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1394 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1396 if (machine_is_aquila()) {
1397 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1399 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1401 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1403 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1406 if (board_is_neptune())
1407 s6d16a0x_set_platform_data(&spi_pd);
1409 s6e63m0_set_platform_data(&spi_pd);
1410 if (board_is_media())
1411 spi_pd.board_is_media = 1;
1415 if (machine_is_cypress()) {
1416 #if 0 /* universal cypress */
1418 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1421 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1423 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1425 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1427 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1429 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1430 #if 0 /* universal cypress */
1431 pd_cs.bank = &gpio_base->gpio_mp0_1;
1434 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1436 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1438 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1441 /* these data would be sent to s6e63m0 lcd panel driver. */
1442 s6e63m0_set_platform_data(&spi_pd);
1448 void backlight_on(unsigned int onoff)
1450 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1453 if (machine_is_geminus())
1454 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1456 if (machine_is_geminus())
1457 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1461 void reset_lcd(void)
1463 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1465 if (machine_is_aquila() || machine_is_geminus())
1466 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1467 if (machine_is_cypress())
1468 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1471 void lcd_power_on(unsigned int onoff)
1473 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1476 if (machine_is_aquila() || machine_is_geminus())
1477 gpio_set_value(&gpio->gpio_j1, 3, 1);
1479 if (machine_is_cypress())
1480 gpio_set_value(&gpio->gpio_g2, 2, 1);
1482 if (board_is_aries() || board_is_neptune()) {
1484 unsigned char val[2];
1485 unsigned char val2[2];
1487 i2c_set_bus_num(I2C_PMIC);
1488 addr = 0xCC >> 1; /* max8998 */
1489 if (i2c_probe(addr)) {
1490 printf("Can't found max8998\n");
1493 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1494 val[0] &= ~(MAX8998_LDO17);
1495 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1496 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1498 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1499 val[0] |= MAX8998_LDO17;
1501 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1502 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1504 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1505 val[0] |= MAX8998_LDO7;
1507 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1508 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1511 if (machine_is_aquila() || machine_is_geminus())
1512 gpio_set_value(&gpio->gpio_j1, 3, 0);
1514 if (machine_is_cypress())
1515 gpio_set_value(&gpio->gpio_g2, 2, 0);
1517 if (board_is_aries() || board_is_neptune()) {
1519 unsigned char val[2];
1521 i2c_set_bus_num(I2C_PMIC);
1522 addr = 0xCC >> 1; /* max8998 */
1523 if (i2c_probe(addr)) {
1524 printf("Can't found max8998\n");
1528 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1529 val[0] &= ~(1 << 7);
1530 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1531 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1533 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1534 val[0] &= ~MAX8998_LDO17;
1535 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1536 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1541 extern void s6e63m0_cfg_ldo(void);
1542 extern void s6e63m0_enable_ldo(unsigned int onoff);
1543 extern void s6d16a0x_cfg_ldo(void);
1544 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1546 void init_panel_info(vidinfo_t *vid)
1548 vid->cfg_gpio = NULL;
1549 vid->reset_lcd = NULL;
1550 vid->backlight_on = NULL;
1551 vid->lcd_power_on = NULL;
1553 vid->cfg_ldo = NULL;
1554 vid->enable_ldo = NULL;
1556 vid->init_delay = 0;
1557 vid->reset_delay = 0;
1558 vid->power_on_delay = 0;
1563 vid->vl_width = 480;
1564 vid->vl_height = 800;
1566 vid->dual_lcd_enabled = 0;
1568 if (board_is_media()) {
1571 vid->vl_width = 960;
1572 vid->vl_height = 800;
1574 /* enable dual lcd mode. */
1575 vid->dual_lcd_enabled = 1;
1578 vid->vl_clkp = CONFIG_SYS_HIGH;
1579 vid->vl_hsp = CONFIG_SYS_LOW;
1580 vid->vl_vsp = CONFIG_SYS_LOW;
1581 vid->vl_dp = CONFIG_SYS_HIGH;
1584 /* S6E63M0 LCD Panel */
1593 if (machine_is_aquila() || machine_is_cypress()) {
1594 vid->cfg_gpio = lcd_cfg_gpio;
1595 vid->reset_lcd = reset_lcd;
1596 vid->backlight_on = backlight_on;
1597 vid->lcd_power_on = lcd_power_on;
1598 vid->cfg_ldo = s6e63m0_cfg_ldo;
1599 vid->enable_ldo = s6e63m0_enable_ldo;
1601 vid->init_delay = 25000;
1602 vid->reset_delay = 120000;
1605 if (board_is_neptune()) {
1609 vid->vl_width = 320;
1610 vid->vl_height = 480;
1612 vid->vl_clkp = CONFIG_SYS_HIGH;
1613 vid->vl_hsp = CONFIG_SYS_HIGH;
1614 vid->vl_vsp = CONFIG_SYS_HIGH;
1615 vid->vl_dp = CONFIG_SYS_LOW;
1618 /* disable dual lcd mode. */
1619 vid->dual_lcd_enabled = 0;
1621 /* S6D16A0X LCD Panel */
1630 vid->cfg_gpio = lcd_cfg_gpio;
1631 vid->backlight_on = NULL;
1632 vid->lcd_power_on = lcd_power_on;
1633 vid->reset_lcd = reset_lcd;
1634 vid->cfg_ldo = s6d16a0x_cfg_ldo;
1635 vid->enable_ldo = s6d16a0x_enable_ldo;
1637 vid->init_delay = 10000;
1638 vid->power_on_delay = 10000;
1639 vid->reset_delay = 1000;
1643 if (machine_is_geminus()) {
1647 vid->vl_width = 1024,
1648 vid->vl_height = 600,
1649 vid->vl_clkp = CONFIG_SYS_LOW,
1650 vid->vl_hsp = CONFIG_SYS_HIGH,
1651 vid->vl_vsp = CONFIG_SYS_HIGH,
1652 vid->vl_dp = CONFIG_SYS_LOW,
1663 vid->cfg_gpio = lcd_cfg_gpio;
1664 vid->reset_lcd = reset_lcd;
1665 vid->backlight_on = backlight_on;
1666 vid->lcd_power_on = lcd_power_on;
1672 vid->vl_width = 480,
1673 vid->vl_height = 800,
1674 vid->vl_clkp = CONFIG_SYS_HIGH,
1675 vid->vl_hsp = CONFIG_SYS_LOW,
1676 vid->vl_vsp = CONFIG_SYS_LOW,
1677 vid->vl_dp = CONFIG_SYS_HIGH,
1693 vid->vl_width = 1024,
1694 vid->vl_height = 600,
1695 vid->vl_clkp = CONFIG_SYS_HIGH,
1696 vid->vl_hsp = CONFIG_SYS_HIGH,
1697 vid->vl_vsp = CONFIG_SYS_HIGH,
1698 vid->vl_dp = CONFIG_SYS_LOW,
1701 /* AMS701KA AMOLED Panel. */
1713 static void setup_meminfo(void)
1715 char meminfo[64] = {0, };
1716 int count = 0, size, real;
1718 size = gd->bd->bi_dram[0].size >> 20;
1719 count += sprintf(meminfo + count, "mem=%dM", size);
1721 /* Each Chip Select can't exceed the 256MiB */
1722 size = gd->bd->bi_dram[1].size >> 20;
1723 real = min(size, 256);
1724 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1725 real, (unsigned int)gd->bd->bi_dram[1].start);
1729 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1730 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1733 setenv("meminfo", meminfo);
1737 * CSA partition Migration
1738 * It will be deleted
1740 static void csa_migration(void)
1742 unsigned int *ubi_id;
1745 run_command("onenand read 0x40000000 0x400000 0x400000", 0);
1747 for (i = 0; i < 10; i++) {
1748 ubi_id = (void *) (0x40000000 + 0x40000 * i);
1749 if (*ubi_id == 0x23494255) /* 0x23494255 = UBI */ {
1750 printf("CSA Migration is already done....\n");
1754 run_command("onenand erase 0x400000 0x800000", 0);
1757 int misc_init_r(void)
1760 /* It should be located at first */
1763 if (board_is_neptune())
1764 setenv("lcdinfo", "lcd=s6d16a0x");
1765 else if ((board_is_limo_real() ||
1766 board_is_limo_universal() ||
1768 setenv("lcdinfo", "lcd=s6e63m0");
1769 /* it can't classify tl2796 with single-lcd and dual-lcd.
1771 setenv("lcdinfo", "lcd=tl2796-dual");
1775 * env values below should be added in case that lcd panel of geminus.
1776 * setenv means that lcd panel has been turned on at u-boot.
1778 if (machine_is_geminus())
1779 setenv("lcdinfo", "lcd=lms480jc01");
1780 if (board_is_media())
1781 setenv("lcdinfo", "lcd=media");
1787 /* Set proper PMIC pins */
1790 /* Check auto burning */
1793 /* To power up I2C2 */
1796 /* Enable T-Flash at Limo Real or Limo Universal */
1799 /* Setup Limo Real board GPIOs */
1800 setup_limo_real_gpios();
1802 /* Setup Media board GPIOs */
1803 setup_media_gpios();
1805 /* To usbdown automatically */
1811 #ifdef CONFIG_S5PC1XXFB
1812 display_device_info();
1815 setup_power_down_mode_registers();
1817 /* check max17040 */
1823 /* csa migration (temporary) */
1830 int board_init(void)
1832 /* Set Initial global variables */
1833 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1835 gd->bd->bi_arch_number = MACH_TYPE;
1836 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1838 /* Check H/W Revision */
1839 check_hw_revision();
1846 unsigned int base, memconfig0, size;
1847 unsigned int memconfig1, sz = 0;
1849 if (cpu_is_s5pc100()) {
1850 /* In mem setup, we swap the bank. So below size is correct */
1851 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1852 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1853 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1856 /* In S5PC110, we can't swap the DMC0/1 */
1857 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1858 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1860 base = S5PC110_DMC1_BASE;
1861 /* DMC configuration */
1862 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1863 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1865 size = (memconfig0 >> 16) & 0xFF;
1866 size = ((unsigned char) ~size) + 1;
1869 * (0x07 + 1) * 16 = 128 MiB
1870 * (0x0f + 1) * 16 = 256 MiB
1875 * Aquila Rev0.5 4G3G1G
1876 * Aquila Rev0.8 4G3G1G
1877 * Aquila Rev0.9 4G3G1G
1879 if (machine_is_aquila() &&
1880 (hwrevision(5) || hwrevision(8) || hwrevision(9))) {
1881 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
1883 sz = (memconfig1 >> 16) & 0xFF;
1884 sz = ((unsigned char) ~sz) + 1;
1890 * bi_dram[1].size contains all DMC1 memory size
1892 gd->bd->bi_dram[1].size = (size + sz) << 20;
1897 /* Used for sleep test */
1898 static unsigned char saved_val[4][2];
1899 void board_sleep_init_late(void)
1901 /* CODEC_LDO_EN: GPF3[4] */
1902 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
1903 /* CODEC_XTAL_EN: GPH3[2] */
1904 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
1906 /* MMC T_FLASH off */
1907 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
1909 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
1910 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
1911 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
1915 void board_sleep_init(void)
1918 unsigned char val[2];
1920 i2c_set_bus_num(I2C_PMIC);
1922 if (i2c_probe(addr)) {
1923 printf("Can't find max8998\n");
1928 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1929 saved_val[0][0] = val[0];
1930 saved_val[0][1] = val[1];
1931 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
1932 (1 << 1) | (1 << 0));
1933 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1934 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1936 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1937 saved_val[1][0] = val[0];
1938 saved_val[1][1] = val[1];
1939 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
1940 (1 << 2) | (1 << 1) | (1 << 0));
1942 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1943 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1945 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1946 saved_val[2][0] = val[0];
1947 saved_val[2][1] = val[1];
1948 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
1949 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1950 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1952 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1953 saved_val[3][0] = val[0];
1954 saved_val[3][1] = val[1];
1955 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
1956 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1957 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1958 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
1959 __FILE__, __LINE__);
1962 void board_sleep_resume(void)
1965 unsigned char val[2];
1969 i2c_set_bus_num(I2C_PMIC);
1971 if (i2c_probe(addr)) {
1972 printf("Can't find max8998\n");
1977 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
1978 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1980 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
1981 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1983 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
1984 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1986 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
1987 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1988 printf("Waked up.\n");
1990 /* check max17040 */
1997 #ifdef CONFIG_CMD_USBDOWN
1998 int usb_board_init(void)
2000 #ifdef CONFIG_CMD_PMIC
2001 run_command("pmic ldo 3 on", 0);
2004 if (cpu_is_s5pc100()) {
2005 #ifdef CONFIG_HARD_I2C
2006 uchar val[2] = {0,};
2009 if (i2c_read(0x66, 0, 1, val, 2)) {
2010 printf("i2c_read error\n");
2017 if (i2c_write(0x66, 0, 1, val, 2)) {
2018 printf("i2c_write error\n");
2021 i2c_read(0x66, 0, 1, val, 2);
2027 if (board_is_limo_universal() ||
2028 board_is_limo_real() ||
2030 /* check usb path */
2031 if (board_is_limo_real() && !hwrevision(6))
2035 if (machine_is_tickertape())
2036 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2037 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2039 /* USB Path to AP */
2040 micro_usb_switch(0);
2046 #ifdef CONFIG_GENERIC_MMC
2047 int board_mmc_init(bd_t *bis)
2051 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2054 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2055 if (machine_is_aquila() && (board_is_aries() || board_is_neptune()))
2056 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2058 /* MMC0 Clock source = SCLKMPLL */
2059 reg = readl(&clk->src4);
2062 writel(reg, &clk->src4);
2064 reg = readl(&clk->div4);
2067 /* set div value near 50MHz */
2068 clock = get_pll_clk(MPLL) / 1000000;
2069 for (i = 0; i < 0xf; i++) {
2070 if ((clock / (i + 1)) <= 50) {
2076 writel(reg, &clk->div4);
2082 * GPG0[2] SD_0_CDn -> Not used
2083 * GPG0[3:6] SD_0_DATA[0:3]
2085 for (i = 0; i < 7; i++) {
2088 /* GPG0[0:6] special function 2 */
2089 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2090 /* GPG0[0:6] pull disable */
2091 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2092 /* GPG0[0:6] drv 4x */
2093 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2096 return s5pc1xx_mmc_init(0);
2100 #ifdef CONFIG_CMD_PMIC
2101 static int pmic_status(void)
2103 unsigned char addr, val[2];
2106 i2c_set_bus_num(I2C_PMIC);
2108 if (i2c_probe(addr)) {
2109 printf("Can't found max8998\n");
2114 i2c_read(addr, reg, 1, val, 1);
2115 for (i = 7; i >= 4; i--)
2116 printf("BUCK%d %s\n", 7 - i + 1,
2117 val[0] & (1 << i) ? "on" : "off");
2119 printf("LDO%d %s\n", 5 - i,
2120 val[0] & (1 << i) ? "on" : "off");
2122 i2c_read(addr, reg, 1, val, 1);
2123 for (i = 7; i >= 0; i--)
2124 printf("LDO%d %s\n", 7 - i + 6,
2125 val[0] & (1 << i) ? "on" : "off");
2127 i2c_read(addr, reg, 1, val, 1);
2128 for (i = 7; i >= 4; i--)
2129 printf("LDO%d %s\n", 7 - i + 14,
2130 val[0] & (1 << i) ? "on" : "off");
2133 i2c_read(addr, reg, 1, val, 1);
2134 for (i = 7; i >= 6; i--)
2135 printf("SAFEOUT%d %s\n", 7 - i + 1,
2136 val[0] & (1 << i) ? "on" : "off");
2140 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2142 unsigned char addr, val[2];
2143 unsigned int reg, shift;
2151 } else if (ldo <= 13) {
2154 } else if (ldo <= 17) {
2156 shift = 17 - ldo + 4;
2163 shift = 4 - buck + 4;
2164 } else if (safeout) {
2168 shift = 8 - safeout;
2172 i2c_set_bus_num(I2C_PMIC);
2174 if (i2c_probe(addr)) {
2175 printf("Can't found max8998\n");
2179 i2c_read(addr, reg, 1, val, 1);
2181 val[0] |= (1 << shift);
2183 val[0] &= ~(1 << shift);
2184 i2c_write(addr, reg, 1, val, 1);
2185 i2c_read(addr, reg, 1, val, 1);
2188 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2189 val[0] & (1 << shift) ? "on" : "off");
2191 printf("buck %d value 0x%x, %s\n", buck, val[0],
2192 val[0] & (1 << shift) ? "on" : "off");
2194 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2195 val[0] & (1 << shift) ? "on" : "off");
2200 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2202 int buck = 0, ldo = 0, safeout = 0, on = -1;
2206 if (strncmp(argv[1], "status", 6) == 0)
2207 return pmic_status();
2210 if (strncmp(argv[1], "ldo", 3) == 0)
2211 ldo = simple_strtoul(argv[2], NULL, 10);
2212 else if (strncmp(argv[1], "buck", 4) == 0)
2213 buck = simple_strtoul(argv[2], NULL, 10);
2214 else if (strncmp(argv[1], "safeout", 7) == 0)
2215 safeout = simple_strtoul(argv[2], NULL, 10);
2219 if (strncmp(argv[3], "on", 2) == 0)
2221 else if (strncmp(argv[3], "off", 3) == 0)
2226 return pmic_ldo_control(buck, ldo, safeout, on);
2237 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2238 "PMIC LDO & BUCK control",
2239 "status - Display PMIC LDO & BUCK status\n"
2240 "pmic ldo num on/off - Turn on/off the LDO\n"
2241 "pmic buck num on/off - Turn on/off the BUCK\n"
2242 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2246 #ifdef CONFIG_CMD_DEVICE_POWER
2260 static void power_display_devices(void)
2262 printf("devices:\n");
2263 printf("\t%d - touch\n", POWER_TOUCH);
2264 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2265 printf("\t%d - LCD\n", POWER_LCD);
2266 printf("\t%d - Haptic\n", POWER_HAPTIC);
2267 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2268 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2269 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2270 printf("\t%d - HDMI\n", POWER_HDMI);
2273 static int power_hdmi(int on)
2275 /* HDMI_EN1: GPJ2[2] */
2276 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2277 /* MHL_ON: GPJ2[3] */
2278 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2282 static int power_bt_wifi(int on)
2284 /* WLAN_BT_EN: GPB[5] */
2285 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2289 static int power_fm_radio(int on)
2291 /* FM_BUS_nRST: GPJ2[5] */
2292 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2296 static int power_audio_codec(int on)
2298 /* CODEC_LDO_EN: GPF3[4] */
2299 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2300 /* CODEC_XTAL_EN: GPH3[2] */
2301 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2305 static int power_haptic(int on)
2307 /* HAPTIC_ON: GPJ1[1] */
2308 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2312 static int power_lcd(int on)
2314 /* MLCD_ON: GPJ1[3] */
2315 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2319 static int power_touch(int on)
2321 /* TOUCH_EN: GPG3[6] */
2322 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2326 static int power_3_touchkey(int on)
2329 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2330 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2331 if (board_rev & J1_B2_BOARD)
2332 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2334 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2336 /* 3_TOUCH_CE - GPJ2[6] */
2337 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2339 /* 3_TOUCH_CE - GPJ2[6] */
2340 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2345 unsigned char val[2];
2346 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2352 i2c_set_bus_num(I2C_GPIO10);
2354 /* Workaround to probe */
2355 if (i2c_probe(addr)) {
2356 if (i2c_probe(addr)) {
2357 printf("Can't found 3 touchkey\n");
2362 #define MCS5000_TK_HW_VERSION 0x06
2363 #define MCS5000_TK_FW_VERSION 0x0A
2364 #define MCS5000_TK_MI_VERSION 0x0B
2366 reg = MCS5000_TK_MI_VERSION;
2367 i2c_read(addr, reg, 1, val, 1);
2368 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2369 reg = MCS5000_TK_HW_VERSION;
2370 i2c_read(addr, reg, 1, val, 1);
2371 printf("H/W 0x%x, ", val[0]);
2372 reg = MCS5000_TK_FW_VERSION;
2373 i2c_read(addr, reg, 1, val, 1);
2374 printf("F/W 0x%x\n", val[0]);
2379 static int power_control(int device, int on)
2383 return power_touch(on);
2384 case POWER_3_TOUCHKEY:
2385 return power_3_touchkey(on);
2387 return power_lcd(on);
2389 return power_haptic(on);
2390 case POWER_AUDIO_CODEC:
2391 return power_audio_codec(on);
2392 case POWER_FM_RADIO:
2393 return power_fm_radio(on);
2395 return power_bt_wifi(on);
2397 return power_hdmi(on);
2399 printf("I don't know device %d\n", device);
2405 static int power_on(int on)
2408 power_3_touchkey(on);
2411 power_audio_codec(on);
2419 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2423 if (!machine_is_aquila())
2428 if (strncmp(argv[1], "on", 2) == 0)
2430 if (strncmp(argv[1], "off", 3) == 0)
2434 device = simple_strtoul(argv[1], NULL, 10);
2438 if (strncmp(argv[2], "on", 2) == 0)
2440 else if (strncmp(argv[2], "off", 3) == 0)
2444 return power_control(device, on);
2450 power_display_devices();
2455 power, CONFIG_SYS_MAXARGS, 1, do_power,
2456 "Device Power Management control",
2457 "device on/off - Turn on/off the device\n"
2460 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2464 if (strncmp(argv[1], "cp", 2) == 0) {
2465 micro_usb_switch(1);
2466 pmic_ldo_control(0, 0, 2, 1);
2467 setenv("usb", "cp");
2468 } else if (strncmp(argv[1], "ap", 2) == 0) {
2469 micro_usb_switch(0);
2470 pmic_ldo_control(0, 0, 2, 0);
2471 setenv("usb", "ap");
2481 printf("USB Path is set to %s\n", getenv("usb"));
2487 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2489 "cp - switch to CP\n"
2490 "microusb ap - switch to AP\n"