2014-04-10 16:51:11 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2008 Intel Corporation
|
|
|
|
* Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
|
|
|
|
*
|
|
|
|
* DRM core CRTC related functions
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Keith Packard
|
|
|
|
* Eric Anholt <eric@anholt.net>
|
|
|
|
* Dave Airlie <airlied@linux.ie>
|
|
|
|
* Jesse Barnes <jesse.barnes@intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
|
2019-08-26 23:26:29 +08:00
|
|
|
#include <drm/drm_bridge.h>
|
2018-07-04 00:03:47 +08:00
|
|
|
#include <drm/drm_client.h>
|
2014-04-10 16:51:11 +08:00
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
#include <drm/drm_edid.h>
|
2019-05-27 01:35:35 +08:00
|
|
|
#include <drm/drm_fourcc.h>
|
2017-05-25 22:19:13 +08:00
|
|
|
#include <drm/drm_modeset_helper_vtables.h>
|
2019-05-27 01:35:35 +08:00
|
|
|
#include <drm/drm_print.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2019-05-27 01:35:35 +08:00
|
|
|
#include <drm/drm_sysfs.h>
|
2017-05-25 22:19:13 +08:00
|
|
|
|
|
|
|
#include "drm_crtc_helper_internal.h"
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: output probing helper overview
|
|
|
|
*
|
|
|
|
* This library provides some helper code for output probing. It provides an
|
2017-01-25 14:26:43 +08:00
|
|
|
* implementation of the core &drm_connector_funcs.fill_modes interface with
|
2017-04-04 17:53:04 +08:00
|
|
|
* drm_helper_probe_single_connector_modes().
|
2014-04-10 16:51:11 +08:00
|
|
|
*
|
|
|
|
* It also provides support for polling connectors with a work item and for
|
|
|
|
* generic hotplug interrupt handling where the driver doesn't or cannot keep
|
|
|
|
* track of a per-connector hpd interrupt.
|
|
|
|
*
|
|
|
|
* This helper library can be used independently of the modeset helper library.
|
|
|
|
* Drivers can also overwrite different parts e.g. use their own hotplug
|
|
|
|
* handling code to avoid probing unrelated outputs.
|
2015-12-04 16:45:44 +08:00
|
|
|
*
|
|
|
|
* The probe helpers share the function table structures with other display
|
2016-12-30 04:48:26 +08:00
|
|
|
* helper libraries. See &struct drm_connector_helper_funcs for the details.
|
2014-04-10 16:51:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static bool drm_kms_helper_poll = true;
|
|
|
|
module_param_named(poll, drm_kms_helper_poll, bool, 0600);
|
|
|
|
|
2014-12-17 19:56:22 +08:00
|
|
|
static enum drm_mode_status
|
|
|
|
drm_mode_validate_flag(const struct drm_display_mode *mode,
|
|
|
|
int flags)
|
2014-04-10 16:51:11 +08:00
|
|
|
{
|
2014-12-17 19:56:22 +08:00
|
|
|
if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
|
|
|
|
!(flags & DRM_MODE_FLAG_INTERLACE))
|
|
|
|
return MODE_NO_INTERLACE;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2014-12-17 19:56:22 +08:00
|
|
|
if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
|
|
|
|
!(flags & DRM_MODE_FLAG_DBLSCAN))
|
|
|
|
return MODE_NO_DBLESCAN;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2014-12-17 19:56:22 +08:00
|
|
|
if ((mode->flags & DRM_MODE_FLAG_3D_MASK) &&
|
|
|
|
!(flags & DRM_MODE_FLAG_3D_MASK))
|
|
|
|
return MODE_NO_STEREO;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2014-12-17 19:56:22 +08:00
|
|
|
return MODE_OK;
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
static int
|
2017-05-25 22:19:15 +08:00
|
|
|
drm_mode_validate_pipeline(struct drm_display_mode *mode,
|
2020-07-14 01:07:45 +08:00
|
|
|
struct drm_connector *connector,
|
|
|
|
struct drm_modeset_acquire_ctx *ctx,
|
|
|
|
enum drm_mode_status *status)
|
2017-05-25 22:19:15 +08:00
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
2018-06-28 21:13:09 +08:00
|
|
|
struct drm_encoder *encoder;
|
2020-07-14 01:07:45 +08:00
|
|
|
int ret;
|
2017-05-25 22:19:15 +08:00
|
|
|
|
|
|
|
/* Step 1: Validate against connector */
|
2020-07-14 01:07:45 +08:00
|
|
|
ret = drm_connector_mode_valid(connector, mode, ctx, status);
|
|
|
|
if (ret || *status != MODE_OK)
|
2017-05-25 22:19:15 +08:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Step 2: Validate against encoders and crtcs */
|
2019-09-14 07:28:57 +08:00
|
|
|
drm_connector_for_each_possible_encoder(connector, encoder) {
|
2019-12-03 22:15:07 +08:00
|
|
|
struct drm_bridge *bridge;
|
2017-05-25 22:19:15 +08:00
|
|
|
struct drm_crtc *crtc;
|
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
*status = drm_encoder_mode_valid(encoder, mode);
|
|
|
|
if (*status != MODE_OK) {
|
2017-05-25 22:19:15 +08:00
|
|
|
/* No point in continuing for crtc check as this encoder
|
|
|
|
* will not accept the mode anyway. If all encoders
|
|
|
|
* reject the mode then, at exit, ret will not be
|
|
|
|
* MODE_OK. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-03 22:15:07 +08:00
|
|
|
bridge = drm_bridge_chain_get_first_bridge(encoder);
|
Merge tag 'drm-intel-next-2020-07-15' of git://anongit.freedesktop.org/drm/drm-intel into drm-next
drm/i915 features for v5.9, batch #2
Highlights:
- Very early DG1 enabling (Abdiel, Lucas, Anusha)
Gem/GT:
- Fix spinlock recursion on signaling a signaled request (Chris)
- Perf: Use GTT when saving/restoring engine GPR (Umesh Nerlige Ramappa)
- SSEU refactoring, debugfs move under gt/ (Daniele, Venkata Sandeep Dhanalakota)
- Various GT refactoring and cleanup, preparation for future changes (Daniele)
- Adjust HuC state accordingly after GuC fetch error (Michał Winiarski)
- UC debugfs updates (Michał Winiarski)
- Only revoke the GGTT mmappings on aperture detiling changes (Chris)
- Only revoke mmap handlers if active (Chris)
- Split the context's obj:vma lut into its own mutex (Chris)
- Various memory, mmap and performance optimisations (Chris)
- Improve system stability in case of false CS events (Chris)
- Various refactorings and cleanup (Chris)
- Always reset the engine on execlist failures (Chris)
- Trace placement of timeline HWSP (Chris)
- Update dma-attributes for our sg DMA (Chris)
Display:
- TGL CDCLK workaround tweaks to unbreak 8K display support (Stanislav)
- A number of FBC fixes, along with i865 FBC enabling (Ville)
- Validate MST modes against PBN limits (Lyude, Shawn Lee)
- Do not access non-existing swizzle registers (Lucas)
- Revert GEN11+ HBR3 rate fix that caused issues on TGL (Matt Atwood)
- Update TGL+ combo phy initialization to match spec update (José)
- Fix HDCP Content Protection property state machine (Anshuman)
- Fix HDCP revoked keys handling (Ram)
- Improve DDI BUF status checks and waits (Manasi)
- Various SDVO+HDMI+DVI fixes around colorimetry, clocking, pixel repeat etc. (Ville)
- DP voltage swing function refactoring (José)
- WARN if max vswing/pre-emphasis violates the DP spec (Ville)
Other:
- Add new EHL PCI IDs (José)
- Unify struct intel_digital_port variable naming (Lucas)
- Various taint updates to aid debugging and improve CI (Michał Winiarski)
- Straggler conversions to new mmio register accessors (Daniele)
Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/87a70029vz.fsf@intel.com
2020-07-31 03:25:42 +08:00
|
|
|
*status = drm_bridge_chain_mode_valid(bridge,
|
|
|
|
&connector->display_info,
|
|
|
|
mode);
|
2020-07-14 01:07:45 +08:00
|
|
|
if (*status != MODE_OK) {
|
2017-05-25 22:19:15 +08:00
|
|
|
/* There is also no point in continuing for crtc check
|
|
|
|
* here. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_for_each_crtc(crtc, dev) {
|
|
|
|
if (!drm_encoder_crtc_ok(encoder, crtc))
|
|
|
|
continue;
|
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
*status = drm_crtc_mode_valid(crtc, mode);
|
|
|
|
if (*status == MODE_OK) {
|
2017-05-25 22:19:15 +08:00
|
|
|
/* If we get to this point there is at least
|
|
|
|
* one combination of encoder+crtc that works
|
|
|
|
* for this mode. Lets return now. */
|
2020-07-14 01:07:45 +08:00
|
|
|
return 0;
|
2017-05-25 22:19:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
return 0;
|
2017-05-25 22:19:15 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 16:08:32 +08:00
|
|
|
static int drm_helper_probe_add_cmdline_mode(struct drm_connector *connector)
|
|
|
|
{
|
2016-06-01 17:50:51 +08:00
|
|
|
struct drm_cmdline_mode *cmdline_mode;
|
2014-08-06 16:08:32 +08:00
|
|
|
struct drm_display_mode *mode;
|
|
|
|
|
2016-06-01 17:50:51 +08:00
|
|
|
cmdline_mode = &connector->cmdline_mode;
|
|
|
|
if (!cmdline_mode->specified)
|
2014-08-06 16:08:32 +08:00
|
|
|
return 0;
|
|
|
|
|
2016-06-01 17:50:51 +08:00
|
|
|
/* Only add a GTF mode if we find no matching probed modes */
|
|
|
|
list_for_each_entry(mode, &connector->probed_modes, head) {
|
|
|
|
if (mode->hdisplay != cmdline_mode->xres ||
|
|
|
|
mode->vdisplay != cmdline_mode->yres)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cmdline_mode->refresh_specified) {
|
|
|
|
/* The probed mode's vrefresh is set until later */
|
|
|
|
if (drm_mode_vrefresh(mode) != cmdline_mode->refresh)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-02-22 01:33:13 +08:00
|
|
|
/* Mark the matching mode as being preferred by the user */
|
|
|
|
mode->type |= DRM_MODE_TYPE_USERDEF;
|
2016-06-01 17:50:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-06 16:08:32 +08:00
|
|
|
mode = drm_mode_create_from_cmdline_mode(connector->dev,
|
2016-06-01 17:50:51 +08:00
|
|
|
cmdline_mode);
|
2014-08-06 16:08:32 +08:00
|
|
|
if (mode == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-25 22:19:13 +08:00
|
|
|
enum drm_mode_status drm_crtc_mode_valid(struct drm_crtc *crtc,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
|
|
|
|
|
|
|
|
if (!crtc_funcs || !crtc_funcs->mode_valid)
|
|
|
|
return MODE_OK;
|
|
|
|
|
|
|
|
return crtc_funcs->mode_valid(crtc, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum drm_mode_status drm_encoder_mode_valid(struct drm_encoder *encoder,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
const struct drm_encoder_helper_funcs *encoder_funcs =
|
|
|
|
encoder->helper_private;
|
|
|
|
|
|
|
|
if (!encoder_funcs || !encoder_funcs->mode_valid)
|
|
|
|
return MODE_OK;
|
|
|
|
|
|
|
|
return encoder_funcs->mode_valid(encoder, mode);
|
|
|
|
}
|
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
int
|
|
|
|
drm_connector_mode_valid(struct drm_connector *connector,
|
|
|
|
struct drm_display_mode *mode,
|
|
|
|
struct drm_modeset_acquire_ctx *ctx,
|
|
|
|
enum drm_mode_status *status)
|
2017-05-25 22:19:13 +08:00
|
|
|
{
|
|
|
|
const struct drm_connector_helper_funcs *connector_funcs =
|
|
|
|
connector->helper_private;
|
2020-07-14 01:07:45 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!connector_funcs)
|
|
|
|
*status = MODE_OK;
|
|
|
|
else if (connector_funcs->mode_valid_ctx)
|
|
|
|
ret = connector_funcs->mode_valid_ctx(connector, mode, ctx,
|
|
|
|
status);
|
|
|
|
else if (connector_funcs->mode_valid)
|
|
|
|
*status = connector_funcs->mode_valid(connector, mode);
|
|
|
|
else
|
|
|
|
*status = MODE_OK;
|
2017-05-25 22:19:13 +08:00
|
|
|
|
2020-07-14 01:07:45 +08:00
|
|
|
return ret;
|
2017-05-25 22:19:13 +08:00
|
|
|
}
|
|
|
|
|
2023-01-24 18:45:47 +08:00
|
|
|
static void drm_kms_helper_disable_hpd(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_connector *connector;
|
|
|
|
struct drm_connector_list_iter conn_iter;
|
|
|
|
|
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
|
|
|
const struct drm_connector_helper_funcs *funcs =
|
|
|
|
connector->helper_private;
|
|
|
|
|
|
|
|
if (funcs && funcs->disable_hpd)
|
|
|
|
funcs->disable_hpd(connector);
|
|
|
|
}
|
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_kms_helper_enable_hpd(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
bool poll = false;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
struct drm_connector_list_iter conn_iter;
|
|
|
|
|
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
|
|
|
const struct drm_connector_helper_funcs *funcs =
|
|
|
|
connector->helper_private;
|
|
|
|
|
|
|
|
if (funcs && funcs->enable_hpd)
|
|
|
|
funcs->enable_hpd(connector);
|
|
|
|
|
|
|
|
if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT |
|
|
|
|
DRM_CONNECTOR_POLL_DISCONNECT))
|
|
|
|
poll = true;
|
|
|
|
}
|
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
|
|
|
|
|
|
|
return poll;
|
|
|
|
}
|
|
|
|
|
2015-07-10 05:44:26 +08:00
|
|
|
#define DRM_OUTPUT_POLL_PERIOD (10*HZ)
|
2023-08-22 19:30:14 +08:00
|
|
|
static void reschedule_output_poll_work(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
unsigned long delay = DRM_OUTPUT_POLL_PERIOD;
|
|
|
|
|
|
|
|
if (dev->mode_config.delayed_event)
|
|
|
|
/*
|
|
|
|
* FIXME:
|
|
|
|
*
|
|
|
|
* Use short (1s) delay to handle the initial delayed event.
|
|
|
|
* This delay should not be needed, but Optimus/nouveau will
|
|
|
|
* fail in a mysterious way if the delayed event is handled as
|
|
|
|
* soon as possible like it is done in
|
|
|
|
* drm_helper_probe_single_connector_modes() in case the poll
|
|
|
|
* was enabled before.
|
|
|
|
*/
|
|
|
|
delay = HZ;
|
|
|
|
|
|
|
|
schedule_delayed_work(&dev->mode_config.output_poll_work, delay);
|
|
|
|
}
|
|
|
|
|
2015-09-23 22:13:00 +08:00
|
|
|
/**
|
2017-01-27 10:04:08 +08:00
|
|
|
* drm_kms_helper_poll_enable - re-enable output polling.
|
2015-09-23 22:13:00 +08:00
|
|
|
* @dev: drm_device
|
|
|
|
*
|
2017-01-27 10:04:08 +08:00
|
|
|
* This function re-enables the output polling work, after it has been
|
|
|
|
* temporarily disabled using drm_kms_helper_poll_disable(), for example over
|
|
|
|
* suspend/resume.
|
2015-09-23 22:13:00 +08:00
|
|
|
*
|
2017-01-27 10:04:08 +08:00
|
|
|
* Drivers can call this helper from their device resume implementation. It is
|
2017-11-07 03:18:07 +08:00
|
|
|
* not an error to call this even when output polling isn't enabled.
|
2017-01-27 10:04:08 +08:00
|
|
|
*
|
2024-02-02 14:43:28 +08:00
|
|
|
* If device polling was never initialized before, this call will trigger a
|
|
|
|
* warning and return.
|
|
|
|
*
|
2017-01-27 10:04:08 +08:00
|
|
|
* Note that calls to enable and disable polling must be strictly ordered, which
|
|
|
|
* is automatically the case when they're only call from suspend/resume
|
|
|
|
* callbacks.
|
2015-09-23 22:13:00 +08:00
|
|
|
*/
|
2017-01-27 10:04:08 +08:00
|
|
|
void drm_kms_helper_poll_enable(struct drm_device *dev)
|
2015-07-10 05:44:26 +08:00
|
|
|
{
|
2024-02-02 14:43:28 +08:00
|
|
|
if (drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled) ||
|
|
|
|
!drm_kms_helper_poll || dev->mode_config.poll_running)
|
2015-07-10 05:44:26 +08:00
|
|
|
return;
|
|
|
|
|
2023-08-22 19:30:14 +08:00
|
|
|
if (drm_kms_helper_enable_hpd(dev) ||
|
|
|
|
dev->mode_config.delayed_event)
|
|
|
|
reschedule_output_poll_work(dev);
|
2023-01-24 18:45:48 +08:00
|
|
|
|
|
|
|
dev->mode_config.poll_running = true;
|
2015-07-10 05:44:26 +08:00
|
|
|
}
|
2017-01-27 10:04:08 +08:00
|
|
|
EXPORT_SYMBOL(drm_kms_helper_poll_enable);
|
2015-09-23 22:13:00 +08:00
|
|
|
|
2023-08-22 19:30:14 +08:00
|
|
|
/**
|
|
|
|
* drm_kms_helper_poll_reschedule - reschedule the output polling work
|
|
|
|
* @dev: drm_device
|
|
|
|
*
|
|
|
|
* This function reschedules the output polling work, after polling for a
|
|
|
|
* connector has been enabled.
|
|
|
|
*
|
|
|
|
* Drivers must call this helper after enabling polling for a connector by
|
|
|
|
* setting %DRM_CONNECTOR_POLL_CONNECT / %DRM_CONNECTOR_POLL_DISCONNECT flags
|
|
|
|
* in drm_connector::polled. Note that after disabling polling by clearing these
|
|
|
|
* flags for a connector will stop the output polling work automatically if
|
|
|
|
* the polling is disabled for all other connectors as well.
|
|
|
|
*
|
|
|
|
* The function can be called only after polling has been enabled by calling
|
|
|
|
* drm_kms_helper_poll_init() / drm_kms_helper_poll_enable().
|
|
|
|
*/
|
|
|
|
void drm_kms_helper_poll_reschedule(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
if (dev->mode_config.poll_running)
|
|
|
|
reschedule_output_poll_work(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_poll_reschedule);
|
|
|
|
|
2016-11-30 04:56:30 +08:00
|
|
|
static enum drm_connector_status
|
2017-04-07 02:55:20 +08:00
|
|
|
drm_helper_probe_detect_ctx(struct drm_connector *connector, bool force)
|
2016-11-30 04:56:30 +08:00
|
|
|
{
|
2017-04-07 02:55:20 +08:00
|
|
|
const struct drm_connector_helper_funcs *funcs = connector->helper_private;
|
|
|
|
struct drm_modeset_acquire_ctx ctx;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drm_modeset_acquire_init(&ctx, 0);
|
|
|
|
|
|
|
|
retry:
|
|
|
|
ret = drm_modeset_lock(&connector->dev->mode_config.connection_mutex, &ctx);
|
|
|
|
if (!ret) {
|
|
|
|
if (funcs->detect_ctx)
|
|
|
|
ret = funcs->detect_ctx(connector, &ctx, force);
|
|
|
|
else if (connector->funcs->detect)
|
|
|
|
ret = connector->funcs->detect(connector, force);
|
|
|
|
else
|
|
|
|
ret = connector_status_connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WARN_ON(ret < 0))
|
|
|
|
ret = connector_status_unknown;
|
|
|
|
|
2020-06-30 08:26:59 +08:00
|
|
|
if (ret != connector->status)
|
|
|
|
connector->epoch_counter += 1;
|
|
|
|
|
2017-04-07 02:55:20 +08:00
|
|
|
drm_modeset_drop_locks(&ctx);
|
|
|
|
drm_modeset_acquire_fini(&ctx);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_helper_probe_detect - probe connector status
|
|
|
|
* @connector: connector to probe
|
|
|
|
* @ctx: acquire_ctx, or NULL to let this function handle locking.
|
|
|
|
* @force: Whether destructive probe operations should be performed.
|
|
|
|
*
|
|
|
|
* This function calls the detect callbacks of the connector.
|
|
|
|
* This function returns &drm_connector_status, or
|
|
|
|
* if @ctx is set, it might also return -EDEADLK.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_helper_probe_detect(struct drm_connector *connector,
|
|
|
|
struct drm_modeset_acquire_ctx *ctx,
|
|
|
|
bool force)
|
|
|
|
{
|
|
|
|
const struct drm_connector_helper_funcs *funcs = connector->helper_private;
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return drm_helper_probe_detect_ctx(connector, force);
|
|
|
|
|
|
|
|
ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (funcs->detect_ctx)
|
2020-06-30 08:26:59 +08:00
|
|
|
ret = funcs->detect_ctx(connector, ctx, force);
|
2017-04-07 02:55:20 +08:00
|
|
|
else if (connector->funcs->detect)
|
2020-06-30 08:26:59 +08:00
|
|
|
ret = connector->funcs->detect(connector, force);
|
2017-04-07 02:55:20 +08:00
|
|
|
else
|
2020-06-30 08:26:59 +08:00
|
|
|
ret = connector_status_connected;
|
|
|
|
|
|
|
|
if (ret != connector->status)
|
|
|
|
connector->epoch_counter += 1;
|
|
|
|
|
|
|
|
return ret;
|
2016-11-30 04:56:30 +08:00
|
|
|
}
|
2017-04-07 02:55:20 +08:00
|
|
|
EXPORT_SYMBOL(drm_helper_probe_detect);
|
2016-11-30 04:56:30 +08:00
|
|
|
|
2022-06-08 15:50:37 +08:00
|
|
|
static int drm_helper_probe_get_modes(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
const struct drm_connector_helper_funcs *connector_funcs =
|
|
|
|
connector->helper_private;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = connector_funcs->get_modes(connector);
|
|
|
|
|
2024-03-09 00:03:39 +08:00
|
|
|
/* The .get_modes() callback should not return negative values. */
|
|
|
|
if (count < 0) {
|
|
|
|
drm_err(connector->dev, ".get_modes() returned %pe\n",
|
|
|
|
ERR_PTR(count));
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-08 15:50:37 +08:00
|
|
|
/*
|
|
|
|
* Fallback for when DDC probe failed in drm_get_edid() and thus skipped
|
|
|
|
* override/firmware EDID.
|
|
|
|
*/
|
|
|
|
if (count == 0 && connector->status == connector_status_connected)
|
2022-10-24 20:33:34 +08:00
|
|
|
count = drm_edid_override_connector_update(connector);
|
2022-06-08 15:50:37 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2022-05-12 06:58:07 +08:00
|
|
|
static int __drm_helper_update_and_validate(struct drm_connector *connector,
|
|
|
|
uint32_t maxX, uint32_t maxY,
|
|
|
|
struct drm_modeset_acquire_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
int mode_flags = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
drm_connector_list_update(connector);
|
|
|
|
|
|
|
|
if (connector->interlace_allowed)
|
|
|
|
mode_flags |= DRM_MODE_FLAG_INTERLACE;
|
|
|
|
if (connector->doublescan_allowed)
|
|
|
|
mode_flags |= DRM_MODE_FLAG_DBLSCAN;
|
|
|
|
if (connector->stereo_allowed)
|
|
|
|
mode_flags |= DRM_MODE_FLAG_3D_MASK;
|
|
|
|
|
|
|
|
list_for_each_entry(mode, &connector->modes, head) {
|
|
|
|
if (mode->status != MODE_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mode->status = drm_mode_validate_driver(dev, mode);
|
|
|
|
if (mode->status != MODE_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mode->status = drm_mode_validate_size(mode, maxX, maxY);
|
|
|
|
if (mode->status != MODE_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mode->status = drm_mode_validate_flag(mode, mode_flags);
|
|
|
|
if (mode->status != MODE_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = drm_mode_validate_pipeline(mode, connector, ctx,
|
|
|
|
&mode->status);
|
|
|
|
if (ret) {
|
|
|
|
drm_dbg_kms(dev,
|
|
|
|
"drm_mode_validate_pipeline failed: %d\n",
|
|
|
|
ret);
|
|
|
|
|
|
|
|
if (drm_WARN_ON_ONCE(dev, ret != -EDEADLK))
|
|
|
|
mode->status = MODE_ERROR;
|
|
|
|
else
|
|
|
|
return -EDEADLK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode->status != MODE_OK)
|
|
|
|
continue;
|
|
|
|
mode->status = drm_mode_validate_ycbcr420(mode, connector);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 05:14:14 +08:00
|
|
|
/**
|
|
|
|
* drm_helper_probe_single_connector_modes - get complete set of display modes
|
|
|
|
* @connector: connector to probe
|
|
|
|
* @maxX: max width for modes
|
|
|
|
* @maxY: max height for modes
|
|
|
|
*
|
|
|
|
* Based on the helper callbacks implemented by @connector in struct
|
|
|
|
* &drm_connector_helper_funcs try to detect all valid modes. Modes will first
|
|
|
|
* be added to the connector's probed_modes list, then culled (based on validity
|
|
|
|
* and the @maxX, @maxY parameters) and put into the normal modes list.
|
|
|
|
*
|
2017-01-25 14:26:43 +08:00
|
|
|
* Intended to be used as a generic implementation of the
|
|
|
|
* &drm_connector_funcs.fill_modes() vfunc for drivers that use the CRTC helpers
|
|
|
|
* for output mode filtering and detection.
|
2015-12-04 05:14:14 +08:00
|
|
|
*
|
2015-12-11 05:13:57 +08:00
|
|
|
* The basic procedure is as follows
|
|
|
|
*
|
|
|
|
* 1. All modes currently on the connector's modes list are marked as stale
|
|
|
|
*
|
|
|
|
* 2. New modes are added to the connector's probed_modes list with
|
|
|
|
* drm_mode_probed_add(). New modes start their life with status as OK.
|
|
|
|
* Modes are added from a single source using the following priority order.
|
|
|
|
*
|
2017-01-25 14:26:43 +08:00
|
|
|
* - &drm_connector_helper_funcs.get_modes vfunc
|
2015-12-11 05:13:57 +08:00
|
|
|
* - if the connector status is connector_status_connected, standard
|
|
|
|
* VESA DMT modes up to 1024x768 are automatically added
|
|
|
|
* (drm_add_modes_noedid())
|
|
|
|
*
|
|
|
|
* Finally modes specified via the kernel command line (video=...) are
|
|
|
|
* added in addition to what the earlier probes produced
|
|
|
|
* (drm_helper_probe_add_cmdline_mode()). These modes are generated
|
|
|
|
* using the VESA GTF/CVT formulas.
|
|
|
|
*
|
|
|
|
* 3. Modes are moved from the probed_modes list to the modes list. Potential
|
2018-07-09 16:40:08 +08:00
|
|
|
* duplicates are merged together (see drm_connector_list_update()).
|
2015-12-11 05:13:57 +08:00
|
|
|
* After this step the probed_modes list will be empty again.
|
|
|
|
*
|
|
|
|
* 4. Any non-stale mode on the modes list then undergoes validation
|
|
|
|
*
|
|
|
|
* - drm_mode_validate_basic() performs basic sanity checks
|
|
|
|
* - drm_mode_validate_size() filters out modes larger than @maxX and @maxY
|
|
|
|
* (if specified)
|
2017-02-28 06:29:12 +08:00
|
|
|
* - drm_mode_validate_flag() checks the modes against basic connector
|
|
|
|
* capabilities (interlace_allowed,doublescan_allowed,stereo_allowed)
|
2020-07-14 01:07:45 +08:00
|
|
|
* - the optional &drm_connector_helper_funcs.mode_valid or
|
|
|
|
* &drm_connector_helper_funcs.mode_valid_ctx helpers can perform driver
|
|
|
|
* and/or sink specific checks
|
2017-05-25 22:19:15 +08:00
|
|
|
* - the optional &drm_crtc_helper_funcs.mode_valid,
|
|
|
|
* &drm_bridge_funcs.mode_valid and &drm_encoder_helper_funcs.mode_valid
|
|
|
|
* helpers can perform driver and/or source specific checks which are also
|
|
|
|
* enforced by the modeset/atomic helpers
|
2015-12-11 05:13:57 +08:00
|
|
|
*
|
|
|
|
* 5. Any mode whose status is not OK is pruned from the connector's modes list,
|
|
|
|
* accompanied by a debug message indicating the reason for the mode's
|
|
|
|
* rejection (see drm_mode_prune_invalid()).
|
2015-12-04 05:14:14 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The number of modes found on @connector.
|
|
|
|
*/
|
|
|
|
int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
|
|
|
|
uint32_t maxX, uint32_t maxY)
|
2014-04-10 16:51:11 +08:00
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_display_mode *mode;
|
2017-04-07 02:55:20 +08:00
|
|
|
int count = 0, ret;
|
2015-01-21 15:45:21 +08:00
|
|
|
enum drm_connector_status old_status;
|
2017-04-07 02:55:20 +08:00
|
|
|
struct drm_modeset_acquire_ctx ctx;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
|
|
|
|
|
2017-04-07 02:55:20 +08:00
|
|
|
drm_modeset_acquire_init(&ctx, 0);
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
|
2014-06-03 19:56:20 +08:00
|
|
|
connector->name);
|
2017-04-07 02:55:20 +08:00
|
|
|
|
|
|
|
retry:
|
|
|
|
ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
|
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
|
|
|
} else
|
|
|
|
WARN_ON(ret < 0);
|
|
|
|
|
2015-12-11 04:39:08 +08:00
|
|
|
/* set all old modes to the stale state */
|
2014-04-10 16:51:11 +08:00
|
|
|
list_for_each_entry(mode, &connector->modes, head)
|
2015-12-11 04:39:08 +08:00
|
|
|
mode->status = MODE_STALE;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2015-11-20 00:46:50 +08:00
|
|
|
old_status = connector->status;
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
if (connector->force) {
|
2014-11-04 09:51:45 +08:00
|
|
|
if (connector->force == DRM_FORCE_ON ||
|
|
|
|
connector->force == DRM_FORCE_ON_DIGITAL)
|
2014-04-10 16:51:11 +08:00
|
|
|
connector->status = connector_status_connected;
|
|
|
|
else
|
|
|
|
connector->status = connector_status_disconnected;
|
|
|
|
if (connector->funcs->force)
|
|
|
|
connector->funcs->force(connector);
|
|
|
|
} else {
|
2017-04-07 02:55:20 +08:00
|
|
|
ret = drm_helper_probe_detect(connector, &ctx, true);
|
|
|
|
|
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
|
|
|
} else if (WARN(ret < 0, "Invalid return value %i for connector detection\n", ret))
|
|
|
|
ret = connector_status_unknown;
|
|
|
|
|
|
|
|
connector->status = ret;
|
2015-11-20 00:46:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally either the driver's hpd code or the poll loop should
|
|
|
|
* pick up any changes and fire the hotplug event. But if
|
|
|
|
* userspace sneaks in a probe, we might miss a change. Hence
|
|
|
|
* check here, and if anything changed start the hotplug code.
|
|
|
|
*/
|
|
|
|
if (old_status != connector->status) {
|
2015-12-03 20:00:03 +08:00
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
|
2015-11-20 00:46:50 +08:00
|
|
|
connector->base.id,
|
|
|
|
connector->name,
|
2015-12-03 20:00:03 +08:00
|
|
|
drm_get_connector_status_name(old_status),
|
|
|
|
drm_get_connector_status_name(connector->status));
|
2015-01-21 15:45:21 +08:00
|
|
|
|
|
|
|
/*
|
2015-11-20 00:46:50 +08:00
|
|
|
* The hotplug event code might call into the fb
|
|
|
|
* helpers, and so expects that we do not hold any
|
|
|
|
* locks. Fire up the poll struct instead, it will
|
|
|
|
* disable itself again.
|
2015-01-21 15:45:21 +08:00
|
|
|
*/
|
2015-11-20 00:46:50 +08:00
|
|
|
dev->mode_config.delayed_event = true;
|
|
|
|
if (dev->mode_config.poll_enabled)
|
2023-01-27 23:40:52 +08:00
|
|
|
mod_delayed_work(system_wq,
|
|
|
|
&dev->mode_config.output_poll_work,
|
|
|
|
0);
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
|
2024-02-02 14:43:44 +08:00
|
|
|
/*
|
|
|
|
* Re-enable polling in case the global poll config changed but polling
|
|
|
|
* is still initialized.
|
|
|
|
*/
|
|
|
|
if (dev->mode_config.poll_enabled)
|
|
|
|
drm_kms_helper_poll_enable(dev);
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
if (connector->status == connector_status_disconnected) {
|
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
|
2014-06-03 19:56:20 +08:00
|
|
|
connector->base.id, connector->name);
|
2018-07-09 16:40:06 +08:00
|
|
|
drm_connector_update_edid_property(connector, NULL);
|
2022-05-12 06:58:08 +08:00
|
|
|
drm_mode_prune_invalid(dev, &connector->modes, false);
|
|
|
|
goto exit;
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
|
2022-06-08 15:50:37 +08:00
|
|
|
count = drm_helper_probe_get_modes(connector);
|
drm: add fallback override/firmware EDID modes workaround
We've moved the override and firmware EDID (simply "override EDID" from
now on) handling to the low level drm_do_get_edid() function in order to
transparently use the override throughout the stack. The idea is that
you get the override EDID via the ->get_modes() hook.
Unfortunately, there are scenarios where the DDC probe in drm_get_edid()
called via ->get_modes() fails, although the preceding ->detect()
succeeds.
In the case reported by Paul Wise, the ->detect() hook,
intel_crt_detect(), relies on hotplug detect, bypassing the DDC. In the
case reported by Ilpo Järvinen, there is no ->detect() hook, which is
interpreted as connected. The subsequent DDC probe reached via
->get_modes() fails, and we don't even look at the override EDID,
resulting in no modes being added.
Because drm_get_edid() is used via ->detect() all over the place, we
can't trivially remove the DDC probe, as it leads to override EDID
effectively meaning connector forcing. The goal is that connector
forcing and override EDID remain orthogonal.
Generally, the underlying problem here is the conflation of ->detect()
and ->get_modes() via drm_get_edid(). The former should just detect, and
the latter should just get the modes, typically via reading the EDID. As
long as drm_get_edid() is used in ->detect(), it needs to retain the DDC
probe. Or such users need to have a separate DDC probe step first.
The EDID caching between ->detect() and ->get_modes() done by some
drivers is a further complication that prevents us from making
drm_do_get_edid() adapt to the two cases.
Work around the regression by falling back to a separate attempt at
getting the override EDID at drm_helper_probe_single_connector_modes()
level. With a working DDC and override EDID, it'll never be called; the
override EDID will come via ->get_modes(). There will still be a failing
DDC probe attempt in the cases that require the fallback.
v2:
- Call drm_connector_update_edid_property (Paul)
- Update commit message about EDID caching (Daniel)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107583
Reported-by: Paul Wise <pabs3@bonedaddy.net>
Cc: Paul Wise <pabs3@bonedaddy.net>
References: http://mid.mail-archive.com/alpine.DEB.2.20.1905262211270.24390@whs-18.cs.helsinki.fi
Reported-by: Ilpo Järvinen <ilpo.jarvinen@cs.helsinki.fi>
Cc: Ilpo Järvinen <ilpo.jarvinen@cs.helsinki.fi>
Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
References: 15f080f08d48 ("drm/edid: respect connector force for drm_get_edid ddc probe")
Fixes: 53fd40a90f3c ("drm: handle override and firmware EDID at drm_do_get_edid() level")
Cc: <stable@vger.kernel.org> # v4.15+ 56a2b7f2a39a drm/edid: abstract override/firmware EDID retrieval
Cc: <stable@vger.kernel.org> # v4.15+
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Harish Chegondi <harish.chegondi@intel.com>
Tested-by: Paul Wise <pabs3@bonedaddy.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190610093054.28445-1-jani.nikula@intel.com
2019-06-10 17:30:54 +08:00
|
|
|
|
2013-06-14 08:55:25 +08:00
|
|
|
if (count == 0 && (connector->status == connector_status_connected ||
|
2022-06-02 02:23:24 +08:00
|
|
|
connector->status == connector_status_unknown)) {
|
2014-04-10 16:51:11 +08:00
|
|
|
count = drm_add_modes_noedid(connector, 1024, 768);
|
2022-06-02 02:23:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Section 4.2.2.6 (EDID Corruption Detection) of the DP 1.4a
|
|
|
|
* Link CTS specifies that 640x480 (the official "failsafe"
|
|
|
|
* mode) needs to be the default if there's no EDID.
|
|
|
|
*/
|
|
|
|
if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort)
|
|
|
|
drm_set_preferred_mode(connector, 640, 480);
|
|
|
|
}
|
2014-08-06 16:08:32 +08:00
|
|
|
count += drm_helper_probe_add_cmdline_mode(connector);
|
2022-05-12 06:58:07 +08:00
|
|
|
if (count != 0) {
|
|
|
|
ret = __drm_helper_update_and_validate(connector, maxX, maxY, &ctx);
|
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
2020-07-14 01:07:45 +08:00
|
|
|
}
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 06:58:08 +08:00
|
|
|
drm_mode_prune_invalid(dev, &connector->modes, true);
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2022-05-12 06:58:08 +08:00
|
|
|
/*
|
|
|
|
* Displayport spec section 5.2.1.2 ("Video Timing Format") says that
|
|
|
|
* all detachable sinks shall support 640x480 @60Hz as a fail safe
|
|
|
|
* mode. If all modes were pruned, perhaps because they need more
|
|
|
|
* lanes or a higher pixel clock than available, at least try to add
|
|
|
|
* in 640x480.
|
|
|
|
*/
|
|
|
|
if (list_empty(&connector->modes) &&
|
|
|
|
connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
|
|
|
|
count = drm_add_modes_noedid(connector, 640, 480);
|
|
|
|
ret = __drm_helper_update_and_validate(connector, maxX, maxY, &ctx);
|
|
|
|
if (ret == -EDEADLK) {
|
|
|
|
drm_modeset_backoff(&ctx);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
drm_mode_prune_invalid(dev, &connector->modes, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2017-04-07 02:55:20 +08:00
|
|
|
drm_modeset_drop_locks(&ctx);
|
|
|
|
drm_modeset_acquire_fini(&ctx);
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
if (list_empty(&connector->modes))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
drm_mode_sort(&connector->modes);
|
|
|
|
|
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id,
|
2014-06-03 19:56:20 +08:00
|
|
|
connector->name);
|
2014-04-10 16:51:11 +08:00
|
|
|
list_for_each_entry(mode, &connector->modes, head) {
|
|
|
|
drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
|
|
|
|
drm_mode_debug_printmodeline(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_kms_helper_hotplug_event - fire off KMS hotplug events
|
|
|
|
* @dev: drm_device whose connector state changed
|
|
|
|
*
|
|
|
|
* This function fires off the uevent for userspace and also calls the
|
|
|
|
* output_poll_changed function, which is most commonly used to inform the fbdev
|
|
|
|
* emulation code and allow it to update the fbcon output configuration.
|
|
|
|
*
|
|
|
|
* Drivers should call this from their hotplug handling code when a change is
|
|
|
|
* detected. Note that this function does not do any output detection of its
|
|
|
|
* own, like drm_helper_hpd_irq_event() does - this is assumed to be done by the
|
|
|
|
* driver already.
|
|
|
|
*
|
|
|
|
* This function must be called from process context with no mode
|
|
|
|
* setting locks held.
|
2021-10-18 16:47:26 +08:00
|
|
|
*
|
|
|
|
* If only a single connector has changed, consider calling
|
|
|
|
* drm_kms_helper_connector_hotplug_event() instead.
|
2014-04-10 16:51:11 +08:00
|
|
|
*/
|
|
|
|
void drm_kms_helper_hotplug_event(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
/* send a uevent + call fbdev */
|
|
|
|
drm_sysfs_hotplug_event(dev);
|
|
|
|
if (dev->mode_config.funcs->output_poll_changed)
|
|
|
|
dev->mode_config.funcs->output_poll_changed(dev);
|
2018-07-04 00:03:47 +08:00
|
|
|
|
|
|
|
drm_client_dev_hotplug(dev);
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_hotplug_event);
|
|
|
|
|
2021-10-18 16:47:26 +08:00
|
|
|
/**
|
|
|
|
* drm_kms_helper_connector_hotplug_event - fire off a KMS connector hotplug event
|
|
|
|
* @connector: drm_connector which has changed
|
|
|
|
*
|
|
|
|
* This is the same as drm_kms_helper_hotplug_event(), except it fires a more
|
|
|
|
* fine-grained uevent for a single connector.
|
|
|
|
*/
|
|
|
|
void drm_kms_helper_connector_hotplug_event(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
|
|
|
|
/* send a uevent + call fbdev */
|
|
|
|
drm_sysfs_connector_hotplug_event(connector);
|
|
|
|
if (dev->mode_config.funcs->output_poll_changed)
|
|
|
|
dev->mode_config.funcs->output_poll_changed(dev);
|
|
|
|
|
|
|
|
drm_client_dev_hotplug(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_connector_hotplug_event);
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
static void output_poll_execute(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct delayed_work *delayed_work = to_delayed_work(work);
|
|
|
|
struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work);
|
|
|
|
struct drm_connector *connector;
|
2016-12-15 23:58:43 +08:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2014-04-10 16:51:11 +08:00
|
|
|
enum drm_connector_status old_status;
|
2015-01-21 15:45:21 +08:00
|
|
|
bool repoll = false, changed;
|
2021-03-13 19:25:44 +08:00
|
|
|
u64 old_epoch_counter;
|
2015-01-21 15:45:21 +08:00
|
|
|
|
2019-06-03 21:58:57 +08:00
|
|
|
if (!dev->mode_config.poll_enabled)
|
|
|
|
return;
|
|
|
|
|
2015-01-21 15:45:21 +08:00
|
|
|
/* Pick up any changes detected by the probe functions. */
|
|
|
|
changed = dev->mode_config.delayed_event;
|
|
|
|
dev->mode_config.delayed_event = false;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2024-03-01 23:22:43 +08:00
|
|
|
if (!drm_kms_helper_poll) {
|
|
|
|
if (dev->mode_config.poll_running) {
|
|
|
|
drm_kms_helper_disable_hpd(dev);
|
|
|
|
dev->mode_config.poll_running = false;
|
|
|
|
}
|
2015-01-21 15:45:21 +08:00
|
|
|
goto out;
|
2023-01-24 18:45:48 +08:00
|
|
|
}
|
2014-04-10 16:51:11 +08:00
|
|
|
|
2016-12-06 19:37:15 +08:00
|
|
|
if (!mutex_trylock(&dev->mode_config.mutex)) {
|
|
|
|
repoll = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-28 22:46:43 +08:00
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
2016-12-15 23:58:43 +08:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
2014-04-10 16:51:11 +08:00
|
|
|
/* Ignore forced connectors. */
|
|
|
|
if (connector->force)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ignore HPD capable connectors and connectors where we don't
|
|
|
|
* want any hotplug detection at all for polling. */
|
|
|
|
if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
old_status = connector->status;
|
|
|
|
/* if we are connected and don't want to poll for disconnect
|
|
|
|
skip it */
|
|
|
|
if (old_status == connector_status_connected &&
|
|
|
|
!(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT))
|
|
|
|
continue;
|
|
|
|
|
2015-04-16 20:16:29 +08:00
|
|
|
repoll = true;
|
|
|
|
|
2021-03-13 19:25:44 +08:00
|
|
|
old_epoch_counter = connector->epoch_counter;
|
2017-04-07 02:55:20 +08:00
|
|
|
connector->status = drm_helper_probe_detect(connector, NULL, false);
|
2021-03-13 19:25:44 +08:00
|
|
|
if (old_epoch_counter != connector->epoch_counter) {
|
2014-04-10 16:51:11 +08:00
|
|
|
const char *old, *new;
|
|
|
|
|
2015-01-21 15:45:22 +08:00
|
|
|
/*
|
|
|
|
* The poll work sets force=false when calling detect so
|
|
|
|
* that drivers can avoid to do disruptive tests (e.g.
|
|
|
|
* when load detect cycles could cause flickering on
|
|
|
|
* other, running displays). This bears the risk that we
|
|
|
|
* flip-flop between unknown here in the poll work and
|
|
|
|
* the real state when userspace forces a full detect
|
|
|
|
* call after receiving a hotplug event due to this
|
|
|
|
* change.
|
|
|
|
*
|
|
|
|
* Hence clamp an unknown detect status to the old
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
if (connector->status == connector_status_unknown) {
|
|
|
|
connector->status = old_status;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
old = drm_get_connector_status_name(old_status);
|
|
|
|
new = drm_get_connector_status_name(connector->status);
|
|
|
|
|
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] "
|
|
|
|
"status updated from %s to %s\n",
|
|
|
|
connector->base.id,
|
2014-06-03 19:56:20 +08:00
|
|
|
connector->name,
|
2014-04-10 16:51:11 +08:00
|
|
|
old, new);
|
2021-03-13 19:25:44 +08:00
|
|
|
DRM_DEBUG_KMS("[CONNECTOR:%d:%s] epoch counter %llu -> %llu\n",
|
|
|
|
connector->base.id, connector->name,
|
|
|
|
old_epoch_counter, connector->epoch_counter);
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 22:46:43 +08:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
mutex_unlock(&dev->mode_config.mutex);
|
|
|
|
|
2015-01-21 15:45:21 +08:00
|
|
|
out:
|
2014-04-10 16:51:11 +08:00
|
|
|
if (changed)
|
|
|
|
drm_kms_helper_hotplug_event(dev);
|
|
|
|
|
|
|
|
if (repoll)
|
|
|
|
schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD);
|
|
|
|
}
|
|
|
|
|
2018-02-14 13:41:25 +08:00
|
|
|
/**
|
|
|
|
* drm_kms_helper_is_poll_worker - is %current task an output poll worker?
|
|
|
|
*
|
|
|
|
* Determine if %current task is an output poll worker. This can be used
|
|
|
|
* to select distinct code paths for output polling versus other contexts.
|
|
|
|
*
|
|
|
|
* One use case is to avoid a deadlock between the output poll worker and
|
|
|
|
* the autosuspend worker wherein the latter waits for polling to finish
|
|
|
|
* upon calling drm_kms_helper_poll_disable(), while the former waits for
|
|
|
|
* runtime suspend to finish upon calling pm_runtime_get_sync() in a
|
|
|
|
* connector ->detect hook.
|
|
|
|
*/
|
|
|
|
bool drm_kms_helper_is_poll_worker(void)
|
|
|
|
{
|
|
|
|
struct work_struct *work = current_work();
|
|
|
|
|
|
|
|
return work && work->func == output_poll_execute;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_is_poll_worker);
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
/**
|
|
|
|
* drm_kms_helper_poll_disable - disable output polling
|
|
|
|
* @dev: drm_device
|
|
|
|
*
|
|
|
|
* This function disables the output polling work.
|
|
|
|
*
|
|
|
|
* Drivers can call this helper from their device suspend implementation. It is
|
2017-01-27 10:04:08 +08:00
|
|
|
* not an error to call this even when output polling isn't enabled or already
|
|
|
|
* disabled. Polling is re-enabled by calling drm_kms_helper_poll_enable().
|
|
|
|
*
|
2024-02-02 14:43:28 +08:00
|
|
|
* If however, the polling was never initialized, this call will trigger a
|
|
|
|
* warning and return
|
|
|
|
*
|
2017-01-27 10:04:08 +08:00
|
|
|
* Note that calls to enable and disable polling must be strictly ordered, which
|
|
|
|
* is automatically the case when they're only call from suspend/resume
|
|
|
|
* callbacks.
|
2014-04-10 16:51:11 +08:00
|
|
|
*/
|
|
|
|
void drm_kms_helper_poll_disable(struct drm_device *dev)
|
|
|
|
{
|
2024-02-02 14:43:28 +08:00
|
|
|
if (drm_WARN_ON(dev, !dev->mode_config.poll_enabled))
|
|
|
|
return;
|
|
|
|
|
2023-01-24 18:45:48 +08:00
|
|
|
if (dev->mode_config.poll_running)
|
|
|
|
drm_kms_helper_disable_hpd(dev);
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
|
|
|
|
|
|
|
|
dev->mode_config.poll_running = false;
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_poll_disable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_kms_helper_poll_init - initialize and enable output polling
|
|
|
|
* @dev: drm_device
|
|
|
|
*
|
2021-07-30 21:27:29 +08:00
|
|
|
* This function initializes and then also enables output polling support for
|
2014-04-10 16:51:11 +08:00
|
|
|
* @dev. Drivers which do not have reliable hotplug support in hardware can use
|
|
|
|
* this helper infrastructure to regularly poll such connectors for changes in
|
|
|
|
* their connection state.
|
|
|
|
*
|
|
|
|
* Drivers can control which connectors are polled by setting the
|
|
|
|
* DRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags. On
|
|
|
|
* connectors where probing live outputs can result in visual distortion drivers
|
|
|
|
* should not set the DRM_CONNECTOR_POLL_DISCONNECT flag to avoid this.
|
|
|
|
* Connectors which have no flag or only DRM_CONNECTOR_POLL_HPD set are
|
|
|
|
* completely ignored by the polling logic.
|
|
|
|
*
|
|
|
|
* Note that a connector can be both polled and probed from the hotplug handler,
|
|
|
|
* in case the hotplug interrupt is known to be unreliable.
|
|
|
|
*/
|
|
|
|
void drm_kms_helper_poll_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute);
|
|
|
|
dev->mode_config.poll_enabled = true;
|
|
|
|
|
|
|
|
drm_kms_helper_poll_enable(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_poll_init);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_kms_helper_poll_fini - disable output polling and clean it up
|
|
|
|
* @dev: drm_device
|
|
|
|
*/
|
|
|
|
void drm_kms_helper_poll_fini(struct drm_device *dev)
|
|
|
|
{
|
2023-01-24 18:45:48 +08:00
|
|
|
if (!dev->mode_config.poll_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
drm_kms_helper_poll_disable(dev);
|
|
|
|
|
|
|
|
dev->mode_config.poll_enabled = false;
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_kms_helper_poll_fini);
|
|
|
|
|
2021-09-14 18:17:23 +08:00
|
|
|
static bool check_connector_changed(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
enum drm_connector_status old_status;
|
|
|
|
u64 old_epoch_counter;
|
|
|
|
|
|
|
|
/* Only handle HPD capable connectors. */
|
|
|
|
drm_WARN_ON(dev, !(connector->polled & DRM_CONNECTOR_POLL_HPD));
|
|
|
|
|
|
|
|
drm_WARN_ON(dev, !mutex_is_locked(&dev->mode_config.mutex));
|
|
|
|
|
|
|
|
old_status = connector->status;
|
|
|
|
old_epoch_counter = connector->epoch_counter;
|
|
|
|
connector->status = drm_helper_probe_detect(connector, NULL, false);
|
|
|
|
|
|
|
|
if (old_epoch_counter == connector->epoch_counter) {
|
|
|
|
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Same epoch counter %llu\n",
|
|
|
|
connector->base.id,
|
|
|
|
connector->name,
|
|
|
|
connector->epoch_counter);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] status updated from %s to %s\n",
|
|
|
|
connector->base.id,
|
|
|
|
connector->name,
|
|
|
|
drm_get_connector_status_name(old_status),
|
|
|
|
drm_get_connector_status_name(connector->status));
|
|
|
|
|
|
|
|
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Changed epoch counter %llu => %llu\n",
|
|
|
|
connector->base.id,
|
|
|
|
connector->name,
|
|
|
|
old_epoch_counter,
|
|
|
|
connector->epoch_counter);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_connector_helper_hpd_irq_event - hotplug processing
|
|
|
|
* @connector: drm_connector
|
|
|
|
*
|
|
|
|
* Drivers can use this helper function to run a detect cycle on a connector
|
|
|
|
* which has the DRM_CONNECTOR_POLL_HPD flag set in its &polled member.
|
|
|
|
*
|
|
|
|
* This helper function is useful for drivers which can track hotplug
|
|
|
|
* interrupts for a single connector. Drivers that want to send a
|
|
|
|
* hotplug event for all connectors or can't track hotplug interrupts
|
|
|
|
* per connector need to use drm_helper_hpd_irq_event().
|
|
|
|
*
|
|
|
|
* This function must be called from process context with no mode
|
|
|
|
* setting locks held.
|
|
|
|
*
|
|
|
|
* Note that a connector can be both polled and probed from the hotplug
|
|
|
|
* handler, in case the hotplug interrupt is known to be unreliable.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* A boolean indicating whether the connector status changed or not
|
|
|
|
*/
|
|
|
|
bool drm_connector_helper_hpd_irq_event(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
bool changed;
|
|
|
|
|
|
|
|
mutex_lock(&dev->mode_config.mutex);
|
|
|
|
changed = check_connector_changed(connector);
|
|
|
|
mutex_unlock(&dev->mode_config.mutex);
|
|
|
|
|
|
|
|
if (changed) {
|
2021-10-18 16:47:30 +08:00
|
|
|
drm_kms_helper_connector_hotplug_event(connector);
|
2021-09-14 18:17:23 +08:00
|
|
|
drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Sent hotplug event\n",
|
|
|
|
connector->base.id,
|
|
|
|
connector->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_connector_helper_hpd_irq_event);
|
|
|
|
|
2014-04-10 16:51:11 +08:00
|
|
|
/**
|
|
|
|
* drm_helper_hpd_irq_event - hotplug processing
|
|
|
|
* @dev: drm_device
|
|
|
|
*
|
|
|
|
* Drivers can use this helper function to run a detect cycle on all connectors
|
|
|
|
* which have the DRM_CONNECTOR_POLL_HPD flag set in their &polled member. All
|
|
|
|
* other connectors are ignored, which is useful to avoid reprobing fixed
|
|
|
|
* panels.
|
|
|
|
*
|
|
|
|
* This helper function is useful for drivers which can't or don't track hotplug
|
|
|
|
* interrupts for each connector.
|
|
|
|
*
|
|
|
|
* Drivers which support hotplug interrupts for each connector individually and
|
2021-09-14 18:17:23 +08:00
|
|
|
* which have a more fine-grained detect logic can use
|
|
|
|
* drm_connector_helper_hpd_irq_event(). Alternatively, they should bypass this
|
|
|
|
* code and directly call drm_kms_helper_hotplug_event() in case the connector
|
|
|
|
* state changed.
|
2014-04-10 16:51:11 +08:00
|
|
|
*
|
|
|
|
* This function must be called from process context with no mode
|
|
|
|
* setting locks held.
|
|
|
|
*
|
|
|
|
* Note that a connector can be both polled and probed from the hotplug handler,
|
|
|
|
* in case the hotplug interrupt is known to be unreliable.
|
2021-09-14 18:17:22 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* A boolean indicating whether the connector status changed or not
|
2014-04-10 16:51:11 +08:00
|
|
|
*/
|
|
|
|
bool drm_helper_hpd_irq_event(struct drm_device *dev)
|
|
|
|
{
|
2021-10-18 16:47:30 +08:00
|
|
|
struct drm_connector *connector, *first_changed_connector = NULL;
|
2016-12-15 23:58:43 +08:00
|
|
|
struct drm_connector_list_iter conn_iter;
|
2021-10-18 16:47:30 +08:00
|
|
|
int changed = 0;
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
if (!dev->mode_config.poll_enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mutex_lock(&dev->mode_config.mutex);
|
2017-02-28 22:46:43 +08:00
|
|
|
drm_connector_list_iter_begin(dev, &conn_iter);
|
2016-12-15 23:58:43 +08:00
|
|
|
drm_for_each_connector_iter(connector, &conn_iter) {
|
2014-04-10 16:51:11 +08:00
|
|
|
/* Only handle HPD capable connectors. */
|
|
|
|
if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
|
|
|
|
continue;
|
|
|
|
|
2021-10-18 16:47:30 +08:00
|
|
|
if (check_connector_changed(connector)) {
|
|
|
|
if (!first_changed_connector) {
|
|
|
|
drm_connector_get(connector);
|
|
|
|
first_changed_connector = connector;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed++;
|
|
|
|
}
|
2014-04-10 16:51:11 +08:00
|
|
|
}
|
2017-02-28 22:46:43 +08:00
|
|
|
drm_connector_list_iter_end(&conn_iter);
|
2014-04-10 16:51:11 +08:00
|
|
|
mutex_unlock(&dev->mode_config.mutex);
|
|
|
|
|
2021-10-18 16:47:30 +08:00
|
|
|
if (changed == 1)
|
|
|
|
drm_kms_helper_connector_hotplug_event(first_changed_connector);
|
|
|
|
else if (changed > 0)
|
2014-04-10 16:51:11 +08:00
|
|
|
drm_kms_helper_hotplug_event(dev);
|
2021-10-18 16:47:30 +08:00
|
|
|
|
|
|
|
if (first_changed_connector)
|
|
|
|
drm_connector_put(first_changed_connector);
|
2014-04-10 16:51:11 +08:00
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_helper_hpd_irq_event);
|
2022-05-16 21:43:39 +08:00
|
|
|
|
2022-09-05 22:16:46 +08:00
|
|
|
/**
|
|
|
|
* drm_crtc_helper_mode_valid_fixed - Validates a display mode
|
|
|
|
* @crtc: the crtc
|
|
|
|
* @mode: the mode to validate
|
|
|
|
* @fixed_mode: the display hardware's mode
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* MODE_OK on success, or another mode-status code otherwise.
|
|
|
|
*/
|
|
|
|
enum drm_mode_status drm_crtc_helper_mode_valid_fixed(struct drm_crtc *crtc,
|
|
|
|
const struct drm_display_mode *mode,
|
|
|
|
const struct drm_display_mode *fixed_mode)
|
|
|
|
{
|
|
|
|
if (mode->hdisplay != fixed_mode->hdisplay && mode->vdisplay != fixed_mode->vdisplay)
|
|
|
|
return MODE_ONE_SIZE;
|
|
|
|
else if (mode->hdisplay != fixed_mode->hdisplay)
|
|
|
|
return MODE_ONE_WIDTH;
|
|
|
|
else if (mode->vdisplay != fixed_mode->vdisplay)
|
|
|
|
return MODE_ONE_HEIGHT;
|
|
|
|
|
|
|
|
return MODE_OK;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_crtc_helper_mode_valid_fixed);
|
|
|
|
|
2022-09-05 22:16:45 +08:00
|
|
|
/**
|
|
|
|
* drm_connector_helper_get_modes_fixed - Duplicates a display mode for a connector
|
|
|
|
* @connector: the connector
|
|
|
|
* @fixed_mode: the display hardware's mode
|
|
|
|
*
|
|
|
|
* This function duplicates a display modes for a connector. Drivers for hardware
|
|
|
|
* that only supports a single fixed mode can use this function in their connector's
|
|
|
|
* get_modes helper.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The number of created modes.
|
|
|
|
*/
|
|
|
|
int drm_connector_helper_get_modes_fixed(struct drm_connector *connector,
|
|
|
|
const struct drm_display_mode *fixed_mode)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
|
|
|
|
mode = drm_mode_duplicate(dev, fixed_mode);
|
|
|
|
if (!mode) {
|
|
|
|
drm_err(dev, "Failed to duplicate mode " DRM_MODE_FMT "\n",
|
|
|
|
DRM_MODE_ARG(fixed_mode));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode->name[0] == '\0')
|
|
|
|
drm_mode_set_name(mode);
|
|
|
|
|
|
|
|
mode->type |= DRM_MODE_TYPE_PREFERRED;
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
|
|
|
|
if (mode->width_mm)
|
|
|
|
connector->display_info.width_mm = mode->width_mm;
|
|
|
|
if (mode->height_mm)
|
|
|
|
connector->display_info.height_mm = mode->height_mm;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_connector_helper_get_modes_fixed);
|
|
|
|
|
2022-06-29 17:27:51 +08:00
|
|
|
/**
|
|
|
|
* drm_connector_helper_get_modes - Read EDID and update connector.
|
|
|
|
* @connector: The connector
|
|
|
|
*
|
|
|
|
* Read the EDID using drm_edid_read() (which requires that connector->ddc is
|
|
|
|
* set), and update the connector using the EDID.
|
|
|
|
*
|
|
|
|
* This can be used as the "default" connector helper .get_modes() hook if the
|
|
|
|
* driver does not need any special processing. This is sets the example what
|
|
|
|
* custom .get_modes() hooks should do regarding EDID read and connector update.
|
|
|
|
*
|
|
|
|
* Returns: Number of modes.
|
|
|
|
*/
|
|
|
|
int drm_connector_helper_get_modes(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
const struct drm_edid *drm_edid;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
drm_edid = drm_edid_read(connector);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unconditionally update the connector. If the EDID was read
|
|
|
|
* successfully, fill in the connector information derived from the
|
|
|
|
* EDID. Otherwise, if the EDID is NULL, clear the connector
|
|
|
|
* information.
|
|
|
|
*/
|
drm/edid: add separate drm_edid_connector_add_modes()
The original goal with drm_edid_connector_update() was to have a single
call for updating the connector and adding probed modes, in this order,
but that turned out to be problematic. Drivers that need to update the
connector in the .detect() callback would end up updating the probed
modes as well. Turns out the callback may be called so many times that
the probed mode list fills up without bounds, and this is amplified by
add_alternate_cea_modes() duplicating the CEA modes on every call,
actually running out of memory on some machines.
Kudos to Imre Deak <imre.deak@intel.com> for explaining this to me.
Go back to having separate drm_edid_connector_update() and
drm_edid_connector_add_modes() calls. The former may be called from
.detect(), .force(), or .get_modes(), but the latter only from
.get_modes().
Unlike drm_add_edid_modes(), have drm_edid_connector_add_modes() update
the probed modes from the EDID property instead of the passed in
EDID. This is mainly to enforce two things:
1) drm_edid_connector_update() must be called before
drm_edid_connector_add_modes().
Display info and quirks are needed for parsing the modes, and we
don't want to call update_display_info() again to ensure the info is
available, like drm_add_edid_modes() does.
2) The same EDID is used for both updating the connector and adding the
probed modes.
Fortunately, the change is easy, because no driver has actually adopted
drm_edid_connector_update(). Not even i915, and that's mainly because of
the problem described above.
Cc: Imre Deak <imre.deak@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/e86fff1579f14ebf6334692526c8f6831cd02cac.1674144945.git.jani.nikula@intel.com
2023-01-20 00:18:56 +08:00
|
|
|
drm_edid_connector_update(connector, drm_edid);
|
|
|
|
|
|
|
|
count = drm_edid_connector_add_modes(connector);
|
2022-06-29 17:27:51 +08:00
|
|
|
|
|
|
|
drm_edid_free(drm_edid);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_connector_helper_get_modes);
|
2022-11-17 17:28:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_connector_helper_tv_get_modes - Fills the modes availables to a TV connector
|
|
|
|
* @connector: The connector
|
|
|
|
*
|
|
|
|
* Fills the available modes for a TV connector based on the supported
|
|
|
|
* TV modes, and the default mode expressed by the kernel command line.
|
|
|
|
*
|
|
|
|
* This can be used as the default TV connector helper .get_modes() hook
|
|
|
|
* if the driver does not need any special processing.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The number of modes added to the connector.
|
|
|
|
*/
|
|
|
|
int drm_connector_helper_tv_get_modes(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = connector->dev;
|
|
|
|
struct drm_property *tv_mode_property =
|
|
|
|
dev->mode_config.tv_mode_property;
|
|
|
|
struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
|
|
|
|
unsigned int ntsc_modes = BIT(DRM_MODE_TV_MODE_NTSC) |
|
|
|
|
BIT(DRM_MODE_TV_MODE_NTSC_443) |
|
|
|
|
BIT(DRM_MODE_TV_MODE_NTSC_J) |
|
|
|
|
BIT(DRM_MODE_TV_MODE_PAL_M);
|
|
|
|
unsigned int pal_modes = BIT(DRM_MODE_TV_MODE_PAL) |
|
|
|
|
BIT(DRM_MODE_TV_MODE_PAL_N) |
|
|
|
|
BIT(DRM_MODE_TV_MODE_SECAM);
|
|
|
|
unsigned int tv_modes[2] = { UINT_MAX, UINT_MAX };
|
|
|
|
unsigned int i, supported_tv_modes = 0;
|
|
|
|
|
|
|
|
if (!tv_mode_property)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < tv_mode_property->num_values; i++)
|
|
|
|
supported_tv_modes |= BIT(tv_mode_property->values[i]);
|
|
|
|
|
|
|
|
if ((supported_tv_modes & ntsc_modes) &&
|
|
|
|
(supported_tv_modes & pal_modes)) {
|
|
|
|
uint64_t default_mode;
|
|
|
|
|
|
|
|
if (drm_object_property_get_default_value(&connector->base,
|
|
|
|
tv_mode_property,
|
|
|
|
&default_mode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (cmdline->tv_mode_specified)
|
|
|
|
default_mode = cmdline->tv_mode;
|
|
|
|
|
|
|
|
if (BIT(default_mode) & ntsc_modes) {
|
|
|
|
tv_modes[0] = DRM_MODE_TV_MODE_NTSC;
|
|
|
|
tv_modes[1] = DRM_MODE_TV_MODE_PAL;
|
|
|
|
} else {
|
|
|
|
tv_modes[0] = DRM_MODE_TV_MODE_PAL;
|
|
|
|
tv_modes[1] = DRM_MODE_TV_MODE_NTSC;
|
|
|
|
}
|
|
|
|
} else if (supported_tv_modes & ntsc_modes) {
|
|
|
|
tv_modes[0] = DRM_MODE_TV_MODE_NTSC;
|
|
|
|
} else if (supported_tv_modes & pal_modes) {
|
|
|
|
tv_modes[0] = DRM_MODE_TV_MODE_PAL;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
|
|
|
|
if (tv_modes[i] == DRM_MODE_TV_MODE_NTSC)
|
|
|
|
mode = drm_mode_analog_ntsc_480i(dev);
|
|
|
|
else if (tv_modes[i] == DRM_MODE_TV_MODE_PAL)
|
|
|
|
mode = drm_mode_analog_pal_576i(dev);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
if (!mode)
|
|
|
|
return i;
|
|
|
|
if (!i)
|
|
|
|
mode->type |= DRM_MODE_TYPE_PREFERRED;
|
|
|
|
drm_mode_probed_add(connector, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_connector_helper_tv_get_modes);
|