2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
23 #define _CONS(a,b) a##b
24 #define CONS(a,b) _CONS(a,b)
27 #define _STR(x) __STR(x)
28 #define STR(x) _STR(x)
30 /* Sensor Driver Configuration */
31 #define SENSOR_NAME ov9650
32 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV9650
33 #define SENSOR_ID 0x96
34 #define SENSOR_MIN_WIDTH 176
35 #define SENSOR_MIN_HEIGHT 144
36 #define SENSOR_MAX_WIDTH 1280
37 #define SENSOR_MAX_HEIGHT 1024
38 #define SENSOR_INIT_WIDTH 320 /* Sensor pixel size for sensor_init_data array */
39 #define SENSOR_INIT_HEIGHT 240
40 #define SENSOR_INIT_WINSEQADR sensor_qvga
42 #define CONFIG_SENSOR_WhiteBalance 1
43 #define CONFIG_SENSOR_Brightness 0
44 #define CONFIG_SENSOR_Contrast 0
45 #define CONFIG_SENSOR_Saturation 0
46 #define CONFIG_SENSOR_Effect 1
47 #define CONFIG_SENSOR_Scene 0
48 #define CONFIG_SENSOR_DigitalZoom 0
49 #define CONFIG_SENSOR_Focus 0
50 #define CONFIG_SENSOR_Exposure 0
51 #define CONFIG_SENSOR_Flash 0
52 #define CONFIG_SENSOR_Mirror 0
53 #define CONFIG_SENSOR_Flip 0
55 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
57 #define CONFIG_SENSOR_TR 1
58 #define CONFIG_SENSOR_DEBUG 1
60 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
61 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
63 #define MIN(x,y) ((x<y) ? x: y)
64 #define MAX(x,y) ((x>y) ? x: y)
66 #if (CONFIG_SENSOR_TR)
67 #define SENSOR_TR(format, ...) printk(format, ## __VA_ARGS__)
68 #if (CONFIG_SENSOR_DEBUG)
69 #define SENSOR_DG(format, ...) printk(format, ## __VA_ARGS__)
71 #define SENSOR_DG(format, ...)
74 #define SENSOR_TR(format, ...)
77 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
78 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
79 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
81 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
82 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
83 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
84 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
85 #define COLOR_TEMPERATURE_OFFICE_DN 3500
86 #define COLOR_TEMPERATURE_OFFICE_UP 5000
87 #define COLOR_TEMPERATURE_HOME_DN 2500
88 #define COLOR_TEMPERATURE_HOME_UP 3500
96 /* init 320X240 QVGA */
97 static struct reginfo sensor_init_data[] =
100 {0x11, 0x00},//0x82:Ϊ20Ø
\91£»//0x02£ºÎª10Ø
\91£»
103 {0x3b, 0x09}, // night mode
107 // {0x00, 0x00}, //jyk_0913, this setting is useless, but cause init unfinished!
115 {0x1e, 0x24},//34£ºµÚÒ»¸öˮƽÏßÓÐÒì³£ -> ;//04: <- ;//14: ;//Ðýת¶È
128 {0x14, 0x1e},//½µµÍÔöÒ棬¼õСÔêÉù
233 static struct reginfo sensor_sxga[] =
259 static struct reginfo sensor_svga[] =
265 static struct reginfo sensor_vga[] =
291 static struct reginfo sensor_cif[] =
310 static struct reginfo sensor_qvga[] =
335 static struct reginfo sensor_qcif[] =
353 #if CONFIG_SENSOR_WhiteBalance
354 static struct reginfo sensor_WhiteB_Auto[]=
356 {0x84, 0x6C}, //Contrast 4
380 {0x0f, 0x4a}, //Saturation 3
392 {0x4f, 0x2e}, //Brightness 3
406 /* Cloudy Colour Temperature : 6500K - 8000K */
407 static struct reginfo sensor_WhiteB_Cloudy[]=
409 {0x7C,0x04}, //Contrast 5
443 {0x4f,0x3a}, //Saturation 4
449 {0x4f, 0x2e}, //Brightness 3
462 /* ClearDay Colour Temperature : 5000K - 6500K */
463 static struct reginfo sensor_WhiteB_ClearDay[]=
466 {0x7C,0x04}, //Contrast 5
500 {0x4f,0x3a}, //Saturation 4
506 {0x4f, 0x2e}, //Brightness 3
519 /* Office Colour Temperature : 3500K - 5000K */
520 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
523 {0x84, 0x6C}, //Contrast 4
547 {0x0f, 0x4a}, //Saturation 3
559 {0x4f, 0x2e}, //Brightness 3
575 /* Home Colour Temperature : 2500K - 3500K */
576 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
579 {0x84, 0x6C}, //Contrast 4
603 {0x0f, 0x4a}, //Saturation 3
615 {0x4f, 0x2e}, //Brightness 3
628 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
629 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
633 #if CONFIG_SENSOR_Brightness
634 static struct reginfo sensor_Brightness0[]=
637 {0x3301, 0xff},//bit[7]:1, enable SDE
644 static struct reginfo sensor_Brightness1[]=
647 {0x3301, 0xff},//bit[7]:1, enable SDE
654 static struct reginfo sensor_Brightness2[]=
657 {0x3301, 0xff},//bit[7]:1, enable SDE
664 static struct reginfo sensor_Brightness3[]=
667 {0x3301, 0xff},//bit[7]:1, enable SDE
674 static struct reginfo sensor_Brightness4[]=
677 {0x3301, 0xff},//bit[7]:1, enable SDE
684 static struct reginfo sensor_Brightness5[]=
687 {0x3301, 0xff},//bit[7]:1, enable SDE
688 {0x3391, 0x04}, //bit[2] enable
689 {0x3390, 0x41}, //bit[3] sign of brightness
693 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
694 sensor_Brightness4, sensor_Brightness5,NULL,
699 #if CONFIG_SENSOR_Effect
700 static struct reginfo sensor_Effect_Normal[] =
708 static struct reginfo sensor_Effect_WandB[] =
716 static struct reginfo sensor_Effect_Sepia[] =
724 static struct reginfo sensor_Effect_Negative[] =
732 static struct reginfo sensor_Effect_Bluish[] =
741 static struct reginfo sensor_Effect_Green[] =
749 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
750 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
753 #if CONFIG_SENSOR_Exposure
754 static struct reginfo sensor_Exposure0[]=
759 static struct reginfo sensor_Exposure1[]=
764 static struct reginfo sensor_Exposure2[]=
769 static struct reginfo sensor_Exposure3[]=
774 static struct reginfo sensor_Exposure4[]=
779 static struct reginfo sensor_Exposure5[]=
784 static struct reginfo sensor_Exposure6[]=
789 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
790 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
793 #if CONFIG_SENSOR_Saturation
794 static struct reginfo sensor_Saturation0[]=
799 static struct reginfo sensor_Saturation1[]=
804 static struct reginfo sensor_Saturation2[]=
808 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
811 #if CONFIG_SENSOR_Contrast
812 static struct reginfo sensor_Contrast0[]=
817 static struct reginfo sensor_Contrast1[]=
822 static struct reginfo sensor_Contrast2[]=
827 static struct reginfo sensor_Contrast3[]=
832 static struct reginfo sensor_Contrast4[]=
838 static struct reginfo sensor_Contrast5[]=
843 static struct reginfo sensor_Contrast6[]=
847 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
848 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
852 #if CONFIG_SENSOR_Mirror
853 static struct reginfo sensor_MirrorOn[]=
858 static struct reginfo sensor_MirrorOff[]=
862 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
864 #if CONFIG_SENSOR_Flip
865 static struct reginfo sensor_FlipOn[]=
870 static struct reginfo sensor_FlipOff[]=
874 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
877 #if CONFIG_SENSOR_Scene
878 static struct reginfo sensor_SceneAuto[] =
883 static struct reginfo sensor_SceneNight[] =
887 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
890 #if CONFIG_SENSOR_DigitalZoom
891 static struct reginfo sensor_Zoom0[] =
896 static struct reginfo sensor_Zoom1[] =
901 static struct reginfo sensor_Zoom2[] =
907 static struct reginfo sensor_Zoom3[] =
911 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
913 static const struct v4l2_querymenu sensor_menus[] =
915 #if CONFIG_SENSOR_WhiteBalance
916 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
917 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
918 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
921 #if CONFIG_SENSOR_Effect
922 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
923 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
924 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
927 #if CONFIG_SENSOR_Scene
928 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
931 #if CONFIG_SENSOR_Flash
932 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
933 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
937 static const struct v4l2_queryctrl sensor_controls[] =
939 #if CONFIG_SENSOR_WhiteBalance
941 .id = V4L2_CID_DO_WHITE_BALANCE,
942 .type = V4L2_CTRL_TYPE_MENU,
943 .name = "White Balance Control",
951 #if CONFIG_SENSOR_Brightness
953 .id = V4L2_CID_BRIGHTNESS,
954 .type = V4L2_CTRL_TYPE_INTEGER,
955 .name = "Brightness Control",
963 #if CONFIG_SENSOR_Effect
965 .id = V4L2_CID_EFFECT,
966 .type = V4L2_CTRL_TYPE_MENU,
967 .name = "Effect Control",
975 #if CONFIG_SENSOR_Exposure
977 .id = V4L2_CID_EXPOSURE,
978 .type = V4L2_CTRL_TYPE_INTEGER,
979 .name = "Exposure Control",
987 #if CONFIG_SENSOR_Saturation
989 .id = V4L2_CID_SATURATION,
990 .type = V4L2_CTRL_TYPE_INTEGER,
991 .name = "Saturation Control",
999 #if CONFIG_SENSOR_Contrast
1001 .id = V4L2_CID_CONTRAST,
1002 .type = V4L2_CTRL_TYPE_INTEGER,
1003 .name = "Contrast Control",
1011 #if CONFIG_SENSOR_Mirror
1013 .id = V4L2_CID_HFLIP,
1014 .type = V4L2_CTRL_TYPE_BOOLEAN,
1015 .name = "Mirror Control",
1023 #if CONFIG_SENSOR_Flip
1025 .id = V4L2_CID_VFLIP,
1026 .type = V4L2_CTRL_TYPE_BOOLEAN,
1027 .name = "Flip Control",
1035 #if CONFIG_SENSOR_Scene
1037 .id = V4L2_CID_SCENE,
1038 .type = V4L2_CTRL_TYPE_MENU,
1039 .name = "Scene Control",
1047 #if CONFIG_SENSOR_DigitalZoom
1049 .id = V4L2_CID_ZOOM_RELATIVE,
1050 .type = V4L2_CTRL_TYPE_INTEGER,
1051 .name = "DigitalZoom Control",
1057 .id = V4L2_CID_ZOOM_ABSOLUTE,
1058 .type = V4L2_CTRL_TYPE_INTEGER,
1059 .name = "DigitalZoom Control",
1067 #if CONFIG_SENSOR_Focus
1069 .id = V4L2_CID_FOCUS_RELATIVE,
1070 .type = V4L2_CTRL_TYPE_INTEGER,
1071 .name = "Focus Control",
1077 .id = V4L2_CID_FOCUS_ABSOLUTE,
1078 .type = V4L2_CTRL_TYPE_INTEGER,
1079 .name = "Focus Control",
1083 .default_value = 125,
1087 #if CONFIG_SENSOR_Flash
1089 .id = V4L2_CID_FLASH,
1090 .type = V4L2_CTRL_TYPE_MENU,
1091 .name = "Flash Control",
1100 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1101 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1102 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1103 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1104 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1105 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1106 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1107 static int sensor_resume(struct soc_camera_device *icd);
1108 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1109 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1111 static struct soc_camera_ops sensor_ops =
1113 .suspend = sensor_suspend,
1114 .resume = sensor_resume,
1115 .set_bus_param = sensor_set_bus_param,
1116 .query_bus_param = sensor_query_bus_param,
1117 .controls = sensor_controls,
1118 .menus = sensor_menus,
1119 .num_controls = ARRAY_SIZE(sensor_controls),
1120 .num_menus = ARRAY_SIZE(sensor_menus),
1123 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1124 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1125 .colorspace = _colorspace }
1127 #define JPG_FMT(_name, _depth, _fourcc) \
1128 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1130 static const struct soc_camera_data_format sensor_colour_formats[] = {
1131 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1132 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1135 typedef struct sensor_info_priv_s
1147 unsigned char mirror; /* HFLIP */
1148 unsigned char flip; /* VFLIP */
1149 unsigned int winseqe_cur_addr;
1151 } sensor_info_priv_t;
1155 struct v4l2_subdev subdev;
1156 struct i2c_client *client;
1157 sensor_info_priv_t info_priv;
1158 unsigned int pixfmt;
1159 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1162 static struct sensor* to_sensor(const struct i2c_client *client)
1164 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1167 /* sensor register write */
1168 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1172 struct i2c_msg msg[1];
1174 buf[0] = reg & 0xFF;
1177 msg->addr = client->addr;
1178 msg->flags = client->flags;
1180 msg->len = sizeof(buf);
1181 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1182 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1187 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1188 err = i2c_transfer(client->adapter, msg, 1);
1193 SENSOR_TR("\n %s write reg failed, try to write again!\n",SENSOR_NAME_STRING());
1201 /* sensor register read */
1202 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1206 struct i2c_msg msg[2];
1209 buf[1] = reg & 0xFF;
1211 msg[0].addr = client->addr;
1212 msg[0].flags = client->flags;
1214 msg[0].len = sizeof(buf);
1215 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1216 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1218 msg[1].addr = client->addr;
1219 msg[1].flags = client->flags|I2C_M_RD;
1222 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1223 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1227 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1228 err = i2c_transfer(client->adapter, msg, 2);
1234 SENSOR_TR("\n %s read reg failed, try to read again! reg:0x%x \n",SENSOR_NAME_STRING(),val);
1242 /* write a array of registers */
1243 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1248 while (regarray[i].reg != 0)
1250 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1253 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1261 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1263 struct i2c_client *client = sd->priv;
1264 struct soc_camera_device *icd = client->dev.platform_data;
1265 struct sensor *sensor = to_sensor(client);
1266 const struct v4l2_queryctrl *qctrl;
1269 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1272 ret = sensor_write(client, 0x12, 0x80);
1275 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1277 goto sensor_INIT_ERR;
1280 mdelay(5); //delay 5 microseconds
1282 ret = sensor_write_array(client, sensor_init_data);
1285 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1286 goto sensor_INIT_ERR;
1289 icd->user_width = SENSOR_INIT_WIDTH;
1290 icd->user_height = SENSOR_INIT_HEIGHT;
1291 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1293 /* sensor sensor information for initialization */
1294 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1296 sensor->info_priv.whiteBalance = qctrl->default_value;
1297 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1299 sensor->info_priv.brightness = qctrl->default_value;
1300 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1302 sensor->info_priv.effect = qctrl->default_value;
1303 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1305 sensor->info_priv.exposure = qctrl->default_value;
1307 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1309 sensor->info_priv.saturation = qctrl->default_value;
1310 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1312 sensor->info_priv.contrast = qctrl->default_value;
1313 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1315 sensor->info_priv.mirror = qctrl->default_value;
1316 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1318 sensor->info_priv.flip = qctrl->default_value;
1319 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1321 sensor->info_priv.scene = qctrl->default_value;
1322 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1324 sensor->info_priv.digitalzoom = qctrl->default_value;
1326 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1327 #if CONFIG_SENSOR_Focus
1329 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1331 sensor->info_priv.focus = qctrl->default_value;
1334 #if CONFIG_SENSOR_Flash
1336 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1338 sensor->info_priv.flash = qctrl->default_value;
1341 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,icd->user_width,icd->user_height);
1348 static struct reginfo sensor_power_down_sequence[]=
1352 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1355 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1356 struct soc_camera_link *icl;
1359 if (pm_msg.event == PM_EVENT_SUSPEND)
1361 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1362 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1365 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1370 icl = to_soc_camera_link(icd);
1372 ret = icl->power(icd->pdev, 0);
1380 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1386 static int sensor_resume(struct soc_camera_device *icd)
1388 struct soc_camera_link *icl;
1391 icl = to_soc_camera_link(icd);
1393 ret = icl->power(icd->pdev, 0);
1402 static int sensor_set_bus_param(struct soc_camera_device *icd,
1403 unsigned long flags)
1409 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1411 struct soc_camera_link *icl = to_soc_camera_link(icd);
1412 unsigned long flags = SENSOR_BUS_PARAM;
1414 return soc_camera_apply_sensor_flags(icl, flags);
1417 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1419 struct i2c_client *client = sd->priv;
1420 struct soc_camera_device *icd = client->dev.platform_data;
1421 struct sensor *sensor = to_sensor(client);
1422 struct v4l2_pix_format *pix = &f->fmt.pix;
1424 pix->width = icd->user_width;
1425 pix->height = icd->user_height;
1426 pix->pixelformat = sensor->pixfmt;
1427 pix->field = V4L2_FIELD_NONE;
1428 pix->colorspace = V4L2_COLORSPACE_JPEG;
1432 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1434 struct i2c_client *client = sd->priv;
1435 struct sensor *sensor = to_sensor(client);
1436 struct v4l2_pix_format *pix = &f->fmt.pix;
1437 struct reginfo *winseqe_set_addr;
1438 int ret, set_w,set_h;
1441 set_h = pix->height;
1443 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1445 winseqe_set_addr = sensor_qcif;
1449 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1451 winseqe_set_addr = sensor_qvga;
1455 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1457 winseqe_set_addr = sensor_cif;
1461 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1463 winseqe_set_addr = sensor_vga;
1467 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1469 winseqe_set_addr = sensor_sxga;
1473 else if (sensor_qvga[0].reg)
1475 winseqe_set_addr = sensor_qvga; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1481 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1485 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1487 ret = sensor_write_array(client, winseqe_set_addr);
1490 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1494 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1497 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1501 SENSOR_TR("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1507 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1509 struct v4l2_pix_format *pix = &f->fmt.pix;
1510 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1511 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1514 * With Bayer format enforce even side lengths, but let the user play
1515 * with the starting pixel
1518 if (pix->height > SENSOR_MAX_HEIGHT)
1519 pix->height = SENSOR_MAX_HEIGHT;
1520 else if (pix->height < SENSOR_MIN_HEIGHT)
1521 pix->height = SENSOR_MIN_HEIGHT;
1523 pix->height = ALIGN(pix->height, 2);
1525 if (pix->width > SENSOR_MAX_WIDTH)
1526 pix->width = SENSOR_MAX_WIDTH;
1527 else if (pix->width < SENSOR_MIN_WIDTH)
1528 pix->width = SENSOR_MIN_WIDTH;
1530 pix->width = ALIGN(pix->width, 2);
1535 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1537 struct i2c_client *client = sd->priv;
1539 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1542 if (id->match.addr != client->addr)
1545 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1550 #if CONFIG_SENSOR_Brightness
1551 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1553 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1555 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1557 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1559 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1561 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1564 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1568 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1572 #if CONFIG_SENSOR_Effect
1573 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1575 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1577 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1579 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1581 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1583 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1586 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1590 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1594 #if CONFIG_SENSOR_Exposure
1595 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1597 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1599 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1601 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1603 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1605 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1608 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1612 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1616 #if CONFIG_SENSOR_Saturation
1617 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1619 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1621 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1623 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1625 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1627 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1630 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1634 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1638 #if CONFIG_SENSOR_Contrast
1639 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1641 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1643 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1645 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1647 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1649 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1652 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1656 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1660 #if CONFIG_SENSOR_Mirror
1661 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1663 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1665 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1667 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1669 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1671 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1674 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1678 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1682 #if CONFIG_SENSOR_Flip
1683 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1685 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1687 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1689 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1691 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1693 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1696 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1700 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1704 #if CONFIG_SENSOR_Scene
1705 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1707 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1709 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1711 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1713 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1715 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1718 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1722 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1726 #if CONFIG_SENSOR_WhiteBalance
1727 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1729 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1731 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1733 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1735 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1737 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1740 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1744 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1748 #if CONFIG_SENSOR_DigitalZoom
1749 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
1751 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1752 struct sensor *sensor = to_sensor(client);
1753 const struct v4l2_queryctrl *qctrl_info;
1754 int digitalzoom_cur, digitalzoom_total;
1756 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1760 digitalzoom_cur = sensor->info_priv.digitalzoom;
1761 digitalzoom_total = qctrl_info->maximum;
1763 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
1765 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1769 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
1771 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1775 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
1777 *value = digitalzoom_total - digitalzoom_cur;
1780 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
1782 *value = 0 - digitalzoom_cur;
1785 digitalzoom_cur += *value;
1787 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
1789 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
1791 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1794 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
1801 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1803 struct i2c_client *client = sd->priv;
1804 struct sensor *sensor = to_sensor(client);
1805 const struct v4l2_queryctrl *qctrl;
1807 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1811 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1817 case V4L2_CID_BRIGHTNESS:
1819 ctrl->value = sensor->info_priv.brightness;
1822 case V4L2_CID_SATURATION:
1824 ctrl->value = sensor->info_priv.saturation;
1827 case V4L2_CID_CONTRAST:
1829 ctrl->value = sensor->info_priv.contrast;
1832 case V4L2_CID_DO_WHITE_BALANCE:
1834 ctrl->value = sensor->info_priv.whiteBalance;
1837 case V4L2_CID_EXPOSURE:
1839 ctrl->value = sensor->info_priv.exposure;
1842 case V4L2_CID_HFLIP:
1844 ctrl->value = sensor->info_priv.mirror;
1847 case V4L2_CID_VFLIP:
1849 ctrl->value = sensor->info_priv.flip;
1860 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1862 struct i2c_client *client = sd->priv;
1863 struct sensor *sensor = to_sensor(client);
1864 struct soc_camera_device *icd = client->dev.platform_data;
1865 const struct v4l2_queryctrl *qctrl;
1868 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1872 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1878 #if CONFIG_SENSOR_Brightness
1879 case V4L2_CID_BRIGHTNESS:
1881 if (ctrl->value != sensor->info_priv.brightness)
1883 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
1887 sensor->info_priv.brightness = ctrl->value;
1892 #if CONFIG_SENSOR_Exposure
1893 case V4L2_CID_EXPOSURE:
1895 if (ctrl->value != sensor->info_priv.exposure)
1897 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
1901 sensor->info_priv.exposure = ctrl->value;
1906 #if CONFIG_SENSOR_Saturation
1907 case V4L2_CID_SATURATION:
1909 if (ctrl->value != sensor->info_priv.saturation)
1911 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
1915 sensor->info_priv.saturation = ctrl->value;
1920 #if CONFIG_SENSOR_Contrast
1921 case V4L2_CID_CONTRAST:
1923 if (ctrl->value != sensor->info_priv.contrast)
1925 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
1929 sensor->info_priv.contrast = ctrl->value;
1934 #if CONFIG_SENSOR_WhiteBalance
1935 case V4L2_CID_DO_WHITE_BALANCE:
1937 if (ctrl->value != sensor->info_priv.whiteBalance)
1939 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
1943 sensor->info_priv.whiteBalance = ctrl->value;
1948 #if CONFIG_SENSOR_Mirror
1949 case V4L2_CID_HFLIP:
1951 if (ctrl->value != sensor->info_priv.mirror)
1953 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
1955 sensor->info_priv.mirror = ctrl->value;
1960 #if CONFIG_SENSOR_Flip
1961 case V4L2_CID_VFLIP:
1963 if (ctrl->value != sensor->info_priv.flip)
1965 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
1967 sensor->info_priv.flip = ctrl->value;
1978 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
1980 const struct v4l2_queryctrl *qctrl;
1981 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1982 struct sensor *sensor = to_sensor(client);
1984 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
1988 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
1992 switch (ext_ctrl->id)
1994 case V4L2_CID_SCENE:
1996 ext_ctrl->value = sensor->info_priv.scene;
1999 case V4L2_CID_EFFECT:
2001 ext_ctrl->value = sensor->info_priv.effect;
2004 case V4L2_CID_ZOOM_ABSOLUTE:
2006 ext_ctrl->value = sensor->info_priv.digitalzoom;
2009 case V4L2_CID_ZOOM_RELATIVE:
2013 case V4L2_CID_FOCUS_ABSOLUTE:
2015 ext_ctrl->value = sensor->info_priv.focus;
2018 case V4L2_CID_FOCUS_RELATIVE:
2022 case V4L2_CID_FLASH:
2024 ext_ctrl->value = sensor->info_priv.flash;
2032 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2034 const struct v4l2_queryctrl *qctrl;
2035 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2036 struct sensor *sensor = to_sensor(client);
2039 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2043 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2048 switch (ext_ctrl->id)
2050 #if CONFIG_SENSOR_Scene
2051 case V4L2_CID_SCENE:
2053 if (ext_ctrl->value != sensor->info_priv.scene)
2055 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2057 sensor->info_priv.scene = ext_ctrl->value;
2062 #if CONFIG_SENSOR_Effect
2063 case V4L2_CID_EFFECT:
2065 if (ext_ctrl->value != sensor->info_priv.effect)
2067 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2069 sensor->info_priv.effect= ext_ctrl->value;
2074 #if CONFIG_SENSOR_DigitalZoom
2075 case V4L2_CID_ZOOM_ABSOLUTE:
2077 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2080 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2082 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2084 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2086 sensor->info_priv.digitalzoom += val_offset;
2088 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2093 case V4L2_CID_ZOOM_RELATIVE:
2095 if (ext_ctrl->value)
2097 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2099 sensor->info_priv.digitalzoom += ext_ctrl->value;
2101 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2106 #if CONFIG_SENSOR_Focus
2107 case V4L2_CID_FOCUS_ABSOLUTE:
2109 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2112 if (ext_ctrl->value != sensor->info_priv.focus)
2114 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2116 sensor->info_priv.focus += val_offset;
2121 case V4L2_CID_FOCUS_RELATIVE:
2123 if (ext_ctrl->value)
2125 sensor->info_priv.focus += ext_ctrl->value;
2127 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2132 #if CONFIG_SENSOR_Flash
2133 case V4L2_CID_FLASH:
2135 sensor->info_priv.flash = ext_ctrl->value;
2137 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2148 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2150 struct i2c_client *client = sd->priv;
2151 struct soc_camera_device *icd = client->dev.platform_data;
2152 int i, error_cnt=0, error_idx=-1;
2155 for (i=0; i<ext_ctrl->count; i++) {
2156 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2163 error_idx = ext_ctrl->count;
2165 if (error_idx != -1) {
2166 ext_ctrl->error_idx = error_idx;
2173 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2175 struct i2c_client *client = sd->priv;
2176 struct soc_camera_device *icd = client->dev.platform_data;
2177 int i, error_cnt=0, error_idx=-1;
2180 for (i=0; i<ext_ctrl->count; i++) {
2181 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2188 error_idx = ext_ctrl->count;
2190 if (error_idx != -1) {
2191 ext_ctrl->error_idx = error_idx;
2198 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2199 * this wasn't our capture interface, so, we wait for the right one */
2200 static int sensor_video_probe(struct soc_camera_device *icd,
2201 struct i2c_client *client)
2205 struct sensor *sensor = to_sensor(client);
2207 /* We must have a parent by now. And it cannot be a wrong one.
2208 * So this entire test is completely redundant. */
2209 if (!icd->dev.parent ||
2210 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2214 ret = sensor_write(client, 0x12, 0x80);
2217 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2220 mdelay(5); //delay 5 microseconds
2222 /* check if it is an sensor sensor */
2223 ret = sensor_read(client, 0x0a, &pid);
2225 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2227 goto sensor_video_probe_err;
2230 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2231 if (pid == SENSOR_ID) {
2232 sensor->model = SENSOR_V4L2_IDENT;
2234 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2236 goto sensor_video_probe_err;
2239 icd->formats = sensor_colour_formats;
2240 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2244 sensor_video_probe_err:
2249 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2250 .init = sensor_init,
2251 .g_ctrl = sensor_g_control,
2252 .s_ctrl = sensor_s_control,
2253 .g_ext_ctrls = sensor_g_ext_controls,
2254 .s_ext_ctrls = sensor_s_ext_controls,
2255 .g_chip_ident = sensor_g_chip_ident,
2258 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2259 .s_fmt = sensor_s_fmt,
2260 .g_fmt = sensor_g_fmt,
2261 .try_fmt = sensor_try_fmt,
2264 static struct v4l2_subdev_ops sensor_subdev_ops = {
2265 .core = &sensor_subdev_core_ops,
2266 .video = &sensor_subdev_video_ops,
2269 static int sensor_probe(struct i2c_client *client,
2270 const struct i2c_device_id *did)
2272 struct sensor *sensor;
2273 struct soc_camera_device *icd = client->dev.platform_data;
2274 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2275 struct soc_camera_link *icl;
2278 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2280 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2284 icl = to_soc_camera_link(icd);
2286 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2290 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2291 dev_warn(&adapter->dev,
2292 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2296 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2300 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2302 /* Second stage probe - when a capture adapter is there */
2303 icd->ops = &sensor_ops;
2304 icd->y_skip_top = 0;
2306 ret = sensor_video_probe(icd, client);
2309 i2c_set_clientdata(client, NULL);
2312 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2316 static int sensor_remove(struct i2c_client *client)
2318 struct sensor *sensor = to_sensor(client);
2319 struct soc_camera_device *icd = client->dev.platform_data;
2322 i2c_set_clientdata(client, NULL);
2323 client->driver = NULL;
2329 static const struct i2c_device_id sensor_id[] = {
2330 {SENSOR_NAME_STRING(), 0 },
2333 MODULE_DEVICE_TABLE(i2c, sensor_id);
2335 static struct i2c_driver sensor_i2c_driver = {
2337 .name = SENSOR_NAME_STRING(),
2339 .probe = sensor_probe,
2340 .remove = sensor_remove,
2341 .id_table = sensor_id,
2344 static int __init sensor_mod_init(void)
2346 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2347 return i2c_add_driver(&sensor_i2c_driver);
2350 static void __exit sensor_mod_exit(void)
2352 i2c_del_driver(&sensor_i2c_driver);
2355 device_initcall_sync(sensor_mod_init);
2356 module_exit(sensor_mod_exit);
2358 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2359 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2360 MODULE_LICENSE("GPL");