2 o* Driver for MT9M001 CMOS Image Sensor from Micron
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk_camera.h>
23 #include <linux/vmalloc.h>
25 module_param(debug, int, S_IRUGO|S_IWUSR);
27 #define dprintk(level, fmt, arg...) do { \
29 printk(KERN_WARNING fmt , ## arg); } while (0)
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK_CAM_SENSOR_OV7690
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV7690
48 #define SENSOR_ID 0x76
49 #define SENSOR_MIN_WIDTH 176
50 #define SENSOR_MIN_HEIGHT 144
51 #define SENSOR_MAX_WIDTH 640
52 #define SENSOR_MAX_HEIGHT 480
53 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT sensor_init_height
55 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM sensor_init_busparam
59 #define CONFIG_SENSOR_WhiteBalance 1
60 #define CONFIG_SENSOR_Brightness 0
61 #define CONFIG_SENSOR_Contrast 0
62 #define CONFIG_SENSOR_Saturation 0
63 #define CONFIG_SENSOR_Effect 1
64 #define CONFIG_SENSOR_Scene 0
65 #define CONFIG_SENSOR_DigitalZoom 0
66 #define CONFIG_SENSOR_Focus 0
67 #define CONFIG_SENSOR_Exposure 0
68 #define CONFIG_SENSOR_Flash 0
69 #define CONFIG_SENSOR_Mirror 0
70 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED 0
75 #define CONFIG_SENSOR_I2C_RDWRCHK 0
77 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
81 #define COLOR_TEMPERATURE_OFFICE_DN 3500
82 #define COLOR_TEMPERATURE_OFFICE_UP 5000
83 #define COLOR_TEMPERATURE_HOME_DN 2500
84 #define COLOR_TEMPERATURE_HOME_UP 3500
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
95 static s32 sensor_init_width = 0;
96 static s32 sensor_init_height = 0;
97 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
98 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
99 static struct reginfo* sensor_init_data_p = NULL;
100 static struct reginfo* sensor_init_winseq_p = NULL;
101 static struct reginfo* sensor_init_winseq_board = NULL;
102 /* init 800*600 SVGA */
103 static struct reginfo sensor_init_data[] =
157 {0xb9, 0x00}, //0x07//0x27
230 static struct reginfo sensor_720p[]=
237 static struct reginfo sensor_uxga[] =
243 static struct reginfo sensor_sxga[] =
248 static struct reginfo sensor_xga[] =
253 static struct reginfo sensor_svga[] =
259 static struct reginfo sensor_vga[] =
279 static struct reginfo sensor_cif[] =
285 static struct reginfo sensor_qvga[] =
305 static struct reginfo sensor_qcif[] =
325 static struct reginfo ov2655_qqvga[] =
332 static struct reginfo ov2655_Sharpness_auto[] =
337 static struct reginfo ov2655_Sharpness1[] =
343 static struct reginfo ov2655_Sharpness2[][3] =
350 static struct reginfo ov2655_Sharpness3[] =
356 static struct reginfo ov2655_Sharpness4[]=
363 static struct reginfo ov2655_Sharpness5[] =
371 static struct reginfo sensor_ClrFmt_YUYV[]=
376 static struct reginfo sensor_ClrFmt_UYVY[]=
382 #if CONFIG_SENSOR_WhiteBalance
383 static struct reginfo sensor_WhiteB_Auto[]=
388 /* Cloudy Colour Temperature : 6500K - 8000K */
389 static struct reginfo sensor_WhiteB_Cloudy[]=
397 /* ClearDay Colour Temperature : 5000K - 6500K */
398 static struct reginfo sensor_WhiteB_ClearDay[]=
406 /* Office Colour Temperature : 3500K - 5000K */
407 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
416 /* Home Colour Temperature : 2500K - 3500K */
417 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
425 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
426 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
430 #if CONFIG_SENSOR_Brightness
431 static struct reginfo sensor_Brightness0[]=
437 static struct reginfo sensor_Brightness1[]=
444 static struct reginfo sensor_Brightness2[]=
451 static struct reginfo sensor_Brightness3[]=
458 static struct reginfo sensor_Brightness4[]=
465 static struct reginfo sensor_Brightness5[]=
471 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
472 sensor_Brightness4, sensor_Brightness5,NULL,
477 #if CONFIG_SENSOR_Effect
478 static struct reginfo sensor_Effect_Normal[] =
484 static struct reginfo sensor_Effect_WandB[] =
492 static struct reginfo sensor_Effect_Sepia[] =
500 static struct reginfo sensor_Effect_Negative[] =
506 static struct reginfo sensor_Effect_Bluish[] =
515 static struct reginfo sensor_Effect_Green[] =
523 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
524 sensor_Effect_Bluish, sensor_Effect_Green,NULL,
527 #if CONFIG_SENSOR_Exposure
528 static struct reginfo sensor_Exposure0[]=
533 static struct reginfo sensor_Exposure1[]=
538 static struct reginfo sensor_Exposure2[]=
543 static struct reginfo sensor_Exposure3[]=
548 static struct reginfo sensor_Exposure4[]=
553 static struct reginfo sensor_Exposure5[]=
558 static struct reginfo sensor_Exposure6[]=
563 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
564 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
567 #if CONFIG_SENSOR_Saturation
568 static struct reginfo sensor_Saturation0[]=
573 static struct reginfo sensor_Saturation1[]=
578 static struct reginfo sensor_Saturation2[]=
582 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
585 #if CONFIG_SENSOR_Contrast
586 static struct reginfo sensor_Contrast0[]=
591 static struct reginfo sensor_Contrast1[]=
596 static struct reginfo sensor_Contrast2[]=
601 static struct reginfo sensor_Contrast3[]=
606 static struct reginfo sensor_Contrast4[]=
612 static struct reginfo sensor_Contrast5[]=
617 static struct reginfo sensor_Contrast6[]=
621 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
622 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
626 #if CONFIG_SENSOR_Mirror
627 static struct reginfo sensor_MirrorOn[]=
632 static struct reginfo sensor_MirrorOff[]=
636 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
638 #if CONFIG_SENSOR_Flip
639 static struct reginfo sensor_FlipOn[]=
644 static struct reginfo sensor_FlipOff[]=
648 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
651 #if CONFIG_SENSOR_Scene
652 static struct reginfo sensor_SceneAuto[] =
657 static struct reginfo sensor_SceneNight[] =
661 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
664 #if CONFIG_SENSOR_DigitalZoom
665 static struct reginfo sensor_Zoom0[] =
670 static struct reginfo sensor_Zoom1[] =
675 static struct reginfo sensor_Zoom2[] =
681 static struct reginfo sensor_Zoom3[] =
685 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
687 static const struct v4l2_querymenu sensor_menus[] =
689 #if CONFIG_SENSOR_WhiteBalance
690 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
691 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
692 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
695 #if CONFIG_SENSOR_Effect
696 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
697 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
698 { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
701 #if CONFIG_SENSOR_Scene
702 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
705 #if CONFIG_SENSOR_Flash
706 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
707 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
711 static const struct v4l2_queryctrl sensor_controls[] =
713 #if CONFIG_SENSOR_WhiteBalance
715 .id = V4L2_CID_DO_WHITE_BALANCE,
716 .type = V4L2_CTRL_TYPE_MENU,
717 .name = "White Balance Control",
725 #if CONFIG_SENSOR_Brightness
727 .id = V4L2_CID_BRIGHTNESS,
728 .type = V4L2_CTRL_TYPE_INTEGER,
729 .name = "Brightness Control",
737 #if CONFIG_SENSOR_Effect
739 .id = V4L2_CID_EFFECT,
740 .type = V4L2_CTRL_TYPE_MENU,
741 .name = "Effect Control",
749 #if CONFIG_SENSOR_Exposure
751 .id = V4L2_CID_EXPOSURE,
752 .type = V4L2_CTRL_TYPE_INTEGER,
753 .name = "Exposure Control",
761 #if CONFIG_SENSOR_Saturation
763 .id = V4L2_CID_SATURATION,
764 .type = V4L2_CTRL_TYPE_INTEGER,
765 .name = "Saturation Control",
773 #if CONFIG_SENSOR_Contrast
775 .id = V4L2_CID_CONTRAST,
776 .type = V4L2_CTRL_TYPE_INTEGER,
777 .name = "Contrast Control",
785 #if CONFIG_SENSOR_Mirror
787 .id = V4L2_CID_HFLIP,
788 .type = V4L2_CTRL_TYPE_BOOLEAN,
789 .name = "Mirror Control",
797 #if CONFIG_SENSOR_Flip
799 .id = V4L2_CID_VFLIP,
800 .type = V4L2_CTRL_TYPE_BOOLEAN,
801 .name = "Flip Control",
809 #if CONFIG_SENSOR_Scene
811 .id = V4L2_CID_SCENE,
812 .type = V4L2_CTRL_TYPE_MENU,
813 .name = "Scene Control",
821 #if CONFIG_SENSOR_DigitalZoom
823 .id = V4L2_CID_ZOOM_RELATIVE,
824 .type = V4L2_CTRL_TYPE_INTEGER,
825 .name = "DigitalZoom Control",
831 .id = V4L2_CID_ZOOM_ABSOLUTE,
832 .type = V4L2_CTRL_TYPE_INTEGER,
833 .name = "DigitalZoom Control",
841 #if CONFIG_SENSOR_Focus
843 .id = V4L2_CID_FOCUS_RELATIVE,
844 .type = V4L2_CTRL_TYPE_INTEGER,
845 .name = "Focus Control",
851 .id = V4L2_CID_FOCUS_ABSOLUTE,
852 .type = V4L2_CTRL_TYPE_INTEGER,
853 .name = "Focus Control",
857 .default_value = 125,
861 #if CONFIG_SENSOR_Flash
863 .id = V4L2_CID_FLASH,
864 .type = V4L2_CTRL_TYPE_MENU,
865 .name = "Flash Control",
874 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
875 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
876 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
877 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
878 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
879 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
880 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
881 static int sensor_resume(struct soc_camera_device *icd);
882 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
883 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
884 #if CONFIG_SENSOR_Effect
885 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
887 #if CONFIG_SENSOR_WhiteBalance
888 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
890 static int sensor_deactivate(struct i2c_client *client);
892 static struct soc_camera_ops sensor_ops =
894 .suspend = sensor_suspend,
895 .resume = sensor_resume,
896 .set_bus_param = sensor_set_bus_param,
897 .query_bus_param = sensor_query_bus_param,
898 .controls = sensor_controls,
899 .menus = sensor_menus,
900 .num_controls = ARRAY_SIZE(sensor_controls),
901 .num_menus = ARRAY_SIZE(sensor_menus),
904 /* only one fixed colorspace per pixelcode */
905 struct sensor_datafmt {
906 enum v4l2_mbus_pixelcode code;
907 enum v4l2_colorspace colorspace;
910 /* Find a data format by a pixel code in an array */
911 static const struct sensor_datafmt *sensor_find_datafmt(
912 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
916 for (i = 0; i < n; i++)
917 if (fmt[i].code == code)
923 static const struct sensor_datafmt sensor_colour_fmts[] = {
924 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
925 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
928 typedef struct sensor_info_priv_s
942 unsigned char mirror; /* HFLIP */
943 unsigned char flip; /* VFLIP */
944 unsigned int winseqe_cur_addr;
945 struct sensor_datafmt fmt;
946 unsigned int funmodule_state;
947 } sensor_info_priv_t;
951 struct v4l2_subdev subdev;
952 struct i2c_client *client;
953 sensor_info_priv_t info_priv;
954 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
955 #if CONFIG_SENSOR_I2C_NOSCHED
956 atomic_t tasklock_cnt;
958 struct rkcamera_platform_data *sensor_io_request;
959 struct rkcamera_gpio_res *sensor_gpio_res;
963 static struct sensor* to_sensor(const struct i2c_client *client)
965 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
968 static int sensor_task_lock(struct i2c_client *client, int lock)
970 #if CONFIG_SENSOR_I2C_NOSCHED
972 struct sensor *sensor = to_sensor(client);
975 if (atomic_read(&sensor->tasklock_cnt) == 0) {
976 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
977 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
981 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
982 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
983 goto sensor_task_lock_err;
988 atomic_add(1, &sensor->tasklock_cnt);
990 if (atomic_read(&sensor->tasklock_cnt) > 0) {
991 atomic_sub(1, &sensor->tasklock_cnt);
993 if (atomic_read(&sensor->tasklock_cnt) == 0)
998 sensor_task_lock_err:
1006 /* sensor register write */
1007 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1011 struct i2c_msg msg[1];
1013 buf[0] = reg & 0xFF;
1016 msg->addr = client->addr;
1017 msg->flags = client->flags;
1019 msg->len = sizeof(buf);
1020 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1021 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1026 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1027 err = i2c_transfer(client->adapter, msg, 1);
1032 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1040 /* sensor register read */
1041 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1045 struct i2c_msg msg[2];
1049 msg[0].addr = client->addr;
1050 msg[0].flags = client->flags;
1052 msg[0].len = sizeof(buf);
1053 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1054 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1056 msg[1].addr = client->addr;
1057 msg[1].flags = client->flags|I2C_M_RD;
1060 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1061 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1065 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1066 err = i2c_transfer(client->adapter, msg, 2);
1072 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1080 /* write a array of registers */
1081 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1085 #if CONFIG_SENSOR_I2C_RDWRCHK
1090 if (sensor_task_lock(client, 1) < 0)
1091 goto sensor_write_array_end;
1093 while (regarray[i].reg != 0)
1095 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1099 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1103 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1105 goto sensor_write_array_end;
1108 #if CONFIG_SENSOR_I2C_RDWRCHK
1109 sensor_read(client, regarray[i].reg, &valchk);
1110 if (valchk != regarray[i].val)
1111 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1117 sensor_write_array_end:
1118 sensor_task_lock(client,0);
1121 #if CONFIG_SENSOR_I2C_RDWRCHK
1122 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1130 while (regarray[i].reg != 0)
1132 sensor_read(client, regarray[i].reg, &valchk);
1133 if (valchk != regarray[i].val)
1134 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1141 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1143 struct soc_camera_link *icl = to_soc_camera_link(icd);
1146 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1149 case Sensor_PowerDown:
1151 if (icl->powerdown) {
1154 ret = icl->powerdown(icd->pdev, on);
1155 if (ret == RK_CAM_IO_SUCCESS) {
1159 icl->reset(icd->pdev);
1161 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1163 goto sensor_power_end;
1170 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1171 struct sensor *sensor = to_sensor(client);
1173 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1174 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1180 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1187 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1189 struct i2c_client *client = v4l2_get_subdevdata(sd);
1190 struct soc_camera_device *icd = client->dev.platform_data;
1191 struct sensor *sensor = to_sensor(client);
1192 const struct v4l2_queryctrl *qctrl;
1193 const struct sensor_datafmt *fmt;
1194 int ret,pid = 0,i = 0,j=0;
1195 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1196 sensor_init_data_p = sensor_init_data;
1197 sensor_init_winseq_p = sensor_vga;
1198 sensor_init_width = 640;
1199 sensor_init_height = 480;
1200 if (tmp_plat_data != NULL) {
1201 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1202 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1203 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1207 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1208 //user has defined the init data
1210 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1211 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1212 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1213 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1215 sensor_init_data_p = sensor_init_data;
1217 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1218 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1221 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1222 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1223 if(sensor_init_winseq_board)
1225 vfree(sensor_init_winseq_board);
1226 sensor_init_winseq_board = NULL;
1228 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1229 if(!sensor_init_winseq_board)
1230 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1231 for(j = 0;j< tmp_winseq_size;j++){
1232 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1233 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1235 sensor_init_winseq_p = sensor_init_winseq_board;
1237 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1238 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1240 //init width,height,bus,pixelcode
1241 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1242 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1243 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1244 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1245 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1246 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1247 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1248 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1250 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1252 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1254 goto sensor_INIT_ERR;
1258 if (sensor_task_lock(client,1)<0)
1259 goto sensor_INIT_ERR;
1260 ret = sensor_write(client, 0x12, 0x80);
1263 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1265 goto sensor_INIT_ERR;
1267 mdelay(5); //delay 5 microseconds
1269 ret = sensor_write_array(client, sensor_init_data_p);
1272 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1273 goto sensor_INIT_ERR;
1275 sensor_task_lock(client,0);
1277 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1278 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1280 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1282 goto sensor_INIT_ERR;
1284 sensor->info_priv.fmt = *fmt;
1286 /* sensor sensor information for initialization */
1287 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1289 sensor->info_priv.whiteBalance = qctrl->default_value;
1290 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1292 sensor->info_priv.brightness = qctrl->default_value;
1293 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1295 sensor->info_priv.effect = qctrl->default_value;
1296 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1298 sensor->info_priv.exposure = qctrl->default_value;
1300 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1302 sensor->info_priv.saturation = qctrl->default_value;
1303 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1305 sensor->info_priv.contrast = qctrl->default_value;
1306 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1308 sensor->info_priv.mirror = qctrl->default_value;
1309 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1311 sensor->info_priv.flip = qctrl->default_value;
1312 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1314 sensor->info_priv.scene = qctrl->default_value;
1315 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1317 sensor->info_priv.digitalzoom = qctrl->default_value;
1319 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1320 #if CONFIG_SENSOR_Focus
1322 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1324 sensor->info_priv.focus = qctrl->default_value;
1327 #if CONFIG_SENSOR_Flash
1328 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1330 sensor->info_priv.flash = qctrl->default_value;
1333 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);
1337 sensor_task_lock(client,0);
1338 sensor_deactivate(client);
1342 static int sensor_deactivate(struct i2c_client *client)
1344 struct soc_camera_device *icd = client->dev.platform_data;
1347 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1349 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1350 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1352 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1353 icd->user_width = SENSOR_INIT_WIDTH;
1354 icd->user_height = SENSOR_INIT_HEIGHT;
1358 static struct reginfo sensor_power_down_sequence[]=
1362 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1365 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1367 if (pm_msg.event == PM_EVENT_SUSPEND) {
1368 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1369 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1371 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1374 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1376 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1381 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1387 static int sensor_resume(struct soc_camera_device *icd)
1391 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1393 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1397 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1403 static int sensor_set_bus_param(struct soc_camera_device *icd,
1404 unsigned long flags)
1410 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1412 struct soc_camera_link *icl = to_soc_camera_link(icd);
1413 unsigned long flags = SENSOR_BUS_PARAM;
1415 return soc_camera_apply_sensor_flags(icl, flags);
1418 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1420 struct i2c_client *client = v4l2_get_subdevdata(sd);
1421 struct soc_camera_device *icd = client->dev.platform_data;
1422 struct sensor *sensor = to_sensor(client);
1424 mf->width = icd->user_width;
1425 mf->height = icd->user_height;
1426 mf->code = sensor->info_priv.fmt.code;
1427 mf->colorspace = sensor->info_priv.fmt.colorspace;
1428 mf->field = V4L2_FIELD_NONE;
1432 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1436 if ((mf->width == 1024) && (mf->height == 768)) {
1438 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1440 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1442 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1444 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1449 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1453 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1457 if ((mf->width == 1280) && (mf->height == 720)) {
1459 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1464 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1467 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1469 struct i2c_client *client = v4l2_get_subdevdata(sd);
1470 const struct sensor_datafmt *fmt;
1471 struct sensor *sensor = to_sensor(client);
1472 const struct v4l2_queryctrl *qctrl;
1473 struct soc_camera_device *icd = client->dev.platform_data;
1474 struct reginfo *winseqe_set_addr=NULL;
1476 int ret=0, set_w,set_h;
1478 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1479 ARRAY_SIZE(sensor_colour_fmts));
1482 goto sensor_s_fmt_end;
1485 if (sensor->info_priv.fmt.code != mf->code) {
1488 case V4L2_MBUS_FMT_YUYV8_2X8:
1490 //winseqe_set_addr = sensor_ClrFmt_YUYV;
1491 sensor_read(client, 0x3a, &readval);
1492 sensor_write(client,0x3a, readval&0xf7);
1493 sensor_read(client,0x3d,&readval);
1494 sensor_write(client,0x3d,readval&0xfe);
1497 case V4L2_MBUS_FMT_UYVY8_2X8:
1499 //winseqe_set_addr = sensor_ClrFmt_UYVY;
1500 sensor_read(client, 0x3a, &readval);
1501 sensor_write(client,0x3a, readval|0x08);
1502 sensor_read(client,0x3d,&readval);
1503 sensor_write(client,0x3d,readval&0xfe);
1509 if (winseqe_set_addr != NULL) {
1510 sensor_write_array(client, winseqe_set_addr);
1511 sensor->info_priv.fmt.code = mf->code;
1512 sensor->info_priv.fmt.colorspace= mf->colorspace;
1513 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1515 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1522 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1524 winseqe_set_addr = sensor_qcif;
1528 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1530 winseqe_set_addr = sensor_qvga;
1534 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1536 winseqe_set_addr = sensor_cif;
1540 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1542 winseqe_set_addr = sensor_vga;
1546 else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1548 winseqe_set_addr = sensor_svga;
1552 else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
1554 winseqe_set_addr = sensor_720p;
1558 else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
1560 winseqe_set_addr = sensor_xga;
1564 else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1566 winseqe_set_addr = sensor_vga; //sensor_sxga;
1570 else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1572 winseqe_set_addr = sensor_uxga;
1578 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1579 set_w = SENSOR_INIT_WIDTH;
1580 set_h = SENSOR_INIT_HEIGHT;
1581 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1584 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) {
1585 #if CONFIG_SENSOR_Flash
1586 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1587 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1588 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
1589 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
1591 } else { /* ddl@rock-chips.com : Video */
1592 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1593 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1594 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
1598 ret |= sensor_write_array(client, winseqe_set_addr);
1600 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1601 #if CONFIG_SENSOR_Flash
1602 if (sensor_fmt_capturechk(sd,mf) == true) {
1603 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
1604 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1605 SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
1609 goto sensor_s_fmt_end;
1612 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1614 if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
1615 #if CONFIG_SENSOR_Effect
1616 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1617 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1619 #if CONFIG_SENSOR_WhiteBalance
1620 if (sensor->info_priv.whiteBalance != 0) {
1621 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1622 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1625 sensor->info_priv.snap2preview = true;
1626 } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
1627 #if CONFIG_SENSOR_Effect
1628 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1629 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1631 #if CONFIG_SENSOR_WhiteBalance
1632 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1633 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1635 sensor->info_priv.video2preview = true;
1636 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
1637 #if CONFIG_SENSOR_Effect
1638 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1639 sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
1641 #if CONFIG_SENSOR_WhiteBalance
1642 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1643 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
1645 sensor->info_priv.video2preview = false;
1646 sensor->info_priv.snap2preview = false;
1649 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1653 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1663 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1665 struct i2c_client *client = v4l2_get_subdevdata(sd);
1666 struct sensor *sensor = to_sensor(client);
1667 const struct sensor_datafmt *fmt;
1670 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1671 ARRAY_SIZE(sensor_colour_fmts));
1673 fmt = &sensor->info_priv.fmt;
1674 mf->code = fmt->code;
1677 if (mf->height > SENSOR_MAX_HEIGHT)
1678 mf->height = SENSOR_MAX_HEIGHT;
1679 else if (mf->height < SENSOR_MIN_HEIGHT)
1680 mf->height = SENSOR_MIN_HEIGHT;
1682 if (mf->width > SENSOR_MAX_WIDTH)
1683 mf->width = SENSOR_MAX_WIDTH;
1684 else if (mf->width < SENSOR_MIN_WIDTH)
1685 mf->width = SENSOR_MIN_WIDTH;
1687 mf->colorspace = fmt->colorspace;
1692 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1694 struct i2c_client *client = v4l2_get_subdevdata(sd);
1696 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1699 if (id->match.addr != client->addr)
1702 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1707 #if CONFIG_SENSOR_Brightness
1708 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1710 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1712 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1714 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1716 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1718 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1721 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1725 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1729 #if CONFIG_SENSOR_Effect
1730 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1732 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1734 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1736 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1738 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1740 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1743 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1747 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1751 #if CONFIG_SENSOR_Exposure
1752 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1754 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1756 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1758 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1760 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1762 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1765 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1769 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1773 #if CONFIG_SENSOR_Saturation
1774 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1776 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1778 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1780 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1782 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1784 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1787 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1791 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1795 #if CONFIG_SENSOR_Contrast
1796 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1798 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1800 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1802 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1804 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1806 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1809 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1813 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1817 #if CONFIG_SENSOR_Mirror
1818 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1820 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1822 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1824 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1826 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1828 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1831 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1835 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1839 #if CONFIG_SENSOR_Flip
1840 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1842 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1844 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1846 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1848 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1850 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1853 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1857 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1861 #if CONFIG_SENSOR_Scene
1862 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1864 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1866 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1868 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1870 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1872 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1875 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1879 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1883 #if CONFIG_SENSOR_WhiteBalance
1884 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1886 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1888 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1890 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1892 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1894 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1897 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1901 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1905 #if CONFIG_SENSOR_DigitalZoom
1906 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
1908 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1909 struct sensor *sensor = to_sensor(client);
1910 const struct v4l2_queryctrl *qctrl_info;
1911 int digitalzoom_cur, digitalzoom_total;
1913 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1917 digitalzoom_cur = sensor->info_priv.digitalzoom;
1918 digitalzoom_total = qctrl_info->maximum;
1920 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
1922 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1926 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
1928 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
1932 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
1934 value = digitalzoom_total - digitalzoom_cur;
1937 if ((value < 0) && ((digitalzoom_cur + value) < 0))
1939 value = 0 - digitalzoom_cur;
1942 digitalzoom_cur += value;
1944 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
1946 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
1948 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1951 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1958 #if CONFIG_SENSOR_Flash
1959 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1961 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
1962 if (value == 3) { /* ddl@rock-chips.com: torch */
1963 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
1965 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
1967 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1971 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1976 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1978 struct i2c_client *client = v4l2_get_subdevdata(sd);
1979 struct sensor *sensor = to_sensor(client);
1980 const struct v4l2_queryctrl *qctrl;
1982 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
1986 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
1992 case V4L2_CID_BRIGHTNESS:
1994 ctrl->value = sensor->info_priv.brightness;
1997 case V4L2_CID_SATURATION:
1999 ctrl->value = sensor->info_priv.saturation;
2002 case V4L2_CID_CONTRAST:
2004 ctrl->value = sensor->info_priv.contrast;
2007 case V4L2_CID_DO_WHITE_BALANCE:
2009 ctrl->value = sensor->info_priv.whiteBalance;
2012 case V4L2_CID_EXPOSURE:
2014 ctrl->value = sensor->info_priv.exposure;
2017 case V4L2_CID_HFLIP:
2019 ctrl->value = sensor->info_priv.mirror;
2022 case V4L2_CID_VFLIP:
2024 ctrl->value = sensor->info_priv.flip;
2035 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2037 struct i2c_client *client = v4l2_get_subdevdata(sd);
2038 struct sensor *sensor = to_sensor(client);
2039 struct soc_camera_device *icd = client->dev.platform_data;
2040 const struct v4l2_queryctrl *qctrl;
2043 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2047 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2053 #if CONFIG_SENSOR_Brightness
2054 case V4L2_CID_BRIGHTNESS:
2056 if (ctrl->value != sensor->info_priv.brightness)
2058 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2062 sensor->info_priv.brightness = ctrl->value;
2067 #if CONFIG_SENSOR_Exposure
2068 case V4L2_CID_EXPOSURE:
2070 if (ctrl->value != sensor->info_priv.exposure)
2072 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2076 sensor->info_priv.exposure = ctrl->value;
2081 #if CONFIG_SENSOR_Saturation
2082 case V4L2_CID_SATURATION:
2084 if (ctrl->value != sensor->info_priv.saturation)
2086 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2090 sensor->info_priv.saturation = ctrl->value;
2095 #if CONFIG_SENSOR_Contrast
2096 case V4L2_CID_CONTRAST:
2098 if (ctrl->value != sensor->info_priv.contrast)
2100 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2104 sensor->info_priv.contrast = ctrl->value;
2109 #if CONFIG_SENSOR_WhiteBalance
2110 case V4L2_CID_DO_WHITE_BALANCE:
2112 if (ctrl->value != sensor->info_priv.whiteBalance)
2114 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2118 sensor->info_priv.whiteBalance = ctrl->value;
2123 #if CONFIG_SENSOR_Mirror
2124 case V4L2_CID_HFLIP:
2126 if (ctrl->value != sensor->info_priv.mirror)
2128 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2130 sensor->info_priv.mirror = ctrl->value;
2135 #if CONFIG_SENSOR_Flip
2136 case V4L2_CID_VFLIP:
2138 if (ctrl->value != sensor->info_priv.flip)
2140 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2142 sensor->info_priv.flip = ctrl->value;
2153 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2155 const struct v4l2_queryctrl *qctrl;
2156 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2157 struct sensor *sensor = to_sensor(client);
2159 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2163 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2167 switch (ext_ctrl->id)
2169 case V4L2_CID_SCENE:
2171 ext_ctrl->value = sensor->info_priv.scene;
2174 case V4L2_CID_EFFECT:
2176 ext_ctrl->value = sensor->info_priv.effect;
2179 case V4L2_CID_ZOOM_ABSOLUTE:
2181 ext_ctrl->value = sensor->info_priv.digitalzoom;
2184 case V4L2_CID_ZOOM_RELATIVE:
2188 case V4L2_CID_FOCUS_ABSOLUTE:
2190 ext_ctrl->value = sensor->info_priv.focus;
2193 case V4L2_CID_FOCUS_RELATIVE:
2197 case V4L2_CID_FLASH:
2199 ext_ctrl->value = sensor->info_priv.flash;
2207 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2209 const struct v4l2_queryctrl *qctrl;
2210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2211 struct sensor *sensor = to_sensor(client);
2214 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2218 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2223 switch (ext_ctrl->id)
2225 #if CONFIG_SENSOR_Scene
2226 case V4L2_CID_SCENE:
2228 if (ext_ctrl->value != sensor->info_priv.scene)
2230 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2232 sensor->info_priv.scene = ext_ctrl->value;
2237 #if CONFIG_SENSOR_Effect
2238 case V4L2_CID_EFFECT:
2240 if (ext_ctrl->value != sensor->info_priv.effect)
2242 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2244 sensor->info_priv.effect= ext_ctrl->value;
2249 #if CONFIG_SENSOR_DigitalZoom
2250 case V4L2_CID_ZOOM_ABSOLUTE:
2252 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2255 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2257 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2259 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2261 sensor->info_priv.digitalzoom += val_offset;
2263 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2268 case V4L2_CID_ZOOM_RELATIVE:
2270 if (ext_ctrl->value)
2272 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2274 sensor->info_priv.digitalzoom += ext_ctrl->value;
2276 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2281 #if CONFIG_SENSOR_Focus
2282 case V4L2_CID_FOCUS_ABSOLUTE:
2284 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2287 if (ext_ctrl->value != sensor->info_priv.focus)
2289 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2291 sensor->info_priv.focus += val_offset;
2296 case V4L2_CID_FOCUS_RELATIVE:
2298 if (ext_ctrl->value)
2300 sensor->info_priv.focus += ext_ctrl->value;
2302 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2307 #if CONFIG_SENSOR_Flash
2308 case V4L2_CID_FLASH:
2310 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2312 sensor->info_priv.flash = ext_ctrl->value;
2314 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2325 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2327 struct i2c_client *client = v4l2_get_subdevdata(sd);
2328 struct soc_camera_device *icd = client->dev.platform_data;
2329 int i, error_cnt=0, error_idx=-1;
2332 for (i=0; i<ext_ctrl->count; i++) {
2333 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2340 error_idx = ext_ctrl->count;
2342 if (error_idx != -1) {
2343 ext_ctrl->error_idx = error_idx;
2350 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2352 struct i2c_client *client = v4l2_get_subdevdata(sd);
2353 struct soc_camera_device *icd = client->dev.platform_data;
2354 int i, error_cnt=0, error_idx=-1;
2357 for (i=0; i<ext_ctrl->count; i++) {
2358 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2365 error_idx = ext_ctrl->count;
2367 if (error_idx != -1) {
2368 ext_ctrl->error_idx = error_idx;
2375 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2376 * this wasn't our capture interface, so, we wait for the right one */
2377 static int sensor_video_probe(struct soc_camera_device *icd,
2378 struct i2c_client *client)
2382 struct sensor *sensor = to_sensor(client);
2384 /* We must have a parent by now. And it cannot be a wrong one.
2385 * So this entire test is completely redundant. */
2386 if (!icd->dev.parent ||
2387 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2390 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2392 goto sensor_video_probe_err;
2395 ret = sensor_write(client, 0x12, 0x80);
2398 SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2401 mdelay(50); //delay 5 microseconds
2403 /* check if it is an sensor sensor */
2404 ret = sensor_read(client, 0x0a, &pid);
2406 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2408 goto sensor_video_probe_err;
2411 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2412 if (pid == SENSOR_ID) {
2413 sensor->model = SENSOR_V4L2_IDENT;
2415 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2417 goto sensor_video_probe_err;
2422 sensor_video_probe_err:
2427 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2429 struct i2c_client *client = v4l2_get_subdevdata(sd);
2430 struct soc_camera_device *icd = client->dev.platform_data;
2431 struct sensor *sensor = to_sensor(client);
2433 #if CONFIG_SENSOR_Flash
2437 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2440 case RK_CAM_SUBDEV_DEACTIVATE:
2442 sensor_deactivate(client);
2446 case RK_CAM_SUBDEV_IOREQUEST:
2448 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2449 if (sensor->sensor_io_request != NULL) {
2450 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2451 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2452 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2453 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2454 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2455 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2458 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2460 goto sensor_ioctl_end;
2462 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2464 #if CONFIG_SENSOR_Flash
2465 if (sensor->sensor_gpio_res) {
2466 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2467 for (i = 0; i < icd->ops->num_controls; i++) {
2468 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2469 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2472 sensor->info_priv.flash = 0xff;
2473 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2481 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2489 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2490 enum v4l2_mbus_pixelcode *code)
2492 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2495 *code = sensor_colour_fmts[index].code;
2498 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2499 .init = sensor_init,
2500 .g_ctrl = sensor_g_control,
2501 .s_ctrl = sensor_s_control,
2502 .g_ext_ctrls = sensor_g_ext_controls,
2503 .s_ext_ctrls = sensor_s_ext_controls,
2504 .g_chip_ident = sensor_g_chip_ident,
2505 .ioctl = sensor_ioctl,
2508 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2509 .s_mbus_fmt = sensor_s_fmt,
2510 .g_mbus_fmt = sensor_g_fmt,
2511 .try_mbus_fmt = sensor_try_fmt,
2512 .enum_mbus_fmt = sensor_enum_fmt,
2514 static struct v4l2_subdev_ops sensor_subdev_ops = {
2515 .core = &sensor_subdev_core_ops,
2516 .video = &sensor_subdev_video_ops,
2519 static int sensor_probe(struct i2c_client *client,
2520 const struct i2c_device_id *did)
2522 struct sensor *sensor;
2523 struct soc_camera_device *icd = client->dev.platform_data;
2524 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2525 struct soc_camera_link *icl;
2528 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2530 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2534 icl = to_soc_camera_link(icd);
2536 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2540 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2541 dev_warn(&adapter->dev,
2542 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2546 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2550 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2552 /* Second stage probe - when a capture adapter is there */
2553 icd->ops = &sensor_ops;
2555 sensor->info_priv.fmt = sensor_colour_fmts[0];
2557 #if CONFIG_SENSOR_I2C_NOSCHED
2558 atomic_set(&sensor->tasklock_cnt,0);
2561 ret = sensor_video_probe(icd, client);
2564 i2c_set_clientdata(client, NULL);
2568 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2572 static int sensor_remove(struct i2c_client *client)
2574 struct sensor *sensor = to_sensor(client);
2575 struct soc_camera_device *icd = client->dev.platform_data;
2578 i2c_set_clientdata(client, NULL);
2579 client->driver = NULL;
2585 static const struct i2c_device_id sensor_id[] = {
2586 {SENSOR_NAME_STRING(), 0 },
2589 MODULE_DEVICE_TABLE(i2c, sensor_id);
2591 static struct i2c_driver sensor_i2c_driver = {
2593 .name = SENSOR_NAME_STRING(),
2595 .probe = sensor_probe,
2596 .remove = sensor_remove,
2597 .id_table = sensor_id,
2600 static int __init sensor_mod_init(void)
2602 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2603 return i2c_add_driver(&sensor_i2c_driver);
2606 static void __exit sensor_mod_exit(void)
2608 i2c_del_driver(&sensor_i2c_driver);
2611 device_initcall_sync(sensor_mod_init);
2612 module_exit(sensor_mod_exit);
2614 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2615 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2616 MODULE_LICENSE("GPL");