On Fri Feb 21 16:22:15 2025 +0530, Jai Luthra wrote:
> The LLP_MIN of 3560 is only needed to fix artefacts seen with binned
> resolutions. As increasing the LLP reduces the highest possible
> framerate by ~3%, use the old default minimum of 3448 if we are not
> doing 2x2 analog binning.
> 
> Also restore the fll_def value for non-binned modes in the modes
> definition to restore the default mode framerate to 30fps.
> 
> Suggested-by: Dave Stevenson <dave.steven...@raspberrypi.com>
> Link: 
> https://lore.kernel.org/linux-media/capy8ntc1-s6zktdvmc6egyxp+j6rtshug8dr8pkb9xqr2pe...@mail.gmail.com/
> Signed-off-by: Jai Luthra <jai.lut...@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo.mo...@ideasonboard.com>
> Signed-off-by: Sakari Ailus <sakari.ai...@linux.intel.com>
> Signed-off-by: Hans Verkuil <hverk...@xs4all.nl>

Patch committed.

Thanks,
Hans Verkuil

 drivers/media/i2c/imx219.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

---

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 4542ab28a6e9..04262bbf6306 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -74,7 +74,8 @@
 #define IMX219_FLL_MAX                 0xffff
 #define IMX219_VBLANK_MIN              32
 #define IMX219_REG_LINE_LENGTH_A       CCI_REG16(0x0162)
-#define IMX219_LLP_MIN                 0x0de8
+#define IMX219_LLP_MIN                 0x0d78
+#define IMX219_BINNED_LLP_MIN          0x0de8
 #define IMX219_LLP_MAX                 0x7ff0
 
 #define IMX219_REG_X_ADD_STA_A         CCI_REG16(0x0164)
@@ -311,13 +312,13 @@ static const struct imx219_mode supported_modes[] = {
                /* 8MPix 15fps mode */
                .width = 3280,
                .height = 2464,
-               .fll_def = 3415,
+               .fll_def = 3526,
        },
        {
                /* 1080P 30fps cropped */
                .width = 1920,
                .height = 1080,
-               .fll_def = 1707,
+               .fll_def = 1763,
        },
        {
                /* 2x2 binned 60fps mode */
@@ -865,7 +866,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
        const struct imx219_mode *mode;
        struct v4l2_mbus_framefmt *format;
        struct v4l2_rect *crop;
-       unsigned int bin_h, bin_v;
+       u8 bin_h, bin_v;
        u32 prev_line_len;
 
        format = v4l2_subdev_state_get_format(state, 0);
@@ -895,7 +896,7 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
        if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
                int exposure_max;
                int exposure_def;
-               int hblank;
+               int hblank, llp_min;
                int pixel_rate;
 
                /* Update limits and set FPS to default */
@@ -912,6 +913,19 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
                                         imx219->exposure->minimum,
                                         exposure_max, imx219->exposure->step,
                                         exposure_def);
+
+               /*
+                * With analog binning the default minimum line length of 3448
+                * can cause artefacts with RAW10 formats, because the ADC
+                * operates on two lines together. So we switch to a higher
+                * minimum of 3560.
+                */
+               imx219_get_binning(state, &bin_h, &bin_v);
+               llp_min = (bin_h & bin_v) == IMX219_BINNING_X2_ANALOG ?
+                                 IMX219_BINNED_LLP_MIN : IMX219_LLP_MIN;
+               __v4l2_ctrl_modify_range(imx219->hblank, llp_min - mode->width,
+                                        IMX219_LLP_MAX - mode->width, 1,
+                                        llp_min - mode->width);
                /*
                 * Retain PPL setting from previous mode so that the
                 * line time does not change on a mode change.
@@ -920,10 +934,6 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
                 * mode width subtracted.
                 */
                hblank = prev_line_len - mode->width;
-               __v4l2_ctrl_modify_range(imx219->hblank,
-                                        IMX219_LLP_MIN - mode->width,
-                                        IMX219_LLP_MAX - mode->width, 1,
-                                        IMX219_LLP_MIN - mode->width);
                __v4l2_ctrl_s_ctrl(imx219->hblank, hblank);
 
                /* Scale the pixel rate based on the mode specific factor */

Reply via email to