2 * linux/arch/arm/mach-s5pv310/board-camera.c
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
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.
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>
17 #include <mach/gpio.h>
19 #include <plat/devs.h>
20 #include <plat/fimc.h>
21 #include <plat/csis.h>
24 #ifdef CONFIG_VIDEO_M5MO
25 #include <media/m5mo_platform.h>
27 #ifdef CONFIG_VIDEO_S5K5BAFX
28 #include <media/s5k5bafx_platform.h>
31 extern void s3c_i2c0_force_stop(void);
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); \
39 #define CAM_CHECK_ERR(x, msg) \
40 if (unlikely((x) < 0)) { \
41 printk(KERN_ERR "\nfail to %s: err = %d\n", msg, x); \
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 */
49 static int m5mo_flash_power(int enable, struct device *dev)
51 static DEFINE_MUTEX(lock);
57 if (enabled == !!enable)
60 if (flash_supplies[0].consumer == NULL) {
61 ret = regulator_bulk_get(dev, ARRAY_SIZE(flash_supplies),
64 WARN(ret, "Cannot get regulators for M5MO.\n");
70 ret = regulator_bulk_enable(ARRAY_SIZE(flash_supplies),
73 ret = regulator_bulk_disable(ARRAY_SIZE(flash_supplies),
81 static struct m5mo_platform_data m5mo_pdata = {
82 .flash_power = m5mo_flash_power,
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)
93 static int u1_rear_cam_power_on(struct device *dev)
95 static DEFINE_MUTEX(lock);
96 struct regulator *regulator;
101 /* Camera Power ON */
102 ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
104 printk(KERN_ERR "failed to request gpio(GPIO_CAM_VGA_nSTBY)\n");
107 ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
109 printk(KERN_ERR "failed to request gpio(GPIO_CAM_VGA_nRST)\n");
112 ret = gpio_request(GPIO_CAM_SENSOR_CORE, "GPE2");
114 printk(KERN_ERR "failed to request gpio(CAM_SENSOR_CORE)\n");
117 ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
119 printk(KERN_ERR "failed to request gpio(CAM_IO_EN)\n");
122 ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
124 printk(KERN_ERR "failed to request gpio(GPIO_VT_CAM_15V)\n");
127 ret = gpio_request(GPIO_ISP_RESET, "GPY3");
129 printk(KERN_ERR "failed to request gpio(ISP_RESET)\n");
132 ret = gpio_request(GPIO_8M_AF_EN, "GPK1");
134 printk(KERN_ERR "failed to request gpio(8M_AF_EN)\n");
138 /* CAM_VT_nSTBY low */
139 ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 0);
140 CAM_CHECK_ERR_RET(ret, "output VGA_nSTBY");
142 /* CAM_VT_nRST low */
143 gpio_direction_output(GPIO_CAM_VGA_nRST, 0);
144 CAM_CHECK_ERR_RET(ret, "output VGA_nRST");
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__);
155 ret = regulator_enable(regulator);
156 regulator_put(regulator);
157 CAM_CHECK_ERR_RET(ret, "enable i_core_12");
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");
165 /* CAM_SENSOR_A2.8V */
166 ret = gpio_direction_output(GPIO_CAM_IO_EN, 1);
167 CAM_CHECK_ERR_RET(ret, "output IO_EN");
172 ret = gpio_direction_output(GPIO_VT_CAM_15V, 1);
173 CAM_CHECK_ERR_RET(ret, "output VT_CAM_1.5V");
178 ret = gpio_direction_output(GPIO_8M_AF_EN, 1);
179 CAM_CHECK_ERR(ret, "output AF");
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__);
188 ret = regulator_enable(regulator);
189 regulator_put(regulator);
190 CAM_CHECK_ERR_RET(ret, "enable i_host_18");
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__);
201 ret = regulator_enable(regulator);
202 regulator_put(regulator);
203 CAM_CHECK_ERR_RET(ret, "enable s_vif_18");
212 ret = gpio_direction_output(GPIO_ISP_RESET, 1);
213 CAM_CHECK_ERR_RET(ret, "output reset");
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);
230 static int u1_rear_cam_power_off(struct device *dev)
232 static DEFINE_MUTEX(lock);
233 struct regulator *regulator;
236 /* Camera Power OFF */
240 ret = gpio_request(GPIO_8M_AF_EN, "GPK1");
242 printk(KERN_ERR "failed to request gpio(8M_AF_EN)\n");
245 ret = gpio_request(GPIO_ISP_RESET, "GPY3");
247 printk(KERN_ERR "failed to request gpio(ISP_RESET)\n");
250 ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
252 printk(KERN_ERR "failed to request gpio(GPIO_CAM_IO_EN)\n");
255 ret = gpio_request(GPIO_CAM_SENSOR_CORE, "GPE2");
257 printk(KERN_ERR "failed to request gpio(CAM_SENSOR_CORE)\n");
260 ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
262 printk(KERN_ERR "failed to request gpio(GPIO_VT_CAM_15V)\n");
269 ret = gpio_direction_output(GPIO_ISP_RESET, 0);
270 CAM_CHECK_ERR(ret, "output reset");
274 ret = gpio_direction_output(GPIO_8M_AF_EN, 0);
275 CAM_CHECK_ERR(ret, "output AF");
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__);
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");
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__);
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 */
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 */
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");
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");
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__);
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");
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);
341 static int u1_rear_cam_power(int enable, struct device *dev)
346 printk("%s %s\n", __func__, enable ? "on" : "down");
348 if (enabled == !!enable)
352 ret = u1_rear_cam_power_on(dev);
356 ret = u1_rear_cam_power_off(dev);
357 s3c_i2c0_force_stop();
366 static struct i2c_board_info m5mo_i2c_info = {
367 I2C_BOARD_INFO("M5MO", 0x1F),
368 .platform_data = &m5mo_pdata,
371 static struct s3c_platform_camera m5mo = {
373 .type = CAM_TYPE_MIPI,
374 .fmt = MIPI_CSI_YCBCR422_8BIT,
375 .order422 = CAM_ORDER422_8BIT_YCBYCR,
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 */
402 .cam_power = u1_rear_cam_power,
404 #endif /* CONFIG_VIDEO_M5MO */
406 #ifdef CONFIG_VIDEO_S5K5BAFX
408 static int s5k5bafx_power_on(struct device *dev)
410 static DEFINE_MUTEX(lock);
411 struct regulator *regulator;
416 ret = gpio_request(GPIO_ISP_RESET, "GPY3");
418 printk(KERN_ERR "faile to request gpio(ISP_RESET)\n");
421 ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
423 printk(KERN_ERR "faile to request gpio(GPIO_CAM_IO_EN)\n");
426 ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
428 printk(KERN_ERR "faile to request gpio(GPIO_VT_CAM_15V)\n");
431 ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
433 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nSTBY)\n");
436 ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
438 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nRST)\n");
443 ret = gpio_direction_output(GPIO_ISP_RESET, 0);
444 CAM_CHECK_ERR_RET(ret, "output reset");
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__);
454 ret = regulator_enable(regulator);
455 regulator_put(regulator);
456 CAM_CHECK_ERR_RET(ret, "enable i_core_12");
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 */
465 ret = gpio_direction_output(GPIO_VT_CAM_15V, 1);
466 CAM_CHECK_ERR_RET(ret, "output vt_15v");
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__);
476 ret = regulator_enable(regulator);
477 regulator_put(regulator);
478 CAM_CHECK_ERR_RET(ret, "enable i_host_18");
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__);
488 ret = regulator_enable(regulator);
489 regulator_put(regulator);
490 CAM_CHECK_ERR_RET(ret, "enable vt_core_18");
494 ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 1);
495 CAM_CHECK_ERR_RET(ret, "output VGA_nSTBY");
499 ret = gpio_direction_output(GPIO_CAM_VGA_nRST, 1);
500 CAM_CHECK_ERR_RET(ret, "output VGA_nRST");
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);
514 static int s5k5bafx_power_off(struct device *dev)
516 static DEFINE_MUTEX(lock);
517 struct regulator *regulator;
522 ret = gpio_request(GPIO_CAM_VGA_nRST, "GPL2");
524 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nRST)\n");
527 ret = gpio_request(GPIO_CAM_VGA_nSTBY, "GPL2");
529 printk(KERN_ERR "faile to request gpio(GPIO_CAM_VGA_nSTBY)\n");
532 ret = gpio_request(GPIO_VT_CAM_15V, "GPE2");
534 printk(KERN_ERR "faile to request gpio(GPIO_VT_CAM_15V)\n");
537 ret = gpio_request(GPIO_CAM_IO_EN, "GPE2");
539 printk(KERN_ERR "faile to request gpio(GPIO_CAM_IO_EN)\n");
544 ret = gpio_direction_output(GPIO_CAM_VGA_nRST, 0);
545 CAM_CHECK_ERR(ret, "output VGA_nRST");
549 ret = gpio_direction_output(GPIO_CAM_VGA_nSTBY, 0);
550 CAM_CHECK_ERR(ret, "output VGA_nSTBY");
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__);
560 if (regulator_is_enabled(regulator))
561 ret = regulator_disable(regulator);
562 regulator_put(regulator);
563 CAM_CHECK_ERR(ret, "disable vt_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__);
573 if (regulator_is_enabled(regulator))
574 ret = regulator_force_disable(regulator);
575 regulator_put(regulator);
576 CAM_CHECK_ERR(ret, "disable cam_isp");
580 ret = gpio_direction_output(GPIO_VT_CAM_15V, 0);
581 CAM_CHECK_ERR(ret, "output vt_1.5v");
584 /* CAM_SENSOR_A2.8V */
585 ret = gpio_direction_output(GPIO_CAM_IO_EN, 0);
586 CAM_CHECK_ERR(ret, "output io_en");
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__);
596 if (regulator_is_enabled(regulator))
597 ret = regulator_force_disable(regulator);
598 regulator_put(regulator);
599 CAM_CHECK_ERR(ret, "disable isp_core");
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);
611 static int s5k5bafx_power(int enable, struct device *dev)
616 printk("%s: %s\n", __func__, !!enable ? "on" : "down");
618 if (enabled == !!enable)
622 ret = s5k5bafx_power_on(dev);
626 ret = s5k5bafx_power_off(dev);
627 s3c_i2c0_force_stop();
636 static struct s5k5bafx_platform_data s5k5bafx_pdata = {
637 .default_width = 640,
638 .default_height = 480,
639 .pixelformat = V4L2_PIX_FMT_UYVY,
644 static struct i2c_board_info s5k5bafx_i2c_info = {
645 I2C_BOARD_INFO("S5K5BAFX", 0x2D),
646 .platform_data = &s5k5bafx_pdata,
649 static struct s3c_platform_camera s5k5bafx = {
651 .type = CAM_TYPE_MIPI,
652 .fmt = ITU_601_YCBCR422_8BIT,
653 .order422 = CAM_ORDER422_8BIT_CBYCRY,
659 .info = &s5k5bafx_i2c_info,
660 .pixelformat = V4L2_PIX_FMT_UYVY,
661 .srclk_name = "xusbxti",
662 .clk_name = "sclk_cam",
663 .clk_rate = 24000000,
680 .cam_power = s5k5bafx_power,
682 #endif /* CONFIG_VIDEO_S5K5BAFX */
684 #define WRITEBACK_ENABLED
685 #ifdef WRITEBACK_ENABLED
686 static struct i2c_board_info __initdata writeback_i2c_info = {
687 I2C_BOARD_INFO("WriteBack", 0x0),
690 static struct s3c_platform_camera writeback = {
692 .fmt = ITU_601_YCBCR422_8BIT,
693 .order422 = CAM_ORDER422_8BIT_CBYCRY,
695 .info = &writeback_i2c_info,
696 .pixelformat = V4L2_PIX_FMT_YUV444,
709 #endif /* WRITEBACK_ENABLED */
711 #ifdef CONFIG_VIDEO_FIMC
712 struct s3c_platform_fimc fimc_plat = {
713 .default_cam = CAMERA_CSI_C,
715 #ifdef CONFIG_VIDEO_M5MO
718 #ifdef CONFIG_VIDEO_S5K5BAFX
721 #ifdef WRITEBACK_ENABLED
727 #endif /* CONFIG_VIDEO_FIMC */
729 #ifdef CONFIG_VIDEO_FIMC_MIPI
730 static struct regulator_bulk_data mipi_supplies[] = {
731 { .supply = "vdd11_mipi", },
732 { .supply = "vdd18_mipi", },
735 static int u1_mipi_power(bool enable, struct device *dev)
737 static DEFINE_MUTEX(lock);
743 if (enabled == !!enable)
746 if (mipi_supplies[0].consumer == NULL) {
747 ret = regulator_bulk_get(dev, ARRAY_SIZE(mipi_supplies),
750 WARN(ret, "Cannot get regulators for MIPI Block.\n");
756 ret = regulator_bulk_enable(ARRAY_SIZE(mipi_supplies),
759 ret = regulator_bulk_disable(ARRAY_SIZE(mipi_supplies),
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,
774 #endif /* CONFIG_VIDEO_FIMC_MIPI */
776 void __init s5pv310_camera_init(void)
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;
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;
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);