upate:更新双目sensor驱动
This commit is contained in:
161
lichee/linux-4.9/drivers/media/platform/sunxi-vin/modules/sensor/sc202cs_mipi.c
Normal file → Executable file
161
lichee/linux-4.9/drivers/media/platform/sunxi-vin/modules/sensor/sc202cs_mipi.c
Normal file → Executable file
@@ -74,6 +74,10 @@ MODULE_LICENSE("GPL");
|
||||
#define GAIN_MAX 0xF8
|
||||
#define GAIN_STEP 1
|
||||
#define GAIN_DEFAULT 20
|
||||
#define GAIN_STEP_BASE 128 //mean gain min step is 1/64gain
|
||||
#define DIG_GAIN 0x3e06
|
||||
#define DIG_FINE_GAIN 0x3e07
|
||||
#define ANA_GAIN 0x3e09
|
||||
|
||||
#define MCLK (24*1000*1000)
|
||||
|
||||
@@ -331,32 +335,21 @@ static int sensor_s_exp(struct v4l2_subdev *sd, unsigned int exp_val)
|
||||
{
|
||||
data_type explow, expmid, exphigh;
|
||||
struct sensor_info *info = to_state(sd);
|
||||
/*struct vin_md *vind = dev_get_drvdata(sd->v4l2_dev->dev);*/
|
||||
/*struct vin_core *vinc = vind->vinc[0];*/
|
||||
|
||||
if (exp_val > EXPOSURE_MAX << 4)
|
||||
exp_val = EXPOSURE_MAX << 4;
|
||||
|
||||
if (exp_val < 16)
|
||||
exp_val = 16;
|
||||
|
||||
if (exp_val == info->exp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (SC202CS == 1)
|
||||
exphigh = (unsigned char)(0xf & (exp_val >> 12)); // upper 4 bits
|
||||
expmid = (unsigned char)(0xff & (exp_val >> 4)); // middle 7 bits
|
||||
explow = (unsigned char)(0xf0 & (exp_val << 4)); // lower 4 bits
|
||||
sensor_write(sd, 0x3e02, explow); //[7:4]
|
||||
sensor_write(sd, 0x3e01, expmid); //[7:0]
|
||||
sensor_write(sd, 0x3e00, exphigh); //[3:0]
|
||||
#else
|
||||
exphigh = (unsigned char)(exp_val >> 8);
|
||||
explow = (unsigned char)(exp_val & 0xFF);
|
||||
expmid = 0;
|
||||
sensor_write(sd, 0x3e01, exphigh);
|
||||
exphigh = (unsigned char) (0x0f & (exp_val>>16));
|
||||
expmid = (unsigned char) (0xff & (exp_val>>8));
|
||||
explow = (unsigned char) (0xf0 & (exp_val<<0));
|
||||
sensor_write(sd, 0x3e02, explow);
|
||||
sensor_write(sd, 0x3e01, expmid);
|
||||
sensor_write(sd, 0x3e00, exphigh);
|
||||
|
||||
#else
|
||||
exphigh = (unsigned char) (0x0f & (exp_val>>16));
|
||||
expmid = (unsigned char) (0xff & (exp_val>>8));
|
||||
explow = (unsigned char) (0xf0 & (exp_val<<0));
|
||||
sensor_write(sd, 0x3e02, explow);
|
||||
sensor_write(sd, 0x3e01, expmid);
|
||||
sensor_write(sd, 0x3e00, exphigh);
|
||||
#endif
|
||||
|
||||
sensor_dbg("%s():%d, exp_val = %d\n", __func__, __LINE__, exp_val);
|
||||
@@ -373,56 +366,96 @@ static int sensor_g_gain(struct v4l2_subdev *sd, __s32 *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned char analog_Gain_Reg[] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f};
|
||||
|
||||
static int setSensorGain(struct v4l2_subdev *sd, int gain)
|
||||
{
|
||||
int ana_gain = gain / GAIN_STEP_BASE;
|
||||
int dig_Gain;
|
||||
int gain_flag = 1;
|
||||
|
||||
if (ana_gain >= 16) {
|
||||
gain_flag = 4;
|
||||
} else if (ana_gain >= 8) {
|
||||
gain_flag = 3;
|
||||
} else if (ana_gain >= 4) {
|
||||
gain_flag = 2;
|
||||
} else if (ana_gain >= 2) {
|
||||
gain_flag = 1;
|
||||
} else {
|
||||
gain_flag = 0;
|
||||
}
|
||||
|
||||
sensor_write(sd, ANA_GAIN, analog_Gain_Reg[gain_flag]);
|
||||
dig_Gain = gain >> gain_flag; //dig_Gain min mean 1/128gain
|
||||
if (dig_Gain < 2 * GAIN_STEP_BASE) {
|
||||
//step1/128
|
||||
sensor_write(sd, DIG_GAIN, 0x00);
|
||||
sensor_write(sd, DIG_FINE_GAIN, dig_Gain - GAIN_STEP_BASE + 0x80);
|
||||
//sensor_print("sensor set analog_gain:0x%02x, dig_gain:0x%02x, dig_fine_gain:0x%02x", analog_Gain_Reg[gain_flag], 0x00, dig_Gain - 128 + 0x80);
|
||||
} else if (dig_Gain < 4 * GAIN_STEP_BASE) {
|
||||
//step1/64
|
||||
sensor_write(sd, DIG_GAIN, 0x01);
|
||||
sensor_write(sd, DIG_FINE_GAIN, (dig_Gain - GAIN_STEP_BASE * 2) / 2 + 0x80);
|
||||
//sensor_print("sensor set analog_gain:0x%02x, dig_gain:0x%02x, dig_fine_gain:0x%02x", analog_Gain_Reg[gain_flag], 0x01, (dig_Gain - 128 * 2) / 2 + 0x80);
|
||||
} else {
|
||||
sensor_write(sd, DIG_GAIN, 0x01);
|
||||
sensor_write(sd, DIG_FINE_GAIN, 0xfc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_s_gain(struct v4l2_subdev *sd, int gain_val)
|
||||
{
|
||||
struct sensor_info *info = to_state(sd);
|
||||
//sensor_dbg("%s():%d. info:%p, gain_val:%d\n", __func__, __LINE__, info, gain_val);
|
||||
if (gain_val == info->gain) {
|
||||
return 0;
|
||||
}
|
||||
sensor_dbg("%s():%d. info:%p, gain_val:%d\n", __func__, __LINE__, info, gain_val);
|
||||
info->gain = gain_val;
|
||||
int tem_gain_val;
|
||||
|
||||
return 0;
|
||||
|
||||
// if (gain_val < 1 * 16)
|
||||
// gain_val = 16;
|
||||
if (gain_val > 16 * 16 - 1)
|
||||
gain_val = 16 * 16 - 1;
|
||||
|
||||
if (gain_val < 32) {
|
||||
sensor_write(sd, 0x3314, 0x1e);
|
||||
sensor_write(sd, 0x3317, 0x10);
|
||||
//gain min step is 1/128gain
|
||||
tem_gain_val = gain_val * GAIN_STEP_BASE;
|
||||
if ((tem_gain_val - tem_gain_val / 16 * 16) > 0) {
|
||||
tem_gain_val = tem_gain_val / 16 + 1;
|
||||
} else {
|
||||
sensor_write(sd, 0x3314, 0x4f);
|
||||
sensor_write(sd, 0x3317, 0x0f);
|
||||
}
|
||||
tem_gain_val = tem_gain_val / 16;
|
||||
}
|
||||
|
||||
if (gain_val < 32) {
|
||||
sensor_write(sd, 0x3e08, 0x03);
|
||||
sensor_write(sd, 0x3e09, gain_val);
|
||||
} else if (gain_val >= 32 && gain_val < 64) {
|
||||
sensor_write(sd, 0x3e08, 0x07);
|
||||
sensor_write(sd, 0x3e09, gain_val >> 1);
|
||||
} else if (gain_val >= 64 && gain_val < 128) {
|
||||
sensor_write(sd, 0x3e08, 0x0f);
|
||||
sensor_write(sd, 0x3e09, gain_val >> 2);
|
||||
} else if (gain_val >= 128) {
|
||||
sensor_write(sd, 0x3e08, 0x1f);
|
||||
sensor_write(sd, 0x3e09, gain_val >> 3);
|
||||
}
|
||||
sensor_dbg("%s(), L:%d, gain_val:%d, tem_gain_val:%d, info->gain:%d\n",
|
||||
__func__, __LINE__, gain_val, tem_gain_val, info->gain);
|
||||
|
||||
sensor_dbg("drv sensor_s_gain(%d)\n", gain_val);
|
||||
setSensorGain(sd, tem_gain_val);
|
||||
info->gain = gain_val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sc202cs_sensor_vts;
|
||||
static int sensor_s_exp_gain(struct v4l2_subdev *sd,
|
||||
struct sensor_exp_gain *exp_gain)
|
||||
{
|
||||
struct sensor_info *info = to_state(sd);
|
||||
struct i2c_client *client = v4l2_get_subdevdata(sd);
|
||||
int shutter = 0, frame_length = 0;
|
||||
|
||||
sensor_dbg("(%d, %d)\n", exp_gain->exp_val, exp_gain->gain_val);
|
||||
|
||||
|
||||
shutter = exp_gain->exp_val >> 4;
|
||||
if (shutter > sc202cs_sensor_vts - 8)
|
||||
frame_length = shutter + 8;
|
||||
else
|
||||
frame_length = sc202cs_sensor_vts;
|
||||
|
||||
|
||||
sensor_dbg("shutter = %d, frame_length = %d\n", shutter, frame_length);
|
||||
sensor_write(sd, 0x320e, (frame_length >> 8));
|
||||
sensor_write(sd, 0x320f, (frame_length & 0xff));
|
||||
|
||||
|
||||
sensor_s_exp(sd, exp_gain->exp_val);
|
||||
sensor_s_gain(sd, exp_gain->gain_val);
|
||||
info->exp = exp_gain->exp_val;
|
||||
info->gain = exp_gain->gain_val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -466,7 +499,7 @@ static int sensor_s_hflip(struct v4l2_subdev *sd, int enable)
|
||||
|
||||
static int sensor_get_fmt_mbus_core(struct v4l2_subdev *sd, int *code)
|
||||
{
|
||||
*code = MEDIA_BUS_FMT_SRGGB10_1X10; // gc2053 support change the rgb format by itself
|
||||
*code = MEDIA_BUS_FMT_SBGGR10_1X10;//MEDIA_BUS_FMT_SRGGB10_1X10; // gc2053 support change the rgb format by itself
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -727,7 +760,7 @@ static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
|
||||
static struct sensor_format_struct sensor_formats[] = {
|
||||
{
|
||||
.desc = "Raw RGB Bayer",
|
||||
.mbus_code = MEDIA_BUS_FMT_SRGGB10_1X10, /*.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, */
|
||||
.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,//MEDIA_BUS_FMT_SRGGB10_1X10, /*.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, */
|
||||
.regs = sensor_fmt_raw,
|
||||
.regs_size = ARRAY_SIZE(sensor_fmt_raw),
|
||||
.bpp = 1
|
||||
@@ -746,16 +779,16 @@ static struct sensor_win_size sensor_win_sizes[] = {
|
||||
.height = 1200, //
|
||||
.hoffset = 0,
|
||||
.voffset = 0,
|
||||
.hts = 2200,
|
||||
.hts = 1920,
|
||||
.vts = 1250,
|
||||
.pclk = 74250000,
|
||||
.pclk = 72000000,
|
||||
.mipi_bps = 371250000,
|
||||
.fps_fixed = 30,
|
||||
.bin_factor = 1,
|
||||
.intg_min = 1 << 4,
|
||||
.intg_max = (1250 - 8) << 4,
|
||||
.gain_min = 1 << 4,
|
||||
.gain_max = 128 << 4,
|
||||
.gain_max = 64 << 4,
|
||||
.regs = sensor_normal_regs,
|
||||
.regs_size = ARRAY_SIZE(sensor_normal_regs),
|
||||
.set_size = NULL,
|
||||
@@ -885,7 +918,7 @@ static int sensor_reg_init(struct sensor_info *info)
|
||||
|
||||
info->width = wsize->width;
|
||||
info->height = wsize->height;
|
||||
|
||||
sc202cs_sensor_vts = wsize->vts;
|
||||
exp_gain.exp_val = EXPOSURE_DEFAULT;
|
||||
exp_gain.gain_val = GAIN_DEFAULT;
|
||||
sensor_s_exp_gain(sd, &exp_gain);
|
||||
@@ -1037,6 +1070,8 @@ static int sensor_probe(struct i2c_client *client,
|
||||
//info->combo_mode = CMB_PHYA_OFFSET2 | MIPI_NORMAL_MODE;
|
||||
info->stream_seq = MIPI_BEFORE_SENSOR;
|
||||
info->af_first_flag = 1;
|
||||
//info->time_hs = 0x11;
|
||||
info->deskew = 0x02;
|
||||
info->exp = 0;
|
||||
info->gain = 0;
|
||||
|
||||
|
||||
@@ -88,9 +88,10 @@ CONFIG_RT_USING_WORKQUEUE=y
|
||||
CONFIG_RT_USING_MEMPOOL=y
|
||||
CONFIG_RT_USING_MEMHEAP=y
|
||||
# CONFIG_RT_USING_NOHEAP is not set
|
||||
# CONFIG_RT_USING_SMALL_MEM is not set
|
||||
CONFIG_RT_USING_SLAB=y
|
||||
CONFIG_RT_USING_SMALL_MEM=y
|
||||
# CONFIG_RT_USING_SLAB is not set
|
||||
# CONFIG_RT_USING_MEMHEAP_AS_HEAP is not set
|
||||
# CONFIG_RT_USING_MEMTRACE is not set
|
||||
CONFIG_RT_USING_HEAP=y
|
||||
|
||||
#
|
||||
@@ -219,7 +220,7 @@ CONFIG_ISP_NUMBER=1
|
||||
# CONFIG_SENSOR_GC1054_MIPI is not set
|
||||
# CONFIG_SENSOR_GC1084_MIPI is not set
|
||||
# CONFIG_SENSOR_GC2053_MIPI is not set
|
||||
CONFIG_SENSOR_GC2083_MIPI=y
|
||||
# CONFIG_SENSOR_GC2083_MIPI is not set
|
||||
# CONFIG_SENSOR_GC4663_MIPI is not set
|
||||
# CONFIG_SENSOR_SC2355_MIPI is not set
|
||||
# CONFIG_SENSOR_SC2356_MIPI is not set
|
||||
@@ -242,6 +243,7 @@ CONFIG_SENSOR_GC2083_MIPI=y
|
||||
# CONFIG_SENSOR_F37P_DVP is not set
|
||||
# CONFIG_SENSOR_F37P_MIPI is not set
|
||||
# CONFIG_SENSOR_OV02B10_MIPI is not set
|
||||
CONFIG_SENSOR_SC202CS_MIPI=y
|
||||
|
||||
#
|
||||
# Osal Setup
|
||||
@@ -285,7 +287,7 @@ CONFIG_RPMSG_NOTIFY=y
|
||||
# CONFIG_RPMSG_SPEEDTEST is not set
|
||||
CONFIG_AMP_SHARE_IRQ=y
|
||||
CONFIG_RPMSG_CLIENT=y
|
||||
# CONFIG_RPMSG_CLIENT_TEST is not set
|
||||
CONFIG_RPMSG_CLIENT_TEST=y
|
||||
CONFIG_RPMSG_CLIENT_QUEUE_SIZE=16
|
||||
# CONFIG_RPMSG_CLIENT_DEBUG is not set
|
||||
CONFIG_RPMSG_HEARBEAT=y
|
||||
@@ -426,7 +428,7 @@ CONFIG_MODVERSIONS=y
|
||||
# CONFIG_SHOW_FULL_VERSION is not set
|
||||
CONFIG_CROSS_COMPILE="riscv64-unknown-elf-"
|
||||
# CONFIG_INIT_CARD_PRODUCT is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL=1
|
||||
CONFIG_LOG_DEFAULT_LEVEL=4
|
||||
# CONFIG_CC_STACKPROTECTOR_STRONG is not set
|
||||
# CONFIG_LOG_RELEASE is not set
|
||||
# CONFIG_BOOTUP_TURBO is not set
|
||||
@@ -435,7 +437,7 @@ CONFIG_LOG_DEFAULT_LEVEL=1
|
||||
CONFIG_DYNAMIC_LOG_LEVEL_SUPPORT=y
|
||||
CONFIG_LOG_LEVEL_STORAGE_NONE=y
|
||||
# CONFIG_LOG_LEVEL_STORAGE_RTC is not set
|
||||
CONFIG_DYNAMIC_LOG_DEFAULT_LEVEL=2
|
||||
CONFIG_DYNAMIC_LOG_DEFAULT_LEVEL=4
|
||||
# CONFIG_FRAME_POINTER is not set
|
||||
CONFIG_FRAME_WARN=8192
|
||||
CONFIG_UART_CLI_USE_NONE=y
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
;----------------------------------------------------------------------------------
|
||||
;i2c configuration
|
||||
;----------------------------------------------------------------------------------
|
||||
;[twi0]
|
||||
;twi0_scl = port:PA16<4><1><default><default>
|
||||
;twi0_sda = port:PA17<4><1><default><default>
|
||||
[twi0]
|
||||
twi0_scl = port:PE4<8><1><default><default>
|
||||
twi0_sda = port:PE5<8><1><default><default>
|
||||
|
||||
[twi1]
|
||||
twi1_scl = port:PA06<4><1><default><default>
|
||||
twi1_sda = port:PA07<4><1><default><default>
|
||||
;twi1_scl = port:PA06<4><1><default><default>
|
||||
;twi1_sda = port:PA07<4><1><default><default>
|
||||
|
||||
;[twi2]
|
||||
;twi2_scl = port:PH05<4><1><default><default>
|
||||
@@ -47,7 +47,6 @@ uart_rx = port:PE01<7><1><default><default>
|
||||
|
||||
[sensor0]
|
||||
used0 = 1
|
||||
reset0 = port:PA11<1><1><default><default>
|
||||
pwdn0 = port:PA09<1><1><default><default>
|
||||
mclk0 = port:PA10<4><1><default><default>
|
||||
|
||||
reset0 = port:PE10<1><1><default><default>
|
||||
pwdn0 = port:PF0<1><1><default><default>
|
||||
mclk0 = port:PE13<5><1><default><default>
|
||||
|
||||
@@ -16,17 +16,26 @@ int app_entry(void *param)
|
||||
printf("csi init fail!\n");
|
||||
}
|
||||
#if 1
|
||||
rpmsg_notify("twi1", NULL, 0);
|
||||
rpmsg_notify("twi0", NULL, 0);
|
||||
rpmsg_notify("tdm0", NULL, 0);
|
||||
rpmsg_notify("isp0", NULL, 0);
|
||||
// rpmsg_notify("isp1", NULL, 0);
|
||||
rpmsg_notify("scaler0", NULL, 0);
|
||||
// rpmsg_notify("scaler1", NULL, 0);
|
||||
rpmsg_notify("scaler4", NULL, 0);
|
||||
// rpmsg_notify("scaler5", NULL, 0);
|
||||
rpmsg_notify("scaler8", NULL, 0);
|
||||
// rpmsg_notify("scaler9", NULL, 0);
|
||||
rpmsg_notify("scaler12", NULL, 0);
|
||||
// rpmsg_notify("scaler13", NULL, 0);
|
||||
rpmsg_notify("vinc0", NULL, 0);
|
||||
// rpmsg_notify("vinc1", NULL, 0);
|
||||
rpmsg_notify("vinc4", NULL, 0);
|
||||
// rpmsg_notify("vinc5", NULL, 0);
|
||||
rpmsg_notify("vinc8", NULL, 0);
|
||||
// rpmsg_notify("vinc9", NULL, 0);
|
||||
rpmsg_notify("vinc12", NULL, 0);
|
||||
// rpmsg_notify("vinc13", NULL, 0);
|
||||
#endif
|
||||
#else
|
||||
hal_msleep(200);
|
||||
|
||||
@@ -110,4 +110,8 @@ config SENSOR_F37P_MIPI
|
||||
|
||||
config SENSOR_OV02B10_MIPI
|
||||
tristate "use ov02b10_mipi driver"
|
||||
default n
|
||||
|
||||
config SENSOR_SC202CS_MIPI
|
||||
tristate "use sc202cs_mipi driver"
|
||||
default n
|
||||
@@ -24,3 +24,4 @@ obj-$(CONFIG_SENSOR_F355P_DVP) += f355p_dvp.o
|
||||
obj-$(CONFIG_SENSOR_F37P_DVP) += f37p_dvp.o
|
||||
obj-$(CONFIG_SENSOR_F37P_MIPI) += f37p_mipi.o
|
||||
obj-$(CONFIG_SENSOR_OV02B10_MIPI) += ov02b10_mipi.o
|
||||
obj-$(CONFIG_SENSOR_SC202CS_MIPI) += sc202cs_mipi.o
|
||||
|
||||
@@ -178,4 +178,5 @@ extern struct sensor_fuc_core f355p_dvp_core;
|
||||
extern struct sensor_fuc_core f355p_core;
|
||||
extern struct sensor_fuc_core bf2257cs_core;
|
||||
extern struct sensor_fuc_core ov02b10_core;
|
||||
extern struct sensor_fuc_core sc202cs_core;
|
||||
#endif /*__CAMERA__H__*/
|
||||
|
||||
857
lichee/rtos-hal/hal/source/vin/modules/sensor/sc202cs_mipi.c
Executable file
857
lichee/rtos-hal/hal/source/vin/modules/sensor/sc202cs_mipi.c
Executable file
@@ -0,0 +1,857 @@
|
||||
/*
|
||||
* A V4L2 driver for Raw cameras.
|
||||
*
|
||||
* Copyright (c) 2017 by Allwinnertech Co., Ltd. http://www.allwinnertech.com
|
||||
*
|
||||
* Authors: Zhao Wei <zhaowei@allwinnertech.com>
|
||||
* Liang WeiJie <liangweijie@allwinnertech.com>
|
||||
*
|
||||
* 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 <hal_timer.h>
|
||||
|
||||
#include "../../vin_mipi/combo_common.h"
|
||||
#include "camera.h"
|
||||
#include "../../utility/sunxi_camera_v2.h"
|
||||
#include "../../utility/media-bus-format.h"
|
||||
#include "../../utility/vin_supply.h"
|
||||
|
||||
#define MCLK (24*1000*1000)
|
||||
#define V4L2_IDENT_SENSOR 0xeb52
|
||||
|
||||
/*
|
||||
* Our nominal (default) frame rate.
|
||||
*/
|
||||
#define ID_REG_HIGH 0xf0
|
||||
#define ID_REG_LOW 0xf1
|
||||
#define ID_VAL_HIGH ((V4L2_IDENT_SENSOR) >> 8)
|
||||
#define ID_VAL_LOW ((V4L2_IDENT_SENSOR) & 0xff)
|
||||
#define SENSOR_FRAME_RATE 30
|
||||
|
||||
#define VTS 1250
|
||||
|
||||
#define EXPOSURE_MIN 6
|
||||
#define EXPOSURE_MAX (VTS - 6)
|
||||
#define EXPOSURE_STEP 1
|
||||
#define EXPOSURE_DEFAULT 0x0148
|
||||
|
||||
#define GAIN_MIN 0x00
|
||||
#define GAIN_MAX 0xF8
|
||||
#define GAIN_STEP 1
|
||||
#define GAIN_DEFAULT 20
|
||||
#define GAIN_STEP_BASE 128 //mean gain min step is 1/64gain
|
||||
#define DIG_GAIN 0x3e06
|
||||
#define DIG_FINE_GAIN 0x3e07
|
||||
#define ANA_GAIN 0x3e09
|
||||
|
||||
/*
|
||||
* The sc202cs i2c address
|
||||
*/
|
||||
#define I2C_ADDR 0x7c//0xdc
|
||||
|
||||
#define SENSOR_NUM 0x2
|
||||
#define SENSOR_NAME "sc202cs_mipi"
|
||||
#define SENSOR_NAME_2 "sc202cs_mipi_2"
|
||||
|
||||
static int sensor_power_count[2];
|
||||
static int sensor_stream_count[2];
|
||||
static struct sensor_format_struct *current_win[2];
|
||||
static struct sensor_format_struct *current_switch_win[2];
|
||||
|
||||
#define SENSOR_30FPS 1
|
||||
#define SENSOR_25FPS 0
|
||||
#define SENSOR_20FPS 0
|
||||
#define SENSOR_15FPS 0
|
||||
|
||||
/*
|
||||
* The default register settings
|
||||
*/
|
||||
|
||||
static struct regval_list sensor_default_regs[] = {
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#if defined CONFIG_ISP_READ_THRESHOLD || defined CONFIG_ISP_ONLY_HARD_LIGHTADC//FULL_SIZE
|
||||
#if SENSOR_30FPS
|
||||
|
||||
static struct regval_list sensor_1600x1200_30_regs[] = {
|
||||
{0x0103, 0x01},
|
||||
{0x0100, 0x00},
|
||||
{0x36e9, 0x80},
|
||||
{0x36e9, 0x24},
|
||||
{0x301f, 0x01},
|
||||
{0x3301, 0xff},
|
||||
{0x3304, 0x68},
|
||||
{0x3306, 0x40},
|
||||
{0x3308, 0x08},
|
||||
{0x3309, 0xa8},
|
||||
{0x330b, 0xb0},
|
||||
{0x330c, 0x18},
|
||||
{0x330d, 0xff},
|
||||
{0x330e, 0x20},
|
||||
{0x331e, 0x59},
|
||||
{0x331f, 0x99},
|
||||
{0x3333, 0x10},
|
||||
{0x335e, 0x06},
|
||||
{0x335f, 0x08},
|
||||
{0x3364, 0x1f},
|
||||
{0x337c, 0x02},
|
||||
{0x337d, 0x0a},
|
||||
{0x338f, 0xa0},
|
||||
{0x3390, 0x01},
|
||||
{0x3391, 0x03},
|
||||
{0x3392, 0x1f},
|
||||
{0x3393, 0xff},
|
||||
{0x3394, 0xff},
|
||||
{0x3395, 0xff},
|
||||
{0x33a2, 0x04},
|
||||
{0x33ad, 0x0c},
|
||||
{0x33b1, 0x20},
|
||||
{0x33b3, 0x38},
|
||||
{0x33f9, 0x40},
|
||||
{0x33fb, 0x48},
|
||||
{0x33fc, 0x0f},
|
||||
{0x33fd, 0x1f},
|
||||
{0x349f, 0x03},
|
||||
{0x34a6, 0x03},
|
||||
{0x34a7, 0x1f},
|
||||
{0x34a8, 0x38},
|
||||
{0x34a9, 0x30},
|
||||
{0x34ab, 0xb0},
|
||||
{0x34ad, 0xb0},
|
||||
{0x34f8, 0x1f},
|
||||
{0x34f9, 0x20},
|
||||
{0x3630, 0xa0},
|
||||
{0x3631, 0x92},
|
||||
{0x3632, 0x64},
|
||||
{0x3633, 0x43},
|
||||
{0x3637, 0x49},
|
||||
{0x363a, 0x85},
|
||||
{0x363c, 0x0f},
|
||||
{0x3650, 0x31},
|
||||
{0x3670, 0x0d},
|
||||
{0x3674, 0xc0},
|
||||
{0x3675, 0xa0},
|
||||
{0x3676, 0xa0},
|
||||
{0x3677, 0x92},
|
||||
{0x3678, 0x96},
|
||||
{0x3679, 0x9a},
|
||||
{0x367c, 0x03},
|
||||
{0x367d, 0x0f},
|
||||
{0x367e, 0x01},
|
||||
{0x367f, 0x0f},
|
||||
{0x3698, 0x83},
|
||||
{0x3699, 0x86},
|
||||
{0x369a, 0x8c},
|
||||
{0x369b, 0x94},
|
||||
{0x36a2, 0x01},
|
||||
{0x36a3, 0x03},
|
||||
{0x36a4, 0x07},
|
||||
{0x36ae, 0x0f},
|
||||
{0x36af, 0x1f},
|
||||
{0x36bd, 0x22},
|
||||
{0x36be, 0x22},
|
||||
{0x36bf, 0x22},
|
||||
{0x36d0, 0x01},
|
||||
{0x370f, 0x02},
|
||||
{0x3721, 0x6c},
|
||||
{0x3722, 0x8d},
|
||||
{0x3725, 0xc5},
|
||||
{0x3727, 0x14},
|
||||
{0x3728, 0x04},
|
||||
{0x37b7, 0x04},
|
||||
{0x37b8, 0x04},
|
||||
{0x37b9, 0x06},
|
||||
{0x37bd, 0x07},
|
||||
{0x37be, 0x0f},
|
||||
{0x3901, 0x02},
|
||||
{0x3903, 0x40},
|
||||
{0x3905, 0x8d},
|
||||
{0x3907, 0x00},
|
||||
{0x3908, 0x41},
|
||||
{0x391f, 0x41},
|
||||
{0x3933, 0x80},
|
||||
{0x3934, 0x02},
|
||||
{0x3937, 0x6f},
|
||||
{0x393a, 0x01},
|
||||
{0x393d, 0x01},
|
||||
{0x393e, 0xc0},
|
||||
{0x39dd, 0x41},
|
||||
{0x3e00, 0x00},
|
||||
{0x3e01, 0x4d},
|
||||
{0x3e02, 0xc0},
|
||||
{0x3e09, 0x00},
|
||||
{0x4509, 0x28},
|
||||
{0x450d, 0x61},
|
||||
{0x0100, 0x01},
|
||||
};
|
||||
#endif
|
||||
|
||||
#else //CONFIG_ISP_FAST_CONVERGENCE || CONFIG_ISP_HARD_LIGHTADC
|
||||
static struct regval_list sensor_480p120_regs[] = {
|
||||
|
||||
};
|
||||
#if SENSOR_30FPS
|
||||
static struct regval_list sensor_480p120fps_to_1600x1200_30fps[] = {
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Here we'll try to encapsulate the changes for just the output
|
||||
* video format.
|
||||
*
|
||||
*/
|
||||
|
||||
static struct regval_list sensor_fmt_raw[] = {
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Code for dealing with controls.
|
||||
* fill with different sensor module
|
||||
* different sensor module has different settings here
|
||||
* if not support the follow function , retrun -EINVAL
|
||||
*/
|
||||
#if 0
|
||||
static int sensor_g_exp(struct v4l2_subdev *sd, __s32 *value)
|
||||
{
|
||||
struct sensor_info *info = to_state(sd);
|
||||
*value = info->exp;
|
||||
sensor_dbg("sensor_get_exposure = %d\n", info->exp);
|
||||
return 0;
|
||||
}
|
||||
static int sensor_g_gain(struct v4l2_subdev *sd, __s32 *value)
|
||||
{
|
||||
struct sensor_info *info = to_state(sd);
|
||||
*value = info->gain;
|
||||
sensor_dbg("sensor_get_gain = %d\n", info->gain);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sensor_s_exp(int id, unsigned int exp_val)
|
||||
{
|
||||
|
||||
int explow, expmid, exphigh;
|
||||
//struct sensor_info *info = to_state(sd);
|
||||
/*struct vin_md *vind = dev_get_drvdata(sd->v4l2_dev->dev);*/
|
||||
/*struct vin_core *vinc = vind->vinc[0];*/
|
||||
|
||||
if (exp_val > EXPOSURE_MAX << 4)
|
||||
exp_val = EXPOSURE_MAX << 4;
|
||||
|
||||
if (exp_val < 16)
|
||||
exp_val = 16;
|
||||
|
||||
exphigh = (unsigned char) (0x0f & (exp_val>>16));
|
||||
expmid = (unsigned char) (0xff & (exp_val>>8));
|
||||
explow = (unsigned char) (0xf0 & (exp_val<<0));
|
||||
sensor_write(id, 0x3e02, explow);
|
||||
sensor_write(id, 0x3e01, expmid);
|
||||
sensor_write(id, 0x3e00, exphigh);
|
||||
sensor_dbg("%s():%d, exp_val = %d\n", __func__, __LINE__, exp_val);
|
||||
//info->exp = exp_val;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned char analog_Gain_Reg[] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f};
|
||||
|
||||
static int setSensorGain(int id, int gain)
|
||||
{
|
||||
int ana_gain = gain / GAIN_STEP_BASE;
|
||||
int dig_Gain;
|
||||
int gain_flag = 1;
|
||||
|
||||
if (ana_gain >= 16) {
|
||||
gain_flag = 4;
|
||||
} else if (ana_gain >= 8) {
|
||||
gain_flag = 3;
|
||||
} else if (ana_gain >= 4) {
|
||||
gain_flag = 2;
|
||||
} else if (ana_gain >= 2) {
|
||||
gain_flag = 1;
|
||||
} else {
|
||||
gain_flag = 0;
|
||||
}
|
||||
|
||||
sensor_write(id, ANA_GAIN, analog_Gain_Reg[gain_flag]);
|
||||
dig_Gain = gain >> gain_flag; //dig_Gain min mean 1/128gain
|
||||
if (dig_Gain < 2 * GAIN_STEP_BASE) {
|
||||
//step1/128
|
||||
sensor_write(id, DIG_GAIN, 0x00);
|
||||
sensor_write(id, DIG_FINE_GAIN, dig_Gain - GAIN_STEP_BASE + 0x80);
|
||||
//sensor_print("sensor set analog_gain:0x%02x, dig_gain:0x%02x, dig_fine_gain:0x%02x", analog_Gain_Reg[gain_flag], 0x00, dig_Gain - 128 + 0x80);
|
||||
} else if (dig_Gain < 4 * GAIN_STEP_BASE) {
|
||||
//step1/64
|
||||
sensor_write(id, DIG_GAIN, 0x01);
|
||||
sensor_write(id, DIG_FINE_GAIN, (dig_Gain - GAIN_STEP_BASE * 2) / 2 + 0x80);
|
||||
//sensor_print("sensor set analog_gain:0x%02x, dig_gain:0x%02x, dig_fine_gain:0x%02x", analog_Gain_Reg[gain_flag], 0x01, (dig_Gain - 128 * 2) / 2 + 0x80);
|
||||
} else {
|
||||
sensor_write(id, DIG_GAIN, 0x01);
|
||||
sensor_write(id, DIG_FINE_GAIN, 0xfc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_s_gain(int id, int gain_val)
|
||||
{
|
||||
int tem_gain_val;
|
||||
|
||||
//gain min step is 1/128gain
|
||||
tem_gain_val = gain_val * GAIN_STEP_BASE;
|
||||
if ((tem_gain_val - tem_gain_val / 16 * 16) > 0) {
|
||||
tem_gain_val = tem_gain_val / 16 + 1;
|
||||
} else {
|
||||
tem_gain_val = tem_gain_val / 16;
|
||||
}
|
||||
|
||||
sensor_dbg("%s(), L:%d, gain_val:%d, tem_gain_val:%d, info->gain:%d\n",
|
||||
__func__, __LINE__, gain_val, tem_gain_val, info->gain);
|
||||
|
||||
setSensorGain(id, tem_gain_val);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int sc202cs_sensor_vts;
|
||||
static int sensor_s_exp_gain(int id, struct sensor_exp_gain *exp_gain)
|
||||
{
|
||||
int exp_val, gain_val;
|
||||
int shutter = 0, frame_length = 0;
|
||||
|
||||
exp_val = exp_gain->exp_val;
|
||||
gain_val = exp_gain->gain_val;
|
||||
sensor_s_exp(id, exp_gain->exp_val);
|
||||
sensor_s_gain(id, exp_gain->gain_val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int sensor_flip_status;
|
||||
static int sensor_s_vflip(int id, int enable)
|
||||
{
|
||||
data_type get_value;
|
||||
data_type set_value;
|
||||
|
||||
if (!(enable == 0 || enable == 1))
|
||||
return -1;
|
||||
|
||||
sensor_read(id, 0x00, &get_value);
|
||||
sensor_dbg("ready to vflip, regs_data = 0x%x\n", get_value);
|
||||
|
||||
if (enable) {
|
||||
set_value = get_value | 0x04;
|
||||
sensor_flip_status |= 0x04;
|
||||
} else {
|
||||
set_value = get_value & 0xFB;
|
||||
sensor_flip_status &= 0xFB;
|
||||
}
|
||||
sensor_write(id, 0x00, set_value);
|
||||
usleep_range(80000, 100000);
|
||||
sensor_read(id, 0x00, &get_value);
|
||||
sensor_dbg("after vflip, regs_data = 0x%x, sensor_flip_status = %d\n",
|
||||
get_value, sensor_flip_status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_s_hflip(int id, int enable)
|
||||
{
|
||||
data_type get_value;
|
||||
data_type set_value;
|
||||
|
||||
if (!(enable == 0 || enable == 1))
|
||||
return -1;
|
||||
|
||||
sensor_read(id, 0x00, &get_value);
|
||||
sensor_dbg("ready to hflip, regs_data = 0x%x\n", get_value);
|
||||
|
||||
if (enable) {
|
||||
set_value = get_value | 0x08;
|
||||
sensor_flip_status |= 0x08;
|
||||
} else {
|
||||
set_value = get_value & 0xF7;
|
||||
sensor_flip_status &= 0xF7;
|
||||
}
|
||||
sensor_write(id, 0x00, set_value);
|
||||
usleep_range(80000, 100000);
|
||||
sensor_read(id, 0x00, &get_value);
|
||||
sensor_dbg("after hflip, regs_data = 0x%x, sensor_flip_status = %d\n",
|
||||
get_value, sensor_flip_status);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_get_fmt_mbus_core(struct v4l2_subdev *sd, int *code)
|
||||
{
|
||||
// struct sensor_info *info = to_state(sd);
|
||||
// data_type get_value = 0, check_value = 0;
|
||||
|
||||
// sensor_read(sd, 0x17, &get_value);
|
||||
// check_value = get_value & 0x03;
|
||||
// check_value = sensor_flip_status & 0x3;
|
||||
// sensor_dbg("0x17 = 0x%x, check_value = 0x%x\n", get_value, check_value);
|
||||
|
||||
// switch (check_value) {
|
||||
// case 0x00:
|
||||
// sensor_dbg("RGGB\n");
|
||||
// *code = MEDIA_BUS_FMT_SRGGB10_1X10;
|
||||
// break;
|
||||
// case 0x01:
|
||||
// sensor_dbg("GRBG\n");
|
||||
// *code = MEDIA_BUS_FMT_SGRBG10_1X10;
|
||||
// break;
|
||||
// case 0x02:
|
||||
// sensor_dbg("GBRG\n");
|
||||
// *code = MEDIA_BUS_FMT_SGBRG10_1X10;
|
||||
// break;
|
||||
// case 0x03:
|
||||
// sensor_dbg("BGGR\n");
|
||||
// *code = MEDIA_BUS_FMT_SBGGR10_1X10;
|
||||
// break;
|
||||
// default:
|
||||
// *code = info->fmt->mbus_code;
|
||||
// }
|
||||
*code = MEDIA_BUS_FMT_SRGGB10_1X10; // sc202cs support change the rgb format by itself
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Stuff that knows about the sensor.
|
||||
*/
|
||||
static int sensor_power(int id, int on)
|
||||
{
|
||||
if (on && (sensor_power_count[id])++ > 0)
|
||||
return 0;
|
||||
else if (!on && (sensor_power_count[id] == 0 || --(sensor_power_count[id]) > 0))
|
||||
return 0;
|
||||
|
||||
switch (on) {
|
||||
case PWR_ON:
|
||||
sensor_print("PWR_ON!\n");
|
||||
vin_set_mclk_freq(id, MCLK);
|
||||
vin_set_mclk(id, 1);
|
||||
hal_usleep(1000);
|
||||
//vin_gpio_set_status(id, PWDN, 1);
|
||||
vin_gpio_set_status(id, RESET, 1);
|
||||
//vin_gpio_set_status(sd, POWER_EN, 1);
|
||||
//vin_gpio_write(id, PWDN, CSI_GPIO_LOW);
|
||||
vin_gpio_write(id, RESET, CSI_GPIO_LOW);
|
||||
hal_usleep(1000);
|
||||
//vin_gpio_write(id, PWDN, CSI_GPIO_HIGH);
|
||||
hal_usleep(1000);
|
||||
vin_gpio_write(id, RESET, CSI_GPIO_HIGH);
|
||||
hal_usleep(1000);
|
||||
break;
|
||||
case PWR_OFF:
|
||||
sensor_print("PWR_OFF!\n");
|
||||
vin_set_mclk(id, 0);
|
||||
hal_usleep(1000);
|
||||
// vin_gpio_set_status(id, PWDN, 1);
|
||||
vin_gpio_set_status(id, RESET, 1);
|
||||
// vin_gpio_write(id, PWDN, CSI_GPIO_LOW);
|
||||
vin_gpio_write(id, RESET, CSI_GPIO_LOW);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_set_ir(int id, int status)
|
||||
{
|
||||
#if 0
|
||||
vin_gpio_set_status(id, IR_CUT0, 1);
|
||||
vin_gpio_set_status(id, IR_CUT1, 1);
|
||||
vin_gpio_set_status(id, IR_LED, 1);
|
||||
switch (status) {
|
||||
case IR_DAY:
|
||||
vin_gpio_write(id, IR_CUT0, CSI_GPIO_HIGH);
|
||||
vin_gpio_write(id, IR_CUT1, CSI_GPIO_LOW);
|
||||
vin_gpio_write(id, IR_LED, CSI_GPIO_LOW);
|
||||
break;
|
||||
case IR_NIGHT:
|
||||
vin_gpio_write(id, IR_CUT0, CSI_GPIO_LOW);
|
||||
vin_gpio_write(id, IR_CUT1, CSI_GPIO_HIGH);
|
||||
vin_gpio_write(id, IR_LED, CSI_GPIO_HIGH);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int sensor_reset(int id, u32 val)
|
||||
{
|
||||
|
||||
sensor_dbg("%s: val=%d\n", __func__);
|
||||
switch (val) {
|
||||
case 0:
|
||||
vin_gpio_write(id, RESET, CSI_GPIO_HIGH);
|
||||
hal_usleep(1000);
|
||||
break;
|
||||
case 1:
|
||||
vin_gpio_write(id, RESET, CSI_GPIO_LOW);
|
||||
hal_usleep(1000);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sensor_detect(int id)
|
||||
{
|
||||
data_type rdval;
|
||||
int eRet;
|
||||
int times_out = 3;
|
||||
do {
|
||||
eRet = sensor_read(id, ID_REG_HIGH, &rdval);
|
||||
sensor_dbg("eRet:%d, ID_VAL_HIGH:0x%x, times_out:%d\n", eRet, rdval, times_out);
|
||||
hal_usleep(200);
|
||||
times_out--;
|
||||
} while (eRet < 0 && times_out > 0);
|
||||
|
||||
sensor_read(id, ID_REG_HIGH, &rdval);
|
||||
sensor_dbg("ID_VAL_HIGH = %2x, Done!\n", rdval);
|
||||
if (rdval != ID_VAL_HIGH)
|
||||
return -ENODEV;
|
||||
|
||||
sensor_read(id, ID_REG_LOW, &rdval);
|
||||
sensor_dbg("ID_VAL_LOW = %2x, Done!\n", rdval);
|
||||
if (rdval != ID_VAL_LOW)
|
||||
return -ENODEV;
|
||||
|
||||
sensor_dbg("Done!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_init(int id)
|
||||
{
|
||||
int ret;
|
||||
|
||||
sensor_dbg("sensor_init\n");
|
||||
|
||||
/*Make sure it is a target sensor */
|
||||
ret = sensor_detect(id);
|
||||
if (ret) {
|
||||
sensor_err("chip found is not an target chip.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Store information about the video data format.
|
||||
*/
|
||||
static struct sensor_format_struct sensor_formats[] = {
|
||||
#if defined CONFIG_ISP_READ_THRESHOLD || defined CONFIG_ISP_ONLY_HARD_LIGHTADC // FULL_SIZE
|
||||
#if SENSOR_30FPS
|
||||
{
|
||||
.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,//MEDIA_BUS_FMT_SRGGB10_1X10, /*.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10, */
|
||||
.width = 1600,
|
||||
.height = 1200,
|
||||
.hoffset = 0,
|
||||
.voffset = 0,
|
||||
.hts = 1920,
|
||||
.vts = 1250,
|
||||
.pclk = 72000000,
|
||||
.mipi_bps = 371250000,
|
||||
.fps_fixed = 30,
|
||||
.bin_factor = 1,
|
||||
.intg_min = 1 << 4,
|
||||
.intg_max = (1250 - 8) << 4,
|
||||
.gain_min = 1 << 4,
|
||||
.gain_max = 64 << 4,
|
||||
.offs_h = 0,
|
||||
.offs_v = 0,
|
||||
.regs = sensor_1600x1200_30_regs,
|
||||
.regs_size = ARRAY_SIZE(sensor_1600x1200_30_regs),
|
||||
}
|
||||
#endif
|
||||
#else //CONFIG_ISP_FAST_CONVERGENCE || CONFIG_ISP_HARD_LIGHTADC
|
||||
{
|
||||
.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
|
||||
.width = 640,
|
||||
.height = 480,
|
||||
.hoffset = 0,
|
||||
.voffset = 0,
|
||||
.hts = 1696,
|
||||
.vts = 525,
|
||||
.pclk = 106848000,
|
||||
.mipi_bps = 648 * 1000 * 1000,
|
||||
.fps_fixed = 120,
|
||||
.bin_factor = 1,
|
||||
.intg_min = 1 << 4,
|
||||
.intg_max = (525 - 16) << 4,
|
||||
.gain_min = 1 << 4,
|
||||
.gain_max = 110 << 4,
|
||||
.offs_h = 0,
|
||||
.offs_v = 0,
|
||||
.regs = sensor_480p120_regs,
|
||||
.regs_size = ARRAY_SIZE(sensor_480p120_regs),
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct sensor_format_struct *sensor_get_format(int id, int isp_id)
|
||||
{
|
||||
#if defined CONFIG_ISP_READ_THRESHOLD || defined CONFIG_ISP_ONLY_HARD_LIGHTADC
|
||||
int ispid = clamp(isp_id, 0, ISP_GET_CFG_NUM - 1);
|
||||
struct sensor_format_struct *sensor_format = NULL;
|
||||
int wdr_on = isp_get_cfg[ispid].sensor_wdr_on;
|
||||
int fps = isp_get_cfg[ispid].sensor_get_fps;
|
||||
int i;
|
||||
|
||||
if (current_win[id])
|
||||
return current_win[id];
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sensor_formats); i++) {
|
||||
if (sensor_formats[i].wdr_mode == wdr_on) {
|
||||
if (sensor_formats[i].fps_fixed == fps) {
|
||||
sensor_format = &sensor_formats[i];
|
||||
sensor_print("fine wdr is %d, fine fps is %d\n", wdr_on, fps);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sensor_format == NULL) {
|
||||
for (i = 0; i < ARRAY_SIZE(sensor_formats); i++) {
|
||||
if (sensor_formats[i].wdr_mode == wdr_on) {
|
||||
sensor_format = &sensor_formats[i];
|
||||
isp_get_cfg[ispid].sensor_get_fps = sensor_format->fps_fixed;
|
||||
sensor_print("fine wdr is %d, use fps is %d\n", wdr_on, sensor_format->fps_fixed);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sensor_format == NULL) {
|
||||
sensor_format = &sensor_formats[0];
|
||||
isp_get_cfg[ispid].sensor_wdr_on = sensor_format->wdr_mode;
|
||||
isp_get_cfg[ispid].sensor_get_fps = sensor_format->fps_fixed;
|
||||
sensor_print("use wdr is %d, use fps is %d\n", sensor_format->wdr_mode, sensor_format->fps_fixed);
|
||||
}
|
||||
|
||||
done:
|
||||
current_win[id] = sensor_format;
|
||||
return sensor_format;
|
||||
#else //CONFIG_ISP_FAST_CONVERGENCE || CONFIG_ISP_HARD_LIGHTADC
|
||||
if (current_win[id])
|
||||
return current_win[id];
|
||||
|
||||
current_win[id] = &sensor_formats[0];
|
||||
sensor_print("fine wdr is %d, fps is %d\n", sensor_formats[0].wdr_mode, sensor_formats[0].fps_fixed);
|
||||
return &sensor_formats[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct sensor_format_struct switch_sensor_formats[] = {
|
||||
#if defined CONFIG_ISP_FAST_CONVERGENCE || defined CONFIG_ISP_HARD_LIGHTADC
|
||||
|
||||
#if SENSOR_30FPS
|
||||
{
|
||||
.mbus_code = MEDIA_BUS_FMT_SBGGR10_1X10,
|
||||
.width = 1600,
|
||||
.height = 1200,//1080,
|
||||
.hoffset = 0,
|
||||
.voffset = 0,
|
||||
.hts = 1920,
|
||||
.vts = 1250,
|
||||
.pclk = 72000000,
|
||||
.mipi_bps = 672 * 1000 * 1000,
|
||||
.fps_fixed = 30,
|
||||
.bin_factor = 1,
|
||||
.intg_min = 1 << 4,
|
||||
.intg_max = (1250 - 16) << 4,
|
||||
.gain_min = 1 << 4,
|
||||
.gain_max = 110 << 4,
|
||||
.switch_regs = sensor_480p120fps_to_1600x1200_30fps,
|
||||
.switch_regs_size = ARRAY_SIZE(sensor_480p120fps_to_1600x1200_30fps),
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct sensor_format_struct *sensor_get_switch_format(int id, int isp_id)
|
||||
{
|
||||
#if defined CONFIG_ISP_FAST_CONVERGENCE || defined CONFIG_ISP_HARD_LIGHTADC
|
||||
int ispid = clamp(isp_id, 0, ISP_GET_CFG_NUM - 1);
|
||||
struct sensor_format_struct *sensor_format = NULL;
|
||||
int wdr_on = isp_get_cfg[ispid].sensor_wdr_on;
|
||||
int fps = isp_get_cfg[ispid].sensor_get_fps;
|
||||
int i;
|
||||
|
||||
if (current_switch_win[id])
|
||||
return current_switch_win[id];
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(switch_sensor_formats); i++) {
|
||||
if (switch_sensor_formats[i].wdr_mode == wdr_on) {
|
||||
if (switch_sensor_formats[i].fps_fixed == fps) {
|
||||
sensor_format = &switch_sensor_formats[i];
|
||||
sensor_print("switch fine wdr is %d, fine fps is %d\n", wdr_on, fps);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sensor_format == NULL) {
|
||||
for (i = 0; i < ARRAY_SIZE(switch_sensor_formats); i++) {
|
||||
if (switch_sensor_formats[i].wdr_mode == wdr_on) {
|
||||
sensor_format = &switch_sensor_formats[i];
|
||||
isp_get_cfg[ispid].sensor_get_fps = sensor_format->fps_fixed;
|
||||
sensor_print("switch fine wdr is %d, use fps is %d\n", wdr_on, sensor_format->fps_fixed);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sensor_format == NULL) {
|
||||
sensor_format = &switch_sensor_formats[0];
|
||||
isp_get_cfg[ispid].sensor_wdr_on = sensor_format->wdr_mode;
|
||||
isp_get_cfg[ispid].sensor_get_fps = sensor_format->fps_fixed;
|
||||
sensor_print("switch use wdr is %d, use fps is %d\n", sensor_format->wdr_mode, sensor_format->fps_fixed);
|
||||
}
|
||||
|
||||
done:
|
||||
current_switch_win[id] = sensor_format;
|
||||
return sensor_format;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int sensor_g_mbus_config(int id, struct v4l2_mbus_config *cfg, struct mbus_framefmt_res *res)
|
||||
{
|
||||
//struct sensor_info *info = to_state(sd);
|
||||
|
||||
cfg->type = V4L2_MBUS_CSI2;
|
||||
cfg->flags = 0 | V4L2_MBUS_CSI2_1_LANE | V4L2_MBUS_CSI2_CHANNEL_0;
|
||||
// res->res_time_hs = 0x11;
|
||||
res->deskew = 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_reg_init(int id, int isp_id)
|
||||
{
|
||||
int ret = 0;
|
||||
int ispid = clamp(isp_id, 0, ISP_GET_CFG_NUM - 1);
|
||||
struct sensor_exp_gain exp_gain;
|
||||
|
||||
ret = sensor_write_array(id, sensor_default_regs,
|
||||
ARRAY_SIZE(sensor_default_regs));
|
||||
if (ret < 0) {
|
||||
sensor_err("write sensor_default_regs error\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (current_win[id]->regs)
|
||||
ret = sensor_write_array(id, current_win[id]->regs, current_win[id]->regs_size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
sc202cs_sensor_vts = current_win[id]->vts;
|
||||
#if 0
|
||||
//#if defined CONFIG_ISP_READ_THRESHOLD || defined CONFIG_ISP_FAST_CONVERGENCE
|
||||
if (ispid == 0) {
|
||||
exp_gain.exp_val = clamp(*((unsigned int *)ISP0_NORFLASH_SAVE + 2), 16, 1125 << 4);
|
||||
exp_gain.gain_val = clamp(*((unsigned int *)ISP0_NORFLASH_SAVE + 1), 16, 110 << 4);
|
||||
} else {
|
||||
exp_gain.exp_val = clamp(*((unsigned int *)ISP1_NORFLASH_SAVE + 2), 16, 1125 << 4);
|
||||
exp_gain.gain_val = clamp(*((unsigned int *)ISP1_NORFLASH_SAVE + 1), 16, 110 << 4);
|
||||
}
|
||||
#if defined CONFIG_ISP_FAST_CONVERGENCE || defined CONFIG_ISP_HARD_LIGHTADC
|
||||
temperature_ctrl = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
exp_gain.exp_val = 0xff0302;
|
||||
exp_gain.gain_val = 0xff24;
|
||||
sensor_s_exp_gain(id, &exp_gain);
|
||||
// sensor_write(id, 0x3e, 0x91);
|
||||
//#else //CONFIG_ISP_HARD_LIGHTADC
|
||||
|
||||
//#endif
|
||||
//sensor_flip_status = 0x0;
|
||||
//sensor_dbg("sc202cs_sensor_vts = %d\n", sc202cs_sensor_vts);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_s_stream(int id, int isp_id, int enable)
|
||||
{
|
||||
if (enable && sensor_stream_count[id]++ > 0)
|
||||
return 0;
|
||||
else if (!enable && (sensor_stream_count[id] == 0 || --sensor_stream_count[id] > 0))
|
||||
return 0;
|
||||
|
||||
sensor_dbg("%s on = %d, 2560*1440 fps: 15\n", __func__, enable);
|
||||
|
||||
if (!enable)
|
||||
return 0;
|
||||
|
||||
return sensor_reg_init(id, isp_id);
|
||||
}
|
||||
|
||||
static int sensor_s_switch(int id)
|
||||
{
|
||||
#if defined CONFIG_ISP_FAST_CONVERGENCE || defined CONFIG_ISP_HARD_LIGHTADC
|
||||
struct sensor_exp_gain exp_gain;
|
||||
int ret = -1;
|
||||
temperature_ctrl = 1;
|
||||
sc202cs_sensor_vts = current_switch_win[id]->vts;
|
||||
if (current_switch_win[id]->switch_regs)
|
||||
ret = sensor_write_array(id, current_switch_win[id]->switch_regs, current_switch_win[id]->switch_regs_size);
|
||||
else
|
||||
sensor_err("cannot find 480p120fps to 1600x1200_%dfps reg\n", current_switch_win[id]->fps_fixed);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sensor_test_i2c(int id)
|
||||
{
|
||||
int ret;
|
||||
sensor_power(id, PWR_ON);
|
||||
ret = sensor_init(id);
|
||||
sensor_power(id, PWR_OFF);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct sensor_fuc_core sc202cs_core = {
|
||||
.g_mbus_config = sensor_g_mbus_config,
|
||||
.sensor_test_i2c = sensor_test_i2c,
|
||||
.sensor_power = sensor_power,
|
||||
.s_ir_status = sensor_set_ir,
|
||||
.s_stream = sensor_s_stream,
|
||||
.s_switch = sensor_s_switch,
|
||||
.s_exp_gain = sensor_s_exp_gain,
|
||||
.sensor_g_format = sensor_get_format,
|
||||
.sensor_g_switch_format = sensor_get_switch_format,
|
||||
};
|
||||
@@ -68,6 +68,9 @@ struct sensor_cfg_array sensor_array[] = {
|
||||
#ifdef CONFIG_SENSOR_GC2083_MIPI
|
||||
{"gc2083_mipi", &gc2083_core},
|
||||
#endif
|
||||
#ifdef CONFIG_SENSOR_SC202CS_MIPI
|
||||
{"sc202cs_mipi", &sc202cs_core},
|
||||
#endif
|
||||
};
|
||||
|
||||
struct sensor_fuc_core *find_sensor_func(char *sensor_name)
|
||||
|
||||
@@ -159,15 +159,15 @@ struct vin_mclk_info vind_default_mclk[VIN_MAX_CCI] = {
|
||||
.mclk = HAL_CLK_PERIPH_CSI_MASTER0,
|
||||
.clk_24m = HAL_CLK_SRC_HOSC,
|
||||
.clk_pll = HAL_CLK_PLL_CSI,
|
||||
.pin = GPIOA(10),
|
||||
.pin_func = {0x4, 0xf},
|
||||
.pin = GPIOE(12),
|
||||
.pin_func = {0x5, 0xf},
|
||||
},
|
||||
{
|
||||
.mclk = HAL_CLK_PERIPH_CSI_MASTER1,
|
||||
.clk_24m = HAL_CLK_SRC_HOSC,
|
||||
.clk_pll = HAL_CLK_PLL_CSI,
|
||||
.pin = GPIOA(13),
|
||||
.pin_func = {0x4, 0xf},
|
||||
.pin = GPIOE(13),
|
||||
.pin_func = {0x5, 0xf},
|
||||
},
|
||||
{
|
||||
.mclk = HAL_CLK_PERIPH_CSI_MASTER1,
|
||||
@@ -226,6 +226,21 @@ struct sensor_list global_sensors[VIN_MAX_CSI] = {
|
||||
.ir_cut_gpio[0] = GPIOD(18), /*-cut*/
|
||||
.ir_cut_gpio[1] = GPIOD(8), /*+cut*/
|
||||
.ir_led_gpio = 0xffff, //GPIOE(10)
|
||||
#elif defined(CONFIG_SENSOR_SC202CS_MIPI)
|
||||
.used = 1,
|
||||
.sensor_name = "sc202cs_mipi",
|
||||
.sensor_twi_addr = 0x20,
|
||||
.sensor_twi_id = 0,
|
||||
.mclk_id = 1,
|
||||
.use_isp = 1,
|
||||
.id = 0,
|
||||
.addr_width = 16,
|
||||
.data_width = 8,
|
||||
.reset_gpio = GPIOE(10),
|
||||
.pwdn_gpio = 0xffff,
|
||||
.ir_cut_gpio[0] = 0xffff,/*-cut*/
|
||||
.ir_cut_gpio[1] = 0xffff,/*+cut*/
|
||||
.ir_led_gpio = 0xffff,
|
||||
#else //CONFIG_SENSOR_GC2053_MIPI
|
||||
.used = 1,
|
||||
.sensor_name = "gc2083_mipi",
|
||||
@@ -478,6 +493,21 @@ struct sensor_list global_sensors[VIN_MAX_CSI] = {
|
||||
// .ir_cut_gpio[0] = 0xffff,/*-cut*/
|
||||
// .ir_cut_gpio[1] = 0xffff,/*+cut*/
|
||||
// .ir_led_gpio = GPIOF(3),
|
||||
#elif defined(CONFIG_SENSOR_SC202CS_MIPI)
|
||||
.used = 1,
|
||||
.sensor_name = "sc202cs_mipi",
|
||||
.sensor_twi_addr = 0x20,
|
||||
.sensor_twi_id = 0,
|
||||
.mclk_id = 1,
|
||||
.use_isp = 1,
|
||||
.id = 0,
|
||||
.addr_width = 16,
|
||||
.data_width = 8,
|
||||
.reset_gpio = GPIOE(10),
|
||||
.pwdn_gpio = 0xffff,
|
||||
.ir_cut_gpio[0] = 0xffff,/*-cut*/
|
||||
.ir_cut_gpio[1] = 0xffff,/*+cut*/
|
||||
.ir_led_gpio = 0xffff,
|
||||
#else
|
||||
.used = 1,
|
||||
.sensor_name = "gc2083_mipi",
|
||||
@@ -527,6 +557,21 @@ struct sensor_list global_sensors[VIN_MAX_CSI] = {
|
||||
.ir_cut_gpio[0] = 0xffff,/*-cut*/
|
||||
.ir_cut_gpio[1] = 0xffff,/*+cut*/
|
||||
.ir_led_gpio = 0xffff,
|
||||
#elif defined(CONFIG_SENSOR_SC202CS_MIPI)
|
||||
.used = 1,
|
||||
.sensor_name = "sc202cs_mipi_2",
|
||||
.sensor_twi_addr = 0x6c,
|
||||
.sensor_twi_id = 0,
|
||||
.mclk_id = 1,
|
||||
.use_isp = 1,
|
||||
.id = 1,
|
||||
.addr_width = 16,
|
||||
.data_width = 8,
|
||||
.reset_gpio = GPIOE(11),
|
||||
.pwdn_gpio = 0xffff,
|
||||
.ir_cut_gpio[0] = 0xffff,/*-cut*/
|
||||
.ir_cut_gpio[1] = 0xffff,/*+cut*/
|
||||
.ir_led_gpio = 0xffff,
|
||||
#else
|
||||
.used = 1,
|
||||
.sensor_name = "gc2083_mipi",
|
||||
@@ -559,8 +604,8 @@ struct vin_core global_video[VIN_MAX_VIDEO] = {
|
||||
.isp_tx_ch = 0,
|
||||
.base = CSI_DMA0_REG_BASE,
|
||||
.irq = SUNXI_IRQ_CSIC_DMA0,
|
||||
.o_width = 512,
|
||||
.o_height = 288,
|
||||
.o_width = 1600,
|
||||
.o_height = 1200,
|
||||
//.fourcc = V4L2_PIX_FMT_LBC_2_5X,
|
||||
.fourcc = V4L2_PIX_FMT_NV12,
|
||||
.use_sensor_list = 0,
|
||||
@@ -569,7 +614,7 @@ struct vin_core global_video[VIN_MAX_VIDEO] = {
|
||||
.used = 1,
|
||||
.id = 1,
|
||||
.rear_sensor = 1,
|
||||
.front_sensor = 0,
|
||||
.front_sensor = 1,
|
||||
.csi_sel = 1,
|
||||
.mipi_sel = 1,
|
||||
.isp_sel = 1,
|
||||
@@ -577,8 +622,8 @@ struct vin_core global_video[VIN_MAX_VIDEO] = {
|
||||
.isp_tx_ch = 0,
|
||||
.base = CSI_DMA0_REG_BASE,
|
||||
.irq = SUNXI_IRQ_CSIC_DMA0,
|
||||
.o_width = 512,
|
||||
.o_height = 288,
|
||||
.o_width = 1600,
|
||||
.o_height = 1200,
|
||||
//.fourcc = V4L2_PIX_FMT_LBC_2_5X,
|
||||
.fourcc = V4L2_PIX_FMT_NV12,
|
||||
.use_sensor_list = 0,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,8 @@
|
||||
#if (ISP_VERSION >= 600)
|
||||
#if defined CONFIG_SENSOR_GC2053_MIPI || defined CONFIG_SENSOR_GC4663_MIPI || defined CONFIG_SENSOR_SC5336_MIPI || \
|
||||
defined CONFIG_SENSOR_GC1084_MIPI || CONFIG_SENSOR_BF2257CS_MIPI || CONFIG_SENSOR_SC2355_MIPI || CONFIG_SENSOR_F37P_MIPI || \
|
||||
defined CONFIG_SENSOR_F355P_MIPI || CONFIG_SENSOR_OV02B10_MIPI || CONFIG_SENSOR_GC2083_MIPI || CONFIG_SENSOR_SC2356_MIPI
|
||||
defined CONFIG_SENSOR_F355P_MIPI || CONFIG_SENSOR_OV02B10_MIPI || CONFIG_SENSOR_GC2083_MIPI || CONFIG_SENSOR_SC2356_MIPI || CONFIG_SENSOR_SC202CS_MIPI
|
||||
|
||||
#ifdef CONFIG_SENSOR_GC4663_MIPI
|
||||
#include "SENSOR_H/gc4663_mipi_default_ini_v853.h"
|
||||
#include "SENSOR_H/gc4663_120fps_mipi_default_ini_v853.h"
|
||||
@@ -122,6 +123,11 @@
|
||||
#include "SENSOR_H/sc2365_mipi_isp600_20250107_100622.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSOR_SC202CS_MIPI
|
||||
#include "SENSOR_H/sc202cs_mipi_isp600_ir_20250221_141621.h"
|
||||
#include "SENSOR_H/sc202cs_mipi_isp600_rgb_20250304_100237.h"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include "SENSOR_H/gc2053_mipi_default_ini_v853.h"
|
||||
#endif
|
||||
@@ -136,7 +142,7 @@ struct isp_cfg_array cfg_arr[] = {
|
||||
#if (ISP_VERSION >= 600)
|
||||
#if defined CONFIG_SENSOR_GC2053_MIPI || defined CONFIG_SENSOR_GC4663_MIPI || defined CONFIG_SENSOR_SC5336_MIPI || \
|
||||
defined CONFIG_SENSOR_GC1084_MIPI || CONFIG_SENSOR_BF2257CS_MIPI || CONFIG_SENSOR_SC2355_MIPI || CONFIG_SENSOR_F37P_MIPI || \
|
||||
defined CONFIG_SENSOR_F355P_MIPI || CONFIG_SENSOR_OV02B10_MIPI || CONFIG_SENSOR_GC2083_MIPI || CONFIG_SENSOR_SC2356_MIPI
|
||||
defined CONFIG_SENSOR_F355P_MIPI || CONFIG_SENSOR_OV02B10_MIPI || CONFIG_SENSOR_GC2083_MIPI || CONFIG_SENSOR_SC2356_MIPI || CONFIG_SENSOR_SC202CS_MIPI
|
||||
|
||||
#ifdef CONFIG_SENSOR_GC2053_MIPI
|
||||
{"gc2053_mipi", "gc2053_mipi_isp600_20231212_111630_day", 1920, 1088, 20, 0, 0, &gc2053_mipi_v853_isp_cfg},
|
||||
@@ -212,6 +218,13 @@ struct isp_cfg_array cfg_arr[] = {
|
||||
{"sc2356_mipi", "sc2365_mipi_isp600_20250107_100622", 1600, 1200, 15, 1, 0, &sc2356_mipi_isp_cfg},
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSOR_SC202CS_MIPI
|
||||
{"sc202cs_mipi", "sc202cs_mipi_isp600_rgb_20250304_100237", 1600, 1200, 30, 0, 0, &sc202cs_mipi_rgb_isp_cfg},
|
||||
{"sc202cs_mipi", "sc202cs_mipi_isp600_rgb_20250304_100237", 1600, 1200, 30, 1, 0, &sc202cs_mipi_rgb_isp_cfg},
|
||||
{"sc202ms_mipi", "sc202cs_mipi_isp600_ir_20250221_141621", 1600, 1200, 30, 0, 0, &sc202cs_mipi_ir_isp_cfg},
|
||||
{"sc202ms_mipi", "sc202cs_mipi_isp600_ir_20250221_141621", 1600, 1200, 30, 1, 0, &sc202cs_mipi_ir_isp_cfg},
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSOR_GC1084_MIPI
|
||||
{"gc1084_mipi", "gc1084_mipi_v853_20230410_164555_day", 1280, 720, 15, 0, 0, &gc1084_mipi_v853_isp_cfg},
|
||||
#ifdef CONFIG_ENABLE_AIISP
|
||||
|
||||
Reference in New Issue
Block a user