exynos_drm_drv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 void 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. }
  159. static int commit_is_pending(struct exynos_drm_private *priv, u32 crtcs)
  160. {
  161. bool pending;
  162. spin_lock(&priv->lock);
  163. pending = priv->pending & crtcs;
  164. spin_unlock(&priv->lock);
  165. return pending;
  166. }
  167. int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
  168. bool nonblock)
  169. {
  170. struct exynos_drm_private *priv = dev->dev_private;
  171. struct exynos_atomic_commit *commit;
  172. struct drm_crtc *crtc;
  173. struct drm_crtc_state *crtc_state;
  174. int i, ret;
  175. commit = kzalloc(sizeof(*commit), GFP_KERNEL);
  176. if (!commit)
  177. return -ENOMEM;
  178. ret = drm_atomic_helper_prepare_planes(dev, state);
  179. if (ret) {
  180. kfree(commit);
  181. return ret;
  182. }
  183. /* This is the point of no return */
  184. INIT_WORK(&commit->work, exynos_drm_atomic_work);
  185. commit->dev = dev;
  186. commit->state = state;
  187. /* Wait until all affected CRTCs have completed previous commits and
  188. * mark them as pending.
  189. */
  190. for_each_crtc_in_state(state, crtc, crtc_state, i)
  191. commit->crtcs |= drm_crtc_mask(crtc);
  192. wait_event(priv->wait, !commit_is_pending(priv, commit->crtcs));
  193. spin_lock(&priv->lock);
  194. priv->pending |= commit->crtcs;
  195. spin_unlock(&priv->lock);
  196. drm_atomic_helper_swap_state(state, true);
  197. drm_atomic_state_get(state);
  198. if (nonblock)
  199. schedule_work(&commit->work);
  200. else
  201. exynos_atomic_commit_complete(commit);
  202. return 0;
  203. }
  204. int exynos_atomic_check(struct drm_device *dev,
  205. struct drm_atomic_state *state)
  206. {
  207. int ret;
  208. ret = drm_atomic_helper_check_modeset(dev, state);
  209. if (ret)
  210. return ret;
  211. ret = drm_atomic_normalize_zpos(dev, state);
  212. if (ret)
  213. return ret;
  214. ret = drm_atomic_helper_check_planes(dev, state);
  215. if (ret)
  216. return ret;
  217. return ret;
  218. }
  219. static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
  220. {
  221. struct drm_exynos_file_private *file_priv;
  222. int ret;
  223. file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
  224. if (!file_priv)
  225. return -ENOMEM;
  226. file->driver_priv = file_priv;
  227. ret = exynos_drm_subdrv_open(dev, file);
  228. if (ret)
  229. goto err_file_priv_free;
  230. return ret;
  231. err_file_priv_free:
  232. kfree(file_priv);
  233. file->driver_priv = NULL;
  234. return ret;
  235. }
  236. static void exynos_drm_preclose(struct drm_device *dev,
  237. struct drm_file *file)
  238. {
  239. struct drm_crtc *crtc;
  240. exynos_drm_subdrv_close(dev, file);
  241. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  242. exynos_drm_crtc_cancel_page_flip(crtc, file);
  243. }
  244. static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
  245. {
  246. kfree(file->driver_priv);
  247. file->driver_priv = NULL;
  248. }
  249. static void exynos_drm_lastclose(struct drm_device *dev)
  250. {
  251. exynos_drm_fbdev_restore_mode(dev);
  252. }
  253. static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
  254. .fault = exynos_drm_gem_fault,
  255. .open = drm_gem_vm_open,
  256. .close = drm_gem_vm_close,
  257. };
  258. static const struct drm_ioctl_desc exynos_ioctls[] = {
  259. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
  260. DRM_AUTH | DRM_RENDER_ALLOW),
  261. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MAP, exynos_drm_gem_map_ioctl,
  262. DRM_AUTH | DRM_RENDER_ALLOW),
  263. DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET, exynos_drm_gem_get_ioctl,
  264. DRM_RENDER_ALLOW),
  265. DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION, vidi_connection_ioctl,
  266. DRM_AUTH),
  267. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_GET_VER, exynos_g2d_get_ver_ioctl,
  268. DRM_AUTH | DRM_RENDER_ALLOW),
  269. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_SET_CMDLIST, exynos_g2d_set_cmdlist_ioctl,
  270. DRM_AUTH | DRM_RENDER_ALLOW),
  271. DRM_IOCTL_DEF_DRV(EXYNOS_G2D_EXEC, exynos_g2d_exec_ioctl,
  272. DRM_AUTH | DRM_RENDER_ALLOW),
  273. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_GET_PROPERTY, exynos_drm_ipp_get_property,
  274. DRM_AUTH | DRM_RENDER_ALLOW),
  275. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_SET_PROPERTY, exynos_drm_ipp_set_property,
  276. DRM_AUTH | DRM_RENDER_ALLOW),
  277. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_QUEUE_BUF, exynos_drm_ipp_queue_buf,
  278. DRM_AUTH | DRM_RENDER_ALLOW),
  279. DRM_IOCTL_DEF_DRV(EXYNOS_IPP_CMD_CTRL, exynos_drm_ipp_cmd_ctrl,
  280. DRM_AUTH | DRM_RENDER_ALLOW),
  281. };
  282. static const struct file_operations exynos_drm_driver_fops = {
  283. .owner = THIS_MODULE,
  284. .open = drm_open,
  285. .mmap = exynos_drm_gem_mmap,
  286. .poll = drm_poll,
  287. .read = drm_read,
  288. .unlocked_ioctl = drm_ioctl,
  289. .compat_ioctl = drm_compat_ioctl,
  290. .release = drm_release,
  291. };
  292. static struct drm_driver exynos_drm_driver = {
  293. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME
  294. | DRIVER_ATOMIC | DRIVER_RENDER,
  295. .load = exynos_drm_load,
  296. .unload = exynos_drm_unload,
  297. .open = exynos_drm_open,
  298. .preclose = exynos_drm_preclose,
  299. .lastclose = exynos_drm_lastclose,
  300. .postclose = exynos_drm_postclose,
  301. .get_vblank_counter = drm_vblank_no_hw_counter,
  302. .enable_vblank = exynos_drm_crtc_enable_vblank,
  303. .disable_vblank = exynos_drm_crtc_disable_vblank,
  304. .gem_free_object_unlocked = exynos_drm_gem_free_object,
  305. .gem_vm_ops = &exynos_drm_gem_vm_ops,
  306. .dumb_create = exynos_drm_gem_dumb_create,
  307. .dumb_map_offset = exynos_drm_gem_dumb_map_offset,
  308. .dumb_destroy = drm_gem_dumb_destroy,
  309. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  310. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  311. .gem_prime_export = drm_gem_prime_export,
  312. .gem_prime_import = drm_gem_prime_import,
  313. .gem_prime_get_sg_table = exynos_drm_gem_prime_get_sg_table,
  314. .gem_prime_import_sg_table = exynos_drm_gem_prime_import_sg_table,
  315. .gem_prime_vmap = exynos_drm_gem_prime_vmap,
  316. .gem_prime_vunmap = exynos_drm_gem_prime_vunmap,
  317. .gem_prime_mmap = exynos_drm_gem_prime_mmap,
  318. .ioctls = exynos_ioctls,
  319. .num_ioctls = ARRAY_SIZE(exynos_ioctls),
  320. .fops = &exynos_drm_driver_fops,
  321. .name = DRIVER_NAME,
  322. .desc = DRIVER_DESC,
  323. .date = DRIVER_DATE,
  324. .major = DRIVER_MAJOR,
  325. .minor = DRIVER_MINOR,
  326. };
  327. #ifdef CONFIG_PM_SLEEP
  328. static int exynos_drm_suspend(struct device *dev)
  329. {
  330. struct drm_device *drm_dev = dev_get_drvdata(dev);
  331. struct drm_connector *connector;
  332. if (pm_runtime_suspended(dev) || !drm_dev)
  333. return 0;
  334. drm_modeset_lock_all(drm_dev);
  335. drm_for_each_connector(connector, drm_dev) {
  336. int old_dpms = connector->dpms;
  337. if (connector->funcs->dpms)
  338. connector->funcs->dpms(connector, DRM_MODE_DPMS_OFF);
  339. /* Set the old mode back to the connector for resume */
  340. connector->dpms = old_dpms;
  341. }
  342. drm_modeset_unlock_all(drm_dev);
  343. return 0;
  344. }
  345. static int exynos_drm_resume(struct device *dev)
  346. {
  347. struct drm_device *drm_dev = dev_get_drvdata(dev);
  348. struct drm_connector *connector;
  349. if (pm_runtime_suspended(dev) || !drm_dev)
  350. return 0;
  351. drm_modeset_lock_all(drm_dev);
  352. drm_for_each_connector(connector, drm_dev) {
  353. if (connector->funcs->dpms) {
  354. int dpms = connector->dpms;
  355. connector->dpms = DRM_MODE_DPMS_OFF;
  356. connector->funcs->dpms(connector, dpms);
  357. }
  358. }
  359. drm_modeset_unlock_all(drm_dev);
  360. return 0;
  361. }
  362. #endif
  363. static const struct dev_pm_ops exynos_drm_pm_ops = {
  364. SET_SYSTEM_SLEEP_PM_OPS(exynos_drm_suspend, exynos_drm_resume)
  365. };
  366. /* forward declaration */
  367. static struct platform_driver exynos_drm_platform_driver;
  368. struct exynos_drm_driver_info {
  369. struct platform_driver *driver;
  370. unsigned int flags;
  371. };
  372. #define DRM_COMPONENT_DRIVER BIT(0) /* supports component framework */
  373. #define DRM_VIRTUAL_DEVICE BIT(1) /* create virtual platform device */
  374. #define DRM_DMA_DEVICE BIT(2) /* can be used for dma allocations */
  375. #define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
  376. /*
  377. * Connector drivers should not be placed before associated crtc drivers,
  378. * because connector requires pipe number of its crtc during initialization.
  379. */
  380. static struct exynos_drm_driver_info exynos_drm_drivers[] = {
  381. {
  382. DRV_PTR(fimd_driver, CONFIG_DRM_EXYNOS_FIMD),
  383. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  384. }, {
  385. DRV_PTR(exynos5433_decon_driver, CONFIG_DRM_EXYNOS5433_DECON),
  386. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  387. }, {
  388. DRV_PTR(decon_driver, CONFIG_DRM_EXYNOS7_DECON),
  389. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  390. }, {
  391. DRV_PTR(mixer_driver, CONFIG_DRM_EXYNOS_MIXER),
  392. DRM_COMPONENT_DRIVER | DRM_DMA_DEVICE
  393. }, {
  394. DRV_PTR(mic_driver, CONFIG_DRM_EXYNOS_MIC),
  395. DRM_COMPONENT_DRIVER
  396. }, {
  397. DRV_PTR(dp_driver, CONFIG_DRM_EXYNOS_DP),
  398. DRM_COMPONENT_DRIVER
  399. }, {
  400. DRV_PTR(dsi_driver, CONFIG_DRM_EXYNOS_DSI),
  401. DRM_COMPONENT_DRIVER
  402. }, {
  403. DRV_PTR(hdmi_driver, CONFIG_DRM_EXYNOS_HDMI),
  404. DRM_COMPONENT_DRIVER
  405. }, {
  406. DRV_PTR(vidi_driver, CONFIG_DRM_EXYNOS_VIDI),
  407. DRM_COMPONENT_DRIVER | DRM_VIRTUAL_DEVICE
  408. }, {
  409. DRV_PTR(g2d_driver, CONFIG_DRM_EXYNOS_G2D),
  410. }, {
  411. DRV_PTR(fimc_driver, CONFIG_DRM_EXYNOS_FIMC),
  412. }, {
  413. DRV_PTR(rotator_driver, CONFIG_DRM_EXYNOS_ROTATOR),
  414. }, {
  415. DRV_PTR(gsc_driver, CONFIG_DRM_EXYNOS_GSC),
  416. }, {
  417. DRV_PTR(ipp_driver, CONFIG_DRM_EXYNOS_IPP),
  418. DRM_VIRTUAL_DEVICE
  419. }, {
  420. &exynos_drm_platform_driver,
  421. DRM_VIRTUAL_DEVICE
  422. }
  423. };
  424. static int compare_dev(struct device *dev, void *data)
  425. {
  426. return dev == (struct device *)data;
  427. }
  428. static struct component_match *exynos_drm_match_add(struct device *dev)
  429. {
  430. struct component_match *match = NULL;
  431. int i;
  432. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  433. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  434. struct device *p = NULL, *d;
  435. if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER))
  436. continue;
  437. while ((d = bus_find_device(&platform_bus_type, p,
  438. &info->driver->driver,
  439. (void *)platform_bus_type.match))) {
  440. put_device(p);
  441. component_match_add(dev, &match, compare_dev, d);
  442. p = d;
  443. }
  444. put_device(p);
  445. }
  446. return match ?: ERR_PTR(-ENODEV);
  447. }
  448. static int exynos_drm_bind(struct device *dev)
  449. {
  450. return drm_platform_init(&exynos_drm_driver, to_platform_device(dev));
  451. }
  452. static void exynos_drm_unbind(struct device *dev)
  453. {
  454. drm_put_dev(dev_get_drvdata(dev));
  455. }
  456. static const struct component_master_ops exynos_drm_ops = {
  457. .bind = exynos_drm_bind,
  458. .unbind = exynos_drm_unbind,
  459. };
  460. static int exynos_drm_platform_probe(struct platform_device *pdev)
  461. {
  462. struct component_match *match;
  463. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  464. exynos_drm_driver.num_ioctls = ARRAY_SIZE(exynos_ioctls);
  465. match = exynos_drm_match_add(&pdev->dev);
  466. if (IS_ERR(match))
  467. return PTR_ERR(match);
  468. return component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
  469. match);
  470. }
  471. static int exynos_drm_platform_remove(struct platform_device *pdev)
  472. {
  473. component_master_del(&pdev->dev, &exynos_drm_ops);
  474. return 0;
  475. }
  476. static struct platform_driver exynos_drm_platform_driver = {
  477. .probe = exynos_drm_platform_probe,
  478. .remove = exynos_drm_platform_remove,
  479. .driver = {
  480. .name = "exynos-drm",
  481. .pm = &exynos_drm_pm_ops,
  482. },
  483. };
  484. static struct device *exynos_drm_get_dma_device(void)
  485. {
  486. int i;
  487. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  488. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  489. struct device *dev;
  490. if (!info->driver || !(info->flags & DRM_DMA_DEVICE))
  491. continue;
  492. while ((dev = bus_find_device(&platform_bus_type, NULL,
  493. &info->driver->driver,
  494. (void *)platform_bus_type.match))) {
  495. put_device(dev);
  496. return dev;
  497. }
  498. }
  499. return NULL;
  500. }
  501. static void exynos_drm_unregister_devices(void)
  502. {
  503. int i;
  504. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  505. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  506. struct device *dev;
  507. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  508. continue;
  509. while ((dev = bus_find_device(&platform_bus_type, NULL,
  510. &info->driver->driver,
  511. (void *)platform_bus_type.match))) {
  512. put_device(dev);
  513. platform_device_unregister(to_platform_device(dev));
  514. }
  515. }
  516. }
  517. static int exynos_drm_register_devices(void)
  518. {
  519. struct platform_device *pdev;
  520. int i;
  521. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  522. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  523. if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE))
  524. continue;
  525. pdev = platform_device_register_simple(
  526. info->driver->driver.name, -1, NULL, 0);
  527. if (IS_ERR(pdev))
  528. goto fail;
  529. }
  530. return 0;
  531. fail:
  532. exynos_drm_unregister_devices();
  533. return PTR_ERR(pdev);
  534. }
  535. static void exynos_drm_unregister_drivers(void)
  536. {
  537. int i;
  538. for (i = ARRAY_SIZE(exynos_drm_drivers) - 1; i >= 0; --i) {
  539. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  540. if (!info->driver)
  541. continue;
  542. platform_driver_unregister(info->driver);
  543. }
  544. }
  545. static int exynos_drm_register_drivers(void)
  546. {
  547. int i, ret;
  548. for (i = 0; i < ARRAY_SIZE(exynos_drm_drivers); ++i) {
  549. struct exynos_drm_driver_info *info = &exynos_drm_drivers[i];
  550. if (!info->driver)
  551. continue;
  552. ret = platform_driver_register(info->driver);
  553. if (ret)
  554. goto fail;
  555. }
  556. return 0;
  557. fail:
  558. exynos_drm_unregister_drivers();
  559. return ret;
  560. }
  561. static int exynos_drm_init(void)
  562. {
  563. int ret;
  564. ret = exynos_drm_register_devices();
  565. if (ret)
  566. return ret;
  567. ret = exynos_drm_register_drivers();
  568. if (ret)
  569. goto err_unregister_pdevs;
  570. return 0;
  571. err_unregister_pdevs:
  572. exynos_drm_unregister_devices();
  573. return ret;
  574. }
  575. static void exynos_drm_exit(void)
  576. {
  577. exynos_drm_unregister_drivers();
  578. exynos_drm_unregister_devices();
  579. }
  580. module_init(exynos_drm_init);
  581. module_exit(exynos_drm_exit);
  582. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  583. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  584. MODULE_AUTHOR("Seung-Woo Kim <sw0312.kim@samsung.com>");
  585. MODULE_DESCRIPTION("Samsung SoC DRM Driver");
  586. MODULE_LICENSE("GPL");