From patchwork Fri Mar 24 15:12:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 13186920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E944C76196 for ; Fri, 24 Mar 2023 15:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RXEVy569PCFlDZ4FK3JfOgTZlNgxgptBpOX/31R5NiM=; b=CG/54t/2rgFgIR FL0N/PHn9dfxfV1qr8V8lptRhD9HfacRCfSPTdEgbwvjWDtBTTgaW7/gEG71eSuzKLx+v45f3dEu4 4H0WUkATyA+3GSMkoAubqBRpJwiHJsaGArfDlLYYu9sXyDDYEwy8rs4UanLKl/HrwzNsmfQ7qFFuS 8+pnauXICrjF4c/kIf5v5k3a6eGKITuiIHGTrUDclfQnTSL31RA5mKBwOA2QKC1dgh3S0RX30MXeu /tjbkS5TQBXoZLAopXVvfj1whTmA9Jzn+sWWCskq4ZIRhV8MwYwtipC6UjFlC8Pi9eeSACp9aXofc jqtAjtXfrLHz/2+xzTew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfj6J-004mQM-1F; Fri, 24 Mar 2023 15:13:07 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfj63-004mET-0o for linux-arm-kernel@lists.infradead.org; Fri, 24 Mar 2023 15:12:53 +0000 Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 87CD6E000F; Fri, 24 Mar 2023 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679670769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ibm3tSrzHRilK0eBOck6yRC9NMDYkOhhKkBru4BHJTA=; b=maCXEZC95D2g/i9VZ5tpBHfFcnTLOUQJ1MypJvDDCf74A0M9WoHL5bs+RIwRk8bgrDLnXN ua+6SzvTtX7A4/h0T2boXWqL1VIW6zkPeSCNR52PjXpryFVOjA6Oz6PBLrvsX1wfsnaL1E qclE37AWysUEkygHd3MtLrv4KLfIs5Y8gjsghOpL6KtjSRx17KThxcbBbvCcOHnABoymVD c1MHQi4omFqhwewKM1z0AAYQXC9qoHtqm42V6XMfGgF0u/oAxzDYdcEsSvqLAg+8usLb53 MyqNJceNgYZwmqZsRjerh54qvZj3tWEhcGtvZL5gXJVE11aNVvUDVHvoouwQ7A== From: Paul Kocialkowski To: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev Cc: Paul Kocialkowski , Mauro Carvalho Chehab , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Laurent Pinchart , Adam Pigg , Thomas Petazzoni Subject: [PATCH 6/9] media: sun6i-csi: capture: Implement MC I/O with extended enum_fmt Date: Fri, 24 Mar 2023 16:12:25 +0100 Message-Id: <20230324151228.2778112-7-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324151228.2778112-1-paul.kocialkowski@bootlin.com> References: <20230324151228.2778112-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230324_081251_592088_72A756B3 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation. Properly report the IO_MC device cap and extend the enum_fmt implementation to support enumeration with an explicit mbus_code. Signed-off-by: Paul Kocialkowski Reviewed-by: Jernej Skrabec --- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c index 6ce7f1d3ed57..9627030ff060 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c @@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) { u32 index = fmtdesc->index; + u32 mbus_code = fmtdesc->mbus_code; + unsigned int index_valid = 0; + unsigned int i; + + if (!mbus_code) { + if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) + return -EINVAL; + + fmtdesc->pixelformat = + sun6i_csi_capture_formats[index].pixelformat; + + return 0; + } + + /* Check capture pixel format matching with mbus code. */ - if (index >= ARRAY_SIZE(sun6i_csi_capture_formats)) + if (!sun6i_csi_bridge_format_find(mbus_code)) return -EINVAL; - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; + for (i = 0; i < ARRAY_SIZE(sun6i_csi_capture_formats); i++) { + u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; - return 0; + if (!sun6i_csi_capture_format_check(pixelformat, mbus_code)) + continue; + + if (index == index_valid) { + fmtdesc->pixelformat = pixelformat; + return 0; + } + + index_valid++; + } + + return -EINVAL; } static int sun6i_csi_capture_g_fmt(struct file *file, void *private, @@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev) strscpy(video_dev->name, SUN6I_CSI_CAPTURE_NAME, sizeof(video_dev->name)); - video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + video_dev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | + V4L2_CAP_IO_MC; video_dev->vfl_dir = VFL_DIR_RX; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_csi_capture_fops;