forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015-2016 MediaTek Inc.
34 * Author: Houlong Wei <houlong.wei@mediatek.com>
45 * Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
168 #include <linux/clk.h>
....@@ -63,19 +55,19 @@
6355 static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
6456 {
6557 struct device *dev = &mdp->pdev->dev;
66
- int i;
58
+ struct mtk_mdp_comp *comp_node;
6759
68
- for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
69
- mtk_mdp_comp_clock_on(dev, mdp->comp[i]);
60
+ list_for_each_entry(comp_node, &mdp->comp_list, node)
61
+ mtk_mdp_comp_clock_on(dev, comp_node);
7062 }
7163
7264 static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
7365 {
7466 struct device *dev = &mdp->pdev->dev;
75
- int i;
67
+ struct mtk_mdp_comp *comp_node;
7668
77
- for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
78
- mtk_mdp_comp_clock_off(dev, mdp->comp[i]);
69
+ list_for_each_entry(comp_node, &mdp->comp_list, node)
70
+ mtk_mdp_comp_clock_off(dev, comp_node);
7971 }
8072
8173 static void mtk_mdp_wdt_worker(struct work_struct *work)
....@@ -99,12 +91,25 @@
9991 queue_work(mdp->wdt_wq, &mdp->wdt_work);
10092 }
10193
94
+void mtk_mdp_register_component(struct mtk_mdp_dev *mdp,
95
+ struct mtk_mdp_comp *comp)
96
+{
97
+ list_add(&comp->node, &mdp->comp_list);
98
+}
99
+
100
+void mtk_mdp_unregister_component(struct mtk_mdp_dev *mdp,
101
+ struct mtk_mdp_comp *comp)
102
+{
103
+ list_del(&comp->node);
104
+}
105
+
102106 static int mtk_mdp_probe(struct platform_device *pdev)
103107 {
104108 struct mtk_mdp_dev *mdp;
105109 struct device *dev = &pdev->dev;
106110 struct device_node *node, *parent;
107
- int i, ret = 0;
111
+ struct mtk_mdp_comp *comp, *comp_temp;
112
+ int ret = 0;
108113
109114 mdp = devm_kzalloc(dev, sizeof(*mdp), GFP_KERNEL);
110115 if (!mdp)
....@@ -112,6 +117,7 @@
112117
113118 mdp->id = pdev->id;
114119 mdp->pdev = pdev;
120
+ INIT_LIST_HEAD(&mdp->comp_list);
115121 INIT_LIST_HEAD(&mdp->ctx_list);
116122
117123 mutex_init(&mdp->lock);
....@@ -131,8 +137,6 @@
131137 for_each_child_of_node(parent, node) {
132138 const struct of_device_id *of_id;
133139 enum mtk_mdp_comp_type comp_type;
134
- int comp_id;
135
- struct mtk_mdp_comp *comp;
136140
137141 of_id = of_match_node(mtk_mdp_comp_dt_ids, node);
138142 if (!of_id)
....@@ -145,23 +149,21 @@
145149 }
146150
147151 comp_type = (enum mtk_mdp_comp_type)of_id->data;
148
- comp_id = mtk_mdp_comp_get_id(dev, node, comp_type);
149
- if (comp_id < 0) {
150
- dev_warn(dev, "Skipping unknown component %pOF\n",
151
- node);
152
- continue;
153
- }
154152
155153 comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
156154 if (!comp) {
157155 ret = -ENOMEM;
156
+ of_node_put(node);
158157 goto err_comp;
159158 }
160
- mdp->comp[comp_id] = comp;
161159
162
- ret = mtk_mdp_comp_init(dev, node, comp, comp_id);
163
- if (ret)
160
+ ret = mtk_mdp_comp_init(dev, node, comp, comp_type);
161
+ if (ret) {
162
+ of_node_put(node);
164163 goto err_comp;
164
+ }
165
+
166
+ mtk_mdp_register_component(mdp, comp);
165167 }
166168
167169 mdp->job_wq = create_singlethread_workqueue(MTK_MDP_MODULE_NAME);
....@@ -193,12 +195,20 @@
193195 }
194196
195197 mdp->vpu_dev = vpu_get_plat_device(pdev);
196
- vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
197
- VPU_RST_MDP);
198
+ ret = vpu_wdt_reg_handler(mdp->vpu_dev, mtk_mdp_reset_handler, mdp,
199
+ VPU_RST_MDP);
200
+ if (ret) {
201
+ dev_err(&pdev->dev, "Failed to register reset handler\n");
202
+ goto err_m2m_register;
203
+ }
198204
199205 platform_set_drvdata(pdev, mdp);
200206
201
- vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
207
+ ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
208
+ if (ret) {
209
+ dev_err(&pdev->dev, "Failed to set vb2 dma mag seg size\n");
210
+ goto err_m2m_register;
211
+ }
202212
203213 pm_runtime_enable(dev);
204214 dev_dbg(dev, "mdp-%d registered successfully\n", mdp->id);
....@@ -217,8 +227,10 @@
217227 err_alloc_job_wq:
218228
219229 err_comp:
220
- for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
221
- mtk_mdp_comp_deinit(dev, mdp->comp[i]);
230
+ list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) {
231
+ mtk_mdp_unregister_component(mdp, comp);
232
+ mtk_mdp_comp_deinit(dev, comp);
233
+ }
222234
223235 dev_dbg(dev, "err %d\n", ret);
224236 return ret;
....@@ -227,18 +239,23 @@
227239 static int mtk_mdp_remove(struct platform_device *pdev)
228240 {
229241 struct mtk_mdp_dev *mdp = platform_get_drvdata(pdev);
230
- int i;
242
+ struct mtk_mdp_comp *comp, *comp_temp;
231243
232244 pm_runtime_disable(&pdev->dev);
233245 vb2_dma_contig_clear_max_seg_size(&pdev->dev);
234246 mtk_mdp_unregister_m2m_device(mdp);
235247 v4l2_device_unregister(&mdp->v4l2_dev);
236248
249
+ flush_workqueue(mdp->wdt_wq);
250
+ destroy_workqueue(mdp->wdt_wq);
251
+
237252 flush_workqueue(mdp->job_wq);
238253 destroy_workqueue(mdp->job_wq);
239254
240
- for (i = 0; i < ARRAY_SIZE(mdp->comp); i++)
241
- mtk_mdp_comp_deinit(&pdev->dev, mdp->comp[i]);
255
+ list_for_each_entry_safe(comp, comp_temp, &mdp->comp_list, node) {
256
+ mtk_mdp_unregister_component(mdp, comp);
257
+ mtk_mdp_comp_deinit(&pdev->dev, comp);
258
+ }
242259
243260 dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
244261 return 0;