From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795975687; b=juiTE36YUcKoDvQhM/QupM5RKvrafZbXQMgW5kztNyDq9aCWcy1gJuLfz9MFgK/Fgx1x +3StwcVv/kxqgLG3tiXz0X7ARIaWrWBZ6C6vP7BGd1MYlkyqkoYXNlflF+DsgDpRHQ2ru 8HWPc7NTIKkbMmy3AMb3kZAgOa59dfUG8HDouznGxSo/8dit4jUjhU67kSBWlYOyEUZWn xZa5A+AXqrqgCW05rGitAdrPysibJSlN8K8+jnvhNPIB+28WgzvReNmQy3nhXbrCXTRgB 6qdBxPfu1HExD15/9vEsyPby17PA0leznTO870Pni5PEemxnT4gEiNlPtuNfQbtNrcQ== 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-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=G0DDK9BPWeAtxatfBp6NWjMN2KixSyzWfnHFjpvk28g7hA7XQI7Cl7xZyhuNsD9/eJlj 50bzr6/mtX+KraPS1F/XxLnsyw6e+WuQwOCYGI9iSCA+HwXm/8SBnxUfa48IASgq3THk8 Ghbo5A/YU5WHCZ5yPcRb3/EjVCbuiiyZu5BDrxlA5Z5SRkDwBvZEylX3JzsOFwRR3Aggc DrwepTgi4DXUfnI1PXogPHkrQCMj4vtNlcIWUVIZAQMIg5zIa4nXwd7GeI+VLB2Lntjvi +GaNoNVbkf1o8ofwD+D/+ybmtz0SOEnsCusQ+2EHNWrvE23kM+K3IPAMX7tuuIHqaMg== 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.41 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 DAF3E606A699 for ; Sun, 29 Nov 2026 18:08:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DAF3E606A699 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-f41.google.com with SMTP id a640c23a62f3a-c516a1623d0so1163505866b.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=sm3go7P/GUFO+zGgc1QoqExe/qshlIfuW2VUmX2X2LFvM7CPy0VxZ+2cdOy9vrnL8F /JXBiAZgNdVKanONECyXBVWW1eb82D/uuH66AdECMMAHc77XusukbcpFROsQpmlb9yFL mObLrpjfMZKMck76ggztgZcNJMDSxHdqFB7TOAkfW48MlidpAAgDbPK+7UOj3vOwwoFq V5E1Z6+aXMOCeQMR4X9xA71iYU/noo2ZDoYbvcgUrWDEWNvfAcgPGIhyyQEgFPJK2cbi QESkVl5Xc4dzCNpvtXA0N2WgG1yrBXommpkRm0f7SPDddEVImZVxu2efCcwqan0jJ4KK UdVA== X-Gm-Message-State: APuU4Z8+gZlkFBdbTefIJVohZk1ROpl13snNlDPs30S5t2Wh8UAs9ls3 GIxxFJ64RJ5QpUPkLaNma8K48vwno3CgFepxeMKF1LR6Gk3IesENQGaU X-Gm-Gg: AZFdTZenQJPXLTLgQXfwwSZwf9cmnHiXXvjN3z7I+mgOJ7R9RLSxisOq7rK81JFylpO TlA4Kz/VqiwD3bKQ7C62WcwvcW/fg5bzK8V6UKg9fm68O8HKYCtKKSwzHQZoEefIvP6koy5aj1d OoRdeYwO9PQ6EqM55fcydc5tI6OjKsfpaOZwYQMspKpY2/Y8h/OmjiD4MdpecNE6gwORXg8sika SI87Xmxa9hfuEb2qHRCekpYu3GUrv5LsItEAE/hD7dZkK6Q3loRJ3Lek0s3gre7sztX5tDWO46I 6PtGuA5EnHLAsd+oPVL0x2unnAg6OyTbD8KTLAlCO63/canUC/Glp8Ps3szJGhAjOUg54D4MhQ+ 5Uxmc59zUuWXbL1fgfv9gKEr7qURIcfPI+YXFDnPN4S1F1l5zr+8HoJrYn8ym3mEETA1c6rUBKB 1s4vmg9Pz6oGYLe0T/WCeeOuhH11lXGPbQEXfR42e1QCbl+Qih+CaDQ9Ibmh/FPMCANuaX0amb4 rhcoHfwydE1HEtVVJZXfePaxKUvcA9S1Q5N8K3qHbkjyRBy9zHs84D4IRM1th0jEYjaLJWr1dbN /jU8nMCYGkPGFOfVjtKmORWDhr/g0Ot2yq6PPcH8DdlNQ1HNqcOuHJNTgQ5/My21+85lNQV6D4N X2qEWO+wEoQ== 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-kernel@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