exynos_drm_drv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. * 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.
  12. */
  13. #include <linux/pm_runtime.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_atomic.h>
  16. #include <drm/drm_atomic_helper.h>
  17. #include <drm/drm_crtc_helper.h>
  18. #include <linux/component.h>
  19. #include <drm/exynos_drm.h>
  20. #include "exynos_drm_drv.h"
  21. #include "exynos_drm_crtc.h"
  22. #include "exynos_drm_fbdev.h"
  23. #include "exynos_drm_fb.h"
  24. #include "exynos_drm_gem.h"
  25. #include "exynos_drm_plane.h"
  26. #include "exynos_drm_vidi.h"
  27. #include "exynos_drm_g2d.h"
  28. #include "exynos_drm_ipp.h"
  29. #include "exynos_drm_iommu.h"
  30. #define DRIVER_NAME "exynos"
  31. #define DRIVER_DESC "Samsung SoC DRM"
  32. #define DRIVER_DATE "20110530"
  33. #define DRIVER_MAJOR 1
  34. #define DRIVER_MINOR 0
  35. struct exynos_atomic_commit {
  36. struct work_struct work;
  37. struct drm_device *dev;
  38. struct drm_atomic_state *state;
  39. u32 crtcs;
  40. };
  41. static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit)
  42. {
  43. struct drm_device *dev = commit->dev;
  44. struct exynos_drm_private *priv = dev->dev_private;
  45. struct drm_atomic_state *state = commit->state;
  46. drm_atomic_helper_commit_modeset_disables(dev, state);
  47. drm_atomic_helper_commit_modeset_enables(dev, state);
  48. /*
  49. * Exynos can't update planes with CRTCs and encoders disabled,
  50. * its updates routines, specially for FIMD, requires the clocks
  51. * to be enabled. So it is necessary to handle the modeset operations
  52. * *before* the commit_planes() step, this way it will always
  53. * have the relevant clocks enabled to perform the update.
  54. */
  55. drm_atomic_helper_commit_planes(dev, state, 0);
  56. drm_atomic_helper_wait_for_vblanks(dev, state);
  57. drm_atomic_helper_cleanup_planes(dev, state);
  58. drm_atomic_state_put(state);
  59. spin_lock(&priv->lock);
  60. priv->pending &= ~commit->crtcs;
  61. spin_unlock(&priv->lock);
  62. wake_up_all(&priv->wait);
  63. kfree(commit);
  64. }
  65. static void exynos_drm_atomic_work(struct work_struct *work)
  66. {
  67. struct exynos_atomic_commit *commit = container_of(work,
  68. struct exynos_atomic_commit, work);
  69. exynos_atomic_commit_complete(commit);
  70. }
  71. static struct device *exynos_drm_get_dma_device(void);
  72. static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
  73. {
  74. struct exynos_drm_private *private;
  75. struct drm_encoder *encoder;
  76. unsigned int clone_mask;
  77. int cnt, ret;
  78. private = kzalloc(sizeof(struct exynos_drm_private), GFP_KERNEL);
  79. if (!private)
  80. return -ENOMEM;
  81. init_waitqueue_head(&private->wait);
  82. spin_lock_init(&private->lock);
  83. dev_set_drvdata(dev->dev, dev);
  84. dev->dev_private = (void *)private;
  85. /* the first real CRTC device is used for all dma mapping operations */
  86. private->dma_dev = exynos_drm_get_dma_device();
  87. if (!private->dma_dev) {
  88. DRM_ERROR("no device found for DMA mapping operations.\n");
  89. ret = -ENODEV;
  90. goto err_free_private;
  91. }
  92. DRM_INFO("Exynos DRM: using %s device for DMA mapping operations\n",
  93. dev_name(private->dma_dev));
  94. /* create common IOMMU mapping for all devices attached to Exynos DRM */
  95. ret = drm_create_iommu_mapping(dev);
  96. if (ret < 0) {
  97. DRM_ERROR("failed to create iommu mapping.\n");
  98. goto err_free_private;
  99. }
  100. drm_mode_config_init(dev);
  101. exynos_drm_mode_config_init(dev);
  102. /* setup possible_clones. */
  103. cnt = 0;
  104. clone_mask = 0;
  105. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  106. clone_mask |= (1 << (cnt++));
  107. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  108. encoder->possible_clones = clone_mask;
  109. platform_set_drvdata(dev->platformdev, dev);
  110. /* Try to bind all sub drivers. */
  111. ret = component_bind_all(dev->dev, dev);
  112. if (ret)
  113. goto err_mode_config_cleanup;
  114. ret = drm_vblank_init(dev, dev->mode_config.num_crtc);
  115. if (ret)
  116. goto err_unbind_all;
  117. /* Probe non kms sub drivers and virtual display driver. */
  118. ret = exynos_drm_device_subdrv_probe(dev);
  119. if (ret)
  120. goto err_cleanup_vblank;
  121. drm_mode_config_reset(dev);
  122. /*
  123. * enable drm irq mode.
  124. * - with irq_enabled = true, we can use the vblank feature.
  125. *
  126. * P.S. note that we wouldn't use drm irq handler but
  127. * just specific driver own one instead because
  128. * drm framework supports only one irq handler.
  129. */
  130. dev->irq_enabled = true;
  131. /* init kms poll for handling hpd */
  132. drm_kms_helper_poll_init(dev);
  133. /* force connectors detection */
  134. drm_helper_hpd_irq_event(dev);
  135. return 0;
  136. err_cleanup_vblank:
  137. drm_vblank_cleanup(dev);
  138. err_unbind_all:
  139. component_unbind_all(dev->dev, dev);
  140. err_mode_config_cleanup:
  141. drm_mode_config_cleanup(dev);
  142. drm_release_iommu_mapping(dev);
  143. err_free_private:
  144. kfree(private);
  145. return ret;
  146. }
  147. static int exynos_drm_unload(struct drm_device *dev)
  148. {
  149. exynos_drm_device_subdrv_remove(dev);
  150. exynos_drm_fbdev_fini(dev);
  151. drm_kms_helper_poll_fini(dev);
  152. drm_vblank_cleanup(dev);
  153. component_unbind_all(dev->dev, dev);
  154. drm_mode_config_cleanup(dev);
  155. drm_release_iommu_mapping(dev);
  156. kfree(dev->dev_private);
  157. dev->dev_private = NULL;
  158. return 0;
  159. }
  160. static int commit_is_pending(struct exynos_drm_private *priv, u32 crtcs)
  161. {
  162. bool pending;
  163. spin_lock(&priv->lock);
  164. pending = priv->pending & crtcs;
  165. spin_unlock(&priv->lock);
  166. return pending;
  167. }
  168. int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
  169. bool nonblock)
  170. {
  171. struct exynos_drm_private *priv = dev->dev_private;
  172. struct exynos_atomic_commit *commit;
  173. struct drm_crtc *crtc;
  174. struct drm_crtc_state *crtc_state;
  175. int i, ret;
  176. commit = kzalloc(sizeof(*commit), GFP_KERNEL);
  177. if (!commit)
  178. return -ENOMEM;
  179. ret = drm_atomic_helper_prepare_planes(dev, state);
  180. if (ret) {
  181. kfree(commit);
  182. return ret;
  183. }
  184. /* This is the point of no return */
  185. INIT_WORK(&commit->work, exynos_drm_atomic_work);
  186. commit->dev = dev;
  187. commit->state = state;
  188. /* Wait until all affected CRTCs have completed previous commits and
  189. * mark them as pending.
  190. */
  191. for_each_crtc_in_state(state, crtc, crtc_state, i)
  192. commit->crtcs |= drm_crtc_mask(crtc);
  193. wait_event(priv->wait, !commit_is_pending(priv, commit->crtcs));
  194. spin_lock(&priv->lock);
  195. priv->pending |= commit->crtcs;
  196. spin_unlock(&priv->lock);
  197. drm_atomic_helper_swap_state(state, true);
  198. drm_atomic_state_get(state);
  199. if (nonblock)
  200. schedule_work(&commit->work);
  201. else
  202. exynos_atomic_commit_complete(commit);
  203. return 0;
  204. }
  205. int exynos_atomic_check(struct drm_device *dev,
  206. struct drm_atomic_state *state)
  207. {
  208. int ret;
  209. ret = drm_atomic_helper_check_modeset(dev, state);
  210. if (ret)
  211. return ret;
  212. ret = drm_atomic_normalize_zpos(dev, state);
  213. if (ret)
  214. return ret;
  215. ret = drm_atomic_helper_check_planes(dev, state);
  216. if (ret)
  217. return ret;
  218. return ret;
  219. }
  220. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  221. {
  222. struct drm_exynos_file_private *file_priv;
  223. int ret;
  224. file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
  225. if (!file_priv)
  226. return -ENOMEM;
  227. file->driver_priv = file_priv;
  228. ret = exynos_drm_subdrv_open(dev, file);
  229. if (ret)
  230. goto err_file_priv_free;
  231. return ret;
  232. err_file_priv_free:
  233. kfree(file_priv);
  234. file->driver_priv = NULL;
  235. return ret;
  236. }
  237. static void exynos_drm_preclose(struct drm_device *dev,
  238. struct drm_file *file)
  239. {
  240. struct drm_crtc *crtc;
  241. exynos_drm_subdrv_close(dev, file);
  242. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  243. exynos_drm_crtc_cancel_page_flip(crtc, file);
  244. }
  245. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  246. {
  247. kfree(file->driver_priv);
  248. file->driver_priv = NULL;
  249. }
  250. static void exynos_drm_lastclose(struct drm_device *dev)
  251. {
  252. exynos_drm_fbdev_restore_mode(dev);
  253. }
  254. static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
  255. .fault = exynos_drm_gem_fault,
  256. .open = drm_gem_vm_open,
  257. .close = drm_gem_vm_close,
  258. };
  259. static const struct drm_ioctl_desc exynos_ioctls[] = {
  260. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  261. DRM_AUTH | DRM_RENDER_ALLOW),
  262. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP, exynos_drm_gem_map_ioctl,
  263. DRM_AUTH | DRM_RENDER_ALLOW),
  264. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, exynos_drm_gem_get_ioctl,
  265. DRM_RENDER_ALLOW),
  266. DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, vidi_connection_ioctl,
  267. DRM_AUTH),
  268. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, exynos_g2d_get_ver_ioctl,
  269. DRM_AUTH | DRM_RENDER_ALLOW),
  270. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, exynos_g2d_set_cmdlist_ioctl,
  271. DRM_AUTH | DRM_RENDER_ALLOW),
  272. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, exynos_g2d_exec_ioctl,
  273. DRM_AUTH | DRM_RENDER_ALLOW),
  274. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY, exynos_drm_ipp_get_property,
  275. DRM_AUTH | DRM_RENDER_ALLOW),
  276. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY, exynos_drm_ipp_set_property,
  277. DRM_AUTH | DRM_RENDER_ALLOW),
  278. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF, exynos_drm_ipp_queue_buf,
  279. DRM_AUTH | DRM_RENDER_ALLOW),
  280. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL, exynos_drm_ipp_cmd_ctrl,
  281. DRM_AUTH | DRM_RENDER_ALLOW),
  282. };
  283. static const struct file_operations exynos_drm_driver_fops = {
  284. .owner = THIS_MODULE,
  285. .open = drm_open,
  286. .mmap = exynos_drm_gem_mmap,
  287. .poll = drm_poll,
  288. .read = drm_read,
  289. .unlocked_ioctl = drm_ioctl,
  290. .compat_ioctl = drm_compat_ioctl,
  291. .release = drm_release,
  292. };
  293. static struct drm_driver exynos_drm_driver = {
  294. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME
  295. | DRIVER_ATOMIC | DRIVER_RENDER,
  296. .load = exynos_drm_load,
  297. .unload = exynos_drm_unload,
  298. .open = exynos_drm_open,
  299. .preclose = exynos_drm_preclose,
  300. .lastclose = exynos_drm_lastclose,
  301. .postclose = exynos_drm_postclose,
  302. .get_vblank_counter = drm_vblank_no_hw_counter,
  303. .enable_vblank = exynos_drm_crtc_enable_vblank,
  304. .disable_vblank = exynos_drm_crtc_disable_vblank,
  305. .gem_free_object_unlocked = exynos_drm_gem_free_object,
  306. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  307. .dumb_create = exynos_drm_gem_dumb_create,
  308. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  309. .dumb_destroy = drm_gem_dumb_destroy,
  310. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  311. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  312. .gem_prime_export = drm_gem_prime_export,
  313. .gem_prime_import = drm_gem_prime_import,
  314. .gem_prime_get_sg_table = exynos_drm_gem_prime_get_sg_table,
  315. .gem_prime_import_sg_table = exynos_drm_gem_prime_import_sg_table,
  316. .gem_prime_vmap = exynos_drm_gem_prime_vmap,
  317. .gem_prime_vunmap = exynos_drm_gem_prime_vunmap,
  318. .gem_prime_mmap = exynos_drm_gem_prime_mmap,
  319. .ioctls = exynos_ioctls,
  320. .num_ioctls = ARRAY_SIZE(exynos_ioctls),
  321. .fops = &exynos_drm_driver_fops,
  322. .name = DRIVER_NAME,
  323. .desc = DRIVER_DESC,
  324. .date = DRIVER_DATE,
  325. .major = DRIVER_MAJOR,
  326. .minor = DRIVER_MINOR,
  327. };
  328. #ifdef CONFIG_PM_SLEEP
  329. static int exynos_drm_suspend(struct device *dev)
  330. {
  331. struct drm_device *drm_dev = dev_get_drvdata(dev);
  332. struct drm_connector *connector;
  333. if (pm_runtime_suspended(dev) || !drm_dev)
  334. return 0;
  335. drm_modeset_lock_all(drm_dev);
  336. drm_for_each_connector(connector, drm_dev) {
  337. int old_dpms = connector->dpms;
  338. if (connector->funcs->dpms)
  339. connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
  340. /* Set the old mode back to the connector for resume */
  341. connector->dpms = old_dpms;
  342. }
  343. drm_modeset_unlock_all(drm_dev);
  344. return 0;
  345. }
  346. static int exynos_drm_resume(struct device *dev)
  347. {
  348. struct drm_device *drm_dev = dev_get_drvdata(dev);
  349. struct drm_connector *connector;
  350. if (pm_runtime_suspended(dev) || !drm_dev)
  351. return 0;
  352. drm_modeset_lock_all(drm_dev);
  353. drm_for_each_connector(connector, drm_dev) {
  354. if (connector->funcs->dpms) {
  355. int dpms = connector->dpms;
  356. connector->dpms = DRM_MODE_DPMS_OFF;
  357. connector->funcs->dpms(connector, dpms);
  358. }
  359. }
  360. drm_modeset_unlock_all(drm_dev);
  361. return 0;
  362. }
  363. #endif
  364. static const struct dev_pm_ops exynos_drm_pm_ops = {
  365. SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_suspend, exynos_drm_resume)
  366. };
  367. /* forward declaration */
  368. static struct platform_driver exynos_drm_platform_driver;
  369. struct exynos_drm_driver_info {
  370. struct platform_driver *driver;
  371. unsigned int flags;
  372. };
  373. #define DRM_COMPONENT_DRIVER BIT(0) /* supports component framework */
  374. #define DRM_VIRTUAL_DEVICE BIT(1) /* create virtual platform device */
  375. #define DRM_DMA_DEVICE BIT(2) /* can be used for dma allocations */
  376. #define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
  377. /*
  378. * Connector drivers should not be placed before associated crtc drivers,
  379. * because connector requires pipe number of its crtc during initialization.
  380. */
  381. static struct exynos_drm_driver_info exynos_drm_drivers[] = {
  382. {
  383. DRV_PTR(fimd_driver, CONFIG_DRM_EXYNOS_FIMD),
  384. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  385. }, {
  386. DRV_PTR(exynos5433_decon_driver, CONFIG_DRM_EXYNOS5433_DECON),
  387. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  388. }, {
  389. DRV_PTR(decon_driver, CONFIG_DRM_EXYNOS7_DECON),
  390. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  391. }, {
  392. DRV_PTR(mixer_driver, CONFIG_DRM_EXYNOS_MIXER),
  393. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  394. }, {
  395. DRV_PTR(mic_driver, CONFIG_DRM_EXYNOS_MIC),
  396. DRM_COMPONENT_DRIVER
  397. }, {
  398. DRV_PTR(dp_driver, CONFIG_DRM_EXYNOS_DP),
  399. DRM_COMPONENT_DRIVER
  400. }, {
  401. DRV_PTR(dsi_driver, CONFIG_DRM_EXYNOS_DSI),
  402. DRM_COMPONENT_DRIVER
  403. }, {
  404. DRV_PTR(hdmi_driver, CONFIG_DRM_EXYNOS_HDMI),
  405. DRM_COMPONENT_DRIVER
  406. }, {
  407. DRV_PTR(vidi_driver, CONFIG_DRM_EXYNOS_VIDI),
  408. DRM_COMPONENT_DRIVER | DRM_VIRTUAL_DEVICE
  409. }, {
  410. DRV_PTR(g2d_driver, CONFIG_DRM_EXYNOS_G2D),
  411. }, {
  412. DRV_PTR(fimc_driver, CONFIG_DRM_EXYNOS_FIMC),
  413. }, {
  414. DRV_PTR(rotator_driver, CONFIG_DRM_EXYNOS_ROTATOR),
  415. }, {
  416. DRV_PTR(gsc_driver, CONFIG_DRM_EXYNOS_GSC),
  417. }, {
  418. DRV_PTR(ipp_driver, CONFIG_DRM_EXYNOS_IPP),
  419. DRM_VIRTUAL_DEVICE
  420. }, {
  421. &exynos_drm_platform_driver,
  422. DRM_VIRTUAL_DEVICE
  423. }
  424. };
  425. static int compare_dev(struct device *dev, void *data)
  426. {
  427. return dev == (struct device *)data;
  428. }
  429. static struct component_match *exynos_drm_match_add(struct device *dev)
  430. {
  431. struct component_match *match = NULL;
  432. int i;
  433. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  434. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  435. struct device *p = NULL, *d;
  436. if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
  437. continue;
  438. while ((d = bus_find_device(&platform_bus_type, p,
  439. &info->driver->driver,
  440. (void *)platform_bus_type.match))) {
  441. put_device(p);
  442. component_match_add(dev, &match, compare_dev, d);
  443. p = d;
  444. }
  445. put_device(p);
  446. }
  447. return match ?: ERR_PTR(-ENODEV);
  448. }
  449. static int exynos_drm_bind(struct device *dev)
  450. {
  451. return drm_platform_init(&exynos_drm_driver, to_platform_device(dev));
  452. }
  453. static void exynos_drm_unbind(struct device *dev)
  454. {
  455. drm_put_dev(dev_get_drvdata(dev));
  456. }
  457. static const struct component_master_ops exynos_drm_ops = {
  458. .bind = exynos_drm_bind,
  459. .unbind = exynos_drm_unbind,
  460. };
  461. static int exynos_drm_platform_probe(struct platform_device *pdev)
  462. {
  463. struct component_match *match;
  464. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  465. exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
  466. match = exynos_drm_match_add(&pdev->dev);
  467. if (IS_ERR(match))
  468. return PTR_ERR(match);
  469. return component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
  470. match);
  471. }
  472. static int exynos_drm_platform_remove(struct platform_device *pdev)
  473. {
  474. component_master_del(&pdev->dev, &exynos_drm_ops);
  475. return 0;
  476. }
  477. static struct platform_driver exynos_drm_platform_driver = {
  478. .probe = exynos_drm_platform_probe,
  479. .remove = exynos_drm_platform_remove,
  480. .driver = {
  481. .name = "exynos-drm",
  482. .pm = &exynos_drm_pm_ops,
  483. },
  484. };
  485. static struct device *exynos_drm_get_dma_device(void)
  486. {
  487. int i;
  488. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  489. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  490. struct device *dev;
  491. if (!info->driver || !(info->flags & DRM_DMA_DEVICE))
  492. continue;
  493. while ((dev = bus_find_device(&platform_bus_type, NULL,
  494. &info->driver->driver,
  495. (void *)platform_bus_type.match))) {
  496. put_device(dev);
  497. return dev;
  498. }
  499. }
  500. return NULL;
  501. }
  502. static void exynos_drm_unregister_devices(void)
  503. {
  504. int i;
  505. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  506. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  507. struct device *dev;
  508. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  509. continue;
  510. while ((dev = bus_find_device(&platform_bus_type, NULL,
  511. &info->driver->driver,
  512. (void *)platform_bus_type.match))) {
  513. put_device(dev);
  514. platform_device_unregister(to_platform_device(dev));
  515. }
  516. }
  517. }
  518. static int exynos_drm_register_devices(void)
  519. {
  520. struct platform_device *pdev;
  521. int i;
  522. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  523. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  524. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  525. continue;
  526. pdev = platform_device_register_simple(
  527. info->driver->driver.name, -1, NULL, 0);
  528. if (IS_ERR(pdev))
  529. goto fail;
  530. }
  531. return 0;
  532. fail:
  533. exynos_drm_unregister_devices();
  534. return PTR_ERR(pdev);
  535. }
  536. static void exynos_drm_unregister_drivers(void)
  537. {
  538. int i;
  539. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  540. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  541. if (!info->driver)
  542. continue;
  543. platform_driver_unregister(info->driver);
  544. }
  545. }
  546. static int exynos_drm_register_drivers(void)
  547. {
  548. int i, ret;
  549. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  550. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  551. if (!info->driver)
  552. continue;
  553. ret = platform_driver_register(info->driver);
  554. if (ret)
  555. goto fail;
  556. }
  557. return 0;
  558. fail:
  559. exynos_drm_unregister_drivers();
  560. return ret;
  561. }
  562. static int exynos_drm_init(void)
  563. {
  564. int ret;
  565. ret = exynos_drm_register_devices();
  566. if (ret)
  567. return ret;
  568. ret = exynos_drm_register_drivers();
  569. if (ret)
  570. goto err_unregister_pdevs;
  571. return 0;
  572. err_unregister_pdevs:
  573. exynos_drm_unregister_devices();
  574. return ret;
  575. }
  576. static void exynos_drm_exit(void)
  577. {
  578. exynos_drm_unregister_drivers();
  579. exynos_drm_unregister_devices();
  580. }
  581. module_init(exynos_drm_init);
  582. module_exit(exynos_drm_exit);
  583. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  584. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  585. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  586. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  587. MODULE_LICENSE("GPL");