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>
41 #include <asm/errno.h>
46 #include <bmp_layout.h>
50 #include "animation_frames.h"
51 #include "gpio_setting.h"
52 #include "usb_mass_storage.h"
54 DECLARE_GLOBAL_DATA_PTR;
56 #define C100_MACH_START 3000
57 #define C110_MACH_START 3100
59 static unsigned int arch_number;
60 static unsigned int board_rev;
61 static unsigned int battery_soc;
62 static struct s5pc110_gpio *gpio;
80 static struct i2c_gpio_bus_data i2c_2 = {
90 static struct i2c_gpio_bus_data i2c_gpio3 = {
100 static struct i2c_gpio_bus_data i2c_pmic = {
110 static struct i2c_gpio_bus_data i2c_gpio5 = {
120 static struct i2c_gpio_bus_data i2c_gpio6 = {
130 static struct i2c_gpio_bus_data i2c_gpio7 = {
136 * i2c gpio7 - cypress
140 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
150 static struct i2c_gpio_bus_data i2c_gpio10 = {
155 static struct i2c_gpio_bus i2c_gpio[I2C_NUM];
157 u32 get_board_rev(void)
162 static int hwrevision(int rev)
164 return (board_rev & 0xf) == rev;
171 MACH_P1P2, /* Don't remove it */
180 #define SPLIT_SCREEN_FEATURE 0x100
182 /* board is MACH_AQUILA and board is like below. */
183 #define J1_B2_BOARD 0x0200
184 #define LIMO_UNIVERSAL_BOARD 0x0400
185 #define LIMO_REAL_BOARD 0x0800
186 #define MEDIA_BOARD 0x1000
187 #define BAMBOO_BOARD 0x2000
189 /* board is MACH_GONI and board is like below */
190 #define S1_BOARD 0x1000
191 #define HAYDN_BOARD 0x2000
192 #define KESSLER_BOARD 0x4000
193 #define SDK_BOARD 0x8000
195 #define BOARD_MASK 0xFF00
197 static int c110_machine_id(void)
199 return arch_number - C110_MACH_START;
202 static int mach_is_aquila(void)
204 return arch_number == MACH_TYPE_AQUILA;
207 static int mach_is_tickertape(void)
209 return c110_machine_id() == MACH_TICKERTAPE;
212 static int mach_is_geminus(void)
214 return c110_machine_id() == MACH_GEMINUS;
217 static int mach_is_cypress(void)
219 return c110_machine_id() == MACH_CYPRESS;
222 static int board_is_limo_universal(void)
224 return mach_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
227 static int board_is_limo_real(void)
229 return mach_is_aquila() && (board_rev & LIMO_REAL_BOARD);
232 static int board_is_bamboo(void)
234 return mach_is_aquila() && (board_rev & BAMBOO_BOARD);
237 static int board_is_media(void)
239 return mach_is_aquila() && (board_rev & MEDIA_BOARD);
242 static int board_is_j1b2(void)
244 return mach_is_aquila() && (board_rev & J1_B2_BOARD);
248 static int mach_is_goni(void)
250 return arch_number == MACH_TYPE_GONI;
253 static int board_is_sdk(void)
255 return mach_is_goni() && (board_rev & SDK_BOARD);
258 static int board_is_s1(void)
260 return mach_is_goni() && (board_rev & S1_BOARD);
264 static int board_is_haydn(void)
266 return mach_is_goni() && (board_rev & HAYDN_BOARD);
270 static int mach_is_wmg160(void)
272 return c110_machine_id() == MACH_WMG160;
275 #ifdef CONFIG_AVS_TEST
276 static int board_has_AVS(void)
278 return board_is_sdk() && hwrevision(6);
281 static int board_has_AVS(void)
287 static void check_battery(int mode);
288 static void check_micro_usb(int intr);
290 static struct i2c_gpio_bus i2c_gpio[] = {
308 void i2c_init_board(void)
310 i2c_gpio[I2C_2].bus = &i2c_2;
311 i2c_gpio[I2C_GPIO3].bus = &i2c_gpio3;
312 i2c_gpio[I2C_PMIC].bus = &i2c_pmic;
313 i2c_gpio[I2C_GPIO5].bus = &i2c_gpio5;
314 i2c_gpio[I2C_GPIO6].bus = &i2c_gpio6;
315 i2c_gpio[I2C_GPIO7].bus = &i2c_gpio7;
316 i2c_gpio[I2C_GPIO10].bus = &i2c_gpio10;
318 if (mach_is_aquila()) {
319 i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
320 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
321 } else if (mach_is_goni()) {
322 i2c_gpio[I2C_GPIO7].bus->gpio_base =
323 (unsigned int)&gpio->mp0_5;
324 } else if (mach_is_cypress()) {
325 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
326 i2c_gpio[I2C_GPIO7].bus->gpio_base =
327 (unsigned int)&gpio->mp0_5;
329 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
332 if (board_has_AVS()) { /* no I2C2. it's used by AVS-IEM */
333 static int printed = 0;
334 struct s5p_gpio_bank *bank =
335 (struct s5p_gpio_bank *)(&gpio->d1);
336 /* set GPD1CON[4], [5] as IEM_SPWI/SCLK */
337 gpio_cfg_pin(bank, 4, 0x2); /* IEM_SCLK */
338 gpio_cfg_pin(bank, 5, 0x2); /* IEM_SPWI */
340 i2c_gpio[I2C_2].bus->gpio_base = 0;
342 puts("(I2C2 Diabled. AVS Mode) ");
346 i2c_gpio[I2C_2].bus->gpio_base =
347 (unsigned int)&gpio->d1;
350 i2c_gpio[I2C_GPIO3].bus->gpio_base =
351 (unsigned int)&gpio->j3;
352 i2c_gpio[I2C_PMIC].bus->gpio_base =
353 (unsigned int)&gpio->j4;
354 i2c_gpio[I2C_GPIO5].bus->gpio_base =
355 (unsigned int)&gpio->mp0_5;
356 i2c_gpio[I2C_GPIO6].bus->gpio_base =
357 (unsigned int)&gpio->j3;
359 i2c_gpio_init(i2c_gpio, I2C_NUM, I2C_PMIC);
361 /* Reset on fsa9480 early */
363 /* Reset on max17040 early */
367 #ifdef CONFIG_MISC_INIT_R
368 #define DEV_INFO_LEN 256
369 static char device_info[DEV_INFO_LEN];
370 static int display_info;
372 static void empty_device_info_buffer(void)
374 memset(device_info, 0x0, DEV_INFO_LEN);
377 static void dprintf(const char *fmt, ...)
384 i = vsprintf(buf, fmt, args);
389 if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
390 puts("Flushing device info...\n");
392 empty_device_info_buffer();
394 strncat(device_info, buf, 127);
398 #ifdef CONFIG_S5PC1XXFB
399 static void display_device_info(void)
406 set_font_color(FONT_WHITE);
407 fb_printf(device_info);
410 memset(device_info, 0x0, DEV_INFO_LEN);
412 udelay(5 * 1000 * 1000);
416 static const char *board_name[] = {
420 "P1P2", /* Don't remove it */
433 static char feature_buffer[32];
435 static char *display_features(int board, int board_rev)
438 char *buf = feature_buffer;
441 if (board == MACH_TYPE_AQUILA) {
442 if (board_rev & SPLIT_SCREEN_FEATURE)
443 name = "SplitScreen";
444 if (board_rev & J1_B2_BOARD)
446 /* Limo Real or Universal */
447 if (board_rev & LIMO_REAL_BOARD)
449 else if (board_rev & LIMO_UNIVERSAL_BOARD)
450 name = "Limo Universal";
451 if (board_rev & MEDIA_BOARD)
453 if (board_rev & BAMBOO_BOARD)
455 } else if (board == MACH_TYPE_GONI) {
456 if (board_rev & SDK_BOARD) {
461 name = "SLP SDK 4.3inch";
462 else if (hwrevision(4))
463 name = "SLP SDK 4.5inch";
468 if (board_rev & S1_BOARD)
470 if (board_rev & HAYDN_BOARD)
474 count += sprintf(buf + count, " - %s", name);
479 static char *get_board_name(int board)
481 if (board == MACH_TYPE_AQUILA)
483 else if (board == MACH_TYPE_GONI)
485 else if (board == MACH_WMG160)
487 return (char *) board_name[board];
490 static void check_board_revision(int board, int rev)
492 if (board == MACH_TYPE_AQUILA) {
493 /* Limo Real or Universal */
494 if (rev & LIMO_UNIVERSAL_BOARD)
495 board_rev &= ~J1_B2_BOARD;
496 if (rev & LIMO_REAL_BOARD)
497 board_rev &= ~(J1_B2_BOARD |
498 LIMO_UNIVERSAL_BOARD);
499 if (rev & MEDIA_BOARD)
500 board_rev &= ~(J1_B2_BOARD |
501 LIMO_UNIVERSAL_BOARD);
502 if (rev & BAMBOO_BOARD)
503 board_rev &= ~(J1_B2_BOARD |
504 LIMO_UNIVERSAL_BOARD |
507 } else if (board == MACH_TYPE_GONI) {
508 if (rev & KESSLER_BOARD)
509 board_rev &= ~(J1_B2_BOARD |
510 LIMO_UNIVERSAL_BOARD);
512 board_rev &= ~(J1_B2_BOARD |
513 LIMO_UNIVERSAL_BOARD);
515 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
517 if (rev & HAYDN_BOARD)
518 board_rev &= ~(J1_B2_BOARD | LIMO_UNIVERSAL_BOARD |
521 board_rev &= ~BOARD_MASK;
525 static unsigned int get_hw_revision(struct s5p_gpio_bank *bank, int hwrev3)
529 gpio_direction_input(bank, 2);
530 gpio_direction_input(bank, 3);
531 gpio_direction_input(bank, 4);
532 gpio_direction_input(bank, hwrev3);
534 gpio_set_pull(bank, 2, GPIO_PULL_NONE); /* HWREV_MODE0 */
535 gpio_set_pull(bank, 3, GPIO_PULL_NONE); /* HWREV_MODE1 */
536 gpio_set_pull(bank, 4, GPIO_PULL_NONE); /* HWREV_MODE2 */
537 gpio_set_pull(bank, hwrev3, GPIO_PULL_NONE); /* HWREV_MODE3 */
539 rev = gpio_get_value(bank, 2);
540 rev |= (gpio_get_value(bank, 3) << 1);
541 rev |= (gpio_get_value(bank, 4) << 2);
542 rev |= (gpio_get_value(bank, hwrev3) << 3);
547 static void check_hw_revision(void)
549 unsigned int board = MACH_UNIVERSAL; /* Default is Universal */
555 * Note Check 'Aquila' board first
559 * LRA: Limo Real Aquila
560 * LUA: Limo Universal Aquila
565 * ADDR = 0xE0200000 + OFF
567 * OFF Universal BB LRA LUA OA TT SS CYP
568 * J1: 0x0264 0x10 0x10 0x00 0x00 0x00 0x00 0x00
569 * J2: 0x0284 0x01 0x10 0x00
570 * H1: 0x0C24 W 0x28 0xA8 0x1C 0x0F
571 * H3: 0x0C64 0x03 0x07 0x0F
572 * D1: 0x00C4 0x0F 0x3F 0x3F 0x0F 0xXC 0x3F
573 * I: 0x0224 0x02 0x00 0x08
574 * MP03: 0x0324 0x9x 0xbx 0x9x
575 * MP05: 0x0364 0x80 0x88
579 if (gpio_get_value(&gpio->j1, 4) == 0) {
580 board = MACH_TYPE_AQUILA;
581 board_rev |= J1_B2_BOARD;
583 gpio_set_pull(&gpio->j2, 6, GPIO_PULL_NONE);
584 gpio_direction_input(&gpio->j2, 6);
587 if (gpio_get_value(&gpio->h1, 2) == 0)
588 board_rev |= LIMO_UNIVERSAL_BOARD;
590 if (gpio_get_value(&gpio->h3, 2) == 0)
591 board_rev |= LIMO_REAL_BOARD;
593 if (gpio_get_value(&gpio->j2, 6) == 1)
594 board_rev |= MEDIA_BOARD;
596 /* set gpio to default value. */
597 gpio_set_pull(&gpio->j2, 6, GPIO_PULL_DOWN);
598 gpio_direction_output(&gpio->j2, 6, 0);
601 /* Workaround: C110 Aquila Rev0.6 */
602 if (board_rev == 6) {
603 board = MACH_TYPE_AQUILA;
604 board_rev |= LIMO_REAL_BOARD;
607 /* C110 Aquila Bamboo */
608 if (gpio_get_value(&gpio->j2, 0) == 1) {
609 board = MACH_TYPE_AQUILA;
610 board_rev |= BAMBOO_BOARD;
613 /* C110 TickerTape */
614 if (gpio_get_value(&gpio->d1, 0) == 0 &&
615 gpio_get_value(&gpio->d1, 1) == 0)
616 board = MACH_TICKERTAPE;
618 /* WMG160 - GPH3[0:4] = 0x00 */
619 if (board == MACH_TICKERTAPE) {
622 for (i = 0; i < 4; i++) {
623 if (gpio_get_value(&gpio->h3, i) != 0) {
634 /* C110 Geminus for rev0.0 */
635 gpio_set_pull(&gpio->j1, 2, GPIO_PULL_NONE);
636 gpio_direction_input(&gpio->j1, 2);
637 if (gpio_get_value(&gpio->j1, 2) == 1) {
638 board = MACH_GEMINUS;
639 if ((board_rev & ~BOARD_MASK) == 3)
642 gpio_set_pull(&gpio->j1, 2, GPIO_PULL_DOWN);
643 gpio_direction_output(&gpio->j1, 2, 0);
645 /* C110 Geminus for rev0.1 ~ */
646 gpio_set_pull(&gpio->j0, 6, GPIO_PULL_NONE);
647 gpio_direction_input(&gpio->j0, 6);
648 if (gpio_get_value(&gpio->j0, 6) == 1) {
649 board = MACH_GEMINUS;
652 gpio_set_pull(&gpio->j0, 6, GPIO_PULL_DOWN);
654 /* Kessler MP0_5[6] == 1 */
655 gpio_direction_input(&gpio->mp0_5, 6);
656 if (gpio_get_value(&gpio->mp0_5, 6) == 1) {
657 /* Cypress: Do this for cypress */
658 gpio_set_pull(&gpio->j2, 2, GPIO_PULL_NONE);
659 gpio_direction_input(&gpio->j2, 2);
660 if (gpio_get_value(&gpio->j2, 2) == 1) {
661 board = MACH_CYPRESS;
662 gpio_direction_output(&gpio->mp0_5, 6, 0);
664 board = MACH_TYPE_GONI;
665 board_rev |= KESSLER_BOARD;
667 /* workaround: temporarily use sdk rev0.5 */
668 board_rev |= SDK_BOARD;
671 /* Limo SDK MP0_5[4] == 1 */
672 gpio_direction_input(&gpio->mp0_5, 4);
673 if (gpio_get_value(&gpio->mp0_5, 4) == 1) {
674 board_rev &= ~KESSLER_BOARD;
677 /* Haydn MP0_4[0] == 1 */
678 gpio_direction_input(
681 &gpio->mp0_4, 0) == 1)
682 board_rev |= HAYDN_BOARD;
685 board_rev |= SDK_BOARD;
689 gpio_set_pull(&gpio->j2, 2, GPIO_PULL_DOWN);
692 gpio_direction_output(&gpio->mp0_5, 6, 0);
693 /* Goni S1 board detection */
694 if (board == MACH_TICKERTAPE) {
695 board = MACH_TYPE_GONI;
696 board_rev |= S1_BOARD;
701 board_rev |= get_hw_revision(&gpio->j0, hwrev3);
704 if (board < MACH_PSEUDO_END)
705 arch_number = C110_MACH_START + board;
710 static void check_cpu_revision(void)
715 * Workaround for Rev 0.3 + CP Ver ES 3.1
718 if (board_is_limo_real()) {
720 /* default is Rev 0.4 */
726 if (mach_is_goni() || mach_is_aquila())
729 board = arch_number - C110_MACH_START;
731 check_board_revision(board, board_rev);
733 /* Set CPU Revision */
734 if (mach_is_aquila()) {
735 if (board_is_limo_real()) {
736 if ((board_rev & 0xf) < 8)
738 } else if (board_is_bamboo())
740 } else if (mach_is_goni()) {
741 if (board_is_sdk() && (hwrevision(2) || hwrevision(4) ||
742 hwrevision(5) || hwrevision(6)))
743 s5p_set_cpu_rev(2); /* EVT1-Fused */
746 } else if (mach_is_geminus()) {
747 if ((board_rev & 0xf) < 1)
749 } else if (mach_is_cypress()) {
751 } else if (mach_is_wmg160()) {
760 writel(0xc1100000 | (0xffff & (s5p_get_cpu_rev() ? 1 : 0)),
765 static void show_hw_revision(void)
769 if (mach_is_goni() || mach_is_aquila())
772 board = arch_number - C110_MACH_START;
774 check_board_revision(board, board_rev);
776 empty_device_info_buffer();
777 dprintf("HW Revision:\t%x (%s%s) %s\n",
778 board_rev, get_board_name(board),
779 display_features(board, board_rev),
780 s5p_get_cpu_rev() ? "" : "EVT0");
783 void get_rev_info(char *rev_info)
787 if (mach_is_goni() || mach_is_aquila())
790 board = arch_number - C110_MACH_START;
792 check_board_revision(board, board_rev);
794 sprintf(rev_info, "HW Revision: %x (%s%s) %s\n",
795 board_rev, get_board_name(board),
796 display_features(board, board_rev),
797 s5p_get_cpu_rev() ? "" : "EVT0");
800 static void check_auto_burn(void)
802 unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
803 unsigned int count = 0;
807 if (readl(magic_base) == 0x426f6f74) { /* ASICC: Boot */
808 puts("Auto burning bootloader\n");
809 count += sprintf(buf + count, "run updateb; ");
812 if (readl(magic_base) == 0x654D4D43) { /* ASICC: eMMC */
813 puts("Auto burning bootloader (eMMC)\n");
814 count += sprintf(buf + count, "run updatemmc; ");
816 if (readl(magic_base + 0x04) == 0x4b65726e) { /* ASICC: Kern */
817 puts("Auto burning kernel\n");
818 count += sprintf(buf + count, "run updatek; ");
820 /* Backup u-boot in eMMC */
821 if (readl(magic_base + 0x8) == 0x4261636B) { /* ASICC: Back */
822 puts("Auto buring u-boot image (boot partition2 in eMMC)\n");
823 count += sprintf(buf + count, "run updatebackup; ");
827 count += sprintf(buf + count, "reset");
828 setenv("bootcmd", buf);
831 /* Clear the magic value */
832 memset((void*) magic_base, 0, 2);
835 static void pmic_pin_init(void)
837 unsigned int reg, value;
839 /* AP_PS_HOLD: XEINT_0: GPH0[0]
840 * Note: Don't use GPIO PS_HOLD it doesn't work
842 reg = S5PC110_PS_HOLD_CONTROL;
844 value |= S5PC110_PS_HOLD_DIR_OUTPUT |
845 S5PC110_PS_HOLD_DATA_HIGH |
846 S5PC110_PS_HOLD_OUT_EN;
849 /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
850 gpio_cfg_pin(&gpio->h2, 6, GPIO_IRQ);
851 gpio_set_pull(&gpio->h2, 6, GPIO_PULL_UP);
854 static void enable_ldos(void)
856 /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
857 gpio_direction_output(&gpio->g3, 6, 1);
860 static void enable_t_flash(void)
862 if (!(board_is_limo_universal() || board_is_limo_real()))
865 /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
866 gpio_direction_output(&gpio->mp0_5, 4, 1);
869 static void setup_limo_real_gpios(void)
871 if (!board_is_limo_real())
875 * Note: Please write GPIO alphabet order
878 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
879 gpio_direction_output(&gpio->mp0_2, 1, 1);
881 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
882 gpio_direction_output(&gpio->mp0_1, 2, 1);
885 static void setup_media_gpios(void)
887 if (!board_is_media())
891 * Note: Please write GPIO alphabet order
893 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
894 gpio_direction_output(&gpio->mp0_1, 2, 1);
897 static void check_battery(int mode)
899 unsigned char val[2];
900 unsigned char addr = 0x36; /* max17040 fuel gauge */
902 i2c_set_bus_num(I2C_GPIO3);
904 if (mach_is_aquila()) {
907 } else if (mach_is_goni()) {
908 i2c_set_bus_num(I2C_GPIO7);
909 } else if (mach_is_cypress()) {
910 i2c_set_bus_num(I2C_GPIO7);
911 } else if (mach_is_geminus()) {
913 i2c_set_bus_num(I2C_GPIO7);
917 if (i2c_probe(addr)) {
918 puts("Can't found max17040 fuel gauge\n");
922 /* mode 0: check mode / 1: enable mode */
926 i2c_write(addr, 0xfe, 1, val, 2);
928 i2c_read(addr, 0x04, 1, val, 1);
929 dprintf("battery:\t%d%%\n", val[0]);
930 battery_soc = val[0];
934 static void check_mhl(void)
936 unsigned char val[2];
937 unsigned char addr = 0x39; /* SIL9230 */
939 /* MHL Power enable */
940 /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
941 gpio_direction_output(&gpio->j2, 2, 1);
943 /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
944 gpio_direction_output(&gpio->mp0_4, 7, 0);
946 /* 10ms required after reset */
950 gpio_set_value(&gpio->mp0_4, 7, 1);
952 i2c_set_bus_num(I2C_GPIO5);
955 if (i2c_probe(addr)) {
956 puts("Can't found MHL Chip\n");
962 * set to Normal operation
965 i2c_write((0x72 >> 1), 0x08, 1, val, 1);
966 i2c_read((0x72 >> 1), 0x08, 1, val, 1);
971 * 00 = MHL termination ON
972 * 11 = MHL termination OFF
975 i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
976 i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
979 static int max8998_probe(void)
981 unsigned char addr = 0xCC >> 1;
983 i2c_set_bus_num(I2C_PMIC);
985 if (i2c_probe(addr)) {
986 puts("Can't found max8998\n");
993 #define CHARGER_ANIMATION_FRAME 6
994 static void max8998_clear_interrupt(void)
996 unsigned char addr, val[2];
1002 i2c_read(addr, 0x00, 1, val, 1);
1003 i2c_read(addr, 0x01, 1, val, 1);
1004 i2c_read(addr, 0x02, 1, val, 1);
1005 i2c_read(addr, 0x03, 1, val, 1);
1008 int check_exit_key(void)
1010 return pmic_get_irq(PWRON1S);
1013 #define KBR3 (1 << 3)
1014 #define KBR2 (1 << 2)
1015 #define KBR1 (1 << 1)
1016 #define KBR0 (1 << 0)
1018 static void check_keypad(void)
1020 unsigned int reg, value;
1021 unsigned int col_num, row_num;
1022 unsigned int col_mask;
1023 unsigned int col_mask_shift;
1024 unsigned int row_state[4];
1025 unsigned int i, power_key;
1026 unsigned int auto_download = 0;
1028 if (mach_is_wmg160())
1031 if (board_is_limo_real() || board_is_limo_universal()) {
1039 for (i = 0; i < row_num; i++) {
1040 if (board_is_sdk() &&
1041 (hwrevision(3) || hwrevision(4)) && i == 0)
1044 /* Set GPH3[3:0] to KP_ROW[3:0] */
1045 gpio_cfg_pin(&gpio->h3, i, 0x3);
1046 gpio_set_pull(&gpio->h3, i, GPIO_PULL_UP);
1049 for (i = 0; i < col_num; i++)
1050 /* Set GPH2[3:0] to KP_COL[3:0] */
1051 gpio_cfg_pin(&gpio->h2, i, 0x3);
1053 reg = S5PC110_KEYPAD_BASE;
1054 col_mask = S5PC110_KEYIFCOLEN_MASK;
1057 /* KEYIFCOL reg clear */
1058 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
1060 /* power_key check */
1061 power_key = pmic_get_irq(PWRONR);
1064 for (i = 0; i < col_num; i++) {
1066 value &= ~(1 << i) << col_mask_shift;
1068 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
1071 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
1072 row_state[i] = ~value & ((1 << row_num) - 1);
1075 /* KEYIFCOL reg clear */
1076 writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
1078 if (mach_is_aquila() || mach_is_goni()) {
1080 if (row_state[1] & 0x2)
1082 if (board_is_sdk() && hwrevision(0)) {
1083 /* home & volume down
1084 * or hold key & volume down*/
1085 if ((power_key || (row_state[1] & 0x1))
1086 && (row_state[1] & 0x2))
1088 } else if (board_is_sdk() && hwrevision(2)) {
1089 /* cam full shot & volume down
1090 * or hold key & volume down */
1091 if ((power_key || (row_state[1] & 0x6))
1092 && (row_state[2] & 0x4))
1094 } else if (board_is_sdk() && (hwrevision(3) || hwrevision(4) ||
1096 /* cam full shot & volume down
1097 * or hold key & volume down */
1098 if ((power_key || (row_state[1] & 0x6))
1099 && (row_state[2] & 0x4))
1102 /* cam full shot & volume down
1103 * or hold key & volume down */
1104 if ((power_key || (row_state[0] & 0x1))
1105 && (row_state[1] & 0x2))
1108 } else if (mach_is_geminus())
1109 /* volume down & home or hold key & volume down */
1110 if ((row_state[1] & 0x2) && ((power_key || row_state[2] & 0x1)))
1114 setenv("bootcmd", "usbdown");
1118 static int max8998_has_ext_power_source(void)
1120 unsigned char addr, val[2];
1123 if (max8998_probe())
1126 /* Accessing STATUS2 register */
1127 i2c_read(addr, 0x09, 1, val, 1);
1128 if (val[0] & (1 << 5))
1134 struct thermister_stat {
1139 static struct thermister_stat adc_to_temperature_data[] = {
1140 { .centigrade = -20, .adc = 1856, },
1141 { .centigrade = -15, .adc = 1799, },
1142 { .centigrade = -10, .adc = 1730, },
1143 { .centigrade = -5, .adc = 1649, },
1144 { .centigrade = 0, .adc = 1556, },
1145 { .centigrade = 5, .adc = 1454, },
1146 { .centigrade = 10, .adc = 1343, },
1147 { .centigrade = 15, .adc = 1227, },
1148 { .centigrade = 20, .adc = 1109, },
1149 { .centigrade = 25, .adc = 992, },
1150 { .centigrade = 30, .adc = 880, },
1151 { .centigrade = 35, .adc = 773, },
1152 { .centigrade = 40, .adc = 675, },
1153 { .centigrade = 45, .adc = 586, },
1154 { .centigrade = 50, .adc = 507, },
1155 { .centigrade = 55, .adc = 436, },
1156 { .centigrade = 58, .adc = 399, },
1157 { .centigrade = 63, .adc = 343, },
1158 { .centigrade = 65, .adc = 322, },
1162 #define USHRT_MAX 0xFFFFU
1164 static int adc_to_temperature_centigrade(unsigned short adc)
1168 /* low_*: Greatest Lower Bound,
1169 * * * * high_*: Smallest Upper Bound */
1170 int low_temp = 0, high_temp = 0;
1171 unsigned short low_adc = 0, high_adc = USHRT_MAX;
1172 for (i = 0; i < ARRAY_SIZE(adc_to_temperature_data); i++) {
1173 if (adc_to_temperature_data[i].adc <= adc &&
1174 adc_to_temperature_data[i].adc >= low_adc) {
1175 low_temp = adc_to_temperature_data[i].centigrade;
1176 low_adc = adc_to_temperature_data[i].adc;
1178 if (adc_to_temperature_data[i].adc >= adc &&
1179 adc_to_temperature_data[i].adc <= high_adc) {
1180 high_temp = adc_to_temperature_data[i].centigrade;
1181 high_adc = adc_to_temperature_data[i].adc;
1185 /* Linear approximation between cloest low and high,
1186 * which is the weighted average of the two. */
1188 /* The following equation is correct only when the two are different */
1189 if (low_adc == high_adc)
1191 if (ARRAY_SIZE(adc_to_temperature_data) < 2)
1192 return 20; /* The room temperature */
1195 if (high_adc == USHRT_MAX)
1198 approximation = low_temp * (adc - low_adc) +
1199 high_temp * (high_adc - adc);
1200 approximation /= high_adc - low_adc;
1202 return approximation;
1205 static int adc_get_average_ambient_temperature(void)
1207 if (mach_is_goni()) {
1208 unsigned short min = USHRT_MAX;
1209 unsigned short max = 0;
1210 unsigned int sum = 0;
1211 unsigned int measured = 0;
1214 run_command("pmic ldo 4 on", 0);
1216 for (i = 0; i < 7; i++) {
1217 unsigned short measurement = get_adc_value(6);
1220 if (min > measurement)
1222 if (max < measurement)
1226 run_command("pmic ldo 4 off", 0);
1228 if (measured >= 3) {
1234 printf("Average Ambient Temperature = %d(ADC=%d)\n",
1235 adc_to_temperature_centigrade(sum), sum);
1236 return adc_to_temperature_centigrade(sum);
1239 return 20; /* 20 Centigrade */
1242 enum temperature_level {
1250 static enum temperature_level temperature_check(void)
1252 int temp = adc_get_average_ambient_temperature();
1254 return _TEMP_TOO_LOW;
1256 return _TEMP_OK_LOW;
1258 return _TEMP_TOO_HIGH;
1260 return _TEMP_OK_HIGH;
1264 extern void lcd_display_clear(void);
1265 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1267 static void charger_en(int enable)
1273 unsigned char addr = 0xCC >> 1; /* max8998 */
1274 unsigned char val[2];
1276 if (max8998_probe())
1280 puts("Disable the charger.\n");
1281 i2c_read(addr, 0x0D, 1, val, 1);
1284 i2c_write(addr, 0x0D, 1, val, 1);
1286 i2c_read(addr, 0x0C, 1, val, 1);
1287 val[0] &= ~(0x7 << 0);
1288 val[0] &= ~(0x7 << 5);
1289 if (enable == 600) {
1290 val[0] |= 5; /* 600mA */
1291 val[0] |= (3 << 5); /* Stop at 150mA (25%) */
1292 } else { /* Assume 475 mA */
1294 val[0] |= 2; /* 475mA */
1295 val[0] |= (4 << 5); /* Stop at 142.5mA (30%) */
1297 i2c_write(addr, 0x0C, 1, val, 1);
1299 i2c_read(addr, 0x0D, 1, val, 1);
1301 i2c_write(addr, 0x0D, 1, val, 1);
1302 printf("Enable the charger @ %dmA\n", enable);
1306 void lcd_power_on(unsigned int onoff);
1307 extern int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
1308 extern int drv_lcd_init_resume(void);
1310 static void into_charge_mode(void)
1312 struct s5pc110_rtc *rtc = (struct s5pc110_rtc *)S5PC110_RTC_BASE;
1313 enum temperature_level previous_state = _TEMP_OK;
1318 ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1319 unsigned int reg, wakeup_stat;
1320 int charger_speed = 600;
1322 max8998_clear_interrupt();
1324 puts("Charge Mode\n");
1325 charger_en(charger_speed);
1327 #ifdef CONFIG_S5PC1XXFB
1330 /* TODO: write the image-text for the charger */
1332 level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1333 if (level >= CHARGER_ANIMATION_FRAME)
1334 level = CHARGER_ANIMATION_FRAME - 1;
1336 for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1337 bmp_addr[i] = (ulong)battery_charging_animation[i];
1339 lcd_display_clear();
1340 for (i = 0; i < 3; i++) {
1341 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1344 bmp = gunzip_bmp(bmp_addr[j], &len);
1345 lcd_display_bitmap((ulong)bmp, 140, 202);
1348 for (k = 0; k < 10; k++) {
1349 if (pmic_get_irq(PWRONF)) {
1350 lcd_display_clear();
1351 goto restore_screen;
1352 } else if (!max8998_has_ext_power_source()) {
1353 lcd_display_clear();
1354 goto restore_screen;
1363 /* Disable the display to prevent flickering */
1364 /* TODO: how to reenable the display later? */
1369 unsigned int org, org_ip3;
1371 empty_device_info_buffer();
1372 if (pmic_get_irq(PWRONF))
1374 else if (!max8998_has_ext_power_source())
1377 /* Enable RTC, SYSTIMER, ADC at CLKGATE IP3 */
1378 org_ip3 = readl(0xE010046C);
1379 writel(org_ip3 | (1 << 15) | (1 << 16) | (1 << 24), 0xE010046C);
1381 reg = org = readl(&rtc->rtccon);
1383 writel(reg, &rtc->rtccon);
1385 reg = readl(&rtc->rtccon);
1386 writel(reg | (1 << 3), &rtc->rtccon);
1388 writel(reg & ~(1 << 3), &rtc->rtccon);
1391 reg = readl(&rtc->rtccon);
1392 reg &= ~((1 << 8) | (0xF << 4));
1393 reg |= (1 << 8) | (0xD << 4); /* D: 4 Hz, 9: 64 Hz */
1394 writel(reg, &rtc->rtccon);
1396 reg = 15 * 4 - 1; /* 15 sec */
1397 writel(reg, &rtc->ticcnt);
1399 /* EVT0: sleep 1, EVT1: sleep */
1400 if (cpu_is_s5pc110()) {
1401 char *name = "dummy";
1402 char *usage = "N/A";
1409 if (s5p_get_cpu_rev() == 0) {
1410 char *argv[] = {"1", "1"};
1411 wakeup_stat = do_sleep(&ctt, 0, 2, argv);
1413 char *argv[] = {"0", "0"};
1414 wakeup_stat = do_sleep(&ctt, 0, 1, argv);
1418 /* Check TEMP HIGH/LOW */
1419 switch (temperature_check()) {
1421 charger_en(charger_speed);
1422 previous_state = _TEMP_OK;
1426 previous_state = _TEMP_TOO_LOW;
1428 case _TEMP_TOO_HIGH:
1430 previous_state = _TEMP_TOO_HIGH;
1433 if (previous_state == _TEMP_TOO_LOW) {
1436 charger_en(charger_speed);
1437 previous_state = _TEMP_OK;
1441 if (previous_state == _TEMP_TOO_HIGH) {
1444 charger_en(charger_speed);
1445 previous_state = _TEMP_OK;
1450 writel(org, &rtc->rtccon);
1451 writel(org_ip3, 0xE010046C);
1453 } while (wakeup_stat == 0x04); /* RTC TICK */
1455 #ifdef CONFIG_S5PC1XXFB
1457 /* TODO: Reenable logo display (not working yet) */
1459 drv_lcd_init_resume();
1463 #define S5PC110_RST_STAT 0xE010A000
1465 #define SWRESET (1 << 3)
1466 #define WDTRESET (1 << 2)
1467 #define WARMRESET (1 << 1)
1468 #define EXTRESET (1 << 0)
1470 static int get_reset_status(void)
1472 return readl(S5PC110_RST_STAT) & 0xf;
1475 static void check_reset_status(void)
1477 int status = get_reset_status();
1479 puts("Reset Status: ");
1483 puts("Pin(Ext) Reset\n");
1486 puts("Warm Reset\n");
1489 puts("Watchdog Reset\n");
1492 puts("S/W Reset\n");
1495 printf("Unknown (0x%x)\n", status);
1499 static int fsa9480_probe(void)
1501 unsigned char addr = 0x25;
1503 if (board_is_limo_real()) {
1504 if (hwrevision(0) || hwrevision(1))
1508 i2c_set_bus_num(I2C_PMIC);
1510 if (mach_is_goni()) {
1511 i2c_set_bus_num(I2C_GPIO6);
1512 } else if (mach_is_cypress()) {
1513 i2c_set_bus_num(I2C_GPIO6);
1514 } else if (mach_is_geminus()) {
1516 i2c_set_bus_num(I2C_GPIO6);
1517 } else if (mach_is_wmg160()) {
1518 i2c_set_bus_num(I2C_GPIO6);
1521 if (i2c_probe(addr)) {
1522 puts("Can't found fsa9480\n");
1529 static void check_micro_usb(int intr)
1532 unsigned char val[2];
1533 static int started_charging_once = 0;
1536 if (fsa9480_probe())
1539 addr = 0x25; /* fsa9480 */
1541 /* Clear Interrupt */
1543 i2c_read(addr, 0x03, 1, val, 2);
1547 /* Read Device Type 1 */
1548 i2c_read(addr, 0x0a, 1, val, 1);
1550 #define FSA_DEV1_CHARGER (1 << 6)
1551 #define FSA_DEV1_UART (1 << 3)
1552 #define FSA_DEV1_USB (1 << 2)
1553 #define FSA_DEV2_JIG_USB_OFF (1 << 1)
1554 #define FSA_DEV2_JIG_USB_ON (1 << 0)
1557 * If USB, use default 475mA
1558 * If Charger, use 600mA and go to charge mode
1560 if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1561 started_charging_once = 1;
1563 /* If it's full, do not charge. */
1564 if (battery_soc < 100)
1568 } else if (val[0] & FSA_DEV1_USB) {
1569 if (battery_soc < 100)
1570 charger_en(475); /* enable charger and keep booting */
1575 /* If reset status is watchdog reset then skip it */
1576 if (!(get_reset_status() & SWRESET)) {
1577 /* If Factory Mode is Boot ON-USB, go to download mode */
1578 i2c_read(addr, 0x07, 1, val, 1);
1580 #define FSA_ADC_FAC_USB_OFF 0x18
1581 #define FSA_ADC_FAC_USB_ON 0x19
1582 #define FSA_ADC_FAC_UART 0x1d
1584 if (val[0] == FSA_ADC_FAC_USB_ON ||
1585 val[0] == FSA_ADC_FAC_USB_OFF)
1586 setenv("bootcmd", "usbdown");
1589 path = getenv("usb");
1591 if (!strncmp(path, "cp", 2))
1592 run_command("microusb cp", 0);
1595 static void micro_usb_switch(int path)
1598 unsigned char val[2];
1600 if (fsa9480_probe())
1603 addr = 0x25; /* fsa9480 */
1606 val[0] = 0x90; /* VAUDIO */
1608 val[0] = (1 << 5) | (1 << 2); /* DHOST */
1610 i2c_write(addr, 0x13, 1, val, 1); /* MANSW1 */
1612 i2c_read(addr, 0x2, 1, val, 1);
1613 val[0] &= ~(1 << 2); /* Manual switching */
1614 i2c_write(addr, 0x2, 1, val, 1);
1617 #define MAX8998_REG_ONOFF1 0x11
1618 #define MAX8998_REG_ONOFF2 0x12
1619 #define MAX8998_REG_ONOFF3 0x13
1620 #define MAX8998_REG_ONOFF4 0x14
1621 #define MAX8998_REG_LDO7 0x21
1622 #define MAX8998_REG_LDO17 0x29
1624 #define MAX8998_LDO3 (1 << 2)
1626 #define MAX8998_LDO6 (1 << 7)
1627 #define MAX8998_LDO7 (1 << 6)
1628 #define MAX8998_LDO8 (1 << 5)
1629 #define MAX8998_LDO9 (1 << 4)
1630 #define MAX8998_LDO10 (1 << 3)
1631 #define MAX8998_LDO11 (1 << 2)
1632 #define MAX8998_LDO12 (1 << 1)
1633 #define MAX8998_LDO13 (1 << 0)
1635 #define MAX8998_LDO14 (1 << 7)
1636 #define MAX8998_LDO15 (1 << 6)
1637 #define MAX8998_LDO16 (1 << 5)
1638 #define MAX8998_LDO17 (1 << 4)
1641 static void init_pmic(void)
1644 unsigned char val[2];
1646 addr = 0xCC >> 1; /* max8998 */
1647 if (max8998_probe())
1651 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1652 val[0] &= ~MAX8998_LDO3;
1653 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1656 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1658 * Disable LDO8(USB_3.3V), LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1659 * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1661 val[0] &= ~(MAX8998_LDO8 | MAX8998_LDO10 | MAX8998_LDO11 |
1662 MAX8998_LDO12 | MAX8998_LDO13);
1665 val[0] |= MAX8998_LDO7; /* LDO7: VLCD_1.8V */
1667 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1668 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1670 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1672 * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1673 * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1675 val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1676 MAX8998_LDO16 | MAX8998_LDO17);
1679 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
1681 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1682 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1685 static void setup_power_down_mode_registers(void)
1687 struct s5p_gpio_bank *bank;
1688 struct gpio_powermode *p;
1690 struct gpio_external *ge;
1692 struct s5pc1xx_gpio_item *mr;
1696 /* Only Limo real and kessler supports worked for sleep currnet */
1697 if (mach_is_aquila()) {
1698 if (board_is_limo_real())
1702 } else if (mach_is_goni()) {
1704 } else if (mach_is_geminus()) {
1710 if (mach_is_aquila()) {
1711 /* Aquila rev 0.8 or lower */
1712 p = aquila_powerdown_modes;
1713 ge = aquila_external_powerdown_modes;
1714 mr = aquila_mirror_powerdown_mode;
1715 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1716 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1717 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1718 } else if (mach_is_goni()) {
1719 /* Aquila rev 0.9 */
1720 p = kessler_powerdown_modes;
1721 ge = kessler_external_powerdown_modes;
1722 mr = kessler_mirror_powerdown_mode;
1723 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1724 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1725 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1726 } else if (mach_is_geminus()) {
1727 if (hwrevision(1)) {
1728 /* Same as Aquila rev 0.9 */
1730 p = kessler_powerdown_modes;
1731 ge = kessler_external_powerdown_modes;
1732 mr = kessler_mirror_powerdown_mode;
1733 n_p = ARRAY_SIZE(kessler_powerdown_modes);
1734 n_ge = ARRAY_SIZE(kessler_external_powerdown_modes);
1735 n_mr = ARRAY_SIZE(kessler_mirror_powerdown_mode);
1737 p = aquila_powerdown_modes;
1738 ge = aquila_external_powerdown_modes;
1739 mr = aquila_mirror_powerdown_mode;
1740 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1741 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1742 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1744 } else if (hwrevision(0)) {
1745 /* Same as Aquila rev 0.8 or lower */
1746 p = aquila_powerdown_modes;
1747 ge = aquila_external_powerdown_modes;
1748 mr = aquila_mirror_powerdown_mode;
1749 n_p = ARRAY_SIZE(aquila_powerdown_modes);
1750 n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1751 n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1753 return; /* Not supported */
1759 for (i = 0; i < n_p; i++, p++, bank++) {
1760 writel(p->conpdn, &bank->pdn_con);
1761 writel(p->pudpdn, &bank->pdn_pull);
1764 writel(0xff0022b0, (unsigned int *)0xF0000000);
1765 writel(0xff0022b0, (unsigned int *)0xF1400000);
1769 for (i = 0; i < n_ge; i++) {
1770 writel(ge->con, &bank->con);
1771 writel(ge->dat, &bank->dat);
1772 writel(ge->pud, &bank->pull);
1778 for (i = 0; i < n_mr; i++) {
1779 unsigned int reg = readl(&mr->bank->pdn_con);
1780 reg &= ~(0x3 << (mr->number << 1));
1781 if (readl(&mr->bank->dat) & (1 << mr->number))
1782 reg |= 0x1 << (mr->number << 1);
1783 writel(reg, &mr->bank->pdn_con);
1790 void fimd_clk_set(void)
1792 struct s5pc110_clock *clk =
1793 (struct s5pc110_clock *)samsung_get_base_clock();
1794 unsigned int cfg = 0;
1796 /* set lcd src clock */
1797 cfg = readl(&clk->src1);
1798 cfg &= ~(0xf << 20);
1800 writel(cfg, &clk->src1);
1802 /* set fimd ratio */
1803 cfg = readl(&clk->div1);
1804 cfg &= ~(0xf << 20);
1806 writel(cfg, &clk->div1);
1809 void mipi_power_on(void)
1811 run_command("pmic ldo 3 on", 0);
1812 run_command("pmic ldo 7 on", 0);
1816 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1817 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1818 extern void ld9040_set_platform_data(struct spi_platform_data *pd);
1820 struct spi_platform_data spi_pd;
1822 void lcd_cfg_gpio(void)
1824 unsigned int i, f3_end = 4;
1826 for (i = 0; i < 8; i++) {
1827 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1828 gpio_cfg_pin(&gpio->f0, i, GPIO_FUNC(2));
1829 gpio_cfg_pin(&gpio->f1, i, GPIO_FUNC(2));
1830 gpio_cfg_pin(&gpio->f2, i, GPIO_FUNC(2));
1831 /* pull-up/down disable */
1832 gpio_set_pull(&gpio->f0, i, GPIO_PULL_NONE);
1833 gpio_set_pull(&gpio->f1, i, GPIO_PULL_NONE);
1834 gpio_set_pull(&gpio->f2, i, GPIO_PULL_NONE);
1836 /* drive strength to max (24bit) */
1837 gpio_set_drv(&gpio->f0, i, GPIO_DRV_4X);
1838 gpio_set_rate(&gpio->f0, i, GPIO_DRV_SLOW);
1839 gpio_set_drv(&gpio->f1, i, GPIO_DRV_4X);
1840 gpio_set_rate(&gpio->f1, i, GPIO_DRV_SLOW);
1841 gpio_set_drv(&gpio->f2, i, GPIO_DRV_4X);
1842 gpio_set_rate(&gpio->f2, i, GPIO_DRV_SLOW);
1845 /* set DISPLAY_DE_B pin for dual rgb mode. */
1846 if (board_is_media())
1849 for (i = 0; i < f3_end; i++) {
1850 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1851 gpio_cfg_pin(&gpio->f3, i, GPIO_PULL_UP);
1852 /* pull-up/down disable */
1853 gpio_set_pull(&gpio->f3, i, GPIO_PULL_NONE);
1854 /* drive strength to max (24bit) */
1855 gpio_set_drv(&gpio->f3, i, GPIO_DRV_4X);
1856 gpio_set_rate(&gpio->f3, i, GPIO_DRV_SLOW);
1858 /* display output path selection (only [1:0] valid) */
1859 writel(0x2, 0xE0107008);
1861 /* gpio pad configuration for LCD reset. */
1862 gpio_cfg_pin(&gpio->mp0_5, 5, GPIO_OUTPUT);
1864 /* gpio pad configuration for LCD ON. */
1865 gpio_cfg_pin(&gpio->j1, 3, GPIO_OUTPUT);
1867 /* LCD_BACKLIGHT_EN */
1868 if (mach_is_geminus())
1869 gpio_cfg_pin(&gpio->mp0_5, 0, GPIO_OUTPUT);
1870 if (board_is_sdk() && hwrevision(0)) {
1871 gpio_cfg_pin(&gpio->mp0_4, 4, GPIO_OUTPUT);
1872 gpio_direction_output(&gpio->mp0_4, 4, 0);
1876 * gpio pad configuration for
1877 * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1879 gpio_cfg_pin(&gpio->mp0_1, 1, GPIO_OUTPUT);
1880 gpio_cfg_pin(&gpio->mp0_4, 1, GPIO_OUTPUT);
1881 gpio_cfg_pin(&gpio->mp0_4, 2, GPIO_INPUT);
1882 gpio_cfg_pin(&gpio->mp0_4, 3, GPIO_OUTPUT);
1884 if (mach_is_aquila() || mach_is_goni()) {
1885 spi_pd.cs_bank = &gpio->mp0_1;
1887 spi_pd.clk_bank = &gpio->mp0_4;
1889 spi_pd.si_bank = &gpio->mp0_4;
1891 spi_pd.so_bank = &gpio->mp0_4;
1894 spi_pd.mode = SPI_MODE_3;
1896 spi_pd.cs_active = ACTIVE_LOW;
1897 spi_pd.word_len = 8;
1899 if (board_is_sdk() && hwrevision(0))
1900 s6d16a0x_set_platform_data(&spi_pd);
1901 else if (board_is_sdk() && (hwrevision(3) || hwrevision(6)))
1902 ld9040_set_platform_data(&spi_pd);
1904 s6e63m0_set_platform_data(&spi_pd);
1905 if (board_is_media())
1910 if (mach_is_cypress()) {
1911 #if 0 /* universal cypress */
1913 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1916 gpio_cfg_pin(&gpio->mp0_5, 1, GPIO_OUTPUT);
1918 gpio_cfg_pin(&gpio->mp0_4, 0, GPIO_OUTPUT);
1920 gpio_cfg_pin(&gpio->mp0_4, 2, GPIO_OUTPUT);
1922 gpio_cfg_pin(&gpio->mp0_4, 5, GPIO_OUTPUT);
1924 gpio_cfg_pin(&gpio->g2, 2, GPIO_OUTPUT);
1925 #if 0 /* universal cypress */
1926 pd_cs.bank = &gpio_base->gpio_mp0_1;
1929 spi_pd.cs_bank = &gpio->mp0_5;
1931 spi_pd.clk_bank = &gpio->mp0_4;
1933 spi_pd.si_bank = &gpio->mp0_4;
1938 spi_pd.mode = SPI_MODE_3;
1940 spi_pd.cs_active = ACTIVE_LOW;
1941 spi_pd.word_len = 8;
1943 /* these data would be sent to s6e63m0 lcd panel driver. */
1944 s6e63m0_set_platform_data(&spi_pd);
1950 #define SWRST_REG 0x00
1951 #define LEDCON_REG 0x01
1952 #define LED_CUR_SET_REG 0x03
1953 #define LED_CUR_TR_REG 0x08
1956 #define NORMAL_MODE 0x09
1957 #define CUR_SET 0x63
1959 void backlight_on(unsigned int onoff)
1963 unsigned char val[2];
1966 if (mach_is_geminus())
1967 gpio_set_value(&gpio->mp0_5, 0, 1);
1969 if (mach_is_geminus())
1970 gpio_set_value(&gpio->mp0_5, 0, 0);
1973 if (mach_is_goni() && board_is_sdk() && hwrevision(0)) {
1974 gpio_set_value(&gpio->mp0_4, 4, 1);
1977 i2c_set_bus_num(I2C_GPIO5);
1980 if (i2c_probe(addr)) {
1981 if (i2c_probe(addr)) {
1982 puts("Can't found s6d16a0x backlight i2c\n");
1987 i2c_write(addr, SWRST_REG, 1, val, 1);
1990 i2c_write(addr, LED_CUR_SET_REG, 1, val, 1);
1992 i2c_write(addr, LED_CUR_TR_REG, 1, val, 1);
1993 val[0] = NORMAL_MODE;
1994 i2c_write(addr, LEDCON_REG, 1, val, 1);
1999 void reset_lcd(void)
2001 if (mach_is_aquila() || mach_is_goni() || mach_is_geminus()) {
2002 gpio_set_value(&gpio->mp0_5, 5, 1);
2003 if (board_is_sdk() &&
2004 (hwrevision(3) || hwrevision(4) || hwrevision(5) ||hwrevision(6))) {
2006 gpio_set_value(&gpio->mp0_5, 5, 0);
2008 gpio_set_value(&gpio->mp0_5, 5, 1);
2012 if (mach_is_cypress())
2013 gpio_set_value(&gpio->mp0_4, 5, 1);
2016 void lcd_power_on(unsigned int onoff)
2020 if (mach_is_aquila() || mach_is_geminus())
2021 gpio_set_value(&gpio->j1, 3, 1);
2023 if (mach_is_cypress())
2024 gpio_set_value(&gpio->g2, 2, 1);
2026 if (mach_is_goni()) {
2028 unsigned char val[2];
2029 unsigned char val2[2];
2031 gpio_set_value(&gpio->j1, 3, 1);
2033 addr = 0xCC >> 1; /* max8998 */
2034 if (max8998_probe())
2037 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2038 val[0] &= ~(MAX8998_LDO17);
2039 val[0] |= MAX8998_LDO17; /* LDO17: VCC_3.0V_LCD */
2040 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2042 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2043 val[0] |= MAX8998_LDO17;
2045 i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
2046 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2048 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2049 val[0] |= MAX8998_LDO7;
2051 i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
2052 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2055 if (mach_is_aquila() || mach_is_geminus())
2056 gpio_set_value(&gpio->j1, 3, 0);
2058 if (mach_is_cypress())
2059 gpio_set_value(&gpio->g2, 2, 0);
2061 if (mach_is_goni()) {
2063 unsigned char val[2];
2065 gpio_set_value(&gpio->j1, 3, 0);
2067 addr = 0xCC >> 1; /* max8998 */
2068 if (max8998_probe())
2071 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2072 val[0] &= ~(MAX8998_LDO7);
2073 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2074 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2076 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2077 val[0] &= ~(MAX8998_LDO17);
2078 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2079 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2084 extern void s6e63m0_cfg_ldo(void);
2085 extern void s6e63m0_enable_ldo(unsigned int onoff);
2086 extern void s6d16a0x_cfg_ldo(void);
2087 extern void s6d16a0x_enable_ldo(unsigned int onoff);
2088 extern void ld9040_cfg_ldo(void);
2089 extern void ld9040_enable_ldo(unsigned int onoff);
2090 extern void s3cfb_set_trigger(void);
2091 extern int s3cfb_is_i80_frame_done(void);
2093 int s5p_no_lcd_support(void)
2095 if (mach_is_wmg160())
2100 static struct dsim_config dsim_info = {
2101 /* main frame fifo auto flush at VSYNC pulse */
2102 .auto_flush = DSIM_FALSE,
2103 .eot_disable = DSIM_FALSE,
2105 .auto_vertical_cnt = DSIM_FALSE,
2111 .e_no_data_lane = DSIM_DATA_LANE_2,
2112 .e_byte_clk = DSIM_PLL_OUT_DIV8,
2114 /* 472MHz: LSI Recommended */
2119 /* D-PHY PLL stable time spec :min = 200usec ~ max 400usec */
2120 .pll_stable_time = 500,
2122 .esc_clk = 10 * 1000000, /* escape clk : 10MHz */
2124 /* stop state holding counter after bta change count 0 ~ 0xfff */
2125 .stop_holding_cnt = 0x0f,
2126 .bta_timeout = 0xff, /* bta timeout 0 ~ 0xff */
2127 .rx_timeout = 0xffff, /* lp rx timeout 0 ~ 0xffff */
2129 .e_lane_swap = DSIM_NO_CHANGE,
2132 static struct dsim_lcd_config dsim_lcd_info = {
2133 .e_interface = DSIM_COMMAND,
2135 .parameter[DSI_VIRTUAL_CH_ID] = (unsigned int) DSIM_VIRTUAL_CH_0,
2136 .parameter[DSI_FORMAT] = (unsigned int) DSIM_24BPP_888,
2137 .parameter[DSI_VIDEO_MODE_SEL] = (unsigned int) DSIM_BURST,
2139 .mipi_ddi_pd = NULL,
2142 struct s5p_platform_dsim s6e39a0x_platform_data = {
2145 .dsim_info = &dsim_info,
2146 .dsim_lcd_info = &dsim_lcd_info,
2147 .lcd_panel_name = "s6e39a0x",
2151 * the stable time of needing to write data on SFR
2152 * when the mipi mode becomes LP mode.
2154 .delay_for_stabilization = 600000,
2157 extern void s5p_set_dsim_platform_data(struct s5p_platform_dsim *pd);
2158 extern void s6e39a0x_init(void);
2160 void init_panel_info(vidinfo_t *vid)
2162 vid->cfg_gpio = NULL;
2163 vid->reset_lcd = NULL;
2164 vid->backlight_on = NULL;
2165 vid->lcd_power_on = NULL;
2166 vid->mipi_power = NULL;
2168 vid->cfg_ldo = NULL;
2169 vid->enable_ldo = NULL;
2171 vid->init_delay = 0;
2172 vid->reset_delay = 0;
2173 vid->power_on_delay = 0;
2178 vid->vl_width = 480;
2179 vid->vl_height = 800;
2181 vid->dual_lcd_enabled = 0;
2182 vid->interface_mode = FIMD_RGB_INTERFACE;
2184 if (board_is_media()) {
2187 vid->vl_width = 960;
2188 vid->vl_height = 800;
2190 /* enable dual lcd mode. */
2191 vid->dual_lcd_enabled = 1;
2194 vid->vl_clkp = CONFIG_SYS_HIGH;
2195 vid->vl_hsp = CONFIG_SYS_LOW;
2196 vid->vl_vsp = CONFIG_SYS_LOW;
2197 vid->vl_dp = CONFIG_SYS_HIGH;
2200 /* S6E63M0 LCD Panel */
2209 if (mach_is_aquila() || mach_is_goni()
2210 || mach_is_cypress()) {
2211 vid->cfg_gpio = lcd_cfg_gpio;
2212 vid->reset_lcd = reset_lcd;
2213 vid->backlight_on = backlight_on;
2214 vid->lcd_power_on = lcd_power_on;
2215 vid->cfg_ldo = s6e63m0_cfg_ldo;
2216 vid->enable_ldo = s6e63m0_enable_ldo;
2218 vid->init_delay = 25000;
2219 vid->reset_delay = 120000;
2222 if (board_is_sdk() && hwrevision(0)) {
2226 vid->vl_width = 320;
2227 vid->vl_height = 480;
2229 vid->vl_clkp = CONFIG_SYS_HIGH;
2230 vid->vl_hsp = CONFIG_SYS_HIGH;
2231 vid->vl_vsp = CONFIG_SYS_HIGH;
2232 vid->vl_dp = CONFIG_SYS_LOW;
2235 /* disable dual lcd mode. */
2236 vid->dual_lcd_enabled = 0;
2238 /* S6D16A0X LCD Panel */
2247 vid->cfg_gpio = lcd_cfg_gpio;
2248 vid->backlight_on = backlight_on;
2249 vid->lcd_power_on = lcd_power_on;
2250 vid->reset_lcd = reset_lcd;
2251 vid->cfg_ldo = s6d16a0x_cfg_ldo;
2252 vid->enable_ldo = s6d16a0x_enable_ldo;
2254 vid->init_delay = 10000;
2255 vid->power_on_delay = 10000;
2256 vid->reset_delay = 1000;
2259 if (board_is_sdk() && (hwrevision(3) || hwrevision(6))) {
2263 vid->vl_width = 480;
2264 vid->vl_height = 800;
2265 vid->vl_clkp = CONFIG_SYS_HIGH;
2266 vid->vl_hsp = CONFIG_SYS_HIGH;
2267 vid->vl_vsp = CONFIG_SYS_HIGH;
2268 vid->vl_dp = CONFIG_SYS_HIGH;
2271 /* disable dual lcd mode. */
2272 vid->dual_lcd_enabled = 0;
2274 /* LD9040 LCD Panel */
2283 vid->cfg_gpio = lcd_cfg_gpio;
2284 vid->backlight_on = NULL;
2285 vid->lcd_power_on = lcd_power_on;
2286 vid->reset_lcd = reset_lcd;
2287 vid->cfg_ldo = ld9040_cfg_ldo;
2288 vid->enable_ldo = ld9040_enable_ldo;
2290 vid->init_delay = 0;
2291 vid->power_on_delay = 30000;
2292 vid->reset_delay = 20000;
2293 } else if (board_is_sdk() && (hwrevision(4) || hwrevision(5))) {
2297 vid->vl_width = 600;
2298 vid->vl_height = 1024;
2301 /* disable dual lcd mode. */
2302 vid->dual_lcd_enabled = 0;
2309 vid->cfg_gpio = lcd_cfg_gpio;
2310 vid->backlight_on = NULL;
2311 vid->lcd_power_on = lcd_power_on;
2312 vid->reset_lcd = reset_lcd;
2313 vid->mipi_power = mipi_power_on;
2315 vid->init_delay = 0;
2316 vid->power_on_delay = 30000;
2317 vid->reset_delay = 20000;
2318 vid->interface_mode = FIMD_CPU_INTERFACE;
2320 s6e39a0x_platform_data.part_reset = s5p_dsim_part_reset;
2321 s6e39a0x_platform_data.init_d_phy = s5p_dsim_init_d_phy;
2322 s6e39a0x_platform_data.get_fb_frame_done = s3cfb_is_i80_frame_done;
2323 s6e39a0x_platform_data.trigger = s3cfb_set_trigger;
2324 s6e39a0x_platform_data.pvid = vid;
2326 s5p_set_dsim_platform_data(&s6e39a0x_platform_data);
2329 if (mach_is_geminus()) {
2333 vid->vl_width = 1024,
2334 vid->vl_height = 600,
2335 vid->vl_clkp = CONFIG_SYS_LOW,
2336 vid->vl_hsp = CONFIG_SYS_HIGH,
2337 vid->vl_vsp = CONFIG_SYS_HIGH,
2338 vid->vl_dp = CONFIG_SYS_LOW,
2349 vid->cfg_gpio = lcd_cfg_gpio;
2350 vid->reset_lcd = reset_lcd;
2351 vid->backlight_on = backlight_on;
2352 vid->lcd_power_on = lcd_power_on;
2358 vid->vl_width = 480,
2359 vid->vl_height = 800,
2360 vid->vl_clkp = CONFIG_SYS_HIGH,
2361 vid->vl_hsp = CONFIG_SYS_LOW,
2362 vid->vl_vsp = CONFIG_SYS_LOW,
2363 vid->vl_dp = CONFIG_SYS_HIGH,
2379 vid->vl_width = 1024,
2380 vid->vl_height = 600,
2381 vid->vl_clkp = CONFIG_SYS_HIGH,
2382 vid->vl_hsp = CONFIG_SYS_HIGH,
2383 vid->vl_vsp = CONFIG_SYS_HIGH,
2384 vid->vl_dp = CONFIG_SYS_LOW,
2387 /* AMS701KA AMOLED Panel. */
2399 static void setup_meminfo(void)
2401 char meminfo[64] = {0, };
2402 int count = 0, size, real;
2404 size = gd->bd->bi_dram[0].size >> 20;
2405 count += sprintf(meminfo + count, "mem=%dM", size);
2407 /* Each Chip Select can't exceed the 256MiB */
2408 size = gd->bd->bi_dram[1].size >> 20;
2409 real = min(size, 256);
2410 count += sprintf(meminfo + count, " mem=%dM@0x%x",
2411 real, (unsigned int)gd->bd->bi_dram[1].start);
2415 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
2416 (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
2419 setenv("meminfo", meminfo);
2422 #ifdef CONFIG_CMD_RAMOOPS
2423 static void show_dump_msg(void)
2427 ret = ramoops_init(samsung_get_base_modem());
2430 setenv("bootdelay", "-1");
2434 int misc_init_r(void)
2436 check_reset_status();
2437 #ifdef CONFIG_CMD_RAMOOPS
2442 /* It should be located at first */
2445 if (mach_is_aquila() || mach_is_goni()) {
2446 if (board_is_sdk() && hwrevision(0))
2447 setenv("lcdinfo", "lcd=s6d16a0x");
2448 else if (board_is_sdk() && (hwrevision(3) || hwrevision(6)))
2449 setenv("lcdinfo", "lcd=ld9040");
2450 else if (board_is_sdk() && (hwrevision(4) || hwrevision(5)))
2451 setenv("lcdinfo", "lcd=s6e39a0x");
2452 else if (board_is_media())
2453 setenv("lcdinfo", "lcd=s6e63m0");
2455 setenv("lcdinfo", "lcd=s6e63m0");
2457 if (mach_is_geminus())
2458 setenv("lcdinfo", "lcd=lms480jc01");
2459 if (mach_is_cypress())
2460 setenv("lcdinfo", "lcd=s6e63m0");
2466 /* Set proper PMIC pins */
2469 /* Check auto burning */
2472 /* To power up I2C2 */
2475 /* Enable T-Flash at Limo Real or Limo Universal */
2478 /* Setup Limo Real board GPIOs */
2479 setup_limo_real_gpios();
2481 /* Setup Media board GPIOs */
2482 setup_media_gpios();
2485 pmic_bus_init(I2C_PMIC);
2488 /* To usbdown automatically */
2491 #ifdef CONFIG_S5PC1XXFB
2492 display_device_info();
2495 setup_power_down_mode_registers();
2497 /* check max17040 */
2503 #ifdef CONFIG_INFO_ACTION
2504 info_action_check();
2511 #ifdef CONFIG_BOARD_EARLY_INIT_F
2512 int board_early_init_f(void)
2514 /* Set Initial global variables */
2515 gpio = (struct s5pc110_gpio *)samsung_get_base_gpio();
2517 /* Check H/W Revision */
2518 check_hw_revision();
2524 int board_init(void)
2526 /* Set Initial global variables */
2527 gpio = (struct s5pc110_gpio *)samsung_get_base_gpio();
2529 /* Check H/W Revision */
2530 check_hw_revision();
2532 gd->bd->bi_arch_number = arch_number;
2533 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
2535 check_cpu_revision();
2542 gd->ram_size = PHYS_SDRAM_1_SIZE;
2547 void dram_init_banksize(void)
2549 unsigned int base, memconfig0, size;
2550 unsigned int memconfig1, sz = 0;
2553 /* In S5PC110, we can't swap the DMC0/1 */
2554 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
2555 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
2557 base = S5PC110_DMC1_BASE;
2558 /* DMC configuration */
2559 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
2560 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
2562 size = (memconfig0 >> 16) & 0xFF;
2563 size = ((unsigned char) ~size) + 1;
2566 * (0x07 + 1) * 16 = 128 MiB
2567 * (0x0f + 1) * 16 = 256 MiB
2572 * Aquila Rev0.5 4G3G1G
2573 * Aquila Rev0.8 4G3G1G
2574 * Aquila Rev0.9 4G3G1G
2575 * Limo SDK Rev 0.2 4G3G1G
2576 * Limo SDK Rev 0.3 4G3G1G
2577 * Limo SDK Rev 0.4 4G3G1G
2578 * WMG160 Rev 0.7 4G3G1G
2580 if (mach_is_aquila() || mach_is_goni()) {
2581 if ((!board_is_sdk() && (hwrevision(5) ||
2582 hwrevision(8) || hwrevision(9))) ||
2583 (board_is_sdk() && !hwrevision(1)))
2585 if (mach_is_goni() && board_is_s1()) {
2589 } else if (mach_is_wmg160() && !hwrevision(5)) {
2594 memconfig1 = readl(base + MEMCONFIG1_OFFSET);
2596 sz = (memconfig1 >> 16) & 0xFF;
2597 sz = ((unsigned char) ~sz) + 1;
2601 * bi_dram[1].size contains all DMC1 memory size
2603 gd->bd->bi_dram[1].size = (size + sz) << 20;
2605 /* Set the memory size correctly */
2606 gd->ram_size = gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size;
2609 /* Used for sleep test */
2610 static unsigned char saved_val[4][2];
2611 void board_sleep_init_late(void)
2613 /* CODEC_LDO_EN: GPF3[4] */
2614 gpio_direction_output(&gpio->f3, 4, 0);
2615 /* CODEC_XTAL_EN: GPH3[2] */
2616 gpio_direction_output(&gpio->h3, 2, 0);
2618 /* MMC T_FLASH off */
2619 gpio_direction_output(&gpio->mp0_5, 4, 0);
2621 gpio_direction_output(&gpio->j2, 2, 0);
2622 gpio_direction_output(&gpio->mp0_4, 7, 0);
2623 /* MHL_ON for REV02 or higher */
2624 gpio_direction_output(&gpio->j2, 3, 0);
2627 void board_sleep_init(void)
2630 unsigned char val[2];
2633 if (max8998_probe())
2636 if (mach_is_goni()) {
2638 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2639 saved_val[0][0] = val[0];
2640 saved_val[0][1] = val[1];
2641 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2642 (1 << 1) | (1 << 0));
2643 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2644 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2647 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2648 saved_val[1][0] = val[0];
2649 saved_val[1][1] = val[1];
2650 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2651 (1 << 2) | (1 << 1) | (1 << 0));
2653 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2654 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2657 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2658 saved_val[2][0] = val[0];
2659 saved_val[2][1] = val[1];
2660 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2661 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2662 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2665 i2c_read(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2666 saved_val[3][0] = val[0];
2667 saved_val[3][1] = val[1];
2668 val[0] &= ~((1 << 6) | (1 << 4));
2669 i2c_write(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2670 i2c_read(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2672 printf("Turned off regulators with Kessler setting."
2673 " Preparing to sleep. [%s:%d]\n",
2674 __FILE__, __LINE__);
2675 } else { /* Default */
2677 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2678 saved_val[0][0] = val[0];
2679 saved_val[0][1] = val[1];
2680 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
2681 (1 << 1) | (1 << 0));
2682 i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2683 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2686 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2687 saved_val[1][0] = val[0];
2688 saved_val[1][1] = val[1];
2689 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2690 (1 << 2) | (1 << 1) | (1 << 0));
2692 i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2693 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2696 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2697 saved_val[2][0] = val[0];
2698 saved_val[2][1] = val[1];
2699 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2700 i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2701 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2704 i2c_read(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2705 saved_val[3][0] = val[0];
2706 saved_val[3][1] = val[1];
2707 val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2708 i2c_write(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2709 i2c_read(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2711 printf("Turned off regulators with default(Aquila) setting."
2712 " Preparing to sleep. [%s:%d]\n",
2713 __FILE__, __LINE__);
2717 void board_sleep_resume(void)
2720 unsigned char val[2];
2722 check_cpu_revision();
2726 if (max8998_probe())
2730 i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2731 i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2733 i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2734 i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2736 i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2737 i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2739 i2c_write(addr, MAX8998_REG_ONOFF4, 1, saved_val[3], 1);
2740 i2c_read(addr, MAX8998_REG_ONOFF4, 1, val, 1);
2741 puts("Waked up.\n");
2743 /* check max17040 */
2751 static int s5pc1xx_phy_control(int on)
2755 if (on && !status) {
2756 #ifdef CONFIG_CMD_PMIC
2757 run_command("pmic ldo 8 on", 0);
2758 run_command("pmic ldo 3 on", 0);
2761 if (board_is_limo_universal() ||
2762 board_is_limo_real() ||
2764 /* check usb path */
2765 if (board_is_limo_real() && !hwrevision(6))
2769 if (mach_is_tickertape())
2770 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2771 gpio_direction_output(&gpio->mp0_4, 0, 0);
2773 /* USB Path to AP */
2774 micro_usb_switch(0);
2776 } else if (!on && status) {
2777 #ifdef CONFIG_CMD_PMIC
2778 run_command("pmic ldo 3 off", 0);
2779 run_command("pmic ldo 8 off", 0);
2788 struct s3c_plat_otg_data s5pc110_otg_data = {
2789 .phy_control = s5pc1xx_phy_control,
2790 .regs_phy = S5PC110_PHY_BASE,
2791 .regs_otg = S5PC110_OTG_BASE,
2794 #if defined(CONFIG_USB_ETHER)
2795 int board_eth_init(bd_t *bis)
2799 s3c_udc_probe(&s5pc110_otg_data);
2800 if (usb_eth_initialize(bis) >= 0)
2806 #ifdef CONFIG_CMD_USB_MASS_STORAGE
2807 static int dummy_read_sector(unsigned int n, void *buf)
2809 memset(buf, n % 16, SECTOR_SIZE);
2813 static int dummy_write_sector(unsigned int n, void *buf)
2815 printf("%c", *((char*)buf + 0));
2816 printf("%c", *((char*)buf + 1));
2817 printf("%c", *((char*)buf + 2));
2822 static int dummy_get_capacity(void)
2827 static struct ums_board_info ums_board = {
2828 .read_sector = dummy_read_sector,
2829 .write_sector = dummy_write_sector,
2830 .get_capacity = dummy_get_capacity,
2831 .name = "u-Boot disk",
2834 struct ums_board_info *board_ums_init(void)
2836 s3c_udc_probe(&s5pc110_otg_data);
2841 #ifdef CONFIG_CMD_USBDOWN
2842 int usb_board_init(void)
2844 /* interrupt clear */
2845 pmic_get_irq(PWRON1S);
2847 #ifdef CONFIG_CMD_PMIC
2848 run_command("pmic ldo 8 on", 0);
2849 run_command("pmic ldo 3 on", 0);
2853 if (board_is_limo_universal() ||
2854 board_is_limo_real() ||
2856 /* check usb path */
2857 if (board_is_limo_real() && !hwrevision(6))
2861 if (mach_is_tickertape())
2862 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2863 gpio_direction_output(&gpio->mp0_4, 0, 0);
2865 /* USB Path to AP */
2866 micro_usb_switch(0);
2872 #ifdef CONFIG_GENERIC_MMC
2873 int s5p_no_mmc_support(void)
2875 if (mach_is_wmg160() && hwrevision(5))
2880 int board_mmc_init(bd_t *bis)
2885 if (s5p_no_mmc_support())
2888 /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2889 if (mach_is_goni() || mach_is_wmg160())
2890 gpio_direction_output(&gpio->j2, 7, 1);
2896 * GPG0[2] SD_0_CDn -> Not used
2897 * GPG0[3:6] SD_0_DATA[0:3]
2899 for (i = 0; i < 7; i++) {
2902 /* GPG0[0:6] special function 2 */
2903 gpio_cfg_pin(&gpio->g0, i, 0x2);
2904 /* GPG0[0:6] pull disable */
2905 gpio_set_pull(&gpio->g0, i, GPIO_PULL_NONE);
2906 /* GPG0[0:6] drv 4x */
2907 gpio_set_drv(&gpio->g0, i, GPIO_DRV_4X);
2910 if (board_is_sdk() && hwrevision(6)) {
2911 for (i = 3; i < 7; i++) {
2912 /* GPG1[3:6] special function 3 */
2913 gpio_cfg_pin(&gpio->g1, i, 0x3);
2914 /* GPG1[3:6] pull disable */
2915 gpio_set_pull(&gpio->g1,
2917 /* GPG1[3:6] drv 4x */
2918 gpio_set_drv(&gpio->g1, i, GPIO_DRV_4X);
2921 buswidth = 8; /* 8-bit buswidth */
2924 if (mach_is_geminus()) {
2925 gpio_direction_output(&gpio->j2, 7, 1);
2926 gpio_set_pull(&gpio->j2, 7, GPIO_PULL_NONE);
2929 /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
2930 gpio_cfg_pin(&gpio->h3, 4, GPIO_IRQ);
2931 gpio_set_pull(&gpio->h3, 4, GPIO_PULL_UP);
2933 err = s5p_mmc_init(0, buswidth);
2935 if (!gpio_get_value(&gpio->h3, 4)) {
2936 for (i = 0; i < 7; i++) {
2939 /* GPG2[0:6] special function 2 */
2940 gpio_cfg_pin(&gpio->g2, i, 0x2);
2941 /* GPG2[0:6] pull disable */
2942 gpio_set_pull(&gpio->g2, i, GPIO_PULL_NONE);
2943 /* GPG2[0:6] drv 4x */
2944 gpio_set_drv(&gpio->g2, i, GPIO_DRV_4X);
2946 err =s5p_mmc_init(2, 4);
2953 #ifdef CONFIG_CMD_DEVICE_POWER
2954 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
2958 if (strncmp(argv[1], "cp", 2) == 0) {
2959 micro_usb_switch(1);
2960 run_command("pmic safeout 2 on", 0);
2961 setenv("usb", "cp");
2962 } else if (strncmp(argv[1], "ap", 2) == 0) {
2963 micro_usb_switch(0);
2964 run_command("pmic safeout 2 off", 0);
2965 setenv("usb", "ap");
2975 printf("USB Path is set to %s\n", getenv("usb"));
2981 microusb, CONFIG_SYS_MAXARGS, 1, do_microusb,
2983 "cp - switch to CP\n"
2984 "microusb ap - switch to AP\n"