omap_drv.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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/of.h>
  18. #include <linux/sort.h>
  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(priv->dispc);
  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(priv->dispc);
  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 *display)
  109. {
  110. switch (display->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_pipelines(struct drm_device *ddev)
  130. {
  131. struct omap_drm_private *priv = ddev->dev_private;
  132. unsigned int i;
  133. for (i = 0; i < priv->num_pipes; i++) {
  134. struct omap_drm_pipeline *pipe = &priv->pipes[i];
  135. omapdss_device_disconnect(NULL, pipe->output);
  136. omapdss_device_put(pipe->output);
  137. omapdss_device_put(pipe->display);
  138. pipe->output = NULL;
  139. pipe->display = NULL;
  140. }
  141. memset(&priv->channels, 0, sizeof(priv->channels));
  142. priv->num_pipes = 0;
  143. }
  144. static int omap_compare_pipes(const void *a, const void *b)
  145. {
  146. const struct omap_drm_pipeline *pipe1 = a;
  147. const struct omap_drm_pipeline *pipe2 = b;
  148. if (pipe1->display->alias_id > pipe2->display->alias_id)
  149. return 1;
  150. else if (pipe1->display->alias_id < pipe2->display->alias_id)
  151. return -1;
  152. return 0;
  153. }
  154. static int omap_connect_pipelines(struct drm_device *ddev)
  155. {
  156. struct omap_drm_private *priv = ddev->dev_private;
  157. struct omap_dss_device *output = NULL;
  158. unsigned int i;
  159. int r;
  160. if (!omapdss_stack_is_ready())
  161. return -EPROBE_DEFER;
  162. for_each_dss_output(output) {
  163. r = omapdss_device_connect(priv->dss, NULL, output);
  164. if (r == -EPROBE_DEFER) {
  165. omapdss_device_put(output);
  166. goto cleanup;
  167. } else if (r) {
  168. dev_warn(output->dev, "could not connect output %s\n",
  169. output->name);
  170. } else {
  171. struct omap_drm_pipeline *pipe;
  172. pipe = &priv->pipes[priv->num_pipes++];
  173. pipe->output = omapdss_device_get(output);
  174. pipe->display = omapdss_display_get(output);
  175. if (priv->num_pipes == ARRAY_SIZE(priv->pipes)) {
  176. /* To balance the 'for_each_dss_output' loop */
  177. omapdss_device_put(output);
  178. break;
  179. }
  180. }
  181. }
  182. /* Sort the list by DT aliases */
  183. sort(priv->pipes, priv->num_pipes, sizeof(priv->pipes[0]),
  184. omap_compare_pipes, NULL);
  185. /*
  186. * Populate the pipeline lookup table by DISPC channel. Only one display
  187. * is allowed per channel.
  188. */
  189. for (i = 0; i < priv->num_pipes; ++i) {
  190. struct omap_drm_pipeline *pipe = &priv->pipes[i];
  191. enum omap_channel channel = pipe->output->dispc_channel;
  192. if (WARN_ON(priv->channels[channel] != NULL)) {
  193. r = -EINVAL;
  194. goto cleanup;
  195. }
  196. priv->channels[channel] = pipe;
  197. }
  198. return 0;
  199. cleanup:
  200. /*
  201. * if we are deferring probe, we disconnect the devices we previously
  202. * connected
  203. */
  204. omap_disconnect_pipelines(ddev);
  205. return r;
  206. }
  207. static int omap_modeset_init_properties(struct drm_device *dev)
  208. {
  209. struct omap_drm_private *priv = dev->dev_private;
  210. unsigned int num_planes = priv->dispc_ops->get_num_ovls(priv->dispc);
  211. priv->zorder_prop = drm_property_create_range(dev, 0, "zorder", 0,
  212. num_planes - 1);
  213. if (!priv->zorder_prop)
  214. return -ENOMEM;
  215. return 0;
  216. }
  217. static int omap_modeset_init(struct drm_device *dev)
  218. {
  219. struct omap_drm_private *priv = dev->dev_private;
  220. int num_ovls = priv->dispc_ops->get_num_ovls(priv->dispc);
  221. int num_mgrs = priv->dispc_ops->get_num_mgrs(priv->dispc);
  222. unsigned int i;
  223. int ret;
  224. u32 plane_crtc_mask;
  225. drm_mode_config_init(dev);
  226. ret = omap_modeset_init_properties(dev);
  227. if (ret < 0)
  228. return ret;
  229. /*
  230. * This function creates exactly one connector, encoder, crtc,
  231. * and primary plane per each connected dss-device. Each
  232. * connector->encoder->crtc chain is expected to be separate
  233. * and each crtc is connect to a single dss-channel. If the
  234. * configuration does not match the expectations or exceeds
  235. * the available resources, the configuration is rejected.
  236. */
  237. if (priv->num_pipes > num_mgrs || priv->num_pipes > num_ovls) {
  238. dev_err(dev->dev, "%s(): Too many connected displays\n",
  239. __func__);
  240. return -EINVAL;
  241. }
  242. /* Create all planes first. They can all be put to any CRTC. */
  243. plane_crtc_mask = (1 << priv->num_pipes) - 1;
  244. for (i = 0; i < num_ovls; i++) {
  245. enum drm_plane_type type = i < priv->num_pipes
  246. ? DRM_PLANE_TYPE_PRIMARY
  247. : DRM_PLANE_TYPE_OVERLAY;
  248. struct drm_plane *plane;
  249. if (WARN_ON(priv->num_planes >= ARRAY_SIZE(priv->planes)))
  250. return -EINVAL;
  251. plane = omap_plane_init(dev, i, type, plane_crtc_mask);
  252. if (IS_ERR(plane))
  253. return PTR_ERR(plane);
  254. priv->planes[priv->num_planes++] = plane;
  255. }
  256. /* Create the CRTCs, encoders and connectors. */
  257. for (i = 0; i < priv->num_pipes; i++) {
  258. struct omap_drm_pipeline *pipe = &priv->pipes[i];
  259. struct omap_dss_device *display = pipe->display;
  260. struct drm_connector *connector;
  261. struct drm_encoder *encoder;
  262. struct drm_crtc *crtc;
  263. encoder = omap_encoder_init(dev, display);
  264. if (!encoder)
  265. return -ENOMEM;
  266. connector = omap_connector_init(dev,
  267. get_connector_type(display), display, encoder);
  268. if (!connector)
  269. return -ENOMEM;
  270. crtc = omap_crtc_init(dev, pipe, priv->planes[i]);
  271. if (IS_ERR(crtc))
  272. return PTR_ERR(crtc);
  273. drm_connector_attach_encoder(connector, encoder);
  274. encoder->possible_crtcs = 1 << i;
  275. pipe->crtc = crtc;
  276. pipe->encoder = encoder;
  277. pipe->connector = connector;
  278. }
  279. DBG("registered %u planes, %u crtcs/encoders/connectors\n",
  280. priv->num_planes, priv->num_pipes);
  281. dev->mode_config.min_width = 8;
  282. dev->mode_config.min_height = 2;
  283. /*
  284. * Note: these values are used for multiple independent things:
  285. * connector mode filtering, buffer sizes, crtc sizes...
  286. * Use big enough values here to cover all use cases, and do more
  287. * specific checking in the respective code paths.
  288. */
  289. dev->mode_config.max_width = 8192;
  290. dev->mode_config.max_height = 8192;
  291. /* We want the zpos to be normalized */
  292. dev->mode_config.normalize_zpos = true;
  293. dev->mode_config.funcs = &omap_mode_config_funcs;
  294. dev->mode_config.helper_private = &omap_mode_config_helper_funcs;
  295. drm_mode_config_reset(dev);
  296. omap_drm_irq_install(dev);
  297. return 0;
  298. }
  299. /*
  300. * Enable the HPD in external components if supported
  301. */
  302. static void omap_modeset_enable_external_hpd(struct drm_device *ddev)
  303. {
  304. struct omap_drm_private *priv = ddev->dev_private;
  305. int i;
  306. for (i = 0; i < priv->num_pipes; i++)
  307. omap_connector_enable_hpd(priv->pipes[i].connector);
  308. }
  309. /*
  310. * Disable the HPD in external components if supported
  311. */
  312. static void omap_modeset_disable_external_hpd(struct drm_device *ddev)
  313. {
  314. struct omap_drm_private *priv = ddev->dev_private;
  315. int i;
  316. for (i = 0; i < priv->num_pipes; i++)
  317. omap_connector_disable_hpd(priv->pipes[i].connector);
  318. }
  319. /*
  320. * drm ioctl funcs
  321. */
  322. static int ioctl_get_param(struct drm_device *dev, void *data,
  323. struct drm_file *file_priv)
  324. {
  325. struct omap_drm_private *priv = dev->dev_private;
  326. struct drm_omap_param *args = data;
  327. DBG("%p: param=%llu", dev, args->param);
  328. switch (args->param) {
  329. case OMAP_PARAM_CHIPSET_ID:
  330. args->value = priv->omaprev;
  331. break;
  332. default:
  333. DBG("unknown parameter %lld", args->param);
  334. return -EINVAL;
  335. }
  336. return 0;
  337. }
  338. static int ioctl_set_param(struct drm_device *dev, void *data,
  339. struct drm_file *file_priv)
  340. {
  341. struct drm_omap_param *args = data;
  342. switch (args->param) {
  343. default:
  344. DBG("unknown parameter %lld", args->param);
  345. return -EINVAL;
  346. }
  347. return 0;
  348. }
  349. #define OMAP_BO_USER_MASK 0x00ffffff /* flags settable by userspace */
  350. static int ioctl_gem_new(struct drm_device *dev, void *data,
  351. struct drm_file *file_priv)
  352. {
  353. struct drm_omap_gem_new *args = data;
  354. u32 flags = args->flags & OMAP_BO_USER_MASK;
  355. VERB("%p:%p: size=0x%08x, flags=%08x", dev, file_priv,
  356. args->size.bytes, flags);
  357. return omap_gem_new_handle(dev, file_priv, args->size, flags,
  358. &args->handle);
  359. }
  360. static int ioctl_gem_info(struct drm_device *dev, void *data,
  361. struct drm_file *file_priv)
  362. {
  363. struct drm_omap_gem_info *args = data;
  364. struct drm_gem_object *obj;
  365. int ret = 0;
  366. VERB("%p:%p: handle=%d", dev, file_priv, args->handle);
  367. obj = drm_gem_object_lookup(file_priv, args->handle);
  368. if (!obj)
  369. return -ENOENT;
  370. args->size = omap_gem_mmap_size(obj);
  371. args->offset = omap_gem_mmap_offset(obj);
  372. drm_gem_object_unreference_unlocked(obj);
  373. return ret;
  374. }
  375. static const struct drm_ioctl_desc ioctls[DRM_COMMAND_END - DRM_COMMAND_BASE] = {
  376. DRM_IOCTL_DEF_DRV(OMAP_GET_PARAM, ioctl_get_param,
  377. DRM_AUTH | DRM_RENDER_ALLOW),
  378. DRM_IOCTL_DEF_DRV(OMAP_SET_PARAM, ioctl_set_param,
  379. DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY),
  380. DRM_IOCTL_DEF_DRV(OMAP_GEM_NEW, ioctl_gem_new,
  381. DRM_AUTH | DRM_RENDER_ALLOW),
  382. /* Deprecated, to be removed. */
  383. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_PREP, drm_noop,
  384. DRM_AUTH | DRM_RENDER_ALLOW),
  385. /* Deprecated, to be removed. */
  386. DRM_IOCTL_DEF_DRV(OMAP_GEM_CPU_FINI, drm_noop,
  387. DRM_AUTH | DRM_RENDER_ALLOW),
  388. DRM_IOCTL_DEF_DRV(OMAP_GEM_INFO, ioctl_gem_info,
  389. DRM_AUTH | DRM_RENDER_ALLOW),
  390. };
  391. /*
  392. * drm driver funcs
  393. */
  394. static int dev_open(struct drm_device *dev, struct drm_file *file)
  395. {
  396. file->driver_priv = NULL;
  397. DBG("open: dev=%p, file=%p", dev, file);
  398. return 0;
  399. }
  400. static const struct vm_operations_struct omap_gem_vm_ops = {
  401. .fault = omap_gem_fault,
  402. .open = drm_gem_vm_open,
  403. .close = drm_gem_vm_close,
  404. };
  405. static const struct file_operations omapdriver_fops = {
  406. .owner = THIS_MODULE,
  407. .open = drm_open,
  408. .unlocked_ioctl = drm_ioctl,
  409. .compat_ioctl = drm_compat_ioctl,
  410. .release = drm_release,
  411. .mmap = omap_gem_mmap,
  412. .poll = drm_poll,
  413. .read = drm_read,
  414. .llseek = noop_llseek,
  415. };
  416. static struct drm_driver omap_drm_driver = {
  417. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME |
  418. DRIVER_ATOMIC | DRIVER_RENDER,
  419. .open = dev_open,
  420. .lastclose = drm_fb_helper_lastclose,
  421. #ifdef CONFIG_DEBUG_FS
  422. .debugfs_init = omap_debugfs_init,
  423. #endif
  424. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  425. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  426. .gem_prime_export = omap_gem_prime_export,
  427. .gem_prime_import = omap_gem_prime_import,
  428. .gem_free_object_unlocked = omap_gem_free_object,
  429. .gem_vm_ops = &omap_gem_vm_ops,
  430. .dumb_create = omap_gem_dumb_create,
  431. .dumb_map_offset = omap_gem_dumb_map_offset,
  432. .ioctls = ioctls,
  433. .num_ioctls = DRM_OMAP_NUM_IOCTLS,
  434. .fops = &omapdriver_fops,
  435. .name = DRIVER_NAME,
  436. .desc = DRIVER_DESC,
  437. .date = DRIVER_DATE,
  438. .major = DRIVER_MAJOR,
  439. .minor = DRIVER_MINOR,
  440. .patchlevel = DRIVER_PATCHLEVEL,
  441. };
  442. static const struct soc_device_attribute omapdrm_soc_devices[] = {
  443. { .family = "OMAP3", .data = (void *)0x3430 },
  444. { .family = "OMAP4", .data = (void *)0x4430 },
  445. { .family = "OMAP5", .data = (void *)0x5430 },
  446. { .family = "DRA7", .data = (void *)0x0752 },
  447. { /* sentinel */ }
  448. };
  449. static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
  450. {
  451. const struct soc_device_attribute *soc;
  452. struct drm_device *ddev;
  453. unsigned int i;
  454. int ret;
  455. DBG("%s", dev_name(dev));
  456. /* Allocate and initialize the DRM device. */
  457. ddev = drm_dev_alloc(&omap_drm_driver, dev);
  458. if (IS_ERR(ddev))
  459. return PTR_ERR(ddev);
  460. priv->ddev = ddev;
  461. ddev->dev_private = priv;
  462. priv->dev = dev;
  463. priv->dss = omapdss_get_dss();
  464. priv->dispc = dispc_get_dispc(priv->dss);
  465. priv->dispc_ops = dispc_get_ops(priv->dss);
  466. omap_crtc_pre_init(priv);
  467. ret = omap_connect_pipelines(ddev);
  468. if (ret)
  469. goto err_crtc_uninit;
  470. soc = soc_device_match(omapdrm_soc_devices);
  471. priv->omaprev = soc ? (unsigned int)soc->data : 0;
  472. priv->wq = alloc_ordered_workqueue("omapdrm", 0);
  473. mutex_init(&priv->list_lock);
  474. INIT_LIST_HEAD(&priv->obj_list);
  475. /* Get memory bandwidth limits */
  476. if (priv->dispc_ops->get_memory_bandwidth_limit)
  477. priv->max_bandwidth =
  478. priv->dispc_ops->get_memory_bandwidth_limit(priv->dispc);
  479. omap_gem_init(ddev);
  480. ret = omap_modeset_init(ddev);
  481. if (ret) {
  482. dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
  483. goto err_gem_deinit;
  484. }
  485. /* Initialize vblank handling, start with all CRTCs disabled. */
  486. ret = drm_vblank_init(ddev, priv->num_pipes);
  487. if (ret) {
  488. dev_err(priv->dev, "could not init vblank\n");
  489. goto err_cleanup_modeset;
  490. }
  491. for (i = 0; i < priv->num_pipes; i++)
  492. drm_crtc_vblank_off(priv->pipes[i].crtc);
  493. omap_fbdev_init(ddev);
  494. drm_kms_helper_poll_init(ddev);
  495. omap_modeset_enable_external_hpd(ddev);
  496. /*
  497. * Register the DRM device with the core and the connectors with
  498. * sysfs.
  499. */
  500. ret = drm_dev_register(ddev, 0);
  501. if (ret)
  502. goto err_cleanup_helpers;
  503. return 0;
  504. err_cleanup_helpers:
  505. omap_modeset_disable_external_hpd(ddev);
  506. drm_kms_helper_poll_fini(ddev);
  507. omap_fbdev_fini(ddev);
  508. err_cleanup_modeset:
  509. drm_mode_config_cleanup(ddev);
  510. omap_drm_irq_uninstall(ddev);
  511. err_gem_deinit:
  512. omap_gem_deinit(ddev);
  513. destroy_workqueue(priv->wq);
  514. omap_disconnect_pipelines(ddev);
  515. err_crtc_uninit:
  516. omap_crtc_pre_uninit(priv);
  517. drm_dev_unref(ddev);
  518. return ret;
  519. }
  520. static void omapdrm_cleanup(struct omap_drm_private *priv)
  521. {
  522. struct drm_device *ddev = priv->ddev;
  523. DBG("");
  524. drm_dev_unregister(ddev);
  525. omap_modeset_disable_external_hpd(ddev);
  526. drm_kms_helper_poll_fini(ddev);
  527. omap_fbdev_fini(ddev);
  528. drm_atomic_helper_shutdown(ddev);
  529. drm_mode_config_cleanup(ddev);
  530. omap_drm_irq_uninstall(ddev);
  531. omap_gem_deinit(ddev);
  532. destroy_workqueue(priv->wq);
  533. omap_disconnect_pipelines(ddev);
  534. omap_crtc_pre_uninit(priv);
  535. drm_dev_unref(ddev);
  536. }
  537. static int pdev_probe(struct platform_device *pdev)
  538. {
  539. struct omap_drm_private *priv;
  540. int ret;
  541. if (omapdss_is_initialized() == false)
  542. return -EPROBE_DEFER;
  543. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  544. if (ret) {
  545. dev_err(&pdev->dev, "Failed to set the DMA mask\n");
  546. return ret;
  547. }
  548. /* Allocate and initialize the driver private structure. */
  549. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  550. if (!priv)
  551. return -ENOMEM;
  552. platform_set_drvdata(pdev, priv);
  553. ret = omapdrm_init(priv, &pdev->dev);
  554. if (ret < 0)
  555. kfree(priv);
  556. return ret;
  557. }
  558. static int pdev_remove(struct platform_device *pdev)
  559. {
  560. struct omap_drm_private *priv = platform_get_drvdata(pdev);
  561. omapdrm_cleanup(priv);
  562. kfree(priv);
  563. return 0;
  564. }
  565. #ifdef CONFIG_PM_SLEEP
  566. static int omap_drm_suspend_all_displays(struct drm_device *ddev)
  567. {
  568. struct omap_drm_private *priv = ddev->dev_private;
  569. int i;
  570. for (i = 0; i < priv->num_pipes; i++) {
  571. struct omap_dss_device *display = priv->pipes[i].display;
  572. if (display->state == OMAP_DSS_DISPLAY_ACTIVE) {
  573. display->ops->disable(display);
  574. display->activate_after_resume = true;
  575. } else {
  576. display->activate_after_resume = false;
  577. }
  578. }
  579. return 0;
  580. }
  581. static int omap_drm_resume_all_displays(struct drm_device *ddev)
  582. {
  583. struct omap_drm_private *priv = ddev->dev_private;
  584. int i;
  585. for (i = 0; i < priv->num_pipes; i++) {
  586. struct omap_dss_device *display = priv->pipes[i].display;
  587. if (display->activate_after_resume) {
  588. display->ops->enable(display);
  589. display->activate_after_resume = false;
  590. }
  591. }
  592. return 0;
  593. }
  594. static int omap_drm_suspend(struct device *dev)
  595. {
  596. struct omap_drm_private *priv = dev_get_drvdata(dev);
  597. struct drm_device *drm_dev = priv->ddev;
  598. drm_kms_helper_poll_disable(drm_dev);
  599. drm_modeset_lock_all(drm_dev);
  600. omap_drm_suspend_all_displays(drm_dev);
  601. drm_modeset_unlock_all(drm_dev);
  602. return 0;
  603. }
  604. static int omap_drm_resume(struct device *dev)
  605. {
  606. struct omap_drm_private *priv = dev_get_drvdata(dev);
  607. struct drm_device *drm_dev = priv->ddev;
  608. drm_modeset_lock_all(drm_dev);
  609. omap_drm_resume_all_displays(drm_dev);
  610. drm_modeset_unlock_all(drm_dev);
  611. drm_kms_helper_poll_enable(drm_dev);
  612. return omap_gem_resume(drm_dev);
  613. }
  614. #endif
  615. static SIMPLE_DEV_PM_OPS(omapdrm_pm_ops, omap_drm_suspend, omap_drm_resume);
  616. static struct platform_driver pdev = {
  617. .driver = {
  618. .name = "omapdrm",
  619. .pm = &omapdrm_pm_ops,
  620. },
  621. .probe = pdev_probe,
  622. .remove = pdev_remove,
  623. };
  624. static struct platform_driver * const drivers[] = {
  625. &omap_dmm_driver,
  626. &pdev,
  627. };
  628. static int __init omap_drm_init(void)
  629. {
  630. DBG("init");
  631. return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  632. }
  633. static void __exit omap_drm_fini(void)
  634. {
  635. DBG("fini");
  636. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  637. }
  638. /* need late_initcall() so we load after dss_driver's are loaded */
  639. late_initcall(omap_drm_init);
  640. module_exit(omap_drm_fini);
  641. MODULE_AUTHOR("Rob Clark <rob@ti.com>");
  642. MODULE_DESCRIPTION("OMAP DRM Display Driver");
  643. MODULE_ALIAS("platform:" DRIVER_NAME);
  644. MODULE_LICENSE("GPL v2");