From patchwork Thu Nov 3 16:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 15005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp638581wru; Thu, 3 Nov 2022 09:35:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CtPJFDfFMeIwdCUKzwYeWsQtSxUthydoav8d5rvImWHcxoWALvsnYBXFMHp0hC2G6y8eL X-Received: by 2002:a17:907:2d1e:b0:7a9:c2f9:2c2c with SMTP id gs30-20020a1709072d1e00b007a9c2f92c2cmr29785900ejc.405.1667493321414; Thu, 03 Nov 2022 09:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667493321; cv=none; d=google.com; s=arc-20160816; b=Ee5oVazy8m2rSsNKppt9vy+9hV0YeP7ueVhdg5mtA5V2b6sDu3D6VIHsW4JgDBJ4yQ R2MF2tZU+Fgudlr/C3a1Srum6qeq0q5gaorw+sEIdbrTrrYPY3AN75Q6K7hYLCmDFRT9 OK9wHnSN3ByQ7MKeiroCA0/1wC4wncNJAxEYhQmSCA+zStl9edGKGfAPUxaS6qU/bfns jAG5vHM478XJvCf3NeG+STb+H+FPvWcVTbsB6Q/IlRzbhNc8O5c/TEa3NSMEVHHT4oUX yfMWgj1EwGyDZhypNuhGiLKHOtKBw6yhSqq2pFP4zXdRm+xOr30z9HE9BNFyBAWO+14+ Yp8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=92BIwhr37phAu6zFjhrUh2a2nbnrbEyc1MsvZ589sKc=; b=yITWnxoQgcN6j5Y1n2ZT5oaGCS6VVOrBEyFWkvTQ8Mn860OM5oNshXVopYIt+kKpaj Xiug3tWHubeWNQ42MAKCwSB0jqpr5CBTxa0jw0iEG91uQ+mtGMWBdCGlcIcRZnoI5Iec bzL1x3d0XtEV9+PSuYcwXVuGf9LGIUMquR+rvOb6jFjL4LOFj/rLlBSNMqG9VrZuEWj8 HZLnYPCxaHTcgru5ya/OniQglZO05UfEChEEkLI4GmzU2yMxFOgG4u0wvhrQ2D2A7Xev wKeod88a7yGabeqD5VGFTP4pVr7bWSTtpdxhZ/YXzCQcSZc4jRcrzIIV6XokEyKw5wSo IeLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YH+vj+c7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq10-20020a1709073f0a00b007707ab4be28si1859871ejc.972.2022.11.03.09.34.56; Thu, 03 Nov 2022 09:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YH+vj+c7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232453AbiKCQds (ORCPT + 99 others); Thu, 3 Nov 2022 12:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232260AbiKCQch (ORCPT ); Thu, 3 Nov 2022 12:32:37 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2CB31B1FE; Thu, 3 Nov 2022 09:32:17 -0700 (PDT) Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3291A240004; Thu, 3 Nov 2022 16:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1667493135; 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=92BIwhr37phAu6zFjhrUh2a2nbnrbEyc1MsvZ589sKc=; b=YH+vj+c7YkvyiMmM+LngYWdeRDG6LTpjQLPpo72IROtnEwM7BzDmKvTSNgFJ2vSPER8LQS bFlznZ0sp/QwDQf5pHuOgWd5USHzcV1r1sLTji4Ekizem+6ysXu53rGe/zA0Ya8zokJFDX EatOMGnsmgUU4JtxTWL4Ovjl7y3eUiMAqbIR3LRMOadeKJM5qRhxoNA6IEnBhuOIwvNBBJ IIloxOR4oXt99P3E125ydm4ybz4zkympqL4m+7GORoPiIZOu8fUhej8VJnLeubm7s6SzcE +Lz+lS6MB2daYKH7dRYSKkkTi5lnpnXBWAUcSl69iR2+S72dRoE9r/FA0jGZGg== From: Paul Kocialkowski To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Cc: Yong Deng , Paul Kocialkowski , Mauro Carvalho Chehab , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Laurent Pinchart , Maxime Ripard , Thomas Petazzoni Subject: [PATCH v7 24/28] media: sun6i-csi: Add support for MIPI CSI-2 to the bridge code Date: Thu, 3 Nov 2022 17:31:09 +0100 Message-Id: <20221103163113.245462-25-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221103163113.245462-1-paul.kocialkowski@bootlin.com> References: <20221103163113.245462-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748493476961127874?= X-GMAIL-MSGID: =?utf-8?q?1748493476961127874?= Introduce MIPI CSI-2 support to the bridge with a new port, source and hardware configuration helper. Signed-off-by: Paul Kocialkowski Acked-by: Jernej Skrabec --- .../platform/sunxi/sun6i-csi/sun6i_csi.h | 1 + .../sunxi/sun6i-csi/sun6i_csi_bridge.c | 46 +++++++++++++++++-- .../sunxi/sun6i-csi/sun6i_csi_bridge.h | 1 + 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index fd6e98b66f12..e611bdd6e9b2 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h @@ -20,6 +20,7 @@ enum sun6i_csi_port { SUN6I_CSI_PORT_PARALLEL = 0, + SUN6I_CSI_PORT_MIPI_CSI2 = 1, }; struct sun6i_csi_buffer { diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c index c82270ac8759..69c1fa7151d9 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c @@ -226,7 +226,7 @@ static void sun6i_csi_bridge_disable(struct sun6i_csi_device *csi_dev) } static void -sun6i_csi_bridge_configure_interface(struct sun6i_csi_device *csi_dev) +sun6i_csi_bridge_configure_parallel(struct sun6i_csi_device *csi_dev) { struct device *dev = csi_dev->dev; struct regmap *regmap = csi_dev->regmap; @@ -316,6 +316,25 @@ sun6i_csi_bridge_configure_interface(struct sun6i_csi_device *csi_dev) regmap_write(regmap, SUN6I_CSI_IF_CFG_REG, value); } +static void +sun6i_csi_bridge_configure_mipi_csi2(struct sun6i_csi_device *csi_dev) +{ + struct regmap *regmap = csi_dev->regmap; + u32 value = SUN6I_CSI_IF_CFG_IF_MIPI; + u32 field; + + sun6i_csi_bridge_format(csi_dev, NULL, &field); + + if (field == V4L2_FIELD_INTERLACED || + field == V4L2_FIELD_INTERLACED_TB || + field == V4L2_FIELD_INTERLACED_BT) + value |= SUN6I_CSI_IF_CFG_SRC_TYPE_INTERLACED; + else + value |= SUN6I_CSI_IF_CFG_SRC_TYPE_PROGRESSIVE; + + regmap_write(regmap, SUN6I_CSI_IF_CFG_REG, value); +} + static void sun6i_csi_bridge_configure_format(struct sun6i_csi_device *csi_dev) { struct regmap *regmap = csi_dev->regmap; @@ -367,9 +386,16 @@ static void sun6i_csi_bridge_configure_format(struct sun6i_csi_device *csi_dev) regmap_write(regmap, SUN6I_CSI_CH_CFG_REG, value); } -static void sun6i_csi_bridge_configure(struct sun6i_csi_device *csi_dev) +static void sun6i_csi_bridge_configure(struct sun6i_csi_device *csi_dev, + struct sun6i_csi_bridge_source *source) { - sun6i_csi_bridge_configure_interface(csi_dev); + struct sun6i_csi_bridge *bridge = &csi_dev->bridge; + + if (source == &bridge->source_parallel) + sun6i_csi_bridge_configure_parallel(csi_dev); + else + sun6i_csi_bridge_configure_mipi_csi2(csi_dev); + sun6i_csi_bridge_configure_format(csi_dev); } @@ -381,6 +407,7 @@ static int sun6i_csi_bridge_s_stream(struct v4l2_subdev *subdev, int on) struct sun6i_csi_bridge *bridge = &csi_dev->bridge; struct media_pad *local_pad = &bridge->pads[SUN6I_CSI_BRIDGE_PAD_SINK]; struct device *dev = csi_dev->dev; + struct sun6i_csi_bridge_source *source; struct v4l2_subdev *source_subdev; struct media_pad *remote_pad; /* Initialize to 0 to use both in disable label (ret != 0) and off. */ @@ -397,6 +424,11 @@ static int sun6i_csi_bridge_s_stream(struct v4l2_subdev *subdev, int on) source_subdev = media_entity_to_v4l2_subdev(remote_pad->entity); + if (source_subdev == bridge->source_parallel.subdev) + source = &bridge->source_parallel; + else + source = &bridge->source_mipi_csi2; + if (!on) { v4l2_subdev_call(source_subdev, video, s_stream, 0); goto disable; @@ -414,7 +446,7 @@ static int sun6i_csi_bridge_s_stream(struct v4l2_subdev *subdev, int on) /* Configure */ - sun6i_csi_bridge_configure(csi_dev); + sun6i_csi_bridge_configure(csi_dev, source); sun6i_csi_capture_configure(csi_dev); /* State Update */ @@ -606,6 +638,7 @@ sun6i_csi_bridge_notifier_bound(struct v4l2_async_notifier *notifier, struct sun6i_csi_bridge_async_subdev *bridge_async_subdev = container_of(async_subdev, struct sun6i_csi_bridge_async_subdev, async_subdev); + struct sun6i_csi_bridge *bridge = &csi_dev->bridge; struct sun6i_csi_bridge_source *source = bridge_async_subdev->source; bool enabled; @@ -613,6 +646,9 @@ sun6i_csi_bridge_notifier_bound(struct v4l2_async_notifier *notifier, case SUN6I_CSI_PORT_PARALLEL: enabled = true; break; + case SUN6I_CSI_PORT_MIPI_CSI2: + enabled = !bridge->source_parallel.expected; + break; default: break; } @@ -759,6 +795,8 @@ int sun6i_csi_bridge_setup(struct sun6i_csi_device *csi_dev) sun6i_csi_bridge_source_setup(csi_dev, &bridge->source_parallel, SUN6I_CSI_PORT_PARALLEL, parallel_mbus_types); + sun6i_csi_bridge_source_setup(csi_dev, &bridge->source_mipi_csi2, + SUN6I_CSI_PORT_MIPI_CSI2, NULL); ret = v4l2_async_nf_register(v4l2_dev, notifier); if (ret) { diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.h index cb3b27af4607..ee592a14b9c5 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.h +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.h @@ -46,6 +46,7 @@ struct sun6i_csi_bridge { struct mutex lock; /* Mbus format lock. */ struct sun6i_csi_bridge_source source_parallel; + struct sun6i_csi_bridge_source source_mipi_csi2; }; /* Helpers */