2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_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(0, 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_GC2015
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_GC2015
48 #define SENSOR_ID 0x2005
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 1024 /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT 768
55 #define SENSOR_INIT_WINSEQADR sensor_svga
56 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
58 #define CONFIG_SENSOR_WhiteBalance 1
59 #define CONFIG_SENSOR_Brightness 0
60 #define CONFIG_SENSOR_Contrast 0
61 #define CONFIG_SENSOR_Saturation 0
62 #define CONFIG_SENSOR_Effect 1
63 #define CONFIG_SENSOR_Scene 1
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 100000 /* 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 /* init SVGA preview */
104 static struct reginfo sensor_init_data[] =
106 //{0xfe , 0x80}, //soft reset
107 {0x45 , 0x00}, //output_enable
108 //////////////////////////////////////////////////////////////////////////////////////
109 //////////////////////////preview capture switch /////////////////////////////////////
110 //////////////////////////////////////////////////////////////////////////////////////
112 {0x02 , 0x01}, //preview mode
113 {0x2a , 0xca}, //[7]col_binning , 0x[6]even skip
114 {0x48 , 0x40}, //manual_gain
116 ////////////////////////////////////////////////////////////////////////
117 ////////////////////////// preview LSC /////////////////////////////////
118 ////////////////////////////////////////////////////////////////////////
120 {0xb0 , 0x13}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
121 {0xb1 , 0x20}, //P_LSC_red_b2
122 {0xb2 , 0x20}, //P_LSC_green_b2
123 {0xb3 , 0x20}, //P_LSC_blue_b2
124 {0xb4 , 0x20}, //P_LSC_red_b4
125 {0xb5 , 0x20}, //P_LSC_green_b4
126 {0xb6 , 0x20}, //P_LSC_blue_b4
127 {0xb7 , 0x00}, //P_LSC_compensate_b2
128 {0xb8 , 0x80}, //P_LSC_row_center , 0x344 , 0x (0x600/2-100)/2=100
129 {0xb9 , 0x80}, //P_LSC_col_center , 0x544 , 0x (0x800/2-200)/2=100
131 ////////////////////////////////////////////////////////////////////////
132 ////////////////////////// capture LSC ///////////////////////////
133 ////////////////////////////////////////////////////////////////////////
134 {0xba , 0x13}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
135 {0xbb , 0x20}, //C_LSC_red_b2
136 {0xbc , 0x20}, //C_LSC_green_b2
137 {0xbd , 0x20}, //C_LSC_blue_b2
138 {0xbe , 0x20}, //C_LSC_red_b4
139 {0xbf , 0x20}, //C_LSC_green_b4
140 {0xc0 , 0x20}, //C_LSC_blue_b4
141 {0xc1 , 0x00}, //C_Lsc_compensate_b2
142 {0xc2 , 0x80}, //C_LSC_row_center , 0x344 , 0x (0x1200/2-344)/2=128
143 {0xc3 , 0x80}, //C_LSC_col_center , 0x544 , 0x (0x1600/2-544)/2=128
145 //GC2015_SET_PAGE0; //page0
147 ////////////////////////////////////////////////////////////////////////
148 ////////////////////////// analog configure ///////////////////////////
149 ////////////////////////////////////////////////////////////////////////
150 {0x29 , 0x00}, //cisctl mode 1
151 {0x2b , 0x06}, //cisctl mode 3
152 {0x32 , 0x0c}, //analog mode 1
153 {0x33 , 0x0f}, //analog mode 2
154 {0x34 , 0x00}, //[6:4]da_rsg
156 {0x35 , 0x88}, //Vref_A25
157 {0x37 , 0x16}, //Drive Current
159 /////////////////////////////////////////////////////////////////////
160 ///////////////////////////ISP Related//////////////////////////////
161 /////////////////////////////////////////////////////////////////////
163 {0x41 , 0x24}, //[5]skin_detectionenable[2]auto_gray , 0x[1]y_gamma
164 {0x42 , 0x76}, //[7]auto_sa[6]auto_ee[5]auto_dndd[4]auto_lsc[3]na[2]abs , 0x[1]awb
165 {0x4b , 0xea}, //[1]AWB_gain_mode , 0x1:atpregain0:atpostgain
166 {0x4d , 0x03}, //[1]inbf_en
167 {0x4f , 0x01}, //AEC enable
169 ////////////////////////////////////////////////////////////////////
170 /////////////////////////// BLK ///////////////////////////////////
171 ////////////////////////////////////////////////////////////////////
172 {0x63 , 0x77}, //BLK mode 1
173 {0x66 , 0x00}, //BLK global offset
175 {0x6e , 0x18}, //BLK offset submode,offset R
182 ////////////////////////////////////////////////////////////////////
183 /////////////////////////// DNDD ////////////////////////////////
184 ////////////////////////////////////////////////////////////////////
185 {0x80 , 0x07}, //[7]dn_inc_or_dec [4]zero_weight_mode[3]share [2]c_weight_adap [1]dn_lsc_mode [0]dn_b
186 {0x82 , 0x08}, //DN lilat b base
188 ////////////////////////////////////////////////////////////////////
189 /////////////////////////// EEINTP ////////////////////////////////
190 ////////////////////////////////////////////////////////////////////
196 /////////////////////////////////////////////////////////////////////
197 /////////////////////////// CC_t ///////////////////////////////
198 /////////////////////////////////////////////////////////////////////
209 /////////////////////////////////////////////////////////////////////
210 /////////////////////////// GAMMA ///////////////////////////////////
211 /////////////////////////////////////////////////////////////////////
231 /////////////////////////////////////////////////////////////////////
232 /////////////////////////// YCP_t ///////////////////////////////
233 /////////////////////////////////////////////////////////////////////
234 {0xd1 , 0x38}, //saturation
235 {0xd2 , 0x38}, //saturation
236 {0xde , 0x21}, //auto_gray
238 ////////////////////////////////////////////////////////////////////
239 /////////////////////////// ASDE ////////////////////////////////
240 ////////////////////////////////////////////////////////////////////
245 //GC2015_SET_PAGE1; //page1
246 ////////////////////////////////////////////////////////////////////
247 /////////////////////////// AEC ////////////////////////////////
248 ////////////////////////////////////////////////////////////////////
249 {0x10 , 0x45}, //AEC mode 1
250 {0x11 , 0x32}, //[7]fix target
255 {0x21 , 0xc0}, //max_post_gain
256 {0x22 , 0x40}, //max_pre_gain
257 {0x2d , 0x06}, //P_N_AEC_exp_level_1[12:8]
258 {0x2e , 0x00}, //P_N_AEC_exp_level_1[7:0]
260 {0x33 , 0x00}, //[6:5]max_exp_level [4:0]min_exp_level
262 ////////////////////////////////////////////////////////////////////
263 /////////////////////////// AWB ////////////////////////////////
264 ////////////////////////////////////////////////////////////////////
265 {0x57 , 0x40}, //number limit
267 {0x5c , 0x35}, //show mode,close dark_mode
268 {0x5e , 0x29}, //close color temp
273 ////////////////////////////////////////////////////////////////////
274 /////////////////////////// ABS ////////////////////////////////
275 ////////////////////////////////////////////////////////////////////
278 {0x83 , 0x00}, //ABS Y stretch limit
282 //////////////////////////////////////////////////////////////////////////////////////
283 ///////////////////////////// Crop //////////////////////////////////////////////////
284 //////////////////////////////////////////////////////////////////////////////////////
285 {0x50 , 0x01},//out window
295 ////////////////////////////////////////////////////////////////////
296 /////////////////////////// OUT ////////////////////////////////
297 ////////////////////////////////////////////////////////////////////
298 {0x44 , 0xa0}, //YUV sequence
299 {0x45 , 0x0f}, //output enable
300 {0x46 , 0x02}, //sync mode
303 /* 1600X1200 UXGA capture */
304 static struct reginfo sensor_uxga[] =
306 {0x45 , 0x0f}, //output enable
311 static struct reginfo sensor_sxga[] =
315 static struct reginfo sensor_xga[] =
319 /* 800X600 SVGA,30fps*/
320 static struct reginfo sensor_svga[] =
322 {0x45 , 0x0f}, //output enable
327 static struct reginfo sensor_vga[] =
329 {0x45 , 0x0f}, //output enable
334 static struct reginfo sensor_cif[] =
338 static struct reginfo sensor_qvga[] =
342 static struct reginfo sensor_qcif[] =
346 static struct reginfo ov2655_qqvga[] =
390 static struct reginfo ov2655_Sharpness_auto[] =
395 static struct reginfo ov2655_Sharpness1[] =
401 static struct reginfo ov2655_Sharpness2[][3] =
408 static struct reginfo ov2655_Sharpness3[] =
414 static struct reginfo ov2655_Sharpness4[]=
421 static struct reginfo ov2655_Sharpness5[] =
429 static struct reginfo sensor_ClrFmt_YUYV[]=
435 static struct reginfo sensor_ClrFmt_UYVY[]=
441 #if CONFIG_SENSOR_WhiteBalance
442 static struct reginfo sensor_WhiteB_Auto[]=
447 /* Cloudy Colour Temperature : 6500K - 8000K */
448 static struct reginfo sensor_WhiteB_Cloudy[]=
453 /* ClearDay Colour Temperature : 5000K - 6500K */
454 static struct reginfo sensor_WhiteB_ClearDay[]=
460 /* Office Colour Temperature : 3500K - 5000K */
461 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
468 /* Home Colour Temperature : 2500K - 3500K */
469 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
475 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
476 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
480 #if CONFIG_SENSOR_Brightness
481 static struct reginfo sensor_Brightness0[]=
488 static struct reginfo sensor_Brightness1[]=
495 static struct reginfo sensor_Brightness2[]=
502 static struct reginfo sensor_Brightness3[]=
509 static struct reginfo sensor_Brightness4[]=
516 static struct reginfo sensor_Brightness5[]=
522 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
523 sensor_Brightness4, sensor_Brightness5,NULL,
528 #if CONFIG_SENSOR_Effect
529 static struct reginfo sensor_Effect_Normal[] =
535 static struct reginfo sensor_Effect_WandB[] =
541 static struct reginfo sensor_Effect_Sepia[] =
547 static struct reginfo sensor_Effect_Negative[] =
553 static struct reginfo sensor_Effect_Bluish[] =
560 static struct reginfo sensor_Effect_Green[] =
566 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
567 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
570 #if CONFIG_SENSOR_Exposure
571 static struct reginfo sensor_Exposure0[]=
577 static struct reginfo sensor_Exposure1[]=
584 static struct reginfo sensor_Exposure2[]=
591 static struct reginfo sensor_Exposure3[]=
598 static struct reginfo sensor_Exposure4[]=
605 static struct reginfo sensor_Exposure5[]=
612 static struct reginfo sensor_Exposure6[]=
619 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
620 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
623 #if CONFIG_SENSOR_Saturation
624 static struct reginfo sensor_Saturation0[]=
630 static struct reginfo sensor_Saturation1[]=
636 static struct reginfo sensor_Saturation2[]=
641 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
644 #if CONFIG_SENSOR_Contrast
645 static struct reginfo sensor_Contrast0[]=
652 static struct reginfo sensor_Contrast1[]=
659 static struct reginfo sensor_Contrast2[]=
666 static struct reginfo sensor_Contrast3[]=
673 static struct reginfo sensor_Contrast4[]=
681 static struct reginfo sensor_Contrast5[]=
688 static struct reginfo sensor_Contrast6[]=
694 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
695 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
699 #if CONFIG_SENSOR_Mirror
700 static struct reginfo sensor_MirrorOn[]=
706 static struct reginfo sensor_MirrorOff[]=
711 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
713 #if CONFIG_SENSOR_Flip
714 static struct reginfo sensor_FlipOn[]=
720 static struct reginfo sensor_FlipOff[]=
725 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
728 #if CONFIG_SENSOR_Scene
729 static struct reginfo sensor_SceneAuto[] =
731 #if 0 /* ddl@rock-chips.com : */
743 static struct reginfo sensor_SceneNight[] =
746 //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
750 //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
766 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
769 #if CONFIG_SENSOR_DigitalZoom
770 static struct reginfo sensor_Zoom0[] =
775 static struct reginfo sensor_Zoom1[] =
780 static struct reginfo sensor_Zoom2[] =
786 static struct reginfo sensor_Zoom3[] =
790 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
792 static const struct v4l2_querymenu sensor_menus[] =
794 #if CONFIG_SENSOR_WhiteBalance
795 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
796 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
797 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
800 #if CONFIG_SENSOR_Effect
801 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
802 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
803 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
806 #if CONFIG_SENSOR_Scene
807 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
810 #if CONFIG_SENSOR_Flash
811 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
812 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
816 static const struct v4l2_queryctrl sensor_controls[] =
818 #if CONFIG_SENSOR_WhiteBalance
820 .id = V4L2_CID_DO_WHITE_BALANCE,
821 .type = V4L2_CTRL_TYPE_MENU,
822 .name = "White Balance Control",
830 #if CONFIG_SENSOR_Brightness
832 .id = V4L2_CID_BRIGHTNESS,
833 .type = V4L2_CTRL_TYPE_INTEGER,
834 .name = "Brightness Control",
842 #if CONFIG_SENSOR_Effect
844 .id = V4L2_CID_EFFECT,
845 .type = V4L2_CTRL_TYPE_MENU,
846 .name = "Effect Control",
854 #if CONFIG_SENSOR_Exposure
856 .id = V4L2_CID_EXPOSURE,
857 .type = V4L2_CTRL_TYPE_INTEGER,
858 .name = "Exposure Control",
866 #if CONFIG_SENSOR_Saturation
868 .id = V4L2_CID_SATURATION,
869 .type = V4L2_CTRL_TYPE_INTEGER,
870 .name = "Saturation Control",
878 #if CONFIG_SENSOR_Contrast
880 .id = V4L2_CID_CONTRAST,
881 .type = V4L2_CTRL_TYPE_INTEGER,
882 .name = "Contrast Control",
890 #if CONFIG_SENSOR_Mirror
892 .id = V4L2_CID_HFLIP,
893 .type = V4L2_CTRL_TYPE_BOOLEAN,
894 .name = "Mirror Control",
902 #if CONFIG_SENSOR_Flip
904 .id = V4L2_CID_VFLIP,
905 .type = V4L2_CTRL_TYPE_BOOLEAN,
906 .name = "Flip Control",
914 #if CONFIG_SENSOR_Scene
916 .id = V4L2_CID_SCENE,
917 .type = V4L2_CTRL_TYPE_MENU,
918 .name = "Scene Control",
926 #if CONFIG_SENSOR_DigitalZoom
928 .id = V4L2_CID_ZOOM_RELATIVE,
929 .type = V4L2_CTRL_TYPE_INTEGER,
930 .name = "DigitalZoom Control",
936 .id = V4L2_CID_ZOOM_ABSOLUTE,
937 .type = V4L2_CTRL_TYPE_INTEGER,
938 .name = "DigitalZoom Control",
946 #if CONFIG_SENSOR_Focus
948 .id = V4L2_CID_FOCUS_RELATIVE,
949 .type = V4L2_CTRL_TYPE_INTEGER,
950 .name = "Focus Control",
956 .id = V4L2_CID_FOCUS_ABSOLUTE,
957 .type = V4L2_CTRL_TYPE_INTEGER,
958 .name = "Focus Control",
962 .default_value = 125,
966 #if CONFIG_SENSOR_Flash
968 .id = V4L2_CID_FLASH,
969 .type = V4L2_CTRL_TYPE_MENU,
970 .name = "Flash Control",
979 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
980 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
981 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
982 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
983 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
984 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
985 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
986 static int sensor_resume(struct soc_camera_device *icd);
987 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
988 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
989 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
990 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
991 static int sensor_deactivate(struct i2c_client *client);
993 static struct soc_camera_ops sensor_ops =
995 .suspend = sensor_suspend,
996 .resume = sensor_resume,
997 .set_bus_param = sensor_set_bus_param,
998 .query_bus_param = sensor_query_bus_param,
999 .controls = sensor_controls,
1000 .menus = sensor_menus,
1001 .num_controls = ARRAY_SIZE(sensor_controls),
1002 .num_menus = ARRAY_SIZE(sensor_menus),
1005 /* only one fixed colorspace per pixelcode */
1006 struct sensor_datafmt {
1007 enum v4l2_mbus_pixelcode code;
1008 enum v4l2_colorspace colorspace;
1011 /* Find a data format by a pixel code in an array */
1012 static const struct sensor_datafmt *sensor_find_datafmt(
1013 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1017 for (i = 0; i < n; i++)
1018 if (fmt[i].code == code)
1024 static const struct sensor_datafmt sensor_colour_fmts[] = {
1025 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1026 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1029 typedef struct sensor_info_priv_s
1043 unsigned char mirror; /* HFLIP */
1044 unsigned char flip; /* VFLIP */
1045 unsigned int winseqe_cur_addr;
1046 struct sensor_datafmt fmt;
1047 unsigned int funmodule_state;
1048 } sensor_info_priv_t;
1052 struct v4l2_subdev subdev;
1053 struct i2c_client *client;
1054 sensor_info_priv_t info_priv;
1055 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1056 #if CONFIG_SENSOR_I2C_NOSCHED
1057 atomic_t tasklock_cnt;
1059 struct rk29camera_platform_data *sensor_io_request;
1060 struct rk29camera_gpio_res *sensor_gpio_res;
1063 static struct sensor* to_sensor(const struct i2c_client *client)
1065 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1068 static int sensor_task_lock(struct i2c_client *client, int lock)
1070 #if CONFIG_SENSOR_I2C_NOSCHED
1072 struct sensor *sensor = to_sensor(client);
1075 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1076 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1077 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1081 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1082 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1083 goto sensor_task_lock_err;
1088 atomic_add(1, &sensor->tasklock_cnt);
1090 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1091 atomic_sub(1, &sensor->tasklock_cnt);
1093 if (atomic_read(&sensor->tasklock_cnt) == 0)
1099 sensor_task_lock_err:
1104 /* sensor register */
1105 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1109 ret = i2c_master_reg8_recv(client, reg, val, 1, CONFIG_SENSOR_I2C_SPEED);
1111 return (ret > 0)? 0 : ret;
1114 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1118 ret = i2c_master_reg8_send(client, reg, &val, 1, CONFIG_SENSOR_I2C_SPEED);
1120 return (ret > 0)? 0 : ret;
1123 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1127 struct i2c_msg msg[1];
1135 msg->addr = client->addr;
1136 msg->flags = client->flags;
1138 msg->len = sizeof(buf);
1139 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1140 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1145 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1146 err = i2c_transfer(client->adapter, msg, 1);
1151 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1159 /* sensor register read */
1160 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1164 struct i2c_msg msg[2];
1168 msg[0].addr = client->addr;
1169 msg[0].flags = client->flags;
1171 msg[0].len = sizeof(buf);
1172 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1173 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1175 msg[1].addr = client->addr;
1176 msg[1].flags = client->flags|I2C_M_RD;
1179 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1180 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1184 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1185 err = i2c_transfer(client->adapter, msg, 2);
1191 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1201 /* write a array of registers */
1202 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1206 #if CONFIG_SENSOR_I2C_RDWRCHK
1212 if (sensor_task_lock(client, 1) < 0)
1213 goto sensor_write_array_end;
1214 while (regarray[i].reg != 0)
1216 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1220 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1224 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1226 goto sensor_write_array_end;
1229 #if CONFIG_SENSOR_I2C_RDWRCHK
1231 sensor_read(client, regarray[i].reg, &valchk);
1232 if (valchk != regarray[i].val)
1233 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1239 sensor_write_array_end:
1240 sensor_task_lock(client,0);
1243 #if CONFIG_SENSOR_I2C_RDWRCHK
1244 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1252 while (regarray[i].reg != 0)
1254 sensor_read(client, regarray[i].reg, &valchk);
1255 if (valchk != regarray[i].val)
1256 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1263 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1265 struct soc_camera_link *icl = to_soc_camera_link(icd);
1268 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1271 case Sensor_PowerDown:
1273 if (icl->powerdown) {
1274 ret = icl->powerdown(icd->pdev, on);
1275 if (ret == RK29_CAM_IO_SUCCESS) {
1279 icl->reset(icd->pdev);
1281 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1283 goto sensor_power_end;
1290 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1291 struct sensor *sensor = to_sensor(client);
1293 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1294 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1300 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1307 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1309 struct i2c_client *client = sd->priv;
1310 struct soc_camera_device *icd = client->dev.platform_data;
1311 struct sensor *sensor = to_sensor(client);
1312 const struct v4l2_queryctrl *qctrl;
1313 const struct sensor_datafmt *fmt;
1317 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1319 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1321 goto sensor_INIT_ERR;
1325 if (sensor_task_lock(client,1)<0)
1326 goto sensor_INIT_ERR;
1327 ret = sensor_write(client, 0xfe, 0x80);
1330 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1332 goto sensor_INIT_ERR;
1335 mdelay(5); //delay 5 microseconds
1336 /* check if it is an sensor sensor */
1337 ret = sensor_read(client, 0x00, &value);
1339 SENSOR_TR("read chip id high byte failed\n");
1341 goto sensor_INIT_ERR;
1344 pid |= (value << 8);
1346 ret = sensor_read(client, 0x01, &value);
1348 SENSOR_TR("read chip id low byte failed\n");
1350 goto sensor_INIT_ERR;
1353 pid |= (value & 0xff);
1354 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1355 if (pid == SENSOR_ID) {
1356 sensor->model = SENSOR_V4L2_IDENT;
1358 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1360 goto sensor_INIT_ERR;
1363 ret = sensor_write_array(client, sensor_init_data);
1366 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1367 goto sensor_INIT_ERR;
1369 sensor_task_lock(client,0);
1371 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1372 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1374 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1376 goto sensor_INIT_ERR;
1378 sensor->info_priv.fmt = *fmt;
1380 /* sensor sensor information for initialization */
1381 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1383 sensor->info_priv.whiteBalance = qctrl->default_value;
1384 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1386 sensor->info_priv.brightness = qctrl->default_value;
1387 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1389 sensor->info_priv.effect = qctrl->default_value;
1390 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1392 sensor->info_priv.exposure = qctrl->default_value;
1394 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1396 sensor->info_priv.saturation = qctrl->default_value;
1397 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1399 sensor->info_priv.contrast = qctrl->default_value;
1400 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1402 sensor->info_priv.mirror = qctrl->default_value;
1403 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1405 sensor->info_priv.flip = qctrl->default_value;
1406 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1408 sensor->info_priv.scene = qctrl->default_value;
1409 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1411 sensor->info_priv.digitalzoom = qctrl->default_value;
1413 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1414 #if CONFIG_SENSOR_Focus
1416 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1418 sensor->info_priv.focus = qctrl->default_value;
1421 #if CONFIG_SENSOR_Flash
1422 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1424 sensor->info_priv.flash = qctrl->default_value;
1427 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);
1428 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1431 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1432 sensor_task_lock(client,0);
1433 sensor_deactivate(client);
1437 static int sensor_deactivate(struct i2c_client *client)
1439 struct soc_camera_device *icd = client->dev.platform_data;
1441 struct sensor *sensor = to_sensor(client);
1442 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1444 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1445 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1448 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1449 icd->user_width = SENSOR_INIT_WIDTH;
1450 icd->user_height = SENSOR_INIT_HEIGHT;
1451 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1456 static struct reginfo sensor_power_down_sequence[]=
1460 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1463 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1465 if (pm_msg.event == PM_EVENT_SUSPEND) {
1466 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1467 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1469 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1472 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1474 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1479 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1485 static int sensor_resume(struct soc_camera_device *icd)
1489 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1491 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1495 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1501 static int sensor_set_bus_param(struct soc_camera_device *icd,
1502 unsigned long flags)
1508 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1510 struct soc_camera_link *icl = to_soc_camera_link(icd);
1511 unsigned long flags = SENSOR_BUS_PARAM;
1513 return soc_camera_apply_sensor_flags(icl, flags);
1516 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1518 struct i2c_client *client = sd->priv;
1519 struct soc_camera_device *icd = client->dev.platform_data;
1520 struct sensor *sensor = to_sensor(client);
1522 mf->width = icd->user_width;
1523 mf->height = icd->user_height;
1524 mf->code = sensor->info_priv.fmt.code;
1525 mf->colorspace = sensor->info_priv.fmt.colorspace;
1526 mf->field = V4L2_FIELD_NONE;
1530 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1534 if ((mf->width == 1024) && (mf->height == 768)) {
1536 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1538 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1540 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1542 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1547 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1551 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1555 if ((mf->width == 1280) && (mf->height == 720)) {
1557 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1562 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1565 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1567 struct i2c_client *client = sd->priv;
1568 const struct sensor_datafmt *fmt;
1569 struct sensor *sensor = to_sensor(client);
1570 const struct v4l2_queryctrl *qctrl;
1571 struct soc_camera_device *icd = client->dev.platform_data;
1572 struct reginfo *winseqe_set_addr=NULL;
1573 int ret=0, set_w,set_h;
1575 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1576 ARRAY_SIZE(sensor_colour_fmts));
1579 goto sensor_s_fmt_end;
1582 if (sensor->info_priv.fmt.code != mf->code) {
1585 case V4L2_MBUS_FMT_YUYV8_2X8:
1587 winseqe_set_addr = sensor_ClrFmt_YUYV;
1590 case V4L2_MBUS_FMT_UYVY8_2X8:
1592 winseqe_set_addr = sensor_ClrFmt_UYVY;
1598 if (winseqe_set_addr != NULL) {
1599 sensor_write_array(client, winseqe_set_addr);
1600 sensor->info_priv.fmt.code = mf->code;
1601 sensor->info_priv.fmt.colorspace= mf->colorspace;
1602 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1604 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1611 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1613 winseqe_set_addr = sensor_qcif;
1617 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1619 winseqe_set_addr = sensor_qvga;
1623 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1625 winseqe_set_addr = sensor_cif;
1629 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1631 winseqe_set_addr = sensor_vga;
1635 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1637 winseqe_set_addr = sensor_svga;
1641 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1643 winseqe_set_addr = sensor_xga;
1647 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1649 winseqe_set_addr = sensor_sxga;
1653 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1655 winseqe_set_addr = sensor_uxga;
1661 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1662 set_w = SENSOR_INIT_WIDTH;
1663 set_h = SENSOR_INIT_HEIGHT;
1664 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1667 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1668 #if CONFIG_SENSOR_Flash
1669 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1670 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1671 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1672 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1674 } else { /* ddl@rock-chips.com : Video */
1675 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1676 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1677 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1681 ret |= sensor_write_array(client, winseqe_set_addr);
1683 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1684 #if CONFIG_SENSOR_Flash
1685 if (sensor_fmt_capturechk(sd,mf) == true) {
1686 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1687 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1688 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1692 goto sensor_s_fmt_end;
1695 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1697 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1698 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1699 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1700 if (sensor->info_priv.whiteBalance != 0) {
1701 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1702 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1704 sensor->info_priv.snap2preview = true;
1705 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1706 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1707 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1708 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1709 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1710 sensor->info_priv.video2preview = true;
1711 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1712 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1713 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1715 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1716 sensor->info_priv.video2preview = false;
1717 sensor->info_priv.snap2preview = false;
1719 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1723 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1733 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1735 struct i2c_client *client = sd->priv;
1736 struct sensor *sensor = to_sensor(client);
1737 const struct sensor_datafmt *fmt;
1740 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1741 ARRAY_SIZE(sensor_colour_fmts));
1743 fmt = &sensor->info_priv.fmt;
1744 mf->code = fmt->code;
1747 if (mf->height > SENSOR_MAX_HEIGHT)
1748 mf->height = SENSOR_MAX_HEIGHT;
1749 else if (mf->height < SENSOR_MIN_HEIGHT)
1750 mf->height = SENSOR_MIN_HEIGHT;
1752 if (mf->width > SENSOR_MAX_WIDTH)
1753 mf->width = SENSOR_MAX_WIDTH;
1754 else if (mf->width < SENSOR_MIN_WIDTH)
1755 mf->width = SENSOR_MIN_WIDTH;
1757 mf->colorspace = fmt->colorspace;
1762 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1764 struct i2c_client *client = sd->priv;
1766 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1769 if (id->match.addr != client->addr)
1772 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1777 #if CONFIG_SENSOR_Brightness
1778 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1780 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1782 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1784 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1786 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1788 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1791 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1795 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1799 #if CONFIG_SENSOR_Effect
1800 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1802 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1804 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1806 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1808 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1810 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1813 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1817 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1821 #if CONFIG_SENSOR_Exposure
1822 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1824 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1826 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1828 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1830 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1832 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1835 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1839 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1843 #if CONFIG_SENSOR_Saturation
1844 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1846 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1848 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1850 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1852 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1854 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1857 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1861 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1865 #if CONFIG_SENSOR_Contrast
1866 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1868 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1870 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1872 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1874 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1876 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1879 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1883 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1887 #if CONFIG_SENSOR_Mirror
1888 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1890 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1892 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1894 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1896 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1898 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1901 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1905 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1909 #if CONFIG_SENSOR_Flip
1910 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1912 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1914 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1916 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1918 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1920 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1923 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1927 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1931 #if CONFIG_SENSOR_Scene
1932 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1934 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1936 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1938 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1940 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1942 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1945 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1949 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1953 #if CONFIG_SENSOR_WhiteBalance
1954 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1956 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1958 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1960 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1962 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1964 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1967 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1971 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1975 #if CONFIG_SENSOR_DigitalZoom
1976 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
1978 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1979 struct sensor *sensor = to_sensor(client);
1980 const struct v4l2_queryctrl *qctrl_info;
1981 int digitalzoom_cur, digitalzoom_total;
1983 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1987 digitalzoom_cur = sensor->info_priv.digitalzoom;
1988 digitalzoom_total = qctrl_info->maximum;
1990 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
1992 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1996 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
1998 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2002 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2004 value = digitalzoom_total - digitalzoom_cur;
2007 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2009 value = 0 - digitalzoom_cur;
2012 digitalzoom_cur += value;
2014 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2016 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2018 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2021 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2028 #if CONFIG_SENSOR_Flash
2029 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2031 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2032 if (value == 3) { /* ddl@rock-chips.com: torch */
2033 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2035 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2037 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2041 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2046 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2048 struct i2c_client *client = sd->priv;
2049 struct sensor *sensor = to_sensor(client);
2050 const struct v4l2_queryctrl *qctrl;
2052 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2056 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2062 case V4L2_CID_BRIGHTNESS:
2064 ctrl->value = sensor->info_priv.brightness;
2067 case V4L2_CID_SATURATION:
2069 ctrl->value = sensor->info_priv.saturation;
2072 case V4L2_CID_CONTRAST:
2074 ctrl->value = sensor->info_priv.contrast;
2077 case V4L2_CID_DO_WHITE_BALANCE:
2079 ctrl->value = sensor->info_priv.whiteBalance;
2082 case V4L2_CID_EXPOSURE:
2084 ctrl->value = sensor->info_priv.exposure;
2087 case V4L2_CID_HFLIP:
2089 ctrl->value = sensor->info_priv.mirror;
2092 case V4L2_CID_VFLIP:
2094 ctrl->value = sensor->info_priv.flip;
2105 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2107 struct i2c_client *client = sd->priv;
2108 struct sensor *sensor = to_sensor(client);
2109 struct soc_camera_device *icd = client->dev.platform_data;
2110 const struct v4l2_queryctrl *qctrl;
2113 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2117 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2123 #if CONFIG_SENSOR_Brightness
2124 case V4L2_CID_BRIGHTNESS:
2126 if (ctrl->value != sensor->info_priv.brightness)
2128 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2132 sensor->info_priv.brightness = ctrl->value;
2137 #if CONFIG_SENSOR_Exposure
2138 case V4L2_CID_EXPOSURE:
2140 if (ctrl->value != sensor->info_priv.exposure)
2142 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2146 sensor->info_priv.exposure = ctrl->value;
2151 #if CONFIG_SENSOR_Saturation
2152 case V4L2_CID_SATURATION:
2154 if (ctrl->value != sensor->info_priv.saturation)
2156 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2160 sensor->info_priv.saturation = ctrl->value;
2165 #if CONFIG_SENSOR_Contrast
2166 case V4L2_CID_CONTRAST:
2168 if (ctrl->value != sensor->info_priv.contrast)
2170 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2174 sensor->info_priv.contrast = ctrl->value;
2179 #if CONFIG_SENSOR_WhiteBalance
2180 case V4L2_CID_DO_WHITE_BALANCE:
2182 if (ctrl->value != sensor->info_priv.whiteBalance)
2184 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2188 sensor->info_priv.whiteBalance = ctrl->value;
2193 #if CONFIG_SENSOR_Mirror
2194 case V4L2_CID_HFLIP:
2196 if (ctrl->value != sensor->info_priv.mirror)
2198 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2200 sensor->info_priv.mirror = ctrl->value;
2205 #if CONFIG_SENSOR_Flip
2206 case V4L2_CID_VFLIP:
2208 if (ctrl->value != sensor->info_priv.flip)
2210 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2212 sensor->info_priv.flip = ctrl->value;
2223 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2225 const struct v4l2_queryctrl *qctrl;
2226 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2227 struct sensor *sensor = to_sensor(client);
2229 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2233 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2237 switch (ext_ctrl->id)
2239 case V4L2_CID_SCENE:
2241 ext_ctrl->value = sensor->info_priv.scene;
2244 case V4L2_CID_EFFECT:
2246 ext_ctrl->value = sensor->info_priv.effect;
2249 case V4L2_CID_ZOOM_ABSOLUTE:
2251 ext_ctrl->value = sensor->info_priv.digitalzoom;
2254 case V4L2_CID_ZOOM_RELATIVE:
2258 case V4L2_CID_FOCUS_ABSOLUTE:
2260 ext_ctrl->value = sensor->info_priv.focus;
2263 case V4L2_CID_FOCUS_RELATIVE:
2267 case V4L2_CID_FLASH:
2269 ext_ctrl->value = sensor->info_priv.flash;
2277 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2279 const struct v4l2_queryctrl *qctrl;
2280 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2281 struct sensor *sensor = to_sensor(client);
2284 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2288 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2293 switch (ext_ctrl->id)
2295 #if CONFIG_SENSOR_Scene
2296 case V4L2_CID_SCENE:
2298 if (ext_ctrl->value != sensor->info_priv.scene)
2300 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2302 sensor->info_priv.scene = ext_ctrl->value;
2307 #if CONFIG_SENSOR_Effect
2308 case V4L2_CID_EFFECT:
2310 if (ext_ctrl->value != sensor->info_priv.effect)
2312 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2314 sensor->info_priv.effect= ext_ctrl->value;
2319 #if CONFIG_SENSOR_DigitalZoom
2320 case V4L2_CID_ZOOM_ABSOLUTE:
2322 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2325 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2327 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2329 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2331 sensor->info_priv.digitalzoom += val_offset;
2333 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2338 case V4L2_CID_ZOOM_RELATIVE:
2340 if (ext_ctrl->value)
2342 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2344 sensor->info_priv.digitalzoom += ext_ctrl->value;
2346 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2351 #if CONFIG_SENSOR_Focus
2352 case V4L2_CID_FOCUS_ABSOLUTE:
2354 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2357 if (ext_ctrl->value != sensor->info_priv.focus)
2359 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2361 sensor->info_priv.focus += val_offset;
2366 case V4L2_CID_FOCUS_RELATIVE:
2368 if (ext_ctrl->value)
2370 sensor->info_priv.focus += ext_ctrl->value;
2372 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2377 #if CONFIG_SENSOR_Flash
2378 case V4L2_CID_FLASH:
2380 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2382 sensor->info_priv.flash = ext_ctrl->value;
2384 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2395 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2397 struct i2c_client *client = sd->priv;
2398 struct soc_camera_device *icd = client->dev.platform_data;
2399 int i, error_cnt=0, error_idx=-1;
2402 for (i=0; i<ext_ctrl->count; i++) {
2403 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2410 error_idx = ext_ctrl->count;
2412 if (error_idx != -1) {
2413 ext_ctrl->error_idx = error_idx;
2420 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2422 struct i2c_client *client = sd->priv;
2423 struct soc_camera_device *icd = client->dev.platform_data;
2424 int i, error_cnt=0, error_idx=-1;
2427 for (i=0; i<ext_ctrl->count; i++) {
2428 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2435 error_idx = ext_ctrl->count;
2437 if (error_idx != -1) {
2438 ext_ctrl->error_idx = error_idx;
2445 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2446 * this wasn't our capture interface, so, we wait for the right one */
2447 static int sensor_video_probe(struct soc_camera_device *icd,
2448 struct i2c_client *client)
2452 struct sensor *sensor = to_sensor(client);
2454 /* We must have a parent by now. And it cannot be a wrong one.
2455 * So this entire test is completely redundant. */
2456 if (!icd->dev.parent ||
2457 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2460 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2462 goto sensor_video_probe_err;
2466 ret = sensor_write(client, 0xfe, 0x80);
2469 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2472 mdelay(5); //delay 5 microseconds
2474 /* check if it is an sensor sensor */
2475 ret = sensor_read(client, 0x00, &value);
2477 SENSOR_TR("read chip id high byte failed\n");
2479 goto sensor_video_probe_err;
2482 pid |= (value << 8);
2484 ret = sensor_read(client, 0x01, &value);
2486 SENSOR_TR("read chip id low byte failed\n");
2488 goto sensor_video_probe_err;
2491 pid |= (value & 0xff);
2492 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2493 if (pid == SENSOR_ID) {
2494 sensor->model = SENSOR_V4L2_IDENT;
2496 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2498 goto sensor_video_probe_err;
2503 sensor_video_probe_err:
2507 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2509 struct i2c_client *client = sd->priv;
2510 struct soc_camera_device *icd = client->dev.platform_data;
2511 struct sensor *sensor = to_sensor(client);
2513 #if CONFIG_SENSOR_Flash
2517 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2520 case RK29_CAM_SUBDEV_DEACTIVATE:
2522 sensor_deactivate(client);
2526 case RK29_CAM_SUBDEV_IOREQUEST:
2528 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2529 if (sensor->sensor_io_request != NULL) {
2530 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2531 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2532 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2533 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2534 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2535 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2538 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2540 goto sensor_ioctl_end;
2542 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2544 #if CONFIG_SENSOR_Flash
2545 if (sensor->sensor_gpio_res) {
2546 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2547 for (i = 0; i < icd->ops->num_controls; i++) {
2548 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2549 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2552 sensor->info_priv.flash = 0xff;
2553 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2561 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2569 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2570 enum v4l2_mbus_pixelcode *code)
2572 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2575 *code = sensor_colour_fmts[index].code;
2578 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2579 .init = sensor_init,
2580 .g_ctrl = sensor_g_control,
2581 .s_ctrl = sensor_s_control,
2582 .g_ext_ctrls = sensor_g_ext_controls,
2583 .s_ext_ctrls = sensor_s_ext_controls,
2584 .g_chip_ident = sensor_g_chip_ident,
2585 .ioctl = sensor_ioctl,
2588 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2589 .s_mbus_fmt = sensor_s_fmt,
2590 .g_mbus_fmt = sensor_g_fmt,
2591 .try_mbus_fmt = sensor_try_fmt,
2592 .enum_mbus_fmt = sensor_enum_fmt,
2595 static struct v4l2_subdev_ops sensor_subdev_ops = {
2596 .core = &sensor_subdev_core_ops,
2597 .video = &sensor_subdev_video_ops,
2600 static int sensor_probe(struct i2c_client *client,
2601 const struct i2c_device_id *did)
2603 struct sensor *sensor;
2604 struct soc_camera_device *icd = client->dev.platform_data;
2605 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2606 struct soc_camera_link *icl;
2609 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2611 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2615 icl = to_soc_camera_link(icd);
2617 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2621 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2622 dev_warn(&adapter->dev,
2623 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2627 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2631 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2633 /* Second stage probe - when a capture adapter is there */
2634 icd->ops = &sensor_ops;
2636 sensor->info_priv.fmt = sensor_colour_fmts[0];
2638 #if CONFIG_SENSOR_I2C_NOSCHED
2639 atomic_set(&sensor->tasklock_cnt,0);
2642 ret = sensor_video_probe(icd, client);
2645 i2c_set_clientdata(client, NULL);
2649 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2653 static int sensor_remove(struct i2c_client *client)
2655 struct sensor *sensor = to_sensor(client);
2656 struct soc_camera_device *icd = client->dev.platform_data;
2659 i2c_set_clientdata(client, NULL);
2660 client->driver = NULL;
2666 static const struct i2c_device_id sensor_id[] = {
2667 {SENSOR_NAME_STRING(), 0 },
2670 MODULE_DEVICE_TABLE(i2c, sensor_id);
2672 static struct i2c_driver sensor_i2c_driver = {
2674 .name = SENSOR_NAME_STRING(),
2676 .probe = sensor_probe,
2677 .remove = sensor_remove,
2678 .id_table = sensor_id,
2681 static int __init sensor_mod_init(void)
2683 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2684 return i2c_add_driver(&sensor_i2c_driver);
2687 static void __exit sensor_mod_exit(void)
2689 i2c_del_driver(&sensor_i2c_driver);
2692 device_initcall_sync(sensor_mod_init);
2693 module_exit(sensor_mod_exit);
2695 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2696 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2697 MODULE_LICENSE("GPL");