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