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);
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 (mach_is_aquila()) {
282 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
283 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
284 } else if (mach_is_kessler()) {
285 i2c_gpio[I2C_GPIO7].bus->gpio_base =
286 (unsigned int)&gpio->gpio_mp0_5;
287 } else if (mach_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_TYPE_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)
399 if (board_rev & S1_BOARD)
403 count += sprintf(buf + count, " - %s", name);
408 static char *get_board_name(int board)
410 if (board == MACH_TYPE_AQUILA)
412 else if (board == MACH_KESSLER)
414 else if (board == MACH_WMG160)
416 return (char *) board_name[board];
419 static void check_board_revision(int board, int rev)
421 if (board == MACH_TYPE_AQUILA) {
422 /* Limo Real or Universal */
423 if (rev & LIMO_UNIVERSAL_BOARD)
424 board_rev &= ~J1_B2_BOARD;
425 if (rev & LIMO_REAL_BOARD)
426 board_rev &= ~(J1_B2_BOARD |
427 LIMO_UNIVERSAL_BOARD);
428 if (rev & MEDIA_BOARD)
429 board_rev &= ~(J1_B2_BOARD |
430 LIMO_UNIVERSAL_BOARD);
431 if (rev & BAMBOO_BOARD)
432 board_rev &= ~(J1_B2_BOARD |
433 LIMO_UNIVERSAL_BOARD |
436 } else if (board == MACH_KESSLER) {
437 if (rev & KESSLER_BOARD)
438 board_rev &= ~(J1_B2_BOARD |
439 LIMO_UNIVERSAL_BOARD);
440 if (rev & NEPTUNE_BOARD)
441 board_rev &= ~(J1_B2_BOARD |
442 LIMO_UNIVERSAL_BOARD);
444 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
447 board_rev &= ~BOARD_MASK;
451 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
455 gpio_direction_input(bank, 2);
456 gpio_direction_input(bank, 3);
457 gpio_direction_input(bank, 4);
458 gpio_direction_input(bank, hwrev3);
460 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
461 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
462 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
463 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
465 rev = gpio_get_value(bank, 2);
466 rev |= (gpio_get_value(bank, 3) << 1);
467 rev |= (gpio_get_value(bank, 4) << 2);
468 rev |= (gpio_get_value(bank, hwrev3) << 3);
473 static void check_hw_revision(void)
475 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
477 if (cpu_is_s5pc100()) {
478 struct s5pc100_gpio *gpio =
479 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
481 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
483 /* C100 TickerTape */
485 board = MACH_TICKERTAPE;
487 struct s5pc110_gpio *gpio =
488 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
494 * Note Check 'Aquila' board first
498 * LRA: Limo Real Aquila
499 * LUA: Limo Universal Aquila
504 * ADDR = 0xE0200000 + OFF
506 * OFF Universal BB LRA LUA OA TT SS CYP
507 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
508 * J2: 0x0284 0x01 0x10 0x00
509 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
510 * H3: 0x0C64 0x03 0x07 0x0F
511 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
512 * I: 0x0224 0x02 0x00 0x08
513 * MP03: 0x0324 0x9x 0xbx 0x9x
514 * MP05: 0x0364 0x80 0x88
518 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
519 board = MACH_TYPE_AQUILA;
520 board_rev |= J1_B2_BOARD;
522 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
523 gpio_direction_input(&gpio->gpio_j2, 6);
526 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
527 board_rev |= LIMO_UNIVERSAL_BOARD;
529 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
530 board_rev |= LIMO_REAL_BOARD;
532 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
533 board_rev |= MEDIA_BOARD;
535 /* set gpio to default value. */
536 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
537 gpio_direction_output(&gpio->gpio_j2, 6, 0);
540 /* Workaround: C110 Aquila Rev0.6 */
541 if (board_rev == 6) {
542 board = MACH_TYPE_AQUILA;
543 board_rev |= LIMO_REAL_BOARD;
546 /* C110 Aquila Bamboo */
547 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
548 board = MACH_TYPE_AQUILA;
549 board_rev |= BAMBOO_BOARD;
552 /* C110 TickerTape */
553 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
554 gpio_get_value(&gpio->gpio_d1, 1) == 0)
555 board = MACH_TICKERTAPE;
557 /* WMG160 - GPH3[0:4] = 0x00 */
558 if (board == MACH_TICKERTAPE) {
561 for (i = 0; i < 4; i++) {
562 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
573 /* C110 Geminus for rev0.0 */
574 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
575 gpio_direction_input(&gpio->gpio_j1, 2);
576 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
577 board = MACH_GEMINUS;
578 if ((board_rev & ~BOARD_MASK) == 3)
581 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
582 gpio_direction_output(&gpio->gpio_j1, 2, 0);
584 /* C110 Geminus for rev0.1 ~ */
585 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
586 gpio_direction_input(&gpio->gpio_j0, 6);
587 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
588 board = MACH_GEMINUS;
591 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
593 /* Kessler MP0_5[6] == 1 */
594 gpio_direction_input(&gpio->gpio_mp0_5, 6);
595 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
596 /* Cypress: Do this for cypress */
597 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
598 gpio_direction_input(&gpio->gpio_j2, 2);
599 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
600 board = MACH_CYPRESS;
601 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
603 board = MACH_KESSLER;
604 board_rev |= KESSLER_BOARD;
606 /* Neptune MP0_5[4] == 1 */
607 gpio_direction_input(&gpio->gpio_mp0_5, 4);
608 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
609 board_rev &= ~KESSLER_BOARD;
610 board_rev |= NEPTUNE_BOARD;
613 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
616 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
617 /* Kessler S1 board detection */
618 if (board == MACH_TICKERTAPE) {
619 board = MACH_KESSLER;
620 board_rev |= S1_BOARD;
625 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
629 if (board < MACH_PSEUDO_END) {
630 if (cpu_is_s5pc110())
631 gd->bd->bi_arch_number = C110_MACH_START + board;
633 gd->bd->bi_arch_number = C100_MACH_START + board;
635 gd->bd->bi_arch_number = board;
638 /* Architecture Common settings */
639 if (cpu_is_s5pc110()) {
640 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
642 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
644 setenv("updatek", "onenand erase 0x60000 0x300000; "
645 "onenand write 0x31008000 0x60000 0x300000");
649 static void show_hw_revision(void)
654 * Workaround for Rev 0.3 + CP Ver ES 3.1
657 if (board_is_limo_real()) {
659 /* default is Rev 0.4 */
665 if (mach_is_kessler() || mach_is_aquila())
666 board = gd->bd->bi_arch_number;
667 else if (cpu_is_s5pc110())
668 board = gd->bd->bi_arch_number - C110_MACH_START;
670 board = gd->bd->bi_arch_number - C100_MACH_START;
672 check_board_revision(board, board_rev);
674 /* Set CPU Revision */
675 if (mach_is_aquila()) {
676 if (board_is_limo_real()) {
677 if ((board_rev & 0xf) < 8)
678 s5pc1xx_set_cpu_rev(0);
680 } else if (mach_is_kessler()) {
681 s5pc1xx_set_cpu_rev(1);
682 } else if (mach_is_geminus()) {
683 if ((board_rev & 0xf) < 1)
684 s5pc1xx_set_cpu_rev(0);
685 } else if (mach_is_cypress()) {
686 s5pc1xx_set_cpu_rev(1);
688 s5pc1xx_set_cpu_rev(0);
691 empty_device_info_buffer();
692 dprintf("HW Revision:\t%x (%s%s) %s\n",
693 board_rev, get_board_name(board),
694 display_features(board, board_rev),
695 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
698 static void check_auto_burn(void)
700 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
701 unsigned int count = 0;
704 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
705 printf("Auto burning bootloader\n");
706 count += sprintf(buf + count, "run updateb; ");
708 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
709 printf("Auto burning kernel\n");
710 count += sprintf(buf + count, "run updatek; ");
714 count += sprintf(buf + count, "reset");
715 setenv("bootcmd", buf);
718 /* Clear the magic value */
719 writel(0xa5a55a5a, magic_base);
720 writel(0xa5a55a5a, magic_base + 0x4);
723 static void pmic_pin_init(void)
725 unsigned int reg, value;
727 if (cpu_is_s5pc100())
730 /* AP_PS_HOLD: XEINT_0: GPH0[0]
731 * Note: Don't use GPIO PS_HOLD it doesn't work
733 reg = S5PC110_PS_HOLD_CONTROL;
735 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
736 S5PC110_PS_HOLD_DATA_HIGH |
737 S5PC110_PS_HOLD_OUT_EN;
740 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
741 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
742 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
745 static void enable_ldos(void)
747 if (cpu_is_s5pc100())
750 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
751 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
754 static void enable_t_flash(void)
756 if (!(board_is_limo_universal() || board_is_limo_real()))
759 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
760 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
763 static void setup_limo_real_gpios(void)
765 if (!board_is_limo_real())
769 * Note: Please write GPIO alphabet order
771 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
772 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
775 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
776 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
778 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
779 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
781 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
782 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
783 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
786 static void setup_media_gpios(void)
788 if (!board_is_media())
792 * Note: Please write GPIO alphabet order
794 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
795 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
797 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
798 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
799 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
802 #define KBR3 (1 << 3)
803 #define KBR2 (1 << 2)
804 #define KBR1 (1 << 1)
805 #define KBR0 (1 << 0)
807 static void check_keypad(void)
809 unsigned int reg, value;
810 unsigned int col_num, row_num;
811 unsigned int col_mask;
812 unsigned int col_mask_shift;
813 unsigned int row_state[4];
815 unsigned int auto_download = 0;
817 if (mach_is_wmg160())
820 if (cpu_is_s5pc100()) {
821 struct s5pc100_gpio *gpio =
822 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
827 /* Set GPH2[2:0] to KP_COL[2:0] */
828 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
829 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
830 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
832 /* Set GPH3[2:0] to KP_ROW[2:0] */
833 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
834 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
835 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
837 reg = S5PC100_KEYPAD_BASE;
838 col_mask = S5PC1XX_KEYIFCOL_MASK;
841 if (board_is_limo_real() || board_is_limo_universal()) {
849 for (i = 0; i < row_num; i++) {
850 /* Set GPH3[3:0] to KP_ROW[3:0] */
851 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
852 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
855 for (i = 0; i < col_num; i++)
856 /* Set GPH2[3:0] to KP_COL[3:0] */
857 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
859 reg = S5PC110_KEYPAD_BASE;
860 col_mask = S5PC110_KEYIFCOLEN_MASK;
864 /* KEYIFCOL reg clear */
865 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
868 for (i = 0; i < col_num; i++) {
870 value &= ~(1 << i) << col_mask_shift;
872 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
875 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
876 row_state[i] = ~value & ((1 << row_num) - 1);
878 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
881 /* KEYIFCOL reg clear */
882 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
884 if (mach_is_aquila() || mach_is_kessler()) {
886 if (row_state[1] & 0x2)
888 if (board_is_neptune()) {
889 /* home & volume down */
890 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
893 /* cam full shot & volume down */
894 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
897 } else if (mach_is_geminus())
898 /* volume down & home */
899 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
903 setenv("bootcmd", "usbdown");
906 static void check_battery(int mode)
908 unsigned char val[2];
909 unsigned char addr = 0x36; /* max17040 fuel gauge */
911 i2c_set_bus_num(I2C_GPIO3);
913 if (mach_is_aquila()) {
916 } else if (mach_is_kessler()) {
917 i2c_set_bus_num(I2C_GPIO7);
918 } else if (mach_is_cypress()) {
919 i2c_set_bus_num(I2C_GPIO7);
920 } else if (mach_is_geminus()) {
922 i2c_set_bus_num(I2C_GPIO7);
926 if (i2c_probe(addr)) {
927 printf("Can't found max17040 fuel gauge\n");
931 /* mode 0: check mode / 1: enable mode */
935 i2c_write(addr, 0xfe, 1, val, 2);
937 i2c_read(addr, 0x04, 1, val, 1);
938 dprintf("battery:\t%d%%\n", val[0]);
939 battery_soc = val[0];
943 static void check_mhl(void)
945 unsigned char val[2];
946 unsigned char addr = 0x39; /* SIL9230 */
948 /* MHL Power enable */
949 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
950 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
952 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
953 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
955 /* 10ms required after reset */
959 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
961 i2c_set_bus_num(I2C_GPIO5);
964 if (i2c_probe(addr)) {
965 printf("Can't found MHL Chip\n");
971 * set to Normal operation
974 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
975 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
980 * 00 = MHL termination ON
981 * 11 = MHL termination OFF
984 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
985 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
988 static int max8998_probe(void)
990 unsigned char addr = 0xCC >> 1;
992 i2c_set_bus_num(I2C_PMIC);
994 if (i2c_probe(addr)) {
995 printf("Can't found max8998\n");
1002 #define CHARGER_ANIMATION_FRAME 6
1003 static void max8998_clear_interrupt(void)
1005 unsigned char addr, val[2];
1008 if (max8998_probe())
1011 i2c_read(addr, 0x00, 1, val, 1);
1012 i2c_read(addr, 0x01, 1, val, 1);
1013 i2c_read(addr, 0x02, 1, val, 1);
1014 i2c_read(addr, 0x03, 1, val, 1);
1017 static int max8998_power_key(void)
1019 unsigned char addr, val[2];
1022 if (max8998_probe())
1025 /* Accessing IRQ1 register */
1026 i2c_read(addr, 0x00, 1, val, 1);
1027 if (val[0] & (1 << 6))
1033 static int max8998_has_ext_power_source(void)
1035 unsigned char addr, val[2];
1038 if (max8998_probe())
1041 /* Accessing STATUS2 register */
1042 i2c_read(addr, 0x09, 1, val, 1);
1043 if (val[0] & (1 << 5))
1049 struct thermister_stat {
1054 static struct thermister_stat adc_to_temperature_data[] = {
1055 { .centigrade = -20, .adc = 1856, },
1056 { .centigrade = -15, .adc = 1799, },
1057 { .centigrade = -10, .adc = 1730, },
1058 { .centigrade = -5, .adc = 1649, },
1059 { .centigrade = 0, .adc = 1556, },
1060 { .centigrade = 5, .adc = 1454, },
1061 { .centigrade = 10, .adc = 1343, },
1062 { .centigrade = 15, .adc = 1227, },
1063 { .centigrade = 20, .adc = 1109, },
1064 { .centigrade = 25, .adc = 992, },
1065 { .centigrade = 30, .adc = 880, },
1066 { .centigrade = 35, .adc = 773, },
1067 { .centigrade = 40, .adc = 675, },
1068 { .centigrade = 45, .adc = 586, },
1069 { .centigrade = 50, .adc = 507, },
1070 { .centigrade = 55, .adc = 436, },
1071 { .centigrade = 58, .adc = 399, },
1072 { .centigrade = 63, .adc = 343, },
1073 { .centigrade = 65, .adc = 322, },
1077 #define USHRT_MAX 0xFFFFU
1079 static int adc_to_temperature_centigrade(unsigned short adc)
1083 /* low_*: Greatest Lower Bound,
1084 * * * * high_*: Smallest Upper Bound */
1085 int low_temp = 0, high_temp = 0;
1086 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1087 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1088 if (adc_to_temperature_data[i].adc <= adc &&
1089 adc_to_temperature_data[i].adc >= low_adc) {
1090 low_temp = adc_to_temperature_data[i].centigrade;
1091 low_adc = adc_to_temperature_data[i].adc;
1093 if (adc_to_temperature_data[i].adc >= adc &&
1094 adc_to_temperature_data[i].adc <= high_adc) {
1095 high_temp = adc_to_temperature_data[i].centigrade;
1096 high_adc = adc_to_temperature_data[i].adc;
1100 /* Linear approximation between cloest low and high,
1101 * which is the weighted average of the two. */
1103 /* The following equation is correct only when the two are different */
1104 if (low_adc == high_adc)
1106 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1107 return 20; /* The room temperature */
1110 if (high_adc == USHRT_MAX)
1113 approximation = low_temp * (adc - low_adc) +
1114 high_temp * (high_adc - adc);
1115 approximation /= high_adc - low_adc;
1117 return approximation;
1120 static unsigned short get_adc_value(int channel)
1122 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1123 unsigned short ret = 0;
1127 unsigned int loop = 0;
1129 if (mach_is_kessler())
1131 else if (mach_is_geminus())
1133 else if (mach_is_wmg160())
1135 else if (mach_is_cypress())
1137 else if (mach_is_tickertape())
1139 else if (mach_is_aquila())
1142 else if (mach_is_p1p2())
1146 sprintf(buf, "pmic ldo %d on", ldonum);
1147 run_command(buf, 0);
1149 writel(channel & 0xF, &adc->adcmux);
1150 writel((1 << 14) | (49 << 6), &adc->adccon);
1151 writel(1000 & 0xffff, &adc->adcdly);
1152 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1154 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1159 reg = readl(&adc->adccon);
1160 } while (!reg & (1 << 15) && loop++ < 1000);
1162 ret = readl(&adc->adcdat0) & 0xFFF;
1163 sprintf(buf, "pmic ldo %d off", ldonum);
1164 run_command(buf, 0);
1169 static int adc_get_average_ambient_temperature(void)
1171 if (mach_is_kessler()) {
1172 unsigned short min = USHRT_MAX;
1173 unsigned short max = 0;
1174 unsigned int sum = 0;
1175 unsigned int measured = 0;
1178 for (i = 0; i < 7; i++) {
1179 unsigned short measurement = get_adc_value(6);
1182 if (min > measurement)
1184 if (max < measurement)
1187 if (measured >= 3) {
1193 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1194 adc_to_temperature_centigrade(sum), sum);
1195 return adc_to_temperature_centigrade(sum);
1198 return 20; /* 20 Centigrade */
1201 enum temperature_level {
1209 static enum temperature_level temperature_check(void)
1211 int temp = adc_get_average_ambient_temperature();
1213 return _TEMP_TOO_LOW;
1215 return _TEMP_OK_LOW;
1217 return _TEMP_TOO_HIGH;
1219 return _TEMP_OK_HIGH;
1223 extern void lcd_display_clear(void);
1224 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1226 static void charger_en(int enable)
1232 unsigned char addr = 0xCC >> 1; /* max8998 */
1233 unsigned char val[2];
1235 if (max8998_probe())
1239 printf("Disable the charger.\n");
1240 i2c_read(addr, 0x0D, 1, val, 1);
1243 i2c_write(addr, 0x0D, 1, val, 1);
1245 i2c_read(addr, 0x0C, 1, val, 1);
1246 val[0] &= ~(0x7 << 0);
1247 val[0] &= ~(0x7 << 5);
1248 if (enable == 600) {
1249 val[0] |= 5; /* 600mA */
1250 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1251 } else { /* Assume 475 mA */
1253 val[0] |= 2; /* 475mA */
1254 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1256 i2c_write(addr, 0x0C, 1, val, 1);
1258 i2c_read(addr, 0x0D, 1, val, 1);
1260 i2c_write(addr, 0x0D, 1, val, 1);
1261 printf("Enable the charger @ %dmA\n", enable);
1265 void lcd_power_on(unsigned int onoff);
1266 extern int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1267 extern int drv_lcd_init_resume (void);
1269 static void into_charge_mode(void)
1275 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1276 unsigned int reg, wakeup_stat;
1277 int charger_speed = 600;
1279 max8998_clear_interrupt();
1281 printf("Charge Mode\n");
1282 charger_en(charger_speed);
1284 #ifdef CONFIG_S5PC1XXFB
1287 /* TODO: write the image-text for the charger */
1289 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1290 if (level >= CHARGER_ANIMATION_FRAME)
1291 level = CHARGER_ANIMATION_FRAME - 1;
1293 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1294 bmp_addr[i] = (ulong)battery_charging_animation[i];
1296 lcd_display_clear();
1297 for (i = 0; i < 3; i++) {
1298 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1301 bmp = gunzip_bmp(bmp_addr[j], &len);
1302 lcd_display_bitmap((ulong)bmp, 140, 202);
1305 for (k = 0; k < 10; k++) {
1306 if (max8998_power_key()) {
1307 lcd_display_clear();
1308 goto restore_screen;
1309 } else if (!max8998_has_ext_power_source()) {
1310 lcd_display_clear();
1311 goto restore_screen;
1320 /* Disable the display to prevent flickering */
1321 /* TODO: how to reenable the display later? */
1325 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1326 unsigned int org, org_ip3;
1327 enum temperature_level previous_state = _TEMP_OK;
1329 empty_device_info_buffer();
1330 if (max8998_power_key())
1332 else if (!max8998_has_ext_power_source())
1335 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1336 org_ip3 = readl(0xE010046C);
1337 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1339 reg = org = readl(&rtc->rtccon);
1341 writel(reg, &rtc->rtccon);
1343 reg = readl(&rtc->rtccon);
1344 writel(reg | (1 << 3), &rtc->rtccon);
1346 writel(reg & ~(1 << 3), &rtc->rtccon);
1349 reg = readl(&rtc->rtccon);
1350 reg &= ~((1 << 8) | (0xF << 4));
1351 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1352 writel(reg, &rtc->rtccon);
1354 reg = 15 * 4 - 1; /* 15 sec */
1355 writel(reg, &rtc->ticcnt);
1357 /* EVT0: sleep 1, EVT1: sleep */
1358 if (cpu_is_s5pc110()) {
1359 char *name = "dummy";
1360 char *usage = "N/A";
1367 if (s5pc1xx_get_cpu_rev() == 0) {
1368 char *argv[] = {"1", "1"};
1369 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1371 char *argv[] = {"0", "0"};
1372 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1375 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1379 /* Check TEMP HIGH/LOW */
1380 switch (temperature_check()) {
1382 charger_en(charger_speed);
1383 previous_state = _TEMP_OK;
1387 previous_state = _TEMP_TOO_LOW;
1389 case _TEMP_TOO_HIGH:
1391 previous_state = _TEMP_TOO_HIGH;
1394 if (previous_state == _TEMP_TOO_LOW) {
1397 charger_en(charger_speed);
1398 previous_state = _TEMP_OK;
1402 if (previous_state == _TEMP_TOO_HIGH) {
1405 charger_en(charger_speed);
1406 previous_state = _TEMP_OK;
1411 writel(org, &rtc->rtccon);
1412 writel(org_ip3, 0xE010046C);
1414 } while (wakeup_stat == 0x04); /* RTC TICK */
1417 /* TODO: Reenable logo display (not working yet) */
1419 drv_lcd_init_resume();
1422 static int fsa9480_probe(void)
1424 unsigned char addr = 0x25;
1426 if (cpu_is_s5pc100())
1429 if (board_is_limo_real()) {
1430 if (hwrevision(0) || hwrevision(1))
1434 i2c_set_bus_num(I2C_PMIC);
1436 if (mach_is_kessler()) {
1437 i2c_set_bus_num(I2C_GPIO6);
1438 } else if (mach_is_cypress()) {
1439 i2c_set_bus_num(I2C_GPIO6);
1440 } else if (mach_is_geminus()) {
1442 i2c_set_bus_num(I2C_GPIO6);
1443 } else if (mach_is_wmg160()) {
1444 i2c_set_bus_num(I2C_GPIO6);
1447 if (i2c_probe(addr)) {
1448 printf("Can't found fsa9480\n");
1455 static void check_micro_usb(int intr)
1458 unsigned char val[2];
1459 static int started_charging_once = 0;
1462 if (fsa9480_probe())
1465 addr = 0x25; /* fsa9480 */
1467 /* Clear Interrupt */
1469 i2c_read(addr, 0x03, 1, val, 2);
1473 /* Read Device Type 1 */
1474 i2c_read(addr, 0x0a, 1, val, 1);
1476 #define FSA_DEV1_CHARGER (1 << 6)
1477 #define FSA_DEV1_UART (1 << 3)
1478 #define FSA_DEV1_USB (1 << 2)
1479 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1480 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1483 * If USB, use default 475mA
1484 * If Charger, use 600mA and go to charge mode
1486 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1487 started_charging_once = 1;
1489 /* If it's full, do not charge. */
1490 if (battery_soc < 100)
1494 } else if (val[0] & FSA_DEV1_USB) {
1495 if (battery_soc < 100)
1496 charger_en(475); /* enable charger and keep booting */
1501 /* If Factory Mode is Boot ON-USB, go to download mode */
1502 i2c_read(addr, 0x07, 1, val, 1);
1504 #define FSA_ADC_FAC_USB_OFF 0x18
1505 #define FSA_ADC_FAC_USB_ON 0x19
1506 #define FSA_ADC_FAC_UART 0x1d
1508 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1509 setenv("bootcmd", "usbdown");
1511 path = getenv("usb");
1513 if (!strncmp(path, "cp", 2))
1514 run_command("microusb cp", 0);
1517 static void micro_usb_switch(int path)
1520 unsigned char val[2];
1522 if (fsa9480_probe())
1525 addr = 0x25; /* fsa9480 */
1528 val[0] = 0x90; /* VAUDIO */
1530 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1532 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1534 i2c_read(addr, 0x2, 1, val, 1);
1535 val[0] &= ~(1 << 2); /* Manual switching */
1536 i2c_write(addr, 0x2, 1, val, 1);
1539 #define MAX8998_REG_ONOFF1 0x11
1540 #define MAX8998_REG_ONOFF2 0x12
1541 #define MAX8998_REG_ONOFF3 0x13
1542 #define MAX8998_REG_LDO7 0x21
1543 #define MAX8998_REG_LDO17 0x29
1545 #define MAX8998_LDO3 (1 << 2)
1547 #define MAX8998_LDO6 (1 << 7)
1548 #define MAX8998_LDO7 (1 << 6)
1549 #define MAX8998_LDO8 (1 << 5)
1550 #define MAX8998_LDO9 (1 << 4)
1551 #define MAX8998_LDO10 (1 << 3)
1552 #define MAX8998_LDO11 (1 << 2)
1553 #define MAX8998_LDO12 (1 << 1)
1554 #define MAX8998_LDO13 (1 << 0)
1556 #define MAX8998_LDO14 (1 << 7)
1557 #define MAX8998_LDO15 (1 << 6)
1558 #define MAX8998_LDO16 (1 << 5)
1559 #define MAX8998_LDO17 (1 << 4)
1562 static void init_pmic(void)
1565 unsigned char val[2];
1567 if (cpu_is_s5pc100())
1570 addr = 0xCC >> 1; /* max8998 */
1571 if (max8998_probe())
1575 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1576 val[0] &= ~MAX8998_LDO3;
1577 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1580 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1582 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1583 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1585 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1586 MAX8998_LDO12 | MAX8998_LDO13);
1588 if (mach_is_kessler())
1589 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1591 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1592 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1594 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1596 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1597 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1599 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1600 MAX8998_LDO16 | MAX8998_LDO17);
1602 if (mach_is_kessler())
1603 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1605 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1606 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1609 static void setup_power_down_mode_registers(void)
1611 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1612 struct s5pc1xx_gpio_bank *bank;
1613 struct gpio_powermode *p;
1615 struct gpio_external *ge;
1617 struct s5pc1xx_gpio_item *mr;
1621 if (cpu_is_s5pc100())
1624 /* Only Limo real and kessler supports worked for sleep currnet */
1625 if (mach_is_aquila()) {
1626 if (board_is_limo_real())
1630 } else if (mach_is_kessler()) {
1632 } else if (mach_is_geminus()) {
1638 if (mach_is_aquila()) {
1639 /* Aquila rev 0.8 or lower */
1640 p = aquila_powerdown_modes;
1641 ge = aquila_external_powerdown_modes;
1642 mr = aquila_mirror_powerdown_mode;
1643 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1644 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1645 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1646 } else if (mach_is_kessler()) {
1647 /* Aquila rev 0.9 */
1648 p = kessler_powerdown_modes;
1649 ge = kessler_external_powerdown_modes;
1650 mr = kessler_mirror_powerdown_mode;
1651 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1652 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1653 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1654 } else if (mach_is_geminus()) {
1655 if (hwrevision(1)) {
1656 /* Same as Aquila rev 0.9 */
1658 p = kessler_powerdown_modes;
1659 ge = kessler_external_powerdown_modes;
1660 mr = kessler_mirror_powerdown_mode;
1661 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1662 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1663 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1665 p = aquila_powerdown_modes;
1666 ge = aquila_external_powerdown_modes;
1667 mr = aquila_mirror_powerdown_mode;
1668 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1669 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1670 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1672 } else if (hwrevision(0)) {
1673 /* Same as Aquila rev 0.8 or lower */
1674 p = aquila_powerdown_modes;
1675 ge = aquila_external_powerdown_modes;
1676 mr = aquila_mirror_powerdown_mode;
1677 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1678 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1679 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1681 return; /* Not supported */
1685 bank = &gpio->gpio_a0;
1687 for (i = 0; i < n_p; i++, p++, bank++) {
1688 writel(p->conpdn, &bank->pdn_con);
1689 writel(p->pudpdn, &bank->pdn_pull);
1692 writel(0xff0022b0, (unsigned int *)0xF0000000);
1693 writel(0xff0022b0, (unsigned int *)0xF1400000);
1695 bank = &gpio->gpio_h0;
1697 for (i = 0; i < n_ge; i++) {
1698 writel(ge->con, &bank->con);
1699 writel(ge->dat, &bank->dat);
1700 writel(ge->pud, &bank->pull);
1706 for (i = 0; i < n_mr; i++) {
1707 unsigned int reg = readl(&mr->bank->pdn_con);
1708 reg &= ~(0x3 << (mr->number << 1));
1709 if (readl(&mr->bank->dat) & (1 << mr->number))
1710 reg |= 0x1 << (mr->number << 1);
1711 writel(reg, &mr->bank->pdn_con);
1717 #include "../../../drivers/video/s5p-spi.h"
1719 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1720 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1722 struct spi_platform_data spi_pd;
1724 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1726 void lcd_cfg_gpio(void)
1728 unsigned int i, f3_end = 4;
1730 for (i = 0; i < 8; i++) {
1731 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1732 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1733 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1734 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1735 /* pull-up/down disable */
1736 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1737 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1738 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1740 /* drive strength to max (24bit) */
1741 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1742 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1743 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1744 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1745 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1746 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1749 /* set DISPLAY_DE_B pin for dual rgb mode. */
1750 if (board_is_media())
1753 for (i = 0; i < f3_end; i++) {
1754 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1755 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1756 /* pull-up/down disable */
1757 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1758 /* drive strength to max (24bit) */
1759 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1760 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1762 /* display output path selection (only [1:0] valid) */
1763 writel(0x2, 0xE0107008);
1765 /* gpio pad configuration for LCD reset. */
1766 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1768 /* gpio pad configuration for LCD ON. */
1769 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1771 /* LCD_BACKLIGHT_EN */
1772 if (mach_is_geminus())
1773 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1774 if (board_is_neptune()) {
1775 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1776 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1780 * gpio pad configuration for
1781 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1783 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1784 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1785 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1786 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1788 if (mach_is_aquila() || mach_is_kessler()) {
1789 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1791 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1793 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1795 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1798 if (board_is_neptune())
1799 s6d16a0x_set_platform_data(&spi_pd);
1801 s6e63m0_set_platform_data(&spi_pd);
1802 if (board_is_media())
1807 if (mach_is_cypress()) {
1808 #if 0 /* universal cypress */
1810 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1813 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1815 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1817 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1819 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1821 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1822 #if 0 /* universal cypress */
1823 pd_cs.bank = &gpio_base->gpio_mp0_1;
1826 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1828 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1830 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1835 /* these data would be sent to s6e63m0 lcd panel driver. */
1836 s6e63m0_set_platform_data(&spi_pd);
1842 #define SWRST_REG 0x00
1843 #define LEDCON_REG 0x01
1844 #define LED_CUR_SET_REG 0x03
1845 #define LED_CUR_TR_REG 0x08
1848 #define NORMAL_MODE 0x09
1849 #define CUR_SET 0x63
1851 void backlight_on(unsigned int onoff)
1855 unsigned char val[2];
1856 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1859 if (mach_is_geminus())
1860 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1862 if (mach_is_geminus())
1863 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1866 if (mach_is_kessler() && board_is_neptune()) {
1867 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1870 i2c_set_bus_num(I2C_GPIO5);
1873 if (i2c_probe(addr)) {
1874 if (i2c_probe(addr)) {
1875 printf("Can't found s6d16a0x backlight i2c\n");
1880 i2c_write(addr, SWRST_REG, 1, val, 1);
1883 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1885 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1886 val[0] = NORMAL_MODE;
1887 i2c_write(addr, LEDCON_REG, 1, val, 1);
1892 void reset_lcd(void)
1894 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1896 if (mach_is_aquila() || mach_is_kessler() || mach_is_geminus())
1897 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1898 if (mach_is_cypress())
1899 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1902 void lcd_power_on(unsigned int onoff)
1904 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1907 if (mach_is_aquila() || mach_is_geminus())
1908 gpio_set_value(&gpio->gpio_j1, 3, 1);
1910 if (mach_is_cypress())
1911 gpio_set_value(&gpio->gpio_g2, 2, 1);
1913 if (mach_is_kessler()) {
1915 unsigned char val[2];
1916 unsigned char val2[2];
1918 gpio_set_value(&gpio->gpio_j1, 3, 1);
1920 addr = 0xCC >> 1; /* max8998 */
1921 if (max8998_probe())
1924 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1925 val[0] &= ~(MAX8998_LDO17);
1926 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1927 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1929 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1930 val[0] |= MAX8998_LDO17;
1932 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1933 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1935 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1936 val[0] |= MAX8998_LDO7;
1938 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1939 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1942 if (mach_is_aquila() || mach_is_geminus())
1943 gpio_set_value(&gpio->gpio_j1, 3, 0);
1945 if (mach_is_cypress())
1946 gpio_set_value(&gpio->gpio_g2, 2, 0);
1948 if (mach_is_kessler()) {
1950 unsigned char val[2];
1952 gpio_set_value(&gpio->gpio_j1, 3, 0);
1954 addr = 0xCC >> 1; /* max8998 */
1955 if (max8998_probe())
1958 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1959 val[0] &= ~(MAX8998_LDO7);
1960 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1961 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1963 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1964 val[0] &= ~(MAX8998_LDO17);
1965 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1966 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1971 extern void s6e63m0_cfg_ldo(void);
1972 extern void s6e63m0_enable_ldo(unsigned int onoff);
1973 extern void s6d16a0x_cfg_ldo(void);
1974 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1976 int s5p_no_lcd_support(void)
1978 if (mach_is_wmg160())
1983 void init_panel_info(vidinfo_t *vid)
1985 vid->cfg_gpio = NULL;
1986 vid->reset_lcd = NULL;
1987 vid->backlight_on = NULL;
1988 vid->lcd_power_on = NULL;
1990 vid->cfg_ldo = NULL;
1991 vid->enable_ldo = NULL;
1993 vid->init_delay = 0;
1994 vid->reset_delay = 0;
1995 vid->power_on_delay = 0;
2000 vid->vl_width = 480;
2001 vid->vl_height = 800;
2003 vid->dual_lcd_enabled = 0;
2005 if (board_is_media()) {
2008 vid->vl_width = 960;
2009 vid->vl_height = 800;
2011 /* enable dual lcd mode. */
2012 vid->dual_lcd_enabled = 1;
2015 vid->vl_clkp = CONFIG_SYS_HIGH;
2016 vid->vl_hsp = CONFIG_SYS_LOW;
2017 vid->vl_vsp = CONFIG_SYS_LOW;
2018 vid->vl_dp = CONFIG_SYS_HIGH;
2021 /* S6E63M0 LCD Panel */
2030 if (mach_is_aquila() || mach_is_kessler()
2031 || mach_is_cypress()) {
2032 vid->cfg_gpio = lcd_cfg_gpio;
2033 vid->reset_lcd = reset_lcd;
2034 vid->backlight_on = backlight_on;
2035 vid->lcd_power_on = lcd_power_on;
2036 vid->cfg_ldo = s6e63m0_cfg_ldo;
2037 vid->enable_ldo = s6e63m0_enable_ldo;
2039 vid->init_delay = 25000;
2040 vid->reset_delay = 120000;
2043 if (board_is_neptune()) {
2047 vid->vl_width = 320;
2048 vid->vl_height = 480;
2050 vid->vl_clkp = CONFIG_SYS_HIGH;
2051 vid->vl_hsp = CONFIG_SYS_HIGH;
2052 vid->vl_vsp = CONFIG_SYS_HIGH;
2053 vid->vl_dp = CONFIG_SYS_LOW;
2056 /* disable dual lcd mode. */
2057 vid->dual_lcd_enabled = 0;
2059 /* S6D16A0X LCD Panel */
2068 vid->cfg_gpio = lcd_cfg_gpio;
2069 vid->backlight_on = backlight_on;
2070 vid->lcd_power_on = lcd_power_on;
2071 vid->reset_lcd = reset_lcd;
2072 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2073 vid->enable_ldo = s6d16a0x_enable_ldo;
2075 vid->init_delay = 10000;
2076 vid->power_on_delay = 10000;
2077 vid->reset_delay = 1000;
2081 if (mach_is_geminus()) {
2085 vid->vl_width = 1024,
2086 vid->vl_height = 600,
2087 vid->vl_clkp = CONFIG_SYS_LOW,
2088 vid->vl_hsp = CONFIG_SYS_HIGH,
2089 vid->vl_vsp = CONFIG_SYS_HIGH,
2090 vid->vl_dp = CONFIG_SYS_LOW,
2101 vid->cfg_gpio = lcd_cfg_gpio;
2102 vid->reset_lcd = reset_lcd;
2103 vid->backlight_on = backlight_on;
2104 vid->lcd_power_on = lcd_power_on;
2110 vid->vl_width = 480,
2111 vid->vl_height = 800,
2112 vid->vl_clkp = CONFIG_SYS_HIGH,
2113 vid->vl_hsp = CONFIG_SYS_LOW,
2114 vid->vl_vsp = CONFIG_SYS_LOW,
2115 vid->vl_dp = CONFIG_SYS_HIGH,
2131 vid->vl_width = 1024,
2132 vid->vl_height = 600,
2133 vid->vl_clkp = CONFIG_SYS_HIGH,
2134 vid->vl_hsp = CONFIG_SYS_HIGH,
2135 vid->vl_vsp = CONFIG_SYS_HIGH,
2136 vid->vl_dp = CONFIG_SYS_LOW,
2139 /* AMS701KA AMOLED Panel. */
2151 static void setup_meminfo(void)
2153 char meminfo[64] = {0, };
2154 int count = 0, size, real;
2156 size = gd->bd->bi_dram[0].size >> 20;
2157 count += sprintf(meminfo + count, "mem=%dM", size);
2159 /* Each Chip Select can't exceed the 256MiB */
2160 size = gd->bd->bi_dram[1].size >> 20;
2161 real = min(size, 256);
2162 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2163 real, (unsigned int)gd->bd->bi_dram[1].start);
2167 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2168 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2171 setenv("meminfo", meminfo);
2174 int misc_init_r(void)
2177 /* It should be located at first */
2180 if (mach_is_aquila() || mach_is_kessler()) {
2181 if (board_is_neptune())
2182 setenv("lcdinfo", "lcd=s6d16a0x");
2183 else if (board_is_media())
2184 setenv("lcdinfo", "lcd=s6e63m0");
2186 setenv("lcdinfo", "lcd=s6e63m0");
2188 if (mach_is_geminus())
2189 setenv("lcdinfo", "lcd=lms480jc01");
2190 if (mach_is_cypress())
2191 setenv("lcdinfo", "lcd=s6e63m0");
2197 /* Set proper PMIC pins */
2200 /* Check auto burning */
2203 /* To power up I2C2 */
2206 /* Enable T-Flash at Limo Real or Limo Universal */
2209 /* Setup Limo Real board GPIOs */
2210 setup_limo_real_gpios();
2212 /* Setup Media board GPIOs */
2213 setup_media_gpios();
2215 /* To usbdown automatically */
2221 #ifdef CONFIG_S5PC1XXFB
2222 display_device_info();
2225 setup_power_down_mode_registers();
2227 /* check max17040 */
2237 int board_init(void)
2239 /* Set Initial global variables */
2240 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2242 gd->bd->bi_arch_number = MACH_TYPE_AQUILA;
2243 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2245 /* Check H/W Revision */
2246 check_hw_revision();
2253 unsigned int base, memconfig0, size;
2254 unsigned int memconfig1, sz = 0;
2256 if (cpu_is_s5pc100()) {
2257 /* In mem setup, we swap the bank. So below size is correct */
2258 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2259 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2260 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2263 /* In S5PC110, we can't swap the DMC0/1 */
2264 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2265 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2267 base = S5PC110_DMC1_BASE;
2268 /* DMC configuration */
2269 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2270 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2272 size = (memconfig0 >> 16) & 0xFF;
2273 size = ((unsigned char) ~size) + 1;
2276 * (0x07 + 1) * 16 = 128 MiB
2277 * (0x0f + 1) * 16 = 256 MiB
2282 * Aquila Rev0.5 4G3G1G
2283 * Aquila Rev0.8 4G3G1G
2284 * Aquila Rev0.9 4G3G1G
2286 if (mach_is_aquila() || mach_is_kessler())
2287 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2288 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2290 sz = (memconfig1 >> 16) & 0xFF;
2291 sz = ((unsigned char) ~sz) + 1;
2297 * bi_dram[1].size contains all DMC1 memory size
2299 gd->bd->bi_dram[1].size = (size + sz) << 20;
2304 /* Used for sleep test */
2305 static unsigned char saved_val[4][2];
2306 void board_sleep_init_late(void)
2308 /* CODEC_LDO_EN: GPF3[4] */
2309 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2310 /* CODEC_XTAL_EN: GPH3[2] */
2311 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2313 /* MMC T_FLASH off */
2314 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2316 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2317 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2318 /* MHL_ON for REV02 or higher */
2319 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2322 void board_sleep_init(void)
2325 unsigned char val[2];
2328 if (max8998_probe())
2331 if (mach_is_kessler()) {
2333 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2334 saved_val[0][0] = val[0];
2335 saved_val[0][1] = val[1];
2336 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2337 (1 << 1) | (1 << 0));
2338 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2339 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2342 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2343 saved_val[1][0] = val[0];
2344 saved_val[1][1] = val[1];
2345 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2346 (1 << 2) | (1 << 1) | (1 << 0));
2348 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2349 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2352 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2353 saved_val[2][0] = val[0];
2354 saved_val[2][1] = val[1];
2355 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2356 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2357 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2360 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2361 saved_val[3][0] = val[0];
2362 saved_val[3][1] = val[1];
2363 val[0] &= ~((1 << 6) | (1 << 4));
2364 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2365 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2367 printf("Turned off regulators with Kessler setting."
2368 " Preparing to sleep. [%s:%d]\n",
2369 __FILE__, __LINE__);
2370 } else { /* Default */
2372 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2373 saved_val[0][0] = val[0];
2374 saved_val[0][1] = val[1];
2375 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2376 (1 << 1) | (1 << 0));
2377 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2378 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2381 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2382 saved_val[1][0] = val[0];
2383 saved_val[1][1] = val[1];
2384 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2385 (1 << 2) | (1 << 1) | (1 << 0));
2387 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2388 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2391 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2392 saved_val[2][0] = val[0];
2393 saved_val[2][1] = val[1];
2394 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2395 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2396 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2400 saved_val[3][0] = val[0];
2401 saved_val[3][1] = val[1];
2402 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2403 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2404 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2406 printf("Turned off regulators with default(Aquila) setting."
2407 " Preparing to sleep. [%s:%d]\n",
2408 __FILE__, __LINE__);
2412 void board_sleep_resume(void)
2415 unsigned char val[2];
2420 if (max8998_probe())
2424 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2425 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2427 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2430 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2431 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2433 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2434 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2435 printf("Waked up.\n");
2437 /* check max17040 */
2444 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2446 static int s5pc1xx_phy_control(int on)
2450 if (on && !status) {
2451 #ifdef CONFIG_CMD_PMIC
2452 run_command("pmic ldo 3 on", 0);
2455 if (board_is_limo_universal() ||
2456 board_is_limo_real() ||
2458 /* check usb path */
2459 if (board_is_limo_real() && !hwrevision(6))
2463 if (mach_is_tickertape())
2464 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2465 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2467 /* USB Path to AP */
2468 micro_usb_switch(0);
2470 } else if (!on && status) {
2471 #ifdef CONFIG_CMD_PMIC
2472 run_command("pmic ldo 3 off", 0);
2481 struct s3c_plat_otg_data s5pc110_otg_data = {
2482 .phy_control = s5pc1xx_phy_control,
2483 .regs_phy = S5PC110_PHY_BASE,
2484 .regs_otg = S5PC110_OTG_BASE,
2487 int board_eth_init(bd_t *bis)
2491 if (cpu_is_s5pc100())
2494 s3c_udc_probe(&s5pc110_otg_data);
2495 if (usb_eth_initialize(bis) >= 0)
2501 #ifdef CONFIG_CMD_USBDOWN
2502 int usb_board_init(void)
2504 #ifdef CONFIG_CMD_PMIC
2505 run_command("pmic ldo 3 on", 0);
2508 if (cpu_is_s5pc100()) {
2509 #ifdef CONFIG_HARD_I2C
2510 uchar val[2] = {0,};
2513 if (i2c_read(0x66, 0, 1, val, 2)) {
2514 printf("i2c_read error\n");
2521 if (i2c_write(0x66, 0, 1, val, 2)) {
2522 printf("i2c_write error\n");
2525 i2c_read(0x66, 0, 1, val, 2);
2531 if (board_is_limo_universal() ||
2532 board_is_limo_real() ||
2534 /* check usb path */
2535 if (board_is_limo_real() && !hwrevision(6))
2539 if (mach_is_tickertape())
2540 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2541 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2543 /* USB Path to AP */
2544 micro_usb_switch(0);
2550 #ifdef CONFIG_GENERIC_MMC
2551 int s5p_no_mmc_support(void)
2553 if (mach_is_wmg160())
2558 int board_mmc_init(bd_t *bis)
2562 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2565 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2566 if (mach_is_kessler())
2567 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2569 if (mach_is_wmg160())
2572 /* MMC0 Clock source = SCLKMPLL */
2573 reg = readl(&clk->src4);
2576 writel(reg, &clk->src4);
2578 reg = readl(&clk->div4);
2581 /* set div value near 50MHz */
2582 clock = get_pll_clk(MPLL) / 1000000;
2583 for (i = 0; i < 0xf; i++) {
2584 if ((clock / (i + 1)) <= 50) {
2590 writel(reg, &clk->div4);
2596 * GPG0[2] SD_0_CDn -> Not used
2597 * GPG0[3:6] SD_0_DATA[0:3]
2599 for (i = 0; i < 7; i++) {
2602 /* GPG0[0:6] special function 2 */
2603 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2604 /* GPG0[0:6] pull disable */
2605 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2606 /* GPG0[0:6] drv 4x */
2607 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2610 if (mach_is_geminus()) {
2611 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2612 gpio_set_pull(&s5pc110_gpio->gpio_j2, 7, GPIO_PULL_NONE);
2615 return s5pc1xx_mmc_init(0);
2619 #ifdef CONFIG_CMD_PMIC
2620 static int pmic_status(void)
2622 unsigned char addr, val[2];
2627 if (max8998_probe())
2631 i2c_read(addr, reg, 1, val, 1);
2632 for (i = 7; i >= 4; i--)
2633 printf("BUCK%d %s\n", 7 - i + 1,
2634 val[0] & (1 << i) ? "on" : "off");
2636 printf("LDO%d %s\n", 5 - i,
2637 val[0] & (1 << i) ? "on" : "off");
2639 i2c_read(addr, reg, 1, val, 1);
2640 for (i = 7; i >= 0; i--)
2641 printf("LDO%d %s\n", 7 - i + 6,
2642 val[0] & (1 << i) ? "on" : "off");
2644 i2c_read(addr, reg, 1, val, 1);
2645 for (i = 7; i >= 4; i--)
2646 printf("LDO%d %s\n", 7 - i + 14,
2647 val[0] & (1 << i) ? "on" : "off");
2650 i2c_read(addr, reg, 1, val, 1);
2651 for (i = 7; i >= 6; i--)
2652 printf("SAFEOUT%d %s\n", 7 - i + 1,
2653 val[0] & (1 << i) ? "on" : "off");
2657 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2659 unsigned char addr, val[2];
2660 unsigned int reg, shift;
2668 } else if (ldo <= 13) {
2671 } else if (ldo <= 17) {
2673 shift = 17 - ldo + 4;
2680 shift = 4 - buck + 4;
2681 } else if (safeout) {
2685 shift = 8 - safeout;
2691 if (max8998_probe())
2694 i2c_read(addr, reg, 1, val, 1);
2696 val[0] |= (1 << shift);
2698 val[0] &= ~(1 << shift);
2699 i2c_write(addr, reg, 1, val, 1);
2700 i2c_read(addr, reg, 1, val, 1);
2703 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2704 val[0] & (1 << shift) ? "on" : "off");
2706 printf("buck %d value 0x%x, %s\n", buck, val[0],
2707 val[0] & (1 << shift) ? "on" : "off");
2709 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2710 val[0] & (1 << shift) ? "on" : "off");
2715 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2717 int buck = 0, ldo = 0, safeout = 0, on = -1;
2721 if (strncmp(argv[1], "status", 6) == 0)
2722 return pmic_status();
2725 if (strncmp(argv[1], "ldo", 3) == 0)
2726 ldo = simple_strtoul(argv[2], NULL, 10);
2727 else if (strncmp(argv[1], "buck", 4) == 0)
2728 buck = simple_strtoul(argv[2], NULL, 10);
2729 else if (strncmp(argv[1], "safeout", 7) == 0)
2730 safeout = simple_strtoul(argv[2], NULL, 10);
2734 if (strncmp(argv[3], "on", 2) == 0)
2736 else if (strncmp(argv[3], "off", 3) == 0)
2741 return pmic_ldo_control(buck, ldo, safeout, on);
2752 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2753 "PMIC LDO & BUCK control",
2754 "status - Display PMIC LDO & BUCK status\n"
2755 "pmic ldo num on/off - Turn on/off the LDO\n"
2756 "pmic buck num on/off - Turn on/off the BUCK\n"
2757 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2761 #ifdef CONFIG_CMD_DEVICE_POWER
2762 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2766 if (strncmp(argv[1], "cp", 2) == 0) {
2767 micro_usb_switch(1);
2768 pmic_ldo_control(0, 0, 2, 1);
2769 setenv("usb", "cp");
2770 } else if (strncmp(argv[1], "ap", 2) == 0) {
2771 micro_usb_switch(0);
2772 pmic_ldo_control(0, 0, 2, 0);
2773 setenv("usb", "ap");
2783 printf("USB Path is set to %s\n", getenv("usb"));
2789 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2791 "cp - switch to CP\n"
2792 "microusb ap - switch to AP\n"