exynos_drm_drv.c 6.6 KB

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