3 o* Driver for MT9M001 CMOS Image Sensor from Micron
\r
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
\r
7 * This program is free software; you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License version 2 as
\r
9 * published by the Free Software Foundation.
\r
12 #include <linux/videodev2.h>
\r
13 #include <linux/slab.h>
\r
14 #include <linux/i2c.h>
\r
15 #include <linux/log2.h>
\r
16 #include <linux/platform_device.h>
\r
17 #include <linux/delay.h>
\r
18 #include <linux/circ_buf.h>
\r
19 #include <linux/miscdevice.h>
\r
20 #include <media/v4l2-common.h>
\r
21 #include <media/v4l2-chip-ident.h>
\r
22 #include <media/soc_camera.h>
\r
23 //#include <mach/rk29_camera.h>
\r
24 #include <plat/rk_camera.h>
\r
27 module_param(debug, int, S_IRUGO|S_IWUSR);
\r
29 #define dprintk(level, fmt, arg...) do { \
\r
30 if (debug >= level) \
\r
31 printk(KERN_WARNING fmt , ## arg); } while (0)
\r
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
\r
34 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
\r
37 #define _CONS(a,b) a##b
\r
38 #define CONS(a,b) _CONS(a,b)
\r
41 #define _STR(x) __STR(x)
\r
42 #define STR(x) _STR(x)
\r
44 #define MIN(x,y) ((x<y) ? x: y)
\r
45 #define MAX(x,y) ((x>y) ? x: y)
\r
47 /* Sensor Driver Configuration */
\r
48 #define SENSOR_NAME RK29_CAM_SENSOR_SIV121D
\r
49 #define SENSOR_V4L2_IDENT V4L2_IDENT_SIV121D
\r
50 #define SENSOR_ID 0xde
\r
51 #define SENSOR_MIN_WIDTH 640//176
\r
52 #define SENSOR_MIN_HEIGHT 480//144
\r
53 #define SENSOR_MAX_WIDTH 640
\r
54 #define SENSOR_MAX_HEIGHT 480
\r
55 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
\r
56 #define SENSOR_INIT_HEIGHT 480
\r
57 #define SENSOR_INIT_WINSEQADR sensor_vga
\r
58 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
\r
60 #define CONFIG_SENSOR_WhiteBalance 1
\r
61 #define CONFIG_SENSOR_Brightness 0
\r
62 #define CONFIG_SENSOR_Contrast 0
\r
63 #define CONFIG_SENSOR_Saturation 0
\r
64 #define CONFIG_SENSOR_Effect 1
\r
65 #define CONFIG_SENSOR_Scene 1
\r
66 #define CONFIG_SENSOR_DigitalZoom 0
\r
67 #define CONFIG_SENSOR_Focus 0
\r
68 #define CONFIG_SENSOR_Exposure 1
\r
69 #define CONFIG_SENSOR_Flash 0
\r
70 #define CONFIG_SENSOR_Mirror 0
\r
71 #define CONFIG_SENSOR_Flip 0
\r
73 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
\r
74 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
\r
75 #define CONFIG_SENSOR_I2C_NOSCHED 0
\r
76 #define CONFIG_SENSOR_I2C_RDWRCHK 0
\r
78 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
\r
79 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
\r
80 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
\r
82 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
\r
83 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
\r
84 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
\r
85 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
\r
86 #define COLOR_TEMPERATURE_OFFICE_DN 3500
\r
87 #define COLOR_TEMPERATURE_OFFICE_UP 5000
\r
88 #define COLOR_TEMPERATURE_HOME_DN 2500
\r
89 #define COLOR_TEMPERATURE_HOME_UP 3500
\r
91 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
\r
92 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
\r
94 #define SENSOR_AF_IS_ERR (0x00<<0)
\r
95 #define SENSOR_AF_IS_OK (0x01<<0)
\r
96 #define SENSOR_INIT_IS_ERR (0x00<<28)
\r
97 #define SENSOR_INIT_IS_OK (0x01<<28)
\r
105 /* init 640X480 VGA */
\r
106 static struct reginfo sensor_init_data[] =
\r
125 {0x17, 0x86}, //ABS 1.74V
\r
174 {0x13, 0x7e}, //Cr target
\r
175 {0x14, 0x7d}, //Cb target
\r
176 {0x15, 0xd8}, // R gain Top
\r
177 {0x16, 0x7c}, // R gain bottom
\r
178 {0x17, 0xe0}, // B gain Top
\r
179 {0x18, 0x88}, // B gain bottom 0x80
\r
180 {0x19, 0x8c}, // Cr top value 0x90
\r
181 {0x1a, 0x64}, // Cr bottom value 0x70
\r
182 {0x1b, 0x98}, // Cb top value 0x90
\r
183 {0x1c, 0x6c}, // Cb bottom value 0x70
\r
184 {0x1d, 0x94}, // 0xa0
\r
185 {0x1e, 0x6c}, // 0x60
\r
186 {0x20, 0xe8}, // AWB luminous top value
\r
187 {0x21, 0x30}, // AWB luminous bottom value 0x20
\r
192 {0x27, 0x08}, // BRTSRT
\r
193 {0x28, 0x0f}, // BRTEND
\r
194 {0x29, 0xba}, // BRTRGNBOT
\r
195 {0x2a, 0xa0}, // BRTBGNTOP
\r
206 {0x63, 0x90}, // R D30 to D20
\r
207 {0x64, 0xd0}, // B D30 to D20
\r
208 {0x65, 0x98}, // R D20 to D30
\r
209 {0x66, 0xd0}, // B D20 to D30
\r
214 {0x11, 0x0d},//1 d},
\r
218 {0x18, 0xbe}, // DPCNRCTRL
\r
219 {0x19, 0x00}, // DPCTHV
\r
220 {0x1A, 0x00}, // DPCTHVSLP
\r
221 {0x1B, 0x00}, // DPCTHVDIFSRT
\r
222 {0x1C, 0x0f}, // DPCTHVDIFSLP
\r
223 {0x1d, 0xFF}, // DPCTHVMAX
\r
225 {0x1E, 0x04}, // BNRTHV 0c
\r
226 {0x1F, 0x04}, // BNRTHVSLPN 10
\r
227 {0x20, 0x10}, // BNRTHVSLPD
\r
228 {0x21, 0x00}, // BNRNEICNT
\r
229 {0x22, 0x10}, // STRTNOR
\r
230 {0x23, 0x40}, // STRTDRK
\r
234 {0x31, 0x08}, //0x08
\r
235 {0x32, 0x12}, //0x10
\r
236 {0x33, 0x24}, //0x1B
\r
237 {0x34, 0x47}, //0x37
\r
238 {0x35, 0x64}, //0x4D
\r
239 {0x36, 0x7c}, //0x60
\r
240 {0x37, 0x8f}, //0x72
\r
241 {0x38, 0x9f}, //0x82
\r
242 {0x39, 0xad}, //0x91
\r
243 {0x3a, 0xba}, //0xA0
\r
244 {0x3b, 0xcf}, //0xBA
\r
245 {0x3c, 0xe2}, //0xD3
\r
246 {0x3d, 0xf0}, //0xEA
\r
248 // Shading Register Setting
\r
253 {0x44, 0x22}, // left R gain[7:4], right R gain[3:0]
\r
254 {0x45, 0x22}, // top R gain[7:4], bottom R gain[3:0]
\r
255 {0x46, 0x00}, // left G gain[7:4], right G gain[3:0]
\r
256 {0x47, 0x11}, // top G gain[7:4], bottom G gain[3:0]
\r
257 {0x48, 0x00}, // left B gain[7:4], right B gain[3:0]
\r
258 {0x49, 0x00}, // top B gain[7:4], bottom B gain[3:0]
\r
259 {0x4a, 0x04}, // X-axis center high[3:2], Y-axis center high[1:0]
\r
260 {0x4b, 0x48}, // X-axis center low[7:0]
\r
261 {0x4c, 0xe8}, // Y-axis center low[7:0]
\r
262 {0x4d, 0x84}, // Shading Center Gain
\r
263 {0x4e, 0x00}, // Shading R Offset
\r
264 {0x4f, 0x00}, // Shading Gr Offset
\r
265 {0x50, 0x00}, // Shading B Offset
\r
269 {0x61, 0x08}, // INTCTRL outdoor
\r
271 // Color matrix (D65) - Daylight
\r
282 // Color matrix (D20) - A
\r
283 {0x83, 0x38}, //0x3c
\r
284 {0x84, 0xd1}, //0xc6
\r
285 {0x85, 0xf7}, //0xff
\r
286 {0x86, 0x12}, //0x12
\r
287 {0x87, 0x25}, //0x24
\r
288 {0x88, 0x09}, //0x0a
\r
289 {0x89, 0xed}, //0xed
\r
290 {0x8a, 0xbb}, //0xc2
\r
291 {0x8b, 0x58}, //0x51
\r
293 {0x8c, 0x10}, //CMA select
\r
296 {0x90, 0x18}, //Upper gain
\r
297 {0x91, 0x28}, //down gain
\r
298 {0x92, 0x55}, //[7:4] upper coring [3:0] down coring
\r
301 {0x9c, 0x38}, //edge suppress start
\r
302 {0x9d, 0x30}, //edge suppress slope
\r
307 {0xb9, 0x30}, // nightmode 38 at gain 0x48 5fps
\r
308 {0xba, 0x44}, // nightmode 80 at gain 0x48 5fps
\r
318 {0xe5, 0x15}, //MEMSPDA
\r
319 {0xe6, 0x02}, //MEMSPDB
\r
320 {0xe7, 0x04}, //MEMSPDC
\r
324 {0x03, 0x01} // SNR Enable
\r
329 /* 1280X1024 SXGA */
\r
330 static struct reginfo sensor_sxga[] =
\r
336 static struct reginfo sensor_svga[] =
\r
341 /* 640X480 VGA @30fps for both preview & capture. */
\r
342 static struct reginfo sensor_vga[] =
\r
355 /* 352X288 CIF @30fps*/
\r
356 static struct reginfo sensor_cif[] =
\r
370 static struct reginfo sensor_qvga[] =
\r
384 static struct reginfo sensor_qcif[] =
\r
397 static struct reginfo sensor_ClrFmt_YUYV[]=
\r
403 static struct reginfo sensor_ClrFmt_UYVY[]=
\r
410 #if CONFIG_SENSOR_WhiteBalance
\r
411 static struct reginfo sensor_WhiteB_Auto[]=
\r
417 /* Cloudy Colour Temperature : 6500K - 8000K */
\r
418 static struct reginfo sensor_WhiteB_Cloudy[]=
\r
421 {0x10, 0x00}, // disable AWB
\r
427 /* ClearDay Colour Temperature : 5000K - 6500K */
\r
428 static struct reginfo sensor_WhiteB_ClearDay[]=
\r
431 {0x10, 0x00}, // disable AWB
\r
437 /* Office Colour Temperature : 3500K - 5000K */
\r
438 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
\r
441 {0x10, 0x00}, // disable AWB
\r
446 /* Home Colour Temperature : 2500K - 3500K */
\r
447 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
\r
450 {0x10, 0x00}, // disable AWB
\r
455 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
\r
456 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
\r
460 #if CONFIG_SENSOR_Brightness
\r
461 static struct reginfo sensor_Brightness0[]=
\r
469 static struct reginfo sensor_Brightness1[]=
\r
477 static struct reginfo sensor_Brightness2[]=
\r
485 static struct reginfo sensor_Brightness3[]=
\r
493 static struct reginfo sensor_Brightness4[]=
\r
501 static struct reginfo sensor_Brightness5[]=
\r
508 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
\r
509 sensor_Brightness4, sensor_Brightness5,NULL,
\r
514 #if CONFIG_SENSOR_Effect
\r
515 static struct reginfo sensor_Effect_Normal[] =
\r
524 static struct reginfo sensor_Effect_WandB[] =
\r
534 static struct reginfo sensor_Effect_Sepia[] =
\r
545 static struct reginfo sensor_Effect_Negative[] =
\r
555 static struct reginfo sensor_Effect_Bluish[] =
\r
566 static struct reginfo sensor_Effect_Green[] =
\r
577 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
578 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
\r
581 #if CONFIG_SENSOR_Exposure
\r
582 static struct reginfo sensor_Exposure0[]=
\r
590 static struct reginfo sensor_Exposure1[]=
\r
598 static struct reginfo sensor_Exposure2[]=
\r
606 static struct reginfo sensor_Exposure3[]=
\r
614 static struct reginfo sensor_Exposure4[]=
\r
622 static struct reginfo sensor_Exposure5[]=
\r
630 static struct reginfo sensor_Exposure6[]=
\r
638 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
639 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
642 #if CONFIG_SENSOR_Saturation
\r
643 static struct reginfo sensor_Saturation0[]=
\r
648 static struct reginfo sensor_Saturation1[]=
\r
653 static struct reginfo sensor_Saturation2[]=
\r
657 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
660 #if CONFIG_SENSOR_Contrast
\r
661 static struct reginfo sensor_Contrast0[]=
\r
669 static struct reginfo sensor_Contrast1[]=
\r
677 static struct reginfo sensor_Contrast2[]=
\r
685 static struct reginfo sensor_Contrast3[]=
\r
693 static struct reginfo sensor_Contrast4[]=
\r
702 static struct reginfo sensor_Contrast5[]=
\r
710 static struct reginfo sensor_Contrast6[]=
\r
717 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
718 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
722 #if CONFIG_SENSOR_Mirror
\r
723 static struct reginfo sensor_MirrorOn[]=
\r
730 static struct reginfo sensor_MirrorOff[]=
\r
736 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
\r
738 #if CONFIG_SENSOR_Flip
\r
739 static struct reginfo sensor_FlipOn[]=
\r
745 static struct reginfo sensor_FlipOff[]=
\r
750 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
\r
753 #if CONFIG_SENSOR_Scene
\r
754 static struct reginfo sensor_SceneAuto[] =
\r
763 static struct reginfo sensor_SceneNight[] =
\r
771 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
774 #if CONFIG_SENSOR_DigitalZoom
\r
775 static struct reginfo sensor_Zoom0[] =
\r
782 static struct reginfo sensor_Zoom1[] =
\r
788 static struct reginfo sensor_Zoom2[] =
\r
795 static struct reginfo sensor_Zoom3[] =
\r
800 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
802 static struct v4l2_querymenu sensor_menus[] =
\r
804 #if CONFIG_SENSOR_WhiteBalance
\r
805 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
\r
806 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
\r
807 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
\r
810 #if CONFIG_SENSOR_Effect
\r
811 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
\r
812 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
\r
813 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
\r
816 #if CONFIG_SENSOR_Scene
\r
817 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
\r
820 #if CONFIG_SENSOR_Flash
\r
821 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
\r
822 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
\r
826 static const struct v4l2_queryctrl sensor_controls[] =
\r
828 #if CONFIG_SENSOR_WhiteBalance
\r
830 .id = V4L2_CID_DO_WHITE_BALANCE,
\r
831 .type = V4L2_CTRL_TYPE_MENU,
\r
832 .name = "White Balance Control",
\r
836 .default_value = 0,
\r
840 #if CONFIG_SENSOR_Brightness
\r
842 .id = V4L2_CID_BRIGHTNESS,
\r
843 .type = V4L2_CTRL_TYPE_INTEGER,
\r
844 .name = "Brightness Control",
\r
848 .default_value = 0,
\r
852 #if CONFIG_SENSOR_Effect
\r
854 .id = V4L2_CID_EFFECT,
\r
855 .type = V4L2_CTRL_TYPE_MENU,
\r
856 .name = "Effect Control",
\r
860 .default_value = 0,
\r
864 #if CONFIG_SENSOR_Exposure
\r
866 .id = V4L2_CID_EXPOSURE,
\r
867 .type = V4L2_CTRL_TYPE_INTEGER,
\r
868 .name = "Exposure Control",
\r
872 .default_value = 0,
\r
876 #if CONFIG_SENSOR_Saturation
\r
878 .id = V4L2_CID_SATURATION,
\r
879 .type = V4L2_CTRL_TYPE_INTEGER,
\r
880 .name = "Saturation Control",
\r
884 .default_value = 0,
\r
888 #if CONFIG_SENSOR_Contrast
\r
890 .id = V4L2_CID_CONTRAST,
\r
891 .type = V4L2_CTRL_TYPE_INTEGER,
\r
892 .name = "Contrast Control",
\r
896 .default_value = 0,
\r
900 #if CONFIG_SENSOR_Mirror
\r
902 .id = V4L2_CID_HFLIP,
\r
903 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
904 .name = "Mirror Control",
\r
908 .default_value = 1,
\r
912 #if CONFIG_SENSOR_Flip
\r
914 .id = V4L2_CID_VFLIP,
\r
915 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
916 .name = "Flip Control",
\r
920 .default_value = 1,
\r
924 #if CONFIG_SENSOR_Scene
\r
926 .id = V4L2_CID_SCENE,
\r
927 .type = V4L2_CTRL_TYPE_MENU,
\r
928 .name = "Scene Control",
\r
932 .default_value = 0,
\r
936 #if CONFIG_SENSOR_DigitalZoom
\r
938 .id = V4L2_CID_ZOOM_RELATIVE,
\r
939 .type = V4L2_CTRL_TYPE_INTEGER,
\r
940 .name = "DigitalZoom Control",
\r
944 .default_value = 0,
\r
946 .id = V4L2_CID_ZOOM_ABSOLUTE,
\r
947 .type = V4L2_CTRL_TYPE_INTEGER,
\r
948 .name = "DigitalZoom Control",
\r
952 .default_value = 0,
\r
956 #if CONFIG_SENSOR_Focus
\r
958 .id = V4L2_CID_FOCUS_RELATIVE,
\r
959 .type = V4L2_CTRL_TYPE_INTEGER,
\r
960 .name = "Focus Control",
\r
964 .default_value = 0,
\r
966 .id = V4L2_CID_FOCUS_ABSOLUTE,
\r
967 .type = V4L2_CTRL_TYPE_INTEGER,
\r
968 .name = "Focus Control",
\r
972 .default_value = 125,
\r
976 #if CONFIG_SENSOR_Flash
\r
978 .id = V4L2_CID_FLASH,
\r
979 .type = V4L2_CTRL_TYPE_MENU,
\r
980 .name = "Flash Control",
\r
984 .default_value = 0,
\r
989 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
\r
990 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
\r
991 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
992 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
993 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
994 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
995 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
\r
996 static int sensor_resume(struct soc_camera_device *icd);
\r
997 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
\r
998 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
\r
999 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1000 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1001 static int sensor_deactivate(struct i2c_client *client);
\r
1003 static struct soc_camera_ops sensor_ops =
\r
1005 .suspend = sensor_suspend,
\r
1006 .resume = sensor_resume,
\r
1007 .set_bus_param = sensor_set_bus_param,
\r
1008 .query_bus_param = sensor_query_bus_param,
\r
1009 .controls = sensor_controls,
\r
1010 .menus = sensor_menus,
\r
1011 .num_controls = ARRAY_SIZE(sensor_controls),
\r
1012 .num_menus = ARRAY_SIZE(sensor_menus),
\r
1015 /* only one fixed colorspace per pixelcode */
\r
1016 struct sensor_datafmt {
\r
1017 enum v4l2_mbus_pixelcode code;
\r
1018 enum v4l2_colorspace colorspace;
\r
1021 /* Find a data format by a pixel code in an array */
\r
1022 static const struct sensor_datafmt *sensor_find_datafmt(
\r
1023 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
\r
1027 for (i = 0; i < n; i++)
\r
1028 if (fmt[i].code == code)
\r
1034 static const struct sensor_datafmt sensor_colour_fmts[] = {
\r
1035 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
\r
1038 typedef struct sensor_info_priv_s
\r
1050 bool snap2preview;
\r
1051 bool video2preview;
\r
1052 unsigned char mirror; /* HFLIP */
\r
1053 unsigned char flip; /* VFLIP */
\r
1054 unsigned int winseqe_cur_addr;
\r
1055 struct sensor_datafmt fmt;
\r
1056 unsigned int funmodule_state;
\r
1057 } sensor_info_priv_t;
\r
1061 struct v4l2_subdev subdev;
\r
1062 struct i2c_client *client;
\r
1063 sensor_info_priv_t info_priv;
\r
1064 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
\r
1065 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1066 atomic_t tasklock_cnt;
\r
1068 struct rk29camera_platform_data *sensor_io_request;
\r
1069 struct rk29camera_gpio_res *sensor_gpio_res;
\r
1072 static struct sensor* to_sensor(const struct i2c_client *client)
\r
1074 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
\r
1077 static int sensor_task_lock(struct i2c_client *client, int lock)
\r
1079 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1081 struct sensor *sensor = to_sensor(client);
\r
1084 if (atomic_read(&sensor->tasklock_cnt) == 0) {
\r
1085 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
\r
1086 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
\r
1090 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
\r
1091 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
\r
1092 goto sensor_task_lock_err;
\r
1094 preempt_disable();
\r
1097 atomic_add(1, &sensor->tasklock_cnt);
\r
1099 if (atomic_read(&sensor->tasklock_cnt) > 0) {
\r
1100 atomic_sub(1, &sensor->tasklock_cnt);
\r
1102 if (atomic_read(&sensor->tasklock_cnt) == 0)
\r
1107 sensor_task_lock_err:
\r
1115 /* sensor register write */
\r
1116 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
\r
1120 struct i2c_msg msg[1];
\r
1122 buf[0] = reg & 0xFF;
\r
1125 msg->addr = client->addr;
\r
1126 msg->flags = client->flags;
\r
1128 msg->len = sizeof(buf);
\r
1129 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1130 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
\r
1135 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1136 err = i2c_transfer(client->adapter, msg, 1);
\r
1141 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
\r
1149 /* sensor register read */
\r
1150 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
\r
1155 struct i2c_msg msg[2];
\r
1157 //buf[0] = reg >> 8;
\r
1159 buf[1] = reg & 0xFF;
\r
1161 msg[0].addr = client->addr;
\r
1162 msg[0].flags = client->flags;
\r
1164 msg[0].len = sizeof(buf);
\r
1165 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1166 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1168 msg[1].addr = client->addr;
\r
1169 msg[1].flags = client->flags|I2C_M_RD;
\r
1172 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1173 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
\r
1177 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1178 err = i2c_transfer(client->adapter, msg, 2);
\r
1184 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
\r
1191 static int sensor_effect_write_array(struct i2c_client *client,struct reginfo *regarray)
\r
1196 //for(i=0; i < sizeof(sensor_init_data) / 2;i++)
\r
1197 while((regarray[i].reg != 0xff) && (regarray[i].val != 0xff))
\r
1199 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1202 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1211 /* write a array of registers */
\r
1213 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1218 for(i=0; i < sizeof(sensor_init_data) / 2;i++)
\r
1219 //while((regarray[i].reg != 0xff) && (regarray[i].val != 0xff))
\r
1221 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1224 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1233 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1238 while (regarray[i].reg != 0)
\r
1240 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1243 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1246 err = sensor_read(client, regarray[i].reg, &val_read);
\r
1247 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
\r
1254 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1255 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
\r
1262 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
\r
1263 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
\r
1265 ret = sensor_read(client,regarray[i].reg,&value);
\r
1268 SENSOR_TR("read value failed\n");
\r
1271 if(regarray[i].val != value)
\r
1273 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
\r
1282 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
\r
1284 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1287 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
\r
1290 case Sensor_PowerDown:
\r
1292 if (icl->powerdown) {
\r
1293 ret = icl->powerdown(icd->pdev, on);
\r
1294 if (ret == RK29_CAM_IO_SUCCESS) {
\r
1298 icl->reset(icd->pdev);
\r
1300 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
\r
1302 goto sensor_power_end;
\r
1307 case Sensor_Flash:
\r
1309 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1310 struct sensor *sensor = to_sensor(client);
\r
1312 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
\r
1313 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
\r
1319 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
1327 static int sensor_init(struct v4l2_subdev *sd, u32 val)
\r
1329 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1330 struct soc_camera_device *icd = client->dev.platform_data;
\r
1331 struct sensor *sensor = to_sensor(client);
\r
1332 const struct v4l2_queryctrl *qctrl;
\r
1333 const struct sensor_datafmt *fmt;
\r
1336 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1338 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
1340 goto sensor_INIT_ERR;
\r
1344 if (sensor_task_lock(client,1)<0)
\r
1345 goto sensor_INIT_ERR;
\r
1346 /* ret = sensor_write(client, 0x12, 0x80);
\r
1349 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
\r
1351 goto sensor_INIT_ERR;
\r
1354 mdelay(5); */ //delay 5 microseconds
\r
1356 ret = sensor_write_array(client, sensor_init_data);
\r
1359 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
\r
1360 goto sensor_INIT_ERR;
\r
1363 sensor_task_lock(client,0);
\r
1365 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
\r
1366 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
\r
1368 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
\r
1370 goto sensor_INIT_ERR;
\r
1372 sensor->info_priv.fmt = *fmt;
\r
1374 /* sensor sensor information for initialization */
\r
1375 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1377 sensor->info_priv.whiteBalance = qctrl->default_value;
\r
1378 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
\r
1380 sensor->info_priv.brightness = qctrl->default_value;
\r
1381 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1383 sensor->info_priv.effect = qctrl->default_value;
\r
1384 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
\r
1386 sensor->info_priv.exposure = qctrl->default_value;
\r
1388 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
\r
1390 sensor->info_priv.saturation = qctrl->default_value;
\r
1391 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
\r
1393 sensor->info_priv.contrast = qctrl->default_value;
\r
1394 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
\r
1396 sensor->info_priv.mirror = qctrl->default_value;
\r
1397 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
\r
1399 sensor->info_priv.flip = qctrl->default_value;
\r
1400 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
\r
1402 sensor->info_priv.scene = qctrl->default_value;
\r
1403 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
1405 sensor->info_priv.digitalzoom = qctrl->default_value;
\r
1407 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
\r
1408 #if CONFIG_SENSOR_Focus
\r
1409 sensor_set_focus();
\r
1410 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
\r
1412 sensor->info_priv.focus = qctrl->default_value;
\r
1415 #if CONFIG_SENSOR_Flash
\r
1416 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
\r
1418 sensor->info_priv.flash = qctrl->default_value;
\r
1421 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);
\r
1422 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
\r
1425 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1426 sensor_task_lock(client,0);
\r
1427 sensor_deactivate(client);
\r
1431 static int sensor_deactivate(struct i2c_client *client)
\r
1433 struct soc_camera_device *icd = client->dev.platform_data;
\r
1435 struct sensor *sensor = to_sensor(client);
\r
1436 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1438 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
\r
1439 sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1442 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
\r
1443 icd->user_width = SENSOR_INIT_WIDTH;
\r
1444 icd->user_height = SENSOR_INIT_HEIGHT;
\r
1445 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1449 static struct reginfo sensor_power_down_sequence[]=
\r
1454 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1457 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1459 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1460 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
\r
1461 ret = sensor_write_array(client, sensor_power_down_sequence) ;
\r
1463 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
\r
1466 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1468 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1473 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
\r
1479 static int sensor_resume(struct soc_camera_device *icd)
\r
1483 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
\r
1485 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1489 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
\r
1495 static int sensor_set_bus_param(struct soc_camera_device *icd,
\r
1496 unsigned long flags)
\r
1502 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
\r
1504 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1505 unsigned long flags = SENSOR_BUS_PARAM;
\r
1507 return soc_camera_apply_sensor_flags(icl, flags);
\r
1510 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1512 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1513 struct soc_camera_device *icd = client->dev.platform_data;
\r
1514 struct sensor *sensor = to_sensor(client);
\r
1516 mf->width = icd->user_width;
\r
1517 mf->height = icd->user_height;
\r
1518 mf->code = sensor->info_priv.fmt.code;
\r
1519 mf->colorspace = sensor->info_priv.fmt.colorspace;
\r
1520 mf->field = V4L2_FIELD_NONE;
\r
1524 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1528 if ((mf->width == 1024) && (mf->height == 768)) {
\r
1530 } else if ((mf->width == 1280) && (mf->height == 1024)) {
\r
1532 } else if ((mf->width == 1600) && (mf->height == 1200)) {
\r
1534 } else if ((mf->width == 2048) && (mf->height == 1536)) {
\r
1536 } else if ((mf->width == 2592) && (mf->height == 1944)) {
\r
1541 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
\r
1545 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1549 if ((mf->width == 1280) && (mf->height == 720)) {
\r
1551 } else if ((mf->width == 1920) && (mf->height == 1080)) {
\r
1556 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
\r
1559 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1561 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1562 const struct sensor_datafmt *fmt;
\r
1563 struct sensor *sensor = to_sensor(client);
\r
1564 const struct v4l2_queryctrl *qctrl;
\r
1565 struct soc_camera_device *icd = client->dev.platform_data;
\r
1566 struct reginfo *winseqe_set_addr=NULL;
\r
1567 int ret=0, set_w,set_h;
\r
1569 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1570 ARRAY_SIZE(sensor_colour_fmts));
\r
1573 goto sensor_s_fmt_end;
\r
1576 if (sensor->info_priv.fmt.code != mf->code) {
\r
1579 case V4L2_MBUS_FMT_YUYV8_2X8:
\r
1581 winseqe_set_addr = sensor_ClrFmt_YUYV;
\r
1584 case V4L2_MBUS_FMT_UYVY8_2X8:
\r
1586 winseqe_set_addr = sensor_ClrFmt_UYVY;
\r
1592 if (winseqe_set_addr != NULL) {
\r
1593 sensor_write_array(client, winseqe_set_addr);
\r
1594 sensor->info_priv.fmt.code = mf->code;
\r
1595 sensor->info_priv.fmt.colorspace= mf->colorspace;
\r
1596 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
\r
1598 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
\r
1602 set_w = mf->width;
\r
1603 set_h = mf->height;
\r
1605 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
1607 winseqe_set_addr = sensor_qcif;
\r
1611 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
1613 winseqe_set_addr = sensor_qvga;
\r
1617 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
1619 winseqe_set_addr = sensor_cif;
\r
1623 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
1625 winseqe_set_addr = sensor_vga;
\r
1629 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
1631 winseqe_set_addr = sensor_svga;
\r
1635 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
1637 winseqe_set_addr = sensor_sxga;
\r
1643 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
\r
1644 set_w = SENSOR_INIT_WIDTH;
\r
1645 set_h = SENSOR_INIT_HEIGHT;
\r
1646 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
\r
1649 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
\r
1650 #if CONFIG_SENSOR_Flash
\r
1651 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
1652 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1653 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
\r
1654 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
\r
1656 } else { /* ddl@rock-chips.com : Video */
\r
1657 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1658 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
1659 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
\r
1663 ret |= sensor_write_array(client, winseqe_set_addr);
\r
1665 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
\r
1666 #if CONFIG_SENSOR_Flash
\r
1667 if (sensor_fmt_capturechk(sd,mf) == true) {
\r
1668 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1669 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
1670 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
\r
1674 goto sensor_s_fmt_end;
\r
1677 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
\r
1679 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
1680 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1681 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1682 if (sensor->info_priv.whiteBalance != 0) {
\r
1683 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1684 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1686 sensor->info_priv.snap2preview = true;
\r
1687 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
\r
1688 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1689 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1691 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1692 sensor->info_priv.video2preview = true;
\r
1693 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
\r
1694 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1695 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1696 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1697 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1699 sensor->info_priv.video2preview = false;
\r
1700 sensor->info_priv.snap2preview = false;
\r
1703 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
\r
1707 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
\r
1710 mf->width = set_w;
\r
1711 mf->height = set_h;
\r
1717 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1719 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1720 struct sensor *sensor = to_sensor(client);
\r
1721 const struct sensor_datafmt *fmt;
\r
1722 int ret = 0,set_w,set_h;
\r
1724 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1725 ARRAY_SIZE(sensor_colour_fmts));
\r
1726 if (fmt == NULL) {
\r
1727 fmt = &sensor->info_priv.fmt;
\r
1728 mf->code = fmt->code;
\r
1731 if (mf->height > SENSOR_MAX_HEIGHT)
\r
1732 mf->height = SENSOR_MAX_HEIGHT;
\r
1733 else if (mf->height < SENSOR_MIN_HEIGHT)
\r
1734 mf->height = SENSOR_MIN_HEIGHT;
\r
1736 if (mf->width > SENSOR_MAX_WIDTH)
\r
1737 mf->width = SENSOR_MAX_WIDTH;
\r
1738 else if (mf->width < SENSOR_MIN_WIDTH)
\r
1739 mf->width = SENSOR_MIN_WIDTH;
\r
1741 set_w = mf->width;
\r
1742 set_h = mf->height;
\r
1744 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
1749 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
1754 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
1759 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
1764 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
1769 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
1776 set_w = SENSOR_INIT_WIDTH;
\r
1777 set_h = SENSOR_INIT_HEIGHT;
\r
1780 mf->width = set_w;
\r
1781 mf->height = set_h;
\r
1783 mf->colorspace = fmt->colorspace;
\r
1788 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
\r
1790 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1792 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
\r
1795 if (id->match.addr != client->addr)
\r
1798 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
\r
1803 #if CONFIG_SENSOR_Brightness
\r
1804 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1806 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1808 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1810 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
\r
1812 if (sensor_effect_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
\r
1814 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1817 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1821 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1825 #if CONFIG_SENSOR_Effect
\r
1826 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1828 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1830 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1832 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
\r
1834 if (sensor_effect_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
\r
1836 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1839 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1843 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1847 #if CONFIG_SENSOR_Exposure
\r
1848 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1850 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1852 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1854 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
\r
1856 if (sensor_effect_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
\r
1858 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1861 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1865 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1869 #if CONFIG_SENSOR_Saturation
\r
1870 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1872 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1874 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1876 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
\r
1878 if (sensor_effect_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
\r
1880 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1883 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1887 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1891 #if CONFIG_SENSOR_Contrast
\r
1892 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1894 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1896 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1898 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
\r
1900 if (sensor_effect_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
\r
1902 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1905 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1909 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1913 #if CONFIG_SENSOR_Mirror
\r
1914 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1916 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1918 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1920 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
\r
1922 if (sensor_effect_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
\r
1924 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1927 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1931 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1935 #if CONFIG_SENSOR_Flip
\r
1936 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1938 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1940 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1942 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
\r
1944 if (sensor_effect_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
\r
1946 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1949 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1953 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1957 #if CONFIG_SENSOR_Scene
\r
1958 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1960 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1962 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1964 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
\r
1966 if (sensor_effect_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
\r
1968 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1971 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1975 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1979 #if CONFIG_SENSOR_WhiteBalance
\r
1980 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1982 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1984 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1986 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
\r
1988 if (sensor_effect_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
\r
1990 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1993 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1997 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2001 #if CONFIG_SENSOR_DigitalZoom
\r
2002 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
\r
2004 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2005 struct sensor *sensor = to_sensor(client);
\r
2006 const struct v4l2_queryctrl *qctrl_info;
\r
2007 int digitalzoom_cur, digitalzoom_total;
\r
2009 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
2013 digitalzoom_cur = sensor->info_priv.digitalzoom;
\r
2014 digitalzoom_total = qctrl_info->maximum;
\r
2016 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
\r
2018 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2022 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
\r
2024 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2028 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
\r
2030 *value = digitalzoom_total - digitalzoom_cur;
\r
2033 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
\r
2035 *value = 0 - digitalzoom_cur;
\r
2038 digitalzoom_cur += *value;
\r
2040 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
\r
2042 if (sensor_effect_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
\r
2044 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2047 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
\r
2054 #if CONFIG_SENSOR_Flash
\r
2055 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2057 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
\r
2058 if (value == 3) { /* ddl@rock-chips.com: torch */
\r
2059 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
\r
2061 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2063 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2067 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2072 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2074 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2075 struct sensor *sensor = to_sensor(client);
\r
2076 const struct v4l2_queryctrl *qctrl;
\r
2078 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2082 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2088 case V4L2_CID_BRIGHTNESS:
\r
2090 ctrl->value = sensor->info_priv.brightness;
\r
2093 case V4L2_CID_SATURATION:
\r
2095 ctrl->value = sensor->info_priv.saturation;
\r
2098 case V4L2_CID_CONTRAST:
\r
2100 ctrl->value = sensor->info_priv.contrast;
\r
2103 case V4L2_CID_DO_WHITE_BALANCE:
\r
2105 ctrl->value = sensor->info_priv.whiteBalance;
\r
2108 case V4L2_CID_EXPOSURE:
\r
2110 ctrl->value = sensor->info_priv.exposure;
\r
2113 case V4L2_CID_HFLIP:
\r
2115 ctrl->value = sensor->info_priv.mirror;
\r
2118 case V4L2_CID_VFLIP:
\r
2120 ctrl->value = sensor->info_priv.flip;
\r
2131 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2133 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2134 struct sensor *sensor = to_sensor(client);
\r
2135 struct soc_camera_device *icd = client->dev.platform_data;
\r
2136 const struct v4l2_queryctrl *qctrl;
\r
2139 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2143 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2149 #if CONFIG_SENSOR_Brightness
\r
2150 case V4L2_CID_BRIGHTNESS:
\r
2152 if (ctrl->value != sensor->info_priv.brightness)
\r
2154 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
\r
2158 sensor->info_priv.brightness = ctrl->value;
\r
2163 #if CONFIG_SENSOR_Exposure
\r
2164 case V4L2_CID_EXPOSURE:
\r
2166 if (ctrl->value != sensor->info_priv.exposure)
\r
2168 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
\r
2172 sensor->info_priv.exposure = ctrl->value;
\r
2177 #if CONFIG_SENSOR_Saturation
\r
2178 case V4L2_CID_SATURATION:
\r
2180 if (ctrl->value != sensor->info_priv.saturation)
\r
2182 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
\r
2186 sensor->info_priv.saturation = ctrl->value;
\r
2191 #if CONFIG_SENSOR_Contrast
\r
2192 case V4L2_CID_CONTRAST:
\r
2194 if (ctrl->value != sensor->info_priv.contrast)
\r
2196 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
\r
2200 sensor->info_priv.contrast = ctrl->value;
\r
2205 #if CONFIG_SENSOR_WhiteBalance
\r
2206 case V4L2_CID_DO_WHITE_BALANCE:
\r
2208 if (ctrl->value != sensor->info_priv.whiteBalance)
\r
2210 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
\r
2214 sensor->info_priv.whiteBalance = ctrl->value;
\r
2219 #if CONFIG_SENSOR_Mirror
\r
2220 case V4L2_CID_HFLIP:
\r
2222 if (ctrl->value != sensor->info_priv.mirror)
\r
2224 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
\r
2226 sensor->info_priv.mirror = ctrl->value;
\r
2231 #if CONFIG_SENSOR_Flip
\r
2232 case V4L2_CID_VFLIP:
\r
2234 if (ctrl->value != sensor->info_priv.flip)
\r
2236 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
\r
2238 sensor->info_priv.flip = ctrl->value;
\r
2249 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
\r
2251 const struct v4l2_queryctrl *qctrl;
\r
2252 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2253 struct sensor *sensor = to_sensor(client);
\r
2255 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2259 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2263 switch (ext_ctrl->id)
\r
2265 case V4L2_CID_SCENE:
\r
2267 ext_ctrl->value = sensor->info_priv.scene;
\r
2270 case V4L2_CID_EFFECT:
\r
2272 ext_ctrl->value = sensor->info_priv.effect;
\r
2275 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2277 ext_ctrl->value = sensor->info_priv.digitalzoom;
\r
2280 case V4L2_CID_ZOOM_RELATIVE:
\r
2284 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2286 ext_ctrl->value = sensor->info_priv.focus;
\r
2289 case V4L2_CID_FOCUS_RELATIVE:
\r
2293 case V4L2_CID_FLASH:
\r
2295 ext_ctrl->value = sensor->info_priv.flash;
\r
2303 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
\r
2305 const struct v4l2_queryctrl *qctrl;
\r
2306 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2307 struct sensor *sensor = to_sensor(client);
\r
2310 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2314 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2319 switch (ext_ctrl->id)
\r
2321 #if CONFIG_SENSOR_Scene
\r
2322 case V4L2_CID_SCENE:
\r
2324 if (ext_ctrl->value != sensor->info_priv.scene)
\r
2326 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
\r
2328 sensor->info_priv.scene = ext_ctrl->value;
\r
2333 #if CONFIG_SENSOR_Effect
\r
2334 case V4L2_CID_EFFECT:
\r
2336 if (ext_ctrl->value != sensor->info_priv.effect)
\r
2338 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
\r
2340 sensor->info_priv.effect= ext_ctrl->value;
\r
2345 #if CONFIG_SENSOR_DigitalZoom
\r
2346 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2348 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2351 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
\r
2353 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
\r
2355 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
\r
2357 sensor->info_priv.digitalzoom += val_offset;
\r
2359 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2364 case V4L2_CID_ZOOM_RELATIVE:
\r
2366 if (ext_ctrl->value)
\r
2368 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
\r
2370 sensor->info_priv.digitalzoom += ext_ctrl->value;
\r
2372 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2377 #if CONFIG_SENSOR_Focus
\r
2378 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2380 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2383 if (ext_ctrl->value != sensor->info_priv.focus)
\r
2385 val_offset = ext_ctrl->value -sensor->info_priv.focus;
\r
2387 sensor->info_priv.focus += val_offset;
\r
2392 case V4L2_CID_FOCUS_RELATIVE:
\r
2394 if (ext_ctrl->value)
\r
2396 sensor->info_priv.focus += ext_ctrl->value;
\r
2398 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
\r
2403 #if CONFIG_SENSOR_Flash
\r
2404 case V4L2_CID_FLASH:
\r
2406 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
\r
2408 sensor->info_priv.flash = ext_ctrl->value;
\r
2410 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
\r
2421 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2423 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2424 struct soc_camera_device *icd = client->dev.platform_data;
\r
2425 int i, error_cnt=0, error_idx=-1;
\r
2428 for (i=0; i<ext_ctrl->count; i++) {
\r
2429 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2435 if (error_cnt > 1)
\r
2436 error_idx = ext_ctrl->count;
\r
2438 if (error_idx != -1) {
\r
2439 ext_ctrl->error_idx = error_idx;
\r
2446 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2448 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2449 struct soc_camera_device *icd = client->dev.platform_data;
\r
2450 int i, error_cnt=0, error_idx=-1;
\r
2453 for (i=0; i<ext_ctrl->count; i++) {
\r
2454 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2460 if (error_cnt > 1)
\r
2461 error_idx = ext_ctrl->count;
\r
2463 if (error_idx != -1) {
\r
2464 ext_ctrl->error_idx = error_idx;
\r
2471 /* Interface active, can use i2c. If it fails, it can indeed mean, that
\r
2472 * this wasn't our capture interface, so, we wait for the right one */
\r
2473 static int sensor_video_probe(struct soc_camera_device *icd,
\r
2474 struct i2c_client *client)
\r
2478 struct sensor *sensor = to_sensor(client);
\r
2480 /* We must have a parent by now. And it cannot be a wrong one.
\r
2481 * So this entire test is completely redundant. */
\r
2482 if (!icd->dev.parent ||
\r
2483 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
\r
2486 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
2488 goto sensor_video_probe_err;
\r
2492 /* ret = sensor_write(client, 0x12, 0x80);
\r
2495 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
\r
2498 mdelay(50); *///delay 5 microseconds
\r
2499 sensor_write(client, 0x00, 0x01);
\r
2500 sensor_write(client, 0x03, 0x0a);
\r
2501 mdelay(100); //delay 5 microseconds
\r
2502 sensor_write(client, 0x00, 0x01);
\r
2503 sensor_write(client, 0x03, 0x0a);
\r
2504 mdelay(100); //delay 5 microseconds
\r
2506 /* check if it is an sensor sensor */
\r
2507 sensor_write(client, 0x00, 0x00);
\r
2509 ret = sensor_read(client, 0x01, &pid);
\r
2511 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
\r
2513 goto sensor_video_probe_err;
\r
2516 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2517 if (pid == SENSOR_ID) {
\r
2518 sensor->model = SENSOR_V4L2_IDENT;
\r
2520 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2522 goto sensor_video_probe_err;
\r
2527 sensor_video_probe_err:
\r
2532 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
\r
2534 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2535 struct soc_camera_device *icd = client->dev.platform_data;
\r
2536 struct sensor *sensor = to_sensor(client);
\r
2542 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2545 case RK29_CAM_SUBDEV_DEACTIVATE:
\r
2547 sensor_deactivate(client);
\r
2551 case RK29_CAM_SUBDEV_IOREQUEST:
\r
2553 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2554 if (sensor->sensor_io_request != NULL) {
\r
2555 sensor->sensor_gpio_res = NULL;
\r
2556 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
\r
2557 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
\r
2558 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
\r
2559 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
\r
2562 if (sensor->sensor_gpio_res == NULL) {
\r
2563 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2565 goto sensor_ioctl_end;
\r
2568 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2570 goto sensor_ioctl_end;
\r
2572 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
\r
2573 for this project */
\r
2574 #if CONFIG_SENSOR_Flash
\r
2575 if (sensor->sensor_gpio_res) {
\r
2576 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
\r
2577 for (i = 0; i < icd->ops->num_controls; i++) {
\r
2578 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
\r
2579 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
\r
2582 sensor->info_priv.flash = 0xff;
\r
2583 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
\r
2591 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2599 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
\r
2600 enum v4l2_mbus_pixelcode *code)
\r
2602 if (index >= ARRAY_SIZE(sensor_colour_fmts))
\r
2605 *code = sensor_colour_fmts[index].code;
\r
2608 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
\r
2609 .init = sensor_init,
\r
2610 .g_ctrl = sensor_g_control,
\r
2611 .s_ctrl = sensor_s_control,
\r
2612 .g_ext_ctrls = sensor_g_ext_controls,
\r
2613 .s_ext_ctrls = sensor_s_ext_controls,
\r
2614 .g_chip_ident = sensor_g_chip_ident,
\r
2615 .ioctl = sensor_ioctl,
\r
2618 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
\r
2619 .s_mbus_fmt = sensor_s_fmt,
\r
2620 .g_mbus_fmt = sensor_g_fmt,
\r
2621 .try_mbus_fmt = sensor_try_fmt,
\r
2622 .enum_mbus_fmt = sensor_enum_fmt,
\r
2625 static struct v4l2_subdev_ops sensor_subdev_ops = {
\r
2626 .core = &sensor_subdev_core_ops,
\r
2627 .video = &sensor_subdev_video_ops,
\r
2630 static int sensor_probe(struct i2c_client *client,
\r
2631 const struct i2c_device_id *did)
\r
2633 struct sensor *sensor;
\r
2634 struct soc_camera_device *icd = client->dev.platform_data;
\r
2635 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
\r
2636 struct soc_camera_link *icl;
\r
2639 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
\r
2641 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
\r
2645 icl = to_soc_camera_link(icd);
\r
2647 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
\r
2651 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
\r
2652 dev_warn(&adapter->dev,
\r
2653 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
\r
2657 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
\r
2661 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
\r
2663 /* Second stage probe - when a capture adapter is there */
\r
2664 icd->ops = &sensor_ops;
\r
2666 sensor->info_priv.fmt = sensor_colour_fmts[0];
\r
2668 #if CONFIG_SENSOR_I2C_NOSCHED
\r
2669 atomic_set(&sensor->tasklock_cnt,0);
\r
2672 ret = sensor_video_probe(icd, client);
\r
2675 i2c_set_clientdata(client, NULL);
\r
2679 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
\r
2683 static int sensor_remove(struct i2c_client *client)
\r
2685 struct sensor *sensor = to_sensor(client);
\r
2686 struct soc_camera_device *icd = client->dev.platform_data;
\r
2689 i2c_set_clientdata(client, NULL);
\r
2690 client->driver = NULL;
\r
2696 static const struct i2c_device_id sensor_id[] = {
\r
2697 {SENSOR_NAME_STRING(), 0 },
\r
2700 MODULE_DEVICE_TABLE(i2c, sensor_id);
\r
2702 static struct i2c_driver sensor_i2c_driver = {
\r
2704 .name = SENSOR_NAME_STRING(),
\r
2706 .probe = sensor_probe,
\r
2707 .remove = sensor_remove,
\r
2708 .id_table = sensor_id,
\r
2711 static int __init sensor_mod_init(void)
\r
2713 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
\r
2714 return i2c_add_driver(&sensor_i2c_driver);
\r
2717 static void __exit sensor_mod_exit(void)
\r
2719 i2c_del_driver(&sensor_i2c_driver);
\r
2722 device_initcall_sync(sensor_mod_init);
\r
2723 module_exit(sensor_mod_exit);
\r
2725 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
\r
2726 MODULE_AUTHOR("ddl <kernel@rock-chips>");
\r
2727 MODULE_LICENSE("GPL");
\r