2 * Copyright (C) 2009 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Minkyu Kang <mk7.kang@samsung.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/arch/clk.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/gpio.h>
31 #include <asm/arch/keypad.h>
32 #include <asm/arch/mmc.h>
33 #include <asm/arch/power.h>
34 #include <asm/arch/mem.h>
35 #include <asm/errno.h>
38 #include <bmp_layout.h>
40 #include "animation_frames.h"
42 DECLARE_GLOBAL_DATA_PTR;
46 #define C100_MACH_START 3000
47 #define C110_MACH_START 3100
49 static unsigned int board_rev;
50 static unsigned int battery_soc;
51 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 = {
113 * i2c gpio6 - cypress
117 static struct i2c_gpio_bus_data i2c_cypress_gpio6 = {
123 * i2c gpio7 - cypress
127 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
133 * i2c gpio7 - kessler rev 09
137 static struct i2c_gpio_bus_data i2c_aries_gpio7 = {
143 static struct i2c_gpio_bus i2c_gpio[] = {
159 u32 get_board_rev(void)
164 static int hwrevision(int rev)
166 return (board_rev & 0xf) == rev;
178 #define SPLIT_SCREEN_FEATURE 0x100
180 /* board is MACH_AQUILA and board is like below. */
181 #define J1_B2_BOARD 0x200
182 #define LIMO_UNIVERSAL_BOARD 0x400
183 #define LIMO_REAL_BOARD 0x800
184 #define MEDIA_BOARD 0x1000
185 #define BAMBOO_BOARD 0x2000
188 #define ARIES_BOARD 0x4000
191 /* board is MACH_P1P2 and board is like below. */
192 #define P1_REAL_BOARD 0x200
193 #define P2_REAL_BOARD 0x400
195 #define BOARD_MASK 0xF00
197 static int c110_machine_id(void)
199 return gd->bd->bi_arch_number - C110_MACH_START;
202 static int machine_is_aquila(void)
204 return c110_machine_id() == MACH_AQUILA;
207 static int machine_is_p1p2(void)
209 return c110_machine_id() == MACH_P1P2;
212 static int machine_is_tickertape(void)
214 return c110_machine_id() == MACH_TICKERTAPE;
217 static int machine_is_geminus(void)
219 return c110_machine_id() == MACH_GEMINUS;
222 static int machine_is_cypress(void)
224 return c110_machine_id() == MACH_CYPRESS;
227 static int board_is_limo_universal(void)
229 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
232 static int board_is_limo_real(void)
234 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
237 static int board_is_media(void)
239 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
242 static int board_is_bamboo(void)
244 return machine_is_aquila() && (board_rev & BAMBOO_BOARD);
247 static int board_is_j1b2(void)
249 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
253 static int board_is_aries(void)
255 return machine_is_aquila() && (board_rev & ARIES_BOARD);
259 static int board_is_p2_real(void)
261 return machine_is_p1p2() && (board_rev & P2_REAL_BOARD);
264 static void enable_battery(void);
266 void i2c_init_board(void)
268 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
271 if (cpu_is_s5pc100())
274 num_bus = ARRAY_SIZE(i2c_gpio);
276 if (machine_is_cypress()) {
277 i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
278 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
279 i2c_gpio[I2C_GPIO7].bus->gpio_base =
280 (unsigned int)&gpio->gpio_mp0_5;
283 else if (board_is_aries()) {
284 i2c_gpio[I2C_GPIO6].bus = &i2c_cypress_gpio6;
285 i2c_gpio[I2C_GPIO7].bus = &i2c_aries_gpio7;
286 i2c_gpio[I2C_GPIO7].bus->gpio_base =
287 (unsigned int)&gpio->gpio_mp0_5;
294 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
295 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
296 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
297 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
298 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
300 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
302 /* Reset on max17040 early */
303 if (battery_soc == 0)
307 #ifdef CONFIG_MISC_INIT_R
308 #define DEV_INFO_LEN 512
309 static char device_info[DEV_INFO_LEN];
310 static int display_info;
312 static void dprintf(const char *fmt, ...)
319 i = vsprintf(buf, fmt, args);
324 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
325 puts("Flushing device info...\n");
329 strcat(device_info, buf);
333 #ifdef CONFIG_S5PC1XXFB
334 static void display_device_info(void)
341 set_font_color(FONT_WHITE);
342 fb_printf(device_info);
345 memset(device_info, 0x0, DEV_INFO_LEN);
347 udelay(5 * 1000 * 1000);
351 static const char *board_name[] = {
367 static char feature_buffer[32];
369 static char *display_features(int board, int board_rev)
372 char *buf = feature_buffer;
374 if (board == MACH_AQUILA) {
375 if (board_rev & SPLIT_SCREEN_FEATURE)
376 count += sprintf(buf + count, " - SplitScreen");
377 if (board_rev & J1_B2_BOARD)
378 count += sprintf(buf + count, " - J1 B2 board");
379 /* Limo Real or Universal */
380 if (board_rev & LIMO_REAL_BOARD)
381 count += sprintf(buf + count, " - Limo Real");
382 else if (board_rev & LIMO_UNIVERSAL_BOARD)
383 count += sprintf(buf + count, " - Limo Universal");
384 if (board_rev & MEDIA_BOARD)
385 count += sprintf(buf + count, " - Media");
386 if (board_rev & BAMBOO_BOARD)
387 count += sprintf(buf + count, " - Bamboo");
389 if (board_rev & ARIES_BOARD)
390 count += sprintf(buf + count, " - Aries");
392 } else if (board == MACH_P1P2) {
394 if (board_rev & P1_REAL_BOARD)
395 count += sprintf(buf + count, " - P1 Real");
396 else if (board_rev & P2_REAL_BOARD)
397 count += sprintf(buf + count, " - P2 Real");
399 count += sprintf(buf + count, " - Universal");
405 static void check_board_revision(int board, int rev)
409 /* Limo Real or Universal */
410 if (rev & LIMO_UNIVERSAL_BOARD)
411 board_rev &= ~J1_B2_BOARD;
412 if (rev & LIMO_REAL_BOARD) {
413 board_rev &= ~(J1_B2_BOARD |
414 LIMO_UNIVERSAL_BOARD);
417 if (rev & ARIES_BOARD)
418 board_rev &= ~(J1_B2_BOARD);
420 if (rev & MEDIA_BOARD)
421 board_rev &= ~(J1_B2_BOARD |
422 LIMO_UNIVERSAL_BOARD);
423 if (rev & BAMBOO_BOARD)
424 board_rev &= ~(J1_B2_BOARD |
425 LIMO_UNIVERSAL_BOARD |
432 /* There's no HWREV_MODE3 */
433 board_rev &= ~(1 << 3);
435 case MACH_TICKERTAPE:
437 board_rev &= ~BOARD_MASK;
444 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank)
448 gpio_direction_input(bank, 2);
449 gpio_direction_input(bank, 3);
450 gpio_direction_input(bank, 4);
451 gpio_direction_input(bank, 7);
453 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
454 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
455 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
456 gpio_set_pull(bank, 7, GPIO_PULL_NONE); /* HWREV_MODE3 */
458 rev = gpio_get_value(bank, 2);
459 rev |= (gpio_get_value(bank, 3) << 1);
460 rev |= (gpio_get_value(bank, 4) << 2);
461 rev |= (gpio_get_value(bank, 7) << 3);
465 gpio_direction_input(bank, 1);
466 gpio_direction_input(bank, 2);
467 gpio_direction_input(bank, 3);
468 gpio_direction_input(bank, 4);
470 gpio_set_pull(bank, 1, GPIO_PULL_NONE); /* HWREV_MODE3 */
471 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
472 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
473 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
475 rev = gpio_get_value(bank, 2);
476 rev |= (gpio_get_value(bank, 3) << 1);
477 rev |= (gpio_get_value(bank, 4) << 2);
478 rev |= (gpio_get_value(bank, 1) << 3);
484 static void check_hw_revision(void)
486 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
488 if (cpu_is_s5pc100()) {
489 struct s5pc100_gpio *gpio =
490 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
492 board_rev = get_hw_revision(&gpio->gpio_j0);
494 /* C100 TickerTape */
496 board = MACH_TICKERTAPE;
498 struct s5pc110_gpio *gpio =
499 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
501 board_rev = get_hw_revision(&gpio->gpio_j0);
504 * Note Check 'Aquila' board first
508 * LRA: Limo Real Aquila
509 * LUA: Limo Universal Aquila
515 * ADDR = 0xE0200000 + OFF
517 * OFF Universal BB LRA LUA OA TT SS P1P2 CYP
518 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00 0x00
519 * J2: 0x0284 0x01 0x10 0x00
520 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x18 0x0F
521 * H3: 0x0C64 0x03 0x07 0x0F 0xff
522 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
523 * I: 0x0224 0x02 0x00 0x08
524 * MP03: 0x0324 0x9x 0xbx 0x9x
525 * MP05: 0x0364 0x80 0x88
529 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
531 board_rev |= J1_B2_BOARD;
533 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
534 gpio_direction_input(&gpio->gpio_j2, 6);
538 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
539 board_rev |= LIMO_UNIVERSAL_BOARD;
541 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
542 board_rev |= ARIES_BOARD;
545 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
546 board_rev |= LIMO_REAL_BOARD;
548 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
549 board_rev |= MEDIA_BOARD;
551 /* set gpio to default value. */
552 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
553 gpio_direction_output(&gpio->gpio_j2, 6, 0);
555 /* Workaround: C110 Aquila Rev0.6 */
556 if (board_rev == 6) {
558 board_rev |= LIMO_REAL_BOARD;
560 /* C110 Aquila Bamboo */
561 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
563 board_rev |= BAMBOO_BOARD;
566 /* C110 TickerTape */
567 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
568 gpio_get_value(&gpio->gpio_d1, 1) == 0)
569 board = MACH_TICKERTAPE;
571 /* C110 Cypress: Do first this than P1P2 */
572 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
573 gpio_direction_input(&gpio->gpio_j2, 2);
574 if (gpio_get_value(&gpio->gpio_j2, 2) == 1)
575 board = MACH_CYPRESS;
576 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
579 if (gpio_get_value(&gpio->gpio_h3, 7) == 1) {
581 board_rev &= ~BOARD_MASK;
584 /* set gpio configuration for P1P2. */
585 gpio_direction_input(&gpio->gpio_j0, 6);
586 gpio_direction_input(&gpio->gpio_j0, 7);
589 * do not change order below
590 * because it needs delay to get gpio value.
593 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_NONE);
595 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
597 if (gpio_get_value(&gpio->gpio_j0, 7) == 1) {
599 board_rev &= ~BOARD_MASK;
600 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
601 board_rev |= P1_REAL_BOARD;
602 if (gpio_get_value(&gpio->gpio_j0, 6) == 0)
603 board_rev |= P2_REAL_BOARD;
606 /* set gpio to default value. */
608 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
610 gpio_set_pull(&gpio->gpio_j0, 7, GPIO_PULL_DOWN);
612 /* C110 Geminus for rev0.0 */
613 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
614 gpio_direction_input(&gpio->gpio_j1, 2);
615 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
616 board = MACH_GEMINUS;
617 if ((board_rev & ~BOARD_MASK) == 3)
620 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
621 gpio_direction_output(&gpio->gpio_j1, 2, 0);
623 /* C110 Geminus for rev0.1 ~ */
624 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
625 gpio_direction_input(&gpio->gpio_j0, 6);
626 if (gpio_get_value(&gpio->gpio_j0, 6) == 1)
627 board = MACH_GEMINUS;
628 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
632 if (cpu_is_s5pc110())
633 gd->bd->bi_arch_number = C110_MACH_START + board;
635 gd->bd->bi_arch_number = C100_MACH_START + board;
637 /* Architecture Common settings */
638 if (cpu_is_s5pc110()) {
639 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
641 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
643 setenv("updatek", "onenand erase 0x60000 0x300000; "
644 "onenand write 0x31008000 0x60000 0x300000");
648 static void show_hw_revision(void)
653 * Workaround for Rev 0.3 + CP Ver ES 3.1
656 if (board_is_limo_real()) {
658 /* default is Rev 0.4 */
664 if (cpu_is_s5pc110())
665 board = gd->bd->bi_arch_number - C110_MACH_START;
667 board = gd->bd->bi_arch_number - C100_MACH_START;
669 check_board_revision(board, board_rev);
671 /* Set CPU Revision */
672 if (board_is_limo_real()) {
673 if ((board_rev & 0xf) < 8)
674 s5pc1xx_set_cpu_rev(0);
676 s5pc1xx_set_cpu_rev(0);
679 dprintf("HW Revision:\t%x (%s%s)\n", board_rev, board_name[board],
680 display_features(board, board_rev));
683 static void check_auto_burn(void)
685 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
686 unsigned int count = 0;
689 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
690 printf("Auto burning bootloader\n");
691 count += sprintf(buf + count, "run updateb; ");
693 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
694 printf("Auto burning kernel\n");
695 count += sprintf(buf + count, "run updatek; ");
699 count += sprintf(buf + count, "reset");
700 setenv("bootcmd", buf);
703 /* Clear the magic value */
704 writel(0xa5a55a5a, magic_base);
705 writel(0xa5a55a5a, magic_base + 0x4);
708 static void pmic_pin_init(void)
710 unsigned int reg, value;
712 if (cpu_is_s5pc100())
715 /* AP_PS_HOLD: XEINT_0: GPH0[0]
716 * Note: Don't use GPIO PS_HOLD it doesn't work
718 reg = S5PC110_PS_HOLD_CONTROL;
720 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
721 S5PC110_PS_HOLD_DATA_HIGH |
722 S5PC110_PS_HOLD_OUT_EN;
725 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
726 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
727 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
730 static void enable_ldos(void)
732 if (cpu_is_s5pc100())
735 if (machine_is_p1p2())
738 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
739 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
742 static void enable_t_flash(void)
744 if (!(board_is_limo_universal() || board_is_limo_real()))
747 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
748 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
751 static void setup_limo_real_gpios(void)
753 if (!board_is_limo_real())
757 * Note: Please write GPIO alphabet order
759 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
760 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
763 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
764 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
766 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
767 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
769 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
770 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
771 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
774 static void setup_media_gpios(void)
776 if (!board_is_media())
780 * Note: Please write GPIO alphabet order
782 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
783 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
785 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
786 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
787 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
790 static void setup_p1p2_gpios(void)
792 if (!machine_is_p1p2())
796 * Note: Please write GPIO alphabet order
798 /* RESET_REQ_N: XM0FRnB[1]: MP0_3[5] output high */
799 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 5, 1);
800 /* CODEC_LDO_EN: XM0FRnB[2]: MP0_3[6] output high */
801 gpio_direction_output(&s5pc110_gpio->gpio_mp0_3, 6, 1);
804 #define KBR3 (1 << 3)
805 #define KBR2 (1 << 2)
806 #define KBR1 (1 << 1)
807 #define KBR0 (1 << 0)
809 static void check_p2_keypad(void)
811 unsigned int auto_download = 0;
812 unsigned char addr = 0x34, val[2]; /* adp5587 key controller */
814 i2c_set_bus_num(I2C_2);
816 if (i2c_probe(addr)) {
817 printf("Can't found adp5587 key controller\n");
820 /* Row 8, Column 10 */
822 ret = i2c_write(addr, 0x1D, 1, val, 1); /* Set KP_GPIO1 */
824 ret |= i2c_write(addr, 0x1E, 1, val, 1); /* Set KP_GPIO2 */
826 ret |= i2c_write(addr, 0x1F, 1, val, 1); /* Set KP_GPIO3 */
827 val[0] = 0x3f; /* CMP2_INT | CMP1_INT | OVR_FLOW_INT |
828 K_LCK_INT | GPI_INT | KE_INT */
829 ret |= i2c_write(addr, 0x02, 1, val, 1); /* Status is W1C */
830 val[0] = 0x19; /* INT_CFG | OVR_FLOW_IEN | KE_IEN */
831 ret |= i2c_write(addr, 0x01, 1, val, 1);
832 for (i = 0; i < 10; i++) {
833 udelay(1000); /* FIXME */
834 i2c_read(addr, 0x04 + i, 1, val, 1);
839 if (auto_download == 1)
840 setenv("bootcmd", "usbdown");
843 static void check_keypad(void)
845 unsigned int reg, value;
846 unsigned int col_mask, row_mask;
847 unsigned int auto_download = 0;
848 unsigned int col_value[4], i;
850 if (cpu_is_s5pc100()) {
851 struct s5pc100_gpio *gpio =
852 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
854 /* Set GPH2[2:0] to KP_COL[2:0] */
855 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
856 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
857 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
859 /* Set GPH3[2:0] to KP_ROW[2:0] */
860 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
861 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
862 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
864 reg = S5PC100_KEYPAD_BASE;
866 if (board_is_limo_real() || board_is_limo_universal()) {
874 for (i = 0; i < 4; i++) {
875 /* Set GPH3[3:0] to KP_ROW[3:0] */
876 if (row_mask & (0xF << (i << 2))) {
877 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
878 if (!machine_is_p1p2())
879 gpio_set_pull(&s5pc110_gpio->gpio_h3,
883 /* Set GPH2[3:0] to KP_COL[3:0] */
884 if (col_mask & (0xF << (i << 2)))
885 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
886 if (machine_is_p1p2())
887 gpio_set_pull(&s5pc110_gpio->gpio_h2, i, GPIO_PULL_UP);
890 reg = S5PC110_KEYPAD_BASE;
894 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
895 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
896 /* VOLUMEDOWN and CAM(Half shot) Button */
897 if ((value & KBR1) == 0) {
900 value = readl(reg + S5PC1XX_KEYIFCOL_OFFSET);
903 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
905 col_value[i++] = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
907 writel(0x00, reg + S5PC1XX_KEYIFCOL_OFFSET);
909 /* expected value is row_value[0] = 0x00 row_value[1] = 0x01 */
911 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) == 0x3)
914 if ((col_value[0] & 0x3) == 0x3 && (col_value[1] & 0x3) != 0x3)
916 if (machine_is_p1p2()) {
917 if ((col_value[0] & 0xd) == 0xd)
923 setenv("bootcmd", "usbdown");
926 static void enable_battery(void)
928 unsigned char val[2];
929 unsigned char addr = 0x36; /* max17040 fuel gauge */
931 if (machine_is_aquila()) {
936 if (machine_is_tickertape())
939 if (machine_is_cypress())
940 i2c_set_bus_num(I2C_GPIO7);
942 i2c_set_bus_num(I2C_GPIO3);
944 if (i2c_probe(addr)) {
945 printf("Can't found max17040 fuel gauge\n");
951 i2c_write(addr, 0xfe, 1, val, 2);
954 static void check_battery(void)
956 unsigned char val[2];
957 unsigned char addr = 0x36; /* max17040 fuel gauge */
959 if (machine_is_aquila()) {
964 if (machine_is_tickertape())
967 if (machine_is_cypress())
968 i2c_set_bus_num(I2C_GPIO7);
970 i2c_set_bus_num(I2C_GPIO3);
972 if (i2c_probe(addr)) {
973 printf("Can't found max17040 fuel gauge\n");
977 i2c_read(addr, 0x04, 1, val, 1);
979 dprintf("battery:\t%d%%\n", val[0]);
981 battery_soc = val[0];
984 static void check_mhl(void)
986 unsigned char val[2];
987 unsigned char addr = 0x39; /* SIL9230 */
989 /* MHL Power enable */
990 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
991 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
993 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
994 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
996 /* 10ms required after reset */
1000 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
1002 i2c_set_bus_num(I2C_GPIO5);
1005 if (i2c_probe(addr)) {
1006 printf("Can't found MHL Chip\n");
1012 * set to Normal operation
1015 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
1016 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
1021 * 00 = MHL termination ON
1022 * 11 = MHL termination OFF
1025 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1026 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1029 #define CHARGER_ANIMATION_FRAME 6
1030 static int max8998_power_key(void)
1032 unsigned char addr, val[2];
1033 i2c_set_bus_num(I2C_PMIC);
1035 if (i2c_probe(addr)) {
1036 printf("Can't found max8998\n");
1040 /* Accessing IRQ1 register */
1041 i2c_read(addr, 0x00, 1, val, 1);
1042 printf("MAX8998 IRQ1 = 0x%x\n", val[0]);
1043 if (val[0] & (1 << 6))
1046 static void into_charge_mode(void)
1048 unsigned char addr = 0xCC >> 1; /* max8998 */;
1049 unsigned char val[2];
1052 bmp_image_t *bmp[CHARGER_ANIMATION_FRAME];
1053 unsigned long len[CHARGER_ANIMATION_FRAME];
1054 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1056 i2c_set_bus_num(I2C_PMIC);
1058 if (i2c_probe(addr)) {
1059 printf("Can't found max8998\n");
1063 printf("Charge Mode\n");
1065 i2c_read(addr, 0x0C, 1, val, 1);
1066 val[0] &= ~(0x7 << 0);
1067 val[0] |= 5; /* 600mA */
1068 i2c_write(addr, 0x0C, 1, val, 1);
1070 #ifdef CONFIG_S5PC1XXFB
1073 /* TODO: write the image-text for the charger */
1075 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1076 if (level >= CHARGER_ANIMATION_FRAME)
1077 level = CHARGER_ANIMATION_FRAME - 1;
1079 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1080 bmp_addr[i] = battery_charging_animation[i];
1082 lcd_display_clear();
1083 for (i = 0; i < 3; i++) {
1084 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1087 bmp[j] = gunzip_bmp(bmp_addr[j], &len[j]);
1088 lcd_display_bitmap((ulong) bmp[j], 140, 202);
1091 for (k = 0; k < 10; k++)
1092 if (max8998_power_key())
1096 if (max8998_power_key())
1103 /* EVT0: sleep 1, EVT1: sleep */
1104 if (s5pc1xx_get_cpu_rev() == 0) {
1105 run_command("sleep 1", 0);
1109 run_command("sleep", 0);
1112 static void check_micro_usb(int intr)
1115 unsigned char val[2];
1116 static int started_charging_once = 0;
1118 if (cpu_is_s5pc100())
1121 if (board_is_limo_real()) {
1122 if (hwrevision(0) || hwrevision(1))
1126 if (machine_is_cypress())
1127 i2c_set_bus_num(I2C_GPIO6);
1129 if (board_is_aries())
1130 i2c_set_bus_num(I2C_GPIO6);
1133 i2c_set_bus_num(I2C_PMIC);
1135 addr = 0x25; /* fsa9480 */
1136 if (i2c_probe(addr)) {
1137 printf("Can't found fsa9480\n");
1141 /* Clear Interrupt */
1143 i2c_read(addr, 0x03, 1, val, 2);
1147 /* Read Device Type 1 */
1148 i2c_read(addr, 0x0a, 1, val, 1);
1150 #define FSA_DEDICATED_CHARGER (1 << 6)
1151 #define FSA_UART (1 << 3)
1152 #define FSA_USB (1 << 2)
1155 * If USB, use default 475mA
1156 * If Charger, use 600mA and go to charge mode
1158 if ((val[0] & FSA_DEDICATED_CHARGER) && !started_charging_once) {
1159 started_charging_once = 1;
1163 /* If Factory Mode is Boot ON-USB, go to download mode */
1164 i2c_read(addr, 0x07, 1, val, 1);
1166 #define FSA_ADC_FAC_USB 0x19
1167 #define FSA_ADC_FAC_UART 0x1d
1169 if (val[0] == FSA_ADC_FAC_USB)
1170 setenv("bootcmd", "usbdown");
1173 static void micro_usb_switch(int path)
1176 unsigned char val[2];
1178 if (machine_is_cypress())
1179 i2c_set_bus_num(I2C_GPIO6);
1181 if (board_is_aries())
1182 i2c_set_bus_num(I2C_GPIO6);
1185 i2c_set_bus_num(I2C_PMIC);
1187 addr = 0x25; /* fsa9480 */
1188 if (i2c_probe(addr)) {
1189 printf("Can't found fsa9480\n");
1194 val[0] = 0x90; /* VAUDIO */
1196 val[0] = 0x24; /* DHOST */
1198 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1200 i2c_read(addr, 0x2, 1, val, 1);
1201 val[0] &= ~(1 << 2);
1202 i2c_write(addr, 0x2, 1, val, 1);
1205 #define MAX8998_REG_ONOFF1 0x11
1206 #define MAX8998_REG_ONOFF2 0x12
1207 #define MAX8998_REG_ONOFF3 0x13
1208 #define MAX8998_LDO3 (1 << 2)
1209 #define MAX8998_LDO10 (1 << 3)
1210 #define MAX8998_LDO11 (1 << 2)
1211 #define MAX8998_LDO12 (1 << 1)
1212 #define MAX8998_LDO13 (1 << 0)
1213 #define MAX8998_LDO14 (1 << 7)
1214 #define MAX8998_LDO15 (1 << 6)
1215 #define MAX8998_LDO16 (1 << 5)
1216 #define MAX8998_LDO17 (1 << 4)
1219 #define MAX8998_REG_LDO7 0x21
1220 #define MAX8998_REG_LDO17 0x29
1223 static void init_pmic(void)
1226 unsigned char val[2];
1228 unsigned char val2[2];
1231 if (cpu_is_s5pc100())
1234 i2c_set_bus_num(I2C_PMIC);
1236 addr = 0xCC >> 1; /* max8998 */
1237 if (i2c_probe(addr)) {
1238 printf("Can't found max8998\n");
1243 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1244 val[0] &= ~MAX8998_LDO3;
1245 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1248 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1250 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1251 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1253 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1254 MAX8998_LDO12 | MAX8998_LDO13);
1258 val[0] |= ((1 << 7)|(1 << 6));
1260 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1261 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1263 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1264 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1266 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1269 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1270 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1272 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1273 MAX8998_LDO16 | MAX8998_LDO17);
1277 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1278 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1280 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1283 val[0] |= MAX8998_LDO17;
1285 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1286 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1288 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1289 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1292 #define PDN_MASK(x) (0x3 << ((x) << 1))
1294 #define CON_INPUT(x) (0x0 << ((x) << 2))
1295 #define CON_OUTPUT(x) (0x1 << ((x) << 2))
1296 #define CON_IRQ(x) (0xf << ((x) << 2))
1298 #define DAT_SET(x) (0x1 << (x))
1299 #define DAT_CLEAR(x) (0x0 << (x))
1301 #define OUTPUT0(x) (0x0 << ((x) << 1))
1302 #define OUTPUT1(x) (0x1 << ((x) << 1))
1303 #define INPUT(x) (0x2 << ((x) << 1))
1305 #define PULL_DIS(x) (0x0 << ((x) << 1))
1306 #define PULL_DOWN(x) (0x1 << ((x) << 1))
1307 #define PULL_UP(x) (0x2 << ((x) << 1))
1309 #define PREVIOUS(x) (0x3 << ((x) << 1))
1311 struct gpio_powermode {
1312 unsigned int conpdn;
1313 unsigned int pudpdn;
1316 struct gpio_external {
1322 static struct gpio_powermode powerdown_modes[] = {
1323 { /* S5PC110_GPIO_A0_OFFSET */
1324 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
1325 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1326 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1327 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1328 }, { /* S5PC110_GPIO_A1_OFFSET */
1329 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
1330 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1331 }, { /* S5PC110_GPIO_B_OFFSET */
1332 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1333 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1334 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1335 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1336 }, { /* S5PC110_GPIO_C0_OFFSET */
1337 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1339 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1341 }, { /* S5PC110_GPIO_C1_OFFSET */
1342 /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1344 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1346 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1348 }, { /* S5PC110_GPIO_D0_OFFSET */
1349 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
1350 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1351 }, { /* S5PC110_GPIO_D1_OFFSET */
1352 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1353 INPUT(4) | INPUT(5),
1354 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1355 PULL_DIS(4) | PULL_DIS(5),
1356 }, { /* S5PC110_GPIO_E0_OFFSET */
1357 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1358 INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
1359 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
1360 PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
1361 }, { /* S5PC110_GPIO_E1_OFFSET */
1362 INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
1364 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
1366 }, { /* S5PC110_GPIO_F0_OFFSET */
1367 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1368 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1369 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1370 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1371 }, { /* S5PC110_GPIO_F1_OFFSET */
1372 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1373 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1374 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1375 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1376 }, { /* S5PC110_GPIO_F2_OFFSET */
1377 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1378 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1379 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1380 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1381 }, { /* S5PC110_GPIO_F3_OFFSET */
1382 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1383 OUTPUT0(4) | OUTPUT0(5),
1384 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1385 PULL_DIS(4) | PULL_DIS(5),
1386 }, { /* S5PC110_GPIO_G0_OFFSET */
1387 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1388 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1389 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1390 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1391 }, { /* S5PC110_GPIO_G1_OFFSET */
1392 OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
1393 INPUT(4) | INPUT(5) | INPUT(6),
1394 PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
1395 PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
1396 }, { /* S5PC110_GPIO_G2_OFFSET */
1397 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1398 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1399 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1400 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1401 }, { /* S5PC110_GPIO_G3_OFFSET */
1402 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
1403 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1404 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1405 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1406 }, { /* S5PC110_GPIO_I_OFFSET */
1407 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1408 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1409 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1410 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1411 }, { /* S5PC110_GPIO_J0_OFFSET */
1412 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1413 INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
1414 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1415 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1416 }, { /* S5PC110_GPIO_J1_OFFSET */
1417 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1418 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1419 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1420 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1421 }, { /* S5PC110_GPIO_J2_OFFSET */
1422 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1423 INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1424 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1425 PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
1426 }, { /* S5PC110_GPIO_J3_OFFSET */
1427 INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
1428 OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1429 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
1430 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1431 }, { /* S5PC110_GPIO_J4_OFFSET */
1432 INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1434 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1436 }, { /* S5PC110_MP0_1_OFFSET */
1437 /* XM0CSN[4]: MP0_1[4] -> output high */
1438 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1439 OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
1440 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1441 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1442 }, { /* S5PC110_MP0_2_OFFSET */
1443 OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1444 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1445 }, { /* S5PC110_MP0_3_OFFSET */
1446 /* XM0FWEN: MP0_3[2] -> output high */
1447 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1448 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1449 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1450 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1451 }, { /* S5PC110_MP0_4_OFFSET */
1452 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1453 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1454 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
1455 PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1456 }, { /* S5PC110_MP0_5_OFFSET */
1457 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1458 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1459 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1460 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1461 }, { /* S5PC110_MP0_6_OFFSET */
1462 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1463 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1464 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1465 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1466 }, { /* S5PC110_MP0_7_OFFSET */
1467 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1468 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1469 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1470 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1474 static struct gpio_external external_powerdown_modes[] = {
1475 { /* S5PC110_GPIO_H0_OFFSET */
1476 CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1477 CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1478 DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
1479 DAT_CLEAR(4) | DAT_CLEAR(5),
1480 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1481 PULL_DIS(4) | PULL_DIS(5),
1482 }, { /* S5PC110_GPIO_H1_OFFSET */
1483 /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1484 CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1486 PULL_DOWN(0) | PULL_DOWN(1) |
1488 CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1489 CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
1491 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1493 }, { /* S5PC110_GPIO_H2_OFFSET */
1494 CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1495 CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
1496 DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
1498 }, { /* S5PC110_GPIO_H3_OFFSET */
1499 CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
1500 CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
1501 DAT_CLEAR(3) | DAT_CLEAR(7),
1506 static void setup_power_down_mode_registers(void)
1508 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1509 struct s5pc1xx_gpio_bank *bank;
1510 struct gpio_powermode *p;
1511 struct gpio_external *ge;
1514 if (cpu_is_s5pc100())
1517 if (!(machine_is_aquila() && board_is_limo_real()))
1520 bank = &gpio->gpio_a0;
1521 p = powerdown_modes;
1523 for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
1524 writel(p->conpdn, &bank->pdn_con);
1525 writel(p->pudpdn, &bank->pdn_pull);
1528 writel(0xff0022b0, (unsigned int *)0xF0000000);
1529 writel(0xff0022b0, (unsigned int *)0xF1400000);
1532 bank = &gpio->gpio_h0;
1533 ge = external_powerdown_modes;
1535 for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
1536 writel(ge->con, &bank->con);
1537 writel(ge->dat, &bank->dat);
1538 writel(ge->pud, &bank->pull);
1546 struct s6e63m0_platform_data {
1547 struct s5pc1xx_gpio_bank *bank;
1551 extern void s6e63m0_set_spi_interface(struct s6e63m0_platform_data *cs,
1552 struct s6e63m0_platform_data *clk, struct s6e63m0_platform_data *si,
1553 struct s6e63m0_platform_data *so);
1555 struct s6e63m0_platform_data pd_cs, pd_clk, pd_si, pd_so;
1556 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1558 void lcd_cfg_gpio(void)
1560 unsigned int i, f3_end = 4;
1562 for (i = 0; i < 8; i++) {
1563 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1564 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1565 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1566 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1567 /* pull-up/down disable */
1568 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1569 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1570 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1572 /* drive strength to max (24bit) */
1573 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1574 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1575 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1576 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1577 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1578 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1581 /* set DISPLAY_DE_B pin for dual rgb mode. */
1582 if (board_is_media())
1585 for (i = 0; i < f3_end; i++) {
1586 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1587 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1588 /* pull-up/down disable */
1589 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1590 /* drive strength to max (24bit) */
1591 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1592 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1594 /* display output path selection (only [1:0] valid) */
1595 writel(0x2, 0xE0107008);
1597 /* gpio pad configuration for LCD reset. */
1598 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1600 /* gpio pad configuration for LCD ON. */
1601 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1605 if (board_is_p2_real())
1606 gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
1609 /* LCD_BACKLIGHT_EN */
1610 if (machine_is_geminus())
1611 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1614 * gpio pad configuration for
1615 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1617 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1618 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1619 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1620 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1622 if (machine_is_aquila()) {
1623 pd_cs.bank = &gpio_base->gpio_mp0_1;
1625 pd_clk.bank = &gpio_base->gpio_mp0_4;
1627 pd_si.bank = &gpio_base->gpio_mp0_4;
1629 pd_so.bank = &gpio_base->gpio_mp0_4;
1632 /* these data would be sent to s6e63m0 lcd panel driver. */
1633 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, &pd_so);
1636 if (machine_is_cypress()) {
1637 #if 0 /* universal cypress */
1639 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1642 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1644 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1646 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1648 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1650 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1651 #if 0 /* universal cypress */
1652 pd_cs.bank = &gpio_base->gpio_mp0_1;
1655 pd_cs.bank = &gpio_base->gpio_mp0_5;
1657 pd_clk.bank = &gpio_base->gpio_mp0_4;
1659 pd_si.bank = &gpio_base->gpio_mp0_4;
1662 /* these data would be sent to s6e63m0 lcd panel driver. */
1663 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, NULL);
1669 void backlight_on(unsigned int onoff)
1671 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1674 if (machine_is_geminus())
1675 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1677 if (machine_is_geminus())
1678 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1682 void reset_lcd(void)
1684 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1686 if (machine_is_aquila() || machine_is_geminus())
1687 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1688 if (machine_is_cypress())
1689 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1692 void lcd_power_on(unsigned int onoff)
1694 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1697 if (machine_is_aquila() || machine_is_geminus())
1698 gpio_set_value(&gpio->gpio_j1, 3, 1);
1700 if (machine_is_cypress())
1701 gpio_set_value(&gpio->gpio_g2, 2, 1);
1704 if (board_is_p2_real())
1705 gpio_set_value(&gpio->gpio_j1, 4, 1);
1709 if (board_is_aries())
1712 unsigned char val[2];
1713 unsigned char val2[2];
1715 i2c_set_bus_num(I2C_PMIC);
1716 addr = 0xCC >> 1; /* max8998 */
1717 if (i2c_probe(addr)) {
1718 printf("Can't found max8998\n");
1722 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1725 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1726 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1727 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1728 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1730 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1731 val[0] |= MAX8998_LDO17;
1733 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1734 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1735 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1736 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1742 if (machine_is_aquila() || machine_is_geminus())
1743 gpio_set_value(&gpio->gpio_j1, 3, 0);
1745 if (machine_is_cypress())
1746 gpio_set_value(&gpio->gpio_g2, 2, 0);
1749 if (board_is_p2_real())
1750 gpio_set_value(&gpio->gpio_j1, 4, 0);
1754 if (board_is_aries())
1757 unsigned char val[2];
1759 i2c_set_bus_num(I2C_PMIC);
1760 addr = 0xCC >> 1; /* max8998 */
1761 if (i2c_probe(addr)) {
1762 printf("Can't found max8998\n");
1766 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1767 val[0] &= ~(1 << 7);
1768 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1769 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1771 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1772 val[0] &= ~MAX8998_LDO17;
1773 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1774 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1781 extern void s6e63m0_cfg_ldo(void);
1782 extern void s6e63m0_enable_ldo(unsigned int onoff);
1784 void init_panel_info(vidinfo_t *vid)
1786 vid->cfg_gpio = NULL;
1787 vid->reset_lcd = NULL;
1788 vid->backlight_on = NULL;
1789 vid->lcd_power_on = NULL;
1791 vid->cfg_ldo = NULL;
1792 vid->enable_ldo = NULL;
1794 vid->init_delay = 0;
1795 vid->reset_delay = 0;
1796 vid->power_on_delay = 0;
1801 vid->vl_width = 480;
1802 vid->vl_height = 800;
1804 vid->dual_lcd_enabled = 0;
1806 if (board_is_media()) {
1809 vid->vl_width = 960;
1810 vid->vl_height = 800;
1812 /* enable dual lcd mode. */
1813 vid->dual_lcd_enabled = 1;
1816 vid->vl_clkp = CONFIG_SYS_HIGH;
1817 vid->vl_hsp = CONFIG_SYS_LOW;
1818 vid->vl_vsp = CONFIG_SYS_LOW;
1819 vid->vl_dp = CONFIG_SYS_HIGH;
1822 /* S6E63M0 LCD Panel */
1831 if (machine_is_aquila() || machine_is_cypress()) {
1832 vid->cfg_gpio = lcd_cfg_gpio;
1833 vid->reset_lcd = reset_lcd;
1834 vid->backlight_on = backlight_on;
1835 vid->lcd_power_on = lcd_power_on;
1837 vid->cfg_ldo = s6e63m0_cfg_ldo;
1838 vid->enable_ldo = s6e63m0_enable_ldo;
1840 vid->init_delay = 25000;
1841 vid->reset_delay = 120000;
1844 if (machine_is_geminus()) {
1848 vid->vl_width = 1024,
1849 vid->vl_height = 600,
1850 vid->vl_clkp = CONFIG_SYS_LOW,
1851 vid->vl_hsp = CONFIG_SYS_HIGH,
1852 vid->vl_vsp = CONFIG_SYS_HIGH,
1853 vid->vl_dp = CONFIG_SYS_LOW,
1864 vid->cfg_gpio = lcd_cfg_gpio;
1865 vid->reset_lcd = reset_lcd;
1866 vid->backlight_on = backlight_on;
1867 vid->lcd_power_on = lcd_power_on;
1873 vid->vl_width = 480,
1874 vid->vl_height = 800,
1875 vid->vl_clkp = CONFIG_SYS_HIGH,
1876 vid->vl_hsp = CONFIG_SYS_LOW,
1877 vid->vl_vsp = CONFIG_SYS_LOW,
1878 vid->vl_dp = CONFIG_SYS_HIGH,
1894 vid->vl_width = 1024,
1895 vid->vl_height = 600,
1896 vid->vl_clkp = CONFIG_SYS_HIGH,
1897 vid->vl_hsp = CONFIG_SYS_HIGH,
1898 vid->vl_vsp = CONFIG_SYS_HIGH,
1899 vid->vl_dp = CONFIG_SYS_LOW,
1902 /* AMS701KA AMOLED Panel. */
1914 static void setup_meminfo(void)
1916 char meminfo[64] = {0, };
1917 int count = 0, size, real;
1919 size = gd->bd->bi_dram[0].size >> 20;
1920 count += sprintf(meminfo + count, "mem=%dM", size);
1922 /* Each Chip Select can't exceed the 256MiB */
1923 size = gd->bd->bi_dram[1].size >> 20;
1924 real = min(size, 256);
1925 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1926 real, (unsigned int)gd->bd->bi_dram[1].start);
1930 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1931 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1934 setenv("meminfo", meminfo);
1937 int misc_init_r(void)
1940 /* It should be located at first */
1943 if (board_is_limo_real() ||
1944 board_is_limo_universal() ||
1946 setenv("lcdinfo", "lcd=s6e63m0");
1947 /* it can't classify tl2796 with single-lcd and dual-lcd.
1949 setenv("lcdinfo", "lcd=tl2796-dual");
1953 * env values below should be added in case that lcd panel of geminus,
1954 * p1 and p2 are enabled at u-boot.
1955 * setenv means that lcd panel has been turned on at u-boot.
1957 if (machine_is_geminus())
1958 setenv("lcdinfo", "lcd=lms480jc01");
1959 if (board_is_media())
1960 setenv("lcdinfo", "lcd=media");
1962 if (board_is_p2_real())
1963 setenv("lcdinfo", "lcd=ams701");
1970 /* Set proper PMIC pins */
1973 /* Check auto burning */
1976 /* To power up I2C2 */
1979 /* Enable T-Flash at Limo Real or Limo Universal */
1982 /* Setup Limo Real board GPIOs */
1983 setup_limo_real_gpios();
1985 /* Setup Media board GPIOs */
1986 setup_media_gpios();
1988 /* Setup P1P2 board GPIOS */
1991 /* To usbdown automatically */
1992 if (board_is_p2_real())
2000 #ifdef CONFIG_S5PC1XXFB
2001 display_device_info();
2004 setup_power_down_mode_registers();
2006 /* check max17040 */
2016 int board_init(void)
2018 /* Set Initial global variables */
2019 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2021 gd->bd->bi_arch_number = MACH_TYPE;
2022 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2024 /* Check H/W Revision */
2025 check_hw_revision();
2032 unsigned int base, memconfig0, size;
2033 unsigned int memconfig1, sz = 0;
2035 if (cpu_is_s5pc100()) {
2036 /* In mem setup, we swap the bank. So below size is correct */
2037 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2038 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2039 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2042 /* In S5PC110, we can't swap the DMC0/1 */
2043 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2044 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2046 base = S5PC110_DMC1_BASE;
2047 /* DMC configuration */
2048 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2049 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2051 size = (memconfig0 >> 16) & 0xFF;
2052 size = ((unsigned char) ~size) + 1;
2055 * (0x07 + 1) * 16 = 128 MiB
2056 * (0x0f + 1) * 16 = 256 MiB
2061 * Aquila Rev0.5 4G3G1G
2062 * Aquila Rev0.8 4G3G1G
2064 if (machine_is_aquila() && (hwrevision(5) || hwrevision(8))) {
2065 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2067 sz = (memconfig1 >> 16) & 0xFF;
2068 sz = ((unsigned char) ~sz) + 1;
2074 * bi_dram[1].size contains all DMC1 memory size
2076 gd->bd->bi_dram[1].size = (size + sz) << 20;
2081 /* Used for sleep test */
2082 static unsigned char saved_val[4][2];
2083 void board_sleep_init_late(void)
2085 /* CODEC_LDO_EN: GPF3[4] */
2086 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2087 /* CODEC_XTAL_EN: GPH3[2] */
2088 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2090 /* MMC T_FLASH off */
2091 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2093 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2094 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2095 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2099 void board_sleep_init(void)
2102 unsigned char val[2];
2104 i2c_set_bus_num(I2C_PMIC);
2106 if (i2c_probe(addr)) {
2107 printf("Can't find max8998\n");
2112 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2113 saved_val[0][0] = val[0];
2114 saved_val[0][1] = val[1];
2115 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2116 (1 << 1) | (1 << 0));
2117 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2118 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2120 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2121 saved_val[1][0] = val[0];
2122 saved_val[1][1] = val[1];
2123 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2124 (1 << 2) | (1 << 1) | (1 << 0));
2126 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2127 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2129 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2130 saved_val[2][0] = val[0];
2131 saved_val[2][1] = val[1];
2132 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2133 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2134 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2136 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2137 saved_val[3][0] = val[0];
2138 saved_val[3][1] = val[1];
2139 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2140 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2141 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2142 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
2143 __FILE__, __LINE__);
2146 void board_sleep_resume(void)
2149 unsigned char val[2];
2153 i2c_set_bus_num(I2C_PMIC);
2155 if (i2c_probe(addr)) {
2156 printf("Can't find max8998\n");
2161 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2162 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2164 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2165 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2167 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2168 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2170 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2171 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2172 printf("Waked up.\n");
2174 /* check max17040 */
2181 #ifdef CONFIG_CMD_USBDOWN
2182 int usb_board_init(void)
2184 #ifdef CONFIG_CMD_PMIC
2185 run_command("pmic ldo 3 on", 0);
2188 if (cpu_is_s5pc100()) {
2189 #ifdef CONFIG_HARD_I2C
2190 uchar val[2] = {0,};
2193 if (i2c_read(0x66, 0, 1, val, 2)) {
2194 printf("i2c_read error\n");
2201 if (i2c_write(0x66, 0, 1, val, 2)) {
2202 printf("i2c_write error\n");
2205 i2c_read(0x66, 0, 1, val, 2);
2211 if (board_is_limo_universal() ||
2212 board_is_limo_real() ||
2214 /* check usb path */
2215 if (board_is_limo_real() && !hwrevision(6))
2219 if (machine_is_tickertape())
2220 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2221 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2227 #ifdef CONFIG_GENERIC_MMC
2228 int board_mmc_init(bd_t *bis)
2232 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2235 /* MMC0 Clock source = SCLKMPLL */
2236 reg = readl(&clk->src4);
2239 writel(reg, &clk->src4);
2241 reg = readl(&clk->div4);
2244 /* set div value near 50MHz */
2245 clock = get_pll_clk(MPLL) / 1000000;
2246 for (i = 0; i < 0xf; i++) {
2247 if ((clock / (i + 1)) <= 50) {
2253 writel(reg, &clk->div4);
2259 * GPG0[2] SD_0_CDn -> Not used
2260 * GPG0[3:6] SD_0_DATA[0:3]
2262 for (i = 0; i < 7; i++) {
2265 /* GPG0[0:6] special function 2 */
2266 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2267 /* GPG0[0:6] pull disable */
2268 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2269 /* GPG0[0:6] drv 4x */
2270 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2273 return s5pc1xx_mmc_init(0);
2277 #ifdef CONFIG_CMD_PMIC
2278 static int pmic_status(void)
2280 unsigned char addr, val[2];
2283 i2c_set_bus_num(I2C_PMIC);
2285 if (i2c_probe(addr)) {
2286 printf("Can't found max8998\n");
2291 i2c_read(addr, reg, 1, val, 1);
2292 for (i = 7; i >= 4; i--)
2293 printf("BUCK%d %s\n", 7 - i + 1,
2294 val[0] & (1 << i) ? "on" : "off");
2296 printf("LDO%d %s\n", 5 - i,
2297 val[0] & (1 << i) ? "on" : "off");
2299 i2c_read(addr, reg, 1, val, 1);
2300 for (i = 7; i >= 0; i--)
2301 printf("LDO%d %s\n", 7 - i + 6,
2302 val[0] & (1 << i) ? "on" : "off");
2304 i2c_read(addr, reg, 1, val, 1);
2305 for (i = 7; i >= 4; i--)
2306 printf("LDO%d %s\n", 7 - i + 14,
2307 val[0] & (1 << i) ? "on" : "off");
2310 i2c_read(addr, reg, 1, val, 1);
2311 for (i = 7; i >= 6; i--)
2312 printf("SAFEOUT%d %s\n", 7 - i + 1,
2313 val[0] & (1 << i) ? "on" : "off");
2317 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2319 unsigned char addr, val[2];
2320 unsigned int reg, shift;
2328 } else if (ldo <= 13) {
2331 } else if (ldo <= 17) {
2333 shift = 17 - ldo + 4;
2340 shift = 4 - buck + 4;
2341 } else if (safeout) {
2345 shift = 8 - safeout;
2349 i2c_set_bus_num(I2C_PMIC);
2351 if (i2c_probe(addr)) {
2352 printf("Can't found max8998\n");
2356 i2c_read(addr, reg, 1, val, 1);
2358 val[0] |= (1 << shift);
2360 val[0] &= ~(1 << shift);
2361 i2c_write(addr, reg, 1, val, 1);
2362 i2c_read(addr, reg, 1, val, 1);
2365 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2366 val[0] & (1 << shift) ? "on" : "off");
2368 printf("buck %d value 0x%x, %s\n", buck, val[0],
2369 val[0] & (1 << shift) ? "on" : "off");
2371 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2372 val[0] & (1 << shift) ? "on" : "off");
2377 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2379 int buck = 0, ldo = 0, safeout = 0, on = -1;
2383 if (strncmp(argv[1], "status", 6) == 0)
2384 return pmic_status();
2387 if (strncmp(argv[1], "ldo", 3) == 0)
2388 ldo = simple_strtoul(argv[2], NULL, 10);
2389 else if (strncmp(argv[1], "buck", 4) == 0)
2390 buck = simple_strtoul(argv[2], NULL, 10);
2391 else if (strncmp(argv[1], "safeout", 7) == 0)
2392 safeout = simple_strtoul(argv[2], NULL, 10);
2396 if (strncmp(argv[3], "on", 2) == 0)
2398 else if (strncmp(argv[3], "off", 3) == 0)
2403 return pmic_ldo_control(buck, ldo, safeout, on);
2414 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2415 "PMIC LDO & BUCK control",
2416 "status - Display PMIC LDO & BUCK status\n"
2417 "pmic ldo num on/off - Turn on/off the LDO\n"
2418 "pmic buck num on/off - Turn on/off the BUCK\n"
2419 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2423 #ifdef CONFIG_CMD_DEVICE_POWER
2437 static void power_display_devices(void)
2439 printf("devices:\n");
2440 printf("\t%d - touch\n", POWER_TOUCH);
2441 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2442 printf("\t%d - LCD\n", POWER_LCD);
2443 printf("\t%d - Haptic\n", POWER_HAPTIC);
2444 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2445 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2446 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2447 printf("\t%d - HDMI\n", POWER_HDMI);
2450 static int power_hdmi(int on)
2452 /* HDMI_EN1: GPJ2[2] */
2453 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2454 /* MHL_ON: GPJ2[3] */
2455 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2459 static int power_bt_wifi(int on)
2461 /* WLAN_BT_EN: GPB[5] */
2462 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2466 static int power_fm_radio(int on)
2468 /* FM_BUS_nRST: GPJ2[5] */
2469 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2473 static int power_audio_codec(int on)
2475 /* CODEC_LDO_EN: GPF3[4] */
2476 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2477 /* CODEC_XTAL_EN: GPH3[2] */
2478 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2482 static int power_haptic(int on)
2484 /* HAPTIC_ON: GPJ1[1] */
2485 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2489 static int power_lcd(int on)
2491 /* MLCD_ON: GPJ1[3] */
2492 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2496 static int power_touch(int on)
2498 /* TOUCH_EN: GPG3[6] */
2499 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2503 static int power_3_touchkey(int on)
2506 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2507 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2508 if (board_rev & J1_B2_BOARD)
2509 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2511 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2513 /* 3_TOUCH_CE - GPJ2[6] */
2514 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2516 /* 3_TOUCH_CE - GPJ2[6] */
2517 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2522 unsigned char val[2];
2523 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2529 i2c_set_bus_num(I2C_GPIO6);
2531 /* Workaround to probe */
2532 if (i2c_probe(addr)) {
2533 if (i2c_probe(addr)) {
2534 printf("Can't found 3 touchkey\n");
2539 #define MCS5000_TK_HW_VERSION 0x06
2540 #define MCS5000_TK_FW_VERSION 0x0A
2541 #define MCS5000_TK_MI_VERSION 0x0B
2543 reg = MCS5000_TK_MI_VERSION;
2544 i2c_read(addr, reg, 1, val, 1);
2545 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2546 reg = MCS5000_TK_HW_VERSION;
2547 i2c_read(addr, reg, 1, val, 1);
2548 printf("H/W 0x%x, ", val[0]);
2549 reg = MCS5000_TK_FW_VERSION;
2550 i2c_read(addr, reg, 1, val, 1);
2551 printf("F/W 0x%x\n", val[0]);
2556 static int power_control(int device, int on)
2560 return power_touch(on);
2561 case POWER_3_TOUCHKEY:
2562 return power_3_touchkey(on);
2564 return power_lcd(on);
2566 return power_haptic(on);
2567 case POWER_AUDIO_CODEC:
2568 return power_audio_codec(on);
2569 case POWER_FM_RADIO:
2570 return power_fm_radio(on);
2572 return power_bt_wifi(on);
2574 return power_hdmi(on);
2576 printf("I don't know device %d\n", device);
2582 static int power_on(int on)
2585 power_3_touchkey(on);
2588 power_audio_codec(on);
2596 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2600 if (!machine_is_aquila())
2605 if (strncmp(argv[1], "on", 2) == 0)
2607 if (strncmp(argv[1], "off", 3) == 0)
2611 device = simple_strtoul(argv[1], NULL, 10);
2615 if (strncmp(argv[2], "on", 2) == 0)
2617 else if (strncmp(argv[2], "off", 3) == 0)
2621 return power_control(device, on);
2627 power_display_devices();
2632 power, CONFIG_SYS_MAXARGS, 1, do_power,
2633 "Device Power Management control",
2634 "device on/off - Turn on/off the device\n"
2637 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2641 if (strncmp(argv[1], "cp", 2) == 0) {
2642 micro_usb_switch(1);
2643 pmic_ldo_control(0, 0, 2, 1);
2645 } else if (strncmp(argv[1], "ap", 2) == 0) {
2646 micro_usb_switch(0);
2647 pmic_ldo_control(0, 0, 2, 0);
2660 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2662 "cp - switch to CP\n"
2663 "microusb ap - switch to AP\n"