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