exynos_drm_drv.c 9.1 KB

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