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 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
110 static struct flash_timer flash_off_timer;
111 //for user defined if user want to customize the series , zyc
112 #ifdef CONFIG_NT99250_USER_DEFINED_SERIES
113 #include "NT99250_user_series.c"
115 /* init 352X288 SVGA */
116 static struct reginfo sensor_init_data[] =
118 {0x3024,0x02}, //TG //0x02
119 {0x32F0,0x00},//0:UYVY 2:VYUY 1:YUYV 3:YVYU
241 {0x32f6,0x0c},//effect function
242 {0x3069, 0x00}, //Pix //01 :for M1002 00 :for other
243 {0x306d, 0x01}, //pclk //00 :for M1002 01 :for other
245 //==============================
247 //==============================
299 {0x32c2,0x5c}, //7.14fps @ 48M
303 {0x3290,0x01}, //awb init ++++
313 {0x32a8,0xa0}, //awb init ----
314 {0x3012,0x02}, //AE init +++
317 {0x3201,0x7f}, //AE init ---
320 {0x0, 0x0}, //end flag
325 static struct reginfo sensor_uxga[] =
327 //Output format & size
331 {0x3332, 0x80}, //0x20
332 {0x3320, 0x20}, //0x28
383 static struct reginfo sensor_sxga[] =
431 static struct reginfo sensor_svga[] =
461 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
483 {0x32c2,0x5c}, //7.14fps @ 48M
485 //{0x32c2,0xd4}, //10fps @ 48M
489 //{0x3290,0x01}, //awb init ++++
499 {0x32a8,0xa0}, //awb init ----
500 //{0x3012,0x02}, //AE init +++
503 //{0x3201,0x7f}, //AE init ---
511 static struct reginfo sensor_vga[] =
542 {0x301f,0x20}, //pll 0x20 48Mhz 0x24 32Mhz
564 //{0x32c2,0x5c}, //7.14fps @ 48M
566 {0x32c2,0xd4}, //10fps @ 48M
570 //{0x3290,0x01}, //awb init ++++
580 {0x32a8,0xa0}, //awb init ----
581 //{0x3012,0x02}, //AE init +++
584 //{0x3201,0x7f}, //AE init ---
591 static struct reginfo sensor_cif[] =
597 static struct reginfo sensor_qvga[] =
603 static struct reginfo sensor_qcif[] =
609 static struct reginfo sensor_ClrFmt_YUYV[]=
611 {0x32f0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
615 static struct reginfo sensor_ClrFmt_UYVY[]=
617 {0x32F0, 0x00}, //0:UYVY 2:VYUY 1:YUYV 3:YVYU
621 #if CONFIG_SENSOR_WhiteBalance
622 static struct reginfo sensor_WhiteB_Auto[]=
624 {0x3201, 0x3f}, //AWB auto, bit[1]:0,auto
627 /* Cloudy Colour Temperature : 6500K - 8000K */
628 static struct reginfo sensor_WhiteB_Cloudy[]=
637 /* ClearDay Colour Temperature : 5000K - 6500K */
638 static struct reginfo sensor_WhiteB_ClearDay[]=
649 /* Office Colour Temperature : 3500K - 5000K */
650 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
661 /* Home Colour Temperature : 2500K - 3500K */
662 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
672 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
673 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
677 #if CONFIG_SENSOR_Brightness
678 static struct reginfo sensor_Brightness0[]=
686 static struct reginfo sensor_Brightness1[]=
694 static struct reginfo sensor_Brightness2[]=
702 static struct reginfo sensor_Brightness3[]=
710 static struct reginfo sensor_Brightness4[]=
718 static struct reginfo sensor_Brightness5[]=
725 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
726 sensor_Brightness4, sensor_Brightness5,NULL,
731 #if CONFIG_SENSOR_Effect
732 static struct reginfo sensor_Effect_Normal[] =
738 static struct reginfo sensor_Effect_WandB[] =
744 static struct reginfo sensor_Effect_Sepia[] =
751 static struct reginfo sensor_Effect_Negative[] =
758 static struct reginfo sensor_Effect_Bluish[] =
768 static struct reginfo sensor_Effect_Green[] =
777 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
778 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
781 #if CONFIG_SENSOR_Exposure
782 static struct reginfo sensor_Exposure0[]=
788 static struct reginfo sensor_Exposure1[]=
794 static struct reginfo sensor_Exposure2[]=
800 static struct reginfo sensor_Exposure3[]=
806 static struct reginfo sensor_Exposure4[]=
812 static struct reginfo sensor_Exposure5[]=
818 static struct reginfo sensor_Exposure6[]=
824 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
825 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
828 #if CONFIG_SENSOR_Saturation
829 static struct reginfo sensor_Saturation0[]=
834 static struct reginfo sensor_Saturation1[]=
839 static struct reginfo sensor_Saturation2[]=
843 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
846 #if CONFIG_SENSOR_Contrast
847 static struct reginfo sensor_Contrast0[]=
853 static struct reginfo sensor_Contrast1[]=
859 static struct reginfo sensor_Contrast2[]=
865 static struct reginfo sensor_Contrast3[]=
871 static struct reginfo sensor_Contrast4[]=
878 static struct reginfo sensor_Contrast5[]=
884 static struct reginfo sensor_Contrast6[]=
889 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
890 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
894 #if CONFIG_SENSOR_Mirror
895 static struct reginfo sensor_MirrorOn[]=
900 static struct reginfo sensor_MirrorOff[]=
904 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
906 #if CONFIG_SENSOR_Flip
907 static struct reginfo sensor_FlipOn[]=
912 static struct reginfo sensor_FlipOff[]=
916 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
919 #if CONFIG_SENSOR_Scene
920 static struct reginfo sensor_SceneAuto[] =
926 static struct reginfo sensor_SceneNight[] =
928 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
932 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
935 #if CONFIG_SENSOR_DigitalZoom
936 static struct reginfo sensor_Zoom0[] =
941 static struct reginfo sensor_Zoom1[] =
946 static struct reginfo sensor_Zoom2[] =
952 static struct reginfo sensor_Zoom3[] =
956 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
958 static const struct v4l2_querymenu sensor_menus[] =
960 #if CONFIG_SENSOR_WhiteBalance
961 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
962 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
963 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
966 #if CONFIG_SENSOR_Effect
967 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
968 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
969 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
972 #if CONFIG_SENSOR_Scene
973 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
976 #if CONFIG_SENSOR_Flash
977 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
978 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
982 static struct v4l2_queryctrl sensor_controls[] =
984 #if CONFIG_SENSOR_WhiteBalance
986 .id = V4L2_CID_DO_WHITE_BALANCE,
987 .type = V4L2_CTRL_TYPE_MENU,
988 .name = "White Balance Control",
996 #if CONFIG_SENSOR_Brightness
998 .id = V4L2_CID_BRIGHTNESS,
999 .type = V4L2_CTRL_TYPE_INTEGER,
1000 .name = "Brightness Control",
1008 #if CONFIG_SENSOR_Effect
1010 .id = V4L2_CID_EFFECT,
1011 .type = V4L2_CTRL_TYPE_MENU,
1012 .name = "Effect Control",
1020 #if CONFIG_SENSOR_Exposure
1022 .id = V4L2_CID_EXPOSURE,
1023 .type = V4L2_CTRL_TYPE_INTEGER,
1024 .name = "Exposure Control",
1032 #if CONFIG_SENSOR_Saturation
1034 .id = V4L2_CID_SATURATION,
1035 .type = V4L2_CTRL_TYPE_INTEGER,
1036 .name = "Saturation Control",
1044 #if CONFIG_SENSOR_Contrast
1046 .id = V4L2_CID_CONTRAST,
1047 .type = V4L2_CTRL_TYPE_INTEGER,
1048 .name = "Contrast Control",
1056 #if CONFIG_SENSOR_Mirror
1058 .id = V4L2_CID_HFLIP,
1059 .type = V4L2_CTRL_TYPE_BOOLEAN,
1060 .name = "Mirror Control",
1068 #if CONFIG_SENSOR_Flip
1070 .id = V4L2_CID_VFLIP,
1071 .type = V4L2_CTRL_TYPE_BOOLEAN,
1072 .name = "Flip Control",
1080 #if CONFIG_SENSOR_Scene
1082 .id = V4L2_CID_SCENE,
1083 .type = V4L2_CTRL_TYPE_MENU,
1084 .name = "Scene Control",
1092 #if CONFIG_SENSOR_DigitalZoom
1094 .id = V4L2_CID_ZOOM_RELATIVE,
1095 .type = V4L2_CTRL_TYPE_INTEGER,
1096 .name = "DigitalZoom Control",
1102 .id = V4L2_CID_ZOOM_ABSOLUTE,
1103 .type = V4L2_CTRL_TYPE_INTEGER,
1104 .name = "DigitalZoom Control",
1112 #if CONFIG_SENSOR_Focus
1114 .id = V4L2_CID_FOCUS_RELATIVE,
1115 .type = V4L2_CTRL_TYPE_INTEGER,
1116 .name = "Focus Control",
1122 .id = V4L2_CID_FOCUS_ABSOLUTE,
1123 .type = V4L2_CTRL_TYPE_INTEGER,
1124 .name = "Focus Control",
1128 .default_value = 125,
1132 #if CONFIG_SENSOR_Flash
1134 .id = V4L2_CID_FLASH,
1135 .type = V4L2_CTRL_TYPE_MENU,
1136 .name = "Flash Control",
1145 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1146 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1147 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1148 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1149 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1150 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1151 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1152 static int sensor_resume(struct soc_camera_device *icd);
1153 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1154 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1155 #if CONFIG_SENSOR_Effect
1156 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1158 #if CONFIG_SENSOR_WhiteBalance
1159 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1161 static int sensor_deactivate(struct i2c_client *client);
1163 static struct soc_camera_ops sensor_ops =
1165 .suspend = sensor_suspend,
1166 .resume = sensor_resume,
1167 .set_bus_param = sensor_set_bus_param,
1168 .query_bus_param = sensor_query_bus_param,
1169 .controls = sensor_controls,
1170 .menus = sensor_menus,
1171 .num_controls = ARRAY_SIZE(sensor_controls),
1172 .num_menus = ARRAY_SIZE(sensor_menus),
1175 /* only one fixed colorspace per pixelcode */
1176 struct sensor_datafmt {
1177 enum v4l2_mbus_pixelcode code;
1178 enum v4l2_colorspace colorspace;
1181 /* Find a data format by a pixel code in an array */
1182 static const struct sensor_datafmt *sensor_find_datafmt(
1183 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1187 for (i = 0; i < n; i++)
1188 if (fmt[i].code == code)
1194 static const struct sensor_datafmt sensor_colour_fmts[] = {
1195 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1196 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1199 typedef struct sensor_info_priv_s
1213 unsigned char mirror; /* HFLIP */
1214 unsigned char flip; /* VFLIP */
1215 unsigned int winseqe_cur_addr;
1216 struct sensor_datafmt fmt;
1217 unsigned int funmodule_state;
1219 } sensor_info_priv_t;
1223 struct v4l2_subdev subdev;
1224 struct i2c_client *client;
1225 sensor_info_priv_t info_priv;
1226 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1227 #if CONFIG_SENSOR_I2C_NOSCHED
1228 atomic_t tasklock_cnt;
1230 struct rk29camera_platform_data *sensor_io_request;
1231 struct rk29camera_gpio_res *sensor_gpio_res;
1235 static struct sensor* to_sensor(const struct i2c_client *client)
1237 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1240 static int sensor_task_lock(struct i2c_client *client, int lock)
1242 #if CONFIG_SENSOR_I2C_NOSCHED
1244 struct sensor *sensor = to_sensor(client);
1247 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1248 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1249 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1253 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1254 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1255 goto sensor_task_lock_err;
1260 atomic_add(1, &sensor->tasklock_cnt);
1262 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1263 atomic_sub(1, &sensor->tasklock_cnt);
1265 if (atomic_read(&sensor->tasklock_cnt) == 0)
1270 sensor_task_lock_err:
1278 /* sensor register write */
1279 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1283 struct i2c_msg msg[1];
1286 buf[1] = reg & 0xFF;
1289 msg->addr = client->addr;
1290 msg->flags = client->flags;
1292 msg->len = sizeof(buf);
1293 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1294 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1299 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1300 err = i2c_transfer(client->adapter, msg, 1);
1305 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1313 /* sensor register read */
1314 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1318 struct i2c_msg msg[2];
1321 buf[1] = reg & 0xFF;
1323 msg[0].addr = client->addr;
1324 msg[0].flags = client->flags;
1326 msg[0].len = sizeof(buf);
1327 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1328 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1330 msg[1].addr = client->addr;
1331 msg[1].flags = client->flags|I2C_M_RD;
1334 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1335 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1339 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1340 err = i2c_transfer(client->adapter, msg, 2);
1346 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1354 /* write a array of registers */
1355 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1359 #if CONFIG_SENSOR_I2C_RDWRCHK
1364 if (sensor_task_lock(client, 1) < 0)
1365 goto sensor_write_array_end;
1367 while (regarray[i].reg != 0)
1369 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1373 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1377 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1379 goto sensor_write_array_end;
1382 #if CONFIG_SENSOR_I2C_RDWRCHK
1383 sensor_read(client, regarray[i].reg, &valchk);
1384 if (valchk != regarray[i].val)
1385 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1391 sensor_write_array_end:
1392 sensor_task_lock(client,0);
1395 #if CONFIG_SENSOR_I2C_RDWRCHK
1396 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1404 while (regarray[i].reg != 0)
1406 sensor_read(client, regarray[i].reg, &valchk);
1407 if (valchk != regarray[i].val)
1408 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1415 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1417 struct soc_camera_link *icl = to_soc_camera_link(icd);
1420 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1423 case Sensor_PowerDown:
1425 if (icl->powerdown) {
1426 ret = icl->powerdown(icd->pdev, on);
1427 if (ret == RK29_CAM_IO_SUCCESS) {
1431 icl->reset(icd->pdev);
1433 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1435 goto sensor_power_end;
1442 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1443 struct sensor *sensor = to_sensor(client);
1445 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1446 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1448 //flash off after 2 secs
1449 hrtimer_cancel(&(flash_off_timer.timer));
1450 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1457 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1465 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1466 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1467 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1468 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1472 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1474 struct i2c_client *client = v4l2_get_subdevdata(sd);
1475 struct soc_camera_device *icd = client->dev.platform_data;
1476 struct sensor *sensor = to_sensor(client);
1477 const struct v4l2_queryctrl *qctrl;
1478 const struct sensor_datafmt *fmt;
1482 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1484 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1486 goto sensor_INIT_ERR;
1490 if (sensor_task_lock(client,1)<0)
1491 goto sensor_INIT_ERR;
1493 ret = sensor_write(client, 0x3021, 0x61);
1496 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1498 goto sensor_INIT_ERR;
1501 mdelay(5); //delay 5 microseconds
1502 /* check if it is an sensor sensor */
1503 ret = sensor_read(client, 0x307e, &value);
1505 SENSOR_TR("read chip id high byte failed\n");
1507 goto sensor_INIT_ERR;
1510 pid |= (value << 8);
1512 ret = sensor_read(client, 0x307f, &value);
1514 SENSOR_TR("read chip id low byte failed\n");
1516 goto sensor_INIT_ERR;
1519 pid |= (value & 0xff);
1520 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1522 if (pid == SENSOR_ID) {
1523 sensor->model = SENSOR_V4L2_IDENT;
1525 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1527 goto sensor_INIT_ERR;
1531 ret = sensor_write_array(client, sensor_init_data);
1534 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1535 goto sensor_INIT_ERR;
1537 sensor_task_lock(client,0);
1539 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1540 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1542 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1544 goto sensor_INIT_ERR;
1546 sensor->info_priv.fmt = *fmt;
1548 /* sensor sensor information for initialization */
1549 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1551 sensor->info_priv.whiteBalance = qctrl->default_value;
1552 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1554 sensor->info_priv.brightness = qctrl->default_value;
1555 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1557 sensor->info_priv.effect = qctrl->default_value;
1558 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1560 sensor->info_priv.exposure = qctrl->default_value;
1562 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1564 sensor->info_priv.saturation = qctrl->default_value;
1565 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1567 sensor->info_priv.contrast = qctrl->default_value;
1568 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1570 sensor->info_priv.mirror = qctrl->default_value;
1571 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1573 sensor->info_priv.flip = qctrl->default_value;
1574 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1576 sensor->info_priv.scene = qctrl->default_value;
1577 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1579 sensor->info_priv.digitalzoom = qctrl->default_value;
1581 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1582 #if CONFIG_SENSOR_Focus
1584 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1586 sensor->info_priv.focus = qctrl->default_value;
1589 #if CONFIG_SENSOR_Flash
1590 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1592 sensor->info_priv.flash = qctrl->default_value;
1593 flash_off_timer.icd = icd;
1594 flash_off_timer.timer.function = flash_off_func;
1597 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);
1598 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1601 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1602 sensor_task_lock(client,0);
1603 sensor_deactivate(client);
1607 static int sensor_deactivate(struct i2c_client *client)
1609 struct soc_camera_device *icd = client->dev.platform_data;
1610 struct sensor *sensor = to_sensor(client);
1611 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1613 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1614 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1617 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1618 icd->user_width = SENSOR_INIT_WIDTH;
1619 icd->user_height = SENSOR_INIT_HEIGHT;
1620 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1625 static struct reginfo sensor_power_down_sequence[]=
1633 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1636 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1638 if (pm_msg.event == PM_EVENT_SUSPEND) {
1639 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1640 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1642 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1645 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1647 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1652 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1658 static int sensor_resume(struct soc_camera_device *icd)
1662 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1664 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1668 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1674 static int sensor_set_bus_param(struct soc_camera_device *icd,
1675 unsigned long flags)
1681 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1683 struct soc_camera_link *icl = to_soc_camera_link(icd);
1684 unsigned long flags = SENSOR_BUS_PARAM;
1686 return soc_camera_apply_sensor_flags(icl, flags);
1689 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1691 struct i2c_client *client = v4l2_get_subdevdata(sd);
1692 struct soc_camera_device *icd = client->dev.platform_data;
1693 struct sensor *sensor = to_sensor(client);
1695 mf->width = icd->user_width;
1696 mf->height = icd->user_height;
1697 mf->code = sensor->info_priv.fmt.code;
1698 mf->colorspace = sensor->info_priv.fmt.colorspace;
1699 mf->field = V4L2_FIELD_NONE;
1703 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1707 if ((mf->width == 1024) && (mf->height == 768)) {
1709 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1711 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1713 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1715 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1720 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1724 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1728 if ((mf->width == 1280) && (mf->height == 720)) {
1730 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1735 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1738 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1740 struct i2c_client *client = v4l2_get_subdevdata(sd);
1741 const struct sensor_datafmt *fmt;
1742 struct sensor *sensor = to_sensor(client);
1743 struct reginfo *winseqe_set_addr=NULL;
1744 int ret=0, set_w,set_h;
1748 //turn on scaler for preivew
1749 sensor_read(client ,0x3201, ®_1);
1750 sensor_write(client, 0x3201, (reg_1|0x40) );
1752 sensor_read(client ,0x32f1, ®);
1753 sensor_write(client, 0x32f1, (reg|0x10) );
1755 #if 0 //preview_fastmode
1756 u16 AE_reg, AGC_reg;
1757 u8 temp_reg12,temp_reg13
1758 // turn off AE for preview
1759 sensor_read(client ,0x3201, &AE_reg);
1760 sensor_write(client, 0x3201, (AE_reg|0x20) );
1761 // turn off AGC for preview
1762 sensor_read(client ,0x32bb, &AGC_reg);
1763 sensor_write(client, 0x32bb, (AGC_reg|0x01) );
1765 sensor_read(client, 0x3012, &temp_reg12);
1766 sensor_read(client, 0x3013, &temp_reg13);
1767 shutter = (temp_reg13 & 0x00FF) | (temp_reg12 << 8);
1769 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1770 ARRAY_SIZE(sensor_colour_fmts));
1773 goto sensor_s_fmt_end;
1776 if (sensor->info_priv.fmt.code != mf->code) {
1779 case V4L2_MBUS_FMT_YUYV8_2X8:
1781 winseqe_set_addr = sensor_ClrFmt_YUYV;
1784 case V4L2_MBUS_FMT_UYVY8_2X8:
1786 winseqe_set_addr = sensor_ClrFmt_UYVY;
1792 if (winseqe_set_addr != NULL) {
1793 sensor_write_array(client, winseqe_set_addr);
1794 sensor->info_priv.fmt.code = mf->code;
1795 sensor->info_priv.fmt.colorspace= mf->colorspace;
1796 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1798 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1805 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1807 winseqe_set_addr = sensor_qcif;
1811 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1813 winseqe_set_addr = sensor_qvga;
1817 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1819 winseqe_set_addr = sensor_cif;
1823 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1825 winseqe_set_addr = sensor_vga;
1829 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1831 winseqe_set_addr = sensor_svga;
1835 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1837 winseqe_set_addr = sensor_sxga;
1841 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1843 winseqe_set_addr = sensor_uxga;
1849 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1850 set_w = SENSOR_INIT_WIDTH;
1851 set_h = SENSOR_INIT_HEIGHT;
1852 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1855 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1856 #if CONFIG_SENSOR_Flash
1857 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1858 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1859 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1860 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1862 } else { /* ddl@rock-chips.com : Video */
1863 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1864 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1865 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1869 ret |= sensor_write_array(client, winseqe_set_addr);
1871 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1872 #if CONFIG_SENSOR_Flash
1873 if (sensor_fmt_capturechk(sd,mf) == true) {
1874 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1875 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1876 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1880 goto sensor_s_fmt_end;
1883 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1885 if ((set_w <= 640) && (set_h <= 480))
1892 sensor_read(client ,0x32f1, ®);
1893 sensor_write(client, 0x32f1, (reg&(~0x10)) );
1894 if ((set_w <= 1600) && (set_h <= 1200))
1896 //turn off scaler for UXGA capture
1897 sensor_read(client ,0x3201, ®_1);
1898 sensor_write(client, 0x3201, (reg_1&(~0x40)) );
1900 #if 0 //preview_fastmode
1902 sensor_read(client ,0x3201, &AE_reg);
1903 sensor_write(client, 0x3201, (AE_reg&(~0x20)) );
1905 sensor_read(client ,0x32bb, &AGC_reg);
1906 sensor_write(client, 0x32bb, (AGC_reg&(~0x01)) );
1907 if ((set_w <= 800) && (set_h <= 600))
1909 shutter = shutter*1984/2434;
1911 else if ((set_w <= 2434) && (set_h <= 1024))
1913 shutter = shutter*1984/2434;
1915 else if ((set_w <= 1600) && (set_h <= 1200))
1917 shutter = shutter*1984/2434;
1923 sensor_write(client, 0x3012, sizeof((shutter >> 8) & 0xff) );
1924 sensor_write(client, 0x3013, sizeof(shutter & 0xFF) );
1929 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1933 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1943 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1945 struct i2c_client *client = v4l2_get_subdevdata(sd);
1946 struct sensor *sensor = to_sensor(client);
1947 const struct sensor_datafmt *fmt;
1950 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1951 ARRAY_SIZE(sensor_colour_fmts));
1953 fmt = &sensor->info_priv.fmt;
1954 mf->code = fmt->code;
1957 if (mf->height > SENSOR_MAX_HEIGHT)
1958 mf->height = SENSOR_MAX_HEIGHT;
1959 else if (mf->height < SENSOR_MIN_HEIGHT)
1960 mf->height = SENSOR_MIN_HEIGHT;
1962 if (mf->width > SENSOR_MAX_WIDTH)
1963 mf->width = SENSOR_MAX_WIDTH;
1964 else if (mf->width < SENSOR_MIN_WIDTH)
1965 mf->width = SENSOR_MIN_WIDTH;
1967 mf->colorspace = fmt->colorspace;
1968 /*not support 720p video*/
1969 if(mf->height == 720 && mf->width == 1280){
1976 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1978 struct i2c_client *client = v4l2_get_subdevdata(sd);
1980 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1983 if (id->match.addr != client->addr)
1986 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1991 #if CONFIG_SENSOR_Brightness
1992 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1994 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1996 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1998 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2000 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2002 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2005 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2009 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2013 #if CONFIG_SENSOR_Effect
2014 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2016 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2018 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2020 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2022 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2024 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2027 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2031 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2035 #if CONFIG_SENSOR_Exposure
2036 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2038 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2040 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2042 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2044 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2046 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2049 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2053 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2057 #if CONFIG_SENSOR_Saturation
2058 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2060 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2062 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2064 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2066 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2068 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2071 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2075 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2079 #if CONFIG_SENSOR_Contrast
2080 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2082 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2084 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2086 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2088 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2090 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2093 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2097 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2101 #if CONFIG_SENSOR_Mirror
2102 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2104 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2106 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2108 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2110 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2112 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2115 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2119 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2123 #if CONFIG_SENSOR_Flip
2124 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2126 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2128 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2130 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2132 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2134 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2137 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2141 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2145 #if CONFIG_SENSOR_Scene
2146 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2148 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2150 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2152 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2154 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2156 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2159 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2163 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2167 #if CONFIG_SENSOR_WhiteBalance
2168 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2170 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2172 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2174 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2176 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2178 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2181 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2185 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2189 #if CONFIG_SENSOR_DigitalZoom
2190 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2192 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2193 struct sensor *sensor = to_sensor(client);
2194 const struct v4l2_queryctrl *qctrl_info;
2195 int digitalzoom_cur, digitalzoom_total;
2197 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2201 digitalzoom_cur = sensor->info_priv.digitalzoom;
2202 digitalzoom_total = qctrl_info->maximum;
2204 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2206 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2210 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2212 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2216 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2218 value = digitalzoom_total - digitalzoom_cur;
2221 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2223 value = 0 - digitalzoom_cur;
2226 digitalzoom_cur += value;
2228 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2230 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2232 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2235 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2242 #if CONFIG_SENSOR_Flash
2243 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2245 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2246 if (value == 3) { /* ddl@rock-chips.com: torch */
2247 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2249 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2251 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2255 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2260 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2262 struct i2c_client *client = v4l2_get_subdevdata(sd);
2263 struct sensor *sensor = to_sensor(client);
2264 const struct v4l2_queryctrl *qctrl;
2266 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2270 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2276 case V4L2_CID_BRIGHTNESS:
2278 ctrl->value = sensor->info_priv.brightness;
2281 case V4L2_CID_SATURATION:
2283 ctrl->value = sensor->info_priv.saturation;
2286 case V4L2_CID_CONTRAST:
2288 ctrl->value = sensor->info_priv.contrast;
2291 case V4L2_CID_DO_WHITE_BALANCE:
2293 ctrl->value = sensor->info_priv.whiteBalance;
2296 case V4L2_CID_EXPOSURE:
2298 ctrl->value = sensor->info_priv.exposure;
2301 case V4L2_CID_HFLIP:
2303 ctrl->value = sensor->info_priv.mirror;
2306 case V4L2_CID_VFLIP:
2308 ctrl->value = sensor->info_priv.flip;
2319 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2321 struct i2c_client *client = v4l2_get_subdevdata(sd);
2322 struct sensor *sensor = to_sensor(client);
2323 struct soc_camera_device *icd = client->dev.platform_data;
2324 const struct v4l2_queryctrl *qctrl;
2327 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2331 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2337 #if CONFIG_SENSOR_Brightness
2338 case V4L2_CID_BRIGHTNESS:
2340 if (ctrl->value != sensor->info_priv.brightness)
2342 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2346 sensor->info_priv.brightness = ctrl->value;
2351 #if CONFIG_SENSOR_Exposure
2352 case V4L2_CID_EXPOSURE:
2354 if (ctrl->value != sensor->info_priv.exposure)
2356 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2360 sensor->info_priv.exposure = ctrl->value;
2365 #if CONFIG_SENSOR_Saturation
2366 case V4L2_CID_SATURATION:
2368 if (ctrl->value != sensor->info_priv.saturation)
2370 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2374 sensor->info_priv.saturation = ctrl->value;
2379 #if CONFIG_SENSOR_Contrast
2380 case V4L2_CID_CONTRAST:
2382 if (ctrl->value != sensor->info_priv.contrast)
2384 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2388 sensor->info_priv.contrast = ctrl->value;
2393 #if CONFIG_SENSOR_WhiteBalance
2394 case V4L2_CID_DO_WHITE_BALANCE:
2396 if (ctrl->value != sensor->info_priv.whiteBalance)
2398 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2402 sensor->info_priv.whiteBalance = ctrl->value;
2407 #if CONFIG_SENSOR_Mirror
2408 case V4L2_CID_HFLIP:
2410 if (ctrl->value != sensor->info_priv.mirror)
2412 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2414 sensor->info_priv.mirror = ctrl->value;
2419 #if CONFIG_SENSOR_Flip
2420 case V4L2_CID_VFLIP:
2422 if (ctrl->value != sensor->info_priv.flip)
2424 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2426 sensor->info_priv.flip = ctrl->value;
2437 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2439 const struct v4l2_queryctrl *qctrl;
2440 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2441 struct sensor *sensor = to_sensor(client);
2443 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2447 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2451 switch (ext_ctrl->id)
2453 case V4L2_CID_SCENE:
2455 ext_ctrl->value = sensor->info_priv.scene;
2458 case V4L2_CID_EFFECT:
2460 ext_ctrl->value = sensor->info_priv.effect;
2463 case V4L2_CID_ZOOM_ABSOLUTE:
2465 ext_ctrl->value = sensor->info_priv.digitalzoom;
2468 case V4L2_CID_ZOOM_RELATIVE:
2472 case V4L2_CID_FOCUS_ABSOLUTE:
2474 ext_ctrl->value = sensor->info_priv.focus;
2477 case V4L2_CID_FOCUS_RELATIVE:
2481 case V4L2_CID_FLASH:
2483 ext_ctrl->value = sensor->info_priv.flash;
2491 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2493 const struct v4l2_queryctrl *qctrl;
2494 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2495 struct sensor *sensor = to_sensor(client);
2498 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2502 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2507 switch (ext_ctrl->id)
2509 #if CONFIG_SENSOR_Scene
2510 case V4L2_CID_SCENE:
2512 if (ext_ctrl->value != sensor->info_priv.scene)
2514 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2516 sensor->info_priv.scene = ext_ctrl->value;
2521 #if CONFIG_SENSOR_Effect
2522 case V4L2_CID_EFFECT:
2524 if (ext_ctrl->value != sensor->info_priv.effect)
2526 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2528 sensor->info_priv.effect= ext_ctrl->value;
2533 #if CONFIG_SENSOR_DigitalZoom
2534 case V4L2_CID_ZOOM_ABSOLUTE:
2536 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2539 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2541 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2543 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2545 sensor->info_priv.digitalzoom += val_offset;
2547 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2552 case V4L2_CID_ZOOM_RELATIVE:
2554 if (ext_ctrl->value)
2556 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2558 sensor->info_priv.digitalzoom += ext_ctrl->value;
2560 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2565 #if CONFIG_SENSOR_Focus
2566 case V4L2_CID_FOCUS_ABSOLUTE:
2568 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2571 if (ext_ctrl->value != sensor->info_priv.focus)
2573 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2575 sensor->info_priv.focus += val_offset;
2580 case V4L2_CID_FOCUS_RELATIVE:
2582 if (ext_ctrl->value)
2584 sensor->info_priv.focus += ext_ctrl->value;
2586 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2591 #if CONFIG_SENSOR_Flash
2592 case V4L2_CID_FLASH:
2594 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2596 sensor->info_priv.flash = ext_ctrl->value;
2598 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2609 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2611 struct i2c_client *client = v4l2_get_subdevdata(sd);
2612 struct soc_camera_device *icd = client->dev.platform_data;
2613 int i, error_cnt=0, error_idx=-1;
2616 for (i=0; i<ext_ctrl->count; i++) {
2617 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2624 error_idx = ext_ctrl->count;
2626 if (error_idx != -1) {
2627 ext_ctrl->error_idx = error_idx;
2634 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2636 struct i2c_client *client = v4l2_get_subdevdata(sd);
2637 struct soc_camera_device *icd = client->dev.platform_data;
2638 int i, error_cnt=0, error_idx=-1;
2641 for (i=0; i<ext_ctrl->count; i++) {
2642 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2649 error_idx = ext_ctrl->count;
2651 if (error_idx != -1) {
2652 ext_ctrl->error_idx = error_idx;
2659 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2660 * this wasn't our capture interface, so, we wait for the right one */
2661 static int sensor_video_probe(struct soc_camera_device *icd,
2662 struct i2c_client *client)
2666 struct sensor *sensor = to_sensor(client);
2668 /* We must have a parent by now. And it cannot be a wrong one.
2669 * So this entire test is completely redundant. */
2670 if (!icd->dev.parent ||
2671 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2674 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2676 goto sensor_video_probe_err;
2680 ret = sensor_write(client, 0x3021, 0x61);
2682 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2684 goto sensor_video_probe_err;
2686 mdelay(5); //delay 5 microseconds
2688 /* check if it is an sensor sensor */
2689 ret = sensor_read(client, 0x307e, &value);
2691 SENSOR_TR("read chip id high byte failed\n");
2693 goto sensor_video_probe_err;
2696 pid |= (value << 8);
2698 ret = sensor_read(client, 0x307f, &value);
2700 SENSOR_TR("read chip id low byte failed\n");
2702 goto sensor_video_probe_err;
2705 pid |= (value & 0xff);
2706 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2707 if (pid == SENSOR_ID) {
2708 sensor->model = SENSOR_V4L2_IDENT;
2710 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2712 goto sensor_video_probe_err;
2717 sensor_video_probe_err:
2721 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2723 struct i2c_client *client = v4l2_get_subdevdata(sd);
2724 struct soc_camera_device *icd = client->dev.platform_data;
2725 struct sensor *sensor = to_sensor(client);
2727 #if CONFIG_SENSOR_Flash
2731 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2734 case RK29_CAM_SUBDEV_DEACTIVATE:
2736 sensor_deactivate(client);
2740 case RK29_CAM_SUBDEV_IOREQUEST:
2742 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2743 if (sensor->sensor_io_request != NULL) {
2744 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2745 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2746 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2747 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2748 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2749 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2752 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2754 goto sensor_ioctl_end;
2756 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2758 #if CONFIG_SENSOR_Flash
2759 if (sensor->sensor_gpio_res) {
2760 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2761 for (i = 0; i < icd->ops->num_controls; i++) {
2762 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2763 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2764 sensor_controls[i].id=0xffff;
2767 sensor->info_priv.flash = 0xff;
2768 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2769 }else{ //two cameras are the same,need to deal diffrently ,zyc
2770 for (i = 0; i < icd->ops->num_controls; i++) {
2771 if(0xffff == icd->ops->controls[i].id){
2772 sensor_controls[i].id=V4L2_CID_FLASH;
2782 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2790 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2791 enum v4l2_mbus_pixelcode *code)
2793 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2796 *code = sensor_colour_fmts[index].code;
2799 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2800 .init = sensor_init,
2801 .g_ctrl = sensor_g_control,
2802 .s_ctrl = sensor_s_control,
2803 .g_ext_ctrls = sensor_g_ext_controls,
2804 .s_ext_ctrls = sensor_s_ext_controls,
2805 .g_chip_ident = sensor_g_chip_ident,
2806 .ioctl = sensor_ioctl,
2809 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2810 .s_mbus_fmt = sensor_s_fmt,
2811 .g_mbus_fmt = sensor_g_fmt,
2812 .try_mbus_fmt = sensor_try_fmt,
2813 .enum_mbus_fmt = sensor_enum_fmt,
2816 static struct v4l2_subdev_ops sensor_subdev_ops = {
2817 .core = &sensor_subdev_core_ops,
2818 .video = &sensor_subdev_video_ops,
2821 static int sensor_probe(struct i2c_client *client,
2822 const struct i2c_device_id *did)
2824 struct sensor *sensor;
2825 struct soc_camera_device *icd = client->dev.platform_data;
2826 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2827 struct soc_camera_link *icl;
2830 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2832 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2836 icl = to_soc_camera_link(icd);
2838 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2842 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2843 dev_warn(&adapter->dev,
2844 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2848 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2852 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2854 /* Second stage probe - when a capture adapter is there */
2855 icd->ops = &sensor_ops;
2857 sensor->info_priv.fmt = sensor_colour_fmts[0];
2859 #if CONFIG_SENSOR_I2C_NOSCHED
2860 atomic_set(&sensor->tasklock_cnt,0);
2863 ret = sensor_video_probe(icd, client);
2866 i2c_set_clientdata(client, NULL);
2870 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2871 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2875 static int sensor_remove(struct i2c_client *client)
2877 struct sensor *sensor = to_sensor(client);
2878 struct soc_camera_device *icd = client->dev.platform_data;
2881 i2c_set_clientdata(client, NULL);
2882 client->driver = NULL;
2888 static const struct i2c_device_id sensor_id[] = {
2889 {SENSOR_NAME_STRING(), 0 },
2892 MODULE_DEVICE_TABLE(i2c, sensor_id);
2894 static struct i2c_driver sensor_i2c_driver = {
2896 .name = SENSOR_NAME_STRING(),
2898 .probe = sensor_probe,
2899 .remove = sensor_remove,
2900 .id_table = sensor_id,
2903 static int __init sensor_mod_init(void)
2905 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2906 return i2c_add_driver(&sensor_i2c_driver);
2909 static void __exit sensor_mod_exit(void)
2911 i2c_del_driver(&sensor_i2c_driver);
2914 device_initcall_sync(sensor_mod_init);
2915 module_exit(sensor_mod_exit);
2917 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2918 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2919 MODULE_LICENSE("GPL");