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/errno.h>
42 #include <bmp_layout.h>
44 #include "animation_frames.h"
45 #include "gpio_setting.h"
47 DECLARE_GLOBAL_DATA_PTR;
49 #define C100_MACH_START 3000
50 #define C110_MACH_START 3100
52 static unsigned int board_rev;
53 static unsigned int battery_soc;
54 static struct s5pc110_gpio *s5pc110_gpio;
71 static struct i2c_gpio_bus_data i2c_2 = {
81 static struct i2c_gpio_bus_data i2c_gpio3 = {
91 static struct i2c_gpio_bus_data i2c_pmic = {
101 static struct i2c_gpio_bus_data i2c_gpio5 = {
111 static struct i2c_gpio_bus_data i2c_gpio6 = {
117 * i2c gpio7 - kessler
121 static struct i2c_gpio_bus_data i2c_gpio7 = {
127 * i2c gpio7 - cypress
131 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
141 static struct i2c_gpio_bus_data i2c_gpio10 = {
147 static struct i2c_gpio_bus i2c_gpio[] = {
165 u32 get_board_rev(void)
170 static int hwrevision(int rev)
172 return (board_rev & 0xf) == rev;
179 MACH_P1P2, /* Don't remove it */
190 #define SPLIT_SCREEN_FEATURE 0x100
192 /* board is MACH_AQUILA and board is like below. */
193 #define J1_B2_BOARD 0x0200
194 #define LIMO_UNIVERSAL_BOARD 0x0400
195 #define LIMO_REAL_BOARD 0x0800
196 #define MEDIA_BOARD 0x1000
197 #define BAMBOO_BOARD 0x2000
199 /* board is MACH_KESSLER and board is like below */
200 #define ARIES_BOARD 0x4000
201 #define NEPTUNE_BOARD 0x8000
203 #define BOARD_MASK 0xFF00
205 static int c110_machine_id(void)
207 return gd->bd->bi_arch_number - C110_MACH_START;
210 static int machine_is_aquila(void)
212 return (gd->bd->bi_arch_number == MACH_AQUILA);
215 static int machine_is_tickertape(void)
217 return c110_machine_id() == MACH_TICKERTAPE;
220 static int machine_is_geminus(void)
222 return c110_machine_id() == MACH_GEMINUS;
225 static int machine_is_cypress(void)
227 return c110_machine_id() == MACH_CYPRESS;
230 static int board_is_limo_universal(void)
232 return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
235 static int board_is_limo_real(void)
237 return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
240 static int board_is_media(void)
242 return machine_is_aquila() && (board_rev & MEDIA_BOARD);
245 static int board_is_j1b2(void)
247 return machine_is_aquila() && (board_rev & J1_B2_BOARD);
251 static int machine_is_kessler(void)
253 return gd->bd->bi_arch_number == MACH_KESSLER;
256 static int board_is_neptune(void)
258 return machine_is_kessler() && (board_rev & NEPTUNE_BOARD);
262 static int machine_is_wmg160(void)
264 return c110_machine_id() == MACH_WMG160;
267 static void enable_battery(void);
269 void i2c_init_board(void)
271 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
274 if (cpu_is_s5pc100())
277 num_bus = ARRAY_SIZE(i2c_gpio);
279 if (machine_is_aquila()) {
280 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
281 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
282 } else if (machine_is_kessler()) {
283 i2c_gpio[I2C_GPIO7].bus->gpio_base =
284 (unsigned int)&gpio->gpio_mp0_5;
285 } else if (machine_is_cypress()) {
286 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
287 i2c_gpio[I2C_GPIO7].bus->gpio_base =
288 (unsigned int)&gpio->gpio_mp0_5;
290 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
293 i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
294 i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
295 i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
296 i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
297 i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
299 i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
301 /* Reset on max17040 early */
302 if (battery_soc == 0)
306 #ifdef CONFIG_MISC_INIT_R
307 #define DEV_INFO_LEN 512
308 static char device_info[DEV_INFO_LEN];
309 static int display_info;
311 static void empty_device_info_buffer(void)
313 memset(device_info, 0x0, DEV_INFO_LEN);
316 static void dprintf(const char *fmt, ...)
323 i = vsprintf(buf, fmt, args);
328 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
329 puts("Flushing device info...\n");
331 empty_device_info_buffer();
333 strcat(device_info, buf);
337 #ifdef CONFIG_S5PC1XXFB
338 static void display_device_info(void)
345 set_font_color(FONT_WHITE);
346 fb_printf(device_info);
349 memset(device_info, 0x0, DEV_INFO_LEN);
351 udelay(5 * 1000 * 1000);
355 static const char *board_name[] = {
359 "P1P2", /* Don't remove it */
372 static char feature_buffer[32];
374 static char *display_features(int board, int board_rev)
377 char *buf = feature_buffer;
380 if (board == MACH_AQUILA) {
381 if (board_rev & SPLIT_SCREEN_FEATURE)
382 name = "SplitScreen";
383 if (board_rev & J1_B2_BOARD)
385 /* Limo Real or Universal */
386 if (board_rev & LIMO_REAL_BOARD)
388 else if (board_rev & LIMO_UNIVERSAL_BOARD)
389 name = "Limo Universal";
390 if (board_rev & MEDIA_BOARD)
392 if (board_rev & BAMBOO_BOARD)
394 } else if (board == MACH_KESSLER) {
395 if (board_rev & ARIES_BOARD)
397 if (board_rev & NEPTUNE_BOARD)
401 count += sprintf(buf + count, " - %s", name);
406 static char *get_board_name(int board)
408 if (board == MACH_AQUILA)
410 else if (board == MACH_KESSLER)
412 else if (board == MACH_WMG160)
414 return (char *) board_name[board];
417 static void check_board_revision(int board, int rev)
419 if (board == MACH_AQUILA) {
420 /* Limo Real or Universal */
421 if (rev & LIMO_UNIVERSAL_BOARD)
422 board_rev &= ~J1_B2_BOARD;
423 if (rev & LIMO_REAL_BOARD)
424 board_rev &= ~(J1_B2_BOARD |
425 LIMO_UNIVERSAL_BOARD);
426 if (rev & MEDIA_BOARD)
427 board_rev &= ~(J1_B2_BOARD |
428 LIMO_UNIVERSAL_BOARD);
429 if (rev & BAMBOO_BOARD)
430 board_rev &= ~(J1_B2_BOARD |
431 LIMO_UNIVERSAL_BOARD |
434 } else if (board == MACH_KESSLER) {
435 if (rev & ARIES_BOARD)
436 board_rev &= ~(J1_B2_BOARD |
437 LIMO_UNIVERSAL_BOARD);
438 if (rev & NEPTUNE_BOARD)
439 board_rev &= ~(J1_B2_BOARD |
440 LIMO_UNIVERSAL_BOARD);
442 board_rev &= ~BOARD_MASK;
445 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
453 gpio_direction_input(bank, 2);
454 gpio_direction_input(bank, 3);
455 gpio_direction_input(bank, 4);
456 gpio_direction_input(bank, mode3);
458 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
459 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
460 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
461 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
463 rev = gpio_get_value(bank, 2);
464 rev |= (gpio_get_value(bank, 3) << 1);
465 rev |= (gpio_get_value(bank, 4) << 2);
466 rev |= (gpio_get_value(bank, mode3) << 3);
471 static void check_hw_revision(void)
473 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
475 if (cpu_is_s5pc100()) {
476 struct s5pc100_gpio *gpio =
477 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
479 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
481 /* C100 TickerTape */
483 board = MACH_TICKERTAPE;
485 struct s5pc110_gpio *gpio =
486 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
492 * Note Check 'Aquila' board first
496 * LRA: Limo Real Aquila
497 * LUA: Limo Universal Aquila
502 * ADDR = 0xE0200000 + OFF
504 * OFF Universal BB LRA LUA OA TT SS CYP
505 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
506 * J2: 0x0284 0x01 0x10 0x00
507 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
508 * H3: 0x0C64 0x03 0x07 0x0F
509 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
510 * I: 0x0224 0x02 0x00 0x08
511 * MP03: 0x0324 0x9x 0xbx 0x9x
512 * MP05: 0x0364 0x80 0x88
516 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
518 board_rev |= J1_B2_BOARD;
520 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
521 gpio_direction_input(&gpio->gpio_j2, 6);
524 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
525 board_rev |= LIMO_UNIVERSAL_BOARD;
527 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
528 board_rev |= LIMO_REAL_BOARD;
530 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
531 board_rev |= MEDIA_BOARD;
533 /* set gpio to default value. */
534 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
535 gpio_direction_output(&gpio->gpio_j2, 6, 0);
538 /* Workaround: C110 Aquila Rev0.6 */
539 if (board_rev == 6) {
541 board_rev |= LIMO_REAL_BOARD;
544 /* C110 Aquila Bamboo */
545 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
547 board_rev |= BAMBOO_BOARD;
550 /* C110 TickerTape */
551 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
552 gpio_get_value(&gpio->gpio_d1, 1) == 0)
553 board = MACH_TICKERTAPE;
555 /* WMG160 - GPH3[0:4] = 0x00 */
556 if (board == MACH_TICKERTAPE) {
559 for (i = 0; i < 4; i++) {
560 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
571 /* C110 Geminus for rev0.0 */
572 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
573 gpio_direction_input(&gpio->gpio_j1, 2);
574 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
575 board = MACH_GEMINUS;
576 if ((board_rev & ~BOARD_MASK) == 3)
579 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
580 gpio_direction_output(&gpio->gpio_j1, 2, 0);
582 /* C110 Geminus for rev0.1 ~ */
583 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
584 gpio_direction_input(&gpio->gpio_j0, 6);
585 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
586 board = MACH_GEMINUS;
589 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
591 /* Kessler MP0_5[6] == 1 */
592 gpio_direction_input(&gpio->gpio_mp0_5, 6);
593 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
594 /* Cypress: Do this for cypress */
595 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
596 gpio_direction_input(&gpio->gpio_j2, 2);
597 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
598 board = MACH_CYPRESS;
599 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
601 board = MACH_KESSLER;
602 board_rev |= ARIES_BOARD;
604 /* Neptune MP0_5[4] == 1 */
605 gpio_direction_input(&gpio->gpio_mp0_5, 4);
606 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
607 board_rev &= ~ARIES_BOARD;
608 board_rev |= NEPTUNE_BOARD;
611 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
614 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
616 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
620 if (board == MACH_AQUILA)
621 gd->bd->bi_arch_number = MACH_AQUILA;
622 else if (board == MACH_KESSLER)
623 gd->bd->bi_arch_number = MACH_KESSLER;
624 else if (cpu_is_s5pc110())
625 gd->bd->bi_arch_number = C110_MACH_START + board;
627 gd->bd->bi_arch_number = C100_MACH_START + board;
629 /* Architecture Common settings */
630 if (cpu_is_s5pc110()) {
631 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
633 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
635 setenv("updatek", "onenand erase 0x60000 0x300000; "
636 "onenand write 0x31008000 0x60000 0x300000");
640 static void show_hw_revision(void)
645 * Workaround for Rev 0.3 + CP Ver ES 3.1
648 if (board_is_limo_real()) {
650 /* default is Rev 0.4 */
656 if (machine_is_aquila())
658 else if (machine_is_kessler())
659 board = MACH_KESSLER;
660 else if (cpu_is_s5pc110())
661 board = gd->bd->bi_arch_number - C110_MACH_START;
663 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);
684 dprintf("HW Revision:\t%x (%s%s) %s\n",
685 board_rev, get_board_name(board),
686 display_features(board, board_rev),
687 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
690 static void check_auto_burn(void)
692 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
693 unsigned int count = 0;
696 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
697 printf("Auto burning bootloader\n");
698 count += sprintf(buf + count, "run updateb; ");
700 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
701 printf("Auto burning kernel\n");
702 count += sprintf(buf + count, "run updatek; ");
706 count += sprintf(buf + count, "reset");
707 setenv("bootcmd", buf);
710 /* Clear the magic value */
711 writel(0xa5a55a5a, magic_base);
712 writel(0xa5a55a5a, magic_base + 0x4);
715 static void pmic_pin_init(void)
717 unsigned int reg, value;
719 if (cpu_is_s5pc100())
722 /* AP_PS_HOLD: XEINT_0: GPH0[0]
723 * Note: Don't use GPIO PS_HOLD it doesn't work
725 reg = S5PC110_PS_HOLD_CONTROL;
727 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
728 S5PC110_PS_HOLD_DATA_HIGH |
729 S5PC110_PS_HOLD_OUT_EN;
732 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
733 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
734 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
737 static void enable_ldos(void)
739 if (cpu_is_s5pc100())
742 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
743 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
746 static void enable_t_flash(void)
748 if (!(board_is_limo_universal() || board_is_limo_real()))
751 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
752 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
755 static void setup_limo_real_gpios(void)
757 if (!board_is_limo_real())
761 * Note: Please write GPIO alphabet order
763 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
764 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
767 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
768 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
770 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
771 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
773 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
774 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
775 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
778 static void setup_media_gpios(void)
780 if (!board_is_media())
784 * Note: Please write GPIO alphabet order
786 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
787 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
789 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
790 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
791 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
794 #define KBR3 (1 << 3)
795 #define KBR2 (1 << 2)
796 #define KBR1 (1 << 1)
797 #define KBR0 (1 << 0)
799 static void check_keypad(void)
801 unsigned int reg, value;
802 unsigned int col_num, row_num;
803 unsigned int col_mask;
804 unsigned int col_mask_shift;
805 unsigned int row_state[4];
807 unsigned int auto_download = 0;
809 if (machine_is_wmg160())
812 if (cpu_is_s5pc100()) {
813 struct s5pc100_gpio *gpio =
814 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
819 /* Set GPH2[2:0] to KP_COL[2:0] */
820 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
821 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
822 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
824 /* Set GPH3[2:0] to KP_ROW[2:0] */
825 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
826 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
827 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
829 reg = S5PC100_KEYPAD_BASE;
830 col_mask = S5PC1XX_KEYIFCOL_MASK;
833 if (board_is_limo_real() || board_is_limo_universal()) {
841 for (i = 0; i < row_num; i++) {
842 /* Set GPH3[3:0] to KP_ROW[3:0] */
843 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
844 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
847 for (i = 0; i < col_num; i++)
848 /* Set GPH2[3:0] to KP_COL[3:0] */
849 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
851 reg = S5PC110_KEYPAD_BASE;
852 col_mask = S5PC110_KEYIFCOLEN_MASK;
856 /* KEYIFCOL reg clear */
857 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
860 for (i = 0; i < col_num; i++) {
862 value &= ~(1 << i) << col_mask_shift;
864 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
867 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
868 row_state[i] = ~value & ((1 << row_num) - 1);
870 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
873 /* KEYIFCOL reg clear */
874 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
876 if (machine_is_aquila() || machine_is_kessler()) {
877 /* cam full shot & volume down */
878 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
881 else if ((row_state[1] & 0x2))
883 } else if (machine_is_geminus())
884 /* volume down & home */
885 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
889 setenv("bootcmd", "usbdown");
892 static void enable_battery(void)
894 unsigned char val[2];
895 unsigned char addr = 0x36; /* max17040 fuel gauge */
897 i2c_set_bus_num(I2C_GPIO3);
899 if (machine_is_aquila()) {
902 } else if (machine_is_kessler())
903 i2c_set_bus_num(I2C_GPIO7);
904 else if (machine_is_tickertape()) {
906 } else if (machine_is_cypress()) {
907 i2c_set_bus_num(I2C_GPIO7);
908 } else if (machine_is_geminus()) {
910 i2c_set_bus_num(I2C_GPIO7);
913 if (i2c_probe(addr)) {
914 printf("Can't found max17040 fuel gauge\n");
920 i2c_write(addr, 0xfe, 1, val, 2);
923 static void check_battery(void)
925 unsigned char val[2];
926 unsigned char addr = 0x36; /* max17040 fuel gauge */
928 i2c_set_bus_num(I2C_GPIO3);
930 if (machine_is_aquila()) {
933 } else if (machine_is_kessler())
934 i2c_set_bus_num(I2C_GPIO7);
935 else if (machine_is_cypress()) {
936 i2c_set_bus_num(I2C_GPIO7);
937 } else if (machine_is_geminus()) {
939 i2c_set_bus_num(I2C_GPIO7);
943 if (i2c_probe(addr)) {
944 printf("Can't found max17040 fuel gauge\n");
948 i2c_read(addr, 0x04, 1, val, 1);
950 dprintf("battery:\t%d%%\n", val[0]);
952 battery_soc = val[0];
955 static void check_mhl(void)
957 unsigned char val[2];
958 unsigned char addr = 0x39; /* SIL9230 */
960 /* MHL Power enable */
961 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
962 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
964 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
965 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
967 /* 10ms required after reset */
971 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
973 i2c_set_bus_num(I2C_GPIO5);
976 if (i2c_probe(addr)) {
977 printf("Can't found MHL Chip\n");
983 * set to Normal operation
986 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
987 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
992 * 00 = MHL termination ON
993 * 11 = MHL termination OFF
996 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
997 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
1000 #define CHARGER_ANIMATION_FRAME 6
1001 static int max8998_power_key(void)
1003 unsigned char addr, val[2];
1004 i2c_set_bus_num(I2C_PMIC);
1006 if (i2c_probe(addr)) {
1007 printf("Can't found max8998\n");
1011 /* Accessing IRQ1 register */
1012 i2c_read(addr, 0x00, 1, val, 1);
1013 if (val[0] & (1 << 6))
1019 static int max8998_has_ext_power_source(void)
1021 unsigned char addr, val[2];
1022 i2c_set_bus_num(I2C_PMIC);
1024 if (i2c_probe(addr)) {
1025 printf("Can't found max8998\n");
1029 /* Accessing STATUS2 register */
1030 i2c_read(addr, 0x09, 1, val, 1);
1031 if (val[0] & (1 << 5))
1037 extern void lcd_display_clear(void);
1038 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1040 static void into_charge_mode(void)
1042 unsigned char addr = 0xCC >> 1; /* max8998 */;
1043 unsigned char val[2];
1048 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1049 unsigned int reg, wakeup_stat;
1051 i2c_set_bus_num(I2C_PMIC);
1053 if (i2c_probe(addr)) {
1054 printf("Can't found max8998\n");
1058 printf("Charge Mode\n");
1060 i2c_read(addr, 0x0C, 1, val, 1);
1061 val[0] &= ~(0x7 << 0);
1062 val[0] &= ~(0x7 << 5);
1063 val[0] |= 5; /* 600mA */
1064 val[0] |= (3 << 5); /* Stop at 150mA(25%) */
1065 i2c_write(addr, 0x0C, 1, val, 1);
1067 #ifdef CONFIG_S5PC1XXFB
1070 /* TODO: write the image-text for the charger */
1072 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1073 if (level >= CHARGER_ANIMATION_FRAME)
1074 level = CHARGER_ANIMATION_FRAME - 1;
1076 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1077 bmp_addr[i] = (ulong)battery_charging_animation[i];
1079 lcd_display_clear();
1080 for (i = 0; i < 3; i++) {
1081 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1084 bmp = gunzip_bmp(bmp_addr[j], &len);
1085 lcd_display_bitmap((ulong) bmp, 140, 202);
1088 for (k = 0; k < 10; k++)
1089 if (max8998_power_key()) {
1090 lcd_display_clear();
1092 } else if (!max8998_has_ext_power_source()) {
1093 lcd_display_clear();
1103 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *) S5PC110_RTC_BASE;
1104 unsigned int org, org_ip3, org_tcfg0;
1106 empty_device_info_buffer();
1107 if (max8998_power_key()) {
1108 lcd_display_clear();
1110 } else if (!max8998_has_ext_power_source()) {
1111 lcd_display_clear();
1115 /* Enable RTC at CLKGATE IP3 */
1116 org_ip3 = readl(0xE010046C);
1117 writel(org_ip3 | (1 << 15) | (1 << 16), 0xE010046C);
1119 reg = org = readl(&rtc->rtccon);
1121 writel(reg, &rtc->rtccon);
1123 reg = readl(&rtc->rtccon);
1124 writel(reg | (1 << 3), &rtc->rtccon);
1126 writel(reg & ~(1 << 3), &rtc->rtccon);
1129 reg = readl(&rtc->rtccon);
1130 reg &= ~( (1 << 8) | (0xF << 4));
1131 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1132 writel(reg, &rtc->rtccon);
1134 reg = 15 * 4 - 1; /* 15 sec */
1135 writel(reg, &rtc->ticcnt);
1137 /* TODO: turn LCD/FB off for sure */
1139 /* EVT0: sleep 1, EVT1: sleep */
1140 if (cpu_is_s5pc110()) {
1141 char *name = "dummy";
1142 char *usage = "N/A";
1149 if (s5pc1xx_get_cpu_rev() == 0) {
1150 char *argv[] = {"1", "1"};
1151 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1153 char *argv[] = {"0", "0"};
1154 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1157 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1161 writel(org, &rtc->rtccon);
1162 writel(org_tcfg0, 0xE2600000);
1163 writel(org_ip3, 0xE010046C);
1165 /* TODO: 1. TEMP HIGH/LOW: stop charging and wake it up */
1166 /* TODO: 2. BATT FULL: stop charing and wake it up */
1168 } while (wakeup_stat == 0x04); /* RTC TICK */
1170 /* TODO: Reenable logo display */
1173 static void check_micro_usb(int intr)
1176 unsigned char val[2];
1177 static int started_charging_once = 0;
1180 if (cpu_is_s5pc100())
1183 if (board_is_limo_real()) {
1184 if (hwrevision(0) || hwrevision(1))
1188 i2c_set_bus_num(I2C_PMIC);
1190 if (machine_is_kessler())
1191 i2c_set_bus_num(I2C_GPIO6);
1192 else if (machine_is_cypress()) {
1193 i2c_set_bus_num(I2C_GPIO6);
1194 } else if (machine_is_geminus()) {
1196 i2c_set_bus_num(I2C_GPIO6);
1197 } else if (machine_is_wmg160())
1198 i2c_set_bus_num(I2C_GPIO6);
1200 addr = 0x25; /* fsa9480 */
1201 if (i2c_probe(addr)) {
1202 printf("Can't found fsa9480\n");
1206 /* Clear Interrupt */
1208 i2c_read(addr, 0x03, 1, val, 2);
1212 /* Read Device Type 1 */
1213 i2c_read(addr, 0x0a, 1, val, 1);
1215 #define FSA_DEV1_CHARGER (1 << 6)
1216 #define FSA_DEV1_UART (1 << 3)
1217 #define FSA_DEV1_USB (1 << 2)
1218 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1219 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1222 * If USB, use default 475mA
1223 * If Charger, use 600mA and go to charge mode
1225 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1226 started_charging_once = 1;
1230 /* If Factory Mode is Boot ON-USB, go to download mode */
1231 i2c_read(addr, 0x07, 1, val, 1);
1233 #define FSA_ADC_FAC_USB_OFF 0x18
1234 #define FSA_ADC_FAC_USB_ON 0x19
1235 #define FSA_ADC_FAC_UART 0x1d
1237 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1238 setenv("bootcmd", "usbdown");
1240 path = getenv("usb");
1242 if (!strncmp(path, "cp", 2))
1243 run_command("microusb cp", 0);
1246 static void micro_usb_switch(int path)
1249 unsigned char val[2];
1251 i2c_set_bus_num(I2C_PMIC);
1253 if (machine_is_kessler())
1254 i2c_set_bus_num(I2C_GPIO6);
1255 else if (machine_is_cypress()) {
1256 i2c_set_bus_num(I2C_GPIO6);
1257 } else if (machine_is_geminus()) {
1259 i2c_set_bus_num(I2C_GPIO6);
1260 } else if (machine_is_wmg160()) {
1261 i2c_set_bus_num(I2C_GPIO6);
1265 addr = 0x25; /* fsa9480 */
1266 if (i2c_probe(addr)) {
1267 printf("Can't found fsa9480\n");
1272 val[0] = 0x90; /* VAUDIO */
1274 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1276 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1278 i2c_read(addr, 0x2, 1, val, 1);
1279 val[0] &= ~(1 << 2); /* Manual switching */
1280 i2c_write(addr, 0x2, 1, val, 1);
1283 #define MAX8998_REG_ONOFF1 0x11
1284 #define MAX8998_REG_ONOFF2 0x12
1285 #define MAX8998_REG_ONOFF3 0x13
1286 #define MAX8998_REG_LDO7 0x21
1287 #define MAX8998_REG_LDO17 0x29
1289 #define MAX8998_LDO3 (1 << 2)
1291 #define MAX8998_LDO6 (1 << 7)
1292 #define MAX8998_LDO7 (1 << 6)
1293 #define MAX8998_LDO8 (1 << 5)
1294 #define MAX8998_LDO9 (1 << 4)
1295 #define MAX8998_LDO10 (1 << 3)
1296 #define MAX8998_LDO11 (1 << 2)
1297 #define MAX8998_LDO12 (1 << 1)
1298 #define MAX8998_LDO13 (1 << 0)
1300 #define MAX8998_LDO14 (1 << 7)
1301 #define MAX8998_LDO15 (1 << 6)
1302 #define MAX8998_LDO16 (1 << 5)
1303 #define MAX8998_LDO17 (1 << 4)
1306 static void init_pmic(void)
1309 unsigned char val[2];
1311 if (cpu_is_s5pc100())
1314 i2c_set_bus_num(I2C_PMIC);
1316 addr = 0xCC >> 1; /* max8998 */
1317 if (i2c_probe(addr)) {
1318 if (i2c_probe(addr)) {
1319 printf("Can't found max8998\n");
1325 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1326 val[0] &= ~MAX8998_LDO3;
1327 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1330 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1332 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1333 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1335 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1336 MAX8998_LDO12 | MAX8998_LDO13);
1338 if (machine_is_kessler())
1339 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1341 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1342 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1344 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1346 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1347 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1349 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1350 MAX8998_LDO16 | MAX8998_LDO17);
1352 if (machine_is_kessler())
1353 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1355 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1356 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1359 static void setup_power_down_mode_registers(void)
1361 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1362 struct s5pc1xx_gpio_bank *bank;
1363 struct gpio_powermode *p;
1365 struct gpio_external *ge;
1367 struct s5pc1xx_gpio_item *mr;
1371 if (cpu_is_s5pc100())
1374 /* Only Limo real and kessler supports worked for sleep currnet */
1375 if (machine_is_aquila()) {
1376 if (board_is_limo_real())
1380 } else if (machine_is_kessler()) {
1382 } else if (machine_is_geminus()) {
1387 if (machine_is_aquila()) {
1388 /* Aquila rev 0.8 or lower */
1389 p = aquila_powerdown_modes;
1390 ge = aquila_external_powerdown_modes;
1391 mr = aquila_mirror_powerdown_mode;
1392 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1393 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1394 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1395 } else if (machine_is_kessler()) {
1396 /* Aquila rev 0.9 */
1397 p = kessler_powerdown_modes;
1398 ge = kessler_external_powerdown_modes;
1399 mr = kessler_mirror_powerdown_mode;
1400 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1401 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1402 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1403 } else if (machine_is_geminus()) {
1404 if (hwrevision(1)) {
1405 /* Same as Aquila rev 0.9 */
1407 p = kessler_powerdown_modes;
1408 ge = kessler_external_powerdown_modes;
1409 mr = kessler_mirror_powerdown_mode;
1410 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1411 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1412 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1414 p = aquila_powerdown_modes;
1415 ge = aquila_external_powerdown_modes;
1416 mr = aquila_mirror_powerdown_mode;
1417 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1418 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1419 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1421 } else if (hwrevision(0)) {
1422 /* Same as Aquila rev 0.8 or lower */
1423 p = aquila_powerdown_modes;
1424 ge = aquila_external_powerdown_modes;
1425 mr = aquila_mirror_powerdown_mode;
1426 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1427 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1428 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1430 return; /* Not supported */
1434 bank = &gpio->gpio_a0;
1436 for (i = 0; i < n_p; i++, p++, bank++) {
1437 writel(p->conpdn, &bank->pdn_con);
1438 writel(p->pudpdn, &bank->pdn_pull);
1441 writel(0xff0022b0, (unsigned int *)0xF0000000);
1442 writel(0xff0022b0, (unsigned int *)0xF1400000);
1444 bank = &gpio->gpio_h0;
1446 for (i = 0; i < n_ge; i++) {
1447 writel(ge->con, &bank->con);
1448 writel(ge->dat, &bank->dat);
1449 writel(ge->pud, &bank->pull);
1455 for (i = 0; i < n_mr; i++) {
1456 unsigned int reg = readl(&mr->bank->pdn_con);
1457 reg &= ~(1 << mr->number);
1458 if (readl(&mr->bank->dat) & (1 << mr->number))
1459 reg |= 1 << mr->number;
1460 writel(reg, &mr->bank->pdn_con);
1466 #include "../../../drivers/video/s5p-spi.h"
1468 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1469 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1471 struct spi_platform_data spi_pd;
1473 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1475 void lcd_cfg_gpio(void)
1477 unsigned int i, f3_end = 4;
1479 for (i = 0; i < 8; i++) {
1480 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1481 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1482 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1483 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1484 /* pull-up/down disable */
1485 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1486 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1487 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1489 /* drive strength to max (24bit) */
1490 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1491 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1492 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1493 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1494 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1495 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1498 /* set DISPLAY_DE_B pin for dual rgb mode. */
1499 if (board_is_media())
1502 for (i = 0; i < f3_end; i++) {
1503 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1504 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1505 /* pull-up/down disable */
1506 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1507 /* drive strength to max (24bit) */
1508 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1509 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1511 /* display output path selection (only [1:0] valid) */
1512 writel(0x2, 0xE0107008);
1514 /* gpio pad configuration for LCD reset. */
1515 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1517 /* gpio pad configuration for LCD ON. */
1518 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1520 /* LCD_BACKLIGHT_EN */
1521 if (machine_is_geminus())
1522 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1525 * gpio pad configuration for
1526 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1528 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1529 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1530 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1531 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1533 if (machine_is_aquila() || machine_is_kessler()) {
1534 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1536 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1538 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1540 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1543 if (board_is_neptune())
1544 s6d16a0x_set_platform_data(&spi_pd);
1546 s6e63m0_set_platform_data(&spi_pd);
1547 if (board_is_media())
1552 if (machine_is_cypress()) {
1553 #if 0 /* universal cypress */
1555 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1558 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1560 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1562 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1564 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1566 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1567 #if 0 /* universal cypress */
1568 pd_cs.bank = &gpio_base->gpio_mp0_1;
1571 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1573 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1575 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1580 /* these data would be sent to s6e63m0 lcd panel driver. */
1581 s6e63m0_set_platform_data(&spi_pd);
1587 void backlight_on(unsigned int onoff)
1589 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1592 if (machine_is_geminus())
1593 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1595 if (machine_is_geminus())
1596 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1600 void reset_lcd(void)
1602 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1604 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1605 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1606 if (machine_is_cypress())
1607 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1610 void lcd_power_on(unsigned int onoff)
1612 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1615 if (machine_is_aquila() || machine_is_geminus())
1616 gpio_set_value(&gpio->gpio_j1, 3, 1);
1618 if (machine_is_cypress())
1619 gpio_set_value(&gpio->gpio_g2, 2, 1);
1621 if (machine_is_kessler()) {
1623 unsigned char val[2];
1624 unsigned char val2[2];
1626 gpio_set_value(&gpio->gpio_j1, 3, 1);
1628 i2c_set_bus_num(I2C_PMIC);
1629 addr = 0xCC >> 1; /* max8998 */
1630 if (i2c_probe(addr)) {
1631 printf("Can't found max8998\n");
1634 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1635 val[0] &= ~(MAX8998_LDO17);
1636 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1637 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1639 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1640 val[0] |= MAX8998_LDO17;
1642 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1643 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1645 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1646 val[0] |= MAX8998_LDO7;
1648 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1649 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1652 if (machine_is_aquila() || machine_is_geminus())
1653 gpio_set_value(&gpio->gpio_j1, 3, 0);
1655 if (machine_is_cypress())
1656 gpio_set_value(&gpio->gpio_g2, 2, 0);
1658 if (machine_is_kessler()) {
1660 unsigned char val[2];
1662 i2c_set_bus_num(I2C_PMIC);
1663 addr = 0xCC >> 1; /* max8998 */
1664 if (i2c_probe(addr)) {
1665 printf("Can't found max8998\n");
1669 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1670 val[0] &= ~(1 << 7);
1671 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1672 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1674 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1675 val[0] &= ~MAX8998_LDO17;
1676 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1677 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1682 extern void s6e63m0_cfg_ldo(void);
1683 extern void s6e63m0_enable_ldo(unsigned int onoff);
1684 extern void s6d16a0x_cfg_ldo(void);
1685 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1687 int s5p_no_lcd_support(void)
1689 if (machine_is_wmg160())
1694 void init_panel_info(vidinfo_t *vid)
1696 vid->cfg_gpio = NULL;
1697 vid->reset_lcd = NULL;
1698 vid->backlight_on = NULL;
1699 vid->lcd_power_on = NULL;
1701 vid->cfg_ldo = NULL;
1702 vid->enable_ldo = NULL;
1704 vid->init_delay = 0;
1705 vid->reset_delay = 0;
1706 vid->power_on_delay = 0;
1711 vid->vl_width = 480;
1712 vid->vl_height = 800;
1714 vid->dual_lcd_enabled = 0;
1716 if (board_is_media()) {
1719 vid->vl_width = 960;
1720 vid->vl_height = 800;
1722 /* enable dual lcd mode. */
1723 vid->dual_lcd_enabled = 1;
1726 vid->vl_clkp = CONFIG_SYS_HIGH;
1727 vid->vl_hsp = CONFIG_SYS_LOW;
1728 vid->vl_vsp = CONFIG_SYS_LOW;
1729 vid->vl_dp = CONFIG_SYS_HIGH;
1732 /* S6E63M0 LCD Panel */
1741 if (machine_is_aquila() || machine_is_kessler() || machine_is_cypress()) {
1742 vid->cfg_gpio = lcd_cfg_gpio;
1743 vid->reset_lcd = reset_lcd;
1744 vid->backlight_on = backlight_on;
1745 vid->lcd_power_on = lcd_power_on;
1746 vid->cfg_ldo = s6e63m0_cfg_ldo;
1747 vid->enable_ldo = s6e63m0_enable_ldo;
1749 vid->init_delay = 25000;
1750 vid->reset_delay = 120000;
1753 if (board_is_neptune()) {
1757 vid->vl_width = 320;
1758 vid->vl_height = 480;
1760 vid->vl_clkp = CONFIG_SYS_HIGH;
1761 vid->vl_hsp = CONFIG_SYS_HIGH;
1762 vid->vl_vsp = CONFIG_SYS_HIGH;
1763 vid->vl_dp = CONFIG_SYS_LOW;
1766 /* disable dual lcd mode. */
1767 vid->dual_lcd_enabled = 0;
1769 /* S6D16A0X LCD Panel */
1778 vid->cfg_gpio = lcd_cfg_gpio;
1779 vid->backlight_on = NULL;
1780 vid->lcd_power_on = lcd_power_on;
1781 vid->reset_lcd = reset_lcd;
1782 vid->cfg_ldo = s6d16a0x_cfg_ldo;
1783 vid->enable_ldo = s6d16a0x_enable_ldo;
1785 vid->init_delay = 10000;
1786 vid->power_on_delay = 10000;
1787 vid->reset_delay = 1000;
1791 if (machine_is_geminus()) {
1795 vid->vl_width = 1024,
1796 vid->vl_height = 600,
1797 vid->vl_clkp = CONFIG_SYS_LOW,
1798 vid->vl_hsp = CONFIG_SYS_HIGH,
1799 vid->vl_vsp = CONFIG_SYS_HIGH,
1800 vid->vl_dp = CONFIG_SYS_LOW,
1811 vid->cfg_gpio = lcd_cfg_gpio;
1812 vid->reset_lcd = reset_lcd;
1813 vid->backlight_on = backlight_on;
1814 vid->lcd_power_on = lcd_power_on;
1820 vid->vl_width = 480,
1821 vid->vl_height = 800,
1822 vid->vl_clkp = CONFIG_SYS_HIGH,
1823 vid->vl_hsp = CONFIG_SYS_LOW,
1824 vid->vl_vsp = CONFIG_SYS_LOW,
1825 vid->vl_dp = CONFIG_SYS_HIGH,
1841 vid->vl_width = 1024,
1842 vid->vl_height = 600,
1843 vid->vl_clkp = CONFIG_SYS_HIGH,
1844 vid->vl_hsp = CONFIG_SYS_HIGH,
1845 vid->vl_vsp = CONFIG_SYS_HIGH,
1846 vid->vl_dp = CONFIG_SYS_LOW,
1849 /* AMS701KA AMOLED Panel. */
1861 static void setup_meminfo(void)
1863 char meminfo[64] = {0, };
1864 int count = 0, size, real;
1866 size = gd->bd->bi_dram[0].size >> 20;
1867 count += sprintf(meminfo + count, "mem=%dM", size);
1869 /* Each Chip Select can't exceed the 256MiB */
1870 size = gd->bd->bi_dram[1].size >> 20;
1871 real = min(size, 256);
1872 count += sprintf(meminfo + count, " mem=%dM@0x%x",
1873 real, (unsigned int)gd->bd->bi_dram[1].start);
1877 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1878 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1881 setenv("meminfo", meminfo);
1884 int misc_init_r(void)
1887 /* It should be located at first */
1890 if (machine_is_aquila() || machine_is_kessler()) {
1891 if (board_is_neptune())
1892 setenv("lcdinfo", "lcd=s6d16a0x");
1893 else if (board_is_media())
1894 setenv("lcdinfo", "lcd=s6e63m0");
1896 setenv("lcdinfo", "lcd=s6e63m0");
1898 if (machine_is_geminus())
1899 setenv("lcdinfo", "lcd=lms480jc01");
1900 if (machine_is_cypress())
1901 setenv("lcdinfo", "lcd=s6e63m0");
1907 /* Set proper PMIC pins */
1910 /* Check auto burning */
1913 /* To power up I2C2 */
1916 /* Enable T-Flash at Limo Real or Limo Universal */
1919 /* Setup Limo Real board GPIOs */
1920 setup_limo_real_gpios();
1922 /* Setup Media board GPIOs */
1923 setup_media_gpios();
1925 /* To usbdown automatically */
1931 #ifdef CONFIG_S5PC1XXFB
1932 display_device_info();
1935 setup_power_down_mode_registers();
1937 /* check max17040 */
1947 int board_init(void)
1949 /* Set Initial global variables */
1950 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1952 gd->bd->bi_arch_number = MACH_AQUILA;
1953 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1955 /* Check H/W Revision */
1956 check_hw_revision();
1963 unsigned int base, memconfig0, size;
1964 unsigned int memconfig1, sz = 0;
1966 if (cpu_is_s5pc100()) {
1967 /* In mem setup, we swap the bank. So below size is correct */
1968 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1969 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1970 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1973 /* In S5PC110, we can't swap the DMC0/1 */
1974 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1975 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1977 base = S5PC110_DMC1_BASE;
1978 /* DMC configuration */
1979 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1980 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1982 size = (memconfig0 >> 16) & 0xFF;
1983 size = ((unsigned char) ~size) + 1;
1986 * (0x07 + 1) * 16 = 128 MiB
1987 * (0x0f + 1) * 16 = 256 MiB
1992 * Aquila Rev0.5 4G3G1G
1993 * Aquila Rev0.8 4G3G1G
1994 * Aquila Rev0.9 4G3G1G
1996 if (machine_is_aquila() || machine_is_kessler())
1997 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
1998 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2000 sz = (memconfig1 >> 16) & 0xFF;
2001 sz = ((unsigned char) ~sz) + 1;
2007 * bi_dram[1].size contains all DMC1 memory size
2009 gd->bd->bi_dram[1].size = (size + sz) << 20;
2014 /* Used for sleep test */
2015 static unsigned char saved_val[4][2];
2016 void board_sleep_init_late(void)
2018 /* CODEC_LDO_EN: GPF3[4] */
2019 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2020 /* CODEC_XTAL_EN: GPH3[2] */
2021 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2023 /* MMC T_FLASH off */
2024 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2026 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2027 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2028 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
2032 void board_sleep_init(void)
2035 unsigned char val[2];
2037 i2c_set_bus_num(I2C_PMIC);
2039 if (i2c_probe(addr)) {
2040 printf("Can't find max8998\n");
2044 if (machine_is_kessler()) {
2047 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2048 saved_val[0][0] = val[0];
2049 saved_val[0][1] = val[1];
2050 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2051 (1 << 1) | (1 << 0));
2052 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2053 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2055 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2056 saved_val[1][0] = val[0];
2057 saved_val[1][1] = val[1];
2058 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2059 (1 << 2) | (1 << 1) | (1 << 0));
2061 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2062 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2064 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2065 saved_val[2][0] = val[0];
2066 saved_val[2][1] = val[1];
2067 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2068 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2069 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2071 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2072 saved_val[3][0] = val[0];
2073 saved_val[3][1] = val[1];
2074 val[0] &= ~((1 << 6) | (1 << 4));
2075 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2076 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2077 printf("Turned off regulators with Kessler setting."
2078 " Preparing to sleep. [%s:%d]\n",
2079 __FILE__, __LINE__);
2080 } else { /* Default */
2083 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2084 saved_val[0][0] = val[0];
2085 saved_val[0][1] = val[1];
2086 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2087 (1 << 1) | (1 << 0));
2088 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2089 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2091 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2092 saved_val[1][0] = val[0];
2093 saved_val[1][1] = val[1];
2094 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2095 (1 << 2) | (1 << 1) | (1 << 0));
2097 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2098 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2100 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2101 saved_val[2][0] = val[0];
2102 saved_val[2][1] = val[1];
2103 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2104 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2105 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2107 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2108 saved_val[3][0] = val[0];
2109 saved_val[3][1] = val[1];
2110 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2111 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2112 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2113 printf("Turned off regulators with default(Aquila) setting."
2114 " Preparing to sleep. [%s:%d]\n",
2115 __FILE__, __LINE__);
2119 void board_sleep_resume(void)
2122 unsigned char val[2];
2126 i2c_set_bus_num(I2C_PMIC);
2128 if (i2c_probe(addr)) {
2129 printf("Can't find max8998\n");
2134 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2135 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2137 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2138 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2140 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2141 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2143 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2144 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2145 printf("Waked up.\n");
2147 /* check max17040 */
2154 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2156 static int s5pc1xx_phy_control(int on)
2160 if (on && !status) {
2161 // printf("turning USB power on\n");
2162 #ifdef CONFIG_CMD_PMIC
2163 run_command("pmic ldo 3 on", 0);
2166 if (board_is_limo_universal() ||
2167 board_is_limo_real() ||
2169 /* check usb path */
2170 if (board_is_limo_real() && !hwrevision(6))
2174 if (machine_is_tickertape())
2175 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2176 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2178 /* USB Path to AP */
2179 micro_usb_switch(0);
2181 } else if (!on && status) {
2182 // printf("turning USB power off\n");
2183 #ifdef CONFIG_CMD_PMIC
2184 run_command("pmic ldo 3 off", 0);
2191 struct s3c_plat_otg_data s5pc110_otg_data = {
2192 .phy_control = s5pc1xx_phy_control,
2193 .regs_phy = S5PC110_PHY_BASE,
2194 .regs_otg = S5PC110_OTG_BASE,
2197 int board_eth_init(bd_t *bis)
2201 if (cpu_is_s5pc100())
2204 s3c_udc_probe(&s5pc110_otg_data);
2205 if (usb_eth_initialize(bis) >= 0)
2211 #ifdef CONFIG_CMD_USBDOWN
2212 int usb_board_init(void)
2214 #ifdef CONFIG_CMD_PMIC
2215 run_command("pmic ldo 3 on", 0);
2218 if (cpu_is_s5pc100()) {
2219 #ifdef CONFIG_HARD_I2C
2220 uchar val[2] = {0,};
2223 if (i2c_read(0x66, 0, 1, val, 2)) {
2224 printf("i2c_read error\n");
2231 if (i2c_write(0x66, 0, 1, val, 2)) {
2232 printf("i2c_write error\n");
2235 i2c_read(0x66, 0, 1, val, 2);
2241 if (board_is_limo_universal() ||
2242 board_is_limo_real() ||
2244 /* check usb path */
2245 if (board_is_limo_real() && !hwrevision(6))
2249 if (machine_is_tickertape())
2250 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2251 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2253 /* USB Path to AP */
2254 micro_usb_switch(0);
2260 #ifdef CONFIG_GENERIC_MMC
2261 int s5p_no_mmc_support(void)
2263 if (machine_is_wmg160())
2268 int board_mmc_init(bd_t *bis)
2272 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2275 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2276 if (machine_is_kessler())
2277 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2279 if (machine_is_wmg160())
2282 /* MMC0 Clock source = SCLKMPLL */
2283 reg = readl(&clk->src4);
2286 writel(reg, &clk->src4);
2288 reg = readl(&clk->div4);
2291 /* set div value near 50MHz */
2292 clock = get_pll_clk(MPLL) / 1000000;
2293 for (i = 0; i < 0xf; i++) {
2294 if ((clock / (i + 1)) <= 50) {
2300 writel(reg, &clk->div4);
2306 * GPG0[2] SD_0_CDn -> Not used
2307 * GPG0[3:6] SD_0_DATA[0:3]
2309 for (i = 0; i < 7; i++) {
2312 /* GPG0[0:6] special function 2 */
2313 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2314 /* GPG0[0:6] pull disable */
2315 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2316 /* GPG0[0:6] drv 4x */
2317 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2320 return s5pc1xx_mmc_init(0);
2324 #ifdef CONFIG_CMD_PMIC
2325 static int pmic_status(void)
2327 unsigned char addr, val[2];
2330 i2c_set_bus_num(I2C_PMIC);
2332 if (i2c_probe(addr)) {
2333 printf("Can't found max8998\n");
2338 i2c_read(addr, reg, 1, val, 1);
2339 for (i = 7; i >= 4; i--)
2340 printf("BUCK%d %s\n", 7 - i + 1,
2341 val[0] & (1 << i) ? "on" : "off");
2343 printf("LDO%d %s\n", 5 - i,
2344 val[0] & (1 << i) ? "on" : "off");
2346 i2c_read(addr, reg, 1, val, 1);
2347 for (i = 7; i >= 0; i--)
2348 printf("LDO%d %s\n", 7 - i + 6,
2349 val[0] & (1 << i) ? "on" : "off");
2351 i2c_read(addr, reg, 1, val, 1);
2352 for (i = 7; i >= 4; i--)
2353 printf("LDO%d %s\n", 7 - i + 14,
2354 val[0] & (1 << i) ? "on" : "off");
2357 i2c_read(addr, reg, 1, val, 1);
2358 for (i = 7; i >= 6; i--)
2359 printf("SAFEOUT%d %s\n", 7 - i + 1,
2360 val[0] & (1 << i) ? "on" : "off");
2364 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2366 unsigned char addr, val[2];
2367 unsigned int reg, shift;
2375 } else if (ldo <= 13) {
2378 } else if (ldo <= 17) {
2380 shift = 17 - ldo + 4;
2387 shift = 4 - buck + 4;
2388 } else if (safeout) {
2392 shift = 8 - safeout;
2396 i2c_set_bus_num(I2C_PMIC);
2398 if (i2c_probe(addr)) {
2399 printf("Can't found max8998\n");
2403 i2c_read(addr, reg, 1, val, 1);
2405 val[0] |= (1 << shift);
2407 val[0] &= ~(1 << shift);
2408 i2c_write(addr, reg, 1, val, 1);
2409 i2c_read(addr, reg, 1, val, 1);
2412 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2413 val[0] & (1 << shift) ? "on" : "off");
2415 printf("buck %d value 0x%x, %s\n", buck, val[0],
2416 val[0] & (1 << shift) ? "on" : "off");
2418 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2419 val[0] & (1 << shift) ? "on" : "off");
2424 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2426 int buck = 0, ldo = 0, safeout = 0, on = -1;
2430 if (strncmp(argv[1], "status", 6) == 0)
2431 return pmic_status();
2434 if (strncmp(argv[1], "ldo", 3) == 0)
2435 ldo = simple_strtoul(argv[2], NULL, 10);
2436 else if (strncmp(argv[1], "buck", 4) == 0)
2437 buck = simple_strtoul(argv[2], NULL, 10);
2438 else if (strncmp(argv[1], "safeout", 7) == 0)
2439 safeout = simple_strtoul(argv[2], NULL, 10);
2443 if (strncmp(argv[3], "on", 2) == 0)
2445 else if (strncmp(argv[3], "off", 3) == 0)
2450 return pmic_ldo_control(buck, ldo, safeout, on);
2461 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2462 "PMIC LDO & BUCK control",
2463 "status - Display PMIC LDO & BUCK status\n"
2464 "pmic ldo num on/off - Turn on/off the LDO\n"
2465 "pmic buck num on/off - Turn on/off the BUCK\n"
2466 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2470 #ifdef CONFIG_CMD_DEVICE_POWER
2484 static void power_display_devices(void)
2486 printf("devices:\n");
2487 printf("\t%d - touch\n", POWER_TOUCH);
2488 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2489 printf("\t%d - LCD\n", POWER_LCD);
2490 printf("\t%d - Haptic\n", POWER_HAPTIC);
2491 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2492 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2493 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2494 printf("\t%d - HDMI\n", POWER_HDMI);
2497 static int power_hdmi(int on)
2499 /* HDMI_EN1: GPJ2[2] */
2500 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2501 /* MHL_ON: GPJ2[3] */
2502 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2506 static int power_bt_wifi(int on)
2508 /* WLAN_BT_EN: GPB[5] */
2509 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2513 static int power_fm_radio(int on)
2515 /* FM_BUS_nRST: GPJ2[5] */
2516 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2520 static int power_audio_codec(int on)
2522 /* CODEC_LDO_EN: GPF3[4] */
2523 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2524 /* CODEC_XTAL_EN: GPH3[2] */
2525 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2529 static int power_haptic(int on)
2531 /* HAPTIC_ON: GPJ1[1] */
2532 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2536 static int power_lcd(int on)
2538 /* MLCD_ON: GPJ1[3] */
2539 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2543 static int power_touch(int on)
2545 /* TOUCH_EN: GPG3[6] */
2546 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2550 static int power_3_touchkey(int on)
2553 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2554 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2555 if (board_rev & J1_B2_BOARD)
2556 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2558 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2560 /* 3_TOUCH_CE - GPJ2[6] */
2561 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2563 /* 3_TOUCH_CE - GPJ2[6] */
2564 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2569 unsigned char val[2];
2570 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2576 i2c_set_bus_num(I2C_GPIO10);
2578 /* Workaround to probe */
2579 if (i2c_probe(addr)) {
2580 if (i2c_probe(addr)) {
2581 printf("Can't found 3 touchkey\n");
2586 #define MCS5000_TK_HW_VERSION 0x06
2587 #define MCS5000_TK_FW_VERSION 0x0A
2588 #define MCS5000_TK_MI_VERSION 0x0B
2590 reg = MCS5000_TK_MI_VERSION;
2591 i2c_read(addr, reg, 1, val, 1);
2592 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2593 reg = MCS5000_TK_HW_VERSION;
2594 i2c_read(addr, reg, 1, val, 1);
2595 printf("H/W 0x%x, ", val[0]);
2596 reg = MCS5000_TK_FW_VERSION;
2597 i2c_read(addr, reg, 1, val, 1);
2598 printf("F/W 0x%x\n", val[0]);
2603 static int power_control(int device, int on)
2607 return power_touch(on);
2608 case POWER_3_TOUCHKEY:
2609 return power_3_touchkey(on);
2611 return power_lcd(on);
2613 return power_haptic(on);
2614 case POWER_AUDIO_CODEC:
2615 return power_audio_codec(on);
2616 case POWER_FM_RADIO:
2617 return power_fm_radio(on);
2619 return power_bt_wifi(on);
2621 return power_hdmi(on);
2623 printf("I don't know device %d\n", device);
2629 static int power_on(int on)
2632 power_3_touchkey(on);
2635 power_audio_codec(on);
2643 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2647 if (!machine_is_aquila() && !machine_is_kessler())
2652 if (strncmp(argv[1], "on", 2) == 0)
2654 if (strncmp(argv[1], "off", 3) == 0)
2658 device = simple_strtoul(argv[1], NULL, 10);
2662 if (strncmp(argv[2], "on", 2) == 0)
2664 else if (strncmp(argv[2], "off", 3) == 0)
2668 return power_control(device, on);
2674 power_display_devices();
2679 power, CONFIG_SYS_MAXARGS, 1, do_power,
2680 "Device Power Management control",
2681 "device on/off - Turn on/off the device\n"
2684 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2688 if (strncmp(argv[1], "cp", 2) == 0) {
2689 micro_usb_switch(1);
2690 pmic_ldo_control(0, 0, 2, 1);
2691 setenv("usb", "cp");
2692 } else if (strncmp(argv[1], "ap", 2) == 0) {
2693 micro_usb_switch(0);
2694 pmic_ldo_control(0, 0, 2, 0);
2695 setenv("usb", "ap");
2705 printf("USB Path is set to %s\n", getenv("usb"));
2711 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2713 "cp - switch to CP\n"
2714 "microusb ap - switch to AP\n"