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 <linux/anon_inodes.h>
19 #include <drm/exynos_drm.h>
21 #include "exynos_drm_drv.h"
22 #include "exynos_drm_crtc.h"
23 #include "exynos_drm_encoder.h"
24 #include "exynos_drm_fbdev.h"
25 #include "exynos_drm_fb.h"
26 #include "exynos_drm_gem.h"
27 #include "exynos_drm_plane.h"
28 #include "exynos_drm_vidi.h"
29 #include "exynos_drm_dmabuf.h"
30 #include "exynos_drm_g2d.h"
31 #include "exynos_drm_ipp.h"
32 #include "exynos_drm_iommu.h"
34 #define DRIVER_NAME "exynos"
35 #define DRIVER_DESC "Samsung SoC DRM"
36 #define DRIVER_DATE "20110530"
37 #define DRIVER_MAJOR 1
38 #define DRIVER_MINOR 0
40 #define VBLANK_OFF_DELAY 50000
42 /* platform device pointer for eynos drm device. */
43 static struct platform_device
*exynos_drm_pdev
;
45 static int exynos_drm_load(struct drm_device
*dev
, unsigned long flags
)
47 struct exynos_drm_private
*private;
51 private = kzalloc(sizeof(struct exynos_drm_private
), GFP_KERNEL
);
55 INIT_LIST_HEAD(&private->pageflip_event_list
);
56 dev
->dev_private
= (void *)private;
59 * create mapping to manage iommu table and set a pointer to iommu
60 * mapping structure to iommu_mapping of private data.
61 * also this iommu_mapping can be used to check if iommu is supported
64 ret
= drm_create_iommu_mapping(dev
);
66 DRM_ERROR("failed to create iommu mapping.\n");
70 drm_mode_config_init(dev
);
72 /* init kms poll for handling hpd */
73 drm_kms_helper_poll_init(dev
);
75 exynos_drm_mode_config_init(dev
);
78 * EXYNOS4 is enough to have two CRTCs and each crtc would be used
79 * without dependency of hardware.
81 for (nr
= 0; nr
< MAX_CRTC
; nr
++) {
82 ret
= exynos_drm_crtc_create(dev
, nr
);
84 goto err_release_iommu_mapping
;
87 for (nr
= 0; nr
< MAX_PLANE
; nr
++) {
88 struct drm_plane
*plane
;
89 unsigned int possible_crtcs
= (1 << MAX_CRTC
) - 1;
91 plane
= exynos_plane_init(dev
, possible_crtcs
, false);
93 goto err_release_iommu_mapping
;
96 ret
= drm_vblank_init(dev
, MAX_CRTC
);
98 goto err_release_iommu_mapping
;
101 * probe sub drivers such as display controller and hdmi driver,
102 * that were registered at probe() of platform driver
103 * to the sub driver and create encoder and connector for them.
105 ret
= exynos_drm_device_register(dev
);
109 /* setup possible_clones. */
110 exynos_drm_encoder_setup(dev
);
113 * create and configure fb helper and also exynos specific
116 ret
= exynos_drm_fbdev_init(dev
);
118 DRM_ERROR("failed to initialize drm fbdev\n");
122 drm_vblank_offdelay
= VBLANK_OFF_DELAY
;
124 platform_set_drvdata(dev
->platformdev
, dev
);
129 exynos_drm_device_unregister(dev
);
131 drm_vblank_cleanup(dev
);
132 err_release_iommu_mapping
:
133 drm_release_iommu_mapping(dev
);
135 drm_mode_config_cleanup(dev
);
141 static int exynos_drm_unload(struct drm_device
*dev
)
143 exynos_drm_fbdev_fini(dev
);
144 exynos_drm_device_unregister(dev
);
145 drm_vblank_cleanup(dev
);
146 drm_kms_helper_poll_fini(dev
);
147 drm_mode_config_cleanup(dev
);
149 drm_release_iommu_mapping(dev
);
150 kfree(dev
->dev_private
);
152 dev
->dev_private
= NULL
;
157 static const struct file_operations exynos_drm_gem_fops
= {
158 .mmap
= exynos_drm_gem_mmap_buffer
,
161 static int exynos_drm_open(struct drm_device
*dev
, struct drm_file
*file
)
163 struct drm_exynos_file_private
*file_priv
;
164 struct file
*anon_filp
;
167 file_priv
= kzalloc(sizeof(*file_priv
), GFP_KERNEL
);
171 file
->driver_priv
= file_priv
;
173 ret
= exynos_drm_subdrv_open(dev
, file
);
177 anon_filp
= anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops
,
179 if (IS_ERR(anon_filp
)) {
180 ret
= PTR_ERR(anon_filp
);
184 anon_filp
->f_mode
= FMODE_READ
| FMODE_WRITE
;
185 file_priv
->anon_filp
= anon_filp
;
190 file
->driver_priv
= NULL
;
194 static void exynos_drm_preclose(struct drm_device
*dev
,
195 struct drm_file
*file
)
197 exynos_drm_subdrv_close(dev
, file
);
200 static void exynos_drm_postclose(struct drm_device
*dev
, struct drm_file
*file
)
202 struct exynos_drm_private
*private = dev
->dev_private
;
203 struct drm_exynos_file_private
*file_priv
;
204 struct drm_pending_vblank_event
*v
, *vt
;
205 struct drm_pending_event
*e
, *et
;
208 if (!file
->driver_priv
)
211 /* Release all events not unhandled by page flip handler. */
212 spin_lock_irqsave(&dev
->event_lock
, flags
);
213 list_for_each_entry_safe(v
, vt
, &private->pageflip_event_list
,
215 if (v
->base
.file_priv
== file
) {
216 list_del(&v
->base
.link
);
217 drm_vblank_put(dev
, v
->pipe
);
218 v
->base
.destroy(&v
->base
);
222 /* Release all events handled by page flip handler but not freed. */
223 list_for_each_entry_safe(e
, et
, &file
->event_list
, link
) {
227 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
229 file_priv
= file
->driver_priv
;
230 if (file_priv
->anon_filp
)
231 fput(file_priv
->anon_filp
);
233 kfree(file
->driver_priv
);
234 file
->driver_priv
= NULL
;
237 static void exynos_drm_lastclose(struct drm_device
*dev
)
239 exynos_drm_fbdev_restore_mode(dev
);
242 static const struct vm_operations_struct exynos_drm_gem_vm_ops
= {
243 .fault
= exynos_drm_gem_fault
,
244 .open
= drm_gem_vm_open
,
245 .close
= drm_gem_vm_close
,
248 static const struct drm_ioctl_desc exynos_ioctls
[] = {
249 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE
, exynos_drm_gem_create_ioctl
,
250 DRM_UNLOCKED
| DRM_AUTH
),
251 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET
,
252 exynos_drm_gem_map_offset_ioctl
, DRM_UNLOCKED
|
254 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP
,
255 exynos_drm_gem_mmap_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
256 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET
,
257 exynos_drm_gem_get_ioctl
, DRM_UNLOCKED
),
258 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION
,
259 vidi_connection_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
260 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER
,
261 exynos_g2d_get_ver_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
262 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST
,
263 exynos_g2d_set_cmdlist_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
264 DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC
,
265 exynos_g2d_exec_ioctl
, DRM_UNLOCKED
| DRM_AUTH
),
266 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY
,
267 exynos_drm_ipp_get_property
, DRM_UNLOCKED
| DRM_AUTH
),
268 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY
,
269 exynos_drm_ipp_set_property
, DRM_UNLOCKED
| DRM_AUTH
),
270 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF
,
271 exynos_drm_ipp_queue_buf
, DRM_UNLOCKED
| DRM_AUTH
),
272 DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL
,
273 exynos_drm_ipp_cmd_ctrl
, DRM_UNLOCKED
| DRM_AUTH
),
276 static const struct file_operations exynos_drm_driver_fops
= {
277 .owner
= THIS_MODULE
,
279 .mmap
= exynos_drm_gem_mmap
,
282 .unlocked_ioctl
= drm_ioctl
,
284 .compat_ioctl
= drm_compat_ioctl
,
286 .release
= drm_release
,
289 static struct drm_driver exynos_drm_driver
= {
290 .driver_features
= DRIVER_HAVE_IRQ
| DRIVER_MODESET
|
291 DRIVER_GEM
| DRIVER_PRIME
,
292 .load
= exynos_drm_load
,
293 .unload
= exynos_drm_unload
,
294 .open
= exynos_drm_open
,
295 .preclose
= exynos_drm_preclose
,
296 .lastclose
= exynos_drm_lastclose
,
297 .postclose
= exynos_drm_postclose
,
298 .get_vblank_counter
= drm_vblank_count
,
299 .enable_vblank
= exynos_drm_crtc_enable_vblank
,
300 .disable_vblank
= exynos_drm_crtc_disable_vblank
,
301 .gem_free_object
= exynos_drm_gem_free_object
,
302 .gem_vm_ops
= &exynos_drm_gem_vm_ops
,
303 .dumb_create
= exynos_drm_gem_dumb_create
,
304 .dumb_map_offset
= exynos_drm_gem_dumb_map_offset
,
305 .dumb_destroy
= drm_gem_dumb_destroy
,
306 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
307 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
308 .gem_prime_export
= exynos_dmabuf_prime_export
,
309 .gem_prime_import
= exynos_dmabuf_prime_import
,
310 .ioctls
= exynos_ioctls
,
311 .num_ioctls
= ARRAY_SIZE(exynos_ioctls
),
312 .fops
= &exynos_drm_driver_fops
,
316 .major
= DRIVER_MAJOR
,
317 .minor
= DRIVER_MINOR
,
320 static int exynos_drm_platform_probe(struct platform_device
*pdev
)
324 ret
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
328 return drm_platform_init(&exynos_drm_driver
, pdev
);
331 static int exynos_drm_platform_remove(struct platform_device
*pdev
)
333 drm_put_dev(platform_get_drvdata(pdev
));
338 static struct platform_driver exynos_drm_platform_driver
= {
339 .probe
= exynos_drm_platform_probe
,
340 .remove
= exynos_drm_platform_remove
,
342 .owner
= THIS_MODULE
,
343 .name
= "exynos-drm",
347 static int __init
exynos_drm_init(void)
351 #ifdef CONFIG_DRM_EXYNOS_FIMD
352 ret
= platform_driver_register(&fimd_driver
);
357 #ifdef CONFIG_DRM_EXYNOS_HDMI
358 ret
= platform_driver_register(&hdmi_driver
);
361 ret
= platform_driver_register(&mixer_driver
);
364 ret
= platform_driver_register(&exynos_drm_common_hdmi_driver
);
366 goto out_common_hdmi
;
368 ret
= exynos_platform_device_hdmi_register();
370 goto out_common_hdmi_dev
;
373 #ifdef CONFIG_DRM_EXYNOS_VIDI
374 ret
= platform_driver_register(&vidi_driver
);
379 #ifdef CONFIG_DRM_EXYNOS_G2D
380 ret
= platform_driver_register(&g2d_driver
);
385 #ifdef CONFIG_DRM_EXYNOS_FIMC
386 ret
= platform_driver_register(&fimc_driver
);
391 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
392 ret
= platform_driver_register(&rotator_driver
);
397 #ifdef CONFIG_DRM_EXYNOS_GSC
398 ret
= platform_driver_register(&gsc_driver
);
403 #ifdef CONFIG_DRM_EXYNOS_IPP
404 ret
= platform_driver_register(&ipp_driver
);
408 ret
= exynos_platform_device_ipp_register();
413 ret
= platform_driver_register(&exynos_drm_platform_driver
);
417 exynos_drm_pdev
= platform_device_register_simple("exynos-drm", -1,
419 if (IS_ERR(exynos_drm_pdev
)) {
420 ret
= PTR_ERR(exynos_drm_pdev
);
427 platform_driver_unregister(&exynos_drm_platform_driver
);
430 #ifdef CONFIG_DRM_EXYNOS_IPP
431 exynos_platform_device_ipp_unregister();
433 platform_driver_unregister(&ipp_driver
);
437 #ifdef CONFIG_DRM_EXYNOS_GSC
438 platform_driver_unregister(&gsc_driver
);
442 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
443 platform_driver_unregister(&rotator_driver
);
447 #ifdef CONFIG_DRM_EXYNOS_FIMC
448 platform_driver_unregister(&fimc_driver
);
452 #ifdef CONFIG_DRM_EXYNOS_G2D
453 platform_driver_unregister(&g2d_driver
);
457 #ifdef CONFIG_DRM_EXYNOS_VIDI
458 platform_driver_unregister(&vidi_driver
);
462 #ifdef CONFIG_DRM_EXYNOS_HDMI
463 exynos_platform_device_hdmi_unregister();
465 platform_driver_unregister(&exynos_drm_common_hdmi_driver
);
467 platform_driver_unregister(&mixer_driver
);
469 platform_driver_unregister(&hdmi_driver
);
473 #ifdef CONFIG_DRM_EXYNOS_FIMD
474 platform_driver_unregister(&fimd_driver
);
480 static void __exit
exynos_drm_exit(void)
482 platform_device_unregister(exynos_drm_pdev
);
484 platform_driver_unregister(&exynos_drm_platform_driver
);
486 #ifdef CONFIG_DRM_EXYNOS_IPP
487 exynos_platform_device_ipp_unregister();
488 platform_driver_unregister(&ipp_driver
);
491 #ifdef CONFIG_DRM_EXYNOS_GSC
492 platform_driver_unregister(&gsc_driver
);
495 #ifdef CONFIG_DRM_EXYNOS_ROTATOR
496 platform_driver_unregister(&rotator_driver
);
499 #ifdef CONFIG_DRM_EXYNOS_FIMC
500 platform_driver_unregister(&fimc_driver
);
503 #ifdef CONFIG_DRM_EXYNOS_G2D
504 platform_driver_unregister(&g2d_driver
);
507 #ifdef CONFIG_DRM_EXYNOS_HDMI
508 exynos_platform_device_hdmi_unregister();
509 platform_driver_unregister(&exynos_drm_common_hdmi_driver
);
510 platform_driver_unregister(&mixer_driver
);
511 platform_driver_unregister(&hdmi_driver
);
514 #ifdef CONFIG_DRM_EXYNOS_VIDI
515 platform_driver_unregister(&vidi_driver
);
518 #ifdef CONFIG_DRM_EXYNOS_FIMD
519 platform_driver_unregister(&fimd_driver
);
523 module_init(exynos_drm_init
);
524 module_exit(exynos_drm_exit
);
526 MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
527 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
528 MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
529 MODULE_DESCRIPTION("Samsung SoC DRM Driver");
530 MODULE_LICENSE("GPL");