From patchwork Thu Nov 9 21:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13451738 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 350E7C04E88 for ; Thu, 9 Nov 2023 21:04:47 +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=XrmWaEgQRzfzHroSJ/f+qWPg4wgFg3kcifD75kcsfK0=; b=kqt+w9VYK9OWTW Mi3uxqK9Fj1m5KVwbdL3KA32xQIFEzCWqqiCz4jQRZzCs1ZAIcFeCjq0Fx5fHPkuSFDpWcH862tGh V9Mt2fFtj+SxRVgDLE+CpF4i6sl5wQY5Cx57VxJR87pp+T13RK3jTGrssPGmplEhLA2YQkdPtXLHq r1HiGzDVzwEBs25NzDn5SzjNuMHHyjheFHtDQA+Aj9qp4NsbNFMQRLV4eck7TVPU5hXU5V05STzcD Xs1AoyUXaYKwj5psycSOeHg0yuaKBRDUnl9N42dQf4g7nTnROZuZBrfyxO1rpNbc2mo98q9htnV2j WfWXWI/jh7mtW/WC8cFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r1CCB-007E3o-1a; Thu, 09 Nov 2023 21:04:11 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r1CBu-007Dl1-1E; Thu, 09 Nov 2023 21:03:57 +0000 Received: from umang.jain (unknown [103.251.226.64]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 84CCF124F; Thu, 9 Nov 2023 22:03:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1699563810; bh=/NhVBkmAZJpXUdV/Jyjhk0OJS8toVJ5blJzkBkbr6Kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CvgblSuqljkOD0d8324ELh4rRIfsAlfbn5V3NRpTHVKi0qJPcdshB50g24NTFQiPY xelivhSZbzi2bS4oFz6nfAFhT1loHvmixQ44aawVULJhQ/3P/xX27u1c7T0fiJMqxB fmXZa02gCxm3svoAMFWEOg1QuXCiIjrfZeIWTdO0= From: Umang Jain To: linux-media@vger.kernel.org, kernel-list@raspberrypi.com, linux-kernel@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev Cc: Dave Stevenson , Kieran Bingham , Laurent Pinchart , "Ricardo B . Marliere" , Dan Carpenter , Stefan Wahren , Naushir Patuck , Umang Jain Subject: [PATCH v2 13/15] staging: vc04_services: bcm2835_isp: Allow multiple users Date: Thu, 9 Nov 2023 16:03:05 -0500 Message-ID: <20231109210309.638594-14-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231109210309.638594-1-umang.jain@ideasonboard.com> References: <20231109210309.638594-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_130354_561773_4B325BB6 X-CRM114-Status: GOOD ( 17.67 ) 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 From: Naushir Patuck Add a second (identical) set of device nodes to allow concurrent use of the bcm2835-isp hardware by another user. This change effectively creates a second state structure (struct bcm2835_isp_dev) to maintain independent state for the second user. Node and media entity names are appened with the instance index appropriately. Further users can be added by changing the BCM2835_ISP_NUM_INSTANCES define. Signed-off-by: Naushir Patuck Signed-off-by: Umang Jain --- .../bcm2835-isp/bcm2835-v4l2-isp.c | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c index b6ac1ee8f9f3..316d35d5f19d 100644 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c @@ -28,13 +28,19 @@ MODULE_IMPORT_NS(DMA_BUF); +/* + * We want to instantiate 2 independent instances allowing 2 simultaneous users + * of the ISP hardware. + */ +#define BCM2835_ISP_NUM_INSTANCES 2 + static unsigned int debug; module_param(debug, uint, 0644); MODULE_PARM_DESC(debug, "activates debug info"); -static unsigned int video_nr = 13; -module_param(video_nr, uint, 0644); -MODULE_PARM_DESC(video_nr, "base video device number"); +static unsigned int video_nr[BCM2835_ISP_NUM_INSTANCES] = { 13, 20 }; +module_param_array(video_nr, uint, NULL, 0644); +MODULE_PARM_DESC(video_nr, "base video device numbers"); #define BCM2835_ISP_NAME "bcm2835-isp" #define BCM2835_ISP_ENTITY_NAME_LEN 32 @@ -1287,6 +1293,7 @@ static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node) * or output nodes. */ static int register_node(struct bcm2835_isp_dev *dev, + unsigned int instance, struct bcm2835_isp_node *node, int index) { @@ -1448,7 +1455,7 @@ static int register_node(struct bcm2835_isp_dev *dev, snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME, node->name, node->id); - ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr + index); + ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register video %s[%d] device node\n", @@ -1669,9 +1676,8 @@ static int media_controller_register(struct bcm2835_isp_dev *dev) return ret; } -static void bcm2835_isp_remove(struct vchiq_device *device) +static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev) { - struct bcm2835_isp_dev *dev = vchiq_get_drvdata(device); unsigned int i; media_controller_unregister(dev); @@ -1688,7 +1694,9 @@ static void bcm2835_isp_remove(struct vchiq_device *device) vchiq_mmal_finalise(dev->mmal_instance); } -static int bcm2835_isp_probe(struct vchiq_device *device) +static int bcm2835_isp_probe_instance(struct vchiq_device *device, + struct bcm2835_isp_dev **dev_int, + unsigned int instance) { struct bcm2835_isp_dev *dev; unsigned int i; @@ -1698,6 +1706,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) if (!dev) return -ENOMEM; + *dev_int = dev; dev->dev = &device->dev; ret = v4l2_device_register(&device->dev, &dev->v4l2_dev); @@ -1715,7 +1724,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) if (ret) { v4l2_err(&dev->v4l2_dev, "%s: failed to create ril.isp component\n", __func__); - goto error; + return ret; } if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS || @@ -1727,7 +1736,7 @@ static int bcm2835_isp_probe(struct vchiq_device *device) BCM2835_ISP_NUM_OUTPUTS, dev->component->outputs, BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA); - goto error; + return -EINVAL; } atomic_set(&dev->num_streaming, 0); @@ -1735,17 +1744,53 @@ static int bcm2835_isp_probe(struct vchiq_device *device) for (i = 0; i < BCM2835_ISP_NUM_NODES; i++) { struct bcm2835_isp_node *node = &dev->node[i]; - ret = register_node(dev, node, i); + ret = register_node(dev, instance, node, i); if (ret) - goto error; + return ret; } ret = media_controller_register(dev); if (ret) - goto error; + return ret; + + return 0; +} + +static void bcm2835_isp_remove(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + + bcm2835_isp_instances = vchiq_get_drvdata(device); + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + if (bcm2835_isp_instances[i]) + bcm2835_isp_remove_instance(bcm2835_isp_instances[i]); + } +} + +static int bcm2835_isp_probe(struct vchiq_device *device) +{ + struct bcm2835_isp_dev **bcm2835_isp_instances; + unsigned int i; + int ret; + + bcm2835_isp_instances = devm_kzalloc(&device->dev, + sizeof(bcm2835_isp_instances) * + BCM2835_ISP_NUM_INSTANCES, + GFP_KERNEL); + if (!bcm2835_isp_instances) + return -ENOMEM; + + vchiq_set_drvdata(device, bcm2835_isp_instances); + + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) { + ret = bcm2835_isp_probe_instance(device, + &bcm2835_isp_instances[i], i); + if (ret) + goto error; + } - vchiq_set_drvdata(device, dev); - v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME); + dev_info(&device->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME); return 0; error: