upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-s5pv310 / board-camera.c
1 /*
2  * linux/arch/arm/mach-s5pv310/board-camera.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/err.h>
13 #include <linux/regulator/machine.h>
14 #include <linux/delay.h>
15 #include <linux/i2c.h>
16
17 #include <mach/gpio.h>
18
19 #include <plat/devs.h>
20 #include <plat/fimc.h>
21 #include <plat/csis.h>
22 #include <plat/pd.h>
23
24 #ifdef CONFIG_VIDEO_M5MO
25 #include <media/m5mo_platform.h>
26 #endif
27 #ifdef CONFIG_VIDEO_S5K5BAFX
28 #include <media/s5k5bafx_platform.h>
29 #endif
30
31 extern void s3c_i2c0_force_stop(void);
32
33 #ifdef CONFIG_VIDEO_M5MO
34 #define CAM_CHECK_ERR_RET(x, msg)       \
35         if (unlikely((x) < 0)) { \
36                 printk(KERN_ERR "\nfail to %s: err = %d\n", msg, x); \
37                 return x; \
38         }
39 #define CAM_CHECK_ERR(x, msg)   \
40         if (unlikely((x) < 0)) { \
41                 printk(KERN_ERR "\nfail to %s: err = %d\n", msg, x); \
42         }
43
44 static struct regulator_bulk_data flash_supplies[] = {
45         { .supply = "flash_en", },      /* FLED_EN:U1, ldo6:U1HD */
46         { .supply = "flash_set", },     /* GSMB:U1, Dummy:U1HD */
47 };
48
49 static int m5mo_flash_power(int enable, struct device *dev)
50 {
51         static DEFINE_MUTEX(lock);
52         static bool enabled;
53         int ret = 0;
54
55         mutex_lock(&lock);
56
57         if (enabled == !!enable)
58                 goto out;
59
60         if (flash_supplies[0].consumer == NULL) {
61                 ret = regulator_bulk_get(dev, ARRAY_SIZE(flash_supplies),
62                                          flash_supplies);
63                 if (ret) {
64                         WARN(ret, "Cannot get regulators for M5MO.\n");
65                         goto out;
66                 }
67         }
68
69         if (enable)
70                 ret = regulator_bulk_enable(ARRAY_SIZE(flash_supplies),
71                                 flash_supplies);
72         else
73                 ret = regulator_bulk_disable(ARRAY_SIZE(flash_supplies),
74                                 flash_supplies);
75         enabled = !!enable;
76 out:
77         mutex_unlock(&lock);
78         return ret;
79 }
80
81 static struct m5mo_platform_data m5mo_pdata = {
82         .flash_power = m5mo_flash_power,
83 };
84
85 #define GPIO_CAM_VGA_nSTBY              S5PV310_GPL2(0)
86 #define GPIO_CAM_VGA_nRST               S5PV310_GPL2(1)
87 #define GPIO_CAM_SENSOR_CORE    S5PV310_GPE2(5)
88 #define GPIO_CAM_IO_EN                  S5PV310_GPE2(1)
89 #define GPIO_VT_CAM_15V                 S5PV310_GPE2(2)
90 #define GPIO_ISP_RESET                  S5PV310_GPY3(7)
91 #define GPIO_8M_AF_EN                   S5PV310_GPK1(1)
92
93 static int u1_rear_cam_power_on(struct device *dev)
94 {
95         static DEFINE_MUTEX(lock);
96         struct regulator *regulator;
97         int ret = 0;
98
99         mutex_lock(&lock);
100
101         /* Camera Power ON */
102         ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
103         if (ret) {
104                 printk(KERN_ERR "failed to request gpio(GPIO_CAM_VGA_nSTBY)\n");
105                 goto out;
106         }
107         ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
108         if (ret) {
109                 printk(KERN_ERR "failed to request gpio(GPIO_CAM_VGA_nRST)\n");
110                 goto out;
111         }
112         ret = gpio_request(GPIO_CAM_SENSOR_CORE, "GPE2");
113         if (ret) {
114                 printk(KERN_ERR "failed to request gpio(CAM_SENSOR_CORE)\n");
115                 goto out;
116         }
117         ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
118         if (ret) {
119                 printk(KERN_ERR "failed to request gpio(CAM_IO_EN)\n");
120                 goto out;
121         }
122         ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
123         if (ret) {
124                 printk(KERN_ERR "failed to request gpio(GPIO_VT_CAM_15V)\n");
125                 goto out;
126         }
127         ret = gpio_request(GPIO_ISP_RESET, "GPY3");
128         if (ret) {
129                 printk(KERN_ERR "failed to request gpio(ISP_RESET)\n");
130                 goto out;
131         }
132         ret = gpio_request(GPIO_8M_AF_EN, "GPK1");
133         if (ret) {
134                 printk(KERN_ERR "failed to request gpio(8M_AF_EN)\n");
135                 goto out;
136         }
137
138         /* CAM_VT_nSTBY low */
139         ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 0);
140         CAM_CHECK_ERR_RET(ret, "output VGA_nSTBY");
141
142         /* CAM_VT_nRST  low */
143         gpio_direction_output(GPIO_CAM_VGA_nRST, 0);
144         CAM_CHECK_ERR_RET(ret, "output VGA_nRST");
145
146         udelay(10);
147
148         /* CAM_ISP_CORE_1.2V */
149         regulator = regulator_get(dev, "i_core_12");
150         if (IS_ERR(regulator)) {
151                 ret = PTR_ERR(regulator);
152                 printk("%s: i_core_12 regulator get failed\n", __func__);
153                 goto out;
154         }
155         ret = regulator_enable(regulator);
156         regulator_put(regulator);
157         CAM_CHECK_ERR_RET(ret, "enable i_core_12");
158
159         /* CAM_SENSOR_CORE_1.2V */
160         ret = gpio_direction_output(GPIO_CAM_SENSOR_CORE, 1);
161         CAM_CHECK_ERR_RET(ret, "output senser_core");
162
163         udelay(120);
164
165         /* CAM_SENSOR_A2.8V */
166         ret = gpio_direction_output(GPIO_CAM_IO_EN, 1);
167         CAM_CHECK_ERR_RET(ret, "output IO_EN");
168
169         udelay(20);
170
171         /* VT_CORE_1.5V */
172         ret = gpio_direction_output(GPIO_VT_CAM_15V, 1);
173         CAM_CHECK_ERR_RET(ret, "output VT_CAM_1.5V");
174
175         udelay(15);
176
177         /* 8M_AF_2.8V_EN */
178         ret = gpio_direction_output(GPIO_8M_AF_EN, 1);
179         CAM_CHECK_ERR(ret, "output AF");
180
181         /* CAM_ISP_1.8V */
182         regulator = regulator_get(dev, "i_host_18");
183         if (IS_ERR(regulator)) {
184                 ret = PTR_ERR(regulator);
185                 printk("%s: i_host_18 regulator get failed\n", __func__);
186                 goto out;
187         }
188         ret = regulator_enable(regulator);
189         regulator_put(regulator);
190         CAM_CHECK_ERR_RET(ret, "enable i_host_18");
191
192         udelay(10);
193
194         /* CAM_SENSOR_IO_1.8V */
195         regulator = regulator_get(dev, "s_vif_18");
196         if (IS_ERR(regulator)) {
197                 ret = PTR_ERR(regulator);
198                 printk("%s: s_vif_18 regulator get failed\n", __func__);
199                 goto out;
200         }
201         ret = regulator_enable(regulator);
202         regulator_put(regulator);
203         CAM_CHECK_ERR_RET(ret, "enable s_vif_18");
204
205         udelay(10);
206
207         /* MCLK */
208
209         udelay(350);
210
211         /* ISP_RESET */
212         ret = gpio_direction_output(GPIO_ISP_RESET, 1);
213         CAM_CHECK_ERR_RET(ret, "output reset");
214
215         mdelay(3);
216
217         gpio_free(GPIO_CAM_VGA_nSTBY);
218         gpio_free(GPIO_CAM_VGA_nRST);
219         gpio_free(GPIO_CAM_SENSOR_CORE);
220         gpio_free(GPIO_CAM_IO_EN);
221         gpio_free(GPIO_VT_CAM_15V);
222         gpio_free(GPIO_ISP_RESET);
223         gpio_free(GPIO_8M_AF_EN);
224
225 out:
226         mutex_unlock(&lock);
227         return ret;
228 }
229
230 static int u1_rear_cam_power_off(struct device *dev)
231 {
232         static DEFINE_MUTEX(lock);
233         struct regulator *regulator;
234         int ret = 0;
235
236         /* Camera Power OFF */
237
238         mutex_lock(&lock);
239
240         ret = gpio_request(GPIO_8M_AF_EN, "GPK1");
241         if (ret) {
242                 printk(KERN_ERR "failed to request gpio(8M_AF_EN)\n");
243                 return ret;
244         }
245         ret = gpio_request(GPIO_ISP_RESET, "GPY3");
246         if (ret) {
247                 printk(KERN_ERR "failed to request gpio(ISP_RESET)\n");
248                 return ret;
249         }
250         ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
251         if (ret) {
252                 printk(KERN_ERR "failed to request gpio(GPIO_CAM_IO_EN)\n");
253                 return ret;
254         }
255         ret = gpio_request(GPIO_CAM_SENSOR_CORE, "GPE2");
256         if (ret) {
257                 printk(KERN_ERR "failed to request gpio(CAM_SENSOR_CORE)\n");
258                 return ret;
259         }
260         ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
261         if (ret) {
262                 printk(KERN_ERR "failed to request gpio(GPIO_VT_CAM_15V)\n");
263                 return ret;
264         }
265
266         mdelay(3);
267
268         /* ISP_RESET */
269         ret = gpio_direction_output(GPIO_ISP_RESET, 0);
270         CAM_CHECK_ERR(ret, "output reset");
271         mdelay(1);
272
273         /* CAM_AF_2.8V */
274         ret = gpio_direction_output(GPIO_8M_AF_EN, 0);
275         CAM_CHECK_ERR(ret, "output AF");
276
277         /* CAM_SENSOR_IO_1.8V */
278         regulator = regulator_get(dev, "s_vif_18");
279         if (IS_ERR(regulator)) {
280                 ret = PTR_ERR(regulator);
281                 printk("%s: s_vif_18 regulator get failed\n", __func__);
282                         goto out;
283                 }
284         if (regulator_is_enabled(regulator))
285                 ret = regulator_force_disable(regulator);
286         regulator_put(regulator);
287         CAM_CHECK_ERR(ret, "disable, s_vif_18");
288         udelay(10);
289
290         /* CAM_ISP_1.8V */
291         regulator = regulator_get(dev, "i_host_18");
292         if (IS_ERR(regulator)) {
293                 ret = PTR_ERR(regulator);
294                 printk("%s: i_host_18 regulator get failed\n", __func__);
295                 goto out;
296         }
297         if (regulator_is_enabled(regulator))
298                 ret = regulator_force_disable(regulator);
299         regulator_put(regulator);
300         CAM_CHECK_ERR(ret, "disable i_host_18");
301         udelay(500); /* 100us -> 500us */
302
303         /* VT_CORE_1.5V : vt_core_15 */
304         ret = gpio_direction_output(GPIO_VT_CAM_15V, 0);
305         CAM_CHECK_ERR(ret, "output VT_CAM_1.5V");
306         udelay(300); /*10 -> 300 us */
307
308         /* CAM_SENSOR_A2.8V : s_vana_28 */
309         ret = gpio_direction_output(GPIO_CAM_IO_EN, 0);
310         CAM_CHECK_ERR(ret, "output IO_EN");
311         udelay(800);
312
313         /* CAM_SENSOR_CORE_1.2V : s_vdig_12 */
314         ret = gpio_direction_output(GPIO_CAM_SENSOR_CORE, 0);
315         CAM_CHECK_ERR(ret, "output SENSOR_CORE");
316         udelay(5);
317
318         /* CAM_ISP_CORE_1.2V */
319         regulator = regulator_get(dev, "i_core_12");
320         if (IS_ERR(regulator)) {
321                 ret = PTR_ERR(regulator);
322                 printk("%s: i_core_12 regulator get failed\n", __func__);
323                 goto out;
324         }
325         if (regulator_is_enabled(regulator))
326                 ret = regulator_force_disable(regulator);
327         regulator_put(regulator);
328         CAM_CHECK_ERR(ret, "disable i_core_12");
329
330         gpio_free(GPIO_8M_AF_EN);
331         gpio_free(GPIO_ISP_RESET);
332         gpio_free(GPIO_CAM_IO_EN);
333         gpio_free(GPIO_CAM_SENSOR_CORE);
334         gpio_free(GPIO_VT_CAM_15V);
335
336 out:
337         mutex_unlock(&lock);
338         return ret;
339 }
340
341 static int u1_rear_cam_power(int enable, struct device *dev)
342 {
343         static bool enabled;
344         int ret = 0;
345
346         printk("%s %s\n", __func__, enable ? "on" : "down");
347
348         if (enabled == !!enable)
349                 goto error_out;
350
351         if (enable) {
352                 ret = u1_rear_cam_power_on(dev);
353                 if (unlikely(ret))
354                         goto error_out;
355         } else {
356                 ret = u1_rear_cam_power_off(dev);
357                 s3c_i2c0_force_stop();
358         }
359
360         enabled = !!enable;
361
362 error_out:
363         return ret;
364 }
365
366 static struct i2c_board_info m5mo_i2c_info = {
367         I2C_BOARD_INFO("M5MO", 0x1F),
368         .platform_data = &m5mo_pdata,
369 };
370
371 static struct s3c_platform_camera m5mo = {
372         .id             = CAMERA_CSI_C,
373         .type           = CAM_TYPE_MIPI,
374         .fmt            = MIPI_CSI_YCBCR422_8BIT,
375         .order422       = CAM_ORDER422_8BIT_YCBYCR,
376         .mipi_lanes     = 2,
377         .mipi_settle    = 12,
378         .mipi_align     = 32,
379
380         .i2c_busnum     = 0,
381         .info           = &m5mo_i2c_info,
382         .pixelformat    = V4L2_PIX_FMT_UYVY,
383         .srclk_name     = "xusbxti",            /* "mout_mpll" */
384         .clk_name       = "sclk_cam",
385         .clk_rate       = 24000000,             /* 48000000 */
386         .line_length    = 1920,
387         .width          = 640,
388         .height         = 480,
389         .window         = {
390                 .left   = 0,
391                 .top    = 0,
392                 .width  = 640,
393                 .height = 480,
394         },
395
396         .inv_pclk       = 1,
397         .inv_vsync      = 1,
398         .inv_href       = 0,
399         .inv_hsync      = 0,
400         .reset_camera   = 0,
401         .initialized    = 0,
402         .cam_power      = u1_rear_cam_power,
403 };
404 #endif  /* CONFIG_VIDEO_M5MO */
405
406 #ifdef CONFIG_VIDEO_S5K5BAFX
407
408 static int s5k5bafx_power_on(struct device *dev)
409 {
410         static DEFINE_MUTEX(lock);
411         struct regulator *regulator;
412         int ret = 0;
413
414         mutex_lock(&lock);
415
416         ret = gpio_request(GPIO_ISP_RESET, "GPY3");
417         if (ret) {
418                 printk(KERN_ERR "faile to request gpio(ISP_RESET)\n");
419                 return ret;
420         }
421         ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
422         if (ret) {
423                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_IO_EN)\n");
424                 return ret;
425         }
426         ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
427         if (ret) {
428                 printk(KERN_ERR "faile to request gpio(GPIO_VT_CAM_15V)\n");
429                 return ret;
430         }
431         ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
432         if (ret) {
433                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nSTBY)\n");
434                 return ret;
435         }
436         ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
437         if (ret) {
438                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nRST)\n");
439                 return ret;
440         }
441
442         /* ISP_RESET low*/
443         ret = gpio_direction_output(GPIO_ISP_RESET, 0);
444         CAM_CHECK_ERR_RET(ret, "output reset");
445         udelay(100);
446
447         /* CAM_ISP_CORE_1.2V */
448         regulator = regulator_get(dev, "i_core_12");
449         if (IS_ERR(regulator)) {
450                 ret = PTR_ERR(regulator);
451                 printk("%s: i_core_12 regulator get failed\n", __func__);
452                 goto out;
453         }
454         ret = regulator_enable(regulator);
455         regulator_put(regulator);
456         CAM_CHECK_ERR_RET(ret, "enable i_core_12");
457         udelay(10);
458
459         /* CAM_SENSOR_A2.8V */
460         ret = gpio_direction_output(GPIO_CAM_IO_EN, 1);
461         CAM_CHECK_ERR_RET(ret, "output io_en");
462         udelay(300); /* don't change me */
463
464         /* VT_CORE_1.5V */
465         ret = gpio_direction_output(GPIO_VT_CAM_15V, 1);
466         CAM_CHECK_ERR_RET(ret, "output vt_15v");
467         udelay(100);
468
469         /* CAM_ISP_1.8V */
470         regulator = regulator_get(dev, "i_host_18");
471         if (IS_ERR(regulator)) {
472                 ret = PTR_ERR(regulator);
473                 printk("%s: i_host_18 regulator get failed\n", __func__);
474                 goto out;
475         }
476         ret = regulator_enable(regulator);
477         regulator_put(regulator);
478         CAM_CHECK_ERR_RET(ret, "enable i_host_18");
479         udelay(10);
480
481         /* VT_CAM_1.8V */
482         regulator = regulator_get(dev, "vt_core_18");
483         if (IS_ERR(regulator)) {
484                 ret = PTR_ERR(regulator);
485                 printk("%s: vt_core_18 regulator get failed\n", __func__);
486                 goto out;
487         }
488         ret = regulator_enable(regulator);
489         regulator_put(regulator);
490         CAM_CHECK_ERR_RET(ret, "enable vt_core_18");
491         udelay(10);
492
493         /* CAM_VGA_nSTBY */
494         ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 1);
495         CAM_CHECK_ERR_RET(ret, "output VGA_nSTBY");
496         udelay(50);
497
498         /* CAM_VGA_nRST  */
499         ret = gpio_direction_output(GPIO_CAM_VGA_nRST, 1);
500         CAM_CHECK_ERR_RET(ret, "output VGA_nRST");
501         mdelay(2);
502
503         gpio_free(GPIO_ISP_RESET);
504         gpio_free(GPIO_CAM_IO_EN);
505         gpio_free(GPIO_VT_CAM_15V);
506         gpio_free(GPIO_CAM_VGA_nSTBY);
507         gpio_free(GPIO_CAM_VGA_nRST);
508
509 out:
510         mutex_unlock(&lock);
511         return ret;
512 }
513
514 static int s5k5bafx_power_off(struct device *dev)
515 {
516         static DEFINE_MUTEX(lock);
517         struct regulator *regulator;
518         int ret = 0;
519
520         mutex_lock(&lock);
521
522         ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
523         if (ret) {
524                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nRST)\n");
525                 return ret;
526         }
527         ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
528         if (ret) {
529                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nSTBY)\n");
530                 return ret;
531         }
532         ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
533         if (ret) {
534                 printk(KERN_ERR "faile to request gpio(GPIO_VT_CAM_15V)\n");
535                 return ret;
536         }
537         ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
538         if (ret) {
539                 printk(KERN_ERR "faile to request gpio(GPIO_CAM_IO_EN)\n");
540                 return ret;
541         }
542
543         /* CAM_VGA_nRST  */
544         ret = gpio_direction_output(GPIO_CAM_VGA_nRST, 0);
545         CAM_CHECK_ERR(ret, "output VGA_nRST");
546         udelay(100);
547
548         /* CAM_VGA_nSTBY */
549         ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 0);
550         CAM_CHECK_ERR(ret, "output VGA_nSTBY");
551         udelay(20);
552
553         /* VT_CAM_1.8V */
554         regulator = regulator_get(dev, "vt_core_18");
555         if (IS_ERR(regulator)) {
556                 ret = PTR_ERR(regulator);
557                 printk("%s: vt_core_18 regulator get failed\n", __func__);
558                 goto out;
559         }
560         if (regulator_is_enabled(regulator))
561                 ret = regulator_disable(regulator);
562         regulator_put(regulator);
563         CAM_CHECK_ERR(ret, "disable vt_1.8v");
564         udelay(10);
565
566         /* CAM_ISP_1.8V */
567         regulator = regulator_get(dev, "i_host_18");
568         if (IS_ERR(regulator)) {
569                 ret = PTR_ERR(regulator);
570                 printk("%s: i_host_18 regulator get failed\n", __func__);
571                 goto out;
572         }
573         if (regulator_is_enabled(regulator))
574                 ret = regulator_force_disable(regulator);
575         regulator_put(regulator);
576         CAM_CHECK_ERR(ret, "disable cam_isp");
577         udelay(10);
578
579         /* VT_CORE_1.5V */
580         ret = gpio_direction_output(GPIO_VT_CAM_15V, 0);
581         CAM_CHECK_ERR(ret, "output vt_1.5v");
582         udelay(10);
583
584         /* CAM_SENSOR_A2.8V */
585         ret = gpio_direction_output(GPIO_CAM_IO_EN, 0);
586         CAM_CHECK_ERR(ret, "output io_en");
587         udelay(10);
588
589         /* CAM_ISP_CORE_1.2V */
590         regulator = regulator_get(dev, "i_core_12");
591         if (IS_ERR(regulator)) {
592                 ret = PTR_ERR(regulator);
593                 printk("%s: i_core_12 regulator get failed\n", __func__);
594                 goto out;
595         }
596         if (regulator_is_enabled(regulator))
597                 ret = regulator_force_disable(regulator);
598         regulator_put(regulator);
599         CAM_CHECK_ERR(ret, "disable isp_core");
600
601         gpio_free(GPIO_CAM_VGA_nRST);
602         gpio_free(GPIO_CAM_VGA_nSTBY);
603         gpio_free(GPIO_VT_CAM_15V);
604         gpio_free(GPIO_CAM_IO_EN);
605
606 out:
607         mutex_unlock(&lock);
608         return 0;
609 }
610
611 static int s5k5bafx_power(int enable, struct device *dev)
612 {
613         static bool enabled;
614         int ret = 0;
615
616         printk("%s: %s\n", __func__, !!enable ? "on" : "down");
617
618         if (enabled == !!enable)
619                 goto error_out;
620
621         if (enable) {
622                 ret = s5k5bafx_power_on(dev);
623                 if (unlikely(ret))
624                         goto error_out;
625         } else {
626                 ret = s5k5bafx_power_off(dev);
627                 s3c_i2c0_force_stop();
628         }
629
630         enabled = !!enable;
631
632 error_out:
633         return ret;
634 }
635
636 static struct s5k5bafx_platform_data s5k5bafx_pdata = {
637         .default_width = 640,
638         .default_height = 480,
639         .pixelformat = V4L2_PIX_FMT_UYVY,
640         .freq = 24000000,
641         .is_mipi = 1,
642 };
643
644 static struct i2c_board_info s5k5bafx_i2c_info = {
645         I2C_BOARD_INFO("S5K5BAFX", 0x2D),
646         .platform_data = &s5k5bafx_pdata,
647 };
648
649 static struct s3c_platform_camera s5k5bafx = {
650         .id             = CAMERA_CSI_D,
651         .type           = CAM_TYPE_MIPI,
652         .fmt            = ITU_601_YCBCR422_8BIT,
653         .order422       = CAM_ORDER422_8BIT_CBYCRY,
654         .mipi_lanes     = 1,
655         .mipi_settle    = 6,
656         .mipi_align     = 32,
657
658         .i2c_busnum     = 17,
659         .info           = &s5k5bafx_i2c_info,
660         .pixelformat    = V4L2_PIX_FMT_UYVY,
661         .srclk_name     = "xusbxti",
662         .clk_name       = "sclk_cam",
663         .clk_rate       = 24000000,
664         .line_length    = 640,
665         .width          = 640,
666         .height         = 480,
667         .window         = {
668                 .left   = 0,
669                 .top    = 0,
670                 .width  = 640,
671                 .height = 480,
672         },
673
674         .inv_pclk       = 0,
675         .inv_vsync      = 1,
676         .inv_href       = 0,
677         .inv_hsync      = 0,
678         .reset_camera   = 0,
679         .initialized    = 0,
680         .cam_power      = s5k5bafx_power,
681 };
682 #endif  /* CONFIG_VIDEO_S5K5BAFX */
683
684 #define WRITEBACK_ENABLED
685 #ifdef WRITEBACK_ENABLED
686 static struct i2c_board_info  __initdata writeback_i2c_info = {
687         I2C_BOARD_INFO("WriteBack", 0x0),
688 };
689
690 static struct s3c_platform_camera writeback = {
691         .id             = CAMERA_WB,
692         .fmt            = ITU_601_YCBCR422_8BIT,
693         .order422       = CAM_ORDER422_8BIT_CBYCRY,
694         .i2c_busnum     = 0,
695         .info           = &writeback_i2c_info,
696         .pixelformat    = V4L2_PIX_FMT_YUV444,
697         .line_length    = 1280,
698         .width          = 720,
699         .height         = 1280,
700         .window         = {
701                 .left   = 0,
702                 .top    = 0,
703                 .width  = 720,
704                 .height = 1280,
705         },
706
707         .initialized    = 0,
708 };
709 #endif  /* WRITEBACK_ENABLED */
710
711 #ifdef CONFIG_VIDEO_FIMC
712 struct s3c_platform_fimc fimc_plat = {
713         .default_cam    = CAMERA_CSI_C,
714         .camera         = {
715 #ifdef CONFIG_VIDEO_M5MO
716                 &m5mo,
717 #endif
718 #ifdef CONFIG_VIDEO_S5K5BAFX
719                 &s5k5bafx,
720 #endif
721 #ifdef WRITEBACK_ENABLED
722                 &writeback,
723 #endif
724         },
725         .hw_ver         = 0x51,
726 };
727 #endif /* CONFIG_VIDEO_FIMC */
728
729 #ifdef CONFIG_VIDEO_FIMC_MIPI
730 static struct regulator_bulk_data mipi_supplies[] = {
731         { .supply = "vdd11_mipi", },
732         { .supply = "vdd18_mipi", },
733 };
734
735 static int u1_mipi_power(bool enable, struct device *dev)
736 {
737         static DEFINE_MUTEX(lock);
738         static bool enabled;
739         int ret = 0;
740
741         mutex_lock(&lock);
742
743         if (enabled == !!enable)
744                 goto out;
745
746         if (mipi_supplies[0].consumer == NULL) {
747                 ret = regulator_bulk_get(dev, ARRAY_SIZE(mipi_supplies),
748                                 mipi_supplies);
749                 if (ret) {
750                         WARN(ret, "Cannot get regulators for MIPI Block.\n");
751                         goto out;
752                 }
753         }
754
755         if (enable)
756                 ret = regulator_bulk_enable(ARRAY_SIZE(mipi_supplies),
757                                 mipi_supplies);
758         else
759                 ret = regulator_bulk_disable(ARRAY_SIZE(mipi_supplies),
760                                 mipi_supplies);
761
762         enabled = !!enable;
763 out:
764         mutex_unlock(&lock);
765         return ret;
766 }
767
768 struct s3c_platform_csis csis_plat = {
769         .srclk_name     = "mout_mpll",
770         .clk_name       = "sclk_csis",
771         .clk_rate       = 166000000,
772         .power          = u1_mipi_power,
773 };
774 #endif /* CONFIG_VIDEO_FIMC_MIPI */
775
776 void __init s5pv310_camera_init(void)
777 {
778         unsigned int gpio;
779
780 #ifdef CONFIG_VIDEO_FIMC
781         s3c_fimc0_set_platdata(&fimc_plat);
782         s3c_fimc1_set_platdata(&fimc_plat);
783         s3c_fimc2_set_platdata(&fimc_plat);
784         s3c_fimc3_set_platdata(&fimc_plat);
785  #ifdef CONFIG_S5PV310_DEV_PD
786         s3c_device_fimc0.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
787         s3c_device_fimc1.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
788         s3c_device_fimc2.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
789         s3c_device_fimc3.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
790  #endif
791  #ifdef CONFIG_VIDEO_FIMC_MIPI
792         s3c_csis0_set_platdata(&csis_plat);
793         s3c_csis1_set_platdata(&csis_plat);
794   #ifdef CONFIG_S5PV310_DEV_PD
795         s3c_device_csis0.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
796         s3c_device_csis1.dev.parent = &s5pv310_device_pd[PD_CAM].dev;
797   #endif
798  #endif
799 #endif
800
801 #ifdef CONFIG_VIDEO_M5MO
802         gpio = S5PV310_GPX1(5);         /* ISP_INT: XEINT[13] */
803         gpio_request(gpio, "M5MO_INT");
804         gpio_direction_input(gpio);
805         m5mo_pdata.irq = gpio_to_irq(gpio);
806 #endif
807 }