omap_drv.c 18 KB

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