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 enable_battery(void);
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 enable_battery(void)
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_tickertape()) {
905 } else if (machine_is_cypress()) {
906 i2c_set_bus_num(I2C_GPIO7);
907 } else if (machine_is_geminus()) {
909 i2c_set_bus_num(I2C_GPIO7);
912 if (i2c_probe(addr)) {
913 printf("Can't found max17040 fuel gauge\n");
919 i2c_write(addr, 0xfe, 1, val, 2);
922 static void check_battery(void)
924 unsigned char val[2];
925 unsigned char addr = 0x36; /* max17040 fuel gauge */
927 i2c_set_bus_num(I2C_GPIO3);
929 if (machine_is_aquila()) {
932 } else if (machine_is_kessler())
933 i2c_set_bus_num(I2C_GPIO7);
934 else if (machine_is_cypress()) {
935 i2c_set_bus_num(I2C_GPIO7);
936 } else if (machine_is_geminus()) {
938 i2c_set_bus_num(I2C_GPIO7);
942 if (i2c_probe(addr)) {
943 printf("Can't found max17040 fuel gauge\n");
947 i2c_read(addr, 0x04, 1, val, 1);
949 dprintf("battery:\t%d%%\n", val[0]);
951 battery_soc = val[0];
954 static void check_mhl(void)
956 unsigned char val[2];
957 unsigned char addr = 0x39; /* SIL9230 */
959 /* MHL Power enable */
960 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
961 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
963 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
964 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
966 /* 10ms required after reset */
970 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
972 i2c_set_bus_num(I2C_GPIO5);
975 if (i2c_probe(addr)) {
976 printf("Can't found MHL Chip\n");
982 * set to Normal operation
985 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
986 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
991 * 00 = MHL termination ON
992 * 11 = MHL termination OFF
995 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
996 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
999 #define CHARGER_ANIMATION_FRAME 6
1000 static int max8998_power_key(void)
1002 unsigned char addr, val[2];
1003 i2c_set_bus_num(I2C_PMIC);
1005 if (i2c_probe(addr)) {
1006 printf("Can't found max8998\n");
1010 /* Accessing IRQ1 register */
1011 i2c_read(addr, 0x00, 1, val, 1);
1012 if (val[0] & (1 << 6))
1018 static int max8998_has_ext_power_source(void)
1020 unsigned char addr, val[2];
1021 i2c_set_bus_num(I2C_PMIC);
1023 if (i2c_probe(addr)) {
1024 printf("Can't found max8998\n");
1028 /* Accessing STATUS2 register */
1029 i2c_read(addr, 0x09, 1, val, 1);
1030 if (val[0] & (1 << 5))
1036 struct thermister_stat {
1041 static struct thermister_stat adc_to_temperature_data[] = {
1042 { .centigrade = -20, .adc = 1856, },
1043 { .centigrade = -15, .adc = 1799, },
1044 { .centigrade = -10, .adc = 1730, },
1045 { .centigrade = -5, .adc = 1649, },
1046 { .centigrade = 0, .adc = 1556, },
1047 { .centigrade = 5, .adc = 1454, },
1048 { .centigrade = 10, .adc = 1343, },
1049 { .centigrade = 15, .adc = 1227, },
1050 { .centigrade = 20, .adc = 1109, },
1051 { .centigrade = 25, .adc = 992, },
1052 { .centigrade = 30, .adc = 880, },
1053 { .centigrade = 35, .adc = 773, },
1054 { .centigrade = 40, .adc = 675, },
1055 { .centigrade = 45, .adc = 586, },
1056 { .centigrade = 50, .adc = 507, },
1057 { .centigrade = 55, .adc = 436, },
1058 { .centigrade = 58, .adc = 399, },
1059 { .centigrade = 63, .adc = 343, },
1060 { .centigrade = 65, .adc = 322, },
1064 #define USHRT_MAX 0xFFFFU
1066 static int adc_to_temperature_centigrade(unsigned short adc)
1070 /* low_*: Greatest Lower Bound,
1071 * * * * high_*: Smallest Upper Bound */
1072 int low_temp, high_temp;
1073 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1074 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1075 if (adc_to_temperature_data[i].adc <= adc &&
1076 adc_to_temperature_data[i].adc >= low_adc) {
1077 low_temp = adc_to_temperature_data[i].centigrade;
1078 low_adc = adc_to_temperature_data[i].adc;
1080 if (adc_to_temperature_data[i].adc >= adc &&
1081 adc_to_temperature_data[i].adc <= high_adc) {
1082 high_temp = adc_to_temperature_data[i].centigrade;
1083 high_adc = adc_to_temperature_data[i].adc;
1087 /* Linear approximation between cloest low and high,
1088 * which is the weighted average of the two. */
1090 /* The following equation is correct only when the two are different */
1091 if (low_adc == high_adc)
1093 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1094 return 20; /* The room temperature */
1097 if (high_adc == USHRT_MAX)
1099 approximation = low_temp * (adc - low_adc) +
1100 high_temp * (high_adc - adc);
1101 approximation /= high_adc - low_adc;
1102 return approximation;
1105 static unsigned short get_adc_value(int channel)
1107 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1108 unsigned short ret = 0;
1112 unsigned int loop = 0;
1114 if (machine_is_kessler())
1116 else if (machine_is_geminus())
1118 else if (machine_is_wmg160())
1120 else if (machine_is_cypress())
1122 else if (machine_is_tickertape())
1124 else if (machine_is_aquila())
1127 else if (machine_is_p1p2())
1131 sprintf(buf, "pmic ldo %d on", ldonum);
1132 run_command(buf, 0);
1133 writel(channel & 0xF, &adc->adcmux);
1134 writel((1 << 14) | (49 << 6), &adc->adccon);
1135 writel(1000 & 0xffff, &adc->adcdly);
1136 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1138 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1142 reg = readl(&adc->adccon);
1143 } while (!reg & (1 << 15) && loop++ < 1000);
1144 ret = readl(&adc->adcdat0) & 0xFFF;
1145 sprintf(buf, "pmic ldo %d off", ldonum);
1146 run_command(buf, 0);
1151 static int adc_get_average_ambient_temperature(void)
1153 if (machine_is_kessler()) {
1154 unsigned short min = USHRT_MAX;
1155 unsigned short max = 0;
1156 unsigned int sum = 0;
1157 unsigned int measured = 0;
1160 for (i = 0; i < 7; i++) {
1161 unsigned short measurement = get_adc_value(6);
1164 if (min > measurement)
1166 if (max < measurement)
1169 if (measured >= 3) {
1175 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1176 adc_to_temperature_centigrade(sum), sum);
1177 return adc_to_temperature_centigrade(sum);
1180 return 20; /* 20 Centigrade */
1183 enum temperature_level {
1191 static enum temperature_level temperature_check(void)
1193 int temp = adc_get_average_ambient_temperature();
1195 return _TEMP_TOO_LOW;
1197 return _TEMP_OK_LOW;
1199 return _TEMP_TOO_HIGH;
1201 return _TEMP_OK_HIGH;
1205 extern void lcd_display_clear(void);
1206 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1208 static void charger_en(int enable)
1214 unsigned char addr = 0xCC >> 1; /* max8998 */
1215 unsigned char val[2];
1217 i2c_set_bus_num(I2C_PMIC);
1218 if (i2c_probe(addr)) {
1219 printf("Can't found max8998 (%s:%d)\n", __func__, __LINE__);
1224 printf("Disable the charger.\n");
1225 i2c_read(addr, 0x0D, 1, val, 1);
1228 i2c_write(addr, 0x0D, 1, val, 1);
1230 i2c_read(addr, 0x0C, 1, val, 1);
1231 val[0] &= ~(0x7 << 0);
1232 val[0] &= ~(0x7 << 5);
1233 if (enable == 600) {
1234 val[0] |= 5; /* 600mA */
1235 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1236 } else { /* Assume 475 mA */
1238 val[0] |= 2; /* 475mA */
1239 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1241 i2c_write(addr, 0x0C, 1, val, 1);
1243 i2c_read(addr, 0x0D, 1, val, 1);
1245 i2c_write(addr, 0x0D, 1, val, 1);
1246 printf("Enable the charger @ %dmA\n", enable);
1250 static void into_charge_mode(void)
1256 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1257 unsigned int reg, wakeup_stat;
1258 int charger_speed = 600;
1260 printf("Charge Mode\n");
1261 charger_en(charger_speed);
1263 #ifdef CONFIG_S5PC1XXFB
1266 /* TODO: write the image-text for the charger */
1268 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1269 if (level >= CHARGER_ANIMATION_FRAME)
1270 level = CHARGER_ANIMATION_FRAME - 1;
1272 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1273 bmp_addr[i] = (ulong)battery_charging_animation[i];
1275 lcd_display_clear();
1276 for (i = 0; i < 3; i++) {
1277 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1280 bmp = gunzip_bmp(bmp_addr[j], &len);
1281 lcd_display_bitmap((ulong) bmp, 140, 202);
1284 for (k = 0; k < 10; k++)
1285 if (max8998_power_key()) {
1286 lcd_display_clear();
1288 } else if (!max8998_has_ext_power_source()) {
1289 lcd_display_clear();
1299 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1300 unsigned int org, org_ip3, org_tcfg0;
1301 enum temperature_level previous_state = _TEMP_OK;
1303 empty_device_info_buffer();
1304 if (max8998_power_key()) {
1305 lcd_display_clear();
1307 } else if (!max8998_has_ext_power_source()) {
1308 lcd_display_clear();
1312 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1313 org_ip3 = readl(0xE010046C);
1314 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1316 reg = org = readl(&rtc->rtccon);
1318 writel(reg, &rtc->rtccon);
1320 reg = readl(&rtc->rtccon);
1321 writel(reg | (1 << 3), &rtc->rtccon);
1323 writel(reg & ~(1 << 3), &rtc->rtccon);
1326 reg = readl(&rtc->rtccon);
1327 reg &= ~( (1 << 8) | (0xF << 4));
1328 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1329 writel(reg, &rtc->rtccon);
1331 reg = 15 * 4 - 1; /* 15 sec */
1332 writel(reg, &rtc->ticcnt);
1334 /* TODO: turn LCD/FB off for sure */
1337 /* EVT0: sleep 1, EVT1: sleep */
1338 if (cpu_is_s5pc110()) {
1339 char *name = "dummy";
1340 char *usage = "N/A";
1347 if (s5pc1xx_get_cpu_rev() == 0) {
1348 char *argv[] = {"1", "1"};
1349 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1351 char *argv[] = {"0", "0"};
1352 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1355 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1360 /* Check TEMP HIGH/LOW */
1361 switch (temperature_check()) {
1363 charger_en(charger_speed);
1364 previous_state = _TEMP_OK;
1368 previous_state = _TEMP_TOO_LOW;
1370 case _TEMP_TOO_HIGH:
1372 previous_state = _TEMP_TOO_HIGH;
1375 if (previous_state == _TEMP_TOO_LOW)
1379 charger_en(charger_speed);
1380 previous_state = _TEMP_OK;
1384 if (previous_state == _TEMP_TOO_HIGH)
1388 charger_en(charger_speed);
1389 previous_state = _TEMP_OK;
1394 writel(org, &rtc->rtccon);
1395 writel(org_tcfg0, 0xE2600000);
1396 writel(org_ip3, 0xE010046C);
1398 } while (wakeup_stat == 0x04); /* RTC TICK */
1400 /* TODO: Reenable logo display */
1404 run_command("cls", 0);
1407 static void check_micro_usb(int intr)
1410 unsigned char val[2];
1411 static int started_charging_once = 0;
1414 if (cpu_is_s5pc100())
1417 if (board_is_limo_real()) {
1418 if (hwrevision(0) || hwrevision(1))
1422 i2c_set_bus_num(I2C_PMIC);
1424 if (machine_is_kessler())
1425 i2c_set_bus_num(I2C_GPIO6);
1426 else if (machine_is_cypress()) {
1427 i2c_set_bus_num(I2C_GPIO6);
1428 } else if (machine_is_geminus()) {
1430 i2c_set_bus_num(I2C_GPIO6);
1431 } else if (machine_is_wmg160())
1432 i2c_set_bus_num(I2C_GPIO6);
1434 addr = 0x25; /* fsa9480 */
1435 if (i2c_probe(addr)) {
1436 printf("Can't found fsa9480\n");
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)
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 i2c_set_bus_num(I2C_PMIC);
1498 if (machine_is_kessler())
1499 i2c_set_bus_num(I2C_GPIO6);
1500 else if (machine_is_cypress()) {
1501 i2c_set_bus_num(I2C_GPIO6);
1502 } else if (machine_is_geminus()) {
1504 i2c_set_bus_num(I2C_GPIO6);
1505 } else if (machine_is_wmg160()) {
1506 i2c_set_bus_num(I2C_GPIO6);
1510 addr = 0x25; /* fsa9480 */
1511 if (i2c_probe(addr)) {
1512 printf("Can't found fsa9480\n");
1517 val[0] = 0x90; /* VAUDIO */
1519 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1521 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1523 i2c_read(addr, 0x2, 1, val, 1);
1524 val[0] &= ~(1 << 2); /* Manual switching */
1525 i2c_write(addr, 0x2, 1, val, 1);
1528 #define MAX8998_REG_ONOFF1 0x11
1529 #define MAX8998_REG_ONOFF2 0x12
1530 #define MAX8998_REG_ONOFF3 0x13
1531 #define MAX8998_REG_LDO7 0x21
1532 #define MAX8998_REG_LDO17 0x29
1534 #define MAX8998_LDO3 (1 << 2)
1536 #define MAX8998_LDO6 (1 << 7)
1537 #define MAX8998_LDO7 (1 << 6)
1538 #define MAX8998_LDO8 (1 << 5)
1539 #define MAX8998_LDO9 (1 << 4)
1540 #define MAX8998_LDO10 (1 << 3)
1541 #define MAX8998_LDO11 (1 << 2)
1542 #define MAX8998_LDO12 (1 << 1)
1543 #define MAX8998_LDO13 (1 << 0)
1545 #define MAX8998_LDO14 (1 << 7)
1546 #define MAX8998_LDO15 (1 << 6)
1547 #define MAX8998_LDO16 (1 << 5)
1548 #define MAX8998_LDO17 (1 << 4)
1551 static void init_pmic(void)
1554 unsigned char val[2];
1556 if (cpu_is_s5pc100())
1559 i2c_set_bus_num(I2C_PMIC);
1561 addr = 0xCC >> 1; /* max8998 */
1562 if (i2c_probe(addr)) {
1563 if (i2c_probe(addr)) {
1564 printf("Can't found max8998\n");
1570 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1571 val[0] &= ~MAX8998_LDO3;
1572 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1575 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1577 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1578 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1580 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1581 MAX8998_LDO12 | MAX8998_LDO13);
1583 if (machine_is_kessler())
1584 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1586 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1587 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1589 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1591 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1592 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1594 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1595 MAX8998_LDO16 | MAX8998_LDO17);
1597 if (machine_is_kessler())
1598 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1600 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1601 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1604 static void setup_power_down_mode_registers(void)
1606 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1607 struct s5pc1xx_gpio_bank *bank;
1608 struct gpio_powermode *p;
1610 struct gpio_external *ge;
1612 struct s5pc1xx_gpio_item *mr;
1616 if (cpu_is_s5pc100())
1619 /* Only Limo real and kessler supports worked for sleep currnet */
1620 if (machine_is_aquila()) {
1621 if (board_is_limo_real())
1625 } else if (machine_is_kessler()) {
1627 } else if (machine_is_geminus()) {
1632 if (machine_is_aquila()) {
1633 /* Aquila rev 0.8 or lower */
1634 p = aquila_powerdown_modes;
1635 ge = aquila_external_powerdown_modes;
1636 mr = aquila_mirror_powerdown_mode;
1637 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1638 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1639 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1640 } else if (machine_is_kessler()) {
1641 /* Aquila rev 0.9 */
1642 p = kessler_powerdown_modes;
1643 ge = kessler_external_powerdown_modes;
1644 mr = kessler_mirror_powerdown_mode;
1645 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1646 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1647 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1648 } else if (machine_is_geminus()) {
1649 if (hwrevision(1)) {
1650 /* Same as Aquila rev 0.9 */
1652 p = kessler_powerdown_modes;
1653 ge = kessler_external_powerdown_modes;
1654 mr = kessler_mirror_powerdown_mode;
1655 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1656 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1657 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1659 p = aquila_powerdown_modes;
1660 ge = aquila_external_powerdown_modes;
1661 mr = aquila_mirror_powerdown_mode;
1662 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1663 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1664 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1666 } else if (hwrevision(0)) {
1667 /* Same as Aquila rev 0.8 or lower */
1668 p = aquila_powerdown_modes;
1669 ge = aquila_external_powerdown_modes;
1670 mr = aquila_mirror_powerdown_mode;
1671 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1672 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1673 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1675 return; /* Not supported */
1679 bank = &gpio->gpio_a0;
1681 for (i = 0; i < n_p; i++, p++, bank++) {
1682 writel(p->conpdn, &bank->pdn_con);
1683 writel(p->pudpdn, &bank->pdn_pull);
1686 writel(0xff0022b0, (unsigned int *)0xF0000000);
1687 writel(0xff0022b0, (unsigned int *)0xF1400000);
1689 bank = &gpio->gpio_h0;
1691 for (i = 0; i < n_ge; i++) {
1692 writel(ge->con, &bank->con);
1693 writel(ge->dat, &bank->dat);
1694 writel(ge->pud, &bank->pull);
1700 for (i = 0; i < n_mr; i++) {
1701 unsigned int reg = readl(&mr->bank->pdn_con);
1702 reg &= ~(1 << mr->number);
1703 if (readl(&mr->bank->dat) & (1 << mr->number))
1704 reg |= 1 << mr->number;
1705 writel(reg, &mr->bank->pdn_con);
1711 #include "../../../drivers/video/s5p-spi.h"
1713 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1714 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1716 struct spi_platform_data spi_pd;
1718 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1720 void lcd_cfg_gpio(void)
1722 unsigned int i, f3_end = 4;
1724 for (i = 0; i < 8; i++) {
1725 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1726 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1727 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1728 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1729 /* pull-up/down disable */
1730 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1731 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1732 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1734 /* drive strength to max (24bit) */
1735 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1736 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1737 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1738 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1739 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1740 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1743 /* set DISPLAY_DE_B pin for dual rgb mode. */
1744 if (board_is_media())
1747 for (i = 0; i < f3_end; i++) {
1748 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1749 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1750 /* pull-up/down disable */
1751 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1752 /* drive strength to max (24bit) */
1753 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1754 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1756 /* display output path selection (only [1:0] valid) */
1757 writel(0x2, 0xE0107008);
1759 /* gpio pad configuration for LCD reset. */
1760 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1762 /* gpio pad configuration for LCD ON. */
1763 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1765 /* LCD_BACKLIGHT_EN */
1766 if (machine_is_geminus())
1767 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1768 if (board_is_neptune()) {
1769 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1770 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1774 * gpio pad configuration for
1775 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1777 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1778 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1779 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1780 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1782 if (machine_is_aquila() || machine_is_kessler()) {
1783 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1785 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1787 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1789 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1792 if (board_is_neptune())
1793 s6d16a0x_set_platform_data(&spi_pd);
1795 s6e63m0_set_platform_data(&spi_pd);
1796 if (board_is_media())
1801 if (machine_is_cypress()) {
1802 #if 0 /* universal cypress */
1804 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1807 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1809 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1811 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1813 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1815 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1816 #if 0 /* universal cypress */
1817 pd_cs.bank = &gpio_base->gpio_mp0_1;
1820 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1822 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1824 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1829 /* these data would be sent to s6e63m0 lcd panel driver. */
1830 s6e63m0_set_platform_data(&spi_pd);
1836 #define SWRST_REG 0x00
1837 #define LEDCON_REG 0x01
1838 #define LED_CUR_SET_REG 0x03
1839 #define LED_CUR_TR_REG 0x08
1842 #define NORMAL_MODE 0x01
1843 #define CUR_SET 0x63
1846 void backlight_on(unsigned int onoff)
1850 unsigned char val[2];
1851 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1854 if (machine_is_geminus())
1855 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1857 if (machine_is_geminus())
1858 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1861 if (board_is_neptune) {
1862 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1865 i2c_set_bus_num(I2C_GPIO5);
1868 if (i2c_probe(addr)) {
1869 if (i2c_probe(addr)) {
1870 printf("Can't found s6d16a0x backlight i2c\n");
1875 i2c_write(addr, SWRST_REG, 1, val, 1);
1878 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1880 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1881 val[0] = NORMAL_MODE;
1882 i2c_write(addr, LEDCON_REG, 1, val, 1);
1887 void reset_lcd(void)
1889 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1891 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1892 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1893 if (machine_is_cypress())
1894 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1897 void lcd_power_on(unsigned int onoff)
1899 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1902 if (machine_is_aquila() || machine_is_geminus())
1903 gpio_set_value(&gpio->gpio_j1, 3, 1);
1905 if (machine_is_cypress())
1906 gpio_set_value(&gpio->gpio_g2, 2, 1);
1908 if (machine_is_kessler()) {
1910 unsigned char val[2];
1911 unsigned char val2[2];
1913 gpio_set_value(&gpio->gpio_j1, 3, 1);
1915 i2c_set_bus_num(I2C_PMIC);
1916 addr = 0xCC >> 1; /* max8998 */
1917 if (i2c_probe(addr)) {
1918 printf("Can't found max8998\n");
1921 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1922 val[0] &= ~(MAX8998_LDO17);
1923 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1924 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1926 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1927 val[0] |= MAX8998_LDO17;
1929 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1930 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1932 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1933 val[0] |= MAX8998_LDO7;
1935 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1936 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1939 if (machine_is_aquila() || machine_is_geminus())
1940 gpio_set_value(&gpio->gpio_j1, 3, 0);
1942 if (machine_is_cypress())
1943 gpio_set_value(&gpio->gpio_g2, 2, 0);
1945 if (machine_is_kessler()) {
1947 unsigned char val[2];
1949 i2c_set_bus_num(I2C_PMIC);
1950 addr = 0xCC >> 1; /* max8998 */
1951 if (i2c_probe(addr)) {
1952 printf("Can't found max8998\n");
1956 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1957 val[0] &= ~(1 << 7);
1958 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1959 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1961 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1962 val[0] &= ~MAX8998_LDO17;
1963 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1964 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1969 extern void s6e63m0_cfg_ldo(void);
1970 extern void s6e63m0_enable_ldo(unsigned int onoff);
1971 extern void s6d16a0x_cfg_ldo(void);
1972 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1974 int s5p_no_lcd_support(void)
1976 if (machine_is_wmg160())
1981 void init_panel_info(vidinfo_t *vid)
1983 vid->cfg_gpio = NULL;
1984 vid->reset_lcd = NULL;
1985 vid->backlight_on = NULL;
1986 vid->lcd_power_on = NULL;
1988 vid->cfg_ldo = NULL;
1989 vid->enable_ldo = NULL;
1991 vid->init_delay = 0;
1992 vid->reset_delay = 0;
1993 vid->power_on_delay = 0;
1998 vid->vl_width = 480;
1999 vid->vl_height = 800;
2001 vid->dual_lcd_enabled = 0;
2003 if (board_is_media()) {
2006 vid->vl_width = 960;
2007 vid->vl_height = 800;
2009 /* enable dual lcd mode. */
2010 vid->dual_lcd_enabled = 1;
2013 vid->vl_clkp = CONFIG_SYS_HIGH;
2014 vid->vl_hsp = CONFIG_SYS_LOW;
2015 vid->vl_vsp = CONFIG_SYS_LOW;
2016 vid->vl_dp = CONFIG_SYS_HIGH;
2019 /* S6E63M0 LCD Panel */
2028 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
2029 vid->cfg_gpio = lcd_cfg_gpio;
2030 vid->reset_lcd = reset_lcd;
2031 vid->backlight_on = backlight_on;
2032 vid->lcd_power_on = lcd_power_on;
2033 vid->cfg_ldo = s6e63m0_cfg_ldo;
2034 vid->enable_ldo = s6e63m0_enable_ldo;
2036 vid->init_delay = 25000;
2037 vid->reset_delay = 120000;
2040 if (board_is_neptune()) {
2044 vid->vl_width = 320;
2045 vid->vl_height = 480;
2047 vid->vl_clkp = CONFIG_SYS_HIGH;
2048 vid->vl_hsp = CONFIG_SYS_HIGH;
2049 vid->vl_vsp = CONFIG_SYS_HIGH;
2050 vid->vl_dp = CONFIG_SYS_LOW;
2053 /* disable dual lcd mode. */
2054 vid->dual_lcd_enabled = 0;
2056 /* S6D16A0X LCD Panel */
2065 vid->cfg_gpio = lcd_cfg_gpio;
2066 vid->backlight_on = backlight_on;
2067 vid->lcd_power_on = lcd_power_on;
2068 vid->reset_lcd = reset_lcd;
2069 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2070 vid->enable_ldo = s6d16a0x_enable_ldo;
2072 vid->init_delay = 10000;
2073 vid->power_on_delay = 10000;
2074 vid->reset_delay = 1000;
2078 if (machine_is_geminus()) {
2082 vid->vl_width = 1024,
2083 vid->vl_height = 600,
2084 vid->vl_clkp = CONFIG_SYS_LOW,
2085 vid->vl_hsp = CONFIG_SYS_HIGH,
2086 vid->vl_vsp = CONFIG_SYS_HIGH,
2087 vid->vl_dp = CONFIG_SYS_LOW,
2098 vid->cfg_gpio = lcd_cfg_gpio;
2099 vid->reset_lcd = reset_lcd;
2100 vid->backlight_on = backlight_on;
2101 vid->lcd_power_on = lcd_power_on;
2107 vid->vl_width = 480,
2108 vid->vl_height = 800,
2109 vid->vl_clkp = CONFIG_SYS_HIGH,
2110 vid->vl_hsp = CONFIG_SYS_LOW,
2111 vid->vl_vsp = CONFIG_SYS_LOW,
2112 vid->vl_dp = CONFIG_SYS_HIGH,
2128 vid->vl_width = 1024,
2129 vid->vl_height = 600,
2130 vid->vl_clkp = CONFIG_SYS_HIGH,
2131 vid->vl_hsp = CONFIG_SYS_HIGH,
2132 vid->vl_vsp = CONFIG_SYS_HIGH,
2133 vid->vl_dp = CONFIG_SYS_LOW,
2136 /* AMS701KA AMOLED Panel. */
2148 static void setup_meminfo(void)
2150 char meminfo[64] = {0, };
2151 int count = 0, size, real;
2153 size = gd->bd->bi_dram[0].size >> 20;
2154 count += sprintf(meminfo + count, "mem=%dM", size);
2156 /* Each Chip Select can't exceed the 256MiB */
2157 size = gd->bd->bi_dram[1].size >> 20;
2158 real = min(size, 256);
2159 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2160 real, (unsigned int)gd->bd->bi_dram[1].start);
2164 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2165 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2168 setenv("meminfo", meminfo);
2171 int misc_init_r(void)
2174 /* It should be located at first */
2177 if (machine_is_aquila() || machine_is_kessler()) {
2178 if (board_is_neptune())
2179 setenv("lcdinfo", "lcd=s6d16a0x");
2180 else if (board_is_media())
2181 setenv("lcdinfo", "lcd=s6e63m0");
2183 setenv("lcdinfo", "lcd=s6e63m0");
2185 if (machine_is_geminus())
2186 setenv("lcdinfo", "lcd=lms480jc01");
2187 if (machine_is_cypress())
2188 setenv("lcdinfo", "lcd=s6e63m0");
2194 /* Set proper PMIC pins */
2197 /* Check auto burning */
2200 /* To power up I2C2 */
2203 /* Enable T-Flash at Limo Real or Limo Universal */
2206 /* Setup Limo Real board GPIOs */
2207 setup_limo_real_gpios();
2209 /* Setup Media board GPIOs */
2210 setup_media_gpios();
2212 /* To usbdown automatically */
2218 #ifdef CONFIG_S5PC1XXFB
2219 display_device_info();
2222 setup_power_down_mode_registers();
2224 /* check max17040 */
2234 int board_init(void)
2236 /* Set Initial global variables */
2237 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2239 gd->bd->bi_arch_number = MACH_AQUILA;
2240 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2242 /* Check H/W Revision */
2243 check_hw_revision();
2250 unsigned int base, memconfig0, size;
2251 unsigned int memconfig1, sz = 0;
2253 if (cpu_is_s5pc100()) {
2254 /* In mem setup, we swap the bank. So below size is correct */
2255 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2256 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2257 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2260 /* In S5PC110, we can't swap the DMC0/1 */
2261 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2262 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2264 base = S5PC110_DMC1_BASE;
2265 /* DMC configuration */
2266 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2267 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2269 size = (memconfig0 >> 16) & 0xFF;
2270 size = ((unsigned char) ~size) + 1;
2273 * (0x07 + 1) * 16 = 128 MiB
2274 * (0x0f + 1) * 16 = 256 MiB
2279 * Aquila Rev0.5 4G3G1G
2280 * Aquila Rev0.8 4G3G1G
2281 * Aquila Rev0.9 4G3G1G
2283 if (machine_is_aquila() || machine_is_kessler())
2284 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2285 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2287 sz = (memconfig1 >> 16) & 0xFF;
2288 sz = ((unsigned char) ~sz) + 1;
2294 * bi_dram[1].size contains all DMC1 memory size
2296 gd->bd->bi_dram[1].size = (size + sz) << 20;
2301 /* Used for sleep test */
2302 static unsigned char saved_val[4][2];
2303 void board_sleep_init_late(void)
2305 /* CODEC_LDO_EN: GPF3[4] */
2306 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2307 /* CODEC_XTAL_EN: GPH3[2] */
2308 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2310 /* MMC T_FLASH off */
2311 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2313 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2314 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2315 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2319 void board_sleep_init(void)
2322 unsigned char val[2];
2324 i2c_set_bus_num(I2C_PMIC);
2326 if (i2c_probe(addr)) {
2327 printf("Can't find max8998\n");
2331 if (machine_is_kessler()) {
2334 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2335 saved_val[0][0] = val[0];
2336 saved_val[0][1] = val[1];
2337 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2338 (1 << 1) | (1 << 0));
2339 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2340 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2342 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2343 saved_val[1][0] = val[0];
2344 saved_val[1][1] = val[1];
2345 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2346 (1 << 2) | (1 << 1) | (1 << 0));
2348 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2349 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2351 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2352 saved_val[2][0] = val[0];
2353 saved_val[2][1] = val[1];
2354 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2355 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2356 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2358 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2359 saved_val[3][0] = val[0];
2360 saved_val[3][1] = val[1];
2361 val[0] &= ~((1 << 6) | (1 << 4));
2362 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2363 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2364 printf("Turned off regulators with Kessler setting."
2365 " Preparing to sleep. [%s:%d]\n",
2366 __FILE__, __LINE__);
2367 } else { /* Default */
2370 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2371 saved_val[0][0] = val[0];
2372 saved_val[0][1] = val[1];
2373 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2374 (1 << 1) | (1 << 0));
2375 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2376 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2378 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2379 saved_val[1][0] = val[0];
2380 saved_val[1][1] = val[1];
2381 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2382 (1 << 2) | (1 << 1) | (1 << 0));
2384 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2385 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2387 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2388 saved_val[2][0] = val[0];
2389 saved_val[2][1] = val[1];
2390 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2391 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2392 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2394 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2395 saved_val[3][0] = val[0];
2396 saved_val[3][1] = val[1];
2397 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2398 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2400 printf("Turned off regulators with default(Aquila) setting."
2401 " Preparing to sleep. [%s:%d]\n",
2402 __FILE__, __LINE__);
2406 void board_sleep_resume(void)
2409 unsigned char val[2];
2413 i2c_set_bus_num(I2C_PMIC);
2415 if (i2c_probe(addr)) {
2416 printf("Can't find max8998\n");
2421 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2422 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2424 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2425 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2427 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2430 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2431 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2432 printf("Waked up.\n");
2434 /* check max17040 */
2441 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2443 static int s5pc1xx_phy_control(int on)
2447 if (on && !status) {
2448 // printf("turning USB power on\n");
2449 #ifdef CONFIG_CMD_PMIC
2450 run_command("pmic ldo 3 on", 0);
2453 if (board_is_limo_universal() ||
2454 board_is_limo_real() ||
2456 /* check usb path */
2457 if (board_is_limo_real() && !hwrevision(6))
2461 if (machine_is_tickertape())
2462 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2463 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2465 /* USB Path to AP */
2466 micro_usb_switch(0);
2468 } else if (!on && status) {
2469 // printf("turning USB power off\n");
2470 #ifdef CONFIG_CMD_PMIC
2471 run_command("pmic ldo 3 off", 0);
2480 struct s3c_plat_otg_data s5pc110_otg_data = {
2481 .phy_control = s5pc1xx_phy_control,
2482 .regs_phy = S5PC110_PHY_BASE,
2483 .regs_otg = S5PC110_OTG_BASE,
2486 int board_eth_init(bd_t *bis)
2490 if (cpu_is_s5pc100())
2493 s3c_udc_probe(&s5pc110_otg_data);
2494 if (usb_eth_initialize(bis) >= 0)
2500 #ifdef CONFIG_CMD_USBDOWN
2501 int usb_board_init(void)
2503 #ifdef CONFIG_CMD_PMIC
2504 run_command("pmic ldo 3 on", 0);
2507 if (cpu_is_s5pc100()) {
2508 #ifdef CONFIG_HARD_I2C
2509 uchar val[2] = {0,};
2512 if (i2c_read(0x66, 0, 1, val, 2)) {
2513 printf("i2c_read error\n");
2520 if (i2c_write(0x66, 0, 1, val, 2)) {
2521 printf("i2c_write error\n");
2524 i2c_read(0x66, 0, 1, val, 2);
2530 if (board_is_limo_universal() ||
2531 board_is_limo_real() ||
2533 /* check usb path */
2534 if (board_is_limo_real() && !hwrevision(6))
2538 if (machine_is_tickertape())
2539 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2540 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2542 /* USB Path to AP */
2543 micro_usb_switch(0);
2549 #ifdef CONFIG_GENERIC_MMC
2550 int s5p_no_mmc_support(void)
2552 if (machine_is_wmg160())
2557 int board_mmc_init(bd_t *bis)
2561 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2564 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2565 if (machine_is_kessler())
2566 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2568 if (machine_is_wmg160())
2571 /* MMC0 Clock source = SCLKMPLL */
2572 reg = readl(&clk->src4);
2575 writel(reg, &clk->src4);
2577 reg = readl(&clk->div4);
2580 /* set div value near 50MHz */
2581 clock = get_pll_clk(MPLL) / 1000000;
2582 for (i = 0; i < 0xf; i++) {
2583 if ((clock / (i + 1)) <= 50) {
2589 writel(reg, &clk->div4);
2595 * GPG0[2] SD_0_CDn -> Not used
2596 * GPG0[3:6] SD_0_DATA[0:3]
2598 for (i = 0; i < 7; i++) {
2601 /* GPG0[0:6] special function 2 */
2602 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2603 /* GPG0[0:6] pull disable */
2604 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2605 /* GPG0[0:6] drv 4x */
2606 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2609 return s5pc1xx_mmc_init(0);
2613 #ifdef CONFIG_CMD_PMIC
2614 static int pmic_status(void)
2616 unsigned char addr, val[2];
2619 i2c_set_bus_num(I2C_PMIC);
2621 if (i2c_probe(addr)) {
2622 printf("Can't found max8998\n");
2627 i2c_read(addr, reg, 1, val, 1);
2628 for (i = 7; i >= 4; i--)
2629 printf("BUCK%d %s\n", 7 - i + 1,
2630 val[0] & (1 << i) ? "on" : "off");
2632 printf("LDO%d %s\n", 5 - i,
2633 val[0] & (1 << i) ? "on" : "off");
2635 i2c_read(addr, reg, 1, val, 1);
2636 for (i = 7; i >= 0; i--)
2637 printf("LDO%d %s\n", 7 - i + 6,
2638 val[0] & (1 << i) ? "on" : "off");
2640 i2c_read(addr, reg, 1, val, 1);
2641 for (i = 7; i >= 4; i--)
2642 printf("LDO%d %s\n", 7 - i + 14,
2643 val[0] & (1 << i) ? "on" : "off");
2646 i2c_read(addr, reg, 1, val, 1);
2647 for (i = 7; i >= 6; i--)
2648 printf("SAFEOUT%d %s\n", 7 - i + 1,
2649 val[0] & (1 << i) ? "on" : "off");
2653 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2655 unsigned char addr, val[2];
2656 unsigned int reg, shift;
2664 } else if (ldo <= 13) {
2667 } else if (ldo <= 17) {
2669 shift = 17 - ldo + 4;
2676 shift = 4 - buck + 4;
2677 } else if (safeout) {
2681 shift = 8 - safeout;
2685 i2c_set_bus_num(I2C_PMIC);
2687 if (i2c_probe(addr)) {
2688 printf("Can't found max8998\n");
2692 i2c_read(addr, reg, 1, val, 1);
2694 val[0] |= (1 << shift);
2696 val[0] &= ~(1 << shift);
2697 i2c_write(addr, reg, 1, val, 1);
2698 i2c_read(addr, reg, 1, val, 1);
2701 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2702 val[0] & (1 << shift) ? "on" : "off");
2704 printf("buck %d value 0x%x, %s\n", buck, val[0],
2705 val[0] & (1 << shift) ? "on" : "off");
2707 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2708 val[0] & (1 << shift) ? "on" : "off");
2713 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2715 int buck = 0, ldo = 0, safeout = 0, on = -1;
2719 if (strncmp(argv[1], "status", 6) == 0)
2720 return pmic_status();
2723 if (strncmp(argv[1], "ldo", 3) == 0)
2724 ldo = simple_strtoul(argv[2], NULL, 10);
2725 else if (strncmp(argv[1], "buck", 4) == 0)
2726 buck = simple_strtoul(argv[2], NULL, 10);
2727 else if (strncmp(argv[1], "safeout", 7) == 0)
2728 safeout = simple_strtoul(argv[2], NULL, 10);
2732 if (strncmp(argv[3], "on", 2) == 0)
2734 else if (strncmp(argv[3], "off", 3) == 0)
2739 return pmic_ldo_control(buck, ldo, safeout, on);
2750 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2751 "PMIC LDO & BUCK control",
2752 "status - Display PMIC LDO & BUCK status\n"
2753 "pmic ldo num on/off - Turn on/off the LDO\n"
2754 "pmic buck num on/off - Turn on/off the BUCK\n"
2755 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2759 #ifdef CONFIG_CMD_DEVICE_POWER
2773 static void power_display_devices(void)
2775 printf("devices:\n");
2776 printf("\t%d - touch\n", POWER_TOUCH);
2777 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2778 printf("\t%d - LCD\n", POWER_LCD);
2779 printf("\t%d - Haptic\n", POWER_HAPTIC);
2780 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2781 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2782 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2783 printf("\t%d - HDMI\n", POWER_HDMI);
2786 static int power_hdmi(int on)
2788 /* HDMI_EN1: GPJ2[2] */
2789 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2790 /* MHL_ON: GPJ2[3] */
2791 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2795 static int power_bt_wifi(int on)
2797 /* WLAN_BT_EN: GPB[5] */
2798 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2802 static int power_fm_radio(int on)
2804 /* FM_BUS_nRST: GPJ2[5] */
2805 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2809 static int power_audio_codec(int on)
2811 /* CODEC_LDO_EN: GPF3[4] */
2812 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2813 /* CODEC_XTAL_EN: GPH3[2] */
2814 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2818 static int power_haptic(int on)
2820 /* HAPTIC_ON: GPJ1[1] */
2821 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2825 static int power_lcd(int on)
2827 /* MLCD_ON: GPJ1[3] */
2828 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2832 static int power_touch(int on)
2834 /* TOUCH_EN: GPG3[6] */
2835 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2839 static int power_3_touchkey(int on)
2842 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2843 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2844 if (board_rev & J1_B2_BOARD)
2845 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2847 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2849 /* 3_TOUCH_CE - GPJ2[6] */
2850 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2852 /* 3_TOUCH_CE - GPJ2[6] */
2853 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2858 unsigned char val[2];
2859 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2865 i2c_set_bus_num(I2C_GPIO10);
2867 /* Workaround to probe */
2868 if (i2c_probe(addr)) {
2869 if (i2c_probe(addr)) {
2870 printf("Can't found 3 touchkey\n");
2875 #define MCS5000_TK_HW_VERSION 0x06
2876 #define MCS5000_TK_FW_VERSION 0x0A
2877 #define MCS5000_TK_MI_VERSION 0x0B
2879 reg = MCS5000_TK_MI_VERSION;
2880 i2c_read(addr, reg, 1, val, 1);
2881 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2882 reg = MCS5000_TK_HW_VERSION;
2883 i2c_read(addr, reg, 1, val, 1);
2884 printf("H/W 0x%x, ", val[0]);
2885 reg = MCS5000_TK_FW_VERSION;
2886 i2c_read(addr, reg, 1, val, 1);
2887 printf("F/W 0x%x\n", val[0]);
2892 static int power_control(int device, int on)
2896 return power_touch(on);
2897 case POWER_3_TOUCHKEY:
2898 return power_3_touchkey(on);
2900 return power_lcd(on);
2902 return power_haptic(on);
2903 case POWER_AUDIO_CODEC:
2904 return power_audio_codec(on);
2905 case POWER_FM_RADIO:
2906 return power_fm_radio(on);
2908 return power_bt_wifi(on);
2910 return power_hdmi(on);
2912 printf("I don't know device %d\n", device);
2918 static int power_on(int on)
2921 power_3_touchkey(on);
2924 power_audio_codec(on);
2932 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2936 if (!machine_is_aquila() && !machine_is_kessler())
2941 if (strncmp(argv[1], "on", 2) == 0)
2943 if (strncmp(argv[1], "off", 3) == 0)
2947 device = simple_strtoul(argv[1], NULL, 10);
2951 if (strncmp(argv[2], "on", 2) == 0)
2953 else if (strncmp(argv[2], "off", 3) == 0)
2957 return power_control(device, on);
2963 power_display_devices();
2968 power, CONFIG_SYS_MAXARGS, 1, do_power,
2969 "Device Power Management control",
2970 "device on/off - Turn on/off the device\n"
2973 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2977 if (strncmp(argv[1], "cp", 2) == 0) {
2978 micro_usb_switch(1);
2979 pmic_ldo_control(0, 0, 2, 1);
2980 setenv("usb", "cp");
2981 } else if (strncmp(argv[1], "ap", 2) == 0) {
2982 micro_usb_switch(0);
2983 pmic_ldo_control(0, 0, 2, 0);
2984 setenv("usb", "ap");
2994 printf("USB Path is set to %s\n", getenv("usb"));
3000 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
3002 "cp - switch to CP\n"
3003 "microusb ap - switch to AP\n"