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 if (board_is_neptune() && (hwrevision(3) || hwrevision(4)) && i == 0) {
875 /* Set GPH3[3:0] to KP_ROW[3:0] */
876 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
877 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
880 for (i = 0; i < col_num; i++)
881 /* Set GPH2[3:0] to KP_COL[3:0] */
882 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
884 reg = S5PC110_KEYPAD_BASE;
885 col_mask = S5PC110_KEYIFCOLEN_MASK;
889 /* KEYIFCOL reg clear */
890 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
893 for (i = 0; i < col_num; i++) {
895 value &= ~(1 << i) << col_mask_shift;
897 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
900 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
901 row_state[i] = ~value & ((1 << row_num) - 1);
903 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
906 /* KEYIFCOL reg clear */
907 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
909 if (mach_is_aquila() || mach_is_kessler()) {
911 if (row_state[1] & 0x2)
913 if (board_is_neptune() && hwrevision(0)) {
914 /* home & volume down */
915 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
917 } else if (board_is_neptune() && hwrevision(2)) {
918 /* cam full shot & volume down */
919 if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
921 } else if (board_is_neptune() && (hwrevision(3) || hwrevision(4))) {
922 /* cam full shot & volume down */
923 if ((row_state[1] & 0x6) && (row_state[2] & 0x4))
926 /* cam full shot & volume down */
927 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
930 } else if (mach_is_geminus())
931 /* volume down & home */
932 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
936 setenv("bootcmd", "usbdown");
939 static void check_battery(int mode)
941 unsigned char val[2];
942 unsigned char addr = 0x36; /* max17040 fuel gauge */
944 i2c_set_bus_num(I2C_GPIO3);
946 if (mach_is_aquila()) {
949 } else if (mach_is_kessler()) {
950 i2c_set_bus_num(I2C_GPIO7);
951 } else if (mach_is_cypress()) {
952 i2c_set_bus_num(I2C_GPIO7);
953 } else if (mach_is_geminus()) {
955 i2c_set_bus_num(I2C_GPIO7);
959 if (i2c_probe(addr)) {
960 puts("Can't found max17040 fuel gauge\n");
964 /* mode 0: check mode / 1: enable mode */
968 i2c_write(addr, 0xfe, 1, val, 2);
970 i2c_read(addr, 0x04, 1, val, 1);
971 dprintf("battery:\t%d%%\n", val[0]);
972 battery_soc = val[0];
976 static void check_mhl(void)
978 unsigned char val[2];
979 unsigned char addr = 0x39; /* SIL9230 */
981 /* MHL Power enable */
982 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
983 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
985 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
986 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
988 /* 10ms required after reset */
992 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
994 i2c_set_bus_num(I2C_GPIO5);
997 if (i2c_probe(addr)) {
998 puts("Can't found MHL Chip\n");
1004 * set to Normal operation
1007 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
1008 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
1013 * 00 = MHL termination ON
1014 * 11 = MHL termination OFF
1017 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
1018 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1021 static int max8998_probe(void)
1023 unsigned char addr = 0xCC >> 1;
1025 i2c_set_bus_num(I2C_PMIC);
1027 if (i2c_probe(addr)) {
1028 puts("Can't found max8998\n");
1035 #define CHARGER_ANIMATION_FRAME 6
1036 static void max8998_clear_interrupt(void)
1038 unsigned char addr, val[2];
1041 if (max8998_probe())
1044 i2c_read(addr, 0x00, 1, val, 1);
1045 i2c_read(addr, 0x01, 1, val, 1);
1046 i2c_read(addr, 0x02, 1, val, 1);
1047 i2c_read(addr, 0x03, 1, val, 1);
1050 static int max8998_power_key(void)
1052 unsigned char addr, val[2];
1055 if (max8998_probe())
1058 /* Accessing IRQ1 register */
1059 i2c_read(addr, 0x00, 1, val, 1);
1060 if (val[0] & (1 << 6))
1066 static int max8998_has_ext_power_source(void)
1068 unsigned char addr, val[2];
1071 if (max8998_probe())
1074 /* Accessing STATUS2 register */
1075 i2c_read(addr, 0x09, 1, val, 1);
1076 if (val[0] & (1 << 5))
1082 struct thermister_stat {
1087 static struct thermister_stat adc_to_temperature_data[] = {
1088 { .centigrade = -20, .adc = 1856, },
1089 { .centigrade = -15, .adc = 1799, },
1090 { .centigrade = -10, .adc = 1730, },
1091 { .centigrade = -5, .adc = 1649, },
1092 { .centigrade = 0, .adc = 1556, },
1093 { .centigrade = 5, .adc = 1454, },
1094 { .centigrade = 10, .adc = 1343, },
1095 { .centigrade = 15, .adc = 1227, },
1096 { .centigrade = 20, .adc = 1109, },
1097 { .centigrade = 25, .adc = 992, },
1098 { .centigrade = 30, .adc = 880, },
1099 { .centigrade = 35, .adc = 773, },
1100 { .centigrade = 40, .adc = 675, },
1101 { .centigrade = 45, .adc = 586, },
1102 { .centigrade = 50, .adc = 507, },
1103 { .centigrade = 55, .adc = 436, },
1104 { .centigrade = 58, .adc = 399, },
1105 { .centigrade = 63, .adc = 343, },
1106 { .centigrade = 65, .adc = 322, },
1110 #define USHRT_MAX 0xFFFFU
1112 static int adc_to_temperature_centigrade(unsigned short adc)
1116 /* low_*: Greatest Lower Bound,
1117 * * * * high_*: Smallest Upper Bound */
1118 int low_temp = 0, high_temp = 0;
1119 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1120 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1121 if (adc_to_temperature_data[i].adc <= adc &&
1122 adc_to_temperature_data[i].adc >= low_adc) {
1123 low_temp = adc_to_temperature_data[i].centigrade;
1124 low_adc = adc_to_temperature_data[i].adc;
1126 if (adc_to_temperature_data[i].adc >= adc &&
1127 adc_to_temperature_data[i].adc <= high_adc) {
1128 high_temp = adc_to_temperature_data[i].centigrade;
1129 high_adc = adc_to_temperature_data[i].adc;
1133 /* Linear approximation between cloest low and high,
1134 * which is the weighted average of the two. */
1136 /* The following equation is correct only when the two are different */
1137 if (low_adc == high_adc)
1139 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1140 return 20; /* The room temperature */
1143 if (high_adc == USHRT_MAX)
1146 approximation = low_temp * (adc - low_adc) +
1147 high_temp * (high_adc - adc);
1148 approximation /= high_adc - low_adc;
1150 return approximation;
1153 static unsigned short get_adc_value(int channel)
1155 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1156 unsigned short ret = 0;
1160 unsigned int loop = 0;
1162 if (mach_is_kessler())
1164 else if (mach_is_geminus())
1166 else if (mach_is_wmg160())
1168 else if (mach_is_cypress())
1170 else if (mach_is_tickertape())
1172 else if (mach_is_aquila())
1175 else if (mach_is_p1p2())
1179 sprintf(buf, "pmic ldo %d on", ldonum);
1180 run_command(buf, 0);
1182 writel(channel & 0xF, &adc->adcmux);
1183 writel((1 << 14) | (49 << 6), &adc->adccon);
1184 writel(1000 & 0xffff, &adc->adcdly);
1185 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1187 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1192 reg = readl(&adc->adccon);
1193 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1195 ret = readl(&adc->adcdat0) & 0xFFF;
1196 sprintf(buf, "pmic ldo %d off", ldonum);
1197 run_command(buf, 0);
1202 static int adc_get_average_ambient_temperature(void)
1204 if (mach_is_kessler()) {
1205 unsigned short min = USHRT_MAX;
1206 unsigned short max = 0;
1207 unsigned int sum = 0;
1208 unsigned int measured = 0;
1211 for (i = 0; i < 7; i++) {
1212 unsigned short measurement = get_adc_value(6);
1215 if (min > measurement)
1217 if (max < measurement)
1220 if (measured >= 3) {
1226 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1227 adc_to_temperature_centigrade(sum), sum);
1228 return adc_to_temperature_centigrade(sum);
1231 return 20; /* 20 Centigrade */
1234 enum temperature_level {
1242 static enum temperature_level temperature_check(void)
1244 int temp = adc_get_average_ambient_temperature();
1246 return _TEMP_TOO_LOW;
1248 return _TEMP_OK_LOW;
1250 return _TEMP_TOO_HIGH;
1252 return _TEMP_OK_HIGH;
1256 extern void lcd_display_clear(void);
1257 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1259 static void charger_en(int enable)
1265 unsigned char addr = 0xCC >> 1; /* max8998 */
1266 unsigned char val[2];
1268 if (max8998_probe())
1272 puts("Disable the charger.\n");
1273 i2c_read(addr, 0x0D, 1, val, 1);
1276 i2c_write(addr, 0x0D, 1, val, 1);
1278 i2c_read(addr, 0x0C, 1, val, 1);
1279 val[0] &= ~(0x7 << 0);
1280 val[0] &= ~(0x7 << 5);
1281 if (enable == 600) {
1282 val[0] |= 5; /* 600mA */
1283 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1284 } else { /* Assume 475 mA */
1286 val[0] |= 2; /* 475mA */
1287 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1289 i2c_write(addr, 0x0C, 1, val, 1);
1291 i2c_read(addr, 0x0D, 1, val, 1);
1293 i2c_write(addr, 0x0D, 1, val, 1);
1294 printf("Enable the charger @ %dmA\n", enable);
1298 void lcd_power_on(unsigned int onoff);
1299 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1300 extern int drv_lcd_init_resume (void);
1302 static void into_charge_mode(void)
1308 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1309 unsigned int reg, wakeup_stat;
1310 int charger_speed = 600;
1312 max8998_clear_interrupt();
1314 puts("Charge Mode\n");
1315 charger_en(charger_speed);
1317 #ifdef CONFIG_S5PC1XXFB
1320 /* TODO: write the image-text for the charger */
1322 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1323 if (level >= CHARGER_ANIMATION_FRAME)
1324 level = CHARGER_ANIMATION_FRAME - 1;
1326 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1327 bmp_addr[i] = (ulong)battery_charging_animation[i];
1329 lcd_display_clear();
1330 for (i = 0; i < 3; i++) {
1331 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1334 bmp = gunzip_bmp(bmp_addr[j], &len);
1335 lcd_display_bitmap((ulong)bmp, 140, 202);
1338 for (k = 0; k < 10; k++) {
1339 if (max8998_power_key()) {
1340 lcd_display_clear();
1341 goto restore_screen;
1342 } else if (!max8998_has_ext_power_source()) {
1343 lcd_display_clear();
1344 goto restore_screen;
1353 /* Disable the display to prevent flickering */
1354 /* TODO: how to reenable the display later? */
1359 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1360 unsigned int org, org_ip3;
1361 enum temperature_level previous_state = _TEMP_OK;
1363 empty_device_info_buffer();
1364 if (max8998_power_key())
1366 else if (!max8998_has_ext_power_source())
1369 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1370 org_ip3 = readl(0xE010046C);
1371 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1373 reg = org = readl(&rtc->rtccon);
1375 writel(reg, &rtc->rtccon);
1377 reg = readl(&rtc->rtccon);
1378 writel(reg | (1 << 3), &rtc->rtccon);
1380 writel(reg & ~(1 << 3), &rtc->rtccon);
1383 reg = readl(&rtc->rtccon);
1384 reg &= ~((1 << 8) | (0xF << 4));
1385 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1386 writel(reg, &rtc->rtccon);
1388 reg = 15 * 4 - 1; /* 15 sec */
1389 writel(reg, &rtc->ticcnt);
1391 /* EVT0: sleep 1, EVT1: sleep */
1392 if (cpu_is_s5pc110()) {
1393 char *name = "dummy";
1394 char *usage = "N/A";
1401 if (s5pc1xx_get_cpu_rev() == 0) {
1402 char *argv[] = {"1", "1"};
1403 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1405 char *argv[] = {"0", "0"};
1406 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1409 puts("\n\n\nERROR: this is not S5PC110.\n\n\n");
1413 /* Check TEMP HIGH/LOW */
1414 switch (temperature_check()) {
1416 charger_en(charger_speed);
1417 previous_state = _TEMP_OK;
1421 previous_state = _TEMP_TOO_LOW;
1423 case _TEMP_TOO_HIGH:
1425 previous_state = _TEMP_TOO_HIGH;
1428 if (previous_state == _TEMP_TOO_LOW) {
1431 charger_en(charger_speed);
1432 previous_state = _TEMP_OK;
1436 if (previous_state == _TEMP_TOO_HIGH) {
1439 charger_en(charger_speed);
1440 previous_state = _TEMP_OK;
1445 writel(org, &rtc->rtccon);
1446 writel(org_ip3, 0xE010046C);
1448 } while (wakeup_stat == 0x04); /* RTC TICK */
1450 #ifdef CONFIG_S5PC1XXFB
1452 /* TODO: Reenable logo display (not working yet) */
1454 drv_lcd_init_resume();
1458 #define S5PC110_RST_STAT 0xE010A000
1460 #define SWRESET (1 << 3)
1461 #define WDTRESET (1 << 2)
1462 #define WARMRESET (1 << 1)
1463 #define EXTRESET (1 << 0)
1465 static int get_reset_status(void)
1467 return readl(S5PC110_RST_STAT) & 0xf;
1470 static int fsa9480_probe(void)
1472 unsigned char addr = 0x25;
1474 if (cpu_is_s5pc100())
1477 if (board_is_limo_real()) {
1478 if (hwrevision(0) || hwrevision(1))
1482 i2c_set_bus_num(I2C_PMIC);
1484 if (mach_is_kessler()) {
1485 i2c_set_bus_num(I2C_GPIO6);
1486 } else if (mach_is_cypress()) {
1487 i2c_set_bus_num(I2C_GPIO6);
1488 } else if (mach_is_geminus()) {
1490 i2c_set_bus_num(I2C_GPIO6);
1491 } else if (mach_is_wmg160()) {
1492 i2c_set_bus_num(I2C_GPIO6);
1495 if (i2c_probe(addr)) {
1496 puts("Can't found fsa9480\n");
1503 static void check_micro_usb(int intr)
1506 unsigned char val[2];
1507 static int started_charging_once = 0;
1510 if (fsa9480_probe())
1513 addr = 0x25; /* fsa9480 */
1515 /* Clear Interrupt */
1517 i2c_read(addr, 0x03, 1, val, 2);
1521 /* Read Device Type 1 */
1522 i2c_read(addr, 0x0a, 1, val, 1);
1524 #define FSA_DEV1_CHARGER (1 << 6)
1525 #define FSA_DEV1_UART (1 << 3)
1526 #define FSA_DEV1_USB (1 << 2)
1527 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1528 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1531 * If USB, use default 475mA
1532 * If Charger, use 600mA and go to charge mode
1534 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1535 started_charging_once = 1;
1537 /* If it's full, do not charge. */
1538 if (battery_soc < 100)
1542 } else if (val[0] & FSA_DEV1_USB) {
1543 if (battery_soc < 100)
1544 charger_en(475); /* enable charger and keep booting */
1549 /* If reset status is watchdog reset then skip it */
1550 if (!(get_reset_status() & WDTRESET)) {
1551 /* If Factory Mode is Boot ON-USB, go to download mode */
1552 i2c_read(addr, 0x07, 1, val, 1);
1554 #define FSA_ADC_FAC_USB_OFF 0x18
1555 #define FSA_ADC_FAC_USB_ON 0x19
1556 #define FSA_ADC_FAC_UART 0x1d
1558 if (val[0] == FSA_ADC_FAC_USB_ON ||
1559 val[0] == FSA_ADC_FAC_USB_OFF)
1560 setenv("bootcmd", "usbdown");
1563 path = getenv("usb");
1565 if (!strncmp(path, "cp", 2))
1566 run_command("microusb cp", 0);
1569 static void micro_usb_switch(int path)
1572 unsigned char val[2];
1574 if (fsa9480_probe())
1577 addr = 0x25; /* fsa9480 */
1580 val[0] = 0x90; /* VAUDIO */
1582 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1584 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1586 i2c_read(addr, 0x2, 1, val, 1);
1587 val[0] &= ~(1 << 2); /* Manual switching */
1588 i2c_write(addr, 0x2, 1, val, 1);
1591 #define MAX8998_REG_ONOFF1 0x11
1592 #define MAX8998_REG_ONOFF2 0x12
1593 #define MAX8998_REG_ONOFF3 0x13
1594 #define MAX8998_REG_LDO7 0x21
1595 #define MAX8998_REG_LDO17 0x29
1597 #define MAX8998_LDO3 (1 << 2)
1599 #define MAX8998_LDO6 (1 << 7)
1600 #define MAX8998_LDO7 (1 << 6)
1601 #define MAX8998_LDO8 (1 << 5)
1602 #define MAX8998_LDO9 (1 << 4)
1603 #define MAX8998_LDO10 (1 << 3)
1604 #define MAX8998_LDO11 (1 << 2)
1605 #define MAX8998_LDO12 (1 << 1)
1606 #define MAX8998_LDO13 (1 << 0)
1608 #define MAX8998_LDO14 (1 << 7)
1609 #define MAX8998_LDO15 (1 << 6)
1610 #define MAX8998_LDO16 (1 << 5)
1611 #define MAX8998_LDO17 (1 << 4)
1614 static void init_pmic(void)
1617 unsigned char val[2];
1619 if (cpu_is_s5pc100())
1622 addr = 0xCC >> 1; /* max8998 */
1623 if (max8998_probe())
1627 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1628 val[0] &= ~MAX8998_LDO3;
1629 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1632 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1634 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1635 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1637 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1638 MAX8998_LDO12 | MAX8998_LDO13);
1640 if (mach_is_kessler())
1641 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1643 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1644 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1646 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1648 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1649 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1651 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1652 MAX8998_LDO16 | MAX8998_LDO17);
1654 if (mach_is_kessler())
1655 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1657 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1658 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1661 static void setup_power_down_mode_registers(void)
1663 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1664 struct s5pc1xx_gpio_bank *bank;
1665 struct gpio_powermode *p;
1667 struct gpio_external *ge;
1669 struct s5pc1xx_gpio_item *mr;
1673 if (cpu_is_s5pc100())
1676 /* Only Limo real and kessler supports worked for sleep currnet */
1677 if (mach_is_aquila()) {
1678 if (board_is_limo_real())
1682 } else if (mach_is_kessler()) {
1684 } else if (mach_is_geminus()) {
1690 if (mach_is_aquila()) {
1691 /* Aquila rev 0.8 or lower */
1692 p = aquila_powerdown_modes;
1693 ge = aquila_external_powerdown_modes;
1694 mr = aquila_mirror_powerdown_mode;
1695 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1696 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1697 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1698 } else if (mach_is_kessler()) {
1699 /* Aquila rev 0.9 */
1700 p = kessler_powerdown_modes;
1701 ge = kessler_external_powerdown_modes;
1702 mr = kessler_mirror_powerdown_mode;
1703 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1704 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1705 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1706 } else if (mach_is_geminus()) {
1707 if (hwrevision(1)) {
1708 /* Same as Aquila rev 0.9 */
1710 p = kessler_powerdown_modes;
1711 ge = kessler_external_powerdown_modes;
1712 mr = kessler_mirror_powerdown_mode;
1713 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1714 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1715 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1717 p = aquila_powerdown_modes;
1718 ge = aquila_external_powerdown_modes;
1719 mr = aquila_mirror_powerdown_mode;
1720 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1721 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1722 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1724 } else if (hwrevision(0)) {
1725 /* Same as Aquila rev 0.8 or lower */
1726 p = aquila_powerdown_modes;
1727 ge = aquila_external_powerdown_modes;
1728 mr = aquila_mirror_powerdown_mode;
1729 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1730 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1731 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1733 return; /* Not supported */
1737 bank = &gpio->gpio_a0;
1739 for (i = 0; i < n_p; i++, p++, bank++) {
1740 writel(p->conpdn, &bank->pdn_con);
1741 writel(p->pudpdn, &bank->pdn_pull);
1744 writel(0xff0022b0, (unsigned int *)0xF0000000);
1745 writel(0xff0022b0, (unsigned int *)0xF1400000);
1747 bank = &gpio->gpio_h0;
1749 for (i = 0; i < n_ge; i++) {
1750 writel(ge->con, &bank->con);
1751 writel(ge->dat, &bank->dat);
1752 writel(ge->pud, &bank->pull);
1758 for (i = 0; i < n_mr; i++) {
1759 unsigned int reg = readl(&mr->bank->pdn_con);
1760 reg &= ~(0x3 << (mr->number << 1));
1761 if (readl(&mr->bank->dat) & (1 << mr->number))
1762 reg |= 0x1 << (mr->number << 1);
1763 writel(reg, &mr->bank->pdn_con);
1769 #include "../../../drivers/video/s5p-spi.h"
1771 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1772 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1773 extern void ld9040_set_platform_data(struct spi_platform_data *pd);
1775 struct spi_platform_data spi_pd;
1777 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1779 void lcd_cfg_gpio(void)
1781 unsigned int i, f3_end = 4;
1783 for (i = 0; i < 8; i++) {
1784 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1785 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1786 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1787 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1788 /* pull-up/down disable */
1789 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1790 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1791 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1793 /* drive strength to max (24bit) */
1794 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1795 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1796 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1797 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1798 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1799 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1802 /* set DISPLAY_DE_B pin for dual rgb mode. */
1803 if (board_is_media())
1806 for (i = 0; i < f3_end; i++) {
1807 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1808 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1809 /* pull-up/down disable */
1810 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1811 /* drive strength to max (24bit) */
1812 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1813 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1815 /* display output path selection (only [1:0] valid) */
1816 writel(0x2, 0xE0107008);
1818 /* gpio pad configuration for LCD reset. */
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1821 /* gpio pad configuration for LCD ON. */
1822 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1824 /* LCD_BACKLIGHT_EN */
1825 if (mach_is_geminus())
1826 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1827 if (board_is_neptune() && hwrevision(0)) {
1828 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1829 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1833 * gpio pad configuration for
1834 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1836 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1837 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1838 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1839 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1841 if (mach_is_aquila() || mach_is_kessler()) {
1842 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1844 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1846 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1848 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1851 if (board_is_neptune() && hwrevision(0))
1852 s6d16a0x_set_platform_data(&spi_pd);
1853 else if (board_is_neptune() && hwrevision(3))
1854 ld9040_set_platform_data(&spi_pd);
1856 s6e63m0_set_platform_data(&spi_pd);
1857 if (board_is_media())
1862 if (mach_is_cypress()) {
1863 #if 0 /* universal cypress */
1865 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1868 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1870 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1872 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1874 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1876 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1877 #if 0 /* universal cypress */
1878 pd_cs.bank = &gpio_base->gpio_mp0_1;
1881 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1883 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1885 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1890 /* these data would be sent to s6e63m0 lcd panel driver. */
1891 s6e63m0_set_platform_data(&spi_pd);
1897 #define SWRST_REG 0x00
1898 #define LEDCON_REG 0x01
1899 #define LED_CUR_SET_REG 0x03
1900 #define LED_CUR_TR_REG 0x08
1903 #define NORMAL_MODE 0x09
1904 #define CUR_SET 0x63
1906 void backlight_on(unsigned int onoff)
1910 unsigned char val[2];
1911 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1912 printf("%s\n", __func__);
1915 if (mach_is_geminus())
1916 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1918 if (mach_is_geminus())
1919 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1922 if (mach_is_kessler() && board_is_neptune() && hwrevision(0)) {
1923 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1926 i2c_set_bus_num(I2C_GPIO5);
1929 if (i2c_probe(addr)) {
1930 if (i2c_probe(addr)) {
1931 puts("Can't found s6d16a0x backlight i2c\n");
1936 i2c_write(addr, SWRST_REG, 1, val, 1);
1939 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1941 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1942 val[0] = NORMAL_MODE;
1943 i2c_write(addr, LEDCON_REG, 1, val, 1);
1948 void reset_lcd(void)
1950 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1952 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus()) {
1953 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1954 if (board_is_neptune() && (hwrevision(3) || hwrevision(4))) {
1956 gpio_set_value(&gpio->gpio_mp0_5, 5, 0);
1958 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1962 if (mach_is_cypress())
1963 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1966 void lcd_power_on(unsigned int onoff)
1968 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1971 if (mach_is_aquila() || mach_is_geminus())
1972 gpio_set_value(&gpio->gpio_j1, 3, 1);
1974 if (mach_is_cypress())
1975 gpio_set_value(&gpio->gpio_g2, 2, 1);
1977 if (mach_is_kessler()) {
1979 unsigned char val[2];
1980 unsigned char val2[2];
1982 gpio_set_value(&gpio->gpio_j1, 3, 1);
1984 addr = 0xCC >> 1; /* max8998 */
1985 if (max8998_probe())
1988 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1989 val[0] &= ~(MAX8998_LDO17);
1990 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1991 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1993 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1994 val[0] |= MAX8998_LDO17;
1996 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1997 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1999 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2000 val[0] |= MAX8998_LDO7;
2002 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
2003 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2006 if (mach_is_aquila() || mach_is_geminus())
2007 gpio_set_value(&gpio->gpio_j1, 3, 0);
2009 if (mach_is_cypress())
2010 gpio_set_value(&gpio->gpio_g2, 2, 0);
2012 if (mach_is_kessler()) {
2014 unsigned char val[2];
2016 gpio_set_value(&gpio->gpio_j1, 3, 0);
2018 addr = 0xCC >> 1; /* max8998 */
2019 if (max8998_probe())
2022 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2023 val[0] &= ~(MAX8998_LDO7);
2024 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2025 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2027 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2028 val[0] &= ~(MAX8998_LDO17);
2029 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2030 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2035 extern void s6e63m0_cfg_ldo(void);
2036 extern void s6e63m0_enable_ldo(unsigned int onoff);
2037 extern void s6d16a0x_cfg_ldo(void);
2038 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2039 extern void ld9040_cfg_ldo(void);
2040 extern void ld9040_enable_ldo(unsigned int onoff);
2042 int s5p_no_lcd_support(void)
2044 if (mach_is_wmg160())
2049 void init_panel_info(vidinfo_t *vid)
2051 vid->cfg_gpio = NULL;
2052 vid->reset_lcd = NULL;
2053 vid->backlight_on = NULL;
2054 vid->lcd_power_on = NULL;
2056 vid->cfg_ldo = NULL;
2057 vid->enable_ldo = NULL;
2059 vid->init_delay = 0;
2060 vid->reset_delay = 0;
2061 vid->power_on_delay = 0;
2066 vid->vl_width = 480;
2067 vid->vl_height = 800;
2069 vid->dual_lcd_enabled = 0;
2071 if (board_is_media()) {
2074 vid->vl_width = 960;
2075 vid->vl_height = 800;
2077 /* enable dual lcd mode. */
2078 vid->dual_lcd_enabled = 1;
2081 vid->vl_clkp = CONFIG_SYS_HIGH;
2082 vid->vl_hsp = CONFIG_SYS_LOW;
2083 vid->vl_vsp = CONFIG_SYS_LOW;
2084 vid->vl_dp = CONFIG_SYS_HIGH;
2087 /* S6E63M0 LCD Panel */
2096 if (mach_is_aquila() || mach_is_kessler()
2097 || mach_is_cypress()) {
2098 vid->cfg_gpio = lcd_cfg_gpio;
2099 vid->reset_lcd = reset_lcd;
2100 vid->backlight_on = backlight_on;
2101 vid->lcd_power_on = lcd_power_on;
2102 vid->cfg_ldo = s6e63m0_cfg_ldo;
2103 vid->enable_ldo = s6e63m0_enable_ldo;
2105 vid->init_delay = 25000;
2106 vid->reset_delay = 120000;
2109 if (board_is_neptune() && hwrevision(0)) {
2113 vid->vl_width = 320;
2114 vid->vl_height = 480;
2116 vid->vl_clkp = CONFIG_SYS_HIGH;
2117 vid->vl_hsp = CONFIG_SYS_HIGH;
2118 vid->vl_vsp = CONFIG_SYS_HIGH;
2119 vid->vl_dp = CONFIG_SYS_LOW;
2122 /* disable dual lcd mode. */
2123 vid->dual_lcd_enabled = 0;
2125 /* S6D16A0X LCD Panel */
2134 vid->cfg_gpio = lcd_cfg_gpio;
2135 vid->backlight_on = backlight_on;
2136 vid->lcd_power_on = lcd_power_on;
2137 vid->reset_lcd = reset_lcd;
2138 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2139 vid->enable_ldo = s6d16a0x_enable_ldo;
2141 vid->init_delay = 10000;
2142 vid->power_on_delay = 10000;
2143 vid->reset_delay = 1000;
2146 if (board_is_neptune() && hwrevision(3)) {
2150 vid->vl_width = 480;
2151 vid->vl_height = 800;
2152 vid->vl_clkp = CONFIG_SYS_HIGH;
2153 vid->vl_hsp = CONFIG_SYS_HIGH;
2154 vid->vl_vsp = CONFIG_SYS_HIGH;
2155 vid->vl_dp = CONFIG_SYS_HIGH;
2158 /* disable dual lcd mode. */
2159 vid->dual_lcd_enabled = 0;
2161 /* LD9040 LCD Panel */
2170 vid->cfg_gpio = lcd_cfg_gpio;
2171 vid->backlight_on = NULL;
2172 vid->lcd_power_on = lcd_power_on;
2173 vid->reset_lcd = reset_lcd;
2174 vid->cfg_ldo = ld9040_cfg_ldo;
2175 vid->enable_ldo = ld9040_enable_ldo;
2177 vid->init_delay = 0;
2178 vid->power_on_delay = 30000;
2179 vid->reset_delay = 20000;
2181 if (mach_is_geminus()) {
2185 vid->vl_width = 1024,
2186 vid->vl_height = 600,
2187 vid->vl_clkp = CONFIG_SYS_LOW,
2188 vid->vl_hsp = CONFIG_SYS_HIGH,
2189 vid->vl_vsp = CONFIG_SYS_HIGH,
2190 vid->vl_dp = CONFIG_SYS_LOW,
2201 vid->cfg_gpio = lcd_cfg_gpio;
2202 vid->reset_lcd = reset_lcd;
2203 vid->backlight_on = backlight_on;
2204 vid->lcd_power_on = lcd_power_on;
2210 vid->vl_width = 480,
2211 vid->vl_height = 800,
2212 vid->vl_clkp = CONFIG_SYS_HIGH,
2213 vid->vl_hsp = CONFIG_SYS_LOW,
2214 vid->vl_vsp = CONFIG_SYS_LOW,
2215 vid->vl_dp = CONFIG_SYS_HIGH,
2231 vid->vl_width = 1024,
2232 vid->vl_height = 600,
2233 vid->vl_clkp = CONFIG_SYS_HIGH,
2234 vid->vl_hsp = CONFIG_SYS_HIGH,
2235 vid->vl_vsp = CONFIG_SYS_HIGH,
2236 vid->vl_dp = CONFIG_SYS_LOW,
2239 /* AMS701KA AMOLED Panel. */
2251 static void setup_meminfo(void)
2253 char meminfo[64] = {0, };
2254 int count = 0, size, real;
2256 size = gd->bd->bi_dram[0].size >> 20;
2257 count += sprintf(meminfo + count, "mem=%dM", size);
2259 /* Each Chip Select can't exceed the 256MiB */
2260 size = gd->bd->bi_dram[1].size >> 20;
2261 real = min(size, 256);
2262 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2263 real, (unsigned int)gd->bd->bi_dram[1].start);
2267 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2268 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2271 setenv("meminfo", meminfo);
2274 int misc_init_r(void)
2277 /* It should be located at first */
2280 if (mach_is_aquila() || mach_is_kessler()) {
2281 if (board_is_neptune() && hwrevision(0))
2282 setenv("lcdinfo", "lcd=s6d16a0x");
2283 else if (board_is_neptune() && hwrevision(3))
2284 setenv("lcdinfo", "lcd=ld9040");
2285 else if (board_is_media())
2286 setenv("lcdinfo", "lcd=s6e63m0");
2288 setenv("lcdinfo", "lcd=s6e63m0");
2290 if (mach_is_geminus())
2291 setenv("lcdinfo", "lcd=lms480jc01");
2292 if (mach_is_cypress())
2293 setenv("lcdinfo", "lcd=s6e63m0");
2299 /* Set proper PMIC pins */
2302 /* Check auto burning */
2305 /* To power up I2C2 */
2308 /* Enable T-Flash at Limo Real or Limo Universal */
2311 /* Setup Limo Real board GPIOs */
2312 setup_limo_real_gpios();
2314 /* Setup Media board GPIOs */
2315 setup_media_gpios();
2317 /* To usbdown automatically */
2323 #ifdef CONFIG_S5PC1XXFB
2324 display_device_info();
2327 setup_power_down_mode_registers();
2329 /* check max17040 */
2339 int board_init(void)
2341 /* Set Initial global variables */
2342 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2344 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2345 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2349 * set reserved memory region for framebuffer.
2351 * this region wouldn't be rewrited by kernel so
2352 * could avoid nosie screen filled by garbages
2353 * after hibernation resume has been completed.
2355 gd->fb_base = CONFIG_FB_RESERVED_MEM;
2358 /* Check H/W Revision */
2359 check_hw_revision();
2366 unsigned int base, memconfig0, size;
2367 unsigned int memconfig1, sz = 0;
2369 if (cpu_is_s5pc100()) {
2370 /* In mem setup, we swap the bank. So below size is correct */
2371 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2372 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2373 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2376 /* In S5PC110, we can't swap the DMC0/1 */
2377 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2378 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2380 base = S5PC110_DMC1_BASE;
2381 /* DMC configuration */
2382 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2383 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2385 size = (memconfig0 >> 16) & 0xFF;
2386 size = ((unsigned char) ~size) + 1;
2389 * (0x07 + 1) * 16 = 128 MiB
2390 * (0x0f + 1) * 16 = 256 MiB
2395 * Aquila Rev0.5 4G3G1G
2396 * Aquila Rev0.8 4G3G1G
2397 * Aquila Rev0.9 4G3G1G
2398 * Neptune Rev 0.2 4G3G1G
2400 if (mach_is_aquila() || mach_is_kessler()) {
2401 if ((!board_is_neptune() && (hwrevision(5) ||
2402 hwrevision(8) || hwrevision(9))) ||
2403 (board_is_neptune() && hwrevision(2))) {
2404 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2406 sz = (memconfig1 >> 16) & 0xFF;
2407 sz = ((unsigned char) ~sz) + 1;
2410 if (mach_is_kessler() && board_is_s1())
2415 * bi_dram[1].size contains all DMC1 memory size
2417 gd->bd->bi_dram[1].size = (size + sz) << 20;
2422 /* Used for sleep test */
2423 static unsigned char saved_val[4][2];
2424 void board_sleep_init_late(void)
2426 /* CODEC_LDO_EN: GPF3[4] */
2427 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2428 /* CODEC_XTAL_EN: GPH3[2] */
2429 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2431 /* MMC T_FLASH off */
2432 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2434 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2435 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2436 /* MHL_ON for REV02 or higher */
2437 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2440 void board_sleep_init(void)
2443 unsigned char val[2];
2446 if (max8998_probe())
2449 if (mach_is_kessler()) {
2451 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2452 saved_val[0][0] = val[0];
2453 saved_val[0][1] = val[1];
2454 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2455 (1 << 1) | (1 << 0));
2456 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2457 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2460 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2461 saved_val[1][0] = val[0];
2462 saved_val[1][1] = val[1];
2463 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2464 (1 << 2) | (1 << 1) | (1 << 0));
2466 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2467 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2470 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2471 saved_val[2][0] = val[0];
2472 saved_val[2][1] = val[1];
2473 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2474 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2475 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2478 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2479 saved_val[3][0] = val[0];
2480 saved_val[3][1] = val[1];
2481 val[0] &= ~((1 << 6) | (1 << 4));
2482 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2483 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2485 printf("Turned off regulators with Kessler setting."
2486 " Preparing to sleep. [%s:%d]\n",
2487 __FILE__, __LINE__);
2488 } else { /* Default */
2490 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2491 saved_val[0][0] = val[0];
2492 saved_val[0][1] = val[1];
2493 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2494 (1 << 1) | (1 << 0));
2495 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2496 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2499 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2500 saved_val[1][0] = val[0];
2501 saved_val[1][1] = val[1];
2502 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2503 (1 << 2) | (1 << 1) | (1 << 0));
2505 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2506 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2509 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2510 saved_val[2][0] = val[0];
2511 saved_val[2][1] = val[1];
2512 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2513 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2514 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2517 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2518 saved_val[3][0] = val[0];
2519 saved_val[3][1] = val[1];
2520 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2521 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2522 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2524 printf("Turned off regulators with default(Aquila) setting."
2525 " Preparing to sleep. [%s:%d]\n",
2526 __FILE__, __LINE__);
2530 void board_sleep_resume(void)
2533 unsigned char val[2];
2538 if (max8998_probe())
2542 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2543 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2545 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2546 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2548 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2549 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2551 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2552 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2553 puts("Waked up.\n");
2555 /* check max17040 */
2562 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2564 static int s5pc1xx_phy_control(int on)
2568 if (on && !status) {
2569 #ifdef CONFIG_CMD_PMIC
2570 run_command("pmic ldo 3 on", 0);
2573 if (board_is_limo_universal() ||
2574 board_is_limo_real() ||
2576 /* check usb path */
2577 if (board_is_limo_real() && !hwrevision(6))
2581 if (mach_is_tickertape())
2582 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2583 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2585 /* USB Path to AP */
2586 micro_usb_switch(0);
2588 } else if (!on && status) {
2589 #ifdef CONFIG_CMD_PMIC
2590 run_command("pmic ldo 3 off", 0);
2599 struct s3c_plat_otg_data s5pc110_otg_data = {
2600 .phy_control = s5pc1xx_phy_control,
2601 .regs_phy = S5PC110_PHY_BASE,
2602 .regs_otg = S5PC110_OTG_BASE,
2605 int board_eth_init(bd_t *bis)
2609 if (cpu_is_s5pc100())
2612 s3c_udc_probe(&s5pc110_otg_data);
2613 if (usb_eth_initialize(bis) >= 0)
2619 #ifdef CONFIG_CMD_USBDOWN
2620 int usb_board_init(void)
2622 #ifdef CONFIG_CMD_PMIC
2623 run_command("pmic ldo 3 on", 0);
2626 if (cpu_is_s5pc100()) {
2627 #ifdef CONFIG_HARD_I2C
2628 uchar val[2] = {0,};
2631 if (i2c_read(0x66, 0, 1, val, 2)) {
2632 puts("i2c_read error\n");
2639 if (i2c_write(0x66, 0, 1, val, 2)) {
2640 puts("i2c_write error\n");
2643 i2c_read(0x66, 0, 1, val, 2);
2649 if (board_is_limo_universal() ||
2650 board_is_limo_real() ||
2652 /* check usb path */
2653 if (board_is_limo_real() && !hwrevision(6))
2657 if (mach_is_tickertape())
2658 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2659 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2661 /* USB Path to AP */
2662 micro_usb_switch(0);
2668 #ifdef CONFIG_GENERIC_MMC
2669 int s5p_no_mmc_support(void)
2671 if (mach_is_wmg160())
2676 int board_mmc_init(bd_t *bis)
2680 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2683 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2684 if (mach_is_kessler())
2685 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2687 if (mach_is_wmg160())
2690 /* MMC0 Clock source = SCLKMPLL */
2691 reg = readl(&clk->src4);
2694 writel(reg, &clk->src4);
2696 reg = readl(&clk->div4);
2699 /* set div value near 50MHz */
2700 clock = get_pll_clk(MPLL) / 1000000;
2701 for (i = 0; i < 0xf; i++) {
2702 if ((clock / (i + 1)) <= 50) {
2708 writel(reg, &clk->div4);
2714 * GPG0[2] SD_0_CDn -> Not used
2715 * GPG0[3:6] SD_0_DATA[0:3]
2717 for (i = 0; i < 7; i++) {
2720 /* GPG0[0:6] special function 2 */
2721 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2722 /* GPG0[0:6] pull disable */
2723 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2724 /* GPG0[0:6] drv 4x */
2725 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2728 if (mach_is_geminus()) {
2729 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2730 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2733 return s5pc1xx_mmc_init(0);
2737 #ifdef CONFIG_CMD_PMIC
2738 static int pmic_status(void)
2740 unsigned char addr, val[2];
2745 if (max8998_probe())
2749 i2c_read(addr, reg, 1, val, 1);
2750 for (i = 7; i >= 4; i--)
2751 printf("BUCK%d %s\n", 7 - i + 1,
2752 val[0] & (1 << i) ? "on" : "off");
2754 printf("LDO%d %s\n", 5 - i,
2755 val[0] & (1 << i) ? "on" : "off");
2757 i2c_read(addr, reg, 1, val, 1);
2758 for (i = 7; i >= 0; i--)
2759 printf("LDO%d %s\n", 7 - i + 6,
2760 val[0] & (1 << i) ? "on" : "off");
2762 i2c_read(addr, reg, 1, val, 1);
2763 for (i = 7; i >= 4; i--)
2764 printf("LDO%d %s\n", 7 - i + 14,
2765 val[0] & (1 << i) ? "on" : "off");
2768 i2c_read(addr, reg, 1, val, 1);
2769 for (i = 7; i >= 6; i--)
2770 printf("SAFEOUT%d %s\n", 7 - i + 1,
2771 val[0] & (1 << i) ? "on" : "off");
2775 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2777 unsigned char addr, val[2];
2778 unsigned int reg, shift;
2786 } else if (ldo <= 13) {
2789 } else if (ldo <= 17) {
2791 shift = 17 - ldo + 4;
2798 shift = 4 - buck + 4;
2799 } else if (safeout) {
2803 shift = 8 - safeout;
2809 if (max8998_probe())
2812 i2c_read(addr, reg, 1, val, 1);
2814 val[0] |= (1 << shift);
2816 val[0] &= ~(1 << shift);
2817 i2c_write(addr, reg, 1, val, 1);
2818 i2c_read(addr, reg, 1, val, 1);
2821 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2822 val[0] & (1 << shift) ? "on" : "off");
2824 printf("buck %d value 0x%x, %s\n", buck, val[0],
2825 val[0] & (1 << shift) ? "on" : "off");
2827 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2828 val[0] & (1 << shift) ? "on" : "off");
2833 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2835 int buck = 0, ldo = 0, safeout = 0, on = -1;
2839 if (strncmp(argv[1], "status", 6) == 0)
2840 return pmic_status();
2843 if (strncmp(argv[1], "ldo", 3) == 0)
2844 ldo = simple_strtoul(argv[2], NULL, 10);
2845 else if (strncmp(argv[1], "buck", 4) == 0)
2846 buck = simple_strtoul(argv[2], NULL, 10);
2847 else if (strncmp(argv[1], "safeout", 7) == 0)
2848 safeout = simple_strtoul(argv[2], NULL, 10);
2852 if (strncmp(argv[3], "on", 2) == 0)
2854 else if (strncmp(argv[3], "off", 3) == 0)
2859 return pmic_ldo_control(buck, ldo, safeout, on);
2870 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2871 "PMIC LDO & BUCK control",
2872 "status - Display PMIC LDO & BUCK status\n"
2873 "pmic ldo num on/off - Turn on/off the LDO\n"
2874 "pmic buck num on/off - Turn on/off the BUCK\n"
2875 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2879 #ifdef CONFIG_CMD_DEVICE_POWER
2880 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2884 if (strncmp(argv[1], "cp", 2) == 0) {
2885 micro_usb_switch(1);
2886 pmic_ldo_control(0, 0, 2, 1);
2887 setenv("usb", "cp");
2888 } else if (strncmp(argv[1], "ap", 2) == 0) {
2889 micro_usb_switch(0);
2890 pmic_ldo_control(0, 0, 2, 0);
2891 setenv("usb", "ap");
2901 printf("USB Path is set to %s\n", getenv("usb"));
2907 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2909 "cp - switch to CP\n"
2910 "microusb ap - switch to AP\n"