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