Skip to content

Commit c293474

Browse files
naushirpelwell
authored andcommitted
drivers: bcm2835_isp: Allow multiple users for the ISP driver.
Add a second (identical) set of device nodes to allow concurrent use of the 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 <[email protected]>
1 parent f9bd396 commit c293474

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

drivers/staging/vc04_services/bcm2835-isp/bcm2835-v4l2-isp.c

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626
#include "bcm2835-isp-ctrls.h"
2727
#include "bcm2835-isp-fmts.h"
2828

29+
/*
30+
* We want to instantiate 2 independent instances allowing 2 simultaneous users
31+
* of the ISP hardware.
32+
*/
33+
#define BCM2835_ISP_NUM_INSTANCES 2
34+
2935
static unsigned int debug;
3036
module_param(debug, uint, 0644);
3137
MODULE_PARM_DESC(debug, "activates debug info");
3238

33-
static unsigned int video_nr = 13;
34-
module_param(video_nr, uint, 0644);
35-
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");
3642

3743
#define BCM2835_ISP_NAME "bcm2835-isp"
3844
#define BCM2835_ISP_ENTITY_NAME_LEN 32
@@ -1279,6 +1285,7 @@ static int bcm2835_isp_get_supported_fmts(struct bcm2835_isp_node *node)
12791285
* or output nodes.
12801286
*/
12811287
static int register_node(struct bcm2835_isp_dev *dev,
1288+
unsigned int instance,
12821289
struct bcm2835_isp_node *node,
12831290
int index)
12841291
{
@@ -1439,7 +1446,7 @@ static int register_node(struct bcm2835_isp_dev *dev,
14391446
snprintf(vfd->name, sizeof(node->vfd.name), "%s-%s%d", BCM2835_ISP_NAME,
14401447
node->name, node->id);
14411448

1442-
ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr + index);
1449+
ret = video_register_device(vfd, VFL_TYPE_VIDEO, video_nr[instance]);
14431450
if (ret) {
14441451
v4l2_err(&dev->v4l2_dev,
14451452
"Failed to register video %s[%d] device node\n",
@@ -1660,9 +1667,8 @@ static int media_controller_register(struct bcm2835_isp_dev *dev)
16601667
return ret;
16611668
}
16621669

1663-
static int bcm2835_isp_remove(struct platform_device *pdev)
1670+
static void bcm2835_isp_remove_instance(struct bcm2835_isp_dev *dev)
16641671
{
1665-
struct bcm2835_isp_dev *dev = platform_get_drvdata(pdev);
16661672
unsigned int i;
16671673

16681674
media_controller_unregister(dev);
@@ -1677,11 +1683,11 @@ static int bcm2835_isp_remove(struct platform_device *pdev)
16771683
dev->component);
16781684

16791685
vchiq_mmal_finalise(dev->mmal_instance);
1680-
1681-
return 0;
16821686
}
16831687

1684-
static int bcm2835_isp_probe(struct platform_device *pdev)
1688+
static int bcm2835_isp_probe_instance(struct platform_device *pdev,
1689+
struct bcm2835_isp_dev **dev_int,
1690+
unsigned int instance)
16851691
{
16861692
struct bcm2835_isp_dev *dev;
16871693
unsigned int i;
@@ -1691,6 +1697,7 @@ static int bcm2835_isp_probe(struct platform_device *pdev)
16911697
if (!dev)
16921698
return -ENOMEM;
16931699

1700+
*dev_int = dev;
16941701
dev->dev = &pdev->dev;
16951702

16961703
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
@@ -1708,7 +1715,7 @@ static int bcm2835_isp_probe(struct platform_device *pdev)
17081715
if (ret) {
17091716
v4l2_err(&dev->v4l2_dev,
17101717
"%s: failed to create ril.isp component\n", __func__);
1711-
goto error;
1718+
return ret;
17121719
}
17131720

17141721
if (dev->component->inputs < BCM2835_ISP_NUM_OUTPUTS ||
@@ -1720,25 +1727,62 @@ static int bcm2835_isp_probe(struct platform_device *pdev)
17201727
BCM2835_ISP_NUM_OUTPUTS,
17211728
dev->component->outputs,
17221729
BCM2835_ISP_NUM_CAPTURES + BCM2835_ISP_NUM_METADATA);
1723-
goto error;
1730+
return -EINVAL;
17241731
}
17251732

17261733
atomic_set(&dev->num_streaming, 0);
17271734

17281735
for (i = 0; i < BCM2835_ISP_NUM_NODES; i++) {
17291736
struct bcm2835_isp_node *node = &dev->node[i];
17301737

1731-
ret = register_node(dev, node, i);
1738+
ret = register_node(dev, instance, node, i);
17321739
if (ret)
1733-
goto error;
1740+
return ret;
17341741
}
17351742

17361743
ret = media_controller_register(dev);
17371744
if (ret)
1738-
goto error;
1745+
return ret;
1746+
1747+
return 0;
1748+
}
1749+
1750+
static int bcm2835_isp_remove(struct platform_device *pdev)
1751+
{
1752+
struct bcm2835_isp_dev **bcm2835_isp_instances;
1753+
unsigned int i;
1754+
1755+
bcm2835_isp_instances = platform_get_drvdata(pdev);
1756+
for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
1757+
if (bcm2835_isp_instances[i])
1758+
bcm2835_isp_remove_instance(bcm2835_isp_instances[i]);
1759+
}
1760+
1761+
return 0;
1762+
}
1763+
1764+
static int bcm2835_isp_probe(struct platform_device *pdev)
1765+
{
1766+
struct bcm2835_isp_dev **bcm2835_isp_instances;
1767+
unsigned int i;
1768+
int ret;
1769+
1770+
bcm2835_isp_instances = devm_kzalloc(&pdev->dev,
1771+
sizeof(bcm2835_isp_instances) *
1772+
BCM2835_ISP_NUM_INSTANCES,
1773+
GFP_KERNEL);
1774+
if (!bcm2835_isp_instances)
1775+
return -ENOMEM;
1776+
1777+
for (i = 0; i < BCM2835_ISP_NUM_INSTANCES; i++) {
1778+
ret = bcm2835_isp_probe_instance(pdev,
1779+
&bcm2835_isp_instances[i], i);
1780+
if (ret)
1781+
goto error;
1782+
}
17391783

1740-
platform_set_drvdata(pdev, dev);
1741-
v4l2_info(&dev->v4l2_dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);
1784+
platform_set_drvdata(pdev, bcm2835_isp_instances);
1785+
dev_info(&pdev->dev, "Loaded V4L2 %s\n", BCM2835_ISP_NAME);
17421786
return 0;
17431787

17441788
error:

0 commit comments

Comments
 (0)