|
@@ -22,6 +22,7 @@
|
|
#include <media/v4l2-event.h>
|
|
#include <media/v4l2-event.h>
|
|
#include <linux/workqueue.h>
|
|
#include <linux/workqueue.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of.h>
|
|
|
|
+#include <linux/of_reserved_mem.h>
|
|
#include <media/videobuf2-v4l2.h>
|
|
#include <media/videobuf2-v4l2.h>
|
|
#include "s5p_mfc_common.h"
|
|
#include "s5p_mfc_common.h"
|
|
#include "s5p_mfc_ctrl.h"
|
|
#include "s5p_mfc_ctrl.h"
|
|
@@ -29,6 +30,7 @@
|
|
#include "s5p_mfc_dec.h"
|
|
#include "s5p_mfc_dec.h"
|
|
#include "s5p_mfc_enc.h"
|
|
#include "s5p_mfc_enc.h"
|
|
#include "s5p_mfc_intr.h"
|
|
#include "s5p_mfc_intr.h"
|
|
|
|
+#include "s5p_mfc_iommu.h"
|
|
#include "s5p_mfc_opr.h"
|
|
#include "s5p_mfc_opr.h"
|
|
#include "s5p_mfc_cmd.h"
|
|
#include "s5p_mfc_cmd.h"
|
|
#include "s5p_mfc_pm.h"
|
|
#include "s5p_mfc_pm.h"
|
|
@@ -1043,55 +1045,94 @@ static const struct v4l2_file_operations s5p_mfc_fops = {
|
|
.mmap = s5p_mfc_mmap,
|
|
.mmap = s5p_mfc_mmap,
|
|
};
|
|
};
|
|
|
|
|
|
-static int match_child(struct device *dev, void *data)
|
|
|
|
|
|
+/* DMA memory related helper functions */
|
|
|
|
+static void s5p_mfc_memdev_release(struct device *dev)
|
|
{
|
|
{
|
|
- if (!dev_name(dev))
|
|
|
|
- return 0;
|
|
|
|
- return !strcmp(dev_name(dev), (char *)data);
|
|
|
|
|
|
+ of_reserved_mem_device_release(dev);
|
|
}
|
|
}
|
|
|
|
|
|
-static void *mfc_get_drv_data(struct platform_device *pdev);
|
|
|
|
-
|
|
|
|
-static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
|
|
|
|
|
|
+static struct device *s5p_mfc_alloc_memdev(struct device *dev,
|
|
|
|
+ const char *name, unsigned int idx)
|
|
{
|
|
{
|
|
- unsigned int mem_info[2] = { };
|
|
|
|
|
|
+ struct device *child;
|
|
|
|
+ int ret;
|
|
|
|
|
|
- dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
|
|
|
|
- sizeof(struct device), GFP_KERNEL);
|
|
|
|
- if (!dev->mem_dev_l) {
|
|
|
|
- mfc_err("Not enough memory\n");
|
|
|
|
- return -ENOMEM;
|
|
|
|
- }
|
|
|
|
- device_initialize(dev->mem_dev_l);
|
|
|
|
- of_property_read_u32_array(dev->plat_dev->dev.of_node,
|
|
|
|
- "samsung,mfc-l", mem_info, 2);
|
|
|
|
- if (dma_declare_coherent_memory(dev->mem_dev_l, mem_info[0],
|
|
|
|
- mem_info[0], mem_info[1],
|
|
|
|
- DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
|
|
|
|
- mfc_err("Failed to declare coherent memory for\n"
|
|
|
|
- "MFC device\n");
|
|
|
|
- return -ENOMEM;
|
|
|
|
|
|
+ child = devm_kzalloc(dev, sizeof(struct device), GFP_KERNEL);
|
|
|
|
+ if (!child)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ device_initialize(child);
|
|
|
|
+ dev_set_name(child, "%s:%s", dev_name(dev), name);
|
|
|
|
+ child->parent = dev;
|
|
|
|
+ child->bus = dev->bus;
|
|
|
|
+ child->coherent_dma_mask = dev->coherent_dma_mask;
|
|
|
|
+ child->dma_mask = dev->dma_mask;
|
|
|
|
+ child->release = s5p_mfc_memdev_release;
|
|
|
|
+
|
|
|
|
+ if (device_add(child) == 0) {
|
|
|
|
+ ret = of_reserved_mem_device_init_by_idx(child, dev->of_node,
|
|
|
|
+ idx);
|
|
|
|
+ if (ret == 0)
|
|
|
|
+ return child;
|
|
}
|
|
}
|
|
|
|
|
|
- dev->mem_dev_r = devm_kzalloc(&dev->plat_dev->dev,
|
|
|
|
- sizeof(struct device), GFP_KERNEL);
|
|
|
|
- if (!dev->mem_dev_r) {
|
|
|
|
- mfc_err("Not enough memory\n");
|
|
|
|
- return -ENOMEM;
|
|
|
|
|
|
+ put_device(child);
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int s5p_mfc_configure_dma_memory(struct s5p_mfc_dev *mfc_dev)
|
|
|
|
+{
|
|
|
|
+ struct device *dev = &mfc_dev->plat_dev->dev;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * When IOMMU is available, we cannot use the default configuration,
|
|
|
|
+ * because of MFC firmware requirements: address space limited to
|
|
|
|
+ * 256M and non-zero default start address.
|
|
|
|
+ * This is still simplified, not optimal configuration, but for now
|
|
|
|
+ * IOMMU core doesn't allow to configure device's IOMMUs channel
|
|
|
|
+ * separately.
|
|
|
|
+ */
|
|
|
|
+ if (exynos_is_iommu_available(dev)) {
|
|
|
|
+ int ret = exynos_configure_iommu(dev, S5P_MFC_IOMMU_DMA_BASE,
|
|
|
|
+ S5P_MFC_IOMMU_DMA_SIZE);
|
|
|
|
+ if (ret == 0)
|
|
|
|
+ mfc_dev->mem_dev_l = mfc_dev->mem_dev_r = dev;
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
- device_initialize(dev->mem_dev_r);
|
|
|
|
- of_property_read_u32_array(dev->plat_dev->dev.of_node,
|
|
|
|
- "samsung,mfc-r", mem_info, 2);
|
|
|
|
- if (dma_declare_coherent_memory(dev->mem_dev_r, mem_info[0],
|
|
|
|
- mem_info[0], mem_info[1],
|
|
|
|
- DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
|
|
|
|
- pr_err("Failed to declare coherent memory for\n"
|
|
|
|
- "MFC device\n");
|
|
|
|
- return -ENOMEM;
|
|
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Create and initialize virtual devices for accessing
|
|
|
|
+ * reserved memory regions.
|
|
|
|
+ */
|
|
|
|
+ mfc_dev->mem_dev_l = s5p_mfc_alloc_memdev(dev, "left",
|
|
|
|
+ MFC_BANK1_ALLOC_CTX);
|
|
|
|
+ if (!mfc_dev->mem_dev_l)
|
|
|
|
+ return -ENODEV;
|
|
|
|
+ mfc_dev->mem_dev_r = s5p_mfc_alloc_memdev(dev, "right",
|
|
|
|
+ MFC_BANK2_ALLOC_CTX);
|
|
|
|
+ if (!mfc_dev->mem_dev_r) {
|
|
|
|
+ device_unregister(mfc_dev->mem_dev_l);
|
|
|
|
+ return -ENODEV;
|
|
}
|
|
}
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void s5p_mfc_unconfigure_dma_memory(struct s5p_mfc_dev *mfc_dev)
|
|
|
|
+{
|
|
|
|
+ struct device *dev = &mfc_dev->plat_dev->dev;
|
|
|
|
+
|
|
|
|
+ if (exynos_is_iommu_available(dev)) {
|
|
|
|
+ exynos_unconfigure_iommu(dev);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ device_unregister(mfc_dev->mem_dev_l);
|
|
|
|
+ device_unregister(mfc_dev->mem_dev_r);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void *mfc_get_drv_data(struct platform_device *pdev);
|
|
|
|
+
|
|
/* MFC probe function */
|
|
/* MFC probe function */
|
|
static int s5p_mfc_probe(struct platform_device *pdev)
|
|
static int s5p_mfc_probe(struct platform_device *pdev)
|
|
{
|
|
{
|
|
@@ -1117,12 +1158,6 @@ static int s5p_mfc_probe(struct platform_device *pdev)
|
|
|
|
|
|
dev->variant = mfc_get_drv_data(pdev);
|
|
dev->variant = mfc_get_drv_data(pdev);
|
|
|
|
|
|
- ret = s5p_mfc_init_pm(dev);
|
|
|
|
- if (ret < 0) {
|
|
|
|
- dev_err(&pdev->dev, "failed to get mfc clock source\n");
|
|
|
|
- return ret;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
|
dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
|
|
dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
|
|
@@ -1143,32 +1178,25 @@ static int s5p_mfc_probe(struct platform_device *pdev)
|
|
goto err_res;
|
|
goto err_res;
|
|
}
|
|
}
|
|
|
|
|
|
- if (pdev->dev.of_node) {
|
|
|
|
- ret = s5p_mfc_alloc_memdevs(dev);
|
|
|
|
- if (ret < 0)
|
|
|
|
- goto err_res;
|
|
|
|
- } else {
|
|
|
|
- dev->mem_dev_l = device_find_child(&dev->plat_dev->dev,
|
|
|
|
- "s5p-mfc-l", match_child);
|
|
|
|
- if (!dev->mem_dev_l) {
|
|
|
|
- mfc_err("Mem child (L) device get failed\n");
|
|
|
|
- ret = -ENODEV;
|
|
|
|
- goto err_res;
|
|
|
|
- }
|
|
|
|
- dev->mem_dev_r = device_find_child(&dev->plat_dev->dev,
|
|
|
|
- "s5p-mfc-r", match_child);
|
|
|
|
- if (!dev->mem_dev_r) {
|
|
|
|
- mfc_err("Mem child (R) device get failed\n");
|
|
|
|
- ret = -ENODEV;
|
|
|
|
- goto err_res;
|
|
|
|
- }
|
|
|
|
|
|
+ ret = s5p_mfc_configure_dma_memory(dev);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&pdev->dev, "failed to configure DMA memory\n");
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ret = s5p_mfc_init_pm(dev);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ dev_err(&pdev->dev, "failed to get mfc clock source\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vb2_dma_contig_set_max_seg_size(dev->mem_dev_l, DMA_BIT_MASK(32));
|
|
dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l);
|
|
dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l);
|
|
if (IS_ERR(dev->alloc_ctx[0])) {
|
|
if (IS_ERR(dev->alloc_ctx[0])) {
|
|
ret = PTR_ERR(dev->alloc_ctx[0]);
|
|
ret = PTR_ERR(dev->alloc_ctx[0]);
|
|
goto err_res;
|
|
goto err_res;
|
|
}
|
|
}
|
|
|
|
+ vb2_dma_contig_set_max_seg_size(dev->mem_dev_r, DMA_BIT_MASK(32));
|
|
dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r);
|
|
dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r);
|
|
if (IS_ERR(dev->alloc_ctx[1])) {
|
|
if (IS_ERR(dev->alloc_ctx[1])) {
|
|
ret = PTR_ERR(dev->alloc_ctx[1]);
|
|
ret = PTR_ERR(dev->alloc_ctx[1]);
|
|
@@ -1201,14 +1229,6 @@ static int s5p_mfc_probe(struct platform_device *pdev)
|
|
vfd->vfl_dir = VFL_DIR_M2M;
|
|
vfd->vfl_dir = VFL_DIR_M2M;
|
|
snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME);
|
|
snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME);
|
|
dev->vfd_dec = vfd;
|
|
dev->vfd_dec = vfd;
|
|
- ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
|
|
|
|
- if (ret) {
|
|
|
|
- v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
|
|
|
|
- video_device_release(vfd);
|
|
|
|
- goto err_dec_reg;
|
|
|
|
- }
|
|
|
|
- v4l2_info(&dev->v4l2_dev,
|
|
|
|
- "decoder registered as /dev/video%d\n", vfd->num);
|
|
|
|
video_set_drvdata(vfd, dev);
|
|
video_set_drvdata(vfd, dev);
|
|
|
|
|
|
/* encoder */
|
|
/* encoder */
|
|
@@ -1226,14 +1246,6 @@ static int s5p_mfc_probe(struct platform_device *pdev)
|
|
vfd->vfl_dir = VFL_DIR_M2M;
|
|
vfd->vfl_dir = VFL_DIR_M2M;
|
|
snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_ENC_NAME);
|
|
snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_ENC_NAME);
|
|
dev->vfd_enc = vfd;
|
|
dev->vfd_enc = vfd;
|
|
- ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
|
|
|
|
- if (ret) {
|
|
|
|
- v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
|
|
|
|
- video_device_release(vfd);
|
|
|
|
- goto err_enc_reg;
|
|
|
|
- }
|
|
|
|
- v4l2_info(&dev->v4l2_dev,
|
|
|
|
- "encoder registered as /dev/video%d\n", vfd->num);
|
|
|
|
video_set_drvdata(vfd, dev);
|
|
video_set_drvdata(vfd, dev);
|
|
platform_set_drvdata(pdev, dev);
|
|
platform_set_drvdata(pdev, dev);
|
|
|
|
|
|
@@ -1250,15 +1262,34 @@ static int s5p_mfc_probe(struct platform_device *pdev)
|
|
s5p_mfc_init_hw_cmds(dev);
|
|
s5p_mfc_init_hw_cmds(dev);
|
|
s5p_mfc_init_regs(dev);
|
|
s5p_mfc_init_regs(dev);
|
|
|
|
|
|
|
|
+ /* Register decoder and encoder */
|
|
|
|
+ ret = video_register_device(dev->vfd_dec, VFL_TYPE_GRABBER, 0);
|
|
|
|
+ if (ret) {
|
|
|
|
+ v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
|
|
|
|
+ video_device_release(dev->vfd_dec);
|
|
|
|
+ goto err_dec_reg;
|
|
|
|
+ }
|
|
|
|
+ v4l2_info(&dev->v4l2_dev,
|
|
|
|
+ "decoder registered as /dev/video%d\n", dev->vfd_dec->num);
|
|
|
|
+
|
|
|
|
+ ret = video_register_device(dev->vfd_enc, VFL_TYPE_GRABBER, 0);
|
|
|
|
+ if (ret) {
|
|
|
|
+ v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
|
|
|
|
+ video_device_release(dev->vfd_enc);
|
|
|
|
+ goto err_enc_reg;
|
|
|
|
+ }
|
|
|
|
+ v4l2_info(&dev->v4l2_dev,
|
|
|
|
+ "encoder registered as /dev/video%d\n", dev->vfd_enc->num);
|
|
|
|
+
|
|
pr_debug("%s--\n", __func__);
|
|
pr_debug("%s--\n", __func__);
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
/* Deinit MFC if probe had failed */
|
|
/* Deinit MFC if probe had failed */
|
|
err_enc_reg:
|
|
err_enc_reg:
|
|
- video_device_release(dev->vfd_enc);
|
|
|
|
-err_enc_alloc:
|
|
|
|
video_unregister_device(dev->vfd_dec);
|
|
video_unregister_device(dev->vfd_dec);
|
|
err_dec_reg:
|
|
err_dec_reg:
|
|
|
|
+ video_device_release(dev->vfd_enc);
|
|
|
|
+err_enc_alloc:
|
|
video_device_release(dev->vfd_dec);
|
|
video_device_release(dev->vfd_dec);
|
|
err_dec_alloc:
|
|
err_dec_alloc:
|
|
v4l2_device_unregister(&dev->v4l2_dev);
|
|
v4l2_device_unregister(&dev->v4l2_dev);
|
|
@@ -1293,10 +1324,9 @@ static int s5p_mfc_remove(struct platform_device *pdev)
|
|
s5p_mfc_release_firmware(dev);
|
|
s5p_mfc_release_firmware(dev);
|
|
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
|
|
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
|
|
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
|
|
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
|
|
- if (pdev->dev.of_node) {
|
|
|
|
- put_device(dev->mem_dev_l);
|
|
|
|
- put_device(dev->mem_dev_r);
|
|
|
|
- }
|
|
|
|
|
|
+ s5p_mfc_unconfigure_dma_memory(dev);
|
|
|
|
+ vb2_dma_contig_clear_max_seg_size(dev->mem_dev_l);
|
|
|
|
+ vb2_dma_contig_clear_max_seg_size(dev->mem_dev_r);
|
|
|
|
|
|
s5p_mfc_final_pm(dev);
|
|
s5p_mfc_final_pm(dev);
|
|
return 0;
|
|
return 0;
|