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