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 #define MAX8998_REG_ONOFF1 0x11
1174 #define MAX8998_REG_ONOFF2 0x12
1175 #define MAX8998_REG_ONOFF3 0x13
1176 #define MAX8998_LDO3 (1 << 2)
1177 #define MAX8998_LDO10 (1 << 3)
1178 #define MAX8998_LDO11 (1 << 2)
1179 #define MAX8998_LDO12 (1 << 1)
1180 #define MAX8998_LDO13 (1 << 0)
1181 #define MAX8998_LDO14 (1 << 7)
1182 #define MAX8998_LDO15 (1 << 6)
1183 #define MAX8998_LDO16 (1 << 5)
1184 #define MAX8998_LDO17 (1 << 4)
1187 #define MAX8998_REG_LDO7 0x21
1188 #define MAX8998_REG_LDO17 0x29
1191 static void init_pmic(void)
1194 unsigned char val[2];
1196 unsigned char val2[2];
1199 if (cpu_is_s5pc100())
1202 i2c_set_bus_num(I2C_PMIC);
1204 addr = 0xCC >> 1; /* max8998 */
1205 if (i2c_probe(addr)) {
1206 printf("Can't found max8998\n");
1211 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1212 val[0] &= ~MAX8998_LDO3;
1213 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1216 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1218 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1219 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1221 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1222 MAX8998_LDO12 | MAX8998_LDO13);
1226 val[0] |= ((1 << 7)|(1 << 6));
1228 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1229 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1231 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1232 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1234 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1237 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1238 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1240 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1241 MAX8998_LDO16 | MAX8998_LDO17);
1245 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1246 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1248 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1251 val[0] |= MAX8998_LDO17;
1253 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1254 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1256 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1257 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1260 #define PDN_MASK(x) (0x3 << ((x) << 1))
1262 #define CON_INPUT(x) (0x0 << ((x) << 2))
1263 #define CON_OUTPUT(x) (0x1 << ((x) << 2))
1264 #define CON_IRQ(x) (0xf << ((x) << 2))
1266 #define DAT_SET(x) (0x1 << (x))
1267 #define DAT_CLEAR(x) (0x0 << (x))
1269 #define OUTPUT0(x) (0x0 << ((x) << 1))
1270 #define OUTPUT1(x) (0x1 << ((x) << 1))
1271 #define INPUT(x) (0x2 << ((x) << 1))
1273 #define PULL_DIS(x) (0x0 << ((x) << 1))
1274 #define PULL_DOWN(x) (0x1 << ((x) << 1))
1275 #define PULL_UP(x) (0x2 << ((x) << 1))
1277 #define PREVIOUS(x) (0x3 << ((x) << 1))
1279 struct gpio_powermode {
1280 unsigned int conpdn;
1281 unsigned int pudpdn;
1284 struct gpio_external {
1290 static struct gpio_powermode powerdown_modes[] = {
1291 { /* S5PC110_GPIO_A0_OFFSET */
1292 INPUT(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3) |
1293 INPUT(4) | OUTPUT0(5) | INPUT(6) | OUTPUT0(7),
1294 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1295 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1296 }, { /* S5PC110_GPIO_A1_OFFSET */
1297 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3),
1298 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1299 }, { /* S5PC110_GPIO_B_OFFSET */
1300 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1301 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1302 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1303 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1304 }, { /* S5PC110_GPIO_C0_OFFSET */
1305 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1307 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1309 }, { /* S5PC110_GPIO_C1_OFFSET */
1310 /* OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1312 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1314 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1316 }, { /* S5PC110_GPIO_D0_OFFSET */
1317 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3),
1318 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1319 }, { /* S5PC110_GPIO_D1_OFFSET */
1320 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1321 INPUT(4) | INPUT(5),
1322 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1323 PULL_DIS(4) | PULL_DIS(5),
1324 }, { /* S5PC110_GPIO_E0_OFFSET */
1325 INPUT(0) | INPUT(1) | INPUT(2) | INPUT(3) |
1326 INPUT(4) | INPUT(5) | INPUT(6) | INPUT(7),
1327 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DOWN(3) |
1328 PULL_DOWN(4) | PULL_DOWN(5) | PULL_DOWN(6) | PULL_DOWN(7),
1329 }, { /* S5PC110_GPIO_E1_OFFSET */
1330 INPUT(0) | INPUT(1) | INPUT(2) | OUTPUT0(3) |
1332 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DOWN(2) | PULL_DIS(3) |
1334 }, { /* S5PC110_GPIO_F0_OFFSET */
1335 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1336 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1337 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1338 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1339 }, { /* S5PC110_GPIO_F1_OFFSET */
1340 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1341 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1342 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1343 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1344 }, { /* S5PC110_GPIO_F2_OFFSET */
1345 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1346 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1347 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1348 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1349 }, { /* S5PC110_GPIO_F3_OFFSET */
1350 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1351 OUTPUT0(4) | OUTPUT0(5),
1352 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1353 PULL_DIS(4) | PULL_DIS(5),
1354 }, { /* S5PC110_GPIO_G0_OFFSET */
1355 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1356 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1357 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1358 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1359 }, { /* S5PC110_GPIO_G1_OFFSET */
1360 OUTPUT0(0) | INPUT(1) | OUTPUT0(2) | INPUT(3) |
1361 INPUT(4) | INPUT(5) | INPUT(6),
1362 PULL_DIS(0) | PULL_UP(1) | PULL_DIS(2) | PULL_UP(3) |
1363 PULL_UP(4) | PULL_UP(5) | PULL_UP(6),
1364 }, { /* S5PC110_GPIO_G2_OFFSET */
1365 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1366 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1367 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1368 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1369 }, { /* S5PC110_GPIO_G3_OFFSET */
1370 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | INPUT(3) |
1371 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1372 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1373 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1374 }, { /* S5PC110_GPIO_I_OFFSET */
1375 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1376 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6),
1377 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1378 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6),
1379 }, { /* S5PC110_GPIO_J0_OFFSET */
1380 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1381 INPUT(4) | INPUT(5) | OUTPUT0(6) | OUTPUT0(7),
1382 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1383 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1384 }, { /* S5PC110_GPIO_J1_OFFSET */
1385 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1386 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1387 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1388 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1389 }, { /* S5PC110_GPIO_J2_OFFSET */
1390 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1391 INPUT(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1392 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1393 PULL_DIS(4) | PULL_DIS(5) | PULL_DOWN(6) | PULL_DOWN(7),
1394 }, { /* S5PC110_GPIO_J3_OFFSET */
1395 INPUT(0) | INPUT(1) | OUTPUT0(2) | OUTPUT0(3) |
1396 OUTPUT1(4) | OUTPUT0(5) | INPUT(6) | INPUT(7),
1397 PULL_DOWN(0) | PULL_DOWN(1) | PULL_DIS(2) | PULL_DIS(3) |
1398 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1399 }, { /* S5PC110_GPIO_J4_OFFSET */
1400 INPUT(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1402 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1404 }, { /* S5PC110_MP0_1_OFFSET */
1405 /* XM0CSN[4]: MP0_1[4] -> output high */
1406 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1407 OUTPUT1(4) | OUTPUT0(5) | OUTPUT1(6) | OUTPUT1(7),
1408 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1409 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1410 }, { /* S5PC110_MP0_2_OFFSET */
1411 OUTPUT0(0) | OUTPUT0(1) | INPUT(2) | OUTPUT0(3),
1412 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3),
1413 }, { /* S5PC110_MP0_3_OFFSET */
1414 /* XM0FWEN: MP0_3[2] -> output high */
1415 OUTPUT0(0) | OUTPUT0(1) | OUTPUT1(2) | OUTPUT0(3) |
1416 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1417 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1418 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1419 }, { /* S5PC110_MP0_4_OFFSET */
1420 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | INPUT(3) |
1421 INPUT(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1422 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DOWN(3) |
1423 PULL_DOWN(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1424 }, { /* S5PC110_MP0_5_OFFSET */
1425 INPUT(0) | OUTPUT0(1) | INPUT(2) | INPUT(3) |
1426 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1427 PULL_DOWN(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1428 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1429 }, { /* S5PC110_MP0_6_OFFSET */
1430 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1431 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1432 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1433 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1434 }, { /* S5PC110_MP0_7_OFFSET */
1435 OUTPUT0(0) | OUTPUT0(1) | OUTPUT0(2) | OUTPUT0(3) |
1436 OUTPUT0(4) | OUTPUT0(5) | OUTPUT0(6) | OUTPUT0(7),
1437 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1438 PULL_DIS(4) | PULL_DIS(5) | PULL_DIS(6) | PULL_DIS(7),
1442 static struct gpio_external external_powerdown_modes[] = {
1443 { /* S5PC110_GPIO_H0_OFFSET */
1444 CON_OUTPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1445 CON_OUTPUT(4) | CON_OUTPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1446 DAT_SET(0) | DAT_CLEAR(2) | DAT_CLEAR(3) |
1447 DAT_CLEAR(4) | DAT_CLEAR(5),
1448 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1449 PULL_DIS(4) | PULL_DIS(5),
1450 }, { /* S5PC110_GPIO_H1_OFFSET */
1451 /* CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1452 CON_IRQ(4) | CON_INPUT(5) | CON_INPUT(6) | CON_INPUT(7),
1454 PULL_DOWN(0) | PULL_DOWN(1) |
1456 CON_INPUT(0) | CON_INPUT(1) | CON_OUTPUT(2) | CON_IRQ(3) |
1457 CON_INPUT(4) | CON_INPUT(5) | CON_OUTPUT(6) | CON_INPUT(7),
1459 PULL_DIS(0) | PULL_DIS(1) | PULL_DIS(2) | PULL_DIS(3) |
1461 }, { /* S5PC110_GPIO_H2_OFFSET */
1462 CON_OUTPUT(0) | CON_OUTPUT(1) | CON_OUTPUT(2) | CON_OUTPUT(3) |
1463 CON_IRQ(4) | CON_IRQ(5) | CON_IRQ(6) | CON_IRQ(7),
1464 DAT_CLEAR(0) | DAT_CLEAR(1) | DAT_CLEAR(2) | DAT_CLEAR(3),
1466 }, { /* S5PC110_GPIO_H3_OFFSET */
1467 CON_IRQ(0) | CON_IRQ(1) | CON_IRQ(2) | CON_OUTPUT(3) |
1468 CON_IRQ(4) | CON_INPUT(5) | CON_IRQ(6) | CON_OUTPUT(7),
1469 DAT_CLEAR(3) | DAT_CLEAR(7),
1474 static void setup_power_down_mode_registers(void)
1476 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1477 struct s5pc1xx_gpio_bank *bank;
1478 struct gpio_powermode *p;
1479 struct gpio_external *ge;
1482 if (cpu_is_s5pc100())
1485 if (!(machine_is_aquila() && board_is_limo_real()))
1488 bank = &gpio->gpio_a0;
1489 p = powerdown_modes;
1491 for (i = 0; i < ARRAY_SIZE(powerdown_modes); i++, p++, bank++) {
1492 writel(p->conpdn, &bank->pdn_con);
1493 writel(p->pudpdn, &bank->pdn_pull);
1496 writel(0xff0022b0, (unsigned int *)0xF0000000);
1497 writel(0xff0022b0, (unsigned int *)0xF1400000);
1500 bank = &gpio->gpio_h0;
1501 ge = external_powerdown_modes;
1503 for (i = 0; i < ARRAY_SIZE(external_powerdown_modes); i++) {
1504 writel(ge->con, &bank->con);
1505 writel(ge->dat, &bank->dat);
1506 writel(ge->pud, &bank->pull);
1514 struct s6e63m0_platform_data {
1515 struct s5pc1xx_gpio_bank *bank;
1519 extern void s6e63m0_set_spi_interface(struct s6e63m0_platform_data *cs,
1520 struct s6e63m0_platform_data *clk, struct s6e63m0_platform_data *si,
1521 struct s6e63m0_platform_data *so);
1523 struct s6e63m0_platform_data pd_cs, pd_clk, pd_si, pd_so;
1524 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1526 void lcd_cfg_gpio(void)
1528 unsigned int i, f3_end = 4;
1530 for (i = 0; i < 8; i++) {
1531 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1532 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1533 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1534 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1535 /* pull-up/down disable */
1536 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1537 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1538 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1540 /* drive strength to max (24bit) */
1541 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1542 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1543 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1544 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1545 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1546 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1549 /* set DISPLAY_DE_B pin for dual rgb mode. */
1550 if (board_is_media())
1553 for (i = 0; i < f3_end; i++) {
1554 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1555 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1556 /* pull-up/down disable */
1557 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1558 /* drive strength to max (24bit) */
1559 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1560 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1562 /* display output path selection (only [1:0] valid) */
1563 writel(0x2, 0xE0107008);
1565 /* gpio pad configuration for LCD reset. */
1566 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1568 /* gpio pad configuration for LCD ON. */
1569 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1573 if (board_is_p2_real())
1574 gpio_cfg_pin(&gpio_base->gpio_j1, 4, GPIO_OUTPUT);
1577 /* LCD_BACKLIGHT_EN */
1578 if (machine_is_geminus())
1579 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1582 * gpio pad configuration for
1583 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1585 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1586 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1587 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1588 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1590 if (machine_is_aquila()) {
1591 pd_cs.bank = &gpio_base->gpio_mp0_1;
1593 pd_clk.bank = &gpio_base->gpio_mp0_4;
1595 pd_si.bank = &gpio_base->gpio_mp0_4;
1597 pd_so.bank = &gpio_base->gpio_mp0_4;
1600 /* these data would be sent to s6e63m0 lcd panel driver. */
1601 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, &pd_so);
1604 if (machine_is_cypress()) {
1605 #if 0 /* universal cypress */
1607 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1610 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1612 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1614 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1616 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1618 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1619 #if 0 /* universal cypress */
1620 pd_cs.bank = &gpio_base->gpio_mp0_1;
1623 pd_cs.bank = &gpio_base->gpio_mp0_5;
1625 pd_clk.bank = &gpio_base->gpio_mp0_4;
1627 pd_si.bank = &gpio_base->gpio_mp0_4;
1630 /* these data would be sent to s6e63m0 lcd panel driver. */
1631 s6e63m0_set_spi_interface(&pd_cs, &pd_clk, &pd_si, NULL);
1637 void backlight_on(unsigned int onoff)
1639 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1642 if (machine_is_geminus())
1643 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1645 if (machine_is_geminus())
1646 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1650 void reset_lcd(void)
1652 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1654 if (machine_is_aquila() || machine_is_geminus())
1655 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1656 if (machine_is_cypress())
1657 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1660 void lcd_power_on(unsigned int onoff)
1662 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1665 if (machine_is_aquila() || machine_is_geminus())
1666 gpio_set_value(&gpio->gpio_j1, 3, 1);
1668 if (machine_is_cypress())
1669 gpio_set_value(&gpio->gpio_g2, 2, 1);
1672 if (board_is_p2_real())
1673 gpio_set_value(&gpio->gpio_j1, 4, 1);
1677 if (board_is_aries())
1680 unsigned char val[2];
1681 unsigned char val2[2];
1683 i2c_set_bus_num(I2C_PMIC);
1684 addr = 0xCC >> 1; /* max8998 */
1685 if (i2c_probe(addr)) {
1686 printf("Can't found max8998\n");
1690 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1693 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1694 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1695 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1696 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1698 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1699 val[0] |= MAX8998_LDO17;
1701 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1702 i2c_read(addr, MAX8998_REG_LDO7, 1, val2, 1);
1703 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1704 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1710 if (machine_is_aquila() || machine_is_geminus())
1711 gpio_set_value(&gpio->gpio_j1, 3, 0);
1713 if (machine_is_cypress())
1714 gpio_set_value(&gpio->gpio_g2, 2, 0);
1717 if (board_is_p2_real())
1718 gpio_set_value(&gpio->gpio_j1, 4, 0);
1722 if (board_is_aries())
1725 unsigned char val[2];
1727 i2c_set_bus_num(I2C_PMIC);
1728 addr = 0xCC >> 1; /* max8998 */
1729 if (i2c_probe(addr)) {
1730 printf("Can't found max8998\n");
1734 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1735 val[0] &= ~(1 << 7);
1736 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1737 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1739 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1740 val[0] &= ~MAX8998_LDO17;
1741 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1742 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1749 extern void s6e63m0_cfg_ldo(void);
1750 extern void s6e63m0_enable_ldo(unsigned int onoff);
1752 void init_panel_info(vidinfo_t *vid)
1754 vid->cfg_gpio = NULL;
1755 vid->reset_lcd = NULL;
1756 vid->backlight_on = NULL;
1757 vid->lcd_power_on = NULL;
1759 vid->cfg_ldo = NULL;
1760 vid->enable_ldo = NULL;
1762 vid->init_delay = 0;
1763 vid->reset_delay = 0;
1764 vid->power_on_delay = 0;
1769 vid->vl_width = 480;
1770 vid->vl_height = 800;
1772 vid->dual_lcd_enabled = 0;
1774 if (board_is_media()) {
1777 vid->vl_width = 960;
1778 vid->vl_height = 800;
1780 /* enable dual lcd mode. */
1781 vid->dual_lcd_enabled = 1;
1784 vid->vl_clkp = CONFIG_SYS_HIGH;
1785 vid->vl_hsp = CONFIG_SYS_LOW;
1786 vid->vl_vsp = CONFIG_SYS_LOW;
1787 vid->vl_dp = CONFIG_SYS_HIGH;
1790 /* S6E63M0 LCD Panel */
1799 if (machine_is_aquila() || machine_is_cypress()) {
1800 vid->cfg_gpio = lcd_cfg_gpio;
1801 vid->reset_lcd = reset_lcd;
1802 vid->backlight_on = backlight_on;
1803 vid->lcd_power_on = lcd_power_on;
1805 vid->cfg_ldo = s6e63m0_cfg_ldo;
1806 vid->enable_ldo = s6e63m0_enable_ldo;
1808 vid->init_delay = 25000;
1809 vid->reset_delay = 120000;
1812 if (machine_is_geminus()) {
1816 vid->vl_width = 1024,
1817 vid->vl_height = 600,
1818 vid->vl_clkp = CONFIG_SYS_LOW,
1819 vid->vl_hsp = CONFIG_SYS_HIGH,
1820 vid->vl_vsp = CONFIG_SYS_HIGH,
1821 vid->vl_dp = CONFIG_SYS_LOW,
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;
1841 vid->vl_width = 480,
1842 vid->vl_height = 800,
1843 vid->vl_clkp = CONFIG_SYS_HIGH,
1844 vid->vl_hsp = CONFIG_SYS_LOW,
1845 vid->vl_vsp = CONFIG_SYS_LOW,
1846 vid->vl_dp = CONFIG_SYS_HIGH,
1862 vid->vl_width = 1024,
1863 vid->vl_height = 600,
1864 vid->vl_clkp = CONFIG_SYS_HIGH,
1865 vid->vl_hsp = CONFIG_SYS_HIGH,
1866 vid->vl_vsp = CONFIG_SYS_HIGH,
1867 vid->vl_dp = CONFIG_SYS_LOW,
1870 /* AMS701KA AMOLED Panel. */
1882 static void setup_meminfo(void)
1884 char meminfo[64] = {0, };
1885 int count = 0, size, real;
1887 size = gd->bd->bi_dram[0].size >> 20;
1888 count += sprintf(meminfo + count, "mem=%dM", size);
1890 /* Each Chip Select can't exceed the 256MiB */
1891 size = gd->bd->bi_dram[1].size >> 20;
1892 real = min(size, 256);
1893 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1894 real, (unsigned int)gd->bd->bi_dram[1].start);
1898 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1899 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1902 setenv("meminfo", meminfo);
1905 int misc_init_r(void)
1908 /* It should be located at first */
1911 if (board_is_limo_real() ||
1912 board_is_limo_universal() ||
1914 setenv("lcdinfo", "lcd=s6e63m0");
1915 /* it can't classify tl2796 with single-lcd and dual-lcd.
1917 setenv("lcdinfo", "lcd=tl2796-dual");
1921 * env values below should be added in case that lcd panel of geminus,
1922 * p1 and p2 are enabled at u-boot.
1923 * setenv means that lcd panel has been turned on at u-boot.
1925 if (machine_is_geminus())
1926 setenv("lcdinfo", "lcd=lms480jc01");
1927 if (board_is_media())
1928 setenv("lcdinfo", "lcd=media");
1930 if (board_is_p2_real())
1931 setenv("lcdinfo", "lcd=ams701");
1938 /* Set proper PMIC pins */
1941 /* Check auto burning */
1944 /* To power up I2C2 */
1947 /* Enable T-Flash at Limo Real or Limo Universal */
1950 /* Setup Limo Real board GPIOs */
1951 setup_limo_real_gpios();
1953 /* Setup Media board GPIOs */
1954 setup_media_gpios();
1956 /* Setup P1P2 board GPIOS */
1959 /* To usbdown automatically */
1960 if (board_is_p2_real())
1968 #ifdef CONFIG_S5PC1XXFB
1969 display_device_info();
1972 setup_power_down_mode_registers();
1974 /* check max17040 */
1984 int board_init(void)
1986 /* Set Initial global variables */
1987 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1989 gd->bd->bi_arch_number = MACH_TYPE;
1990 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1992 /* Check H/W Revision */
1993 check_hw_revision();
2000 unsigned int base, memconfig0, size;
2001 unsigned int memconfig1, sz = 0;
2003 if (cpu_is_s5pc100()) {
2004 /* In mem setup, we swap the bank. So below size is correct */
2005 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2006 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2007 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2010 /* In S5PC110, we can't swap the DMC0/1 */
2011 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2012 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2014 base = S5PC110_DMC1_BASE;
2015 /* DMC configuration */
2016 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2017 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2019 size = (memconfig0 >> 16) & 0xFF;
2020 size = ((unsigned char) ~size) + 1;
2023 * (0x07 + 1) * 16 = 128 MiB
2024 * (0x0f + 1) * 16 = 256 MiB
2029 * Aquila Rev0.5 4G3G1G
2030 * Aquila Rev0.8 4G3G1G
2032 if (machine_is_aquila() && (hwrevision(5) || hwrevision(8))) {
2033 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2035 sz = (memconfig1 >> 16) & 0xFF;
2036 sz = ((unsigned char) ~sz) + 1;
2042 * bi_dram[1].size contains all DMC1 memory size
2044 gd->bd->bi_dram[1].size = (size + sz) << 20;
2049 /* Used for sleep test */
2050 static unsigned char saved_val[4][2];
2051 void board_sleep_init_late(void)
2053 /* CODEC_LDO_EN: GPF3[4] */
2054 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2055 /* CODEC_XTAL_EN: GPH3[2] */
2056 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2058 /* MMC T_FLASH off */
2059 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2061 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2062 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2063 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2067 void board_sleep_init(void)
2070 unsigned char val[2];
2072 i2c_set_bus_num(I2C_PMIC);
2074 if (i2c_probe(addr)) {
2075 printf("Can't find max8998\n");
2080 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2081 saved_val[0][0] = val[0];
2082 saved_val[0][1] = val[1];
2083 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2084 (1 << 1) | (1 << 0));
2085 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2086 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2088 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2089 saved_val[1][0] = val[0];
2090 saved_val[1][1] = val[1];
2091 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2092 (1 << 2) | (1 << 1) | (1 << 0));
2094 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2095 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2097 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2098 saved_val[2][0] = val[0];
2099 saved_val[2][1] = val[1];
2100 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2101 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2102 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2104 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2105 saved_val[3][0] = val[0];
2106 saved_val[3][1] = val[1];
2107 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2108 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2109 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2110 printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
2111 __FILE__, __LINE__);
2114 void board_sleep_resume(void)
2117 unsigned char val[2];
2121 i2c_set_bus_num(I2C_PMIC);
2123 if (i2c_probe(addr)) {
2124 printf("Can't find max8998\n");
2129 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2130 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2132 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2133 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2135 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2136 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2138 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2139 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2140 printf("Waked up.\n");
2142 /* check max17040 */
2149 #ifdef CONFIG_CMD_USBDOWN
2150 int usb_board_init(void)
2152 #ifdef CONFIG_CMD_PMIC
2153 run_command("pmic ldo 3 on", 0);
2156 if (cpu_is_s5pc100()) {
2157 #ifdef CONFIG_HARD_I2C
2158 uchar val[2] = {0,};
2161 if (i2c_read(0x66, 0, 1, val, 2)) {
2162 printf("i2c_read error\n");
2169 if (i2c_write(0x66, 0, 1, val, 2)) {
2170 printf("i2c_write error\n");
2173 i2c_read(0x66, 0, 1, val, 2);
2179 if (board_is_limo_universal() ||
2180 board_is_limo_real() ||
2182 /* check usb path */
2183 if (board_is_limo_real() && !hwrevision(6))
2187 if (machine_is_tickertape())
2188 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2189 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2195 #ifdef CONFIG_GENERIC_MMC
2196 int board_mmc_init(bd_t *bis)
2200 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2203 /* MMC0 Clock source = SCLKMPLL */
2204 reg = readl(&clk->src4);
2207 writel(reg, &clk->src4);
2209 reg = readl(&clk->div4);
2212 /* set div value near 50MHz */
2213 clock = get_pll_clk(MPLL) / 1000000;
2214 for (i = 0; i < 0xf; i++) {
2215 if ((clock / (i + 1)) <= 50) {
2221 writel(reg, &clk->div4);
2227 * GPG0[2] SD_0_CDn -> Not used
2228 * GPG0[3:6] SD_0_DATA[0:3]
2230 for (i = 0; i < 7; i++) {
2233 /* GPG0[0:6] special function 2 */
2234 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2235 /* GPG0[0:6] pull disable */
2236 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2237 /* GPG0[0:6] drv 4x */
2238 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2241 return s5pc1xx_mmc_init(0);
2245 #ifdef CONFIG_CMD_PMIC
2246 static int pmic_status(void)
2248 unsigned char addr, val[2];
2251 i2c_set_bus_num(I2C_PMIC);
2253 if (i2c_probe(addr)) {
2254 printf("Can't found max8998\n");
2259 i2c_read(addr, reg, 1, val, 1);
2260 for (i = 7; i >= 4; i--)
2261 printf("BUCK%d %s\n", 7 - i + 1,
2262 val[0] & (1 << i) ? "on" : "off");
2264 printf("LDO%d %s\n", 5 - i,
2265 val[0] & (1 << i) ? "on" : "off");
2267 i2c_read(addr, reg, 1, val, 1);
2268 for (i = 7; i >= 0; i--)
2269 printf("LDO%d %s\n", 7 - i + 6,
2270 val[0] & (1 << i) ? "on" : "off");
2272 i2c_read(addr, reg, 1, val, 1);
2273 for (i = 7; i >= 4; i--)
2274 printf("LDO%d %s\n", 7 - i + 14,
2275 val[0] & (1 << i) ? "on" : "off");
2279 static int pmic_ldo_control(int buck, int ldo, int on)
2281 unsigned char addr, val[2];
2282 unsigned int reg, shift;
2290 } else if (ldo <= 13) {
2293 } else if (ldo <= 17) {
2295 shift = 17 - ldo + 4;
2302 shift = 4 - buck + 4;
2306 i2c_set_bus_num(I2C_PMIC);
2308 if (i2c_probe(addr)) {
2309 printf("Can't found max8998\n");
2313 i2c_read(addr, reg, 1, val, 1);
2315 val[0] |= (1 << shift);
2317 val[0] &= ~(1 << shift);
2318 i2c_write(addr, reg, 1, val, 1);
2319 i2c_read(addr, reg, 1, val, 1);
2320 printf("%s %d value 0x%x, %s\n", buck ? "buck" : "ldo", buck ? : ldo,
2321 val[0], val[0] & (1 << shift) ? "on" : "off");
2326 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2328 int buck = 0, ldo = 0, on = -1;
2332 if (strncmp(argv[1], "status", 6) == 0)
2333 return pmic_status();
2336 if (strncmp(argv[1], "ldo", 3) == 0) {
2337 ldo = simple_strtoul(argv[2], NULL, 10);
2338 if (strncmp(argv[3], "on", 2) == 0)
2340 else if (strncmp(argv[3], "off", 3) == 0)
2344 return pmic_ldo_control(buck, ldo, on);
2346 if (strncmp(argv[1], "buck", 4) == 0) {
2347 buck = simple_strtoul(argv[2], NULL, 10);
2348 if (strncmp(argv[3], "on", 2) == 0)
2350 else if (strncmp(argv[3], "off", 3) == 0)
2354 return pmic_ldo_control(buck, ldo, on);
2366 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2367 "PMIC LDO & BUCK control",
2368 "status - Display PMIC LDO & BUCK status\n"
2369 "pmic ldo num on/off - Turn on/off the LDO\n"
2370 "pmic buck num on/off - Turn on/off the BUCK\n"
2374 #ifdef CONFIG_CMD_DEVICE_POWER
2388 static void power_display_devices(void)
2390 printf("devices:\n");
2391 printf("\t%d - touch\n", POWER_TOUCH);
2392 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2393 printf("\t%d - LCD\n", POWER_LCD);
2394 printf("\t%d - Haptic\n", POWER_HAPTIC);
2395 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2396 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2397 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2398 printf("\t%d - HDMI\n", POWER_HDMI);
2401 static int power_hdmi(int on)
2403 /* HDMI_EN1: GPJ2[2] */
2404 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2405 /* MHL_ON: GPJ2[3] */
2406 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2410 static int power_bt_wifi(int on)
2412 /* WLAN_BT_EN: GPB[5] */
2413 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2417 static int power_fm_radio(int on)
2419 /* FM_BUS_nRST: GPJ2[5] */
2420 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2424 static int power_audio_codec(int on)
2426 /* CODEC_LDO_EN: GPF3[4] */
2427 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2428 /* CODEC_XTAL_EN: GPH3[2] */
2429 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2433 static int power_haptic(int on)
2435 /* HAPTIC_ON: GPJ1[1] */
2436 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2440 static int power_lcd(int on)
2442 /* MLCD_ON: GPJ1[3] */
2443 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2447 static int power_touch(int on)
2449 /* TOUCH_EN: GPG3[6] */
2450 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2454 static int power_3_touchkey(int on)
2457 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2458 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2459 if (board_rev & J1_B2_BOARD)
2460 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2462 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2464 /* 3_TOUCH_CE - GPJ2[6] */
2465 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2467 /* 3_TOUCH_CE - GPJ2[6] */
2468 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2473 unsigned char val[2];
2474 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2480 i2c_set_bus_num(I2C_GPIO6);
2482 /* Workaround to probe */
2483 if (i2c_probe(addr)) {
2484 if (i2c_probe(addr)) {
2485 printf("Can't found 3 touchkey\n");
2490 #define MCS5000_TK_HW_VERSION 0x06
2491 #define MCS5000_TK_FW_VERSION 0x0A
2492 #define MCS5000_TK_MI_VERSION 0x0B
2494 reg = MCS5000_TK_MI_VERSION;
2495 i2c_read(addr, reg, 1, val, 1);
2496 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2497 reg = MCS5000_TK_HW_VERSION;
2498 i2c_read(addr, reg, 1, val, 1);
2499 printf("H/W 0x%x, ", val[0]);
2500 reg = MCS5000_TK_FW_VERSION;
2501 i2c_read(addr, reg, 1, val, 1);
2502 printf("F/W 0x%x\n", val[0]);
2507 static int power_control(int device, int on)
2511 return power_touch(on);
2512 case POWER_3_TOUCHKEY:
2513 return power_3_touchkey(on);
2515 return power_lcd(on);
2517 return power_haptic(on);
2518 case POWER_AUDIO_CODEC:
2519 return power_audio_codec(on);
2520 case POWER_FM_RADIO:
2521 return power_fm_radio(on);
2523 return power_bt_wifi(on);
2525 return power_hdmi(on);
2527 printf("I don't know device %d\n", device);
2533 static int power_on(int on)
2536 power_3_touchkey(on);
2539 power_audio_codec(on);
2547 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2551 if (!machine_is_aquila())
2556 if (strncmp(argv[1], "on", 2) == 0)
2558 if (strncmp(argv[1], "off", 3) == 0)
2562 device = simple_strtoul(argv[1], NULL, 10);
2566 if (strncmp(argv[2], "on", 2) == 0)
2568 else if (strncmp(argv[2], "off", 3) == 0)
2572 return power_control(device, on);
2578 power_display_devices();
2583 power, CONFIG_SYS_MAXARGS, 1, do_power,
2584 "Device Power Management control",
2585 "device on/off - Turn on/off the device\n"