2 * Copyright (C) 2009 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 * Minkyu Kang <mk7.kang@samsung.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/arch/clk.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/gpio.h>
32 #include <asm/arch/keypad.h>
33 #include <asm/arch/mmc.h>
34 #include <asm/arch/power.h>
35 #include <asm/arch/mem.h>
36 #include <asm/arch/hs_otg.h>
37 #include <asm/arch/regs-otg.h>
38 #include <asm/arch/rtc.h>
39 #include <asm/arch/adc.h>
40 #include <asm/errno.h>
43 #include <bmp_layout.h>
45 #include "animation_frames.h"
46 #include "gpio_setting.h"
48 DECLARE_GLOBAL_DATA_PTR;
50 #define C100_MACH_START 3000
51 #define C110_MACH_START 3100
53 static unsigned int board_rev;
54 static unsigned int battery_soc;
55 static struct s5pc110_gpio *s5pc110_gpio;
72 static struct i2c_gpio_bus_data i2c_2 = {
82 static struct i2c_gpio_bus_data i2c_gpio3 = {
92 static struct i2c_gpio_bus_data i2c_pmic = {
102 static struct i2c_gpio_bus_data i2c_gpio5 = {
112 static struct i2c_gpio_bus_data i2c_gpio6 = {
118 * i2c gpio7 - kessler
122 static struct i2c_gpio_bus_data i2c_gpio7 = {
128 * i2c gpio7 - cypress
132 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
142 static struct i2c_gpio_bus_data i2c_gpio10 = {
148 static struct i2c_gpio_bus i2c_gpio[] = {
166 u32 get_board_rev(void)
171 static int hwrevision(int rev)
173 return (board_rev & 0xf) == rev;
180 MACH_P1P2, /* Don't remove it */
191 #define SPLIT_SCREEN_FEATURE 0x100
193 /* board is MACH_AQUILA and board is like below. */
194 #define J1_B2_BOARD 0x0200
195 #define LIMO_UNIVERSAL_BOARD 0x0400
196 #define LIMO_REAL_BOARD 0x0800
197 #define MEDIA_BOARD 0x1000
198 #define BAMBOO_BOARD 0x2000
200 /* board is MACH_KESSLER and board is like below */
201 #define S1_BOARD 0x1000
202 #define KESSLER_BOARD 0x4000
203 #define NEPTUNE_BOARD 0x8000
205 #define BOARD_MASK 0xFF00
207 static int c110_machine_id(void)
209 return gd->bd->bi_arch_number - C110_MACH_START;
212 static int mach_is_aquila(void)
214 return gd->bd->bi_arch_number == MACH_TYPE_AQUILA;
217 static int mach_is_tickertape(void)
219 return c110_machine_id() == MACH_TICKERTAPE;
222 static int mach_is_geminus(void)
224 return c110_machine_id() == MACH_GEMINUS;
227 static int mach_is_cypress(void)
229 return c110_machine_id() == MACH_CYPRESS;
232 static int board_is_limo_universal(void)
234 return mach_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
237 static int board_is_limo_real(void)
239 return mach_is_aquila() && (board_rev & LIMO_REAL_BOARD);
242 static int board_is_media(void)
244 return mach_is_aquila() && (board_rev & MEDIA_BOARD);
247 static int board_is_j1b2(void)
249 return mach_is_aquila() && (board_rev & J1_B2_BOARD);
253 static int mach_is_kessler(void)
255 return gd->bd->bi_arch_number == MACH_KESSLER;
258 static int board_is_neptune(void)
260 return mach_is_kessler() && (board_rev & NEPTUNE_BOARD);
264 static int mach_is_wmg160(void)
266 return c110_machine_id() == MACH_WMG160;
269 static void check_battery(int mode);
270 static void check_micro_usb(int intr);
272 void i2c_init_board(void)
274 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
277 if (cpu_is_s5pc100())
280 num_bus = ARRAY_SIZE(i2c_gpio);
282 if (mach_is_aquila()) {
283 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
284 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
285 } else if (mach_is_kessler()) {
286 i2c_gpio[I2C_GPIO7].bus->gpio_base =
287 (unsigned int)&gpio->gpio_mp0_5;
288 } else if (mach_is_cypress()) {
289 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
290 i2c_gpio[I2C_GPIO7].bus->gpio_base =
291 (unsigned int)&gpio->gpio_mp0_5;
293 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
296 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
297 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
298 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
299 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
300 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
302 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
304 /* Reset on fsa9480 early */
306 /* Reset on max17040 early */
307 if (battery_soc == 0)
311 #ifdef CONFIG_MISC_INIT_R
312 #define DEV_INFO_LEN 256
313 static char device_info[DEV_INFO_LEN];
314 static int display_info;
316 static void empty_device_info_buffer(void)
318 memset(device_info, 0x0, DEV_INFO_LEN);
321 static void dprintf(const char *fmt, ...)
328 i = vsprintf(buf, fmt, args);
333 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
334 puts("Flushing device info...\n");
336 empty_device_info_buffer();
338 strncat(device_info, buf, 127);
342 #ifdef CONFIG_S5PC1XXFB
343 static void display_device_info(void)
350 set_font_color(FONT_WHITE);
351 fb_printf(device_info);
354 memset(device_info, 0x0, DEV_INFO_LEN);
356 udelay(5 * 1000 * 1000);
360 static const char *board_name[] = {
364 "P1P2", /* Don't remove it */
377 static char feature_buffer[32];
379 static char *display_features(int board, int board_rev)
382 char *buf = feature_buffer;
385 if (board == MACH_TYPE_AQUILA) {
386 if (board_rev & SPLIT_SCREEN_FEATURE)
387 name = "SplitScreen";
388 if (board_rev & J1_B2_BOARD)
390 /* Limo Real or Universal */
391 if (board_rev & LIMO_REAL_BOARD)
393 else if (board_rev & LIMO_UNIVERSAL_BOARD)
394 name = "Limo Universal";
395 if (board_rev & MEDIA_BOARD)
397 if (board_rev & BAMBOO_BOARD)
399 } else if (board == MACH_KESSLER) {
400 if (board_rev & NEPTUNE_BOARD)
402 if (board_rev & S1_BOARD)
406 count += sprintf(buf + count, " - %s", name);
411 static char *get_board_name(int board)
413 if (board == MACH_TYPE_AQUILA)
415 else if (board == MACH_KESSLER)
417 else if (board == MACH_WMG160)
419 return (char *) board_name[board];
422 static void check_board_revision(int board, int rev)
424 if (board == MACH_TYPE_AQUILA) {
425 /* Limo Real or Universal */
426 if (rev & LIMO_UNIVERSAL_BOARD)
427 board_rev &= ~J1_B2_BOARD;
428 if (rev & LIMO_REAL_BOARD)
429 board_rev &= ~(J1_B2_BOARD |
430 LIMO_UNIVERSAL_BOARD);
431 if (rev & MEDIA_BOARD)
432 board_rev &= ~(J1_B2_BOARD |
433 LIMO_UNIVERSAL_BOARD);
434 if (rev & BAMBOO_BOARD)
435 board_rev &= ~(J1_B2_BOARD |
436 LIMO_UNIVERSAL_BOARD |
439 } else if (board == MACH_KESSLER) {
440 if (rev & KESSLER_BOARD)
441 board_rev &= ~(J1_B2_BOARD |
442 LIMO_UNIVERSAL_BOARD);
443 if (rev & NEPTUNE_BOARD)
444 board_rev &= ~(J1_B2_BOARD |
445 LIMO_UNIVERSAL_BOARD);
447 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
450 board_rev &= ~BOARD_MASK;
454 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
458 gpio_direction_input(bank, 2);
459 gpio_direction_input(bank, 3);
460 gpio_direction_input(bank, 4);
461 gpio_direction_input(bank, hwrev3);
463 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
464 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
465 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
466 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
468 rev = gpio_get_value(bank, 2);
469 rev |= (gpio_get_value(bank, 3) << 1);
470 rev |= (gpio_get_value(bank, 4) << 2);
471 rev |= (gpio_get_value(bank, hwrev3) << 3);
476 static void check_hw_revision(void)
478 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
480 if (cpu_is_s5pc100()) {
481 struct s5pc100_gpio *gpio =
482 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
484 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
486 /* C100 TickerTape */
488 board = MACH_TICKERTAPE;
490 struct s5pc110_gpio *gpio =
491 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
497 * Note Check 'Aquila' board first
501 * LRA: Limo Real Aquila
502 * LUA: Limo Universal Aquila
507 * ADDR = 0xE0200000 + OFF
509 * OFF Universal BB LRA LUA OA TT SS CYP
510 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
511 * J2: 0x0284 0x01 0x10 0x00
512 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
513 * H3: 0x0C64 0x03 0x07 0x0F
514 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
515 * I: 0x0224 0x02 0x00 0x08
516 * MP03: 0x0324 0x9x 0xbx 0x9x
517 * MP05: 0x0364 0x80 0x88
521 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
522 board = MACH_TYPE_AQUILA;
523 board_rev |= J1_B2_BOARD;
525 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
526 gpio_direction_input(&gpio->gpio_j2, 6);
529 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
530 board_rev |= LIMO_UNIVERSAL_BOARD;
532 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
533 board_rev |= LIMO_REAL_BOARD;
535 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
536 board_rev |= MEDIA_BOARD;
538 /* set gpio to default value. */
539 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
540 gpio_direction_output(&gpio->gpio_j2, 6, 0);
543 /* Workaround: C110 Aquila Rev0.6 */
544 if (board_rev == 6) {
545 board = MACH_TYPE_AQUILA;
546 board_rev |= LIMO_REAL_BOARD;
549 /* C110 Aquila Bamboo */
550 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
551 board = MACH_TYPE_AQUILA;
552 board_rev |= BAMBOO_BOARD;
555 /* C110 TickerTape */
556 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
557 gpio_get_value(&gpio->gpio_d1, 1) == 0)
558 board = MACH_TICKERTAPE;
560 /* WMG160 - GPH3[0:4] = 0x00 */
561 if (board == MACH_TICKERTAPE) {
564 for (i = 0; i < 4; i++) {
565 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
576 /* C110 Geminus for rev0.0 */
577 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
578 gpio_direction_input(&gpio->gpio_j1, 2);
579 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
580 board = MACH_GEMINUS;
581 if ((board_rev & ~BOARD_MASK) == 3)
584 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
585 gpio_direction_output(&gpio->gpio_j1, 2, 0);
587 /* C110 Geminus for rev0.1 ~ */
588 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
589 gpio_direction_input(&gpio->gpio_j0, 6);
590 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
591 board = MACH_GEMINUS;
594 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
596 /* Kessler MP0_5[6] == 1 */
597 gpio_direction_input(&gpio->gpio_mp0_5, 6);
598 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
599 /* Cypress: Do this for cypress */
600 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
601 gpio_direction_input(&gpio->gpio_j2, 2);
602 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
603 board = MACH_CYPRESS;
604 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
606 board = MACH_KESSLER;
607 board_rev |= KESSLER_BOARD;
609 /* Neptune MP0_5[4] == 1 */
610 gpio_direction_input(&gpio->gpio_mp0_5, 4);
611 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
612 board_rev &= ~KESSLER_BOARD;
613 board_rev |= NEPTUNE_BOARD;
616 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
619 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
620 /* Kessler S1 board detection */
621 if (board == MACH_TICKERTAPE) {
622 board = MACH_KESSLER;
623 board_rev |= S1_BOARD;
628 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
632 if (board < MACH_PSEUDO_END) {
633 if (cpu_is_s5pc110())
634 gd->bd->bi_arch_number = C110_MACH_START + board;
636 gd->bd->bi_arch_number = C100_MACH_START + board;
638 gd->bd->bi_arch_number = board;
641 /* Architecture Common settings */
642 if (cpu_is_s5pc110()) {
643 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
645 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
647 setenv("updatek", "onenand erase 0x60000 0x300000; "
648 "onenand write 0x31008000 0x60000 0x300000");
652 static void show_hw_revision(void)
657 * Workaround for Rev 0.3 + CP Ver ES 3.1
660 if (board_is_limo_real()) {
662 /* default is Rev 0.4 */
668 if (mach_is_kessler() || mach_is_aquila())
669 board = gd->bd->bi_arch_number;
670 else if (cpu_is_s5pc110())
671 board = gd->bd->bi_arch_number - C110_MACH_START;
673 board = gd->bd->bi_arch_number - C100_MACH_START;
675 check_board_revision(board, board_rev);
677 /* Set CPU Revision */
678 if (mach_is_aquila()) {
679 if (board_is_limo_real()) {
680 if ((board_rev & 0xf) < 8)
681 s5pc1xx_set_cpu_rev(0);
683 } else if (mach_is_kessler()) {
684 s5pc1xx_set_cpu_rev(1);
685 } else if (mach_is_geminus()) {
686 if ((board_rev & 0xf) < 1)
687 s5pc1xx_set_cpu_rev(0);
688 } else if (mach_is_cypress()) {
689 s5pc1xx_set_cpu_rev(1);
691 s5pc1xx_set_cpu_rev(0);
694 if (cpu_is_s5pc110())
695 writel(0xc1100000 | 0xffff & s5pc1xx_get_cpu_rev(),
698 empty_device_info_buffer();
699 dprintf("HW Revision:\t%x (%s%s) %s\n",
700 board_rev, get_board_name(board),
701 display_features(board, board_rev),
702 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
705 static void check_auto_burn(void)
707 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
708 unsigned int count = 0;
711 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
712 printf("Auto burning bootloader\n");
713 count += sprintf(buf + count, "run updateb; ");
715 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
716 printf("Auto burning kernel\n");
717 count += sprintf(buf + count, "run updatek; ");
721 count += sprintf(buf + count, "reset");
722 setenv("bootcmd", buf);
725 /* Clear the magic value */
726 writel(0xa5a55a5a, magic_base);
727 writel(0xa5a55a5a, magic_base + 0x4);
730 static void pmic_pin_init(void)
732 unsigned int reg, value;
734 if (cpu_is_s5pc100())
737 /* AP_PS_HOLD: XEINT_0: GPH0[0]
738 * Note: Don't use GPIO PS_HOLD it doesn't work
740 reg = S5PC110_PS_HOLD_CONTROL;
742 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
743 S5PC110_PS_HOLD_DATA_HIGH |
744 S5PC110_PS_HOLD_OUT_EN;
747 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
748 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
749 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
752 static void enable_ldos(void)
754 if (cpu_is_s5pc100())
757 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
758 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
761 static void enable_t_flash(void)
763 if (!(board_is_limo_universal() || board_is_limo_real()))
766 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
767 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
770 static void setup_limo_real_gpios(void)
772 if (!board_is_limo_real())
776 * Note: Please write GPIO alphabet order
778 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
779 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
782 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
783 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
785 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
786 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
788 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
789 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
790 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
793 static void setup_media_gpios(void)
795 if (!board_is_media())
799 * Note: Please write GPIO alphabet order
801 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
802 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
804 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
805 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
806 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
809 #define KBR3 (1 << 3)
810 #define KBR2 (1 << 2)
811 #define KBR1 (1 << 1)
812 #define KBR0 (1 << 0)
814 static void check_keypad(void)
816 unsigned int reg, value;
817 unsigned int col_num, row_num;
818 unsigned int col_mask;
819 unsigned int col_mask_shift;
820 unsigned int row_state[4];
822 unsigned int auto_download = 0;
824 if (mach_is_wmg160())
827 if (cpu_is_s5pc100()) {
828 struct s5pc100_gpio *gpio =
829 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
834 /* Set GPH2[2:0] to KP_COL[2:0] */
835 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
836 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
837 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
839 /* Set GPH3[2:0] to KP_ROW[2:0] */
840 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
841 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
842 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
844 reg = S5PC100_KEYPAD_BASE;
845 col_mask = S5PC1XX_KEYIFCOL_MASK;
848 if (board_is_limo_real() || board_is_limo_universal()) {
856 for (i = 0; i < row_num; i++) {
857 /* Set GPH3[3:0] to KP_ROW[3:0] */
858 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
859 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
862 for (i = 0; i < col_num; i++)
863 /* Set GPH2[3:0] to KP_COL[3:0] */
864 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
866 reg = S5PC110_KEYPAD_BASE;
867 col_mask = S5PC110_KEYIFCOLEN_MASK;
871 /* KEYIFCOL reg clear */
872 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
875 for (i = 0; i < col_num; i++) {
877 value &= ~(1 << i) << col_mask_shift;
879 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
882 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
883 row_state[i] = ~value & ((1 << row_num) - 1);
885 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
888 /* KEYIFCOL reg clear */
889 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
891 if (mach_is_aquila() || mach_is_kessler()) {
893 if (row_state[1] & 0x2)
895 if (board_is_neptune()) {
896 /* home & volume down */
897 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
900 /* cam full shot & volume down */
901 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
904 } else if (mach_is_geminus())
905 /* volume down & home */
906 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
910 setenv("bootcmd", "usbdown");
913 static void check_battery(int mode)
915 unsigned char val[2];
916 unsigned char addr = 0x36; /* max17040 fuel gauge */
918 i2c_set_bus_num(I2C_GPIO3);
920 if (mach_is_aquila()) {
923 } else if (mach_is_kessler()) {
924 i2c_set_bus_num(I2C_GPIO7);
925 } else if (mach_is_cypress()) {
926 i2c_set_bus_num(I2C_GPIO7);
927 } else if (mach_is_geminus()) {
929 i2c_set_bus_num(I2C_GPIO7);
933 if (i2c_probe(addr)) {
934 printf("Can't found max17040 fuel gauge\n");
938 /* mode 0: check mode / 1: enable mode */
942 i2c_write(addr, 0xfe, 1, val, 2);
944 i2c_read(addr, 0x04, 1, val, 1);
945 dprintf("battery:\t%d%%\n", val[0]);
946 battery_soc = val[0];
950 static void check_mhl(void)
952 unsigned char val[2];
953 unsigned char addr = 0x39; /* SIL9230 */
955 /* MHL Power enable */
956 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
957 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
959 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
960 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
962 /* 10ms required after reset */
966 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
968 i2c_set_bus_num(I2C_GPIO5);
971 if (i2c_probe(addr)) {
972 printf("Can't found MHL Chip\n");
978 * set to Normal operation
981 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
982 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
987 * 00 = MHL termination ON
988 * 11 = MHL termination OFF
991 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
992 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
995 static int max8998_probe(void)
997 unsigned char addr = 0xCC >> 1;
999 i2c_set_bus_num(I2C_PMIC);
1001 if (i2c_probe(addr)) {
1002 printf("Can't found max8998\n");
1009 #define CHARGER_ANIMATION_FRAME 6
1010 static void max8998_clear_interrupt(void)
1012 unsigned char addr, val[2];
1015 if (max8998_probe())
1018 i2c_read(addr, 0x00, 1, val, 1);
1019 i2c_read(addr, 0x01, 1, val, 1);
1020 i2c_read(addr, 0x02, 1, val, 1);
1021 i2c_read(addr, 0x03, 1, val, 1);
1024 static int max8998_power_key(void)
1026 unsigned char addr, val[2];
1029 if (max8998_probe())
1032 /* Accessing IRQ1 register */
1033 i2c_read(addr, 0x00, 1, val, 1);
1034 if (val[0] & (1 << 6))
1040 static int max8998_has_ext_power_source(void)
1042 unsigned char addr, val[2];
1045 if (max8998_probe())
1048 /* Accessing STATUS2 register */
1049 i2c_read(addr, 0x09, 1, val, 1);
1050 if (val[0] & (1 << 5))
1056 struct thermister_stat {
1061 static struct thermister_stat adc_to_temperature_data[] = {
1062 { .centigrade = -20, .adc = 1856, },
1063 { .centigrade = -15, .adc = 1799, },
1064 { .centigrade = -10, .adc = 1730, },
1065 { .centigrade = -5, .adc = 1649, },
1066 { .centigrade = 0, .adc = 1556, },
1067 { .centigrade = 5, .adc = 1454, },
1068 { .centigrade = 10, .adc = 1343, },
1069 { .centigrade = 15, .adc = 1227, },
1070 { .centigrade = 20, .adc = 1109, },
1071 { .centigrade = 25, .adc = 992, },
1072 { .centigrade = 30, .adc = 880, },
1073 { .centigrade = 35, .adc = 773, },
1074 { .centigrade = 40, .adc = 675, },
1075 { .centigrade = 45, .adc = 586, },
1076 { .centigrade = 50, .adc = 507, },
1077 { .centigrade = 55, .adc = 436, },
1078 { .centigrade = 58, .adc = 399, },
1079 { .centigrade = 63, .adc = 343, },
1080 { .centigrade = 65, .adc = 322, },
1084 #define USHRT_MAX 0xFFFFU
1086 static int adc_to_temperature_centigrade(unsigned short adc)
1090 /* low_*: Greatest Lower Bound,
1091 * * * * high_*: Smallest Upper Bound */
1092 int low_temp = 0, high_temp = 0;
1093 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1094 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1095 if (adc_to_temperature_data[i].adc <= adc &&
1096 adc_to_temperature_data[i].adc >= low_adc) {
1097 low_temp = adc_to_temperature_data[i].centigrade;
1098 low_adc = adc_to_temperature_data[i].adc;
1100 if (adc_to_temperature_data[i].adc >= adc &&
1101 adc_to_temperature_data[i].adc <= high_adc) {
1102 high_temp = adc_to_temperature_data[i].centigrade;
1103 high_adc = adc_to_temperature_data[i].adc;
1107 /* Linear approximation between cloest low and high,
1108 * which is the weighted average of the two. */
1110 /* The following equation is correct only when the two are different */
1111 if (low_adc == high_adc)
1113 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1114 return 20; /* The room temperature */
1117 if (high_adc == USHRT_MAX)
1120 approximation = low_temp * (adc - low_adc) +
1121 high_temp * (high_adc - adc);
1122 approximation /= high_adc - low_adc;
1124 return approximation;
1127 static unsigned short get_adc_value(int channel)
1129 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1130 unsigned short ret = 0;
1134 unsigned int loop = 0;
1136 if (mach_is_kessler())
1138 else if (mach_is_geminus())
1140 else if (mach_is_wmg160())
1142 else if (mach_is_cypress())
1144 else if (mach_is_tickertape())
1146 else if (mach_is_aquila())
1149 else if (mach_is_p1p2())
1153 sprintf(buf, "pmic ldo %d on", ldonum);
1154 run_command(buf, 0);
1156 writel(channel & 0xF, &adc->adcmux);
1157 writel((1 << 14) | (49 << 6), &adc->adccon);
1158 writel(1000 & 0xffff, &adc->adcdly);
1159 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1161 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1166 reg = readl(&adc->adccon);
1167 } while (!(reg & (1 << 15)) && (loop++ < 1000));
1169 ret = readl(&adc->adcdat0) & 0xFFF;
1170 sprintf(buf, "pmic ldo %d off", ldonum);
1171 run_command(buf, 0);
1176 static int adc_get_average_ambient_temperature(void)
1178 if (mach_is_kessler()) {
1179 unsigned short min = USHRT_MAX;
1180 unsigned short max = 0;
1181 unsigned int sum = 0;
1182 unsigned int measured = 0;
1185 for (i = 0; i < 7; i++) {
1186 unsigned short measurement = get_adc_value(6);
1189 if (min > measurement)
1191 if (max < measurement)
1194 if (measured >= 3) {
1200 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1201 adc_to_temperature_centigrade(sum), sum);
1202 return adc_to_temperature_centigrade(sum);
1205 return 20; /* 20 Centigrade */
1208 enum temperature_level {
1216 static enum temperature_level temperature_check(void)
1218 int temp = adc_get_average_ambient_temperature();
1220 return _TEMP_TOO_LOW;
1222 return _TEMP_OK_LOW;
1224 return _TEMP_TOO_HIGH;
1226 return _TEMP_OK_HIGH;
1230 extern void lcd_display_clear(void);
1231 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1233 static void charger_en(int enable)
1239 unsigned char addr = 0xCC >> 1; /* max8998 */
1240 unsigned char val[2];
1242 if (max8998_probe())
1246 printf("Disable the charger.\n");
1247 i2c_read(addr, 0x0D, 1, val, 1);
1250 i2c_write(addr, 0x0D, 1, val, 1);
1252 i2c_read(addr, 0x0C, 1, val, 1);
1253 val[0] &= ~(0x7 << 0);
1254 val[0] &= ~(0x7 << 5);
1255 if (enable == 600) {
1256 val[0] |= 5; /* 600mA */
1257 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1258 } else { /* Assume 475 mA */
1260 val[0] |= 2; /* 475mA */
1261 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1263 i2c_write(addr, 0x0C, 1, val, 1);
1265 i2c_read(addr, 0x0D, 1, val, 1);
1267 i2c_write(addr, 0x0D, 1, val, 1);
1268 printf("Enable the charger @ %dmA\n", enable);
1272 void lcd_power_on(unsigned int onoff);
1273 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1274 extern int drv_lcd_init_resume (void);
1276 static void into_charge_mode(void)
1282 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1283 unsigned int reg, wakeup_stat;
1284 int charger_speed = 600;
1286 max8998_clear_interrupt();
1288 printf("Charge Mode\n");
1289 charger_en(charger_speed);
1291 #ifdef CONFIG_S5PC1XXFB
1294 /* TODO: write the image-text for the charger */
1296 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1297 if (level >= CHARGER_ANIMATION_FRAME)
1298 level = CHARGER_ANIMATION_FRAME - 1;
1300 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1301 bmp_addr[i] = (ulong)battery_charging_animation[i];
1303 lcd_display_clear();
1304 for (i = 0; i < 3; i++) {
1305 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1308 bmp = gunzip_bmp(bmp_addr[j], &len);
1309 lcd_display_bitmap((ulong)bmp, 140, 202);
1312 for (k = 0; k < 10; k++) {
1313 if (max8998_power_key()) {
1314 lcd_display_clear();
1315 goto restore_screen;
1316 } else if (!max8998_has_ext_power_source()) {
1317 lcd_display_clear();
1318 goto restore_screen;
1327 /* Disable the display to prevent flickering */
1328 /* TODO: how to reenable the display later? */
1333 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1334 unsigned int org, org_ip3;
1335 enum temperature_level previous_state = _TEMP_OK;
1337 empty_device_info_buffer();
1338 if (max8998_power_key())
1340 else if (!max8998_has_ext_power_source())
1343 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1344 org_ip3 = readl(0xE010046C);
1345 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1347 reg = org = readl(&rtc->rtccon);
1349 writel(reg, &rtc->rtccon);
1351 reg = readl(&rtc->rtccon);
1352 writel(reg | (1 << 3), &rtc->rtccon);
1354 writel(reg & ~(1 << 3), &rtc->rtccon);
1357 reg = readl(&rtc->rtccon);
1358 reg &= ~((1 << 8) | (0xF << 4));
1359 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1360 writel(reg, &rtc->rtccon);
1362 reg = 15 * 4 - 1; /* 15 sec */
1363 writel(reg, &rtc->ticcnt);
1365 /* EVT0: sleep 1, EVT1: sleep */
1366 if (cpu_is_s5pc110()) {
1367 char *name = "dummy";
1368 char *usage = "N/A";
1375 if (s5pc1xx_get_cpu_rev() == 0) {
1376 char *argv[] = {"1", "1"};
1377 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1379 char *argv[] = {"0", "0"};
1380 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1383 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1387 /* Check TEMP HIGH/LOW */
1388 switch (temperature_check()) {
1390 charger_en(charger_speed);
1391 previous_state = _TEMP_OK;
1395 previous_state = _TEMP_TOO_LOW;
1397 case _TEMP_TOO_HIGH:
1399 previous_state = _TEMP_TOO_HIGH;
1402 if (previous_state == _TEMP_TOO_LOW) {
1405 charger_en(charger_speed);
1406 previous_state = _TEMP_OK;
1410 if (previous_state == _TEMP_TOO_HIGH) {
1413 charger_en(charger_speed);
1414 previous_state = _TEMP_OK;
1419 writel(org, &rtc->rtccon);
1420 writel(org_ip3, 0xE010046C);
1422 } while (wakeup_stat == 0x04); /* RTC TICK */
1424 #ifdef CONFIG_S5PC1XXFB
1426 /* TODO: Reenable logo display (not working yet) */
1428 drv_lcd_init_resume();
1432 #define S5PC110_RST_STAT 0xE010A000
1434 #define SWRESET (1 << 3)
1435 #define WDTRESET (1 << 2)
1436 #define WARMRESET (1 << 1)
1437 #define EXTRESET (1 << 0)
1439 static int get_reset_status(void)
1441 return readl(S5PC110_RST_STAT) & 0xf;
1444 static int fsa9480_probe(void)
1446 unsigned char addr = 0x25;
1448 if (cpu_is_s5pc100())
1451 if (board_is_limo_real()) {
1452 if (hwrevision(0) || hwrevision(1))
1456 i2c_set_bus_num(I2C_PMIC);
1458 if (mach_is_kessler()) {
1459 i2c_set_bus_num(I2C_GPIO6);
1460 } else if (mach_is_cypress()) {
1461 i2c_set_bus_num(I2C_GPIO6);
1462 } else if (mach_is_geminus()) {
1464 i2c_set_bus_num(I2C_GPIO6);
1465 } else if (mach_is_wmg160()) {
1466 i2c_set_bus_num(I2C_GPIO6);
1469 if (i2c_probe(addr)) {
1470 printf("Can't found fsa9480\n");
1477 static void check_micro_usb(int intr)
1480 unsigned char val[2];
1481 static int started_charging_once = 0;
1484 if (fsa9480_probe())
1487 addr = 0x25; /* fsa9480 */
1489 /* Clear Interrupt */
1491 i2c_read(addr, 0x03, 1, val, 2);
1495 /* Read Device Type 1 */
1496 i2c_read(addr, 0x0a, 1, val, 1);
1498 #define FSA_DEV1_CHARGER (1 << 6)
1499 #define FSA_DEV1_UART (1 << 3)
1500 #define FSA_DEV1_USB (1 << 2)
1501 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1502 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1505 * If USB, use default 475mA
1506 * If Charger, use 600mA and go to charge mode
1508 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1509 started_charging_once = 1;
1511 /* If it's full, do not charge. */
1512 if (battery_soc < 100)
1516 } else if (val[0] & FSA_DEV1_USB) {
1517 if (battery_soc < 100)
1518 charger_en(475); /* enable charger and keep booting */
1523 /* If reset status is watchdog reset then skip it */
1524 if (!(get_reset_status() & WDTRESET)) {
1525 /* If Factory Mode is Boot ON-USB, go to download mode */
1526 i2c_read(addr, 0x07, 1, val, 1);
1528 #define FSA_ADC_FAC_USB_OFF 0x18
1529 #define FSA_ADC_FAC_USB_ON 0x19
1530 #define FSA_ADC_FAC_UART 0x1d
1532 if (val[0] == FSA_ADC_FAC_USB_ON ||
1533 val[0] == FSA_ADC_FAC_USB_OFF)
1534 setenv("bootcmd", "usbdown");
1537 path = getenv("usb");
1539 if (!strncmp(path, "cp", 2))
1540 run_command("microusb cp", 0);
1543 static void micro_usb_switch(int path)
1546 unsigned char val[2];
1548 if (fsa9480_probe())
1551 addr = 0x25; /* fsa9480 */
1554 val[0] = 0x90; /* VAUDIO */
1556 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1558 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1560 i2c_read(addr, 0x2, 1, val, 1);
1561 val[0] &= ~(1 << 2); /* Manual switching */
1562 i2c_write(addr, 0x2, 1, val, 1);
1565 #define MAX8998_REG_ONOFF1 0x11
1566 #define MAX8998_REG_ONOFF2 0x12
1567 #define MAX8998_REG_ONOFF3 0x13
1568 #define MAX8998_REG_LDO7 0x21
1569 #define MAX8998_REG_LDO17 0x29
1571 #define MAX8998_LDO3 (1 << 2)
1573 #define MAX8998_LDO6 (1 << 7)
1574 #define MAX8998_LDO7 (1 << 6)
1575 #define MAX8998_LDO8 (1 << 5)
1576 #define MAX8998_LDO9 (1 << 4)
1577 #define MAX8998_LDO10 (1 << 3)
1578 #define MAX8998_LDO11 (1 << 2)
1579 #define MAX8998_LDO12 (1 << 1)
1580 #define MAX8998_LDO13 (1 << 0)
1582 #define MAX8998_LDO14 (1 << 7)
1583 #define MAX8998_LDO15 (1 << 6)
1584 #define MAX8998_LDO16 (1 << 5)
1585 #define MAX8998_LDO17 (1 << 4)
1588 static void init_pmic(void)
1591 unsigned char val[2];
1593 if (cpu_is_s5pc100())
1596 addr = 0xCC >> 1; /* max8998 */
1597 if (max8998_probe())
1601 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1602 val[0] &= ~MAX8998_LDO3;
1603 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1606 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1608 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1609 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1611 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1612 MAX8998_LDO12 | MAX8998_LDO13);
1614 if (mach_is_kessler())
1615 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1617 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1618 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1620 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1622 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1623 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1625 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1626 MAX8998_LDO16 | MAX8998_LDO17);
1628 if (mach_is_kessler())
1629 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1631 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1632 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1635 static void setup_power_down_mode_registers(void)
1637 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1638 struct s5pc1xx_gpio_bank *bank;
1639 struct gpio_powermode *p;
1641 struct gpio_external *ge;
1643 struct s5pc1xx_gpio_item *mr;
1647 if (cpu_is_s5pc100())
1650 /* Only Limo real and kessler supports worked for sleep currnet */
1651 if (mach_is_aquila()) {
1652 if (board_is_limo_real())
1656 } else if (mach_is_kessler()) {
1658 } else if (mach_is_geminus()) {
1664 if (mach_is_aquila()) {
1665 /* Aquila rev 0.8 or lower */
1666 p = aquila_powerdown_modes;
1667 ge = aquila_external_powerdown_modes;
1668 mr = aquila_mirror_powerdown_mode;
1669 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1670 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1671 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1672 } else if (mach_is_kessler()) {
1673 /* Aquila rev 0.9 */
1674 p = kessler_powerdown_modes;
1675 ge = kessler_external_powerdown_modes;
1676 mr = kessler_mirror_powerdown_mode;
1677 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1678 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1679 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1680 } else if (mach_is_geminus()) {
1681 if (hwrevision(1)) {
1682 /* Same as Aquila rev 0.9 */
1684 p = kessler_powerdown_modes;
1685 ge = kessler_external_powerdown_modes;
1686 mr = kessler_mirror_powerdown_mode;
1687 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1688 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1689 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1691 p = aquila_powerdown_modes;
1692 ge = aquila_external_powerdown_modes;
1693 mr = aquila_mirror_powerdown_mode;
1694 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1695 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1696 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1698 } else if (hwrevision(0)) {
1699 /* Same as Aquila rev 0.8 or lower */
1700 p = aquila_powerdown_modes;
1701 ge = aquila_external_powerdown_modes;
1702 mr = aquila_mirror_powerdown_mode;
1703 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1704 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1705 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1707 return; /* Not supported */
1711 bank = &gpio->gpio_a0;
1713 for (i = 0; i < n_p; i++, p++, bank++) {
1714 writel(p->conpdn, &bank->pdn_con);
1715 writel(p->pudpdn, &bank->pdn_pull);
1718 writel(0xff0022b0, (unsigned int *)0xF0000000);
1719 writel(0xff0022b0, (unsigned int *)0xF1400000);
1721 bank = &gpio->gpio_h0;
1723 for (i = 0; i < n_ge; i++) {
1724 writel(ge->con, &bank->con);
1725 writel(ge->dat, &bank->dat);
1726 writel(ge->pud, &bank->pull);
1732 for (i = 0; i < n_mr; i++) {
1733 unsigned int reg = readl(&mr->bank->pdn_con);
1734 reg &= ~(0x3 << (mr->number << 1));
1735 if (readl(&mr->bank->dat) & (1 << mr->number))
1736 reg |= 0x1 << (mr->number << 1);
1737 writel(reg, &mr->bank->pdn_con);
1743 #include "../../../drivers/video/s5p-spi.h"
1745 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1746 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1748 struct spi_platform_data spi_pd;
1750 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1752 void lcd_cfg_gpio(void)
1754 unsigned int i, f3_end = 4;
1756 for (i = 0; i < 8; i++) {
1757 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1758 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1759 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1760 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1761 /* pull-up/down disable */
1762 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1763 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1764 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1766 /* drive strength to max (24bit) */
1767 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1768 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1769 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1770 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1771 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1772 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1775 /* set DISPLAY_DE_B pin for dual rgb mode. */
1776 if (board_is_media())
1779 for (i = 0; i < f3_end; i++) {
1780 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1781 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1782 /* pull-up/down disable */
1783 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1784 /* drive strength to max (24bit) */
1785 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1786 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1788 /* display output path selection (only [1:0] valid) */
1789 writel(0x2, 0xE0107008);
1791 /* gpio pad configuration for LCD reset. */
1792 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1794 /* gpio pad configuration for LCD ON. */
1795 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1797 /* LCD_BACKLIGHT_EN */
1798 if (mach_is_geminus())
1799 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1800 if (board_is_neptune()) {
1801 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1802 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1806 * gpio pad configuration for
1807 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1809 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1810 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1811 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1812 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1814 if (mach_is_aquila() || mach_is_kessler()) {
1815 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1817 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1819 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1821 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1824 if (board_is_neptune())
1825 s6d16a0x_set_platform_data(&spi_pd);
1827 s6e63m0_set_platform_data(&spi_pd);
1828 if (board_is_media())
1833 if (mach_is_cypress()) {
1834 #if 0 /* universal cypress */
1836 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1839 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1841 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1843 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1845 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1847 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1848 #if 0 /* universal cypress */
1849 pd_cs.bank = &gpio_base->gpio_mp0_1;
1852 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1854 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1856 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1861 /* these data would be sent to s6e63m0 lcd panel driver. */
1862 s6e63m0_set_platform_data(&spi_pd);
1868 #define SWRST_REG 0x00
1869 #define LEDCON_REG 0x01
1870 #define LED_CUR_SET_REG 0x03
1871 #define LED_CUR_TR_REG 0x08
1874 #define NORMAL_MODE 0x09
1875 #define CUR_SET 0x63
1877 void backlight_on(unsigned int onoff)
1881 unsigned char val[2];
1882 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1885 if (mach_is_geminus())
1886 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1888 if (mach_is_geminus())
1889 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1892 if (mach_is_kessler() && board_is_neptune()) {
1893 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1896 i2c_set_bus_num(I2C_GPIO5);
1899 if (i2c_probe(addr)) {
1900 if (i2c_probe(addr)) {
1901 printf("Can't found s6d16a0x backlight i2c\n");
1906 i2c_write(addr, SWRST_REG, 1, val, 1);
1909 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1911 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1912 val[0] = NORMAL_MODE;
1913 i2c_write(addr, LEDCON_REG, 1, val, 1);
1918 void reset_lcd(void)
1920 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1922 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1923 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1924 if (mach_is_cypress())
1925 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1928 void lcd_power_on(unsigned int onoff)
1930 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1933 if (mach_is_aquila() || mach_is_geminus())
1934 gpio_set_value(&gpio->gpio_j1, 3, 1);
1936 if (mach_is_cypress())
1937 gpio_set_value(&gpio->gpio_g2, 2, 1);
1939 if (mach_is_kessler()) {
1941 unsigned char val[2];
1942 unsigned char val2[2];
1944 gpio_set_value(&gpio->gpio_j1, 3, 1);
1946 addr = 0xCC >> 1; /* max8998 */
1947 if (max8998_probe())
1950 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1951 val[0] &= ~(MAX8998_LDO17);
1952 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1953 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1955 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1956 val[0] |= MAX8998_LDO17;
1958 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1959 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1961 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1962 val[0] |= MAX8998_LDO7;
1964 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1965 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1968 if (mach_is_aquila() || mach_is_geminus())
1969 gpio_set_value(&gpio->gpio_j1, 3, 0);
1971 if (mach_is_cypress())
1972 gpio_set_value(&gpio->gpio_g2, 2, 0);
1974 if (mach_is_kessler()) {
1976 unsigned char val[2];
1978 gpio_set_value(&gpio->gpio_j1, 3, 0);
1980 addr = 0xCC >> 1; /* max8998 */
1981 if (max8998_probe())
1984 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1985 val[0] &= ~(MAX8998_LDO7);
1986 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1987 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1989 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1990 val[0] &= ~(MAX8998_LDO17);
1991 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1992 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1997 extern void s6e63m0_cfg_ldo(void);
1998 extern void s6e63m0_enable_ldo(unsigned int onoff);
1999 extern void s6d16a0x_cfg_ldo(void);
2000 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2002 int s5p_no_lcd_support(void)
2004 if (mach_is_wmg160())
2009 void init_panel_info(vidinfo_t *vid)
2011 vid->cfg_gpio = NULL;
2012 vid->reset_lcd = NULL;
2013 vid->backlight_on = NULL;
2014 vid->lcd_power_on = NULL;
2016 vid->cfg_ldo = NULL;
2017 vid->enable_ldo = NULL;
2019 vid->init_delay = 0;
2020 vid->reset_delay = 0;
2021 vid->power_on_delay = 0;
2026 vid->vl_width = 480;
2027 vid->vl_height = 800;
2029 vid->dual_lcd_enabled = 0;
2031 if (board_is_media()) {
2034 vid->vl_width = 960;
2035 vid->vl_height = 800;
2037 /* enable dual lcd mode. */
2038 vid->dual_lcd_enabled = 1;
2041 vid->vl_clkp = CONFIG_SYS_HIGH;
2042 vid->vl_hsp = CONFIG_SYS_LOW;
2043 vid->vl_vsp = CONFIG_SYS_LOW;
2044 vid->vl_dp = CONFIG_SYS_HIGH;
2047 /* S6E63M0 LCD Panel */
2056 if (mach_is_aquila() || mach_is_kessler()
2057 || mach_is_cypress()) {
2058 vid->cfg_gpio = lcd_cfg_gpio;
2059 vid->reset_lcd = reset_lcd;
2060 vid->backlight_on = backlight_on;
2061 vid->lcd_power_on = lcd_power_on;
2062 vid->cfg_ldo = s6e63m0_cfg_ldo;
2063 vid->enable_ldo = s6e63m0_enable_ldo;
2065 vid->init_delay = 25000;
2066 vid->reset_delay = 120000;
2069 if (board_is_neptune()) {
2073 vid->vl_width = 320;
2074 vid->vl_height = 480;
2076 vid->vl_clkp = CONFIG_SYS_HIGH;
2077 vid->vl_hsp = CONFIG_SYS_HIGH;
2078 vid->vl_vsp = CONFIG_SYS_HIGH;
2079 vid->vl_dp = CONFIG_SYS_LOW;
2082 /* disable dual lcd mode. */
2083 vid->dual_lcd_enabled = 0;
2085 /* S6D16A0X LCD Panel */
2094 vid->cfg_gpio = lcd_cfg_gpio;
2095 vid->backlight_on = backlight_on;
2096 vid->lcd_power_on = lcd_power_on;
2097 vid->reset_lcd = reset_lcd;
2098 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2099 vid->enable_ldo = s6d16a0x_enable_ldo;
2101 vid->init_delay = 10000;
2102 vid->power_on_delay = 10000;
2103 vid->reset_delay = 1000;
2107 if (mach_is_geminus()) {
2111 vid->vl_width = 1024,
2112 vid->vl_height = 600,
2113 vid->vl_clkp = CONFIG_SYS_LOW,
2114 vid->vl_hsp = CONFIG_SYS_HIGH,
2115 vid->vl_vsp = CONFIG_SYS_HIGH,
2116 vid->vl_dp = CONFIG_SYS_LOW,
2127 vid->cfg_gpio = lcd_cfg_gpio;
2128 vid->reset_lcd = reset_lcd;
2129 vid->backlight_on = backlight_on;
2130 vid->lcd_power_on = lcd_power_on;
2136 vid->vl_width = 480,
2137 vid->vl_height = 800,
2138 vid->vl_clkp = CONFIG_SYS_HIGH,
2139 vid->vl_hsp = CONFIG_SYS_LOW,
2140 vid->vl_vsp = CONFIG_SYS_LOW,
2141 vid->vl_dp = CONFIG_SYS_HIGH,
2157 vid->vl_width = 1024,
2158 vid->vl_height = 600,
2159 vid->vl_clkp = CONFIG_SYS_HIGH,
2160 vid->vl_hsp = CONFIG_SYS_HIGH,
2161 vid->vl_vsp = CONFIG_SYS_HIGH,
2162 vid->vl_dp = CONFIG_SYS_LOW,
2165 /* AMS701KA AMOLED Panel. */
2178 void fb_set_reserved_mem(void)
2180 unsigned int addr = CONFIG_FB_RESERVED_MEM_BASE;
2188 static void setup_meminfo(void)
2190 char meminfo[64] = {0, };
2191 int count = 0, size, real;
2193 size = gd->bd->bi_dram[0].size >> 20;
2194 count += sprintf(meminfo + count, "mem=%dM", size);
2196 /* Each Chip Select can't exceed the 256MiB */
2197 size = gd->bd->bi_dram[1].size >> 20;
2198 real = min(size, 256);
2199 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2200 real, (unsigned int)gd->bd->bi_dram[1].start);
2204 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2205 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2208 setenv("meminfo", meminfo);
2211 int misc_init_r(void)
2214 /* It should be located at first */
2217 if (mach_is_aquila() || mach_is_kessler()) {
2218 if (board_is_neptune())
2219 setenv("lcdinfo", "lcd=s6d16a0x");
2220 else if (board_is_media())
2221 setenv("lcdinfo", "lcd=s6e63m0");
2223 setenv("lcdinfo", "lcd=s6e63m0");
2225 if (mach_is_geminus())
2226 setenv("lcdinfo", "lcd=lms480jc01");
2227 if (mach_is_cypress())
2228 setenv("lcdinfo", "lcd=s6e63m0");
2234 /* Set proper PMIC pins */
2237 /* Check auto burning */
2240 /* To power up I2C2 */
2243 /* Enable T-Flash at Limo Real or Limo Universal */
2246 /* Setup Limo Real board GPIOs */
2247 setup_limo_real_gpios();
2249 /* Setup Media board GPIOs */
2250 setup_media_gpios();
2252 /* To usbdown automatically */
2258 #ifdef CONFIG_S5PC1XXFB
2259 display_device_info();
2262 setup_power_down_mode_registers();
2264 /* check max17040 */
2274 int board_init(void)
2276 /* Set Initial global variables */
2277 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2279 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2280 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2282 /* Check H/W Revision */
2283 check_hw_revision();
2290 unsigned int base, memconfig0, size;
2291 unsigned int memconfig1, sz = 0;
2293 if (cpu_is_s5pc100()) {
2294 /* In mem setup, we swap the bank. So below size is correct */
2295 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2296 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2297 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2300 /* In S5PC110, we can't swap the DMC0/1 */
2301 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2302 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2304 base = S5PC110_DMC1_BASE;
2305 /* DMC configuration */
2306 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2307 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2309 size = (memconfig0 >> 16) & 0xFF;
2310 size = ((unsigned char) ~size) + 1;
2313 * (0x07 + 1) * 16 = 128 MiB
2314 * (0x0f + 1) * 16 = 256 MiB
2319 * Aquila Rev0.5 4G3G1G
2320 * Aquila Rev0.8 4G3G1G
2321 * Aquila Rev0.9 4G3G1G
2323 if (mach_is_aquila() || mach_is_kessler())
2324 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2325 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2327 sz = (memconfig1 >> 16) & 0xFF;
2328 sz = ((unsigned char) ~sz) + 1;
2334 * bi_dram[1].size contains all DMC1 memory size
2336 gd->bd->bi_dram[1].size = (size + sz) << 20;
2341 /* Used for sleep test */
2342 static unsigned char saved_val[4][2];
2343 void board_sleep_init_late(void)
2345 /* CODEC_LDO_EN: GPF3[4] */
2346 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2347 /* CODEC_XTAL_EN: GPH3[2] */
2348 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2350 /* MMC T_FLASH off */
2351 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2353 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2354 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2355 /* MHL_ON for REV02 or higher */
2356 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2359 void board_sleep_init(void)
2362 unsigned char val[2];
2365 if (max8998_probe())
2368 if (mach_is_kessler()) {
2370 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2371 saved_val[0][0] = val[0];
2372 saved_val[0][1] = val[1];
2373 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2374 (1 << 1) | (1 << 0));
2375 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2376 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2379 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2380 saved_val[1][0] = val[0];
2381 saved_val[1][1] = val[1];
2382 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2383 (1 << 2) | (1 << 1) | (1 << 0));
2385 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2386 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2389 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2390 saved_val[2][0] = val[0];
2391 saved_val[2][1] = val[1];
2392 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2393 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2394 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2397 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2398 saved_val[3][0] = val[0];
2399 saved_val[3][1] = val[1];
2400 val[0] &= ~((1 << 6) | (1 << 4));
2401 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2402 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2404 printf("Turned off regulators with Kessler setting."
2405 " Preparing to sleep. [%s:%d]\n",
2406 __FILE__, __LINE__);
2407 } else { /* Default */
2409 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2410 saved_val[0][0] = val[0];
2411 saved_val[0][1] = val[1];
2412 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2413 (1 << 1) | (1 << 0));
2414 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2415 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2418 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2419 saved_val[1][0] = val[0];
2420 saved_val[1][1] = val[1];
2421 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2422 (1 << 2) | (1 << 1) | (1 << 0));
2424 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2425 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2429 saved_val[2][0] = val[0];
2430 saved_val[2][1] = val[1];
2431 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2432 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2433 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2436 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2437 saved_val[3][0] = val[0];
2438 saved_val[3][1] = val[1];
2439 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2440 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2441 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2443 printf("Turned off regulators with default(Aquila) setting."
2444 " Preparing to sleep. [%s:%d]\n",
2445 __FILE__, __LINE__);
2449 void board_sleep_resume(void)
2452 unsigned char val[2];
2457 if (max8998_probe())
2461 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2462 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2464 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2465 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2467 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2468 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2470 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2471 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2472 printf("Waked up.\n");
2474 /* check max17040 */
2481 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2483 static int s5pc1xx_phy_control(int on)
2487 if (on && !status) {
2488 #ifdef CONFIG_CMD_PMIC
2489 run_command("pmic ldo 3 on", 0);
2492 if (board_is_limo_universal() ||
2493 board_is_limo_real() ||
2495 /* check usb path */
2496 if (board_is_limo_real() && !hwrevision(6))
2500 if (mach_is_tickertape())
2501 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2502 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2504 /* USB Path to AP */
2505 micro_usb_switch(0);
2507 } else if (!on && status) {
2508 #ifdef CONFIG_CMD_PMIC
2509 run_command("pmic ldo 3 off", 0);
2518 struct s3c_plat_otg_data s5pc110_otg_data = {
2519 .phy_control = s5pc1xx_phy_control,
2520 .regs_phy = S5PC110_PHY_BASE,
2521 .regs_otg = S5PC110_OTG_BASE,
2524 int board_eth_init(bd_t *bis)
2528 if (cpu_is_s5pc100())
2531 s3c_udc_probe(&s5pc110_otg_data);
2532 if (usb_eth_initialize(bis) >= 0)
2538 #ifdef CONFIG_CMD_USBDOWN
2539 int usb_board_init(void)
2541 #ifdef CONFIG_CMD_PMIC
2542 run_command("pmic ldo 3 on", 0);
2545 if (cpu_is_s5pc100()) {
2546 #ifdef CONFIG_HARD_I2C
2547 uchar val[2] = {0,};
2550 if (i2c_read(0x66, 0, 1, val, 2)) {
2551 printf("i2c_read error\n");
2558 if (i2c_write(0x66, 0, 1, val, 2)) {
2559 printf("i2c_write error\n");
2562 i2c_read(0x66, 0, 1, val, 2);
2568 if (board_is_limo_universal() ||
2569 board_is_limo_real() ||
2571 /* check usb path */
2572 if (board_is_limo_real() && !hwrevision(6))
2576 if (mach_is_tickertape())
2577 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2578 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2580 /* USB Path to AP */
2581 micro_usb_switch(0);
2587 #ifdef CONFIG_GENERIC_MMC
2588 int s5p_no_mmc_support(void)
2590 if (mach_is_wmg160())
2595 int board_mmc_init(bd_t *bis)
2599 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2602 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2603 if (mach_is_kessler())
2604 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2606 if (mach_is_wmg160())
2609 /* MMC0 Clock source = SCLKMPLL */
2610 reg = readl(&clk->src4);
2613 writel(reg, &clk->src4);
2615 reg = readl(&clk->div4);
2618 /* set div value near 50MHz */
2619 clock = get_pll_clk(MPLL) / 1000000;
2620 for (i = 0; i < 0xf; i++) {
2621 if ((clock / (i + 1)) <= 50) {
2627 writel(reg, &clk->div4);
2633 * GPG0[2] SD_0_CDn -> Not used
2634 * GPG0[3:6] SD_0_DATA[0:3]
2636 for (i = 0; i < 7; i++) {
2639 /* GPG0[0:6] special function 2 */
2640 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2641 /* GPG0[0:6] pull disable */
2642 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2643 /* GPG0[0:6] drv 4x */
2644 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2647 if (mach_is_geminus()) {
2648 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2649 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2652 return s5pc1xx_mmc_init(0);
2656 #ifdef CONFIG_CMD_PMIC
2657 static int pmic_status(void)
2659 unsigned char addr, val[2];
2664 if (max8998_probe())
2668 i2c_read(addr, reg, 1, val, 1);
2669 for (i = 7; i >= 4; i--)
2670 printf("BUCK%d %s\n", 7 - i + 1,
2671 val[0] & (1 << i) ? "on" : "off");
2673 printf("LDO%d %s\n", 5 - i,
2674 val[0] & (1 << i) ? "on" : "off");
2676 i2c_read(addr, reg, 1, val, 1);
2677 for (i = 7; i >= 0; i--)
2678 printf("LDO%d %s\n", 7 - i + 6,
2679 val[0] & (1 << i) ? "on" : "off");
2681 i2c_read(addr, reg, 1, val, 1);
2682 for (i = 7; i >= 4; i--)
2683 printf("LDO%d %s\n", 7 - i + 14,
2684 val[0] & (1 << i) ? "on" : "off");
2687 i2c_read(addr, reg, 1, val, 1);
2688 for (i = 7; i >= 6; i--)
2689 printf("SAFEOUT%d %s\n", 7 - i + 1,
2690 val[0] & (1 << i) ? "on" : "off");
2694 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2696 unsigned char addr, val[2];
2697 unsigned int reg, shift;
2705 } else if (ldo <= 13) {
2708 } else if (ldo <= 17) {
2710 shift = 17 - ldo + 4;
2717 shift = 4 - buck + 4;
2718 } else if (safeout) {
2722 shift = 8 - safeout;
2728 if (max8998_probe())
2731 i2c_read(addr, reg, 1, val, 1);
2733 val[0] |= (1 << shift);
2735 val[0] &= ~(1 << shift);
2736 i2c_write(addr, reg, 1, val, 1);
2737 i2c_read(addr, reg, 1, val, 1);
2740 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2741 val[0] & (1 << shift) ? "on" : "off");
2743 printf("buck %d value 0x%x, %s\n", buck, val[0],
2744 val[0] & (1 << shift) ? "on" : "off");
2746 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2747 val[0] & (1 << shift) ? "on" : "off");
2752 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2754 int buck = 0, ldo = 0, safeout = 0, on = -1;
2758 if (strncmp(argv[1], "status", 6) == 0)
2759 return pmic_status();
2762 if (strncmp(argv[1], "ldo", 3) == 0)
2763 ldo = simple_strtoul(argv[2], NULL, 10);
2764 else if (strncmp(argv[1], "buck", 4) == 0)
2765 buck = simple_strtoul(argv[2], NULL, 10);
2766 else if (strncmp(argv[1], "safeout", 7) == 0)
2767 safeout = simple_strtoul(argv[2], NULL, 10);
2771 if (strncmp(argv[3], "on", 2) == 0)
2773 else if (strncmp(argv[3], "off", 3) == 0)
2778 return pmic_ldo_control(buck, ldo, safeout, on);
2789 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2790 "PMIC LDO & BUCK control",
2791 "status - Display PMIC LDO & BUCK status\n"
2792 "pmic ldo num on/off - Turn on/off the LDO\n"
2793 "pmic buck num on/off - Turn on/off the BUCK\n"
2794 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2798 #ifdef CONFIG_CMD_DEVICE_POWER
2799 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2803 if (strncmp(argv[1], "cp", 2) == 0) {
2804 micro_usb_switch(1);
2805 pmic_ldo_control(0, 0, 2, 1);
2806 setenv("usb", "cp");
2807 } else if (strncmp(argv[1], "ap", 2) == 0) {
2808 micro_usb_switch(0);
2809 pmic_ldo_control(0, 0, 2, 0);
2810 setenv("usb", "ap");
2820 printf("USB Path is set to %s\n", getenv("usb"));
2826 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2828 "cp - switch to CP\n"
2829 "microusb ap - switch to AP\n"