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 printf("Auto burning bootloader\n");
721 count += sprintf(buf + count, "run updateb; ");
723 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
724 printf("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()) {
904 /* home & volume down */
905 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
908 /* cam full shot & volume down */
909 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
912 } else if (mach_is_geminus())
913 /* volume down & home */
914 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
918 setenv("bootcmd", "usbdown");
921 static void check_battery(int mode)
923 unsigned char val[2];
924 unsigned char addr = 0x36; /* max17040 fuel gauge */
926 i2c_set_bus_num(I2C_GPIO3);
928 if (mach_is_aquila()) {
931 } else if (mach_is_kessler()) {
932 i2c_set_bus_num(I2C_GPIO7);
933 } else if (mach_is_cypress()) {
934 i2c_set_bus_num(I2C_GPIO7);
935 } else if (mach_is_geminus()) {
937 i2c_set_bus_num(I2C_GPIO7);
941 if (i2c_probe(addr)) {
942 printf("Can't found max17040 fuel gauge\n");
946 /* mode 0: check mode / 1: enable mode */
950 i2c_write(addr, 0xfe, 1, val, 2);
952 i2c_read(addr, 0x04, 1, val, 1);
953 dprintf("battery:\t%d%%\n", val[0]);
954 battery_soc = val[0];
958 static void check_mhl(void)
960 unsigned char val[2];
961 unsigned char addr = 0x39; /* SIL9230 */
963 /* MHL Power enable */
964 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
965 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
967 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
968 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
970 /* 10ms required after reset */
974 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
976 i2c_set_bus_num(I2C_GPIO5);
979 if (i2c_probe(addr)) {
980 printf("Can't found MHL Chip\n");
986 * set to Normal operation
989 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
990 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
995 * 00 = MHL termination ON
996 * 11 = MHL termination OFF
999 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1000 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1003 static int max8998_probe(void)
1005 unsigned char addr = 0xCC >> 1;
1007 i2c_set_bus_num(I2C_PMIC);
1009 if (i2c_probe(addr)) {
1010 printf("Can't found max8998\n");
1017 #define CHARGER_ANIMATION_FRAME 6
1018 static void max8998_clear_interrupt(void)
1020 unsigned char addr, val[2];
1023 if (max8998_probe())
1026 i2c_read(addr, 0x00, 1, val, 1);
1027 i2c_read(addr, 0x01, 1, val, 1);
1028 i2c_read(addr, 0x02, 1, val, 1);
1029 i2c_read(addr, 0x03, 1, val, 1);
1032 static int max8998_power_key(void)
1034 unsigned char addr, val[2];
1037 if (max8998_probe())
1040 /* Accessing IRQ1 register */
1041 i2c_read(addr, 0x00, 1, val, 1);
1042 if (val[0] & (1 << 6))
1048 static int max8998_has_ext_power_source(void)
1050 unsigned char addr, val[2];
1053 if (max8998_probe())
1056 /* Accessing STATUS2 register */
1057 i2c_read(addr, 0x09, 1, val, 1);
1058 if (val[0] & (1 << 5))
1064 struct thermister_stat {
1069 static struct thermister_stat adc_to_temperature_data[] = {
1070 { .centigrade = -20, .adc = 1856, },
1071 { .centigrade = -15, .adc = 1799, },
1072 { .centigrade = -10, .adc = 1730, },
1073 { .centigrade = -5, .adc = 1649, },
1074 { .centigrade = 0, .adc = 1556, },
1075 { .centigrade = 5, .adc = 1454, },
1076 { .centigrade = 10, .adc = 1343, },
1077 { .centigrade = 15, .adc = 1227, },
1078 { .centigrade = 20, .adc = 1109, },
1079 { .centigrade = 25, .adc = 992, },
1080 { .centigrade = 30, .adc = 880, },
1081 { .centigrade = 35, .adc = 773, },
1082 { .centigrade = 40, .adc = 675, },
1083 { .centigrade = 45, .adc = 586, },
1084 { .centigrade = 50, .adc = 507, },
1085 { .centigrade = 55, .adc = 436, },
1086 { .centigrade = 58, .adc = 399, },
1087 { .centigrade = 63, .adc = 343, },
1088 { .centigrade = 65, .adc = 322, },
1092 #define USHRT_MAX 0xFFFFU
1094 static int adc_to_temperature_centigrade(unsigned short adc)
1098 /* low_*: Greatest Lower Bound,
1099 * * * * high_*: Smallest Upper Bound */
1100 int low_temp = 0, high_temp = 0;
1101 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1102 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1103 if (adc_to_temperature_data[i].adc <= adc &&
1104 adc_to_temperature_data[i].adc >= low_adc) {
1105 low_temp = adc_to_temperature_data[i].centigrade;
1106 low_adc = adc_to_temperature_data[i].adc;
1108 if (adc_to_temperature_data[i].adc >= adc &&
1109 adc_to_temperature_data[i].adc <= high_adc) {
1110 high_temp = adc_to_temperature_data[i].centigrade;
1111 high_adc = adc_to_temperature_data[i].adc;
1115 /* Linear approximation between cloest low and high,
1116 * which is the weighted average of the two. */
1118 /* The following equation is correct only when the two are different */
1119 if (low_adc == high_adc)
1121 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1122 return 20; /* The room temperature */
1125 if (high_adc == USHRT_MAX)
1128 approximation = low_temp * (adc - low_adc) +
1129 high_temp * (high_adc - adc);
1130 approximation /= high_adc - low_adc;
1132 return approximation;
1135 static unsigned short get_adc_value(int channel)
1137 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1138 unsigned short ret = 0;
1142 unsigned int loop = 0;
1144 if (mach_is_kessler())
1146 else if (mach_is_geminus())
1148 else if (mach_is_wmg160())
1150 else if (mach_is_cypress())
1152 else if (mach_is_tickertape())
1154 else if (mach_is_aquila())
1157 else if (mach_is_p1p2())
1161 sprintf(buf, "pmic ldo %d on", ldonum);
1162 run_command(buf, 0);
1164 writel(channel & 0xF, &adc->adcmux);
1165 writel((1 << 14) | (49 << 6), &adc->adccon);
1166 writel(1000 & 0xffff, &adc->adcdly);
1167 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1169 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1174 reg = readl(&adc->adccon);
1175 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1177 ret = readl(&adc->adcdat0) & 0xFFF;
1178 sprintf(buf, "pmic ldo %d off", ldonum);
1179 run_command(buf, 0);
1184 static int adc_get_average_ambient_temperature(void)
1186 if (mach_is_kessler()) {
1187 unsigned short min = USHRT_MAX;
1188 unsigned short max = 0;
1189 unsigned int sum = 0;
1190 unsigned int measured = 0;
1193 for (i = 0; i < 7; i++) {
1194 unsigned short measurement = get_adc_value(6);
1197 if (min > measurement)
1199 if (max < measurement)
1202 if (measured >= 3) {
1208 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1209 adc_to_temperature_centigrade(sum), sum);
1210 return adc_to_temperature_centigrade(sum);
1213 return 20; /* 20 Centigrade */
1216 enum temperature_level {
1224 static enum temperature_level temperature_check(void)
1226 int temp = adc_get_average_ambient_temperature();
1228 return _TEMP_TOO_LOW;
1230 return _TEMP_OK_LOW;
1232 return _TEMP_TOO_HIGH;
1234 return _TEMP_OK_HIGH;
1238 extern void lcd_display_clear(void);
1239 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1241 static void charger_en(int enable)
1247 unsigned char addr = 0xCC >> 1; /* max8998 */
1248 unsigned char val[2];
1250 if (max8998_probe())
1254 printf("Disable the charger.\n");
1255 i2c_read(addr, 0x0D, 1, val, 1);
1258 i2c_write(addr, 0x0D, 1, val, 1);
1260 i2c_read(addr, 0x0C, 1, val, 1);
1261 val[0] &= ~(0x7 << 0);
1262 val[0] &= ~(0x7 << 5);
1263 if (enable == 600) {
1264 val[0] |= 5; /* 600mA */
1265 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1266 } else { /* Assume 475 mA */
1268 val[0] |= 2; /* 475mA */
1269 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1271 i2c_write(addr, 0x0C, 1, val, 1);
1273 i2c_read(addr, 0x0D, 1, val, 1);
1275 i2c_write(addr, 0x0D, 1, val, 1);
1276 printf("Enable the charger @ %dmA\n", enable);
1280 void lcd_power_on(unsigned int onoff);
1281 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1282 extern int drv_lcd_init_resume (void);
1284 static void into_charge_mode(void)
1290 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1291 unsigned int reg, wakeup_stat;
1292 int charger_speed = 600;
1294 max8998_clear_interrupt();
1296 printf("Charge Mode\n");
1297 charger_en(charger_speed);
1299 #ifdef CONFIG_S5PC1XXFB
1302 /* TODO: write the image-text for the charger */
1304 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1305 if (level >= CHARGER_ANIMATION_FRAME)
1306 level = CHARGER_ANIMATION_FRAME - 1;
1308 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1309 bmp_addr[i] = (ulong)battery_charging_animation[i];
1311 lcd_display_clear();
1312 for (i = 0; i < 3; i++) {
1313 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1316 bmp = gunzip_bmp(bmp_addr[j], &len);
1317 lcd_display_bitmap((ulong)bmp, 140, 202);
1320 for (k = 0; k < 10; k++) {
1321 if (max8998_power_key()) {
1322 lcd_display_clear();
1323 goto restore_screen;
1324 } else if (!max8998_has_ext_power_source()) {
1325 lcd_display_clear();
1326 goto restore_screen;
1335 /* Disable the display to prevent flickering */
1336 /* TODO: how to reenable the display later? */
1341 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1342 unsigned int org, org_ip3;
1343 enum temperature_level previous_state = _TEMP_OK;
1345 empty_device_info_buffer();
1346 if (max8998_power_key())
1348 else if (!max8998_has_ext_power_source())
1351 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1352 org_ip3 = readl(0xE010046C);
1353 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1355 reg = org = readl(&rtc->rtccon);
1357 writel(reg, &rtc->rtccon);
1359 reg = readl(&rtc->rtccon);
1360 writel(reg | (1 << 3), &rtc->rtccon);
1362 writel(reg & ~(1 << 3), &rtc->rtccon);
1365 reg = readl(&rtc->rtccon);
1366 reg &= ~((1 << 8) | (0xF << 4));
1367 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1368 writel(reg, &rtc->rtccon);
1370 reg = 15 * 4 - 1; /* 15 sec */
1371 writel(reg, &rtc->ticcnt);
1373 /* EVT0: sleep 1, EVT1: sleep */
1374 if (cpu_is_s5pc110()) {
1375 char *name = "dummy";
1376 char *usage = "N/A";
1383 if (s5pc1xx_get_cpu_rev() == 0) {
1384 char *argv[] = {"1", "1"};
1385 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1387 char *argv[] = {"0", "0"};
1388 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1391 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1395 /* Check TEMP HIGH/LOW */
1396 switch (temperature_check()) {
1398 charger_en(charger_speed);
1399 previous_state = _TEMP_OK;
1403 previous_state = _TEMP_TOO_LOW;
1405 case _TEMP_TOO_HIGH:
1407 previous_state = _TEMP_TOO_HIGH;
1410 if (previous_state == _TEMP_TOO_LOW) {
1413 charger_en(charger_speed);
1414 previous_state = _TEMP_OK;
1418 if (previous_state == _TEMP_TOO_HIGH) {
1421 charger_en(charger_speed);
1422 previous_state = _TEMP_OK;
1427 writel(org, &rtc->rtccon);
1428 writel(org_ip3, 0xE010046C);
1430 } while (wakeup_stat == 0x04); /* RTC TICK */
1432 #ifdef CONFIG_S5PC1XXFB
1434 /* TODO: Reenable logo display (not working yet) */
1436 drv_lcd_init_resume();
1440 #define S5PC110_RST_STAT 0xE010A000
1442 #define SWRESET (1 << 3)
1443 #define WDTRESET (1 << 2)
1444 #define WARMRESET (1 << 1)
1445 #define EXTRESET (1 << 0)
1447 static int get_reset_status(void)
1449 return readl(S5PC110_RST_STAT) & 0xf;
1452 static int fsa9480_probe(void)
1454 unsigned char addr = 0x25;
1456 if (cpu_is_s5pc100())
1459 if (board_is_limo_real()) {
1460 if (hwrevision(0) || hwrevision(1))
1464 i2c_set_bus_num(I2C_PMIC);
1466 if (mach_is_kessler()) {
1467 i2c_set_bus_num(I2C_GPIO6);
1468 } else if (mach_is_cypress()) {
1469 i2c_set_bus_num(I2C_GPIO6);
1470 } else if (mach_is_geminus()) {
1472 i2c_set_bus_num(I2C_GPIO6);
1473 } else if (mach_is_wmg160()) {
1474 i2c_set_bus_num(I2C_GPIO6);
1477 if (i2c_probe(addr)) {
1478 printf("Can't found fsa9480\n");
1485 static void check_micro_usb(int intr)
1488 unsigned char val[2];
1489 static int started_charging_once = 0;
1492 if (fsa9480_probe())
1495 addr = 0x25; /* fsa9480 */
1497 /* Clear Interrupt */
1499 i2c_read(addr, 0x03, 1, val, 2);
1503 /* Read Device Type 1 */
1504 i2c_read(addr, 0x0a, 1, val, 1);
1506 #define FSA_DEV1_CHARGER (1 << 6)
1507 #define FSA_DEV1_UART (1 << 3)
1508 #define FSA_DEV1_USB (1 << 2)
1509 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1510 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1513 * If USB, use default 475mA
1514 * If Charger, use 600mA and go to charge mode
1516 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1517 started_charging_once = 1;
1519 /* If it's full, do not charge. */
1520 if (battery_soc < 100)
1524 } else if (val[0] & FSA_DEV1_USB) {
1525 if (battery_soc < 100)
1526 charger_en(475); /* enable charger and keep booting */
1531 /* If reset status is watchdog reset then skip it */
1532 if (!(get_reset_status() & WDTRESET)) {
1533 /* If Factory Mode is Boot ON-USB, go to download mode */
1534 i2c_read(addr, 0x07, 1, val, 1);
1536 #define FSA_ADC_FAC_USB_OFF 0x18
1537 #define FSA_ADC_FAC_USB_ON 0x19
1538 #define FSA_ADC_FAC_UART 0x1d
1540 if (val[0] == FSA_ADC_FAC_USB_ON ||
1541 val[0] == FSA_ADC_FAC_USB_OFF)
1542 setenv("bootcmd", "usbdown");
1545 path = getenv("usb");
1547 if (!strncmp(path, "cp", 2))
1548 run_command("microusb cp", 0);
1551 static void micro_usb_switch(int path)
1554 unsigned char val[2];
1556 if (fsa9480_probe())
1559 addr = 0x25; /* fsa9480 */
1562 val[0] = 0x90; /* VAUDIO */
1564 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1566 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1568 i2c_read(addr, 0x2, 1, val, 1);
1569 val[0] &= ~(1 << 2); /* Manual switching */
1570 i2c_write(addr, 0x2, 1, val, 1);
1573 #define MAX8998_REG_ONOFF1 0x11
1574 #define MAX8998_REG_ONOFF2 0x12
1575 #define MAX8998_REG_ONOFF3 0x13
1576 #define MAX8998_REG_LDO7 0x21
1577 #define MAX8998_REG_LDO17 0x29
1579 #define MAX8998_LDO3 (1 << 2)
1581 #define MAX8998_LDO6 (1 << 7)
1582 #define MAX8998_LDO7 (1 << 6)
1583 #define MAX8998_LDO8 (1 << 5)
1584 #define MAX8998_LDO9 (1 << 4)
1585 #define MAX8998_LDO10 (1 << 3)
1586 #define MAX8998_LDO11 (1 << 2)
1587 #define MAX8998_LDO12 (1 << 1)
1588 #define MAX8998_LDO13 (1 << 0)
1590 #define MAX8998_LDO14 (1 << 7)
1591 #define MAX8998_LDO15 (1 << 6)
1592 #define MAX8998_LDO16 (1 << 5)
1593 #define MAX8998_LDO17 (1 << 4)
1596 static void init_pmic(void)
1599 unsigned char val[2];
1601 if (cpu_is_s5pc100())
1604 addr = 0xCC >> 1; /* max8998 */
1605 if (max8998_probe())
1609 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1610 val[0] &= ~MAX8998_LDO3;
1611 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1614 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1616 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1617 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1619 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1620 MAX8998_LDO12 | MAX8998_LDO13);
1622 if (mach_is_kessler())
1623 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1625 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1626 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1628 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1630 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1631 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1633 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1634 MAX8998_LDO16 | MAX8998_LDO17);
1636 if (mach_is_kessler())
1637 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1639 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1640 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1643 static void setup_power_down_mode_registers(void)
1645 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1646 struct s5pc1xx_gpio_bank *bank;
1647 struct gpio_powermode *p;
1649 struct gpio_external *ge;
1651 struct s5pc1xx_gpio_item *mr;
1655 if (cpu_is_s5pc100())
1658 /* Only Limo real and kessler supports worked for sleep currnet */
1659 if (mach_is_aquila()) {
1660 if (board_is_limo_real())
1664 } else if (mach_is_kessler()) {
1666 } else if (mach_is_geminus()) {
1672 if (mach_is_aquila()) {
1673 /* Aquila rev 0.8 or lower */
1674 p = aquila_powerdown_modes;
1675 ge = aquila_external_powerdown_modes;
1676 mr = aquila_mirror_powerdown_mode;
1677 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1678 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1679 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1680 } else if (mach_is_kessler()) {
1681 /* Aquila rev 0.9 */
1682 p = kessler_powerdown_modes;
1683 ge = kessler_external_powerdown_modes;
1684 mr = kessler_mirror_powerdown_mode;
1685 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1686 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1687 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1688 } else if (mach_is_geminus()) {
1689 if (hwrevision(1)) {
1690 /* Same as Aquila rev 0.9 */
1692 p = kessler_powerdown_modes;
1693 ge = kessler_external_powerdown_modes;
1694 mr = kessler_mirror_powerdown_mode;
1695 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1696 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1697 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1699 p = aquila_powerdown_modes;
1700 ge = aquila_external_powerdown_modes;
1701 mr = aquila_mirror_powerdown_mode;
1702 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1703 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1704 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1706 } else if (hwrevision(0)) {
1707 /* Same as Aquila rev 0.8 or lower */
1708 p = aquila_powerdown_modes;
1709 ge = aquila_external_powerdown_modes;
1710 mr = aquila_mirror_powerdown_mode;
1711 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1712 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1713 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1715 return; /* Not supported */
1719 bank = &gpio->gpio_a0;
1721 for (i = 0; i < n_p; i++, p++, bank++) {
1722 writel(p->conpdn, &bank->pdn_con);
1723 writel(p->pudpdn, &bank->pdn_pull);
1726 writel(0xff0022b0, (unsigned int *)0xF0000000);
1727 writel(0xff0022b0, (unsigned int *)0xF1400000);
1729 bank = &gpio->gpio_h0;
1731 for (i = 0; i < n_ge; i++) {
1732 writel(ge->con, &bank->con);
1733 writel(ge->dat, &bank->dat);
1734 writel(ge->pud, &bank->pull);
1740 for (i = 0; i < n_mr; i++) {
1741 unsigned int reg = readl(&mr->bank->pdn_con);
1742 reg &= ~(0x3 << (mr->number << 1));
1743 if (readl(&mr->bank->dat) & (1 << mr->number))
1744 reg |= 0x1 << (mr->number << 1);
1745 writel(reg, &mr->bank->pdn_con);
1751 #include "../../../drivers/video/s5p-spi.h"
1753 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1754 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1756 struct spi_platform_data spi_pd;
1758 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1760 void lcd_cfg_gpio(void)
1762 unsigned int i, f3_end = 4;
1764 for (i = 0; i < 8; i++) {
1765 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1766 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1767 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1768 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1769 /* pull-up/down disable */
1770 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1771 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1772 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1774 /* drive strength to max (24bit) */
1775 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1776 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1777 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1778 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1779 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1780 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1783 /* set DISPLAY_DE_B pin for dual rgb mode. */
1784 if (board_is_media())
1787 for (i = 0; i < f3_end; i++) {
1788 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1789 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1790 /* pull-up/down disable */
1791 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1792 /* drive strength to max (24bit) */
1793 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1794 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1796 /* display output path selection (only [1:0] valid) */
1797 writel(0x2, 0xE0107008);
1799 /* gpio pad configuration for LCD reset. */
1800 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1802 /* gpio pad configuration for LCD ON. */
1803 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1805 /* LCD_BACKLIGHT_EN */
1806 if (mach_is_geminus())
1807 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1808 if (board_is_neptune() && hwrevision(0)) {
1809 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1810 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1814 * gpio pad configuration for
1815 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1817 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1818 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1820 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1822 if (mach_is_aquila() || mach_is_kessler()) {
1823 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1825 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1827 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1829 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1832 if (board_is_neptune() && hwrevision(0))
1833 s6d16a0x_set_platform_data(&spi_pd);
1835 s6e63m0_set_platform_data(&spi_pd);
1836 if (board_is_media())
1841 if (mach_is_cypress()) {
1842 #if 0 /* universal cypress */
1844 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1847 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1849 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1851 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1853 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1855 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1856 #if 0 /* universal cypress */
1857 pd_cs.bank = &gpio_base->gpio_mp0_1;
1860 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1862 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1864 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1869 /* these data would be sent to s6e63m0 lcd panel driver. */
1870 s6e63m0_set_platform_data(&spi_pd);
1876 #define SWRST_REG 0x00
1877 #define LEDCON_REG 0x01
1878 #define LED_CUR_SET_REG 0x03
1879 #define LED_CUR_TR_REG 0x08
1882 #define NORMAL_MODE 0x09
1883 #define CUR_SET 0x63
1885 void backlight_on(unsigned int onoff)
1889 unsigned char val[2];
1890 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1893 if (mach_is_geminus())
1894 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1896 if (mach_is_geminus())
1897 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1900 if (mach_is_kessler() && board_is_neptune() && hwrevision(0)) {
1901 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1904 i2c_set_bus_num(I2C_GPIO5);
1907 if (i2c_probe(addr)) {
1908 if (i2c_probe(addr)) {
1909 printf("Can't found s6d16a0x backlight i2c\n");
1914 i2c_write(addr, SWRST_REG, 1, val, 1);
1917 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1919 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1920 val[0] = NORMAL_MODE;
1921 i2c_write(addr, LEDCON_REG, 1, val, 1);
1926 void reset_lcd(void)
1928 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1930 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1931 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1932 if (mach_is_cypress())
1933 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1936 void lcd_power_on(unsigned int onoff)
1938 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1941 if (mach_is_aquila() || mach_is_geminus())
1942 gpio_set_value(&gpio->gpio_j1, 3, 1);
1944 if (mach_is_cypress())
1945 gpio_set_value(&gpio->gpio_g2, 2, 1);
1947 if (mach_is_kessler()) {
1949 unsigned char val[2];
1950 unsigned char val2[2];
1952 gpio_set_value(&gpio->gpio_j1, 3, 1);
1954 addr = 0xCC >> 1; /* max8998 */
1955 if (max8998_probe())
1958 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1959 val[0] &= ~(MAX8998_LDO17);
1960 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1961 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1963 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1964 val[0] |= MAX8998_LDO17;
1966 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1967 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1969 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1970 val[0] |= MAX8998_LDO7;
1972 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1973 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1976 if (mach_is_aquila() || mach_is_geminus())
1977 gpio_set_value(&gpio->gpio_j1, 3, 0);
1979 if (mach_is_cypress())
1980 gpio_set_value(&gpio->gpio_g2, 2, 0);
1982 if (mach_is_kessler()) {
1984 unsigned char val[2];
1986 gpio_set_value(&gpio->gpio_j1, 3, 0);
1988 addr = 0xCC >> 1; /* max8998 */
1989 if (max8998_probe())
1992 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1993 val[0] &= ~(MAX8998_LDO7);
1994 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1995 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1997 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1998 val[0] &= ~(MAX8998_LDO17);
1999 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2000 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2005 extern void s6e63m0_cfg_ldo(void);
2006 extern void s6e63m0_enable_ldo(unsigned int onoff);
2007 extern void s6d16a0x_cfg_ldo(void);
2008 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2010 int s5p_no_lcd_support(void)
2012 if (mach_is_wmg160())
2017 void init_panel_info(vidinfo_t *vid)
2019 vid->cfg_gpio = NULL;
2020 vid->reset_lcd = NULL;
2021 vid->backlight_on = NULL;
2022 vid->lcd_power_on = NULL;
2024 vid->cfg_ldo = NULL;
2025 vid->enable_ldo = NULL;
2027 vid->init_delay = 0;
2028 vid->reset_delay = 0;
2029 vid->power_on_delay = 0;
2034 vid->vl_width = 480;
2035 vid->vl_height = 800;
2037 vid->dual_lcd_enabled = 0;
2039 if (board_is_media()) {
2042 vid->vl_width = 960;
2043 vid->vl_height = 800;
2045 /* enable dual lcd mode. */
2046 vid->dual_lcd_enabled = 1;
2049 vid->vl_clkp = CONFIG_SYS_HIGH;
2050 vid->vl_hsp = CONFIG_SYS_LOW;
2051 vid->vl_vsp = CONFIG_SYS_LOW;
2052 vid->vl_dp = CONFIG_SYS_HIGH;
2055 /* S6E63M0 LCD Panel */
2064 if (mach_is_aquila() || mach_is_kessler()
2065 || mach_is_cypress()) {
2066 vid->cfg_gpio = lcd_cfg_gpio;
2067 vid->reset_lcd = reset_lcd;
2068 vid->backlight_on = backlight_on;
2069 vid->lcd_power_on = lcd_power_on;
2070 vid->cfg_ldo = s6e63m0_cfg_ldo;
2071 vid->enable_ldo = s6e63m0_enable_ldo;
2073 vid->init_delay = 25000;
2074 vid->reset_delay = 120000;
2077 if (board_is_neptune() && hwrevision(0)) {
2081 vid->vl_width = 320;
2082 vid->vl_height = 480;
2084 vid->vl_clkp = CONFIG_SYS_HIGH;
2085 vid->vl_hsp = CONFIG_SYS_HIGH;
2086 vid->vl_vsp = CONFIG_SYS_HIGH;
2087 vid->vl_dp = CONFIG_SYS_LOW;
2090 /* disable dual lcd mode. */
2091 vid->dual_lcd_enabled = 0;
2093 /* S6D16A0X LCD Panel */
2102 vid->cfg_gpio = lcd_cfg_gpio;
2103 vid->backlight_on = backlight_on;
2104 vid->lcd_power_on = lcd_power_on;
2105 vid->reset_lcd = reset_lcd;
2106 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2107 vid->enable_ldo = s6d16a0x_enable_ldo;
2109 vid->init_delay = 10000;
2110 vid->power_on_delay = 10000;
2111 vid->reset_delay = 1000;
2115 if (mach_is_geminus()) {
2119 vid->vl_width = 1024,
2120 vid->vl_height = 600,
2121 vid->vl_clkp = CONFIG_SYS_LOW,
2122 vid->vl_hsp = CONFIG_SYS_HIGH,
2123 vid->vl_vsp = CONFIG_SYS_HIGH,
2124 vid->vl_dp = CONFIG_SYS_LOW,
2135 vid->cfg_gpio = lcd_cfg_gpio;
2136 vid->reset_lcd = reset_lcd;
2137 vid->backlight_on = backlight_on;
2138 vid->lcd_power_on = lcd_power_on;
2144 vid->vl_width = 480,
2145 vid->vl_height = 800,
2146 vid->vl_clkp = CONFIG_SYS_HIGH,
2147 vid->vl_hsp = CONFIG_SYS_LOW,
2148 vid->vl_vsp = CONFIG_SYS_LOW,
2149 vid->vl_dp = CONFIG_SYS_HIGH,
2165 vid->vl_width = 1024,
2166 vid->vl_height = 600,
2167 vid->vl_clkp = CONFIG_SYS_HIGH,
2168 vid->vl_hsp = CONFIG_SYS_HIGH,
2169 vid->vl_vsp = CONFIG_SYS_HIGH,
2170 vid->vl_dp = CONFIG_SYS_LOW,
2173 /* AMS701KA AMOLED Panel. */
2185 static void setup_meminfo(void)
2187 char meminfo[64] = {0, };
2188 int count = 0, size, real;
2190 size = gd->bd->bi_dram[0].size >> 20;
2191 count += sprintf(meminfo + count, "mem=%dM", size);
2193 /* Each Chip Select can't exceed the 256MiB */
2194 size = gd->bd->bi_dram[1].size >> 20;
2195 real = min(size, 256);
2196 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2197 real, (unsigned int)gd->bd->bi_dram[1].start);
2201 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2202 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2205 setenv("meminfo", meminfo);
2208 int misc_init_r(void)
2211 /* It should be located at first */
2214 if (mach_is_aquila() || mach_is_kessler()) {
2215 if (board_is_neptune() && hwrevision(0))
2216 setenv("lcdinfo", "lcd=s6d16a0x");
2217 else if (board_is_media())
2218 setenv("lcdinfo", "lcd=s6e63m0");
2220 setenv("lcdinfo", "lcd=s6e63m0");
2222 if (mach_is_geminus())
2223 setenv("lcdinfo", "lcd=lms480jc01");
2224 if (mach_is_cypress())
2225 setenv("lcdinfo", "lcd=s6e63m0");
2231 /* Set proper PMIC pins */
2234 /* Check auto burning */
2237 /* To power up I2C2 */
2240 /* Enable T-Flash at Limo Real or Limo Universal */
2243 /* Setup Limo Real board GPIOs */
2244 setup_limo_real_gpios();
2246 /* Setup Media board GPIOs */
2247 setup_media_gpios();
2249 /* To usbdown automatically */
2255 #ifdef CONFIG_S5PC1XXFB
2256 display_device_info();
2259 setup_power_down_mode_registers();
2261 /* check max17040 */
2271 int board_init(void)
2273 /* Set Initial global variables */
2274 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2276 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2277 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2281 * set reserved memory region for framebuffer.
2283 * this region wouldn't be rewrited by kernel so
2284 * could avoid nosie screen filled by garbages
2285 * after hibernation resume has been completed.
2287 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2290 /* Check H/W Revision */
2291 check_hw_revision();
2298 unsigned int base, memconfig0, size;
2299 unsigned int memconfig1, sz = 0;
2301 if (cpu_is_s5pc100()) {
2302 /* In mem setup, we swap the bank. So below size is correct */
2303 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2304 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2305 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2308 /* In S5PC110, we can't swap the DMC0/1 */
2309 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2310 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2312 base = S5PC110_DMC1_BASE;
2313 /* DMC configuration */
2314 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2315 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2317 size = (memconfig0 >> 16) & 0xFF;
2318 size = ((unsigned char) ~size) + 1;
2321 * (0x07 + 1) * 16 = 128 MiB
2322 * (0x0f + 1) * 16 = 256 MiB
2327 * Aquila Rev0.5 4G3G1G
2328 * Aquila Rev0.8 4G3G1G
2329 * Aquila Rev0.9 4G3G1G
2331 if (mach_is_aquila() || mach_is_kessler()) {
2332 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2333 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2335 sz = (memconfig1 >> 16) & 0xFF;
2336 sz = ((unsigned char) ~sz) + 1;
2339 if (mach_is_kessler() && board_is_s1())
2344 * bi_dram[1].size contains all DMC1 memory size
2346 gd->bd->bi_dram[1].size = (size + sz) << 20;
2351 /* Used for sleep test */
2352 static unsigned char saved_val[4][2];
2353 void board_sleep_init_late(void)
2355 /* CODEC_LDO_EN: GPF3[4] */
2356 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2357 /* CODEC_XTAL_EN: GPH3[2] */
2358 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2360 /* MMC T_FLASH off */
2361 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2363 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2364 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2365 /* MHL_ON for REV02 or higher */
2366 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2369 void board_sleep_init(void)
2372 unsigned char val[2];
2375 if (max8998_probe())
2378 if (mach_is_kessler()) {
2380 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2381 saved_val[0][0] = val[0];
2382 saved_val[0][1] = val[1];
2383 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2384 (1 << 1) | (1 << 0));
2385 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2386 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2389 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2390 saved_val[1][0] = val[0];
2391 saved_val[1][1] = val[1];
2392 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2393 (1 << 2) | (1 << 1) | (1 << 0));
2395 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2396 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2400 saved_val[2][0] = val[0];
2401 saved_val[2][1] = val[1];
2402 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2403 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2404 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2407 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2408 saved_val[3][0] = val[0];
2409 saved_val[3][1] = val[1];
2410 val[0] &= ~((1 << 6) | (1 << 4));
2411 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2412 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2414 printf("Turned off regulators with Kessler setting."
2415 " Preparing to sleep. [%s:%d]\n",
2416 __FILE__, __LINE__);
2417 } else { /* Default */
2419 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2420 saved_val[0][0] = val[0];
2421 saved_val[0][1] = val[1];
2422 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2423 (1 << 1) | (1 << 0));
2424 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2425 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2429 saved_val[1][0] = val[0];
2430 saved_val[1][1] = val[1];
2431 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2432 (1 << 2) | (1 << 1) | (1 << 0));
2434 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2435 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2438 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2439 saved_val[2][0] = val[0];
2440 saved_val[2][1] = val[1];
2441 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2442 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2443 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2446 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2447 saved_val[3][0] = val[0];
2448 saved_val[3][1] = val[1];
2449 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2450 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2451 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2453 printf("Turned off regulators with default(Aquila) setting."
2454 " Preparing to sleep. [%s:%d]\n",
2455 __FILE__, __LINE__);
2459 void board_sleep_resume(void)
2462 unsigned char val[2];
2467 if (max8998_probe())
2471 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2472 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2474 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2475 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2477 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2478 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2480 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2481 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2482 printf("Waked up.\n");
2484 /* check max17040 */
2491 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2493 static int s5pc1xx_phy_control(int on)
2497 if (on && !status) {
2498 #ifdef CONFIG_CMD_PMIC
2499 run_command("pmic ldo 3 on", 0);
2502 if (board_is_limo_universal() ||
2503 board_is_limo_real() ||
2505 /* check usb path */
2506 if (board_is_limo_real() && !hwrevision(6))
2510 if (mach_is_tickertape())
2511 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2512 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2514 /* USB Path to AP */
2515 micro_usb_switch(0);
2517 } else if (!on && status) {
2518 #ifdef CONFIG_CMD_PMIC
2519 run_command("pmic ldo 3 off", 0);
2528 struct s3c_plat_otg_data s5pc110_otg_data = {
2529 .phy_control = s5pc1xx_phy_control,
2530 .regs_phy = S5PC110_PHY_BASE,
2531 .regs_otg = S5PC110_OTG_BASE,
2534 int board_eth_init(bd_t *bis)
2538 if (cpu_is_s5pc100())
2541 s3c_udc_probe(&s5pc110_otg_data);
2542 if (usb_eth_initialize(bis) >= 0)
2548 #ifdef CONFIG_CMD_USBDOWN
2549 int usb_board_init(void)
2551 #ifdef CONFIG_CMD_PMIC
2552 run_command("pmic ldo 3 on", 0);
2555 if (cpu_is_s5pc100()) {
2556 #ifdef CONFIG_HARD_I2C
2557 uchar val[2] = {0,};
2560 if (i2c_read(0x66, 0, 1, val, 2)) {
2561 printf("i2c_read error\n");
2568 if (i2c_write(0x66, 0, 1, val, 2)) {
2569 printf("i2c_write error\n");
2572 i2c_read(0x66, 0, 1, val, 2);
2578 if (board_is_limo_universal() ||
2579 board_is_limo_real() ||
2581 /* check usb path */
2582 if (board_is_limo_real() && !hwrevision(6))
2586 if (mach_is_tickertape())
2587 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2588 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2590 /* USB Path to AP */
2591 micro_usb_switch(0);
2597 #ifdef CONFIG_GENERIC_MMC
2598 int s5p_no_mmc_support(void)
2600 if (mach_is_wmg160())
2605 int board_mmc_init(bd_t *bis)
2609 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2612 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2613 if (mach_is_kessler())
2614 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2616 if (mach_is_wmg160())
2619 /* MMC0 Clock source = SCLKMPLL */
2620 reg = readl(&clk->src4);
2623 writel(reg, &clk->src4);
2625 reg = readl(&clk->div4);
2628 /* set div value near 50MHz */
2629 clock = get_pll_clk(MPLL) / 1000000;
2630 for (i = 0; i < 0xf; i++) {
2631 if ((clock / (i + 1)) <= 50) {
2637 writel(reg, &clk->div4);
2643 * GPG0[2] SD_0_CDn -> Not used
2644 * GPG0[3:6] SD_0_DATA[0:3]
2646 for (i = 0; i < 7; i++) {
2649 /* GPG0[0:6] special function 2 */
2650 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2651 /* GPG0[0:6] pull disable */
2652 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2653 /* GPG0[0:6] drv 4x */
2654 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2657 if (mach_is_geminus()) {
2658 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2659 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2662 return s5pc1xx_mmc_init(0);
2666 #ifdef CONFIG_CMD_PMIC
2667 static int pmic_status(void)
2669 unsigned char addr, val[2];
2674 if (max8998_probe())
2678 i2c_read(addr, reg, 1, val, 1);
2679 for (i = 7; i >= 4; i--)
2680 printf("BUCK%d %s\n", 7 - i + 1,
2681 val[0] & (1 << i) ? "on" : "off");
2683 printf("LDO%d %s\n", 5 - i,
2684 val[0] & (1 << i) ? "on" : "off");
2686 i2c_read(addr, reg, 1, val, 1);
2687 for (i = 7; i >= 0; i--)
2688 printf("LDO%d %s\n", 7 - i + 6,
2689 val[0] & (1 << i) ? "on" : "off");
2691 i2c_read(addr, reg, 1, val, 1);
2692 for (i = 7; i >= 4; i--)
2693 printf("LDO%d %s\n", 7 - i + 14,
2694 val[0] & (1 << i) ? "on" : "off");
2697 i2c_read(addr, reg, 1, val, 1);
2698 for (i = 7; i >= 6; i--)
2699 printf("SAFEOUT%d %s\n", 7 - i + 1,
2700 val[0] & (1 << i) ? "on" : "off");
2704 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2706 unsigned char addr, val[2];
2707 unsigned int reg, shift;
2715 } else if (ldo <= 13) {
2718 } else if (ldo <= 17) {
2720 shift = 17 - ldo + 4;
2727 shift = 4 - buck + 4;
2728 } else if (safeout) {
2732 shift = 8 - safeout;
2738 if (max8998_probe())
2741 i2c_read(addr, reg, 1, val, 1);
2743 val[0] |= (1 << shift);
2745 val[0] &= ~(1 << shift);
2746 i2c_write(addr, reg, 1, val, 1);
2747 i2c_read(addr, reg, 1, val, 1);
2750 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2751 val[0] & (1 << shift) ? "on" : "off");
2753 printf("buck %d value 0x%x, %s\n", buck, val[0],
2754 val[0] & (1 << shift) ? "on" : "off");
2756 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2757 val[0] & (1 << shift) ? "on" : "off");
2762 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2764 int buck = 0, ldo = 0, safeout = 0, on = -1;
2768 if (strncmp(argv[1], "status", 6) == 0)
2769 return pmic_status();
2772 if (strncmp(argv[1], "ldo", 3) == 0)
2773 ldo = simple_strtoul(argv[2], NULL, 10);
2774 else if (strncmp(argv[1], "buck", 4) == 0)
2775 buck = simple_strtoul(argv[2], NULL, 10);
2776 else if (strncmp(argv[1], "safeout", 7) == 0)
2777 safeout = simple_strtoul(argv[2], NULL, 10);
2781 if (strncmp(argv[3], "on", 2) == 0)
2783 else if (strncmp(argv[3], "off", 3) == 0)
2788 return pmic_ldo_control(buck, ldo, safeout, on);
2799 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2800 "PMIC LDO & BUCK control",
2801 "status - Display PMIC LDO & BUCK status\n"
2802 "pmic ldo num on/off - Turn on/off the LDO\n"
2803 "pmic buck num on/off - Turn on/off the BUCK\n"
2804 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2808 #ifdef CONFIG_CMD_DEVICE_POWER
2809 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2813 if (strncmp(argv[1], "cp", 2) == 0) {
2814 micro_usb_switch(1);
2815 pmic_ldo_control(0, 0, 2, 1);
2816 setenv("usb", "cp");
2817 } else if (strncmp(argv[1], "ap", 2) == 0) {
2818 micro_usb_switch(0);
2819 pmic_ldo_control(0, 0, 2, 0);
2820 setenv("usb", "ap");
2830 printf("USB Path is set to %s\n", getenv("usb"));
2836 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2838 "cp - switch to CP\n"
2839 "microusb ap - switch to AP\n"