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);
1766 extern void ld9040_set_platform_data(struct spi_platform_data *pd);
1768 struct spi_platform_data spi_pd;
1770 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1772 void lcd_cfg_gpio(void)
1774 unsigned int i, f3_end = 4;
1776 for (i = 0; i < 8; i++) {
1777 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1778 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1779 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1780 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1781 /* pull-up/down disable */
1782 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1783 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1784 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1786 /* drive strength to max (24bit) */
1787 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1788 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1789 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1790 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1791 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1792 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1795 /* set DISPLAY_DE_B pin for dual rgb mode. */
1796 if (board_is_media())
1799 for (i = 0; i < f3_end; i++) {
1800 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1801 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1802 /* pull-up/down disable */
1803 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1804 /* drive strength to max (24bit) */
1805 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1806 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1808 /* display output path selection (only [1:0] valid) */
1809 writel(0x2, 0xE0107008);
1811 /* gpio pad configuration for LCD reset. */
1812 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1814 /* gpio pad configuration for LCD ON. */
1815 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1817 /* LCD_BACKLIGHT_EN */
1818 if (mach_is_geminus())
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1820 if (board_is_neptune() && hwrevision(0)) {
1821 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1822 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1826 * gpio pad configuration for
1827 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1829 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1830 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1831 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1832 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1834 if (mach_is_aquila() || mach_is_kessler()) {
1835 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1837 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1839 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1841 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1844 if (board_is_neptune() && hwrevision(0))
1845 s6d16a0x_set_platform_data(&spi_pd);
1846 else if (board_is_neptune() && hwrevision(3))
1847 ld9040_set_platform_data(&spi_pd);
1849 s6e63m0_set_platform_data(&spi_pd);
1850 if (board_is_media())
1855 if (mach_is_cypress()) {
1856 #if 0 /* universal cypress */
1858 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1861 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1863 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1865 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1867 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1869 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1870 #if 0 /* universal cypress */
1871 pd_cs.bank = &gpio_base->gpio_mp0_1;
1874 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1876 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1878 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1883 /* these data would be sent to s6e63m0 lcd panel driver. */
1884 s6e63m0_set_platform_data(&spi_pd);
1890 #define SWRST_REG 0x00
1891 #define LEDCON_REG 0x01
1892 #define LED_CUR_SET_REG 0x03
1893 #define LED_CUR_TR_REG 0x08
1896 #define NORMAL_MODE 0x09
1897 #define CUR_SET 0x63
1899 void backlight_on(unsigned int onoff)
1903 unsigned char val[2];
1904 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1905 printf("%s\n", __func__);
1908 if (mach_is_geminus())
1909 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1911 if (mach_is_geminus())
1912 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1915 if (mach_is_kessler() && board_is_neptune() && hwrevision(0)) {
1916 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1919 i2c_set_bus_num(I2C_GPIO5);
1922 if (i2c_probe(addr)) {
1923 if (i2c_probe(addr)) {
1924 puts("Can't found s6d16a0x backlight i2c\n");
1929 i2c_write(addr, SWRST_REG, 1, val, 1);
1932 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1934 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1935 val[0] = NORMAL_MODE;
1936 i2c_write(addr, LEDCON_REG, 1, val, 1);
1941 void reset_lcd(void)
1943 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1945 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus()) {
1946 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1947 if (board_is_neptune() && hwrevision(3)) {
1949 gpio_set_value(&gpio->gpio_mp0_5, 5, 0);
1951 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1955 if (mach_is_cypress())
1956 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1959 void lcd_power_on(unsigned int onoff)
1961 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1964 if (mach_is_aquila() || mach_is_geminus())
1965 gpio_set_value(&gpio->gpio_j1, 3, 1);
1967 if (mach_is_cypress())
1968 gpio_set_value(&gpio->gpio_g2, 2, 1);
1970 if (mach_is_kessler()) {
1972 unsigned char val[2];
1973 unsigned char val2[2];
1975 gpio_set_value(&gpio->gpio_j1, 3, 1);
1977 addr = 0xCC >> 1; /* max8998 */
1978 if (max8998_probe())
1981 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1982 val[0] &= ~(MAX8998_LDO17);
1983 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1984 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1986 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1987 val[0] |= MAX8998_LDO17;
1989 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1990 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1992 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1993 val[0] |= MAX8998_LDO7;
1995 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1996 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1999 if (mach_is_aquila() || mach_is_geminus())
2000 gpio_set_value(&gpio->gpio_j1, 3, 0);
2002 if (mach_is_cypress())
2003 gpio_set_value(&gpio->gpio_g2, 2, 0);
2005 if (mach_is_kessler()) {
2007 unsigned char val[2];
2009 gpio_set_value(&gpio->gpio_j1, 3, 0);
2011 addr = 0xCC >> 1; /* max8998 */
2012 if (max8998_probe())
2015 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2016 val[0] &= ~(MAX8998_LDO7);
2017 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2018 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2020 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2021 val[0] &= ~(MAX8998_LDO17);
2022 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2023 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2028 extern void s6e63m0_cfg_ldo(void);
2029 extern void s6e63m0_enable_ldo(unsigned int onoff);
2030 extern void s6d16a0x_cfg_ldo(void);
2031 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2032 extern void ld9040_cfg_ldo(void);
2033 extern void ld9040_enable_ldo(unsigned int onoff);
2035 int s5p_no_lcd_support(void)
2037 if (mach_is_wmg160())
2042 void init_panel_info(vidinfo_t *vid)
2044 vid->cfg_gpio = NULL;
2045 vid->reset_lcd = NULL;
2046 vid->backlight_on = NULL;
2047 vid->lcd_power_on = NULL;
2049 vid->cfg_ldo = NULL;
2050 vid->enable_ldo = NULL;
2052 vid->init_delay = 0;
2053 vid->reset_delay = 0;
2054 vid->power_on_delay = 0;
2059 vid->vl_width = 480;
2060 vid->vl_height = 800;
2062 vid->dual_lcd_enabled = 0;
2064 if (board_is_media()) {
2067 vid->vl_width = 960;
2068 vid->vl_height = 800;
2070 /* enable dual lcd mode. */
2071 vid->dual_lcd_enabled = 1;
2074 vid->vl_clkp = CONFIG_SYS_HIGH;
2075 vid->vl_hsp = CONFIG_SYS_LOW;
2076 vid->vl_vsp = CONFIG_SYS_LOW;
2077 vid->vl_dp = CONFIG_SYS_HIGH;
2080 /* S6E63M0 LCD Panel */
2089 if (mach_is_aquila() || mach_is_kessler()
2090 || mach_is_cypress()) {
2091 vid->cfg_gpio = lcd_cfg_gpio;
2092 vid->reset_lcd = reset_lcd;
2093 vid->backlight_on = backlight_on;
2094 vid->lcd_power_on = lcd_power_on;
2095 vid->cfg_ldo = s6e63m0_cfg_ldo;
2096 vid->enable_ldo = s6e63m0_enable_ldo;
2098 vid->init_delay = 25000;
2099 vid->reset_delay = 120000;
2102 if (board_is_neptune() && hwrevision(0)) {
2106 vid->vl_width = 320;
2107 vid->vl_height = 480;
2109 vid->vl_clkp = CONFIG_SYS_HIGH;
2110 vid->vl_hsp = CONFIG_SYS_HIGH;
2111 vid->vl_vsp = CONFIG_SYS_HIGH;
2112 vid->vl_dp = CONFIG_SYS_LOW;
2115 /* disable dual lcd mode. */
2116 vid->dual_lcd_enabled = 0;
2118 /* S6D16A0X LCD Panel */
2127 vid->cfg_gpio = lcd_cfg_gpio;
2128 vid->backlight_on = backlight_on;
2129 vid->lcd_power_on = lcd_power_on;
2130 vid->reset_lcd = reset_lcd;
2131 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2132 vid->enable_ldo = s6d16a0x_enable_ldo;
2134 vid->init_delay = 10000;
2135 vid->power_on_delay = 10000;
2136 vid->reset_delay = 1000;
2139 if (board_is_neptune() && hwrevision(3)) {
2143 vid->vl_width = 480;
2144 vid->vl_height = 800;
2145 vid->vl_clkp = CONFIG_SYS_HIGH;
2146 vid->vl_hsp = CONFIG_SYS_HIGH;
2147 vid->vl_vsp = CONFIG_SYS_HIGH;
2148 vid->vl_dp = CONFIG_SYS_HIGH;
2151 /* disable dual lcd mode. */
2152 vid->dual_lcd_enabled = 0;
2154 /* LD9040 LCD Panel */
2163 vid->cfg_gpio = lcd_cfg_gpio;
2164 vid->backlight_on = NULL;
2165 vid->lcd_power_on = lcd_power_on;
2166 vid->reset_lcd = reset_lcd;
2167 vid->cfg_ldo = ld9040_cfg_ldo;
2168 vid->enable_ldo = ld9040_enable_ldo;
2170 vid->init_delay = 0;
2171 vid->power_on_delay = 30000;
2172 vid->reset_delay = 20000;
2174 if (mach_is_geminus()) {
2178 vid->vl_width = 1024,
2179 vid->vl_height = 600,
2180 vid->vl_clkp = CONFIG_SYS_LOW,
2181 vid->vl_hsp = CONFIG_SYS_HIGH,
2182 vid->vl_vsp = CONFIG_SYS_HIGH,
2183 vid->vl_dp = CONFIG_SYS_LOW,
2194 vid->cfg_gpio = lcd_cfg_gpio;
2195 vid->reset_lcd = reset_lcd;
2196 vid->backlight_on = backlight_on;
2197 vid->lcd_power_on = lcd_power_on;
2203 vid->vl_width = 480,
2204 vid->vl_height = 800,
2205 vid->vl_clkp = CONFIG_SYS_HIGH,
2206 vid->vl_hsp = CONFIG_SYS_LOW,
2207 vid->vl_vsp = CONFIG_SYS_LOW,
2208 vid->vl_dp = CONFIG_SYS_HIGH,
2224 vid->vl_width = 1024,
2225 vid->vl_height = 600,
2226 vid->vl_clkp = CONFIG_SYS_HIGH,
2227 vid->vl_hsp = CONFIG_SYS_HIGH,
2228 vid->vl_vsp = CONFIG_SYS_HIGH,
2229 vid->vl_dp = CONFIG_SYS_LOW,
2232 /* AMS701KA AMOLED Panel. */
2244 static void setup_meminfo(void)
2246 char meminfo[64] = {0, };
2247 int count = 0, size, real;
2249 size = gd->bd->bi_dram[0].size >> 20;
2250 count += sprintf(meminfo + count, "mem=%dM", size);
2252 /* Each Chip Select can't exceed the 256MiB */
2253 size = gd->bd->bi_dram[1].size >> 20;
2254 real = min(size, 256);
2255 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2256 real, (unsigned int)gd->bd->bi_dram[1].start);
2260 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2261 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2264 setenv("meminfo", meminfo);
2267 int misc_init_r(void)
2270 /* It should be located at first */
2273 if (mach_is_aquila() || mach_is_kessler()) {
2274 if (board_is_neptune() && hwrevision(0))
2275 setenv("lcdinfo", "lcd=s6d16a0x");
2276 else if (board_is_neptune() && hwrevision(3))
2277 setenv("lcdinfo", "lcd=ld9040");
2278 else if (board_is_media())
2279 setenv("lcdinfo", "lcd=s6e63m0");
2281 setenv("lcdinfo", "lcd=s6e63m0");
2283 if (mach_is_geminus())
2284 setenv("lcdinfo", "lcd=lms480jc01");
2285 if (mach_is_cypress())
2286 setenv("lcdinfo", "lcd=s6e63m0");
2292 /* Set proper PMIC pins */
2295 /* Check auto burning */
2298 /* To power up I2C2 */
2301 /* Enable T-Flash at Limo Real or Limo Universal */
2304 /* Setup Limo Real board GPIOs */
2305 setup_limo_real_gpios();
2307 /* Setup Media board GPIOs */
2308 setup_media_gpios();
2310 /* To usbdown automatically */
2316 #ifdef CONFIG_S5PC1XXFB
2317 display_device_info();
2320 setup_power_down_mode_registers();
2322 /* check max17040 */
2332 int board_init(void)
2334 /* Set Initial global variables */
2335 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2337 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2338 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2342 * set reserved memory region for framebuffer.
2344 * this region wouldn't be rewrited by kernel so
2345 * could avoid nosie screen filled by garbages
2346 * after hibernation resume has been completed.
2348 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2351 /* Check H/W Revision */
2352 check_hw_revision();
2359 unsigned int base, memconfig0, size;
2360 unsigned int memconfig1, sz = 0;
2362 if (cpu_is_s5pc100()) {
2363 /* In mem setup, we swap the bank. So below size is correct */
2364 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2365 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2366 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2369 /* In S5PC110, we can't swap the DMC0/1 */
2370 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2371 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2373 base = S5PC110_DMC1_BASE;
2374 /* DMC configuration */
2375 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2376 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2378 size = (memconfig0 >> 16) & 0xFF;
2379 size = ((unsigned char) ~size) + 1;
2382 * (0x07 + 1) * 16 = 128 MiB
2383 * (0x0f + 1) * 16 = 256 MiB
2388 * Aquila Rev0.5 4G3G1G
2389 * Aquila Rev0.8 4G3G1G
2390 * Aquila Rev0.9 4G3G1G
2391 * Neptune Rev 0.2 4G3G1G
2393 if (mach_is_aquila() || mach_is_kessler()) {
2394 if ((!board_is_neptune() && (hwrevision(5) ||
2395 hwrevision(8) || hwrevision(9))) ||
2396 (board_is_neptune() && hwrevision(2))) {
2397 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2399 sz = (memconfig1 >> 16) & 0xFF;
2400 sz = ((unsigned char) ~sz) + 1;
2403 if (mach_is_kessler() && board_is_s1())
2408 * bi_dram[1].size contains all DMC1 memory size
2410 gd->bd->bi_dram[1].size = (size + sz) << 20;
2415 /* Used for sleep test */
2416 static unsigned char saved_val[4][2];
2417 void board_sleep_init_late(void)
2419 /* CODEC_LDO_EN: GPF3[4] */
2420 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2421 /* CODEC_XTAL_EN: GPH3[2] */
2422 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2424 /* MMC T_FLASH off */
2425 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2427 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2428 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2429 /* MHL_ON for REV02 or higher */
2430 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2433 void board_sleep_init(void)
2436 unsigned char val[2];
2439 if (max8998_probe())
2442 if (mach_is_kessler()) {
2444 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2445 saved_val[0][0] = val[0];
2446 saved_val[0][1] = val[1];
2447 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2448 (1 << 1) | (1 << 0));
2449 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2450 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2453 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2454 saved_val[1][0] = val[0];
2455 saved_val[1][1] = val[1];
2456 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2457 (1 << 2) | (1 << 1) | (1 << 0));
2459 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2460 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2463 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2464 saved_val[2][0] = val[0];
2465 saved_val[2][1] = val[1];
2466 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2467 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2468 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2471 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2472 saved_val[3][0] = val[0];
2473 saved_val[3][1] = val[1];
2474 val[0] &= ~((1 << 6) | (1 << 4));
2475 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2476 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2478 printf("Turned off regulators with Kessler setting."
2479 " Preparing to sleep. [%s:%d]\n",
2480 __FILE__, __LINE__);
2481 } else { /* Default */
2483 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2484 saved_val[0][0] = val[0];
2485 saved_val[0][1] = val[1];
2486 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2487 (1 << 1) | (1 << 0));
2488 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2489 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2492 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2493 saved_val[1][0] = val[0];
2494 saved_val[1][1] = val[1];
2495 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2496 (1 << 2) | (1 << 1) | (1 << 0));
2498 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2499 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2502 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2503 saved_val[2][0] = val[0];
2504 saved_val[2][1] = val[1];
2505 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2506 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2507 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2510 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2511 saved_val[3][0] = val[0];
2512 saved_val[3][1] = val[1];
2513 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2514 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2515 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2517 printf("Turned off regulators with default(Aquila) setting."
2518 " Preparing to sleep. [%s:%d]\n",
2519 __FILE__, __LINE__);
2523 void board_sleep_resume(void)
2526 unsigned char val[2];
2531 if (max8998_probe())
2535 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2536 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2538 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2539 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2541 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2542 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2544 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2545 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2546 puts("Waked up.\n");
2548 /* check max17040 */
2555 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2557 static int s5pc1xx_phy_control(int on)
2561 if (on && !status) {
2562 #ifdef CONFIG_CMD_PMIC
2563 run_command("pmic ldo 3 on", 0);
2566 if (board_is_limo_universal() ||
2567 board_is_limo_real() ||
2569 /* check usb path */
2570 if (board_is_limo_real() && !hwrevision(6))
2574 if (mach_is_tickertape())
2575 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2576 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2578 /* USB Path to AP */
2579 micro_usb_switch(0);
2581 } else if (!on && status) {
2582 #ifdef CONFIG_CMD_PMIC
2583 run_command("pmic ldo 3 off", 0);
2592 struct s3c_plat_otg_data s5pc110_otg_data = {
2593 .phy_control = s5pc1xx_phy_control,
2594 .regs_phy = S5PC110_PHY_BASE,
2595 .regs_otg = S5PC110_OTG_BASE,
2598 int board_eth_init(bd_t *bis)
2602 if (cpu_is_s5pc100())
2605 s3c_udc_probe(&s5pc110_otg_data);
2606 if (usb_eth_initialize(bis) >= 0)
2612 #ifdef CONFIG_CMD_USBDOWN
2613 int usb_board_init(void)
2615 #ifdef CONFIG_CMD_PMIC
2616 run_command("pmic ldo 3 on", 0);
2619 if (cpu_is_s5pc100()) {
2620 #ifdef CONFIG_HARD_I2C
2621 uchar val[2] = {0,};
2624 if (i2c_read(0x66, 0, 1, val, 2)) {
2625 puts("i2c_read error\n");
2632 if (i2c_write(0x66, 0, 1, val, 2)) {
2633 puts("i2c_write error\n");
2636 i2c_read(0x66, 0, 1, val, 2);
2642 if (board_is_limo_universal() ||
2643 board_is_limo_real() ||
2645 /* check usb path */
2646 if (board_is_limo_real() && !hwrevision(6))
2650 if (mach_is_tickertape())
2651 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2652 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2654 /* USB Path to AP */
2655 micro_usb_switch(0);
2661 #ifdef CONFIG_GENERIC_MMC
2662 int s5p_no_mmc_support(void)
2664 if (mach_is_wmg160())
2669 int board_mmc_init(bd_t *bis)
2673 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2676 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2677 if (mach_is_kessler())
2678 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2680 if (mach_is_wmg160())
2683 /* MMC0 Clock source = SCLKMPLL */
2684 reg = readl(&clk->src4);
2687 writel(reg, &clk->src4);
2689 reg = readl(&clk->div4);
2692 /* set div value near 50MHz */
2693 clock = get_pll_clk(MPLL) / 1000000;
2694 for (i = 0; i < 0xf; i++) {
2695 if ((clock / (i + 1)) <= 50) {
2701 writel(reg, &clk->div4);
2707 * GPG0[2] SD_0_CDn -> Not used
2708 * GPG0[3:6] SD_0_DATA[0:3]
2710 for (i = 0; i < 7; i++) {
2713 /* GPG0[0:6] special function 2 */
2714 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2715 /* GPG0[0:6] pull disable */
2716 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2717 /* GPG0[0:6] drv 4x */
2718 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2721 if (mach_is_geminus()) {
2722 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2723 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2726 return s5pc1xx_mmc_init(0);
2730 #ifdef CONFIG_CMD_PMIC
2731 static int pmic_status(void)
2733 unsigned char addr, val[2];
2738 if (max8998_probe())
2742 i2c_read(addr, reg, 1, val, 1);
2743 for (i = 7; i >= 4; i--)
2744 printf("BUCK%d %s\n", 7 - i + 1,
2745 val[0] & (1 << i) ? "on" : "off");
2747 printf("LDO%d %s\n", 5 - i,
2748 val[0] & (1 << i) ? "on" : "off");
2750 i2c_read(addr, reg, 1, val, 1);
2751 for (i = 7; i >= 0; i--)
2752 printf("LDO%d %s\n", 7 - i + 6,
2753 val[0] & (1 << i) ? "on" : "off");
2755 i2c_read(addr, reg, 1, val, 1);
2756 for (i = 7; i >= 4; i--)
2757 printf("LDO%d %s\n", 7 - i + 14,
2758 val[0] & (1 << i) ? "on" : "off");
2761 i2c_read(addr, reg, 1, val, 1);
2762 for (i = 7; i >= 6; i--)
2763 printf("SAFEOUT%d %s\n", 7 - i + 1,
2764 val[0] & (1 << i) ? "on" : "off");
2768 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2770 unsigned char addr, val[2];
2771 unsigned int reg, shift;
2779 } else if (ldo <= 13) {
2782 } else if (ldo <= 17) {
2784 shift = 17 - ldo + 4;
2791 shift = 4 - buck + 4;
2792 } else if (safeout) {
2796 shift = 8 - safeout;
2802 if (max8998_probe())
2805 i2c_read(addr, reg, 1, val, 1);
2807 val[0] |= (1 << shift);
2809 val[0] &= ~(1 << shift);
2810 i2c_write(addr, reg, 1, val, 1);
2811 i2c_read(addr, reg, 1, val, 1);
2814 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2815 val[0] & (1 << shift) ? "on" : "off");
2817 printf("buck %d value 0x%x, %s\n", buck, val[0],
2818 val[0] & (1 << shift) ? "on" : "off");
2820 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2821 val[0] & (1 << shift) ? "on" : "off");
2826 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2828 int buck = 0, ldo = 0, safeout = 0, on = -1;
2832 if (strncmp(argv[1], "status", 6) == 0)
2833 return pmic_status();
2836 if (strncmp(argv[1], "ldo", 3) == 0)
2837 ldo = simple_strtoul(argv[2], NULL, 10);
2838 else if (strncmp(argv[1], "buck", 4) == 0)
2839 buck = simple_strtoul(argv[2], NULL, 10);
2840 else if (strncmp(argv[1], "safeout", 7) == 0)
2841 safeout = simple_strtoul(argv[2], NULL, 10);
2845 if (strncmp(argv[3], "on", 2) == 0)
2847 else if (strncmp(argv[3], "off", 3) == 0)
2852 return pmic_ldo_control(buck, ldo, safeout, on);
2863 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2864 "PMIC LDO & BUCK control",
2865 "status - Display PMIC LDO & BUCK status\n"
2866 "pmic ldo num on/off - Turn on/off the LDO\n"
2867 "pmic buck num on/off - Turn on/off the BUCK\n"
2868 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2872 #ifdef CONFIG_CMD_DEVICE_POWER
2873 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2877 if (strncmp(argv[1], "cp", 2) == 0) {
2878 micro_usb_switch(1);
2879 pmic_ldo_control(0, 0, 2, 1);
2880 setenv("usb", "cp");
2881 } else if (strncmp(argv[1], "ap", 2) == 0) {
2882 micro_usb_switch(0);
2883 pmic_ldo_control(0, 0, 2, 0);
2884 setenv("usb", "ap");
2894 printf("USB Path is set to %s\n", getenv("usb"));
2900 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2902 "cp - switch to CP\n"
2903 "microusb ap - switch to AP\n"