mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-26 05:34:13 +08:00
[media] media: Add Mediatek MDP Driver
Add MDP driver for MT8173 Signed-off-by: Minghsiu Tsai <minghsiu.tsai@mediatek.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
parent
b391202c06
commit
c8eb2d7e82
@ -175,6 +175,23 @@ config VIDEO_MEDIATEK_VPU
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called mtk-vpu.
|
||||
|
||||
config VIDEO_MEDIATEK_MDP
|
||||
tristate "Mediatek MDP driver"
|
||||
depends on MTK_IOMMU || COMPILE_TEST
|
||||
depends on VIDEO_DEV && VIDEO_V4L2
|
||||
depends on ARCH_MEDIATEK || COMPILE_TEST
|
||||
depends on HAS_DMA
|
||||
select VIDEOBUF2_DMA_CONTIG
|
||||
select V4L2_MEM2MEM_DEV
|
||||
select VIDEO_MEDIATEK_VPU
|
||||
default n
|
||||
---help---
|
||||
It is a v4l2 driver and present in Mediatek MT8173 SoCs.
|
||||
The driver supports for scaling and color space conversion.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called mtk-mdp.
|
||||
|
||||
config VIDEO_MEDIATEK_VCODEC
|
||||
tristate "Mediatek Video Codec driver"
|
||||
depends on MTK_IOMMU || COMPILE_TEST
|
||||
|
@ -66,3 +66,5 @@ ccflags-y += -I$(srctree)/drivers/media/i2c
|
||||
obj-$(CONFIG_VIDEO_MEDIATEK_VPU) += mtk-vpu/
|
||||
|
||||
obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec/
|
||||
|
||||
obj-$(CONFIG_VIDEO_MEDIATEK_MDP) += mtk-mdp/
|
||||
|
9
drivers/media/platform/mtk-mdp/Makefile
Normal file
9
drivers/media/platform/mtk-mdp/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
mtk-mdp-y += mtk_mdp_core.o
|
||||
mtk-mdp-y += mtk_mdp_comp.o
|
||||
mtk-mdp-y += mtk_mdp_m2m.o
|
||||
mtk-mdp-y += mtk_mdp_regs.o
|
||||
mtk-mdp-y += mtk_mdp_vpu.o
|
||||
|
||||
obj-$(CONFIG_VIDEO_MEDIATEK_MDP) += mtk-mdp.o
|
||||
|
||||
ccflags-y += -I$(srctree)/drivers/media/platform/mtk-vpu
|
159
drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
Normal file
159
drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
Normal file
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MediaTek Inc.
|
||||
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <soc/mediatek/smi.h>
|
||||
|
||||
#include "mtk_mdp_comp.h"
|
||||
|
||||
|
||||
static const char * const mtk_mdp_comp_stem[MTK_MDP_COMP_TYPE_MAX] = {
|
||||
"mdp_rdma",
|
||||
"mdp_rsz",
|
||||
"mdp_wdma",
|
||||
"mdp_wrot",
|
||||
};
|
||||
|
||||
struct mtk_mdp_comp_match {
|
||||
enum mtk_mdp_comp_type type;
|
||||
int alias_id;
|
||||
};
|
||||
|
||||
static const struct mtk_mdp_comp_match mtk_mdp_matches[MTK_MDP_COMP_ID_MAX] = {
|
||||
{ MTK_MDP_RDMA, 0 },
|
||||
{ MTK_MDP_RDMA, 1 },
|
||||
{ MTK_MDP_RSZ, 0 },
|
||||
{ MTK_MDP_RSZ, 1 },
|
||||
{ MTK_MDP_RSZ, 2 },
|
||||
{ MTK_MDP_WDMA, 0 },
|
||||
{ MTK_MDP_WROT, 0 },
|
||||
{ MTK_MDP_WROT, 1 },
|
||||
};
|
||||
|
||||
int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
|
||||
enum mtk_mdp_comp_type comp_type)
|
||||
{
|
||||
int id = of_alias_get_id(node, mtk_mdp_comp_stem[comp_type]);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mtk_mdp_matches); i++) {
|
||||
if (comp_type == mtk_mdp_matches[i].type &&
|
||||
id == mtk_mdp_matches[i].alias_id)
|
||||
return i;
|
||||
}
|
||||
|
||||
dev_err(dev, "Failed to get id. type: %d, id: %d\n", comp_type, id);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
|
||||
{
|
||||
int i, err;
|
||||
|
||||
if (comp->larb_dev) {
|
||||
err = mtk_smi_larb_get(comp->larb_dev);
|
||||
if (err)
|
||||
dev_err(dev,
|
||||
"failed to get larb, err %d. type:%d id:%d\n",
|
||||
err, comp->type, comp->id);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
|
||||
if (!comp->clk[i])
|
||||
continue;
|
||||
err = clk_prepare_enable(comp->clk[i]);
|
||||
if (err)
|
||||
dev_err(dev,
|
||||
"failed to enable clock, err %d. type:%d id:%d i:%d\n",
|
||||
err, comp->type, comp->id, i);
|
||||
}
|
||||
}
|
||||
|
||||
void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
|
||||
if (!comp->clk[i])
|
||||
continue;
|
||||
clk_disable_unprepare(comp->clk[i]);
|
||||
}
|
||||
|
||||
if (comp->larb_dev)
|
||||
mtk_smi_larb_put(comp->larb_dev);
|
||||
}
|
||||
|
||||
int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
|
||||
struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id)
|
||||
{
|
||||
struct device_node *larb_node;
|
||||
struct platform_device *larb_pdev;
|
||||
int i;
|
||||
|
||||
if (comp_id < 0 || comp_id >= MTK_MDP_COMP_ID_MAX) {
|
||||
dev_err(dev, "Invalid comp_id %d\n", comp_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
comp->dev_node = of_node_get(node);
|
||||
comp->id = comp_id;
|
||||
comp->type = mtk_mdp_matches[comp_id].type;
|
||||
comp->regs = of_iomap(node, 0);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
|
||||
comp->clk[i] = of_clk_get(node, i);
|
||||
|
||||
/* Only RDMA needs two clocks */
|
||||
if (comp->type != MTK_MDP_RDMA)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Only DMA capable components need the LARB property */
|
||||
comp->larb_dev = NULL;
|
||||
if (comp->type != MTK_MDP_RDMA &&
|
||||
comp->type != MTK_MDP_WDMA &&
|
||||
comp->type != MTK_MDP_WROT)
|
||||
return 0;
|
||||
|
||||
larb_node = of_parse_phandle(node, "mediatek,larb", 0);
|
||||
if (!larb_node) {
|
||||
dev_err(dev,
|
||||
"Missing mediadek,larb phandle in %s node\n",
|
||||
node->full_name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
larb_pdev = of_find_device_by_node(larb_node);
|
||||
if (!larb_pdev) {
|
||||
dev_warn(dev, "Waiting for larb device %s\n",
|
||||
larb_node->full_name);
|
||||
of_node_put(larb_node);
|
||||
return -EPROBE_DEFER;
|
||||
}
|
||||
of_node_put(larb_node);
|
||||
|
||||
comp->larb_dev = &larb_pdev->dev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp)
|
||||
{
|
||||
of_node_put(comp->dev_node);
|
||||
}
|
72
drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
Normal file
72
drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MediaTek Inc.
|
||||
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_COMP_H__
|
||||
#define __MTK_MDP_COMP_H__
|
||||
|
||||
/**
|
||||
* enum mtk_mdp_comp_type - the MDP component
|
||||
* @MTK_MDP_RDMA: Read DMA
|
||||
* @MTK_MDP_RSZ: Riszer
|
||||
* @MTK_MDP_WDMA: Write DMA
|
||||
* @MTK_MDP_WROT: Write DMA with rotation
|
||||
*/
|
||||
enum mtk_mdp_comp_type {
|
||||
MTK_MDP_RDMA,
|
||||
MTK_MDP_RSZ,
|
||||
MTK_MDP_WDMA,
|
||||
MTK_MDP_WROT,
|
||||
MTK_MDP_COMP_TYPE_MAX,
|
||||
};
|
||||
|
||||
enum mtk_mdp_comp_id {
|
||||
MTK_MDP_COMP_RDMA0,
|
||||
MTK_MDP_COMP_RDMA1,
|
||||
MTK_MDP_COMP_RSZ0,
|
||||
MTK_MDP_COMP_RSZ1,
|
||||
MTK_MDP_COMP_RSZ2,
|
||||
MTK_MDP_COMP_WDMA,
|
||||
MTK_MDP_COMP_WROT0,
|
||||
MTK_MDP_COMP_WROT1,
|
||||
MTK_MDP_COMP_ID_MAX,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_comp - the MDP's function component data
|
||||
* @dev_node: component device node
|
||||
* @clk: clocks required for component
|
||||
* @regs: Mapped address of component registers.
|
||||
* @larb_dev: SMI device required for component
|
||||
* @type: component type
|
||||
* @id: component ID
|
||||
*/
|
||||
struct mtk_mdp_comp {
|
||||
struct device_node *dev_node;
|
||||
struct clk *clk[2];
|
||||
void __iomem *regs;
|
||||
struct device *larb_dev;
|
||||
enum mtk_mdp_comp_type type;
|
||||
enum mtk_mdp_comp_id id;
|
||||
};
|
||||
|
||||
int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
|
||||
struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id);
|
||||
void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp);
|
||||
int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
|
||||
enum mtk_mdp_comp_type comp_type);
|
||||
void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp);
|
||||
void mtk_mdp_comp_clock_off(struct device *dev, struct mtk_mdp_comp *comp);
|
||||
|
||||
|
||||
#endif /* __MTK_MDP_COMP_H__ */
|
294
drivers/media/platform/mtk-mdp/mtk_mdp_core.c
Normal file
294
drivers/media/platform/mtk-mdp/mtk_mdp_core.c
Normal file
@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <soc/mediatek/smi.h>
|
||||
|
||||
#include "mtk_mdp_core.h"
|
||||
#include "mtk_mdp_m2m.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
/* MDP debug log level (0-3). 3 shows all the logs. */
|
||||
int mtk_mdp_dbg_level;
|
||||
EXPORT_SYMBOL(mtk_mdp_dbg_level);
|
||||
|
||||
module_param(mtk_mdp_dbg_level, int, 0644);
|
||||
|
||||
static const struct of_device_id mtk_mdp_comp_dt_ids[] = {
|
||||
{
|
||||
.compatible = "mediatek,mt8173-mdp-rdma",
|
||||
.data = (void *)MTK_MDP_RDMA
|
||||
}, {
|
||||
.compatible = "mediatek,mt8173-mdp-rsz",
|
||||
.data = (void *)MTK_MDP_RSZ
|
||||
}, {
|
||||
.compatible = "mediatek,mt8173-mdp-wdma",
|
||||
.data = (void *)MTK_MDP_WDMA
|
||||
}, {
|
||||
.compatible = "mediatek,mt8173-mdp-wrot",
|
||||
.data = (void *)MTK_MDP_WROT
|
||||
}
|
||||
};
|
||||
|
||||
static const struct of_device_id mtk_mdp_of_ids[] = {
|
||||
{ .compatible = "mediatek,mt8173-mdp", },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
|
||||
|
||||
static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
|
||||
{
|
||||
struct device *dev = &mdp->pdev->dev;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
|
||||
mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
|
||||
}
|
||||
|
||||
static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
|
||||
{
|
||||
struct device *dev = &mdp->pdev->dev;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
|
||||
mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
|
||||
}
|
||||
|
||||
static void mtk_mdp_wdt_worker(struct work_struct *work)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp =
|
||||
container_of(work, struct mtk_mdp_dev, wdt_work);
|
||||
struct mtk_mdp_ctx *ctx;
|
||||
|
||||
mtk_mdp_err("Watchdog timeout");
|
||||
|
||||
list_for_each_entry(ctx, &mdp->ctx_list, list) {
|
||||
mtk_mdp_dbg(0, "[%d] Change as state error", ctx->id);
|
||||
mtk_mdp_ctx_state_lock_set(ctx, MTK_MDP_CTX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_mdp_reset_handler(void *priv)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp = priv;
|
||||
|
||||
queue_work(mdp->wdt_wq, &mdp->wdt_work);
|
||||
}
|
||||
|
||||
static int mtk_mdp_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct device_node *node;
|
||||
int i, ret = 0;
|
||||
|
||||
mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
|
||||
if (!mdp)
|
||||
return -ENOMEM;
|
||||
|
||||
mdp->id = pdev->id;
|
||||
mdp->pdev = pdev;
|
||||
INIT_LIST_HEAD(&mdp->ctx_list);
|
||||
|
||||
mutex_init(&mdp->lock);
|
||||
mutex_init(&mdp->vpulock);
|
||||
|
||||
/* Iterate over sibling MDP function blocks */
|
||||
for_each_child_of_node(dev->of_node, node) {
|
||||
const struct of_device_id *of_id;
|
||||
enum mtk_mdp_comp_type comp_type;
|
||||
int comp_id;
|
||||
struct mtk_mdp_comp *comp;
|
||||
|
||||
of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
|
||||
if (!of_id)
|
||||
continue;
|
||||
|
||||
if (!of_device_is_available(node)) {
|
||||
dev_err(dev, "Skipping disabled component %s\n",
|
||||
node->full_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
comp_type = (enum mtk_mdp_comp_type)of_id->data;
|
||||
comp_id = mtk_mdp_comp_get_id(dev, node, comp_type);
|
||||
if (comp_id < 0) {
|
||||
dev_warn(dev, "Skipping unknown component %s\n",
|
||||
node->full_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
|
||||
if (!comp) {
|
||||
ret = -ENOMEM;
|
||||
goto err_comp;
|
||||
}
|
||||
mdp->comp[comp_id] = comp;
|
||||
|
||||
ret = mtk_mdp_comp_init(dev, node, comp, comp_id);
|
||||
if (ret)
|
||||
goto err_comp;
|
||||
}
|
||||
|
||||
mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME);
|
||||
if (!mdp->job_wq) {
|
||||
dev_err(&pdev->dev, "unable to alloc job workqueue\n");
|
||||
ret = -ENOMEM;
|
||||
goto err_alloc_job_wq;
|
||||
}
|
||||
|
||||
mdp->wdt_wq = create_singlethread_workqueue("mdp_wdt_wq");
|
||||
if (!mdp->wdt_wq) {
|
||||
dev_err(&pdev->dev, "unable to alloc wdt workqueue\n");
|
||||
ret = -ENOMEM;
|
||||
goto err_alloc_wdt_wq;
|
||||
}
|
||||
INIT_WORK(&mdp->wdt_work, mtk_mdp_wdt_worker);
|
||||
|
||||
ret = v4l2_device_register(dev, &mdp->v4l2_dev);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "Failed to register v4l2 device\n");
|
||||
ret = -EINVAL;
|
||||
goto err_dev_register;
|
||||
}
|
||||
|
||||
ret = mtk_mdp_register_m2m_device(mdp);
|
||||
if (ret) {
|
||||
v4l2_err(&mdp->v4l2_dev, "Failed to init mem2mem device\n");
|
||||
goto err_m2m_register;
|
||||
}
|
||||
|
||||
mdp->vpu_dev = vpu_get_plat_device(pdev);
|
||||
vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
|
||||
VPU_RST_MDP);
|
||||
|
||||
platform_set_drvdata(pdev, mdp);
|
||||
|
||||
vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
|
||||
|
||||
pm_runtime_enable(dev);
|
||||
dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id);
|
||||
|
||||
return 0;
|
||||
|
||||
err_m2m_register:
|
||||
v4l2_device_unregister(&mdp->v4l2_dev);
|
||||
|
||||
err_dev_register:
|
||||
destroy_workqueue(mdp->wdt_wq);
|
||||
|
||||
err_alloc_wdt_wq:
|
||||
destroy_workqueue(mdp->job_wq);
|
||||
|
||||
err_alloc_job_wq:
|
||||
|
||||
err_comp:
|
||||
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
|
||||
mtk_mdp_comp_deinit(dev, mdp->comp[i]);
|
||||
|
||||
dev_dbg(dev, "err %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mtk_mdp_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
|
||||
int i;
|
||||
|
||||
pm_runtime_disable(&pdev->dev);
|
||||
vb2_dma_contig_clear_max_seg_size(&pdev->dev);
|
||||
mtk_mdp_unregister_m2m_device(mdp);
|
||||
v4l2_device_unregister(&mdp->v4l2_dev);
|
||||
|
||||
flush_workqueue(mdp->job_wq);
|
||||
destroy_workqueue(mdp->job_wq);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
|
||||
mtk_mdp_comp_deinit(&pdev->dev, mdp->comp[i]);
|
||||
|
||||
dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
|
||||
static int mtk_mdp_pm_suspend(struct device *dev)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp = dev_get_drvdata(dev);
|
||||
|
||||
mtk_mdp_clock_off(mdp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mtk_mdp_pm_resume(struct device *dev)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp = dev_get_drvdata(dev);
|
||||
|
||||
mtk_mdp_clock_on(mdp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_PM_RUNTIME || CONFIG_PM_SLEEP */
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP
|
||||
static int mtk_mdp_suspend(struct device *dev)
|
||||
{
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
|
||||
return mtk_mdp_pm_suspend(dev);
|
||||
}
|
||||
|
||||
static int mtk_mdp_resume(struct device *dev)
|
||||
{
|
||||
if (pm_runtime_suspended(dev))
|
||||
return 0;
|
||||
|
||||
return mtk_mdp_pm_resume(dev);
|
||||
}
|
||||
#endif /* CONFIG_PM_SLEEP */
|
||||
|
||||
static const struct dev_pm_ops mtk_mdp_pm_ops = {
|
||||
SET_SYSTEM_SLEEP_PM_OPS(mtk_mdp_suspend, mtk_mdp_resume)
|
||||
SET_RUNTIME_PM_OPS(mtk_mdp_pm_suspend, mtk_mdp_pm_resume, NULL)
|
||||
};
|
||||
|
||||
static struct platform_driver mtk_mdp_driver = {
|
||||
.probe = mtk_mdp_probe,
|
||||
.remove = mtk_mdp_remove,
|
||||
.driver = {
|
||||
.name = MTK_MDP_MODULE_NAME,
|
||||
.owner = THIS_MODULE,
|
||||
.pm = &mtk_mdp_pm_ops,
|
||||
.of_match_table = mtk_mdp_of_ids,
|
||||
}
|
||||
};
|
||||
|
||||
module_platform_driver(mtk_mdp_driver);
|
||||
|
||||
MODULE_AUTHOR("Houlong Wei <houlong.wei@mediatek.com>");
|
||||
MODULE_DESCRIPTION("Mediatek image processor driver");
|
||||
MODULE_LICENSE("GPL v2");
|
260
drivers/media/platform/mtk-mdp/mtk_mdp_core.h
Normal file
260
drivers/media/platform/mtk-mdp/mtk_mdp_core.h
Normal file
@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_CORE_H__
|
||||
#define __MTK_MDP_CORE_H__
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
#include <media/v4l2-ctrls.h>
|
||||
#include <media/v4l2-device.h>
|
||||
#include <media/v4l2-mem2mem.h>
|
||||
#include <media/videobuf2-core.h>
|
||||
#include <media/videobuf2-dma-contig.h>
|
||||
|
||||
#include "mtk_mdp_vpu.h"
|
||||
#include "mtk_mdp_comp.h"
|
||||
|
||||
|
||||
#define MTK_MDP_MODULE_NAME "mtk-mdp"
|
||||
|
||||
#define MTK_MDP_SHUTDOWN_TIMEOUT ((100*HZ)/1000) /* 100ms */
|
||||
#define MTK_MDP_MAX_CTRL_NUM 10
|
||||
|
||||
#define MTK_MDP_FMT_FLAG_OUTPUT BIT(0)
|
||||
#define MTK_MDP_FMT_FLAG_CAPTURE BIT(1)
|
||||
|
||||
#define MTK_MDP_VPU_INIT BIT(0)
|
||||
#define MTK_MDP_SRC_FMT BIT(1)
|
||||
#define MTK_MDP_DST_FMT BIT(2)
|
||||
#define MTK_MDP_CTX_ERROR BIT(5)
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_pix_align - alignement of image
|
||||
* @org_w: source alignment of width
|
||||
* @org_h: source alignment of height
|
||||
* @target_w: dst alignment of width
|
||||
* @target_h: dst alignment of height
|
||||
*/
|
||||
struct mtk_mdp_pix_align {
|
||||
u16 org_w;
|
||||
u16 org_h;
|
||||
u16 target_w;
|
||||
u16 target_h;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_fmt - the driver's internal color format data
|
||||
* @pixelformat: the fourcc code for this format, 0 if not applicable
|
||||
* @num_planes: number of physically non-contiguous data planes
|
||||
* @num_comp: number of logical data planes
|
||||
* @depth: per plane driver's private 'number of bits per pixel'
|
||||
* @row_depth: per plane driver's private 'number of bits per pixel per row'
|
||||
* @flags: flags indicating which operation mode format applies to
|
||||
MTK_MDP_FMT_FLAG_OUTPUT is used in OUTPUT stream
|
||||
MTK_MDP_FMT_FLAG_CAPTURE is used in CAPTURE stream
|
||||
* @align: pointer to a pixel alignment struct, NULL if using default value
|
||||
*/
|
||||
struct mtk_mdp_fmt {
|
||||
u32 pixelformat;
|
||||
u16 num_planes;
|
||||
u16 num_comp;
|
||||
u8 depth[VIDEO_MAX_PLANES];
|
||||
u8 row_depth[VIDEO_MAX_PLANES];
|
||||
u32 flags;
|
||||
struct mtk_mdp_pix_align *align;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_addr - the image processor physical address set
|
||||
* @addr: address of planes
|
||||
*/
|
||||
struct mtk_mdp_addr {
|
||||
dma_addr_t addr[MTK_MDP_MAX_NUM_PLANE];
|
||||
};
|
||||
|
||||
/* struct mtk_mdp_ctrls - the image processor control set
|
||||
* @rotate: rotation degree
|
||||
* @hflip: horizontal flip
|
||||
* @vflip: vertical flip
|
||||
* @global_alpha: the alpha value of current frame
|
||||
*/
|
||||
struct mtk_mdp_ctrls {
|
||||
struct v4l2_ctrl *rotate;
|
||||
struct v4l2_ctrl *hflip;
|
||||
struct v4l2_ctrl *vflip;
|
||||
struct v4l2_ctrl *global_alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_frame - source/target frame properties
|
||||
* @width: SRC : SRCIMG_WIDTH, DST : OUTPUTDMA_WHOLE_IMG_WIDTH
|
||||
* @height: SRC : SRCIMG_HEIGHT, DST : OUTPUTDMA_WHOLE_IMG_HEIGHT
|
||||
* @crop: cropped(source)/scaled(destination) size
|
||||
* @payload: image size in bytes (w x h x bpp)
|
||||
* @pitch: bytes per line of image in memory
|
||||
* @addr: image frame buffer physical addresses
|
||||
* @fmt: color format pointer
|
||||
* @alpha: frame's alpha value
|
||||
*/
|
||||
struct mtk_mdp_frame {
|
||||
u32 width;
|
||||
u32 height;
|
||||
struct v4l2_rect crop;
|
||||
unsigned long payload[VIDEO_MAX_PLANES];
|
||||
unsigned int pitch[VIDEO_MAX_PLANES];
|
||||
struct mtk_mdp_addr addr;
|
||||
const struct mtk_mdp_fmt *fmt;
|
||||
u8 alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_variant - image processor variant information
|
||||
* @pix_max: maximum limit of image size
|
||||
* @pix_min: minimun limit of image size
|
||||
* @pix_align: alignement of image
|
||||
* @h_scale_up_max: maximum scale-up in horizontal
|
||||
* @v_scale_up_max: maximum scale-up in vertical
|
||||
* @h_scale_down_max: maximum scale-down in horizontal
|
||||
* @v_scale_down_max: maximum scale-down in vertical
|
||||
*/
|
||||
struct mtk_mdp_variant {
|
||||
struct mtk_mdp_pix_limit *pix_max;
|
||||
struct mtk_mdp_pix_limit *pix_min;
|
||||
struct mtk_mdp_pix_align *pix_align;
|
||||
u16 h_scale_up_max;
|
||||
u16 v_scale_up_max;
|
||||
u16 h_scale_down_max;
|
||||
u16 v_scale_down_max;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_dev - abstraction for image processor entity
|
||||
* @lock: the mutex protecting this data structure
|
||||
* @vpulock: the mutex protecting the communication with VPU
|
||||
* @pdev: pointer to the image processor platform device
|
||||
* @variant: the IP variant information
|
||||
* @id: image processor device index (0..MTK_MDP_MAX_DEVS)
|
||||
* @comp: MDP function components
|
||||
* @m2m_dev: v4l2 memory-to-memory device data
|
||||
* @ctx_list: list of struct mtk_mdp_ctx
|
||||
* @vdev: video device for image processor driver
|
||||
* @v4l2_dev: V4L2 device to register video devices for.
|
||||
* @job_wq: processor work queue
|
||||
* @vpu_dev: VPU platform device
|
||||
* @ctx_num: counter of active MTK MDP context
|
||||
* @id_counter: An integer id given to the next opened context
|
||||
* @wdt_wq: work queue for VPU watchdog
|
||||
* @wdt_work: worker for VPU watchdog
|
||||
*/
|
||||
struct mtk_mdp_dev {
|
||||
struct mutex lock;
|
||||
struct mutex vpulock;
|
||||
struct platform_device *pdev;
|
||||
struct mtk_mdp_variant *variant;
|
||||
u16 id;
|
||||
struct mtk_mdp_comp *comp[MTK_MDP_COMP_ID_MAX];
|
||||
struct v4l2_m2m_dev *m2m_dev;
|
||||
struct list_head ctx_list;
|
||||
struct video_device vdev;
|
||||
struct v4l2_device v4l2_dev;
|
||||
struct workqueue_struct *job_wq;
|
||||
struct platform_device *vpu_dev;
|
||||
int ctx_num;
|
||||
unsigned long id_counter;
|
||||
struct workqueue_struct *wdt_wq;
|
||||
struct work_struct wdt_work;
|
||||
};
|
||||
|
||||
/**
|
||||
* mtk_mdp_ctx - the device context data
|
||||
* @list: link to ctx_list of mtk_mdp_dev
|
||||
* @s_frame: source frame properties
|
||||
* @d_frame: destination frame properties
|
||||
* @id: index of the context that this structure describes
|
||||
* @flags: additional flags for image conversion
|
||||
* @state: flags to keep track of user configuration
|
||||
Protected by slock
|
||||
* @rotation: rotates the image by specified angle
|
||||
* @hflip: mirror the picture horizontally
|
||||
* @vflip: mirror the picture vertically
|
||||
* @mdp_dev: the image processor device this context applies to
|
||||
* @m2m_ctx: memory-to-memory device context
|
||||
* @fh: v4l2 file handle
|
||||
* @ctrl_handler: v4l2 controls handler
|
||||
* @ctrls image processor control set
|
||||
* @ctrls_rdy: true if the control handler is initialized
|
||||
* @colorspace: enum v4l2_colorspace; supplemental to pixelformat
|
||||
* @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
|
||||
* @xfer_func: enum v4l2_xfer_func, colorspace transfer function
|
||||
* @quant: enum v4l2_quantization, colorspace quantization
|
||||
* @vpu: VPU instance
|
||||
* @slock: the mutex protecting mtp_mdp_ctx.state
|
||||
* @work: worker for image processing
|
||||
*/
|
||||
struct mtk_mdp_ctx {
|
||||
struct list_head list;
|
||||
struct mtk_mdp_frame s_frame;
|
||||
struct mtk_mdp_frame d_frame;
|
||||
u32 flags;
|
||||
u32 state;
|
||||
int id;
|
||||
int rotation;
|
||||
u32 hflip:1;
|
||||
u32 vflip:1;
|
||||
struct mtk_mdp_dev *mdp_dev;
|
||||
struct v4l2_m2m_ctx *m2m_ctx;
|
||||
struct v4l2_fh fh;
|
||||
struct v4l2_ctrl_handler ctrl_handler;
|
||||
struct mtk_mdp_ctrls ctrls;
|
||||
bool ctrls_rdy;
|
||||
enum v4l2_colorspace colorspace;
|
||||
enum v4l2_ycbcr_encoding ycbcr_enc;
|
||||
enum v4l2_xfer_func xfer_func;
|
||||
enum v4l2_quantization quant;
|
||||
|
||||
struct mtk_mdp_vpu vpu;
|
||||
struct mutex slock;
|
||||
struct work_struct work;
|
||||
};
|
||||
|
||||
extern int mtk_mdp_dbg_level;
|
||||
|
||||
#if defined(DEBUG)
|
||||
|
||||
#define mtk_mdp_dbg(level, fmt, args...) \
|
||||
do { \
|
||||
if (mtk_mdp_dbg_level >= level) \
|
||||
pr_info("[MTK_MDP] level=%d %s(),%d: " fmt "\n", \
|
||||
level, __func__, __LINE__, ##args); \
|
||||
} while (0)
|
||||
|
||||
#define mtk_mdp_err(fmt, args...) \
|
||||
pr_err("[MTK_MDP][ERROR] %s:%d: " fmt "\n", __func__, __LINE__, \
|
||||
##args)
|
||||
|
||||
|
||||
#define mtk_mdp_dbg_enter() mtk_mdp_dbg(3, "+")
|
||||
#define mtk_mdp_dbg_leave() mtk_mdp_dbg(3, "-")
|
||||
|
||||
#else
|
||||
|
||||
#define mtk_mdp_dbg(level, fmt, args...)
|
||||
#define mtk_mdp_err(fmt, args...)
|
||||
#define mtk_mdp_dbg_enter()
|
||||
#define mtk_mdp_dbg_leave()
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* __MTK_MDP_CORE_H__ */
|
126
drivers/media/platform/mtk-mdp/mtk_mdp_ipi.h
Normal file
126
drivers/media/platform/mtk-mdp/mtk_mdp_ipi.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_IPI_H__
|
||||
#define __MTK_MDP_IPI_H__
|
||||
|
||||
#define MTK_MDP_MAX_NUM_PLANE 3
|
||||
|
||||
enum mdp_ipi_msgid {
|
||||
AP_MDP_INIT = 0xd000,
|
||||
AP_MDP_DEINIT = 0xd001,
|
||||
AP_MDP_PROCESS = 0xd002,
|
||||
|
||||
VPU_MDP_INIT_ACK = 0xe000,
|
||||
VPU_MDP_DEINIT_ACK = 0xe001,
|
||||
VPU_MDP_PROCESS_ACK = 0xe002
|
||||
};
|
||||
|
||||
#pragma pack(push, 4)
|
||||
|
||||
/**
|
||||
* struct mdp_ipi_init - for AP_MDP_INIT
|
||||
* @msg_id : AP_MDP_INIT
|
||||
* @ipi_id : IPI_MDP
|
||||
* @ap_inst : AP mtk_mdp_vpu address
|
||||
*/
|
||||
struct mdp_ipi_init {
|
||||
uint32_t msg_id;
|
||||
uint32_t ipi_id;
|
||||
uint64_t ap_inst;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mdp_ipi_comm - for AP_MDP_PROCESS, AP_MDP_DEINIT
|
||||
* @msg_id : AP_MDP_PROCESS, AP_MDP_DEINIT
|
||||
* @ipi_id : IPI_MDP
|
||||
* @ap_inst : AP mtk_mdp_vpu address
|
||||
* @vpu_inst_addr : VPU MDP instance address
|
||||
*/
|
||||
struct mdp_ipi_comm {
|
||||
uint32_t msg_id;
|
||||
uint32_t ipi_id;
|
||||
uint64_t ap_inst;
|
||||
uint32_t vpu_inst_addr;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mdp_ipi_comm_ack - for VPU_MDP_DEINIT_ACK, VPU_MDP_PROCESS_ACK
|
||||
* @msg_id : VPU_MDP_DEINIT_ACK, VPU_MDP_PROCESS_ACK
|
||||
* @ipi_id : IPI_MDP
|
||||
* @ap_inst : AP mtk_mdp_vpu address
|
||||
* @vpu_inst_addr : VPU MDP instance address
|
||||
* @status : VPU exeuction result
|
||||
*/
|
||||
struct mdp_ipi_comm_ack {
|
||||
uint32_t msg_id;
|
||||
uint32_t ipi_id;
|
||||
uint64_t ap_inst;
|
||||
uint32_t vpu_inst_addr;
|
||||
int32_t status;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mdp_config - configured for source/destination image
|
||||
* @x : left
|
||||
* @y : top
|
||||
* @w : width
|
||||
* @h : height
|
||||
* @w_stride : bytes in horizontal
|
||||
* @h_stride : bytes in vertical
|
||||
* @crop_x : cropped left
|
||||
* @crop_y : cropped top
|
||||
* @crop_w : cropped width
|
||||
* @crop_h : cropped height
|
||||
* @format : color format
|
||||
*/
|
||||
struct mdp_config {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
int32_t w_stride;
|
||||
int32_t h_stride;
|
||||
int32_t crop_x;
|
||||
int32_t crop_y;
|
||||
int32_t crop_w;
|
||||
int32_t crop_h;
|
||||
int32_t format;
|
||||
};
|
||||
|
||||
struct mdp_buffer {
|
||||
uint64_t addr_mva[MTK_MDP_MAX_NUM_PLANE];
|
||||
int32_t plane_size[MTK_MDP_MAX_NUM_PLANE];
|
||||
int32_t plane_num;
|
||||
};
|
||||
|
||||
struct mdp_config_misc {
|
||||
int32_t orientation; /* 0, 90, 180, 270 */
|
||||
int32_t hflip; /* 1 will enable the flip */
|
||||
int32_t vflip; /* 1 will enable the flip */
|
||||
int32_t alpha; /* global alpha */
|
||||
};
|
||||
|
||||
struct mdp_process_vsi {
|
||||
struct mdp_config src_config;
|
||||
struct mdp_buffer src_buffer;
|
||||
struct mdp_config dst_config;
|
||||
struct mdp_buffer dst_buffer;
|
||||
struct mdp_config_misc misc;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif /* __MTK_MDP_IPI_H__ */
|
1270
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
Normal file
1270
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
Normal file
File diff suppressed because it is too large
Load Diff
22
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.h
Normal file
22
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MediaTek Inc.
|
||||
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_M2M_H__
|
||||
#define __MTK_MDP_M2M_H__
|
||||
|
||||
void mtk_mdp_ctx_state_lock_set(struct mtk_mdp_ctx *ctx, u32 state);
|
||||
int mtk_mdp_register_m2m_device(struct mtk_mdp_dev *mdp);
|
||||
void mtk_mdp_unregister_m2m_device(struct mtk_mdp_dev *mdp);
|
||||
|
||||
#endif /* __MTK_MDP_M2M_H__ */
|
152
drivers/media/platform/mtk-mdp/mtk_mdp_regs.c
Normal file
152
drivers/media/platform/mtk-mdp/mtk_mdp_regs.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include "mtk_mdp_core.h"
|
||||
#include "mtk_mdp_regs.h"
|
||||
|
||||
|
||||
#define MDP_COLORFMT_PACK(VIDEO, PLANE, COPLANE, HF, VF, BITS, GROUP, SWAP, ID)\
|
||||
(((VIDEO) << 27) | ((PLANE) << 24) | ((COPLANE) << 22) |\
|
||||
((HF) << 20) | ((VF) << 18) | ((BITS) << 8) | ((GROUP) << 6) |\
|
||||
((SWAP) << 5) | ((ID) << 0))
|
||||
|
||||
enum MDP_COLOR_ENUM {
|
||||
MDP_COLOR_UNKNOWN = 0,
|
||||
MDP_COLOR_NV12 = MDP_COLORFMT_PACK(0, 2, 1, 1, 1, 8, 1, 0, 12),
|
||||
MDP_COLOR_I420 = MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 0, 8),
|
||||
MDP_COLOR_YV12 = MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 1, 8),
|
||||
};
|
||||
|
||||
static int32_t mtk_mdp_map_color_format(int v4l2_format)
|
||||
{
|
||||
switch (v4l2_format) {
|
||||
case V4L2_PIX_FMT_NV12M:
|
||||
case V4L2_PIX_FMT_NV12:
|
||||
return MDP_COLOR_NV12;
|
||||
case V4L2_PIX_FMT_YUV420M:
|
||||
case V4L2_PIX_FMT_YUV420:
|
||||
return MDP_COLOR_I420;
|
||||
case V4L2_PIX_FMT_YVU420:
|
||||
return MDP_COLOR_YV12;
|
||||
}
|
||||
|
||||
mtk_mdp_err("Unknown format 0x%x", v4l2_format);
|
||||
|
||||
return MDP_COLOR_UNKNOWN;
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_input_addr(struct mtk_mdp_ctx *ctx,
|
||||
struct mtk_mdp_addr *addr)
|
||||
{
|
||||
struct mdp_buffer *src_buf = &ctx->vpu.vsi->src_buffer;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(addr->addr); i++)
|
||||
src_buf->addr_mva[i] = (uint64_t)addr->addr[i];
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_output_addr(struct mtk_mdp_ctx *ctx,
|
||||
struct mtk_mdp_addr *addr)
|
||||
{
|
||||
struct mdp_buffer *dst_buf = &ctx->vpu.vsi->dst_buffer;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(addr->addr); i++)
|
||||
dst_buf->addr_mva[i] = (uint64_t)addr->addr[i];
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_in_size(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
struct mtk_mdp_frame *frame = &ctx->s_frame;
|
||||
struct mdp_config *config = &ctx->vpu.vsi->src_config;
|
||||
|
||||
/* Set input pixel offset */
|
||||
config->crop_x = frame->crop.left;
|
||||
config->crop_y = frame->crop.top;
|
||||
|
||||
/* Set input cropped size */
|
||||
config->crop_w = frame->crop.width;
|
||||
config->crop_h = frame->crop.height;
|
||||
|
||||
/* Set input original size */
|
||||
config->x = 0;
|
||||
config->y = 0;
|
||||
config->w = frame->width;
|
||||
config->h = frame->height;
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_in_image_format(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
unsigned int i;
|
||||
struct mtk_mdp_frame *frame = &ctx->s_frame;
|
||||
struct mdp_config *config = &ctx->vpu.vsi->src_config;
|
||||
struct mdp_buffer *src_buf = &ctx->vpu.vsi->src_buffer;
|
||||
|
||||
src_buf->plane_num = frame->fmt->num_comp;
|
||||
config->format = mtk_mdp_map_color_format(frame->fmt->pixelformat);
|
||||
config->w_stride = 0; /* MDP will calculate it by color format. */
|
||||
config->h_stride = 0; /* MDP will calculate it by color format. */
|
||||
|
||||
for (i = 0; i < src_buf->plane_num; i++)
|
||||
src_buf->plane_size[i] = frame->payload[i];
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_out_size(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
struct mtk_mdp_frame *frame = &ctx->d_frame;
|
||||
struct mdp_config *config = &ctx->vpu.vsi->dst_config;
|
||||
|
||||
config->crop_x = frame->crop.left;
|
||||
config->crop_y = frame->crop.top;
|
||||
config->crop_w = frame->crop.width;
|
||||
config->crop_h = frame->crop.height;
|
||||
config->x = 0;
|
||||
config->y = 0;
|
||||
config->w = frame->width;
|
||||
config->h = frame->height;
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_out_image_format(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
unsigned int i;
|
||||
struct mtk_mdp_frame *frame = &ctx->d_frame;
|
||||
struct mdp_config *config = &ctx->vpu.vsi->dst_config;
|
||||
struct mdp_buffer *dst_buf = &ctx->vpu.vsi->dst_buffer;
|
||||
|
||||
dst_buf->plane_num = frame->fmt->num_comp;
|
||||
config->format = mtk_mdp_map_color_format(frame->fmt->pixelformat);
|
||||
config->w_stride = 0; /* MDP will calculate it by color format. */
|
||||
config->h_stride = 0; /* MDP will calculate it by color format. */
|
||||
for (i = 0; i < dst_buf->plane_num; i++)
|
||||
dst_buf->plane_size[i] = frame->payload[i];
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_rotation(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
struct mdp_config_misc *misc = &ctx->vpu.vsi->misc;
|
||||
|
||||
misc->orientation = ctx->ctrls.rotate->val;
|
||||
misc->hflip = ctx->ctrls.hflip->val;
|
||||
misc->vflip = ctx->ctrls.vflip->val;
|
||||
}
|
||||
|
||||
void mtk_mdp_hw_set_global_alpha(struct mtk_mdp_ctx *ctx)
|
||||
{
|
||||
struct mdp_config_misc *misc = &ctx->vpu.vsi->misc;
|
||||
|
||||
misc->alpha = ctx->ctrls.global_alpha->val;
|
||||
}
|
31
drivers/media/platform/mtk-mdp/mtk_mdp_regs.h
Normal file
31
drivers/media/platform/mtk-mdp/mtk_mdp_regs.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MediaTek Inc.
|
||||
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_REGS_H__
|
||||
#define __MTK_MDP_REGS_H__
|
||||
|
||||
|
||||
void mtk_mdp_hw_set_input_addr(struct mtk_mdp_ctx *ctx,
|
||||
struct mtk_mdp_addr *addr);
|
||||
void mtk_mdp_hw_set_output_addr(struct mtk_mdp_ctx *ctx,
|
||||
struct mtk_mdp_addr *addr);
|
||||
void mtk_mdp_hw_set_in_size(struct mtk_mdp_ctx *ctx);
|
||||
void mtk_mdp_hw_set_in_image_format(struct mtk_mdp_ctx *ctx);
|
||||
void mtk_mdp_hw_set_out_size(struct mtk_mdp_ctx *ctx);
|
||||
void mtk_mdp_hw_set_out_image_format(struct mtk_mdp_ctx *ctx);
|
||||
void mtk_mdp_hw_set_rotation(struct mtk_mdp_ctx *ctx);
|
||||
void mtk_mdp_hw_set_global_alpha(struct mtk_mdp_ctx *ctx);
|
||||
|
||||
|
||||
#endif /* __MTK_MDP_REGS_H__ */
|
145
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c
Normal file
145
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "mtk_mdp_core.h"
|
||||
#include "mtk_mdp_vpu.h"
|
||||
#include "mtk_vpu.h"
|
||||
|
||||
|
||||
static inline struct mtk_mdp_ctx *vpu_to_ctx(struct mtk_mdp_vpu *vpu)
|
||||
{
|
||||
return container_of(vpu, struct mtk_mdp_ctx, vpu);
|
||||
}
|
||||
|
||||
static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack *msg)
|
||||
{
|
||||
struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
|
||||
|
||||
/* mapping VPU address to kernel virtual address */
|
||||
vpu->vsi = (struct mdp_process_vsi *)
|
||||
vpu_mapping_dm_addr(vpu->pdev, msg->vpu_inst_addr);
|
||||
vpu->inst_addr = msg->vpu_inst_addr;
|
||||
}
|
||||
|
||||
static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len, void *priv)
|
||||
{
|
||||
unsigned int msg_id = *(unsigned int *)data;
|
||||
struct mdp_ipi_comm_ack *msg = (struct mdp_ipi_comm_ack *)data;
|
||||
struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
|
||||
struct mtk_mdp_ctx *ctx;
|
||||
|
||||
vpu->failure = msg->status;
|
||||
if (!vpu->failure) {
|
||||
switch (msg_id) {
|
||||
case VPU_MDP_INIT_ACK:
|
||||
mtk_mdp_vpu_handle_init_ack(data);
|
||||
break;
|
||||
case VPU_MDP_DEINIT_ACK:
|
||||
case VPU_MDP_PROCESS_ACK:
|
||||
break;
|
||||
default:
|
||||
ctx = vpu_to_ctx(vpu);
|
||||
dev_err(&ctx->mdp_dev->pdev->dev,
|
||||
"handle unknown ipi msg:0x%x\n",
|
||||
msg_id);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ctx = vpu_to_ctx(vpu);
|
||||
mtk_mdp_dbg(0, "[%d]:msg 0x%x, failure:%d", ctx->id,
|
||||
msg_id, vpu->failure);
|
||||
}
|
||||
}
|
||||
|
||||
int mtk_mdp_vpu_register(struct platform_device *pdev)
|
||||
{
|
||||
struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
|
||||
int err;
|
||||
|
||||
err = vpu_ipi_register(mdp->vpu_dev, IPI_MDP,
|
||||
mtk_mdp_vpu_ipi_handler, "mdp_vpu", NULL);
|
||||
if (err)
|
||||
dev_err(&mdp->pdev->dev,
|
||||
"vpu_ipi_registration fail status=%d\n", err);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu,
|
||||
int id)
|
||||
{
|
||||
struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
|
||||
int err;
|
||||
|
||||
if (!vpu->pdev) {
|
||||
mtk_mdp_dbg(1, "[%d]:vpu pdev is NULL", ctx->id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mutex_lock(&ctx->mdp_dev->vpulock);
|
||||
err = vpu_ipi_send(vpu->pdev, (enum ipi_id)id, msg, len);
|
||||
if (err) {
|
||||
mutex_unlock(&ctx->mdp_dev->vpulock);
|
||||
dev_err(&ctx->mdp_dev->pdev->dev,
|
||||
"vpu_ipi_send fail status %d\n", err);
|
||||
}
|
||||
mutex_unlock(&ctx->mdp_dev->vpulock);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu *vpu, uint32_t msg_id)
|
||||
{
|
||||
int err;
|
||||
struct mdp_ipi_comm msg;
|
||||
|
||||
msg.msg_id = msg_id;
|
||||
msg.ipi_id = IPI_MDP;
|
||||
msg.vpu_inst_addr = vpu->inst_addr;
|
||||
msg.ap_inst = (uint64_t)vpu;
|
||||
err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
|
||||
if (!err && vpu->failure)
|
||||
err = -EINVAL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu)
|
||||
{
|
||||
int err;
|
||||
struct mdp_ipi_init msg;
|
||||
struct mtk_mdp_ctx *ctx = vpu_to_ctx(vpu);
|
||||
|
||||
vpu->pdev = ctx->mdp_dev->vpu_dev;
|
||||
|
||||
msg.msg_id = AP_MDP_INIT;
|
||||
msg.ipi_id = IPI_MDP;
|
||||
msg.ap_inst = (uint64_t)vpu;
|
||||
err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
|
||||
if (!err && vpu->failure)
|
||||
err = -EINVAL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mtk_mdp_vpu_deinit(struct mtk_mdp_vpu *vpu)
|
||||
{
|
||||
return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_DEINIT);
|
||||
}
|
||||
|
||||
int mtk_mdp_vpu_process(struct mtk_mdp_vpu *vpu)
|
||||
{
|
||||
return mtk_mdp_vpu_send_ap_ipi(vpu, AP_MDP_PROCESS);
|
||||
}
|
41
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.h
Normal file
41
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016 MediaTek Inc.
|
||||
* Author: Houlong Wei <houlong.wei@mediatek.com>
|
||||
* Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __MTK_MDP_VPU_H__
|
||||
#define __MTK_MDP_VPU_H__
|
||||
|
||||
#include "mtk_mdp_ipi.h"
|
||||
|
||||
|
||||
/**
|
||||
* struct mtk_mdp_vpu - VPU instance for MDP
|
||||
* @pdev : pointer to the VPU platform device
|
||||
* @inst_addr : VPU MDP instance address
|
||||
* @failure : VPU execution result status
|
||||
* @vsi : VPU shared information
|
||||
*/
|
||||
struct mtk_mdp_vpu {
|
||||
struct platform_device *pdev;
|
||||
uint32_t inst_addr;
|
||||
int32_t failure;
|
||||
struct mdp_process_vsi *vsi;
|
||||
};
|
||||
|
||||
int mtk_mdp_vpu_register(struct platform_device *pdev);
|
||||
int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu);
|
||||
int mtk_mdp_vpu_deinit(struct mtk_mdp_vpu *vpu);
|
||||
int mtk_mdp_vpu_process(struct mtk_mdp_vpu *vpu);
|
||||
|
||||
#endif /* __MTK_MDP_VPU_H__ */
|
Loading…
Reference in New Issue
Block a user