forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/arc/arcpgu_drv.c
....@@ -1,40 +1,31 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ARC PGU DRM driver.
34 *
45 * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.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.
14
- *
156 */
167
178 #include <linux/clk.h>
18
-#include <drm/drm_crtc_helper.h>
9
+#include <drm/drm_atomic_helper.h>
10
+#include <drm/drm_debugfs.h>
11
+#include <drm/drm_device.h>
12
+#include <drm/drm_drv.h>
1913 #include <drm/drm_fb_cma_helper.h>
14
+#include <drm/drm_fb_helper.h>
2015 #include <drm/drm_gem_cma_helper.h>
2116 #include <drm/drm_gem_framebuffer_helper.h>
22
-#include <drm/drm_atomic_helper.h>
17
+#include <drm/drm_of.h>
18
+#include <drm/drm_probe_helper.h>
19
+#include <linux/dma-mapping.h>
20
+#include <linux/module.h>
2321 #include <linux/of_reserved_mem.h>
22
+#include <linux/platform_device.h>
2423
2524 #include "arcpgu.h"
2625 #include "arcpgu_regs.h"
2726
28
-static void arcpgu_fb_output_poll_changed(struct drm_device *dev)
29
-{
30
- struct arcpgu_drm_private *arcpgu = dev->dev_private;
31
-
32
- drm_fbdev_cma_hotplug_event(arcpgu->fbdev);
33
-}
34
-
3527 static const struct drm_mode_config_funcs arcpgu_drm_modecfg_funcs = {
3628 .fb_create = drm_gem_fb_create,
37
- .output_poll_changed = arcpgu_fb_output_poll_changed,
3829 .atomic_check = drm_atomic_helper_check,
3930 .atomic_commit = drm_atomic_helper_commit,
4031 };
....@@ -51,18 +42,11 @@
5142
5243 DEFINE_DRM_GEM_CMA_FOPS(arcpgu_drm_ops);
5344
54
-static void arcpgu_lastclose(struct drm_device *drm)
55
-{
56
- struct arcpgu_drm_private *arcpgu = drm->dev_private;
57
-
58
- drm_fbdev_cma_restore_mode(arcpgu->fbdev);
59
-}
60
-
6145 static int arcpgu_load(struct drm_device *drm)
6246 {
6347 struct platform_device *pdev = to_platform_device(drm->dev);
6448 struct arcpgu_drm_private *arcpgu;
65
- struct device_node *encoder_node;
49
+ struct device_node *encoder_node = NULL, *endpoint_node = NULL;
6650 struct resource *res;
6751 int ret;
6852
....@@ -97,14 +81,23 @@
9781 if (arc_pgu_setup_crtc(drm) < 0)
9882 return -ENODEV;
9983
100
- /* find the encoder node and initialize it */
101
- encoder_node = of_parse_phandle(drm->dev->of_node, "encoder-slave", 0);
84
+ /*
85
+ * There is only one output port inside each device. It is linked with
86
+ * encoder endpoint.
87
+ */
88
+ endpoint_node = of_graph_get_next_endpoint(pdev->dev.of_node, NULL);
89
+ if (endpoint_node) {
90
+ encoder_node = of_graph_get_remote_port_parent(endpoint_node);
91
+ of_node_put(endpoint_node);
92
+ }
93
+
10294 if (encoder_node) {
10395 ret = arcpgu_drm_hdmi_init(drm, encoder_node);
10496 of_node_put(encoder_node);
10597 if (ret < 0)
10698 return ret;
10799 } else {
100
+ dev_info(drm->dev, "no encoder found. Assumed virtual LCD on simulation platform\n");
108101 ret = arcpgu_drm_sim_init(drm, NULL);
109102 if (ret < 0)
110103 return ret;
....@@ -113,27 +106,14 @@
113106 drm_mode_config_reset(drm);
114107 drm_kms_helper_poll_init(drm);
115108
116
- arcpgu->fbdev = drm_fbdev_cma_init(drm, 16,
117
- drm->mode_config.num_connector);
118
- if (IS_ERR(arcpgu->fbdev)) {
119
- ret = PTR_ERR(arcpgu->fbdev);
120
- arcpgu->fbdev = NULL;
121
- return -ENODEV;
122
- }
123
-
124109 platform_set_drvdata(pdev, drm);
125110 return 0;
126111 }
127112
128113 static int arcpgu_unload(struct drm_device *drm)
129114 {
130
- struct arcpgu_drm_private *arcpgu = drm->dev_private;
131
-
132
- if (arcpgu->fbdev) {
133
- drm_fbdev_cma_fini(arcpgu->fbdev);
134
- arcpgu->fbdev = NULL;
135
- }
136115 drm_kms_helper_poll_fini(drm);
116
+ drm_atomic_helper_shutdown(drm);
137117 drm_mode_config_cleanup(drm);
138118
139119 return 0;
....@@ -157,17 +137,16 @@
157137 { "clocks", arcpgu_show_pxlclock, 0 },
158138 };
159139
160
-static int arcpgu_debugfs_init(struct drm_minor *minor)
140
+static void arcpgu_debugfs_init(struct drm_minor *minor)
161141 {
162
- return drm_debugfs_create_files(arcpgu_debugfs_list,
163
- ARRAY_SIZE(arcpgu_debugfs_list), minor->debugfs_root, minor);
142
+ drm_debugfs_create_files(arcpgu_debugfs_list,
143
+ ARRAY_SIZE(arcpgu_debugfs_list),
144
+ minor->debugfs_root, minor);
164145 }
165146 #endif
166147
167148 static struct drm_driver arcpgu_drm_driver = {
168
- .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
169
- DRIVER_ATOMIC,
170
- .lastclose = arcpgu_lastclose,
149
+ .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
171150 .name = "arcpgu",
172151 .desc = "ARC PGU Controller",
173152 .date = "20160219",
....@@ -175,19 +154,7 @@
175154 .minor = 0,
176155 .patchlevel = 0,
177156 .fops = &arcpgu_drm_ops,
178
- .dumb_create = drm_gem_cma_dumb_create,
179
- .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
180
- .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
181
- .gem_free_object_unlocked = drm_gem_cma_free_object,
182
- .gem_print_info = drm_gem_cma_print_info,
183
- .gem_vm_ops = &drm_gem_cma_vm_ops,
184
- .gem_prime_export = drm_gem_prime_export,
185
- .gem_prime_import = drm_gem_prime_import,
186
- .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
187
- .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
188
- .gem_prime_vmap = drm_gem_cma_prime_vmap,
189
- .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
190
- .gem_prime_mmap = drm_gem_cma_prime_mmap,
157
+ DRM_GEM_CMA_DRIVER_OPS,
191158 #ifdef CONFIG_DEBUG_FS
192159 .debugfs_init = arcpgu_debugfs_init,
193160 #endif
....@@ -210,13 +177,15 @@
210177 if (ret)
211178 goto err_unload;
212179
180
+ drm_fbdev_generic_setup(drm, 16);
181
+
213182 return 0;
214183
215184 err_unload:
216185 arcpgu_unload(drm);
217186
218187 err_unref:
219
- drm_dev_unref(drm);
188
+ drm_dev_put(drm);
220189
221190 return ret;
222191 }
....@@ -227,7 +196,7 @@
227196
228197 drm_dev_unregister(drm);
229198 arcpgu_unload(drm);
230
- drm_dev_unref(drm);
199
+ drm_dev_put(drm);
231200
232201 return 0;
233202 }