1*592ffb21SWarner Losh /*
2*592ffb21SWarner Losh * Copyright (c) 2006-2008 Intel Corporation
3*592ffb21SWarner Losh * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4*592ffb21SWarner Losh *
5*592ffb21SWarner Losh * DRM core CRTC related functions
6*592ffb21SWarner Losh *
7*592ffb21SWarner Losh * Permission to use, copy, modify, distribute, and sell this software and its
8*592ffb21SWarner Losh * documentation for any purpose is hereby granted without fee, provided that
9*592ffb21SWarner Losh * the above copyright notice appear in all copies and that both that copyright
10*592ffb21SWarner Losh * notice and this permission notice appear in supporting documentation, and
11*592ffb21SWarner Losh * that the name of the copyright holders not be used in advertising or
12*592ffb21SWarner Losh * publicity pertaining to distribution of the software without specific,
13*592ffb21SWarner Losh * written prior permission. The copyright holders make no representations
14*592ffb21SWarner Losh * about the suitability of this software for any purpose. It is provided "as
15*592ffb21SWarner Losh * is" without express or implied warranty.
16*592ffb21SWarner Losh *
17*592ffb21SWarner Losh * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18*592ffb21SWarner Losh * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19*592ffb21SWarner Losh * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20*592ffb21SWarner Losh * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21*592ffb21SWarner Losh * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22*592ffb21SWarner Losh * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23*592ffb21SWarner Losh * OF THIS SOFTWARE.
24*592ffb21SWarner Losh *
25*592ffb21SWarner Losh * Authors:
26*592ffb21SWarner Losh * Keith Packard
27*592ffb21SWarner Losh * Eric Anholt <eric@anholt.net>
28*592ffb21SWarner Losh * Dave Airlie <airlied@linux.ie>
29*592ffb21SWarner Losh * Jesse Barnes <jesse.barnes@intel.com>
30*592ffb21SWarner Losh */
31*592ffb21SWarner Losh
32*592ffb21SWarner Losh #include <sys/cdefs.h>
33*592ffb21SWarner Losh #include <dev/drm2/drmP.h>
34*592ffb21SWarner Losh #include <dev/drm2/drm_crtc.h>
35*592ffb21SWarner Losh #include <dev/drm2/drm_fourcc.h>
36*592ffb21SWarner Losh #include <dev/drm2/drm_crtc_helper.h>
37*592ffb21SWarner Losh #include <dev/drm2/drm_fb_helper.h>
38*592ffb21SWarner Losh #include <dev/drm2/drm_edid.h>
39*592ffb21SWarner Losh
40*592ffb21SWarner Losh /**
41*592ffb21SWarner Losh * drm_helper_move_panel_connectors_to_head() - move panels to the front in the
42*592ffb21SWarner Losh * connector list
43*592ffb21SWarner Losh * @dev: drm device to operate on
44*592ffb21SWarner Losh *
45*592ffb21SWarner Losh * Some userspace presumes that the first connected connector is the main
46*592ffb21SWarner Losh * display, where it's supposed to display e.g. the login screen. For
47*592ffb21SWarner Losh * laptops, this should be the main panel. Use this function to sort all
48*592ffb21SWarner Losh * (eDP/LVDS) panels to the front of the connector list, instead of
49*592ffb21SWarner Losh * painstakingly trying to initialize them in the right order.
50*592ffb21SWarner Losh */
drm_helper_move_panel_connectors_to_head(struct drm_device * dev)51*592ffb21SWarner Losh void drm_helper_move_panel_connectors_to_head(struct drm_device *dev)
52*592ffb21SWarner Losh {
53*592ffb21SWarner Losh struct drm_connector *connector, *tmp;
54*592ffb21SWarner Losh struct list_head panel_list;
55*592ffb21SWarner Losh
56*592ffb21SWarner Losh INIT_LIST_HEAD(&panel_list);
57*592ffb21SWarner Losh
58*592ffb21SWarner Losh list_for_each_entry_safe(connector, tmp,
59*592ffb21SWarner Losh &dev->mode_config.connector_list, head) {
60*592ffb21SWarner Losh if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS ||
61*592ffb21SWarner Losh connector->connector_type == DRM_MODE_CONNECTOR_eDP)
62*592ffb21SWarner Losh list_move_tail(&connector->head, &panel_list);
63*592ffb21SWarner Losh }
64*592ffb21SWarner Losh
65*592ffb21SWarner Losh list_splice(&panel_list, &dev->mode_config.connector_list);
66*592ffb21SWarner Losh }
67*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_move_panel_connectors_to_head);
68*592ffb21SWarner Losh
69*592ffb21SWarner Losh static bool drm_kms_helper_poll = true;
70*592ffb21SWarner Losh module_param_named(poll, drm_kms_helper_poll, bool, 0600);
71*592ffb21SWarner Losh
drm_mode_validate_flag(struct drm_connector * connector,int flags)72*592ffb21SWarner Losh static void drm_mode_validate_flag(struct drm_connector *connector,
73*592ffb21SWarner Losh int flags)
74*592ffb21SWarner Losh {
75*592ffb21SWarner Losh struct drm_display_mode *mode;
76*592ffb21SWarner Losh
77*592ffb21SWarner Losh if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE))
78*592ffb21SWarner Losh return;
79*592ffb21SWarner Losh
80*592ffb21SWarner Losh list_for_each_entry(mode, &connector->modes, head) {
81*592ffb21SWarner Losh if ((mode->flags & DRM_MODE_FLAG_INTERLACE) &&
82*592ffb21SWarner Losh !(flags & DRM_MODE_FLAG_INTERLACE))
83*592ffb21SWarner Losh mode->status = MODE_NO_INTERLACE;
84*592ffb21SWarner Losh if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) &&
85*592ffb21SWarner Losh !(flags & DRM_MODE_FLAG_DBLSCAN))
86*592ffb21SWarner Losh mode->status = MODE_NO_DBLESCAN;
87*592ffb21SWarner Losh }
88*592ffb21SWarner Losh
89*592ffb21SWarner Losh return;
90*592ffb21SWarner Losh }
91*592ffb21SWarner Losh
92*592ffb21SWarner Losh /**
93*592ffb21SWarner Losh * drm_helper_probe_single_connector_modes - get complete set of display modes
94*592ffb21SWarner Losh * @connector: connector to probe
95*592ffb21SWarner Losh * @maxX: max width for modes
96*592ffb21SWarner Losh * @maxY: max height for modes
97*592ffb21SWarner Losh *
98*592ffb21SWarner Losh * LOCKING:
99*592ffb21SWarner Losh * Caller must hold mode config lock.
100*592ffb21SWarner Losh *
101*592ffb21SWarner Losh * Based on the helper callbacks implemented by @connector try to detect all
102*592ffb21SWarner Losh * valid modes. Modes will first be added to the connector's probed_modes list,
103*592ffb21SWarner Losh * then culled (based on validity and the @maxX, @maxY parameters) and put into
104*592ffb21SWarner Losh * the normal modes list.
105*592ffb21SWarner Losh *
106*592ffb21SWarner Losh * Intended to be use as a generic implementation of the ->probe() @connector
107*592ffb21SWarner Losh * callback for drivers that use the crtc helpers for output mode filtering and
108*592ffb21SWarner Losh * detection.
109*592ffb21SWarner Losh *
110*592ffb21SWarner Losh * RETURNS:
111*592ffb21SWarner Losh * Number of modes found on @connector.
112*592ffb21SWarner Losh */
drm_helper_probe_single_connector_modes(struct drm_connector * connector,uint32_t maxX,uint32_t maxY)113*592ffb21SWarner Losh int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
114*592ffb21SWarner Losh uint32_t maxX, uint32_t maxY)
115*592ffb21SWarner Losh {
116*592ffb21SWarner Losh struct drm_device *dev = connector->dev;
117*592ffb21SWarner Losh struct drm_display_mode *mode;
118*592ffb21SWarner Losh struct drm_connector_helper_funcs *connector_funcs =
119*592ffb21SWarner Losh connector->helper_private;
120*592ffb21SWarner Losh int count = 0;
121*592ffb21SWarner Losh int mode_flags = 0;
122*592ffb21SWarner Losh
123*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
124*592ffb21SWarner Losh drm_get_connector_name(connector));
125*592ffb21SWarner Losh /* set all modes to the unverified state */
126*592ffb21SWarner Losh list_for_each_entry(mode, &connector->modes, head)
127*592ffb21SWarner Losh mode->status = MODE_UNVERIFIED;
128*592ffb21SWarner Losh
129*592ffb21SWarner Losh if (connector->force) {
130*592ffb21SWarner Losh if (connector->force == DRM_FORCE_ON)
131*592ffb21SWarner Losh connector->status = connector_status_connected;
132*592ffb21SWarner Losh else
133*592ffb21SWarner Losh connector->status = connector_status_disconnected;
134*592ffb21SWarner Losh if (connector->funcs->force)
135*592ffb21SWarner Losh connector->funcs->force(connector);
136*592ffb21SWarner Losh } else {
137*592ffb21SWarner Losh connector->status = connector->funcs->detect(connector, true);
138*592ffb21SWarner Losh }
139*592ffb21SWarner Losh
140*592ffb21SWarner Losh /* Re-enable polling in case the global poll config changed. */
141*592ffb21SWarner Losh if (drm_kms_helper_poll != dev->mode_config.poll_running)
142*592ffb21SWarner Losh drm_kms_helper_poll_enable(dev);
143*592ffb21SWarner Losh
144*592ffb21SWarner Losh dev->mode_config.poll_running = drm_kms_helper_poll;
145*592ffb21SWarner Losh
146*592ffb21SWarner Losh if (connector->status == connector_status_disconnected) {
147*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n",
148*592ffb21SWarner Losh connector->base.id, drm_get_connector_name(connector));
149*592ffb21SWarner Losh drm_mode_connector_update_edid_property(connector, NULL);
150*592ffb21SWarner Losh goto prune;
151*592ffb21SWarner Losh }
152*592ffb21SWarner Losh
153*592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
154*592ffb21SWarner Losh #ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
155*592ffb21SWarner Losh count = drm_load_edid_firmware(connector);
156*592ffb21SWarner Losh if (count == 0)
157*592ffb21SWarner Losh #endif
158*592ffb21SWarner Losh #endif /* FREEBSD_NOTYET */
159*592ffb21SWarner Losh count = (*connector_funcs->get_modes)(connector);
160*592ffb21SWarner Losh
161*592ffb21SWarner Losh if (count == 0 && connector->status == connector_status_connected)
162*592ffb21SWarner Losh count = drm_add_modes_noedid(connector, 1024, 768);
163*592ffb21SWarner Losh if (count == 0)
164*592ffb21SWarner Losh goto prune;
165*592ffb21SWarner Losh
166*592ffb21SWarner Losh drm_mode_connector_list_update(connector);
167*592ffb21SWarner Losh
168*592ffb21SWarner Losh if (maxX && maxY)
169*592ffb21SWarner Losh drm_mode_validate_size(dev, &connector->modes, maxX,
170*592ffb21SWarner Losh maxY, 0);
171*592ffb21SWarner Losh
172*592ffb21SWarner Losh if (connector->interlace_allowed)
173*592ffb21SWarner Losh mode_flags |= DRM_MODE_FLAG_INTERLACE;
174*592ffb21SWarner Losh if (connector->doublescan_allowed)
175*592ffb21SWarner Losh mode_flags |= DRM_MODE_FLAG_DBLSCAN;
176*592ffb21SWarner Losh drm_mode_validate_flag(connector, mode_flags);
177*592ffb21SWarner Losh
178*592ffb21SWarner Losh list_for_each_entry(mode, &connector->modes, head) {
179*592ffb21SWarner Losh if (mode->status == MODE_OK)
180*592ffb21SWarner Losh mode->status = connector_funcs->mode_valid(connector,
181*592ffb21SWarner Losh mode);
182*592ffb21SWarner Losh }
183*592ffb21SWarner Losh
184*592ffb21SWarner Losh prune:
185*592ffb21SWarner Losh drm_mode_prune_invalid(dev, &connector->modes, true);
186*592ffb21SWarner Losh
187*592ffb21SWarner Losh if (list_empty(&connector->modes))
188*592ffb21SWarner Losh return 0;
189*592ffb21SWarner Losh
190*592ffb21SWarner Losh list_for_each_entry(mode, &connector->modes, head)
191*592ffb21SWarner Losh mode->vrefresh = drm_mode_vrefresh(mode);
192*592ffb21SWarner Losh
193*592ffb21SWarner Losh drm_mode_sort(&connector->modes);
194*592ffb21SWarner Losh
195*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id,
196*592ffb21SWarner Losh drm_get_connector_name(connector));
197*592ffb21SWarner Losh list_for_each_entry(mode, &connector->modes, head) {
198*592ffb21SWarner Losh drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
199*592ffb21SWarner Losh drm_mode_debug_printmodeline(mode);
200*592ffb21SWarner Losh }
201*592ffb21SWarner Losh
202*592ffb21SWarner Losh return count;
203*592ffb21SWarner Losh }
204*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);
205*592ffb21SWarner Losh
206*592ffb21SWarner Losh /**
207*592ffb21SWarner Losh * drm_helper_encoder_in_use - check if a given encoder is in use
208*592ffb21SWarner Losh * @encoder: encoder to check
209*592ffb21SWarner Losh *
210*592ffb21SWarner Losh * LOCKING:
211*592ffb21SWarner Losh * Caller must hold mode config lock.
212*592ffb21SWarner Losh *
213*592ffb21SWarner Losh * Walk @encoders's DRM device's mode_config and see if it's in use.
214*592ffb21SWarner Losh *
215*592ffb21SWarner Losh * RETURNS:
216*592ffb21SWarner Losh * True if @encoder is part of the mode_config, false otherwise.
217*592ffb21SWarner Losh */
drm_helper_encoder_in_use(struct drm_encoder * encoder)218*592ffb21SWarner Losh bool drm_helper_encoder_in_use(struct drm_encoder *encoder)
219*592ffb21SWarner Losh {
220*592ffb21SWarner Losh struct drm_connector *connector;
221*592ffb21SWarner Losh struct drm_device *dev = encoder->dev;
222*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head)
223*592ffb21SWarner Losh if (connector->encoder == encoder)
224*592ffb21SWarner Losh return true;
225*592ffb21SWarner Losh return false;
226*592ffb21SWarner Losh }
227*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_encoder_in_use);
228*592ffb21SWarner Losh
229*592ffb21SWarner Losh /**
230*592ffb21SWarner Losh * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config
231*592ffb21SWarner Losh * @crtc: CRTC to check
232*592ffb21SWarner Losh *
233*592ffb21SWarner Losh * LOCKING:
234*592ffb21SWarner Losh * Caller must hold mode config lock.
235*592ffb21SWarner Losh *
236*592ffb21SWarner Losh * Walk @crtc's DRM device's mode_config and see if it's in use.
237*592ffb21SWarner Losh *
238*592ffb21SWarner Losh * RETURNS:
239*592ffb21SWarner Losh * True if @crtc is part of the mode_config, false otherwise.
240*592ffb21SWarner Losh */
drm_helper_crtc_in_use(struct drm_crtc * crtc)241*592ffb21SWarner Losh bool drm_helper_crtc_in_use(struct drm_crtc *crtc)
242*592ffb21SWarner Losh {
243*592ffb21SWarner Losh struct drm_encoder *encoder;
244*592ffb21SWarner Losh struct drm_device *dev = crtc->dev;
245*592ffb21SWarner Losh /* FIXME: Locking around list access? */
246*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
247*592ffb21SWarner Losh if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder))
248*592ffb21SWarner Losh return true;
249*592ffb21SWarner Losh return false;
250*592ffb21SWarner Losh }
251*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_crtc_in_use);
252*592ffb21SWarner Losh
253*592ffb21SWarner Losh static void
drm_encoder_disable(struct drm_encoder * encoder)254*592ffb21SWarner Losh drm_encoder_disable(struct drm_encoder *encoder)
255*592ffb21SWarner Losh {
256*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
257*592ffb21SWarner Losh
258*592ffb21SWarner Losh if (encoder_funcs->disable)
259*592ffb21SWarner Losh (*encoder_funcs->disable)(encoder);
260*592ffb21SWarner Losh else
261*592ffb21SWarner Losh (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF);
262*592ffb21SWarner Losh }
263*592ffb21SWarner Losh
264*592ffb21SWarner Losh /**
265*592ffb21SWarner Losh * drm_helper_disable_unused_functions - disable unused objects
266*592ffb21SWarner Losh * @dev: DRM device
267*592ffb21SWarner Losh *
268*592ffb21SWarner Losh * LOCKING:
269*592ffb21SWarner Losh * Caller must hold mode config lock.
270*592ffb21SWarner Losh *
271*592ffb21SWarner Losh * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled
272*592ffb21SWarner Losh * by calling its dpms function, which should power it off.
273*592ffb21SWarner Losh */
drm_helper_disable_unused_functions(struct drm_device * dev)274*592ffb21SWarner Losh void drm_helper_disable_unused_functions(struct drm_device *dev)
275*592ffb21SWarner Losh {
276*592ffb21SWarner Losh struct drm_encoder *encoder;
277*592ffb21SWarner Losh struct drm_connector *connector;
278*592ffb21SWarner Losh struct drm_crtc *crtc;
279*592ffb21SWarner Losh
280*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
281*592ffb21SWarner Losh if (!connector->encoder)
282*592ffb21SWarner Losh continue;
283*592ffb21SWarner Losh if (connector->status == connector_status_disconnected)
284*592ffb21SWarner Losh connector->encoder = NULL;
285*592ffb21SWarner Losh }
286*592ffb21SWarner Losh
287*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
288*592ffb21SWarner Losh if (!drm_helper_encoder_in_use(encoder)) {
289*592ffb21SWarner Losh drm_encoder_disable(encoder);
290*592ffb21SWarner Losh /* disconnector encoder from any connector */
291*592ffb21SWarner Losh encoder->crtc = NULL;
292*592ffb21SWarner Losh }
293*592ffb21SWarner Losh }
294*592ffb21SWarner Losh
295*592ffb21SWarner Losh list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
296*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
297*592ffb21SWarner Losh crtc->enabled = drm_helper_crtc_in_use(crtc);
298*592ffb21SWarner Losh if (!crtc->enabled) {
299*592ffb21SWarner Losh if (crtc_funcs->disable)
300*592ffb21SWarner Losh (*crtc_funcs->disable)(crtc);
301*592ffb21SWarner Losh else
302*592ffb21SWarner Losh (*crtc_funcs->dpms)(crtc, DRM_MODE_DPMS_OFF);
303*592ffb21SWarner Losh crtc->fb = NULL;
304*592ffb21SWarner Losh }
305*592ffb21SWarner Losh }
306*592ffb21SWarner Losh }
307*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_disable_unused_functions);
308*592ffb21SWarner Losh
309*592ffb21SWarner Losh /**
310*592ffb21SWarner Losh * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
311*592ffb21SWarner Losh * @encoder: encoder to test
312*592ffb21SWarner Losh * @crtc: crtc to test
313*592ffb21SWarner Losh *
314*592ffb21SWarner Losh * Return false if @encoder can't be driven by @crtc, true otherwise.
315*592ffb21SWarner Losh */
drm_encoder_crtc_ok(struct drm_encoder * encoder,struct drm_crtc * crtc)316*592ffb21SWarner Losh static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
317*592ffb21SWarner Losh struct drm_crtc *crtc)
318*592ffb21SWarner Losh {
319*592ffb21SWarner Losh struct drm_device *dev;
320*592ffb21SWarner Losh struct drm_crtc *tmp;
321*592ffb21SWarner Losh int crtc_mask = 1;
322*592ffb21SWarner Losh
323*592ffb21SWarner Losh if (crtc == NULL)
324*592ffb21SWarner Losh printf("checking null crtc?\n");
325*592ffb21SWarner Losh
326*592ffb21SWarner Losh dev = crtc->dev;
327*592ffb21SWarner Losh
328*592ffb21SWarner Losh list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
329*592ffb21SWarner Losh if (tmp == crtc)
330*592ffb21SWarner Losh break;
331*592ffb21SWarner Losh crtc_mask <<= 1;
332*592ffb21SWarner Losh }
333*592ffb21SWarner Losh
334*592ffb21SWarner Losh if (encoder->possible_crtcs & crtc_mask)
335*592ffb21SWarner Losh return true;
336*592ffb21SWarner Losh return false;
337*592ffb21SWarner Losh }
338*592ffb21SWarner Losh
339*592ffb21SWarner Losh /*
340*592ffb21SWarner Losh * Check the CRTC we're going to map each output to vs. its current
341*592ffb21SWarner Losh * CRTC. If they don't match, we have to disable the output and the CRTC
342*592ffb21SWarner Losh * since the driver will have to re-route things.
343*592ffb21SWarner Losh */
344*592ffb21SWarner Losh static void
drm_crtc_prepare_encoders(struct drm_device * dev)345*592ffb21SWarner Losh drm_crtc_prepare_encoders(struct drm_device *dev)
346*592ffb21SWarner Losh {
347*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs;
348*592ffb21SWarner Losh struct drm_encoder *encoder;
349*592ffb21SWarner Losh
350*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
351*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
352*592ffb21SWarner Losh /* Disable unused encoders */
353*592ffb21SWarner Losh if (encoder->crtc == NULL)
354*592ffb21SWarner Losh drm_encoder_disable(encoder);
355*592ffb21SWarner Losh /* Disable encoders whose CRTC is about to change */
356*592ffb21SWarner Losh if (encoder_funcs->get_crtc &&
357*592ffb21SWarner Losh encoder->crtc != (*encoder_funcs->get_crtc)(encoder))
358*592ffb21SWarner Losh drm_encoder_disable(encoder);
359*592ffb21SWarner Losh }
360*592ffb21SWarner Losh }
361*592ffb21SWarner Losh
362*592ffb21SWarner Losh /**
363*592ffb21SWarner Losh * drm_crtc_helper_set_mode - internal helper to set a mode
364*592ffb21SWarner Losh * @crtc: CRTC to program
365*592ffb21SWarner Losh * @mode: mode to use
366*592ffb21SWarner Losh * @x: horizontal offset into the surface
367*592ffb21SWarner Losh * @y: vertical offset into the surface
368*592ffb21SWarner Losh * @old_fb: old framebuffer, for cleanup
369*592ffb21SWarner Losh *
370*592ffb21SWarner Losh * LOCKING:
371*592ffb21SWarner Losh * Caller must hold mode config lock.
372*592ffb21SWarner Losh *
373*592ffb21SWarner Losh * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance
374*592ffb21SWarner Losh * to fixup or reject the mode prior to trying to set it. This is an internal
375*592ffb21SWarner Losh * helper that drivers could e.g. use to update properties that require the
376*592ffb21SWarner Losh * entire output pipe to be disabled and re-enabled in a new configuration. For
377*592ffb21SWarner Losh * example for changing whether audio is enabled on a hdmi link or for changing
378*592ffb21SWarner Losh * panel fitter or dither attributes. It is also called by the
379*592ffb21SWarner Losh * drm_crtc_helper_set_config() helper function to drive the mode setting
380*592ffb21SWarner Losh * sequence.
381*592ffb21SWarner Losh *
382*592ffb21SWarner Losh * RETURNS:
383*592ffb21SWarner Losh * True if the mode was set successfully, or false otherwise.
384*592ffb21SWarner Losh */
drm_crtc_helper_set_mode(struct drm_crtc * crtc,struct drm_display_mode * mode,int x,int y,struct drm_framebuffer * old_fb)385*592ffb21SWarner Losh bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
386*592ffb21SWarner Losh struct drm_display_mode *mode,
387*592ffb21SWarner Losh int x, int y,
388*592ffb21SWarner Losh struct drm_framebuffer *old_fb)
389*592ffb21SWarner Losh {
390*592ffb21SWarner Losh struct drm_device *dev = crtc->dev;
391*592ffb21SWarner Losh struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
392*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
393*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs;
394*592ffb21SWarner Losh int saved_x, saved_y;
395*592ffb21SWarner Losh struct drm_encoder *encoder;
396*592ffb21SWarner Losh bool ret = true;
397*592ffb21SWarner Losh
398*592ffb21SWarner Losh crtc->enabled = drm_helper_crtc_in_use(crtc);
399*592ffb21SWarner Losh if (!crtc->enabled)
400*592ffb21SWarner Losh return true;
401*592ffb21SWarner Losh
402*592ffb21SWarner Losh adjusted_mode = drm_mode_duplicate(dev, mode);
403*592ffb21SWarner Losh if (!adjusted_mode)
404*592ffb21SWarner Losh return false;
405*592ffb21SWarner Losh
406*592ffb21SWarner Losh saved_hwmode = crtc->hwmode;
407*592ffb21SWarner Losh saved_mode = crtc->mode;
408*592ffb21SWarner Losh saved_x = crtc->x;
409*592ffb21SWarner Losh saved_y = crtc->y;
410*592ffb21SWarner Losh
411*592ffb21SWarner Losh /* Update crtc values up front so the driver can rely on them for mode
412*592ffb21SWarner Losh * setting.
413*592ffb21SWarner Losh */
414*592ffb21SWarner Losh crtc->mode = *mode;
415*592ffb21SWarner Losh crtc->x = x;
416*592ffb21SWarner Losh crtc->y = y;
417*592ffb21SWarner Losh
418*592ffb21SWarner Losh /* Pass our mode to the connectors and the CRTC to give them a chance to
419*592ffb21SWarner Losh * adjust it according to limitations or connector properties, and also
420*592ffb21SWarner Losh * a chance to reject the mode entirely.
421*592ffb21SWarner Losh */
422*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
423*592ffb21SWarner Losh
424*592ffb21SWarner Losh if (encoder->crtc != crtc)
425*592ffb21SWarner Losh continue;
426*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
427*592ffb21SWarner Losh if (!(ret = encoder_funcs->mode_fixup(encoder, mode,
428*592ffb21SWarner Losh adjusted_mode))) {
429*592ffb21SWarner Losh DRM_DEBUG_KMS("Encoder fixup failed\n");
430*592ffb21SWarner Losh goto done;
431*592ffb21SWarner Losh }
432*592ffb21SWarner Losh }
433*592ffb21SWarner Losh
434*592ffb21SWarner Losh if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) {
435*592ffb21SWarner Losh DRM_DEBUG_KMS("CRTC fixup failed\n");
436*592ffb21SWarner Losh goto done;
437*592ffb21SWarner Losh }
438*592ffb21SWarner Losh DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
439*592ffb21SWarner Losh
440*592ffb21SWarner Losh /* Prepare the encoders and CRTCs before setting the mode. */
441*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
442*592ffb21SWarner Losh
443*592ffb21SWarner Losh if (encoder->crtc != crtc)
444*592ffb21SWarner Losh continue;
445*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
446*592ffb21SWarner Losh /* Disable the encoders as the first thing we do. */
447*592ffb21SWarner Losh encoder_funcs->prepare(encoder);
448*592ffb21SWarner Losh }
449*592ffb21SWarner Losh
450*592ffb21SWarner Losh drm_crtc_prepare_encoders(dev);
451*592ffb21SWarner Losh
452*592ffb21SWarner Losh crtc_funcs->prepare(crtc);
453*592ffb21SWarner Losh
454*592ffb21SWarner Losh /* Set up the DPLL and any encoders state that needs to adjust or depend
455*592ffb21SWarner Losh * on the DPLL.
456*592ffb21SWarner Losh */
457*592ffb21SWarner Losh ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb);
458*592ffb21SWarner Losh if (!ret)
459*592ffb21SWarner Losh goto done;
460*592ffb21SWarner Losh
461*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
462*592ffb21SWarner Losh
463*592ffb21SWarner Losh if (encoder->crtc != crtc)
464*592ffb21SWarner Losh continue;
465*592ffb21SWarner Losh
466*592ffb21SWarner Losh DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
467*592ffb21SWarner Losh encoder->base.id, drm_get_encoder_name(encoder),
468*592ffb21SWarner Losh mode->base.id, mode->name);
469*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
470*592ffb21SWarner Losh encoder_funcs->mode_set(encoder, mode, adjusted_mode);
471*592ffb21SWarner Losh }
472*592ffb21SWarner Losh
473*592ffb21SWarner Losh /* Now enable the clocks, plane, pipe, and connectors that we set up. */
474*592ffb21SWarner Losh crtc_funcs->commit(crtc);
475*592ffb21SWarner Losh
476*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
477*592ffb21SWarner Losh
478*592ffb21SWarner Losh if (encoder->crtc != crtc)
479*592ffb21SWarner Losh continue;
480*592ffb21SWarner Losh
481*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
482*592ffb21SWarner Losh encoder_funcs->commit(encoder);
483*592ffb21SWarner Losh
484*592ffb21SWarner Losh }
485*592ffb21SWarner Losh
486*592ffb21SWarner Losh /* Store real post-adjustment hardware mode. */
487*592ffb21SWarner Losh crtc->hwmode = *adjusted_mode;
488*592ffb21SWarner Losh
489*592ffb21SWarner Losh /* Calculate and store various constants which
490*592ffb21SWarner Losh * are later needed by vblank and swap-completion
491*592ffb21SWarner Losh * timestamping. They are derived from true hwmode.
492*592ffb21SWarner Losh */
493*592ffb21SWarner Losh drm_calc_timestamping_constants(crtc);
494*592ffb21SWarner Losh
495*592ffb21SWarner Losh /* FIXME: add subpixel order */
496*592ffb21SWarner Losh done:
497*592ffb21SWarner Losh drm_mode_destroy(dev, adjusted_mode);
498*592ffb21SWarner Losh if (!ret) {
499*592ffb21SWarner Losh crtc->hwmode = saved_hwmode;
500*592ffb21SWarner Losh crtc->mode = saved_mode;
501*592ffb21SWarner Losh crtc->x = saved_x;
502*592ffb21SWarner Losh crtc->y = saved_y;
503*592ffb21SWarner Losh }
504*592ffb21SWarner Losh
505*592ffb21SWarner Losh return ret;
506*592ffb21SWarner Losh }
507*592ffb21SWarner Losh EXPORT_SYMBOL(drm_crtc_helper_set_mode);
508*592ffb21SWarner Losh
509*592ffb21SWarner Losh
510*592ffb21SWarner Losh static int
drm_crtc_helper_disable(struct drm_crtc * crtc)511*592ffb21SWarner Losh drm_crtc_helper_disable(struct drm_crtc *crtc)
512*592ffb21SWarner Losh {
513*592ffb21SWarner Losh struct drm_device *dev = crtc->dev;
514*592ffb21SWarner Losh struct drm_connector *connector;
515*592ffb21SWarner Losh struct drm_encoder *encoder;
516*592ffb21SWarner Losh
517*592ffb21SWarner Losh /* Decouple all encoders and their attached connectors from this crtc */
518*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
519*592ffb21SWarner Losh if (encoder->crtc != crtc)
520*592ffb21SWarner Losh continue;
521*592ffb21SWarner Losh
522*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
523*592ffb21SWarner Losh if (connector->encoder != encoder)
524*592ffb21SWarner Losh continue;
525*592ffb21SWarner Losh
526*592ffb21SWarner Losh connector->encoder = NULL;
527*592ffb21SWarner Losh }
528*592ffb21SWarner Losh }
529*592ffb21SWarner Losh
530*592ffb21SWarner Losh drm_helper_disable_unused_functions(dev);
531*592ffb21SWarner Losh return 0;
532*592ffb21SWarner Losh }
533*592ffb21SWarner Losh
534*592ffb21SWarner Losh /**
535*592ffb21SWarner Losh * drm_crtc_helper_set_config - set a new config from userspace
536*592ffb21SWarner Losh * @set: mode set configuration
537*592ffb21SWarner Losh *
538*592ffb21SWarner Losh * LOCKING:
539*592ffb21SWarner Losh * Caller must hold mode config lock.
540*592ffb21SWarner Losh *
541*592ffb21SWarner Losh * Setup a new configuration, provided by the upper layers (either an ioctl call
542*592ffb21SWarner Losh * from userspace or internally e.g. from the fbdev suppport code) in @set, and
543*592ffb21SWarner Losh * enable it. This is the main helper functions for drivers that implement
544*592ffb21SWarner Losh * kernel mode setting with the crtc helper functions and the assorted
545*592ffb21SWarner Losh * ->prepare(), ->modeset() and ->commit() helper callbacks.
546*592ffb21SWarner Losh *
547*592ffb21SWarner Losh * RETURNS:
548*592ffb21SWarner Losh * Returns 0 on success, -ERRNO on failure.
549*592ffb21SWarner Losh */
drm_crtc_helper_set_config(struct drm_mode_set * set)550*592ffb21SWarner Losh int drm_crtc_helper_set_config(struct drm_mode_set *set)
551*592ffb21SWarner Losh {
552*592ffb21SWarner Losh struct drm_device *dev;
553*592ffb21SWarner Losh struct drm_crtc *save_crtcs, *new_crtc, *crtc;
554*592ffb21SWarner Losh struct drm_encoder *save_encoders, *new_encoder, *encoder;
555*592ffb21SWarner Losh struct drm_framebuffer *old_fb = NULL;
556*592ffb21SWarner Losh bool mode_changed = false; /* if true do a full mode set */
557*592ffb21SWarner Losh bool fb_changed = false; /* if true and !mode_changed just do a flip */
558*592ffb21SWarner Losh struct drm_connector *save_connectors, *connector;
559*592ffb21SWarner Losh int count = 0, ro, fail = 0;
560*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs;
561*592ffb21SWarner Losh struct drm_mode_set save_set;
562*592ffb21SWarner Losh int ret;
563*592ffb21SWarner Losh int i;
564*592ffb21SWarner Losh
565*592ffb21SWarner Losh DRM_DEBUG_KMS("\n");
566*592ffb21SWarner Losh
567*592ffb21SWarner Losh if (!set)
568*592ffb21SWarner Losh return -EINVAL;
569*592ffb21SWarner Losh
570*592ffb21SWarner Losh if (!set->crtc)
571*592ffb21SWarner Losh return -EINVAL;
572*592ffb21SWarner Losh
573*592ffb21SWarner Losh if (!set->crtc->helper_private)
574*592ffb21SWarner Losh return -EINVAL;
575*592ffb21SWarner Losh
576*592ffb21SWarner Losh crtc_funcs = set->crtc->helper_private;
577*592ffb21SWarner Losh
578*592ffb21SWarner Losh if (!set->mode)
579*592ffb21SWarner Losh set->fb = NULL;
580*592ffb21SWarner Losh
581*592ffb21SWarner Losh if (set->fb) {
582*592ffb21SWarner Losh DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
583*592ffb21SWarner Losh set->crtc->base.id, set->fb->base.id,
584*592ffb21SWarner Losh (int)set->num_connectors, set->x, set->y);
585*592ffb21SWarner Losh } else {
586*592ffb21SWarner Losh DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
587*592ffb21SWarner Losh return drm_crtc_helper_disable(set->crtc);
588*592ffb21SWarner Losh }
589*592ffb21SWarner Losh
590*592ffb21SWarner Losh dev = set->crtc->dev;
591*592ffb21SWarner Losh
592*592ffb21SWarner Losh /* Allocate space for the backup of all (non-pointer) crtc, encoder and
593*592ffb21SWarner Losh * connector data. */
594*592ffb21SWarner Losh save_crtcs = malloc(dev->mode_config.num_crtc *
595*592ffb21SWarner Losh sizeof(struct drm_crtc), DRM_MEM_KMS, M_NOWAIT | M_ZERO);
596*592ffb21SWarner Losh if (!save_crtcs)
597*592ffb21SWarner Losh return -ENOMEM;
598*592ffb21SWarner Losh
599*592ffb21SWarner Losh save_encoders = malloc(dev->mode_config.num_encoder *
600*592ffb21SWarner Losh sizeof(struct drm_encoder), DRM_MEM_KMS, M_NOWAIT | M_ZERO);
601*592ffb21SWarner Losh if (!save_encoders) {
602*592ffb21SWarner Losh free(save_crtcs, DRM_MEM_KMS);
603*592ffb21SWarner Losh return -ENOMEM;
604*592ffb21SWarner Losh }
605*592ffb21SWarner Losh
606*592ffb21SWarner Losh save_connectors = malloc(dev->mode_config.num_connector *
607*592ffb21SWarner Losh sizeof(struct drm_connector), DRM_MEM_KMS, M_NOWAIT | M_ZERO);
608*592ffb21SWarner Losh if (!save_connectors) {
609*592ffb21SWarner Losh free(save_crtcs, DRM_MEM_KMS);
610*592ffb21SWarner Losh free(save_encoders, DRM_MEM_KMS);
611*592ffb21SWarner Losh return -ENOMEM;
612*592ffb21SWarner Losh }
613*592ffb21SWarner Losh
614*592ffb21SWarner Losh /* Copy data. Note that driver private data is not affected.
615*592ffb21SWarner Losh * Should anything bad happen only the expected state is
616*592ffb21SWarner Losh * restored, not the drivers personal bookkeeping.
617*592ffb21SWarner Losh */
618*592ffb21SWarner Losh count = 0;
619*592ffb21SWarner Losh list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
620*592ffb21SWarner Losh save_crtcs[count++] = *crtc;
621*592ffb21SWarner Losh }
622*592ffb21SWarner Losh
623*592ffb21SWarner Losh count = 0;
624*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
625*592ffb21SWarner Losh save_encoders[count++] = *encoder;
626*592ffb21SWarner Losh }
627*592ffb21SWarner Losh
628*592ffb21SWarner Losh count = 0;
629*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
630*592ffb21SWarner Losh save_connectors[count++] = *connector;
631*592ffb21SWarner Losh }
632*592ffb21SWarner Losh
633*592ffb21SWarner Losh save_set.crtc = set->crtc;
634*592ffb21SWarner Losh save_set.mode = &set->crtc->mode;
635*592ffb21SWarner Losh save_set.x = set->crtc->x;
636*592ffb21SWarner Losh save_set.y = set->crtc->y;
637*592ffb21SWarner Losh save_set.fb = set->crtc->fb;
638*592ffb21SWarner Losh
639*592ffb21SWarner Losh /* We should be able to check here if the fb has the same properties
640*592ffb21SWarner Losh * and then just flip_or_move it */
641*592ffb21SWarner Losh if (set->crtc->fb != set->fb) {
642*592ffb21SWarner Losh /* If we have no fb then treat it as a full mode set */
643*592ffb21SWarner Losh if (set->crtc->fb == NULL) {
644*592ffb21SWarner Losh DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
645*592ffb21SWarner Losh mode_changed = true;
646*592ffb21SWarner Losh } else if (set->fb == NULL) {
647*592ffb21SWarner Losh mode_changed = true;
648*592ffb21SWarner Losh } else if (set->fb->depth != set->crtc->fb->depth) {
649*592ffb21SWarner Losh mode_changed = true;
650*592ffb21SWarner Losh } else if (set->fb->bits_per_pixel !=
651*592ffb21SWarner Losh set->crtc->fb->bits_per_pixel) {
652*592ffb21SWarner Losh mode_changed = true;
653*592ffb21SWarner Losh } else
654*592ffb21SWarner Losh fb_changed = true;
655*592ffb21SWarner Losh }
656*592ffb21SWarner Losh
657*592ffb21SWarner Losh if (set->x != set->crtc->x || set->y != set->crtc->y)
658*592ffb21SWarner Losh fb_changed = true;
659*592ffb21SWarner Losh
660*592ffb21SWarner Losh if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
661*592ffb21SWarner Losh DRM_DEBUG_KMS("modes are different, full mode set\n");
662*592ffb21SWarner Losh drm_mode_debug_printmodeline(&set->crtc->mode);
663*592ffb21SWarner Losh drm_mode_debug_printmodeline(set->mode);
664*592ffb21SWarner Losh mode_changed = true;
665*592ffb21SWarner Losh }
666*592ffb21SWarner Losh
667*592ffb21SWarner Losh /* a) traverse passed in connector list and get encoders for them */
668*592ffb21SWarner Losh count = 0;
669*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
670*592ffb21SWarner Losh struct drm_connector_helper_funcs *connector_funcs =
671*592ffb21SWarner Losh connector->helper_private;
672*592ffb21SWarner Losh new_encoder = connector->encoder;
673*592ffb21SWarner Losh for (ro = 0; ro < set->num_connectors; ro++) {
674*592ffb21SWarner Losh if (set->connectors[ro] == connector) {
675*592ffb21SWarner Losh new_encoder = connector_funcs->best_encoder(connector);
676*592ffb21SWarner Losh /* if we can't get an encoder for a connector
677*592ffb21SWarner Losh we are setting now - then fail */
678*592ffb21SWarner Losh if (new_encoder == NULL)
679*592ffb21SWarner Losh /* don't break so fail path works correct */
680*592ffb21SWarner Losh fail = 1;
681*592ffb21SWarner Losh break;
682*592ffb21SWarner Losh }
683*592ffb21SWarner Losh }
684*592ffb21SWarner Losh
685*592ffb21SWarner Losh if (new_encoder != connector->encoder) {
686*592ffb21SWarner Losh DRM_DEBUG_KMS("encoder changed, full mode switch\n");
687*592ffb21SWarner Losh mode_changed = true;
688*592ffb21SWarner Losh /* If the encoder is reused for another connector, then
689*592ffb21SWarner Losh * the appropriate crtc will be set later.
690*592ffb21SWarner Losh */
691*592ffb21SWarner Losh if (connector->encoder)
692*592ffb21SWarner Losh connector->encoder->crtc = NULL;
693*592ffb21SWarner Losh connector->encoder = new_encoder;
694*592ffb21SWarner Losh }
695*592ffb21SWarner Losh }
696*592ffb21SWarner Losh
697*592ffb21SWarner Losh if (fail) {
698*592ffb21SWarner Losh ret = -EINVAL;
699*592ffb21SWarner Losh goto fail;
700*592ffb21SWarner Losh }
701*592ffb21SWarner Losh
702*592ffb21SWarner Losh count = 0;
703*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
704*592ffb21SWarner Losh if (!connector->encoder)
705*592ffb21SWarner Losh continue;
706*592ffb21SWarner Losh
707*592ffb21SWarner Losh if (connector->encoder->crtc == set->crtc)
708*592ffb21SWarner Losh new_crtc = NULL;
709*592ffb21SWarner Losh else
710*592ffb21SWarner Losh new_crtc = connector->encoder->crtc;
711*592ffb21SWarner Losh
712*592ffb21SWarner Losh for (ro = 0; ro < set->num_connectors; ro++) {
713*592ffb21SWarner Losh if (set->connectors[ro] == connector)
714*592ffb21SWarner Losh new_crtc = set->crtc;
715*592ffb21SWarner Losh }
716*592ffb21SWarner Losh
717*592ffb21SWarner Losh /* Make sure the new CRTC will work with the encoder */
718*592ffb21SWarner Losh if (new_crtc &&
719*592ffb21SWarner Losh !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
720*592ffb21SWarner Losh ret = -EINVAL;
721*592ffb21SWarner Losh goto fail;
722*592ffb21SWarner Losh }
723*592ffb21SWarner Losh if (new_crtc != connector->encoder->crtc) {
724*592ffb21SWarner Losh DRM_DEBUG_KMS("crtc changed, full mode switch\n");
725*592ffb21SWarner Losh mode_changed = true;
726*592ffb21SWarner Losh connector->encoder->crtc = new_crtc;
727*592ffb21SWarner Losh }
728*592ffb21SWarner Losh if (new_crtc) {
729*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
730*592ffb21SWarner Losh connector->base.id, drm_get_connector_name(connector),
731*592ffb21SWarner Losh new_crtc->base.id);
732*592ffb21SWarner Losh } else {
733*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
734*592ffb21SWarner Losh connector->base.id, drm_get_connector_name(connector));
735*592ffb21SWarner Losh }
736*592ffb21SWarner Losh }
737*592ffb21SWarner Losh
738*592ffb21SWarner Losh /* mode_set_base is not a required function */
739*592ffb21SWarner Losh if (fb_changed && !crtc_funcs->mode_set_base)
740*592ffb21SWarner Losh mode_changed = true;
741*592ffb21SWarner Losh
742*592ffb21SWarner Losh if (mode_changed) {
743*592ffb21SWarner Losh set->crtc->enabled = drm_helper_crtc_in_use(set->crtc);
744*592ffb21SWarner Losh if (set->crtc->enabled) {
745*592ffb21SWarner Losh DRM_DEBUG_KMS("attempting to set mode from"
746*592ffb21SWarner Losh " userspace\n");
747*592ffb21SWarner Losh drm_mode_debug_printmodeline(set->mode);
748*592ffb21SWarner Losh old_fb = set->crtc->fb;
749*592ffb21SWarner Losh set->crtc->fb = set->fb;
750*592ffb21SWarner Losh if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
751*592ffb21SWarner Losh set->x, set->y,
752*592ffb21SWarner Losh old_fb)) {
753*592ffb21SWarner Losh DRM_ERROR("failed to set mode on [CRTC:%d]\n",
754*592ffb21SWarner Losh set->crtc->base.id);
755*592ffb21SWarner Losh set->crtc->fb = old_fb;
756*592ffb21SWarner Losh ret = -EINVAL;
757*592ffb21SWarner Losh goto fail;
758*592ffb21SWarner Losh }
759*592ffb21SWarner Losh DRM_DEBUG_KMS("Setting connector DPMS state to on\n");
760*592ffb21SWarner Losh for (i = 0; i < set->num_connectors; i++) {
761*592ffb21SWarner Losh DRM_DEBUG_KMS("\t[CONNECTOR:%d:%s] set DPMS on\n", set->connectors[i]->base.id,
762*592ffb21SWarner Losh drm_get_connector_name(set->connectors[i]));
763*592ffb21SWarner Losh set->connectors[i]->funcs->dpms(set->connectors[i], DRM_MODE_DPMS_ON);
764*592ffb21SWarner Losh }
765*592ffb21SWarner Losh }
766*592ffb21SWarner Losh drm_helper_disable_unused_functions(dev);
767*592ffb21SWarner Losh } else if (fb_changed) {
768*592ffb21SWarner Losh set->crtc->x = set->x;
769*592ffb21SWarner Losh set->crtc->y = set->y;
770*592ffb21SWarner Losh
771*592ffb21SWarner Losh old_fb = set->crtc->fb;
772*592ffb21SWarner Losh if (set->crtc->fb != set->fb)
773*592ffb21SWarner Losh set->crtc->fb = set->fb;
774*592ffb21SWarner Losh ret = crtc_funcs->mode_set_base(set->crtc,
775*592ffb21SWarner Losh set->x, set->y, old_fb);
776*592ffb21SWarner Losh if (ret != 0) {
777*592ffb21SWarner Losh set->crtc->fb = old_fb;
778*592ffb21SWarner Losh goto fail;
779*592ffb21SWarner Losh }
780*592ffb21SWarner Losh }
781*592ffb21SWarner Losh
782*592ffb21SWarner Losh free(save_connectors, DRM_MEM_KMS);
783*592ffb21SWarner Losh free(save_encoders, DRM_MEM_KMS);
784*592ffb21SWarner Losh free(save_crtcs, DRM_MEM_KMS);
785*592ffb21SWarner Losh return 0;
786*592ffb21SWarner Losh
787*592ffb21SWarner Losh fail:
788*592ffb21SWarner Losh /* Restore all previous data. */
789*592ffb21SWarner Losh count = 0;
790*592ffb21SWarner Losh list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
791*592ffb21SWarner Losh *crtc = save_crtcs[count++];
792*592ffb21SWarner Losh }
793*592ffb21SWarner Losh
794*592ffb21SWarner Losh count = 0;
795*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
796*592ffb21SWarner Losh *encoder = save_encoders[count++];
797*592ffb21SWarner Losh }
798*592ffb21SWarner Losh
799*592ffb21SWarner Losh count = 0;
800*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
801*592ffb21SWarner Losh *connector = save_connectors[count++];
802*592ffb21SWarner Losh }
803*592ffb21SWarner Losh
804*592ffb21SWarner Losh /* Try to restore the config */
805*592ffb21SWarner Losh if (mode_changed &&
806*592ffb21SWarner Losh !drm_crtc_helper_set_mode(save_set.crtc, save_set.mode, save_set.x,
807*592ffb21SWarner Losh save_set.y, save_set.fb))
808*592ffb21SWarner Losh DRM_ERROR("failed to restore config after modeset failure\n");
809*592ffb21SWarner Losh
810*592ffb21SWarner Losh free(save_connectors, DRM_MEM_KMS);
811*592ffb21SWarner Losh free(save_encoders, DRM_MEM_KMS);
812*592ffb21SWarner Losh free(save_crtcs, DRM_MEM_KMS);
813*592ffb21SWarner Losh return ret;
814*592ffb21SWarner Losh }
815*592ffb21SWarner Losh EXPORT_SYMBOL(drm_crtc_helper_set_config);
816*592ffb21SWarner Losh
drm_helper_choose_encoder_dpms(struct drm_encoder * encoder)817*592ffb21SWarner Losh static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder)
818*592ffb21SWarner Losh {
819*592ffb21SWarner Losh int dpms = DRM_MODE_DPMS_OFF;
820*592ffb21SWarner Losh struct drm_connector *connector;
821*592ffb21SWarner Losh struct drm_device *dev = encoder->dev;
822*592ffb21SWarner Losh
823*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head)
824*592ffb21SWarner Losh if (connector->encoder == encoder)
825*592ffb21SWarner Losh if (connector->dpms < dpms)
826*592ffb21SWarner Losh dpms = connector->dpms;
827*592ffb21SWarner Losh return dpms;
828*592ffb21SWarner Losh }
829*592ffb21SWarner Losh
drm_helper_choose_crtc_dpms(struct drm_crtc * crtc)830*592ffb21SWarner Losh static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc)
831*592ffb21SWarner Losh {
832*592ffb21SWarner Losh int dpms = DRM_MODE_DPMS_OFF;
833*592ffb21SWarner Losh struct drm_connector *connector;
834*592ffb21SWarner Losh struct drm_device *dev = crtc->dev;
835*592ffb21SWarner Losh
836*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head)
837*592ffb21SWarner Losh if (connector->encoder && connector->encoder->crtc == crtc)
838*592ffb21SWarner Losh if (connector->dpms < dpms)
839*592ffb21SWarner Losh dpms = connector->dpms;
840*592ffb21SWarner Losh return dpms;
841*592ffb21SWarner Losh }
842*592ffb21SWarner Losh
843*592ffb21SWarner Losh /**
844*592ffb21SWarner Losh * drm_helper_connector_dpms() - connector dpms helper implementation
845*592ffb21SWarner Losh * @connector: affected connector
846*592ffb21SWarner Losh * @mode: DPMS mode
847*592ffb21SWarner Losh *
848*592ffb21SWarner Losh * This is the main helper function provided by the crtc helper framework for
849*592ffb21SWarner Losh * implementing the DPMS connector attribute. It computes the new desired DPMS
850*592ffb21SWarner Losh * state for all encoders and crtcs in the output mesh and calls the ->dpms()
851*592ffb21SWarner Losh * callback provided by the driver appropriately.
852*592ffb21SWarner Losh */
drm_helper_connector_dpms(struct drm_connector * connector,int mode)853*592ffb21SWarner Losh void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
854*592ffb21SWarner Losh {
855*592ffb21SWarner Losh struct drm_encoder *encoder = connector->encoder;
856*592ffb21SWarner Losh struct drm_crtc *crtc = encoder ? encoder->crtc : NULL;
857*592ffb21SWarner Losh int old_dpms;
858*592ffb21SWarner Losh
859*592ffb21SWarner Losh if (mode == connector->dpms)
860*592ffb21SWarner Losh return;
861*592ffb21SWarner Losh
862*592ffb21SWarner Losh old_dpms = connector->dpms;
863*592ffb21SWarner Losh connector->dpms = mode;
864*592ffb21SWarner Losh
865*592ffb21SWarner Losh /* from off to on, do crtc then encoder */
866*592ffb21SWarner Losh if (mode < old_dpms) {
867*592ffb21SWarner Losh if (crtc) {
868*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
869*592ffb21SWarner Losh if (crtc_funcs->dpms)
870*592ffb21SWarner Losh (*crtc_funcs->dpms) (crtc,
871*592ffb21SWarner Losh drm_helper_choose_crtc_dpms(crtc));
872*592ffb21SWarner Losh }
873*592ffb21SWarner Losh if (encoder) {
874*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
875*592ffb21SWarner Losh if (encoder_funcs->dpms)
876*592ffb21SWarner Losh (*encoder_funcs->dpms) (encoder,
877*592ffb21SWarner Losh drm_helper_choose_encoder_dpms(encoder));
878*592ffb21SWarner Losh }
879*592ffb21SWarner Losh }
880*592ffb21SWarner Losh
881*592ffb21SWarner Losh /* from on to off, do encoder then crtc */
882*592ffb21SWarner Losh if (mode > old_dpms) {
883*592ffb21SWarner Losh if (encoder) {
884*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
885*592ffb21SWarner Losh if (encoder_funcs->dpms)
886*592ffb21SWarner Losh (*encoder_funcs->dpms) (encoder,
887*592ffb21SWarner Losh drm_helper_choose_encoder_dpms(encoder));
888*592ffb21SWarner Losh }
889*592ffb21SWarner Losh if (crtc) {
890*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
891*592ffb21SWarner Losh if (crtc_funcs->dpms)
892*592ffb21SWarner Losh (*crtc_funcs->dpms) (crtc,
893*592ffb21SWarner Losh drm_helper_choose_crtc_dpms(crtc));
894*592ffb21SWarner Losh }
895*592ffb21SWarner Losh }
896*592ffb21SWarner Losh
897*592ffb21SWarner Losh return;
898*592ffb21SWarner Losh }
899*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_connector_dpms);
900*592ffb21SWarner Losh
drm_helper_mode_fill_fb_struct(struct drm_framebuffer * fb,struct drm_mode_fb_cmd2 * mode_cmd)901*592ffb21SWarner Losh int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
902*592ffb21SWarner Losh struct drm_mode_fb_cmd2 *mode_cmd)
903*592ffb21SWarner Losh {
904*592ffb21SWarner Losh int i;
905*592ffb21SWarner Losh
906*592ffb21SWarner Losh fb->width = mode_cmd->width;
907*592ffb21SWarner Losh fb->height = mode_cmd->height;
908*592ffb21SWarner Losh for (i = 0; i < 4; i++) {
909*592ffb21SWarner Losh fb->pitches[i] = mode_cmd->pitches[i];
910*592ffb21SWarner Losh fb->offsets[i] = mode_cmd->offsets[i];
911*592ffb21SWarner Losh }
912*592ffb21SWarner Losh drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
913*592ffb21SWarner Losh &fb->bits_per_pixel);
914*592ffb21SWarner Losh fb->pixel_format = mode_cmd->pixel_format;
915*592ffb21SWarner Losh
916*592ffb21SWarner Losh return 0;
917*592ffb21SWarner Losh }
918*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct);
919*592ffb21SWarner Losh
drm_helper_resume_force_mode(struct drm_device * dev)920*592ffb21SWarner Losh int drm_helper_resume_force_mode(struct drm_device *dev)
921*592ffb21SWarner Losh {
922*592ffb21SWarner Losh struct drm_crtc *crtc;
923*592ffb21SWarner Losh struct drm_encoder *encoder;
924*592ffb21SWarner Losh struct drm_encoder_helper_funcs *encoder_funcs;
925*592ffb21SWarner Losh struct drm_crtc_helper_funcs *crtc_funcs;
926*592ffb21SWarner Losh int ret;
927*592ffb21SWarner Losh
928*592ffb21SWarner Losh list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
929*592ffb21SWarner Losh
930*592ffb21SWarner Losh if (!crtc->enabled)
931*592ffb21SWarner Losh continue;
932*592ffb21SWarner Losh
933*592ffb21SWarner Losh ret = drm_crtc_helper_set_mode(crtc, &crtc->mode,
934*592ffb21SWarner Losh crtc->x, crtc->y, crtc->fb);
935*592ffb21SWarner Losh
936*592ffb21SWarner Losh if (ret == false)
937*592ffb21SWarner Losh DRM_ERROR("failed to set mode on crtc %p\n", crtc);
938*592ffb21SWarner Losh
939*592ffb21SWarner Losh /* Turn off outputs that were already powered off */
940*592ffb21SWarner Losh if (drm_helper_choose_crtc_dpms(crtc)) {
941*592ffb21SWarner Losh list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
942*592ffb21SWarner Losh
943*592ffb21SWarner Losh if(encoder->crtc != crtc)
944*592ffb21SWarner Losh continue;
945*592ffb21SWarner Losh
946*592ffb21SWarner Losh encoder_funcs = encoder->helper_private;
947*592ffb21SWarner Losh if (encoder_funcs->dpms)
948*592ffb21SWarner Losh (*encoder_funcs->dpms) (encoder,
949*592ffb21SWarner Losh drm_helper_choose_encoder_dpms(encoder));
950*592ffb21SWarner Losh }
951*592ffb21SWarner Losh
952*592ffb21SWarner Losh crtc_funcs = crtc->helper_private;
953*592ffb21SWarner Losh if (crtc_funcs->dpms)
954*592ffb21SWarner Losh (*crtc_funcs->dpms) (crtc,
955*592ffb21SWarner Losh drm_helper_choose_crtc_dpms(crtc));
956*592ffb21SWarner Losh }
957*592ffb21SWarner Losh }
958*592ffb21SWarner Losh /* disable the unused connectors while restoring the modesetting */
959*592ffb21SWarner Losh drm_helper_disable_unused_functions(dev);
960*592ffb21SWarner Losh return 0;
961*592ffb21SWarner Losh }
962*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_resume_force_mode);
963*592ffb21SWarner Losh
drm_kms_helper_hotplug_event(struct drm_device * dev)964*592ffb21SWarner Losh void drm_kms_helper_hotplug_event(struct drm_device *dev)
965*592ffb21SWarner Losh {
966*592ffb21SWarner Losh /* send a uevent + call fbdev */
967*592ffb21SWarner Losh #ifdef FREEBSD_NOTYET
968*592ffb21SWarner Losh drm_sysfs_hotplug_event(dev);
969*592ffb21SWarner Losh #endif /* FREEBSD_NOTYET */
970*592ffb21SWarner Losh if (dev->mode_config.funcs->output_poll_changed)
971*592ffb21SWarner Losh dev->mode_config.funcs->output_poll_changed(dev);
972*592ffb21SWarner Losh }
973*592ffb21SWarner Losh EXPORT_SYMBOL(drm_kms_helper_hotplug_event);
974*592ffb21SWarner Losh
975*592ffb21SWarner Losh #define DRM_OUTPUT_POLL_PERIOD (10*HZ)
output_poll_execute(void * ctx,int pending)976*592ffb21SWarner Losh static void output_poll_execute(void *ctx, int pending)
977*592ffb21SWarner Losh {
978*592ffb21SWarner Losh struct drm_device *dev = ctx;
979*592ffb21SWarner Losh struct drm_connector *connector;
980*592ffb21SWarner Losh enum drm_connector_status old_status;
981*592ffb21SWarner Losh bool repoll = false, changed = false;
982*592ffb21SWarner Losh
983*592ffb21SWarner Losh if (!drm_kms_helper_poll)
984*592ffb21SWarner Losh return;
985*592ffb21SWarner Losh
986*592ffb21SWarner Losh sx_xlock(&dev->mode_config.mutex);
987*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
988*592ffb21SWarner Losh
989*592ffb21SWarner Losh /* Ignore forced connectors. */
990*592ffb21SWarner Losh if (connector->force)
991*592ffb21SWarner Losh continue;
992*592ffb21SWarner Losh
993*592ffb21SWarner Losh /* Ignore HPD capable connectors and connectors where we don't
994*592ffb21SWarner Losh * want any hotplug detection at all for polling. */
995*592ffb21SWarner Losh if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD)
996*592ffb21SWarner Losh continue;
997*592ffb21SWarner Losh
998*592ffb21SWarner Losh repoll = true;
999*592ffb21SWarner Losh
1000*592ffb21SWarner Losh old_status = connector->status;
1001*592ffb21SWarner Losh /* if we are connected and don't want to poll for disconnect
1002*592ffb21SWarner Losh skip it */
1003*592ffb21SWarner Losh if (old_status == connector_status_connected &&
1004*592ffb21SWarner Losh !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT))
1005*592ffb21SWarner Losh continue;
1006*592ffb21SWarner Losh
1007*592ffb21SWarner Losh connector->status = connector->funcs->detect(connector, false);
1008*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
1009*592ffb21SWarner Losh connector->base.id,
1010*592ffb21SWarner Losh drm_get_connector_name(connector),
1011*592ffb21SWarner Losh old_status, connector->status);
1012*592ffb21SWarner Losh if (old_status != connector->status)
1013*592ffb21SWarner Losh changed = true;
1014*592ffb21SWarner Losh }
1015*592ffb21SWarner Losh
1016*592ffb21SWarner Losh sx_xunlock(&dev->mode_config.mutex);
1017*592ffb21SWarner Losh
1018*592ffb21SWarner Losh if (changed)
1019*592ffb21SWarner Losh drm_kms_helper_hotplug_event(dev);
1020*592ffb21SWarner Losh
1021*592ffb21SWarner Losh if (repoll)
1022*592ffb21SWarner Losh taskqueue_enqueue_timeout(taskqueue_thread,
1023*592ffb21SWarner Losh &dev->mode_config.output_poll_work,
1024*592ffb21SWarner Losh DRM_OUTPUT_POLL_PERIOD);
1025*592ffb21SWarner Losh }
1026*592ffb21SWarner Losh
drm_kms_helper_poll_disable(struct drm_device * dev)1027*592ffb21SWarner Losh void drm_kms_helper_poll_disable(struct drm_device *dev)
1028*592ffb21SWarner Losh {
1029*592ffb21SWarner Losh if (!dev->mode_config.poll_enabled)
1030*592ffb21SWarner Losh return;
1031*592ffb21SWarner Losh taskqueue_cancel_timeout(taskqueue_thread,
1032*592ffb21SWarner Losh &dev->mode_config.output_poll_work, NULL);
1033*592ffb21SWarner Losh }
1034*592ffb21SWarner Losh EXPORT_SYMBOL(drm_kms_helper_poll_disable);
1035*592ffb21SWarner Losh
drm_kms_helper_poll_enable(struct drm_device * dev)1036*592ffb21SWarner Losh void drm_kms_helper_poll_enable(struct drm_device *dev)
1037*592ffb21SWarner Losh {
1038*592ffb21SWarner Losh bool poll = false;
1039*592ffb21SWarner Losh struct drm_connector *connector;
1040*592ffb21SWarner Losh
1041*592ffb21SWarner Losh if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll)
1042*592ffb21SWarner Losh return;
1043*592ffb21SWarner Losh
1044*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1045*592ffb21SWarner Losh if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT |
1046*592ffb21SWarner Losh DRM_CONNECTOR_POLL_DISCONNECT))
1047*592ffb21SWarner Losh poll = true;
1048*592ffb21SWarner Losh }
1049*592ffb21SWarner Losh
1050*592ffb21SWarner Losh if (poll)
1051*592ffb21SWarner Losh taskqueue_enqueue_timeout(taskqueue_thread,
1052*592ffb21SWarner Losh &dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD);
1053*592ffb21SWarner Losh }
1054*592ffb21SWarner Losh EXPORT_SYMBOL(drm_kms_helper_poll_enable);
1055*592ffb21SWarner Losh
drm_kms_helper_poll_init(struct drm_device * dev)1056*592ffb21SWarner Losh void drm_kms_helper_poll_init(struct drm_device *dev)
1057*592ffb21SWarner Losh {
1058*592ffb21SWarner Losh TIMEOUT_TASK_INIT(taskqueue_thread, &dev->mode_config.output_poll_work,
1059*592ffb21SWarner Losh 0, output_poll_execute, dev);
1060*592ffb21SWarner Losh dev->mode_config.poll_enabled = true;
1061*592ffb21SWarner Losh
1062*592ffb21SWarner Losh drm_kms_helper_poll_enable(dev);
1063*592ffb21SWarner Losh }
1064*592ffb21SWarner Losh EXPORT_SYMBOL(drm_kms_helper_poll_init);
1065*592ffb21SWarner Losh
drm_kms_helper_poll_fini(struct drm_device * dev)1066*592ffb21SWarner Losh void drm_kms_helper_poll_fini(struct drm_device *dev)
1067*592ffb21SWarner Losh {
1068*592ffb21SWarner Losh drm_kms_helper_poll_disable(dev);
1069*592ffb21SWarner Losh }
1070*592ffb21SWarner Losh EXPORT_SYMBOL(drm_kms_helper_poll_fini);
1071*592ffb21SWarner Losh
drm_helper_hpd_irq_event(struct drm_device * dev)1072*592ffb21SWarner Losh void drm_helper_hpd_irq_event(struct drm_device *dev)
1073*592ffb21SWarner Losh {
1074*592ffb21SWarner Losh struct drm_connector *connector;
1075*592ffb21SWarner Losh enum drm_connector_status old_status;
1076*592ffb21SWarner Losh bool changed = false;
1077*592ffb21SWarner Losh
1078*592ffb21SWarner Losh if (!dev->mode_config.poll_enabled)
1079*592ffb21SWarner Losh return;
1080*592ffb21SWarner Losh
1081*592ffb21SWarner Losh sx_xlock(&dev->mode_config.mutex);
1082*592ffb21SWarner Losh list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1083*592ffb21SWarner Losh
1084*592ffb21SWarner Losh /* Only handle HPD capable connectors. */
1085*592ffb21SWarner Losh if (!(connector->polled & DRM_CONNECTOR_POLL_HPD))
1086*592ffb21SWarner Losh continue;
1087*592ffb21SWarner Losh
1088*592ffb21SWarner Losh old_status = connector->status;
1089*592ffb21SWarner Losh
1090*592ffb21SWarner Losh connector->status = connector->funcs->detect(connector, false);
1091*592ffb21SWarner Losh DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
1092*592ffb21SWarner Losh connector->base.id,
1093*592ffb21SWarner Losh drm_get_connector_name(connector),
1094*592ffb21SWarner Losh old_status, connector->status);
1095*592ffb21SWarner Losh if (old_status != connector->status)
1096*592ffb21SWarner Losh changed = true;
1097*592ffb21SWarner Losh }
1098*592ffb21SWarner Losh
1099*592ffb21SWarner Losh sx_xunlock(&dev->mode_config.mutex);
1100*592ffb21SWarner Losh
1101*592ffb21SWarner Losh if (changed)
1102*592ffb21SWarner Losh drm_kms_helper_hotplug_event(dev);
1103*592ffb21SWarner Losh }
1104*592ffb21SWarner Losh EXPORT_SYMBOL(drm_helper_hpd_irq_event);
1105