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 <mach/rk29_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 /* init SVGA preview */
105 static struct reginfo sensor_init_data[] =
108 //Image Size/Windowing/HSYNC/VSYNC[Type1]
109 {0x03, 0x00}, //PAGEMODE(0x03)
111 {0x01, 0xf3}, //PWRCTL(0x01[P0])Bit[1]:Software Reset.
113 {0x10, 0x00},//vga mode
114 {0x11, 0x91}, //For No Fixed Framerate Bit[2]
127 {0x40, 0x00}, //HBLANK: 0x70 = 112
129 {0x42, 0x00}, //VBLANK: 0x40 = 64
130 {0x43, 0x40}, //0x04 -> 0x40: For Max Framerate = 30fps
161 {0x23, 0xb1}, //For Sun Pot
225 //Image Format, Image Effect
231 {0x40, 0x10},//brightness +1
233 {0x48, 0x98},//contrast level +1
238 {0x61, 0x00}, //Use default
239 {0x62, 0xa0}, //SATB (1.4x)
240 {0x63, 0xa0}, //SATR (1.2x)
241 {0x64, 0x48}, //AGSAT
242 {0x66, 0x90}, //wht_th2
243 {0x67, 0x36}, //wht_gain Dark (0.4x), Normal (0.75x)
292 {0x14, 0x08}, //Test Setting
293 {0x20, 0x06}, //SHARP_Negative
294 {0x21, 0x03}, //SHARP_Positive
295 {0x23, 0x30}, //SHARP_DY_CTL
296 {0x24, 0x33}, //40->33
297 {0x25, 0x08}, //SHARP_PGA_TH
298 {0x26, 0x18}, //Test Setting
299 {0x27, 0x00}, //Test Setting
300 {0x28, 0x08}, //Test Setting
301 {0x29, 0x50}, //AG_TH
302 {0x2a, 0xe0}, //region ratio
303 {0x2b, 0x10}, //Test Setting
304 {0x2c, 0x28}, //Test Setting
305 {0x2d, 0x40}, //Test Setting
306 {0x2e, 0x00}, //Test Setting
307 {0x2f, 0x00}, //Test Setting
308 {0x30, 0x11}, //Test Setting
309 {0x80, 0x03}, //SHARP2D_CTL
310 {0x81, 0x07}, //Test Setting
311 {0x90, 0x04}, //SHARP2D_SLOPE
312 {0x91, 0x02}, //SHARP2D_DIFF_CTL
313 {0x92, 0x00}, //SHARP2D_HI_CLIP
314 {0x93, 0x20}, //SHARP2D_DY_CTL
315 {0x94, 0x42}, //Test Setting
316 {0x95, 0x60}, //Test Setting
322 {0x21, 0x60}, //YCEN 80
323 {0x22, 0x66}, //76, 34, 2b
324 {0x23, 0x50}, //4b, 15, 0d
325 {0x24, 0x44}, //3b, 10, 0b
425 {0x2c, 0x2b}, //23->2b 2010_04_06 hhzin
431 {0x3b, 0x22}, //23->22 _10_04_06 hhzin
434 {0x60, 0x95}, //d5, 99
440 {0x70, 0x42},//Y Target 42
442 {0x76, 0x22}, //Unlock bnd1
443 {0x77, 0x02}, //Unlock bnd2 02->a2 _10_04_06 hhzin
445 {0x78, 0x12}, //Yth 1
446 {0x79, 0x27}, //Yth 2 26->27 _10_04_06 hhzin
447 {0x7a, 0x23}, //Yth 3
449 {0x7c, 0x1d}, //1c->1d _10_04_06 hhzin
453 {0x83, 0x00},//ExpTime 30fps
458 //{0x83, 0x00},//ExpTime 30fps
462 {0x86, 0x00},//ExpMin
466 {0x88, 0x02},//ExpMax 8fps(8fps)
471 //{0x88, 0x04},//ExpMax 8fps(8fps)
476 //{0x88, 0x02},//ExpMax 8fps(8fps)
480 {0x8b, 0x3a},//Exp100
483 {0x8d, 0x30},//Exp120
490 {0x94, 0x01}, //fix_step
497 {0x9c, 0x0b}, //4shared limit_10_04_06 hhzin
498 {0x9d, 0x3b}, // 0x06d3 --> 0x0b3b
499 {0x9e, 0x00}, //4shared Unit_10_04_06 hhzin
500 {0x9f, 0xfa}, // 0x01f4 --> 0xfa
541 {0x83, 0x52}, //RMAX Default : 50 -> 48 -> 52
542 {0x84, 0x1b}, //RMIN Default : 20
543 {0x85, 0x50}, //BMAX Default : 50, 5a -> 58 -> 55
544 {0x86, 0x25}, //BMIN Default : 20
545 {0x87, 0x4d}, //RMAXB Default : 50, 4d
546 {0x88, 0x38}, //RMINB Default : 3e, 45 --> 42
547 {0x89, 0x3e}, //BMAXB Default : 2e, 2d --> 30
548 {0x8a, 0x29}, //BMINB Default : 20, 22 --> 26 --> 29
549 {0x8b, 0x02}, //OUT TH
578 {0x01, 0x90}, //0xf1 ->0x41 : For Preview Green/Red Line.
579 {0xff, 0xff} //End of Initial Setting
584 static struct reginfo sensor_vga[] =
587 {0x10, 0x00}, //VGA Size
592 {0x40, 0x00}, //HBLANK: 0x70 = 112
594 {0x42, 0x00}, //VBLANK: 0x04 = 4
620 static struct reginfo sensor_cif[] =
626 static struct reginfo sensor_qvga[] =
629 {0x10, 0x01}, //QVGA Size: 0x10 -> 0x01
634 {0x40, 0x01}, //HBLANK: 0x0158 = 344
636 {0x42, 0x00}, //VBLANK: 0x14 = 20
639 {0x03, 0x11}, //QVGA Fixframerate
663 static struct reginfo sensor_qcif[] =
669 static struct reginfo sensor_ClrFmt_YUYV[]=
675 static struct reginfo sensor_ClrFmt_UYVY[]=
681 #if CONFIG_SENSOR_WhiteBalance
682 static struct reginfo sensor_WhiteB_Auto[]=
696 /* Cloudy Colour Temperature : 6500K - 8000K */
697 static struct reginfo sensor_WhiteB_Cloudy[]=
710 /* ClearDay Colour Temperature : 5000K - 6500K */
711 static struct reginfo sensor_WhiteB_ClearDay[]=
725 /* Office Colour Temperature : 3500K - 5000K */
726 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
728 //Office£¬Ó«¹âµÆ
741 /* Home Colour Temperature : 2500K - 3500K */
742 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
756 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
757 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
761 #if CONFIG_SENSOR_Brightness
762 static struct reginfo sensor_Brightness0[]=
770 static struct reginfo sensor_Brightness1[]=
778 static struct reginfo sensor_Brightness2[]=
786 static struct reginfo sensor_Brightness3[]=
794 static struct reginfo sensor_Brightness4[]=
802 static struct reginfo sensor_Brightness5[]=
809 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
810 sensor_Brightness4, sensor_Brightness5,NULL,
815 #if CONFIG_SENSOR_Effect
816 static struct reginfo sensor_Effect_Normal[] =
831 static struct reginfo sensor_Effect_WandB[] =
846 static struct reginfo sensor_Effect_Sepia[] =
861 static struct reginfo sensor_Effect_Negative[] =
876 static struct reginfo sensor_Effect_Bluish[] =
892 static struct reginfo sensor_Effect_Green[] =
907 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
908 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
911 #if CONFIG_SENSOR_Exposure
912 static struct reginfo sensor_Exposure0[]=
918 static struct reginfo sensor_Exposure1[]=
925 static struct reginfo sensor_Exposure2[]=
931 static struct reginfo sensor_Exposure3[]=
937 static struct reginfo sensor_Exposure4[]=
944 static struct reginfo sensor_Exposure5[]=
950 static struct reginfo sensor_Exposure6[]=
957 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
958 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
961 #if CONFIG_SENSOR_Saturation
962 static struct reginfo sensor_Saturation0[]=
971 static struct reginfo sensor_Saturation1[]=
980 static struct reginfo sensor_Saturation2[]=
988 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
991 #if CONFIG_SENSOR_Contrast
992 static struct reginfo sensor_Contrast0[]=
1000 static struct reginfo sensor_Contrast1[]=
1008 static struct reginfo sensor_Contrast2[]=
1016 static struct reginfo sensor_Contrast3[]=
1024 static struct reginfo sensor_Contrast4[]=
1033 static struct reginfo sensor_Contrast5[]=
1041 static struct reginfo sensor_Contrast6[]=
1048 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1049 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1053 #if CONFIG_SENSOR_Mirror
1054 static struct reginfo sensor_MirrorOn[]=
1060 static struct reginfo sensor_MirrorOff[]=
1065 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1067 #if CONFIG_SENSOR_Flip
1068 static struct reginfo sensor_FlipOn[]=
1074 static struct reginfo sensor_FlipOff[]=
1079 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1082 #if CONFIG_SENSOR_Scene
1083 static struct reginfo sensor_SceneAuto[] =
1088 static struct reginfo sensor_SceneNight[] =
1092 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1095 #if CONFIG_SENSOR_DigitalZoom
1096 static struct reginfo sensor_Zoom0[] =
1101 static struct reginfo sensor_Zoom1[] =
1106 static struct reginfo sensor_Zoom2[] =
1112 static struct reginfo sensor_Zoom3[] =
1116 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1118 static const struct v4l2_querymenu sensor_menus[] =
1120 #if CONFIG_SENSOR_WhiteBalance
1121 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1122 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1123 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1126 #if CONFIG_SENSOR_Effect
1127 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1128 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1129 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1132 #if CONFIG_SENSOR_Scene
1133 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1136 #if CONFIG_SENSOR_Flash
1137 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1138 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1142 static const struct v4l2_queryctrl sensor_controls[] =
1144 #if CONFIG_SENSOR_WhiteBalance
1146 .id = V4L2_CID_DO_WHITE_BALANCE,
1147 .type = V4L2_CTRL_TYPE_MENU,
1148 .name = "White Balance Control",
1156 #if CONFIG_SENSOR_Brightness
1158 .id = V4L2_CID_BRIGHTNESS,
1159 .type = V4L2_CTRL_TYPE_INTEGER,
1160 .name = "Brightness Control",
1168 #if CONFIG_SENSOR_Effect
1170 .id = V4L2_CID_EFFECT,
1171 .type = V4L2_CTRL_TYPE_MENU,
1172 .name = "Effect Control",
1180 #if CONFIG_SENSOR_Exposure
1182 .id = V4L2_CID_EXPOSURE,
1183 .type = V4L2_CTRL_TYPE_INTEGER,
1184 .name = "Exposure Control",
1192 #if CONFIG_SENSOR_Saturation
1194 .id = V4L2_CID_SATURATION,
1195 .type = V4L2_CTRL_TYPE_INTEGER,
1196 .name = "Saturation Control",
1204 #if CONFIG_SENSOR_Contrast
1206 .id = V4L2_CID_CONTRAST,
1207 .type = V4L2_CTRL_TYPE_INTEGER,
1208 .name = "Contrast Control",
1216 #if CONFIG_SENSOR_Mirror
1218 .id = V4L2_CID_HFLIP,
1219 .type = V4L2_CTRL_TYPE_BOOLEAN,
1220 .name = "Mirror Control",
1228 #if CONFIG_SENSOR_Flip
1230 .id = V4L2_CID_VFLIP,
1231 .type = V4L2_CTRL_TYPE_BOOLEAN,
1232 .name = "Flip Control",
1240 #if CONFIG_SENSOR_Scene
1242 .id = V4L2_CID_SCENE,
1243 .type = V4L2_CTRL_TYPE_MENU,
1244 .name = "Scene Control",
1252 #if CONFIG_SENSOR_DigitalZoom
1254 .id = V4L2_CID_ZOOM_RELATIVE,
1255 .type = V4L2_CTRL_TYPE_INTEGER,
1256 .name = "DigitalZoom Control",
1262 .id = V4L2_CID_ZOOM_ABSOLUTE,
1263 .type = V4L2_CTRL_TYPE_INTEGER,
1264 .name = "DigitalZoom Control",
1272 #if CONFIG_SENSOR_Focus
1274 .id = V4L2_CID_FOCUS_RELATIVE,
1275 .type = V4L2_CTRL_TYPE_INTEGER,
1276 .name = "Focus Control",
1282 .id = V4L2_CID_FOCUS_ABSOLUTE,
1283 .type = V4L2_CTRL_TYPE_INTEGER,
1284 .name = "Focus Control",
1288 .default_value = 125,
1292 #if CONFIG_SENSOR_Flash
1294 .id = V4L2_CID_FLASH,
1295 .type = V4L2_CTRL_TYPE_MENU,
1296 .name = "Flash Control",
1305 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1306 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1307 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1308 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1309 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1310 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1311 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1312 static int sensor_resume(struct soc_camera_device *icd);
1313 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1314 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1315 #if CONFIG_SENSOR_Effect
1316 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1318 #if CONFIG_SENSOR_WhiteBalance
1319 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1321 static int sensor_deactivate(struct i2c_client *client);
1323 static struct soc_camera_ops sensor_ops =
1325 .suspend = sensor_suspend,
1326 .resume = sensor_resume,
1327 .set_bus_param = sensor_set_bus_param,
1328 .query_bus_param = sensor_query_bus_param,
1329 .controls = sensor_controls,
1330 .menus = sensor_menus,
1331 .num_controls = ARRAY_SIZE(sensor_controls),
1332 .num_menus = ARRAY_SIZE(sensor_menus),
1335 /* only one fixed colorspace per pixelcode */
1336 struct sensor_datafmt {
1337 enum v4l2_mbus_pixelcode code;
1338 enum v4l2_colorspace colorspace;
1341 /* Find a data format by a pixel code in an array */
1342 static const struct sensor_datafmt *sensor_find_datafmt(
1343 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1347 for (i = 0; i < n; i++)
1348 if (fmt[i].code == code)
1354 static const struct sensor_datafmt sensor_colour_fmts[] = {
1355 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1356 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1359 typedef struct sensor_info_priv_s
1373 unsigned char mirror; /* HFLIP */
1374 unsigned char flip; /* VFLIP */
1375 unsigned int winseqe_cur_addr;
1376 struct sensor_datafmt fmt;
1377 unsigned int funmodule_state;
1379 } sensor_info_priv_t;
1383 struct v4l2_subdev subdev;
1384 struct i2c_client *client;
1385 sensor_info_priv_t info_priv;
1386 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1387 #if CONFIG_SENSOR_I2C_NOSCHED
1388 atomic_t tasklock_cnt;
1390 struct rk29camera_platform_data *sensor_io_request;
1391 struct rk29camera_gpio_res *sensor_gpio_res;
1394 static struct sensor* to_sensor(const struct i2c_client *client)
1396 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1399 static int sensor_task_lock(struct i2c_client *client, int lock)
1401 #if CONFIG_SENSOR_I2C_NOSCHED
1403 struct sensor *sensor = to_sensor(client);
1406 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1407 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1408 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1412 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1413 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1414 goto sensor_task_lock_err;
1419 atomic_add(1, &sensor->tasklock_cnt);
1421 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1422 atomic_sub(1, &sensor->tasklock_cnt);
1424 if (atomic_read(&sensor->tasklock_cnt) == 0)
1429 sensor_task_lock_err:
1437 /* sensor register */
1438 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1442 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1444 return (ret > 0)? 0 : ret;
1447 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1451 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1453 return (ret > 0)? 0 : ret;
1456 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1460 struct i2c_msg msg[1];
1465 msg->addr = client->addr;
1466 msg->flags = client->flags;
1468 msg->len = sizeof(buf);
1469 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1470 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1475 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1476 err = i2c_transfer(client->adapter, msg, 1);
1481 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1489 /* sensor register read */
1490 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1494 struct i2c_msg msg[2];
1498 msg[0].addr = client->addr;
1499 msg[0].flags = client->flags;
1501 msg[0].len = sizeof(buf);
1502 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1503 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1505 msg[1].addr = client->addr;
1506 msg[1].flags = client->flags|I2C_M_RD;
1509 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1510 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1514 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1515 err = i2c_transfer(client->adapter, msg, 2);
1521 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1531 /* write a array of registers */
1532 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1536 #if CONFIG_SENSOR_I2C_RDWRCHK
1541 if (sensor_task_lock(client, 1) < 0)
1542 goto sensor_write_array_end;
1543 while (regarray[i].reg != END_REG)
1545 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1549 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1553 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1555 goto sensor_write_array_end;
1558 #if CONFIG_SENSOR_I2C_RDWRCHK
1560 sensor_read(client, regarray[i].reg, &valchk);
1561 if (valchk != regarray[i].val)
1562 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1568 sensor_write_array_end:
1569 sensor_task_lock(client,0);
1572 #if CONFIG_SENSOR_I2C_RDWRCHK
1573 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1581 while (regarray[i].reg != 0)
1583 sensor_read(client, regarray[i].reg, &valchk);
1584 if (valchk != regarray[i].val)
1585 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1592 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1594 struct soc_camera_link *icl = to_soc_camera_link(icd);
1597 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1600 case Sensor_PowerDown:
1602 if (icl->powerdown) {
1603 ret = icl->powerdown(icd->pdev, on);
1604 if (ret == RK29_CAM_IO_SUCCESS) {
1608 icl->reset(icd->pdev);
1610 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1612 goto sensor_power_end;
1619 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1620 struct sensor *sensor = to_sensor(client);
1622 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1623 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1629 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1636 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1638 struct i2c_client *client = v4l2_get_subdevdata(sd);
1639 struct soc_camera_device *icd = client->dev.platform_data;
1640 struct sensor *sensor = to_sensor(client);
1641 const struct v4l2_queryctrl *qctrl;
1642 const struct sensor_datafmt *fmt;
1646 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1648 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1650 goto sensor_INIT_ERR;
1654 if (sensor_task_lock(client,1)<0)
1655 goto sensor_INIT_ERR;
1657 ret = sensor_write(client, 0x01, 0xF3);
1660 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1662 goto sensor_INIT_ERR;
1665 mdelay(5); //delay 5 microseconds
1666 /* check if it is an sensor sensor */
1667 ret = sensor_read(client, 0x04, &value);
1669 SENSOR_TR("read chip id high byte failed\n");
1671 goto sensor_INIT_ERR;
1675 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1676 if (value == SENSOR_ID) {
1677 sensor->model = SENSOR_V4L2_IDENT;
1679 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
1681 goto sensor_INIT_ERR;
1684 ret = sensor_write_array(client, sensor_init_data);
1687 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1688 goto sensor_INIT_ERR;
1690 sensor_task_lock(client,0);
1691 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1692 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1694 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1696 goto sensor_INIT_ERR;
1698 sensor->info_priv.fmt = *fmt;
1700 /* sensor sensor information for initialization */
1701 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1703 sensor->info_priv.whiteBalance = qctrl->default_value;
1704 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1706 sensor->info_priv.brightness = qctrl->default_value;
1707 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1709 sensor->info_priv.effect = qctrl->default_value;
1710 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1712 sensor->info_priv.exposure = qctrl->default_value;
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1716 sensor->info_priv.saturation = qctrl->default_value;
1717 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1719 sensor->info_priv.contrast = qctrl->default_value;
1720 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1722 sensor->info_priv.mirror = qctrl->default_value;
1723 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1725 sensor->info_priv.flip = qctrl->default_value;
1726 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1728 sensor->info_priv.scene = qctrl->default_value;
1729 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1731 sensor->info_priv.digitalzoom = qctrl->default_value;
1733 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1734 #if CONFIG_SENSOR_Focus
1736 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1738 sensor->info_priv.focus = qctrl->default_value;
1741 #if CONFIG_SENSOR_Flash
1742 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1744 sensor->info_priv.flash = qctrl->default_value;
1747 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);
1748 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1751 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1752 sensor_task_lock(client,0);
1753 sensor_deactivate(client);
1757 static int sensor_deactivate(struct i2c_client *client)
1759 struct soc_camera_device *icd = client->dev.platform_data;
1760 struct sensor *sensor = to_sensor(client);
1761 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1763 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1764 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1766 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1767 icd->user_width = SENSOR_INIT_WIDTH;
1768 icd->user_height = SENSOR_INIT_HEIGHT;
1770 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1774 static struct reginfo sensor_power_down_sequence[]=
1778 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1781 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1783 if (pm_msg.event == PM_EVENT_SUSPEND) {
1784 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1785 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1787 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1790 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1792 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1797 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1803 static int sensor_resume(struct soc_camera_device *icd)
1807 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1809 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1813 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1819 static int sensor_set_bus_param(struct soc_camera_device *icd,
1820 unsigned long flags)
1826 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1828 struct soc_camera_link *icl = to_soc_camera_link(icd);
1829 unsigned long flags = SENSOR_BUS_PARAM;
1831 return soc_camera_apply_sensor_flags(icl, flags);
1834 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1836 struct i2c_client *client = v4l2_get_subdevdata(sd);
1837 struct soc_camera_device *icd = client->dev.platform_data;
1838 struct sensor *sensor = to_sensor(client);
1840 mf->width = icd->user_width;
1841 mf->height = icd->user_height;
1842 mf->code = sensor->info_priv.fmt.code;
1843 mf->colorspace = sensor->info_priv.fmt.colorspace;
1844 mf->field = V4L2_FIELD_NONE;
1848 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1852 if ((mf->width == 1024) && (mf->height == 768)) {
1854 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1856 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1858 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1860 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1865 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1869 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1873 if ((mf->width == 1280) && (mf->height == 720)) {
1875 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1880 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1883 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1885 struct i2c_client *client = v4l2_get_subdevdata(sd);
1886 struct sensor *sensor = to_sensor(client);
1887 const struct sensor_datafmt *fmt;
1888 const struct v4l2_queryctrl *qctrl;
1889 struct soc_camera_device *icd = client->dev.platform_data;
1890 struct reginfo *winseqe_set_addr=NULL;
1891 int ret=0, set_w,set_h;
1893 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1894 ARRAY_SIZE(sensor_colour_fmts));
1897 goto sensor_s_fmt_end;
1900 if (sensor->info_priv.fmt.code != mf->code) {
1903 case V4L2_MBUS_FMT_YUYV8_2X8:
1905 winseqe_set_addr = sensor_ClrFmt_YUYV;
1908 case V4L2_MBUS_FMT_UYVY8_2X8:
1910 winseqe_set_addr = sensor_ClrFmt_UYVY;
1916 if (winseqe_set_addr != NULL) {
1917 sensor_write_array(client, winseqe_set_addr);
1918 sensor->info_priv.fmt.code = mf->code;
1919 sensor->info_priv.fmt.colorspace= mf->colorspace;
1920 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1922 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1929 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg != END_REG))
1931 winseqe_set_addr = sensor_qcif;
1935 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg != END_REG))
1937 winseqe_set_addr = sensor_qvga;
1941 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg != END_REG))
1943 winseqe_set_addr = sensor_cif;
1947 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg != END_REG))
1949 winseqe_set_addr = sensor_vga;
1955 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1956 set_w = SENSOR_INIT_WIDTH;
1957 set_h = SENSOR_INIT_HEIGHT;
1959 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1962 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1963 #if CONFIG_SENSOR_Flash
1964 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1965 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1966 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1967 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1969 } else { /* ddl@rock-chips.com : Video */
1970 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1971 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1972 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1976 ret |= sensor_write_array(client, winseqe_set_addr);
1978 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1979 #if CONFIG_SENSOR_Flash
1980 if (sensor_fmt_capturechk(sd,mf) == true) {
1981 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1982 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1983 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1987 goto sensor_s_fmt_end;
1990 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1992 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1993 #if CONFIG_SENSOR_Effect
1994 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1995 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1997 #if CONFIG_SENSOR_WhiteBalance
1998 if (sensor->info_priv.whiteBalance != 0) {
1999 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2000 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2003 sensor->info_priv.snap2preview = true;
2004 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2005 #if CONFIG_SENSOR_Effect
2006 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2007 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2009 #if CONFIG_SENSOR_WhiteBalance
2010 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2011 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2013 sensor->info_priv.video2preview = true;
2014 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2015 #if CONFIG_SENSOR_Effect
2016 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2017 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2019 #if CONFIG_SENSOR_WhiteBalance
2020 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2021 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2023 sensor->info_priv.video2preview = false;
2024 sensor->info_priv.snap2preview = false;
2027 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2031 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2041 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2043 struct i2c_client *client = v4l2_get_subdevdata(sd);
2044 struct sensor *sensor = to_sensor(client);
2045 const struct sensor_datafmt *fmt;
2048 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2049 ARRAY_SIZE(sensor_colour_fmts));
2051 fmt = &sensor->info_priv.fmt;
2052 mf->code = fmt->code;
2055 if (mf->height > SENSOR_MAX_HEIGHT)
2056 mf->height = SENSOR_MAX_HEIGHT;
2057 else if (mf->height < SENSOR_MIN_HEIGHT)
2058 mf->height = SENSOR_MIN_HEIGHT;
2060 if (mf->width > SENSOR_MAX_WIDTH)
2061 mf->width = SENSOR_MAX_WIDTH;
2062 else if (mf->width < SENSOR_MIN_WIDTH)
2063 mf->width = SENSOR_MIN_WIDTH;
2065 mf->colorspace = fmt->colorspace;
2070 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2072 struct i2c_client *client = v4l2_get_subdevdata(sd);
2074 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2077 if (id->match.addr != client->addr)
2080 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2085 #if CONFIG_SENSOR_Brightness
2086 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2088 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2090 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2092 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2094 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2096 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2099 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2103 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2107 #if CONFIG_SENSOR_Effect
2108 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2110 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2112 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2114 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2116 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2118 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2121 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2125 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2129 #if CONFIG_SENSOR_Exposure
2130 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2132 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2134 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2136 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2138 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2140 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2143 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2147 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2151 #if CONFIG_SENSOR_Saturation
2152 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2154 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2156 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2158 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2160 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2162 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2165 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2169 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2173 #if CONFIG_SENSOR_Contrast
2174 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2176 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2178 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2180 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2182 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2184 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2187 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2191 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2195 #if CONFIG_SENSOR_Mirror
2196 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2198 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2200 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2202 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2204 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2206 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2209 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2213 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2217 #if CONFIG_SENSOR_Flip
2218 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2220 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2222 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2224 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2226 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2228 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2231 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2235 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2239 #if CONFIG_SENSOR_Scene
2240 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2242 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2244 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2246 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2248 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2250 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2253 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2257 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2261 #if CONFIG_SENSOR_WhiteBalance
2262 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2264 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2266 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2268 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2270 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2272 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2275 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2279 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2283 #if CONFIG_SENSOR_DigitalZoom
2284 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2286 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2287 struct sensor *sensor = to_sensor(client);
2288 const struct v4l2_queryctrl *qctrl_info;
2289 int digitalzoom_cur, digitalzoom_total;
2291 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2295 digitalzoom_cur = sensor->info_priv.digitalzoom;
2296 digitalzoom_total = qctrl_info->maximum;
2298 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2300 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2304 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2306 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2310 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2312 value = digitalzoom_total - digitalzoom_cur;
2315 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2317 value = 0 - digitalzoom_cur;
2320 digitalzoom_cur += value;
2322 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2324 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2326 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2329 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2336 #if CONFIG_SENSOR_Flash
2337 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2339 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2340 if (value == 3) { /* ddl@rock-chips.com: torch */
2341 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2343 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2345 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2349 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2354 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2356 struct i2c_client *client = v4l2_get_subdevdata(sd);
2357 struct sensor *sensor = to_sensor(client);
2358 const struct v4l2_queryctrl *qctrl;
2360 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2364 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2370 case V4L2_CID_BRIGHTNESS:
2372 ctrl->value = sensor->info_priv.brightness;
2375 case V4L2_CID_SATURATION:
2377 ctrl->value = sensor->info_priv.saturation;
2380 case V4L2_CID_CONTRAST:
2382 ctrl->value = sensor->info_priv.contrast;
2385 case V4L2_CID_DO_WHITE_BALANCE:
2387 ctrl->value = sensor->info_priv.whiteBalance;
2390 case V4L2_CID_EXPOSURE:
2392 ctrl->value = sensor->info_priv.exposure;
2395 case V4L2_CID_HFLIP:
2397 ctrl->value = sensor->info_priv.mirror;
2400 case V4L2_CID_VFLIP:
2402 ctrl->value = sensor->info_priv.flip;
2413 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2415 struct i2c_client *client = v4l2_get_subdevdata(sd);
2416 struct sensor *sensor = to_sensor(client);
2417 struct soc_camera_device *icd = client->dev.platform_data;
2418 const struct v4l2_queryctrl *qctrl;
2421 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2425 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2431 #if CONFIG_SENSOR_Brightness
2432 case V4L2_CID_BRIGHTNESS:
2434 if (ctrl->value != sensor->info_priv.brightness)
2436 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2440 sensor->info_priv.brightness = ctrl->value;
2445 #if CONFIG_SENSOR_Exposure
2446 case V4L2_CID_EXPOSURE:
2448 if (ctrl->value != sensor->info_priv.exposure)
2450 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2454 sensor->info_priv.exposure = ctrl->value;
2459 #if CONFIG_SENSOR_Saturation
2460 case V4L2_CID_SATURATION:
2462 if (ctrl->value != sensor->info_priv.saturation)
2464 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2468 sensor->info_priv.saturation = ctrl->value;
2473 #if CONFIG_SENSOR_Contrast
2474 case V4L2_CID_CONTRAST:
2476 if (ctrl->value != sensor->info_priv.contrast)
2478 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2482 sensor->info_priv.contrast = ctrl->value;
2487 #if CONFIG_SENSOR_WhiteBalance
2488 case V4L2_CID_DO_WHITE_BALANCE:
2490 if (ctrl->value != sensor->info_priv.whiteBalance)
2492 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2496 sensor->info_priv.whiteBalance = ctrl->value;
2501 #if CONFIG_SENSOR_Mirror
2502 case V4L2_CID_HFLIP:
2504 if (ctrl->value != sensor->info_priv.mirror)
2506 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2508 sensor->info_priv.mirror = ctrl->value;
2513 #if CONFIG_SENSOR_Flip
2514 case V4L2_CID_VFLIP:
2516 if (ctrl->value != sensor->info_priv.flip)
2518 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2520 sensor->info_priv.flip = ctrl->value;
2531 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2533 const struct v4l2_queryctrl *qctrl;
2534 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2535 struct sensor *sensor = to_sensor(client);
2537 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2541 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2545 switch (ext_ctrl->id)
2547 case V4L2_CID_SCENE:
2549 ext_ctrl->value = sensor->info_priv.scene;
2552 case V4L2_CID_EFFECT:
2554 ext_ctrl->value = sensor->info_priv.effect;
2557 case V4L2_CID_ZOOM_ABSOLUTE:
2559 ext_ctrl->value = sensor->info_priv.digitalzoom;
2562 case V4L2_CID_ZOOM_RELATIVE:
2566 case V4L2_CID_FOCUS_ABSOLUTE:
2568 ext_ctrl->value = sensor->info_priv.focus;
2571 case V4L2_CID_FOCUS_RELATIVE:
2575 case V4L2_CID_FLASH:
2577 ext_ctrl->value = sensor->info_priv.flash;
2585 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2587 const struct v4l2_queryctrl *qctrl;
2588 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2589 struct sensor *sensor = to_sensor(client);
2592 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2596 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2601 switch (ext_ctrl->id)
2603 #if CONFIG_SENSOR_Scene
2604 case V4L2_CID_SCENE:
2606 if (ext_ctrl->value != sensor->info_priv.scene)
2608 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2610 sensor->info_priv.scene = ext_ctrl->value;
2615 #if CONFIG_SENSOR_Effect
2616 case V4L2_CID_EFFECT:
2618 if (ext_ctrl->value != sensor->info_priv.effect)
2620 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2622 sensor->info_priv.effect= ext_ctrl->value;
2627 #if CONFIG_SENSOR_DigitalZoom
2628 case V4L2_CID_ZOOM_ABSOLUTE:
2630 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2633 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2635 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2637 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2639 sensor->info_priv.digitalzoom += val_offset;
2641 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2646 case V4L2_CID_ZOOM_RELATIVE:
2648 if (ext_ctrl->value)
2650 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2652 sensor->info_priv.digitalzoom += ext_ctrl->value;
2654 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2659 #if CONFIG_SENSOR_Focus
2660 case V4L2_CID_FOCUS_ABSOLUTE:
2662 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2665 if (ext_ctrl->value != sensor->info_priv.focus)
2667 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2669 sensor->info_priv.focus += val_offset;
2674 case V4L2_CID_FOCUS_RELATIVE:
2676 if (ext_ctrl->value)
2678 sensor->info_priv.focus += ext_ctrl->value;
2680 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2685 #if CONFIG_SENSOR_Flash
2686 case V4L2_CID_FLASH:
2688 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2690 sensor->info_priv.flash = ext_ctrl->value;
2692 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2703 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2705 struct i2c_client *client = v4l2_get_subdevdata(sd);
2706 struct soc_camera_device *icd = client->dev.platform_data;
2707 int i, error_cnt=0, error_idx=-1;
2710 for (i=0; i<ext_ctrl->count; i++) {
2711 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2718 error_idx = ext_ctrl->count;
2720 if (error_idx != -1) {
2721 ext_ctrl->error_idx = error_idx;
2728 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2730 struct i2c_client *client = v4l2_get_subdevdata(sd);
2731 struct soc_camera_device *icd = client->dev.platform_data;
2732 int i, error_cnt=0, error_idx=-1;
2735 for (i=0; i<ext_ctrl->count; i++) {
2736 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2743 error_idx = ext_ctrl->count;
2745 if (error_idx != -1) {
2746 ext_ctrl->error_idx = error_idx;
2753 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2754 * this wasn't our capture interface, so, we wait for the right one */
2755 static int sensor_video_probe(struct soc_camera_device *icd,
2756 struct i2c_client *client)
2760 struct sensor *sensor = to_sensor(client);
2762 /* We must have a parent by now. And it cannot be a wrong one.
2763 * So this entire test is completely redundant. */
2764 if (!icd->dev.parent ||
2765 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2768 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2770 goto sensor_video_probe_err;
2774 ret = sensor_write(client, 0x01, 0xf3);
2777 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2780 mdelay(5); //delay 5 microseconds
2782 /* check if it is an sensor sensor */
2783 ret = sensor_read(client, 0x04, &value);
2785 SENSOR_TR("read chip id high byte failed\n");
2787 goto sensor_video_probe_err;
2790 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2792 if (value == SENSOR_ID) {
2793 sensor->model = SENSOR_V4L2_IDENT;
2795 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), value);
2797 goto sensor_video_probe_err;
2802 sensor_video_probe_err:
2806 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2808 struct i2c_client *client = v4l2_get_subdevdata(sd);
2809 struct soc_camera_device *icd = client->dev.platform_data;
2810 struct sensor *sensor = to_sensor(client);
2812 #if CONFIG_SENSOR_Flash
2816 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2819 case RK29_CAM_SUBDEV_DEACTIVATE:
2821 sensor_deactivate(client);
2825 case RK29_CAM_SUBDEV_IOREQUEST:
2827 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2828 if (sensor->sensor_io_request != NULL) {
2829 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2830 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2831 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2832 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2833 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2834 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2837 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2839 goto sensor_ioctl_end;
2841 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2843 #if CONFIG_SENSOR_Flash
2844 if (sensor->sensor_gpio_res) {
2845 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2846 for (i = 0; i < icd->ops->num_controls; i++) {
2847 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2848 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2851 sensor->info_priv.flash = 0xff;
2852 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2860 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2868 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2869 enum v4l2_mbus_pixelcode *code)
2871 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2874 *code = sensor_colour_fmts[index].code;
2877 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2878 .init = sensor_init,
2879 .g_ctrl = sensor_g_control,
2880 .s_ctrl = sensor_s_control,
2881 .g_ext_ctrls = sensor_g_ext_controls,
2882 .s_ext_ctrls = sensor_s_ext_controls,
2883 .g_chip_ident = sensor_g_chip_ident,
2884 .ioctl = sensor_ioctl,
2887 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2888 .s_mbus_fmt = sensor_s_fmt,
2889 .g_mbus_fmt = sensor_g_fmt,
2890 .try_mbus_fmt = sensor_try_fmt,
2891 .enum_mbus_fmt = sensor_enum_fmt,
2894 static struct v4l2_subdev_ops sensor_subdev_ops = {
2895 .core = &sensor_subdev_core_ops,
2896 .video = &sensor_subdev_video_ops,
2899 static int sensor_probe(struct i2c_client *client,
2900 const struct i2c_device_id *did)
2902 struct sensor *sensor;
2903 struct soc_camera_device *icd = client->dev.platform_data;
2904 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2905 struct soc_camera_link *icl;
2908 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2910 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2914 icl = to_soc_camera_link(icd);
2916 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2920 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2921 dev_warn(&adapter->dev,
2922 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2926 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2930 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2932 /* Second stage probe - when a capture adapter is there */
2933 icd->ops = &sensor_ops;
2934 sensor->info_priv.fmt = sensor_colour_fmts[0];
2935 #if CONFIG_SENSOR_I2C_NOSCHED
2936 atomic_set(&sensor->tasklock_cnt,0);
2939 ret = sensor_video_probe(icd, client);
2942 i2c_set_clientdata(client, NULL);
2946 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2950 static int sensor_remove(struct i2c_client *client)
2952 struct sensor *sensor = to_sensor(client);
2953 struct soc_camera_device *icd = client->dev.platform_data;
2956 i2c_set_clientdata(client, NULL);
2957 client->driver = NULL;
2963 static const struct i2c_device_id sensor_id[] = {
2964 {SENSOR_NAME_STRING(), 0 },
2967 MODULE_DEVICE_TABLE(i2c, sensor_id);
2969 static struct i2c_driver sensor_i2c_driver = {
2971 .name = SENSOR_NAME_STRING(),
2973 .probe = sensor_probe,
2974 .remove = sensor_remove,
2975 .id_table = sensor_id,
2978 static int __init sensor_mod_init(void)
2980 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2981 return i2c_add_driver(&sensor_i2c_driver);
2984 static void __exit sensor_mod_exit(void)
2986 i2c_del_driver(&sensor_i2c_driver);
2989 device_initcall_sync(sensor_mod_init);
2990 module_exit(sensor_mod_exit);
2992 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2993 MODULE_AUTHOR("lxh@wisky.com.cn");
2994 MODULE_LICENSE("GPL");