omap_drv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_drv.c
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/sys_soc.h>
  20. #include <drm/drm_atomic.h>
  21. #include <drm/drm_atomic_helper.h>
  22. #include <drm/drm_crtc_helper.h>
  23. #include <drm/drm_fb_helper.h>
  24. #include "omap_dmm_tiler.h"
  25. #include "omap_drv.h"
  26. #define DRIVER_NAME MODULE_NAME
  27. #define DRIVER_DESC "OMAP DRM"
  28. #define DRIVER_DATE "20110917"
  29. #define DRIVER_MAJOR 1
  30. #define DRIVER_MINOR 0
  31. #define DRIVER_PATCHLEVEL 0
  32. /*
  33. * mode config funcs
  34. */
  35. /* Notes about mapping DSS and DRM entities:
  36. * CRTC: overlay
  37. * encoder: manager.. with some extension to allow one primary CRTC
  38. * and zero or more video CRTC's to be mapped to one encoder?
  39. * connector: dssdev.. manager can be attached/detached from different
  40. * devices
  41. */
  42. static void omap_atomic_wait_for_completion(struct drm_device *dev,
  43. struct drm_atomic_state *old_state)
  44. {
  45. struct drm_crtc_state *new_crtc_state;
  46. struct drm_crtc *crtc;
  47. unsigned int i;
  48. int ret;
  49. for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) {
  50. if (!new_crtc_state->active)
  51. continue;
  52. ret = omap_crtc_wait_pending(crtc);
  53. if (!ret)
  54. dev_warn(dev->dev,
  55. "atomic complete timeout (pipe %u)!\n", i);
  56. }
  57. }
  58. static void omap_atomic_commit_tail(struct drm_atomic_state *old_state)
  59. {
  60. struct drm_device *dev = old_state->dev;
  61. struct omap_drm_private *priv = dev->dev_private;
  62. priv->dispc_ops->runtime_get();
  63. /* Apply the atomic update. */
  64. drm_atomic_helper_commit_modeset_disables(dev, old_state);
  65. if (priv->omaprev != 0x3430) {
  66. /* With the current dss dispc implementation we have to enable
  67. * the new modeset before we can commit planes. The dispc ovl
  68. * configuration relies on the video mode configuration been
  69. * written into the HW when the ovl configuration is
  70. * calculated.
  71. *
  72. * This approach is not ideal because after a mode change the
  73. * plane update is executed only after the first vblank
  74. * interrupt. The dispc implementation should be fixed so that
  75. * it is able use uncommitted drm state information.
  76. */
  77. drm_atomic_helper_commit_modeset_enables(dev, old_state);
  78. omap_atomic_wait_for_completion(dev, old_state);
  79. drm_atomic_helper_commit_planes(dev, old_state, 0);
  80. drm_atomic_helper_commit_hw_done(old_state);
  81. } else {
  82. /*
  83. * OMAP3 DSS seems to have issues with the work-around above,
  84. * resulting in endless sync losts if a crtc is enabled without
  85. * a plane. For now, skip the WA for OMAP3.
  86. */
  87. drm_atomic_helper_commit_planes(dev, old_state, 0);
  88. drm_atomic_helper_commit_modeset_enables(dev, old_state);
  89. drm_atomic_helper_commit_hw_done(old_state);
  90. }
  91. /*
  92. * Wait for completion of the page flips to ensure that old buffers
  93. * can't be touched by the hardware anymore before cleaning up planes.
  94. */
  95. omap_atomic_wait_for_completion(dev, old_state);
  96. drm_atomic_helper_cleanup_planes(dev, old_state);
  97. priv->dispc_ops->runtime_put();
  98. }
  99. static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = {
  100. .atomic_commit_tail = omap_atomic_commit_tail,
  101. };
  102. static const struct drm_mode_config_funcs omap_mode_config_funcs = {
  103. .fb_create = omap_framebuffer_create,
  104. .output_poll_changed = drm_fb_helper_output_poll_changed,
  105. .atomic_check = drm_atomic_helper_check,
  106. .atomic_commit = drm_atomic_helper_commit,
  107. };
  108. static int get_connector_type(struct omap_dss_device *dssdev)
  109. {
  110. switch (dssdev->type) {
  111. case OMAP_DISPLAY_TYPE_HDMI:
  112. return DRM_MODE_CONNECTOR_HDMIA;
  113. case OMAP_DISPLAY_TYPE_DVI:
  114. return DRM_MODE_CONNECTOR_DVID;
  115. case OMAP_DISPLAY_TYPE_DSI:
  116. return DRM_MODE_CONNECTOR_DSI;
  117. case OMAP_DISPLAY_TYPE_DPI:
  118. case OMAP_DISPLAY_TYPE_DBI:
  119. return DRM_MODE_CONNECTOR_DPI;
  120. case OMAP_DISPLAY_TYPE_VENC:
  121. /* TODO: This could also be composite */
  122. return DRM_MODE_CONNECTOR_SVIDEO;
  123. case OMAP_DISPLAY_TYPE_SDI:
  124. return DRM_MODE_CONNECTOR_LVDS;
  125. default:
  126. return DRM_MODE_CONNECTOR_Unknown;
  127. }
  128. }
  129. static void omap_disconnect_dssdevs(void)
  130. {
  131. struct omap_dss_device *dssdev = NULL;
  132. for_each_dss_dev(dssdev)
  133. dssdev->driver->disconnect(dssdev);
  134. }
  135. static int omap_connect_dssdevs(void)
  136. {
  137. int r;
  138. struct omap_dss_device *dssdev = NULL;
  139. if (!omapdss_stack_is_ready())
  140. return -EPROBE_DEFER;
  141. for_each_dss_dev(dssdev) {
  142. r = dssdev->driver->connect(dssdev);
  143. if (r == -EPROBE_DEFER) {
  144. omap_dss_put_device(dssdev);
  145. goto cleanup;
  146. } else if (r) {
  147. dev_warn(dssdev->dev, "could not connect display: %s\n",
  148. dssdev->name);
  149. }
  150. }
  151. return 0;
  152. cleanup:
  153. /*
  154. * if we are deferring probe, we disconnect the devices we previously
  155. * connected
  156. */
  157. omap_disconnect_dssdevs();
  158. return r;
  159. }
  160. static int omap_modeset_init_properties(struct drm_device *dev)
  161. {
  162. struct omap_drm_private *priv = dev->dev_private;
  163. unsigned int num_planes = priv->dispc_ops->get_num_ovls();
  164. priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0,
  165. num_planes - 1);
  166. if (!priv->zorder_prop)
  167. return -ENOMEM;
  168. return 0;
  169. }
  170. static int omap_modeset_init(struct drm_device *dev)
  171. {
  172. struct omap_drm_private *priv = dev->dev_private;
  173. struct omap_dss_device *dssdev = NULL;
  174. int num_ovls = priv->dispc_ops->get_num_ovls();
  175. int num_mgrs = priv->dispc_ops->get_num_mgrs();
  176. int num_crtcs, crtc_idx, plane_idx;
  177. int ret;
  178. u32 plane_crtc_mask;
  179. drm_mode_config_init(dev);
  180. ret = omap_modeset_init_properties(dev);
  181. if (ret < 0)
  182. return ret;
  183. /*
  184. * This function creates exactly one connector, encoder, crtc,
  185. * and primary plane per each connected dss-device. Each
  186. * connector->encoder->crtc chain is expected to be separate
  187. * and each crtc is connect to a single dss-channel. If the
  188. * configuration does not match the expectations or exceeds
  189. * the available resources, the configuration is rejected.
  190. */
  191. num_crtcs = 0;
  192. for_each_dss_dev(dssdev)
  193. if (omapdss_device_is_connected(dssdev))
  194. num_crtcs++;
  195. if (num_crtcs > num_mgrs || num_crtcs > num_ovls ||
  196. num_crtcs > ARRAY_SIZE(priv->crtcs) ||
  197. num_crtcs > ARRAY_SIZE(priv->planes) ||
  198. num_crtcs > ARRAY_SIZE(priv->encoders) ||
  199. num_crtcs > ARRAY_SIZE(priv->connectors)) {
  200. dev_err(dev->dev, "%s(): Too many connected displays\n",
  201. __func__);
  202. return -EINVAL;
  203. }
  204. /* All planes can be put to any CRTC */
  205. plane_crtc_mask = (1 << num_crtcs) - 1;
  206. dssdev = NULL;
  207. crtc_idx = 0;
  208. plane_idx = 0;
  209. for_each_dss_dev(dssdev) {
  210. struct drm_connector *connector;
  211. struct drm_encoder *encoder;
  212. struct drm_plane *plane;
  213. struct drm_crtc *crtc;
  214. if (!omapdss_device_is_connected(dssdev))
  215. continue;
  216. encoder = omap_encoder_init(dev, dssdev);
  217. if (!encoder)
  218. return -ENOMEM;
  219. connector = omap_connector_init(dev,
  220. get_connector_type(dssdev), dssdev, encoder);
  221. if (!connector)
  222. return -ENOMEM;
  223. plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_PRIMARY,
  224. plane_crtc_mask);
  225. if (IS_ERR(plane))
  226. return PTR_ERR(plane);
  227. crtc = omap_crtc_init(dev, plane, dssdev);
  228. if (IS_ERR(crtc))
  229. return PTR_ERR(crtc);
  230. drm_mode_connector_attach_encoder(connector, encoder);
  231. encoder->possible_crtcs = (1 << crtc_idx);
  232. priv->crtcs[priv->num_crtcs++] = crtc;
  233. priv->planes[priv->num_planes++] = plane;
  234. priv->encoders[priv->num_encoders++] = encoder;
  235. priv->connectors[priv->num_connectors++] = connector;
  236. plane_idx++;
  237. crtc_idx++;
  238. }
  239. /*
  240. * Create normal planes for the remaining overlays:
  241. */
  242. for (; plane_idx < num_ovls; plane_idx++) {
  243. struct drm_plane *plane;
  244. if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)))
  245. return -EINVAL;
  246. plane = omap_plane_init(dev, plane_idx, DRM_PLANE_TYPE_OVERLAY,
  247. plane_crtc_mask);
  248. if (IS_ERR(plane))
  249. return PTR_ERR(plane);
  250. priv->planes[priv->num_planes++] = plane;
  251. }
  252. DBG("registered %d planes, %d crtcs, %d encoders and %d connectors\n",
  253. priv->num_planes, priv->num_crtcs, priv->num_encoders,
  254. priv->num_connectors);
  255. dev->mode_config.min_width = 8;
  256. dev->mode_config.min_height = 2;
  257. /* note: eventually will need some cpu_is_omapXYZ() type stuff here
  258. * to fill in these limits properly on different OMAP generations..
  259. */
  260. dev->mode_config.max_width = 2048;
  261. dev->mode_config.max_height = 2048;
  262. dev->mode_config.funcs = &omap_mode_config_funcs;
  263. dev->mode_config.helper_private = &omap_mode_config_helper_funcs;
  264. drm_mode_config_reset(dev);
  265. omap_drm_irq_install(dev);
  266. return 0;
  267. }
  268. /*
  269. * Enable the HPD in external components if supported
  270. */
  271. static void omap_modeset_enable_external_hpd(void)
  272. {
  273. struct omap_dss_device *dssdev = NULL;
  274. for_each_dss_dev(dssdev) {
  275. if (dssdev->driver->enable_hpd)
  276. dssdev->driver->enable_hpd(dssdev);
  277. }
  278. }
  279. /*
  280. * Disable the HPD in external components if supported
  281. */
  282. static void omap_modeset_disable_external_hpd(void)
  283. {
  284. struct omap_dss_device *dssdev = NULL;
  285. for_each_dss_dev(dssdev) {
  286. if (dssdev->driver->disable_hpd)
  287. dssdev->driver->disable_hpd(dssdev);
  288. }
  289. }
  290. /*
  291. * drm ioctl funcs
  292. */
  293. static int ioctl_get_param(struct drm_device *dev, void *data,
  294. struct drm_file *file_priv)
  295. {
  296. struct omap_drm_private *priv = dev->dev_private;
  297. struct drm_omap_param *args = data;
  298. DBG("%p: param=%llu", dev, args->param);
  299. switch (args->param) {
  300. case OMAP_PARAM_CHIPSET_ID:
  301. args->value = priv->omaprev;
  302. break;
  303. default:
  304. DBG("unknown parameter %lld", args->param);
  305. return -EINVAL;
  306. }
  307. return 0;
  308. }
  309. static int ioctl_set_param(struct drm_device *dev, void *data,
  310. struct drm_file *file_priv)
  311. {
  312. struct drm_omap_param *args = data;
  313. switch (args->param) {
  314. default:
  315. DBG("unknown parameter %lld", args->param);
  316. return -EINVAL;
  317. }
  318. return 0;
  319. }
  320. #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */
  321. static int ioctl_gem_new(struct drm_device *dev, void *data,
  322. struct drm_file *file_priv)
  323. {
  324. struct drm_omap_gem_new *args = data;
  325. u32 flags = args->flags & OMAP_BO_USER_MASK;
  326. VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv,
  327. args->size.bytes, flags);
  328. return omap_gem_new_handle(dev, file_priv, args->size, flags,
  329. &args->handle);
  330. }
  331. static int ioctl_gem_info(struct drm_device *dev, void *data,
  332. struct drm_file *file_priv)
  333. {
  334. struct drm_omap_gem_info *args = data;
  335. struct drm_gem_object *obj;
  336. int ret = 0;
  337. VERB("%p:%p: handle=%d", dev, file_priv, args->handle);
  338. obj = drm_gem_object_lookup(file_priv, args->handle);
  339. if (!obj)
  340. return -ENOENT;
  341. args->size = omap_gem_mmap_size(obj);
  342. args->offset = omap_gem_mmap_offset(obj);
  343. drm_gem_object_unreference_unlocked(obj);
  344. return ret;
  345. }
  346. static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = {
  347. DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param,
  348. DRM_AUTH | DRM_RENDER_ALLOW),
  349. DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param,
  350. DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
  351. DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new,
  352. DRM_AUTH | DRM_RENDER_ALLOW),
  353. /* Deprecated, to be removed. */
  354. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop,
  355. DRM_AUTH | DRM_RENDER_ALLOW),
  356. /* Deprecated, to be removed. */
  357. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop,
  358. DRM_AUTH | DRM_RENDER_ALLOW),
  359. DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info,
  360. DRM_AUTH | DRM_RENDER_ALLOW),
  361. };
  362. /*
  363. * drm driver funcs
  364. */
  365. static int dev_open(struct drm_device *dev, struct drm_file *file)
  366. {
  367. file->driver_priv = NULL;
  368. DBG("open: dev=%p, file=%p", dev, file);
  369. return 0;
  370. }
  371. static const struct vm_operations_struct omap_gem_vm_ops = {
  372. .fault = omap_gem_fault,
  373. .open = drm_gem_vm_open,
  374. .close = drm_gem_vm_close,
  375. };
  376. static const struct file_operations omapdriver_fops = {
  377. .owner = THIS_MODULE,
  378. .open = drm_open,
  379. .unlocked_ioctl = drm_ioctl,
  380. .compat_ioctl = drm_compat_ioctl,
  381. .release = drm_release,
  382. .mmap = omap_gem_mmap,
  383. .poll = drm_poll,
  384. .read = drm_read,
  385. .llseek = noop_llseek,
  386. };
  387. static struct drm_driver omap_drm_driver = {
  388. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
  389. DRIVER_ATOMIC | DRIVER_RENDER,
  390. .open = dev_open,
  391. .lastclose = drm_fb_helper_lastclose,
  392. #ifdef CONFIG_DEBUG_FS
  393. .debugfs_init = omap_debugfs_init,
  394. #endif
  395. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  396. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  397. .gem_prime_export = omap_gem_prime_export,
  398. .gem_prime_import = omap_gem_prime_import,
  399. .gem_free_object = omap_gem_free_object,
  400. .gem_vm_ops = &omap_gem_vm_ops,
  401. .dumb_create = omap_gem_dumb_create,
  402. .dumb_map_offset = omap_gem_dumb_map_offset,
  403. .ioctls = ioctls,
  404. .num_ioctls = DRM_OMAP_NUM_IOCTLS,
  405. .fops = &omapdriver_fops,
  406. .name = DRIVER_NAME,
  407. .desc = DRIVER_DESC,
  408. .date = DRIVER_DATE,
  409. .major = DRIVER_MAJOR,
  410. .minor = DRIVER_MINOR,
  411. .patchlevel = DRIVER_PATCHLEVEL,
  412. };
  413. static const struct soc_device_attribute omapdrm_soc_devices[] = {
  414. { .family = "OMAP3", .data = (void *)0x3430 },
  415. { .family = "OMAP4", .data = (void *)0x4430 },
  416. { .family = "OMAP5", .data = (void *)0x5430 },
  417. { .family = "DRA7", .data = (void *)0x0752 },
  418. { /* sentinel */ }
  419. };
  420. static int pdev_probe(struct platform_device *pdev)
  421. {
  422. const struct soc_device_attribute *soc;
  423. struct omap_drm_private *priv;
  424. struct drm_device *ddev;
  425. unsigned int i;
  426. int ret;
  427. DBG("%s", pdev->name);
  428. if (omapdss_is_initialized() == false)
  429. return -EPROBE_DEFER;
  430. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  431. if (ret) {
  432. dev_err(&pdev->dev, "Failed to set the DMA mask\n");
  433. return ret;
  434. }
  435. omap_crtc_pre_init();
  436. ret = omap_connect_dssdevs();
  437. if (ret)
  438. goto err_crtc_uninit;
  439. /* Allocate and initialize the driver private structure. */
  440. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  441. if (!priv) {
  442. ret = -ENOMEM;
  443. goto err_disconnect_dssdevs;
  444. }
  445. priv->dispc_ops = dispc_get_ops();
  446. soc = soc_device_match(omapdrm_soc_devices);
  447. priv->omaprev = soc ? (unsigned int)soc->data : 0;
  448. priv->wq = alloc_ordered_workqueue("omapdrm", 0);
  449. spin_lock_init(&priv->list_lock);
  450. INIT_LIST_HEAD(&priv->obj_list);
  451. /* Allocate and initialize the DRM device. */
  452. ddev = drm_dev_alloc(&omap_drm_driver, &pdev->dev);
  453. if (IS_ERR(ddev)) {
  454. ret = PTR_ERR(ddev);
  455. goto err_free_priv;
  456. }
  457. ddev->dev_private = priv;
  458. platform_set_drvdata(pdev, ddev);
  459. omap_gem_init(ddev);
  460. ret = omap_modeset_init(ddev);
  461. if (ret) {
  462. dev_err(&pdev->dev, "omap_modeset_init failed: ret=%d\n", ret);
  463. goto err_free_drm_dev;
  464. }
  465. /* Initialize vblank handling, start with all CRTCs disabled. */
  466. ret = drm_vblank_init(ddev, priv->num_crtcs);
  467. if (ret) {
  468. dev_err(&pdev->dev, "could not init vblank\n");
  469. goto err_cleanup_modeset;
  470. }
  471. for (i = 0; i < priv->num_crtcs; i++)
  472. drm_crtc_vblank_off(priv->crtcs[i]);
  473. priv->fbdev = omap_fbdev_init(ddev);
  474. drm_kms_helper_poll_init(ddev);
  475. omap_modeset_enable_external_hpd();
  476. /*
  477. * Register the DRM device with the core and the connectors with
  478. * sysfs.
  479. */
  480. ret = drm_dev_register(ddev, 0);
  481. if (ret)
  482. goto err_cleanup_helpers;
  483. return 0;
  484. err_cleanup_helpers:
  485. omap_modeset_disable_external_hpd();
  486. drm_kms_helper_poll_fini(ddev);
  487. if (priv->fbdev)
  488. omap_fbdev_free(ddev);
  489. err_cleanup_modeset:
  490. drm_mode_config_cleanup(ddev);
  491. omap_drm_irq_uninstall(ddev);
  492. err_free_drm_dev:
  493. omap_gem_deinit(ddev);
  494. drm_dev_unref(ddev);
  495. err_free_priv:
  496. destroy_workqueue(priv->wq);
  497. kfree(priv);
  498. err_disconnect_dssdevs:
  499. omap_disconnect_dssdevs();
  500. err_crtc_uninit:
  501. omap_crtc_pre_uninit();
  502. return ret;
  503. }
  504. static int pdev_remove(struct platform_device *pdev)
  505. {
  506. struct drm_device *ddev = platform_get_drvdata(pdev);
  507. struct omap_drm_private *priv = ddev->dev_private;
  508. DBG("");
  509. drm_dev_unregister(ddev);
  510. omap_modeset_disable_external_hpd();
  511. drm_kms_helper_poll_fini(ddev);
  512. if (priv->fbdev)
  513. omap_fbdev_free(ddev);
  514. drm_atomic_helper_shutdown(ddev);
  515. drm_mode_config_cleanup(ddev);
  516. omap_drm_irq_uninstall(ddev);
  517. omap_gem_deinit(ddev);
  518. drm_dev_unref(ddev);
  519. destroy_workqueue(priv->wq);
  520. kfree(priv);
  521. omap_disconnect_dssdevs();
  522. omap_crtc_pre_uninit();
  523. return 0;
  524. }
  525. #ifdef CONFIG_PM_SLEEP
  526. static int omap_drm_suspend_all_displays(void)
  527. {
  528. struct omap_dss_device *dssdev = NULL;
  529. for_each_dss_dev(dssdev) {
  530. if (!dssdev->driver)
  531. continue;
  532. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  533. dssdev->driver->disable(dssdev);
  534. dssdev->activate_after_resume = true;
  535. } else {
  536. dssdev->activate_after_resume = false;
  537. }
  538. }
  539. return 0;
  540. }
  541. static int omap_drm_resume_all_displays(void)
  542. {
  543. struct omap_dss_device *dssdev = NULL;
  544. for_each_dss_dev(dssdev) {
  545. if (!dssdev->driver)
  546. continue;
  547. if (dssdev->activate_after_resume) {
  548. dssdev->driver->enable(dssdev);
  549. dssdev->activate_after_resume = false;
  550. }
  551. }
  552. return 0;
  553. }
  554. static int omap_drm_suspend(struct device *dev)
  555. {
  556. struct drm_device *drm_dev = dev_get_drvdata(dev);
  557. drm_kms_helper_poll_disable(drm_dev);
  558. drm_modeset_lock_all(drm_dev);
  559. omap_drm_suspend_all_displays();
  560. drm_modeset_unlock_all(drm_dev);
  561. return 0;
  562. }
  563. static int omap_drm_resume(struct device *dev)
  564. {
  565. struct drm_device *drm_dev = dev_get_drvdata(dev);
  566. drm_modeset_lock_all(drm_dev);
  567. omap_drm_resume_all_displays();
  568. drm_modeset_unlock_all(drm_dev);
  569. drm_kms_helper_poll_enable(drm_dev);
  570. return omap_gem_resume(dev);
  571. }
  572. #endif
  573. static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume);
  574. static struct platform_driver pdev = {
  575. .driver = {
  576. .name = "omapdrm",
  577. .pm = &omapdrm_pm_ops,
  578. },
  579. .probe = pdev_probe,
  580. .remove = pdev_remove,
  581. };
  582. static struct platform_driver * const drivers[] = {
  583. &omap_dmm_driver,
  584. &pdev,
  585. };
  586. static int __init omap_drm_init(void)
  587. {
  588. DBG("init");
  589. return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  590. }
  591. static void __exit omap_drm_fini(void)
  592. {
  593. DBG("fini");
  594. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  595. }
  596. /* need late_initcall() so we load after dss_driver's are loaded */
  597. late_initcall(omap_drm_init);
  598. module_exit(omap_drm_fini);
  599. MODULE_AUTHOR("Rob Clark <rob@ti.com>");
  600. MODULE_DESCRIPTION("OMAP DRM Display Driver");
  601. MODULE_ALIAS("platform:" DRIVER_NAME);
  602. MODULE_LICENSE("GPL v2");