1 From e858cd97b4301df3cc6b65f0ef16b4c1db1e1a06 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Tue, 16 Nov 2021 12:38:44 +0000
4 Subject: [PATCH] drivers: bcm2835_isp: Allow multiple users for the
7 Add a second (identical) set of device nodes to allow concurrent use of the ISP
8 hardware by another user. This change effectively creates a second state
9 structure (struct bcm2835_isp_dev) to maintain independent state for the second
10 user. Node and media entity names are appened with the instance index
13 Further users can be added by changing the BCM2835_ISP_NUM_INSTANCES define.
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
17 .../bcm2835-isp/bcm2835-v4l2-isp.c | 76 +++++++++++++++----
18 1 file changed, 60 insertions(+), 16 deletions(-)
20 --- a/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
21 +++ b/drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c
23 #include "bcm2835-isp-ctrls.h"
24 #include "bcm2835-isp-fmts.h"
27 + * We want to instantiate 2 independent instances allowing 2 simultaneous users
28 + * of the ISP hardware.
30 +#define BCM2835_ISP_NUM_INSTANCES 2
32 MODULE_IMPORT_NS(DMA_BUF);
34 static unsigned int debug;
35 module_param(debug, uint, 0644);
36 MODULE_PARM_DESC(debug, "activates debug info");
38 -static unsigned int video_nr = 13;
39 -module_param(video_nr, uint, 0644);
40 -MODULE_PARM_DESC(video_nr, "base video device number");
41 +static unsigned int video_nr[BCM2835_ISP_NUM_INSTANCES] = { 13, 20 };
42 +module_param_array(video_nr, uint, NULL, 0644);
43 +MODULE_PARM_DESC(video_nr, "base video device numbers");
45 #define BCM2835_ISP_NAME "bcm2835-isp"
46 #define BCM2835_ISP_ENTITY_NAME_LEN 32
47 @@ -1281,6 +1287,7 @@ static int bcm2835_isp_get_supported_fmt
50 static int register_node(struct bcm2835_isp_dev *dev,
51 + unsigned int instance,
52 struct bcm2835_isp_node *node,
55 @@ -1441,7 +1448,7 @@ static int register_node(struct bcm2835_
56 snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME,
57 node->name, node->id);
59 - ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr + index);
60 + ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]);
62 v4l2_err(&dev->v4l2_dev,
63 "Failed to register video %s[%d] device node\n",
64 @@ -1662,9 +1669,8 @@ done:
68 -static int bcm2835_isp_remove(struct platform_device *pdev)
69 +static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev)
71 - struct bcm2835_isp_dev *dev = platform_get_drvdata(pdev);
74 media_controller_unregister(dev);
75 @@ -1679,11 +1685,11 @@ static int bcm2835_isp_remove(struct pla
78 vchiq_mmal_finalise(dev->mmal_instance);
83 -static int bcm2835_isp_probe(struct platform_device *pdev)
84 +static int bcm2835_isp_probe_instance(struct platform_device *pdev,
85 + struct bcm2835_isp_dev **dev_int,
86 + unsigned int instance)
88 struct bcm2835_isp_dev *dev;
90 @@ -1693,6 +1699,7 @@ static int bcm2835_isp_probe(struct plat
95 dev->dev = &pdev->dev;
97 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
98 @@ -1710,7 +1717,7 @@ static int bcm2835_isp_probe(struct plat
100 v4l2_err(&dev->v4l2_dev,
101 "%s: failed to create ril.isp component\n", __func__);
106 if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS ||
107 @@ -1722,7 +1729,7 @@ static int bcm2835_isp_probe(struct plat
108 BCM2835_ISP_NUM_OUTPUTS,
109 dev->component->outputs,
110 BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA);
115 atomic_set(&dev->num_streaming, 0);
116 @@ -1730,17 +1737,54 @@ static int bcm2835_isp_probe(struct plat
117 for (i = 0; i < BCM2835_ISP_NUM_NODES; i++) {
118 struct bcm2835_isp_node *node = &dev->node[i];
120 - ret = register_node(dev, node, i);
121 + ret = register_node(dev, instance, node, i);
127 ret = media_controller_register(dev);
135 +static int bcm2835_isp_remove(struct platform_device *pdev)
137 + struct bcm2835_isp_dev **bcm2835_isp_instances;
140 + bcm2835_isp_instances = platform_get_drvdata(pdev);
141 + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
142 + if (bcm2835_isp_instances[i])
143 + bcm2835_isp_remove_instance(bcm2835_isp_instances[i]);
149 +static int bcm2835_isp_probe(struct platform_device *pdev)
151 + struct bcm2835_isp_dev **bcm2835_isp_instances;
155 + bcm2835_isp_instances = devm_kzalloc(&pdev->dev,
156 + sizeof(bcm2835_isp_instances) *
157 + BCM2835_ISP_NUM_INSTANCES,
159 + if (!bcm2835_isp_instances)
162 + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
163 + ret = bcm2835_isp_probe_instance(pdev,
164 + &bcm2835_isp_instances[i], i);
169 - platform_set_drvdata(pdev, dev);
170 - v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);
171 + platform_set_drvdata(pdev, bcm2835_isp_instances);
172 + dev_info(&pdev->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);