3 o* Driver for MT9M001 CMOS Image Sensor from Micron
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/videodev2.h>
13 #include <linux/slab.h>
14 #include <linux/i2c.h>
15 #include <linux/log2.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/circ_buf.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <mach/rk_camera.h>
24 #include <linux/vmalloc.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK_CAM_SENSOR_OV7675
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV7675
49 #define SENSOR_ID 0x76
50 #define SENSOR_MIN_WIDTH 640//176
51 #define SENSOR_MIN_HEIGHT 480//144
52 #define SENSOR_MAX_WIDTH 640
53 #define SENSOR_MAX_HEIGHT 480
54 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT sensor_init_height
56 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
57 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
58 #define SENSOR_BUS_PARAM sensor_init_busparam
60 #define CONFIG_SENSOR_WhiteBalance 0
61 #define CONFIG_SENSOR_Brightness 0
62 #define CONFIG_SENSOR_Contrast 0
63 #define CONFIG_SENSOR_Saturation 0
64 #define CONFIG_SENSOR_Effect 1
65 #define CONFIG_SENSOR_Scene 0
66 #define CONFIG_SENSOR_DigitalZoom 0
67 #define CONFIG_SENSOR_Focus 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
73 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
74 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
75 #define CONFIG_SENSOR_I2C_NOSCHED 0
76 #define CONFIG_SENSOR_I2C_RDWRCHK 0
78 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
79 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
80 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
81 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
82 #define COLOR_TEMPERATURE_OFFICE_DN 3500
83 #define COLOR_TEMPERATURE_OFFICE_UP 5000
84 #define COLOR_TEMPERATURE_HOME_DN 2500
85 #define COLOR_TEMPERATURE_HOME_UP 3500
87 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
88 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
95 static s32 sensor_init_width = 0;
96 static s32 sensor_init_height = 0;
97 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);
98 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
99 static struct reginfo* sensor_init_data_p = NULL;
100 static struct reginfo* sensor_init_winseq_p = NULL;
101 static struct reginfo* sensor_init_winseq_board = NULL;
102 /* init 800*600 SVGA */
103 static struct reginfo sensor_init_data[] =
150 {0x1e, 0x17}, //0x07//0x27
187 {0x7a, 0x20},// {0x7a, 0x24},
188 {0x7b, 0x16},// {0x7b, 0x04},
189 {0x7c, 0x23},// {0x7c, 0x07},
190 {0x7d, 0x3c},// {0x7d, 0x12},
191 {0x7e, 0x5c},// {0x7e, 0x2f},
192 {0x7f, 0x69},// {0x7f, 0x3f},
193 {0x80, 0x75},// {0x80, 0x4d},
194 {0x81, 0x7e},// {0x81, 0x5a},
195 {0x82, 0x88},// {0x82, 0x69},
196 {0x83, 0x8f},// {0x83, 0x74},
197 {0x84, 0x96},// {0x84, 0x7f},
198 {0x85, 0xa3},// {0x85, 0x91},
199 {0x86, 0xaf},// {0x86, 0x9e},
200 {0x87, 0xc4},// {0x87, 0xbb},
201 {0x88, 0xd7},// {0x88, 0xd2},
202 {0x89, 0xe8},// {0x89, 0xe5},
279 static struct reginfo sensor_sxga[] =
285 static struct reginfo sensor_svga[] =
291 static struct reginfo sensor_vga[] =
303 static struct reginfo sensor_cif[] =
309 static struct reginfo sensor_qvga[] =
315 static struct reginfo sensor_qcif[] =
320 static struct reginfo sensor_ClrFmt_YUYV[]=
325 static struct reginfo sensor_ClrFmt_UYVY[]=
331 #if CONFIG_SENSOR_WhiteBalance
332 static struct reginfo sensor_WhiteB_Auto[]=
334 {0x84, 0x6C}, //Contrast 4
358 {0x0f, 0x4a}, //Saturation 3
370 {0x4f, 0x2e}, //Brightness 3
384 /* Cloudy Colour Temperature : 6500K - 8000K */
385 static struct reginfo sensor_WhiteB_Cloudy[]=
387 {0x7C,0x04}, //Contrast 5
421 {0x4f,0x3a}, //Saturation 4
427 {0x4f, 0x2e}, //Brightness 3
440 /* ClearDay Colour Temperature : 5000K - 6500K */
441 static struct reginfo sensor_WhiteB_ClearDay[]=
444 {0x7C,0x04}, //Contrast 5
478 {0x4f,0x3a}, //Saturation 4
484 {0x4f, 0x2e}, //Brightness 3
497 /* Office Colour Temperature : 3500K - 5000K */
498 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
501 {0x84, 0x6C}, //Contrast 4
525 {0x0f, 0x4a}, //Saturation 3
537 {0x4f, 0x2e}, //Brightness 3
553 /* Home Colour Temperature : 2500K - 3500K */
554 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
557 {0x84, 0x6C}, //Contrast 4
581 {0x0f, 0x4a}, //Saturation 3
593 {0x4f, 0x2e}, //Brightness 3
606 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
607 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
611 #if CONFIG_SENSOR_Brightness
612 static struct reginfo sensor_Brightness0[]=
615 {0x3301, 0xff},//bit[7]:1, enable SDE
622 static struct reginfo sensor_Brightness1[]=
625 {0x3301, 0xff},//bit[7]:1, enable SDE
632 static struct reginfo sensor_Brightness2[]=
635 {0x3301, 0xff},//bit[7]:1, enable SDE
642 static struct reginfo sensor_Brightness3[]=
645 {0x3301, 0xff},//bit[7]:1, enable SDE
652 static struct reginfo sensor_Brightness4[]=
655 {0x3301, 0xff},//bit[7]:1, enable SDE
662 static struct reginfo sensor_Brightness5[]=
665 {0x3301, 0xff},//bit[7]:1, enable SDE
666 {0x3391, 0x04}, //bit[2] enable
667 {0x3390, 0x41}, //bit[3] sign of brightness
671 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
672 sensor_Brightness4, sensor_Brightness5,NULL,
677 #if CONFIG_SENSOR_Effect
678 static struct reginfo sensor_Effect_Normal[] =
686 static struct reginfo sensor_Effect_WandB[] =
694 static struct reginfo sensor_Effect_Sepia[] =
702 static struct reginfo sensor_Effect_Negative[] =
710 static struct reginfo sensor_Effect_Bluish[] =
719 static struct reginfo sensor_Effect_Green[] =
727 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
728 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
731 #if CONFIG_SENSOR_Exposure
732 static struct reginfo sensor_Exposure0[]=
737 static struct reginfo sensor_Exposure1[]=
742 static struct reginfo sensor_Exposure2[]=
747 static struct reginfo sensor_Exposure3[]=
752 static struct reginfo sensor_Exposure4[]=
757 static struct reginfo sensor_Exposure5[]=
762 static struct reginfo sensor_Exposure6[]=
767 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
768 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
771 #if CONFIG_SENSOR_Saturation
772 static struct reginfo sensor_Saturation0[]=
777 static struct reginfo sensor_Saturation1[]=
782 static struct reginfo sensor_Saturation2[]=
786 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
789 #if CONFIG_SENSOR_Contrast
790 static struct reginfo sensor_Contrast0[]=
795 static struct reginfo sensor_Contrast1[]=
800 static struct reginfo sensor_Contrast2[]=
805 static struct reginfo sensor_Contrast3[]=
810 static struct reginfo sensor_Contrast4[]=
816 static struct reginfo sensor_Contrast5[]=
821 static struct reginfo sensor_Contrast6[]=
825 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
826 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
830 #if CONFIG_SENSOR_Mirror
831 static struct reginfo sensor_MirrorOn[]=
836 static struct reginfo sensor_MirrorOff[]=
840 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
842 #if CONFIG_SENSOR_Flip
843 static struct reginfo sensor_FlipOn[]=
848 static struct reginfo sensor_FlipOff[]=
852 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
855 #if CONFIG_SENSOR_Scene
856 static struct reginfo sensor_SceneAuto[] =
861 static struct reginfo sensor_SceneNight[] =
865 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
868 #if CONFIG_SENSOR_DigitalZoom
869 static struct reginfo sensor_Zoom0[] =
874 static struct reginfo sensor_Zoom1[] =
879 static struct reginfo sensor_Zoom2[] =
885 static struct reginfo sensor_Zoom3[] =
889 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
891 static const struct v4l2_querymenu sensor_menus[] =
893 #if CONFIG_SENSOR_WhiteBalance
894 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
895 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
896 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
899 #if CONFIG_SENSOR_Effect
900 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
901 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
902 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
905 #if CONFIG_SENSOR_Scene
906 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
909 #if CONFIG_SENSOR_Flash
910 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
911 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
915 static const struct v4l2_queryctrl sensor_controls[] =
917 #if CONFIG_SENSOR_WhiteBalance
919 .id = V4L2_CID_DO_WHITE_BALANCE,
920 .type = V4L2_CTRL_TYPE_MENU,
921 .name = "White Balance Control",
929 #if CONFIG_SENSOR_Brightness
931 .id = V4L2_CID_BRIGHTNESS,
932 .type = V4L2_CTRL_TYPE_INTEGER,
933 .name = "Brightness Control",
941 #if CONFIG_SENSOR_Effect
943 .id = V4L2_CID_EFFECT,
944 .type = V4L2_CTRL_TYPE_MENU,
945 .name = "Effect Control",
953 #if CONFIG_SENSOR_Exposure
955 .id = V4L2_CID_EXPOSURE,
956 .type = V4L2_CTRL_TYPE_INTEGER,
957 .name = "Exposure Control",
965 #if CONFIG_SENSOR_Saturation
967 .id = V4L2_CID_SATURATION,
968 .type = V4L2_CTRL_TYPE_INTEGER,
969 .name = "Saturation Control",
977 #if CONFIG_SENSOR_Contrast
979 .id = V4L2_CID_CONTRAST,
980 .type = V4L2_CTRL_TYPE_INTEGER,
981 .name = "Contrast Control",
989 #if CONFIG_SENSOR_Mirror
991 .id = V4L2_CID_HFLIP,
992 .type = V4L2_CTRL_TYPE_BOOLEAN,
993 .name = "Mirror Control",
1001 #if CONFIG_SENSOR_Flip
1003 .id = V4L2_CID_VFLIP,
1004 .type = V4L2_CTRL_TYPE_BOOLEAN,
1005 .name = "Flip Control",
1013 #if CONFIG_SENSOR_Scene
1015 .id = V4L2_CID_SCENE,
1016 .type = V4L2_CTRL_TYPE_MENU,
1017 .name = "Scene Control",
1025 #if CONFIG_SENSOR_DigitalZoom
1027 .id = V4L2_CID_ZOOM_RELATIVE,
1028 .type = V4L2_CTRL_TYPE_INTEGER,
1029 .name = "DigitalZoom Control",
1035 .id = V4L2_CID_ZOOM_ABSOLUTE,
1036 .type = V4L2_CTRL_TYPE_INTEGER,
1037 .name = "DigitalZoom Control",
1045 #if CONFIG_SENSOR_Focus
1047 .id = V4L2_CID_FOCUS_RELATIVE,
1048 .type = V4L2_CTRL_TYPE_INTEGER,
1049 .name = "Focus Control",
1055 .id = V4L2_CID_FOCUS_ABSOLUTE,
1056 .type = V4L2_CTRL_TYPE_INTEGER,
1057 .name = "Focus Control",
1061 .default_value = 125,
1065 #if CONFIG_SENSOR_Flash
1067 .id = V4L2_CID_FLASH,
1068 .type = V4L2_CTRL_TYPE_MENU,
1069 .name = "Flash Control",
1078 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1079 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1080 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1081 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1082 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1083 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1084 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1085 static int sensor_resume(struct soc_camera_device *icd);
1086 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1087 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1088 #if CONFIG_SENSOR_Effect
1089 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1091 #if CONFIG_SENSOR_WhiteBalance
1092 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1094 static int sensor_deactivate(struct i2c_client *client);
1097 static struct soc_camera_ops sensor_ops =
1099 .suspend = sensor_suspend,
1100 .resume = sensor_resume,
1101 .set_bus_param = sensor_set_bus_param,
1102 .query_bus_param = sensor_query_bus_param,
1103 .controls = sensor_controls,
1104 .menus = sensor_menus,
1105 .num_controls = ARRAY_SIZE(sensor_controls),
1106 .num_menus = ARRAY_SIZE(sensor_menus),
1109 /* only one fixed colorspace per pixelcode */
1110 struct sensor_datafmt {
1111 enum v4l2_mbus_pixelcode code;
1112 enum v4l2_colorspace colorspace;
1115 /* Find a data format by a pixel code in an array */
1116 static const struct sensor_datafmt *sensor_find_datafmt(
1117 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1121 for (i = 0; i < n; i++)
1122 if (fmt[i].code == code)
1128 static const struct sensor_datafmt sensor_colour_fmts[] = {
1129 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1130 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1133 typedef struct sensor_info_priv_s
1147 unsigned char mirror; /* HFLIP */
1148 unsigned char flip; /* VFLIP */
1149 unsigned int winseqe_cur_addr;
1150 struct sensor_datafmt fmt;
1152 } sensor_info_priv_t;
1156 struct v4l2_subdev subdev;
1157 struct i2c_client *client;
1158 sensor_info_priv_t info_priv;
1159 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1160 #if CONFIG_SENSOR_I2C_NOSCHED
1161 atomic_t tasklock_cnt;
1163 struct rkcamera_platform_data *sensor_io_request;
1164 struct rkcamera_gpio_res *sensor_gpio_res;
1167 static struct sensor* to_sensor(const struct i2c_client *client)
1169 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1172 static int sensor_task_lock(struct i2c_client *client, int lock)
1174 #if CONFIG_SENSOR_I2C_NOSCHED
1176 struct sensor *sensor = to_sensor(client);
1179 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1180 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1181 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1185 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1186 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1187 goto sensor_task_lock_err;
1192 atomic_add(1, &sensor->tasklock_cnt);
1194 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1195 atomic_sub(1, &sensor->tasklock_cnt);
1197 if (atomic_read(&sensor->tasklock_cnt) == 0)
1202 sensor_task_lock_err:
1210 /* sensor register write */
1211 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1215 struct i2c_msg msg[1];
1217 buf[0] = reg & 0xFF;
1220 msg->addr = client->addr;
1221 msg->flags = client->flags;
1223 msg->len = sizeof(buf);
1224 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1225 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1230 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1231 err = i2c_transfer(client->adapter, msg, 1);
1236 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1244 /* sensor register read */
1245 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1249 struct i2c_msg msg[2];
1253 msg[0].addr = client->addr;
1254 msg[0].flags = client->flags;
1256 msg[0].len = sizeof(buf);
1257 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1258 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1260 msg[1].addr = client->addr;
1261 msg[1].flags = client->flags|I2C_M_RD;
1264 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1265 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1269 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1270 err = i2c_transfer(client->adapter, msg, 2);
1276 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1284 /* write a array of registers */
1285 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1289 #if CONFIG_SENSOR_I2C_RDWRCHK
1294 if (sensor_task_lock(client, 1) < 0)
1295 goto sensor_write_array_end;
1297 while (regarray[i].reg != 0)
1299 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1303 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1307 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1309 goto sensor_write_array_end;
1312 #if CONFIG_SENSOR_I2C_RDWRCHK
1313 sensor_read(client, regarray[i].reg, &valchk);
1314 if (valchk != regarray[i].val)
1315 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1321 sensor_write_array_end:
1322 sensor_task_lock(client,0);
1325 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1333 while (regarray[i].reg != 0)
1335 sensor_read(client, regarray[i].reg, &valchk);
1336 if (valchk != regarray[i].val)
1337 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1343 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1345 struct soc_camera_link *icl = to_soc_camera_link(icd);
1348 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1351 case Sensor_PowerDown:
1353 if (icl->powerdown) {
1356 ret = icl->powerdown(icd->pdev, on);
1357 if (ret == RK_CAM_IO_SUCCESS) {
1361 icl->reset(icd->pdev);
1363 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1365 goto sensor_power_end;
1372 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1373 struct sensor *sensor = to_sensor(client);
1375 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1376 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1382 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1389 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1391 struct i2c_client *client = v4l2_get_subdevdata(sd);
1392 struct soc_camera_device *icd = client->dev.platform_data;
1393 struct sensor *sensor = to_sensor(client);
1394 const struct v4l2_queryctrl *qctrl;
1395 const struct sensor_datafmt *fmt;
1396 int ret,pid = 0,i = 0,j=0;
1397 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1398 sensor_init_data_p = sensor_init_data;
1399 sensor_init_winseq_p = sensor_svga;
1400 sensor_init_width = 800;
1401 sensor_init_height = 600;
1402 if (tmp_plat_data != NULL) {
1403 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1404 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1405 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1409 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1410 //user has defined the init data
1412 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1413 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1414 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1415 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1417 sensor_init_data_p = sensor_init_data;
1419 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1420 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1423 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1424 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1425 if(sensor_init_winseq_board)
1427 vfree(sensor_init_winseq_board);
1428 sensor_init_winseq_board = NULL;
1430 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1431 if(!sensor_init_winseq_board)
1432 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1433 for(j = 0;j< tmp_winseq_size;j++){
1434 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1435 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1437 sensor_init_winseq_p = sensor_init_winseq_board;
1439 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1440 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1442 //init width,height,bus,pixelcode
1443 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1444 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1445 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1446 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1447 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1448 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1449 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1450 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1453 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1455 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1457 goto sensor_INIT_ERR;
1461 if (sensor_task_lock(client,1)<0)
1462 goto sensor_INIT_ERR;
1463 ret = sensor_write(client, 0x12, 0x80);
1466 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1468 goto sensor_INIT_ERR;
1471 mdelay(5); //delay 5 microseconds
1473 ret = sensor_write_array(client, sensor_init_data_p);
1476 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1477 goto sensor_INIT_ERR;
1479 sensor_task_lock(client,0);
1480 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1481 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1483 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1485 goto sensor_INIT_ERR;
1487 sensor->info_priv.fmt = *fmt;
1489 /* sensor sensor information for initialization */
1490 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1492 sensor->info_priv.whiteBalance = qctrl->default_value;
1493 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1495 sensor->info_priv.brightness = qctrl->default_value;
1496 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1498 sensor->info_priv.effect = qctrl->default_value;
1499 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1501 sensor->info_priv.exposure = qctrl->default_value;
1503 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1505 sensor->info_priv.saturation = qctrl->default_value;
1506 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1508 sensor->info_priv.contrast = qctrl->default_value;
1509 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1511 sensor->info_priv.mirror = qctrl->default_value;
1512 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1514 sensor->info_priv.flip = qctrl->default_value;
1515 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1517 sensor->info_priv.scene = qctrl->default_value;
1518 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1520 sensor->info_priv.digitalzoom = qctrl->default_value;
1522 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1523 #if CONFIG_SENSOR_Focus
1525 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1527 sensor->info_priv.focus = qctrl->default_value;
1530 #if CONFIG_SENSOR_Flash
1531 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1533 sensor->info_priv.flash = qctrl->default_value;
1536 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);
1540 sensor_task_lock(client,0);
1541 sensor_deactivate(client);
1545 static int sensor_deactivate(struct i2c_client *client)
1547 struct soc_camera_device *icd = client->dev.platform_data;
1550 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1552 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1553 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1555 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1556 icd->user_width = SENSOR_INIT_WIDTH;
1557 icd->user_height = SENSOR_INIT_HEIGHT;
1561 static struct reginfo sensor_power_down_sequence[]=
1565 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1568 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1570 if (pm_msg.event == PM_EVENT_SUSPEND) {
1571 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1572 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1574 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1577 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1579 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1584 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1590 static int sensor_resume(struct soc_camera_device *icd)
1594 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1596 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1600 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1606 static int sensor_set_bus_param(struct soc_camera_device *icd,
1607 unsigned long flags)
1613 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1615 struct soc_camera_link *icl = to_soc_camera_link(icd);
1616 unsigned long flags = SENSOR_BUS_PARAM;
1618 return soc_camera_apply_sensor_flags(icl, flags);
1621 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1623 struct i2c_client *client = v4l2_get_subdevdata(sd);
1624 struct soc_camera_device *icd = client->dev.platform_data;
1625 struct sensor *sensor = to_sensor(client);
1627 mf->width = icd->user_width;
1628 mf->height = icd->user_height;
1629 mf->code = sensor->info_priv.fmt.code;
1630 mf->colorspace = sensor->info_priv.fmt.colorspace;
1631 mf->field = V4L2_FIELD_NONE;
1635 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1639 if ((mf->width == 1024) && (mf->height == 768)) {
1641 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1643 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1645 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1647 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1652 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1656 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1660 if ((mf->width == 1280) && (mf->height == 720)) {
1662 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1667 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1670 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1672 struct i2c_client *client = v4l2_get_subdevdata(sd);
1673 struct sensor *sensor = to_sensor(client);
1674 const struct sensor_datafmt *fmt;
1675 const struct v4l2_queryctrl *qctrl;
1676 struct soc_camera_device *icd = client->dev.platform_data;
1677 struct reginfo *winseqe_set_addr=NULL;
1679 int ret=0, set_w,set_h;
1681 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1682 ARRAY_SIZE(sensor_colour_fmts));
1685 goto sensor_s_fmt_end;
1688 if (sensor->info_priv.fmt.code != mf->code) {
1691 case V4L2_MBUS_FMT_YUYV8_2X8:
1693 //winseqe_set_addr = sensor_ClrFmt_YUYV;
1694 sensor_read(client, 0x3a, &readval);
1695 sensor_write(client,0x3a, readval&0xf7);
1696 sensor_read(client,0x3d,&readval);
1697 sensor_write(client,0x3d,readval&0xfe);
1700 case V4L2_MBUS_FMT_UYVY8_2X8:
1702 //winseqe_set_addr = sensor_ClrFmt_UYVY;
1703 sensor_read(client, 0x3a, &readval);
1704 sensor_write(client,0x3a, readval|0x08);
1705 sensor_read(client,0x3d,&readval);
1706 sensor_write(client,0x3d,readval&0xfe);
1712 if (winseqe_set_addr != NULL) {
1713 sensor_write_array(client, winseqe_set_addr);
1714 sensor->info_priv.fmt.code = mf->code;
1715 sensor->info_priv.fmt.colorspace= mf->colorspace;
1716 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1718 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1725 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1727 winseqe_set_addr = sensor_qcif;
1731 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1733 winseqe_set_addr = sensor_qvga;
1737 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1739 winseqe_set_addr = sensor_cif;
1743 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1745 winseqe_set_addr = sensor_vga;
1749 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1751 winseqe_set_addr = sensor_svga;
1755 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1757 winseqe_set_addr = sensor_vga; //sensor_sxga;
1763 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1764 set_w = SENSOR_INIT_WIDTH;
1765 set_h = SENSOR_INIT_HEIGHT;
1766 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1769 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1770 #if CONFIG_SENSOR_Flash
1771 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1772 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1773 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1774 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1776 } else { /* ddl@rock-chips.com : Video */
1777 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1778 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1779 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1783 ret |= sensor_write_array(client, winseqe_set_addr);
1785 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1786 #if CONFIG_SENSOR_Flash
1787 if (sensor_fmt_capturechk(sd,mf) == true) {
1788 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1789 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1790 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1794 goto sensor_s_fmt_end;
1797 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1799 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1800 #if CONFIG_SENSOR_Effect
1801 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1802 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1804 #if CONFIG_SENSOR_WhiteBalance
1805 if (sensor->info_priv.whiteBalance != 0) {
1806 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1807 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1810 sensor->info_priv.snap2preview = true;
1811 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1812 #if CONFIG_SENSOR_Effect
1813 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1814 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1816 #if CONFIG_SENSOR_WhiteBalance
1817 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1818 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1820 sensor->info_priv.video2preview = true;
1821 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1822 #if CONFIG_SENSOR_Effect
1823 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1824 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1826 #if CONFIG_SENSOR_WhiteBalance
1827 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1828 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1830 sensor->info_priv.video2preview = false;
1831 sensor->info_priv.snap2preview = false;
1834 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1838 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1848 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1850 struct i2c_client *client = v4l2_get_subdevdata(sd);
1851 struct sensor *sensor = to_sensor(client);
1852 const struct sensor_datafmt *fmt;
1855 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1856 ARRAY_SIZE(sensor_colour_fmts));
1858 fmt = &sensor->info_priv.fmt;
1859 mf->code = fmt->code;
1862 if (mf->height > SENSOR_MAX_HEIGHT)
1863 mf->height = SENSOR_MAX_HEIGHT;
1864 else if (mf->height < SENSOR_MIN_HEIGHT)
1865 mf->height = SENSOR_MIN_HEIGHT;
1867 if (mf->width > SENSOR_MAX_WIDTH)
1868 mf->width = SENSOR_MAX_WIDTH;
1869 else if (mf->width < SENSOR_MIN_WIDTH)
1870 mf->width = SENSOR_MIN_WIDTH;
1872 mf->colorspace = fmt->colorspace;
1877 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1879 struct i2c_client *client = v4l2_get_subdevdata(sd);
1881 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1884 if (id->match.addr != client->addr)
1887 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1892 #if CONFIG_SENSOR_Brightness
1893 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1895 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1897 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1899 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1901 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1903 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1906 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1910 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1914 #if CONFIG_SENSOR_Effect
1915 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1917 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1919 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1921 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1923 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1925 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1928 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1932 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1936 #if CONFIG_SENSOR_Exposure
1937 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1939 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1941 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1943 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1945 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1947 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1950 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1954 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1958 #if CONFIG_SENSOR_Saturation
1959 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1961 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1963 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1965 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1967 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1969 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1972 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1976 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1980 #if CONFIG_SENSOR_Contrast
1981 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1983 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1985 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1987 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1989 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1991 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1994 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1998 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2002 #if CONFIG_SENSOR_Mirror
2003 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2005 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2007 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2009 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2011 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2013 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2016 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2020 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2024 #if CONFIG_SENSOR_Flip
2025 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2027 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2029 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2031 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2033 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2035 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2038 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2042 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2046 #if CONFIG_SENSOR_Scene
2047 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2049 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2051 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2053 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2055 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2057 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2060 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2064 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2068 #if CONFIG_SENSOR_WhiteBalance
2069 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2071 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2073 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2075 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2077 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2079 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2082 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2086 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2090 #if CONFIG_SENSOR_DigitalZoom
2091 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2093 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2094 struct sensor *sensor = to_sensor(client);
2095 const struct v4l2_queryctrl *qctrl_info;
2096 int digitalzoom_cur, digitalzoom_total;
2098 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2102 digitalzoom_cur = sensor->info_priv.digitalzoom;
2103 digitalzoom_total = qctrl_info->maximum;
2105 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2107 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2111 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2113 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2117 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2119 *value = digitalzoom_total - digitalzoom_cur;
2122 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2124 *value = 0 - digitalzoom_cur;
2127 digitalzoom_cur += *value;
2129 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2131 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2133 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2136 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2143 #if CONFIG_SENSOR_Flash
2144 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2146 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2147 if (value == 3) { /* ddl@rock-chips.com: torch */
2148 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2150 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2152 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2156 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2161 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2163 struct i2c_client *client = v4l2_get_subdevdata(sd);
2164 struct sensor *sensor = to_sensor(client);
2165 const struct v4l2_queryctrl *qctrl;
2167 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2171 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2177 case V4L2_CID_BRIGHTNESS:
2179 ctrl->value = sensor->info_priv.brightness;
2182 case V4L2_CID_SATURATION:
2184 ctrl->value = sensor->info_priv.saturation;
2187 case V4L2_CID_CONTRAST:
2189 ctrl->value = sensor->info_priv.contrast;
2192 case V4L2_CID_DO_WHITE_BALANCE:
2194 ctrl->value = sensor->info_priv.whiteBalance;
2197 case V4L2_CID_EXPOSURE:
2199 ctrl->value = sensor->info_priv.exposure;
2202 case V4L2_CID_HFLIP:
2204 ctrl->value = sensor->info_priv.mirror;
2207 case V4L2_CID_VFLIP:
2209 ctrl->value = sensor->info_priv.flip;
2220 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2222 struct i2c_client *client = v4l2_get_subdevdata(sd);
2223 const struct v4l2_queryctrl *qctrl;
2225 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2229 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2235 #if CONFIG_SENSOR_Brightness
2236 case V4L2_CID_BRIGHTNESS:
2238 if (ctrl->value != sensor->info_priv.brightness)
2240 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2244 sensor->info_priv.brightness = ctrl->value;
2249 #if CONFIG_SENSOR_Exposure
2250 case V4L2_CID_EXPOSURE:
2252 if (ctrl->value != sensor->info_priv.exposure)
2254 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2258 sensor->info_priv.exposure = ctrl->value;
2263 #if CONFIG_SENSOR_Saturation
2264 case V4L2_CID_SATURATION:
2266 if (ctrl->value != sensor->info_priv.saturation)
2268 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2272 sensor->info_priv.saturation = ctrl->value;
2277 #if CONFIG_SENSOR_Contrast
2278 case V4L2_CID_CONTRAST:
2280 if (ctrl->value != sensor->info_priv.contrast)
2282 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2286 sensor->info_priv.contrast = ctrl->value;
2291 #if CONFIG_SENSOR_WhiteBalance
2292 case V4L2_CID_DO_WHITE_BALANCE:
2294 if (ctrl->value != sensor->info_priv.whiteBalance)
2296 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2300 sensor->info_priv.whiteBalance = ctrl->value;
2305 #if CONFIG_SENSOR_Mirror
2306 case V4L2_CID_HFLIP:
2308 if (ctrl->value != sensor->info_priv.mirror)
2310 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2312 sensor->info_priv.mirror = ctrl->value;
2317 #if CONFIG_SENSOR_Flip
2318 case V4L2_CID_VFLIP:
2320 if (ctrl->value != sensor->info_priv.flip)
2322 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2324 sensor->info_priv.flip = ctrl->value;
2335 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2337 const struct v4l2_queryctrl *qctrl;
2338 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2339 struct sensor *sensor = to_sensor(client);
2341 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2345 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2349 switch (ext_ctrl->id)
2351 case V4L2_CID_SCENE:
2353 ext_ctrl->value = sensor->info_priv.scene;
2356 case V4L2_CID_EFFECT:
2358 ext_ctrl->value = sensor->info_priv.effect;
2361 case V4L2_CID_ZOOM_ABSOLUTE:
2363 ext_ctrl->value = sensor->info_priv.digitalzoom;
2366 case V4L2_CID_ZOOM_RELATIVE:
2370 case V4L2_CID_FOCUS_ABSOLUTE:
2372 ext_ctrl->value = sensor->info_priv.focus;
2375 case V4L2_CID_FOCUS_RELATIVE:
2379 case V4L2_CID_FLASH:
2381 ext_ctrl->value = sensor->info_priv.flash;
2389 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2391 const struct v4l2_queryctrl *qctrl;
2392 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2393 struct sensor *sensor = to_sensor(client);
2396 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2400 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2405 switch (ext_ctrl->id)
2407 #if CONFIG_SENSOR_Scene
2408 case V4L2_CID_SCENE:
2410 if (ext_ctrl->value != sensor->info_priv.scene)
2412 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2414 sensor->info_priv.scene = ext_ctrl->value;
2419 #if CONFIG_SENSOR_Effect
2420 case V4L2_CID_EFFECT:
2422 if (ext_ctrl->value != sensor->info_priv.effect)
2424 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2426 sensor->info_priv.effect= ext_ctrl->value;
2431 #if CONFIG_SENSOR_DigitalZoom
2432 case V4L2_CID_ZOOM_ABSOLUTE:
2434 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2437 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2439 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2441 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2443 sensor->info_priv.digitalzoom += val_offset;
2445 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2450 case V4L2_CID_ZOOM_RELATIVE:
2452 if (ext_ctrl->value)
2454 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2456 sensor->info_priv.digitalzoom += ext_ctrl->value;
2458 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2463 #if CONFIG_SENSOR_Focus
2464 case V4L2_CID_FOCUS_ABSOLUTE:
2466 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2469 if (ext_ctrl->value != sensor->info_priv.focus)
2471 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2473 sensor->info_priv.focus += val_offset;
2478 case V4L2_CID_FOCUS_RELATIVE:
2480 if (ext_ctrl->value)
2482 sensor->info_priv.focus += ext_ctrl->value;
2484 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2489 #if CONFIG_SENSOR_Flash
2490 case V4L2_CID_FLASH:
2492 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2494 sensor->info_priv.flash = ext_ctrl->value;
2496 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2507 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2509 struct i2c_client *client = v4l2_get_subdevdata(sd);
2510 struct soc_camera_device *icd = client->dev.platform_data;
2511 int i, error_cnt=0, error_idx=-1;
2514 for (i=0; i<ext_ctrl->count; i++) {
2515 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2522 error_idx = ext_ctrl->count;
2524 if (error_idx != -1) {
2525 ext_ctrl->error_idx = error_idx;
2532 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2534 struct i2c_client *client = v4l2_get_subdevdata(sd);
2535 struct soc_camera_device *icd = client->dev.platform_data;
2536 int i, error_cnt=0, error_idx=-1;
2539 for (i=0; i<ext_ctrl->count; i++) {
2540 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2547 error_idx = ext_ctrl->count;
2549 if (error_idx != -1) {
2550 ext_ctrl->error_idx = error_idx;
2557 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2558 * this wasn't our capture interface, so, we wait for the right one */
2559 static int sensor_video_probe(struct soc_camera_device *icd,
2560 struct i2c_client *client)
2564 struct sensor *sensor = to_sensor(client);
2566 /* We must have a parent by now. And it cannot be a wrong one.
2567 * So this entire test is completely redundant. */
2568 if (!icd->dev.parent ||
2569 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2572 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2574 goto sensor_video_probe_err;
2577 ret = sensor_write(client, 0x12, 0x80);
2580 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2583 mdelay(50); //delay 5 microseconds
2585 /* check if it is an sensor sensor */
2586 ret = sensor_read(client, 0x0a, &pid);
2588 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2590 goto sensor_video_probe_err;
2593 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2594 if (pid == SENSOR_ID) {
2595 sensor->model = SENSOR_V4L2_IDENT;
2597 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2599 goto sensor_video_probe_err;
2604 sensor_video_probe_err:
2609 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2611 struct i2c_client *client = v4l2_get_subdevdata(sd);
2612 struct soc_camera_device *icd = client->dev.platform_data;
2613 struct sensor *sensor = to_sensor(client);
2615 #if CONFIG_SENSOR_Flash
2619 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2622 case RK_CAM_SUBDEV_DEACTIVATE:
2624 sensor_deactivate(client);
2628 case RK_CAM_SUBDEV_IOREQUEST:
2630 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2631 if (sensor->sensor_io_request != NULL) {
2632 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2633 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2634 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2635 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2636 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2637 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2640 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2642 goto sensor_ioctl_end;
2644 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2646 #if CONFIG_SENSOR_Flash
2647 if (sensor->sensor_gpio_res) {
2648 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2649 for (i = 0; i < icd->ops->num_controls; i++) {
2650 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2651 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2654 sensor->info_priv.flash = 0xff;
2655 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2663 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2671 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2672 enum v4l2_mbus_pixelcode *code)
2674 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2677 *code = sensor_colour_fmts[index].code;
2680 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2681 .init = sensor_init,
2682 .g_ctrl = sensor_g_control,
2683 .s_ctrl = sensor_s_control,
2684 .g_ext_ctrls = sensor_g_ext_controls,
2685 .s_ext_ctrls = sensor_s_ext_controls,
2686 .g_chip_ident = sensor_g_chip_ident,
2687 .ioctl = sensor_ioctl,
2690 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2691 .s_mbus_fmt = sensor_s_fmt,
2692 .g_mbus_fmt = sensor_g_fmt,
2693 .try_mbus_fmt = sensor_try_fmt,
2694 .enum_mbus_fmt = sensor_enum_fmt,
2697 static struct v4l2_subdev_ops sensor_subdev_ops = {
2698 .core = &sensor_subdev_core_ops,
2699 .video = &sensor_subdev_video_ops,
2702 static int sensor_probe(struct i2c_client *client,
2703 const struct i2c_device_id *did)
2705 struct sensor *sensor;
2706 struct soc_camera_device *icd = client->dev.platform_data;
2707 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2708 struct soc_camera_link *icl;
2711 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2713 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2717 icl = to_soc_camera_link(icd);
2719 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2723 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2724 dev_warn(&adapter->dev,
2725 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2729 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2733 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2735 /* Second stage probe - when a capture adapter is there */
2736 icd->ops = &sensor_ops;
2737 sensor->info_priv.fmt = sensor_colour_fmts[0];
2738 #if CONFIG_SENSOR_I2C_NOSCHED
2739 atomic_set(&sensor->tasklock_cnt,0);
2742 ret = sensor_video_probe(icd, client);
2745 i2c_set_clientdata(client, NULL);
2749 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2753 static int sensor_remove(struct i2c_client *client)
2755 struct sensor *sensor = to_sensor(client);
2756 struct soc_camera_device *icd = client->dev.platform_data;
2759 i2c_set_clientdata(client, NULL);
2760 client->driver = NULL;
2766 static const struct i2c_device_id sensor_id[] = {
2767 {SENSOR_NAME_STRING(), 0 },
2770 MODULE_DEVICE_TABLE(i2c, sensor_id);
2772 static struct i2c_driver sensor_i2c_driver = {
2774 .name = SENSOR_NAME_STRING(),
2776 .probe = sensor_probe,
2777 .remove = sensor_remove,
2778 .id_table = sensor_id,
2781 static int __init sensor_mod_init(void)
2783 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2784 return i2c_add_driver(&sensor_i2c_driver);
2787 static void __exit sensor_mod_exit(void)
2789 i2c_del_driver(&sensor_i2c_driver);
2792 device_initcall_sync(sensor_mod_init);
2793 module_exit(sensor_mod_exit);
2795 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2796 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2797 MODULE_LICENSE("GPL");