From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26F113D9043 for ; Mon, 11 May 2026 10:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778496202; cv=none; b=P/dtUvUrjq80p1aUTPMp2Iz64jUIZxbrvL6Cs80SQTH1U4EvWPYXe/QXa4oDxHoQ79cojCOK5oGyHqMm8SieUDORkZKirgcW2rh7f3tHAQe/o3qiYT5bE4q3rU80bsAVoPlDv99BLYCwFxFYhfrWWy0UYX6xJQbq+zUwLXvU8jI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778496202; c=relaxed/simple; bh=Arh65FwgpuoQyK0HMQPAmmIpzCVfFvZU3gN/HmExq5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FpDhwulw4otB8IPnNm0nSAFl0ZszuxW6jkrAoJiZyI8D1GJrwX52qzwhLPyWuFDYLXy68BlhFtPMBlRjMZ0q9bXHaHjB6wVRuRks3Us9zj342sxydmTNTdvR7FW02qK46LFGEe41ktmznRrM9WX7Q5140CIbD2Xk7BiCKaU0dYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GTribr/m; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GTribr/m" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-3653cb9c6f8so3477709a91.0 for ; Mon, 11 May 2026 03:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778496200; x=1779101000; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DRXDOC53itDbvSH3E3HyxAV1yZ2/7SesuEGqqAx3Huo=; b=GTribr/mh2Ti4TE9bjSPs5RsdDpXreue5rGGMRR1P1ZMU1ZFvxd/TC5rileFOBOlUZ kggNLzORFR0NgyhBWFZiVH+XHO79bZHPLpvNiYi59gC6jWng6hMYw/mHEWj6t1wMPTGX PROPxdSpGnqTBBgPtqWNMOgR3FKdsJG8NeqamqsI+5txPgvNxVypDQ2Y50gi9Q68qY2q HhZ4tkEbo6oIFsdwkE/F5Mbj62NNsl0Q6vn3NLaYxb+cBe68GTLtN9D8gg4AmXyS2vvi QxufEjeT7ljXeHv97ITsh+EP7yLbVdHoKcpWEOWbriPauJQos3tPyAYwQeKDl51YlDBw V62A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778496200; x=1779101000; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DRXDOC53itDbvSH3E3HyxAV1yZ2/7SesuEGqqAx3Huo=; b=qNTwML1npk4tRi4MuU9LubqAkp0rGumqfZFBa70gE+Xr2+SLLYotwsRPBpzOAwWrIM 2QXui2BpxQ10UYD3tw8rcHswK97/kSkiwiNR4KGYq6sfeYn07pPg6Md7yTTEzZtxqbhS DtvXhx++KKsjWT6fgIITguj+tUzSrCs/zQDSqI2CnjuJ1lkEcUjzQ+kvKM2q79JR3LFD LlSBX67yV0wKvLG/00xbYgXZVkCVJFdZcdSoGK/VWKhXjm3f993gsGt+4H295LIHy29p E73ZEsEAmeV7OlOUWE00NSlYp7i/3mueJ9JvCqi4/hT2Qwr46CX8whXy6aZF3SjK5L/Z 7EUA== X-Forwarded-Encrypted: i=1; AFNElJ8+giDrByOBywik3nUsWfoMtIzdCyfg8etnJNyq8FYuMcZgOmhvVaQCxFNnC4q1KNbiyQX8P5XXyvsxfGQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0AKch8Zr1JoSlMI8GZR3gAUCjMT2IS0JZfAfK6BgN+DrqQy+a 1yjfsm1Q5r1/TitDVg91OVudHV36F8fSoYHdF6ufujGihfyN25kbgGOg X-Gm-Gg: Acq92OHVFwxJdQ8jD2uOoZhrhpNDv/3rzb+DgWL+zEadzKjBPkL6mzFFGelHVWAR7Sh tI6l+2B2G2Jhe3gsTDs44VTgoefdVuqe6BkIXOLJjhN5R8ZR59d7Pu8bVC0u1xHoXTuxqUQXo9Y rvKa8ituIDqTDtwFoQe9eU88RPzdEIvSsG2RoH8sdIWaH6+7zpJFBpnKZTexkRtfnjnPjUF82bS 2kHpJgF2DT8R7Dp8Erhgs0C4gX3CqMvQpT0+utUrs0P0MzS1aeIxjnWsqL8c/rmNQ5/493t08rS f2Bc1gy0Ft6/0ylHptPUAATEoI+9q6OmNgoRKfG+05Q9/U/fgvmhh9TpYVCu8nswg+tBxxLfjNr Yu9vejYJbJQpvi4yHYPo6Bea+u5oVzUFXW6LUrqJm17N8TR7M7qdZRqvAZDZMhqEaugAFZU0KHC PFJ89IIrElZhJALVl56kODEkZMUDL8 X-Received: by 2002:a17:90b:3903:b0:367:f9f1:af78 with SMTP id 98e67ed59e1d1-367f9f1b66amr8598826a91.7.1778496200549; Mon, 11 May 2026 03:43:20 -0700 (PDT) Received: from nuvole ([144.202.86.13]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d684009esm7533423a91.11.2026.05.11.03.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2026 03:43:20 -0700 (PDT) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Sakari Ailus , Martin Kepplinger-Novakovic , Mauro Carvalho Chehab , Hans Verkuil , Sebastian Krzyszkowiak Cc: devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Pengyu Luo Subject: [PATCH v4 3/5] media: hi846: fix modes handling for different lane cases Date: Mon, 11 May 2026 18:39:25 +0800 Message-ID: <20260511103927.279550-4-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260511103927.279550-1-mitltlatltl@gmail.com> References: <20260511103927.279550-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When using 4-lane, v4l2_find_nearest_size may return an unsupported mode, 640x480 mode, and it is set to the default mode. To fix it, specifying the supported modes for different lane cases, once the lane count is determined. Reported-by: Sebastian Krzyszkowiak Closes: https://lore.kernel.org/linux-media/OmTXoHZJTSGePymL9I-1Cw@puri.sm/ Fixes: e8c0882685f9 ("media: i2c: add driver for the SK Hynix Hi-846 8M pixel camera") Signed-off-by: Pengyu Luo --- drivers/media/i2c/hi846.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c index 61297ef66a0e..c77b34a5e166 100644 --- a/drivers/media/i2c/hi846.c +++ b/drivers/media/i2c/hi846.c @@ -1130,6 +1130,8 @@ static const struct hi846_mode supported_modes[] = { }, } }; +#define NUM_MODES_2LANE ARRAY_SIZE(supported_modes) +#define NUM_MODES_4LANE (ARRAY_SIZE(supported_modes) - 1) struct hi846_datafmt { u32 code; @@ -1162,6 +1164,8 @@ struct hi846 { struct mutex mutex; /* protect cur_mode, streaming and chip access */ const struct hi846_mode *cur_mode; + const struct hi846_mode *supported_modes; + int num_modes; bool streaming; }; @@ -1736,8 +1740,8 @@ static int hi846_set_format(struct v4l2_subdev *sd, hi846->fmt = fmt; hi846->cur_mode = - v4l2_find_nearest_size(supported_modes, - ARRAY_SIZE(supported_modes), + v4l2_find_nearest_size(hi846->supported_modes, + hi846->num_modes, width, height, mf->width, mf->height); dev_dbg(&client->dev, "%s: found mode: %dx%d\n", __func__, hi846->cur_mode->width, hi846->cur_mode->height); @@ -1821,8 +1825,11 @@ static int hi846_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_frame_size_enum *fse) { struct i2c_client *client = v4l2_get_subdevdata(sd); + struct hi846 *hi846 = to_hi846(sd); + const struct hi846_mode *supported_modes = hi846->supported_modes; + - if (fse->pad || fse->index >= ARRAY_SIZE(supported_modes)) + if (fse->pad || fse->index >= hi846->num_modes) return -EINVAL; if (fse->code != HI846_MEDIA_BUS_FORMAT) { @@ -1950,12 +1957,12 @@ static int hi846_identify_module(struct hi846 *hi846) static s64 hi846_check_link_freqs(struct hi846 *hi846, struct v4l2_fwnode_endpoint *ep) { - int freqs_count = ARRAY_SIZE(supported_modes); + int freqs_count = hi846->num_modes; u64 link_freq; int i, j; for (i = 0; i < freqs_count; i++) { - link_freq = hi846_get_link_freq(hi846, &supported_modes[i]); + link_freq = hi846_get_link_freq(hi846, &hi846->supported_modes[i]); for (j = 0; j < ep->nr_of_link_frequencies; j++) if (link_freq == ep->link_frequencies[j]) break; @@ -1999,6 +2006,13 @@ static int hi846_parse_dt(struct hi846 *hi846, struct device *dev) hi846->nr_lanes = bus_cfg.bus.mipi_csi2.num_data_lanes; + hi846->supported_modes = supported_modes; + hi846->num_modes = NUM_MODES_2LANE; + if (hi846->nr_lanes == 4) { + hi846->supported_modes = supported_modes + 1; + hi846->num_modes = NUM_MODES_4LANE; + } + if (!bus_cfg.nr_of_link_frequencies) { dev_err(dev, "link-frequency property not found in DT\n"); ret = -EINVAL; @@ -2088,7 +2102,7 @@ static int hi846_probe(struct i2c_client *client) if (ret) goto err_power_off; - hi846->cur_mode = &supported_modes[0]; + hi846->cur_mode = &hi846->supported_modes[0]; ret = hi846_init_controls(hi846); if (ret) { -- 2.54.0