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 <plat/rk_camera.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 RK29_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 640 /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT 480
56 #define SENSOR_INIT_WINSEQADR sensor_vga
57 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
59 #define CONFIG_SENSOR_WhiteBalance 0
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 1
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 SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
90 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
91 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
99 //flash off in fixed time to prevent from too hot , zyc
101 struct soc_camera_device *icd;
102 struct hrtimer timer;
104 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
106 static struct flash_timer flash_off_timer;
107 //for user defined if user want to customize the series , zyc
108 #ifdef CONFIG_OV7675_USER_DEFINED_SERIES
109 #include "ov7675_user_series.c"
111 /* init 640X480 VGA */
112 static struct reginfo sensor_init_data[] =
159 {0x1e, 0x17}, //0x07//0x27
196 {0x7a, 0x20},// {0x7a, 0x24},
197 {0x7b, 0x16},// {0x7b, 0x04},
198 {0x7c, 0x23},// {0x7c, 0x07},
199 {0x7d, 0x3c},// {0x7d, 0x12},
200 {0x7e, 0x5c},// {0x7e, 0x2f},
201 {0x7f, 0x69},// {0x7f, 0x3f},
202 {0x80, 0x75},// {0x80, 0x4d},
203 {0x81, 0x7e},// {0x81, 0x5a},
204 {0x82, 0x88},// {0x82, 0x69},
205 {0x83, 0x8f},// {0x83, 0x74},
206 {0x84, 0x96},// {0x84, 0x7f},
207 {0x85, 0xa3},// {0x85, 0x91},
208 {0x86, 0xaf},// {0x86, 0x9e},
209 {0x87, 0xc4},// {0x87, 0xbb},
210 {0x88, 0xd7},// {0x88, 0xd2},
211 {0x89, 0xe8},// {0x89, 0xe5},
288 static struct reginfo sensor_sxga[] =
294 static struct reginfo sensor_svga[] =
300 static struct reginfo sensor_vga[] =
312 static struct reginfo sensor_cif[] =
318 static struct reginfo sensor_qvga[] =
324 static struct reginfo sensor_qcif[] =
329 static struct reginfo sensor_ClrFmt_YUYV[]=
334 static struct reginfo sensor_ClrFmt_UYVY[]=
340 #if CONFIG_SENSOR_WhiteBalance
341 static struct reginfo sensor_WhiteB_Auto[]=
343 {0x84, 0x6C}, //Contrast 4
367 {0x0f, 0x4a}, //Saturation 3
379 {0x4f, 0x2e}, //Brightness 3
393 /* Cloudy Colour Temperature : 6500K - 8000K */
394 static struct reginfo sensor_WhiteB_Cloudy[]=
396 {0x7C,0x04}, //Contrast 5
430 {0x4f,0x3a}, //Saturation 4
436 {0x4f, 0x2e}, //Brightness 3
449 /* ClearDay Colour Temperature : 5000K - 6500K */
450 static struct reginfo sensor_WhiteB_ClearDay[]=
453 {0x7C,0x04}, //Contrast 5
487 {0x4f,0x3a}, //Saturation 4
493 {0x4f, 0x2e}, //Brightness 3
506 /* Office Colour Temperature : 3500K - 5000K */
507 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
510 {0x84, 0x6C}, //Contrast 4
534 {0x0f, 0x4a}, //Saturation 3
546 {0x4f, 0x2e}, //Brightness 3
562 /* Home Colour Temperature : 2500K - 3500K */
563 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
566 {0x84, 0x6C}, //Contrast 4
590 {0x0f, 0x4a}, //Saturation 3
602 {0x4f, 0x2e}, //Brightness 3
615 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
616 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
620 #if CONFIG_SENSOR_Brightness
621 static struct reginfo sensor_Brightness0[]=
624 {0x3301, 0xff},//bit[7]:1, enable SDE
631 static struct reginfo sensor_Brightness1[]=
634 {0x3301, 0xff},//bit[7]:1, enable SDE
641 static struct reginfo sensor_Brightness2[]=
644 {0x3301, 0xff},//bit[7]:1, enable SDE
651 static struct reginfo sensor_Brightness3[]=
654 {0x3301, 0xff},//bit[7]:1, enable SDE
661 static struct reginfo sensor_Brightness4[]=
664 {0x3301, 0xff},//bit[7]:1, enable SDE
671 static struct reginfo sensor_Brightness5[]=
674 {0x3301, 0xff},//bit[7]:1, enable SDE
675 {0x3391, 0x04}, //bit[2] enable
676 {0x3390, 0x41}, //bit[3] sign of brightness
680 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
681 sensor_Brightness4, sensor_Brightness5,NULL,
686 #if CONFIG_SENSOR_Effect
687 static struct reginfo sensor_Effect_Normal[] =
695 static struct reginfo sensor_Effect_WandB[] =
703 static struct reginfo sensor_Effect_Sepia[] =
711 static struct reginfo sensor_Effect_Negative[] =
719 static struct reginfo sensor_Effect_Bluish[] =
728 static struct reginfo sensor_Effect_Green[] =
736 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
737 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
740 #if CONFIG_SENSOR_Exposure
741 static struct reginfo sensor_Exposure0[]=
746 static struct reginfo sensor_Exposure1[]=
751 static struct reginfo sensor_Exposure2[]=
756 static struct reginfo sensor_Exposure3[]=
761 static struct reginfo sensor_Exposure4[]=
766 static struct reginfo sensor_Exposure5[]=
771 static struct reginfo sensor_Exposure6[]=
776 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
777 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
780 #if CONFIG_SENSOR_Saturation
781 static struct reginfo sensor_Saturation0[]=
786 static struct reginfo sensor_Saturation1[]=
791 static struct reginfo sensor_Saturation2[]=
795 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
798 #if CONFIG_SENSOR_Contrast
799 static struct reginfo sensor_Contrast0[]=
804 static struct reginfo sensor_Contrast1[]=
809 static struct reginfo sensor_Contrast2[]=
814 static struct reginfo sensor_Contrast3[]=
819 static struct reginfo sensor_Contrast4[]=
825 static struct reginfo sensor_Contrast5[]=
830 static struct reginfo sensor_Contrast6[]=
834 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
835 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
839 #if CONFIG_SENSOR_Mirror
840 static struct reginfo sensor_MirrorOn[]=
845 static struct reginfo sensor_MirrorOff[]=
849 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
851 #if CONFIG_SENSOR_Flip
852 static struct reginfo sensor_FlipOn[]=
857 static struct reginfo sensor_FlipOff[]=
861 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
864 #if CONFIG_SENSOR_Scene
865 static struct reginfo sensor_SceneAuto[] =
870 static struct reginfo sensor_SceneNight[] =
874 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
877 #if CONFIG_SENSOR_DigitalZoom
878 static struct reginfo sensor_Zoom0[] =
883 static struct reginfo sensor_Zoom1[] =
888 static struct reginfo sensor_Zoom2[] =
894 static struct reginfo sensor_Zoom3[] =
898 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
900 static const struct v4l2_querymenu sensor_menus[] =
902 #if CONFIG_SENSOR_WhiteBalance
903 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
904 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
905 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
908 #if CONFIG_SENSOR_Effect
909 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
910 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
911 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
914 #if CONFIG_SENSOR_Scene
915 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
918 #if CONFIG_SENSOR_Flash
919 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
920 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
924 static struct v4l2_queryctrl sensor_controls[] =
926 #if CONFIG_SENSOR_WhiteBalance
928 .id = V4L2_CID_DO_WHITE_BALANCE,
929 .type = V4L2_CTRL_TYPE_MENU,
930 .name = "White Balance Control",
938 #if CONFIG_SENSOR_Brightness
940 .id = V4L2_CID_BRIGHTNESS,
941 .type = V4L2_CTRL_TYPE_INTEGER,
942 .name = "Brightness Control",
950 #if CONFIG_SENSOR_Effect
952 .id = V4L2_CID_EFFECT,
953 .type = V4L2_CTRL_TYPE_MENU,
954 .name = "Effect Control",
962 #if CONFIG_SENSOR_Exposure
964 .id = V4L2_CID_EXPOSURE,
965 .type = V4L2_CTRL_TYPE_INTEGER,
966 .name = "Exposure Control",
974 #if CONFIG_SENSOR_Saturation
976 .id = V4L2_CID_SATURATION,
977 .type = V4L2_CTRL_TYPE_INTEGER,
978 .name = "Saturation Control",
986 #if CONFIG_SENSOR_Contrast
988 .id = V4L2_CID_CONTRAST,
989 .type = V4L2_CTRL_TYPE_INTEGER,
990 .name = "Contrast Control",
998 #if CONFIG_SENSOR_Mirror
1000 .id = V4L2_CID_HFLIP,
1001 .type = V4L2_CTRL_TYPE_BOOLEAN,
1002 .name = "Mirror Control",
1010 #if CONFIG_SENSOR_Flip
1012 .id = V4L2_CID_VFLIP,
1013 .type = V4L2_CTRL_TYPE_BOOLEAN,
1014 .name = "Flip Control",
1022 #if CONFIG_SENSOR_Scene
1024 .id = V4L2_CID_SCENE,
1025 .type = V4L2_CTRL_TYPE_MENU,
1026 .name = "Scene Control",
1034 #if CONFIG_SENSOR_DigitalZoom
1036 .id = V4L2_CID_ZOOM_RELATIVE,
1037 .type = V4L2_CTRL_TYPE_INTEGER,
1038 .name = "DigitalZoom Control",
1044 .id = V4L2_CID_ZOOM_ABSOLUTE,
1045 .type = V4L2_CTRL_TYPE_INTEGER,
1046 .name = "DigitalZoom Control",
1054 #if CONFIG_SENSOR_Focus
1056 .id = V4L2_CID_FOCUS_RELATIVE,
1057 .type = V4L2_CTRL_TYPE_INTEGER,
1058 .name = "Focus Control",
1064 .id = V4L2_CID_FOCUS_ABSOLUTE,
1065 .type = V4L2_CTRL_TYPE_INTEGER,
1066 .name = "Focus Control",
1070 .default_value = 125,
1074 #if CONFIG_SENSOR_Flash
1076 .id = V4L2_CID_FLASH,
1077 .type = V4L2_CTRL_TYPE_MENU,
1078 .name = "Flash Control",
1087 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1088 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1089 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1090 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1091 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1092 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1093 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1094 static int sensor_resume(struct soc_camera_device *icd);
1095 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1096 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1097 #if CONFIG_SENSOR_Effect
1098 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1100 #if CONFIG_SENSOR_WhiteBalance
1101 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1103 static int sensor_deactivate(struct i2c_client *client);
1106 static struct soc_camera_ops sensor_ops =
1108 .suspend = sensor_suspend,
1109 .resume = sensor_resume,
1110 .set_bus_param = sensor_set_bus_param,
1111 .query_bus_param = sensor_query_bus_param,
1112 .controls = sensor_controls,
1113 .menus = sensor_menus,
1114 .num_controls = ARRAY_SIZE(sensor_controls),
1115 .num_menus = ARRAY_SIZE(sensor_menus),
1118 /* only one fixed colorspace per pixelcode */
1119 struct sensor_datafmt {
1120 enum v4l2_mbus_pixelcode code;
1121 enum v4l2_colorspace colorspace;
1124 /* Find a data format by a pixel code in an array */
1125 static const struct sensor_datafmt *sensor_find_datafmt(
1126 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1130 for (i = 0; i < n; i++)
1131 if (fmt[i].code == code)
1137 static const struct sensor_datafmt sensor_colour_fmts[] = {
1138 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1139 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1142 typedef struct sensor_info_priv_s
1156 unsigned char mirror; /* HFLIP */
1157 unsigned char flip; /* VFLIP */
1158 unsigned int winseqe_cur_addr;
1159 struct sensor_datafmt fmt;
1161 } sensor_info_priv_t;
1165 struct v4l2_subdev subdev;
1166 struct i2c_client *client;
1167 sensor_info_priv_t info_priv;
1168 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1169 #if CONFIG_SENSOR_I2C_NOSCHED
1170 atomic_t tasklock_cnt;
1172 struct rk29camera_platform_data *sensor_io_request;
1173 struct rk29camera_gpio_res *sensor_gpio_res;
1176 static struct sensor* to_sensor(const struct i2c_client *client)
1178 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1181 static int sensor_task_lock(struct i2c_client *client, int lock)
1183 #if CONFIG_SENSOR_I2C_NOSCHED
1185 struct sensor *sensor = to_sensor(client);
1188 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1189 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1190 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1194 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1195 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1196 goto sensor_task_lock_err;
1201 atomic_add(1, &sensor->tasklock_cnt);
1203 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1204 atomic_sub(1, &sensor->tasklock_cnt);
1206 if (atomic_read(&sensor->tasklock_cnt) == 0)
1211 sensor_task_lock_err:
1219 /* sensor register write */
1220 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1224 struct i2c_msg msg[1];
1226 buf[0] = reg & 0xFF;
1229 msg->addr = client->addr;
1230 msg->flags = client->flags;
1232 msg->len = sizeof(buf);
1233 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1234 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1239 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1240 err = i2c_transfer(client->adapter, msg, 1);
1245 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1253 /* sensor register read */
1254 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1258 struct i2c_msg msg[2];
1262 msg[0].addr = client->addr;
1263 msg[0].flags = client->flags;
1265 msg[0].len = sizeof(buf);
1266 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1267 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1269 msg[1].addr = client->addr;
1270 msg[1].flags = client->flags|I2C_M_RD;
1273 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1274 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1278 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1279 err = i2c_transfer(client->adapter, msg, 2);
1285 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1293 /* write a array of registers */
1294 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1298 #if CONFIG_SENSOR_I2C_RDWRCHK
1303 if (sensor_task_lock(client, 1) < 0)
1304 goto sensor_write_array_end;
1306 while (regarray[i].reg != 0)
1308 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1312 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1316 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1318 goto sensor_write_array_end;
1321 #if CONFIG_SENSOR_I2C_RDWRCHK
1322 sensor_read(client, regarray[i].reg, &valchk);
1323 if (valchk != regarray[i].val)
1324 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1330 sensor_write_array_end:
1331 sensor_task_lock(client,0);
1334 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1342 while (regarray[i].reg != 0)
1344 sensor_read(client, regarray[i].reg, &valchk);
1345 if (valchk != regarray[i].val)
1346 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1352 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1354 struct soc_camera_link *icl = to_soc_camera_link(icd);
1357 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1360 case Sensor_PowerDown:
1362 if (icl->powerdown) {
1365 ret = icl->powerdown(icd->pdev, on);
1366 if (ret == RK29_CAM_IO_SUCCESS) {
1370 icl->reset(icd->pdev);
1372 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1374 goto sensor_power_end;
1381 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1382 struct sensor *sensor = to_sensor(client);
1384 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1385 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1387 //flash off after 2 secs
1388 hrtimer_cancel(&(flash_off_timer.timer));
1389 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1396 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1404 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1405 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1406 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1407 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1411 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1413 struct i2c_client *client = v4l2_get_subdevdata(sd);
1414 struct soc_camera_device *icd = client->dev.platform_data;
1415 struct sensor *sensor = to_sensor(client);
1416 const struct v4l2_queryctrl *qctrl;
1417 const struct sensor_datafmt *fmt;
1420 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1422 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1424 goto sensor_INIT_ERR;
1428 if (sensor_task_lock(client,1)<0)
1429 goto sensor_INIT_ERR;
1430 ret = sensor_write(client, 0x12, 0x80);
1433 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1435 goto sensor_INIT_ERR;
1438 mdelay(5); //delay 5 microseconds
1440 ret = sensor_write_array(client, sensor_init_data);
1443 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1444 goto sensor_INIT_ERR;
1446 sensor_task_lock(client,0);
1447 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1448 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1450 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1452 goto sensor_INIT_ERR;
1454 sensor->info_priv.fmt = *fmt;
1456 /* sensor sensor information for initialization */
1457 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1459 sensor->info_priv.whiteBalance = qctrl->default_value;
1460 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1462 sensor->info_priv.brightness = qctrl->default_value;
1463 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1465 sensor->info_priv.effect = qctrl->default_value;
1466 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1468 sensor->info_priv.exposure = qctrl->default_value;
1470 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1472 sensor->info_priv.saturation = qctrl->default_value;
1473 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1475 sensor->info_priv.contrast = qctrl->default_value;
1476 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1478 sensor->info_priv.mirror = qctrl->default_value;
1479 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1481 sensor->info_priv.flip = qctrl->default_value;
1482 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1484 sensor->info_priv.scene = qctrl->default_value;
1485 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1487 sensor->info_priv.digitalzoom = qctrl->default_value;
1489 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1490 #if CONFIG_SENSOR_Focus
1492 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1494 sensor->info_priv.focus = qctrl->default_value;
1497 #if CONFIG_SENSOR_Flash
1498 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1500 sensor->info_priv.flash = qctrl->default_value;
1501 flash_off_timer.icd = icd;
1502 flash_off_timer.timer.function = flash_off_func;
1505 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);
1509 sensor_task_lock(client,0);
1510 sensor_deactivate(client);
1514 static int sensor_deactivate(struct i2c_client *client)
1516 struct soc_camera_device *icd = client->dev.platform_data;
1519 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1521 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1522 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1523 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1524 icd->user_width = SENSOR_INIT_WIDTH;
1525 icd->user_height = SENSOR_INIT_HEIGHT;
1529 static struct reginfo sensor_power_down_sequence[]=
1533 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1536 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1538 if (pm_msg.event == PM_EVENT_SUSPEND) {
1539 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1540 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1542 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1545 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1547 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1552 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1558 static int sensor_resume(struct soc_camera_device *icd)
1562 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1564 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1568 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1574 static int sensor_set_bus_param(struct soc_camera_device *icd,
1575 unsigned long flags)
1581 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1583 struct soc_camera_link *icl = to_soc_camera_link(icd);
1584 unsigned long flags = SENSOR_BUS_PARAM;
1586 return soc_camera_apply_sensor_flags(icl, flags);
1589 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1591 struct i2c_client *client = v4l2_get_subdevdata(sd);
1592 struct soc_camera_device *icd = client->dev.platform_data;
1593 struct sensor *sensor = to_sensor(client);
1595 mf->width = icd->user_width;
1596 mf->height = icd->user_height;
1597 mf->code = sensor->info_priv.fmt.code;
1598 mf->colorspace = sensor->info_priv.fmt.colorspace;
1599 mf->field = V4L2_FIELD_NONE;
1603 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1607 if ((mf->width == 1024) && (mf->height == 768)) {
1609 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1611 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1613 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1615 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1620 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1624 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1628 if ((mf->width == 1280) && (mf->height == 720)) {
1630 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1635 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1638 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1640 struct i2c_client *client = v4l2_get_subdevdata(sd);
1641 struct sensor *sensor = to_sensor(client);
1642 const struct sensor_datafmt *fmt;
1643 const struct v4l2_queryctrl *qctrl;
1644 struct soc_camera_device *icd = client->dev.platform_data;
1645 struct reginfo *winseqe_set_addr=NULL;
1647 int ret=0, set_w,set_h;
1649 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1650 ARRAY_SIZE(sensor_colour_fmts));
1653 goto sensor_s_fmt_end;
1656 if (sensor->info_priv.fmt.code != mf->code) {
1659 case V4L2_MBUS_FMT_YUYV8_2X8:
1661 //winseqe_set_addr = sensor_ClrFmt_YUYV;
1662 sensor_read(client, 0x3a, &readval);
1663 sensor_write(client,0x3a, readval&0xf7);
1664 sensor_read(client,0x3d,&readval);
1665 sensor_write(client,0x3d,readval&0xfe);
1668 case V4L2_MBUS_FMT_UYVY8_2X8:
1670 //winseqe_set_addr = sensor_ClrFmt_UYVY;
1671 sensor_read(client, 0x3a, &readval);
1672 sensor_write(client,0x3a, readval|0x08);
1673 sensor_read(client,0x3d,&readval);
1674 sensor_write(client,0x3d,readval&0xfe);
1680 if (winseqe_set_addr != NULL) {
1681 sensor_write_array(client, winseqe_set_addr);
1682 sensor->info_priv.fmt.code = mf->code;
1683 sensor->info_priv.fmt.colorspace= mf->colorspace;
1684 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1686 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1693 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1695 winseqe_set_addr = sensor_qcif;
1699 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1701 winseqe_set_addr = sensor_qvga;
1705 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1707 winseqe_set_addr = sensor_cif;
1711 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1713 winseqe_set_addr = sensor_vga;
1717 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1719 winseqe_set_addr = sensor_svga;
1723 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1725 winseqe_set_addr = sensor_vga; //sensor_sxga;
1731 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1732 set_w = SENSOR_INIT_WIDTH;
1733 set_h = SENSOR_INIT_HEIGHT;
1734 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1737 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1738 #if CONFIG_SENSOR_Flash
1739 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1740 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1741 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1742 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1744 } else { /* ddl@rock-chips.com : Video */
1745 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1746 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1747 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1751 ret |= sensor_write_array(client, winseqe_set_addr);
1753 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1754 #if CONFIG_SENSOR_Flash
1755 if (sensor_fmt_capturechk(sd,mf) == true) {
1756 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1757 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1758 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1762 goto sensor_s_fmt_end;
1765 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1767 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1768 #if CONFIG_SENSOR_Effect
1769 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1770 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1772 #if CONFIG_SENSOR_WhiteBalance
1773 if (sensor->info_priv.whiteBalance != 0) {
1774 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1775 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1778 sensor->info_priv.snap2preview = true;
1779 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1780 #if CONFIG_SENSOR_Effect
1781 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1782 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1784 #if CONFIG_SENSOR_WhiteBalance
1785 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1786 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1788 sensor->info_priv.video2preview = true;
1789 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1790 #if CONFIG_SENSOR_Effect
1791 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1792 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1794 #if CONFIG_SENSOR_WhiteBalance
1795 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1796 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1798 sensor->info_priv.video2preview = false;
1799 sensor->info_priv.snap2preview = false;
1802 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1806 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1816 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1818 struct i2c_client *client = v4l2_get_subdevdata(sd);
1819 struct sensor *sensor = to_sensor(client);
1820 const struct sensor_datafmt *fmt;
1821 int ret = 0,set_w,set_h;
1823 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1824 ARRAY_SIZE(sensor_colour_fmts));
1826 fmt = &sensor->info_priv.fmt;
1827 mf->code = fmt->code;
1830 if (mf->height > SENSOR_MAX_HEIGHT)
1831 mf->height = SENSOR_MAX_HEIGHT;
1832 else if (mf->height < SENSOR_MIN_HEIGHT)
1833 mf->height = SENSOR_MIN_HEIGHT;
1835 if (mf->width > SENSOR_MAX_WIDTH)
1836 mf->width = SENSOR_MAX_WIDTH;
1837 else if (mf->width < SENSOR_MIN_WIDTH)
1838 mf->width = SENSOR_MIN_WIDTH;
1843 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1848 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1853 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1858 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1863 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1868 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1875 set_w = SENSOR_INIT_WIDTH;
1876 set_h = SENSOR_INIT_HEIGHT;
1881 mf->colorspace = fmt->colorspace;
1886 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1888 struct i2c_client *client = v4l2_get_subdevdata(sd);
1890 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1893 if (id->match.addr != client->addr)
1896 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1901 #if CONFIG_SENSOR_Brightness
1902 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1904 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1906 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1908 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1910 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1912 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1915 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1919 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1923 #if CONFIG_SENSOR_Effect
1924 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1926 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1928 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1930 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1932 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1934 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1937 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1941 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1945 #if CONFIG_SENSOR_Exposure
1946 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1948 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1950 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1952 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1954 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1956 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1959 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1963 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1967 #if CONFIG_SENSOR_Saturation
1968 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1970 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1972 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1974 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1976 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1978 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1981 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1985 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1989 #if CONFIG_SENSOR_Contrast
1990 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1992 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1994 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1996 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1998 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2000 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2003 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2007 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2011 #if CONFIG_SENSOR_Mirror
2012 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2014 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2016 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2018 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2020 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2022 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2025 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2029 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2033 #if CONFIG_SENSOR_Flip
2034 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2036 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2038 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2040 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2042 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2044 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2047 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2051 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2055 #if CONFIG_SENSOR_Scene
2056 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2058 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2060 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2062 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2064 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2066 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2069 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2073 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2077 #if CONFIG_SENSOR_WhiteBalance
2078 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2080 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2082 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2084 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2086 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2088 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2091 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2095 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2099 #if CONFIG_SENSOR_DigitalZoom
2100 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2102 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2103 struct sensor *sensor = to_sensor(client);
2104 const struct v4l2_queryctrl *qctrl_info;
2105 int digitalzoom_cur, digitalzoom_total;
2107 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2111 digitalzoom_cur = sensor->info_priv.digitalzoom;
2112 digitalzoom_total = qctrl_info->maximum;
2114 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2116 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2120 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2122 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2126 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2128 *value = digitalzoom_total - digitalzoom_cur;
2131 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2133 *value = 0 - digitalzoom_cur;
2136 digitalzoom_cur += *value;
2138 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2140 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2142 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2145 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2152 #if CONFIG_SENSOR_Flash
2153 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2155 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2156 if (value == 3) { /* ddl@rock-chips.com: torch */
2157 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2159 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2161 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2165 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2170 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2172 struct i2c_client *client = v4l2_get_subdevdata(sd);
2173 struct sensor *sensor = to_sensor(client);
2174 const struct v4l2_queryctrl *qctrl;
2176 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2180 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2186 case V4L2_CID_BRIGHTNESS:
2188 ctrl->value = sensor->info_priv.brightness;
2191 case V4L2_CID_SATURATION:
2193 ctrl->value = sensor->info_priv.saturation;
2196 case V4L2_CID_CONTRAST:
2198 ctrl->value = sensor->info_priv.contrast;
2201 case V4L2_CID_DO_WHITE_BALANCE:
2203 ctrl->value = sensor->info_priv.whiteBalance;
2206 case V4L2_CID_EXPOSURE:
2208 ctrl->value = sensor->info_priv.exposure;
2211 case V4L2_CID_HFLIP:
2213 ctrl->value = sensor->info_priv.mirror;
2216 case V4L2_CID_VFLIP:
2218 ctrl->value = sensor->info_priv.flip;
2229 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2231 struct i2c_client *client = v4l2_get_subdevdata(sd);
2232 const struct v4l2_queryctrl *qctrl;
2234 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2238 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2244 #if CONFIG_SENSOR_Brightness
2245 case V4L2_CID_BRIGHTNESS:
2247 if (ctrl->value != sensor->info_priv.brightness)
2249 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2253 sensor->info_priv.brightness = ctrl->value;
2258 #if CONFIG_SENSOR_Exposure
2259 case V4L2_CID_EXPOSURE:
2261 if (ctrl->value != sensor->info_priv.exposure)
2263 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2267 sensor->info_priv.exposure = ctrl->value;
2272 #if CONFIG_SENSOR_Saturation
2273 case V4L2_CID_SATURATION:
2275 if (ctrl->value != sensor->info_priv.saturation)
2277 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2281 sensor->info_priv.saturation = ctrl->value;
2286 #if CONFIG_SENSOR_Contrast
2287 case V4L2_CID_CONTRAST:
2289 if (ctrl->value != sensor->info_priv.contrast)
2291 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2295 sensor->info_priv.contrast = ctrl->value;
2300 #if CONFIG_SENSOR_WhiteBalance
2301 case V4L2_CID_DO_WHITE_BALANCE:
2303 if (ctrl->value != sensor->info_priv.whiteBalance)
2305 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2309 sensor->info_priv.whiteBalance = ctrl->value;
2314 #if CONFIG_SENSOR_Mirror
2315 case V4L2_CID_HFLIP:
2317 if (ctrl->value != sensor->info_priv.mirror)
2319 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2321 sensor->info_priv.mirror = ctrl->value;
2326 #if CONFIG_SENSOR_Flip
2327 case V4L2_CID_VFLIP:
2329 if (ctrl->value != sensor->info_priv.flip)
2331 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2333 sensor->info_priv.flip = ctrl->value;
2344 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2346 const struct v4l2_queryctrl *qctrl;
2347 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2348 struct sensor *sensor = to_sensor(client);
2350 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2354 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2358 switch (ext_ctrl->id)
2360 case V4L2_CID_SCENE:
2362 ext_ctrl->value = sensor->info_priv.scene;
2365 case V4L2_CID_EFFECT:
2367 ext_ctrl->value = sensor->info_priv.effect;
2370 case V4L2_CID_ZOOM_ABSOLUTE:
2372 ext_ctrl->value = sensor->info_priv.digitalzoom;
2375 case V4L2_CID_ZOOM_RELATIVE:
2379 case V4L2_CID_FOCUS_ABSOLUTE:
2381 ext_ctrl->value = sensor->info_priv.focus;
2384 case V4L2_CID_FOCUS_RELATIVE:
2388 case V4L2_CID_FLASH:
2390 ext_ctrl->value = sensor->info_priv.flash;
2398 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2400 const struct v4l2_queryctrl *qctrl;
2401 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2402 struct sensor *sensor = to_sensor(client);
2405 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2409 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2414 switch (ext_ctrl->id)
2416 #if CONFIG_SENSOR_Scene
2417 case V4L2_CID_SCENE:
2419 if (ext_ctrl->value != sensor->info_priv.scene)
2421 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2423 sensor->info_priv.scene = ext_ctrl->value;
2428 #if CONFIG_SENSOR_Effect
2429 case V4L2_CID_EFFECT:
2431 if (ext_ctrl->value != sensor->info_priv.effect)
2433 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2435 sensor->info_priv.effect= ext_ctrl->value;
2440 #if CONFIG_SENSOR_DigitalZoom
2441 case V4L2_CID_ZOOM_ABSOLUTE:
2443 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2446 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2448 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2450 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2452 sensor->info_priv.digitalzoom += val_offset;
2454 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2459 case V4L2_CID_ZOOM_RELATIVE:
2461 if (ext_ctrl->value)
2463 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2465 sensor->info_priv.digitalzoom += ext_ctrl->value;
2467 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2472 #if CONFIG_SENSOR_Focus
2473 case V4L2_CID_FOCUS_ABSOLUTE:
2475 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2478 if (ext_ctrl->value != sensor->info_priv.focus)
2480 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2482 sensor->info_priv.focus += val_offset;
2487 case V4L2_CID_FOCUS_RELATIVE:
2489 if (ext_ctrl->value)
2491 sensor->info_priv.focus += ext_ctrl->value;
2493 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2498 #if CONFIG_SENSOR_Flash
2499 case V4L2_CID_FLASH:
2501 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2503 sensor->info_priv.flash = ext_ctrl->value;
2505 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2516 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2518 struct i2c_client *client = v4l2_get_subdevdata(sd);
2519 struct soc_camera_device *icd = client->dev.platform_data;
2520 int i, error_cnt=0, error_idx=-1;
2523 for (i=0; i<ext_ctrl->count; i++) {
2524 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2531 error_idx = ext_ctrl->count;
2533 if (error_idx != -1) {
2534 ext_ctrl->error_idx = error_idx;
2541 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2543 struct i2c_client *client = v4l2_get_subdevdata(sd);
2544 struct soc_camera_device *icd = client->dev.platform_data;
2545 int i, error_cnt=0, error_idx=-1;
2548 for (i=0; i<ext_ctrl->count; i++) {
2549 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2556 error_idx = ext_ctrl->count;
2558 if (error_idx != -1) {
2559 ext_ctrl->error_idx = error_idx;
2566 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2567 * this wasn't our capture interface, so, we wait for the right one */
2568 static int sensor_video_probe(struct soc_camera_device *icd,
2569 struct i2c_client *client)
2573 struct sensor *sensor = to_sensor(client);
2575 /* We must have a parent by now. And it cannot be a wrong one.
2576 * So this entire test is completely redundant. */
2577 if (!icd->dev.parent ||
2578 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2581 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2583 goto sensor_video_probe_err;
2586 ret = sensor_write(client, 0x12, 0x80);
2589 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2592 mdelay(50); //delay 5 microseconds
2594 /* check if it is an sensor sensor */
2595 ret = sensor_read(client, 0x0a, &pid);
2597 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2599 goto sensor_video_probe_err;
2602 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2603 if (pid == SENSOR_ID) {
2604 sensor->model = SENSOR_V4L2_IDENT;
2606 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2608 goto sensor_video_probe_err;
2613 sensor_video_probe_err:
2618 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2620 struct i2c_client *client = v4l2_get_subdevdata(sd);
2621 struct soc_camera_device *icd = client->dev.platform_data;
2622 struct sensor *sensor = to_sensor(client);
2624 #if CONFIG_SENSOR_Flash
2628 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2631 case RK29_CAM_SUBDEV_DEACTIVATE:
2633 sensor_deactivate(client);
2637 case RK29_CAM_SUBDEV_IOREQUEST:
2639 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2640 if (sensor->sensor_io_request != NULL) {
2641 sensor->sensor_gpio_res = NULL;
2642 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2643 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2644 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2645 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2648 if (sensor->sensor_gpio_res == NULL) {
2649 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2651 goto sensor_ioctl_end;
2654 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2656 goto sensor_ioctl_end;
2658 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2660 #if CONFIG_SENSOR_Flash
2661 if (sensor->sensor_gpio_res) {
2662 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2663 for (i = 0; i < icd->ops->num_controls; i++) {
2664 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2665 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2666 sensor_controls[i].id=0xffff;
2669 sensor->info_priv.flash = 0xff;
2670 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2671 }else{ //two cameras are the same,need to deal diffrently ,zyc
2672 for (i = 0; i < icd->ops->num_controls; i++) {
2673 if(0xffff == icd->ops->controls[i].id){
2674 sensor_controls[i].id=V4L2_CID_FLASH;
2684 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2692 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2693 enum v4l2_mbus_pixelcode *code)
2695 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2698 *code = sensor_colour_fmts[index].code;
2701 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2702 .init = sensor_init,
2703 .g_ctrl = sensor_g_control,
2704 .s_ctrl = sensor_s_control,
2705 .g_ext_ctrls = sensor_g_ext_controls,
2706 .s_ext_ctrls = sensor_s_ext_controls,
2707 .g_chip_ident = sensor_g_chip_ident,
2708 .ioctl = sensor_ioctl,
2711 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2712 .s_mbus_fmt = sensor_s_fmt,
2713 .g_mbus_fmt = sensor_g_fmt,
2714 .try_mbus_fmt = sensor_try_fmt,
2715 .enum_mbus_fmt = sensor_enum_fmt,
2718 static struct v4l2_subdev_ops sensor_subdev_ops = {
2719 .core = &sensor_subdev_core_ops,
2720 .video = &sensor_subdev_video_ops,
2723 static int sensor_probe(struct i2c_client *client,
2724 const struct i2c_device_id *did)
2726 struct sensor *sensor;
2727 struct soc_camera_device *icd = client->dev.platform_data;
2728 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2729 struct soc_camera_link *icl;
2732 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2734 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2738 icl = to_soc_camera_link(icd);
2740 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2744 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2745 dev_warn(&adapter->dev,
2746 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2750 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2754 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2756 /* Second stage probe - when a capture adapter is there */
2757 icd->ops = &sensor_ops;
2758 sensor->info_priv.fmt = sensor_colour_fmts[0];
2759 #if CONFIG_SENSOR_I2C_NOSCHED
2760 atomic_set(&sensor->tasklock_cnt,0);
2763 ret = sensor_video_probe(icd, client);
2766 i2c_set_clientdata(client, NULL);
2770 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2771 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2775 static int sensor_remove(struct i2c_client *client)
2777 struct sensor *sensor = to_sensor(client);
2778 struct soc_camera_device *icd = client->dev.platform_data;
2781 i2c_set_clientdata(client, NULL);
2782 client->driver = NULL;
2788 static const struct i2c_device_id sensor_id[] = {
2789 {SENSOR_NAME_STRING(), 0 },
2792 MODULE_DEVICE_TABLE(i2c, sensor_id);
2794 static struct i2c_driver sensor_i2c_driver = {
2796 .name = SENSOR_NAME_STRING(),
2798 .probe = sensor_probe,
2799 .remove = sensor_remove,
2800 .id_table = sensor_id,
2803 static int __init sensor_mod_init(void)
2805 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2806 return i2c_add_driver(&sensor_i2c_driver);
2809 static void __exit sensor_mod_exit(void)
2811 i2c_del_driver(&sensor_i2c_driver);
2814 device_initcall_sync(sensor_mod_init);
2815 module_exit(sensor_mod_exit);
2817 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2818 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2819 MODULE_LICENSE("GPL");