2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <plat/rk_camera.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_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 800 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 600
55 #define SENSOR_INIT_WINSEQADR sensor_svga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 0
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 0
63 #define CONFIG_SENSOR_Scene 0
64 #define CONFIG_SENSOR_DigitalZoom 0
65 #define CONFIG_SENSOR_Focus 0
66 #define CONFIG_SENSOR_Exposure 0
67 #define CONFIG_SENSOR_Flash 0
68 #define CONFIG_SENSOR_Mirror 0
69 #define CONFIG_SENSOR_Flip 0
71 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
72 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
73 #define CONFIG_SENSOR_I2C_NOSCHED 0
74 #define CONFIG_SENSOR_I2C_RDWRCHK 0
76 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
77 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
78 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
80 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
81 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
82 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
83 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
84 #define COLOR_TEMPERATURE_OFFICE_DN 3500
85 #define COLOR_TEMPERATURE_OFFICE_UP 5000
86 #define COLOR_TEMPERATURE_HOME_DN 2500
87 #define COLOR_TEMPERATURE_HOME_UP 3500
89 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
90 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
92 #define SENSOR_AF_IS_ERR (0x00<<0)
93 #define SENSOR_AF_IS_OK (0x01<<0)
94 #define SENSOR_INIT_IS_ERR (0x00<<28)
95 #define SENSOR_INIT_IS_OK (0x01<<28)
103 //flash off in fixed time to prevent from too hot , zyc
105 struct soc_camera_device *icd;
106 struct hrtimer timer;
108 #if CONFIG_SENSOR_Flash
109 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
111 static struct flash_timer flash_off_timer;
112 //for user defined if user want to customize the series , zyc
113 #ifdef CONFIG_NT99250_USER_DEFINED_SERIES
114 #include "NT99250_user_series.c"
116 /* init 352X288 SVGA */
117 static struct reginfo sensor_init_data[] =
119 {0x3024,0x02}, //TG //0x02
120 {0x32F0,0x00},//0:UYVY 2:VYUY 1:YUYV 3:YVYU
242 {0x32f6,0x0c},//effect function
243 {0x3069, 0x00}, //Pix //01 :for M1002 00 :for other
244 {0x306d, 0x01}, //pclk //00 :for M1002 01 :for other
246 //==============================
248 //==============================
300 {0x32c2,0x5c}, //7.14fps @ 48M
304 {0x3290,0x01}, //awb init ++++
314 {0x32a8,0xa0}, //awb init ----
315 {0x3012,0x02}, //AE init +++
318 {0x3201,0x7f}, //AE init ---
321 {0x0, 0x0}, //end flag
326 static struct reginfo sensor_uxga[] =
328 //Output format & size
332 {0x3332, 0x80}, //0x20
333 {0x3320, 0x20}, //0x28
384 static struct reginfo sensor_sxga[] =
432 static struct reginfo sensor_svga[] =
462 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
484 {0x32c2,0x5c}, //7.14fps @ 48M
486 //{0x32c2,0xd4}, //10fps @ 48M
490 //{0x3290,0x01}, //awb init ++++
500 {0x32a8,0xa0}, //awb init ----
501 //{0x3012,0x02}, //AE init +++
504 //{0x3201,0x7f}, //AE init ---
512 static struct reginfo sensor_vga[] =
543 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
565 //{0x32c2,0x5c}, //7.14fps @ 48M
567 {0x32c2,0xd4}, //10fps @ 48M
571 //{0x3290,0x01}, //awb init ++++
581 {0x32a8,0xa0}, //awb init ----
582 //{0x3012,0x02}, //AE init +++
585 //{0x3201,0x7f}, //AE init ---
592 static struct reginfo sensor_cif[] =
598 static struct reginfo sensor_qvga[] =
604 static struct reginfo sensor_qcif[] =
610 static struct reginfo sensor_ClrFmt_YUYV[]=
612 {0x32f0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
616 static struct reginfo sensor_ClrFmt_UYVY[]=
618 {0x32F0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
622 #if CONFIG_SENSOR_WhiteBalance
623 static struct reginfo sensor_WhiteB_Auto[]=
625 {0x3201, 0x3f}, //AWB auto, bit[1]:0,auto
628 /* Cloudy Colour Temperature : 6500K - 8000K */
629 static struct reginfo sensor_WhiteB_Cloudy[]=
638 /* ClearDay Colour Temperature : 5000K - 6500K */
639 static struct reginfo sensor_WhiteB_ClearDay[]=
650 /* Office Colour Temperature : 3500K - 5000K */
651 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
662 /* Home Colour Temperature : 2500K - 3500K */
663 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
673 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
674 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
678 #if CONFIG_SENSOR_Brightness
679 static struct reginfo sensor_Brightness0[]=
687 static struct reginfo sensor_Brightness1[]=
695 static struct reginfo sensor_Brightness2[]=
703 static struct reginfo sensor_Brightness3[]=
711 static struct reginfo sensor_Brightness4[]=
719 static struct reginfo sensor_Brightness5[]=
726 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
727 sensor_Brightness4, sensor_Brightness5,NULL,
732 #if CONFIG_SENSOR_Effect
733 static struct reginfo sensor_Effect_Normal[] =
739 static struct reginfo sensor_Effect_WandB[] =
745 static struct reginfo sensor_Effect_Sepia[] =
752 static struct reginfo sensor_Effect_Negative[] =
759 static struct reginfo sensor_Effect_Bluish[] =
769 static struct reginfo sensor_Effect_Green[] =
778 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
779 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
782 #if CONFIG_SENSOR_Exposure
783 static struct reginfo sensor_Exposure0[]=
789 static struct reginfo sensor_Exposure1[]=
795 static struct reginfo sensor_Exposure2[]=
801 static struct reginfo sensor_Exposure3[]=
807 static struct reginfo sensor_Exposure4[]=
813 static struct reginfo sensor_Exposure5[]=
819 static struct reginfo sensor_Exposure6[]=
825 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
826 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
829 #if CONFIG_SENSOR_Saturation
830 static struct reginfo sensor_Saturation0[]=
835 static struct reginfo sensor_Saturation1[]=
840 static struct reginfo sensor_Saturation2[]=
844 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
847 #if CONFIG_SENSOR_Contrast
848 static struct reginfo sensor_Contrast0[]=
854 static struct reginfo sensor_Contrast1[]=
860 static struct reginfo sensor_Contrast2[]=
866 static struct reginfo sensor_Contrast3[]=
872 static struct reginfo sensor_Contrast4[]=
879 static struct reginfo sensor_Contrast5[]=
885 static struct reginfo sensor_Contrast6[]=
890 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
891 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
895 #if CONFIG_SENSOR_Mirror
896 static struct reginfo sensor_MirrorOn[]=
901 static struct reginfo sensor_MirrorOff[]=
905 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
907 #if CONFIG_SENSOR_Flip
908 static struct reginfo sensor_FlipOn[]=
913 static struct reginfo sensor_FlipOff[]=
917 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
920 #if CONFIG_SENSOR_Scene
921 static struct reginfo sensor_SceneAuto[] =
927 static struct reginfo sensor_SceneNight[] =
929 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
933 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
936 #if CONFIG_SENSOR_DigitalZoom
937 static struct reginfo sensor_Zoom0[] =
942 static struct reginfo sensor_Zoom1[] =
947 static struct reginfo sensor_Zoom2[] =
953 static struct reginfo sensor_Zoom3[] =
957 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
959 static struct v4l2_querymenu sensor_menus[] =
961 #if CONFIG_SENSOR_WhiteBalance
962 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
963 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
964 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
967 #if CONFIG_SENSOR_Effect
968 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
969 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
970 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
973 #if CONFIG_SENSOR_Scene
974 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
977 #if CONFIG_SENSOR_Flash
978 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
979 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
983 static struct v4l2_queryctrl sensor_controls[] =
985 #if CONFIG_SENSOR_WhiteBalance
987 .id = V4L2_CID_DO_WHITE_BALANCE,
988 .type = V4L2_CTRL_TYPE_MENU,
989 .name = "White Balance Control",
997 #if CONFIG_SENSOR_Brightness
999 .id = V4L2_CID_BRIGHTNESS,
1000 .type = V4L2_CTRL_TYPE_INTEGER,
1001 .name = "Brightness Control",
1009 #if CONFIG_SENSOR_Effect
1011 .id = V4L2_CID_EFFECT,
1012 .type = V4L2_CTRL_TYPE_MENU,
1013 .name = "Effect Control",
1021 #if CONFIG_SENSOR_Exposure
1023 .id = V4L2_CID_EXPOSURE,
1024 .type = V4L2_CTRL_TYPE_INTEGER,
1025 .name = "Exposure Control",
1033 #if CONFIG_SENSOR_Saturation
1035 .id = V4L2_CID_SATURATION,
1036 .type = V4L2_CTRL_TYPE_INTEGER,
1037 .name = "Saturation Control",
1045 #if CONFIG_SENSOR_Contrast
1047 .id = V4L2_CID_CONTRAST,
1048 .type = V4L2_CTRL_TYPE_INTEGER,
1049 .name = "Contrast Control",
1057 #if CONFIG_SENSOR_Mirror
1059 .id = V4L2_CID_HFLIP,
1060 .type = V4L2_CTRL_TYPE_BOOLEAN,
1061 .name = "Mirror Control",
1069 #if CONFIG_SENSOR_Flip
1071 .id = V4L2_CID_VFLIP,
1072 .type = V4L2_CTRL_TYPE_BOOLEAN,
1073 .name = "Flip Control",
1081 #if CONFIG_SENSOR_Scene
1083 .id = V4L2_CID_SCENE,
1084 .type = V4L2_CTRL_TYPE_MENU,
1085 .name = "Scene Control",
1093 #if CONFIG_SENSOR_DigitalZoom
1095 .id = V4L2_CID_ZOOM_RELATIVE,
1096 .type = V4L2_CTRL_TYPE_INTEGER,
1097 .name = "DigitalZoom Control",
1103 .id = V4L2_CID_ZOOM_ABSOLUTE,
1104 .type = V4L2_CTRL_TYPE_INTEGER,
1105 .name = "DigitalZoom Control",
1113 #if CONFIG_SENSOR_Focus
1115 .id = V4L2_CID_FOCUS_RELATIVE,
1116 .type = V4L2_CTRL_TYPE_INTEGER,
1117 .name = "Focus Control",
1123 .id = V4L2_CID_FOCUS_ABSOLUTE,
1124 .type = V4L2_CTRL_TYPE_INTEGER,
1125 .name = "Focus Control",
1129 .default_value = 125,
1133 #if CONFIG_SENSOR_Flash
1135 .id = V4L2_CID_FLASH,
1136 .type = V4L2_CTRL_TYPE_MENU,
1137 .name = "Flash Control",
1146 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1147 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1148 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1149 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1150 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1151 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1152 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1153 static int sensor_resume(struct soc_camera_device *icd);
1154 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1155 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1156 #if CONFIG_SENSOR_Effect
1157 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1159 #if CONFIG_SENSOR_WhiteBalance
1160 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1162 static int sensor_deactivate(struct i2c_client *client);
1164 static struct soc_camera_ops sensor_ops =
1166 .suspend = sensor_suspend,
1167 .resume = sensor_resume,
1168 .set_bus_param = sensor_set_bus_param,
1169 .query_bus_param = sensor_query_bus_param,
1170 .controls = sensor_controls,
1171 .menus = sensor_menus,
1172 .num_controls = ARRAY_SIZE(sensor_controls),
1173 .num_menus = ARRAY_SIZE(sensor_menus),
1176 /* only one fixed colorspace per pixelcode */
1177 struct sensor_datafmt {
1178 enum v4l2_mbus_pixelcode code;
1179 enum v4l2_colorspace colorspace;
1182 /* Find a data format by a pixel code in an array */
1183 static const struct sensor_datafmt *sensor_find_datafmt(
1184 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1188 for (i = 0; i < n; i++)
1189 if (fmt[i].code == code)
1195 static const struct sensor_datafmt sensor_colour_fmts[] = {
1196 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1197 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1200 typedef struct sensor_info_priv_s
1214 unsigned char mirror; /* HFLIP */
1215 unsigned char flip; /* VFLIP */
1216 unsigned int winseqe_cur_addr;
1217 struct sensor_datafmt fmt;
1218 unsigned int funmodule_state;
1220 } sensor_info_priv_t;
1224 struct v4l2_subdev subdev;
1225 struct i2c_client *client;
1226 sensor_info_priv_t info_priv;
1227 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1228 #if CONFIG_SENSOR_I2C_NOSCHED
1229 atomic_t tasklock_cnt;
1231 struct rk29camera_platform_data *sensor_io_request;
1232 struct rk29camera_gpio_res *sensor_gpio_res;
1236 static struct sensor* to_sensor(const struct i2c_client *client)
1238 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1241 static int sensor_task_lock(struct i2c_client *client, int lock)
1243 #if CONFIG_SENSOR_I2C_NOSCHED
1245 struct sensor *sensor = to_sensor(client);
1248 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1249 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1250 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1254 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1255 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1256 goto sensor_task_lock_err;
1261 atomic_add(1, &sensor->tasklock_cnt);
1263 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1264 atomic_sub(1, &sensor->tasklock_cnt);
1266 if (atomic_read(&sensor->tasklock_cnt) == 0)
1271 sensor_task_lock_err:
1279 /* sensor register write */
1280 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1284 struct i2c_msg msg[1];
1287 buf[1] = reg & 0xFF;
1290 msg->addr = client->addr;
1291 msg->flags = client->flags;
1293 msg->len = sizeof(buf);
1294 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1295 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1300 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1301 err = i2c_transfer(client->adapter, msg, 1);
1306 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1314 /* sensor register read */
1315 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1319 struct i2c_msg msg[2];
1322 buf[1] = reg & 0xFF;
1324 msg[0].addr = client->addr;
1325 msg[0].flags = client->flags;
1327 msg[0].len = sizeof(buf);
1328 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1329 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1331 msg[1].addr = client->addr;
1332 msg[1].flags = client->flags|I2C_M_RD;
1335 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1336 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1340 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1341 err = i2c_transfer(client->adapter, msg, 2);
1347 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1355 /* write a array of registers */
1356 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1360 #if CONFIG_SENSOR_I2C_RDWRCHK
1365 if (sensor_task_lock(client, 1) < 0)
1366 goto sensor_write_array_end;
1368 while (regarray[i].reg != 0)
1370 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1374 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1378 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1380 goto sensor_write_array_end;
1383 #if CONFIG_SENSOR_I2C_RDWRCHK
1384 sensor_read(client, regarray[i].reg, &valchk);
1385 if (valchk != regarray[i].val)
1386 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1392 sensor_write_array_end:
1393 sensor_task_lock(client,0);
1396 #if CONFIG_SENSOR_I2C_RDWRCHK
1397 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1405 while (regarray[i].reg != 0)
1407 sensor_read(client, regarray[i].reg, &valchk);
1408 if (valchk != regarray[i].val)
1409 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1416 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1418 struct soc_camera_link *icl = to_soc_camera_link(icd);
1421 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1424 case Sensor_PowerDown:
1426 if (icl->powerdown) {
1427 ret = icl->powerdown(icd->pdev, on);
1428 if (ret == RK29_CAM_IO_SUCCESS) {
1432 icl->reset(icd->pdev);
1434 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1436 goto sensor_power_end;
1443 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1444 struct sensor *sensor = to_sensor(client);
1446 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1447 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1449 //flash off after 2 secs
1450 hrtimer_cancel(&(flash_off_timer.timer));
1451 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1458 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1465 #if CONFIG_SENSOR_Flash
1466 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1467 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1468 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1469 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1474 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1476 struct i2c_client *client = v4l2_get_subdevdata(sd);
1477 struct soc_camera_device *icd = client->dev.platform_data;
1478 struct sensor *sensor = to_sensor(client);
1479 const struct v4l2_queryctrl *qctrl;
1480 const struct sensor_datafmt *fmt;
1484 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1486 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1488 goto sensor_INIT_ERR;
1492 if (sensor_task_lock(client,1)<0)
1493 goto sensor_INIT_ERR;
1495 ret = sensor_write(client, 0x3021, 0x61);
1498 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1500 goto sensor_INIT_ERR;
1503 mdelay(5); //delay 5 microseconds
1504 /* check if it is an sensor sensor */
1505 ret = sensor_read(client, 0x307e, &value);
1507 SENSOR_TR("read chip id high byte failed\n");
1509 goto sensor_INIT_ERR;
1512 pid |= (value << 8);
1514 ret = sensor_read(client, 0x307f, &value);
1516 SENSOR_TR("read chip id low byte failed\n");
1518 goto sensor_INIT_ERR;
1521 pid |= (value & 0xff);
1522 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1524 if (pid == SENSOR_ID) {
1525 sensor->model = SENSOR_V4L2_IDENT;
1527 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1529 goto sensor_INIT_ERR;
1533 ret = sensor_write_array(client, sensor_init_data);
1536 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1537 goto sensor_INIT_ERR;
1539 sensor_task_lock(client,0);
1541 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1542 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1544 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1546 goto sensor_INIT_ERR;
1548 sensor->info_priv.fmt = *fmt;
1550 /* sensor sensor information for initialization */
1551 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1553 sensor->info_priv.whiteBalance = qctrl->default_value;
1554 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1556 sensor->info_priv.brightness = qctrl->default_value;
1557 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1559 sensor->info_priv.effect = qctrl->default_value;
1560 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1562 sensor->info_priv.exposure = qctrl->default_value;
1564 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1566 sensor->info_priv.saturation = qctrl->default_value;
1567 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1569 sensor->info_priv.contrast = qctrl->default_value;
1570 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1572 sensor->info_priv.mirror = qctrl->default_value;
1573 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1575 sensor->info_priv.flip = qctrl->default_value;
1576 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1578 sensor->info_priv.scene = qctrl->default_value;
1579 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1581 sensor->info_priv.digitalzoom = qctrl->default_value;
1583 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1584 #if CONFIG_SENSOR_Focus
1586 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1588 sensor->info_priv.focus = qctrl->default_value;
1591 #if CONFIG_SENSOR_Flash
1592 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1594 sensor->info_priv.flash = qctrl->default_value;
1595 flash_off_timer.icd = icd;
1596 flash_off_timer.timer.function = flash_off_func;
1599 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);
1600 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1603 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1604 sensor_task_lock(client,0);
1605 sensor_deactivate(client);
1609 static int sensor_deactivate(struct i2c_client *client)
1611 struct soc_camera_device *icd = client->dev.platform_data;
1612 struct sensor *sensor = to_sensor(client);
1613 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1615 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1616 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1619 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1620 icd->user_width = SENSOR_INIT_WIDTH;
1621 icd->user_height = SENSOR_INIT_HEIGHT;
1622 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1627 static struct reginfo sensor_power_down_sequence[]=
1635 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1638 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1640 if (pm_msg.event == PM_EVENT_SUSPEND) {
1641 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1642 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1644 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1647 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1649 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1654 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1660 static int sensor_resume(struct soc_camera_device *icd)
1664 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1666 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1670 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1676 static int sensor_set_bus_param(struct soc_camera_device *icd,
1677 unsigned long flags)
1683 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1685 struct soc_camera_link *icl = to_soc_camera_link(icd);
1686 unsigned long flags = SENSOR_BUS_PARAM;
1688 return soc_camera_apply_sensor_flags(icl, flags);
1691 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1693 struct i2c_client *client = v4l2_get_subdevdata(sd);
1694 struct soc_camera_device *icd = client->dev.platform_data;
1695 struct sensor *sensor = to_sensor(client);
1697 mf->width = icd->user_width;
1698 mf->height = icd->user_height;
1699 mf->code = sensor->info_priv.fmt.code;
1700 mf->colorspace = sensor->info_priv.fmt.colorspace;
1701 mf->field = V4L2_FIELD_NONE;
1706 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1710 if ((mf->width == 1024) && (mf->height == 768)) {
1712 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1714 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1716 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1718 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1723 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1727 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1731 if ((mf->width == 1280) && (mf->height == 720)) {
1733 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1738 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1742 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1744 struct i2c_client *client = v4l2_get_subdevdata(sd);
1745 const struct sensor_datafmt *fmt;
1746 struct sensor *sensor = to_sensor(client);
1747 struct reginfo *winseqe_set_addr=NULL;
1748 int ret=0, set_w,set_h;
1752 //turn on scaler for preivew
1753 sensor_read(client ,0x3201, ®_1);
1754 sensor_write(client, 0x3201, (reg_1|0x40) );
1756 sensor_read(client ,0x32f1, ®);
1757 sensor_write(client, 0x32f1, (reg|0x10) );
1759 #if 0 //preview_fastmode
1760 u16 AE_reg, AGC_reg;
1761 u8 temp_reg12,temp_reg13
1762 // turn off AE for preview
1763 sensor_read(client ,0x3201, &AE_reg);
1764 sensor_write(client, 0x3201, (AE_reg|0x20) );
1765 // turn off AGC for preview
1766 sensor_read(client ,0x32bb, &AGC_reg);
1767 sensor_write(client, 0x32bb, (AGC_reg|0x01) );
1769 sensor_read(client, 0x3012, &temp_reg12);
1770 sensor_read(client, 0x3013, &temp_reg13);
1771 shutter = (temp_reg13 & 0x00FF) | (temp_reg12 << 8);
1773 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1774 ARRAY_SIZE(sensor_colour_fmts));
1777 goto sensor_s_fmt_end;
1780 if (sensor->info_priv.fmt.code != mf->code) {
1783 case V4L2_MBUS_FMT_YUYV8_2X8:
1785 winseqe_set_addr = sensor_ClrFmt_YUYV;
1788 case V4L2_MBUS_FMT_UYVY8_2X8:
1790 winseqe_set_addr = sensor_ClrFmt_UYVY;
1796 if (winseqe_set_addr != NULL) {
1797 sensor_write_array(client, winseqe_set_addr);
1798 sensor->info_priv.fmt.code = mf->code;
1799 sensor->info_priv.fmt.colorspace= mf->colorspace;
1800 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1802 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1809 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1811 winseqe_set_addr = sensor_qcif;
1815 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1817 winseqe_set_addr = sensor_qvga;
1821 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1823 winseqe_set_addr = sensor_cif;
1827 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1829 winseqe_set_addr = sensor_vga;
1833 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1835 winseqe_set_addr = sensor_svga;
1839 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1841 winseqe_set_addr = sensor_sxga;
1845 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1847 winseqe_set_addr = sensor_uxga;
1853 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1854 set_w = SENSOR_INIT_WIDTH;
1855 set_h = SENSOR_INIT_HEIGHT;
1856 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1859 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1860 #if CONFIG_SENSOR_Flash
1861 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1862 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1863 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1864 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1866 } else { /* ddl@rock-chips.com : Video */
1867 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1868 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1869 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1873 ret |= sensor_write_array(client, winseqe_set_addr);
1875 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1876 #if CONFIG_SENSOR_Flash
1877 if (sensor_fmt_capturechk(sd,mf) == true) {
1878 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1879 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1880 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1884 goto sensor_s_fmt_end;
1887 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1889 if ((set_w <= 640) && (set_h <= 480))
1896 sensor_read(client ,0x32f1, ®);
1897 sensor_write(client, 0x32f1, (reg&(~0x10)) );
1898 if ((set_w <= 1600) && (set_h <= 1200))
1900 //turn off scaler for UXGA capture
1901 sensor_read(client ,0x3201, ®_1);
1902 sensor_write(client, 0x3201, (reg_1&(~0x40)) );
1904 #if 0 //preview_fastmode
1906 sensor_read(client ,0x3201, &AE_reg);
1907 sensor_write(client, 0x3201, (AE_reg&(~0x20)) );
1909 sensor_read(client ,0x32bb, &AGC_reg);
1910 sensor_write(client, 0x32bb, (AGC_reg&(~0x01)) );
1911 if ((set_w <= 800) && (set_h <= 600))
1913 shutter = shutter*1984/2434;
1915 else if ((set_w <= 2434) && (set_h <= 1024))
1917 shutter = shutter*1984/2434;
1919 else if ((set_w <= 1600) && (set_h <= 1200))
1921 shutter = shutter*1984/2434;
1927 sensor_write(client, 0x3012, sizeof((shutter >> 8) & 0xff) );
1928 sensor_write(client, 0x3013, sizeof(shutter & 0xFF) );
1933 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1937 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1947 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1949 struct i2c_client *client = v4l2_get_subdevdata(sd);
1950 struct sensor *sensor = to_sensor(client);
1951 const struct sensor_datafmt *fmt;
1954 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1955 ARRAY_SIZE(sensor_colour_fmts));
1957 fmt = &sensor->info_priv.fmt;
1958 mf->code = fmt->code;
1961 if (mf->height > SENSOR_MAX_HEIGHT)
1962 mf->height = SENSOR_MAX_HEIGHT;
1963 else if (mf->height < SENSOR_MIN_HEIGHT)
1964 mf->height = SENSOR_MIN_HEIGHT;
1966 if (mf->width > SENSOR_MAX_WIDTH)
1967 mf->width = SENSOR_MAX_WIDTH;
1968 else if (mf->width < SENSOR_MIN_WIDTH)
1969 mf->width = SENSOR_MIN_WIDTH;
1971 mf->colorspace = fmt->colorspace;
1972 /*not support 720p video*/
1973 if(mf->height == 720 && mf->width == 1280){
1980 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1982 struct i2c_client *client = v4l2_get_subdevdata(sd);
1984 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1987 if (id->match.addr != client->addr)
1990 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1995 #if CONFIG_SENSOR_Brightness
1996 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1998 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2000 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2002 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2004 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2006 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2009 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2013 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2017 #if CONFIG_SENSOR_Effect
2018 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2020 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2022 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2024 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2026 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2028 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2031 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2035 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2039 #if CONFIG_SENSOR_Exposure
2040 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2042 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2044 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2046 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2048 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2050 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2053 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2057 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2061 #if CONFIG_SENSOR_Saturation
2062 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2064 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2066 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2068 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2070 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2072 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2075 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2079 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2083 #if CONFIG_SENSOR_Contrast
2084 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2086 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2088 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2090 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2092 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2094 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2097 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2101 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2105 #if CONFIG_SENSOR_Mirror
2106 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2108 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2110 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2112 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2114 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2116 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2119 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2123 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2127 #if CONFIG_SENSOR_Flip
2128 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2130 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2132 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2134 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2136 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2138 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2141 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2145 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2149 #if CONFIG_SENSOR_Scene
2150 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2152 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2154 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2156 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2158 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2160 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2163 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2167 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2171 #if CONFIG_SENSOR_WhiteBalance
2172 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2174 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2176 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2178 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2180 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2182 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2185 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2189 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2193 #if CONFIG_SENSOR_DigitalZoom
2194 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2196 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2197 struct sensor *sensor = to_sensor(client);
2198 const struct v4l2_queryctrl *qctrl_info;
2199 int digitalzoom_cur, digitalzoom_total;
2201 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2205 digitalzoom_cur = sensor->info_priv.digitalzoom;
2206 digitalzoom_total = qctrl_info->maximum;
2208 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2210 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2214 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2216 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2220 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2222 value = digitalzoom_total - digitalzoom_cur;
2225 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2227 value = 0 - digitalzoom_cur;
2230 digitalzoom_cur += value;
2232 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2234 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2236 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2239 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2246 #if CONFIG_SENSOR_Flash
2247 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2249 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2250 if (value == 3) { /* ddl@rock-chips.com: torch */
2251 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2253 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2255 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2259 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2264 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2266 struct i2c_client *client = v4l2_get_subdevdata(sd);
2267 struct sensor *sensor = to_sensor(client);
2268 const struct v4l2_queryctrl *qctrl;
2270 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2274 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2280 case V4L2_CID_BRIGHTNESS:
2282 ctrl->value = sensor->info_priv.brightness;
2285 case V4L2_CID_SATURATION:
2287 ctrl->value = sensor->info_priv.saturation;
2290 case V4L2_CID_CONTRAST:
2292 ctrl->value = sensor->info_priv.contrast;
2295 case V4L2_CID_DO_WHITE_BALANCE:
2297 ctrl->value = sensor->info_priv.whiteBalance;
2300 case V4L2_CID_EXPOSURE:
2302 ctrl->value = sensor->info_priv.exposure;
2305 case V4L2_CID_HFLIP:
2307 ctrl->value = sensor->info_priv.mirror;
2310 case V4L2_CID_VFLIP:
2312 ctrl->value = sensor->info_priv.flip;
2323 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2325 //struct i2c_client *client = v4l2_get_subdevdata(sd);
2326 //struct sensor *sensor = to_sensor(client);
2327 //struct soc_camera_device *icd = client->dev.platform_data;
2328 const struct v4l2_queryctrl *qctrl;
2331 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2335 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2341 #if CONFIG_SENSOR_Brightness
2342 case V4L2_CID_BRIGHTNESS:
2344 if (ctrl->value != sensor->info_priv.brightness)
2346 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2350 sensor->info_priv.brightness = ctrl->value;
2355 #if CONFIG_SENSOR_Exposure
2356 case V4L2_CID_EXPOSURE:
2358 if (ctrl->value != sensor->info_priv.exposure)
2360 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2364 sensor->info_priv.exposure = ctrl->value;
2369 #if CONFIG_SENSOR_Saturation
2370 case V4L2_CID_SATURATION:
2372 if (ctrl->value != sensor->info_priv.saturation)
2374 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2378 sensor->info_priv.saturation = ctrl->value;
2383 #if CONFIG_SENSOR_Contrast
2384 case V4L2_CID_CONTRAST:
2386 if (ctrl->value != sensor->info_priv.contrast)
2388 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2392 sensor->info_priv.contrast = ctrl->value;
2397 #if CONFIG_SENSOR_WhiteBalance
2398 case V4L2_CID_DO_WHITE_BALANCE:
2400 if (ctrl->value != sensor->info_priv.whiteBalance)
2402 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2406 sensor->info_priv.whiteBalance = ctrl->value;
2411 #if CONFIG_SENSOR_Mirror
2412 case V4L2_CID_HFLIP:
2414 if (ctrl->value != sensor->info_priv.mirror)
2416 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2418 sensor->info_priv.mirror = ctrl->value;
2423 #if CONFIG_SENSOR_Flip
2424 case V4L2_CID_VFLIP:
2426 if (ctrl->value != sensor->info_priv.flip)
2428 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2430 sensor->info_priv.flip = ctrl->value;
2441 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2443 const struct v4l2_queryctrl *qctrl;
2444 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2445 struct sensor *sensor = to_sensor(client);
2447 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2451 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2455 switch (ext_ctrl->id)
2457 case V4L2_CID_SCENE:
2459 ext_ctrl->value = sensor->info_priv.scene;
2462 case V4L2_CID_EFFECT:
2464 ext_ctrl->value = sensor->info_priv.effect;
2467 case V4L2_CID_ZOOM_ABSOLUTE:
2469 ext_ctrl->value = sensor->info_priv.digitalzoom;
2472 case V4L2_CID_ZOOM_RELATIVE:
2476 case V4L2_CID_FOCUS_ABSOLUTE:
2478 ext_ctrl->value = sensor->info_priv.focus;
2481 case V4L2_CID_FOCUS_RELATIVE:
2485 case V4L2_CID_FLASH:
2487 ext_ctrl->value = sensor->info_priv.flash;
2495 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2497 const struct v4l2_queryctrl *qctrl;
2498 //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2499 //struct sensor *sensor = to_sensor(client);
2502 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2506 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2511 switch (ext_ctrl->id)
2513 #if CONFIG_SENSOR_Scene
2514 case V4L2_CID_SCENE:
2516 if (ext_ctrl->value != sensor->info_priv.scene)
2518 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2520 sensor->info_priv.scene = ext_ctrl->value;
2525 #if CONFIG_SENSOR_Effect
2526 case V4L2_CID_EFFECT:
2528 if (ext_ctrl->value != sensor->info_priv.effect)
2530 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2532 sensor->info_priv.effect= ext_ctrl->value;
2537 #if CONFIG_SENSOR_DigitalZoom
2538 case V4L2_CID_ZOOM_ABSOLUTE:
2540 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2543 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2545 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2547 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2549 sensor->info_priv.digitalzoom += val_offset;
2551 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2556 case V4L2_CID_ZOOM_RELATIVE:
2558 if (ext_ctrl->value)
2560 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2562 sensor->info_priv.digitalzoom += ext_ctrl->value;
2564 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2569 #if CONFIG_SENSOR_Focus
2570 case V4L2_CID_FOCUS_ABSOLUTE:
2572 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2575 if (ext_ctrl->value != sensor->info_priv.focus)
2577 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2579 sensor->info_priv.focus += val_offset;
2584 case V4L2_CID_FOCUS_RELATIVE:
2586 if (ext_ctrl->value)
2588 sensor->info_priv.focus += ext_ctrl->value;
2590 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2595 #if CONFIG_SENSOR_Flash
2596 case V4L2_CID_FLASH:
2598 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2600 sensor->info_priv.flash = ext_ctrl->value;
2602 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2613 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2615 struct i2c_client *client = v4l2_get_subdevdata(sd);
2616 struct soc_camera_device *icd = client->dev.platform_data;
2617 int i, error_cnt=0, error_idx=-1;
2620 for (i=0; i<ext_ctrl->count; i++) {
2621 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2628 error_idx = ext_ctrl->count;
2630 if (error_idx != -1) {
2631 ext_ctrl->error_idx = error_idx;
2638 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2640 struct i2c_client *client = v4l2_get_subdevdata(sd);
2641 struct soc_camera_device *icd = client->dev.platform_data;
2642 int i, error_cnt=0, error_idx=-1;
2645 for (i=0; i<ext_ctrl->count; i++) {
2646 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2653 error_idx = ext_ctrl->count;
2655 if (error_idx != -1) {
2656 ext_ctrl->error_idx = error_idx;
2663 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2664 * this wasn't our capture interface, so, we wait for the right one */
2665 static int sensor_video_probe(struct soc_camera_device *icd,
2666 struct i2c_client *client)
2670 struct sensor *sensor = to_sensor(client);
2672 /* We must have a parent by now. And it cannot be a wrong one.
2673 * So this entire test is completely redundant. */
2674 if (!icd->dev.parent ||
2675 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2678 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2680 goto sensor_video_probe_err;
2684 ret = sensor_write(client, 0x3021, 0x61);
2686 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2688 goto sensor_video_probe_err;
2690 mdelay(5); //delay 5 microseconds
2692 /* check if it is an sensor sensor */
2693 ret = sensor_read(client, 0x307e, &value);
2695 SENSOR_TR("read chip id high byte failed\n");
2697 goto sensor_video_probe_err;
2700 pid |= (value << 8);
2702 ret = sensor_read(client, 0x307f, &value);
2704 SENSOR_TR("read chip id low byte failed\n");
2706 goto sensor_video_probe_err;
2709 pid |= (value & 0xff);
2710 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2711 if (pid == SENSOR_ID) {
2712 sensor->model = SENSOR_V4L2_IDENT;
2714 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2716 goto sensor_video_probe_err;
2721 sensor_video_probe_err:
2725 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2727 struct i2c_client *client = v4l2_get_subdevdata(sd);
2728 struct soc_camera_device *icd = client->dev.platform_data;
2729 struct sensor *sensor = to_sensor(client);
2731 #if CONFIG_SENSOR_Flash
2735 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2738 case RK29_CAM_SUBDEV_DEACTIVATE:
2740 sensor_deactivate(client);
2744 case RK29_CAM_SUBDEV_IOREQUEST:
2746 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2747 if (sensor->sensor_io_request != NULL) {
2748 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2749 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2750 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2751 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2752 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2753 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2756 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2758 goto sensor_ioctl_end;
2760 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2762 #if CONFIG_SENSOR_Flash
2763 if (sensor->sensor_gpio_res) {
2764 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2765 for (i = 0; i < icd->ops->num_controls; i++) {
2766 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2767 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2768 sensor_controls[i].id=0xffff;
2771 sensor->info_priv.flash = 0xff;
2772 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2773 }else{ //two cameras are the same,need to deal diffrently ,zyc
2774 for (i = 0; i < icd->ops->num_controls; i++) {
2775 if(0xffff == icd->ops->controls[i].id){
2776 sensor_controls[i].id=V4L2_CID_FLASH;
2786 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2794 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2795 enum v4l2_mbus_pixelcode *code)
2797 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2800 *code = sensor_colour_fmts[index].code;
2803 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2804 .init = sensor_init,
2805 .g_ctrl = sensor_g_control,
2806 .s_ctrl = sensor_s_control,
2807 .g_ext_ctrls = sensor_g_ext_controls,
2808 .s_ext_ctrls = sensor_s_ext_controls,
2809 .g_chip_ident = sensor_g_chip_ident,
2810 .ioctl = sensor_ioctl,
2813 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2814 .s_mbus_fmt = sensor_s_fmt,
2815 .g_mbus_fmt = sensor_g_fmt,
2816 .try_mbus_fmt = sensor_try_fmt,
2817 .enum_mbus_fmt = sensor_enum_fmt,
2820 static struct v4l2_subdev_ops sensor_subdev_ops = {
2821 .core = &sensor_subdev_core_ops,
2822 .video = &sensor_subdev_video_ops,
2825 static int sensor_probe(struct i2c_client *client,
2826 const struct i2c_device_id *did)
2828 struct sensor *sensor;
2829 struct soc_camera_device *icd = client->dev.platform_data;
2830 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2831 struct soc_camera_link *icl;
2834 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2836 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2840 icl = to_soc_camera_link(icd);
2842 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2846 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2847 dev_warn(&adapter->dev,
2848 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2852 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2856 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2858 /* Second stage probe - when a capture adapter is there */
2859 icd->ops = &sensor_ops;
2861 sensor->info_priv.fmt = sensor_colour_fmts[0];
2863 #if CONFIG_SENSOR_I2C_NOSCHED
2864 atomic_set(&sensor->tasklock_cnt,0);
2867 ret = sensor_video_probe(icd, client);
2870 i2c_set_clientdata(client, NULL);
2874 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2875 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2879 static int sensor_remove(struct i2c_client *client)
2881 struct sensor *sensor = to_sensor(client);
2882 struct soc_camera_device *icd = client->dev.platform_data;
2885 i2c_set_clientdata(client, NULL);
2886 client->driver = NULL;
2892 static const struct i2c_device_id sensor_id[] = {
2893 {SENSOR_NAME_STRING(), 0 },
2896 MODULE_DEVICE_TABLE(i2c, sensor_id);
2898 static struct i2c_driver sensor_i2c_driver = {
2900 .name = SENSOR_NAME_STRING(),
2902 .probe = sensor_probe,
2903 .remove = sensor_remove,
2904 .id_table = sensor_id,
2907 static int __init sensor_mod_init(void)
2909 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2910 return i2c_add_driver(&sensor_i2c_driver);
2913 static void __exit sensor_mod_exit(void)
2915 i2c_del_driver(&sensor_i2c_driver);
2918 device_initcall_sync(sensor_mod_init);
2919 module_exit(sensor_mod_exit);
2921 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2922 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2923 MODULE_LICENSE("GPL");