From nobody Tue Dec 2 02:32:14 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 046D33115A5 for ; Thu, 20 Nov 2025 08:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763628598; cv=none; b=BRjZmFaUK6PSJCmeZqoQacklEF39l6dlNVl20ikVCIadppi8R+CHW4Vx2W8kPs9HaljdDwBuIT5adEA385/TOKqHvWAE1NFpwksKSUzBJKX0qnBPlhZedyviyArYo5lkcJTx2JMzN4DFatNJ9Z9uEW5r+2hzQ9zLo8Xn9g1wM2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763628598; c=relaxed/simple; bh=MQV8jD27ZG+yZve5+9joqOYFG9IDBUKao+l7F/BRtLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p9wVrGWuYlg354C/X7fz6ftWIUKFAcsIRZCxrzgPG7xHOnGR55AGlXd5pb6d0fePt4JOj90Q9FPuLctIwPYnF/e7YVgYE82tS2+iHyNxRtkj9Zuaztrw+ZqupxLmfjytYhgXJ61mlU2/Y9glIBNmxiTougT6DVAR7edWqDjZOjc= 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=b46VllM0; arc=none smtp.client-ip=209.85.210.170 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="b46VllM0" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7aace33b75bso573286b3a.1 for ; Thu, 20 Nov 2025 00:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763628596; x=1764233396; 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=cGP4x/41RYIg15mQcXh3AwtklkR1Te1lPQnjCYwhFmM=; b=b46VllM0mNbqjcyT1g4C/WwRSsIWjt4RNF2tIrmyQndjZVKW1zH3QbJWmWH1a4J8EM F+ygTVsE2xRue7UDRl14bfqVYB5BnTIJ0D9zwnKu8QbO3ts++mFUYCGuSoycxsTdSHIJ ytjJigcJeK8FhjQu9LeE5UVmBilitFIqLYRzY8rYGI4KuRPC4x3e+iVWxAyk7MKvwHpT XH71mAJXXOp+PdYFiDV4wJhPCH4UA6zbmqQDSRjY1YfjTPkYY6o2rYdJabov6ityAtt6 QiScSGL/i7FUFVyCQlAP2fFUb2I+7+2YCAswpIH8ZJiD12Q4ZKUABARCQlCu1Evw0a+h fW7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763628596; x=1764233396; 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=cGP4x/41RYIg15mQcXh3AwtklkR1Te1lPQnjCYwhFmM=; b=tn6fqBS1fjkslBjG78D9B0T4MGdCXET+4K2JTf6Is+JO/baeSQj2eH7aL8e+e5SQ9d 8nif+zcCoXJ6zbwAwZ621u18eBOdvsxpy4PSQFI6NYIvYeJ7VbMcJOWAjtkT1OR8EAaJ DJJdcAnhmOW4ipOr6ro6Du3PenOYXMPBqjbm75Yr77oJcMBG1tQ+ui6opWnild6gdl6t xtA8ZYFYm22qcMzidUYmN+Wf+OooB6LAVum7O23Y/YUn46coOlnPrOZsKhbsTAwRWJGR CCP+xBC3StQxAp1/JxlgYlv36bXzJG4AAEh+GqG/Fc/U8uOvUV+9D2nhZ1IEMvC7hPLe 2qig== X-Gm-Message-State: AOJu0YwqUnJowKgdDr7Xxb6RaOg5I4Poqox8TaYMzjza3he1VZfhYfLE Mlo65OwCw7WE6qQ50jAzi9QxOiFA4lHe31phqjUm77De8BAtEUz+PxXZ X-Gm-Gg: ASbGncsjXs8ZpxBcabuS/InExMBweB4xGU2HD6TK1IfRkFqSd2Zvw1i816pDpJyeYXA rzZxGfjjDb/ZNhEGIszf00JvYE1appxkME4tehNvHwrY8R1g5D9+NHyu8sYSo2h4846W0SJdnGy eR9fugYiGIUGxMp7JfYmEnbu3Aha7Rp/QT1GIJk1KrN+vFe3bBJpFuVaqxpnQ7RvHxIJx1xt5oj 9UmNW/AhDsnFOXFmLDrxavcWUO0o/UMtOhttzEdLrHSsGPf1+geI5+fgtU5jJAL82EtuAQHIgqW OF3bwBjV0Syoj6+E/rGspbXQVAMyBRfOvs+dBhtKh2wDblnUnFLUkFBzUw+ze/9W0s0bsU3QeES /sW69CmuDyBd66iaaw6Yy/M3mVq3gB2HSxHuri1JWjO/dWgy4SG2R2vJ4dwlA6LAOX45lcYVo0c 82Mq4J8hXN9r5N37XxnS52yHZGD4HiOeOIP9xKtg== X-Google-Smtp-Source: AGHT+IECkCFNKIq/dOmcM+rn72ZbItA41tgJJU1WjHJ7EZr5qY/C2DRz99gNei/A0E9dQvLJp0yjFQ== X-Received: by 2002:a05:6a00:c8f:b0:7a9:b9e0:551c with SMTP id d2e1a72fcca58-7c3f095c12fmr2797914b3a.21.1763628596176; Thu, 20 Nov 2025 00:49:56 -0800 (PST) Received: from opensource206.. ([157.50.102.16]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7c3f023fba8sm1974900b3a.41.2025.11.20.00.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Nov 2025 00:49:55 -0800 (PST) From: Pavan Bobba To: skhan@linuxfoundation.org, kieran.bingham@ideasonboard.com, mchehab@kernel.org Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Pavan Bobba Subject: [PATCH 3/5] media: vimc: debayer: add support for multiple RGB formats Date: Thu, 20 Nov 2025 14:19:24 +0530 Message-ID: <20251120084926.18620-4-opensource206@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251120084926.18620-1-opensource206@gmail.com> References: <20251120084926.18620-1-opensource206@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: quoted-printable Content-Type: text/plain; charset="utf-8" Enhance the vimc debayer subdevice to support multiple RGB output formats and improve its format negotiation behavior. This patch introduces the following changes: - Adds ARGB8888_1X32 to the list of supported source pad mbus codes. - Allows userspace to select any valid RGB code on the source pad through set_fmt(). - Propagates width, height, and field settings from sink to source while preserving the selected RGB code. - Sets appropriate default colorimetry for RGB output (sRGB, full-range). - Updates vimc_debayer_process_rgb_frame() to handle RGB24, BGR24, and ARGB32 pixel formats with proper channel ordering and alpha fill. - Adds debug and warning logs for invalid or unsupported formats. These changes make the virtual debayer pipeline more flexible and realistic for testing RGB/ARGB camera capture paths. Signed-off-by: Pavan Bobba --- .../media/test-drivers/vimc/vimc-debayer.c | 113 ++++++++++++++---- 1 file changed, 90 insertions(+), 23 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media= /test-drivers/vimc/vimc-debayer.c index bbb7c7a86df0..0fa1cb8d3be1 100644 --- a/drivers/media/test-drivers/vimc/vimc-debayer.c +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c @@ -15,9 +15,6 @@ =20 #include "vimc-common.h" =20 -/* TODO: Add support for more output formats, we only support RGB888 for n= ow. */ -#define VIMC_DEBAYER_SOURCE_MBUS_FMT MEDIA_BUS_FMT_RGB888_1X24 - enum vimc_debayer_rgb_colors { VIMC_DEBAYER_RED =3D 0, VIMC_DEBAYER_GREEN =3D 1, @@ -73,6 +70,7 @@ static const u32 vimc_debayer_src_mbus_codes[] =3D { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG, MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA, MEDIA_BUS_FMT_RGB888_1X32_PADHI, + MEDIA_BUS_FMT_ARGB8888_1X32, }; =20 static const struct vimc_debayer_pix_map vimc_debayer_pix_map_list[] =3D { @@ -170,7 +168,7 @@ static int vimc_debayer_init_state(struct v4l2_subdev *= sd, =20 mf =3D v4l2_subdev_state_get_format(sd_state, 1); *mf =3D sink_fmt_default; - mf->code =3D VIMC_DEBAYER_SOURCE_MBUS_FMT; + mf->code =3D vimc_debayer_src_mbus_codes[0]; =20 return 0; } @@ -239,6 +237,14 @@ static void vimc_debayer_adjust_sink_fmt(struct v4l2_m= bus_framefmt *fmt) vimc_colorimetry_clamp(fmt); } =20 +static void vimc_debayer_set_rgb_mbus_fmt_default(struct v4l2_mbus_framefm= t *fmt) +{ + fmt->colorspace =3D V4L2_COLORSPACE_SRGB; + fmt->quantization =3D V4L2_QUANTIZATION_FULL_RANGE; + fmt->xfer_func =3D V4L2_XFER_FUNC_SRGB; + fmt->ycbcr_enc =3D V4L2_YCBCR_ENC_DEFAULT; +} + static int vimc_debayer_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) @@ -250,12 +256,30 @@ static int vimc_debayer_set_fmt(struct v4l2_subdev *s= d, if (fmt->which =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE && vdebayer->src_frame) return -EBUSY; =20 - /* - * Do not change the format of the source pad, it is propagated from - * the sink. - */ - if (VIMC_IS_SRC(fmt->pad)) - return v4l2_subdev_get_fmt(sd, sd_state, fmt); + if (VIMC_IS_SRC(fmt->pad)) { + struct v4l2_mbus_framefmt *source_fmt; + struct v4l2_mbus_framefmt *sink_fmt; + + /* Validate the requested source format */ + if (!vimc_debayer_src_code_is_valid(fmt->format.code)) + return -EINVAL; + + /* Get current formats */ + source_fmt =3D v4l2_subdev_state_get_format(sd_state, 1); + sink_fmt =3D v4l2_subdev_state_get_format(sd_state, 0); + + /* Update source format with appropriate properties for RGB output */ + source_fmt->code =3D fmt->format.code; + source_fmt->width =3D sink_fmt->width; /* Size should match */ + source_fmt->height =3D sink_fmt->height; /* Size should match */ + source_fmt->field =3D sink_fmt->field; /* Field handling should match = */ + + /* Set appropriate colorimetry for RGB output */ + vimc_debayer_set_rgb_mbus_fmt_default(source_fmt); + + fmt->format =3D *source_fmt; + return 0; + } =20 /* Set the new format in the sink pad. */ vimc_debayer_adjust_sink_fmt(&fmt->format); @@ -278,8 +302,25 @@ static int vimc_debayer_set_fmt(struct v4l2_subdev *sd, =20 /* Propagate the format to the source pad. */ format =3D v4l2_subdev_state_get_format(sd_state, 1); - *format =3D fmt->format; - format->code =3D VIMC_DEBAYER_SOURCE_MBUS_FMT; + + /* Propagate size and field from sink, but maintain source code */ + format->width =3D fmt->format.width; + format->height =3D fmt->format.height; + format->field =3D fmt->format.field; + + /* + * Source code should always be valid (set during init or via set_fmt). + * If somehow it's not, this is a bug - log warning and fix it. + */ + if (!vimc_debayer_src_code_is_valid(format->code)) { + dev_warn(vdebayer->ved.dev, + "%s: Invalid source code 0x%x, resetting to default\n", + vdebayer->sd.name, format->code); + format->code =3D vimc_debayer_src_mbus_codes[0]; + } + + /* Set appropriate colorimetry for RGB output */ + vimc_debayer_set_rgb_mbus_fmt_default(format); =20 return 0; } @@ -297,19 +338,45 @@ static void vimc_debayer_process_rgb_frame(struct vim= c_debayer_device *vdebayer, unsigned int rgb[3]) { const struct vimc_pix_map *vpix; - unsigned int i, index; + unsigned int index; =20 vpix =3D vimc_pix_map_by_code(vdebayer->hw.src_code); - index =3D VIMC_FRAME_INDEX(lin, col, vdebayer->hw.size.width, 3); - for (i =3D 0; i < 3; i++) { - switch (vpix->pixelformat) { - case V4L2_PIX_FMT_RGB24: - vdebayer->src_frame[index + i] =3D rgb[i]; - break; - case V4L2_PIX_FMT_BGR24: - vdebayer->src_frame[index + i] =3D rgb[2 - i]; - break; - } + if (!vpix) { + dev_dbg(vdebayer->ved.dev, "Invalid source code: 0x%x\n", + vdebayer->hw.src_code); + return; + } + + index =3D VIMC_FRAME_INDEX(lin, col, vdebayer->hw.size.width, vpix->bpp); + + switch (vpix->pixelformat) { + case V4L2_PIX_FMT_RGB24: + /* RGB24: R-G-B */ + vdebayer->src_frame[index + 0] =3D rgb[0]; /* Red */ + vdebayer->src_frame[index + 1] =3D rgb[1]; /* Green */ + vdebayer->src_frame[index + 2] =3D rgb[2]; /* Blue */ + break; + + case V4L2_PIX_FMT_BGR24: + /* BGR24: B-G-R */ + vdebayer->src_frame[index + 0] =3D rgb[2]; /* Blue */ + vdebayer->src_frame[index + 1] =3D rgb[1]; /* Green */ + vdebayer->src_frame[index + 2] =3D rgb[0]; /* Red */ + break; + + case V4L2_PIX_FMT_ARGB32: + /* ARGB32: A-R-G-B (set alpha to 255) */ + vdebayer->src_frame[index + 0] =3D 255; /* Alpha */ + vdebayer->src_frame[index + 1] =3D rgb[0]; /* Red */ + vdebayer->src_frame[index + 2] =3D rgb[1]; /* Green */ + vdebayer->src_frame[index + 3] =3D rgb[2]; /* Blue */ + break; + + default: + dev_dbg(vdebayer->ved.dev, + "Unsupported pixel format for debayer: 0x%x\n", + vpix->pixelformat); + break; } } =20 --=20 2.43.0