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_NT99250
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_NT99250
48 #define SENSOR_ID 0x0105
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
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 0
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 0
64 #define CONFIG_SENSOR_Scene 0
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define 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)
100 /* init 800*600 SVGA */
101 static struct reginfo sensor_init_data[] =
103 {0x3024,0x02}, //TG //0x02
104 {0x32F0,0x00},//0:UYVY 2:VYUY 1:YUYV 3:YVYU
226 {0x32f6,0x0c},//effect function
227 {0x3069, 0x00}, //Pix //01 :for M1002 00 :for other
228 {0x306d, 0x01}, //pclk //00 :for M1002 01 :for other
230 //==============================
232 //==============================
284 {0x32c2,0x5c}, //7.14fps @ 48M
288 {0x3290,0x01}, //awb init ++++
298 {0x32a8,0xa0}, //awb init ----
299 {0x3012,0x02}, //AE init +++
302 {0x3201,0x7f}, //AE init ---
305 {0x0, 0x0}, //end flag
310 static struct reginfo sensor_uxga[] =
312 //Output format & size
316 {0x3332, 0x80}, //0x20
317 {0x3320, 0x20}, //0x28
368 static struct reginfo sensor_sxga[] =
416 static struct reginfo sensor_svga[] =
446 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
468 {0x32c2,0x5c}, //7.14fps @ 48M
470 //{0x32c2,0xd4}, //10fps @ 48M
474 //{0x3290,0x01}, //awb init ++++
484 {0x32a8,0xa0}, //awb init ----
485 //{0x3012,0x02}, //AE init +++
488 //{0x3201,0x7f}, //AE init ---
496 static struct reginfo sensor_vga[] =
527 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
549 //{0x32c2,0x5c}, //7.14fps @ 48M
551 {0x32c2,0xd4}, //10fps @ 48M
555 //{0x3290,0x01}, //awb init ++++
565 {0x32a8,0xa0}, //awb init ----
566 //{0x3012,0x02}, //AE init +++
569 //{0x3201,0x7f}, //AE init ---
576 static struct reginfo sensor_cif[] =
582 static struct reginfo sensor_qvga[] =
588 static struct reginfo sensor_qcif[] =
594 static struct reginfo sensor_ClrFmt_YUYV[]=
596 {0x32f0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
600 static struct reginfo sensor_ClrFmt_UYVY[]=
602 {0x32F0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
606 #if CONFIG_SENSOR_WhiteBalance
607 static struct reginfo sensor_WhiteB_Auto[]=
609 {0x3201, 0x3f}, //AWB auto, bit[1]:0,auto
612 /* Cloudy Colour Temperature : 6500K - 8000K */
613 static struct reginfo sensor_WhiteB_Cloudy[]=
622 /* ClearDay Colour Temperature : 5000K - 6500K */
623 static struct reginfo sensor_WhiteB_ClearDay[]=
634 /* Office Colour Temperature : 3500K - 5000K */
635 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
646 /* Home Colour Temperature : 2500K - 3500K */
647 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
657 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
658 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
662 #if CONFIG_SENSOR_Brightness
663 static struct reginfo sensor_Brightness0[]=
671 static struct reginfo sensor_Brightness1[]=
679 static struct reginfo sensor_Brightness2[]=
687 static struct reginfo sensor_Brightness3[]=
695 static struct reginfo sensor_Brightness4[]=
703 static struct reginfo sensor_Brightness5[]=
710 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
711 sensor_Brightness4, sensor_Brightness5,NULL,
716 #if CONFIG_SENSOR_Effect
717 static struct reginfo sensor_Effect_Normal[] =
723 static struct reginfo sensor_Effect_WandB[] =
729 static struct reginfo sensor_Effect_Sepia[] =
736 static struct reginfo sensor_Effect_Negative[] =
743 static struct reginfo sensor_Effect_Bluish[] =
753 static struct reginfo sensor_Effect_Green[] =
762 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
763 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
766 #if CONFIG_SENSOR_Exposure
767 static struct reginfo sensor_Exposure0[]=
773 static struct reginfo sensor_Exposure1[]=
779 static struct reginfo sensor_Exposure2[]=
785 static struct reginfo sensor_Exposure3[]=
791 static struct reginfo sensor_Exposure4[]=
797 static struct reginfo sensor_Exposure5[]=
803 static struct reginfo sensor_Exposure6[]=
809 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
810 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
813 #if CONFIG_SENSOR_Saturation
814 static struct reginfo sensor_Saturation0[]=
819 static struct reginfo sensor_Saturation1[]=
824 static struct reginfo sensor_Saturation2[]=
828 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
831 #if CONFIG_SENSOR_Contrast
832 static struct reginfo sensor_Contrast0[]=
838 static struct reginfo sensor_Contrast1[]=
844 static struct reginfo sensor_Contrast2[]=
850 static struct reginfo sensor_Contrast3[]=
856 static struct reginfo sensor_Contrast4[]=
863 static struct reginfo sensor_Contrast5[]=
869 static struct reginfo sensor_Contrast6[]=
874 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
875 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
879 #if CONFIG_SENSOR_Mirror
880 static struct reginfo sensor_MirrorOn[]=
885 static struct reginfo sensor_MirrorOff[]=
889 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
891 #if CONFIG_SENSOR_Flip
892 static struct reginfo sensor_FlipOn[]=
897 static struct reginfo sensor_FlipOff[]=
901 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
904 #if CONFIG_SENSOR_Scene
905 static struct reginfo sensor_SceneAuto[] =
911 static struct reginfo sensor_SceneNight[] =
913 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
917 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
920 #if CONFIG_SENSOR_DigitalZoom
921 static struct reginfo sensor_Zoom0[] =
926 static struct reginfo sensor_Zoom1[] =
931 static struct reginfo sensor_Zoom2[] =
937 static struct reginfo sensor_Zoom3[] =
941 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
943 static const struct v4l2_querymenu sensor_menus[] =
945 #if CONFIG_SENSOR_WhiteBalance
946 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
947 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
948 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
951 #if CONFIG_SENSOR_Effect
952 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
953 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
954 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
957 #if CONFIG_SENSOR_Scene
958 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
961 #if CONFIG_SENSOR_Flash
962 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
963 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
967 static const struct v4l2_queryctrl sensor_controls[] =
969 #if CONFIG_SENSOR_WhiteBalance
971 .id = V4L2_CID_DO_WHITE_BALANCE,
972 .type = V4L2_CTRL_TYPE_MENU,
973 .name = "White Balance Control",
981 #if CONFIG_SENSOR_Brightness
983 .id = V4L2_CID_BRIGHTNESS,
984 .type = V4L2_CTRL_TYPE_INTEGER,
985 .name = "Brightness Control",
993 #if CONFIG_SENSOR_Effect
995 .id = V4L2_CID_EFFECT,
996 .type = V4L2_CTRL_TYPE_MENU,
997 .name = "Effect Control",
1005 #if CONFIG_SENSOR_Exposure
1007 .id = V4L2_CID_EXPOSURE,
1008 .type = V4L2_CTRL_TYPE_INTEGER,
1009 .name = "Exposure Control",
1017 #if CONFIG_SENSOR_Saturation
1019 .id = V4L2_CID_SATURATION,
1020 .type = V4L2_CTRL_TYPE_INTEGER,
1021 .name = "Saturation Control",
1029 #if CONFIG_SENSOR_Contrast
1031 .id = V4L2_CID_CONTRAST,
1032 .type = V4L2_CTRL_TYPE_INTEGER,
1033 .name = "Contrast Control",
1041 #if CONFIG_SENSOR_Mirror
1043 .id = V4L2_CID_HFLIP,
1044 .type = V4L2_CTRL_TYPE_BOOLEAN,
1045 .name = "Mirror Control",
1053 #if CONFIG_SENSOR_Flip
1055 .id = V4L2_CID_VFLIP,
1056 .type = V4L2_CTRL_TYPE_BOOLEAN,
1057 .name = "Flip Control",
1065 #if CONFIG_SENSOR_Scene
1067 .id = V4L2_CID_SCENE,
1068 .type = V4L2_CTRL_TYPE_MENU,
1069 .name = "Scene Control",
1077 #if CONFIG_SENSOR_DigitalZoom
1079 .id = V4L2_CID_ZOOM_RELATIVE,
1080 .type = V4L2_CTRL_TYPE_INTEGER,
1081 .name = "DigitalZoom Control",
1087 .id = V4L2_CID_ZOOM_ABSOLUTE,
1088 .type = V4L2_CTRL_TYPE_INTEGER,
1089 .name = "DigitalZoom Control",
1097 #if CONFIG_SENSOR_Focus
1099 .id = V4L2_CID_FOCUS_RELATIVE,
1100 .type = V4L2_CTRL_TYPE_INTEGER,
1101 .name = "Focus Control",
1107 .id = V4L2_CID_FOCUS_ABSOLUTE,
1108 .type = V4L2_CTRL_TYPE_INTEGER,
1109 .name = "Focus Control",
1113 .default_value = 125,
1117 #if CONFIG_SENSOR_Flash
1119 .id = V4L2_CID_FLASH,
1120 .type = V4L2_CTRL_TYPE_MENU,
1121 .name = "Flash Control",
1130 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1131 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1132 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1133 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1134 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1135 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1136 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1137 static int sensor_resume(struct soc_camera_device *icd);
1138 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1139 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1140 #if CONFIG_SENSOR_Effect
1141 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1143 #if CONFIG_SENSOR_WhiteBalance
1144 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1146 static int sensor_deactivate(struct i2c_client *client);
1148 static struct soc_camera_ops sensor_ops =
1150 .suspend = sensor_suspend,
1151 .resume = sensor_resume,
1152 .set_bus_param = sensor_set_bus_param,
1153 .query_bus_param = sensor_query_bus_param,
1154 .controls = sensor_controls,
1155 .menus = sensor_menus,
1156 .num_controls = ARRAY_SIZE(sensor_controls),
1157 .num_menus = ARRAY_SIZE(sensor_menus),
1160 /* only one fixed colorspace per pixelcode */
1161 struct sensor_datafmt {
1162 enum v4l2_mbus_pixelcode code;
1163 enum v4l2_colorspace colorspace;
1166 /* Find a data format by a pixel code in an array */
1167 static const struct sensor_datafmt *sensor_find_datafmt(
1168 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1172 for (i = 0; i < n; i++)
1173 if (fmt[i].code == code)
1179 static const struct sensor_datafmt sensor_colour_fmts[] = {
1180 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1181 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1184 typedef struct sensor_info_priv_s
1198 unsigned char mirror; /* HFLIP */
1199 unsigned char flip; /* VFLIP */
1200 unsigned int winseqe_cur_addr;
1201 struct sensor_datafmt fmt;
1202 unsigned int funmodule_state;
1204 } sensor_info_priv_t;
1208 struct v4l2_subdev subdev;
1209 struct i2c_client *client;
1210 sensor_info_priv_t info_priv;
1211 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1212 #if CONFIG_SENSOR_I2C_NOSCHED
1213 atomic_t tasklock_cnt;
1215 struct rk29camera_platform_data *sensor_io_request;
1216 struct rk29camera_gpio_res *sensor_gpio_res;
1220 static struct sensor* to_sensor(const struct i2c_client *client)
1222 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1225 static int sensor_task_lock(struct i2c_client *client, int lock)
1227 #if CONFIG_SENSOR_I2C_NOSCHED
1229 struct sensor *sensor = to_sensor(client);
1232 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1233 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1234 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1238 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1239 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1240 goto sensor_task_lock_err;
1245 atomic_add(1, &sensor->tasklock_cnt);
1247 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1248 atomic_sub(1, &sensor->tasklock_cnt);
1250 if (atomic_read(&sensor->tasklock_cnt) == 0)
1255 sensor_task_lock_err:
1263 /* sensor register write */
1264 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1268 struct i2c_msg msg[1];
1271 buf[1] = reg & 0xFF;
1274 msg->addr = client->addr;
1275 msg->flags = client->flags;
1277 msg->len = sizeof(buf);
1278 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1279 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1284 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1285 err = i2c_transfer(client->adapter, msg, 1);
1290 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1298 /* sensor register read */
1299 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1303 struct i2c_msg msg[2];
1306 buf[1] = reg & 0xFF;
1308 msg[0].addr = client->addr;
1309 msg[0].flags = client->flags;
1311 msg[0].len = sizeof(buf);
1312 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1313 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1315 msg[1].addr = client->addr;
1316 msg[1].flags = client->flags|I2C_M_RD;
1319 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1320 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1324 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1325 err = i2c_transfer(client->adapter, msg, 2);
1331 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1339 /* write a array of registers */
1340 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1344 #if CONFIG_SENSOR_I2C_RDWRCHK
1349 if (sensor_task_lock(client, 1) < 0)
1350 goto sensor_write_array_end;
1352 while (regarray[i].reg != 0)
1354 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1358 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1362 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1364 goto sensor_write_array_end;
1367 #if CONFIG_SENSOR_I2C_RDWRCHK
1368 sensor_read(client, regarray[i].reg, &valchk);
1369 if (valchk != regarray[i].val)
1370 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1376 sensor_write_array_end:
1377 sensor_task_lock(client,0);
1380 #if CONFIG_SENSOR_I2C_RDWRCHK
1381 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1389 while (regarray[i].reg != 0)
1391 sensor_read(client, regarray[i].reg, &valchk);
1392 if (valchk != regarray[i].val)
1393 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1400 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1402 struct soc_camera_link *icl = to_soc_camera_link(icd);
1405 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1408 case Sensor_PowerDown:
1410 if (icl->powerdown) {
1411 ret = icl->powerdown(icd->pdev, on);
1412 if (ret == RK29_CAM_IO_SUCCESS) {
1416 icl->reset(icd->pdev);
1418 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1420 goto sensor_power_end;
1427 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1428 struct sensor *sensor = to_sensor(client);
1430 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1431 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1437 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1444 static s32 sensor_init_width = 800;
1445 static s32 sensor_init_height = 600;
1446 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);
1447 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1448 static struct reginfo* sensor_init_data_p = NULL;
1449 static struct reginfo* sensor_init_winseq_p = NULL;
1450 static struct reginfo* sensor_init_winseq_board = NULL;
1452 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1454 struct i2c_client *client = v4l2_get_subdevdata(sd);
1455 struct soc_camera_device *icd = client->dev.platform_data;
1456 struct sensor *sensor = to_sensor(client);
1457 const struct v4l2_queryctrl *qctrl;
1458 const struct sensor_datafmt *fmt;
1460 int ret,pid = 0,i = 0,j=0;
1461 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1462 sensor_init_data_p = sensor_init_data;
1463 sensor_init_winseq_p = sensor_svga;
1464 sensor_init_width = 800;
1465 sensor_init_height = 600;
1466 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1467 for(i = 0;i < RK_CAM_NUM;i++){
1468 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1469 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1473 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1474 //user has defined the init data
1476 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1477 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1478 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1479 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1481 sensor_init_data_p = sensor_init_data;
1483 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1484 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1487 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1488 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1489 if(sensor_init_winseq_board)
1491 vfree(sensor_init_winseq_board);
1492 sensor_init_winseq_board = NULL;
1494 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1495 if(!sensor_init_winseq_board)
1496 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1497 for(j = 0;j< tmp_winseq_size;j++){
1498 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1499 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1501 sensor_init_winseq_p = sensor_init_winseq_board;
1503 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1504 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1506 //init width,height,bus,pixelcode
1507 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1508 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1509 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1510 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1511 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1512 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1513 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1514 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1516 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1518 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1520 goto sensor_INIT_ERR;
1524 if (sensor_task_lock(client,1)<0)
1525 goto sensor_INIT_ERR;
1527 ret = sensor_write(client, 0x3021, 0x61);
1530 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1532 goto sensor_INIT_ERR;
1535 mdelay(5); //delay 5 microseconds
1536 /* check if it is an sensor sensor */
1537 ret = sensor_read(client, 0x307e, &value);
1539 SENSOR_TR("read chip id high byte failed\n");
1541 goto sensor_INIT_ERR;
1544 pid |= (value << 8);
1546 ret = sensor_read(client, 0x307f, &value);
1548 SENSOR_TR("read chip id low byte failed\n");
1550 goto sensor_INIT_ERR;
1553 pid |= (value & 0xff);
1554 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1556 if (pid == SENSOR_ID) {
1557 sensor->model = SENSOR_V4L2_IDENT;
1559 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1561 goto sensor_INIT_ERR;
1565 ret = sensor_write_array(client, sensor_init_data_p);
1568 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1569 goto sensor_INIT_ERR;
1571 sensor_task_lock(client,0);
1573 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1574 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1576 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1578 goto sensor_INIT_ERR;
1580 sensor->info_priv.fmt = *fmt;
1582 /* sensor sensor information for initialization */
1583 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1585 sensor->info_priv.whiteBalance = qctrl->default_value;
1586 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1588 sensor->info_priv.brightness = qctrl->default_value;
1589 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1591 sensor->info_priv.effect = qctrl->default_value;
1592 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1594 sensor->info_priv.exposure = qctrl->default_value;
1596 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1598 sensor->info_priv.saturation = qctrl->default_value;
1599 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1601 sensor->info_priv.contrast = qctrl->default_value;
1602 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1604 sensor->info_priv.mirror = qctrl->default_value;
1605 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1607 sensor->info_priv.flip = qctrl->default_value;
1608 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1610 sensor->info_priv.scene = qctrl->default_value;
1611 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1613 sensor->info_priv.digitalzoom = qctrl->default_value;
1615 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1616 #if CONFIG_SENSOR_Focus
1618 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1620 sensor->info_priv.focus = qctrl->default_value;
1623 #if CONFIG_SENSOR_Flash
1624 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1626 sensor->info_priv.flash = qctrl->default_value;
1629 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);
1630 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1633 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1634 sensor_task_lock(client,0);
1635 sensor_deactivate(client);
1639 static int sensor_deactivate(struct i2c_client *client)
1641 struct soc_camera_device *icd = client->dev.platform_data;
1642 struct sensor *sensor = to_sensor(client);
1643 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1645 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1646 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1649 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1650 icd->user_width = SENSOR_INIT_WIDTH;
1651 icd->user_height = SENSOR_INIT_HEIGHT;
1652 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1657 static struct reginfo sensor_power_down_sequence[]=
1665 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1668 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1670 if (pm_msg.event == PM_EVENT_SUSPEND) {
1671 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1672 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1674 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1677 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1679 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1684 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1690 static int sensor_resume(struct soc_camera_device *icd)
1694 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1696 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1700 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1706 static int sensor_set_bus_param(struct soc_camera_device *icd,
1707 unsigned long flags)
1713 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1715 struct soc_camera_link *icl = to_soc_camera_link(icd);
1716 unsigned long flags = SENSOR_BUS_PARAM;
1718 return soc_camera_apply_sensor_flags(icl, flags);
1721 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1723 struct i2c_client *client = v4l2_get_subdevdata(sd);
1724 struct soc_camera_device *icd = client->dev.platform_data;
1725 struct sensor *sensor = to_sensor(client);
1727 mf->width = icd->user_width;
1728 mf->height = icd->user_height;
1729 mf->code = sensor->info_priv.fmt.code;
1730 mf->colorspace = sensor->info_priv.fmt.colorspace;
1731 mf->field = V4L2_FIELD_NONE;
1735 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1739 if ((mf->width == 1024) && (mf->height == 768)) {
1741 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1743 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1745 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1747 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1752 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1756 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1760 if ((mf->width == 1280) && (mf->height == 720)) {
1762 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1767 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1770 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1772 struct i2c_client *client = v4l2_get_subdevdata(sd);
1773 const struct sensor_datafmt *fmt;
1774 struct sensor *sensor = to_sensor(client);
1775 struct reginfo *winseqe_set_addr=NULL;
1776 int ret=0, set_w,set_h;
1780 //turn on scaler for preivew
1781 sensor_read(client ,0x3201, ®_1);
1782 sensor_write(client, 0x3201, (reg_1|0x40) );
1784 sensor_read(client ,0x32f1, ®);
1785 sensor_write(client, 0x32f1, (reg|0x10) );
1787 #if 0 //preview_fastmode
1788 u16 AE_reg, AGC_reg;
1789 u8 temp_reg12,temp_reg13
1790 // turn off AE for preview
1791 sensor_read(client ,0x3201, &AE_reg);
1792 sensor_write(client, 0x3201, (AE_reg|0x20) );
1793 // turn off AGC for preview
1794 sensor_read(client ,0x32bb, &AGC_reg);
1795 sensor_write(client, 0x32bb, (AGC_reg|0x01) );
1797 sensor_read(client, 0x3012, &temp_reg12);
1798 sensor_read(client, 0x3013, &temp_reg13);
1799 shutter = (temp_reg13 & 0x00FF) | (temp_reg12 << 8);
1801 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1802 ARRAY_SIZE(sensor_colour_fmts));
1805 goto sensor_s_fmt_end;
1808 if (sensor->info_priv.fmt.code != mf->code) {
1811 case V4L2_MBUS_FMT_YUYV8_2X8:
1813 winseqe_set_addr = sensor_ClrFmt_YUYV;
1816 case V4L2_MBUS_FMT_UYVY8_2X8:
1818 winseqe_set_addr = sensor_ClrFmt_UYVY;
1824 if (winseqe_set_addr != NULL) {
1825 sensor_write_array(client, winseqe_set_addr);
1826 sensor->info_priv.fmt.code = mf->code;
1827 sensor->info_priv.fmt.colorspace= mf->colorspace;
1828 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1830 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1837 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1839 winseqe_set_addr = sensor_qcif;
1843 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1845 winseqe_set_addr = sensor_qvga;
1849 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1851 winseqe_set_addr = sensor_cif;
1855 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1857 winseqe_set_addr = sensor_vga;
1861 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1863 winseqe_set_addr = sensor_svga;
1867 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1869 winseqe_set_addr = sensor_sxga;
1873 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1875 winseqe_set_addr = sensor_uxga;
1881 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1882 set_w = SENSOR_INIT_WIDTH;
1883 set_h = SENSOR_INIT_HEIGHT;
1884 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1887 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1888 #if CONFIG_SENSOR_Flash
1889 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1890 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1891 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1892 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1894 } else { /* ddl@rock-chips.com : Video */
1895 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1896 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1897 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1901 ret |= sensor_write_array(client, winseqe_set_addr);
1903 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1904 #if CONFIG_SENSOR_Flash
1905 if (sensor_fmt_capturechk(sd,mf) == true) {
1906 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1907 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1908 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1912 goto sensor_s_fmt_end;
1915 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1917 if ((set_w <= 640) && (set_h <= 480))
1924 sensor_read(client ,0x32f1, ®);
1925 sensor_write(client, 0x32f1, (reg&(~0x10)) );
1926 if ((set_w <= 1600) && (set_h <= 1200))
1928 //turn off scaler for UXGA capture
1929 sensor_read(client ,0x3201, ®_1);
1930 sensor_write(client, 0x3201, (reg_1&(~0x40)) );
1932 #if 0 //preview_fastmode
1934 sensor_read(client ,0x3201, &AE_reg);
1935 sensor_write(client, 0x3201, (AE_reg&(~0x20)) );
1937 sensor_read(client ,0x32bb, &AGC_reg);
1938 sensor_write(client, 0x32bb, (AGC_reg&(~0x01)) );
1939 if ((set_w <= 800) && (set_h <= 600))
1941 shutter = shutter*1984/2434;
1943 else if ((set_w <= 2434) && (set_h <= 1024))
1945 shutter = shutter*1984/2434;
1947 else if ((set_w <= 1600) && (set_h <= 1200))
1949 shutter = shutter*1984/2434;
1955 sensor_write(client, 0x3012, sizeof((shutter >> 8) & 0xff) );
1956 sensor_write(client, 0x3013, sizeof(shutter & 0xFF) );
1961 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1965 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1975 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1977 struct i2c_client *client = v4l2_get_subdevdata(sd);
1978 struct sensor *sensor = to_sensor(client);
1979 const struct sensor_datafmt *fmt;
1982 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1983 ARRAY_SIZE(sensor_colour_fmts));
1985 fmt = &sensor->info_priv.fmt;
1986 mf->code = fmt->code;
1989 if (mf->height > SENSOR_MAX_HEIGHT)
1990 mf->height = SENSOR_MAX_HEIGHT;
1991 else if (mf->height < SENSOR_MIN_HEIGHT)
1992 mf->height = SENSOR_MIN_HEIGHT;
1994 if (mf->width > SENSOR_MAX_WIDTH)
1995 mf->width = SENSOR_MAX_WIDTH;
1996 else if (mf->width < SENSOR_MIN_WIDTH)
1997 mf->width = SENSOR_MIN_WIDTH;
1999 mf->colorspace = fmt->colorspace;
2000 /*not support 720p video*/
2001 if(mf->height == 720 && mf->width == 1280){
2008 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2010 struct i2c_client *client = v4l2_get_subdevdata(sd);
2012 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2015 if (id->match.addr != client->addr)
2018 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2023 #if CONFIG_SENSOR_Brightness
2024 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2026 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2028 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2030 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2032 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2034 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2037 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2041 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2045 #if CONFIG_SENSOR_Effect
2046 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2048 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2050 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2052 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2054 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2056 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2059 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2063 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2067 #if CONFIG_SENSOR_Exposure
2068 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2070 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2072 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2074 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2076 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2078 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2081 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2085 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2089 #if CONFIG_SENSOR_Saturation
2090 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2092 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2094 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2096 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2098 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2100 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2103 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2107 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2111 #if CONFIG_SENSOR_Contrast
2112 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2114 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2116 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2118 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2120 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2122 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2125 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2129 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2133 #if CONFIG_SENSOR_Mirror
2134 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2136 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2138 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2140 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2142 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2144 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2147 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2151 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2155 #if CONFIG_SENSOR_Flip
2156 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2158 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2160 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2162 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2164 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2166 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2169 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2173 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2177 #if CONFIG_SENSOR_Scene
2178 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2180 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2182 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2184 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2186 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2188 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2191 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2195 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2199 #if CONFIG_SENSOR_WhiteBalance
2200 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2202 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2204 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2206 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2208 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2210 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2213 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2217 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2221 #if CONFIG_SENSOR_DigitalZoom
2222 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2224 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2225 struct sensor *sensor = to_sensor(client);
2226 const struct v4l2_queryctrl *qctrl_info;
2227 int digitalzoom_cur, digitalzoom_total;
2229 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2233 digitalzoom_cur = sensor->info_priv.digitalzoom;
2234 digitalzoom_total = qctrl_info->maximum;
2236 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2238 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2242 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2244 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2248 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2250 value = digitalzoom_total - digitalzoom_cur;
2253 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2255 value = 0 - digitalzoom_cur;
2258 digitalzoom_cur += value;
2260 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2262 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2264 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2267 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2274 #if CONFIG_SENSOR_Flash
2275 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2277 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2278 if (value == 3) { /* ddl@rock-chips.com: torch */
2279 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2281 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2283 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2287 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2292 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2294 struct i2c_client *client = v4l2_get_subdevdata(sd);
2295 struct sensor *sensor = to_sensor(client);
2296 const struct v4l2_queryctrl *qctrl;
2298 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2302 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2308 case V4L2_CID_BRIGHTNESS:
2310 ctrl->value = sensor->info_priv.brightness;
2313 case V4L2_CID_SATURATION:
2315 ctrl->value = sensor->info_priv.saturation;
2318 case V4L2_CID_CONTRAST:
2320 ctrl->value = sensor->info_priv.contrast;
2323 case V4L2_CID_DO_WHITE_BALANCE:
2325 ctrl->value = sensor->info_priv.whiteBalance;
2328 case V4L2_CID_EXPOSURE:
2330 ctrl->value = sensor->info_priv.exposure;
2333 case V4L2_CID_HFLIP:
2335 ctrl->value = sensor->info_priv.mirror;
2338 case V4L2_CID_VFLIP:
2340 ctrl->value = sensor->info_priv.flip;
2351 static int sensor_s_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 struct soc_camera_device *icd = client->dev.platform_data;
2356 const struct v4l2_queryctrl *qctrl;
2359 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2363 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2369 #if CONFIG_SENSOR_Brightness
2370 case V4L2_CID_BRIGHTNESS:
2372 if (ctrl->value != sensor->info_priv.brightness)
2374 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2378 sensor->info_priv.brightness = ctrl->value;
2383 #if CONFIG_SENSOR_Exposure
2384 case V4L2_CID_EXPOSURE:
2386 if (ctrl->value != sensor->info_priv.exposure)
2388 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2392 sensor->info_priv.exposure = ctrl->value;
2397 #if CONFIG_SENSOR_Saturation
2398 case V4L2_CID_SATURATION:
2400 if (ctrl->value != sensor->info_priv.saturation)
2402 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2406 sensor->info_priv.saturation = ctrl->value;
2411 #if CONFIG_SENSOR_Contrast
2412 case V4L2_CID_CONTRAST:
2414 if (ctrl->value != sensor->info_priv.contrast)
2416 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2420 sensor->info_priv.contrast = ctrl->value;
2425 #if CONFIG_SENSOR_WhiteBalance
2426 case V4L2_CID_DO_WHITE_BALANCE:
2428 if (ctrl->value != sensor->info_priv.whiteBalance)
2430 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2434 sensor->info_priv.whiteBalance = ctrl->value;
2439 #if CONFIG_SENSOR_Mirror
2440 case V4L2_CID_HFLIP:
2442 if (ctrl->value != sensor->info_priv.mirror)
2444 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2446 sensor->info_priv.mirror = ctrl->value;
2451 #if CONFIG_SENSOR_Flip
2452 case V4L2_CID_VFLIP:
2454 if (ctrl->value != sensor->info_priv.flip)
2456 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2458 sensor->info_priv.flip = ctrl->value;
2469 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2471 const struct v4l2_queryctrl *qctrl;
2472 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2473 struct sensor *sensor = to_sensor(client);
2475 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2479 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2483 switch (ext_ctrl->id)
2485 case V4L2_CID_SCENE:
2487 ext_ctrl->value = sensor->info_priv.scene;
2490 case V4L2_CID_EFFECT:
2492 ext_ctrl->value = sensor->info_priv.effect;
2495 case V4L2_CID_ZOOM_ABSOLUTE:
2497 ext_ctrl->value = sensor->info_priv.digitalzoom;
2500 case V4L2_CID_ZOOM_RELATIVE:
2504 case V4L2_CID_FOCUS_ABSOLUTE:
2506 ext_ctrl->value = sensor->info_priv.focus;
2509 case V4L2_CID_FOCUS_RELATIVE:
2513 case V4L2_CID_FLASH:
2515 ext_ctrl->value = sensor->info_priv.flash;
2523 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2525 const struct v4l2_queryctrl *qctrl;
2526 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2527 struct sensor *sensor = to_sensor(client);
2530 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2534 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2539 switch (ext_ctrl->id)
2541 #if CONFIG_SENSOR_Scene
2542 case V4L2_CID_SCENE:
2544 if (ext_ctrl->value != sensor->info_priv.scene)
2546 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2548 sensor->info_priv.scene = ext_ctrl->value;
2553 #if CONFIG_SENSOR_Effect
2554 case V4L2_CID_EFFECT:
2556 if (ext_ctrl->value != sensor->info_priv.effect)
2558 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2560 sensor->info_priv.effect= ext_ctrl->value;
2565 #if CONFIG_SENSOR_DigitalZoom
2566 case V4L2_CID_ZOOM_ABSOLUTE:
2568 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2571 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2573 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2575 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2577 sensor->info_priv.digitalzoom += val_offset;
2579 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2584 case V4L2_CID_ZOOM_RELATIVE:
2586 if (ext_ctrl->value)
2588 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2590 sensor->info_priv.digitalzoom += ext_ctrl->value;
2592 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2597 #if CONFIG_SENSOR_Focus
2598 case V4L2_CID_FOCUS_ABSOLUTE:
2600 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2603 if (ext_ctrl->value != sensor->info_priv.focus)
2605 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2607 sensor->info_priv.focus += val_offset;
2612 case V4L2_CID_FOCUS_RELATIVE:
2614 if (ext_ctrl->value)
2616 sensor->info_priv.focus += ext_ctrl->value;
2618 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2623 #if CONFIG_SENSOR_Flash
2624 case V4L2_CID_FLASH:
2626 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2628 sensor->info_priv.flash = ext_ctrl->value;
2630 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2641 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2643 struct i2c_client *client = v4l2_get_subdevdata(sd);
2644 struct soc_camera_device *icd = client->dev.platform_data;
2645 int i, error_cnt=0, error_idx=-1;
2648 for (i=0; i<ext_ctrl->count; i++) {
2649 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2656 error_idx = ext_ctrl->count;
2658 if (error_idx != -1) {
2659 ext_ctrl->error_idx = error_idx;
2666 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2668 struct i2c_client *client = v4l2_get_subdevdata(sd);
2669 struct soc_camera_device *icd = client->dev.platform_data;
2670 int i, error_cnt=0, error_idx=-1;
2673 for (i=0; i<ext_ctrl->count; i++) {
2674 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2681 error_idx = ext_ctrl->count;
2683 if (error_idx != -1) {
2684 ext_ctrl->error_idx = error_idx;
2691 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2692 * this wasn't our capture interface, so, we wait for the right one */
2693 static int sensor_video_probe(struct soc_camera_device *icd,
2694 struct i2c_client *client)
2698 struct sensor *sensor = to_sensor(client);
2700 /* We must have a parent by now. And it cannot be a wrong one.
2701 * So this entire test is completely redundant. */
2702 if (!icd->dev.parent ||
2703 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2706 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2708 goto sensor_video_probe_err;
2712 ret = sensor_write(client, 0x3021, 0x61);
2714 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2716 goto sensor_video_probe_err;
2718 mdelay(5); //delay 5 microseconds
2720 /* check if it is an sensor sensor */
2721 ret = sensor_read(client, 0x307e, &value);
2723 SENSOR_TR("read chip id high byte failed\n");
2725 goto sensor_video_probe_err;
2728 pid |= (value << 8);
2730 ret = sensor_read(client, 0x307f, &value);
2732 SENSOR_TR("read chip id low byte failed\n");
2734 goto sensor_video_probe_err;
2737 pid |= (value & 0xff);
2738 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2739 if (pid == SENSOR_ID) {
2740 sensor->model = SENSOR_V4L2_IDENT;
2742 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2744 goto sensor_video_probe_err;
2749 sensor_video_probe_err:
2753 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2755 struct i2c_client *client = v4l2_get_subdevdata(sd);
2756 struct soc_camera_device *icd = client->dev.platform_data;
2757 struct sensor *sensor = to_sensor(client);
2759 #if CONFIG_SENSOR_Flash
2763 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2766 case RK29_CAM_SUBDEV_DEACTIVATE:
2768 sensor_deactivate(client);
2772 case RK29_CAM_SUBDEV_IOREQUEST:
2774 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2775 if (sensor->sensor_io_request != NULL) {
2777 for(j = 0;j < RK_CAM_NUM;j++){
2778 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
2779 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
2780 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
2784 if(j == RK_CAM_NUM){
2785 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2787 goto sensor_ioctl_end;
2790 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2792 #if CONFIG_SENSOR_Flash
2793 if (sensor->sensor_gpio_res) {
2794 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2795 for (i = 0; i < icd->ops->num_controls; i++) {
2796 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2797 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2800 sensor->info_priv.flash = 0xff;
2801 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2809 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2817 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2818 enum v4l2_mbus_pixelcode *code)
2820 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2823 *code = sensor_colour_fmts[index].code;
2826 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2827 .init = sensor_init,
2828 .g_ctrl = sensor_g_control,
2829 .s_ctrl = sensor_s_control,
2830 .g_ext_ctrls = sensor_g_ext_controls,
2831 .s_ext_ctrls = sensor_s_ext_controls,
2832 .g_chip_ident = sensor_g_chip_ident,
2833 .ioctl = sensor_ioctl,
2836 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2837 .s_mbus_fmt = sensor_s_fmt,
2838 .g_mbus_fmt = sensor_g_fmt,
2839 .try_mbus_fmt = sensor_try_fmt,
2840 .enum_mbus_fmt = sensor_enum_fmt,
2843 static struct v4l2_subdev_ops sensor_subdev_ops = {
2844 .core = &sensor_subdev_core_ops,
2845 .video = &sensor_subdev_video_ops,
2848 static int sensor_probe(struct i2c_client *client,
2849 const struct i2c_device_id *did)
2851 struct sensor *sensor;
2852 struct soc_camera_device *icd = client->dev.platform_data;
2853 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2854 struct soc_camera_link *icl;
2857 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2859 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2863 icl = to_soc_camera_link(icd);
2865 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2869 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2870 dev_warn(&adapter->dev,
2871 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2875 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2879 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2881 /* Second stage probe - when a capture adapter is there */
2882 icd->ops = &sensor_ops;
2884 sensor->info_priv.fmt = sensor_colour_fmts[0];
2886 #if CONFIG_SENSOR_I2C_NOSCHED
2887 atomic_set(&sensor->tasklock_cnt,0);
2890 ret = sensor_video_probe(icd, client);
2893 i2c_set_clientdata(client, NULL);
2897 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2901 static int sensor_remove(struct i2c_client *client)
2903 struct sensor *sensor = to_sensor(client);
2904 struct soc_camera_device *icd = client->dev.platform_data;
2907 i2c_set_clientdata(client, NULL);
2908 client->driver = NULL;
2914 static const struct i2c_device_id sensor_id[] = {
2915 {SENSOR_NAME_STRING(), 0 },
2918 MODULE_DEVICE_TABLE(i2c, sensor_id);
2920 static struct i2c_driver sensor_i2c_driver = {
2922 .name = SENSOR_NAME_STRING(),
2924 .probe = sensor_probe,
2925 .remove = sensor_remove,
2926 .id_table = sensor_id,
2929 static int __init sensor_mod_init(void)
2931 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2932 return i2c_add_driver(&sensor_i2c_driver);
2935 static void __exit sensor_mod_exit(void)
2937 i2c_del_driver(&sensor_i2c_driver);
2940 device_initcall_sync(sensor_mod_init);
2941 module_exit(sensor_mod_exit);
2943 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2944 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2945 MODULE_LICENSE("GPL");