upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-s5pv310 / mach-u1hd_c210.c
1 /*
2  * linux/arch/arm/mach-s5pv310/mach-c1_c210.c
3  *
4  * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/platform_device.h>
12 #include <linux/serial_core.h>
13 #include <linux/input.h>
14 #include <linux/gpio.h>
15 #include <linux/gpio_keys.h>
16 #include <linux/delay.h>
17 #include <linux/cma.h>
18 #include <linux/lcd.h>
19 #include <linux/spi/spi.h>
20 #include <linux/spi/spi_gpio.h>
21 #include <linux/i2c.h>
22 #include <linux/i2c-gpio.h>
23 #include <linux/i2c/cypress_touchkey.h>
24 #include <linux/i2c/atmel_mxt_ts.h>
25 #include <linux/clk.h>
26 #include <linux/ntc.h>
27 #include <linux/regulator/machine.h>
28 #include <linux/regulator/fixed.h>
29 #include <linux/power_supply.h>
30 #include <linux/mfd/max8997.h>
31 #include <linux/mfd/max8997-private.h>
32 #include <linux/mfd/mc1n2_pdata.h>
33 #include <linux/power/max17042_battery.h>
34 #include <linux/ramoops.h>
35 #include <linux/mmcoops.h>
36 #include <linux/uart_select.h>
37 #include <linux/memblock.h>
38 #include <linux/rtc/rtc-s3c.h>
39 #include <linux/swi.h>
40 #include <linux/jack.h>
41 #include <linux/k3g.h>
42 #include <linux/kr3dh.h>
43 #include <linux/pn544.h>
44 #include <linux/tmd27711.h>
45 #include <linux/ak8975.h>
46 #include <linux/micro_usb_switch.h>
47 #include <linux/switch.h>
48 #include <linux/cm3623.h>
49 #include <linux/host_notify.h>
50 #include <linux/utsname.h>
51
52 #include <linux/cpufreq.h>
53 #include <linux/modem/xmm6260.h>
54 #include <linux/power/charger-manager.h>
55 #include <linux/leds-max8997.h>
56 #include <linux/irq.h>
57 #include <video/platform_lcd.h>
58
59 #include <asm/mach-types.h>
60 #include <asm/mach/arch.h>
61 #include <asm/setup.h>
62 #include <asm/cacheflush.h>
63
64 #include <mach/map.h>
65 #include <mach/gpio.h>
66 #include <mach/regs-clock.h>
67 #include <mach/regs-pmu.h>
68 #include <mach/pm-core.h>
69 #include <mach/nt39411.h>
70 #include <mach/universal.h>
71
72 #include <plat/cpu.h>
73 #include <plat/clock.h>
74 #include <plat/devs.h>
75 #include <plat/gpio-cfg.h>
76 #include <plat/gpio-core.h>
77 #include <plat/fb.h>
78 #include <plat/fimg2d.h>
79 #include <plat/mali.h>
80 #include <plat/iic.h>
81 #include <plat/pm.h>
82 #include <plat/regs-otg.h>
83 #include <plat/regs-serial.h>
84 #include <plat/s5pv310.h>
85 #include <plat/adc.h>
86 #include <plat/fimd_drm.h>
87 #include <plat/tvout.h>
88 #include <plat/pd.h>
89 #include <plat/s5p_fimd_lite.h>
90 #include <plat/usb_ehci.h>
91 #include <plat/sysmmu.h>
92 #include <plat/s5p-otghost.h>
93 #include <plat/udc-hs.h>
94 #include <plat/mipi_dsim.h>
95
96 #include "gpio-mobile.h"
97 #include "gpio-u1hd.h"
98 #include "board-mobile.h"
99 #include "../../../drivers/usb/gadget/s3c_udc.h"
100
101 #ifdef CONFIG_TOUCHSCREEN_MELFAS
102 #include <linux/melfas_ts.h>
103 #endif
104
105 #ifdef CONFIG_INPUT_SECBRIDGE
106 #include <linux/input/sec-input-bridge.h>
107 #endif
108
109 #ifdef CONFIG_CHARGERCTRL_MAX8922
110 #include <linux/max8922-charger.h>
111 #endif
112
113 #if defined(CONFIG_DEV_THERMAL)
114 #include <plat/s5p-tmu.h>
115 #include <mach/regs-tmu.h>
116 #endif
117
118 #ifdef CONFIG_INPUT_GP2A
119 #include <linux/input/gp2a.h>
120 #endif
121
122 /* Following are default values for UCON, ULCON and UFCON UART registers */
123 #define UNIVERSAL_UCON_DEFAULT  (S3C2410_UCON_TXILEVEL |        \
124                                  S3C2410_UCON_RXILEVEL |        \
125                                  S3C2410_UCON_TXIRQMODE |       \
126                                  S3C2410_UCON_RXIRQMODE |       \
127                                  S3C2410_UCON_RXFIFO_TOI |      \
128                                  S3C2443_UCON_RXERR_IRQEN)
129
130 #define UNIVERSAL_ULCON_DEFAULT S3C2410_LCON_CS8
131
132 #define UNIVERSAL_UFCON_DEFAULT (S3C2410_UFCON_FIFOMODE |       \
133                                  S5PV210_UFCON_TXTRIG0 |        \
134                                  S5PV210_UFCON_RXTRIG128)
135
136 #define UNIVERSAL_UFCON_UART2   (S3C2410_UFCON_FIFOMODE |       \
137                                  S5PV210_UFCON_TXTRIG0 |        \
138                                  S5PV210_UFCON_RXTRIG4)
139
140 extern void u1hd_config_sleep_gpio_table(void);
141
142 enum fixed_regulator_id {
143         FIXED_REG_ID_MMC = 0,
144         FIXED_REG_ID_CAM0,
145         FIXED_REG_ID_CAM1,
146         FIXED_REG_ID_CAM2,
147         FIXED_REG_ID_CAM3,
148         FIXED_REG_ID_LED_A,
149         FIXED_REG_ID_RADIO,
150         DUMMY_REG_ID_FLASH,
151         DUMMY_REG_ID_MOVIE,
152 };
153
154
155 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_PROFILING
156 /*
157  * This string add for profiling of each segments
158  *
159  * 0 =
160  * 1 =
161  * 2 =
162  * 3 =
163  *
164  */
165 static unsigned int u1hd_profile_level = 0;
166
167 static int __init u1hd_profile_level_setup(char *str)
168 {
169         char *endp;
170         if (!str)
171                 return -EINVAL;
172
173         u1hd_profile_level = memparse(str, &endp);
174         if (u1hd_profile_level > 3)
175                 u1hd_profile_level = 0;
176
177         return endp > str ? 0 : -EINVAL;
178 }
179
180 early_param("profile_level=", u1hd_profile_level_setup);
181 #endif
182
183
184 static struct s3c2410_uartcfg u1hd_uartcfgs[] __initdata = {
185         {
186                 .hwport         = 0,
187                 .ucon           = UNIVERSAL_UCON_DEFAULT,
188                 .ulcon          = UNIVERSAL_ULCON_DEFAULT,
189                 .ufcon          = UNIVERSAL_UFCON_DEFAULT,
190         },
191         {
192                 .hwport         = 1,
193                 .ucon           = UNIVERSAL_UCON_DEFAULT,
194                 .ulcon          = UNIVERSAL_ULCON_DEFAULT,
195                 .ufcon          = UNIVERSAL_UFCON_DEFAULT,
196         },
197         {
198                 .hwport         = 2,
199                 .ucon           = UNIVERSAL_UCON_DEFAULT,
200                 .ulcon          = UNIVERSAL_ULCON_DEFAULT,
201                 .ufcon          = UNIVERSAL_UFCON_UART2,
202         },
203         {
204                 .hwport         = 3,
205                 .ucon           = UNIVERSAL_UCON_DEFAULT,
206                 .ulcon          = UNIVERSAL_ULCON_DEFAULT,
207                 .ufcon          = UNIVERSAL_UFCON_DEFAULT,
208         },
209 };
210
211 static struct s3c2410_platform_i2c u1hd_i2c0_platdata __initdata = {
212         .frequency      = 300 * 1000,
213         .sda_delay      = 200,
214 };
215
216 static struct k3g_platform_data u1hd_k3g_data = {
217         .irq2                   = IRQ_EINT(1),
218         .powerdown              = K3G_POWERDOWN_NORMAL,
219         .zen                    = K3G_Z_EN,
220         .yen                    = K3G_Y_EN,
221         .xen                    = K3G_X_EN,
222         .block_data_update      = K3G_BLOCK_DATA_UPDATE,
223         .fullscale              = K3G_FULL_SCALE_500DPS,
224         .fifo_mode              = K3G_FIFO_FIFO_MODE,
225         .int2_src               = K3G_INT2_OVERRUN,
226         .fifo_threshold         = 16,
227         .int1_z_high_enable     = K3G_Z_HIGH_INT_EN,
228         .int1_y_high_enable     = K3G_Y_HIGH_INT_EN,
229         .int1_x_high_enable     = K3G_X_HIGH_INT_EN,
230         .int1_latch             = K3G_INTERRUPT_LATCHED,
231         .int1_z_threshold       = 0x12,
232         .int1_y_threshold       = 0x25,
233         .int1_x_threshold       = 0x25,
234         .int1_wait_enable       = K3G_INT1_WAIT_EN,
235         .int1_wait_duration     = 0x10,
236 };
237
238 static struct kr3dh_platform_data u1hd_kr3dh_data = {
239         .power_mode             = KR3DH_LOW_POWER_ONE_HALF_HZ,
240         .data_rate              = KR3DH_ODR_50HZ,
241         .zen                    = 1,
242         .yen                    = 1,
243         .xen                    = 1,
244         .int1_latch             = 1,
245         .int1_cfg               = KR3DH_INT_SOURCE,
246         .block_data_update      = 1,
247         .fullscale              = KR3DH_RANGE_2G,
248         .int1_combination       = KR3DH_OR_COMBINATION,
249         .int1_6d_enable         = 1,
250         .int1_z_high_enable     = 1,
251         .int1_z_low_enable      = 1,
252         .int1_y_high_enable     = 1,
253         .int1_y_low_enable      = 1,
254         .int1_x_high_enable     = 1,
255         .int1_x_low_enable      = 1,
256         .int1_threshold         = 0x25,
257         .int1_duration          = 0x01,
258         .negate_x               = 0,
259         .negate_y               = 0,
260         .negate_z               = 1,
261         .change_xy              = 1,
262 };
263
264 static void user_input_response_work(struct work_struct *work)
265 {
266 #ifdef CONFIG_CPU_FREQ_GOV_ONDEMAND_FLEXRATE
267         /* Run CPUFREQ with 10000us 10 times. */
268         cpufreq_ondemand_flexrate_request(10000, 10);
269 #endif /* CONFIG_CPU_FREQ_GOV_ONDEMAND_FLEXRATE */
270 }
271
272 static DECLARE_WORK(uir_work, user_input_response_work);
273
274 static __maybe_unused void user_input_response(void *data)
275 {
276         if (!work_pending(&uir_work))
277                 schedule_work_on(0, &uir_work);
278 }
279
280 /* I2C1 */
281 static struct i2c_board_info i2c1_devs[] __initdata = {
282         {
283                 /* Gyro sensor */
284                 I2C_BOARD_INFO("K3G_1", 0x69),
285                 .platform_data  = &u1hd_k3g_data,
286                 .irq            = IRQ_EINT(0),
287         }, {
288                 /* Accelerometer */
289                 I2C_BOARD_INFO("KR3DH", 0x19),
290                 .platform_data  = &u1hd_kr3dh_data,
291                 .irq            = IRQ_EINT(24),
292         }
293 };
294
295 /* TODO: should be modify for U1 */
296 extern struct max8997_platform_data u1hd_max8997_pdata;
297 extern void __init u1hd_pmic_init(void);
298
299 static void haptic_control_power(struct device *dev, int on)
300 {
301         static struct regulator *regulator;
302         static DEFINE_MUTEX(lock);
303         static bool enabled;
304         int ret;
305
306         mutex_lock(&lock);
307
308         if (enabled == !!on)
309                 goto out;
310
311         if (regulator == NULL)
312                 regulator = regulator_get(dev, "inmotor");
313         if (IS_ERR_OR_NULL(regulator)) {
314                 regulator = NULL;
315                 goto out;
316         }
317
318         if (on)
319                 ret = regulator_enable(regulator);
320         else
321                 ret = regulator_disable(regulator);
322
323         if (!ret)
324                 enabled = !!on;
325 out:
326         mutex_unlock(&lock);
327 }
328
329 struct max8997_haptic_platform_data u1hd_haptic_pdata = {
330         .name           = "vibtone",
331         .pwm_timer      = 1,
332         .control_power  = haptic_control_power,
333 };
334
335 /* GPIO I2C 5 (PMIC) */
336 enum { I2C5_MAX8997 };
337 static struct i2c_board_info i2c5_devs[] __initdata = {
338         [I2C5_MAX8997] = {
339                 I2C_BOARD_INFO("max8997", 0xCC >> 1),
340                 .platform_data  = &u1hd_max8997_pdata,
341         },
342 };
343
344 void sec_set_sub_mic_bias(bool on)
345 {
346         int gpio;
347         gpio = MOBILE_GPIO(SUB_MICBIAS_EN);
348         gpio_set_value(gpio, on);
349         pr_err(KERN_ERR "SUB_MIC_BIAS_EN GPIO set [%d] !\n", on);
350 }
351
352 void sec_set_main_mic_bias(bool on)
353 {
354         int gpio;
355         gpio = MOBILE_GPIO(MICBIAS_EN);
356         gpio_set_value(gpio, on);
357         pr_err(KERN_ERR "MAIN_MIC_BIAS_EN GPIO set [%d] !\n", on);
358 }
359
360 static struct mc1n2_platform_data mc1n2_pdata = {
361         .set_main_mic_bias = sec_set_main_mic_bias,
362         .set_sub_mic_bias = sec_set_sub_mic_bias,
363 };
364
365 /* GPIO I2C 6 */
366 static struct i2c_board_info i2c6_devs[] __initdata = {
367         {
368                 /* Audio Codec */
369                 I2C_BOARD_INFO("mc1n2", 0x3a),
370                 .platform_data = &mc1n2_pdata,
371         },
372 };
373
374 static void __init u1hd_sound_init(void)
375 {
376         int val;
377         int err;
378         int gpio;
379
380         /* Set PMU register to set CLK_OUT to use XUSBXTI
381          * as codec source clock */
382         val = 0x900;
383         __raw_writel(val, S5P_PMREG(0xA00));
384
385         gpio = MOBILE_GPIO(MICBIAS_EN);
386         err = gpio_request(gpio, "MICBIAS_EN");
387         if (err) {
388                 pr_err(KERN_ERR "MIC_BIAS_EN GPIO set error!\n");
389                 return;
390         }
391         gpio_direction_output(gpio, 1);
392         gpio_set_value(gpio, 0);
393
394         gpio = MOBILE_GPIO(EAR_MICBIAS_EN);
395         err = gpio_request(gpio, "EAR_MICBIAS_EN");
396         if (err) {
397                 pr_err(KERN_ERR "EAR_MIC_BIAS_EN GPIO set error!\n");
398                 return;
399         }
400         gpio_direction_output(gpio, 1);
401         gpio_set_value(gpio, 0);
402
403         gpio = MOBILE_GPIO(SUB_MICBIAS_EN);
404         err = gpio_request(gpio, "submic_bias");
405         if (err) {
406                 pr_err(KERN_ERR "SUB_MIC_BIAS_EN GPIO set error!\n");
407                 return;
408         }
409         gpio_direction_output(gpio, 0);
410 }
411
412 static struct ak8975_platform_data universal_ak8975_data = {
413         .poll_interval = 100,
414 };
415
416 /* I2C7 */
417 static struct i2c_board_info i2c7_devs[] __initdata = {
418         {
419                 /* Compass */
420                 I2C_BOARD_INFO("ak8975", 0x0c),
421                 .platform_data  = &universal_ak8975_data,
422         }, {
423                 I2C_BOARD_INFO("s5p_ddc", 0x72 >> 1),
424         },
425 };
426
427 /* I2C8: HDMI */
428 static struct s3c2410_platform_i2c i2c_data8 __initdata = {
429         .bus_num        = 8,
430         .flags          = 0,
431         .slave_addr     = 0x10,
432         .frequency      = 100*1000,
433         .sda_delay      = 100,
434 };
435
436 /* I2C9 */
437 static struct i2c_gpio_platform_data i2c9_gpio_data = {
438         .sda_pin                = S5PV310_GPY4(0),      /* XM0ADDR_8 */
439         .scl_pin                = S5PV310_GPY4(1),      /* XM0ADDR_9 */
440 };
441
442 static struct platform_device i2c9_gpio = {
443         .name                   = "i2c-gpio",
444         .id                     = 9,
445         .dev                    = {
446                 .platform_data  = &i2c9_gpio_data,
447         },
448 };
449
450 static struct max17042_reg_data max17042_init_data[] = {
451         { MAX17042_CGAIN,               0x0000 },
452         { MAX17042_MiscCFG,             0x0003 },
453         { MAX17042_LearnCFG,            0x0007 },
454         /* RCOMP: 0x0050 2011.02.29 from MAXIM */
455         { MAX17042_RCOMP0,              0x0050 },
456 };
457 /* Alert only when the battery is removed or inserted */
458 static struct max17042_reg_data max17042_alert_init_data[] = {
459         /* SALRT Threshold setting (disable) unsigned MAX/MIN */
460         { MAX17042_SALRT_Th,    0xFF00 },
461         /* VALRT Threshold setting (disable) unsigned MAX/MIN */
462         { MAX17042_VALRT_Th,    0xFF00 },
463         /* TALRT Threshold setting (disable) signed MAX/MIN */
464         { MAX17042_TALRT_Th,    0x7F80 },
465 };
466 static struct max17042_platform_data u1hd_battery_platform_data = {
467         .init_data = max17042_init_data,
468         .num_init_data = ARRAY_SIZE(max17042_init_data),
469         .alrt_data = max17042_alert_init_data,
470         .num_alrt_data = ARRAY_SIZE(max17042_alert_init_data),
471         .irq_base = IRQ_FUEL_BASE,
472         .enable_alert = true,
473         .wakeup = true,
474         .r_sns = 10000, /* 10m Ohm */
475 };
476
477 enum { I2C9_MAX17042};
478 static struct i2c_board_info i2c9_devs[] __initdata = {
479         [I2C9_MAX17042] = {
480                 I2C_BOARD_INFO("max17042", 0x36),
481                 .platform_data = &u1hd_battery_platform_data,
482         },
483 };
484
485
486 /* GPIO I2C 12 (3 Touchkey) */
487 #define TOUCHKEY_INT    S5PV310_GPL0(5)
488 #define TOUCHKEY_SCL    S5PV310_GPK1(0)
489 #define TOUCHKEY_SDA    S5PV310_GPK1(2)
490
491 static struct i2c_gpio_platform_data i2c12_gpio_data = {
492         .sda_pin                = S5PV310_GPK1(2),      /* XMDMDATA_8 */
493         .scl_pin                = S5PV310_GPK1(0),      /* XMDMDATA_9 */
494 };
495
496 static struct platform_device i2c12_gpio = {
497         .name                   = "i2c-gpio",
498         .id                     = 12,
499         .dev                    = {
500                 .platform_data  = &i2c12_gpio_data,
501         },
502 };
503
504 /*===============================*/
505 /*=     CYPRESS TOUCH KEY       =*/
506 /*===============================*/
507 static struct cypress_pin cypress_tk_pin = {
508         .gpio_en        = -1,
509         .gpio_int       = TOUCHKEY_INT,
510         .gpio_sda       = TOUCHKEY_SDA,
511         .gpio_scl       = TOUCHKEY_SCL,
512 };
513
514 static void cypress_tk_cfg_pin(void)
515 {
516         s3c_gpio_setpull(cypress_tk_pin.gpio_sda, S3C_GPIO_PULL_NONE);
517         s3c_gpio_setpull(cypress_tk_pin.gpio_scl, S3C_GPIO_PULL_NONE);
518
519         s3c_gpio_cfgpin(cypress_tk_pin.gpio_sda, S3C_GPIO_SFN(2));
520         s3c_gpio_cfgpin(cypress_tk_pin.gpio_scl, S3C_GPIO_SFN(2));
521
522         s3c_gpio_cfgpin(cypress_tk_pin.gpio_int, S3C_GPIO_SFN(0xf));
523         if (gpio_is_valid(cypress_tk_pin.gpio_en))
524                 s3c_gpio_cfgpin(cypress_tk_pin.gpio_en, S3C_GPIO_OUTPUT);
525 };
526
527 static int cypress_touchkey_power(int onoff)
528 {
529         static struct regulator *regulator;
530         static DEFINE_MUTEX(lock);
531         static bool enabled;
532         int ret = 0;
533
534         mutex_lock(&lock);
535
536         if (enabled == !!onoff)
537                 goto out;
538
539         if (regulator == NULL)
540                 regulator = regulator_get(NULL, "touch_2.8v");
541         if (IS_ERR_OR_NULL(regulator)) {
542                 regulator = NULL;
543                 pr_err("[TK][ERROR] regulator_get fail\n");
544                 ret = -EINVAL;
545                 goto out;
546         }
547
548         if (onoff)
549                 ret = regulator_enable(regulator);
550         else
551                 ret = regulator_disable(regulator);
552
553         if (!ret)
554                 enabled = !!onoff;
555
556         msleep(100);
557 out:
558         mutex_unlock(&lock);
559         return ret;
560 }
561
562 static int cypress_touchled_power(int onoff)
563 {
564         static struct regulator *regulator;
565         static DEFINE_MUTEX(lock);
566         static bool enabled;
567         int ret = 0;
568
569         mutex_lock(&lock);
570
571         if (enabled == !!onoff)
572                 goto out;
573
574         if (regulator == NULL)
575                 regulator = regulator_get(NULL, "touch_led_3.3v");
576         if (IS_ERR_OR_NULL(regulator)) {
577                 regulator = NULL;
578                 pr_err("[TK][ERROR] regulator_get fail\n");
579                 ret = -EINVAL;
580                 goto out;
581         }
582
583         if (onoff)
584                 ret = regulator_enable(regulator);
585         else
586                 ret = regulator_disable(regulator);
587
588         if (!ret)
589                 enabled = !!onoff;
590
591         msleep(100);
592 out:
593         mutex_unlock(&lock);
594         return ret;
595 }
596
597 static unsigned int u1hd_cypress_touch_keycode[] = {
598         KEY_PHONE,      /* not use this value 0x00 */
599         KEY_PHONE,      /* KEY_SEND 0x01 */
600         KEY_BACK,       /* KEY_END 0x02 */
601 };
602
603 static unsigned char u1hd_cypress_keycode_setbit[] = {
604         0,
605         1,
606         1,
607 };
608
609 static struct cypress_platform_data cypress_tk_data = {
610         .cfg_pin                = cypress_tk_cfg_pin,
611         .power_pin              = cypress_touchkey_power,
612         .led_pin                = cypress_touchled_power,
613         .pin                    = &cypress_tk_pin,
614         .keycode                = u1hd_cypress_touch_keycode,
615         .keycode_size   = ARRAY_SIZE(u1hd_cypress_touch_keycode),
616         .keycode_setbit = u1hd_cypress_keycode_setbit,
617         .gpio_control   = 0,
618 };
619
620 static struct i2c_board_info i2c12_devs_cypress[] __initdata = {
621         {
622                 I2C_BOARD_INFO("cypress_tk", 0x20),
623                 .platform_data  = &cypress_tk_data,
624         },
625 };
626
627 static void __init universal_touchkey_init(void)
628 {
629         int gpio;
630         int irq;
631
632         gpio = TOUCHKEY_INT;                    /* XMDMDATA_7 */
633         gpio_request(gpio, "3_TOUCH_INT");
634         s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
635         irq = gpio_to_irq(gpio);
636         i2c12_devs_cypress[0].irq = irq;
637 }
638
639 static struct regulator_consumer_supply supplies_ps_on_led_a[] = {
640         REGULATOR_SUPPLY("led_a_2.8v", NULL),
641 };
642 static struct regulator_init_data ps_on_led_a_data = {
643         .constraints = {
644                 .name           = "LED_A_2.8V",
645                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
646                 .boot_on        = 0,
647                 .state_mem      = {
648                         .enabled        = 1,
649                         .disabled       = 0,
650                 },
651         },
652         .num_consumer_supplies = ARRAY_SIZE(supplies_ps_on_led_a),
653         .consumer_supplies = supplies_ps_on_led_a,
654 };
655 static struct fixed_voltage_config ps_on_led_a_pdata = {
656         .supply_name = "LED_A_2.8V",
657         .microvolts = 2800000,
658         .gpio = S5PV310_GPE2(3), /* PS_ON */
659         .enable_high = 1,
660         .enabled_at_boot = 0,
661         .init_data = &ps_on_led_a_data,
662 };
663 static struct platform_device ps_on_led_a_fixed_reg_dev = {
664         .name = "reg-fixed-voltage",
665         .id = FIXED_REG_ID_LED_A,
666         .dev = { .platform_data = &ps_on_led_a_pdata },
667 };
668
669 /* I2C14: Light */
670 static struct i2c_gpio_platform_data i2c14_gpio_data = {
671         .sda_pin                = S5PV310_GPK2(2),      /* XMMC2CDn */
672         .scl_pin                = S5PV310_GPK3(2),      /* XMMC3CDn */
673         .udelay                 = 1,                    /* 500kHz   */
674 };
675
676 static struct platform_device i2c14_gpio = {
677         .name                   = "i2c-gpio",
678         .id                     = 14,
679         .dev                    = {
680                 .platform_data  = &i2c14_gpio_data,
681         },
682 };
683
684 #ifdef CONFIG_INPUT_GP2A
685 static int gp2a_led_control(bool enable)
686 {
687         static struct regulator *regulator;
688         static DEFINE_MUTEX(lock);
689         int ret = 0;
690
691         mutex_lock(&lock);
692
693         if (regulator == NULL)
694                 regulator = regulator_get_exclusive(NULL, "led_a_2.8v");
695         WARN(IS_ERR_OR_NULL(regulator), "%s cannot get regulator\n", __func__);
696         if (IS_ERR_OR_NULL(regulator)) {
697                 regulator = NULL;
698                 ret = ENODEV;
699                 goto out;
700         }
701
702         if (regulator_is_enabled(regulator)) {
703                 regulator_disable(regulator);
704                 if (enable)
705                         msleep(15);
706         }
707
708         if (enable)
709                 regulator_enable(regulator);
710 out:
711         mutex_unlock(&lock);
712         return ret;
713 }
714
715 static int gp2a_get_low_threshold(void)
716 {
717         int low_threshold = 7; /* LTH value */
718
719         if (system_rev == 2)    /* U1HD Linchbox board is not calibrated */
720                 low_threshold = 100;
721
722         return low_threshold;
723 }
724
725 static struct gp2a_platform_data u1hd_gp2a_pdata = {
726         .gp2a_led_on            = gp2a_led_control,
727         .p_out                          = S5PV310_GPX0(2),
728         .gp2a_get_low_threshold = gp2a_get_low_threshold,
729 };
730
731 static struct platform_device opt_gp2a = {
732         .name   = "gp2a-opt",
733         .id             = -1,
734         .dev    = {
735                 .platform_data  = &u1hd_gp2a_pdata,
736         },
737 };
738
739 static struct i2c_board_info i2c14_devs[] __initdata = {
740         {
741                 I2C_BOARD_INFO("gp2a", 0x72 >> 1),
742         },
743 };
744 #endif
745
746 static void __init u1hd_sensor_init(void)
747 {
748         int gpio;
749
750         gpio = S5PV310_GPX2(2); /* XEINT_18 */
751         gpio_request(gpio, "MSENSE_INT");
752         s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
753         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
754         i2c7_devs[0].irq = gpio_to_irq(gpio);
755
756         gpio = S5PV310_GPX0(0); /* XEINT_0 */
757         gpio_request(gpio, "GYRO_INT");
758         gpio_direction_input(gpio);
759         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
760
761         gpio = S5PV310_GPX0(1); /* XEINT_1 */
762         gpio_request(gpio, "GYRO_INT1");
763         gpio_direction_input(gpio);
764         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
765
766
767         gpio = S5PV310_GPX3(0); /* XEINT_24 */
768         gpio_request(gpio, "ACC_INT");
769         s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
770         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
771
772         /* added for gp2a light sensor*/
773         platform_device_register_simple("light_gp2a", 0, NULL, 0);
774 }
775
776 /* I2C15: MHL */
777 static struct i2c_gpio_platform_data i2c15_gpio_data = {
778         .sda_pin                = S5PV310_GPY3(0),      /* XM0ADDR_0 */
779         .scl_pin                = S5PV310_GPY3(2),      /* XM0ADDR_2 */
780         .udelay                 = 3,
781 };
782
783 static struct platform_device i2c15_gpio = {
784         .name                   = "i2c-gpio",
785         .id                     = 15,
786         .dev                    = {
787                 .platform_data  = &i2c15_gpio_data,
788         },
789 };
790
791 static struct i2c_board_info i2c15_devs[] __initdata = {
792         {
793                 I2C_BOARD_INFO("SII9234", 0x72>>1),
794         },
795         {
796                 I2C_BOARD_INFO("SII9234A", 0x7A>>1),
797         },
798         {
799                 I2C_BOARD_INFO("SII9234B", 0x92>>1),
800         },
801         {
802                 I2C_BOARD_INFO("SII9234C", 0xC8>>1),
803         },
804 };
805
806 /* I2C16: NFC */
807 #define GPIO_NFC_SCL_1_8V               S5PV310_GPY0(0)
808 #define GPIO_NFC_SDA_1_8V               S5PV310_GPY0(1)
809 #define GPIO_NFC_IRQ                    S5PV310_GPX1(7)
810 #define GPIO_NFC_EN                             S5PV310_GPL2(6)
811 #define GPIO_NFC_FIRMWARE               S5PV310_GPL2(7)
812
813 /* GPIO_LEVEL_NONE = 2, GPIO_LEVEL_LOW = 0 */
814 static unsigned int nfc_gpio_table[][4] = {
815         {GPIO_NFC_IRQ, S3C_GPIO_INPUT, 2, S3C_GPIO_PULL_DOWN},
816         {GPIO_NFC_EN, S3C_GPIO_OUTPUT, 0, S3C_GPIO_PULL_NONE},
817         {GPIO_NFC_FIRMWARE, S3C_GPIO_OUTPUT, 0, S3C_GPIO_PULL_NONE},
818         {GPIO_NFC_SCL_1_8V, S3C_GPIO_INPUT, 2, S3C_GPIO_PULL_NONE},
819         {GPIO_NFC_SDA_1_8V, S3C_GPIO_INPUT, 2, S3C_GPIO_PULL_NONE},
820 };
821
822 void u1hd_nfc_setup_gpio(void)
823 {
824         int array_size = ARRAY_SIZE(nfc_gpio_table);
825         u32 i, gpio;
826         for (i = 0; i < array_size; i++) {
827                 gpio = nfc_gpio_table[i][0];
828                 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(nfc_gpio_table[i][1]));
829                 s3c_gpio_setpull(gpio, nfc_gpio_table[i][3]);
830                 if (nfc_gpio_table[i][2] != 2)
831                         gpio_set_value(gpio, nfc_gpio_table[i][2]);
832         }
833 }
834
835 static struct i2c_gpio_platform_data i2c16_gpio_data = {
836         .sda_pin                = GPIO_NFC_SDA_1_8V,
837         .scl_pin                = GPIO_NFC_SCL_1_8V,
838         .udelay                 = 1,
839 };
840
841 static struct platform_device i2c16_gpio = {
842         .name                   = "i2c-gpio",
843         .id                     = 16,
844         .dev                    = {
845                 .platform_data  = &i2c16_gpio_data,
846         },
847 };
848
849 /* I2C16 */
850 static struct pn544_i2c_platform_data pn544_pdata = {
851         .irq_gpio = GPIO_NFC_IRQ,
852         .ven_gpio = GPIO_NFC_EN,
853         .firm_gpio = GPIO_NFC_FIRMWARE,
854 };
855
856 /* PN65NET1 NFC */
857 static struct i2c_board_info i2c16_devs[] __initdata = {
858         {
859                 I2C_BOARD_INFO("pn544", 0x2b),
860                 .platform_data  = &pn544_pdata,
861                 .irq            = IRQ_EINT(15),
862         },
863 };
864
865
866 /* I2C17: VGA CAM */
867 #if defined(CONFIG_VIDEO_S5K5BAFX)
868 #define VT_CAM_SDA_18V          S5PV310_GPC1(0)
869 #define VT_CAM_SCL_18V          S5PV310_GPC1(2)
870
871 static struct i2c_gpio_platform_data i2c17_platdata = {
872         .sda_pin                = VT_CAM_SDA_18V,
873         .scl_pin                = VT_CAM_SCL_18V,
874         .udelay                 = 2,
875         .sda_is_open_drain = 0,
876         .scl_is_open_drain = 0,
877         .scl_is_output_only = 0,
878 };
879
880 static struct platform_device s3c_device_i2c17 = {
881         .name           = "i2c-gpio",
882         .id                     = 17,
883         .dev.platform_data      = &i2c17_platdata,
884 };
885 /*
886 static struct i2c_board_info i2c17_devs[] __initdata = {
887         {
888                 I2C_BOARD_INFO("s5k5bafx", (0x5A >> 1)),
889         }
890 };
891 */
892 #endif
893
894 /* I2C18: FM RADIO*/
895 #define GPIO_FM_SDA_28V                 S5PV310_GPB(2)
896 #define GPIO_FM_SCL_28V                 S5PV310_GPB(3)
897
898 static struct i2c_gpio_platform_data i2c18_gpio_data = {
899         .sda_pin                = GPIO_FM_SDA_28V,
900         .scl_pin                = GPIO_FM_SCL_28V,
901 };
902
903 static struct platform_device i2c18_gpio = {
904         .name                   = "i2c-gpio",
905         .id                     = 18,
906         .dev                    = {
907                 .platform_data  = &i2c18_gpio_data,
908         },
909 };
910
911 static struct i2c_board_info i2c18_devs[] __initdata = {
912         {
913                 I2C_BOARD_INFO("si470x", (0x20 >> 1)),
914                 .irq = IRQ_EINT(20),
915         }
916 };
917
918 /* USB EHCI */
919 static struct s5p_usb_ehci_platdata u1hd_usb_ehci_pdata;
920
921 static void __init u1hd_usb_ehci_init(void)
922 {
923         struct s5p_usb_ehci_platdata *pdata = &u1hd_usb_ehci_pdata;
924
925         /* The gpios is initialized from modem_init */
926         pdata->gpio_active = MOBILE_GPIO(ACTIVE_STATE_HSIC);
927
928         s5p_usb_ehci_set_platdata(pdata);
929 }
930
931 /* USB OTG */
932 /* we don't use OTGDRVVBUS pin for powering up otg charging pump */
933 static void u1hd_otg_power_cb(int enable)
934 {
935         int gpio;
936         u8 on = (u8)!!enable;
937         gpio = MOBILE_GPIO(USB_OTG_EN);
938         gpio_request(gpio, "USB_OTG_EN");
939         gpio_direction_output(gpio, on);
940         gpio_free(gpio);
941         pr_info("%s: otg power = %d\n", __func__, on);
942 }
943
944 static void __init u1hd_usb_otg_init(void)
945 {
946         struct host_notify_dev *u1hd_otg_ndev =
947                         dev_get_platdata(&s3c_device_usbgadget.dev);
948         struct sec_otghost_data *u1hd_otg_host_data =
949                         dev_get_platdata(&s3c_device_usb_otghcd.dev);
950
951         u1hd_otg_ndev->set_booster = u1hd_otg_power_cb;
952         u1hd_otg_host_data->set_pwr_cb = u1hd_otg_power_cb;
953 }
954
955 /* MODEM Net */
956 static struct platform_device u1hd_modem_net = {
957         .name                   = "modem_net",
958         .id                     = -1,
959 };
960
961 /* XMM6260 control */
962 static struct xmm6260_gpios u1hd_xmm6260_gpios;
963
964 static struct xmm6260_platform_data u1hd_xmm6260_pdata = {
965         .gpios                  = &u1hd_xmm6260_gpios,
966         .wakeup                 = 1,
967 };
968
969 /*
970  * SLP uses standardized device name of modemctl
971  * and this is same to Android.
972  */
973 static struct platform_device u1hd_xmm6260 = {
974         .name                   = "modemctl",
975         .id                     = -1,
976         .dev                    = {
977                 .platform_data  = &u1hd_xmm6260_pdata,
978         },
979 };
980
981 static void __init u1hd_modem_init(void)
982 {
983         struct xmm6260_gpios *gpios = &u1hd_xmm6260_gpios;
984         int gpio;
985
986         gpio = MOBILE_GPIO(CP_ON);
987         gpio_request(gpio, "CP_ON");
988         gpio_direction_output(gpio, 0);
989         gpios->cp_on = gpio;
990
991         gpio = MOBILE_GPIO(PHONE_ACTIVE);
992         gpio_request(gpio, "PHONE_ACTIVE");
993         gpios->phone_active = gpio;
994
995         gpio = MOBILE_GPIO(PDA_ACTIVE);
996         gpio_request(gpio, "PDA_ACTIVE");
997         gpio_direction_output(gpio, 0);
998         gpios->pda_active = gpio;
999
1000         gpio = MOBILE_GPIO(CP_DUMP_INT);
1001         gpio_request(gpio, "CP_DUMP_INT");
1002         gpios->cp_dump_int = gpio;
1003
1004         gpio = MOBILE_GPIO(CP_PMU_RST);
1005         gpio_request(gpio, "CP_PMU_RST");
1006         gpio_direction_output(gpio, 0);
1007         gpios->cp_pmu_rst = gpio;
1008
1009         gpio = MOBILE_GPIO(RESET_REQ_N);
1010         gpio_request(gpio, "RESET_REQ_N");
1011         gpio_direction_output(gpio, 0);
1012         gpios->reset_req_n = gpio;
1013
1014         gpio = MOBILE_GPIO(IPC_SLAVE_WAKEUP);
1015         gpio_request(gpio, "IPC_SLAVE_WAKEUP");
1016         gpio_direction_output(gpio, 0);
1017         gpios->ipc_slave_wakeup = gpio;
1018
1019         gpio = MOBILE_GPIO(IPC_HOST_WAKEUP);
1020         gpio_request(gpio, "IPC_HOST_WAKEUP");
1021         gpios->ipc_host_wakeup = gpio;
1022
1023         gpio = MOBILE_GPIO(SUSPEND_REQUEST_HSIC);
1024         gpio_request(gpio, "SUSPEND_REQUEST_HSIC");
1025         gpios->suspend_request_hsic = gpio;
1026
1027         gpio = MOBILE_GPIO(ACTIVE_STATE_HSIC);
1028         gpio_request(gpio, "ACTIVE_STATE_HSIC");
1029         gpio_direction_output(gpio, 0);
1030         gpios->active_state_hsic = gpio;
1031 }
1032
1033 /* Uart Select */
1034 static void u1hd_set_uart_switch(int path)
1035 {
1036         int gpio;
1037
1038         gpio = MOBILE_GPIO(UART_SEL);
1039         gpio_request(gpio, "UART_SEL");
1040
1041         /* u1hd target is gpio_high == AP */
1042         if (path == UART_SW_PATH_AP)
1043                 gpio_set_value(gpio, GPIO_LEVEL_HIGH);
1044         else if (path == UART_SW_PATH_CP)
1045                 gpio_set_value(gpio, GPIO_LEVEL_LOW);
1046
1047         gpio_free(gpio);
1048         return;
1049 }
1050
1051 static int u1hd_get_uart_switch(void)
1052 {
1053         int val;
1054         int gpio;
1055
1056         gpio = MOBILE_GPIO(UART_SEL);
1057         gpio_request(gpio, "UART_SEL");
1058         val = gpio_get_value(gpio);
1059         gpio_free(gpio);
1060
1061         /* u1hd target is gpio_high == AP */
1062         if (val == GPIO_LEVEL_HIGH)
1063                 return UART_SW_PATH_AP;
1064         else if (val == GPIO_LEVEL_LOW)
1065                 return UART_SW_PATH_CP;
1066         else
1067                 return UART_SW_PATH_NA;
1068 }
1069
1070 static struct uart_select_platform_data u1hd_uart_select_data = {
1071         .set_uart_switch        = u1hd_set_uart_switch,
1072         .get_uart_switch        = u1hd_get_uart_switch,
1073 };
1074
1075 static struct platform_device u1hd_uart_select = {
1076         .name                   = "uart-select",
1077         .id                     = -1,
1078         .dev                    = {
1079                 .platform_data  = &u1hd_uart_select_data,
1080         },
1081 };
1082
1083 static struct regulator_consumer_supply emmc_supplies[] = {
1084         REGULATOR_SUPPLY("vmmc", "s3c-sdhci.0"),
1085         REGULATOR_SUPPLY("vmmc", "dw_mmc"),
1086 };
1087
1088 static struct regulator_init_data emmc_fixed_voltage_init_data = {
1089         .constraints            = {
1090                 .name           = "VMEM_VDD_2.8V",
1091                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1092         },
1093         .num_consumer_supplies  = ARRAY_SIZE(emmc_supplies),
1094         .consumer_supplies      = emmc_supplies,
1095 };
1096
1097 static struct fixed_voltage_config emmc_fixed_voltage_config = {
1098         .supply_name            = "eMMC_EN",
1099         .microvolts             = 2800000,
1100         .gpio                   = S5PV310_GPK0(2),
1101         .enable_high            = true,
1102         .init_data              = &emmc_fixed_voltage_init_data,
1103 };
1104
1105 static struct platform_device emmc_fixed_voltage = {
1106         .name                   = "reg-fixed-voltage",
1107         .id                     = FIXED_REG_ID_MMC,
1108         .dev                    = {
1109                 .platform_data  = &emmc_fixed_voltage_config,
1110         },
1111 };
1112
1113 #ifdef CONFIG_GSD4T
1114 #include "gsd4t.h"
1115
1116 /* GSD4T GPS module */
1117 static struct gsd4t_platform_data u1hd_gsd4t_data = {
1118         .onoff          = S5PV310_GPE0(3),
1119         .nrst           = S5PV310_GPE0(4),
1120         .tsync          = S5PV310_GPE0(1),
1121         .uart_rxd       = S5PV310_GPA0(4),
1122         .uart_txd       = S5PV310_GPA0(5),
1123         .uart_cts       = S5PV310_GPA0(6),
1124         .uart_rts       = S5PV310_GPA0(7),
1125 };
1126
1127 static struct platform_device u1hd_gsd4t = {
1128         .name                   = "gsd4t",
1129         .id                     = -1,
1130         .dev                    = {
1131                 .platform_data  = &u1hd_gsd4t_data,
1132         },
1133 };
1134 #endif
1135
1136 /* MALI DRM. */
1137 #ifdef CONFIG_DRM_MALI
1138 static struct platform_device s5p_device_mali_drm = {
1139         .name                   = "mali_drm",
1140         .id                     = -1,
1141 };
1142 #endif
1143
1144 /* FIMD DRM. */
1145 #ifdef CONFIG_DRM_FIMD
1146 static struct resource fimd_drm_resource[] = {
1147         [0] = {
1148                 .start          = S5P_PA_LCD0,
1149                 .end            = S5P_PA_LCD0 + S5P_SZ_LCD0 - 1,
1150                 .flags          = IORESOURCE_MEM,
1151         },
1152         [1] = {
1153                 .start          = S5P_PA_LCD1,
1154                 .end            = S5P_PA_LCD1 + S5P_SZ_LCD1 - 1,
1155                 .flags          = IORESOURCE_MEM,
1156         },
1157         [2] = {
1158                 .start          = IRQ_LCD1,
1159                 .end            = IRQ_LCD1,
1160                 .flags          = IORESOURCE_IRQ,
1161         },
1162         [3] = {
1163                 .start          = IRQ_LCD0,
1164                 .end            = IRQ_LCD0,
1165                 .flags          = IORESOURCE_IRQ,
1166         },
1167 };
1168
1169 static struct fimd_drm_platform_data fimd_drm_pd = {
1170         .hw_ver = 0x70,
1171 };
1172
1173 static struct platform_device s5p_device_fimd_drm = {
1174         .name                   = "fimd_drm",
1175         .id                     = -1,
1176         .num_resources          = ARRAY_SIZE(fimd_drm_resource),
1177         .resource               = fimd_drm_resource,
1178         .dev                    = {
1179                 .platform_data = &fimd_drm_pd,
1180         },
1181 };
1182 #endif
1183
1184 /* ADC */
1185 static struct s3c_adc_platform_data s3c_adc_pdata __initdata = {
1186         .delay                  = 1000,
1187         .presc                  = 49,
1188         .resolution             = 12,
1189         .max_adc_voltage_uV     = 3300000,
1190 };
1191
1192 static void __init u1hd_adc_init(void)
1193 {
1194         s3c_adc_set_platdata(&s3c_adc_pdata);
1195 }
1196
1197 static void ramoops_enable(int enable)
1198 {
1199         struct clk *clk;
1200
1201         clk = clk_get(NULL, "modem");
1202         if (enable)
1203                 clk_enable(clk);
1204         else
1205                 clk_disable(clk);
1206         clk_put(clk);
1207 }
1208
1209 static struct ramoops_platform_data u1hd_ramoops_data = {
1210         .mem_address            = 0x13A00000,           /* MODEM I/F */
1211         .mem_size               = SZ_16K,
1212         .enable                 = ramoops_enable,
1213 };
1214
1215 static struct platform_device u1hd_ramoops = {
1216         .name                   = "ramoops",
1217         .dev                    = {
1218                 .platform_data  = &u1hd_ramoops_data,
1219         },
1220 };
1221
1222 /* TZPC */
1223 static struct platform_device u1hd_tzpc = {
1224         .name                   = "tzpc",
1225         .id                     = -1,
1226 };
1227
1228 #ifdef CONFIG_ANDROID_RAM_CONSOLE
1229 static struct resource ram_console_resource[] = {
1230         [0] = {
1231                 .flags = IORESOURCE_MEM,
1232         },
1233 };
1234
1235 static struct platform_device ram_console_device = {
1236         .name                   = "ram_console",
1237         .id                     = -1,
1238         .num_resources          = ARRAY_SIZE(ram_console_resource),
1239         .resource               = ram_console_resource,
1240 };
1241 #endif
1242
1243 static void __init u1hd_map_io(void)
1244 {
1245         s5p_init_io(NULL, 0, S5P_VA_CHIPID);
1246         s5p_xtal_set_parent(CLK_XUSBXTI);
1247         s3c24xx_init_clocks(24000000);
1248         s3c24xx_init_uarts(u1hd_uartcfgs, ARRAY_SIZE(u1hd_uartcfgs));
1249 }
1250
1251 static unsigned long fbmem_start, fbmem_size;
1252 static int __init early_fbmem(char *p)
1253 {
1254         char *endp;
1255
1256         if (!p)
1257                 return -EINVAL;
1258
1259         fbmem_size = memparse(p, &endp);
1260         if (*endp == '@')
1261                 fbmem_start = memparse(endp + 1, &endp);
1262
1263         return endp > p ? 0 : -EINVAL;
1264 }
1265 early_param("fbmem", early_fbmem);
1266
1267 static struct cma_region regions[] = {
1268 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMD0
1269         {
1270                 .name = "fimd",
1271                 .size = (CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMD0
1272 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMD1
1273                                 + CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMD1
1274 #endif
1275                         ) * SZ_1K,
1276         },
1277 #endif
1278 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC0
1279                 {
1280                         .name = "fimc0",
1281                         .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC0 * SZ_1K,
1282                         .start = 0
1283                 },
1284 #endif
1285 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC1
1286                 {
1287                         .name = "fimc1",
1288                         .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC1 * SZ_1K,
1289                         .start = 0
1290                 },
1291 #endif
1292 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC2
1293                 {
1294                         .name = "fimc2",
1295                         .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC2 * SZ_1K,
1296                         .start = 0
1297                 },
1298 #endif
1299 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC3
1300                 {
1301                         .name = "fimc3",
1302                         .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_FIMC3 * SZ_1K,
1303                         .start = 0
1304                 },
1305 #endif
1306
1307 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_S3C_MEM_CMA
1308                 {
1309                         .name = "s3c-mem-cma",
1310                         .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_S3C_MEM_CMA * SZ_1K,
1311                         .start = 0
1312                 },
1313 #endif
1314
1315 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_JPEG
1316         {
1317                 .name           = "jpeg",
1318                 .size           = CONFIG_VIDEO_SAMSUNG_MEMSIZE_JPEG *  SZ_1K,
1319         },
1320 #endif
1321 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC
1322         {
1323                 .name = "mfc",
1324                 .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC *  SZ_1K,
1325         },
1326 #endif
1327 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC0
1328         {
1329                 .name = "mfc0",
1330                 .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC0 * SZ_1K,
1331                 {
1332                         .alignment = 1 << 17,
1333                 },
1334         },
1335 #endif
1336 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC1
1337         {
1338                 .name = "mfc1",
1339                 .size = CONFIG_VIDEO_SAMSUNG_MEMSIZE_MFC1 * SZ_1K,
1340                 {
1341                         .alignment = 1 << 17,
1342                 },
1343         },
1344 #endif
1345 #ifdef CONFIG_VIDEO_SAMSUNG_S5P_TV
1346         {
1347                 .name           = "tv",
1348                 .size           = 16 << 20,
1349         },
1350 #endif
1351 #ifdef CONFIG_VIDEO_SAMSUNG_S5P_MFC
1352         {
1353                 .name           = "fw",
1354                 .size           = 1 << 20,
1355                 { .alignment    = 128 << 10 },
1356                 .start          = 0x42000000,
1357         },
1358         {
1359                 .name           = "b1",
1360                 .size           = 32 << 20,
1361                 .start          = 0x43000000,
1362         },
1363         {
1364                 .name           = "b2",
1365                 .size           = 32 << 20,
1366                 .start          = 0x51000000,
1367         },
1368 #endif
1369 #ifdef CONFIG_SEC_DEBUG
1370         {
1371                 .name           = "getlog",
1372                 .size           = 1 << 12,
1373                 .start          = 0x40003000,
1374         },
1375 #endif
1376         { }
1377 };
1378
1379 static void __init s5pv310_reserve(void)
1380 {
1381         static const char map[] __initconst =
1382                 "s3cfb=fimd;"
1383 #ifdef CONFIG_VIDEO_FIMC
1384                 "s3c-fimc.0=fimc0;"
1385                 "s3c-fimc.1=fimc1;"
1386                 "s3c-fimc.2=fimc2;"
1387                 "s3c-fimc.3=fimc3;"
1388 #endif
1389 #ifdef CONFIG_S3C_MEM_CMA_ALLOC
1390                 "s3c-mem=s3c-mem-cma;"
1391 #endif
1392
1393                 "s5p-jpeg=jpeg;"
1394 #ifdef CONFIG_SEC_DEBUG
1395                 "s3c-getlog=getlog;"
1396 #endif
1397
1398 #if defined(CONFIG_VIDEO_SAMSUNG_S5P_MFC)
1399                 "mfc=mfc,mfc0,mfc1;"
1400                 "s5p-mfc/f=fw;s5p-mfc/a=b1;s5p-mfc/b=b2;"
1401 #else
1402 #ifdef CONFIG_VIDEO_SAMSUNG_MEMSIZE_PROFILING
1403                 "s3c-mfc/mfc=mfc;s3c-mfc/mfc0=mfc0;s3c-mfc/mfc1=mfc1;"
1404 #else
1405                 "s3c-mfc=mfc,mfc0,mfc1;"
1406 #endif
1407 #endif
1408                 "*=b1,b2,tv";
1409
1410         unsigned int i = 0;
1411
1412 #ifdef CONFIG_ANDROID_RAM_CONSOLE
1413         unsigned int addr;
1414
1415         /* FIXME: ram console MUST be reserved at first time */
1416         addr = memblock_alloc_base(SZ_1M, SZ_4K, 0x60000000);
1417         ram_console_resource[0].start = addr;
1418         ram_console_resource[0].end = addr + SZ_1M - 1;
1419         pr_info("ram_console: 0x%08x ~ 0x%08x (1MB)\n",
1420                         addr, addr + SZ_1M);
1421 #endif
1422
1423         if (fbmem_start)
1424                 regions[0].start = (dma_addr_t)fbmem_start;
1425         if (fbmem_size)
1426                 regions[0].size = (size_t)fbmem_size;
1427
1428         cma_set_defaults(regions, map);
1429         cma_early_regions_reserve(NULL);
1430
1431         for (; i < ARRAY_SIZE(regions) - 1 /* terminator */; ++i) {
1432                 pr_info("cma: region: %-8s: 0x%08x ~ 0x%08x (%dMB)\n",
1433                                 regions[i].name, regions[i].start,
1434                                 regions[i].start + regions[i].size,
1435                                 regions[i].size / SZ_1M);
1436         }
1437 }
1438
1439 #ifdef CONFIG_HIBERNATION
1440 static int __init u1hd_set_nosave_regions(void)
1441 {
1442         int i;
1443
1444         for ( i = ARRAY_SIZE(regions) - 2; i >= 0 /* terminator */; i--) {
1445                 /* MFC firmware SHOULD BE saved.
1446                  * If the region is fw, don't register to nosave regions */
1447                 if (strcmp(regions[i].name, "fw"))
1448                         register_nosave_region_late(
1449                                         __phys_to_pfn(regions[i].start),
1450                                         __phys_to_pfn(regions[i].start +
1451                                                 regions[i].size));
1452         }
1453         return 0;
1454 }
1455 late_initcall(u1hd_set_nosave_regions);
1456 #endif
1457
1458 /*
1459  * GPX are saved and restored at plat-samsung/pm.c:s5c_pm_enter.
1460  * However, they are inside of pm_prepare and pm_finish, so it
1461  * does not save ours against universal_pm_prepare:2.
1462  */
1463 static struct sleep_save s5pc210_gpx[] = {
1464         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C00),
1465         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C04),
1466         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C08),
1467         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C0C),
1468         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C20),
1469         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C24),
1470         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C28),
1471         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C2C),
1472         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C40),
1473         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C44),
1474         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C48),
1475         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C4C),
1476         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C60),
1477         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C64),
1478         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C68),
1479         SAVE_ITEM(S5P_VA_GPIO2 + 0x0C6C),
1480 };
1481
1482 /* GPIO KEYS */
1483 static struct gpio_keys_button u1hd_gpio_keys_tables[] = {
1484         {
1485                 .code                   = KEY_VOLUMEUP,
1486                 .gpio                   = S5PV310_GPX2(0),      /* XEINT16 */
1487                 .desc                   = "gpio-keys: KEY_VOLUMEUP",
1488                 .type                   = EV_KEY,
1489                 .active_low             = 1,
1490                 .debounce_interval      = 1,
1491 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump ++ */
1492         #ifdef CONFIG_INPUT_FORCE_PANIC_KEY
1493                 .isr_hook = sec_debug_check_crash_key , /* VOL UP */
1494         #endif
1495 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump -- */
1496
1497         }, {
1498                 .code                   = KEY_VOLUMEDOWN,
1499                 .gpio                   = S5PV310_GPX2(1),      /* XEINT17 */
1500                 .desc                   = "gpio-keys: KEY_VOLUMEDOWN",
1501                 .type                   = EV_KEY,
1502                 .active_low             = 1,
1503                 .debounce_interval      = 1,
1504 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump ++ */
1505         #ifdef CONFIG_INPUT_FORCE_PANIC_KEY
1506                 .isr_hook = sec_debug_check_crash_key , /*VOL DOWN */
1507         #endif
1508 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump -- */
1509
1510         }, {
1511                 .code                   = KEY_POWER,
1512                 .gpio                   = S5PV310_GPX2(7),      /* XEINT23 */
1513                 .desc                   = "gpio-keys: KEY_POWER",
1514                 .type                   = EV_KEY,
1515                 .active_low             = 1,
1516                 .wakeup                 = 1,
1517                 .debounce_interval      = 1,
1518         }, {
1519                                         /* KEY_MENU will be used */
1520                 .code                   = KEY_MENU,             /* KEY_OK */
1521                 .gpio                   = S5PV310_GPX3(5),      /* XEINT29 */
1522                 .desc                   = "gpio-keys: KEY_MENU",
1523                 .type                   = EV_KEY,
1524                 .active_low             = 1,
1525                 .wakeup                 = 1,
1526                 .debounce_interval      = 1,
1527 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump ++ */
1528         #ifdef CONFIG_INPUT_FORCE_PANIC_KEY
1529                 .isr_hook = sec_debug_check_crash_key , /* HOME */
1530         #endif
1531 /* YUBAEK 20110905 RAMDUMP_DEBUG : Android forceable ramdump -- */
1532
1533         },
1534 };
1535
1536 static struct gpio_keys_platform_data u1hd_gpio_keys_data = {
1537         .buttons                = u1hd_gpio_keys_tables,
1538         .nbuttons               = ARRAY_SIZE(u1hd_gpio_keys_tables),
1539 };
1540
1541 static struct platform_device u1hd_gpio_keys = {
1542         .name                   = "gpio-keys",
1543         .dev                    = {
1544                 .platform_data  = &u1hd_gpio_keys_data,
1545         },
1546 };
1547 /* s6e8aa0 panel. */
1548 static struct s3cfb_lcd s6e8aa0 = {
1549         .width = 720,
1550         .height = 1280,
1551         .width_mm = 58,
1552         .height_mm = 103,
1553         .bpp = 24,
1554
1555         .freq = 60,
1556         .dynamic_refresh = 1,
1557         .timing = {
1558                 .h_fp = 10,
1559                 .h_bp = 10,
1560                 .h_sw = 5,
1561                 .v_fp = 13,
1562                 .v_fpe = 1,
1563                 .v_bp = 1,
1564                 .v_bpe = 1,
1565                 .v_sw = 2,
1566                 .cmd_allow_len = 0xf,
1567         },
1568         .polarity = {
1569                 .rise_vclk = 1,
1570                 .inv_hsync = 0,
1571                 .inv_vsync = 0,
1572                 .inv_vden = 0,
1573         },
1574 };
1575
1576 static int lcd_power_on(struct lcd_device *ld, int enable)
1577 {
1578         static struct regulator *r_22, *r_33;
1579         static DEFINE_MUTEX(lock);
1580         int ret = -1;
1581
1582         dev_info(&ld->dev, "enable=%d\n", enable);
1583
1584         mutex_lock(&lock);
1585
1586         if (r_22 == NULL)
1587                 r_22 = regulator_get_exclusive(&ld->dev, "vlcd_2.2v");
1588         if (IS_ERR_OR_NULL(r_22)) {
1589                 ret = -EINVAL;
1590                 r_22 = NULL;
1591                 goto out;
1592         }
1593
1594         if (r_33 == NULL)
1595                 r_33 = regulator_get_exclusive(&ld->dev, "vcc_3.0v_lcd");
1596         if (IS_ERR_OR_NULL(r_33)) {
1597                 ret = -EINVAL;
1598                 r_33 = NULL;
1599                 goto out;
1600         }
1601
1602         /* These are exclusively got regulators. use is_enabled */
1603         if (enable && regulator_is_enabled(r_22) == 0)
1604                 regulator_enable(r_22);
1605         if (enable && regulator_is_enabled(r_33) == 0)
1606                 regulator_enable(r_33);
1607         if (!enable && regulator_is_enabled(r_22))
1608                 regulator_disable(r_22);
1609         if (!enable && regulator_is_enabled(r_33))
1610                 regulator_disable(r_33);
1611
1612         /* reset pull_down */
1613         if (!enable) {
1614                 int reset_gpio = -1;
1615                 reset_gpio = S5PV310_GPY4(5);
1616                 gpio_direction_output(reset_gpio, 0);
1617                 dev_info(&ld->dev, "reset LOW completed.\n");
1618         }
1619
1620 out:
1621         mutex_unlock(&lock);
1622         return ret;
1623 }
1624
1625 static int reset_lcd(struct lcd_device *ld)
1626 {
1627         static unsigned int first = 1;
1628         int reset_gpio = -1;
1629
1630         reset_gpio = S5PV310_GPY4(5);
1631
1632         if (first) {
1633                 gpio_request(reset_gpio, "MLCD_RST");
1634                 first = 0;
1635         }
1636
1637         gpio_direction_output(reset_gpio, 1);
1638         usleep_range(1000, 2000);
1639         gpio_direction_output(reset_gpio, 0);
1640         usleep_range(1000, 2000);
1641         gpio_direction_output(reset_gpio, 1);
1642         dev_info(&ld->dev, "reset HIGH completed.\n");
1643
1644         return 0;
1645 }
1646
1647 int s5p_mipi_dphy_power(struct platform_device *pdev, unsigned int enable)
1648 {
1649         static struct regulator *p_mipi_1_1v, *p_mipi_1_8v;
1650         static DEFINE_MUTEX(lock);
1651         static bool enabled;
1652         int ret = 0;
1653
1654         dev_info(&pdev->dev, "enable = %d\n", enable);
1655
1656         mutex_lock(&lock);
1657
1658         if (enabled == !!enable)
1659                 goto out;
1660
1661         if (p_mipi_1_1v == NULL)
1662                 p_mipi_1_1v = regulator_get(&pdev->dev, "mipi_1.1v_c210");
1663         if (IS_ERR_OR_NULL(p_mipi_1_1v)) {
1664                 ret = -EFAULT;
1665                 p_mipi_1_1v = NULL;
1666                 dev_err(&pdev->dev, "failed to get regulator.\n");
1667                 goto out;
1668         }
1669
1670         if (p_mipi_1_8v == NULL)
1671                 p_mipi_1_8v = regulator_get(&pdev->dev, "vmipi_1.8v");
1672         if (IS_ERR_OR_NULL(p_mipi_1_8v)) {
1673                 ret = -EFAULT;
1674                 p_mipi_1_8v = NULL;
1675                 dev_err(&pdev->dev, "failed to get regulator.\n");
1676                 goto out;
1677         }
1678
1679         if (enable) {
1680                 ret = regulator_enable(p_mipi_1_1v);
1681                 if (ret)
1682                         goto out;
1683                 ret = regulator_enable(p_mipi_1_8v);
1684                 if (ret)
1685                         goto out;
1686         } else {
1687                 ret = regulator_disable(p_mipi_1_1v);
1688                 if (ret)
1689                         goto out;
1690                 ret = regulator_disable(p_mipi_1_8v);
1691                 if (ret)
1692                         goto out;
1693         }
1694
1695         enabled = !!enable;
1696 out:
1697         mutex_unlock(&lock);
1698         return ret;
1699 }
1700
1701 static struct mipi_dsim_config dsim_config = {
1702         .e_interface            = DSIM_VIDEO,
1703         .e_virtual_ch           = DSIM_VIRTUAL_CH_0,
1704         .e_pixel_format         = DSIM_24BPP_888,
1705         .e_burst_mode           = DSIM_BURST_SYNC_EVENT,
1706         .e_no_data_lane         = DSIM_DATA_LANE_4,
1707         .e_byte_clk             = DSIM_PLL_OUT_DIV8,
1708
1709         /*
1710          * ===========================================
1711          * |    P    |    M    |    S    |    MHz    |
1712          * -------------------------------------------
1713          * |    3    |   100   |    3    |    100    |
1714          * |    3    |   100   |    2    |    200    |
1715          * |    3    |    63   |    1    |    252    |
1716          * |    4    |   100   |    1    |    300    |
1717          * |    4    |   110   |    1    |    330    |
1718          * |   12    |   350   |    1    |    350    |
1719          * |    3    |   100   |    1    |    400    |
1720          * |    4    |   150   |    1    |    450    |
1721          * |    3    |   120   |    1    |    480    |
1722          * |   12    |   250   |    0    |    500    |
1723          * |    4    |   100   |    0    |    600    |
1724          * |    3    |    81   |    0    |    648    |
1725          * |    3    |    88   |    0    |    704    |
1726          * |    3    |    90   |    0    |    720    |
1727          * |    3    |   100   |    0    |    800    |
1728          * |   12    |   425   |    0    |    850    |
1729          * |    4    |   150   |    0    |    900    |
1730          * |   12    |   475   |    0    |    950    |
1731          * |    6    |   250   |    0    |   1000    |
1732          * -------------------------------------------
1733          */
1734
1735         .p                      = 12,
1736         .m                      = 250,
1737         .s                      = 0,
1738
1739         /* D-PHY PLL stable time spec :min = 200usec ~ max 400usec */
1740         .pll_stable_time        = 500,
1741
1742         /* escape clk : 10MHz */
1743         .esc_clk                = 10 * 1000000,
1744
1745         /* stop state holding counter after bta change count 0 ~ 0xfff */
1746         .stop_holding_cnt       = 0x7ff,
1747         /* bta timeout 0 ~ 0xff */
1748         .bta_timeout            = 0xff,
1749         /* lp rx timeout 0 ~ 0xffff */
1750         .rx_timeout             = 0xffff,
1751 };
1752
1753 static struct s5p_platform_mipi_dsim dsim_platform_data = {
1754         /* FIXME. */
1755         .enabled                = 0,
1756         .phy_enable             = s5p_dsim_phy_enable,
1757         .dsim_config            = &dsim_config,
1758 };
1759
1760 static struct lcd_platform_data s6e8aa0_pd = {
1761         .reset                  = reset_lcd,
1762         .power_on               = lcd_power_on,
1763         .reset_delay            = 25,
1764         .power_off_delay        = 120,
1765         .power_on_delay         = 120,
1766 };
1767
1768 static struct mipi_dsim_lcd_device mipi_lcd_device = {
1769         .name                   = "s6e8aa0",
1770         .panel_id               = "ams465gs01", /* U1HD */
1771         .id                     = -1,
1772         .bus_id                 = 0,
1773
1774         .platform_data          = (void *)&s6e8aa0_pd,
1775 };
1776
1777 #ifdef CONFIG_VIDEO_FIMG2D
1778 static struct fimg2d_platdata fimg2d_data __initdata = {
1779         .hw_ver                 = 30,
1780         .parent_clkname         = "mout_g2d0",
1781         .clkname                = "sclk_fimg2d",
1782         .gate_clkname           = "fimg2d",
1783         .smmu_gate_clkname      = "smmu_fimg2d",
1784         .clkrate                = 250 * 1000000,
1785 };
1786 #endif
1787
1788 static struct s3c_platform_fb fb_platform_data __initdata = {
1789         .hw_ver                 = 0x70,
1790         .nr_wins                = 5,
1791 #ifdef CONFIG_FB_S3C_DEFAULT_WINDOW
1792         .default_win            = CONFIG_FB_S3C_DEFAULT_WINDOW,
1793 #else
1794         .default_win            = 0,
1795 #endif
1796         .swap                   = FB_SWAP_HWORD | FB_SWAP_WORD,
1797 };
1798
1799 #ifdef CONFIG_FB_S3C_HIBERNATION_LOADING
1800 #include <linux/hib_ani.h> /* FIXME:!! hib_ani_hd.h */
1801
1802 static struct s3cfb_hib_ani hib_ani_set __initdata = {
1803         .text_ani1 = {
1804                 .width = 300,
1805                 .height = 34,
1806                 .x_point = 72,
1807                 .y_point =473,
1808
1809         },
1810         .text_ani2 = {
1811                 .width = 580,
1812                 .height = 59,
1813                 .x_point = 66,
1814                 .y_point = 520,
1815
1816         },
1817         .count_ani = {
1818                 .width = 720,
1819                 .height = 178,
1820                 .x_point = 0,
1821                 .y_point = 579,
1822         },
1823         .delay = 400,
1824         .hib_animation = hib_anis, /* FIXME:!! hib_anis_hd */
1825
1826 };
1827 #endif
1828
1829
1830 static void __init u1hd_fb_init(void)
1831 {
1832         struct device *dev = s3c_device_fb.dev.parent;
1833         struct samsung_pd_info *pdinfo;
1834         struct s5p_platform_mipi_dsim *dsim_pd;
1835
1836         if (dev) {
1837                 pdinfo = (struct samsung_pd_info *)dev->platform_data;
1838                 /* fimd driver have to know LCD domain power status. */
1839                 if (pdinfo)
1840                         fb_platform_data.boot_on = pdinfo->boot_on;
1841         }
1842
1843         if (fbmem_start)
1844                 fb_platform_data.logo_on = 1;
1845
1846         s5p_device_mipi_dsim0.dev.platform_data = (void *)&dsim_platform_data;
1847         dsim_pd = (struct s5p_platform_mipi_dsim *)&dsim_platform_data;
1848
1849         strcpy(dsim_pd->lcd_panel_name, "s6e8aa0");
1850         dsim_pd->mipi_power = s5p_mipi_dphy_power;
1851         dsim_pd->lcd_panel_info = &s6e8aa0;
1852         s5p_mipi_dsi_register_lcd_device(&mipi_lcd_device);
1853         platform_device_register(&s5p_device_mipi_dsim0);
1854
1855         s5p_device_mipi_dsim0.dev.parent = &s5pv310_device_pd[PD_LCD0].dev;
1856
1857 #ifdef CONFIG_FB_S3C_HIBERNATION_LOADING
1858         fb_platform_data.hib_ani = (void *)&hib_ani_set;
1859 #endif
1860         fb_platform_data.lcd_data = (struct s3cfb_lcd *)&s6e8aa0;
1861         s3cfb_set_platdata(&fb_platform_data);
1862
1863         s3cfb_cfg_gpio(NULL);
1864 }
1865
1866 /* YUBAEK 20110905 RAMDUMP_DEBUG : GPIO Dump ++ */
1867 #ifdef CONFIG_SEC_DEBUG_PERIPHERAL_DUMP_GPIO
1868 void __iomem *s5pv310_gpio_class_a_addr;
1869 void __iomem *s5pv310_gpio_class_b_addr;
1870 static void s5pv310_gpio_io_map(void)
1871 {
1872     s5pv310_gpio_class_a_addr = ioremap(S5PV310_PA_GPIO1, SZ_4K);
1873     s5pv310_gpio_class_b_addr = ioremap(S5PV310_PA_GPIO2, SZ_4K);
1874 }
1875 #endif /* CONFIG_SEC_DEBUG_PERIPHERAL_DUMP_GPIO */
1876 /* YUBAEK 20110905 RAMDUMP_DEBUG : GPIO Dump -- */
1877
1878 /* Jack */
1879 static struct jack_platform_data u1hd_jack_data = {
1880         .usb_online             = 0,
1881         .charger_online         = 0,
1882         .hdmi_online            = 0,
1883         .earjack_online         = 0,
1884         .earkey_online          = 0,
1885         .ums_online             = -1,
1886         .cdrom_online           = -1,
1887         .jig_online             = 0,
1888 };
1889
1890 static struct platform_device u1hd_jack = {
1891         .name                   = "jack",
1892         .id                     = -1,
1893         .dev                    = {
1894                 .platform_data  = &u1hd_jack_data,
1895         },
1896 };
1897
1898 //device dependent regulator feature
1899
1900 //============================================================
1901 // FM Radio
1902 //============================================================
1903 static struct regulator_consumer_supply fmradio_supplies[] = {
1904         {
1905                 .supply         = "vradio",
1906         },
1907 };
1908
1909 static struct regulator_init_data fmradio_fixed_voltage_init_data = {
1910         .constraints    = {
1911                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1912         },
1913         .num_consumer_supplies  = ARRAY_SIZE(fmradio_supplies),
1914         .consumer_supplies      = fmradio_supplies,
1915 };
1916 #define GPIO_FM_RST             S5PV310_GPB(0)
1917 static struct fixed_voltage_config fmradio_fixed_voltage_config = {
1918         .supply_name            = "FM_RST",
1919         .microvolts             = 2800000,
1920         .gpio                   = GPIO_FM_RST,
1921         .enable_high            = true,
1922         .init_data              = &fmradio_fixed_voltage_init_data,
1923 };
1924
1925 static struct platform_device fmradio_fixed_voltage = {
1926         .name           = "reg-fixed-voltage",
1927         .id             = FIXED_REG_ID_RADIO,
1928         .dev            = {
1929                 .platform_data  = &fmradio_fixed_voltage_config,
1930         },
1931 };
1932 /*
1933 static void u1hd_sec_switch_init(void)
1934 {
1935         sec_class = class_create(THIS_MODULE, "sec");
1936
1937         if (IS_ERR(sec_class))
1938                 pr_err("Failed to create class(sec)!\n");
1939
1940         switch_dev = device_create(sec_class, NULL, 0, NULL, "switch");
1941
1942         if (IS_ERR(switch_dev))
1943                 pr_err("Failed to create device(switch)!\n");
1944
1945 //      ret = device_create_file(switch_dev, &dev_attr_disable_vbus);
1946 //      if (ret)
1947 //              pr_err("Failed to create device file(disable_vbus)!\n");
1948
1949 #ifdef CONFIG_TARGET_LOCALE_KOR
1950         usb_lock = device_create(sec_class, switch_dev,
1951                                 MKDEV(0, 0), NULL, ".usb_lock");
1952
1953         if (IS_ERR(usb_lock)) {
1954                 pr_err("Failed to create device (usb_lock)!\n");
1955                 return;
1956         }
1957
1958         if (device_create_file(usb_lock, &dev_attr_enable) < 0)
1959                 pr_err("Failed to create device file(.usblock/enable)!\n");
1960 #endif
1961 };
1962 */
1963 static struct u1hd_charging_status_callbacks {
1964 void    (*tsp_set_charging_cable) (int type);
1965 } charging_cbs;
1966
1967 static bool is_cable_attached;
1968
1969 static int u1hd_charger_cb(cable_type_t cable_type)
1970 {
1971         union power_supply_propval value;
1972         int ret = 0;
1973
1974         switch(cable_type) {
1975         case CABLE_TYPE_NONE:
1976         case CABLE_TYPE_OTG:
1977         case CABLE_TYPE_JIG_UART_OFF:
1978                 value.intval = POWER_SUPPLY_TYPE_BATTERY;
1979                 is_cable_attached = false;
1980                 break;
1981         case CABLE_TYPE_USB:
1982         case CABLE_TYPE_JIG_USB_OFF:
1983         case CABLE_TYPE_JIG_USB_ON:
1984                 value.intval = POWER_SUPPLY_TYPE_USB;
1985                 is_cable_attached = true;
1986                 break;
1987         case CABLE_TYPE_DESKDOCK:
1988         case CABLE_TYPE_CARDOCK:
1989                 value.intval = POWER_SUPPLY_TYPE_DOCK;
1990                 is_cable_attached = true;
1991                 break;
1992         case CABLE_TYPE_TA:
1993         case CABLE_TYPE_JIG_UART_OFF_VB:
1994                 value.intval = POWER_SUPPLY_TYPE_MAINS;
1995                 is_cable_attached = true;
1996                 break;
1997         default:
1998                 pr_err("%s: invalid type:%d\n", __func__, cable_type);
1999                 return -EINVAL;
2000         }
2001
2002         if (charging_cbs.tsp_set_charging_cable)
2003                 charging_cbs.tsp_set_charging_cable(value.intval);
2004
2005 #ifdef CONFIG_JACK_MON
2006         jack_event_handler("charger", is_cable_attached);
2007 #endif
2008
2009         return ret;
2010 }
2011
2012 static struct regulator *regulator_vbus_ap;
2013 static bool ap_enabled;
2014 static DEFINE_MUTEX(usb_ap_lock);
2015
2016 static void u1hd_usb_cb(u8 usb_mode)
2017 {
2018         int ret;
2019         struct s3c_udc *udc = platform_get_drvdata(&s3c_device_usbgadget);
2020         struct sec_otghost_data *otg_data =
2021                         dev_get_platdata(&s3c_device_usb_otghcd.dev);
2022
2023         unsigned long inform6 = __raw_readl(S5P_INFORM6);
2024
2025         pr_info("%s: usb mode=%d, inform6=0x%08lx\n", __func__, usb_mode, inform6);
2026
2027         if (inform6 & RST_FLAG_CHARGE_REBOOT_CHECK ) {
2028                 pr_info("%s: lpcharging: disable USB\n", __func__);
2029                 ret = udc->change_usb_mode(USB_CABLE_DETACHED);
2030                 if (ret < 0)
2031                         pr_warn("%s: fail to change mode!!!\n", __func__);
2032
2033                 mutex_lock(&usb_ap_lock);
2034
2035                 if (regulator_vbus_ap == NULL)
2036                         regulator_vbus_ap =
2037                             regulator_get_exclusive(NULL, "usb_vbus_ap_5v");
2038                 if (IS_ERR_OR_NULL(regulator_vbus_ap)) {
2039                         pr_err("%s: fail to get regulator\n", __func__);
2040                         regulator_vbus_ap = NULL;
2041                         goto out;
2042                 }
2043
2044                 if (ap_enabled) {
2045                         ret = regulator_disable(regulator_vbus_ap);
2046                         if (ret)
2047                                 goto out;
2048                         ap_enabled = false;
2049                 }
2050 out:
2051                 mutex_unlock(&usb_ap_lock);
2052                 return;
2053         }
2054
2055         if (udc) {
2056                 if (usb_mode == USB_OTGHOST_ATTACHED) {
2057                         otg_data->set_pwr_cb(1);
2058                         u1hd_charger_cb(CABLE_TYPE_OTG);
2059                 }
2060
2061                 pr_info("%s: prev_usb_mode=%d\n", __func__, udc->get_usb_mode());
2062
2063                 ret = udc->change_usb_mode(usb_mode);
2064                 if (ret < 0)
2065                         pr_err("%s: fail to change mode!!!\n", __func__);
2066
2067                 if (usb_mode == USB_OTGHOST_DETACHED)
2068                         otg_data->set_pwr_cb(0);
2069
2070 #ifdef CONFIG_JACK_MON
2071                 if (usb_mode == USB_OTGHOST_ATTACHED)
2072                         jack_event_handler("host", USB_CABLE_ATTACHED);
2073                 else if (usb_mode == USB_OTGHOST_DETACHED)
2074                         jack_event_handler("host", USB_CABLE_DETACHED);
2075                 else if ((usb_mode == USB_CABLE_ATTACHED)
2076                                 || (usb_mode == USB_CABLE_DETACHED))
2077                         jack_event_handler("usb", usb_mode);
2078 #endif
2079         }
2080 }
2081
2082
2083 /* I2C3: TSP */
2084
2085 #if defined(CONFIG_TOUCHSCREEN_MELFAS)
2086 static int melfas_power(int on)
2087 {
2088         int gpio = 0;
2089
2090         if (on) {
2091                 gpio = MOBILE_GPIO(TSP_LDO_ON);
2092                 gpio_request(gpio, "TSP_LDO_ON");
2093                 s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
2094                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
2095                 gpio_set_value(gpio, GPIO_LEVEL_HIGH);
2096
2097                 mdelay(70);
2098                 gpio = MOBILE_GPIO(TSP_INT);
2099                 gpio_request(gpio, "TSP_INT");
2100                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
2101                 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
2102 /*
2103         regulator = regulator_get(NULL, "touch");
2104                 if (IS_ERR(regulator))
2105                         return 0;
2106                 regulator_enable(regulator);
2107                 regulator_put(regulator);
2108 */
2109                 printk(KERN_INFO "[TSP]melfas power on\n");
2110                 return 1;
2111         } else {
2112                 gpio = MOBILE_GPIO(TSP_INT);
2113                 gpio_request(gpio, "TSP_INT");
2114                 s3c_gpio_cfgpin(gpio, S3C_GPIO_INPUT);
2115                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
2116
2117                 gpio = MOBILE_GPIO(TSP_LDO_ON);
2118                 gpio_request(gpio, "TSP_LDO_ON");
2119                 s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
2120                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
2121                 gpio_set_value(gpio, GPIO_LEVEL_LOW);
2122 /*
2123                 regulator = regulator_get(NULL, "touch");
2124                 if (IS_ERR(regulator))
2125                         return 0;
2126                 if (regulator_is_enabled(regulator))
2127                         regulator_force_disable(regulator);
2128                 regulator_put(regulator);
2129 */
2130                 return 1;
2131         }
2132 }
2133
2134 static int __init melfas_change_pin(int value)
2135 {
2136         int gpio;
2137
2138         if (value) {
2139                 gpio = MOBILE_GPIO(TSP_SDA);
2140                 gpio_request(gpio, "TSP_SDA");
2141                 s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
2142                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
2143
2144                 gpio = MOBILE_GPIO(TSP_SCL);
2145                 gpio_request(gpio, "TSP_SCL");
2146                 s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
2147                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
2148         } else {
2149                 gpio = MOBILE_GPIO(TSP_SDA);
2150                 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0x3));
2151                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
2152                 gpio_free(gpio);
2153
2154                 gpio = MOBILE_GPIO(TSP_SCL);
2155                 s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0x3));
2156                 s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
2157                 gpio_free(gpio);
2158         }
2159         return 1;
2160 }
2161
2162 static struct melfas_tsi_platform_data melfas_pdata = {
2163         .x_size = 720,
2164         .y_size = 1280,
2165         .power = melfas_power,
2166
2167         /* For the faster user response */
2168         .input_event            = user_input_response,
2169         .change_pin = melfas_change_pin,
2170 };
2171 #endif
2172
2173 static struct i2c_board_info i2c3_devs[] __initdata = {
2174         {
2175 #ifdef CONFIG_TOUCHSCREEN_MELFAS
2176                 I2C_BOARD_INFO(MELFAS_TS_NAME, 0x48),
2177                 .platform_data = &melfas_pdata,
2178 #endif
2179         },
2180
2181 };
2182
2183 static void u1hd_power_off(void)
2184 {
2185         char rst_mode = 'r';
2186         char *str_ptr = "reset\n";
2187         int poweroff_try = 0;
2188         int gpio;
2189
2190         printk(KERN_INFO "%s: u1hd power off\n", __func__);
2191         while (1) {
2192                 /* Check reboot charging */
2193                 if (is_cable_attached || (poweroff_try >= 5)) {
2194                 printk(KERN_INFO
2195                         "%s: charger connected(%d) or power off failed(%d), reboot!\n",
2196                                 __func__, is_cable_attached, poweroff_try);
2197
2198                         flush_cache_all();
2199                         outer_flush_all();
2200                         arm_machine_restart(rst_mode, str_ptr);
2201 //                        arch_reset(0, 0);
2202
2203                         printk(KERN_INFO "%s: waiting for reboot.\n", __func__);
2204                         while (1);
2205                 }
2206
2207                 /* wait for power button release */
2208                 gpio = MOBILE_GPIO(nPOWER);
2209                 gpio_request(gpio, "nPOWER");
2210                 if (gpio_get_value(gpio)) {
2211                         printk(KERN_INFO "%s: set PS_HOLD low.\n", __func__);
2212                         /* power off code
2213                          * PS_HOLD Out/High -->
2214                          * Low PS_HOLD_CONTROL, R/W, 0x1002_330C
2215                          */
2216                         writel(readl(S5P_PS_HOLD_CONTROL) & 0xFFFFFEFF,
2217                                 S5P_PS_HOLD_CONTROL);
2218
2219                         ++poweroff_try;
2220
2221                         /* when connected zig cable with power, we can't make PS_HOLD_CONTROL low.
2222                          * we try power_off 5 times. then if it failed, do restart.
2223                          */
2224                         printk(KERN_INFO
2225                                 "%s: Should not reach here! (poweroff_try:%d)\n",
2226                                 __func__, poweroff_try);
2227                 }
2228
2229                 /* if power button is not released, wait and check TA again */
2230                 printk(KERN_INFO "%s: PowerButton is not released!.\n",
2231                         __func__);
2232                 mdelay(1000);
2233         }
2234 }
2235
2236 static void __init u1hd_tsp_init(void)
2237 {
2238         int gpio;
2239
2240 #if 1
2241         /* TSP_LDO_ON: XGNSS_QSIGN */
2242         gpio = MOBILE_GPIO(TSP_LDO_ON);
2243         gpio_request(gpio, "TSP_LDO_ON");
2244         gpio_direction_output(gpio, 1);
2245         gpio_export(gpio, 0);
2246
2247         /* TSP_INT: XEINT[4] */
2248         gpio = MOBILE_GPIO(TSP_INT);
2249         gpio_request(gpio, "TSP_INT");
2250         s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
2251
2252 #endif
2253         /*
2254          * Note that because TSP_LDO provides an external pull-up to TSP_INT,
2255          * the pull-up setting at GPE1(7) is useless and may be omitted in
2256          * order to reduce idle current. However, it probably needs some
2257          * sleep/delay from TSP_LDO_ON = true event because there could be
2258          * "ramp-up" delay. Before knowing this, let's just use PULL_UP here.
2259          */
2260         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
2261         i2c3_devs[0].irq = gpio_to_irq(gpio);
2262
2263 }
2264
2265 extern void MHL_On(bool on);
2266 static void max8997_muic_mhl_cb(int attached)
2267 {
2268         pr_info("%s(%d)\n", __func__, attached);
2269
2270         if (attached == MAX8997_MUIC_ATTACHED) {
2271                 MHL_On(1);
2272         } else {
2273                 MHL_On(0);
2274         }
2275
2276 #ifdef CONFIG_JACK_MON
2277         jack_event_handler("hdmi", attached);
2278 #endif
2279 }
2280
2281 static bool max8997_muic_is_mhl_attached(void)
2282 {
2283         int val;
2284         int gpio;
2285
2286         gpio = MOBILE_GPIO(MHL_SEL);
2287         gpio_request(gpio, "MHL_SEL");
2288         val = gpio_get_value(gpio);
2289         gpio_free(gpio);
2290
2291         return !!val;
2292 }
2293
2294 static int u1hd_set_safeout(int path)
2295 {
2296         static struct regulator *regulator_vbus_cp;
2297         static bool cp_enabled;
2298         int ret = 0;
2299
2300         mutex_lock(&usb_ap_lock);
2301
2302         if (regulator_vbus_ap == NULL)
2303                 regulator_vbus_ap =
2304                     regulator_get_exclusive(NULL, "usb_vbus_ap_5v");
2305         if (IS_ERR_OR_NULL(regulator_vbus_ap)) {
2306                 ret = -ENODEV;
2307                 regulator_vbus_ap = NULL;
2308                 goto out;
2309         }
2310
2311         if (regulator_vbus_cp == NULL)
2312                 regulator_vbus_cp =
2313                     regulator_get_exclusive(NULL, "usb_vbus_cp_5v");
2314         if (IS_ERR_OR_NULL(regulator_vbus_cp)) {
2315                 ret = -ENODEV;
2316                 regulator_vbus_cp = NULL;
2317                 goto out;
2318         }
2319
2320         if (path == CP_USB_MODE) {
2321                 if (ap_enabled) {
2322                         ret = regulator_disable(regulator_vbus_ap);
2323                         if (ret)
2324                                 goto out;
2325                         ap_enabled = false;
2326                 }
2327
2328                 if (!cp_enabled) {
2329                         if (!regulator_is_enabled(regulator_vbus_cp))
2330                                 ret = regulator_enable(regulator_vbus_cp);
2331                         if (ret)
2332                                 goto out;
2333                         cp_enabled = true;
2334                 }
2335         } else {
2336                 /* AP_USB_MODE || AUDIO_MODE */
2337                 if (!ap_enabled) {
2338                         if (!regulator_is_enabled(regulator_vbus_ap))
2339                                 ret = regulator_enable(regulator_vbus_ap);
2340                         if (ret)
2341                                 goto out;
2342                         ap_enabled = true;
2343                 }
2344
2345                 if (cp_enabled) {
2346                         ret = regulator_disable(regulator_vbus_cp);
2347                         if (ret)
2348                                 goto out;
2349                         cp_enabled = false;
2350                 }
2351         }
2352 out:
2353         mutex_unlock(&usb_ap_lock);
2354         return ret;
2355 }
2356
2357 static struct switch_dev switch_dock = {
2358         .name = "dock",
2359 };
2360
2361 static const char *switch_cable_names[] = {
2362         "TA",
2363         "USB",
2364         NULL,
2365 };
2366
2367 static struct switch_dev switch_usb = {
2368         .name = "switch-usb",
2369         .supported_cable = switch_cable_names,
2370 };
2371
2372 static void u1hd_deskdock_cb(bool attached)
2373 {
2374         if (attached)
2375                 switch_set_state(&switch_dock, 1);
2376         else
2377                 switch_set_state(&switch_dock, 0);
2378 }
2379
2380 static void u1hd_cardock_cb(bool attached)
2381 {
2382         if (attached)
2383                 switch_set_state(&switch_dock, 2);
2384         else
2385                 switch_set_state(&switch_dock, 0);
2386 }
2387
2388 static void u1hd_switch_dev_init(void)
2389 {
2390         int ret;
2391
2392         /* for CarDock, DeskDock */
2393         ret = switch_dev_register(&switch_dock);
2394         if (ret < 0)
2395                 pr_err("Failed to register dock switch. %d\n", ret);
2396
2397         ret = switch_dev_register(&switch_usb);
2398         if (ret < 0)
2399                 pr_err("Failed to register switch-usb. %d\n", ret);
2400 }
2401
2402 static int u1hd_host_notify_cb(int enable)
2403 {
2404         struct host_notify_dev * ndev = NULL;
2405
2406         if (s3c_device_usbgadget.dev.platform_data)
2407                 ndev = s3c_device_usbgadget.dev.platform_data;
2408         else {
2409                 pr_err("%s: ndev is null.\n", __func__);
2410                 return -1;
2411         }
2412
2413         ndev->booster = enable ? NOTIFY_POWER_ON : NOTIFY_POWER_OFF;
2414         pr_info("%s: mode %d, enable %d\n", __func__, ndev->mode, enable);
2415         return ndev->mode;
2416 }
2417
2418 struct max8997_muic_platform_data u1hd_muic_pdata = {
2419         .usb_cb = u1hd_usb_cb,
2420         .charger_cb = u1hd_charger_cb, /* done */
2421         .mhl_cb = max8997_muic_mhl_cb, /* done */
2422         .is_mhl_attached = max8997_muic_is_mhl_attached, /* done */
2423         .set_safeout = u1hd_set_safeout, /* done */
2424         .deskdock_cb = u1hd_deskdock_cb, /* done */
2425         .cardock_cb = u1hd_cardock_cb, /* done */
2426         .host_notify_cb = u1hd_host_notify_cb, /* done */
2427         .gpio_usb_sel = S5PV310_GPL0(6),        /* done */
2428         .uart_path = -1,        /* muic does not control uart path*/
2429 };
2430
2431 static void u1hd_set_usb_switch(int path)
2432 {
2433         printk(KERN_INFO "set_usb_switch = [%d]\n",path);
2434         u1hd_muic_pdata.sw_path = path;
2435 }
2436
2437 static int u1hd_get_usb_switch(void)
2438 {
2439         printk(KERN_INFO "get_usb_switch = [%d]\n",u1hd_muic_pdata.sw_path);
2440         return u1hd_muic_pdata.sw_path;
2441 }
2442
2443 /* Micro USB Switch */
2444 static struct micro_usb_switch_platform_data u1hd_usb_switch_data = {
2445         .set_usb_switch         = u1hd_set_usb_switch,
2446         .get_usb_switch         = u1hd_get_usb_switch,
2447 };
2448
2449 static struct platform_device u1hd_micro_usb_switch = {
2450         .name                   = "usb-switch",
2451         .id                     = -1,
2452         .dev                    = {
2453                 .platform_data  = &u1hd_usb_switch_data,
2454         },
2455 };
2456
2457 static void u1hd_pm_finish(void)
2458 {
2459         /* Restore GPX conf */
2460         s3c_pm_do_restore(s5pc210_gpx, ARRAY_SIZE(s5pc210_gpx));
2461 }
2462
2463 static void u1hd_pm_prepare(void)
2464 {
2465         /* 1. Save GPX conf */
2466         s3c_pm_do_save(s5pc210_gpx, ARRAY_SIZE(s5pc210_gpx));
2467
2468         /* 2. Set GPX as Power Save Mode */
2469
2470         /* 3. Debug: Look at the diff */
2471         mobile_gpios_groupx_difference();
2472
2473 }
2474
2475 int u1hd_common_setup_clock(const char *sclk_name, const char *pclk_name,
2476                 unsigned long rate, unsigned int rate_set)
2477 {
2478         struct clk *sclk = NULL;
2479         struct clk *pclk = NULL;
2480
2481         sclk = clk_get(NULL, sclk_name);
2482         if (IS_ERR(sclk)) {
2483                 printk(KERN_ERR "failed to get %s clock.\n", sclk_name);
2484                 goto err_clk;
2485         }
2486
2487         pclk = clk_get(NULL, pclk_name);
2488         if (IS_ERR(pclk)) {
2489                 printk(KERN_ERR "failed to get %s clock.\n", pclk_name);
2490                 goto err_clk;
2491         }
2492
2493         clk_set_parent(sclk, pclk);
2494
2495         printk(KERN_INFO "set parent clock of %s to %s\n", sclk_name,
2496                         pclk_name);
2497         if (!rate_set)
2498                 goto set_end;
2499
2500         if (!rate)
2501                 rate = 200 * MHZ;
2502
2503         clk_set_rate(sclk, rate);
2504         printk(KERN_INFO "set %s rate to %lu\n", sclk_name, rate);
2505
2506 set_end:
2507         clk_put(sclk);
2508         clk_put(pclk);
2509
2510         return 0;
2511
2512 err_clk:
2513         clk_put(sclk);
2514         clk_put(pclk);
2515
2516         return -EINVAL;
2517
2518 }
2519
2520 #ifdef CONFIG_S5PV310_DEV_PD
2521 static inline void powerdomain_boot_on(int pd)
2522 {
2523         struct samsung_pd_info *pdinfo = (struct samsung_pd_info *)
2524                 s5pv310_device_pd[pd].dev.platform_data;
2525         pdinfo->boot_on = true;
2526 }
2527 #endif
2528
2529 #ifdef CONFIG_INPUT_SECBRIDGE
2530 //============================================================
2531 /* sec-input-bridge */
2532 //============================================================
2533 static const struct sec_input_bridge_mkey u1hd_rbdump_mkey_map[] = {
2534         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2535         { .type = EV_KEY , .code = KEY_VOLUMEDOWN               },
2536         { .type = EV_KEY , .code = KEY_MENU                             },
2537         { .type = EV_KEY , .code = KEY_MENU                             },
2538         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2539         { .type = EV_KEY , .code = KEY_VOLUMEDOWN               },
2540         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2541         { .type = EV_KEY , .code = KEY_MENU                             },
2542 };
2543
2544 static const struct sec_input_bridge_mkey u1hd_default_mkey_map[] = {
2545         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2546         { .type = EV_KEY , .code = KEY_VOLUMEDOWN               },
2547         { .type = EV_KEY , .code = KEY_MENU                             },
2548         { .type = EV_KEY , .code = KEY_MENU                             },
2549         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2550         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2551         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2552         { .type = EV_KEY , .code = KEY_MENU                             },
2553 };
2554
2555 static const struct sec_input_bridge_mkey u1hd_uart_mkey_map[] = {
2556         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2557         { .type = EV_KEY , .code = KEY_VOLUMEDOWN               },
2558         { .type = EV_KEY , .code = KEY_MENU                             },
2559         { .type = EV_KEY , .code = KEY_MENU                             },
2560         { .type = EV_KEY , .code = KEY_VOLUMEUP                 },
2561         { .type = EV_KEY , .code = KEY_MENU                             },
2562         { .type = EV_KEY , .code = KEY_VOLUMEDOWN               },
2563         { .type = EV_KEY , .code = KEY_MENU                             },
2564 };
2565
2566 static void mkey_uart_path_change (void *event_data)
2567 {
2568         if (u1hd_get_uart_switch() == UART_SW_PATH_CP)
2569                 u1hd_set_uart_switch(UART_SW_PATH_AP);
2570         else
2571                 u1hd_set_uart_switch(UART_SW_PATH_CP);
2572 }
2573
2574 static const struct sec_input_bridge_mmap u1hd_mmap[] = {
2575         {
2576                 .mkey_map = u1hd_rbdump_mkey_map,
2577                 .num_mkey = ARRAY_SIZE(u1hd_rbdump_mkey_map),
2578                 .uevent_env_str = "RB_DUMP",
2579                 .enable_uevent = 1,
2580                 .uevent_action = KOBJ_CHANGE,
2581                 .uevent_env_str = "RB_DUMP",
2582                 .uevent_env_value = "ON",
2583         },
2584         {
2585                 .mkey_map = u1hd_default_mkey_map,
2586                 .num_mkey = ARRAY_SIZE(u1hd_default_mkey_map),
2587                 .uevent_env_str = "DEFAULT",
2588                 .enable_uevent = 1,
2589                 .uevent_action = KOBJ_CHANGE,
2590                 .uevent_env_str = "DEFAULT",
2591                 .uevent_env_value = "ON",
2592         },
2593         {
2594                 .mkey_map = u1hd_uart_mkey_map,
2595                 .num_mkey = ARRAY_SIZE(u1hd_uart_mkey_map),
2596                 .uevent_env_str = "UART_SW",
2597                 .enable_uevent = 0,
2598                 .uevent_action = KOBJ_CHANGE,
2599                 .uevent_env_str = "DEFAULT",
2600                 .uevent_env_value = "ON",
2601                 .pre_event_func = mkey_uart_path_change,
2602         },
2603 };
2604
2605 static struct sec_input_bridge_platform_data u1hd_input_bridge_data = {
2606         .mmap = u1hd_mmap,
2607         .num_map = ARRAY_SIZE(u1hd_mmap),
2608 };
2609
2610 static struct platform_device u1hd_input_bridge = {
2611         .name   = "samsung_input_bridge",
2612         .id             = -1,
2613         .dev    = {
2614                 .platform_data = &u1hd_input_bridge_data,
2615         },
2616 };
2617 #endif
2618
2619 #ifdef CONFIG_CHARGERCTRL_MAX8922
2620 #define GPIO_CHG_EN             S5PV310_GPL2(2)
2621 #define GPIO_CHG_ING_N          S5PV310_GPL2(4)
2622 #define GPIO_TA_nCONNECTED      S5PV310_GPL2(5)
2623
2624 static int max8922_cfg_gpio(void)
2625 {
2626         s3c_gpio_cfgpin(GPIO_CHG_EN, S3C_GPIO_OUTPUT);
2627         s3c_gpio_setpull(GPIO_CHG_EN, S3C_GPIO_PULL_NONE);
2628         gpio_set_value(GPIO_CHG_EN, GPIO_LEVEL_LOW);
2629
2630         s3c_gpio_cfgpin(GPIO_CHG_ING_N, S3C_GPIO_INPUT);
2631         s3c_gpio_setpull(GPIO_CHG_ING_N, S3C_GPIO_PULL_NONE);
2632
2633         s3c_gpio_cfgpin(GPIO_TA_nCONNECTED, S3C_GPIO_INPUT);
2634         s3c_gpio_setpull(GPIO_TA_nCONNECTED, S3C_GPIO_PULL_NONE);
2635
2636         return 0;
2637 }
2638
2639 static int u1hd_charger_topoff_cb(void)
2640 {
2641         struct power_supply *psy = power_supply_get_by_name("battery");
2642         union power_supply_propval value;
2643
2644         if (!psy) {
2645                 pr_err("%s: fail to get battery ps\n", __func__);
2646                 return -ENODEV;
2647         }
2648
2649         value.intval = POWER_SUPPLY_STATUS_FULL;
2650         return psy->set_property(psy, POWER_SUPPLY_PROP_STATUS, &value);
2651 }
2652
2653 static struct regulator_consumer_supply supplies_max8922[] = {
2654         REGULATOR_SUPPLY("vinchg2", "charger-manager.0"),
2655         REGULATOR_SUPPLY("vinchg2_mach", NULL),
2656 };
2657
2658 static struct regulator_init_data max8922_charger_en_data = {
2659         .constraints = {
2660                 .name           = "MAX8922_CHARGER",
2661                 .min_uA = 395000,
2662                 .max_uA = 650000,
2663                 .valid_ops_mask = REGULATOR_CHANGE_STATUS |
2664                                 REGULATOR_CHANGE_CURRENT,
2665         },
2666         .num_consumer_supplies = ARRAY_SIZE(supplies_max8922),
2667         .consumer_supplies = supplies_max8922,
2668 };
2669 static struct max8922_platform_data max8922_pdata = {
2670         .topoff_cb = u1hd_charger_topoff_cb,
2671         .cfg_gpio = max8922_cfg_gpio,
2672         .gpio_chg_en = GPIO_CHG_EN,
2673         .gpio_chg_ing = GPIO_CHG_ING_N,
2674         .gpio_ta_nconnected = GPIO_TA_nCONNECTED,
2675         .init_data = &max8922_charger_en_data,
2676 };
2677
2678 static struct platform_device max8922_device_charger = {
2679         .name = "max8922-charger",
2680         .id = 0,
2681         .dev.platform_data = &max8922_pdata,
2682 };
2683 #endif /* CONFIG_MAX8922_CHARGER */
2684
2685 struct led_max8997_platform_data u1hd_led_max8997_platform_data = {
2686         .name = "leds-torch",
2687         .brightness = 0,
2688 };
2689
2690 struct platform_device u1hd_device_leds_max8997 = {
2691         .name   = "leds-max8997",
2692         .id     = -1,
2693         .dev = { .platform_data = &u1hd_led_max8997_platform_data},
2694 };
2695
2696 #ifdef CONFIG_CHARGER_MANAGER
2697 extern struct platform_device u1hd_charger_manager;
2698 extern struct platform_device u1hd_ncp15wb473_thermistor;
2699 extern struct charger_global_desc u1hd_charger_g_desc;
2700 #endif
2701
2702 static struct platform_device *u1hd_devices[] __initdata = {
2703         /* Samsung Platform Devices */
2704 #ifdef CONFIG_S5PV310_DEV_PD
2705         &s5pv310_device_pd[PD_MFC],
2706         &s5pv310_device_pd[PD_G3D],
2707         &s5pv310_device_pd[PD_LCD0],
2708         &s5pv310_device_pd[PD_LCD1],
2709         &s5pv310_device_pd[PD_TV],
2710         &s5pv310_device_pd[PD_CAM],
2711         &s5pv310_device_pd[PD_GPS],
2712 #endif
2713 #ifdef CONFIG_DRM_MALI
2714         &s5p_device_mali_drm,
2715 #endif
2716 #ifdef CONFIG_DRM_FIMD
2717         &s5p_device_fimd_drm,
2718 #endif
2719         &s3c_device_i2c0,
2720         &s3c_device_i2c1,
2721         &s3c_device_i2c3,
2722         &s3c_device_i2c5,
2723         &s3c_device_i2c6,
2724         &s3c_device_i2c7,
2725         &s3c_device_i2c8,
2726         &i2c9_gpio,
2727         &i2c12_gpio,
2728         &i2c14_gpio,
2729         &i2c15_gpio,
2730         &i2c16_gpio,
2731         &s3c_device_i2c17,
2732         &i2c18_gpio,
2733
2734         &s3c_device_timer[0],
2735         &s3c_device_timer[1],
2736
2737 #ifdef CONFIG_S3C_DEV_RTC
2738         &s3c_device_rtc,
2739 #endif
2740         &ps_on_led_a_fixed_reg_dev,
2741 #ifdef CONFIG_CHARGERCTRL_MAX8922
2742         &max8922_device_charger,
2743 #endif
2744
2745 #ifdef CONFIG_VIDEO_FIMC_MIPI
2746         &s3c_device_csis0,
2747         &s3c_device_csis1,
2748 #endif
2749 #ifdef CONFIG_VIDEO_FIMC
2750         &s3c_device_fimc0,
2751         &s3c_device_fimc1,
2752         &s3c_device_fimc2,
2753         &s3c_device_fimc3,
2754 #endif
2755
2756 #ifdef CONFIG_VIDEO_JPEG
2757         &s5p_device_jpeg,
2758 #endif
2759
2760         &u1hd_gpio_keys,
2761
2762 #ifdef CONFIG_USB_GADGET
2763         &s3c_device_usbgadget,
2764 #endif
2765 #ifdef CONFIG_USB_ANDROID_RNDIS
2766        &s3c_device_rndis,
2767 #endif
2768 #ifdef CONFIG_USB_ANDROID_ECM
2769        &s3c_device_ecm,
2770 #endif
2771 #ifdef CONFIG_USB_ANDROID
2772     &s3c_device_android_usb,
2773     &s3c_device_usb_mass_storage,
2774 #endif
2775 #ifdef CONFIG_USB_S3C_OTG_HOST
2776         &s3c_device_usb_otghcd,
2777 #endif
2778 #ifdef CONFIG_S3C_DEV_HSMMC4
2779         &s3c_device_hsmmc4,
2780 #else
2781         &s3c_device_hsmmc0,
2782 #endif
2783         &emmc_fixed_voltage,
2784         &s3c_device_hsmmc2,
2785         &s3c_device_hsmmc3,
2786
2787         &u1hd_uart_select,
2788         &s3c_device_adc,
2789
2790 #ifdef CONFIG_SND_S3C64XX_SOC_I2S_V4
2791         &s5pv310_device_iis0,
2792 #endif
2793 #ifdef CONFIG_SND_S3C_SOC_PCM
2794         &s5pv310_device_pcm1,
2795 #endif
2796 #ifdef CONFIG_SND_SOC_SMDK_WM9713
2797         &s5pv310_device_ac97,
2798 #endif
2799 #ifdef CONFIG_SND_SAMSUNG_SOC_SPDIF
2800         &s5pv310_device_spdif,
2801 #endif
2802 #ifdef CONFIG_SND_S5P_RP
2803         &s5pv310_device_rp,
2804 #endif
2805
2806         &u1hd_jack,
2807         &fmradio_fixed_voltage,
2808         &s5pv310_bcm4330,
2809 #ifdef CONFIG_GSD4T
2810         &u1hd_gsd4t,
2811 #endif
2812         &u1hd_ramoops,
2813         &u1hd_micro_usb_switch,
2814
2815 #ifdef CONFIG_S3C2410_WATCHDOG
2816         &s3c_device_wdt,
2817 #endif
2818
2819 #ifdef CONFIG_S5P_SYSMMU
2820         &s5p_device_sysmmu[SYSMMU_G2D],
2821         &s5p_device_sysmmu[SYSMMU_MFC_L],
2822         &s5p_device_sysmmu[SYSMMU_MFC_R],
2823         &s5p_device_sysmmu[SYSMMU_FIMC0],
2824         &s5p_device_sysmmu[SYSMMU_FIMC1],
2825         &s5p_device_sysmmu[SYSMMU_FIMC2],
2826         &s5p_device_sysmmu[SYSMMU_FIMC3],
2827 #endif
2828 #ifdef CONFIG_VIDEO_FIMG2D
2829         &s5p_device_fimg2d,
2830 #endif
2831 #if defined(CONFIG_VIDEO_MFC5X) || defined(CONFIG_VIDEO_SAMSUNG_S5P_MFC)
2832         &s5p_device_mfc,
2833 #endif
2834 #ifdef CONFIG_VIDEO_SAMSUNG_S5P_TV
2835         &s5p_device_hdmi,
2836         &s5p_device_mixer,
2837 #endif
2838 #ifdef CONFIG_FB_S3C
2839         &s3c_device_fb,
2840 #endif
2841 #ifdef CONFIG_ANDROID_RAM_CONSOLE
2842         &ram_console_device,
2843 #endif
2844         &u1hd_tzpc,
2845         &u1hd_device_leds_max8997,
2846
2847 #ifdef CONFIG_CHARGER_MANAGER
2848         /* Should be placed after fuel gauge, charger control chips, pmics */
2849         &u1hd_ncp15wb473_thermistor,
2850         &u1hd_charger_manager,
2851 #endif
2852 #ifdef CONFIG_INPUT_SECBRIDGE
2853         &u1hd_input_bridge,
2854 #endif
2855 #ifdef CONFIG_SAMSUNG_BOOT_MODE
2856         &s3c_device_samsung_boot_mode,
2857 #endif
2858 #ifdef CONFIG_SEC_DEBUG
2859         &s3c_device_getlog,
2860 #endif
2861 #ifdef CONFIG_S5PV310_STOPWATCH
2862         &s5pv310_device_stopwatch,
2863 #endif
2864 #ifdef CONFIG_DEV_THERMAL
2865         &s5p_device_tmu,
2866 #endif
2867         &u1hd_xmm6260,
2868         &u1hd_modem_net,
2869         &s5p_device_usb_ehci,
2870 #ifdef CONFIG_INPUT_GP2A
2871         &opt_gp2a,
2872 #endif
2873 };
2874
2875 extern void (*s5p_inform6_set)(char mode);
2876 extern void s5pv310_inform6_set(char mode);
2877 extern struct machine_desc *lookup_machine_type(unsigned int);
2878
2879 static void __init u1hd_machine_init(void)
2880 {
2881         int gpio;
2882         struct machine_desc *list;
2883         list = lookup_machine_type(machine_arch_type);
2884         strcpy(utsname()->nodename, list->name);
2885
2886         /* to support system shut down */
2887         pm_power_off = u1hd_power_off;
2888
2889         /* to support inform6 set */
2890         s5p_inform6_set = s5pv310_inform6_set;
2891
2892         /* Initialize GPIO default setting */
2893         mobile_gpios_init();
2894         s3c_config_sleep_gpio_table = u1hd_config_sleep_gpio_table;
2895
2896         u1hd_switch_dev_init();
2897
2898         s3c_i2c0_set_platdata(&u1hd_i2c0_platdata);
2899
2900         u1hd_sensor_init();
2901         s3c_i2c1_set_platdata(NULL);
2902
2903         i2c_register_board_info(1, i2c1_devs, ARRAY_SIZE(i2c1_devs));
2904
2905         u1hd_tsp_init();
2906         s3c_i2c3_set_platdata(NULL);
2907         i2c_register_board_info(3, i2c3_devs, ARRAY_SIZE(i2c3_devs));
2908
2909 #ifdef CONFIG_S5PV310_DEV_PD
2910         s5pv310_device_pd[PD_CAM].dev.parent = &s5pv310_device_pd[PD_LCD0].dev;
2911 #ifdef CONFIG_FB_S3C
2912         s3c_device_fb.dev.parent = &s5pv310_device_pd[PD_LCD0].dev;
2913         powerdomain_boot_on(PD_LCD0);
2914 #endif
2915 #endif
2916         u1hd_fb_init();
2917
2918 /* YUBAEK 20110905 RAMDUMP_DEBUG : GPIO Dump ++ */
2919 #ifdef CONFIG_SEC_DEBUG_PERIPHERAL_DUMP_GPIO
2920         s5pv310_gpio_io_map();
2921 #endif
2922 /* YUBAEK 20110905 RAMDUMP_DEBUG : GPIO Dump ++ */
2923
2924
2925 #ifdef CONFIG_S5PV310_DEV_PD
2926 #if defined(CONFIG_VIDEO_MFC5X) || defined(CONFIG_VIDEO_SAMSUNG_S5P_MFC)
2927         s5p_device_mfc.dev.parent = &s5pv310_device_pd[PD_MFC].dev;
2928         u1hd_common_setup_clock("mout_mfc0", "mout_mpll", 0, 0);
2929         u1hd_common_setup_clock("sclk_mfc", "mout_mfc0", 200 * MHZ, 1);
2930 #endif
2931 #endif
2932
2933         u1hd_pmic_init();       /* TODO: should be modify for U1 */
2934         s3c_i2c5_set_platdata(NULL);
2935         i2c5_devs[I2C5_MAX8997].irq = gpio_to_irq(S5PV310_GPX0(7)),
2936         i2c_register_board_info(5, i2c5_devs, ARRAY_SIZE(i2c5_devs));
2937
2938         u1hd_sound_init();
2939         s3c_i2c6_set_platdata(NULL);
2940         i2c_register_board_info(6, i2c6_devs, ARRAY_SIZE(i2c6_devs));
2941
2942         s3c_i2c7_set_platdata(NULL);
2943         i2c_register_board_info(7, i2c7_devs, ARRAY_SIZE(i2c7_devs));
2944
2945         s3c_i2c8_set_platdata(&i2c_data8);
2946
2947         gpio = S5PV310_GPX2(3);
2948         gpio_request(gpio, "FUEL_ALERT");
2949         s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
2950         s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
2951         i2c9_devs[I2C9_MAX17042].irq = gpio_to_irq(gpio);
2952         i2c_register_board_info(9, i2c9_devs, ARRAY_SIZE(i2c9_devs));
2953
2954         universal_touchkey_init();
2955         i2c_register_board_info(12, i2c12_devs_cypress, ARRAY_SIZE(i2c12_devs_cypress));
2956
2957         i2c_register_board_info(14, i2c14_devs, ARRAY_SIZE(i2c14_devs));
2958
2959         i2c_register_board_info(15, i2c15_devs, ARRAY_SIZE(i2c15_devs));
2960
2961         /* NFC sensor */
2962         u1hd_nfc_setup_gpio();
2963         i2c_register_board_info(16, i2c16_devs, ARRAY_SIZE(i2c16_devs));
2964 /*
2965 #if defined(CONFIG_VIDEO_S5K5BAFX)
2966         i2c_register_board_info(17, i2c17_devs, ARRAY_SIZE(i2c17_devs));
2967 #endif
2968 */
2969         i2c_register_board_info(18, i2c18_devs, ARRAY_SIZE(i2c18_devs));
2970
2971         u1hd_usb_ehci_init();
2972
2973         u1hd_usb_otg_init();
2974
2975         s3c_usb_set_serial();
2976
2977         u1hd_modem_init();
2978
2979 #ifdef CONFIG_VIDEO_FIMG2D
2980         s5p_fimg2d_set_platdata(&fimg2d_data);
2981 #ifdef CONFIG_S5PV310_DEV_PD
2982         s5p_device_fimg2d.dev.parent = &s5pv310_device_pd[PD_LCD0].dev;
2983 #endif
2984 #endif
2985
2986 #ifdef CONFIG_PM
2987         pm_cpu_prepare = u1hd_pm_prepare;
2988         pm_cpu_finish = u1hd_pm_finish;
2989
2990         s3c_pm_init();
2991         s3c_irq_wake(IRQ_RTC_ALARM, 1);
2992 #endif
2993
2994 #if defined(CONFIG_S5PV310_DEV_PD) && !defined(CONFIG_PM_RUNTIME)
2995         /*
2996          * These power domains should be always on
2997          * without runtime pm support.
2998          */
2999         s5pv310_pd_enable(&s5pv310_device_pd[PD_MFC].dev);
3000         s5pv310_pd_enable(&s5pv310_device_pd[PD_G3D].dev);
3001         s5pv310_pd_enable(&s5pv310_device_pd[PD_LCD0].dev);
3002         s5pv310_pd_enable(&s5pv310_device_pd[PD_LCD1].dev);
3003         s5pv310_pd_enable(&s5pv310_device_pd[PD_CAM].dev);
3004         s5pv310_pd_enable(&s5pv310_device_pd[PD_TV].dev);
3005         s5pv310_pd_enable(&s5pv310_device_pd[PD_GPS].dev);
3006 #endif
3007
3008 #ifdef CONFIG_VIDEO_FIMG2D
3009         /* setup fimg2d parent clock. */
3010         universal_fimg2d_setup_clock("mout_g2d0", "mout_mpll");
3011 #endif
3012
3013         s5pv310_sdhci_init();
3014 #ifdef CONFIG_S5P_ADC
3015         u1hd_adc_init();
3016 #endif
3017
3018 #ifdef CONFIG_DEV_THERMAL
3019         s5p_tmu_set_platdata(NULL);
3020 #endif
3021
3022         s5pv310_camera_init();
3023
3024         /* Last */
3025         platform_add_devices(u1hd_devices, ARRAY_SIZE(u1hd_devices));
3026
3027         regulator_has_full_constraints();
3028 /* Temp. commented */
3029 #if 0
3030         if (s5pv310_subrev() != 0) {
3031                 pr_emerg("\n\n This kernel does NOT support subrevision %d of S5PC210.\n\n\n",
3032                         s5pv310_subrev());
3033                 panic("Not supported subrevision");
3034         }
3035 #endif
3036 }
3037
3038 MACHINE_START(U1HD_C210, "U1HD")
3039         /* Maintainer: mhban <mhban@samsung.com> */
3040         .phys_io        = S3C_PA_UART & 0xfff00000,
3041         .io_pg_offst    = (((u32)S3C_VA_UART) >> 18) & 0xfffc,
3042         .boot_params    = S5P_PA_SDRAM + 0x100,
3043         .init_irq       = s5pv310_init_irq,
3044         .map_io         = u1hd_map_io,
3045         .init_machine   = u1hd_machine_init,
3046         .timer          = &s5pv310_timer,
3047         .reserve        = &s5pv310_reserve,
3048 MACHINE_END