From 88ad6215ec3375d7f0aae7caa0834bf976dcddf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Moj=C5=BE=C3=AD=C5=A1?= Date: Mon, 2 Mar 2026 16:00:25 +0100 Subject: [PATCH 1/2] 4.4 gc4023 t41 --- 4.4/sensor-src/include/sensor-info.h | 1 + 4.4/sensor-src/t41/gc4023.c | 510 +++++++++++++++------------ 2 files changed, 290 insertions(+), 221 deletions(-) diff --git a/4.4/sensor-src/include/sensor-info.h b/4.4/sensor-src/include/sensor-info.h index 0da94fea1..b35417895 100644 --- a/4.4/sensor-src/include/sensor-info.h +++ b/4.4/sensor-src/include/sensor-info.h @@ -7,6 +7,7 @@ struct sensor_info { const char *version; int min_fps; int max_fps; + int actual_fps; unsigned int chip_i2c_addr; int width; int height; diff --git a/4.4/sensor-src/t41/gc4023.c b/4.4/sensor-src/t41/gc4023.c index 9d89331f9..19d95cbb3 100644 --- a/4.4/sensor-src/t41/gc4023.c +++ b/4.4/sensor-src/t41/gc4023.c @@ -1,8 +1,14 @@ // SPDX-License-Identifier: GPL-2.0+ /* * gc4023.c + * * Copyright (C) 2022 Ingenic Semiconductor Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. */ +#define DEBUG #include #include @@ -14,52 +20,112 @@ #include #include #include + #include #include #include -#define SENSOR_NAME "gc4023" -#define SENSOR_CHIP_ID_H (0x40) -#define SENSOR_CHIP_ID_L (0x23) -#define SENSOR_REG_END 0xffff -#define SENSOR_REG_DELAY 0x0000 -#define SENSOR_REG_DELAY 0x0000 -#define SENSOR_SUPPORT_30FPS_SCLK (0x7e9 * 0x4b0 * 2 * 25) -#define SENSOR_SUPPORT_20FPS_SCLK 108*1000*1000 -#define SENSOR_OUTPUT_MIN_FPS 5 -#define SENSOR_VERSION "H20230720" -#define SENSOR_HIGH_TEMP "highTemp" -#define SENSOR_LOW_TEMP "lowTemp" -#define CAMERA_PROC_NAME "camera" -#define SENSOR_TEMP_PROC_NAME "sensorTemp" - -static int reset_gpio = GPIO_PC(27); -static int pwdn_gpio = -1; -static int shvflip = 1; +// ============================================================================ +// SENSOR IDENTIFICATION +// ============================================================================ +#define SENSOR_CHIP_ID_H (0x40) +#define SENSOR_CHIP_ID_L (0x23) +#define SENSOR_VERSION "H20230720" +#define SENSOR_NAME "gc4023" +#define SENSOR_TEMP_PROC_NAME "sensorTemp" + +// ============================================================================ +// REGISTER DEFINITIONS +// ============================================================================ +#define SENSOR_REG_END 0xffff +#define SENSOR_REG_DELAY 0x0000 + +// ============================================================================ +// TIMING AND PERFORMANCE +// ============================================================================ +#define SENSOR_SUPPORT_30FPS_SCLK (0x7e9 * 0x4b0 * 2 * 25) +#define SENSOR_SUPPORT_20FPS_SCLK 108*1000*1000 +#define SENSOR_OUTPUT_MAX_FPS 30 +#define SENSOR_OUTPUT_MIN_FPS 5 + +// ============================================================================ +// HARDWARE INTERFACE +// ============================================================================ +#define SENSOR_BUS_TYPE TX_SENSOR_CONTROL_INTERFACE_I2C +#define SENSOR_I2C_ADDRESS 0x29 + +// ============================================================================ +// SENSOR CAPABILITIES +// ============================================================================ +#define SENSOR_MAX_WIDTH 2560 +#define SENSOR_MAX_HEIGHT 1440 +// ============================================================================ +// SPECIAL FEATURES +// ============================================================================ +#define SENSOR_HIGH_TEMP "highTemp" +#define SENSOR_LOW_TEMP "lowTemp" +#define CAMERA_PROC_NAME "camera" + +static int reset_gpio = GPIO_PA(18); +module_param(reset_gpio, int, S_IRUGO); +MODULE_PARM_DESC(reset_gpio, "Reset GPIO NUM"); + +static int pwdn_gpio = -1; +module_param(pwdn_gpio, int, S_IRUGO); +MODULE_PARM_DESC(pwdn_gpio, "Power down GPIO NUM"); + +static int shvflip = 1; +module_param(shvflip, int, S_IRUGO); +MODULE_PARM_DESC(shvflip, "Sensor HV Flip Enable interface"); struct proc_dir_entry *g_sinfo_proc; -module_param(shvflip, int, S_IRUGO); -MODULE_PARM_DESC(shvflip, "Sensor HV Flip Enable interface"); +static int sensor_max_fps = TX_SENSOR_MAX_FPS_30; +module_param(sensor_max_fps, int, S_IRUGO); +MODULE_PARM_DESC(sensor_max_fps, "Sensor Max Fps set interface"); struct regval_list { - uint16_t reg_num; - unsigned char value; + uint16_t reg_num; + unsigned char value; }; -static unsigned char ht_gain = 24; -static unsigned char gain_flag = 0; -static unsigned char ag_last = 0; +static unsigned char ht_gain = 24; +static unsigned char gain_flag = 0; +static unsigned char ag_last = 0; /* Function prototypes */ static int sinfo_proc_open(struct inode *inode, struct file *file); +static int data_interface = TX_SENSOR_DATA_INTERFACE_MIPI; +module_param(data_interface, int, S_IRUGO); +MODULE_PARM_DESC(data_interface, "Sensor Date interface"); + +static int data_type = TX_SENSOR_DATA_TYPE_LINEAR; +module_param(data_type, int, S_IRUGO); +MODULE_PARM_DESC(data_type, "Sensor Date Type"); + +static int sensor_resolution = TX_SENSOR_RES_400; +module_param(sensor_resolution, int, S_IRUGO); +MODULE_PARM_DESC(sensor_resolution, "Sensor resolution"); + +static struct sensor_info sensor_info = { + .name = SENSOR_NAME, + .chip_id = SENSOR_CHIP_ID_H, + .version = SENSOR_VERSION, + .min_fps = SENSOR_OUTPUT_MIN_FPS, + .max_fps = SENSOR_OUTPUT_MAX_FPS, + .actual_fps = 0, + .chip_i2c_addr = SENSOR_I2C_ADDRESS, + .width = SENSOR_MAX_WIDTH, + .height = SENSOR_MAX_HEIGHT, +}; + static const struct file_operations sinfo_proc_fops = { - .owner = THIS_MODULE, - .open = sinfo_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release + .owner = THIS_MODULE, + .open = sinfo_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release }; static int sinfo_proc_show(struct seq_file *m, void *v) { @@ -71,6 +137,10 @@ static int sinfo_proc_open(struct inode *inode, struct file *file) { return single_open(file, sinfo_proc_show, NULL); } + +/* + * the part of driver maybe modify about different sensor and different board. + */ struct again_lut { unsigned int index; unsigned char reg614; @@ -84,31 +154,31 @@ struct again_lut { }; struct again_lut sensor_again_lut[] = { - {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x01, 0x00, 0}, - {0x01, 0x80, 0x02, 0x00, 0x19, 0x19, 0x01, 0x0B, 16208}, - {0x02, 0x01, 0x00, 0x00, 0x19, 0x19, 0x01, 0x19, 32217}, - {0x03, 0x81, 0x02, 0x00, 0x1a, 0x1a, 0x01, 0x2A, 47690}, - {0x04, 0x02, 0x00, 0x00, 0x1b, 0x1b, 0x02, 0x00, 65536}, - {0x05, 0x82, 0x02, 0x00, 0x1c, 0x1c, 0x02, 0x17, 81784}, - {0x06, 0x03, 0x00, 0x00, 0x1d, 0x1d, 0x02, 0x33, 97213}, - {0x07, 0x83, 0x02, 0x00, 0x1e, 0x1e, 0x03, 0x14, 113226}, - {0x08, 0x04, 0x00, 0x00, 0x20, 0x20, 0x04, 0x00, 131072}, - {0x09, 0x80, 0x02, 0x20, 0x22, 0x22, 0x04, 0x2F, 147001}, - {0x0A, 0x01, 0x00, 0x20, 0x23, 0x23, 0x05, 0x26, 162766}, - {0x0B, 0x81, 0x02, 0x20, 0x25, 0x25, 0x06, 0x28, 178990}, - {0x0C, 0x02, 0x00, 0x20, 0x25, 0x25, 0x08, 0x00, 196608}, - {0x0D, 0x82, 0x02, 0x20, 0x26, 0x26, 0x09, 0x1E, 212696}, - {0x0E, 0x03, 0x00, 0x20, 0x26, 0x26, 0x0B, 0x0C, 228446}, - {0x0F, 0x83, 0x02, 0x20, 0x26, 0x26, 0x0D, 0x11, 244419}, - {0x10, 0x04, 0x00, 0x20, 0x27, 0x27, 0x10, 0x00, 262144}, - {0x11, 0x84, 0x02, 0x20, 0x27, 0x27, 0x12, 0x3D, 278158}, - {0x12, 0x05, 0x00, 0x20, 0x28, 0x28, 0x16, 0x19, 293982}, - {0x13, 0x85, 0x02, 0x20, 0x28, 0x28, 0x1A, 0x22, 310012}, - {0x14, 0xb5, 0x04, 0x20, 0x29, 0x29, 0x20, 0x00, 327680}, - {0x15, 0x85, 0x05, 0x20, 0x2a, 0x2a, 0x25, 0x3A, 343731}, - {0x16, 0x05, 0x08, 0x20, 0x2b, 0x2b, 0x2C, 0x33, 359484}, - {0x17, 0x45, 0x09, 0x20, 0x2d, 0x2d, 0x35, 0x05, 375550}, - {0x18, 0x55, 0x0a, 0x20, 0x2e, 0x2e, 0x40, 0x00, 393216}, + {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x01, 0x00, 0}, + {0x01, 0x80, 0x02, 0x00, 0x19, 0x19, 0x01, 0x0B, 16208}, + {0x02, 0x01, 0x00, 0x00, 0x19, 0x19, 0x01, 0x19, 32217}, + {0x03, 0x81, 0x02, 0x00, 0x1a, 0x1a, 0x01, 0x2A, 47690}, + {0x04, 0x02, 0x00, 0x00, 0x1b, 0x1b, 0x02, 0x00, 65536}, + {0x05, 0x82, 0x02, 0x00, 0x1c, 0x1c, 0x02, 0x17, 81784}, + {0x06, 0x03, 0x00, 0x00, 0x1d, 0x1d, 0x02, 0x33, 97213}, + {0x07, 0x83, 0x02, 0x00, 0x1e, 0x1e, 0x03, 0x14, 113226}, + {0x08, 0x04, 0x00, 0x00, 0x20, 0x20, 0x04, 0x00, 131072}, + {0x09, 0x80, 0x02, 0x20, 0x22, 0x22, 0x04, 0x2F, 147001}, + {0x0A, 0x01, 0x00, 0x20, 0x23, 0x23, 0x05, 0x26, 162766}, + {0x0B, 0x81, 0x02, 0x20, 0x25, 0x25, 0x06, 0x28, 178990}, + {0x0C, 0x02, 0x00, 0x20, 0x25, 0x25, 0x08, 0x00, 196608}, + {0x0D, 0x82, 0x02, 0x20, 0x26, 0x26, 0x09, 0x1E, 212696}, + {0x0E, 0x03, 0x00, 0x20, 0x26, 0x26, 0x0B, 0x0C, 228446}, + {0x0F, 0x83, 0x02, 0x20, 0x26, 0x26, 0x0D, 0x11, 244419}, + {0x10, 0x04, 0x00, 0x20, 0x27, 0x27, 0x10, 0x00, 262144}, + {0x11, 0x84, 0x02, 0x20, 0x27, 0x27, 0x12, 0x3D, 278158}, + {0x12, 0x05, 0x00, 0x20, 0x28, 0x28, 0x16, 0x19, 293982}, + {0x13, 0x85, 0x02, 0x20, 0x28, 0x28, 0x1A, 0x22, 310012}, + {0x14, 0xb5, 0x04, 0x20, 0x29, 0x29, 0x20, 0x00, 327680}, + {0x15, 0x85, 0x05, 0x20, 0x2a, 0x2a, 0x25, 0x3A, 343731}, + {0x16, 0x05, 0x08, 0x20, 0x2b, 0x2b, 0x2C, 0x33, 359484}, + {0x17, 0x45, 0x09, 0x20, 0x2d, 0x2d, 0x35, 0x05, 375550}, + {0x18, 0x55, 0x0a, 0x20, 0x2e, 0x2e, 0x40, 0x00, 393216}, }; struct tx_isp_sensor_attribute sensor_attr; @@ -150,91 +220,91 @@ unsigned int sensor_alloc_dgain(unsigned int isp_gain, unsigned char shift, unsi } struct tx_isp_mipi_bus sensor_mipi_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 702, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 702, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; struct tx_isp_mipi_bus sensor_mipi_20fps_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 464, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 464, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; struct tx_isp_mipi_bus sensor_mipi_15fps_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 352, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 352, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { @@ -242,7 +312,7 @@ struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { .clk = 351, .lans = 2, .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 .mipi_sc.hcrop_diff_en = 0, .mipi_sc.mipi_vcomp_en = 0, .mipi_sc.mipi_hcomp_en = 0, @@ -267,24 +337,24 @@ struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { }; struct tx_isp_sensor_attribute sensor_attr = { - .name = SENSOR_NAME, - .chip_id = 0x4023, - .cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C, - .cbus_mask = TISP_SBUS_MASK_SAMPLE_8BITS | TISP_SBUS_MASK_ADDR_16BITS, - .dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI, - .data_type = TX_SENSOR_DATA_TYPE_LINEAR, - .cbus_device = 0x29, - .max_again = 393216, - .max_dgain = 0, - .expo_fs = 1, - .min_integration_time = 2, - .min_integration_time_short = 2, - .min_integration_time_native = 2, - .integration_time_apply_delay = 2, - .again_apply_delay = 2, - .dgain_apply_delay = 2, - .sensor_ctrl.alloc_again = sensor_alloc_again, - .sensor_ctrl.alloc_dgain = sensor_alloc_dgain, + .name = SENSOR_NAME, + .chip_id = 0x4023, + .cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C, + .cbus_mask = TISP_SBUS_MASK_SAMPLE_8BITS | TISP_SBUS_MASK_ADDR_16BITS, + .dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI, + .data_type = TX_SENSOR_DATA_TYPE_LINEAR, + .cbus_device = 0x29, + .max_again = 393216, + .max_dgain = 0, + .expo_fs = 1, + .min_integration_time = 2, + .min_integration_time_short = 2, + .min_integration_time_native = 2, + .integration_time_apply_delay = 2, + .again_apply_delay = 2, + .dgain_apply_delay = 2, + .sensor_ctrl.alloc_again = sensor_alloc_again, + .sensor_ctrl.alloc_dgain = sensor_alloc_dgain, // void priv; /* point to struct tx_isp_sensor_board_info */ }; @@ -456,7 +526,7 @@ static struct regval_list sensor_init_regs_2560_1440_25fps_mipi[] = { {0x0080, 0x02}, {0x0a67, 0x00}, {0x0100, 0x09}, - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; static struct regval_list sensor_init_regs_2560_1440_25fps_24Mmipi[] = { @@ -628,7 +698,7 @@ static struct regval_list sensor_init_regs_2560_1440_25fps_24Mmipi[] = { {0x0080, 0x02}, {0x0a67, 0x00}, {0x0100, 0x09}, - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; static struct regval_list sensor_init_regs_2560_1440_20fps_mipi[] = { @@ -969,7 +1039,7 @@ static struct regval_list sensor_init_regs_2560_1440_15fps_mipi[] = { {0x0080, 0x02}, {0x0a67, 0x00}, {0x0100, 0x09}, - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; @@ -1139,62 +1209,67 @@ static struct regval_list sensor_init_regs_1280_360_120fps_mipi[] = { {0x0a70, 0x00}, {0x0080, 0x02}, {0x0a67, 0x00}, - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; /* - * the order of the jxf23_win_sizes is [full_resolution, preview_resolution]. */ +* the order of the jxf23_win_sizes is [full_resolution, preview_resolution]. +*/ static struct tx_isp_sensor_win_setting sensor_win_sizes[] = { /* [0] 2560*1440 @max 30fps*/ { - .width = 2560, - .height = 1440, - .fps = 30 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_25fps_mipi, + .width = 2560, + .height = 1440, + .fps = 30 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_25fps_mipi, }, { - .width = 2560, - .height = 1440, - .fps = 25 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_25fps_24Mmipi, + .width = 2560, + .height = 1440, + .fps = 25 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_25fps_24Mmipi, }, { - .width = 2560, - .height = 1440, - .fps = 20 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_20fps_mipi, + .width = 2560, + .height = 1440, + .fps = 20 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_20fps_mipi, }, { - .width = 2560, - .height = 1440, - .fps = 15 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_15fps_mipi, + .width = 2560, + .height = 1440, + .fps = 15 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_15fps_mipi, }, { - .width = 1280, - .height = 360, - .fps = 120 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_1280_360_120fps_mipi, + .width = 1280, + .height = 360, + .fps = 120 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_1280_360_120fps_mipi, }, }; struct tx_isp_sensor_win_setting *wsize = &sensor_win_sizes[0]; +/* +* the part of driver was fixed. +*/ + static struct regval_list sensor_stream_on[] = { - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; static struct regval_list sensor_stream_off[] = { - {SENSOR_REG_END, 0x00}, + {SENSOR_REG_END, 0x00}, /* END MARKER */ }; int sensor_read(struct tx_isp_subdev *sd, uint16_t reg, @@ -1203,16 +1278,16 @@ int sensor_read(struct tx_isp_subdev *sd, uint16_t reg, uint8_t buf[2] = {(reg >> 8) & 0xff, reg & 0xff}; struct i2c_msg msg[2] = { [0] = { - .addr = client->addr, - .flags = 0, - .len = 2, - .buf = buf, + .addr = client->addr, + .flags = 0, + .len = 2, + .buf = buf, }, [1] = { - .addr = client->addr, - .flags = I2C_M_RD, - .len = 1, - .buf = value, + .addr = client->addr, + .flags = I2C_M_RD, + .len = 1, + .buf = value, } }; int ret; @@ -1228,10 +1303,10 @@ int sensor_write(struct tx_isp_subdev *sd, uint16_t reg, struct i2c_client *client = tx_isp_get_subdevdata(sd); uint8_t buf[3] = {(reg >> 8) & 0xff, reg & 0xff, value}; struct i2c_msg msg = { - .addr = client->addr, - .flags = 0, - .len = 3, - .buf = buf, + .addr = client->addr, + .flags = 0, + .len = 3, + .buf = buf, }; int ret; ret = private_i2c_transfer(client->adapter, &msg, 1); @@ -1242,8 +1317,7 @@ int sensor_write(struct tx_isp_subdev *sd, uint16_t reg, } #if 0 -static int sensor_read_array(struct tx_isp_subdev *sd, struct regval_list *vals) -{ +static int sensor_read_array(struct tx_isp_subdev *sd, struct regval_list *vals) { int ret; unsigned char val; while (vals->reg_num != SENSOR_REG_END) { @@ -1303,7 +1377,6 @@ static int sensor_detect(struct tx_isp_subdev *sd, unsigned int *ident) { } #if 1 - static int sensor_set_expo(struct tx_isp_subdev *sd, int value) { int ret = 0; int expo = (value & 0xffff); @@ -1339,26 +1412,23 @@ static int sensor_set_expo(struct tx_isp_subdev *sd, int value) { return 0; } - #endif #if 0 -static int sensor_set_integration_time(struct tx_isp_subdev *sd, int value) -{ +static int sensor_set_integration_time(struct tx_isp_subdev *sd, int value) { int ret = 0; ret = sensor_write(sd, 0x0203, value & 0xff); ret += sensor_write(sd, 0x0202, value >> 8); if (ret < 0) { - ISP_ERROR("sensor_write error %d\n",__LINE__ ); + ISP_ERROR("sensor_write error %d\n", __LINE__); return ret; } return 0; } -static int sensor_set_analog_gain(struct tx_isp_subdev *sd, int value) -{ +static int sensor_set_analog_gain(struct tx_isp_subdev *sd, int value) { int ret = 0; struct again_lut *val_lut = sensor_again_lut; @@ -1392,7 +1462,7 @@ static int sensor_set_logic(struct tx_isp_subdev *sd, int value) { if (reg_410 > 0x1a) gain_flag = 1; //0x1d if (gain_flag == 1) { - if (reg_410 > 0x16)//0x14 + if (reg_410 > 0x16) //0x14 { ht_gain = ht_gain - 1; if (ht_gain < 21) ht_gain = 21; @@ -1722,8 +1792,7 @@ static int sensor_attr_check(struct tx_isp_subdev *sd) { case 4: if (((rate / 1000) % 27000) != 0) { ret = clk_set_parent(sclka, clk_get(NULL, SEN_TCLK)); - printk("\n====>[clk_set_parent(sclka, clk_get(NULL, SEN_TCLK:%s))=%d]\n", SEN_TCLK, - ret); + printk("\n====>[clk_set_parent(sclka, clk_get(NULL, SEN_TCLK:%s))=%d]\n", SEN_TCLK, ret); sclka = private_devm_clk_get(&client->dev, SEN_TCLK); if (IS_ERR(sclka)) { pr_err("get sclka failed\n"); @@ -1740,8 +1809,7 @@ static int sensor_attr_check(struct tx_isp_subdev *sd) { break; } - ISP_WARNING("\n====>[default_boot=%d] [resolution=%dx%d] [video_interface=%d] [MCLK=%d] \n", info->default_boot, - wsize->width, wsize->height, info->video_interface, info->mclk); + ISP_WARNING("\n====>[default_boot=%d] [resolution=%dx%d] [video_interface=%d] [MCLK=%d] \n", info->default_boot, wsize->width, wsize->height, info->video_interface, info->mclk); reset_gpio = info->rst_gpio; pwdn_gpio = info->pwdn_gpio; @@ -1754,8 +1822,7 @@ static int sensor_attr_check(struct tx_isp_subdev *sd) { return 0; } -static int sensor_g_chip_ident(struct tx_isp_subdev *sd, - struct tx_isp_chip_ident *chip) { +static int sensor_g_chip_ident(struct tx_isp_subdev *sd, struct tx_isp_chip_ident *chip) { struct i2c_client *client = tx_isp_get_subdevdata(sd); unsigned int ident = 0; int ret = ISP_SUCCESS; @@ -1789,12 +1856,10 @@ static int sensor_g_chip_ident(struct tx_isp_subdev *sd, } ret = sensor_detect(sd, &ident); if (ret) { - ISP_ERROR("chip found @ 0x%x (%s) is not an %s chip.\n", - client->addr, client->adapter->name, SENSOR_NAME); + ISP_ERROR("chip found @ 0x%x (%s) is not an %s chip.\n", client->addr, client->adapter->name, SENSOR_NAME); return ret; } - ISP_WARNING("%s chip found @ 0x%02x (%s)\n", - SENSOR_NAME, client->addr, client->adapter->name); + ISP_WARNING("%s chip found @ 0x%02x (%s)\n sensor drv version %s\n", SENSOR_NAME, client->addr, client->adapter->name, SENSOR_VERSION); if (chip) { memcpy(chip->name, SENSOR_NAME, sizeof(SENSOR_NAME)); chip->ident = ident; @@ -1980,6 +2045,7 @@ static const struct i2c_device_id sensor_id[] = { {SENSOR_NAME, 0}, {} }; + MODULE_DEVICE_TABLE(i2c, sensor_id); static struct i2c_driver sensor_driver = { @@ -1993,6 +2059,7 @@ static struct i2c_driver sensor_driver = { }; static __init int init_sensor(void) { + sensor_common_init(&sensor_info); g_sinfo_proc = proc_mkdir(CAMERA_PROC_NAME, 0); if (!g_sinfo_proc) { printk("err: jz_proc_mkdir failed\n"); @@ -2005,6 +2072,7 @@ static __init int init_sensor(void) { static __exit void exit_sensor(void) { proc_remove(g_sinfo_proc); private_i2c_del_driver(&sensor_driver); + sensor_common_exit(); } module_init(init_sensor); From 1da6aa2f372b1d7148a26a251140f7c9e66899df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Moj=C5=BE=C3=AD=C5=A1?= Date: Tue, 3 Mar 2026 20:32:13 +0100 Subject: [PATCH 2/2] formatting --- 4.4/sensor-src/t41/gc4023.c | 879 ++++++++++++++++++------------------ 1 file changed, 442 insertions(+), 437 deletions(-) diff --git a/4.4/sensor-src/t41/gc4023.c b/4.4/sensor-src/t41/gc4023.c index 19d95cbb3..fb6df8d8a 100644 --- a/4.4/sensor-src/t41/gc4023.c +++ b/4.4/sensor-src/t41/gc4023.c @@ -28,104 +28,104 @@ // ============================================================================ // SENSOR IDENTIFICATION // ============================================================================ -#define SENSOR_CHIP_ID_H (0x40) -#define SENSOR_CHIP_ID_L (0x23) -#define SENSOR_VERSION "H20230720" -#define SENSOR_NAME "gc4023" -#define SENSOR_TEMP_PROC_NAME "sensorTemp" +#define SENSOR_CHIP_ID_H (0x40) +#define SENSOR_CHIP_ID_L (0x23) +#define SENSOR_VERSION "H20230720" +#define SENSOR_NAME "gc4023" +#define SENSOR_TEMP_PROC_NAME "sensorTemp" // ============================================================================ // REGISTER DEFINITIONS // ============================================================================ -#define SENSOR_REG_END 0xffff -#define SENSOR_REG_DELAY 0x0000 +#define SENSOR_REG_END 0xffff +#define SENSOR_REG_DELAY 0x0000 // ============================================================================ // TIMING AND PERFORMANCE // ============================================================================ -#define SENSOR_SUPPORT_30FPS_SCLK (0x7e9 * 0x4b0 * 2 * 25) -#define SENSOR_SUPPORT_20FPS_SCLK 108*1000*1000 -#define SENSOR_OUTPUT_MAX_FPS 30 -#define SENSOR_OUTPUT_MIN_FPS 5 +#define SENSOR_SUPPORT_30FPS_SCLK (0x7e9 * 0x4b0 * 2 * 25) +#define SENSOR_SUPPORT_20FPS_SCLK 108 * 1000 * 1000 +#define SENSOR_OUTPUT_MAX_FPS 30 +#define SENSOR_OUTPUT_MIN_FPS 5 // ============================================================================ // HARDWARE INTERFACE // ============================================================================ -#define SENSOR_BUS_TYPE TX_SENSOR_CONTROL_INTERFACE_I2C -#define SENSOR_I2C_ADDRESS 0x29 +#define SENSOR_BUS_TYPE TX_SENSOR_CONTROL_INTERFACE_I2C +#define SENSOR_I2C_ADDRESS 0x29 // ============================================================================ // SENSOR CAPABILITIES // ============================================================================ -#define SENSOR_MAX_WIDTH 2560 -#define SENSOR_MAX_HEIGHT 1440 +#define SENSOR_MAX_WIDTH 2560 +#define SENSOR_MAX_HEIGHT 1440 // ============================================================================ // SPECIAL FEATURES // ============================================================================ -#define SENSOR_HIGH_TEMP "highTemp" -#define SENSOR_LOW_TEMP "lowTemp" -#define CAMERA_PROC_NAME "camera" +#define SENSOR_HIGH_TEMP "highTemp" +#define SENSOR_LOW_TEMP "lowTemp" +#define CAMERA_PROC_NAME "camera" -static int reset_gpio = GPIO_PA(18); +static int reset_gpio = GPIO_PA(18); module_param(reset_gpio, int, S_IRUGO); -MODULE_PARM_DESC(reset_gpio, "Reset GPIO NUM"); +MODULE_PARM_DESC(reset_gpio, "Reset GPIO NUM"); -static int pwdn_gpio = -1; +static int pwdn_gpio = -1; module_param(pwdn_gpio, int, S_IRUGO); -MODULE_PARM_DESC(pwdn_gpio, "Power down GPIO NUM"); +MODULE_PARM_DESC(pwdn_gpio, "Power down GPIO NUM"); -static int shvflip = 1; +static int shvflip = 1; module_param(shvflip, int, S_IRUGO); -MODULE_PARM_DESC(shvflip, "Sensor HV Flip Enable interface"); +MODULE_PARM_DESC(shvflip, "Sensor HV Flip Enable interface"); struct proc_dir_entry *g_sinfo_proc; static int sensor_max_fps = TX_SENSOR_MAX_FPS_30; module_param(sensor_max_fps, int, S_IRUGO); -MODULE_PARM_DESC(sensor_max_fps, "Sensor Max Fps set interface"); +MODULE_PARM_DESC(sensor_max_fps, "Sensor Max Fps set interface"); struct regval_list { - uint16_t reg_num; - unsigned char value; + uint16_t reg_num; + unsigned char value; }; -static unsigned char ht_gain = 24; -static unsigned char gain_flag = 0; -static unsigned char ag_last = 0; +static unsigned char ht_gain = 24; +static unsigned char gain_flag = 0; +static unsigned char ag_last = 0; /* Function prototypes */ static int sinfo_proc_open(struct inode *inode, struct file *file); static int data_interface = TX_SENSOR_DATA_INTERFACE_MIPI; module_param(data_interface, int, S_IRUGO); -MODULE_PARM_DESC(data_interface, "Sensor Date interface"); +MODULE_PARM_DESC(data_interface, "Sensor Date interface"); static int data_type = TX_SENSOR_DATA_TYPE_LINEAR; module_param(data_type, int, S_IRUGO); -MODULE_PARM_DESC(data_type, "Sensor Date Type"); +MODULE_PARM_DESC(data_type, "Sensor Date Type"); static int sensor_resolution = TX_SENSOR_RES_400; module_param(sensor_resolution, int, S_IRUGO); -MODULE_PARM_DESC(sensor_resolution, "Sensor resolution"); +MODULE_PARM_DESC(sensor_resolution, "Sensor resolution"); static struct sensor_info sensor_info = { - .name = SENSOR_NAME, - .chip_id = SENSOR_CHIP_ID_H, - .version = SENSOR_VERSION, - .min_fps = SENSOR_OUTPUT_MIN_FPS, - .max_fps = SENSOR_OUTPUT_MAX_FPS, - .actual_fps = 0, - .chip_i2c_addr = SENSOR_I2C_ADDRESS, - .width = SENSOR_MAX_WIDTH, - .height = SENSOR_MAX_HEIGHT, + .name = SENSOR_NAME, + .chip_id = SENSOR_CHIP_ID_H, + .version = SENSOR_VERSION, + .min_fps = SENSOR_OUTPUT_MIN_FPS, + .max_fps = SENSOR_OUTPUT_MAX_FPS, + .actual_fps = 0, + .chip_i2c_addr = SENSOR_I2C_ADDRESS, + .width = SENSOR_MAX_WIDTH, + .height = SENSOR_MAX_HEIGHT, }; static const struct file_operations sinfo_proc_fops = { - .owner = THIS_MODULE, - .open = sinfo_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release + .owner = THIS_MODULE, + .open = sinfo_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; static int sinfo_proc_show(struct seq_file *m, void *v) { @@ -137,7 +137,6 @@ static int sinfo_proc_open(struct inode *inode, struct file *file) { return single_open(file, sinfo_proc_show, NULL); } - /* * the part of driver maybe modify about different sensor and different board. */ @@ -154,31 +153,31 @@ struct again_lut { }; struct again_lut sensor_again_lut[] = { - {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x01, 0x00, 0}, - {0x01, 0x80, 0x02, 0x00, 0x19, 0x19, 0x01, 0x0B, 16208}, - {0x02, 0x01, 0x00, 0x00, 0x19, 0x19, 0x01, 0x19, 32217}, - {0x03, 0x81, 0x02, 0x00, 0x1a, 0x1a, 0x01, 0x2A, 47690}, - {0x04, 0x02, 0x00, 0x00, 0x1b, 0x1b, 0x02, 0x00, 65536}, - {0x05, 0x82, 0x02, 0x00, 0x1c, 0x1c, 0x02, 0x17, 81784}, - {0x06, 0x03, 0x00, 0x00, 0x1d, 0x1d, 0x02, 0x33, 97213}, - {0x07, 0x83, 0x02, 0x00, 0x1e, 0x1e, 0x03, 0x14, 113226}, - {0x08, 0x04, 0x00, 0x00, 0x20, 0x20, 0x04, 0x00, 131072}, - {0x09, 0x80, 0x02, 0x20, 0x22, 0x22, 0x04, 0x2F, 147001}, - {0x0A, 0x01, 0x00, 0x20, 0x23, 0x23, 0x05, 0x26, 162766}, - {0x0B, 0x81, 0x02, 0x20, 0x25, 0x25, 0x06, 0x28, 178990}, - {0x0C, 0x02, 0x00, 0x20, 0x25, 0x25, 0x08, 0x00, 196608}, - {0x0D, 0x82, 0x02, 0x20, 0x26, 0x26, 0x09, 0x1E, 212696}, - {0x0E, 0x03, 0x00, 0x20, 0x26, 0x26, 0x0B, 0x0C, 228446}, - {0x0F, 0x83, 0x02, 0x20, 0x26, 0x26, 0x0D, 0x11, 244419}, - {0x10, 0x04, 0x00, 0x20, 0x27, 0x27, 0x10, 0x00, 262144}, - {0x11, 0x84, 0x02, 0x20, 0x27, 0x27, 0x12, 0x3D, 278158}, - {0x12, 0x05, 0x00, 0x20, 0x28, 0x28, 0x16, 0x19, 293982}, - {0x13, 0x85, 0x02, 0x20, 0x28, 0x28, 0x1A, 0x22, 310012}, - {0x14, 0xb5, 0x04, 0x20, 0x29, 0x29, 0x20, 0x00, 327680}, - {0x15, 0x85, 0x05, 0x20, 0x2a, 0x2a, 0x25, 0x3A, 343731}, - {0x16, 0x05, 0x08, 0x20, 0x2b, 0x2b, 0x2C, 0x33, 359484}, - {0x17, 0x45, 0x09, 0x20, 0x2d, 0x2d, 0x35, 0x05, 375550}, - {0x18, 0x55, 0x0a, 0x20, 0x2e, 0x2e, 0x40, 0x00, 393216}, + {0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x01, 0x00, 0}, + {0x01, 0x80, 0x02, 0x00, 0x19, 0x19, 0x01, 0x0B, 16208}, + {0x02, 0x01, 0x00, 0x00, 0x19, 0x19, 0x01, 0x19, 32217}, + {0x03, 0x81, 0x02, 0x00, 0x1a, 0x1a, 0x01, 0x2A, 47690}, + {0x04, 0x02, 0x00, 0x00, 0x1b, 0x1b, 0x02, 0x00, 65536}, + {0x05, 0x82, 0x02, 0x00, 0x1c, 0x1c, 0x02, 0x17, 81784}, + {0x06, 0x03, 0x00, 0x00, 0x1d, 0x1d, 0x02, 0x33, 97213}, + {0x07, 0x83, 0x02, 0x00, 0x1e, 0x1e, 0x03, 0x14, 113226}, + {0x08, 0x04, 0x00, 0x00, 0x20, 0x20, 0x04, 0x00, 131072}, + {0x09, 0x80, 0x02, 0x20, 0x22, 0x22, 0x04, 0x2F, 147001}, + {0x0A, 0x01, 0x00, 0x20, 0x23, 0x23, 0x05, 0x26, 162766}, + {0x0B, 0x81, 0x02, 0x20, 0x25, 0x25, 0x06, 0x28, 178990}, + {0x0C, 0x02, 0x00, 0x20, 0x25, 0x25, 0x08, 0x00, 196608}, + {0x0D, 0x82, 0x02, 0x20, 0x26, 0x26, 0x09, 0x1E, 212696}, + {0x0E, 0x03, 0x00, 0x20, 0x26, 0x26, 0x0B, 0x0C, 228446}, + {0x0F, 0x83, 0x02, 0x20, 0x26, 0x26, 0x0D, 0x11, 244419}, + {0x10, 0x04, 0x00, 0x20, 0x27, 0x27, 0x10, 0x00, 262144}, + {0x11, 0x84, 0x02, 0x20, 0x27, 0x27, 0x12, 0x3D, 278158}, + {0x12, 0x05, 0x00, 0x20, 0x28, 0x28, 0x16, 0x19, 293982}, + {0x13, 0x85, 0x02, 0x20, 0x28, 0x28, 0x1A, 0x22, 310012}, + {0x14, 0xb5, 0x04, 0x20, 0x29, 0x29, 0x20, 0x00, 327680}, + {0x15, 0x85, 0x05, 0x20, 0x2a, 0x2a, 0x25, 0x3A, 343731}, + {0x16, 0x05, 0x08, 0x20, 0x2b, 0x2b, 0x2C, 0x33, 359484}, + {0x17, 0x45, 0x09, 0x20, 0x2d, 0x2d, 0x35, 0x05, 375550}, + {0x18, 0x55, 0x0a, 0x20, 0x2e, 0x2e, 0x40, 0x00, 393216}, }; struct tx_isp_sensor_attribute sensor_attr; @@ -220,91 +219,90 @@ unsigned int sensor_alloc_dgain(unsigned int isp_gain, unsigned char shift, unsi } struct tx_isp_mipi_bus sensor_mipi_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 702, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 702, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, //RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; - struct tx_isp_mipi_bus sensor_mipi_20fps_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 464, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 464, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, //RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; struct tx_isp_mipi_bus sensor_mipi_15fps_linear = { - .mode = SENSOR_MIPI_OTHER_MODE, - .clk = 352, - .lans = 2, - .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 - .mipi_sc.hcrop_diff_en = 0, - .mipi_sc.mipi_vcomp_en = 0, - .mipi_sc.mipi_hcomp_en = 0, - .image_twidth = 2560, - .image_theight = 1440, - .mipi_sc.mipi_crop_start0x = 0, - .mipi_sc.mipi_crop_start0y = 0, - .mipi_sc.mipi_crop_start1x = 0, - .mipi_sc.mipi_crop_start1y = 0, - .mipi_sc.mipi_crop_start2x = 0, - .mipi_sc.mipi_crop_start2y = 0, - .mipi_sc.mipi_crop_start3x = 0, - .mipi_sc.mipi_crop_start3y = 0, - .mipi_sc.line_sync_mode = 0, - .mipi_sc.work_start_flag = 0, - .mipi_sc.data_type_en = 0, - .mipi_sc.data_type_value = RAW10, - .mipi_sc.del_start = 0, - .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, - .mipi_sc.sensor_fid_mode = 0, - .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, + .mode = SENSOR_MIPI_OTHER_MODE, + .clk = 352, + .lans = 2, + .settle_time_apative_en = 0, + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, //RAW10 + .mipi_sc.hcrop_diff_en = 0, + .mipi_sc.mipi_vcomp_en = 0, + .mipi_sc.mipi_hcomp_en = 0, + .image_twidth = 2560, + .image_theight = 1440, + .mipi_sc.mipi_crop_start0x = 0, + .mipi_sc.mipi_crop_start0y = 0, + .mipi_sc.mipi_crop_start1x = 0, + .mipi_sc.mipi_crop_start1y = 0, + .mipi_sc.mipi_crop_start2x = 0, + .mipi_sc.mipi_crop_start2y = 0, + .mipi_sc.mipi_crop_start3x = 0, + .mipi_sc.mipi_crop_start3y = 0, + .mipi_sc.line_sync_mode = 0, + .mipi_sc.work_start_flag = 0, + .mipi_sc.data_type_en = 0, + .mipi_sc.data_type_value = RAW10, + .mipi_sc.del_start = 0, + .mipi_sc.sensor_frame_mode = TX_SENSOR_DEFAULT_FRAME_MODE, + .mipi_sc.sensor_fid_mode = 0, + .mipi_sc.sensor_mode = TX_SENSOR_DEFAULT_MODE, }; struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { @@ -312,7 +310,7 @@ struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { .clk = 351, .lans = 2, .settle_time_apative_en = 0, - .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10,//RAW10 + .mipi_sc.sensor_csi_fmt = TX_SENSOR_RAW10, //RAW10 .mipi_sc.hcrop_diff_en = 0, .mipi_sc.mipi_vcomp_en = 0, .mipi_sc.mipi_hcomp_en = 0, @@ -337,28 +335,27 @@ struct tx_isp_mipi_bus sensor_mipi_120fps_linear = { }; struct tx_isp_sensor_attribute sensor_attr = { - .name = SENSOR_NAME, - .chip_id = 0x4023, - .cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C, - .cbus_mask = TISP_SBUS_MASK_SAMPLE_8BITS | TISP_SBUS_MASK_ADDR_16BITS, - .dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI, - .data_type = TX_SENSOR_DATA_TYPE_LINEAR, - .cbus_device = 0x29, - .max_again = 393216, - .max_dgain = 0, - .expo_fs = 1, - .min_integration_time = 2, - .min_integration_time_short = 2, - .min_integration_time_native = 2, - .integration_time_apply_delay = 2, - .again_apply_delay = 2, - .dgain_apply_delay = 2, - .sensor_ctrl.alloc_again = sensor_alloc_again, - .sensor_ctrl.alloc_dgain = sensor_alloc_dgain, + .name = SENSOR_NAME, + .chip_id = 0x4023, + .cbus_type = TX_SENSOR_CONTROL_INTERFACE_I2C, + .cbus_mask = TISP_SBUS_MASK_SAMPLE_8BITS | TISP_SBUS_MASK_ADDR_16BITS, + .dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI, + .data_type = TX_SENSOR_DATA_TYPE_LINEAR, + .cbus_device = 0x29, + .max_again = 393216, + .max_dgain = 0, + .expo_fs = 1, + .min_integration_time = 2, + .min_integration_time_short = 2, + .min_integration_time_native = 2, + .integration_time_apply_delay = 2, + .again_apply_delay = 2, + .dgain_apply_delay = 2, + .sensor_ctrl.alloc_again = sensor_alloc_again, + .sensor_ctrl.alloc_dgain = sensor_alloc_dgain, // void priv; /* point to struct tx_isp_sensor_board_info */ }; - static struct regval_list sensor_init_regs_2560_1440_25fps_mipi[] = { /*version 1.2*/ /*mclk 27Mhz*/ @@ -539,7 +536,6 @@ static struct regval_list sensor_init_regs_2560_1440_25fps_24Mmipi[] = { /*row time=22.22us*/ /*bayer order rggb*/ - {0x03fe, 0xf0}, {0x03fe, 0x00}, {0x03fe, 0x10}, @@ -736,7 +732,7 @@ static struct regval_list sensor_init_regs_2560_1440_20fps_mipi[] = { {0x0343, 0xb0}, {0x0259, 0x05}, {0x025a, 0xa0}, - {0x0340, 0x08},//vts -> 0x5dc = 1500 + {0x0340, 0x08}, //vts -> 0x5dc = 1500 {0x0341, 0xca}, {0x0347, 0x02}, {0x0348, 0x0a}, @@ -871,7 +867,6 @@ static struct regval_list sensor_init_regs_2560_1440_20fps_mipi[] = { {SENSOR_REG_END, 0x00}, }; - static struct regval_list sensor_init_regs_2560_1440_15fps_mipi[] = { /*version 1.2*/ /*mclk 27Mhz*/ @@ -907,8 +902,8 @@ static struct regval_list sensor_init_regs_2560_1440_15fps_mipi[] = { {0x0343, 0xb0}, {0x0259, 0x05}, {0x025a, 0xa0}, - {0x0340, 0x0b},//vts -> 1500 - {0x0341, 0xb8},// + {0x0340, 0x0b}, //vts -> 1500 + {0x0341, 0xb8}, // {0x0347, 0x02}, {0x0348, 0x0a}, {0x0349, 0x08}, @@ -1042,7 +1037,6 @@ static struct regval_list sensor_init_regs_2560_1440_15fps_mipi[] = { {SENSOR_REG_END, 0x00}, /* END MARKER */ }; - static struct regval_list sensor_init_regs_1280_360_120fps_mipi[] = { //version 0.5 //mclk 27Mhz @@ -1072,12 +1066,12 @@ static struct regval_list sensor_init_regs_1280_360_120fps_mipi[] = { {0x0315, 0x00}, {0x031c, 0xce}, {0x0219, 0x47}, - {0x0342, 0x04},//hts -> 0x465 = 1125 - {0x0343, 0x65},// + {0x0342, 0x04}, //hts -> 0x465 = 1125 + {0x0343, 0x65}, // {0x0259, 0x01}, {0x025a, 0x8a}, - {0x0340, 0x01},//vts -> 0x190 = 400 - {0x0341, 0x90},// + {0x0340, 0x01}, //vts -> 0x190 = 400 + {0x0341, 0x90}, // {0x0346, 0x01}, {0x0347, 0x68}, {0x0348, 0x0a}, @@ -1217,44 +1211,44 @@ static struct regval_list sensor_init_regs_1280_360_120fps_mipi[] = { static struct tx_isp_sensor_win_setting sensor_win_sizes[] = { /* [0] 2560*1440 @max 30fps*/ { - .width = 2560, - .height = 1440, - .fps = 30 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_25fps_mipi, + .width = 2560, + .height = 1440, + .fps = 30 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_25fps_mipi, }, { - .width = 2560, - .height = 1440, - .fps = 25 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_25fps_24Mmipi, + .width = 2560, + .height = 1440, + .fps = 25 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_25fps_24Mmipi, }, { - .width = 2560, - .height = 1440, - .fps = 20 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_20fps_mipi, + .width = 2560, + .height = 1440, + .fps = 20 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_20fps_mipi, }, { - .width = 2560, - .height = 1440, - .fps = 15 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_2560_1440_15fps_mipi, + .width = 2560, + .height = 1440, + .fps = 15 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_2560_1440_15fps_mipi, }, { - .width = 1280, - .height = 360, - .fps = 120 << 16 | 1, - .mbus_code = TISP_VI_FMT_SRGGB10_1X10, - .colorspace = TISP_COLORSPACE_SRGB, - .regs = sensor_init_regs_1280_360_120fps_mipi, + .width = 1280, + .height = 360, + .fps = 120 << 16 | 1, + .mbus_code = TISP_VI_FMT_SRGGB10_1X10, + .colorspace = TISP_COLORSPACE_SRGB, + .regs = sensor_init_regs_1280_360_120fps_mipi, }, }; @@ -1272,24 +1266,22 @@ static struct regval_list sensor_stream_off[] = { {SENSOR_REG_END, 0x00}, /* END MARKER */ }; -int sensor_read(struct tx_isp_subdev *sd, uint16_t reg, - unsigned char *value) { +int sensor_read(struct tx_isp_subdev *sd, uint16_t reg, unsigned char *value) { struct i2c_client *client = tx_isp_get_subdevdata(sd); uint8_t buf[2] = {(reg >> 8) & 0xff, reg & 0xff}; - struct i2c_msg msg[2] = { - [0] = { - .addr = client->addr, - .flags = 0, - .len = 2, - .buf = buf, - }, + struct i2c_msg msg[2] = {[0] = + { + .addr = client->addr, + .flags = 0, + .len = 2, + .buf = buf, + }, [1] = { - .addr = client->addr, - .flags = I2C_M_RD, - .len = 1, - .buf = value, - } - }; + .addr = client->addr, + .flags = I2C_M_RD, + .len = 1, + .buf = value, + }}; int ret; ret = private_i2c_transfer(client->adapter, msg, 2); if (ret > 0) @@ -1298,15 +1290,14 @@ int sensor_read(struct tx_isp_subdev *sd, uint16_t reg, return ret; } -int sensor_write(struct tx_isp_subdev *sd, uint16_t reg, - unsigned char value) { +int sensor_write(struct tx_isp_subdev *sd, uint16_t reg, unsigned char value) { struct i2c_client *client = tx_isp_get_subdevdata(sd); uint8_t buf[3] = {(reg >> 8) & 0xff, reg & 0xff, value}; struct i2c_msg msg = { - .addr = client->addr, - .flags = 0, - .len = 3, - .buf = buf, + .addr = client->addr, + .flags = 0, + .len = 3, + .buf = buf, }; int ret; ret = private_i2c_transfer(client->adapter, &msg, 1); @@ -1393,7 +1384,8 @@ static int sensor_set_expo(struct tx_isp_subdev *sd, int value) { } /*gain*/ - if (again > ht_gain) again = ht_gain; + if (again > ht_gain) + again = ht_gain; ret = sensor_write(sd, 0x0614, val_lut[again].reg614); ret = sensor_write(sd, 0x0615, val_lut[again].reg615); @@ -1406,7 +1398,7 @@ static int sensor_set_expo(struct tx_isp_subdev *sd, int value) { ag_last = again; if (ret < 0) { - ISP_ERROR("sensor_write error %d",__LINE__ ); + ISP_ERROR("sensor_write error %d", __LINE__); return ret; } @@ -1459,13 +1451,15 @@ static int sensor_set_logic(struct tx_isp_subdev *sd, int value) { ret = sensor_read(sd, 0x0410, ®_410); if (ret < 0) return ret; - if (reg_410 > 0x1a) gain_flag = 1; //0x1d + if (reg_410 > 0x1a) + gain_flag = 1; //0x1d if (gain_flag == 1) { if (reg_410 > 0x16) //0x14 { ht_gain = ht_gain - 1; - if (ht_gain < 21) ht_gain = 21; + if (ht_gain < 21) + ht_gain = 21; } if (reg_410 < 0x10) { ht_gain = ht_gain + 1; @@ -1567,25 +1561,25 @@ static int sensor_set_fps(struct tx_isp_subdev *sd, int fps) { /* return 0; */ switch (sensor->info.default_boot) { - case 0: - case 1: - wpclk = SENSOR_SUPPORT_30FPS_SCLK; - sensor_max_fps = TX_SENSOR_MAX_FPS_30; - break; - case 2: - wpclk = SENSOR_SUPPORT_20FPS_SCLK; - sensor_max_fps = TX_SENSOR_MAX_FPS_20; - break; - case 3: - wpclk = SENSOR_SUPPORT_30FPS_SCLK; - sensor_max_fps = TX_SENSOR_MAX_FPS_15; - break; - case 4: - wpclk = 1125 * 400 * 120 * 2; - sensor_max_fps = TX_SENSOR_MAX_FPS_120; - break; - default: - ISP_ERROR("Now we do not support this framerate!!!\n"); + case 0: + case 1: + wpclk = SENSOR_SUPPORT_30FPS_SCLK; + sensor_max_fps = TX_SENSOR_MAX_FPS_30; + break; + case 2: + wpclk = SENSOR_SUPPORT_20FPS_SCLK; + sensor_max_fps = TX_SENSOR_MAX_FPS_20; + break; + case 3: + wpclk = SENSOR_SUPPORT_30FPS_SCLK; + sensor_max_fps = TX_SENSOR_MAX_FPS_15; + break; + case 4: + wpclk = 1125 * 400 * 120 * 2; + sensor_max_fps = TX_SENSOR_MAX_FPS_120; + break; + default: + ISP_ERROR("Now we do not support this framerate!!!\n"); } /* the format of fps is 16/16. for example 30 << 16 | 2, the value is 30/2 fps. */ @@ -1603,8 +1597,8 @@ static int sensor_set_fps(struct tx_isp_subdev *sd, int fps) { hts = ((hts << 8) + tmp) << 1; vts = wpclk * (fps & 0xffff) / hts / ((fps & 0xffff0000) >> 16); - ret = sensor_write(sd, 0x0340, (unsigned char) ((vts & 0x3f00) >> 8)); - ret += sensor_write(sd, 0x0341, (unsigned char) (vts & 0xff)); + ret = sensor_write(sd, 0x0340, (unsigned char)((vts & 0x3f00) >> 8)); + ret += sensor_write(sd, 0x0341, (unsigned char)(vts & 0xff)); if (ret < 0) return -1; @@ -1640,18 +1634,18 @@ static int sensor_set_vflip(struct tx_isp_subdev *sd, int enable) { val = (val & (~0x3)); /* 2'b01 mirror; 2'b10 flip; 2'b11 mirror &flip */ switch (enable) { - case 0: - sensor_write(sd, 0x022c, val); - break; - case 1: - sensor_write(sd, 0x022c, (val | 0x1)); - break; - case 2: - sensor_write(sd, 0x022c, (val | 0x2)); - break; - case 3: - sensor_write(sd, 0x022c, (val | 0x3)); - break; + case 0: + sensor_write(sd, 0x022c, val); + break; + case 1: + sensor_write(sd, 0x022c, (val | 0x1)); + break; + case 2: + sensor_write(sd, 0x022c, (val | 0x2)); + break; + case 3: + sensor_write(sd, 0x022c, (val | 0x3)); + break; } otp_val = 0x60 | val; ret += sensor_write(sd, 0x0a67, 0x80); @@ -1689,127 +1683,132 @@ static int sensor_attr_check(struct tx_isp_subdev *sd) { int ret = 0; switch (info->default_boot) { - case 0: - wsize = &sensor_win_sizes[0]; - sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; - memcpy(&sensor_attr.mipi, &sensor_mipi_linear, sizeof(sensor_mipi_linear)); - sensor_attr.one_line_expr_in_us = 22; - sensor_attr.total_width = 3840; - sensor_attr.total_height = 1500; - sensor_attr.max_integration_time_native = 1500 - 8; - sensor_attr.integration_time_limit = 1500 - 8; - sensor_attr.max_integration_time = 1500 - 8; - sensor_attr.again = 0; - sensor_attr.integration_time = 0x627; - break; - case 1: - wsize = &sensor_win_sizes[1]; - sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; - memcpy(&sensor_attr.mipi, &sensor_mipi_linear, sizeof(sensor_mipi_linear)); - sensor_attr.one_line_expr_in_us = 22; - sensor_attr.total_width = 3840; - sensor_attr.total_height = 1500; - sensor_attr.max_integration_time_native = 1500 - 8; - sensor_attr.integration_time_limit = 1500 - 8; - sensor_attr.max_integration_time = 1500 - 8; - sensor_attr.again = 0; - sensor_attr.integration_time = 0x627; - break; - case 2: - wsize = &sensor_win_sizes[2]; - sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; - memcpy(&sensor_attr.mipi, &sensor_mipi_20fps_linear, sizeof(sensor_mipi_20fps_linear)); - sensor_attr.one_line_expr_in_us = 33; - sensor_attr.total_width = 2400; - sensor_attr.total_height = 1500; - sensor_attr.max_integration_time_native = 1500 - 8; - sensor_attr.integration_time_limit = 1500 - 8; - sensor_attr.max_integration_time = 1500 - 8; - sensor_attr.again = 0; - sensor_attr.integration_time = 0x627; - break; - case 3: - wsize = &sensor_win_sizes[3]; - sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; - memcpy(&sensor_attr.mipi, &sensor_mipi_15fps_linear, sizeof(sensor_mipi_15fps_linear)); - sensor_attr.one_line_expr_in_us = 44; - sensor_attr.total_width = 2400; - sensor_attr.total_height = 1500; - sensor_attr.max_integration_time_native = 1500 - 8; - sensor_attr.integration_time_limit = 1500 - 8; - sensor_attr.max_integration_time = 1500 - 8; - sensor_attr.again = 0; - sensor_attr.integration_time = 0x627; - break; - case 4: - wsize = &sensor_win_sizes[4]; - sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; - memcpy(&sensor_attr.mipi, &sensor_mipi_120fps_linear, sizeof(sensor_mipi_120fps_linear)); - sensor_attr.one_line_expr_in_us = 44; - sensor_attr.total_width = 2250; - sensor_attr.total_height = 400; - sensor_attr.max_integration_time_native = 1125 - 8; - sensor_attr.integration_time_limit = 1125 - 8; - sensor_attr.max_integration_time = 1125 - 8; - sensor_attr.again = 0; - sensor_attr.integration_time = 0x627; - break; - default: - ISP_ERROR("Have no this Setting Source!!!\n"); + case 0: + wsize = &sensor_win_sizes[0]; + sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; + memcpy(&sensor_attr.mipi, &sensor_mipi_linear, sizeof(sensor_mipi_linear)); + sensor_attr.one_line_expr_in_us = 22; + sensor_attr.total_width = 3840; + sensor_attr.total_height = 1500; + sensor_attr.max_integration_time_native = 1500 - 8; + sensor_attr.integration_time_limit = 1500 - 8; + sensor_attr.max_integration_time = 1500 - 8; + sensor_attr.again = 0; + sensor_attr.integration_time = 0x627; + break; + case 1: + wsize = &sensor_win_sizes[1]; + sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; + memcpy(&sensor_attr.mipi, &sensor_mipi_linear, sizeof(sensor_mipi_linear)); + sensor_attr.one_line_expr_in_us = 22; + sensor_attr.total_width = 3840; + sensor_attr.total_height = 1500; + sensor_attr.max_integration_time_native = 1500 - 8; + sensor_attr.integration_time_limit = 1500 - 8; + sensor_attr.max_integration_time = 1500 - 8; + sensor_attr.again = 0; + sensor_attr.integration_time = 0x627; + break; + case 2: + wsize = &sensor_win_sizes[2]; + sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; + memcpy(&sensor_attr.mipi, &sensor_mipi_20fps_linear, sizeof(sensor_mipi_20fps_linear)); + sensor_attr.one_line_expr_in_us = 33; + sensor_attr.total_width = 2400; + sensor_attr.total_height = 1500; + sensor_attr.max_integration_time_native = 1500 - 8; + sensor_attr.integration_time_limit = 1500 - 8; + sensor_attr.max_integration_time = 1500 - 8; + sensor_attr.again = 0; + sensor_attr.integration_time = 0x627; + break; + case 3: + wsize = &sensor_win_sizes[3]; + sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; + memcpy(&sensor_attr.mipi, &sensor_mipi_15fps_linear, sizeof(sensor_mipi_15fps_linear)); + sensor_attr.one_line_expr_in_us = 44; + sensor_attr.total_width = 2400; + sensor_attr.total_height = 1500; + sensor_attr.max_integration_time_native = 1500 - 8; + sensor_attr.integration_time_limit = 1500 - 8; + sensor_attr.max_integration_time = 1500 - 8; + sensor_attr.again = 0; + sensor_attr.integration_time = 0x627; + break; + case 4: + wsize = &sensor_win_sizes[4]; + sensor_attr.data_type = TX_SENSOR_DATA_TYPE_LINEAR; + memcpy(&sensor_attr.mipi, &sensor_mipi_120fps_linear, sizeof(sensor_mipi_120fps_linear)); + sensor_attr.one_line_expr_in_us = 44; + sensor_attr.total_width = 2250; + sensor_attr.total_height = 400; + sensor_attr.max_integration_time_native = 1125 - 8; + sensor_attr.integration_time_limit = 1125 - 8; + sensor_attr.max_integration_time = 1125 - 8; + sensor_attr.again = 0; + sensor_attr.integration_time = 0x627; + break; + default: + ISP_ERROR("Have no this Setting Source!!!\n"); } switch (info->video_interface) { - case TISP_SENSOR_VI_MIPI_CSI0: - sensor_attr.dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI; - sensor_attr.mipi.index = 0; - break; - case TISP_SENSOR_VI_DVP: - sensor_attr.dbus_type = TX_SENSOR_DATA_INTERFACE_DVP; - break; - default: - ISP_ERROR("Have no this Interface Source!!!\n"); + case TISP_SENSOR_VI_MIPI_CSI0: + sensor_attr.dbus_type = TX_SENSOR_DATA_INTERFACE_MIPI; + sensor_attr.mipi.index = 0; + break; + case TISP_SENSOR_VI_DVP: + sensor_attr.dbus_type = TX_SENSOR_DATA_INTERFACE_DVP; + break; + default: + ISP_ERROR("Have no this Interface Source!!!\n"); } switch (info->mclk) { - case TISP_SENSOR_MCLK0: - case TISP_SENSOR_MCLK1: - case TISP_SENSOR_MCLK2: - sclka = private_devm_clk_get(&client->dev, SEN_MCLK); - sensor->mclk = private_devm_clk_get(sensor->dev, SEN_BCLK); - set_sensor_mclk_function(0); - break; - default: - ISP_ERROR("Have no this MCLK Source!!!\n"); + case TISP_SENSOR_MCLK0: + case TISP_SENSOR_MCLK1: + case TISP_SENSOR_MCLK2: + sclka = private_devm_clk_get(&client->dev, SEN_MCLK); + sensor->mclk = private_devm_clk_get(sensor->dev, SEN_BCLK); + set_sensor_mclk_function(0); + break; + default: + ISP_ERROR("Have no this MCLK Source!!!\n"); } rate = private_clk_get_rate(sensor->mclk); printk("\n====>[private_clk_get_rate(sensor->mclk)=%ld]\n", rate); switch (info->default_boot) { - case 0: - case 1: - case 2: - case 3: - case 4: - if (((rate / 1000) % 27000) != 0) { - ret = clk_set_parent(sclka, clk_get(NULL, SEN_TCLK)); - printk("\n====>[clk_set_parent(sclka, clk_get(NULL, SEN_TCLK:%s))=%d]\n", SEN_TCLK, ret); - sclka = private_devm_clk_get(&client->dev, SEN_TCLK); - if (IS_ERR(sclka)) { - pr_err("get sclka failed\n"); - } else { - rate = private_clk_get_rate(sclka); - printk("\n====>[private_clk_get_rate(sclka)=%ld]\n", rate); - if (((rate / 1000) % 27000) != 0) { - private_clk_set_rate(sclka, 1080000000); - } + case 0: + case 1: + case 2: + case 3: + case 4: + if (((rate / 1000) % 27000) != 0) { + ret = clk_set_parent(sclka, clk_get(NULL, SEN_TCLK)); + printk("\n====>[clk_set_parent(sclka, clk_get(NULL, SEN_TCLK:%s))=%d]\n", SEN_TCLK, ret); + sclka = private_devm_clk_get(&client->dev, SEN_TCLK); + if (IS_ERR(sclka)) { + pr_err("get sclka failed\n"); + } else { + rate = private_clk_get_rate(sclka); + printk("\n====>[private_clk_get_rate(sclka)=%ld]\n", rate); + if (((rate / 1000) % 27000) != 0) { + private_clk_set_rate(sclka, 1080000000); } } - private_clk_set_rate(sensor->mclk, 27000000); - private_clk_prepare_enable(sensor->mclk); - break; + } + private_clk_set_rate(sensor->mclk, 27000000); + private_clk_prepare_enable(sensor->mclk); + break; } - ISP_WARNING("\n====>[default_boot=%d] [resolution=%dx%d] [video_interface=%d] [MCLK=%d] \n", info->default_boot, wsize->width, wsize->height, info->video_interface, info->mclk); + ISP_WARNING("\n====>[default_boot=%d] [resolution=%dx%d] [video_interface=%d] [MCLK=%d] \n", + info->default_boot, + wsize->width, + wsize->height, + info->video_interface, + info->mclk); reset_gpio = info->rst_gpio; pwdn_gpio = info->pwdn_gpio; @@ -1856,10 +1855,17 @@ static int sensor_g_chip_ident(struct tx_isp_subdev *sd, struct tx_isp_chip_iden } ret = sensor_detect(sd, &ident); if (ret) { - ISP_ERROR("chip found @ 0x%x (%s) is not an %s chip.\n", client->addr, client->adapter->name, SENSOR_NAME); + ISP_ERROR("chip found @ 0x%x (%s) is not an %s chip.\n", + client->addr, + client->adapter->name, + SENSOR_NAME); return ret; } - ISP_WARNING("%s chip found @ 0x%02x (%s)\n sensor drv version %s\n", SENSOR_NAME, client->addr, client->adapter->name, SENSOR_VERSION); + ISP_WARNING("%s chip found @ 0x%02x (%s)\n sensor drv version %s\n", + SENSOR_NAME, + client->addr, + client->adapter->name, + SENSOR_VERSION); if (chip) { memcpy(chip->name, SENSOR_NAME, sizeof(SENSOR_NAME)); chip->ident = ident; @@ -1879,51 +1885,51 @@ static int sensor_sensor_ops_ioctl(struct tx_isp_subdev *sd, unsigned int cmd, v } switch (cmd) { #if 1 - case TX_ISP_EVENT_SENSOR_EXPO: - if (arg) - ret = sensor_set_expo(sd, sensor_val->value); - break; + case TX_ISP_EVENT_SENSOR_EXPO: + if (arg) + ret = sensor_set_expo(sd, sensor_val->value); + break; #else - case TX_ISP_EVENT_SENSOR_INT_TIME: - if (arg) - ret = sensor_set_integration_time(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_AGAIN: - if (arg) - ret = sensor_set_analog_gain(sd, sensor_val->value); - break; + case TX_ISP_EVENT_SENSOR_INT_TIME: + if (arg) + ret = sensor_set_integration_time(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_AGAIN: + if (arg) + ret = sensor_set_analog_gain(sd, sensor_val->value); + break; #endif - case TX_ISP_EVENT_SENSOR_DGAIN: - if (arg) - ret = sensor_set_digital_gain(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_BLACK_LEVEL: - if (arg) - ret = sensor_get_black_pedestal(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_RESIZE: - if (arg) - ret = sensor_set_mode(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_PREPARE_CHANGE: - ret = sensor_write_array(sd, sensor_stream_off); - break; - case TX_ISP_EVENT_SENSOR_FINISH_CHANGE: - ret = sensor_write_array(sd, sensor_stream_on); - break; - case TX_ISP_EVENT_SENSOR_FPS: - if (arg) - ret = sensor_set_fps(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_VFLIP: - if (arg) - ret = sensor_set_vflip(sd, sensor_val->value); - break; - case TX_ISP_EVENT_SENSOR_LOGIC: - if (arg) - ret = sensor_set_logic(sd, *(int *) arg); - default: - break; + case TX_ISP_EVENT_SENSOR_DGAIN: + if (arg) + ret = sensor_set_digital_gain(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_BLACK_LEVEL: + if (arg) + ret = sensor_get_black_pedestal(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_RESIZE: + if (arg) + ret = sensor_set_mode(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_PREPARE_CHANGE: + ret = sensor_write_array(sd, sensor_stream_off); + break; + case TX_ISP_EVENT_SENSOR_FINISH_CHANGE: + ret = sensor_write_array(sd, sensor_stream_on); + break; + case TX_ISP_EVENT_SENSOR_FPS: + if (arg) + ret = sensor_set_fps(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_VFLIP: + if (arg) + ret = sensor_set_vflip(sd, sensor_val->value); + break; + case TX_ISP_EVENT_SENSOR_LOGIC: + if (arg) + ret = sensor_set_logic(sd, *(int *)arg); + default: + break; } return ret; @@ -1984,15 +1990,16 @@ static struct tx_isp_subdev_ops sensor_ops = { }; /* It's the sensor device */ -static u64 tx_isp_module_dma_mask = ~(u64) 0; +static u64 tx_isp_module_dma_mask = ~(u64)0; struct platform_device sensor_platform_device = { .name = SENSOR_NAME, .id = -1, - .dev = { - .dma_mask = &tx_isp_module_dma_mask, - .coherent_dma_mask = 0xffffffff, - .platform_data = NULL, - }, + .dev = + { + .dma_mask = &tx_isp_module_dma_mask, + .coherent_dma_mask = 0xffffffff, + .platform_data = NULL, + }, .num_resources = 0, }; @@ -2001,7 +2008,7 @@ static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *i struct tx_isp_video_in *video; struct tx_isp_sensor *sensor; - sensor = (struct tx_isp_sensor *) kzalloc(sizeof(*sensor), GFP_KERNEL); + sensor = (struct tx_isp_sensor *)kzalloc(sizeof(*sensor), GFP_KERNEL); if (!sensor) { ISP_ERROR("Failed to allocate sensor subdev.\n"); return -ENOMEM; @@ -2041,18 +2048,16 @@ static int sensor_remove(struct i2c_client *client) { return 0; } -static const struct i2c_device_id sensor_id[] = { - {SENSOR_NAME, 0}, - {} -}; +static const struct i2c_device_id sensor_id[] = {{SENSOR_NAME, 0}, {}}; MODULE_DEVICE_TABLE(i2c, sensor_id); static struct i2c_driver sensor_driver = { - .driver = { - .owner = THIS_MODULE, - .name = SENSOR_NAME, - }, + .driver = + { + .owner = THIS_MODULE, + .name = SENSOR_NAME, + }, .probe = sensor_probe, .remove = sensor_remove, .id_table = sensor_id, @@ -2078,5 +2083,5 @@ static __exit void exit_sensor(void) { module_init(init_sensor); module_exit(exit_sensor); -MODULE_DESCRIPTION("A low-level driver for "SENSOR_NAME" sensor"); +MODULE_DESCRIPTION("A low-level driver for " SENSOR_NAME " sensor"); MODULE_LICENSE("GPL");