forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
....@@ -1,15 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2016 MediaTek Inc.
34 * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
146
157 #include <linux/clk.h>
....@@ -22,46 +14,6 @@
2214 #include "mtk_mdp_comp.h"
2315
2416
25
-static const char * const mtk_mdp_comp_stem[MTK_MDP_COMP_TYPE_MAX] = {
26
- "mdp_rdma",
27
- "mdp_rsz",
28
- "mdp_wdma",
29
- "mdp_wrot",
30
-};
31
-
32
-struct mtk_mdp_comp_match {
33
- enum mtk_mdp_comp_type type;
34
- int alias_id;
35
-};
36
-
37
-static const struct mtk_mdp_comp_match mtk_mdp_matches[MTK_MDP_COMP_ID_MAX] = {
38
- { MTK_MDP_RDMA, 0 },
39
- { MTK_MDP_RDMA, 1 },
40
- { MTK_MDP_RSZ, 0 },
41
- { MTK_MDP_RSZ, 1 },
42
- { MTK_MDP_RSZ, 2 },
43
- { MTK_MDP_WDMA, 0 },
44
- { MTK_MDP_WROT, 0 },
45
- { MTK_MDP_WROT, 1 },
46
-};
47
-
48
-int mtk_mdp_comp_get_id(struct device *dev, struct device_node *node,
49
- enum mtk_mdp_comp_type comp_type)
50
-{
51
- int id = of_alias_get_id(node, mtk_mdp_comp_stem[comp_type]);
52
- int i;
53
-
54
- for (i = 0; i < ARRAY_SIZE(mtk_mdp_matches); i++) {
55
- if (comp_type == mtk_mdp_matches[i].type &&
56
- id == mtk_mdp_matches[i].alias_id)
57
- return i;
58
- }
59
-
60
- dev_err(dev, "Failed to get id. type: %d, id: %d\n", comp_type, id);
61
-
62
- return -EINVAL;
63
-}
64
-
6517 void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp)
6618 {
6719 int i, err;
....@@ -70,8 +22,8 @@
7022 err = mtk_smi_larb_get(comp->larb_dev);
7123 if (err)
7224 dev_err(dev,
73
- "failed to get larb, err %d. type:%d id:%d\n",
74
- err, comp->type, comp->id);
25
+ "failed to get larb, err %d. type:%d\n",
26
+ err, comp->type);
7527 }
7628
7729 for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
....@@ -80,8 +32,8 @@
8032 err = clk_prepare_enable(comp->clk[i]);
8133 if (err)
8234 dev_err(dev,
83
- "failed to enable clock, err %d. type:%d id:%d i:%d\n",
84
- err, comp->type, comp->id, i);
35
+ "failed to enable clock, err %d. type:%d i:%d\n",
36
+ err, comp->type, i);
8537 }
8638 }
8739
....@@ -100,24 +52,25 @@
10052 }
10153
10254 int mtk_mdp_comp_init(struct device *dev, struct device_node *node,
103
- struct mtk_mdp_comp *comp, enum mtk_mdp_comp_id comp_id)
55
+ struct mtk_mdp_comp *comp,
56
+ enum mtk_mdp_comp_type comp_type)
10457 {
10558 struct device_node *larb_node;
10659 struct platform_device *larb_pdev;
60
+ int ret;
10761 int i;
10862
109
- if (comp_id < 0 || comp_id >= MTK_MDP_COMP_ID_MAX) {
110
- dev_err(dev, "Invalid comp_id %d\n", comp_id);
111
- return -EINVAL;
112
- }
113
-
11463 comp->dev_node = of_node_get(node);
115
- comp->id = comp_id;
116
- comp->type = mtk_mdp_matches[comp_id].type;
117
- comp->regs = of_iomap(node, 0);
64
+ comp->type = comp_type;
11865
11966 for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
12067 comp->clk[i] = of_clk_get(node, i);
68
+ if (IS_ERR(comp->clk[i])) {
69
+ if (PTR_ERR(comp->clk[i]) != -EPROBE_DEFER)
70
+ dev_err(dev, "Failed to get clock\n");
71
+ ret = PTR_ERR(comp->clk[i]);
72
+ goto put_dev;
73
+ }
12174
12275 /* Only RDMA needs two clocks */
12376 if (comp->type != MTK_MDP_RDMA)
....@@ -135,20 +88,27 @@
13588 if (!larb_node) {
13689 dev_err(dev,
13790 "Missing mediadek,larb phandle in %pOF node\n", node);
138
- return -EINVAL;
91
+ ret = -EINVAL;
92
+ goto put_dev;
13993 }
14094
14195 larb_pdev = of_find_device_by_node(larb_node);
14296 if (!larb_pdev) {
14397 dev_warn(dev, "Waiting for larb device %pOF\n", larb_node);
14498 of_node_put(larb_node);
145
- return -EPROBE_DEFER;
99
+ ret = -EPROBE_DEFER;
100
+ goto put_dev;
146101 }
147102 of_node_put(larb_node);
148103
149104 comp->larb_dev = &larb_pdev->dev;
150105
151106 return 0;
107
+
108
+put_dev:
109
+ of_node_put(comp->dev_node);
110
+
111
+ return ret;
152112 }
153113
154114 void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp)