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()) {
877 if(row_state[1] & 0x2)
879 if (board_is_neptune()) {
880 /* home & volume down */
881 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
884 /* cam full shot & volume down */
885 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
888 } else if (machine_is_geminus())
889 /* volume down & home */
890 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
894 setenv("bootcmd", "usbdown");
897 static void check_battery(int mode)
899 unsigned char val[2];
900 unsigned char addr = 0x36; /* max17040 fuel gauge */
902 i2c_set_bus_num(I2C_GPIO3);
904 if (machine_is_aquila()) {
907 } else if (machine_is_kessler())
908 i2c_set_bus_num(I2C_GPIO7);
909 else if (machine_is_cypress()) {
910 i2c_set_bus_num(I2C_GPIO7);
911 } else if (machine_is_geminus()) {
913 i2c_set_bus_num(I2C_GPIO7);
917 if (i2c_probe(addr)) {
918 printf("Can't found max17040 fuel gauge\n");
922 /* mode 0: check mode / 1: enable mode */
926 i2c_write(addr, 0xfe, 1, val, 2);
928 i2c_read(addr, 0x04, 1, val, 1);
929 dprintf("battery:\t%d%%\n", val[0]);
930 battery_soc = val[0];
934 static void check_mhl(void)
936 unsigned char val[2];
937 unsigned char addr = 0x39; /* SIL9230 */
939 /* MHL Power enable */
940 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
941 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
943 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
944 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
946 /* 10ms required after reset */
950 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
952 i2c_set_bus_num(I2C_GPIO5);
955 if (i2c_probe(addr)) {
956 printf("Can't found MHL Chip\n");
962 * set to Normal operation
965 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
966 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
971 * 00 = MHL termination ON
972 * 11 = MHL termination OFF
975 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
976 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
979 #define CHARGER_ANIMATION_FRAME 6
980 static void max8998_clear_interrupt(void)
982 unsigned char addr, val[2];
983 i2c_set_bus_num(I2C_PMIC);
985 if (i2c_probe(addr)) {
986 printf("Can't found max8998\n");
990 i2c_read(addr, 0x00, 1, val, 1);
991 i2c_read(addr, 0x01, 1, val, 1);
992 i2c_read(addr, 0x02, 1, val, 1);
993 i2c_read(addr, 0x03, 1, val, 1);
996 static int max8998_power_key(void)
998 unsigned char addr, val[2];
999 i2c_set_bus_num(I2C_PMIC);
1001 if (i2c_probe(addr)) {
1002 printf("Can't found max8998\n");
1006 /* Accessing IRQ1 register */
1007 i2c_read(addr, 0x00, 1, val, 1);
1008 if (val[0] & (1 << 6))
1014 static int max8998_has_ext_power_source(void)
1016 unsigned char addr, val[2];
1017 i2c_set_bus_num(I2C_PMIC);
1019 if (i2c_probe(addr)) {
1020 printf("Can't found max8998\n");
1024 /* Accessing STATUS2 register */
1025 i2c_read(addr, 0x09, 1, val, 1);
1026 if (val[0] & (1 << 5))
1032 struct thermister_stat {
1037 static struct thermister_stat adc_to_temperature_data[] = {
1038 { .centigrade = -20, .adc = 1856, },
1039 { .centigrade = -15, .adc = 1799, },
1040 { .centigrade = -10, .adc = 1730, },
1041 { .centigrade = -5, .adc = 1649, },
1042 { .centigrade = 0, .adc = 1556, },
1043 { .centigrade = 5, .adc = 1454, },
1044 { .centigrade = 10, .adc = 1343, },
1045 { .centigrade = 15, .adc = 1227, },
1046 { .centigrade = 20, .adc = 1109, },
1047 { .centigrade = 25, .adc = 992, },
1048 { .centigrade = 30, .adc = 880, },
1049 { .centigrade = 35, .adc = 773, },
1050 { .centigrade = 40, .adc = 675, },
1051 { .centigrade = 45, .adc = 586, },
1052 { .centigrade = 50, .adc = 507, },
1053 { .centigrade = 55, .adc = 436, },
1054 { .centigrade = 58, .adc = 399, },
1055 { .centigrade = 63, .adc = 343, },
1056 { .centigrade = 65, .adc = 322, },
1060 #define USHRT_MAX 0xFFFFU
1062 static int adc_to_temperature_centigrade(unsigned short adc)
1066 /* low_*: Greatest Lower Bound,
1067 * * * * high_*: Smallest Upper Bound */
1068 int low_temp, high_temp;
1069 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1070 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1071 if (adc_to_temperature_data[i].adc <= adc &&
1072 adc_to_temperature_data[i].adc >= low_adc) {
1073 low_temp = adc_to_temperature_data[i].centigrade;
1074 low_adc = adc_to_temperature_data[i].adc;
1076 if (adc_to_temperature_data[i].adc >= adc &&
1077 adc_to_temperature_data[i].adc <= high_adc) {
1078 high_temp = adc_to_temperature_data[i].centigrade;
1079 high_adc = adc_to_temperature_data[i].adc;
1083 /* Linear approximation between cloest low and high,
1084 * which is the weighted average of the two. */
1086 /* The following equation is correct only when the two are different */
1087 if (low_adc == high_adc)
1089 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1090 return 20; /* The room temperature */
1093 if (high_adc == USHRT_MAX)
1095 approximation = low_temp * (adc - low_adc) +
1096 high_temp * (high_adc - adc);
1097 approximation /= high_adc - low_adc;
1098 return approximation;
1101 static unsigned short get_adc_value(int channel)
1103 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1104 unsigned short ret = 0;
1108 unsigned int loop = 0;
1110 if (machine_is_kessler())
1112 else if (machine_is_geminus())
1114 else if (machine_is_wmg160())
1116 else if (machine_is_cypress())
1118 else if (machine_is_tickertape())
1120 else if (machine_is_aquila())
1123 else if (machine_is_p1p2())
1127 sprintf(buf, "pmic ldo %d on", ldonum);
1128 run_command(buf, 0);
1129 writel(channel & 0xF, &adc->adcmux);
1130 writel((1 << 14) | (49 << 6), &adc->adccon);
1131 writel(1000 & 0xffff, &adc->adcdly);
1132 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1134 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1138 reg = readl(&adc->adccon);
1139 } while (!reg & (1 << 15) && loop++ < 1000);
1140 ret = readl(&adc->adcdat0) & 0xFFF;
1141 sprintf(buf, "pmic ldo %d off", ldonum);
1142 run_command(buf, 0);
1147 static int adc_get_average_ambient_temperature(void)
1149 if (machine_is_kessler()) {
1150 unsigned short min = USHRT_MAX;
1151 unsigned short max = 0;
1152 unsigned int sum = 0;
1153 unsigned int measured = 0;
1156 for (i = 0; i < 7; i++) {
1157 unsigned short measurement = get_adc_value(6);
1160 if (min > measurement)
1162 if (max < measurement)
1165 if (measured >= 3) {
1171 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1172 adc_to_temperature_centigrade(sum), sum);
1173 return adc_to_temperature_centigrade(sum);
1176 return 20; /* 20 Centigrade */
1179 enum temperature_level {
1187 static enum temperature_level temperature_check(void)
1189 int temp = adc_get_average_ambient_temperature();
1191 return _TEMP_TOO_LOW;
1193 return _TEMP_OK_LOW;
1195 return _TEMP_TOO_HIGH;
1197 return _TEMP_OK_HIGH;
1201 extern void lcd_display_clear(void);
1202 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1204 static void charger_en(int enable)
1210 unsigned char addr = 0xCC >> 1; /* max8998 */
1211 unsigned char val[2];
1213 i2c_set_bus_num(I2C_PMIC);
1214 if (i2c_probe(addr)) {
1215 printf("Can't found max8998 (%s:%d)\n", __func__, __LINE__);
1220 printf("Disable the charger.\n");
1221 i2c_read(addr, 0x0D, 1, val, 1);
1224 i2c_write(addr, 0x0D, 1, val, 1);
1226 i2c_read(addr, 0x0C, 1, val, 1);
1227 val[0] &= ~(0x7 << 0);
1228 val[0] &= ~(0x7 << 5);
1229 if (enable == 600) {
1230 val[0] |= 5; /* 600mA */
1231 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1232 } else { /* Assume 475 mA */
1234 val[0] |= 2; /* 475mA */
1235 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1237 i2c_write(addr, 0x0C, 1, val, 1);
1239 i2c_read(addr, 0x0D, 1, val, 1);
1241 i2c_write(addr, 0x0D, 1, val, 1);
1242 printf("Enable the charger @ %dmA\n", enable);
1246 void lcd_power_on(unsigned int onoff);
1248 static void into_charge_mode(void)
1254 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1255 unsigned int reg, wakeup_stat;
1256 int charger_speed = 600;
1258 max8998_clear_interrupt();
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();
1287 goto restore_screen;
1288 } else if (!max8998_has_ext_power_source()) {
1289 lcd_display_clear();
1290 goto restore_screen;
1297 /* Disable the display to prevent flickering */
1298 /* TODO: how to reenable the display later? */
1302 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1303 unsigned int org, org_ip3, org_tcfg0;
1304 enum temperature_level previous_state = _TEMP_OK;
1306 empty_device_info_buffer();
1307 if (max8998_power_key())
1309 else if (!max8998_has_ext_power_source())
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 /* EVT0: sleep 1, EVT1: sleep */
1335 if (cpu_is_s5pc110()) {
1336 char *name = "dummy";
1337 char *usage = "N/A";
1344 if (s5pc1xx_get_cpu_rev() == 0) {
1345 char *argv[] = {"1", "1"};
1346 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1348 char *argv[] = {"0", "0"};
1349 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1352 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1356 /* Check TEMP HIGH/LOW */
1357 switch (temperature_check()) {
1359 charger_en(charger_speed);
1360 previous_state = _TEMP_OK;
1364 previous_state = _TEMP_TOO_LOW;
1366 case _TEMP_TOO_HIGH:
1368 previous_state = _TEMP_TOO_HIGH;
1371 if (previous_state == _TEMP_TOO_LOW)
1375 charger_en(charger_speed);
1376 previous_state = _TEMP_OK;
1380 if (previous_state == _TEMP_TOO_HIGH)
1384 charger_en(charger_speed);
1385 previous_state = _TEMP_OK;
1390 writel(org, &rtc->rtccon);
1391 writel(org_tcfg0, 0xE2600000);
1392 writel(org_ip3, 0xE010046C);
1394 } while (wakeup_stat == 0x04); /* RTC TICK */
1397 /* TODO: Reenable logo display (not working yet) */
1399 drv_lcd_init_resume();
1402 static int fsa9480_probe(void)
1404 unsigned char addr = 0x25;
1406 if (cpu_is_s5pc100())
1409 if (board_is_limo_real()) {
1410 if (hwrevision(0) || hwrevision(1))
1414 i2c_set_bus_num(I2C_PMIC);
1416 if (machine_is_kessler())
1417 i2c_set_bus_num(I2C_GPIO6);
1418 else if (machine_is_cypress()) {
1419 i2c_set_bus_num(I2C_GPIO6);
1420 } else if (machine_is_geminus()) {
1422 i2c_set_bus_num(I2C_GPIO6);
1423 } else if (machine_is_wmg160())
1424 i2c_set_bus_num(I2C_GPIO6);
1426 if (i2c_probe(addr)) {
1427 printf("Can't found fsa9480\n");
1434 static void check_micro_usb(int intr)
1437 unsigned char val[2];
1438 static int started_charging_once = 0;
1441 if (fsa9480_probe())
1444 addr = 0x25; /* fsa9480 */
1446 /* Clear Interrupt */
1448 i2c_read(addr, 0x03, 1, val, 2);
1452 /* Read Device Type 1 */
1453 i2c_read(addr, 0x0a, 1, val, 1);
1455 #define FSA_DEV1_CHARGER (1 << 6)
1456 #define FSA_DEV1_UART (1 << 3)
1457 #define FSA_DEV1_USB (1 << 2)
1458 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1459 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1462 * If USB, use default 475mA
1463 * If Charger, use 600mA and go to charge mode
1465 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1466 started_charging_once = 1;
1468 /* If it's full, do not charge. */
1469 if (battery_soc < 100)
1474 else if (val[0] & FSA_DEV1_USB) {
1475 if (battery_soc < 100)
1476 charger_en(475); /* enable charger and keep booting */
1481 /* If Factory Mode is Boot ON-USB, go to download mode */
1482 i2c_read(addr, 0x07, 1, val, 1);
1484 #define FSA_ADC_FAC_USB_OFF 0x18
1485 #define FSA_ADC_FAC_USB_ON 0x19
1486 #define FSA_ADC_FAC_UART 0x1d
1488 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1489 setenv("bootcmd", "usbdown");
1491 path = getenv("usb");
1493 if (!strncmp(path, "cp", 2))
1494 run_command("microusb cp", 0);
1497 static void micro_usb_switch(int path)
1500 unsigned char val[2];
1502 if (fsa9480_probe())
1505 addr = 0x25; /* fsa9480 */
1508 val[0] = 0x90; /* VAUDIO */
1510 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1512 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1514 i2c_read(addr, 0x2, 1, val, 1);
1515 val[0] &= ~(1 << 2); /* Manual switching */
1516 i2c_write(addr, 0x2, 1, val, 1);
1519 #define MAX8998_REG_ONOFF1 0x11
1520 #define MAX8998_REG_ONOFF2 0x12
1521 #define MAX8998_REG_ONOFF3 0x13
1522 #define MAX8998_REG_LDO7 0x21
1523 #define MAX8998_REG_LDO17 0x29
1525 #define MAX8998_LDO3 (1 << 2)
1527 #define MAX8998_LDO6 (1 << 7)
1528 #define MAX8998_LDO7 (1 << 6)
1529 #define MAX8998_LDO8 (1 << 5)
1530 #define MAX8998_LDO9 (1 << 4)
1531 #define MAX8998_LDO10 (1 << 3)
1532 #define MAX8998_LDO11 (1 << 2)
1533 #define MAX8998_LDO12 (1 << 1)
1534 #define MAX8998_LDO13 (1 << 0)
1536 #define MAX8998_LDO14 (1 << 7)
1537 #define MAX8998_LDO15 (1 << 6)
1538 #define MAX8998_LDO16 (1 << 5)
1539 #define MAX8998_LDO17 (1 << 4)
1542 static void init_pmic(void)
1545 unsigned char val[2];
1547 if (cpu_is_s5pc100())
1550 i2c_set_bus_num(I2C_PMIC);
1552 addr = 0xCC >> 1; /* max8998 */
1553 if (i2c_probe(addr)) {
1554 printf("Can't found max8998\n");
1559 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1560 val[0] &= ~MAX8998_LDO3;
1561 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1564 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1566 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1567 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1569 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1570 MAX8998_LDO12 | MAX8998_LDO13);
1572 if (machine_is_kessler())
1573 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1575 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1576 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1578 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1580 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1581 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1583 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1584 MAX8998_LDO16 | MAX8998_LDO17);
1586 if (machine_is_kessler())
1587 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1589 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1590 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1593 static void setup_power_down_mode_registers(void)
1595 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1596 struct s5pc1xx_gpio_bank *bank;
1597 struct gpio_powermode *p;
1599 struct gpio_external *ge;
1601 struct s5pc1xx_gpio_item *mr;
1605 if (cpu_is_s5pc100())
1608 /* Only Limo real and kessler supports worked for sleep currnet */
1609 if (machine_is_aquila()) {
1610 if (board_is_limo_real())
1614 } else if (machine_is_kessler()) {
1616 } else if (machine_is_geminus()) {
1621 if (machine_is_aquila()) {
1622 /* Aquila rev 0.8 or lower */
1623 p = aquila_powerdown_modes;
1624 ge = aquila_external_powerdown_modes;
1625 mr = aquila_mirror_powerdown_mode;
1626 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1627 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1628 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1629 } else if (machine_is_kessler()) {
1630 /* Aquila rev 0.9 */
1631 p = kessler_powerdown_modes;
1632 ge = kessler_external_powerdown_modes;
1633 mr = kessler_mirror_powerdown_mode;
1634 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1635 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1636 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1637 } else if (machine_is_geminus()) {
1638 if (hwrevision(1)) {
1639 /* Same as Aquila rev 0.9 */
1641 p = kessler_powerdown_modes;
1642 ge = kessler_external_powerdown_modes;
1643 mr = kessler_mirror_powerdown_mode;
1644 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1645 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1646 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1648 p = aquila_powerdown_modes;
1649 ge = aquila_external_powerdown_modes;
1650 mr = aquila_mirror_powerdown_mode;
1651 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1652 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1653 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1655 } else if (hwrevision(0)) {
1656 /* Same as Aquila rev 0.8 or lower */
1657 p = aquila_powerdown_modes;
1658 ge = aquila_external_powerdown_modes;
1659 mr = aquila_mirror_powerdown_mode;
1660 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1661 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1662 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1664 return; /* Not supported */
1668 bank = &gpio->gpio_a0;
1670 for (i = 0; i < n_p; i++, p++, bank++) {
1671 writel(p->conpdn, &bank->pdn_con);
1672 writel(p->pudpdn, &bank->pdn_pull);
1675 writel(0xff0022b0, (unsigned int *)0xF0000000);
1676 writel(0xff0022b0, (unsigned int *)0xF1400000);
1678 bank = &gpio->gpio_h0;
1680 for (i = 0; i < n_ge; i++) {
1681 writel(ge->con, &bank->con);
1682 writel(ge->dat, &bank->dat);
1683 writel(ge->pud, &bank->pull);
1689 for (i = 0; i < n_mr; i++) {
1690 unsigned int reg = readl(&mr->bank->pdn_con);
1691 reg &= ~(1 << mr->number);
1692 if (readl(&mr->bank->dat) & (1 << mr->number))
1693 reg |= 1 << mr->number;
1694 writel(reg, &mr->bank->pdn_con);
1700 #include "../../../drivers/video/s5p-spi.h"
1702 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1703 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1705 struct spi_platform_data spi_pd;
1707 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1709 void lcd_cfg_gpio(void)
1711 unsigned int i, f3_end = 4;
1713 for (i = 0; i < 8; i++) {
1714 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1715 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1716 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1717 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1718 /* pull-up/down disable */
1719 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1720 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1721 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1723 /* drive strength to max (24bit) */
1724 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1725 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1726 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1727 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1728 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1729 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1732 /* set DISPLAY_DE_B pin for dual rgb mode. */
1733 if (board_is_media())
1736 for (i = 0; i < f3_end; i++) {
1737 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1738 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1739 /* pull-up/down disable */
1740 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1741 /* drive strength to max (24bit) */
1742 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1743 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1745 /* display output path selection (only [1:0] valid) */
1746 writel(0x2, 0xE0107008);
1748 /* gpio pad configuration for LCD reset. */
1749 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1751 /* gpio pad configuration for LCD ON. */
1752 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1754 /* LCD_BACKLIGHT_EN */
1755 if (machine_is_geminus())
1756 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1757 if (board_is_neptune()) {
1758 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1759 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1763 * gpio pad configuration for
1764 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1766 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1767 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1768 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1769 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1771 if (machine_is_aquila() || machine_is_kessler()) {
1772 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1774 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1776 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1778 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1781 if (board_is_neptune())
1782 s6d16a0x_set_platform_data(&spi_pd);
1784 s6e63m0_set_platform_data(&spi_pd);
1785 if (board_is_media())
1790 if (machine_is_cypress()) {
1791 #if 0 /* universal cypress */
1793 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1796 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1798 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1800 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1802 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1804 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1805 #if 0 /* universal cypress */
1806 pd_cs.bank = &gpio_base->gpio_mp0_1;
1809 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1811 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1813 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1818 /* these data would be sent to s6e63m0 lcd panel driver. */
1819 s6e63m0_set_platform_data(&spi_pd);
1825 #define SWRST_REG 0x00
1826 #define LEDCON_REG 0x01
1827 #define LED_CUR_SET_REG 0x03
1828 #define LED_CUR_TR_REG 0x08
1831 #define NORMAL_MODE 0x01
1832 #define CUR_SET 0x63
1835 void backlight_on(unsigned int onoff)
1839 unsigned char val[2];
1840 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1843 if (machine_is_geminus())
1844 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1846 if (machine_is_geminus())
1847 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1850 if (machine_is_kessler() && board_is_neptune()) {
1851 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1854 i2c_set_bus_num(I2C_GPIO5);
1857 if (i2c_probe(addr)) {
1858 if (i2c_probe(addr)) {
1859 printf("Can't found s6d16a0x backlight i2c\n");
1864 i2c_write(addr, SWRST_REG, 1, val, 1);
1867 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1869 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1870 val[0] = NORMAL_MODE;
1871 i2c_write(addr, LEDCON_REG, 1, val, 1);
1876 void reset_lcd(void)
1878 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1880 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1881 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1882 if (machine_is_cypress())
1883 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1886 void lcd_power_on(unsigned int onoff)
1888 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1891 if (machine_is_aquila() || machine_is_geminus())
1892 gpio_set_value(&gpio->gpio_j1, 3, 1);
1894 if (machine_is_cypress())
1895 gpio_set_value(&gpio->gpio_g2, 2, 1);
1897 if (machine_is_kessler()) {
1899 unsigned char val[2];
1900 unsigned char val2[2];
1902 gpio_set_value(&gpio->gpio_j1, 3, 1);
1904 i2c_set_bus_num(I2C_PMIC);
1905 addr = 0xCC >> 1; /* max8998 */
1906 if (i2c_probe(addr)) {
1907 printf("Can't found max8998\n");
1910 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1911 val[0] &= ~(MAX8998_LDO17);
1912 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1913 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1915 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1916 val[0] |= MAX8998_LDO17;
1918 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1919 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1921 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1922 val[0] |= MAX8998_LDO7;
1924 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1925 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1928 if (machine_is_aquila() || machine_is_geminus())
1929 gpio_set_value(&gpio->gpio_j1, 3, 0);
1931 if (machine_is_cypress())
1932 gpio_set_value(&gpio->gpio_g2, 2, 0);
1934 if (machine_is_kessler()) {
1936 unsigned char val[2];
1938 gpio_set_value(&gpio->gpio_j1, 3, 0);
1940 i2c_set_bus_num(I2C_PMIC);
1941 addr = 0xCC >> 1; /* max8998 */
1942 if (i2c_probe(addr)) {
1943 printf("Can't found max8998\n");
1947 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1948 val[0] &= ~(MAX8998_LDO7);
1949 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1950 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1952 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1953 val[0] &= ~(MAX8998_LDO17);
1954 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1955 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1960 extern void s6e63m0_cfg_ldo(void);
1961 extern void s6e63m0_enable_ldo(unsigned int onoff);
1962 extern void s6d16a0x_cfg_ldo(void);
1963 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1965 int s5p_no_lcd_support(void)
1967 if (machine_is_wmg160())
1972 void init_panel_info(vidinfo_t *vid)
1974 vid->cfg_gpio = NULL;
1975 vid->reset_lcd = NULL;
1976 vid->backlight_on = NULL;
1977 vid->lcd_power_on = NULL;
1979 vid->cfg_ldo = NULL;
1980 vid->enable_ldo = NULL;
1982 vid->init_delay = 0;
1983 vid->reset_delay = 0;
1984 vid->power_on_delay = 0;
1989 vid->vl_width = 480;
1990 vid->vl_height = 800;
1992 vid->dual_lcd_enabled = 0;
1994 if (board_is_media()) {
1997 vid->vl_width = 960;
1998 vid->vl_height = 800;
2000 /* enable dual lcd mode. */
2001 vid->dual_lcd_enabled = 1;
2004 vid->vl_clkp = CONFIG_SYS_HIGH;
2005 vid->vl_hsp = CONFIG_SYS_LOW;
2006 vid->vl_vsp = CONFIG_SYS_LOW;
2007 vid->vl_dp = CONFIG_SYS_HIGH;
2010 /* S6E63M0 LCD Panel */
2019 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
2020 vid->cfg_gpio = lcd_cfg_gpio;
2021 vid->reset_lcd = reset_lcd;
2022 vid->backlight_on = backlight_on;
2023 vid->lcd_power_on = lcd_power_on;
2024 vid->cfg_ldo = s6e63m0_cfg_ldo;
2025 vid->enable_ldo = s6e63m0_enable_ldo;
2027 vid->init_delay = 25000;
2028 vid->reset_delay = 120000;
2031 if (board_is_neptune()) {
2035 vid->vl_width = 320;
2036 vid->vl_height = 480;
2038 vid->vl_clkp = CONFIG_SYS_HIGH;
2039 vid->vl_hsp = CONFIG_SYS_HIGH;
2040 vid->vl_vsp = CONFIG_SYS_HIGH;
2041 vid->vl_dp = CONFIG_SYS_LOW;
2044 /* disable dual lcd mode. */
2045 vid->dual_lcd_enabled = 0;
2047 /* S6D16A0X LCD Panel */
2056 vid->cfg_gpio = lcd_cfg_gpio;
2057 vid->backlight_on = backlight_on;
2058 vid->lcd_power_on = lcd_power_on;
2059 vid->reset_lcd = reset_lcd;
2060 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2061 vid->enable_ldo = s6d16a0x_enable_ldo;
2063 vid->init_delay = 10000;
2064 vid->power_on_delay = 10000;
2065 vid->reset_delay = 1000;
2069 if (machine_is_geminus()) {
2073 vid->vl_width = 1024,
2074 vid->vl_height = 600,
2075 vid->vl_clkp = CONFIG_SYS_LOW,
2076 vid->vl_hsp = CONFIG_SYS_HIGH,
2077 vid->vl_vsp = CONFIG_SYS_HIGH,
2078 vid->vl_dp = CONFIG_SYS_LOW,
2089 vid->cfg_gpio = lcd_cfg_gpio;
2090 vid->reset_lcd = reset_lcd;
2091 vid->backlight_on = backlight_on;
2092 vid->lcd_power_on = lcd_power_on;
2098 vid->vl_width = 480,
2099 vid->vl_height = 800,
2100 vid->vl_clkp = CONFIG_SYS_HIGH,
2101 vid->vl_hsp = CONFIG_SYS_LOW,
2102 vid->vl_vsp = CONFIG_SYS_LOW,
2103 vid->vl_dp = CONFIG_SYS_HIGH,
2119 vid->vl_width = 1024,
2120 vid->vl_height = 600,
2121 vid->vl_clkp = CONFIG_SYS_HIGH,
2122 vid->vl_hsp = CONFIG_SYS_HIGH,
2123 vid->vl_vsp = CONFIG_SYS_HIGH,
2124 vid->vl_dp = CONFIG_SYS_LOW,
2127 /* AMS701KA AMOLED Panel. */
2139 static void setup_meminfo(void)
2141 char meminfo[64] = {0, };
2142 int count = 0, size, real;
2144 size = gd->bd->bi_dram[0].size >> 20;
2145 count += sprintf(meminfo + count, "mem=%dM", size);
2147 /* Each Chip Select can't exceed the 256MiB */
2148 size = gd->bd->bi_dram[1].size >> 20;
2149 real = min(size, 256);
2150 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2151 real, (unsigned int)gd->bd->bi_dram[1].start);
2155 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2156 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2159 setenv("meminfo", meminfo);
2162 int misc_init_r(void)
2165 /* It should be located at first */
2168 if (machine_is_aquila() || machine_is_kessler()) {
2169 if (board_is_neptune())
2170 setenv("lcdinfo", "lcd=s6d16a0x");
2171 else if (board_is_media())
2172 setenv("lcdinfo", "lcd=s6e63m0");
2174 setenv("lcdinfo", "lcd=s6e63m0");
2176 if (machine_is_geminus())
2177 setenv("lcdinfo", "lcd=lms480jc01");
2178 if (machine_is_cypress())
2179 setenv("lcdinfo", "lcd=s6e63m0");
2185 /* Set proper PMIC pins */
2188 /* Check auto burning */
2191 /* To power up I2C2 */
2194 /* Enable T-Flash at Limo Real or Limo Universal */
2197 /* Setup Limo Real board GPIOs */
2198 setup_limo_real_gpios();
2200 /* Setup Media board GPIOs */
2201 setup_media_gpios();
2203 /* To usbdown automatically */
2209 #ifdef CONFIG_S5PC1XXFB
2210 display_device_info();
2213 setup_power_down_mode_registers();
2215 /* check max17040 */
2225 int board_init(void)
2227 /* Set Initial global variables */
2228 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2230 gd->bd->bi_arch_number = MACH_AQUILA;
2231 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2233 /* Check H/W Revision */
2234 check_hw_revision();
2241 unsigned int base, memconfig0, size;
2242 unsigned int memconfig1, sz = 0;
2244 if (cpu_is_s5pc100()) {
2245 /* In mem setup, we swap the bank. So below size is correct */
2246 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2247 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2248 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2251 /* In S5PC110, we can't swap the DMC0/1 */
2252 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2253 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2255 base = S5PC110_DMC1_BASE;
2256 /* DMC configuration */
2257 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2258 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2260 size = (memconfig0 >> 16) & 0xFF;
2261 size = ((unsigned char) ~size) + 1;
2264 * (0x07 + 1) * 16 = 128 MiB
2265 * (0x0f + 1) * 16 = 256 MiB
2270 * Aquila Rev0.5 4G3G1G
2271 * Aquila Rev0.8 4G3G1G
2272 * Aquila Rev0.9 4G3G1G
2274 if (machine_is_aquila() || machine_is_kessler())
2275 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2276 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2278 sz = (memconfig1 >> 16) & 0xFF;
2279 sz = ((unsigned char) ~sz) + 1;
2285 * bi_dram[1].size contains all DMC1 memory size
2287 gd->bd->bi_dram[1].size = (size + sz) << 20;
2292 /* Used for sleep test */
2293 static unsigned char saved_val[4][2];
2294 void board_sleep_init_late(void)
2296 /* CODEC_LDO_EN: GPF3[4] */
2297 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2298 /* CODEC_XTAL_EN: GPH3[2] */
2299 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2301 /* MMC T_FLASH off */
2302 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2304 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2305 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2306 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2310 void board_sleep_init(void)
2313 unsigned char val[2];
2315 i2c_set_bus_num(I2C_PMIC);
2317 if (i2c_probe(addr)) {
2318 printf("Can't find max8998\n");
2322 if (machine_is_kessler()) {
2325 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2326 saved_val[0][0] = val[0];
2327 saved_val[0][1] = val[1];
2328 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2329 (1 << 1) | (1 << 0));
2330 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2331 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2333 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2334 saved_val[1][0] = val[0];
2335 saved_val[1][1] = val[1];
2336 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2337 (1 << 2) | (1 << 1) | (1 << 0));
2339 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2340 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2342 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2343 saved_val[2][0] = val[0];
2344 saved_val[2][1] = val[1];
2345 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2346 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2347 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2349 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2350 saved_val[3][0] = val[0];
2351 saved_val[3][1] = val[1];
2352 val[0] &= ~((1 << 6) | (1 << 4));
2353 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2354 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2355 printf("Turned off regulators with Kessler setting."
2356 " Preparing to sleep. [%s:%d]\n",
2357 __FILE__, __LINE__);
2358 } else { /* Default */
2361 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2362 saved_val[0][0] = val[0];
2363 saved_val[0][1] = val[1];
2364 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2365 (1 << 1) | (1 << 0));
2366 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2367 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2369 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2370 saved_val[1][0] = val[0];
2371 saved_val[1][1] = val[1];
2372 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2373 (1 << 2) | (1 << 1) | (1 << 0));
2375 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2376 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2378 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2379 saved_val[2][0] = val[0];
2380 saved_val[2][1] = val[1];
2381 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2382 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2383 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2385 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2386 saved_val[3][0] = val[0];
2387 saved_val[3][1] = val[1];
2388 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2389 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2390 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2391 printf("Turned off regulators with default(Aquila) setting."
2392 " Preparing to sleep. [%s:%d]\n",
2393 __FILE__, __LINE__);
2397 void board_sleep_resume(void)
2400 unsigned char val[2];
2404 i2c_set_bus_num(I2C_PMIC);
2406 if (i2c_probe(addr)) {
2407 printf("Can't find max8998\n");
2412 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2413 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2415 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2416 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2418 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2419 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2421 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2422 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2423 printf("Waked up.\n");
2425 /* check max17040 */
2432 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2434 static int s5pc1xx_phy_control(int on)
2438 if (on && !status) {
2439 // printf("turning USB power on\n");
2440 #ifdef CONFIG_CMD_PMIC
2441 run_command("pmic ldo 3 on", 0);
2444 if (board_is_limo_universal() ||
2445 board_is_limo_real() ||
2447 /* check usb path */
2448 if (board_is_limo_real() && !hwrevision(6))
2452 if (machine_is_tickertape())
2453 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2454 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2456 /* USB Path to AP */
2457 micro_usb_switch(0);
2459 } else if (!on && status) {
2460 // printf("turning USB power off\n");
2461 #ifdef CONFIG_CMD_PMIC
2462 run_command("pmic ldo 3 off", 0);
2471 struct s3c_plat_otg_data s5pc110_otg_data = {
2472 .phy_control = s5pc1xx_phy_control,
2473 .regs_phy = S5PC110_PHY_BASE,
2474 .regs_otg = S5PC110_OTG_BASE,
2477 int board_eth_init(bd_t *bis)
2481 if (cpu_is_s5pc100())
2484 s3c_udc_probe(&s5pc110_otg_data);
2485 if (usb_eth_initialize(bis) >= 0)
2491 #ifdef CONFIG_CMD_USBDOWN
2492 int usb_board_init(void)
2494 #ifdef CONFIG_CMD_PMIC
2495 run_command("pmic ldo 3 on", 0);
2498 if (cpu_is_s5pc100()) {
2499 #ifdef CONFIG_HARD_I2C
2500 uchar val[2] = {0,};
2503 if (i2c_read(0x66, 0, 1, val, 2)) {
2504 printf("i2c_read error\n");
2511 if (i2c_write(0x66, 0, 1, val, 2)) {
2512 printf("i2c_write error\n");
2515 i2c_read(0x66, 0, 1, val, 2);
2521 if (board_is_limo_universal() ||
2522 board_is_limo_real() ||
2524 /* check usb path */
2525 if (board_is_limo_real() && !hwrevision(6))
2529 if (machine_is_tickertape())
2530 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2531 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2533 /* USB Path to AP */
2534 micro_usb_switch(0);
2540 #ifdef CONFIG_GENERIC_MMC
2541 int s5p_no_mmc_support(void)
2543 if (machine_is_wmg160())
2548 int board_mmc_init(bd_t *bis)
2552 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2555 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2556 if (machine_is_kessler())
2557 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2559 if (machine_is_wmg160())
2562 /* MMC0 Clock source = SCLKMPLL */
2563 reg = readl(&clk->src4);
2566 writel(reg, &clk->src4);
2568 reg = readl(&clk->div4);
2571 /* set div value near 50MHz */
2572 clock = get_pll_clk(MPLL) / 1000000;
2573 for (i = 0; i < 0xf; i++) {
2574 if ((clock / (i + 1)) <= 50) {
2580 writel(reg, &clk->div4);
2586 * GPG0[2] SD_0_CDn -> Not used
2587 * GPG0[3:6] SD_0_DATA[0:3]
2589 for (i = 0; i < 7; i++) {
2592 /* GPG0[0:6] special function 2 */
2593 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2594 /* GPG0[0:6] pull disable */
2595 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2596 /* GPG0[0:6] drv 4x */
2597 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2600 return s5pc1xx_mmc_init(0);
2604 #ifdef CONFIG_CMD_PMIC
2605 static int pmic_status(void)
2607 unsigned char addr, val[2];
2610 i2c_set_bus_num(I2C_PMIC);
2612 if (i2c_probe(addr)) {
2613 printf("Can't found max8998\n");
2618 i2c_read(addr, reg, 1, val, 1);
2619 for (i = 7; i >= 4; i--)
2620 printf("BUCK%d %s\n", 7 - i + 1,
2621 val[0] & (1 << i) ? "on" : "off");
2623 printf("LDO%d %s\n", 5 - i,
2624 val[0] & (1 << i) ? "on" : "off");
2626 i2c_read(addr, reg, 1, val, 1);
2627 for (i = 7; i >= 0; i--)
2628 printf("LDO%d %s\n", 7 - i + 6,
2629 val[0] & (1 << i) ? "on" : "off");
2631 i2c_read(addr, reg, 1, val, 1);
2632 for (i = 7; i >= 4; i--)
2633 printf("LDO%d %s\n", 7 - i + 14,
2634 val[0] & (1 << i) ? "on" : "off");
2637 i2c_read(addr, reg, 1, val, 1);
2638 for (i = 7; i >= 6; i--)
2639 printf("SAFEOUT%d %s\n", 7 - i + 1,
2640 val[0] & (1 << i) ? "on" : "off");
2644 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2646 unsigned char addr, val[2];
2647 unsigned int reg, shift;
2655 } else if (ldo <= 13) {
2658 } else if (ldo <= 17) {
2660 shift = 17 - ldo + 4;
2667 shift = 4 - buck + 4;
2668 } else if (safeout) {
2672 shift = 8 - safeout;
2676 i2c_set_bus_num(I2C_PMIC);
2678 if (i2c_probe(addr)) {
2679 printf("Can't found max8998\n");
2683 i2c_read(addr, reg, 1, val, 1);
2685 val[0] |= (1 << shift);
2687 val[0] &= ~(1 << shift);
2688 i2c_write(addr, reg, 1, val, 1);
2689 i2c_read(addr, reg, 1, val, 1);
2692 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2693 val[0] & (1 << shift) ? "on" : "off");
2695 printf("buck %d value 0x%x, %s\n", buck, val[0],
2696 val[0] & (1 << shift) ? "on" : "off");
2698 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2699 val[0] & (1 << shift) ? "on" : "off");
2704 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2706 int buck = 0, ldo = 0, safeout = 0, on = -1;
2710 if (strncmp(argv[1], "status", 6) == 0)
2711 return pmic_status();
2714 if (strncmp(argv[1], "ldo", 3) == 0)
2715 ldo = simple_strtoul(argv[2], NULL, 10);
2716 else if (strncmp(argv[1], "buck", 4) == 0)
2717 buck = simple_strtoul(argv[2], NULL, 10);
2718 else if (strncmp(argv[1], "safeout", 7) == 0)
2719 safeout = simple_strtoul(argv[2], NULL, 10);
2723 if (strncmp(argv[3], "on", 2) == 0)
2725 else if (strncmp(argv[3], "off", 3) == 0)
2730 return pmic_ldo_control(buck, ldo, safeout, on);
2741 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2742 "PMIC LDO & BUCK control",
2743 "status - Display PMIC LDO & BUCK status\n"
2744 "pmic ldo num on/off - Turn on/off the LDO\n"
2745 "pmic buck num on/off - Turn on/off the BUCK\n"
2746 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2750 #ifdef CONFIG_CMD_DEVICE_POWER
2764 static void power_display_devices(void)
2766 printf("devices:\n");
2767 printf("\t%d - touch\n", POWER_TOUCH);
2768 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2769 printf("\t%d - LCD\n", POWER_LCD);
2770 printf("\t%d - Haptic\n", POWER_HAPTIC);
2771 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2772 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2773 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2774 printf("\t%d - HDMI\n", POWER_HDMI);
2777 static int power_hdmi(int on)
2779 /* HDMI_EN1: GPJ2[2] */
2780 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2781 /* MHL_ON: GPJ2[3] */
2782 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2786 static int power_bt_wifi(int on)
2788 /* WLAN_BT_EN: GPB[5] */
2789 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2793 static int power_fm_radio(int on)
2795 /* FM_BUS_nRST: GPJ2[5] */
2796 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2800 static int power_audio_codec(int on)
2802 /* CODEC_LDO_EN: GPF3[4] */
2803 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2804 /* CODEC_XTAL_EN: GPH3[2] */
2805 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2809 static int power_haptic(int on)
2811 /* HAPTIC_ON: GPJ1[1] */
2812 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2816 static int power_lcd(int on)
2818 /* MLCD_ON: GPJ1[3] */
2819 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2823 static int power_touch(int on)
2825 /* TOUCH_EN: GPG3[6] */
2826 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2830 static int power_3_touchkey(int on)
2833 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2834 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2835 if (board_rev & J1_B2_BOARD)
2836 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2838 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2840 /* 3_TOUCH_CE - GPJ2[6] */
2841 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2843 /* 3_TOUCH_CE - GPJ2[6] */
2844 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2849 unsigned char val[2];
2850 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2856 i2c_set_bus_num(I2C_GPIO10);
2858 /* Workaround to probe */
2859 if (i2c_probe(addr)) {
2860 if (i2c_probe(addr)) {
2861 printf("Can't found 3 touchkey\n");
2866 #define MCS5000_TK_HW_VERSION 0x06
2867 #define MCS5000_TK_FW_VERSION 0x0A
2868 #define MCS5000_TK_MI_VERSION 0x0B
2870 reg = MCS5000_TK_MI_VERSION;
2871 i2c_read(addr, reg, 1, val, 1);
2872 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2873 reg = MCS5000_TK_HW_VERSION;
2874 i2c_read(addr, reg, 1, val, 1);
2875 printf("H/W 0x%x, ", val[0]);
2876 reg = MCS5000_TK_FW_VERSION;
2877 i2c_read(addr, reg, 1, val, 1);
2878 printf("F/W 0x%x\n", val[0]);
2883 static int power_control(int device, int on)
2887 return power_touch(on);
2888 case POWER_3_TOUCHKEY:
2889 return power_3_touchkey(on);
2891 return power_lcd(on);
2893 return power_haptic(on);
2894 case POWER_AUDIO_CODEC:
2895 return power_audio_codec(on);
2896 case POWER_FM_RADIO:
2897 return power_fm_radio(on);
2899 return power_bt_wifi(on);
2901 return power_hdmi(on);
2903 printf("I don't know device %d\n", device);
2909 static int power_on(int on)
2912 power_3_touchkey(on);
2915 power_audio_codec(on);
2923 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2927 if (!machine_is_aquila() && !machine_is_kessler())
2932 if (strncmp(argv[1], "on", 2) == 0)
2934 if (strncmp(argv[1], "off", 3) == 0)
2938 device = simple_strtoul(argv[1], NULL, 10);
2942 if (strncmp(argv[2], "on", 2) == 0)
2944 else if (strncmp(argv[2], "off", 3) == 0)
2948 return power_control(device, on);
2954 power_display_devices();
2959 power, CONFIG_SYS_MAXARGS, 1, do_power,
2960 "Device Power Management control",
2961 "device on/off - Turn on/off the device\n"
2964 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2968 if (strncmp(argv[1], "cp", 2) == 0) {
2969 micro_usb_switch(1);
2970 pmic_ldo_control(0, 0, 2, 1);
2971 setenv("usb", "cp");
2972 } else if (strncmp(argv[1], "ap", 2) == 0) {
2973 micro_usb_switch(0);
2974 pmic_ldo_control(0, 0, 2, 0);
2975 setenv("usb", "ap");
2985 printf("USB Path is set to %s\n", getenv("usb"));
2991 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2993 "cp - switch to CP\n"
2994 "microusb ap - switch to AP\n"