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