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 ARIES_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 512
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 strcat(device_info, buf);
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 & ARIES_BOARD)
399 if (board_rev & NEPTUNE_BOARD)
403 count += sprintf(buf + count, " - %s", name);
408 static char *get_board_name(int board)
410 if (board == MACH_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_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 & ARIES_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 &= ~BOARD_MASK;
447 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, mode3);
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, mode3, 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, mode3) << 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) {
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) {
543 board_rev |= LIMO_REAL_BOARD;
546 /* C110 Aquila Bamboo */
547 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
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 |= ARIES_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 &= ~ARIES_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);
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;
630 /* Architecture Common settings */
631 if (cpu_is_s5pc110()) {
632 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
634 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
636 setenv("updatek", "onenand erase 0x60000 0x300000; "
637 "onenand write 0x31008000 0x60000 0x300000");
641 static void show_hw_revision(void)
646 * Workaround for Rev 0.3 + CP Ver ES 3.1
649 if (board_is_limo_real()) {
651 /* default is Rev 0.4 */
657 if (machine_is_kessler() || machine_is_aquila())
658 board = gd->bd->bi_arch_number;
659 else if (cpu_is_s5pc110())
660 board = gd->bd->bi_arch_number - C110_MACH_START;
662 board = gd->bd->bi_arch_number - C100_MACH_START;
665 check_board_revision(board, board_rev);
667 /* Set CPU Revision */
668 if (machine_is_aquila()) {
669 if (board_is_limo_real()) {
670 if ((board_rev & 0xf) < 8)
671 s5pc1xx_set_cpu_rev(0);
673 } else if (machine_is_kessler())
674 s5pc1xx_set_cpu_rev(1);
675 else if (machine_is_geminus()) {
676 if ((board_rev & 0xf) < 1)
677 s5pc1xx_set_cpu_rev(0);
678 } else if (machine_is_cypress())
679 s5pc1xx_set_cpu_rev(1);
681 s5pc1xx_set_cpu_rev(0);
683 dprintf("HW Revision:\t%x (%s%s) %s\n",
684 board_rev, get_board_name(board),
685 display_features(board, board_rev),
686 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
689 static void check_auto_burn(void)
691 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
692 unsigned int count = 0;
695 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
696 printf("Auto burning bootloader\n");
697 count += sprintf(buf + count, "run updateb; ");
699 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
700 printf("Auto burning kernel\n");
701 count += sprintf(buf + count, "run updatek; ");
705 count += sprintf(buf + count, "reset");
706 setenv("bootcmd", buf);
709 /* Clear the magic value */
710 writel(0xa5a55a5a, magic_base);
711 writel(0xa5a55a5a, magic_base + 0x4);
714 static void pmic_pin_init(void)
716 unsigned int reg, value;
718 if (cpu_is_s5pc100())
721 /* AP_PS_HOLD: XEINT_0: GPH0[0]
722 * Note: Don't use GPIO PS_HOLD it doesn't work
724 reg = S5PC110_PS_HOLD_CONTROL;
726 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
727 S5PC110_PS_HOLD_DATA_HIGH |
728 S5PC110_PS_HOLD_OUT_EN;
731 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
732 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
733 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
736 static void enable_ldos(void)
738 if (cpu_is_s5pc100())
741 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
742 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
745 static void enable_t_flash(void)
747 if (!(board_is_limo_universal() || board_is_limo_real()))
750 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
751 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
754 static void setup_limo_real_gpios(void)
756 if (!board_is_limo_real())
760 * Note: Please write GPIO alphabet order
762 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
763 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
766 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
767 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
769 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
770 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
772 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
773 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
774 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
777 static void setup_media_gpios(void)
779 if (!board_is_media())
783 * Note: Please write GPIO alphabet order
785 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
786 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
788 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
789 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
790 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
793 #define KBR3 (1 << 3)
794 #define KBR2 (1 << 2)
795 #define KBR1 (1 << 1)
796 #define KBR0 (1 << 0)
798 static void check_keypad(void)
800 unsigned int reg, value;
801 unsigned int col_num, row_num;
802 unsigned int col_mask;
803 unsigned int col_mask_shift;
804 unsigned int row_state[4];
806 unsigned int auto_download = 0;
808 if (machine_is_wmg160())
811 if (cpu_is_s5pc100()) {
812 struct s5pc100_gpio *gpio =
813 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
818 /* Set GPH2[2:0] to KP_COL[2:0] */
819 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
820 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
821 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
823 /* Set GPH3[2:0] to KP_ROW[2:0] */
824 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
825 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
826 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
828 reg = S5PC100_KEYPAD_BASE;
829 col_mask = S5PC1XX_KEYIFCOL_MASK;
832 if (board_is_limo_real() || board_is_limo_universal()) {
840 for (i = 0; i < row_num; i++) {
841 /* Set GPH3[3:0] to KP_ROW[3:0] */
842 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
843 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
846 for (i = 0; i < col_num; i++)
847 /* Set GPH2[3:0] to KP_COL[3:0] */
848 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
850 reg = S5PC110_KEYPAD_BASE;
851 col_mask = S5PC110_KEYIFCOLEN_MASK;
855 /* KEYIFCOL reg clear */
856 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
859 for (i = 0; i < col_num; i++) {
861 value &= ~(1 << i) << col_mask_shift;
863 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
866 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
867 row_state[i] = ~value & ((1 << row_num) - 1);
869 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
872 /* KEYIFCOL reg clear */
873 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
875 if (machine_is_aquila() || machine_is_kessler()) {
876 /* cam full shot & volume down */
877 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
880 else if ((row_state[1] & 0x2))
882 } else if (machine_is_geminus())
883 /* volume down & home */
884 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
888 setenv("bootcmd", "usbdown");
891 static void check_battery(int mode)
893 unsigned char val[2];
894 unsigned char addr = 0x36; /* max17040 fuel gauge */
896 i2c_set_bus_num(I2C_GPIO3);
898 if (machine_is_aquila()) {
901 } else if (machine_is_kessler())
902 i2c_set_bus_num(I2C_GPIO7);
903 else if (machine_is_cypress()) {
904 i2c_set_bus_num(I2C_GPIO7);
905 } else if (machine_is_geminus()) {
907 i2c_set_bus_num(I2C_GPIO7);
911 if (i2c_probe(addr)) {
912 printf("Can't found max17040 fuel gauge\n");
916 /* mode 0: check mode / 1: enable mode */
920 i2c_write(addr, 0xfe, 1, val, 2);
922 i2c_read(addr, 0x04, 1, val, 1);
923 dprintf("battery:\t%d%%\n", val[0]);
924 battery_soc = val[0];
928 static void check_mhl(void)
930 unsigned char val[2];
931 unsigned char addr = 0x39; /* SIL9230 */
933 /* MHL Power enable */
934 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
935 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
937 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
938 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
940 /* 10ms required after reset */
944 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
946 i2c_set_bus_num(I2C_GPIO5);
949 if (i2c_probe(addr)) {
950 printf("Can't found MHL Chip\n");
956 * set to Normal operation
959 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
960 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
965 * 00 = MHL termination ON
966 * 11 = MHL termination OFF
969 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
970 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
973 #define CHARGER_ANIMATION_FRAME 6
974 static int max8998_power_key(void)
976 unsigned char addr, val[2];
977 i2c_set_bus_num(I2C_PMIC);
979 if (i2c_probe(addr)) {
980 printf("Can't found max8998\n");
984 /* Accessing IRQ1 register */
985 i2c_read(addr, 0x00, 1, val, 1);
986 if (val[0] & (1 << 6))
992 static int max8998_has_ext_power_source(void)
994 unsigned char addr, val[2];
995 i2c_set_bus_num(I2C_PMIC);
997 if (i2c_probe(addr)) {
998 printf("Can't found max8998\n");
1002 /* Accessing STATUS2 register */
1003 i2c_read(addr, 0x09, 1, val, 1);
1004 if (val[0] & (1 << 5))
1010 struct thermister_stat {
1015 static struct thermister_stat adc_to_temperature_data[] = {
1016 { .centigrade = -20, .adc = 1856, },
1017 { .centigrade = -15, .adc = 1799, },
1018 { .centigrade = -10, .adc = 1730, },
1019 { .centigrade = -5, .adc = 1649, },
1020 { .centigrade = 0, .adc = 1556, },
1021 { .centigrade = 5, .adc = 1454, },
1022 { .centigrade = 10, .adc = 1343, },
1023 { .centigrade = 15, .adc = 1227, },
1024 { .centigrade = 20, .adc = 1109, },
1025 { .centigrade = 25, .adc = 992, },
1026 { .centigrade = 30, .adc = 880, },
1027 { .centigrade = 35, .adc = 773, },
1028 { .centigrade = 40, .adc = 675, },
1029 { .centigrade = 45, .adc = 586, },
1030 { .centigrade = 50, .adc = 507, },
1031 { .centigrade = 55, .adc = 436, },
1032 { .centigrade = 58, .adc = 399, },
1033 { .centigrade = 63, .adc = 343, },
1034 { .centigrade = 65, .adc = 322, },
1038 #define USHRT_MAX 0xFFFFU
1040 static int adc_to_temperature_centigrade(unsigned short adc)
1044 /* low_*: Greatest Lower Bound,
1045 * * * * high_*: Smallest Upper Bound */
1046 int low_temp, high_temp;
1047 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1048 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1049 if (adc_to_temperature_data[i].adc <= adc &&
1050 adc_to_temperature_data[i].adc >= low_adc) {
1051 low_temp = adc_to_temperature_data[i].centigrade;
1052 low_adc = adc_to_temperature_data[i].adc;
1054 if (adc_to_temperature_data[i].adc >= adc &&
1055 adc_to_temperature_data[i].adc <= high_adc) {
1056 high_temp = adc_to_temperature_data[i].centigrade;
1057 high_adc = adc_to_temperature_data[i].adc;
1061 /* Linear approximation between cloest low and high,
1062 * which is the weighted average of the two. */
1064 /* The following equation is correct only when the two are different */
1065 if (low_adc == high_adc)
1067 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1068 return 20; /* The room temperature */
1071 if (high_adc == USHRT_MAX)
1073 approximation = low_temp * (adc - low_adc) +
1074 high_temp * (high_adc - adc);
1075 approximation /= high_adc - low_adc;
1076 return approximation;
1079 static unsigned short get_adc_value(int channel)
1081 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1082 unsigned short ret = 0;
1086 unsigned int loop = 0;
1088 if (machine_is_kessler())
1090 else if (machine_is_geminus())
1092 else if (machine_is_wmg160())
1094 else if (machine_is_cypress())
1096 else if (machine_is_tickertape())
1098 else if (machine_is_aquila())
1101 else if (machine_is_p1p2())
1105 sprintf(buf, "pmic ldo %d on", ldonum);
1106 run_command(buf, 0);
1107 writel(channel & 0xF, &adc->adcmux);
1108 writel((1 << 14) | (49 << 6), &adc->adccon);
1109 writel(1000 & 0xffff, &adc->adcdly);
1110 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1112 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1116 reg = readl(&adc->adccon);
1117 } while (!reg & (1 << 15) && loop++ < 1000);
1118 ret = readl(&adc->adcdat0) & 0xFFF;
1119 sprintf(buf, "pmic ldo %d off", ldonum);
1120 run_command(buf, 0);
1125 static int adc_get_average_ambient_temperature(void)
1127 if (machine_is_kessler()) {
1128 unsigned short min = USHRT_MAX;
1129 unsigned short max = 0;
1130 unsigned int sum = 0;
1131 unsigned int measured = 0;
1134 for (i = 0; i < 7; i++) {
1135 unsigned short measurement = get_adc_value(6);
1138 if (min > measurement)
1140 if (max < measurement)
1143 if (measured >= 3) {
1149 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1150 adc_to_temperature_centigrade(sum), sum);
1151 return adc_to_temperature_centigrade(sum);
1154 return 20; /* 20 Centigrade */
1157 enum temperature_level {
1165 static enum temperature_level temperature_check(void)
1167 int temp = adc_get_average_ambient_temperature();
1169 return _TEMP_TOO_LOW;
1171 return _TEMP_OK_LOW;
1173 return _TEMP_TOO_HIGH;
1175 return _TEMP_OK_HIGH;
1179 extern void lcd_display_clear(void);
1180 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1182 static void charger_en(int enable)
1188 unsigned char addr = 0xCC >> 1; /* max8998 */
1189 unsigned char val[2];
1191 i2c_set_bus_num(I2C_PMIC);
1192 if (i2c_probe(addr)) {
1193 printf("Can't found max8998 (%s:%d)\n", __func__, __LINE__);
1198 printf("Disable the charger.\n");
1199 i2c_read(addr, 0x0D, 1, val, 1);
1202 i2c_write(addr, 0x0D, 1, val, 1);
1204 i2c_read(addr, 0x0C, 1, val, 1);
1205 val[0] &= ~(0x7 << 0);
1206 val[0] &= ~(0x7 << 5);
1207 if (enable == 600) {
1208 val[0] |= 5; /* 600mA */
1209 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1210 } else { /* Assume 475 mA */
1212 val[0] |= 2; /* 475mA */
1213 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1215 i2c_write(addr, 0x0C, 1, val, 1);
1217 i2c_read(addr, 0x0D, 1, val, 1);
1219 i2c_write(addr, 0x0D, 1, val, 1);
1220 printf("Enable the charger @ %dmA\n", enable);
1224 static void into_charge_mode(void)
1230 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1231 unsigned int reg, wakeup_stat;
1232 int charger_speed = 600;
1234 printf("Charge Mode\n");
1235 charger_en(charger_speed);
1237 #ifdef CONFIG_S5PC1XXFB
1240 /* TODO: write the image-text for the charger */
1242 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1243 if (level >= CHARGER_ANIMATION_FRAME)
1244 level = CHARGER_ANIMATION_FRAME - 1;
1246 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1247 bmp_addr[i] = (ulong)battery_charging_animation[i];
1249 lcd_display_clear();
1250 for (i = 0; i < 3; i++) {
1251 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1254 bmp = gunzip_bmp(bmp_addr[j], &len);
1255 lcd_display_bitmap((ulong) bmp, 140, 202);
1258 for (k = 0; k < 10; k++)
1259 if (max8998_power_key()) {
1260 lcd_display_clear();
1262 } else if (!max8998_has_ext_power_source()) {
1263 lcd_display_clear();
1273 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1274 unsigned int org, org_ip3, org_tcfg0;
1275 enum temperature_level previous_state = _TEMP_OK;
1277 empty_device_info_buffer();
1278 if (max8998_power_key()) {
1279 lcd_display_clear();
1281 } else if (!max8998_has_ext_power_source()) {
1282 lcd_display_clear();
1286 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1287 org_ip3 = readl(0xE010046C);
1288 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1290 reg = org = readl(&rtc->rtccon);
1292 writel(reg, &rtc->rtccon);
1294 reg = readl(&rtc->rtccon);
1295 writel(reg | (1 << 3), &rtc->rtccon);
1297 writel(reg & ~(1 << 3), &rtc->rtccon);
1300 reg = readl(&rtc->rtccon);
1301 reg &= ~( (1 << 8) | (0xF << 4));
1302 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1303 writel(reg, &rtc->rtccon);
1305 reg = 15 * 4 - 1; /* 15 sec */
1306 writel(reg, &rtc->ticcnt);
1308 /* TODO: turn LCD/FB off for sure */
1311 /* EVT0: sleep 1, EVT1: sleep */
1312 if (cpu_is_s5pc110()) {
1313 char *name = "dummy";
1314 char *usage = "N/A";
1321 if (s5pc1xx_get_cpu_rev() == 0) {
1322 char *argv[] = {"1", "1"};
1323 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1325 char *argv[] = {"0", "0"};
1326 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1329 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1334 /* Check TEMP HIGH/LOW */
1335 switch (temperature_check()) {
1337 charger_en(charger_speed);
1338 previous_state = _TEMP_OK;
1342 previous_state = _TEMP_TOO_LOW;
1344 case _TEMP_TOO_HIGH:
1346 previous_state = _TEMP_TOO_HIGH;
1349 if (previous_state == _TEMP_TOO_LOW)
1353 charger_en(charger_speed);
1354 previous_state = _TEMP_OK;
1358 if (previous_state == _TEMP_TOO_HIGH)
1362 charger_en(charger_speed);
1363 previous_state = _TEMP_OK;
1368 writel(org, &rtc->rtccon);
1369 writel(org_tcfg0, 0xE2600000);
1370 writel(org_ip3, 0xE010046C);
1372 } while (wakeup_stat == 0x04); /* RTC TICK */
1374 /* TODO: Reenable logo display */
1378 run_command("cls", 0);
1381 static void check_micro_usb(int intr)
1384 unsigned char val[2];
1385 static int started_charging_once = 0;
1388 if (cpu_is_s5pc100())
1391 if (board_is_limo_real()) {
1392 if (hwrevision(0) || hwrevision(1))
1396 i2c_set_bus_num(I2C_PMIC);
1398 if (machine_is_kessler())
1399 i2c_set_bus_num(I2C_GPIO6);
1400 else if (machine_is_cypress()) {
1401 i2c_set_bus_num(I2C_GPIO6);
1402 } else if (machine_is_geminus()) {
1404 i2c_set_bus_num(I2C_GPIO6);
1405 } else if (machine_is_wmg160())
1406 i2c_set_bus_num(I2C_GPIO6);
1408 addr = 0x25; /* fsa9480 */
1409 if (i2c_probe(addr)) {
1410 printf("Can't found fsa9480\n");
1414 /* Clear Interrupt */
1416 i2c_read(addr, 0x03, 1, val, 2);
1420 /* Read Device Type 1 */
1421 i2c_read(addr, 0x0a, 1, val, 1);
1423 #define FSA_DEV1_CHARGER (1 << 6)
1424 #define FSA_DEV1_UART (1 << 3)
1425 #define FSA_DEV1_USB (1 << 2)
1426 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1427 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1430 * If USB, use default 475mA
1431 * If Charger, use 600mA and go to charge mode
1433 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1434 started_charging_once = 1;
1436 /* If it's full, do not charge. */
1437 if (battery_soc < 100)
1442 else if (val[0] & FSA_DEV1_USB) {
1443 if (battery_soc < 100)
1449 /* If Factory Mode is Boot ON-USB, go to download mode */
1450 i2c_read(addr, 0x07, 1, val, 1);
1452 #define FSA_ADC_FAC_USB_OFF 0x18
1453 #define FSA_ADC_FAC_USB_ON 0x19
1454 #define FSA_ADC_FAC_UART 0x1d
1456 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1457 setenv("bootcmd", "usbdown");
1459 path = getenv("usb");
1461 if (!strncmp(path, "cp", 2))
1462 run_command("microusb cp", 0);
1465 static void micro_usb_switch(int path)
1468 unsigned char val[2];
1470 i2c_set_bus_num(I2C_PMIC);
1472 if (machine_is_kessler())
1473 i2c_set_bus_num(I2C_GPIO6);
1474 else if (machine_is_cypress()) {
1475 i2c_set_bus_num(I2C_GPIO6);
1476 } else if (machine_is_geminus()) {
1478 i2c_set_bus_num(I2C_GPIO6);
1479 } else if (machine_is_wmg160()) {
1480 i2c_set_bus_num(I2C_GPIO6);
1484 addr = 0x25; /* fsa9480 */
1485 if (i2c_probe(addr)) {
1486 printf("Can't found fsa9480\n");
1491 val[0] = 0x90; /* VAUDIO */
1493 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1495 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1497 i2c_read(addr, 0x2, 1, val, 1);
1498 val[0] &= ~(1 << 2); /* Manual switching */
1499 i2c_write(addr, 0x2, 1, val, 1);
1502 #define MAX8998_REG_ONOFF1 0x11
1503 #define MAX8998_REG_ONOFF2 0x12
1504 #define MAX8998_REG_ONOFF3 0x13
1505 #define MAX8998_REG_LDO7 0x21
1506 #define MAX8998_REG_LDO17 0x29
1508 #define MAX8998_LDO3 (1 << 2)
1510 #define MAX8998_LDO6 (1 << 7)
1511 #define MAX8998_LDO7 (1 << 6)
1512 #define MAX8998_LDO8 (1 << 5)
1513 #define MAX8998_LDO9 (1 << 4)
1514 #define MAX8998_LDO10 (1 << 3)
1515 #define MAX8998_LDO11 (1 << 2)
1516 #define MAX8998_LDO12 (1 << 1)
1517 #define MAX8998_LDO13 (1 << 0)
1519 #define MAX8998_LDO14 (1 << 7)
1520 #define MAX8998_LDO15 (1 << 6)
1521 #define MAX8998_LDO16 (1 << 5)
1522 #define MAX8998_LDO17 (1 << 4)
1525 static void init_pmic(void)
1528 unsigned char val[2];
1530 if (cpu_is_s5pc100())
1533 i2c_set_bus_num(I2C_PMIC);
1535 addr = 0xCC >> 1; /* max8998 */
1536 if (i2c_probe(addr)) {
1537 printf("Can't found max8998\n");
1542 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1543 val[0] &= ~MAX8998_LDO3;
1544 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1547 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1549 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1550 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1552 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1553 MAX8998_LDO12 | MAX8998_LDO13);
1555 if (machine_is_kessler())
1556 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1558 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1559 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1561 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1563 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1564 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1566 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1567 MAX8998_LDO16 | MAX8998_LDO17);
1569 if (machine_is_kessler())
1570 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1572 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1573 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1576 static void setup_power_down_mode_registers(void)
1578 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1579 struct s5pc1xx_gpio_bank *bank;
1580 struct gpio_powermode *p;
1582 struct gpio_external *ge;
1584 struct s5pc1xx_gpio_item *mr;
1588 if (cpu_is_s5pc100())
1591 /* Only Limo real and kessler supports worked for sleep currnet */
1592 if (machine_is_aquila()) {
1593 if (board_is_limo_real())
1597 } else if (machine_is_kessler()) {
1599 } else if (machine_is_geminus()) {
1604 if (machine_is_aquila()) {
1605 /* Aquila rev 0.8 or lower */
1606 p = aquila_powerdown_modes;
1607 ge = aquila_external_powerdown_modes;
1608 mr = aquila_mirror_powerdown_mode;
1609 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1610 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1611 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1612 } else if (machine_is_kessler()) {
1613 /* Aquila rev 0.9 */
1614 p = kessler_powerdown_modes;
1615 ge = kessler_external_powerdown_modes;
1616 mr = kessler_mirror_powerdown_mode;
1617 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1618 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1619 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1620 } else if (machine_is_geminus()) {
1621 if (hwrevision(1)) {
1622 /* Same as Aquila rev 0.9 */
1624 p = kessler_powerdown_modes;
1625 ge = kessler_external_powerdown_modes;
1626 mr = kessler_mirror_powerdown_mode;
1627 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1628 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1629 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1631 p = aquila_powerdown_modes;
1632 ge = aquila_external_powerdown_modes;
1633 mr = aquila_mirror_powerdown_mode;
1634 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1635 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1636 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1638 } else if (hwrevision(0)) {
1639 /* Same as 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);
1647 return; /* Not supported */
1651 bank = &gpio->gpio_a0;
1653 for (i = 0; i < n_p; i++, p++, bank++) {
1654 writel(p->conpdn, &bank->pdn_con);
1655 writel(p->pudpdn, &bank->pdn_pull);
1658 writel(0xff0022b0, (unsigned int *)0xF0000000);
1659 writel(0xff0022b0, (unsigned int *)0xF1400000);
1661 bank = &gpio->gpio_h0;
1663 for (i = 0; i < n_ge; i++) {
1664 writel(ge->con, &bank->con);
1665 writel(ge->dat, &bank->dat);
1666 writel(ge->pud, &bank->pull);
1672 for (i = 0; i < n_mr; i++) {
1673 unsigned int reg = readl(&mr->bank->pdn_con);
1674 reg &= ~(1 << mr->number);
1675 if (readl(&mr->bank->dat) & (1 << mr->number))
1676 reg |= 1 << mr->number;
1677 writel(reg, &mr->bank->pdn_con);
1683 #include "../../../drivers/video/s5p-spi.h"
1685 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1686 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1688 struct spi_platform_data spi_pd;
1690 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1692 void lcd_cfg_gpio(void)
1694 unsigned int i, f3_end = 4;
1696 for (i = 0; i < 8; i++) {
1697 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1698 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1699 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1700 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1701 /* pull-up/down disable */
1702 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1703 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1704 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1706 /* drive strength to max (24bit) */
1707 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1708 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1709 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1710 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1711 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1712 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1715 /* set DISPLAY_DE_B pin for dual rgb mode. */
1716 if (board_is_media())
1719 for (i = 0; i < f3_end; i++) {
1720 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1721 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1722 /* pull-up/down disable */
1723 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1724 /* drive strength to max (24bit) */
1725 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1726 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1728 /* display output path selection (only [1:0] valid) */
1729 writel(0x2, 0xE0107008);
1731 /* gpio pad configuration for LCD reset. */
1732 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1734 /* gpio pad configuration for LCD ON. */
1735 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1737 /* LCD_BACKLIGHT_EN */
1738 if (machine_is_geminus())
1739 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1740 if (board_is_neptune()) {
1741 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1742 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1746 * gpio pad configuration for
1747 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1749 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1750 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1751 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1752 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1754 if (machine_is_aquila() || machine_is_kessler()) {
1755 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1757 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1759 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1761 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1764 if (board_is_neptune())
1765 s6d16a0x_set_platform_data(&spi_pd);
1767 s6e63m0_set_platform_data(&spi_pd);
1768 if (board_is_media())
1773 if (machine_is_cypress()) {
1774 #if 0 /* universal cypress */
1776 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1779 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1781 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1783 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1785 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1787 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1788 #if 0 /* universal cypress */
1789 pd_cs.bank = &gpio_base->gpio_mp0_1;
1792 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1794 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1796 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1801 /* these data would be sent to s6e63m0 lcd panel driver. */
1802 s6e63m0_set_platform_data(&spi_pd);
1808 #define SWRST_REG 0x00
1809 #define LEDCON_REG 0x01
1810 #define LED_CUR_SET_REG 0x03
1811 #define LED_CUR_TR_REG 0x08
1814 #define NORMAL_MODE 0x01
1815 #define CUR_SET 0x63
1818 void backlight_on(unsigned int onoff)
1822 unsigned char val[2];
1823 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1826 if (machine_is_geminus())
1827 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1829 if (machine_is_geminus())
1830 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1833 if (machine_is_kessler() && board_is_neptune()) {
1834 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1837 i2c_set_bus_num(I2C_GPIO5);
1840 if (i2c_probe(addr)) {
1841 if (i2c_probe(addr)) {
1842 printf("Can't found s6d16a0x backlight i2c\n");
1847 i2c_write(addr, SWRST_REG, 1, val, 1);
1850 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1852 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1853 val[0] = NORMAL_MODE;
1854 i2c_write(addr, LEDCON_REG, 1, val, 1);
1859 void reset_lcd(void)
1861 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1863 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1864 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1865 if (machine_is_cypress())
1866 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1869 void lcd_power_on(unsigned int onoff)
1871 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1874 if (machine_is_aquila() || machine_is_geminus())
1875 gpio_set_value(&gpio->gpio_j1, 3, 1);
1877 if (machine_is_cypress())
1878 gpio_set_value(&gpio->gpio_g2, 2, 1);
1880 if (machine_is_kessler()) {
1882 unsigned char val[2];
1883 unsigned char val2[2];
1885 gpio_set_value(&gpio->gpio_j1, 3, 1);
1887 i2c_set_bus_num(I2C_PMIC);
1888 addr = 0xCC >> 1; /* max8998 */
1889 if (i2c_probe(addr)) {
1890 printf("Can't found max8998\n");
1893 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1894 val[0] &= ~(MAX8998_LDO17);
1895 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1896 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1898 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1899 val[0] |= MAX8998_LDO17;
1901 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1902 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1904 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1905 val[0] |= MAX8998_LDO7;
1907 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1908 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1911 if (machine_is_aquila() || machine_is_geminus())
1912 gpio_set_value(&gpio->gpio_j1, 3, 0);
1914 if (machine_is_cypress())
1915 gpio_set_value(&gpio->gpio_g2, 2, 0);
1917 if (machine_is_kessler()) {
1919 unsigned char val[2];
1921 i2c_set_bus_num(I2C_PMIC);
1922 addr = 0xCC >> 1; /* max8998 */
1923 if (i2c_probe(addr)) {
1924 printf("Can't found max8998\n");
1928 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1929 val[0] &= ~(1 << 7);
1930 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1931 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1933 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1934 val[0] &= ~MAX8998_LDO17;
1935 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1936 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1941 extern void s6e63m0_cfg_ldo(void);
1942 extern void s6e63m0_enable_ldo(unsigned int onoff);
1943 extern void s6d16a0x_cfg_ldo(void);
1944 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1946 int s5p_no_lcd_support(void)
1948 if (machine_is_wmg160())
1953 void init_panel_info(vidinfo_t *vid)
1955 vid->cfg_gpio = NULL;
1956 vid->reset_lcd = NULL;
1957 vid->backlight_on = NULL;
1958 vid->lcd_power_on = NULL;
1960 vid->cfg_ldo = NULL;
1961 vid->enable_ldo = NULL;
1963 vid->init_delay = 0;
1964 vid->reset_delay = 0;
1965 vid->power_on_delay = 0;
1970 vid->vl_width = 480;
1971 vid->vl_height = 800;
1973 vid->dual_lcd_enabled = 0;
1975 if (board_is_media()) {
1978 vid->vl_width = 960;
1979 vid->vl_height = 800;
1981 /* enable dual lcd mode. */
1982 vid->dual_lcd_enabled = 1;
1985 vid->vl_clkp = CONFIG_SYS_HIGH;
1986 vid->vl_hsp = CONFIG_SYS_LOW;
1987 vid->vl_vsp = CONFIG_SYS_LOW;
1988 vid->vl_dp = CONFIG_SYS_HIGH;
1991 /* S6E63M0 LCD Panel */
2000 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
2001 vid->cfg_gpio = lcd_cfg_gpio;
2002 vid->reset_lcd = reset_lcd;
2003 vid->backlight_on = backlight_on;
2004 vid->lcd_power_on = lcd_power_on;
2005 vid->cfg_ldo = s6e63m0_cfg_ldo;
2006 vid->enable_ldo = s6e63m0_enable_ldo;
2008 vid->init_delay = 25000;
2009 vid->reset_delay = 120000;
2012 if (board_is_neptune()) {
2016 vid->vl_width = 320;
2017 vid->vl_height = 480;
2019 vid->vl_clkp = CONFIG_SYS_HIGH;
2020 vid->vl_hsp = CONFIG_SYS_HIGH;
2021 vid->vl_vsp = CONFIG_SYS_HIGH;
2022 vid->vl_dp = CONFIG_SYS_LOW;
2025 /* disable dual lcd mode. */
2026 vid->dual_lcd_enabled = 0;
2028 /* S6D16A0X LCD Panel */
2037 vid->cfg_gpio = lcd_cfg_gpio;
2038 vid->backlight_on = backlight_on;
2039 vid->lcd_power_on = lcd_power_on;
2040 vid->reset_lcd = reset_lcd;
2041 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2042 vid->enable_ldo = s6d16a0x_enable_ldo;
2044 vid->init_delay = 10000;
2045 vid->power_on_delay = 10000;
2046 vid->reset_delay = 1000;
2050 if (machine_is_geminus()) {
2054 vid->vl_width = 1024,
2055 vid->vl_height = 600,
2056 vid->vl_clkp = CONFIG_SYS_LOW,
2057 vid->vl_hsp = CONFIG_SYS_HIGH,
2058 vid->vl_vsp = CONFIG_SYS_HIGH,
2059 vid->vl_dp = CONFIG_SYS_LOW,
2070 vid->cfg_gpio = lcd_cfg_gpio;
2071 vid->reset_lcd = reset_lcd;
2072 vid->backlight_on = backlight_on;
2073 vid->lcd_power_on = lcd_power_on;
2079 vid->vl_width = 480,
2080 vid->vl_height = 800,
2081 vid->vl_clkp = CONFIG_SYS_HIGH,
2082 vid->vl_hsp = CONFIG_SYS_LOW,
2083 vid->vl_vsp = CONFIG_SYS_LOW,
2084 vid->vl_dp = CONFIG_SYS_HIGH,
2100 vid->vl_width = 1024,
2101 vid->vl_height = 600,
2102 vid->vl_clkp = CONFIG_SYS_HIGH,
2103 vid->vl_hsp = CONFIG_SYS_HIGH,
2104 vid->vl_vsp = CONFIG_SYS_HIGH,
2105 vid->vl_dp = CONFIG_SYS_LOW,
2108 /* AMS701KA AMOLED Panel. */
2120 static void setup_meminfo(void)
2122 char meminfo[64] = {0, };
2123 int count = 0, size, real;
2125 size = gd->bd->bi_dram[0].size >> 20;
2126 count += sprintf(meminfo + count, "mem=%dM", size);
2128 /* Each Chip Select can't exceed the 256MiB */
2129 size = gd->bd->bi_dram[1].size >> 20;
2130 real = min(size, 256);
2131 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2132 real, (unsigned int)gd->bd->bi_dram[1].start);
2136 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2137 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2140 setenv("meminfo", meminfo);
2143 int misc_init_r(void)
2146 /* It should be located at first */
2149 if (machine_is_aquila() || machine_is_kessler()) {
2150 if (board_is_neptune())
2151 setenv("lcdinfo", "lcd=s6d16a0x");
2152 else if (board_is_media())
2153 setenv("lcdinfo", "lcd=s6e63m0");
2155 setenv("lcdinfo", "lcd=s6e63m0");
2157 if (machine_is_geminus())
2158 setenv("lcdinfo", "lcd=lms480jc01");
2159 if (machine_is_cypress())
2160 setenv("lcdinfo", "lcd=s6e63m0");
2166 /* Set proper PMIC pins */
2169 /* Check auto burning */
2172 /* To power up I2C2 */
2175 /* Enable T-Flash at Limo Real or Limo Universal */
2178 /* Setup Limo Real board GPIOs */
2179 setup_limo_real_gpios();
2181 /* Setup Media board GPIOs */
2182 setup_media_gpios();
2184 /* To usbdown automatically */
2190 #ifdef CONFIG_S5PC1XXFB
2191 display_device_info();
2194 setup_power_down_mode_registers();
2196 /* check max17040 */
2206 int board_init(void)
2208 /* Set Initial global variables */
2209 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2211 gd->bd->bi_arch_number = MACH_AQUILA;
2212 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2214 /* Check H/W Revision */
2215 check_hw_revision();
2222 unsigned int base, memconfig0, size;
2223 unsigned int memconfig1, sz = 0;
2225 if (cpu_is_s5pc100()) {
2226 /* In mem setup, we swap the bank. So below size is correct */
2227 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2228 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2229 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2232 /* In S5PC110, we can't swap the DMC0/1 */
2233 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2234 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2236 base = S5PC110_DMC1_BASE;
2237 /* DMC configuration */
2238 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2239 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2241 size = (memconfig0 >> 16) & 0xFF;
2242 size = ((unsigned char) ~size) + 1;
2245 * (0x07 + 1) * 16 = 128 MiB
2246 * (0x0f + 1) * 16 = 256 MiB
2251 * Aquila Rev0.5 4G3G1G
2252 * Aquila Rev0.8 4G3G1G
2253 * Aquila Rev0.9 4G3G1G
2255 if (machine_is_aquila() || machine_is_kessler())
2256 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2257 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2259 sz = (memconfig1 >> 16) & 0xFF;
2260 sz = ((unsigned char) ~sz) + 1;
2266 * bi_dram[1].size contains all DMC1 memory size
2268 gd->bd->bi_dram[1].size = (size + sz) << 20;
2273 /* Used for sleep test */
2274 static unsigned char saved_val[4][2];
2275 void board_sleep_init_late(void)
2277 /* CODEC_LDO_EN: GPF3[4] */
2278 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2279 /* CODEC_XTAL_EN: GPH3[2] */
2280 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2282 /* MMC T_FLASH off */
2283 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2285 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2286 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2287 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2291 void board_sleep_init(void)
2294 unsigned char val[2];
2296 i2c_set_bus_num(I2C_PMIC);
2298 if (i2c_probe(addr)) {
2299 printf("Can't find max8998\n");
2303 if (machine_is_kessler()) {
2306 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2307 saved_val[0][0] = val[0];
2308 saved_val[0][1] = val[1];
2309 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2310 (1 << 1) | (1 << 0));
2311 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2312 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2314 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2315 saved_val[1][0] = val[0];
2316 saved_val[1][1] = val[1];
2317 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2318 (1 << 2) | (1 << 1) | (1 << 0));
2320 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2321 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2323 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2324 saved_val[2][0] = val[0];
2325 saved_val[2][1] = val[1];
2326 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2327 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2328 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2330 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2331 saved_val[3][0] = val[0];
2332 saved_val[3][1] = val[1];
2333 val[0] &= ~((1 << 6) | (1 << 4));
2334 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2335 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2336 printf("Turned off regulators with Kessler setting."
2337 " Preparing to sleep. [%s:%d]\n",
2338 __FILE__, __LINE__);
2339 } else { /* Default */
2342 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2343 saved_val[0][0] = val[0];
2344 saved_val[0][1] = val[1];
2345 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2346 (1 << 1) | (1 << 0));
2347 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2348 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2350 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2351 saved_val[1][0] = val[0];
2352 saved_val[1][1] = val[1];
2353 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2354 (1 << 2) | (1 << 1) | (1 << 0));
2356 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2357 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2359 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2360 saved_val[2][0] = val[0];
2361 saved_val[2][1] = val[1];
2362 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2363 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2364 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2366 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2367 saved_val[3][0] = val[0];
2368 saved_val[3][1] = val[1];
2369 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2370 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2371 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2372 printf("Turned off regulators with default(Aquila) setting."
2373 " Preparing to sleep. [%s:%d]\n",
2374 __FILE__, __LINE__);
2378 void board_sleep_resume(void)
2381 unsigned char val[2];
2385 i2c_set_bus_num(I2C_PMIC);
2387 if (i2c_probe(addr)) {
2388 printf("Can't find max8998\n");
2393 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2394 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2396 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2397 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2399 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2400 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2402 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2403 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2404 printf("Waked up.\n");
2406 /* check max17040 */
2413 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2415 static int s5pc1xx_phy_control(int on)
2419 if (on && !status) {
2420 // printf("turning USB power on\n");
2421 #ifdef CONFIG_CMD_PMIC
2422 run_command("pmic ldo 3 on", 0);
2425 if (board_is_limo_universal() ||
2426 board_is_limo_real() ||
2428 /* check usb path */
2429 if (board_is_limo_real() && !hwrevision(6))
2433 if (machine_is_tickertape())
2434 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2435 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2437 /* USB Path to AP */
2438 micro_usb_switch(0);
2440 } else if (!on && status) {
2441 // printf("turning USB power off\n");
2442 #ifdef CONFIG_CMD_PMIC
2443 run_command("pmic ldo 3 off", 0);
2452 struct s3c_plat_otg_data s5pc110_otg_data = {
2453 .phy_control = s5pc1xx_phy_control,
2454 .regs_phy = S5PC110_PHY_BASE,
2455 .regs_otg = S5PC110_OTG_BASE,
2458 int board_eth_init(bd_t *bis)
2462 if (cpu_is_s5pc100())
2465 s3c_udc_probe(&s5pc110_otg_data);
2466 if (usb_eth_initialize(bis) >= 0)
2472 #ifdef CONFIG_CMD_USBDOWN
2473 int usb_board_init(void)
2475 #ifdef CONFIG_CMD_PMIC
2476 run_command("pmic ldo 3 on", 0);
2479 if (cpu_is_s5pc100()) {
2480 #ifdef CONFIG_HARD_I2C
2481 uchar val[2] = {0,};
2484 if (i2c_read(0x66, 0, 1, val, 2)) {
2485 printf("i2c_read error\n");
2492 if (i2c_write(0x66, 0, 1, val, 2)) {
2493 printf("i2c_write error\n");
2496 i2c_read(0x66, 0, 1, val, 2);
2502 if (board_is_limo_universal() ||
2503 board_is_limo_real() ||
2505 /* check usb path */
2506 if (board_is_limo_real() && !hwrevision(6))
2510 if (machine_is_tickertape())
2511 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2512 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2514 /* USB Path to AP */
2515 micro_usb_switch(0);
2521 #ifdef CONFIG_GENERIC_MMC
2522 int s5p_no_mmc_support(void)
2524 if (machine_is_wmg160())
2529 int board_mmc_init(bd_t *bis)
2533 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2536 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2537 if (machine_is_kessler())
2538 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2540 if (machine_is_wmg160())
2543 /* MMC0 Clock source = SCLKMPLL */
2544 reg = readl(&clk->src4);
2547 writel(reg, &clk->src4);
2549 reg = readl(&clk->div4);
2552 /* set div value near 50MHz */
2553 clock = get_pll_clk(MPLL) / 1000000;
2554 for (i = 0; i < 0xf; i++) {
2555 if ((clock / (i + 1)) <= 50) {
2561 writel(reg, &clk->div4);
2567 * GPG0[2] SD_0_CDn -> Not used
2568 * GPG0[3:6] SD_0_DATA[0:3]
2570 for (i = 0; i < 7; i++) {
2573 /* GPG0[0:6] special function 2 */
2574 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2575 /* GPG0[0:6] pull disable */
2576 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2577 /* GPG0[0:6] drv 4x */
2578 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2581 return s5pc1xx_mmc_init(0);
2585 #ifdef CONFIG_CMD_PMIC
2586 static int pmic_status(void)
2588 unsigned char addr, val[2];
2591 i2c_set_bus_num(I2C_PMIC);
2593 if (i2c_probe(addr)) {
2594 printf("Can't found max8998\n");
2599 i2c_read(addr, reg, 1, val, 1);
2600 for (i = 7; i >= 4; i--)
2601 printf("BUCK%d %s\n", 7 - i + 1,
2602 val[0] & (1 << i) ? "on" : "off");
2604 printf("LDO%d %s\n", 5 - i,
2605 val[0] & (1 << i) ? "on" : "off");
2607 i2c_read(addr, reg, 1, val, 1);
2608 for (i = 7; i >= 0; i--)
2609 printf("LDO%d %s\n", 7 - i + 6,
2610 val[0] & (1 << i) ? "on" : "off");
2612 i2c_read(addr, reg, 1, val, 1);
2613 for (i = 7; i >= 4; i--)
2614 printf("LDO%d %s\n", 7 - i + 14,
2615 val[0] & (1 << i) ? "on" : "off");
2618 i2c_read(addr, reg, 1, val, 1);
2619 for (i = 7; i >= 6; i--)
2620 printf("SAFEOUT%d %s\n", 7 - i + 1,
2621 val[0] & (1 << i) ? "on" : "off");
2625 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2627 unsigned char addr, val[2];
2628 unsigned int reg, shift;
2636 } else if (ldo <= 13) {
2639 } else if (ldo <= 17) {
2641 shift = 17 - ldo + 4;
2648 shift = 4 - buck + 4;
2649 } else if (safeout) {
2653 shift = 8 - safeout;
2657 i2c_set_bus_num(I2C_PMIC);
2659 if (i2c_probe(addr)) {
2660 printf("Can't found max8998\n");
2664 i2c_read(addr, reg, 1, val, 1);
2666 val[0] |= (1 << shift);
2668 val[0] &= ~(1 << shift);
2669 i2c_write(addr, reg, 1, val, 1);
2670 i2c_read(addr, reg, 1, val, 1);
2673 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2674 val[0] & (1 << shift) ? "on" : "off");
2676 printf("buck %d value 0x%x, %s\n", buck, val[0],
2677 val[0] & (1 << shift) ? "on" : "off");
2679 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2680 val[0] & (1 << shift) ? "on" : "off");
2685 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2687 int buck = 0, ldo = 0, safeout = 0, on = -1;
2691 if (strncmp(argv[1], "status", 6) == 0)
2692 return pmic_status();
2695 if (strncmp(argv[1], "ldo", 3) == 0)
2696 ldo = simple_strtoul(argv[2], NULL, 10);
2697 else if (strncmp(argv[1], "buck", 4) == 0)
2698 buck = simple_strtoul(argv[2], NULL, 10);
2699 else if (strncmp(argv[1], "safeout", 7) == 0)
2700 safeout = simple_strtoul(argv[2], NULL, 10);
2704 if (strncmp(argv[3], "on", 2) == 0)
2706 else if (strncmp(argv[3], "off", 3) == 0)
2711 return pmic_ldo_control(buck, ldo, safeout, on);
2722 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2723 "PMIC LDO & BUCK control",
2724 "status - Display PMIC LDO & BUCK status\n"
2725 "pmic ldo num on/off - Turn on/off the LDO\n"
2726 "pmic buck num on/off - Turn on/off the BUCK\n"
2727 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2731 #ifdef CONFIG_CMD_DEVICE_POWER
2745 static void power_display_devices(void)
2747 printf("devices:\n");
2748 printf("\t%d - touch\n", POWER_TOUCH);
2749 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2750 printf("\t%d - LCD\n", POWER_LCD);
2751 printf("\t%d - Haptic\n", POWER_HAPTIC);
2752 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2753 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2754 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2755 printf("\t%d - HDMI\n", POWER_HDMI);
2758 static int power_hdmi(int on)
2760 /* HDMI_EN1: GPJ2[2] */
2761 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2762 /* MHL_ON: GPJ2[3] */
2763 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2767 static int power_bt_wifi(int on)
2769 /* WLAN_BT_EN: GPB[5] */
2770 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2774 static int power_fm_radio(int on)
2776 /* FM_BUS_nRST: GPJ2[5] */
2777 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2781 static int power_audio_codec(int on)
2783 /* CODEC_LDO_EN: GPF3[4] */
2784 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2785 /* CODEC_XTAL_EN: GPH3[2] */
2786 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2790 static int power_haptic(int on)
2792 /* HAPTIC_ON: GPJ1[1] */
2793 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2797 static int power_lcd(int on)
2799 /* MLCD_ON: GPJ1[3] */
2800 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2804 static int power_touch(int on)
2806 /* TOUCH_EN: GPG3[6] */
2807 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2811 static int power_3_touchkey(int on)
2814 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2815 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2816 if (board_rev & J1_B2_BOARD)
2817 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2819 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2821 /* 3_TOUCH_CE - GPJ2[6] */
2822 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2824 /* 3_TOUCH_CE - GPJ2[6] */
2825 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2830 unsigned char val[2];
2831 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2837 i2c_set_bus_num(I2C_GPIO10);
2839 /* Workaround to probe */
2840 if (i2c_probe(addr)) {
2841 if (i2c_probe(addr)) {
2842 printf("Can't found 3 touchkey\n");
2847 #define MCS5000_TK_HW_VERSION 0x06
2848 #define MCS5000_TK_FW_VERSION 0x0A
2849 #define MCS5000_TK_MI_VERSION 0x0B
2851 reg = MCS5000_TK_MI_VERSION;
2852 i2c_read(addr, reg, 1, val, 1);
2853 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2854 reg = MCS5000_TK_HW_VERSION;
2855 i2c_read(addr, reg, 1, val, 1);
2856 printf("H/W 0x%x, ", val[0]);
2857 reg = MCS5000_TK_FW_VERSION;
2858 i2c_read(addr, reg, 1, val, 1);
2859 printf("F/W 0x%x\n", val[0]);
2864 static int power_control(int device, int on)
2868 return power_touch(on);
2869 case POWER_3_TOUCHKEY:
2870 return power_3_touchkey(on);
2872 return power_lcd(on);
2874 return power_haptic(on);
2875 case POWER_AUDIO_CODEC:
2876 return power_audio_codec(on);
2877 case POWER_FM_RADIO:
2878 return power_fm_radio(on);
2880 return power_bt_wifi(on);
2882 return power_hdmi(on);
2884 printf("I don't know device %d\n", device);
2890 static int power_on(int on)
2893 power_3_touchkey(on);
2896 power_audio_codec(on);
2904 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2908 if (!machine_is_aquila() && !machine_is_kessler())
2913 if (strncmp(argv[1], "on", 2) == 0)
2915 if (strncmp(argv[1], "off", 3) == 0)
2919 device = simple_strtoul(argv[1], NULL, 10);
2923 if (strncmp(argv[2], "on", 2) == 0)
2925 else if (strncmp(argv[2], "off", 3) == 0)
2929 return power_control(device, on);
2935 power_display_devices();
2940 power, CONFIG_SYS_MAXARGS, 1, do_power,
2941 "Device Power Management control",
2942 "device on/off - Turn on/off the device\n"
2945 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2949 if (strncmp(argv[1], "cp", 2) == 0) {
2950 micro_usb_switch(1);
2951 pmic_ldo_control(0, 0, 2, 1);
2952 setenv("usb", "cp");
2953 } else if (strncmp(argv[1], "ap", 2) == 0) {
2954 micro_usb_switch(0);
2955 pmic_ldo_control(0, 0, 2, 0);
2956 setenv("usb", "ap");
2966 printf("USB Path is set to %s\n", getenv("usb"));
2972 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2974 "cp - switch to CP\n"
2975 "microusb ap - switch to AP\n"