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,
28 #include <asm/arch/clk.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/gpio.h>
31 #include <asm/arch/keypad.h>
32 #include <asm/arch/mmc.h>
33 #include <asm/arch/power.h>
34 #include <asm/arch/mem.h>
35 #include <asm/errno.h>
39 DECLARE_GLOBAL_DATA_PTR;
41 #define C100_MACH_START 3000
42 #define C110_MACH_START 3100
44 static unsigned int board_rev;
45 static unsigned int battery_soc;
46 static struct s5pc110_gpio *s5pc110_gpio;
62 static struct i2c_gpio_bus_data i2c_2 = {
72 static struct i2c_gpio_bus_data i2c_gpio3 = {
82 static struct i2c_gpio_bus_data i2c_pmic = {
92 static struct i2c_gpio_bus_data i2c_gpio5 = {
102 static struct i2c_gpio_bus_data i2c_gpio6 = {
108 * i2c gpio6 - cypress
112 static struct i2c_gpio_bus_data i2c_cypress_gpio6 = {
118 * i2c gpio7 - cypress
122 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
127 static struct i2c_gpio_bus i2c_gpio[] = {
143 u32 get_board_rev(void)
148 static int hwrevision(int rev)
150 return (board_rev & 0xf) == rev;
162 #define SPLIT_SCREEN_FEATURE 0x100
164 /* board is MACH_AQUILA and board is like below. */
165 #define J1_B2_BOARD 0x200
166 #define LIMO_UNIVERSAL_BOARD 0x400
167 #define LIMO_REAL_BOARD 0x800
168 #define MEDIA_BOARD 0x1000
169 #define BAMBOO_BOARD 0x2000
170 /* board is MACH_P1P2 and board is like below. */
171 #define P1_REAL_BOARD 0x200
172 #define P2_REAL_BOARD 0x400
174 #define BOARD_MASK 0xF00
176 static int c110_machine_id(void)
178 return gd->bd->bi_arch_number - C110_MACH_START;
181 static int machine_is_aquila(void)
183 return c110_machine_id() == MACH_AQUILA;
186 static int machine_is_p1p2(void)
188 return c110_machine_id() == MACH_P1P2;
191 static int machine_is_tickertape(void)
193 return c110_machine_id() == MACH_TICKERTAPE;
196 static int machine_is_geminus(void)
198 return c110_machine_id() == MACH_GEMINUS;
201 static int machine_is_cypress(void)
203 return c110_machine_id() == MACH_CYPRESS;
206 static int board_is_limo_universal(void)
208 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
211 static int board_is_limo_real(void)
213 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
216 static int board_is_media(void)
218 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
221 static int board_is_bamboo(void)
223 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
226 static int board_is_j1b2(void)
228 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
231 static int board_is_p2_real(void)
233 return machine_is_p1p2() && (board_rev & P2_REAL_BOARD);
236 static void enable_battery(void);
238 void i2c_init_board(void)
240 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
243 if (cpu_is_s5pc100())
246 num_bus = ARRAY_SIZE(i2c_gpio);
248 if (machine_is_cypress()) {
249 i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
250 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
251 i2c_gpio[I2C_GPIO7].bus->gpio_base =
252 (unsigned int)&gpio->gpio_mp0_5;
257 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
258 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
259 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
260 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
261 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
263 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
265 /* Reset on max17040 early */
266 if (battery_soc == 0)
270 #ifdef CONFIG_MISC_INIT_R
271 #define DEV_INFO_LEN 512
272 static char device_info[DEV_INFO_LEN];
273 static int display_info;
275 static void dprintf(const char *fmt, ...)
282 i = vsprintf(buf, fmt, args);
287 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
288 puts("Flushing device info...\n");
292 strcat(device_info, buf);
296 #ifdef CONFIG_S5PC1XXFB
297 static void display_device_info(void)
304 set_font_color(FONT_WHITE);
305 fb_printf(device_info);
308 memset(device_info, 0x0, DEV_INFO_LEN);
310 udelay(5 * 1000 * 1000);
314 static const char *board_name[] = {
330 static char feature_buffer[32];
332 static char *display_features(int board, int board_rev)
335 char *buf = feature_buffer;
337 if (board == MACH_AQUILA) {
338 if (board_rev & SPLIT_SCREEN_FEATURE)
339 count += sprintf(buf + count, " - SplitScreen");
340 if (board_rev & J1_B2_BOARD)
341 count += sprintf(buf + count, " - J1 B2 board");
342 /* Limo Real or Universal */
343 if (board_rev & LIMO_REAL_BOARD)
344 count += sprintf(buf + count, " - Limo Real");
345 else if (board_rev & LIMO_UNIVERSAL_BOARD)
346 count += sprintf(buf + count, " - Limo Universal");
347 if (board_rev & MEDIA_BOARD)
348 count += sprintf(buf + count, " - Media");
349 if (board_rev & BAMBOO_BOARD)
350 count += sprintf(buf + count, " - Bamboo");
351 } else if (board == MACH_P1P2) {
353 if (board_rev & P1_REAL_BOARD)
354 count += sprintf(buf + count, " - P1 Real");
355 else if (board_rev & P2_REAL_BOARD)
356 count += sprintf(buf + count, " - P2 Real");
358 count += sprintf(buf + count, " - Universal");
364 static void check_board_revision(int board, int rev)
368 /* Limo Real or Universal */
369 if (rev & LIMO_UNIVERSAL_BOARD)
370 board_rev &= ~J1_B2_BOARD;
371 if (rev & LIMO_REAL_BOARD) {
372 board_rev &= ~(J1_B2_BOARD |
373 LIMO_UNIVERSAL_BOARD);
375 if (rev & MEDIA_BOARD)
376 board_rev &= ~(J1_B2_BOARD |
377 LIMO_UNIVERSAL_BOARD);
378 if (rev & BAMBOO_BOARD)
379 board_rev &= ~(J1_B2_BOARD |
380 LIMO_UNIVERSAL_BOARD |
387 /* There's no HWREV_MODE3 */
388 board_rev &= ~(1 << 3);
390 case MACH_TICKERTAPE:
392 board_rev &= ~BOARD_MASK;
399 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank)
403 gpio_direction_input(bank, 1);
404 gpio_direction_input(bank, 2);
405 gpio_direction_input(bank, 3);
406 gpio_direction_input(bank, 4);
408 gpio_set_pull(bank, 1, GPIO_PULL_NONE); /* HWREV_MODE3 */
409 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
410 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
411 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
413 rev = gpio_get_value(bank, 2);
414 rev |= (gpio_get_value(bank, 3) << 1);
415 rev |= (gpio_get_value(bank, 4) << 2);
416 rev |= (gpio_get_value(bank, 1) << 3);
421 static void check_hw_revision(void)
423 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
425 if (cpu_is_s5pc100()) {
426 struct s5pc100_gpio *gpio =
427 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
429 board_rev = get_hw_revision(&gpio->gpio_j0);
431 /* C100 TickerTape */
433 board = MACH_TICKERTAPE;
435 struct s5pc110_gpio *gpio =
436 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
438 board_rev = get_hw_revision(&gpio->gpio_j0);
441 * Note Check 'Aquila' board first
445 * LRA: Limo Real Aquila
446 * LUA: Limo Universal Aquila
452 * ADDR = 0xE0200000 + OFF
454 * OFF Universal BB LRA LUA OA TT SS P1P2 CYP
455 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00 0x00
456 * J2: 0x0284 0x01 0x10 0x00
457 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x18 0x0F
458 * H3: 0x0C64 0x03 0x07 0x0F 0xff
459 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
460 * I: 0x0224 0x02 0x00 0x08
461 * MP03: 0x0324 0x9x 0xbx 0x9x
462 * MP05: 0x0364 0x80 0x88
466 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
468 board_rev |= J1_B2_BOARD;
470 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
471 gpio_direction_input(&gpio->gpio_j2, 6);
474 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
475 board_rev |= LIMO_UNIVERSAL_BOARD;
477 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
478 board_rev |= LIMO_REAL_BOARD;
480 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
481 board_rev |= MEDIA_BOARD;
483 /* set gpio to default value. */
484 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
485 gpio_direction_output(&gpio->gpio_j2, 6, 0);
487 /* Workaround: C110 Aquila Rev0.6 */
488 if (board_rev == 6) {
490 board_rev |= LIMO_REAL_BOARD;
492 /* C110 Aquila Bamboo */
493 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
495 board_rev |= BAMBOO_BOARD;
498 /* C110 TickerTape */
499 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
500 gpio_get_value(&gpio->gpio_d1, 1) == 0)
501 board = MACH_TICKERTAPE;
503 /* C110 Cypress: Do first this than P1P2 */
504 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
505 gpio_direction_input(&gpio->gpio_j2, 2);
506 if (gpio_get_value(&gpio->gpio_j2, 2) == 1)
507 board = MACH_CYPRESS;
508 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
511 if (gpio_get_value(&gpio->gpio_h3, 7) == 1) {
513 board_rev &= ~BOARD_MASK;
516 /* set gpio configuration for P1P2. */
517 gpio_direction_input(&gpio->gpio_j0, 6);
518 gpio_direction_input(&gpio->gpio_j0, 7);
521 * do not change order below
522 * because it needs delay to get gpio value.
525 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_NONE);
527 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
529 if (gpio_get_value(&gpio->gpio_j0, 7) == 1) {
531 board_rev &= ~BOARD_MASK;
532 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
533 board_rev |= P1_REAL_BOARD;
534 if (gpio_get_value(&gpio->gpio_j0, 6) == 0)
535 board_rev |= P2_REAL_BOARD;
538 /* set gpio to default value. */
540 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
542 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_DOWN);
544 /* C110 Geminus for rev0.0 */
545 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
546 gpio_direction_input(&gpio->gpio_j1, 2);
547 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
548 board = MACH_GEMINUS;
549 if ((board_rev & ~BOARD_MASK) == 3)
552 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
553 gpio_direction_output(&gpio->gpio_j1, 2, 0);
555 /* C110 Geminus for rev0.1 ~ */
556 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
557 gpio_direction_input(&gpio->gpio_j0, 6);
558 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
559 board = MACH_GEMINUS;
560 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
564 if (cpu_is_s5pc110())
565 gd->bd->bi_arch_number = C110_MACH_START + board;
567 gd->bd->bi_arch_number = C100_MACH_START + board;
569 /* Architecture Common settings */
570 if (cpu_is_s5pc110()) {
571 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
573 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
575 setenv("updatek", "onenand erase 0x60000 0x300000; "
576 "onenand write 0x31008000 0x60000 0x300000");
580 static void show_hw_revision(void)
585 * Workaround for Rev 0.3 + CP Ver ES 3.1
588 if (board_is_limo_real()) {
590 /* default is Rev 0.4 */
596 if (cpu_is_s5pc110())
597 board = gd->bd->bi_arch_number - C110_MACH_START;
599 board = gd->bd->bi_arch_number - C100_MACH_START;
601 check_board_revision(board, board_rev);
603 /* Set CPU Revision */
604 if (board_is_limo_real()) {
605 if ((board_rev & 0xf) < 8)
606 s5pc1xx_set_cpu_rev(0);
608 s5pc1xx_set_cpu_rev(0);
611 dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
612 display_features(board, board_rev));
615 static void check_auto_burn(void)
617 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
618 unsigned int count = 0;
621 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
622 printf("Auto burning bootloader\n");
623 count += sprintf(buf + count, "run updateb; ");
625 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
626 printf("Auto burning kernel\n");
627 count += sprintf(buf + count, "run updatek; ");
631 count += sprintf(buf + count, "reset");
632 setenv("bootcmd", buf);
635 /* Clear the magic value */
636 writel(0xa5a55a5a, magic_base);
637 writel(0xa5a55a5a, magic_base + 0x4);
640 static void pmic_pin_init(void)
642 unsigned int reg, value;
644 if (cpu_is_s5pc100())
647 /* AP_PS_HOLD: XEINT_0: GPH0[0]
648 * Note: Don't use GPIO PS_HOLD it doesn't work
650 reg = S5PC110_PS_HOLD_CONTROL;
652 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
653 S5PC110_PS_HOLD_DATA_HIGH |
654 S5PC110_PS_HOLD_OUT_EN;
657 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
658 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
659 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
662 static void enable_ldos(void)
664 if (cpu_is_s5pc100())
667 if (machine_is_p1p2())
670 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
671 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
674 static void enable_t_flash(void)
676 if (!(board_is_limo_universal() || board_is_limo_real()))
679 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
680 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
683 static void setup_limo_real_gpios(void)
685 if (!board_is_limo_real())
689 * Note: Please write GPIO alphabet order
691 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
692 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
695 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
696 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
698 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
699 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
701 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
702 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
703 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
706 static void setup_media_gpios(void)
708 if (!board_is_media())
712 * Note: Please write GPIO alphabet order
714 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
715 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
717 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
718 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
719 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
722 static void setup_p1p2_gpios(void)
724 if (!machine_is_p1p2())
728 * Note: Please write GPIO alphabet order
730 /* RESET_REQ_N: XM0FRnB[1]: MP0_3[5] output high */
731 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 5, 1);
732 /* CODEC_LDO_EN: XM0FRnB[2]: MP0_3[6] output high */
733 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 6, 1);
736 #define KBR3 (1 << 3)
737 #define KBR2 (1 << 2)
738 #define KBR1 (1 << 1)
739 #define KBR0 (1 << 0)
741 static void check_p2_keypad(void)
743 unsigned int auto_download = 0;
744 unsigned char addr = 0x34, val[2]; /* adp5587 key controller */
746 i2c_set_bus_num(I2C_2);
748 if (i2c_probe(addr)) {
749 printf("Can't found adp5587 key controller\n");
752 /* Row 8, Column 10 */
754 ret = i2c_write(addr, 0x1D, 1, val, 1); /* Set KP_GPIO1 */
756 ret |= i2c_write(addr, 0x1E, 1, val, 1); /* Set KP_GPIO2 */
758 ret |= i2c_write(addr, 0x1F, 1, val, 1); /* Set KP_GPIO3 */
759 val[0] = 0x3f; /* CMP2_INT | CMP1_INT | OVR_FLOW_INT |
760 K_LCK_INT | GPI_INT | KE_INT */
761 ret |= i2c_write(addr, 0x02, 1, val, 1); /* Status is W1C */
762 val[0] = 0x19; /* INT_CFG | OVR_FLOW_IEN | KE_IEN */
763 ret |= i2c_write(addr, 0x01, 1, val, 1);
764 for (i = 0; i < 10; i++) {
765 udelay(1000); /* FIXME */
766 i2c_read(addr, 0x04 + i, 1, val, 1);
771 if (auto_download == 1)
772 setenv("bootcmd", "usbdown");
775 static void check_keypad(void)
777 unsigned int reg, value;
778 unsigned int col_mask, row_mask;
779 unsigned int auto_download = 0;
780 unsigned int col_value[4], i;
782 if (cpu_is_s5pc100()) {
783 struct s5pc100_gpio *gpio =
784 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
786 /* Set GPH2[2:0] to KP_COL[2:0] */
787 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
788 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
789 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
791 /* Set GPH3[2:0] to KP_ROW[2:0] */
792 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
793 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
794 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
796 reg = S5PC100_KEYPAD_BASE;
798 if (board_is_limo_real() || board_is_limo_universal()) {
806 for (i = 0; i < 4; i++) {
807 /* Set GPH3[3:0] to KP_ROW[3:0] */
808 if (row_mask & (0xF << (i << 2))) {
809 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
810 if (!machine_is_p1p2())
811 gpio_set_pull(&s5pc110_gpio->gpio_h3,
815 /* Set GPH2[3:0] to KP_COL[3:0] */
816 if (col_mask & (0xF << (i << 2)))
817 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
818 if (machine_is_p1p2())
819 gpio_set_pull(&s5pc110_gpio->gpio_h2, i, GPIO_PULL_UP);
822 reg = S5PC110_KEYPAD_BASE;
826 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
827 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
828 /* VOLUMEDOWN and CAM(Half shot) Button */
829 if ((value & KBR1) == 0) {
832 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
835 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
837 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
839 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
841 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
843 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
846 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
848 if (machine_is_p1p2()) {
849 if ((col_value[0] & 0xd) == 0xd)
855 setenv("bootcmd", "usbdown");
858 static void enable_battery(void)
860 unsigned char val[2];
861 unsigned char addr = 0x36; /* max17040 fuel gauge */
863 if (machine_is_aquila()) {
868 if (machine_is_tickertape())
871 if (machine_is_cypress())
872 i2c_set_bus_num(I2C_GPIO7);
874 i2c_set_bus_num(I2C_GPIO3);
876 if (i2c_probe(addr)) {
877 printf("Can't found max17040 fuel gauge\n");
883 i2c_write(addr, 0xfe, 1, val, 2);
886 static void check_battery(void)
888 unsigned char val[2];
889 unsigned char addr = 0x36; /* max17040 fuel gauge */
891 if (machine_is_aquila()) {
896 if (machine_is_tickertape())
899 if (machine_is_cypress())
900 i2c_set_bus_num(I2C_GPIO7);
902 i2c_set_bus_num(I2C_GPIO3);
904 if (i2c_probe(addr)) {
905 printf("Can't found max17040 fuel gauge\n");
909 i2c_read(addr, 0x04, 1, val, 1);
911 dprintf("battery:\t%d%%\n", val[0]);
913 battery_soc = val[0];
916 static void check_mhl(void)
918 unsigned char val[2];
919 unsigned char addr = 0x39; /* SIL9230 */
921 /* MHL Power enable */
922 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
923 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
925 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
926 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
928 /* 10ms required after reset */
932 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
934 i2c_set_bus_num(I2C_GPIO5);
937 if (i2c_probe(addr)) {
938 printf("Can't found MHL Chip\n");
944 * set to Normal operation
947 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
948 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
953 * 00 = MHL termination ON
954 * 11 = MHL termination OFF
957 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
958 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
961 static void into_charge_mode(void)
963 unsigned char addr = 0xCC >> 1; /* max8998 */;
964 unsigned char val[2];
968 i2c_set_bus_num(I2C_PMIC);
970 if (i2c_probe(addr)) {
971 printf("Can't found max8998\n");
975 printf("Charge Mode\n");
977 i2c_read(addr, 0x0C, 1, val, 1);
978 val[0] &= ~(0x7 << 0);
979 val[0] |= 5; /* 600mA */
980 i2c_write(addr, 0x0C, 1, val, 1);
982 #ifdef CONFIG_S5PC1XXFB
983 /* TODO: change to Image animation */
986 set_font_color(FONT_WHITE);
987 fb_printf("charging");
989 level = battery_soc / 25;
991 for (i = 0; i < 3; i++) {
993 udelay(1 * 1000 * 1000);
995 for (j = 0; j < 4; j++) {
999 udelay(1 * 1000 * 1000);
1003 udelay(1 * 1000 * 1000);
1006 set_font_color(FONT_XOR);
1007 fb_printf("charging........");
1010 set_font_color(FONT_WHITE);
1011 fb_printf("charging");
1017 /* EVT0: sleep 1, EVT1: sleep */
1018 if (s5pc1xx_get_cpu_rev() == 0) {
1019 run_command("sleep 1", 0);
1023 run_command("sleep", 0);
1026 static void check_micro_usb(int intr)
1029 unsigned char val[2];
1031 if (cpu_is_s5pc100())
1034 if (board_is_limo_real()) {
1035 if (hwrevision(0) || hwrevision(1))
1039 if (machine_is_cypress())
1040 i2c_set_bus_num(I2C_GPIO6);
1042 i2c_set_bus_num(I2C_PMIC);
1044 addr = 0x25; /* fsa9480 */
1045 if (i2c_probe(addr)) {
1046 printf("Can't found fsa9480\n");
1050 /* Clear Interrupt */
1052 i2c_read(addr, 0x03, 1, val, 2);
1056 /* Read Device Type 1 */
1057 i2c_read(addr, 0x0a, 1, val, 1);
1059 #define FSA_DEDICATED_CHARGER (1 << 6)
1060 #define FSA_UART (1 << 3)
1061 #define FSA_USB (1 << 2)
1064 * If USB, use default 475mA
1065 * If Charger, use 600mA and go to charge mode
1067 if (val[0] & FSA_DEDICATED_CHARGER)
1070 /* If Factory Mode is Boot ON-USB, go to download mode */
1071 i2c_read(addr, 0x07, 1, val, 1);
1073 #define FSA_ADC_FAC_USB 0x19
1074 #define FSA_ADC_FAC_UART 0x1d
1076 if (val[0] == FSA_ADC_FAC_USB)
1077 setenv("bootcmd", "usbdown");
1080 #define MAX8998_REG_ONOFF1 0x11
1081 #define MAX8998_REG_ONOFF2 0x12
1082 #define MAX8998_REG_ONOFF3 0x13
1083 #define MAX8998_LDO3 (1 << 2)
1084 #define MAX8998_LDO10 (1 << 3)
1085 #define MAX8998_LDO11 (1 << 2)
1086 #define MAX8998_LDO12 (1 << 1)
1087 #define MAX8998_LDO13 (1 << 0)
1088 #define MAX8998_LDO14 (1 << 7)
1089 #define MAX8998_LDO15 (1 << 6)
1090 #define MAX8998_LDO16 (1 << 5)
1091 #define MAX8998_LDO17 (1 << 4)
1093 static void init_pmic(void)
1096 unsigned char val[2];
1098 if (cpu_is_s5pc100())
1101 i2c_set_bus_num(I2C_PMIC);
1103 addr = 0xCC >> 1; /* max8998 */
1104 if (i2c_probe(addr)) {
1105 printf("Can't found max8998\n");
1110 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1111 val[0] &= ~MAX8998_LDO3;
1112 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1115 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1117 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1118 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1120 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1121 MAX8998_LDO12 | MAX8998_LDO13);
1123 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1124 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1126 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1128 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1129 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1131 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1132 MAX8998_LDO16 | MAX8998_LDO17);
1133 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1134 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1137 #define PDN_MASK(x) (0x3 << ((x) << 1))
1139 #define CON_INPUT(x) (0x0 << ((x) << 2))
1140 #define CON_OUTPUT(x) (0x1 << ((x) << 2))
1141 #define CON_IRQ(x) (0xf << ((x) << 2))
1143 #define DAT_SET(x) (0x1 << (x))
1144 #define DAT_CLEAR(x) (0x0 << (x))
1146 #define OUTPUT0(x) (0x0 << ((x) << 1))
1147 #define OUTPUT1(x) (0x1 << ((x) << 1))
1148 #define INPUT(x) (0x2 << ((x) << 1))
1150 #define PULL_DIS(x) (0x0 << ((x) << 1))
1151 #define PULL_DOWN(x) (0x1 << ((x) << 1))
1152 #define PULL_UP(x) (0x2 << ((x) << 1))
1154 #define PREVIOUS(x) (0x3 << ((x) << 1))
1156 struct gpio_powermode {
1157 unsigned int conpdn;
1158 unsigned int pudpdn;
1161 struct gpio_external {
1167 static struct gpio_powermode powerdown_modes[] = {
1168 { /* S5PC110_GPIO_A0_OFFSET */
1169 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
1170 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1171 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1172 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1173 }, { /* S5PC110_GPIO_A1_OFFSET */
1174 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1175 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1176 }, { /* S5PC110_GPIO_B_OFFSET */
1177 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1178 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1179 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1180 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1181 }, { /* S5PC110_GPIO_C0_OFFSET */
1182 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1184 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1186 }, { /* S5PC110_GPIO_C1_OFFSET */
1187 /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1189 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1191 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1193 }, { /* S5PC110_GPIO_D0_OFFSET */
1194 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
1195 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1196 }, { /* S5PC110_GPIO_D1_OFFSET */
1197 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1198 INPUT(4) | INPUT(5),
1199 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1200 PULL_DIS(4) | PULL_DIS(5),
1201 }, { /* S5PC110_GPIO_E0_OFFSET */
1202 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1203 INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
1204 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
1205 PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
1206 }, { /* S5PC110_GPIO_E1_OFFSET */
1207 INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
1209 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
1211 }, { /* S5PC110_GPIO_F0_OFFSET */
1212 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1213 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1214 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1215 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1216 }, { /* S5PC110_GPIO_F1_OFFSET */
1217 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1218 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1219 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1220 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1221 }, { /* S5PC110_GPIO_F2_OFFSET */
1222 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1223 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1224 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1225 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1226 }, { /* S5PC110_GPIO_F3_OFFSET */
1227 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1228 OUTPUT0(4) | OUTPUT0(5),
1229 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1230 PULL_DIS(4) | PULL_DIS(5),
1231 }, { /* S5PC110_GPIO_G0_OFFSET */
1232 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1233 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1234 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1235 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1236 }, { /* S5PC110_GPIO_G1_OFFSET */
1237 OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
1238 INPUT(4) | INPUT(5) | INPUT(6),
1239 PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
1240 PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
1241 }, { /* S5PC110_GPIO_G2_OFFSET */
1242 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1243 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1244 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1245 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1246 }, { /* S5PC110_GPIO_G3_OFFSET */
1247 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
1248 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1249 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1250 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1251 }, { /* S5PC110_GPIO_I_OFFSET */
1252 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1253 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1254 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1255 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1256 }, { /* S5PC110_GPIO_J0_OFFSET */
1257 OUTPUT1(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1258 INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
1259 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1260 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1261 }, { /* S5PC110_GPIO_J1_OFFSET */
1262 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1263 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1264 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1265 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1266 }, { /* S5PC110_GPIO_J2_OFFSET */
1267 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1268 INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1269 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1270 PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
1271 }, { /* S5PC110_GPIO_J3_OFFSET */
1272 INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
1273 OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1274 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
1275 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1276 }, { /* S5PC110_GPIO_J4_OFFSET */
1277 INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1279 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1281 }, { /* S5PC110_MP0_1_OFFSET */
1282 /* XM0CSN[4]: MP0_1[4] -> output high */
1283 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1284 OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
1285 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1286 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1287 }, { /* S5PC110_MP0_2_OFFSET */
1288 OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1289 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1290 }, { /* S5PC110_MP0_3_OFFSET */
1291 /* XM0FWEN: MP0_3[2] -> output high */
1292 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1293 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1294 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1295 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1296 }, { /* S5PC110_MP0_4_OFFSET */
1297 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1298 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1299 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
1300 PULL_DOWN(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DIS(7),
1301 }, { /* S5PC110_MP0_5_OFFSET */
1302 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1303 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1304 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1305 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1306 }, { /* S5PC110_MP0_6_OFFSET */
1307 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1308 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1309 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1310 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1311 }, { /* S5PC110_MP0_7_OFFSET */
1312 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1313 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1314 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1315 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1319 static struct gpio_external external_powerdown_modes[] = {
1320 { /* S5PC110_GPIO_H0_OFFSET */
1321 CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1322 CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1323 DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
1324 DAT_CLEAR(4) | DAT_CLEAR(5),
1325 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1326 PULL_DIS(4) | PULL_DIS(5),
1327 }, { /* S5PC110_GPIO_H1_OFFSET */
1328 /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1329 CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1331 PULL_DOWN(0) | PULL_DOWN(1) |
1333 CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1334 CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
1336 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1338 }, { /* S5PC110_GPIO_H2_OFFSET */
1339 CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1340 CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
1341 DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
1343 }, { /* S5PC110_GPIO_H3_OFFSET */
1344 CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
1345 CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
1346 DAT_CLEAR(3) | DAT_CLEAR(7),
1351 static void setup_power_down_mode_registers(void)
1353 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1354 struct s5pc1xx_gpio_bank *bank;
1355 struct gpio_powermode *p;
1356 struct gpio_external *ge;
1359 if (cpu_is_s5pc100())
1362 if (!(machine_is_aquila() && board_is_limo_real()))
1365 bank = &gpio->gpio_a0;
1366 p = powerdown_modes;
1368 for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
1369 writel(p->conpdn, &bank->pdn_con);
1370 writel(p->pudpdn, &bank->pdn_pull);
1373 writel(0xff0022b0, (unsigned int *)0xF0000000);
1374 writel(0xff0022b0, (unsigned int *)0xF1400000);
1377 bank = &gpio->gpio_h0;
1378 ge = external_powerdown_modes;
1380 for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
1381 writel(ge->con, &bank->con);
1382 writel(ge->dat, &bank->dat);
1383 writel(ge->pud, &bank->pull);
1391 struct s6e63m0_platform_data {
1392 struct s5pc1xx_gpio_bank *bank;
1396 extern void s6e63m0_set_spi_interface(struct s6e63m0_platform_data *cs,
1397 struct s6e63m0_platform_data *clk, struct s6e63m0_platform_data *si,
1398 struct s6e63m0_platform_data *so);
1400 struct s6e63m0_platform_data pd_cs, pd_clk, pd_si, pd_so;
1401 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1403 void lcd_cfg_gpio(void)
1405 unsigned int i, f3_end = 4;
1407 for (i = 0; i < 8; i++) {
1408 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1409 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1410 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1411 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1412 /* pull-up/down disable */
1413 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1414 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1415 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1417 /* drive strength to max (24bit) */
1418 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1419 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1420 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1421 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1422 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1423 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1426 /* set DISPLAY_DE_B pin for dual rgb mode. */
1427 if (board_is_media())
1430 for (i = 0; i < f3_end; i++) {
1431 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1432 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1433 /* pull-up/down disable */
1434 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1435 /* drive strength to max (24bit) */
1436 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1437 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1439 /* display output path selection (only [1:0] valid) */
1440 writel(0x2, 0xE0107008);
1442 /* gpio pad configuration for LCD reset. */
1443 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1445 /* gpio pad configuration for LCD ON. */
1446 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1450 if (board_is_p2_real())
1451 gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
1454 /* LCD_BACKLIGHT_EN */
1455 if (machine_is_geminus())
1456 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1459 * gpio pad configuration for
1460 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1462 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1463 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1464 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1465 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1467 if (machine_is_aquila()) {
1468 pd_cs.bank = &gpio_base->gpio_mp0_1;
1470 pd_clk.bank = &gpio_base->gpio_mp0_4;
1472 pd_si.bank = &gpio_base->gpio_mp0_4;
1474 pd_so.bank = &gpio_base->gpio_mp0_4;
1477 /* these data would be sent to s6e63m0 lcd panel driver. */
1478 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, &pd_so);
1481 if (machine_is_cypress()) {
1483 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1485 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1487 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1489 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1491 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1493 pd_cs.bank = &gpio_base->gpio_mp0_1;
1495 pd_clk.bank = &gpio_base->gpio_mp0_4;
1497 pd_si.bank = &gpio_base->gpio_mp0_4;
1500 /* these data would be sent to s6e63m0 lcd panel driver. */
1501 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, NULL);
1507 void backlight_on(unsigned int onoff)
1509 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1512 if (machine_is_geminus())
1513 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1515 if (machine_is_geminus())
1516 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1520 void reset_lcd(void)
1522 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1524 if (machine_is_aquila() || machine_is_geminus())
1525 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1526 if (machine_is_cypress())
1527 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1530 void lcd_power_on(unsigned int onoff)
1532 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1535 if (machine_is_aquila() || machine_is_geminus())
1536 gpio_set_value(&gpio->gpio_j1, 3, 1);
1538 if (machine_is_cypress())
1539 gpio_set_value(&gpio->gpio_g2, 2, 1);
1542 if (board_is_p2_real())
1543 gpio_set_value(&gpio->gpio_j1, 4, 1);
1546 if (machine_is_aquila() || machine_is_geminus())
1547 gpio_set_value(&gpio->gpio_j1, 3, 0);
1549 if (machine_is_cypress())
1550 gpio_set_value(&gpio->gpio_g2, 2, 0);
1553 if (board_is_p2_real())
1554 gpio_set_value(&gpio->gpio_j1, 4, 0);
1559 extern void s6e63m0_cfg_ldo(void);
1560 extern void s6e63m0_enable_ldo(unsigned int onoff);
1562 void init_panel_info(vidinfo_t *vid)
1564 vid->cfg_gpio = NULL;
1565 vid->reset_lcd = NULL;
1566 vid->backlight_on = NULL;
1567 vid->lcd_power_on = NULL;
1569 vid->cfg_ldo = NULL;
1570 vid->enable_ldo = NULL;
1572 vid->init_delay = 0;
1573 vid->reset_delay = 0;
1574 vid->power_on_delay = 0;
1579 vid->vl_width = 480;
1580 vid->vl_height = 800;
1582 vid->dual_lcd_enabled = 0;
1584 if (board_is_media()) {
1587 vid->vl_width = 960;
1588 vid->vl_height = 800;
1590 /* enable dual lcd mode. */
1591 vid->dual_lcd_enabled = 1;
1594 vid->vl_clkp = CONFIG_SYS_HIGH;
1595 vid->vl_hsp = CONFIG_SYS_LOW;
1596 vid->vl_vsp = CONFIG_SYS_LOW;
1597 vid->vl_dp = CONFIG_SYS_HIGH;
1600 /* S6E63M0 LCD Panel */
1609 if (machine_is_aquila() || machine_is_cypress()) {
1610 vid->cfg_gpio = lcd_cfg_gpio;
1611 vid->reset_lcd = reset_lcd;
1612 vid->backlight_on = backlight_on;
1613 vid->lcd_power_on = lcd_power_on;
1615 vid->cfg_ldo = s6e63m0_cfg_ldo;
1616 vid->enable_ldo = s6e63m0_enable_ldo;
1618 vid->init_delay = 25000;
1619 vid->reset_delay = 120000;
1622 if (machine_is_geminus()) {
1626 vid->vl_width = 1024,
1627 vid->vl_height = 600,
1628 vid->vl_clkp = CONFIG_SYS_LOW,
1629 vid->vl_hsp = CONFIG_SYS_HIGH,
1630 vid->vl_vsp = CONFIG_SYS_HIGH,
1631 vid->vl_dp = CONFIG_SYS_LOW,
1642 vid->cfg_gpio = lcd_cfg_gpio;
1643 vid->reset_lcd = reset_lcd;
1644 vid->backlight_on = backlight_on;
1645 vid->lcd_power_on = lcd_power_on;
1651 vid->vl_width = 480,
1652 vid->vl_height = 800,
1653 vid->vl_clkp = CONFIG_SYS_HIGH,
1654 vid->vl_hsp = CONFIG_SYS_LOW,
1655 vid->vl_vsp = CONFIG_SYS_LOW,
1656 vid->vl_dp = CONFIG_SYS_HIGH,
1672 vid->vl_width = 1024,
1673 vid->vl_height = 600,
1674 vid->vl_clkp = CONFIG_SYS_HIGH,
1675 vid->vl_hsp = CONFIG_SYS_HIGH,
1676 vid->vl_vsp = CONFIG_SYS_HIGH,
1677 vid->vl_dp = CONFIG_SYS_LOW,
1680 /* AMS701KA AMOLED Panel. */
1692 static void setup_meminfo(void)
1694 char meminfo[64] = {0, };
1695 int count = 0, size, real;
1697 size = gd->bd->bi_dram[0].size >> 20;
1698 count += sprintf(meminfo + count, "mem=%dM", size);
1700 /* Each Chip Select can't exceed the 256MiB */
1701 size = gd->bd->bi_dram[1].size >> 20;
1702 real = min(size, 256);
1703 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1704 real, (unsigned int)gd->bd->bi_dram[1].start);
1708 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1709 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1712 setenv("meminfo", meminfo);
1715 int misc_init_r(void)
1718 /* It should be located at first */
1721 if (board_is_limo_real() ||
1722 board_is_limo_universal() ||
1724 setenv("lcdinfo", "lcd=s6e63m0");
1725 /* it can't classify tl2796 with single-lcd and dual-lcd.
1727 setenv("lcdinfo", "lcd=tl2796-dual");
1731 * env values below should be added in case that lcd panel of geminus,
1732 * p1 and p2 are enabled at u-boot.
1733 * setenv means that lcd panel has been turned on at u-boot.
1735 if (machine_is_geminus())
1736 setenv("lcdinfo", "lcd=lms480jc01");
1739 if (board_is_p2_real())
1740 setenv("lcdinfo", "lcd=ams701");
1747 /* Set proper PMIC pins */
1750 /* Check auto burning */
1753 /* To power up I2C2 */
1756 /* Enable T-Flash at Limo Real or Limo Universal */
1759 /* Setup Limo Real board GPIOs */
1760 setup_limo_real_gpios();
1762 /* Setup Media board GPIOs */
1763 setup_media_gpios();
1765 /* Setup P1P2 board GPIOS */
1768 /* To usbdown automatically */
1769 if (board_is_p2_real())
1777 #ifdef CONFIG_S5PC1XXFB
1778 display_device_info();
1781 setup_power_down_mode_registers();
1783 /* check max17040 */
1793 int board_init(void)
1795 /* Set Initial global variables */
1796 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1798 gd->bd->bi_arch_number = MACH_TYPE;
1799 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1801 /* Check H/W Revision */
1802 check_hw_revision();
1809 unsigned int base, memconfig0, size;
1810 unsigned int memconfig1, sz = 0;
1812 if (cpu_is_s5pc100()) {
1813 /* In mem setup, we swap the bank. So below size is correct */
1814 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1815 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1816 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1819 /* In S5PC110, we can't swap the DMC0/1 */
1820 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1821 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1823 base = S5PC110_DMC1_BASE;
1824 /* DMC configuration */
1825 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1826 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1828 size = (memconfig0 >> 16) & 0xFF;
1829 size = ((unsigned char) ~size) + 1;
1832 * (0x07 + 1) * 16 = 128 MiB
1833 * (0x0f + 1) * 16 = 256 MiB
1838 * Aquila Rev0.5 4G3G1G
1839 * Aquila Rev0.8 4G3G1G
1841 if (machine_is_aquila() && (hwrevision(5) || hwrevision(8))) {
1842 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
1844 sz = (memconfig1 >> 16) & 0xFF;
1845 sz = ((unsigned char) ~sz) + 1;
1851 * bi_dram[1].size contains all DMC1 memory size
1853 gd->bd->bi_dram[1].size = (size + sz) << 20;
1858 /* Used for sleep test */
1859 static unsigned char saved_val[4][2];
1860 void board_sleep_init_late(void)
1862 /* CODEC_LDO_EN: GPF3[4] */
1863 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
1864 /* CODEC_XTAL_EN: GPH3[2] */
1865 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
1867 /* MMC T_FLASH off */
1868 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
1870 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
1871 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
1872 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
1876 void board_sleep_init(void)
1879 unsigned char val[2];
1881 i2c_set_bus_num(I2C_PMIC);
1883 if (i2c_probe(addr)) {
1884 printf("Can't find max8998\n");
1889 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1890 saved_val[0][0] = val[0];
1891 saved_val[0][1] = val[1];
1892 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
1893 (1 << 1) | (1 << 0));
1894 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1895 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1897 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1898 saved_val[1][0] = val[0];
1899 saved_val[1][1] = val[1];
1900 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
1901 (1 << 2) | (1 << 1) | (1 << 0));
1903 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1904 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1906 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1907 saved_val[2][0] = val[0];
1908 saved_val[2][1] = val[1];
1909 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
1910 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1911 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1913 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1914 saved_val[3][0] = val[0];
1915 saved_val[3][1] = val[1];
1916 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
1917 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1918 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1919 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
1920 __FILE__, __LINE__);
1923 void board_sleep_resume(void)
1926 unsigned char val[2];
1930 i2c_set_bus_num(I2C_PMIC);
1932 if (i2c_probe(addr)) {
1933 printf("Can't find max8998\n");
1938 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
1939 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1941 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
1942 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1944 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
1945 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1947 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
1948 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
1949 printf("Waked up.\n");
1951 /* check max17040 */
1958 #ifdef CONFIG_CMD_USBDOWN
1959 int usb_board_init(void)
1961 #ifdef CONFIG_CMD_PMIC
1962 run_command("pmic ldo 3 on", 0);
1965 if (cpu_is_s5pc100()) {
1966 #ifdef CONFIG_HARD_I2C
1967 uchar val[2] = {0,};
1970 if (i2c_read(0x66, 0, 1, val, 2)) {
1971 printf("i2c_read error\n");
1978 if (i2c_write(0x66, 0, 1, val, 2)) {
1979 printf("i2c_write error\n");
1982 i2c_read(0x66, 0, 1, val, 2);
1988 if (board_is_limo_universal() ||
1989 board_is_limo_real() ||
1991 /* check usb path */
1992 if (board_is_limo_real() && !hwrevision(6))
1996 if (machine_is_tickertape())
1997 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
1998 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2004 #ifdef CONFIG_GENERIC_MMC
2005 int board_mmc_init(bd_t *bis)
2009 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2012 /* MMC0 Clock source = SCLKMPLL */
2013 reg = readl(&clk->src4);
2016 writel(reg, &clk->src4);
2018 reg = readl(&clk->div4);
2021 /* set div value near 50MHz */
2022 clock = get_pll_clk(MPLL) / 1000000;
2023 for (i = 0; i < 0xf; i++) {
2024 if ((clock / (i + 1)) <= 50) {
2030 writel(reg, &clk->div4);
2036 * GPG0[2] SD_0_CDn -> Not used
2037 * GPG0[3:6] SD_0_DATA[0:3]
2039 for (i = 0; i < 7; i++) {
2042 /* GPG0[0:6] special function 2 */
2043 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2044 /* GPG0[0:6] pull disable */
2045 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2048 return s5pc1xx_mmc_init(0);
2052 #ifdef CONFIG_CMD_PMIC
2053 static int pmic_status(void)
2055 unsigned char addr, val[2];
2058 i2c_set_bus_num(I2C_PMIC);
2060 if (i2c_probe(addr)) {
2061 printf("Can't found max8998\n");
2066 i2c_read(addr, reg, 1, val, 1);
2067 for (i = 7; i >= 4; i--)
2068 printf("BUCK%d %s\n", 7 - i + 1,
2069 val[0] & (1 << i) ? "on" : "off");
2071 printf("LDO%d %s\n", 5 - i,
2072 val[0] & (1 << i) ? "on" : "off");
2074 i2c_read(addr, reg, 1, val, 1);
2075 for (i = 7; i >= 0; i--)
2076 printf("LDO%d %s\n", 7 - i + 6,
2077 val[0] & (1 << i) ? "on" : "off");
2079 i2c_read(addr, reg, 1, val, 1);
2080 for (i = 7; i >= 4; i--)
2081 printf("LDO%d %s\n", 7 - i + 14,
2082 val[0] & (1 << i) ? "on" : "off");
2086 static int pmic_ldo_control(int buck, int ldo, int on)
2088 unsigned char addr, val[2];
2089 unsigned int reg, shift;
2097 } else if (ldo <= 13) {
2100 } else if (ldo <= 17) {
2102 shift = 17 - ldo + 4;
2109 shift = 4 - buck + 4;
2113 i2c_set_bus_num(I2C_PMIC);
2115 if (i2c_probe(addr)) {
2116 printf("Can't found max8998\n");
2120 i2c_read(addr, reg, 1, val, 1);
2122 val[0] |= (1 << shift);
2124 val[0] &= ~(1 << shift);
2125 i2c_write(addr, reg, 1, val, 1);
2126 i2c_read(addr, reg, 1, val, 1);
2127 printf("%s %d value 0x%x, %s\n", buck ? "buck" : "ldo", buck ? : ldo,
2128 val[0], val[0] & (1 << shift) ? "on" : "off");
2133 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2135 int buck = 0, ldo = 0, on = -1;
2139 if (strncmp(argv[1], "status", 6) == 0)
2140 return pmic_status();
2143 if (strncmp(argv[1], "ldo", 3) == 0) {
2144 ldo = simple_strtoul(argv[2], NULL, 10);
2145 if (strncmp(argv[3], "on", 2) == 0)
2147 else if (strncmp(argv[3], "off", 3) == 0)
2151 return pmic_ldo_control(buck, ldo, on);
2153 if (strncmp(argv[1], "buck", 4) == 0) {
2154 buck = simple_strtoul(argv[2], NULL, 10);
2155 if (strncmp(argv[3], "on", 2) == 0)
2157 else if (strncmp(argv[3], "off", 3) == 0)
2161 return pmic_ldo_control(buck, ldo, on);
2173 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2174 "PMIC LDO & BUCK control",
2175 "status - Display PMIC LDO & BUCK status\n"
2176 "pmic ldo num on/off - Turn on/off the LDO\n"
2177 "pmic buck num on/off - Turn on/off the BUCK\n"
2181 #ifdef CONFIG_CMD_DEVICE_POWER
2195 static void power_display_devices(void)
2197 printf("devices:\n");
2198 printf("\t%d - touch\n", POWER_TOUCH);
2199 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2200 printf("\t%d - LCD\n", POWER_LCD);
2201 printf("\t%d - Haptic\n", POWER_HAPTIC);
2202 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2203 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2204 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2205 printf("\t%d - HDMI\n", POWER_HDMI);
2208 static int power_hdmi(int on)
2210 /* HDMI_EN1: GPJ2[2] */
2211 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2212 /* MHL_ON: GPJ2[3] */
2213 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2217 static int power_bt_wifi(int on)
2219 /* WLAN_BT_EN: GPB[5] */
2220 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2224 static int power_fm_radio(int on)
2226 /* FM_BUS_nRST: GPJ2[5] */
2227 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2231 static int power_audio_codec(int on)
2233 /* CODEC_LDO_EN: GPF3[4] */
2234 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2235 /* CODEC_XTAL_EN: GPH3[2] */
2236 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2240 static int power_haptic(int on)
2242 /* HAPTIC_ON: GPJ1[1] */
2243 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2247 static int power_lcd(int on)
2249 /* MLCD_ON: GPJ1[3] */
2250 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2254 static int power_touch(int on)
2256 /* TOUCH_EN: GPG3[6] */
2257 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2261 static int power_3_touchkey(int on)
2264 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2265 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2266 if (board_rev & J1_B2_BOARD)
2267 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2269 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2271 /* 3_TOUCH_CE - GPJ2[6] */
2272 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2274 /* 3_TOUCH_CE - GPJ2[6] */
2275 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2280 unsigned char val[2];
2281 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2287 i2c_set_bus_num(I2C_GPIO6);
2289 /* Workaround to probe */
2290 if (i2c_probe(addr)) {
2291 if (i2c_probe(addr)) {
2292 printf("Can't found 3 touchkey\n");
2297 #define MCS5000_TK_HW_VERSION 0x06
2298 #define MCS5000_TK_FW_VERSION 0x0A
2299 #define MCS5000_TK_MI_VERSION 0x0B
2301 reg = MCS5000_TK_MI_VERSION;
2302 i2c_read(addr, reg, 1, val, 1);
2303 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2304 reg = MCS5000_TK_HW_VERSION;
2305 i2c_read(addr, reg, 1, val, 1);
2306 printf("H/W 0x%x, ", val[0]);
2307 reg = MCS5000_TK_FW_VERSION;
2308 i2c_read(addr, reg, 1, val, 1);
2309 printf("F/W 0x%x\n", val[0]);
2314 static int power_control(int device, int on)
2318 return power_touch(on);
2319 case POWER_3_TOUCHKEY:
2320 return power_3_touchkey(on);
2322 return power_lcd(on);
2324 return power_haptic(on);
2325 case POWER_AUDIO_CODEC:
2326 return power_audio_codec(on);
2327 case POWER_FM_RADIO:
2328 return power_fm_radio(on);
2330 return power_bt_wifi(on);
2332 return power_hdmi(on);
2334 printf("I don't know device %d\n", device);
2340 static int power_on(int on)
2343 power_3_touchkey(on);
2346 power_audio_codec(on);
2354 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2358 if (!machine_is_aquila())
2363 if (strncmp(argv[1], "on", 2) == 0)
2365 if (strncmp(argv[1], "off", 3) == 0)
2369 device = simple_strtoul(argv[1], NULL, 10);
2373 if (strncmp(argv[2], "on", 2) == 0)
2375 else if (strncmp(argv[2], "off", 3) == 0)
2379 return power_control(device, on);
2385 power_display_devices();
2390 power, CONFIG_SYS_MAXARGS, 1, do_power,
2391 "Device Power Management control",
2392 "device on/off - Turn on/off the device\n"