2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
20 #include <mach/spi_fpga.h>
22 #include <media/v4l2-common.h>
23 #include <media/v4l2-chip-ident.h>
24 #include <media/soc_camera.h>
26 #define _CONS(a,b) a##b
27 #define CONS(a,b) _CONS(a,b)
30 #define _STR(x) __STR(x)
31 #define STR(x) _STR(x)
33 /* Sensor Driver Configuration */
34 #define SENSOR_NAME ov9650
35 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV9650
36 #define SENSOR_ID 0x96
37 #define SENSOR_MIN_WIDTH 176
38 #define SENSOR_MIN_HEIGHT 144
39 #define SENSOR_MAX_WIDTH 1280
40 #define SENSOR_MAX_HEIGHT 1024
41 #define SENSOR_INIT_WIDTH 320 /* Sensor pixel size for sensor_init_data array */
42 #define SENSOR_INIT_HEIGHT 240
43 #define SENSOR_INIT_WINSEQADR sensor_qvga
45 #define CONFIG_SENSOR_WhiteBalance 1
46 #define CONFIG_SENSOR_Brightness 0
47 #define CONFIG_SENSOR_Contrast 0
48 #define CONFIG_SENSOR_Saturation 0
49 #define CONFIG_SENSOR_Effect 1
50 #define CONFIG_SENSOR_Scene 0
51 #define CONFIG_SENSOR_DigitalZoom 0
52 #define CONFIG_SENSOR_Focus 0
53 #define CONFIG_SENSOR_Exposure 0
54 #define CONFIG_SENSOR_Flash 0
55 #define CONFIG_SENSOR_Mirror 0
56 #define CONFIG_SENSOR_Flip 0
58 #define CONFIG_SENSOR_TR 1
59 #define CONFIG_SENSOR_DEBUG 1
61 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
62 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
64 #define MIN(x,y) ((x<y) ? x: y)
65 #define MAX(x,y) ((x>y) ? x: y)
67 #if (CONFIG_SENSOR_TR)
68 #define SENSOR_TR(format, ...) printk(format, ## __VA_ARGS__)
69 #if (CONFIG_SENSOR_DEBUG)
70 #define SENSOR_DG(format, ...) printk(format, ## __VA_ARGS__)
72 #define SENSOR_DG(format, ...)
75 #define SENSOR_TR(format, ...)
78 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
79 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
80 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
82 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
83 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
84 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
85 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
86 #define COLOR_TEMPERATURE_OFFICE_DN 3500
87 #define COLOR_TEMPERATURE_OFFICE_UP 5000
88 #define COLOR_TEMPERATURE_HOME_DN 2500
89 #define COLOR_TEMPERATURE_HOME_UP 3500
97 /* init 320X240 QVGA */
98 static struct reginfo sensor_init_data[] =
101 {0x11, 0x00},//0x82:Ϊ20Ø
\91£»//0x02£ºÎª10Ø
\91£»
104 {0x3b, 0x09}, // night mode
108 // {0x00, 0x00}, //jyk_0913, this setting is useless, but cause init unfinished!
116 {0x1e, 0x04},//34£ºµÚÒ»¸öˮƽÏßÓÐÒì³£ -> ;//04: <- ;//14: ;//Ðýת¶È
129 {0x14, 0x1e},//½µµÍÔöÒ棬¼õСÔêÉù
234 static struct reginfo sensor_sxga[] =
260 static struct reginfo sensor_svga[] =
266 static struct reginfo sensor_vga[] =
292 static struct reginfo sensor_cif[] =
311 static struct reginfo sensor_qvga[] =
336 static struct reginfo sensor_qcif[] =
354 #if CONFIG_SENSOR_WhiteBalance
355 static struct reginfo sensor_WhiteB_Auto[]=
357 {0x84, 0x6C}, //Contrast 4
381 {0x0f, 0x4a}, //Saturation 3
393 {0x4f, 0x2e}, //Brightness 3
407 /* Cloudy Colour Temperature : 6500K - 8000K */
408 static struct reginfo sensor_WhiteB_Cloudy[]=
410 {0x7C,0x04}, //Contrast 5
444 {0x4f,0x3a}, //Saturation 4
450 {0x4f, 0x2e}, //Brightness 3
463 /* ClearDay Colour Temperature : 5000K - 6500K */
464 static struct reginfo sensor_WhiteB_ClearDay[]=
467 {0x7C,0x04}, //Contrast 5
501 {0x4f,0x3a}, //Saturation 4
507 {0x4f, 0x2e}, //Brightness 3
520 /* Office Colour Temperature : 3500K - 5000K */
521 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
524 {0x84, 0x6C}, //Contrast 4
548 {0x0f, 0x4a}, //Saturation 3
560 {0x4f, 0x2e}, //Brightness 3
576 /* Home Colour Temperature : 2500K - 3500K */
577 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
580 {0x84, 0x6C}, //Contrast 4
604 {0x0f, 0x4a}, //Saturation 3
616 {0x4f, 0x2e}, //Brightness 3
629 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
630 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
634 #if CONFIG_SENSOR_Brightness
635 static struct reginfo sensor_Brightness0[]=
638 {0x3301, 0xff},//bit[7]:1, enable SDE
645 static struct reginfo sensor_Brightness1[]=
648 {0x3301, 0xff},//bit[7]:1, enable SDE
655 static struct reginfo sensor_Brightness2[]=
658 {0x3301, 0xff},//bit[7]:1, enable SDE
665 static struct reginfo sensor_Brightness3[]=
668 {0x3301, 0xff},//bit[7]:1, enable SDE
675 static struct reginfo sensor_Brightness4[]=
678 {0x3301, 0xff},//bit[7]:1, enable SDE
685 static struct reginfo sensor_Brightness5[]=
688 {0x3301, 0xff},//bit[7]:1, enable SDE
689 {0x3391, 0x04}, //bit[2] enable
690 {0x3390, 0x41}, //bit[3] sign of brightness
694 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
695 sensor_Brightness4, sensor_Brightness5,NULL,
700 #if CONFIG_SENSOR_Effect
701 static struct reginfo sensor_Effect_Normal[] =
709 static struct reginfo sensor_Effect_WandB[] =
717 static struct reginfo sensor_Effect_Sepia[] =
725 static struct reginfo sensor_Effect_Negative[] =
733 static struct reginfo sensor_Effect_Bluish[] =
742 static struct reginfo sensor_Effect_Green[] =
750 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
751 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
754 #if CONFIG_SENSOR_Exposure
755 static struct reginfo sensor_Exposure0[]=
760 static struct reginfo sensor_Exposure1[]=
765 static struct reginfo sensor_Exposure2[]=
770 static struct reginfo sensor_Exposure3[]=
775 static struct reginfo sensor_Exposure4[]=
780 static struct reginfo sensor_Exposure5[]=
785 static struct reginfo sensor_Exposure6[]=
790 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
791 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
794 #if CONFIG_SENSOR_Saturation
795 static struct reginfo sensor_Saturation0[]=
800 static struct reginfo sensor_Saturation1[]=
805 static struct reginfo sensor_Saturation2[]=
809 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
812 #if CONFIG_SENSOR_Contrast
813 static struct reginfo sensor_Contrast0[]=
818 static struct reginfo sensor_Contrast1[]=
823 static struct reginfo sensor_Contrast2[]=
828 static struct reginfo sensor_Contrast3[]=
833 static struct reginfo sensor_Contrast4[]=
839 static struct reginfo sensor_Contrast5[]=
844 static struct reginfo sensor_Contrast6[]=
848 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
849 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
853 #if CONFIG_SENSOR_Mirror
854 static struct reginfo sensor_MirrorOn[]=
859 static struct reginfo sensor_MirrorOff[]=
863 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
865 #if CONFIG_SENSOR_Flip
866 static struct reginfo sensor_FlipOn[]=
871 static struct reginfo sensor_FlipOff[]=
875 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
878 #if CONFIG_SENSOR_Scene
879 static struct reginfo sensor_SceneAuto[] =
884 static struct reginfo sensor_SceneNight[] =
888 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
891 #if CONFIG_SENSOR_DigitalZoom
892 static struct reginfo sensor_Zoom0[] =
897 static struct reginfo sensor_Zoom1[] =
902 static struct reginfo sensor_Zoom2[] =
908 static struct reginfo sensor_Zoom3[] =
912 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
914 static const struct v4l2_querymenu sensor_menus[] =
916 #if CONFIG_SENSOR_WhiteBalance
917 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
918 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
919 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
922 #if CONFIG_SENSOR_Effect
923 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
924 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
925 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
928 #if CONFIG_SENSOR_Scene
929 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
932 #if CONFIG_SENSOR_Flash
933 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
934 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
938 static const struct v4l2_queryctrl sensor_controls[] =
940 #if CONFIG_SENSOR_WhiteBalance
942 .id = V4L2_CID_DO_WHITE_BALANCE,
943 .type = V4L2_CTRL_TYPE_MENU,
944 .name = "White Balance Control",
952 #if CONFIG_SENSOR_Brightness
954 .id = V4L2_CID_BRIGHTNESS,
955 .type = V4L2_CTRL_TYPE_INTEGER,
956 .name = "Brightness Control",
964 #if CONFIG_SENSOR_Effect
966 .id = V4L2_CID_EFFECT,
967 .type = V4L2_CTRL_TYPE_MENU,
968 .name = "Effect Control",
976 #if CONFIG_SENSOR_Exposure
978 .id = V4L2_CID_EXPOSURE,
979 .type = V4L2_CTRL_TYPE_INTEGER,
980 .name = "Exposure Control",
988 #if CONFIG_SENSOR_Saturation
990 .id = V4L2_CID_SATURATION,
991 .type = V4L2_CTRL_TYPE_INTEGER,
992 .name = "Saturation Control",
1000 #if CONFIG_SENSOR_Contrast
1002 .id = V4L2_CID_CONTRAST,
1003 .type = V4L2_CTRL_TYPE_INTEGER,
1004 .name = "Contrast Control",
1012 #if CONFIG_SENSOR_Mirror
1014 .id = V4L2_CID_HFLIP,
1015 .type = V4L2_CTRL_TYPE_BOOLEAN,
1016 .name = "Mirror Control",
1024 #if CONFIG_SENSOR_Flip
1026 .id = V4L2_CID_VFLIP,
1027 .type = V4L2_CTRL_TYPE_BOOLEAN,
1028 .name = "Flip Control",
1036 #if CONFIG_SENSOR_Scene
1038 .id = V4L2_CID_SCENE,
1039 .type = V4L2_CTRL_TYPE_MENU,
1040 .name = "Scene Control",
1048 #if CONFIG_SENSOR_DigitalZoom
1050 .id = V4L2_CID_ZOOM_RELATIVE,
1051 .type = V4L2_CTRL_TYPE_INTEGER,
1052 .name = "DigitalZoom Control",
1058 .id = V4L2_CID_ZOOM_ABSOLUTE,
1059 .type = V4L2_CTRL_TYPE_INTEGER,
1060 .name = "DigitalZoom Control",
1068 #if CONFIG_SENSOR_Focus
1070 .id = V4L2_CID_FOCUS_RELATIVE,
1071 .type = V4L2_CTRL_TYPE_INTEGER,
1072 .name = "Focus Control",
1078 .id = V4L2_CID_FOCUS_ABSOLUTE,
1079 .type = V4L2_CTRL_TYPE_INTEGER,
1080 .name = "Focus Control",
1084 .default_value = 125,
1088 #if CONFIG_SENSOR_Flash
1090 .id = V4L2_CID_FLASH,
1091 .type = V4L2_CTRL_TYPE_MENU,
1092 .name = "Flash Control",
1101 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1102 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1103 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1104 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1105 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1106 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1107 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1108 static int sensor_resume(struct soc_camera_device *icd);
1109 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1110 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1112 static struct soc_camera_ops sensor_ops =
1114 .suspend = sensor_suspend,
1115 .resume = sensor_resume,
1116 .set_bus_param = sensor_set_bus_param,
1117 .query_bus_param = sensor_query_bus_param,
1118 .controls = sensor_controls,
1119 .menus = sensor_menus,
1120 .num_controls = ARRAY_SIZE(sensor_controls),
1121 .num_menus = ARRAY_SIZE(sensor_menus),
1124 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1125 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1126 .colorspace = _colorspace }
1128 #define JPG_FMT(_name, _depth, _fourcc) \
1129 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1131 static const struct soc_camera_data_format sensor_colour_formats[] = {
1132 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1133 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1136 typedef struct sensor_info_priv_s
1148 unsigned char mirror; /* HFLIP */
1149 unsigned char flip; /* VFLIP */
1150 unsigned int winseqe_cur_addr;
1152 } sensor_info_priv_t;
1156 struct v4l2_subdev subdev;
1157 struct i2c_client *client;
1158 sensor_info_priv_t info_priv;
1159 unsigned int pixfmt;
1160 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1163 static struct sensor* to_sensor(const struct i2c_client *client)
1165 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1168 /* sensor register write */
1169 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1173 struct i2c_msg msg[1];
1175 buf[0] = reg & 0xFF;
1178 msg->addr = client->addr;
1179 msg->flags = client->flags;
1181 msg->len = sizeof(buf);
1182 msg->scl_rate = 400*1000; /* ddl@rock-chips.com : 100kHz */
1183 msg->read_type = I2C_NORMAL;
1188 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1189 err = i2c_transfer(client->adapter, msg, 1);
1194 SENSOR_TR("\n %s write reg failed, try to write again!\n",SENSOR_NAME_STRING());
1202 /* sensor register read */
1203 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1207 struct i2c_msg msg[1];
1209 buf[0] = reg & 0xFF;
1211 msg->addr = client->addr;
1212 msg->flags = client->flags;
1214 msg->len = sizeof(buf);
1215 msg->scl_rate = 400*1000; /* ddl@rock-chips.com : 100kHz */
1216 i2c_transfer(client->adapter, msg, 1);
1217 msg->addr = client->addr;
1218 msg->flags = client->flags|I2C_M_RD;
1220 msg->len = 1; /* ddl@rock-chips.com : 100kHz */
1224 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1225 err = i2c_transfer(client->adapter, msg, 1);
1231 SENSOR_TR("\n %s write reg failed, try to read again!\n",SENSOR_NAME_STRING());
1239 /* write a array of registers */
1240 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1245 while (regarray[i].reg != 0)
1247 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1250 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1258 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1260 struct i2c_client *client = sd->priv;
1261 struct soc_camera_device *icd = client->dev.platform_data;
1262 struct sensor *sensor = to_sensor(client);
1263 const struct v4l2_queryctrl *qctrl;
1266 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1269 ret = sensor_write(client, 0x12, 0x80);
1272 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1274 goto sensor_INIT_ERR;
1277 mdelay(5); //delay 5 microseconds
1279 ret = sensor_write_array(client, sensor_init_data);
1282 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1283 goto sensor_INIT_ERR;
1286 icd->user_width = SENSOR_INIT_WIDTH;
1287 icd->user_height = SENSOR_INIT_HEIGHT;
1288 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1290 /* sensor sensor information for initialization */
1291 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1293 sensor->info_priv.whiteBalance = qctrl->default_value;
1294 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1296 sensor->info_priv.brightness = qctrl->default_value;
1297 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1299 sensor->info_priv.effect = qctrl->default_value;
1300 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1302 sensor->info_priv.exposure = qctrl->default_value;
1304 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1306 sensor->info_priv.saturation = qctrl->default_value;
1307 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1309 sensor->info_priv.contrast = qctrl->default_value;
1310 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1312 sensor->info_priv.mirror = qctrl->default_value;
1313 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1315 sensor->info_priv.flip = qctrl->default_value;
1316 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1318 sensor->info_priv.scene = qctrl->default_value;
1319 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1321 sensor->info_priv.digitalzoom = qctrl->default_value;
1323 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1324 #if CONFIG_SENSOR_Focus
1326 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1328 sensor->info_priv.focus = qctrl->default_value;
1331 #if CONFIG_SENSOR_Flash
1333 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1335 sensor->info_priv.flash = qctrl->default_value;
1338 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,icd->user_width,icd->user_height);
1345 static struct reginfo sensor_power_down_sequence[]=
1349 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1352 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1353 struct soc_camera_link *icl;
1356 if (pm_msg.event == PM_EVENT_SUSPEND)
1358 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1359 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1362 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1367 icl = to_soc_camera_link(icd);
1369 ret = icl->power(icd->pdev, 0);
1377 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1383 static int sensor_resume(struct soc_camera_device *icd)
1385 struct soc_camera_link *icl;
1388 icl = to_soc_camera_link(icd);
1390 ret = icl->power(icd->pdev, 0);
1399 static int sensor_set_bus_param(struct soc_camera_device *icd,
1400 unsigned long flags)
1406 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1408 struct soc_camera_link *icl = to_soc_camera_link(icd);
1409 unsigned long flags = SENSOR_BUS_PARAM;
1411 return soc_camera_apply_sensor_flags(icl, flags);
1414 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1416 struct i2c_client *client = sd->priv;
1417 struct soc_camera_device *icd = client->dev.platform_data;
1418 struct sensor *sensor = to_sensor(client);
1419 struct v4l2_pix_format *pix = &f->fmt.pix;
1421 pix->width = icd->user_width;
1422 pix->height = icd->user_height;
1423 pix->pixelformat = sensor->pixfmt;
1424 pix->field = V4L2_FIELD_NONE;
1425 pix->colorspace = V4L2_COLORSPACE_JPEG;
1429 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1431 struct i2c_client *client = sd->priv;
1432 struct sensor *sensor = to_sensor(client);
1433 struct v4l2_pix_format *pix = &f->fmt.pix;
1434 struct reginfo *winseqe_set_addr;
1435 int ret, set_w,set_h;
1438 set_h = pix->height;
1440 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1442 winseqe_set_addr = sensor_qcif;
1446 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1448 winseqe_set_addr = sensor_qvga;
1452 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1454 winseqe_set_addr = sensor_cif;
1458 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1460 winseqe_set_addr = sensor_vga;
1464 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1466 winseqe_set_addr = sensor_sxga;
1470 else if (sensor_qvga[0].reg)
1472 winseqe_set_addr = sensor_qvga; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1478 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1482 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1484 ret = sensor_write_array(client, winseqe_set_addr);
1487 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1491 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1494 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1498 SENSOR_TR("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1504 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1506 struct v4l2_pix_format *pix = &f->fmt.pix;
1507 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1508 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1511 * With Bayer format enforce even side lengths, but let the user play
1512 * with the starting pixel
1515 if (pix->height > SENSOR_MAX_HEIGHT)
1516 pix->height = SENSOR_MAX_HEIGHT;
1517 else if (pix->height < SENSOR_MIN_HEIGHT)
1518 pix->height = SENSOR_MIN_HEIGHT;
1520 pix->height = ALIGN(pix->height, 2);
1522 if (pix->width > SENSOR_MAX_WIDTH)
1523 pix->width = SENSOR_MAX_WIDTH;
1524 else if (pix->width < SENSOR_MIN_WIDTH)
1525 pix->width = SENSOR_MIN_WIDTH;
1527 pix->width = ALIGN(pix->width, 2);
1532 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1534 struct i2c_client *client = sd->priv;
1536 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1539 if (id->match.addr != client->addr)
1542 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1547 #if CONFIG_SENSOR_Brightness
1548 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1550 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1552 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1554 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1556 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1558 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1561 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1565 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1569 #if CONFIG_SENSOR_Effect
1570 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1572 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1574 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1576 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1578 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1580 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1583 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1587 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1591 #if CONFIG_SENSOR_Exposure
1592 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1594 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1596 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1598 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1600 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1602 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1605 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1609 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1613 #if CONFIG_SENSOR_Saturation
1614 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1616 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1618 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1620 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1622 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1624 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1627 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1631 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1635 #if CONFIG_SENSOR_Contrast
1636 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1638 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1640 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1642 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1644 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1646 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1649 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1653 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1657 #if CONFIG_SENSOR_Mirror
1658 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1660 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1662 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1664 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1666 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1668 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1671 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1675 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1679 #if CONFIG_SENSOR_Flip
1680 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1682 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1684 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1686 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1688 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1690 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1693 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1697 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1701 #if CONFIG_SENSOR_Scene
1702 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1704 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1706 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1708 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1710 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1712 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1715 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1719 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1723 #if CONFIG_SENSOR_WhiteBalance
1724 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1726 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1728 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1730 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1732 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1734 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1737 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1741 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1745 #if CONFIG_SENSOR_DigitalZoom
1746 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
1748 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1749 struct sensor *sensor = to_sensor(client);
1750 const struct v4l2_queryctrl *qctrl_info;
1751 int digitalzoom_cur, digitalzoom_total;
1753 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1757 digitalzoom_cur = sensor->info_priv.digitalzoom;
1758 digitalzoom_total = qctrl_info->maximum;
1760 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
1762 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1766 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
1768 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1772 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
1774 *value = digitalzoom_total - digitalzoom_cur;
1777 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
1779 *value = 0 - digitalzoom_cur;
1782 digitalzoom_cur += *value;
1784 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
1786 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
1788 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1791 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
1798 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1800 struct i2c_client *client = sd->priv;
1801 struct sensor *sensor = to_sensor(client);
1802 const struct v4l2_queryctrl *qctrl;
1804 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1808 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1814 case V4L2_CID_BRIGHTNESS:
1816 ctrl->value = sensor->info_priv.brightness;
1819 case V4L2_CID_SATURATION:
1821 ctrl->value = sensor->info_priv.saturation;
1824 case V4L2_CID_CONTRAST:
1826 ctrl->value = sensor->info_priv.contrast;
1829 case V4L2_CID_DO_WHITE_BALANCE:
1831 ctrl->value = sensor->info_priv.whiteBalance;
1834 case V4L2_CID_EXPOSURE:
1836 ctrl->value = sensor->info_priv.exposure;
1839 case V4L2_CID_HFLIP:
1841 ctrl->value = sensor->info_priv.mirror;
1844 case V4L2_CID_VFLIP:
1846 ctrl->value = sensor->info_priv.flip;
1857 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1859 struct i2c_client *client = sd->priv;
1860 struct sensor *sensor = to_sensor(client);
1861 struct soc_camera_device *icd = client->dev.platform_data;
1862 const struct v4l2_queryctrl *qctrl;
1865 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1869 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1875 #if CONFIG_SENSOR_Brightness
1876 case V4L2_CID_BRIGHTNESS:
1878 if (ctrl->value != sensor->info_priv.brightness)
1880 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
1884 sensor->info_priv.brightness = ctrl->value;
1889 #if CONFIG_SENSOR_Exposure
1890 case V4L2_CID_EXPOSURE:
1892 if (ctrl->value != sensor->info_priv.exposure)
1894 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
1898 sensor->info_priv.exposure = ctrl->value;
1903 #if CONFIG_SENSOR_Saturation
1904 case V4L2_CID_SATURATION:
1906 if (ctrl->value != sensor->info_priv.saturation)
1908 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
1912 sensor->info_priv.saturation = ctrl->value;
1917 #if CONFIG_SENSOR_Contrast
1918 case V4L2_CID_CONTRAST:
1920 if (ctrl->value != sensor->info_priv.contrast)
1922 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
1926 sensor->info_priv.contrast = ctrl->value;
1931 #if CONFIG_SENSOR_WhiteBalance
1932 case V4L2_CID_DO_WHITE_BALANCE:
1934 if (ctrl->value != sensor->info_priv.whiteBalance)
1936 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
1940 sensor->info_priv.whiteBalance = ctrl->value;
1945 #if CONFIG_SENSOR_Mirror
1946 case V4L2_CID_HFLIP:
1948 if (ctrl->value != sensor->info_priv.mirror)
1950 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
1952 sensor->info_priv.mirror = ctrl->value;
1957 #if CONFIG_SENSOR_Flip
1958 case V4L2_CID_VFLIP:
1960 if (ctrl->value != sensor->info_priv.flip)
1962 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
1964 sensor->info_priv.flip = ctrl->value;
1975 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
1977 const struct v4l2_queryctrl *qctrl;
1978 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1979 struct sensor *sensor = to_sensor(client);
1981 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
1985 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
1989 switch (ext_ctrl->id)
1991 case V4L2_CID_SCENE:
1993 ext_ctrl->value = sensor->info_priv.scene;
1996 case V4L2_CID_EFFECT:
1998 ext_ctrl->value = sensor->info_priv.effect;
2001 case V4L2_CID_ZOOM_ABSOLUTE:
2003 ext_ctrl->value = sensor->info_priv.digitalzoom;
2006 case V4L2_CID_ZOOM_RELATIVE:
2010 case V4L2_CID_FOCUS_ABSOLUTE:
2012 ext_ctrl->value = sensor->info_priv.focus;
2015 case V4L2_CID_FOCUS_RELATIVE:
2019 case V4L2_CID_FLASH:
2021 ext_ctrl->value = sensor->info_priv.flash;
2029 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2031 const struct v4l2_queryctrl *qctrl;
2032 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2033 struct sensor *sensor = to_sensor(client);
2036 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2040 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2045 switch (ext_ctrl->id)
2047 #if CONFIG_SENSOR_Scene
2048 case V4L2_CID_SCENE:
2050 if (ext_ctrl->value != sensor->info_priv.scene)
2052 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2054 sensor->info_priv.scene = ext_ctrl->value;
2059 #if CONFIG_SENSOR_Effect
2060 case V4L2_CID_EFFECT:
2062 if (ext_ctrl->value != sensor->info_priv.effect)
2064 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2066 sensor->info_priv.effect= ext_ctrl->value;
2071 #if CONFIG_SENSOR_DigitalZoom
2072 case V4L2_CID_ZOOM_ABSOLUTE:
2074 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2077 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2079 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2081 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2083 sensor->info_priv.digitalzoom += val_offset;
2085 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2090 case V4L2_CID_ZOOM_RELATIVE:
2092 if (ext_ctrl->value)
2094 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2096 sensor->info_priv.digitalzoom += ext_ctrl->value;
2098 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2103 #if CONFIG_SENSOR_Focus
2104 case V4L2_CID_FOCUS_ABSOLUTE:
2106 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2109 if (ext_ctrl->value != sensor->info_priv.focus)
2111 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2113 sensor->info_priv.focus += val_offset;
2118 case V4L2_CID_FOCUS_RELATIVE:
2120 if (ext_ctrl->value)
2122 sensor->info_priv.focus += ext_ctrl->value;
2124 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2129 #if CONFIG_SENSOR_Flash
2130 case V4L2_CID_FLASH:
2132 sensor->info_priv.flash = ext_ctrl->value;
2134 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2145 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2147 struct i2c_client *client = sd->priv;
2148 struct soc_camera_device *icd = client->dev.platform_data;
2149 int i, error_cnt=0, error_idx=-1;
2152 for (i=0; i<ext_ctrl->count; i++) {
2153 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2160 error_idx = ext_ctrl->count;
2162 if (error_idx != -1) {
2163 ext_ctrl->error_idx = error_idx;
2170 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2172 struct i2c_client *client = sd->priv;
2173 struct soc_camera_device *icd = client->dev.platform_data;
2174 int i, error_cnt=0, error_idx=-1;
2177 for (i=0; i<ext_ctrl->count; i++) {
2178 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2185 error_idx = ext_ctrl->count;
2187 if (error_idx != -1) {
2188 ext_ctrl->error_idx = error_idx;
2195 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2196 * this wasn't our capture interface, so, we wait for the right one */
2197 static int sensor_video_probe(struct soc_camera_device *icd,
2198 struct i2c_client *client)
2202 struct sensor *sensor = to_sensor(client);
2204 /* We must have a parent by now. And it cannot be a wrong one.
2205 * So this entire test is completely redundant. */
2206 if (!icd->dev.parent ||
2207 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2211 ret = sensor_write(client, 0x12, 0x80);
2214 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2217 mdelay(5); //delay 5 microseconds
2219 /* check if it is an sensor sensor */
2220 ret = sensor_read(client, 0x0a, &pid);
2222 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2224 goto sensor_video_probe_err;
2227 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2228 if (pid == SENSOR_ID) {
2229 sensor->model = SENSOR_V4L2_IDENT;
2231 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2233 goto sensor_video_probe_err;
2236 icd->formats = sensor_colour_formats;
2237 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2241 sensor_video_probe_err:
2246 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2247 .init = sensor_init,
2248 .g_ctrl = sensor_g_control,
2249 .s_ctrl = sensor_s_control,
2250 .g_ext_ctrls = sensor_g_ext_controls,
2251 .s_ext_ctrls = sensor_s_ext_controls,
2252 .g_chip_ident = sensor_g_chip_ident,
2255 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2256 .s_fmt = sensor_s_fmt,
2257 .g_fmt = sensor_g_fmt,
2258 .try_fmt = sensor_try_fmt,
2261 static struct v4l2_subdev_ops sensor_subdev_ops = {
2262 .core = &sensor_subdev_core_ops,
2263 .video = &sensor_subdev_video_ops,
2266 static int sensor_probe(struct i2c_client *client,
2267 const struct i2c_device_id *did)
2269 struct sensor *sensor;
2270 struct soc_camera_device *icd = client->dev.platform_data;
2271 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2272 struct soc_camera_link *icl;
2275 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2277 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2281 icl = to_soc_camera_link(icd);
2283 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2287 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2288 dev_warn(&adapter->dev,
2289 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2293 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2297 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2299 /* Second stage probe - when a capture adapter is there */
2300 icd->ops = &sensor_ops;
2301 icd->y_skip_top = 0;
2303 ret = sensor_video_probe(icd, client);
2306 i2c_set_clientdata(client, NULL);
2309 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2313 static int sensor_remove(struct i2c_client *client)
2315 struct sensor *sensor = to_sensor(client);
2316 struct soc_camera_device *icd = client->dev.platform_data;
2319 i2c_set_clientdata(client, NULL);
2320 client->driver = NULL;
2326 static const struct i2c_device_id sensor_id[] = {
2327 {SENSOR_NAME_STRING(), 0 },
2330 MODULE_DEVICE_TABLE(i2c, sensor_id);
2332 static struct i2c_driver sensor_i2c_driver = {
2334 .name = SENSOR_NAME_STRING(),
2336 .probe = sensor_probe,
2337 .remove = sensor_remove,
2338 .id_table = sensor_id,
2341 static int __init sensor_mod_init(void)
2343 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2344 return i2c_add_driver(&sensor_i2c_driver);
2347 static void __exit sensor_mod_exit(void)
2349 i2c_del_driver(&sensor_i2c_driver);
2352 device_initcall_sync(sensor_mod_init);
2353 module_exit(sensor_mod_exit);
2355 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2356 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2357 MODULE_LICENSE("GPL");