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