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 void max8998_clear_interrupt(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 i2c_read(addr, 0x00, 1, val, 1);
985 i2c_read(addr, 0x01, 1, val, 1);
986 i2c_read(addr, 0x02, 1, val, 1);
987 i2c_read(addr, 0x03, 1, val, 1);
990 static int max8998_power_key(void)
992 unsigned char addr, val[2];
993 i2c_set_bus_num(I2C_PMIC);
995 if (i2c_probe(addr)) {
996 printf("Can't found max8998\n");
1000 /* Accessing IRQ1 register */
1001 i2c_read(addr, 0x00, 1, val, 1);
1002 if (val[0] & (1 << 6))
1008 static int max8998_has_ext_power_source(void)
1010 unsigned char addr, val[2];
1011 i2c_set_bus_num(I2C_PMIC);
1013 if (i2c_probe(addr)) {
1014 printf("Can't found max8998\n");
1018 /* Accessing STATUS2 register */
1019 i2c_read(addr, 0x09, 1, val, 1);
1020 if (val[0] & (1 << 5))
1026 struct thermister_stat {
1031 static struct thermister_stat adc_to_temperature_data[] = {
1032 { .centigrade = -20, .adc = 1856, },
1033 { .centigrade = -15, .adc = 1799, },
1034 { .centigrade = -10, .adc = 1730, },
1035 { .centigrade = -5, .adc = 1649, },
1036 { .centigrade = 0, .adc = 1556, },
1037 { .centigrade = 5, .adc = 1454, },
1038 { .centigrade = 10, .adc = 1343, },
1039 { .centigrade = 15, .adc = 1227, },
1040 { .centigrade = 20, .adc = 1109, },
1041 { .centigrade = 25, .adc = 992, },
1042 { .centigrade = 30, .adc = 880, },
1043 { .centigrade = 35, .adc = 773, },
1044 { .centigrade = 40, .adc = 675, },
1045 { .centigrade = 45, .adc = 586, },
1046 { .centigrade = 50, .adc = 507, },
1047 { .centigrade = 55, .adc = 436, },
1048 { .centigrade = 58, .adc = 399, },
1049 { .centigrade = 63, .adc = 343, },
1050 { .centigrade = 65, .adc = 322, },
1054 #define USHRT_MAX 0xFFFFU
1056 static int adc_to_temperature_centigrade(unsigned short adc)
1060 /* low_*: Greatest Lower Bound,
1061 * * * * high_*: Smallest Upper Bound */
1062 int low_temp, high_temp;
1063 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1064 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1065 if (adc_to_temperature_data[i].adc <= adc &&
1066 adc_to_temperature_data[i].adc >= low_adc) {
1067 low_temp = adc_to_temperature_data[i].centigrade;
1068 low_adc = adc_to_temperature_data[i].adc;
1070 if (adc_to_temperature_data[i].adc >= adc &&
1071 adc_to_temperature_data[i].adc <= high_adc) {
1072 high_temp = adc_to_temperature_data[i].centigrade;
1073 high_adc = adc_to_temperature_data[i].adc;
1077 /* Linear approximation between cloest low and high,
1078 * which is the weighted average of the two. */
1080 /* The following equation is correct only when the two are different */
1081 if (low_adc == high_adc)
1083 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1084 return 20; /* The room temperature */
1087 if (high_adc == USHRT_MAX)
1089 approximation = low_temp * (adc - low_adc) +
1090 high_temp * (high_adc - adc);
1091 approximation /= high_adc - low_adc;
1092 return approximation;
1095 static unsigned short get_adc_value(int channel)
1097 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1098 unsigned short ret = 0;
1102 unsigned int loop = 0;
1104 if (machine_is_kessler())
1106 else if (machine_is_geminus())
1108 else if (machine_is_wmg160())
1110 else if (machine_is_cypress())
1112 else if (machine_is_tickertape())
1114 else if (machine_is_aquila())
1117 else if (machine_is_p1p2())
1121 sprintf(buf, "pmic ldo %d on", ldonum);
1122 run_command(buf, 0);
1123 writel(channel & 0xF, &adc->adcmux);
1124 writel((1 << 14) | (49 << 6), &adc->adccon);
1125 writel(1000 & 0xffff, &adc->adcdly);
1126 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1128 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1132 reg = readl(&adc->adccon);
1133 } while (!reg & (1 << 15) && loop++ < 1000);
1134 ret = readl(&adc->adcdat0) & 0xFFF;
1135 sprintf(buf, "pmic ldo %d off", ldonum);
1136 run_command(buf, 0);
1141 static int adc_get_average_ambient_temperature(void)
1143 if (machine_is_kessler()) {
1144 unsigned short min = USHRT_MAX;
1145 unsigned short max = 0;
1146 unsigned int sum = 0;
1147 unsigned int measured = 0;
1150 for (i = 0; i < 7; i++) {
1151 unsigned short measurement = get_adc_value(6);
1154 if (min > measurement)
1156 if (max < measurement)
1159 if (measured >= 3) {
1165 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1166 adc_to_temperature_centigrade(sum), sum);
1167 return adc_to_temperature_centigrade(sum);
1170 return 20; /* 20 Centigrade */
1173 enum temperature_level {
1181 static enum temperature_level temperature_check(void)
1183 int temp = adc_get_average_ambient_temperature();
1185 return _TEMP_TOO_LOW;
1187 return _TEMP_OK_LOW;
1189 return _TEMP_TOO_HIGH;
1191 return _TEMP_OK_HIGH;
1195 extern void lcd_display_clear(void);
1196 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1198 static void charger_en(int enable)
1204 unsigned char addr = 0xCC >> 1; /* max8998 */
1205 unsigned char val[2];
1207 i2c_set_bus_num(I2C_PMIC);
1208 if (i2c_probe(addr)) {
1209 printf("Can't found max8998 (%s:%d)\n", __func__, __LINE__);
1214 printf("Disable the charger.\n");
1215 i2c_read(addr, 0x0D, 1, val, 1);
1218 i2c_write(addr, 0x0D, 1, val, 1);
1220 i2c_read(addr, 0x0C, 1, val, 1);
1221 val[0] &= ~(0x7 << 0);
1222 val[0] &= ~(0x7 << 5);
1223 if (enable == 600) {
1224 val[0] |= 5; /* 600mA */
1225 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1226 } else { /* Assume 475 mA */
1228 val[0] |= 2; /* 475mA */
1229 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1231 i2c_write(addr, 0x0C, 1, val, 1);
1233 i2c_read(addr, 0x0D, 1, val, 1);
1235 i2c_write(addr, 0x0D, 1, val, 1);
1236 printf("Enable the charger @ %dmA\n", enable);
1240 void lcd_power_on(unsigned int onoff);
1242 static void into_charge_mode(void)
1248 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1249 unsigned int reg, wakeup_stat;
1250 int charger_speed = 600;
1252 max8998_clear_interrupt();
1254 printf("Charge Mode\n");
1255 charger_en(charger_speed);
1257 #ifdef CONFIG_S5PC1XXFB
1260 /* TODO: write the image-text for the charger */
1262 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1263 if (level >= CHARGER_ANIMATION_FRAME)
1264 level = CHARGER_ANIMATION_FRAME - 1;
1266 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1267 bmp_addr[i] = (ulong)battery_charging_animation[i];
1269 lcd_display_clear();
1270 for (i = 0; i < 3; i++) {
1271 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1274 bmp = gunzip_bmp(bmp_addr[j], &len);
1275 lcd_display_bitmap((ulong) bmp, 140, 202);
1278 for (k = 0; k < 10; k++)
1279 if (max8998_power_key()) {
1280 lcd_display_clear();
1281 goto restore_screen;
1282 } else if (!max8998_has_ext_power_source()) {
1283 lcd_display_clear();
1284 goto restore_screen;
1291 /* Disable the display to prevent flickering */
1292 /* TODO: how to reenable the display later? */
1296 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1297 unsigned int org, org_ip3, org_tcfg0;
1298 enum temperature_level previous_state = _TEMP_OK;
1300 empty_device_info_buffer();
1301 if (max8998_power_key())
1303 else if (!max8998_has_ext_power_source())
1306 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1307 org_ip3 = readl(0xE010046C);
1308 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1310 reg = org = readl(&rtc->rtccon);
1312 writel(reg, &rtc->rtccon);
1314 reg = readl(&rtc->rtccon);
1315 writel(reg | (1 << 3), &rtc->rtccon);
1317 writel(reg & ~(1 << 3), &rtc->rtccon);
1320 reg = readl(&rtc->rtccon);
1321 reg &= ~( (1 << 8) | (0xF << 4));
1322 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1323 writel(reg, &rtc->rtccon);
1325 reg = 15 * 4 - 1; /* 15 sec */
1326 writel(reg, &rtc->ticcnt);
1328 /* EVT0: sleep 1, EVT1: sleep */
1329 if (cpu_is_s5pc110()) {
1330 char *name = "dummy";
1331 char *usage = "N/A";
1338 if (s5pc1xx_get_cpu_rev() == 0) {
1339 char *argv[] = {"1", "1"};
1340 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1342 char *argv[] = {"0", "0"};
1343 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1346 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1350 /* Check TEMP HIGH/LOW */
1351 switch (temperature_check()) {
1353 charger_en(charger_speed);
1354 previous_state = _TEMP_OK;
1358 previous_state = _TEMP_TOO_LOW;
1360 case _TEMP_TOO_HIGH:
1362 previous_state = _TEMP_TOO_HIGH;
1365 if (previous_state == _TEMP_TOO_LOW)
1369 charger_en(charger_speed);
1370 previous_state = _TEMP_OK;
1374 if (previous_state == _TEMP_TOO_HIGH)
1378 charger_en(charger_speed);
1379 previous_state = _TEMP_OK;
1384 writel(org, &rtc->rtccon);
1385 writel(org_tcfg0, 0xE2600000);
1386 writel(org_ip3, 0xE010046C);
1388 } while (wakeup_stat == 0x04); /* RTC TICK */
1391 /* TODO: Reenable logo display (not working yet) */
1393 drv_lcd_init_resume();
1396 static int fsa9480_probe(void)
1398 unsigned char addr = 0x25;
1400 if (cpu_is_s5pc100())
1403 if (board_is_limo_real()) {
1404 if (hwrevision(0) || hwrevision(1))
1408 i2c_set_bus_num(I2C_PMIC);
1410 if (machine_is_kessler())
1411 i2c_set_bus_num(I2C_GPIO6);
1412 else if (machine_is_cypress()) {
1413 i2c_set_bus_num(I2C_GPIO6);
1414 } else if (machine_is_geminus()) {
1416 i2c_set_bus_num(I2C_GPIO6);
1417 } else if (machine_is_wmg160())
1418 i2c_set_bus_num(I2C_GPIO6);
1420 if (i2c_probe(addr)) {
1421 printf("Can't found fsa9480\n");
1428 static void check_micro_usb(int intr)
1431 unsigned char val[2];
1432 static int started_charging_once = 0;
1435 if (fsa9480_probe())
1438 addr = 0x25; /* fsa9480 */
1440 /* Clear Interrupt */
1442 i2c_read(addr, 0x03, 1, val, 2);
1446 /* Read Device Type 1 */
1447 i2c_read(addr, 0x0a, 1, val, 1);
1449 #define FSA_DEV1_CHARGER (1 << 6)
1450 #define FSA_DEV1_UART (1 << 3)
1451 #define FSA_DEV1_USB (1 << 2)
1452 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1453 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1456 * If USB, use default 475mA
1457 * If Charger, use 600mA and go to charge mode
1459 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1460 started_charging_once = 1;
1462 /* If it's full, do not charge. */
1463 if (battery_soc < 100)
1468 else if (val[0] & FSA_DEV1_USB) {
1469 if (battery_soc < 100)
1470 charger_en(475); /* enable charger and keep booting */
1475 /* If Factory Mode is Boot ON-USB, go to download mode */
1476 i2c_read(addr, 0x07, 1, val, 1);
1478 #define FSA_ADC_FAC_USB_OFF 0x18
1479 #define FSA_ADC_FAC_USB_ON 0x19
1480 #define FSA_ADC_FAC_UART 0x1d
1482 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1483 setenv("bootcmd", "usbdown");
1485 path = getenv("usb");
1487 if (!strncmp(path, "cp", 2))
1488 run_command("microusb cp", 0);
1491 static void micro_usb_switch(int path)
1494 unsigned char val[2];
1496 if (fsa9480_probe())
1499 addr = 0x25; /* fsa9480 */
1502 val[0] = 0x90; /* VAUDIO */
1504 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1506 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1508 i2c_read(addr, 0x2, 1, val, 1);
1509 val[0] &= ~(1 << 2); /* Manual switching */
1510 i2c_write(addr, 0x2, 1, val, 1);
1513 #define MAX8998_REG_ONOFF1 0x11
1514 #define MAX8998_REG_ONOFF2 0x12
1515 #define MAX8998_REG_ONOFF3 0x13
1516 #define MAX8998_REG_LDO7 0x21
1517 #define MAX8998_REG_LDO17 0x29
1519 #define MAX8998_LDO3 (1 << 2)
1521 #define MAX8998_LDO6 (1 << 7)
1522 #define MAX8998_LDO7 (1 << 6)
1523 #define MAX8998_LDO8 (1 << 5)
1524 #define MAX8998_LDO9 (1 << 4)
1525 #define MAX8998_LDO10 (1 << 3)
1526 #define MAX8998_LDO11 (1 << 2)
1527 #define MAX8998_LDO12 (1 << 1)
1528 #define MAX8998_LDO13 (1 << 0)
1530 #define MAX8998_LDO14 (1 << 7)
1531 #define MAX8998_LDO15 (1 << 6)
1532 #define MAX8998_LDO16 (1 << 5)
1533 #define MAX8998_LDO17 (1 << 4)
1536 static void init_pmic(void)
1539 unsigned char val[2];
1541 if (cpu_is_s5pc100())
1544 i2c_set_bus_num(I2C_PMIC);
1546 addr = 0xCC >> 1; /* max8998 */
1547 if (i2c_probe(addr)) {
1548 printf("Can't found max8998\n");
1553 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1554 val[0] &= ~MAX8998_LDO3;
1555 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1558 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1560 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1561 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1563 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1564 MAX8998_LDO12 | MAX8998_LDO13);
1566 if (machine_is_kessler())
1567 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1569 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1570 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1572 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1574 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1575 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1577 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1578 MAX8998_LDO16 | MAX8998_LDO17);
1580 if (machine_is_kessler())
1581 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1583 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1584 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1587 static void setup_power_down_mode_registers(void)
1589 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1590 struct s5pc1xx_gpio_bank *bank;
1591 struct gpio_powermode *p;
1593 struct gpio_external *ge;
1595 struct s5pc1xx_gpio_item *mr;
1599 if (cpu_is_s5pc100())
1602 /* Only Limo real and kessler supports worked for sleep currnet */
1603 if (machine_is_aquila()) {
1604 if (board_is_limo_real())
1608 } else if (machine_is_kessler()) {
1610 } else if (machine_is_geminus()) {
1615 if (machine_is_aquila()) {
1616 /* Aquila rev 0.8 or lower */
1617 p = aquila_powerdown_modes;
1618 ge = aquila_external_powerdown_modes;
1619 mr = aquila_mirror_powerdown_mode;
1620 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1621 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1622 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1623 } else if (machine_is_kessler()) {
1624 /* Aquila rev 0.9 */
1625 p = kessler_powerdown_modes;
1626 ge = kessler_external_powerdown_modes;
1627 mr = kessler_mirror_powerdown_mode;
1628 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1629 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1630 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1631 } else if (machine_is_geminus()) {
1632 if (hwrevision(1)) {
1633 /* Same as Aquila rev 0.9 */
1635 p = kessler_powerdown_modes;
1636 ge = kessler_external_powerdown_modes;
1637 mr = kessler_mirror_powerdown_mode;
1638 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1639 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1640 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1642 p = aquila_powerdown_modes;
1643 ge = aquila_external_powerdown_modes;
1644 mr = aquila_mirror_powerdown_mode;
1645 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1646 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1647 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1649 } else if (hwrevision(0)) {
1650 /* Same as Aquila rev 0.8 or lower */
1651 p = aquila_powerdown_modes;
1652 ge = aquila_external_powerdown_modes;
1653 mr = aquila_mirror_powerdown_mode;
1654 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1655 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1656 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1658 return; /* Not supported */
1662 bank = &gpio->gpio_a0;
1664 for (i = 0; i < n_p; i++, p++, bank++) {
1665 writel(p->conpdn, &bank->pdn_con);
1666 writel(p->pudpdn, &bank->pdn_pull);
1669 writel(0xff0022b0, (unsigned int *)0xF0000000);
1670 writel(0xff0022b0, (unsigned int *)0xF1400000);
1672 bank = &gpio->gpio_h0;
1674 for (i = 0; i < n_ge; i++) {
1675 writel(ge->con, &bank->con);
1676 writel(ge->dat, &bank->dat);
1677 writel(ge->pud, &bank->pull);
1683 for (i = 0; i < n_mr; i++) {
1684 unsigned int reg = readl(&mr->bank->pdn_con);
1685 reg &= ~(1 << mr->number);
1686 if (readl(&mr->bank->dat) & (1 << mr->number))
1687 reg |= 1 << mr->number;
1688 writel(reg, &mr->bank->pdn_con);
1694 #include "../../../drivers/video/s5p-spi.h"
1696 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1697 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1699 struct spi_platform_data spi_pd;
1701 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1703 void lcd_cfg_gpio(void)
1705 unsigned int i, f3_end = 4;
1707 for (i = 0; i < 8; i++) {
1708 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1709 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1710 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1711 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1712 /* pull-up/down disable */
1713 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1714 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1715 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1717 /* drive strength to max (24bit) */
1718 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1719 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1720 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1721 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1722 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1723 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1726 /* set DISPLAY_DE_B pin for dual rgb mode. */
1727 if (board_is_media())
1730 for (i = 0; i < f3_end; i++) {
1731 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1732 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1733 /* pull-up/down disable */
1734 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1735 /* drive strength to max (24bit) */
1736 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1737 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1739 /* display output path selection (only [1:0] valid) */
1740 writel(0x2, 0xE0107008);
1742 /* gpio pad configuration for LCD reset. */
1743 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1745 /* gpio pad configuration for LCD ON. */
1746 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1748 /* LCD_BACKLIGHT_EN */
1749 if (machine_is_geminus())
1750 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1751 if (board_is_neptune()) {
1752 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1753 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1757 * gpio pad configuration for
1758 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1760 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1761 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1762 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1763 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1765 if (machine_is_aquila() || machine_is_kessler()) {
1766 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1768 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1770 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1772 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1775 if (board_is_neptune())
1776 s6d16a0x_set_platform_data(&spi_pd);
1778 s6e63m0_set_platform_data(&spi_pd);
1779 if (board_is_media())
1784 if (machine_is_cypress()) {
1785 #if 0 /* universal cypress */
1787 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1790 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1792 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1794 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1796 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1798 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1799 #if 0 /* universal cypress */
1800 pd_cs.bank = &gpio_base->gpio_mp0_1;
1803 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1805 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1807 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1812 /* these data would be sent to s6e63m0 lcd panel driver. */
1813 s6e63m0_set_platform_data(&spi_pd);
1819 #define SWRST_REG 0x00
1820 #define LEDCON_REG 0x01
1821 #define LED_CUR_SET_REG 0x03
1822 #define LED_CUR_TR_REG 0x08
1825 #define NORMAL_MODE 0x01
1826 #define CUR_SET 0x63
1829 void backlight_on(unsigned int onoff)
1833 unsigned char val[2];
1834 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1837 if (machine_is_geminus())
1838 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1840 if (machine_is_geminus())
1841 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1844 if (machine_is_kessler() && board_is_neptune()) {
1845 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1848 i2c_set_bus_num(I2C_GPIO5);
1851 if (i2c_probe(addr)) {
1852 if (i2c_probe(addr)) {
1853 printf("Can't found s6d16a0x backlight i2c\n");
1858 i2c_write(addr, SWRST_REG, 1, val, 1);
1861 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1863 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1864 val[0] = NORMAL_MODE;
1865 i2c_write(addr, LEDCON_REG, 1, val, 1);
1870 void reset_lcd(void)
1872 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1874 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1875 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1876 if (machine_is_cypress())
1877 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1880 void lcd_power_on(unsigned int onoff)
1882 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1885 if (machine_is_aquila() || machine_is_geminus())
1886 gpio_set_value(&gpio->gpio_j1, 3, 1);
1888 if (machine_is_cypress())
1889 gpio_set_value(&gpio->gpio_g2, 2, 1);
1891 if (machine_is_kessler()) {
1893 unsigned char val[2];
1894 unsigned char val2[2];
1896 gpio_set_value(&gpio->gpio_j1, 3, 1);
1898 i2c_set_bus_num(I2C_PMIC);
1899 addr = 0xCC >> 1; /* max8998 */
1900 if (i2c_probe(addr)) {
1901 printf("Can't found max8998\n");
1904 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1905 val[0] &= ~(MAX8998_LDO17);
1906 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1907 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1909 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1910 val[0] |= MAX8998_LDO17;
1912 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1913 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1915 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1916 val[0] |= MAX8998_LDO7;
1918 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1919 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1922 if (machine_is_aquila() || machine_is_geminus())
1923 gpio_set_value(&gpio->gpio_j1, 3, 0);
1925 if (machine_is_cypress())
1926 gpio_set_value(&gpio->gpio_g2, 2, 0);
1928 if (machine_is_kessler()) {
1930 unsigned char val[2];
1932 gpio_set_value(&gpio->gpio_j1, 3, 0);
1934 i2c_set_bus_num(I2C_PMIC);
1935 addr = 0xCC >> 1; /* max8998 */
1936 if (i2c_probe(addr)) {
1937 printf("Can't found max8998\n");
1941 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1942 val[0] &= ~(MAX8998_LDO7);
1943 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1944 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1946 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1947 val[0] &= ~(MAX8998_LDO17);
1948 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1949 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1954 extern void s6e63m0_cfg_ldo(void);
1955 extern void s6e63m0_enable_ldo(unsigned int onoff);
1956 extern void s6d16a0x_cfg_ldo(void);
1957 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1959 int s5p_no_lcd_support(void)
1961 if (machine_is_wmg160())
1966 void init_panel_info(vidinfo_t *vid)
1968 vid->cfg_gpio = NULL;
1969 vid->reset_lcd = NULL;
1970 vid->backlight_on = NULL;
1971 vid->lcd_power_on = NULL;
1973 vid->cfg_ldo = NULL;
1974 vid->enable_ldo = NULL;
1976 vid->init_delay = 0;
1977 vid->reset_delay = 0;
1978 vid->power_on_delay = 0;
1983 vid->vl_width = 480;
1984 vid->vl_height = 800;
1986 vid->dual_lcd_enabled = 0;
1988 if (board_is_media()) {
1991 vid->vl_width = 960;
1992 vid->vl_height = 800;
1994 /* enable dual lcd mode. */
1995 vid->dual_lcd_enabled = 1;
1998 vid->vl_clkp = CONFIG_SYS_HIGH;
1999 vid->vl_hsp = CONFIG_SYS_LOW;
2000 vid->vl_vsp = CONFIG_SYS_LOW;
2001 vid->vl_dp = CONFIG_SYS_HIGH;
2004 /* S6E63M0 LCD Panel */
2013 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
2014 vid->cfg_gpio = lcd_cfg_gpio;
2015 vid->reset_lcd = reset_lcd;
2016 vid->backlight_on = backlight_on;
2017 vid->lcd_power_on = lcd_power_on;
2018 vid->cfg_ldo = s6e63m0_cfg_ldo;
2019 vid->enable_ldo = s6e63m0_enable_ldo;
2021 vid->init_delay = 25000;
2022 vid->reset_delay = 120000;
2025 if (board_is_neptune()) {
2029 vid->vl_width = 320;
2030 vid->vl_height = 480;
2032 vid->vl_clkp = CONFIG_SYS_HIGH;
2033 vid->vl_hsp = CONFIG_SYS_HIGH;
2034 vid->vl_vsp = CONFIG_SYS_HIGH;
2035 vid->vl_dp = CONFIG_SYS_LOW;
2038 /* disable dual lcd mode. */
2039 vid->dual_lcd_enabled = 0;
2041 /* S6D16A0X LCD Panel */
2050 vid->cfg_gpio = lcd_cfg_gpio;
2051 vid->backlight_on = backlight_on;
2052 vid->lcd_power_on = lcd_power_on;
2053 vid->reset_lcd = reset_lcd;
2054 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2055 vid->enable_ldo = s6d16a0x_enable_ldo;
2057 vid->init_delay = 10000;
2058 vid->power_on_delay = 10000;
2059 vid->reset_delay = 1000;
2063 if (machine_is_geminus()) {
2067 vid->vl_width = 1024,
2068 vid->vl_height = 600,
2069 vid->vl_clkp = CONFIG_SYS_LOW,
2070 vid->vl_hsp = CONFIG_SYS_HIGH,
2071 vid->vl_vsp = CONFIG_SYS_HIGH,
2072 vid->vl_dp = CONFIG_SYS_LOW,
2083 vid->cfg_gpio = lcd_cfg_gpio;
2084 vid->reset_lcd = reset_lcd;
2085 vid->backlight_on = backlight_on;
2086 vid->lcd_power_on = lcd_power_on;
2092 vid->vl_width = 480,
2093 vid->vl_height = 800,
2094 vid->vl_clkp = CONFIG_SYS_HIGH,
2095 vid->vl_hsp = CONFIG_SYS_LOW,
2096 vid->vl_vsp = CONFIG_SYS_LOW,
2097 vid->vl_dp = CONFIG_SYS_HIGH,
2113 vid->vl_width = 1024,
2114 vid->vl_height = 600,
2115 vid->vl_clkp = CONFIG_SYS_HIGH,
2116 vid->vl_hsp = CONFIG_SYS_HIGH,
2117 vid->vl_vsp = CONFIG_SYS_HIGH,
2118 vid->vl_dp = CONFIG_SYS_LOW,
2121 /* AMS701KA AMOLED Panel. */
2133 static void setup_meminfo(void)
2135 char meminfo[64] = {0, };
2136 int count = 0, size, real;
2138 size = gd->bd->bi_dram[0].size >> 20;
2139 count += sprintf(meminfo + count, "mem=%dM", size);
2141 /* Each Chip Select can't exceed the 256MiB */
2142 size = gd->bd->bi_dram[1].size >> 20;
2143 real = min(size, 256);
2144 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2145 real, (unsigned int)gd->bd->bi_dram[1].start);
2149 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2150 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2153 setenv("meminfo", meminfo);
2156 int misc_init_r(void)
2159 /* It should be located at first */
2162 if (machine_is_aquila() || machine_is_kessler()) {
2163 if (board_is_neptune())
2164 setenv("lcdinfo", "lcd=s6d16a0x");
2165 else if (board_is_media())
2166 setenv("lcdinfo", "lcd=s6e63m0");
2168 setenv("lcdinfo", "lcd=s6e63m0");
2170 if (machine_is_geminus())
2171 setenv("lcdinfo", "lcd=lms480jc01");
2172 if (machine_is_cypress())
2173 setenv("lcdinfo", "lcd=s6e63m0");
2179 /* Set proper PMIC pins */
2182 /* Check auto burning */
2185 /* To power up I2C2 */
2188 /* Enable T-Flash at Limo Real or Limo Universal */
2191 /* Setup Limo Real board GPIOs */
2192 setup_limo_real_gpios();
2194 /* Setup Media board GPIOs */
2195 setup_media_gpios();
2197 /* To usbdown automatically */
2203 #ifdef CONFIG_S5PC1XXFB
2204 display_device_info();
2207 setup_power_down_mode_registers();
2209 /* check max17040 */
2219 int board_init(void)
2221 /* Set Initial global variables */
2222 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2224 gd->bd->bi_arch_number = MACH_AQUILA;
2225 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2227 /* Check H/W Revision */
2228 check_hw_revision();
2235 unsigned int base, memconfig0, size;
2236 unsigned int memconfig1, sz = 0;
2238 if (cpu_is_s5pc100()) {
2239 /* In mem setup, we swap the bank. So below size is correct */
2240 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2241 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2242 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2245 /* In S5PC110, we can't swap the DMC0/1 */
2246 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2247 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2249 base = S5PC110_DMC1_BASE;
2250 /* DMC configuration */
2251 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2252 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2254 size = (memconfig0 >> 16) & 0xFF;
2255 size = ((unsigned char) ~size) + 1;
2258 * (0x07 + 1) * 16 = 128 MiB
2259 * (0x0f + 1) * 16 = 256 MiB
2264 * Aquila Rev0.5 4G3G1G
2265 * Aquila Rev0.8 4G3G1G
2266 * Aquila Rev0.9 4G3G1G
2268 if (machine_is_aquila() || machine_is_kessler())
2269 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2270 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2272 sz = (memconfig1 >> 16) & 0xFF;
2273 sz = ((unsigned char) ~sz) + 1;
2279 * bi_dram[1].size contains all DMC1 memory size
2281 gd->bd->bi_dram[1].size = (size + sz) << 20;
2286 /* Used for sleep test */
2287 static unsigned char saved_val[4][2];
2288 void board_sleep_init_late(void)
2290 /* CODEC_LDO_EN: GPF3[4] */
2291 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2292 /* CODEC_XTAL_EN: GPH3[2] */
2293 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2295 /* MMC T_FLASH off */
2296 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2298 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2299 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2300 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2304 void board_sleep_init(void)
2307 unsigned char val[2];
2309 i2c_set_bus_num(I2C_PMIC);
2311 if (i2c_probe(addr)) {
2312 printf("Can't find max8998\n");
2316 if (machine_is_kessler()) {
2319 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2320 saved_val[0][0] = val[0];
2321 saved_val[0][1] = val[1];
2322 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2323 (1 << 1) | (1 << 0));
2324 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2325 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2327 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2328 saved_val[1][0] = val[0];
2329 saved_val[1][1] = val[1];
2330 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2331 (1 << 2) | (1 << 1) | (1 << 0));
2333 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2334 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2336 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2337 saved_val[2][0] = val[0];
2338 saved_val[2][1] = val[1];
2339 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2340 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2341 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2343 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2344 saved_val[3][0] = val[0];
2345 saved_val[3][1] = val[1];
2346 val[0] &= ~((1 << 6) | (1 << 4));
2347 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2348 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2349 printf("Turned off regulators with Kessler setting."
2350 " Preparing to sleep. [%s:%d]\n",
2351 __FILE__, __LINE__);
2352 } else { /* Default */
2355 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2356 saved_val[0][0] = val[0];
2357 saved_val[0][1] = val[1];
2358 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2359 (1 << 1) | (1 << 0));
2360 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2361 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2363 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2364 saved_val[1][0] = val[0];
2365 saved_val[1][1] = val[1];
2366 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2367 (1 << 2) | (1 << 1) | (1 << 0));
2369 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2370 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2372 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2373 saved_val[2][0] = val[0];
2374 saved_val[2][1] = val[1];
2375 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2376 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2377 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2379 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2380 saved_val[3][0] = val[0];
2381 saved_val[3][1] = val[1];
2382 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2383 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2384 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2385 printf("Turned off regulators with default(Aquila) setting."
2386 " Preparing to sleep. [%s:%d]\n",
2387 __FILE__, __LINE__);
2391 void board_sleep_resume(void)
2394 unsigned char val[2];
2398 i2c_set_bus_num(I2C_PMIC);
2400 if (i2c_probe(addr)) {
2401 printf("Can't find max8998\n");
2406 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2407 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2409 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2410 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2412 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2413 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2415 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2416 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2417 printf("Waked up.\n");
2419 /* check max17040 */
2426 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2428 static int s5pc1xx_phy_control(int on)
2432 if (on && !status) {
2433 // printf("turning USB power on\n");
2434 #ifdef CONFIG_CMD_PMIC
2435 run_command("pmic ldo 3 on", 0);
2438 if (board_is_limo_universal() ||
2439 board_is_limo_real() ||
2441 /* check usb path */
2442 if (board_is_limo_real() && !hwrevision(6))
2446 if (machine_is_tickertape())
2447 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2448 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2450 /* USB Path to AP */
2451 micro_usb_switch(0);
2453 } else if (!on && status) {
2454 // printf("turning USB power off\n");
2455 #ifdef CONFIG_CMD_PMIC
2456 run_command("pmic ldo 3 off", 0);
2465 struct s3c_plat_otg_data s5pc110_otg_data = {
2466 .phy_control = s5pc1xx_phy_control,
2467 .regs_phy = S5PC110_PHY_BASE,
2468 .regs_otg = S5PC110_OTG_BASE,
2471 int board_eth_init(bd_t *bis)
2475 if (cpu_is_s5pc100())
2478 s3c_udc_probe(&s5pc110_otg_data);
2479 if (usb_eth_initialize(bis) >= 0)
2485 #ifdef CONFIG_CMD_USBDOWN
2486 int usb_board_init(void)
2488 #ifdef CONFIG_CMD_PMIC
2489 run_command("pmic ldo 3 on", 0);
2492 if (cpu_is_s5pc100()) {
2493 #ifdef CONFIG_HARD_I2C
2494 uchar val[2] = {0,};
2497 if (i2c_read(0x66, 0, 1, val, 2)) {
2498 printf("i2c_read error\n");
2505 if (i2c_write(0x66, 0, 1, val, 2)) {
2506 printf("i2c_write error\n");
2509 i2c_read(0x66, 0, 1, val, 2);
2515 if (board_is_limo_universal() ||
2516 board_is_limo_real() ||
2518 /* check usb path */
2519 if (board_is_limo_real() && !hwrevision(6))
2523 if (machine_is_tickertape())
2524 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2525 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2527 /* USB Path to AP */
2528 micro_usb_switch(0);
2534 #ifdef CONFIG_GENERIC_MMC
2535 int s5p_no_mmc_support(void)
2537 if (machine_is_wmg160())
2542 int board_mmc_init(bd_t *bis)
2546 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2549 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2550 if (machine_is_kessler())
2551 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2553 if (machine_is_wmg160())
2556 /* MMC0 Clock source = SCLKMPLL */
2557 reg = readl(&clk->src4);
2560 writel(reg, &clk->src4);
2562 reg = readl(&clk->div4);
2565 /* set div value near 50MHz */
2566 clock = get_pll_clk(MPLL) / 1000000;
2567 for (i = 0; i < 0xf; i++) {
2568 if ((clock / (i + 1)) <= 50) {
2574 writel(reg, &clk->div4);
2580 * GPG0[2] SD_0_CDn -> Not used
2581 * GPG0[3:6] SD_0_DATA[0:3]
2583 for (i = 0; i < 7; i++) {
2586 /* GPG0[0:6] special function 2 */
2587 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2588 /* GPG0[0:6] pull disable */
2589 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2590 /* GPG0[0:6] drv 4x */
2591 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2594 return s5pc1xx_mmc_init(0);
2598 #ifdef CONFIG_CMD_PMIC
2599 static int pmic_status(void)
2601 unsigned char addr, val[2];
2604 i2c_set_bus_num(I2C_PMIC);
2606 if (i2c_probe(addr)) {
2607 printf("Can't found max8998\n");
2612 i2c_read(addr, reg, 1, val, 1);
2613 for (i = 7; i >= 4; i--)
2614 printf("BUCK%d %s\n", 7 - i + 1,
2615 val[0] & (1 << i) ? "on" : "off");
2617 printf("LDO%d %s\n", 5 - i,
2618 val[0] & (1 << i) ? "on" : "off");
2620 i2c_read(addr, reg, 1, val, 1);
2621 for (i = 7; i >= 0; i--)
2622 printf("LDO%d %s\n", 7 - i + 6,
2623 val[0] & (1 << i) ? "on" : "off");
2625 i2c_read(addr, reg, 1, val, 1);
2626 for (i = 7; i >= 4; i--)
2627 printf("LDO%d %s\n", 7 - i + 14,
2628 val[0] & (1 << i) ? "on" : "off");
2631 i2c_read(addr, reg, 1, val, 1);
2632 for (i = 7; i >= 6; i--)
2633 printf("SAFEOUT%d %s\n", 7 - i + 1,
2634 val[0] & (1 << i) ? "on" : "off");
2638 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2640 unsigned char addr, val[2];
2641 unsigned int reg, shift;
2649 } else if (ldo <= 13) {
2652 } else if (ldo <= 17) {
2654 shift = 17 - ldo + 4;
2661 shift = 4 - buck + 4;
2662 } else if (safeout) {
2666 shift = 8 - safeout;
2670 i2c_set_bus_num(I2C_PMIC);
2672 if (i2c_probe(addr)) {
2673 printf("Can't found max8998\n");
2677 i2c_read(addr, reg, 1, val, 1);
2679 val[0] |= (1 << shift);
2681 val[0] &= ~(1 << shift);
2682 i2c_write(addr, reg, 1, val, 1);
2683 i2c_read(addr, reg, 1, val, 1);
2686 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2687 val[0] & (1 << shift) ? "on" : "off");
2689 printf("buck %d value 0x%x, %s\n", buck, val[0],
2690 val[0] & (1 << shift) ? "on" : "off");
2692 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2693 val[0] & (1 << shift) ? "on" : "off");
2698 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2700 int buck = 0, ldo = 0, safeout = 0, on = -1;
2704 if (strncmp(argv[1], "status", 6) == 0)
2705 return pmic_status();
2708 if (strncmp(argv[1], "ldo", 3) == 0)
2709 ldo = simple_strtoul(argv[2], NULL, 10);
2710 else if (strncmp(argv[1], "buck", 4) == 0)
2711 buck = simple_strtoul(argv[2], NULL, 10);
2712 else if (strncmp(argv[1], "safeout", 7) == 0)
2713 safeout = simple_strtoul(argv[2], NULL, 10);
2717 if (strncmp(argv[3], "on", 2) == 0)
2719 else if (strncmp(argv[3], "off", 3) == 0)
2724 return pmic_ldo_control(buck, ldo, safeout, on);
2735 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2736 "PMIC LDO & BUCK control",
2737 "status - Display PMIC LDO & BUCK status\n"
2738 "pmic ldo num on/off - Turn on/off the LDO\n"
2739 "pmic buck num on/off - Turn on/off the BUCK\n"
2740 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2744 #ifdef CONFIG_CMD_DEVICE_POWER
2758 static void power_display_devices(void)
2760 printf("devices:\n");
2761 printf("\t%d - touch\n", POWER_TOUCH);
2762 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2763 printf("\t%d - LCD\n", POWER_LCD);
2764 printf("\t%d - Haptic\n", POWER_HAPTIC);
2765 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2766 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2767 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2768 printf("\t%d - HDMI\n", POWER_HDMI);
2771 static int power_hdmi(int on)
2773 /* HDMI_EN1: GPJ2[2] */
2774 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2775 /* MHL_ON: GPJ2[3] */
2776 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2780 static int power_bt_wifi(int on)
2782 /* WLAN_BT_EN: GPB[5] */
2783 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2787 static int power_fm_radio(int on)
2789 /* FM_BUS_nRST: GPJ2[5] */
2790 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2794 static int power_audio_codec(int on)
2796 /* CODEC_LDO_EN: GPF3[4] */
2797 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2798 /* CODEC_XTAL_EN: GPH3[2] */
2799 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2803 static int power_haptic(int on)
2805 /* HAPTIC_ON: GPJ1[1] */
2806 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2810 static int power_lcd(int on)
2812 /* MLCD_ON: GPJ1[3] */
2813 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2817 static int power_touch(int on)
2819 /* TOUCH_EN: GPG3[6] */
2820 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2824 static int power_3_touchkey(int on)
2827 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2828 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2829 if (board_rev & J1_B2_BOARD)
2830 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2832 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2834 /* 3_TOUCH_CE - GPJ2[6] */
2835 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2837 /* 3_TOUCH_CE - GPJ2[6] */
2838 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2843 unsigned char val[2];
2844 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2850 i2c_set_bus_num(I2C_GPIO10);
2852 /* Workaround to probe */
2853 if (i2c_probe(addr)) {
2854 if (i2c_probe(addr)) {
2855 printf("Can't found 3 touchkey\n");
2860 #define MCS5000_TK_HW_VERSION 0x06
2861 #define MCS5000_TK_FW_VERSION 0x0A
2862 #define MCS5000_TK_MI_VERSION 0x0B
2864 reg = MCS5000_TK_MI_VERSION;
2865 i2c_read(addr, reg, 1, val, 1);
2866 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2867 reg = MCS5000_TK_HW_VERSION;
2868 i2c_read(addr, reg, 1, val, 1);
2869 printf("H/W 0x%x, ", val[0]);
2870 reg = MCS5000_TK_FW_VERSION;
2871 i2c_read(addr, reg, 1, val, 1);
2872 printf("F/W 0x%x\n", val[0]);
2877 static int power_control(int device, int on)
2881 return power_touch(on);
2882 case POWER_3_TOUCHKEY:
2883 return power_3_touchkey(on);
2885 return power_lcd(on);
2887 return power_haptic(on);
2888 case POWER_AUDIO_CODEC:
2889 return power_audio_codec(on);
2890 case POWER_FM_RADIO:
2891 return power_fm_radio(on);
2893 return power_bt_wifi(on);
2895 return power_hdmi(on);
2897 printf("I don't know device %d\n", device);
2903 static int power_on(int on)
2906 power_3_touchkey(on);
2909 power_audio_codec(on);
2917 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2921 if (!machine_is_aquila() && !machine_is_kessler())
2926 if (strncmp(argv[1], "on", 2) == 0)
2928 if (strncmp(argv[1], "off", 3) == 0)
2932 device = simple_strtoul(argv[1], NULL, 10);
2936 if (strncmp(argv[2], "on", 2) == 0)
2938 else if (strncmp(argv[2], "off", 3) == 0)
2942 return power_control(device, on);
2948 power_display_devices();
2953 power, CONFIG_SYS_MAXARGS, 1, do_power,
2954 "Device Power Management control",
2955 "device on/off - Turn on/off the device\n"
2958 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2962 if (strncmp(argv[1], "cp", 2) == 0) {
2963 micro_usb_switch(1);
2964 pmic_ldo_control(0, 0, 2, 1);
2965 setenv("usb", "cp");
2966 } else if (strncmp(argv[1], "ap", 2) == 0) {
2967 micro_usb_switch(0);
2968 pmic_ldo_control(0, 0, 2, 0);
2969 setenv("usb", "ap");
2979 printf("USB Path is set to %s\n", getenv("usb"));
2985 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2987 "cp - switch to CP\n"
2988 "microusb ap - switch to AP\n"