forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/sun4i/sun8i_tcon_top.c
....@@ -1,18 +1,24 @@
11 // SPDX-License-Identifier: GPL-2.0+
22 /* Copyright (c) 2018 Jernej Skrabec <jernej.skrabec@siol.net> */
33
4
-#include <drm/drmP.h>
5
-
6
-#include <dt-bindings/clock/sun8i-tcon-top.h>
74
85 #include <linux/bitfield.h>
96 #include <linux/component.h>
107 #include <linux/device.h>
8
+#include <linux/io.h>
119 #include <linux/module.h>
10
+#include <linux/of_device.h>
1211 #include <linux/of_graph.h>
1312 #include <linux/platform_device.h>
1413
14
+#include <dt-bindings/clock/sun8i-tcon-top.h>
15
+
1516 #include "sun8i_tcon_top.h"
17
+
18
+struct sun8i_tcon_top_quirks {
19
+ bool has_tcon_tv1;
20
+ bool has_dsi;
21
+};
1622
1723 static bool sun8i_tcon_top_node_is_tcon_top(struct device_node *node)
1824 {
....@@ -121,16 +127,18 @@
121127 struct platform_device *pdev = to_platform_device(dev);
122128 struct clk_hw_onecell_data *clk_data;
123129 struct sun8i_tcon_top *tcon_top;
130
+ const struct sun8i_tcon_top_quirks *quirks;
124131 struct resource *res;
125132 void __iomem *regs;
126133 int ret, i;
134
+
135
+ quirks = of_device_get_match_data(&pdev->dev);
127136
128137 tcon_top = devm_kzalloc(dev, sizeof(*tcon_top), GFP_KERNEL);
129138 if (!tcon_top)
130139 return -ENOMEM;
131140
132
- clk_data = devm_kzalloc(dev, sizeof(*clk_data) +
133
- sizeof(*clk_data->hws) * CLK_NUM,
141
+ clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, CLK_NUM),
134142 GFP_KERNEL);
135143 if (!clk_data)
136144 return -ENOMEM;
....@@ -188,15 +196,17 @@
188196 &tcon_top->reg_lock,
189197 TCON_TOP_TCON_TV0_GATE, 0);
190198
191
- clk_data->hws[CLK_TCON_TOP_TV1] =
192
- sun8i_tcon_top_register_gate(dev, "tcon-tv1", regs,
193
- &tcon_top->reg_lock,
194
- TCON_TOP_TCON_TV1_GATE, 1);
199
+ if (quirks->has_tcon_tv1)
200
+ clk_data->hws[CLK_TCON_TOP_TV1] =
201
+ sun8i_tcon_top_register_gate(dev, "tcon-tv1", regs,
202
+ &tcon_top->reg_lock,
203
+ TCON_TOP_TCON_TV1_GATE, 1);
195204
196
- clk_data->hws[CLK_TCON_TOP_DSI] =
197
- sun8i_tcon_top_register_gate(dev, "dsi", regs,
198
- &tcon_top->reg_lock,
199
- TCON_TOP_TCON_DSI_GATE, 2);
205
+ if (quirks->has_dsi)
206
+ clk_data->hws[CLK_TCON_TOP_DSI] =
207
+ sun8i_tcon_top_register_gate(dev, "dsi", regs,
208
+ &tcon_top->reg_lock,
209
+ TCON_TOP_TCON_DSI_GATE, 2);
200210
201211 for (i = 0; i < CLK_NUM; i++)
202212 if (IS_ERR(clk_data->hws[i])) {
....@@ -259,8 +269,25 @@
259269 return 0;
260270 }
261271
272
+static const struct sun8i_tcon_top_quirks sun8i_r40_tcon_top_quirks = {
273
+ .has_tcon_tv1 = true,
274
+ .has_dsi = true,
275
+};
276
+
277
+static const struct sun8i_tcon_top_quirks sun50i_h6_tcon_top_quirks = {
278
+ /* Nothing special */
279
+};
280
+
262281 /* sun4i_drv uses this list to check if a device node is a TCON TOP */
263282 const struct of_device_id sun8i_tcon_top_of_table[] = {
283
+ {
284
+ .compatible = "allwinner,sun8i-r40-tcon-top",
285
+ .data = &sun8i_r40_tcon_top_quirks
286
+ },
287
+ {
288
+ .compatible = "allwinner,sun50i-h6-tcon-top",
289
+ .data = &sun50i_h6_tcon_top_quirks
290
+ },
264291 { /* sentinel */ }
265292 };
266293 MODULE_DEVICE_TABLE(of, sun8i_tcon_top_of_table);