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;
47 #define C100_MACH_START 3000
48 #define C110_MACH_START 3100
50 static unsigned int board_rev;
51 static unsigned int battery_soc;
52 static struct s5pc110_gpio *s5pc110_gpio;
68 static struct i2c_gpio_bus_data i2c_2 = {
78 static struct i2c_gpio_bus_data i2c_gpio3 = {
88 static struct i2c_gpio_bus_data i2c_pmic = {
98 static struct i2c_gpio_bus_data i2c_gpio5 = {
108 static struct i2c_gpio_bus_data i2c_gpio6 = {
114 * i2c gpio6 - cypress
118 static struct i2c_gpio_bus_data i2c_cypress_gpio6 = {
124 * i2c gpio7 - cypress
128 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
134 * i2c gpio7 - kessler rev 09
138 static struct i2c_gpio_bus_data i2c_aries_gpio7 = {
144 static struct i2c_gpio_bus i2c_gpio[] = {
160 u32 get_board_rev(void)
165 static int hwrevision(int rev)
167 return (board_rev & 0xf) == rev;
179 #define SPLIT_SCREEN_FEATURE 0x100
181 /* board is MACH_AQUILA and board is like below. */
182 #define J1_B2_BOARD 0x200
183 #define LIMO_UNIVERSAL_BOARD 0x400
184 #define LIMO_REAL_BOARD 0x800
185 #define MEDIA_BOARD 0x1000
186 #define BAMBOO_BOARD 0x2000
189 #define ARIES_BOARD 0x4000
192 /* board is MACH_P1P2 and board is like below. */
193 #define P1_REAL_BOARD 0x200
194 #define P2_REAL_BOARD 0x400
196 #define BOARD_MASK 0xF00
198 static int c110_machine_id(void)
200 return gd->bd->bi_arch_number - C110_MACH_START;
203 static int machine_is_aquila(void)
205 return c110_machine_id() == MACH_AQUILA;
208 static int machine_is_p1p2(void)
210 return c110_machine_id() == MACH_P1P2;
213 static int machine_is_tickertape(void)
215 return c110_machine_id() == MACH_TICKERTAPE;
218 static int machine_is_geminus(void)
220 return c110_machine_id() == MACH_GEMINUS;
223 static int machine_is_cypress(void)
225 return c110_machine_id() == MACH_CYPRESS;
228 static int board_is_limo_universal(void)
230 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
233 static int board_is_limo_real(void)
235 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
238 static int board_is_media(void)
240 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
243 static int board_is_bamboo(void)
245 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
248 static int board_is_j1b2(void)
250 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
254 static int board_is_aries(void)
256 return machine_is_aquila() && (board_rev & ARIES_BOARD);
260 static int board_is_p2_real(void)
262 return machine_is_p1p2() && (board_rev & P2_REAL_BOARD);
265 static void enable_battery(void);
267 void i2c_init_board(void)
269 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
272 if (cpu_is_s5pc100())
275 num_bus = ARRAY_SIZE(i2c_gpio);
277 if (machine_is_cypress()) {
278 i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
279 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
280 i2c_gpio[I2C_GPIO7].bus->gpio_base =
281 (unsigned int)&gpio->gpio_mp0_5;
284 else if (board_is_aries()) {
285 i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
286 i2c_gpio[I2C_GPIO7].bus = &i2c_aries_gpio7;
287 i2c_gpio[I2C_GPIO7].bus->gpio_base =
288 (unsigned int)&gpio->gpio_mp0_5;
295 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
296 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
297 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
298 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
299 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
301 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
303 /* Reset on max17040 early */
304 if (battery_soc == 0)
308 #ifdef CONFIG_MISC_INIT_R
309 #define DEV_INFO_LEN 512
310 static char device_info[DEV_INFO_LEN];
311 static int display_info;
313 static void dprintf(const char *fmt, ...)
320 i = vsprintf(buf, fmt, args);
325 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
326 puts("Flushing device info...\n");
330 strcat(device_info, buf);
334 #ifdef CONFIG_S5PC1XXFB
335 static void display_device_info(void)
342 set_font_color(FONT_WHITE);
343 fb_printf(device_info);
346 memset(device_info, 0x0, DEV_INFO_LEN);
348 udelay(5 * 1000 * 1000);
352 static const char *board_name[] = {
368 static char feature_buffer[32];
370 static char *display_features(int board, int board_rev)
373 char *buf = feature_buffer;
375 if (board == MACH_AQUILA) {
376 if (board_rev & SPLIT_SCREEN_FEATURE)
377 count += sprintf(buf + count, " - SplitScreen");
378 if (board_rev & J1_B2_BOARD)
379 count += sprintf(buf + count, " - J1 B2 board");
380 /* Limo Real or Universal */
381 if (board_rev & LIMO_REAL_BOARD)
382 count += sprintf(buf + count, " - Limo Real");
383 else if (board_rev & LIMO_UNIVERSAL_BOARD)
384 count += sprintf(buf + count, " - Limo Universal");
385 if (board_rev & MEDIA_BOARD)
386 count += sprintf(buf + count, " - Media");
387 if (board_rev & BAMBOO_BOARD)
388 count += sprintf(buf + count, " - Bamboo");
390 if (board_rev & ARIES_BOARD)
391 count += sprintf(buf + count, " - Aries");
393 } else if (board == MACH_P1P2) {
395 if (board_rev & P1_REAL_BOARD)
396 count += sprintf(buf + count, " - P1 Real");
397 else if (board_rev & P2_REAL_BOARD)
398 count += sprintf(buf + count, " - P2 Real");
400 count += sprintf(buf + count, " - Universal");
406 static void check_board_revision(int board, int rev)
410 /* Limo Real or Universal */
411 if (rev & LIMO_UNIVERSAL_BOARD)
412 board_rev &= ~J1_B2_BOARD;
413 if (rev & LIMO_REAL_BOARD) {
414 board_rev &= ~(J1_B2_BOARD |
415 LIMO_UNIVERSAL_BOARD);
418 if (rev & ARIES_BOARD)
419 board_rev &= ~(J1_B2_BOARD);
421 if (rev & MEDIA_BOARD)
422 board_rev &= ~(J1_B2_BOARD |
423 LIMO_UNIVERSAL_BOARD);
424 if (rev & BAMBOO_BOARD)
425 board_rev &= ~(J1_B2_BOARD |
426 LIMO_UNIVERSAL_BOARD |
433 /* There's no HWREV_MODE3 */
434 board_rev &= ~(1 << 3);
436 case MACH_TICKERTAPE:
438 board_rev &= ~BOARD_MASK;
445 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank)
449 gpio_direction_input(bank, 2);
450 gpio_direction_input(bank, 3);
451 gpio_direction_input(bank, 4);
452 gpio_direction_input(bank, 7);
454 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
455 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
456 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
457 gpio_set_pull(bank, 7, GPIO_PULL_NONE); /* HWREV_MODE3 */
459 rev = gpio_get_value(bank, 2);
460 rev |= (gpio_get_value(bank, 3) << 1);
461 rev |= (gpio_get_value(bank, 4) << 2);
462 rev |= (gpio_get_value(bank, 7) << 3);
466 gpio_direction_input(bank, 1);
467 gpio_direction_input(bank, 2);
468 gpio_direction_input(bank, 3);
469 gpio_direction_input(bank, 4);
471 gpio_set_pull(bank, 1, GPIO_PULL_NONE); /* HWREV_MODE3 */
472 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
473 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
474 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
476 rev = gpio_get_value(bank, 2);
477 rev |= (gpio_get_value(bank, 3) << 1);
478 rev |= (gpio_get_value(bank, 4) << 2);
479 rev |= (gpio_get_value(bank, 1) << 3);
485 static void check_hw_revision(void)
487 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
489 if (cpu_is_s5pc100()) {
490 struct s5pc100_gpio *gpio =
491 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
493 board_rev = get_hw_revision(&gpio->gpio_j0);
495 /* C100 TickerTape */
497 board = MACH_TICKERTAPE;
499 struct s5pc110_gpio *gpio =
500 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
502 board_rev = get_hw_revision(&gpio->gpio_j0);
505 * Note Check 'Aquila' board first
509 * LRA: Limo Real Aquila
510 * LUA: Limo Universal Aquila
516 * ADDR = 0xE0200000 + OFF
518 * OFF Universal BB LRA LUA OA TT SS P1P2 CYP
519 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00 0x00
520 * J2: 0x0284 0x01 0x10 0x00
521 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x18 0x0F
522 * H3: 0x0C64 0x03 0x07 0x0F 0xff
523 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
524 * I: 0x0224 0x02 0x00 0x08
525 * MP03: 0x0324 0x9x 0xbx 0x9x
526 * MP05: 0x0364 0x80 0x88
530 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
532 board_rev |= J1_B2_BOARD;
534 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
535 gpio_direction_input(&gpio->gpio_j2, 6);
539 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
540 board_rev |= LIMO_UNIVERSAL_BOARD;
542 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
543 board_rev |= ARIES_BOARD;
546 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
547 board_rev |= LIMO_REAL_BOARD;
549 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
550 board_rev |= MEDIA_BOARD;
552 /* set gpio to default value. */
553 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
554 gpio_direction_output(&gpio->gpio_j2, 6, 0);
556 /* Workaround: C110 Aquila Rev0.6 */
557 if (board_rev == 6) {
559 board_rev |= LIMO_REAL_BOARD;
561 /* C110 Aquila Bamboo */
562 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
564 board_rev |= BAMBOO_BOARD;
567 /* C110 TickerTape */
568 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
569 gpio_get_value(&gpio->gpio_d1, 1) == 0)
570 board = MACH_TICKERTAPE;
572 /* C110 Cypress: Do first this than P1P2 */
573 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
574 gpio_direction_input(&gpio->gpio_j2, 2);
575 if (gpio_get_value(&gpio->gpio_j2, 2) == 1)
576 board = MACH_CYPRESS;
577 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
580 if (gpio_get_value(&gpio->gpio_h3, 7) == 1) {
582 board_rev &= ~BOARD_MASK;
585 /* set gpio configuration for P1P2. */
586 gpio_direction_input(&gpio->gpio_j0, 6);
587 gpio_direction_input(&gpio->gpio_j0, 7);
590 * do not change order below
591 * because it needs delay to get gpio value.
594 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_NONE);
596 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
598 if (gpio_get_value(&gpio->gpio_j0, 7) == 1) {
600 board_rev &= ~BOARD_MASK;
601 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
602 board_rev |= P1_REAL_BOARD;
603 if (gpio_get_value(&gpio->gpio_j0, 6) == 0)
604 board_rev |= P2_REAL_BOARD;
607 /* set gpio to default value. */
609 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
611 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_DOWN);
613 /* C110 Geminus for rev0.0 */
614 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
615 gpio_direction_input(&gpio->gpio_j1, 2);
616 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
617 board = MACH_GEMINUS;
618 if ((board_rev & ~BOARD_MASK) == 3)
621 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
622 gpio_direction_output(&gpio->gpio_j1, 2, 0);
624 /* C110 Geminus for rev0.1 ~ */
625 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
626 gpio_direction_input(&gpio->gpio_j0, 6);
627 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
628 board = MACH_GEMINUS;
629 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
633 if (cpu_is_s5pc110())
634 gd->bd->bi_arch_number = C110_MACH_START + board;
636 gd->bd->bi_arch_number = C100_MACH_START + board;
638 /* Architecture Common settings */
639 if (cpu_is_s5pc110()) {
640 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
642 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
644 setenv("updatek", "onenand erase 0x60000 0x300000; "
645 "onenand write 0x31008000 0x60000 0x300000");
649 static void show_hw_revision(void)
654 * Workaround for Rev 0.3 + CP Ver ES 3.1
657 if (board_is_limo_real()) {
659 /* default is Rev 0.4 */
665 if (cpu_is_s5pc110())
666 board = gd->bd->bi_arch_number - C110_MACH_START;
668 board = gd->bd->bi_arch_number - C100_MACH_START;
670 check_board_revision(board, board_rev);
672 /* Set CPU Revision */
673 if (board_is_limo_real()) {
674 if ((board_rev & 0xf) < 8)
675 s5pc1xx_set_cpu_rev(0);
677 s5pc1xx_set_cpu_rev(0);
680 dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
681 display_features(board, board_rev));
684 static void check_auto_burn(void)
686 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
687 unsigned int count = 0;
690 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
691 printf("Auto burning bootloader\n");
692 count += sprintf(buf + count, "run updateb; ");
694 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
695 printf("Auto burning kernel\n");
696 count += sprintf(buf + count, "run updatek; ");
700 count += sprintf(buf + count, "reset");
701 setenv("bootcmd", buf);
704 /* Clear the magic value */
705 writel(0xa5a55a5a, magic_base);
706 writel(0xa5a55a5a, magic_base + 0x4);
709 static void pmic_pin_init(void)
711 unsigned int reg, value;
713 if (cpu_is_s5pc100())
716 /* AP_PS_HOLD: XEINT_0: GPH0[0]
717 * Note: Don't use GPIO PS_HOLD it doesn't work
719 reg = S5PC110_PS_HOLD_CONTROL;
721 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
722 S5PC110_PS_HOLD_DATA_HIGH |
723 S5PC110_PS_HOLD_OUT_EN;
726 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
727 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
728 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
731 static void enable_ldos(void)
733 if (cpu_is_s5pc100())
736 if (machine_is_p1p2())
739 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
740 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
743 static void enable_t_flash(void)
745 if (!(board_is_limo_universal() || board_is_limo_real()))
748 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
749 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
752 static void setup_limo_real_gpios(void)
754 if (!board_is_limo_real())
758 * Note: Please write GPIO alphabet order
760 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
761 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
764 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
765 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
767 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
768 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
770 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
771 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
772 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
775 static void setup_media_gpios(void)
777 if (!board_is_media())
781 * Note: Please write GPIO alphabet order
783 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
784 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
786 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
787 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
788 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
791 static void setup_p1p2_gpios(void)
793 if (!machine_is_p1p2())
797 * Note: Please write GPIO alphabet order
799 /* RESET_REQ_N: XM0FRnB[1]: MP0_3[5] output high */
800 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 5, 1);
801 /* CODEC_LDO_EN: XM0FRnB[2]: MP0_3[6] output high */
802 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 6, 1);
805 #define KBR3 (1 << 3)
806 #define KBR2 (1 << 2)
807 #define KBR1 (1 << 1)
808 #define KBR0 (1 << 0)
810 static void check_p2_keypad(void)
812 unsigned int auto_download = 0;
813 unsigned char addr = 0x34, val[2]; /* adp5587 key controller */
815 i2c_set_bus_num(I2C_2);
817 if (i2c_probe(addr)) {
818 printf("Can't found adp5587 key controller\n");
821 /* Row 8, Column 10 */
823 ret = i2c_write(addr, 0x1D, 1, val, 1); /* Set KP_GPIO1 */
825 ret |= i2c_write(addr, 0x1E, 1, val, 1); /* Set KP_GPIO2 */
827 ret |= i2c_write(addr, 0x1F, 1, val, 1); /* Set KP_GPIO3 */
828 val[0] = 0x3f; /* CMP2_INT | CMP1_INT | OVR_FLOW_INT |
829 K_LCK_INT | GPI_INT | KE_INT */
830 ret |= i2c_write(addr, 0x02, 1, val, 1); /* Status is W1C */
831 val[0] = 0x19; /* INT_CFG | OVR_FLOW_IEN | KE_IEN */
832 ret |= i2c_write(addr, 0x01, 1, val, 1);
833 for (i = 0; i < 10; i++) {
834 udelay(1000); /* FIXME */
835 i2c_read(addr, 0x04 + i, 1, val, 1);
840 if (auto_download == 1)
841 setenv("bootcmd", "usbdown");
844 static void check_keypad(void)
846 unsigned int reg, value;
847 unsigned int col_mask, row_mask;
848 unsigned int auto_download = 0;
849 unsigned int col_value[4], i;
851 if (cpu_is_s5pc100()) {
852 struct s5pc100_gpio *gpio =
853 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
855 /* Set GPH2[2:0] to KP_COL[2:0] */
856 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
857 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
858 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
860 /* Set GPH3[2:0] to KP_ROW[2:0] */
861 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
862 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
863 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
865 reg = S5PC100_KEYPAD_BASE;
867 if (board_is_limo_real() || board_is_limo_universal()) {
875 for (i = 0; i < 4; i++) {
876 /* Set GPH3[3:0] to KP_ROW[3:0] */
877 if (row_mask & (0xF << (i << 2))) {
878 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
879 if (!machine_is_p1p2())
880 gpio_set_pull(&s5pc110_gpio->gpio_h3,
884 /* Set GPH2[3:0] to KP_COL[3:0] */
885 if (col_mask & (0xF << (i << 2)))
886 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
887 if (machine_is_p1p2())
888 gpio_set_pull(&s5pc110_gpio->gpio_h2, i, GPIO_PULL_UP);
891 reg = S5PC110_KEYPAD_BASE;
895 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
896 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
897 /* VOLUMEDOWN and CAM(Half shot) Button */
898 if ((value & KBR1) == 0) {
901 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
904 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
906 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
908 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
910 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
912 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
915 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
917 if (machine_is_p1p2()) {
918 if ((col_value[0] & 0xd) == 0xd)
924 setenv("bootcmd", "usbdown");
927 static void enable_battery(void)
929 unsigned char val[2];
930 unsigned char addr = 0x36; /* max17040 fuel gauge */
932 if (machine_is_aquila()) {
937 if (machine_is_tickertape())
940 if (machine_is_cypress())
941 i2c_set_bus_num(I2C_GPIO7);
943 i2c_set_bus_num(I2C_GPIO3);
945 if (i2c_probe(addr)) {
946 printf("Can't found max17040 fuel gauge\n");
952 i2c_write(addr, 0xfe, 1, val, 2);
955 static void check_battery(void)
957 unsigned char val[2];
958 unsigned char addr = 0x36; /* max17040 fuel gauge */
960 if (machine_is_aquila()) {
965 if (machine_is_tickertape())
968 if (machine_is_cypress())
969 i2c_set_bus_num(I2C_GPIO7);
971 i2c_set_bus_num(I2C_GPIO3);
973 if (i2c_probe(addr)) {
974 printf("Can't found max17040 fuel gauge\n");
978 i2c_read(addr, 0x04, 1, val, 1);
980 dprintf("battery:\t%d%%\n", val[0]);
982 battery_soc = val[0];
985 static void check_mhl(void)
987 unsigned char val[2];
988 unsigned char addr = 0x39; /* SIL9230 */
990 /* MHL Power enable */
991 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
992 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
994 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
995 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
997 /* 10ms required after reset */
1001 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
1003 i2c_set_bus_num(I2C_GPIO5);
1006 if (i2c_probe(addr)) {
1007 printf("Can't found MHL Chip\n");
1013 * set to Normal operation
1016 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
1017 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
1022 * 00 = MHL termination ON
1023 * 11 = MHL termination OFF
1026 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1027 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1030 #define CHARGER_ANIMATION_FRAME 6
1031 static int max8998_power_key(void)
1033 unsigned char addr, val[2];
1034 i2c_set_bus_num(I2C_PMIC);
1036 if (i2c_probe(addr)) {
1037 printf("Can't found max8998\n");
1041 /* Accessing IRQ1 register */
1042 i2c_read(addr, 0x00, 1, val, 1);
1043 printf("MAX8998 IRQ1 = 0x%x\n", val[0]);
1044 if (val[0] & (1 << 6))
1050 static void into_charge_mode(void)
1052 unsigned char addr = 0xCC >> 1; /* max8998 */;
1053 unsigned char val[2];
1056 bmp_image_t *bmp[CHARGER_ANIMATION_FRAME];
1057 unsigned long len[CHARGER_ANIMATION_FRAME];
1058 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1060 i2c_set_bus_num(I2C_PMIC);
1062 if (i2c_probe(addr)) {
1063 printf("Can't found max8998\n");
1067 printf("Charge Mode\n");
1069 i2c_read(addr, 0x0C, 1, val, 1);
1070 val[0] &= ~(0x7 << 0);
1071 val[0] |= 5; /* 600mA */
1072 i2c_write(addr, 0x0C, 1, val, 1);
1074 #ifdef CONFIG_S5PC1XXFB
1077 /* TODO: write the image-text for the charger */
1079 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1080 if (level >= CHARGER_ANIMATION_FRAME)
1081 level = CHARGER_ANIMATION_FRAME - 1;
1083 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1084 bmp_addr[i] = (ulong)battery_charging_animation[i];
1086 lcd_display_clear();
1087 for (i = 0; i < 3; i++) {
1088 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1091 bmp[j] = gunzip_bmp(bmp_addr[j], &len[j]);
1092 lcd_display_bitmap((ulong) bmp[j], 140, 202);
1095 for (k = 0; k < 10; k++)
1096 if (max8998_power_key())
1100 if (max8998_power_key())
1107 /* EVT0: sleep 1, EVT1: sleep */
1108 if (s5pc1xx_get_cpu_rev() == 0) {
1109 run_command("sleep 1", 0);
1113 run_command("sleep", 0);
1116 static void check_micro_usb(int intr)
1119 unsigned char val[2];
1120 static int started_charging_once = 0;
1122 if (cpu_is_s5pc100())
1125 if (board_is_limo_real()) {
1126 if (hwrevision(0) || hwrevision(1))
1130 if (machine_is_cypress())
1131 i2c_set_bus_num(I2C_GPIO6);
1133 if (board_is_aries())
1134 i2c_set_bus_num(I2C_GPIO6);
1137 i2c_set_bus_num(I2C_PMIC);
1139 addr = 0x25; /* fsa9480 */
1140 if (i2c_probe(addr)) {
1141 printf("Can't found fsa9480\n");
1145 /* Clear Interrupt */
1147 i2c_read(addr, 0x03, 1, val, 2);
1151 /* Read Device Type 1 */
1152 i2c_read(addr, 0x0a, 1, val, 1);
1154 #define FSA_DEDICATED_CHARGER (1 << 6)
1155 #define FSA_UART (1 << 3)
1156 #define FSA_USB (1 << 2)
1159 * If USB, use default 475mA
1160 * If Charger, use 600mA and go to charge mode
1162 if ((val[0] & FSA_DEDICATED_CHARGER) && !started_charging_once) {
1163 started_charging_once = 1;
1167 /* If Factory Mode is Boot ON-USB, go to download mode */
1168 i2c_read(addr, 0x07, 1, val, 1);
1170 #define FSA_ADC_FAC_USB 0x19
1171 #define FSA_ADC_FAC_UART 0x1d
1173 if (val[0] == FSA_ADC_FAC_USB)
1174 setenv("bootcmd", "usbdown");
1177 static void micro_usb_switch(int path)
1180 unsigned char val[2];
1182 if (machine_is_cypress())
1183 i2c_set_bus_num(I2C_GPIO6);
1185 if (board_is_aries())
1186 i2c_set_bus_num(I2C_GPIO6);
1189 i2c_set_bus_num(I2C_PMIC);
1191 addr = 0x25; /* fsa9480 */
1192 if (i2c_probe(addr)) {
1193 printf("Can't found fsa9480\n");
1198 val[0] = 0x90; /* VAUDIO */
1200 val[0] = 0x24; /* DHOST */
1202 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1204 i2c_read(addr, 0x2, 1, val, 1);
1205 val[0] &= ~(1 << 2);
1206 i2c_write(addr, 0x2, 1, val, 1);
1209 #define MAX8998_REG_ONOFF1 0x11
1210 #define MAX8998_REG_ONOFF2 0x12
1211 #define MAX8998_REG_ONOFF3 0x13
1212 #define MAX8998_LDO3 (1 << 2)
1213 #define MAX8998_LDO10 (1 << 3)
1214 #define MAX8998_LDO11 (1 << 2)
1215 #define MAX8998_LDO12 (1 << 1)
1216 #define MAX8998_LDO13 (1 << 0)
1217 #define MAX8998_LDO14 (1 << 7)
1218 #define MAX8998_LDO15 (1 << 6)
1219 #define MAX8998_LDO16 (1 << 5)
1220 #define MAX8998_LDO17 (1 << 4)
1223 #define MAX8998_REG_LDO7 0x21
1224 #define MAX8998_REG_LDO17 0x29
1227 static void init_pmic(void)
1230 unsigned char val[2];
1232 unsigned char val2[2];
1235 if (cpu_is_s5pc100())
1238 i2c_set_bus_num(I2C_PMIC);
1240 addr = 0xCC >> 1; /* max8998 */
1241 if (i2c_probe(addr)) {
1242 printf("Can't found max8998\n");
1247 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1248 val[0] &= ~MAX8998_LDO3;
1249 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1252 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1254 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1255 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1257 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1258 MAX8998_LDO12 | MAX8998_LDO13);
1262 val[0] |= ((1 << 7)|(1 << 6));
1264 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1265 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1267 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1268 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1270 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1273 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1274 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1276 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1277 MAX8998_LDO16 | MAX8998_LDO17);
1281 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1282 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1284 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1287 val[0] |= MAX8998_LDO17;
1289 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1290 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1292 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1293 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1296 #define PDN_MASK(x) (0x3 << ((x) << 1))
1298 #define CON_INPUT(x) (0x0 << ((x) << 2))
1299 #define CON_OUTPUT(x) (0x1 << ((x) << 2))
1300 #define CON_IRQ(x) (0xf << ((x) << 2))
1302 #define DAT_SET(x) (0x1 << (x))
1303 #define DAT_CLEAR(x) (0x0 << (x))
1305 #define OUTPUT0(x) (0x0 << ((x) << 1))
1306 #define OUTPUT1(x) (0x1 << ((x) << 1))
1307 #define INPUT(x) (0x2 << ((x) << 1))
1309 #define PULL_DIS(x) (0x0 << ((x) << 1))
1310 #define PULL_DOWN(x) (0x1 << ((x) << 1))
1311 #define PULL_UP(x) (0x2 << ((x) << 1))
1313 #define PREVIOUS(x) (0x3 << ((x) << 1))
1315 struct gpio_powermode {
1316 unsigned int conpdn;
1317 unsigned int pudpdn;
1320 struct gpio_external {
1326 static struct gpio_powermode powerdown_modes[] = {
1327 { /* S5PC110_GPIO_A0_OFFSET */
1328 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
1329 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1330 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1331 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1332 }, { /* S5PC110_GPIO_A1_OFFSET */
1333 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
1334 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1335 }, { /* S5PC110_GPIO_B_OFFSET */
1336 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1337 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1338 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1339 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1340 }, { /* S5PC110_GPIO_C0_OFFSET */
1341 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1343 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1345 }, { /* S5PC110_GPIO_C1_OFFSET */
1346 /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1348 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1350 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1352 }, { /* S5PC110_GPIO_D0_OFFSET */
1353 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
1354 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1355 }, { /* S5PC110_GPIO_D1_OFFSET */
1356 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1357 INPUT(4) | INPUT(5),
1358 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1359 PULL_DIS(4) | PULL_DIS(5),
1360 }, { /* S5PC110_GPIO_E0_OFFSET */
1361 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1362 INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
1363 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
1364 PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
1365 }, { /* S5PC110_GPIO_E1_OFFSET */
1366 INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
1368 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
1370 }, { /* S5PC110_GPIO_F0_OFFSET */
1371 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1372 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1373 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1374 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1375 }, { /* S5PC110_GPIO_F1_OFFSET */
1376 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1377 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1378 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1379 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1380 }, { /* S5PC110_GPIO_F2_OFFSET */
1381 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1382 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1383 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1384 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1385 }, { /* S5PC110_GPIO_F3_OFFSET */
1386 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1387 OUTPUT0(4) | OUTPUT0(5),
1388 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1389 PULL_DIS(4) | PULL_DIS(5),
1390 }, { /* S5PC110_GPIO_G0_OFFSET */
1391 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1392 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1393 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1394 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1395 }, { /* S5PC110_GPIO_G1_OFFSET */
1396 OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
1397 INPUT(4) | INPUT(5) | INPUT(6),
1398 PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
1399 PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
1400 }, { /* S5PC110_GPIO_G2_OFFSET */
1401 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1402 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1403 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1404 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1405 }, { /* S5PC110_GPIO_G3_OFFSET */
1406 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
1407 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1408 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1409 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1410 }, { /* S5PC110_GPIO_I_OFFSET */
1411 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1412 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1413 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1414 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1415 }, { /* S5PC110_GPIO_J0_OFFSET */
1416 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1417 INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
1418 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1419 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1420 }, { /* S5PC110_GPIO_J1_OFFSET */
1421 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1422 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1423 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1424 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1425 }, { /* S5PC110_GPIO_J2_OFFSET */
1426 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1427 INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1428 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1429 PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
1430 }, { /* S5PC110_GPIO_J3_OFFSET */
1431 INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
1432 OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1433 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
1434 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1435 }, { /* S5PC110_GPIO_J4_OFFSET */
1436 INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1438 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1440 }, { /* S5PC110_MP0_1_OFFSET */
1441 /* XM0CSN[4]: MP0_1[4] -> output high */
1442 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1443 OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
1444 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1445 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1446 }, { /* S5PC110_MP0_2_OFFSET */
1447 OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1448 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1449 }, { /* S5PC110_MP0_3_OFFSET */
1450 /* XM0FWEN: MP0_3[2] -> output high */
1451 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1452 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1453 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1454 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1455 }, { /* S5PC110_MP0_4_OFFSET */
1456 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1457 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1458 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
1459 PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1460 }, { /* S5PC110_MP0_5_OFFSET */
1461 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1462 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1463 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1464 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1465 }, { /* S5PC110_MP0_6_OFFSET */
1466 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1467 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1468 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1469 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1470 }, { /* S5PC110_MP0_7_OFFSET */
1471 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1472 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1473 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1474 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1478 static struct gpio_external external_powerdown_modes[] = {
1479 { /* S5PC110_GPIO_H0_OFFSET */
1480 CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1481 CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1482 DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
1483 DAT_CLEAR(4) | DAT_CLEAR(5),
1484 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1485 PULL_DIS(4) | PULL_DIS(5),
1486 }, { /* S5PC110_GPIO_H1_OFFSET */
1487 /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1488 CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1490 PULL_DOWN(0) | PULL_DOWN(1) |
1492 CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1493 CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
1495 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1497 }, { /* S5PC110_GPIO_H2_OFFSET */
1498 CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1499 CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
1500 DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
1502 }, { /* S5PC110_GPIO_H3_OFFSET */
1503 CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
1504 CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
1505 DAT_CLEAR(3) | DAT_CLEAR(7),
1510 static void setup_power_down_mode_registers(void)
1512 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1513 struct s5pc1xx_gpio_bank *bank;
1514 struct gpio_powermode *p;
1515 struct gpio_external *ge;
1518 if (cpu_is_s5pc100())
1521 if (!(machine_is_aquila() && board_is_limo_real()))
1524 bank = &gpio->gpio_a0;
1525 p = powerdown_modes;
1527 for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
1528 writel(p->conpdn, &bank->pdn_con);
1529 writel(p->pudpdn, &bank->pdn_pull);
1532 writel(0xff0022b0, (unsigned int *)0xF0000000);
1533 writel(0xff0022b0, (unsigned int *)0xF1400000);
1536 bank = &gpio->gpio_h0;
1537 ge = external_powerdown_modes;
1539 for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
1540 writel(ge->con, &bank->con);
1541 writel(ge->dat, &bank->dat);
1542 writel(ge->pud, &bank->pull);
1550 struct s6e63m0_platform_data {
1551 struct s5pc1xx_gpio_bank *bank;
1555 extern void s6e63m0_set_spi_interface(struct s6e63m0_platform_data *cs,
1556 struct s6e63m0_platform_data *clk, struct s6e63m0_platform_data *si,
1557 struct s6e63m0_platform_data *so);
1559 struct s6e63m0_platform_data pd_cs, pd_clk, pd_si, pd_so;
1560 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1562 void lcd_cfg_gpio(void)
1564 unsigned int i, f3_end = 4;
1566 for (i = 0; i < 8; i++) {
1567 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1568 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1569 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1570 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1571 /* pull-up/down disable */
1572 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1573 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1574 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1576 /* drive strength to max (24bit) */
1577 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1578 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1579 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1580 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1581 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1582 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1585 /* set DISPLAY_DE_B pin for dual rgb mode. */
1586 if (board_is_media())
1589 for (i = 0; i < f3_end; i++) {
1590 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1591 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1592 /* pull-up/down disable */
1593 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1594 /* drive strength to max (24bit) */
1595 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1596 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1598 /* display output path selection (only [1:0] valid) */
1599 writel(0x2, 0xE0107008);
1601 /* gpio pad configuration for LCD reset. */
1602 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1604 /* gpio pad configuration for LCD ON. */
1605 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1609 if (board_is_p2_real())
1610 gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
1613 /* LCD_BACKLIGHT_EN */
1614 if (machine_is_geminus())
1615 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1618 * gpio pad configuration for
1619 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1621 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1622 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1623 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1624 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1626 if (machine_is_aquila()) {
1627 pd_cs.bank = &gpio_base->gpio_mp0_1;
1629 pd_clk.bank = &gpio_base->gpio_mp0_4;
1631 pd_si.bank = &gpio_base->gpio_mp0_4;
1633 pd_so.bank = &gpio_base->gpio_mp0_4;
1636 /* these data would be sent to s6e63m0 lcd panel driver. */
1637 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, &pd_so);
1640 if (machine_is_cypress()) {
1641 #if 0 /* universal cypress */
1643 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1646 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1648 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1650 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1652 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1654 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1655 #if 0 /* universal cypress */
1656 pd_cs.bank = &gpio_base->gpio_mp0_1;
1659 pd_cs.bank = &gpio_base->gpio_mp0_5;
1661 pd_clk.bank = &gpio_base->gpio_mp0_4;
1663 pd_si.bank = &gpio_base->gpio_mp0_4;
1666 /* these data would be sent to s6e63m0 lcd panel driver. */
1667 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, NULL);
1673 void backlight_on(unsigned int onoff)
1675 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1678 if (machine_is_geminus())
1679 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1681 if (machine_is_geminus())
1682 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1686 void reset_lcd(void)
1688 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1690 if (machine_is_aquila() || machine_is_geminus())
1691 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1692 if (machine_is_cypress())
1693 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1696 void lcd_power_on(unsigned int onoff)
1698 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1701 if (machine_is_aquila() || machine_is_geminus())
1702 gpio_set_value(&gpio->gpio_j1, 3, 1);
1704 if (machine_is_cypress())
1705 gpio_set_value(&gpio->gpio_g2, 2, 1);
1708 if (board_is_p2_real())
1709 gpio_set_value(&gpio->gpio_j1, 4, 1);
1713 if (board_is_aries())
1716 unsigned char val[2];
1717 unsigned char val2[2];
1719 i2c_set_bus_num(I2C_PMIC);
1720 addr = 0xCC >> 1; /* max8998 */
1721 if (i2c_probe(addr)) {
1722 printf("Can't found max8998\n");
1726 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1729 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1730 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1731 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1732 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1734 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1735 val[0] |= MAX8998_LDO17;
1737 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1738 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1739 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1740 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1746 if (machine_is_aquila() || machine_is_geminus())
1747 gpio_set_value(&gpio->gpio_j1, 3, 0);
1749 if (machine_is_cypress())
1750 gpio_set_value(&gpio->gpio_g2, 2, 0);
1753 if (board_is_p2_real())
1754 gpio_set_value(&gpio->gpio_j1, 4, 0);
1758 if (board_is_aries())
1761 unsigned char val[2];
1763 i2c_set_bus_num(I2C_PMIC);
1764 addr = 0xCC >> 1; /* max8998 */
1765 if (i2c_probe(addr)) {
1766 printf("Can't found max8998\n");
1770 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1771 val[0] &= ~(1 << 7);
1772 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1773 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1775 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1776 val[0] &= ~MAX8998_LDO17;
1777 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1778 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1785 extern void s6e63m0_cfg_ldo(void);
1786 extern void s6e63m0_enable_ldo(unsigned int onoff);
1788 void init_panel_info(vidinfo_t *vid)
1790 vid->cfg_gpio = NULL;
1791 vid->reset_lcd = NULL;
1792 vid->backlight_on = NULL;
1793 vid->lcd_power_on = NULL;
1795 vid->cfg_ldo = NULL;
1796 vid->enable_ldo = NULL;
1798 vid->init_delay = 0;
1799 vid->reset_delay = 0;
1800 vid->power_on_delay = 0;
1805 vid->vl_width = 480;
1806 vid->vl_height = 800;
1808 vid->dual_lcd_enabled = 0;
1810 if (board_is_media()) {
1813 vid->vl_width = 960;
1814 vid->vl_height = 800;
1816 /* enable dual lcd mode. */
1817 vid->dual_lcd_enabled = 1;
1820 vid->vl_clkp = CONFIG_SYS_HIGH;
1821 vid->vl_hsp = CONFIG_SYS_LOW;
1822 vid->vl_vsp = CONFIG_SYS_LOW;
1823 vid->vl_dp = CONFIG_SYS_HIGH;
1826 /* S6E63M0 LCD Panel */
1835 if (machine_is_aquila() || machine_is_cypress()) {
1836 vid->cfg_gpio = lcd_cfg_gpio;
1837 vid->reset_lcd = reset_lcd;
1838 vid->backlight_on = backlight_on;
1839 vid->lcd_power_on = lcd_power_on;
1841 vid->cfg_ldo = s6e63m0_cfg_ldo;
1842 vid->enable_ldo = s6e63m0_enable_ldo;
1844 vid->init_delay = 25000;
1845 vid->reset_delay = 120000;
1848 if (machine_is_geminus()) {
1852 vid->vl_width = 1024,
1853 vid->vl_height = 600,
1854 vid->vl_clkp = CONFIG_SYS_LOW,
1855 vid->vl_hsp = CONFIG_SYS_HIGH,
1856 vid->vl_vsp = CONFIG_SYS_HIGH,
1857 vid->vl_dp = CONFIG_SYS_LOW,
1868 vid->cfg_gpio = lcd_cfg_gpio;
1869 vid->reset_lcd = reset_lcd;
1870 vid->backlight_on = backlight_on;
1871 vid->lcd_power_on = lcd_power_on;
1877 vid->vl_width = 480,
1878 vid->vl_height = 800,
1879 vid->vl_clkp = CONFIG_SYS_HIGH,
1880 vid->vl_hsp = CONFIG_SYS_LOW,
1881 vid->vl_vsp = CONFIG_SYS_LOW,
1882 vid->vl_dp = CONFIG_SYS_HIGH,
1898 vid->vl_width = 1024,
1899 vid->vl_height = 600,
1900 vid->vl_clkp = CONFIG_SYS_HIGH,
1901 vid->vl_hsp = CONFIG_SYS_HIGH,
1902 vid->vl_vsp = CONFIG_SYS_HIGH,
1903 vid->vl_dp = CONFIG_SYS_LOW,
1906 /* AMS701KA AMOLED Panel. */
1918 static void setup_meminfo(void)
1920 char meminfo[64] = {0, };
1921 int count = 0, size, real;
1923 size = gd->bd->bi_dram[0].size >> 20;
1924 count += sprintf(meminfo + count, "mem=%dM", size);
1926 /* Each Chip Select can't exceed the 256MiB */
1927 size = gd->bd->bi_dram[1].size >> 20;
1928 real = min(size, 256);
1929 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1930 real, (unsigned int)gd->bd->bi_dram[1].start);
1934 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1935 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1938 setenv("meminfo", meminfo);
1941 int misc_init_r(void)
1944 /* It should be located at first */
1947 if (board_is_limo_real() ||
1948 board_is_limo_universal() ||
1950 setenv("lcdinfo", "lcd=s6e63m0");
1951 /* it can't classify tl2796 with single-lcd and dual-lcd.
1953 setenv("lcdinfo", "lcd=tl2796-dual");
1957 * env values below should be added in case that lcd panel of geminus,
1958 * p1 and p2 are enabled at u-boot.
1959 * setenv means that lcd panel has been turned on at u-boot.
1961 if (machine_is_geminus())
1962 setenv("lcdinfo", "lcd=lms480jc01");
1963 if (board_is_media())
1964 setenv("lcdinfo", "lcd=media");
1966 if (board_is_p2_real())
1967 setenv("lcdinfo", "lcd=ams701");
1974 /* Set proper PMIC pins */
1977 /* Check auto burning */
1980 /* To power up I2C2 */
1983 /* Enable T-Flash at Limo Real or Limo Universal */
1986 /* Setup Limo Real board GPIOs */
1987 setup_limo_real_gpios();
1989 /* Setup Media board GPIOs */
1990 setup_media_gpios();
1992 /* Setup P1P2 board GPIOS */
1995 /* To usbdown automatically */
1996 if (board_is_p2_real())
2004 #ifdef CONFIG_S5PC1XXFB
2005 display_device_info();
2008 setup_power_down_mode_registers();
2010 /* check max17040 */
2020 int board_init(void)
2022 /* Set Initial global variables */
2023 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2025 gd->bd->bi_arch_number = MACH_TYPE;
2026 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2028 /* Check H/W Revision */
2029 check_hw_revision();
2036 unsigned int base, memconfig0, size;
2037 unsigned int memconfig1, sz = 0;
2039 if (cpu_is_s5pc100()) {
2040 /* In mem setup, we swap the bank. So below size is correct */
2041 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2042 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2043 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2046 /* In S5PC110, we can't swap the DMC0/1 */
2047 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2048 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2050 base = S5PC110_DMC1_BASE;
2051 /* DMC configuration */
2052 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2053 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2055 size = (memconfig0 >> 16) & 0xFF;
2056 size = ((unsigned char) ~size) + 1;
2059 * (0x07 + 1) * 16 = 128 MiB
2060 * (0x0f + 1) * 16 = 256 MiB
2065 * Aquila Rev0.5 4G3G1G
2066 * Aquila Rev0.8 4G3G1G
2068 if (machine_is_aquila() && (hwrevision(5) || hwrevision(8))) {
2069 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2071 sz = (memconfig1 >> 16) & 0xFF;
2072 sz = ((unsigned char) ~sz) + 1;
2078 * bi_dram[1].size contains all DMC1 memory size
2080 gd->bd->bi_dram[1].size = (size + sz) << 20;
2085 /* Used for sleep test */
2086 static unsigned char saved_val[4][2];
2087 void board_sleep_init_late(void)
2089 /* CODEC_LDO_EN: GPF3[4] */
2090 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2091 /* CODEC_XTAL_EN: GPH3[2] */
2092 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2094 /* MMC T_FLASH off */
2095 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2097 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2098 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2099 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2103 void board_sleep_init(void)
2106 unsigned char val[2];
2108 i2c_set_bus_num(I2C_PMIC);
2110 if (i2c_probe(addr)) {
2111 printf("Can't find max8998\n");
2116 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2117 saved_val[0][0] = val[0];
2118 saved_val[0][1] = val[1];
2119 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2120 (1 << 1) | (1 << 0));
2121 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2122 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2124 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2125 saved_val[1][0] = val[0];
2126 saved_val[1][1] = val[1];
2127 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2128 (1 << 2) | (1 << 1) | (1 << 0));
2130 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2131 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2133 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2134 saved_val[2][0] = val[0];
2135 saved_val[2][1] = val[1];
2136 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2137 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2138 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2140 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2141 saved_val[3][0] = val[0];
2142 saved_val[3][1] = val[1];
2143 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2144 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2145 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2146 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
2147 __FILE__, __LINE__);
2150 void board_sleep_resume(void)
2153 unsigned char val[2];
2157 i2c_set_bus_num(I2C_PMIC);
2159 if (i2c_probe(addr)) {
2160 printf("Can't find max8998\n");
2165 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2166 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2168 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2169 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2171 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2172 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2174 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2175 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2176 printf("Waked up.\n");
2178 /* check max17040 */
2185 #ifdef CONFIG_CMD_USBDOWN
2186 int usb_board_init(void)
2188 #ifdef CONFIG_CMD_PMIC
2189 run_command("pmic ldo 3 on", 0);
2192 if (cpu_is_s5pc100()) {
2193 #ifdef CONFIG_HARD_I2C
2194 uchar val[2] = {0,};
2197 if (i2c_read(0x66, 0, 1, val, 2)) {
2198 printf("i2c_read error\n");
2205 if (i2c_write(0x66, 0, 1, val, 2)) {
2206 printf("i2c_write error\n");
2209 i2c_read(0x66, 0, 1, val, 2);
2215 if (board_is_limo_universal() ||
2216 board_is_limo_real() ||
2218 /* check usb path */
2219 if (board_is_limo_real() && !hwrevision(6))
2223 if (machine_is_tickertape())
2224 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2225 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2231 #ifdef CONFIG_GENERIC_MMC
2232 int board_mmc_init(bd_t *bis)
2236 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2239 /* MMC0 Clock source = SCLKMPLL */
2240 reg = readl(&clk->src4);
2243 writel(reg, &clk->src4);
2245 reg = readl(&clk->div4);
2248 /* set div value near 50MHz */
2249 clock = get_pll_clk(MPLL) / 1000000;
2250 for (i = 0; i < 0xf; i++) {
2251 if ((clock / (i + 1)) <= 50) {
2257 writel(reg, &clk->div4);
2263 * GPG0[2] SD_0_CDn -> Not used
2264 * GPG0[3:6] SD_0_DATA[0:3]
2266 for (i = 0; i < 7; i++) {
2269 /* GPG0[0:6] special function 2 */
2270 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2271 /* GPG0[0:6] pull disable */
2272 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2273 /* GPG0[0:6] drv 4x */
2274 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2277 return s5pc1xx_mmc_init(0);
2281 #ifdef CONFIG_CMD_PMIC
2282 static int pmic_status(void)
2284 unsigned char addr, val[2];
2287 i2c_set_bus_num(I2C_PMIC);
2289 if (i2c_probe(addr)) {
2290 printf("Can't found max8998\n");
2295 i2c_read(addr, reg, 1, val, 1);
2296 for (i = 7; i >= 4; i--)
2297 printf("BUCK%d %s\n", 7 - i + 1,
2298 val[0] & (1 << i) ? "on" : "off");
2300 printf("LDO%d %s\n", 5 - i,
2301 val[0] & (1 << i) ? "on" : "off");
2303 i2c_read(addr, reg, 1, val, 1);
2304 for (i = 7; i >= 0; i--)
2305 printf("LDO%d %s\n", 7 - i + 6,
2306 val[0] & (1 << i) ? "on" : "off");
2308 i2c_read(addr, reg, 1, val, 1);
2309 for (i = 7; i >= 4; i--)
2310 printf("LDO%d %s\n", 7 - i + 14,
2311 val[0] & (1 << i) ? "on" : "off");
2314 i2c_read(addr, reg, 1, val, 1);
2315 for (i = 7; i >= 6; i--)
2316 printf("SAFEOUT%d %s\n", 7 - i + 1,
2317 val[0] & (1 << i) ? "on" : "off");
2321 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2323 unsigned char addr, val[2];
2324 unsigned int reg, shift;
2332 } else if (ldo <= 13) {
2335 } else if (ldo <= 17) {
2337 shift = 17 - ldo + 4;
2344 shift = 4 - buck + 4;
2345 } else if (safeout) {
2349 shift = 8 - safeout;
2353 i2c_set_bus_num(I2C_PMIC);
2355 if (i2c_probe(addr)) {
2356 printf("Can't found max8998\n");
2360 i2c_read(addr, reg, 1, val, 1);
2362 val[0] |= (1 << shift);
2364 val[0] &= ~(1 << shift);
2365 i2c_write(addr, reg, 1, val, 1);
2366 i2c_read(addr, reg, 1, val, 1);
2369 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2370 val[0] & (1 << shift) ? "on" : "off");
2372 printf("buck %d value 0x%x, %s\n", buck, val[0],
2373 val[0] & (1 << shift) ? "on" : "off");
2375 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2376 val[0] & (1 << shift) ? "on" : "off");
2381 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2383 int buck = 0, ldo = 0, safeout = 0, on = -1;
2387 if (strncmp(argv[1], "status", 6) == 0)
2388 return pmic_status();
2391 if (strncmp(argv[1], "ldo", 3) == 0)
2392 ldo = simple_strtoul(argv[2], NULL, 10);
2393 else if (strncmp(argv[1], "buck", 4) == 0)
2394 buck = simple_strtoul(argv[2], NULL, 10);
2395 else if (strncmp(argv[1], "safeout", 7) == 0)
2396 safeout = simple_strtoul(argv[2], NULL, 10);
2400 if (strncmp(argv[3], "on", 2) == 0)
2402 else if (strncmp(argv[3], "off", 3) == 0)
2407 return pmic_ldo_control(buck, ldo, safeout, on);
2418 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2419 "PMIC LDO & BUCK control",
2420 "status - Display PMIC LDO & BUCK status\n"
2421 "pmic ldo num on/off - Turn on/off the LDO\n"
2422 "pmic buck num on/off - Turn on/off the BUCK\n"
2423 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2427 #ifdef CONFIG_CMD_DEVICE_POWER
2441 static void power_display_devices(void)
2443 printf("devices:\n");
2444 printf("\t%d - touch\n", POWER_TOUCH);
2445 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2446 printf("\t%d - LCD\n", POWER_LCD);
2447 printf("\t%d - Haptic\n", POWER_HAPTIC);
2448 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2449 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2450 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2451 printf("\t%d - HDMI\n", POWER_HDMI);
2454 static int power_hdmi(int on)
2456 /* HDMI_EN1: GPJ2[2] */
2457 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2458 /* MHL_ON: GPJ2[3] */
2459 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2463 static int power_bt_wifi(int on)
2465 /* WLAN_BT_EN: GPB[5] */
2466 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2470 static int power_fm_radio(int on)
2472 /* FM_BUS_nRST: GPJ2[5] */
2473 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2477 static int power_audio_codec(int on)
2479 /* CODEC_LDO_EN: GPF3[4] */
2480 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2481 /* CODEC_XTAL_EN: GPH3[2] */
2482 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2486 static int power_haptic(int on)
2488 /* HAPTIC_ON: GPJ1[1] */
2489 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2493 static int power_lcd(int on)
2495 /* MLCD_ON: GPJ1[3] */
2496 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2500 static int power_touch(int on)
2502 /* TOUCH_EN: GPG3[6] */
2503 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2507 static int power_3_touchkey(int on)
2510 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2511 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2512 if (board_rev & J1_B2_BOARD)
2513 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2515 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2517 /* 3_TOUCH_CE - GPJ2[6] */
2518 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2520 /* 3_TOUCH_CE - GPJ2[6] */
2521 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2526 unsigned char val[2];
2527 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2533 i2c_set_bus_num(I2C_GPIO6);
2535 /* Workaround to probe */
2536 if (i2c_probe(addr)) {
2537 if (i2c_probe(addr)) {
2538 printf("Can't found 3 touchkey\n");
2543 #define MCS5000_TK_HW_VERSION 0x06
2544 #define MCS5000_TK_FW_VERSION 0x0A
2545 #define MCS5000_TK_MI_VERSION 0x0B
2547 reg = MCS5000_TK_MI_VERSION;
2548 i2c_read(addr, reg, 1, val, 1);
2549 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2550 reg = MCS5000_TK_HW_VERSION;
2551 i2c_read(addr, reg, 1, val, 1);
2552 printf("H/W 0x%x, ", val[0]);
2553 reg = MCS5000_TK_FW_VERSION;
2554 i2c_read(addr, reg, 1, val, 1);
2555 printf("F/W 0x%x\n", val[0]);
2560 static int power_control(int device, int on)
2564 return power_touch(on);
2565 case POWER_3_TOUCHKEY:
2566 return power_3_touchkey(on);
2568 return power_lcd(on);
2570 return power_haptic(on);
2571 case POWER_AUDIO_CODEC:
2572 return power_audio_codec(on);
2573 case POWER_FM_RADIO:
2574 return power_fm_radio(on);
2576 return power_bt_wifi(on);
2578 return power_hdmi(on);
2580 printf("I don't know device %d\n", device);
2586 static int power_on(int on)
2589 power_3_touchkey(on);
2592 power_audio_codec(on);
2600 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2604 if (!machine_is_aquila())
2609 if (strncmp(argv[1], "on", 2) == 0)
2611 if (strncmp(argv[1], "off", 3) == 0)
2615 device = simple_strtoul(argv[1], NULL, 10);
2619 if (strncmp(argv[2], "on", 2) == 0)
2621 else if (strncmp(argv[2], "off", 3) == 0)
2625 return power_control(device, on);
2631 power_display_devices();
2636 power, CONFIG_SYS_MAXARGS, 1, do_power,
2637 "Device Power Management control",
2638 "device on/off - Turn on/off the device\n"
2641 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2645 if (strncmp(argv[1], "cp", 2) == 0) {
2646 micro_usb_switch(1);
2647 pmic_ldo_control(0, 0, 2, 1);
2649 } else if (strncmp(argv[1], "ap", 2) == 0) {
2650 micro_usb_switch(0);
2651 pmic_ldo_control(0, 0, 2, 0);
2664 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2666 "cp - switch to CP\n"
2667 "microusb ap - switch to AP\n"