exynos_drm_drv.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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_encoder.h"
  34. #include "exynos_drm_fbdev.h"
  35. #include "exynos_drm_fb.h"
  36. #include "exynos_drm_gem.h"
  37. #include "exynos_drm_plane.h"
  38. #define DRIVER_NAME "exynos"
  39. #define DRIVER_DESC "Samsung SoC DRM"
  40. #define DRIVER_DATE "20110530"
  41. #define DRIVER_MAJOR 1
  42. #define DRIVER_MINOR 0
  43. #define VBLANK_OFF_DELAY 50000
  44. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  45. {
  46. struct exynos_drm_private *private;
  47. int ret;
  48. int nr;
  49. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  50. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  51. if (!private) {
  52. DRM_ERROR("failed to allocate private\n");
  53. return -ENOMEM;
  54. }
  55. INIT_LIST_HEAD(&private->pageflip_event_list);
  56. dev->dev_private = (void *)private;
  57. drm_mode_config_init(dev);
  58. /* init kms poll for handling hpd */
  59. drm_kms_helper_poll_init(dev);
  60. exynos_drm_mode_config_init(dev);
  61. /*
  62. * EXYNOS4 is enough to have two CRTCs and each crtc would be used
  63. * without dependency of hardware.
  64. */
  65. for (nr = 0; nr < MAX_CRTC; nr++) {
  66. ret = exynos_drm_crtc_create(dev, nr);
  67. if (ret)
  68. goto err_crtc;
  69. }
  70. for (nr = 0; nr < MAX_PLANE; nr++) {
  71. ret = exynos_plane_init(dev, nr);
  72. if (ret)
  73. goto err_crtc;
  74. }
  75. ret = drm_vblank_init(dev, MAX_CRTC);
  76. if (ret)
  77. goto err_crtc;
  78. /*
  79. * probe sub drivers such as display controller and hdmi driver,
  80. * that were registered at probe() of platform driver
  81. * to the sub driver and create encoder and connector for them.
  82. */
  83. ret = exynos_drm_device_register(dev);
  84. if (ret)
  85. goto err_vblank;
  86. /* setup possible_clones. */
  87. exynos_drm_encoder_setup(dev);
  88. /*
  89. * create and configure fb helper and also exynos specific
  90. * fbdev object.
  91. */
  92. ret = exynos_drm_fbdev_init(dev);
  93. if (ret) {
  94. DRM_ERROR("failed to initialize drm fbdev\n");
  95. goto err_drm_device;
  96. }
  97. drm_vblank_offdelay = VBLANK_OFF_DELAY;
  98. return 0;
  99. err_drm_device:
  100. exynos_drm_device_unregister(dev);
  101. err_vblank:
  102. drm_vblank_cleanup(dev);
  103. err_crtc:
  104. drm_mode_config_cleanup(dev);
  105. kfree(private);
  106. return ret;
  107. }
  108. static int exynos_drm_unload(struct drm_device *dev)
  109. {
  110. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  111. exynos_drm_fbdev_fini(dev);
  112. exynos_drm_device_unregister(dev);
  113. drm_vblank_cleanup(dev);
  114. drm_kms_helper_poll_fini(dev);
  115. drm_mode_config_cleanup(dev);
  116. kfree(dev->dev_private);
  117. dev->dev_private = NULL;
  118. return 0;
  119. }
  120. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  121. {
  122. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  123. return exynos_drm_subdrv_open(dev, file);
  124. }
  125. static void exynos_drm_preclose(struct drm_device *dev,
  126. struct drm_file *file)
  127. {
  128. struct exynos_drm_private *private = dev->dev_private;
  129. struct drm_pending_vblank_event *e, *t;
  130. unsigned long flags;
  131. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  132. /* release events of current file */
  133. spin_lock_irqsave(&dev->event_lock, flags);
  134. list_for_each_entry_safe(e, t, &private->pageflip_event_list,
  135. base.link) {
  136. if (e->base.file_priv == file) {
  137. list_del(&e->base.link);
  138. e->base.destroy(&e->base);
  139. }
  140. }
  141. spin_unlock_irqrestore(&dev->event_lock, flags);
  142. exynos_drm_subdrv_close(dev, file);
  143. }
  144. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  145. {
  146. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  147. if (!file->driver_priv)
  148. return;
  149. kfree(file->driver_priv);
  150. file->driver_priv = NULL;
  151. }
  152. static void exynos_drm_lastclose(struct drm_device *dev)
  153. {
  154. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  155. exynos_drm_fbdev_restore_mode(dev);
  156. }
  157. static struct vm_operations_struct exynos_drm_gem_vm_ops = {
  158. .fault = exynos_drm_gem_fault,
  159. .open = drm_gem_vm_open,
  160. .close = drm_gem_vm_close,
  161. };
  162. static struct drm_ioctl_desc exynos_ioctls[] = {
  163. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  164. DRM_UNLOCKED | DRM_AUTH),
  165. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP_OFFSET,
  166. exynos_drm_gem_map_offset_ioctl, DRM_UNLOCKED |
  167. DRM_AUTH),
  168. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
  169. exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
  170. DRM_IOCTL_DEF_DRV(EXYNOS_PLANE_SET_ZPOS, exynos_plane_set_zpos_ioctl,
  171. DRM_UNLOCKED | DRM_AUTH),
  172. };
  173. static const struct file_operations exynos_drm_driver_fops = {
  174. .owner = THIS_MODULE,
  175. .open = drm_open,
  176. .mmap = exynos_drm_gem_mmap,
  177. .poll = drm_poll,
  178. .read = drm_read,
  179. .unlocked_ioctl = drm_ioctl,
  180. .release = drm_release,
  181. };
  182. static struct drm_driver exynos_drm_driver = {
  183. .driver_features = DRIVER_HAVE_IRQ | DRIVER_BUS_PLATFORM |
  184. DRIVER_MODESET | DRIVER_GEM,
  185. .load = exynos_drm_load,
  186. .unload = exynos_drm_unload,
  187. .open = exynos_drm_open,
  188. .preclose = exynos_drm_preclose,
  189. .lastclose = exynos_drm_lastclose,
  190. .postclose = exynos_drm_postclose,
  191. .get_vblank_counter = drm_vblank_count,
  192. .enable_vblank = exynos_drm_crtc_enable_vblank,
  193. .disable_vblank = exynos_drm_crtc_disable_vblank,
  194. .gem_init_object = exynos_drm_gem_init_object,
  195. .gem_free_object = exynos_drm_gem_free_object,
  196. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  197. .dumb_create = exynos_drm_gem_dumb_create,
  198. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  199. .dumb_destroy = exynos_drm_gem_dumb_destroy,
  200. .ioctls = exynos_ioctls,
  201. .fops = &exynos_drm_driver_fops,
  202. .name = DRIVER_NAME,
  203. .desc = DRIVER_DESC,
  204. .date = DRIVER_DATE,
  205. .major = DRIVER_MAJOR,
  206. .minor = DRIVER_MINOR,
  207. };
  208. static int exynos_drm_platform_probe(struct platform_device *pdev)
  209. {
  210. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  211. exynos_drm_driver.num_ioctls = DRM_ARRAY_SIZE(exynos_ioctls);
  212. return drm_platform_init(&exynos_drm_driver, pdev);
  213. }
  214. static int exynos_drm_platform_remove(struct platform_device *pdev)
  215. {
  216. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  217. drm_platform_exit(&exynos_drm_driver, pdev);
  218. return 0;
  219. }
  220. static struct platform_driver exynos_drm_platform_driver = {
  221. .probe = exynos_drm_platform_probe,
  222. .remove = __devexit_p(exynos_drm_platform_remove),
  223. .driver = {
  224. .owner = THIS_MODULE,
  225. .name = DRIVER_NAME,
  226. },
  227. };
  228. static int __init exynos_drm_init(void)
  229. {
  230. int ret;
  231. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  232. #ifdef CONFIG_DRM_EXYNOS_FIMD
  233. ret = platform_driver_register(&fimd_driver);
  234. if (ret < 0)
  235. goto out_fimd;
  236. #endif
  237. #ifdef CONFIG_DRM_EXYNOS_HDMI
  238. ret = platform_driver_register(&hdmi_driver);
  239. if (ret < 0)
  240. goto out_hdmi;
  241. ret = platform_driver_register(&mixer_driver);
  242. if (ret < 0)
  243. goto out_mixer;
  244. ret = platform_driver_register(&exynos_drm_common_hdmi_driver);
  245. if (ret < 0)
  246. goto out_common_hdmi;
  247. #endif
  248. ret = platform_driver_register(&exynos_drm_platform_driver);
  249. if (ret < 0)
  250. goto out;
  251. return 0;
  252. out:
  253. #ifdef CONFIG_DRM_EXYNOS_HDMI
  254. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  255. out_common_hdmi:
  256. platform_driver_unregister(&mixer_driver);
  257. out_mixer:
  258. platform_driver_unregister(&hdmi_driver);
  259. out_hdmi:
  260. #endif
  261. #ifdef CONFIG_DRM_EXYNOS_FIMD
  262. platform_driver_unregister(&fimd_driver);
  263. out_fimd:
  264. #endif
  265. return ret;
  266. }
  267. static void __exit exynos_drm_exit(void)
  268. {
  269. DRM_DEBUG_DRIVER("%s\n", __FILE__);
  270. platform_driver_unregister(&exynos_drm_platform_driver);
  271. #ifdef CONFIG_DRM_EXYNOS_HDMI
  272. platform_driver_unregister(&exynos_drm_common_hdmi_driver);
  273. platform_driver_unregister(&mixer_driver);
  274. platform_driver_unregister(&hdmi_driver);
  275. #endif
  276. #ifdef CONFIG_DRM_EXYNOS_FIMD
  277. platform_driver_unregister(&fimd_driver);
  278. #endif
  279. }
  280. module_init(exynos_drm_init);
  281. module_exit(exynos_drm_exit);
  282. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  283. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  284. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  285. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  286. MODULE_LICENSE("GPL");