2 * Copyright (C) 2009 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Minkyu Kang <mk7.kang@samsung.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/arch/clk.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/keypad.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/power.h>
35 #include <asm/arch/mem.h>
36 #include <asm/arch/hs_otg.h>
37 #include <asm/arch/regs-otg.h>
38 #include <asm/arch/rtc.h>
39 #include <asm/arch/adc.h>
40 #include <asm/errno.h>
43 #include <bmp_layout.h>
45 #include "animation_frames.h"
46 #include "gpio_setting.h"
48 DECLARE_GLOBAL_DATA_PTR;
50 #define C100_MACH_START 3000
51 #define C110_MACH_START 3100
53 static unsigned int board_rev;
54 static unsigned int battery_soc;
55 static struct s5pc110_gpio *s5pc110_gpio;
72 static struct i2c_gpio_bus_data i2c_2 = {
82 static struct i2c_gpio_bus_data i2c_gpio3 = {
92 static struct i2c_gpio_bus_data i2c_pmic = {
102 static struct i2c_gpio_bus_data i2c_gpio5 = {
112 static struct i2c_gpio_bus_data i2c_gpio6 = {
118 * i2c gpio7 - kessler
122 static struct i2c_gpio_bus_data i2c_gpio7 = {
128 * i2c gpio7 - cypress
132 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
142 static struct i2c_gpio_bus_data i2c_gpio10 = {
148 static struct i2c_gpio_bus i2c_gpio[] = {
166 u32 get_board_rev(void)
171 static int hwrevision(int rev)
173 return (board_rev & 0xf) == rev;
180 MACH_P1P2, /* Don't remove it */
191 #define SPLIT_SCREEN_FEATURE 0x100
193 /* board is MACH_AQUILA and board is like below. */
194 #define J1_B2_BOARD 0x0200
195 #define LIMO_UNIVERSAL_BOARD 0x0400
196 #define LIMO_REAL_BOARD 0x0800
197 #define MEDIA_BOARD 0x1000
198 #define BAMBOO_BOARD 0x2000
200 /* board is MACH_KESSLER and board is like below */
201 #define S1_BOARD 0x1000
202 #define KESSLER_BOARD 0x4000
203 #define NEPTUNE_BOARD 0x8000
205 #define BOARD_MASK 0xFF00
207 static int c110_machine_id(void)
209 return gd->bd->bi_arch_number - C110_MACH_START;
212 static int mach_is_aquila(void)
214 return gd->bd->bi_arch_number == MACH_TYPE_AQUILA;
217 static int mach_is_tickertape(void)
219 return c110_machine_id() == MACH_TICKERTAPE;
222 static int mach_is_geminus(void)
224 return c110_machine_id() == MACH_GEMINUS;
227 static int mach_is_cypress(void)
229 return c110_machine_id() == MACH_CYPRESS;
232 static int board_is_limo_universal(void)
234 return mach_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
237 static int board_is_limo_real(void)
239 return mach_is_aquila() && (board_rev & LIMO_REAL_BOARD);
242 static int board_is_media(void)
244 return mach_is_aquila() && (board_rev & MEDIA_BOARD);
247 static int board_is_j1b2(void)
249 return mach_is_aquila() && (board_rev & J1_B2_BOARD);
253 static int mach_is_kessler(void)
255 return gd->bd->bi_arch_number == MACH_KESSLER;
258 static int board_is_neptune(void)
260 return mach_is_kessler() && (board_rev & NEPTUNE_BOARD);
263 static int board_is_s1(void)
265 return mach_is_kessler() && (board_rev & S1_BOARD);
269 static int mach_is_wmg160(void)
271 return c110_machine_id() == MACH_WMG160;
274 static void check_battery(int mode);
275 static void check_micro_usb(int intr);
277 void i2c_init_board(void)
279 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
282 if (cpu_is_s5pc100())
285 num_bus = ARRAY_SIZE(i2c_gpio);
287 if (mach_is_aquila()) {
288 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
289 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
290 } else if (mach_is_kessler()) {
291 i2c_gpio[I2C_GPIO7].bus->gpio_base =
292 (unsigned int)&gpio->gpio_mp0_5;
293 } else if (mach_is_cypress()) {
294 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
295 i2c_gpio[I2C_GPIO7].bus->gpio_base =
296 (unsigned int)&gpio->gpio_mp0_5;
298 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
301 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
302 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
303 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
304 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
305 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
307 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
309 /* Reset on fsa9480 early */
311 /* Reset on max17040 early */
312 if (battery_soc == 0)
316 #ifdef CONFIG_MISC_INIT_R
317 #define DEV_INFO_LEN 256
318 static char device_info[DEV_INFO_LEN];
319 static int display_info;
321 static void empty_device_info_buffer(void)
323 memset(device_info, 0x0, DEV_INFO_LEN);
326 static void dprintf(const char *fmt, ...)
333 i = vsprintf(buf, fmt, args);
338 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
339 puts("Flushing device info...\n");
341 empty_device_info_buffer();
343 strncat(device_info, buf, 127);
347 #ifdef CONFIG_S5PC1XXFB
348 static void display_device_info(void)
355 set_font_color(FONT_WHITE);
356 fb_printf(device_info);
359 memset(device_info, 0x0, DEV_INFO_LEN);
361 udelay(5 * 1000 * 1000);
365 static const char *board_name[] = {
369 "P1P2", /* Don't remove it */
382 static char feature_buffer[32];
384 static char *display_features(int board, int board_rev)
387 char *buf = feature_buffer;
390 if (board == MACH_TYPE_AQUILA) {
391 if (board_rev & SPLIT_SCREEN_FEATURE)
392 name = "SplitScreen";
393 if (board_rev & J1_B2_BOARD)
395 /* Limo Real or Universal */
396 if (board_rev & LIMO_REAL_BOARD)
398 else if (board_rev & LIMO_UNIVERSAL_BOARD)
399 name = "Limo Universal";
400 if (board_rev & MEDIA_BOARD)
402 if (board_rev & BAMBOO_BOARD)
404 } else if (board == MACH_KESSLER) {
405 if (board_rev & NEPTUNE_BOARD)
407 if (board_rev & S1_BOARD)
411 count += sprintf(buf + count, " - %s", name);
416 static char *get_board_name(int board)
418 if (board == MACH_TYPE_AQUILA)
420 else if (board == MACH_KESSLER)
422 else if (board == MACH_WMG160)
424 return (char *) board_name[board];
427 static void check_board_revision(int board, int rev)
429 if (board == MACH_TYPE_AQUILA) {
430 /* Limo Real or Universal */
431 if (rev & LIMO_UNIVERSAL_BOARD)
432 board_rev &= ~J1_B2_BOARD;
433 if (rev & LIMO_REAL_BOARD)
434 board_rev &= ~(J1_B2_BOARD |
435 LIMO_UNIVERSAL_BOARD);
436 if (rev & MEDIA_BOARD)
437 board_rev &= ~(J1_B2_BOARD |
438 LIMO_UNIVERSAL_BOARD);
439 if (rev & BAMBOO_BOARD)
440 board_rev &= ~(J1_B2_BOARD |
441 LIMO_UNIVERSAL_BOARD |
444 } else if (board == MACH_KESSLER) {
445 if (rev & KESSLER_BOARD)
446 board_rev &= ~(J1_B2_BOARD |
447 LIMO_UNIVERSAL_BOARD);
448 if (rev & NEPTUNE_BOARD)
449 board_rev &= ~(J1_B2_BOARD |
450 LIMO_UNIVERSAL_BOARD);
452 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
455 board_rev &= ~BOARD_MASK;
459 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
463 gpio_direction_input(bank, 2);
464 gpio_direction_input(bank, 3);
465 gpio_direction_input(bank, 4);
466 gpio_direction_input(bank, hwrev3);
468 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
469 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
470 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
471 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
473 rev = gpio_get_value(bank, 2);
474 rev |= (gpio_get_value(bank, 3) << 1);
475 rev |= (gpio_get_value(bank, 4) << 2);
476 rev |= (gpio_get_value(bank, hwrev3) << 3);
481 static void check_hw_revision(void)
483 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
485 if (cpu_is_s5pc100()) {
486 struct s5pc100_gpio *gpio =
487 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
489 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
491 /* C100 TickerTape */
493 board = MACH_TICKERTAPE;
495 struct s5pc110_gpio *gpio =
496 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
502 * Note Check 'Aquila' board first
506 * LRA: Limo Real Aquila
507 * LUA: Limo Universal Aquila
512 * ADDR = 0xE0200000 + OFF
514 * OFF Universal BB LRA LUA OA TT SS CYP
515 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
516 * J2: 0x0284 0x01 0x10 0x00
517 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
518 * H3: 0x0C64 0x03 0x07 0x0F
519 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
520 * I: 0x0224 0x02 0x00 0x08
521 * MP03: 0x0324 0x9x 0xbx 0x9x
522 * MP05: 0x0364 0x80 0x88
526 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
527 board = MACH_TYPE_AQUILA;
528 board_rev |= J1_B2_BOARD;
530 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
531 gpio_direction_input(&gpio->gpio_j2, 6);
534 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
535 board_rev |= LIMO_UNIVERSAL_BOARD;
537 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
538 board_rev |= LIMO_REAL_BOARD;
540 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
541 board_rev |= MEDIA_BOARD;
543 /* set gpio to default value. */
544 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
545 gpio_direction_output(&gpio->gpio_j2, 6, 0);
548 /* Workaround: C110 Aquila Rev0.6 */
549 if (board_rev == 6) {
550 board = MACH_TYPE_AQUILA;
551 board_rev |= LIMO_REAL_BOARD;
554 /* C110 Aquila Bamboo */
555 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
556 board = MACH_TYPE_AQUILA;
557 board_rev |= BAMBOO_BOARD;
560 /* C110 TickerTape */
561 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
562 gpio_get_value(&gpio->gpio_d1, 1) == 0)
563 board = MACH_TICKERTAPE;
565 /* WMG160 - GPH3[0:4] = 0x00 */
566 if (board == MACH_TICKERTAPE) {
569 for (i = 0; i < 4; i++) {
570 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
581 /* C110 Geminus for rev0.0 */
582 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
583 gpio_direction_input(&gpio->gpio_j1, 2);
584 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
585 board = MACH_GEMINUS;
586 if ((board_rev & ~BOARD_MASK) == 3)
589 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
590 gpio_direction_output(&gpio->gpio_j1, 2, 0);
592 /* C110 Geminus for rev0.1 ~ */
593 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
594 gpio_direction_input(&gpio->gpio_j0, 6);
595 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
596 board = MACH_GEMINUS;
599 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
601 /* Kessler MP0_5[6] == 1 */
602 gpio_direction_input(&gpio->gpio_mp0_5, 6);
603 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
604 /* Cypress: Do this for cypress */
605 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
606 gpio_direction_input(&gpio->gpio_j2, 2);
607 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
608 board = MACH_CYPRESS;
609 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
611 board = MACH_KESSLER;
612 board_rev |= KESSLER_BOARD;
614 /* Neptune MP0_5[4] == 1 */
615 gpio_direction_input(&gpio->gpio_mp0_5, 4);
616 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
617 board_rev &= ~KESSLER_BOARD;
618 board_rev |= NEPTUNE_BOARD;
621 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
624 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
625 /* Kessler S1 board detection */
626 if (board == MACH_TICKERTAPE) {
627 board = MACH_KESSLER;
628 board_rev |= S1_BOARD;
633 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
637 if (board < MACH_PSEUDO_END) {
638 if (cpu_is_s5pc110())
639 gd->bd->bi_arch_number = C110_MACH_START + board;
641 gd->bd->bi_arch_number = C100_MACH_START + board;
643 gd->bd->bi_arch_number = board;
646 /* Architecture Common settings */
647 if (cpu_is_s5pc110()) {
648 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
650 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
652 setenv("updatek", "onenand erase 0x60000 0x300000; "
653 "onenand write 0x31008000 0x60000 0x300000");
657 static void show_hw_revision(void)
662 * Workaround for Rev 0.3 + CP Ver ES 3.1
665 if (board_is_limo_real()) {
667 /* default is Rev 0.4 */
673 if (mach_is_kessler() || mach_is_aquila())
674 board = gd->bd->bi_arch_number;
675 else if (cpu_is_s5pc110())
676 board = gd->bd->bi_arch_number - C110_MACH_START;
678 board = gd->bd->bi_arch_number - C100_MACH_START;
680 check_board_revision(board, board_rev);
682 /* Set CPU Revision */
683 if (mach_is_aquila()) {
684 if (board_is_limo_real()) {
685 if ((board_rev & 0xf) < 8)
686 s5pc1xx_set_cpu_rev(0);
688 } else if (mach_is_kessler()) {
689 if (board_is_neptune() && hwrevision(2))
690 s5pc1xx_set_cpu_rev(2); /* EVT1-Fused */
692 s5pc1xx_set_cpu_rev(1);
693 } else if (mach_is_geminus()) {
694 if ((board_rev & 0xf) < 1)
695 s5pc1xx_set_cpu_rev(0);
696 } else if (mach_is_cypress()) {
697 s5pc1xx_set_cpu_rev(1);
699 s5pc1xx_set_cpu_rev(0);
702 if (cpu_is_s5pc110())
703 writel(0xc1100000 | (0xffff & (s5pc1xx_get_cpu_rev() ? 1 : 0)),
706 empty_device_info_buffer();
707 dprintf("HW Revision:\t%x (%s%s) %s\n",
708 board_rev, get_board_name(board),
709 display_features(board, board_rev),
710 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
713 static void check_auto_burn(void)
715 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
716 unsigned int count = 0;
719 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
720 puts("Auto burning bootloader\n");
721 count += sprintf(buf + count, "run updateb; ");
723 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
724 puts("Auto burning kernel\n");
725 count += sprintf(buf + count, "run updatek; ");
729 count += sprintf(buf + count, "reset");
730 setenv("bootcmd", buf);
733 /* Clear the magic value */
734 writel(0xa5a55a5a, magic_base);
735 writel(0xa5a55a5a, magic_base + 0x4);
738 static void pmic_pin_init(void)
740 unsigned int reg, value;
742 if (cpu_is_s5pc100())
745 /* AP_PS_HOLD: XEINT_0: GPH0[0]
746 * Note: Don't use GPIO PS_HOLD it doesn't work
748 reg = S5PC110_PS_HOLD_CONTROL;
750 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
751 S5PC110_PS_HOLD_DATA_HIGH |
752 S5PC110_PS_HOLD_OUT_EN;
755 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
756 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
757 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
760 static void enable_ldos(void)
762 if (cpu_is_s5pc100())
765 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
766 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
769 static void enable_t_flash(void)
771 if (!(board_is_limo_universal() || board_is_limo_real()))
774 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
775 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
778 static void setup_limo_real_gpios(void)
780 if (!board_is_limo_real())
784 * Note: Please write GPIO alphabet order
786 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
787 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
790 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
791 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
793 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
794 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
796 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
797 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
798 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
801 static void setup_media_gpios(void)
803 if (!board_is_media())
807 * Note: Please write GPIO alphabet order
809 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
810 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
812 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
813 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
814 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
817 #define KBR3 (1 << 3)
818 #define KBR2 (1 << 2)
819 #define KBR1 (1 << 1)
820 #define KBR0 (1 << 0)
822 static void check_keypad(void)
824 unsigned int reg, value;
825 unsigned int col_num, row_num;
826 unsigned int col_mask;
827 unsigned int col_mask_shift;
828 unsigned int row_state[4];
830 unsigned int auto_download = 0;
832 if (mach_is_wmg160())
835 if (cpu_is_s5pc100()) {
836 struct s5pc100_gpio *gpio =
837 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
842 /* Set GPH2[2:0] to KP_COL[2:0] */
843 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
844 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
845 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
847 /* Set GPH3[2:0] to KP_ROW[2:0] */
848 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
849 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
850 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
852 reg = S5PC100_KEYPAD_BASE;
853 col_mask = S5PC1XX_KEYIFCOL_MASK;
856 if (board_is_limo_real() || board_is_limo_universal()) {
864 for (i = 0; i < row_num; i++) {
865 /* Set GPH3[3:0] to KP_ROW[3:0] */
866 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
867 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
870 for (i = 0; i < col_num; i++)
871 /* Set GPH2[3:0] to KP_COL[3:0] */
872 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
874 reg = S5PC110_KEYPAD_BASE;
875 col_mask = S5PC110_KEYIFCOLEN_MASK;
879 /* KEYIFCOL reg clear */
880 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
883 for (i = 0; i < col_num; i++) {
885 value &= ~(1 << i) << col_mask_shift;
887 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
890 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
891 row_state[i] = ~value & ((1 << row_num) - 1);
893 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
896 /* KEYIFCOL reg clear */
897 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
899 if (mach_is_aquila() || mach_is_kessler()) {
901 if (row_state[1] & 0x2)
903 if (board_is_neptune() && hwrevision(0)) {
904 /* home & volume down */
905 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
907 } else if (board_is_neptune() && hwrevision(2)) {
908 /* cam full shot & volume down */
909 if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
912 /* cam full shot & volume down */
913 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
916 } else if (mach_is_geminus())
917 /* volume down & home */
918 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
922 setenv("bootcmd", "usbdown");
925 static void check_battery(int mode)
927 unsigned char val[2];
928 unsigned char addr = 0x36; /* max17040 fuel gauge */
930 i2c_set_bus_num(I2C_GPIO3);
932 if (mach_is_aquila()) {
935 } else if (mach_is_kessler()) {
936 i2c_set_bus_num(I2C_GPIO7);
937 } else if (mach_is_cypress()) {
938 i2c_set_bus_num(I2C_GPIO7);
939 } else if (mach_is_geminus()) {
941 i2c_set_bus_num(I2C_GPIO7);
945 if (i2c_probe(addr)) {
946 puts("Can't found max17040 fuel gauge\n");
950 /* mode 0: check mode / 1: enable mode */
954 i2c_write(addr, 0xfe, 1, val, 2);
956 i2c_read(addr, 0x04, 1, val, 1);
957 dprintf("battery:\t%d%%\n", val[0]);
958 battery_soc = val[0];
962 static void check_mhl(void)
964 unsigned char val[2];
965 unsigned char addr = 0x39; /* SIL9230 */
967 /* MHL Power enable */
968 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
969 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
971 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
972 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
974 /* 10ms required after reset */
978 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
980 i2c_set_bus_num(I2C_GPIO5);
983 if (i2c_probe(addr)) {
984 puts("Can't found MHL Chip\n");
990 * set to Normal operation
993 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
994 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
999 * 00 = MHL termination ON
1000 * 11 = MHL termination OFF
1003 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1004 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1007 static int max8998_probe(void)
1009 unsigned char addr = 0xCC >> 1;
1011 i2c_set_bus_num(I2C_PMIC);
1013 if (i2c_probe(addr)) {
1014 puts("Can't found max8998\n");
1021 #define CHARGER_ANIMATION_FRAME 6
1022 static void max8998_clear_interrupt(void)
1024 unsigned char addr, val[2];
1027 if (max8998_probe())
1030 i2c_read(addr, 0x00, 1, val, 1);
1031 i2c_read(addr, 0x01, 1, val, 1);
1032 i2c_read(addr, 0x02, 1, val, 1);
1033 i2c_read(addr, 0x03, 1, val, 1);
1036 static int max8998_power_key(void)
1038 unsigned char addr, val[2];
1041 if (max8998_probe())
1044 /* Accessing IRQ1 register */
1045 i2c_read(addr, 0x00, 1, val, 1);
1046 if (val[0] & (1 << 6))
1052 static int max8998_has_ext_power_source(void)
1054 unsigned char addr, val[2];
1057 if (max8998_probe())
1060 /* Accessing STATUS2 register */
1061 i2c_read(addr, 0x09, 1, val, 1);
1062 if (val[0] & (1 << 5))
1068 struct thermister_stat {
1073 static struct thermister_stat adc_to_temperature_data[] = {
1074 { .centigrade = -20, .adc = 1856, },
1075 { .centigrade = -15, .adc = 1799, },
1076 { .centigrade = -10, .adc = 1730, },
1077 { .centigrade = -5, .adc = 1649, },
1078 { .centigrade = 0, .adc = 1556, },
1079 { .centigrade = 5, .adc = 1454, },
1080 { .centigrade = 10, .adc = 1343, },
1081 { .centigrade = 15, .adc = 1227, },
1082 { .centigrade = 20, .adc = 1109, },
1083 { .centigrade = 25, .adc = 992, },
1084 { .centigrade = 30, .adc = 880, },
1085 { .centigrade = 35, .adc = 773, },
1086 { .centigrade = 40, .adc = 675, },
1087 { .centigrade = 45, .adc = 586, },
1088 { .centigrade = 50, .adc = 507, },
1089 { .centigrade = 55, .adc = 436, },
1090 { .centigrade = 58, .adc = 399, },
1091 { .centigrade = 63, .adc = 343, },
1092 { .centigrade = 65, .adc = 322, },
1096 #define USHRT_MAX 0xFFFFU
1098 static int adc_to_temperature_centigrade(unsigned short adc)
1102 /* low_*: Greatest Lower Bound,
1103 * * * * high_*: Smallest Upper Bound */
1104 int low_temp = 0, high_temp = 0;
1105 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1106 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1107 if (adc_to_temperature_data[i].adc <= adc &&
1108 adc_to_temperature_data[i].adc >= low_adc) {
1109 low_temp = adc_to_temperature_data[i].centigrade;
1110 low_adc = adc_to_temperature_data[i].adc;
1112 if (adc_to_temperature_data[i].adc >= adc &&
1113 adc_to_temperature_data[i].adc <= high_adc) {
1114 high_temp = adc_to_temperature_data[i].centigrade;
1115 high_adc = adc_to_temperature_data[i].adc;
1119 /* Linear approximation between cloest low and high,
1120 * which is the weighted average of the two. */
1122 /* The following equation is correct only when the two are different */
1123 if (low_adc == high_adc)
1125 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1126 return 20; /* The room temperature */
1129 if (high_adc == USHRT_MAX)
1132 approximation = low_temp * (adc - low_adc) +
1133 high_temp * (high_adc - adc);
1134 approximation /= high_adc - low_adc;
1136 return approximation;
1139 static unsigned short get_adc_value(int channel)
1141 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1142 unsigned short ret = 0;
1146 unsigned int loop = 0;
1148 if (mach_is_kessler())
1150 else if (mach_is_geminus())
1152 else if (mach_is_wmg160())
1154 else if (mach_is_cypress())
1156 else if (mach_is_tickertape())
1158 else if (mach_is_aquila())
1161 else if (mach_is_p1p2())
1165 sprintf(buf, "pmic ldo %d on", ldonum);
1166 run_command(buf, 0);
1168 writel(channel & 0xF, &adc->adcmux);
1169 writel((1 << 14) | (49 << 6), &adc->adccon);
1170 writel(1000 & 0xffff, &adc->adcdly);
1171 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1173 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1178 reg = readl(&adc->adccon);
1179 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1181 ret = readl(&adc->adcdat0) & 0xFFF;
1182 sprintf(buf, "pmic ldo %d off", ldonum);
1183 run_command(buf, 0);
1188 static int adc_get_average_ambient_temperature(void)
1190 if (mach_is_kessler()) {
1191 unsigned short min = USHRT_MAX;
1192 unsigned short max = 0;
1193 unsigned int sum = 0;
1194 unsigned int measured = 0;
1197 for (i = 0; i < 7; i++) {
1198 unsigned short measurement = get_adc_value(6);
1201 if (min > measurement)
1203 if (max < measurement)
1206 if (measured >= 3) {
1212 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1213 adc_to_temperature_centigrade(sum), sum);
1214 return adc_to_temperature_centigrade(sum);
1217 return 20; /* 20 Centigrade */
1220 enum temperature_level {
1228 static enum temperature_level temperature_check(void)
1230 int temp = adc_get_average_ambient_temperature();
1232 return _TEMP_TOO_LOW;
1234 return _TEMP_OK_LOW;
1236 return _TEMP_TOO_HIGH;
1238 return _TEMP_OK_HIGH;
1242 extern void lcd_display_clear(void);
1243 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1245 static void charger_en(int enable)
1251 unsigned char addr = 0xCC >> 1; /* max8998 */
1252 unsigned char val[2];
1254 if (max8998_probe())
1258 puts("Disable the charger.\n");
1259 i2c_read(addr, 0x0D, 1, val, 1);
1262 i2c_write(addr, 0x0D, 1, val, 1);
1264 i2c_read(addr, 0x0C, 1, val, 1);
1265 val[0] &= ~(0x7 << 0);
1266 val[0] &= ~(0x7 << 5);
1267 if (enable == 600) {
1268 val[0] |= 5; /* 600mA */
1269 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1270 } else { /* Assume 475 mA */
1272 val[0] |= 2; /* 475mA */
1273 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1275 i2c_write(addr, 0x0C, 1, val, 1);
1277 i2c_read(addr, 0x0D, 1, val, 1);
1279 i2c_write(addr, 0x0D, 1, val, 1);
1280 printf("Enable the charger @ %dmA\n", enable);
1284 void lcd_power_on(unsigned int onoff);
1285 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1286 extern int drv_lcd_init_resume (void);
1288 static void into_charge_mode(void)
1294 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1295 unsigned int reg, wakeup_stat;
1296 int charger_speed = 600;
1298 max8998_clear_interrupt();
1300 puts("Charge Mode\n");
1301 charger_en(charger_speed);
1303 #ifdef CONFIG_S5PC1XXFB
1306 /* TODO: write the image-text for the charger */
1308 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1309 if (level >= CHARGER_ANIMATION_FRAME)
1310 level = CHARGER_ANIMATION_FRAME - 1;
1312 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1313 bmp_addr[i] = (ulong)battery_charging_animation[i];
1315 lcd_display_clear();
1316 for (i = 0; i < 3; i++) {
1317 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1320 bmp = gunzip_bmp(bmp_addr[j], &len);
1321 lcd_display_bitmap((ulong)bmp, 140, 202);
1324 for (k = 0; k < 10; k++) {
1325 if (max8998_power_key()) {
1326 lcd_display_clear();
1327 goto restore_screen;
1328 } else if (!max8998_has_ext_power_source()) {
1329 lcd_display_clear();
1330 goto restore_screen;
1339 /* Disable the display to prevent flickering */
1340 /* TODO: how to reenable the display later? */
1345 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1346 unsigned int org, org_ip3;
1347 enum temperature_level previous_state = _TEMP_OK;
1349 empty_device_info_buffer();
1350 if (max8998_power_key())
1352 else if (!max8998_has_ext_power_source())
1355 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1356 org_ip3 = readl(0xE010046C);
1357 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1359 reg = org = readl(&rtc->rtccon);
1361 writel(reg, &rtc->rtccon);
1363 reg = readl(&rtc->rtccon);
1364 writel(reg | (1 << 3), &rtc->rtccon);
1366 writel(reg & ~(1 << 3), &rtc->rtccon);
1369 reg = readl(&rtc->rtccon);
1370 reg &= ~((1 << 8) | (0xF << 4));
1371 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1372 writel(reg, &rtc->rtccon);
1374 reg = 15 * 4 - 1; /* 15 sec */
1375 writel(reg, &rtc->ticcnt);
1377 /* EVT0: sleep 1, EVT1: sleep */
1378 if (cpu_is_s5pc110()) {
1379 char *name = "dummy";
1380 char *usage = "N/A";
1387 if (s5pc1xx_get_cpu_rev() == 0) {
1388 char *argv[] = {"1", "1"};
1389 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1391 char *argv[] = {"0", "0"};
1392 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1395 puts("\n\n\nERROR: this is not S5PC110.\n\n\n");
1399 /* Check TEMP HIGH/LOW */
1400 switch (temperature_check()) {
1402 charger_en(charger_speed);
1403 previous_state = _TEMP_OK;
1407 previous_state = _TEMP_TOO_LOW;
1409 case _TEMP_TOO_HIGH:
1411 previous_state = _TEMP_TOO_HIGH;
1414 if (previous_state == _TEMP_TOO_LOW) {
1417 charger_en(charger_speed);
1418 previous_state = _TEMP_OK;
1422 if (previous_state == _TEMP_TOO_HIGH) {
1425 charger_en(charger_speed);
1426 previous_state = _TEMP_OK;
1431 writel(org, &rtc->rtccon);
1432 writel(org_ip3, 0xE010046C);
1434 } while (wakeup_stat == 0x04); /* RTC TICK */
1436 #ifdef CONFIG_S5PC1XXFB
1438 /* TODO: Reenable logo display (not working yet) */
1440 drv_lcd_init_resume();
1444 #define S5PC110_RST_STAT 0xE010A000
1446 #define SWRESET (1 << 3)
1447 #define WDTRESET (1 << 2)
1448 #define WARMRESET (1 << 1)
1449 #define EXTRESET (1 << 0)
1451 static int get_reset_status(void)
1453 return readl(S5PC110_RST_STAT) & 0xf;
1456 static int fsa9480_probe(void)
1458 unsigned char addr = 0x25;
1460 if (cpu_is_s5pc100())
1463 if (board_is_limo_real()) {
1464 if (hwrevision(0) || hwrevision(1))
1468 i2c_set_bus_num(I2C_PMIC);
1470 if (mach_is_kessler()) {
1471 i2c_set_bus_num(I2C_GPIO6);
1472 } else if (mach_is_cypress()) {
1473 i2c_set_bus_num(I2C_GPIO6);
1474 } else if (mach_is_geminus()) {
1476 i2c_set_bus_num(I2C_GPIO6);
1477 } else if (mach_is_wmg160()) {
1478 i2c_set_bus_num(I2C_GPIO6);
1481 if (i2c_probe(addr)) {
1482 puts("Can't found fsa9480\n");
1489 static void check_micro_usb(int intr)
1492 unsigned char val[2];
1493 static int started_charging_once = 0;
1496 if (fsa9480_probe())
1499 addr = 0x25; /* fsa9480 */
1501 /* Clear Interrupt */
1503 i2c_read(addr, 0x03, 1, val, 2);
1507 /* Read Device Type 1 */
1508 i2c_read(addr, 0x0a, 1, val, 1);
1510 #define FSA_DEV1_CHARGER (1 << 6)
1511 #define FSA_DEV1_UART (1 << 3)
1512 #define FSA_DEV1_USB (1 << 2)
1513 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1514 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1517 * If USB, use default 475mA
1518 * If Charger, use 600mA and go to charge mode
1520 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1521 started_charging_once = 1;
1523 /* If it's full, do not charge. */
1524 if (battery_soc < 100)
1528 } else if (val[0] & FSA_DEV1_USB) {
1529 if (battery_soc < 100)
1530 charger_en(475); /* enable charger and keep booting */
1535 /* If reset status is watchdog reset then skip it */
1536 if (!(get_reset_status() & WDTRESET)) {
1537 /* If Factory Mode is Boot ON-USB, go to download mode */
1538 i2c_read(addr, 0x07, 1, val, 1);
1540 #define FSA_ADC_FAC_USB_OFF 0x18
1541 #define FSA_ADC_FAC_USB_ON 0x19
1542 #define FSA_ADC_FAC_UART 0x1d
1544 if (val[0] == FSA_ADC_FAC_USB_ON ||
1545 val[0] == FSA_ADC_FAC_USB_OFF)
1546 setenv("bootcmd", "usbdown");
1549 path = getenv("usb");
1551 if (!strncmp(path, "cp", 2))
1552 run_command("microusb cp", 0);
1555 static void micro_usb_switch(int path)
1558 unsigned char val[2];
1560 if (fsa9480_probe())
1563 addr = 0x25; /* fsa9480 */
1566 val[0] = 0x90; /* VAUDIO */
1568 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1570 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1572 i2c_read(addr, 0x2, 1, val, 1);
1573 val[0] &= ~(1 << 2); /* Manual switching */
1574 i2c_write(addr, 0x2, 1, val, 1);
1577 #define MAX8998_REG_ONOFF1 0x11
1578 #define MAX8998_REG_ONOFF2 0x12
1579 #define MAX8998_REG_ONOFF3 0x13
1580 #define MAX8998_REG_LDO7 0x21
1581 #define MAX8998_REG_LDO17 0x29
1583 #define MAX8998_LDO3 (1 << 2)
1585 #define MAX8998_LDO6 (1 << 7)
1586 #define MAX8998_LDO7 (1 << 6)
1587 #define MAX8998_LDO8 (1 << 5)
1588 #define MAX8998_LDO9 (1 << 4)
1589 #define MAX8998_LDO10 (1 << 3)
1590 #define MAX8998_LDO11 (1 << 2)
1591 #define MAX8998_LDO12 (1 << 1)
1592 #define MAX8998_LDO13 (1 << 0)
1594 #define MAX8998_LDO14 (1 << 7)
1595 #define MAX8998_LDO15 (1 << 6)
1596 #define MAX8998_LDO16 (1 << 5)
1597 #define MAX8998_LDO17 (1 << 4)
1600 static void init_pmic(void)
1603 unsigned char val[2];
1605 if (cpu_is_s5pc100())
1608 addr = 0xCC >> 1; /* max8998 */
1609 if (max8998_probe())
1613 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1614 val[0] &= ~MAX8998_LDO3;
1615 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1618 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1620 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1621 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1623 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1624 MAX8998_LDO12 | MAX8998_LDO13);
1626 if (mach_is_kessler())
1627 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1629 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1630 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1632 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1634 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1635 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1637 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1638 MAX8998_LDO16 | MAX8998_LDO17);
1640 if (mach_is_kessler())
1641 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1643 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1644 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1647 static void setup_power_down_mode_registers(void)
1649 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1650 struct s5pc1xx_gpio_bank *bank;
1651 struct gpio_powermode *p;
1653 struct gpio_external *ge;
1655 struct s5pc1xx_gpio_item *mr;
1659 if (cpu_is_s5pc100())
1662 /* Only Limo real and kessler supports worked for sleep currnet */
1663 if (mach_is_aquila()) {
1664 if (board_is_limo_real())
1668 } else if (mach_is_kessler()) {
1670 } else if (mach_is_geminus()) {
1676 if (mach_is_aquila()) {
1677 /* Aquila rev 0.8 or lower */
1678 p = aquila_powerdown_modes;
1679 ge = aquila_external_powerdown_modes;
1680 mr = aquila_mirror_powerdown_mode;
1681 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1682 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1683 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1684 } else if (mach_is_kessler()) {
1685 /* Aquila rev 0.9 */
1686 p = kessler_powerdown_modes;
1687 ge = kessler_external_powerdown_modes;
1688 mr = kessler_mirror_powerdown_mode;
1689 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1690 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1691 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1692 } else if (mach_is_geminus()) {
1693 if (hwrevision(1)) {
1694 /* Same as Aquila rev 0.9 */
1696 p = kessler_powerdown_modes;
1697 ge = kessler_external_powerdown_modes;
1698 mr = kessler_mirror_powerdown_mode;
1699 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1700 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1701 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1703 p = aquila_powerdown_modes;
1704 ge = aquila_external_powerdown_modes;
1705 mr = aquila_mirror_powerdown_mode;
1706 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1707 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1708 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1710 } else if (hwrevision(0)) {
1711 /* Same as Aquila rev 0.8 or lower */
1712 p = aquila_powerdown_modes;
1713 ge = aquila_external_powerdown_modes;
1714 mr = aquila_mirror_powerdown_mode;
1715 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1716 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1717 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1719 return; /* Not supported */
1723 bank = &gpio->gpio_a0;
1725 for (i = 0; i < n_p; i++, p++, bank++) {
1726 writel(p->conpdn, &bank->pdn_con);
1727 writel(p->pudpdn, &bank->pdn_pull);
1730 writel(0xff0022b0, (unsigned int *)0xF0000000);
1731 writel(0xff0022b0, (unsigned int *)0xF1400000);
1733 bank = &gpio->gpio_h0;
1735 for (i = 0; i < n_ge; i++) {
1736 writel(ge->con, &bank->con);
1737 writel(ge->dat, &bank->dat);
1738 writel(ge->pud, &bank->pull);
1744 for (i = 0; i < n_mr; i++) {
1745 unsigned int reg = readl(&mr->bank->pdn_con);
1746 reg &= ~(0x3 << (mr->number << 1));
1747 if (readl(&mr->bank->dat) & (1 << mr->number))
1748 reg |= 0x1 << (mr->number << 1);
1749 writel(reg, &mr->bank->pdn_con);
1755 #include "../../../drivers/video/s5p-spi.h"
1757 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1758 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1760 struct spi_platform_data spi_pd;
1762 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1764 void lcd_cfg_gpio(void)
1766 unsigned int i, f3_end = 4;
1768 for (i = 0; i < 8; i++) {
1769 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1770 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1771 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1772 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1773 /* pull-up/down disable */
1774 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1775 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1776 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1778 /* drive strength to max (24bit) */
1779 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1780 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1781 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1782 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1783 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1784 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1787 /* set DISPLAY_DE_B pin for dual rgb mode. */
1788 if (board_is_media())
1791 for (i = 0; i < f3_end; i++) {
1792 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1793 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1794 /* pull-up/down disable */
1795 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1796 /* drive strength to max (24bit) */
1797 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1798 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1800 /* display output path selection (only [1:0] valid) */
1801 writel(0x2, 0xE0107008);
1803 /* gpio pad configuration for LCD reset. */
1804 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1806 /* gpio pad configuration for LCD ON. */
1807 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1809 /* LCD_BACKLIGHT_EN */
1810 if (mach_is_geminus())
1811 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1812 if (board_is_neptune() && hwrevision(0)) {
1813 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1814 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1818 * gpio pad configuration for
1819 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1821 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1822 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1823 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1824 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1826 if (mach_is_aquila() || mach_is_kessler()) {
1827 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1829 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1831 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1833 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1836 if (board_is_neptune() && hwrevision(0))
1837 s6d16a0x_set_platform_data(&spi_pd);
1839 s6e63m0_set_platform_data(&spi_pd);
1840 if (board_is_media())
1845 if (mach_is_cypress()) {
1846 #if 0 /* universal cypress */
1848 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1851 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1853 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1855 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1857 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1859 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1860 #if 0 /* universal cypress */
1861 pd_cs.bank = &gpio_base->gpio_mp0_1;
1864 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1866 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1868 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1873 /* these data would be sent to s6e63m0 lcd panel driver. */
1874 s6e63m0_set_platform_data(&spi_pd);
1880 #define SWRST_REG 0x00
1881 #define LEDCON_REG 0x01
1882 #define LED_CUR_SET_REG 0x03
1883 #define LED_CUR_TR_REG 0x08
1886 #define NORMAL_MODE 0x09
1887 #define CUR_SET 0x63
1889 void backlight_on(unsigned int onoff)
1893 unsigned char val[2];
1894 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1897 if (mach_is_geminus())
1898 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1900 if (mach_is_geminus())
1901 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1904 if (mach_is_kessler() && board_is_neptune() && hwrevision(0)) {
1905 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1908 i2c_set_bus_num(I2C_GPIO5);
1911 if (i2c_probe(addr)) {
1912 if (i2c_probe(addr)) {
1913 puts("Can't found s6d16a0x backlight i2c\n");
1918 i2c_write(addr, SWRST_REG, 1, val, 1);
1921 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1923 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1924 val[0] = NORMAL_MODE;
1925 i2c_write(addr, LEDCON_REG, 1, val, 1);
1930 void reset_lcd(void)
1932 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1934 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1935 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1936 if (mach_is_cypress())
1937 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1940 void lcd_power_on(unsigned int onoff)
1942 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1945 if (mach_is_aquila() || mach_is_geminus())
1946 gpio_set_value(&gpio->gpio_j1, 3, 1);
1948 if (mach_is_cypress())
1949 gpio_set_value(&gpio->gpio_g2, 2, 1);
1951 if (mach_is_kessler()) {
1953 unsigned char val[2];
1954 unsigned char val2[2];
1956 gpio_set_value(&gpio->gpio_j1, 3, 1);
1958 addr = 0xCC >> 1; /* max8998 */
1959 if (max8998_probe())
1962 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1963 val[0] &= ~(MAX8998_LDO17);
1964 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1965 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1967 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1968 val[0] |= MAX8998_LDO17;
1970 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1971 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1973 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1974 val[0] |= MAX8998_LDO7;
1976 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1977 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1980 if (mach_is_aquila() || mach_is_geminus())
1981 gpio_set_value(&gpio->gpio_j1, 3, 0);
1983 if (mach_is_cypress())
1984 gpio_set_value(&gpio->gpio_g2, 2, 0);
1986 if (mach_is_kessler()) {
1988 unsigned char val[2];
1990 gpio_set_value(&gpio->gpio_j1, 3, 0);
1992 addr = 0xCC >> 1; /* max8998 */
1993 if (max8998_probe())
1996 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1997 val[0] &= ~(MAX8998_LDO7);
1998 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1999 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2001 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2002 val[0] &= ~(MAX8998_LDO17);
2003 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2004 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2009 extern void s6e63m0_cfg_ldo(void);
2010 extern void s6e63m0_enable_ldo(unsigned int onoff);
2011 extern void s6d16a0x_cfg_ldo(void);
2012 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2014 int s5p_no_lcd_support(void)
2016 if (mach_is_wmg160())
2021 void init_panel_info(vidinfo_t *vid)
2023 vid->cfg_gpio = NULL;
2024 vid->reset_lcd = NULL;
2025 vid->backlight_on = NULL;
2026 vid->lcd_power_on = NULL;
2028 vid->cfg_ldo = NULL;
2029 vid->enable_ldo = NULL;
2031 vid->init_delay = 0;
2032 vid->reset_delay = 0;
2033 vid->power_on_delay = 0;
2038 vid->vl_width = 480;
2039 vid->vl_height = 800;
2041 vid->dual_lcd_enabled = 0;
2043 if (board_is_media()) {
2046 vid->vl_width = 960;
2047 vid->vl_height = 800;
2049 /* enable dual lcd mode. */
2050 vid->dual_lcd_enabled = 1;
2053 vid->vl_clkp = CONFIG_SYS_HIGH;
2054 vid->vl_hsp = CONFIG_SYS_LOW;
2055 vid->vl_vsp = CONFIG_SYS_LOW;
2056 vid->vl_dp = CONFIG_SYS_HIGH;
2059 /* S6E63M0 LCD Panel */
2068 if (mach_is_aquila() || mach_is_kessler()
2069 || mach_is_cypress()) {
2070 vid->cfg_gpio = lcd_cfg_gpio;
2071 vid->reset_lcd = reset_lcd;
2072 vid->backlight_on = backlight_on;
2073 vid->lcd_power_on = lcd_power_on;
2074 vid->cfg_ldo = s6e63m0_cfg_ldo;
2075 vid->enable_ldo = s6e63m0_enable_ldo;
2077 vid->init_delay = 25000;
2078 vid->reset_delay = 120000;
2081 if (board_is_neptune() && hwrevision(0)) {
2085 vid->vl_width = 320;
2086 vid->vl_height = 480;
2088 vid->vl_clkp = CONFIG_SYS_HIGH;
2089 vid->vl_hsp = CONFIG_SYS_HIGH;
2090 vid->vl_vsp = CONFIG_SYS_HIGH;
2091 vid->vl_dp = CONFIG_SYS_LOW;
2094 /* disable dual lcd mode. */
2095 vid->dual_lcd_enabled = 0;
2097 /* S6D16A0X LCD Panel */
2106 vid->cfg_gpio = lcd_cfg_gpio;
2107 vid->backlight_on = backlight_on;
2108 vid->lcd_power_on = lcd_power_on;
2109 vid->reset_lcd = reset_lcd;
2110 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2111 vid->enable_ldo = s6d16a0x_enable_ldo;
2113 vid->init_delay = 10000;
2114 vid->power_on_delay = 10000;
2115 vid->reset_delay = 1000;
2119 if (mach_is_geminus()) {
2123 vid->vl_width = 1024,
2124 vid->vl_height = 600,
2125 vid->vl_clkp = CONFIG_SYS_LOW,
2126 vid->vl_hsp = CONFIG_SYS_HIGH,
2127 vid->vl_vsp = CONFIG_SYS_HIGH,
2128 vid->vl_dp = CONFIG_SYS_LOW,
2139 vid->cfg_gpio = lcd_cfg_gpio;
2140 vid->reset_lcd = reset_lcd;
2141 vid->backlight_on = backlight_on;
2142 vid->lcd_power_on = lcd_power_on;
2148 vid->vl_width = 480,
2149 vid->vl_height = 800,
2150 vid->vl_clkp = CONFIG_SYS_HIGH,
2151 vid->vl_hsp = CONFIG_SYS_LOW,
2152 vid->vl_vsp = CONFIG_SYS_LOW,
2153 vid->vl_dp = CONFIG_SYS_HIGH,
2169 vid->vl_width = 1024,
2170 vid->vl_height = 600,
2171 vid->vl_clkp = CONFIG_SYS_HIGH,
2172 vid->vl_hsp = CONFIG_SYS_HIGH,
2173 vid->vl_vsp = CONFIG_SYS_HIGH,
2174 vid->vl_dp = CONFIG_SYS_LOW,
2177 /* AMS701KA AMOLED Panel. */
2189 static void setup_meminfo(void)
2191 char meminfo[64] = {0, };
2192 int count = 0, size, real;
2194 size = gd->bd->bi_dram[0].size >> 20;
2195 count += sprintf(meminfo + count, "mem=%dM", size);
2197 /* Each Chip Select can't exceed the 256MiB */
2198 size = gd->bd->bi_dram[1].size >> 20;
2199 real = min(size, 256);
2200 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2201 real, (unsigned int)gd->bd->bi_dram[1].start);
2205 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2206 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2209 setenv("meminfo", meminfo);
2212 int misc_init_r(void)
2215 /* It should be located at first */
2218 if (mach_is_aquila() || mach_is_kessler()) {
2219 if (board_is_neptune() && hwrevision(0))
2220 setenv("lcdinfo", "lcd=s6d16a0x");
2221 else if (board_is_media())
2222 setenv("lcdinfo", "lcd=s6e63m0");
2224 setenv("lcdinfo", "lcd=s6e63m0");
2226 if (mach_is_geminus())
2227 setenv("lcdinfo", "lcd=lms480jc01");
2228 if (mach_is_cypress())
2229 setenv("lcdinfo", "lcd=s6e63m0");
2235 /* Set proper PMIC pins */
2238 /* Check auto burning */
2241 /* To power up I2C2 */
2244 /* Enable T-Flash at Limo Real or Limo Universal */
2247 /* Setup Limo Real board GPIOs */
2248 setup_limo_real_gpios();
2250 /* Setup Media board GPIOs */
2251 setup_media_gpios();
2253 /* To usbdown automatically */
2259 #ifdef CONFIG_S5PC1XXFB
2260 display_device_info();
2263 setup_power_down_mode_registers();
2265 /* check max17040 */
2275 int board_init(void)
2277 /* Set Initial global variables */
2278 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2280 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2281 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2285 * set reserved memory region for framebuffer.
2287 * this region wouldn't be rewrited by kernel so
2288 * could avoid nosie screen filled by garbages
2289 * after hibernation resume has been completed.
2291 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2294 /* Check H/W Revision */
2295 check_hw_revision();
2302 unsigned int base, memconfig0, size;
2303 unsigned int memconfig1, sz = 0;
2305 if (cpu_is_s5pc100()) {
2306 /* In mem setup, we swap the bank. So below size is correct */
2307 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2308 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2309 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2312 /* In S5PC110, we can't swap the DMC0/1 */
2313 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2314 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2316 base = S5PC110_DMC1_BASE;
2317 /* DMC configuration */
2318 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2319 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2321 size = (memconfig0 >> 16) & 0xFF;
2322 size = ((unsigned char) ~size) + 1;
2325 * (0x07 + 1) * 16 = 128 MiB
2326 * (0x0f + 1) * 16 = 256 MiB
2331 * Aquila Rev0.5 4G3G1G
2332 * Aquila Rev0.8 4G3G1G
2333 * Aquila Rev0.9 4G3G1G
2335 if (mach_is_aquila() || mach_is_kessler()) {
2336 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2337 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2339 sz = (memconfig1 >> 16) & 0xFF;
2340 sz = ((unsigned char) ~sz) + 1;
2343 if (mach_is_kessler() && board_is_s1())
2348 * bi_dram[1].size contains all DMC1 memory size
2350 gd->bd->bi_dram[1].size = (size + sz) << 20;
2355 /* Used for sleep test */
2356 static unsigned char saved_val[4][2];
2357 void board_sleep_init_late(void)
2359 /* CODEC_LDO_EN: GPF3[4] */
2360 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2361 /* CODEC_XTAL_EN: GPH3[2] */
2362 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2364 /* MMC T_FLASH off */
2365 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2367 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2368 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2369 /* MHL_ON for REV02 or higher */
2370 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2373 void board_sleep_init(void)
2376 unsigned char val[2];
2379 if (max8998_probe())
2382 if (mach_is_kessler()) {
2384 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2385 saved_val[0][0] = val[0];
2386 saved_val[0][1] = val[1];
2387 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2388 (1 << 1) | (1 << 0));
2389 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2390 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2393 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2394 saved_val[1][0] = val[0];
2395 saved_val[1][1] = val[1];
2396 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2397 (1 << 2) | (1 << 1) | (1 << 0));
2399 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2400 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2403 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2404 saved_val[2][0] = val[0];
2405 saved_val[2][1] = val[1];
2406 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2407 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2408 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2411 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2412 saved_val[3][0] = val[0];
2413 saved_val[3][1] = val[1];
2414 val[0] &= ~((1 << 6) | (1 << 4));
2415 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2416 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2418 printf("Turned off regulators with Kessler setting."
2419 " Preparing to sleep. [%s:%d]\n",
2420 __FILE__, __LINE__);
2421 } else { /* Default */
2423 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2424 saved_val[0][0] = val[0];
2425 saved_val[0][1] = val[1];
2426 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2427 (1 << 1) | (1 << 0));
2428 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2429 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2432 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2433 saved_val[1][0] = val[0];
2434 saved_val[1][1] = val[1];
2435 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2436 (1 << 2) | (1 << 1) | (1 << 0));
2438 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2439 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2442 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2443 saved_val[2][0] = val[0];
2444 saved_val[2][1] = val[1];
2445 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2446 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2447 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2450 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2451 saved_val[3][0] = val[0];
2452 saved_val[3][1] = val[1];
2453 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2454 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2455 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2457 printf("Turned off regulators with default(Aquila) setting."
2458 " Preparing to sleep. [%s:%d]\n",
2459 __FILE__, __LINE__);
2463 void board_sleep_resume(void)
2466 unsigned char val[2];
2471 if (max8998_probe())
2475 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2476 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2478 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2479 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2481 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2482 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2484 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2485 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2486 puts("Waked up.\n");
2488 /* check max17040 */
2495 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2497 static int s5pc1xx_phy_control(int on)
2501 if (on && !status) {
2502 #ifdef CONFIG_CMD_PMIC
2503 run_command("pmic ldo 3 on", 0);
2506 if (board_is_limo_universal() ||
2507 board_is_limo_real() ||
2509 /* check usb path */
2510 if (board_is_limo_real() && !hwrevision(6))
2514 if (mach_is_tickertape())
2515 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2516 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2518 /* USB Path to AP */
2519 micro_usb_switch(0);
2521 } else if (!on && status) {
2522 #ifdef CONFIG_CMD_PMIC
2523 run_command("pmic ldo 3 off", 0);
2532 struct s3c_plat_otg_data s5pc110_otg_data = {
2533 .phy_control = s5pc1xx_phy_control,
2534 .regs_phy = S5PC110_PHY_BASE,
2535 .regs_otg = S5PC110_OTG_BASE,
2538 int board_eth_init(bd_t *bis)
2542 if (cpu_is_s5pc100())
2545 s3c_udc_probe(&s5pc110_otg_data);
2546 if (usb_eth_initialize(bis) >= 0)
2552 #ifdef CONFIG_CMD_USBDOWN
2553 int usb_board_init(void)
2555 #ifdef CONFIG_CMD_PMIC
2556 run_command("pmic ldo 3 on", 0);
2559 if (cpu_is_s5pc100()) {
2560 #ifdef CONFIG_HARD_I2C
2561 uchar val[2] = {0,};
2564 if (i2c_read(0x66, 0, 1, val, 2)) {
2565 puts("i2c_read error\n");
2572 if (i2c_write(0x66, 0, 1, val, 2)) {
2573 puts("i2c_write error\n");
2576 i2c_read(0x66, 0, 1, val, 2);
2582 if (board_is_limo_universal() ||
2583 board_is_limo_real() ||
2585 /* check usb path */
2586 if (board_is_limo_real() && !hwrevision(6))
2590 if (mach_is_tickertape())
2591 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2592 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2594 /* USB Path to AP */
2595 micro_usb_switch(0);
2601 #ifdef CONFIG_GENERIC_MMC
2602 int s5p_no_mmc_support(void)
2604 if (mach_is_wmg160())
2609 int board_mmc_init(bd_t *bis)
2613 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2616 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2617 if (mach_is_kessler())
2618 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2620 if (mach_is_wmg160())
2623 /* MMC0 Clock source = SCLKMPLL */
2624 reg = readl(&clk->src4);
2627 writel(reg, &clk->src4);
2629 reg = readl(&clk->div4);
2632 /* set div value near 50MHz */
2633 clock = get_pll_clk(MPLL) / 1000000;
2634 for (i = 0; i < 0xf; i++) {
2635 if ((clock / (i + 1)) <= 50) {
2641 writel(reg, &clk->div4);
2647 * GPG0[2] SD_0_CDn -> Not used
2648 * GPG0[3:6] SD_0_DATA[0:3]
2650 for (i = 0; i < 7; i++) {
2653 /* GPG0[0:6] special function 2 */
2654 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2655 /* GPG0[0:6] pull disable */
2656 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2657 /* GPG0[0:6] drv 4x */
2658 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2661 if (mach_is_geminus()) {
2662 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2663 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2666 return s5pc1xx_mmc_init(0);
2670 #ifdef CONFIG_CMD_PMIC
2671 static int pmic_status(void)
2673 unsigned char addr, val[2];
2678 if (max8998_probe())
2682 i2c_read(addr, reg, 1, val, 1);
2683 for (i = 7; i >= 4; i--)
2684 printf("BUCK%d %s\n", 7 - i + 1,
2685 val[0] & (1 << i) ? "on" : "off");
2687 printf("LDO%d %s\n", 5 - i,
2688 val[0] & (1 << i) ? "on" : "off");
2690 i2c_read(addr, reg, 1, val, 1);
2691 for (i = 7; i >= 0; i--)
2692 printf("LDO%d %s\n", 7 - i + 6,
2693 val[0] & (1 << i) ? "on" : "off");
2695 i2c_read(addr, reg, 1, val, 1);
2696 for (i = 7; i >= 4; i--)
2697 printf("LDO%d %s\n", 7 - i + 14,
2698 val[0] & (1 << i) ? "on" : "off");
2701 i2c_read(addr, reg, 1, val, 1);
2702 for (i = 7; i >= 6; i--)
2703 printf("SAFEOUT%d %s\n", 7 - i + 1,
2704 val[0] & (1 << i) ? "on" : "off");
2708 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2710 unsigned char addr, val[2];
2711 unsigned int reg, shift;
2719 } else if (ldo <= 13) {
2722 } else if (ldo <= 17) {
2724 shift = 17 - ldo + 4;
2731 shift = 4 - buck + 4;
2732 } else if (safeout) {
2736 shift = 8 - safeout;
2742 if (max8998_probe())
2745 i2c_read(addr, reg, 1, val, 1);
2747 val[0] |= (1 << shift);
2749 val[0] &= ~(1 << shift);
2750 i2c_write(addr, reg, 1, val, 1);
2751 i2c_read(addr, reg, 1, val, 1);
2754 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2755 val[0] & (1 << shift) ? "on" : "off");
2757 printf("buck %d value 0x%x, %s\n", buck, val[0],
2758 val[0] & (1 << shift) ? "on" : "off");
2760 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2761 val[0] & (1 << shift) ? "on" : "off");
2766 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2768 int buck = 0, ldo = 0, safeout = 0, on = -1;
2772 if (strncmp(argv[1], "status", 6) == 0)
2773 return pmic_status();
2776 if (strncmp(argv[1], "ldo", 3) == 0)
2777 ldo = simple_strtoul(argv[2], NULL, 10);
2778 else if (strncmp(argv[1], "buck", 4) == 0)
2779 buck = simple_strtoul(argv[2], NULL, 10);
2780 else if (strncmp(argv[1], "safeout", 7) == 0)
2781 safeout = simple_strtoul(argv[2], NULL, 10);
2785 if (strncmp(argv[3], "on", 2) == 0)
2787 else if (strncmp(argv[3], "off", 3) == 0)
2792 return pmic_ldo_control(buck, ldo, safeout, on);
2803 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2804 "PMIC LDO & BUCK control",
2805 "status - Display PMIC LDO & BUCK status\n"
2806 "pmic ldo num on/off - Turn on/off the LDO\n"
2807 "pmic buck num on/off - Turn on/off the BUCK\n"
2808 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2812 #ifdef CONFIG_CMD_DEVICE_POWER
2813 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2817 if (strncmp(argv[1], "cp", 2) == 0) {
2818 micro_usb_switch(1);
2819 pmic_ldo_control(0, 0, 2, 1);
2820 setenv("usb", "cp");
2821 } else if (strncmp(argv[1], "ap", 2) == 0) {
2822 micro_usb_switch(0);
2823 pmic_ldo_control(0, 0, 2, 0);
2824 setenv("usb", "ap");
2834 printf("USB Path is set to %s\n", getenv("usb"));
2840 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2842 "cp - switch to CP\n"
2843 "microusb ap - switch to AP\n"