exynos_drm_drv.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #include "drmP.h"
  28. #include "drm.h"
  29. #include "drm_crtc_helper.h"
  30. #include <drm/exynos_drm.h>
  31. #include "exynos_drm_drv.h"
  32. #include "exynos_drm_crtc.h"
  33. #include "exynos_drm_fbdev.h"
  34. #include "exynos_drm_fb.h"
  35. #include "exynos_drm_gem.h"
  36. #include "exynos_drm_plane.h"
  37. #define DRIVER_NAME "exynos"
  38. #define DRIVER_DESC "Samsung SoC DRM"
  39. #define DRIVER_DATE "20110530"
  40. #define DRIVER_MAJOR 1
  41. #define DRIVER_MINOR 0
  42. #define VBLANK_OFF_DELAY 50000
  43. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  44. {
  45. struct exynos_drm_private *private;
  46. int ret;
  47. int nr;
  48. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  49. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  50. if (!private) {
  51. DRM_ERROR("failed to allocate private\n");
  52. return -ENOMEM;
  53. }
  54. INIT_LIST_HEAD(&private->pageflip_event_list);
  55. dev->dev_private = (void *)private;
  56. drm_mode_config_init(dev);
  57. /* init kms poll for handling hpd */
  58. drm_kms_helper_poll_init(dev);
  59. exynos_drm_mode_config_init(dev);
  60. /*
  61. * EXYNOS4 is enough to have two CRTCs and each crtc would be used
  62. * without dependency of hardware.
  63. */
  64. for (nr = 0; nr < MAX_CRTC; nr++) {
  65. ret = exynos_drm_crtc_create(dev, nr);
  66. if (ret)
  67. goto err_crtc;
  68. }
  69. for (nr = 0; nr < MAX_PLANE; nr++) {
  70. ret = exynos_plane_init(dev, nr);
  71. if (ret)
  72. goto err_crtc;
  73. }
  74. ret = drm_vblank_init(dev, MAX_CRTC);
  75. if (ret)
  76. goto err_crtc;
  77. /*
  78. * probe sub drivers such as display controller and hdmi driver,
  79. * that were registered at probe() of platform driver
  80. * to the sub driver and create encoder and connector for them.
  81. */
  82. ret = exynos_drm_device_register(dev);
  83. if (ret)
  84. goto err_vblank;
  85. /*
  86. * create and configure fb helper and also exynos specific
  87. * fbdev object.
  88. */
  89. ret = exynos_drm_fbdev_init(dev);
  90. if (ret) {
  91. DRM_ERROR("failed to initialize drm fbdev\n");
  92. goto err_drm_device;
  93. }
  94. drm_vblank_offdelay = VBLANK_OFF_DELAY;
  95. return 0;
  96. err_drm_device:
  97. exynos_drm_device_unregister(dev);
  98. err_vblank:
  99. drm_vblank_cleanup(dev);
  100. err_crtc:
  101. drm_mode_config_cleanup(dev);
  102. kfree(private);
  103. return ret;
  104. }
  105. static int exynos_drm_unload(struct drm_device *dev)
  106. {
  107. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  108. exynos_drm_fbdev_fini(dev);
  109. exynos_drm_device_unregister(dev);
  110. drm_vblank_cleanup(dev);
  111. drm_kms_helper_poll_fini(dev);
  112. drm_mode_config_cleanup(dev);
  113. kfree(dev->dev_private);
  114. dev->dev_private = NULL;
  115. return 0;
  116. }
  117. static void exynos_drm_preclose(struct drm_device *dev,
  118. struct drm_file *file_priv)
  119. {
  120. struct exynos_drm_private *dev_priv = dev->dev_private;
  121. /*
  122. * drm framework frees all events at release time,
  123. * so private event list should be cleared.
  124. */
  125. if (!list_empty(&dev_priv->pageflip_event_list))
  126. INIT_LIST_HEAD(&dev_priv->pageflip_event_list);
  127. }
  128. static void exynos_drm_lastclose(struct drm_device *dev)
  129. {
  130. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  131. exynos_drm_fbdev_restore_mode(dev);
  132. }
  133. static struct vm_operations_struct exynos_drm_gem_vm_ops = {
  134. .fault = exynos_drm_gem_fault,
  135. .open = drm_gem_vm_open,
  136. .close = drm_gem_vm_close,
  137. };
  138. static struct drm_ioctl_desc exynos_ioctls[] = {
  139. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  140. DRM_UNLOCKED | DRM_AUTH),
  141. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  142. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  143. DRM_AUTH),
  144. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  145. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  146. DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
  147. DRM_UNLOCKED | DRM_AUTH),
  148. };
  149. static const struct file_operations exynos_drm_driver_fops = {
  150. .owner = THIS_MODULE,
  151. .open = drm_open,
  152. .mmap = exynos_drm_gem_mmap,
  153. .poll = drm_poll,
  154. .read = drm_read,
  155. .unlocked_ioctl = drm_ioctl,
  156. .release = drm_release,
  157. };
  158. static struct drm_driver exynos_drm_driver = {
  159. .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
  160. DRIVER_MODESET | DRIVER_GEM,
  161. .load = exynos_drm_load,
  162. .unload = exynos_drm_unload,
  163. .preclose = exynos_drm_preclose,
  164. .lastclose = exynos_drm_lastclose,
  165. .get_vblank_counter = drm_vblank_count,
  166. .enable_vblank = exynos_drm_crtc_enable_vblank,
  167. .disable_vblank = exynos_drm_crtc_disable_vblank,
  168. .gem_init_object = exynos_drm_gem_init_object,
  169. .gem_free_object = exynos_drm_gem_free_object,
  170. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  171. .dumb_create = exynos_drm_gem_dumb_create,
  172. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  173. .dumb_destroy = exynos_drm_gem_dumb_destroy,
  174. .ioctls = exynos_ioctls,
  175. .fops = &exynos_drm_driver_fops,
  176. .name = DRIVER_NAME,
  177. .desc = DRIVER_DESC,
  178. .date = DRIVER_DATE,
  179. .major = DRIVER_MAJOR,
  180. .minor = DRIVER_MINOR,
  181. };
  182. static int exynos_drm_platform_probe(struct platform_device *pdev)
  183. {
  184. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  185. exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
  186. return drm_platform_init(&exynos_drm_driver, pdev);
  187. }
  188. static int exynos_drm_platform_remove(struct platform_device *pdev)
  189. {
  190. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  191. drm_platform_exit(&exynos_drm_driver, pdev);
  192. return 0;
  193. }
  194. static struct platform_driver exynos_drm_platform_driver = {
  195. .probe = exynos_drm_platform_probe,
  196. .remove = __devexit_p(exynos_drm_platform_remove),
  197. .driver = {
  198. .owner = THIS_MODULE,
  199. .name = DRIVER_NAME,
  200. },
  201. };
  202. static int __init exynos_drm_init(void)
  203. {
  204. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  205. return platform_driver_register(&exynos_drm_platform_driver);
  206. }
  207. static void __exit exynos_drm_exit(void)
  208. {
  209. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  210. platform_driver_unregister(&exynos_drm_platform_driver);
  211. }
  212. module_init(exynos_drm_init);
  213. module_exit(exynos_drm_exit);
  214. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  215. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  216. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  217. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  218. MODULE_LICENSE("GPL");