.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2016 MediaTek Inc. |
---|
3 | 4 | * 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. |
---|
13 | 5 | */ |
---|
14 | 6 | |
---|
15 | 7 | #include <linux/clk.h> |
---|
.. | .. |
---|
22 | 14 | #include "mtk_mdp_comp.h" |
---|
23 | 15 | |
---|
24 | 16 | |
---|
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 | | - |
---|
65 | 17 | void mtk_mdp_comp_clock_on(struct device *dev, struct mtk_mdp_comp *comp) |
---|
66 | 18 | { |
---|
67 | 19 | int i, err; |
---|
.. | .. |
---|
70 | 22 | err = mtk_smi_larb_get(comp->larb_dev); |
---|
71 | 23 | if (err) |
---|
72 | 24 | 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); |
---|
75 | 27 | } |
---|
76 | 28 | |
---|
77 | 29 | for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { |
---|
.. | .. |
---|
80 | 32 | err = clk_prepare_enable(comp->clk[i]); |
---|
81 | 33 | if (err) |
---|
82 | 34 | 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); |
---|
85 | 37 | } |
---|
86 | 38 | } |
---|
87 | 39 | |
---|
.. | .. |
---|
100 | 52 | } |
---|
101 | 53 | |
---|
102 | 54 | 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) |
---|
104 | 57 | { |
---|
105 | 58 | struct device_node *larb_node; |
---|
106 | 59 | struct platform_device *larb_pdev; |
---|
| 60 | + int ret; |
---|
107 | 61 | int i; |
---|
108 | 62 | |
---|
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 | | - |
---|
114 | 63 | 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; |
---|
118 | 65 | |
---|
119 | 66 | for (i = 0; i < ARRAY_SIZE(comp->clk); i++) { |
---|
120 | 67 | 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 | + } |
---|
121 | 74 | |
---|
122 | 75 | /* Only RDMA needs two clocks */ |
---|
123 | 76 | if (comp->type != MTK_MDP_RDMA) |
---|
.. | .. |
---|
135 | 88 | if (!larb_node) { |
---|
136 | 89 | dev_err(dev, |
---|
137 | 90 | "Missing mediadek,larb phandle in %pOF node\n", node); |
---|
138 | | - return -EINVAL; |
---|
| 91 | + ret = -EINVAL; |
---|
| 92 | + goto put_dev; |
---|
139 | 93 | } |
---|
140 | 94 | |
---|
141 | 95 | larb_pdev = of_find_device_by_node(larb_node); |
---|
142 | 96 | if (!larb_pdev) { |
---|
143 | 97 | dev_warn(dev, "Waiting for larb device %pOF\n", larb_node); |
---|
144 | 98 | of_node_put(larb_node); |
---|
145 | | - return -EPROBE_DEFER; |
---|
| 99 | + ret = -EPROBE_DEFER; |
---|
| 100 | + goto put_dev; |
---|
146 | 101 | } |
---|
147 | 102 | of_node_put(larb_node); |
---|
148 | 103 | |
---|
149 | 104 | comp->larb_dev = &larb_pdev->dev; |
---|
150 | 105 | |
---|
151 | 106 | return 0; |
---|
| 107 | + |
---|
| 108 | +put_dev: |
---|
| 109 | + of_node_put(comp->dev_node); |
---|
| 110 | + |
---|
| 111 | + return ret; |
---|
152 | 112 | } |
---|
153 | 113 | |
---|
154 | 114 | void mtk_mdp_comp_deinit(struct device *dev, struct mtk_mdp_comp *comp) |
---|