Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795975687; b=kzOulSSt9QRpZea9QWmUpDPH3Em1yWmSnFbD7c7KE5XHdw/ytZgQmicKOVqk+UDmiqIb 7xGpTid1yqRN9TcrICNuRZzfYL/tLr6fpiqcOpsJllWTijGW0P2HH+ZxNcKOBuE3Y1Vif rJ1Twx5bLKNDBvn8srySSZNqr87a2PNBkd0JtBEplxD9Yv4sxFRXwkN6iAmPbf9fOKovH tgRvNbOGu7ghu802ieLKG+wDRq28OUWTjSd4HvQWvIt8x92+5SKWRyfW2RleBUNzGCyFF 7yMAy/56p9cJbpWuYL+ZuumZoeGjtx7D+jIhM4lPiI2bk94YRolDdXdZS9irJM4M25g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795975687; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=nfSTV7Qg6+YKNRSA7wp5ORSmxwIgTJtrGYFqpQ+OR1w=; b=ZkhGwPb1A9LXx2a2jciRc9L4fgTZ5XzkbaUZYR4kkyyzBa/R7guu6HsTlk/RwE0JVacK QKhASpT2tmcmgRIFgGsnp3XfOQuKmn6FbeAz9nyOVGtjSgfS85/WRmT5hFbHcVX8JlQ3B f93GwjzZDB1DsZnoG7zTywJPhBRxqs+m7e47hef1ghQSGR6wVp5IzY102cusd8wPSpEp2 OXk/Fv4tYmVgM/priXnr1jXyWE/O+gbg/qa+QuV9XyWpiYIgxqa2Ud2zxsMVwfeAHNwDe y3dOx7ciJHSTreqPTAUCmg6WAciRy3qWUTJVBUjJK+l1zBQr3cuj9HlrJeB3qso15DA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ir1NEkAq; arc=none smtp.remote-ip=209.85.218.54 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E14ED60A260C for ; Sun, 29 Nov 2026 18:08:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E14ED60A260C 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.a=rsa-sha256 header.s=20260707 header.b=ir1NEkAq Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-c516a1623d0so1163505766b.2 for ; Sun, 29 Nov 2026 10:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795975685; x=1796580485; 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:content-type; bh=nfSTV7Qg6+YKNRSA7wp5ORSmxwIgTJtrGYFqpQ+OR1w=; b=ir1NEkAq8YV1fghsP/89ToiYQ+jg3Fxs0US7xjw+sAAj+DiOnqTJb7WBQnmcbMfltf V3Gzo//uTmDrdfdtXYNP9yeyZXs23mpUdX/zl8DY3i9EGe5+ClPHxVw7fOGOV9+9sVg3 94JzC6jJlchtFY/D2dYP0anoPDv0XOabQ9dwCwIyGLCUQwjGCSZwh8hd6mXEYohP8TXi /bwOJQBvLQ0Enp9w5I85oOJociM5IBW566V+8R4ONIdfUN0mUqCmzkYoxCtUW+Qj1l1n BTWwtqAAJusUQ9MHQH9GkSIbpRFkqiaeUgNvhNzoRa3s8WKqGhKUo+Y8yTwChUrowSV3 ylNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795975685; x=1796580485; 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:content-type; bh=nfSTV7Qg6+YKNRSA7wp5ORSmxwIgTJtrGYFqpQ+OR1w=; b=0bO2lHIzdfaRSqx2Y1g537TtosedkvKm/GGOCA4uEayBm8apxzsP6lgA/OySr8KDW+ ZpCvpsCkTYdXG/10MeaGU8VEfnUjpRsChFUNNvBGjHqUSOb/4oIp58Y5M58FBkSvwwU7 LVn7EF6s5gSEZvAJOGp47snbUK/F5vmoSkyZm6mnXK0yjqWmv8tKdsYsTbsXXz1lxkg0 ShWLlRKjb4G5IzLAwEXwOI97tRpadCX2mR7u0JEmbQgcWOGIaC5guDDqcyos0KUbvrza gquAaYqog3YjtdUmA+lHES0o3iViPk7fhzq61RBauWze7Vl273G8h+YzVEcr5ldKwb0u clzQ== X-Forwarded-Encrypted: i=1; AL+hErFnj4eCoz+2+4pafWlnVM9f1TYJlfX0kJ6TbqPDibRYt1NynXsxHkJZ0cx0DmvCLlQKw8cH5eO8iHHBsQ==@vger.kernel.org X-Gm-Message-State: APuU4Z+bBPVxDUsUQLcTYF0zq23vNU5CF0UeB3GWDqNKLudiSK9C8Ovf sBInXoS6IgJC3ZdMC0pEz/9KYJwitPN5I6ytIwUdp++CaE1X0SyJJsD9 X-Gm-Gg: AZFdTZfNaDKK92fs0wow7IPClQBXTI0bycbDNH0oSZJs+Qtmgo/FxOG59BgFtcblC74 DtoKBi/OXwmx3qFPN2IIrQ+/6Q1RKtNvnJ3YrHaYTSCalmUrYrCU7pnusGs3ATCiu9uOQfQOEn1 C1qb1SfRb8kRgUoqFP5EAX6iGqGQSR5zHvDJ5HEsjIPSB797SirAkIOVDODFpcxfA61UOyHRJFv W3e576PUfOjrSyUJhe2pDvljQ50B7aVO78UDbWBsvVa3/06RSCl+fXGcJHqOXSWTg+8uNDYUh3G UsMLZnHSvhz24ZkGQegHNKYYTzlC/WgzblMn/C/iQMaPnT0MTZYbsj79l1SHFkYlSmz1vWJ8uzP fpDwiQ7kW2eAMeTZzHk1ZYUIQSUfOZAvKx4S+VVecqKTnFH4JX2QLQSK7pZUjzw5RmmJAZsGgWG MPDah8R8DpRLeZJRK1odG6eXR9UUtOWqQDrd+MYS0GbaG2gn5RBz7mm3HNMVNvEHLxt6rdJ/KJZ BNRN4w+I1E+mJEUn7a8b8bIVvv+aK/TXLwYsnssKoYLbfR7WJEbes8QcI+eLCatjboQ5JQ0t340 Sv3GtiqaCyvOY783vxY7yoP8irQnhmG4IBqKMVZRtvMjEqLLUGz5ICUTYoPnmpbzuqxYbk0Pejh iDTPfSI5kcA== X-Received: by 2002:a17:906:9555:b0:c50:52b5:e17 with SMTP id a640c23a62f3a-c513a5e1d53mr2090792966b.13.1795975685227; Sun, 29 Nov 2026 10:08:05 -0800 (PST) Received: from xeon ([188.163.112.54]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513ae8ce16sm1061518266b.37.2026.11.29.10.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 10:08:04 -0800 (PST) From: Svyatoslav Ryhel To: Mauro Carvalho Chehab , Thierry Reding , Jonathan Hunter , Sowjanya Komatineni , Luca Ceresoli , Greg Kroah-Hartman , Svyatoslav Ryhel , Hans Verkuil , Mikko Perttunen Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH v2 15/15] media: tegra-video: vip: Add pad and media operations for VIP Date: Sun, 29 Nov 2026 20:07:22 +0200 Message-ID: <20261129180722.142186-16-clamor95@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261129180722.142186-1-clamor95@gmail.com> References: <20261129180722.142186-1-clamor95@gmail.com> X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Implement pad format enumeration, format negotiation clamped to SoC limits via vi_fmt_align(), and v4l2_subdev_link_validate() for VIP bridge channels. Signed-off-by: Svyatoslav Ryhel --- .../media/platform/nvidia/tegra-video/vip.c | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/nvidia/tegra-video/vip.c b/drivers/media/platform/nvidia/tegra-video/vip.c index 040776775aacc..bc925633b5890 100644 --- a/drivers/media/platform/nvidia/tegra-video/vip.c +++ b/drivers/media/platform/nvidia/tegra-video/vip.c @@ -21,6 +21,14 @@ #include "vip.h" #include "video.h" +static const u32 tegra_vip_mbus_formats[] = { + /* YUV422 */ + MEDIA_BUS_FMT_UYVY8_2X8, + MEDIA_BUS_FMT_VYUY8_2X8, + MEDIA_BUS_FMT_YUYV8_2X8, + MEDIA_BUS_FMT_YVYU8_2X8, +}; + static inline struct tegra_vip *host1x_client_to_vip(struct host1x_client *client) { return container_of(client, struct tegra_vip, client); @@ -36,6 +44,77 @@ static inline struct tegra_vip *vip_channel_to_vip(struct tegra_vip_channel *cha return container_of(chan, struct tegra_vip, chan); } +static u32 tegra_vip_get_format_code(u32 code) +{ + u32 i; + + for (i = 0; i < ARRAY_SIZE(tegra_vip_mbus_formats); i++) + if (tegra_vip_mbus_formats[i] == code) + break; + + if (i >= ARRAY_SIZE(tegra_vip_mbus_formats)) + i = 0; + + return tegra_vip_mbus_formats[i]; +} + +static int tegra_vip_enum_bus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_state *state, + struct v4l2_subdev_mbus_code_enum *code) +{ + const struct v4l2_mbus_framefmt *sink_fmt; + + if (code->pad == TEGRA_VIP_PAD_SINK) { + if (code->index >= ARRAY_SIZE(tegra_vip_mbus_formats)) + return -EINVAL; + + code->code = tegra_vip_mbus_formats[code->index]; + } else { + if (code->index > 0) + return -EINVAL; + + sink_fmt = v4l2_subdev_state_get_format(state, + TEGRA_VIP_PAD_SINK); + code->code = sink_fmt->code; + } + + return 0; +} + +static int tegra_vip_set_format(struct v4l2_subdev *subdev, + const struct v4l2_subdev_client_info *ci, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + struct tegra_vi_channel *chan = v4l2_get_subdev_hostdata(subdev); + struct v4l2_mbus_framefmt *mbus_fmt = &format->format; + struct v4l2_mbus_framefmt *sink_fmt, *src_fmt; + struct tegra_vi *vi = chan->vi; + const struct v4l2_frmsize_stepwise *stepwise = vi->soc->framesize; + + /* The format on the source pad always matches the sink pad */ + if (format->pad == TEGRA_VIP_PAD_SOURCE) + return v4l2_subdev_get_fmt(subdev, state, format); + + sink_fmt = v4l2_subdev_state_get_format(state, TEGRA_VIP_PAD_SINK); + src_fmt = v4l2_subdev_state_get_format(state, TEGRA_VIP_PAD_SOURCE); + if (!sink_fmt || !src_fmt) + return -EINVAL; + + mbus_fmt->code = tegra_vip_get_format_code(mbus_fmt->code); + mbus_fmt->field = V4L2_FIELD_NONE; + + mbus_fmt->width = clamp_t(u32, mbus_fmt->width, stepwise->min_width, + stepwise->max_width); + mbus_fmt->height = clamp_t(u32, mbus_fmt->height, stepwise->min_height, + stepwise->max_height); + + *sink_fmt = *mbus_fmt; + *src_fmt = *mbus_fmt; + + return 0; +} + /* Find the previous subdev in the pipeline (i.e. the one connected to our sink pad) */ static struct v4l2_subdev *tegra_vip_channel_get_prev_subdev(struct tegra_vip_channel *chan) { @@ -104,8 +183,19 @@ static const struct v4l2_subdev_video_ops tegra_vip_video_ops = { .s_stream = tegra_vip_s_stream, }; +static const struct v4l2_subdev_pad_ops tegra_vip_pad_ops = { + .enum_mbus_code = tegra_vip_enum_bus_code, + .get_fmt = v4l2_subdev_get_fmt, + .set_fmt = tegra_vip_set_format, +}; + static const struct v4l2_subdev_ops tegra_vip_ops = { - .video = &tegra_vip_video_ops, + .video = &tegra_vip_video_ops, + .pad = &tegra_vip_pad_ops, +}; + +static const struct media_entity_operations tegra_vip_media_ops = { + .link_validate = v4l2_subdev_link_validate, }; static int tegra_vip_channel_of_parse(struct tegra_vip *vip) @@ -165,6 +255,7 @@ static int tegra_vip_channel_init(struct tegra_vip *vip) v4l2_set_subdevdata(subdev, &vip->chan); subdev->fwnode = of_fwnode_handle(vip->chan.of_node); subdev->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; + subdev->entity.ops = &tegra_vip_media_ops; subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; err = media_entity_pads_init(&subdev->entity, TEGRA_VIP_PADS_NUM, vip->chan.pads); -- 2.53.0