2 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * Inki Dae <inki.dae@samsung.com>
5 * Joonyoung Shim <jy0922.shim@samsung.com>
6 * Seung-Woo Kim <sw0312.kim@samsung.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <drm/drm_crtc_helper.h>
17 #include <drm/exynos_drm.h>
19 #include "exynos_drm_drv.h"
20 #include "exynos_drm_crtc.h"
21 #include "exynos_drm_encoder.h"
22 #include "exynos_drm_fbdev.h"
23 #include "exynos_drm_fb.h"
24 #include "exynos_drm_gem.h"
25 #include "exynos_drm_plane.h"
26 #include "exynos_drm_vidi.h"
27 #include "exynos_drm_dmabuf.h"
28 #include "exynos_drm_g2d.h"
29 #include "exynos_drm_ipp.h"
30 #include "exynos_drm_iommu.h"
32 #define DRIVER_NAME "exynos"
33 #define DRIVER_DESC "Samsung SoC DRM"
34 #define DRIVER_DATE "20110530"
35 #define DRIVER_MAJOR 1
36 #define DRIVER_MINOR 0
38 #define VBLANK_OFF_DELAY 50000
40 /* platform device pointer for eynos drm device. */
41 static struct platform_device
*exynos_drm_pdev
;
43 static int exynos_drm_load(struct drm_device
*dev
, unsigned long flags
)
45 struct exynos_drm_private
*private;
49 private = kzalloc(sizeof(struct exynos_drm_private
), GFP_KERNEL
);
53 INIT_LIST_HEAD(&private->pageflip_event_list
);
54 dev
->dev_private
= (void *)private;
57 * create mapping to manage iommu table and set a pointer to iommu
58 * mapping structure to iommu_mapping of private data.
59 * also this iommu_mapping can be used to check if iommu is supported
62 ret
= drm_create_iommu_mapping(dev
);
64 DRM_ERROR("failed to create iommu mapping.\n");
68 drm_mode_config_init(dev
);
70 /* init kms poll for handling hpd */
71 drm_kms_helper_poll_init(dev
);
73 exynos_drm_mode_config_init(dev
);
76 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
77 * without dependency of hardware.
79 for (nr
= 0; nr
< MAX_CRTC
; nr
++) {
80 ret
= exynos_drm_crtc_create(dev
, nr
);
82 goto err_release_iommu_mapping
;
85 for (nr
= 0; nr
< MAX_PLANE
; nr
++) {
86 struct drm_plane
*plane
;
87 unsigned int possible_crtcs
= (1 << MAX_CRTC
) - 1;
89 plane
= exynos_plane_init(dev
, possible_crtcs
, false);
91 goto err_release_iommu_mapping
;
94 ret
= drm_vblank_init(dev
, MAX_CRTC
);
96 goto err_release_iommu_mapping
;
99 * probe sub drivers such as display controller and hdmi driver,
100 * that were registered at probe() of platform driver
101 * to the sub driver and create encoder and connector for them.
103 ret
= exynos_drm_device_register(dev
);
107 /* setup possible_clones. */
108 exynos_drm_encoder_setup(dev
);
111 * create and configure fb helper and also exynos specific
114 ret
= exynos_drm_fbdev_init(dev
);
116 DRM_ERROR("failed to initialize drm fbdev\n");
120 drm_vblank_offdelay
= VBLANK_OFF_DELAY
;
125 exynos_drm_device_unregister(dev
);
127 drm_vblank_cleanup(dev
);
128 err_release_iommu_mapping
:
129 drm_release_iommu_mapping(dev
);
131 drm_mode_config_cleanup(dev
);
137 static int exynos_drm_unload(struct drm_device
*dev
)
139 exynos_drm_fbdev_fini(dev
);
140 exynos_drm_device_unregister(dev
);
141 drm_vblank_cleanup(dev
);
142 drm_kms_helper_poll_fini(dev
);
143 drm_mode_config_cleanup(dev
);
145 drm_release_iommu_mapping(dev
);
146 kfree(dev
->dev_private
);
148 dev
->dev_private
= NULL
;
153 static int exynos_drm_open(struct drm_device
*dev
, struct drm_file
*file
)
155 struct drm_exynos_file_private
*file_priv
;
158 file_priv
= kzalloc(sizeof(*file_priv
), GFP_KERNEL
);
162 file
->driver_priv
= file_priv
;
164 ret
= exynos_drm_subdrv_open(dev
, file
);
167 file
->driver_priv
= NULL
;
173 static void exynos_drm_preclose(struct drm_device
*dev
,
174 struct drm_file
*file
)
176 struct exynos_drm_private
*private = dev
->dev_private
;
177 struct drm_pending_vblank_event
*e
, *t
;
180 /* release events of current file */
181 spin_lock_irqsave(&dev
->event_lock
, flags
);
182 list_for_each_entry_safe(e
, t
, &private->pageflip_event_list
,
184 if (e
->base
.file_priv
== file
) {
185 list_del(&e
->base
.link
);
186 e
->base
.destroy(&e
->base
);
189 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
191 exynos_drm_subdrv_close(dev
, file
);
194 static void exynos_drm_postclose(struct drm_device
*dev
, struct drm_file
*file
)
196 if (!file
->driver_priv
)
199 kfree(file
->driver_priv
);
200 file
->driver_priv
= NULL
;
203 static void exynos_drm_lastclose(struct drm_device
*dev
)
205 exynos_drm_fbdev_restore_mode(dev
);
208 static const struct vm_operations_struct exynos_drm_gem_vm_ops
= {
209 .fault
= exynos_drm_gem_fault
,
210 .open
= drm_gem_vm_open
,
211 .close
= drm_gem_vm_close
,
214 static const 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
|
220 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP
,
221 exynos_drm_gem_mmap_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
222 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET
,
223 exynos_drm_gem_get_ioctl
, DRM_UNLOCKED
),
224 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION
,
225 vidi_connection_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
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
),
232 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY
,
233 exynos_drm_ipp_get_property
, DRM_UNLOCKED
| DRM_AUTH
),
234 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY
,
235 exynos_drm_ipp_set_property
, DRM_UNLOCKED
| DRM_AUTH
),
236 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF
,
237 exynos_drm_ipp_queue_buf
, DRM_UNLOCKED
| DRM_AUTH
),
238 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL
,
239 exynos_drm_ipp_cmd_ctrl
, DRM_UNLOCKED
| DRM_AUTH
),
242 static const struct file_operations exynos_drm_driver_fops
= {
243 .owner
= THIS_MODULE
,
245 .mmap
= exynos_drm_gem_mmap
,
248 .unlocked_ioctl
= drm_ioctl
,
250 .compat_ioctl
= drm_compat_ioctl
,
252 .release
= drm_release
,
255 static struct drm_driver exynos_drm_driver
= {
256 .driver_features
= DRIVER_HAVE_IRQ
| DRIVER_MODESET
|
257 DRIVER_GEM
| DRIVER_PRIME
,
258 .load
= exynos_drm_load
,
259 .unload
= exynos_drm_unload
,
260 .open
= exynos_drm_open
,
261 .preclose
= exynos_drm_preclose
,
262 .lastclose
= exynos_drm_lastclose
,
263 .postclose
= exynos_drm_postclose
,
264 .get_vblank_counter
= drm_vblank_count
,
265 .enable_vblank
= exynos_drm_crtc_enable_vblank
,
266 .disable_vblank
= exynos_drm_crtc_disable_vblank
,
267 .gem_init_object
= exynos_drm_gem_init_object
,
268 .gem_free_object
= exynos_drm_gem_free_object
,
269 .gem_vm_ops
= &exynos_drm_gem_vm_ops
,
270 .dumb_create
= exynos_drm_gem_dumb_create
,
271 .dumb_map_offset
= exynos_drm_gem_dumb_map_offset
,
272 .dumb_destroy
= drm_gem_dumb_destroy
,
273 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
274 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
275 .gem_prime_export
= exynos_dmabuf_prime_export
,
276 .gem_prime_import
= exynos_dmabuf_prime_import
,
277 .ioctls
= exynos_ioctls
,
278 .num_ioctls
= ARRAY_SIZE(exynos_ioctls
),
279 .fops
= &exynos_drm_driver_fops
,
283 .major
= DRIVER_MAJOR
,
284 .minor
= DRIVER_MINOR
,
287 static int exynos_drm_platform_probe(struct platform_device
*pdev
)
289 pdev
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
291 return drm_platform_init(&exynos_drm_driver
, pdev
);
294 static int exynos_drm_platform_remove(struct platform_device
*pdev
)
296 drm_platform_exit(&exynos_drm_driver
, pdev
);
301 static struct platform_driver exynos_drm_platform_driver
= {
302 .probe
= exynos_drm_platform_probe
,
303 .remove
= exynos_drm_platform_remove
,
305 .owner
= THIS_MODULE
,
306 .name
= "exynos-drm",
310 static int __init
exynos_drm_init(void)
314 #ifdef CONFIG_DRM_EXYNOS_FIMD
315 ret
= platform_driver_register(&fimd_driver
);
320 #ifdef CONFIG_DRM_EXYNOS_HDMI
321 ret
= platform_driver_register(&hdmi_driver
);
324 ret
= platform_driver_register(&mixer_driver
);
327 ret
= platform_driver_register(&exynos_drm_common_hdmi_driver
);
329 goto out_common_hdmi
;
331 ret
= exynos_platform_device_hdmi_register();
333 goto out_common_hdmi_dev
;
336 #ifdef CONFIG_DRM_EXYNOS_VIDI
337 ret
= platform_driver_register(&vidi_driver
);
342 #ifdef CONFIG_DRM_EXYNOS_G2D
343 ret
= platform_driver_register(&g2d_driver
);
348 #ifdef CONFIG_DRM_EXYNOS_FIMC
349 ret
= platform_driver_register(&fimc_driver
);
354 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
355 ret
= platform_driver_register(&rotator_driver
);
360 #ifdef CONFIG_DRM_EXYNOS_GSC
361 ret
= platform_driver_register(&gsc_driver
);
366 #ifdef CONFIG_DRM_EXYNOS_IPP
367 ret
= platform_driver_register(&ipp_driver
);
371 ret
= exynos_platform_device_ipp_register();
376 ret
= platform_driver_register(&exynos_drm_platform_driver
);
380 exynos_drm_pdev
= platform_device_register_simple("exynos-drm", -1,
382 if (IS_ERR(exynos_drm_pdev
)) {
383 ret
= PTR_ERR(exynos_drm_pdev
);
390 platform_driver_unregister(&exynos_drm_platform_driver
);
393 #ifdef CONFIG_DRM_EXYNOS_IPP
394 exynos_platform_device_ipp_unregister();
396 platform_driver_unregister(&ipp_driver
);
400 #ifdef CONFIG_DRM_EXYNOS_GSC
401 platform_driver_unregister(&gsc_driver
);
405 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
406 platform_driver_unregister(&rotator_driver
);
410 #ifdef CONFIG_DRM_EXYNOS_FIMC
411 platform_driver_unregister(&fimc_driver
);
415 #ifdef CONFIG_DRM_EXYNOS_G2D
416 platform_driver_unregister(&g2d_driver
);
420 #ifdef CONFIG_DRM_EXYNOS_VIDI
421 platform_driver_unregister(&vidi_driver
);
425 #ifdef CONFIG_DRM_EXYNOS_HDMI
426 exynos_platform_device_hdmi_unregister();
428 platform_driver_unregister(&exynos_drm_common_hdmi_driver
);
430 platform_driver_unregister(&mixer_driver
);
432 platform_driver_unregister(&hdmi_driver
);
436 #ifdef CONFIG_DRM_EXYNOS_FIMD
437 platform_driver_unregister(&fimd_driver
);
443 static void __exit
exynos_drm_exit(void)
445 platform_device_unregister(exynos_drm_pdev
);
447 platform_driver_unregister(&exynos_drm_platform_driver
);
449 #ifdef CONFIG_DRM_EXYNOS_IPP
450 exynos_platform_device_ipp_unregister();
451 platform_driver_unregister(&ipp_driver
);
454 #ifdef CONFIG_DRM_EXYNOS_GSC
455 platform_driver_unregister(&gsc_driver
);
458 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
459 platform_driver_unregister(&rotator_driver
);
462 #ifdef CONFIG_DRM_EXYNOS_FIMC
463 platform_driver_unregister(&fimc_driver
);
466 #ifdef CONFIG_DRM_EXYNOS_G2D
467 platform_driver_unregister(&g2d_driver
);
470 #ifdef CONFIG_DRM_EXYNOS_HDMI
471 exynos_platform_device_hdmi_unregister();
472 platform_driver_unregister(&exynos_drm_common_hdmi_driver
);
473 platform_driver_unregister(&mixer_driver
);
474 platform_driver_unregister(&hdmi_driver
);
477 #ifdef CONFIG_DRM_EXYNOS_VIDI
478 platform_driver_unregister(&vidi_driver
);
481 #ifdef CONFIG_DRM_EXYNOS_FIMD
482 platform_driver_unregister(&fimd_driver
);
486 module_init(exynos_drm_init
);
487 module_exit(exynos_drm_exit
);
489 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
490 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
491 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
492 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
493 MODULE_LICENSE("GPL");