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/errno.h>
42 #include <bmp_layout.h>
44 #include "animation_frames.h"
45 #include "gpio_setting.h"
47 DECLARE_GLOBAL_DATA_PTR;
49 #define C100_MACH_START 3000
50 #define C110_MACH_START 3100
52 static unsigned int board_rev;
53 static unsigned int battery_soc;
54 static struct s5pc110_gpio *s5pc110_gpio;
71 static struct i2c_gpio_bus_data i2c_2 = {
81 static struct i2c_gpio_bus_data i2c_gpio3 = {
91 static struct i2c_gpio_bus_data i2c_pmic = {
101 static struct i2c_gpio_bus_data i2c_gpio5 = {
111 static struct i2c_gpio_bus_data i2c_gpio6 = {
117 * i2c gpio7 - kessler
121 static struct i2c_gpio_bus_data i2c_gpio7 = {
127 * i2c gpio7 - cypress
131 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
141 static struct i2c_gpio_bus_data i2c_gpio10 = {
147 static struct i2c_gpio_bus i2c_gpio[] = {
165 u32 get_board_rev(void)
170 static int hwrevision(int rev)
172 return (board_rev & 0xf) == rev;
179 MACH_P1P2, /* Don't remove it */
190 #define SPLIT_SCREEN_FEATURE 0x100
192 /* board is MACH_AQUILA and board is like below. */
193 #define J1_B2_BOARD 0x0200
194 #define LIMO_UNIVERSAL_BOARD 0x0400
195 #define LIMO_REAL_BOARD 0x0800
196 #define MEDIA_BOARD 0x1000
197 #define BAMBOO_BOARD 0x2000
199 /* board is MACH_KESSLER and board is like below */
200 #define ARIES_BOARD 0x4000
201 #define NEPTUNE_BOARD 0x8000
203 #define BOARD_MASK 0xFF00
205 static int c110_machine_id(void)
207 return gd->bd->bi_arch_number - C110_MACH_START;
210 static int machine_is_aquila(void)
212 return (gd->bd->bi_arch_number == MACH_AQUILA);
215 static int machine_is_tickertape(void)
217 return c110_machine_id() == MACH_TICKERTAPE;
220 static int machine_is_geminus(void)
222 return c110_machine_id() == MACH_GEMINUS;
225 static int machine_is_cypress(void)
227 return c110_machine_id() == MACH_CYPRESS;
230 static int board_is_limo_universal(void)
232 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
235 static int board_is_limo_real(void)
237 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
240 static int board_is_media(void)
242 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
245 static int board_is_j1b2(void)
247 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
251 static int machine_is_kessler(void)
253 return gd->bd->bi_arch_number == MACH_KESSLER;
256 static int board_is_neptune(void)
258 return machine_is_kessler() && (board_rev & NEPTUNE_BOARD);
262 static int machine_is_wmg160(void)
264 return c110_machine_id() == MACH_WMG160;
267 static void enable_battery(void);
269 void i2c_init_board(void)
271 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
274 if (cpu_is_s5pc100())
277 num_bus = ARRAY_SIZE(i2c_gpio);
279 if (machine_is_aquila()) {
280 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
281 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
282 } else if (machine_is_kessler()) {
283 i2c_gpio[I2C_GPIO7].bus->gpio_base =
284 (unsigned int)&gpio->gpio_mp0_5;
285 } else if (machine_is_cypress()) {
286 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
287 i2c_gpio[I2C_GPIO7].bus->gpio_base =
288 (unsigned int)&gpio->gpio_mp0_5;
290 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
293 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
294 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
295 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
296 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
297 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
299 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
301 /* Reset on max17040 early */
302 if (battery_soc == 0)
306 #ifdef CONFIG_MISC_INIT_R
307 #define DEV_INFO_LEN 512
308 static char device_info[DEV_INFO_LEN];
309 static int display_info;
311 static void dprintf(const char *fmt, ...)
318 i = vsprintf(buf, fmt, args);
323 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
324 puts("Flushing device info...\n");
328 strcat(device_info, buf);
332 #ifdef CONFIG_S5PC1XXFB
333 static void display_device_info(void)
340 set_font_color(FONT_WHITE);
341 fb_printf(device_info);
344 memset(device_info, 0x0, DEV_INFO_LEN);
346 udelay(5 * 1000 * 1000);
350 static const char *board_name[] = {
354 "P1P2", /* Don't remove it */
367 static char feature_buffer[32];
369 static char *display_features(int board, int board_rev)
372 char *buf = feature_buffer;
375 if (board == MACH_AQUILA) {
376 if (board_rev & SPLIT_SCREEN_FEATURE)
377 name = "SplitScreen";
378 if (board_rev & J1_B2_BOARD)
380 /* Limo Real or Universal */
381 if (board_rev & LIMO_REAL_BOARD)
383 else if (board_rev & LIMO_UNIVERSAL_BOARD)
384 name = "Limo Universal";
385 if (board_rev & MEDIA_BOARD)
387 if (board_rev & BAMBOO_BOARD)
389 } else if (board == MACH_KESSLER) {
390 if (board_rev & ARIES_BOARD)
392 if (board_rev & NEPTUNE_BOARD)
396 count += sprintf(buf + count, " - %s", name);
401 static char *get_board_name(int board)
403 if (board == MACH_AQUILA)
405 else if (board == MACH_KESSLER)
407 else if (board == MACH_WMG160)
409 return (char *) board_name[board];
412 static void check_board_revision(int board, int rev)
414 if (board == MACH_AQUILA) {
415 /* Limo Real or Universal */
416 if (rev & LIMO_UNIVERSAL_BOARD)
417 board_rev &= ~J1_B2_BOARD;
418 if (rev & LIMO_REAL_BOARD)
419 board_rev &= ~(J1_B2_BOARD |
420 LIMO_UNIVERSAL_BOARD);
421 if (rev & MEDIA_BOARD)
422 board_rev &= ~(J1_B2_BOARD |
423 LIMO_UNIVERSAL_BOARD);
424 if (rev & BAMBOO_BOARD)
425 board_rev &= ~(J1_B2_BOARD |
426 LIMO_UNIVERSAL_BOARD |
429 } else if (board == MACH_KESSLER) {
430 if (rev & ARIES_BOARD)
431 board_rev &= ~(J1_B2_BOARD |
432 LIMO_UNIVERSAL_BOARD);
433 if (rev & NEPTUNE_BOARD)
434 board_rev &= ~(J1_B2_BOARD |
435 LIMO_UNIVERSAL_BOARD);
437 board_rev &= ~BOARD_MASK;
440 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
448 gpio_direction_input(bank, 2);
449 gpio_direction_input(bank, 3);
450 gpio_direction_input(bank, 4);
451 gpio_direction_input(bank, mode3);
453 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
454 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
455 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
456 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
458 rev = gpio_get_value(bank, 2);
459 rev |= (gpio_get_value(bank, 3) << 1);
460 rev |= (gpio_get_value(bank, 4) << 2);
461 rev |= (gpio_get_value(bank, mode3) << 3);
466 static void check_hw_revision(void)
468 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
470 if (cpu_is_s5pc100()) {
471 struct s5pc100_gpio *gpio =
472 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
474 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
476 /* C100 TickerTape */
478 board = MACH_TICKERTAPE;
480 struct s5pc110_gpio *gpio =
481 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
487 * Note Check 'Aquila' board first
491 * LRA: Limo Real Aquila
492 * LUA: Limo Universal Aquila
497 * ADDR = 0xE0200000 + OFF
499 * OFF Universal BB LRA LUA OA TT SS CYP
500 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
501 * J2: 0x0284 0x01 0x10 0x00
502 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
503 * H3: 0x0C64 0x03 0x07 0x0F
504 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
505 * I: 0x0224 0x02 0x00 0x08
506 * MP03: 0x0324 0x9x 0xbx 0x9x
507 * MP05: 0x0364 0x80 0x88
511 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
513 board_rev |= J1_B2_BOARD;
515 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
516 gpio_direction_input(&gpio->gpio_j2, 6);
519 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
520 board_rev |= LIMO_UNIVERSAL_BOARD;
522 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
523 board_rev |= LIMO_REAL_BOARD;
525 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
526 board_rev |= MEDIA_BOARD;
528 /* set gpio to default value. */
529 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
530 gpio_direction_output(&gpio->gpio_j2, 6, 0);
533 /* Workaround: C110 Aquila Rev0.6 */
534 if (board_rev == 6) {
536 board_rev |= LIMO_REAL_BOARD;
539 /* C110 Aquila Bamboo */
540 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
542 board_rev |= BAMBOO_BOARD;
545 /* C110 TickerTape */
546 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
547 gpio_get_value(&gpio->gpio_d1, 1) == 0)
548 board = MACH_TICKERTAPE;
550 /* WMG160 - GPH3[0:4] = 0x00 */
551 if (board == MACH_TICKERTAPE) {
554 for (i = 0; i < 4; i++) {
555 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
566 /* C110 Geminus for rev0.0 */
567 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
568 gpio_direction_input(&gpio->gpio_j1, 2);
569 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
570 board = MACH_GEMINUS;
571 if ((board_rev & ~BOARD_MASK) == 3)
574 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
575 gpio_direction_output(&gpio->gpio_j1, 2, 0);
577 /* C110 Geminus for rev0.1 ~ */
578 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
579 gpio_direction_input(&gpio->gpio_j0, 6);
580 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
581 board = MACH_GEMINUS;
584 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
586 /* Kessler MP0_5[6] == 1 */
587 gpio_direction_input(&gpio->gpio_mp0_5, 6);
588 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
589 /* Cypress: Do this for cypress */
590 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
591 gpio_direction_input(&gpio->gpio_j2, 2);
592 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
593 board = MACH_CYPRESS;
594 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
596 board = MACH_KESSLER;
597 board_rev |= ARIES_BOARD;
599 /* Neptune MP0_5[4] == 1 */
600 gpio_direction_input(&gpio->gpio_mp0_5, 4);
601 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
602 board_rev &= ~ARIES_BOARD;
603 board_rev |= NEPTUNE_BOARD;
606 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
609 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
611 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
615 if (board == MACH_AQUILA)
616 gd->bd->bi_arch_number = MACH_AQUILA;
617 else if (board == MACH_KESSLER)
618 gd->bd->bi_arch_number = MACH_KESSLER;
619 else if (cpu_is_s5pc110())
620 gd->bd->bi_arch_number = C110_MACH_START + board;
622 gd->bd->bi_arch_number = C100_MACH_START + board;
624 /* Architecture Common settings */
625 if (cpu_is_s5pc110()) {
626 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
628 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
630 setenv("updatek", "onenand erase 0x60000 0x300000; "
631 "onenand write 0x31008000 0x60000 0x300000");
635 static void show_hw_revision(void)
640 * Workaround for Rev 0.3 + CP Ver ES 3.1
643 if (board_is_limo_real()) {
645 /* default is Rev 0.4 */
651 if (machine_is_aquila())
653 else if (machine_is_kessler())
654 board = MACH_KESSLER;
655 else if (cpu_is_s5pc110())
656 board = gd->bd->bi_arch_number - C110_MACH_START;
658 board = gd->bd->bi_arch_number - C100_MACH_START;
660 check_board_revision(board, board_rev);
662 /* Set CPU Revision */
663 if (machine_is_aquila()) {
664 if (board_is_limo_real()) {
665 if ((board_rev & 0xf) < 8)
666 s5pc1xx_set_cpu_rev(0);
668 } else if (machine_is_kessler())
669 s5pc1xx_set_cpu_rev(1);
670 else if (machine_is_geminus()) {
671 if ((board_rev & 0xf) < 1)
672 s5pc1xx_set_cpu_rev(0);
673 } else if (machine_is_cypress()) {
674 s5pc1xx_set_cpu_rev(1);
676 s5pc1xx_set_cpu_rev(0);
679 dprintf("HW Revision:\t%x (%s%s) %s\n",
680 board_rev, get_board_name(board),
681 display_features(board, board_rev),
682 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
685 static void check_auto_burn(void)
687 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
688 unsigned int count = 0;
691 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
692 printf("Auto burning bootloader\n");
693 count += sprintf(buf + count, "run updateb; ");
695 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
696 printf("Auto burning kernel\n");
697 count += sprintf(buf + count, "run updatek; ");
701 count += sprintf(buf + count, "reset");
702 setenv("bootcmd", buf);
705 /* Clear the magic value */
706 writel(0xa5a55a5a, magic_base);
707 writel(0xa5a55a5a, magic_base + 0x4);
710 static void pmic_pin_init(void)
712 unsigned int reg, value;
714 if (cpu_is_s5pc100())
717 /* AP_PS_HOLD: XEINT_0: GPH0[0]
718 * Note: Don't use GPIO PS_HOLD it doesn't work
720 reg = S5PC110_PS_HOLD_CONTROL;
722 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
723 S5PC110_PS_HOLD_DATA_HIGH |
724 S5PC110_PS_HOLD_OUT_EN;
727 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
728 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
729 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
732 static void enable_ldos(void)
734 if (cpu_is_s5pc100())
737 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
738 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
741 static void enable_t_flash(void)
743 if (!(board_is_limo_universal() || board_is_limo_real()))
746 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
747 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
750 static void setup_limo_real_gpios(void)
752 if (!board_is_limo_real())
756 * Note: Please write GPIO alphabet order
758 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
759 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
762 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
763 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
765 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
766 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
768 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
769 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
770 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
773 static void setup_media_gpios(void)
775 if (!board_is_media())
779 * Note: Please write GPIO alphabet order
781 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
782 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
784 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
785 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
786 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
789 #define KBR3 (1 << 3)
790 #define KBR2 (1 << 2)
791 #define KBR1 (1 << 1)
792 #define KBR0 (1 << 0)
794 static void check_keypad(void)
796 unsigned int reg, value;
797 unsigned int col_num, row_num;
798 unsigned int col_mask;
799 unsigned int col_mask_shift;
800 unsigned int row_state[4];
802 unsigned int auto_download = 0;
804 if (machine_is_wmg160())
807 if (cpu_is_s5pc100()) {
808 struct s5pc100_gpio *gpio =
809 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
814 /* Set GPH2[2:0] to KP_COL[2:0] */
815 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
816 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
817 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
819 /* Set GPH3[2:0] to KP_ROW[2:0] */
820 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
821 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
822 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
824 reg = S5PC100_KEYPAD_BASE;
825 col_mask = S5PC1XX_KEYIFCOL_MASK;
828 if (board_is_limo_real() || board_is_limo_universal()) {
836 for (i = 0; i < row_num; i++) {
837 /* Set GPH3[3:0] to KP_ROW[3:0] */
838 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
839 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
842 for (i = 0; i < col_num; i++)
843 /* Set GPH2[3:0] to KP_COL[3:0] */
844 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
846 reg = S5PC110_KEYPAD_BASE;
847 col_mask = S5PC110_KEYIFCOLEN_MASK;
851 /* KEYIFCOL reg clear */
852 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
855 for (i = 0; i < col_num; i++) {
857 value &= ~(1 << i) << col_mask_shift;
859 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
862 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
863 row_state[i] = ~value & ((1 << row_num) - 1);
865 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
868 /* KEYIFCOL reg clear */
869 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
871 if (machine_is_aquila() || machine_is_kessler()) {
872 /* cam full shot & volume down */
873 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
876 else if ((row_state[1] & 0x2))
878 } else if (machine_is_geminus())
879 /* volume down & home */
880 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
884 setenv("bootcmd", "usbdown");
887 static void enable_battery(void)
889 unsigned char val[2];
890 unsigned char addr = 0x36; /* max17040 fuel gauge */
892 i2c_set_bus_num(I2C_GPIO3);
894 if (machine_is_aquila()) {
897 } else if (machine_is_kessler())
898 i2c_set_bus_num(I2C_GPIO7);
899 else if (machine_is_tickertape()) {
901 } else if (machine_is_cypress()) {
902 i2c_set_bus_num(I2C_GPIO7);
903 } else if (machine_is_geminus()) {
905 i2c_set_bus_num(I2C_GPIO7);
908 if (i2c_probe(addr)) {
909 printf("Can't found max17040 fuel gauge\n");
915 i2c_write(addr, 0xfe, 1, val, 2);
918 static void check_battery(void)
920 unsigned char val[2];
921 unsigned char addr = 0x36; /* max17040 fuel gauge */
923 i2c_set_bus_num(I2C_GPIO3);
925 if (machine_is_aquila()) {
928 } else if (machine_is_kessler())
929 i2c_set_bus_num(I2C_GPIO7);
930 else if (machine_is_cypress()) {
931 i2c_set_bus_num(I2C_GPIO7);
932 } else if (machine_is_geminus()) {
934 i2c_set_bus_num(I2C_GPIO7);
938 if (i2c_probe(addr)) {
939 printf("Can't found max17040 fuel gauge\n");
943 i2c_read(addr, 0x04, 1, val, 1);
945 dprintf("battery:\t%d%%\n", val[0]);
947 battery_soc = val[0];
950 static void check_mhl(void)
952 unsigned char val[2];
953 unsigned char addr = 0x39; /* SIL9230 */
955 /* MHL Power enable */
956 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
957 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
959 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
960 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
962 /* 10ms required after reset */
966 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
968 i2c_set_bus_num(I2C_GPIO5);
971 if (i2c_probe(addr)) {
972 printf("Can't found MHL Chip\n");
978 * set to Normal operation
981 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
982 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
987 * 00 = MHL termination ON
988 * 11 = MHL termination OFF
991 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
992 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
995 #define CHARGER_ANIMATION_FRAME 6
996 static int max8998_power_key(void)
998 unsigned char addr, val[2];
999 i2c_set_bus_num(I2C_PMIC);
1001 if (i2c_probe(addr)) {
1002 printf("Can't found max8998\n");
1006 /* Accessing IRQ1 register */
1007 i2c_read(addr, 0x00, 1, val, 1);
1008 if (val[0] & (1 << 6))
1014 static int max8998_has_ext_power_source(void)
1016 unsigned char addr, val[2];
1017 i2c_set_bus_num(I2C_PMIC);
1019 if (i2c_probe(addr)) {
1020 printf("Can't found max8998\n");
1024 /* Accessing STATUS2 register */
1025 i2c_read(addr, 0x09, 1, val, 1);
1026 if (val[0] & (1 << 5))
1032 extern void lcd_display_clear(void);
1033 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1035 static void into_charge_mode(void)
1037 unsigned char addr = 0xCC >> 1; /* max8998 */;
1038 unsigned char val[2];
1043 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1044 unsigned int reg, wakeup_stat;
1046 i2c_set_bus_num(I2C_PMIC);
1048 if (i2c_probe(addr)) {
1049 printf("Can't found max8998\n");
1053 printf("Charge Mode\n");
1055 i2c_read(addr, 0x0C, 1, val, 1);
1056 val[0] &= ~(0x7 << 0);
1057 val[0] &= ~(0x7 << 5);
1058 val[0] |= 5; /* 600mA */
1059 val[0] |= (3 << 5); /* Stop at 150mA(25%) */
1060 i2c_write(addr, 0x0C, 1, val, 1);
1062 #ifdef CONFIG_S5PC1XXFB
1065 /* TODO: write the image-text for the charger */
1067 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1068 if (level >= CHARGER_ANIMATION_FRAME)
1069 level = CHARGER_ANIMATION_FRAME - 1;
1071 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1072 bmp_addr[i] = (ulong)battery_charging_animation[i];
1074 lcd_display_clear();
1075 for (i = 0; i < 3; i++) {
1076 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1079 bmp = gunzip_bmp(bmp_addr[j], &len);
1080 lcd_display_bitmap((ulong) bmp, 140, 202);
1083 for (k = 0; k < 10; k++)
1084 if (max8998_power_key()) {
1085 lcd_display_clear();
1087 } else if (!max8998_has_ext_power_source()) {
1088 lcd_display_clear();
1098 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1099 unsigned int org, org_ip3, org_tcfg0;
1101 if (max8998_power_key()) {
1102 lcd_display_clear();
1104 } else if (!max8998_has_ext_power_source()) {
1105 lcd_display_clear();
1109 /* Enable RTC at CLKGATE IP3 */
1110 org_ip3 = readl(0xE010046C);
1111 writel(org_ip3 | (1 << 15) | (1 << 16), 0xE010046C);
1113 reg = org = readl(&rtc->rtccon);
1115 writel(reg, &rtc->rtccon);
1117 reg = readl(&rtc->rtccon);
1118 writel(reg | (1 << 3), &rtc->rtccon);
1120 writel(reg & ~(1 << 3), &rtc->rtccon);
1123 reg = readl(&rtc->rtccon);
1124 reg &= ~( (1 << 8) | (0xF << 4));
1125 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1126 writel(reg, &rtc->rtccon);
1128 reg = 15 * 4 - 1; /* 15 sec */
1129 writel(reg, &rtc->ticcnt);
1131 /* TODO: turn LCD/FB off for sure */
1133 /* EVT0: sleep 1, EVT1: sleep */
1134 if (cpu_is_s5pc110()) {
1135 char *name = "dummy";
1136 char *usage = "N/A";
1143 if (s5pc1xx_get_cpu_rev() == 0) {
1144 char *argv[] = {"1", "1"};
1145 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1147 char *argv[] = {"0", "0"};
1148 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1151 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1155 writel(org, &rtc->rtccon);
1156 writel(org_tcfg0, 0xE2600000);
1157 writel(org_ip3, 0xE010046C);
1159 /* TODO: 1. TEMP HIGH/LOW: stop charging and wake it up */
1160 /* TODO: 2. BATT FULL: stop charing and wake it up */
1162 } while (wakeup_stat == 0x04); /* RTC TICK */
1164 /* TODO: Reenable logo display */
1167 static void check_micro_usb(int intr)
1170 unsigned char val[2];
1171 static int started_charging_once = 0;
1174 if (cpu_is_s5pc100())
1177 if (board_is_limo_real()) {
1178 if (hwrevision(0) || hwrevision(1))
1182 i2c_set_bus_num(I2C_PMIC);
1184 if (machine_is_kessler())
1185 i2c_set_bus_num(I2C_GPIO6);
1186 else if (machine_is_cypress()) {
1187 i2c_set_bus_num(I2C_GPIO6);
1188 } else if (machine_is_geminus()) {
1190 i2c_set_bus_num(I2C_GPIO6);
1191 } else if (machine_is_wmg160())
1192 i2c_set_bus_num(I2C_GPIO6);
1194 addr = 0x25; /* fsa9480 */
1195 if (i2c_probe(addr)) {
1196 printf("Can't found fsa9480\n");
1200 /* Clear Interrupt */
1202 i2c_read(addr, 0x03, 1, val, 2);
1206 /* Read Device Type 1 */
1207 i2c_read(addr, 0x0a, 1, val, 1);
1209 #define FSA_DEV1_CHARGER (1 << 6)
1210 #define FSA_DEV1_UART (1 << 3)
1211 #define FSA_DEV1_USB (1 << 2)
1212 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1213 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1216 * If USB, use default 475mA
1217 * If Charger, use 600mA and go to charge mode
1219 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1220 started_charging_once = 1;
1224 /* If Factory Mode is Boot ON-USB, go to download mode */
1225 i2c_read(addr, 0x07, 1, val, 1);
1227 #define FSA_ADC_FAC_USB_OFF 0x18
1228 #define FSA_ADC_FAC_USB_ON 0x19
1229 #define FSA_ADC_FAC_UART 0x1d
1231 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1232 setenv("bootcmd", "usbdown");
1234 path = getenv("usb");
1236 if (!strncmp(path, "cp", 2))
1237 run_command("microusb cp", 0);
1240 static void micro_usb_switch(int path)
1243 unsigned char val[2];
1245 i2c_set_bus_num(I2C_PMIC);
1247 if (machine_is_kessler())
1248 i2c_set_bus_num(I2C_GPIO6);
1249 else if (machine_is_cypress()) {
1250 i2c_set_bus_num(I2C_GPIO6);
1251 } else if (machine_is_geminus()) {
1253 i2c_set_bus_num(I2C_GPIO6);
1254 } else if (machine_is_wmg160()) {
1255 i2c_set_bus_num(I2C_GPIO6);
1259 addr = 0x25; /* fsa9480 */
1260 if (i2c_probe(addr)) {
1261 printf("Can't found fsa9480\n");
1266 val[0] = 0x90; /* VAUDIO */
1268 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1270 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1272 i2c_read(addr, 0x2, 1, val, 1);
1273 val[0] &= ~(1 << 2); /* Manual switching */
1274 i2c_write(addr, 0x2, 1, val, 1);
1277 #define MAX8998_REG_ONOFF1 0x11
1278 #define MAX8998_REG_ONOFF2 0x12
1279 #define MAX8998_REG_ONOFF3 0x13
1280 #define MAX8998_REG_LDO7 0x21
1281 #define MAX8998_REG_LDO17 0x29
1283 #define MAX8998_LDO3 (1 << 2)
1285 #define MAX8998_LDO6 (1 << 7)
1286 #define MAX8998_LDO7 (1 << 6)
1287 #define MAX8998_LDO8 (1 << 5)
1288 #define MAX8998_LDO9 (1 << 4)
1289 #define MAX8998_LDO10 (1 << 3)
1290 #define MAX8998_LDO11 (1 << 2)
1291 #define MAX8998_LDO12 (1 << 1)
1292 #define MAX8998_LDO13 (1 << 0)
1294 #define MAX8998_LDO14 (1 << 7)
1295 #define MAX8998_LDO15 (1 << 6)
1296 #define MAX8998_LDO16 (1 << 5)
1297 #define MAX8998_LDO17 (1 << 4)
1300 static void init_pmic(void)
1303 unsigned char val[2];
1305 if (cpu_is_s5pc100())
1308 i2c_set_bus_num(I2C_PMIC);
1310 addr = 0xCC >> 1; /* max8998 */
1311 if (i2c_probe(addr)) {
1312 if (i2c_probe(addr)) {
1313 printf("Can't found max8998\n");
1319 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1320 val[0] &= ~MAX8998_LDO3;
1321 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1324 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1326 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1327 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1329 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1330 MAX8998_LDO12 | MAX8998_LDO13);
1332 if (machine_is_kessler())
1333 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1335 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1336 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1338 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1340 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1341 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1343 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1344 MAX8998_LDO16 | MAX8998_LDO17);
1346 if (machine_is_kessler())
1347 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1349 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1350 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1353 static void setup_power_down_mode_registers(void)
1355 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1356 struct s5pc1xx_gpio_bank *bank;
1357 struct gpio_powermode *p;
1359 struct gpio_external *ge;
1361 struct s5pc1xx_gpio_item *mr;
1365 if (cpu_is_s5pc100())
1368 /* Only Limo real and kessler supports worked for sleep currnet */
1369 if (machine_is_aquila()) {
1370 if (board_is_limo_real())
1374 } else if (machine_is_kessler()) {
1376 } else if (machine_is_geminus()) {
1381 if (machine_is_aquila()) {
1382 /* Aquila rev 0.8 or lower */
1383 p = aquila_powerdown_modes;
1384 ge = aquila_external_powerdown_modes;
1385 mr = aquila_mirror_powerdown_mode;
1386 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1387 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1388 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1389 } else if (machine_is_kessler()) {
1390 /* Aquila rev 0.9 */
1391 p = kessler_powerdown_modes;
1392 ge = kessler_external_powerdown_modes;
1393 mr = kessler_mirror_powerdown_mode;
1394 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1395 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1396 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1397 } else if (machine_is_geminus()) {
1398 if (hwrevision(1)) {
1399 /* Same as Aquila rev 0.9 */
1401 p = kessler_powerdown_modes;
1402 ge = kessler_external_powerdown_modes;
1403 mr = kessler_mirror_powerdown_mode;
1404 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1405 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1406 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1408 p = aquila_powerdown_modes;
1409 ge = aquila_external_powerdown_modes;
1410 mr = aquila_mirror_powerdown_mode;
1411 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1412 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1413 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1415 } else if (hwrevision(0)) {
1416 /* Same as Aquila rev 0.8 or lower */
1417 p = aquila_powerdown_modes;
1418 ge = aquila_external_powerdown_modes;
1419 mr = aquila_mirror_powerdown_mode;
1420 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1421 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1422 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1424 return; /* Not supported */
1428 bank = &gpio->gpio_a0;
1430 for (i = 0; i < n_p; i++, p++, bank++) {
1431 writel(p->conpdn, &bank->pdn_con);
1432 writel(p->pudpdn, &bank->pdn_pull);
1435 writel(0xff0022b0, (unsigned int *)0xF0000000);
1436 writel(0xff0022b0, (unsigned int *)0xF1400000);
1438 bank = &gpio->gpio_h0;
1440 for (i = 0; i < n_ge; i++) {
1441 writel(ge->con, &bank->con);
1442 writel(ge->dat, &bank->dat);
1443 writel(ge->pud, &bank->pull);
1449 for (i = 0; i < n_mr; i++) {
1450 unsigned int reg = readl(&mr->bank->pdn_con);
1451 reg &= ~(1 << mr->number);
1452 if (readl(&mr->bank->dat) & (1 << mr->number))
1453 reg |= 1 << mr->number;
1454 writel(reg, &mr->bank->pdn_con);
1460 #include "../../../drivers/video/s5p-spi.h"
1462 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1463 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1465 struct spi_platform_data spi_pd;
1467 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1469 void lcd_cfg_gpio(void)
1471 unsigned int i, f3_end = 4;
1473 for (i = 0; i < 8; i++) {
1474 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1475 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1476 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1477 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1478 /* pull-up/down disable */
1479 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1480 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1481 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1483 /* drive strength to max (24bit) */
1484 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1485 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1486 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1487 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1488 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1489 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1492 /* set DISPLAY_DE_B pin for dual rgb mode. */
1493 if (board_is_media())
1496 for (i = 0; i < f3_end; i++) {
1497 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1498 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1499 /* pull-up/down disable */
1500 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1501 /* drive strength to max (24bit) */
1502 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1503 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1505 /* display output path selection (only [1:0] valid) */
1506 writel(0x2, 0xE0107008);
1508 /* gpio pad configuration for LCD reset. */
1509 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1511 /* gpio pad configuration for LCD ON. */
1512 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1514 /* LCD_BACKLIGHT_EN */
1515 if (machine_is_geminus())
1516 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1519 * gpio pad configuration for
1520 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1522 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1523 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1524 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1525 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1527 if (machine_is_aquila() || machine_is_kessler()) {
1528 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1530 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1532 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1534 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1537 if (board_is_neptune())
1538 s6d16a0x_set_platform_data(&spi_pd);
1540 s6e63m0_set_platform_data(&spi_pd);
1541 if (board_is_media())
1546 if (machine_is_cypress()) {
1547 #if 0 /* universal cypress */
1549 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1552 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1554 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1556 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1558 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1560 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1561 #if 0 /* universal cypress */
1562 pd_cs.bank = &gpio_base->gpio_mp0_1;
1565 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1567 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1569 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1574 /* these data would be sent to s6e63m0 lcd panel driver. */
1575 s6e63m0_set_platform_data(&spi_pd);
1581 void backlight_on(unsigned int onoff)
1583 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1586 if (machine_is_geminus())
1587 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1589 if (machine_is_geminus())
1590 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1594 void reset_lcd(void)
1596 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1598 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1599 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1600 if (machine_is_cypress())
1601 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1604 void lcd_power_on(unsigned int onoff)
1606 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1609 if (machine_is_aquila() || machine_is_geminus())
1610 gpio_set_value(&gpio->gpio_j1, 3, 1);
1612 if (machine_is_cypress())
1613 gpio_set_value(&gpio->gpio_g2, 2, 1);
1615 if (machine_is_kessler()) {
1617 unsigned char val[2];
1618 unsigned char val2[2];
1620 gpio_set_value(&gpio->gpio_j1, 3, 1);
1622 i2c_set_bus_num(I2C_PMIC);
1623 addr = 0xCC >> 1; /* max8998 */
1624 if (i2c_probe(addr)) {
1625 printf("Can't found max8998\n");
1628 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1629 val[0] &= ~(MAX8998_LDO17);
1630 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1631 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1633 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1634 val[0] |= MAX8998_LDO17;
1636 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1637 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1639 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1640 val[0] |= MAX8998_LDO7;
1642 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1643 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1646 if (machine_is_aquila() || machine_is_geminus())
1647 gpio_set_value(&gpio->gpio_j1, 3, 0);
1649 if (machine_is_cypress())
1650 gpio_set_value(&gpio->gpio_g2, 2, 0);
1652 if (machine_is_kessler()) {
1654 unsigned char val[2];
1656 i2c_set_bus_num(I2C_PMIC);
1657 addr = 0xCC >> 1; /* max8998 */
1658 if (i2c_probe(addr)) {
1659 printf("Can't found max8998\n");
1663 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1664 val[0] &= ~(1 << 7);
1665 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1666 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1668 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1669 val[0] &= ~MAX8998_LDO17;
1670 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1671 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1676 extern void s6e63m0_cfg_ldo(void);
1677 extern void s6e63m0_enable_ldo(unsigned int onoff);
1678 extern void s6d16a0x_cfg_ldo(void);
1679 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1681 int s5p_no_lcd_support(void)
1683 if (machine_is_wmg160())
1688 void init_panel_info(vidinfo_t *vid)
1690 vid->cfg_gpio = NULL;
1691 vid->reset_lcd = NULL;
1692 vid->backlight_on = NULL;
1693 vid->lcd_power_on = NULL;
1695 vid->cfg_ldo = NULL;
1696 vid->enable_ldo = NULL;
1698 vid->init_delay = 0;
1699 vid->reset_delay = 0;
1700 vid->power_on_delay = 0;
1705 vid->vl_width = 480;
1706 vid->vl_height = 800;
1708 vid->dual_lcd_enabled = 0;
1710 if (board_is_media()) {
1713 vid->vl_width = 960;
1714 vid->vl_height = 800;
1716 /* enable dual lcd mode. */
1717 vid->dual_lcd_enabled = 1;
1720 vid->vl_clkp = CONFIG_SYS_HIGH;
1721 vid->vl_hsp = CONFIG_SYS_LOW;
1722 vid->vl_vsp = CONFIG_SYS_LOW;
1723 vid->vl_dp = CONFIG_SYS_HIGH;
1726 /* S6E63M0 LCD Panel */
1735 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
1736 vid->cfg_gpio = lcd_cfg_gpio;
1737 vid->reset_lcd = reset_lcd;
1738 vid->backlight_on = backlight_on;
1739 vid->lcd_power_on = lcd_power_on;
1740 vid->cfg_ldo = s6e63m0_cfg_ldo;
1741 vid->enable_ldo = s6e63m0_enable_ldo;
1743 vid->init_delay = 25000;
1744 vid->reset_delay = 120000;
1747 if (board_is_neptune()) {
1751 vid->vl_width = 320;
1752 vid->vl_height = 480;
1754 vid->vl_clkp = CONFIG_SYS_HIGH;
1755 vid->vl_hsp = CONFIG_SYS_HIGH;
1756 vid->vl_vsp = CONFIG_SYS_HIGH;
1757 vid->vl_dp = CONFIG_SYS_LOW;
1760 /* disable dual lcd mode. */
1761 vid->dual_lcd_enabled = 0;
1763 /* S6D16A0X LCD Panel */
1772 vid->cfg_gpio = lcd_cfg_gpio;
1773 vid->backlight_on = NULL;
1774 vid->lcd_power_on = lcd_power_on;
1775 vid->reset_lcd = reset_lcd;
1776 vid->cfg_ldo = s6d16a0x_cfg_ldo;
1777 vid->enable_ldo = s6d16a0x_enable_ldo;
1779 vid->init_delay = 10000;
1780 vid->power_on_delay = 10000;
1781 vid->reset_delay = 1000;
1785 if (machine_is_geminus()) {
1789 vid->vl_width = 1024,
1790 vid->vl_height = 600,
1791 vid->vl_clkp = CONFIG_SYS_LOW,
1792 vid->vl_hsp = CONFIG_SYS_HIGH,
1793 vid->vl_vsp = CONFIG_SYS_HIGH,
1794 vid->vl_dp = CONFIG_SYS_LOW,
1805 vid->cfg_gpio = lcd_cfg_gpio;
1806 vid->reset_lcd = reset_lcd;
1807 vid->backlight_on = backlight_on;
1808 vid->lcd_power_on = lcd_power_on;
1814 vid->vl_width = 480,
1815 vid->vl_height = 800,
1816 vid->vl_clkp = CONFIG_SYS_HIGH,
1817 vid->vl_hsp = CONFIG_SYS_LOW,
1818 vid->vl_vsp = CONFIG_SYS_LOW,
1819 vid->vl_dp = CONFIG_SYS_HIGH,
1835 vid->vl_width = 1024,
1836 vid->vl_height = 600,
1837 vid->vl_clkp = CONFIG_SYS_HIGH,
1838 vid->vl_hsp = CONFIG_SYS_HIGH,
1839 vid->vl_vsp = CONFIG_SYS_HIGH,
1840 vid->vl_dp = CONFIG_SYS_LOW,
1843 /* AMS701KA AMOLED Panel. */
1855 static void setup_meminfo(void)
1857 char meminfo[64] = {0, };
1858 int count = 0, size, real;
1860 size = gd->bd->bi_dram[0].size >> 20;
1861 count += sprintf(meminfo + count, "mem=%dM", size);
1863 /* Each Chip Select can't exceed the 256MiB */
1864 size = gd->bd->bi_dram[1].size >> 20;
1865 real = min(size, 256);
1866 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1867 real, (unsigned int)gd->bd->bi_dram[1].start);
1871 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1872 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1875 setenv("meminfo", meminfo);
1878 int misc_init_r(void)
1881 /* It should be located at first */
1884 if (machine_is_aquila() || machine_is_kessler()) {
1885 if (board_is_neptune())
1886 setenv("lcdinfo", "lcd=s6d16a0x");
1887 else if (board_is_media())
1888 setenv("lcdinfo", "lcd=s6e63m0");
1890 setenv("lcdinfo", "lcd=s6e63m0");
1892 if (machine_is_geminus())
1893 setenv("lcdinfo", "lcd=lms480jc01");
1894 if (machine_is_cypress())
1895 setenv("lcdinfo", "lcd=s6e63m0");
1901 /* Set proper PMIC pins */
1904 /* Check auto burning */
1907 /* To power up I2C2 */
1910 /* Enable T-Flash at Limo Real or Limo Universal */
1913 /* Setup Limo Real board GPIOs */
1914 setup_limo_real_gpios();
1916 /* Setup Media board GPIOs */
1917 setup_media_gpios();
1919 /* To usbdown automatically */
1925 #ifdef CONFIG_S5PC1XXFB
1926 display_device_info();
1929 setup_power_down_mode_registers();
1931 /* check max17040 */
1941 int board_init(void)
1943 /* Set Initial global variables */
1944 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1946 gd->bd->bi_arch_number = MACH_AQUILA;
1947 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1949 /* Check H/W Revision */
1950 check_hw_revision();
1957 unsigned int base, memconfig0, size;
1958 unsigned int memconfig1, sz = 0;
1960 if (cpu_is_s5pc100()) {
1961 /* In mem setup, we swap the bank. So below size is correct */
1962 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1963 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1964 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1967 /* In S5PC110, we can't swap the DMC0/1 */
1968 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1969 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1971 base = S5PC110_DMC1_BASE;
1972 /* DMC configuration */
1973 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1974 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1976 size = (memconfig0 >> 16) & 0xFF;
1977 size = ((unsigned char) ~size) + 1;
1980 * (0x07 + 1) * 16 = 128 MiB
1981 * (0x0f + 1) * 16 = 256 MiB
1986 * Aquila Rev0.5 4G3G1G
1987 * Aquila Rev0.8 4G3G1G
1988 * Aquila Rev0.9 4G3G1G
1990 if (machine_is_aquila() || machine_is_kessler())
1991 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
1992 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
1994 sz = (memconfig1 >> 16) & 0xFF;
1995 sz = ((unsigned char) ~sz) + 1;
2001 * bi_dram[1].size contains all DMC1 memory size
2003 gd->bd->bi_dram[1].size = (size + sz) << 20;
2008 /* Used for sleep test */
2009 static unsigned char saved_val[4][2];
2010 void board_sleep_init_late(void)
2012 /* CODEC_LDO_EN: GPF3[4] */
2013 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2014 /* CODEC_XTAL_EN: GPH3[2] */
2015 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2017 /* MMC T_FLASH off */
2018 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2020 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2021 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2022 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2026 void board_sleep_init(void)
2029 unsigned char val[2];
2031 i2c_set_bus_num(I2C_PMIC);
2033 if (i2c_probe(addr)) {
2034 printf("Can't find max8998\n");
2038 if (machine_is_kessler()) {
2041 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2042 saved_val[0][0] = val[0];
2043 saved_val[0][1] = val[1];
2044 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2045 (1 << 1) | (1 << 0));
2046 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2047 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2049 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2050 saved_val[1][0] = val[0];
2051 saved_val[1][1] = val[1];
2052 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2053 (1 << 2) | (1 << 1) | (1 << 0));
2055 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2056 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2058 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2059 saved_val[2][0] = val[0];
2060 saved_val[2][1] = val[1];
2061 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2062 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2063 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2065 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2066 saved_val[3][0] = val[0];
2067 saved_val[3][1] = val[1];
2068 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2069 //i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2070 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2071 printf("Turned off regulators with Kessler setting."
2072 " Preparing to sleep. [%s:%d]\n",
2073 __FILE__, __LINE__);
2074 } else { /* Default */
2077 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2078 saved_val[0][0] = val[0];
2079 saved_val[0][1] = val[1];
2080 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2081 (1 << 1) | (1 << 0));
2082 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2083 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2085 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2086 saved_val[1][0] = val[0];
2087 saved_val[1][1] = val[1];
2088 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2089 (1 << 2) | (1 << 1) | (1 << 0));
2091 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2092 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2094 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2095 saved_val[2][0] = val[0];
2096 saved_val[2][1] = val[1];
2097 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2098 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2099 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2101 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2102 saved_val[3][0] = val[0];
2103 saved_val[3][1] = val[1];
2104 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2105 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2106 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2107 printf("Turned off regulators with default(Aquila) setting."
2108 " Preparing to sleep. [%s:%d]\n",
2109 __FILE__, __LINE__);
2113 void board_sleep_resume(void)
2116 unsigned char val[2];
2120 i2c_set_bus_num(I2C_PMIC);
2122 if (i2c_probe(addr)) {
2123 printf("Can't find max8998\n");
2128 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2129 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2131 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2132 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2134 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2135 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2137 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2138 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2139 printf("Waked up.\n");
2141 /* check max17040 */
2148 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2150 static int s5pc1xx_phy_control(int on)
2154 if (on && !status) {
2155 // printf("turning USB power on\n");
2156 #ifdef CONFIG_CMD_PMIC
2157 run_command("pmic ldo 3 on", 0);
2160 if (board_is_limo_universal() ||
2161 board_is_limo_real() ||
2163 /* check usb path */
2164 if (board_is_limo_real() && !hwrevision(6))
2168 if (machine_is_tickertape())
2169 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2170 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2172 /* USB Path to AP */
2173 micro_usb_switch(0);
2175 } else if (!on && status) {
2176 // printf("turning USB power off\n");
2177 #ifdef CONFIG_CMD_PMIC
2178 run_command("pmic ldo 3 off", 0);
2185 struct s3c_plat_otg_data s5pc110_otg_data = {
2186 .phy_control = s5pc1xx_phy_control,
2187 .regs_phy = S5PC110_PHY_BASE,
2188 .regs_otg = S5PC110_OTG_BASE,
2191 int board_eth_init(bd_t *bis)
2195 if (cpu_is_s5pc100())
2198 s3c_udc_probe(&s5pc110_otg_data);
2199 if (usb_eth_initialize(bis) >= 0)
2205 #ifdef CONFIG_CMD_USBDOWN
2206 int usb_board_init(void)
2208 #ifdef CONFIG_CMD_PMIC
2209 run_command("pmic ldo 3 on", 0);
2212 if (cpu_is_s5pc100()) {
2213 #ifdef CONFIG_HARD_I2C
2214 uchar val[2] = {0,};
2217 if (i2c_read(0x66, 0, 1, val, 2)) {
2218 printf("i2c_read error\n");
2225 if (i2c_write(0x66, 0, 1, val, 2)) {
2226 printf("i2c_write error\n");
2229 i2c_read(0x66, 0, 1, val, 2);
2235 if (board_is_limo_universal() ||
2236 board_is_limo_real() ||
2238 /* check usb path */
2239 if (board_is_limo_real() && !hwrevision(6))
2243 if (machine_is_tickertape())
2244 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2245 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2247 /* USB Path to AP */
2248 micro_usb_switch(0);
2254 #ifdef CONFIG_GENERIC_MMC
2255 int s5p_no_mmc_support(void)
2257 if (machine_is_wmg160())
2262 int board_mmc_init(bd_t *bis)
2266 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2269 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2270 if (machine_is_kessler())
2271 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2273 if (machine_is_wmg160())
2276 /* MMC0 Clock source = SCLKMPLL */
2277 reg = readl(&clk->src4);
2280 writel(reg, &clk->src4);
2282 reg = readl(&clk->div4);
2285 /* set div value near 50MHz */
2286 clock = get_pll_clk(MPLL) / 1000000;
2287 for (i = 0; i < 0xf; i++) {
2288 if ((clock / (i + 1)) <= 50) {
2294 writel(reg, &clk->div4);
2300 * GPG0[2] SD_0_CDn -> Not used
2301 * GPG0[3:6] SD_0_DATA[0:3]
2303 for (i = 0; i < 7; i++) {
2306 /* GPG0[0:6] special function 2 */
2307 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2308 /* GPG0[0:6] pull disable */
2309 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2310 /* GPG0[0:6] drv 4x */
2311 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2314 return s5pc1xx_mmc_init(0);
2318 #ifdef CONFIG_CMD_PMIC
2319 static int pmic_status(void)
2321 unsigned char addr, val[2];
2324 i2c_set_bus_num(I2C_PMIC);
2326 if (i2c_probe(addr)) {
2327 printf("Can't found max8998\n");
2332 i2c_read(addr, reg, 1, val, 1);
2333 for (i = 7; i >= 4; i--)
2334 printf("BUCK%d %s\n", 7 - i + 1,
2335 val[0] & (1 << i) ? "on" : "off");
2337 printf("LDO%d %s\n", 5 - i,
2338 val[0] & (1 << i) ? "on" : "off");
2340 i2c_read(addr, reg, 1, val, 1);
2341 for (i = 7; i >= 0; i--)
2342 printf("LDO%d %s\n", 7 - i + 6,
2343 val[0] & (1 << i) ? "on" : "off");
2345 i2c_read(addr, reg, 1, val, 1);
2346 for (i = 7; i >= 4; i--)
2347 printf("LDO%d %s\n", 7 - i + 14,
2348 val[0] & (1 << i) ? "on" : "off");
2351 i2c_read(addr, reg, 1, val, 1);
2352 for (i = 7; i >= 6; i--)
2353 printf("SAFEOUT%d %s\n", 7 - i + 1,
2354 val[0] & (1 << i) ? "on" : "off");
2358 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2360 unsigned char addr, val[2];
2361 unsigned int reg, shift;
2369 } else if (ldo <= 13) {
2372 } else if (ldo <= 17) {
2374 shift = 17 - ldo + 4;
2381 shift = 4 - buck + 4;
2382 } else if (safeout) {
2386 shift = 8 - safeout;
2390 i2c_set_bus_num(I2C_PMIC);
2392 if (i2c_probe(addr)) {
2393 printf("Can't found max8998\n");
2397 i2c_read(addr, reg, 1, val, 1);
2399 val[0] |= (1 << shift);
2401 val[0] &= ~(1 << shift);
2402 i2c_write(addr, reg, 1, val, 1);
2403 i2c_read(addr, reg, 1, val, 1);
2406 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2407 val[0] & (1 << shift) ? "on" : "off");
2409 printf("buck %d value 0x%x, %s\n", buck, val[0],
2410 val[0] & (1 << shift) ? "on" : "off");
2412 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2413 val[0] & (1 << shift) ? "on" : "off");
2418 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2420 int buck = 0, ldo = 0, safeout = 0, on = -1;
2424 if (strncmp(argv[1], "status", 6) == 0)
2425 return pmic_status();
2428 if (strncmp(argv[1], "ldo", 3) == 0)
2429 ldo = simple_strtoul(argv[2], NULL, 10);
2430 else if (strncmp(argv[1], "buck", 4) == 0)
2431 buck = simple_strtoul(argv[2], NULL, 10);
2432 else if (strncmp(argv[1], "safeout", 7) == 0)
2433 safeout = simple_strtoul(argv[2], NULL, 10);
2437 if (strncmp(argv[3], "on", 2) == 0)
2439 else if (strncmp(argv[3], "off", 3) == 0)
2444 return pmic_ldo_control(buck, ldo, safeout, on);
2455 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2456 "PMIC LDO & BUCK control",
2457 "status - Display PMIC LDO & BUCK status\n"
2458 "pmic ldo num on/off - Turn on/off the LDO\n"
2459 "pmic buck num on/off - Turn on/off the BUCK\n"
2460 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2464 #ifdef CONFIG_CMD_DEVICE_POWER
2478 static void power_display_devices(void)
2480 printf("devices:\n");
2481 printf("\t%d - touch\n", POWER_TOUCH);
2482 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2483 printf("\t%d - LCD\n", POWER_LCD);
2484 printf("\t%d - Haptic\n", POWER_HAPTIC);
2485 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2486 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2487 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2488 printf("\t%d - HDMI\n", POWER_HDMI);
2491 static int power_hdmi(int on)
2493 /* HDMI_EN1: GPJ2[2] */
2494 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2495 /* MHL_ON: GPJ2[3] */
2496 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2500 static int power_bt_wifi(int on)
2502 /* WLAN_BT_EN: GPB[5] */
2503 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2507 static int power_fm_radio(int on)
2509 /* FM_BUS_nRST: GPJ2[5] */
2510 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2514 static int power_audio_codec(int on)
2516 /* CODEC_LDO_EN: GPF3[4] */
2517 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2518 /* CODEC_XTAL_EN: GPH3[2] */
2519 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2523 static int power_haptic(int on)
2525 /* HAPTIC_ON: GPJ1[1] */
2526 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2530 static int power_lcd(int on)
2532 /* MLCD_ON: GPJ1[3] */
2533 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2537 static int power_touch(int on)
2539 /* TOUCH_EN: GPG3[6] */
2540 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2544 static int power_3_touchkey(int on)
2547 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2548 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2549 if (board_rev & J1_B2_BOARD)
2550 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2552 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2554 /* 3_TOUCH_CE - GPJ2[6] */
2555 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2557 /* 3_TOUCH_CE - GPJ2[6] */
2558 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2563 unsigned char val[2];
2564 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2570 i2c_set_bus_num(I2C_GPIO10);
2572 /* Workaround to probe */
2573 if (i2c_probe(addr)) {
2574 if (i2c_probe(addr)) {
2575 printf("Can't found 3 touchkey\n");
2580 #define MCS5000_TK_HW_VERSION 0x06
2581 #define MCS5000_TK_FW_VERSION 0x0A
2582 #define MCS5000_TK_MI_VERSION 0x0B
2584 reg = MCS5000_TK_MI_VERSION;
2585 i2c_read(addr, reg, 1, val, 1);
2586 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2587 reg = MCS5000_TK_HW_VERSION;
2588 i2c_read(addr, reg, 1, val, 1);
2589 printf("H/W 0x%x, ", val[0]);
2590 reg = MCS5000_TK_FW_VERSION;
2591 i2c_read(addr, reg, 1, val, 1);
2592 printf("F/W 0x%x\n", val[0]);
2597 static int power_control(int device, int on)
2601 return power_touch(on);
2602 case POWER_3_TOUCHKEY:
2603 return power_3_touchkey(on);
2605 return power_lcd(on);
2607 return power_haptic(on);
2608 case POWER_AUDIO_CODEC:
2609 return power_audio_codec(on);
2610 case POWER_FM_RADIO:
2611 return power_fm_radio(on);
2613 return power_bt_wifi(on);
2615 return power_hdmi(on);
2617 printf("I don't know device %d\n", device);
2623 static int power_on(int on)
2626 power_3_touchkey(on);
2629 power_audio_codec(on);
2637 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2641 if (!machine_is_aquila() && !machine_is_kessler())
2646 if (strncmp(argv[1], "on", 2) == 0)
2648 if (strncmp(argv[1], "off", 3) == 0)
2652 device = simple_strtoul(argv[1], NULL, 10);
2656 if (strncmp(argv[2], "on", 2) == 0)
2658 else if (strncmp(argv[2], "off", 3) == 0)
2662 return power_control(device, on);
2668 power_display_devices();
2673 power, CONFIG_SYS_MAXARGS, 1, do_power,
2674 "Device Power Management control",
2675 "device on/off - Turn on/off the device\n"
2678 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2682 if (strncmp(argv[1], "cp", 2) == 0) {
2683 micro_usb_switch(1);
2684 pmic_ldo_control(0, 0, 2, 1);
2685 setenv("usb", "cp");
2686 } else if (strncmp(argv[1], "ap", 2) == 0) {
2687 micro_usb_switch(0);
2688 pmic_ldo_control(0, 0, 2, 0);
2689 setenv("usb", "ap");
2699 printf("USB Path is set to %s\n", getenv("usb"));
2705 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2707 "cp - switch to CP\n"
2708 "microusb ap - switch to AP\n"