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;
448 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
456 gpio_direction_input(bank, 2);
457 gpio_direction_input(bank, 3);
458 gpio_direction_input(bank, 4);
459 gpio_direction_input(bank, mode3);
461 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
462 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
463 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
464 gpio_set_pull(bank, mode3, GPIO_PULL_NONE); /* HWREV_MODE3 */
466 rev = gpio_get_value(bank, 2);
467 rev |= (gpio_get_value(bank, 3) << 1);
468 rev |= (gpio_get_value(bank, 4) << 2);
469 rev |= (gpio_get_value(bank, mode3) << 3);
474 static void check_hw_revision(void)
476 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
478 if (cpu_is_s5pc100()) {
479 struct s5pc100_gpio *gpio =
480 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
482 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
484 /* C100 TickerTape */
486 board = MACH_TICKERTAPE;
488 struct s5pc110_gpio *gpio =
489 (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
495 * Note Check 'Aquila' board first
499 * LRA: Limo Real Aquila
500 * LUA: Limo Universal Aquila
505 * ADDR = 0xE0200000 + OFF
507 * OFF Universal BB LRA LUA OA TT SS CYP
508 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
509 * J2: 0x0284 0x01 0x10 0x00
510 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
511 * H3: 0x0C64 0x03 0x07 0x0F
512 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
513 * I: 0x0224 0x02 0x00 0x08
514 * MP03: 0x0324 0x9x 0xbx 0x9x
515 * MP05: 0x0364 0x80 0x88
519 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
521 board_rev |= J1_B2_BOARD;
523 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
524 gpio_direction_input(&gpio->gpio_j2, 6);
527 if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
528 board_rev |= LIMO_UNIVERSAL_BOARD;
530 if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
531 board_rev |= LIMO_REAL_BOARD;
533 if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
534 board_rev |= MEDIA_BOARD;
536 /* set gpio to default value. */
537 gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
538 gpio_direction_output(&gpio->gpio_j2, 6, 0);
541 /* Workaround: C110 Aquila Rev0.6 */
542 if (board_rev == 6) {
544 board_rev |= LIMO_REAL_BOARD;
547 /* C110 Aquila Bamboo */
548 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
550 board_rev |= BAMBOO_BOARD;
553 /* C110 TickerTape */
554 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
555 gpio_get_value(&gpio->gpio_d1, 1) == 0)
556 board = MACH_TICKERTAPE;
558 /* WMG160 - GPH3[0:4] = 0x00 */
559 if (board == MACH_TICKERTAPE) {
562 for (i = 0; i < 4; i++) {
563 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
574 /* C110 Geminus for rev0.0 */
575 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
576 gpio_direction_input(&gpio->gpio_j1, 2);
577 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
578 board = MACH_GEMINUS;
579 if ((board_rev & ~BOARD_MASK) == 3)
582 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
583 gpio_direction_output(&gpio->gpio_j1, 2, 0);
585 /* C110 Geminus for rev0.1 ~ */
586 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
587 gpio_direction_input(&gpio->gpio_j0, 6);
588 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
589 board = MACH_GEMINUS;
592 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
594 /* Kessler MP0_5[6] == 1 */
595 gpio_direction_input(&gpio->gpio_mp0_5, 6);
596 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
597 /* Cypress: Do this for cypress */
598 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
599 gpio_direction_input(&gpio->gpio_j2, 2);
600 if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
601 board = MACH_CYPRESS;
602 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
604 board = MACH_KESSLER;
605 board_rev |= ARIES_BOARD;
607 /* Neptune MP0_5[4] == 1 */
608 gpio_direction_input(&gpio->gpio_mp0_5, 4);
609 if (gpio_get_value(&gpio->gpio_mp0_5, 4) == 1) {
610 board_rev &= ~ARIES_BOARD;
611 board_rev |= NEPTUNE_BOARD;
614 gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
617 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
620 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
624 if (board < MACH_PSEUDO_END) {
625 if (cpu_is_s5pc110())
626 gd->bd->bi_arch_number = C110_MACH_START + board;
628 gd->bd->bi_arch_number = C100_MACH_START + board;
630 gd->bd->bi_arch_number = board;
633 /* Architecture Common settings */
634 if (cpu_is_s5pc110()) {
635 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
637 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
639 setenv("updatek", "onenand erase 0x60000 0x300000; "
640 "onenand write 0x31008000 0x60000 0x300000");
644 static void show_hw_revision(void)
649 * Workaround for Rev 0.3 + CP Ver ES 3.1
652 if (board_is_limo_real()) {
654 /* default is Rev 0.4 */
660 if (machine_is_kessler() || machine_is_aquila())
661 board = gd->bd->bi_arch_number;
662 else if (cpu_is_s5pc110())
663 board = gd->bd->bi_arch_number - C110_MACH_START;
665 board = gd->bd->bi_arch_number - C100_MACH_START;
668 check_board_revision(board, board_rev);
670 /* Set CPU Revision */
671 if (machine_is_aquila()) {
672 if (board_is_limo_real()) {
673 if ((board_rev & 0xf) < 8)
674 s5pc1xx_set_cpu_rev(0);
676 } else if (machine_is_kessler()) {
677 s5pc1xx_set_cpu_rev(1);
678 } else if (machine_is_geminus()) {
679 if ((board_rev & 0xf) < 1)
680 s5pc1xx_set_cpu_rev(0);
681 } else if (machine_is_cypress()) {
682 s5pc1xx_set_cpu_rev(1);
684 s5pc1xx_set_cpu_rev(0);
687 dprintf("HW Revision:\t%x (%s%s) %s\n",
688 board_rev, get_board_name(board),
689 display_features(board, board_rev),
690 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
693 static void check_auto_burn(void)
695 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
696 unsigned int count = 0;
699 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
700 printf("Auto burning bootloader\n");
701 count += sprintf(buf + count, "run updateb; ");
703 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
704 printf("Auto burning kernel\n");
705 count += sprintf(buf + count, "run updatek; ");
709 count += sprintf(buf + count, "reset");
710 setenv("bootcmd", buf);
713 /* Clear the magic value */
714 writel(0xa5a55a5a, magic_base);
715 writel(0xa5a55a5a, magic_base + 0x4);
718 static void pmic_pin_init(void)
720 unsigned int reg, value;
722 if (cpu_is_s5pc100())
725 /* AP_PS_HOLD: XEINT_0: GPH0[0]
726 * Note: Don't use GPIO PS_HOLD it doesn't work
728 reg = S5PC110_PS_HOLD_CONTROL;
730 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
731 S5PC110_PS_HOLD_DATA_HIGH |
732 S5PC110_PS_HOLD_OUT_EN;
735 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
736 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
737 gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
740 static void enable_ldos(void)
742 if (cpu_is_s5pc100())
745 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
746 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
749 static void enable_t_flash(void)
751 if (!(board_is_limo_universal() || board_is_limo_real()))
754 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
755 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
758 static void setup_limo_real_gpios(void)
760 if (!board_is_limo_real())
764 * Note: Please write GPIO alphabet order
766 /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
767 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
770 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
771 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
773 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
774 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
776 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
777 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
778 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
781 static void setup_media_gpios(void)
783 if (!board_is_media())
787 * Note: Please write GPIO alphabet order
789 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
790 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
792 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
793 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
794 gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
797 #define KBR3 (1 << 3)
798 #define KBR2 (1 << 2)
799 #define KBR1 (1 << 1)
800 #define KBR0 (1 << 0)
802 static void check_keypad(void)
804 unsigned int reg, value;
805 unsigned int col_num, row_num;
806 unsigned int col_mask;
807 unsigned int col_mask_shift;
808 unsigned int row_state[4];
810 unsigned int auto_download = 0;
812 if (machine_is_wmg160())
815 if (cpu_is_s5pc100()) {
816 struct s5pc100_gpio *gpio =
817 (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
822 /* Set GPH2[2:0] to KP_COL[2:0] */
823 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
824 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
825 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
827 /* Set GPH3[2:0] to KP_ROW[2:0] */
828 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
829 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
830 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
832 reg = S5PC100_KEYPAD_BASE;
833 col_mask = S5PC1XX_KEYIFCOL_MASK;
836 if (board_is_limo_real() || board_is_limo_universal()) {
844 for (i = 0; i < row_num; i++) {
845 /* Set GPH3[3:0] to KP_ROW[3:0] */
846 gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
847 gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
850 for (i = 0; i < col_num; i++)
851 /* Set GPH2[3:0] to KP_COL[3:0] */
852 gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
854 reg = S5PC110_KEYPAD_BASE;
855 col_mask = S5PC110_KEYIFCOLEN_MASK;
859 /* KEYIFCOL reg clear */
860 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
863 for (i = 0; i < col_num; i++) {
865 value &= ~(1 << i) << col_mask_shift;
867 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
870 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
871 row_state[i] = ~value & ((1 << row_num) - 1);
873 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
876 /* KEYIFCOL reg clear */
877 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
879 if (machine_is_aquila() || machine_is_kessler()) {
881 if (row_state[1] & 0x2)
883 if (board_is_neptune()) {
884 /* home & volume down */
885 if ((row_state[1] & 0x1) && (row_state[1] & 0x2))
888 /* cam full shot & volume down */
889 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
892 } else if (machine_is_geminus())
893 /* volume down & home */
894 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
898 setenv("bootcmd", "usbdown");
901 static void check_battery(int mode)
903 unsigned char val[2];
904 unsigned char addr = 0x36; /* max17040 fuel gauge */
906 i2c_set_bus_num(I2C_GPIO3);
908 if (machine_is_aquila()) {
911 } else if (machine_is_kessler())
912 i2c_set_bus_num(I2C_GPIO7);
913 else if (machine_is_cypress()) {
914 i2c_set_bus_num(I2C_GPIO7);
915 } else if (machine_is_geminus()) {
917 i2c_set_bus_num(I2C_GPIO7);
921 if (i2c_probe(addr)) {
922 printf("Can't found max17040 fuel gauge\n");
926 /* mode 0: check mode / 1: enable mode */
930 i2c_write(addr, 0xfe, 1, val, 2);
932 i2c_read(addr, 0x04, 1, val, 1);
933 dprintf("battery:\t%d%%\n", val[0]);
934 battery_soc = val[0];
938 static void check_mhl(void)
940 unsigned char val[2];
941 unsigned char addr = 0x39; /* SIL9230 */
943 /* MHL Power enable */
944 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
945 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
947 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
948 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
950 /* 10ms required after reset */
954 gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
956 i2c_set_bus_num(I2C_GPIO5);
959 if (i2c_probe(addr)) {
960 printf("Can't found MHL Chip\n");
966 * set to Normal operation
969 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
970 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
975 * 00 = MHL termination ON
976 * 11 = MHL termination OFF
979 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
980 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
983 #define CHARGER_ANIMATION_FRAME 6
984 static void max8998_clear_interrupt(void)
986 unsigned char addr, val[2];
987 i2c_set_bus_num(I2C_PMIC);
989 if (i2c_probe(addr)) {
990 printf("Can't found max8998\n");
994 i2c_read(addr, 0x00, 1, val, 1);
995 i2c_read(addr, 0x01, 1, val, 1);
996 i2c_read(addr, 0x02, 1, val, 1);
997 i2c_read(addr, 0x03, 1, val, 1);
1000 static int max8998_power_key(void)
1002 unsigned char addr, val[2];
1003 i2c_set_bus_num(I2C_PMIC);
1005 if (i2c_probe(addr)) {
1006 printf("Can't found max8998\n");
1010 /* Accessing IRQ1 register */
1011 i2c_read(addr, 0x00, 1, val, 1);
1012 if (val[0] & (1 << 6))
1018 static int max8998_has_ext_power_source(void)
1020 unsigned char addr, val[2];
1021 i2c_set_bus_num(I2C_PMIC);
1023 if (i2c_probe(addr)) {
1024 printf("Can't found max8998\n");
1028 /* Accessing STATUS2 register */
1029 i2c_read(addr, 0x09, 1, val, 1);
1030 if (val[0] & (1 << 5))
1036 struct thermister_stat {
1041 static struct thermister_stat adc_to_temperature_data[] = {
1042 { .centigrade = -20, .adc = 1856, },
1043 { .centigrade = -15, .adc = 1799, },
1044 { .centigrade = -10, .adc = 1730, },
1045 { .centigrade = -5, .adc = 1649, },
1046 { .centigrade = 0, .adc = 1556, },
1047 { .centigrade = 5, .adc = 1454, },
1048 { .centigrade = 10, .adc = 1343, },
1049 { .centigrade = 15, .adc = 1227, },
1050 { .centigrade = 20, .adc = 1109, },
1051 { .centigrade = 25, .adc = 992, },
1052 { .centigrade = 30, .adc = 880, },
1053 { .centigrade = 35, .adc = 773, },
1054 { .centigrade = 40, .adc = 675, },
1055 { .centigrade = 45, .adc = 586, },
1056 { .centigrade = 50, .adc = 507, },
1057 { .centigrade = 55, .adc = 436, },
1058 { .centigrade = 58, .adc = 399, },
1059 { .centigrade = 63, .adc = 343, },
1060 { .centigrade = 65, .adc = 322, },
1064 #define USHRT_MAX 0xFFFFU
1066 static int adc_to_temperature_centigrade(unsigned short adc)
1070 /* low_*: Greatest Lower Bound,
1071 * * * * high_*: Smallest Upper Bound */
1072 int low_temp, high_temp;
1073 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1074 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1075 if (adc_to_temperature_data[i].adc <= adc &&
1076 adc_to_temperature_data[i].adc >= low_adc) {
1077 low_temp = adc_to_temperature_data[i].centigrade;
1078 low_adc = adc_to_temperature_data[i].adc;
1080 if (adc_to_temperature_data[i].adc >= adc &&
1081 adc_to_temperature_data[i].adc <= high_adc) {
1082 high_temp = adc_to_temperature_data[i].centigrade;
1083 high_adc = adc_to_temperature_data[i].adc;
1087 /* Linear approximation between cloest low and high,
1088 * which is the weighted average of the two. */
1090 /* The following equation is correct only when the two are different */
1091 if (low_adc == high_adc)
1093 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1094 return 20; /* The room temperature */
1097 if (high_adc == USHRT_MAX)
1100 approximation = low_temp * (adc - low_adc) +
1101 high_temp * (high_adc - adc);
1102 approximation /= high_adc - low_adc;
1104 return approximation;
1107 static unsigned short get_adc_value(int channel)
1109 struct s5pc110_adc *adc = (struct s5pc110_adc *) S5PC110_ADC_BASE;
1110 unsigned short ret = 0;
1114 unsigned int loop = 0;
1116 if (machine_is_kessler())
1118 else if (machine_is_geminus())
1120 else if (machine_is_wmg160())
1122 else if (machine_is_cypress())
1124 else if (machine_is_tickertape())
1126 else if (machine_is_aquila())
1129 else if (machine_is_p1p2())
1133 sprintf(buf, "pmic ldo %d on", ldonum);
1134 run_command(buf, 0);
1136 writel(channel & 0xF, &adc->adcmux);
1137 writel((1 << 14) | (49 << 6), &adc->adccon);
1138 writel(1000 & 0xffff, &adc->adcdly);
1139 writel(readl(&adc->adccon) | (1 << 16), &adc->adccon); /* 12 bit */
1141 writel(readl(&adc->adccon) | (1 << 0), &adc->adccon); /* Enable */
1146 reg = readl(&adc->adccon);
1147 } while (!reg & (1 << 15) && loop++ < 1000);
1149 ret = readl(&adc->adcdat0) & 0xFFF;
1150 sprintf(buf, "pmic ldo %d off", ldonum);
1151 run_command(buf, 0);
1156 static int adc_get_average_ambient_temperature(void)
1158 if (machine_is_kessler()) {
1159 unsigned short min = USHRT_MAX;
1160 unsigned short max = 0;
1161 unsigned int sum = 0;
1162 unsigned int measured = 0;
1165 for (i = 0; i < 7; i++) {
1166 unsigned short measurement = get_adc_value(6);
1169 if (min > measurement)
1171 if (max < measurement)
1174 if (measured >= 3) {
1180 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1181 adc_to_temperature_centigrade(sum), sum);
1182 return adc_to_temperature_centigrade(sum);
1185 return 20; /* 20 Centigrade */
1188 enum temperature_level {
1196 static enum temperature_level temperature_check(void)
1198 int temp = adc_get_average_ambient_temperature();
1200 return _TEMP_TOO_LOW;
1202 return _TEMP_OK_LOW;
1204 return _TEMP_TOO_HIGH;
1206 return _TEMP_OK_HIGH;
1210 extern void lcd_display_clear(void);
1211 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1213 static void charger_en(int enable)
1219 unsigned char addr = 0xCC >> 1; /* max8998 */
1220 unsigned char val[2];
1222 i2c_set_bus_num(I2C_PMIC);
1223 if (i2c_probe(addr)) {
1224 printf("Can't found max8998 (%s:%d)\n", __func__, __LINE__);
1229 printf("Disable the charger.\n");
1230 i2c_read(addr, 0x0D, 1, val, 1);
1233 i2c_write(addr, 0x0D, 1, val, 1);
1235 i2c_read(addr, 0x0C, 1, val, 1);
1236 val[0] &= ~(0x7 << 0);
1237 val[0] &= ~(0x7 << 5);
1238 if (enable == 600) {
1239 val[0] |= 5; /* 600mA */
1240 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1241 } else { /* Assume 475 mA */
1243 val[0] |= 2; /* 475mA */
1244 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1246 i2c_write(addr, 0x0C, 1, val, 1);
1248 i2c_read(addr, 0x0D, 1, val, 1);
1250 i2c_write(addr, 0x0D, 1, val, 1);
1251 printf("Enable the charger @ %dmA\n", enable);
1255 void lcd_power_on(unsigned int onoff);
1257 static void into_charge_mode(void)
1263 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1264 unsigned int reg, wakeup_stat;
1265 int charger_speed = 600;
1267 max8998_clear_interrupt();
1269 printf("Charge Mode\n");
1270 charger_en(charger_speed);
1272 #ifdef CONFIG_S5PC1XXFB
1275 /* TODO: write the image-text for the charger */
1277 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1278 if (level >= CHARGER_ANIMATION_FRAME)
1279 level = CHARGER_ANIMATION_FRAME - 1;
1281 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1282 bmp_addr[i] = (ulong)battery_charging_animation[i];
1284 lcd_display_clear();
1285 for (i = 0; i < 3; i++) {
1286 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1289 bmp = gunzip_bmp(bmp_addr[j], &len);
1290 lcd_display_bitmap((ulong) bmp, 140, 202);
1293 for (k = 0; k < 10; k++)
1294 if (max8998_power_key()) {
1295 lcd_display_clear();
1296 goto restore_screen;
1297 } else if (!max8998_has_ext_power_source()) {
1298 lcd_display_clear();
1299 goto restore_screen;
1306 /* Disable the display to prevent flickering */
1307 /* TODO: how to reenable the display later? */
1311 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1312 unsigned int org, org_ip3, org_tcfg0;
1313 enum temperature_level previous_state = _TEMP_OK;
1315 empty_device_info_buffer();
1316 if (max8998_power_key())
1318 else if (!max8998_has_ext_power_source())
1321 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1322 org_ip3 = readl(0xE010046C);
1323 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1325 reg = org = readl(&rtc->rtccon);
1327 writel(reg, &rtc->rtccon);
1329 reg = readl(&rtc->rtccon);
1330 writel(reg | (1 << 3), &rtc->rtccon);
1332 writel(reg & ~(1 << 3), &rtc->rtccon);
1335 reg = readl(&rtc->rtccon);
1336 reg &= ~((1 << 8) | (0xF << 4));
1337 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1338 writel(reg, &rtc->rtccon);
1340 reg = 15 * 4 - 1; /* 15 sec */
1341 writel(reg, &rtc->ticcnt);
1343 /* EVT0: sleep 1, EVT1: sleep */
1344 if (cpu_is_s5pc110()) {
1345 char *name = "dummy";
1346 char *usage = "N/A";
1353 if (s5pc1xx_get_cpu_rev() == 0) {
1354 char *argv[] = {"1", "1"};
1355 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1357 char *argv[] = {"0", "0"};
1358 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1361 printf("\n\n\nERROR: this is not S5PC110.\n\n\n");
1365 /* Check TEMP HIGH/LOW */
1366 switch (temperature_check()) {
1368 charger_en(charger_speed);
1369 previous_state = _TEMP_OK;
1373 previous_state = _TEMP_TOO_LOW;
1375 case _TEMP_TOO_HIGH:
1377 previous_state = _TEMP_TOO_HIGH;
1380 if (previous_state == _TEMP_TOO_LOW) {
1383 charger_en(charger_speed);
1384 previous_state = _TEMP_OK;
1388 if (previous_state == _TEMP_TOO_HIGH) {
1391 charger_en(charger_speed);
1392 previous_state = _TEMP_OK;
1397 writel(org, &rtc->rtccon);
1398 writel(org_tcfg0, 0xE2600000);
1399 writel(org_ip3, 0xE010046C);
1401 } while (wakeup_stat == 0x04); /* RTC TICK */
1404 /* TODO: Reenable logo display (not working yet) */
1406 drv_lcd_init_resume();
1409 static int fsa9480_probe(void)
1411 unsigned char addr = 0x25;
1413 if (cpu_is_s5pc100())
1416 if (board_is_limo_real()) {
1417 if (hwrevision(0) || hwrevision(1))
1421 i2c_set_bus_num(I2C_PMIC);
1423 if (machine_is_kessler()) {
1424 i2c_set_bus_num(I2C_GPIO6);
1425 } else if (machine_is_cypress()) {
1426 i2c_set_bus_num(I2C_GPIO6);
1427 } else if (machine_is_geminus()) {
1429 i2c_set_bus_num(I2C_GPIO6);
1430 } else if (machine_is_wmg160()) {
1431 i2c_set_bus_num(I2C_GPIO6);
1434 if (i2c_probe(addr)) {
1435 printf("Can't found fsa9480\n");
1442 static void check_micro_usb(int intr)
1445 unsigned char val[2];
1446 static int started_charging_once = 0;
1449 if (fsa9480_probe())
1452 addr = 0x25; /* fsa9480 */
1454 /* Clear Interrupt */
1456 i2c_read(addr, 0x03, 1, val, 2);
1460 /* Read Device Type 1 */
1461 i2c_read(addr, 0x0a, 1, val, 1);
1463 #define FSA_DEV1_CHARGER (1 << 6)
1464 #define FSA_DEV1_UART (1 << 3)
1465 #define FSA_DEV1_USB (1 << 2)
1466 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1467 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1470 * If USB, use default 475mA
1471 * If Charger, use 600mA and go to charge mode
1473 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1474 started_charging_once = 1;
1476 /* If it's full, do not charge. */
1477 if (battery_soc < 100)
1481 } else if (val[0] & FSA_DEV1_USB) {
1482 if (battery_soc < 100)
1483 charger_en(475); /* enable charger and keep booting */
1488 /* If Factory Mode is Boot ON-USB, go to download mode */
1489 i2c_read(addr, 0x07, 1, val, 1);
1491 #define FSA_ADC_FAC_USB_OFF 0x18
1492 #define FSA_ADC_FAC_USB_ON 0x19
1493 #define FSA_ADC_FAC_UART 0x1d
1495 if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1496 setenv("bootcmd", "usbdown");
1498 path = getenv("usb");
1500 if (!strncmp(path, "cp", 2))
1501 run_command("microusb cp", 0);
1504 static void micro_usb_switch(int path)
1507 unsigned char val[2];
1509 if (fsa9480_probe())
1512 addr = 0x25; /* fsa9480 */
1515 val[0] = 0x90; /* VAUDIO */
1517 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1519 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1521 i2c_read(addr, 0x2, 1, val, 1);
1522 val[0] &= ~(1 << 2); /* Manual switching */
1523 i2c_write(addr, 0x2, 1, val, 1);
1526 #define MAX8998_REG_ONOFF1 0x11
1527 #define MAX8998_REG_ONOFF2 0x12
1528 #define MAX8998_REG_ONOFF3 0x13
1529 #define MAX8998_REG_LDO7 0x21
1530 #define MAX8998_REG_LDO17 0x29
1532 #define MAX8998_LDO3 (1 << 2)
1534 #define MAX8998_LDO6 (1 << 7)
1535 #define MAX8998_LDO7 (1 << 6)
1536 #define MAX8998_LDO8 (1 << 5)
1537 #define MAX8998_LDO9 (1 << 4)
1538 #define MAX8998_LDO10 (1 << 3)
1539 #define MAX8998_LDO11 (1 << 2)
1540 #define MAX8998_LDO12 (1 << 1)
1541 #define MAX8998_LDO13 (1 << 0)
1543 #define MAX8998_LDO14 (1 << 7)
1544 #define MAX8998_LDO15 (1 << 6)
1545 #define MAX8998_LDO16 (1 << 5)
1546 #define MAX8998_LDO17 (1 << 4)
1549 static void init_pmic(void)
1552 unsigned char val[2];
1554 if (cpu_is_s5pc100())
1557 i2c_set_bus_num(I2C_PMIC);
1559 addr = 0xCC >> 1; /* max8998 */
1560 if (i2c_probe(addr)) {
1561 printf("Can't found max8998\n");
1566 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1567 val[0] &= ~MAX8998_LDO3;
1568 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1571 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1573 * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1574 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1576 val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1577 MAX8998_LDO12 | MAX8998_LDO13);
1579 if (machine_is_kessler())
1580 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1582 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1583 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1585 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1587 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1588 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1590 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1591 MAX8998_LDO16 | MAX8998_LDO17);
1593 if (machine_is_kessler())
1594 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1596 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1597 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1600 static void setup_power_down_mode_registers(void)
1602 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1603 struct s5pc1xx_gpio_bank *bank;
1604 struct gpio_powermode *p;
1606 struct gpio_external *ge;
1608 struct s5pc1xx_gpio_item *mr;
1612 if (cpu_is_s5pc100())
1615 /* Only Limo real and kessler supports worked for sleep currnet */
1616 if (machine_is_aquila()) {
1617 if (board_is_limo_real())
1621 } else if (machine_is_kessler()) {
1623 } else if (machine_is_geminus()) {
1629 if (machine_is_aquila()) {
1630 /* Aquila rev 0.8 or lower */
1631 p = aquila_powerdown_modes;
1632 ge = aquila_external_powerdown_modes;
1633 mr = aquila_mirror_powerdown_mode;
1634 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1635 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1636 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1637 } else if (machine_is_kessler()) {
1638 /* Aquila rev 0.9 */
1639 p = kessler_powerdown_modes;
1640 ge = kessler_external_powerdown_modes;
1641 mr = kessler_mirror_powerdown_mode;
1642 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1643 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1644 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1645 } else if (machine_is_geminus()) {
1646 if (hwrevision(1)) {
1647 /* Same as Aquila rev 0.9 */
1649 p = kessler_powerdown_modes;
1650 ge = kessler_external_powerdown_modes;
1651 mr = kessler_mirror_powerdown_mode;
1652 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1653 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1654 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1656 p = aquila_powerdown_modes;
1657 ge = aquila_external_powerdown_modes;
1658 mr = aquila_mirror_powerdown_mode;
1659 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1660 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1661 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1663 } else if (hwrevision(0)) {
1664 /* Same as Aquila rev 0.8 or lower */
1665 p = aquila_powerdown_modes;
1666 ge = aquila_external_powerdown_modes;
1667 mr = aquila_mirror_powerdown_mode;
1668 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1669 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1670 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1672 return; /* Not supported */
1676 bank = &gpio->gpio_a0;
1678 for (i = 0; i < n_p; i++, p++, bank++) {
1679 writel(p->conpdn, &bank->pdn_con);
1680 writel(p->pudpdn, &bank->pdn_pull);
1683 writel(0xff0022b0, (unsigned int *)0xF0000000);
1684 writel(0xff0022b0, (unsigned int *)0xF1400000);
1686 bank = &gpio->gpio_h0;
1688 for (i = 0; i < n_ge; i++) {
1689 writel(ge->con, &bank->con);
1690 writel(ge->dat, &bank->dat);
1691 writel(ge->pud, &bank->pull);
1697 for (i = 0; i < n_mr; i++) {
1698 unsigned int reg = readl(&mr->bank->pdn_con);
1699 reg &= ~(1 << mr->number);
1700 if (readl(&mr->bank->dat) & (1 << mr->number))
1701 reg |= 1 << mr->number;
1702 writel(reg, &mr->bank->pdn_con);
1708 #include "../../../drivers/video/s5p-spi.h"
1710 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1711 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1713 struct spi_platform_data spi_pd;
1715 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1717 void lcd_cfg_gpio(void)
1719 unsigned int i, f3_end = 4;
1721 for (i = 0; i < 8; i++) {
1722 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1723 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1724 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1725 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1726 /* pull-up/down disable */
1727 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1728 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1729 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1731 /* drive strength to max (24bit) */
1732 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4X);
1733 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1734 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4X);
1735 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1736 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4X);
1737 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1740 /* set DISPLAY_DE_B pin for dual rgb mode. */
1741 if (board_is_media())
1744 for (i = 0; i < f3_end; i++) {
1745 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1746 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1747 /* pull-up/down disable */
1748 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1749 /* drive strength to max (24bit) */
1750 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4X);
1751 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1753 /* display output path selection (only [1:0] valid) */
1754 writel(0x2, 0xE0107008);
1756 /* gpio pad configuration for LCD reset. */
1757 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1759 /* gpio pad configuration for LCD ON. */
1760 gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1762 /* LCD_BACKLIGHT_EN */
1763 if (machine_is_geminus())
1764 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1765 if (board_is_neptune()) {
1766 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 4, GPIO_OUTPUT);
1767 gpio_direction_output(&gpio_base->gpio_mp0_4, 4, 0);
1771 * gpio pad configuration for
1772 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1774 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1775 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1776 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1777 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1779 if (machine_is_aquila() || machine_is_kessler()) {
1780 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1782 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1784 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1786 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1789 if (board_is_neptune())
1790 s6d16a0x_set_platform_data(&spi_pd);
1792 s6e63m0_set_platform_data(&spi_pd);
1793 if (board_is_media())
1798 if (machine_is_cypress()) {
1799 #if 0 /* universal cypress */
1801 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1804 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1806 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1808 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1810 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1812 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1813 #if 0 /* universal cypress */
1814 pd_cs.bank = &gpio_base->gpio_mp0_1;
1817 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1819 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1821 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1826 /* these data would be sent to s6e63m0 lcd panel driver. */
1827 s6e63m0_set_platform_data(&spi_pd);
1833 #define SWRST_REG 0x00
1834 #define LEDCON_REG 0x01
1835 #define LED_CUR_SET_REG 0x03
1836 #define LED_CUR_TR_REG 0x08
1839 #define NORMAL_MODE 0x01
1840 #define CUR_SET 0x63
1843 void backlight_on(unsigned int onoff)
1847 unsigned char val[2];
1848 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1851 if (machine_is_geminus())
1852 gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1854 if (machine_is_geminus())
1855 gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1858 if (machine_is_kessler() && board_is_neptune()) {
1859 gpio_set_value(&gpio->gpio_mp0_4, 4, 1);
1862 i2c_set_bus_num(I2C_GPIO5);
1865 if (i2c_probe(addr)) {
1866 if (i2c_probe(addr)) {
1867 printf("Can't found s6d16a0x backlight i2c\n");
1872 i2c_write(addr, SWRST_REG, 1, val, 1);
1875 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1877 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1878 val[0] = NORMAL_MODE;
1879 i2c_write(addr, LEDCON_REG, 1, val, 1);
1884 void reset_lcd(void)
1886 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1888 if (machine_is_aquila() || machine_is_kessler() || machine_is_geminus())
1889 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1890 if (machine_is_cypress())
1891 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1894 void lcd_power_on(unsigned int onoff)
1896 struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1899 if (machine_is_aquila() || machine_is_geminus())
1900 gpio_set_value(&gpio->gpio_j1, 3, 1);
1902 if (machine_is_cypress())
1903 gpio_set_value(&gpio->gpio_g2, 2, 1);
1905 if (machine_is_kessler()) {
1907 unsigned char val[2];
1908 unsigned char val2[2];
1910 gpio_set_value(&gpio->gpio_j1, 3, 1);
1912 i2c_set_bus_num(I2C_PMIC);
1913 addr = 0xCC >> 1; /* max8998 */
1914 if (i2c_probe(addr)) {
1915 printf("Can't found max8998\n");
1918 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1919 val[0] &= ~(MAX8998_LDO17);
1920 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1921 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1923 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1924 val[0] |= MAX8998_LDO17;
1926 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1927 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1929 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1930 val[0] |= MAX8998_LDO7;
1932 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1933 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1936 if (machine_is_aquila() || machine_is_geminus())
1937 gpio_set_value(&gpio->gpio_j1, 3, 0);
1939 if (machine_is_cypress())
1940 gpio_set_value(&gpio->gpio_g2, 2, 0);
1942 if (machine_is_kessler()) {
1944 unsigned char val[2];
1946 gpio_set_value(&gpio->gpio_j1, 3, 0);
1948 i2c_set_bus_num(I2C_PMIC);
1949 addr = 0xCC >> 1; /* max8998 */
1950 if (i2c_probe(addr)) {
1951 printf("Can't found max8998\n");
1955 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1956 val[0] &= ~(MAX8998_LDO7);
1957 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1958 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1960 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1961 val[0] &= ~(MAX8998_LDO17);
1962 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1963 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1968 extern void s6e63m0_cfg_ldo(void);
1969 extern void s6e63m0_enable_ldo(unsigned int onoff);
1970 extern void s6d16a0x_cfg_ldo(void);
1971 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1973 int s5p_no_lcd_support(void)
1975 if (machine_is_wmg160())
1980 void init_panel_info(vidinfo_t *vid)
1982 vid->cfg_gpio = NULL;
1983 vid->reset_lcd = NULL;
1984 vid->backlight_on = NULL;
1985 vid->lcd_power_on = NULL;
1987 vid->cfg_ldo = NULL;
1988 vid->enable_ldo = NULL;
1990 vid->init_delay = 0;
1991 vid->reset_delay = 0;
1992 vid->power_on_delay = 0;
1997 vid->vl_width = 480;
1998 vid->vl_height = 800;
2000 vid->dual_lcd_enabled = 0;
2002 if (board_is_media()) {
2005 vid->vl_width = 960;
2006 vid->vl_height = 800;
2008 /* enable dual lcd mode. */
2009 vid->dual_lcd_enabled = 1;
2012 vid->vl_clkp = CONFIG_SYS_HIGH;
2013 vid->vl_hsp = CONFIG_SYS_LOW;
2014 vid->vl_vsp = CONFIG_SYS_LOW;
2015 vid->vl_dp = CONFIG_SYS_HIGH;
2018 /* S6E63M0 LCD Panel */
2027 if (machine_is_aquila() || machine_is_kessler()
2028 || machine_is_cypress()) {
2029 vid->cfg_gpio = lcd_cfg_gpio;
2030 vid->reset_lcd = reset_lcd;
2031 vid->backlight_on = backlight_on;
2032 vid->lcd_power_on = lcd_power_on;
2033 vid->cfg_ldo = s6e63m0_cfg_ldo;
2034 vid->enable_ldo = s6e63m0_enable_ldo;
2036 vid->init_delay = 25000;
2037 vid->reset_delay = 120000;
2040 if (board_is_neptune()) {
2044 vid->vl_width = 320;
2045 vid->vl_height = 480;
2047 vid->vl_clkp = CONFIG_SYS_HIGH;
2048 vid->vl_hsp = CONFIG_SYS_HIGH;
2049 vid->vl_vsp = CONFIG_SYS_HIGH;
2050 vid->vl_dp = CONFIG_SYS_LOW;
2053 /* disable dual lcd mode. */
2054 vid->dual_lcd_enabled = 0;
2056 /* S6D16A0X LCD Panel */
2065 vid->cfg_gpio = lcd_cfg_gpio;
2066 vid->backlight_on = backlight_on;
2067 vid->lcd_power_on = lcd_power_on;
2068 vid->reset_lcd = reset_lcd;
2069 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2070 vid->enable_ldo = s6d16a0x_enable_ldo;
2072 vid->init_delay = 10000;
2073 vid->power_on_delay = 10000;
2074 vid->reset_delay = 1000;
2078 if (machine_is_geminus()) {
2082 vid->vl_width = 1024,
2083 vid->vl_height = 600,
2084 vid->vl_clkp = CONFIG_SYS_LOW,
2085 vid->vl_hsp = CONFIG_SYS_HIGH,
2086 vid->vl_vsp = CONFIG_SYS_HIGH,
2087 vid->vl_dp = CONFIG_SYS_LOW,
2098 vid->cfg_gpio = lcd_cfg_gpio;
2099 vid->reset_lcd = reset_lcd;
2100 vid->backlight_on = backlight_on;
2101 vid->lcd_power_on = lcd_power_on;
2107 vid->vl_width = 480,
2108 vid->vl_height = 800,
2109 vid->vl_clkp = CONFIG_SYS_HIGH,
2110 vid->vl_hsp = CONFIG_SYS_LOW,
2111 vid->vl_vsp = CONFIG_SYS_LOW,
2112 vid->vl_dp = CONFIG_SYS_HIGH,
2128 vid->vl_width = 1024,
2129 vid->vl_height = 600,
2130 vid->vl_clkp = CONFIG_SYS_HIGH,
2131 vid->vl_hsp = CONFIG_SYS_HIGH,
2132 vid->vl_vsp = CONFIG_SYS_HIGH,
2133 vid->vl_dp = CONFIG_SYS_LOW,
2136 /* AMS701KA AMOLED Panel. */
2148 static void setup_meminfo(void)
2150 char meminfo[64] = {0, };
2151 int count = 0, size, real;
2153 size = gd->bd->bi_dram[0].size >> 20;
2154 count += sprintf(meminfo + count, "mem=%dM", size);
2156 /* Each Chip Select can't exceed the 256MiB */
2157 size = gd->bd->bi_dram[1].size >> 20;
2158 real = min(size, 256);
2159 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2160 real, (unsigned int)gd->bd->bi_dram[1].start);
2164 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2165 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2168 setenv("meminfo", meminfo);
2171 int misc_init_r(void)
2174 /* It should be located at first */
2177 if (machine_is_aquila() || machine_is_kessler()) {
2178 if (board_is_neptune())
2179 setenv("lcdinfo", "lcd=s6d16a0x");
2180 else if (board_is_media())
2181 setenv("lcdinfo", "lcd=s6e63m0");
2183 setenv("lcdinfo", "lcd=s6e63m0");
2185 if (machine_is_geminus())
2186 setenv("lcdinfo", "lcd=lms480jc01");
2187 if (machine_is_cypress())
2188 setenv("lcdinfo", "lcd=s6e63m0");
2194 /* Set proper PMIC pins */
2197 /* Check auto burning */
2200 /* To power up I2C2 */
2203 /* Enable T-Flash at Limo Real or Limo Universal */
2206 /* Setup Limo Real board GPIOs */
2207 setup_limo_real_gpios();
2209 /* Setup Media board GPIOs */
2210 setup_media_gpios();
2212 /* To usbdown automatically */
2218 #ifdef CONFIG_S5PC1XXFB
2219 display_device_info();
2222 setup_power_down_mode_registers();
2224 /* check max17040 */
2234 int board_init(void)
2236 /* Set Initial global variables */
2237 s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
2239 gd->bd->bi_arch_number = MACH_AQUILA;
2240 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2242 /* Check H/W Revision */
2243 check_hw_revision();
2250 unsigned int base, memconfig0, size;
2251 unsigned int memconfig1, sz = 0;
2253 if (cpu_is_s5pc100()) {
2254 /* In mem setup, we swap the bank. So below size is correct */
2255 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2256 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
2257 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
2260 /* In S5PC110, we can't swap the DMC0/1 */
2261 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2262 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2264 base = S5PC110_DMC1_BASE;
2265 /* DMC configuration */
2266 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2267 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2269 size = (memconfig0 >> 16) & 0xFF;
2270 size = ((unsigned char) ~size) + 1;
2273 * (0x07 + 1) * 16 = 128 MiB
2274 * (0x0f + 1) * 16 = 256 MiB
2279 * Aquila Rev0.5 4G3G1G
2280 * Aquila Rev0.8 4G3G1G
2281 * Aquila Rev0.9 4G3G1G
2283 if (machine_is_aquila() || machine_is_kessler())
2284 if (hwrevision(5) || hwrevision(8) || hwrevision(9)) {
2285 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2287 sz = (memconfig1 >> 16) & 0xFF;
2288 sz = ((unsigned char) ~sz) + 1;
2294 * bi_dram[1].size contains all DMC1 memory size
2296 gd->bd->bi_dram[1].size = (size + sz) << 20;
2301 /* Used for sleep test */
2302 static unsigned char saved_val[4][2];
2303 void board_sleep_init_late(void)
2305 /* CODEC_LDO_EN: GPF3[4] */
2306 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
2307 /* CODEC_XTAL_EN: GPH3[2] */
2308 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
2310 /* MMC T_FLASH off */
2311 gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
2313 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
2314 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
2315 /* MHL_ON for REV02 or higher */
2316 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0);
2319 void board_sleep_init(void)
2322 unsigned char val[2];
2324 i2c_set_bus_num(I2C_PMIC);
2326 if (i2c_probe(addr)) {
2327 printf("Can't find max8998\n");
2331 if (machine_is_kessler()) {
2333 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2334 saved_val[0][0] = val[0];
2335 saved_val[0][1] = val[1];
2336 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2337 (1 << 1) | (1 << 0));
2338 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2339 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2342 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2343 saved_val[1][0] = val[0];
2344 saved_val[1][1] = val[1];
2345 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2346 (1 << 2) | (1 << 1) | (1 << 0));
2348 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2349 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2352 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2353 saved_val[2][0] = val[0];
2354 saved_val[2][1] = val[1];
2355 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2356 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2357 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2360 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2361 saved_val[3][0] = val[0];
2362 saved_val[3][1] = val[1];
2363 val[0] &= ~((1 << 6) | (1 << 4));
2364 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2365 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2367 printf("Turned off regulators with Kessler setting."
2368 " Preparing to sleep. [%s:%d]\n",
2369 __FILE__, __LINE__);
2370 } else { /* Default */
2372 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2373 saved_val[0][0] = val[0];
2374 saved_val[0][1] = val[1];
2375 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2376 (1 << 1) | (1 << 0));
2377 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2378 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2381 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2382 saved_val[1][0] = val[0];
2383 saved_val[1][1] = val[1];
2384 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2385 (1 << 2) | (1 << 1) | (1 << 0));
2387 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2388 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2391 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2392 saved_val[2][0] = val[0];
2393 saved_val[2][1] = val[1];
2394 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2395 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2396 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2399 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2400 saved_val[3][0] = val[0];
2401 saved_val[3][1] = val[1];
2402 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2403 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2404 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2406 printf("Turned off regulators with default(Aquila) setting."
2407 " Preparing to sleep. [%s:%d]\n",
2408 __FILE__, __LINE__);
2412 void board_sleep_resume(void)
2415 unsigned char val[2];
2419 i2c_set_bus_num(I2C_PMIC);
2421 if (i2c_probe(addr)) {
2422 printf("Can't find max8998\n");
2427 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2428 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2430 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2431 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2433 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2434 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2436 i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2437 i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2438 printf("Waked up.\n");
2440 /* check max17040 */
2447 #if defined(CONFIG_USB_GADGET_S3C_UDC_OTG)
2449 static int s5pc1xx_phy_control(int on)
2453 if (on && !status) {
2454 #ifdef CONFIG_CMD_PMIC
2455 run_command("pmic ldo 3 on", 0);
2458 if (board_is_limo_universal() ||
2459 board_is_limo_real() ||
2461 /* check usb path */
2462 if (board_is_limo_real() && !hwrevision(6))
2466 if (machine_is_tickertape())
2467 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2468 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2470 /* USB Path to AP */
2471 micro_usb_switch(0);
2473 } else if (!on && status) {
2474 #ifdef CONFIG_CMD_PMIC
2475 run_command("pmic ldo 3 off", 0);
2484 struct s3c_plat_otg_data s5pc110_otg_data = {
2485 .phy_control = s5pc1xx_phy_control,
2486 .regs_phy = S5PC110_PHY_BASE,
2487 .regs_otg = S5PC110_OTG_BASE,
2490 int board_eth_init(bd_t *bis)
2494 if (cpu_is_s5pc100())
2497 s3c_udc_probe(&s5pc110_otg_data);
2498 if (usb_eth_initialize(bis) >= 0)
2504 #ifdef CONFIG_CMD_USBDOWN
2505 int usb_board_init(void)
2507 #ifdef CONFIG_CMD_PMIC
2508 run_command("pmic ldo 3 on", 0);
2511 if (cpu_is_s5pc100()) {
2512 #ifdef CONFIG_HARD_I2C
2513 uchar val[2] = {0,};
2516 if (i2c_read(0x66, 0, 1, val, 2)) {
2517 printf("i2c_read error\n");
2524 if (i2c_write(0x66, 0, 1, val, 2)) {
2525 printf("i2c_write error\n");
2528 i2c_read(0x66, 0, 1, val, 2);
2534 if (board_is_limo_universal() ||
2535 board_is_limo_real() ||
2537 /* check usb path */
2538 if (board_is_limo_real() && !hwrevision(6))
2542 if (machine_is_tickertape())
2543 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2544 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2546 /* USB Path to AP */
2547 micro_usb_switch(0);
2553 #ifdef CONFIG_GENERIC_MMC
2554 int s5p_no_mmc_support(void)
2556 if (machine_is_wmg160())
2561 int board_mmc_init(bd_t *bis)
2565 struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2568 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2569 if (machine_is_kessler())
2570 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2572 if (machine_is_wmg160())
2575 /* MMC0 Clock source = SCLKMPLL */
2576 reg = readl(&clk->src4);
2579 writel(reg, &clk->src4);
2581 reg = readl(&clk->div4);
2584 /* set div value near 50MHz */
2585 clock = get_pll_clk(MPLL) / 1000000;
2586 for (i = 0; i < 0xf; i++) {
2587 if ((clock / (i + 1)) <= 50) {
2593 writel(reg, &clk->div4);
2599 * GPG0[2] SD_0_CDn -> Not used
2600 * GPG0[3:6] SD_0_DATA[0:3]
2602 for (i = 0; i < 7; i++) {
2605 /* GPG0[0:6] special function 2 */
2606 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2607 /* GPG0[0:6] pull disable */
2608 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2609 /* GPG0[0:6] drv 4x */
2610 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4X);
2613 return s5pc1xx_mmc_init(0);
2617 #ifdef CONFIG_CMD_PMIC
2618 static int pmic_status(void)
2620 unsigned char addr, val[2];
2623 i2c_set_bus_num(I2C_PMIC);
2625 if (i2c_probe(addr)) {
2626 printf("Can't found max8998\n");
2631 i2c_read(addr, reg, 1, val, 1);
2632 for (i = 7; i >= 4; i--)
2633 printf("BUCK%d %s\n", 7 - i + 1,
2634 val[0] & (1 << i) ? "on" : "off");
2636 printf("LDO%d %s\n", 5 - i,
2637 val[0] & (1 << i) ? "on" : "off");
2639 i2c_read(addr, reg, 1, val, 1);
2640 for (i = 7; i >= 0; i--)
2641 printf("LDO%d %s\n", 7 - i + 6,
2642 val[0] & (1 << i) ? "on" : "off");
2644 i2c_read(addr, reg, 1, val, 1);
2645 for (i = 7; i >= 4; i--)
2646 printf("LDO%d %s\n", 7 - i + 14,
2647 val[0] & (1 << i) ? "on" : "off");
2650 i2c_read(addr, reg, 1, val, 1);
2651 for (i = 7; i >= 6; i--)
2652 printf("SAFEOUT%d %s\n", 7 - i + 1,
2653 val[0] & (1 << i) ? "on" : "off");
2657 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2659 unsigned char addr, val[2];
2660 unsigned int reg, shift;
2668 } else if (ldo <= 13) {
2671 } else if (ldo <= 17) {
2673 shift = 17 - ldo + 4;
2680 shift = 4 - buck + 4;
2681 } else if (safeout) {
2685 shift = 8 - safeout;
2689 i2c_set_bus_num(I2C_PMIC);
2691 if (i2c_probe(addr)) {
2692 printf("Can't found max8998\n");
2696 i2c_read(addr, reg, 1, val, 1);
2698 val[0] |= (1 << shift);
2700 val[0] &= ~(1 << shift);
2701 i2c_write(addr, reg, 1, val, 1);
2702 i2c_read(addr, reg, 1, val, 1);
2705 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2706 val[0] & (1 << shift) ? "on" : "off");
2708 printf("buck %d value 0x%x, %s\n", buck, val[0],
2709 val[0] & (1 << shift) ? "on" : "off");
2711 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2712 val[0] & (1 << shift) ? "on" : "off");
2717 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2719 int buck = 0, ldo = 0, safeout = 0, on = -1;
2723 if (strncmp(argv[1], "status", 6) == 0)
2724 return pmic_status();
2727 if (strncmp(argv[1], "ldo", 3) == 0)
2728 ldo = simple_strtoul(argv[2], NULL, 10);
2729 else if (strncmp(argv[1], "buck", 4) == 0)
2730 buck = simple_strtoul(argv[2], NULL, 10);
2731 else if (strncmp(argv[1], "safeout", 7) == 0)
2732 safeout = simple_strtoul(argv[2], NULL, 10);
2736 if (strncmp(argv[3], "on", 2) == 0)
2738 else if (strncmp(argv[3], "off", 3) == 0)
2743 return pmic_ldo_control(buck, ldo, safeout, on);
2754 pmic, CONFIG_SYS_MAXARGS, 1, do_pmic,
2755 "PMIC LDO & BUCK control",
2756 "status - Display PMIC LDO & BUCK status\n"
2757 "pmic ldo num on/off - Turn on/off the LDO\n"
2758 "pmic buck num on/off - Turn on/off the BUCK\n"
2759 "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2763 #ifdef CONFIG_CMD_DEVICE_POWER
2777 static void power_display_devices(void)
2779 printf("devices:\n");
2780 printf("\t%d - touch\n", POWER_TOUCH);
2781 printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2782 printf("\t%d - LCD\n", POWER_LCD);
2783 printf("\t%d - Haptic\n", POWER_HAPTIC);
2784 printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2785 printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2786 printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2787 printf("\t%d - HDMI\n", POWER_HDMI);
2790 static int power_hdmi(int on)
2792 /* HDMI_EN1: GPJ2[2] */
2793 gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2794 /* MHL_ON: GPJ2[3] */
2795 gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2799 static int power_bt_wifi(int on)
2801 /* WLAN_BT_EN: GPB[5] */
2802 gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2806 static int power_fm_radio(int on)
2808 /* FM_BUS_nRST: GPJ2[5] */
2809 gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2813 static int power_audio_codec(int on)
2815 /* CODEC_LDO_EN: GPF3[4] */
2816 gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2817 /* CODEC_XTAL_EN: GPH3[2] */
2818 gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2822 static int power_haptic(int on)
2824 /* HAPTIC_ON: GPJ1[1] */
2825 gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2829 static int power_lcd(int on)
2831 /* MLCD_ON: GPJ1[3] */
2832 gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2836 static int power_touch(int on)
2838 /* TOUCH_EN: GPG3[6] */
2839 gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2843 static int power_3_touchkey(int on)
2846 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2847 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2848 if (board_rev & J1_B2_BOARD)
2849 gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2851 gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2853 /* 3_TOUCH_CE - GPJ2[6] */
2854 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2856 /* 3_TOUCH_CE - GPJ2[6] */
2857 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on); /* TOUCH_CE */
2862 unsigned char val[2];
2863 unsigned char addr = 0x20; /* mcs5000 3-touchkey */
2869 i2c_set_bus_num(I2C_GPIO10);
2871 /* Workaround to probe */
2872 if (i2c_probe(addr)) {
2873 if (i2c_probe(addr)) {
2874 printf("Can't found 3 touchkey\n");
2879 #define MCS5000_TK_HW_VERSION 0x06
2880 #define MCS5000_TK_FW_VERSION 0x0A
2881 #define MCS5000_TK_MI_VERSION 0x0B
2883 reg = MCS5000_TK_MI_VERSION;
2884 i2c_read(addr, reg, 1, val, 1);
2885 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2886 reg = MCS5000_TK_HW_VERSION;
2887 i2c_read(addr, reg, 1, val, 1);
2888 printf("H/W 0x%x, ", val[0]);
2889 reg = MCS5000_TK_FW_VERSION;
2890 i2c_read(addr, reg, 1, val, 1);
2891 printf("F/W 0x%x\n", val[0]);
2896 static int power_control(int device, int on)
2900 return power_touch(on);
2901 case POWER_3_TOUCHKEY:
2902 return power_3_touchkey(on);
2904 return power_lcd(on);
2906 return power_haptic(on);
2907 case POWER_AUDIO_CODEC:
2908 return power_audio_codec(on);
2909 case POWER_FM_RADIO:
2910 return power_fm_radio(on);
2912 return power_bt_wifi(on);
2914 return power_hdmi(on);
2916 printf("I don't know device %d\n", device);
2922 static int power_on(int on)
2925 power_3_touchkey(on);
2928 power_audio_codec(on);
2936 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2940 if (!machine_is_aquila() && !machine_is_kessler())
2945 if (strncmp(argv[1], "on", 2) == 0)
2947 if (strncmp(argv[1], "off", 3) == 0)
2951 device = simple_strtoul(argv[1], NULL, 10);
2955 if (strncmp(argv[2], "on", 2) == 0)
2957 else if (strncmp(argv[2], "off", 3) == 0)
2961 return power_control(device, on);
2967 power_display_devices();
2972 power, CONFIG_SYS_MAXARGS, 1, do_power,
2973 "Device Power Management control",
2974 "device on/off - Turn on/off the device\n"
2977 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2981 if (strncmp(argv[1], "cp", 2) == 0) {
2982 micro_usb_switch(1);
2983 pmic_ldo_control(0, 0, 2, 1);
2984 setenv("usb", "cp");
2985 } else if (strncmp(argv[1], "ap", 2) == 0) {
2986 micro_usb_switch(0);
2987 pmic_ldo_control(0, 0, 2, 0);
2988 setenv("usb", "ap");
2998 printf("USB Path is set to %s\n", getenv("usb"));
3004 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
3006 "cp - switch to CP\n"
3007 "microusb ap - switch to AP\n"