exynos_drm_drv.c 19 KB

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