charger: wakeup and start booting if TA is out while charging/sleeping.
[kernel/u-boot.git] / board / samsung / universal / universal.c
1 /*
2  * Copyright (C) 2009 Samsung Electronics
3  * Kyungmin Park <kyungmin.park@samsung.com>
4  * Minkyu Kang <mk7.kang@samsung.com>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
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.
13  *
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.
18  *
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,
22  * MA 02111-1307 USA
23  */
24
25 #include <common.h>
26 #include <i2c.h>
27 #include <malloc.h>
28 #include <asm/io.h>
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/errno.h>
37 #include <fbutils.h>
38 #include <lcd.h>
39 #include <bmp_layout.h>
40
41 #include "animation_frames.h"
42 #include "gpio_setting.h"
43
44 DECLARE_GLOBAL_DATA_PTR;
45
46 #define C100_MACH_START                 3000
47 #define C110_MACH_START                 3100
48
49 /* FIXME Neptune workaround */
50 #define USE_NEPTUNE_BOARD
51 #undef USE_NEPTUNE_BOARD
52
53 static unsigned int board_rev;
54 static unsigned int battery_soc;
55 static struct s5pc110_gpio *s5pc110_gpio;
56
57 enum {
58         I2C_2,
59         I2C_GPIO3,
60         I2C_PMIC,
61         I2C_GPIO5,
62         I2C_GPIO6,
63         I2C_GPIO7,
64         I2C_GPIO10,
65 };
66
67 /*
68  * i2c 2
69  * SDA: GPD1[4]
70  * SCL: GPD1[5]
71  */
72 static struct i2c_gpio_bus_data i2c_2 = {
73         .sda_pin        = 4,
74         .scl_pin        = 5,
75 };
76
77 /*
78  * i2c gpio3
79  * SDA: GPJ3[6]
80  * SCL: GPJ3[7]
81  */
82 static struct i2c_gpio_bus_data i2c_gpio3 = {
83         .sda_pin        = 6,
84         .scl_pin        = 7,
85 };
86
87 /*
88  * i2c pmic
89  * SDA: GPJ4[0]
90  * SCL: GPJ4[3]
91  */
92 static struct i2c_gpio_bus_data i2c_pmic = {
93         .sda_pin        = 0,
94         .scl_pin        = 3,
95 };
96
97 /*
98  * i2c gpio5
99  * SDA: MP05[3]
100  * SCL: MP05[2]
101  */
102 static struct i2c_gpio_bus_data i2c_gpio5 = {
103         .sda_pin        = 3,
104         .scl_pin        = 2,
105 };
106
107 /*
108  * i2c gpio6
109  * SDA: GPJ3[4]
110  * SCL: GPJ3[5]
111  */
112 static struct i2c_gpio_bus_data i2c_gpio6 = {
113         .sda_pin        = 4,
114         .scl_pin        = 5,
115 };
116
117 /*
118  * i2c gpio7 - aries
119  * SDA: MP05[1]
120  * SCL: MP05[0]
121  */
122 static struct i2c_gpio_bus_data i2c_gpio7 = {
123         .sda_pin        = 1,
124         .scl_pin        = 0,
125 };
126
127 /*
128  * i2c gpio7 - cypress
129  * SDA: MP05[6]
130  * SCL: MP05[4]
131  */
132 static struct i2c_gpio_bus_data i2c_cypress_gpio7 = {
133         .sda_pin        = 6,
134         .scl_pin        = 4,
135 };
136
137 /*
138  * i2c gpio10
139  * SDA: GPJ3[0]
140  * SCL: GPJ3[1]
141  */
142 static struct i2c_gpio_bus_data i2c_gpio10 = {
143         .sda_pin        = 0,
144         .scl_pin        = 1,
145 };
146
147
148 static struct i2c_gpio_bus i2c_gpio[] = {
149         {
150                 .bus    = &i2c_2,
151         }, {
152                 .bus    = &i2c_gpio3,
153         }, {
154                 .bus    = &i2c_pmic,
155         }, {
156                 .bus    = &i2c_gpio5,
157         }, {
158                 .bus    = &i2c_gpio6,
159         }, {
160                 .bus    = &i2c_gpio7,
161         }, {
162                 .bus    = &i2c_gpio10,
163         },
164 };
165
166 u32 get_board_rev(void)
167 {
168         return board_rev;
169 }
170
171 static int hwrevision(int rev)
172 {
173         return (board_rev & 0xf) == rev;
174 }
175
176 enum {
177         MACH_UNIVERSAL,
178         MACH_TICKERTAPE,
179         MACH_AQUILA,
180         MACH_P1P2,      /* Don't remove it */
181         MACH_GEMINUS,
182         MACH_CYPRESS,
183
184         MACH_WMG160 = 160,
185 };
186
187 #define SPLIT_SCREEN_FEATURE    0x100
188
189 /* board is MACH_AQUILA and board is like below. */
190 #define J1_B2_BOARD             0x0200
191 #define LIMO_UNIVERSAL_BOARD    0x0400
192 #define LIMO_REAL_BOARD         0x0800
193 #define MEDIA_BOARD             0x1000
194 #define BAMBOO_BOARD            0x2000
195 #define ARIES_BOARD             0x4000
196 #define NEPTUNE_BOARD           0x8000
197
198 #define BOARD_MASK              0xFF00
199
200 static int c110_machine_id(void)
201 {
202         return gd->bd->bi_arch_number - C110_MACH_START;
203 }
204
205 static int machine_is_aquila(void)
206 {
207         return c110_machine_id() == MACH_AQUILA;
208 }
209
210 static int machine_is_tickertape(void)
211 {
212         return c110_machine_id() == MACH_TICKERTAPE;
213 }
214
215 static int machine_is_geminus(void)
216 {
217         return c110_machine_id() == MACH_GEMINUS;
218 }
219
220 static int machine_is_cypress(void)
221 {
222         return c110_machine_id() == MACH_CYPRESS;
223 }
224
225 static int board_is_limo_universal(void)
226 {
227         return machine_is_aquila() && (board_rev & LIMO_UNIVERSAL_BOARD);
228 }
229
230 static int board_is_limo_real(void)
231 {
232         return machine_is_aquila() && (board_rev & LIMO_REAL_BOARD);
233 }
234
235 static int board_is_media(void)
236 {
237         return machine_is_aquila() && (board_rev & MEDIA_BOARD);
238 }
239
240 static int board_is_j1b2(void)
241 {
242         return machine_is_aquila() && (board_rev & J1_B2_BOARD);
243 }
244
245 static int board_is_aries(void)
246 {
247         return machine_is_aquila() && (board_rev & ARIES_BOARD);
248 }
249
250 static int board_is_neptune(void)
251 {
252         return machine_is_aquila() && (board_rev & NEPTUNE_BOARD);
253 }
254
255 /* DLNA Dongle */
256 static int machine_is_wmg160(void)
257 {
258         return c110_machine_id() == MACH_WMG160;
259 }
260
261 static void enable_battery(void);
262
263 void i2c_init_board(void)
264 {
265         struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
266         int num_bus;
267
268         if (cpu_is_s5pc100())
269                 return;
270
271         num_bus = ARRAY_SIZE(i2c_gpio);
272
273         if (machine_is_aquila()) {
274                 if (board_is_aries()) {
275                         i2c_gpio[I2C_GPIO7].bus->gpio_base =
276                                 (unsigned int)&gpio->gpio_mp0_5;
277                 } else {
278                         i2c_gpio[I2C_GPIO6].bus->gpio_base = 0;
279                         i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
280                 }
281         } else if (machine_is_cypress()) {
282                 i2c_gpio[I2C_GPIO7].bus = &i2c_cypress_gpio7;
283                 i2c_gpio[I2C_GPIO7].bus->gpio_base =
284                         (unsigned int)&gpio->gpio_mp0_5;
285         } else {
286                 i2c_gpio[I2C_GPIO7].bus->gpio_base = 0;
287         }
288
289         i2c_gpio[I2C_2].bus->gpio_base = (unsigned int)&gpio->gpio_d1;
290         i2c_gpio[I2C_GPIO3].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
291         i2c_gpio[I2C_PMIC].bus->gpio_base = (unsigned int)&gpio->gpio_j4;
292         i2c_gpio[I2C_GPIO5].bus->gpio_base = (unsigned int)&gpio->gpio_mp0_5;
293         i2c_gpio[I2C_GPIO6].bus->gpio_base = (unsigned int)&gpio->gpio_j3;
294
295         i2c_gpio_init(i2c_gpio, num_bus, I2C_PMIC);
296
297         /* Reset on max17040 early */
298         if (battery_soc == 0)
299                 enable_battery();
300 }
301
302 #ifdef CONFIG_MISC_INIT_R
303 #define DEV_INFO_LEN            512
304 static char device_info[DEV_INFO_LEN];
305 static int display_info;
306
307 static void dprintf(const char *fmt, ...)
308 {
309         va_list args;
310         uint i;
311         char buf[128];
312
313         va_start(args, fmt);
314         i = vsprintf(buf, fmt, args);
315         va_end(args);
316
317         buf[127] = 0;
318
319         if ((strlen(device_info) + strlen(buf)) > (DEV_INFO_LEN - 1)) {
320                 puts("Flushing device info...\n");
321                 puts(device_info);
322                 device_info[0] = 0;
323         }
324         strcat(device_info, buf);
325         puts(buf);
326 }
327
328 #ifdef CONFIG_S5PC1XXFB
329 static void display_device_info(void)
330 {
331         if (!display_info)
332                 return;
333
334         init_font();
335         set_font_xy(0, 450);
336         set_font_color(FONT_WHITE);
337         fb_printf(device_info);
338         exit_font();
339
340         memset(device_info, 0x0, DEV_INFO_LEN);
341
342         udelay(5 * 1000 * 1000);
343 }
344 #endif
345
346 static const char *board_name[] = {
347         "Universal",
348         "TickerTape",
349         "Aquila",
350         "P1P2",         /* Don't remove it */
351         "Geminus",
352         "Cypress",
353         "Neptune",
354 };
355
356 enum {
357         MEM_4G1G1G,
358         MEM_4G2G1G,
359         MEM_4G3G1G,
360         MEM_4G4G1G,
361 };
362
363 static char feature_buffer[32];
364
365 static char *display_features(int board, int board_rev)
366 {
367         int count = 0;
368         char *buf = feature_buffer;
369         char *name = NULL;
370
371         if (board == MACH_AQUILA) {
372                 if (board_rev & SPLIT_SCREEN_FEATURE)
373                         name = "SplitScreen";
374                 if (board_rev & J1_B2_BOARD)
375                         name = "J1 B2";
376                 /* Limo Real or Universal */
377                 if (board_rev & LIMO_REAL_BOARD)
378                         name = "Limo Real";
379                 else if (board_rev & LIMO_UNIVERSAL_BOARD)
380                         name = "Limo Universal";
381                 if (board_rev & MEDIA_BOARD)
382                         name = "Media";
383                 if (board_rev & BAMBOO_BOARD)
384                         name = "Bamboo";
385                 if (board_rev & ARIES_BOARD)
386                         name = "Aries";
387                 if (board_rev & NEPTUNE_BOARD)
388                         name = "Neptune";
389
390                 if (name)
391                         count += sprintf(buf + count, " - %s", name);
392         }
393
394         return buf;
395 }
396
397 static char *get_board_name(int board)
398 {
399         if (board == MACH_WMG160)
400                 return "WMG160";
401         return (char *) board_name[board];
402 }
403
404 static void check_board_revision(int board, int rev)
405 {
406         switch (board) {
407         case MACH_AQUILA:
408                 /* Limo Real or Universal */
409                 if (rev & LIMO_UNIVERSAL_BOARD)
410                         board_rev &= ~J1_B2_BOARD;
411                 if (rev & LIMO_REAL_BOARD)
412                         board_rev &= ~(J1_B2_BOARD |
413                                         LIMO_UNIVERSAL_BOARD);
414                 if (rev & MEDIA_BOARD)
415                         board_rev &= ~(J1_B2_BOARD |
416                                         LIMO_UNIVERSAL_BOARD);
417                 if (rev & BAMBOO_BOARD)
418                         board_rev &= ~(J1_B2_BOARD |
419                                         LIMO_UNIVERSAL_BOARD |
420                                         LIMO_REAL_BOARD |
421                                         MEDIA_BOARD);
422                 if (rev & ARIES_BOARD)
423                         board_rev &= ~(J1_B2_BOARD |
424                                         LIMO_UNIVERSAL_BOARD);
425                 if (rev & NEPTUNE_BOARD)
426                         board_rev &= ~(J1_B2_BOARD |
427                                         LIMO_UNIVERSAL_BOARD);
428                 break;
429         case MACH_CYPRESS:
430         case MACH_TICKERTAPE:
431         case MACH_GEMINUS:
432         case MACH_WMG160:
433                 board_rev &= ~BOARD_MASK;
434                 break;
435         default:
436                 break;
437         }
438 }
439
440 static unsigned int get_hw_revision(struct s5pc1xx_gpio_bank *bank, int hwrev3)
441 {
442         unsigned int rev;
443         int mode3 = 1;
444
445         if (hwrev3)
446                 mode3 = 7;
447
448         gpio_direction_input(bank, 2);
449         gpio_direction_input(bank, 3);
450         gpio_direction_input(bank, 4);
451         gpio_direction_input(bank, mode3);
452
453         gpio_set_pull(bank, 2, GPIO_PULL_NONE);         /* HWREV_MODE0 */
454         gpio_set_pull(bank, 3, GPIO_PULL_NONE);         /* HWREV_MODE1 */
455         gpio_set_pull(bank, 4, GPIO_PULL_NONE);         /* HWREV_MODE2 */
456         gpio_set_pull(bank, mode3, GPIO_PULL_NONE);     /* HWREV_MODE3 */
457
458         rev = gpio_get_value(bank, 2);
459         rev |= (gpio_get_value(bank, 3) << 1);
460         rev |= (gpio_get_value(bank, 4) << 2);
461         rev |= (gpio_get_value(bank, mode3) << 3);
462
463         return rev;
464 }
465
466 static void check_hw_revision(void)
467 {
468         unsigned int board = MACH_UNIVERSAL;    /* Default is Universal */
469
470         if (cpu_is_s5pc100()) {
471                 struct s5pc100_gpio *gpio =
472                         (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
473
474                 board_rev = get_hw_revision(&gpio->gpio_j0, 0);
475
476                 /* C100 TickerTape */
477                 if (board_rev == 3)
478                         board = MACH_TICKERTAPE;
479         } else {
480                 struct s5pc110_gpio *gpio =
481                         (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
482                 int hwrev3 = 0;
483
484                 board_rev = 0;
485
486                 /*
487                  * Note Check 'Aquila' board first
488                  *
489                  * TT: TickerTape
490                  * SS: SplitScreen
491                  * LRA: Limo Real Aquila
492                  * LUA: Limo Universal Aquila
493                  * OA: Old Aquila
494                  * CYP: Cypress
495                  * BB: Bamboo
496                  *
497                  * ADDR = 0xE0200000 + OFF
498                  *
499                  *       OFF    Universal BB   LRA  LUA  OA   TT   SS        CYP
500                  *   J1: 0x0264 0x10      0x10 0x00 0x00 0x00 0x00 0x00     
501                  *   J2: 0x0284           0x01 0x10 0x00 
502                  *   H1: 0x0C24    W           0x28 0xA8 0x1C                0x0F
503                  *   H3: 0x0C64                0x03 0x07 0x0F               
504                  *   D1: 0x00C4 0x0F           0x3F 0x3F 0x0F 0xXC 0x3F
505                  *    I: 0x0224                          0x02 0x00 0x08
506                  * MP03: 0x0324                          0x9x      0xbx 0x9x
507                  * MP05: 0x0364                          0x80      0x88
508                  */
509
510                 /* C110 Aquila */
511                 if (gpio_get_value(&gpio->gpio_j1, 4) == 0) {
512                         board = MACH_AQUILA;
513                         board_rev |= J1_B2_BOARD;
514
515                         gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_NONE);
516                         gpio_direction_input(&gpio->gpio_j2, 6);
517
518                         /* Check board */
519                         if (gpio_get_value(&gpio->gpio_h1, 2) == 0)
520                                 board_rev |= LIMO_UNIVERSAL_BOARD;
521
522                         if (gpio_get_value(&gpio->gpio_h3, 2) == 0)
523                                 board_rev |= LIMO_REAL_BOARD;
524
525                         if (gpio_get_value(&gpio->gpio_j2, 6) == 1)
526                                 board_rev |= MEDIA_BOARD;
527
528                         /* set gpio to default value. */
529                         gpio_set_pull(&gpio->gpio_j2, 6, GPIO_PULL_DOWN);
530                         gpio_direction_output(&gpio->gpio_j2, 6, 0);
531                 }
532
533                 /* Workaround: C110 Aquila Rev0.6 */
534                 if (board_rev == 6) {
535                         board = MACH_AQUILA;
536                         board_rev |= LIMO_REAL_BOARD;
537                 }
538
539                 /* C110 Aquila Bamboo */
540                 if (gpio_get_value(&gpio->gpio_j2, 0) == 1) {
541                         board = MACH_AQUILA;
542                         board_rev |= BAMBOO_BOARD;
543                 }
544
545                 /* C110 TickerTape */
546                 if (gpio_get_value(&gpio->gpio_d1, 0) == 0 &&
547                                 gpio_get_value(&gpio->gpio_d1, 1) == 0)
548                         board = MACH_TICKERTAPE;
549
550                 /* WMG160 - GPH3[0:4] = 0x00 */
551                 if (board == MACH_TICKERTAPE) {
552                         int i, wmg160 = 1;
553
554                         for (i = 0; i < 4; i++) {
555                                 if (gpio_get_value(&gpio->gpio_h3, i) != 0) {
556                                         wmg160 = 0;
557                                         break;
558                                 }
559                         }
560                         if (wmg160) {
561                                 board = MACH_WMG160;
562                                 hwrev3 = 1;
563                         }
564                 }
565
566                 /* C110 Geminus for rev0.0 */
567                 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_NONE);
568                 gpio_direction_input(&gpio->gpio_j1, 2);
569                 if (gpio_get_value(&gpio->gpio_j1, 2) == 1) {
570                         board = MACH_GEMINUS;
571                         if ((board_rev & ~BOARD_MASK) == 3)
572                                 board_rev &= ~0xff;
573                 }
574                 gpio_set_pull(&gpio->gpio_j1, 2, GPIO_PULL_DOWN);
575                 gpio_direction_output(&gpio->gpio_j1, 2, 0);
576
577                 /* C110 Geminus for rev0.1 ~ */
578                 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_NONE);
579                 gpio_direction_input(&gpio->gpio_j0, 6);
580                 if (gpio_get_value(&gpio->gpio_j0, 6) == 1) {
581                         board = MACH_GEMINUS;
582                         hwrev3 = 1;
583                 }
584                 gpio_set_pull(&gpio->gpio_j0, 6, GPIO_PULL_DOWN);
585
586                 /* Aquila - Aries MP0_5[6] == 1 */
587                 gpio_direction_input(&gpio->gpio_mp0_5, 6);
588                 if (gpio_get_value(&gpio->gpio_mp0_5, 6) == 1) {
589                         /* Cypress: Do this for cypress */
590                         gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_NONE);
591                         gpio_direction_input(&gpio->gpio_j2, 2);
592                         if (gpio_get_value(&gpio->gpio_j2, 2) == 1) {
593                                 board = MACH_CYPRESS;
594                                 gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
595                         } else {
596                                 board = MACH_AQUILA;
597                                 board_rev |= ARIES_BOARD;
598 #ifdef USE_NEPTUNE_BOARD
599                                 board_rev &= ~ARIES_BOARD;
600                                 board_rev |= NEPTUNE_BOARD;
601 #endif
602                         }
603                         gpio_set_pull(&gpio->gpio_j2, 2, GPIO_PULL_DOWN);
604                         hwrev3 = 1;
605                 } else
606                         gpio_direction_output(&gpio->gpio_mp0_5, 6, 0);
607
608                 board_rev |= get_hw_revision(&gpio->gpio_j0, hwrev3);
609         }
610
611         /* Set machine id */
612         if (cpu_is_s5pc110())
613                 gd->bd->bi_arch_number = C110_MACH_START + board;
614         else
615                 gd->bd->bi_arch_number = C100_MACH_START + board;
616
617         /* Architecture Common settings */
618         if (cpu_is_s5pc110()) {
619                 setenv("mtdparts", MTDPARTS_DEFAULT_4KB);
620         } else {
621                 setenv("bootk", "onenand read 0x30007FC0 0x60000 0x300000; "
622                                 "bootm 0x30007FC0");
623                 setenv("updatek", "onenand erase 0x60000 0x300000; "
624                                   "onenand write 0x31008000 0x60000 0x300000");
625         }
626 }
627
628 static void show_hw_revision(void)
629 {
630         int board;
631
632         /*
633          * Workaround for Rev 0.3 + CP Ver ES 3.1
634          * it's Rev 0.4
635          */
636         if (board_is_limo_real()) {
637                 if (hwrevision(0)) {
638                         /* default is Rev 0.4 */
639                         board_rev &= ~0xf;
640                         board_rev |= 0x4;
641                 }
642         }
643
644         if (cpu_is_s5pc110())
645                 board = gd->bd->bi_arch_number - C110_MACH_START;
646         else
647                 board = gd->bd->bi_arch_number - C100_MACH_START;
648
649         check_board_revision(board, board_rev);
650
651         /* Set CPU Revision */
652         if (machine_is_aquila()) {
653                 if (board_is_limo_real()) {
654                         if ((board_rev & 0xf) < 8)
655                                 s5pc1xx_set_cpu_rev(0);
656                 }
657         } else if (machine_is_geminus()) {
658                 if ((board_rev & 0xf) < 1)
659                         s5pc1xx_set_cpu_rev(0);
660         } else if (machine_is_cypress()) {
661                 s5pc1xx_set_cpu_rev(1);
662         } else {
663                 s5pc1xx_set_cpu_rev(0);
664         }
665
666         dprintf("HW Revision:\t%x (%s%s) %s\n",
667                 board_rev, get_board_name(board),
668                 display_features(board, board_rev),
669                 s5pc1xx_get_cpu_rev() ? "" : "EVT0");
670 }
671
672 static void check_auto_burn(void)
673 {
674         unsigned long magic_base = CONFIG_SYS_SDRAM_BASE + 0x02000000;
675         unsigned int count = 0;
676         char buf[64];
677
678         if (readl(magic_base) == 0x426f6f74) {  /* ASICC: Boot */
679                 printf("Auto burning bootloader\n");
680                 count += sprintf(buf + count, "run updateb; ");
681         }
682         if (readl(magic_base + 0x04) == 0x4b65726e) {   /* ASICC: Kern */
683                 printf("Auto burning kernel\n");
684                 count += sprintf(buf + count, "run updatek; ");
685         }
686
687         if (count) {
688                 count += sprintf(buf + count, "reset");
689                 setenv("bootcmd", buf);
690         }
691
692         /* Clear the magic value */
693         writel(0xa5a55a5a, magic_base);
694         writel(0xa5a55a5a, magic_base + 0x4);
695 }
696
697 static void pmic_pin_init(void)
698 {
699         unsigned int reg, value;
700
701         if (cpu_is_s5pc100())
702                 return;
703
704         /* AP_PS_HOLD: XEINT_0: GPH0[0]
705          * Note: Don't use GPIO PS_HOLD it doesn't work
706          */
707         reg = S5PC110_PS_HOLD_CONTROL;
708         value = readl(reg);
709         value |= S5PC110_PS_HOLD_DIR_OUTPUT |
710                 S5PC110_PS_HOLD_DATA_HIGH |
711                 S5PC110_PS_HOLD_OUT_EN;
712         writel(value, reg);
713
714         /* nPOWER: XEINT_22: GPH2[6] interrupt mode */
715         gpio_cfg_pin(&s5pc110_gpio->gpio_h2, 6, GPIO_IRQ);
716         gpio_set_pull(&s5pc110_gpio->gpio_h2, 6, GPIO_PULL_UP);
717 }
718
719 static void enable_ldos(void)
720 {
721         if (cpu_is_s5pc100())
722                 return;
723
724         /* TOUCH_EN: XMMC3DATA_3: GPG3[6] output high */
725         gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, 1);
726 }
727
728 static void enable_t_flash(void)
729 {
730         if (!(board_is_limo_universal() || board_is_limo_real()))
731                 return;
732
733         /* T_FLASH_EN : XM0ADDR_13: MP0_5[4] output high */
734         gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 1);
735 }
736
737 static void setup_limo_real_gpios(void)
738 {
739         if (!board_is_limo_real())
740                 return;
741
742         /*
743          * Note: Please write GPIO alphabet order
744          */
745         /* CODEC_LDO_EN: XVVSYNC_LDI: GPF3[4] output high */
746         gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 1);
747
748         if (hwrevision(0))
749                 /* RESET_REQ_N: XM0BEN_1: MP0_2[1] output high */
750                 gpio_direction_output(&s5pc110_gpio->gpio_mp0_2, 1, 1);
751         else
752                 /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
753                 gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
754
755         /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
756         gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
757         gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
758 }
759
760 static void setup_media_gpios(void)
761 {
762         if (!board_is_media())
763                 return;
764
765         /*
766          * Note: Please write GPIO alphabet order
767          */
768         /* RESET_REQ_N: XM0CSn_2: MP0_1[2] output high */
769         gpio_direction_output(&s5pc110_gpio->gpio_mp0_1, 2, 1);
770
771         /* T_FLASH_DETECT: EINT28: GPH3[4] interrupt mode */
772         gpio_cfg_pin(&s5pc110_gpio->gpio_h3, 4, GPIO_IRQ);
773         gpio_set_pull(&s5pc110_gpio->gpio_h3, 4, GPIO_PULL_UP);
774 }
775
776 #define KBR3            (1 << 3)
777 #define KBR2            (1 << 2)
778 #define KBR1            (1 << 1)
779 #define KBR0            (1 << 0)
780
781 static void check_keypad(void)
782 {
783         unsigned int reg, value;
784         unsigned int col_num, row_num;
785         unsigned int col_mask;
786         unsigned int col_mask_shift;
787         unsigned int row_state[4];
788         unsigned int i;
789         unsigned int auto_download = 0;
790
791         if (machine_is_wmg160())
792                 return;
793
794         if (cpu_is_s5pc100()) {
795                 struct s5pc100_gpio *gpio =
796                         (struct s5pc100_gpio *)S5PC100_GPIO_BASE;
797
798                 row_num = 3;
799                 col_num = 3;
800
801                 /* Set GPH2[2:0] to KP_COL[2:0] */
802                 gpio_cfg_pin(&gpio->gpio_h2, 0, 0x3);
803                 gpio_cfg_pin(&gpio->gpio_h2, 1, 0x3);
804                 gpio_cfg_pin(&gpio->gpio_h2, 2, 0x3);
805
806                 /* Set GPH3[2:0] to KP_ROW[2:0] */
807                 gpio_cfg_pin(&gpio->gpio_h3, 0, 0x3);
808                 gpio_cfg_pin(&gpio->gpio_h3, 1, 0x3);
809                 gpio_cfg_pin(&gpio->gpio_h3, 2, 0x3);
810
811                 reg = S5PC100_KEYPAD_BASE;
812                 col_mask = S5PC1XX_KEYIFCOL_MASK;
813                 col_mask_shift = 0;
814         } else {
815                 if (board_is_limo_real() || board_is_limo_universal()) {
816                         row_num = 2;
817                         col_num = 3;
818                 } else {
819                         row_num = 4;
820                         col_num = 4;
821                 }
822
823                 for (i = 0; i < row_num; i++) {
824                         /* Set GPH3[3:0] to KP_ROW[3:0] */
825                         gpio_cfg_pin(&s5pc110_gpio->gpio_h3, i, 0x3);
826                         gpio_set_pull(&s5pc110_gpio->gpio_h3, i, GPIO_PULL_UP);
827                 }
828
829                 for (i = 0; i < col_num; i++)
830                         /* Set GPH2[3:0] to KP_COL[3:0] */
831                         gpio_cfg_pin(&s5pc110_gpio->gpio_h2, i, 0x3);
832
833                 reg = S5PC110_KEYPAD_BASE;
834                 col_mask = S5PC110_KEYIFCOLEN_MASK;
835                 col_mask_shift = 8;
836         }
837
838         /* KEYIFCOL reg clear */
839         writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
840
841         /* key_scan */
842         for (i = 0; i < col_num; i++) {
843                 value = col_mask;
844                 value &= ~(1 << i) << col_mask_shift;
845
846                 writel(value, reg + S5PC1XX_KEYIFCOL_OFFSET);
847                 udelay(1000);
848
849                 value = readl(reg + S5PC1XX_KEYIFROW_OFFSET);
850                 row_state[i] = ~value & ((1 << row_num) - 1);
851                 printf("[%d col] row_state: 0x%x\n", i, row_state[i]);
852         }
853
854         /* KEYIFCOL reg clear */
855         writel(0, reg + S5PC1XX_KEYIFCOL_OFFSET);
856
857         if (machine_is_aquila()) {
858                 /* cam full shot & volume down */
859                 if ((row_state[0] & 0x1) && (row_state[1] & 0x2))
860                         auto_download = 1;
861                 /* volume down */
862                 else if ((row_state[1] & 0x2))
863                         display_info = 1;
864         } else if (machine_is_geminus())
865                 /* volume down & home */
866                 if ((row_state[1] & 0x2) && (row_state[2] & 0x1))
867                         auto_download = 1;
868
869         if (auto_download)
870                 setenv("bootcmd", "usbdown");
871 }
872
873 static void enable_battery(void)
874 {
875         unsigned char val[2];
876         unsigned char addr = 0x36;      /* max17040 fuel gauge */
877
878         i2c_set_bus_num(I2C_GPIO3);
879
880         if (machine_is_aquila()) {
881                 if (board_is_aries() || board_is_neptune())
882                         i2c_set_bus_num(I2C_GPIO7);
883                 else if (board_is_j1b2())
884                         return;
885         } else if (machine_is_tickertape()) {
886                 return;
887         } else if (machine_is_cypress()) {
888                 i2c_set_bus_num(I2C_GPIO7);
889         } else if (machine_is_geminus()) {
890                 if (hwrevision(1))
891                         i2c_set_bus_num(I2C_GPIO7);
892         }
893
894         if (i2c_probe(addr)) {
895                 printf("Can't found max17040 fuel gauge\n");
896                 return;
897         }
898
899         val[0] = 0x54;
900         val[1] = 0x00;
901         i2c_write(addr, 0xfe, 1, val, 2);
902 }
903
904 static void check_battery(void)
905 {
906         unsigned char val[2];
907         unsigned char addr = 0x36;      /* max17040 fuel gauge */
908
909         i2c_set_bus_num(I2C_GPIO3);
910
911         if (machine_is_aquila()) {
912                 if (board_is_aries() || board_is_neptune())
913                         i2c_set_bus_num(I2C_GPIO7);
914                 else if (board_is_j1b2())
915                         return;
916         } else if (machine_is_cypress()) {
917                 i2c_set_bus_num(I2C_GPIO7);
918         } else if (machine_is_geminus()) {
919                 if (hwrevision(1))
920                         i2c_set_bus_num(I2C_GPIO7);
921         } else
922                 return;
923
924         if (i2c_probe(addr)) {
925                 printf("Can't found max17040 fuel gauge\n");
926                 return;
927         }
928
929         i2c_read(addr, 0x04, 1, val, 1);
930
931         dprintf("battery:\t%d%%\n", val[0]);
932
933         battery_soc = val[0];
934 }
935
936 static void check_mhl(void)
937 {
938         unsigned char val[2];
939         unsigned char addr = 0x39;      /* SIL9230 */
940
941         /* MHL Power enable */
942         /* HDMI_EN : GPJ2[2] XMSMDATA_2 output mode */
943         gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 1);
944
945         /* MHL_RST : MP0_4[7] XM0ADDR_7 output mode */
946         gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
947
948         /* 10ms required after reset */
949         udelay(10000);
950
951         /* output enable */
952         gpio_set_value(&s5pc110_gpio->gpio_mp0_4, 7, 1);
953
954         i2c_set_bus_num(I2C_GPIO5);
955
956         /* set usb path */
957         if (i2c_probe(addr)) {
958                 printf("Can't found MHL Chip\n");
959                 return;
960         }
961
962         /*
963          * System Control #1
964          * set to Normal operation
965          */
966         val[0] = 0x35;
967         i2c_write((0x72 >> 1), 0x08, 1, val, 1);
968         i2c_read((0x72 >> 1), 0x08, 1, val, 1);
969
970         /*
971          * MHL TX Control #1
972          * TERM_MODE [7:6]
973          * 00 = MHL termination ON
974          * 11 = MHL termination OFF
975          */
976         val[0] = 0xd0;
977         i2c_write((0x72 >> 1), 0xa0, 1, val, 1);
978         i2c_read((0x72 >> 1), 0xa0, 1, val, 1);
979 }
980
981 #define CHARGER_ANIMATION_FRAME         6
982 static int max8998_power_key(void)
983 {
984         unsigned char addr, val[2];
985         i2c_set_bus_num(I2C_PMIC);
986         addr = 0xCC >> 1;
987         if (i2c_probe(addr)) {
988                 printf("Can't found max8998\n");
989                 return 0;
990         }
991
992         /* Accessing IRQ1 register */
993         i2c_read(addr, 0x00, 1, val, 1);
994         if (val[0] & (1 << 6))
995                 return 1;
996
997         return 0;
998 }
999
1000 static int max8998_has_ext_power_source(void)
1001 {
1002         unsigned char addr, val[2];
1003         i2c_set_bus_num(I2C_PMIC);
1004         addr = 0xCC >> 1;
1005         if (i2c_probe(addr)) {
1006                 printf("Can't found max8998\n");
1007                 return 0;
1008         }
1009
1010         /* Accessing STATUS2 register */
1011         i2c_read(addr, 0x09, 1, val, 1);
1012         if (val[0] & (1 << 5))
1013                 return 1;
1014
1015         return 0;
1016 }
1017
1018 extern void lcd_display_clear(void);
1019 extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
1020
1021 static void into_charge_mode(void)
1022 {
1023         unsigned char addr = 0xCC >> 1; /* max8998 */;
1024         unsigned char val[2];
1025         unsigned int level;
1026         int i, j;
1027         bmp_image_t *bmp;
1028         unsigned long len;
1029         ulong bmp_addr[CHARGER_ANIMATION_FRAME];
1030
1031         i2c_set_bus_num(I2C_PMIC);
1032
1033         if (i2c_probe(addr)) {
1034                 printf("Can't found max8998\n");
1035                 return;
1036         }
1037
1038         printf("Charge Mode\n");
1039
1040         i2c_read(addr, 0x0C, 1, val, 1);
1041         val[0] &= ~(0x7 << 0);
1042         val[0] &= ~(0x7 << 5);
1043         val[0] |= 5;            /* 600mA */
1044         val[0] |= (3 << 5); /* Stop at 150mA(25%) */
1045         i2c_write(addr, 0x0C, 1, val, 1);
1046
1047 #ifdef CONFIG_S5PC1XXFB
1048         init_font();
1049
1050         /* TODO: write the image-text for the charger */
1051
1052         level = battery_soc * CHARGER_ANIMATION_FRAME / 100;
1053         if (level >= CHARGER_ANIMATION_FRAME)
1054                 level = CHARGER_ANIMATION_FRAME - 1;
1055
1056         for (i = 0; i < CHARGER_ANIMATION_FRAME; i++)
1057                 bmp_addr[i] = (ulong)battery_charging_animation[i];
1058
1059         lcd_display_clear();
1060         for (i = 0; i < 3; i++) {
1061                 for (j = level; j < CHARGER_ANIMATION_FRAME; j++) {
1062                         int k;
1063
1064                         bmp = gunzip_bmp(bmp_addr[j], &len);
1065                         lcd_display_bitmap((ulong) bmp, 140, 202);
1066                         free(bmp);
1067
1068                         for (k = 0; k < 10; k++)
1069                                 if (max8998_power_key()) {
1070                                         lcd_display_clear();
1071                                         return;
1072                                 } else if (!max8998_has_ext_power_source()) {
1073                                         lcd_display_clear();
1074                                         return;
1075                                 } else
1076                                         udelay(100 * 1000);
1077                 }
1078         }
1079         exit_font();
1080 #endif
1081
1082         /* EVT0: sleep 1, EVT1: sleep */
1083         if (s5pc1xx_get_cpu_rev() == 0) {
1084                 run_command("sleep 1", 0);
1085                 return;
1086         }
1087
1088         run_command("sleep", 0);
1089 }
1090
1091 static void check_micro_usb(int intr)
1092 {
1093         unsigned char addr;
1094         unsigned char val[2];
1095         static int started_charging_once = 0;
1096         char *path;
1097
1098         if (cpu_is_s5pc100())
1099                 return;
1100
1101         if (board_is_limo_real()) {
1102                 if (hwrevision(0) || hwrevision(1))
1103                         return;
1104         }
1105
1106         i2c_set_bus_num(I2C_PMIC);
1107
1108         if (machine_is_aquila()) {
1109                 if (board_is_aries() || board_is_neptune())
1110                         i2c_set_bus_num(I2C_GPIO6);
1111         } else if (machine_is_cypress()) {
1112                 i2c_set_bus_num(I2C_GPIO6);
1113         } else if (machine_is_geminus()) {
1114                 if (hwrevision(1))
1115                         i2c_set_bus_num(I2C_GPIO6);
1116         } else if (machine_is_wmg160())
1117                 i2c_set_bus_num(I2C_GPIO6);
1118
1119         addr = 0x25;            /* fsa9480 */
1120         if (i2c_probe(addr)) {
1121                 printf("Can't found fsa9480\n");
1122                 return;
1123         }
1124
1125         /* Clear Interrupt */
1126         if (intr) {
1127                 i2c_read(addr, 0x03, 1, val, 2);
1128                 udelay(500 * 1000);
1129         }
1130
1131         /* Read Device Type 1 */
1132         i2c_read(addr, 0x0a, 1, val, 1);
1133
1134 #define FSA_DEV1_CHARGER        (1 << 6)
1135 #define FSA_DEV1_UART           (1 << 3)
1136 #define FSA_DEV1_USB            (1 << 2)
1137 #define FSA_DEV2_JIG_USB_OFF    (1 << 1)
1138 #define FSA_DEV2_JIG_USB_ON     (1 << 0)
1139
1140         /*
1141          * If USB, use default 475mA
1142          * If Charger, use 600mA and go to charge mode
1143          */
1144         if ((val[0] & FSA_DEV1_CHARGER) && !started_charging_once) {
1145                 started_charging_once = 1;
1146                 into_charge_mode();
1147         }
1148
1149         /* If Factory Mode is Boot ON-USB, go to download mode */
1150         i2c_read(addr, 0x07, 1, val, 1);
1151
1152 #define FSA_ADC_FAC_USB_OFF     0x18
1153 #define FSA_ADC_FAC_USB_ON      0x19
1154 #define FSA_ADC_FAC_UART        0x1d
1155
1156         if (val[0] == FSA_ADC_FAC_USB_ON || val[0] == FSA_ADC_FAC_USB_OFF)
1157                 setenv("bootcmd", "usbdown");
1158
1159         path = getenv("usb");
1160
1161         if (!strncmp(path, "cp", 2))
1162                 run_command("microusb cp", 0);
1163 }
1164
1165 static void micro_usb_switch(int path)
1166 {
1167         unsigned char addr;
1168         unsigned char val[2];
1169
1170         i2c_set_bus_num(I2C_PMIC);
1171
1172         if (machine_is_aquila()) {
1173                 if (board_is_aries() || board_is_neptune())
1174                         i2c_set_bus_num(I2C_GPIO6);
1175         } else if (machine_is_cypress()) {
1176                 i2c_set_bus_num(I2C_GPIO6);
1177         } else if (machine_is_geminus()) {
1178                 if (hwrevision(1))
1179                         i2c_set_bus_num(I2C_GPIO6);
1180         } else if (machine_is_wmg160()) {
1181                 i2c_set_bus_num(I2C_GPIO6);
1182                 return;
1183         }
1184
1185         addr = 0x25;            /* fsa9480 */
1186         if (i2c_probe(addr)) {
1187                 printf("Can't found fsa9480\n");
1188                 return;
1189         }
1190
1191         if (path)
1192                 val[0] = 0x90;  /* VAUDIO */
1193         else
1194                 val[0] = (1 << 5) | (1 << 2);   /* DHOST */
1195
1196         i2c_write(addr, 0x13, 1, val, 1);       /* MANSW1 */
1197
1198         i2c_read(addr, 0x2, 1, val, 1);
1199         val[0] &= ~(1 << 2);                    /* Manual switching */
1200         i2c_write(addr, 0x2, 1, val, 1);
1201 }
1202
1203 #define MAX8998_REG_ONOFF1      0x11
1204 #define MAX8998_REG_ONOFF2      0x12
1205 #define MAX8998_REG_ONOFF3      0x13
1206 #define MAX8998_REG_LDO7        0x21
1207 #define MAX8998_REG_LDO17       0x29
1208 /* ONOFF1 */
1209 #define MAX8998_LDO3            (1 << 2)
1210 /* ONOFF2 */
1211 #define MAX8998_LDO6            (1 << 7)
1212 #define MAX8998_LDO7            (1 << 6)
1213 #define MAX8998_LDO8            (1 << 5)
1214 #define MAX8998_LDO9            (1 << 4)
1215 #define MAX8998_LDO10           (1 << 3)
1216 #define MAX8998_LDO11           (1 << 2)
1217 #define MAX8998_LDO12           (1 << 1)
1218 #define MAX8998_LDO13           (1 << 0)
1219 /* ONOFF3 */
1220 #define MAX8998_LDO14           (1 << 7)
1221 #define MAX8998_LDO15           (1 << 6)
1222 #define MAX8998_LDO16           (1 << 5)
1223 #define MAX8998_LDO17           (1 << 4)
1224
1225
1226 static void init_pmic(void)
1227 {
1228         unsigned char addr;
1229         unsigned char val[2];
1230
1231         if (cpu_is_s5pc100())
1232                 return;
1233
1234         i2c_set_bus_num(I2C_PMIC);
1235
1236         addr = 0xCC >> 1;       /* max8998 */
1237         if (i2c_probe(addr)) {
1238                 if (i2c_probe(addr)) {
1239                         printf("Can't found max8998\n");
1240                         return;
1241                 }
1242         }
1243
1244         /* ONOFF1 */
1245         i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1246         val[0] &= ~MAX8998_LDO3;
1247         i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1248
1249         /* ONOFF2 */
1250         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1251         /*
1252          * Disable LDO10(VPLL_1.1V), LDO11(CAM_IO_2.8V),
1253          * LDO12(CAM_ISP_1.2V), LDO13(CAM_A_2.8V)
1254          */
1255         val[0] &= ~(MAX8998_LDO10 | MAX8998_LDO11 |
1256                         MAX8998_LDO12 | MAX8998_LDO13);
1257
1258         if (board_is_aries() || board_is_neptune())
1259                 val[0] |= MAX8998_LDO7;         /* LDO7: VLCD_1.8V */
1260
1261         i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1262         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1263         /* ONOFF3 */
1264         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1265         /*
1266          * Disable LDO14(CAM_CIF_1.8), LDO15(CAM_AF_3.3V),
1267          * LDO16(VMIPI_1.8V), LDO17(CAM_8M_1.8V)
1268          */
1269         val[0] &= ~(MAX8998_LDO14 | MAX8998_LDO15 |
1270                         MAX8998_LDO16 | MAX8998_LDO17);
1271
1272         if (board_is_aries() || board_is_neptune())
1273                 val[0] |= MAX8998_LDO17;        /* LDO17: VCC_3.0V_LCD */
1274
1275         i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1276         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1277 }
1278
1279 static void setup_power_down_mode_registers(void)
1280 {
1281         struct s5pc110_gpio *gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
1282         struct s5pc1xx_gpio_bank *bank;
1283         struct gpio_powermode *p;
1284         int n_p;
1285         struct gpio_external *ge;
1286         int n_ge;
1287         struct s5pc1xx_gpio_item *mr;
1288         int n_mr;
1289         int i;
1290
1291         if (cpu_is_s5pc100())
1292                 return;
1293
1294         /* Only Limo real and aries supports worked for sleep currnet */
1295         if (machine_is_aquila()) {
1296                 if (board_is_limo_real())
1297                         /* Support */;
1298                 else if (board_is_aries() || board_is_neptune())
1299                         /* Support */;
1300                 else
1301                         return;
1302         } else if (machine_is_geminus()) {
1303                 /* Support */;
1304         } else
1305                 return;
1306
1307         if (machine_is_aquila()) {
1308                 if (board_is_aries() || board_is_neptune()) {
1309                         /* Aquila rev 0.9 */
1310                         p = aries_powerdown_modes;
1311                         ge = aries_external_powerdown_modes;
1312                         mr = aries_mirror_powerdown_mode;
1313                         n_p = ARRAY_SIZE(aries_powerdown_modes);
1314                         n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1315                         n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1316                 } else {
1317                         /* Aquila rev 0.8 or lower */
1318                         p = aquila_powerdown_modes;
1319                         ge = aquila_external_powerdown_modes;
1320                         mr = aquila_mirror_powerdown_mode;
1321                         n_p = ARRAY_SIZE(aquila_powerdown_modes);
1322                         n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1323                         n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1324                 }
1325         } else if (machine_is_geminus()) {
1326                 if (hwrevision(1)) {
1327                         /* Same as Aquila rev 0.9 */
1328 #if 0
1329                         p = aries_powerdown_modes;
1330                         ge = aries_external_powerdown_modes;
1331                         mr = aries_mirror_powerdown_mode;
1332                         n_p = ARRAY_SIZE(aries_powerdown_modes);
1333                         n_ge = ARRAY_SIZE(aries_external_powerdown_modes);
1334                         n_mr = ARRAY_SIZE(aries_mirror_powerdown_mode);
1335 #else
1336                         p = aquila_powerdown_modes;
1337                         ge = aquila_external_powerdown_modes;
1338                         mr = aquila_mirror_powerdown_mode;
1339                         n_p = ARRAY_SIZE(aquila_powerdown_modes);
1340                         n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1341                         n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1342 #endif
1343                 } else if (hwrevision(0)) {
1344                         /* Same as Aquila rev 0.8 or lower */
1345                         p = aquila_powerdown_modes;
1346                         ge = aquila_external_powerdown_modes;
1347                         mr = aquila_mirror_powerdown_mode;
1348                         n_p = ARRAY_SIZE(aquila_powerdown_modes);
1349                         n_ge = ARRAY_SIZE(aquila_external_powerdown_modes);
1350                         n_mr = ARRAY_SIZE(aquila_mirror_powerdown_mode);
1351                 } else {
1352                         return; /* Not supported */
1353                 }
1354         }
1355
1356         bank = &gpio->gpio_a0;
1357
1358         for (i = 0; i < n_p; i++, p++, bank++) {
1359                 writel(p->conpdn, &bank->pdn_con);
1360                 writel(p->pudpdn, &bank->pdn_pull);
1361         }
1362         /* M299 */
1363         writel(0xff0022b0, (unsigned int *)0xF0000000);
1364         writel(0xff0022b0, (unsigned int *)0xF1400000);
1365
1366         bank = &gpio->gpio_h0;
1367
1368         for (i = 0; i < n_ge; i++) {
1369                 writel(ge->con, &bank->con);
1370                 writel(ge->dat, &bank->dat);
1371                 writel(ge->pud, &bank->pull);
1372
1373                 bank++;
1374                 ge++;
1375         }
1376
1377         for (i = 0; i < n_mr; i++) {
1378                 unsigned int reg = readl(&mr->bank->pdn_con);
1379                 reg &= ~(1 << mr->number);
1380                 if (readl(&mr->bank->dat) & (1 << mr->number))
1381                         reg |= 1 << mr->number;
1382                 writel(reg, &mr->bank->pdn_con);
1383
1384                 printf("[%8.8X] = %8.8X\n", (unsigned int) (&mr->bank->pdn_con), reg);
1385
1386                 mr++;
1387         }
1388 }
1389
1390 #ifdef CONFIG_LCD
1391 #include "../../../drivers/video/s5p-spi.h"
1392
1393 extern void s6e63m0_set_platform_data(struct spi_platform_data *pd);
1394 extern void s6d16a0x_set_platform_data(struct spi_platform_data *pd);
1395
1396 struct spi_platform_data spi_pd;
1397
1398 struct s5pc110_gpio *gpio_base = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1399
1400 void lcd_cfg_gpio(void)
1401 {
1402         unsigned int i, f3_end = 4;
1403
1404         for (i = 0; i < 8; i++) {
1405                 /* set GPF0,1,2[0:7] for RGB Interface and Data lines (32bit) */
1406                 gpio_cfg_pin(&gpio_base->gpio_f0, i, GPIO_FUNC(2));
1407                 gpio_cfg_pin(&gpio_base->gpio_f1, i, GPIO_FUNC(2));
1408                 gpio_cfg_pin(&gpio_base->gpio_f2, i, GPIO_FUNC(2));
1409                 /* pull-up/down disable */
1410                 gpio_set_pull(&gpio_base->gpio_f0, i, GPIO_PULL_NONE);
1411                 gpio_set_pull(&gpio_base->gpio_f1, i, GPIO_PULL_NONE);
1412                 gpio_set_pull(&gpio_base->gpio_f2, i, GPIO_PULL_NONE);
1413
1414                 /* drive strength to max (24bit) */
1415                 gpio_set_drv(&gpio_base->gpio_f0, i, GPIO_DRV_4x);
1416                 gpio_set_rate(&gpio_base->gpio_f0, i, GPIO_DRV_SLOW);
1417                 gpio_set_drv(&gpio_base->gpio_f1, i, GPIO_DRV_4x);
1418                 gpio_set_rate(&gpio_base->gpio_f1, i, GPIO_DRV_SLOW);
1419                 gpio_set_drv(&gpio_base->gpio_f2, i, GPIO_DRV_4x);
1420                 gpio_set_rate(&gpio_base->gpio_f2, i, GPIO_DRV_SLOW);
1421         }
1422
1423         /* set DISPLAY_DE_B pin for dual rgb mode. */
1424         if (board_is_media())
1425                 f3_end = 5;
1426
1427         for (i = 0; i < f3_end; i++) {
1428                 /* set GPF3[0:3] for RGB Interface and Data lines (32bit) */
1429                 gpio_cfg_pin(&gpio_base->gpio_f3, i, GPIO_PULL_UP);
1430                 /* pull-up/down disable */
1431                 gpio_set_pull(&gpio_base->gpio_f3, i, GPIO_PULL_NONE);
1432                 /* drive strength to max (24bit) */
1433                 gpio_set_drv(&gpio_base->gpio_f3, i, GPIO_DRV_4x);
1434                 gpio_set_rate(&gpio_base->gpio_f3, i, GPIO_DRV_SLOW);
1435         }
1436         /* display output path selection (only [1:0] valid) */
1437         writel(0x2, 0xE0107008);
1438
1439         /* gpio pad configuration for LCD reset. */
1440         gpio_cfg_pin(&gpio_base->gpio_mp0_5, 5, GPIO_OUTPUT);
1441
1442         /* gpio pad configuration for LCD ON. */
1443         gpio_cfg_pin(&gpio_base->gpio_j1, 3, GPIO_OUTPUT);
1444
1445         /* LCD_BACKLIGHT_EN */
1446         if (machine_is_geminus())
1447                 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 0, GPIO_OUTPUT);
1448
1449         /*
1450          * gpio pad configuration for
1451          * DISPLAY_CS, DISPLAY_CLK, DISPLAY_SO, DISPLAY_SI.
1452          */
1453         gpio_cfg_pin(&gpio_base->gpio_mp0_1, 1, GPIO_OUTPUT);
1454         gpio_cfg_pin(&gpio_base->gpio_mp0_4, 1, GPIO_OUTPUT);
1455         gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_INPUT);
1456         gpio_cfg_pin(&gpio_base->gpio_mp0_4, 3, GPIO_OUTPUT);
1457
1458         if (machine_is_aquila()) {
1459                 spi_pd.cs_bank = &gpio_base->gpio_mp0_1;
1460                 spi_pd.cs_num = 1;
1461                 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1462                 spi_pd.clk_num = 1;
1463                 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1464                 spi_pd.si_num = 3;
1465                 spi_pd.so_bank = &gpio_base->gpio_mp0_4;
1466                 spi_pd.so_num = 2;
1467
1468                 if (board_is_neptune())
1469                         s6d16a0x_set_platform_data(&spi_pd);
1470                 else {
1471                         s6e63m0_set_platform_data(&spi_pd);
1472                         if (board_is_media())
1473                                 spi_pd.set_rev = 1;
1474                 }
1475         }
1476
1477         if (machine_is_cypress()) {
1478 #if 0           /* universal cypress */
1479                 /* FLCD_CS */
1480                 gpio_cfg_pin(&gpio_base->gpio_mp0_1, 0, GPIO_OUTPUT);
1481 #endif
1482                 /* FLCD_CS_S */
1483                 gpio_cfg_pin(&gpio_base->gpio_mp0_5, 1, GPIO_OUTPUT);
1484                 /* FLCD_CLK */
1485                 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 0, GPIO_OUTPUT);
1486                 /* FLCD_SDI */
1487                 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 2, GPIO_OUTPUT);
1488                 /* FLCD_RST_S */
1489                 gpio_cfg_pin(&gpio_base->gpio_mp0_4, 5, GPIO_OUTPUT);
1490                 /* FLCD_ON_S */
1491                 gpio_cfg_pin(&gpio_base->gpio_g2, 2, GPIO_OUTPUT);
1492 #if 0           /* universal cypress */
1493                 pd_cs.bank = &gpio_base->gpio_mp0_1;
1494                 pd_cs.num = 0;
1495 #endif
1496                 spi_pd.cs_bank = &gpio_base->gpio_mp0_5;
1497                 spi_pd.cs_num = 1;
1498                 spi_pd.clk_bank = &gpio_base->gpio_mp0_4;
1499                 spi_pd.clk_num = 0;
1500                 spi_pd.si_bank = &gpio_base->gpio_mp0_4;
1501                 spi_pd.si_num = 2;
1502
1503                 spi_pd.set_rev = 1;
1504
1505                 /* these data would be sent to s6e63m0 lcd panel driver. */
1506                 s6e63m0_set_platform_data(&spi_pd);
1507         }
1508
1509         return;
1510 }
1511
1512 void backlight_on(unsigned int onoff)
1513 {
1514         struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1515
1516         if (onoff) {
1517                 if (machine_is_geminus())
1518                         gpio_set_value(&gpio->gpio_mp0_5, 0, 1);
1519         } else {
1520                 if (machine_is_geminus())
1521                         gpio_set_value(&gpio->gpio_mp0_5, 0, 0);
1522         }
1523 }
1524
1525 void reset_lcd(void)
1526 {
1527         struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1528
1529         if (machine_is_aquila() || machine_is_geminus())
1530                 gpio_set_value(&gpio->gpio_mp0_5, 5, 1);
1531         if (machine_is_cypress())
1532                 gpio_set_value(&gpio->gpio_mp0_4, 5, 1);
1533 }
1534
1535 void lcd_power_on(unsigned int onoff)
1536 {
1537         struct s5pc110_gpio *gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1538         if (onoff) {
1539                 /* TSP_LDO_ON */
1540                 if (machine_is_aquila() || machine_is_geminus())
1541                         gpio_set_value(&gpio->gpio_j1, 3, 1);
1542
1543                 if (machine_is_cypress())
1544                         gpio_set_value(&gpio->gpio_g2, 2, 1);
1545
1546                 if (board_is_aries() || board_is_neptune()) {
1547                         unsigned char addr;
1548                         unsigned char val[2];
1549                         unsigned char val2[2];
1550
1551                         i2c_set_bus_num(I2C_PMIC);
1552                         addr = 0xCC >> 1;       /* max8998 */
1553                         if (i2c_probe(addr)) {
1554                                 printf("Can't found max8998\n");
1555                                 return;
1556                         }
1557                         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1558                         val[0] &= ~(MAX8998_LDO17);
1559                         val[0] |= MAX8998_LDO17;        /* LDO17: VCC_3.0V_LCD */
1560                         i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1561
1562                         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1563                         val[0] |= MAX8998_LDO17;
1564                         val2[0] = 0xE;
1565                         i2c_write(addr, MAX8998_REG_LDO17, 1, val2, 1);
1566                         i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1567
1568                         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1569                         val[0] |= MAX8998_LDO7;
1570                         val2[0] = 0x2;
1571                         i2c_write(addr, MAX8998_REG_LDO7, 1, val2, 1);
1572                         i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1573                 }
1574         } else {
1575                 if (machine_is_aquila() || machine_is_geminus())
1576                         gpio_set_value(&gpio->gpio_j1, 3, 0);
1577
1578                 if (machine_is_cypress())
1579                         gpio_set_value(&gpio->gpio_g2, 2, 0);
1580
1581                 if (board_is_aries() || board_is_neptune()) {
1582                         unsigned char addr;
1583                         unsigned char val[2];
1584
1585                         i2c_set_bus_num(I2C_PMIC);
1586                         addr = 0xCC >> 1;       /* max8998 */
1587                         if (i2c_probe(addr)) {
1588                                 printf("Can't found max8998\n");
1589                                 return;
1590                         }
1591
1592                         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1593                         val[0] &= ~(1 << 7);
1594                         i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1595                         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
1596
1597                         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1598                         val[0] &= ~MAX8998_LDO17;
1599                         i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1600                         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
1601                 }
1602         }
1603 }
1604
1605 extern void s6e63m0_cfg_ldo(void);
1606 extern void s6e63m0_enable_ldo(unsigned int onoff);
1607 extern void s6d16a0x_cfg_ldo(void);
1608 extern void s6d16a0x_enable_ldo(unsigned int onoff);
1609
1610 int s5p_no_lcd_support(void)
1611 {
1612         if (machine_is_wmg160())
1613                 return 1;
1614         return 0;
1615 }
1616
1617 void init_panel_info(vidinfo_t *vid)
1618 {
1619         vid->cfg_gpio = NULL;
1620         vid->reset_lcd = NULL;
1621         vid->backlight_on = NULL;
1622         vid->lcd_power_on = NULL;
1623
1624         vid->cfg_ldo = NULL;
1625         vid->enable_ldo = NULL;
1626
1627         vid->init_delay = 0;
1628         vid->reset_delay = 0;
1629         vid->power_on_delay = 0;
1630
1631         vid->vl_freq    = 60;
1632         vid->vl_col     = 480;
1633         vid->vl_row     = 800;
1634         vid->vl_width   = 480;
1635         vid->vl_height  = 800;
1636
1637         vid->dual_lcd_enabled = 0;
1638
1639         if (board_is_media()) {
1640                 vid->vl_col     = 960;
1641                 vid->vl_row     = 800;
1642                 vid->vl_width   = 960;
1643                 vid->vl_height  = 800;
1644
1645                 /* enable dual lcd mode. */
1646                 vid->dual_lcd_enabled = 1;
1647         }
1648
1649         vid->vl_clkp    = CONFIG_SYS_HIGH;
1650         vid->vl_hsp     = CONFIG_SYS_LOW;
1651         vid->vl_vsp     = CONFIG_SYS_LOW;
1652         vid->vl_dp      = CONFIG_SYS_HIGH;
1653         vid->vl_bpix    = 32;
1654
1655         /* S6E63M0 LCD Panel */
1656         vid->vl_hspw    = 2;
1657         vid->vl_hbpd    = 16;
1658         vid->vl_hfpd    = 16;
1659
1660         vid->vl_vspw    = 2;
1661         vid->vl_vbpd    = 3;
1662         vid->vl_vfpd    = 28;
1663
1664         if (machine_is_aquila() || machine_is_cypress()) {
1665                 vid->cfg_gpio = lcd_cfg_gpio;
1666                 vid->reset_lcd = reset_lcd;
1667                 vid->backlight_on = backlight_on;
1668                 vid->lcd_power_on = lcd_power_on;
1669                 vid->cfg_ldo = s6e63m0_cfg_ldo;
1670                 vid->enable_ldo = s6e63m0_enable_ldo;
1671
1672                 vid->init_delay = 25000;
1673                 vid->reset_delay = 120000;
1674         }
1675
1676         if (board_is_neptune()) {
1677                 vid->vl_freq    = 100;
1678                 vid->vl_col     = 320;
1679                 vid->vl_row     = 480;
1680                 vid->vl_width   = 320;
1681                 vid->vl_height  = 480;
1682
1683                 vid->vl_clkp    = CONFIG_SYS_HIGH;
1684                 vid->vl_hsp     = CONFIG_SYS_HIGH;
1685                 vid->vl_vsp     = CONFIG_SYS_HIGH;
1686                 vid->vl_dp      = CONFIG_SYS_LOW;
1687                 vid->vl_bpix    = 32;
1688
1689                 /* disable dual lcd mode. */
1690                 vid->dual_lcd_enabled = 0;
1691
1692                 /* S6D16A0X LCD Panel */
1693                 vid->vl_hspw    = 16;
1694                 vid->vl_hbpd    = 24;
1695                 vid->vl_hfpd    = 16;
1696
1697                 vid->vl_vspw    = 2;
1698                 vid->vl_vbpd    = 2;
1699                 vid->vl_vfpd    = 4;
1700
1701                 vid->cfg_gpio = lcd_cfg_gpio;
1702                 vid->backlight_on = NULL;
1703                 vid->lcd_power_on = lcd_power_on;
1704                 vid->reset_lcd = reset_lcd;
1705                 vid->cfg_ldo = s6d16a0x_cfg_ldo;
1706                 vid->enable_ldo = s6d16a0x_enable_ldo;
1707
1708                 vid->init_delay = 10000;
1709                 vid->power_on_delay = 10000;
1710                 vid->reset_delay = 1000;
1711
1712         }
1713
1714         if (machine_is_geminus()) {
1715                 vid->vl_freq    = 60;
1716                 vid->vl_col     = 1024,
1717                 vid->vl_row     = 600,
1718                 vid->vl_width   = 1024,
1719                 vid->vl_height  = 600,
1720                 vid->vl_clkp    = CONFIG_SYS_LOW,
1721                 vid->vl_hsp     = CONFIG_SYS_HIGH,
1722                 vid->vl_vsp     = CONFIG_SYS_HIGH,
1723                 vid->vl_dp      = CONFIG_SYS_LOW,
1724                 vid->vl_bpix    = 32,
1725
1726                 vid->vl_hspw    = 32,
1727                 vid->vl_hfpd    = 48,
1728                 vid->vl_hbpd    = 80,
1729
1730                 vid->vl_vspw    = 1,
1731                 vid->vl_vfpd    = 3,
1732                 vid->vl_vbpd    = 4,
1733
1734                 vid->cfg_gpio = lcd_cfg_gpio;
1735                 vid->reset_lcd = reset_lcd;
1736                 vid->backlight_on = backlight_on;
1737                 vid->lcd_power_on = lcd_power_on;
1738         }
1739 #if 0
1740         vid->vl_freq    = 60;
1741         vid->vl_col     = 480,
1742         vid->vl_row     = 800,
1743         vid->vl_width   = 480,
1744         vid->vl_height  = 800,
1745         vid->vl_clkp    = CONFIG_SYS_HIGH,
1746         vid->vl_hsp     = CONFIG_SYS_LOW,
1747         vid->vl_vsp     = CONFIG_SYS_LOW,
1748         vid->vl_dp      = CONFIG_SYS_HIGH,
1749         vid->vl_bpix    = 32,
1750
1751         /* tl2796 panel. */
1752         vid->vl_hpw     = 4,
1753         vid->vl_blw     = 8,
1754         vid->vl_elw     = 8,
1755
1756         vid->vl_vpw     = 4,
1757         vid->vl_bfw     = 8,
1758         vid->vl_efw     = 8,
1759 #endif
1760 #if 0
1761         vid->vl_freq    = 60;
1762         vid->vl_col     = 1024,
1763         vid->vl_row     = 600,
1764         vid->vl_width   = 1024,
1765         vid->vl_height  = 600,
1766         vid->vl_clkp    = CONFIG_SYS_HIGH,
1767         vid->vl_hsp     = CONFIG_SYS_HIGH,
1768         vid->vl_vsp     = CONFIG_SYS_HIGH,
1769         vid->vl_dp      = CONFIG_SYS_LOW,
1770         vid->vl_bpix    = 32,
1771
1772         /* AMS701KA AMOLED Panel. */
1773         vid->vl_hpw     = 30,
1774         vid->vl_blw     = 114,
1775         vid->vl_elw     = 48,
1776
1777         vid->vl_vpw     = 2,
1778         vid->vl_bfw     = 6,
1779         vid->vl_efw     = 8,
1780 #endif
1781 }
1782 #endif
1783
1784 static void setup_meminfo(void)
1785 {
1786         char meminfo[64] = {0, };
1787         int count = 0, size, real;
1788
1789         size = gd->bd->bi_dram[0].size >> 20;
1790         count += sprintf(meminfo + count, "mem=%dM", size);
1791
1792         /* Each Chip Select can't exceed the 256MiB */
1793         size = gd->bd->bi_dram[1].size >> 20;
1794         real = min(size, 256);
1795         count += sprintf(meminfo + count, " mem=%dM@0x%x",
1796                 real, (unsigned int)gd->bd->bi_dram[1].start);
1797
1798         size -= real;
1799         if (size > 0) {
1800                 count += sprintf(meminfo + count, " mem=%dM@0x%x", size,
1801                         (unsigned int)gd->bd->bi_dram[1].start + (real << 20));
1802         }
1803
1804         setenv("meminfo", meminfo);
1805 }
1806
1807 /*
1808  * CSA partition Migration
1809  * It will be deleted
1810  */
1811 static void csa_migration(void)
1812 {
1813         unsigned int *ubi_id;
1814         int i;
1815
1816         run_command("onenand read 0x40000000 0x400000 0x400000", 0);
1817
1818         for (i = 0; i < 10; i++) {
1819                 ubi_id = (void *) (0x40000000 + 0x40000 * i);
1820                 if (*ubi_id == 0x23494255) /* 0x23494255 = UBI */ {
1821                         printf("CSA Migration is already done....\n");
1822                         return;
1823                 }
1824         }
1825         run_command("onenand erase 0x400000 0x800000", 0);
1826 }
1827
1828 int misc_init_r(void)
1829 {
1830 #ifdef CONFIG_LCD
1831         /* It should be located at first */
1832         lcd_is_enabled = 0;
1833
1834         if (machine_is_aquila()) {
1835                 if (board_is_neptune())
1836                         setenv("lcdinfo", "lcd=s6d16a0x");
1837                 else if (board_is_media())
1838                         setenv("lcdinfo", "lcd=s6e63m0");
1839                 else
1840                         setenv("lcdinfo", "lcd=s6e63m0");
1841         }
1842         if (machine_is_geminus())
1843                 setenv("lcdinfo", "lcd=lms480jc01");
1844         if (machine_is_cypress())
1845                 setenv("lcdinfo", "lcd=s6e63m0");
1846 #endif
1847         setup_meminfo();
1848
1849         show_hw_revision();
1850
1851         /* Set proper PMIC pins */
1852         pmic_pin_init();
1853
1854         /* Check auto burning */
1855         check_auto_burn();
1856
1857         /* To power up I2C2 */
1858         enable_ldos();
1859
1860         /* Enable T-Flash at Limo Real or Limo Universal */
1861         enable_t_flash();
1862
1863         /* Setup Limo Real board GPIOs */
1864         setup_limo_real_gpios();
1865
1866         /* Setup Media board GPIOs */
1867         setup_media_gpios();
1868
1869         /* To usbdown automatically */
1870         check_keypad();
1871
1872         /* check max8998 */
1873         init_pmic();
1874
1875 #ifdef CONFIG_S5PC1XXFB
1876         display_device_info();
1877 #endif
1878
1879         setup_power_down_mode_registers();
1880
1881         /* check max17040 */
1882         check_battery();
1883
1884         /* check fsa9480 */
1885         check_micro_usb(0);
1886
1887         /* csa migration (temporary) */
1888         csa_migration();
1889
1890         return 0;
1891 }
1892 #endif
1893
1894 int board_init(void)
1895 {
1896         /* Set Initial global variables */
1897         s5pc110_gpio = (struct s5pc110_gpio *) S5PC110_GPIO_BASE;
1898
1899         gd->bd->bi_arch_number = MACH_TYPE;
1900         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
1901
1902         /* Check H/W Revision */
1903         check_hw_revision();
1904
1905         return 0;
1906 }
1907
1908 int dram_init(void)
1909 {
1910         unsigned int base, memconfig0, size;
1911         unsigned int memconfig1, sz = 0;
1912
1913         if (cpu_is_s5pc100()) {
1914                 /* In mem setup, we swap the bank. So below size is correct */
1915                 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1916                 gd->bd->bi_dram[0].size = PHYS_SDRAM_2_SIZE;
1917                 gd->bd->bi_dram[1].start = S5PC100_PHYS_SDRAM_2;
1918                 size = 128;
1919         } else {
1920                 /* In S5PC110, we can't swap the DMC0/1 */
1921                 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
1922                 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
1923
1924                 base = S5PC110_DMC1_BASE;
1925                 /* DMC configuration */
1926                 memconfig0 = readl(base + MEMCONFIG0_OFFSET);
1927                 gd->bd->bi_dram[1].start = memconfig0 & 0xFF000000;
1928
1929                 size = (memconfig0 >> 16) & 0xFF;
1930                 size = ((unsigned char) ~size) + 1;
1931
1932                 /*
1933                  * (0x07 + 1) * 16 = 128 MiB
1934                  * (0x0f + 1) * 16 = 256 MiB
1935                  */
1936                 size = size << 4;
1937
1938                 /*
1939                  * Aquila Rev0.5 4G3G1G
1940                  * Aquila Rev0.8 4G3G1G
1941                  * Aquila Rev0.9 4G3G1G
1942                  */
1943                 if (machine_is_aquila() &&
1944                     (hwrevision(5) || hwrevision(8) || hwrevision(9))) {
1945                         memconfig1 = readl(base + MEMCONFIG1_OFFSET);
1946
1947                         sz = (memconfig1 >> 16) & 0xFF;
1948                         sz = ((unsigned char) ~sz) + 1;
1949                         sz = sz << 4;
1950                 }
1951
1952         }
1953         /*
1954          * bi_dram[1].size contains all DMC1 memory size
1955          */
1956         gd->bd->bi_dram[1].size = (size + sz) << 20;
1957
1958         return 0;
1959 }
1960
1961 /* Used for sleep test */
1962 static unsigned char saved_val[4][2];
1963 void board_sleep_init_late(void)
1964 {
1965         /* CODEC_LDO_EN: GPF3[4] */
1966         gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, 0);
1967         /* CODEC_XTAL_EN: GPH3[2] */
1968         gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, 0);
1969
1970         /* MMC T_FLASH off */
1971         gpio_direction_output(&s5pc110_gpio->gpio_mp0_5, 4, 0);
1972         /* MHL off */
1973         gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, 0);
1974         gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 7, 0);
1975         gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, 0); /* MHL_ON for REV02 or higher */
1976
1977
1978 }
1979 void board_sleep_init(void)
1980 {
1981         unsigned char addr;
1982         unsigned char val[2];
1983
1984         i2c_set_bus_num(I2C_PMIC);
1985         addr = 0xCC >> 1;
1986         if (i2c_probe(addr)) {
1987                 printf("Can't find max8998\n");
1988                 return;
1989         }
1990
1991         /* Set ONOFF1 */
1992         i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1993         saved_val[0][0] = val[0];
1994         saved_val[0][1] = val[1];
1995         val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) |
1996                         (1 << 1) | (1 << 0));
1997         i2c_write(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1998         i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
1999         /* Set ONOFF2 */
2000         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2001         saved_val[1][0] = val[0];
2002         saved_val[1][1] = val[1];
2003         val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 3) |
2004                         (1 << 2) | (1 << 1) | (1 << 0));
2005         val[0] |= (1 << 7);
2006         i2c_write(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2007         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2008         /* Set ONOFF3 */
2009         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2010         saved_val[2][0] = val[0];
2011         saved_val[2][1] = val[1];
2012         val[0] &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
2013         i2c_write(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2014         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2015         /* Set ONOFF4 */
2016         i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2017         saved_val[3][0] = val[0];
2018         saved_val[3][1] = val[1];
2019         val[0] &= ~((1 << 7) | (1 << 6) | (1 << 4));
2020         i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2021         i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2022         printf("Turned off regulators. Preparing to sleep. [%s:%d]\n",
2023                         __FILE__, __LINE__);
2024 }
2025
2026 void board_sleep_resume(void)
2027 {
2028         unsigned char addr;
2029         unsigned char val[2];
2030
2031         show_hw_revision();
2032
2033         i2c_set_bus_num(I2C_PMIC);
2034         addr = 0xCC >> 1;
2035         if (i2c_probe(addr)) {
2036                 printf("Can't find max8998\n");
2037                 return;
2038         }
2039
2040         /* Set ONOFF1 */
2041         i2c_write(addr, MAX8998_REG_ONOFF1, 1, saved_val[0], 1);
2042         i2c_read(addr, MAX8998_REG_ONOFF1, 1, val, 1);
2043         /* Set ONOFF2 */
2044         i2c_write(addr, MAX8998_REG_ONOFF2, 1, saved_val[1], 1);
2045         i2c_read(addr, MAX8998_REG_ONOFF2, 1, val, 1);
2046         /* Set ONOFF3 */
2047         i2c_write(addr, MAX8998_REG_ONOFF3, 1, saved_val[2], 1);
2048         i2c_read(addr, MAX8998_REG_ONOFF3, 1, val, 1);
2049         /* Set ONOFF4 */
2050         i2c_write(addr, MAX8998_REG_ONOFF3+1, 1, saved_val[3], 1);
2051         i2c_read(addr, MAX8998_REG_ONOFF3+1, 1, val, 1);
2052         printf("Waked up.\n");
2053
2054         /* check max17040 */
2055         check_battery();
2056
2057         /* check fsa9480 */
2058         check_micro_usb(1);
2059 }
2060
2061 #ifdef CONFIG_CMD_USBDOWN
2062 int usb_board_init(void)
2063 {
2064 #ifdef CONFIG_CMD_PMIC
2065         run_command("pmic ldo 3 on", 0);
2066 #endif
2067
2068         if (cpu_is_s5pc100()) {
2069 #ifdef CONFIG_HARD_I2C
2070                 uchar val[2] = {0,};
2071
2072                 /* PMIC */
2073                 if (i2c_read(0x66, 0, 1, val, 2)) {
2074                         printf("i2c_read error\n");
2075                         return 1;
2076                 }
2077
2078                 val[0] |= (1 << 3);
2079                 val[1] |= (1 << 5);
2080
2081                 if (i2c_write(0x66, 0, 1, val, 2)) {
2082                         printf("i2c_write error\n");
2083                         return 1;
2084                 }
2085                 i2c_read(0x66, 0, 1, val, 2);
2086 #endif
2087                 return 0;
2088         }
2089
2090         /* S5PC110 */
2091         if (board_is_limo_universal() ||
2092                 board_is_limo_real() ||
2093                 board_is_media()) {
2094                 /* check usb path */
2095                 if (board_is_limo_real() && !hwrevision(6))
2096                         check_mhl();
2097         }
2098
2099         if (machine_is_tickertape())
2100                 /* USB_SEL: XM0ADDR_0: MP04[0] output mode */
2101                 gpio_direction_output(&s5pc110_gpio->gpio_mp0_4, 0, 0);
2102
2103         /* USB Path to AP */
2104         micro_usb_switch(0);
2105
2106         return 0;
2107 }
2108 #endif
2109
2110 #ifdef CONFIG_GENERIC_MMC
2111 int s5p_no_mmc_support(void)
2112 {
2113         if (machine_is_wmg160())
2114                 return 1;
2115         return 0;
2116 }
2117
2118 int board_mmc_init(bd_t *bis)
2119 {
2120         unsigned int reg;
2121         unsigned int clock;
2122         struct s5pc110_clock *clk = (struct s5pc110_clock *)S5PC1XX_CLOCK_BASE;
2123         int i;
2124
2125         /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
2126         if (machine_is_aquila() && (board_is_aries() || board_is_neptune()))
2127                 gpio_direction_output(&s5pc110_gpio->gpio_j2, 7, 1);
2128
2129         if (machine_is_wmg160())
2130                 return -1;
2131
2132         /* MMC0 Clock source = SCLKMPLL */
2133         reg = readl(&clk->src4);
2134         reg &= ~0xf;
2135         reg |= 0x6;
2136         writel(reg, &clk->src4);
2137
2138         reg = readl(&clk->div4);
2139         reg &= ~0xf;
2140
2141         /* set div value near 50MHz */
2142         clock = get_pll_clk(MPLL) / 1000000;
2143         for (i = 0; i < 0xf; i++) {
2144                 if ((clock / (i + 1)) <= 50) {
2145                         reg |= i << 0;
2146                         break;
2147                 }
2148         }
2149
2150         writel(reg, &clk->div4);
2151
2152         /*
2153          * MMC0 GPIO
2154          * GPG0[0]      SD_0_CLK
2155          * GPG0[1]      SD_0_CMD
2156          * GPG0[2]      SD_0_CDn        -> Not used
2157          * GPG0[3:6]    SD_0_DATA[0:3]
2158          */
2159         for (i = 0; i < 7; i++) {
2160                 if (i == 2)
2161                         continue;
2162                 /* GPG0[0:6] special function 2 */
2163                 gpio_cfg_pin(&s5pc110_gpio->gpio_g0, i, 0x2);
2164                 /* GPG0[0:6] pull disable */
2165                 gpio_set_pull(&s5pc110_gpio->gpio_g0, i, GPIO_PULL_NONE);
2166                 /* GPG0[0:6] drv 4x */
2167                 gpio_set_drv(&s5pc110_gpio->gpio_g0, i, GPIO_DRV_4x);
2168         }
2169
2170         return s5pc1xx_mmc_init(0);
2171 }
2172 #endif
2173
2174 #ifdef CONFIG_CMD_PMIC
2175 static int pmic_status(void)
2176 {
2177         unsigned char addr, val[2];
2178         int reg, i;
2179
2180         i2c_set_bus_num(I2C_PMIC);
2181         addr = 0xCC >> 1;
2182         if (i2c_probe(addr)) {
2183                 printf("Can't found max8998\n");
2184                 return -1;
2185         }
2186
2187         reg = 0x11;
2188         i2c_read(addr, reg, 1, val, 1);
2189         for (i = 7; i >= 4; i--)
2190                 printf("BUCK%d %s\n", 7 - i + 1,
2191                         val[0] & (1 << i) ? "on" : "off");
2192         for (; i >= 0; i--)
2193                 printf("LDO%d %s\n", 5 - i,
2194                         val[0] & (1 << i) ? "on" : "off");
2195         reg = 0x12;
2196         i2c_read(addr, reg, 1, val, 1);
2197         for (i = 7; i >= 0; i--)
2198                 printf("LDO%d %s\n", 7 - i + 6,
2199                         val[0] & (1 << i) ? "on" : "off");
2200         reg = 0x13;
2201         i2c_read(addr, reg, 1, val, 1);
2202         for (i = 7; i >= 4; i--)
2203                 printf("LDO%d %s\n", 7 - i + 14,
2204                         val[0] & (1 << i) ? "on" : "off");
2205
2206         reg = 0xd;
2207         i2c_read(addr, reg, 1, val, 1);
2208         for (i = 7; i >= 6; i--)
2209                 printf("SAFEOUT%d %s\n", 7 - i + 1,
2210                         val[0] & (1 << i) ? "on" : "off");
2211         return 0;
2212 }
2213
2214 static int pmic_ldo_control(int buck, int ldo, int safeout, int on)
2215 {
2216         unsigned char addr, val[2];
2217         unsigned int reg, shift;
2218
2219         if (ldo) {
2220                 if (ldo < 2)
2221                         return -1;
2222                 if (ldo <= 5) {
2223                         reg = 0x11;
2224                         shift = 5 - ldo;
2225                 } else if (ldo <= 13) {
2226                         reg = 0x12;
2227                         shift = 13 - ldo;
2228                 } else if (ldo <= 17) {
2229                         reg = 0x13;
2230                         shift = 17 - ldo + 4;
2231                 } else
2232                         return -1;
2233         } else if (buck) {
2234                 if (buck > 4)
2235                         return -1;
2236                 reg = 0x11;
2237                 shift = 4 - buck + 4;
2238         } else if (safeout) {
2239                 if (safeout > 3)
2240                         return -1;
2241                 reg = 0xd;
2242                 shift = 8 - safeout;
2243         } else
2244                 return -1;
2245
2246         i2c_set_bus_num(I2C_PMIC);
2247         addr = 0xCC >> 1;
2248         if (i2c_probe(addr)) {
2249                 printf("Can't found max8998\n");
2250                 return -1;
2251         }
2252
2253         i2c_read(addr, reg, 1, val, 1);
2254         if (on)
2255                 val[0] |= (1 << shift);
2256         else
2257                 val[0] &= ~(1 << shift);
2258         i2c_write(addr, reg, 1, val, 1);
2259         i2c_read(addr, reg, 1, val, 1);
2260
2261         if (ldo)
2262                 printf("ldo %d value 0x%x, %s\n", ldo, val[0],
2263                         val[0] & (1 << shift) ? "on" : "off");
2264         else if (buck)
2265                 printf("buck %d value 0x%x, %s\n", buck, val[0],
2266                         val[0] & (1 << shift) ? "on" : "off");
2267         else if (safeout)
2268                 printf("safeout %d value 0x%x, %s\n", safeout, val[0],
2269                         val[0] & (1 << shift) ? "on" : "off");
2270
2271         return 0;
2272 }
2273
2274 static int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2275 {
2276         int buck = 0, ldo = 0, safeout = 0, on = -1;
2277
2278         switch (argc) {
2279         case 2:
2280                 if (strncmp(argv[1], "status", 6) == 0)
2281                         return pmic_status();
2282                 break;
2283         case 4:
2284                 if (strncmp(argv[1], "ldo", 3) == 0)
2285                         ldo = simple_strtoul(argv[2], NULL, 10);
2286                 else if (strncmp(argv[1], "buck", 4) == 0)
2287                         buck = simple_strtoul(argv[2], NULL, 10);
2288                 else if (strncmp(argv[1], "safeout", 7) == 0)
2289                         safeout = simple_strtoul(argv[2], NULL, 10);
2290                 else
2291                         break;
2292
2293                 if (strncmp(argv[3], "on", 2) == 0)
2294                         on = 1;
2295                 else if (strncmp(argv[3], "off", 3) == 0)
2296                         on = 0;
2297                 else
2298                         break;
2299
2300                 return pmic_ldo_control(buck, ldo, safeout, on);
2301
2302         default:
2303                 break;
2304         }
2305
2306         cmd_usage(cmdtp);
2307         return 1;
2308 }
2309
2310 U_BOOT_CMD(
2311         pmic,           CONFIG_SYS_MAXARGS,     1, do_pmic,
2312         "PMIC LDO & BUCK control",
2313         "status - Display PMIC LDO & BUCK status\n"
2314         "pmic ldo num on/off - Turn on/off the LDO\n"
2315         "pmic buck num on/off - Turn on/off the BUCK\n"
2316         "pmic safeout num on/off - Turn on/off the SAFEOUT\n"
2317 );
2318 #endif
2319
2320 #ifdef CONFIG_CMD_DEVICE_POWER
2321
2322 enum {
2323         POWER_NONE,
2324         POWER_TOUCH,
2325         POWER_3_TOUCHKEY,
2326         POWER_LCD,
2327         POWER_HAPTIC,
2328         POWER_AUDIO_CODEC,
2329         POWER_FM_RADIO,
2330         POWER_BT_WIFI,
2331         POWER_HDMI,
2332 };
2333
2334 static void power_display_devices(void)
2335 {
2336         printf("devices:\n");
2337         printf("\t%d - touch\n", POWER_TOUCH);
2338         printf("\t%d - 3 touchkey\n", POWER_3_TOUCHKEY);
2339         printf("\t%d - LCD\n", POWER_LCD);
2340         printf("\t%d - Haptic\n", POWER_HAPTIC);
2341         printf("\t%d - Audio Codec\n", POWER_AUDIO_CODEC);
2342         printf("\t%d - FM Radio\n", POWER_FM_RADIO);
2343         printf("\t%d - BT/WiFi\n", POWER_BT_WIFI);
2344         printf("\t%d - HDMI\n", POWER_HDMI);
2345 }
2346
2347 static int power_hdmi(int on)
2348 {
2349         /* HDMI_EN1: GPJ2[2] */
2350         gpio_direction_output(&s5pc110_gpio->gpio_j2, 2, on);
2351         /* MHL_ON: GPJ2[3] */
2352         gpio_direction_output(&s5pc110_gpio->gpio_j2, 3, on);
2353         return 0;
2354 }
2355
2356 static int power_bt_wifi(int on)
2357 {
2358         /* WLAN_BT_EN: GPB[5] */
2359         gpio_direction_output(&s5pc110_gpio->gpio_b, 5, on);
2360         return 0;
2361 }
2362
2363 static int power_fm_radio(int on)
2364 {
2365         /* FM_BUS_nRST: GPJ2[5] */
2366         gpio_direction_output(&s5pc110_gpio->gpio_j2, 5, !on);
2367         return 0;
2368 }
2369
2370 static int power_audio_codec(int on)
2371 {
2372         /* CODEC_LDO_EN: GPF3[4] */
2373         gpio_direction_output(&s5pc110_gpio->gpio_f3, 4, on);
2374         /* CODEC_XTAL_EN: GPH3[2] */
2375         gpio_direction_output(&s5pc110_gpio->gpio_h3, 2, on);
2376         return 0;
2377 }
2378
2379 static int power_haptic(int on)
2380 {
2381         /* HAPTIC_ON: GPJ1[1] */
2382         gpio_direction_output(&s5pc110_gpio->gpio_j1, 1, on);
2383         return 0;
2384 }
2385
2386 static int power_lcd(int on)
2387 {
2388         /* MLCD_ON: GPJ1[3] */
2389         gpio_direction_output(&s5pc110_gpio->gpio_j1, 3, on);
2390         return 0;
2391 }
2392
2393 static int power_touch(int on)
2394 {
2395         /* TOUCH_EN: GPG3[6] */
2396         gpio_direction_output(&s5pc110_gpio->gpio_g3, 6, on);
2397         return 0;
2398 }
2399
2400 static int power_3_touchkey(int on)
2401 {
2402         if (on) {
2403                 /* 3_TOUCH_EN - GPJ3[0] : (J1B2) */
2404                 /* 3_TOUCH_EN - GPJ3[5] : (not J1B2) */
2405                 if (board_rev & J1_B2_BOARD)
2406                         gpio_direction_output(&s5pc110_gpio->gpio_j3, 0, on);
2407                 else
2408                         gpio_direction_output(&s5pc110_gpio->gpio_j3, 5, on);
2409
2410                 /* 3_TOUCH_CE - GPJ2[6] */
2411                 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on);   /* TOUCH_CE */
2412         } else {
2413                 /* 3_TOUCH_CE - GPJ2[6] */
2414                 gpio_direction_output(&s5pc110_gpio->gpio_j2, 6, on);   /* TOUCH_CE */
2415         }
2416
2417         if (on) {
2418                 unsigned int reg;
2419                 unsigned char val[2];
2420                 unsigned char addr = 0x20;              /* mcs5000 3-touchkey */
2421
2422                 /* Require 100ms */
2423                 udelay(80 * 1000);
2424
2425                 /* 3 touchkey */
2426                 i2c_set_bus_num(I2C_GPIO10);
2427
2428                 /* Workaround to probe */
2429                 if (i2c_probe(addr)) {
2430                         if (i2c_probe(addr)) {
2431                                 printf("Can't found 3 touchkey\n");
2432                                 return -ENODEV;
2433                         }
2434                 }
2435
2436 #define MCS5000_TK_HW_VERSION  0x06
2437 #define MCS5000_TK_FW_VERSION  0x0A
2438 #define MCS5000_TK_MI_VERSION  0x0B
2439
2440                 reg = MCS5000_TK_MI_VERSION;
2441                 i2c_read(addr, reg, 1, val, 1);
2442                 printf("3-touchkey:\tM/I 0x%x, ", val[0]);
2443                 reg = MCS5000_TK_HW_VERSION;
2444                 i2c_read(addr, reg, 1, val, 1);
2445                 printf("H/W 0x%x, ", val[0]);
2446                 reg = MCS5000_TK_FW_VERSION;
2447                 i2c_read(addr, reg, 1, val, 1);
2448                 printf("F/W 0x%x\n", val[0]);
2449         }
2450         return 0;
2451 }
2452
2453 static int power_control(int device, int on)
2454 {
2455         switch (device) {
2456         case POWER_TOUCH:
2457                 return power_touch(on);
2458         case POWER_3_TOUCHKEY:
2459                 return power_3_touchkey(on);
2460         case POWER_LCD:
2461                 return power_lcd(on);
2462         case POWER_HAPTIC:
2463                 return power_haptic(on);
2464         case POWER_AUDIO_CODEC:
2465                 return power_audio_codec(on);
2466         case POWER_FM_RADIO:
2467                 return power_fm_radio(on);
2468         case POWER_BT_WIFI:
2469                 return power_bt_wifi(on);
2470         case POWER_HDMI:
2471                 return power_hdmi(on);
2472         default:
2473                 printf("I don't know device %d\n", device);
2474                 break;
2475         }
2476         return 0;
2477 }
2478
2479 static int power_on(int on)
2480 {
2481         power_touch(on);
2482         power_3_touchkey(on);
2483         power_lcd(on);
2484         power_haptic(on);
2485         power_audio_codec(on);
2486         power_fm_radio(on);
2487         power_bt_wifi(on);
2488         power_hdmi(on);
2489
2490         return 0;
2491 }
2492
2493 static int do_power(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2494 {
2495         int device, on;
2496
2497         if (!machine_is_aquila())
2498                 goto out;
2499
2500         switch (argc) {
2501         case 2:
2502                 if (strncmp(argv[1], "on", 2) == 0)
2503                         return power_on(1);
2504                 if (strncmp(argv[1], "off", 3) == 0)
2505                         return power_on(0);
2506                 break;
2507         case 3:
2508                 device = simple_strtoul(argv[1], NULL, 10);
2509                 if (device < 0)
2510                         break;
2511
2512                 if (strncmp(argv[2], "on", 2) == 0)
2513                         on = 1;
2514                 else if (strncmp(argv[2], "off", 3) == 0)
2515                         on = 0;
2516                 else
2517                         break;
2518                 return power_control(device, on);
2519         default:
2520                 break;
2521         }
2522 out:
2523         cmd_usage(cmdtp);
2524         power_display_devices();
2525         return 1;
2526 }
2527
2528 U_BOOT_CMD(
2529         power,          CONFIG_SYS_MAXARGS,     1, do_power,
2530         "Device Power Management control",
2531         "device on/off - Turn on/off the device\n"
2532 );
2533
2534 static int do_microusb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
2535 {
2536         switch (argc) {
2537         case 2:
2538                 if (strncmp(argv[1], "cp", 2) == 0) {
2539                         micro_usb_switch(1);
2540                         pmic_ldo_control(0, 0, 2, 1);
2541                         setenv("usb", "cp");
2542                 } else if (strncmp(argv[1], "ap", 2) == 0) {
2543                         micro_usb_switch(0);
2544                         pmic_ldo_control(0, 0, 2, 0);
2545                         setenv("usb", "ap");
2546                 }
2547                 break;
2548         default:
2549                 cmd_usage(cmdtp);
2550                 return 1;
2551         }
2552
2553         saveenv();
2554
2555         printf("USB Path is set to %s\n", getenv("usb"));
2556
2557         return 0;
2558 }
2559
2560 U_BOOT_CMD(
2561         microusb,               CONFIG_SYS_MAXARGS,     1, do_microusb,
2562         "Micro USB Switch",
2563         "cp - switch to CP\n"
2564         "microusb ap - switch to AP\n"
2565 );
2566 #endif