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/arch/hs_otg.h>
37 #include <asm/arch/regs-otg.h>
38 #include <asm/arch/rtc.h>
39 #include <asm/arch/adc.h>
40 #include <asm/errno.h>
43 #include <bmp_layout.h>
45 #include "animation_frames.h"
46 #include "gpio_setting.h"
48 DECLARE_GLOBAL_DATA_PTR;
50 #define C100_MACH_START 3000
51 #define C110_MACH_START 3100
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 = {
118 * i2c gpio7 - kessler
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 */
192 #define SPLIT_SCREEN_FEATURE 0x100
194 /* board is MACH_AQUILA and board is like below. */
195 #define J1_B2_BOARD 0x0200
196 #define LIMO_UNIVERSAL_BOARD 0x0400
197 #define LIMO_REAL_BOARD 0x0800
198 #define MEDIA_BOARD 0x1000
199 #define BAMBOO_BOARD 0x2000
201 /* board is MACH_KESSLER and board is like below */
202 #define S1_BOARD 0x1000
203 #define KESSLER_BOARD 0x4000
204 #define NEPTUNE_BOARD 0x8000
206 #define BOARD_MASK 0xFF00
208 static int c110_machine_id(void)
210 return gd->bd->bi_arch_number - C110_MACH_START;
213 static int machine_is_aquila(void)
215 return (gd->bd->bi_arch_number == MACH_AQUILA);
218 static int machine_is_tickertape(void)
220 return c110_machine_id() == MACH_TICKERTAPE;
223 static int machine_is_geminus(void)
225 return c110_machine_id() == MACH_GEMINUS;
228 static int machine_is_cypress(void)
230 return c110_machine_id() == MACH_CYPRESS;
233 static int board_is_limo_universal(void)
235 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
238 static int board_is_limo_real(void)
240 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
243 static int board_is_media(void)
245 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
248 static int board_is_j1b2(void)
250 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
254 static int machine_is_kessler(void)
256 return gd->bd->bi_arch_number == MACH_KESSLER;
259 static int board_is_neptune(void)
261 return machine_is_kessler() && (board_rev & NEPTUNE_BOARD);
265 static int machine_is_wmg160(void)
267 return c110_machine_id() == MACH_WMG160;
270 static void check_battery(int mode);
272 void i2c_init_board(void)
274 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
277 if (cpu_is_s5pc100())
280 num_bus = ARRAY_SIZE(i2c_gpio);
282 if (machine_is_aquila()) {
283 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
284 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
285 } else if (machine_is_kessler()) {
286 i2c_gpio[I2C_GPIO7].bus->gpio_base =
287 (unsigned int)&gpio->gpio_mp0_5;
288 } else if (machine_is_cypress()) {
289 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
290 i2c_gpio[I2C_GPIO7].bus->gpio_base =
291 (unsigned int)&gpio->gpio_mp0_5;
293 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
296 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
297 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
298 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
299 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
300 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
302 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
304 /* Reset on max17040 early */
305 if (battery_soc == 0)
309 #ifdef CONFIG_MISC_INIT_R
310 #define DEV_INFO_LEN 256
311 static char device_info[DEV_INFO_LEN];
312 static int display_info;
314 static void empty_device_info_buffer(void)
316 memset(device_info, 0x0, DEV_INFO_LEN);
319 static void dprintf(const char *fmt, ...)
326 i = vsprintf(buf, fmt, args);
331 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
332 puts("Flushing device info...\n");
334 empty_device_info_buffer();
336 strncat(device_info, buf, 127);
340 #ifdef CONFIG_S5PC1XXFB
341 static void display_device_info(void)
348 set_font_color(FONT_WHITE);
349 fb_printf(device_info);
352 memset(device_info, 0x0, DEV_INFO_LEN);
354 udelay(5 * 1000 * 1000);
358 static const char *board_name[] = {
362 "P1P2", /* Don't remove it */
375 static char feature_buffer[32];
377 static char *display_features(int board, int board_rev)
380 char *buf = feature_buffer;
383 if (board == MACH_AQUILA) {
384 if (board_rev & SPLIT_SCREEN_FEATURE)
385 name = "SplitScreen";
386 if (board_rev & J1_B2_BOARD)
388 /* Limo Real or Universal */
389 if (board_rev & LIMO_REAL_BOARD)
391 else if (board_rev & LIMO_UNIVERSAL_BOARD)
392 name = "Limo Universal";
393 if (board_rev & MEDIA_BOARD)
395 if (board_rev & BAMBOO_BOARD)
397 } else if (board == MACH_KESSLER) {
398 if (board_rev & NEPTUNE_BOARD)
400 if (board_rev & S1_BOARD)
404 count += sprintf(buf + count, " - %s", name);
409 static char *get_board_name(int board)
411 if (board == MACH_AQUILA)
413 else if (board == MACH_KESSLER)
415 else if (board == MACH_WMG160)
417 return (char *) board_name[board];
420 static void check_board_revision(int board, int rev)
422 if (board == MACH_AQUILA) {
423 /* Limo Real or Universal */
424 if (rev & LIMO_UNIVERSAL_BOARD)
425 board_rev &= ~J1_B2_BOARD;
426 if (rev & LIMO_REAL_BOARD)
427 board_rev &= ~(J1_B2_BOARD |
428 LIMO_UNIVERSAL_BOARD);
429 if (rev & MEDIA_BOARD)
430 board_rev &= ~(J1_B2_BOARD |
431 LIMO_UNIVERSAL_BOARD);
432 if (rev & BAMBOO_BOARD)
433 board_rev &= ~(J1_B2_BOARD |
434 LIMO_UNIVERSAL_BOARD |
437 } else if (board == MACH_KESSLER) {
438 if (rev & KESSLER_BOARD)
439 board_rev &= ~(J1_B2_BOARD |
440 LIMO_UNIVERSAL_BOARD);
441 if (rev & NEPTUNE_BOARD)
442 board_rev &= ~(J1_B2_BOARD |
443 LIMO_UNIVERSAL_BOARD);
445 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
448 board_rev &= ~BOARD_MASK;
452 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
456 gpio_direction_input(bank, 2);
457 gpio_direction_input(bank, 3);
458 gpio_direction_input(bank, 4);
459 gpio_direction_input(bank, hwrev3);
461 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
462 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
463 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
464 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
466 rev = gpio_get_value(bank, 2);
467 rev |= (gpio_get_value(bank, 3) << 1);
468 rev |= (gpio_get_value(bank, 4) << 2);
469 rev |= (gpio_get_value(bank, hwrev3) << 3);
474 static void check_hw_revision(void)
476 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
478 if (cpu_is_s5pc100()) {
479 struct s5pc100_gpio *gpio =
480 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
482 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
484 /* C100 TickerTape */
486 board = MACH_TICKERTAPE;
488 struct s5pc110_gpio *gpio =
489 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
495 * Note Check 'Aquila' board first
499 * LRA: Limo Real Aquila
500 * LUA: Limo Universal Aquila
505 * ADDR = 0xE0200000 + OFF
507 * OFF Universal BB LRA LUA OA TT SS CYP
508 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
509 * J2: 0x0284 0x01 0x10 0x00
510 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
511 * H3: 0x0C64 0x03 0x07 0x0F
512 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
513 * I: 0x0224 0x02 0x00 0x08
514 * MP03: 0x0324 0x9x 0xbx 0x9x
515 * MP05: 0x0364 0x80 0x88
519 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
521 board_rev |= J1_B2_BOARD;
523 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
524 gpio_direction_input(&gpio->gpio_j2, 6);
527 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
528 board_rev |= LIMO_UNIVERSAL_BOARD;
530 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
531 board_rev |= LIMO_REAL_BOARD;
533 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
534 board_rev |= MEDIA_BOARD;
536 /* set gpio to default value. */
537 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
538 gpio_direction_output(&gpio->gpio_j2, 6, 0);
541 /* Workaround: C110 Aquila Rev0.6 */
542 if (board_rev == 6) {
544 board_rev |= LIMO_REAL_BOARD;
547 /* C110 Aquila Bamboo */
548 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
550 board_rev |= BAMBOO_BOARD;
553 /* C110 TickerTape */
554 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
555 gpio_get_value(&gpio->gpio_d1, 1) == 0)
556 board = MACH_TICKERTAPE;
558 /* WMG160 - GPH3[0:4] = 0x00 */
559 if (board == MACH_TICKERTAPE) {
562 for (i = 0; i < 4; i++) {
563 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
574 /* C110 Geminus for rev0.0 */
575 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
576 gpio_direction_input(&gpio->gpio_j1, 2);
577 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
578 board = MACH_GEMINUS;
579 if ((board_rev & ~BOARD_MASK) == 3)
582 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
583 gpio_direction_output(&gpio->gpio_j1, 2, 0);
585 /* C110 Geminus for rev0.1 ~ */
586 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
587 gpio_direction_input(&gpio->gpio_j0, 6);
588 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
589 board = MACH_GEMINUS;
592 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
594 /* Kessler MP0_5[6] == 1 */
595 gpio_direction_input(&gpio->gpio_mp0_5, 6);
596 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
597 /* Cypress: Do this for cypress */
598 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
599 gpio_direction_input(&gpio->gpio_j2, 2);
600 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
601 board = MACH_CYPRESS;
602 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
604 board = MACH_KESSLER;
605 board_rev |= KESSLER_BOARD;
607 /* Neptune MP0_5[4] == 1 */
608 gpio_direction_input(&gpio->gpio_mp0_5, 4);
609 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
610 board_rev &= ~KESSLER_BOARD;
611 board_rev |= NEPTUNE_BOARD;
614 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
617 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
618 /* Kessler S1 board detection */
619 if (board == MACH_TICKERTAPE) {
620 board = MACH_KESSLER;
621 board_rev |= S1_BOARD;
626 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
630 if (board < MACH_PSEUDO_END) {
631 if (cpu_is_s5pc110())
632 gd->bd->bi_arch_number = C110_MACH_START + board;
634 gd->bd->bi_arch_number = C100_MACH_START + board;
636 gd->bd->bi_arch_number = board;
639 /* Architecture Common settings */
640 if (cpu_is_s5pc110()) {
641 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
643 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
645 setenv("updatek", "onenand erase 0x60000 0x300000; "
646 "onenand write 0x31008000 0x60000 0x300000");
650 static void show_hw_revision(void)
655 * Workaround for Rev 0.3 + CP Ver ES 3.1
658 if (board_is_limo_real()) {
660 /* default is Rev 0.4 */
666 if (machine_is_kessler() || machine_is_aquila())
667 board = gd->bd->bi_arch_number;
668 else if (cpu_is_s5pc110())
669 board = gd->bd->bi_arch_number - C110_MACH_START;
671 board = gd->bd->bi_arch_number - C100_MACH_START;
674 check_board_revision(board, board_rev);
676 /* Set CPU Revision */
677 if (machine_is_aquila()) {
678 if (board_is_limo_real()) {
679 if ((board_rev & 0xf) < 8)
680 s5pc1xx_set_cpu_rev(0);
682 } else if (machine_is_kessler()) {
683 s5pc1xx_set_cpu_rev(1);
684 } else if (machine_is_geminus()) {
685 if ((board_rev & 0xf) < 1)
686 s5pc1xx_set_cpu_rev(0);
687 } else if (machine_is_cypress()) {
688 s5pc1xx_set_cpu_rev(1);
690 s5pc1xx_set_cpu_rev(0);
693 empty_device_info_buffer();
694 dprintf("HW Revision:\t%x (%s%s) %s\n",
695 board_rev, get_board_name(board),
696 display_features(board, board_rev),
697 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
700 static void check_auto_burn(void)
702 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
703 unsigned int count = 0;
706 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
707 printf("Auto burning bootloader\n");
708 count += sprintf(buf + count, "run updateb; ");
710 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
711 printf("Auto burning kernel\n");
712 count += sprintf(buf + count, "run updatek; ");
716 count += sprintf(buf + count, "reset");
717 setenv("bootcmd", buf);
720 /* Clear the magic value */
721 writel(0xa5a55a5a, magic_base);
722 writel(0xa5a55a5a, magic_base + 0x4);
725 static void pmic_pin_init(void)
727 unsigned int reg, value;
729 if (cpu_is_s5pc100())
732 /* AP_PS_HOLD: XEINT_0: GPH0[0]
733 * Note: Don't use GPIO PS_HOLD it doesn't work
735 reg = S5PC110_PS_HOLD_CONTROL;
737 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
738 S5PC110_PS_HOLD_DATA_HIGH |
739 S5PC110_PS_HOLD_OUT_EN;
742 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
743 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
744 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
747 static void enable_ldos(void)
749 if (cpu_is_s5pc100())
752 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
753 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
756 static void enable_t_flash(void)
758 if (!(board_is_limo_universal() || board_is_limo_real()))
761 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
762 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
765 static void setup_limo_real_gpios(void)
767 if (!board_is_limo_real())
771 * Note: Please write GPIO alphabet order
773 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
774 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
777 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
778 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
780 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
781 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
783 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
784 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
785 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
788 static void setup_media_gpios(void)
790 if (!board_is_media())
794 * Note: Please write GPIO alphabet order
796 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
797 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
799 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
800 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
801 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
804 #define KBR3 (1 << 3)
805 #define KBR2 (1 << 2)
806 #define KBR1 (1 << 1)
807 #define KBR0 (1 << 0)
809 static void check_keypad(void)
811 unsigned int reg, value;
812 unsigned int col_num, row_num;
813 unsigned int col_mask;
814 unsigned int col_mask_shift;
815 unsigned int row_state[4];
817 unsigned int auto_download = 0;
819 if (machine_is_wmg160())
822 if (cpu_is_s5pc100()) {
823 struct s5pc100_gpio *gpio =
824 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
829 /* Set GPH2[2:0] to KP_COL[2:0] */
830 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
831 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
832 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
834 /* Set GPH3[2:0] to KP_ROW[2:0] */
835 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
836 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
837 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
839 reg = S5PC100_KEYPAD_BASE;
840 col_mask = S5PC1XX_KEYIFCOL_MASK;
843 if (board_is_limo_real() || board_is_limo_universal()) {
851 for (i = 0; i < row_num; i++) {
852 /* Set GPH3[3:0] to KP_ROW[3:0] */
853 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
854 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
857 for (i = 0; i < col_num; i++)
858 /* Set GPH2[3:0] to KP_COL[3:0] */
859 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
861 reg = S5PC110_KEYPAD_BASE;
862 col_mask = S5PC110_KEYIFCOLEN_MASK;
866 /* KEYIFCOL reg clear */
867 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
870 for (i = 0; i < col_num; i++) {
872 value &= ~(1 << i) << col_mask_shift;
874 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
877 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
878 row_state[i] = ~value & ((1 << row_num) - 1);
880 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
883 /* KEYIFCOL reg clear */
884 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
886 if (machine_is_aquila() || machine_is_kessler()) {
888 if (row_state[1] & 0x2)
890 if (board_is_neptune()) {
891 /* home & volume down */
892 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
895 /* cam full shot & volume down */
896 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
899 } else if (machine_is_geminus())
900 /* volume down & home */
901 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
905 setenv("bootcmd", "usbdown");
908 static void check_battery(int mode)
910 unsigned char val[2];
911 unsigned char addr = 0x36; /* max17040 fuel gauge */
913 i2c_set_bus_num(I2C_GPIO3);
915 if (machine_is_aquila()) {
918 } else if (machine_is_kessler()) {
919 i2c_set_bus_num(I2C_GPIO7);
920 } else if (machine_is_cypress()) {
921 i2c_set_bus_num(I2C_GPIO7);
922 } else if (machine_is_geminus()) {
924 i2c_set_bus_num(I2C_GPIO7);
928 if (i2c_probe(addr)) {
929 printf("Can't found max17040 fuel gauge\n");
933 /* mode 0: check mode / 1: enable mode */
937 i2c_write(addr, 0xfe, 1, val, 2);
939 i2c_read(addr, 0x04, 1, val, 1);
940 dprintf("battery:\t%d%%\n", val[0]);
941 battery_soc = val[0];
945 static void check_mhl(void)
947 unsigned char val[2];
948 unsigned char addr = 0x39; /* SIL9230 */
950 /* MHL Power enable */
951 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
952 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
954 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
955 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
957 /* 10ms required after reset */
961 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
963 i2c_set_bus_num(I2C_GPIO5);
966 if (i2c_probe(addr)) {
967 printf("Can't found MHL Chip\n");
973 * set to Normal operation
976 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
977 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
982 * 00 = MHL termination ON
983 * 11 = MHL termination OFF
986 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
987 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
990 static int max8998_probe(void)
992 unsigned char addr = 0xCC >> 1;
994 i2c_set_bus_num(I2C_PMIC);
996 if (i2c_probe(addr)) {
997 printf("Can't found max8998\n");
1004 #define CHARGER_ANIMATION_FRAME 6
1005 static void max8998_clear_interrupt(void)
1007 unsigned char addr, val[2];
1010 if (max8998_probe())
1013 i2c_read(addr, 0x00, 1, val, 1);
1014 i2c_read(addr, 0x01, 1, val, 1);
1015 i2c_read(addr, 0x02, 1, val, 1);
1016 i2c_read(addr, 0x03, 1, val, 1);
1019 static int max8998_power_key(void)
1021 unsigned char addr, val[2];
1024 if (max8998_probe())
1027 /* Accessing IRQ1 register */
1028 i2c_read(addr, 0x00, 1, val, 1);
1029 if (val[0] & (1 << 6))
1035 static int max8998_has_ext_power_source(void)
1037 unsigned char addr, val[2];
1040 if (max8998_probe())
1043 /* Accessing STATUS2 register */
1044 i2c_read(addr, 0x09, 1, val, 1);
1045 if (val[0] & (1 << 5))
1051 struct thermister_stat {
1056 static struct thermister_stat adc_to_temperature_data[] = {
1057 { .centigrade = -20, .adc = 1856, },
1058 { .centigrade = -15, .adc = 1799, },
1059 { .centigrade = -10, .adc = 1730, },
1060 { .centigrade = -5, .adc = 1649, },
1061 { .centigrade = 0, .adc = 1556, },
1062 { .centigrade = 5, .adc = 1454, },
1063 { .centigrade = 10, .adc = 1343, },
1064 { .centigrade = 15, .adc = 1227, },
1065 { .centigrade = 20, .adc = 1109, },
1066 { .centigrade = 25, .adc = 992, },
1067 { .centigrade = 30, .adc = 880, },
1068 { .centigrade = 35, .adc = 773, },
1069 { .centigrade = 40, .adc = 675, },
1070 { .centigrade = 45, .adc = 586, },
1071 { .centigrade = 50, .adc = 507, },
1072 { .centigrade = 55, .adc = 436, },
1073 { .centigrade = 58, .adc = 399, },
1074 { .centigrade = 63, .adc = 343, },
1075 { .centigrade = 65, .adc = 322, },
1079 #define USHRT_MAX 0xFFFFU
1081 static int adc_to_temperature_centigrade(unsigned short adc)
1085 /* low_*: Greatest Lower Bound,
1086 * * * * high_*: Smallest Upper Bound */
1087 int low_temp = 0, high_temp = 0;
1088 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1089 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1090 if (adc_to_temperature_data[i].adc <= adc &&
1091 adc_to_temperature_data[i].adc >= low_adc) {
1092 low_temp = adc_to_temperature_data[i].centigrade;
1093 low_adc = adc_to_temperature_data[i].adc;
1095 if (adc_to_temperature_data[i].adc >= adc &&
1096 adc_to_temperature_data[i].adc <= high_adc) {
1097 high_temp = adc_to_temperature_data[i].centigrade;
1098 high_adc = adc_to_temperature_data[i].adc;
1102 /* Linear approximation between cloest low and high,
1103 * which is the weighted average of the two. */
1105 /* The following equation is correct only when the two are different */
1106 if (low_adc == high_adc)
1108 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1109 return 20; /* The room temperature */
1112 if (high_adc == USHRT_MAX)
1115 approximation = low_temp * (adc - low_adc) +
1116 high_temp * (high_adc - adc);
1117 approximation /= high_adc - low_adc;
1119 return approximation;
1122 static unsigned short get_adc_value(int channel)
1124 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1125 unsigned short ret = 0;
1129 unsigned int loop = 0;
1131 if (machine_is_kessler())
1133 else if (machine_is_geminus())
1135 else if (machine_is_wmg160())
1137 else if (machine_is_cypress())
1139 else if (machine_is_tickertape())
1141 else if (machine_is_aquila())
1144 else if (machine_is_p1p2())
1148 sprintf(buf, "pmic ldo %d on", ldonum);
1149 run_command(buf, 0);
1151 writel(channel & 0xF, &adc->adcmux);
1152 writel((1 << 14) | (49 << 6), &adc->adccon);
1153 writel(1000 & 0xffff, &adc->adcdly);
1154 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1156 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1161 reg = readl(&adc->adccon);
1162 } while (!reg & (1 << 15) && loop++ < 1000);
1164 ret = readl(&adc->adcdat0) & 0xFFF;
1165 sprintf(buf, "pmic ldo %d off", ldonum);
1166 run_command(buf, 0);
1171 static int adc_get_average_ambient_temperature(void)
1173 if (machine_is_kessler()) {
1174 unsigned short min = USHRT_MAX;
1175 unsigned short max = 0;
1176 unsigned int sum = 0;
1177 unsigned int measured = 0;
1180 for (i = 0; i < 7; i++) {
1181 unsigned short measurement = get_adc_value(6);
1184 if (min > measurement)
1186 if (max < measurement)
1189 if (measured >= 3) {
1195 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1196 adc_to_temperature_centigrade(sum), sum);
1197 return adc_to_temperature_centigrade(sum);
1200 return 20; /* 20 Centigrade */
1203 enum temperature_level {
1211 static enum temperature_level temperature_check(void)
1213 int temp = adc_get_average_ambient_temperature();
1215 return _TEMP_TOO_LOW;
1217 return _TEMP_OK_LOW;
1219 return _TEMP_TOO_HIGH;
1221 return _TEMP_OK_HIGH;
1225 extern void lcd_display_clear(void);
1226 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1228 static void charger_en(int enable)
1234 unsigned char addr = 0xCC >> 1; /* max8998 */
1235 unsigned char val[2];
1237 if (max8998_probe())
1241 printf("Disable the charger.\n");
1242 i2c_read(addr, 0x0D, 1, val, 1);
1245 i2c_write(addr, 0x0D, 1, val, 1);
1247 i2c_read(addr, 0x0C, 1, val, 1);
1248 val[0] &= ~(0x7 << 0);
1249 val[0] &= ~(0x7 << 5);
1250 if (enable == 600) {
1251 val[0] |= 5; /* 600mA */
1252 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1253 } else { /* Assume 475 mA */
1255 val[0] |= 2; /* 475mA */
1256 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1258 i2c_write(addr, 0x0C, 1, val, 1);
1260 i2c_read(addr, 0x0D, 1, val, 1);
1262 i2c_write(addr, 0x0D, 1, val, 1);
1263 printf("Enable the charger @ %dmA\n", enable);
1267 void lcd_power_on(unsigned int onoff);
1268 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1269 extern int drv_lcd_init_resume (void);
1271 static void into_charge_mode(void)
1277 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1278 unsigned int reg, wakeup_stat;
1279 int charger_speed = 600;
1281 max8998_clear_interrupt();
1283 printf("Charge Mode\n");
1284 charger_en(charger_speed);
1286 #ifdef CONFIG_S5PC1XXFB
1289 /* TODO: write the image-text for the charger */
1291 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1292 if (level >= CHARGER_ANIMATION_FRAME)
1293 level = CHARGER_ANIMATION_FRAME - 1;
1295 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1296 bmp_addr[i] = (ulong)battery_charging_animation[i];
1298 lcd_display_clear();
1299 for (i = 0; i < 3; i++) {
1300 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1303 bmp = gunzip_bmp(bmp_addr[j], &len);
1304 lcd_display_bitmap((ulong)bmp, 140, 202);
1307 for (k = 0; k < 10; k++) {
1308 if (max8998_power_key()) {
1309 lcd_display_clear();
1310 goto restore_screen;
1311 } else if (!max8998_has_ext_power_source()) {
1312 lcd_display_clear();
1313 goto restore_screen;
1322 /* Disable the display to prevent flickering */
1323 /* TODO: how to reenable the display later? */
1327 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1328 unsigned int org, org_ip3;
1329 enum temperature_level previous_state = _TEMP_OK;
1331 empty_device_info_buffer();
1332 if (max8998_power_key())
1334 else if (!max8998_has_ext_power_source())
1337 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1338 org_ip3 = readl(0xE010046C);
1339 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1341 reg = org = readl(&rtc->rtccon);
1343 writel(reg, &rtc->rtccon);
1345 reg = readl(&rtc->rtccon);
1346 writel(reg | (1 << 3), &rtc->rtccon);
1348 writel(reg & ~(1 << 3), &rtc->rtccon);
1351 reg = readl(&rtc->rtccon);
1352 reg &= ~((1 << 8) | (0xF << 4));
1353 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1354 writel(reg, &rtc->rtccon);
1356 reg = 15 * 4 - 1; /* 15 sec */
1357 writel(reg, &rtc->ticcnt);
1359 /* EVT0: sleep 1, EVT1: sleep */
1360 if (cpu_is_s5pc110()) {
1361 char *name = "dummy";
1362 char *usage = "N/A";
1369 if (s5pc1xx_get_cpu_rev() == 0) {
1370 char *argv[] = {"1", "1"};
1371 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1373 char *argv[] = {"0", "0"};
1374 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1377 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1381 /* Check TEMP HIGH/LOW */
1382 switch (temperature_check()) {
1384 charger_en(charger_speed);
1385 previous_state = _TEMP_OK;
1389 previous_state = _TEMP_TOO_LOW;
1391 case _TEMP_TOO_HIGH:
1393 previous_state = _TEMP_TOO_HIGH;
1396 if (previous_state == _TEMP_TOO_LOW) {
1399 charger_en(charger_speed);
1400 previous_state = _TEMP_OK;
1404 if (previous_state == _TEMP_TOO_HIGH) {
1407 charger_en(charger_speed);
1408 previous_state = _TEMP_OK;
1413 writel(org, &rtc->rtccon);
1414 writel(org_ip3, 0xE010046C);
1416 } while (wakeup_stat == 0x04); /* RTC TICK */
1419 /* TODO: Reenable logo display (not working yet) */
1421 drv_lcd_init_resume();
1424 static int fsa9480_probe(void)
1426 unsigned char addr = 0x25;
1428 if (cpu_is_s5pc100())
1431 if (board_is_limo_real()) {
1432 if (hwrevision(0) || hwrevision(1))
1436 i2c_set_bus_num(I2C_PMIC);
1438 if (machine_is_kessler()) {
1439 i2c_set_bus_num(I2C_GPIO6);
1440 } else if (machine_is_cypress()) {
1441 i2c_set_bus_num(I2C_GPIO6);
1442 } else if (machine_is_geminus()) {
1444 i2c_set_bus_num(I2C_GPIO6);
1445 } else if (machine_is_wmg160()) {
1446 i2c_set_bus_num(I2C_GPIO6);
1449 if (i2c_probe(addr)) {
1450 printf("Can't found fsa9480\n");
1457 static void check_micro_usb(int intr)
1460 unsigned char val[2];
1461 static int started_charging_once = 0;
1464 if (fsa9480_probe())
1467 addr = 0x25; /* fsa9480 */
1469 /* Clear Interrupt */
1471 i2c_read(addr, 0x03, 1, val, 2);
1475 /* Read Device Type 1 */
1476 i2c_read(addr, 0x0a, 1, val, 1);
1478 #define FSA_DEV1_CHARGER (1 << 6)
1479 #define FSA_DEV1_UART (1 << 3)
1480 #define FSA_DEV1_USB (1 << 2)
1481 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1482 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1485 * If USB, use default 475mA
1486 * If Charger, use 600mA and go to charge mode
1488 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1489 started_charging_once = 1;
1491 /* If it's full, do not charge. */
1492 if (battery_soc < 100)
1496 } else if (val[0] & FSA_DEV1_USB) {
1497 if (battery_soc < 100)
1498 charger_en(475); /* enable charger and keep booting */
1503 /* If Factory Mode is Boot ON-USB, go to download mode */
1504 i2c_read(addr, 0x07, 1, val, 1);
1506 #define FSA_ADC_FAC_USB_OFF 0x18
1507 #define FSA_ADC_FAC_USB_ON 0x19
1508 #define FSA_ADC_FAC_UART 0x1d
1510 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1511 setenv("bootcmd", "usbdown");
1513 path = getenv("usb");
1515 if (!strncmp(path, "cp", 2))
1516 run_command("microusb cp", 0);
1519 static void micro_usb_switch(int path)
1522 unsigned char val[2];
1524 if (fsa9480_probe())
1527 addr = 0x25; /* fsa9480 */
1530 val[0] = 0x90; /* VAUDIO */
1532 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1534 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1536 i2c_read(addr, 0x2, 1, val, 1);
1537 val[0] &= ~(1 << 2); /* Manual switching */
1538 i2c_write(addr, 0x2, 1, val, 1);
1541 #define MAX8998_REG_ONOFF1 0x11
1542 #define MAX8998_REG_ONOFF2 0x12
1543 #define MAX8998_REG_ONOFF3 0x13
1544 #define MAX8998_REG_LDO7 0x21
1545 #define MAX8998_REG_LDO17 0x29
1547 #define MAX8998_LDO3 (1 << 2)
1549 #define MAX8998_LDO6 (1 << 7)
1550 #define MAX8998_LDO7 (1 << 6)
1551 #define MAX8998_LDO8 (1 << 5)
1552 #define MAX8998_LDO9 (1 << 4)
1553 #define MAX8998_LDO10 (1 << 3)
1554 #define MAX8998_LDO11 (1 << 2)
1555 #define MAX8998_LDO12 (1 << 1)
1556 #define MAX8998_LDO13 (1 << 0)
1558 #define MAX8998_LDO14 (1 << 7)
1559 #define MAX8998_LDO15 (1 << 6)
1560 #define MAX8998_LDO16 (1 << 5)
1561 #define MAX8998_LDO17 (1 << 4)
1564 static void init_pmic(void)
1567 unsigned char val[2];
1569 if (cpu_is_s5pc100())
1572 addr = 0xCC >> 1; /* max8998 */
1573 if (max8998_probe())
1577 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1578 val[0] &= ~MAX8998_LDO3;
1579 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1582 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1584 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1585 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1587 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1588 MAX8998_LDO12 | MAX8998_LDO13);
1590 if (machine_is_kessler())
1591 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1593 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1594 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1596 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1598 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1599 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1601 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1602 MAX8998_LDO16 | MAX8998_LDO17);
1604 if (machine_is_kessler())
1605 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1607 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1608 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1611 static void setup_power_down_mode_registers(void)
1613 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1614 struct s5pc1xx_gpio_bank *bank;
1615 struct gpio_powermode *p;
1617 struct gpio_external *ge;
1619 struct s5pc1xx_gpio_item *mr;
1623 if (cpu_is_s5pc100())
1626 /* Only Limo real and kessler supports worked for sleep currnet */
1627 if (machine_is_aquila()) {
1628 if (board_is_limo_real())
1632 } else if (machine_is_kessler()) {
1634 } else if (machine_is_geminus()) {
1640 if (machine_is_aquila()) {
1641 /* Aquila rev 0.8 or lower */
1642 p = aquila_powerdown_modes;
1643 ge = aquila_external_powerdown_modes;
1644 mr = aquila_mirror_powerdown_mode;
1645 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1646 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1647 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1648 } else if (machine_is_kessler()) {
1649 /* Aquila rev 0.9 */
1650 p = kessler_powerdown_modes;
1651 ge = kessler_external_powerdown_modes;
1652 mr = kessler_mirror_powerdown_mode;
1653 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1654 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1655 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1656 } else if (machine_is_geminus()) {
1657 if (hwrevision(1)) {
1658 /* Same as Aquila rev 0.9 */
1660 p = kessler_powerdown_modes;
1661 ge = kessler_external_powerdown_modes;
1662 mr = kessler_mirror_powerdown_mode;
1663 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1664 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1665 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1667 p = aquila_powerdown_modes;
1668 ge = aquila_external_powerdown_modes;
1669 mr = aquila_mirror_powerdown_mode;
1670 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1671 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1672 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1674 } else if (hwrevision(0)) {
1675 /* Same as Aquila rev 0.8 or lower */
1676 p = aquila_powerdown_modes;
1677 ge = aquila_external_powerdown_modes;
1678 mr = aquila_mirror_powerdown_mode;
1679 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1680 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1681 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1683 return; /* Not supported */
1687 bank = &gpio->gpio_a0;
1689 for (i = 0; i < n_p; i++, p++, bank++) {
1690 writel(p->conpdn, &bank->pdn_con);
1691 writel(p->pudpdn, &bank->pdn_pull);
1694 writel(0xff0022b0, (unsigned int *)0xF0000000);
1695 writel(0xff0022b0, (unsigned int *)0xF1400000);
1697 bank = &gpio->gpio_h0;
1699 for (i = 0; i < n_ge; i++) {
1700 writel(ge->con, &bank->con);
1701 writel(ge->dat, &bank->dat);
1702 writel(ge->pud, &bank->pull);
1708 for (i = 0; i < n_mr; i++) {
1709 unsigned int reg = readl(&mr->bank->pdn_con);
1710 reg &= ~(0x3 << (mr->number << 1));
1711 if (readl(&mr->bank->dat) & (1 << mr->number))
1712 reg |= 0x1 << (mr->number << 1);
1713 writel(reg, &mr->bank->pdn_con);
1719 #include "../../../drivers/video/s5p-spi.h"
1721 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1722 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1724 struct spi_platform_data spi_pd;
1726 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1728 void lcd_cfg_gpio(void)
1730 unsigned int i, f3_end = 4;
1732 for (i = 0; i < 8; i++) {
1733 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1734 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1735 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1736 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1737 /* pull-up/down disable */
1738 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1739 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1740 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1742 /* drive strength to max (24bit) */
1743 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1744 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1745 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1746 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1747 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1748 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1751 /* set DISPLAY_DE_B pin for dual rgb mode. */
1752 if (board_is_media())
1755 for (i = 0; i < f3_end; i++) {
1756 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1757 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1758 /* pull-up/down disable */
1759 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1760 /* drive strength to max (24bit) */
1761 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1762 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1764 /* display output path selection (only [1:0] valid) */
1765 writel(0x2, 0xE0107008);
1767 /* gpio pad configuration for LCD reset. */
1768 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1770 /* gpio pad configuration for LCD ON. */
1771 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1773 /* LCD_BACKLIGHT_EN */
1774 if (machine_is_geminus())
1775 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1776 if (board_is_neptune()) {
1777 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1778 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1782 * gpio pad configuration for
1783 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1785 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1786 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1787 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1788 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1790 if (machine_is_aquila() || machine_is_kessler()) {
1791 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1793 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1795 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1797 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1800 if (board_is_neptune())
1801 s6d16a0x_set_platform_data(&spi_pd);
1803 s6e63m0_set_platform_data(&spi_pd);
1804 if (board_is_media())
1809 if (machine_is_cypress()) {
1810 #if 0 /* universal cypress */
1812 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1815 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1817 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1821 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1823 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1824 #if 0 /* universal cypress */
1825 pd_cs.bank = &gpio_base->gpio_mp0_1;
1828 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1830 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1832 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1837 /* these data would be sent to s6e63m0 lcd panel driver. */
1838 s6e63m0_set_platform_data(&spi_pd);
1844 #define SWRST_REG 0x00
1845 #define LEDCON_REG 0x01
1846 #define LED_CUR_SET_REG 0x03
1847 #define LED_CUR_TR_REG 0x08
1850 #define NORMAL_MODE 0x01
1851 #define CUR_SET 0x63
1854 void backlight_on(unsigned int onoff)
1858 unsigned char val[2];
1859 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1862 if (machine_is_geminus())
1863 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1865 if (machine_is_geminus())
1866 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1869 if (machine_is_kessler() && board_is_neptune()) {
1870 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1873 i2c_set_bus_num(I2C_GPIO5);
1876 if (i2c_probe(addr)) {
1877 if (i2c_probe(addr)) {
1878 printf("Can't found s6d16a0x backlight i2c\n");
1883 i2c_write(addr, SWRST_REG, 1, val, 1);
1886 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1888 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1889 val[0] = NORMAL_MODE;
1890 i2c_write(addr, LEDCON_REG, 1, val, 1);
1895 void reset_lcd(void)
1897 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1899 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1900 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1901 if (machine_is_cypress())
1902 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1905 void lcd_power_on(unsigned int onoff)
1907 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1910 if (machine_is_aquila() || machine_is_geminus())
1911 gpio_set_value(&gpio->gpio_j1, 3, 1);
1913 if (machine_is_cypress())
1914 gpio_set_value(&gpio->gpio_g2, 2, 1);
1916 if (machine_is_kessler()) {
1918 unsigned char val[2];
1919 unsigned char val2[2];
1921 gpio_set_value(&gpio->gpio_j1, 3, 1);
1923 addr = 0xCC >> 1; /* max8998 */
1924 if (max8998_probe())
1927 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1928 val[0] &= ~(MAX8998_LDO17);
1929 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1930 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1932 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1933 val[0] |= MAX8998_LDO17;
1935 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1936 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1938 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1939 val[0] |= MAX8998_LDO7;
1941 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1942 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1945 if (machine_is_aquila() || machine_is_geminus())
1946 gpio_set_value(&gpio->gpio_j1, 3, 0);
1948 if (machine_is_cypress())
1949 gpio_set_value(&gpio->gpio_g2, 2, 0);
1951 if (machine_is_kessler()) {
1953 unsigned char val[2];
1955 gpio_set_value(&gpio->gpio_j1, 3, 0);
1957 addr = 0xCC >> 1; /* max8998 */
1958 if (max8998_probe())
1961 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1962 val[0] &= ~(MAX8998_LDO7);
1963 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1964 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1966 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1967 val[0] &= ~(MAX8998_LDO17);
1968 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1969 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1974 extern void s6e63m0_cfg_ldo(void);
1975 extern void s6e63m0_enable_ldo(unsigned int onoff);
1976 extern void s6d16a0x_cfg_ldo(void);
1977 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1979 int s5p_no_lcd_support(void)
1981 if (machine_is_wmg160())
1986 void init_panel_info(vidinfo_t *vid)
1988 vid->cfg_gpio = NULL;
1989 vid->reset_lcd = NULL;
1990 vid->backlight_on = NULL;
1991 vid->lcd_power_on = NULL;
1993 vid->cfg_ldo = NULL;
1994 vid->enable_ldo = NULL;
1996 vid->init_delay = 0;
1997 vid->reset_delay = 0;
1998 vid->power_on_delay = 0;
2003 vid->vl_width = 480;
2004 vid->vl_height = 800;
2006 vid->dual_lcd_enabled = 0;
2008 if (board_is_media()) {
2011 vid->vl_width = 960;
2012 vid->vl_height = 800;
2014 /* enable dual lcd mode. */
2015 vid->dual_lcd_enabled = 1;
2018 vid->vl_clkp = CONFIG_SYS_HIGH;
2019 vid->vl_hsp = CONFIG_SYS_LOW;
2020 vid->vl_vsp = CONFIG_SYS_LOW;
2021 vid->vl_dp = CONFIG_SYS_HIGH;
2024 /* S6E63M0 LCD Panel */
2033 if (machine_is_aquila() || machine_is_kessler()
2034 || machine_is_cypress()) {
2035 vid->cfg_gpio = lcd_cfg_gpio;
2036 vid->reset_lcd = reset_lcd;
2037 vid->backlight_on = backlight_on;
2038 vid->lcd_power_on = lcd_power_on;
2039 vid->cfg_ldo = s6e63m0_cfg_ldo;
2040 vid->enable_ldo = s6e63m0_enable_ldo;
2042 vid->init_delay = 25000;
2043 vid->reset_delay = 120000;
2046 if (board_is_neptune()) {
2050 vid->vl_width = 320;
2051 vid->vl_height = 480;
2053 vid->vl_clkp = CONFIG_SYS_HIGH;
2054 vid->vl_hsp = CONFIG_SYS_HIGH;
2055 vid->vl_vsp = CONFIG_SYS_HIGH;
2056 vid->vl_dp = CONFIG_SYS_LOW;
2059 /* disable dual lcd mode. */
2060 vid->dual_lcd_enabled = 0;
2062 /* S6D16A0X LCD Panel */
2071 vid->cfg_gpio = lcd_cfg_gpio;
2072 vid->backlight_on = backlight_on;
2073 vid->lcd_power_on = lcd_power_on;
2074 vid->reset_lcd = reset_lcd;
2075 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2076 vid->enable_ldo = s6d16a0x_enable_ldo;
2078 vid->init_delay = 10000;
2079 vid->power_on_delay = 10000;
2080 vid->reset_delay = 1000;
2084 if (machine_is_geminus()) {
2088 vid->vl_width = 1024,
2089 vid->vl_height = 600,
2090 vid->vl_clkp = CONFIG_SYS_LOW,
2091 vid->vl_hsp = CONFIG_SYS_HIGH,
2092 vid->vl_vsp = CONFIG_SYS_HIGH,
2093 vid->vl_dp = CONFIG_SYS_LOW,
2104 vid->cfg_gpio = lcd_cfg_gpio;
2105 vid->reset_lcd = reset_lcd;
2106 vid->backlight_on = backlight_on;
2107 vid->lcd_power_on = lcd_power_on;
2113 vid->vl_width = 480,
2114 vid->vl_height = 800,
2115 vid->vl_clkp = CONFIG_SYS_HIGH,
2116 vid->vl_hsp = CONFIG_SYS_LOW,
2117 vid->vl_vsp = CONFIG_SYS_LOW,
2118 vid->vl_dp = CONFIG_SYS_HIGH,
2134 vid->vl_width = 1024,
2135 vid->vl_height = 600,
2136 vid->vl_clkp = CONFIG_SYS_HIGH,
2137 vid->vl_hsp = CONFIG_SYS_HIGH,
2138 vid->vl_vsp = CONFIG_SYS_HIGH,
2139 vid->vl_dp = CONFIG_SYS_LOW,
2142 /* AMS701KA AMOLED Panel. */
2154 static void setup_meminfo(void)
2156 char meminfo[64] = {0, };
2157 int count = 0, size, real;
2159 size = gd->bd->bi_dram[0].size >> 20;
2160 count += sprintf(meminfo + count, "mem=%dM", size);
2162 /* Each Chip Select can't exceed the 256MiB */
2163 size = gd->bd->bi_dram[1].size >> 20;
2164 real = min(size, 256);
2165 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2166 real, (unsigned int)gd->bd->bi_dram[1].start);
2170 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2171 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2174 setenv("meminfo", meminfo);
2177 int misc_init_r(void)
2180 /* It should be located at first */
2183 if (machine_is_aquila() || machine_is_kessler()) {
2184 if (board_is_neptune())
2185 setenv("lcdinfo", "lcd=s6d16a0x");
2186 else if (board_is_media())
2187 setenv("lcdinfo", "lcd=s6e63m0");
2189 setenv("lcdinfo", "lcd=s6e63m0");
2191 if (machine_is_geminus())
2192 setenv("lcdinfo", "lcd=lms480jc01");
2193 if (machine_is_cypress())
2194 setenv("lcdinfo", "lcd=s6e63m0");
2200 /* Set proper PMIC pins */
2203 /* Check auto burning */
2206 /* To power up I2C2 */
2209 /* Enable T-Flash at Limo Real or Limo Universal */
2212 /* Setup Limo Real board GPIOs */
2213 setup_limo_real_gpios();
2215 /* Setup Media board GPIOs */
2216 setup_media_gpios();
2218 /* To usbdown automatically */
2224 #ifdef CONFIG_S5PC1XXFB
2225 display_device_info();
2228 setup_power_down_mode_registers();
2230 /* check max17040 */
2240 int board_init(void)
2242 /* Set Initial global variables */
2243 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2245 gd->bd->bi_arch_number = MACH_AQUILA;
2246 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2248 /* Check H/W Revision */
2249 check_hw_revision();
2256 unsigned int base, memconfig0, size;
2257 unsigned int memconfig1, sz = 0;
2259 if (cpu_is_s5pc100()) {
2260 /* In mem setup, we swap the bank. So below size is correct */
2261 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2262 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2263 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2266 /* In S5PC110, we can't swap the DMC0/1 */
2267 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2268 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2270 base = S5PC110_DMC1_BASE;
2271 /* DMC configuration */
2272 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2273 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2275 size = (memconfig0 >> 16) & 0xFF;
2276 size = ((unsigned char) ~size) + 1;
2279 * (0x07 + 1) * 16 = 128 MiB
2280 * (0x0f + 1) * 16 = 256 MiB
2285 * Aquila Rev0.5 4G3G1G
2286 * Aquila Rev0.8 4G3G1G
2287 * Aquila Rev0.9 4G3G1G
2289 if (machine_is_aquila() || machine_is_kessler())
2290 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2291 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2293 sz = (memconfig1 >> 16) & 0xFF;
2294 sz = ((unsigned char) ~sz) + 1;
2300 * bi_dram[1].size contains all DMC1 memory size
2302 gd->bd->bi_dram[1].size = (size + sz) << 20;
2307 /* Used for sleep test */
2308 static unsigned char saved_val[4][2];
2309 void board_sleep_init_late(void)
2311 /* CODEC_LDO_EN: GPF3[4] */
2312 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2313 /* CODEC_XTAL_EN: GPH3[2] */
2314 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2316 /* MMC T_FLASH off */
2317 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2319 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2320 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2321 /* MHL_ON for REV02 or higher */
2322 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2325 void board_sleep_init(void)
2328 unsigned char val[2];
2331 if (max8998_probe())
2334 if (machine_is_kessler()) {
2336 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2337 saved_val[0][0] = val[0];
2338 saved_val[0][1] = val[1];
2339 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2340 (1 << 1) | (1 << 0));
2341 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2342 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2345 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2346 saved_val[1][0] = val[0];
2347 saved_val[1][1] = val[1];
2348 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2349 (1 << 2) | (1 << 1) | (1 << 0));
2351 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2352 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2355 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2356 saved_val[2][0] = val[0];
2357 saved_val[2][1] = val[1];
2358 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2359 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2360 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2363 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2364 saved_val[3][0] = val[0];
2365 saved_val[3][1] = val[1];
2366 val[0] &= ~((1 << 6) | (1 << 4));
2367 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2368 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2370 printf("Turned off regulators with Kessler setting."
2371 " Preparing to sleep. [%s:%d]\n",
2372 __FILE__, __LINE__);
2373 } else { /* Default */
2375 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2376 saved_val[0][0] = val[0];
2377 saved_val[0][1] = val[1];
2378 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2379 (1 << 1) | (1 << 0));
2380 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2381 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2384 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2385 saved_val[1][0] = val[0];
2386 saved_val[1][1] = val[1];
2387 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2388 (1 << 2) | (1 << 1) | (1 << 0));
2390 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2391 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2394 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2395 saved_val[2][0] = val[0];
2396 saved_val[2][1] = val[1];
2397 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2398 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2402 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2403 saved_val[3][0] = val[0];
2404 saved_val[3][1] = val[1];
2405 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2406 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2407 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2409 printf("Turned off regulators with default(Aquila) setting."
2410 " Preparing to sleep. [%s:%d]\n",
2411 __FILE__, __LINE__);
2415 void board_sleep_resume(void)
2418 unsigned char val[2];
2423 if (max8998_probe())
2427 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2430 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2431 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2433 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2434 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2436 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2437 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2438 printf("Waked up.\n");
2440 /* check max17040 */
2447 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2449 static int s5pc1xx_phy_control(int on)
2453 if (on && !status) {
2454 #ifdef CONFIG_CMD_PMIC
2455 run_command("pmic ldo 3 on", 0);
2458 if (board_is_limo_universal() ||
2459 board_is_limo_real() ||
2461 /* check usb path */
2462 if (board_is_limo_real() && !hwrevision(6))
2466 if (machine_is_tickertape())
2467 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2468 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2470 /* USB Path to AP */
2471 micro_usb_switch(0);
2473 } else if (!on && status) {
2474 #ifdef CONFIG_CMD_PMIC
2475 run_command("pmic ldo 3 off", 0);
2484 struct s3c_plat_otg_data s5pc110_otg_data = {
2485 .phy_control = s5pc1xx_phy_control,
2486 .regs_phy = S5PC110_PHY_BASE,
2487 .regs_otg = S5PC110_OTG_BASE,
2490 int board_eth_init(bd_t *bis)
2494 if (cpu_is_s5pc100())
2497 s3c_udc_probe(&s5pc110_otg_data);
2498 if (usb_eth_initialize(bis) >= 0)
2504 #ifdef CONFIG_CMD_USBDOWN
2505 int usb_board_init(void)
2507 #ifdef CONFIG_CMD_PMIC
2508 run_command("pmic ldo 3 on", 0);
2511 if (cpu_is_s5pc100()) {
2512 #ifdef CONFIG_HARD_I2C
2513 uchar val[2] = {0,};
2516 if (i2c_read(0x66, 0, 1, val, 2)) {
2517 printf("i2c_read error\n");
2524 if (i2c_write(0x66, 0, 1, val, 2)) {
2525 printf("i2c_write error\n");
2528 i2c_read(0x66, 0, 1, val, 2);
2534 if (board_is_limo_universal() ||
2535 board_is_limo_real() ||
2537 /* check usb path */
2538 if (board_is_limo_real() && !hwrevision(6))
2542 if (machine_is_tickertape())
2543 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2544 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2546 /* USB Path to AP */
2547 micro_usb_switch(0);
2553 #ifdef CONFIG_GENERIC_MMC
2554 int s5p_no_mmc_support(void)
2556 if (machine_is_wmg160())
2561 int board_mmc_init(bd_t *bis)
2565 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2568 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2569 if (machine_is_kessler())
2570 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2572 if (machine_is_wmg160())
2575 /* MMC0 Clock source = SCLKMPLL */
2576 reg = readl(&clk->src4);
2579 writel(reg, &clk->src4);
2581 reg = readl(&clk->div4);
2584 /* set div value near 50MHz */
2585 clock = get_pll_clk(MPLL) / 1000000;
2586 for (i = 0; i < 0xf; i++) {
2587 if ((clock / (i + 1)) <= 50) {
2593 writel(reg, &clk->div4);
2599 * GPG0[2] SD_0_CDn -> Not used
2600 * GPG0[3:6] SD_0_DATA[0:3]
2602 for (i = 0; i < 7; i++) {
2605 /* GPG0[0:6] special function 2 */
2606 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2607 /* GPG0[0:6] pull disable */
2608 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2609 /* GPG0[0:6] drv 4x */
2610 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2613 if (machine_is_geminus()) {
2614 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2615 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2618 return s5pc1xx_mmc_init(0);
2622 #ifdef CONFIG_CMD_PMIC
2623 static int pmic_status(void)
2625 unsigned char addr, val[2];
2630 if (max8998_probe())
2634 i2c_read(addr, reg, 1, val, 1);
2635 for (i = 7; i >= 4; i--)
2636 printf("BUCK%d %s\n", 7 - i + 1,
2637 val[0] & (1 << i) ? "on" : "off");
2639 printf("LDO%d %s\n", 5 - i,
2640 val[0] & (1 << i) ? "on" : "off");
2642 i2c_read(addr, reg, 1, val, 1);
2643 for (i = 7; i >= 0; i--)
2644 printf("LDO%d %s\n", 7 - i + 6,
2645 val[0] & (1 << i) ? "on" : "off");
2647 i2c_read(addr, reg, 1, val, 1);
2648 for (i = 7; i >= 4; i--)
2649 printf("LDO%d %s\n", 7 - i + 14,
2650 val[0] & (1 << i) ? "on" : "off");
2653 i2c_read(addr, reg, 1, val, 1);
2654 for (i = 7; i >= 6; i--)
2655 printf("SAFEOUT%d %s\n", 7 - i + 1,
2656 val[0] & (1 << i) ? "on" : "off");
2660 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2662 unsigned char addr, val[2];
2663 unsigned int reg, shift;
2671 } else if (ldo <= 13) {
2674 } else if (ldo <= 17) {
2676 shift = 17 - ldo + 4;
2683 shift = 4 - buck + 4;
2684 } else if (safeout) {
2688 shift = 8 - safeout;
2694 if (max8998_probe())
2697 i2c_read(addr, reg, 1, val, 1);
2699 val[0] |= (1 << shift);
2701 val[0] &= ~(1 << shift);
2702 i2c_write(addr, reg, 1, val, 1);
2703 i2c_read(addr, reg, 1, val, 1);
2706 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2707 val[0] & (1 << shift) ? "on" : "off");
2709 printf("buck %d value 0x%x, %s\n", buck, val[0],
2710 val[0] & (1 << shift) ? "on" : "off");
2712 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2713 val[0] & (1 << shift) ? "on" : "off");
2718 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2720 int buck = 0, ldo = 0, safeout = 0, on = -1;
2724 if (strncmp(argv[1], "status", 6) == 0)
2725 return pmic_status();
2728 if (strncmp(argv[1], "ldo", 3) == 0)
2729 ldo = simple_strtoul(argv[2], NULL, 10);
2730 else if (strncmp(argv[1], "buck", 4) == 0)
2731 buck = simple_strtoul(argv[2], NULL, 10);
2732 else if (strncmp(argv[1], "safeout", 7) == 0)
2733 safeout = simple_strtoul(argv[2], NULL, 10);
2737 if (strncmp(argv[3], "on", 2) == 0)
2739 else if (strncmp(argv[3], "off", 3) == 0)
2744 return pmic_ldo_control(buck, ldo, safeout, on);
2755 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2756 "PMIC LDO & BUCK control",
2757 "status - Display PMIC LDO & BUCK status\n"
2758 "pmic ldo num on/off - Turn on/off the LDO\n"
2759 "pmic buck num on/off - Turn on/off the BUCK\n"
2760 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2764 #ifdef CONFIG_CMD_DEVICE_POWER
2765 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2769 if (strncmp(argv[1], "cp", 2) == 0) {
2770 micro_usb_switch(1);
2771 pmic_ldo_control(0, 0, 2, 1);
2772 setenv("usb", "cp");
2773 } else if (strncmp(argv[1], "ap", 2) == 0) {
2774 micro_usb_switch(0);
2775 pmic_ldo_control(0, 0, 2, 0);
2776 setenv("usb", "ap");
2786 printf("USB Path is set to %s\n", getenv("usb"));
2792 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2794 "cp - switch to CP\n"
2795 "microusb ap - switch to AP\n"