60f489c6c08f52632d649dda605a630520466588
[openwrt/staging/ansuel.git] /
1 From f364e0eb8f973e1aa24a3c451d18e84247a8efcd Mon Sep 17 00:00:00 2001
2 From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
3 Date: Wed, 8 Nov 2023 10:57:45 +0000
4 Subject: [PATCH] drivers: media: imx708: Adjust broken line correction
5 parameter
6
7 In full-resolution mode, the LPF_INTENSITY_EN and LPF_INTENSITY
8 registers control Quad Bayer Re-mosaic broken line correction.
9 Expose this as a module parameter "qbc_adjust": zero disables
10 the correction and values in the range 2 to 5 set its strength.
11
12 There is a trade-off between coloured and monochrome patterns.
13 The previous fixed value 4 could produce ladder/spots artefacts
14 in coloured textures. The new default value 2 may suit a wider
15 range of scenes.
16
17 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
18 ---
19 drivers/media/i2c/imx708.c | 50 ++++++++++++++++++++++++++++++++------
20 1 file changed, 42 insertions(+), 8 deletions(-)
21
22 --- a/drivers/media/i2c/imx708.c
23 +++ b/drivers/media/i2c/imx708.c
24 @@ -20,6 +20,14 @@
25 #include <media/v4l2-fwnode.h>
26 #include <media/v4l2-mediabus.h>
27
28 +/*
29 + * Parameter to adjust Quad Bayer re-mosaic broken line correction
30 + * strength, used in full-resolution mode only. Set zero to disable.
31 + */
32 +static int qbc_adjust = 2;
33 +module_param(qbc_adjust, int, 0644);
34 +MODULE_PARM_DESC(qbc_adjust, "Quad Bayer broken line correction strength [0,2-5]");
35 +
36 #define IMX708_REG_VALUE_08BIT 1
37 #define IMX708_REG_VALUE_16BIT 2
38
39 @@ -99,11 +107,17 @@
40
41 /* HDR exposure ratio (long:med == med:short) */
42 #define IMX708_HDR_EXPOSURE_RATIO 4
43 -#define IMX708_REG_MID_EXPOSURE 0x3116
44 -#define IMX708_REG_SHT_EXPOSURE 0x0224
45 +#define IMX708_REG_MID_EXPOSURE 0x3116
46 +#define IMX708_REG_SHT_EXPOSURE 0x0224
47 #define IMX708_REG_MID_ANALOG_GAIN 0x3118
48 #define IMX708_REG_SHT_ANALOG_GAIN 0x0216
49
50 +/* QBC Re-mosaic broken line correction registers */
51 +#define IMX708_LPF_INTENSITY_EN 0xC428
52 +#define IMX708_LPF_INTENSITY_ENABLED 0x00
53 +#define IMX708_LPF_INTENSITY_DISABLED 0x01
54 +#define IMX708_LPF_INTENSITY 0xC429
55 +
56 /*
57 * Metadata buffer holds a variety of data, all sent with the same VC/DT (0x12).
58 * It comprises two scanlines (of up to 5760 bytes each, for 4608 pixels)
59 @@ -171,6 +185,9 @@ struct imx708_mode {
60
61 /* HDR flag, used for checking if the current mode is HDR */
62 bool hdr;
63 +
64 + /* Quad Bayer Re-mosaic flag */
65 + bool remosaic;
66 };
67
68 /* Default PDAF pixel correction gains */
69 @@ -363,8 +380,6 @@ static const struct imx708_reg mode_4608
70 {0x341f, 0x20},
71 {0x3420, 0x00},
72 {0x3421, 0xd8},
73 - {0xC428, 0x00},
74 - {0xC429, 0x04},
75 {0x3366, 0x00},
76 {0x3367, 0x00},
77 {0x3368, 0x00},
78 @@ -677,7 +692,8 @@ static const struct imx708_mode supporte
79 .pixel_rate = 595200000,
80 .exposure_lines_min = 8,
81 .exposure_lines_step = 1,
82 - .hdr = false
83 + .hdr = false,
84 + .remosaic = true
85 },
86 {
87 /* regular 2x2 binned. */
88 @@ -699,7 +715,8 @@ static const struct imx708_mode supporte
89 .pixel_rate = 585600000,
90 .exposure_lines_min = 4,
91 .exposure_lines_step = 2,
92 - .hdr = false
93 + .hdr = false,
94 + .remosaic = false
95 },
96 {
97 /* 2x2 binned and cropped for 720p. */
98 @@ -721,7 +738,8 @@ static const struct imx708_mode supporte
99 .pixel_rate = 566400000,
100 .exposure_lines_min = 4,
101 .exposure_lines_step = 2,
102 - .hdr = false
103 + .hdr = false,
104 + .remosaic = false
105 },
106 };
107
108 @@ -746,7 +764,8 @@ static const struct imx708_mode supporte
109 .pixel_rate = 777600000,
110 .exposure_lines_min = 8 * IMX708_HDR_EXPOSURE_RATIO * IMX708_HDR_EXPOSURE_RATIO,
111 .exposure_lines_step = 2 * IMX708_HDR_EXPOSURE_RATIO * IMX708_HDR_EXPOSURE_RATIO,
112 - .hdr = true
113 + .hdr = true,
114 + .remosaic = false
115 }
116 };
117
118 @@ -1515,6 +1534,21 @@ static int imx708_start_streaming(struct
119 return ret;
120 }
121
122 + /* Quad Bayer re-mosaic adjustments (for full-resolution mode only) */
123 + if (imx708->mode->remosaic && qbc_adjust > 0) {
124 + imx708_write_reg(imx708, IMX708_LPF_INTENSITY,
125 + IMX708_REG_VALUE_08BIT, qbc_adjust);
126 + imx708_write_reg(imx708,
127 + IMX708_LPF_INTENSITY_EN,
128 + IMX708_REG_VALUE_08BIT,
129 + IMX708_LPF_INTENSITY_ENABLED);
130 + } else {
131 + imx708_write_reg(imx708,
132 + IMX708_LPF_INTENSITY_EN,
133 + IMX708_REG_VALUE_08BIT,
134 + IMX708_LPF_INTENSITY_DISABLED);
135 + }
136 +
137 /* Apply customized values from user */
138 ret = __v4l2_ctrl_handler_setup(imx708->sd.ctrl_handler);
139 if (ret)