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