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