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