2 * Copyright (C) 2009 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Minkyu Kang <mk7.kang@samsung.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/arch/clk.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/keypad.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/power.h>
35 #include <asm/arch/mem.h>
36 #include <asm/errno.h>
39 #include <bmp_layout.h>
41 #include "animation_frames.h"
43 DECLARE_GLOBAL_DATA_PTR;
45 #define C100_MACH_START 3000
46 #define C110_MACH_START 3100
48 static unsigned int board_rev;
49 static unsigned int battery_soc;
50 static struct s5pc110_gpio *s5pc110_gpio;
67 static struct i2c_gpio_bus_data i2c_2 = {
77 static struct i2c_gpio_bus_data i2c_gpio3 = {
87 static struct i2c_gpio_bus_data i2c_pmic = {
97 static struct i2c_gpio_bus_data i2c_gpio5 = {
107 static struct i2c_gpio_bus_data i2c_gpio6 = {
117 static struct i2c_gpio_bus_data i2c_gpio7 = {
123 * i2c gpio7 - cypress
127 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
137 static struct i2c_gpio_bus_data i2c_gpio10 = {
143 static struct i2c_gpio_bus i2c_gpio[] = {
161 u32 get_board_rev(void)
166 static int hwrevision(int rev)
168 return (board_rev & 0xf) == rev;
180 #define SPLIT_SCREEN_FEATURE 0x100
182 /* board is MACH_AQUILA and board is like below. */
183 #define J1_B2_BOARD 0x200
184 #define LIMO_UNIVERSAL_BOARD 0x400
185 #define LIMO_REAL_BOARD 0x800
186 #define MEDIA_BOARD 0x1000
187 #define BAMBOO_BOARD 0x2000
188 #define ARIES_BOARD 0x4000
190 /* board is MACH_P1P2 and board is like below. */
191 #define P1_REAL_BOARD 0x200
192 #define P2_REAL_BOARD 0x400
194 #define BOARD_MASK 0xF00
196 static int c110_machine_id(void)
198 return gd->bd->bi_arch_number - C110_MACH_START;
201 static int machine_is_aquila(void)
203 return c110_machine_id() == MACH_AQUILA;
206 static int machine_is_p1p2(void)
208 return c110_machine_id() == MACH_P1P2;
211 static int machine_is_tickertape(void)
213 return c110_machine_id() == MACH_TICKERTAPE;
216 static int machine_is_geminus(void)
218 return c110_machine_id() == MACH_GEMINUS;
221 static int machine_is_cypress(void)
223 return c110_machine_id() == MACH_CYPRESS;
226 static int board_is_limo_universal(void)
228 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
231 static int board_is_limo_real(void)
233 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
236 static int board_is_media(void)
238 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
241 static int board_is_bamboo(void)
243 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
246 static int board_is_j1b2(void)
248 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
251 static int board_is_aries(void)
253 return machine_is_aquila() && (board_rev & ARIES_BOARD);
256 static int board_is_p2_real(void)
258 return machine_is_p1p2() && (board_rev & P2_REAL_BOARD);
261 static void enable_battery(void);
263 void i2c_init_board(void)
265 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
268 if (cpu_is_s5pc100())
271 num_bus = ARRAY_SIZE(i2c_gpio);
273 if (machine_is_aquila()) {
274 if (board_is_aries()) {
275 i2c_gpio[I2C_GPIO7].bus->gpio_base =
276 (unsigned int)&gpio->gpio_mp0_5;
278 i2c_gpio[I2C_GPIO6].bus->gpio_base = NULL;
279 i2c_gpio[I2C_GPIO7].bus->gpio_base = NULL;
281 } else if (machine_is_cypress()) {
282 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
283 i2c_gpio[I2C_GPIO7].bus->gpio_base =
284 (unsigned int)&gpio->gpio_mp0_5;
286 i2c_gpio[I2C_GPIO7].bus->gpio_base = NULL;
289 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
290 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
291 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
292 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
293 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
295 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
297 /* Reset on max17040 early */
298 if (battery_soc == 0)
302 #ifdef CONFIG_MISC_INIT_R
303 #define DEV_INFO_LEN 512
304 static char device_info[DEV_INFO_LEN];
305 static int display_info;
307 static void dprintf(const char *fmt, ...)
314 i = vsprintf(buf, fmt, args);
319 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
320 puts("Flushing device info...\n");
324 strcat(device_info, buf);
328 #ifdef CONFIG_S5PC1XXFB
329 static void display_device_info(void)
336 set_font_color(FONT_WHITE);
337 fb_printf(device_info);
340 memset(device_info, 0x0, DEV_INFO_LEN);
342 udelay(5 * 1000 * 1000);
346 static const char *board_name[] = {
362 static char feature_buffer[32];
364 static char *display_features(int board, int board_rev)
367 char *buf = feature_buffer;
369 if (board == MACH_AQUILA) {
370 if (board_rev & SPLIT_SCREEN_FEATURE)
371 count += sprintf(buf + count, " - SplitScreen");
372 if (board_rev & J1_B2_BOARD)
373 count += sprintf(buf + count, " - J1 B2 board");
374 /* Limo Real or Universal */
375 if (board_rev & LIMO_REAL_BOARD)
376 count += sprintf(buf + count, " - Limo Real");
377 else if (board_rev & LIMO_UNIVERSAL_BOARD)
378 count += sprintf(buf + count, " - Limo Universal");
379 if (board_rev & MEDIA_BOARD)
380 count += sprintf(buf + count, " - Media");
381 if (board_rev & BAMBOO_BOARD)
382 count += sprintf(buf + count, " - Bamboo");
383 if (board_rev & ARIES_BOARD)
384 count += sprintf(buf + count, " - Aries");
385 } else if (board == MACH_P1P2) {
387 if (board_rev & P1_REAL_BOARD)
388 count += sprintf(buf + count, " - P1 Real");
389 else if (board_rev & P2_REAL_BOARD)
390 count += sprintf(buf + count, " - P2 Real");
392 count += sprintf(buf + count, " - Universal");
398 static void check_board_revision(int board, int rev)
402 /* Limo Real or Universal */
403 if (rev & LIMO_UNIVERSAL_BOARD)
404 board_rev &= ~J1_B2_BOARD;
405 if (rev & LIMO_REAL_BOARD)
406 board_rev &= ~(J1_B2_BOARD |
407 LIMO_UNIVERSAL_BOARD);
408 if (rev & ARIES_BOARD)
409 board_rev &= ~(J1_B2_BOARD |
410 LIMO_UNIVERSAL_BOARD);
411 if (rev & MEDIA_BOARD)
412 board_rev &= ~(J1_B2_BOARD |
413 LIMO_UNIVERSAL_BOARD);
414 if (rev & BAMBOO_BOARD)
415 board_rev &= ~(J1_B2_BOARD |
416 LIMO_UNIVERSAL_BOARD |
423 /* There's no HWREV_MODE3 */
424 board_rev &= ~(1 << 3);
426 case MACH_TICKERTAPE:
428 board_rev &= ~BOARD_MASK;
435 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
443 gpio_direction_input(bank, 2);
444 gpio_direction_input(bank, 3);
445 gpio_direction_input(bank, 4);
446 gpio_direction_input(bank, mode3);
448 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
449 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
450 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
451 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
453 rev = gpio_get_value(bank, 2);
454 rev |= (gpio_get_value(bank, 3) << 1);
455 rev |= (gpio_get_value(bank, 4) << 2);
456 rev |= (gpio_get_value(bank, mode3) << 3);
461 static void check_hw_revision(void)
463 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
465 if (cpu_is_s5pc100()) {
466 struct s5pc100_gpio *gpio =
467 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
469 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
471 /* C100 TickerTape */
473 board = MACH_TICKERTAPE;
475 struct s5pc110_gpio *gpio =
476 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
482 * Note Check 'Aquila' board first
486 * LRA: Limo Real Aquila
487 * LUA: Limo Universal Aquila
493 * ADDR = 0xE0200000 + OFF
495 * OFF Universal BB LRA LUA OA TT SS P1P2 CYP
496 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00 0x00
497 * J2: 0x0284 0x01 0x10 0x00
498 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x18 0x0F
499 * H3: 0x0C64 0x03 0x07 0x0F 0xff
500 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
501 * I: 0x0224 0x02 0x00 0x08
502 * MP03: 0x0324 0x9x 0xbx 0x9x
503 * MP05: 0x0364 0x80 0x88
507 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
509 board_rev |= J1_B2_BOARD;
511 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
512 gpio_direction_input(&gpio->gpio_j2, 6);
515 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
516 board_rev |= LIMO_UNIVERSAL_BOARD;
518 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
519 board_rev |= LIMO_REAL_BOARD;
521 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
522 board_rev |= MEDIA_BOARD;
524 /* set gpio to default value. */
525 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
526 gpio_direction_output(&gpio->gpio_j2, 6, 0);
529 /* Workaround: C110 Aquila Rev0.6 */
530 if (board_rev == 6) {
532 board_rev |= LIMO_REAL_BOARD;
534 /* C110 Aquila Bamboo */
535 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
537 board_rev |= BAMBOO_BOARD;
540 /* C110 TickerTape */
541 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
542 gpio_get_value(&gpio->gpio_d1, 1) == 0)
543 board = MACH_TICKERTAPE;
545 /* C110 Cypress: Do first this than P1P2 */
546 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
547 gpio_direction_input(&gpio->gpio_j2, 2);
548 if (gpio_get_value(&gpio->gpio_j2, 2) == 1)
549 board = MACH_CYPRESS;
550 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
553 if (gpio_get_value(&gpio->gpio_h3, 7) == 1) {
555 board_rev &= ~BOARD_MASK;
558 /* set gpio configuration for P1P2. */
559 gpio_direction_input(&gpio->gpio_j0, 6);
560 gpio_direction_input(&gpio->gpio_j0, 7);
563 * do not change order below
564 * because it needs delay to get gpio value.
567 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_NONE);
569 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
571 if (gpio_get_value(&gpio->gpio_j0, 7) == 1) {
573 board_rev &= ~BOARD_MASK;
574 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
575 board_rev |= P1_REAL_BOARD;
576 if (gpio_get_value(&gpio->gpio_j0, 6) == 0)
577 board_rev |= P2_REAL_BOARD;
580 /* set gpio to default value. */
582 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
584 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_DOWN);
586 /* C110 Geminus for rev0.0 */
587 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
588 gpio_direction_input(&gpio->gpio_j1, 2);
589 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
590 board = MACH_GEMINUS;
591 if ((board_rev & ~BOARD_MASK) == 3)
594 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
595 gpio_direction_output(&gpio->gpio_j1, 2, 0);
597 /* C110 Geminus for rev0.1 ~ */
598 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
599 gpio_direction_input(&gpio->gpio_j0, 6);
600 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
601 board = MACH_GEMINUS;
602 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
604 /* Aquila - Aries MP0_5[6] == 1 */
605 gpio_direction_input(&gpio->gpio_mp0_5, 6);
606 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
608 board_rev |= ARIES_BOARD;
611 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
613 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
617 if (cpu_is_s5pc110())
618 gd->bd->bi_arch_number = C110_MACH_START + board;
620 gd->bd->bi_arch_number = C100_MACH_START + board;
622 /* Architecture Common settings */
623 if (cpu_is_s5pc110()) {
624 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
626 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
628 setenv("updatek", "onenand erase 0x60000 0x300000; "
629 "onenand write 0x31008000 0x60000 0x300000");
633 static void show_hw_revision(void)
638 * Workaround for Rev 0.3 + CP Ver ES 3.1
641 if (board_is_limo_real()) {
643 /* default is Rev 0.4 */
649 if (cpu_is_s5pc110())
650 board = gd->bd->bi_arch_number - C110_MACH_START;
652 board = gd->bd->bi_arch_number - C100_MACH_START;
654 check_board_revision(board, board_rev);
656 /* Set CPU Revision */
657 if (board_is_limo_real()) {
658 if ((board_rev & 0xf) < 8)
659 s5pc1xx_set_cpu_rev(0);
660 } else if (board_is_aries()) {
661 s5pc1xx_set_cpu_rev(1);
663 s5pc1xx_set_cpu_rev(0);
666 dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
667 display_features(board, board_rev));
670 static void check_auto_burn(void)
672 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
673 unsigned int count = 0;
676 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
677 printf("Auto burning bootloader\n");
678 count += sprintf(buf + count, "run updateb; ");
680 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
681 printf("Auto burning kernel\n");
682 count += sprintf(buf + count, "run updatek; ");
686 count += sprintf(buf + count, "reset");
687 setenv("bootcmd", buf);
690 /* Clear the magic value */
691 writel(0xa5a55a5a, magic_base);
692 writel(0xa5a55a5a, magic_base + 0x4);
695 static void pmic_pin_init(void)
697 unsigned int reg, value;
699 if (cpu_is_s5pc100())
702 /* AP_PS_HOLD: XEINT_0: GPH0[0]
703 * Note: Don't use GPIO PS_HOLD it doesn't work
705 reg = S5PC110_PS_HOLD_CONTROL;
707 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
708 S5PC110_PS_HOLD_DATA_HIGH |
709 S5PC110_PS_HOLD_OUT_EN;
712 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
713 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
714 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
717 static void enable_ldos(void)
719 if (cpu_is_s5pc100())
722 if (machine_is_p1p2())
725 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
726 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
729 static void enable_t_flash(void)
731 if (!(board_is_limo_universal() || board_is_limo_real()))
734 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
735 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
738 static void setup_limo_real_gpios(void)
740 if (!board_is_limo_real())
744 * Note: Please write GPIO alphabet order
746 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
747 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
750 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
751 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
753 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
754 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
756 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
757 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
758 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
761 static void setup_media_gpios(void)
763 if (!board_is_media())
767 * Note: Please write GPIO alphabet order
769 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
770 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
772 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
773 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
774 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
777 static void setup_p1p2_gpios(void)
779 if (!machine_is_p1p2())
783 * Note: Please write GPIO alphabet order
785 /* RESET_REQ_N: XM0FRnB[1]: MP0_3[5] output high */
786 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 5, 1);
787 /* CODEC_LDO_EN: XM0FRnB[2]: MP0_3[6] output high */
788 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 6, 1);
791 #define KBR3 (1 << 3)
792 #define KBR2 (1 << 2)
793 #define KBR1 (1 << 1)
794 #define KBR0 (1 << 0)
796 static void check_p2_keypad(void)
798 unsigned int auto_download = 0;
799 unsigned char addr = 0x34, val[2]; /* adp5587 key controller */
801 i2c_set_bus_num(I2C_2);
803 if (i2c_probe(addr)) {
804 printf("Can't found adp5587 key controller\n");
807 /* Row 8, Column 10 */
809 ret = i2c_write(addr, 0x1D, 1, val, 1); /* Set KP_GPIO1 */
811 ret |= i2c_write(addr, 0x1E, 1, val, 1); /* Set KP_GPIO2 */
813 ret |= i2c_write(addr, 0x1F, 1, val, 1); /* Set KP_GPIO3 */
814 val[0] = 0x3f; /* CMP2_INT | CMP1_INT | OVR_FLOW_INT |
815 K_LCK_INT | GPI_INT | KE_INT */
816 ret |= i2c_write(addr, 0x02, 1, val, 1); /* Status is W1C */
817 val[0] = 0x19; /* INT_CFG | OVR_FLOW_IEN | KE_IEN */
818 ret |= i2c_write(addr, 0x01, 1, val, 1);
819 for (i = 0; i < 10; i++) {
820 udelay(1000); /* FIXME */
821 i2c_read(addr, 0x04 + i, 1, val, 1);
826 if (auto_download == 1)
827 setenv("bootcmd", "usbdown");
830 static void check_keypad(void)
832 unsigned int reg, value;
833 unsigned int col_mask, row_mask;
834 unsigned int auto_download = 0;
835 unsigned int col_value[4], i;
837 if (cpu_is_s5pc100()) {
838 struct s5pc100_gpio *gpio =
839 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
841 /* Set GPH2[2:0] to KP_COL[2:0] */
842 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
843 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
844 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
846 /* Set GPH3[2:0] to KP_ROW[2:0] */
847 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
848 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
849 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
851 reg = S5PC100_KEYPAD_BASE;
853 if (board_is_limo_real() || board_is_limo_universal()) {
861 for (i = 0; i < 4; i++) {
862 /* Set GPH3[3:0] to KP_ROW[3:0] */
863 if (row_mask & (0xF << (i << 2))) {
864 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
865 if (!machine_is_p1p2())
866 gpio_set_pull(&s5pc110_gpio->gpio_h3,
870 /* Set GPH2[3:0] to KP_COL[3:0] */
871 if (col_mask & (0xF << (i << 2)))
872 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
873 if (machine_is_p1p2())
874 gpio_set_pull(&s5pc110_gpio->gpio_h2, i, GPIO_PULL_UP);
877 reg = S5PC110_KEYPAD_BASE;
881 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
882 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
883 /* VOLUMEDOWN and CAM(Half shot) Button */
884 if ((value & KBR1) == 0) {
887 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
890 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
892 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
894 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
896 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
898 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
901 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
903 if (machine_is_p1p2()) {
904 if ((col_value[0] & 0xd) == 0xd)
910 setenv("bootcmd", "usbdown");
913 static void enable_battery(void)
915 unsigned char val[2];
916 unsigned char addr = 0x36; /* max17040 fuel gauge */
918 i2c_set_bus_num(I2C_GPIO3);
920 if (machine_is_aquila()) {
921 if (board_is_aries())
922 i2c_set_bus_num(I2C_GPIO7);
923 else if (board_is_j1b2())
925 } else if (machine_is_tickertape()) {
927 } else if (machine_is_cypress()) {
928 i2c_set_bus_num(I2C_GPIO7);
931 if (i2c_probe(addr)) {
932 printf("Can't found max17040 fuel gauge\n");
938 i2c_write(addr, 0xfe, 1, val, 2);
941 static void check_battery(void)
943 unsigned char val[2];
944 unsigned char addr = 0x36; /* max17040 fuel gauge */
946 i2c_set_bus_num(I2C_GPIO3);
948 if (machine_is_aquila()) {
949 if (board_is_aries())
950 i2c_set_bus_num(I2C_GPIO7);
951 else if (board_is_j1b2())
953 } else if (machine_is_tickertape()) {
955 } else if (machine_is_cypress()) {
956 i2c_set_bus_num(I2C_GPIO7);
959 if (i2c_probe(addr)) {
960 printf("Can't found max17040 fuel gauge\n");
964 i2c_read(addr, 0x04, 1, val, 1);
966 dprintf("battery:\t%d%%\n", val[0]);
968 battery_soc = val[0];
971 static void check_mhl(void)
973 unsigned char val[2];
974 unsigned char addr = 0x39; /* SIL9230 */
976 /* MHL Power enable */
977 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
978 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
980 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
981 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
983 /* 10ms required after reset */
987 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
989 i2c_set_bus_num(I2C_GPIO5);
992 if (i2c_probe(addr)) {
993 printf("Can't found MHL Chip\n");
999 * set to Normal operation
1002 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
1003 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
1008 * 00 = MHL termination ON
1009 * 11 = MHL termination OFF
1012 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1013 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1016 #define CHARGER_ANIMATION_FRAME 6
1017 static int max8998_power_key(void)
1019 unsigned char addr, val[2];
1020 i2c_set_bus_num(I2C_PMIC);
1022 if (i2c_probe(addr)) {
1023 printf("Can't found max8998\n");
1027 /* Accessing IRQ1 register */
1028 i2c_read(addr, 0x00, 1, val, 1);
1029 if (val[0] & (1 << 6))
1035 static void into_charge_mode(void)
1037 unsigned char addr = 0xCC >> 1; /* max8998 */;
1038 unsigned char val[2];
1041 bmp_image_t *bmp[CHARGER_ANIMATION_FRAME];
1042 unsigned long len[CHARGER_ANIMATION_FRAME];
1043 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1045 i2c_set_bus_num(I2C_PMIC);
1047 if (i2c_probe(addr)) {
1048 printf("Can't found max8998\n");
1052 printf("Charge Mode\n");
1054 i2c_read(addr, 0x0C, 1, val, 1);
1055 val[0] &= ~(0x7 << 0);
1056 val[0] |= 5; /* 600mA */
1057 i2c_write(addr, 0x0C, 1, val, 1);
1059 #ifdef CONFIG_S5PC1XXFB
1062 /* TODO: write the image-text for the charger */
1064 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1065 if (level >= CHARGER_ANIMATION_FRAME)
1066 level = CHARGER_ANIMATION_FRAME - 1;
1068 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1069 bmp_addr[i] = (ulong)battery_charging_animation[i];
1071 lcd_display_clear();
1072 for (i = 0; i < 3; i++) {
1073 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1076 bmp[j] = gunzip_bmp(bmp_addr[j], &len[j]);
1077 lcd_display_bitmap((ulong) bmp[j], 140, 202);
1080 for (k = 0; k < 10; k++)
1081 if (max8998_power_key()) {
1082 lcd_display_clear();
1083 /* FIXME don't use static function */
1084 /* draw_samsung_logo(lcd_base); */
1093 /* EVT0: sleep 1, EVT1: sleep */
1094 if (s5pc1xx_get_cpu_rev() == 0) {
1095 run_command("sleep 1", 0);
1099 run_command("sleep", 0);
1102 static void check_micro_usb(int intr)
1105 unsigned char val[2];
1106 static int started_charging_once = 0;
1108 if (cpu_is_s5pc100())
1111 if (board_is_limo_real()) {
1112 if (hwrevision(0) || hwrevision(1))
1116 i2c_set_bus_num(I2C_PMIC);
1118 if (machine_is_aquila()) {
1119 if (board_is_aries())
1120 i2c_set_bus_num(I2C_GPIO6);
1121 } else if (machine_is_cypress()) {
1122 i2c_set_bus_num(I2C_GPIO6);
1125 addr = 0x25; /* fsa9480 */
1126 if (i2c_probe(addr)) {
1127 printf("Can't found fsa9480\n");
1131 /* Clear Interrupt */
1133 i2c_read(addr, 0x03, 1, val, 2);
1137 /* Read Device Type 1 */
1138 i2c_read(addr, 0x0a, 1, val, 1);
1140 #define FSA_DEDICATED_CHARGER (1 << 6)
1141 #define FSA_UART (1 << 3)
1142 #define FSA_USB (1 << 2)
1145 * If USB, use default 475mA
1146 * If Charger, use 600mA and go to charge mode
1148 if ((val[0] & FSA_DEDICATED_CHARGER) && !started_charging_once) {
1149 started_charging_once = 1;
1153 /* If Factory Mode is Boot ON-USB, go to download mode */
1154 i2c_read(addr, 0x07, 1, val, 1);
1156 #define FSA_ADC_FAC_USB 0x19
1157 #define FSA_ADC_FAC_UART 0x1d
1159 if (val[0] == FSA_ADC_FAC_USB)
1160 setenv("bootcmd", "usbdown");
1163 static void micro_usb_switch(int path)
1166 unsigned char val[2];
1168 i2c_set_bus_num(I2C_PMIC);
1170 if (machine_is_aquila()) {
1171 if (board_is_aries())
1172 i2c_set_bus_num(I2C_GPIO6);
1173 } else if (machine_is_cypress()) {
1174 i2c_set_bus_num(I2C_GPIO6);
1177 addr = 0x25; /* fsa9480 */
1178 if (i2c_probe(addr)) {
1179 printf("Can't found fsa9480\n");
1184 val[0] = 0x90; /* VAUDIO */
1186 val[0] = 0x24; /* DHOST */
1188 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1190 i2c_read(addr, 0x2, 1, val, 1);
1191 val[0] &= ~(1 << 2);
1192 i2c_write(addr, 0x2, 1, val, 1);
1195 #define MAX8998_REG_ONOFF1 0x11
1196 #define MAX8998_REG_ONOFF2 0x12
1197 #define MAX8998_REG_ONOFF3 0x13
1198 #define MAX8998_REG_LDO7 0x21
1199 #define MAX8998_REG_LDO17 0x29
1201 #define MAX8998_LDO3 (1 << 2)
1203 #define MAX8998_LDO6 (1 << 7)
1204 #define MAX8998_LDO7 (1 << 6)
1205 #define MAX8998_LDO8 (1 << 5)
1206 #define MAX8998_LDO9 (1 << 4)
1207 #define MAX8998_LDO10 (1 << 3)
1208 #define MAX8998_LDO11 (1 << 2)
1209 #define MAX8998_LDO12 (1 << 1)
1210 #define MAX8998_LDO13 (1 << 0)
1212 #define MAX8998_LDO14 (1 << 7)
1213 #define MAX8998_LDO15 (1 << 6)
1214 #define MAX8998_LDO16 (1 << 5)
1215 #define MAX8998_LDO17 (1 << 4)
1218 static void init_pmic(void)
1221 unsigned char val[2];
1223 if (cpu_is_s5pc100())
1226 i2c_set_bus_num(I2C_PMIC);
1228 addr = 0xCC >> 1; /* max8998 */
1229 if (i2c_probe(addr)) {
1230 printf("Can't found max8998\n");
1235 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1236 val[0] &= ~MAX8998_LDO3;
1237 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1240 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1242 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1243 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1245 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1246 MAX8998_LDO12 | MAX8998_LDO13);
1248 if (board_is_aries())
1249 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1251 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1252 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1254 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1256 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1257 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1259 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1260 MAX8998_LDO16 | MAX8998_LDO17);
1262 if (board_is_aries())
1263 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1265 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1266 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1269 #define PDN_MASK(x) (0x3 << ((x) << 1))
1271 #define CON_INPUT(x) (0x0 << ((x) << 2))
1272 #define CON_OUTPUT(x) (0x1 << ((x) << 2))
1273 #define CON_IRQ(x) (0xf << ((x) << 2))
1275 #define DAT_SET(x) (0x1 << (x))
1276 #define DAT_CLEAR(x) (0x0 << (x))
1278 #define OUTPUT0(x) (0x0 << ((x) << 1))
1279 #define OUTPUT1(x) (0x1 << ((x) << 1))
1280 #define INPUT(x) (0x2 << ((x) << 1))
1282 #define PULL_DIS(x) (0x0 << ((x) << 1))
1283 #define PULL_DOWN(x) (0x1 << ((x) << 1))
1284 #define PULL_UP(x) (0x2 << ((x) << 1))
1286 #define PREVIOUS(x) (0x3 << ((x) << 1))
1288 struct gpio_powermode {
1289 unsigned int conpdn;
1290 unsigned int pudpdn;
1293 struct gpio_external {
1299 static struct gpio_powermode powerdown_modes[] = {
1300 { /* S5PC110_GPIO_A0_OFFSET */
1301 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
1302 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1303 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1304 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1305 }, { /* S5PC110_GPIO_A1_OFFSET */
1306 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
1307 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1308 }, { /* S5PC110_GPIO_B_OFFSET */
1309 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1310 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1311 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1312 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1313 }, { /* S5PC110_GPIO_C0_OFFSET */
1314 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1316 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1318 }, { /* S5PC110_GPIO_C1_OFFSET */
1319 /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1321 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1323 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1325 }, { /* S5PC110_GPIO_D0_OFFSET */
1326 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
1327 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1328 }, { /* S5PC110_GPIO_D1_OFFSET */
1329 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1330 INPUT(4) | INPUT(5),
1331 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1332 PULL_DIS(4) | PULL_DIS(5),
1333 }, { /* S5PC110_GPIO_E0_OFFSET */
1334 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1335 INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
1336 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
1337 PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
1338 }, { /* S5PC110_GPIO_E1_OFFSET */
1339 INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
1341 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
1343 }, { /* S5PC110_GPIO_F0_OFFSET */
1344 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1345 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1346 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1347 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1348 }, { /* S5PC110_GPIO_F1_OFFSET */
1349 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1350 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1351 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1352 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1353 }, { /* S5PC110_GPIO_F2_OFFSET */
1354 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1355 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1356 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1357 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1358 }, { /* S5PC110_GPIO_F3_OFFSET */
1359 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1360 OUTPUT0(4) | OUTPUT0(5),
1361 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1362 PULL_DIS(4) | PULL_DIS(5),
1363 }, { /* S5PC110_GPIO_G0_OFFSET */
1364 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1365 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1366 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1367 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1368 }, { /* S5PC110_GPIO_G1_OFFSET */
1369 OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
1370 INPUT(4) | INPUT(5) | INPUT(6),
1371 PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
1372 PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
1373 }, { /* S5PC110_GPIO_G2_OFFSET */
1374 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1375 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1376 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1377 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1378 }, { /* S5PC110_GPIO_G3_OFFSET */
1379 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
1380 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1381 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1382 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1383 }, { /* S5PC110_GPIO_I_OFFSET */
1384 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1385 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1386 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1387 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1388 }, { /* S5PC110_GPIO_J0_OFFSET */
1389 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1390 INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
1391 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1392 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1393 }, { /* S5PC110_GPIO_J1_OFFSET */
1394 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1395 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1396 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1397 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1398 }, { /* S5PC110_GPIO_J2_OFFSET */
1399 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1400 INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1401 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1402 PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
1403 }, { /* S5PC110_GPIO_J3_OFFSET */
1404 INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
1405 OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1406 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
1407 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1408 }, { /* S5PC110_GPIO_J4_OFFSET */
1409 INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1411 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1413 }, { /* S5PC110_MP0_1_OFFSET */
1414 /* XM0CSN[4]: MP0_1[4] -> output high */
1415 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1416 OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
1417 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1418 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1419 }, { /* S5PC110_MP0_2_OFFSET */
1420 OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1421 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1422 }, { /* S5PC110_MP0_3_OFFSET */
1423 /* XM0FWEN: MP0_3[2] -> output high */
1424 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1425 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1426 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1427 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1428 }, { /* S5PC110_MP0_4_OFFSET */
1429 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1430 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1431 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
1432 PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1433 }, { /* S5PC110_MP0_5_OFFSET */
1434 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1435 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1436 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1437 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1438 }, { /* S5PC110_MP0_6_OFFSET */
1439 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1440 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1441 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1442 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1443 }, { /* S5PC110_MP0_7_OFFSET */
1444 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1445 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1446 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1447 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1451 static struct gpio_external external_powerdown_modes[] = {
1452 { /* S5PC110_GPIO_H0_OFFSET */
1453 CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1454 CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1455 DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
1456 DAT_CLEAR(4) | DAT_CLEAR(5),
1457 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1458 PULL_DIS(4) | PULL_DIS(5),
1459 }, { /* S5PC110_GPIO_H1_OFFSET */
1460 /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1461 CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1463 PULL_DOWN(0) | PULL_DOWN(1) |
1465 CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1466 CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
1468 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1470 }, { /* S5PC110_GPIO_H2_OFFSET */
1471 CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1472 CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
1473 DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
1475 }, { /* S5PC110_GPIO_H3_OFFSET */
1476 CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
1477 CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
1478 DAT_CLEAR(3) | DAT_CLEAR(7),
1483 static void setup_power_down_mode_registers(void)
1485 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1486 struct s5pc1xx_gpio_bank *bank;
1487 struct gpio_powermode *p;
1488 struct gpio_external *ge;
1491 if (cpu_is_s5pc100())
1494 if (!(machine_is_aquila() && board_is_limo_real()))
1497 bank = &gpio->gpio_a0;
1498 p = powerdown_modes;
1500 for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
1501 writel(p->conpdn, &bank->pdn_con);
1502 writel(p->pudpdn, &bank->pdn_pull);
1505 writel(0xff0022b0, (unsigned int *)0xF0000000);
1506 writel(0xff0022b0, (unsigned int *)0xF1400000);
1509 bank = &gpio->gpio_h0;
1510 ge = external_powerdown_modes;
1512 for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
1513 writel(ge->con, &bank->con);
1514 writel(ge->dat, &bank->dat);
1515 writel(ge->pud, &bank->pull);
1523 struct s6e63m0_platform_data {
1524 struct s5pc1xx_gpio_bank *cs_bank;
1525 struct s5pc1xx_gpio_bank *clk_bank;
1526 struct s5pc1xx_gpio_bank *si_bank;
1527 struct s5pc1xx_gpio_bank *so_bank;
1529 unsigned int cs_num;
1530 unsigned int clk_num;
1531 unsigned int si_num;
1532 unsigned int so_num;
1534 unsigned int board_is_media;
1537 extern void s6e63m0_set_platform_data(struct s6e63m0_platform_data *pd);
1539 struct s6e63m0_platform_data s6e63m0_pd;
1540 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1542 void lcd_cfg_gpio(void)
1544 unsigned int i, f3_end = 4;
1546 for (i = 0; i < 8; i++) {
1547 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1548 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1549 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1550 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1551 /* pull-up/down disable */
1552 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1553 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1554 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1556 /* drive strength to max (24bit) */
1557 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1558 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1559 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1560 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1561 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1562 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1565 /* set DISPLAY_DE_B pin for dual rgb mode. */
1566 if (board_is_media())
1569 for (i = 0; i < f3_end; i++) {
1570 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1571 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1572 /* pull-up/down disable */
1573 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1574 /* drive strength to max (24bit) */
1575 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1576 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1578 /* display output path selection (only [1:0] valid) */
1579 writel(0x2, 0xE0107008);
1581 /* gpio pad configuration for LCD reset. */
1582 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1584 /* gpio pad configuration for LCD ON. */
1585 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1589 if (board_is_p2_real())
1590 gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
1593 /* LCD_BACKLIGHT_EN */
1594 if (machine_is_geminus())
1595 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1598 * gpio pad configuration for
1599 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1601 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1602 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1603 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1604 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1606 if (machine_is_aquila()) {
1607 s6e63m0_pd.cs_bank = &gpio_base->gpio_mp0_1;
1608 s6e63m0_pd.cs_num = 1;
1609 s6e63m0_pd.clk_bank = &gpio_base->gpio_mp0_4;
1610 s6e63m0_pd.clk_num = 1;
1611 s6e63m0_pd.si_bank = &gpio_base->gpio_mp0_4;
1612 s6e63m0_pd.si_num = 3;
1613 s6e63m0_pd.so_bank = &gpio_base->gpio_mp0_4;
1614 s6e63m0_pd.so_num = 2;
1616 if (board_is_media())
1617 s6e63m0_pd.board_is_media = 1;
1619 /* these data would be sent to s6e63m0 lcd panel driver. */
1620 s6e63m0_set_platform_data(&s6e63m0_pd);
1623 if (machine_is_cypress()) {
1624 #if 0 /* universal cypress */
1626 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1629 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1631 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1633 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1635 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1637 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1638 #if 0 /* universal cypress */
1639 pd_cs.bank = &gpio_base->gpio_mp0_1;
1642 s6e63m0_pd.cs_bank = &gpio_base->gpio_mp0_5;
1643 s6e63m0_pd.cs_num = 1;
1644 s6e63m0_pd.clk_bank = &gpio_base->gpio_mp0_4;
1645 s6e63m0_pd.clk_num = 0;
1646 s6e63m0_pd.si_bank = &gpio_base->gpio_mp0_4;
1647 s6e63m0_pd.si_num = 2;
1649 /* these data would be sent to s6e63m0 lcd panel driver. */
1650 s6e63m0_set_platform_data(&s6e63m0_pd);
1656 void backlight_on(unsigned int onoff)
1658 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1661 if (machine_is_geminus())
1662 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1664 if (machine_is_geminus())
1665 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1669 void reset_lcd(void)
1671 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1673 if (machine_is_aquila() || machine_is_geminus())
1674 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1675 if (machine_is_cypress())
1676 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1679 void lcd_power_on(unsigned int onoff)
1681 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1684 if (machine_is_aquila() || machine_is_geminus())
1685 gpio_set_value(&gpio->gpio_j1, 3, 1);
1687 if (machine_is_cypress())
1688 gpio_set_value(&gpio->gpio_g2, 2, 1);
1691 if (board_is_p2_real())
1692 gpio_set_value(&gpio->gpio_j1, 4, 1);
1695 if (board_is_aries()) {
1697 unsigned char val[2];
1698 unsigned char val2[2];
1700 i2c_set_bus_num(I2C_PMIC);
1701 addr = 0xCC >> 1; /* max8998 */
1702 if (i2c_probe(addr)) {
1703 printf("Can't found max8998\n");
1707 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1710 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1711 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1712 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1713 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1715 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1716 val[0] |= MAX8998_LDO17;
1718 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1719 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1720 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1721 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1724 if (machine_is_aquila() || machine_is_geminus())
1725 gpio_set_value(&gpio->gpio_j1, 3, 0);
1727 if (machine_is_cypress())
1728 gpio_set_value(&gpio->gpio_g2, 2, 0);
1731 if (board_is_p2_real())
1732 gpio_set_value(&gpio->gpio_j1, 4, 0);
1735 if (board_is_aries()) {
1737 unsigned char val[2];
1739 i2c_set_bus_num(I2C_PMIC);
1740 addr = 0xCC >> 1; /* max8998 */
1741 if (i2c_probe(addr)) {
1742 printf("Can't found max8998\n");
1746 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1747 val[0] &= ~(1 << 7);
1748 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1749 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1751 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1752 val[0] &= ~MAX8998_LDO17;
1753 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1754 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1759 extern void s6e63m0_cfg_ldo(void);
1760 extern void s6e63m0_enable_ldo(unsigned int onoff);
1762 void init_panel_info(vidinfo_t *vid)
1764 vid->cfg_gpio = NULL;
1765 vid->reset_lcd = NULL;
1766 vid->backlight_on = NULL;
1767 vid->lcd_power_on = NULL;
1769 vid->cfg_ldo = NULL;
1770 vid->enable_ldo = NULL;
1772 vid->init_delay = 0;
1773 vid->reset_delay = 0;
1774 vid->power_on_delay = 0;
1779 vid->vl_width = 480;
1780 vid->vl_height = 800;
1782 vid->dual_lcd_enabled = 0;
1784 if (board_is_media()) {
1787 vid->vl_width = 960;
1788 vid->vl_height = 800;
1790 /* enable dual lcd mode. */
1791 vid->dual_lcd_enabled = 1;
1794 vid->vl_clkp = CONFIG_SYS_HIGH;
1795 vid->vl_hsp = CONFIG_SYS_LOW;
1796 vid->vl_vsp = CONFIG_SYS_LOW;
1797 vid->vl_dp = CONFIG_SYS_HIGH;
1800 /* S6E63M0 LCD Panel */
1809 if (machine_is_aquila() || machine_is_cypress()) {
1810 vid->cfg_gpio = lcd_cfg_gpio;
1811 vid->reset_lcd = reset_lcd;
1812 vid->backlight_on = backlight_on;
1813 vid->lcd_power_on = lcd_power_on;
1815 vid->cfg_ldo = s6e63m0_cfg_ldo;
1816 vid->enable_ldo = s6e63m0_enable_ldo;
1818 vid->init_delay = 25000;
1819 vid->reset_delay = 120000;
1822 if (machine_is_geminus()) {
1826 vid->vl_width = 1024,
1827 vid->vl_height = 600,
1828 vid->vl_clkp = CONFIG_SYS_LOW,
1829 vid->vl_hsp = CONFIG_SYS_HIGH,
1830 vid->vl_vsp = CONFIG_SYS_HIGH,
1831 vid->vl_dp = CONFIG_SYS_LOW,
1842 vid->cfg_gpio = lcd_cfg_gpio;
1843 vid->reset_lcd = reset_lcd;
1844 vid->backlight_on = backlight_on;
1845 vid->lcd_power_on = lcd_power_on;
1851 vid->vl_width = 480,
1852 vid->vl_height = 800,
1853 vid->vl_clkp = CONFIG_SYS_HIGH,
1854 vid->vl_hsp = CONFIG_SYS_LOW,
1855 vid->vl_vsp = CONFIG_SYS_LOW,
1856 vid->vl_dp = CONFIG_SYS_HIGH,
1872 vid->vl_width = 1024,
1873 vid->vl_height = 600,
1874 vid->vl_clkp = CONFIG_SYS_HIGH,
1875 vid->vl_hsp = CONFIG_SYS_HIGH,
1876 vid->vl_vsp = CONFIG_SYS_HIGH,
1877 vid->vl_dp = CONFIG_SYS_LOW,
1880 /* AMS701KA AMOLED Panel. */
1892 static void setup_meminfo(void)
1894 char meminfo[64] = {0, };
1895 int count = 0, size, real;
1897 size = gd->bd->bi_dram[0].size >> 20;
1898 count += sprintf(meminfo + count, "mem=%dM", size);
1900 /* Each Chip Select can't exceed the 256MiB */
1901 size = gd->bd->bi_dram[1].size >> 20;
1902 real = min(size, 256);
1903 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1904 real, (unsigned int)gd->bd->bi_dram[1].start);
1908 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1909 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1912 setenv("meminfo", meminfo);
1915 int misc_init_r(void)
1918 /* It should be located at first */
1921 if (board_is_limo_real() ||
1922 board_is_limo_universal() ||
1924 setenv("lcdinfo", "lcd=s6e63m0");
1925 /* it can't classify tl2796 with single-lcd and dual-lcd.
1927 setenv("lcdinfo", "lcd=tl2796-dual");
1931 * env values below should be added in case that lcd panel of geminus,
1932 * p1 and p2 are enabled at u-boot.
1933 * setenv means that lcd panel has been turned on at u-boot.
1935 if (machine_is_geminus())
1936 setenv("lcdinfo", "lcd=lms480jc01");
1937 if (board_is_media())
1938 setenv("lcdinfo", "lcd=media");
1940 if (board_is_p2_real())
1941 setenv("lcdinfo", "lcd=ams701");
1948 /* Set proper PMIC pins */
1951 /* Check auto burning */
1954 /* To power up I2C2 */
1957 /* Enable T-Flash at Limo Real or Limo Universal */
1960 /* Setup Limo Real board GPIOs */
1961 setup_limo_real_gpios();
1963 /* Setup Media board GPIOs */
1964 setup_media_gpios();
1966 /* Setup P1P2 board GPIOS */
1969 /* To usbdown automatically */
1970 if (board_is_p2_real())
1978 #ifdef CONFIG_S5PC1XXFB
1979 display_device_info();
1982 setup_power_down_mode_registers();
1984 /* check max17040 */
1994 int board_init(void)
1996 /* Set Initial global variables */
1997 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1999 gd->bd->bi_arch_number = MACH_TYPE;
2000 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2002 /* Check H/W Revision */
2003 check_hw_revision();
2010 unsigned int base, memconfig0, size;
2011 unsigned int memconfig1, sz = 0;
2013 if (cpu_is_s5pc100()) {
2014 /* In mem setup, we swap the bank. So below size is correct */
2015 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2016 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2017 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2020 /* In S5PC110, we can't swap the DMC0/1 */
2021 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2022 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2024 base = S5PC110_DMC1_BASE;
2025 /* DMC configuration */
2026 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2027 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2029 size = (memconfig0 >> 16) & 0xFF;
2030 size = ((unsigned char) ~size) + 1;
2033 * (0x07 + 1) * 16 = 128 MiB
2034 * (0x0f + 1) * 16 = 256 MiB
2039 * Aquila Rev0.5 4G3G1G
2040 * Aquila Rev0.8 4G3G1G
2041 * Aquila Rev0.9 4G3G1G
2043 if (machine_is_aquila() &&
2044 (hwrevision(5) || hwrevision(8) || hwrevision(9))) {
2045 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2047 sz = (memconfig1 >> 16) & 0xFF;
2048 sz = ((unsigned char) ~sz) + 1;
2054 * bi_dram[1].size contains all DMC1 memory size
2056 gd->bd->bi_dram[1].size = (size + sz) << 20;
2061 /* Used for sleep test */
2062 static unsigned char saved_val[4][2];
2063 void board_sleep_init_late(void)
2065 /* CODEC_LDO_EN: GPF3[4] */
2066 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2067 /* CODEC_XTAL_EN: GPH3[2] */
2068 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2070 /* MMC T_FLASH off */
2071 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2073 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2074 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2075 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2079 void board_sleep_init(void)
2082 unsigned char val[2];
2084 i2c_set_bus_num(I2C_PMIC);
2086 if (i2c_probe(addr)) {
2087 printf("Can't find max8998\n");
2092 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2093 saved_val[0][0] = val[0];
2094 saved_val[0][1] = val[1];
2095 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2096 (1 << 1) | (1 << 0));
2097 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2098 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2100 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2101 saved_val[1][0] = val[0];
2102 saved_val[1][1] = val[1];
2103 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2104 (1 << 2) | (1 << 1) | (1 << 0));
2106 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2107 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2109 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2110 saved_val[2][0] = val[0];
2111 saved_val[2][1] = val[1];
2112 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2113 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2114 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2116 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2117 saved_val[3][0] = val[0];
2118 saved_val[3][1] = val[1];
2119 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2120 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2121 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2122 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
2123 __FILE__, __LINE__);
2126 void board_sleep_resume(void)
2129 unsigned char val[2];
2133 i2c_set_bus_num(I2C_PMIC);
2135 if (i2c_probe(addr)) {
2136 printf("Can't find max8998\n");
2141 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2142 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2144 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2145 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2147 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2148 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2150 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2151 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2152 printf("Waked up.\n");
2154 /* check max17040 */
2161 #ifdef CONFIG_CMD_USBDOWN
2162 int usb_board_init(void)
2164 #ifdef CONFIG_CMD_PMIC
2165 run_command("pmic ldo 3 on", 0);
2168 if (cpu_is_s5pc100()) {
2169 #ifdef CONFIG_HARD_I2C
2170 uchar val[2] = {0,};
2173 if (i2c_read(0x66, 0, 1, val, 2)) {
2174 printf("i2c_read error\n");
2181 if (i2c_write(0x66, 0, 1, val, 2)) {
2182 printf("i2c_write error\n");
2185 i2c_read(0x66, 0, 1, val, 2);
2191 if (board_is_limo_universal() ||
2192 board_is_limo_real() ||
2194 /* check usb path */
2195 if (board_is_limo_real() && !hwrevision(6))
2199 if (machine_is_tickertape())
2200 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2201 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2207 #ifdef CONFIG_GENERIC_MMC
2208 int board_mmc_init(bd_t *bis)
2212 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2215 /* MMC0 Clock source = SCLKMPLL */
2216 reg = readl(&clk->src4);
2219 writel(reg, &clk->src4);
2221 reg = readl(&clk->div4);
2224 /* set div value near 50MHz */
2225 clock = get_pll_clk(MPLL) / 1000000;
2226 for (i = 0; i < 0xf; i++) {
2227 if ((clock / (i + 1)) <= 50) {
2233 writel(reg, &clk->div4);
2239 * GPG0[2] SD_0_CDn -> Not used
2240 * GPG0[3:6] SD_0_DATA[0:3]
2242 for (i = 0; i < 7; i++) {
2245 /* GPG0[0:6] special function 2 */
2246 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2247 /* GPG0[0:6] pull disable */
2248 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2249 /* GPG0[0:6] drv 4x */
2250 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2253 return s5pc1xx_mmc_init(0);
2257 #ifdef CONFIG_CMD_PMIC
2258 static int pmic_status(void)
2260 unsigned char addr, val[2];
2263 i2c_set_bus_num(I2C_PMIC);
2265 if (i2c_probe(addr)) {
2266 printf("Can't found max8998\n");
2271 i2c_read(addr, reg, 1, val, 1);
2272 for (i = 7; i >= 4; i--)
2273 printf("BUCK%d %s\n", 7 - i + 1,
2274 val[0] & (1 << i) ? "on" : "off");
2276 printf("LDO%d %s\n", 5 - i,
2277 val[0] & (1 << i) ? "on" : "off");
2279 i2c_read(addr, reg, 1, val, 1);
2280 for (i = 7; i >= 0; i--)
2281 printf("LDO%d %s\n", 7 - i + 6,
2282 val[0] & (1 << i) ? "on" : "off");
2284 i2c_read(addr, reg, 1, val, 1);
2285 for (i = 7; i >= 4; i--)
2286 printf("LDO%d %s\n", 7 - i + 14,
2287 val[0] & (1 << i) ? "on" : "off");
2290 i2c_read(addr, reg, 1, val, 1);
2291 for (i = 7; i >= 6; i--)
2292 printf("SAFEOUT%d %s\n", 7 - i + 1,
2293 val[0] & (1 << i) ? "on" : "off");
2297 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2299 unsigned char addr, val[2];
2300 unsigned int reg, shift;
2308 } else if (ldo <= 13) {
2311 } else if (ldo <= 17) {
2313 shift = 17 - ldo + 4;
2320 shift = 4 - buck + 4;
2321 } else if (safeout) {
2325 shift = 8 - safeout;
2329 i2c_set_bus_num(I2C_PMIC);
2331 if (i2c_probe(addr)) {
2332 printf("Can't found max8998\n");
2336 i2c_read(addr, reg, 1, val, 1);
2338 val[0] |= (1 << shift);
2340 val[0] &= ~(1 << shift);
2341 i2c_write(addr, reg, 1, val, 1);
2342 i2c_read(addr, reg, 1, val, 1);
2345 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2346 val[0] & (1 << shift) ? "on" : "off");
2348 printf("buck %d value 0x%x, %s\n", buck, val[0],
2349 val[0] & (1 << shift) ? "on" : "off");
2351 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2352 val[0] & (1 << shift) ? "on" : "off");
2357 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2359 int buck = 0, ldo = 0, safeout = 0, on = -1;
2363 if (strncmp(argv[1], "status", 6) == 0)
2364 return pmic_status();
2367 if (strncmp(argv[1], "ldo", 3) == 0)
2368 ldo = simple_strtoul(argv[2], NULL, 10);
2369 else if (strncmp(argv[1], "buck", 4) == 0)
2370 buck = simple_strtoul(argv[2], NULL, 10);
2371 else if (strncmp(argv[1], "safeout", 7) == 0)
2372 safeout = simple_strtoul(argv[2], NULL, 10);
2376 if (strncmp(argv[3], "on", 2) == 0)
2378 else if (strncmp(argv[3], "off", 3) == 0)
2383 return pmic_ldo_control(buck, ldo, safeout, on);
2394 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2395 "PMIC LDO & BUCK control",
2396 "status - Display PMIC LDO & BUCK status\n"
2397 "pmic ldo num on/off - Turn on/off the LDO\n"
2398 "pmic buck num on/off - Turn on/off the BUCK\n"
2399 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2403 #ifdef CONFIG_CMD_DEVICE_POWER
2417 static void power_display_devices(void)
2419 printf("devices:\n");
2420 printf("\t%d - touch\n", POWER_TOUCH);
2421 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2422 printf("\t%d - LCD\n", POWER_LCD);
2423 printf("\t%d - Haptic\n", POWER_HAPTIC);
2424 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2425 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2426 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2427 printf("\t%d - HDMI\n", POWER_HDMI);
2430 static int power_hdmi(int on)
2432 /* HDMI_EN1: GPJ2[2] */
2433 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2434 /* MHL_ON: GPJ2[3] */
2435 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2439 static int power_bt_wifi(int on)
2441 /* WLAN_BT_EN: GPB[5] */
2442 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2446 static int power_fm_radio(int on)
2448 /* FM_BUS_nRST: GPJ2[5] */
2449 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2453 static int power_audio_codec(int on)
2455 /* CODEC_LDO_EN: GPF3[4] */
2456 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2457 /* CODEC_XTAL_EN: GPH3[2] */
2458 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2462 static int power_haptic(int on)
2464 /* HAPTIC_ON: GPJ1[1] */
2465 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2469 static int power_lcd(int on)
2471 /* MLCD_ON: GPJ1[3] */
2472 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2476 static int power_touch(int on)
2478 /* TOUCH_EN: GPG3[6] */
2479 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2483 static int power_3_touchkey(int on)
2486 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2487 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2488 if (board_rev & J1_B2_BOARD)
2489 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2491 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2493 /* 3_TOUCH_CE - GPJ2[6] */
2494 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2496 /* 3_TOUCH_CE - GPJ2[6] */
2497 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2502 unsigned char val[2];
2503 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2509 i2c_set_bus_num(I2C_GPIO10);
2511 /* Workaround to probe */
2512 if (i2c_probe(addr)) {
2513 if (i2c_probe(addr)) {
2514 printf("Can't found 3 touchkey\n");
2519 #define MCS5000_TK_HW_VERSION 0x06
2520 #define MCS5000_TK_FW_VERSION 0x0A
2521 #define MCS5000_TK_MI_VERSION 0x0B
2523 reg = MCS5000_TK_MI_VERSION;
2524 i2c_read(addr, reg, 1, val, 1);
2525 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2526 reg = MCS5000_TK_HW_VERSION;
2527 i2c_read(addr, reg, 1, val, 1);
2528 printf("H/W 0x%x, ", val[0]);
2529 reg = MCS5000_TK_FW_VERSION;
2530 i2c_read(addr, reg, 1, val, 1);
2531 printf("F/W 0x%x\n", val[0]);
2536 static int power_control(int device, int on)
2540 return power_touch(on);
2541 case POWER_3_TOUCHKEY:
2542 return power_3_touchkey(on);
2544 return power_lcd(on);
2546 return power_haptic(on);
2547 case POWER_AUDIO_CODEC:
2548 return power_audio_codec(on);
2549 case POWER_FM_RADIO:
2550 return power_fm_radio(on);
2552 return power_bt_wifi(on);
2554 return power_hdmi(on);
2556 printf("I don't know device %d\n", device);
2562 static int power_on(int on)
2565 power_3_touchkey(on);
2568 power_audio_codec(on);
2576 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2580 if (!machine_is_aquila())
2585 if (strncmp(argv[1], "on", 2) == 0)
2587 if (strncmp(argv[1], "off", 3) == 0)
2591 device = simple_strtoul(argv[1], NULL, 10);
2595 if (strncmp(argv[2], "on", 2) == 0)
2597 else if (strncmp(argv[2], "off", 3) == 0)
2601 return power_control(device, on);
2607 power_display_devices();
2612 power, CONFIG_SYS_MAXARGS, 1, do_power,
2613 "Device Power Management control",
2614 "device on/off - Turn on/off the device\n"
2617 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2621 if (strncmp(argv[1], "cp", 2) == 0) {
2622 micro_usb_switch(1);
2623 pmic_ldo_control(0, 0, 2, 1);
2625 } else if (strncmp(argv[1], "ap", 2) == 0) {
2626 micro_usb_switch(0);
2627 pmic_ldo_control(0, 0, 2, 0);
2640 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2642 "cp - switch to CP\n"
2643 "microusb ap - switch to AP\n"