1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2006-2007 Intel Corporation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun * Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun * DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * Authors:
24*4882a593Smuzhiyun * Eric Anholt <eric@anholt.net>
25*4882a593Smuzhiyun */
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #include <linux/dmi.h>
28*4882a593Smuzhiyun #include <linux/i2c.h>
29*4882a593Smuzhiyun #include <linux/slab.h>
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <drm/drm_atomic_helper.h>
32*4882a593Smuzhiyun #include <drm/drm_crtc.h>
33*4882a593Smuzhiyun #include <drm/drm_edid.h>
34*4882a593Smuzhiyun #include <drm/drm_probe_helper.h>
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include "i915_drv.h"
37*4882a593Smuzhiyun #include "intel_connector.h"
38*4882a593Smuzhiyun #include "intel_crt.h"
39*4882a593Smuzhiyun #include "intel_ddi.h"
40*4882a593Smuzhiyun #include "intel_display_types.h"
41*4882a593Smuzhiyun #include "intel_fifo_underrun.h"
42*4882a593Smuzhiyun #include "intel_gmbus.h"
43*4882a593Smuzhiyun #include "intel_hotplug.h"
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /* Here's the desired hotplug mode */
46*4882a593Smuzhiyun #define ADPA_HOTPLUG_BITS (ADPA_CRT_HOTPLUG_PERIOD_128 | \
47*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_WARMUP_10MS | \
48*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_SAMPLE_4S | \
49*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_VOLTAGE_50 | \
50*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_VOLREF_325MV | \
51*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_ENABLE)
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun struct intel_crt {
54*4882a593Smuzhiyun struct intel_encoder base;
55*4882a593Smuzhiyun /* DPMS state is stored in the connector, which we need in the
56*4882a593Smuzhiyun * encoder's enable/disable callbacks */
57*4882a593Smuzhiyun struct intel_connector *connector;
58*4882a593Smuzhiyun bool force_hotplug_required;
59*4882a593Smuzhiyun i915_reg_t adpa_reg;
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun
intel_encoder_to_crt(struct intel_encoder * encoder)62*4882a593Smuzhiyun static struct intel_crt *intel_encoder_to_crt(struct intel_encoder *encoder)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun return container_of(encoder, struct intel_crt, base);
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun
intel_attached_crt(struct intel_connector * connector)67*4882a593Smuzhiyun static struct intel_crt *intel_attached_crt(struct intel_connector *connector)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun return intel_encoder_to_crt(intel_attached_encoder(connector));
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
intel_crt_port_enabled(struct drm_i915_private * dev_priv,i915_reg_t adpa_reg,enum pipe * pipe)72*4882a593Smuzhiyun bool intel_crt_port_enabled(struct drm_i915_private *dev_priv,
73*4882a593Smuzhiyun i915_reg_t adpa_reg, enum pipe *pipe)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun u32 val;
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun val = intel_de_read(dev_priv, adpa_reg);
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /* asserts want to know the pipe even if the port is disabled */
80*4882a593Smuzhiyun if (HAS_PCH_CPT(dev_priv))
81*4882a593Smuzhiyun *pipe = (val & ADPA_PIPE_SEL_MASK_CPT) >> ADPA_PIPE_SEL_SHIFT_CPT;
82*4882a593Smuzhiyun else
83*4882a593Smuzhiyun *pipe = (val & ADPA_PIPE_SEL_MASK) >> ADPA_PIPE_SEL_SHIFT;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun return val & ADPA_DAC_ENABLE;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
intel_crt_get_hw_state(struct intel_encoder * encoder,enum pipe * pipe)88*4882a593Smuzhiyun static bool intel_crt_get_hw_state(struct intel_encoder *encoder,
89*4882a593Smuzhiyun enum pipe *pipe)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
92*4882a593Smuzhiyun struct intel_crt *crt = intel_encoder_to_crt(encoder);
93*4882a593Smuzhiyun intel_wakeref_t wakeref;
94*4882a593Smuzhiyun bool ret;
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun wakeref = intel_display_power_get_if_enabled(dev_priv,
97*4882a593Smuzhiyun encoder->power_domain);
98*4882a593Smuzhiyun if (!wakeref)
99*4882a593Smuzhiyun return false;
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun ret = intel_crt_port_enabled(dev_priv, crt->adpa_reg, pipe);
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun intel_display_power_put(dev_priv, encoder->power_domain, wakeref);
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun return ret;
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
intel_crt_get_flags(struct intel_encoder * encoder)108*4882a593Smuzhiyun static unsigned int intel_crt_get_flags(struct intel_encoder *encoder)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
111*4882a593Smuzhiyun struct intel_crt *crt = intel_encoder_to_crt(encoder);
112*4882a593Smuzhiyun u32 tmp, flags = 0;
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun tmp = intel_de_read(dev_priv, crt->adpa_reg);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun if (tmp & ADPA_HSYNC_ACTIVE_HIGH)
117*4882a593Smuzhiyun flags |= DRM_MODE_FLAG_PHSYNC;
118*4882a593Smuzhiyun else
119*4882a593Smuzhiyun flags |= DRM_MODE_FLAG_NHSYNC;
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun if (tmp & ADPA_VSYNC_ACTIVE_HIGH)
122*4882a593Smuzhiyun flags |= DRM_MODE_FLAG_PVSYNC;
123*4882a593Smuzhiyun else
124*4882a593Smuzhiyun flags |= DRM_MODE_FLAG_NVSYNC;
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun return flags;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
intel_crt_get_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config)129*4882a593Smuzhiyun static void intel_crt_get_config(struct intel_encoder *encoder,
130*4882a593Smuzhiyun struct intel_crtc_state *pipe_config)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun pipe_config->hw.adjusted_mode.flags |= intel_crt_get_flags(encoder);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun pipe_config->hw.adjusted_mode.crtc_clock = pipe_config->port_clock;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun
hsw_crt_get_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config)139*4882a593Smuzhiyun static void hsw_crt_get_config(struct intel_encoder *encoder,
140*4882a593Smuzhiyun struct intel_crtc_state *pipe_config)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun intel_ddi_get_config(encoder, pipe_config);
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun pipe_config->hw.adjusted_mode.flags &= ~(DRM_MODE_FLAG_PHSYNC |
147*4882a593Smuzhiyun DRM_MODE_FLAG_NHSYNC |
148*4882a593Smuzhiyun DRM_MODE_FLAG_PVSYNC |
149*4882a593Smuzhiyun DRM_MODE_FLAG_NVSYNC);
150*4882a593Smuzhiyun pipe_config->hw.adjusted_mode.flags |= intel_crt_get_flags(encoder);
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun pipe_config->hw.adjusted_mode.crtc_clock = lpt_get_iclkip(dev_priv);
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun /* Note: The caller is required to filter out dpms modes not supported by the
156*4882a593Smuzhiyun * platform. */
intel_crt_set_dpms(struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,int mode)157*4882a593Smuzhiyun static void intel_crt_set_dpms(struct intel_encoder *encoder,
158*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
159*4882a593Smuzhiyun int mode)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
162*4882a593Smuzhiyun struct intel_crt *crt = intel_encoder_to_crt(encoder);
163*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
164*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
165*4882a593Smuzhiyun u32 adpa;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 5)
168*4882a593Smuzhiyun adpa = ADPA_HOTPLUG_BITS;
169*4882a593Smuzhiyun else
170*4882a593Smuzhiyun adpa = 0;
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
173*4882a593Smuzhiyun adpa |= ADPA_HSYNC_ACTIVE_HIGH;
174*4882a593Smuzhiyun if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
175*4882a593Smuzhiyun adpa |= ADPA_VSYNC_ACTIVE_HIGH;
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /* For CPT allow 3 pipe config, for others just use A or B */
178*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv))
179*4882a593Smuzhiyun ; /* Those bits don't exist here */
180*4882a593Smuzhiyun else if (HAS_PCH_CPT(dev_priv))
181*4882a593Smuzhiyun adpa |= ADPA_PIPE_SEL_CPT(crtc->pipe);
182*4882a593Smuzhiyun else
183*4882a593Smuzhiyun adpa |= ADPA_PIPE_SEL(crtc->pipe);
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun if (!HAS_PCH_SPLIT(dev_priv))
186*4882a593Smuzhiyun intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun switch (mode) {
189*4882a593Smuzhiyun case DRM_MODE_DPMS_ON:
190*4882a593Smuzhiyun adpa |= ADPA_DAC_ENABLE;
191*4882a593Smuzhiyun break;
192*4882a593Smuzhiyun case DRM_MODE_DPMS_STANDBY:
193*4882a593Smuzhiyun adpa |= ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE;
194*4882a593Smuzhiyun break;
195*4882a593Smuzhiyun case DRM_MODE_DPMS_SUSPEND:
196*4882a593Smuzhiyun adpa |= ADPA_DAC_ENABLE | ADPA_VSYNC_CNTL_DISABLE;
197*4882a593Smuzhiyun break;
198*4882a593Smuzhiyun case DRM_MODE_DPMS_OFF:
199*4882a593Smuzhiyun adpa |= ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE;
200*4882a593Smuzhiyun break;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, adpa);
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
intel_disable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)206*4882a593Smuzhiyun static void intel_disable_crt(struct intel_atomic_state *state,
207*4882a593Smuzhiyun struct intel_encoder *encoder,
208*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state,
209*4882a593Smuzhiyun const struct drm_connector_state *old_conn_state)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun intel_crt_set_dpms(encoder, old_crtc_state, DRM_MODE_DPMS_OFF);
212*4882a593Smuzhiyun }
213*4882a593Smuzhiyun
pch_disable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)214*4882a593Smuzhiyun static void pch_disable_crt(struct intel_atomic_state *state,
215*4882a593Smuzhiyun struct intel_encoder *encoder,
216*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state,
217*4882a593Smuzhiyun const struct drm_connector_state *old_conn_state)
218*4882a593Smuzhiyun {
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
pch_post_disable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)221*4882a593Smuzhiyun static void pch_post_disable_crt(struct intel_atomic_state *state,
222*4882a593Smuzhiyun struct intel_encoder *encoder,
223*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state,
224*4882a593Smuzhiyun const struct drm_connector_state *old_conn_state)
225*4882a593Smuzhiyun {
226*4882a593Smuzhiyun intel_disable_crt(state, encoder, old_crtc_state, old_conn_state);
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun
hsw_disable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)229*4882a593Smuzhiyun static void hsw_disable_crt(struct intel_atomic_state *state,
230*4882a593Smuzhiyun struct intel_encoder *encoder,
231*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state,
232*4882a593Smuzhiyun const struct drm_connector_state *old_conn_state)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !old_crtc_state->has_pch_encoder);
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun
hsw_post_disable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * old_crtc_state,const struct drm_connector_state * old_conn_state)241*4882a593Smuzhiyun static void hsw_post_disable_crt(struct intel_atomic_state *state,
242*4882a593Smuzhiyun struct intel_encoder *encoder,
243*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state,
244*4882a593Smuzhiyun const struct drm_connector_state *old_conn_state)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun intel_crtc_vblank_off(old_crtc_state);
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun intel_disable_pipe(old_crtc_state);
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun intel_ddi_disable_transcoder_func(old_crtc_state);
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun ilk_pfit_disable(old_crtc_state);
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun intel_ddi_disable_pipe_clock(old_crtc_state);
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun pch_post_disable_crt(state, encoder, old_crtc_state, old_conn_state);
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun lpt_disable_pch_transcoder(dev_priv);
261*4882a593Smuzhiyun lpt_disable_iclkip(dev_priv);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun intel_ddi_fdi_post_disable(state, encoder, old_crtc_state, old_conn_state);
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !old_crtc_state->has_pch_encoder);
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
hsw_pre_pll_enable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)270*4882a593Smuzhiyun static void hsw_pre_pll_enable_crt(struct intel_atomic_state *state,
271*4882a593Smuzhiyun struct intel_encoder *encoder,
272*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
273*4882a593Smuzhiyun const struct drm_connector_state *conn_state)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !crtc_state->has_pch_encoder);
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun
hsw_pre_enable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)282*4882a593Smuzhiyun static void hsw_pre_enable_crt(struct intel_atomic_state *state,
283*4882a593Smuzhiyun struct intel_encoder *encoder,
284*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
285*4882a593Smuzhiyun const struct drm_connector_state *conn_state)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
288*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
289*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !crtc_state->has_pch_encoder);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun hsw_fdi_link_train(encoder, crtc_state);
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun intel_ddi_enable_pipe_clock(encoder, crtc_state);
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun
hsw_enable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)300*4882a593Smuzhiyun static void hsw_enable_crt(struct intel_atomic_state *state,
301*4882a593Smuzhiyun struct intel_encoder *encoder,
302*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
303*4882a593Smuzhiyun const struct drm_connector_state *conn_state)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
306*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
307*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !crtc_state->has_pch_encoder);
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun intel_ddi_enable_transcoder_func(encoder, crtc_state);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun intel_enable_pipe(crtc_state);
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun lpt_pch_enable(crtc_state);
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun intel_crtc_vblank_on(crtc_state);
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun intel_crt_set_dpms(encoder, crtc_state, DRM_MODE_DPMS_ON);
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun intel_wait_for_vblank(dev_priv, pipe);
322*4882a593Smuzhiyun intel_wait_for_vblank(dev_priv, pipe);
323*4882a593Smuzhiyun intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
324*4882a593Smuzhiyun intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun
intel_enable_crt(struct intel_atomic_state * state,struct intel_encoder * encoder,const struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)327*4882a593Smuzhiyun static void intel_enable_crt(struct intel_atomic_state *state,
328*4882a593Smuzhiyun struct intel_encoder *encoder,
329*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
330*4882a593Smuzhiyun const struct drm_connector_state *conn_state)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun intel_crt_set_dpms(encoder, crtc_state, DRM_MODE_DPMS_ON);
333*4882a593Smuzhiyun }
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun static enum drm_mode_status
intel_crt_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)336*4882a593Smuzhiyun intel_crt_mode_valid(struct drm_connector *connector,
337*4882a593Smuzhiyun struct drm_display_mode *mode)
338*4882a593Smuzhiyun {
339*4882a593Smuzhiyun struct drm_device *dev = connector->dev;
340*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
341*4882a593Smuzhiyun int max_dotclk = dev_priv->max_dotclk_freq;
342*4882a593Smuzhiyun int max_clock;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
345*4882a593Smuzhiyun return MODE_NO_DBLESCAN;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun if (mode->clock < 25000)
348*4882a593Smuzhiyun return MODE_CLOCK_LOW;
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv))
351*4882a593Smuzhiyun max_clock = 180000;
352*4882a593Smuzhiyun else if (IS_VALLEYVIEW(dev_priv))
353*4882a593Smuzhiyun /*
354*4882a593Smuzhiyun * 270 MHz due to current DPLL limits,
355*4882a593Smuzhiyun * DAC limit supposedly 355 MHz.
356*4882a593Smuzhiyun */
357*4882a593Smuzhiyun max_clock = 270000;
358*4882a593Smuzhiyun else if (IS_GEN_RANGE(dev_priv, 3, 4))
359*4882a593Smuzhiyun max_clock = 400000;
360*4882a593Smuzhiyun else
361*4882a593Smuzhiyun max_clock = 350000;
362*4882a593Smuzhiyun if (mode->clock > max_clock)
363*4882a593Smuzhiyun return MODE_CLOCK_HIGH;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun if (mode->clock > max_dotclk)
366*4882a593Smuzhiyun return MODE_CLOCK_HIGH;
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun /* The FDI receiver on LPT only supports 8bpc and only has 2 lanes. */
369*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv) &&
370*4882a593Smuzhiyun ilk_get_lanes_required(mode->clock, 270000, 24) > 2)
371*4882a593Smuzhiyun return MODE_CLOCK_HIGH;
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun /* HSW/BDW FDI limited to 4k */
374*4882a593Smuzhiyun if (mode->hdisplay > 4096)
375*4882a593Smuzhiyun return MODE_H_ILLEGAL;
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun return MODE_OK;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun
intel_crt_compute_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config,struct drm_connector_state * conn_state)380*4882a593Smuzhiyun static int intel_crt_compute_config(struct intel_encoder *encoder,
381*4882a593Smuzhiyun struct intel_crtc_state *pipe_config,
382*4882a593Smuzhiyun struct drm_connector_state *conn_state)
383*4882a593Smuzhiyun {
384*4882a593Smuzhiyun struct drm_display_mode *adjusted_mode =
385*4882a593Smuzhiyun &pipe_config->hw.adjusted_mode;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
388*4882a593Smuzhiyun return -EINVAL;
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun return 0;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun
pch_crt_compute_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config,struct drm_connector_state * conn_state)395*4882a593Smuzhiyun static int pch_crt_compute_config(struct intel_encoder *encoder,
396*4882a593Smuzhiyun struct intel_crtc_state *pipe_config,
397*4882a593Smuzhiyun struct drm_connector_state *conn_state)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun struct drm_display_mode *adjusted_mode =
400*4882a593Smuzhiyun &pipe_config->hw.adjusted_mode;
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
403*4882a593Smuzhiyun return -EINVAL;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun pipe_config->has_pch_encoder = true;
406*4882a593Smuzhiyun pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun return 0;
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun
hsw_crt_compute_config(struct intel_encoder * encoder,struct intel_crtc_state * pipe_config,struct drm_connector_state * conn_state)411*4882a593Smuzhiyun static int hsw_crt_compute_config(struct intel_encoder *encoder,
412*4882a593Smuzhiyun struct intel_crtc_state *pipe_config,
413*4882a593Smuzhiyun struct drm_connector_state *conn_state)
414*4882a593Smuzhiyun {
415*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
416*4882a593Smuzhiyun struct drm_display_mode *adjusted_mode =
417*4882a593Smuzhiyun &pipe_config->hw.adjusted_mode;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
420*4882a593Smuzhiyun return -EINVAL;
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun /* HSW/BDW FDI limited to 4k */
423*4882a593Smuzhiyun if (adjusted_mode->crtc_hdisplay > 4096 ||
424*4882a593Smuzhiyun adjusted_mode->crtc_hblank_start > 4096)
425*4882a593Smuzhiyun return -EINVAL;
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun pipe_config->has_pch_encoder = true;
428*4882a593Smuzhiyun pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun /* LPT FDI RX only supports 8bpc. */
431*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv)) {
432*4882a593Smuzhiyun if (pipe_config->bw_constrained && pipe_config->pipe_bpp < 24) {
433*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
434*4882a593Smuzhiyun "LPT only supports 24bpp\n");
435*4882a593Smuzhiyun return -EINVAL;
436*4882a593Smuzhiyun }
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun pipe_config->pipe_bpp = 24;
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* FDI must always be 2.7 GHz */
442*4882a593Smuzhiyun pipe_config->port_clock = 135000 * 2;
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun return 0;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
ilk_crt_detect_hotplug(struct drm_connector * connector)447*4882a593Smuzhiyun static bool ilk_crt_detect_hotplug(struct drm_connector *connector)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun struct drm_device *dev = connector->dev;
450*4882a593Smuzhiyun struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector));
451*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
452*4882a593Smuzhiyun u32 adpa;
453*4882a593Smuzhiyun bool ret;
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun /* The first time through, trigger an explicit detection cycle */
456*4882a593Smuzhiyun if (crt->force_hotplug_required) {
457*4882a593Smuzhiyun bool turn_off_dac = HAS_PCH_SPLIT(dev_priv);
458*4882a593Smuzhiyun u32 save_adpa;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun crt->force_hotplug_required = false;
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun save_adpa = adpa = intel_de_read(dev_priv, crt->adpa_reg);
463*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
464*4882a593Smuzhiyun "trigger hotplug detect cycle: adpa=0x%x\n", adpa);
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
467*4882a593Smuzhiyun if (turn_off_dac)
468*4882a593Smuzhiyun adpa &= ~ADPA_DAC_ENABLE;
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, adpa);
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun if (intel_de_wait_for_clear(dev_priv,
473*4882a593Smuzhiyun crt->adpa_reg,
474*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_FORCE_TRIGGER,
475*4882a593Smuzhiyun 1000))
476*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
477*4882a593Smuzhiyun "timed out waiting for FORCE_TRIGGER");
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun if (turn_off_dac) {
480*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, save_adpa);
481*4882a593Smuzhiyun intel_de_posting_read(dev_priv, crt->adpa_reg);
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun }
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun /* Check the status to see if both blue and green are on now */
486*4882a593Smuzhiyun adpa = intel_de_read(dev_priv, crt->adpa_reg);
487*4882a593Smuzhiyun if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
488*4882a593Smuzhiyun ret = true;
489*4882a593Smuzhiyun else
490*4882a593Smuzhiyun ret = false;
491*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "ironlake hotplug adpa=0x%x, result %d\n",
492*4882a593Smuzhiyun adpa, ret);
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun return ret;
495*4882a593Smuzhiyun }
496*4882a593Smuzhiyun
valleyview_crt_detect_hotplug(struct drm_connector * connector)497*4882a593Smuzhiyun static bool valleyview_crt_detect_hotplug(struct drm_connector *connector)
498*4882a593Smuzhiyun {
499*4882a593Smuzhiyun struct drm_device *dev = connector->dev;
500*4882a593Smuzhiyun struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector));
501*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
502*4882a593Smuzhiyun bool reenable_hpd;
503*4882a593Smuzhiyun u32 adpa;
504*4882a593Smuzhiyun bool ret;
505*4882a593Smuzhiyun u32 save_adpa;
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun /*
508*4882a593Smuzhiyun * Doing a force trigger causes a hpd interrupt to get sent, which can
509*4882a593Smuzhiyun * get us stuck in a loop if we're polling:
510*4882a593Smuzhiyun * - We enable power wells and reset the ADPA
511*4882a593Smuzhiyun * - output_poll_exec does force probe on VGA, triggering a hpd
512*4882a593Smuzhiyun * - HPD handler waits for poll to unlock dev->mode_config.mutex
513*4882a593Smuzhiyun * - output_poll_exec shuts off the ADPA, unlocks
514*4882a593Smuzhiyun * dev->mode_config.mutex
515*4882a593Smuzhiyun * - HPD handler runs, resets ADPA and brings us back to the start
516*4882a593Smuzhiyun *
517*4882a593Smuzhiyun * Just disable HPD interrupts here to prevent this
518*4882a593Smuzhiyun */
519*4882a593Smuzhiyun reenable_hpd = intel_hpd_disable(dev_priv, crt->base.hpd_pin);
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun save_adpa = adpa = intel_de_read(dev_priv, crt->adpa_reg);
522*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
523*4882a593Smuzhiyun "trigger hotplug detect cycle: adpa=0x%x\n", adpa);
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun adpa |= ADPA_CRT_HOTPLUG_FORCE_TRIGGER;
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, adpa);
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun if (intel_de_wait_for_clear(dev_priv, crt->adpa_reg,
530*4882a593Smuzhiyun ADPA_CRT_HOTPLUG_FORCE_TRIGGER, 1000)) {
531*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
532*4882a593Smuzhiyun "timed out waiting for FORCE_TRIGGER");
533*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, save_adpa);
534*4882a593Smuzhiyun }
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun /* Check the status to see if both blue and green are on now */
537*4882a593Smuzhiyun adpa = intel_de_read(dev_priv, crt->adpa_reg);
538*4882a593Smuzhiyun if ((adpa & ADPA_CRT_HOTPLUG_MONITOR_MASK) != 0)
539*4882a593Smuzhiyun ret = true;
540*4882a593Smuzhiyun else
541*4882a593Smuzhiyun ret = false;
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
544*4882a593Smuzhiyun "valleyview hotplug adpa=0x%x, result %d\n", adpa, ret);
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun if (reenable_hpd)
547*4882a593Smuzhiyun intel_hpd_enable(dev_priv, crt->base.hpd_pin);
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun return ret;
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun
intel_crt_detect_hotplug(struct drm_connector * connector)552*4882a593Smuzhiyun static bool intel_crt_detect_hotplug(struct drm_connector *connector)
553*4882a593Smuzhiyun {
554*4882a593Smuzhiyun struct drm_device *dev = connector->dev;
555*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
556*4882a593Smuzhiyun u32 stat;
557*4882a593Smuzhiyun bool ret = false;
558*4882a593Smuzhiyun int i, tries = 0;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun if (HAS_PCH_SPLIT(dev_priv))
561*4882a593Smuzhiyun return ilk_crt_detect_hotplug(connector);
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun if (IS_VALLEYVIEW(dev_priv))
564*4882a593Smuzhiyun return valleyview_crt_detect_hotplug(connector);
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun /*
567*4882a593Smuzhiyun * On 4 series desktop, CRT detect sequence need to be done twice
568*4882a593Smuzhiyun * to get a reliable result.
569*4882a593Smuzhiyun */
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun if (IS_G45(dev_priv))
572*4882a593Smuzhiyun tries = 2;
573*4882a593Smuzhiyun else
574*4882a593Smuzhiyun tries = 1;
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun for (i = 0; i < tries ; i++) {
577*4882a593Smuzhiyun /* turn on the FORCE_DETECT */
578*4882a593Smuzhiyun i915_hotplug_interrupt_update(dev_priv,
579*4882a593Smuzhiyun CRT_HOTPLUG_FORCE_DETECT,
580*4882a593Smuzhiyun CRT_HOTPLUG_FORCE_DETECT);
581*4882a593Smuzhiyun /* wait for FORCE_DETECT to go off */
582*4882a593Smuzhiyun if (intel_de_wait_for_clear(dev_priv, PORT_HOTPLUG_EN,
583*4882a593Smuzhiyun CRT_HOTPLUG_FORCE_DETECT, 1000))
584*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
585*4882a593Smuzhiyun "timed out waiting for FORCE_DETECT to go off");
586*4882a593Smuzhiyun }
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun stat = intel_de_read(dev_priv, PORT_HOTPLUG_STAT);
589*4882a593Smuzhiyun if ((stat & CRT_HOTPLUG_MONITOR_MASK) != CRT_HOTPLUG_MONITOR_NONE)
590*4882a593Smuzhiyun ret = true;
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun /* clear the interrupt we just generated, if any */
593*4882a593Smuzhiyun intel_de_write(dev_priv, PORT_HOTPLUG_STAT, CRT_HOTPLUG_INT_STATUS);
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun i915_hotplug_interrupt_update(dev_priv, CRT_HOTPLUG_FORCE_DETECT, 0);
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun return ret;
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun
intel_crt_get_edid(struct drm_connector * connector,struct i2c_adapter * i2c)600*4882a593Smuzhiyun static struct edid *intel_crt_get_edid(struct drm_connector *connector,
601*4882a593Smuzhiyun struct i2c_adapter *i2c)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun struct edid *edid;
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun edid = drm_get_edid(connector, i2c);
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun if (!edid && !intel_gmbus_is_forced_bit(i2c)) {
608*4882a593Smuzhiyun drm_dbg_kms(connector->dev,
609*4882a593Smuzhiyun "CRT GMBUS EDID read failed, retry using GPIO bit-banging\n");
610*4882a593Smuzhiyun intel_gmbus_force_bit(i2c, true);
611*4882a593Smuzhiyun edid = drm_get_edid(connector, i2c);
612*4882a593Smuzhiyun intel_gmbus_force_bit(i2c, false);
613*4882a593Smuzhiyun }
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun return edid;
616*4882a593Smuzhiyun }
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun /* local version of intel_ddc_get_modes() to use intel_crt_get_edid() */
intel_crt_ddc_get_modes(struct drm_connector * connector,struct i2c_adapter * adapter)619*4882a593Smuzhiyun static int intel_crt_ddc_get_modes(struct drm_connector *connector,
620*4882a593Smuzhiyun struct i2c_adapter *adapter)
621*4882a593Smuzhiyun {
622*4882a593Smuzhiyun struct edid *edid;
623*4882a593Smuzhiyun int ret;
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun edid = intel_crt_get_edid(connector, adapter);
626*4882a593Smuzhiyun if (!edid)
627*4882a593Smuzhiyun return 0;
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun ret = intel_connector_update_modes(connector, edid);
630*4882a593Smuzhiyun kfree(edid);
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun return ret;
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun
intel_crt_detect_ddc(struct drm_connector * connector)635*4882a593Smuzhiyun static bool intel_crt_detect_ddc(struct drm_connector *connector)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector));
638*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crt->base.base.dev);
639*4882a593Smuzhiyun struct edid *edid;
640*4882a593Smuzhiyun struct i2c_adapter *i2c;
641*4882a593Smuzhiyun bool ret = false;
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun BUG_ON(crt->base.type != INTEL_OUTPUT_ANALOG);
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->vbt.crt_ddc_pin);
646*4882a593Smuzhiyun edid = intel_crt_get_edid(connector, i2c);
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun if (edid) {
649*4882a593Smuzhiyun bool is_digital = edid->input & DRM_EDID_INPUT_DIGITAL;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun /*
652*4882a593Smuzhiyun * This may be a DVI-I connector with a shared DDC
653*4882a593Smuzhiyun * link between analog and digital outputs, so we
654*4882a593Smuzhiyun * have to check the EDID input spec of the attached device.
655*4882a593Smuzhiyun */
656*4882a593Smuzhiyun if (!is_digital) {
657*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
658*4882a593Smuzhiyun "CRT detected via DDC:0x50 [EDID]\n");
659*4882a593Smuzhiyun ret = true;
660*4882a593Smuzhiyun } else {
661*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
662*4882a593Smuzhiyun "CRT not detected via DDC:0x50 [EDID reports a digital panel]\n");
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun } else {
665*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
666*4882a593Smuzhiyun "CRT not detected via DDC:0x50 [no valid EDID found]\n");
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun kfree(edid);
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun return ret;
672*4882a593Smuzhiyun }
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun static enum drm_connector_status
intel_crt_load_detect(struct intel_crt * crt,u32 pipe)675*4882a593Smuzhiyun intel_crt_load_detect(struct intel_crt *crt, u32 pipe)
676*4882a593Smuzhiyun {
677*4882a593Smuzhiyun struct drm_device *dev = crt->base.base.dev;
678*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
679*4882a593Smuzhiyun struct intel_uncore *uncore = &dev_priv->uncore;
680*4882a593Smuzhiyun u32 save_bclrpat;
681*4882a593Smuzhiyun u32 save_vtotal;
682*4882a593Smuzhiyun u32 vtotal, vactive;
683*4882a593Smuzhiyun u32 vsample;
684*4882a593Smuzhiyun u32 vblank, vblank_start, vblank_end;
685*4882a593Smuzhiyun u32 dsl;
686*4882a593Smuzhiyun i915_reg_t bclrpat_reg, vtotal_reg,
687*4882a593Smuzhiyun vblank_reg, vsync_reg, pipeconf_reg, pipe_dsl_reg;
688*4882a593Smuzhiyun u8 st00;
689*4882a593Smuzhiyun enum drm_connector_status status;
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "starting load-detect on CRT\n");
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun bclrpat_reg = BCLRPAT(pipe);
694*4882a593Smuzhiyun vtotal_reg = VTOTAL(pipe);
695*4882a593Smuzhiyun vblank_reg = VBLANK(pipe);
696*4882a593Smuzhiyun vsync_reg = VSYNC(pipe);
697*4882a593Smuzhiyun pipeconf_reg = PIPECONF(pipe);
698*4882a593Smuzhiyun pipe_dsl_reg = PIPEDSL(pipe);
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun save_bclrpat = intel_uncore_read(uncore, bclrpat_reg);
701*4882a593Smuzhiyun save_vtotal = intel_uncore_read(uncore, vtotal_reg);
702*4882a593Smuzhiyun vblank = intel_uncore_read(uncore, vblank_reg);
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun vtotal = ((save_vtotal >> 16) & 0xfff) + 1;
705*4882a593Smuzhiyun vactive = (save_vtotal & 0x7ff) + 1;
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun vblank_start = (vblank & 0xfff) + 1;
708*4882a593Smuzhiyun vblank_end = ((vblank >> 16) & 0xfff) + 1;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun /* Set the border color to purple. */
711*4882a593Smuzhiyun intel_uncore_write(uncore, bclrpat_reg, 0x500050);
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun if (!IS_GEN(dev_priv, 2)) {
714*4882a593Smuzhiyun u32 pipeconf = intel_uncore_read(uncore, pipeconf_reg);
715*4882a593Smuzhiyun intel_uncore_write(uncore,
716*4882a593Smuzhiyun pipeconf_reg,
717*4882a593Smuzhiyun pipeconf | PIPECONF_FORCE_BORDER);
718*4882a593Smuzhiyun intel_uncore_posting_read(uncore, pipeconf_reg);
719*4882a593Smuzhiyun /* Wait for next Vblank to substitue
720*4882a593Smuzhiyun * border color for Color info */
721*4882a593Smuzhiyun intel_wait_for_vblank(dev_priv, pipe);
722*4882a593Smuzhiyun st00 = intel_uncore_read8(uncore, _VGA_MSR_WRITE);
723*4882a593Smuzhiyun status = ((st00 & (1 << 4)) != 0) ?
724*4882a593Smuzhiyun connector_status_connected :
725*4882a593Smuzhiyun connector_status_disconnected;
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun intel_uncore_write(uncore, pipeconf_reg, pipeconf);
728*4882a593Smuzhiyun } else {
729*4882a593Smuzhiyun bool restore_vblank = false;
730*4882a593Smuzhiyun int count, detect;
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun /*
733*4882a593Smuzhiyun * If there isn't any border, add some.
734*4882a593Smuzhiyun * Yes, this will flicker
735*4882a593Smuzhiyun */
736*4882a593Smuzhiyun if (vblank_start <= vactive && vblank_end >= vtotal) {
737*4882a593Smuzhiyun u32 vsync = intel_de_read(dev_priv, vsync_reg);
738*4882a593Smuzhiyun u32 vsync_start = (vsync & 0xffff) + 1;
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun vblank_start = vsync_start;
741*4882a593Smuzhiyun intel_uncore_write(uncore,
742*4882a593Smuzhiyun vblank_reg,
743*4882a593Smuzhiyun (vblank_start - 1) |
744*4882a593Smuzhiyun ((vblank_end - 1) << 16));
745*4882a593Smuzhiyun restore_vblank = true;
746*4882a593Smuzhiyun }
747*4882a593Smuzhiyun /* sample in the vertical border, selecting the larger one */
748*4882a593Smuzhiyun if (vblank_start - vactive >= vtotal - vblank_end)
749*4882a593Smuzhiyun vsample = (vblank_start + vactive) >> 1;
750*4882a593Smuzhiyun else
751*4882a593Smuzhiyun vsample = (vtotal + vblank_end) >> 1;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /*
754*4882a593Smuzhiyun * Wait for the border to be displayed
755*4882a593Smuzhiyun */
756*4882a593Smuzhiyun while (intel_uncore_read(uncore, pipe_dsl_reg) >= vactive)
757*4882a593Smuzhiyun ;
758*4882a593Smuzhiyun while ((dsl = intel_uncore_read(uncore, pipe_dsl_reg)) <=
759*4882a593Smuzhiyun vsample)
760*4882a593Smuzhiyun ;
761*4882a593Smuzhiyun /*
762*4882a593Smuzhiyun * Watch ST00 for an entire scanline
763*4882a593Smuzhiyun */
764*4882a593Smuzhiyun detect = 0;
765*4882a593Smuzhiyun count = 0;
766*4882a593Smuzhiyun do {
767*4882a593Smuzhiyun count++;
768*4882a593Smuzhiyun /* Read the ST00 VGA status register */
769*4882a593Smuzhiyun st00 = intel_uncore_read8(uncore, _VGA_MSR_WRITE);
770*4882a593Smuzhiyun if (st00 & (1 << 4))
771*4882a593Smuzhiyun detect++;
772*4882a593Smuzhiyun } while ((intel_uncore_read(uncore, pipe_dsl_reg) == dsl));
773*4882a593Smuzhiyun
774*4882a593Smuzhiyun /* restore vblank if necessary */
775*4882a593Smuzhiyun if (restore_vblank)
776*4882a593Smuzhiyun intel_uncore_write(uncore, vblank_reg, vblank);
777*4882a593Smuzhiyun /*
778*4882a593Smuzhiyun * If more than 3/4 of the scanline detected a monitor,
779*4882a593Smuzhiyun * then it is assumed to be present. This works even on i830,
780*4882a593Smuzhiyun * where there isn't any way to force the border color across
781*4882a593Smuzhiyun * the screen
782*4882a593Smuzhiyun */
783*4882a593Smuzhiyun status = detect * 4 > count * 3 ?
784*4882a593Smuzhiyun connector_status_connected :
785*4882a593Smuzhiyun connector_status_disconnected;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun /* Restore previous settings */
789*4882a593Smuzhiyun intel_uncore_write(uncore, bclrpat_reg, save_bclrpat);
790*4882a593Smuzhiyun
791*4882a593Smuzhiyun return status;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun
intel_spurious_crt_detect_dmi_callback(const struct dmi_system_id * id)794*4882a593Smuzhiyun static int intel_spurious_crt_detect_dmi_callback(const struct dmi_system_id *id)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun DRM_DEBUG_DRIVER("Skipping CRT detection for %s\n", id->ident);
797*4882a593Smuzhiyun return 1;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun static const struct dmi_system_id intel_spurious_crt_detect[] = {
801*4882a593Smuzhiyun {
802*4882a593Smuzhiyun .callback = intel_spurious_crt_detect_dmi_callback,
803*4882a593Smuzhiyun .ident = "ACER ZGB",
804*4882a593Smuzhiyun .matches = {
805*4882a593Smuzhiyun DMI_MATCH(DMI_SYS_VENDOR, "ACER"),
806*4882a593Smuzhiyun DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
807*4882a593Smuzhiyun },
808*4882a593Smuzhiyun },
809*4882a593Smuzhiyun {
810*4882a593Smuzhiyun .callback = intel_spurious_crt_detect_dmi_callback,
811*4882a593Smuzhiyun .ident = "Intel DZ77BH-55K",
812*4882a593Smuzhiyun .matches = {
813*4882a593Smuzhiyun DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
814*4882a593Smuzhiyun DMI_MATCH(DMI_BOARD_NAME, "DZ77BH-55K"),
815*4882a593Smuzhiyun },
816*4882a593Smuzhiyun },
817*4882a593Smuzhiyun { }
818*4882a593Smuzhiyun };
819*4882a593Smuzhiyun
820*4882a593Smuzhiyun static int
intel_crt_detect(struct drm_connector * connector,struct drm_modeset_acquire_ctx * ctx,bool force)821*4882a593Smuzhiyun intel_crt_detect(struct drm_connector *connector,
822*4882a593Smuzhiyun struct drm_modeset_acquire_ctx *ctx,
823*4882a593Smuzhiyun bool force)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(connector->dev);
826*4882a593Smuzhiyun struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector));
827*4882a593Smuzhiyun struct intel_encoder *intel_encoder = &crt->base;
828*4882a593Smuzhiyun intel_wakeref_t wakeref;
829*4882a593Smuzhiyun int status, ret;
830*4882a593Smuzhiyun struct intel_load_detect_pipe tmp;
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s] force=%d\n",
833*4882a593Smuzhiyun connector->base.id, connector->name,
834*4882a593Smuzhiyun force);
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun if (!INTEL_DISPLAY_ENABLED(dev_priv))
837*4882a593Smuzhiyun return connector_status_disconnected;
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun if (dev_priv->params.load_detect_test) {
840*4882a593Smuzhiyun wakeref = intel_display_power_get(dev_priv,
841*4882a593Smuzhiyun intel_encoder->power_domain);
842*4882a593Smuzhiyun goto load_detect;
843*4882a593Smuzhiyun }
844*4882a593Smuzhiyun
845*4882a593Smuzhiyun /* Skip machines without VGA that falsely report hotplug events */
846*4882a593Smuzhiyun if (dmi_check_system(intel_spurious_crt_detect))
847*4882a593Smuzhiyun return connector_status_disconnected;
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun wakeref = intel_display_power_get(dev_priv,
850*4882a593Smuzhiyun intel_encoder->power_domain);
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun if (I915_HAS_HOTPLUG(dev_priv)) {
853*4882a593Smuzhiyun /* We can not rely on the HPD pin always being correctly wired
854*4882a593Smuzhiyun * up, for example many KVM do not pass it through, and so
855*4882a593Smuzhiyun * only trust an assertion that the monitor is connected.
856*4882a593Smuzhiyun */
857*4882a593Smuzhiyun if (intel_crt_detect_hotplug(connector)) {
858*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
859*4882a593Smuzhiyun "CRT detected via hotplug\n");
860*4882a593Smuzhiyun status = connector_status_connected;
861*4882a593Smuzhiyun goto out;
862*4882a593Smuzhiyun } else
863*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
864*4882a593Smuzhiyun "CRT not detected via hotplug\n");
865*4882a593Smuzhiyun }
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun if (intel_crt_detect_ddc(connector)) {
868*4882a593Smuzhiyun status = connector_status_connected;
869*4882a593Smuzhiyun goto out;
870*4882a593Smuzhiyun }
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun /* Load detection is broken on HPD capable machines. Whoever wants a
873*4882a593Smuzhiyun * broken monitor (without edid) to work behind a broken kvm (that fails
874*4882a593Smuzhiyun * to have the right resistors for HP detection) needs to fix this up.
875*4882a593Smuzhiyun * For now just bail out. */
876*4882a593Smuzhiyun if (I915_HAS_HOTPLUG(dev_priv)) {
877*4882a593Smuzhiyun status = connector_status_disconnected;
878*4882a593Smuzhiyun goto out;
879*4882a593Smuzhiyun }
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun load_detect:
882*4882a593Smuzhiyun if (!force) {
883*4882a593Smuzhiyun status = connector->status;
884*4882a593Smuzhiyun goto out;
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun /* for pre-945g platforms use load detect */
888*4882a593Smuzhiyun ret = intel_get_load_detect_pipe(connector, &tmp, ctx);
889*4882a593Smuzhiyun if (ret > 0) {
890*4882a593Smuzhiyun if (intel_crt_detect_ddc(connector))
891*4882a593Smuzhiyun status = connector_status_connected;
892*4882a593Smuzhiyun else if (INTEL_GEN(dev_priv) < 4)
893*4882a593Smuzhiyun status = intel_crt_load_detect(crt,
894*4882a593Smuzhiyun to_intel_crtc(connector->state->crtc)->pipe);
895*4882a593Smuzhiyun else if (dev_priv->params.load_detect_test)
896*4882a593Smuzhiyun status = connector_status_disconnected;
897*4882a593Smuzhiyun else
898*4882a593Smuzhiyun status = connector_status_unknown;
899*4882a593Smuzhiyun intel_release_load_detect_pipe(connector, &tmp, ctx);
900*4882a593Smuzhiyun } else if (ret == 0) {
901*4882a593Smuzhiyun status = connector_status_unknown;
902*4882a593Smuzhiyun } else {
903*4882a593Smuzhiyun status = ret;
904*4882a593Smuzhiyun }
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun out:
907*4882a593Smuzhiyun intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref);
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun /*
910*4882a593Smuzhiyun * Make sure the refs for power wells enabled during detect are
911*4882a593Smuzhiyun * dropped to avoid a new detect cycle triggered by HPD polling.
912*4882a593Smuzhiyun */
913*4882a593Smuzhiyun intel_display_power_flush_work(dev_priv);
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun return status;
916*4882a593Smuzhiyun }
917*4882a593Smuzhiyun
intel_crt_get_modes(struct drm_connector * connector)918*4882a593Smuzhiyun static int intel_crt_get_modes(struct drm_connector *connector)
919*4882a593Smuzhiyun {
920*4882a593Smuzhiyun struct drm_device *dev = connector->dev;
921*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
922*4882a593Smuzhiyun struct intel_crt *crt = intel_attached_crt(to_intel_connector(connector));
923*4882a593Smuzhiyun struct intel_encoder *intel_encoder = &crt->base;
924*4882a593Smuzhiyun intel_wakeref_t wakeref;
925*4882a593Smuzhiyun struct i2c_adapter *i2c;
926*4882a593Smuzhiyun int ret;
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun wakeref = intel_display_power_get(dev_priv,
929*4882a593Smuzhiyun intel_encoder->power_domain);
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun i2c = intel_gmbus_get_adapter(dev_priv, dev_priv->vbt.crt_ddc_pin);
932*4882a593Smuzhiyun ret = intel_crt_ddc_get_modes(connector, i2c);
933*4882a593Smuzhiyun if (ret || !IS_G4X(dev_priv))
934*4882a593Smuzhiyun goto out;
935*4882a593Smuzhiyun
936*4882a593Smuzhiyun /* Try to probe digital port for output in DVI-I -> VGA mode. */
937*4882a593Smuzhiyun i2c = intel_gmbus_get_adapter(dev_priv, GMBUS_PIN_DPB);
938*4882a593Smuzhiyun ret = intel_crt_ddc_get_modes(connector, i2c);
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun out:
941*4882a593Smuzhiyun intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref);
942*4882a593Smuzhiyun
943*4882a593Smuzhiyun return ret;
944*4882a593Smuzhiyun }
945*4882a593Smuzhiyun
intel_crt_reset(struct drm_encoder * encoder)946*4882a593Smuzhiyun void intel_crt_reset(struct drm_encoder *encoder)
947*4882a593Smuzhiyun {
948*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(encoder->dev);
949*4882a593Smuzhiyun struct intel_crt *crt = intel_encoder_to_crt(to_intel_encoder(encoder));
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 5) {
952*4882a593Smuzhiyun u32 adpa;
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun adpa = intel_de_read(dev_priv, crt->adpa_reg);
955*4882a593Smuzhiyun adpa &= ~ADPA_CRT_HOTPLUG_MASK;
956*4882a593Smuzhiyun adpa |= ADPA_HOTPLUG_BITS;
957*4882a593Smuzhiyun intel_de_write(dev_priv, crt->adpa_reg, adpa);
958*4882a593Smuzhiyun intel_de_posting_read(dev_priv, crt->adpa_reg);
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "crt adpa set to 0x%x\n", adpa);
961*4882a593Smuzhiyun crt->force_hotplug_required = true;
962*4882a593Smuzhiyun }
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun }
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun /*
967*4882a593Smuzhiyun * Routines for controlling stuff on the analog port
968*4882a593Smuzhiyun */
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun static const struct drm_connector_funcs intel_crt_connector_funcs = {
971*4882a593Smuzhiyun .fill_modes = drm_helper_probe_single_connector_modes,
972*4882a593Smuzhiyun .late_register = intel_connector_register,
973*4882a593Smuzhiyun .early_unregister = intel_connector_unregister,
974*4882a593Smuzhiyun .destroy = intel_connector_destroy,
975*4882a593Smuzhiyun .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
976*4882a593Smuzhiyun .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
977*4882a593Smuzhiyun };
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = {
980*4882a593Smuzhiyun .detect_ctx = intel_crt_detect,
981*4882a593Smuzhiyun .mode_valid = intel_crt_mode_valid,
982*4882a593Smuzhiyun .get_modes = intel_crt_get_modes,
983*4882a593Smuzhiyun };
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun static const struct drm_encoder_funcs intel_crt_enc_funcs = {
986*4882a593Smuzhiyun .reset = intel_crt_reset,
987*4882a593Smuzhiyun .destroy = intel_encoder_destroy,
988*4882a593Smuzhiyun };
989*4882a593Smuzhiyun
intel_crt_init(struct drm_i915_private * dev_priv)990*4882a593Smuzhiyun void intel_crt_init(struct drm_i915_private *dev_priv)
991*4882a593Smuzhiyun {
992*4882a593Smuzhiyun struct drm_connector *connector;
993*4882a593Smuzhiyun struct intel_crt *crt;
994*4882a593Smuzhiyun struct intel_connector *intel_connector;
995*4882a593Smuzhiyun i915_reg_t adpa_reg;
996*4882a593Smuzhiyun u32 adpa;
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun if (HAS_PCH_SPLIT(dev_priv))
999*4882a593Smuzhiyun adpa_reg = PCH_ADPA;
1000*4882a593Smuzhiyun else if (IS_VALLEYVIEW(dev_priv))
1001*4882a593Smuzhiyun adpa_reg = VLV_ADPA;
1002*4882a593Smuzhiyun else
1003*4882a593Smuzhiyun adpa_reg = ADPA;
1004*4882a593Smuzhiyun
1005*4882a593Smuzhiyun adpa = intel_de_read(dev_priv, adpa_reg);
1006*4882a593Smuzhiyun if ((adpa & ADPA_DAC_ENABLE) == 0) {
1007*4882a593Smuzhiyun /*
1008*4882a593Smuzhiyun * On some machines (some IVB at least) CRT can be
1009*4882a593Smuzhiyun * fused off, but there's no known fuse bit to
1010*4882a593Smuzhiyun * indicate that. On these machine the ADPA register
1011*4882a593Smuzhiyun * works normally, except the DAC enable bit won't
1012*4882a593Smuzhiyun * take. So the only way to tell is attempt to enable
1013*4882a593Smuzhiyun * it and see what happens.
1014*4882a593Smuzhiyun */
1015*4882a593Smuzhiyun intel_de_write(dev_priv, adpa_reg,
1016*4882a593Smuzhiyun adpa | ADPA_DAC_ENABLE | ADPA_HSYNC_CNTL_DISABLE | ADPA_VSYNC_CNTL_DISABLE);
1017*4882a593Smuzhiyun if ((intel_de_read(dev_priv, adpa_reg) & ADPA_DAC_ENABLE) == 0)
1018*4882a593Smuzhiyun return;
1019*4882a593Smuzhiyun intel_de_write(dev_priv, adpa_reg, adpa);
1020*4882a593Smuzhiyun }
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL);
1023*4882a593Smuzhiyun if (!crt)
1024*4882a593Smuzhiyun return;
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun intel_connector = intel_connector_alloc();
1027*4882a593Smuzhiyun if (!intel_connector) {
1028*4882a593Smuzhiyun kfree(crt);
1029*4882a593Smuzhiyun return;
1030*4882a593Smuzhiyun }
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun connector = &intel_connector->base;
1033*4882a593Smuzhiyun crt->connector = intel_connector;
1034*4882a593Smuzhiyun drm_connector_init(&dev_priv->drm, &intel_connector->base,
1035*4882a593Smuzhiyun &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
1036*4882a593Smuzhiyun
1037*4882a593Smuzhiyun drm_encoder_init(&dev_priv->drm, &crt->base.base, &intel_crt_enc_funcs,
1038*4882a593Smuzhiyun DRM_MODE_ENCODER_DAC, "CRT");
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun intel_connector_attach_encoder(intel_connector, &crt->base);
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun crt->base.type = INTEL_OUTPUT_ANALOG;
1043*4882a593Smuzhiyun crt->base.cloneable = (1 << INTEL_OUTPUT_DVO) | (1 << INTEL_OUTPUT_HDMI);
1044*4882a593Smuzhiyun if (IS_I830(dev_priv))
1045*4882a593Smuzhiyun crt->base.pipe_mask = BIT(PIPE_A);
1046*4882a593Smuzhiyun else
1047*4882a593Smuzhiyun crt->base.pipe_mask = ~0;
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun if (IS_GEN(dev_priv, 2))
1050*4882a593Smuzhiyun connector->interlace_allowed = 0;
1051*4882a593Smuzhiyun else
1052*4882a593Smuzhiyun connector->interlace_allowed = 1;
1053*4882a593Smuzhiyun connector->doublescan_allowed = 0;
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun crt->adpa_reg = adpa_reg;
1056*4882a593Smuzhiyun
1057*4882a593Smuzhiyun crt->base.power_domain = POWER_DOMAIN_PORT_CRT;
1058*4882a593Smuzhiyun
1059*4882a593Smuzhiyun if (I915_HAS_HOTPLUG(dev_priv) &&
1060*4882a593Smuzhiyun !dmi_check_system(intel_spurious_crt_detect)) {
1061*4882a593Smuzhiyun crt->base.hpd_pin = HPD_CRT;
1062*4882a593Smuzhiyun crt->base.hotplug = intel_encoder_hotplug;
1063*4882a593Smuzhiyun intel_connector->polled = DRM_CONNECTOR_POLL_HPD;
1064*4882a593Smuzhiyun } else {
1065*4882a593Smuzhiyun intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
1066*4882a593Smuzhiyun }
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun if (HAS_DDI(dev_priv)) {
1069*4882a593Smuzhiyun crt->base.port = PORT_E;
1070*4882a593Smuzhiyun crt->base.get_config = hsw_crt_get_config;
1071*4882a593Smuzhiyun crt->base.get_hw_state = intel_ddi_get_hw_state;
1072*4882a593Smuzhiyun crt->base.compute_config = hsw_crt_compute_config;
1073*4882a593Smuzhiyun crt->base.pre_pll_enable = hsw_pre_pll_enable_crt;
1074*4882a593Smuzhiyun crt->base.pre_enable = hsw_pre_enable_crt;
1075*4882a593Smuzhiyun crt->base.enable = hsw_enable_crt;
1076*4882a593Smuzhiyun crt->base.disable = hsw_disable_crt;
1077*4882a593Smuzhiyun crt->base.post_disable = hsw_post_disable_crt;
1078*4882a593Smuzhiyun } else {
1079*4882a593Smuzhiyun if (HAS_PCH_SPLIT(dev_priv)) {
1080*4882a593Smuzhiyun crt->base.compute_config = pch_crt_compute_config;
1081*4882a593Smuzhiyun crt->base.disable = pch_disable_crt;
1082*4882a593Smuzhiyun crt->base.post_disable = pch_post_disable_crt;
1083*4882a593Smuzhiyun } else {
1084*4882a593Smuzhiyun crt->base.compute_config = intel_crt_compute_config;
1085*4882a593Smuzhiyun crt->base.disable = intel_disable_crt;
1086*4882a593Smuzhiyun }
1087*4882a593Smuzhiyun crt->base.port = PORT_NONE;
1088*4882a593Smuzhiyun crt->base.get_config = intel_crt_get_config;
1089*4882a593Smuzhiyun crt->base.get_hw_state = intel_crt_get_hw_state;
1090*4882a593Smuzhiyun crt->base.enable = intel_enable_crt;
1091*4882a593Smuzhiyun }
1092*4882a593Smuzhiyun intel_connector->get_hw_state = intel_connector_get_hw_state;
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun /*
1097*4882a593Smuzhiyun * TODO: find a proper way to discover whether we need to set the the
1098*4882a593Smuzhiyun * polarity and link reversal bits or not, instead of relying on the
1099*4882a593Smuzhiyun * BIOS.
1100*4882a593Smuzhiyun */
1101*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv)) {
1102*4882a593Smuzhiyun u32 fdi_config = FDI_RX_POLARITY_REVERSED_LPT |
1103*4882a593Smuzhiyun FDI_RX_LINK_REVERSAL_OVERRIDE;
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun dev_priv->fdi_rx_config = intel_de_read(dev_priv,
1106*4882a593Smuzhiyun FDI_RX_CTL(PIPE_A)) & fdi_config;
1107*4882a593Smuzhiyun }
1108*4882a593Smuzhiyun
1109*4882a593Smuzhiyun intel_crt_reset(&crt->base.base);
1110*4882a593Smuzhiyun }
1111