exynos_drm_drv.c 19 KB

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