@@ -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: