From 5cede1ef85a4aaa147b31e81e4f79ed54cc0bd13 Mon Sep 17 00:00:00 2001 From: dchvs Date: Mon, 8 Mar 2021 16:28:55 -0600 Subject: [PATCH 1/6] Fix dotted image --- .../tegra186-tx2-spiri-camera.dtsi | 44 +++++++++---------- .../nvidia-spiri/drivers/media/i2c/mt9m021.c | 20 ++++----- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi index 6928c01..85a4543 100644 --- a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi +++ b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi @@ -98,25 +98,25 @@ i2c8 = "/i2c@31e0000"; inherent_gain = "1"; pix_clk_hz = "74250000"; - gain_factor = "3125"; - framerate_factor = "1000000"; - exposure_factor = "1000000"; - min_gain_val = "100000"; - max_gain_val = "796000"; - step_gain_val = "1"; - default_gain = "100000"; + gain_factor = "3"; + framerate_factor = "1000000"; + exposure_factor = "1000000"; //"1000000"; + min_gain_val = "100"; + max_gain_val = "762"; + step_gain_val = "1"; + default_gain = "100"; min_hdr_ratio = "1"; max_hdr_ratio = "1"; min_framerate = "2000000"; max_framerate = "60000000"; step_framerate = "1"; - default_framerate = "60000000"; // 60.0 fps + default_framerate = "60000000"; // 60.0 fps - min_exp_time = "500"; // us - max_exp_time = "16000"; // us + min_exp_time = "23000"; // us + max_exp_time = "1000000"; // us step_exp_time = "1"; - default_exp_time = "12000"; // us + default_exp_time = "40000"; // us }; ports { #address-cells = <0x1>; @@ -185,25 +185,25 @@ i2c8 = "/i2c@31e0000"; inherent_gain = "1"; pix_clk_hz = "74250000"; - gain_factor = "3125"; - framerate_factor = "1000000"; - exposure_factor = "1000000"; - min_gain_val = "100000"; - max_gain_val = "796000"; - step_gain_val = "1"; - default_gain = "100000"; + gain_factor = "3"; + framerate_factor = "1000000"; + exposure_factor = "1000000"; + min_gain_val = "100"; + max_gain_val = "762"; + step_gain_val = "1"; + default_gain = "100"; min_hdr_ratio = "1"; max_hdr_ratio = "1"; min_framerate = "2000000"; max_framerate = "60000000"; step_framerate = "1"; - default_framerate = "60000000"; // 60.0 fps + default_framerate = "60000000"; // 60.0 fps - min_exp_time = "500"; // us - max_exp_time = "16000"; // us + min_exp_time = "23000"; // us + max_exp_time = "1000000"; // us step_exp_time = "1"; - default_exp_time = "12000"; // us + default_exp_time = "40000"; // us }; ports { #address-cells = <0x1>; diff --git a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c index 7af9435..67ec898 100644 --- a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c +++ b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c @@ -135,8 +135,8 @@ #define MT9M021_ANALOG_GAIN_SHIFT 4 #define MT9M021_ANALOG_GAIN_MASK 0x0030 -#define MT9M021_GLOBAL_GAIN_MIN 100000 -#define MT9M021_GLOBAL_GAIN_MAX 796000 +#define MT9M021_GLOBAL_GAIN_MIN 100 +#define MT9M021_GLOBAL_GAIN_MAX 762 #define MT9M021_GLOBAL_GAIN_DEF 100 #define MT9M021_COARSE_INT_TIME_MIN 0x0001 @@ -420,15 +420,15 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) * GAIN: VAL / STEPS; * STEPS: 1/32 * - * SCALE FACTOR = 100.000 + * SCALE FACTOR = 32 * - * min_gain_val = 100.000 - * max_gain_val = 797.000 - * gain_factor = 3125 + * min_gain_val = 100 + * max_gain_val = 762 + * gain_factor = 3 * * gain maps to range 32 - 255 */ - gain = val / 3125; + gain = val / 3; /* Update analog gain multiplier */ err = mt9m021_read_reg16(s_data, MT9M021_DIGITAL_TEST, ®16); @@ -527,12 +527,12 @@ static int mt9m021_set_coarse_time(struct mt9m021 *priv, s64 val) static int mt9m021_set_exposure(struct tegracam_device *tc_dev, s64 val) { - struct camera_common_data *s_data = tc_dev->s_data; + struct camera_common_data *s_data = tc_dev->s_data; struct mt9m021 *priv = (struct mt9m021 *)tc_dev->priv; struct device *dev = tc_dev->dev; - const struct sensor_mode_properties *mode = + const struct sensor_mode_properties *mode = &s_data->sensor_props.sensor_modes[s_data->mode]; - u64 coarse_time; + u64 coarse_time; int err = 0; dev_dbg(dev, "Setting Exposure Time to : %lld", val); From abc331988f0dd5403ab58548d5905bbde19e070f Mon Sep 17 00:00:00 2001 From: dchvs Date: Wed, 10 Mar 2021 17:59:54 -0600 Subject: [PATCH 2/6] Fix dotted image -- still have some blinking --- .../tegra186-tx2-spiri-camera.dtsi | 26 +++++++++---------- .../nvidia-spiri/drivers/media/i2c/mt9m021.c | 9 ++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi index 85a4543..dae2433 100644 --- a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi +++ b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi @@ -100,11 +100,11 @@ i2c8 = "/i2c@31e0000"; gain_factor = "3"; framerate_factor = "1000000"; - exposure_factor = "1000000"; //"1000000"; - min_gain_val = "100"; + exposure_factor = "1000000"; + min_gain_val = "102"; max_gain_val = "762"; step_gain_val = "1"; - default_gain = "100"; + default_gain = "102"; min_hdr_ratio = "1"; max_hdr_ratio = "1"; @@ -113,10 +113,10 @@ i2c8 = "/i2c@31e0000"; step_framerate = "1"; default_framerate = "60000000"; // 60.0 fps - min_exp_time = "23000"; // us - max_exp_time = "1000000"; // us - step_exp_time = "1"; - default_exp_time = "40000"; // us + min_exp_time = "24000"; // us + max_exp_time = "74000"; // us + step_exp_time = "1"; + default_exp_time = "50000"; // us }; ports { #address-cells = <0x1>; @@ -188,10 +188,10 @@ i2c8 = "/i2c@31e0000"; gain_factor = "3"; framerate_factor = "1000000"; exposure_factor = "1000000"; - min_gain_val = "100"; + min_gain_val = "102"; max_gain_val = "762"; step_gain_val = "1"; - default_gain = "100"; + default_gain = "102"; min_hdr_ratio = "1"; max_hdr_ratio = "1"; @@ -200,10 +200,10 @@ i2c8 = "/i2c@31e0000"; step_framerate = "1"; default_framerate = "60000000"; // 60.0 fps - min_exp_time = "23000"; // us - max_exp_time = "1000000"; // us - step_exp_time = "1"; - default_exp_time = "40000"; // us + min_exp_time = "24000"; // us + max_exp_time = "74000"; // us + step_exp_time = "1"; + default_exp_time = "50000"; // us }; ports { #address-cells = <0x1>; diff --git a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c index 67ec898..7443a06 100644 --- a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c +++ b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c @@ -439,14 +439,13 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) ((gain_mul << MT9M021_ANALOG_GAIN_SHIFT) & MT9M021_ANALOG_GAIN_MASK); err = mt9m021_write_reg16(s_data, MT9M021_DIGITAL_TEST, reg16); -// msleep(10); if (err) goto exit; /* Update global gain */ err = mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN, gain); -// msleep(10); +// msleep(10); if (err) goto exit; err = @@ -454,6 +453,8 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) if (err) goto exit; +// usleep_range(1000, 1500); + return 0; exit: @@ -473,7 +474,7 @@ static int mt9m021_set_frame_length(struct mt9m021 *priv, s64 val) err = mt9m021_write_reg16(s_data, MT9M021_FRAME_LENGTH_LINES, val); if (err) return err; - msleep(30); + msleep(30); return 0; } @@ -520,7 +521,7 @@ static int mt9m021_set_coarse_time(struct mt9m021 *priv, s64 val) err = mt9m021_write_reg16(s_data, MT9M021_COARSE_INT_TIME_CB, val); if (err) return err; -// msleep(30); +//msleep(30); return 0; } From e4327010bd85004c8e92024dd18ffcd544ec661a Mon Sep 17 00:00:00 2001 From: dchvs Date: Wed, 10 Mar 2021 18:23:42 -0600 Subject: [PATCH 3/6] Fix dotted image -- with fixed blinking --- .../t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi index dae2433..9a8bbcf 100644 --- a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi +++ b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi @@ -102,7 +102,7 @@ i2c8 = "/i2c@31e0000"; framerate_factor = "1000000"; exposure_factor = "1000000"; min_gain_val = "102"; - max_gain_val = "762"; + max_gain_val = "160"; step_gain_val = "1"; default_gain = "102"; min_hdr_ratio = "1"; @@ -189,7 +189,7 @@ i2c8 = "/i2c@31e0000"; framerate_factor = "1000000"; exposure_factor = "1000000"; min_gain_val = "102"; - max_gain_val = "762"; + max_gain_val = "160" ; //"762"; step_gain_val = "1"; default_gain = "102"; min_hdr_ratio = "1"; From 809d88dd935595fb8165ce2c15dcda02bb13792e Mon Sep 17 00:00:00 2001 From: dchvs Date: Mon, 15 Mar 2021 21:41:54 -0600 Subject: [PATCH 4/6] documentation: Update README --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 19dc4b2..e63c457 100644 --- a/README.md +++ b/README.md @@ -105,23 +105,24 @@ As the AE has interdependency with the digital gain. This gain it's and operatio * Digital gain equation: * * RANGE: 1x, 7.97x - * GAIN: VAL / STEPS; * STEPS: 1/32 * - * SCALE FACTOR = 100.000 + * SCALE FACTOR = 3 * - * min_gain_val = 100.000 - * max_gain_val = 797.000 - * step_gain_val = 3125 + * min_gain_val = 102 + * max_gain_val = 160 + * gain_factor = 3 + * + * gain accepts mapping to range 32 - 53 */ - - MT9M021 sensor datasheet: - * MT9M021 Developer Guide ``` + MT9M021 sensor datasheet: + + * MT9M021 Developer Guide -Where, the min_gain_val, max_gain_val, step_gain_val are part of the cameras' DTSI (tegra186-tx2-spiri-camera.dtsi) fixed parameters -as per the datasheet. The step_gain_val consists of the steps (1/32 for the register) scaled to a value that makes this fraction become an significant -in integer. + +Where, the `min_gain_val, max_gain_val, step_gain_val` are part of the cameras' DTSI (tegra186-tx2-spiri-camera.dtsi) fixed parameters +as per the datasheet. The `gain` consists on the steps (1x + n * 1/32 for the register) scaled to a value that represents this fraction in an integer value for the gain register. #### Kernel Changes From d4df26e9f987dbac7097c728ce81c6bd1957910c Mon Sep 17 00:00:00 2001 From: dchvs Date: Mon, 15 Mar 2021 22:22:34 -0600 Subject: [PATCH 5/6] documentation: Fix gain equation on Driver --- kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c index 7443a06..f0ca5b2 100644 --- a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c +++ b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c @@ -417,16 +417,15 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) * Digital gain equation: * * RANGE: 1x, 7.97x - * GAIN: VAL / STEPS; * STEPS: 1/32 * - * SCALE FACTOR = 32 + * SCALE FACTOR = 3 * - * min_gain_val = 100 - * max_gain_val = 762 + * min_gain_val = 102 + * max_gain_val = 160 * gain_factor = 3 * - * gain maps to range 32 - 255 + * gain accepts mapping to range 32 - 53 */ gain = val / 3; From e00ce6abcc010a623fbddddd537a7dbca468d9ea Mon Sep 17 00:00:00 2001 From: dchvs Date: Mon, 15 Mar 2021 22:27:57 -0600 Subject: [PATCH 6/6] Clean up comments in the code --- .../tegra186-tx2-spiri-camera.dtsi | 2 +- kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi index 9a8bbcf..1734d40 100644 --- a/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi +++ b/hardware/nvidia-spiri/platform/t18x/common/kernel-dts/t18x-common-platforms/tegra186-tx2-spiri-camera.dtsi @@ -189,7 +189,7 @@ i2c8 = "/i2c@31e0000"; framerate_factor = "1000000"; exposure_factor = "1000000"; min_gain_val = "102"; - max_gain_val = "160" ; //"762"; + max_gain_val = "160" ; step_gain_val = "1"; default_gain = "102"; min_hdr_ratio = "1"; diff --git a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c index f0ca5b2..e968908 100644 --- a/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c +++ b/kernel/nvidia-spiri/drivers/media/i2c/mt9m021.c @@ -444,7 +444,6 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) /* Update global gain */ err = mt9m021_write_reg16(s_data, MT9M021_GLOBAL_GAIN, gain); -// msleep(10); if (err) goto exit; err = @@ -452,8 +451,6 @@ static int mt9m021_set_gain(struct tegracam_device *tc_dev, s64 val) if (err) goto exit; -// usleep_range(1000, 1500); - return 0; exit: @@ -520,7 +517,6 @@ static int mt9m021_set_coarse_time(struct mt9m021 *priv, s64 val) err = mt9m021_write_reg16(s_data, MT9M021_COARSE_INT_TIME_CB, val); if (err) return err; -//msleep(30); return 0; } @@ -571,7 +567,6 @@ static int mt9m021_set_analog_gain(struct tegracam_device *tc_dev, s64 val) ((val << MT9M021_ANALOG_GAIN_SHIFT) & MT9M021_ANALOG_GAIN_MASK); err = mt9m021_write_reg16(s_data, MT9M021_DIGITAL_TEST, reg16); -// msleep(30); if (err) goto exit; @@ -627,7 +622,6 @@ static int mt9m021_set_digital_gain(struct tegracam_device *tc_dev, s64 val, err = mt9m021_write_reg16(s_data, gain_cb_reg, val); if (err) goto exit; -// msleep(30); return 0; @@ -650,7 +644,6 @@ static int mt9m021_set_test_pattern(struct tegracam_device *tc_dev, s32 val) else err = mt9m021_write_reg16(s_data, MT9M021_TEST_PATTERN, val); -// msleep(30); if (err) goto exit; @@ -963,15 +956,10 @@ static int mt9m021_col_correction(struct mt9m021 *priv) if (ret < 0) return ret; -// msleep(200); -// usleep(200); - /* Enable Streaming */ ret = mt9m021_write_table(priv, mode_table[MT9M021_MODE_START_STREAM]); if (ret < 0) return ret; -// msleep(200); -// usleep(200); /* Disable Streaming */ ret = mt9m021_write_table(priv, mode_table[MT9M021_MODE_STOP_STREAM]); @@ -982,8 +970,6 @@ static int mt9m021_col_correction(struct mt9m021 *priv) ret = mt9m021_write_reg16(s_data, MT9M021_COLUMN_CORRECTION, 0xE007); if (ret < 0) return ret; -// msleep(200); -// usleep(200); return ret; }