.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ARC PGU DRM driver. |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | | - * |
---|
15 | 6 | */ |
---|
16 | 7 | |
---|
17 | 8 | #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> |
---|
19 | 13 | #include <drm/drm_fb_cma_helper.h> |
---|
| 14 | +#include <drm/drm_fb_helper.h> |
---|
20 | 15 | #include <drm/drm_gem_cma_helper.h> |
---|
21 | 16 | #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> |
---|
23 | 21 | #include <linux/of_reserved_mem.h> |
---|
| 22 | +#include <linux/platform_device.h> |
---|
24 | 23 | |
---|
25 | 24 | #include "arcpgu.h" |
---|
26 | 25 | #include "arcpgu_regs.h" |
---|
27 | 26 | |
---|
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 | | - |
---|
35 | 27 | static const struct drm_mode_config_funcs arcpgu_drm_modecfg_funcs = { |
---|
36 | 28 | .fb_create = drm_gem_fb_create, |
---|
37 | | - .output_poll_changed = arcpgu_fb_output_poll_changed, |
---|
38 | 29 | .atomic_check = drm_atomic_helper_check, |
---|
39 | 30 | .atomic_commit = drm_atomic_helper_commit, |
---|
40 | 31 | }; |
---|
.. | .. |
---|
51 | 42 | |
---|
52 | 43 | DEFINE_DRM_GEM_CMA_FOPS(arcpgu_drm_ops); |
---|
53 | 44 | |
---|
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 | | - |
---|
61 | 45 | static int arcpgu_load(struct drm_device *drm) |
---|
62 | 46 | { |
---|
63 | 47 | struct platform_device *pdev = to_platform_device(drm->dev); |
---|
64 | 48 | struct arcpgu_drm_private *arcpgu; |
---|
65 | | - struct device_node *encoder_node; |
---|
| 49 | + struct device_node *encoder_node = NULL, *endpoint_node = NULL; |
---|
66 | 50 | struct resource *res; |
---|
67 | 51 | int ret; |
---|
68 | 52 | |
---|
.. | .. |
---|
97 | 81 | if (arc_pgu_setup_crtc(drm) < 0) |
---|
98 | 82 | return -ENODEV; |
---|
99 | 83 | |
---|
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 | + |
---|
102 | 94 | if (encoder_node) { |
---|
103 | 95 | ret = arcpgu_drm_hdmi_init(drm, encoder_node); |
---|
104 | 96 | of_node_put(encoder_node); |
---|
105 | 97 | if (ret < 0) |
---|
106 | 98 | return ret; |
---|
107 | 99 | } else { |
---|
| 100 | + dev_info(drm->dev, "no encoder found. Assumed virtual LCD on simulation platform\n"); |
---|
108 | 101 | ret = arcpgu_drm_sim_init(drm, NULL); |
---|
109 | 102 | if (ret < 0) |
---|
110 | 103 | return ret; |
---|
.. | .. |
---|
113 | 106 | drm_mode_config_reset(drm); |
---|
114 | 107 | drm_kms_helper_poll_init(drm); |
---|
115 | 108 | |
---|
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 | | - |
---|
124 | 109 | platform_set_drvdata(pdev, drm); |
---|
125 | 110 | return 0; |
---|
126 | 111 | } |
---|
127 | 112 | |
---|
128 | 113 | static int arcpgu_unload(struct drm_device *drm) |
---|
129 | 114 | { |
---|
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 | | - } |
---|
136 | 115 | drm_kms_helper_poll_fini(drm); |
---|
| 116 | + drm_atomic_helper_shutdown(drm); |
---|
137 | 117 | drm_mode_config_cleanup(drm); |
---|
138 | 118 | |
---|
139 | 119 | return 0; |
---|
.. | .. |
---|
157 | 137 | { "clocks", arcpgu_show_pxlclock, 0 }, |
---|
158 | 138 | }; |
---|
159 | 139 | |
---|
160 | | -static int arcpgu_debugfs_init(struct drm_minor *minor) |
---|
| 140 | +static void arcpgu_debugfs_init(struct drm_minor *minor) |
---|
161 | 141 | { |
---|
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); |
---|
164 | 145 | } |
---|
165 | 146 | #endif |
---|
166 | 147 | |
---|
167 | 148 | 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, |
---|
171 | 150 | .name = "arcpgu", |
---|
172 | 151 | .desc = "ARC PGU Controller", |
---|
173 | 152 | .date = "20160219", |
---|
.. | .. |
---|
175 | 154 | .minor = 0, |
---|
176 | 155 | .patchlevel = 0, |
---|
177 | 156 | .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, |
---|
191 | 158 | #ifdef CONFIG_DEBUG_FS |
---|
192 | 159 | .debugfs_init = arcpgu_debugfs_init, |
---|
193 | 160 | #endif |
---|
.. | .. |
---|
210 | 177 | if (ret) |
---|
211 | 178 | goto err_unload; |
---|
212 | 179 | |
---|
| 180 | + drm_fbdev_generic_setup(drm, 16); |
---|
| 181 | + |
---|
213 | 182 | return 0; |
---|
214 | 183 | |
---|
215 | 184 | err_unload: |
---|
216 | 185 | arcpgu_unload(drm); |
---|
217 | 186 | |
---|
218 | 187 | err_unref: |
---|
219 | | - drm_dev_unref(drm); |
---|
| 188 | + drm_dev_put(drm); |
---|
220 | 189 | |
---|
221 | 190 | return ret; |
---|
222 | 191 | } |
---|
.. | .. |
---|
227 | 196 | |
---|
228 | 197 | drm_dev_unregister(drm); |
---|
229 | 198 | arcpgu_unload(drm); |
---|
230 | | - drm_dev_unref(drm); |
---|
| 199 | + drm_dev_put(drm); |
---|
231 | 200 | |
---|
232 | 201 | return 0; |
---|
233 | 202 | } |
---|