2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_HI704
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_HI704
48 #define SENSOR_ID 0x96
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 640
52 #define SENSOR_MAX_HEIGHT 480
53 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 480
55 #define SENSOR_INIT_WINSEQADR sensor_vga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Focus 0
66 #define CONFIG_SENSOR_Exposure 0
67 #define CONFIG_SENSOR_Flash 0
68 #define CONFIG_SENSOR_Mirror 0
69 #define CONFIG_SENSOR_Flip 0
71 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
86 #define COLOR_TEMPERATURE_HOME_DN 2500
87 #define COLOR_TEMPERATURE_HOME_UP 3500
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
91 #define SENSOR_AF_IS_ERR (0x00<<0)
92 #define SENSOR_AF_IS_OK (0x01<<0)
93 #define SENSOR_INIT_IS_ERR (0x00<<28)
94 #define SENSOR_INIT_IS_OK (0x01<<28)
104 //flash off in fixed time to prevent from too hot , zyc
106 struct soc_camera_device *icd;
107 struct hrtimer timer;
109 #if CONFIG_SENSOR_Flash
110 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
112 static struct flash_timer flash_off_timer;
113 //for user defined if user want to customize the series , zyc
114 #ifdef CONFIG_HI704_USER_DEFINED_SERIES
115 #include "hi704_user_series.c"
117 /* init SVGA preview */
118 static struct reginfo sensor_init_data[] =
121 //Image Size/Windowing/HSYNC/VSYNC[Type1]
122 {0x03, 0x00}, //PAGEMODE(0x03)
124 {0x01, 0xf3}, //PWRCTL(0x01[P0])Bit[1]:Software Reset.
126 {0x10, 0x00},//vga mode
127 {0x11, 0x90}, //For No Fixed Framerate Bit[2]
140 {0x40, 0x00}, //HBLANK: 0x70 = 112
142 {0x42, 0x00}, //VBLANK: 0x40 = 64
143 {0x43, 0x40}, //0x04 -> 0x40: For Max Framerate = 30fps
174 {0x23, 0xb1}, //For Sun Pot
238 //Image Format, Image Effect
244 {0x40, 0x00},//brightness +1
246 {0x48, 0x98},//contrast level +1
251 {0x61, 0x00}, //Use default
252 {0x62, 0xa0}, //SATB (1.4x)
253 {0x63, 0xa0}, //SATR (1.2x)
254 {0x64, 0x48}, //AGSAT
255 {0x66, 0x90}, //wht_th2
256 {0x67, 0x36}, //wht_gain Dark (0.4x), Normal (0.75x)
305 {0x14, 0x08}, //Test Setting
306 {0x20, 0x06}, //SHARP_Negative
307 {0x21, 0x03}, //SHARP_Positive
308 {0x23, 0x30}, //SHARP_DY_CTL
309 {0x24, 0x33}, //40->33
310 {0x25, 0x08}, //SHARP_PGA_TH
311 {0x26, 0x18}, //Test Setting
312 {0x27, 0x00}, //Test Setting
313 {0x28, 0x08}, //Test Setting
314 {0x29, 0x50}, //AG_TH
315 {0x2a, 0xe0}, //region ratio
316 {0x2b, 0x10}, //Test Setting
317 {0x2c, 0x28}, //Test Setting
318 {0x2d, 0x40}, //Test Setting
319 {0x2e, 0x00}, //Test Setting
320 {0x2f, 0x00}, //Test Setting
321 {0x30, 0x11}, //Test Setting
322 {0x80, 0x03}, //SHARP2D_CTL
323 {0x81, 0x07}, //Test Setting
324 {0x90, 0x04}, //SHARP2D_SLOPE
325 {0x91, 0x02}, //SHARP2D_DIFF_CTL
326 {0x92, 0x00}, //SHARP2D_HI_CLIP
327 {0x93, 0x20}, //SHARP2D_DY_CTL
328 {0x94, 0x42}, //Test Setting
329 {0x95, 0x60}, //Test Setting
335 {0x21, 0x60}, //YCEN 80
336 {0x22, 0x66}, //76, 34, 2b
337 {0x23, 0x50}, //4b, 15, 0d
338 {0x24, 0x44}, //3b, 10, 0b
438 {0x2c, 0x2b}, //23->2b 2010_04_06 hhzin
444 {0x3b, 0x22}, //23->22 _10_04_06 hhzin
447 {0x60, 0x95}, //d5, 99
453 {0x70, 0x38},//Y Target 42
455 {0x76, 0x22}, //Unlock bnd1
456 {0x77, 0x02}, //Unlock bnd2 02->a2 _10_04_06 hhzin
458 {0x78, 0x12}, //Yth 1
459 {0x79, 0x27}, //Yth 2 26->27 _10_04_06 hhzin
460 {0x7a, 0x23}, //Yth 3
462 {0x7c, 0x1d}, //1c->1d _10_04_06 hhzin
466 {0x83, 0x00},//ExpTime 30fps
471 //{0x83, 0x00},//ExpTime 30fps
475 {0x86, 0x00},//ExpMin
479 {0x88, 0x02},//ExpMax 8fps(8fps)
484 //{0x88, 0x04},//ExpMax 8fps(8fps)
489 //{0x88, 0x02},//ExpMax 8fps(8fps)
493 {0x8b, 0x3a},//Exp100
496 {0x8d, 0x30},//Exp120
503 {0x94, 0x01}, //fix_step
510 {0x9c, 0x0b}, //4shared limit_10_04_06 hhzin
511 {0x9d, 0xb8}, // 0x06d3 --> 0x0b3b
512 {0x9e, 0x00}, //4shared Unit_10_04_06 hhzin
513 {0x9f, 0xfa}, // 0x01f4 --> 0xfa
554 {0x83, 0x52}, //RMAX Default : 50 -> 48 -> 52
555 {0x84, 0x1b}, //RMIN Default : 20
556 {0x85, 0x50}, //BMAX Default : 50, 5a -> 58 -> 55
557 {0x86, 0x25}, //BMIN Default : 20
558 {0x87, 0x4d}, //RMAXB Default : 50, 4d
559 {0x88, 0x38}, //RMINB Default : 3e, 45 --> 42
560 {0x89, 0x3e}, //BMAXB Default : 2e, 2d --> 30
561 {0x8a, 0x29}, //BMINB Default : 20, 22 --> 26 --> 29
562 {0x8b, 0x02}, //OUT TH
591 {0x01, 0x90}, //0xf1 ->0x41 : For Preview Green/Red Line.
592 {0xff, 0xff} //End of Initial Setting
597 static struct reginfo sensor_vga[] =
600 {0x10, 0x00}, //VGA Size
605 {0x40, 0x01}, //HBLANK: 0x70 = 112
607 {0x42, 0x00}, //VBLANK: 0x04 = 4
633 static struct reginfo sensor_cif[] =
639 static struct reginfo sensor_qvga[] =
642 {0x10, 0x01}, //QVGA Size: 0x10 -> 0x01
647 {0x40, 0x01}, //HBLANK: 0x0158 = 344
649 {0x42, 0x00}, //VBLANK: 0x14 = 20
652 {0x03, 0x11}, //QVGA Fixframerate
676 static struct reginfo sensor_qcif[] =
682 static struct reginfo sensor_ClrFmt_YUYV[]=
688 static struct reginfo sensor_ClrFmt_UYVY[]=
694 #if CONFIG_SENSOR_WhiteBalance
695 static struct reginfo sensor_WhiteB_Auto[]=
709 /* Cloudy Colour Temperature : 6500K - 8000K */
710 static struct reginfo sensor_WhiteB_Cloudy[]=
723 /* ClearDay Colour Temperature : 5000K - 6500K */
724 static struct reginfo sensor_WhiteB_ClearDay[]=
738 /* Office Colour Temperature : 3500K - 5000K */
739 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
741 //Office£¬Ó«¹âµÆ
754 /* Home Colour Temperature : 2500K - 3500K */
755 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
769 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
770 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
774 #if CONFIG_SENSOR_Brightness
775 static struct reginfo sensor_Brightness0[]=
783 static struct reginfo sensor_Brightness1[]=
791 static struct reginfo sensor_Brightness2[]=
799 static struct reginfo sensor_Brightness3[]=
807 static struct reginfo sensor_Brightness4[]=
815 static struct reginfo sensor_Brightness5[]=
822 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
823 sensor_Brightness4, sensor_Brightness5,NULL,
828 #if CONFIG_SENSOR_Effect
829 static struct reginfo sensor_Effect_Normal[] =
844 static struct reginfo sensor_Effect_WandB[] =
859 static struct reginfo sensor_Effect_Sepia[] =
874 static struct reginfo sensor_Effect_Negative[] =
889 static struct reginfo sensor_Effect_Bluish[] =
905 static struct reginfo sensor_Effect_Green[] =
920 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
921 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
924 #if CONFIG_SENSOR_Exposure
925 static struct reginfo sensor_Exposure0[]=
931 static struct reginfo sensor_Exposure1[]=
938 static struct reginfo sensor_Exposure2[]=
944 static struct reginfo sensor_Exposure3[]=
950 static struct reginfo sensor_Exposure4[]=
957 static struct reginfo sensor_Exposure5[]=
963 static struct reginfo sensor_Exposure6[]=
970 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
971 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
974 #if CONFIG_SENSOR_Saturation
975 static struct reginfo sensor_Saturation0[]=
984 static struct reginfo sensor_Saturation1[]=
993 static struct reginfo sensor_Saturation2[]=
1001 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1004 #if CONFIG_SENSOR_Contrast
1005 static struct reginfo sensor_Contrast0[]=
1013 static struct reginfo sensor_Contrast1[]=
1021 static struct reginfo sensor_Contrast2[]=
1029 static struct reginfo sensor_Contrast3[]=
1037 static struct reginfo sensor_Contrast4[]=
1046 static struct reginfo sensor_Contrast5[]=
1054 static struct reginfo sensor_Contrast6[]=
1061 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1062 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1066 #if CONFIG_SENSOR_Mirror
1067 static struct reginfo sensor_MirrorOn[]=
1073 static struct reginfo sensor_MirrorOff[]=
1078 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1080 #if CONFIG_SENSOR_Flip
1081 static struct reginfo sensor_FlipOn[]=
1087 static struct reginfo sensor_FlipOff[]=
1092 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1095 #if CONFIG_SENSOR_Scene
1096 static struct reginfo sensor_SceneAuto[] =
1101 static struct reginfo sensor_SceneNight[] =
1105 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1108 #if CONFIG_SENSOR_DigitalZoom
1109 static struct reginfo sensor_Zoom0[] =
1114 static struct reginfo sensor_Zoom1[] =
1119 static struct reginfo sensor_Zoom2[] =
1125 static struct reginfo sensor_Zoom3[] =
1129 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1131 static struct v4l2_querymenu sensor_menus[] =
1133 #if CONFIG_SENSOR_WhiteBalance
1134 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1135 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1136 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1139 #if CONFIG_SENSOR_Effect
1140 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1141 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1142 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1145 #if CONFIG_SENSOR_Scene
1146 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1149 #if CONFIG_SENSOR_Flash
1150 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1151 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1155 static struct v4l2_queryctrl sensor_controls[] =
1157 #if CONFIG_SENSOR_WhiteBalance
1159 .id = V4L2_CID_DO_WHITE_BALANCE,
1160 .type = V4L2_CTRL_TYPE_MENU,
1161 .name = "White Balance Control",
1169 #if CONFIG_SENSOR_Brightness
1171 .id = V4L2_CID_BRIGHTNESS,
1172 .type = V4L2_CTRL_TYPE_INTEGER,
1173 .name = "Brightness Control",
1181 #if CONFIG_SENSOR_Effect
1183 .id = V4L2_CID_EFFECT,
1184 .type = V4L2_CTRL_TYPE_MENU,
1185 .name = "Effect Control",
1193 #if CONFIG_SENSOR_Exposure
1195 .id = V4L2_CID_EXPOSURE,
1196 .type = V4L2_CTRL_TYPE_INTEGER,
1197 .name = "Exposure Control",
1205 #if CONFIG_SENSOR_Saturation
1207 .id = V4L2_CID_SATURATION,
1208 .type = V4L2_CTRL_TYPE_INTEGER,
1209 .name = "Saturation Control",
1217 #if CONFIG_SENSOR_Contrast
1219 .id = V4L2_CID_CONTRAST,
1220 .type = V4L2_CTRL_TYPE_INTEGER,
1221 .name = "Contrast Control",
1229 #if CONFIG_SENSOR_Mirror
1231 .id = V4L2_CID_HFLIP,
1232 .type = V4L2_CTRL_TYPE_BOOLEAN,
1233 .name = "Mirror Control",
1241 #if CONFIG_SENSOR_Flip
1243 .id = V4L2_CID_VFLIP,
1244 .type = V4L2_CTRL_TYPE_BOOLEAN,
1245 .name = "Flip Control",
1253 #if CONFIG_SENSOR_Scene
1255 .id = V4L2_CID_SCENE,
1256 .type = V4L2_CTRL_TYPE_MENU,
1257 .name = "Scene Control",
1265 #if CONFIG_SENSOR_DigitalZoom
1267 .id = V4L2_CID_ZOOM_RELATIVE,
1268 .type = V4L2_CTRL_TYPE_INTEGER,
1269 .name = "DigitalZoom Control",
1275 .id = V4L2_CID_ZOOM_ABSOLUTE,
1276 .type = V4L2_CTRL_TYPE_INTEGER,
1277 .name = "DigitalZoom Control",
1285 #if CONFIG_SENSOR_Focus
1287 .id = V4L2_CID_FOCUS_RELATIVE,
1288 .type = V4L2_CTRL_TYPE_INTEGER,
1289 .name = "Focus Control",
1295 .id = V4L2_CID_FOCUS_ABSOLUTE,
1296 .type = V4L2_CTRL_TYPE_INTEGER,
1297 .name = "Focus Control",
1301 .default_value = 125,
1305 #if CONFIG_SENSOR_Flash
1307 .id = V4L2_CID_FLASH,
1308 .type = V4L2_CTRL_TYPE_MENU,
1309 .name = "Flash Control",
1318 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1319 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1320 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1321 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1322 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1323 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1324 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1325 static int sensor_resume(struct soc_camera_device *icd);
1326 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1327 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1328 #if CONFIG_SENSOR_Effect
1329 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1331 #if CONFIG_SENSOR_WhiteBalance
1332 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1334 static int sensor_deactivate(struct i2c_client *client);
1336 static struct soc_camera_ops sensor_ops =
1338 .suspend = sensor_suspend,
1339 .resume = sensor_resume,
1340 .set_bus_param = sensor_set_bus_param,
1341 .query_bus_param = sensor_query_bus_param,
1342 .controls = sensor_controls,
1343 .menus = sensor_menus,
1344 .num_controls = ARRAY_SIZE(sensor_controls),
1345 .num_menus = ARRAY_SIZE(sensor_menus),
1348 /* only one fixed colorspace per pixelcode */
1349 struct sensor_datafmt {
1350 enum v4l2_mbus_pixelcode code;
1351 enum v4l2_colorspace colorspace;
1354 /* Find a data format by a pixel code in an array */
1355 static const struct sensor_datafmt *sensor_find_datafmt(
1356 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1360 for (i = 0; i < n; i++)
1361 if (fmt[i].code == code)
1367 static const struct sensor_datafmt sensor_colour_fmts[] = {
1368 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1369 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1372 typedef struct sensor_info_priv_s
1386 unsigned char mirror; /* HFLIP */
1387 unsigned char flip; /* VFLIP */
1388 unsigned int winseqe_cur_addr;
1389 struct sensor_datafmt fmt;
1390 unsigned int funmodule_state;
1392 } sensor_info_priv_t;
1396 struct v4l2_subdev subdev;
1397 struct i2c_client *client;
1398 sensor_info_priv_t info_priv;
1399 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1400 #if CONFIG_SENSOR_I2C_NOSCHED
1401 atomic_t tasklock_cnt;
1403 struct rk29camera_platform_data *sensor_io_request;
1404 struct rk29camera_gpio_res *sensor_gpio_res;
1407 static struct sensor* to_sensor(const struct i2c_client *client)
1409 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1412 static int sensor_task_lock(struct i2c_client *client, int lock)
1414 #if CONFIG_SENSOR_I2C_NOSCHED
1416 struct sensor *sensor = to_sensor(client);
1419 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1420 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1421 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1425 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1426 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1427 goto sensor_task_lock_err;
1432 atomic_add(1, &sensor->tasklock_cnt);
1434 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1435 atomic_sub(1, &sensor->tasklock_cnt);
1437 if (atomic_read(&sensor->tasklock_cnt) == 0)
1442 sensor_task_lock_err:
1450 /* sensor register */
1451 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1455 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1457 return (ret > 0)? 0 : ret;
1460 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1464 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1466 return (ret > 0)? 0 : ret;
1469 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1473 struct i2c_msg msg[1];
1478 msg->addr = client->addr;
1479 msg->flags = client->flags;
1481 msg->len = sizeof(buf);
1482 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1483 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1488 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1489 err = i2c_transfer(client->adapter, msg, 1);
1494 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1502 /* sensor register read */
1503 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1507 struct i2c_msg msg[2];
1511 msg[0].addr = client->addr;
1512 msg[0].flags = client->flags;
1514 msg[0].len = sizeof(buf);
1515 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1516 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1518 msg[1].addr = client->addr;
1519 msg[1].flags = client->flags|I2C_M_RD;
1522 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1523 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1527 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1528 err = i2c_transfer(client->adapter, msg, 2);
1534 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1544 /* write a array of registers */
1545 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1549 #if CONFIG_SENSOR_I2C_RDWRCHK
1554 if (sensor_task_lock(client, 1) < 0)
1555 goto sensor_write_array_end;
1556 while (regarray[i].reg != END_REG)
1558 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1562 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1566 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1568 goto sensor_write_array_end;
1571 #if CONFIG_SENSOR_I2C_RDWRCHK
1573 sensor_read(client, regarray[i].reg, &valchk);
1574 if (valchk != regarray[i].val)
1575 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1581 sensor_write_array_end:
1582 sensor_task_lock(client,0);
1585 #if CONFIG_SENSOR_I2C_RDWRCHK
1586 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1594 while (regarray[i].reg != 0)
1596 sensor_read(client, regarray[i].reg, &valchk);
1597 if (valchk != regarray[i].val)
1598 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1605 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1607 struct soc_camera_link *icl = to_soc_camera_link(icd);
1610 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1613 case Sensor_PowerDown:
1615 if (icl->powerdown) {
1616 ret = icl->powerdown(icd->pdev, on);
1617 if (ret == RK29_CAM_IO_SUCCESS) {
1621 icl->reset(icd->pdev);
1623 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1625 goto sensor_power_end;
1632 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1633 struct sensor *sensor = to_sensor(client);
1635 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1636 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1638 //flash off after 2 secs
1639 hrtimer_cancel(&(flash_off_timer.timer));
1640 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1647 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1654 #if CONFIG_SENSOR_Flash
1655 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1656 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1657 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1658 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1663 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1665 struct i2c_client *client = v4l2_get_subdevdata(sd);
1666 struct soc_camera_device *icd = client->dev.platform_data;
1667 struct sensor *sensor = to_sensor(client);
1668 const struct v4l2_queryctrl *qctrl;
1669 const struct sensor_datafmt *fmt;
1673 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1675 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1677 goto sensor_INIT_ERR;
1681 if (sensor_task_lock(client,1)<0)
1682 goto sensor_INIT_ERR;
1684 ret = sensor_write(client, 0x01, 0xF3);
1687 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1689 goto sensor_INIT_ERR;
1692 mdelay(5); //delay 5 microseconds
1693 /* check if it is an sensor sensor */
1694 ret = sensor_read(client, 0x04, &value);
1696 SENSOR_TR("read chip id high byte failed\n");
1698 goto sensor_INIT_ERR;
1702 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1703 if (value == SENSOR_ID) {
1704 sensor->model = SENSOR_V4L2_IDENT;
1706 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1708 goto sensor_INIT_ERR;
1711 ret = sensor_write_array(client, sensor_init_data);
1714 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1715 goto sensor_INIT_ERR;
1717 sensor_task_lock(client,0);
1718 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1719 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1721 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1723 goto sensor_INIT_ERR;
1725 sensor->info_priv.fmt = *fmt;
1727 /* sensor sensor information for initialization */
1728 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1730 sensor->info_priv.whiteBalance = qctrl->default_value;
1731 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1733 sensor->info_priv.brightness = qctrl->default_value;
1734 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1736 sensor->info_priv.effect = qctrl->default_value;
1737 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1739 sensor->info_priv.exposure = qctrl->default_value;
1741 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1743 sensor->info_priv.saturation = qctrl->default_value;
1744 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1746 sensor->info_priv.contrast = qctrl->default_value;
1747 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1749 sensor->info_priv.mirror = qctrl->default_value;
1750 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1752 sensor->info_priv.flip = qctrl->default_value;
1753 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1755 sensor->info_priv.scene = qctrl->default_value;
1756 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1758 sensor->info_priv.digitalzoom = qctrl->default_value;
1760 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1761 #if CONFIG_SENSOR_Focus
1763 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1765 sensor->info_priv.focus = qctrl->default_value;
1768 #if CONFIG_SENSOR_Flash
1769 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1771 sensor->info_priv.flash = qctrl->default_value;
1772 flash_off_timer.icd = icd;
1773 flash_off_timer.timer.function = flash_off_func;
1776 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);
1777 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1780 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1781 sensor_task_lock(client,0);
1782 sensor_deactivate(client);
1786 static int sensor_deactivate(struct i2c_client *client)
1788 struct soc_camera_device *icd = client->dev.platform_data;
1789 struct sensor *sensor = to_sensor(client);
1790 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1792 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1793 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1795 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1796 icd->user_width = SENSOR_INIT_WIDTH;
1797 icd->user_height = SENSOR_INIT_HEIGHT;
1799 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1803 static struct reginfo sensor_power_down_sequence[]=
1807 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1810 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1812 if (pm_msg.event == PM_EVENT_SUSPEND) {
1813 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1814 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1816 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1819 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1821 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1826 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1832 static int sensor_resume(struct soc_camera_device *icd)
1836 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1838 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1842 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1848 static int sensor_set_bus_param(struct soc_camera_device *icd,
1849 unsigned long flags)
1855 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1857 struct soc_camera_link *icl = to_soc_camera_link(icd);
1858 unsigned long flags = SENSOR_BUS_PARAM;
1860 return soc_camera_apply_sensor_flags(icl, flags);
1863 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1865 struct i2c_client *client = v4l2_get_subdevdata(sd);
1866 struct soc_camera_device *icd = client->dev.platform_data;
1867 struct sensor *sensor = to_sensor(client);
1869 mf->width = icd->user_width;
1870 mf->height = icd->user_height;
1871 mf->code = sensor->info_priv.fmt.code;
1872 mf->colorspace = sensor->info_priv.fmt.colorspace;
1873 mf->field = V4L2_FIELD_NONE;
1877 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1881 if ((mf->width == 1024) && (mf->height == 768)) {
1883 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1885 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1887 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1889 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1894 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1898 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1902 if ((mf->width == 1280) && (mf->height == 720)) {
1904 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1909 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1912 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1914 struct i2c_client *client = v4l2_get_subdevdata(sd);
1915 struct sensor *sensor = to_sensor(client);
1916 const struct sensor_datafmt *fmt;
1917 const struct v4l2_queryctrl *qctrl;
1918 struct soc_camera_device *icd = client->dev.platform_data;
1919 struct reginfo *winseqe_set_addr=NULL;
1920 int ret=0, set_w,set_h;
1922 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1923 ARRAY_SIZE(sensor_colour_fmts));
1926 goto sensor_s_fmt_end;
1929 if (sensor->info_priv.fmt.code != mf->code) {
1932 case V4L2_MBUS_FMT_YUYV8_2X8:
1934 winseqe_set_addr = sensor_ClrFmt_YUYV;
1937 case V4L2_MBUS_FMT_UYVY8_2X8:
1939 winseqe_set_addr = sensor_ClrFmt_UYVY;
1945 if (winseqe_set_addr != NULL) {
1946 sensor_write_array(client, winseqe_set_addr);
1947 sensor->info_priv.fmt.code = mf->code;
1948 sensor->info_priv.fmt.colorspace= mf->colorspace;
1949 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1951 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1958 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg != END_REG))
1960 winseqe_set_addr = sensor_qcif;
1964 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg != END_REG))
1966 winseqe_set_addr = sensor_qvga;
1970 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg != END_REG))
1972 winseqe_set_addr = sensor_cif;
1976 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg != END_REG))
1978 winseqe_set_addr = sensor_vga;
1984 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1985 set_w = SENSOR_INIT_WIDTH;
1986 set_h = SENSOR_INIT_HEIGHT;
1988 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1991 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1992 #if CONFIG_SENSOR_Flash
1993 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1994 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1995 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1996 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1998 } else { /* ddl@rock-chips.com : Video */
1999 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2000 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2001 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2005 ret |= sensor_write_array(client, winseqe_set_addr);
2007 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2008 #if CONFIG_SENSOR_Flash
2009 if (sensor_fmt_capturechk(sd,mf) == true) {
2010 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2011 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2012 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2016 goto sensor_s_fmt_end;
2019 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2021 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2022 #if CONFIG_SENSOR_Effect
2023 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2024 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2026 #if CONFIG_SENSOR_WhiteBalance
2027 if (sensor->info_priv.whiteBalance != 0) {
2028 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2029 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2032 sensor->info_priv.snap2preview = true;
2033 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2034 #if CONFIG_SENSOR_Effect
2035 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2036 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2038 #if CONFIG_SENSOR_WhiteBalance
2039 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2040 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2042 sensor->info_priv.video2preview = true;
2043 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2044 #if CONFIG_SENSOR_Effect
2045 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2046 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2048 #if CONFIG_SENSOR_WhiteBalance
2049 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2050 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2052 sensor->info_priv.video2preview = false;
2053 sensor->info_priv.snap2preview = false;
2056 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2060 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2070 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2072 struct i2c_client *client = v4l2_get_subdevdata(sd);
2073 struct sensor *sensor = to_sensor(client);
2074 const struct sensor_datafmt *fmt;
2077 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2078 ARRAY_SIZE(sensor_colour_fmts));
2080 fmt = &sensor->info_priv.fmt;
2081 mf->code = fmt->code;
2084 if (mf->height > SENSOR_MAX_HEIGHT)
2085 mf->height = SENSOR_MAX_HEIGHT;
2086 else if (mf->height < SENSOR_MIN_HEIGHT)
2087 mf->height = SENSOR_MIN_HEIGHT;
2089 if (mf->width > SENSOR_MAX_WIDTH)
2090 mf->width = SENSOR_MAX_WIDTH;
2091 else if (mf->width < SENSOR_MIN_WIDTH)
2092 mf->width = SENSOR_MIN_WIDTH;
2094 mf->colorspace = fmt->colorspace;
2099 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2101 struct i2c_client *client = v4l2_get_subdevdata(sd);
2103 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2106 if (id->match.addr != client->addr)
2109 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2114 #if CONFIG_SENSOR_Brightness
2115 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2117 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2119 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2121 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2123 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2125 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2128 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2132 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2136 #if CONFIG_SENSOR_Effect
2137 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2139 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2141 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2143 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2145 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2147 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2150 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2154 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2158 #if CONFIG_SENSOR_Exposure
2159 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2161 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2163 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2165 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2167 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2169 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2172 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2176 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2180 #if CONFIG_SENSOR_Saturation
2181 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2183 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2185 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2187 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2189 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2191 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2194 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2198 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2202 #if CONFIG_SENSOR_Contrast
2203 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2205 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2207 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2209 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2211 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2213 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2216 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2220 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2224 #if CONFIG_SENSOR_Mirror
2225 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2227 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2229 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2231 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2233 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2235 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2238 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2242 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2246 #if CONFIG_SENSOR_Flip
2247 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2249 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2251 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2253 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2255 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2257 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2260 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2264 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2268 #if CONFIG_SENSOR_Scene
2269 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2271 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2273 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2275 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2277 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2279 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2282 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2286 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2290 #if CONFIG_SENSOR_WhiteBalance
2291 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2293 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2295 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2297 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2299 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2301 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2304 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2308 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2312 #if CONFIG_SENSOR_DigitalZoom
2313 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2315 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2316 struct sensor *sensor = to_sensor(client);
2317 const struct v4l2_queryctrl *qctrl_info;
2318 int digitalzoom_cur, digitalzoom_total;
2320 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2324 digitalzoom_cur = sensor->info_priv.digitalzoom;
2325 digitalzoom_total = qctrl_info->maximum;
2327 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2329 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2333 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2335 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2339 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2341 value = digitalzoom_total - digitalzoom_cur;
2344 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2346 value = 0 - digitalzoom_cur;
2349 digitalzoom_cur += value;
2351 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2353 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2355 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2358 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2365 #if CONFIG_SENSOR_Flash
2366 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2368 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2369 if (value == 3) { /* ddl@rock-chips.com: torch */
2370 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2372 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2374 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2378 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2383 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2385 struct i2c_client *client = v4l2_get_subdevdata(sd);
2386 struct sensor *sensor = to_sensor(client);
2387 const struct v4l2_queryctrl *qctrl;
2389 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2393 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2399 case V4L2_CID_BRIGHTNESS:
2401 ctrl->value = sensor->info_priv.brightness;
2404 case V4L2_CID_SATURATION:
2406 ctrl->value = sensor->info_priv.saturation;
2409 case V4L2_CID_CONTRAST:
2411 ctrl->value = sensor->info_priv.contrast;
2414 case V4L2_CID_DO_WHITE_BALANCE:
2416 ctrl->value = sensor->info_priv.whiteBalance;
2419 case V4L2_CID_EXPOSURE:
2421 ctrl->value = sensor->info_priv.exposure;
2424 case V4L2_CID_HFLIP:
2426 ctrl->value = sensor->info_priv.mirror;
2429 case V4L2_CID_VFLIP:
2431 ctrl->value = sensor->info_priv.flip;
2442 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2444 struct i2c_client *client = v4l2_get_subdevdata(sd);
2445 struct sensor *sensor = to_sensor(client);
2446 struct soc_camera_device *icd = client->dev.platform_data;
2447 const struct v4l2_queryctrl *qctrl;
2450 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2454 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2460 #if CONFIG_SENSOR_Brightness
2461 case V4L2_CID_BRIGHTNESS:
2463 if (ctrl->value != sensor->info_priv.brightness)
2465 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2469 sensor->info_priv.brightness = ctrl->value;
2474 #if CONFIG_SENSOR_Exposure
2475 case V4L2_CID_EXPOSURE:
2477 if (ctrl->value != sensor->info_priv.exposure)
2479 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2483 sensor->info_priv.exposure = ctrl->value;
2488 #if CONFIG_SENSOR_Saturation
2489 case V4L2_CID_SATURATION:
2491 if (ctrl->value != sensor->info_priv.saturation)
2493 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2497 sensor->info_priv.saturation = ctrl->value;
2502 #if CONFIG_SENSOR_Contrast
2503 case V4L2_CID_CONTRAST:
2505 if (ctrl->value != sensor->info_priv.contrast)
2507 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2511 sensor->info_priv.contrast = ctrl->value;
2516 #if CONFIG_SENSOR_WhiteBalance
2517 case V4L2_CID_DO_WHITE_BALANCE:
2519 if (ctrl->value != sensor->info_priv.whiteBalance)
2521 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2525 sensor->info_priv.whiteBalance = ctrl->value;
2530 #if CONFIG_SENSOR_Mirror
2531 case V4L2_CID_HFLIP:
2533 if (ctrl->value != sensor->info_priv.mirror)
2535 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2537 sensor->info_priv.mirror = ctrl->value;
2542 #if CONFIG_SENSOR_Flip
2543 case V4L2_CID_VFLIP:
2545 if (ctrl->value != sensor->info_priv.flip)
2547 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2549 sensor->info_priv.flip = ctrl->value;
2560 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2562 const struct v4l2_queryctrl *qctrl;
2563 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2564 struct sensor *sensor = to_sensor(client);
2566 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2570 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2574 switch (ext_ctrl->id)
2576 case V4L2_CID_SCENE:
2578 ext_ctrl->value = sensor->info_priv.scene;
2581 case V4L2_CID_EFFECT:
2583 ext_ctrl->value = sensor->info_priv.effect;
2586 case V4L2_CID_ZOOM_ABSOLUTE:
2588 ext_ctrl->value = sensor->info_priv.digitalzoom;
2591 case V4L2_CID_ZOOM_RELATIVE:
2595 case V4L2_CID_FOCUS_ABSOLUTE:
2597 ext_ctrl->value = sensor->info_priv.focus;
2600 case V4L2_CID_FOCUS_RELATIVE:
2604 case V4L2_CID_FLASH:
2606 ext_ctrl->value = sensor->info_priv.flash;
2614 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2616 const struct v4l2_queryctrl *qctrl;
2617 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2618 struct sensor *sensor = to_sensor(client);
2621 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2625 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2630 switch (ext_ctrl->id)
2632 #if CONFIG_SENSOR_Scene
2633 case V4L2_CID_SCENE:
2635 if (ext_ctrl->value != sensor->info_priv.scene)
2637 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2639 sensor->info_priv.scene = ext_ctrl->value;
2644 #if CONFIG_SENSOR_Effect
2645 case V4L2_CID_EFFECT:
2647 if (ext_ctrl->value != sensor->info_priv.effect)
2649 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2651 sensor->info_priv.effect= ext_ctrl->value;
2656 #if CONFIG_SENSOR_DigitalZoom
2657 case V4L2_CID_ZOOM_ABSOLUTE:
2659 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2662 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2664 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2666 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2668 sensor->info_priv.digitalzoom += val_offset;
2670 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2675 case V4L2_CID_ZOOM_RELATIVE:
2677 if (ext_ctrl->value)
2679 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2681 sensor->info_priv.digitalzoom += ext_ctrl->value;
2683 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2688 #if CONFIG_SENSOR_Focus
2689 case V4L2_CID_FOCUS_ABSOLUTE:
2691 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2694 if (ext_ctrl->value != sensor->info_priv.focus)
2696 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2698 sensor->info_priv.focus += val_offset;
2703 case V4L2_CID_FOCUS_RELATIVE:
2705 if (ext_ctrl->value)
2707 sensor->info_priv.focus += ext_ctrl->value;
2709 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2714 #if CONFIG_SENSOR_Flash
2715 case V4L2_CID_FLASH:
2717 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2719 sensor->info_priv.flash = ext_ctrl->value;
2721 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2732 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2734 struct i2c_client *client = v4l2_get_subdevdata(sd);
2735 struct soc_camera_device *icd = client->dev.platform_data;
2736 int i, error_cnt=0, error_idx=-1;
2739 for (i=0; i<ext_ctrl->count; i++) {
2740 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2747 error_idx = ext_ctrl->count;
2749 if (error_idx != -1) {
2750 ext_ctrl->error_idx = error_idx;
2757 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2759 struct i2c_client *client = v4l2_get_subdevdata(sd);
2760 struct soc_camera_device *icd = client->dev.platform_data;
2761 int i, error_cnt=0, error_idx=-1;
2764 for (i=0; i<ext_ctrl->count; i++) {
2765 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2772 error_idx = ext_ctrl->count;
2774 if (error_idx != -1) {
2775 ext_ctrl->error_idx = error_idx;
2782 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2783 * this wasn't our capture interface, so, we wait for the right one */
2784 static int sensor_video_probe(struct soc_camera_device *icd,
2785 struct i2c_client *client)
2789 struct sensor *sensor = to_sensor(client);
2791 /* We must have a parent by now. And it cannot be a wrong one.
2792 * So this entire test is completely redundant. */
2793 if (!icd->dev.parent ||
2794 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2797 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2799 goto sensor_video_probe_err;
2803 ret = sensor_write(client, 0x01, 0xf3);
2806 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2809 mdelay(5); //delay 5 microseconds
2811 /* check if it is an sensor sensor */
2812 ret = sensor_read(client, 0x04, &value);
2814 SENSOR_TR("read chip id high byte failed\n");
2816 goto sensor_video_probe_err;
2819 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2821 if (value == SENSOR_ID) {
2822 sensor->model = SENSOR_V4L2_IDENT;
2824 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2826 goto sensor_video_probe_err;
2831 sensor_video_probe_err:
2835 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2837 struct i2c_client *client = v4l2_get_subdevdata(sd);
2838 struct soc_camera_device *icd = client->dev.platform_data;
2839 struct sensor *sensor = to_sensor(client);
2841 #if CONFIG_SENSOR_Flash
2845 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2848 case RK29_CAM_SUBDEV_DEACTIVATE:
2850 sensor_deactivate(client);
2854 case RK29_CAM_SUBDEV_IOREQUEST:
2856 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2857 if (sensor->sensor_io_request != NULL) {
2858 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2859 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2860 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2861 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2862 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2863 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2866 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2868 goto sensor_ioctl_end;
2870 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2872 #if CONFIG_SENSOR_Flash
2873 if (sensor->sensor_gpio_res) {
2874 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2875 for (i = 0; i < icd->ops->num_controls; i++) {
2876 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2877 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2878 sensor_controls[i].id=0xffff;
2881 sensor->info_priv.flash = 0xff;
2882 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2883 }else{ //two cameras are the same,need to deal diffrently ,zyc
2884 for (i = 0; i < icd->ops->num_controls; i++) {
2885 if(0xffff == icd->ops->controls[i].id){
2886 sensor_controls[i].id=V4L2_CID_FLASH;
2896 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2904 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2905 enum v4l2_mbus_pixelcode *code)
2907 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2910 *code = sensor_colour_fmts[index].code;
2913 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2914 .init = sensor_init,
2915 .g_ctrl = sensor_g_control,
2916 .s_ctrl = sensor_s_control,
2917 .g_ext_ctrls = sensor_g_ext_controls,
2918 .s_ext_ctrls = sensor_s_ext_controls,
2919 .g_chip_ident = sensor_g_chip_ident,
2920 .ioctl = sensor_ioctl,
2923 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2924 .s_mbus_fmt = sensor_s_fmt,
2925 .g_mbus_fmt = sensor_g_fmt,
2926 .try_mbus_fmt = sensor_try_fmt,
2927 .enum_mbus_fmt = sensor_enum_fmt,
2930 static struct v4l2_subdev_ops sensor_subdev_ops = {
2931 .core = &sensor_subdev_core_ops,
2932 .video = &sensor_subdev_video_ops,
2935 static int sensor_probe(struct i2c_client *client,
2936 const struct i2c_device_id *did)
2938 struct sensor *sensor;
2939 struct soc_camera_device *icd = client->dev.platform_data;
2940 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2941 struct soc_camera_link *icl;
2944 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2946 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2950 icl = to_soc_camera_link(icd);
2952 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2956 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2957 dev_warn(&adapter->dev,
2958 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2962 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2966 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2968 /* Second stage probe - when a capture adapter is there */
2969 icd->ops = &sensor_ops;
2970 sensor->info_priv.fmt = sensor_colour_fmts[0];
2971 #if CONFIG_SENSOR_I2C_NOSCHED
2972 atomic_set(&sensor->tasklock_cnt,0);
2975 ret = sensor_video_probe(icd, client);
2978 i2c_set_clientdata(client, NULL);
2982 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2983 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2987 static int sensor_remove(struct i2c_client *client)
2989 struct sensor *sensor = to_sensor(client);
2990 struct soc_camera_device *icd = client->dev.platform_data;
2993 i2c_set_clientdata(client, NULL);
2994 client->driver = NULL;
3000 static const struct i2c_device_id sensor_id[] = {
3001 {SENSOR_NAME_STRING(), 0 },
3004 MODULE_DEVICE_TABLE(i2c, sensor_id);
3006 static struct i2c_driver sensor_i2c_driver = {
3008 .name = SENSOR_NAME_STRING(),
3010 .probe = sensor_probe,
3011 .remove = sensor_remove,
3012 .id_table = sensor_id,
3015 static int __init sensor_mod_init(void)
3017 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3018 return i2c_add_driver(&sensor_i2c_driver);
3021 static void __exit sensor_mod_exit(void)
3023 i2c_del_driver(&sensor_i2c_driver);
3026 device_initcall_sync(sensor_mod_init);
3027 module_exit(sensor_mod_exit);
3029 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3030 MODULE_AUTHOR("lxh@wisky.com.cn");
3031 MODULE_LICENSE("GPL");