2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
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/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
23 #include <linux/vmalloc.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_OV7690
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV7690
48 #define SENSOR_ID 0x76
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 640
52 #define SENSOR_MAX_HEIGHT 480
53 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT sensor_init_height
55 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM sensor_init_busparam
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 0
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
81 #define COLOR_TEMPERATURE_OFFICE_DN 3500
82 #define COLOR_TEMPERATURE_OFFICE_UP 5000
83 #define COLOR_TEMPERATURE_HOME_DN 2500
84 #define COLOR_TEMPERATURE_HOME_UP 3500
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
95 /* init 640*480 VGA */
96 static struct reginfo sensor_init_data[] =
150 {0xb9, 0x00}, //0x07//0x27
223 static struct reginfo sensor_720p[]=
230 static struct reginfo sensor_uxga[] =
236 static struct reginfo sensor_sxga[] =
241 static struct reginfo sensor_xga[] =
246 static struct reginfo sensor_svga[] =
252 static struct reginfo sensor_vga[] =
272 static struct reginfo sensor_cif[] =
278 static struct reginfo sensor_qvga[] =
298 static struct reginfo sensor_qcif[] =
318 static struct reginfo ov2655_qqvga[] =
325 static struct reginfo ov2655_Sharpness_auto[] =
330 static struct reginfo ov2655_Sharpness1[] =
336 static struct reginfo ov2655_Sharpness2[][3] =
343 static struct reginfo ov2655_Sharpness3[] =
349 static struct reginfo ov2655_Sharpness4[]=
356 static struct reginfo ov2655_Sharpness5[] =
364 static struct reginfo sensor_ClrFmt_YUYV[]=
369 static struct reginfo sensor_ClrFmt_UYVY[]=
375 #if CONFIG_SENSOR_WhiteBalance
376 static struct reginfo sensor_WhiteB_Auto[]=
381 /* Cloudy Colour Temperature : 6500K - 8000K */
382 static struct reginfo sensor_WhiteB_Cloudy[]=
390 /* ClearDay Colour Temperature : 5000K - 6500K */
391 static struct reginfo sensor_WhiteB_ClearDay[]=
399 /* Office Colour Temperature : 3500K - 5000K */
400 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
409 /* Home Colour Temperature : 2500K - 3500K */
410 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
418 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
419 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
423 #if CONFIG_SENSOR_Brightness
424 static struct reginfo sensor_Brightness0[]=
430 static struct reginfo sensor_Brightness1[]=
437 static struct reginfo sensor_Brightness2[]=
444 static struct reginfo sensor_Brightness3[]=
451 static struct reginfo sensor_Brightness4[]=
458 static struct reginfo sensor_Brightness5[]=
464 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
465 sensor_Brightness4, sensor_Brightness5,NULL,
470 #if CONFIG_SENSOR_Effect
471 static struct reginfo sensor_Effect_Normal[] =
477 static struct reginfo sensor_Effect_WandB[] =
485 static struct reginfo sensor_Effect_Sepia[] =
493 static struct reginfo sensor_Effect_Negative[] =
499 static struct reginfo sensor_Effect_Bluish[] =
508 static struct reginfo sensor_Effect_Green[] =
516 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
517 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
520 #if CONFIG_SENSOR_Exposure
521 static struct reginfo sensor_Exposure0[]=
526 static struct reginfo sensor_Exposure1[]=
531 static struct reginfo sensor_Exposure2[]=
536 static struct reginfo sensor_Exposure3[]=
541 static struct reginfo sensor_Exposure4[]=
546 static struct reginfo sensor_Exposure5[]=
551 static struct reginfo sensor_Exposure6[]=
556 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
557 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
560 #if CONFIG_SENSOR_Saturation
561 static struct reginfo sensor_Saturation0[]=
566 static struct reginfo sensor_Saturation1[]=
571 static struct reginfo sensor_Saturation2[]=
575 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
578 #if CONFIG_SENSOR_Contrast
579 static struct reginfo sensor_Contrast0[]=
584 static struct reginfo sensor_Contrast1[]=
589 static struct reginfo sensor_Contrast2[]=
594 static struct reginfo sensor_Contrast3[]=
599 static struct reginfo sensor_Contrast4[]=
605 static struct reginfo sensor_Contrast5[]=
610 static struct reginfo sensor_Contrast6[]=
614 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
615 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
619 #if CONFIG_SENSOR_Mirror
620 static struct reginfo sensor_MirrorOn[]=
625 static struct reginfo sensor_MirrorOff[]=
629 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
631 #if CONFIG_SENSOR_Flip
632 static struct reginfo sensor_FlipOn[]=
637 static struct reginfo sensor_FlipOff[]=
641 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
644 #if CONFIG_SENSOR_Scene
645 static struct reginfo sensor_SceneAuto[] =
650 static struct reginfo sensor_SceneNight[] =
654 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
657 #if CONFIG_SENSOR_DigitalZoom
658 static struct reginfo sensor_Zoom0[] =
663 static struct reginfo sensor_Zoom1[] =
668 static struct reginfo sensor_Zoom2[] =
674 static struct reginfo sensor_Zoom3[] =
678 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
680 static const struct v4l2_querymenu sensor_menus[] =
682 #if CONFIG_SENSOR_WhiteBalance
683 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
684 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
685 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
688 #if CONFIG_SENSOR_Effect
689 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
690 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
691 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
694 #if CONFIG_SENSOR_Scene
695 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
698 #if CONFIG_SENSOR_Flash
699 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
700 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
704 static const struct v4l2_queryctrl sensor_controls[] =
706 #if CONFIG_SENSOR_WhiteBalance
708 .id = V4L2_CID_DO_WHITE_BALANCE,
709 .type = V4L2_CTRL_TYPE_MENU,
710 .name = "White Balance Control",
718 #if CONFIG_SENSOR_Brightness
720 .id = V4L2_CID_BRIGHTNESS,
721 .type = V4L2_CTRL_TYPE_INTEGER,
722 .name = "Brightness Control",
730 #if CONFIG_SENSOR_Effect
732 .id = V4L2_CID_EFFECT,
733 .type = V4L2_CTRL_TYPE_MENU,
734 .name = "Effect Control",
742 #if CONFIG_SENSOR_Exposure
744 .id = V4L2_CID_EXPOSURE,
745 .type = V4L2_CTRL_TYPE_INTEGER,
746 .name = "Exposure Control",
754 #if CONFIG_SENSOR_Saturation
756 .id = V4L2_CID_SATURATION,
757 .type = V4L2_CTRL_TYPE_INTEGER,
758 .name = "Saturation Control",
766 #if CONFIG_SENSOR_Contrast
768 .id = V4L2_CID_CONTRAST,
769 .type = V4L2_CTRL_TYPE_INTEGER,
770 .name = "Contrast Control",
778 #if CONFIG_SENSOR_Mirror
780 .id = V4L2_CID_HFLIP,
781 .type = V4L2_CTRL_TYPE_BOOLEAN,
782 .name = "Mirror Control",
790 #if CONFIG_SENSOR_Flip
792 .id = V4L2_CID_VFLIP,
793 .type = V4L2_CTRL_TYPE_BOOLEAN,
794 .name = "Flip Control",
802 #if CONFIG_SENSOR_Scene
804 .id = V4L2_CID_SCENE,
805 .type = V4L2_CTRL_TYPE_MENU,
806 .name = "Scene Control",
814 #if CONFIG_SENSOR_DigitalZoom
816 .id = V4L2_CID_ZOOM_RELATIVE,
817 .type = V4L2_CTRL_TYPE_INTEGER,
818 .name = "DigitalZoom Control",
824 .id = V4L2_CID_ZOOM_ABSOLUTE,
825 .type = V4L2_CTRL_TYPE_INTEGER,
826 .name = "DigitalZoom Control",
834 #if CONFIG_SENSOR_Focus
836 .id = V4L2_CID_FOCUS_RELATIVE,
837 .type = V4L2_CTRL_TYPE_INTEGER,
838 .name = "Focus Control",
844 .id = V4L2_CID_FOCUS_ABSOLUTE,
845 .type = V4L2_CTRL_TYPE_INTEGER,
846 .name = "Focus Control",
850 .default_value = 125,
854 #if CONFIG_SENSOR_Flash
856 .id = V4L2_CID_FLASH,
857 .type = V4L2_CTRL_TYPE_MENU,
858 .name = "Flash Control",
867 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
868 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
869 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
870 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
871 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
872 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
873 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
874 static int sensor_resume(struct soc_camera_device *icd);
875 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
876 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
877 #if CONFIG_SENSOR_Effect
878 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
880 #if CONFIG_SENSOR_WhiteBalance
881 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
883 static int sensor_deactivate(struct i2c_client *client);
885 static struct soc_camera_ops sensor_ops =
887 .suspend = sensor_suspend,
888 .resume = sensor_resume,
889 .set_bus_param = sensor_set_bus_param,
890 .query_bus_param = sensor_query_bus_param,
891 .controls = sensor_controls,
892 .menus = sensor_menus,
893 .num_controls = ARRAY_SIZE(sensor_controls),
894 .num_menus = ARRAY_SIZE(sensor_menus),
897 /* only one fixed colorspace per pixelcode */
898 struct sensor_datafmt {
899 enum v4l2_mbus_pixelcode code;
900 enum v4l2_colorspace colorspace;
903 /* Find a data format by a pixel code in an array */
904 static const struct sensor_datafmt *sensor_find_datafmt(
905 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
909 for (i = 0; i < n; i++)
910 if (fmt[i].code == code)
916 static const struct sensor_datafmt sensor_colour_fmts[] = {
917 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
918 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
921 typedef struct sensor_info_priv_s
935 unsigned char mirror; /* HFLIP */
936 unsigned char flip; /* VFLIP */
937 unsigned int winseqe_cur_addr;
938 struct sensor_datafmt fmt;
939 unsigned int funmodule_state;
940 } sensor_info_priv_t;
944 struct v4l2_subdev subdev;
945 struct i2c_client *client;
946 sensor_info_priv_t info_priv;
947 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
948 #if CONFIG_SENSOR_I2C_NOSCHED
949 atomic_t tasklock_cnt;
951 struct rk29camera_platform_data *sensor_io_request;
952 struct rk29camera_gpio_res *sensor_gpio_res;
956 static struct sensor* to_sensor(const struct i2c_client *client)
958 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
961 static int sensor_task_lock(struct i2c_client *client, int lock)
963 #if CONFIG_SENSOR_I2C_NOSCHED
965 struct sensor *sensor = to_sensor(client);
968 if (atomic_read(&sensor->tasklock_cnt) == 0) {
969 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
970 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
974 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
975 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
976 goto sensor_task_lock_err;
981 atomic_add(1, &sensor->tasklock_cnt);
983 if (atomic_read(&sensor->tasklock_cnt) > 0) {
984 atomic_sub(1, &sensor->tasklock_cnt);
986 if (atomic_read(&sensor->tasklock_cnt) == 0)
991 sensor_task_lock_err:
999 /* sensor register write */
1000 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1004 struct i2c_msg msg[1];
1006 buf[0] = reg & 0xFF;
1009 msg->addr = client->addr;
1010 msg->flags = client->flags;
1012 msg->len = sizeof(buf);
1013 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1014 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1019 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1020 err = i2c_transfer(client->adapter, msg, 1);
1025 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1033 /* sensor register read */
1034 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1038 struct i2c_msg msg[2];
1042 msg[0].addr = client->addr;
1043 msg[0].flags = client->flags;
1045 msg[0].len = sizeof(buf);
1046 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1047 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1049 msg[1].addr = client->addr;
1050 msg[1].flags = client->flags|I2C_M_RD;
1053 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1054 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1058 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1059 err = i2c_transfer(client->adapter, msg, 2);
1065 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1073 /* write a array of registers */
1074 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1078 #if CONFIG_SENSOR_I2C_RDWRCHK
1083 if (sensor_task_lock(client, 1) < 0)
1084 goto sensor_write_array_end;
1086 while (regarray[i].reg != 0)
1088 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1092 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1096 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1098 goto sensor_write_array_end;
1101 #if CONFIG_SENSOR_I2C_RDWRCHK
1102 sensor_read(client, regarray[i].reg, &valchk);
1103 if (valchk != regarray[i].val)
1104 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1110 sensor_write_array_end:
1111 sensor_task_lock(client,0);
1114 #if CONFIG_SENSOR_I2C_RDWRCHK
1115 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1123 while (regarray[i].reg != 0)
1125 sensor_read(client, regarray[i].reg, &valchk);
1126 if (valchk != regarray[i].val)
1127 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1134 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1136 struct soc_camera_link *icl = to_soc_camera_link(icd);
1139 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1142 case Sensor_PowerDown:
1144 if (icl->powerdown) {
1147 ret = icl->powerdown(icd->pdev, on);
1148 if (ret == RK29_CAM_IO_SUCCESS) {
1152 icl->reset(icd->pdev);
1154 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1156 goto sensor_power_end;
1163 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1164 struct sensor *sensor = to_sensor(client);
1166 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1167 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1173 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1180 static s32 sensor_init_width = 640;
1181 static s32 sensor_init_height = 480;
1182 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
1183 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1184 static struct reginfo* sensor_init_data_p = NULL;
1185 static struct reginfo* sensor_init_winseq_p = NULL;
1186 static struct reginfo* sensor_init_winseq_board = NULL;
1187 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1189 struct i2c_client *client = v4l2_get_subdevdata(sd);
1190 struct soc_camera_device *icd = client->dev.platform_data;
1191 struct sensor *sensor = to_sensor(client);
1192 const struct v4l2_queryctrl *qctrl;
1193 const struct sensor_datafmt *fmt;
1194 int ret,pid = 0,i = 0,j=0;
1195 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1196 sensor_init_data_p = sensor_init_data;
1197 sensor_init_winseq_p = sensor_vga;
1198 sensor_init_width = 640;
1199 sensor_init_height = 480;
1200 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1201 for(i = 0;i < RK_CAM_NUM;i++){
1202 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1203 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1207 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1208 //user has defined the init data
1210 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1211 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1212 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1213 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1215 sensor_init_data_p = sensor_init_data;
1217 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1218 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1221 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1222 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1223 if(sensor_init_winseq_board)
1225 vfree(sensor_init_winseq_board);
1226 sensor_init_winseq_board = NULL;
1228 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1229 if(!sensor_init_winseq_board)
1230 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1231 for(j = 0;j< tmp_winseq_size;j++){
1232 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1233 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1235 sensor_init_winseq_p = sensor_init_winseq_board;
1237 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1238 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1240 //init width,height,bus,pixelcode
1241 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1242 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1243 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1244 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1245 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1246 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1247 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1248 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1250 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1252 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1254 goto sensor_INIT_ERR;
1258 if (sensor_task_lock(client,1)<0)
1259 goto sensor_INIT_ERR;
1260 ret = sensor_write(client, 0x12, 0x80);
1263 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1265 goto sensor_INIT_ERR;
1267 mdelay(5); //delay 5 microseconds
1269 ret = sensor_write_array(client, sensor_init_data_p);
1272 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1273 goto sensor_INIT_ERR;
1275 sensor_task_lock(client,0);
1277 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1278 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1280 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1282 goto sensor_INIT_ERR;
1284 sensor->info_priv.fmt = *fmt;
1286 /* sensor sensor information for initialization */
1287 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1289 sensor->info_priv.whiteBalance = qctrl->default_value;
1290 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1292 sensor->info_priv.brightness = qctrl->default_value;
1293 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1295 sensor->info_priv.effect = qctrl->default_value;
1296 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1298 sensor->info_priv.exposure = qctrl->default_value;
1300 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1302 sensor->info_priv.saturation = qctrl->default_value;
1303 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1305 sensor->info_priv.contrast = qctrl->default_value;
1306 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1308 sensor->info_priv.mirror = qctrl->default_value;
1309 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1311 sensor->info_priv.flip = qctrl->default_value;
1312 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1314 sensor->info_priv.scene = qctrl->default_value;
1315 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1317 sensor->info_priv.digitalzoom = qctrl->default_value;
1319 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1320 #if CONFIG_SENSOR_Focus
1322 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1324 sensor->info_priv.focus = qctrl->default_value;
1327 #if CONFIG_SENSOR_Flash
1328 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1330 sensor->info_priv.flash = qctrl->default_value;
1333 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
1337 sensor_task_lock(client,0);
1338 sensor_deactivate(client);
1342 static int sensor_deactivate(struct i2c_client *client)
1344 struct soc_camera_device *icd = client->dev.platform_data;
1347 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1349 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1350 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1352 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1353 icd->user_width = SENSOR_INIT_WIDTH;
1354 icd->user_height = SENSOR_INIT_HEIGHT;
1358 static struct reginfo sensor_power_down_sequence[]=
1362 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1365 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1367 if (pm_msg.event == PM_EVENT_SUSPEND) {
1368 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1369 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1371 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1374 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1376 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1381 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1387 static int sensor_resume(struct soc_camera_device *icd)
1391 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1393 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1397 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1403 static int sensor_set_bus_param(struct soc_camera_device *icd,
1404 unsigned long flags)
1410 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1412 struct soc_camera_link *icl = to_soc_camera_link(icd);
1413 unsigned long flags = SENSOR_BUS_PARAM;
1415 return soc_camera_apply_sensor_flags(icl, flags);
1418 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1420 struct i2c_client *client = v4l2_get_subdevdata(sd);
1421 struct soc_camera_device *icd = client->dev.platform_data;
1422 struct sensor *sensor = to_sensor(client);
1424 mf->width = icd->user_width;
1425 mf->height = icd->user_height;
1426 mf->code = sensor->info_priv.fmt.code;
1427 mf->colorspace = sensor->info_priv.fmt.colorspace;
1428 mf->field = V4L2_FIELD_NONE;
1432 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1436 if ((mf->width == 1024) && (mf->height == 768)) {
1438 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1440 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1442 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1444 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1449 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1453 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1457 if ((mf->width == 1280) && (mf->height == 720)) {
1459 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1464 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1467 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1469 struct i2c_client *client = v4l2_get_subdevdata(sd);
1470 const struct sensor_datafmt *fmt;
1471 struct sensor *sensor = to_sensor(client);
1472 const struct v4l2_queryctrl *qctrl;
1473 struct soc_camera_device *icd = client->dev.platform_data;
1474 struct reginfo *winseqe_set_addr=NULL;
1476 int ret=0, set_w,set_h;
1478 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1479 ARRAY_SIZE(sensor_colour_fmts));
1482 goto sensor_s_fmt_end;
1485 if (sensor->info_priv.fmt.code != mf->code) {
1488 case V4L2_MBUS_FMT_YUYV8_2X8:
1490 //winseqe_set_addr = sensor_ClrFmt_YUYV;
1491 sensor_read(client, 0x3a, &readval);
1492 sensor_write(client,0x3a, readval&0xf7);
1493 sensor_read(client,0x3d,&readval);
1494 sensor_write(client,0x3d,readval&0xfe);
1497 case V4L2_MBUS_FMT_UYVY8_2X8:
1499 //winseqe_set_addr = sensor_ClrFmt_UYVY;
1500 sensor_read(client, 0x3a, &readval);
1501 sensor_write(client,0x3a, readval|0x08);
1502 sensor_read(client,0x3d,&readval);
1503 sensor_write(client,0x3d,readval&0xfe);
1509 if (winseqe_set_addr != NULL) {
1510 sensor_write_array(client, winseqe_set_addr);
1511 sensor->info_priv.fmt.code = mf->code;
1512 sensor->info_priv.fmt.colorspace= mf->colorspace;
1513 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1515 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1522 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1524 winseqe_set_addr = sensor_qcif;
1528 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1530 winseqe_set_addr = sensor_qvga;
1534 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1536 winseqe_set_addr = sensor_cif;
1540 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1542 winseqe_set_addr = sensor_vga;
1546 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1548 winseqe_set_addr = sensor_svga;
1552 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
1554 winseqe_set_addr = sensor_720p;
1558 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1560 winseqe_set_addr = sensor_xga;
1564 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1566 winseqe_set_addr = sensor_vga; //sensor_sxga;
1570 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1572 winseqe_set_addr = sensor_uxga;
1578 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1579 set_w = SENSOR_INIT_WIDTH;
1580 set_h = SENSOR_INIT_HEIGHT;
1581 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1584 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1585 #if CONFIG_SENSOR_Flash
1586 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1587 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1588 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1589 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1591 } else { /* ddl@rock-chips.com : Video */
1592 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1593 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1594 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1598 ret |= sensor_write_array(client, winseqe_set_addr);
1600 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1601 #if CONFIG_SENSOR_Flash
1602 if (sensor_fmt_capturechk(sd,mf) == true) {
1603 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1604 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1605 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1609 goto sensor_s_fmt_end;
1612 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1614 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1615 #if CONFIG_SENSOR_Effect
1616 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1617 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1619 #if CONFIG_SENSOR_WhiteBalance
1620 if (sensor->info_priv.whiteBalance != 0) {
1621 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1622 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1625 sensor->info_priv.snap2preview = true;
1626 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1627 #if CONFIG_SENSOR_Effect
1628 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1629 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1631 #if CONFIG_SENSOR_WhiteBalance
1632 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1633 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1635 sensor->info_priv.video2preview = true;
1636 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1637 #if CONFIG_SENSOR_Effect
1638 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1639 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1641 #if CONFIG_SENSOR_WhiteBalance
1642 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1643 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1645 sensor->info_priv.video2preview = false;
1646 sensor->info_priv.snap2preview = false;
1649 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1653 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1663 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1665 struct i2c_client *client = v4l2_get_subdevdata(sd);
1666 struct sensor *sensor = to_sensor(client);
1667 const struct sensor_datafmt *fmt;
1670 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1671 ARRAY_SIZE(sensor_colour_fmts));
1673 fmt = &sensor->info_priv.fmt;
1674 mf->code = fmt->code;
1677 if (mf->height > SENSOR_MAX_HEIGHT)
1678 mf->height = SENSOR_MAX_HEIGHT;
1679 else if (mf->height < SENSOR_MIN_HEIGHT)
1680 mf->height = SENSOR_MIN_HEIGHT;
1682 if (mf->width > SENSOR_MAX_WIDTH)
1683 mf->width = SENSOR_MAX_WIDTH;
1684 else if (mf->width < SENSOR_MIN_WIDTH)
1685 mf->width = SENSOR_MIN_WIDTH;
1687 mf->colorspace = fmt->colorspace;
1692 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1694 struct i2c_client *client = v4l2_get_subdevdata(sd);
1696 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1699 if (id->match.addr != client->addr)
1702 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1707 #if CONFIG_SENSOR_Brightness
1708 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1710 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1712 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1714 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1716 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1718 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1721 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1725 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1729 #if CONFIG_SENSOR_Effect
1730 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1732 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1734 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1736 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1738 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1740 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1743 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1747 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1751 #if CONFIG_SENSOR_Exposure
1752 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1754 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1756 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1758 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1760 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1762 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1765 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1769 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1773 #if CONFIG_SENSOR_Saturation
1774 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1776 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1778 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1780 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1782 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1784 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1787 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1791 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1795 #if CONFIG_SENSOR_Contrast
1796 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1798 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1800 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1802 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1804 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1806 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1809 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1813 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1817 #if CONFIG_SENSOR_Mirror
1818 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1820 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1822 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1824 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1826 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1828 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1831 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1835 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1839 #if CONFIG_SENSOR_Flip
1840 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1842 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1844 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1846 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1848 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1850 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1853 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1857 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1861 #if CONFIG_SENSOR_Scene
1862 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1864 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1866 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1868 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1870 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1872 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1875 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1879 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1883 #if CONFIG_SENSOR_WhiteBalance
1884 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1886 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1888 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1890 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1892 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1894 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1897 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1901 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1905 #if CONFIG_SENSOR_DigitalZoom
1906 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
1908 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1909 struct sensor *sensor = to_sensor(client);
1910 const struct v4l2_queryctrl *qctrl_info;
1911 int digitalzoom_cur, digitalzoom_total;
1913 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1917 digitalzoom_cur = sensor->info_priv.digitalzoom;
1918 digitalzoom_total = qctrl_info->maximum;
1920 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
1922 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1926 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
1928 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1932 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
1934 value = digitalzoom_total - digitalzoom_cur;
1937 if ((value < 0) && ((digitalzoom_cur + value) < 0))
1939 value = 0 - digitalzoom_cur;
1942 digitalzoom_cur += value;
1944 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
1946 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
1948 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1951 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1958 #if CONFIG_SENSOR_Flash
1959 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1961 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
1962 if (value == 3) { /* ddl@rock-chips.com: torch */
1963 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
1965 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1967 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1971 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1976 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1978 struct i2c_client *client = v4l2_get_subdevdata(sd);
1979 struct sensor *sensor = to_sensor(client);
1980 const struct v4l2_queryctrl *qctrl;
1982 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1986 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1992 case V4L2_CID_BRIGHTNESS:
1994 ctrl->value = sensor->info_priv.brightness;
1997 case V4L2_CID_SATURATION:
1999 ctrl->value = sensor->info_priv.saturation;
2002 case V4L2_CID_CONTRAST:
2004 ctrl->value = sensor->info_priv.contrast;
2007 case V4L2_CID_DO_WHITE_BALANCE:
2009 ctrl->value = sensor->info_priv.whiteBalance;
2012 case V4L2_CID_EXPOSURE:
2014 ctrl->value = sensor->info_priv.exposure;
2017 case V4L2_CID_HFLIP:
2019 ctrl->value = sensor->info_priv.mirror;
2022 case V4L2_CID_VFLIP:
2024 ctrl->value = sensor->info_priv.flip;
2035 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2037 struct i2c_client *client = v4l2_get_subdevdata(sd);
2038 struct sensor *sensor = to_sensor(client);
2039 struct soc_camera_device *icd = client->dev.platform_data;
2040 const struct v4l2_queryctrl *qctrl;
2043 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2047 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2053 #if CONFIG_SENSOR_Brightness
2054 case V4L2_CID_BRIGHTNESS:
2056 if (ctrl->value != sensor->info_priv.brightness)
2058 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2062 sensor->info_priv.brightness = ctrl->value;
2067 #if CONFIG_SENSOR_Exposure
2068 case V4L2_CID_EXPOSURE:
2070 if (ctrl->value != sensor->info_priv.exposure)
2072 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2076 sensor->info_priv.exposure = ctrl->value;
2081 #if CONFIG_SENSOR_Saturation
2082 case V4L2_CID_SATURATION:
2084 if (ctrl->value != sensor->info_priv.saturation)
2086 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2090 sensor->info_priv.saturation = ctrl->value;
2095 #if CONFIG_SENSOR_Contrast
2096 case V4L2_CID_CONTRAST:
2098 if (ctrl->value != sensor->info_priv.contrast)
2100 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2104 sensor->info_priv.contrast = ctrl->value;
2109 #if CONFIG_SENSOR_WhiteBalance
2110 case V4L2_CID_DO_WHITE_BALANCE:
2112 if (ctrl->value != sensor->info_priv.whiteBalance)
2114 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2118 sensor->info_priv.whiteBalance = ctrl->value;
2123 #if CONFIG_SENSOR_Mirror
2124 case V4L2_CID_HFLIP:
2126 if (ctrl->value != sensor->info_priv.mirror)
2128 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2130 sensor->info_priv.mirror = ctrl->value;
2135 #if CONFIG_SENSOR_Flip
2136 case V4L2_CID_VFLIP:
2138 if (ctrl->value != sensor->info_priv.flip)
2140 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2142 sensor->info_priv.flip = ctrl->value;
2153 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2155 const struct v4l2_queryctrl *qctrl;
2156 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2157 struct sensor *sensor = to_sensor(client);
2159 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2163 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2167 switch (ext_ctrl->id)
2169 case V4L2_CID_SCENE:
2171 ext_ctrl->value = sensor->info_priv.scene;
2174 case V4L2_CID_EFFECT:
2176 ext_ctrl->value = sensor->info_priv.effect;
2179 case V4L2_CID_ZOOM_ABSOLUTE:
2181 ext_ctrl->value = sensor->info_priv.digitalzoom;
2184 case V4L2_CID_ZOOM_RELATIVE:
2188 case V4L2_CID_FOCUS_ABSOLUTE:
2190 ext_ctrl->value = sensor->info_priv.focus;
2193 case V4L2_CID_FOCUS_RELATIVE:
2197 case V4L2_CID_FLASH:
2199 ext_ctrl->value = sensor->info_priv.flash;
2207 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2209 const struct v4l2_queryctrl *qctrl;
2210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2211 struct sensor *sensor = to_sensor(client);
2214 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2218 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2223 switch (ext_ctrl->id)
2225 #if CONFIG_SENSOR_Scene
2226 case V4L2_CID_SCENE:
2228 if (ext_ctrl->value != sensor->info_priv.scene)
2230 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2232 sensor->info_priv.scene = ext_ctrl->value;
2237 #if CONFIG_SENSOR_Effect
2238 case V4L2_CID_EFFECT:
2240 if (ext_ctrl->value != sensor->info_priv.effect)
2242 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2244 sensor->info_priv.effect= ext_ctrl->value;
2249 #if CONFIG_SENSOR_DigitalZoom
2250 case V4L2_CID_ZOOM_ABSOLUTE:
2252 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2255 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2257 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2259 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2261 sensor->info_priv.digitalzoom += val_offset;
2263 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2268 case V4L2_CID_ZOOM_RELATIVE:
2270 if (ext_ctrl->value)
2272 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2274 sensor->info_priv.digitalzoom += ext_ctrl->value;
2276 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2281 #if CONFIG_SENSOR_Focus
2282 case V4L2_CID_FOCUS_ABSOLUTE:
2284 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2287 if (ext_ctrl->value != sensor->info_priv.focus)
2289 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2291 sensor->info_priv.focus += val_offset;
2296 case V4L2_CID_FOCUS_RELATIVE:
2298 if (ext_ctrl->value)
2300 sensor->info_priv.focus += ext_ctrl->value;
2302 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2307 #if CONFIG_SENSOR_Flash
2308 case V4L2_CID_FLASH:
2310 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2312 sensor->info_priv.flash = ext_ctrl->value;
2314 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2325 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2327 struct i2c_client *client = v4l2_get_subdevdata(sd);
2328 struct soc_camera_device *icd = client->dev.platform_data;
2329 int i, error_cnt=0, error_idx=-1;
2332 for (i=0; i<ext_ctrl->count; i++) {
2333 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2340 error_idx = ext_ctrl->count;
2342 if (error_idx != -1) {
2343 ext_ctrl->error_idx = error_idx;
2350 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2352 struct i2c_client *client = v4l2_get_subdevdata(sd);
2353 struct soc_camera_device *icd = client->dev.platform_data;
2354 int i, error_cnt=0, error_idx=-1;
2357 for (i=0; i<ext_ctrl->count; i++) {
2358 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2365 error_idx = ext_ctrl->count;
2367 if (error_idx != -1) {
2368 ext_ctrl->error_idx = error_idx;
2375 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2376 * this wasn't our capture interface, so, we wait for the right one */
2377 static int sensor_video_probe(struct soc_camera_device *icd,
2378 struct i2c_client *client)
2382 struct sensor *sensor = to_sensor(client);
2384 /* We must have a parent by now. And it cannot be a wrong one.
2385 * So this entire test is completely redundant. */
2386 if (!icd->dev.parent ||
2387 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2390 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2392 goto sensor_video_probe_err;
2395 ret = sensor_write(client, 0x12, 0x80);
2398 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2401 mdelay(50); //delay 5 microseconds
2403 /* check if it is an sensor sensor */
2404 ret = sensor_read(client, 0x0a, &pid);
2406 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2408 goto sensor_video_probe_err;
2411 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2412 if (pid == SENSOR_ID) {
2413 sensor->model = SENSOR_V4L2_IDENT;
2415 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2417 goto sensor_video_probe_err;
2422 sensor_video_probe_err:
2427 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2429 struct i2c_client *client = v4l2_get_subdevdata(sd);
2430 struct soc_camera_device *icd = client->dev.platform_data;
2431 struct sensor *sensor = to_sensor(client);
2433 #if CONFIG_SENSOR_Flash
2437 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2440 case RK29_CAM_SUBDEV_DEACTIVATE:
2442 sensor_deactivate(client);
2446 case RK29_CAM_SUBDEV_IOREQUEST:
2448 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2449 if (sensor->sensor_io_request != NULL) {
2451 for(j = 0;j < RK_CAM_NUM;j++){
2452 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2453 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2454 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2458 if(j == RK_CAM_NUM){
2459 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2461 goto sensor_ioctl_end;
2464 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2466 #if CONFIG_SENSOR_Flash
2467 if (sensor->sensor_gpio_res) {
2468 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2469 for (i = 0; i < icd->ops->num_controls; i++) {
2470 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2471 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2474 sensor->info_priv.flash = 0xff;
2475 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2483 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2491 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2492 enum v4l2_mbus_pixelcode *code)
2494 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2497 *code = sensor_colour_fmts[index].code;
2500 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2501 .init = sensor_init,
2502 .g_ctrl = sensor_g_control,
2503 .s_ctrl = sensor_s_control,
2504 .g_ext_ctrls = sensor_g_ext_controls,
2505 .s_ext_ctrls = sensor_s_ext_controls,
2506 .g_chip_ident = sensor_g_chip_ident,
2507 .ioctl = sensor_ioctl,
2510 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2511 .s_mbus_fmt = sensor_s_fmt,
2512 .g_mbus_fmt = sensor_g_fmt,
2513 .try_mbus_fmt = sensor_try_fmt,
2514 .enum_mbus_fmt = sensor_enum_fmt,
2516 static struct v4l2_subdev_ops sensor_subdev_ops = {
2517 .core = &sensor_subdev_core_ops,
2518 .video = &sensor_subdev_video_ops,
2521 static int sensor_probe(struct i2c_client *client,
2522 const struct i2c_device_id *did)
2524 struct sensor *sensor;
2525 struct soc_camera_device *icd = client->dev.platform_data;
2526 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2527 struct soc_camera_link *icl;
2530 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2532 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2536 icl = to_soc_camera_link(icd);
2538 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2542 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2543 dev_warn(&adapter->dev,
2544 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2548 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2552 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2554 /* Second stage probe - when a capture adapter is there */
2555 icd->ops = &sensor_ops;
2557 sensor->info_priv.fmt = sensor_colour_fmts[0];
2559 #if CONFIG_SENSOR_I2C_NOSCHED
2560 atomic_set(&sensor->tasklock_cnt,0);
2563 ret = sensor_video_probe(icd, client);
2566 i2c_set_clientdata(client, NULL);
2570 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2574 static int sensor_remove(struct i2c_client *client)
2576 struct sensor *sensor = to_sensor(client);
2577 struct soc_camera_device *icd = client->dev.platform_data;
2580 i2c_set_clientdata(client, NULL);
2581 client->driver = NULL;
2587 static const struct i2c_device_id sensor_id[] = {
2588 {SENSOR_NAME_STRING(), 0 },
2591 MODULE_DEVICE_TABLE(i2c, sensor_id);
2593 static struct i2c_driver sensor_i2c_driver = {
2595 .name = SENSOR_NAME_STRING(),
2597 .probe = sensor_probe,
2598 .remove = sensor_remove,
2599 .id_table = sensor_id,
2602 static int __init sensor_mod_init(void)
2604 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2605 return i2c_add_driver(&sensor_i2c_driver);
2608 static void __exit sensor_mod_exit(void)
2610 i2c_del_driver(&sensor_i2c_driver);
2613 device_initcall_sync(sensor_mod_init);
2614 module_exit(sensor_mod_exit);
2616 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2617 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2618 MODULE_LICENSE("GPL");