Commit c4320f97 authored by Moudy Ho's avatar Moudy Ho Committed by Hans Verkuil

media: platform: mtk-mdp3: dynamically allocate component clocks

For extensibility of adding more MDP3 components in the further, the
magic number is removed by dynamically allocating component clocks.
Signed-off-by: default avatarMoudy Ho <moudy.ho@mediatek.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent a5b400ea
...@@ -641,7 +641,8 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp) ...@@ -641,7 +641,8 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
{ {
int i, ret; int i, ret;
if (comp->comp_dev) { /* Only DMA capable components need the pm control */
if (comp->comp_dev && is_dma_capable(comp->type)) {
ret = pm_runtime_resume_and_get(comp->comp_dev); ret = pm_runtime_resume_and_get(comp->comp_dev);
if (ret < 0) { if (ret < 0) {
dev_err(dev, dev_err(dev,
...@@ -651,7 +652,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp) ...@@ -651,7 +652,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
} }
} }
for (i = 0; i < ARRAY_SIZE(comp->clks); i++) { for (i = 0; i < comp->clk_num; i++) {
if (IS_ERR_OR_NULL(comp->clks[i])) if (IS_ERR_OR_NULL(comp->clks[i]))
continue; continue;
ret = clk_prepare_enable(comp->clks[i]); ret = clk_prepare_enable(comp->clks[i]);
...@@ -671,7 +672,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp) ...@@ -671,7 +672,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
continue; continue;
clk_disable_unprepare(comp->clks[i]); clk_disable_unprepare(comp->clks[i]);
} }
if (comp->comp_dev) if (comp->comp_dev && is_dma_capable(comp->type))
pm_runtime_put_sync(comp->comp_dev); pm_runtime_put_sync(comp->comp_dev);
return ret; return ret;
...@@ -681,13 +682,13 @@ void mdp_comp_clock_off(struct device *dev, struct mdp_comp *comp) ...@@ -681,13 +682,13 @@ void mdp_comp_clock_off(struct device *dev, struct mdp_comp *comp)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(comp->clks); i++) { for (i = 0; i < comp->clk_num; i++) {
if (IS_ERR_OR_NULL(comp->clks[i])) if (IS_ERR_OR_NULL(comp->clks[i]))
continue; continue;
clk_disable_unprepare(comp->clks[i]); clk_disable_unprepare(comp->clks[i]);
} }
if (comp->comp_dev) if (comp->comp_dev && is_dma_capable(comp->type))
pm_runtime_put(comp->comp_dev); pm_runtime_put(comp->comp_dev);
} }
...@@ -766,7 +767,7 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node, ...@@ -766,7 +767,7 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
struct mdp_comp *comp, enum mtk_mdp_comp_id id) struct mdp_comp *comp, enum mtk_mdp_comp_id id)
{ {
struct device *dev = &mdp->pdev->dev; struct device *dev = &mdp->pdev->dev;
int clk_num; struct platform_device *pdev_c;
int clk_ofst; int clk_ofst;
int i; int i;
s32 event; s32 event;
...@@ -776,6 +777,14 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node, ...@@ -776,6 +777,14 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
return -EINVAL; return -EINVAL;
} }
pdev_c = of_find_device_by_node(node);
if (!pdev_c) {
dev_warn(dev, "can't find platform device of node:%s\n",
node->name);
return -ENODEV;
}
comp->comp_dev = &pdev_c->dev;
comp->public_id = id; comp->public_id = id;
comp->type = mdp->mdp_data->comp_data[id].match.type; comp->type = mdp->mdp_data->comp_data[id].match.type;
comp->inner_id = mdp->mdp_data->comp_data[id].match.inner_id; comp->inner_id = mdp->mdp_data->comp_data[id].match.inner_id;
...@@ -783,10 +792,15 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node, ...@@ -783,10 +792,15 @@ static int mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
comp->ops = mdp_comp_ops[comp->type]; comp->ops = mdp_comp_ops[comp->type];
__mdp_comp_init(mdp, node, comp); __mdp_comp_init(mdp, node, comp);
clk_num = mdp->mdp_data->comp_data[id].info.clk_num; comp->clk_num = mdp->mdp_data->comp_data[id].info.clk_num;
comp->clks = devm_kzalloc(dev, sizeof(struct clk *) * comp->clk_num,
GFP_KERNEL);
if (!comp->clks)
return -ENOMEM;
clk_ofst = mdp->mdp_data->comp_data[id].info.clk_ofst; clk_ofst = mdp->mdp_data->comp_data[id].info.clk_ofst;
for (i = 0; i < clk_num; i++) { for (i = 0; i < comp->clk_num; i++) {
comp->clks[i] = of_clk_get(node, i + clk_ofst); comp->clks[i] = of_clk_get(node, i + clk_ofst);
if (IS_ERR(comp->clks[i])) if (IS_ERR(comp->clks[i]))
break; break;
...@@ -823,6 +837,11 @@ static void mdp_comp_deinit(struct mdp_comp *comp) ...@@ -823,6 +837,11 @@ static void mdp_comp_deinit(struct mdp_comp *comp)
if (!comp) if (!comp)
return; return;
if (comp->comp_dev && comp->clks) {
devm_kfree(&comp->mdp_dev->pdev->dev, comp->clks);
comp->clks = NULL;
}
if (comp->regs) if (comp->regs)
iounmap(comp->regs); iounmap(comp->regs);
} }
...@@ -904,6 +923,7 @@ void mdp_comp_destroy(struct mdp_dev *mdp) ...@@ -904,6 +923,7 @@ void mdp_comp_destroy(struct mdp_dev *mdp)
for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) { for (i = 0; i < ARRAY_SIZE(mdp->comp); i++) {
if (mdp->comp[i]) { if (mdp->comp[i]) {
if (is_dma_capable(mdp->comp[i]->type))
pm_runtime_disable(mdp->comp[i]->comp_dev); pm_runtime_disable(mdp->comp[i]->comp_dev);
mdp_comp_deinit(mdp->comp[i]); mdp_comp_deinit(mdp->comp[i]);
devm_kfree(mdp->comp[i]->comp_dev, mdp->comp[i]); devm_kfree(mdp->comp[i]->comp_dev, mdp->comp[i]);
...@@ -916,7 +936,6 @@ int mdp_comp_config(struct mdp_dev *mdp) ...@@ -916,7 +936,6 @@ int mdp_comp_config(struct mdp_dev *mdp)
{ {
struct device *dev = &mdp->pdev->dev; struct device *dev = &mdp->pdev->dev;
struct device_node *node, *parent; struct device_node *node, *parent;
struct platform_device *pdev;
int ret; int ret;
memset(mdp_comp_alias_id, 0, sizeof(mdp_comp_alias_id)); memset(mdp_comp_alias_id, 0, sizeof(mdp_comp_alias_id));
...@@ -957,19 +976,8 @@ int mdp_comp_config(struct mdp_dev *mdp) ...@@ -957,19 +976,8 @@ int mdp_comp_config(struct mdp_dev *mdp)
} }
/* Only DMA capable components need the pm control */ /* Only DMA capable components need the pm control */
comp->comp_dev = NULL;
if (!is_dma_capable(comp->type)) if (!is_dma_capable(comp->type))
continue; continue;
pdev = of_find_device_by_node(node);
if (!pdev) {
dev_warn(dev, "can't find platform device of node:%s\n",
node->name);
ret = -ENODEV;
goto err_init_comps;
}
comp->comp_dev = &pdev->dev;
pm_runtime_enable(comp->comp_dev); pm_runtime_enable(comp->comp_dev);
} }
......
...@@ -159,7 +159,8 @@ struct mdp_comp { ...@@ -159,7 +159,8 @@ struct mdp_comp {
void __iomem *regs; void __iomem *regs;
phys_addr_t reg_base; phys_addr_t reg_base;
u8 subsys_id; u8 subsys_id;
struct clk *clks[6]; u8 clk_num;
struct clk **clks;
struct device *comp_dev; struct device *comp_dev;
enum mdp_comp_type type; enum mdp_comp_type type;
enum mtk_mdp_comp_id public_id; enum mtk_mdp_comp_id public_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment