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 (bardo_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)
460 gpio_direction_input(bank, 2);
461 gpio_direction_input(bank, 3);
462 gpio_direction_input(bank, 4);
463 gpio_direction_input(bank, mode3);
465 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
466 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
467 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
468 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
470 rev = gpio_get_value(bank, 2);
471 rev |= (gpio_get_value(bank, 3) << 1);
472 rev |= (gpio_get_value(bank, 4) << 2);
473 rev |= (gpio_get_value(bank, mode3) << 3);
478 static void check_hw_revision(void)
480 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
482 if (cpu_is_s5pc100()) {
483 struct s5pc100_gpio *gpio =
484 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
486 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
488 /* C100 TickerTape */
490 board = MACH_TICKERTAPE;
492 struct s5pc110_gpio *gpio =
493 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
499 * Note Check 'Aquila' board first
503 * LRA: Limo Real Aquila
504 * LUA: Limo Universal Aquila
509 * ADDR = 0xE0200000 + OFF
511 * OFF Universal BB LRA LUA OA TT SS CYP
512 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
513 * J2: 0x0284 0x01 0x10 0x00
514 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
515 * H3: 0x0C64 0x03 0x07 0x0F
516 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
517 * I: 0x0224 0x02 0x00 0x08
518 * MP03: 0x0324 0x9x 0xbx 0x9x
519 * MP05: 0x0364 0x80 0x88
523 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
525 board_rev |= J1_B2_BOARD;
527 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
528 gpio_direction_input(&gpio->gpio_j2, 6);
531 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
532 board_rev |= LIMO_UNIVERSAL_BOARD;
534 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
535 board_rev |= LIMO_REAL_BOARD;
537 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
538 board_rev |= MEDIA_BOARD;
540 /* set gpio to default value. */
541 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
542 gpio_direction_output(&gpio->gpio_j2, 6, 0);
545 /* Workaround: C110 Aquila Rev0.6 */
546 if (board_rev == 6) {
548 board_rev |= LIMO_REAL_BOARD;
551 /* C110 Aquila Bamboo */
552 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
554 board_rev |= BAMBOO_BOARD;
557 /* C110 TickerTape */
558 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
559 gpio_get_value(&gpio->gpio_d1, 1) == 0)
560 board = MACH_TICKERTAPE;
562 /* WMG160 - GPH3[0:4] = 0x00 */
563 if (board == MACH_TICKERTAPE) {
566 for (i = 0; i < 4; i++) {
567 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
578 /* C110 Geminus for rev0.0 */
579 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
580 gpio_direction_input(&gpio->gpio_j1, 2);
581 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
582 board = MACH_GEMINUS;
583 if ((board_rev & ~BOARD_MASK) == 3)
586 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
587 gpio_direction_output(&gpio->gpio_j1, 2, 0);
589 /* C110 Geminus for rev0.1 ~ */
590 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
591 gpio_direction_input(&gpio->gpio_j0, 6);
592 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
593 board = MACH_GEMINUS;
596 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
598 /* Kessler MP0_5[6] == 1 */
599 gpio_direction_input(&gpio->gpio_mp0_5, 6);
600 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
601 /* Cypress: Do this for cypress */
602 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
603 gpio_direction_input(&gpio->gpio_j2, 2);
604 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
605 board = MACH_CYPRESS;
606 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
608 board = MACH_KESSLER;
609 board_rev |= KESSLER_BOARD;
611 /* Neptune MP0_5[4] == 1 */
612 gpio_direction_input(&gpio->gpio_mp0_5, 4);
613 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
614 board_rev &= ~KESSLER_BOARD;
615 board_rev |= NEPTUNE_BOARD;
618 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
621 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
622 /* Kessler S1 board detection */
623 if (board == MACH_TICKERTAPE) {
624 board = MACH_KESSLER;
625 board_rev |= S1_BOARD;
630 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
634 if (board < MACH_PSEUDO_END) {
635 if (cpu_is_s5pc110())
636 gd->bd->bi_arch_number = C110_MACH_START + board;
638 gd->bd->bi_arch_number = C100_MACH_START + board;
640 gd->bd->bi_arch_number = board;
643 /* Architecture Common settings */
644 if (cpu_is_s5pc110()) {
645 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
647 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
649 setenv("updatek", "onenand erase 0x60000 0x300000; "
650 "onenand write 0x31008000 0x60000 0x300000");
654 static void show_hw_revision(void)
659 * Workaround for Rev 0.3 + CP Ver ES 3.1
662 if (board_is_limo_real()) {
664 /* default is Rev 0.4 */
670 if (machine_is_kessler() || machine_is_aquila())
671 board = gd->bd->bi_arch_number;
672 else if (cpu_is_s5pc110())
673 board = gd->bd->bi_arch_number - C110_MACH_START;
675 board = gd->bd->bi_arch_number - C100_MACH_START;
678 check_board_revision(board, board_rev);
680 /* Set CPU Revision */
681 if (machine_is_aquila()) {
682 if (board_is_limo_real()) {
683 if ((board_rev & 0xf) < 8)
684 s5pc1xx_set_cpu_rev(0);
686 } else if (machine_is_kessler()) {
687 s5pc1xx_set_cpu_rev(1);
688 } else if (machine_is_geminus()) {
689 if ((board_rev & 0xf) < 1)
690 s5pc1xx_set_cpu_rev(0);
691 } else if (machine_is_cypress()) {
692 s5pc1xx_set_cpu_rev(1);
694 s5pc1xx_set_cpu_rev(0);
697 empty_device_info_buffer();
698 dprintf("HW Revision:\t%x (%s%s) %s\n",
699 board_rev, get_board_name(board),
700 display_features(board, board_rev),
701 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
704 static void check_auto_burn(void)
706 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
707 unsigned int count = 0;
710 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
711 printf("Auto burning bootloader\n");
712 count += sprintf(buf + count, "run updateb; ");
714 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
715 printf("Auto burning kernel\n");
716 count += sprintf(buf + count, "run updatek; ");
720 count += sprintf(buf + count, "reset");
721 setenv("bootcmd", buf);
724 /* Clear the magic value */
725 writel(0xa5a55a5a, magic_base);
726 writel(0xa5a55a5a, magic_base + 0x4);
729 static void pmic_pin_init(void)
731 unsigned int reg, value;
733 if (cpu_is_s5pc100())
736 /* AP_PS_HOLD: XEINT_0: GPH0[0]
737 * Note: Don't use GPIO PS_HOLD it doesn't work
739 reg = S5PC110_PS_HOLD_CONTROL;
741 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
742 S5PC110_PS_HOLD_DATA_HIGH |
743 S5PC110_PS_HOLD_OUT_EN;
746 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
747 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
748 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
751 static void enable_ldos(void)
753 if (cpu_is_s5pc100())
756 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
757 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
760 static void enable_t_flash(void)
762 if (!(board_is_limo_universal() || board_is_limo_real()))
765 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
766 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
769 static void setup_limo_real_gpios(void)
771 if (!board_is_limo_real())
775 * Note: Please write GPIO alphabet order
777 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
778 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
781 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
782 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
784 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
785 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
787 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
788 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
789 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
792 static void setup_media_gpios(void)
794 if (!board_is_media())
798 * Note: Please write GPIO alphabet order
800 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
801 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
803 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
804 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
805 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
808 #define KBR3 (1 << 3)
809 #define KBR2 (1 << 2)
810 #define KBR1 (1 << 1)
811 #define KBR0 (1 << 0)
813 static void check_keypad(void)
815 unsigned int reg, value;
816 unsigned int col_num, row_num;
817 unsigned int col_mask;
818 unsigned int col_mask_shift;
819 unsigned int row_state[4];
821 unsigned int auto_download = 0;
823 if (machine_is_wmg160())
826 if (cpu_is_s5pc100()) {
827 struct s5pc100_gpio *gpio =
828 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
833 /* Set GPH2[2:0] to KP_COL[2:0] */
834 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
835 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
836 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
838 /* Set GPH3[2:0] to KP_ROW[2:0] */
839 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
840 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
841 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
843 reg = S5PC100_KEYPAD_BASE;
844 col_mask = S5PC1XX_KEYIFCOL_MASK;
847 if (board_is_limo_real() || board_is_limo_universal()) {
855 for (i = 0; i < row_num; i++) {
856 /* Set GPH3[3:0] to KP_ROW[3:0] */
857 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
858 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
861 for (i = 0; i < col_num; i++)
862 /* Set GPH2[3:0] to KP_COL[3:0] */
863 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
865 reg = S5PC110_KEYPAD_BASE;
866 col_mask = S5PC110_KEYIFCOLEN_MASK;
870 /* KEYIFCOL reg clear */
871 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
874 for (i = 0; i < col_num; i++) {
876 value &= ~(1 << i) << col_mask_shift;
878 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
881 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
882 row_state[i] = ~value & ((1 << row_num) - 1);
884 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
887 /* KEYIFCOL reg clear */
888 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
890 if (machine_is_aquila() || machine_is_kessler()) {
892 if (row_state[1] & 0x2)
894 if (board_is_neptune()) {
895 /* home & volume down */
896 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
899 /* cam full shot & volume down */
900 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
903 } else if (machine_is_geminus())
904 /* volume down & home */
905 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
909 setenv("bootcmd", "usbdown");
912 static void check_battery(int mode)
914 unsigned char val[2];
915 unsigned char addr = 0x36; /* max17040 fuel gauge */
917 i2c_set_bus_num(I2C_GPIO3);
919 if (machine_is_aquila()) {
922 } else if (machine_is_kessler()) {
923 i2c_set_bus_num(I2C_GPIO7);
924 } else if (machine_is_cypress()) {
925 i2c_set_bus_num(I2C_GPIO7);
926 } else if (machine_is_geminus()) {
928 i2c_set_bus_num(I2C_GPIO7);
932 if (i2c_probe(addr)) {
933 printf("Can't found max17040 fuel gauge\n");
937 /* mode 0: check mode / 1: enable mode */
941 i2c_write(addr, 0xfe, 1, val, 2);
943 i2c_read(addr, 0x04, 1, val, 1);
944 dprintf("battery:\t%d%%\n", val[0]);
945 battery_soc = val[0];
949 static void check_mhl(void)
951 unsigned char val[2];
952 unsigned char addr = 0x39; /* SIL9230 */
954 /* MHL Power enable */
955 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
956 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
958 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
959 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
961 /* 10ms required after reset */
965 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
967 i2c_set_bus_num(I2C_GPIO5);
970 if (i2c_probe(addr)) {
971 printf("Can't found MHL Chip\n");
977 * set to Normal operation
980 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
981 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
986 * 00 = MHL termination ON
987 * 11 = MHL termination OFF
990 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
991 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
994 static int max8998_probe(void)
996 unsigned char addr = 0xCC >> 1;
998 i2c_set_bus_num(I2C_PMIC);
1000 if (i2c_probe(addr)) {
1001 printf("Can't found max8998\n");
1008 #define CHARGER_ANIMATION_FRAME 6
1009 static void max8998_clear_interrupt(void)
1011 unsigned char addr, val[2];
1014 if (max8998_probe())
1017 i2c_read(addr, 0x00, 1, val, 1);
1018 i2c_read(addr, 0x01, 1, val, 1);
1019 i2c_read(addr, 0x02, 1, val, 1);
1020 i2c_read(addr, 0x03, 1, val, 1);
1023 static int max8998_power_key(void)
1025 unsigned char addr, val[2];
1028 if (max8998_probe())
1031 /* Accessing IRQ1 register */
1032 i2c_read(addr, 0x00, 1, val, 1);
1033 if (val[0] & (1 << 6))
1039 static int max8998_has_ext_power_source(void)
1041 unsigned char addr, val[2];
1044 if (max8998_probe())
1047 /* Accessing STATUS2 register */
1048 i2c_read(addr, 0x09, 1, val, 1);
1049 if (val[0] & (1 << 5))
1055 struct thermister_stat {
1060 static struct thermister_stat adc_to_temperature_data[] = {
1061 { .centigrade = -20, .adc = 1856, },
1062 { .centigrade = -15, .adc = 1799, },
1063 { .centigrade = -10, .adc = 1730, },
1064 { .centigrade = -5, .adc = 1649, },
1065 { .centigrade = 0, .adc = 1556, },
1066 { .centigrade = 5, .adc = 1454, },
1067 { .centigrade = 10, .adc = 1343, },
1068 { .centigrade = 15, .adc = 1227, },
1069 { .centigrade = 20, .adc = 1109, },
1070 { .centigrade = 25, .adc = 992, },
1071 { .centigrade = 30, .adc = 880, },
1072 { .centigrade = 35, .adc = 773, },
1073 { .centigrade = 40, .adc = 675, },
1074 { .centigrade = 45, .adc = 586, },
1075 { .centigrade = 50, .adc = 507, },
1076 { .centigrade = 55, .adc = 436, },
1077 { .centigrade = 58, .adc = 399, },
1078 { .centigrade = 63, .adc = 343, },
1079 { .centigrade = 65, .adc = 322, },
1083 #define USHRT_MAX 0xFFFFU
1085 static int adc_to_temperature_centigrade(unsigned short adc)
1089 /* low_*: Greatest Lower Bound,
1090 * * * * high_*: Smallest Upper Bound */
1091 int low_temp = 0, high_temp = 0;
1092 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1093 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1094 if (adc_to_temperature_data[i].adc <= adc &&
1095 adc_to_temperature_data[i].adc >= low_adc) {
1096 low_temp = adc_to_temperature_data[i].centigrade;
1097 low_adc = adc_to_temperature_data[i].adc;
1099 if (adc_to_temperature_data[i].adc >= adc &&
1100 adc_to_temperature_data[i].adc <= high_adc) {
1101 high_temp = adc_to_temperature_data[i].centigrade;
1102 high_adc = adc_to_temperature_data[i].adc;
1106 /* Linear approximation between cloest low and high,
1107 * which is the weighted average of the two. */
1109 /* The following equation is correct only when the two are different */
1110 if (low_adc == high_adc)
1112 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1113 return 20; /* The room temperature */
1116 if (high_adc == USHRT_MAX)
1119 approximation = low_temp * (adc - low_adc) +
1120 high_temp * (high_adc - adc);
1121 approximation /= high_adc - low_adc;
1123 return approximation;
1126 static unsigned short get_adc_value(int channel)
1128 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1129 unsigned short ret = 0;
1133 unsigned int loop = 0;
1135 if (machine_is_kessler())
1137 else if (machine_is_geminus())
1139 else if (machine_is_wmg160())
1141 else if (machine_is_cypress())
1143 else if (machine_is_tickertape())
1145 else if (machine_is_aquila())
1148 else if (machine_is_p1p2())
1152 sprintf(buf, "pmic ldo %d on", ldonum);
1153 run_command(buf, 0);
1155 writel(channel & 0xF, &adc->adcmux);
1156 writel((1 << 14) | (49 << 6), &adc->adccon);
1157 writel(1000 & 0xffff, &adc->adcdly);
1158 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1160 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1165 reg = readl(&adc->adccon);
1166 } while (!reg & (1 << 15) && loop++ < 1000);
1168 ret = readl(&adc->adcdat0) & 0xFFF;
1169 sprintf(buf, "pmic ldo %d off", ldonum);
1170 run_command(buf, 0);
1175 static int adc_get_average_ambient_temperature(void)
1177 if (machine_is_kessler()) {
1178 unsigned short min = USHRT_MAX;
1179 unsigned short max = 0;
1180 unsigned int sum = 0;
1181 unsigned int measured = 0;
1184 for (i = 0; i < 7; i++) {
1185 unsigned short measurement = get_adc_value(6);
1188 if (min > measurement)
1190 if (max < measurement)
1193 if (measured >= 3) {
1199 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1200 adc_to_temperature_centigrade(sum), sum);
1201 return adc_to_temperature_centigrade(sum);
1204 return 20; /* 20 Centigrade */
1207 enum temperature_level {
1215 static enum temperature_level temperature_check(void)
1217 int temp = adc_get_average_ambient_temperature();
1219 return _TEMP_TOO_LOW;
1221 return _TEMP_OK_LOW;
1223 return _TEMP_TOO_HIGH;
1225 return _TEMP_OK_HIGH;
1229 extern void lcd_display_clear(void);
1230 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1232 static void charger_en(int enable)
1238 unsigned char addr = 0xCC >> 1; /* max8998 */
1239 unsigned char val[2];
1241 if (max8998_probe())
1245 printf("Disable the charger.\n");
1246 i2c_read(addr, 0x0D, 1, val, 1);
1249 i2c_write(addr, 0x0D, 1, val, 1);
1251 i2c_read(addr, 0x0C, 1, val, 1);
1252 val[0] &= ~(0x7 << 0);
1253 val[0] &= ~(0x7 << 5);
1254 if (enable == 600) {
1255 val[0] |= 5; /* 600mA */
1256 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1257 } else { /* Assume 475 mA */
1259 val[0] |= 2; /* 475mA */
1260 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1262 i2c_write(addr, 0x0C, 1, val, 1);
1264 i2c_read(addr, 0x0D, 1, val, 1);
1266 i2c_write(addr, 0x0D, 1, val, 1);
1267 printf("Enable the charger @ %dmA\n", enable);
1271 void lcd_power_on(unsigned int onoff);
1272 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1273 extern int drv_lcd_init_resume (void);
1275 static void into_charge_mode(void)
1281 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1282 unsigned int reg, wakeup_stat;
1283 int charger_speed = 600;
1285 max8998_clear_interrupt();
1287 printf("Charge Mode\n");
1288 charger_en(charger_speed);
1290 #ifdef CONFIG_S5PC1XXFB
1293 /* TODO: write the image-text for the charger */
1295 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1296 if (level >= CHARGER_ANIMATION_FRAME)
1297 level = CHARGER_ANIMATION_FRAME - 1;
1299 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1300 bmp_addr[i] = (ulong)battery_charging_animation[i];
1302 lcd_display_clear();
1303 for (i = 0; i < 3; i++) {
1304 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1307 bmp = gunzip_bmp(bmp_addr[j], &len);
1308 lcd_display_bitmap((ulong)bmp, 140, 202);
1311 for (k = 0; k < 10; k++) {
1312 if (max8998_power_key()) {
1313 lcd_display_clear();
1314 goto restore_screen;
1315 } else if (!max8998_has_ext_power_source()) {
1316 lcd_display_clear();
1317 goto restore_screen;
1326 /* Disable the display to prevent flickering */
1327 /* TODO: how to reenable the display later? */
1331 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1332 unsigned int org, org_ip3;
1333 enum temperature_level previous_state = _TEMP_OK;
1335 empty_device_info_buffer();
1336 if (max8998_power_key())
1338 else if (!max8998_has_ext_power_source())
1341 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1342 org_ip3 = readl(0xE010046C);
1343 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1345 reg = org = readl(&rtc->rtccon);
1347 writel(reg, &rtc->rtccon);
1349 reg = readl(&rtc->rtccon);
1350 writel(reg | (1 << 3), &rtc->rtccon);
1352 writel(reg & ~(1 << 3), &rtc->rtccon);
1355 reg = readl(&rtc->rtccon);
1356 reg &= ~((1 << 8) | (0xF << 4));
1357 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1358 writel(reg, &rtc->rtccon);
1360 reg = 15 * 4 - 1; /* 15 sec */
1361 writel(reg, &rtc->ticcnt);
1363 /* EVT0: sleep 1, EVT1: sleep */
1364 if (cpu_is_s5pc110()) {
1365 char *name = "dummy";
1366 char *usage = "N/A";
1373 if (s5pc1xx_get_cpu_rev() == 0) {
1374 char *argv[] = {"1", "1"};
1375 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1377 char *argv[] = {"0", "0"};
1378 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1381 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1385 /* Check TEMP HIGH/LOW */
1386 switch (temperature_check()) {
1388 charger_en(charger_speed);
1389 previous_state = _TEMP_OK;
1393 previous_state = _TEMP_TOO_LOW;
1395 case _TEMP_TOO_HIGH:
1397 previous_state = _TEMP_TOO_HIGH;
1400 if (previous_state == _TEMP_TOO_LOW) {
1403 charger_en(charger_speed);
1404 previous_state = _TEMP_OK;
1408 if (previous_state == _TEMP_TOO_HIGH) {
1411 charger_en(charger_speed);
1412 previous_state = _TEMP_OK;
1417 writel(org, &rtc->rtccon);
1418 writel(org_ip3, 0xE010046C);
1420 } while (wakeup_stat == 0x04); /* RTC TICK */
1423 /* TODO: Reenable logo display (not working yet) */
1425 drv_lcd_init_resume();
1428 static int fsa9480_probe(void)
1430 unsigned char addr = 0x25;
1432 if (cpu_is_s5pc100())
1435 if (board_is_limo_real()) {
1436 if (hwrevision(0) || hwrevision(1))
1440 i2c_set_bus_num(I2C_PMIC);
1442 if (machine_is_kessler()) {
1443 i2c_set_bus_num(I2C_GPIO6);
1444 } else if (machine_is_cypress()) {
1445 i2c_set_bus_num(I2C_GPIO6);
1446 } else if (machine_is_geminus()) {
1448 i2c_set_bus_num(I2C_GPIO6);
1449 } else if (machine_is_wmg160()) {
1450 i2c_set_bus_num(I2C_GPIO6);
1453 if (i2c_probe(addr)) {
1454 printf("Can't found fsa9480\n");
1461 static void check_micro_usb(int intr)
1464 unsigned char val[2];
1465 static int started_charging_once = 0;
1468 if (fsa9480_probe())
1471 addr = 0x25; /* fsa9480 */
1473 /* Clear Interrupt */
1475 i2c_read(addr, 0x03, 1, val, 2);
1479 /* Read Device Type 1 */
1480 i2c_read(addr, 0x0a, 1, val, 1);
1482 #define FSA_DEV1_CHARGER (1 << 6)
1483 #define FSA_DEV1_UART (1 << 3)
1484 #define FSA_DEV1_USB (1 << 2)
1485 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1486 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1489 * If USB, use default 475mA
1490 * If Charger, use 600mA and go to charge mode
1492 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1493 started_charging_once = 1;
1495 /* If it's full, do not charge. */
1496 if (battery_soc < 100)
1500 } else if (val[0] & FSA_DEV1_USB) {
1501 if (battery_soc < 100)
1502 charger_en(475); /* enable charger and keep booting */
1507 /* If Factory Mode is Boot ON-USB, go to download mode */
1508 i2c_read(addr, 0x07, 1, val, 1);
1510 #define FSA_ADC_FAC_USB_OFF 0x18
1511 #define FSA_ADC_FAC_USB_ON 0x19
1512 #define FSA_ADC_FAC_UART 0x1d
1514 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1515 setenv("bootcmd", "usbdown");
1517 path = getenv("usb");
1519 if (!strncmp(path, "cp", 2))
1520 run_command("microusb cp", 0);
1523 static void micro_usb_switch(int path)
1526 unsigned char val[2];
1528 if (fsa9480_probe())
1531 addr = 0x25; /* fsa9480 */
1534 val[0] = 0x90; /* VAUDIO */
1536 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1538 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1540 i2c_read(addr, 0x2, 1, val, 1);
1541 val[0] &= ~(1 << 2); /* Manual switching */
1542 i2c_write(addr, 0x2, 1, val, 1);
1545 #define MAX8998_REG_ONOFF1 0x11
1546 #define MAX8998_REG_ONOFF2 0x12
1547 #define MAX8998_REG_ONOFF3 0x13
1548 #define MAX8998_REG_LDO7 0x21
1549 #define MAX8998_REG_LDO17 0x29
1551 #define MAX8998_LDO3 (1 << 2)
1553 #define MAX8998_LDO6 (1 << 7)
1554 #define MAX8998_LDO7 (1 << 6)
1555 #define MAX8998_LDO8 (1 << 5)
1556 #define MAX8998_LDO9 (1 << 4)
1557 #define MAX8998_LDO10 (1 << 3)
1558 #define MAX8998_LDO11 (1 << 2)
1559 #define MAX8998_LDO12 (1 << 1)
1560 #define MAX8998_LDO13 (1 << 0)
1562 #define MAX8998_LDO14 (1 << 7)
1563 #define MAX8998_LDO15 (1 << 6)
1564 #define MAX8998_LDO16 (1 << 5)
1565 #define MAX8998_LDO17 (1 << 4)
1568 static void init_pmic(void)
1571 unsigned char val[2];
1573 if (cpu_is_s5pc100())
1576 addr = 0xCC >> 1; /* max8998 */
1577 if (max8998_probe())
1581 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1582 val[0] &= ~MAX8998_LDO3;
1583 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1586 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1588 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1589 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1591 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1592 MAX8998_LDO12 | MAX8998_LDO13);
1594 if (machine_is_kessler())
1595 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1597 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1598 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1600 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1602 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1603 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1605 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1606 MAX8998_LDO16 | MAX8998_LDO17);
1608 if (machine_is_kessler())
1609 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1611 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1612 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1615 static void setup_power_down_mode_registers(void)
1617 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1618 struct s5pc1xx_gpio_bank *bank;
1619 struct gpio_powermode *p;
1621 struct gpio_external *ge;
1623 struct s5pc1xx_gpio_item *mr;
1627 if (cpu_is_s5pc100())
1630 /* Only Limo real and kessler supports worked for sleep currnet */
1631 if (machine_is_aquila()) {
1632 if (board_is_limo_real())
1636 } else if (machine_is_kessler()) {
1638 } else if (machine_is_geminus()) {
1644 if (machine_is_aquila()) {
1645 /* Aquila rev 0.8 or lower */
1646 p = aquila_powerdown_modes;
1647 ge = aquila_external_powerdown_modes;
1648 mr = aquila_mirror_powerdown_mode;
1649 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1650 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1651 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1652 } else if (machine_is_kessler()) {
1653 /* Aquila rev 0.9 */
1654 p = kessler_powerdown_modes;
1655 ge = kessler_external_powerdown_modes;
1656 mr = kessler_mirror_powerdown_mode;
1657 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1658 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1659 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1660 } else if (machine_is_geminus()) {
1661 if (hwrevision(1)) {
1662 /* Same as Aquila rev 0.9 */
1664 p = kessler_powerdown_modes;
1665 ge = kessler_external_powerdown_modes;
1666 mr = kessler_mirror_powerdown_mode;
1667 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1668 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1669 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1671 p = aquila_powerdown_modes;
1672 ge = aquila_external_powerdown_modes;
1673 mr = aquila_mirror_powerdown_mode;
1674 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1675 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1676 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1678 } else if (hwrevision(0)) {
1679 /* Same as Aquila rev 0.8 or lower */
1680 p = aquila_powerdown_modes;
1681 ge = aquila_external_powerdown_modes;
1682 mr = aquila_mirror_powerdown_mode;
1683 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1684 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1685 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1687 return; /* Not supported */
1691 bank = &gpio->gpio_a0;
1693 for (i = 0; i < n_p; i++, p++, bank++) {
1694 writel(p->conpdn, &bank->pdn_con);
1695 writel(p->pudpdn, &bank->pdn_pull);
1698 writel(0xff0022b0, (unsigned int *)0xF0000000);
1699 writel(0xff0022b0, (unsigned int *)0xF1400000);
1701 bank = &gpio->gpio_h0;
1703 for (i = 0; i < n_ge; i++) {
1704 writel(ge->con, &bank->con);
1705 writel(ge->dat, &bank->dat);
1706 writel(ge->pud, &bank->pull);
1712 for (i = 0; i < n_mr; i++) {
1713 unsigned int reg = readl(&mr->bank->pdn_con);
1714 reg &= ~(0x3 << (mr->number << 1));
1715 if (readl(&mr->bank->dat) & (1 << mr->number))
1716 reg |= 0x1 << (mr->number << 1);
1717 writel(reg, &mr->bank->pdn_con);
1723 #include "../../../drivers/video/s5p-spi.h"
1725 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1726 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1728 struct spi_platform_data spi_pd;
1730 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1732 void lcd_cfg_gpio(void)
1734 unsigned int i, f3_end = 4;
1736 for (i = 0; i < 8; i++) {
1737 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1738 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1739 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1740 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1741 /* pull-up/down disable */
1742 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1743 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1744 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1746 /* drive strength to max (24bit) */
1747 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1748 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1749 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1750 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1751 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1752 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1755 /* set DISPLAY_DE_B pin for dual rgb mode. */
1756 if (board_is_media())
1759 for (i = 0; i < f3_end; i++) {
1760 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1761 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1762 /* pull-up/down disable */
1763 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1764 /* drive strength to max (24bit) */
1765 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1766 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1768 /* display output path selection (only [1:0] valid) */
1769 writel(0x2, 0xE0107008);
1771 /* gpio pad configuration for LCD reset. */
1772 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1774 /* gpio pad configuration for LCD ON. */
1775 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1777 /* LCD_BACKLIGHT_EN */
1778 if (machine_is_geminus())
1779 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1780 if (board_is_neptune()) {
1781 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1782 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1786 * gpio pad configuration for
1787 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1789 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1790 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1791 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1792 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1794 if (machine_is_aquila() || machine_is_kessler()) {
1795 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1797 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1799 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1801 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1804 if (board_is_neptune())
1805 s6d16a0x_set_platform_data(&spi_pd);
1807 s6e63m0_set_platform_data(&spi_pd);
1808 if (board_is_media())
1813 if (machine_is_cypress()) {
1814 #if 0 /* universal cypress */
1816 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1821 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1823 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1825 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1827 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1828 #if 0 /* universal cypress */
1829 pd_cs.bank = &gpio_base->gpio_mp0_1;
1832 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1834 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1836 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1841 /* these data would be sent to s6e63m0 lcd panel driver. */
1842 s6e63m0_set_platform_data(&spi_pd);
1848 #define SWRST_REG 0x00
1849 #define LEDCON_REG 0x01
1850 #define LED_CUR_SET_REG 0x03
1851 #define LED_CUR_TR_REG 0x08
1854 #define NORMAL_MODE 0x01
1855 #define CUR_SET 0x63
1858 void backlight_on(unsigned int onoff)
1862 unsigned char val[2];
1863 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1866 if (machine_is_geminus())
1867 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1869 if (machine_is_geminus())
1870 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1873 if (machine_is_kessler() && board_is_neptune()) {
1874 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1877 i2c_set_bus_num(I2C_GPIO5);
1880 if (i2c_probe(addr)) {
1881 if (i2c_probe(addr)) {
1882 printf("Can't found s6d16a0x backlight i2c\n");
1887 i2c_write(addr, SWRST_REG, 1, val, 1);
1890 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1892 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1893 val[0] = NORMAL_MODE;
1894 i2c_write(addr, LEDCON_REG, 1, val, 1);
1899 void reset_lcd(void)
1901 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1903 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1904 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1905 if (machine_is_cypress())
1906 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1909 void lcd_power_on(unsigned int onoff)
1911 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1914 if (machine_is_aquila() || machine_is_geminus())
1915 gpio_set_value(&gpio->gpio_j1, 3, 1);
1917 if (machine_is_cypress())
1918 gpio_set_value(&gpio->gpio_g2, 2, 1);
1920 if (machine_is_kessler()) {
1922 unsigned char val[2];
1923 unsigned char val2[2];
1925 gpio_set_value(&gpio->gpio_j1, 3, 1);
1927 addr = 0xCC >> 1; /* max8998 */
1928 if (max8998_probe())
1931 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1932 val[0] &= ~(MAX8998_LDO17);
1933 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1934 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1936 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1937 val[0] |= MAX8998_LDO17;
1939 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1940 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1942 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1943 val[0] |= MAX8998_LDO7;
1945 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1946 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1949 if (machine_is_aquila() || machine_is_geminus())
1950 gpio_set_value(&gpio->gpio_j1, 3, 0);
1952 if (machine_is_cypress())
1953 gpio_set_value(&gpio->gpio_g2, 2, 0);
1955 if (machine_is_kessler()) {
1957 unsigned char val[2];
1959 gpio_set_value(&gpio->gpio_j1, 3, 0);
1961 addr = 0xCC >> 1; /* max8998 */
1962 if (max8998_probe())
1965 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1966 val[0] &= ~(MAX8998_LDO7);
1967 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1968 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1970 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1971 val[0] &= ~(MAX8998_LDO17);
1972 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1973 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1978 extern void s6e63m0_cfg_ldo(void);
1979 extern void s6e63m0_enable_ldo(unsigned int onoff);
1980 extern void s6d16a0x_cfg_ldo(void);
1981 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1983 int s5p_no_lcd_support(void)
1985 if (machine_is_wmg160())
1990 void init_panel_info(vidinfo_t *vid)
1992 vid->cfg_gpio = NULL;
1993 vid->reset_lcd = NULL;
1994 vid->backlight_on = NULL;
1995 vid->lcd_power_on = NULL;
1997 vid->cfg_ldo = NULL;
1998 vid->enable_ldo = NULL;
2000 vid->init_delay = 0;
2001 vid->reset_delay = 0;
2002 vid->power_on_delay = 0;
2007 vid->vl_width = 480;
2008 vid->vl_height = 800;
2010 vid->dual_lcd_enabled = 0;
2012 if (board_is_media()) {
2015 vid->vl_width = 960;
2016 vid->vl_height = 800;
2018 /* enable dual lcd mode. */
2019 vid->dual_lcd_enabled = 1;
2022 vid->vl_clkp = CONFIG_SYS_HIGH;
2023 vid->vl_hsp = CONFIG_SYS_LOW;
2024 vid->vl_vsp = CONFIG_SYS_LOW;
2025 vid->vl_dp = CONFIG_SYS_HIGH;
2028 /* S6E63M0 LCD Panel */
2037 if (machine_is_aquila() || machine_is_kessler()
2038 || machine_is_cypress()) {
2039 vid->cfg_gpio = lcd_cfg_gpio;
2040 vid->reset_lcd = reset_lcd;
2041 vid->backlight_on = backlight_on;
2042 vid->lcd_power_on = lcd_power_on;
2043 vid->cfg_ldo = s6e63m0_cfg_ldo;
2044 vid->enable_ldo = s6e63m0_enable_ldo;
2046 vid->init_delay = 25000;
2047 vid->reset_delay = 120000;
2050 if (board_is_neptune()) {
2054 vid->vl_width = 320;
2055 vid->vl_height = 480;
2057 vid->vl_clkp = CONFIG_SYS_HIGH;
2058 vid->vl_hsp = CONFIG_SYS_HIGH;
2059 vid->vl_vsp = CONFIG_SYS_HIGH;
2060 vid->vl_dp = CONFIG_SYS_LOW;
2063 /* disable dual lcd mode. */
2064 vid->dual_lcd_enabled = 0;
2066 /* S6D16A0X LCD Panel */
2075 vid->cfg_gpio = lcd_cfg_gpio;
2076 vid->backlight_on = backlight_on;
2077 vid->lcd_power_on = lcd_power_on;
2078 vid->reset_lcd = reset_lcd;
2079 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2080 vid->enable_ldo = s6d16a0x_enable_ldo;
2082 vid->init_delay = 10000;
2083 vid->power_on_delay = 10000;
2084 vid->reset_delay = 1000;
2088 if (machine_is_geminus()) {
2092 vid->vl_width = 1024,
2093 vid->vl_height = 600,
2094 vid->vl_clkp = CONFIG_SYS_LOW,
2095 vid->vl_hsp = CONFIG_SYS_HIGH,
2096 vid->vl_vsp = CONFIG_SYS_HIGH,
2097 vid->vl_dp = CONFIG_SYS_LOW,
2108 vid->cfg_gpio = lcd_cfg_gpio;
2109 vid->reset_lcd = reset_lcd;
2110 vid->backlight_on = backlight_on;
2111 vid->lcd_power_on = lcd_power_on;
2117 vid->vl_width = 480,
2118 vid->vl_height = 800,
2119 vid->vl_clkp = CONFIG_SYS_HIGH,
2120 vid->vl_hsp = CONFIG_SYS_LOW,
2121 vid->vl_vsp = CONFIG_SYS_LOW,
2122 vid->vl_dp = CONFIG_SYS_HIGH,
2138 vid->vl_width = 1024,
2139 vid->vl_height = 600,
2140 vid->vl_clkp = CONFIG_SYS_HIGH,
2141 vid->vl_hsp = CONFIG_SYS_HIGH,
2142 vid->vl_vsp = CONFIG_SYS_HIGH,
2143 vid->vl_dp = CONFIG_SYS_LOW,
2146 /* AMS701KA AMOLED Panel. */
2158 static void setup_meminfo(void)
2160 char meminfo[64] = {0, };
2161 int count = 0, size, real;
2163 size = gd->bd->bi_dram[0].size >> 20;
2164 count += sprintf(meminfo + count, "mem=%dM", size);
2166 /* Each Chip Select can't exceed the 256MiB */
2167 size = gd->bd->bi_dram[1].size >> 20;
2168 real = min(size, 256);
2169 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2170 real, (unsigned int)gd->bd->bi_dram[1].start);
2174 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2175 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2178 setenv("meminfo", meminfo);
2181 int misc_init_r(void)
2184 /* It should be located at first */
2187 if (machine_is_aquila() || machine_is_kessler()) {
2188 if (board_is_neptune())
2189 setenv("lcdinfo", "lcd=s6d16a0x");
2190 else if (board_is_media())
2191 setenv("lcdinfo", "lcd=s6e63m0");
2193 setenv("lcdinfo", "lcd=s6e63m0");
2195 if (machine_is_geminus())
2196 setenv("lcdinfo", "lcd=lms480jc01");
2197 if (machine_is_cypress())
2198 setenv("lcdinfo", "lcd=s6e63m0");
2204 /* Set proper PMIC pins */
2207 /* Check auto burning */
2210 /* To power up I2C2 */
2213 /* Enable T-Flash at Limo Real or Limo Universal */
2216 /* Setup Limo Real board GPIOs */
2217 setup_limo_real_gpios();
2219 /* Setup Media board GPIOs */
2220 setup_media_gpios();
2222 /* To usbdown automatically */
2228 #ifdef CONFIG_S5PC1XXFB
2229 display_device_info();
2232 setup_power_down_mode_registers();
2234 /* check max17040 */
2244 int board_init(void)
2246 /* Set Initial global variables */
2247 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2249 gd->bd->bi_arch_number = MACH_AQUILA;
2250 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2252 /* Check H/W Revision */
2253 check_hw_revision();
2260 unsigned int base, memconfig0, size;
2261 unsigned int memconfig1, sz = 0;
2263 if (cpu_is_s5pc100()) {
2264 /* In mem setup, we swap the bank. So below size is correct */
2265 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2266 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2267 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2270 /* In S5PC110, we can't swap the DMC0/1 */
2271 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2272 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2274 base = S5PC110_DMC1_BASE;
2275 /* DMC configuration */
2276 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2277 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2279 size = (memconfig0 >> 16) & 0xFF;
2280 size = ((unsigned char) ~size) + 1;
2283 * (0x07 + 1) * 16 = 128 MiB
2284 * (0x0f + 1) * 16 = 256 MiB
2289 * Aquila Rev0.5 4G3G1G
2290 * Aquila Rev0.8 4G3G1G
2291 * Aquila Rev0.9 4G3G1G
2293 if (machine_is_aquila() || machine_is_kessler())
2294 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2295 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2297 sz = (memconfig1 >> 16) & 0xFF;
2298 sz = ((unsigned char) ~sz) + 1;
2304 * bi_dram[1].size contains all DMC1 memory size
2306 gd->bd->bi_dram[1].size = (size + sz) << 20;
2311 /* Used for sleep test */
2312 static unsigned char saved_val[4][2];
2313 void board_sleep_init_late(void)
2315 /* CODEC_LDO_EN: GPF3[4] */
2316 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2317 /* CODEC_XTAL_EN: GPH3[2] */
2318 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2320 /* MMC T_FLASH off */
2321 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2323 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2324 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2325 /* MHL_ON for REV02 or higher */
2326 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2329 void board_sleep_init(void)
2332 unsigned char val[2];
2335 if (max8998_probe())
2338 if (machine_is_kessler()) {
2340 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2341 saved_val[0][0] = val[0];
2342 saved_val[0][1] = val[1];
2343 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2344 (1 << 1) | (1 << 0));
2345 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2346 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2349 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2350 saved_val[1][0] = val[0];
2351 saved_val[1][1] = val[1];
2352 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2353 (1 << 2) | (1 << 1) | (1 << 0));
2355 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2356 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2359 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2360 saved_val[2][0] = val[0];
2361 saved_val[2][1] = val[1];
2362 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2363 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2364 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2367 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2368 saved_val[3][0] = val[0];
2369 saved_val[3][1] = val[1];
2370 val[0] &= ~((1 << 6) | (1 << 4));
2371 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2372 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2374 printf("Turned off regulators with Kessler setting."
2375 " Preparing to sleep. [%s:%d]\n",
2376 __FILE__, __LINE__);
2377 } else { /* Default */
2379 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2380 saved_val[0][0] = val[0];
2381 saved_val[0][1] = val[1];
2382 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2383 (1 << 1) | (1 << 0));
2384 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2385 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2388 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2389 saved_val[1][0] = val[0];
2390 saved_val[1][1] = val[1];
2391 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2392 (1 << 2) | (1 << 1) | (1 << 0));
2394 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2395 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2398 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2399 saved_val[2][0] = val[0];
2400 saved_val[2][1] = val[1];
2401 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2402 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2403 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2406 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2407 saved_val[3][0] = val[0];
2408 saved_val[3][1] = val[1];
2409 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2410 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2411 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2413 printf("Turned off regulators with default(Aquila) setting."
2414 " Preparing to sleep. [%s:%d]\n",
2415 __FILE__, __LINE__);
2419 void board_sleep_resume(void)
2422 unsigned char val[2];
2427 if (max8998_probe())
2431 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2432 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2434 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2435 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2437 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2438 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2440 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2441 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2442 printf("Waked up.\n");
2444 /* check max17040 */
2451 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2453 static int s5pc1xx_phy_control(int on)
2457 if (on && !status) {
2458 #ifdef CONFIG_CMD_PMIC
2459 run_command("pmic ldo 3 on", 0);
2462 if (board_is_limo_universal() ||
2463 board_is_limo_real() ||
2465 /* check usb path */
2466 if (board_is_limo_real() && !hwrevision(6))
2470 if (machine_is_tickertape())
2471 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2472 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2474 /* USB Path to AP */
2475 micro_usb_switch(0);
2477 } else if (!on && status) {
2478 #ifdef CONFIG_CMD_PMIC
2479 run_command("pmic ldo 3 off", 0);
2488 struct s3c_plat_otg_data s5pc110_otg_data = {
2489 .phy_control = s5pc1xx_phy_control,
2490 .regs_phy = S5PC110_PHY_BASE,
2491 .regs_otg = S5PC110_OTG_BASE,
2494 int board_eth_init(bd_t *bis)
2498 if (cpu_is_s5pc100())
2501 s3c_udc_probe(&s5pc110_otg_data);
2502 if (usb_eth_initialize(bis) >= 0)
2508 #ifdef CONFIG_CMD_USBDOWN
2509 int usb_board_init(void)
2511 #ifdef CONFIG_CMD_PMIC
2512 run_command("pmic ldo 3 on", 0);
2515 if (cpu_is_s5pc100()) {
2516 #ifdef CONFIG_HARD_I2C
2517 uchar val[2] = {0,};
2520 if (i2c_read(0x66, 0, 1, val, 2)) {
2521 printf("i2c_read error\n");
2528 if (i2c_write(0x66, 0, 1, val, 2)) {
2529 printf("i2c_write error\n");
2532 i2c_read(0x66, 0, 1, val, 2);
2538 if (board_is_limo_universal() ||
2539 board_is_limo_real() ||
2541 /* check usb path */
2542 if (board_is_limo_real() && !hwrevision(6))
2546 if (machine_is_tickertape())
2547 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2548 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2550 /* USB Path to AP */
2551 micro_usb_switch(0);
2557 #ifdef CONFIG_GENERIC_MMC
2558 int s5p_no_mmc_support(void)
2560 if (machine_is_wmg160())
2565 int board_mmc_init(bd_t *bis)
2569 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2572 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2573 if (machine_is_kessler())
2574 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2576 if (machine_is_wmg160())
2579 /* MMC0 Clock source = SCLKMPLL */
2580 reg = readl(&clk->src4);
2583 writel(reg, &clk->src4);
2585 reg = readl(&clk->div4);
2588 /* set div value near 50MHz */
2589 clock = get_pll_clk(MPLL) / 1000000;
2590 for (i = 0; i < 0xf; i++) {
2591 if ((clock / (i + 1)) <= 50) {
2597 writel(reg, &clk->div4);
2603 * GPG0[2] SD_0_CDn -> Not used
2604 * GPG0[3:6] SD_0_DATA[0:3]
2606 for (i = 0; i < 7; i++) {
2609 /* GPG0[0:6] special function 2 */
2610 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2611 /* GPG0[0:6] pull disable */
2612 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2613 /* GPG0[0:6] drv 4x */
2614 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2617 if (machine_is_geminus()) {
2618 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2619 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2622 return s5pc1xx_mmc_init(0);
2626 #ifdef CONFIG_CMD_PMIC
2627 static int pmic_status(void)
2629 unsigned char addr, val[2];
2634 if (max8998_probe())
2638 i2c_read(addr, reg, 1, val, 1);
2639 for (i = 7; i >= 4; i--)
2640 printf("BUCK%d %s\n", 7 - i + 1,
2641 val[0] & (1 << i) ? "on" : "off");
2643 printf("LDO%d %s\n", 5 - i,
2644 val[0] & (1 << i) ? "on" : "off");
2646 i2c_read(addr, reg, 1, val, 1);
2647 for (i = 7; i >= 0; i--)
2648 printf("LDO%d %s\n", 7 - i + 6,
2649 val[0] & (1 << i) ? "on" : "off");
2651 i2c_read(addr, reg, 1, val, 1);
2652 for (i = 7; i >= 4; i--)
2653 printf("LDO%d %s\n", 7 - i + 14,
2654 val[0] & (1 << i) ? "on" : "off");
2657 i2c_read(addr, reg, 1, val, 1);
2658 for (i = 7; i >= 6; i--)
2659 printf("SAFEOUT%d %s\n", 7 - i + 1,
2660 val[0] & (1 << i) ? "on" : "off");
2664 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2666 unsigned char addr, val[2];
2667 unsigned int reg, shift;
2675 } else if (ldo <= 13) {
2678 } else if (ldo <= 17) {
2680 shift = 17 - ldo + 4;
2687 shift = 4 - buck + 4;
2688 } else if (safeout) {
2692 shift = 8 - safeout;
2698 if (max8998_probe())
2701 i2c_read(addr, reg, 1, val, 1);
2703 val[0] |= (1 << shift);
2705 val[0] &= ~(1 << shift);
2706 i2c_write(addr, reg, 1, val, 1);
2707 i2c_read(addr, reg, 1, val, 1);
2710 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2711 val[0] & (1 << shift) ? "on" : "off");
2713 printf("buck %d value 0x%x, %s\n", buck, val[0],
2714 val[0] & (1 << shift) ? "on" : "off");
2716 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2717 val[0] & (1 << shift) ? "on" : "off");
2722 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2724 int buck = 0, ldo = 0, safeout = 0, on = -1;
2728 if (strncmp(argv[1], "status", 6) == 0)
2729 return pmic_status();
2732 if (strncmp(argv[1], "ldo", 3) == 0)
2733 ldo = simple_strtoul(argv[2], NULL, 10);
2734 else if (strncmp(argv[1], "buck", 4) == 0)
2735 buck = simple_strtoul(argv[2], NULL, 10);
2736 else if (strncmp(argv[1], "safeout", 7) == 0)
2737 safeout = simple_strtoul(argv[2], NULL, 10);
2741 if (strncmp(argv[3], "on", 2) == 0)
2743 else if (strncmp(argv[3], "off", 3) == 0)
2748 return pmic_ldo_control(buck, ldo, safeout, on);
2759 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2760 "PMIC LDO & BUCK control",
2761 "status - Display PMIC LDO & BUCK status\n"
2762 "pmic ldo num on/off - Turn on/off the LDO\n"
2763 "pmic buck num on/off - Turn on/off the BUCK\n"
2764 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2768 #ifdef CONFIG_CMD_DEVICE_POWER
2769 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2773 if (strncmp(argv[1], "cp", 2) == 0) {
2774 micro_usb_switch(1);
2775 pmic_ldo_control(0, 0, 2, 1);
2776 setenv("usb", "cp");
2777 } else if (strncmp(argv[1], "ap", 2) == 0) {
2778 micro_usb_switch(0);
2779 pmic_ldo_control(0, 0, 2, 0);
2780 setenv("usb", "ap");
2790 printf("USB Path is set to %s\n", getenv("usb"));
2796 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2798 "cp - switch to CP\n"
2799 "microusb ap - switch to AP\n"