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_bamboo(void)
244 return mach_is_aquila() && (board_rev & BAMBOO_BOARD);
247 static int board_is_media(void)
249 return mach_is_aquila() && (board_rev & MEDIA_BOARD);
252 static int board_is_j1b2(void)
254 return mach_is_aquila() && (board_rev & J1_B2_BOARD);
258 static int mach_is_kessler(void)
260 return gd->bd->bi_arch_number == MACH_KESSLER;
263 static int board_is_neptune(void)
265 return mach_is_kessler() && (board_rev & NEPTUNE_BOARD);
268 static int board_is_s1(void)
270 return mach_is_kessler() && (board_rev & S1_BOARD);
274 static int mach_is_wmg160(void)
276 return c110_machine_id() == MACH_WMG160;
279 static void check_battery(int mode);
280 static void check_micro_usb(int intr);
282 void i2c_init_board(void)
284 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
287 if (cpu_is_s5pc100())
290 num_bus = ARRAY_SIZE(i2c_gpio);
292 if (mach_is_aquila()) {
293 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
294 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
295 } else if (mach_is_kessler()) {
296 i2c_gpio[I2C_GPIO7].bus->gpio_base =
297 (unsigned int)&gpio->gpio_mp0_5;
298 } else if (mach_is_cypress()) {
299 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
300 i2c_gpio[I2C_GPIO7].bus->gpio_base =
301 (unsigned int)&gpio->gpio_mp0_5;
303 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
306 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
307 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
308 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
309 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
310 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
312 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
314 /* Reset on fsa9480 early */
316 /* Reset on max17040 early */
317 if (battery_soc == 0)
321 #ifdef CONFIG_MISC_INIT_R
322 #define DEV_INFO_LEN 256
323 static char device_info[DEV_INFO_LEN];
324 static int display_info;
326 static void empty_device_info_buffer(void)
328 memset(device_info, 0x0, DEV_INFO_LEN);
331 static void dprintf(const char *fmt, ...)
338 i = vsprintf(buf, fmt, args);
343 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
344 puts("Flushing device info...\n");
346 empty_device_info_buffer();
348 strncat(device_info, buf, 127);
352 #ifdef CONFIG_S5PC1XXFB
353 static void display_device_info(void)
360 set_font_color(FONT_WHITE);
361 fb_printf(device_info);
364 memset(device_info, 0x0, DEV_INFO_LEN);
366 udelay(5 * 1000 * 1000);
370 static const char *board_name[] = {
374 "P1P2", /* Don't remove it */
387 static char feature_buffer[32];
389 static char *display_features(int board, int board_rev)
392 char *buf = feature_buffer;
395 if (board == MACH_TYPE_AQUILA) {
396 if (board_rev & SPLIT_SCREEN_FEATURE)
397 name = "SplitScreen";
398 if (board_rev & J1_B2_BOARD)
400 /* Limo Real or Universal */
401 if (board_rev & LIMO_REAL_BOARD)
403 else if (board_rev & LIMO_UNIVERSAL_BOARD)
404 name = "Limo Universal";
405 if (board_rev & MEDIA_BOARD)
407 if (board_rev & BAMBOO_BOARD)
409 } else if (board == MACH_KESSLER) {
410 if (board_rev & NEPTUNE_BOARD)
412 if (board_rev & S1_BOARD)
416 count += sprintf(buf + count, " - %s", name);
421 static char *get_board_name(int board)
423 if (board == MACH_TYPE_AQUILA)
425 else if (board == MACH_KESSLER)
427 else if (board == MACH_WMG160)
429 return (char *) board_name[board];
432 static void check_board_revision(int board, int rev)
434 if (board == MACH_TYPE_AQUILA) {
435 /* Limo Real or Universal */
436 if (rev & LIMO_UNIVERSAL_BOARD)
437 board_rev &= ~J1_B2_BOARD;
438 if (rev & LIMO_REAL_BOARD)
439 board_rev &= ~(J1_B2_BOARD |
440 LIMO_UNIVERSAL_BOARD);
441 if (rev & MEDIA_BOARD)
442 board_rev &= ~(J1_B2_BOARD |
443 LIMO_UNIVERSAL_BOARD);
444 if (rev & BAMBOO_BOARD)
445 board_rev &= ~(J1_B2_BOARD |
446 LIMO_UNIVERSAL_BOARD |
449 } else if (board == MACH_KESSLER) {
450 if (rev & KESSLER_BOARD)
451 board_rev &= ~(J1_B2_BOARD |
452 LIMO_UNIVERSAL_BOARD);
453 if (rev & NEPTUNE_BOARD)
454 board_rev &= ~(J1_B2_BOARD |
455 LIMO_UNIVERSAL_BOARD);
457 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
460 board_rev &= ~BOARD_MASK;
464 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
468 gpio_direction_input(bank, 2);
469 gpio_direction_input(bank, 3);
470 gpio_direction_input(bank, 4);
471 gpio_direction_input(bank, hwrev3);
473 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
474 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
475 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
476 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
478 rev = gpio_get_value(bank, 2);
479 rev |= (gpio_get_value(bank, 3) << 1);
480 rev |= (gpio_get_value(bank, 4) << 2);
481 rev |= (gpio_get_value(bank, hwrev3) << 3);
486 static void check_hw_revision(void)
488 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
490 if (cpu_is_s5pc100()) {
491 struct s5pc100_gpio *gpio =
492 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
494 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
496 /* C100 TickerTape */
498 board = MACH_TICKERTAPE;
500 struct s5pc110_gpio *gpio =
501 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
507 * Note Check 'Aquila' board first
511 * LRA: Limo Real Aquila
512 * LUA: Limo Universal Aquila
517 * ADDR = 0xE0200000 + OFF
519 * OFF Universal BB LRA LUA OA TT SS CYP
520 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
521 * J2: 0x0284 0x01 0x10 0x00
522 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
523 * H3: 0x0C64 0x03 0x07 0x0F
524 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
525 * I: 0x0224 0x02 0x00 0x08
526 * MP03: 0x0324 0x9x 0xbx 0x9x
527 * MP05: 0x0364 0x80 0x88
531 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
532 board = MACH_TYPE_AQUILA;
533 board_rev |= J1_B2_BOARD;
535 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
536 gpio_direction_input(&gpio->gpio_j2, 6);
539 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
540 board_rev |= LIMO_UNIVERSAL_BOARD;
542 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
543 board_rev |= LIMO_REAL_BOARD;
545 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
546 board_rev |= MEDIA_BOARD;
548 /* set gpio to default value. */
549 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
550 gpio_direction_output(&gpio->gpio_j2, 6, 0);
553 /* Workaround: C110 Aquila Rev0.6 */
554 if (board_rev == 6) {
555 board = MACH_TYPE_AQUILA;
556 board_rev |= LIMO_REAL_BOARD;
559 /* C110 Aquila Bamboo */
560 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
561 board = MACH_TYPE_AQUILA;
562 board_rev |= BAMBOO_BOARD;
565 /* C110 TickerTape */
566 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
567 gpio_get_value(&gpio->gpio_d1, 1) == 0)
568 board = MACH_TICKERTAPE;
570 /* WMG160 - GPH3[0:4] = 0x00 */
571 if (board == MACH_TICKERTAPE) {
574 for (i = 0; i < 4; i++) {
575 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
586 /* C110 Geminus for rev0.0 */
587 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
588 gpio_direction_input(&gpio->gpio_j1, 2);
589 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
590 board = MACH_GEMINUS;
591 if ((board_rev & ~BOARD_MASK) == 3)
594 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
595 gpio_direction_output(&gpio->gpio_j1, 2, 0);
597 /* C110 Geminus for rev0.1 ~ */
598 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
599 gpio_direction_input(&gpio->gpio_j0, 6);
600 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
601 board = MACH_GEMINUS;
604 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
606 /* Kessler MP0_5[6] == 1 */
607 gpio_direction_input(&gpio->gpio_mp0_5, 6);
608 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
609 /* Cypress: Do this for cypress */
610 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
611 gpio_direction_input(&gpio->gpio_j2, 2);
612 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
613 board = MACH_CYPRESS;
614 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
616 board = MACH_KESSLER;
617 board_rev |= KESSLER_BOARD;
619 /* Neptune MP0_5[4] == 1 */
620 gpio_direction_input(&gpio->gpio_mp0_5, 4);
621 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
622 board_rev &= ~KESSLER_BOARD;
623 board_rev |= NEPTUNE_BOARD;
626 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
629 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
630 /* Kessler S1 board detection */
631 if (board == MACH_TICKERTAPE) {
632 board = MACH_KESSLER;
633 board_rev |= S1_BOARD;
638 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
642 if (board < MACH_PSEUDO_END) {
643 if (cpu_is_s5pc110())
644 gd->bd->bi_arch_number = C110_MACH_START + board;
646 gd->bd->bi_arch_number = C100_MACH_START + board;
648 gd->bd->bi_arch_number = board;
651 /* Architecture Common settings */
652 if (cpu_is_s5pc110()) {
653 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
655 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
657 setenv("updatek", "onenand erase 0x60000 0x300000; "
658 "onenand write 0x31008000 0x60000 0x300000");
662 static void show_hw_revision(void)
667 * Workaround for Rev 0.3 + CP Ver ES 3.1
670 if (board_is_limo_real()) {
672 /* default is Rev 0.4 */
678 if (mach_is_kessler() || mach_is_aquila())
679 board = gd->bd->bi_arch_number;
680 else if (cpu_is_s5pc110())
681 board = gd->bd->bi_arch_number - C110_MACH_START;
683 board = gd->bd->bi_arch_number - C100_MACH_START;
685 check_board_revision(board, board_rev);
687 /* Set CPU Revision */
688 if (mach_is_aquila()) {
689 if (board_is_limo_real()) {
690 if ((board_rev & 0xf) < 8)
691 s5pc1xx_set_cpu_rev(0);
693 else if (board_is_bamboo())
694 s5pc1xx_set_cpu_rev(0);
695 } else if (mach_is_kessler()) {
696 if (board_is_neptune() && hwrevision(2))
697 s5pc1xx_set_cpu_rev(2); /* EVT1-Fused */
699 s5pc1xx_set_cpu_rev(1);
700 } else if (mach_is_geminus()) {
701 if ((board_rev & 0xf) < 1)
702 s5pc1xx_set_cpu_rev(0);
703 } else if (mach_is_cypress()) {
704 s5pc1xx_set_cpu_rev(1);
706 s5pc1xx_set_cpu_rev(0);
709 if (cpu_is_s5pc110())
710 writel(0xc1100000 | (0xffff & (s5pc1xx_get_cpu_rev() ? 1 : 0)),
713 empty_device_info_buffer();
714 dprintf("HW Revision:\t%x (%s%s) %s\n",
715 board_rev, get_board_name(board),
716 display_features(board, board_rev),
717 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
720 static void check_auto_burn(void)
722 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
723 unsigned int count = 0;
726 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
727 puts("Auto burning bootloader\n");
728 count += sprintf(buf + count, "run updateb; ");
730 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
731 puts("Auto burning kernel\n");
732 count += sprintf(buf + count, "run updatek; ");
736 count += sprintf(buf + count, "reset");
737 setenv("bootcmd", buf);
740 /* Clear the magic value */
741 writel(0xa5a55a5a, magic_base);
742 writel(0xa5a55a5a, magic_base + 0x4);
745 static void pmic_pin_init(void)
747 unsigned int reg, value;
749 if (cpu_is_s5pc100())
752 /* AP_PS_HOLD: XEINT_0: GPH0[0]
753 * Note: Don't use GPIO PS_HOLD it doesn't work
755 reg = S5PC110_PS_HOLD_CONTROL;
757 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
758 S5PC110_PS_HOLD_DATA_HIGH |
759 S5PC110_PS_HOLD_OUT_EN;
762 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
763 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
764 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
767 static void enable_ldos(void)
769 if (cpu_is_s5pc100())
772 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
773 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
776 static void enable_t_flash(void)
778 if (!(board_is_limo_universal() || board_is_limo_real()))
781 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
782 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
785 static void setup_limo_real_gpios(void)
787 if (!board_is_limo_real())
791 * Note: Please write GPIO alphabet order
793 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
794 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
797 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
798 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
800 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
801 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
803 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
804 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
805 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
808 static void setup_media_gpios(void)
810 if (!board_is_media())
814 * Note: Please write GPIO alphabet order
816 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
817 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
819 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
820 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
821 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
824 #define KBR3 (1 << 3)
825 #define KBR2 (1 << 2)
826 #define KBR1 (1 << 1)
827 #define KBR0 (1 << 0)
829 static void check_keypad(void)
831 unsigned int reg, value;
832 unsigned int col_num, row_num;
833 unsigned int col_mask;
834 unsigned int col_mask_shift;
835 unsigned int row_state[4];
837 unsigned int auto_download = 0;
839 if (mach_is_wmg160())
842 if (cpu_is_s5pc100()) {
843 struct s5pc100_gpio *gpio =
844 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
849 /* Set GPH2[2:0] to KP_COL[2:0] */
850 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
851 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
852 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
854 /* Set GPH3[2:0] to KP_ROW[2:0] */
855 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
856 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
857 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
859 reg = S5PC100_KEYPAD_BASE;
860 col_mask = S5PC1XX_KEYIFCOL_MASK;
863 if (board_is_limo_real() || board_is_limo_universal()) {
871 for (i = 0; i < row_num; i++) {
872 /* Set GPH3[3:0] to KP_ROW[3:0] */
873 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
874 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
877 for (i = 0; i < col_num; i++)
878 /* Set GPH2[3:0] to KP_COL[3:0] */
879 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
881 reg = S5PC110_KEYPAD_BASE;
882 col_mask = S5PC110_KEYIFCOLEN_MASK;
886 /* KEYIFCOL reg clear */
887 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
890 for (i = 0; i < col_num; i++) {
892 value &= ~(1 << i) << col_mask_shift;
894 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
897 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
898 row_state[i] = ~value & ((1 << row_num) - 1);
900 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
903 /* KEYIFCOL reg clear */
904 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
906 if (mach_is_aquila() || mach_is_kessler()) {
908 if (row_state[1] & 0x2)
910 if (board_is_neptune() && hwrevision(0)) {
911 /* home & volume down */
912 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
914 } else if (board_is_neptune() && hwrevision(2)) {
915 /* cam full shot & volume down */
916 if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
919 /* cam full shot & volume down */
920 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
923 } else if (mach_is_geminus())
924 /* volume down & home */
925 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
929 setenv("bootcmd", "usbdown");
932 static void check_battery(int mode)
934 unsigned char val[2];
935 unsigned char addr = 0x36; /* max17040 fuel gauge */
937 i2c_set_bus_num(I2C_GPIO3);
939 if (mach_is_aquila()) {
942 } else if (mach_is_kessler()) {
943 i2c_set_bus_num(I2C_GPIO7);
944 } else if (mach_is_cypress()) {
945 i2c_set_bus_num(I2C_GPIO7);
946 } else if (mach_is_geminus()) {
948 i2c_set_bus_num(I2C_GPIO7);
952 if (i2c_probe(addr)) {
953 puts("Can't found max17040 fuel gauge\n");
957 /* mode 0: check mode / 1: enable mode */
961 i2c_write(addr, 0xfe, 1, val, 2);
963 i2c_read(addr, 0x04, 1, val, 1);
964 dprintf("battery:\t%d%%\n", val[0]);
965 battery_soc = val[0];
969 static void check_mhl(void)
971 unsigned char val[2];
972 unsigned char addr = 0x39; /* SIL9230 */
974 /* MHL Power enable */
975 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
976 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
978 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
979 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
981 /* 10ms required after reset */
985 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
987 i2c_set_bus_num(I2C_GPIO5);
990 if (i2c_probe(addr)) {
991 puts("Can't found MHL Chip\n");
997 * set to Normal operation
1000 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
1001 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
1006 * 00 = MHL termination ON
1007 * 11 = MHL termination OFF
1010 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1011 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1014 static int max8998_probe(void)
1016 unsigned char addr = 0xCC >> 1;
1018 i2c_set_bus_num(I2C_PMIC);
1020 if (i2c_probe(addr)) {
1021 puts("Can't found max8998\n");
1028 #define CHARGER_ANIMATION_FRAME 6
1029 static void max8998_clear_interrupt(void)
1031 unsigned char addr, val[2];
1034 if (max8998_probe())
1037 i2c_read(addr, 0x00, 1, val, 1);
1038 i2c_read(addr, 0x01, 1, val, 1);
1039 i2c_read(addr, 0x02, 1, val, 1);
1040 i2c_read(addr, 0x03, 1, val, 1);
1043 static int max8998_power_key(void)
1045 unsigned char addr, val[2];
1048 if (max8998_probe())
1051 /* Accessing IRQ1 register */
1052 i2c_read(addr, 0x00, 1, val, 1);
1053 if (val[0] & (1 << 6))
1059 static int max8998_has_ext_power_source(void)
1061 unsigned char addr, val[2];
1064 if (max8998_probe())
1067 /* Accessing STATUS2 register */
1068 i2c_read(addr, 0x09, 1, val, 1);
1069 if (val[0] & (1 << 5))
1075 struct thermister_stat {
1080 static struct thermister_stat adc_to_temperature_data[] = {
1081 { .centigrade = -20, .adc = 1856, },
1082 { .centigrade = -15, .adc = 1799, },
1083 { .centigrade = -10, .adc = 1730, },
1084 { .centigrade = -5, .adc = 1649, },
1085 { .centigrade = 0, .adc = 1556, },
1086 { .centigrade = 5, .adc = 1454, },
1087 { .centigrade = 10, .adc = 1343, },
1088 { .centigrade = 15, .adc = 1227, },
1089 { .centigrade = 20, .adc = 1109, },
1090 { .centigrade = 25, .adc = 992, },
1091 { .centigrade = 30, .adc = 880, },
1092 { .centigrade = 35, .adc = 773, },
1093 { .centigrade = 40, .adc = 675, },
1094 { .centigrade = 45, .adc = 586, },
1095 { .centigrade = 50, .adc = 507, },
1096 { .centigrade = 55, .adc = 436, },
1097 { .centigrade = 58, .adc = 399, },
1098 { .centigrade = 63, .adc = 343, },
1099 { .centigrade = 65, .adc = 322, },
1103 #define USHRT_MAX 0xFFFFU
1105 static int adc_to_temperature_centigrade(unsigned short adc)
1109 /* low_*: Greatest Lower Bound,
1110 * * * * high_*: Smallest Upper Bound */
1111 int low_temp = 0, high_temp = 0;
1112 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1113 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1114 if (adc_to_temperature_data[i].adc <= adc &&
1115 adc_to_temperature_data[i].adc >= low_adc) {
1116 low_temp = adc_to_temperature_data[i].centigrade;
1117 low_adc = adc_to_temperature_data[i].adc;
1119 if (adc_to_temperature_data[i].adc >= adc &&
1120 adc_to_temperature_data[i].adc <= high_adc) {
1121 high_temp = adc_to_temperature_data[i].centigrade;
1122 high_adc = adc_to_temperature_data[i].adc;
1126 /* Linear approximation between cloest low and high,
1127 * which is the weighted average of the two. */
1129 /* The following equation is correct only when the two are different */
1130 if (low_adc == high_adc)
1132 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1133 return 20; /* The room temperature */
1136 if (high_adc == USHRT_MAX)
1139 approximation = low_temp * (adc - low_adc) +
1140 high_temp * (high_adc - adc);
1141 approximation /= high_adc - low_adc;
1143 return approximation;
1146 static unsigned short get_adc_value(int channel)
1148 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1149 unsigned short ret = 0;
1153 unsigned int loop = 0;
1155 if (mach_is_kessler())
1157 else if (mach_is_geminus())
1159 else if (mach_is_wmg160())
1161 else if (mach_is_cypress())
1163 else if (mach_is_tickertape())
1165 else if (mach_is_aquila())
1168 else if (mach_is_p1p2())
1172 sprintf(buf, "pmic ldo %d on", ldonum);
1173 run_command(buf, 0);
1175 writel(channel & 0xF, &adc->adcmux);
1176 writel((1 << 14) | (49 << 6), &adc->adccon);
1177 writel(1000 & 0xffff, &adc->adcdly);
1178 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1180 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1185 reg = readl(&adc->adccon);
1186 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1188 ret = readl(&adc->adcdat0) & 0xFFF;
1189 sprintf(buf, "pmic ldo %d off", ldonum);
1190 run_command(buf, 0);
1195 static int adc_get_average_ambient_temperature(void)
1197 if (mach_is_kessler()) {
1198 unsigned short min = USHRT_MAX;
1199 unsigned short max = 0;
1200 unsigned int sum = 0;
1201 unsigned int measured = 0;
1204 for (i = 0; i < 7; i++) {
1205 unsigned short measurement = get_adc_value(6);
1208 if (min > measurement)
1210 if (max < measurement)
1213 if (measured >= 3) {
1219 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1220 adc_to_temperature_centigrade(sum), sum);
1221 return adc_to_temperature_centigrade(sum);
1224 return 20; /* 20 Centigrade */
1227 enum temperature_level {
1235 static enum temperature_level temperature_check(void)
1237 int temp = adc_get_average_ambient_temperature();
1239 return _TEMP_TOO_LOW;
1241 return _TEMP_OK_LOW;
1243 return _TEMP_TOO_HIGH;
1245 return _TEMP_OK_HIGH;
1249 extern void lcd_display_clear(void);
1250 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1252 static void charger_en(int enable)
1258 unsigned char addr = 0xCC >> 1; /* max8998 */
1259 unsigned char val[2];
1261 if (max8998_probe())
1265 puts("Disable the charger.\n");
1266 i2c_read(addr, 0x0D, 1, val, 1);
1269 i2c_write(addr, 0x0D, 1, val, 1);
1271 i2c_read(addr, 0x0C, 1, val, 1);
1272 val[0] &= ~(0x7 << 0);
1273 val[0] &= ~(0x7 << 5);
1274 if (enable == 600) {
1275 val[0] |= 5; /* 600mA */
1276 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1277 } else { /* Assume 475 mA */
1279 val[0] |= 2; /* 475mA */
1280 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1282 i2c_write(addr, 0x0C, 1, val, 1);
1284 i2c_read(addr, 0x0D, 1, val, 1);
1286 i2c_write(addr, 0x0D, 1, val, 1);
1287 printf("Enable the charger @ %dmA\n", enable);
1291 void lcd_power_on(unsigned int onoff);
1292 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1293 extern int drv_lcd_init_resume (void);
1295 static void into_charge_mode(void)
1301 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1302 unsigned int reg, wakeup_stat;
1303 int charger_speed = 600;
1305 max8998_clear_interrupt();
1307 puts("Charge Mode\n");
1308 charger_en(charger_speed);
1310 #ifdef CONFIG_S5PC1XXFB
1313 /* TODO: write the image-text for the charger */
1315 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1316 if (level >= CHARGER_ANIMATION_FRAME)
1317 level = CHARGER_ANIMATION_FRAME - 1;
1319 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1320 bmp_addr[i] = (ulong)battery_charging_animation[i];
1322 lcd_display_clear();
1323 for (i = 0; i < 3; i++) {
1324 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1327 bmp = gunzip_bmp(bmp_addr[j], &len);
1328 lcd_display_bitmap((ulong)bmp, 140, 202);
1331 for (k = 0; k < 10; k++) {
1332 if (max8998_power_key()) {
1333 lcd_display_clear();
1334 goto restore_screen;
1335 } else if (!max8998_has_ext_power_source()) {
1336 lcd_display_clear();
1337 goto restore_screen;
1346 /* Disable the display to prevent flickering */
1347 /* TODO: how to reenable the display later? */
1352 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1353 unsigned int org, org_ip3;
1354 enum temperature_level previous_state = _TEMP_OK;
1356 empty_device_info_buffer();
1357 if (max8998_power_key())
1359 else if (!max8998_has_ext_power_source())
1362 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1363 org_ip3 = readl(0xE010046C);
1364 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1366 reg = org = readl(&rtc->rtccon);
1368 writel(reg, &rtc->rtccon);
1370 reg = readl(&rtc->rtccon);
1371 writel(reg | (1 << 3), &rtc->rtccon);
1373 writel(reg & ~(1 << 3), &rtc->rtccon);
1376 reg = readl(&rtc->rtccon);
1377 reg &= ~((1 << 8) | (0xF << 4));
1378 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1379 writel(reg, &rtc->rtccon);
1381 reg = 15 * 4 - 1; /* 15 sec */
1382 writel(reg, &rtc->ticcnt);
1384 /* EVT0: sleep 1, EVT1: sleep */
1385 if (cpu_is_s5pc110()) {
1386 char *name = "dummy";
1387 char *usage = "N/A";
1394 if (s5pc1xx_get_cpu_rev() == 0) {
1395 char *argv[] = {"1", "1"};
1396 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1398 char *argv[] = {"0", "0"};
1399 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1402 puts("\n\n\nERROR: this is not S5PC110.\n\n\n");
1406 /* Check TEMP HIGH/LOW */
1407 switch (temperature_check()) {
1409 charger_en(charger_speed);
1410 previous_state = _TEMP_OK;
1414 previous_state = _TEMP_TOO_LOW;
1416 case _TEMP_TOO_HIGH:
1418 previous_state = _TEMP_TOO_HIGH;
1421 if (previous_state == _TEMP_TOO_LOW) {
1424 charger_en(charger_speed);
1425 previous_state = _TEMP_OK;
1429 if (previous_state == _TEMP_TOO_HIGH) {
1432 charger_en(charger_speed);
1433 previous_state = _TEMP_OK;
1438 writel(org, &rtc->rtccon);
1439 writel(org_ip3, 0xE010046C);
1441 } while (wakeup_stat == 0x04); /* RTC TICK */
1443 #ifdef CONFIG_S5PC1XXFB
1445 /* TODO: Reenable logo display (not working yet) */
1447 drv_lcd_init_resume();
1451 #define S5PC110_RST_STAT 0xE010A000
1453 #define SWRESET (1 << 3)
1454 #define WDTRESET (1 << 2)
1455 #define WARMRESET (1 << 1)
1456 #define EXTRESET (1 << 0)
1458 static int get_reset_status(void)
1460 return readl(S5PC110_RST_STAT) & 0xf;
1463 static int fsa9480_probe(void)
1465 unsigned char addr = 0x25;
1467 if (cpu_is_s5pc100())
1470 if (board_is_limo_real()) {
1471 if (hwrevision(0) || hwrevision(1))
1475 i2c_set_bus_num(I2C_PMIC);
1477 if (mach_is_kessler()) {
1478 i2c_set_bus_num(I2C_GPIO6);
1479 } else if (mach_is_cypress()) {
1480 i2c_set_bus_num(I2C_GPIO6);
1481 } else if (mach_is_geminus()) {
1483 i2c_set_bus_num(I2C_GPIO6);
1484 } else if (mach_is_wmg160()) {
1485 i2c_set_bus_num(I2C_GPIO6);
1488 if (i2c_probe(addr)) {
1489 puts("Can't found fsa9480\n");
1496 static void check_micro_usb(int intr)
1499 unsigned char val[2];
1500 static int started_charging_once = 0;
1503 if (fsa9480_probe())
1506 addr = 0x25; /* fsa9480 */
1508 /* Clear Interrupt */
1510 i2c_read(addr, 0x03, 1, val, 2);
1514 /* Read Device Type 1 */
1515 i2c_read(addr, 0x0a, 1, val, 1);
1517 #define FSA_DEV1_CHARGER (1 << 6)
1518 #define FSA_DEV1_UART (1 << 3)
1519 #define FSA_DEV1_USB (1 << 2)
1520 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1521 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1524 * If USB, use default 475mA
1525 * If Charger, use 600mA and go to charge mode
1527 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1528 started_charging_once = 1;
1530 /* If it's full, do not charge. */
1531 if (battery_soc < 100)
1535 } else if (val[0] & FSA_DEV1_USB) {
1536 if (battery_soc < 100)
1537 charger_en(475); /* enable charger and keep booting */
1542 /* If reset status is watchdog reset then skip it */
1543 if (!(get_reset_status() & WDTRESET)) {
1544 /* If Factory Mode is Boot ON-USB, go to download mode */
1545 i2c_read(addr, 0x07, 1, val, 1);
1547 #define FSA_ADC_FAC_USB_OFF 0x18
1548 #define FSA_ADC_FAC_USB_ON 0x19
1549 #define FSA_ADC_FAC_UART 0x1d
1551 if (val[0] == FSA_ADC_FAC_USB_ON ||
1552 val[0] == FSA_ADC_FAC_USB_OFF)
1553 setenv("bootcmd", "usbdown");
1556 path = getenv("usb");
1558 if (!strncmp(path, "cp", 2))
1559 run_command("microusb cp", 0);
1562 static void micro_usb_switch(int path)
1565 unsigned char val[2];
1567 if (fsa9480_probe())
1570 addr = 0x25; /* fsa9480 */
1573 val[0] = 0x90; /* VAUDIO */
1575 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1577 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1579 i2c_read(addr, 0x2, 1, val, 1);
1580 val[0] &= ~(1 << 2); /* Manual switching */
1581 i2c_write(addr, 0x2, 1, val, 1);
1584 #define MAX8998_REG_ONOFF1 0x11
1585 #define MAX8998_REG_ONOFF2 0x12
1586 #define MAX8998_REG_ONOFF3 0x13
1587 #define MAX8998_REG_LDO7 0x21
1588 #define MAX8998_REG_LDO17 0x29
1590 #define MAX8998_LDO3 (1 << 2)
1592 #define MAX8998_LDO6 (1 << 7)
1593 #define MAX8998_LDO7 (1 << 6)
1594 #define MAX8998_LDO8 (1 << 5)
1595 #define MAX8998_LDO9 (1 << 4)
1596 #define MAX8998_LDO10 (1 << 3)
1597 #define MAX8998_LDO11 (1 << 2)
1598 #define MAX8998_LDO12 (1 << 1)
1599 #define MAX8998_LDO13 (1 << 0)
1601 #define MAX8998_LDO14 (1 << 7)
1602 #define MAX8998_LDO15 (1 << 6)
1603 #define MAX8998_LDO16 (1 << 5)
1604 #define MAX8998_LDO17 (1 << 4)
1607 static void init_pmic(void)
1610 unsigned char val[2];
1612 if (cpu_is_s5pc100())
1615 addr = 0xCC >> 1; /* max8998 */
1616 if (max8998_probe())
1620 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1621 val[0] &= ~MAX8998_LDO3;
1622 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1625 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1627 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1628 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1630 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1631 MAX8998_LDO12 | MAX8998_LDO13);
1633 if (mach_is_kessler())
1634 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1636 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1637 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1639 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1641 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1642 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1644 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1645 MAX8998_LDO16 | MAX8998_LDO17);
1647 if (mach_is_kessler())
1648 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1650 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1651 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1654 static void setup_power_down_mode_registers(void)
1656 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1657 struct s5pc1xx_gpio_bank *bank;
1658 struct gpio_powermode *p;
1660 struct gpio_external *ge;
1662 struct s5pc1xx_gpio_item *mr;
1666 if (cpu_is_s5pc100())
1669 /* Only Limo real and kessler supports worked for sleep currnet */
1670 if (mach_is_aquila()) {
1671 if (board_is_limo_real())
1675 } else if (mach_is_kessler()) {
1677 } else if (mach_is_geminus()) {
1683 if (mach_is_aquila()) {
1684 /* Aquila rev 0.8 or lower */
1685 p = aquila_powerdown_modes;
1686 ge = aquila_external_powerdown_modes;
1687 mr = aquila_mirror_powerdown_mode;
1688 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1689 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1690 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1691 } else if (mach_is_kessler()) {
1692 /* Aquila rev 0.9 */
1693 p = kessler_powerdown_modes;
1694 ge = kessler_external_powerdown_modes;
1695 mr = kessler_mirror_powerdown_mode;
1696 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1697 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1698 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1699 } else if (mach_is_geminus()) {
1700 if (hwrevision(1)) {
1701 /* Same as Aquila rev 0.9 */
1703 p = kessler_powerdown_modes;
1704 ge = kessler_external_powerdown_modes;
1705 mr = kessler_mirror_powerdown_mode;
1706 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1707 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1708 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1710 p = aquila_powerdown_modes;
1711 ge = aquila_external_powerdown_modes;
1712 mr = aquila_mirror_powerdown_mode;
1713 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1714 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1715 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1717 } else if (hwrevision(0)) {
1718 /* Same as Aquila rev 0.8 or lower */
1719 p = aquila_powerdown_modes;
1720 ge = aquila_external_powerdown_modes;
1721 mr = aquila_mirror_powerdown_mode;
1722 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1723 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1724 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1726 return; /* Not supported */
1730 bank = &gpio->gpio_a0;
1732 for (i = 0; i < n_p; i++, p++, bank++) {
1733 writel(p->conpdn, &bank->pdn_con);
1734 writel(p->pudpdn, &bank->pdn_pull);
1737 writel(0xff0022b0, (unsigned int *)0xF0000000);
1738 writel(0xff0022b0, (unsigned int *)0xF1400000);
1740 bank = &gpio->gpio_h0;
1742 for (i = 0; i < n_ge; i++) {
1743 writel(ge->con, &bank->con);
1744 writel(ge->dat, &bank->dat);
1745 writel(ge->pud, &bank->pull);
1751 for (i = 0; i < n_mr; i++) {
1752 unsigned int reg = readl(&mr->bank->pdn_con);
1753 reg &= ~(0x3 << (mr->number << 1));
1754 if (readl(&mr->bank->dat) & (1 << mr->number))
1755 reg |= 0x1 << (mr->number << 1);
1756 writel(reg, &mr->bank->pdn_con);
1762 #include "../../../drivers/video/s5p-spi.h"
1764 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1765 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1767 struct spi_platform_data spi_pd;
1769 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1771 void lcd_cfg_gpio(void)
1773 unsigned int i, f3_end = 4;
1775 for (i = 0; i < 8; i++) {
1776 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1777 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1778 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1779 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1780 /* pull-up/down disable */
1781 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1782 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1783 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1785 /* drive strength to max (24bit) */
1786 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1787 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1788 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1789 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1790 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1791 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1794 /* set DISPLAY_DE_B pin for dual rgb mode. */
1795 if (board_is_media())
1798 for (i = 0; i < f3_end; i++) {
1799 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1800 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1801 /* pull-up/down disable */
1802 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1803 /* drive strength to max (24bit) */
1804 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1805 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1807 /* display output path selection (only [1:0] valid) */
1808 writel(0x2, 0xE0107008);
1810 /* gpio pad configuration for LCD reset. */
1811 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1813 /* gpio pad configuration for LCD ON. */
1814 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1816 /* LCD_BACKLIGHT_EN */
1817 if (mach_is_geminus())
1818 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1819 if (board_is_neptune() && hwrevision(0)) {
1820 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1821 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1825 * gpio pad configuration for
1826 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1828 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1829 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1830 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1831 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1833 if (mach_is_aquila() || mach_is_kessler()) {
1834 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1836 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1838 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1840 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1843 if (board_is_neptune() && hwrevision(0))
1844 s6d16a0x_set_platform_data(&spi_pd);
1846 s6e63m0_set_platform_data(&spi_pd);
1847 if (board_is_media())
1852 if (mach_is_cypress()) {
1853 #if 0 /* universal cypress */
1855 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1858 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1860 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1862 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1864 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1866 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1867 #if 0 /* universal cypress */
1868 pd_cs.bank = &gpio_base->gpio_mp0_1;
1871 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1873 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1875 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1880 /* these data would be sent to s6e63m0 lcd panel driver. */
1881 s6e63m0_set_platform_data(&spi_pd);
1887 #define SWRST_REG 0x00
1888 #define LEDCON_REG 0x01
1889 #define LED_CUR_SET_REG 0x03
1890 #define LED_CUR_TR_REG 0x08
1893 #define NORMAL_MODE 0x09
1894 #define CUR_SET 0x63
1896 void backlight_on(unsigned int onoff)
1900 unsigned char val[2];
1901 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1904 if (mach_is_geminus())
1905 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1907 if (mach_is_geminus())
1908 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1911 if (mach_is_kessler() && board_is_neptune() && hwrevision(0)) {
1912 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1915 i2c_set_bus_num(I2C_GPIO5);
1918 if (i2c_probe(addr)) {
1919 if (i2c_probe(addr)) {
1920 puts("Can't found s6d16a0x backlight i2c\n");
1925 i2c_write(addr, SWRST_REG, 1, val, 1);
1928 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1930 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1931 val[0] = NORMAL_MODE;
1932 i2c_write(addr, LEDCON_REG, 1, val, 1);
1937 void reset_lcd(void)
1939 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1941 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1942 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1943 if (mach_is_cypress())
1944 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1947 void lcd_power_on(unsigned int onoff)
1949 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1952 if (mach_is_aquila() || mach_is_geminus())
1953 gpio_set_value(&gpio->gpio_j1, 3, 1);
1955 if (mach_is_cypress())
1956 gpio_set_value(&gpio->gpio_g2, 2, 1);
1958 if (mach_is_kessler()) {
1960 unsigned char val[2];
1961 unsigned char val2[2];
1963 gpio_set_value(&gpio->gpio_j1, 3, 1);
1965 addr = 0xCC >> 1; /* max8998 */
1966 if (max8998_probe())
1969 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1970 val[0] &= ~(MAX8998_LDO17);
1971 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1972 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1974 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1975 val[0] |= MAX8998_LDO17;
1977 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1978 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1980 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1981 val[0] |= MAX8998_LDO7;
1983 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1984 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1987 if (mach_is_aquila() || mach_is_geminus())
1988 gpio_set_value(&gpio->gpio_j1, 3, 0);
1990 if (mach_is_cypress())
1991 gpio_set_value(&gpio->gpio_g2, 2, 0);
1993 if (mach_is_kessler()) {
1995 unsigned char val[2];
1997 gpio_set_value(&gpio->gpio_j1, 3, 0);
1999 addr = 0xCC >> 1; /* max8998 */
2000 if (max8998_probe())
2003 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2004 val[0] &= ~(MAX8998_LDO7);
2005 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2006 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2008 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2009 val[0] &= ~(MAX8998_LDO17);
2010 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2011 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2016 extern void s6e63m0_cfg_ldo(void);
2017 extern void s6e63m0_enable_ldo(unsigned int onoff);
2018 extern void s6d16a0x_cfg_ldo(void);
2019 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2021 int s5p_no_lcd_support(void)
2023 if (mach_is_wmg160())
2028 void init_panel_info(vidinfo_t *vid)
2030 vid->cfg_gpio = NULL;
2031 vid->reset_lcd = NULL;
2032 vid->backlight_on = NULL;
2033 vid->lcd_power_on = NULL;
2035 vid->cfg_ldo = NULL;
2036 vid->enable_ldo = NULL;
2038 vid->init_delay = 0;
2039 vid->reset_delay = 0;
2040 vid->power_on_delay = 0;
2045 vid->vl_width = 480;
2046 vid->vl_height = 800;
2048 vid->dual_lcd_enabled = 0;
2050 if (board_is_media()) {
2053 vid->vl_width = 960;
2054 vid->vl_height = 800;
2056 /* enable dual lcd mode. */
2057 vid->dual_lcd_enabled = 1;
2060 vid->vl_clkp = CONFIG_SYS_HIGH;
2061 vid->vl_hsp = CONFIG_SYS_LOW;
2062 vid->vl_vsp = CONFIG_SYS_LOW;
2063 vid->vl_dp = CONFIG_SYS_HIGH;
2066 /* S6E63M0 LCD Panel */
2075 if (mach_is_aquila() || mach_is_kessler()
2076 || mach_is_cypress()) {
2077 vid->cfg_gpio = lcd_cfg_gpio;
2078 vid->reset_lcd = reset_lcd;
2079 vid->backlight_on = backlight_on;
2080 vid->lcd_power_on = lcd_power_on;
2081 vid->cfg_ldo = s6e63m0_cfg_ldo;
2082 vid->enable_ldo = s6e63m0_enable_ldo;
2084 vid->init_delay = 25000;
2085 vid->reset_delay = 120000;
2088 if (board_is_neptune() && hwrevision(0)) {
2092 vid->vl_width = 320;
2093 vid->vl_height = 480;
2095 vid->vl_clkp = CONFIG_SYS_HIGH;
2096 vid->vl_hsp = CONFIG_SYS_HIGH;
2097 vid->vl_vsp = CONFIG_SYS_HIGH;
2098 vid->vl_dp = CONFIG_SYS_LOW;
2101 /* disable dual lcd mode. */
2102 vid->dual_lcd_enabled = 0;
2104 /* S6D16A0X LCD Panel */
2113 vid->cfg_gpio = lcd_cfg_gpio;
2114 vid->backlight_on = backlight_on;
2115 vid->lcd_power_on = lcd_power_on;
2116 vid->reset_lcd = reset_lcd;
2117 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2118 vid->enable_ldo = s6d16a0x_enable_ldo;
2120 vid->init_delay = 10000;
2121 vid->power_on_delay = 10000;
2122 vid->reset_delay = 1000;
2126 if (mach_is_geminus()) {
2130 vid->vl_width = 1024,
2131 vid->vl_height = 600,
2132 vid->vl_clkp = CONFIG_SYS_LOW,
2133 vid->vl_hsp = CONFIG_SYS_HIGH,
2134 vid->vl_vsp = CONFIG_SYS_HIGH,
2135 vid->vl_dp = CONFIG_SYS_LOW,
2146 vid->cfg_gpio = lcd_cfg_gpio;
2147 vid->reset_lcd = reset_lcd;
2148 vid->backlight_on = backlight_on;
2149 vid->lcd_power_on = lcd_power_on;
2155 vid->vl_width = 480,
2156 vid->vl_height = 800,
2157 vid->vl_clkp = CONFIG_SYS_HIGH,
2158 vid->vl_hsp = CONFIG_SYS_LOW,
2159 vid->vl_vsp = CONFIG_SYS_LOW,
2160 vid->vl_dp = CONFIG_SYS_HIGH,
2176 vid->vl_width = 1024,
2177 vid->vl_height = 600,
2178 vid->vl_clkp = CONFIG_SYS_HIGH,
2179 vid->vl_hsp = CONFIG_SYS_HIGH,
2180 vid->vl_vsp = CONFIG_SYS_HIGH,
2181 vid->vl_dp = CONFIG_SYS_LOW,
2184 /* AMS701KA AMOLED Panel. */
2196 static void setup_meminfo(void)
2198 char meminfo[64] = {0, };
2199 int count = 0, size, real;
2201 size = gd->bd->bi_dram[0].size >> 20;
2202 count += sprintf(meminfo + count, "mem=%dM", size);
2204 /* Each Chip Select can't exceed the 256MiB */
2205 size = gd->bd->bi_dram[1].size >> 20;
2206 real = min(size, 256);
2207 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2208 real, (unsigned int)gd->bd->bi_dram[1].start);
2212 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2213 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2216 setenv("meminfo", meminfo);
2219 int misc_init_r(void)
2222 /* It should be located at first */
2225 if (mach_is_aquila() || mach_is_kessler()) {
2226 if (board_is_neptune() && hwrevision(0))
2227 setenv("lcdinfo", "lcd=s6d16a0x");
2228 else if (board_is_media())
2229 setenv("lcdinfo", "lcd=s6e63m0");
2231 setenv("lcdinfo", "lcd=s6e63m0");
2233 if (mach_is_geminus())
2234 setenv("lcdinfo", "lcd=lms480jc01");
2235 if (mach_is_cypress())
2236 setenv("lcdinfo", "lcd=s6e63m0");
2242 /* Set proper PMIC pins */
2245 /* Check auto burning */
2248 /* To power up I2C2 */
2251 /* Enable T-Flash at Limo Real or Limo Universal */
2254 /* Setup Limo Real board GPIOs */
2255 setup_limo_real_gpios();
2257 /* Setup Media board GPIOs */
2258 setup_media_gpios();
2260 /* To usbdown automatically */
2266 #ifdef CONFIG_S5PC1XXFB
2267 display_device_info();
2270 setup_power_down_mode_registers();
2272 /* check max17040 */
2282 int board_init(void)
2284 /* Set Initial global variables */
2285 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2287 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2288 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2292 * set reserved memory region for framebuffer.
2294 * this region wouldn't be rewrited by kernel so
2295 * could avoid nosie screen filled by garbages
2296 * after hibernation resume has been completed.
2298 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2301 /* Check H/W Revision */
2302 check_hw_revision();
2309 unsigned int base, memconfig0, size;
2310 unsigned int memconfig1, sz = 0;
2312 if (cpu_is_s5pc100()) {
2313 /* In mem setup, we swap the bank. So below size is correct */
2314 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2315 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2316 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2319 /* In S5PC110, we can't swap the DMC0/1 */
2320 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2321 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2323 base = S5PC110_DMC1_BASE;
2324 /* DMC configuration */
2325 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2326 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2328 size = (memconfig0 >> 16) & 0xFF;
2329 size = ((unsigned char) ~size) + 1;
2332 * (0x07 + 1) * 16 = 128 MiB
2333 * (0x0f + 1) * 16 = 256 MiB
2338 * Aquila Rev0.5 4G3G1G
2339 * Aquila Rev0.8 4G3G1G
2340 * Aquila Rev0.9 4G3G1G
2342 if (mach_is_aquila() || mach_is_kessler()) {
2343 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2344 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2346 sz = (memconfig1 >> 16) & 0xFF;
2347 sz = ((unsigned char) ~sz) + 1;
2350 if (mach_is_kessler() && board_is_s1())
2355 * bi_dram[1].size contains all DMC1 memory size
2357 gd->bd->bi_dram[1].size = (size + sz) << 20;
2362 /* Used for sleep test */
2363 static unsigned char saved_val[4][2];
2364 void board_sleep_init_late(void)
2366 /* CODEC_LDO_EN: GPF3[4] */
2367 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2368 /* CODEC_XTAL_EN: GPH3[2] */
2369 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2371 /* MMC T_FLASH off */
2372 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2374 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2375 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2376 /* MHL_ON for REV02 or higher */
2377 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2380 void board_sleep_init(void)
2383 unsigned char val[2];
2386 if (max8998_probe())
2389 if (mach_is_kessler()) {
2391 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2392 saved_val[0][0] = val[0];
2393 saved_val[0][1] = val[1];
2394 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2395 (1 << 1) | (1 << 0));
2396 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2397 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2400 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2401 saved_val[1][0] = val[0];
2402 saved_val[1][1] = val[1];
2403 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2404 (1 << 2) | (1 << 1) | (1 << 0));
2406 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2407 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2410 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2411 saved_val[2][0] = val[0];
2412 saved_val[2][1] = val[1];
2413 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2414 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2415 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2418 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2419 saved_val[3][0] = val[0];
2420 saved_val[3][1] = val[1];
2421 val[0] &= ~((1 << 6) | (1 << 4));
2422 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2423 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2425 printf("Turned off regulators with Kessler setting."
2426 " Preparing to sleep. [%s:%d]\n",
2427 __FILE__, __LINE__);
2428 } else { /* Default */
2430 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2431 saved_val[0][0] = val[0];
2432 saved_val[0][1] = val[1];
2433 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2434 (1 << 1) | (1 << 0));
2435 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2436 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2439 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2440 saved_val[1][0] = val[0];
2441 saved_val[1][1] = val[1];
2442 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2443 (1 << 2) | (1 << 1) | (1 << 0));
2445 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2446 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2449 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2450 saved_val[2][0] = val[0];
2451 saved_val[2][1] = val[1];
2452 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2453 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2454 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2457 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2458 saved_val[3][0] = val[0];
2459 saved_val[3][1] = val[1];
2460 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2461 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2462 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2464 printf("Turned off regulators with default(Aquila) setting."
2465 " Preparing to sleep. [%s:%d]\n",
2466 __FILE__, __LINE__);
2470 void board_sleep_resume(void)
2473 unsigned char val[2];
2478 if (max8998_probe())
2482 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2483 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2485 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2486 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2488 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2489 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2491 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2492 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2493 puts("Waked up.\n");
2495 /* check max17040 */
2502 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2504 static int s5pc1xx_phy_control(int on)
2508 if (on && !status) {
2509 #ifdef CONFIG_CMD_PMIC
2510 run_command("pmic ldo 3 on", 0);
2513 if (board_is_limo_universal() ||
2514 board_is_limo_real() ||
2516 /* check usb path */
2517 if (board_is_limo_real() && !hwrevision(6))
2521 if (mach_is_tickertape())
2522 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2523 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2525 /* USB Path to AP */
2526 micro_usb_switch(0);
2528 } else if (!on && status) {
2529 #ifdef CONFIG_CMD_PMIC
2530 run_command("pmic ldo 3 off", 0);
2539 struct s3c_plat_otg_data s5pc110_otg_data = {
2540 .phy_control = s5pc1xx_phy_control,
2541 .regs_phy = S5PC110_PHY_BASE,
2542 .regs_otg = S5PC110_OTG_BASE,
2545 int board_eth_init(bd_t *bis)
2549 if (cpu_is_s5pc100())
2552 s3c_udc_probe(&s5pc110_otg_data);
2553 if (usb_eth_initialize(bis) >= 0)
2559 #ifdef CONFIG_CMD_USBDOWN
2560 int usb_board_init(void)
2562 #ifdef CONFIG_CMD_PMIC
2563 run_command("pmic ldo 3 on", 0);
2566 if (cpu_is_s5pc100()) {
2567 #ifdef CONFIG_HARD_I2C
2568 uchar val[2] = {0,};
2571 if (i2c_read(0x66, 0, 1, val, 2)) {
2572 puts("i2c_read error\n");
2579 if (i2c_write(0x66, 0, 1, val, 2)) {
2580 puts("i2c_write error\n");
2583 i2c_read(0x66, 0, 1, val, 2);
2589 if (board_is_limo_universal() ||
2590 board_is_limo_real() ||
2592 /* check usb path */
2593 if (board_is_limo_real() && !hwrevision(6))
2597 if (mach_is_tickertape())
2598 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2599 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2601 /* USB Path to AP */
2602 micro_usb_switch(0);
2608 #ifdef CONFIG_GENERIC_MMC
2609 int s5p_no_mmc_support(void)
2611 if (mach_is_wmg160())
2616 int board_mmc_init(bd_t *bis)
2620 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2623 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2624 if (mach_is_kessler())
2625 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2627 if (mach_is_wmg160())
2630 /* MMC0 Clock source = SCLKMPLL */
2631 reg = readl(&clk->src4);
2634 writel(reg, &clk->src4);
2636 reg = readl(&clk->div4);
2639 /* set div value near 50MHz */
2640 clock = get_pll_clk(MPLL) / 1000000;
2641 for (i = 0; i < 0xf; i++) {
2642 if ((clock / (i + 1)) <= 50) {
2648 writel(reg, &clk->div4);
2654 * GPG0[2] SD_0_CDn -> Not used
2655 * GPG0[3:6] SD_0_DATA[0:3]
2657 for (i = 0; i < 7; i++) {
2660 /* GPG0[0:6] special function 2 */
2661 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2662 /* GPG0[0:6] pull disable */
2663 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2664 /* GPG0[0:6] drv 4x */
2665 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2668 if (mach_is_geminus()) {
2669 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2670 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2673 return s5pc1xx_mmc_init(0);
2677 #ifdef CONFIG_CMD_PMIC
2678 static int pmic_status(void)
2680 unsigned char addr, val[2];
2685 if (max8998_probe())
2689 i2c_read(addr, reg, 1, val, 1);
2690 for (i = 7; i >= 4; i--)
2691 printf("BUCK%d %s\n", 7 - i + 1,
2692 val[0] & (1 << i) ? "on" : "off");
2694 printf("LDO%d %s\n", 5 - i,
2695 val[0] & (1 << i) ? "on" : "off");
2697 i2c_read(addr, reg, 1, val, 1);
2698 for (i = 7; i >= 0; i--)
2699 printf("LDO%d %s\n", 7 - i + 6,
2700 val[0] & (1 << i) ? "on" : "off");
2702 i2c_read(addr, reg, 1, val, 1);
2703 for (i = 7; i >= 4; i--)
2704 printf("LDO%d %s\n", 7 - i + 14,
2705 val[0] & (1 << i) ? "on" : "off");
2708 i2c_read(addr, reg, 1, val, 1);
2709 for (i = 7; i >= 6; i--)
2710 printf("SAFEOUT%d %s\n", 7 - i + 1,
2711 val[0] & (1 << i) ? "on" : "off");
2715 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2717 unsigned char addr, val[2];
2718 unsigned int reg, shift;
2726 } else if (ldo <= 13) {
2729 } else if (ldo <= 17) {
2731 shift = 17 - ldo + 4;
2738 shift = 4 - buck + 4;
2739 } else if (safeout) {
2743 shift = 8 - safeout;
2749 if (max8998_probe())
2752 i2c_read(addr, reg, 1, val, 1);
2754 val[0] |= (1 << shift);
2756 val[0] &= ~(1 << shift);
2757 i2c_write(addr, reg, 1, val, 1);
2758 i2c_read(addr, reg, 1, val, 1);
2761 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2762 val[0] & (1 << shift) ? "on" : "off");
2764 printf("buck %d value 0x%x, %s\n", buck, val[0],
2765 val[0] & (1 << shift) ? "on" : "off");
2767 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2768 val[0] & (1 << shift) ? "on" : "off");
2773 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2775 int buck = 0, ldo = 0, safeout = 0, on = -1;
2779 if (strncmp(argv[1], "status", 6) == 0)
2780 return pmic_status();
2783 if (strncmp(argv[1], "ldo", 3) == 0)
2784 ldo = simple_strtoul(argv[2], NULL, 10);
2785 else if (strncmp(argv[1], "buck", 4) == 0)
2786 buck = simple_strtoul(argv[2], NULL, 10);
2787 else if (strncmp(argv[1], "safeout", 7) == 0)
2788 safeout = simple_strtoul(argv[2], NULL, 10);
2792 if (strncmp(argv[3], "on", 2) == 0)
2794 else if (strncmp(argv[3], "off", 3) == 0)
2799 return pmic_ldo_control(buck, ldo, safeout, on);
2810 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2811 "PMIC LDO & BUCK control",
2812 "status - Display PMIC LDO & BUCK status\n"
2813 "pmic ldo num on/off - Turn on/off the LDO\n"
2814 "pmic buck num on/off - Turn on/off the BUCK\n"
2815 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2819 #ifdef CONFIG_CMD_DEVICE_POWER
2820 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2824 if (strncmp(argv[1], "cp", 2) == 0) {
2825 micro_usb_switch(1);
2826 pmic_ldo_control(0, 0, 2, 1);
2827 setenv("usb", "cp");
2828 } else if (strncmp(argv[1], "ap", 2) == 0) {
2829 micro_usb_switch(0);
2830 pmic_ldo_control(0, 0, 2, 0);
2831 setenv("usb", "ap");
2841 printf("USB Path is set to %s\n", getenv("usb"));
2847 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2849 "cp - switch to CP\n"
2850 "microusb ap - switch to AP\n"