1 From 3d3cffb860398e43856ac5f2c831cb042be68795 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 static unsigned int debug;
33 module_param(debug, uint, 0644);
34 MODULE_PARM_DESC(debug, "activates debug info");
36 -static unsigned int video_nr = 13;
37 -module_param(video_nr, uint, 0644);
38 -MODULE_PARM_DESC(video_nr, "base video device number");
39 +static unsigned int video_nr[BCM2835_ISP_NUM_INSTANCES] = { 13, 20 };
40 +module_param_array(video_nr, uint, NULL, 0644);
41 +MODULE_PARM_DESC(video_nr, "base video device numbers");
43 #define BCM2835_ISP_NAME "bcm2835-isp"
44 #define BCM2835_ISP_ENTITY_NAME_LEN 32
45 @@ -1279,6 +1285,7 @@ static int bcm2835_isp_get_supported_fmt
48 static int register_node(struct bcm2835_isp_dev *dev,
49 + unsigned int instance,
50 struct bcm2835_isp_node *node,
53 @@ -1439,7 +1446,7 @@ static int register_node(struct bcm2835_
54 snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME,
55 node->name, node->id);
57 - ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr + index);
58 + ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]);
60 v4l2_err(&dev->v4l2_dev,
61 "Failed to register video %s[%d] device node\n",
62 @@ -1660,9 +1667,8 @@ done:
66 -static int bcm2835_isp_remove(struct platform_device *pdev)
67 +static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev)
69 - struct bcm2835_isp_dev *dev = platform_get_drvdata(pdev);
72 media_controller_unregister(dev);
73 @@ -1677,11 +1683,11 @@ static int bcm2835_isp_remove(struct pla
76 vchiq_mmal_finalise(dev->mmal_instance);
81 -static int bcm2835_isp_probe(struct platform_device *pdev)
82 +static int bcm2835_isp_probe_instance(struct platform_device *pdev,
83 + struct bcm2835_isp_dev **dev_int,
84 + unsigned int instance)
86 struct bcm2835_isp_dev *dev;
88 @@ -1691,6 +1697,7 @@ static int bcm2835_isp_probe(struct plat
93 dev->dev = &pdev->dev;
95 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
96 @@ -1708,7 +1715,7 @@ static int bcm2835_isp_probe(struct plat
98 v4l2_err(&dev->v4l2_dev,
99 "%s: failed to create ril.isp component\n", __func__);
104 if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS ||
105 @@ -1720,7 +1727,7 @@ static int bcm2835_isp_probe(struct plat
106 BCM2835_ISP_NUM_OUTPUTS,
107 dev->component->outputs,
108 BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA);
113 atomic_set(&dev->num_streaming, 0);
114 @@ -1728,17 +1735,54 @@ static int bcm2835_isp_probe(struct plat
115 for (i = 0; i < BCM2835_ISP_NUM_NODES; i++) {
116 struct bcm2835_isp_node *node = &dev->node[i];
118 - ret = register_node(dev, node, i);
119 + ret = register_node(dev, instance, node, i);
125 ret = media_controller_register(dev);
133 +static int bcm2835_isp_remove(struct platform_device *pdev)
135 + struct bcm2835_isp_dev **bcm2835_isp_instances;
138 + bcm2835_isp_instances = platform_get_drvdata(pdev);
139 + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
140 + if (bcm2835_isp_instances[i])
141 + bcm2835_isp_remove_instance(bcm2835_isp_instances[i]);
147 +static int bcm2835_isp_probe(struct platform_device *pdev)
149 + struct bcm2835_isp_dev **bcm2835_isp_instances;
153 + bcm2835_isp_instances = devm_kzalloc(&pdev->dev,
154 + sizeof(bcm2835_isp_instances) *
155 + BCM2835_ISP_NUM_INSTANCES,
157 + if (!bcm2835_isp_instances)
160 + for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
161 + ret = bcm2835_isp_probe_instance(pdev,
162 + &bcm2835_isp_instances[i], i);
167 - platform_set_drvdata(pdev, dev);
168 - v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);
169 + platform_set_drvdata(pdev, bcm2835_isp_instances);
170 + dev_info(&pdev->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);