+ #include "generic_sensor.h"\r
+\r
/*
- * Driver for OV5640 CMOS Image Sensor from OmniVision
- *
- * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/videodev2.h>
-#include <linux/slab.h>
-#include <linux/i2c.h>
-#include <linux/log2.h>
-#include <linux/platform_device.h>
-#include <linux/delay.h>
-#include <linux/circ_buf.h>
-#include <linux/miscdevice.h>
-#include <media/v4l2-common.h>
-#include <media/v4l2-chip-ident.h>
-#include <media/soc_camera.h>
-#include <plat/rk_camera.h>
-#include "ov5640.h"
-
-static int debug;
-module_param(debug, int, S_IRUGO|S_IWUSR);
-
-#define dprintk(level, fmt, arg...) do { \
- if (debug >= level) \
- printk(KERN_WARNING fmt , ## arg); } while (0)
-
-#define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
-#define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
-
-#define _CONS(a,b) a##b
-#define CONS(a,b) _CONS(a,b)
-
-#define __STR(x) #x
-#define _STR(x) __STR(x)
-#define STR(x) _STR(x)
-
-#define MIN(x,y) ((x<y) ? x: y)
-#define MAX(x,y) ((x>y) ? x: y)
-
-/* Sensor Driver Configuration */
-#define SENSOR_NAME RK29_CAM_SENSOR_OV5640
-#define SENSOR_V4L2_IDENT V4L2_IDENT_OV5640
-#define SENSOR_ID 0x5640
-#define SENSOR_MIN_WIDTH 176
-#define SENSOR_MIN_HEIGHT 144
-#define SENSOR_MAX_WIDTH 2592
-#define SENSOR_MAX_HEIGHT 1944
-#define SENSOR_INIT_WIDTH 800 /* Sensor pixel size for sensor_init_data array */
-#define SENSOR_INIT_HEIGHT 600
-#define SENSOR_INIT_WINSEQADR sensor_svga
-#define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
-
-#define CONFIG_SENSOR_WhiteBalance 1
-#define CONFIG_SENSOR_Brightness 0
-#define CONFIG_SENSOR_Contrast 0
-#define CONFIG_SENSOR_Saturation 0
-#define CONFIG_SENSOR_Effect 1
-#define CONFIG_SENSOR_Scene 1
-#define CONFIG_SENSOR_DigitalZoom 0
-#define CONFIG_SENSOR_Exposure 0
-#define CONFIG_SENSOR_Flash 1
-#define CONFIG_SENSOR_Mirror 0
-#define CONFIG_SENSOR_Flip 0
-#ifdef CONFIG_OV5640_AUTOFOCUS
-#define CONFIG_SENSOR_Focus 1
-#include "ov5640_af_firmware.c"
-#else
-#define CONFIG_SENSOR_Focus 0
-#endif
-
-#define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
-/* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
-#define CONFIG_SENSOR_I2C_NOSCHED 0
-#define CONFIG_SENSOR_I2C_RDWRCHK 0
-
-#define CONFIG_SENSOR_WRITE_REGS 1
-#define WRITE_REGS_NUM 3
-
-#define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
- SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
- SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
-
-#define COLOR_TEMPERATURE_CLOUDY_DN 6500
-#define COLOR_TEMPERATURE_CLOUDY_UP 8000
-#define COLOR_TEMPERATURE_CLEARDAY_DN 5000
-#define COLOR_TEMPERATURE_CLEARDAY_UP 6500
-#define COLOR_TEMPERATURE_OFFICE_DN 3500
-#define COLOR_TEMPERATURE_OFFICE_UP 5000
-#define COLOR_TEMPERATURE_HOME_DN 2500
-#define COLOR_TEMPERATURE_HOME_UP 3500
-
-#define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
-#define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
-
-#define SENSOR_AF_IS_ERR (0x00<<0)
-#define SENSOR_AF_IS_OK (0x01<<0)
-#define SENSOR_INIT_IS_ERR (0x00<<28)
-#define SENSOR_INIT_IS_OK (0x01<<28)
-
-#if CONFIG_SENSOR_Focus
-/*#define SENSOR_AF_MODE_INFINITY 0
-#define SENSOR_AF_MODE_MACRO 1
-#define SENSOR_AF_MODE_FIXED 2
-#define SENSOR_AF_MODE_AUTO 3
-#define SENSOR_AF_MODE_CONTINUOUS 4
-#define SENSOR_AF_MODE_CLOSE 5*/
-#define SENSOR_AF_MODE_AUTO 0
-#define SENSOR_AF_MODE_CLOSE 1
-#endif
-
-#if CONFIG_SENSOR_Focus
-/* ov5640 VCM Command and Status Registers */
-#define CMD_MAIN_Reg 0x3022
-//#define CMD_TAG_Reg 0x3023
-#define CMD_ACK_Reg 0x3023
-#define CMD_PARA0_Reg 0x3024
-#define CMD_PARA1_Reg 0x3025
-#define CMD_PARA2_Reg 0x3026
-#define CMD_PARA3_Reg 0x3027
-#define CMD_PARA4_Reg 0x3028
-
-//#define STA_ZONE_Reg 0x3026
-#define STA_FOCUS_Reg 0x3029
-
-/* ov5640 VCM Command */
-#define OverlayEn_Cmd 0x01
-#define OverlayDis_Cmd 0x02
-#define SingleFocus_Cmd 0x03
-#define ConstFocus_Cmd 0x04
-#define StepMode_Cmd 0x05
-#define PauseFocus_Cmd 0x06
-#define ReturnIdle_Cmd 0x08
-#define SetZone_Cmd 0x10
-#define UpdateZone_Cmd 0x12
-#define SetMotor_Cmd 0x20
-
-
-#define Zone_configuration_Cmd 0x12
-#define Trig_autofocus_Cmd 0x03
-#define Get_focus_result_Cmd 0x07
-
-/* ov5640 Focus State */
-//#define S_FIRWRE 0xFF /*Firmware is downloaded and not run*/
-#define S_STARTUP 0x7e /*Firmware is initializing*/
-#define S_ERROR 0x7f
-#define S_IDLE 0x70 /*Idle state, focus is released; lens is located at the furthest position.*/
-#define S_FOCUSING 0x00 /*Auto Focus is running.*/
-#define S_FOCUSED 0x10 /*Auto Focus is completed.*/
-
-#define S_CAPTURE 0x12
-#define S_STEP 0x20
-
-/* ov5640 Zone State */
-#define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))
-#define Zone_Get_ID(zone_val) (zone_val&0x03)
-
-#define Zone_CenterMode 0x01
-#define Zone_5xMode 0x02
-#define Zone_5PlusMode 0x03
-#define Zone_4fMode 0x04
-
-#define ZoneSel_Auto 0x0b
-#define ZoneSel_SemiAuto 0x0c
-#define ZoneSel_Manual 0x0d
-#define ZoneSel_Rotate 0x0e
-
-/* ov5640 Step Focus Commands */
-#define StepFocus_Near_Tag 0x01
-#define StepFocus_Far_Tag 0x02
-#define StepFocus_Furthest_Tag 0x03
-#define StepFocus_Nearest_Tag 0x04
-#define StepFocus_Spec_Tag 0x10
-#endif
-
-//flash off in fixed time to prevent from too hot , zyc
-struct flash_timer{
- struct soc_camera_device *icd;
- struct hrtimer timer;
-};
-static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
-
-static struct flash_timer flash_off_timer;
-//for user defined if user want to customize the series , zyc
-#ifdef CONFIG_OV5640_USER_DEFINED_SERIES
-#include "ov5640_user_series.c"
-#else
-
-/* init 800X600 SVGA */
-static struct reginfo sensor_init_data[] =
-{
- {0x3103, 0x11},
- {0x3008, 0x82},
- {0x3008, 0x42},
- {0x3103, 0x03},
- {0x3017, 0xff},
- {0x3018, 0xff},
- {0x3034, 0x1a},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x3037, 0x13},
- {0x3108, 0x01},
- {0x3630, 0x36},
- {0x3631, 0x0e},
- {0x3632, 0xe2},
- {0x3633, 0x12},
- {0x3621, 0xe0},
- {0x3704, 0xa0},
- {0x3703, 0x5a},
- {0x3715, 0x78},
- {0x3717, 0x01},
- {0x370b, 0x60},
- {0x3705, 0x1a},
- {0x3905, 0x02},
- {0x3906, 0x10},
- {0x3901, 0x0a},
- {0x3731, 0x12},
- {0x3600, 0x08},
- {0x3601, 0x33},
- {0x302d, 0x60},
- {0x3620, 0x52},
- {0x371b, 0x20},
- {0x471c, 0x50},
- {0x3a13, 0x43},
- {0x3a18, 0x00},
- {0x3a19, 0xf8},
- {0x3635, 0x13},
- {0x3636, 0x03},
- {0x3634, 0x40},
- {0x3622, 0x01},
- {0x3c01, 0x34},
- {0x3c04, 0x28},
- {0x3c05, 0x98},
- {0x3c06, 0x00},
- {0x3c07, 0x08},
- {0x3c08, 0x00},
- {0x3c09, 0x1c},
- {0x3c0a, 0x9c},
- {0x3c0b, 0x40},
- {0x3820, 0x41},
- {0x3821, 0x07},
- {0x3814, 0x31},
- {0x3815, 0x31},
- {0x3800, 0x00},
- {0x3801, 0x00},
- {0x3802, 0x00},
- {0x3803, 0x04},
- {0x3804, 0x0a},
- {0x3805, 0x3f},
- {0x3806, 0x07},
- {0x3807, 0x9b},
- {0x3808, 0x03},
- {0x3809, 0x20},
- {0x380a, 0x02},
- {0x380b, 0x58},
- {0x380c, 0x07},
- {0x380d, 0x68},
- {0x380e, 0x03},
- {0x380f, 0xd8},
- {0x3810, 0x00},
- {0x3811, 0x10},
- {0x3812, 0x00},
- {0x3813, 0x06},
- {0x3618, 0x00},
- {0x3612, 0x29},
- {0x3708, 0x64},
- {0x3709, 0x52},
- {0x370c, 0x03},
- {0x3a02, 0x03},
- {0x3a03, 0xd8},
- {0x3a08, 0x01},
- {0x3a09, 0x27},
- {0x3a0a, 0x00},
- {0x3a0b, 0xf6},
- {0x3a0e, 0x03},
- {0x3a0d, 0x04},
- {0x3a14, 0x03},
- {0x3a15, 0xd8},
- {0x4001, 0x02},
- {0x4004, 0x02},
- {0x3000, 0x00},
- {0x3002, 0x1c},
- {0x3004, 0xff},
- {0x3006, 0xc3},
- {0x300e, 0x58},
- {0x302e, 0x00},
- {0x4740, 0x20},
- {0x4300, 0x30},
- {0x501f, 0x00},
- {0x4713, 0x03},
- {0x4407, 0x04},
- {0x440e, 0x00},
- {0x460b, 0x35},
- {0x460c, 0x20},
- {0x4837, 0x22},
- {0x3824, 0x02},
- {0x5000, 0xa7},
- {0x5001, 0xa3},
- {0x5180, 0xff},
- {0x5181, 0xf2},
- {0x5182, 0x00},
- {0x5183, 0x14},
- {0x5184, 0x25},
- {0x5185, 0x24},
- {0x5186, 0x09},
- {0x5187, 0x09},
- {0x5188, 0x09},
- {0x5189, 0x75},
- {0x518a, 0x54},
- {0x518b, 0xe0},
- {0x518c, 0xb2},
- {0x518d, 0x42},
- {0x518e, 0x3d},
- {0x518f, 0x56},
- {0x5190, 0x46},
- {0x5191, 0xf8},
- {0x5192, 0x04},
- {0x5193, 0x70},
- {0x5194, 0xf0},
- {0x5195, 0xf0},
- {0x5196, 0x03},
- {0x5197, 0x01},
- {0x5198, 0x04},
- {0x5199, 0x12},
- {0x519a, 0x04},
- {0x519b, 0x00},
- {0x519c, 0x06},
- {0x519d, 0x82},
- {0x519e, 0x38},
- {0x5381, 0x1e},
- {0x5382, 0x5b},
- {0x5383, 0x08},
- {0x5384, 0x0a},
- {0x5385, 0x7e},
- {0x5386, 0x88},
- {0x5387, 0x7c},
- {0x5388, 0x6c},
- {0x5389, 0x10},
- {0x538a, 0x01},
- {0x538b, 0x98},
- {0x5300, 0x08},
- {0x5301, 0x30},
- {0x5302, 0x10},
- {0x5303, 0x00},
- {0x5304, 0x08},
- {0x5305, 0x30},
- {0x5306, 0x08},
- {0x5307, 0x16},
- {0x5309, 0x08},
- {0x530a, 0x30},
- {0x530b, 0x04},
- {0x530c, 0x06},
- {0x5480, 0x01},
- {0x5481, 0x08},
- {0x5482, 0x14},
- {0x5483, 0x28},
- {0x5484, 0x51},
- {0x5485, 0x65},
- {0x5486, 0x71},
- {0x5487, 0x7d},
- {0x5488, 0x87},
- {0x5489, 0x91},
- {0x548a, 0x9a},
- {0x548b, 0xaa},
- {0x548c, 0xb8},
- {0x548d, 0xcd},
- {0x548e, 0xdd},
- {0x548f, 0xea},
- {0x5490, 0x1d},
- {0x5580, 0x02},
- {0x5583, 0x40},
- {0x5584, 0x10},
- {0x5589, 0x10},
- {0x558a, 0x00},
- {0x558b, 0xf8},
- {0x5800, 0x23},
- {0x5801, 0x14},
- {0x5802, 0x0f},
- {0x5803, 0x0f},
- {0x5804, 0x12},
- {0x5805, 0x26},
- {0x5806, 0x0c},
- {0x5807, 0x08},
- {0x5808, 0x05},
- {0x5809, 0x05},
- {0x580a, 0x08},
- {0x580b, 0x0d},
- {0x580c, 0x08},
- {0x580d, 0x03},
- {0x580e, 0x00},
- {0x580f, 0x00},
- {0x5810, 0x03},
- {0x5811, 0x09},
- {0x5812, 0x07},
- {0x5813, 0x03},
- {0x5814, 0x00},
- {0x5815, 0x01},
- {0x5816, 0x03},
- {0x5817, 0x08},
- {0x5818, 0x0d},
- {0x5819, 0x08},
- {0x581a, 0x05},
- {0x581b, 0x06},
- {0x581c, 0x08},
- {0x581d, 0x0e},
- {0x581e, 0x29},
- {0x581f, 0x17},
- {0x5820, 0x11},
- {0x5821, 0x11},
- {0x5822, 0x15},
- {0x5823, 0x28},
- {0x5824, 0x46},
- {0x5825, 0x26},
- {0x5826, 0x08},
- {0x5827, 0x26},
- {0x5828, 0x64},
- {0x5829, 0x26},
- {0x582a, 0x24},
- {0x582b, 0x22},
- {0x582c, 0x24},
- {0x582d, 0x24},
- {0x582e, 0x06},
- {0x582f, 0x22},
- {0x5830, 0x40},
- {0x5831, 0x42},
- {0x5832, 0x24},
- {0x5833, 0x26},
- {0x5834, 0x24},
- {0x5835, 0x22},
- {0x5836, 0x22},
- {0x5837, 0x26},
- {0x5838, 0x44},
- {0x5839, 0x24},
- {0x583a, 0x26},
- {0x583b, 0x28},
- {0x583c, 0x42},
- {0x583d, 0xce},
- {0x5025, 0x00},
- {0x3a0f, 0x30},
- {0x3a10, 0x28},
- {0x3a1b, 0x30},
- {0x3a1e, 0x26},
- {0x3a11, 0x60},
- {0x3a1f, 0x14},
- {0x3008, 0x02},
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 720p 15fps @ 1280x720 */
-
-static struct reginfo sensor_720p[]=
-{
- {0x3503, 0x00},
-
- {0x3c07,0x07},
- {0x3803,0xfa},
- {0x3806,0x06},////
- {0x3807,0xa9},
- {0x3808,0x05},
- {0x3809,0x00},
- {0x380a,0x02},
- {0x380b,0xd0},
- {0x380c,0x07},
- {0x380d,0x64},
- {0x380e,0x02},
- {0x380f,0xe4},
- {0x3813,0x04},
- {0x3a02,0x02},
- {0x3a03,0xe4},
- {0x3a08,0x01},///
- {0x3a09,0xbc},////
- {0x3a0a,0x01},///
- {0x3a0b,0x72},////
- {0x3a0e,0x01},
- {0x3a0d,0x02},
- {0x3a14,0x02},
- {0x3a15,0xe4},
-
- {0x3820, 0x41}, //ddl@rock-chips.com add start: qsxvga -> 720p isn't stream on
- {0x3821, 0x07},
- {0x3814, 0x31},
- {0x3815, 0x31},
-
- {0x3618, 0x00},
- {0x3612, 0x29},
- {0x3709, 0x52},
- {0x370c, 0x03},
- {0x3a02, 0x03},
- {0x3a03, 0xd8},
- {0x3a08 ,0x01},///
- {0x3a09, 0x27},///
- {0x3a0a, 0x00},///
- {0x3a0b, 0xf6},///
- {0x3a0e, 0x03},
- {0x3a0d, 0x04},
- {0x3a14, 0x03},
- {0x3a15, 0xd8},
- {0x4004, 0x02},
- {0x3002, 0x1c},////
- {0x4713, 0x03},//////ddl@rock-chips.com add end
-
- {0x3002,0x00},///
- {0x4713,0x02},///
- {0x4837,0x16},
- {0x3824,0x04},///
- {0x5001,0x83},
- {0x3035,0x21},
- {0x3036,0x46},
-
- {0x4837, 0x22},
- {0x5001, 0xa3},
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 1080p, 0x15fps, 0xyuv @1920x1080 */
-
-static struct reginfo sensor_1080p[]=
-{
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 2592X1944 QSXGA */
-static struct reginfo sensor_qsxga[] =
-{
- {0x3503, 0x07},
- {0x3a00, 0x78},
- {0x350c, 0x00},
- {0x350d, 0x00},
- {0x3c07, 0x07},
- {0x3820, 0x40},
- {0x3821, 0x06},
- {0x3814, 0x11},
- {0x3815, 0x11},
- {0x3803, 0x00},
- {0x3807, 0x9f},
- {0x3808, 0x0a},
- {0x3809, 0x20},
- {0x380a, 0x07},
- {0x380b, 0x98},
- {0x380c, 0x0b},
- {0x380d, 0x1c},
- {0x380e, 0x07},
- {0x380f, 0xb0},
- {0x3813, 0x04},
- {0x3618, 0x04},
- {0x3612, 0x2b},
- {0x3709, 0x12},
- {0x370c, 0x00},
- {0x3a02, 0x07},
- {0x3a03, 0xb0},
- {0x3a0e, 0x06},
- {0x3a0d, 0x08},
- {0x3a14, 0x07},
- {0x3a15, 0xb0},
- {0x4004, 0x06},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x2c},
- {0x5001, 0x83},
-
- {SEQUENCE_END, 0x00}
-};
-/* 2048*1536 QXGA */
-static struct reginfo sensor_qxga[] =
-{
- {0x3503, 0x07},
- {0x3a00, 0x78},
- {0x350c, 0x00},
- {0x350d, 0x00},
- {0x3c07, 0x07},
- {0x3820, 0x40},
- {0x3821, 0x06},
- {0x3814, 0x11},
- {0x3815, 0x11},
- {0x3803, 0x00},
- {0x3807, 0x9f},
- {0x3808, 0x08},
- {0x3809, 0x00},
- {0x380a, 0x06},
- {0x380b, 0x00},
- {0x380c, 0x0b},
- {0x380d, 0x1c},
- {0x380e, 0x07},
- {0x380f, 0xb0},
- {0x3813, 0x04},
- {0x3618, 0x04},
- {0x3612, 0x2b},
- {0x3709, 0x12},
- {0x370c, 0x00},
- {0x3a02, 0x07},
- {0x3a03, 0xb0},
- {0x3a0e, 0x06},
- {0x3a0d, 0x08},
- {0x3a14, 0x07},
- {0x3a15, 0xb0},
- {0x4004, 0x06},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x2c},
- {0x5001, 0xa3},
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 1600X1200 UXGA */
-static struct reginfo sensor_uxga[] =
-{
- {0x3503, 0x07},
- {0x3a00, 0x78},
- {0x350c, 0x00},
- {0x350d, 0x00},
- {0x3c07, 0x07},
- {0x3820, 0x40},
- {0x3821, 0x06},
- {0x3814, 0x11},
- {0x3815, 0x11},
- {0x3803, 0x00},
- {0x3807, 0x9f},
- {0x3808, 0x06},
- {0x3809, 0x40},
- {0x380a, 0x04},
- {0x380b, 0xb0},
- {0x380c, 0x0b},
- {0x380d, 0x1c},
- {0x380e, 0x07},
- {0x380f, 0xb0},
- {0x3813, 0x04},
- {0x3618, 0x04},
- {0x3612, 0x2b},
- {0x3709, 0x12},
- {0x370c, 0x00},
- {0x3a02, 0x07},
- {0x3a03, 0xb0},
- {0x3a0e, 0x06},
- {0x3a0d, 0x08},
- {0x3a14, 0x07},
- {0x3a15, 0xb0},
- {0x4004, 0x06},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x2c},
- {0x5001, 0xa3},
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 1280X1024 SXGA */
-static struct reginfo sensor_sxga[] =
-{
- {0x3503, 0x07},
- {0x3a00, 0x78},
- {0x350c, 0x00},
- {0x350d, 0x00},
- {0x3c07, 0x07},
- {0x3820, 0x40},
- {0x3821, 0x06},
- {0x3814, 0x11},
- {0x3815, 0x11},
- {0x3803, 0x00},
- {0x3807, 0x9f},
- {0x3808, 0x05},
- {0x3809, 0x00},
- {0x380a, 0x04},
- {0x380b, 0x00},
- {0x380c, 0x0b},
- {0x380d, 0x1c},
- {0x380e, 0x07},
- {0x380f, 0xb0},
- {0x3813, 0x04},
- {0x3618, 0x04},
- {0x3612, 0x2b},
- {0x3709, 0x12},
- {0x370c, 0x00},
- {0x3a02, 0x07},
- {0x3a03, 0xb0},
- {0x3a0e, 0x06},
- {0x3a0d, 0x08},
- {0x3a14, 0x07},
- {0x3a15, 0xb0},
- {0x4004, 0x06},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x2c},
- {0x5001, 0xa3},
-
- {SEQUENCE_END, 0x00}
-};
-/* 1024X768 XGA */
-static struct reginfo sensor_xga[] =
-{
- {0x3503, 0x07},
- {0x3a00, 0x78},
- {0x350c, 0x00},
- {0x350d, 0x00},
- {0x3c07, 0x07},
- {0x3820, 0x40},
- {0x3821, 0x06},
- {0x3814, 0x11},
- {0x3815, 0x11},
- {0x3803, 0x00},
- {0x3807, 0x9f},
- {0x3808, 0x05},
- {0x3809, 0x00},
- {0x380a, 0x04},
- {0x380b, 0x00},
- {0x380c, 0x0b},
- {0x380d, 0x1c},
- {0x380e, 0x07},
- {0x380f, 0xb0},
- {0x3813, 0x04},
- {0x3618, 0x04},
- {0x3612, 0x2b},
- {0x3709, 0x12},
- {0x370c, 0x00},
- {0x3a02, 0x07},
- {0x3a03, 0xb0},
- {0x3a0e, 0x06},
- {0x3a0d, 0x08},
- {0x3a14, 0x07},
- {0x3a15, 0xb0},
- {0x4004, 0x06},
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x2c},
- {0x5001, 0xa3},
- {SEQUENCE_END, 0x00}
-};
-/* 800X600 SVGA*/
-static struct reginfo sensor_svga[] =
-{
- {0x3503, 0x00},
- {0x3c07, 0x08},
- {0x3820, 0x41},
- {0x3821, 0x07},
- {0x3814, 0x31},
- {0x3815, 0x31},
- {0x3803, 0x04},
- {0x3806, 0x07},///
- {0x3807, 0x9b},
- {0x3808, 0x03},
- {0x3809, 0x20},
- {0x380a, 0x02},
- {0x380b, 0x58},
- {0x380c, 0x07},
- {0x380d, 0x68},
- {0x380e, 0x03},
- {0x380f, 0xd8},
- {0x3813, 0x06},
- {0x3618, 0x00},
- {0x3612, 0x29},
- {0x3709, 0x52},
- {0x370c, 0x03},
- {0x3a02, 0x03},
- {0x3a03, 0xd8},
- {0x3a08 ,0x01},///
- {0x3a09, 0x27},///
- {0x3a0a, 0x00},///
- {0x3a0b, 0xf6},///
- {0x3a0e, 0x03},
- {0x3a0d, 0x04},
- {0x3a14, 0x03},
- {0x3a15, 0xd8},
- {0x4004, 0x02},
- {0x3002, 0x1c},////
- {0x4713, 0x03},////
- {0x3035, 0x21},
- {0x3036, 0x46},
- {0x4837, 0x22},
- {0x3824, 0x02},////
- {0x5001, 0xa3},
- {SEQUENCE_END, 0x00}
-};
-
-/* 640X480 VGA */
-static struct reginfo sensor_vga[] =
-{
-
- {SEQUENCE_END, 0x00}
-};
-/* 352X288 CIF */
-static struct reginfo sensor_cif[] =
-{
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 320*240 QVGA */
-static struct reginfo sensor_qvga[] =
-{
-
- {SEQUENCE_END, 0x00}
-};
-
-/* 176X144 QCIF*/
-static struct reginfo sensor_qcif[] =
-{
-
- {SEQUENCE_END, 0x00}
-};
-#endif
-static struct reginfo sensor_ClrFmt_YUYV[]=
-{
- {0x4300,0x30},
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_ClrFmt_UYVY[]=
-{
- {0x4300,0x32},
- {SEQUENCE_END, 0x00}
-};
-
-
-#if CONFIG_SENSOR_WhiteBalance
-static struct reginfo sensor_WhiteB_Auto[]=
-{
- {0x3406 ,0x00},
- {0x5192 ,0x04},
- {0x5191 ,0xf8},
- {0x5193 ,0x70},
- {0x5194 ,0xf0},
- {0x5195 ,0xf0},
- {0x518d ,0x3d},
- {0x518f ,0x54},
- {0x518e ,0x3d},
- {0x5190 ,0x54},
- {0x518b ,0xa8},
- {0x518c ,0xa8},
- {0x5187 ,0x18},
- {0x5188 ,0x18},
- {0x5189 ,0x6e},
- {0x518a ,0x68},
- {0x5186 ,0x1c},
- {0x5181 ,0x50},
- {0x5184 ,0x25},
- {0x5182 ,0x11},
- {0x5183 ,0x14},
- {0x5184 ,0x25},
- {0x5185 ,0x24},
- {SEQUENCE_END, 0x00}
-};
-/* Cloudy Colour Temperature : 6500K - 8000K */
-static struct reginfo sensor_WhiteB_Cloudy[]=
-{
- {0x3406 ,0x1 },
- {0x3400 ,0x6 },
- {0x3401 ,0x48},
- {0x3402 ,0x4 },
- {0x3403 ,0x0 },
- {0x3404 ,0x4 },
- {0x3405 ,0xd3 },
- {SEQUENCE_END, 0x00}
-};
-/* ClearDay Colour Temperature : 5000K - 6500K */
-static struct reginfo sensor_WhiteB_ClearDay[]=
-{
- {0x3406 ,0x1 },
- {0x3400 ,0x6 },
- {0x3401 ,0x1c},
- {0x3402 ,0x4 },
- {0x3403 ,0x0 },
- {0x3404 ,0x4 },
- {0x3405 ,0xf3},
- {SEQUENCE_END, 0x00}
-};
-/* Office Colour Temperature : 3500K - 5000K */
-static struct reginfo sensor_WhiteB_TungstenLamp1[]=
-{
- {0x3406 ,0x1 },
- {0x3400 ,0x5 },
- {0x3401 ,0x48},
- {0x3402 ,0x4 },
- {0x3403 ,0x0 },
- {0x3404 ,0x7 },
- {0x3405 ,0xcf},
- {SEQUENCE_END, 0x00}
-};
-/* Home Colour Temperature : 2500K - 3500K */
-static struct reginfo sensor_WhiteB_TungstenLamp2[]=
-{
- {0x3406 ,0x1 },
- {0x3400 ,0x4 },
- {0x3401 ,0x10},
- {0x3402 ,0x4 },
- {0x3403 ,0x0 },
- {0x3404 ,0x8 },
- {0x3405 ,0xb6},
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
- sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
-};
-#endif
-
-#if CONFIG_SENSOR_Brightness
-static struct reginfo sensor_Brightness0[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Brightness1[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Brightness2[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Brightness3[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Brightness4[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Brightness5[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
- sensor_Brightness4, sensor_Brightness5,NULL,
-};
-
-#endif
-
-#if CONFIG_SENSOR_Effect
-static struct reginfo sensor_Effect_Normal[] =
-{
- {0x5001, 0x7f},
- {0x5580, 0x00},
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Effect_WandB[] =
-{
- {0x5001, 0xff},
- {0x5580, 0x18},
- {0x5583, 0x80},
- {0x5584, 0x80},
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Effect_Sepia[] =
-{
- {0x5001, 0xff},
- {0x5580, 0x18},
- {0x5583, 0x40},
- {0x5584, 0xa0},
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Effect_Negative[] =
-{
- //Negative
- {0x5001, 0xff},
- {0x5580, 0x40},
- {SEQUENCE_END, 0x00}
-};static struct reginfo sensor_Effect_Bluish[] =
-{
- // Bluish
- {0x5001, 0xff},
- {0x5580, 0x18},
- {0x5583, 0xa0},
- {0x5584, 0x40},
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Effect_Green[] =
-{
- // Greenish
- {0x5001, 0xff},
- {0x5580, 0x18},
- {0x5583, 0x60},
- {0x5584, 0x60},
- {SEQUENCE_END, 0x00}
-};
-/*static struct reginfo sensor_Effect_Reddish[] =
-{
- // Greenish
- {0x5001, 0xff},
- {0x5580, 0x18},
- {0x5583, 0x80},
- {0x5584, 0xc0},
- {SEQUENCE_END, 0x00}
-};*/
-
-static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
- sensor_Effect_Bluish, sensor_Effect_Green,NULL,
-};
-#endif
-#if CONFIG_SENSOR_Exposure
-static struct reginfo sensor_Exposure0[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Exposure1[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Exposure2[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Exposure3[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Exposure4[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Exposure5[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Exposure6[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
- sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
-};
-#endif
-#if CONFIG_SENSOR_Saturation
-static struct reginfo sensor_Saturation0[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Saturation1[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Saturation2[]=
-{
- {SEQUENCE_END, 0x00}
-};static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
-
-#endif
-#if CONFIG_SENSOR_Contrast
-static struct reginfo sensor_Contrast0[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Contrast1[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Contrast2[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Contrast3[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Contrast4[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-
-static struct reginfo sensor_Contrast5[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Contrast6[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
- sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
-};
-
-#endif
-#if CONFIG_SENSOR_Mirror
-static struct reginfo sensor_MirrorOn[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_MirrorOff[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
-#endif
-#if CONFIG_SENSOR_Flip
-static struct reginfo sensor_FlipOn[]=
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_FlipOff[]=
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
-
-#endif
-#if CONFIG_SENSOR_Scene
-static struct reginfo sensor_SceneAuto[] =
-{
- {0x3a00 , 0x78},
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_SceneNight[] =
-{
- //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
- {0x3034 ,0x1a},
- {0x3035 ,0x21},
- {0x3036 ,0x46},
- {0x3037 ,0x13},
- {0x3038 ,0x00},
- {0x3039 ,0x00},
- {0x3a00 ,0x7c},
- {0x3a08 ,0x01},
- {0x3a09 ,0x27},
- {0x3a0a ,0x00},
- {0x3a0b ,0xf6},
- {0x3a0d ,0x04},
- {0x3a0e ,0x04},
- {0x3a02 ,0x0b},
- {0x3a03 ,0x88},
- {0x3a14 ,0x0b},
- {0x3a15 ,0x88},
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
-
-#endif
-#if CONFIG_SENSOR_DigitalZoom
-static struct reginfo sensor_Zoom0[] =
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo sensor_Zoom1[] =
-{
- {SEQUENCE_END, 0x00}
-};
-
-static struct reginfo sensor_Zoom2[] =
-{
- {SEQUENCE_END, 0x00}
-};
-
-
-static struct reginfo sensor_Zoom3[] =
-{
- {SEQUENCE_END, 0x00}
-};
-static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
-#endif
-static const struct v4l2_querymenu sensor_menus[] =
-{
- #if CONFIG_SENSOR_WhiteBalance
- { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
- { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
- { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
- #endif
-
- #if CONFIG_SENSOR_Effect
- { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
- { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
- { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT, .index = 5, .name = "aqua", .reserved = 0,},
- #endif
-
- #if CONFIG_SENSOR_Scene
- { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
- #endif
-
- #if CONFIG_SENSOR_Flash
- { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
- { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
- #endif
-};
-
-static struct v4l2_queryctrl sensor_controls[] =
-{
- #if CONFIG_SENSOR_WhiteBalance
- {
- .id = V4L2_CID_DO_WHITE_BALANCE,
- .type = V4L2_CTRL_TYPE_MENU,
- .name = "White Balance Control",
- .minimum = 0,
- .maximum = 4,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Brightness
- {
- .id = V4L2_CID_BRIGHTNESS,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Brightness Control",
- .minimum = -3,
- .maximum = 2,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Effect
- {
- .id = V4L2_CID_EFFECT,
- .type = V4L2_CTRL_TYPE_MENU,
- .name = "Effect Control",
- .minimum = 0,
- .maximum = 5,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Exposure
- {
- .id = V4L2_CID_EXPOSURE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Exposure Control",
- .minimum = 0,
- .maximum = 6,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Saturation
- {
- .id = V4L2_CID_SATURATION,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Saturation Control",
- .minimum = 0,
- .maximum = 2,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Contrast
- {
- .id = V4L2_CID_CONTRAST,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Contrast Control",
- .minimum = -3,
- .maximum = 3,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Mirror
- {
- .id = V4L2_CID_HFLIP,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Mirror Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = 1,
- },
- #endif
-
- #if CONFIG_SENSOR_Flip
- {
- .id = V4L2_CID_VFLIP,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Flip Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = 1,
- },
- #endif
-
- #if CONFIG_SENSOR_Scene
- {
- .id = V4L2_CID_SCENE,
- .type = V4L2_CTRL_TYPE_MENU,
- .name = "Scene Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_DigitalZoom
- {
- .id = V4L2_CID_ZOOM_RELATIVE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "DigitalZoom Control",
- .minimum = -1,
- .maximum = 1,
- .step = 1,
- .default_value = 0,
- }, {
- .id = V4L2_CID_ZOOM_ABSOLUTE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "DigitalZoom Control",
- .minimum = 0,
- .maximum = 3,
- .step = 1,
- .default_value = 0,
- },
- #endif
-
- #if CONFIG_SENSOR_Focus
- /*{
- .id = V4L2_CID_FOCUS_RELATIVE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Focus Control",
- .minimum = -1,
- .maximum = 1,
- .step = 1,
- .default_value = 0,
- }, {
- .id = V4L2_CID_FOCUS_ABSOLUTE,
- .type = V4L2_CTRL_TYPE_INTEGER,
- .name = "Focus Control",
- .minimum = 0,
- .maximum = 255,
- .step = 1,
- .default_value = 125,
- },*/
- {
- .id = V4L2_CID_FOCUS_AUTO,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Focus Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = 0,
- },/*{
- .id = V4L2_CID_FOCUS_CONTINUOUS,
- .type = V4L2_CTRL_TYPE_BOOLEAN,
- .name = "Focus Control",
- .minimum = 0,
- .maximum = 1,
- .step = 1,
- .default_value = 0,
- },*/
- #endif
-
- #if CONFIG_SENSOR_Flash
- {
- .id = V4L2_CID_FLASH,
- .type = V4L2_CTRL_TYPE_MENU,
- .name = "Flash Control",
- .minimum = 0,
- .maximum = 3,
- .step = 1,
- .default_value = 0,
- },
- #endif
-};
-
-static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
-static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
-static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
-static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
-static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
-static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
-static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
-static int sensor_resume(struct soc_camera_device *icd);
-static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
-static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
-static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
-static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
-static int sensor_deactivate(struct i2c_client *client);
-static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
-static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
-
-static struct soc_camera_ops sensor_ops =
-{
- .suspend = sensor_suspend,
- .resume = sensor_resume,
- .set_bus_param = sensor_set_bus_param,
- .query_bus_param = sensor_query_bus_param,
- .controls = sensor_controls,
- .menus = sensor_menus,
- .num_controls = ARRAY_SIZE(sensor_controls),
- .num_menus = ARRAY_SIZE(sensor_menus),
-};
-/* only one fixed colorspace per pixelcode */
-struct sensor_datafmt {
- enum v4l2_mbus_pixelcode code;
- enum v4l2_colorspace colorspace;
-};
-
-/* Find a data format by a pixel code in an array */
-static const struct sensor_datafmt *sensor_find_datafmt(
- enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
- int n)
-{
- int i;
- for (i = 0; i < n; i++)
- if (fmt[i].code == code)
- return fmt + i;
-
- return NULL;
-}
-
-static const struct sensor_datafmt sensor_colour_fmts[] = {
- {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
- {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
-};
-enum sensor_wq_cmd
-{
- WqCmd_af_init,
- WqCmd_af_single,
- WqCmd_af_special_pos,
- WqCmd_af_far_pos,
- WqCmd_af_near_pos,
- WqCmd_af_continues,
- WqCmd_af_return_idle,
-};
-enum sensor_wq_result
-{
- WqRet_success = 0,
- WqRet_fail = -1,
- WqRet_inval = -2
-};
-struct sensor_work
-{
- struct i2c_client *client;
- struct delayed_work dwork;
- enum sensor_wq_cmd cmd;
- wait_queue_head_t done;
- enum sensor_wq_result result;
- bool wait;
- int var;
-};
-
-typedef struct sensor_info_priv_s
-{
- int whiteBalance;
- int brightness;
- int contrast;
- int saturation;
- int effect;
- int scene;
- int digitalzoom;
- int focus;
- int auto_focus;
- int affm_reinit;
- int flash;
- int exposure;
- bool snap2preview;
- bool video2preview;
- unsigned char mirror; /* HFLIP */
- unsigned char flip; /* VFLIP */
- struct reginfo *winseqe_cur_addr;
- struct sensor_datafmt fmt;
- unsigned int enable;
- unsigned int funmodule_state;
-} sensor_info_priv_t;
-
-
-
-struct sensor_parameter
-{
- unsigned short int preview_maxlines;
- unsigned short int preview_exposure;
- unsigned short int preview_line_width;
- unsigned short int preview_gain;
-
- unsigned short int capture_framerate;
- unsigned short int preview_framerate;
- char awb[6];
-};
-
-struct sensor
-{
- struct v4l2_subdev subdev;
- struct i2c_client *client;
- sensor_info_priv_t info_priv;
- struct sensor_parameter parameter;
- struct workqueue_struct *sensor_wq;
- struct mutex wq_lock;
- int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
-#if CONFIG_SENSOR_I2C_NOSCHED
- atomic_t tasklock_cnt;
-#endif
- struct rk29camera_platform_data *sensor_io_request;
- struct rk29camera_gpio_res *sensor_gpio_res;
-};
-
-static struct sensor* to_sensor(const struct i2c_client *client)
-{
- return container_of(i2c_get_clientdata(client), struct sensor, subdev);
-}
-
-static int sensor_task_lock(struct i2c_client *client, int lock)
-{
-#if CONFIG_SENSOR_I2C_NOSCHED
- int cnt = 3;
- struct sensor *sensor = to_sensor(client);
-
- if (lock) {
- if (atomic_read(&sensor->tasklock_cnt) == 0) {
- while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
- SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
- msleep(35);
- cnt--;
- }
- if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
- SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
- goto sensor_task_lock_err;
- }
- preempt_disable();
- }
-
- atomic_add(1, &sensor->tasklock_cnt);
- } else {
- if (atomic_read(&sensor->tasklock_cnt) > 0) {
- atomic_sub(1, &sensor->tasklock_cnt);
-
- if (atomic_read(&sensor->tasklock_cnt) == 0)
- preempt_enable();
- }
- }
- return 0;
-sensor_task_lock_err:
- return -1;
-#else
- return 0;
-#endif
-
-}
-
-
-#if CONFIG_SENSOR_WRITE_REGS
-static int sensor_write_regs(struct i2c_client *client, u8 *reg_info, int num)
-{
- int err=0,cnt;
- struct i2c_msg msg[1];
-
- msg->len = num;
- msg->addr = client->addr;
- msg->flags = client->flags;
- msg->buf = reg_info;
- msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
- msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
-
-
- cnt= 3;
- err = -EAGAIN;
-
- while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
- err = i2c_transfer(client->adapter, msg, 1);
- if (err >= 0) {
- return 0;
- } else {
- SENSOR_TR("\n %s write reg failed, try to write again!\n", SENSOR_NAME_STRING());
- udelay(10);
- }
- }
-
- return err;
-
-}
-
-#endif
-
-
-
-
-/* sensor register write */
-static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
-{
- int err,cnt;
- u8 buf[3];
- struct i2c_msg msg[1];
-
- buf[0] = reg >> 8;
- buf[1] = reg & 0xFF;
- buf[2] = val;
-
- msg->addr = client->addr;
- msg->flags = client->flags;
- msg->buf = buf;
- msg->len = sizeof(buf);
- msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
- msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
-
- cnt = 3;
- err = -EAGAIN;
-
- while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
- err = i2c_transfer(client->adapter, msg, 1);
-
- if (err >= 0) {
- return 0;
- } else {
- SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
- udelay(10);
- }
- }
-
- return err;
-}
-
-/* sensor register read */
-static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
-{
- int err,cnt;
- u8 buf[2];
- struct i2c_msg msg[2];
-
- buf[0] = reg >> 8;
- buf[1] = reg & 0xFF;
-
- msg[0].addr = client->addr;
- msg[0].flags = client->flags;
- msg[0].buf = buf;
- msg[0].len = sizeof(buf);
- msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
- msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
-
- msg[1].addr = client->addr;
- msg[1].flags = client->flags|I2C_M_RD;
- msg[1].buf = buf;
- msg[1].len = 1;
- msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
- msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
-
- cnt = 3;
- err = -EAGAIN;
- while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
- err = i2c_transfer(client->adapter, msg, 2);
-
- if (err >= 0) {
- *val = buf[0];
- return 0;
- } else {
- SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
- udelay(10);
- }
- }
-
- return err;
-}
-
-/* write a array of registers */
-static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
-{
- int err = 0, cnt;
- int i = 0;
-#if CONFIG_SENSOR_Focus
- struct sensor *sensor = to_sensor(client);
-#endif
-#if CONFIG_SENSOR_I2C_RDWRCHK
- char valchk;
-#endif
-#if CONFIG_SENSOR_WRITE_REGS
- int j = 0, reg_num;
- u8 *ptemp, *phead;
- int reg_length;
-#endif
-
- cnt = 0;
- if (sensor_task_lock(client, 1) < 0)
- goto sensor_write_array_end;
- while (regarray[i].reg != SEQUENCE_END) {
- #if CONFIG_SENSOR_Focus
- if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
- SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
- err = -EINVAL;
- goto sensor_write_array_end;
- }
- #endif
-
-#if CONFIG_SENSOR_WRITE_REGS
-
- j = i;
- reg_num = 2;
- reg_length = 0x0001;
-
- while((regarray[i].reg + reg_length) == regarray[i+1].reg) {
- i++;
- reg_num++;
- if(reg_num >= WRITE_REGS_NUM)
- break;
- }
-
- if(reg_num > 2) {
-
- int size_num;
- size_num = reg_num + 1;
-
- ptemp = phead = (u8*)kmalloc((size_num+10)*sizeof(u8),GFP_KERNEL);
- if (!phead) {
- SENSOR_DG("-------------write registers allocate memory fail!!!\n");
- i = j;
- err = sensor_write(client, regarray[i].reg, regarray[i].val);
- } else {
- *phead = regarray[j].reg >> 8;
- *(ptemp+1) = regarray[j].reg & 0xFF;
- ptemp += 2;
- for( ; reg_num > 0; reg_num --, j++) {
- *ptemp ++ = regarray[j].val;
- }
-
- ptemp = phead;
- err = sensor_write_regs(client, ptemp,size_num);
- kfree(phead);
- }
- }else{
- err = sensor_write(client, regarray[i].reg, regarray[i].val);
- }
-#else
- err = sensor_write(client, regarray[i].reg, regarray[i].val);
-#endif
- if (err < 0)
- {
- if (cnt-- > 0) {
- SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
- i = 0;
- continue;
- } else {
- SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
- err = -EPERM;
- goto sensor_write_array_end;
- }
- } else {
- #if CONFIG_SENSOR_I2C_RDWRCHK
- sensor_read(client, regarray[i].reg, &valchk);
- if (valchk != regarray[i].val)
- SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
- #endif
- }
- i++;
- }
-
- #if CONFIG_SENSOR_Focus
- if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
- || (regarray == sensor_init_data)) {
- sensor->info_priv.affm_reinit = 1;
- }
- #endif
-
-sensor_write_array_end:
- sensor_task_lock(client,0);
- return err;
-}
-#if CONFIG_SENSOR_I2C_RDWRCHK
-static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
-{
- int cnt;
- int i = 0;
- char valchk;
-
- cnt = 0;
- valchk = 0;
- while (regarray[i].reg != 0)
- {
- sensor_read(client, regarray[i].reg, &valchk);
- if (valchk != regarray[i].val)
- SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
-
- i++;
- }
- return 0;
-}
-#endif
-#if CONFIG_SENSOR_Focus
-struct af_cmdinfo
-{
- char cmd_tag;
- char cmd_para[4];
- char validate_bit;
-};
-static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
-{
- int i;
- char read_tag=0xff,cnt;
-
- if (cmdinfo) {
- if (cmdinfo->validate_bit & 0x80) {
- if (sensor_write(client, CMD_ACK_Reg, cmdinfo->cmd_tag)) {
- SENSOR_TR("%s write CMD_ACK_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
- goto sensor_af_cmdset_err;
- }
- SENSOR_DG("%s write CMD_ACK_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
- }
- for (i=0; i<4; i++) {
- if (cmdinfo->validate_bit & (1<<i)) {
- if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
- SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
- goto sensor_af_cmdset_err;
- }
- SENSOR_DG("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
- }
- }
- } else {
- if (sensor_write(client, CMD_ACK_Reg, 0xff)) {
- SENSOR_TR("%s write CMD_ACK_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
- goto sensor_af_cmdset_err;
- }
- SENSOR_DG("%s write CMD_ACK_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
- }
-
- if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
- SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
- goto sensor_af_cmdset_err;
- }
-
- cnt = 0;
- do
- {
- msleep(5);
- if (sensor_read(client,CMD_ACK_Reg,&read_tag)){
- SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
- break;
- }
- } while((read_tag != 0x00)&& (cnt++<100));
-
- SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
- return 0;
-sensor_af_cmdset_err:
- return -1;
-}
-
-static int sensor_af_idlechk(struct i2c_client *client)
-{
- int ret = 0;
- char state;
- struct af_cmdinfo cmdinfo;
-
- SENSOR_DG("%s , %d\n",__FUNCTION__,__LINE__);
-
- cmdinfo.cmd_tag = 0x01;
- cmdinfo.validate_bit = 0x80;
- ret = sensor_af_cmdset(client, ReturnIdle_Cmd, &cmdinfo);
- if(0 != ret) {
- SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
- ret = -1;
- goto sensor_af_idlechk_end;
- }
-
-
- do{
- ret = sensor_read(client, CMD_ACK_Reg, &state);
- if (ret != 0){
- SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
- ret = -1;
- goto sensor_af_idlechk_end;
- }
- }while(0x00 != state);
-
-
-sensor_af_idlechk_end:
- return ret;
-}
-
-static int sensor_af_single(struct i2c_client *client)
-{
- int ret = 0;
- char state,cnt;
- struct af_cmdinfo cmdinfo;
-
- cmdinfo.cmd_tag = 0x01;
- cmdinfo.validate_bit = 0x80;
- ret = sensor_af_cmdset(client, SingleFocus_Cmd, &cmdinfo);
- if(0 != ret) {
- SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
- ret = -1;
- goto sensor_af_single_end;
- }
-
- cnt = 0;
- do
- {
- if (cnt != 0) {
- msleep(1);
- }
- cnt++;
- ret = sensor_read(client, STA_FOCUS_Reg, &state);
- if (ret != 0){
- SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
- ret = -1;
- goto sensor_af_single_end;
- }
- }while((state == S_FOCUSING) && (cnt<100));
-
- if (state != S_FOCUSED) {
- SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
- ret = -1;
- goto sensor_af_single_end;
- }
-
-sensor_af_single_end:
- return ret;
-}
-
-static int sensor_af_const(struct i2c_client *client)
-{
- int ret = 0;
-
-
- return ret;
-}
-
-
-static int sensor_af_init(struct i2c_client *client)
-{
- int ret = 0;
- char state,cnt;
-
- ret = sensor_write_array(client, sensor_af_firmware);
- if (ret != 0) {
- SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
- ret = -1;
- goto sensor_af_init_end;
- }
-
- cnt = 0;
- do
- {
- if (cnt != 0) {
- msleep(1);
- }
- cnt++;
- ret = sensor_read(client, STA_FOCUS_Reg, &state);
- if (ret != 0){
- SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
- ret = -1;
- goto sensor_af_init_end;
- }
- }while((state == S_STARTUP) && (cnt<100));
-
- if (state != S_IDLE) {
- SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
- ret = -1;
- goto sensor_af_init_end;
- }
-
-sensor_af_init_end:
- SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
- return ret;
-}
-
-static int sensor_af_downfirmware(struct i2c_client *client)
-{
- struct sensor *sensor = to_sensor(client);
- int ret=0;
- struct soc_camera_device *icd = client->dev.platform_data;
- struct v4l2_mbus_framefmt mf;
-
- SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
-
- if (sensor_af_init(client)) {
- sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
- ret = -1;
- } else {
- sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
-
- mf.width = icd->user_width;
- mf.height = icd->user_height;
- mf.code = sensor->info_priv.fmt.code;
- mf.colorspace = sensor->info_priv.fmt.colorspace;
- mf.field = V4L2_FIELD_NONE;
- if (sensor_fmt_videochk(NULL, &mf) == true) { /* ddl@rock-chips.com: focus mode fix const auto focus in video */
- ret = sensor_af_const(client);
- } else {
- switch (sensor->info_priv.auto_focus)
- {
- case SENSOR_AF_MODE_AUTO:
- {
- ret = sensor_af_single(client);
- break;
- }
- case SENSOR_AF_MODE_CLOSE:
- {
- ret = 0;
- break;
- }
- default:
- {
- SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
- goto sensor_af_downfirmware_end;
- }
- }
- }
- SENSOR_DG("%s sensor_af_downfirmware set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
- }
-
-sensor_af_downfirmware_end:
-
- return ret;
-}
-static void sensor_af_workqueue(struct work_struct *work)
-{
- struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
- struct i2c_client *client = sensor_work->client;
- struct sensor *sensor = to_sensor(client);
- struct af_cmdinfo cmdinfo;
-
- SENSOR_DG("%s %s Enter, cmd:0x%x \n",SENSOR_NAME_STRING(), __FUNCTION__,sensor_work->cmd);
-
- mutex_lock(&sensor->wq_lock);
-
- switch (sensor_work->cmd)
- {
- case WqCmd_af_init:
- {
- if (sensor_af_downfirmware(client) < 0) {
- SENSOR_TR("%s Sensor_af_init is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
- }
- break;
- }
- case WqCmd_af_single:
- {
- if (sensor_af_single(client) < 0) {
- SENSOR_TR("%s Sensor_af_single is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
- sensor_work->result = WqRet_fail;
- } else {
- sensor_work->result = WqRet_success;
- }
- break;
- }
- case WqCmd_af_special_pos:
- {
- sensor_af_idlechk(client);
-
- cmdinfo.cmd_tag = StepFocus_Spec_Tag;
- cmdinfo.cmd_para[0] = sensor_work->var;
- cmdinfo.validate_bit = 0x81;
- if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
- sensor_work->result = WqRet_fail;
- else
- sensor_work->result = WqRet_success;
- break;
- }
- case WqCmd_af_near_pos:
- {
- sensor_af_idlechk(client);
- cmdinfo.cmd_tag = StepFocus_Near_Tag;
- cmdinfo.validate_bit = 0x80;
- if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
- sensor_work->result = WqRet_fail;
- else
- sensor_work->result = WqRet_success;
- break;
- }
- case WqCmd_af_far_pos:
- {
- sensor_af_idlechk(client);
- cmdinfo.cmd_tag = StepFocus_Far_Tag;
- cmdinfo.validate_bit = 0x80;
- if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
- sensor_work->result = WqRet_fail;
- else
- sensor_work->result = WqRet_success;
- break;
- }
- case WqCmd_af_continues:
- {
- if (sensor_af_const(client) < 0)
- sensor_work->result = WqRet_fail;
- else
- sensor_work->result = WqRet_success;
- break;
- }
- case WqCmd_af_return_idle:
- {
- if (sensor_af_idlechk(client) < 0)
- sensor_work->result = WqRet_fail;
- else
- sensor_work->result = WqRet_success;
- break;
- }
- default:
- SENSOR_TR("Unknow command(%d) in %s af workqueue!",sensor_work->cmd,SENSOR_NAME_STRING());
- break;
- }
-set_end:
- if (sensor_work->wait == false) {
- kfree((void*)sensor_work);
- } else {
- wake_up(&sensor_work->done);
- }
- mutex_unlock(&sensor->wq_lock);
- return;
-}
-
-static int sensor_af_workqueue_set(struct soc_camera_device *icd, enum sensor_wq_cmd cmd, int var, bool wait)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- struct sensor_work *wk;
- int ret=0;
-
- if (sensor->sensor_wq == NULL) {
- ret = -EINVAL;
- goto sensor_af_workqueue_set_end;
- }
-
- if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) != SENSOR_AF_IS_OK) {
- if (cmd != WqCmd_af_init) {
- SENSOR_TR("%s %s cmd(%d) ingore,because af module isn't ready!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
- ret = -1;
- goto sensor_af_workqueue_set_end;
- }
- }
-
- wk = kzalloc(sizeof(struct sensor_work), GFP_KERNEL);
- if (wk) {
- wk->client = client;
- INIT_WORK(&(wk->dwork.work), sensor_af_workqueue);
- wk->cmd = cmd;
- wk->result = WqRet_inval;
- wk->wait = wait;
- wk->var = var;
- init_waitqueue_head(&wk->done);
-
- queue_delayed_work(sensor->sensor_wq,&(wk->dwork),0);
-
- /* ddl@rock-chips.com:
- * video_lock is been locked in v4l2_ioctl function, but auto focus may slow,
- * As a result any other ioctl calls will proceed very, very slowly since each call
- * will have to wait for the AF to finish. Camera preview is pause,because VIDIOC_QBUF
- * and VIDIOC_DQBUF is sched. so unlock video_lock here.
- */
- if (wait == true) {
- mutex_unlock(&icd->video_lock);
- if (wait_event_timeout(wk->done, (wk->result != WqRet_inval), msecs_to_jiffies(2500)) == 0) {
- SENSOR_TR("%s %s cmd(%d) is timeout!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
- }
- ret = wk->result;
- kfree((void*)wk);
- mutex_lock(&icd->video_lock);
- }
-
- } else {
- SENSOR_TR("%s %s cmd(%d) ingore,because struct sensor_work malloc failed!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
- ret = -1;
- }
-sensor_af_workqueue_set_end:
- return ret;
-}
-#endif
-static int sensor_parameter_record(struct i2c_client *client)
-{
- u8 ret_l,ret_m,ret_h;
- u8 tp_l,tp_m,tp_h;
- struct sensor *sensor = to_sensor(client);
-
- sensor_write(client,0x3503,0x07); //stop AE/AG
- sensor_write(client,0x3406,0x01); //stop AWB
-
- sensor_read(client,0x3500,&ret_h);
- sensor_read(client,0x3501, &ret_m);
- sensor_read(client,0x3502, &ret_l);
- tp_l = ret_l;
- tp_m = ret_m;
- tp_h = ret_h;
- SENSOR_DG(" %s Read 0x3500 = 0x%02x 0x3501 = 0x%02x 0x3502=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_m, ret_l);
- //sensor->parameter.preview_exposure = (tp_h<<12)+(tp_m<<4)+(tp_l>>4);
- sensor->parameter.preview_exposure = ((((tp_h & 0x0f) << 8)+ tp_m) << 4) + (tp_l>>4);
-
- sensor_read(client,0x350c, &ret_h);
- sensor_read(client,0x350d, &ret_l);
- sensor->parameter.preview_line_width = ret_h & 0xff;
- sensor->parameter.preview_line_width = (sensor->parameter.preview_line_width << 8) +ret_l;
- //Read back AGC Gain for preview
- sensor_read(client,0x350a, &ret_h);
- sensor_read(client,0x350b, &tp_l);
- sensor->parameter.preview_gain = ((ret_h & 0x01) << 8) + tp_l;
- //preview_maxlines
- sensor_read(client,0x380e, &ret_h);
- sensor->parameter.preview_maxlines = ret_h;
- sensor->parameter.preview_maxlines <<= 8;
- sensor_read(client,0x380f, &tp_l);
- sensor->parameter.preview_maxlines += tp_l;
-
- sensor->parameter.capture_framerate = 375;
- sensor->parameter.preview_framerate = 1500;
-
- sensor_read(client,0x3400,&sensor->parameter.awb[0]); //record awb value
- sensor_read(client,0x3401,&sensor->parameter.awb[1]);
- sensor_read(client,0x3402,&sensor->parameter.awb[2]);
- sensor_read(client,0x3403,&sensor->parameter.awb[3]);
- sensor_read(client,0x3404,&sensor->parameter.awb[4]);
- sensor_read(client,0x3405,&sensor->parameter.awb[5]);
-
- SENSOR_DG(" %s Read 0x350c = 0x%02x 0x350d = 0x%02x 0x350b=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_l, sensor->parameter.preview_gain);
- return 0;
-}
-static int sensor_ae_transfer(struct i2c_client *client)
-{
- u8 ExposureLow;
- u8 ExposureMid;
- u8 ExposureHigh;
- u16 ulCapture_Exposure;
- u32 ulCapture_Exposure_Gain;
- u16 iCapture_Gain;
- u8 Lines_10ms;
- bool m_60Hz = 0;
- u8 reg_l = 0,reg_h =0;
- u16 Preview_Maxlines;
- u8 Gain;
- u32 Capture_MaxLines;
- struct sensor *sensor = to_sensor(client);
-
- //Preview_Maxlines = sensor->parameter.preview_line_width;
- Preview_Maxlines = sensor->parameter.preview_maxlines;
- Gain = sensor->parameter.preview_gain;
- /*
- sensor_read(client,0x350c, ®_h);
- sensor_read(client,0x350d, ®_l);
- Capture_MaxLines = reg_h & 0xff;
- Capture_MaxLines = (Capture_MaxLines << 8) + reg_l;
- */
- //capture_maxlines
- sensor_read(client,0x380e, ®_h);
- Capture_MaxLines = reg_h;
- Capture_MaxLines <<= 8;
- sensor_read(client,0x380f, ®_l);
- Capture_MaxLines += reg_l;
-
- if(m_60Hz== 1) {
- Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/12000;
- } else {
- Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/10000;
- }
- Lines_10ms = Lines_10ms & 0xffff;
-
- if(Preview_Maxlines == 0)
- Preview_Maxlines = 1;
-
- //ulCapture_Exposure =
- // (sensor->parameter.preview_exposure*(sensor->parameter.capture_framerate)*(Capture_MaxLines))/(((Preview_Maxlines)*(sensor->parameter.preview_framerate)));
-
- ulCapture_Exposure =
- ((sensor->parameter.preview_exposure*(((sensor->parameter.capture_framerate)*(Capture_MaxLines) + 50)/100)) << 1)/(((Preview_Maxlines)*(sensor->parameter.preview_framerate) + 50)/100);
- ulCapture_Exposure = ulCapture_Exposure & 0xffff;
-
- iCapture_Gain = (Gain & 0x0f) + 16;
- if (Gain & 0x10) {
- iCapture_Gain = iCapture_Gain << 1;
- }
- if (Gain & 0x20) {
- iCapture_Gain = iCapture_Gain << 1;
- }
- if (Gain & 0x40) {
- iCapture_Gain = iCapture_Gain << 1;
- }
- if (Gain & 0x80) {
- iCapture_Gain = iCapture_Gain << 1;
- }
-
- //ulCapture_Exposure_Gain =(u32) (11 * ulCapture_Exposure * iCapture_Gain/5); //0ld value 2.5, ½â¾ö¹ýÁÁ
- ulCapture_Exposure_Gain =(u32) (ulCapture_Exposure * iCapture_Gain);
-
- if(ulCapture_Exposure_Gain < Capture_MaxLines*16) {
- ulCapture_Exposure = ulCapture_Exposure_Gain/16;
- if (ulCapture_Exposure > Lines_10ms)
- {
- //ulCapture_Exposure *= 1.7;
- ulCapture_Exposure /= Lines_10ms;
- ulCapture_Exposure *= Lines_10ms;
- }
- } else {
- ulCapture_Exposure = Capture_MaxLines;
- //ulCapture_Exposure_Gain *= 1.5;
- }
-
- if(ulCapture_Exposure == 0)
- ulCapture_Exposure = 1;
-
- iCapture_Gain = ((ulCapture_Exposure_Gain << 1)/ulCapture_Exposure + 1) >> 1;
- iCapture_Gain = iCapture_Gain & 0xffff;
-
- ExposureLow = ((unsigned char)ulCapture_Exposure)<<4;
- ExposureMid = (unsigned char)(ulCapture_Exposure >> 4) & 0xff;
- ExposureHigh = (unsigned char)(ulCapture_Exposure >> 12);
-
- //Gain = 0;
- Gain = 0x10;
- if (iCapture_Gain > 31) {
- Gain |= 0x10;
- iCapture_Gain = iCapture_Gain >> 1;
- }
- if (iCapture_Gain > 31) {
- Gain |= 0x20;
- iCapture_Gain = iCapture_Gain >> 1;
- }
- if (iCapture_Gain > 31) {
- Gain |= 0x40;
- iCapture_Gain = iCapture_Gain >> 1;
- }
- if (iCapture_Gain > 31) {
- Gain |= 0x80;
- iCapture_Gain = iCapture_Gain >> 1;
- }
- if (iCapture_Gain > 16)
- Gain |= ((iCapture_Gain -16) & 0x0f);
- if(Gain == 0x10)
- Gain = 0x11;
- // write the gain and exposure to 0x350* registers
- //m_iWrite0x350b=Gain;
- sensor_write(client,0x350b, Gain);
- Gain = (Gain >> 8) & 0x01;
- sensor_write(client,0x350a, Gain);
- //m_iWrite0x3502=ExposureLow;
- sensor_write(client,0x3502, ExposureLow);
- //m_iWrite0x3501=ExposureMid;
- sensor_write(client,0x3501, ExposureMid);
- //m_iWrite0x3500=ExposureHigh;
- sensor_write(client,0x3500, ExposureHigh);
- // SendToFile("Gain = 0x%x\r\n", Gain);
- // SendToFile("ExposureLow = 0x%x\r\n", ExposureLow);
- // SendToFile("ExposureMid = 0x%x\r\n", ExposureMid);
- // SendToFile("ExposureHigh = 0x%x\r\n", ExposureHigh);
- //¼Ó³¤ÑÓʱ£¬±ÜÃâ°µ´¦ÅÄÕÕʱµÄÃ÷°µ·Ö½çÎÊÌâ
- //camera_timed_wait(200);
- //linzhk camera_timed_wait(500);
-
- sensor_write(client,0x3400,sensor->parameter.awb[0]); // resume awb value
- sensor_write(client,0x3401,sensor->parameter.awb[1]);
- sensor_write(client,0x3402,sensor->parameter.awb[2]);
- sensor_write(client,0x3403,sensor->parameter.awb[3]);
- sensor_write(client,0x3404,sensor->parameter.awb[4]);
- sensor_write(client,0x3405,sensor->parameter.awb[5]);
-
- SENSOR_DG(" %s Write 0x350b = 0x%02x 0x3502 = 0x%02x 0x3501=0x%02x 0x3500 = 0x%02x\n",SENSOR_NAME_STRING(), Gain, ExposureLow, ExposureMid, ExposureHigh);
- mdelay(100);
- return 0;
-}
-static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
-{
- struct soc_camera_link *icl = to_soc_camera_link(icd);
- int ret = 0;
-
- SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
-
- switch (cmd)
- {
- case Sensor_PowerDown:
- {
- if (icl->powerdown) {
- ret = icl->powerdown(icd->pdev, on);
- if (ret == RK29_CAM_IO_SUCCESS) {
- if (on == 0) {
- mdelay(2);
- if (icl->reset)
- icl->reset(icd->pdev);
- }
- } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
- ret = -ENODEV;
- goto sensor_power_end;
- }
- }
- break;
- }
- case Sensor_Flash:
- {
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
-
- if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
- sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
- if(on){
- //flash off after 2 secs
- hrtimer_cancel(&(flash_off_timer.timer));
- hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
- }
- }
- break;
- }
- default:
- {
- SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
- break;
- }
- }
-
-sensor_power_end:
- return ret;
-}
-
-static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
- struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
- sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
- SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
- return 0;
-
-}
-
-static int sensor_init(struct v4l2_subdev *sd, u32 val)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_device *icd = client->dev.platform_data;
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl;
- const struct sensor_datafmt *fmt;
- char value;
- int ret,pid = 0;
-
- SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
-
- if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
- ret = -ENODEV;
- goto sensor_INIT_ERR;
- }
-
- /* soft reset */
- if (sensor_task_lock(client,1)<0)
- goto sensor_INIT_ERR;
- ret = sensor_write(client, 0x3008, 0x80);
- if (ret != 0) {
- SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
- ret = -ENODEV;
- goto sensor_INIT_ERR;
- }
-
- mdelay(5); //delay 5 microseconds
- /* check if it is an sensor sensor */
- ret = sensor_read(client, 0x300a, &value);
- if (ret != 0) {
- SENSOR_TR("read chip id high byte failed\n");
- ret = -ENODEV;
- goto sensor_INIT_ERR;
- }
-
- pid |= (value << 8);
-
- ret = sensor_read(client, 0x300b, &value);
- if (ret != 0) {
- SENSOR_TR("read chip id low byte failed\n");
- ret = -ENODEV;
- goto sensor_INIT_ERR;
- }
-
- pid |= (value & 0xff);
- SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
-
- if (pid == SENSOR_ID) {
- sensor->model = SENSOR_V4L2_IDENT;
- } else {
- SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
- ret = -ENODEV;
- goto sensor_INIT_ERR;
- }
-
- ret = sensor_write_array(client, sensor_init_data);
- if (ret != 0) {
- SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
- goto sensor_INIT_ERR;
- }
- sensor_task_lock(client,0);
- sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
- fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
- if (!fmt) {
- SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
- ret = -EINVAL;
- goto sensor_INIT_ERR;
- }
- sensor->info_priv.fmt = *fmt;
-
- /* sensor sensor information for initialization */
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
- if (qctrl)
- sensor->info_priv.whiteBalance = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
- if (qctrl)
- sensor->info_priv.brightness = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
- if (qctrl)
- sensor->info_priv.effect = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
- if (qctrl)
- sensor->info_priv.exposure = qctrl->default_value;
-
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
- if (qctrl)
- sensor->info_priv.saturation = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
- if (qctrl)
- sensor->info_priv.contrast = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
- if (qctrl)
- sensor->info_priv.mirror = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
- if (qctrl)
- sensor->info_priv.flip = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
- if (qctrl)
- sensor->info_priv.scene = qctrl->default_value;
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
- if (qctrl)
- sensor->info_priv.digitalzoom = qctrl->default_value;
-
- /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
- if (qctrl)
- sensor->info_priv.focus = qctrl->default_value;
-
- #if CONFIG_SENSOR_Flash
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
- if (qctrl)
- sensor->info_priv.flash = qctrl->default_value;
- flash_off_timer.icd = icd;
- flash_off_timer.timer.function = flash_off_func;
- #endif
- 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);
-
- sensor->info_priv.funmodule_state = SENSOR_INIT_IS_OK;
-
- return 0;
-sensor_INIT_ERR:
- sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
- sensor_task_lock(client,0);
- sensor_deactivate(client);
- return ret;
-}
-static int sensor_deactivate(struct i2c_client *client)
-{
- struct soc_camera_device *icd = client->dev.platform_data;
- struct sensor *sensor = to_sensor(client);
-
- SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
-
- /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
- if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
- sensor_task_lock(client, 1);
- sensor_write(client, 0x3017, 0x00); // FREX,VSYNC,HREF,PCLK,D9-D6
- sensor_write(client, 0x3018, 0x03); // D5-D0
- sensor_write(client,0x3019,0x00); // STROBE,SDA
- sensor_task_lock(client, 0);
- }
- sensor_ioctrl(icd, Sensor_PowerDown, 1);
- msleep(100);
- /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
- icd->user_width = SENSOR_INIT_WIDTH;
- icd->user_height = SENSOR_INIT_HEIGHT;
- sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
- return 0;
-}
-
-static struct reginfo sensor_power_down_sequence[]=
-{
- {0x00,0x00}
-};
-
-static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
-{
- int ret;
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if (pm_msg.event == PM_EVENT_SUSPEND) {
- SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
- ret = sensor_write_array(client, sensor_power_down_sequence) ;
- if (ret != 0) {
- SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
- return ret;
- } else {
- ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
- if (ret < 0) {
- SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
- return -EINVAL;
- }
- }
- } else {
- SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
- return -EINVAL;
- }
-
- return 0;
-}
-
-static int sensor_resume(struct soc_camera_device *icd)
-{
- int ret;
-
- ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
- if (ret < 0) {
- SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
- return -EINVAL;
- }
-
- SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
- return 0;
-}
-
-static int sensor_set_bus_param(struct soc_camera_device *icd,
- unsigned long flags)
-{
-
- return 0;
-}
-
-static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
-{
- struct soc_camera_link *icl = to_soc_camera_link(icd);
- unsigned long flags = SENSOR_BUS_PARAM;
-
- return soc_camera_apply_sensor_flags(icl, flags);
-}
-
-static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_device *icd = client->dev.platform_data;
- struct sensor *sensor = to_sensor(client);
-
- mf->width = icd->user_width;
- mf->height = icd->user_height;
- mf->code = sensor->info_priv.fmt.code;
- mf->colorspace = sensor->info_priv.fmt.colorspace;
- mf->field = V4L2_FIELD_NONE;
-
- return 0;
-}
-static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
-{
- bool ret = false;
-
- if ((mf->width == 1024) && (mf->height == 768)) {
- ret = true;
- } else if ((mf->width == 1280) && (mf->height == 1024)) {
- ret = true;
- } else if ((mf->width == 1600) && (mf->height == 1200)) {
- ret = true;
- } else if ((mf->width == 2048) && (mf->height == 1536)) {
- ret = true;
- } else if ((mf->width == 2592) && (mf->height == 1944)) {
- ret = true;
- }
-
- if (ret == true)
- SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
- return ret;
-}
-
-static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
-{
- bool ret = false;
-
- if ((mf->width == 1280) && (mf->height == 720)) {
- ret = true;
- } else if ((mf->width == 1920) && (mf->height == 1080)) {
- ret = true;
- }
-
- if (ret == true)
- SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
- return ret;
-}
-static int sensor_s_fmt(struct v4l2_subdev *sd,struct v4l2_mbus_framefmt *mf)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- const struct sensor_datafmt *fmt;
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl;
- struct soc_camera_device *icd = client->dev.platform_data;
- struct reginfo *winseqe_set_addr=NULL;
- int ret = 0, set_w,set_h;
-
- fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
- ARRAY_SIZE(sensor_colour_fmts));
- if (!fmt) {
- ret = -EINVAL;
- goto sensor_s_fmt_end;
- }
-
- if (sensor->info_priv.fmt.code != mf->code) {
- switch (mf->code)
- {
- case V4L2_MBUS_FMT_YUYV8_2X8:
- {
- winseqe_set_addr = sensor_ClrFmt_YUYV;
- break;
- }
- case V4L2_MBUS_FMT_UYVY8_2X8:
- {
- winseqe_set_addr = sensor_ClrFmt_UYVY;
- break;
- }
- default:
- break;
- }
- if (winseqe_set_addr != NULL) {
- sensor_write_array(client, winseqe_set_addr);
- sensor->info_priv.fmt.code = mf->code;
- sensor->info_priv.fmt.colorspace= mf->colorspace;
- SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
- } else {
- SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
- }
- }
-
- set_w = mf->width;
- set_h = mf->height;
-
- if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_qcif;
- set_w = 176;
- set_h = 144;
- }
- else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_qvga;
- set_w = 320;
- set_h = 240;
- }
- else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_cif;
- set_w = 352;
- set_h = 288;
- }
- else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_vga;
- set_w = 640;
- set_h = 480;
- }
- else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_svga;
- set_w = 800;
- set_h = 600;
- }
- else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_xga;
- set_w = 1024;
- set_h = 768;
- }
- else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_720p;
- set_w = 1280;
- set_h = 720;
- }
- else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_sxga;
- set_w = 1280;
- set_h = 1024;
- }
- else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_uxga;
- set_w = 1600;
- set_h = 1200;
- }
- else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_1080p;
- set_w = 1920;
- set_h = 1080;
- }
- else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_qxga;
- set_w = 2048;
- set_h = 1536;
- }
- else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
- {
- winseqe_set_addr = sensor_qsxga;
- set_w = 2592;
- set_h = 1944;
- }
- else
- {
- winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
- set_w = SENSOR_INIT_WIDTH;
- set_h = SENSOR_INIT_HEIGHT;
- SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
- }
-
- if (winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
- {
- if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
- sensor_parameter_record(client);
- /*#if CONFIG_SENSOR_Focus
- sensor_af_idlechk(client);
- if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)
- sensor_af_cmdset(client, PauseFocus_Cmd, NULL);
- #endif*/
- #if CONFIG_SENSOR_Flash
- if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
- sensor_ioctrl(icd, Sensor_Flash, Flash_On);
- SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
- }
- #endif
- }else { /* ddl@rock-chips.com : Video */
- #if CONFIG_SENSOR_Flash
- if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
- sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
- SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
- }
- #endif
- }
- if ((sensor->info_priv.winseqe_cur_addr->reg == SEQUENCE_PROPERTY) && (sensor->info_priv.winseqe_cur_addr->val == SEQUENCE_INIT)) {
- if (((winseqe_set_addr->reg == SEQUENCE_PROPERTY) && (winseqe_set_addr->val == SEQUENCE_NORMAL))
- || (winseqe_set_addr->reg != SEQUENCE_PROPERTY)) {
- ret |= sensor_write_array(client,sensor_init_data);
- SENSOR_DG("\n%s reinit ret:0x%x \n",SENSOR_NAME_STRING(), ret);
- }
- }
- ret |= sensor_write_array(client, winseqe_set_addr);
- if (ret != 0) {
- SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
- #if CONFIG_SENSOR_Flash
- if (sensor_fmt_capturechk(sd,mf) == true) {
- if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
- sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
- SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
- }
- }
- #endif
- goto sensor_s_fmt_end;
- }
- sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
-
- if (sensor_fmt_capturechk(sd,mf) == true) { /* ddl@rock-chips.com : Capture */
- sensor_ae_transfer(client);
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
- sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
- if (sensor->info_priv.whiteBalance != 0) {
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
- sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
- }
- sensor->info_priv.snap2preview = true;
- } else if (sensor_fmt_videochk(sd,mf) == true) { /* ddl@rock-chips.com : Video */
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
- sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
-
- sensor->info_priv.video2preview = true;
- } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
- sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
- if (sensor->info_priv.snap2preview == true) {
- qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
- sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
- }
- #if CONFIG_SENSOR_Focus
- if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) {
- sensor_af_workqueue_set(icd,WqCmd_af_return_idle,0,true);
- msleep(200);
- } else {
- msleep(500);
- }
- #else
- msleep(500);
- #endif
- sensor->info_priv.video2preview = false;
- sensor->info_priv.snap2preview = false;
- }
- SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
- }
- else
- {
- SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
- }
- mf->width = set_w;
- mf->height = set_h;
-sensor_s_fmt_end:
- return ret;
-}
-
-static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct sensor *sensor = to_sensor(client);
- const struct sensor_datafmt *fmt;
- int ret = 0,set_w,set_h;
-
- fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
- ARRAY_SIZE(sensor_colour_fmts));
- if (fmt == NULL) {
- fmt = &sensor->info_priv.fmt;
- mf->code = fmt->code;
- }
-
- if (mf->height > SENSOR_MAX_HEIGHT)
- mf->height = SENSOR_MAX_HEIGHT;
- else if (mf->height < SENSOR_MIN_HEIGHT)
- mf->height = SENSOR_MIN_HEIGHT;
-
- if (mf->width > SENSOR_MAX_WIDTH)
- mf->width = SENSOR_MAX_WIDTH;
- else if (mf->width < SENSOR_MIN_WIDTH)
- mf->width = SENSOR_MIN_WIDTH;
-
- set_w = mf->width;
- set_h = mf->height;
-
- if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
- {
- set_w = 176;
- set_h = 144;
- }
- else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
- {
- set_w = 320;
- set_h = 240;
- }
- else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
- {
- set_w = 352;
- set_h = 288;
- }
- else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
- {
- set_w = 640;
- set_h = 480;
- }
- else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
- {
- set_w = 800;
- set_h = 600;
- }
- else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
- {
- set_w = 1024;
- set_h = 768;
- }
- else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
- {
- set_w = 1280;
- set_h = 720;
- }
- else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
- {
- set_w = 1280;
- set_h = 1024;
- }
- else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
- {
- set_w = 1600;
- set_h = 1200;
- }
- else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
- {
- set_w = 1920;
- set_h = 1080;
- }
- else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
- {
- set_w = 2048;
- set_h = 1536;
- }
- else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
- {
- set_w = 2592;
- set_h = 1944;
- }
- else
- {
- set_w = SENSOR_INIT_WIDTH;
- set_h = SENSOR_INIT_HEIGHT;
- }
-
- mf->width = set_w;
- mf->height = set_h;
-
- mf->colorspace = fmt->colorspace;
-
- return ret;
-}
-
- static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
-
- if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
- return -EINVAL;
-
- if (id->match.addr != client->addr)
- return -ENODEV;
-
- id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
- id->revision = 0;
-
- return 0;
-}
-#if CONFIG_SENSOR_Brightness
-static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Effect
-static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n%s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Exposure
-static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Saturation
-static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Contrast
-static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Mirror
-static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Flip
-static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Scene
-static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_WhiteBalance
-static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
-
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
- {
- if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
- {
- if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
- }
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_DigitalZoom
-static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl_info;
- int digitalzoom_cur, digitalzoom_total;
-
- qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
- if (qctrl_info)
- return -EINVAL;
-
- digitalzoom_cur = sensor->info_priv.digitalzoom;
- digitalzoom_total = qctrl_info->maximum;
-
- if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
- {
- SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
- return -EINVAL;
- }
-
- if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
- {
- SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
- return -EINVAL;
- }
-
- if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
- {
- *value = digitalzoom_total - digitalzoom_cur;
- }
-
- if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
- {
- *value = 0 - digitalzoom_cur;
- }
-
- digitalzoom_cur += *value;
-
- if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
- {
- if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
- {
- SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
- return -EINVAL;
- }
- SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
- return 0;
- }
-
- return -EINVAL;
-}
-#endif
-#if CONFIG_SENSOR_Focus
-static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl_info;
- int ret = 0;
-
- qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
- if (!qctrl_info)
- return -EINVAL;
-
- if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
- if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
- ret = sensor_af_workqueue_set(icd, WqCmd_af_special_pos, value, true);
- SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
- } else {
- ret = -EINVAL;
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- }
- } else {
- ret = -EACCES;
- SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
- sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
- }
-
- return ret;
-}
-static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl_info;
- int ret = 0;
-
- qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
- if (!qctrl_info)
- return -EINVAL;
-
- if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
- if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
- if (value > 0) {
- ret = sensor_af_workqueue_set(icd, WqCmd_af_near_pos, 0, true);
- } else {
- ret = sensor_af_workqueue_set(icd, WqCmd_af_far_pos, 0, true);
- }
- SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
- } else {
- ret = -EINVAL;
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- }
- } else {
- ret = -EACCES;
- SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
- sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
- }
- return ret;
-}
-
-static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- int ret = 0;
-
- if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
- switch (value)
- {
- case SENSOR_AF_MODE_AUTO:
- {
- ret = sensor_af_workqueue_set(icd, WqCmd_af_single, 0, true);
- break;
- }
-
- /*case SENSOR_AF_MODE_MACRO:
- {
- ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
- break;
- }
-
- case SENSOR_AF_MODE_INFINITY:
- {
- ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
- break;
- }
-
- case SENSOR_AF_MODE_CONTINUOUS:
- {
- ret = sensor_af_workqueue_set(icd, WqCmd_af_continues, 0, true);
- break;
- }*/
- default:
- SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- break;
-
- }
-
- SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
- } else {
- ret = -EACCES;
- SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
- sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
- }
-
- return ret;
-}
-#endif
-#if CONFIG_SENSOR_Flash
-static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
-{
- if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
- if (value == 3) { /* ddl@rock-chips.com: torch */
- sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
- } else {
- sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
- }
- SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
- return 0;
- }
-
- SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
- return -EINVAL;
-}
-#endif
-static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct sensor *sensor = to_sensor(client);
- const struct v4l2_queryctrl *qctrl;
-
- qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
-
- if (!qctrl)
- {
- SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
- return -EINVAL;
- }
-
- switch (ctrl->id)
- {
- case V4L2_CID_BRIGHTNESS:
- {
- ctrl->value = sensor->info_priv.brightness;
- break;
- }
- case V4L2_CID_SATURATION:
- {
- ctrl->value = sensor->info_priv.saturation;
- break;
- }
- case V4L2_CID_CONTRAST:
- {
- ctrl->value = sensor->info_priv.contrast;
- break;
- }
- case V4L2_CID_DO_WHITE_BALANCE:
- {
- ctrl->value = sensor->info_priv.whiteBalance;
- break;
- }
- case V4L2_CID_EXPOSURE:
- {
- ctrl->value = sensor->info_priv.exposure;
- break;
- }
- case V4L2_CID_HFLIP:
- {
- ctrl->value = sensor->info_priv.mirror;
- break;
- }
- case V4L2_CID_VFLIP:
- {
- ctrl->value = sensor->info_priv.flip;
- break;
- }
- default :
- break;
- }
- return 0;
-}
-
-
-
-static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct sensor *sensor = to_sensor(client);
- struct soc_camera_device *icd = client->dev.platform_data;
- const struct v4l2_queryctrl *qctrl;
-
-
- qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
-
- if (!qctrl)
- {
- SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
- return -EINVAL;
- }
-
- switch (ctrl->id)
- {
-#if CONFIG_SENSOR_Brightness
- case V4L2_CID_BRIGHTNESS:
- {
- if (ctrl->value != sensor->info_priv.brightness)
- {
- if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
- {
- return -EINVAL;
- }
- sensor->info_priv.brightness = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Exposure
- case V4L2_CID_EXPOSURE:
- {
- if (ctrl->value != sensor->info_priv.exposure)
- {
- if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
- {
- return -EINVAL;
- }
- sensor->info_priv.exposure = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Saturation
- case V4L2_CID_SATURATION:
- {
- if (ctrl->value != sensor->info_priv.saturation)
- {
- if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
- {
- return -EINVAL;
- }
- sensor->info_priv.saturation = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Contrast
- case V4L2_CID_CONTRAST:
- {
- if (ctrl->value != sensor->info_priv.contrast)
- {
- if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
- {
- return -EINVAL;
- }
- sensor->info_priv.contrast = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_WhiteBalance
- case V4L2_CID_DO_WHITE_BALANCE:
- {
- if (ctrl->value != sensor->info_priv.whiteBalance)
- {
- if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
- {
- return -EINVAL;
- }
- sensor->info_priv.whiteBalance = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Mirror
- case V4L2_CID_HFLIP:
- {
- if (ctrl->value != sensor->info_priv.mirror)
- {
- if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.mirror = ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Flip
- case V4L2_CID_VFLIP:
- {
- if (ctrl->value != sensor->info_priv.flip)
- {
- if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.flip = ctrl->value;
- }
- break;
- }
-#endif
- default:
- break;
- }
-
- return 0;
-}
-static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
-{
- const struct v4l2_queryctrl *qctrl;
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
-
- qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
-
- if (!qctrl)
- {
- SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
- return -EINVAL;
- }
-
- switch (ext_ctrl->id)
- {
- case V4L2_CID_SCENE:
- {
- ext_ctrl->value = sensor->info_priv.scene;
- break;
- }
- case V4L2_CID_EFFECT:
- {
- ext_ctrl->value = sensor->info_priv.effect;
- break;
- }
- case V4L2_CID_ZOOM_ABSOLUTE:
- {
- ext_ctrl->value = sensor->info_priv.digitalzoom;
- break;
- }
- case V4L2_CID_ZOOM_RELATIVE:
- {
- return -EINVAL;
- }
- case V4L2_CID_FOCUS_ABSOLUTE:
- {
- return -EINVAL;
- }
- case V4L2_CID_FOCUS_RELATIVE:
- {
- return -EINVAL;
- }
- case V4L2_CID_FLASH:
- {
- ext_ctrl->value = sensor->info_priv.flash;
- break;
- }
- default :
- break;
- }
- return 0;
-}
-static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
-{
- const struct v4l2_queryctrl *qctrl;
- struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
- struct sensor *sensor = to_sensor(client);
- int val_offset,ret;
-
- qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
-
- if (!qctrl)
- {
- SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
- return -EINVAL;
- }
-
- val_offset = 0;
- switch (ext_ctrl->id)
- {
-#if CONFIG_SENSOR_Scene
- case V4L2_CID_SCENE:
- {
- if (ext_ctrl->value != sensor->info_priv.scene)
- {
- if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.scene = ext_ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Effect
- case V4L2_CID_EFFECT:
- {
- if (ext_ctrl->value != sensor->info_priv.effect)
- {
- if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.effect= ext_ctrl->value;
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_DigitalZoom
- case V4L2_CID_ZOOM_ABSOLUTE:
- {
- if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
- return -EINVAL;
-
- if (ext_ctrl->value != sensor->info_priv.digitalzoom)
- {
- val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
-
- if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
- return -EINVAL;
- sensor->info_priv.digitalzoom += val_offset;
-
- SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
- }
-
- break;
- }
- case V4L2_CID_ZOOM_RELATIVE:
- {
- if (ext_ctrl->value)
- {
- if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.digitalzoom += ext_ctrl->value;
-
- SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
- }
- break;
- }
-#endif
-#if CONFIG_SENSOR_Focus
- case V4L2_CID_FOCUS_ABSOLUTE:
- {
- if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
- return -EINVAL;
-
- break;
- }
- case V4L2_CID_FOCUS_RELATIVE:
- {
- if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
- return -EINVAL;
-
- sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
- break;
- }
- case V4L2_CID_FOCUS_AUTO:
- {
- if (ext_ctrl->value == 1) {
- if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0) {
- if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
- sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
- }
- return -EINVAL;
- }
- sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
- } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
- if (ext_ctrl->value == 0)
- sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
- }
- break;
- }
- case V4L2_CID_FOCUS_CONTINUOUS:
- {
- /*if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
- if (ext_ctrl->value == 1) {
- if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
- return -EINVAL;
- sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
- }
- } else {
- if (ext_ctrl->value == 0)
- sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
- }*/
- break;
- }
-#endif
-#if CONFIG_SENSOR_Flash
- case V4L2_CID_FLASH:
- {
- if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
- return -EINVAL;
- sensor->info_priv.flash = ext_ctrl->value;
-
- SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
- break;
- }
-#endif
- default:
- break;
- }
-
- return 0;
-}
-
-static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_device *icd = client->dev.platform_data;
- int i, error_cnt=0, error_idx=-1;
-
-
- for (i=0; i<ext_ctrl->count; i++) {
- if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
- error_cnt++;
- error_idx = i;
- }
- }
-
- if (error_cnt > 1)
- error_idx = ext_ctrl->count;
-
- if (error_idx != -1) {
- ext_ctrl->error_idx = error_idx;
- return -EINVAL;
- } else {
- return 0;
- }
-}
-
-static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_device *icd = client->dev.platform_data;
- int i, error_cnt=0, error_idx=-1;
-
- for (i=0; i<ext_ctrl->count; i++) {
- if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
- error_cnt++;
- error_idx = i;
- }
- }
-
- if (error_cnt > 1)
- error_idx = ext_ctrl->count;
-
- if (error_idx != -1) {
- ext_ctrl->error_idx = error_idx;
- return -EINVAL;
- } else {
- return 0;
- }
-}
-
-static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct sensor *sensor = to_sensor(client);
- #if CONFIG_SENSOR_Focus
- struct soc_camera_device *icd = client->dev.platform_data;
- struct v4l2_mbus_framefmt mf;
- #endif
-
- if (enable == 1) {
- sensor->info_priv.enable = 1;
- #if CONFIG_SENSOR_Focus
- mf.width = icd->user_width;
- mf.height = icd->user_height;
- mf.code = sensor->info_priv.fmt.code;
- mf.colorspace = sensor->info_priv.fmt.colorspace;
- mf.field = V4L2_FIELD_NONE;
- /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
- if (sensor_fmt_capturechk(sd, &mf) == false) {
- if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
- sensor_af_workqueue_set(icd, WqCmd_af_init, 0, false);
- sensor->info_priv.affm_reinit = 0;
- }
- }
- #endif
- } else if (enable == 0) {
- sensor->info_priv.enable = 0;
- #if CONFIG_SENSOR_Focus
- flush_workqueue(sensor->sensor_wq);
- #endif
- }
- return 0;
-}
-
-/* Interface active, can use i2c. If it fails, it can indeed mean, that
- * this wasn't our capture interface, so, we wait for the right one */
-static int sensor_video_probe(struct soc_camera_device *icd,
- struct i2c_client *client)
-{
- char value;
- int ret,pid = 0;
- struct sensor *sensor = to_sensor(client);
-
- /* We must have a parent by now. And it cannot be a wrong one.
- * So this entire test is completely redundant. */
- if (!icd->dev.parent ||
- to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
- return -ENODEV;
-
- if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
- ret = -ENODEV;
- goto sensor_video_probe_err;
- }
- /* soft reset */
- ret = sensor_write(client, 0x3008, 0x80);
- if (ret != 0) {
- SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
- ret = -ENODEV;
- goto sensor_video_probe_err;
- }
- mdelay(5); //delay 5 microseconds
-
- /* check if it is an sensor sensor */
- ret = sensor_read(client, 0x300a, &value);
- if (ret != 0) {
- SENSOR_TR("read chip id high byte failed\n");
- ret = -ENODEV;
- goto sensor_video_probe_err;
- }
-
- pid |= (value << 8);
-
- ret = sensor_read(client, 0x300b, &value);
- if (ret != 0) {
- SENSOR_TR("read chip id low byte failed\n");
- ret = -ENODEV;
- goto sensor_video_probe_err;
- }
-
- pid |= (value & 0xff);
- SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
- if (pid == SENSOR_ID) {
- sensor->model = SENSOR_V4L2_IDENT;
- } else {
- SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
- ret = -ENODEV;
- goto sensor_video_probe_err;
- }
-
- return 0;
-
-sensor_video_probe_err:
- return ret;
-}
-static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
-{
- struct i2c_client *client = v4l2_get_subdevdata(sd);
- struct soc_camera_device *icd = client->dev.platform_data;
- struct sensor *sensor = to_sensor(client);
- int ret = 0,i;
-
- SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
- switch (cmd)
- {
- case RK29_CAM_SUBDEV_DEACTIVATE:
- {
- sensor_deactivate(client);
- break;
- }
- case RK29_CAM_SUBDEV_IOREQUEST:
- {
- sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
- if (sensor->sensor_io_request != NULL) {
- sensor->sensor_gpio_res = NULL;
- for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
- if (sensor->sensor_io_request->gpio_res[i].dev_name &&
- (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
- sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
- }
- }
- if (sensor->sensor_gpio_res == NULL) {
- SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
- ret = -EINVAL;
- goto sensor_ioctl_end;
- }
- } else {
- SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
- ret = -EINVAL;
- goto sensor_ioctl_end;
- }
- /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
- for this project */
- #if CONFIG_SENSOR_Flash
- if (sensor->sensor_gpio_res) {
- printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
- if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
- for (i = 0; i < icd->ops->num_controls; i++) {
- if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
- //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
- sensor_controls[i].id=0xffff;
- }
- }
- sensor->info_priv.flash = 0xff;
- SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
- }else{ //two cameras are the same,need to deal diffrently ,zyc
- for (i = 0; i < icd->ops->num_controls; i++) {
- if(0xffff == icd->ops->controls[i].id){
- sensor_controls[i].id=V4L2_CID_FLASH;
- }
- }
- }
- }
- #endif
- break;
- }
- default:
- {
- SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
- break;
- }
- }
-
-sensor_ioctl_end:
- return ret;
-
-}
-static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
- enum v4l2_mbus_pixelcode *code)
-{
- if (index >= ARRAY_SIZE(sensor_colour_fmts))
- return -EINVAL;
-
- *code = sensor_colour_fmts[index].code;
- return 0;
-}
-static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
- .init = sensor_init,
- .g_ctrl = sensor_g_control,
- .s_ctrl = sensor_s_control,
- .g_ext_ctrls = sensor_g_ext_controls,
- .s_ext_ctrls = sensor_s_ext_controls,
- .g_chip_ident = sensor_g_chip_ident,
- .ioctl = sensor_ioctl,
-};
-
-static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
- .s_mbus_fmt = sensor_s_fmt,
- .g_mbus_fmt = sensor_g_fmt,
- .try_mbus_fmt = sensor_try_fmt,
- .enum_mbus_fmt = sensor_enum_fmt,
- .s_stream = sensor_s_stream,
-};
-
-static struct v4l2_subdev_ops sensor_subdev_ops = {
- .core = &sensor_subdev_core_ops,
- .video = &sensor_subdev_video_ops,
-};
-
-static int sensor_probe(struct i2c_client *client,
- const struct i2c_device_id *did)
-{
- struct sensor *sensor;
- struct soc_camera_device *icd = client->dev.platform_data;
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
- struct soc_camera_link *icl;
- int ret;
-
- SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
- if (!icd) {
- dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
- return -EINVAL;
- }
-
- icl = to_soc_camera_link(icd);
- if (!icl) {
- dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
- return -EINVAL;
- }
-
- if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
- dev_warn(&adapter->dev,
- "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
- return -EIO;
- }
-
- sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
- if (!sensor)
- return -ENOMEM;
-
- v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
-
- /* Second stage probe - when a capture adapter is there */
- icd->ops = &sensor_ops;
- sensor->info_priv.fmt = sensor_colour_fmts[0];
- #if CONFIG_SENSOR_I2C_NOSCHED
- atomic_set(&sensor->tasklock_cnt,0);
- #endif
-
- ret = sensor_video_probe(icd, client);
- if (ret < 0) {
- icd->ops = NULL;
- i2c_set_clientdata(client, NULL);
- kfree(sensor);
- sensor = NULL;
- } else {
- #if CONFIG_SENSOR_Focus
- sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING(_af_workqueue));
- if (sensor->sensor_wq == NULL)
- SENSOR_TR("%s create fail!", SENSOR_NAME_STRING(_af_workqueue));
- mutex_init(&sensor->wq_lock);
- #endif
- }
- hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
- SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
- return ret;
-}
-
-static int sensor_remove(struct i2c_client *client)
-{
- struct sensor *sensor = to_sensor(client);
- struct soc_camera_device *icd = client->dev.platform_data;
-
- #if CONFIG_SENSOR_Focus
- if (sensor->sensor_wq) {
- destroy_workqueue(sensor->sensor_wq);
- sensor->sensor_wq = NULL;
- }
- #endif
-
- icd->ops = NULL;
- i2c_set_clientdata(client, NULL);
- client->driver = NULL;
- kfree(sensor);
- sensor = NULL;
- return 0;
-}
-
-static const struct i2c_device_id sensor_id[] = {
- {SENSOR_NAME_STRING(), 0 },
- { }
-};
-MODULE_DEVICE_TABLE(i2c, sensor_id);
-
-static struct i2c_driver sensor_i2c_driver = {
- .driver = {
- .name = SENSOR_NAME_STRING(),
- },
- .probe = sensor_probe,
- .remove = sensor_remove,
- .id_table = sensor_id,
-};
-
-static int __init sensor_mod_init(void)
-{
- SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
- return i2c_add_driver(&sensor_i2c_driver);
-}
-
-static void __exit sensor_mod_exit(void)
-{
- i2c_del_driver(&sensor_i2c_driver);
-}
-
-device_initcall_sync(sensor_mod_init);
-module_exit(sensor_mod_exit);
-
-MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
-MODULE_AUTHOR("ddl <kernel@rock-chips>");
-MODULE_LICENSE("GPL");
-
-
+* Driver Version Note\r
+*v0.0.1: this driver is compatible with generic_sensor\r
+*v0.1.1:\r
+* add sensor_focus_af_const_pause_usr_cb;\r
+*v0.1.3:\r
+* config sensor io H-Z in sensor_deactive_cb;\r
+*/\r
+static int version = KERNEL_VERSION(0,1,3);\r
+module_param(version, int, S_IRUGO);\r
+\r
+\r
+static int debug;\r
+module_param(debug, int, S_IRUGO|S_IWUSR);\r
+\r
+#define dprintk(level, fmt, arg...) do { \\r
+ if (debug >= level) \\r
+ printk(KERN_WARNING fmt , ## arg); } while (0)\r
+\r
+/* Sensor Driver Configuration Begin */\r
+#define SENSOR_NAME RK29_CAM_SENSOR_OV5640\r
+#define SENSOR_V4L2_IDENT V4L2_IDENT_OV5640\r
+#define SENSOR_ID 0x5640\r
+#define SENSOR_BUS_PARAM (V4L2_MBUS_MASTER |\\r
+ V4L2_MBUS_PCLK_SAMPLE_RISING|V4L2_MBUS_HSYNC_ACTIVE_HIGH| V4L2_MBUS_VSYNC_ACTIVE_LOW|\\r
+ V4L2_MBUS_DATA_ACTIVE_HIGH |SOCAM_MCLK_24MHZ)\r
+#define SENSOR_PREVIEW_W 800\r
+#define SENSOR_PREVIEW_H 600\r
+#define SENSOR_PREVIEW_FPS 15000 // 15fps \r
+#define SENSOR_FULLRES_L_FPS 7500 // 7.5fps\r
+#define SENSOR_FULLRES_H_FPS 7500 // 7.5fps\r
+#define SENSOR_720P_FPS 30000\r
+#define SENSOR_1080P_FPS 15000\r
+\r
+#define SENSOR_REGISTER_LEN 2 // sensor register address bytes\r
+#define SENSOR_VALUE_LEN 1 // sensor register value bytes\r
+ \r
+static unsigned int SensorConfiguration = (CFG_WhiteBalance|CFG_Effect\r
+ |CFG_Scene|CFG_Focus\r
+ |CFG_FocusZone);\r
+\r
+static unsigned int SensorChipID[] = {SENSOR_ID};\r
+/* Sensor Driver Configuration End */\r
+\r
+\r
+#define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))\r
+#define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)\r
+\r
+#define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)\r
+#define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))\r
+#define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))\r
+#define sensor_write_array generic_sensor_write_array\r
+\r
+#if 1//CONFIG_SENSOR_Focus\r
+#include "ov5640_af_firmware.c"\r
+/* ov5640 VCM Command and Status Registers */\r
+#define CONFIG_SENSOR_FocusCenterInCapture 0\r
+#define CMD_MAIN_Reg 0x3022\r
+//#define CMD_TAG_Reg 0x3023\r
+#define CMD_ACK_Reg 0x3023\r
+#define CMD_PARA0_Reg 0x3024\r
+#define CMD_PARA1_Reg 0x3025\r
+#define CMD_PARA2_Reg 0x3026\r
+#define CMD_PARA3_Reg 0x3027\r
+#define CMD_PARA4_Reg 0x3028\r
+\r
+//#define STA_ZONE_Reg 0x3026\r
+#define STA_FOCUS_Reg 0x3029\r
+\r
+/* ov5640 VCM Command */\r
+\r
+#define ConstFocus_Cmd 0x04\r
+#define StepMode_Cmd 0x05\r
+#define PauseFocus_Cmd 0x06\r
+#define ReturnIdle_Cmd 0x08\r
+#define SetZone_Cmd 0x10\r
+#define UpdateZone_Cmd 0x12\r
+#define SetMotor_Cmd 0x20\r
+#define SingleFocus_Cmd 0x03\r
+#define GetFocusResult_Cmd 0x07\r
+#define ReleaseFocus_Cmd 0x08\r
+#define ZoneRelaunch_Cmd 0x12\r
+#define DefaultZoneConfig_Cmd 0x80\r
+#define TouchZoneConfig_Cmd 0x81\r
+#define CustomZoneConfig_Cmd 0x8f\r
+\r
+\r
+/* ov5640 Focus State */\r
+//#define S_FIRWRE 0xFF /*Firmware is downloaded and not run*/\r
+#define S_STARTUP 0x7e /*Firmware is initializing*/\r
+#define S_ERROR 0x7f\r
+#define S_IDLE 0x70 /*Idle state, focus is released; lens is located at the furthest position.*/\r
+#define S_FOCUSING 0x00 /*Auto Focus is running.*/\r
+#define S_FOCUSED 0x10 /*Auto Focus is completed.*/\r
+\r
+#define S_CAPTURE 0x12\r
+#define S_STEP 0x20\r
+\r
+/* ov5640 Zone State */\r
+#define Zone_Is_Focused(a, zone_val) (zone_val&(1<<(a-3)))\r
+#define Zone_Get_ID(zone_val) (zone_val&0x03)\r
+\r
+#define Zone_CenterMode 0x01\r
+#define Zone_5xMode 0x02\r
+#define Zone_5PlusMode 0x03\r
+#define Zone_4fMode 0x04\r
+\r
+#define ZoneSel_Auto 0x0b\r
+#define ZoneSel_SemiAuto 0x0c\r
+#define ZoneSel_Manual 0x0d\r
+#define ZoneSel_Rotate 0x0e\r
+\r
+/* ov5640 Step Focus Commands */\r
+#define StepFocus_Near_Tag 0x01\r
+#define StepFocus_Far_Tag 0x02\r
+#define StepFocus_Furthest_Tag 0x03\r
+#define StepFocus_Nearest_Tag 0x04\r
+#define StepFocus_Spec_Tag 0x10\r
+#endif\r
+\r
+struct sensor_parameter\r
+{\r
+ unsigned int PreviewDummyPixels;\r
+ unsigned int CaptureDummyPixels;\r
+ unsigned int preview_exposure;\r
+ unsigned short int preview_line_width;\r
+ unsigned short int preview_gain;\r
+ unsigned short int preview_maxlines;\r
+\r
+ unsigned short int PreviewPclk;\r
+ unsigned short int CapturePclk;\r
+ char awb[6];\r
+};\r
+\r
+struct specific_sensor{\r
+ struct generic_sensor common_sensor;\r
+ //define user data below\r
+ struct sensor_parameter parameter;\r
+\r
+};\r
+\r
+/*\r
+* The follow setting need been filled.\r
+* \r
+* Must Filled:\r
+* sensor_init_data : Sensor initial setting;\r
+* sensor_fullres_lowfps_data : Sensor full resolution setting with best auality, recommand for video;\r
+* sensor_preview_data : Sensor preview resolution setting, recommand it is vga or svga;\r
+* sensor_softreset_data : Sensor software reset register;\r
+* sensor_check_id_data : Sensir chip id register;\r
+*\r
+* Optional filled:\r
+* sensor_fullres_highfps_data: Sensor full resolution setting with high framerate, recommand for video;\r
+* sensor_720p: Sensor 720p setting, it is for video;\r
+* sensor_1080p: Sensor 1080p setting, it is for video;\r
+*\r
+* :::::WARNING:::::\r
+* The SensorEnd which is the setting end flag must be filled int the last of each setting;\r
+*/\r
+\r
+/* Sensor initial setting */\r
+static struct rk_sensor_reg sensor_init_data[] ={\r
+ {0x3103, 0x11},\r
+ {0x3008, 0x82},\r
+ SensorWaitMs(5),\r
+ {0x3008, 0x42},\r
+ {0x3103, 0x03},\r
+ {0x3017, 0xff},\r
+ {0x3018, 0xff},\r
+ {0x3034, 0x1a},\r
+ {0x3035, 0x21},\r
+ {0x3036, 0x46},\r
+ {0x3037, 0x12},\r
+ {0x3108, 0x01},\r
+ {0x3630, 0x36},\r
+ {0x3631, 0x0e},\r
+ {0x3632, 0xe2},\r
+ {0x3633, 0x12},\r
+ {0x3621, 0xe0},\r
+ {0x3704, 0xa0},\r
+ {0x3703, 0x5a},\r
+ {0x3715, 0x78},\r
+ {0x3717, 0x01},\r
+ {0x370b, 0x60},\r
+ {0x3705, 0x1a},\r
+ {0x3905, 0x02},\r
+ {0x3906, 0x10},\r
+ {0x3901, 0x0a},\r
+ {0x3731, 0x12},\r
+ {0x3600, 0x08},\r
+ {0x3601, 0x33},\r
+ {0x302d, 0x60},\r
+ {0x3620, 0x52},\r
+ {0x371b, 0x20},\r
+ {0x471c, 0x50},\r
+ {0x3a13, 0x43},\r
+ {0x3a18, 0x00},\r
+ {0x3a19, 0xf8},\r
+ {0x3635, 0x13},\r
+ {0x3636, 0x03},\r
+ {0x3634, 0x40},\r
+ {0x3622, 0x01},\r
+ {0x3c01, 0x34},\r
+ {0x3c04, 0x28},\r
+ {0x3c05, 0x98},\r
+ {0x3c06, 0x00},\r
+ {0x3c07, 0x08},\r
+ {0x3c08, 0x00},\r
+ {0x3c09, 0x1c},\r
+ {0x3c0a, 0x9c},\r
+ {0x3c0b, 0x40},\r
+ {0x3820, 0x41},\r
+ {0x3821, 0x07},\r
+ {0x3814, 0x31},\r
+ {0x3815, 0x31},\r
+ {0x3800, 0x00},\r
+ {0x3801, 0x00},\r
+ {0x3802, 0x00},\r
+ {0x3803, 0x04},\r
+ {0x3804, 0x0a},\r
+ {0x3805, 0x3f},\r
+ {0x3806, 0x07},\r
+ {0x3807, 0x9b},\r
+ {0x3808, 0x03},\r
+ {0x3809, 0x20},\r
+ {0x380a, 0x02},\r
+ {0x380b, 0x58},\r
+ {0x380c, 0x07},\r
+ {0x380d, 0x68},\r
+ {0x380e, 0x03},\r
+ {0x380f, 0xd8},\r
+ {0x3810, 0x00},\r
+ {0x3811, 0x10},\r
+ {0x3812, 0x00},\r
+ {0x3813, 0x06},\r
+ {0x3618, 0x00},\r
+ {0x3612, 0x29},\r
+ {0x3708, 0x64},\r
+ {0x3709, 0x52},\r
+ {0x370c, 0x03},\r
+ {0x3a02, 0x03},\r
+ {0x3a03, 0xd8},\r
+ {0x3a08, 0x01},\r
+ {0x3a09, 0x27},\r
+ {0x3a0a, 0x00},\r
+ {0x3a0b, 0xf6},\r
+ {0x3a0e, 0x03},\r
+ {0x3a0d, 0x04},\r
+ {0x3a14, 0x03},\r
+ {0x3a15, 0xd8},\r
+ {0x4001, 0x02},\r
+ {0x4004, 0x02},\r
+ {0x3000, 0x00},\r
+ {0x3002, 0x1c},\r
+ {0x3004, 0xff},\r
+ {0x3006, 0xc3},\r
+ {0x300e, 0x58},\r
+ {0x302e, 0x00},\r
+ {0x4740, 0x20},\r
+ {0x4300, 0x32},//uyvy:0x32,yuyv:0x30\r
+ {0x501f, 0x00},\r
+ {0x4713, 0x03},\r
+ {0x4407, 0x04},\r
+ {0x440e, 0x00},\r
+ {0x460b, 0x35},\r
+ {0x460c, 0x20},\r
+ {0x4837, 0x22},\r
+ {0x3824, 0x02},\r
+ {0x5000, 0xa7},\r
+ {0x5001, 0xa3},\r
+ {0x5180, 0xff},\r
+ {0x5181, 0xf2},\r
+ {0x5182, 0x00},\r
+ {0x5183, 0x14},\r
+ {0x5184, 0x25},\r
+ {0x5185, 0x24},\r
+ {0x5186, 0x09},\r
+ {0x5187, 0x09},\r
+ {0x5188, 0x09},\r
+ {0x5189, 0x75},\r
+ {0x518a, 0x54},\r
+ {0x518b, 0xe0},\r
+ {0x518c, 0xb2},\r
+ {0x518d, 0x42},\r
+ {0x518e, 0x3d},\r
+ {0x518f, 0x56},\r
+ {0x5190, 0x46},\r
+ {0x5191, 0xf8},\r
+ {0x5192, 0x04},\r
+ {0x5193, 0x70},\r
+ {0x5194, 0xf0},\r
+ {0x5195, 0xf0},\r
+ {0x5196, 0x03},\r
+ {0x5197, 0x01},\r
+ {0x5198, 0x04},\r
+ {0x5199, 0x12},\r
+ {0x519a, 0x04},\r
+ {0x519b, 0x00},\r
+ {0x519c, 0x06},\r
+ {0x519d, 0x82},\r
+ {0x519e, 0x38},\r
+ {0x5381, 0x1e},\r
+ {0x5382, 0x5b},\r
+ {0x5383, 0x08},\r
+ {0x5384, 0x0a},\r
+ {0x5385, 0x7e},\r
+ {0x5386, 0x88},\r
+ {0x5387, 0x7c},\r
+ {0x5388, 0x6c},\r
+ {0x5389, 0x10},\r
+ {0x538a, 0x01},\r
+ {0x538b, 0x98},\r
+ {0x5300, 0x08},\r
+ {0x5301, 0x30},\r
+ {0x5302, 0x10},\r
+ {0x5303, 0x00},\r
+ {0x5304, 0x08},\r
+ {0x5305, 0x30},\r
+ {0x5306, 0x08},\r
+ {0x5307, 0x16},\r
+ {0x5309, 0x08},\r
+ {0x530a, 0x30},\r
+ {0x530b, 0x04},\r
+ {0x530c, 0x06},\r
+ {0x5480, 0x01},\r
+ {0x5481, 0x08},\r
+ {0x5482, 0x14},\r
+ {0x5483, 0x28},\r
+ {0x5484, 0x51},\r
+ {0x5485, 0x65},\r
+ {0x5486, 0x71},\r
+ {0x5487, 0x7d},\r
+ {0x5488, 0x87},\r
+ {0x5489, 0x91},\r
+ {0x548a, 0x9a},\r
+ {0x548b, 0xaa},\r
+ {0x548c, 0xb8},\r
+ {0x548d, 0xcd},\r
+ {0x548e, 0xdd},\r
+ {0x548f, 0xea},\r
+ {0x5490, 0x1d},\r
+ {0x5580, 0x02},\r
+ {0x5583, 0x40},\r
+ {0x5584, 0x10},\r
+ {0x5589, 0x10},\r
+ {0x558a, 0x00},\r
+ {0x558b, 0xf8},\r
+ {0x5800, 0x23},\r
+ {0x5801, 0x14},\r
+ {0x5802, 0x0f},\r
+ {0x5803, 0x0f},\r
+ {0x5804, 0x12},\r
+ {0x5805, 0x26},\r
+ {0x5806, 0x0c},\r
+ {0x5807, 0x08},\r
+ {0x5808, 0x05},\r
+ {0x5809, 0x05},\r
+ {0x580a, 0x08},\r
+ {0x580b, 0x0d},\r
+ {0x580c, 0x08},\r
+ {0x580d, 0x03},\r
+ {0x580e, 0x00},\r
+ {0x580f, 0x00},\r
+ {0x5810, 0x03},\r
+ {0x5811, 0x09},\r
+ {0x5812, 0x07},\r
+ {0x5813, 0x03},\r
+ {0x5814, 0x00},\r
+ {0x5815, 0x01},\r
+ {0x5816, 0x03},\r
+ {0x5817, 0x08},\r
+ {0x5818, 0x0d},\r
+ {0x5819, 0x08},\r
+ {0x581a, 0x05},\r
+ {0x581b, 0x06},\r
+ {0x581c, 0x08},\r
+ {0x581d, 0x0e},\r
+ {0x581e, 0x29},\r
+ {0x581f, 0x17},\r
+ {0x5820, 0x11},\r
+ {0x5821, 0x11},\r
+ {0x5822, 0x15},\r
+ {0x5823, 0x28},\r
+ {0x5824, 0x46},\r
+ {0x5825, 0x26},\r
+ {0x5826, 0x08},\r
+ {0x5827, 0x26},\r
+ {0x5828, 0x64},\r
+ {0x5829, 0x26},\r
+ {0x582a, 0x24},\r
+ {0x582b, 0x22},\r
+ {0x582c, 0x24},\r
+ {0x582d, 0x24},\r
+ {0x582e, 0x06},\r
+ {0x582f, 0x22},\r
+ {0x5830, 0x40},\r
+ {0x5831, 0x42},\r
+ {0x5832, 0x24},\r
+ {0x5833, 0x26},\r
+ {0x5834, 0x24},\r
+ {0x5835, 0x22},\r
+ {0x5836, 0x22},\r
+ {0x5837, 0x26},\r
+ {0x5838, 0x44},\r
+ {0x5839, 0x24},\r
+ {0x583a, 0x26},\r
+ {0x583b, 0x28},\r
+ {0x583c, 0x42},\r
+ {0x583d, 0xce},\r
+ {0x5025, 0x00},\r
+ {0x3a0f, 0x30},\r
+ {0x3a10, 0x28},\r
+ {0x3a1b, 0x30},\r
+ {0x3a1e, 0x26},\r
+ {0x3a11, 0x60},\r
+ {0x3a1f, 0x14},\r
+ {0x3008, 0x02},\r
+ {0x302c, 0xc2},\r
+ SensorWaitUs(1000),\r
+ SensorEnd\r
+};\r
+/* Senor full resolution setting: recommand for capture */\r
+static struct rk_sensor_reg sensor_fullres_lowfps_data[] ={\r
+\r
+ {0x3820, 0x40}, \r
+ {0x3821, 0x06}, \r
+ {0x3814, 0x11}, \r
+ {0x3815, 0x11}, \r
+ {0x3803, 0x00}, \r
+ {0x3807, 0x9f}, \r
+ {0x3808, 0x0a}, \r
+ {0x3809, 0x20}, \r
+ {0x380a, 0x07}, \r
+ {0x380b, 0x98}, \r
+ {0x380c, 0x0b}, \r
+ {0x380d, 0x1c}, \r
+ {0x380e, 0x07}, \r
+ {0x380f, 0xb0}, \r
+ {0x3811, 0x10}, //\r
+ {0x3813, 0x04}, \r
+ {0x3618, 0x04}, \r
+ {0x3612, 0x2b}, //4b \r
+ {0x3708, 0x64},\r
+ {0x3709, 0x12}, \r
+ {0x370c, 0x00}, \r
+ {0x3a02, 0x07}, \r
+ {0x3a03, 0xb0}, \r
+ {0x3a0e, 0x06}, \r
+ {0x3a0d, 0x08}, \r
+ {0x3a14, 0x07}, \r
+ {0x3a15, 0xb0}, \r
+ {0x4004, 0x06},\r
+ {0x5000, 0xa7}, \r
+ {0x5001, 0x83},\r
+ {0x519e, 0x38},\r
+ {0x5381, 0x1e},\r
+ {0x5382, 0x5b},\r
+ {0x5383, 0x08},\r
+ {0x460b, 0x37}, \r
+ {0x460c, 0x20}, \r
+ {0x3824, 0x01}, \r
+ {0x4005, 0x1A}, \r
+ SensorEnd\r
+};\r
+/* Senor full resolution setting: recommand for video */\r
+static struct rk_sensor_reg sensor_fullres_highfps_data[] ={\r
+ SensorEnd\r
+};\r
+/* Preview resolution setting*/\r
+static struct rk_sensor_reg sensor_preview_data[] =\r
+{\r
+ {0x3503, 0x00},\r
+ {0x3c07, 0x08},\r
+ {0x3820, 0x41},\r
+ {0x3821, 0x07},\r
+ {0x3814, 0x31},\r
+ {0x3815, 0x31},\r
+ {0x3803, 0x04},\r
+ {0x3806, 0x07},///\r
+ {0x3807, 0x9b},\r
+ {0x3808, 0x03},\r
+ {0x3809, 0x20},\r
+ {0x380a, 0x02},\r
+ {0x380b, 0x58},\r
+ {0x380c, 0x07},\r
+ {0x380d, 0x68},\r
+ {0x380e, 0x03},\r
+ {0x380f, 0xd8},\r
+ {0x3813, 0x06},\r
+ {0x3618, 0x00},\r
+ {0x3612, 0x29},\r
+ {0x3709, 0x52},\r
+ {0x370c, 0x03},\r
+ {0x3a02, 0x03},\r
+ {0x3a03, 0xd8},\r
+ {0x3a08 ,0x01},///\r
+ {0x3a09, 0x27},///\r
+ {0x3a0a, 0x00},///\r
+ {0x3a0b, 0xf6},///\r
+ {0x3a0e, 0x03},\r
+ {0x3a0d, 0x04},\r
+ {0x3a14, 0x03},\r
+ {0x3a15, 0xd8},\r
+ {0x4004, 0x02},\r
+ {0x3002, 0x1c},////\r
+ {0x4713, 0x03},////\r
+ {0x3035, 0x21},\r
+ {0x3036, 0x46},\r
+ {0x4837, 0x22},\r
+ {0x3824, 0x02},////\r
+ {0x5001, 0xa3},\r
+\r
+ SensorEnd\r
+};\r
+/* 1280x720 */\r
+static struct rk_sensor_reg sensor_720p[]={\r
+ {0x3503, 0x00},\r
+ \r
+ {0x3c07,0x07},\r
+ {0x3803,0xfa},\r
+ {0x3806,0x06},////\r
+ {0x3807,0xa9},\r
+ {0x3808,0x05},\r
+ {0x3809,0x00},\r
+ {0x380a,0x02},\r
+ {0x380b,0xd0},\r
+ {0x380c,0x07},\r
+ {0x380d,0x64},\r
+ {0x380e,0x02},\r
+ {0x380f,0xe4},\r
+ {0x3813,0x04},\r
+ {0x3a02,0x02},\r
+ {0x3a03,0xe4},\r
+ {0x3a08,0x01},///\r
+ {0x3a09,0xbc},////\r
+ {0x3a0a,0x01},///\r
+ {0x3a0b,0x72},////\r
+ {0x3a0e,0x01},\r
+ {0x3a0d,0x02},\r
+ {0x3a14,0x02},\r
+ {0x3a15,0xe4},\r
+ \r
+ {0x3820, 0x41}, //ddl@rock-chips.com add start: qsxvga -> 720p isn't stream on \r
+ {0x3821, 0x07},\r
+ {0x3814, 0x31},\r
+ {0x3815, 0x31},\r
+ \r
+ {0x3618, 0x00},\r
+ {0x3612, 0x29},\r
+ {0x3709, 0x52},\r
+ {0x370c, 0x03},\r
+ {0x3a02, 0x03},\r
+ {0x3a03, 0xd8},\r
+ {0x3a08 ,0x01},///\r
+ {0x3a09, 0x27},///\r
+ {0x3a0a, 0x00},///\r
+ {0x3a0b, 0xf6},///\r
+ {0x3a0e, 0x03},\r
+ {0x3a0d, 0x04},\r
+ {0x3a14, 0x03},\r
+ {0x3a15, 0xd8},\r
+ {0x4004, 0x02},\r
+ {0x3002, 0x1c},////\r
+ {0x4713, 0x03},//////ddl@rock-chips.com add end\r
+ \r
+ {0x3002,0x00},///\r
+ {0x4713,0x02},///\r
+ {0x4837,0x16},\r
+ {0x3824,0x04},///\r
+ {0x5001,0x83},\r
+ {0x3035,0x21},\r
+ {0x3036,0x46},\r
+ \r
+ {0x4837, 0x22},\r
+ {0x5001, 0xa3},\r
+ SensorEnd\r
+};\r
+\r
+/* 1920x1080 */\r
+static struct rk_sensor_reg sensor_1080p[]={\r
+ SensorEnd\r
+};\r
+\r
+\r
+static struct rk_sensor_reg sensor_softreset_data[]={\r
+ SensorRegVal(0x3008, 0x80),\r
+ SensorWaitMs(5),\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_check_id_data[]={\r
+ SensorRegVal(0x300a,0),\r
+ SensorRegVal(0x300b,0),\r
+ SensorEnd\r
+};\r
+/*\r
+* The following setting must been filled, if the function is turn on by CONFIG_SENSOR_xxxx\r
+*/\r
+static struct rk_sensor_reg sensor_WhiteB_Auto[]=\r
+{\r
+ {0x3406 ,0x00},\r
+ {0x5192 ,0x04},\r
+ {0x5191 ,0xf8},\r
+ {0x5193 ,0x70},\r
+ {0x5194 ,0xf0},\r
+ {0x5195 ,0xf0},\r
+ {0x518d ,0x3d},\r
+ {0x518f ,0x54},\r
+ {0x518e ,0x3d},\r
+ {0x5190 ,0x54},\r
+ {0x518b ,0xa8},\r
+ {0x518c ,0xa8},\r
+ {0x5187 ,0x18},\r
+ {0x5188 ,0x18},\r
+ {0x5189 ,0x6e},\r
+ {0x518a ,0x68},\r
+ {0x5186 ,0x1c},\r
+ {0x5181 ,0x50},\r
+ {0x5184 ,0x25},\r
+ {0x5182 ,0x11},\r
+ {0x5183 ,0x14},\r
+ {0x5184 ,0x25},\r
+ {0x5185 ,0x24},\r
+ SensorEnd\r
+};\r
+/* Cloudy Colour Temperature : 6500K - 8000K */\r
+static struct rk_sensor_reg sensor_WhiteB_Cloudy[]=\r
+{\r
+ {0x3406 ,0x1 },\r
+ {0x3400 ,0x6 },\r
+ {0x3401 ,0x48},\r
+ {0x3402 ,0x4 },\r
+ {0x3403 ,0x0 },\r
+ {0x3404 ,0x4 },\r
+ {0x3405 ,0xd3 },\r
+ SensorEnd\r
+};\r
+/* ClearDay Colour Temperature : 5000K - 6500K */\r
+static struct rk_sensor_reg sensor_WhiteB_ClearDay[]=\r
+{\r
+ {0x3406 ,0x1 },\r
+ {0x3400 ,0x6 },\r
+ {0x3401 ,0x1c},\r
+ {0x3402 ,0x4 },\r
+ {0x3403 ,0x0 },\r
+ {0x3404 ,0x4 },\r
+ {0x3405 ,0xf3},\r
+ SensorEnd\r
+};\r
+/* Office Colour Temperature : 3500K - 5000K */\r
+static struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[]=\r
+{\r
+ //Office\r
+ {0x3406 ,0x1 },\r
+ {0x3400 ,0x5 },\r
+ {0x3401 ,0x48},\r
+ {0x3402 ,0x4 },\r
+ {0x3403 ,0x0 },\r
+ {0x3404 ,0x7 },\r
+ {0x3405 ,0xcf},\r
+ SensorEnd\r
+\r
+};\r
+/* Home Colour Temperature : 2500K - 3500K */\r
+static struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[]=\r
+{\r
+ //Home\r
+ {0x3406 ,0x1 },\r
+ {0x3400 ,0x4 },\r
+ {0x3401 ,0x10},\r
+ {0x3402 ,0x4 },\r
+ {0x3403 ,0x0 },\r
+ {0x3404 ,0x8 },\r
+ {0x3405 ,0xb6},\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,\r
+ sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness0[]=\r
+{\r
+ // Brightness -2\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness1[]=\r
+{\r
+ // Brightness -1\r
+\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness2[]=\r
+{\r
+ // Brightness 0\r
+\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness3[]=\r
+{\r
+ // Brightness +1\r
+\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness4[]=\r
+{\r
+ // Brightness +2\r
+\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Brightness5[]=\r
+{\r
+ // Brightness +3\r
+\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,\r
+ sensor_Brightness4, sensor_Brightness5,NULL,\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Effect_Normal[] =\r
+{\r
+ {0x5001, 0x7f},\r
+ {0x5580, 0x00},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Effect_WandB[] =\r
+{\r
+ {0x5001, 0xff},\r
+ {0x5580, 0x18},\r
+ {0x5583, 0x80},\r
+ {0x5584, 0x80},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Effect_Sepia[] =\r
+{\r
+ {0x5001, 0xff},\r
+ {0x5580, 0x18},\r
+ {0x5583, 0x40},\r
+ {0x5584, 0xa0},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Effect_Negative[] =\r
+{\r
+ //Negative\r
+ {0x5001, 0xff},\r
+ {0x5580, 0x40},\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg sensor_Effect_Bluish[] =\r
+{\r
+ // Bluish\r
+ {0x5001, 0xff},\r
+ {0x5580, 0x18},\r
+ {0x5583, 0xa0},\r
+ {0x5584, 0x40},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Effect_Green[] =\r
+{\r
+ // Greenish\r
+ {0x5001, 0xff},\r
+ {0x5580, 0x18},\r
+ {0x5583, 0x60},\r
+ {0x5584, 0x60},\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,\r
+ sensor_Effect_Bluish, sensor_Effect_Green,NULL,\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure0[]=\r
+{\r
+ {0x3a0f, 0x10},\r
+ {0x3a10, 0x08},\r
+ {0x3a1b, 0x10},\r
+ {0x3a1e, 0x08},\r
+ {0x3a11, 0x20},\r
+ {0x3a1f, 0x10},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure1[]=\r
+{\r
+ {0x3a0f, 0x20},\r
+ {0x3a10, 0x18},\r
+ {0x3a11, 0x41},\r
+ {0x3a1b, 0x20},\r
+ {0x3a1e, 0x18},\r
+ {0x3a1f, 0x10},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure2[]=\r
+{\r
+ {0x3a0f, 0x30},\r
+ {0x3a10, 0x28},\r
+ {0x3a11, 0x61},\r
+ {0x3a1b, 0x30},\r
+ {0x3a1e, 0x28},\r
+ {0x3a1f, 0x10},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure3[]=\r
+{\r
+ {0x3a0f, 0x38},\r
+ {0x3a10, 0x30},\r
+ {0x3a11, 0x61},\r
+ {0x3a1b, 0x38},\r
+ {0x3a1e, 0x30},\r
+ {0x3a1f, 0x10},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure4[]=\r
+{\r
+ {0x3a0f, 0x40},\r
+ {0x3a10, 0x38},\r
+ {0x3a11, 0x71},\r
+ {0x3a1b, 0x40},\r
+ {0x3a1e, 0x38},\r
+ {0x3a1f, 0x10},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure5[]=\r
+{\r
+ {0x3a0f, 0x50},\r
+ {0x3a10, 0x48},\r
+ {0x3a11, 0x90},\r
+ {0x3a1b, 0x50},\r
+ {0x3a1e, 0x48},\r
+ {0x3a1f, 0x20},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Exposure6[]=\r
+{\r
+ {0x3a0f, 0x60},\r
+ {0x3a10, 0x58},\r
+ {0x3a11, 0xa0},\r
+ {0x3a1b, 0x60},\r
+ {0x3a1e, 0x58},\r
+ {0x3a1f, 0x20},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,\r
+ sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Saturation0[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Saturation1[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Saturation2[]=\r
+{\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};\r
+\r
+static struct rk_sensor_reg sensor_Contrast0[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Contrast1[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Contrast2[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Contrast3[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Contrast4[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+\r
+static struct rk_sensor_reg sensor_Contrast5[]=\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Contrast6[]=\r
+{\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,\r
+ sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,\r
+};\r
+static struct rk_sensor_reg sensor_SceneAuto[] =\r
+{\r
+ {0x3a00, 0x78},\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_SceneNight[] =\r
+{\r
+ //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk\r
+ {0x3034 ,0x1a},\r
+ {0x3035 ,0x21},\r
+ {0x3036 ,0x46},\r
+ {0x3037 ,0x13},\r
+ {0x3038 ,0x00},\r
+ {0x3039 ,0x00},\r
+ {0x3a00 ,0x7c},\r
+ {0x3a08 ,0x01},\r
+ {0x3a09 ,0x27},\r
+ {0x3a0a ,0x00},\r
+ {0x3a0b ,0xf6},\r
+ {0x3a0d ,0x04},\r
+ {0x3a0e ,0x04},\r
+ {0x3a02 ,0x0b},\r
+ {0x3a03 ,0x88},\r
+ {0x3a14 ,0x0b},\r
+ {0x3a15 ,0x88},\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};\r
+\r
+static struct rk_sensor_reg sensor_Zoom0[] =\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Zoom1[] =\r
+{\r
+ SensorEnd\r
+};\r
+\r
+static struct rk_sensor_reg sensor_Zoom2[] =\r
+{\r
+ SensorEnd\r
+};\r
+\r
+\r
+static struct rk_sensor_reg sensor_Zoom3[] =\r
+{\r
+ SensorEnd\r
+};\r
+static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};\r
+\r
+/*\r
+* User could be add v4l2_querymenu in sensor_controls by new_usr_v4l2menu\r
+*/\r
+static struct v4l2_querymenu sensor_menus[] =\r
+{\r
+};\r
+/*\r
+* User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl\r
+*/\r
+static struct sensor_v4l2ctrl_usr_s sensor_controls[] =\r
+{\r
+};\r
+\r
+//MUST define the current used format as the first item \r
+static struct rk_sensor_datafmt sensor_colour_fmts[] = {\r
+ {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG} \r
+};\r
+/*static struct soc_camera_ops sensor_ops;*/\r
+\r
+\r
+/*\r
+**********************************************************\r
+* Following is local code:\r
+* \r
+* Please codeing your program here \r
+**********************************************************\r
+*/\r
+ static int sensor_parameter_record(struct i2c_client *client)\r
+ {\r
+ u8 ret_l,ret_m,ret_h;\r
+ int tp_l,tp_m,tp_h;\r
+ struct generic_sensor*sensor = to_generic_sensor(client);\r
+ struct specific_sensor *spsensor = to_specific_sensor(sensor);\r
+ sensor_read(client,0x3a00, &ret_l);\r
+ sensor_write(client,0x3a00, ret_l&0xfb);\r
+ \r
+ sensor_write(client,0x3503,0x07); //stop AE/AG\r
+ sensor_read(client,0x3406, &ret_l);\r
+ sensor_write(client,0x3406, ret_l|0x01);\r
+ \r
+ sensor_read(client,0x3500,&ret_h);\r
+ sensor_read(client,0x3501, &ret_m);\r
+ sensor_read(client,0x3502, &ret_l);\r
+ tp_l = ret_l;\r
+ tp_m = ret_m;\r
+ tp_h = ret_h;\r
+ spsensor->parameter.preview_exposure = ((tp_h<<12) & 0xF000) | ((tp_m<<4) & 0x0FF0) | ((tp_l>>4) & 0x0F);\r
+ \r
+ //Read back AGC Gain for preview\r
+ sensor_read(client,0x350b, &ret_l);\r
+ spsensor->parameter.preview_gain = ret_l;\r
+ \r
+ SENSOR_DG(" %s Read 0x350b=0x%02x PreviewExposure:%d 0x3500=0x%02x 0x3501=0x%02x 0x3502=0x%02x \n",\r
+ SENSOR_NAME_STRING(), tp_l,spsensor->parameter.preview_exposure,tp_h, tp_m, tp_l);\r
+ return 0;\r
+ }\r
+#define OV5640_FULL_PERIOD_PIXEL_NUMS_HTS (2844) \r
+#define OV5640_FULL_PERIOD_LINE_NUMS_VTS (1968) \r
+#define OV5640_PV_PERIOD_PIXEL_NUMS_HTS (1896) \r
+#define OV5640_PV_PERIOD_LINE_NUMS_VTS (984) \r
+ static int sensor_ae_transfer(struct i2c_client *client)\r
+ {\r
+ u8 ExposureLow;\r
+ u8 ExposureMid;\r
+ u8 ExposureHigh;\r
+ u16 ulCapture_Exposure;\r
+ u16 Preview_Maxlines;\r
+ u8 Gain;\r
+ u16 OV5640_g_iExtra_ExpLines;\r
+ struct generic_sensor*sensor = to_generic_sensor(client);\r
+ struct specific_sensor *spsensor = to_specific_sensor(sensor);\r
+ //Preview_Maxlines = sensor->parameter.preview_line_width;\r
+ Preview_Maxlines = spsensor->parameter.preview_maxlines;\r
+ Gain = spsensor->parameter.preview_gain;\r
+ \r
+ \r
+ ulCapture_Exposure = (spsensor->parameter.preview_exposure*OV5640_PV_PERIOD_PIXEL_NUMS_HTS)/OV5640_FULL_PERIOD_PIXEL_NUMS_HTS;\r
+ \r
+ SENSOR_DG("cap shutter calutaed = %d, 0x%x\n", ulCapture_Exposure,ulCapture_Exposure);\r
+ \r
+ // write the gain and exposure to 0x350* registers \r
+ sensor_write(client,0x350b, Gain); \r
+ \r
+ if (ulCapture_Exposure <= 1940) {\r
+ OV5640_g_iExtra_ExpLines = 0;\r
+ }else {\r
+ OV5640_g_iExtra_ExpLines = ulCapture_Exposure - 1940;\r
+ }\r
+ SENSOR_DG("Set Extra-line = %d, iExp = %d \n", OV5640_g_iExtra_ExpLines, ulCapture_Exposure);\r
+ \r
+ ExposureLow = (ulCapture_Exposure<<4)&0xff;\r
+ ExposureMid = (ulCapture_Exposure>>4)&0xff;\r
+ ExposureHigh = (ulCapture_Exposure>>12);\r
+ \r
+ sensor_write(client,0x350c, (OV5640_g_iExtra_ExpLines&0xff00)>>8);\r
+ sensor_write(client,0x350d, OV5640_g_iExtra_ExpLines&0xff);\r
+ sensor_write(client,0x3502, ExposureLow);\r
+ sensor_write(client,0x3501, ExposureMid);\r
+ sensor_write(client,0x3500, ExposureHigh);\r
+ \r
+ //SENSOR_DG(" %s Write 0x350b=0x%02x 0x350c=0x%2x 0x350d=0x%2x 0x3502=0x%02x 0x3501=0x%02x 0x3500=0x%02x\n",SENSOR_NAME_STRING(), Gain, ExposureLow, ExposureMid, ExposureHigh);\r
+ mdelay(100);\r
+ return 0;\r
+ }\r
+/*\r
+**********************************************************\r
+* Following is callback\r
+* If necessary, you could coding these callback\r
+**********************************************************\r
+*/\r
+/*\r
+* the function is called in open sensor \r
+*/\r
+static int sensor_activate_cb(struct i2c_client *client)\r
+{\r
+ SENSOR_DG("%s",__FUNCTION__);\r
+ return 0;\r
+}\r
+/*\r
+* the function is called in close sensor\r
+*/\r
+static int sensor_deactivate_cb(struct i2c_client *client)\r
+{\r
+ struct generic_sensor *sensor = to_generic_sensor(client);\r
+ \r
+ SENSOR_DG("%s",__FUNCTION__);\r
+ if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {\r
+ sensor_write(client, 0x3017, 0x00); // FREX,VSYNC,HREF,PCLK,D9-D6\r
+ sensor_write(client, 0x3018, 0x03); // D5-D0\r
+ sensor_write(client,0x3019,0x00); // STROBE,SDA\r
+ }\r
+ \r
+ return 0;\r
+}\r
+/*\r
+* the function is called before sensor register setting in VIDIOC_S_FMT \r
+*/\r
+static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)\r
+{\r
+ //struct generic_sensor*sensor = to_generic_sensor(client);\r
+ \r
+ if (capture) {\r
+ sensor_parameter_record(client);\r
+ }\r
+ return 0;\r
+}\r
+static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)\r
+{\r
+ \r
+ return 0;\r
+}\r
+static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)\r
+{\r
+ return 0;\r
+}\r
+\r
+/*\r
+* the function is called after sensor register setting finished in VIDIOC_S_FMT \r
+*/\r
+static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)\r
+{\r
+ //struct generic_sensor*sensor = to_generic_sensor(client);\r
+ if (capture) {\r
+ sensor_ae_transfer(client);\r
+ }\r
+ msleep(400);\r
+ return 0;\r
+}\r
+static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)\r
+{\r
+ return 0;\r
+}\r
+\r
+static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)\r
+{\r
+ //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
+ \r
+ if (pm_msg.event == PM_EVENT_SUSPEND) {\r
+ SENSOR_DG("Suspend");\r
+ \r
+ } else {\r
+ SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);\r
+ return -EINVAL;\r
+ }\r
+ return 0;\r
+}\r
+\r
+static int sensor_resume(struct soc_camera_device *icd)\r
+{\r
+\r
+ SENSOR_DG("Resume");\r
+\r
+ return 0;\r
+\r
+}\r
+static int sensor_mirror_cb (struct i2c_client *client, int mirror)\r
+{\r
+ \r
+ SENSOR_DG("mirror: %d",mirror);\r
+\r
+ return 0; \r
+}\r
+/*\r
+* the function is v4l2 control V4L2_CID_HFLIP callback \r
+*/\r
+static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, \r
+ struct v4l2_ext_control *ext_ctrl)\r
+{\r
+ struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
+\r
+ if (sensor_mirror_cb(client,ext_ctrl->value) != 0)\r
+ SENSOR_TR("sensor_mirror failed, value:0x%x",ext_ctrl->value);\r
+ \r
+ SENSOR_DG("sensor_mirror success, value:0x%x",ext_ctrl->value);\r
+ return 0;\r
+}\r
+\r
+static int sensor_flip_cb(struct i2c_client *client, int flip)\r
+{\r
+ SENSOR_DG("flip: %d",flip);\r
+\r
+ return 0; \r
+}\r
+/*\r
+* the function is v4l2 control V4L2_CID_VFLIP callback \r
+*/\r
+static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, \r
+ struct v4l2_ext_control *ext_ctrl)\r
+{\r
+ struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
+\r
+ if (sensor_flip_cb(client,ext_ctrl->value) != 0)\r
+ SENSOR_TR("sensor_flip failed, value:0x%x",ext_ctrl->value);\r
+ \r
+ SENSOR_DG("sensor_flip success, value:0x%x",ext_ctrl->value);\r
+ return 0;\r
+}\r
+/*\r
+* the functions are focus callbacks\r
+*/\r
+/*\r
+for 5640 focus\r
+*/\r
+struct af_cmdinfo\r
+{\r
+ char cmd_tag;\r
+ char cmd_para[4];\r
+ char validate_bit;\r
+};\r
+static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)\r
+{\r
+ int i;\r
+ char read_tag=0xff,cnt;\r
+\r
+ if (cmdinfo) {\r
+ for (i=0; i<4; i++) {\r
+ if (cmdinfo->validate_bit & (1<<i)) {\r
+ if (sensor_write(client, CMD_PARA0_Reg+i, cmdinfo->cmd_para[i])) {\r
+ SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);\r
+ goto sensor_af_cmdset_err;\r
+ }\r
+ SENSOR_DG("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);\r
+ }\r
+ }\r
+ \r
+ if (cmdinfo->validate_bit & 0x80) {\r
+ if (sensor_write(client, CMD_ACK_Reg, cmdinfo->cmd_tag)) {\r
+ SENSOR_TR("%s write CMD_ACK_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);\r
+ goto sensor_af_cmdset_err;\r
+ }\r
+ SENSOR_DG("%s write CMD_ACK_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);\r
+ }\r
+ \r
+ } else {\r
+ if (sensor_write(client, CMD_ACK_Reg, 0x01)) {\r
+ SENSOR_TR("%s write CMD_ACK_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);\r
+ goto sensor_af_cmdset_err;\r
+ }\r
+ SENSOR_DG("%s write CMD_ACK_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);\r
+ }\r
+\r
+ if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {\r
+ SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);\r
+ goto sensor_af_cmdset_err;\r
+ }\r
+\r
+ cnt = 0;\r
+ do\r
+ {\r
+ msleep(5);\r
+ if (sensor_read(client,CMD_ACK_Reg,&read_tag)){\r
+ SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);\r
+ break;\r
+ }\r
+ } while((read_tag != 0x00)&& (cnt++<100));\r
+\r
+ SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);\r
+ return 0;\r
+sensor_af_cmdset_err:\r
+ return -1;\r
+}\r
+static int sensor_af_idlechk(struct i2c_client *client)\r
+{\r
+ int ret = 0;\r
+ char state; \r
+ struct af_cmdinfo cmdinfo;\r
+ \r
+ SENSOR_DG("%s , %d\n",__FUNCTION__,__LINE__);\r
+ \r
+ cmdinfo.cmd_tag = 0x01;\r
+ cmdinfo.validate_bit = 0x80;\r
+ ret = sensor_af_cmdset(client, ReturnIdle_Cmd, &cmdinfo);\r
+ if(0 != ret) {\r
+ SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);\r
+ ret = -1;\r
+ goto sensor_af_idlechk_end;\r
+ }\r
+ \r
+\r
+ do{\r
+ ret = sensor_read(client, CMD_ACK_Reg, &state);\r
+ if (ret != 0){\r
+ SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);\r
+ ret = -1;\r
+ goto sensor_af_idlechk_end;\r
+ }\r
+ }while(0x00 != state);\r
+\r
+ SENSOR_DG("%s , %d\n",__FUNCTION__,__LINE__);\r
+sensor_af_idlechk_end:\r
+ return ret;\r
+}\r
+/*for 5640 focus end*/\r
+//\r
+static int sensor_focus_af_single_usr_cb(struct i2c_client *client);\r
+\r
+static int sensor_focus_init_usr_cb(struct i2c_client *client)\r
+{\r
+ int ret = 0, cnt;\r
+ char state;\r
+\r
+ msleep(1);\r
+ ret = sensor_write_array(client, sensor_af_firmware);\r
+ if (ret != 0) {\r
+ SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());\r
+ ret = -1;\r
+ goto sensor_af_init_end;\r
+ }\r
+\r
+ cnt = 0;\r
+ do\r
+ {\r
+ msleep(1);\r
+ if (cnt++ > 500)\r
+ break;\r
+ ret = sensor_read(client, STA_FOCUS_Reg, &state);\r
+ if (ret != 0){\r
+ SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);\r
+ ret = -1;\r
+ goto sensor_af_init_end;\r
+ }\r
+ } while (state != S_IDLE);\r
+\r
+ if (state != S_IDLE) {\r
+ SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);\r
+ ret = -1;\r
+ goto sensor_af_init_end;\r
+ }\r
+sensor_af_init_end:\r
+ SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);\r
+ return ret;\r
+}\r
+\r
+static int sensor_focus_af_single_usr_cb(struct i2c_client *client) \r
+{\r
+ int ret = 0;\r
+ char state,cnt;\r
+ struct af_cmdinfo cmdinfo;\r
+ //char s_zone[5],i;\r
+ cmdinfo.cmd_tag = 0x01;\r
+ cmdinfo.validate_bit = 0x80;\r
+ ret = sensor_af_cmdset(client, SingleFocus_Cmd, &cmdinfo);\r
+ if(0 != ret) {\r
+ SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());\r
+ ret = -1;\r
+ goto sensor_af_single_end;\r
+ }\r
+ \r
+ cnt = 0;\r
+ do\r
+ {\r
+ if (cnt != 0) {\r
+ msleep(1);\r
+ }\r
+ cnt++;\r
+ ret = sensor_read(client, STA_FOCUS_Reg, &state);\r
+ if (ret != 0){\r
+ SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);\r
+ ret = -1;\r
+ goto sensor_af_single_end;\r
+ }\r
+ }while((state == S_FOCUSING) && (cnt<100));\r
+\r
+ if (state != S_FOCUSED) {\r
+ SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);\r
+ ret = -1;\r
+ goto sensor_af_single_end;\r
+ } else {\r
+ SENSOR_DG("%s[%d] single focus mode set success!\n",SENSOR_NAME_STRING(),__LINE__); \r
+ }\r
+sensor_af_single_end:\r
+ return ret;\r
+}\r
+\r
+static int sensor_focus_af_near_usr_cb(struct i2c_client *client)\r
+{\r
+ return 0;\r
+}\r
+\r
+static int sensor_focus_af_far_usr_cb(struct i2c_client *client)\r
+{\r
+ \r
+ return 0;\r
+}\r
+\r
+static int sensor_focus_af_specialpos_usr_cb(struct i2c_client *client,int pos)\r
+{\r
+ struct af_cmdinfo cmdinfo;\r
+ sensor_af_idlechk(client);\r
+ return 0;\r
+ cmdinfo.cmd_tag = StepFocus_Spec_Tag;\r
+ cmdinfo.cmd_para[0] = pos;\r
+ cmdinfo.validate_bit = 0x81;\r
+ return sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);\r
+}\r
+\r
+static int sensor_focus_af_const_usr_cb(struct i2c_client *client)\r
+{\r
+ int ret = 0;\r
+ struct af_cmdinfo cmdinfo;\r
+ cmdinfo.cmd_tag = 0x01;\r
+ cmdinfo.cmd_para[0] = 0x00;\r
+ cmdinfo.validate_bit = 0x81;\r
+ sensor_af_idlechk(client);\r
+ if (sensor_af_cmdset(client, ConstFocus_Cmd, &cmdinfo)) {\r
+ SENSOR_TR("%s[%d] const focus mode set error!\n",SENSOR_NAME_STRING(),__LINE__);\r
+ ret = -1;\r
+ goto sensor_af_const_end;\r
+ } else {\r
+ SENSOR_DG("%s[%d] const focus mode set success!\n",SENSOR_NAME_STRING(),__LINE__); \r
+ }\r
+sensor_af_const_end:\r
+ return ret;\r
+}\r
+static int sensor_focus_af_const_pause_usr_cb(struct i2c_client *client)\r
+{\r
+ return 0;\r
+}\r
+static int sensor_focus_af_close_usr_cb(struct i2c_client *client)\r
+{\r
+ int ret = 0; \r
+ sensor_af_idlechk(client);\r
+ if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {\r
+ SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());\r
+ ret = -1;\r
+ goto sensor_af_pause_end;\r
+ }\r
+sensor_af_pause_end:\r
+ return ret;\r
+}\r
+\r
+static int sensor_focus_af_zoneupdate_usr_cb(struct i2c_client *client, int *zone_tm_pos)\r
+{\r
+ int ret = 0;\r
+ struct af_cmdinfo cmdinfo;\r
+ //int zone_tm_pos[4];\r
+ int zone_center_pos[2];\r
+ //struct generic_sensor*sensor = to_generic_sensor(client); \r
+ \r
+ if (zone_tm_pos) {\r
+ zone_tm_pos[0] += 1000;\r
+ zone_tm_pos[1] += 1000;\r
+ zone_tm_pos[2]+= 1000;\r
+ zone_tm_pos[3] += 1000;\r
+ zone_center_pos[0] = ((zone_tm_pos[0] + zone_tm_pos[2])>>1)*80/2000;\r
+ zone_center_pos[1] = ((zone_tm_pos[1] + zone_tm_pos[3])>>1)*60/2000;\r
+ } else {\r
+#if CONFIG_SENSOR_FocusCenterInCapture\r
+ zone_center_pos[0] = 32;\r
+ zone_center_pos[1] = 24;\r
+#else\r
+ zone_center_pos[0] = -1;\r
+ zone_center_pos[1] = -1;\r
+#endif\r
+ }\r
+ if ((zone_center_pos[0] >=0) && (zone_center_pos[1]>=0)){\r
+ cmdinfo.cmd_tag = 0x01;\r
+ cmdinfo.validate_bit = 0x83;\r
+ if (zone_center_pos[0]<=8)\r
+ cmdinfo.cmd_para[0] = 0;\r
+ else if ((zone_center_pos[0]>8) && (zone_center_pos[0]<72))\r
+ cmdinfo.cmd_para[0] = zone_center_pos[0]-8;\r
+ else \r
+ cmdinfo.cmd_para[0] = 72; \r
+ \r
+ if (zone_center_pos[1]<=6)\r
+ cmdinfo.cmd_para[1] = 0;\r
+ else if ((zone_center_pos[1]>6) && (zone_center_pos[1]<54))\r
+ cmdinfo.cmd_para[1] = zone_center_pos[1]-6;\r
+ else \r
+ cmdinfo.cmd_para[1] = 54;\r
+ \r
+ ret = sensor_af_cmdset(client, TouchZoneConfig_Cmd, &cmdinfo);\r
+ if(0 != ret) {\r
+ SENSOR_TR("%s touch zone config error!\n",SENSOR_NAME_STRING());\r
+ ret = -1;\r
+ goto sensor_af_zone_end;\r
+ } \r
+ }\r
+sensor_af_zone_end:\r
+ return ret;\r
+}\r
+\r
+/*\r
+face defect call back\r
+*/\r
+static int sensor_face_detect_usr_cb(struct i2c_client *client,int on){\r
+ return 0;\r
+}\r
+\r
+/*\r
+* The function can been run in sensor_init_parametres which run in sensor_probe, so user can do some\r
+* initialization in the function. \r
+*/\r
+static void sensor_init_parameters_user(struct specific_sensor* spsensor,struct soc_camera_device *icd)\r
+{\r
+ return;\r
+}\r
+\r
+/*\r
+* :::::WARNING:::::\r
+* It is not allowed to modify the following code\r
+*/\r
+\r
+sensor_init_parameters_default_code();\r
+\r
+sensor_v4l2_struct_initialization();\r
+\r
+sensor_probe_default_code();\r
+\r
+sensor_remove_default_code();\r
+\r
+sensor_driver_default_module_code();\r
+\r
+ \r
+\r