media: venus: firmware: register separate platform_device for firmware loader
authorStanimir Varbanov <stanimir.varbanov@linaro.org>
Wed, 17 Oct 2018 13:18:21 +0000 (09:18 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 23 Nov 2018 11:32:00 +0000 (06:32 -0500)
This registers a firmware platform_device and associate it with
video-firmware DT subnode. Then calls dma configure to initialize
dma and iommu.

Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/qcom/venus/core.c
drivers/media/platform/qcom/venus/core.h
drivers/media/platform/qcom/venus/firmware.c
drivers/media/platform/qcom/venus/firmware.h

index 75b9785..440f25f 100644 (file)
@@ -284,6 +284,14 @@ static int venus_probe(struct platform_device *pdev)
        if (ret < 0)
                goto err_runtime_disable;
 
+       ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
+       if (ret)
+               goto err_runtime_disable;
+
+       ret = venus_firmware_init(core);
+       if (ret)
+               goto err_runtime_disable;
+
        ret = venus_boot(core);
        if (ret)
                goto err_runtime_disable;
@@ -308,10 +316,6 @@ static int venus_probe(struct platform_device *pdev)
        if (ret)
                goto err_core_deinit;
 
-       ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
-       if (ret)
-               goto err_dev_unregister;
-
        ret = pm_runtime_put_sync(dev);
        if (ret)
                goto err_dev_unregister;
@@ -347,6 +351,8 @@ static int venus_remove(struct platform_device *pdev)
        venus_shutdown(dev);
        of_platform_depopulate(dev);
 
+       venus_firmware_deinit(core);
+
        pm_runtime_put_sync(dev);
        pm_runtime_disable(dev);
 
index 8b85dc8..c629666 100644 (file)
@@ -131,6 +131,9 @@ struct venus_core {
        struct device *dev_dec;
        struct device *dev_enc;
        unsigned int use_tz;
+       struct video_firmware {
+               struct device *dev;
+       } fw;
        struct mutex lock;
        struct list_head instances;
        atomic_t insts_count;
index 1d4f066..98b3b16 100644 (file)
@@ -18,6 +18,8 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
 #include <linux/qcom_scm.h>
 #include <linux/sizes.h>
 #include <linux/soc/qcom/mdt_loader.h>
@@ -144,3 +146,56 @@ int venus_shutdown(struct device *dev)
 {
        return qcom_scm_pas_shutdown(VENUS_PAS_ID);
 }
+
+int venus_firmware_init(struct venus_core *core)
+{
+       struct platform_device_info info;
+       struct platform_device *pdev;
+       struct device_node *np;
+       int ret;
+
+       np = of_get_child_by_name(core->dev->of_node, "video-firmware");
+       if (!np) {
+               core->use_tz = true;
+               return 0;
+       }
+
+       memset(&info, 0, sizeof(info));
+       info.fwnode = &np->fwnode;
+       info.parent = core->dev;
+       info.name = np->name;
+       info.dma_mask = DMA_BIT_MASK(32);
+
+       pdev = platform_device_register_full(&info);
+       if (IS_ERR(pdev)) {
+               of_node_put(np);
+               return PTR_ERR(pdev);
+       }
+
+       pdev->dev.of_node = np;
+
+       ret = of_dma_configure(&pdev->dev, np, true);
+       if (ret) {
+               dev_err(core->dev, "dma configure fail\n");
+               goto err_unregister;
+       }
+
+       core->fw.dev = &pdev->dev;
+
+       of_node_put(np);
+
+       return 0;
+
+err_unregister:
+       platform_device_unregister(pdev);
+       of_node_put(np);
+       return ret;
+}
+
+void venus_firmware_deinit(struct venus_core *core)
+{
+       if (!core->fw.dev)
+               return;
+
+       platform_device_unregister(to_platform_device(core->fw.dev));
+}
index 1343747..fd7edf0 100644 (file)
@@ -16,6 +16,8 @@
 
 struct device;
 
+int venus_firmware_init(struct venus_core *core);
+void venus_firmware_deinit(struct venus_core *core);
 int venus_boot(struct venus_core *core);
 int venus_shutdown(struct device *dev);
 int venus_set_hw_state(struct venus_core *core, bool suspend);