drm_probe_helper.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Copyright (c) 2006-2008 Intel Corporation
  3. * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
  4. *
  5. * DRM core CRTC related functions
  6. *
  7. * Permission to use, copy, modify, distribute, and sell this software and its
  8. * documentation for any purpose is hereby granted without fee, provided that
  9. * the above copyright notice appear in all copies and that both that copyright
  10. * notice and this permission notice appear in supporting documentation, and
  11. * that the name of the copyright holders not be used in advertising or
  12. * publicity pertaining to distribution of the software without specific,
  13. * written prior permission. The copyright holders make no representations
  14. * about the suitability of this software for any purpose. It is provided "as
  15. * is" without express or implied warranty.
  16. *
  17. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  19. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  21. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  22. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. *
  25. * Authors:
  26. * Keith Packard
  27. * Eric Anholt <eric@anholt.net>
  28. * Dave Airlie <airlied@linux.ie>
  29. * Jesse Barnes <jesse.barnes@intel.com>
  30. */
  31. #include <linux/export.h>
  32. #include <linux/moduleparam.h>
  33. #include <drm/drmP.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_fourcc.h>
  36. #include <drm/drm_crtc_helper.h>
  37. #include <drm/drm_fb_helper.h>
  38. #include <drm/drm_edid.h>
  39. /**
  40. * DOC: output probing helper overview
  41. *
  42. * This library provides some helper code for output probing. It provides an
  43. * implementation of the core &drm_connector_funcs.fill_modes interface with
  44. * drm_helper_probe_single_connector_modes().
  45. *
  46. * It also provides support for polling connectors with a work item and for
  47. * generic hotplug interrupt handling where the driver doesn't or cannot keep
  48. * track of a per-connector hpd interrupt.
  49. *
  50. * This helper library can be used independently of the modeset helper library.
  51. * Drivers can also overwrite different parts e.g. use their own hotplug
  52. * handling code to avoid probing unrelated outputs.
  53. *
  54. * The probe helpers share the function table structures with other display
  55. * helper libraries. See &struct drm_connector_helper_funcs for the details.
  56. */
  57. static bool drm_kms_helper_poll = true;
  58. module_param_named(poll, drm_kms_helper_poll, bool, 0600);
  59. static enum drm_mode_status
  60. drm_mode_validate_flag(const struct drm_display_mode *mode,
  61. int flags)
  62. {
  63. if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
  64. !(flags & DRM_MODE_FLAG_INTERLACE))
  65. return MODE_NO_INTERLACE;
  66. if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
  67. !(flags & DRM_MODE_FLAG_DBLSCAN))
  68. return MODE_NO_DBLESCAN;
  69. if ((mode->flags & DRM_MODE_FLAG_3D_MASK) &&
  70. !(flags & DRM_MODE_FLAG_3D_MASK))
  71. return MODE_NO_STEREO;
  72. return MODE_OK;
  73. }
  74. static int drm_helper_probe_add_cmdline_mode(struct drm_connector *connector)
  75. {
  76. struct drm_cmdline_mode *cmdline_mode;
  77. struct drm_display_mode *mode;
  78. cmdline_mode = &connector->cmdline_mode;
  79. if (!cmdline_mode->specified)
  80. return 0;
  81. /* Only add a GTF mode if we find no matching probed modes */
  82. list_for_each_entry(mode, &connector->probed_modes, head) {
  83. if (mode->hdisplay != cmdline_mode->xres ||
  84. mode->vdisplay != cmdline_mode->yres)
  85. continue;
  86. if (cmdline_mode->refresh_specified) {
  87. /* The probed mode's vrefresh is set until later */
  88. if (drm_mode_vrefresh(mode) != cmdline_mode->refresh)
  89. continue;
  90. }
  91. return 0;
  92. }
  93. mode = drm_mode_create_from_cmdline_mode(connector->dev,
  94. cmdline_mode);
  95. if (mode == NULL)
  96. return 0;
  97. drm_mode_probed_add(connector, mode);
  98. return 1;
  99. }
  100. #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
  101. /**
  102. * drm_kms_helper_poll_enable - re-enable output polling.
  103. * @dev: drm_device
  104. *
  105. * This function re-enables the output polling work, after it has been
  106. * temporarily disabled using drm_kms_helper_poll_disable(), for example over
  107. * suspend/resume.
  108. *
  109. * Drivers can call this helper from their device resume implementation. It is
  110. * an error to call this when the output polling support has not yet been set
  111. * up.
  112. *
  113. * Note that calls to enable and disable polling must be strictly ordered, which
  114. * is automatically the case when they're only call from suspend/resume
  115. * callbacks.
  116. */
  117. void drm_kms_helper_poll_enable(struct drm_device *dev)
  118. {
  119. bool poll = false;
  120. struct drm_connector *connector;
  121. struct drm_connector_list_iter conn_iter;
  122. unsigned long delay = DRM_OUTPUT_POLL_PERIOD;
  123. if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
  124. return;
  125. drm_connector_list_iter_begin(dev, &conn_iter);
  126. drm_for_each_connector_iter(connector, &conn_iter) {
  127. if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT |
  128. DRM_CONNECTOR_POLL_DISCONNECT))
  129. poll = true;
  130. }
  131. drm_connector_list_iter_end(&conn_iter);
  132. if (dev->mode_config.delayed_event) {
  133. /*
  134. * FIXME:
  135. *
  136. * Use short (1s) delay to handle the initial delayed event.
  137. * This delay should not be needed, but Optimus/nouveau will
  138. * fail in a mysterious way if the delayed event is handled as
  139. * soon as possible like it is done in
  140. * drm_helper_probe_single_connector_modes() in case the poll
  141. * was enabled before.
  142. */
  143. poll = true;
  144. delay = HZ;
  145. }
  146. if (poll)
  147. schedule_delayed_work(&dev->mode_config.output_poll_work, delay);
  148. }
  149. EXPORT_SYMBOL(drm_kms_helper_poll_enable);
  150. static enum drm_connector_status
  151. drm_helper_probe_detect_ctx(struct drm_connector *connector, bool force)
  152. {
  153. const struct drm_connector_helper_funcs *funcs = connector->helper_private;
  154. struct drm_modeset_acquire_ctx ctx;
  155. int ret;
  156. drm_modeset_acquire_init(&ctx, 0);
  157. retry:
  158. ret = drm_modeset_lock(&connector->dev->mode_config.connection_mutex, &ctx);
  159. if (!ret) {
  160. if (funcs->detect_ctx)
  161. ret = funcs->detect_ctx(connector, &ctx, force);
  162. else if (connector->funcs->detect)
  163. ret = connector->funcs->detect(connector, force);
  164. else
  165. ret = connector_status_connected;
  166. }
  167. if (ret == -EDEADLK) {
  168. drm_modeset_backoff(&ctx);
  169. goto retry;
  170. }
  171. if (WARN_ON(ret < 0))
  172. ret = connector_status_unknown;
  173. drm_modeset_drop_locks(&ctx);
  174. drm_modeset_acquire_fini(&ctx);
  175. return ret;
  176. }
  177. /**
  178. * drm_helper_probe_detect - probe connector status
  179. * @connector: connector to probe
  180. * @ctx: acquire_ctx, or NULL to let this function handle locking.
  181. * @force: Whether destructive probe operations should be performed.
  182. *
  183. * This function calls the detect callbacks of the connector.
  184. * This function returns &drm_connector_status, or
  185. * if @ctx is set, it might also return -EDEADLK.
  186. */
  187. int
  188. drm_helper_probe_detect(struct drm_connector *connector,
  189. struct drm_modeset_acquire_ctx *ctx,
  190. bool force)
  191. {
  192. const struct drm_connector_helper_funcs *funcs = connector->helper_private;
  193. struct drm_device *dev = connector->dev;
  194. int ret;
  195. if (!ctx)
  196. return drm_helper_probe_detect_ctx(connector, force);
  197. ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
  198. if (ret)
  199. return ret;
  200. if (funcs->detect_ctx)
  201. return funcs->detect_ctx(connector, ctx, force);
  202. else if (connector->funcs->detect)
  203. return connector->funcs->detect(connector, force);
  204. else
  205. return connector_status_connected;
  206. }
  207. EXPORT_SYMBOL(drm_helper_probe_detect);
  208. /**
  209. * drm_helper_probe_single_connector_modes - get complete set of display modes
  210. * @connector: connector to probe
  211. * @maxX: max width for modes
  212. * @maxY: max height for modes
  213. *
  214. * Based on the helper callbacks implemented by @connector in struct
  215. * &drm_connector_helper_funcs try to detect all valid modes. Modes will first
  216. * be added to the connector's probed_modes list, then culled (based on validity
  217. * and the @maxX, @maxY parameters) and put into the normal modes list.
  218. *
  219. * Intended to be used as a generic implementation of the
  220. * &drm_connector_funcs.fill_modes() vfunc for drivers that use the CRTC helpers
  221. * for output mode filtering and detection.
  222. *
  223. * The basic procedure is as follows
  224. *
  225. * 1. All modes currently on the connector's modes list are marked as stale
  226. *
  227. * 2. New modes are added to the connector's probed_modes list with
  228. * drm_mode_probed_add(). New modes start their life with status as OK.
  229. * Modes are added from a single source using the following priority order.
  230. *
  231. * - debugfs 'override_edid' (used for testing only)
  232. * - firmware EDID (drm_load_edid_firmware())
  233. * - &drm_connector_helper_funcs.get_modes vfunc
  234. * - if the connector status is connector_status_connected, standard
  235. * VESA DMT modes up to 1024x768 are automatically added
  236. * (drm_add_modes_noedid())
  237. *
  238. * Finally modes specified via the kernel command line (video=...) are
  239. * added in addition to what the earlier probes produced
  240. * (drm_helper_probe_add_cmdline_mode()). These modes are generated
  241. * using the VESA GTF/CVT formulas.
  242. *
  243. * 3. Modes are moved from the probed_modes list to the modes list. Potential
  244. * duplicates are merged together (see drm_mode_connector_list_update()).
  245. * After this step the probed_modes list will be empty again.
  246. *
  247. * 4. Any non-stale mode on the modes list then undergoes validation
  248. *
  249. * - drm_mode_validate_basic() performs basic sanity checks
  250. * - drm_mode_validate_size() filters out modes larger than @maxX and @maxY
  251. * (if specified)
  252. * - drm_mode_validate_flag() checks the modes against basic connector
  253. * capabilities (interlace_allowed,doublescan_allowed,stereo_allowed)
  254. * - the optional &drm_connector_helper_funcs.mode_valid helper can perform
  255. * driver and/or hardware specific checks
  256. *
  257. * 5. Any mode whose status is not OK is pruned from the connector's modes list,
  258. * accompanied by a debug message indicating the reason for the mode's
  259. * rejection (see drm_mode_prune_invalid()).
  260. *
  261. * Returns:
  262. * The number of modes found on @connector.
  263. */
  264. int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
  265. uint32_t maxX, uint32_t maxY)
  266. {
  267. struct drm_device *dev = connector->dev;
  268. struct drm_display_mode *mode;
  269. const struct drm_connector_helper_funcs *connector_funcs =
  270. connector->helper_private;
  271. int count = 0, ret;
  272. int mode_flags = 0;
  273. bool verbose_prune = true;
  274. enum drm_connector_status old_status;
  275. struct drm_modeset_acquire_ctx ctx;
  276. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  277. drm_modeset_acquire_init(&ctx, 0);
  278. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
  279. connector->name);
  280. retry:
  281. ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
  282. if (ret == -EDEADLK) {
  283. drm_modeset_backoff(&ctx);
  284. goto retry;
  285. } else
  286. WARN_ON(ret < 0);
  287. /* set all old modes to the stale state */
  288. list_for_each_entry(mode, &connector->modes, head)
  289. mode->status = MODE_STALE;
  290. old_status = connector->status;
  291. if (connector->force) {
  292. if (connector->force == DRM_FORCE_ON ||
  293. connector->force == DRM_FORCE_ON_DIGITAL)
  294. connector->status = connector_status_connected;
  295. else
  296. connector->status = connector_status_disconnected;
  297. if (connector->funcs->force)
  298. connector->funcs->force(connector);
  299. } else {
  300. ret = drm_helper_probe_detect(connector, &ctx, true);
  301. if (ret == -EDEADLK) {
  302. drm_modeset_backoff(&ctx);
  303. goto retry;
  304. } else if (WARN(ret < 0, "Invalid return value %i for connector detection\n", ret))
  305. ret = connector_status_unknown;
  306. connector->status = ret;
  307. }
  308. /*
  309. * Normally either the driver's hpd code or the poll loop should
  310. * pick up any changes and fire the hotplug event. But if
  311. * userspace sneaks in a probe, we might miss a change. Hence
  312. * check here, and if anything changed start the hotplug code.
  313. */
  314. if (old_status != connector->status) {
  315. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  316. connector->base.id,
  317. connector->name,
  318. drm_get_connector_status_name(old_status),
  319. drm_get_connector_status_name(connector->status));
  320. /*
  321. * The hotplug event code might call into the fb
  322. * helpers, and so expects that we do not hold any
  323. * locks. Fire up the poll struct instead, it will
  324. * disable itself again.
  325. */
  326. dev->mode_config.delayed_event = true;
  327. if (dev->mode_config.poll_enabled)
  328. schedule_delayed_work(&dev->mode_config.output_poll_work,
  329. 0);
  330. }
  331. /* Re-enable polling in case the global poll config changed. */
  332. if (drm_kms_helper_poll != dev->mode_config.poll_running)
  333. drm_kms_helper_poll_enable(dev);
  334. dev->mode_config.poll_running = drm_kms_helper_poll;
  335. if (connector->status == connector_status_disconnected) {
  336. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
  337. connector->base.id, connector->name);
  338. drm_mode_connector_update_edid_property(connector, NULL);
  339. verbose_prune = false;
  340. goto prune;
  341. }
  342. if (connector->override_edid) {
  343. struct edid *edid = (struct edid *) connector->edid_blob_ptr->data;
  344. count = drm_add_edid_modes(connector, edid);
  345. drm_edid_to_eld(connector, edid);
  346. } else {
  347. struct edid *edid = drm_load_edid_firmware(connector);
  348. if (!IS_ERR_OR_NULL(edid)) {
  349. drm_mode_connector_update_edid_property(connector, edid);
  350. count = drm_add_edid_modes(connector, edid);
  351. drm_edid_to_eld(connector, edid);
  352. kfree(edid);
  353. }
  354. if (count == 0)
  355. count = (*connector_funcs->get_modes)(connector);
  356. }
  357. if (count == 0 && connector->status == connector_status_connected)
  358. count = drm_add_modes_noedid(connector, 1024, 768);
  359. count += drm_helper_probe_add_cmdline_mode(connector);
  360. if (count == 0)
  361. goto prune;
  362. drm_mode_connector_list_update(connector);
  363. if (connector->interlace_allowed)
  364. mode_flags |= DRM_MODE_FLAG_INTERLACE;
  365. if (connector->doublescan_allowed)
  366. mode_flags |= DRM_MODE_FLAG_DBLSCAN;
  367. if (connector->stereo_allowed)
  368. mode_flags |= DRM_MODE_FLAG_3D_MASK;
  369. list_for_each_entry(mode, &connector->modes, head) {
  370. if (mode->status == MODE_OK)
  371. mode->status = drm_mode_validate_basic(mode);
  372. if (mode->status == MODE_OK)
  373. mode->status = drm_mode_validate_size(mode, maxX, maxY);
  374. if (mode->status == MODE_OK)
  375. mode->status = drm_mode_validate_flag(mode, mode_flags);
  376. if (mode->status == MODE_OK && connector_funcs->mode_valid)
  377. mode->status = connector_funcs->mode_valid(connector,
  378. mode);
  379. }
  380. prune:
  381. drm_mode_prune_invalid(dev, &connector->modes, verbose_prune);
  382. drm_modeset_drop_locks(&ctx);
  383. drm_modeset_acquire_fini(&ctx);
  384. if (list_empty(&connector->modes))
  385. return 0;
  386. list_for_each_entry(mode, &connector->modes, head)
  387. mode->vrefresh = drm_mode_vrefresh(mode);
  388. drm_mode_sort(&connector->modes);
  389. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id,
  390. connector->name);
  391. list_for_each_entry(mode, &connector->modes, head) {
  392. drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
  393. drm_mode_debug_printmodeline(mode);
  394. }
  395. return count;
  396. }
  397. EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
  398. /**
  399. * drm_kms_helper_hotplug_event - fire off KMS hotplug events
  400. * @dev: drm_device whose connector state changed
  401. *
  402. * This function fires off the uevent for userspace and also calls the
  403. * output_poll_changed function, which is most commonly used to inform the fbdev
  404. * emulation code and allow it to update the fbcon output configuration.
  405. *
  406. * Drivers should call this from their hotplug handling code when a change is
  407. * detected. Note that this function does not do any output detection of its
  408. * own, like drm_helper_hpd_irq_event() does - this is assumed to be done by the
  409. * driver already.
  410. *
  411. * This function must be called from process context with no mode
  412. * setting locks held.
  413. */
  414. void drm_kms_helper_hotplug_event(struct drm_device *dev)
  415. {
  416. /* send a uevent + call fbdev */
  417. drm_sysfs_hotplug_event(dev);
  418. if (dev->mode_config.funcs->output_poll_changed)
  419. dev->mode_config.funcs->output_poll_changed(dev);
  420. }
  421. EXPORT_SYMBOL(drm_kms_helper_hotplug_event);
  422. static void output_poll_execute(struct work_struct *work)
  423. {
  424. struct delayed_work *delayed_work = to_delayed_work(work);
  425. struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work);
  426. struct drm_connector *connector;
  427. struct drm_connector_list_iter conn_iter;
  428. enum drm_connector_status old_status;
  429. bool repoll = false, changed;
  430. /* Pick up any changes detected by the probe functions. */
  431. changed = dev->mode_config.delayed_event;
  432. dev->mode_config.delayed_event = false;
  433. if (!drm_kms_helper_poll)
  434. goto out;
  435. if (!mutex_trylock(&dev->mode_config.mutex)) {
  436. repoll = true;
  437. goto out;
  438. }
  439. drm_connector_list_iter_begin(dev, &conn_iter);
  440. drm_for_each_connector_iter(connector, &conn_iter) {
  441. /* Ignore forced connectors. */
  442. if (connector->force)
  443. continue;
  444. /* Ignore HPD capable connectors and connectors where we don't
  445. * want any hotplug detection at all for polling. */
  446. if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD)
  447. continue;
  448. old_status = connector->status;
  449. /* if we are connected and don't want to poll for disconnect
  450. skip it */
  451. if (old_status == connector_status_connected &&
  452. !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT))
  453. continue;
  454. repoll = true;
  455. connector->status = drm_helper_probe_detect(connector, NULL, false);
  456. if (old_status != connector->status) {
  457. const char *old, *new;
  458. /*
  459. * The poll work sets force=false when calling detect so
  460. * that drivers can avoid to do disruptive tests (e.g.
  461. * when load detect cycles could cause flickering on
  462. * other, running displays). This bears the risk that we
  463. * flip-flop between unknown here in the poll work and
  464. * the real state when userspace forces a full detect
  465. * call after receiving a hotplug event due to this
  466. * change.
  467. *
  468. * Hence clamp an unknown detect status to the old
  469. * value.
  470. */
  471. if (connector->status == connector_status_unknown) {
  472. connector->status = old_status;
  473. continue;
  474. }
  475. old = drm_get_connector_status_name(old_status);
  476. new = drm_get_connector_status_name(connector->status);
  477. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] "
  478. "status updated from %s to %s\n",
  479. connector->base.id,
  480. connector->name,
  481. old, new);
  482. changed = true;
  483. }
  484. }
  485. drm_connector_list_iter_end(&conn_iter);
  486. mutex_unlock(&dev->mode_config.mutex);
  487. out:
  488. if (changed)
  489. drm_kms_helper_hotplug_event(dev);
  490. if (repoll)
  491. schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD);
  492. }
  493. /**
  494. * drm_kms_helper_poll_disable - disable output polling
  495. * @dev: drm_device
  496. *
  497. * This function disables the output polling work.
  498. *
  499. * Drivers can call this helper from their device suspend implementation. It is
  500. * not an error to call this even when output polling isn't enabled or already
  501. * disabled. Polling is re-enabled by calling drm_kms_helper_poll_enable().
  502. *
  503. * Note that calls to enable and disable polling must be strictly ordered, which
  504. * is automatically the case when they're only call from suspend/resume
  505. * callbacks.
  506. */
  507. void drm_kms_helper_poll_disable(struct drm_device *dev)
  508. {
  509. if (!dev->mode_config.poll_enabled)
  510. return;
  511. cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
  512. }
  513. EXPORT_SYMBOL(drm_kms_helper_poll_disable);
  514. /**
  515. * drm_kms_helper_poll_init - initialize and enable output polling
  516. * @dev: drm_device
  517. *
  518. * This function intializes and then also enables output polling support for
  519. * @dev. Drivers which do not have reliable hotplug support in hardware can use
  520. * this helper infrastructure to regularly poll such connectors for changes in
  521. * their connection state.
  522. *
  523. * Drivers can control which connectors are polled by setting the
  524. * DRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags. On
  525. * connectors where probing live outputs can result in visual distortion drivers
  526. * should not set the DRM_CONNECTOR_POLL_DISCONNECT flag to avoid this.
  527. * Connectors which have no flag or only DRM_CONNECTOR_POLL_HPD set are
  528. * completely ignored by the polling logic.
  529. *
  530. * Note that a connector can be both polled and probed from the hotplug handler,
  531. * in case the hotplug interrupt is known to be unreliable.
  532. */
  533. void drm_kms_helper_poll_init(struct drm_device *dev)
  534. {
  535. INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute);
  536. dev->mode_config.poll_enabled = true;
  537. drm_kms_helper_poll_enable(dev);
  538. }
  539. EXPORT_SYMBOL(drm_kms_helper_poll_init);
  540. /**
  541. * drm_kms_helper_poll_fini - disable output polling and clean it up
  542. * @dev: drm_device
  543. */
  544. void drm_kms_helper_poll_fini(struct drm_device *dev)
  545. {
  546. drm_kms_helper_poll_disable(dev);
  547. }
  548. EXPORT_SYMBOL(drm_kms_helper_poll_fini);
  549. /**
  550. * drm_helper_hpd_irq_event - hotplug processing
  551. * @dev: drm_device
  552. *
  553. * Drivers can use this helper function to run a detect cycle on all connectors
  554. * which have the DRM_CONNECTOR_POLL_HPD flag set in their &polled member. All
  555. * other connectors are ignored, which is useful to avoid reprobing fixed
  556. * panels.
  557. *
  558. * This helper function is useful for drivers which can't or don't track hotplug
  559. * interrupts for each connector.
  560. *
  561. * Drivers which support hotplug interrupts for each connector individually and
  562. * which have a more fine-grained detect logic should bypass this code and
  563. * directly call drm_kms_helper_hotplug_event() in case the connector state
  564. * changed.
  565. *
  566. * This function must be called from process context with no mode
  567. * setting locks held.
  568. *
  569. * Note that a connector can be both polled and probed from the hotplug handler,
  570. * in case the hotplug interrupt is known to be unreliable.
  571. */
  572. bool drm_helper_hpd_irq_event(struct drm_device *dev)
  573. {
  574. struct drm_connector *connector;
  575. struct drm_connector_list_iter conn_iter;
  576. enum drm_connector_status old_status;
  577. bool changed = false;
  578. if (!dev->mode_config.poll_enabled)
  579. return false;
  580. mutex_lock(&dev->mode_config.mutex);
  581. drm_connector_list_iter_begin(dev, &conn_iter);
  582. drm_for_each_connector_iter(connector, &conn_iter) {
  583. /* Only handle HPD capable connectors. */
  584. if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
  585. continue;
  586. old_status = connector->status;
  587. connector->status = drm_helper_probe_detect(connector, NULL, false);
  588. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  589. connector->base.id,
  590. connector->name,
  591. drm_get_connector_status_name(old_status),
  592. drm_get_connector_status_name(connector->status));
  593. if (old_status != connector->status)
  594. changed = true;
  595. }
  596. drm_connector_list_iter_end(&conn_iter);
  597. mutex_unlock(&dev->mode_config.mutex);
  598. if (changed)
  599. drm_kms_helper_hotplug_event(dev);
  600. return changed;
  601. }
  602. EXPORT_SYMBOL(drm_helper_hpd_irq_event);