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
554 static struct reginfo sensor_Effect_Bluish[] =
\r
565 static struct reginfo sensor_Effect_Green[] =
\r
576 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
\r
577 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
\r
580 #if CONFIG_SENSOR_Exposure
\r
581 static struct reginfo sensor_Exposure0[]=
\r
589 static struct reginfo sensor_Exposure1[]=
\r
597 static struct reginfo sensor_Exposure2[]=
\r
605 static struct reginfo sensor_Exposure3[]=
\r
613 static struct reginfo sensor_Exposure4[]=
\r
621 static struct reginfo sensor_Exposure5[]=
\r
629 static struct reginfo sensor_Exposure6[]=
\r
637 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
\r
638 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
\r
641 #if CONFIG_SENSOR_Saturation
\r
642 static struct reginfo sensor_Saturation0[]=
\r
647 static struct reginfo sensor_Saturation1[]=
\r
652 static struct reginfo sensor_Saturation2[]=
\r
656 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
\r
659 #if CONFIG_SENSOR_Contrast
\r
660 static struct reginfo sensor_Contrast0[]=
\r
668 static struct reginfo sensor_Contrast1[]=
\r
676 static struct reginfo sensor_Contrast2[]=
\r
684 static struct reginfo sensor_Contrast3[]=
\r
692 static struct reginfo sensor_Contrast4[]=
\r
701 static struct reginfo sensor_Contrast5[]=
\r
709 static struct reginfo sensor_Contrast6[]=
\r
716 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
\r
717 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
\r
721 #if CONFIG_SENSOR_Mirror
\r
722 static struct reginfo sensor_MirrorOn[]=
\r
729 static struct reginfo sensor_MirrorOff[]=
\r
735 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
\r
737 #if CONFIG_SENSOR_Flip
\r
738 static struct reginfo sensor_FlipOn[]=
\r
744 static struct reginfo sensor_FlipOff[]=
\r
749 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
\r
752 #if CONFIG_SENSOR_Scene
\r
753 static struct reginfo sensor_SceneAuto[] =
\r
762 static struct reginfo sensor_SceneNight[] =
\r
770 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
\r
773 #if CONFIG_SENSOR_DigitalZoom
\r
774 static struct reginfo sensor_Zoom0[] =
\r
781 static struct reginfo sensor_Zoom1[] =
\r
787 static struct reginfo sensor_Zoom2[] =
\r
794 static struct reginfo sensor_Zoom3[] =
\r
799 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
\r
801 static const struct v4l2_querymenu sensor_menus[] =
\r
803 #if CONFIG_SENSOR_WhiteBalance
\r
804 { .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
805 { .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
806 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
\r
809 #if CONFIG_SENSOR_Effect
\r
810 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
\r
811 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
\r
812 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
\r
815 #if CONFIG_SENSOR_Scene
\r
816 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
\r
819 #if CONFIG_SENSOR_Flash
\r
820 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
\r
821 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
\r
825 static const struct v4l2_queryctrl sensor_controls[] =
\r
827 #if CONFIG_SENSOR_WhiteBalance
\r
829 .id = V4L2_CID_DO_WHITE_BALANCE,
\r
830 .type = V4L2_CTRL_TYPE_MENU,
\r
831 .name = "White Balance Control",
\r
835 .default_value = 0,
\r
839 #if CONFIG_SENSOR_Brightness
\r
841 .id = V4L2_CID_BRIGHTNESS,
\r
842 .type = V4L2_CTRL_TYPE_INTEGER,
\r
843 .name = "Brightness Control",
\r
847 .default_value = 0,
\r
851 #if CONFIG_SENSOR_Effect
\r
853 .id = V4L2_CID_EFFECT,
\r
854 .type = V4L2_CTRL_TYPE_MENU,
\r
855 .name = "Effect Control",
\r
859 .default_value = 0,
\r
863 #if CONFIG_SENSOR_Exposure
\r
865 .id = V4L2_CID_EXPOSURE,
\r
866 .type = V4L2_CTRL_TYPE_INTEGER,
\r
867 .name = "Exposure Control",
\r
871 .default_value = 0,
\r
875 #if CONFIG_SENSOR_Saturation
\r
877 .id = V4L2_CID_SATURATION,
\r
878 .type = V4L2_CTRL_TYPE_INTEGER,
\r
879 .name = "Saturation Control",
\r
883 .default_value = 0,
\r
887 #if CONFIG_SENSOR_Contrast
\r
889 .id = V4L2_CID_CONTRAST,
\r
890 .type = V4L2_CTRL_TYPE_INTEGER,
\r
891 .name = "Contrast Control",
\r
895 .default_value = 0,
\r
899 #if CONFIG_SENSOR_Mirror
\r
901 .id = V4L2_CID_HFLIP,
\r
902 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
903 .name = "Mirror Control",
\r
907 .default_value = 1,
\r
911 #if CONFIG_SENSOR_Flip
\r
913 .id = V4L2_CID_VFLIP,
\r
914 .type = V4L2_CTRL_TYPE_BOOLEAN,
\r
915 .name = "Flip Control",
\r
919 .default_value = 1,
\r
923 #if CONFIG_SENSOR_Scene
\r
925 .id = V4L2_CID_SCENE,
\r
926 .type = V4L2_CTRL_TYPE_MENU,
\r
927 .name = "Scene Control",
\r
931 .default_value = 0,
\r
935 #if CONFIG_SENSOR_DigitalZoom
\r
937 .id = V4L2_CID_ZOOM_RELATIVE,
\r
938 .type = V4L2_CTRL_TYPE_INTEGER,
\r
939 .name = "DigitalZoom Control",
\r
943 .default_value = 0,
\r
945 .id = V4L2_CID_ZOOM_ABSOLUTE,
\r
946 .type = V4L2_CTRL_TYPE_INTEGER,
\r
947 .name = "DigitalZoom Control",
\r
951 .default_value = 0,
\r
955 #if CONFIG_SENSOR_Focus
\r
957 .id = V4L2_CID_FOCUS_RELATIVE,
\r
958 .type = V4L2_CTRL_TYPE_INTEGER,
\r
959 .name = "Focus Control",
\r
963 .default_value = 0,
\r
965 .id = V4L2_CID_FOCUS_ABSOLUTE,
\r
966 .type = V4L2_CTRL_TYPE_INTEGER,
\r
967 .name = "Focus Control",
\r
971 .default_value = 125,
\r
975 #if CONFIG_SENSOR_Flash
\r
977 .id = V4L2_CID_FLASH,
\r
978 .type = V4L2_CTRL_TYPE_MENU,
\r
979 .name = "Flash Control",
\r
983 .default_value = 0,
\r
988 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
\r
989 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
\r
990 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
991 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
\r
992 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
993 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
\r
994 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
\r
995 static int sensor_resume(struct soc_camera_device *icd);
\r
996 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
\r
997 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
\r
998 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
999 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
\r
1000 static int sensor_deactivate(struct i2c_client *client);
\r
1002 static struct soc_camera_ops sensor_ops =
\r
1004 .suspend = sensor_suspend,
\r
1005 .resume = sensor_resume,
\r
1006 .set_bus_param = sensor_set_bus_param,
\r
1007 .query_bus_param = sensor_query_bus_param,
\r
1008 .controls = sensor_controls,
\r
1009 .menus = sensor_menus,
\r
1010 .num_controls = ARRAY_SIZE(sensor_controls),
\r
1011 .num_menus = ARRAY_SIZE(sensor_menus),
\r
1014 /* only one fixed colorspace per pixelcode */
\r
1015 struct sensor_datafmt {
\r
1016 enum v4l2_mbus_pixelcode code;
\r
1017 enum v4l2_colorspace colorspace;
\r
1020 /* Find a data format by a pixel code in an array */
\r
1021 static const struct sensor_datafmt *sensor_find_datafmt(
\r
1022 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
\r
1026 for (i = 0; i < n; i++)
\r
1027 if (fmt[i].code == code)
\r
1033 static const struct sensor_datafmt sensor_colour_fmts[] = {
\r
1034 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
\r
1037 typedef struct sensor_info_priv_s
\r
1049 bool snap2preview;
\r
1050 bool video2preview;
\r
1051 unsigned char mirror; /* HFLIP */
\r
1052 unsigned char flip; /* VFLIP */
\r
1053 unsigned int winseqe_cur_addr;
\r
1054 struct sensor_datafmt fmt;
\r
1055 unsigned int funmodule_state;
\r
1056 } sensor_info_priv_t;
\r
1060 struct v4l2_subdev subdev;
\r
1061 struct i2c_client *client;
\r
1062 sensor_info_priv_t info_priv;
\r
1063 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
\r
1064 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1065 atomic_t tasklock_cnt;
\r
1067 struct rk29camera_platform_data *sensor_io_request;
\r
1068 struct rk29camera_gpio_res *sensor_gpio_res;
\r
1071 static struct sensor* to_sensor(const struct i2c_client *client)
\r
1073 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
\r
1076 static int sensor_task_lock(struct i2c_client *client, int lock)
\r
1078 #if CONFIG_SENSOR_I2C_NOSCHED
\r
1080 struct sensor *sensor = to_sensor(client);
\r
1083 if (atomic_read(&sensor->tasklock_cnt) == 0) {
\r
1084 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
\r
1085 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
\r
1089 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
\r
1090 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
\r
1091 goto sensor_task_lock_err;
\r
1093 preempt_disable();
\r
1096 atomic_add(1, &sensor->tasklock_cnt);
\r
1098 if (atomic_read(&sensor->tasklock_cnt) > 0) {
\r
1099 atomic_sub(1, &sensor->tasklock_cnt);
\r
1101 if (atomic_read(&sensor->tasklock_cnt) == 0)
\r
1106 sensor_task_lock_err:
\r
1114 /* sensor register write */
\r
1115 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
\r
1119 struct i2c_msg msg[1];
\r
1121 buf[0] = reg & 0xFF;
\r
1124 msg->addr = client->addr;
\r
1125 msg->flags = client->flags;
\r
1127 msg->len = sizeof(buf);
\r
1128 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1129 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
\r
1134 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1135 err = i2c_transfer(client->adapter, msg, 1);
\r
1140 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
\r
1148 /* sensor register read */
\r
1149 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
\r
1154 struct i2c_msg msg[2];
\r
1156 //buf[0] = reg >> 8;
\r
1158 buf[1] = reg & 0xFF;
\r
1160 msg[0].addr = client->addr;
\r
1161 msg[0].flags = client->flags;
\r
1163 msg[0].len = sizeof(buf);
\r
1164 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1165 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
1167 msg[1].addr = client->addr;
\r
1168 msg[1].flags = client->flags|I2C_M_RD;
\r
1171 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
\r
1172 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
1176 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
\r
1177 err = i2c_transfer(client->adapter, msg, 2);
\r
1183 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
\r
1190 static int sensor_effect_write_array(struct i2c_client *client,struct reginfo *regarray)
\r
1195 //for(i=0; i < sizeof(sensor_init_data) / 2;i++)
\r
1196 while((regarray[i].reg != 0xff) && (regarray[i].val != 0xff))
\r
1198 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1201 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1210 /* write a array of registers */
\r
1212 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1217 for(i=0; i < sizeof(sensor_init_data) / 2;i++)
\r
1218 //while((regarray[i].reg != 0xff) && (regarray[i].val != 0xff))
\r
1220 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1223 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1232 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
\r
1237 while (regarray[i].reg != 0)
\r
1239 err = sensor_write(client, regarray[i].reg, regarray[i].val);
\r
1242 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
\r
1245 err = sensor_read(client, regarray[i].reg, &val_read);
\r
1246 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
\r
1253 #if CONFIG_SENSOR_I2C_RDWRCHK
\r
1254 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
\r
1261 SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
\r
1262 for(i=0;i<sizeof(sensor_init_data) / 2;i++)
\r
1264 ret = sensor_read(client,regarray[i].reg,&value);
\r
1267 SENSOR_TR("read value failed\n");
\r
1270 if(regarray[i].val != value)
\r
1272 SENSOR_DG("%s reg[0x%x] check err,writte :0x%x read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
\r
1281 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
\r
1283 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1286 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
\r
1289 case Sensor_PowerDown:
\r
1291 if (icl->powerdown) {
\r
1292 ret = icl->powerdown(icd->pdev, on);
\r
1293 if (ret == RK29_CAM_IO_SUCCESS) {
\r
1297 icl->reset(icd->pdev);
\r
1299 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
\r
1301 goto sensor_power_end;
\r
1306 case Sensor_Flash:
\r
1308 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1309 struct sensor *sensor = to_sensor(client);
\r
1311 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
\r
1312 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
\r
1318 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
1326 static int sensor_init(struct v4l2_subdev *sd, u32 val)
\r
1328 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1329 struct soc_camera_device *icd = client->dev.platform_data;
\r
1330 struct sensor *sensor = to_sensor(client);
\r
1331 const struct v4l2_queryctrl *qctrl;
\r
1332 const struct sensor_datafmt *fmt;
\r
1335 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1337 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
1339 goto sensor_INIT_ERR;
\r
1343 if (sensor_task_lock(client,1)<0)
\r
1344 goto sensor_INIT_ERR;
\r
1345 /* ret = sensor_write(client, 0x12, 0x80);
\r
1348 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
\r
1350 goto sensor_INIT_ERR;
\r
1353 mdelay(5); */ //delay 5 microseconds
\r
1355 ret = sensor_write_array(client, sensor_init_data);
\r
1358 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
\r
1359 goto sensor_INIT_ERR;
\r
1362 sensor_task_lock(client,0);
\r
1364 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
\r
1365 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
\r
1367 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
\r
1369 goto sensor_INIT_ERR;
\r
1371 sensor->info_priv.fmt = *fmt;
\r
1373 /* sensor sensor information for initialization */
\r
1374 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1376 sensor->info_priv.whiteBalance = qctrl->default_value;
\r
1377 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
\r
1379 sensor->info_priv.brightness = qctrl->default_value;
\r
1380 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1382 sensor->info_priv.effect = qctrl->default_value;
\r
1383 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
\r
1385 sensor->info_priv.exposure = qctrl->default_value;
\r
1387 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
\r
1389 sensor->info_priv.saturation = qctrl->default_value;
\r
1390 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
\r
1392 sensor->info_priv.contrast = qctrl->default_value;
\r
1393 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
\r
1395 sensor->info_priv.mirror = qctrl->default_value;
\r
1396 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
\r
1398 sensor->info_priv.flip = qctrl->default_value;
\r
1399 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
\r
1401 sensor->info_priv.scene = qctrl->default_value;
\r
1402 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
1404 sensor->info_priv.digitalzoom = qctrl->default_value;
\r
1406 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
\r
1407 #if CONFIG_SENSOR_Focus
\r
1408 sensor_set_focus();
\r
1409 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
\r
1411 sensor->info_priv.focus = qctrl->default_value;
\r
1414 #if CONFIG_SENSOR_Flash
\r
1415 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
\r
1417 sensor->info_priv.flash = qctrl->default_value;
\r
1420 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
1421 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
\r
1424 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1425 sensor_task_lock(client,0);
\r
1426 sensor_deactivate(client);
\r
1430 static int sensor_deactivate(struct i2c_client *client)
\r
1432 struct soc_camera_device *icd = client->dev.platform_data;
\r
1434 struct sensor *sensor = to_sensor(client);
\r
1435 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
1437 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
\r
1438 sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1441 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
\r
1442 icd->user_width = SENSOR_INIT_WIDTH;
\r
1443 icd->user_height = SENSOR_INIT_HEIGHT;
\r
1444 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
\r
1448 static struct reginfo sensor_power_down_sequence[]=
\r
1453 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
\r
1456 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1458 if (pm_msg.event == PM_EVENT_SUSPEND) {
\r
1459 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
\r
1460 ret = sensor_write_array(client, sensor_power_down_sequence) ;
\r
1462 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
\r
1465 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
\r
1467 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1472 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
\r
1478 static int sensor_resume(struct soc_camera_device *icd)
\r
1482 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
\r
1484 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
\r
1488 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
\r
1494 static int sensor_set_bus_param(struct soc_camera_device *icd,
\r
1495 unsigned long flags)
\r
1501 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
\r
1503 struct soc_camera_link *icl = to_soc_camera_link(icd);
\r
1504 unsigned long flags = SENSOR_BUS_PARAM;
\r
1506 return soc_camera_apply_sensor_flags(icl, flags);
\r
1509 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1511 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1512 struct soc_camera_device *icd = client->dev.platform_data;
\r
1513 struct sensor *sensor = to_sensor(client);
\r
1515 mf->width = icd->user_width;
\r
1516 mf->height = icd->user_height;
\r
1517 mf->code = sensor->info_priv.fmt.code;
\r
1518 mf->colorspace = sensor->info_priv.fmt.colorspace;
\r
1519 mf->field = V4L2_FIELD_NONE;
\r
1523 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1527 if ((mf->width == 1024) && (mf->height == 768)) {
\r
1529 } else if ((mf->width == 1280) && (mf->height == 1024)) {
\r
1531 } else if ((mf->width == 1600) && (mf->height == 1200)) {
\r
1533 } else if ((mf->width == 2048) && (mf->height == 1536)) {
\r
1535 } else if ((mf->width == 2592) && (mf->height == 1944)) {
\r
1540 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
\r
1544 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1548 if ((mf->width == 1280) && (mf->height == 720)) {
\r
1550 } else if ((mf->width == 1920) && (mf->height == 1080)) {
\r
1555 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
\r
1558 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1560 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1561 const struct sensor_datafmt *fmt;
\r
1562 struct sensor *sensor = to_sensor(client);
\r
1563 const struct v4l2_queryctrl *qctrl;
\r
1564 struct soc_camera_device *icd = client->dev.platform_data;
\r
1565 struct reginfo *winseqe_set_addr=NULL;
\r
1566 int ret=0, set_w,set_h;
\r
1568 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1569 ARRAY_SIZE(sensor_colour_fmts));
\r
1572 goto sensor_s_fmt_end;
\r
1575 if (sensor->info_priv.fmt.code != mf->code) {
\r
1578 case V4L2_MBUS_FMT_YUYV8_2X8:
\r
1580 winseqe_set_addr = sensor_ClrFmt_YUYV;
\r
1583 case V4L2_MBUS_FMT_UYVY8_2X8:
\r
1585 winseqe_set_addr = sensor_ClrFmt_UYVY;
\r
1591 if (winseqe_set_addr != NULL) {
\r
1592 sensor_write_array(client, winseqe_set_addr);
\r
1593 sensor->info_priv.fmt.code = mf->code;
\r
1594 sensor->info_priv.fmt.colorspace= mf->colorspace;
\r
1595 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
\r
1597 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
\r
1601 set_w = mf->width;
\r
1602 set_h = mf->height;
\r
1604 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
1606 winseqe_set_addr = sensor_qcif;
\r
1610 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
1612 winseqe_set_addr = sensor_qvga;
\r
1616 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
1618 winseqe_set_addr = sensor_cif;
\r
1622 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
1624 winseqe_set_addr = sensor_vga;
\r
1628 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
1630 winseqe_set_addr = sensor_svga;
\r
1634 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
1636 winseqe_set_addr = sensor_sxga;
\r
1642 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
\r
1643 set_w = SENSOR_INIT_WIDTH;
\r
1644 set_h = SENSOR_INIT_HEIGHT;
\r
1645 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
\r
1648 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
\r
1649 #if CONFIG_SENSOR_Flash
\r
1650 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
1651 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1652 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
\r
1653 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
\r
1655 } else { /* ddl@rock-chips.com : Video */
\r
1656 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1657 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
1658 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
\r
1662 ret |= sensor_write_array(client, winseqe_set_addr);
\r
1664 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
\r
1665 #if CONFIG_SENSOR_Flash
\r
1666 if (sensor_fmt_capturechk(sd,mf) == true) {
\r
1667 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
\r
1668 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
1669 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
\r
1673 goto sensor_s_fmt_end;
\r
1676 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
\r
1678 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
\r
1679 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1680 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1681 if (sensor->info_priv.whiteBalance != 0) {
\r
1682 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1683 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1685 sensor->info_priv.snap2preview = true;
\r
1686 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
\r
1687 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1688 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1689 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1690 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1691 sensor->info_priv.video2preview = true;
\r
1692 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
\r
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
\r
1694 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
\r
1695 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
\r
1696 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
\r
1698 sensor->info_priv.video2preview = false;
\r
1699 sensor->info_priv.snap2preview = false;
\r
1702 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
\r
1706 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
\r
1709 mf->width = set_w;
\r
1710 mf->height = set_h;
\r
1716 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
\r
1718 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1719 struct sensor *sensor = to_sensor(client);
\r
1720 const struct sensor_datafmt *fmt;
\r
1721 int ret = 0,set_w,set_h;
\r
1723 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
\r
1724 ARRAY_SIZE(sensor_colour_fmts));
\r
1725 if (fmt == NULL) {
\r
1726 fmt = &sensor->info_priv.fmt;
\r
1727 mf->code = fmt->code;
\r
1730 if (mf->height > SENSOR_MAX_HEIGHT)
\r
1731 mf->height = SENSOR_MAX_HEIGHT;
\r
1732 else if (mf->height < SENSOR_MIN_HEIGHT)
\r
1733 mf->height = SENSOR_MIN_HEIGHT;
\r
1735 if (mf->width > SENSOR_MAX_WIDTH)
\r
1736 mf->width = SENSOR_MAX_WIDTH;
\r
1737 else if (mf->width < SENSOR_MIN_WIDTH)
\r
1738 mf->width = SENSOR_MIN_WIDTH;
\r
1740 set_w = mf->width;
\r
1741 set_h = mf->height;
\r
1743 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
\r
1748 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
\r
1753 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
\r
1758 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
\r
1763 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
\r
1768 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
\r
1775 set_w = SENSOR_INIT_WIDTH;
\r
1776 set_h = SENSOR_INIT_HEIGHT;
\r
1779 mf->width = set_w;
\r
1780 mf->height = set_h;
\r
1782 mf->colorspace = fmt->colorspace;
\r
1787 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
\r
1789 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
1791 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
\r
1794 if (id->match.addr != client->addr)
\r
1797 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
\r
1802 #if CONFIG_SENSOR_Brightness
\r
1803 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1805 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1807 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1809 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
\r
1811 if (sensor_effect_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
\r
1813 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1816 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1820 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1824 #if CONFIG_SENSOR_Effect
\r
1825 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1827 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1829 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1831 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
\r
1833 if (sensor_effect_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
\r
1835 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1838 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1842 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1846 #if CONFIG_SENSOR_Exposure
\r
1847 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1849 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1851 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1853 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
\r
1855 if (sensor_effect_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
\r
1857 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1860 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1864 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1868 #if CONFIG_SENSOR_Saturation
\r
1869 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1871 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1873 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1875 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
\r
1877 if (sensor_effect_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
\r
1879 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1882 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1886 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1890 #if CONFIG_SENSOR_Contrast
\r
1891 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1893 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1895 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1897 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
\r
1899 if (sensor_effect_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
\r
1901 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1904 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1908 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1912 #if CONFIG_SENSOR_Mirror
\r
1913 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1915 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1917 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1919 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
\r
1921 if (sensor_effect_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
\r
1923 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1926 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1930 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1934 #if CONFIG_SENSOR_Flip
\r
1935 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1937 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1939 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1941 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
\r
1943 if (sensor_effect_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
\r
1945 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1948 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1952 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1956 #if CONFIG_SENSOR_Scene
\r
1957 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1959 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1961 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1963 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
\r
1965 if (sensor_effect_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
\r
1967 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1970 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1974 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
1978 #if CONFIG_SENSOR_WhiteBalance
\r
1979 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
1981 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
1983 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
\r
1985 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
\r
1987 if (sensor_effect_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
\r
1989 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
1992 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
1996 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2000 #if CONFIG_SENSOR_DigitalZoom
\r
2001 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
\r
2003 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2004 struct sensor *sensor = to_sensor(client);
\r
2005 const struct v4l2_queryctrl *qctrl_info;
\r
2006 int digitalzoom_cur, digitalzoom_total;
\r
2008 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
\r
2012 digitalzoom_cur = sensor->info_priv.digitalzoom;
\r
2013 digitalzoom_total = qctrl_info->maximum;
\r
2015 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
\r
2017 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2021 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
\r
2023 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
\r
2027 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
\r
2029 *value = digitalzoom_total - digitalzoom_cur;
\r
2032 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
\r
2034 *value = 0 - digitalzoom_cur;
\r
2037 digitalzoom_cur += *value;
\r
2039 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
\r
2041 if (sensor_effect_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
\r
2043 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
\r
2046 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
\r
2053 #if CONFIG_SENSOR_Flash
\r
2054 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
\r
2056 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
\r
2057 if (value == 3) { /* ddl@rock-chips.com: torch */
\r
2058 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
\r
2060 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
\r
2062 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
\r
2066 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
\r
2071 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2073 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2074 struct sensor *sensor = to_sensor(client);
\r
2075 const struct v4l2_queryctrl *qctrl;
\r
2077 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2081 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2087 case V4L2_CID_BRIGHTNESS:
\r
2089 ctrl->value = sensor->info_priv.brightness;
\r
2092 case V4L2_CID_SATURATION:
\r
2094 ctrl->value = sensor->info_priv.saturation;
\r
2097 case V4L2_CID_CONTRAST:
\r
2099 ctrl->value = sensor->info_priv.contrast;
\r
2102 case V4L2_CID_DO_WHITE_BALANCE:
\r
2104 ctrl->value = sensor->info_priv.whiteBalance;
\r
2107 case V4L2_CID_EXPOSURE:
\r
2109 ctrl->value = sensor->info_priv.exposure;
\r
2112 case V4L2_CID_HFLIP:
\r
2114 ctrl->value = sensor->info_priv.mirror;
\r
2117 case V4L2_CID_VFLIP:
\r
2119 ctrl->value = sensor->info_priv.flip;
\r
2130 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
\r
2132 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2133 struct sensor *sensor = to_sensor(client);
\r
2134 struct soc_camera_device *icd = client->dev.platform_data;
\r
2135 const struct v4l2_queryctrl *qctrl;
\r
2138 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
\r
2142 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
\r
2148 #if CONFIG_SENSOR_Brightness
\r
2149 case V4L2_CID_BRIGHTNESS:
\r
2151 if (ctrl->value != sensor->info_priv.brightness)
\r
2153 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
\r
2157 sensor->info_priv.brightness = ctrl->value;
\r
2162 #if CONFIG_SENSOR_Exposure
\r
2163 case V4L2_CID_EXPOSURE:
\r
2165 if (ctrl->value != sensor->info_priv.exposure)
\r
2167 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
\r
2171 sensor->info_priv.exposure = ctrl->value;
\r
2176 #if CONFIG_SENSOR_Saturation
\r
2177 case V4L2_CID_SATURATION:
\r
2179 if (ctrl->value != sensor->info_priv.saturation)
\r
2181 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
\r
2185 sensor->info_priv.saturation = ctrl->value;
\r
2190 #if CONFIG_SENSOR_Contrast
\r
2191 case V4L2_CID_CONTRAST:
\r
2193 if (ctrl->value != sensor->info_priv.contrast)
\r
2195 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
\r
2199 sensor->info_priv.contrast = ctrl->value;
\r
2204 #if CONFIG_SENSOR_WhiteBalance
\r
2205 case V4L2_CID_DO_WHITE_BALANCE:
\r
2207 if (ctrl->value != sensor->info_priv.whiteBalance)
\r
2209 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
\r
2213 sensor->info_priv.whiteBalance = ctrl->value;
\r
2218 #if CONFIG_SENSOR_Mirror
\r
2219 case V4L2_CID_HFLIP:
\r
2221 if (ctrl->value != sensor->info_priv.mirror)
\r
2223 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
\r
2225 sensor->info_priv.mirror = ctrl->value;
\r
2230 #if CONFIG_SENSOR_Flip
\r
2231 case V4L2_CID_VFLIP:
\r
2233 if (ctrl->value != sensor->info_priv.flip)
\r
2235 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
\r
2237 sensor->info_priv.flip = ctrl->value;
\r
2248 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
\r
2250 const struct v4l2_queryctrl *qctrl;
\r
2251 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2252 struct sensor *sensor = to_sensor(client);
\r
2254 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2258 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2262 switch (ext_ctrl->id)
\r
2264 case V4L2_CID_SCENE:
\r
2266 ext_ctrl->value = sensor->info_priv.scene;
\r
2269 case V4L2_CID_EFFECT:
\r
2271 ext_ctrl->value = sensor->info_priv.effect;
\r
2274 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2276 ext_ctrl->value = sensor->info_priv.digitalzoom;
\r
2279 case V4L2_CID_ZOOM_RELATIVE:
\r
2283 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2285 ext_ctrl->value = sensor->info_priv.focus;
\r
2288 case V4L2_CID_FOCUS_RELATIVE:
\r
2292 case V4L2_CID_FLASH:
\r
2294 ext_ctrl->value = sensor->info_priv.flash;
\r
2302 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
\r
2304 const struct v4l2_queryctrl *qctrl;
\r
2305 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
\r
2306 struct sensor *sensor = to_sensor(client);
\r
2309 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
\r
2313 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
\r
2318 switch (ext_ctrl->id)
\r
2320 #if CONFIG_SENSOR_Scene
\r
2321 case V4L2_CID_SCENE:
\r
2323 if (ext_ctrl->value != sensor->info_priv.scene)
\r
2325 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
\r
2327 sensor->info_priv.scene = ext_ctrl->value;
\r
2332 #if CONFIG_SENSOR_Effect
\r
2333 case V4L2_CID_EFFECT:
\r
2335 if (ext_ctrl->value != sensor->info_priv.effect)
\r
2337 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
\r
2339 sensor->info_priv.effect= ext_ctrl->value;
\r
2344 #if CONFIG_SENSOR_DigitalZoom
\r
2345 case V4L2_CID_ZOOM_ABSOLUTE:
\r
2347 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2350 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
\r
2352 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
\r
2354 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
\r
2356 sensor->info_priv.digitalzoom += val_offset;
\r
2358 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2363 case V4L2_CID_ZOOM_RELATIVE:
\r
2365 if (ext_ctrl->value)
\r
2367 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
\r
2369 sensor->info_priv.digitalzoom += ext_ctrl->value;
\r
2371 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
\r
2376 #if CONFIG_SENSOR_Focus
\r
2377 case V4L2_CID_FOCUS_ABSOLUTE:
\r
2379 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
\r
2382 if (ext_ctrl->value != sensor->info_priv.focus)
\r
2384 val_offset = ext_ctrl->value -sensor->info_priv.focus;
\r
2386 sensor->info_priv.focus += val_offset;
\r
2391 case V4L2_CID_FOCUS_RELATIVE:
\r
2393 if (ext_ctrl->value)
\r
2395 sensor->info_priv.focus += ext_ctrl->value;
\r
2397 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
\r
2402 #if CONFIG_SENSOR_Flash
\r
2403 case V4L2_CID_FLASH:
\r
2405 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
\r
2407 sensor->info_priv.flash = ext_ctrl->value;
\r
2409 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
\r
2420 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2422 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2423 struct soc_camera_device *icd = client->dev.platform_data;
\r
2424 int i, error_cnt=0, error_idx=-1;
\r
2427 for (i=0; i<ext_ctrl->count; i++) {
\r
2428 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2434 if (error_cnt > 1)
\r
2435 error_idx = ext_ctrl->count;
\r
2437 if (error_idx != -1) {
\r
2438 ext_ctrl->error_idx = error_idx;
\r
2445 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
\r
2447 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2448 struct soc_camera_device *icd = client->dev.platform_data;
\r
2449 int i, error_cnt=0, error_idx=-1;
\r
2452 for (i=0; i<ext_ctrl->count; i++) {
\r
2453 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
\r
2459 if (error_cnt > 1)
\r
2460 error_idx = ext_ctrl->count;
\r
2462 if (error_idx != -1) {
\r
2463 ext_ctrl->error_idx = error_idx;
\r
2470 /* Interface active, can use i2c. If it fails, it can indeed mean, that
\r
2471 * this wasn't our capture interface, so, we wait for the right one */
\r
2472 static int sensor_video_probe(struct soc_camera_device *icd,
\r
2473 struct i2c_client *client)
\r
2477 struct sensor *sensor = to_sensor(client);
\r
2479 /* We must have a parent by now. And it cannot be a wrong one.
\r
2480 * So this entire test is completely redundant. */
\r
2481 if (!icd->dev.parent ||
\r
2482 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
\r
2485 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
\r
2487 goto sensor_video_probe_err;
\r
2491 /* ret = sensor_write(client, 0x12, 0x80);
\r
2494 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
\r
2497 mdelay(50); *///delay 5 microseconds
\r
2498 sensor_write(client, 0x00, 0x01);
\r
2499 sensor_write(client, 0x03, 0x0a);
\r
2500 mdelay(100); //delay 5 microseconds
\r
2501 sensor_write(client, 0x00, 0x01);
\r
2502 sensor_write(client, 0x03, 0x0a);
\r
2503 mdelay(100); //delay 5 microseconds
\r
2505 /* check if it is an sensor sensor */
\r
2506 sensor_write(client, 0x00, 0x00);
\r
2508 ret = sensor_read(client, 0x01, &pid);
\r
2510 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
\r
2512 goto sensor_video_probe_err;
\r
2515 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2516 if (pid == SENSOR_ID) {
\r
2517 sensor->model = SENSOR_V4L2_IDENT;
\r
2519 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
\r
2521 goto sensor_video_probe_err;
\r
2526 sensor_video_probe_err:
\r
2531 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
\r
2533 struct i2c_client *client = v4l2_get_subdevdata(sd);
\r
2534 struct soc_camera_device *icd = client->dev.platform_data;
\r
2535 struct sensor *sensor = to_sensor(client);
\r
2541 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2544 case RK29_CAM_SUBDEV_DEACTIVATE:
\r
2546 sensor_deactivate(client);
\r
2550 case RK29_CAM_SUBDEV_IOREQUEST:
\r
2552 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
\r
2553 if (sensor->sensor_io_request != NULL) {
\r
2554 sensor->sensor_gpio_res = NULL;
\r
2555 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
\r
2556 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
\r
2557 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
\r
2558 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
\r
2561 if (sensor->sensor_gpio_res == NULL) {
\r
2562 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2564 goto sensor_ioctl_end;
\r
2567 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
\r
2569 goto sensor_ioctl_end;
\r
2571 /* 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
2572 for this project */
\r
2573 #if CONFIG_SENSOR_Flash
\r
2574 if (sensor->sensor_gpio_res) {
\r
2575 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
\r
2576 for (i = 0; i < icd->ops->num_controls; i++) {
\r
2577 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
\r
2578 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
\r
2581 sensor->info_priv.flash = 0xff;
\r
2582 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
\r
2590 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
\r
2598 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
\r
2599 enum v4l2_mbus_pixelcode *code)
\r
2601 if (index >= ARRAY_SIZE(sensor_colour_fmts))
\r
2604 *code = sensor_colour_fmts[index].code;
\r
2607 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
\r
2608 .init = sensor_init,
\r
2609 .g_ctrl = sensor_g_control,
\r
2610 .s_ctrl = sensor_s_control,
\r
2611 .g_ext_ctrls = sensor_g_ext_controls,
\r
2612 .s_ext_ctrls = sensor_s_ext_controls,
\r
2613 .g_chip_ident = sensor_g_chip_ident,
\r
2614 .ioctl = sensor_ioctl,
\r
2617 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
\r
2618 .s_mbus_fmt = sensor_s_fmt,
\r
2619 .g_mbus_fmt = sensor_g_fmt,
\r
2620 .try_mbus_fmt = sensor_try_fmt,
\r
2621 .enum_mbus_fmt = sensor_enum_fmt,
\r
2624 static struct v4l2_subdev_ops sensor_subdev_ops = {
\r
2625 .core = &sensor_subdev_core_ops,
\r
2626 .video = &sensor_subdev_video_ops,
\r
2629 static int sensor_probe(struct i2c_client *client,
\r
2630 const struct i2c_device_id *did)
\r
2632 struct sensor *sensor;
\r
2633 struct soc_camera_device *icd = client->dev.platform_data;
\r
2634 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
\r
2635 struct soc_camera_link *icl;
\r
2638 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
\r
2640 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
\r
2644 icl = to_soc_camera_link(icd);
\r
2646 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
\r
2650 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
\r
2651 dev_warn(&adapter->dev,
\r
2652 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
\r
2656 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
\r
2660 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
\r
2662 /* Second stage probe - when a capture adapter is there */
\r
2663 icd->ops = &sensor_ops;
\r
2665 sensor->info_priv.fmt = sensor_colour_fmts[0];
\r
2667 #if CONFIG_SENSOR_I2C_NOSCHED
\r
2668 atomic_set(&sensor->tasklock_cnt,0);
\r
2671 ret = sensor_video_probe(icd, client);
\r
2674 i2c_set_clientdata(client, NULL);
\r
2678 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
\r
2682 static int sensor_remove(struct i2c_client *client)
\r
2684 struct sensor *sensor = to_sensor(client);
\r
2685 struct soc_camera_device *icd = client->dev.platform_data;
\r
2688 i2c_set_clientdata(client, NULL);
\r
2689 client->driver = NULL;
\r
2695 static const struct i2c_device_id sensor_id[] = {
\r
2696 {SENSOR_NAME_STRING(), 0 },
\r
2699 MODULE_DEVICE_TABLE(i2c, sensor_id);
\r
2701 static struct i2c_driver sensor_i2c_driver = {
\r
2703 .name = SENSOR_NAME_STRING(),
\r
2705 .probe = sensor_probe,
\r
2706 .remove = sensor_remove,
\r
2707 .id_table = sensor_id,
\r
2710 static int __init sensor_mod_init(void)
\r
2712 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
\r
2713 return i2c_add_driver(&sensor_i2c_driver);
\r
2716 static void __exit sensor_mod_exit(void)
\r
2718 i2c_del_driver(&sensor_i2c_driver);
\r
2721 device_initcall_sync(sensor_mod_init);
\r
2722 module_exit(sensor_mod_exit);
\r
2724 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
\r
2725 MODULE_AUTHOR("ddl <kernel@rock-chips>");
\r
2726 MODULE_LICENSE("GPL");
\r