2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
23 #include <linux/vmalloc.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_OV2659
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2659
48 #define SENSOR_ID 0x2656
49 #define SENSOR_MIN_WIDTH 800
50 #define SENSOR_MIN_HEIGHT 600
51 #define SENSOR_MAX_WIDTH 1600
52 #define SENSOR_MAX_HEIGHT 1200
53 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT sensor_init_height
55 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM sensor_init_busparam
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 1
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 1
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 350000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
81 #define COLOR_TEMPERATURE_OFFICE_DN 3500
82 #define COLOR_TEMPERATURE_OFFICE_UP 5000
83 #define COLOR_TEMPERATURE_HOME_DN 2500
84 #define COLOR_TEMPERATURE_HOME_UP 3500
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
89 #define SENSOR_AF_IS_ERR (0x00<<0)
90 #define SENSOR_AF_IS_OK (0x01<<0)
91 #define SENSOR_INIT_IS_ERR (0x00<<28)
92 #define SENSOR_INIT_IS_OK (0x01<<28)
99 //flash off in fixed time to prevent from too hot , zyc
101 struct soc_camera_device *icd;
102 struct hrtimer timer;
104 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
106 static struct flash_timer flash_off_timer;
107 //for user defined if user want to customize the series , zyc
108 #ifdef CONFIG_OV2659_USER_DEFINED_SERIES
109 #include "ov2659_user_series.c"
111 /* init 800*600 SVGA */
112 static struct reginfo sensor_init_data[] =
117 //{0x0100, 0x01}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
283 static struct reginfo sensor_720p[]=
289 //{0x0100, 0x01 }, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
452 static struct reginfo sensor_uxga[] =
503 static struct reginfo sensor_sxga[] =
508 static struct reginfo sensor_xga[] =
513 static struct reginfo sensor_svga[] =
515 {0x0100, 0x00}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
561 {0x0100, 0x01}, //software wake
566 static struct reginfo sensor_vga[] =
572 static struct reginfo sensor_cif[] =
578 static struct reginfo sensor_qvga[] =
584 static struct reginfo sensor_qcif[] =
591 static struct reginfo ov2655_qqvga[] =
635 static struct reginfo ov2655_Sharpness_auto[] =
640 static struct reginfo ov2655_Sharpness1[] =
646 static struct reginfo ov2655_Sharpness2[][3] =
653 static struct reginfo ov2655_Sharpness3[] =
659 static struct reginfo ov2655_Sharpness4[]=
666 static struct reginfo ov2655_Sharpness5[] =
674 static struct reginfo sensor_ClrFmt_YUYV[]=
680 static struct reginfo sensor_ClrFmt_UYVY[]=
686 #if CONFIG_SENSOR_WhiteBalance
687 static struct reginfo sensor_WhiteB_Auto[]=
689 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
692 /* Cloudy Colour Temperature : 6500K - 8000K */
693 static struct reginfo sensor_WhiteB_Cloudy[]=
704 /* ClearDay Colour Temperature : 5000K - 6500K */
705 static struct reginfo sensor_WhiteB_ClearDay[]=
717 /* Office Colour Temperature : 3500K - 5000K */
718 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
731 /* Home Colour Temperature : 2500K - 3500K */
732 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
744 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
745 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
749 #if CONFIG_SENSOR_Brightness
750 static struct reginfo sensor_Brightness0[]=
756 static struct reginfo sensor_Brightness1[]=
763 static struct reginfo sensor_Brightness2[]=
770 static struct reginfo sensor_Brightness3[]=
777 static struct reginfo sensor_Brightness4[]=
784 static struct reginfo sensor_Brightness5[]=
790 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
791 sensor_Brightness4, sensor_Brightness5,NULL,
796 #if CONFIG_SENSOR_Effect
797 static struct reginfo sensor_Effect_Normal[] =
803 static struct reginfo sensor_Effect_WandB[] =
809 static struct reginfo sensor_Effect_Sepia[] =
817 static struct reginfo sensor_Effect_Negative[] =
820 {0x507b, 0x40}, //bit[6] negative
823 static struct reginfo sensor_Effect_Bluish[] =
832 static struct reginfo sensor_Effect_Green[] =
840 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
841 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
844 #if CONFIG_SENSOR_Exposure
845 static struct reginfo sensor_Exposure0[]=
850 static struct reginfo sensor_Exposure1[]=
855 static struct reginfo sensor_Exposure2[]=
860 static struct reginfo sensor_Exposure3[]=
865 static struct reginfo sensor_Exposure4[]=
870 static struct reginfo sensor_Exposure5[]=
875 static struct reginfo sensor_Exposure6[]=
880 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
881 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
884 #if CONFIG_SENSOR_Saturation
885 static struct reginfo sensor_Saturation0[]=
890 static struct reginfo sensor_Saturation1[]=
895 static struct reginfo sensor_Saturation2[]=
899 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
902 #if CONFIG_SENSOR_Contrast
903 static struct reginfo sensor_Contrast0[]=
908 static struct reginfo sensor_Contrast1[]=
913 static struct reginfo sensor_Contrast2[]=
918 static struct reginfo sensor_Contrast3[]=
923 static struct reginfo sensor_Contrast4[]=
929 static struct reginfo sensor_Contrast5[]=
934 static struct reginfo sensor_Contrast6[]=
938 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
939 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
943 #if CONFIG_SENSOR_Mirror
944 static struct reginfo sensor_MirrorOn[]=
949 static struct reginfo sensor_MirrorOff[]=
953 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
955 #if CONFIG_SENSOR_Flip
956 static struct reginfo sensor_FlipOn[]=
961 static struct reginfo sensor_FlipOff[]=
965 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
968 #if CONFIG_SENSOR_Scene
969 static struct reginfo sensor_SceneAuto[] =
975 static struct reginfo sensor_SceneNight[] =
988 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
991 #if CONFIG_SENSOR_DigitalZoom
992 static struct reginfo sensor_Zoom0[] =
997 static struct reginfo sensor_Zoom1[] =
1002 static struct reginfo sensor_Zoom2[] =
1008 static struct reginfo sensor_Zoom3[] =
1012 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1014 static const struct v4l2_querymenu sensor_menus[] =
1016 #if CONFIG_SENSOR_WhiteBalance
1017 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1018 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1019 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1022 #if CONFIG_SENSOR_Effect
1023 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1024 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1025 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1028 #if CONFIG_SENSOR_Scene
1029 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1032 #if CONFIG_SENSOR_Flash
1033 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1034 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1038 static struct v4l2_queryctrl sensor_controls[] =
1040 #if CONFIG_SENSOR_WhiteBalance
1042 .id = V4L2_CID_DO_WHITE_BALANCE,
1043 .type = V4L2_CTRL_TYPE_MENU,
1044 .name = "White Balance Control",
1052 #if CONFIG_SENSOR_Brightness
1054 .id = V4L2_CID_BRIGHTNESS,
1055 .type = V4L2_CTRL_TYPE_INTEGER,
1056 .name = "Brightness Control",
1064 #if CONFIG_SENSOR_Effect
1066 .id = V4L2_CID_EFFECT,
1067 .type = V4L2_CTRL_TYPE_MENU,
1068 .name = "Effect Control",
1076 #if CONFIG_SENSOR_Exposure
1078 .id = V4L2_CID_EXPOSURE,
1079 .type = V4L2_CTRL_TYPE_INTEGER,
1080 .name = "Exposure Control",
1088 #if CONFIG_SENSOR_Saturation
1090 .id = V4L2_CID_SATURATION,
1091 .type = V4L2_CTRL_TYPE_INTEGER,
1092 .name = "Saturation Control",
1100 #if CONFIG_SENSOR_Contrast
1102 .id = V4L2_CID_CONTRAST,
1103 .type = V4L2_CTRL_TYPE_INTEGER,
1104 .name = "Contrast Control",
1112 #if CONFIG_SENSOR_Mirror
1114 .id = V4L2_CID_HFLIP,
1115 .type = V4L2_CTRL_TYPE_BOOLEAN,
1116 .name = "Mirror Control",
1124 #if CONFIG_SENSOR_Flip
1126 .id = V4L2_CID_VFLIP,
1127 .type = V4L2_CTRL_TYPE_BOOLEAN,
1128 .name = "Flip Control",
1136 #if CONFIG_SENSOR_Scene
1138 .id = V4L2_CID_SCENE,
1139 .type = V4L2_CTRL_TYPE_MENU,
1140 .name = "Scene Control",
1148 #if CONFIG_SENSOR_DigitalZoom
1150 .id = V4L2_CID_ZOOM_RELATIVE,
1151 .type = V4L2_CTRL_TYPE_INTEGER,
1152 .name = "DigitalZoom Control",
1158 .id = V4L2_CID_ZOOM_ABSOLUTE,
1159 .type = V4L2_CTRL_TYPE_INTEGER,
1160 .name = "DigitalZoom Control",
1168 #if CONFIG_SENSOR_Focus
1170 .id = V4L2_CID_FOCUS_RELATIVE,
1171 .type = V4L2_CTRL_TYPE_INTEGER,
1172 .name = "Focus Control",
1178 .id = V4L2_CID_FOCUS_ABSOLUTE,
1179 .type = V4L2_CTRL_TYPE_INTEGER,
1180 .name = "Focus Control",
1184 .default_value = 125,
1188 #if CONFIG_SENSOR_Flash
1190 .id = V4L2_CID_FLASH,
1191 .type = V4L2_CTRL_TYPE_MENU,
1192 .name = "Flash Control",
1201 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1202 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1203 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1204 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1205 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1206 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1207 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1208 static int sensor_resume(struct soc_camera_device *icd);
1209 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1210 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1211 #if CONFIG_SENSOR_Effect
1212 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1214 #if CONFIG_SENSOR_WhiteBalance
1215 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1217 static int sensor_deactivate(struct i2c_client *client);
1219 static struct soc_camera_ops sensor_ops =
1221 .suspend = sensor_suspend,
1222 .resume = sensor_resume,
1223 .set_bus_param = sensor_set_bus_param,
1224 .query_bus_param = sensor_query_bus_param,
1225 .controls = sensor_controls,
1226 .menus = sensor_menus,
1227 .num_controls = ARRAY_SIZE(sensor_controls),
1228 .num_menus = ARRAY_SIZE(sensor_menus),
1231 /* only one fixed colorspace per pixelcode */
1232 struct sensor_datafmt {
1233 enum v4l2_mbus_pixelcode code;
1234 enum v4l2_colorspace colorspace;
1237 /* Find a data format by a pixel code in an array */
1238 static const struct sensor_datafmt *sensor_find_datafmt(
1239 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1243 for (i = 0; i < n; i++)
1244 if (fmt[i].code == code)
1250 static const struct sensor_datafmt sensor_colour_fmts[] = {
1251 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1252 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1255 typedef struct sensor_info_priv_s
1269 unsigned char mirror; /* HFLIP */
1270 unsigned char flip; /* VFLIP */
1271 unsigned int winseqe_cur_addr;
1272 struct sensor_datafmt fmt;
1273 unsigned int funmodule_state;
1274 } sensor_info_priv_t;
1278 struct v4l2_subdev subdev;
1279 struct i2c_client *client;
1280 sensor_info_priv_t info_priv;
1281 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1282 #if CONFIG_SENSOR_I2C_NOSCHED
1283 atomic_t tasklock_cnt;
1285 struct rk29camera_platform_data *sensor_io_request;
1286 struct rk29camera_gpio_res *sensor_gpio_res;
1290 static struct sensor* to_sensor(const struct i2c_client *client)
1292 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1295 static int sensor_task_lock(struct i2c_client *client, int lock)
1297 #if CONFIG_SENSOR_I2C_NOSCHED
1299 struct sensor *sensor = to_sensor(client);
1302 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1303 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1304 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1308 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1309 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1310 goto sensor_task_lock_err;
1315 atomic_add(1, &sensor->tasklock_cnt);
1317 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1318 atomic_sub(1, &sensor->tasklock_cnt);
1320 if (atomic_read(&sensor->tasklock_cnt) == 0)
1325 sensor_task_lock_err:
1333 /* sensor register write */
1334 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1338 struct i2c_msg msg[1];
1341 buf[1] = reg & 0xFF;
1344 msg->addr = client->addr;
1345 msg->flags = client->flags;
1347 msg->len = sizeof(buf);
1348 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1349 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1354 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1355 err = i2c_transfer(client->adapter, msg, 1);
1360 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1368 /* sensor register read */
1369 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1373 struct i2c_msg msg[2];
1376 buf[1] = reg & 0xFF;
1378 msg[0].addr = client->addr;
1379 msg[0].flags = client->flags;
1381 msg[0].len = sizeof(buf);
1382 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1383 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1385 msg[1].addr = client->addr;
1386 msg[1].flags = client->flags|I2C_M_RD;
1389 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1390 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1394 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1395 err = i2c_transfer(client->adapter, msg, 2);
1401 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1409 /* write a array of registers */
1410 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1414 #if CONFIG_SENSOR_I2C_RDWRCHK
1419 if (sensor_task_lock(client, 1) < 0)
1420 goto sensor_write_array_end;
1422 while (regarray[i].reg != 0)
1424 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1428 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1432 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1434 goto sensor_write_array_end;
1437 #if CONFIG_SENSOR_I2C_RDWRCHK
1438 sensor_read(client, regarray[i].reg, &valchk);
1439 if (valchk != regarray[i].val)
1440 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1446 sensor_write_array_end:
1447 sensor_task_lock(client,0);
1450 #if CONFIG_SENSOR_I2C_RDWRCHK
1451 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1459 while (regarray[i].reg != 0)
1461 sensor_read(client, regarray[i].reg, &valchk);
1462 if (valchk != regarray[i].val)
1463 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1470 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1472 struct soc_camera_link *icl = to_soc_camera_link(icd);
1475 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1478 case Sensor_PowerDown:
1480 if (icl->powerdown) {
1481 ret = icl->powerdown(icd->pdev, on);
1482 if (ret == RK29_CAM_IO_SUCCESS) {
1486 icl->reset(icd->pdev);
1488 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1490 goto sensor_power_end;
1497 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1498 struct sensor *sensor = to_sensor(client);
1500 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1501 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1503 //flash off after 2 secs
1504 hrtimer_cancel(&(flash_off_timer.timer));
1505 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1512 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1520 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1521 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1522 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1523 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1528 static s32 sensor_init_width = 800;
1529 static s32 sensor_init_height = 600;
1530 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH| SOCAM_VSYNC_ACTIVE_LOW|SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
1531 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1532 static struct reginfo* sensor_init_data_p = sensor_init_data;
1533 static struct reginfo* sensor_init_winseq_p = sensor_svga;
1534 static struct reginfo* sensor_init_winseq_board = NULL;
1535 static struct reginfo* sensor_init_data_board = NULL;
1536 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1538 struct i2c_client *client = v4l2_get_subdevdata(sd);
1539 struct soc_camera_device *icd = client->dev.platform_data;
1540 struct sensor *sensor = to_sensor(client);
1541 const struct v4l2_queryctrl *qctrl;
1542 const struct sensor_datafmt *fmt;
1544 int ret,pid = 0,i = 0,j=0;
1545 //if val ==1,mean that sensor need to be reinit
1546 struct rk29camera_platform_data* tmp_plat_data =sensor->sensor_io_request;
1548 sensor_init_data_p = sensor_init_data;
1549 sensor_init_winseq_p = sensor_svga;
1550 sensor_init_width = 800;
1551 sensor_init_height = 600;
1553 if (tmp_plat_data != NULL) {
1554 for(i = 0;i < RK_CAM_NUM;i++){
1555 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1556 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0)) {
1562 if(tmp_plat_data &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1563 //user has defined the init data
1565 int tmp_init_data_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data_size;
1566 if(tmp_init_data_size > 2){//init data is valid
1567 if((sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1568 if(sensor_init_data_board) {
1569 vfree(sensor_init_data_board);
1570 sensor_init_data_board = NULL;
1572 sensor_init_data_board = (struct reginfo*)vmalloc(tmp_init_data_size);
1573 if(!sensor_init_data_board)
1574 SENSOR_TR("%s :vmalloc init data erro !",__FUNCTION__);
1575 for(j = 0;j< tmp_init_data_size;j++) {
1576 sensor_init_data_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1577 sensor_init_data_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1579 sensor_init_data_p = sensor_init_data_board;
1581 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1585 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1586 if(tmp_winseq_size > 2){
1587 if(sizeof(struct reginfo) != sizeof(struct reginfo_t)){
1588 if(sensor_init_winseq_board) {
1589 vfree(sensor_init_winseq_board);
1590 sensor_init_winseq_board = NULL;
1592 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1593 if(!sensor_init_winseq_board)
1594 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1595 for(j = 0;j< tmp_winseq_size;j++){
1596 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1597 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1599 sensor_init_winseq_p = sensor_init_winseq_board;
1601 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1604 //init width,height,bus,pixelcode
1605 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1606 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1607 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1608 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1609 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1610 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1611 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1612 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1614 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1616 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1618 goto sensor_INIT_ERR;
1622 if (sensor_task_lock(client,1)<0)
1623 goto sensor_INIT_ERR;
1625 ret = sensor_write(client, 0x0103, 0x01);
1628 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1630 goto sensor_INIT_ERR;
1632 mdelay(5); //delay 5 microseconds
1634 /* check if it is an sensor sensor */
1635 ret = sensor_read(client, 0x300a, &value);
1637 SENSOR_TR("read chip id high byte failed\n");
1639 goto sensor_INIT_ERR;
1642 pid |= (value << 8);
1644 ret = sensor_read(client, 0x300b, &value);
1646 SENSOR_TR("read chip id low byte failed\n");
1648 goto sensor_INIT_ERR;
1651 pid |= (value & 0xff);
1652 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1653 if (pid == SENSOR_ID) {
1654 sensor->model = SENSOR_V4L2_IDENT;
1656 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1658 goto sensor_INIT_ERR;
1661 ret = sensor_write_array(client, sensor_init_data_p);
1664 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1665 goto sensor_INIT_ERR;
1667 sensor_task_lock(client,0);
1669 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1670 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1672 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1674 goto sensor_INIT_ERR;
1676 sensor->info_priv.fmt = *fmt;
1678 /* sensor sensor information for initialization */
1679 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1681 sensor->info_priv.whiteBalance = qctrl->default_value;
1682 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1684 sensor->info_priv.brightness = qctrl->default_value;
1685 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1687 sensor->info_priv.effect = qctrl->default_value;
1688 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1690 sensor->info_priv.exposure = qctrl->default_value;
1692 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1694 sensor->info_priv.saturation = qctrl->default_value;
1695 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1697 sensor->info_priv.contrast = qctrl->default_value;
1698 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1700 sensor->info_priv.mirror = qctrl->default_value;
1701 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1703 sensor->info_priv.flip = qctrl->default_value;
1704 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1706 sensor->info_priv.scene = qctrl->default_value;
1707 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1709 sensor->info_priv.digitalzoom = qctrl->default_value;
1711 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1712 #if CONFIG_SENSOR_Focus
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1716 sensor->info_priv.focus = qctrl->default_value;
1719 #if CONFIG_SENSOR_Flash
1720 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1722 sensor->info_priv.flash = qctrl->default_value;
1723 flash_off_timer.icd = icd;
1724 flash_off_timer.timer.function = flash_off_func;
1727 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);
1728 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1731 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1732 sensor_task_lock(client,0);
1733 sensor_deactivate(client);
1737 static int sensor_deactivate(struct i2c_client *client)
1739 struct soc_camera_device *icd = client->dev.platform_data;
1741 struct sensor *sensor = to_sensor(client);
1742 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1744 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1745 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1746 sensor_task_lock(client, 1);
1747 sensor_read(client,0x3000,®_val);
1748 sensor_write(client, 0x3000, reg_val&0xfc);
1749 sensor_write(client, 0x3001, 0x00);
1750 sensor_read(client,0x3002,®_val);
1751 sensor_write(client, 0x3002, reg_val&0x1f);
1752 sensor_task_lock(client, 0);
1754 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1756 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1757 icd->user_width = SENSOR_INIT_WIDTH;
1758 icd->user_height = SENSOR_INIT_HEIGHT;
1759 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1764 static struct reginfo sensor_power_down_sequence[]=
1768 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1771 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1773 if (pm_msg.event == PM_EVENT_SUSPEND) {
1774 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1775 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1777 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1780 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1782 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1787 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1793 static int sensor_resume(struct soc_camera_device *icd)
1797 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1799 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1803 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1809 static int sensor_set_bus_param(struct soc_camera_device *icd,
1810 unsigned long flags)
1816 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1818 struct soc_camera_link *icl = to_soc_camera_link(icd);
1819 unsigned long flags = SENSOR_BUS_PARAM;
1821 return soc_camera_apply_sensor_flags(icl, flags);
1824 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1826 struct i2c_client *client = v4l2_get_subdevdata(sd);
1827 struct soc_camera_device *icd = client->dev.platform_data;
1828 struct sensor *sensor = to_sensor(client);
1830 mf->width = icd->user_width;
1831 mf->height = icd->user_height;
1832 mf->code = sensor->info_priv.fmt.code;
1833 mf->colorspace = sensor->info_priv.fmt.colorspace;
1834 mf->field = V4L2_FIELD_NONE;
1838 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1842 if ((mf->width == 1024) && (mf->height == 768)) {
1844 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1846 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1848 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1850 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1855 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1859 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1863 if ((mf->width == 1280) && (mf->height == 720)) {
1865 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1870 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1873 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1875 struct i2c_client *client = v4l2_get_subdevdata(sd);
1876 const struct sensor_datafmt *fmt;
1877 struct sensor *sensor = to_sensor(client);
1878 const struct v4l2_queryctrl *qctrl;
1879 struct soc_camera_device *icd = client->dev.platform_data;
1880 struct reginfo *winseqe_set_addr=NULL;
1881 int ret=0, set_w,set_h;
1883 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1884 ARRAY_SIZE(sensor_colour_fmts));
1887 goto sensor_s_fmt_end;
1890 if (sensor->info_priv.fmt.code != mf->code) {
1893 case V4L2_MBUS_FMT_YUYV8_2X8:
1895 winseqe_set_addr = sensor_ClrFmt_YUYV;
1898 case V4L2_MBUS_FMT_UYVY8_2X8:
1900 winseqe_set_addr = sensor_ClrFmt_UYVY;
1906 if (winseqe_set_addr != NULL) {
1907 sensor_write_array(client, winseqe_set_addr);
1908 sensor->info_priv.fmt.code = mf->code;
1909 sensor->info_priv.fmt.colorspace= mf->colorspace;
1910 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1912 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1919 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1921 winseqe_set_addr = sensor_qcif;
1925 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1927 winseqe_set_addr = sensor_qvga;
1931 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1933 winseqe_set_addr = sensor_cif;
1937 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1939 winseqe_set_addr = sensor_vga;
1943 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1945 winseqe_set_addr = sensor_svga;
1949 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
1951 winseqe_set_addr = sensor_720p;
1955 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1957 winseqe_set_addr = sensor_xga;
1961 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1963 winseqe_set_addr = sensor_sxga;
1967 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1969 winseqe_set_addr = sensor_uxga;
1975 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1976 set_w = SENSOR_INIT_WIDTH;
1977 set_h = SENSOR_INIT_HEIGHT;
1978 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1981 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1982 #if CONFIG_SENSOR_Flash
1983 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1984 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1985 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1986 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1988 } else { /* ddl@rock-chips.com : Video */
1989 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1990 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1991 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1995 ret |= sensor_write_array(client, winseqe_set_addr);
1997 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1998 #if CONFIG_SENSOR_Flash
1999 if (sensor_fmt_capturechk(sd,mf) == true) {
2000 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2001 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2002 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2006 goto sensor_s_fmt_end;
2009 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
2011 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
2012 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2013 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2014 if (sensor->info_priv.whiteBalance != 0) {
2015 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2016 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2019 sensor->info_priv.snap2preview = true;
2020 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
2021 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2022 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2023 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2024 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2025 sensor->info_priv.video2preview = true;
2026 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2027 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2028 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2029 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2030 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2032 sensor->info_priv.video2preview = false;
2033 sensor->info_priv.snap2preview = false;
2036 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2040 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2050 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2052 struct i2c_client *client = v4l2_get_subdevdata(sd);
2053 struct sensor *sensor = to_sensor(client);
2054 const struct sensor_datafmt *fmt;
2055 int ret = 0,set_w,set_h;
2057 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2058 ARRAY_SIZE(sensor_colour_fmts));
2060 fmt = &sensor->info_priv.fmt;
2061 mf->code = fmt->code;
2064 if (mf->height > SENSOR_MAX_HEIGHT)
2065 mf->height = SENSOR_MAX_HEIGHT;
2066 else if (mf->height < SENSOR_MIN_HEIGHT)
2067 mf->height = SENSOR_MIN_HEIGHT;
2069 if (mf->width > SENSOR_MAX_WIDTH)
2070 mf->width = SENSOR_MAX_WIDTH;
2071 else if (mf->width < SENSOR_MIN_WIDTH)
2072 mf->width = SENSOR_MIN_WIDTH;
2077 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2082 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2087 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2092 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2097 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2102 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
2107 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
2112 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2117 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2123 { /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
2124 set_w = SENSOR_INIT_WIDTH;
2125 set_h = SENSOR_INIT_HEIGHT;
2130 mf->colorspace = fmt->colorspace;
2135 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2137 struct i2c_client *client = v4l2_get_subdevdata(sd);
2139 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2142 if (id->match.addr != client->addr)
2145 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2150 #if CONFIG_SENSOR_Brightness
2151 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2153 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2155 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2157 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2159 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2161 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2164 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2168 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2172 #if CONFIG_SENSOR_Effect
2173 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2175 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2177 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2179 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2181 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2183 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2186 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2190 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2194 #if CONFIG_SENSOR_Exposure
2195 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2197 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2199 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2201 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2203 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2205 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2208 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2212 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2216 #if CONFIG_SENSOR_Saturation
2217 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2219 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2221 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2223 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2225 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2227 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2230 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2234 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2238 #if CONFIG_SENSOR_Contrast
2239 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2241 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2243 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2245 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2247 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2249 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2252 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2256 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2260 #if CONFIG_SENSOR_Mirror
2261 static int sensor_mirror(struct i2c_client *client, int on)
2267 err = sensor_read(client, 0x3821, &val);
2270 err = sensor_write(client, 0x3821, val);
2273 err = sensor_read(client, 0x3821, &val);
2276 err = sensor_write(client, 0x3821, val);
2282 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2284 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2286 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2288 if (sensor_mirror(client,value) != 0)
2289 SENSOR_TR("%s(%d): sensor_mirror failed, value:0x%x",__FUNCTION__, __LINE__,value);
2291 SENSOR_DG("%s(%d): sensor_mirror success, value:0x%x",__FUNCTION__, __LINE__,value);
2294 SENSOR_TR("\n %s..%s value = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2298 #if CONFIG_SENSOR_Flip
2299 static int sensor_flip(struct i2c_client *client, int on)
2305 err = sensor_read(client, 0x3820, &val);
2308 err = sensor_write(client, 0x3820, val);
2311 err = sensor_read(client, 0x3820, &val);
2314 err = sensor_write(client, 0x3820, val);
2320 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2322 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2324 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2326 if (sensor_flip(client,value) != 0)
2327 SENSOR_TR("%s(%d): sensor_flip failed, value:0x%x",__FUNCTION__, __LINE__,value);
2329 SENSOR_DG("%s(%d): sensor_flip success, value:0x%x",__FUNCTION__, __LINE__,value);
2332 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2336 #if CONFIG_SENSOR_Scene
2337 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2339 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2341 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2343 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2345 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2347 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2350 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2354 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2358 #if CONFIG_SENSOR_WhiteBalance
2359 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2361 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2363 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2365 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2367 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2369 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2372 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2376 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2380 #if CONFIG_SENSOR_DigitalZoom
2381 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2383 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2384 struct sensor *sensor = to_sensor(client);
2385 const struct v4l2_queryctrl *qctrl_info;
2386 int digitalzoom_cur, digitalzoom_total;
2388 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2392 digitalzoom_cur = sensor->info_priv.digitalzoom;
2393 digitalzoom_total = qctrl_info->maximum;
2395 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2397 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2401 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2403 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2407 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2409 value = digitalzoom_total - digitalzoom_cur;
2412 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2414 value = 0 - digitalzoom_cur;
2417 digitalzoom_cur += value;
2419 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2421 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2423 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2426 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2433 #if CONFIG_SENSOR_Flash
2434 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2436 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2437 if (value == 3) { /* ddl@rock-chips.com: torch */
2438 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2440 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2442 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2446 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2451 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2453 struct i2c_client *client = v4l2_get_subdevdata(sd);
2454 struct sensor *sensor = to_sensor(client);
2455 const struct v4l2_queryctrl *qctrl;
2457 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2461 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2467 case V4L2_CID_BRIGHTNESS:
2469 ctrl->value = sensor->info_priv.brightness;
2472 case V4L2_CID_SATURATION:
2474 ctrl->value = sensor->info_priv.saturation;
2477 case V4L2_CID_CONTRAST:
2479 ctrl->value = sensor->info_priv.contrast;
2482 case V4L2_CID_DO_WHITE_BALANCE:
2484 ctrl->value = sensor->info_priv.whiteBalance;
2487 case V4L2_CID_EXPOSURE:
2489 ctrl->value = sensor->info_priv.exposure;
2492 case V4L2_CID_HFLIP:
2494 ctrl->value = sensor->info_priv.mirror;
2497 case V4L2_CID_VFLIP:
2499 ctrl->value = sensor->info_priv.flip;
2510 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2512 struct i2c_client *client = v4l2_get_subdevdata(sd);
2513 struct sensor *sensor = to_sensor(client);
2514 struct soc_camera_device *icd = client->dev.platform_data;
2515 const struct v4l2_queryctrl *qctrl;
2518 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2522 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2528 #if CONFIG_SENSOR_Brightness
2529 case V4L2_CID_BRIGHTNESS:
2531 if (ctrl->value != sensor->info_priv.brightness)
2533 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2537 sensor->info_priv.brightness = ctrl->value;
2542 #if CONFIG_SENSOR_Exposure
2543 case V4L2_CID_EXPOSURE:
2545 if (ctrl->value != sensor->info_priv.exposure)
2547 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2551 sensor->info_priv.exposure = ctrl->value;
2556 #if CONFIG_SENSOR_Saturation
2557 case V4L2_CID_SATURATION:
2559 if (ctrl->value != sensor->info_priv.saturation)
2561 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2565 sensor->info_priv.saturation = ctrl->value;
2570 #if CONFIG_SENSOR_Contrast
2571 case V4L2_CID_CONTRAST:
2573 if (ctrl->value != sensor->info_priv.contrast)
2575 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2579 sensor->info_priv.contrast = ctrl->value;
2584 #if CONFIG_SENSOR_WhiteBalance
2585 case V4L2_CID_DO_WHITE_BALANCE:
2587 if (ctrl->value != sensor->info_priv.whiteBalance)
2589 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2593 sensor->info_priv.whiteBalance = ctrl->value;
2598 #if CONFIG_SENSOR_Mirror
2599 case V4L2_CID_HFLIP:
2601 if (ctrl->value != sensor->info_priv.mirror)
2603 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2605 sensor->info_priv.mirror = ctrl->value;
2610 #if CONFIG_SENSOR_Flip
2611 case V4L2_CID_VFLIP:
2613 if (ctrl->value != sensor->info_priv.flip)
2615 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2617 sensor->info_priv.flip = ctrl->value;
2628 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2630 const struct v4l2_queryctrl *qctrl;
2631 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2632 struct sensor *sensor = to_sensor(client);
2634 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2638 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2642 switch (ext_ctrl->id)
2644 case V4L2_CID_SCENE:
2646 ext_ctrl->value = sensor->info_priv.scene;
2649 case V4L2_CID_EFFECT:
2651 ext_ctrl->value = sensor->info_priv.effect;
2654 case V4L2_CID_ZOOM_ABSOLUTE:
2656 ext_ctrl->value = sensor->info_priv.digitalzoom;
2659 case V4L2_CID_ZOOM_RELATIVE:
2663 case V4L2_CID_FOCUS_ABSOLUTE:
2665 ext_ctrl->value = sensor->info_priv.focus;
2668 case V4L2_CID_FOCUS_RELATIVE:
2672 case V4L2_CID_FLASH:
2674 ext_ctrl->value = sensor->info_priv.flash;
2682 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2684 const struct v4l2_queryctrl *qctrl;
2685 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2686 struct sensor *sensor = to_sensor(client);
2689 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2693 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2698 switch (ext_ctrl->id)
2700 #if CONFIG_SENSOR_Scene
2701 case V4L2_CID_SCENE:
2703 if (ext_ctrl->value != sensor->info_priv.scene)
2705 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2707 sensor->info_priv.scene = ext_ctrl->value;
2712 #if CONFIG_SENSOR_Effect
2713 case V4L2_CID_EFFECT:
2715 if (ext_ctrl->value != sensor->info_priv.effect)
2717 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2719 sensor->info_priv.effect= ext_ctrl->value;
2724 #if CONFIG_SENSOR_DigitalZoom
2725 case V4L2_CID_ZOOM_ABSOLUTE:
2727 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2730 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2732 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2734 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2736 sensor->info_priv.digitalzoom += val_offset;
2738 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2743 case V4L2_CID_ZOOM_RELATIVE:
2745 if (ext_ctrl->value)
2747 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2749 sensor->info_priv.digitalzoom += ext_ctrl->value;
2751 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2756 #if CONFIG_SENSOR_Focus
2757 case V4L2_CID_FOCUS_ABSOLUTE:
2759 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2762 if (ext_ctrl->value != sensor->info_priv.focus)
2764 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2766 sensor->info_priv.focus += val_offset;
2771 case V4L2_CID_FOCUS_RELATIVE:
2773 if (ext_ctrl->value)
2775 sensor->info_priv.focus += ext_ctrl->value;
2777 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2782 #if CONFIG_SENSOR_Flash
2783 case V4L2_CID_FLASH:
2785 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2787 sensor->info_priv.flash = ext_ctrl->value;
2789 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2800 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2802 struct i2c_client *client = v4l2_get_subdevdata(sd);
2803 struct soc_camera_device *icd = client->dev.platform_data;
2804 int i, error_cnt=0, error_idx=-1;
2807 for (i=0; i<ext_ctrl->count; i++) {
2808 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2815 error_idx = ext_ctrl->count;
2817 if (error_idx != -1) {
2818 ext_ctrl->error_idx = error_idx;
2825 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2827 struct i2c_client *client = v4l2_get_subdevdata(sd);
2828 struct soc_camera_device *icd = client->dev.platform_data;
2829 int i, error_cnt=0, error_idx=-1;
2832 for (i=0; i<ext_ctrl->count; i++) {
2833 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2840 error_idx = ext_ctrl->count;
2842 if (error_idx != -1) {
2843 ext_ctrl->error_idx = error_idx;
2850 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2851 * this wasn't our capture interface, so, we wait for the right one */
2852 static int sensor_video_probe(struct soc_camera_device *icd,
2853 struct i2c_client *client)
2857 struct sensor *sensor = to_sensor(client);
2859 /* We must have a parent by now. And it cannot be a wrong one.
2860 * So this entire test is completely redundant. */
2861 if (!icd->dev.parent ||
2862 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2865 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2866 SENSOR_TR("power down %s failed\n",SENSOR_NAME_STRING());
2868 goto sensor_video_probe_err;
2872 ret = sensor_write(client, 0x0103, 0x01);
2874 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2876 goto sensor_video_probe_err;
2878 mdelay(5); //delay 5 microseconds
2880 /* check if it is an sensor sensor */
2881 ret = sensor_read(client, 0x300a, &value);
2883 SENSOR_TR("read chip id high byte failed\n");
2885 goto sensor_video_probe_err;
2888 pid |= (value << 8);
2890 ret = sensor_read(client, 0x300b, &value);
2892 SENSOR_TR("read chip id low byte failed\n");
2894 goto sensor_video_probe_err;
2897 pid |= (value & 0xff);
2898 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2899 if (pid == SENSOR_ID) {
2900 sensor->model = SENSOR_V4L2_IDENT;
2902 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2904 goto sensor_video_probe_err;
2909 sensor_video_probe_err:
2914 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2916 struct i2c_client *client = v4l2_get_subdevdata(sd);
2917 struct soc_camera_device *icd = client->dev.platform_data;
2918 struct sensor *sensor = to_sensor(client);
2920 #if CONFIG_SENSOR_Flash
2924 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2927 case RK29_CAM_SUBDEV_DEACTIVATE:
2929 sensor_deactivate(client);
2933 case RK29_CAM_SUBDEV_IOREQUEST:
2935 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2936 if (sensor->sensor_io_request != NULL) {
2938 for(j = 0;j < RK_CAM_NUM;j++){
2939 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2940 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2941 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2945 if(j == RK_CAM_NUM){
2946 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2948 goto sensor_ioctl_end;
2952 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2954 #if CONFIG_SENSOR_Flash
2955 if (sensor->sensor_gpio_res) {
2956 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2957 for (i = 0; i < icd->ops->num_controls; i++) {
2958 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2959 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2960 sensor_controls[i].id=0xffff;
2963 sensor->info_priv.flash = 0xff;
2964 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2965 }else{ //two cameras are the same,need to deal diffrently ,zyc
2966 for (i = 0; i < icd->ops->num_controls; i++) {
2967 if(0xffff == icd->ops->controls[i].id){
2968 sensor_controls[i].id=V4L2_CID_FLASH;
2978 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2986 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2987 enum v4l2_mbus_pixelcode *code)
2989 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2992 *code = sensor_colour_fmts[index].code;
2995 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2996 .init = sensor_init,
2997 .g_ctrl = sensor_g_control,
2998 .s_ctrl = sensor_s_control,
2999 .g_ext_ctrls = sensor_g_ext_controls,
3000 .s_ext_ctrls = sensor_s_ext_controls,
3001 .g_chip_ident = sensor_g_chip_ident,
3002 .ioctl = sensor_ioctl,
3005 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3006 .s_mbus_fmt = sensor_s_fmt,
3007 .g_mbus_fmt = sensor_g_fmt,
3008 .try_mbus_fmt = sensor_try_fmt,
3009 .enum_mbus_fmt = sensor_enum_fmt,
3011 static struct v4l2_subdev_ops sensor_subdev_ops = {
3012 .core = &sensor_subdev_core_ops,
3013 .video = &sensor_subdev_video_ops,
3016 static int sensor_probe(struct i2c_client *client,
3017 const struct i2c_device_id *did)
3019 struct sensor *sensor;
3020 struct soc_camera_device *icd = client->dev.platform_data;
3021 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3022 struct soc_camera_link *icl;
3025 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3027 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3031 icl = to_soc_camera_link(icd);
3033 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3037 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3038 dev_warn(&adapter->dev,
3039 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3043 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3047 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3049 /* Second stage probe - when a capture adapter is there */
3050 icd->ops = &sensor_ops;
3052 sensor->info_priv.fmt = sensor_colour_fmts[0];
3054 #if CONFIG_SENSOR_I2C_NOSCHED
3055 atomic_set(&sensor->tasklock_cnt,0);
3058 ret = sensor_video_probe(icd, client);
3061 i2c_set_clientdata(client, NULL);
3065 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3066 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3070 static int sensor_remove(struct i2c_client *client)
3072 struct sensor *sensor = to_sensor(client);
3073 struct soc_camera_device *icd = client->dev.platform_data;
3076 i2c_set_clientdata(client, NULL);
3077 client->driver = NULL;
3083 static const struct i2c_device_id sensor_id[] = {
3084 {SENSOR_NAME_STRING(), 0 },
3087 MODULE_DEVICE_TABLE(i2c, sensor_id);
3089 static struct i2c_driver sensor_i2c_driver = {
3091 .name = SENSOR_NAME_STRING(),
3093 .probe = sensor_probe,
3094 .remove = sensor_remove,
3095 .id_table = sensor_id,
3098 static int __init sensor_mod_init(void)
3100 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3101 return i2c_add_driver(&sensor_i2c_driver);
3104 static void __exit sensor_mod_exit(void)
3106 i2c_del_driver(&sensor_i2c_driver);
3109 device_initcall_sync(sensor_mod_init);
3110 module_exit(sensor_mod_exit);
3112 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3113 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3114 MODULE_LICENSE("GPL");