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 */
192 #define SPLIT_SCREEN_FEATURE 0x100
194 /* board is MACH_AQUILA and board is like below. */
195 #define J1_B2_BOARD 0x0200
196 #define LIMO_UNIVERSAL_BOARD 0x0400
197 #define LIMO_REAL_BOARD 0x0800
198 #define MEDIA_BOARD 0x1000
199 #define BAMBOO_BOARD 0x2000
201 /* board is MACH_KESSLER and board is like below */
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 machine_is_aquila(void)
214 return (gd->bd->bi_arch_number == MACH_AQUILA);
217 static int machine_is_tickertape(void)
219 return c110_machine_id() == MACH_TICKERTAPE;
222 static int machine_is_geminus(void)
224 return c110_machine_id() == MACH_GEMINUS;
227 static int machine_is_cypress(void)
229 return c110_machine_id() == MACH_CYPRESS;
232 static int board_is_limo_universal(void)
234 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
237 static int board_is_limo_real(void)
239 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
242 static int board_is_media(void)
244 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
247 static int board_is_j1b2(void)
249 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
253 static int machine_is_kessler(void)
255 return gd->bd->bi_arch_number == MACH_KESSLER;
258 static int board_is_neptune(void)
260 return machine_is_kessler() && (board_rev & NEPTUNE_BOARD);
264 static int machine_is_wmg160(void)
266 return c110_machine_id() == MACH_WMG160;
269 static void check_battery(int mode);
271 void i2c_init_board(void)
273 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
276 if (cpu_is_s5pc100())
279 num_bus = ARRAY_SIZE(i2c_gpio);
281 if (machine_is_aquila()) {
282 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
283 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
284 } else if (machine_is_kessler()) {
285 i2c_gpio[I2C_GPIO7].bus->gpio_base =
286 (unsigned int)&gpio->gpio_mp0_5;
287 } else if (machine_is_cypress()) {
288 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
289 i2c_gpio[I2C_GPIO7].bus->gpio_base =
290 (unsigned int)&gpio->gpio_mp0_5;
292 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
295 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
296 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
297 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
298 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
299 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
301 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
303 /* Reset on max17040 early */
304 if (battery_soc == 0)
308 #ifdef CONFIG_MISC_INIT_R
309 #define DEV_INFO_LEN 256
310 static char device_info[DEV_INFO_LEN];
311 static int display_info;
313 static void empty_device_info_buffer(void)
315 memset(device_info, 0x0, DEV_INFO_LEN);
318 static void dprintf(const char *fmt, ...)
325 i = vsprintf(buf, fmt, args);
330 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
331 puts("Flushing device info...\n");
333 empty_device_info_buffer();
335 strncat(device_info, buf, 127);
339 #ifdef CONFIG_S5PC1XXFB
340 static void display_device_info(void)
347 set_font_color(FONT_WHITE);
348 fb_printf(device_info);
351 memset(device_info, 0x0, DEV_INFO_LEN);
353 udelay(5 * 1000 * 1000);
357 static const char *board_name[] = {
361 "P1P2", /* Don't remove it */
374 static char feature_buffer[32];
376 static char *display_features(int board, int board_rev)
379 char *buf = feature_buffer;
382 if (board == MACH_AQUILA) {
383 if (board_rev & SPLIT_SCREEN_FEATURE)
384 name = "SplitScreen";
385 if (board_rev & J1_B2_BOARD)
387 /* Limo Real or Universal */
388 if (board_rev & LIMO_REAL_BOARD)
390 else if (board_rev & LIMO_UNIVERSAL_BOARD)
391 name = "Limo Universal";
392 if (board_rev & MEDIA_BOARD)
394 if (board_rev & BAMBOO_BOARD)
396 } else if (board == MACH_KESSLER) {
397 if (board_rev & NEPTUNE_BOARD)
401 count += sprintf(buf + count, " - %s", name);
406 static char *get_board_name(int board)
408 if (board == MACH_AQUILA)
410 else if (board == MACH_KESSLER)
412 else if (board == MACH_WMG160)
414 return (char *) board_name[board];
417 static void check_board_revision(int board, int rev)
419 if (board == MACH_AQUILA) {
420 /* Limo Real or Universal */
421 if (rev & LIMO_UNIVERSAL_BOARD)
422 board_rev &= ~J1_B2_BOARD;
423 if (rev & LIMO_REAL_BOARD)
424 board_rev &= ~(J1_B2_BOARD |
425 LIMO_UNIVERSAL_BOARD);
426 if (rev & MEDIA_BOARD)
427 board_rev &= ~(J1_B2_BOARD |
428 LIMO_UNIVERSAL_BOARD);
429 if (rev & BAMBOO_BOARD)
430 board_rev &= ~(J1_B2_BOARD |
431 LIMO_UNIVERSAL_BOARD |
434 } else if (board == MACH_KESSLER) {
435 if (rev & KESSLER_BOARD)
436 board_rev &= ~(J1_B2_BOARD |
437 LIMO_UNIVERSAL_BOARD);
438 if (rev & NEPTUNE_BOARD)
439 board_rev &= ~(J1_B2_BOARD |
440 LIMO_UNIVERSAL_BOARD);
442 board_rev &= ~BOARD_MASK;
446 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
454 gpio_direction_input(bank, 2);
455 gpio_direction_input(bank, 3);
456 gpio_direction_input(bank, 4);
457 gpio_direction_input(bank, mode3);
459 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
460 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
461 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
462 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
464 rev = gpio_get_value(bank, 2);
465 rev |= (gpio_get_value(bank, 3) << 1);
466 rev |= (gpio_get_value(bank, 4) << 2);
467 rev |= (gpio_get_value(bank, mode3) << 3);
472 static void check_hw_revision(void)
474 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
476 if (cpu_is_s5pc100()) {
477 struct s5pc100_gpio *gpio =
478 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
480 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
482 /* C100 TickerTape */
484 board = MACH_TICKERTAPE;
486 struct s5pc110_gpio *gpio =
487 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
493 * Note Check 'Aquila' board first
497 * LRA: Limo Real Aquila
498 * LUA: Limo Universal Aquila
503 * ADDR = 0xE0200000 + OFF
505 * OFF Universal BB LRA LUA OA TT SS CYP
506 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
507 * J2: 0x0284 0x01 0x10 0x00
508 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
509 * H3: 0x0C64 0x03 0x07 0x0F
510 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
511 * I: 0x0224 0x02 0x00 0x08
512 * MP03: 0x0324 0x9x 0xbx 0x9x
513 * MP05: 0x0364 0x80 0x88
517 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
519 board_rev |= J1_B2_BOARD;
521 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
522 gpio_direction_input(&gpio->gpio_j2, 6);
525 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
526 board_rev |= LIMO_UNIVERSAL_BOARD;
528 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
529 board_rev |= LIMO_REAL_BOARD;
531 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
532 board_rev |= MEDIA_BOARD;
534 /* set gpio to default value. */
535 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
536 gpio_direction_output(&gpio->gpio_j2, 6, 0);
539 /* Workaround: C110 Aquila Rev0.6 */
540 if (board_rev == 6) {
542 board_rev |= LIMO_REAL_BOARD;
545 /* C110 Aquila Bamboo */
546 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
548 board_rev |= BAMBOO_BOARD;
551 /* C110 TickerTape */
552 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
553 gpio_get_value(&gpio->gpio_d1, 1) == 0)
554 board = MACH_TICKERTAPE;
556 /* WMG160 - GPH3[0:4] = 0x00 */
557 if (board == MACH_TICKERTAPE) {
560 for (i = 0; i < 4; i++) {
561 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
572 /* C110 Geminus for rev0.0 */
573 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
574 gpio_direction_input(&gpio->gpio_j1, 2);
575 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
576 board = MACH_GEMINUS;
577 if ((board_rev & ~BOARD_MASK) == 3)
580 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
581 gpio_direction_output(&gpio->gpio_j1, 2, 0);
583 /* C110 Geminus for rev0.1 ~ */
584 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
585 gpio_direction_input(&gpio->gpio_j0, 6);
586 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
587 board = MACH_GEMINUS;
590 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
592 /* Kessler MP0_5[6] == 1 */
593 gpio_direction_input(&gpio->gpio_mp0_5, 6);
594 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
595 /* Cypress: Do this for cypress */
596 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
597 gpio_direction_input(&gpio->gpio_j2, 2);
598 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
599 board = MACH_CYPRESS;
600 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
602 board = MACH_KESSLER;
603 board_rev |= KESSLER_BOARD;
605 /* Neptune MP0_5[4] == 1 */
606 gpio_direction_input(&gpio->gpio_mp0_5, 4);
607 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
608 board_rev &= ~KESSLER_BOARD;
609 board_rev |= NEPTUNE_BOARD;
612 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
615 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
618 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
622 if (board < MACH_PSEUDO_END) {
623 if (cpu_is_s5pc110())
624 gd->bd->bi_arch_number = C110_MACH_START + board;
626 gd->bd->bi_arch_number = C100_MACH_START + board;
628 gd->bd->bi_arch_number = board;
631 /* Architecture Common settings */
632 if (cpu_is_s5pc110()) {
633 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
635 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
637 setenv("updatek", "onenand erase 0x60000 0x300000; "
638 "onenand write 0x31008000 0x60000 0x300000");
642 static void show_hw_revision(void)
647 * Workaround for Rev 0.3 + CP Ver ES 3.1
650 if (board_is_limo_real()) {
652 /* default is Rev 0.4 */
658 if (machine_is_kessler() || machine_is_aquila())
659 board = gd->bd->bi_arch_number;
660 else if (cpu_is_s5pc110())
661 board = gd->bd->bi_arch_number - C110_MACH_START;
663 board = gd->bd->bi_arch_number - C100_MACH_START;
666 check_board_revision(board, board_rev);
668 /* Set CPU Revision */
669 if (machine_is_aquila()) {
670 if (board_is_limo_real()) {
671 if ((board_rev & 0xf) < 8)
672 s5pc1xx_set_cpu_rev(0);
674 } else if (machine_is_kessler()) {
675 s5pc1xx_set_cpu_rev(1);
676 } else if (machine_is_geminus()) {
677 if ((board_rev & 0xf) < 1)
678 s5pc1xx_set_cpu_rev(0);
679 } else if (machine_is_cypress()) {
680 s5pc1xx_set_cpu_rev(1);
682 s5pc1xx_set_cpu_rev(0);
685 empty_device_info_buffer();
686 dprintf("HW Revision:\t%x (%s%s) %s\n",
687 board_rev, get_board_name(board),
688 display_features(board, board_rev),
689 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
692 static void check_auto_burn(void)
694 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
695 unsigned int count = 0;
698 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
699 printf("Auto burning bootloader\n");
700 count += sprintf(buf + count, "run updateb; ");
702 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
703 printf("Auto burning kernel\n");
704 count += sprintf(buf + count, "run updatek; ");
708 count += sprintf(buf + count, "reset");
709 setenv("bootcmd", buf);
712 /* Clear the magic value */
713 writel(0xa5a55a5a, magic_base);
714 writel(0xa5a55a5a, magic_base + 0x4);
717 static void pmic_pin_init(void)
719 unsigned int reg, value;
721 if (cpu_is_s5pc100())
724 /* AP_PS_HOLD: XEINT_0: GPH0[0]
725 * Note: Don't use GPIO PS_HOLD it doesn't work
727 reg = S5PC110_PS_HOLD_CONTROL;
729 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
730 S5PC110_PS_HOLD_DATA_HIGH |
731 S5PC110_PS_HOLD_OUT_EN;
734 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
735 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
736 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
739 static void enable_ldos(void)
741 if (cpu_is_s5pc100())
744 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
745 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
748 static void enable_t_flash(void)
750 if (!(board_is_limo_universal() || board_is_limo_real()))
753 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
754 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
757 static void setup_limo_real_gpios(void)
759 if (!board_is_limo_real())
763 * Note: Please write GPIO alphabet order
765 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
766 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
769 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
770 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
772 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
773 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
775 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
776 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
777 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
780 static void setup_media_gpios(void)
782 if (!board_is_media())
786 * Note: Please write GPIO alphabet order
788 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
789 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
791 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
792 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
793 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
796 #define KBR3 (1 << 3)
797 #define KBR2 (1 << 2)
798 #define KBR1 (1 << 1)
799 #define KBR0 (1 << 0)
801 static void check_keypad(void)
803 unsigned int reg, value;
804 unsigned int col_num, row_num;
805 unsigned int col_mask;
806 unsigned int col_mask_shift;
807 unsigned int row_state[4];
809 unsigned int auto_download = 0;
811 if (machine_is_wmg160())
814 if (cpu_is_s5pc100()) {
815 struct s5pc100_gpio *gpio =
816 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
821 /* Set GPH2[2:0] to KP_COL[2:0] */
822 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
823 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
824 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
826 /* Set GPH3[2:0] to KP_ROW[2:0] */
827 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
828 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
829 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
831 reg = S5PC100_KEYPAD_BASE;
832 col_mask = S5PC1XX_KEYIFCOL_MASK;
835 if (board_is_limo_real() || board_is_limo_universal()) {
843 for (i = 0; i < row_num; i++) {
844 /* Set GPH3[3:0] to KP_ROW[3:0] */
845 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
846 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
849 for (i = 0; i < col_num; i++)
850 /* Set GPH2[3:0] to KP_COL[3:0] */
851 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
853 reg = S5PC110_KEYPAD_BASE;
854 col_mask = S5PC110_KEYIFCOLEN_MASK;
858 /* KEYIFCOL reg clear */
859 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
862 for (i = 0; i < col_num; i++) {
864 value &= ~(1 << i) << col_mask_shift;
866 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
869 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
870 row_state[i] = ~value & ((1 << row_num) - 1);
872 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
875 /* KEYIFCOL reg clear */
876 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
878 if (machine_is_aquila() || machine_is_kessler()) {
880 if (row_state[1] & 0x2)
882 if (board_is_neptune()) {
883 /* home & volume down */
884 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
887 /* cam full shot & volume down */
888 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
891 } else if (machine_is_geminus())
892 /* volume down & home */
893 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
897 setenv("bootcmd", "usbdown");
900 static void check_battery(int mode)
902 unsigned char val[2];
903 unsigned char addr = 0x36; /* max17040 fuel gauge */
905 i2c_set_bus_num(I2C_GPIO3);
907 if (machine_is_aquila()) {
910 } else if (machine_is_kessler()) {
911 i2c_set_bus_num(I2C_GPIO7);
912 } else if (machine_is_cypress()) {
913 i2c_set_bus_num(I2C_GPIO7);
914 } else if (machine_is_geminus()) {
916 i2c_set_bus_num(I2C_GPIO7);
920 if (i2c_probe(addr)) {
921 printf("Can't found max17040 fuel gauge\n");
925 /* mode 0: check mode / 1: enable mode */
929 i2c_write(addr, 0xfe, 1, val, 2);
931 i2c_read(addr, 0x04, 1, val, 1);
932 dprintf("battery:\t%d%%\n", val[0]);
933 battery_soc = val[0];
937 static void check_mhl(void)
939 unsigned char val[2];
940 unsigned char addr = 0x39; /* SIL9230 */
942 /* MHL Power enable */
943 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
944 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
946 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
947 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
949 /* 10ms required after reset */
953 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
955 i2c_set_bus_num(I2C_GPIO5);
958 if (i2c_probe(addr)) {
959 printf("Can't found MHL Chip\n");
965 * set to Normal operation
968 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
969 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
974 * 00 = MHL termination ON
975 * 11 = MHL termination OFF
978 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
979 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
982 static int max8998_probe(void)
984 unsigned char addr = 0xCC >> 1;
986 i2c_set_bus_num(I2C_PMIC);
988 if (i2c_probe(addr)) {
989 printf("Can't found max8998\n");
996 #define CHARGER_ANIMATION_FRAME 6
997 static void max8998_clear_interrupt(void)
999 unsigned char addr, val[2];
1002 if (max8998_probe())
1005 i2c_read(addr, 0x00, 1, val, 1);
1006 i2c_read(addr, 0x01, 1, val, 1);
1007 i2c_read(addr, 0x02, 1, val, 1);
1008 i2c_read(addr, 0x03, 1, val, 1);
1011 static int max8998_power_key(void)
1013 unsigned char addr, val[2];
1016 if (max8998_probe())
1019 /* Accessing IRQ1 register */
1020 i2c_read(addr, 0x00, 1, val, 1);
1021 if (val[0] & (1 << 6))
1027 static int max8998_has_ext_power_source(void)
1029 unsigned char addr, val[2];
1032 if (max8998_probe())
1035 /* Accessing STATUS2 register */
1036 i2c_read(addr, 0x09, 1, val, 1);
1037 if (val[0] & (1 << 5))
1043 struct thermister_stat {
1048 static struct thermister_stat adc_to_temperature_data[] = {
1049 { .centigrade = -20, .adc = 1856, },
1050 { .centigrade = -15, .adc = 1799, },
1051 { .centigrade = -10, .adc = 1730, },
1052 { .centigrade = -5, .adc = 1649, },
1053 { .centigrade = 0, .adc = 1556, },
1054 { .centigrade = 5, .adc = 1454, },
1055 { .centigrade = 10, .adc = 1343, },
1056 { .centigrade = 15, .adc = 1227, },
1057 { .centigrade = 20, .adc = 1109, },
1058 { .centigrade = 25, .adc = 992, },
1059 { .centigrade = 30, .adc = 880, },
1060 { .centigrade = 35, .adc = 773, },
1061 { .centigrade = 40, .adc = 675, },
1062 { .centigrade = 45, .adc = 586, },
1063 { .centigrade = 50, .adc = 507, },
1064 { .centigrade = 55, .adc = 436, },
1065 { .centigrade = 58, .adc = 399, },
1066 { .centigrade = 63, .adc = 343, },
1067 { .centigrade = 65, .adc = 322, },
1071 #define USHRT_MAX 0xFFFFU
1073 static int adc_to_temperature_centigrade(unsigned short adc)
1077 /* low_*: Greatest Lower Bound,
1078 * * * * high_*: Smallest Upper Bound */
1079 int low_temp = 0, high_temp = 0;
1080 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1081 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1082 if (adc_to_temperature_data[i].adc <= adc &&
1083 adc_to_temperature_data[i].adc >= low_adc) {
1084 low_temp = adc_to_temperature_data[i].centigrade;
1085 low_adc = adc_to_temperature_data[i].adc;
1087 if (adc_to_temperature_data[i].adc >= adc &&
1088 adc_to_temperature_data[i].adc <= high_adc) {
1089 high_temp = adc_to_temperature_data[i].centigrade;
1090 high_adc = adc_to_temperature_data[i].adc;
1094 /* Linear approximation between cloest low and high,
1095 * which is the weighted average of the two. */
1097 /* The following equation is correct only when the two are different */
1098 if (low_adc == high_adc)
1100 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1101 return 20; /* The room temperature */
1104 if (high_adc == USHRT_MAX)
1107 approximation = low_temp * (adc - low_adc) +
1108 high_temp * (high_adc - adc);
1109 approximation /= high_adc - low_adc;
1111 return approximation;
1114 static unsigned short get_adc_value(int channel)
1116 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1117 unsigned short ret = 0;
1121 unsigned int loop = 0;
1123 if (machine_is_kessler())
1125 else if (machine_is_geminus())
1127 else if (machine_is_wmg160())
1129 else if (machine_is_cypress())
1131 else if (machine_is_tickertape())
1133 else if (machine_is_aquila())
1136 else if (machine_is_p1p2())
1140 sprintf(buf, "pmic ldo %d on", ldonum);
1141 run_command(buf, 0);
1143 writel(channel & 0xF, &adc->adcmux);
1144 writel((1 << 14) | (49 << 6), &adc->adccon);
1145 writel(1000 & 0xffff, &adc->adcdly);
1146 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1148 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1153 reg = readl(&adc->adccon);
1154 } while (!reg & (1 << 15) && loop++ < 1000);
1156 ret = readl(&adc->adcdat0) & 0xFFF;
1157 sprintf(buf, "pmic ldo %d off", ldonum);
1158 run_command(buf, 0);
1163 static int adc_get_average_ambient_temperature(void)
1165 if (machine_is_kessler()) {
1166 unsigned short min = USHRT_MAX;
1167 unsigned short max = 0;
1168 unsigned int sum = 0;
1169 unsigned int measured = 0;
1172 for (i = 0; i < 7; i++) {
1173 unsigned short measurement = get_adc_value(6);
1176 if (min > measurement)
1178 if (max < measurement)
1181 if (measured >= 3) {
1187 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1188 adc_to_temperature_centigrade(sum), sum);
1189 return adc_to_temperature_centigrade(sum);
1192 return 20; /* 20 Centigrade */
1195 enum temperature_level {
1203 static enum temperature_level temperature_check(void)
1205 int temp = adc_get_average_ambient_temperature();
1207 return _TEMP_TOO_LOW;
1209 return _TEMP_OK_LOW;
1211 return _TEMP_TOO_HIGH;
1213 return _TEMP_OK_HIGH;
1217 extern void lcd_display_clear(void);
1218 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1220 static void charger_en(int enable)
1226 unsigned char addr = 0xCC >> 1; /* max8998 */
1227 unsigned char val[2];
1229 if (max8998_probe())
1233 printf("Disable the charger.\n");
1234 i2c_read(addr, 0x0D, 1, val, 1);
1237 i2c_write(addr, 0x0D, 1, val, 1);
1239 i2c_read(addr, 0x0C, 1, val, 1);
1240 val[0] &= ~(0x7 << 0);
1241 val[0] &= ~(0x7 << 5);
1242 if (enable == 600) {
1243 val[0] |= 5; /* 600mA */
1244 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1245 } else { /* Assume 475 mA */
1247 val[0] |= 2; /* 475mA */
1248 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1250 i2c_write(addr, 0x0C, 1, val, 1);
1252 i2c_read(addr, 0x0D, 1, val, 1);
1254 i2c_write(addr, 0x0D, 1, val, 1);
1255 printf("Enable the charger @ %dmA\n", enable);
1259 void lcd_power_on(unsigned int onoff);
1260 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1261 extern int drv_lcd_init_resume (void);
1263 static void into_charge_mode(void)
1269 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1270 unsigned int reg, wakeup_stat;
1271 int charger_speed = 600;
1273 max8998_clear_interrupt();
1275 printf("Charge Mode\n");
1276 charger_en(charger_speed);
1278 #ifdef CONFIG_S5PC1XXFB
1281 /* TODO: write the image-text for the charger */
1283 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1284 if (level >= CHARGER_ANIMATION_FRAME)
1285 level = CHARGER_ANIMATION_FRAME - 1;
1287 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1288 bmp_addr[i] = (ulong)battery_charging_animation[i];
1290 lcd_display_clear();
1291 for (i = 0; i < 3; i++) {
1292 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1295 bmp = gunzip_bmp(bmp_addr[j], &len);
1296 lcd_display_bitmap((ulong)bmp, 140, 202);
1299 for (k = 0; k < 10; k++) {
1300 if (max8998_power_key()) {
1301 lcd_display_clear();
1302 goto restore_screen;
1303 } else if (!max8998_has_ext_power_source()) {
1304 lcd_display_clear();
1305 goto restore_screen;
1314 /* Disable the display to prevent flickering */
1315 /* TODO: how to reenable the display later? */
1319 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1320 unsigned int org, org_ip3;
1321 enum temperature_level previous_state = _TEMP_OK;
1323 empty_device_info_buffer();
1324 if (max8998_power_key())
1326 else if (!max8998_has_ext_power_source())
1329 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1330 org_ip3 = readl(0xE010046C);
1331 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1333 reg = org = readl(&rtc->rtccon);
1335 writel(reg, &rtc->rtccon);
1337 reg = readl(&rtc->rtccon);
1338 writel(reg | (1 << 3), &rtc->rtccon);
1340 writel(reg & ~(1 << 3), &rtc->rtccon);
1343 reg = readl(&rtc->rtccon);
1344 reg &= ~((1 << 8) | (0xF << 4));
1345 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1346 writel(reg, &rtc->rtccon);
1348 reg = 15 * 4 - 1; /* 15 sec */
1349 writel(reg, &rtc->ticcnt);
1351 /* EVT0: sleep 1, EVT1: sleep */
1352 if (cpu_is_s5pc110()) {
1353 char *name = "dummy";
1354 char *usage = "N/A";
1361 if (s5pc1xx_get_cpu_rev() == 0) {
1362 char *argv[] = {"1", "1"};
1363 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1365 char *argv[] = {"0", "0"};
1366 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1369 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1373 /* Check TEMP HIGH/LOW */
1374 switch (temperature_check()) {
1376 charger_en(charger_speed);
1377 previous_state = _TEMP_OK;
1381 previous_state = _TEMP_TOO_LOW;
1383 case _TEMP_TOO_HIGH:
1385 previous_state = _TEMP_TOO_HIGH;
1388 if (previous_state == _TEMP_TOO_LOW) {
1391 charger_en(charger_speed);
1392 previous_state = _TEMP_OK;
1396 if (previous_state == _TEMP_TOO_HIGH) {
1399 charger_en(charger_speed);
1400 previous_state = _TEMP_OK;
1405 writel(org, &rtc->rtccon);
1406 writel(org_ip3, 0xE010046C);
1408 } while (wakeup_stat == 0x04); /* RTC TICK */
1411 /* TODO: Reenable logo display (not working yet) */
1413 drv_lcd_init_resume();
1416 static int fsa9480_probe(void)
1418 unsigned char addr = 0x25;
1420 if (cpu_is_s5pc100())
1423 if (board_is_limo_real()) {
1424 if (hwrevision(0) || hwrevision(1))
1428 i2c_set_bus_num(I2C_PMIC);
1430 if (machine_is_kessler()) {
1431 i2c_set_bus_num(I2C_GPIO6);
1432 } else if (machine_is_cypress()) {
1433 i2c_set_bus_num(I2C_GPIO6);
1434 } else if (machine_is_geminus()) {
1436 i2c_set_bus_num(I2C_GPIO6);
1437 } else if (machine_is_wmg160()) {
1438 i2c_set_bus_num(I2C_GPIO6);
1441 if (i2c_probe(addr)) {
1442 printf("Can't found fsa9480\n");
1449 static void check_micro_usb(int intr)
1452 unsigned char val[2];
1453 static int started_charging_once = 0;
1456 if (fsa9480_probe())
1459 addr = 0x25; /* fsa9480 */
1461 /* Clear Interrupt */
1463 i2c_read(addr, 0x03, 1, val, 2);
1467 /* Read Device Type 1 */
1468 i2c_read(addr, 0x0a, 1, val, 1);
1470 #define FSA_DEV1_CHARGER (1 << 6)
1471 #define FSA_DEV1_UART (1 << 3)
1472 #define FSA_DEV1_USB (1 << 2)
1473 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1474 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1477 * If USB, use default 475mA
1478 * If Charger, use 600mA and go to charge mode
1480 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1481 started_charging_once = 1;
1483 /* If it's full, do not charge. */
1484 if (battery_soc < 100)
1488 } else if (val[0] & FSA_DEV1_USB) {
1489 if (battery_soc < 100)
1490 charger_en(475); /* enable charger and keep booting */
1495 /* If Factory Mode is Boot ON-USB, go to download mode */
1496 i2c_read(addr, 0x07, 1, val, 1);
1498 #define FSA_ADC_FAC_USB_OFF 0x18
1499 #define FSA_ADC_FAC_USB_ON 0x19
1500 #define FSA_ADC_FAC_UART 0x1d
1502 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1503 setenv("bootcmd", "usbdown");
1505 path = getenv("usb");
1507 if (!strncmp(path, "cp", 2))
1508 run_command("microusb cp", 0);
1511 static void micro_usb_switch(int path)
1514 unsigned char val[2];
1516 if (fsa9480_probe())
1519 addr = 0x25; /* fsa9480 */
1522 val[0] = 0x90; /* VAUDIO */
1524 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1526 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1528 i2c_read(addr, 0x2, 1, val, 1);
1529 val[0] &= ~(1 << 2); /* Manual switching */
1530 i2c_write(addr, 0x2, 1, val, 1);
1533 #define MAX8998_REG_ONOFF1 0x11
1534 #define MAX8998_REG_ONOFF2 0x12
1535 #define MAX8998_REG_ONOFF3 0x13
1536 #define MAX8998_REG_LDO7 0x21
1537 #define MAX8998_REG_LDO17 0x29
1539 #define MAX8998_LDO3 (1 << 2)
1541 #define MAX8998_LDO6 (1 << 7)
1542 #define MAX8998_LDO7 (1 << 6)
1543 #define MAX8998_LDO8 (1 << 5)
1544 #define MAX8998_LDO9 (1 << 4)
1545 #define MAX8998_LDO10 (1 << 3)
1546 #define MAX8998_LDO11 (1 << 2)
1547 #define MAX8998_LDO12 (1 << 1)
1548 #define MAX8998_LDO13 (1 << 0)
1550 #define MAX8998_LDO14 (1 << 7)
1551 #define MAX8998_LDO15 (1 << 6)
1552 #define MAX8998_LDO16 (1 << 5)
1553 #define MAX8998_LDO17 (1 << 4)
1556 static void init_pmic(void)
1559 unsigned char val[2];
1561 if (cpu_is_s5pc100())
1564 addr = 0xCC >> 1; /* max8998 */
1565 if (max8998_probe())
1569 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1570 val[0] &= ~MAX8998_LDO3;
1571 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1574 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1576 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1577 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1579 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1580 MAX8998_LDO12 | MAX8998_LDO13);
1582 if (machine_is_kessler())
1583 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1585 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1586 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1588 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1590 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1591 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1593 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1594 MAX8998_LDO16 | MAX8998_LDO17);
1596 if (machine_is_kessler())
1597 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1599 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1600 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1603 static void setup_power_down_mode_registers(void)
1605 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1606 struct s5pc1xx_gpio_bank *bank;
1607 struct gpio_powermode *p;
1609 struct gpio_external *ge;
1611 struct s5pc1xx_gpio_item *mr;
1615 if (cpu_is_s5pc100())
1618 /* Only Limo real and kessler supports worked for sleep currnet */
1619 if (machine_is_aquila()) {
1620 if (board_is_limo_real())
1624 } else if (machine_is_kessler()) {
1626 } else if (machine_is_geminus()) {
1632 if (machine_is_aquila()) {
1633 /* Aquila rev 0.8 or lower */
1634 p = aquila_powerdown_modes;
1635 ge = aquila_external_powerdown_modes;
1636 mr = aquila_mirror_powerdown_mode;
1637 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1638 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1639 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1640 } else if (machine_is_kessler()) {
1641 /* Aquila rev 0.9 */
1642 p = kessler_powerdown_modes;
1643 ge = kessler_external_powerdown_modes;
1644 mr = kessler_mirror_powerdown_mode;
1645 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1646 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1647 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1648 } else if (machine_is_geminus()) {
1649 if (hwrevision(1)) {
1650 /* Same as Aquila rev 0.9 */
1652 p = kessler_powerdown_modes;
1653 ge = kessler_external_powerdown_modes;
1654 mr = kessler_mirror_powerdown_mode;
1655 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1656 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1657 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1659 p = aquila_powerdown_modes;
1660 ge = aquila_external_powerdown_modes;
1661 mr = aquila_mirror_powerdown_mode;
1662 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1663 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1664 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1666 } else if (hwrevision(0)) {
1667 /* Same as Aquila rev 0.8 or lower */
1668 p = aquila_powerdown_modes;
1669 ge = aquila_external_powerdown_modes;
1670 mr = aquila_mirror_powerdown_mode;
1671 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1672 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1673 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1675 return; /* Not supported */
1679 bank = &gpio->gpio_a0;
1681 for (i = 0; i < n_p; i++, p++, bank++) {
1682 writel(p->conpdn, &bank->pdn_con);
1683 writel(p->pudpdn, &bank->pdn_pull);
1686 writel(0xff0022b0, (unsigned int *)0xF0000000);
1687 writel(0xff0022b0, (unsigned int *)0xF1400000);
1689 bank = &gpio->gpio_h0;
1691 for (i = 0; i < n_ge; i++) {
1692 writel(ge->con, &bank->con);
1693 writel(ge->dat, &bank->dat);
1694 writel(ge->pud, &bank->pull);
1700 for (i = 0; i < n_mr; i++) {
1701 unsigned int reg = readl(&mr->bank->pdn_con);
1702 reg &= ~(0x3 << (mr->number << 1));
1703 if (readl(&mr->bank->dat) & (1 << mr->number))
1704 reg |= 0x1 << (mr->number << 1);
1705 writel(reg, &mr->bank->pdn_con);
1711 #include "../../../drivers/video/s5p-spi.h"
1713 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1714 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1716 struct spi_platform_data spi_pd;
1718 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1720 void lcd_cfg_gpio(void)
1722 unsigned int i, f3_end = 4;
1724 for (i = 0; i < 8; i++) {
1725 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1726 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1727 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1728 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1729 /* pull-up/down disable */
1730 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1731 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1732 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1734 /* drive strength to max (24bit) */
1735 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1736 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1737 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1738 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1739 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1740 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1743 /* set DISPLAY_DE_B pin for dual rgb mode. */
1744 if (board_is_media())
1747 for (i = 0; i < f3_end; i++) {
1748 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1749 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1750 /* pull-up/down disable */
1751 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1752 /* drive strength to max (24bit) */
1753 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1754 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1756 /* display output path selection (only [1:0] valid) */
1757 writel(0x2, 0xE0107008);
1759 /* gpio pad configuration for LCD reset. */
1760 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1762 /* gpio pad configuration for LCD ON. */
1763 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1765 /* LCD_BACKLIGHT_EN */
1766 if (machine_is_geminus())
1767 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1768 if (board_is_neptune()) {
1769 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1770 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1774 * gpio pad configuration for
1775 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1777 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1778 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1779 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1780 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1782 if (machine_is_aquila() || machine_is_kessler()) {
1783 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1785 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1787 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1789 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1792 if (board_is_neptune())
1793 s6d16a0x_set_platform_data(&spi_pd);
1795 s6e63m0_set_platform_data(&spi_pd);
1796 if (board_is_media())
1801 if (machine_is_cypress()) {
1802 #if 0 /* universal cypress */
1804 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1807 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1809 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1811 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1813 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1815 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1816 #if 0 /* universal cypress */
1817 pd_cs.bank = &gpio_base->gpio_mp0_1;
1820 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1822 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1824 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1829 /* these data would be sent to s6e63m0 lcd panel driver. */
1830 s6e63m0_set_platform_data(&spi_pd);
1836 #define SWRST_REG 0x00
1837 #define LEDCON_REG 0x01
1838 #define LED_CUR_SET_REG 0x03
1839 #define LED_CUR_TR_REG 0x08
1842 #define NORMAL_MODE 0x01
1843 #define CUR_SET 0x63
1846 void backlight_on(unsigned int onoff)
1850 unsigned char val[2];
1851 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1854 if (machine_is_geminus())
1855 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1857 if (machine_is_geminus())
1858 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1861 if (machine_is_kessler() && board_is_neptune()) {
1862 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1865 i2c_set_bus_num(I2C_GPIO5);
1868 if (i2c_probe(addr)) {
1869 if (i2c_probe(addr)) {
1870 printf("Can't found s6d16a0x backlight i2c\n");
1875 i2c_write(addr, SWRST_REG, 1, val, 1);
1878 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1880 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1881 val[0] = NORMAL_MODE;
1882 i2c_write(addr, LEDCON_REG, 1, val, 1);
1887 void reset_lcd(void)
1889 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1891 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1892 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1893 if (machine_is_cypress())
1894 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1897 void lcd_power_on(unsigned int onoff)
1899 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1902 if (machine_is_aquila() || machine_is_geminus())
1903 gpio_set_value(&gpio->gpio_j1, 3, 1);
1905 if (machine_is_cypress())
1906 gpio_set_value(&gpio->gpio_g2, 2, 1);
1908 if (machine_is_kessler()) {
1910 unsigned char val[2];
1911 unsigned char val2[2];
1913 gpio_set_value(&gpio->gpio_j1, 3, 1);
1915 addr = 0xCC >> 1; /* max8998 */
1916 if (max8998_probe())
1919 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1920 val[0] &= ~(MAX8998_LDO17);
1921 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1922 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1924 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1925 val[0] |= MAX8998_LDO17;
1927 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1928 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1930 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1931 val[0] |= MAX8998_LDO7;
1933 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1934 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1937 if (machine_is_aquila() || machine_is_geminus())
1938 gpio_set_value(&gpio->gpio_j1, 3, 0);
1940 if (machine_is_cypress())
1941 gpio_set_value(&gpio->gpio_g2, 2, 0);
1943 if (machine_is_kessler()) {
1945 unsigned char val[2];
1947 gpio_set_value(&gpio->gpio_j1, 3, 0);
1949 addr = 0xCC >> 1; /* max8998 */
1950 if (max8998_probe())
1953 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1954 val[0] &= ~(MAX8998_LDO7);
1955 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1956 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1958 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1959 val[0] &= ~(MAX8998_LDO17);
1960 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1961 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1966 extern void s6e63m0_cfg_ldo(void);
1967 extern void s6e63m0_enable_ldo(unsigned int onoff);
1968 extern void s6d16a0x_cfg_ldo(void);
1969 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1971 int s5p_no_lcd_support(void)
1973 if (machine_is_wmg160())
1978 void init_panel_info(vidinfo_t *vid)
1980 vid->cfg_gpio = NULL;
1981 vid->reset_lcd = NULL;
1982 vid->backlight_on = NULL;
1983 vid->lcd_power_on = NULL;
1985 vid->cfg_ldo = NULL;
1986 vid->enable_ldo = NULL;
1988 vid->init_delay = 0;
1989 vid->reset_delay = 0;
1990 vid->power_on_delay = 0;
1995 vid->vl_width = 480;
1996 vid->vl_height = 800;
1998 vid->dual_lcd_enabled = 0;
2000 if (board_is_media()) {
2003 vid->vl_width = 960;
2004 vid->vl_height = 800;
2006 /* enable dual lcd mode. */
2007 vid->dual_lcd_enabled = 1;
2010 vid->vl_clkp = CONFIG_SYS_HIGH;
2011 vid->vl_hsp = CONFIG_SYS_LOW;
2012 vid->vl_vsp = CONFIG_SYS_LOW;
2013 vid->vl_dp = CONFIG_SYS_HIGH;
2016 /* S6E63M0 LCD Panel */
2025 if (machine_is_aquila() || machine_is_kessler()
2026 || machine_is_cypress()) {
2027 vid->cfg_gpio = lcd_cfg_gpio;
2028 vid->reset_lcd = reset_lcd;
2029 vid->backlight_on = backlight_on;
2030 vid->lcd_power_on = lcd_power_on;
2031 vid->cfg_ldo = s6e63m0_cfg_ldo;
2032 vid->enable_ldo = s6e63m0_enable_ldo;
2034 vid->init_delay = 25000;
2035 vid->reset_delay = 120000;
2038 if (board_is_neptune()) {
2042 vid->vl_width = 320;
2043 vid->vl_height = 480;
2045 vid->vl_clkp = CONFIG_SYS_HIGH;
2046 vid->vl_hsp = CONFIG_SYS_HIGH;
2047 vid->vl_vsp = CONFIG_SYS_HIGH;
2048 vid->vl_dp = CONFIG_SYS_LOW;
2051 /* disable dual lcd mode. */
2052 vid->dual_lcd_enabled = 0;
2054 /* S6D16A0X LCD Panel */
2063 vid->cfg_gpio = lcd_cfg_gpio;
2064 vid->backlight_on = backlight_on;
2065 vid->lcd_power_on = lcd_power_on;
2066 vid->reset_lcd = reset_lcd;
2067 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2068 vid->enable_ldo = s6d16a0x_enable_ldo;
2070 vid->init_delay = 10000;
2071 vid->power_on_delay = 10000;
2072 vid->reset_delay = 1000;
2076 if (machine_is_geminus()) {
2080 vid->vl_width = 1024,
2081 vid->vl_height = 600,
2082 vid->vl_clkp = CONFIG_SYS_LOW,
2083 vid->vl_hsp = CONFIG_SYS_HIGH,
2084 vid->vl_vsp = CONFIG_SYS_HIGH,
2085 vid->vl_dp = CONFIG_SYS_LOW,
2096 vid->cfg_gpio = lcd_cfg_gpio;
2097 vid->reset_lcd = reset_lcd;
2098 vid->backlight_on = backlight_on;
2099 vid->lcd_power_on = lcd_power_on;
2105 vid->vl_width = 480,
2106 vid->vl_height = 800,
2107 vid->vl_clkp = CONFIG_SYS_HIGH,
2108 vid->vl_hsp = CONFIG_SYS_LOW,
2109 vid->vl_vsp = CONFIG_SYS_LOW,
2110 vid->vl_dp = CONFIG_SYS_HIGH,
2126 vid->vl_width = 1024,
2127 vid->vl_height = 600,
2128 vid->vl_clkp = CONFIG_SYS_HIGH,
2129 vid->vl_hsp = CONFIG_SYS_HIGH,
2130 vid->vl_vsp = CONFIG_SYS_HIGH,
2131 vid->vl_dp = CONFIG_SYS_LOW,
2134 /* AMS701KA AMOLED Panel. */
2146 static void setup_meminfo(void)
2148 char meminfo[64] = {0, };
2149 int count = 0, size, real;
2151 size = gd->bd->bi_dram[0].size >> 20;
2152 count += sprintf(meminfo + count, "mem=%dM", size);
2154 /* Each Chip Select can't exceed the 256MiB */
2155 size = gd->bd->bi_dram[1].size >> 20;
2156 real = min(size, 256);
2157 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2158 real, (unsigned int)gd->bd->bi_dram[1].start);
2162 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2163 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2166 setenv("meminfo", meminfo);
2169 int misc_init_r(void)
2172 /* It should be located at first */
2175 if (machine_is_aquila() || machine_is_kessler()) {
2176 if (board_is_neptune())
2177 setenv("lcdinfo", "lcd=s6d16a0x");
2178 else if (board_is_media())
2179 setenv("lcdinfo", "lcd=s6e63m0");
2181 setenv("lcdinfo", "lcd=s6e63m0");
2183 if (machine_is_geminus())
2184 setenv("lcdinfo", "lcd=lms480jc01");
2185 if (machine_is_cypress())
2186 setenv("lcdinfo", "lcd=s6e63m0");
2192 /* Set proper PMIC pins */
2195 /* Check auto burning */
2198 /* To power up I2C2 */
2201 /* Enable T-Flash at Limo Real or Limo Universal */
2204 /* Setup Limo Real board GPIOs */
2205 setup_limo_real_gpios();
2207 /* Setup Media board GPIOs */
2208 setup_media_gpios();
2210 /* To usbdown automatically */
2216 #ifdef CONFIG_S5PC1XXFB
2217 display_device_info();
2220 setup_power_down_mode_registers();
2222 /* check max17040 */
2232 int board_init(void)
2234 /* Set Initial global variables */
2235 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2237 gd->bd->bi_arch_number = MACH_AQUILA;
2238 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2240 /* Check H/W Revision */
2241 check_hw_revision();
2248 unsigned int base, memconfig0, size;
2249 unsigned int memconfig1, sz = 0;
2251 if (cpu_is_s5pc100()) {
2252 /* In mem setup, we swap the bank. So below size is correct */
2253 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2254 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2255 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2258 /* In S5PC110, we can't swap the DMC0/1 */
2259 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2260 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2262 base = S5PC110_DMC1_BASE;
2263 /* DMC configuration */
2264 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2265 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2267 size = (memconfig0 >> 16) & 0xFF;
2268 size = ((unsigned char) ~size) + 1;
2271 * (0x07 + 1) * 16 = 128 MiB
2272 * (0x0f + 1) * 16 = 256 MiB
2277 * Aquila Rev0.5 4G3G1G
2278 * Aquila Rev0.8 4G3G1G
2279 * Aquila Rev0.9 4G3G1G
2281 if (machine_is_aquila() || machine_is_kessler())
2282 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2283 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2285 sz = (memconfig1 >> 16) & 0xFF;
2286 sz = ((unsigned char) ~sz) + 1;
2292 * bi_dram[1].size contains all DMC1 memory size
2294 gd->bd->bi_dram[1].size = (size + sz) << 20;
2299 /* Used for sleep test */
2300 static unsigned char saved_val[4][2];
2301 void board_sleep_init_late(void)
2303 /* CODEC_LDO_EN: GPF3[4] */
2304 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2305 /* CODEC_XTAL_EN: GPH3[2] */
2306 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2308 /* MMC T_FLASH off */
2309 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2311 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2312 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2313 /* MHL_ON for REV02 or higher */
2314 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2317 void board_sleep_init(void)
2320 unsigned char val[2];
2323 if (max8998_probe())
2326 if (machine_is_kessler()) {
2328 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2329 saved_val[0][0] = val[0];
2330 saved_val[0][1] = val[1];
2331 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2332 (1 << 1) | (1 << 0));
2333 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2334 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2337 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2338 saved_val[1][0] = val[0];
2339 saved_val[1][1] = val[1];
2340 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2341 (1 << 2) | (1 << 1) | (1 << 0));
2343 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2344 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2347 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2348 saved_val[2][0] = val[0];
2349 saved_val[2][1] = val[1];
2350 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2351 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2352 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2355 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2356 saved_val[3][0] = val[0];
2357 saved_val[3][1] = val[1];
2358 val[0] &= ~((1 << 6) | (1 << 4));
2359 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2360 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2362 printf("Turned off regulators with Kessler setting."
2363 " Preparing to sleep. [%s:%d]\n",
2364 __FILE__, __LINE__);
2365 } else { /* Default */
2367 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2368 saved_val[0][0] = val[0];
2369 saved_val[0][1] = val[1];
2370 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2371 (1 << 1) | (1 << 0));
2372 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2373 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2376 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2377 saved_val[1][0] = val[0];
2378 saved_val[1][1] = val[1];
2379 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2380 (1 << 2) | (1 << 1) | (1 << 0));
2382 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2383 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2386 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2387 saved_val[2][0] = val[0];
2388 saved_val[2][1] = val[1];
2389 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2390 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2391 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2394 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2395 saved_val[3][0] = val[0];
2396 saved_val[3][1] = val[1];
2397 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2398 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2401 printf("Turned off regulators with default(Aquila) setting."
2402 " Preparing to sleep. [%s:%d]\n",
2403 __FILE__, __LINE__);
2407 void board_sleep_resume(void)
2410 unsigned char val[2];
2415 if (max8998_probe())
2419 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2420 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2422 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2423 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2425 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2426 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2428 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2429 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2430 printf("Waked up.\n");
2432 /* check max17040 */
2439 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2441 static int s5pc1xx_phy_control(int on)
2445 if (on && !status) {
2446 #ifdef CONFIG_CMD_PMIC
2447 run_command("pmic ldo 3 on", 0);
2450 if (board_is_limo_universal() ||
2451 board_is_limo_real() ||
2453 /* check usb path */
2454 if (board_is_limo_real() && !hwrevision(6))
2458 if (machine_is_tickertape())
2459 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2460 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2462 /* USB Path to AP */
2463 micro_usb_switch(0);
2465 } else if (!on && status) {
2466 #ifdef CONFIG_CMD_PMIC
2467 run_command("pmic ldo 3 off", 0);
2476 struct s3c_plat_otg_data s5pc110_otg_data = {
2477 .phy_control = s5pc1xx_phy_control,
2478 .regs_phy = S5PC110_PHY_BASE,
2479 .regs_otg = S5PC110_OTG_BASE,
2482 int board_eth_init(bd_t *bis)
2486 if (cpu_is_s5pc100())
2489 s3c_udc_probe(&s5pc110_otg_data);
2490 if (usb_eth_initialize(bis) >= 0)
2496 #ifdef CONFIG_CMD_USBDOWN
2497 int usb_board_init(void)
2499 #ifdef CONFIG_CMD_PMIC
2500 run_command("pmic ldo 3 on", 0);
2503 if (cpu_is_s5pc100()) {
2504 #ifdef CONFIG_HARD_I2C
2505 uchar val[2] = {0,};
2508 if (i2c_read(0x66, 0, 1, val, 2)) {
2509 printf("i2c_read error\n");
2516 if (i2c_write(0x66, 0, 1, val, 2)) {
2517 printf("i2c_write error\n");
2520 i2c_read(0x66, 0, 1, val, 2);
2526 if (board_is_limo_universal() ||
2527 board_is_limo_real() ||
2529 /* check usb path */
2530 if (board_is_limo_real() && !hwrevision(6))
2534 if (machine_is_tickertape())
2535 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2536 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2538 /* USB Path to AP */
2539 micro_usb_switch(0);
2545 #ifdef CONFIG_GENERIC_MMC
2546 int s5p_no_mmc_support(void)
2548 if (machine_is_wmg160())
2553 int board_mmc_init(bd_t *bis)
2557 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2560 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2561 if (machine_is_kessler())
2562 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2564 if (machine_is_wmg160())
2567 /* MMC0 Clock source = SCLKMPLL */
2568 reg = readl(&clk->src4);
2571 writel(reg, &clk->src4);
2573 reg = readl(&clk->div4);
2576 /* set div value near 50MHz */
2577 clock = get_pll_clk(MPLL) / 1000000;
2578 for (i = 0; i < 0xf; i++) {
2579 if ((clock / (i + 1)) <= 50) {
2585 writel(reg, &clk->div4);
2591 * GPG0[2] SD_0_CDn -> Not used
2592 * GPG0[3:6] SD_0_DATA[0:3]
2594 for (i = 0; i < 7; i++) {
2597 /* GPG0[0:6] special function 2 */
2598 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2599 /* GPG0[0:6] pull disable */
2600 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2601 /* GPG0[0:6] drv 4x */
2602 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2605 if (machine_is_geminus()) {
2606 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2607 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2610 return s5pc1xx_mmc_init(0);
2614 #ifdef CONFIG_CMD_PMIC
2615 static int pmic_status(void)
2617 unsigned char addr, val[2];
2622 if (max8998_probe())
2626 i2c_read(addr, reg, 1, val, 1);
2627 for (i = 7; i >= 4; i--)
2628 printf("BUCK%d %s\n", 7 - i + 1,
2629 val[0] & (1 << i) ? "on" : "off");
2631 printf("LDO%d %s\n", 5 - i,
2632 val[0] & (1 << i) ? "on" : "off");
2634 i2c_read(addr, reg, 1, val, 1);
2635 for (i = 7; i >= 0; i--)
2636 printf("LDO%d %s\n", 7 - i + 6,
2637 val[0] & (1 << i) ? "on" : "off");
2639 i2c_read(addr, reg, 1, val, 1);
2640 for (i = 7; i >= 4; i--)
2641 printf("LDO%d %s\n", 7 - i + 14,
2642 val[0] & (1 << i) ? "on" : "off");
2645 i2c_read(addr, reg, 1, val, 1);
2646 for (i = 7; i >= 6; i--)
2647 printf("SAFEOUT%d %s\n", 7 - i + 1,
2648 val[0] & (1 << i) ? "on" : "off");
2652 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2654 unsigned char addr, val[2];
2655 unsigned int reg, shift;
2663 } else if (ldo <= 13) {
2666 } else if (ldo <= 17) {
2668 shift = 17 - ldo + 4;
2675 shift = 4 - buck + 4;
2676 } else if (safeout) {
2680 shift = 8 - safeout;
2686 if (max8998_probe())
2689 i2c_read(addr, reg, 1, val, 1);
2691 val[0] |= (1 << shift);
2693 val[0] &= ~(1 << shift);
2694 i2c_write(addr, reg, 1, val, 1);
2695 i2c_read(addr, reg, 1, val, 1);
2698 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2699 val[0] & (1 << shift) ? "on" : "off");
2701 printf("buck %d value 0x%x, %s\n", buck, val[0],
2702 val[0] & (1 << shift) ? "on" : "off");
2704 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2705 val[0] & (1 << shift) ? "on" : "off");
2710 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2712 int buck = 0, ldo = 0, safeout = 0, on = -1;
2716 if (strncmp(argv[1], "status", 6) == 0)
2717 return pmic_status();
2720 if (strncmp(argv[1], "ldo", 3) == 0)
2721 ldo = simple_strtoul(argv[2], NULL, 10);
2722 else if (strncmp(argv[1], "buck", 4) == 0)
2723 buck = simple_strtoul(argv[2], NULL, 10);
2724 else if (strncmp(argv[1], "safeout", 7) == 0)
2725 safeout = simple_strtoul(argv[2], NULL, 10);
2729 if (strncmp(argv[3], "on", 2) == 0)
2731 else if (strncmp(argv[3], "off", 3) == 0)
2736 return pmic_ldo_control(buck, ldo, safeout, on);
2747 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2748 "PMIC LDO & BUCK control",
2749 "status - Display PMIC LDO & BUCK status\n"
2750 "pmic ldo num on/off - Turn on/off the LDO\n"
2751 "pmic buck num on/off - Turn on/off the BUCK\n"
2752 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2756 #ifdef CONFIG_CMD_DEVICE_POWER
2757 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2761 if (strncmp(argv[1], "cp", 2) == 0) {
2762 micro_usb_switch(1);
2763 pmic_ldo_control(0, 0, 2, 1);
2764 setenv("usb", "cp");
2765 } else if (strncmp(argv[1], "ap", 2) == 0) {
2766 micro_usb_switch(0);
2767 pmic_ldo_control(0, 0, 2, 0);
2768 setenv("usb", "ap");
2778 printf("USB Path is set to %s\n", getenv("usb"));
2784 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2786 "cp - switch to CP\n"
2787 "microusb ap - switch to AP\n"