Commit | Line | Data |
---|---|---|
1c248b7d ID |
1 | /* |
2 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | |
3 | * Authors: | |
4 | * Inki Dae <inki.dae@samsung.com> | |
5 | * Joonyoung Shim <jy0922.shim@samsung.com> | |
6 | * Seung-Woo Kim <sw0312.kim@samsung.com> | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a | |
9 | * copy of this software and associated documentation files (the "Software"), | |
10 | * to deal in the Software without restriction, including without limitation | |
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
12 | * and/or sell copies of the Software, and to permit persons to whom the | |
13 | * Software is furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice (including the next | |
16 | * paragraph) shall be included in all copies or substantial portions of the | |
17 | * Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
22 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
23 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
24 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
25 | * OTHER DEALINGS IN THE SOFTWARE. | |
26 | */ | |
27 | ||
760285e7 DH |
28 | #include <drm/drmP.h> |
29 | #include <drm/drm_crtc_helper.h> | |
1c248b7d ID |
30 | |
31 | #include <drm/exynos_drm.h> | |
32 | ||
33 | #include "exynos_drm_drv.h" | |
34 | #include "exynos_drm_crtc.h" | |
d081f566 | 35 | #include "exynos_drm_encoder.h" |
1c248b7d ID |
36 | #include "exynos_drm_fbdev.h" |
37 | #include "exynos_drm_fb.h" | |
38 | #include "exynos_drm_gem.h" | |
864ee9e6 | 39 | #include "exynos_drm_plane.h" |
b73d1230 | 40 | #include "exynos_drm_vidi.h" |
b2df26c1 | 41 | #include "exynos_drm_dmabuf.h" |
d7f1642c | 42 | #include "exynos_drm_g2d.h" |
1c248b7d | 43 | |
0edf9936 | 44 | #define DRIVER_NAME "exynos" |
1c248b7d ID |
45 | #define DRIVER_DESC "Samsung SoC DRM" |
46 | #define DRIVER_DATE "20110530" | |
47 | #define DRIVER_MAJOR 1 | |
48 | #define DRIVER_MINOR 0 | |
49 | ||
52c68814 ID |
50 | #define VBLANK_OFF_DELAY 50000 |
51 | ||
1c248b7d ID |
52 | static int exynos_drm_load(struct drm_device *dev, unsigned long flags) |
53 | { | |
54 | struct exynos_drm_private *private; | |
55 | int ret; | |
56 | int nr; | |
57 | ||
58 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
59 | ||
60 | private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL); | |
61 | if (!private) { | |
62 | DRM_ERROR("failed to allocate private\n"); | |
63 | return -ENOMEM; | |
64 | } | |
65 | ||
66 | INIT_LIST_HEAD(&private->pageflip_event_list); | |
67 | dev->dev_private = (void *)private; | |
68 | ||
69 | drm_mode_config_init(dev); | |
70 | ||
7db3eba6 SWK |
71 | /* init kms poll for handling hpd */ |
72 | drm_kms_helper_poll_init(dev); | |
73 | ||
1c248b7d ID |
74 | exynos_drm_mode_config_init(dev); |
75 | ||
76 | /* | |
77 | * EXYNOS4 is enough to have two CRTCs and each crtc would be used | |
78 | * without dependency of hardware. | |
79 | */ | |
80 | for (nr = 0; nr < MAX_CRTC; nr++) { | |
81 | ret = exynos_drm_crtc_create(dev, nr); | |
82 | if (ret) | |
83 | goto err_crtc; | |
84 | } | |
85 | ||
864ee9e6 | 86 | for (nr = 0; nr < MAX_PLANE; nr++) { |
b5d2eb3b JS |
87 | struct drm_plane *plane; |
88 | unsigned int possible_crtcs = (1 << MAX_CRTC) - 1; | |
89 | ||
90 | plane = exynos_plane_init(dev, possible_crtcs, false); | |
91 | if (!plane) | |
864ee9e6 JS |
92 | goto err_crtc; |
93 | } | |
94 | ||
1c248b7d ID |
95 | ret = drm_vblank_init(dev, MAX_CRTC); |
96 | if (ret) | |
97 | goto err_crtc; | |
98 | ||
99 | /* | |
100 | * probe sub drivers such as display controller and hdmi driver, | |
101 | * that were registered at probe() of platform driver | |
102 | * to the sub driver and create encoder and connector for them. | |
103 | */ | |
104 | ret = exynos_drm_device_register(dev); | |
105 | if (ret) | |
106 | goto err_vblank; | |
107 | ||
d081f566 ID |
108 | /* setup possible_clones. */ |
109 | exynos_drm_encoder_setup(dev); | |
110 | ||
1c248b7d ID |
111 | /* |
112 | * create and configure fb helper and also exynos specific | |
113 | * fbdev object. | |
114 | */ | |
115 | ret = exynos_drm_fbdev_init(dev); | |
116 | if (ret) { | |
117 | DRM_ERROR("failed to initialize drm fbdev\n"); | |
118 | goto err_drm_device; | |
119 | } | |
120 | ||
52c68814 ID |
121 | drm_vblank_offdelay = VBLANK_OFF_DELAY; |
122 | ||
1c248b7d ID |
123 | return 0; |
124 | ||
125 | err_drm_device: | |
126 | exynos_drm_device_unregister(dev); | |
127 | err_vblank: | |
128 | drm_vblank_cleanup(dev); | |
129 | err_crtc: | |
130 | drm_mode_config_cleanup(dev); | |
131 | kfree(private); | |
132 | ||
133 | return ret; | |
134 | } | |
135 | ||
136 | static int exynos_drm_unload(struct drm_device *dev) | |
137 | { | |
138 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
139 | ||
140 | exynos_drm_fbdev_fini(dev); | |
141 | exynos_drm_device_unregister(dev); | |
142 | drm_vblank_cleanup(dev); | |
7db3eba6 | 143 | drm_kms_helper_poll_fini(dev); |
1c248b7d ID |
144 | drm_mode_config_cleanup(dev); |
145 | kfree(dev->dev_private); | |
146 | ||
147 | dev->dev_private = NULL; | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
9084f7b8 JS |
152 | static int exynos_drm_open(struct drm_device *dev, struct drm_file *file) |
153 | { | |
d7f1642c JS |
154 | struct drm_exynos_file_private *file_priv; |
155 | ||
9084f7b8 JS |
156 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
157 | ||
d7f1642c JS |
158 | file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL); |
159 | if (!file_priv) | |
160 | return -ENOMEM; | |
161 | ||
d7f1642c | 162 | file->driver_priv = file_priv; |
b2df26c1 | 163 | |
9084f7b8 JS |
164 | return exynos_drm_subdrv_open(dev, file); |
165 | } | |
166 | ||
ccf4d883 | 167 | static void exynos_drm_preclose(struct drm_device *dev, |
6f811502 | 168 | struct drm_file *file) |
ccf4d883 | 169 | { |
3ab09435 JS |
170 | struct exynos_drm_private *private = dev->dev_private; |
171 | struct drm_pending_vblank_event *e, *t; | |
172 | unsigned long flags; | |
173 | ||
6f811502 | 174 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
ccf4d883 | 175 | |
3ab09435 JS |
176 | /* release events of current file */ |
177 | spin_lock_irqsave(&dev->event_lock, flags); | |
178 | list_for_each_entry_safe(e, t, &private->pageflip_event_list, | |
179 | base.link) { | |
180 | if (e->base.file_priv == file) { | |
181 | list_del(&e->base.link); | |
182 | e->base.destroy(&e->base); | |
183 | } | |
184 | } | |
185 | spin_unlock_irqrestore(&dev->event_lock, flags); | |
9084f7b8 JS |
186 | |
187 | exynos_drm_subdrv_close(dev, file); | |
ccf4d883 ID |
188 | } |
189 | ||
53ef299f ID |
190 | static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file) |
191 | { | |
192 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
193 | ||
194 | if (!file->driver_priv) | |
195 | return; | |
196 | ||
197 | kfree(file->driver_priv); | |
198 | file->driver_priv = NULL; | |
199 | } | |
200 | ||
1c248b7d ID |
201 | static void exynos_drm_lastclose(struct drm_device *dev) |
202 | { | |
203 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
204 | ||
205 | exynos_drm_fbdev_restore_mode(dev); | |
206 | } | |
207 | ||
78b68556 | 208 | static const struct vm_operations_struct exynos_drm_gem_vm_ops = { |
1c248b7d ID |
209 | .fault = exynos_drm_gem_fault, |
210 | .open = drm_gem_vm_open, | |
211 | .close = drm_gem_vm_close, | |
212 | }; | |
213 | ||
214 | static struct drm_ioctl_desc exynos_ioctls[] = { | |
215 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl, | |
216 | DRM_UNLOCKED | DRM_AUTH), | |
217 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET, | |
218 | exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED | | |
219 | DRM_AUTH), | |
220 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP, | |
221 | exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
40cd7e0c ID |
222 | DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, |
223 | exynos_drm_gem_get_ioctl, DRM_UNLOCKED), | |
b73d1230 ID |
224 | DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, |
225 | vidi_connection_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
d7f1642c JS |
226 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, |
227 | exynos_g2d_get_ver_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
228 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, | |
229 | exynos_g2d_set_cmdlist_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
230 | DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, | |
231 | exynos_g2d_exec_ioctl, DRM_UNLOCKED | DRM_AUTH), | |
1c248b7d ID |
232 | }; |
233 | ||
ac2bdf73 JS |
234 | static const struct file_operations exynos_drm_driver_fops = { |
235 | .owner = THIS_MODULE, | |
236 | .open = drm_open, | |
237 | .mmap = exynos_drm_gem_mmap, | |
238 | .poll = drm_poll, | |
239 | .read = drm_read, | |
240 | .unlocked_ioctl = drm_ioctl, | |
804d74ab KP |
241 | #ifdef CONFIG_COMPAT |
242 | .compat_ioctl = drm_compat_ioctl, | |
243 | #endif | |
ac2bdf73 JS |
244 | .release = drm_release, |
245 | }; | |
246 | ||
1c248b7d | 247 | static struct drm_driver exynos_drm_driver = { |
293a1c12 LP |
248 | .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET | |
249 | DRIVER_GEM | DRIVER_PRIME, | |
1c248b7d ID |
250 | .load = exynos_drm_load, |
251 | .unload = exynos_drm_unload, | |
9084f7b8 | 252 | .open = exynos_drm_open, |
ccf4d883 | 253 | .preclose = exynos_drm_preclose, |
1c248b7d | 254 | .lastclose = exynos_drm_lastclose, |
53ef299f | 255 | .postclose = exynos_drm_postclose, |
1c248b7d ID |
256 | .get_vblank_counter = drm_vblank_count, |
257 | .enable_vblank = exynos_drm_crtc_enable_vblank, | |
258 | .disable_vblank = exynos_drm_crtc_disable_vblank, | |
259 | .gem_init_object = exynos_drm_gem_init_object, | |
260 | .gem_free_object = exynos_drm_gem_free_object, | |
261 | .gem_vm_ops = &exynos_drm_gem_vm_ops, | |
262 | .dumb_create = exynos_drm_gem_dumb_create, | |
263 | .dumb_map_offset = exynos_drm_gem_dumb_map_offset, | |
264 | .dumb_destroy = exynos_drm_gem_dumb_destroy, | |
b2df26c1 ID |
265 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
266 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, | |
267 | .gem_prime_export = exynos_dmabuf_prime_export, | |
268 | .gem_prime_import = exynos_dmabuf_prime_import, | |
1c248b7d | 269 | .ioctls = exynos_ioctls, |
ac2bdf73 | 270 | .fops = &exynos_drm_driver_fops, |
1c248b7d ID |
271 | .name = DRIVER_NAME, |
272 | .desc = DRIVER_DESC, | |
273 | .date = DRIVER_DATE, | |
274 | .major = DRIVER_MAJOR, | |
275 | .minor = DRIVER_MINOR, | |
276 | }; | |
277 | ||
278 | static int exynos_drm_platform_probe(struct platform_device *pdev) | |
279 | { | |
280 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
281 | ||
282 | exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls); | |
283 | ||
284 | return drm_platform_init(&exynos_drm_driver, pdev); | |
285 | } | |
286 | ||
287 | static int exynos_drm_platform_remove(struct platform_device *pdev) | |
288 | { | |
289 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
290 | ||
291 | drm_platform_exit(&exynos_drm_driver, pdev); | |
292 | ||
293 | return 0; | |
294 | } | |
295 | ||
296 | static struct platform_driver exynos_drm_platform_driver = { | |
297 | .probe = exynos_drm_platform_probe, | |
298 | .remove = __devexit_p(exynos_drm_platform_remove), | |
299 | .driver = { | |
300 | .owner = THIS_MODULE, | |
9866b6c6 | 301 | .name = "exynos-drm", |
1c248b7d ID |
302 | }, |
303 | }; | |
304 | ||
305 | static int __init exynos_drm_init(void) | |
306 | { | |
132a5b91 JS |
307 | int ret; |
308 | ||
1c248b7d ID |
309 | DRM_DEBUG_DRIVER("%s\n", __FILE__); |
310 | ||
132a5b91 JS |
311 | #ifdef CONFIG_DRM_EXYNOS_FIMD |
312 | ret = platform_driver_register(&fimd_driver); | |
313 | if (ret < 0) | |
314 | goto out_fimd; | |
315 | #endif | |
316 | ||
317 | #ifdef CONFIG_DRM_EXYNOS_HDMI | |
318 | ret = platform_driver_register(&hdmi_driver); | |
319 | if (ret < 0) | |
320 | goto out_hdmi; | |
321 | ret = platform_driver_register(&mixer_driver); | |
322 | if (ret < 0) | |
323 | goto out_mixer; | |
324 | ret = platform_driver_register(&exynos_drm_common_hdmi_driver); | |
325 | if (ret < 0) | |
326 | goto out_common_hdmi; | |
327 | #endif | |
328 | ||
b73d1230 ID |
329 | #ifdef CONFIG_DRM_EXYNOS_VIDI |
330 | ret = platform_driver_register(&vidi_driver); | |
331 | if (ret < 0) | |
332 | goto out_vidi; | |
333 | #endif | |
334 | ||
d7f1642c JS |
335 | #ifdef CONFIG_DRM_EXYNOS_G2D |
336 | ret = platform_driver_register(&g2d_driver); | |
337 | if (ret < 0) | |
338 | goto out_g2d; | |
339 | #endif | |
340 | ||
132a5b91 JS |
341 | ret = platform_driver_register(&exynos_drm_platform_driver); |
342 | if (ret < 0) | |
343 | goto out; | |
344 | ||
345 | return 0; | |
346 | ||
347 | out: | |
d7f1642c JS |
348 | #ifdef CONFIG_DRM_EXYNOS_G2D |
349 | platform_driver_unregister(&g2d_driver); | |
350 | out_g2d: | |
351 | #endif | |
352 | ||
b73d1230 ID |
353 | #ifdef CONFIG_DRM_EXYNOS_VIDI |
354 | out_vidi: | |
355 | platform_driver_unregister(&vidi_driver); | |
356 | #endif | |
357 | ||
132a5b91 JS |
358 | #ifdef CONFIG_DRM_EXYNOS_HDMI |
359 | platform_driver_unregister(&exynos_drm_common_hdmi_driver); | |
360 | out_common_hdmi: | |
361 | platform_driver_unregister(&mixer_driver); | |
362 | out_mixer: | |
363 | platform_driver_unregister(&hdmi_driver); | |
364 | out_hdmi: | |
365 | #endif | |
366 | ||
367 | #ifdef CONFIG_DRM_EXYNOS_FIMD | |
368 | platform_driver_unregister(&fimd_driver); | |
369 | out_fimd: | |
370 | #endif | |
371 | return ret; | |
1c248b7d ID |
372 | } |
373 | ||
374 | static void __exit exynos_drm_exit(void) | |
375 | { | |
376 | DRM_DEBUG_DRIVER("%s\n", __FILE__); | |
377 | ||
378 | platform_driver_unregister(&exynos_drm_platform_driver); | |
132a5b91 | 379 | |
d7f1642c JS |
380 | #ifdef CONFIG_DRM_EXYNOS_G2D |
381 | platform_driver_unregister(&g2d_driver); | |
382 | #endif | |
383 | ||
132a5b91 JS |
384 | #ifdef CONFIG_DRM_EXYNOS_HDMI |
385 | platform_driver_unregister(&exynos_drm_common_hdmi_driver); | |
386 | platform_driver_unregister(&mixer_driver); | |
387 | platform_driver_unregister(&hdmi_driver); | |
388 | #endif | |
389 | ||
b73d1230 ID |
390 | #ifdef CONFIG_DRM_EXYNOS_VIDI |
391 | platform_driver_unregister(&vidi_driver); | |
392 | #endif | |
393 | ||
132a5b91 JS |
394 | #ifdef CONFIG_DRM_EXYNOS_FIMD |
395 | platform_driver_unregister(&fimd_driver); | |
396 | #endif | |
1c248b7d ID |
397 | } |
398 | ||
399 | module_init(exynos_drm_init); | |
400 | module_exit(exynos_drm_exit); | |
401 | ||
402 | MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); | |
403 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | |
404 | MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>"); | |
405 | MODULE_DESCRIPTION("Samsung SoC DRM Driver"); | |
406 | MODULE_LICENSE("GPL"); |