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 empty_device_info_buffer();
695 dprintf("HW Revision:\t%x (%s%s) %s\n",
696 board_rev, get_board_name(board),
697 display_features(board, board_rev),
698 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
701 static void check_auto_burn(void)
703 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
704 unsigned int count = 0;
707 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
708 printf("Auto burning bootloader\n");
709 count += sprintf(buf + count, "run updateb; ");
711 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
712 printf("Auto burning kernel\n");
713 count += sprintf(buf + count, "run updatek; ");
717 count += sprintf(buf + count, "reset");
718 setenv("bootcmd", buf);
721 /* Clear the magic value */
722 writel(0xa5a55a5a, magic_base);
723 writel(0xa5a55a5a, magic_base + 0x4);
726 static void pmic_pin_init(void)
728 unsigned int reg, value;
730 if (cpu_is_s5pc100())
733 /* AP_PS_HOLD: XEINT_0: GPH0[0]
734 * Note: Don't use GPIO PS_HOLD it doesn't work
736 reg = S5PC110_PS_HOLD_CONTROL;
738 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
739 S5PC110_PS_HOLD_DATA_HIGH |
740 S5PC110_PS_HOLD_OUT_EN;
743 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
744 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
745 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
748 static void enable_ldos(void)
750 if (cpu_is_s5pc100())
753 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
754 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
757 static void enable_t_flash(void)
759 if (!(board_is_limo_universal() || board_is_limo_real()))
762 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
763 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
766 static void setup_limo_real_gpios(void)
768 if (!board_is_limo_real())
772 * Note: Please write GPIO alphabet order
774 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
775 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
778 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
779 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
781 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
782 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
784 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
785 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
786 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
789 static void setup_media_gpios(void)
791 if (!board_is_media())
795 * Note: Please write GPIO alphabet order
797 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
798 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
800 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
801 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
802 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
805 #define KBR3 (1 << 3)
806 #define KBR2 (1 << 2)
807 #define KBR1 (1 << 1)
808 #define KBR0 (1 << 0)
810 static void check_keypad(void)
812 unsigned int reg, value;
813 unsigned int col_num, row_num;
814 unsigned int col_mask;
815 unsigned int col_mask_shift;
816 unsigned int row_state[4];
818 unsigned int auto_download = 0;
820 if (mach_is_wmg160())
823 if (cpu_is_s5pc100()) {
824 struct s5pc100_gpio *gpio =
825 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
830 /* Set GPH2[2:0] to KP_COL[2:0] */
831 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
832 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
833 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
835 /* Set GPH3[2:0] to KP_ROW[2:0] */
836 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
837 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
838 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
840 reg = S5PC100_KEYPAD_BASE;
841 col_mask = S5PC1XX_KEYIFCOL_MASK;
844 if (board_is_limo_real() || board_is_limo_universal()) {
852 for (i = 0; i < row_num; i++) {
853 /* Set GPH3[3:0] to KP_ROW[3:0] */
854 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
855 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
858 for (i = 0; i < col_num; i++)
859 /* Set GPH2[3:0] to KP_COL[3:0] */
860 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
862 reg = S5PC110_KEYPAD_BASE;
863 col_mask = S5PC110_KEYIFCOLEN_MASK;
867 /* KEYIFCOL reg clear */
868 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
871 for (i = 0; i < col_num; i++) {
873 value &= ~(1 << i) << col_mask_shift;
875 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
878 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
879 row_state[i] = ~value & ((1 << row_num) - 1);
881 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
884 /* KEYIFCOL reg clear */
885 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
887 if (mach_is_aquila() || mach_is_kessler()) {
889 if (row_state[1] & 0x2)
891 if (board_is_neptune()) {
892 /* home & volume down */
893 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
896 /* cam full shot & volume down */
897 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
900 } else if (mach_is_geminus())
901 /* volume down & home */
902 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
906 setenv("bootcmd", "usbdown");
909 static void check_battery(int mode)
911 unsigned char val[2];
912 unsigned char addr = 0x36; /* max17040 fuel gauge */
914 i2c_set_bus_num(I2C_GPIO3);
916 if (mach_is_aquila()) {
919 } else if (mach_is_kessler()) {
920 i2c_set_bus_num(I2C_GPIO7);
921 } else if (mach_is_cypress()) {
922 i2c_set_bus_num(I2C_GPIO7);
923 } else if (mach_is_geminus()) {
925 i2c_set_bus_num(I2C_GPIO7);
929 if (i2c_probe(addr)) {
930 printf("Can't found max17040 fuel gauge\n");
934 /* mode 0: check mode / 1: enable mode */
938 i2c_write(addr, 0xfe, 1, val, 2);
940 i2c_read(addr, 0x04, 1, val, 1);
941 dprintf("battery:\t%d%%\n", val[0]);
942 battery_soc = val[0];
946 static void check_mhl(void)
948 unsigned char val[2];
949 unsigned char addr = 0x39; /* SIL9230 */
951 /* MHL Power enable */
952 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
953 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
955 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
956 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
958 /* 10ms required after reset */
962 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
964 i2c_set_bus_num(I2C_GPIO5);
967 if (i2c_probe(addr)) {
968 printf("Can't found MHL Chip\n");
974 * set to Normal operation
977 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
978 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
983 * 00 = MHL termination ON
984 * 11 = MHL termination OFF
987 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
988 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
991 static int max8998_probe(void)
993 unsigned char addr = 0xCC >> 1;
995 i2c_set_bus_num(I2C_PMIC);
997 if (i2c_probe(addr)) {
998 printf("Can't found max8998\n");
1005 #define CHARGER_ANIMATION_FRAME 6
1006 static void max8998_clear_interrupt(void)
1008 unsigned char addr, val[2];
1011 if (max8998_probe())
1014 i2c_read(addr, 0x00, 1, val, 1);
1015 i2c_read(addr, 0x01, 1, val, 1);
1016 i2c_read(addr, 0x02, 1, val, 1);
1017 i2c_read(addr, 0x03, 1, val, 1);
1020 static int max8998_power_key(void)
1022 unsigned char addr, val[2];
1025 if (max8998_probe())
1028 /* Accessing IRQ1 register */
1029 i2c_read(addr, 0x00, 1, val, 1);
1030 if (val[0] & (1 << 6))
1036 static int max8998_has_ext_power_source(void)
1038 unsigned char addr, val[2];
1041 if (max8998_probe())
1044 /* Accessing STATUS2 register */
1045 i2c_read(addr, 0x09, 1, val, 1);
1046 if (val[0] & (1 << 5))
1052 struct thermister_stat {
1057 static struct thermister_stat adc_to_temperature_data[] = {
1058 { .centigrade = -20, .adc = 1856, },
1059 { .centigrade = -15, .adc = 1799, },
1060 { .centigrade = -10, .adc = 1730, },
1061 { .centigrade = -5, .adc = 1649, },
1062 { .centigrade = 0, .adc = 1556, },
1063 { .centigrade = 5, .adc = 1454, },
1064 { .centigrade = 10, .adc = 1343, },
1065 { .centigrade = 15, .adc = 1227, },
1066 { .centigrade = 20, .adc = 1109, },
1067 { .centigrade = 25, .adc = 992, },
1068 { .centigrade = 30, .adc = 880, },
1069 { .centigrade = 35, .adc = 773, },
1070 { .centigrade = 40, .adc = 675, },
1071 { .centigrade = 45, .adc = 586, },
1072 { .centigrade = 50, .adc = 507, },
1073 { .centigrade = 55, .adc = 436, },
1074 { .centigrade = 58, .adc = 399, },
1075 { .centigrade = 63, .adc = 343, },
1076 { .centigrade = 65, .adc = 322, },
1080 #define USHRT_MAX 0xFFFFU
1082 static int adc_to_temperature_centigrade(unsigned short adc)
1086 /* low_*: Greatest Lower Bound,
1087 * * * * high_*: Smallest Upper Bound */
1088 int low_temp = 0, high_temp = 0;
1089 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1090 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1091 if (adc_to_temperature_data[i].adc <= adc &&
1092 adc_to_temperature_data[i].adc >= low_adc) {
1093 low_temp = adc_to_temperature_data[i].centigrade;
1094 low_adc = adc_to_temperature_data[i].adc;
1096 if (adc_to_temperature_data[i].adc >= adc &&
1097 adc_to_temperature_data[i].adc <= high_adc) {
1098 high_temp = adc_to_temperature_data[i].centigrade;
1099 high_adc = adc_to_temperature_data[i].adc;
1103 /* Linear approximation between cloest low and high,
1104 * which is the weighted average of the two. */
1106 /* The following equation is correct only when the two are different */
1107 if (low_adc == high_adc)
1109 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1110 return 20; /* The room temperature */
1113 if (high_adc == USHRT_MAX)
1116 approximation = low_temp * (adc - low_adc) +
1117 high_temp * (high_adc - adc);
1118 approximation /= high_adc - low_adc;
1120 return approximation;
1123 static unsigned short get_adc_value(int channel)
1125 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1126 unsigned short ret = 0;
1130 unsigned int loop = 0;
1132 if (mach_is_kessler())
1134 else if (mach_is_geminus())
1136 else if (mach_is_wmg160())
1138 else if (mach_is_cypress())
1140 else if (mach_is_tickertape())
1142 else if (mach_is_aquila())
1145 else if (mach_is_p1p2())
1149 sprintf(buf, "pmic ldo %d on", ldonum);
1150 run_command(buf, 0);
1152 writel(channel & 0xF, &adc->adcmux);
1153 writel((1 << 14) | (49 << 6), &adc->adccon);
1154 writel(1000 & 0xffff, &adc->adcdly);
1155 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1157 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1162 reg = readl(&adc->adccon);
1163 } while (!reg & (1 << 15) && loop++ < 1000);
1165 ret = readl(&adc->adcdat0) & 0xFFF;
1166 sprintf(buf, "pmic ldo %d off", ldonum);
1167 run_command(buf, 0);
1172 static int adc_get_average_ambient_temperature(void)
1174 if (mach_is_kessler()) {
1175 unsigned short min = USHRT_MAX;
1176 unsigned short max = 0;
1177 unsigned int sum = 0;
1178 unsigned int measured = 0;
1181 for (i = 0; i < 7; i++) {
1182 unsigned short measurement = get_adc_value(6);
1185 if (min > measurement)
1187 if (max < measurement)
1190 if (measured >= 3) {
1196 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1197 adc_to_temperature_centigrade(sum), sum);
1198 return adc_to_temperature_centigrade(sum);
1201 return 20; /* 20 Centigrade */
1204 enum temperature_level {
1212 static enum temperature_level temperature_check(void)
1214 int temp = adc_get_average_ambient_temperature();
1216 return _TEMP_TOO_LOW;
1218 return _TEMP_OK_LOW;
1220 return _TEMP_TOO_HIGH;
1222 return _TEMP_OK_HIGH;
1226 extern void lcd_display_clear(void);
1227 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1229 static void charger_en(int enable)
1235 unsigned char addr = 0xCC >> 1; /* max8998 */
1236 unsigned char val[2];
1238 if (max8998_probe())
1242 printf("Disable the charger.\n");
1243 i2c_read(addr, 0x0D, 1, val, 1);
1246 i2c_write(addr, 0x0D, 1, val, 1);
1248 i2c_read(addr, 0x0C, 1, val, 1);
1249 val[0] &= ~(0x7 << 0);
1250 val[0] &= ~(0x7 << 5);
1251 if (enable == 600) {
1252 val[0] |= 5; /* 600mA */
1253 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1254 } else { /* Assume 475 mA */
1256 val[0] |= 2; /* 475mA */
1257 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1259 i2c_write(addr, 0x0C, 1, val, 1);
1261 i2c_read(addr, 0x0D, 1, val, 1);
1263 i2c_write(addr, 0x0D, 1, val, 1);
1264 printf("Enable the charger @ %dmA\n", enable);
1268 void lcd_power_on(unsigned int onoff);
1269 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1270 extern int drv_lcd_init_resume (void);
1272 static void into_charge_mode(void)
1278 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1279 unsigned int reg, wakeup_stat;
1280 int charger_speed = 600;
1282 max8998_clear_interrupt();
1284 printf("Charge Mode\n");
1285 charger_en(charger_speed);
1287 #ifdef CONFIG_S5PC1XXFB
1290 /* TODO: write the image-text for the charger */
1292 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1293 if (level >= CHARGER_ANIMATION_FRAME)
1294 level = CHARGER_ANIMATION_FRAME - 1;
1296 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1297 bmp_addr[i] = (ulong)battery_charging_animation[i];
1299 lcd_display_clear();
1300 for (i = 0; i < 3; i++) {
1301 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1304 bmp = gunzip_bmp(bmp_addr[j], &len);
1305 lcd_display_bitmap((ulong)bmp, 140, 202);
1308 for (k = 0; k < 10; k++) {
1309 if (max8998_power_key()) {
1310 lcd_display_clear();
1311 goto restore_screen;
1312 } else if (!max8998_has_ext_power_source()) {
1313 lcd_display_clear();
1314 goto restore_screen;
1323 /* Disable the display to prevent flickering */
1324 /* TODO: how to reenable the display later? */
1329 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1330 unsigned int org, org_ip3;
1331 enum temperature_level previous_state = _TEMP_OK;
1333 empty_device_info_buffer();
1334 if (max8998_power_key())
1336 else if (!max8998_has_ext_power_source())
1339 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1340 org_ip3 = readl(0xE010046C);
1341 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1343 reg = org = readl(&rtc->rtccon);
1345 writel(reg, &rtc->rtccon);
1347 reg = readl(&rtc->rtccon);
1348 writel(reg | (1 << 3), &rtc->rtccon);
1350 writel(reg & ~(1 << 3), &rtc->rtccon);
1353 reg = readl(&rtc->rtccon);
1354 reg &= ~((1 << 8) | (0xF << 4));
1355 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1356 writel(reg, &rtc->rtccon);
1358 reg = 15 * 4 - 1; /* 15 sec */
1359 writel(reg, &rtc->ticcnt);
1361 /* EVT0: sleep 1, EVT1: sleep */
1362 if (cpu_is_s5pc110()) {
1363 char *name = "dummy";
1364 char *usage = "N/A";
1371 if (s5pc1xx_get_cpu_rev() == 0) {
1372 char *argv[] = {"1", "1"};
1373 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1375 char *argv[] = {"0", "0"};
1376 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1379 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1383 /* Check TEMP HIGH/LOW */
1384 switch (temperature_check()) {
1386 charger_en(charger_speed);
1387 previous_state = _TEMP_OK;
1391 previous_state = _TEMP_TOO_LOW;
1393 case _TEMP_TOO_HIGH:
1395 previous_state = _TEMP_TOO_HIGH;
1398 if (previous_state == _TEMP_TOO_LOW) {
1401 charger_en(charger_speed);
1402 previous_state = _TEMP_OK;
1406 if (previous_state == _TEMP_TOO_HIGH) {
1409 charger_en(charger_speed);
1410 previous_state = _TEMP_OK;
1415 writel(org, &rtc->rtccon);
1416 writel(org_ip3, 0xE010046C);
1418 } while (wakeup_stat == 0x04); /* RTC TICK */
1420 #ifdef CONFIG_S5PC1XXFB
1422 /* TODO: Reenable logo display (not working yet) */
1424 drv_lcd_init_resume();
1428 #define S5PC110_RST_STAT 0xE010A000
1430 #define SWRESET (1 << 3)
1431 #define WDTRESET (1 << 2)
1432 #define WARMRESET (1 << 1)
1433 #define EXTRESET (1 << 0)
1435 static int get_reset_status(void)
1437 return readl(S5PC110_RST_STAT) & 0xf;
1440 static int fsa9480_probe(void)
1442 unsigned char addr = 0x25;
1444 if (cpu_is_s5pc100())
1447 if (board_is_limo_real()) {
1448 if (hwrevision(0) || hwrevision(1))
1452 i2c_set_bus_num(I2C_PMIC);
1454 if (mach_is_kessler()) {
1455 i2c_set_bus_num(I2C_GPIO6);
1456 } else if (mach_is_cypress()) {
1457 i2c_set_bus_num(I2C_GPIO6);
1458 } else if (mach_is_geminus()) {
1460 i2c_set_bus_num(I2C_GPIO6);
1461 } else if (mach_is_wmg160()) {
1462 i2c_set_bus_num(I2C_GPIO6);
1465 if (i2c_probe(addr)) {
1466 printf("Can't found fsa9480\n");
1473 static void check_micro_usb(int intr)
1476 unsigned char val[2];
1477 static int started_charging_once = 0;
1480 if (fsa9480_probe())
1483 addr = 0x25; /* fsa9480 */
1485 /* Clear Interrupt */
1487 i2c_read(addr, 0x03, 1, val, 2);
1491 /* Read Device Type 1 */
1492 i2c_read(addr, 0x0a, 1, val, 1);
1494 #define FSA_DEV1_CHARGER (1 << 6)
1495 #define FSA_DEV1_UART (1 << 3)
1496 #define FSA_DEV1_USB (1 << 2)
1497 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1498 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1501 * If USB, use default 475mA
1502 * If Charger, use 600mA and go to charge mode
1504 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1505 started_charging_once = 1;
1507 /* If it's full, do not charge. */
1508 if (battery_soc < 100)
1512 } else if (val[0] & FSA_DEV1_USB) {
1513 if (battery_soc < 100)
1514 charger_en(475); /* enable charger and keep booting */
1519 /* If reset status is watchdog reset then skip it */
1520 if (!(get_reset_status() & WDTRESET)) {
1521 /* If Factory Mode is Boot ON-USB, go to download mode */
1522 i2c_read(addr, 0x07, 1, val, 1);
1524 #define FSA_ADC_FAC_USB_OFF 0x18
1525 #define FSA_ADC_FAC_USB_ON 0x19
1526 #define FSA_ADC_FAC_UART 0x1d
1528 if (val[0] == FSA_ADC_FAC_USB_ON ||
1529 val[0] == FSA_ADC_FAC_USB_OFF)
1530 setenv("bootcmd", "usbdown");
1533 path = getenv("usb");
1535 if (!strncmp(path, "cp", 2))
1536 run_command("microusb cp", 0);
1539 static void micro_usb_switch(int path)
1542 unsigned char val[2];
1544 if (fsa9480_probe())
1547 addr = 0x25; /* fsa9480 */
1550 val[0] = 0x90; /* VAUDIO */
1552 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1554 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1556 i2c_read(addr, 0x2, 1, val, 1);
1557 val[0] &= ~(1 << 2); /* Manual switching */
1558 i2c_write(addr, 0x2, 1, val, 1);
1561 #define MAX8998_REG_ONOFF1 0x11
1562 #define MAX8998_REG_ONOFF2 0x12
1563 #define MAX8998_REG_ONOFF3 0x13
1564 #define MAX8998_REG_LDO7 0x21
1565 #define MAX8998_REG_LDO17 0x29
1567 #define MAX8998_LDO3 (1 << 2)
1569 #define MAX8998_LDO6 (1 << 7)
1570 #define MAX8998_LDO7 (1 << 6)
1571 #define MAX8998_LDO8 (1 << 5)
1572 #define MAX8998_LDO9 (1 << 4)
1573 #define MAX8998_LDO10 (1 << 3)
1574 #define MAX8998_LDO11 (1 << 2)
1575 #define MAX8998_LDO12 (1 << 1)
1576 #define MAX8998_LDO13 (1 << 0)
1578 #define MAX8998_LDO14 (1 << 7)
1579 #define MAX8998_LDO15 (1 << 6)
1580 #define MAX8998_LDO16 (1 << 5)
1581 #define MAX8998_LDO17 (1 << 4)
1584 static void init_pmic(void)
1587 unsigned char val[2];
1589 if (cpu_is_s5pc100())
1592 addr = 0xCC >> 1; /* max8998 */
1593 if (max8998_probe())
1597 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1598 val[0] &= ~MAX8998_LDO3;
1599 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1602 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1604 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1605 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1607 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1608 MAX8998_LDO12 | MAX8998_LDO13);
1610 if (mach_is_kessler())
1611 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1613 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1614 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1616 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1618 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1619 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1621 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1622 MAX8998_LDO16 | MAX8998_LDO17);
1624 if (mach_is_kessler())
1625 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1627 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1628 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1631 static void setup_power_down_mode_registers(void)
1633 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1634 struct s5pc1xx_gpio_bank *bank;
1635 struct gpio_powermode *p;
1637 struct gpio_external *ge;
1639 struct s5pc1xx_gpio_item *mr;
1643 if (cpu_is_s5pc100())
1646 /* Only Limo real and kessler supports worked for sleep currnet */
1647 if (mach_is_aquila()) {
1648 if (board_is_limo_real())
1652 } else if (mach_is_kessler()) {
1654 } else if (mach_is_geminus()) {
1660 if (mach_is_aquila()) {
1661 /* Aquila rev 0.8 or lower */
1662 p = aquila_powerdown_modes;
1663 ge = aquila_external_powerdown_modes;
1664 mr = aquila_mirror_powerdown_mode;
1665 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1666 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1667 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1668 } else if (mach_is_kessler()) {
1669 /* Aquila rev 0.9 */
1670 p = kessler_powerdown_modes;
1671 ge = kessler_external_powerdown_modes;
1672 mr = kessler_mirror_powerdown_mode;
1673 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1674 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1675 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1676 } else if (mach_is_geminus()) {
1677 if (hwrevision(1)) {
1678 /* Same as Aquila rev 0.9 */
1680 p = kessler_powerdown_modes;
1681 ge = kessler_external_powerdown_modes;
1682 mr = kessler_mirror_powerdown_mode;
1683 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1684 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1685 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1687 p = aquila_powerdown_modes;
1688 ge = aquila_external_powerdown_modes;
1689 mr = aquila_mirror_powerdown_mode;
1690 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1691 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1692 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1694 } else if (hwrevision(0)) {
1695 /* Same as Aquila rev 0.8 or lower */
1696 p = aquila_powerdown_modes;
1697 ge = aquila_external_powerdown_modes;
1698 mr = aquila_mirror_powerdown_mode;
1699 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1700 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1701 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1703 return; /* Not supported */
1707 bank = &gpio->gpio_a0;
1709 for (i = 0; i < n_p; i++, p++, bank++) {
1710 writel(p->conpdn, &bank->pdn_con);
1711 writel(p->pudpdn, &bank->pdn_pull);
1714 writel(0xff0022b0, (unsigned int *)0xF0000000);
1715 writel(0xff0022b0, (unsigned int *)0xF1400000);
1717 bank = &gpio->gpio_h0;
1719 for (i = 0; i < n_ge; i++) {
1720 writel(ge->con, &bank->con);
1721 writel(ge->dat, &bank->dat);
1722 writel(ge->pud, &bank->pull);
1728 for (i = 0; i < n_mr; i++) {
1729 unsigned int reg = readl(&mr->bank->pdn_con);
1730 reg &= ~(0x3 << (mr->number << 1));
1731 if (readl(&mr->bank->dat) & (1 << mr->number))
1732 reg |= 0x1 << (mr->number << 1);
1733 writel(reg, &mr->bank->pdn_con);
1739 #include "../../../drivers/video/s5p-spi.h"
1741 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1742 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1744 struct spi_platform_data spi_pd;
1746 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1748 void lcd_cfg_gpio(void)
1750 unsigned int i, f3_end = 4;
1752 for (i = 0; i < 8; i++) {
1753 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1754 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1755 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1756 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1757 /* pull-up/down disable */
1758 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1759 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1760 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1762 /* drive strength to max (24bit) */
1763 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1764 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1765 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1766 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1767 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1768 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1771 /* set DISPLAY_DE_B pin for dual rgb mode. */
1772 if (board_is_media())
1775 for (i = 0; i < f3_end; i++) {
1776 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1777 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1778 /* pull-up/down disable */
1779 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1780 /* drive strength to max (24bit) */
1781 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1782 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1784 /* display output path selection (only [1:0] valid) */
1785 writel(0x2, 0xE0107008);
1787 /* gpio pad configuration for LCD reset. */
1788 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1790 /* gpio pad configuration for LCD ON. */
1791 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1793 /* LCD_BACKLIGHT_EN */
1794 if (mach_is_geminus())
1795 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1796 if (board_is_neptune()) {
1797 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1798 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1802 * gpio pad configuration for
1803 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1805 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1806 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1807 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1808 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1810 if (mach_is_aquila() || mach_is_kessler()) {
1811 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1813 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1815 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1817 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1820 if (board_is_neptune())
1821 s6d16a0x_set_platform_data(&spi_pd);
1823 s6e63m0_set_platform_data(&spi_pd);
1824 if (board_is_media())
1829 if (mach_is_cypress()) {
1830 #if 0 /* universal cypress */
1832 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1835 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1837 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1839 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1841 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1843 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1844 #if 0 /* universal cypress */
1845 pd_cs.bank = &gpio_base->gpio_mp0_1;
1848 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1850 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1852 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1857 /* these data would be sent to s6e63m0 lcd panel driver. */
1858 s6e63m0_set_platform_data(&spi_pd);
1864 #define SWRST_REG 0x00
1865 #define LEDCON_REG 0x01
1866 #define LED_CUR_SET_REG 0x03
1867 #define LED_CUR_TR_REG 0x08
1870 #define NORMAL_MODE 0x09
1871 #define CUR_SET 0x63
1873 void backlight_on(unsigned int onoff)
1877 unsigned char val[2];
1878 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1881 if (mach_is_geminus())
1882 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1884 if (mach_is_geminus())
1885 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1888 if (mach_is_kessler() && board_is_neptune()) {
1889 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1892 i2c_set_bus_num(I2C_GPIO5);
1895 if (i2c_probe(addr)) {
1896 if (i2c_probe(addr)) {
1897 printf("Can't found s6d16a0x backlight i2c\n");
1902 i2c_write(addr, SWRST_REG, 1, val, 1);
1905 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1907 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1908 val[0] = NORMAL_MODE;
1909 i2c_write(addr, LEDCON_REG, 1, val, 1);
1914 void reset_lcd(void)
1916 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1918 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1919 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1920 if (mach_is_cypress())
1921 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1924 void lcd_power_on(unsigned int onoff)
1926 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1929 if (mach_is_aquila() || mach_is_geminus())
1930 gpio_set_value(&gpio->gpio_j1, 3, 1);
1932 if (mach_is_cypress())
1933 gpio_set_value(&gpio->gpio_g2, 2, 1);
1935 if (mach_is_kessler()) {
1937 unsigned char val[2];
1938 unsigned char val2[2];
1940 gpio_set_value(&gpio->gpio_j1, 3, 1);
1942 addr = 0xCC >> 1; /* max8998 */
1943 if (max8998_probe())
1946 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1947 val[0] &= ~(MAX8998_LDO17);
1948 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1949 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1951 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1952 val[0] |= MAX8998_LDO17;
1954 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1955 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1957 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1958 val[0] |= MAX8998_LDO7;
1960 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1961 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1964 if (mach_is_aquila() || mach_is_geminus())
1965 gpio_set_value(&gpio->gpio_j1, 3, 0);
1967 if (mach_is_cypress())
1968 gpio_set_value(&gpio->gpio_g2, 2, 0);
1970 if (mach_is_kessler()) {
1972 unsigned char val[2];
1974 gpio_set_value(&gpio->gpio_j1, 3, 0);
1976 addr = 0xCC >> 1; /* max8998 */
1977 if (max8998_probe())
1980 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1981 val[0] &= ~(MAX8998_LDO7);
1982 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1983 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1985 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1986 val[0] &= ~(MAX8998_LDO17);
1987 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1988 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1993 extern void s6e63m0_cfg_ldo(void);
1994 extern void s6e63m0_enable_ldo(unsigned int onoff);
1995 extern void s6d16a0x_cfg_ldo(void);
1996 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1998 int s5p_no_lcd_support(void)
2000 if (mach_is_wmg160())
2005 void init_panel_info(vidinfo_t *vid)
2007 vid->cfg_gpio = NULL;
2008 vid->reset_lcd = NULL;
2009 vid->backlight_on = NULL;
2010 vid->lcd_power_on = NULL;
2012 vid->cfg_ldo = NULL;
2013 vid->enable_ldo = NULL;
2015 vid->init_delay = 0;
2016 vid->reset_delay = 0;
2017 vid->power_on_delay = 0;
2022 vid->vl_width = 480;
2023 vid->vl_height = 800;
2025 vid->dual_lcd_enabled = 0;
2027 if (board_is_media()) {
2030 vid->vl_width = 960;
2031 vid->vl_height = 800;
2033 /* enable dual lcd mode. */
2034 vid->dual_lcd_enabled = 1;
2037 vid->vl_clkp = CONFIG_SYS_HIGH;
2038 vid->vl_hsp = CONFIG_SYS_LOW;
2039 vid->vl_vsp = CONFIG_SYS_LOW;
2040 vid->vl_dp = CONFIG_SYS_HIGH;
2043 /* S6E63M0 LCD Panel */
2052 if (mach_is_aquila() || mach_is_kessler()
2053 || mach_is_cypress()) {
2054 vid->cfg_gpio = lcd_cfg_gpio;
2055 vid->reset_lcd = reset_lcd;
2056 vid->backlight_on = backlight_on;
2057 vid->lcd_power_on = lcd_power_on;
2058 vid->cfg_ldo = s6e63m0_cfg_ldo;
2059 vid->enable_ldo = s6e63m0_enable_ldo;
2061 vid->init_delay = 25000;
2062 vid->reset_delay = 120000;
2065 if (board_is_neptune()) {
2069 vid->vl_width = 320;
2070 vid->vl_height = 480;
2072 vid->vl_clkp = CONFIG_SYS_HIGH;
2073 vid->vl_hsp = CONFIG_SYS_HIGH;
2074 vid->vl_vsp = CONFIG_SYS_HIGH;
2075 vid->vl_dp = CONFIG_SYS_LOW;
2078 /* disable dual lcd mode. */
2079 vid->dual_lcd_enabled = 0;
2081 /* S6D16A0X LCD Panel */
2090 vid->cfg_gpio = lcd_cfg_gpio;
2091 vid->backlight_on = backlight_on;
2092 vid->lcd_power_on = lcd_power_on;
2093 vid->reset_lcd = reset_lcd;
2094 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2095 vid->enable_ldo = s6d16a0x_enable_ldo;
2097 vid->init_delay = 10000;
2098 vid->power_on_delay = 10000;
2099 vid->reset_delay = 1000;
2103 if (mach_is_geminus()) {
2107 vid->vl_width = 1024,
2108 vid->vl_height = 600,
2109 vid->vl_clkp = CONFIG_SYS_LOW,
2110 vid->vl_hsp = CONFIG_SYS_HIGH,
2111 vid->vl_vsp = CONFIG_SYS_HIGH,
2112 vid->vl_dp = CONFIG_SYS_LOW,
2123 vid->cfg_gpio = lcd_cfg_gpio;
2124 vid->reset_lcd = reset_lcd;
2125 vid->backlight_on = backlight_on;
2126 vid->lcd_power_on = lcd_power_on;
2132 vid->vl_width = 480,
2133 vid->vl_height = 800,
2134 vid->vl_clkp = CONFIG_SYS_HIGH,
2135 vid->vl_hsp = CONFIG_SYS_LOW,
2136 vid->vl_vsp = CONFIG_SYS_LOW,
2137 vid->vl_dp = CONFIG_SYS_HIGH,
2153 vid->vl_width = 1024,
2154 vid->vl_height = 600,
2155 vid->vl_clkp = CONFIG_SYS_HIGH,
2156 vid->vl_hsp = CONFIG_SYS_HIGH,
2157 vid->vl_vsp = CONFIG_SYS_HIGH,
2158 vid->vl_dp = CONFIG_SYS_LOW,
2161 /* AMS701KA AMOLED Panel. */
2173 static void setup_meminfo(void)
2175 char meminfo[64] = {0, };
2176 int count = 0, size, real;
2178 size = gd->bd->bi_dram[0].size >> 20;
2179 count += sprintf(meminfo + count, "mem=%dM", size);
2181 /* Each Chip Select can't exceed the 256MiB */
2182 size = gd->bd->bi_dram[1].size >> 20;
2183 real = min(size, 256);
2184 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2185 real, (unsigned int)gd->bd->bi_dram[1].start);
2189 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2190 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2193 setenv("meminfo", meminfo);
2196 int misc_init_r(void)
2199 /* It should be located at first */
2202 if (mach_is_aquila() || mach_is_kessler()) {
2203 if (board_is_neptune())
2204 setenv("lcdinfo", "lcd=s6d16a0x");
2205 else if (board_is_media())
2206 setenv("lcdinfo", "lcd=s6e63m0");
2208 setenv("lcdinfo", "lcd=s6e63m0");
2210 if (mach_is_geminus())
2211 setenv("lcdinfo", "lcd=lms480jc01");
2212 if (mach_is_cypress())
2213 setenv("lcdinfo", "lcd=s6e63m0");
2219 /* Set proper PMIC pins */
2222 /* Check auto burning */
2225 /* To power up I2C2 */
2228 /* Enable T-Flash at Limo Real or Limo Universal */
2231 /* Setup Limo Real board GPIOs */
2232 setup_limo_real_gpios();
2234 /* Setup Media board GPIOs */
2235 setup_media_gpios();
2237 /* To usbdown automatically */
2243 #ifdef CONFIG_S5PC1XXFB
2244 display_device_info();
2247 setup_power_down_mode_registers();
2249 /* check max17040 */
2259 int board_init(void)
2261 /* Set Initial global variables */
2262 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2264 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2265 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2267 /* Check H/W Revision */
2268 check_hw_revision();
2275 unsigned int base, memconfig0, size;
2276 unsigned int memconfig1, sz = 0;
2278 if (cpu_is_s5pc100()) {
2279 /* In mem setup, we swap the bank. So below size is correct */
2280 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2281 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2282 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2285 /* In S5PC110, we can't swap the DMC0/1 */
2286 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2287 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2289 base = S5PC110_DMC1_BASE;
2290 /* DMC configuration */
2291 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2292 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2294 size = (memconfig0 >> 16) & 0xFF;
2295 size = ((unsigned char) ~size) + 1;
2298 * (0x07 + 1) * 16 = 128 MiB
2299 * (0x0f + 1) * 16 = 256 MiB
2304 * Aquila Rev0.5 4G3G1G
2305 * Aquila Rev0.8 4G3G1G
2306 * Aquila Rev0.9 4G3G1G
2308 if (mach_is_aquila() || mach_is_kessler())
2309 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2310 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2312 sz = (memconfig1 >> 16) & 0xFF;
2313 sz = ((unsigned char) ~sz) + 1;
2319 * bi_dram[1].size contains all DMC1 memory size
2321 gd->bd->bi_dram[1].size = (size + sz) << 20;
2326 /* Used for sleep test */
2327 static unsigned char saved_val[4][2];
2328 void board_sleep_init_late(void)
2330 /* CODEC_LDO_EN: GPF3[4] */
2331 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2332 /* CODEC_XTAL_EN: GPH3[2] */
2333 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2335 /* MMC T_FLASH off */
2336 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2338 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2339 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2340 /* MHL_ON for REV02 or higher */
2341 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2344 void board_sleep_init(void)
2347 unsigned char val[2];
2350 if (max8998_probe())
2353 if (mach_is_kessler()) {
2355 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2356 saved_val[0][0] = val[0];
2357 saved_val[0][1] = val[1];
2358 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2359 (1 << 1) | (1 << 0));
2360 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2361 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2364 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2365 saved_val[1][0] = val[0];
2366 saved_val[1][1] = val[1];
2367 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2368 (1 << 2) | (1 << 1) | (1 << 0));
2370 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2371 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2374 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2375 saved_val[2][0] = val[0];
2376 saved_val[2][1] = val[1];
2377 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2378 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2379 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2382 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2383 saved_val[3][0] = val[0];
2384 saved_val[3][1] = val[1];
2385 val[0] &= ~((1 << 6) | (1 << 4));
2386 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2387 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2389 printf("Turned off regulators with Kessler setting."
2390 " Preparing to sleep. [%s:%d]\n",
2391 __FILE__, __LINE__);
2392 } else { /* Default */
2394 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2395 saved_val[0][0] = val[0];
2396 saved_val[0][1] = val[1];
2397 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2398 (1 << 1) | (1 << 0));
2399 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2400 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2403 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2404 saved_val[1][0] = val[0];
2405 saved_val[1][1] = val[1];
2406 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2407 (1 << 2) | (1 << 1) | (1 << 0));
2409 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2410 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2413 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2414 saved_val[2][0] = val[0];
2415 saved_val[2][1] = val[1];
2416 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2417 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2418 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2421 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2422 saved_val[3][0] = val[0];
2423 saved_val[3][1] = val[1];
2424 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2425 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2426 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2428 printf("Turned off regulators with default(Aquila) setting."
2429 " Preparing to sleep. [%s:%d]\n",
2430 __FILE__, __LINE__);
2434 void board_sleep_resume(void)
2437 unsigned char val[2];
2442 if (max8998_probe())
2446 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2447 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2449 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2450 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2452 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2453 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2455 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2456 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2457 printf("Waked up.\n");
2459 /* check max17040 */
2466 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2468 static int s5pc1xx_phy_control(int on)
2472 if (on && !status) {
2473 #ifdef CONFIG_CMD_PMIC
2474 run_command("pmic ldo 3 on", 0);
2477 if (board_is_limo_universal() ||
2478 board_is_limo_real() ||
2480 /* check usb path */
2481 if (board_is_limo_real() && !hwrevision(6))
2485 if (mach_is_tickertape())
2486 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2487 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2489 /* USB Path to AP */
2490 micro_usb_switch(0);
2492 } else if (!on && status) {
2493 #ifdef CONFIG_CMD_PMIC
2494 run_command("pmic ldo 3 off", 0);
2503 struct s3c_plat_otg_data s5pc110_otg_data = {
2504 .phy_control = s5pc1xx_phy_control,
2505 .regs_phy = S5PC110_PHY_BASE,
2506 .regs_otg = S5PC110_OTG_BASE,
2509 int board_eth_init(bd_t *bis)
2513 if (cpu_is_s5pc100())
2516 s3c_udc_probe(&s5pc110_otg_data);
2517 if (usb_eth_initialize(bis) >= 0)
2523 #ifdef CONFIG_CMD_USBDOWN
2524 int usb_board_init(void)
2526 #ifdef CONFIG_CMD_PMIC
2527 run_command("pmic ldo 3 on", 0);
2530 if (cpu_is_s5pc100()) {
2531 #ifdef CONFIG_HARD_I2C
2532 uchar val[2] = {0,};
2535 if (i2c_read(0x66, 0, 1, val, 2)) {
2536 printf("i2c_read error\n");
2543 if (i2c_write(0x66, 0, 1, val, 2)) {
2544 printf("i2c_write error\n");
2547 i2c_read(0x66, 0, 1, val, 2);
2553 if (board_is_limo_universal() ||
2554 board_is_limo_real() ||
2556 /* check usb path */
2557 if (board_is_limo_real() && !hwrevision(6))
2561 if (mach_is_tickertape())
2562 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2563 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2565 /* USB Path to AP */
2566 micro_usb_switch(0);
2572 #ifdef CONFIG_GENERIC_MMC
2573 int s5p_no_mmc_support(void)
2575 if (mach_is_wmg160())
2580 int board_mmc_init(bd_t *bis)
2584 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2587 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2588 if (mach_is_kessler())
2589 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2591 if (mach_is_wmg160())
2594 /* MMC0 Clock source = SCLKMPLL */
2595 reg = readl(&clk->src4);
2598 writel(reg, &clk->src4);
2600 reg = readl(&clk->div4);
2603 /* set div value near 50MHz */
2604 clock = get_pll_clk(MPLL) / 1000000;
2605 for (i = 0; i < 0xf; i++) {
2606 if ((clock / (i + 1)) <= 50) {
2612 writel(reg, &clk->div4);
2618 * GPG0[2] SD_0_CDn -> Not used
2619 * GPG0[3:6] SD_0_DATA[0:3]
2621 for (i = 0; i < 7; i++) {
2624 /* GPG0[0:6] special function 2 */
2625 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2626 /* GPG0[0:6] pull disable */
2627 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2628 /* GPG0[0:6] drv 4x */
2629 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2632 if (mach_is_geminus()) {
2633 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2634 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2637 return s5pc1xx_mmc_init(0);
2641 #ifdef CONFIG_CMD_PMIC
2642 static int pmic_status(void)
2644 unsigned char addr, val[2];
2649 if (max8998_probe())
2653 i2c_read(addr, reg, 1, val, 1);
2654 for (i = 7; i >= 4; i--)
2655 printf("BUCK%d %s\n", 7 - i + 1,
2656 val[0] & (1 << i) ? "on" : "off");
2658 printf("LDO%d %s\n", 5 - i,
2659 val[0] & (1 << i) ? "on" : "off");
2661 i2c_read(addr, reg, 1, val, 1);
2662 for (i = 7; i >= 0; i--)
2663 printf("LDO%d %s\n", 7 - i + 6,
2664 val[0] & (1 << i) ? "on" : "off");
2666 i2c_read(addr, reg, 1, val, 1);
2667 for (i = 7; i >= 4; i--)
2668 printf("LDO%d %s\n", 7 - i + 14,
2669 val[0] & (1 << i) ? "on" : "off");
2672 i2c_read(addr, reg, 1, val, 1);
2673 for (i = 7; i >= 6; i--)
2674 printf("SAFEOUT%d %s\n", 7 - i + 1,
2675 val[0] & (1 << i) ? "on" : "off");
2679 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2681 unsigned char addr, val[2];
2682 unsigned int reg, shift;
2690 } else if (ldo <= 13) {
2693 } else if (ldo <= 17) {
2695 shift = 17 - ldo + 4;
2702 shift = 4 - buck + 4;
2703 } else if (safeout) {
2707 shift = 8 - safeout;
2713 if (max8998_probe())
2716 i2c_read(addr, reg, 1, val, 1);
2718 val[0] |= (1 << shift);
2720 val[0] &= ~(1 << shift);
2721 i2c_write(addr, reg, 1, val, 1);
2722 i2c_read(addr, reg, 1, val, 1);
2725 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2726 val[0] & (1 << shift) ? "on" : "off");
2728 printf("buck %d value 0x%x, %s\n", buck, val[0],
2729 val[0] & (1 << shift) ? "on" : "off");
2731 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2732 val[0] & (1 << shift) ? "on" : "off");
2737 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2739 int buck = 0, ldo = 0, safeout = 0, on = -1;
2743 if (strncmp(argv[1], "status", 6) == 0)
2744 return pmic_status();
2747 if (strncmp(argv[1], "ldo", 3) == 0)
2748 ldo = simple_strtoul(argv[2], NULL, 10);
2749 else if (strncmp(argv[1], "buck", 4) == 0)
2750 buck = simple_strtoul(argv[2], NULL, 10);
2751 else if (strncmp(argv[1], "safeout", 7) == 0)
2752 safeout = simple_strtoul(argv[2], NULL, 10);
2756 if (strncmp(argv[3], "on", 2) == 0)
2758 else if (strncmp(argv[3], "off", 3) == 0)
2763 return pmic_ldo_control(buck, ldo, safeout, on);
2774 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2775 "PMIC LDO & BUCK control",
2776 "status - Display PMIC LDO & BUCK status\n"
2777 "pmic ldo num on/off - Turn on/off the LDO\n"
2778 "pmic buck num on/off - Turn on/off the BUCK\n"
2779 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2783 #ifdef CONFIG_CMD_DEVICE_POWER
2784 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2788 if (strncmp(argv[1], "cp", 2) == 0) {
2789 micro_usb_switch(1);
2790 pmic_ldo_control(0, 0, 2, 1);
2791 setenv("usb", "cp");
2792 } else if (strncmp(argv[1], "ap", 2) == 0) {
2793 micro_usb_switch(0);
2794 pmic_ldo_control(0, 0, 2, 0);
2795 setenv("usb", "ap");
2805 printf("USB Path is set to %s\n", getenv("usb"));
2811 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2813 "cp - switch to CP\n"
2814 "microusb ap - switch to AP\n"