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/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 RK_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 100000 /* 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 static s32 sensor_init_width = 0;
100 static s32 sensor_init_height = 0;
101 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);
102 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
103 static struct reginfo* sensor_init_data_p = NULL;
104 static struct reginfo* sensor_init_winseq_p = NULL;
105 static struct reginfo* sensor_init_winseq_board = NULL;
106 /* init 800*600 SVGA */
107 static struct reginfo sensor_init_data[] =
112 //{0x0100, 0x01}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
278 static struct reginfo sensor_720p[]=
284 //{0x0100, 0x01 }, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
447 static struct reginfo sensor_uxga[] =
498 static struct reginfo sensor_sxga[] =
503 static struct reginfo sensor_xga[] =
508 static struct reginfo sensor_svga[] =
510 {0x0100, 0x00}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
556 {0x0100, 0x01}, //software wake
561 static struct reginfo sensor_vga[] =
567 static struct reginfo sensor_cif[] =
573 static struct reginfo sensor_qvga[] =
579 static struct reginfo sensor_qcif[] =
585 static struct reginfo ov2655_qqvga[] =
629 static struct reginfo ov2655_Sharpness_auto[] =
634 static struct reginfo ov2655_Sharpness1[] =
640 static struct reginfo ov2655_Sharpness2[][3] =
647 static struct reginfo ov2655_Sharpness3[] =
653 static struct reginfo ov2655_Sharpness4[]=
660 static struct reginfo ov2655_Sharpness5[] =
668 static struct reginfo sensor_ClrFmt_YUYV[]=
674 static struct reginfo sensor_ClrFmt_UYVY[]=
680 #if CONFIG_SENSOR_WhiteBalance
681 static struct reginfo sensor_WhiteB_Auto[]=
683 {0x3406, 0x00}, //AWB auto, bit[1]:0,auto
686 /* Cloudy Colour Temperature : 6500K - 8000K */
687 static struct reginfo sensor_WhiteB_Cloudy[]=
698 /* ClearDay Colour Temperature : 5000K - 6500K */
699 static struct reginfo sensor_WhiteB_ClearDay[]=
711 /* Office Colour Temperature : 3500K - 5000K */
712 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
725 /* Home Colour Temperature : 2500K - 3500K */
726 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
738 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
739 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
743 #if CONFIG_SENSOR_Brightness
744 static struct reginfo sensor_Brightness0[]=
750 static struct reginfo sensor_Brightness1[]=
757 static struct reginfo sensor_Brightness2[]=
764 static struct reginfo sensor_Brightness3[]=
771 static struct reginfo sensor_Brightness4[]=
778 static struct reginfo sensor_Brightness5[]=
784 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
785 sensor_Brightness4, sensor_Brightness5,NULL,
790 #if CONFIG_SENSOR_Effect
791 static struct reginfo sensor_Effect_Normal[] =
797 static struct reginfo sensor_Effect_WandB[] =
803 static struct reginfo sensor_Effect_Sepia[] =
811 static struct reginfo sensor_Effect_Negative[] =
814 {0x507b, 0x40}, //bit[6] negative
817 static struct reginfo sensor_Effect_Bluish[] =
826 static struct reginfo sensor_Effect_Green[] =
834 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
835 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
838 #if CONFIG_SENSOR_Exposure
839 static struct reginfo sensor_Exposure0[]=
844 static struct reginfo sensor_Exposure1[]=
849 static struct reginfo sensor_Exposure2[]=
854 static struct reginfo sensor_Exposure3[]=
859 static struct reginfo sensor_Exposure4[]=
864 static struct reginfo sensor_Exposure5[]=
869 static struct reginfo sensor_Exposure6[]=
874 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
875 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
878 #if CONFIG_SENSOR_Saturation
879 static struct reginfo sensor_Saturation0[]=
884 static struct reginfo sensor_Saturation1[]=
889 static struct reginfo sensor_Saturation2[]=
893 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
896 #if CONFIG_SENSOR_Contrast
897 static struct reginfo sensor_Contrast0[]=
902 static struct reginfo sensor_Contrast1[]=
907 static struct reginfo sensor_Contrast2[]=
912 static struct reginfo sensor_Contrast3[]=
917 static struct reginfo sensor_Contrast4[]=
923 static struct reginfo sensor_Contrast5[]=
928 static struct reginfo sensor_Contrast6[]=
932 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
933 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
937 #if CONFIG_SENSOR_Mirror
938 static struct reginfo sensor_MirrorOn[]=
943 static struct reginfo sensor_MirrorOff[]=
947 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
949 #if CONFIG_SENSOR_Flip
950 static struct reginfo sensor_FlipOn[]=
955 static struct reginfo sensor_FlipOff[]=
959 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
962 #if CONFIG_SENSOR_Scene
963 static struct reginfo sensor_SceneAuto[] =
969 static struct reginfo sensor_SceneNight[] =
982 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
985 #if CONFIG_SENSOR_DigitalZoom
986 static struct reginfo sensor_Zoom0[] =
991 static struct reginfo sensor_Zoom1[] =
996 static struct reginfo sensor_Zoom2[] =
1002 static struct reginfo sensor_Zoom3[] =
1006 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1008 static const struct v4l2_querymenu sensor_menus[] =
1010 #if CONFIG_SENSOR_WhiteBalance
1011 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1012 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1013 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1016 #if CONFIG_SENSOR_Effect
1017 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1018 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1019 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
1022 #if CONFIG_SENSOR_Scene
1023 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1026 #if CONFIG_SENSOR_Flash
1027 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1028 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1032 static const struct v4l2_queryctrl sensor_controls[] =
1034 #if CONFIG_SENSOR_WhiteBalance
1036 .id = V4L2_CID_DO_WHITE_BALANCE,
1037 .type = V4L2_CTRL_TYPE_MENU,
1038 .name = "White Balance Control",
1046 #if CONFIG_SENSOR_Brightness
1048 .id = V4L2_CID_BRIGHTNESS,
1049 .type = V4L2_CTRL_TYPE_INTEGER,
1050 .name = "Brightness Control",
1058 #if CONFIG_SENSOR_Effect
1060 .id = V4L2_CID_EFFECT,
1061 .type = V4L2_CTRL_TYPE_MENU,
1062 .name = "Effect Control",
1070 #if CONFIG_SENSOR_Exposure
1072 .id = V4L2_CID_EXPOSURE,
1073 .type = V4L2_CTRL_TYPE_INTEGER,
1074 .name = "Exposure Control",
1082 #if CONFIG_SENSOR_Saturation
1084 .id = V4L2_CID_SATURATION,
1085 .type = V4L2_CTRL_TYPE_INTEGER,
1086 .name = "Saturation Control",
1094 #if CONFIG_SENSOR_Contrast
1096 .id = V4L2_CID_CONTRAST,
1097 .type = V4L2_CTRL_TYPE_INTEGER,
1098 .name = "Contrast Control",
1106 #if CONFIG_SENSOR_Mirror
1108 .id = V4L2_CID_HFLIP,
1109 .type = V4L2_CTRL_TYPE_BOOLEAN,
1110 .name = "Mirror Control",
1118 #if CONFIG_SENSOR_Flip
1120 .id = V4L2_CID_VFLIP,
1121 .type = V4L2_CTRL_TYPE_BOOLEAN,
1122 .name = "Flip Control",
1130 #if CONFIG_SENSOR_Scene
1132 .id = V4L2_CID_SCENE,
1133 .type = V4L2_CTRL_TYPE_MENU,
1134 .name = "Scene Control",
1142 #if CONFIG_SENSOR_DigitalZoom
1144 .id = V4L2_CID_ZOOM_RELATIVE,
1145 .type = V4L2_CTRL_TYPE_INTEGER,
1146 .name = "DigitalZoom Control",
1152 .id = V4L2_CID_ZOOM_ABSOLUTE,
1153 .type = V4L2_CTRL_TYPE_INTEGER,
1154 .name = "DigitalZoom Control",
1162 #if CONFIG_SENSOR_Focus
1164 .id = V4L2_CID_FOCUS_RELATIVE,
1165 .type = V4L2_CTRL_TYPE_INTEGER,
1166 .name = "Focus Control",
1172 .id = V4L2_CID_FOCUS_ABSOLUTE,
1173 .type = V4L2_CTRL_TYPE_INTEGER,
1174 .name = "Focus Control",
1178 .default_value = 125,
1182 #if CONFIG_SENSOR_Flash
1184 .id = V4L2_CID_FLASH,
1185 .type = V4L2_CTRL_TYPE_MENU,
1186 .name = "Flash Control",
1195 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1196 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1197 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1198 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1199 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1200 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1201 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1202 static int sensor_resume(struct soc_camera_device *icd);
1203 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1204 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1205 #if CONFIG_SENSOR_Effect
1206 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1208 #if CONFIG_SENSOR_WhiteBalance
1209 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1211 static int sensor_deactivate(struct i2c_client *client);
1213 static struct soc_camera_ops sensor_ops =
1215 .suspend = sensor_suspend,
1216 .resume = sensor_resume,
1217 .set_bus_param = sensor_set_bus_param,
1218 .query_bus_param = sensor_query_bus_param,
1219 .controls = sensor_controls,
1220 .menus = sensor_menus,
1221 .num_controls = ARRAY_SIZE(sensor_controls),
1222 .num_menus = ARRAY_SIZE(sensor_menus),
1225 /* only one fixed colorspace per pixelcode */
1226 struct sensor_datafmt {
1227 enum v4l2_mbus_pixelcode code;
1228 enum v4l2_colorspace colorspace;
1231 /* Find a data format by a pixel code in an array */
1232 static const struct sensor_datafmt *sensor_find_datafmt(
1233 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1237 for (i = 0; i < n; i++)
1238 if (fmt[i].code == code)
1244 static const struct sensor_datafmt sensor_colour_fmts[] = {
1245 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1246 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1249 typedef struct sensor_info_priv_s
1263 unsigned char mirror; /* HFLIP */
1264 unsigned char flip; /* VFLIP */
1265 unsigned int winseqe_cur_addr;
1266 struct sensor_datafmt fmt;
1267 unsigned int funmodule_state;
1268 } sensor_info_priv_t;
1272 struct v4l2_subdev subdev;
1273 struct i2c_client *client;
1274 sensor_info_priv_t info_priv;
1275 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1276 #if CONFIG_SENSOR_I2C_NOSCHED
1277 atomic_t tasklock_cnt;
1279 struct rkcamera_platform_data *sensor_io_request;
1280 struct rkcamera_gpio_res *sensor_gpio_res;
1284 static struct sensor* to_sensor(const struct i2c_client *client)
1286 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1289 static int sensor_task_lock(struct i2c_client *client, int lock)
1291 #if CONFIG_SENSOR_I2C_NOSCHED
1293 struct sensor *sensor = to_sensor(client);
1296 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1297 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1298 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1302 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1303 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1304 goto sensor_task_lock_err;
1309 atomic_add(1, &sensor->tasklock_cnt);
1311 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1312 atomic_sub(1, &sensor->tasklock_cnt);
1314 if (atomic_read(&sensor->tasklock_cnt) == 0)
1319 sensor_task_lock_err:
1327 /* sensor register write */
1328 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1332 struct i2c_msg msg[1];
1335 buf[1] = reg & 0xFF;
1338 msg->addr = client->addr;
1339 msg->flags = client->flags;
1341 msg->len = sizeof(buf);
1342 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1343 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1348 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1349 err = i2c_transfer(client->adapter, msg, 1);
1354 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1362 /* sensor register read */
1363 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1367 struct i2c_msg msg[2];
1370 buf[1] = reg & 0xFF;
1372 msg[0].addr = client->addr;
1373 msg[0].flags = client->flags;
1375 msg[0].len = sizeof(buf);
1376 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1377 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1379 msg[1].addr = client->addr;
1380 msg[1].flags = client->flags|I2C_M_RD;
1383 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1384 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1388 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1389 err = i2c_transfer(client->adapter, msg, 2);
1395 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1403 /* write a array of registers */
1404 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1408 #if CONFIG_SENSOR_I2C_RDWRCHK
1413 if (sensor_task_lock(client, 1) < 0)
1414 goto sensor_write_array_end;
1416 while (regarray[i].reg != 0)
1418 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1422 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1426 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1428 goto sensor_write_array_end;
1431 #if CONFIG_SENSOR_I2C_RDWRCHK
1432 sensor_read(client, regarray[i].reg, &valchk);
1433 if (valchk != regarray[i].val)
1434 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1440 sensor_write_array_end:
1441 sensor_task_lock(client,0);
1444 #if CONFIG_SENSOR_I2C_RDWRCHK
1445 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1453 while (regarray[i].reg != 0)
1455 sensor_read(client, regarray[i].reg, &valchk);
1456 if (valchk != regarray[i].val)
1457 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1464 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1466 struct soc_camera_link *icl = to_soc_camera_link(icd);
1469 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1472 case Sensor_PowerDown:
1474 if (icl->powerdown) {
1475 ret = icl->powerdown(icd->pdev, on);
1476 if (ret == RK_CAM_IO_SUCCESS) {
1480 icl->reset(icd->pdev);
1482 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1484 goto sensor_power_end;
1491 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1492 struct sensor *sensor = to_sensor(client);
1494 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1495 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1501 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1508 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1510 struct i2c_client *client = v4l2_get_subdevdata(sd);
1511 struct soc_camera_device *icd = client->dev.platform_data;
1512 struct sensor *sensor = to_sensor(client);
1513 const struct v4l2_queryctrl *qctrl;
1514 const struct sensor_datafmt *fmt;
1516 int ret,pid = 0,i = 0,j=0;
1517 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1518 sensor_init_data_p = sensor_init_data;
1519 sensor_init_winseq_p = sensor_svga;
1520 sensor_init_width = 800;
1521 sensor_init_height = 600;
1522 if (tmp_plat_data != NULL) {
1523 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1524 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1525 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1529 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1530 //user has defined the init data
1532 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1533 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1534 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1535 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1537 sensor_init_data_p = sensor_init_data;
1539 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1540 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1543 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1544 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1545 if(sensor_init_winseq_board)
1547 vfree(sensor_init_winseq_board);
1548 sensor_init_winseq_board = NULL;
1550 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1551 if(!sensor_init_winseq_board)
1552 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1553 for(j = 0;j< tmp_winseq_size;j++){
1554 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1555 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1557 sensor_init_winseq_p = sensor_init_winseq_board;
1559 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1560 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1562 //init width,height,bus,pixelcode
1563 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1564 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1565 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1566 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1567 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1568 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1569 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1570 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1572 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1574 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1576 goto sensor_INIT_ERR;
1580 if (sensor_task_lock(client,1)<0)
1581 goto sensor_INIT_ERR;
1583 ret = sensor_write(client, 0x0103, 0x01);
1586 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1588 goto sensor_INIT_ERR;
1590 mdelay(5); //delay 5 microseconds
1592 /* check if it is an sensor sensor */
1593 ret = sensor_read(client, 0x300a, &value);
1595 SENSOR_TR("read chip id high byte failed\n");
1597 goto sensor_INIT_ERR;
1600 pid |= (value << 8);
1602 ret = sensor_read(client, 0x300b, &value);
1604 SENSOR_TR("read chip id low byte failed\n");
1606 goto sensor_INIT_ERR;
1609 pid |= (value & 0xff);
1610 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1611 if (pid == SENSOR_ID) {
1612 sensor->model = SENSOR_V4L2_IDENT;
1614 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1616 goto sensor_INIT_ERR;
1619 ret = sensor_write_array(client, sensor_init_data_p);
1622 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1623 goto sensor_INIT_ERR;
1625 sensor_task_lock(client,0);
1627 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1628 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1630 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1632 goto sensor_INIT_ERR;
1634 sensor->info_priv.fmt = *fmt;
1636 /* sensor sensor information for initialization */
1637 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1639 sensor->info_priv.whiteBalance = qctrl->default_value;
1640 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1642 sensor->info_priv.brightness = qctrl->default_value;
1643 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1645 sensor->info_priv.effect = qctrl->default_value;
1646 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1648 sensor->info_priv.exposure = qctrl->default_value;
1650 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1652 sensor->info_priv.saturation = qctrl->default_value;
1653 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1655 sensor->info_priv.contrast = qctrl->default_value;
1656 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1658 sensor->info_priv.mirror = qctrl->default_value;
1659 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1661 sensor->info_priv.flip = qctrl->default_value;
1662 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1664 sensor->info_priv.scene = qctrl->default_value;
1665 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1667 sensor->info_priv.digitalzoom = qctrl->default_value;
1669 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1670 #if CONFIG_SENSOR_Focus
1672 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1674 sensor->info_priv.focus = qctrl->default_value;
1677 #if CONFIG_SENSOR_Flash
1678 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1680 sensor->info_priv.flash = qctrl->default_value;
1683 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);
1684 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1687 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1688 sensor_task_lock(client,0);
1689 sensor_deactivate(client);
1693 static int sensor_deactivate(struct i2c_client *client)
1695 struct soc_camera_device *icd = client->dev.platform_data;
1697 struct sensor *sensor = to_sensor(client);
1698 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1700 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1701 if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
1702 sensor_task_lock(client, 1);
1703 sensor_read(client,0x3000,®_val);
1704 sensor_write(client, 0x3000, reg_val&0xfc);
1705 sensor_write(client, 0x3001, 0x00);
1706 sensor_read(client,0x3002,®_val);
1707 sensor_write(client, 0x3002, reg_val&0x1f);
1708 sensor_task_lock(client, 0);
1710 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1713 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1714 icd->user_width = SENSOR_INIT_WIDTH;
1715 icd->user_height = SENSOR_INIT_HEIGHT;
1716 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1721 static struct reginfo sensor_power_down_sequence[]=
1725 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1728 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1730 if (pm_msg.event == PM_EVENT_SUSPEND) {
1731 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1732 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1734 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1737 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1739 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1744 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1750 static int sensor_resume(struct soc_camera_device *icd)
1754 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1756 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1760 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1766 static int sensor_set_bus_param(struct soc_camera_device *icd,
1767 unsigned long flags)
1773 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1775 struct soc_camera_link *icl = to_soc_camera_link(icd);
1776 unsigned long flags = SENSOR_BUS_PARAM;
1778 return soc_camera_apply_sensor_flags(icl, flags);
1781 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1783 struct i2c_client *client = v4l2_get_subdevdata(sd);
1784 struct soc_camera_device *icd = client->dev.platform_data;
1785 struct sensor *sensor = to_sensor(client);
1787 mf->width = icd->user_width;
1788 mf->height = icd->user_height;
1789 mf->code = sensor->info_priv.fmt.code;
1790 mf->colorspace = sensor->info_priv.fmt.colorspace;
1791 mf->field = V4L2_FIELD_NONE;
1795 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1799 if ((mf->width == 1024) && (mf->height == 768)) {
1801 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1803 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1805 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1807 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1812 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1816 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1820 if ((mf->width == 1280) && (mf->height == 720)) {
1822 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1827 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1830 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1832 struct i2c_client *client = v4l2_get_subdevdata(sd);
1833 const struct sensor_datafmt *fmt;
1834 struct sensor *sensor = to_sensor(client);
1835 const struct v4l2_queryctrl *qctrl;
1836 struct soc_camera_device *icd = client->dev.platform_data;
1837 struct reginfo *winseqe_set_addr=NULL;
1838 int ret=0, set_w,set_h;
1840 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1841 ARRAY_SIZE(sensor_colour_fmts));
1844 goto sensor_s_fmt_end;
1847 if (sensor->info_priv.fmt.code != mf->code) {
1850 case V4L2_MBUS_FMT_YUYV8_2X8:
1852 winseqe_set_addr = sensor_ClrFmt_YUYV;
1855 case V4L2_MBUS_FMT_UYVY8_2X8:
1857 winseqe_set_addr = sensor_ClrFmt_UYVY;
1863 if (winseqe_set_addr != NULL) {
1864 sensor_write_array(client, winseqe_set_addr);
1865 sensor->info_priv.fmt.code = mf->code;
1866 sensor->info_priv.fmt.colorspace= mf->colorspace;
1867 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1869 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1876 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1878 winseqe_set_addr = sensor_qcif;
1882 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1884 winseqe_set_addr = sensor_qvga;
1888 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1890 winseqe_set_addr = sensor_cif;
1894 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1896 winseqe_set_addr = sensor_vga;
1900 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1902 winseqe_set_addr = sensor_svga;
1906 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
1908 winseqe_set_addr = sensor_720p;
1912 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1914 winseqe_set_addr = sensor_xga;
1918 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1920 winseqe_set_addr = sensor_sxga;
1924 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1926 winseqe_set_addr = sensor_uxga;
1932 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1933 set_w = SENSOR_INIT_WIDTH;
1934 set_h = SENSOR_INIT_HEIGHT;
1935 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1938 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1939 #if CONFIG_SENSOR_Flash
1940 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1941 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1942 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1943 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1945 } else { /* ddl@rock-chips.com : Video */
1946 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1947 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1948 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1952 ret |= sensor_write_array(client, winseqe_set_addr);
1954 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1955 #if CONFIG_SENSOR_Flash
1956 if (sensor_fmt_capturechk(sd,mf) == true) {
1957 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1958 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1959 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1963 goto sensor_s_fmt_end;
1966 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1968 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1969 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1970 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1971 if (sensor->info_priv.whiteBalance != 0) {
1972 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1973 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1975 sensor->info_priv.snap2preview = true;
1976 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1977 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1978 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1979 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1980 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1981 sensor->info_priv.video2preview = true;
1982 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1983 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1984 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1985 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1986 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1988 sensor->info_priv.video2preview = false;
1989 sensor->info_priv.snap2preview = false;
1992 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1996 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2006 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2008 struct i2c_client *client = v4l2_get_subdevdata(sd);
2009 struct sensor *sensor = to_sensor(client);
2010 const struct sensor_datafmt *fmt;
2013 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2014 ARRAY_SIZE(sensor_colour_fmts));
2016 fmt = &sensor->info_priv.fmt;
2017 mf->code = fmt->code;
2020 if (mf->height > SENSOR_MAX_HEIGHT)
2021 mf->height = SENSOR_MAX_HEIGHT;
2022 else if (mf->height < SENSOR_MIN_HEIGHT)
2023 mf->height = SENSOR_MIN_HEIGHT;
2025 if (mf->width > SENSOR_MAX_WIDTH)
2026 mf->width = SENSOR_MAX_WIDTH;
2027 else if (mf->width < SENSOR_MIN_WIDTH)
2028 mf->width = SENSOR_MIN_WIDTH;
2030 mf->colorspace = fmt->colorspace;
2035 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2037 struct i2c_client *client = v4l2_get_subdevdata(sd);
2039 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2042 if (id->match.addr != client->addr)
2045 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2050 #if CONFIG_SENSOR_Brightness
2051 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2053 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2055 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2057 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2059 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2061 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2064 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2068 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2072 #if CONFIG_SENSOR_Effect
2073 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2075 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2077 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2079 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2081 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2083 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2086 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2090 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2094 #if CONFIG_SENSOR_Exposure
2095 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2097 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2099 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2101 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2103 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2105 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2108 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2112 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2116 #if CONFIG_SENSOR_Saturation
2117 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2119 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2121 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2123 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2125 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2127 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2130 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2134 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2138 #if CONFIG_SENSOR_Contrast
2139 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2141 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2143 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2145 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2147 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2149 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2152 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2156 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2160 #if CONFIG_SENSOR_Mirror
2161 static int sensor_mirror(struct i2c_client *client, int on)
2167 err = sensor_read(client, 0x3821, &val);
2170 err = sensor_write(client, 0x3821, val);
2173 err = sensor_read(client, 0x3821, &val);
2176 err = sensor_write(client, 0x3821, val);
2182 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2184 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2186 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2188 if (sensor_mirror(client,value) != 0)
2189 SENSOR_TR("%s(%d): sensor_mirror failed, value:0x%x",__FUNCTION__, __LINE__,value);
2191 SENSOR_DG("%s(%d): sensor_mirror success, value:0x%x",__FUNCTION__, __LINE__,value);
2194 SENSOR_TR("\n %s..%s value = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2198 #if CONFIG_SENSOR_Flip
2199 static int sensor_flip(struct i2c_client *client, int on)
2205 err = sensor_read(client, 0x3820, &val);
2208 err = sensor_write(client, 0x3820, val);
2211 err = sensor_read(client, 0x3820, &val);
2214 err = sensor_write(client, 0x3820, val);
2220 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2222 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2224 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2226 if (sensor_flip(client,value) != 0)
2227 SENSOR_TR("%s(%d): sensor_flip failed, value:0x%x",__FUNCTION__, __LINE__,value);
2229 SENSOR_DG("%s(%d): sensor_flip success, value:0x%x",__FUNCTION__, __LINE__,value);
2232 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2236 #if CONFIG_SENSOR_Scene
2237 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2239 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2241 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2243 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2245 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2247 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2250 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2254 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2258 #if CONFIG_SENSOR_WhiteBalance
2259 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2261 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2263 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2265 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2267 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2269 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2272 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2276 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2280 #if CONFIG_SENSOR_DigitalZoom
2281 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2283 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2284 struct sensor *sensor = to_sensor(client);
2285 const struct v4l2_queryctrl *qctrl_info;
2286 int digitalzoom_cur, digitalzoom_total;
2288 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2292 digitalzoom_cur = sensor->info_priv.digitalzoom;
2293 digitalzoom_total = qctrl_info->maximum;
2295 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2297 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2301 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2303 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2307 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2309 value = digitalzoom_total - digitalzoom_cur;
2312 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2314 value = 0 - digitalzoom_cur;
2317 digitalzoom_cur += value;
2319 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2321 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2323 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2326 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2333 #if CONFIG_SENSOR_Flash
2334 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2336 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2337 if (value == 3) { /* ddl@rock-chips.com: torch */
2338 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2340 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2342 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2346 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2351 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2353 struct i2c_client *client = v4l2_get_subdevdata(sd);
2354 struct sensor *sensor = to_sensor(client);
2355 const struct v4l2_queryctrl *qctrl;
2357 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2361 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2367 case V4L2_CID_BRIGHTNESS:
2369 ctrl->value = sensor->info_priv.brightness;
2372 case V4L2_CID_SATURATION:
2374 ctrl->value = sensor->info_priv.saturation;
2377 case V4L2_CID_CONTRAST:
2379 ctrl->value = sensor->info_priv.contrast;
2382 case V4L2_CID_DO_WHITE_BALANCE:
2384 ctrl->value = sensor->info_priv.whiteBalance;
2387 case V4L2_CID_EXPOSURE:
2389 ctrl->value = sensor->info_priv.exposure;
2392 case V4L2_CID_HFLIP:
2394 ctrl->value = sensor->info_priv.mirror;
2397 case V4L2_CID_VFLIP:
2399 ctrl->value = sensor->info_priv.flip;
2410 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2412 struct i2c_client *client = v4l2_get_subdevdata(sd);
2413 struct sensor *sensor = to_sensor(client);
2414 struct soc_camera_device *icd = client->dev.platform_data;
2415 const struct v4l2_queryctrl *qctrl;
2418 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2422 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2428 #if CONFIG_SENSOR_Brightness
2429 case V4L2_CID_BRIGHTNESS:
2431 if (ctrl->value != sensor->info_priv.brightness)
2433 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2437 sensor->info_priv.brightness = ctrl->value;
2442 #if CONFIG_SENSOR_Exposure
2443 case V4L2_CID_EXPOSURE:
2445 if (ctrl->value != sensor->info_priv.exposure)
2447 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2451 sensor->info_priv.exposure = ctrl->value;
2456 #if CONFIG_SENSOR_Saturation
2457 case V4L2_CID_SATURATION:
2459 if (ctrl->value != sensor->info_priv.saturation)
2461 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2465 sensor->info_priv.saturation = ctrl->value;
2470 #if CONFIG_SENSOR_Contrast
2471 case V4L2_CID_CONTRAST:
2473 if (ctrl->value != sensor->info_priv.contrast)
2475 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2479 sensor->info_priv.contrast = ctrl->value;
2484 #if CONFIG_SENSOR_WhiteBalance
2485 case V4L2_CID_DO_WHITE_BALANCE:
2487 if (ctrl->value != sensor->info_priv.whiteBalance)
2489 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2493 sensor->info_priv.whiteBalance = ctrl->value;
2498 #if CONFIG_SENSOR_Mirror
2499 case V4L2_CID_HFLIP:
2501 if (ctrl->value != sensor->info_priv.mirror)
2503 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2505 sensor->info_priv.mirror = ctrl->value;
2510 #if CONFIG_SENSOR_Flip
2511 case V4L2_CID_VFLIP:
2513 if (ctrl->value != sensor->info_priv.flip)
2515 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2517 sensor->info_priv.flip = ctrl->value;
2528 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2530 const struct v4l2_queryctrl *qctrl;
2531 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2532 struct sensor *sensor = to_sensor(client);
2534 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2538 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2542 switch (ext_ctrl->id)
2544 case V4L2_CID_SCENE:
2546 ext_ctrl->value = sensor->info_priv.scene;
2549 case V4L2_CID_EFFECT:
2551 ext_ctrl->value = sensor->info_priv.effect;
2554 case V4L2_CID_ZOOM_ABSOLUTE:
2556 ext_ctrl->value = sensor->info_priv.digitalzoom;
2559 case V4L2_CID_ZOOM_RELATIVE:
2563 case V4L2_CID_FOCUS_ABSOLUTE:
2565 ext_ctrl->value = sensor->info_priv.focus;
2568 case V4L2_CID_FOCUS_RELATIVE:
2572 case V4L2_CID_FLASH:
2574 ext_ctrl->value = sensor->info_priv.flash;
2582 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2584 const struct v4l2_queryctrl *qctrl;
2585 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2586 struct sensor *sensor = to_sensor(client);
2589 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2593 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2598 switch (ext_ctrl->id)
2600 #if CONFIG_SENSOR_Scene
2601 case V4L2_CID_SCENE:
2603 if (ext_ctrl->value != sensor->info_priv.scene)
2605 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2607 sensor->info_priv.scene = ext_ctrl->value;
2612 #if CONFIG_SENSOR_Effect
2613 case V4L2_CID_EFFECT:
2615 if (ext_ctrl->value != sensor->info_priv.effect)
2617 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2619 sensor->info_priv.effect= ext_ctrl->value;
2624 #if CONFIG_SENSOR_DigitalZoom
2625 case V4L2_CID_ZOOM_ABSOLUTE:
2627 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2630 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2632 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2634 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2636 sensor->info_priv.digitalzoom += val_offset;
2638 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2643 case V4L2_CID_ZOOM_RELATIVE:
2645 if (ext_ctrl->value)
2647 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2649 sensor->info_priv.digitalzoom += ext_ctrl->value;
2651 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2656 #if CONFIG_SENSOR_Focus
2657 case V4L2_CID_FOCUS_ABSOLUTE:
2659 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2662 if (ext_ctrl->value != sensor->info_priv.focus)
2664 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2666 sensor->info_priv.focus += val_offset;
2671 case V4L2_CID_FOCUS_RELATIVE:
2673 if (ext_ctrl->value)
2675 sensor->info_priv.focus += ext_ctrl->value;
2677 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2682 #if CONFIG_SENSOR_Flash
2683 case V4L2_CID_FLASH:
2685 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2687 sensor->info_priv.flash = ext_ctrl->value;
2689 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2700 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2702 struct i2c_client *client = v4l2_get_subdevdata(sd);
2703 struct soc_camera_device *icd = client->dev.platform_data;
2704 int i, error_cnt=0, error_idx=-1;
2707 for (i=0; i<ext_ctrl->count; i++) {
2708 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2715 error_idx = ext_ctrl->count;
2717 if (error_idx != -1) {
2718 ext_ctrl->error_idx = error_idx;
2725 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2727 struct i2c_client *client = v4l2_get_subdevdata(sd);
2728 struct soc_camera_device *icd = client->dev.platform_data;
2729 int i, error_cnt=0, error_idx=-1;
2732 for (i=0; i<ext_ctrl->count; i++) {
2733 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2740 error_idx = ext_ctrl->count;
2742 if (error_idx != -1) {
2743 ext_ctrl->error_idx = error_idx;
2750 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2751 * this wasn't our capture interface, so, we wait for the right one */
2752 static int sensor_video_probe(struct soc_camera_device *icd,
2753 struct i2c_client *client)
2756 int ret,pid = 0,i=0;
2757 struct sensor *sensor = to_sensor(client);
2759 /* We must have a parent by now. And it cannot be a wrong one.
2760 * So this entire test is completely redundant. */
2761 if (!icd->dev.parent ||
2762 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2765 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2767 printk("sensor ioctrl powdown erro!!!");
2768 goto sensor_video_probe_err;
2771 ret = sensor_write(client, 0x0103, 0x01);
2773 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2775 goto sensor_video_probe_err;
2777 mdelay(5); //delay 5 microseconds
2779 /* check if it is an sensor sensor */
2780 ret = sensor_read(client, 0x300a, &value);
2782 SENSOR_TR("read chip id high byte failed\n");
2784 goto sensor_video_probe_err;
2787 pid |= (value << 8);
2789 ret = sensor_read(client, 0x300b, &value);
2791 SENSOR_TR("read chip id low byte failed\n");
2793 goto sensor_video_probe_err;
2795 pid |= (value & 0xff);
2796 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2797 if (pid == SENSOR_ID) {
2798 sensor->model = SENSOR_V4L2_IDENT;
2800 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2802 goto sensor_video_probe_err;
2807 sensor_video_probe_err:
2808 printk("the erro value = %d\n",i);
2813 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2815 struct i2c_client *client = v4l2_get_subdevdata(sd);
2816 struct soc_camera_device *icd = client->dev.platform_data;
2817 struct sensor *sensor = to_sensor(client);
2819 #if CONFIG_SENSOR_Flash
2823 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2826 case RK_CAM_SUBDEV_DEACTIVATE:
2828 sensor_deactivate(client);
2832 case RK_CAM_SUBDEV_IOREQUEST:
2834 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2835 if (sensor->sensor_io_request != NULL) {
2836 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2837 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2838 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2839 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2840 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2841 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2844 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2846 goto sensor_ioctl_end;
2848 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2850 #if CONFIG_SENSOR_Flash
2851 if (sensor->sensor_gpio_res) {
2852 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2853 for (i = 0; i < icd->ops->num_controls; i++) {
2854 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2855 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2858 sensor->info_priv.flash = 0xff;
2859 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2867 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2875 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2876 enum v4l2_mbus_pixelcode *code)
2878 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2881 *code = sensor_colour_fmts[index].code;
2884 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2885 .init = sensor_init,
2886 .g_ctrl = sensor_g_control,
2887 .s_ctrl = sensor_s_control,
2888 .g_ext_ctrls = sensor_g_ext_controls,
2889 .s_ext_ctrls = sensor_s_ext_controls,
2890 .g_chip_ident = sensor_g_chip_ident,
2891 .ioctl = sensor_ioctl,
2894 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2895 .s_mbus_fmt = sensor_s_fmt,
2896 .g_mbus_fmt = sensor_g_fmt,
2897 .try_mbus_fmt = sensor_try_fmt,
2898 .enum_mbus_fmt = sensor_enum_fmt,
2900 static struct v4l2_subdev_ops sensor_subdev_ops = {
2901 .core = &sensor_subdev_core_ops,
2902 .video = &sensor_subdev_video_ops,
2905 static int sensor_probe(struct i2c_client *client,
2906 const struct i2c_device_id *did)
2908 struct sensor *sensor;
2909 struct soc_camera_device *icd = client->dev.platform_data;
2910 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2911 struct soc_camera_link *icl;
2914 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2916 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2920 icl = to_soc_camera_link(icd);
2922 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2926 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2927 dev_warn(&adapter->dev,
2928 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2932 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2936 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2938 /* Second stage probe - when a capture adapter is there */
2939 icd->ops = &sensor_ops;
2941 sensor->info_priv.fmt = sensor_colour_fmts[0];
2943 #if CONFIG_SENSOR_I2C_NOSCHED
2944 atomic_set(&sensor->tasklock_cnt,0);
2947 ret = sensor_video_probe(icd, client);
2950 i2c_set_clientdata(client, NULL);
2954 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2958 static int sensor_remove(struct i2c_client *client)
2960 struct sensor *sensor = to_sensor(client);
2961 struct soc_camera_device *icd = client->dev.platform_data;
2964 i2c_set_clientdata(client, NULL);
2965 client->driver = NULL;
2968 if(sensor_init_winseq_board)
2970 vfree(sensor_init_winseq_board);
2971 sensor_init_winseq_board = NULL;
2976 static const struct i2c_device_id sensor_id[] = {
2977 {SENSOR_NAME_STRING(), 0 },
2980 MODULE_DEVICE_TABLE(i2c, sensor_id);
2982 static struct i2c_driver sensor_i2c_driver = {
2984 .name = SENSOR_NAME_STRING(),
2986 .probe = sensor_probe,
2987 .remove = sensor_remove,
2988 .id_table = sensor_id,
2991 static int __init sensor_mod_init(void)
2993 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2994 return i2c_add_driver(&sensor_i2c_driver);
2997 static void __exit sensor_mod_exit(void)
2999 i2c_del_driver(&sensor_i2c_driver);
3002 device_initcall_sync(sensor_mod_init);
3003 module_exit(sensor_mod_exit);
3005 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3006 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3007 MODULE_LICENSE("GPL");