imx-drm-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Freescale i.MX drm driver
  3. *
  4. * Copyright (C) 2011 Sascha Hauer, Pengutronix
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/component.h>
  17. #include <linux/device.h>
  18. #include <linux/fb.h>
  19. #include <linux/module.h>
  20. #include <linux/of_graph.h>
  21. #include <linux/platform_device.h>
  22. #include <drm/drmP.h>
  23. #include <drm/drm_fb_helper.h>
  24. #include <drm/drm_crtc_helper.h>
  25. #include <drm/drm_gem_cma_helper.h>
  26. #include <drm/drm_fb_cma_helper.h>
  27. #include <drm/drm_plane_helper.h>
  28. #include "imx-drm.h"
  29. #define MAX_CRTC 4
  30. struct imx_drm_component {
  31. struct device_node *of_node;
  32. struct list_head list;
  33. };
  34. struct imx_drm_device {
  35. struct drm_device *drm;
  36. struct imx_drm_crtc *crtc[MAX_CRTC];
  37. int pipes;
  38. struct drm_fbdev_cma *fbhelper;
  39. };
  40. struct imx_drm_crtc {
  41. struct drm_crtc *crtc;
  42. int pipe;
  43. struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
  44. struct device_node *port;
  45. };
  46. static int legacyfb_depth = 16;
  47. module_param(legacyfb_depth, int, 0444);
  48. int imx_drm_crtc_id(struct imx_drm_crtc *crtc)
  49. {
  50. return crtc->pipe;
  51. }
  52. EXPORT_SYMBOL_GPL(imx_drm_crtc_id);
  53. static void imx_drm_driver_lastclose(struct drm_device *drm)
  54. {
  55. #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
  56. struct imx_drm_device *imxdrm = drm->dev_private;
  57. if (imxdrm->fbhelper)
  58. drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
  59. #endif
  60. }
  61. static int imx_drm_driver_unload(struct drm_device *drm)
  62. {
  63. #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
  64. struct imx_drm_device *imxdrm = drm->dev_private;
  65. #endif
  66. drm_kms_helper_poll_fini(drm);
  67. #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
  68. if (imxdrm->fbhelper)
  69. drm_fbdev_cma_fini(imxdrm->fbhelper);
  70. #endif
  71. component_unbind_all(drm->dev, drm);
  72. drm_vblank_cleanup(drm);
  73. drm_mode_config_cleanup(drm);
  74. platform_set_drvdata(drm->platformdev, NULL);
  75. return 0;
  76. }
  77. static struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc)
  78. {
  79. struct imx_drm_device *imxdrm = crtc->dev->dev_private;
  80. unsigned i;
  81. for (i = 0; i < MAX_CRTC; i++)
  82. if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc)
  83. return imxdrm->crtc[i];
  84. return NULL;
  85. }
  86. int imx_drm_panel_format_pins(struct drm_encoder *encoder,
  87. u32 interface_pix_fmt, int hsync_pin, int vsync_pin)
  88. {
  89. struct imx_drm_crtc_helper_funcs *helper;
  90. struct imx_drm_crtc *imx_crtc;
  91. imx_crtc = imx_drm_find_crtc(encoder->crtc);
  92. if (!imx_crtc)
  93. return -EINVAL;
  94. helper = &imx_crtc->imx_drm_helper_funcs;
  95. if (helper->set_interface_pix_fmt)
  96. return helper->set_interface_pix_fmt(encoder->crtc,
  97. encoder->encoder_type, interface_pix_fmt,
  98. hsync_pin, vsync_pin);
  99. return 0;
  100. }
  101. EXPORT_SYMBOL_GPL(imx_drm_panel_format_pins);
  102. int imx_drm_panel_format(struct drm_encoder *encoder, u32 interface_pix_fmt)
  103. {
  104. return imx_drm_panel_format_pins(encoder, interface_pix_fmt, 2, 3);
  105. }
  106. EXPORT_SYMBOL_GPL(imx_drm_panel_format);
  107. int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc)
  108. {
  109. return drm_vblank_get(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
  110. }
  111. EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_get);
  112. void imx_drm_crtc_vblank_put(struct imx_drm_crtc *imx_drm_crtc)
  113. {
  114. drm_vblank_put(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
  115. }
  116. EXPORT_SYMBOL_GPL(imx_drm_crtc_vblank_put);
  117. void imx_drm_handle_vblank(struct imx_drm_crtc *imx_drm_crtc)
  118. {
  119. drm_handle_vblank(imx_drm_crtc->crtc->dev, imx_drm_crtc->pipe);
  120. }
  121. EXPORT_SYMBOL_GPL(imx_drm_handle_vblank);
  122. static int imx_drm_enable_vblank(struct drm_device *drm, int crtc)
  123. {
  124. struct imx_drm_device *imxdrm = drm->dev_private;
  125. struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc];
  126. int ret;
  127. if (!imx_drm_crtc)
  128. return -EINVAL;
  129. if (!imx_drm_crtc->imx_drm_helper_funcs.enable_vblank)
  130. return -ENOSYS;
  131. ret = imx_drm_crtc->imx_drm_helper_funcs.enable_vblank(
  132. imx_drm_crtc->crtc);
  133. return ret;
  134. }
  135. static void imx_drm_disable_vblank(struct drm_device *drm, int crtc)
  136. {
  137. struct imx_drm_device *imxdrm = drm->dev_private;
  138. struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[crtc];
  139. if (!imx_drm_crtc)
  140. return;
  141. if (!imx_drm_crtc->imx_drm_helper_funcs.disable_vblank)
  142. return;
  143. imx_drm_crtc->imx_drm_helper_funcs.disable_vblank(imx_drm_crtc->crtc);
  144. }
  145. static void imx_drm_driver_preclose(struct drm_device *drm,
  146. struct drm_file *file)
  147. {
  148. int i;
  149. if (!file->is_master)
  150. return;
  151. for (i = 0; i < MAX_CRTC; i++)
  152. imx_drm_disable_vblank(drm, i);
  153. }
  154. static const struct file_operations imx_drm_driver_fops = {
  155. .owner = THIS_MODULE,
  156. .open = drm_open,
  157. .release = drm_release,
  158. .unlocked_ioctl = drm_ioctl,
  159. .mmap = drm_gem_cma_mmap,
  160. .poll = drm_poll,
  161. .read = drm_read,
  162. .llseek = noop_llseek,
  163. };
  164. void imx_drm_connector_destroy(struct drm_connector *connector)
  165. {
  166. drm_connector_unregister(connector);
  167. drm_connector_cleanup(connector);
  168. }
  169. EXPORT_SYMBOL_GPL(imx_drm_connector_destroy);
  170. void imx_drm_encoder_destroy(struct drm_encoder *encoder)
  171. {
  172. drm_encoder_cleanup(encoder);
  173. }
  174. EXPORT_SYMBOL_GPL(imx_drm_encoder_destroy);
  175. static void imx_drm_output_poll_changed(struct drm_device *drm)
  176. {
  177. #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
  178. struct imx_drm_device *imxdrm = drm->dev_private;
  179. drm_fbdev_cma_hotplug_event(imxdrm->fbhelper);
  180. #endif
  181. }
  182. static struct drm_mode_config_funcs imx_drm_mode_config_funcs = {
  183. .fb_create = drm_fb_cma_create,
  184. .output_poll_changed = imx_drm_output_poll_changed,
  185. };
  186. /*
  187. * Main DRM initialisation. This binds, initialises and registers
  188. * with DRM the subcomponents of the driver.
  189. */
  190. static int imx_drm_driver_load(struct drm_device *drm, unsigned long flags)
  191. {
  192. struct imx_drm_device *imxdrm;
  193. struct drm_connector *connector;
  194. int ret;
  195. imxdrm = devm_kzalloc(drm->dev, sizeof(*imxdrm), GFP_KERNEL);
  196. if (!imxdrm)
  197. return -ENOMEM;
  198. imxdrm->drm = drm;
  199. drm->dev_private = imxdrm;
  200. /*
  201. * enable drm irq mode.
  202. * - with irq_enabled = true, we can use the vblank feature.
  203. *
  204. * P.S. note that we wouldn't use drm irq handler but
  205. * just specific driver own one instead because
  206. * drm framework supports only one irq handler and
  207. * drivers can well take care of their interrupts
  208. */
  209. drm->irq_enabled = true;
  210. /*
  211. * set max width and height as default value(4096x4096).
  212. * this value would be used to check framebuffer size limitation
  213. * at drm_mode_addfb().
  214. */
  215. drm->mode_config.min_width = 64;
  216. drm->mode_config.min_height = 64;
  217. drm->mode_config.max_width = 4096;
  218. drm->mode_config.max_height = 4096;
  219. drm->mode_config.funcs = &imx_drm_mode_config_funcs;
  220. drm_mode_config_init(drm);
  221. ret = drm_vblank_init(drm, MAX_CRTC);
  222. if (ret)
  223. goto err_kms;
  224. /*
  225. * with vblank_disable_allowed = true, vblank interrupt will be
  226. * disabled by drm timer once a current process gives up ownership
  227. * of vblank event. (after drm_vblank_put function is called)
  228. */
  229. drm->vblank_disable_allowed = true;
  230. platform_set_drvdata(drm->platformdev, drm);
  231. /* Now try and bind all our sub-components */
  232. ret = component_bind_all(drm->dev, drm);
  233. if (ret)
  234. goto err_vblank;
  235. /*
  236. * All components are now added, we can publish the connector sysfs
  237. * entries to userspace. This will generate hotplug events and so
  238. * userspace will expect to be able to access DRM at this point.
  239. */
  240. list_for_each_entry(connector, &drm->mode_config.connector_list, head) {
  241. ret = drm_connector_register(connector);
  242. if (ret) {
  243. dev_err(drm->dev,
  244. "[CONNECTOR:%d:%s] drm_connector_register failed: %d\n",
  245. connector->base.id,
  246. connector->name, ret);
  247. goto err_unbind;
  248. }
  249. }
  250. /*
  251. * All components are now initialised, so setup the fb helper.
  252. * The fb helper takes copies of key hardware information, so the
  253. * crtcs/connectors/encoders must not change after this point.
  254. */
  255. #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
  256. if (legacyfb_depth != 16 && legacyfb_depth != 32) {
  257. dev_warn(drm->dev, "Invalid legacyfb_depth. Defaulting to 16bpp\n");
  258. legacyfb_depth = 16;
  259. }
  260. imxdrm->fbhelper = drm_fbdev_cma_init(drm, legacyfb_depth,
  261. drm->mode_config.num_crtc, MAX_CRTC);
  262. if (IS_ERR(imxdrm->fbhelper)) {
  263. ret = PTR_ERR(imxdrm->fbhelper);
  264. imxdrm->fbhelper = NULL;
  265. goto err_unbind;
  266. }
  267. #endif
  268. drm_kms_helper_poll_init(drm);
  269. return 0;
  270. err_unbind:
  271. component_unbind_all(drm->dev, drm);
  272. err_vblank:
  273. drm_vblank_cleanup(drm);
  274. err_kms:
  275. drm_mode_config_cleanup(drm);
  276. return ret;
  277. }
  278. /*
  279. * imx_drm_add_crtc - add a new crtc
  280. */
  281. int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
  282. struct imx_drm_crtc **new_crtc,
  283. const struct imx_drm_crtc_helper_funcs *imx_drm_helper_funcs,
  284. struct device_node *port)
  285. {
  286. struct imx_drm_device *imxdrm = drm->dev_private;
  287. struct imx_drm_crtc *imx_drm_crtc;
  288. int ret;
  289. /*
  290. * The vblank arrays are dimensioned by MAX_CRTC - we can't
  291. * pass IDs greater than this to those functions.
  292. */
  293. if (imxdrm->pipes >= MAX_CRTC)
  294. return -EINVAL;
  295. if (imxdrm->drm->open_count)
  296. return -EBUSY;
  297. imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
  298. if (!imx_drm_crtc)
  299. return -ENOMEM;
  300. imx_drm_crtc->imx_drm_helper_funcs = *imx_drm_helper_funcs;
  301. imx_drm_crtc->pipe = imxdrm->pipes++;
  302. imx_drm_crtc->port = port;
  303. imx_drm_crtc->crtc = crtc;
  304. imxdrm->crtc[imx_drm_crtc->pipe] = imx_drm_crtc;
  305. *new_crtc = imx_drm_crtc;
  306. ret = drm_mode_crtc_set_gamma_size(imx_drm_crtc->crtc, 256);
  307. if (ret)
  308. goto err_register;
  309. drm_crtc_helper_add(crtc,
  310. imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
  311. drm_crtc_init(drm, crtc,
  312. imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
  313. return 0;
  314. err_register:
  315. imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
  316. kfree(imx_drm_crtc);
  317. return ret;
  318. }
  319. EXPORT_SYMBOL_GPL(imx_drm_add_crtc);
  320. /*
  321. * imx_drm_remove_crtc - remove a crtc
  322. */
  323. int imx_drm_remove_crtc(struct imx_drm_crtc *imx_drm_crtc)
  324. {
  325. struct imx_drm_device *imxdrm = imx_drm_crtc->crtc->dev->dev_private;
  326. drm_crtc_cleanup(imx_drm_crtc->crtc);
  327. imxdrm->crtc[imx_drm_crtc->pipe] = NULL;
  328. kfree(imx_drm_crtc);
  329. return 0;
  330. }
  331. EXPORT_SYMBOL_GPL(imx_drm_remove_crtc);
  332. /*
  333. * Find the DRM CRTC possible mask for the connected endpoint.
  334. *
  335. * The encoder possible masks are defined by their position in the
  336. * mode_config crtc_list. This means that CRTCs must not be added
  337. * or removed once the DRM device has been fully initialised.
  338. */
  339. static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm,
  340. struct device_node *endpoint)
  341. {
  342. struct device_node *port;
  343. unsigned i;
  344. port = of_graph_get_remote_port(endpoint);
  345. if (!port)
  346. return 0;
  347. of_node_put(port);
  348. for (i = 0; i < MAX_CRTC; i++) {
  349. struct imx_drm_crtc *imx_drm_crtc = imxdrm->crtc[i];
  350. if (imx_drm_crtc && imx_drm_crtc->port == port)
  351. return drm_crtc_mask(imx_drm_crtc->crtc);
  352. }
  353. return 0;
  354. }
  355. static struct device_node *imx_drm_of_get_next_endpoint(
  356. const struct device_node *parent, struct device_node *prev)
  357. {
  358. struct device_node *node = of_graph_get_next_endpoint(parent, prev);
  359. of_node_put(prev);
  360. return node;
  361. }
  362. int imx_drm_encoder_parse_of(struct drm_device *drm,
  363. struct drm_encoder *encoder, struct device_node *np)
  364. {
  365. struct imx_drm_device *imxdrm = drm->dev_private;
  366. struct device_node *ep = NULL;
  367. uint32_t crtc_mask = 0;
  368. int i;
  369. for (i = 0; ; i++) {
  370. u32 mask;
  371. ep = imx_drm_of_get_next_endpoint(np, ep);
  372. if (!ep)
  373. break;
  374. mask = imx_drm_find_crtc_mask(imxdrm, ep);
  375. /*
  376. * If we failed to find the CRTC(s) which this encoder is
  377. * supposed to be connected to, it's because the CRTC has
  378. * not been registered yet. Defer probing, and hope that
  379. * the required CRTC is added later.
  380. */
  381. if (mask == 0)
  382. return -EPROBE_DEFER;
  383. crtc_mask |= mask;
  384. }
  385. of_node_put(ep);
  386. if (i == 0)
  387. return -ENOENT;
  388. encoder->possible_crtcs = crtc_mask;
  389. /* FIXME: this is the mask of outputs which can clone this output. */
  390. encoder->possible_clones = ~0;
  391. return 0;
  392. }
  393. EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
  394. /*
  395. * @node: device tree node containing encoder input ports
  396. * @encoder: drm_encoder
  397. */
  398. int imx_drm_encoder_get_mux_id(struct device_node *node,
  399. struct drm_encoder *encoder)
  400. {
  401. struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc);
  402. struct device_node *ep = NULL;
  403. struct of_endpoint endpoint;
  404. struct device_node *port;
  405. int ret;
  406. if (!node || !imx_crtc)
  407. return -EINVAL;
  408. do {
  409. ep = imx_drm_of_get_next_endpoint(node, ep);
  410. if (!ep)
  411. break;
  412. port = of_graph_get_remote_port(ep);
  413. of_node_put(port);
  414. if (port == imx_crtc->port) {
  415. ret = of_graph_parse_endpoint(ep, &endpoint);
  416. return ret ? ret : endpoint.port;
  417. }
  418. } while (ep);
  419. return -EINVAL;
  420. }
  421. EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id);
  422. static const struct drm_ioctl_desc imx_drm_ioctls[] = {
  423. /* none so far */
  424. };
  425. static struct drm_driver imx_drm_driver = {
  426. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME,
  427. .load = imx_drm_driver_load,
  428. .unload = imx_drm_driver_unload,
  429. .lastclose = imx_drm_driver_lastclose,
  430. .preclose = imx_drm_driver_preclose,
  431. .set_busid = drm_platform_set_busid,
  432. .gem_free_object = drm_gem_cma_free_object,
  433. .gem_vm_ops = &drm_gem_cma_vm_ops,
  434. .dumb_create = drm_gem_cma_dumb_create,
  435. .dumb_map_offset = drm_gem_cma_dumb_map_offset,
  436. .dumb_destroy = drm_gem_dumb_destroy,
  437. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  438. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  439. .gem_prime_import = drm_gem_prime_import,
  440. .gem_prime_export = drm_gem_prime_export,
  441. .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
  442. .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
  443. .gem_prime_vmap = drm_gem_cma_prime_vmap,
  444. .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
  445. .gem_prime_mmap = drm_gem_cma_prime_mmap,
  446. .get_vblank_counter = drm_vblank_count,
  447. .enable_vblank = imx_drm_enable_vblank,
  448. .disable_vblank = imx_drm_disable_vblank,
  449. .ioctls = imx_drm_ioctls,
  450. .num_ioctls = ARRAY_SIZE(imx_drm_ioctls),
  451. .fops = &imx_drm_driver_fops,
  452. .name = "imx-drm",
  453. .desc = "i.MX DRM graphics",
  454. .date = "20120507",
  455. .major = 1,
  456. .minor = 0,
  457. .patchlevel = 0,
  458. };
  459. static int compare_of(struct device *dev, void *data)
  460. {
  461. struct device_node *np = data;
  462. /* Special case for LDB, one device for two channels */
  463. if (of_node_cmp(np->name, "lvds-channel") == 0) {
  464. np = of_get_parent(np);
  465. of_node_put(np);
  466. }
  467. return dev->of_node == np;
  468. }
  469. static int imx_drm_bind(struct device *dev)
  470. {
  471. return drm_platform_init(&imx_drm_driver, to_platform_device(dev));
  472. }
  473. static void imx_drm_unbind(struct device *dev)
  474. {
  475. drm_put_dev(dev_get_drvdata(dev));
  476. }
  477. static const struct component_master_ops imx_drm_ops = {
  478. .bind = imx_drm_bind,
  479. .unbind = imx_drm_unbind,
  480. };
  481. static int imx_drm_platform_probe(struct platform_device *pdev)
  482. {
  483. struct device_node *ep, *port, *remote;
  484. struct component_match *match = NULL;
  485. int ret;
  486. int i;
  487. /*
  488. * Bind the IPU display interface ports first, so that
  489. * imx_drm_encoder_parse_of called from encoder .bind callbacks
  490. * works as expected.
  491. */
  492. for (i = 0; ; i++) {
  493. port = of_parse_phandle(pdev->dev.of_node, "ports", i);
  494. if (!port)
  495. break;
  496. component_match_add(&pdev->dev, &match, compare_of, port);
  497. }
  498. if (i == 0) {
  499. dev_err(&pdev->dev, "missing 'ports' property\n");
  500. return -ENODEV;
  501. }
  502. /* Then bind all encoders */
  503. for (i = 0; ; i++) {
  504. port = of_parse_phandle(pdev->dev.of_node, "ports", i);
  505. if (!port)
  506. break;
  507. for_each_child_of_node(port, ep) {
  508. remote = of_graph_get_remote_port_parent(ep);
  509. if (!remote || !of_device_is_available(remote)) {
  510. of_node_put(remote);
  511. continue;
  512. } else if (!of_device_is_available(remote->parent)) {
  513. dev_warn(&pdev->dev, "parent device of %s is not available\n",
  514. remote->full_name);
  515. of_node_put(remote);
  516. continue;
  517. }
  518. component_match_add(&pdev->dev, &match, compare_of,
  519. remote);
  520. of_node_put(remote);
  521. }
  522. of_node_put(port);
  523. }
  524. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  525. if (ret)
  526. return ret;
  527. return component_master_add_with_match(&pdev->dev, &imx_drm_ops, match);
  528. }
  529. static int imx_drm_platform_remove(struct platform_device *pdev)
  530. {
  531. component_master_del(&pdev->dev, &imx_drm_ops);
  532. return 0;
  533. }
  534. #ifdef CONFIG_PM_SLEEP
  535. static int imx_drm_suspend(struct device *dev)
  536. {
  537. struct drm_device *drm_dev = dev_get_drvdata(dev);
  538. /* The drm_dev is NULL before .load hook is called */
  539. if (drm_dev == NULL)
  540. return 0;
  541. drm_kms_helper_poll_disable(drm_dev);
  542. return 0;
  543. }
  544. static int imx_drm_resume(struct device *dev)
  545. {
  546. struct drm_device *drm_dev = dev_get_drvdata(dev);
  547. if (drm_dev == NULL)
  548. return 0;
  549. drm_helper_resume_force_mode(drm_dev);
  550. drm_kms_helper_poll_enable(drm_dev);
  551. return 0;
  552. }
  553. #endif
  554. static SIMPLE_DEV_PM_OPS(imx_drm_pm_ops, imx_drm_suspend, imx_drm_resume);
  555. static const struct of_device_id imx_drm_dt_ids[] = {
  556. { .compatible = "fsl,imx-display-subsystem", },
  557. { /* sentinel */ },
  558. };
  559. MODULE_DEVICE_TABLE(of, imx_drm_dt_ids);
  560. static struct platform_driver imx_drm_pdrv = {
  561. .probe = imx_drm_platform_probe,
  562. .remove = imx_drm_platform_remove,
  563. .driver = {
  564. .name = "imx-drm",
  565. .pm = &imx_drm_pm_ops,
  566. .of_match_table = imx_drm_dt_ids,
  567. },
  568. };
  569. module_platform_driver(imx_drm_pdrv);
  570. MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
  571. MODULE_DESCRIPTION("i.MX drm driver core");
  572. MODULE_LICENSE("GPL");