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 s5pc1xx_set_cpu_rev(1);
690 } else if (mach_is_geminus()) {
691 if ((board_rev & 0xf) < 1)
692 s5pc1xx_set_cpu_rev(0);
693 } else if (mach_is_cypress()) {
694 s5pc1xx_set_cpu_rev(1);
696 s5pc1xx_set_cpu_rev(0);
699 if (cpu_is_s5pc110())
700 writel(0xc1100000 | (0xffff & s5pc1xx_get_cpu_rev()),
703 empty_device_info_buffer();
704 dprintf("HW Revision:\t%x (%s%s) %s\n",
705 board_rev, get_board_name(board),
706 display_features(board, board_rev),
707 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
710 static void check_auto_burn(void)
712 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
713 unsigned int count = 0;
716 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
717 printf("Auto burning bootloader\n");
718 count += sprintf(buf + count, "run updateb; ");
720 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
721 printf("Auto burning kernel\n");
722 count += sprintf(buf + count, "run updatek; ");
726 count += sprintf(buf + count, "reset");
727 setenv("bootcmd", buf);
730 /* Clear the magic value */
731 writel(0xa5a55a5a, magic_base);
732 writel(0xa5a55a5a, magic_base + 0x4);
735 static void pmic_pin_init(void)
737 unsigned int reg, value;
739 if (cpu_is_s5pc100())
742 /* AP_PS_HOLD: XEINT_0: GPH0[0]
743 * Note: Don't use GPIO PS_HOLD it doesn't work
745 reg = S5PC110_PS_HOLD_CONTROL;
747 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
748 S5PC110_PS_HOLD_DATA_HIGH |
749 S5PC110_PS_HOLD_OUT_EN;
752 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
753 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
754 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
757 static void enable_ldos(void)
759 if (cpu_is_s5pc100())
762 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
763 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
766 static void enable_t_flash(void)
768 if (!(board_is_limo_universal() || board_is_limo_real()))
771 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
772 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
775 static void setup_limo_real_gpios(void)
777 if (!board_is_limo_real())
781 * Note: Please write GPIO alphabet order
783 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
784 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
787 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
788 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
790 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
791 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
793 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
794 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
795 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
798 static void setup_media_gpios(void)
800 if (!board_is_media())
804 * Note: Please write GPIO alphabet order
806 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
807 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
809 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
810 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
811 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
814 #define KBR3 (1 << 3)
815 #define KBR2 (1 << 2)
816 #define KBR1 (1 << 1)
817 #define KBR0 (1 << 0)
819 static void check_keypad(void)
821 unsigned int reg, value;
822 unsigned int col_num, row_num;
823 unsigned int col_mask;
824 unsigned int col_mask_shift;
825 unsigned int row_state[4];
827 unsigned int auto_download = 0;
829 if (mach_is_wmg160())
832 if (cpu_is_s5pc100()) {
833 struct s5pc100_gpio *gpio =
834 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
839 /* Set GPH2[2:0] to KP_COL[2:0] */
840 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
841 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
842 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
844 /* Set GPH3[2:0] to KP_ROW[2:0] */
845 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
846 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
847 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
849 reg = S5PC100_KEYPAD_BASE;
850 col_mask = S5PC1XX_KEYIFCOL_MASK;
853 if (board_is_limo_real() || board_is_limo_universal()) {
861 for (i = 0; i < row_num; i++) {
862 /* Set GPH3[3:0] to KP_ROW[3:0] */
863 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
864 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
867 for (i = 0; i < col_num; i++)
868 /* Set GPH2[3:0] to KP_COL[3:0] */
869 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
871 reg = S5PC110_KEYPAD_BASE;
872 col_mask = S5PC110_KEYIFCOLEN_MASK;
876 /* KEYIFCOL reg clear */
877 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
880 for (i = 0; i < col_num; i++) {
882 value &= ~(1 << i) << col_mask_shift;
884 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
887 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
888 row_state[i] = ~value & ((1 << row_num) - 1);
890 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
893 /* KEYIFCOL reg clear */
894 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
896 if (mach_is_aquila() || mach_is_kessler()) {
898 if (row_state[1] & 0x2)
900 if (board_is_neptune()) {
901 /* home & volume down */
902 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
905 /* cam full shot & volume down */
906 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
909 } else if (mach_is_geminus())
910 /* volume down & home */
911 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
915 setenv("bootcmd", "usbdown");
918 static void check_battery(int mode)
920 unsigned char val[2];
921 unsigned char addr = 0x36; /* max17040 fuel gauge */
923 i2c_set_bus_num(I2C_GPIO3);
925 if (mach_is_aquila()) {
928 } else if (mach_is_kessler()) {
929 i2c_set_bus_num(I2C_GPIO7);
930 } else if (mach_is_cypress()) {
931 i2c_set_bus_num(I2C_GPIO7);
932 } else if (mach_is_geminus()) {
934 i2c_set_bus_num(I2C_GPIO7);
938 if (i2c_probe(addr)) {
939 printf("Can't found max17040 fuel gauge\n");
943 /* mode 0: check mode / 1: enable mode */
947 i2c_write(addr, 0xfe, 1, val, 2);
949 i2c_read(addr, 0x04, 1, val, 1);
950 dprintf("battery:\t%d%%\n", val[0]);
951 battery_soc = val[0];
955 static void check_mhl(void)
957 unsigned char val[2];
958 unsigned char addr = 0x39; /* SIL9230 */
960 /* MHL Power enable */
961 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
962 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
964 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
965 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
967 /* 10ms required after reset */
971 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
973 i2c_set_bus_num(I2C_GPIO5);
976 if (i2c_probe(addr)) {
977 printf("Can't found MHL Chip\n");
983 * set to Normal operation
986 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
987 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
992 * 00 = MHL termination ON
993 * 11 = MHL termination OFF
996 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
997 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1000 static int max8998_probe(void)
1002 unsigned char addr = 0xCC >> 1;
1004 i2c_set_bus_num(I2C_PMIC);
1006 if (i2c_probe(addr)) {
1007 printf("Can't found max8998\n");
1014 #define CHARGER_ANIMATION_FRAME 6
1015 static void max8998_clear_interrupt(void)
1017 unsigned char addr, val[2];
1020 if (max8998_probe())
1023 i2c_read(addr, 0x00, 1, val, 1);
1024 i2c_read(addr, 0x01, 1, val, 1);
1025 i2c_read(addr, 0x02, 1, val, 1);
1026 i2c_read(addr, 0x03, 1, val, 1);
1029 static int max8998_power_key(void)
1031 unsigned char addr, val[2];
1034 if (max8998_probe())
1037 /* Accessing IRQ1 register */
1038 i2c_read(addr, 0x00, 1, val, 1);
1039 if (val[0] & (1 << 6))
1045 static int max8998_has_ext_power_source(void)
1047 unsigned char addr, val[2];
1050 if (max8998_probe())
1053 /* Accessing STATUS2 register */
1054 i2c_read(addr, 0x09, 1, val, 1);
1055 if (val[0] & (1 << 5))
1061 struct thermister_stat {
1066 static struct thermister_stat adc_to_temperature_data[] = {
1067 { .centigrade = -20, .adc = 1856, },
1068 { .centigrade = -15, .adc = 1799, },
1069 { .centigrade = -10, .adc = 1730, },
1070 { .centigrade = -5, .adc = 1649, },
1071 { .centigrade = 0, .adc = 1556, },
1072 { .centigrade = 5, .adc = 1454, },
1073 { .centigrade = 10, .adc = 1343, },
1074 { .centigrade = 15, .adc = 1227, },
1075 { .centigrade = 20, .adc = 1109, },
1076 { .centigrade = 25, .adc = 992, },
1077 { .centigrade = 30, .adc = 880, },
1078 { .centigrade = 35, .adc = 773, },
1079 { .centigrade = 40, .adc = 675, },
1080 { .centigrade = 45, .adc = 586, },
1081 { .centigrade = 50, .adc = 507, },
1082 { .centigrade = 55, .adc = 436, },
1083 { .centigrade = 58, .adc = 399, },
1084 { .centigrade = 63, .adc = 343, },
1085 { .centigrade = 65, .adc = 322, },
1089 #define USHRT_MAX 0xFFFFU
1091 static int adc_to_temperature_centigrade(unsigned short adc)
1095 /* low_*: Greatest Lower Bound,
1096 * * * * high_*: Smallest Upper Bound */
1097 int low_temp = 0, high_temp = 0;
1098 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1099 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1100 if (adc_to_temperature_data[i].adc <= adc &&
1101 adc_to_temperature_data[i].adc >= low_adc) {
1102 low_temp = adc_to_temperature_data[i].centigrade;
1103 low_adc = adc_to_temperature_data[i].adc;
1105 if (adc_to_temperature_data[i].adc >= adc &&
1106 adc_to_temperature_data[i].adc <= high_adc) {
1107 high_temp = adc_to_temperature_data[i].centigrade;
1108 high_adc = adc_to_temperature_data[i].adc;
1112 /* Linear approximation between cloest low and high,
1113 * which is the weighted average of the two. */
1115 /* The following equation is correct only when the two are different */
1116 if (low_adc == high_adc)
1118 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1119 return 20; /* The room temperature */
1122 if (high_adc == USHRT_MAX)
1125 approximation = low_temp * (adc - low_adc) +
1126 high_temp * (high_adc - adc);
1127 approximation /= high_adc - low_adc;
1129 return approximation;
1132 static unsigned short get_adc_value(int channel)
1134 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1135 unsigned short ret = 0;
1139 unsigned int loop = 0;
1141 if (mach_is_kessler())
1143 else if (mach_is_geminus())
1145 else if (mach_is_wmg160())
1147 else if (mach_is_cypress())
1149 else if (mach_is_tickertape())
1151 else if (mach_is_aquila())
1154 else if (mach_is_p1p2())
1158 sprintf(buf, "pmic ldo %d on", ldonum);
1159 run_command(buf, 0);
1161 writel(channel & 0xF, &adc->adcmux);
1162 writel((1 << 14) | (49 << 6), &adc->adccon);
1163 writel(1000 & 0xffff, &adc->adcdly);
1164 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1166 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1171 reg = readl(&adc->adccon);
1172 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1174 ret = readl(&adc->adcdat0) & 0xFFF;
1175 sprintf(buf, "pmic ldo %d off", ldonum);
1176 run_command(buf, 0);
1181 static int adc_get_average_ambient_temperature(void)
1183 if (mach_is_kessler()) {
1184 unsigned short min = USHRT_MAX;
1185 unsigned short max = 0;
1186 unsigned int sum = 0;
1187 unsigned int measured = 0;
1190 for (i = 0; i < 7; i++) {
1191 unsigned short measurement = get_adc_value(6);
1194 if (min > measurement)
1196 if (max < measurement)
1199 if (measured >= 3) {
1205 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1206 adc_to_temperature_centigrade(sum), sum);
1207 return adc_to_temperature_centigrade(sum);
1210 return 20; /* 20 Centigrade */
1213 enum temperature_level {
1221 static enum temperature_level temperature_check(void)
1223 int temp = adc_get_average_ambient_temperature();
1225 return _TEMP_TOO_LOW;
1227 return _TEMP_OK_LOW;
1229 return _TEMP_TOO_HIGH;
1231 return _TEMP_OK_HIGH;
1235 extern void lcd_display_clear(void);
1236 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1238 static void charger_en(int enable)
1244 unsigned char addr = 0xCC >> 1; /* max8998 */
1245 unsigned char val[2];
1247 if (max8998_probe())
1251 printf("Disable the charger.\n");
1252 i2c_read(addr, 0x0D, 1, val, 1);
1255 i2c_write(addr, 0x0D, 1, val, 1);
1257 i2c_read(addr, 0x0C, 1, val, 1);
1258 val[0] &= ~(0x7 << 0);
1259 val[0] &= ~(0x7 << 5);
1260 if (enable == 600) {
1261 val[0] |= 5; /* 600mA */
1262 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1263 } else { /* Assume 475 mA */
1265 val[0] |= 2; /* 475mA */
1266 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1268 i2c_write(addr, 0x0C, 1, val, 1);
1270 i2c_read(addr, 0x0D, 1, val, 1);
1272 i2c_write(addr, 0x0D, 1, val, 1);
1273 printf("Enable the charger @ %dmA\n", enable);
1277 void lcd_power_on(unsigned int onoff);
1278 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1279 extern int drv_lcd_init_resume (void);
1281 static void into_charge_mode(void)
1287 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1288 unsigned int reg, wakeup_stat;
1289 int charger_speed = 600;
1291 max8998_clear_interrupt();
1293 printf("Charge Mode\n");
1294 charger_en(charger_speed);
1296 #ifdef CONFIG_S5PC1XXFB
1299 /* TODO: write the image-text for the charger */
1301 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1302 if (level >= CHARGER_ANIMATION_FRAME)
1303 level = CHARGER_ANIMATION_FRAME - 1;
1305 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1306 bmp_addr[i] = (ulong)battery_charging_animation[i];
1308 lcd_display_clear();
1309 for (i = 0; i < 3; i++) {
1310 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1313 bmp = gunzip_bmp(bmp_addr[j], &len);
1314 lcd_display_bitmap((ulong)bmp, 140, 202);
1317 for (k = 0; k < 10; k++) {
1318 if (max8998_power_key()) {
1319 lcd_display_clear();
1320 goto restore_screen;
1321 } else if (!max8998_has_ext_power_source()) {
1322 lcd_display_clear();
1323 goto restore_screen;
1332 /* Disable the display to prevent flickering */
1333 /* TODO: how to reenable the display later? */
1338 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1339 unsigned int org, org_ip3;
1340 enum temperature_level previous_state = _TEMP_OK;
1342 empty_device_info_buffer();
1343 if (max8998_power_key())
1345 else if (!max8998_has_ext_power_source())
1348 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1349 org_ip3 = readl(0xE010046C);
1350 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1352 reg = org = readl(&rtc->rtccon);
1354 writel(reg, &rtc->rtccon);
1356 reg = readl(&rtc->rtccon);
1357 writel(reg | (1 << 3), &rtc->rtccon);
1359 writel(reg & ~(1 << 3), &rtc->rtccon);
1362 reg = readl(&rtc->rtccon);
1363 reg &= ~((1 << 8) | (0xF << 4));
1364 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1365 writel(reg, &rtc->rtccon);
1367 reg = 15 * 4 - 1; /* 15 sec */
1368 writel(reg, &rtc->ticcnt);
1370 /* EVT0: sleep 1, EVT1: sleep */
1371 if (cpu_is_s5pc110()) {
1372 char *name = "dummy";
1373 char *usage = "N/A";
1380 if (s5pc1xx_get_cpu_rev() == 0) {
1381 char *argv[] = {"1", "1"};
1382 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1384 char *argv[] = {"0", "0"};
1385 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1388 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1392 /* Check TEMP HIGH/LOW */
1393 switch (temperature_check()) {
1395 charger_en(charger_speed);
1396 previous_state = _TEMP_OK;
1400 previous_state = _TEMP_TOO_LOW;
1402 case _TEMP_TOO_HIGH:
1404 previous_state = _TEMP_TOO_HIGH;
1407 if (previous_state == _TEMP_TOO_LOW) {
1410 charger_en(charger_speed);
1411 previous_state = _TEMP_OK;
1415 if (previous_state == _TEMP_TOO_HIGH) {
1418 charger_en(charger_speed);
1419 previous_state = _TEMP_OK;
1424 writel(org, &rtc->rtccon);
1425 writel(org_ip3, 0xE010046C);
1427 } while (wakeup_stat == 0x04); /* RTC TICK */
1429 #ifdef CONFIG_S5PC1XXFB
1431 /* TODO: Reenable logo display (not working yet) */
1433 drv_lcd_init_resume();
1437 #define S5PC110_RST_STAT 0xE010A000
1439 #define SWRESET (1 << 3)
1440 #define WDTRESET (1 << 2)
1441 #define WARMRESET (1 << 1)
1442 #define EXTRESET (1 << 0)
1444 static int get_reset_status(void)
1446 return readl(S5PC110_RST_STAT) & 0xf;
1449 static int fsa9480_probe(void)
1451 unsigned char addr = 0x25;
1453 if (cpu_is_s5pc100())
1456 if (board_is_limo_real()) {
1457 if (hwrevision(0) || hwrevision(1))
1461 i2c_set_bus_num(I2C_PMIC);
1463 if (mach_is_kessler()) {
1464 i2c_set_bus_num(I2C_GPIO6);
1465 } else if (mach_is_cypress()) {
1466 i2c_set_bus_num(I2C_GPIO6);
1467 } else if (mach_is_geminus()) {
1469 i2c_set_bus_num(I2C_GPIO6);
1470 } else if (mach_is_wmg160()) {
1471 i2c_set_bus_num(I2C_GPIO6);
1474 if (i2c_probe(addr)) {
1475 printf("Can't found fsa9480\n");
1482 static void check_micro_usb(int intr)
1485 unsigned char val[2];
1486 static int started_charging_once = 0;
1489 if (fsa9480_probe())
1492 addr = 0x25; /* fsa9480 */
1494 /* Clear Interrupt */
1496 i2c_read(addr, 0x03, 1, val, 2);
1500 /* Read Device Type 1 */
1501 i2c_read(addr, 0x0a, 1, val, 1);
1503 #define FSA_DEV1_CHARGER (1 << 6)
1504 #define FSA_DEV1_UART (1 << 3)
1505 #define FSA_DEV1_USB (1 << 2)
1506 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1507 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1510 * If USB, use default 475mA
1511 * If Charger, use 600mA and go to charge mode
1513 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1514 started_charging_once = 1;
1516 /* If it's full, do not charge. */
1517 if (battery_soc < 100)
1521 } else if (val[0] & FSA_DEV1_USB) {
1522 if (battery_soc < 100)
1523 charger_en(475); /* enable charger and keep booting */
1528 /* If reset status is watchdog reset then skip it */
1529 if (!(get_reset_status() & WDTRESET)) {
1530 /* If Factory Mode is Boot ON-USB, go to download mode */
1531 i2c_read(addr, 0x07, 1, val, 1);
1533 #define FSA_ADC_FAC_USB_OFF 0x18
1534 #define FSA_ADC_FAC_USB_ON 0x19
1535 #define FSA_ADC_FAC_UART 0x1d
1537 if (val[0] == FSA_ADC_FAC_USB_ON ||
1538 val[0] == FSA_ADC_FAC_USB_OFF)
1539 setenv("bootcmd", "usbdown");
1542 path = getenv("usb");
1544 if (!strncmp(path, "cp", 2))
1545 run_command("microusb cp", 0);
1548 static void micro_usb_switch(int path)
1551 unsigned char val[2];
1553 if (fsa9480_probe())
1556 addr = 0x25; /* fsa9480 */
1559 val[0] = 0x90; /* VAUDIO */
1561 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1563 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1565 i2c_read(addr, 0x2, 1, val, 1);
1566 val[0] &= ~(1 << 2); /* Manual switching */
1567 i2c_write(addr, 0x2, 1, val, 1);
1570 #define MAX8998_REG_ONOFF1 0x11
1571 #define MAX8998_REG_ONOFF2 0x12
1572 #define MAX8998_REG_ONOFF3 0x13
1573 #define MAX8998_REG_LDO7 0x21
1574 #define MAX8998_REG_LDO17 0x29
1576 #define MAX8998_LDO3 (1 << 2)
1578 #define MAX8998_LDO6 (1 << 7)
1579 #define MAX8998_LDO7 (1 << 6)
1580 #define MAX8998_LDO8 (1 << 5)
1581 #define MAX8998_LDO9 (1 << 4)
1582 #define MAX8998_LDO10 (1 << 3)
1583 #define MAX8998_LDO11 (1 << 2)
1584 #define MAX8998_LDO12 (1 << 1)
1585 #define MAX8998_LDO13 (1 << 0)
1587 #define MAX8998_LDO14 (1 << 7)
1588 #define MAX8998_LDO15 (1 << 6)
1589 #define MAX8998_LDO16 (1 << 5)
1590 #define MAX8998_LDO17 (1 << 4)
1593 static void init_pmic(void)
1596 unsigned char val[2];
1598 if (cpu_is_s5pc100())
1601 addr = 0xCC >> 1; /* max8998 */
1602 if (max8998_probe())
1606 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1607 val[0] &= ~MAX8998_LDO3;
1608 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1611 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1613 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1614 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1616 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1617 MAX8998_LDO12 | MAX8998_LDO13);
1619 if (mach_is_kessler())
1620 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1622 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1623 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1625 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1627 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1628 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1630 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1631 MAX8998_LDO16 | MAX8998_LDO17);
1633 if (mach_is_kessler())
1634 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1636 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1637 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1640 static void setup_power_down_mode_registers(void)
1642 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1643 struct s5pc1xx_gpio_bank *bank;
1644 struct gpio_powermode *p;
1646 struct gpio_external *ge;
1648 struct s5pc1xx_gpio_item *mr;
1652 if (cpu_is_s5pc100())
1655 /* Only Limo real and kessler supports worked for sleep currnet */
1656 if (mach_is_aquila()) {
1657 if (board_is_limo_real())
1661 } else if (mach_is_kessler()) {
1663 } else if (mach_is_geminus()) {
1669 if (mach_is_aquila()) {
1670 /* Aquila rev 0.8 or lower */
1671 p = aquila_powerdown_modes;
1672 ge = aquila_external_powerdown_modes;
1673 mr = aquila_mirror_powerdown_mode;
1674 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1675 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1676 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1677 } else if (mach_is_kessler()) {
1678 /* Aquila rev 0.9 */
1679 p = kessler_powerdown_modes;
1680 ge = kessler_external_powerdown_modes;
1681 mr = kessler_mirror_powerdown_mode;
1682 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1683 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1684 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1685 } else if (mach_is_geminus()) {
1686 if (hwrevision(1)) {
1687 /* Same as Aquila rev 0.9 */
1689 p = kessler_powerdown_modes;
1690 ge = kessler_external_powerdown_modes;
1691 mr = kessler_mirror_powerdown_mode;
1692 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1693 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1694 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1696 p = aquila_powerdown_modes;
1697 ge = aquila_external_powerdown_modes;
1698 mr = aquila_mirror_powerdown_mode;
1699 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1700 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1701 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1703 } else if (hwrevision(0)) {
1704 /* Same as Aquila rev 0.8 or lower */
1705 p = aquila_powerdown_modes;
1706 ge = aquila_external_powerdown_modes;
1707 mr = aquila_mirror_powerdown_mode;
1708 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1709 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1710 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1712 return; /* Not supported */
1716 bank = &gpio->gpio_a0;
1718 for (i = 0; i < n_p; i++, p++, bank++) {
1719 writel(p->conpdn, &bank->pdn_con);
1720 writel(p->pudpdn, &bank->pdn_pull);
1723 writel(0xff0022b0, (unsigned int *)0xF0000000);
1724 writel(0xff0022b0, (unsigned int *)0xF1400000);
1726 bank = &gpio->gpio_h0;
1728 for (i = 0; i < n_ge; i++) {
1729 writel(ge->con, &bank->con);
1730 writel(ge->dat, &bank->dat);
1731 writel(ge->pud, &bank->pull);
1737 for (i = 0; i < n_mr; i++) {
1738 unsigned int reg = readl(&mr->bank->pdn_con);
1739 reg &= ~(0x3 << (mr->number << 1));
1740 if (readl(&mr->bank->dat) & (1 << mr->number))
1741 reg |= 0x1 << (mr->number << 1);
1742 writel(reg, &mr->bank->pdn_con);
1748 #include "../../../drivers/video/s5p-spi.h"
1750 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1751 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1753 struct spi_platform_data spi_pd;
1755 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1757 void lcd_cfg_gpio(void)
1759 unsigned int i, f3_end = 4;
1761 for (i = 0; i < 8; i++) {
1762 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1763 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1764 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1765 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1766 /* pull-up/down disable */
1767 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1768 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1769 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1771 /* drive strength to max (24bit) */
1772 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1773 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1774 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1775 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1776 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1777 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1780 /* set DISPLAY_DE_B pin for dual rgb mode. */
1781 if (board_is_media())
1784 for (i = 0; i < f3_end; i++) {
1785 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1786 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1787 /* pull-up/down disable */
1788 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1789 /* drive strength to max (24bit) */
1790 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1791 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1793 /* display output path selection (only [1:0] valid) */
1794 writel(0x2, 0xE0107008);
1796 /* gpio pad configuration for LCD reset. */
1797 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1799 /* gpio pad configuration for LCD ON. */
1800 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1802 /* LCD_BACKLIGHT_EN */
1803 if (mach_is_geminus())
1804 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1805 if (board_is_neptune()) {
1806 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1807 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1811 * gpio pad configuration for
1812 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1814 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1815 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1816 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1817 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1819 if (mach_is_aquila() || mach_is_kessler()) {
1820 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1822 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1824 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1826 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1829 if (board_is_neptune())
1830 s6d16a0x_set_platform_data(&spi_pd);
1832 s6e63m0_set_platform_data(&spi_pd);
1833 if (board_is_media())
1838 if (mach_is_cypress()) {
1839 #if 0 /* universal cypress */
1841 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1844 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1846 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1848 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1850 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1852 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1853 #if 0 /* universal cypress */
1854 pd_cs.bank = &gpio_base->gpio_mp0_1;
1857 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1859 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1861 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1866 /* these data would be sent to s6e63m0 lcd panel driver. */
1867 s6e63m0_set_platform_data(&spi_pd);
1873 #define SWRST_REG 0x00
1874 #define LEDCON_REG 0x01
1875 #define LED_CUR_SET_REG 0x03
1876 #define LED_CUR_TR_REG 0x08
1879 #define NORMAL_MODE 0x09
1880 #define CUR_SET 0x63
1882 void backlight_on(unsigned int onoff)
1886 unsigned char val[2];
1887 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1890 if (mach_is_geminus())
1891 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1893 if (mach_is_geminus())
1894 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1897 if (mach_is_kessler() && board_is_neptune()) {
1898 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1901 i2c_set_bus_num(I2C_GPIO5);
1904 if (i2c_probe(addr)) {
1905 if (i2c_probe(addr)) {
1906 printf("Can't found s6d16a0x backlight i2c\n");
1911 i2c_write(addr, SWRST_REG, 1, val, 1);
1914 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1916 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1917 val[0] = NORMAL_MODE;
1918 i2c_write(addr, LEDCON_REG, 1, val, 1);
1923 void reset_lcd(void)
1925 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1927 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1928 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1929 if (mach_is_cypress())
1930 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1933 void lcd_power_on(unsigned int onoff)
1935 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1938 if (mach_is_aquila() || mach_is_geminus())
1939 gpio_set_value(&gpio->gpio_j1, 3, 1);
1941 if (mach_is_cypress())
1942 gpio_set_value(&gpio->gpio_g2, 2, 1);
1944 if (mach_is_kessler()) {
1946 unsigned char val[2];
1947 unsigned char val2[2];
1949 gpio_set_value(&gpio->gpio_j1, 3, 1);
1951 addr = 0xCC >> 1; /* max8998 */
1952 if (max8998_probe())
1955 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1956 val[0] &= ~(MAX8998_LDO17);
1957 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1958 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1960 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1961 val[0] |= MAX8998_LDO17;
1963 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1964 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1966 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1967 val[0] |= MAX8998_LDO7;
1969 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1970 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1973 if (mach_is_aquila() || mach_is_geminus())
1974 gpio_set_value(&gpio->gpio_j1, 3, 0);
1976 if (mach_is_cypress())
1977 gpio_set_value(&gpio->gpio_g2, 2, 0);
1979 if (mach_is_kessler()) {
1981 unsigned char val[2];
1983 gpio_set_value(&gpio->gpio_j1, 3, 0);
1985 addr = 0xCC >> 1; /* max8998 */
1986 if (max8998_probe())
1989 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1990 val[0] &= ~(MAX8998_LDO7);
1991 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1992 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1994 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1995 val[0] &= ~(MAX8998_LDO17);
1996 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1997 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2002 extern void s6e63m0_cfg_ldo(void);
2003 extern void s6e63m0_enable_ldo(unsigned int onoff);
2004 extern void s6d16a0x_cfg_ldo(void);
2005 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2007 int s5p_no_lcd_support(void)
2009 if (mach_is_wmg160())
2014 void init_panel_info(vidinfo_t *vid)
2016 vid->cfg_gpio = NULL;
2017 vid->reset_lcd = NULL;
2018 vid->backlight_on = NULL;
2019 vid->lcd_power_on = NULL;
2021 vid->cfg_ldo = NULL;
2022 vid->enable_ldo = NULL;
2024 vid->init_delay = 0;
2025 vid->reset_delay = 0;
2026 vid->power_on_delay = 0;
2031 vid->vl_width = 480;
2032 vid->vl_height = 800;
2034 vid->dual_lcd_enabled = 0;
2036 if (board_is_media()) {
2039 vid->vl_width = 960;
2040 vid->vl_height = 800;
2042 /* enable dual lcd mode. */
2043 vid->dual_lcd_enabled = 1;
2046 vid->vl_clkp = CONFIG_SYS_HIGH;
2047 vid->vl_hsp = CONFIG_SYS_LOW;
2048 vid->vl_vsp = CONFIG_SYS_LOW;
2049 vid->vl_dp = CONFIG_SYS_HIGH;
2052 /* S6E63M0 LCD Panel */
2061 if (mach_is_aquila() || mach_is_kessler()
2062 || mach_is_cypress()) {
2063 vid->cfg_gpio = lcd_cfg_gpio;
2064 vid->reset_lcd = reset_lcd;
2065 vid->backlight_on = backlight_on;
2066 vid->lcd_power_on = lcd_power_on;
2067 vid->cfg_ldo = s6e63m0_cfg_ldo;
2068 vid->enable_ldo = s6e63m0_enable_ldo;
2070 vid->init_delay = 25000;
2071 vid->reset_delay = 120000;
2074 if (board_is_neptune()) {
2078 vid->vl_width = 320;
2079 vid->vl_height = 480;
2081 vid->vl_clkp = CONFIG_SYS_HIGH;
2082 vid->vl_hsp = CONFIG_SYS_HIGH;
2083 vid->vl_vsp = CONFIG_SYS_HIGH;
2084 vid->vl_dp = CONFIG_SYS_LOW;
2087 /* disable dual lcd mode. */
2088 vid->dual_lcd_enabled = 0;
2090 /* S6D16A0X LCD Panel */
2099 vid->cfg_gpio = lcd_cfg_gpio;
2100 vid->backlight_on = backlight_on;
2101 vid->lcd_power_on = lcd_power_on;
2102 vid->reset_lcd = reset_lcd;
2103 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2104 vid->enable_ldo = s6d16a0x_enable_ldo;
2106 vid->init_delay = 10000;
2107 vid->power_on_delay = 10000;
2108 vid->reset_delay = 1000;
2112 if (mach_is_geminus()) {
2116 vid->vl_width = 1024,
2117 vid->vl_height = 600,
2118 vid->vl_clkp = CONFIG_SYS_LOW,
2119 vid->vl_hsp = CONFIG_SYS_HIGH,
2120 vid->vl_vsp = CONFIG_SYS_HIGH,
2121 vid->vl_dp = CONFIG_SYS_LOW,
2132 vid->cfg_gpio = lcd_cfg_gpio;
2133 vid->reset_lcd = reset_lcd;
2134 vid->backlight_on = backlight_on;
2135 vid->lcd_power_on = lcd_power_on;
2141 vid->vl_width = 480,
2142 vid->vl_height = 800,
2143 vid->vl_clkp = CONFIG_SYS_HIGH,
2144 vid->vl_hsp = CONFIG_SYS_LOW,
2145 vid->vl_vsp = CONFIG_SYS_LOW,
2146 vid->vl_dp = CONFIG_SYS_HIGH,
2162 vid->vl_width = 1024,
2163 vid->vl_height = 600,
2164 vid->vl_clkp = CONFIG_SYS_HIGH,
2165 vid->vl_hsp = CONFIG_SYS_HIGH,
2166 vid->vl_vsp = CONFIG_SYS_HIGH,
2167 vid->vl_dp = CONFIG_SYS_LOW,
2170 /* AMS701KA AMOLED Panel. */
2182 static void setup_meminfo(void)
2184 char meminfo[64] = {0, };
2185 int count = 0, size, real;
2187 size = gd->bd->bi_dram[0].size >> 20;
2188 count += sprintf(meminfo + count, "mem=%dM", size);
2190 /* Each Chip Select can't exceed the 256MiB */
2191 size = gd->bd->bi_dram[1].size >> 20;
2192 real = min(size, 256);
2193 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2194 real, (unsigned int)gd->bd->bi_dram[1].start);
2198 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2199 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2202 setenv("meminfo", meminfo);
2205 int misc_init_r(void)
2208 /* It should be located at first */
2211 if (mach_is_aquila() || mach_is_kessler()) {
2212 if (board_is_neptune())
2213 setenv("lcdinfo", "lcd=s6d16a0x");
2214 else if (board_is_media())
2215 setenv("lcdinfo", "lcd=s6e63m0");
2217 setenv("lcdinfo", "lcd=s6e63m0");
2219 if (mach_is_geminus())
2220 setenv("lcdinfo", "lcd=lms480jc01");
2221 if (mach_is_cypress())
2222 setenv("lcdinfo", "lcd=s6e63m0");
2228 /* Set proper PMIC pins */
2231 /* Check auto burning */
2234 /* To power up I2C2 */
2237 /* Enable T-Flash at Limo Real or Limo Universal */
2240 /* Setup Limo Real board GPIOs */
2241 setup_limo_real_gpios();
2243 /* Setup Media board GPIOs */
2244 setup_media_gpios();
2246 /* To usbdown automatically */
2252 #ifdef CONFIG_S5PC1XXFB
2253 display_device_info();
2256 setup_power_down_mode_registers();
2258 /* check max17040 */
2268 int board_init(void)
2270 /* Set Initial global variables */
2271 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2273 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2274 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2278 * set reserved memory region for framebuffer.
2280 * this region wouldn't be rewrited by kernel so
2281 * could avoid nosie screen filled by garbages
2282 * after hibernation resume has been completed.
2284 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2287 /* Check H/W Revision */
2288 check_hw_revision();
2295 unsigned int base, memconfig0, size;
2296 unsigned int memconfig1, sz = 0;
2298 if (cpu_is_s5pc100()) {
2299 /* In mem setup, we swap the bank. So below size is correct */
2300 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2301 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2302 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2305 /* In S5PC110, we can't swap the DMC0/1 */
2306 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2307 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2309 base = S5PC110_DMC1_BASE;
2310 /* DMC configuration */
2311 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2312 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2314 size = (memconfig0 >> 16) & 0xFF;
2315 size = ((unsigned char) ~size) + 1;
2318 * (0x07 + 1) * 16 = 128 MiB
2319 * (0x0f + 1) * 16 = 256 MiB
2324 * Aquila Rev0.5 4G3G1G
2325 * Aquila Rev0.8 4G3G1G
2326 * Aquila Rev0.9 4G3G1G
2328 if (mach_is_aquila() || mach_is_kessler()) {
2329 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2330 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2332 sz = (memconfig1 >> 16) & 0xFF;
2333 sz = ((unsigned char) ~sz) + 1;
2336 if (mach_is_kessler() && board_is_s1())
2341 * bi_dram[1].size contains all DMC1 memory size
2343 gd->bd->bi_dram[1].size = (size + sz) << 20;
2348 /* Used for sleep test */
2349 static unsigned char saved_val[4][2];
2350 void board_sleep_init_late(void)
2352 /* CODEC_LDO_EN: GPF3[4] */
2353 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2354 /* CODEC_XTAL_EN: GPH3[2] */
2355 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2357 /* MMC T_FLASH off */
2358 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2360 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2361 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2362 /* MHL_ON for REV02 or higher */
2363 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2366 void board_sleep_init(void)
2369 unsigned char val[2];
2372 if (max8998_probe())
2375 if (mach_is_kessler()) {
2377 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2378 saved_val[0][0] = val[0];
2379 saved_val[0][1] = val[1];
2380 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2381 (1 << 1) | (1 << 0));
2382 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2383 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2386 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2387 saved_val[1][0] = val[0];
2388 saved_val[1][1] = val[1];
2389 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2390 (1 << 2) | (1 << 1) | (1 << 0));
2392 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2393 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2396 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2397 saved_val[2][0] = val[0];
2398 saved_val[2][1] = val[1];
2399 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2400 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2401 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2404 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2405 saved_val[3][0] = val[0];
2406 saved_val[3][1] = val[1];
2407 val[0] &= ~((1 << 6) | (1 << 4));
2408 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2409 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2411 printf("Turned off regulators with Kessler setting."
2412 " Preparing to sleep. [%s:%d]\n",
2413 __FILE__, __LINE__);
2414 } else { /* Default */
2416 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2417 saved_val[0][0] = val[0];
2418 saved_val[0][1] = val[1];
2419 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2420 (1 << 1) | (1 << 0));
2421 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2422 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2425 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2426 saved_val[1][0] = val[0];
2427 saved_val[1][1] = val[1];
2428 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2429 (1 << 2) | (1 << 1) | (1 << 0));
2431 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2432 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2435 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2436 saved_val[2][0] = val[0];
2437 saved_val[2][1] = val[1];
2438 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2439 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2440 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2443 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2444 saved_val[3][0] = val[0];
2445 saved_val[3][1] = val[1];
2446 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2447 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2448 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2450 printf("Turned off regulators with default(Aquila) setting."
2451 " Preparing to sleep. [%s:%d]\n",
2452 __FILE__, __LINE__);
2456 void board_sleep_resume(void)
2459 unsigned char val[2];
2464 if (max8998_probe())
2468 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2469 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2471 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2472 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2474 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2475 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2477 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2478 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2479 printf("Waked up.\n");
2481 /* check max17040 */
2488 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2490 static int s5pc1xx_phy_control(int on)
2494 if (on && !status) {
2495 #ifdef CONFIG_CMD_PMIC
2496 run_command("pmic ldo 3 on", 0);
2499 if (board_is_limo_universal() ||
2500 board_is_limo_real() ||
2502 /* check usb path */
2503 if (board_is_limo_real() && !hwrevision(6))
2507 if (mach_is_tickertape())
2508 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2509 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2511 /* USB Path to AP */
2512 micro_usb_switch(0);
2514 } else if (!on && status) {
2515 #ifdef CONFIG_CMD_PMIC
2516 run_command("pmic ldo 3 off", 0);
2525 struct s3c_plat_otg_data s5pc110_otg_data = {
2526 .phy_control = s5pc1xx_phy_control,
2527 .regs_phy = S5PC110_PHY_BASE,
2528 .regs_otg = S5PC110_OTG_BASE,
2531 int board_eth_init(bd_t *bis)
2535 if (cpu_is_s5pc100())
2538 s3c_udc_probe(&s5pc110_otg_data);
2539 if (usb_eth_initialize(bis) >= 0)
2545 #ifdef CONFIG_CMD_USBDOWN
2546 int usb_board_init(void)
2548 #ifdef CONFIG_CMD_PMIC
2549 run_command("pmic ldo 3 on", 0);
2552 if (cpu_is_s5pc100()) {
2553 #ifdef CONFIG_HARD_I2C
2554 uchar val[2] = {0,};
2557 if (i2c_read(0x66, 0, 1, val, 2)) {
2558 printf("i2c_read error\n");
2565 if (i2c_write(0x66, 0, 1, val, 2)) {
2566 printf("i2c_write error\n");
2569 i2c_read(0x66, 0, 1, val, 2);
2575 if (board_is_limo_universal() ||
2576 board_is_limo_real() ||
2578 /* check usb path */
2579 if (board_is_limo_real() && !hwrevision(6))
2583 if (mach_is_tickertape())
2584 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2585 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2587 /* USB Path to AP */
2588 micro_usb_switch(0);
2594 #ifdef CONFIG_GENERIC_MMC
2595 int s5p_no_mmc_support(void)
2597 if (mach_is_wmg160())
2602 int board_mmc_init(bd_t *bis)
2606 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2609 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2610 if (mach_is_kessler())
2611 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2613 if (mach_is_wmg160())
2616 /* MMC0 Clock source = SCLKMPLL */
2617 reg = readl(&clk->src4);
2620 writel(reg, &clk->src4);
2622 reg = readl(&clk->div4);
2625 /* set div value near 50MHz */
2626 clock = get_pll_clk(MPLL) / 1000000;
2627 for (i = 0; i < 0xf; i++) {
2628 if ((clock / (i + 1)) <= 50) {
2634 writel(reg, &clk->div4);
2640 * GPG0[2] SD_0_CDn -> Not used
2641 * GPG0[3:6] SD_0_DATA[0:3]
2643 for (i = 0; i < 7; i++) {
2646 /* GPG0[0:6] special function 2 */
2647 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2648 /* GPG0[0:6] pull disable */
2649 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2650 /* GPG0[0:6] drv 4x */
2651 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2654 if (mach_is_geminus()) {
2655 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2656 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2659 return s5pc1xx_mmc_init(0);
2663 #ifdef CONFIG_CMD_PMIC
2664 static int pmic_status(void)
2666 unsigned char addr, val[2];
2671 if (max8998_probe())
2675 i2c_read(addr, reg, 1, val, 1);
2676 for (i = 7; i >= 4; i--)
2677 printf("BUCK%d %s\n", 7 - i + 1,
2678 val[0] & (1 << i) ? "on" : "off");
2680 printf("LDO%d %s\n", 5 - i,
2681 val[0] & (1 << i) ? "on" : "off");
2683 i2c_read(addr, reg, 1, val, 1);
2684 for (i = 7; i >= 0; i--)
2685 printf("LDO%d %s\n", 7 - i + 6,
2686 val[0] & (1 << i) ? "on" : "off");
2688 i2c_read(addr, reg, 1, val, 1);
2689 for (i = 7; i >= 4; i--)
2690 printf("LDO%d %s\n", 7 - i + 14,
2691 val[0] & (1 << i) ? "on" : "off");
2694 i2c_read(addr, reg, 1, val, 1);
2695 for (i = 7; i >= 6; i--)
2696 printf("SAFEOUT%d %s\n", 7 - i + 1,
2697 val[0] & (1 << i) ? "on" : "off");
2701 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2703 unsigned char addr, val[2];
2704 unsigned int reg, shift;
2712 } else if (ldo <= 13) {
2715 } else if (ldo <= 17) {
2717 shift = 17 - ldo + 4;
2724 shift = 4 - buck + 4;
2725 } else if (safeout) {
2729 shift = 8 - safeout;
2735 if (max8998_probe())
2738 i2c_read(addr, reg, 1, val, 1);
2740 val[0] |= (1 << shift);
2742 val[0] &= ~(1 << shift);
2743 i2c_write(addr, reg, 1, val, 1);
2744 i2c_read(addr, reg, 1, val, 1);
2747 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2748 val[0] & (1 << shift) ? "on" : "off");
2750 printf("buck %d value 0x%x, %s\n", buck, val[0],
2751 val[0] & (1 << shift) ? "on" : "off");
2753 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2754 val[0] & (1 << shift) ? "on" : "off");
2759 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2761 int buck = 0, ldo = 0, safeout = 0, on = -1;
2765 if (strncmp(argv[1], "status", 6) == 0)
2766 return pmic_status();
2769 if (strncmp(argv[1], "ldo", 3) == 0)
2770 ldo = simple_strtoul(argv[2], NULL, 10);
2771 else if (strncmp(argv[1], "buck", 4) == 0)
2772 buck = simple_strtoul(argv[2], NULL, 10);
2773 else if (strncmp(argv[1], "safeout", 7) == 0)
2774 safeout = simple_strtoul(argv[2], NULL, 10);
2778 if (strncmp(argv[3], "on", 2) == 0)
2780 else if (strncmp(argv[3], "off", 3) == 0)
2785 return pmic_ldo_control(buck, ldo, safeout, on);
2796 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2797 "PMIC LDO & BUCK control",
2798 "status - Display PMIC LDO & BUCK status\n"
2799 "pmic ldo num on/off - Turn on/off the LDO\n"
2800 "pmic buck num on/off - Turn on/off the BUCK\n"
2801 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2805 #ifdef CONFIG_CMD_DEVICE_POWER
2806 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2810 if (strncmp(argv[1], "cp", 2) == 0) {
2811 micro_usb_switch(1);
2812 pmic_ldo_control(0, 0, 2, 1);
2813 setenv("usb", "cp");
2814 } else if (strncmp(argv[1], "ap", 2) == 0) {
2815 micro_usb_switch(0);
2816 pmic_ldo_control(0, 0, 2, 0);
2817 setenv("usb", "ap");
2827 printf("USB Path is set to %s\n", getenv("usb"));
2833 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2835 "cp - switch to CP\n"
2836 "microusb ap - switch to AP\n"