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 void check_micro_usb(int intr)
1399 unsigned char val[2];
1400 static int started_charging_once = 0;
1403 if (cpu_is_s5pc100())
1406 if (board_is_limo_real()) {
1407 if (hwrevision(0) || hwrevision(1))
1411 i2c_set_bus_num(I2C_PMIC);
1413 if (machine_is_kessler())
1414 i2c_set_bus_num(I2C_GPIO6);
1415 else if (machine_is_cypress()) {
1416 i2c_set_bus_num(I2C_GPIO6);
1417 } else if (machine_is_geminus()) {
1419 i2c_set_bus_num(I2C_GPIO6);
1420 } else if (machine_is_wmg160())
1421 i2c_set_bus_num(I2C_GPIO6);
1423 addr = 0x25; /* fsa9480 */
1424 if (i2c_probe(addr)) {
1425 printf("Can't found fsa9480\n");
1429 /* Clear Interrupt */
1431 i2c_read(addr, 0x03, 1, val, 2);
1435 /* Read Device Type 1 */
1436 i2c_read(addr, 0x0a, 1, val, 1);
1438 #define FSA_DEV1_CHARGER (1 << 6)
1439 #define FSA_DEV1_UART (1 << 3)
1440 #define FSA_DEV1_USB (1 << 2)
1441 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1442 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1445 * If USB, use default 475mA
1446 * If Charger, use 600mA and go to charge mode
1448 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1449 started_charging_once = 1;
1451 /* If it's full, do not charge. */
1452 if (battery_soc < 100)
1457 else if (val[0] & FSA_DEV1_USB) {
1458 if (battery_soc < 100)
1459 charger_en(475); /* enable charger and keep booting */
1464 /* If Factory Mode is Boot ON-USB, go to download mode */
1465 i2c_read(addr, 0x07, 1, val, 1);
1467 #define FSA_ADC_FAC_USB_OFF 0x18
1468 #define FSA_ADC_FAC_USB_ON 0x19
1469 #define FSA_ADC_FAC_UART 0x1d
1471 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1472 setenv("bootcmd", "usbdown");
1474 path = getenv("usb");
1476 if (!strncmp(path, "cp", 2))
1477 run_command("microusb cp", 0);
1480 static void micro_usb_switch(int path)
1483 unsigned char val[2];
1485 i2c_set_bus_num(I2C_PMIC);
1487 if (machine_is_kessler())
1488 i2c_set_bus_num(I2C_GPIO6);
1489 else if (machine_is_cypress()) {
1490 i2c_set_bus_num(I2C_GPIO6);
1491 } else if (machine_is_geminus()) {
1493 i2c_set_bus_num(I2C_GPIO6);
1494 } else if (machine_is_wmg160()) {
1495 i2c_set_bus_num(I2C_GPIO6);
1499 addr = 0x25; /* fsa9480 */
1500 if (i2c_probe(addr)) {
1501 printf("Can't found fsa9480\n");
1506 val[0] = 0x90; /* VAUDIO */
1508 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1510 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1512 i2c_read(addr, 0x2, 1, val, 1);
1513 val[0] &= ~(1 << 2); /* Manual switching */
1514 i2c_write(addr, 0x2, 1, val, 1);
1517 #define MAX8998_REG_ONOFF1 0x11
1518 #define MAX8998_REG_ONOFF2 0x12
1519 #define MAX8998_REG_ONOFF3 0x13
1520 #define MAX8998_REG_LDO7 0x21
1521 #define MAX8998_REG_LDO17 0x29
1523 #define MAX8998_LDO3 (1 << 2)
1525 #define MAX8998_LDO6 (1 << 7)
1526 #define MAX8998_LDO7 (1 << 6)
1527 #define MAX8998_LDO8 (1 << 5)
1528 #define MAX8998_LDO9 (1 << 4)
1529 #define MAX8998_LDO10 (1 << 3)
1530 #define MAX8998_LDO11 (1 << 2)
1531 #define MAX8998_LDO12 (1 << 1)
1532 #define MAX8998_LDO13 (1 << 0)
1534 #define MAX8998_LDO14 (1 << 7)
1535 #define MAX8998_LDO15 (1 << 6)
1536 #define MAX8998_LDO16 (1 << 5)
1537 #define MAX8998_LDO17 (1 << 4)
1540 static void init_pmic(void)
1543 unsigned char val[2];
1545 if (cpu_is_s5pc100())
1548 i2c_set_bus_num(I2C_PMIC);
1550 addr = 0xCC >> 1; /* max8998 */
1551 if (i2c_probe(addr)) {
1552 printf("Can't found max8998\n");
1557 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1558 val[0] &= ~MAX8998_LDO3;
1559 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1562 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1564 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1565 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1567 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1568 MAX8998_LDO12 | MAX8998_LDO13);
1570 if (machine_is_kessler())
1571 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1573 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1574 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1576 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1578 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1579 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1581 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1582 MAX8998_LDO16 | MAX8998_LDO17);
1584 if (machine_is_kessler())
1585 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1587 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1588 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1591 static void setup_power_down_mode_registers(void)
1593 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1594 struct s5pc1xx_gpio_bank *bank;
1595 struct gpio_powermode *p;
1597 struct gpio_external *ge;
1599 struct s5pc1xx_gpio_item *mr;
1603 if (cpu_is_s5pc100())
1606 /* Only Limo real and kessler supports worked for sleep currnet */
1607 if (machine_is_aquila()) {
1608 if (board_is_limo_real())
1612 } else if (machine_is_kessler()) {
1614 } else if (machine_is_geminus()) {
1619 if (machine_is_aquila()) {
1620 /* Aquila rev 0.8 or lower */
1621 p = aquila_powerdown_modes;
1622 ge = aquila_external_powerdown_modes;
1623 mr = aquila_mirror_powerdown_mode;
1624 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1625 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1626 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1627 } else if (machine_is_kessler()) {
1628 /* Aquila rev 0.9 */
1629 p = kessler_powerdown_modes;
1630 ge = kessler_external_powerdown_modes;
1631 mr = kessler_mirror_powerdown_mode;
1632 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1633 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1634 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1635 } else if (machine_is_geminus()) {
1636 if (hwrevision(1)) {
1637 /* Same as Aquila rev 0.9 */
1639 p = kessler_powerdown_modes;
1640 ge = kessler_external_powerdown_modes;
1641 mr = kessler_mirror_powerdown_mode;
1642 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1643 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1644 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1646 p = aquila_powerdown_modes;
1647 ge = aquila_external_powerdown_modes;
1648 mr = aquila_mirror_powerdown_mode;
1649 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1650 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1651 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1653 } else if (hwrevision(0)) {
1654 /* Same as Aquila rev 0.8 or lower */
1655 p = aquila_powerdown_modes;
1656 ge = aquila_external_powerdown_modes;
1657 mr = aquila_mirror_powerdown_mode;
1658 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1659 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1660 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1662 return; /* Not supported */
1666 bank = &gpio->gpio_a0;
1668 for (i = 0; i < n_p; i++, p++, bank++) {
1669 writel(p->conpdn, &bank->pdn_con);
1670 writel(p->pudpdn, &bank->pdn_pull);
1673 writel(0xff0022b0, (unsigned int *)0xF0000000);
1674 writel(0xff0022b0, (unsigned int *)0xF1400000);
1676 bank = &gpio->gpio_h0;
1678 for (i = 0; i < n_ge; i++) {
1679 writel(ge->con, &bank->con);
1680 writel(ge->dat, &bank->dat);
1681 writel(ge->pud, &bank->pull);
1687 for (i = 0; i < n_mr; i++) {
1688 unsigned int reg = readl(&mr->bank->pdn_con);
1689 reg &= ~(1 << mr->number);
1690 if (readl(&mr->bank->dat) & (1 << mr->number))
1691 reg |= 1 << mr->number;
1692 writel(reg, &mr->bank->pdn_con);
1698 #include "../../../drivers/video/s5p-spi.h"
1700 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1701 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1703 struct spi_platform_data spi_pd;
1705 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1707 void lcd_cfg_gpio(void)
1709 unsigned int i, f3_end = 4;
1711 for (i = 0; i < 8; i++) {
1712 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1713 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1714 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1715 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1716 /* pull-up/down disable */
1717 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1718 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1719 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1721 /* drive strength to max (24bit) */
1722 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1723 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1724 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1725 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1726 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1727 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1730 /* set DISPLAY_DE_B pin for dual rgb mode. */
1731 if (board_is_media())
1734 for (i = 0; i < f3_end; i++) {
1735 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1736 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1737 /* pull-up/down disable */
1738 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1739 /* drive strength to max (24bit) */
1740 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1741 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1743 /* display output path selection (only [1:0] valid) */
1744 writel(0x2, 0xE0107008);
1746 /* gpio pad configuration for LCD reset. */
1747 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1749 /* gpio pad configuration for LCD ON. */
1750 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1752 /* LCD_BACKLIGHT_EN */
1753 if (machine_is_geminus())
1754 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1755 if (board_is_neptune()) {
1756 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1757 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1761 * gpio pad configuration for
1762 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1764 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1765 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1766 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1767 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1769 if (machine_is_aquila() || machine_is_kessler()) {
1770 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1772 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1774 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1776 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1779 if (board_is_neptune())
1780 s6d16a0x_set_platform_data(&spi_pd);
1782 s6e63m0_set_platform_data(&spi_pd);
1783 if (board_is_media())
1788 if (machine_is_cypress()) {
1789 #if 0 /* universal cypress */
1791 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1794 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1796 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1798 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1800 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1802 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1803 #if 0 /* universal cypress */
1804 pd_cs.bank = &gpio_base->gpio_mp0_1;
1807 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1809 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1811 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1816 /* these data would be sent to s6e63m0 lcd panel driver. */
1817 s6e63m0_set_platform_data(&spi_pd);
1823 #define SWRST_REG 0x00
1824 #define LEDCON_REG 0x01
1825 #define LED_CUR_SET_REG 0x03
1826 #define LED_CUR_TR_REG 0x08
1829 #define NORMAL_MODE 0x01
1830 #define CUR_SET 0x63
1833 void backlight_on(unsigned int onoff)
1837 unsigned char val[2];
1838 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1841 if (machine_is_geminus())
1842 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1844 if (machine_is_geminus())
1845 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1848 if (machine_is_kessler() && board_is_neptune()) {
1849 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1852 i2c_set_bus_num(I2C_GPIO5);
1855 if (i2c_probe(addr)) {
1856 if (i2c_probe(addr)) {
1857 printf("Can't found s6d16a0x backlight i2c\n");
1862 i2c_write(addr, SWRST_REG, 1, val, 1);
1865 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1867 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1868 val[0] = NORMAL_MODE;
1869 i2c_write(addr, LEDCON_REG, 1, val, 1);
1874 void reset_lcd(void)
1876 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1878 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1879 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1880 if (machine_is_cypress())
1881 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1884 void lcd_power_on(unsigned int onoff)
1886 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1889 if (machine_is_aquila() || machine_is_geminus())
1890 gpio_set_value(&gpio->gpio_j1, 3, 1);
1892 if (machine_is_cypress())
1893 gpio_set_value(&gpio->gpio_g2, 2, 1);
1895 if (machine_is_kessler()) {
1897 unsigned char val[2];
1898 unsigned char val2[2];
1900 gpio_set_value(&gpio->gpio_j1, 3, 1);
1902 i2c_set_bus_num(I2C_PMIC);
1903 addr = 0xCC >> 1; /* max8998 */
1904 if (i2c_probe(addr)) {
1905 printf("Can't found max8998\n");
1908 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1909 val[0] &= ~(MAX8998_LDO17);
1910 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1911 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1913 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1914 val[0] |= MAX8998_LDO17;
1916 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1917 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1919 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1920 val[0] |= MAX8998_LDO7;
1922 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1923 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1926 if (machine_is_aquila() || machine_is_geminus())
1927 gpio_set_value(&gpio->gpio_j1, 3, 0);
1929 if (machine_is_cypress())
1930 gpio_set_value(&gpio->gpio_g2, 2, 0);
1932 if (machine_is_kessler()) {
1934 unsigned char val[2];
1936 gpio_set_value(&gpio->gpio_j1, 3, 0);
1938 i2c_set_bus_num(I2C_PMIC);
1939 addr = 0xCC >> 1; /* max8998 */
1940 if (i2c_probe(addr)) {
1941 printf("Can't found max8998\n");
1945 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1946 val[0] &= ~(MAX8998_LDO7);
1947 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1948 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1950 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1951 val[0] &= ~(MAX8998_LDO17);
1952 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1953 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1958 extern void s6e63m0_cfg_ldo(void);
1959 extern void s6e63m0_enable_ldo(unsigned int onoff);
1960 extern void s6d16a0x_cfg_ldo(void);
1961 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1963 int s5p_no_lcd_support(void)
1965 if (machine_is_wmg160())
1970 void init_panel_info(vidinfo_t *vid)
1972 vid->cfg_gpio = NULL;
1973 vid->reset_lcd = NULL;
1974 vid->backlight_on = NULL;
1975 vid->lcd_power_on = NULL;
1977 vid->cfg_ldo = NULL;
1978 vid->enable_ldo = NULL;
1980 vid->init_delay = 0;
1981 vid->reset_delay = 0;
1982 vid->power_on_delay = 0;
1987 vid->vl_width = 480;
1988 vid->vl_height = 800;
1990 vid->dual_lcd_enabled = 0;
1992 if (board_is_media()) {
1995 vid->vl_width = 960;
1996 vid->vl_height = 800;
1998 /* enable dual lcd mode. */
1999 vid->dual_lcd_enabled = 1;
2002 vid->vl_clkp = CONFIG_SYS_HIGH;
2003 vid->vl_hsp = CONFIG_SYS_LOW;
2004 vid->vl_vsp = CONFIG_SYS_LOW;
2005 vid->vl_dp = CONFIG_SYS_HIGH;
2008 /* S6E63M0 LCD Panel */
2017 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
2018 vid->cfg_gpio = lcd_cfg_gpio;
2019 vid->reset_lcd = reset_lcd;
2020 vid->backlight_on = backlight_on;
2021 vid->lcd_power_on = lcd_power_on;
2022 vid->cfg_ldo = s6e63m0_cfg_ldo;
2023 vid->enable_ldo = s6e63m0_enable_ldo;
2025 vid->init_delay = 25000;
2026 vid->reset_delay = 120000;
2029 if (board_is_neptune()) {
2033 vid->vl_width = 320;
2034 vid->vl_height = 480;
2036 vid->vl_clkp = CONFIG_SYS_HIGH;
2037 vid->vl_hsp = CONFIG_SYS_HIGH;
2038 vid->vl_vsp = CONFIG_SYS_HIGH;
2039 vid->vl_dp = CONFIG_SYS_LOW;
2042 /* disable dual lcd mode. */
2043 vid->dual_lcd_enabled = 0;
2045 /* S6D16A0X LCD Panel */
2054 vid->cfg_gpio = lcd_cfg_gpio;
2055 vid->backlight_on = backlight_on;
2056 vid->lcd_power_on = lcd_power_on;
2057 vid->reset_lcd = reset_lcd;
2058 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2059 vid->enable_ldo = s6d16a0x_enable_ldo;
2061 vid->init_delay = 10000;
2062 vid->power_on_delay = 10000;
2063 vid->reset_delay = 1000;
2067 if (machine_is_geminus()) {
2071 vid->vl_width = 1024,
2072 vid->vl_height = 600,
2073 vid->vl_clkp = CONFIG_SYS_LOW,
2074 vid->vl_hsp = CONFIG_SYS_HIGH,
2075 vid->vl_vsp = CONFIG_SYS_HIGH,
2076 vid->vl_dp = CONFIG_SYS_LOW,
2087 vid->cfg_gpio = lcd_cfg_gpio;
2088 vid->reset_lcd = reset_lcd;
2089 vid->backlight_on = backlight_on;
2090 vid->lcd_power_on = lcd_power_on;
2096 vid->vl_width = 480,
2097 vid->vl_height = 800,
2098 vid->vl_clkp = CONFIG_SYS_HIGH,
2099 vid->vl_hsp = CONFIG_SYS_LOW,
2100 vid->vl_vsp = CONFIG_SYS_LOW,
2101 vid->vl_dp = CONFIG_SYS_HIGH,
2117 vid->vl_width = 1024,
2118 vid->vl_height = 600,
2119 vid->vl_clkp = CONFIG_SYS_HIGH,
2120 vid->vl_hsp = CONFIG_SYS_HIGH,
2121 vid->vl_vsp = CONFIG_SYS_HIGH,
2122 vid->vl_dp = CONFIG_SYS_LOW,
2125 /* AMS701KA AMOLED Panel. */
2137 static void setup_meminfo(void)
2139 char meminfo[64] = {0, };
2140 int count = 0, size, real;
2142 size = gd->bd->bi_dram[0].size >> 20;
2143 count += sprintf(meminfo + count, "mem=%dM", size);
2145 /* Each Chip Select can't exceed the 256MiB */
2146 size = gd->bd->bi_dram[1].size >> 20;
2147 real = min(size, 256);
2148 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2149 real, (unsigned int)gd->bd->bi_dram[1].start);
2153 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2154 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2157 setenv("meminfo", meminfo);
2160 int misc_init_r(void)
2163 /* It should be located at first */
2166 if (machine_is_aquila() || machine_is_kessler()) {
2167 if (board_is_neptune())
2168 setenv("lcdinfo", "lcd=s6d16a0x");
2169 else if (board_is_media())
2170 setenv("lcdinfo", "lcd=s6e63m0");
2172 setenv("lcdinfo", "lcd=s6e63m0");
2174 if (machine_is_geminus())
2175 setenv("lcdinfo", "lcd=lms480jc01");
2176 if (machine_is_cypress())
2177 setenv("lcdinfo", "lcd=s6e63m0");
2183 /* Set proper PMIC pins */
2186 /* Check auto burning */
2189 /* To power up I2C2 */
2192 /* Enable T-Flash at Limo Real or Limo Universal */
2195 /* Setup Limo Real board GPIOs */
2196 setup_limo_real_gpios();
2198 /* Setup Media board GPIOs */
2199 setup_media_gpios();
2201 /* To usbdown automatically */
2207 #ifdef CONFIG_S5PC1XXFB
2208 display_device_info();
2211 setup_power_down_mode_registers();
2213 /* check max17040 */
2223 int board_init(void)
2225 /* Set Initial global variables */
2226 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2228 gd->bd->bi_arch_number = MACH_AQUILA;
2229 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2231 /* Check H/W Revision */
2232 check_hw_revision();
2239 unsigned int base, memconfig0, size;
2240 unsigned int memconfig1, sz = 0;
2242 if (cpu_is_s5pc100()) {
2243 /* In mem setup, we swap the bank. So below size is correct */
2244 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2245 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2246 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2249 /* In S5PC110, we can't swap the DMC0/1 */
2250 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2251 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2253 base = S5PC110_DMC1_BASE;
2254 /* DMC configuration */
2255 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2256 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2258 size = (memconfig0 >> 16) & 0xFF;
2259 size = ((unsigned char) ~size) + 1;
2262 * (0x07 + 1) * 16 = 128 MiB
2263 * (0x0f + 1) * 16 = 256 MiB
2268 * Aquila Rev0.5 4G3G1G
2269 * Aquila Rev0.8 4G3G1G
2270 * Aquila Rev0.9 4G3G1G
2272 if (machine_is_aquila() || machine_is_kessler())
2273 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2274 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2276 sz = (memconfig1 >> 16) & 0xFF;
2277 sz = ((unsigned char) ~sz) + 1;
2283 * bi_dram[1].size contains all DMC1 memory size
2285 gd->bd->bi_dram[1].size = (size + sz) << 20;
2290 /* Used for sleep test */
2291 static unsigned char saved_val[4][2];
2292 void board_sleep_init_late(void)
2294 /* CODEC_LDO_EN: GPF3[4] */
2295 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2296 /* CODEC_XTAL_EN: GPH3[2] */
2297 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2299 /* MMC T_FLASH off */
2300 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2302 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2303 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2304 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2308 void board_sleep_init(void)
2311 unsigned char val[2];
2313 i2c_set_bus_num(I2C_PMIC);
2315 if (i2c_probe(addr)) {
2316 printf("Can't find max8998\n");
2320 if (machine_is_kessler()) {
2323 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2324 saved_val[0][0] = val[0];
2325 saved_val[0][1] = val[1];
2326 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2327 (1 << 1) | (1 << 0));
2328 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2329 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2331 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2332 saved_val[1][0] = val[0];
2333 saved_val[1][1] = val[1];
2334 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2335 (1 << 2) | (1 << 1) | (1 << 0));
2337 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2338 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2340 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2341 saved_val[2][0] = val[0];
2342 saved_val[2][1] = val[1];
2343 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2344 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2345 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2347 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2348 saved_val[3][0] = val[0];
2349 saved_val[3][1] = val[1];
2350 val[0] &= ~((1 << 6) | (1 << 4));
2351 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2352 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2353 printf("Turned off regulators with Kessler setting."
2354 " Preparing to sleep. [%s:%d]\n",
2355 __FILE__, __LINE__);
2356 } else { /* Default */
2359 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2360 saved_val[0][0] = val[0];
2361 saved_val[0][1] = val[1];
2362 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2363 (1 << 1) | (1 << 0));
2364 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2365 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2367 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2368 saved_val[1][0] = val[0];
2369 saved_val[1][1] = val[1];
2370 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2371 (1 << 2) | (1 << 1) | (1 << 0));
2373 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2374 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2376 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2377 saved_val[2][0] = val[0];
2378 saved_val[2][1] = val[1];
2379 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2380 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2381 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2383 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2384 saved_val[3][0] = val[0];
2385 saved_val[3][1] = val[1];
2386 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2387 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2388 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2389 printf("Turned off regulators with default(Aquila) setting."
2390 " Preparing to sleep. [%s:%d]\n",
2391 __FILE__, __LINE__);
2395 void board_sleep_resume(void)
2398 unsigned char val[2];
2402 i2c_set_bus_num(I2C_PMIC);
2404 if (i2c_probe(addr)) {
2405 printf("Can't find max8998\n");
2410 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2411 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2413 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2414 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2416 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2417 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2419 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2420 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2421 printf("Waked up.\n");
2423 /* check max17040 */
2430 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2432 static int s5pc1xx_phy_control(int on)
2436 if (on && !status) {
2437 // printf("turning USB power on\n");
2438 #ifdef CONFIG_CMD_PMIC
2439 run_command("pmic ldo 3 on", 0);
2442 if (board_is_limo_universal() ||
2443 board_is_limo_real() ||
2445 /* check usb path */
2446 if (board_is_limo_real() && !hwrevision(6))
2450 if (machine_is_tickertape())
2451 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2452 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2454 /* USB Path to AP */
2455 micro_usb_switch(0);
2457 } else if (!on && status) {
2458 // printf("turning USB power off\n");
2459 #ifdef CONFIG_CMD_PMIC
2460 run_command("pmic ldo 3 off", 0);
2469 struct s3c_plat_otg_data s5pc110_otg_data = {
2470 .phy_control = s5pc1xx_phy_control,
2471 .regs_phy = S5PC110_PHY_BASE,
2472 .regs_otg = S5PC110_OTG_BASE,
2475 int board_eth_init(bd_t *bis)
2479 if (cpu_is_s5pc100())
2482 s3c_udc_probe(&s5pc110_otg_data);
2483 if (usb_eth_initialize(bis) >= 0)
2489 #ifdef CONFIG_CMD_USBDOWN
2490 int usb_board_init(void)
2492 #ifdef CONFIG_CMD_PMIC
2493 run_command("pmic ldo 3 on", 0);
2496 if (cpu_is_s5pc100()) {
2497 #ifdef CONFIG_HARD_I2C
2498 uchar val[2] = {0,};
2501 if (i2c_read(0x66, 0, 1, val, 2)) {
2502 printf("i2c_read error\n");
2509 if (i2c_write(0x66, 0, 1, val, 2)) {
2510 printf("i2c_write error\n");
2513 i2c_read(0x66, 0, 1, val, 2);
2519 if (board_is_limo_universal() ||
2520 board_is_limo_real() ||
2522 /* check usb path */
2523 if (board_is_limo_real() && !hwrevision(6))
2527 if (machine_is_tickertape())
2528 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2529 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2531 /* USB Path to AP */
2532 micro_usb_switch(0);
2538 #ifdef CONFIG_GENERIC_MMC
2539 int s5p_no_mmc_support(void)
2541 if (machine_is_wmg160())
2546 int board_mmc_init(bd_t *bis)
2550 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2553 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2554 if (machine_is_kessler())
2555 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2557 if (machine_is_wmg160())
2560 /* MMC0 Clock source = SCLKMPLL */
2561 reg = readl(&clk->src4);
2564 writel(reg, &clk->src4);
2566 reg = readl(&clk->div4);
2569 /* set div value near 50MHz */
2570 clock = get_pll_clk(MPLL) / 1000000;
2571 for (i = 0; i < 0xf; i++) {
2572 if ((clock / (i + 1)) <= 50) {
2578 writel(reg, &clk->div4);
2584 * GPG0[2] SD_0_CDn -> Not used
2585 * GPG0[3:6] SD_0_DATA[0:3]
2587 for (i = 0; i < 7; i++) {
2590 /* GPG0[0:6] special function 2 */
2591 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2592 /* GPG0[0:6] pull disable */
2593 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2594 /* GPG0[0:6] drv 4x */
2595 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2598 return s5pc1xx_mmc_init(0);
2602 #ifdef CONFIG_CMD_PMIC
2603 static int pmic_status(void)
2605 unsigned char addr, val[2];
2608 i2c_set_bus_num(I2C_PMIC);
2610 if (i2c_probe(addr)) {
2611 printf("Can't found max8998\n");
2616 i2c_read(addr, reg, 1, val, 1);
2617 for (i = 7; i >= 4; i--)
2618 printf("BUCK%d %s\n", 7 - i + 1,
2619 val[0] & (1 << i) ? "on" : "off");
2621 printf("LDO%d %s\n", 5 - i,
2622 val[0] & (1 << i) ? "on" : "off");
2624 i2c_read(addr, reg, 1, val, 1);
2625 for (i = 7; i >= 0; i--)
2626 printf("LDO%d %s\n", 7 - i + 6,
2627 val[0] & (1 << i) ? "on" : "off");
2629 i2c_read(addr, reg, 1, val, 1);
2630 for (i = 7; i >= 4; i--)
2631 printf("LDO%d %s\n", 7 - i + 14,
2632 val[0] & (1 << i) ? "on" : "off");
2635 i2c_read(addr, reg, 1, val, 1);
2636 for (i = 7; i >= 6; i--)
2637 printf("SAFEOUT%d %s\n", 7 - i + 1,
2638 val[0] & (1 << i) ? "on" : "off");
2642 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2644 unsigned char addr, val[2];
2645 unsigned int reg, shift;
2653 } else if (ldo <= 13) {
2656 } else if (ldo <= 17) {
2658 shift = 17 - ldo + 4;
2665 shift = 4 - buck + 4;
2666 } else if (safeout) {
2670 shift = 8 - safeout;
2674 i2c_set_bus_num(I2C_PMIC);
2676 if (i2c_probe(addr)) {
2677 printf("Can't found max8998\n");
2681 i2c_read(addr, reg, 1, val, 1);
2683 val[0] |= (1 << shift);
2685 val[0] &= ~(1 << shift);
2686 i2c_write(addr, reg, 1, val, 1);
2687 i2c_read(addr, reg, 1, val, 1);
2690 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2691 val[0] & (1 << shift) ? "on" : "off");
2693 printf("buck %d value 0x%x, %s\n", buck, val[0],
2694 val[0] & (1 << shift) ? "on" : "off");
2696 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2697 val[0] & (1 << shift) ? "on" : "off");
2702 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2704 int buck = 0, ldo = 0, safeout = 0, on = -1;
2708 if (strncmp(argv[1], "status", 6) == 0)
2709 return pmic_status();
2712 if (strncmp(argv[1], "ldo", 3) == 0)
2713 ldo = simple_strtoul(argv[2], NULL, 10);
2714 else if (strncmp(argv[1], "buck", 4) == 0)
2715 buck = simple_strtoul(argv[2], NULL, 10);
2716 else if (strncmp(argv[1], "safeout", 7) == 0)
2717 safeout = simple_strtoul(argv[2], NULL, 10);
2721 if (strncmp(argv[3], "on", 2) == 0)
2723 else if (strncmp(argv[3], "off", 3) == 0)
2728 return pmic_ldo_control(buck, ldo, safeout, on);
2739 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2740 "PMIC LDO & BUCK control",
2741 "status - Display PMIC LDO & BUCK status\n"
2742 "pmic ldo num on/off - Turn on/off the LDO\n"
2743 "pmic buck num on/off - Turn on/off the BUCK\n"
2744 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2748 #ifdef CONFIG_CMD_DEVICE_POWER
2762 static void power_display_devices(void)
2764 printf("devices:\n");
2765 printf("\t%d - touch\n", POWER_TOUCH);
2766 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2767 printf("\t%d - LCD\n", POWER_LCD);
2768 printf("\t%d - Haptic\n", POWER_HAPTIC);
2769 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2770 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2771 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2772 printf("\t%d - HDMI\n", POWER_HDMI);
2775 static int power_hdmi(int on)
2777 /* HDMI_EN1: GPJ2[2] */
2778 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2779 /* MHL_ON: GPJ2[3] */
2780 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2784 static int power_bt_wifi(int on)
2786 /* WLAN_BT_EN: GPB[5] */
2787 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2791 static int power_fm_radio(int on)
2793 /* FM_BUS_nRST: GPJ2[5] */
2794 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2798 static int power_audio_codec(int on)
2800 /* CODEC_LDO_EN: GPF3[4] */
2801 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2802 /* CODEC_XTAL_EN: GPH3[2] */
2803 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2807 static int power_haptic(int on)
2809 /* HAPTIC_ON: GPJ1[1] */
2810 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2814 static int power_lcd(int on)
2816 /* MLCD_ON: GPJ1[3] */
2817 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2821 static int power_touch(int on)
2823 /* TOUCH_EN: GPG3[6] */
2824 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2828 static int power_3_touchkey(int on)
2831 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2832 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2833 if (board_rev & J1_B2_BOARD)
2834 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2836 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2838 /* 3_TOUCH_CE - GPJ2[6] */
2839 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2841 /* 3_TOUCH_CE - GPJ2[6] */
2842 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2847 unsigned char val[2];
2848 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2854 i2c_set_bus_num(I2C_GPIO10);
2856 /* Workaround to probe */
2857 if (i2c_probe(addr)) {
2858 if (i2c_probe(addr)) {
2859 printf("Can't found 3 touchkey\n");
2864 #define MCS5000_TK_HW_VERSION 0x06
2865 #define MCS5000_TK_FW_VERSION 0x0A
2866 #define MCS5000_TK_MI_VERSION 0x0B
2868 reg = MCS5000_TK_MI_VERSION;
2869 i2c_read(addr, reg, 1, val, 1);
2870 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2871 reg = MCS5000_TK_HW_VERSION;
2872 i2c_read(addr, reg, 1, val, 1);
2873 printf("H/W 0x%x, ", val[0]);
2874 reg = MCS5000_TK_FW_VERSION;
2875 i2c_read(addr, reg, 1, val, 1);
2876 printf("F/W 0x%x\n", val[0]);
2881 static int power_control(int device, int on)
2885 return power_touch(on);
2886 case POWER_3_TOUCHKEY:
2887 return power_3_touchkey(on);
2889 return power_lcd(on);
2891 return power_haptic(on);
2892 case POWER_AUDIO_CODEC:
2893 return power_audio_codec(on);
2894 case POWER_FM_RADIO:
2895 return power_fm_radio(on);
2897 return power_bt_wifi(on);
2899 return power_hdmi(on);
2901 printf("I don't know device %d\n", device);
2907 static int power_on(int on)
2910 power_3_touchkey(on);
2913 power_audio_codec(on);
2921 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2925 if (!machine_is_aquila() && !machine_is_kessler())
2930 if (strncmp(argv[1], "on", 2) == 0)
2932 if (strncmp(argv[1], "off", 3) == 0)
2936 device = simple_strtoul(argv[1], NULL, 10);
2940 if (strncmp(argv[2], "on", 2) == 0)
2942 else if (strncmp(argv[2], "off", 3) == 0)
2946 return power_control(device, on);
2952 power_display_devices();
2957 power, CONFIG_SYS_MAXARGS, 1, do_power,
2958 "Device Power Management control",
2959 "device on/off - Turn on/off the device\n"
2962 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2966 if (strncmp(argv[1], "cp", 2) == 0) {
2967 micro_usb_switch(1);
2968 pmic_ldo_control(0, 0, 2, 1);
2969 setenv("usb", "cp");
2970 } else if (strncmp(argv[1], "ap", 2) == 0) {
2971 micro_usb_switch(0);
2972 pmic_ldo_control(0, 0, 2, 0);
2973 setenv("usb", "ap");
2983 printf("USB Path is set to %s\n", getenv("usb"));
2989 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2991 "cp - switch to CP\n"
2992 "microusb ap - switch to AP\n"