/* * Copyright (c) 2022 Semidrive Semiconductor. * All rights reserved. */ #include #include #include //#define _PLATFORM_SIMULATION_ #ifndef _PLATFORM_SIMULATION_ #include #include #include "camera/sdrv-cam-os-def.h" #include "exvdev.h" #endif #include "ex_ov5640.h" #ifdef BIT #undef BIT #define BIT(nr) (1 << nr) #endif #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define OV5640_LOG 3 #ifndef DIV_ROUND_UP #define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) #endif static int g_load_regs; /* min/typical/max system clock (xclk) frequencies */ #define OV5640_XCLK_MIN 6000000 #define OV5640_XCLK_MAX 54000000 #define OV5640_DEFAULT_SLAVE_ID 0x3c #define OV5640_REG_SYS_RESET02 0x3002 #define OV5640_REG_SYS_CLOCK_ENABLE02 0x3006 #define OV5640_REG_SYS_CTRL0 0x3008 #define OV5640_REG_CHIP_ID 0x300a #define OV5640_REG_IO_MIPI_CTRL00 0x300e #define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017 #define OV5640_REG_PAD_OUTPUT_ENABLE02 0x3018 #define OV5640_REG_PAD_OUTPUT00 0x3019 #define OV5640_REG_SYSTEM_CONTROL1 0x302e #define OV5640_REG_SC_PLL_CTRL0 0x3034 #define OV5640_REG_SC_PLL_CTRL1 0x3035 #define OV5640_REG_SC_PLL_CTRL2 0x3036 #define OV5640_REG_SC_PLL_CTRL3 0x3037 #define OV5640_REG_SLAVE_ID 0x3100 #define OV5640_REG_SCCB_SYS_CTRL1 0x3103 #define OV5640_REG_SYS_ROOT_DIVIDER 0x3108 #define OV5640_REG_AWB_R_GAIN 0x3400 #define OV5640_REG_AWB_G_GAIN 0x3402 #define OV5640_REG_AWB_B_GAIN 0x3404 #define OV5640_REG_AWB_MANUAL_CTRL 0x3406 #define OV5640_REG_AEC_PK_EXPOSURE_HI 0x3500 #define OV5640_REG_AEC_PK_EXPOSURE_MED 0x3501 #define OV5640_REG_AEC_PK_EXPOSURE_LO 0x3502 #define OV5640_REG_AEC_PK_MANUAL 0x3503 #define OV5640_REG_AEC_PK_REAL_GAIN 0x350a #define OV5640_REG_AEC_PK_VTS 0x350c #define OV5640_REG_TIMING_DVPHO 0x3808 #define OV5640_REG_TIMING_DVPVO 0x380a #define OV5640_REG_TIMING_HTS 0x380c #define OV5640_REG_TIMING_VTS 0x380e #define OV5640_REG_TIMING_TC_REG20 0x3820 #define OV5640_REG_TIMING_TC_REG21 0x3821 #define OV5640_REG_AEC_CTRL00 0x3a00 #define OV5640_REG_AEC_B50_STEP 0x3a08 #define OV5640_REG_AEC_B60_STEP 0x3a0a #define OV5640_REG_AEC_CTRL0D 0x3a0d #define OV5640_REG_AEC_CTRL0E 0x3a0e #define OV5640_REG_AEC_CTRL0F 0x3a0f #define OV5640_REG_AEC_CTRL10 0x3a10 #define OV5640_REG_AEC_CTRL11 0x3a11 #define OV5640_REG_AEC_CTRL1B 0x3a1b #define OV5640_REG_AEC_CTRL1E 0x3a1e #define OV5640_REG_AEC_CTRL1F 0x3a1f #define OV5640_REG_HZ5060_CTRL00 0x3c00 #define OV5640_REG_HZ5060_CTRL01 0x3c01 #define OV5640_REG_SIGMADELTA_CTRL0C 0x3c0c #define OV5640_REG_FRAME_CTRL01 0x4202 #define OV5640_REG_FORMAT_CONTROL00 0x4300 #define OV5640_REG_CCIR656_CONTROL00 0x4730 #define OV5640_REG_POLARITY_CTRL00 0x4740 #define OV5640_REG_MIPI_CTRL00 0x4800 #define OV5640_REG_DEBUG_MODE 0x4814 #define OV5640_REG_ISP_FORMAT_MUX_CTRL 0x501f #define OV5640_REG_PRE_ISP_TEST_SET1 0x503d #define OV5640_REG_SDE_CTRL0 0x5580 #define OV5640_REG_SDE_CTRL1 0x5581 #define OV5640_REG_SDE_CTRL3 0x5583 #define OV5640_REG_SDE_CTRL4 0x5584 #define OV5640_REG_SDE_CTRL5 0x5585 #define OV5640_REG_AVG_READOUT 0x56a1 #define OV5640_SCLK2X_ROOT_DIVIDER_DEFAULT 1 #define OV5640_SCLK_ROOT_DIVIDER_DEFAULT 2 /* enum ov5640_mode_id { OV5640_MODE_QCIF_176_144 = 0, OV5640_MODE_QVGA_320_240, OV5640_MODE_VGA_640_480, OV5640_MODE_NTSC_720_480, OV5640_MODE_PAL_720_576, OV5640_MODE_XGA_1024_768, OV5640_MODE_720P_1280_720, OV5640_MODE_1080P_1920_1080, OV5640_MODE_QSXGA_2592_1944, OV5640_NUM_MODES, }; enum ov5640_frame_rate { OV5640_15_FPS = 0, OV5640_30_FPS, OV5640_45_FPS, OV5640_60_FPS, OV5640_NUM_FRAMERATES, }; */ static int ov5640_exit(struct vdev_device *vdev); struct ov5640_pixfmt { uint32_t code; uint32_t colorspace; }; static const struct ov5640_pixfmt ov5640_formats[] = { { VDEV_MBUS_FMT_JPEG, VDEV_COLORSPACE_JPEG, }, { VDEV_MBUS_FMT_UYVY, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_YUYV, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_UYVYSP, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_YUYVSP, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_YUV444, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_YUV420SP, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_YUV420XP, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_RGB565, VDEV_COLORSPACE_SRGB, }, { VDEV_MBUS_FMT_RGB565X, VDEV_COLORSPACE_SRGB, }, }; /* * FIXME: remove this when a subdev API becomes available * to set the MIPI CSI-2 virtual channel. */ static unsigned int virtual_channel; static const int ov5640_framerates[] = { [OV5640_15_FPS] = 15, [OV5640_30_FPS] = 30, [OV5640_45_FPS] = 45, [OV5640_60_FPS] = 60, }; /* * Image size under 1280 * 960 are SUBSAMPLING * Image size upper 1280 * 960 are SCALING */ enum ov5640_downsize_mode { SUBSAMPLING, SCALING, NONMODING = -1, }; struct reg_value { uint16_t reg_addr; uint8_t val; uint8_t mask; uint32_t delay_ms; }; struct ov5640_mode_info { enum ov5640_mode_id id; enum ov5640_downsize_mode dn_mode; uint32_t hact; uint32_t htot; uint32_t vact; uint32_t vtot; const struct reg_value *reg_data; uint32_t reg_data_size; }; struct ov5640_ctrls { bool auto_exp; int exposure; bool auto_wb; int blue_balance; int red_balance; bool auto_gain; int gain; int brightness; int light_freq; int saturation; int contrast; int hue; int test_pattern; int hflip; int vflip; }; struct i2c_client { uint16_t flags; uint16_t addr; uint16_t adapter; }; struct ov5640_dev { void *adap; uint32_t gpio_pwn; uint32_t gpio_reset; struct i2c_client i2c_client; struct vdev_device vdev; uint32_t xclk_freq; bool upside_down; /* lock to protect all members below */ osMutexId_t lock; int power_count; struct vdev_mbus_framefmt fmt; bool pending_fmt_change; const struct ov5640_mode_info *current_mode; const struct ov5640_mode_info *last_mode; enum ov5640_frame_rate current_fr; struct ov5640_ctrls ctrls; uint32_t prev_sysclk, prev_hts; uint32_t ae_low, ae_high, ae_target; bool pending_mode_change; bool streaming; }; static inline struct ov5640_dev *to_ov5640_dev(struct vdev_device *vdev) { return containerof(vdev, struct ov5640_dev, vdev); } /* * FIXME: all of these register tables are likely filled with * entries that set the register to their power-on default values, * and which are otherwise not touched by this driver. Those entries * should be identified and removed to speed register load time * over i2c. */ /* YUV422 UYVY VGA@30fps */ static const struct reg_value ov5640_init_setting_30fps_VGA[] = { {0x3103, 0x11, 0, 0}, {0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0}, {0x3103, 0x03, 0, 0}, {0x3017, 0x00, 0, 0}, {0x3018, 0x00, 0, 0}, {0x3034, 0x18, 0, 0}, {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3037, 0x13, 0, 0}, {0x3630, 0x36, 0, 0}, {0x3631, 0x0e, 0, 0}, {0x3632, 0xe2, 0, 0}, {0x3633, 0x12, 0, 0}, {0x3621, 0xe0, 0, 0}, {0x3704, 0xa0, 0, 0}, {0x3703, 0x5a, 0, 0}, {0x3715, 0x78, 0, 0}, {0x3717, 0x01, 0, 0}, {0x370b, 0x60, 0, 0}, {0x3705, 0x1a, 0, 0}, {0x3905, 0x02, 0, 0}, {0x3906, 0x10, 0, 0}, {0x3901, 0x0a, 0, 0}, {0x3731, 0x12, 0, 0}, {0x3600, 0x08, 0, 0}, {0x3601, 0x33, 0, 0}, {0x302d, 0x60, 0, 0}, {0x3620, 0x52, 0, 0}, {0x371b, 0x20, 0, 0}, {0x471c, 0x50, 0, 0}, {0x3a13, 0x43, 0, 0}, {0x3a18, 0x00, 0, 0}, {0x3a19, 0xf8, 0, 0}, {0x3635, 0x13, 0, 0}, {0x3636, 0x03, 0, 0}, {0x3634, 0x40, 0, 0}, {0x3622, 0x01, 0, 0}, {0x3c01, 0xa4, 0, 0}, {0x3c04, 0x28, 0, 0}, {0x3c05, 0x98, 0, 0}, {0x3c06, 0x00, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c08, 0x00, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x3000, 0x00, 0, 0}, {0x3002, 0x1c, 0, 0}, {0x3004, 0xff, 0, 0}, {0x3006, 0xc3, 0, 0}, {0x302e, 0x08, 0, 0}, {0x4300, 0x3f, 0, 0}, {0x501f, 0x00, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x440e, 0x00, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x4837, 0x0a, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5000, 0xa7, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x5180, 0xff, 0, 0}, {0x5181, 0xf2, 0, 0}, {0x5182, 0x00, 0, 0}, {0x5183, 0x14, 0, 0}, {0x5184, 0x25, 0, 0}, {0x5185, 0x24, 0, 0}, {0x5186, 0x09, 0, 0}, {0x5187, 0x09, 0, 0}, {0x5188, 0x09, 0, 0}, {0x5189, 0x88, 0, 0}, {0x518a, 0x54, 0, 0}, {0x518b, 0xee, 0, 0}, {0x518c, 0xb2, 0, 0}, {0x518d, 0x50, 0, 0}, {0x518e, 0x34, 0, 0}, {0x518f, 0x6b, 0, 0}, {0x5190, 0x46, 0, 0}, {0x5191, 0xf8, 0, 0}, {0x5192, 0x04, 0, 0}, {0x5193, 0x70, 0, 0}, {0x5194, 0xf0, 0, 0}, {0x5195, 0xf0, 0, 0}, {0x5196, 0x03, 0, 0}, {0x5197, 0x01, 0, 0}, {0x5198, 0x04, 0, 0}, {0x5199, 0x6c, 0, 0}, {0x519a, 0x04, 0, 0}, {0x519b, 0x00, 0, 0}, {0x519c, 0x09, 0, 0}, {0x519d, 0x2b, 0, 0}, {0x519e, 0x38, 0, 0}, {0x5381, 0x1e, 0, 0}, {0x5382, 0x5b, 0, 0}, {0x5383, 0x08, 0, 0}, {0x5384, 0x0a, 0, 0}, {0x5385, 0x7e, 0, 0}, {0x5386, 0x88, 0, 0}, {0x5387, 0x7c, 0, 0}, {0x5388, 0x6c, 0, 0}, {0x5389, 0x10, 0, 0}, {0x538a, 0x01, 0, 0}, {0x538b, 0x98, 0, 0}, {0x5300, 0x08, 0, 0}, {0x5301, 0x30, 0, 0}, {0x5302, 0x10, 0, 0}, {0x5303, 0x00, 0, 0}, {0x5304, 0x08, 0, 0}, {0x5305, 0x30, 0, 0}, {0x5306, 0x08, 0, 0}, {0x5307, 0x16, 0, 0}, {0x5309, 0x08, 0, 0}, {0x530a, 0x30, 0, 0}, {0x530b, 0x04, 0, 0}, {0x530c, 0x06, 0, 0}, {0x5480, 0x01, 0, 0}, {0x5481, 0x08, 0, 0}, {0x5482, 0x14, 0, 0}, {0x5483, 0x28, 0, 0}, {0x5484, 0x51, 0, 0}, {0x5485, 0x65, 0, 0}, {0x5486, 0x71, 0, 0}, {0x5487, 0x7d, 0, 0}, {0x5488, 0x87, 0, 0}, {0x5489, 0x91, 0, 0}, {0x548a, 0x9a, 0, 0}, {0x548b, 0xaa, 0, 0}, {0x548c, 0xb8, 0, 0}, {0x548d, 0xcd, 0, 0}, {0x548e, 0xdd, 0, 0}, {0x548f, 0xea, 0, 0}, {0x5490, 0x1d, 0, 0}, {0x5580, 0x02, 0, 0}, {0x5583, 0x40, 0, 0}, {0x5584, 0x10, 0, 0}, {0x5589, 0x10, 0, 0}, {0x558a, 0x00, 0, 0}, {0x558b, 0xf8, 0, 0}, {0x5800, 0x23, 0, 0}, {0x5801, 0x14, 0, 0}, {0x5802, 0x0f, 0, 0}, {0x5803, 0x0f, 0, 0}, {0x5804, 0x12, 0, 0}, {0x5805, 0x26, 0, 0}, {0x5806, 0x0c, 0, 0}, {0x5807, 0x08, 0, 0}, {0x5808, 0x05, 0, 0}, {0x5809, 0x05, 0, 0}, {0x580a, 0x08, 0, 0}, {0x580b, 0x0d, 0, 0}, {0x580c, 0x08, 0, 0}, {0x580d, 0x03, 0, 0}, {0x580e, 0x00, 0, 0}, {0x580f, 0x00, 0, 0}, {0x5810, 0x03, 0, 0}, {0x5811, 0x09, 0, 0}, {0x5812, 0x07, 0, 0}, {0x5813, 0x03, 0, 0}, {0x5814, 0x00, 0, 0}, {0x5815, 0x01, 0, 0}, {0x5816, 0x03, 0, 0}, {0x5817, 0x08, 0, 0}, {0x5818, 0x0d, 0, 0}, {0x5819, 0x08, 0, 0}, {0x581a, 0x05, 0, 0}, {0x581b, 0x06, 0, 0}, {0x581c, 0x08, 0, 0}, {0x581d, 0x0e, 0, 0}, {0x581e, 0x29, 0, 0}, {0x581f, 0x17, 0, 0}, {0x5820, 0x11, 0, 0}, {0x5821, 0x11, 0, 0}, {0x5822, 0x15, 0, 0}, {0x5823, 0x28, 0, 0}, {0x5824, 0x46, 0, 0}, {0x5825, 0x26, 0, 0}, {0x5826, 0x08, 0, 0}, {0x5827, 0x26, 0, 0}, {0x5828, 0x64, 0, 0}, {0x5829, 0x26, 0, 0}, {0x582a, 0x24, 0, 0}, {0x582b, 0x22, 0, 0}, {0x582c, 0x24, 0, 0}, {0x582d, 0x24, 0, 0}, {0x582e, 0x06, 0, 0}, {0x582f, 0x22, 0, 0}, {0x5830, 0x40, 0, 0}, {0x5831, 0x42, 0, 0}, {0x5832, 0x24, 0, 0}, {0x5833, 0x26, 0, 0}, {0x5834, 0x24, 0, 0}, {0x5835, 0x22, 0, 0}, {0x5836, 0x22, 0, 0}, {0x5837, 0x26, 0, 0}, {0x5838, 0x44, 0, 0}, {0x5839, 0x24, 0, 0}, {0x583a, 0x26, 0, 0}, {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, }; static const struct reg_value ov5640_setting_60fps_VGA_640_480[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x70, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, }; static const struct reg_value ov5640_setting_45fps_VGA_640_480[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_VGA_640_480[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_VGA_640_480[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_XGA_1024_768[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, {0x3035, 0x12, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_XGA_1024_768[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_60fps_QVGA_320_240[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x70, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_45fps_QVGA_320_240[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_QVGA_320_240[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_QVGA_320_240[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_60fps_QCIF_176_144[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x70, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_45fps_QCIF_176_144[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_QCIF_176_144[] = { {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_QCIF_176_144[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_60fps_NTSC_720_480[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x70, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_45fps_NTSC_720_480[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_NTSC_720_480[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_NTSC_720_480[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_60fps_PAL_720_576[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x70, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_45fps_PAL_720_576[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_PAL_720_576[] = { {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_PAL_720_576[] = { {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_720P_1280_720[] = { {0x3008, 0x42, 0, 0}, {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x06, 0, 0}, {0x3807, 0xa9, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x02, 0, 0}, {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0}, {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0}, {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_720P_1280_720[] = { {0x3035, 0x41, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x31, 0, 0}, {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x06, 0, 0}, {0x3807, 0xa9, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x02, 0, 0}, {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0}, {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0}, }; static const struct reg_value ov5640_setting_30fps_1080P_1920_1080[] = { {0x3008, 0x42, 0, 0}, {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x11, 0, 0}, {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0}, {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, {0x3035, 0x11, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0}, {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0}, {0x3806, 0x05, 0, 0}, {0x3807, 0xf1, 0, 0}, {0x3612, 0x2b, 0, 0}, {0x3708, 0x64, 0, 0}, {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x50, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x18, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0}, {0x3a15, 0x60, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0}, {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_1080P_1920_1080[] = { {0x3008, 0x42, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x5189, 0x72, 0, 0}, {0x3503, 0x00, 0, 0}, {0x5302, 0x30, 0, 0}, {0x5303, 0x10, 0, 0}, {0x5306, 0x10, 0, 0}, {0x5307, 0x20, 0, 0}, {0x3820, 0x40, 0, 0}, {0x3821, 0x06, 0, 0}, {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0}, {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0}, {0x3806, 0x05, 0, 0}, {0x3807, 0xf1, 0, 0}, {0x3808, 0x07, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x04, 0, 0}, {0x380b, 0x38, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, {0x3814, 0x11, 0, 0}, {0x3815, 0x11, 0, 0}, {0x3034, 0x18, 0, 0}, {0x3035, 0x41, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3037, 0x13, 0, 0}, {0x3108, 0x01, 0, 0}, {0x3824, 0x04, 0, 5}, {0x380c, 0x09, 0, 0}, {0x380d, 0xc4, 0, 0}, {0x380e, 0x04, 0, 0}, {0x380f, 0x60, 0, 0}, {0x3a08, 0x00, 0, 0}, {0x3a09, 0x70, 0, 0}, {0x3a0e, 0x0a, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0x5d, 0, 0}, {0x3a0d, 0x0c, 0, 0}, {0x3a00, 0x38, 0, 0}, {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a14, 0x17, 0, 0}, {0x3a15, 0x76, 0, 0}, {0x3618, 0x04, 0, 0}, {0x3612, 0x2b, 0, 0}, {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x4004, 0x06, 0, 0}, {0x3002, 0x1c, 0, 0}, {0x3006, 0xc3, 0, 0}, {0x5001, 0x83, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x4837, 0x0a, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3023, 0x01, 0, 0}, {0x3022, 0x04, 0, 0}, {0x302c, 0xc3, 0, 0}, }; static const struct reg_value ov5640_setting_15fps_QSXGA_2592_1944[] = { {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, {0x3814, 0x11, 0, 0}, {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0}, {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0}, {0x3810, 0x00, 0, 0}, {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0}, {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0}, {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 70}, }; /* power-on sensor init reg table */ static const struct ov5640_mode_info ov5640_mode_init_data = { (enum ov5640_mode_id)0, SUBSAMPLING, 640, 1896, 480, 984, ov5640_init_setting_30fps_VGA, ARRAY_SIZE(ov5640_init_setting_30fps_VGA), }; static const struct ov5640_mode_info ov5640_mode_data[OV5640_NUM_FRAMERATES][OV5640_NUM_MODES] = { { {OV5640_MODE_QCIF_176_144, SUBSAMPLING, 176, 1896, 144, 984, ov5640_setting_15fps_QCIF_176_144, ARRAY_SIZE(ov5640_setting_15fps_QCIF_176_144)}, {OV5640_MODE_QVGA_320_240, SUBSAMPLING, 320, 1896, 240, 984, ov5640_setting_15fps_QVGA_320_240, ARRAY_SIZE(ov5640_setting_15fps_QVGA_320_240)}, {OV5640_MODE_VGA_640_480, SUBSAMPLING, 640, 1896, 480, 1080, ov5640_setting_15fps_VGA_640_480, ARRAY_SIZE(ov5640_setting_15fps_VGA_640_480)}, {OV5640_MODE_NTSC_720_480, SUBSAMPLING, 720, 1896, 480, 984, ov5640_setting_15fps_NTSC_720_480, ARRAY_SIZE(ov5640_setting_15fps_NTSC_720_480)}, {OV5640_MODE_PAL_720_576, SUBSAMPLING, 720, 1896, 576, 984, ov5640_setting_15fps_PAL_720_576, ARRAY_SIZE(ov5640_setting_15fps_PAL_720_576)}, {OV5640_MODE_XGA_1024_768, SUBSAMPLING, 1024, 1896, 768, 1080, ov5640_setting_15fps_XGA_1024_768, ARRAY_SIZE(ov5640_setting_15fps_XGA_1024_768)}, {OV5640_MODE_720P_1280_720, SUBSAMPLING, 1280, 1892, 720, 740, ov5640_setting_15fps_720P_1280_720, ARRAY_SIZE(ov5640_setting_15fps_720P_1280_720)}, {OV5640_MODE_1080P_1920_1080, SCALING, 1920, 2500, 1080, 1120, ov5640_setting_15fps_1080P_1920_1080, ARRAY_SIZE(ov5640_setting_15fps_1080P_1920_1080)}, {OV5640_MODE_QSXGA_2592_1944, SCALING, 2592, 2844, 1944, 1968, ov5640_setting_15fps_QSXGA_2592_1944, ARRAY_SIZE(ov5640_setting_15fps_QSXGA_2592_1944)}, }, { {OV5640_MODE_QCIF_176_144, SUBSAMPLING, 176, 1896, 144, 984, ov5640_setting_30fps_QCIF_176_144, ARRAY_SIZE(ov5640_setting_30fps_QCIF_176_144)}, {OV5640_MODE_QVGA_320_240, SUBSAMPLING, 320, 1896, 240, 984, ov5640_setting_30fps_QVGA_320_240, ARRAY_SIZE(ov5640_setting_30fps_QVGA_320_240)}, {OV5640_MODE_VGA_640_480, SUBSAMPLING, 640, 1896, 480, 1080, ov5640_setting_30fps_VGA_640_480, ARRAY_SIZE(ov5640_setting_30fps_VGA_640_480)}, {OV5640_MODE_NTSC_720_480, SUBSAMPLING, 720, 1896, 480, 984, ov5640_setting_30fps_NTSC_720_480, ARRAY_SIZE(ov5640_setting_30fps_NTSC_720_480)}, {OV5640_MODE_PAL_720_576, SUBSAMPLING, 720, 1896, 576, 984, ov5640_setting_30fps_PAL_720_576, ARRAY_SIZE(ov5640_setting_30fps_PAL_720_576)}, {OV5640_MODE_XGA_1024_768, SUBSAMPLING, 1024, 1896, 768, 1080, ov5640_setting_30fps_XGA_1024_768, ARRAY_SIZE(ov5640_setting_30fps_XGA_1024_768)}, {OV5640_MODE_720P_1280_720, SUBSAMPLING, 1280, 1892, 720, 740, ov5640_setting_30fps_720P_1280_720, ARRAY_SIZE(ov5640_setting_30fps_720P_1280_720)}, {OV5640_MODE_1080P_1920_1080, SCALING, 1920, 2500, 1080, 1120, ov5640_setting_30fps_1080P_1920_1080, ARRAY_SIZE(ov5640_setting_30fps_1080P_1920_1080)}, {OV5640_MODE_QSXGA_2592_1944, NONMODING, 0, 0, 0, 0, NULL, 0}, }, { {OV5640_MODE_QCIF_176_144, SUBSAMPLING, 176, 1896, 144, 984, ov5640_setting_45fps_QCIF_176_144, ARRAY_SIZE(ov5640_setting_45fps_QCIF_176_144)}, {OV5640_MODE_QVGA_320_240, SUBSAMPLING, 320, 1896, 240, 984, ov5640_setting_45fps_QVGA_320_240, ARRAY_SIZE(ov5640_setting_45fps_QVGA_320_240)}, {OV5640_MODE_VGA_640_480, SUBSAMPLING, 640, 1896, 480, 1080, ov5640_setting_45fps_VGA_640_480, ARRAY_SIZE(ov5640_setting_45fps_VGA_640_480)}, {OV5640_MODE_NTSC_720_480, SUBSAMPLING, 720, 1896, 480, 984, ov5640_setting_45fps_NTSC_720_480, ARRAY_SIZE(ov5640_setting_45fps_NTSC_720_480)}, {OV5640_MODE_PAL_720_576, SUBSAMPLING, 720, 1896, 576, 984, ov5640_setting_45fps_PAL_720_576, ARRAY_SIZE(ov5640_setting_45fps_PAL_720_576)}, {OV5640_MODE_XGA_1024_768, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_720P_1280_720, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_1080P_1920_1080, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_QSXGA_2592_1944, NONMODING, 0, 0, 0, 0, NULL, 0}, }, { {OV5640_MODE_QCIF_176_144, SUBSAMPLING, 176, 1896, 144, 984, ov5640_setting_60fps_QCIF_176_144, ARRAY_SIZE(ov5640_setting_60fps_QCIF_176_144)}, {OV5640_MODE_QVGA_320_240, SUBSAMPLING, 320, 1896, 240, 984, ov5640_setting_60fps_QVGA_320_240, ARRAY_SIZE(ov5640_setting_60fps_QVGA_320_240)}, {OV5640_MODE_VGA_640_480, SUBSAMPLING, 640, 1896, 480, 1080, ov5640_setting_60fps_VGA_640_480, ARRAY_SIZE(ov5640_setting_60fps_VGA_640_480)}, {OV5640_MODE_NTSC_720_480, SUBSAMPLING, 720, 1896, 480, 984, ov5640_setting_60fps_NTSC_720_480, ARRAY_SIZE(ov5640_setting_60fps_NTSC_720_480)}, {OV5640_MODE_PAL_720_576, SUBSAMPLING, 720, 1896, 576, 984, ov5640_setting_60fps_PAL_720_576, ARRAY_SIZE(ov5640_setting_60fps_PAL_720_576)}, {OV5640_MODE_XGA_1024_768, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_720P_1280_720, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_1080P_1920_1080, NONMODING, 0, 0, 0, 0, NULL, 0}, {OV5640_MODE_QSXGA_2592_1944, NONMODING, 0, 0, 0, 0, NULL, 0}, }, }; static int ov5640_init_slave_id(struct ov5640_dev *sensor) { struct i2c_client *client = &sensor->i2c_client; uint8_t buf[3]; bool ret; sensor_debug("%s\n", __func__); client->addr = OV5640_DEFAULT_SLAVE_ID; if (client->addr == OV5640_DEFAULT_SLAVE_ID) return 0; printf("%s: client->addr=0x%x\n", __func__, client->addr); client->addr = OV5640_DEFAULT_SLAVE_ID; buf[0] = OV5640_REG_SLAVE_ID >> 8; buf[1] = OV5640_REG_SLAVE_ID & 0xff; buf[2] = client->addr << 1; ret = i2c_write(sensor->adap, OV5640_DEFAULT_SLAVE_ID, buf, 3); if (!ret) { printf("%s: failed with %d\n", __func__, ret); return ret; } return 0; } static int ov5640_write_reg(struct ov5640_dev *sensor, uint16_t reg, uint8_t val) { uint8_t buf[3]; int ret; if (g_load_regs == 0) sensor_debug("ov5640_write_reg: reg=0x%04x, val=0x%02x\n", reg, val); buf[0] = reg >> 8; buf[1] = reg & 0xff; buf[2] = val; ret = i2c_write(sensor->adap, OV5640_DEFAULT_SLAVE_ID, buf, 3); if (ret < 0) { printf("%s: error: reg=%x, val=%x\n", __func__, reg, val); return ret; } return 0; } static int ov5640_read_reg(struct ov5640_dev *sensor, uint16_t reg16, uint8_t *val) { uint8_t buf[2], reg[2]; int ret; reg[0] = reg16 >> 8; reg[1] = reg16 & 0xff; memset(buf, 0, sizeof(buf)); ret = i2c_write_read(sensor->adap, OV5640_DEFAULT_SLAVE_ID, reg, 2, buf, 1); if (ret < 0) { printf("%s: error: read reg=%x\n", __func__, reg16); return ret; } if (g_load_regs == 0) sensor_debug("ov5640_read_reg: reg=0x%04x, val=0x%02x\n", reg16, buf[0]); *val = buf[0]; return 0; } static int ov5640_read_reg16(struct ov5640_dev *sensor, uint16_t reg, uint16_t *val) { uint8_t hi, lo; int ret; g_load_regs = 1; ret = ov5640_read_reg(sensor, reg, &hi); if (ret) return ret; ret = ov5640_read_reg(sensor, reg + 1, &lo); if (ret) return ret; *val = ((uint16_t)hi << 8) | (uint16_t)lo; g_load_regs = 0; sensor_debug("ov5640_read_reg16: reg=0x%04x, val=0x%04x\n", reg, *val); return 0; } static int ov5640_write_reg16(struct ov5640_dev *sensor, uint16_t reg, uint16_t val) { int ret; g_load_regs = 1; ret = ov5640_write_reg(sensor, reg, val >> 8); if (ret) return ret; // return ov5640_write_reg(sensor, reg + 1, val & 0xff); ret = ov5640_write_reg(sensor, reg + 1, val & 0xff); g_load_regs = 0; sensor_debug("ov5640_write_reg16: reg=0x%04x, val=0x%04x\n", reg, val); return ret; } static int ov5640_mod_reg(struct ov5640_dev *sensor, uint16_t reg, uint8_t mask, uint8_t val) { uint8_t readval; int ret; int bypass = g_load_regs; if (bypass == 0) sensor_debug("ov5640_mod_reg: reg=0x%04x, mask=0x%02x, val=0x%02x\n", reg, mask, val); g_load_regs = 1; ret = ov5640_read_reg(sensor, reg, &readval); if (ret) return ret; readval &= ~mask; val &= mask; val |= readval; // return ov5640_write_reg(sensor, reg, val); ret = ov5640_write_reg(sensor, reg, val); g_load_regs = bypass; return ret; } /* download ov5640 settings to sensor through i2c */ static int ov5640_set_timings(struct ov5640_dev *sensor, const struct ov5640_mode_info *mode) { int ret; sensor_debug("%s\n", __func__); ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->hact); if (ret < 0) return ret; ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPVO, mode->vact); if (ret < 0) return ret; ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_HTS, mode->htot); if (ret < 0) return ret; return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, mode->vtot); } static int ov5640_load_regs(struct ov5640_dev *sensor, const struct ov5640_mode_info *mode) { const struct reg_value *regs = mode->reg_data; unsigned int i; uint32_t delay_ms; uint16_t reg_addr; uint8_t mask, val; int ret = 0; sensor_debug("%s, mode_id %d\n", __func__, mode->id); sensor_debug("init=0x%08x, base=0x%08x, cur=0x%08x\n", (uint32_t)&ov5640_mode_init_data, (uint32_t)&ov5640_mode_data[0][0], (uint32_t)mode); if ((uint32_t)mode > (uint32_t)&ov5640_mode_data[0][0]) { uint32_t offset, total; offset = ((uint32_t)mode - (uint32_t)&ov5640_mode_data[0][0]) / (uint32_t)sizeof(struct ov5640_mode_info); total = (uint32_t)sizeof(ov5640_mode_data) / (uint32_t)sizeof(struct ov5640_mode_info); sensor_debug("%s, offset = %d, total = %d\n", __func__, offset, total); } g_load_regs = 1; for (i = 0; i < mode->reg_data_size; ++i, ++regs) { delay_ms = regs->delay_ms; reg_addr = regs->reg_addr; val = regs->val; mask = regs->mask; if (mask) ret = ov5640_mod_reg(sensor, reg_addr, mask, val); else ret = ov5640_write_reg(sensor, reg_addr, val); if (ret) break; if (delay_ms) mdelay(10 * delay_ms); } g_load_regs = 0; return ov5640_set_timings(sensor, mode); } static int ov5640_set_autoexposure(struct ov5640_dev *sensor, bool on) { sensor_debug("%s\n", __func__); return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, BIT(0), on ? 0 : BIT(0)); } /* read exposure, in number of line periods */ static int ov5640_get_exposure(struct ov5640_dev *sensor) { int exp, ret; uint8_t temp; sensor_debug("%s\n", __func__); ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_HI, &temp); if (ret) return ret; exp = ((int)temp & 0x0f) << 16; ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_MED, &temp); if (ret) return ret; exp |= ((int)temp << 8); ret = ov5640_read_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_LO, &temp); if (ret) return ret; exp |= (int)temp; return exp >> 4; } /* write exposure, given number of line periods */ static int ov5640_set_exposure(struct ov5640_dev *sensor, uint32_t exposure) { int ret; exposure <<= 4; sensor_debug("%s\n", __func__); ret = ov5640_write_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_LO, exposure & 0xff); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_MED, (exposure >> 8) & 0xff); if (ret) return ret; return ov5640_write_reg(sensor, OV5640_REG_AEC_PK_EXPOSURE_HI, (exposure >> 16) & 0x0f); } static int ov5640_get_gain(struct ov5640_dev *sensor) { uint16_t gain; int ret; ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, &gain); if (ret) return ret; return gain & 0x3ff; } static int ov5640_set_gain(struct ov5640_dev *sensor, int gain) { return ov5640_write_reg16(sensor, OV5640_REG_AEC_PK_REAL_GAIN, (uint16_t)gain & 0x3ff); } static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) { return ov5640_mod_reg(sensor, OV5640_REG_AEC_PK_MANUAL, BIT(1), on ? 0 : BIT(1)); } static int ov5640_set_stream_dvp(struct ov5640_dev *sensor, bool on) { int ret; unsigned int flags = sensor->vdev.ep.flags; uint8_t pclk_pol = 0; uint8_t hsync_pol = 0; uint8_t vsync_pol = 0; sensor_debug("%s\n", __func__); /* * Note about parallel port configuration. * * When configured in parallel mode, the OV5640 will * output 10 bits data on DVP data lines [9:0]. * If only 8 bits data are wanted, the 8 bits data lines * of the camera interface must be physically connected * on the DVP data lines [9:2]. * * Control lines polarity can be configured through * devicetree endpoint control lines properties. * If no endpoint control lines properties are set, * polarity will be as below: * - VSYNC: active high * - HREF: active low * - PCLK: active low */ if (on) { /* * reset MIPI PCLK/SERCLK divider * * SC PLL CONTRL1 0 * - [3..0]: MIPI PCLK/SERCLK divider */ ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, 0x0f, 0); if (ret) return ret; /* * configure parallel port control lines polarity * * POLARITY CTRL0 * - [5]: PCLK polarity (0: active low, 1: active high) * - [1]: HREF polarity (0: active low, 1: active high) * - [0]: VSYNC polarity (mismatch here between * datasheet and hardware, 0 is active high * and 1 is active low...) */ if (flags & VDEV_MBUS_PCLK_SAMPLE_RISING) pclk_pol = 1; if (flags & VDEV_MBUS_HSYNC_ACTIVE_HIGH) hsync_pol = 1; if (flags & VDEV_MBUS_VSYNC_ACTIVE_LOW) vsync_pol = 1; sensor_info("%s: pclk_pol %d hsync_pol %d vsync_pol %d\n", __func__, pclk_pol, hsync_pol, vsync_pol); ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, (pclk_pol << 5) | (hsync_pol << 1) | vsync_pol); if (ret) return ret; } /* * powerdown MIPI TX/RX PHY & disable MIPI * * MIPI CONTROL 00 * 4: PWDN PHY TX * 3: PWDN PHY RX * 2: MIPI enable */ ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, on ? 0x18 : 0); if (ret) return ret; /* * enable VSYNC/HREF/PCLK DVP control lines * & D[9:6] DVP data lines * * PAD OUTPUT ENABLE 01 * - 6: VSYNC output enable * - 5: HREF output enable * - 4: PCLK output enable * - [3:0]: D[9:6] output enable */ ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, on ? 0x7f : 0); if (ret) return ret; /* * enable D[5:0] DVP data lines * * PAD OUTPUT ENABLE 02 * - [7:2]: D[5:0] output enable */ return ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, on ? 0xfc : 0); } static int ov5640_set_stream_mipi(struct ov5640_dev *sensor, bool on) { int ret; sensor_debug("%s\n", __func__); /* * Enable/disable the MIPI interface * * 0x300e = on ? 0x45 : 0x40 * * FIXME: the sensor manual (version 2.03) reports * [7:5] = 000 : 1 data lane mode * [7:5] = 001 : 2 data lanes mode * But this settings do not work, while the following ones * have been validated for 2 data lanes mode. * * [7:5] = 010 : 2 data lanes mode * [4] = 0 : Power up MIPI HS Tx * [3] = 0 : Power up MIPI LS Rx * [2] = 1/0 : MIPI interface enable/disable * [1:0] = 01/00: FIXME: 'debug' */ ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, on ? 0x45 : 0x40); if (ret) return ret; return ov5640_write_reg(sensor, OV5640_REG_FRAME_CTRL01, on ? 0x00 : 0x0f); } static int ov5640_get_sysclk(struct ov5640_dev *sensor) { /* calculate sysclk */ uint32_t xvclk = sensor->xclk_freq / 10000; uint32_t multiplier, prediv, VCO, sysdiv, pll_rdiv; uint32_t sclk_rdiv_map[] = {1, 2, 4, 8}; uint32_t bit_div2x = 1, sclk_rdiv, sysclk; uint8_t temp1, temp2; int ret; sensor_debug("%s\n", __func__); ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL0, &temp1); if (ret) return ret; temp2 = temp1 & 0x0f; if (temp2 == 8 || temp2 == 10) bit_div2x = temp2 / 2; ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL1, &temp1); if (ret) return ret; sysdiv = temp1 >> 4; if (sysdiv == 0) sysdiv = 16; ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL2, &temp1); if (ret) return ret; multiplier = temp1; ret = ov5640_read_reg(sensor, OV5640_REG_SC_PLL_CTRL3, &temp1); if (ret) return ret; prediv = temp1 & 0x0f; pll_rdiv = ((temp1 >> 4) & 0x01) + 1; ret = ov5640_read_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, &temp1); if (ret) return ret; temp2 = temp1 & 0x03; sclk_rdiv = sclk_rdiv_map[temp2]; if (!prediv || !sysdiv || !pll_rdiv || !bit_div2x) return -EINVAL; VCO = xvclk * multiplier / prediv; sysclk = VCO / sysdiv / pll_rdiv * 2 / bit_div2x / sclk_rdiv; return sysclk; } static int ov5640_set_night_mode(struct ov5640_dev *sensor) { /* read HTS from register settings */ uint8_t mode; int ret; sensor_debug("%s\n", __func__); ret = ov5640_read_reg(sensor, OV5640_REG_AEC_CTRL00, &mode); if (ret) return ret; mode &= 0xfb; return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL00, mode); } static int ov5640_get_hts(struct ov5640_dev *sensor) { /* read HTS from register settings */ uint16_t hts; int ret; sensor_debug("%s\n", __func__); ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_HTS, &hts); if (ret) return ret; return hts; } static int ov5640_get_vts(struct ov5640_dev *sensor) { uint16_t vts; int ret; sensor_debug("%s\n", __func__); ret = ov5640_read_reg16(sensor, OV5640_REG_TIMING_VTS, &vts); if (ret) return ret; return vts; } static int ov5640_set_vts(struct ov5640_dev *sensor, int vts) { return ov5640_write_reg16(sensor, OV5640_REG_TIMING_VTS, vts); } static int ov5640_get_light_freq(struct ov5640_dev *sensor) { /* get banding filter value */ int ret, light_freq = 0; uint8_t temp, temp1; sensor_debug("%s\n", __func__); ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL01, &temp); if (ret) return ret; if (temp & 0x80) { /* manual */ ret = ov5640_read_reg(sensor, OV5640_REG_HZ5060_CTRL00, &temp1); if (ret) return ret; if (temp1 & 0x04) { /* 50Hz */ light_freq = 50; } else { /* 60Hz */ light_freq = 60; } } else { /* auto */ ret = ov5640_read_reg(sensor, OV5640_REG_SIGMADELTA_CTRL0C, &temp1); if (ret) return ret; if (temp1 & 0x01) { /* 50Hz */ light_freq = 50; } else { /* 60Hz */ } } return light_freq; } static int ov5640_set_bandingfilter(struct ov5640_dev *sensor) { uint32_t band_step60, max_band60, band_step50, max_band50, prev_vts; int ret; sensor_debug("%s\n", __func__); /* read preview PCLK */ ret = ov5640_get_sysclk(sensor); if (ret < 0) return ret; if (ret == 0) return -EINVAL; sensor->prev_sysclk = ret; printf("pclk = %d\n", ret); /* read preview HTS */ ret = ov5640_get_hts(sensor); if (ret < 0) return ret; if (ret == 0) return -EINVAL; sensor->prev_hts = ret; /* read preview VTS */ ret = ov5640_get_vts(sensor); if (ret < 0) return ret; prev_vts = ret; /* calculate banding filter */ /* 60Hz */ band_step60 = sensor->prev_sysclk * 100 / sensor->prev_hts * 100 / 120; ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B60_STEP, band_step60); if (ret) return ret; if (!band_step60) return -EINVAL; max_band60 = (int)((prev_vts - 4) / band_step60); ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0D, max_band60); if (ret) return ret; /* 50Hz */ band_step50 = sensor->prev_sysclk * 100 / sensor->prev_hts; ret = ov5640_write_reg16(sensor, OV5640_REG_AEC_B50_STEP, band_step50); if (ret) return ret; if (!band_step50) return -EINVAL; max_band50 = (int)((prev_vts - 4) / band_step50); return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0E, max_band50); } static int ov5640_set_ae_target(struct ov5640_dev *sensor, int target) { /* stable in high */ uint32_t fast_high, fast_low; int ret; sensor_debug("%s\n", __func__); sensor->ae_low = target * 23 / 25; /* 0.92 */ sensor->ae_high = target * 27 / 25; /* 1.08 */ fast_high = sensor->ae_high << 1; if (fast_high > 255) fast_high = 255; fast_low = sensor->ae_low >> 1; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL0F, sensor->ae_high); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL10, sensor->ae_low); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1B, sensor->ae_high); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1E, sensor->ae_low); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL11, fast_high); if (ret) return ret; return ov5640_write_reg(sensor, OV5640_REG_AEC_CTRL1F, fast_low); } static int ov5640_get_binning(struct ov5640_dev *sensor) { uint8_t temp; int ret; sensor_debug("%s\n", __func__); ret = ov5640_read_reg(sensor, OV5640_REG_TIMING_TC_REG21, &temp); if (ret) return ret; return temp & BIT(0); } static int ov5640_set_binning(struct ov5640_dev *sensor, bool enable) { int ret; sensor_debug("%s\n", __func__); /* * TIMING TC REG21: * - [0]: Horizontal binning enable */ ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, BIT(0), enable ? BIT(0) : 0); if (ret) return ret; /* * TIMING TC REG20: * - [0]: Undocumented, but hardcoded init sequences * are always setting REG21/REG20 bit 0 to same value... */ return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, BIT(0), enable ? BIT(0) : 0); } static int ov5640_set_virtual_channel(struct ov5640_dev *sensor) { uint8_t temp, channel = virtual_channel; int ret; sensor_debug("%s\n", __func__); if (channel > 3) { printf("%s: wrong virtual_channel parameter, expected (0..3), got %d\n", __func__, channel); return -EINVAL; } ret = ov5640_read_reg(sensor, OV5640_REG_DEBUG_MODE, &temp); if (ret) return ret; temp &= ~(3 << 6); temp |= (channel << 6); return ov5640_write_reg(sensor, OV5640_REG_DEBUG_MODE, temp); } static const struct ov5640_mode_info * ov5640_find_mode(struct ov5640_dev *sensor, enum ov5640_frame_rate fr, uint32_t width, uint32_t height, bool nearest) { const struct ov5640_mode_info *mode; sensor_debug("%s\n", __func__); // mode = (struct ov5640_mode_info *)vdev_find_nearest_size(ov5640_mode_data[fr], // ARRAY_SIZE(ov5640_mode_data[fr]), hact, vact, // width, height); mode = (struct ov5640_mode_info *)__vdev_find_nearest_size(ov5640_mode_data[fr], ARRAY_SIZE(ov5640_mode_data[fr]), sizeof(*(ov5640_mode_data[fr])), (size_t)&(((struct ov5640_mode_info *)0)->hact), (size_t)&(((struct ov5640_mode_info *)0)->vact), width, height); if (!mode || (!nearest && (mode->hact != width || mode->vact != height))) return NULL; return mode; } /* * sensor changes between scaling and subsampling, go through * exposure calculation */ static int ov5640_set_mode_exposure_calc(struct ov5640_dev *sensor, const struct ov5640_mode_info *mode) { uint32_t prev_shutter, prev_gain16; uint32_t cap_shutter, cap_gain16; uint32_t cap_sysclk, cap_hts, cap_vts; uint32_t light_freq, cap_bandfilt, cap_maxband; uint32_t cap_gain16_shutter; uint8_t average; int ret; if (!mode->reg_data) return -EINVAL; sensor_debug("%s\n", __func__); /* read preview shutter */ ret = ov5640_get_exposure(sensor); if (ret < 0) return ret; prev_shutter = ret; ret = ov5640_get_binning(sensor); if (ret < 0) return ret; if (ret && mode->id != OV5640_MODE_720P_1280_720 && mode->id != OV5640_MODE_1080P_1920_1080) prev_shutter *= 2; /* read preview gain */ ret = ov5640_get_gain(sensor); if (ret < 0) return ret; prev_gain16 = ret; /* get average */ ret = ov5640_read_reg(sensor, OV5640_REG_AVG_READOUT, &average); if (ret) return ret; /* turn off night mode for capture */ ret = ov5640_set_night_mode(sensor); if (ret < 0) return ret; /* Write capture setting */ ret = ov5640_load_regs(sensor, mode); if (ret < 0) return ret; /* read capture VTS */ ret = ov5640_get_vts(sensor); if (ret < 0) return ret; cap_vts = ret; ret = ov5640_get_hts(sensor); if (ret < 0) return ret; if (ret == 0) return -EINVAL; cap_hts = ret; ret = ov5640_get_sysclk(sensor); if (ret < 0) return ret; if (ret == 0) return -EINVAL; cap_sysclk = ret; /* calculate capture banding filter */ ret = ov5640_get_light_freq(sensor); if (ret < 0) return ret; light_freq = ret; if (light_freq == 60) { /* 60Hz */ cap_bandfilt = cap_sysclk * 100 / cap_hts * 100 / 120; } else { /* 50Hz */ cap_bandfilt = cap_sysclk * 100 / cap_hts; } if (!sensor->prev_sysclk) { ret = ov5640_get_sysclk(sensor); if (ret < 0) return ret; if (ret == 0) return -EINVAL; sensor->prev_sysclk = ret; } if (!cap_bandfilt) return -EINVAL; cap_maxband = (int)((cap_vts - 4) / cap_bandfilt); /* calculate capture shutter/gain16 */ if (average > sensor->ae_low && average < sensor->ae_high) { /* in stable range */ cap_gain16_shutter = prev_gain16 * prev_shutter * cap_sysclk / sensor->prev_sysclk * sensor->prev_hts / cap_hts * sensor->ae_target / average; } else { cap_gain16_shutter = prev_gain16 * prev_shutter * cap_sysclk / sensor->prev_sysclk * sensor->prev_hts / cap_hts; } /* gain to shutter */ if (cap_gain16_shutter < (cap_bandfilt * 16)) { /* shutter < 1/100 */ cap_shutter = cap_gain16_shutter / 16; if (cap_shutter < 1) cap_shutter = 1; cap_gain16 = cap_gain16_shutter / cap_shutter; if (cap_gain16 < 16) cap_gain16 = 16; } else { if (cap_gain16_shutter > (cap_bandfilt * cap_maxband * 16)) { /* exposure reach max */ cap_shutter = cap_bandfilt * cap_maxband; if (!cap_shutter) return -EINVAL; cap_gain16 = cap_gain16_shutter / cap_shutter; } else { /* 1/100 < (cap_shutter = n/100) =< max */ cap_shutter = ((int)(cap_gain16_shutter / 16 / cap_bandfilt)) * cap_bandfilt; if (!cap_shutter) return -EINVAL; cap_gain16 = cap_gain16_shutter / cap_shutter; } } /* set capture gain */ ret = ov5640_set_gain(sensor, cap_gain16); if (ret) return ret; /* write capture shutter */ if (cap_shutter > (cap_vts - 4)) { cap_vts = cap_shutter + 4; ret = ov5640_set_vts(sensor, cap_vts); if (ret < 0) return ret; } /* set exposure */ return ov5640_set_exposure(sensor, cap_shutter); } /* * if sensor changes inside scaling or subsampling * change mode directly */ static int ov5640_set_mode_direct(struct ov5640_dev *sensor, const struct ov5640_mode_info *mode) { if (!mode->reg_data) return -EINVAL; sensor_debug("%s\n", __func__); /* Write capture setting */ return ov5640_load_regs(sensor, mode); } static int ov5640_set_mode(struct ov5640_dev *sensor) { const struct ov5640_mode_info *mode = sensor->current_mode; const struct ov5640_mode_info *orig_mode = sensor->last_mode; enum ov5640_downsize_mode dn_mode, orig_dn_mode; bool auto_gain = sensor->ctrls.auto_gain == 1; bool auto_exp = sensor->ctrls.auto_exp == 1; int ret; dn_mode = mode->dn_mode; orig_dn_mode = orig_mode->dn_mode; sensor_debug("%s, dn_mode %d, orig %d\n", __func__, dn_mode, orig_dn_mode); /* auto gain and exposure must be turned off when changing modes */ if (auto_gain) { ret = ov5640_set_autogain(sensor, false); if (ret) return ret; } if (auto_exp) { ret = ov5640_set_autoexposure(sensor, false); if (ret) goto restore_auto_gain; } if ((dn_mode == SUBSAMPLING && orig_dn_mode == SCALING) || (dn_mode == SCALING && orig_dn_mode == SUBSAMPLING)) { /* * change between subsampling and scaling * go through exposure calculation */ ret = ov5640_set_mode_exposure_calc(sensor, mode); } else { /* * change inside subsampling or scaling * download firmware directly */ ret = ov5640_set_mode_direct(sensor, mode); } if (ret < 0) goto restore_auto_exp_gain; /* restore auto gain and exposure */ if (auto_gain) ov5640_set_autogain(sensor, true); if (auto_exp) ov5640_set_autoexposure(sensor, true); ret = ov5640_set_binning(sensor, dn_mode != SCALING); if (ret < 0) return ret; ret = ov5640_set_ae_target(sensor, sensor->ae_target); if (ret < 0) return ret; ret = ov5640_get_light_freq(sensor); if (ret < 0) return ret; ret = ov5640_set_bandingfilter(sensor); if (ret < 0) return ret; ret = ov5640_set_virtual_channel(sensor); if (ret < 0) return ret; sensor->pending_mode_change = false; sensor->last_mode = mode; return 0; restore_auto_exp_gain: if (auto_exp) ov5640_set_autoexposure(sensor, true); restore_auto_gain: if (auto_gain) ov5640_set_autogain(sensor, true); return ret; } static int ov5640_set_framefmt(struct ov5640_dev *sensor, struct vdev_mbus_framefmt *format); /* restore the last set video mode after chip power-on */ static int ov5640_restore_mode(struct ov5640_dev *sensor) { int ret; sensor_debug("%s\n", __func__); /* first load the initial register values */ ret = ov5640_load_regs(sensor, &ov5640_mode_init_data); if (ret < 0) return ret; sensor->last_mode = &ov5640_mode_init_data; /* ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, (ilog2(OV5640_SCLK2X_ROOT_DIVIDER_DEFAULT) << 2) | ilog2(OV5640_SCLK_ROOT_DIVIDER_DEFAULT)); */ ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, 1); if (ret) return ret; /* now restore the last capture mode */ ret = ov5640_set_mode(sensor); if (ret < 0) return ret; return ov5640_set_framefmt(sensor, &sensor->vdev.fmt); } #ifndef _PLATFORM_SIMULATION_ //extern gpio_dev_t g_gpio_safety; // extern pinctrl_t g_pinctrl_safety; /* OV5640: level_high => power down, low => up */ static void ov5640_sys_power(struct ov5640_dev *sensor, int on) { uint32_t pin = sensor->gpio_pwn; /* GPIO_B1 */ void *gpio_dev = NULL; //gpio_dev_t *gpio_dev = &g_gpio_safety; // pinctrl_t *pinctrl = &g_pinctrl_safety; sensor_info("%s, on %d, pwn_pin %d, reset_pin %d\n", __func__, on, sensor->gpio_pwn, sensor->gpio_reset); // pinctrl_config(pinctrl, pin, PINCTRL_CONFIG_FUNCTION, PIN_MUX_ALT0); // gpio_config(gpio_dev, pin, GPIO_OUT); gpio_set(gpio_dev, pin, true); usleep_range(3000, 4000); if (on) { gpio_set(gpio_dev, pin, false); usleep_range(3000, 4000); /* reset (default)low -> high */ pin = sensor->gpio_reset; /* GPIO_B13; */ gpio_set(gpio_dev, pin, false); usleep_range(3000, 4000); gpio_set(gpio_dev, pin, true); usleep_range(3000, 4000); } else { /* reset low */ pin = sensor->gpio_reset; /* GPIO_B13; */ gpio_set(gpio_dev, pin, false); usleep_range(1000, 1100); } } #else static void ov5640_sys_power(struct ov5640_dev *sensor, int on) {} #endif static int ov5640_set_power_on(struct ov5640_dev *sensor) { int ret; sensor_debug("%s\n", __func__); ov5640_sys_power(sensor, 1); ret = ov5640_init_slave_id(sensor); if (ret) goto power_off; return 0; power_off: return ret; } static void ov5640_set_power_off(struct ov5640_dev *sensor) { return; } static int ov5640_set_power(struct ov5640_dev *sensor, bool on) { int ret = 0; sensor_debug("%s\n", __func__); if (on) { ret = ov5640_set_power_on(sensor); if (ret) return ret; ret = ov5640_restore_mode(sensor); printf("ov5640_set_power: ov5640_restore_mode end\n"); if (ret) goto power_off; printf("bus=%d\n", sensor->vdev.ep.bus_type); /* We're done here for DVP bus, while CSI-2 needs setup. */ if (sensor->vdev.ep.bus_type != VDEV_MBUS_CSI2) return 0; /* * Power up MIPI HS Tx and LS Rx; 2 data lanes mode * * 0x300e = 0x40 * [7:5] = 010 : 2 data lanes mode (see FIXME note in * "ov5640_set_stream_mipi()") * [4] = 0 : Power up MIPI HS Tx * [3] = 0 : Power up MIPI LS Rx * [2] = 0 : MIPI interface disabled */ ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x40); if (ret) goto power_off; /* * Gate clock and set LP11 in 'no packets mode' (idle) * * 0x4800 = 0x24 * [5] = 1 : Gate clock when 'no packets' * [2] = 1 : MIPI bus in LP11 when 'no packets' */ ret = ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x24); if (ret) goto power_off; /* * Set data lanes and clock in LP11 when 'sleeping' * * 0x3019 = 0x70 * [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping' * [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping' * [4] = 1 : MIPI clock lane in LP11 when 'sleeping' */ ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x70); if (ret) goto power_off; /* Give lanes some time to coax into LP11 state. */ udelay(500); } else { if (sensor->vdev.ep.bus_type == VDEV_MBUS_CSI2) { /* Reset MIPI bus settings to their default values. */ ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x04); ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x00); } ov5640_set_power_off(sensor); } return 0; power_off: ov5640_set_power_off(sensor); return ret; } /* --------------- Subdev Operations --------------- */ static int ov5640_s_power(struct vdev_device *vdev, int on) { int ret = 0; struct ov5640_dev *sensor = to_ov5640_dev(vdev); osMutexAcquire(sensor->lock, 0); /* * If the power count is modified from 0 to != 0 or from != 0 to 0, * update the power state. */ if (sensor->power_count == !on) { ret = ov5640_set_power(sensor, !!on); if (ret) goto out; } /* Update the power count. */ sensor->power_count += on ? 1 : -1; out: osMutexRelease(sensor->lock); return ret; } static int ov5640_try_frame_interval(struct ov5640_dev *sensor, struct vdev_fract *fi, uint32_t width, uint32_t height) { const struct ov5640_mode_info *mode; uint32_t minfps, fps30, fps45, maxfps, fps; int ret; sensor_debug("%s\n", __func__); minfps = ov5640_framerates[OV5640_15_FPS]; fps30 = ov5640_framerates[OV5640_30_FPS]; fps45 = ov5640_framerates[OV5640_45_FPS]; maxfps = ov5640_framerates[OV5640_60_FPS]; if (fi->numerator == 0) { fi->denominator = maxfps; fi->numerator = 1; return OV5640_30_FPS; } fps = DIV_ROUND_UP(fi->denominator, fi->numerator); fi->numerator = 1; if (fps >= maxfps) fi->denominator = maxfps; else if (fps <= minfps) fi->denominator = minfps; else if (fps <= fps30) fi->denominator = fps30; else fi->denominator = fps45; // ret = (fi->denominator == minfps) ? OV5640_15_FPS : OV5640_30_FPS; if (fi->denominator == minfps) ret = OV5640_15_FPS; else if (fi->denominator == maxfps) ret = OV5640_60_FPS; else if (fi->denominator == fps45) ret = OV5640_45_FPS; else ret = OV5640_30_FPS; mode = ov5640_find_mode(sensor, (enum ov5640_frame_rate)ret, width, height, false); return mode ? ret : -EINVAL; } static int ov5640_get_fmt(struct vdev_device *vdev, struct vdev_mbus_framefmt *fmt) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); sensor_debug("%s\n", __func__); osMutexAcquire(sensor->lock, 0); *fmt = sensor->vdev.fmt; osMutexRelease(sensor->lock); return 0; } static int ov5640_try_fmt_internal(struct ov5640_dev *sensor, struct vdev_mbus_framefmt *fmt, enum ov5640_frame_rate fr, const struct ov5640_mode_info **new_mode) { const struct ov5640_mode_info *mode; unsigned int i; mode = ov5640_find_mode(sensor, fr, fmt->width, fmt->height, true); sensor_debug("%s\n", __func__); if (!mode) return -EINVAL; fmt->width = mode->hact; fmt->height = mode->vact; if (new_mode) *new_mode = mode; for (i = 0; i < ARRAY_SIZE(ov5640_formats); i++) if (ov5640_formats[i].code == fmt->code) break; if (i >= ARRAY_SIZE(ov5640_formats)) { i = 0; printf("%s(): try fr or fmt err\n", __func__); return -1; } fmt->code = ov5640_formats[i].code; fmt->colorspace = ov5640_formats[i].colorspace; return 0; } static int ov5640_set_fmt(struct vdev_device *vdev, struct vdev_mbus_framefmt format) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); const struct ov5640_mode_info *new_mode; struct vdev_mbus_framefmt *mbus_fmt = &format; int ret; sensor_debug("%s\n", __func__); osMutexAcquire(sensor->lock, 0); if (sensor->streaming) { ret = -EBUSY; goto out; } ret = ov5640_try_fmt_internal(sensor, mbus_fmt, sensor->current_fr, &new_mode); if (ret) goto out; if ((new_mode != sensor->current_mode) || (mbus_fmt->code != sensor->vdev.fmt.code)) { if (mbus_fmt->code != sensor->vdev.fmt.code) { sensor->pending_fmt_change = true; } if (new_mode != sensor->current_mode) { sensor->current_mode = new_mode; sensor->pending_mode_change = true; } sensor->vdev.fmt = *mbus_fmt; } out: osMutexRelease(sensor->lock); return ret; } static int ov5640_set_framefmt(struct ov5640_dev *sensor, struct vdev_mbus_framefmt *format) { int ret = 0; bool is_rgb = false; bool is_jpeg = false; uint8_t val; sensor_debug("%s code %d\n", __func__, format->code); switch (format->code) { case VDEV_MBUS_FMT_YUV420SP: val = 0x40; break; case VDEV_MBUS_FMT_YUV420XP: val = 0xFE; break; case VDEV_MBUS_FMT_UYVY: case VDEV_MBUS_FMT_UYVYSP: /* YUV422, UYVY */ val = 0x3f; break; case VDEV_MBUS_FMT_YUYV: case VDEV_MBUS_FMT_YUYVSP: /* YUV422, YUYV */ val = 0x30; break; case VDEV_MBUS_FMT_YUV444: /* Not work */ val = 0xFA; break; case VDEV_MBUS_FMT_RGB565: /* RGB565 {g[2:0],b[4:0]},{r[4:0],g[5:3]} */ val = 0x6F; is_rgb = true; break; case VDEV_MBUS_FMT_RGB565X: /* RGB565 {r[4:0],g[5:3]},{g[2:0],b[4:0]} */ val = 0x61; is_rgb = true; break; case VDEV_MBUS_FMT_JPEG: /* YUV422, YUYV */ val = 0x30; is_jpeg = true; break; default: return -EINVAL; } /* FORMAT CONTROL00: YUV and RGB formatting */ ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, val); if (ret) return ret; /* FORMAT MUX CONTROL: ISP YUV or RGB */ ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, is_rgb ? 0x01 : 0x00); if (ret) return ret; /* * TIMING TC REG21: * - [5]: JPEG enable */ ret = ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, BIT(5), is_jpeg ? BIT(5) : 0); if (ret) return ret; /* * SYSTEM RESET02: * - [4]: Reset JFIFO * - [3]: Reset SFIFO * - [2]: Reset JPEG */ ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_RESET02, BIT(4) | BIT(3) | BIT(2), is_jpeg ? 0 : (BIT(4) | BIT(3) | BIT(2))); if (ret) return ret; /* * CLOCK ENABLE02: * - [5]: Enable JPEG 2x clock * - [3]: Enable JPEG clock */ return ov5640_mod_reg(sensor, OV5640_REG_SYS_CLOCK_ENABLE02, BIT(5) | BIT(3), is_jpeg ? (BIT(5) | BIT(3)) : 0); } #if CONFIG_SENSOR_CTRL /* * Sensor Controls. */ static int ov5640_set_ctrl_hue(struct ov5640_dev *sensor, int value) { int ret; sensor_debug("%s\n", __func__); if (value) { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(0), BIT(0)); if (ret) return ret; ret = ov5640_write_reg16(sensor, OV5640_REG_SDE_CTRL1, value); } else { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(0), 0); } return ret; } static int ov5640_set_ctrl_contrast(struct ov5640_dev *sensor, int value) { int ret; sensor_debug("%s\n", __func__); if (value) { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(2), BIT(2)); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL5, value & 0xff); } else { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(2), 0); } return ret; } static int ov5640_set_ctrl_saturation(struct ov5640_dev *sensor, int value) { int ret; sensor_debug("%s\n", __func__); if (value) { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(1), BIT(1)); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL3, value & 0xff); if (ret) return ret; ret = ov5640_write_reg(sensor, OV5640_REG_SDE_CTRL4, value & 0xff); } else { ret = ov5640_mod_reg(sensor, OV5640_REG_SDE_CTRL0, BIT(1), 0); } return ret; } static int ov5640_set_ctrl_white_balance(struct ov5640_dev *sensor, int awb) { int ret; sensor_debug("%s\n", __func__); ret = ov5640_mod_reg(sensor, OV5640_REG_AWB_MANUAL_CTRL, BIT(0), awb ? 0 : 1); if (ret) return ret; if (!awb) { uint16_t red = (uint16_t)sensor->ctrls.red_balance; uint16_t blue = (uint16_t)sensor->ctrls.blue_balance; ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_R_GAIN, red); if (ret) return ret; ret = ov5640_write_reg16(sensor, OV5640_REG_AWB_B_GAIN, blue); } return ret; } static int ov5640_set_ctrl_exposure(struct ov5640_dev *sensor, bool auto_exposure) { struct ov5640_ctrls *ctrls = &sensor->ctrls; bool auto_exp = auto_exposure; int ret = 0; sensor_debug("%s\n", __func__); ret = ov5640_set_autoexposure(sensor, auto_exp); if (ret) return ret; if (!auto_exp) { uint16_t max_exp; ret = ov5640_read_reg16(sensor, OV5640_REG_AEC_PK_VTS, &max_exp); if (ret) return ret; ret = ov5640_get_vts(sensor); if (ret < 0) return ret; max_exp += ret; ret = 0; if (ctrls->exposure < max_exp) ret = ov5640_set_exposure(sensor, ctrls->exposure); } return ret; } static int ov5640_set_ctrl_gain(struct ov5640_dev *sensor, bool auto_gain) { struct ov5640_ctrls *ctrls = &sensor->ctrls; int ret = 0; sensor_debug("%s\n", __func__); ret = ov5640_set_autogain(sensor, auto_gain); if (ret) return ret; if (!auto_gain) ret = ov5640_set_gain(sensor, ctrls->gain); return ret; } static int ov5640_set_ctrl_test_pattern(struct ov5640_dev *sensor, int value) { uint8_t readval = 0; sensor_debug("%s\n", __func__); ov5640_mod_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, 0xa4, value ? 0xa4 : 0); ov5640_read_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, &readval); printf("%s: 0x%x = 0x%x\n", __func__, OV5640_REG_PRE_ISP_TEST_SET1, readval); return 0; } static int ov5640_set_ctrl_light_freq(struct ov5640_dev *sensor, int value) { int ret; sensor_debug("%s\n", __func__); ret = ov5640_mod_reg( sensor, OV5640_REG_HZ5060_CTRL01, BIT(7), (value == VDEV_CID_POWER_LINE_FREQUENCY_AUTO) ? 0 : BIT(7)); if (ret) return ret; return ov5640_mod_reg(sensor, OV5640_REG_HZ5060_CTRL00, BIT(2), (value == VDEV_CID_POWER_LINE_FREQUENCY_50HZ) ? BIT(2) : 0); } static int ov5640_set_ctrl_hflip(struct ov5640_dev *sensor, int value) { /* * If sensor is mounted upside down, mirror logic is inversed. * * Sensor is a BSI (Back Side Illuminated) one, * so image captured is physically mirrored. * This is why mirror logic is inversed in * order to cancel this mirror effect. */ sensor_debug("%s\n", __func__); /* * TIMING TC REG21: * - [2]: ISP mirror * - [1]: Sensor mirror */ return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG21, BIT(2) | BIT(1), ((value ^ sensor->upside_down)) ? (BIT(2) | BIT(1)) : 0); } static int ov5640_set_ctrl_vflip(struct ov5640_dev *sensor, int value) { /* If sensor is mounted upside down, flip logic is inversed */ sensor_debug("%s\n", __func__); /* * TIMING TC REG20: * - [2]: ISP vflip * - [1]: Sensor vflip */ return ov5640_mod_reg(sensor, OV5640_REG_TIMING_TC_REG20, BIT(2) | BIT(1), (value ^ sensor->upside_down) ? (BIT(2) | BIT(1)) : 0); } static int ov5640_g_volatile_ctrl(struct vdev_device *vdev, struct vdev_ctrl *ctrl) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); int val; /* vdev_ctrl_lock() locks our own mutex */ sensor_debug("%s, id=%d\n", __func__, ctrl->id); switch (ctrl->id) { case VDEV_CID_AUTOGAIN: val = ov5640_get_gain(sensor); if (val < 0) return val; sensor->ctrls.gain = val; break; case VDEV_CID_EXPOSURE_AUTO: val = ov5640_get_exposure(sensor); if (val < 0) return val; sensor->ctrls.exposure = val; break; } return 0; } static int ov5640_s_ctrl(struct vdev_device *vdev, struct vdev_ctrl *ctrl) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); int ret; /* vdev_ctrl_lock() locks our own mutex */ /* * If the device is not powered up by the host driver do * not apply any controls to H/W at this time. Instead * the controls will be restored right after power-up. */ if (sensor->power_count == 0) return 0; sensor_debug("%s, id=%d\n", __func__, ctrl->id); switch (ctrl->id) { case VDEV_CID_AUTOGAIN: ret = ov5640_set_ctrl_gain(sensor, ctrl->val); break; case VDEV_CID_EXPOSURE_AUTO: ret = ov5640_set_ctrl_exposure(sensor, ctrl->val); break; case VDEV_CID_AUTO_WHITE_BALANCE: ret = ov5640_set_ctrl_white_balance(sensor, ctrl->val); break; case VDEV_CID_HUE: ret = ov5640_set_ctrl_hue(sensor, ctrl->val); break; case VDEV_CID_CONTRAST: ret = ov5640_set_ctrl_contrast(sensor, ctrl->val); break; case VDEV_CID_SATURATION: ret = ov5640_set_ctrl_saturation(sensor, ctrl->val); break; case VDEV_CID_TEST_PATTERN: ret = ov5640_set_ctrl_test_pattern(sensor, ctrl->val); break; case VDEV_CID_POWER_LINE_FREQUENCY: ret = ov5640_set_ctrl_light_freq(sensor, ctrl->val); break; case VDEV_CID_HFLIP: ret = ov5640_set_ctrl_hflip(sensor, ctrl->val); break; case VDEV_CID_VFLIP: ret = ov5640_set_ctrl_vflip(sensor, ctrl->val); break; default: ret = -EINVAL; break; } return ret; } #endif /* CONFIG_SENSOR_CTRL */ static int ov5640_init_controls(struct ov5640_dev *sensor) { struct ov5640_ctrls *ctrls = &sensor->ctrls; sensor_debug("%s\n", __func__); /* Auto/manual white balance */ ctrls->auto_wb = 1; ctrls->blue_balance = 0; ctrls->red_balance = 0; /* Auto/manual exposure */ ctrls->auto_exp = 1; ctrls->exposure = 0; /* Auto/manual gain */ ctrls->auto_gain = 1; ctrls->gain = 0; ctrls->saturation = 64; ctrls->hue = 0; ctrls->contrast = 0; ctrls->test_pattern = 0; ctrls->hflip = 0; ctrls->vflip = 0; ctrls->light_freq = 50; return 0; } static int ov5640_enum_fmt(struct vdev_device *vdev, struct vdev_mbus_framefmt *fmt) { if (!fmt || (fmt->index >= (sizeof(ov5640_formats) / sizeof(ov5640_formats[0])))) { return -1; } fmt->code = ov5640_formats[fmt->index].code; fmt->colorspace = ov5640_formats[fmt->index].colorspace; fmt->field = VDEV_FIELD_NONE; return 0; } static int ov5640_enum_frame_size(struct vdev_device *vdev, struct vdev_frame_size_enum *fse) { if (fse->index >= OV5640_NUM_MODES) { return -1; } fse->min_width = ov5640_mode_data[0][fse->index].hact; fse->max_width = fse->min_width; fse->min_height = ov5640_mode_data[0][fse->index].vact; fse->max_height = fse->min_height; sensor_debug("%s\n", __func__); return 0; } static int ov5640_enum_frame_interval(struct vdev_device *vdev, struct vdev_frame_interval_enum *fie) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); struct vdev_fract tpf; int ret; sensor_debug("%s\n", __func__); if (fie->index >= OV5640_NUM_FRAMERATES) { return -1; } tpf.numerator = 1; tpf.denominator = ov5640_framerates[fie->index]; ret = ov5640_try_frame_interval(sensor, &tpf, fie->width, fie->height); if (ret < 0) return -EINVAL; fie->interval = tpf; return 0; } static int ov5640_g_frame_interval(struct vdev_device *vdev, struct vdev_fract *fi) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); osMutexAcquire(sensor->lock, 0); *fi = sensor->vdev.frame_interval; osMutexRelease(sensor->lock); sensor_debug("%s\n", __func__); return 0; } static int ov5640_s_frame_interval(struct vdev_device *vdev, struct vdev_fract frame_interval) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); const struct ov5640_mode_info *mode; unsigned int frame_rate; int ret = 0; sensor_debug("%s\n", __func__); osMutexAcquire(sensor->lock, 0); if (sensor->streaming) { ret = -EBUSY; goto out; } mode = sensor->current_mode; frame_rate = ov5640_try_frame_interval(sensor, &frame_interval, mode->hact, mode->vact); if (frame_rate >= OV5640_NUM_FRAMERATES) frame_rate = OV5640_15_FPS; mode = ov5640_find_mode(sensor, (enum ov5640_frame_rate)frame_rate, mode->hact, mode->vact, true); if (!mode) { ret = -EINVAL; goto out; } if (mode != sensor->current_mode || frame_rate != sensor->current_fr) { sensor->current_fr = (enum ov5640_frame_rate)frame_rate; sensor->vdev.frame_interval = frame_interval; sensor->current_mode = mode; sensor->pending_mode_change = true; } out: osMutexRelease(sensor->lock); return ret; } static int ov5640_s_stream(struct vdev_device *vdev, int enable) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); int ret = 0; sensor_debug("%s\n", __func__); sensor_info("%s: enable %d, stack 0x%08x\n", __func__, enable, (uint32_t)&ret); osMutexAcquire(sensor->lock, 0); if (sensor->streaming == !enable) { if (enable && sensor->pending_mode_change) { sensor_info("%s: pending_mode_change %d\n", __func__, sensor->pending_mode_change); ret = ov5640_set_mode(sensor); sensor_info("%s: ov5640_set_mode done\n", __func__); if (ret) goto out; } if (enable && sensor->pending_fmt_change) { ret = ov5640_set_framefmt(sensor, &sensor->vdev.fmt); sensor_info("%s: ov5640_set_framefmt done\n", __func__); if (ret) goto out; sensor->pending_fmt_change = false; } if (sensor->vdev.ep.bus_type == VDEV_MBUS_CSI2) ret = ov5640_set_stream_mipi(sensor, enable); else ret = ov5640_set_stream_dvp(sensor, enable); sensor_info("%s: ov5640_set_bus type %d done\n", __func__, sensor->vdev.ep.bus_type); if (!ret) sensor->streaming = enable; } out: osMutexRelease(sensor->lock); sensor_info("%s: enable %d done\n", __func__, enable); return ret; } #if CONFIG_SENSOR_CTRL static int ov5640_set_interface(struct vdev_device *vdev, struct vdev_fwnode_endpoint ep) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); int ret; uint8_t val; sensor_debug("%s\n", __func__); osMutexAcquire(sensor->lock, 0); if (sensor->streaming) { ret = -EBUSY; goto out; } if (ep.bus_type == vdev->ep.bus_type) { ret = 0; goto out; } switch (ep.bus_type) { case VDEV_MBUS_PARALLEL: val = 0x00; break; case VDEV_MBUS_BT656: val = 0x01; break; default: ret = -EINVAL; goto out; } ret = ov5640_write_reg(sensor, OV5640_REG_CCIR656_CONTROL00, val); if (ret) return ret; out: osMutexRelease(sensor->lock); return ret; } static int ov5640_get_interface(struct vdev_device *vdev, struct vdev_fwnode_endpoint *ep) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); sensor_debug("%s\n", __func__); osMutexAcquire(sensor->lock, 0); ep = &sensor->vdev.ep; osMutexRelease(sensor->lock); return 0; } static int ov5640_channel_enable(struct vdev_device *vdev, bool en, uint8_t ch) { if (!vdev) return -1; vdev->ex_info.vcn = 1; if (en) { vdev->ex_info.vc |= ch; } else { vdev->ex_info.vc &= ~ch; } return 0; } static const struct vdev_dev_ops ov5640_vdev_ops = { .s_power = ov5640_s_power, .g_frame_interval = ov5640_g_frame_interval, .s_frame_interval = ov5640_s_frame_interval, .s_stream = ov5640_s_stream, .get_fmt = ov5640_get_fmt, .set_fmt = ov5640_set_fmt, .set_interface = ov5640_set_interface, .get_interface = ov5640_get_interface, .enum_frame_size = ov5640_enum_frame_size, .enum_frame_interval = ov5640_enum_frame_interval, .g_volatile_ctrl = ov5640_g_volatile_ctrl, .s_ctrl = ov5640_s_ctrl, .sync_enable = NULL, .vc_enable = ov5640_channel_enable, .close = ov5640_exit, }; #else static const struct vdev_dev_ops ov5640_vdev_ops = { .s_power = ov5640_s_power, .enum_mbus_fmt = ov5640_enum_fmt, .enum_frame_size = ov5640_enum_frame_size, .enum_frame_interval = ov5640_enum_frame_interval, .g_frame_interval = ov5640_g_frame_interval, .s_frame_interval = ov5640_s_frame_interval, .get_fmt = ov5640_get_fmt, .set_fmt = ov5640_set_fmt, .s_stream = ov5640_s_stream, .close = ov5640_exit, }; #endif static int ov5640_check_chip_id(struct ov5640_dev *sensor) { int ret = 0; uint16_t chip_id; sensor_debug("%s\n", __func__); ret = ov5640_set_power_on(sensor); if (ret) return ret; ret = ov5640_read_reg16(sensor, OV5640_REG_CHIP_ID, &chip_id); sensor_info("%s(): ret=%d, chip_id=0x%x.\n", __func__, ret, chip_id); if (ret) { sensor_err("%s: failed to read chip identifier\n", __func__); goto power_off; } if (chip_id != 0x5640) { sensor_err("%s: wrong chip identifier, expected 0x5640, got 0x%x\n", __func__, chip_id); #if WITH_CSI_DUMMY_I2C ret = 0; #else ret = -ENXIO; #endif } power_off: ov5640_set_power_off(sensor); return ret; } struct vdev_device *ex_ov5640_init(void *init_data) { int ret; struct ov5640_dev *sensor; struct camera_res_cfg *cfg = (struct camera_res_cfg *)init_data; struct vdev_mbus_framefmt *fmt; int fps_mode, size_mode; sensor_info("%s start\n", __func__); if (!cfg || !cfg->i2c_handle) { sensor_err("failed to get res_cfg for ov5640\n"); return NULL; } sensor = pvPortMalloc(sizeof(*sensor)); if (!sensor) { sensor_err("failed to pvPortMalloc for ov5640\n"); return NULL; } memset(sensor, 0, sizeof(struct ov5640_dev)); sensor->adap = cfg->i2c_handle; sensor->gpio_pwn = cfg->gpio[0]; sensor->gpio_reset = cfg->gpio[1]; /* * default init sequence initialize sensor to * YUV422 UYVY VGA@30fps */ fmt = &sensor->vdev.fmt; fps_mode = OV5640_30_FPS; size_mode = OV5640_MODE_720P_1280_720; fmt->code = VDEV_MBUS_FMT_UYVY; //VDEV_MBUS_FMT_RGB565; fmt->colorspace = VDEV_COLORSPACE_SRGB; fmt->width = ov5640_mode_data[fps_mode][size_mode].hact; fmt->height = ov5640_mode_data[fps_mode][size_mode].vact; fmt->field = VDEV_FIELD_NONE; sensor->vdev.frame_interval.numerator = 1; sensor->vdev.frame_interval.denominator = ov5640_framerates[fps_mode]; sensor->current_fr = (enum ov5640_frame_rate)fps_mode; sensor->current_mode = &ov5640_mode_data[fps_mode][size_mode]; sensor->last_mode = sensor->current_mode; sensor->vdev.ep.flags = VDEV_MBUS_PCLK_SAMPLE_RISING; sensor->vdev.ep.bus_type = VDEV_MBUS_PARALLEL2; //VDEV_MBUS_PARALLEL sensor->vdev.ops = ov5640_vdev_ops; sensor->xclk_freq = 24000000; sensor->ae_target = 52; sensor->lock = osMutexNew(NULL); ret = ov5640_check_chip_id(sensor); if (ret) goto entity_cleanup; ov5640_init_controls(sensor); sensor_info("ov5640_init() end, &sensor->vdev=%p\n", &sensor->vdev); return &sensor->vdev; entity_cleanup: osMutexDelete(sensor->lock); vPortFree(sensor); return NULL; } int ov5640_config_mode(struct vdev_device *vdev, int size_mode, int fps_mode) { int ret = 0; const struct ov5640_mode_info *new_mode; struct ov5640_dev *sensor = to_ov5640_dev(vdev); sensor_info("%s: size mode %d, fps_mode %d\n", __func__, size_mode, fps_mode); if ((size_mode < OV5640_MODE_QCIF_176_144) || (size_mode >= OV5640_NUM_MODES)) { sensor_err("%s: error size mode %d\n", __func__, size_mode); return -1; } if ((fps_mode < OV5640_15_FPS) || (fps_mode >= OV5640_NUM_FRAMERATES)) { sensor_err("%s: error fps mode %d\n", __func__, fps_mode); return -1; } new_mode = &ov5640_mode_data[fps_mode][size_mode]; if (new_mode->reg_data == NULL) { sensor_err("%s: unsupported size mode %d, fps_mode %d\n", __func__, size_mode, fps_mode); return -1; } if (new_mode == sensor->current_mode) { goto exit; } sensor->current_mode = new_mode; sensor->pending_mode_change = true; sensor->current_fr = (enum ov5640_frame_rate)fps_mode; sensor->vdev.frame_interval.numerator = 1; sensor->vdev.frame_interval.denominator = ov5640_framerates[fps_mode]; sensor->vdev.fmt.width = new_mode->hact; sensor->vdev.fmt.height = new_mode->vact; exit: sensor_info("%s: done\n", __func__); return ret; } static int ov5640_exit(struct vdev_device *vdev) { struct ov5640_dev *sensor = to_ov5640_dev(vdev); osMutexDelete(sensor->lock); vPortFree(sensor); return 0; }