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