2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Eric Anholt <eric@anholt.net>
26 * Jesse Barnes <jesse.barnes@intel.com>
29 #include <linux/i2c.h>
30 #include <linux/delay.h>
35 #include "intel_drv.h"
39 struct intel_hdmi_priv
{
45 static void intel_hdmi_mode_set(struct drm_encoder
*encoder
,
46 struct drm_display_mode
*mode
,
47 struct drm_display_mode
*adjusted_mode
)
49 struct drm_device
*dev
= encoder
->dev
;
50 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
51 struct drm_crtc
*crtc
= encoder
->crtc
;
52 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
53 struct intel_output
*intel_output
= enc_to_intel_output(encoder
);
54 struct intel_hdmi_priv
*hdmi_priv
= intel_output
->dev_priv
;
57 sdvox
= SDVO_ENCODING_HDMI
|
59 SDVO_VSYNC_ACTIVE_HIGH
|
60 SDVO_HSYNC_ACTIVE_HIGH
;
62 if (hdmi_priv
->has_hdmi_sink
)
63 sdvox
|= SDVO_AUDIO_ENABLE
;
65 if (intel_crtc
->pipe
== 1)
66 sdvox
|= SDVO_PIPE_B_SELECT
;
68 I915_WRITE(hdmi_priv
->sdvox_reg
, sdvox
);
69 POSTING_READ(hdmi_priv
->sdvox_reg
);
72 static void intel_hdmi_dpms(struct drm_encoder
*encoder
, int mode
)
74 struct drm_device
*dev
= encoder
->dev
;
75 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
76 struct intel_output
*intel_output
= enc_to_intel_output(encoder
);
77 struct intel_hdmi_priv
*hdmi_priv
= intel_output
->dev_priv
;
80 temp
= I915_READ(hdmi_priv
->sdvox_reg
);
82 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
83 * we do this anyway which shows more stable in testing.
85 if (IS_IRONLAKE(dev
)) {
86 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
& ~SDVO_ENABLE
);
87 POSTING_READ(hdmi_priv
->sdvox_reg
);
90 if (mode
!= DRM_MODE_DPMS_ON
) {
96 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
);
97 POSTING_READ(hdmi_priv
->sdvox_reg
);
99 /* HW workaround, need to write this twice for issue that may result
100 * in first write getting masked.
102 if (IS_IRONLAKE(dev
)) {
103 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
);
104 POSTING_READ(hdmi_priv
->sdvox_reg
);
108 static void intel_hdmi_save(struct drm_connector
*connector
)
110 struct drm_device
*dev
= connector
->dev
;
111 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
112 struct intel_output
*intel_output
= to_intel_output(connector
);
113 struct intel_hdmi_priv
*hdmi_priv
= intel_output
->dev_priv
;
115 hdmi_priv
->save_SDVOX
= I915_READ(hdmi_priv
->sdvox_reg
);
118 static void intel_hdmi_restore(struct drm_connector
*connector
)
120 struct drm_device
*dev
= connector
->dev
;
121 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
122 struct intel_output
*intel_output
= to_intel_output(connector
);
123 struct intel_hdmi_priv
*hdmi_priv
= intel_output
->dev_priv
;
125 I915_WRITE(hdmi_priv
->sdvox_reg
, hdmi_priv
->save_SDVOX
);
126 POSTING_READ(hdmi_priv
->sdvox_reg
);
129 static int intel_hdmi_mode_valid(struct drm_connector
*connector
,
130 struct drm_display_mode
*mode
)
132 if (mode
->clock
> 165000)
133 return MODE_CLOCK_HIGH
;
134 if (mode
->clock
< 20000)
135 return MODE_CLOCK_HIGH
;
137 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
138 return MODE_NO_DBLESCAN
;
143 static bool intel_hdmi_mode_fixup(struct drm_encoder
*encoder
,
144 struct drm_display_mode
*mode
,
145 struct drm_display_mode
*adjusted_mode
)
150 static enum drm_connector_status
151 intel_hdmi_detect(struct drm_connector
*connector
)
153 struct intel_output
*intel_output
= to_intel_output(connector
);
154 struct intel_hdmi_priv
*hdmi_priv
= intel_output
->dev_priv
;
155 struct edid
*edid
= NULL
;
156 enum drm_connector_status status
= connector_status_disconnected
;
158 hdmi_priv
->has_hdmi_sink
= false;
159 edid
= drm_get_edid(&intel_output
->base
,
160 intel_output
->ddc_bus
);
163 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
) {
164 status
= connector_status_connected
;
165 hdmi_priv
->has_hdmi_sink
= drm_detect_hdmi_monitor(edid
);
167 intel_output
->base
.display_info
.raw_edid
= NULL
;
174 static int intel_hdmi_get_modes(struct drm_connector
*connector
)
176 struct intel_output
*intel_output
= to_intel_output(connector
);
178 /* We should parse the EDID data and find out if it's an HDMI sink so
179 * we can send audio to it.
182 return intel_ddc_get_modes(intel_output
);
185 static void intel_hdmi_destroy(struct drm_connector
*connector
)
187 struct intel_output
*intel_output
= to_intel_output(connector
);
189 if (intel_output
->i2c_bus
)
190 intel_i2c_destroy(intel_output
->i2c_bus
);
191 drm_sysfs_connector_remove(connector
);
192 drm_connector_cleanup(connector
);
196 static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs
= {
197 .dpms
= intel_hdmi_dpms
,
198 .mode_fixup
= intel_hdmi_mode_fixup
,
199 .prepare
= intel_encoder_prepare
,
200 .mode_set
= intel_hdmi_mode_set
,
201 .commit
= intel_encoder_commit
,
204 static const struct drm_connector_funcs intel_hdmi_connector_funcs
= {
205 .dpms
= drm_helper_connector_dpms
,
206 .save
= intel_hdmi_save
,
207 .restore
= intel_hdmi_restore
,
208 .detect
= intel_hdmi_detect
,
209 .fill_modes
= drm_helper_probe_single_connector_modes
,
210 .destroy
= intel_hdmi_destroy
,
213 static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs
= {
214 .get_modes
= intel_hdmi_get_modes
,
215 .mode_valid
= intel_hdmi_mode_valid
,
216 .best_encoder
= intel_best_encoder
,
219 static void intel_hdmi_enc_destroy(struct drm_encoder
*encoder
)
221 drm_encoder_cleanup(encoder
);
224 static const struct drm_encoder_funcs intel_hdmi_enc_funcs
= {
225 .destroy
= intel_hdmi_enc_destroy
,
229 * Enumerate the child dev array parsed from VBT to check whether
230 * the given HDMI is present.
231 * If it is present, return 1.
232 * If it is not present, return false.
233 * If no child dev is parsed from VBT, it assumes that the given
236 static int hdmi_is_present_in_vbt(struct drm_device
*dev
, int hdmi_reg
)
238 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
239 struct child_device_config
*p_child
;
240 int i
, hdmi_port
, ret
;
242 if (!dev_priv
->child_dev_num
)
245 if (hdmi_reg
== SDVOB
)
247 else if (hdmi_reg
== SDVOC
)
249 else if (hdmi_reg
== HDMIB
)
251 else if (hdmi_reg
== HDMIC
)
253 else if (hdmi_reg
== HDMID
)
259 for (i
= 0; i
< dev_priv
->child_dev_num
; i
++) {
260 p_child
= dev_priv
->child_dev
+ i
;
262 * If the device type is not HDMI, continue.
264 if (p_child
->device_type
!= DEVICE_TYPE_HDMI
)
266 /* Find the HDMI port */
267 if (p_child
->dvo_port
== hdmi_port
) {
274 void intel_hdmi_init(struct drm_device
*dev
, int sdvox_reg
)
276 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
277 struct drm_connector
*connector
;
278 struct intel_output
*intel_output
;
279 struct intel_hdmi_priv
*hdmi_priv
;
281 if (!hdmi_is_present_in_vbt(dev
, sdvox_reg
)) {
282 DRM_DEBUG_KMS("HDMI is not present. Ignored it \n");
285 intel_output
= kcalloc(sizeof(struct intel_output
) +
286 sizeof(struct intel_hdmi_priv
), 1, GFP_KERNEL
);
289 hdmi_priv
= (struct intel_hdmi_priv
*)(intel_output
+ 1);
291 connector
= &intel_output
->base
;
292 drm_connector_init(dev
, connector
, &intel_hdmi_connector_funcs
,
293 DRM_MODE_CONNECTOR_HDMIA
);
294 drm_connector_helper_add(connector
, &intel_hdmi_connector_helper_funcs
);
296 intel_output
->type
= INTEL_OUTPUT_HDMI
;
298 connector
->interlace_allowed
= 0;
299 connector
->doublescan_allowed
= 0;
300 intel_output
->crtc_mask
= (1 << 0) | (1 << 1);
302 /* Set up the DDC bus. */
303 if (sdvox_reg
== SDVOB
) {
304 intel_output
->clone_mask
= (1 << INTEL_HDMIB_CLONE_BIT
);
305 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "HDMIB");
306 } else if (sdvox_reg
== SDVOC
) {
307 intel_output
->clone_mask
= (1 << INTEL_HDMIC_CLONE_BIT
);
308 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOD
, "HDMIC");
309 } else if (sdvox_reg
== HDMIB
) {
310 intel_output
->clone_mask
= (1 << INTEL_HDMID_CLONE_BIT
);
311 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOE
,
313 } else if (sdvox_reg
== HDMIC
) {
314 intel_output
->clone_mask
= (1 << INTEL_HDMIE_CLONE_BIT
);
315 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOD
,
317 } else if (sdvox_reg
== HDMID
) {
318 intel_output
->clone_mask
= (1 << INTEL_HDMIF_CLONE_BIT
);
319 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOF
,
322 if (!intel_output
->ddc_bus
)
325 hdmi_priv
->sdvox_reg
= sdvox_reg
;
326 intel_output
->dev_priv
= hdmi_priv
;
328 drm_encoder_init(dev
, &intel_output
->enc
, &intel_hdmi_enc_funcs
,
329 DRM_MODE_ENCODER_TMDS
);
330 drm_encoder_helper_add(&intel_output
->enc
, &intel_hdmi_helper_funcs
);
332 drm_mode_connector_attach_encoder(&intel_output
->base
,
334 drm_sysfs_connector_add(connector
);
336 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
337 * 0xd. Failure to do so will result in spurious interrupts being
338 * generated on the port when a cable is not attached.
340 if (IS_G4X(dev
) && !IS_GM45(dev
)) {
341 u32 temp
= I915_READ(PEG_BAND_GAP_DATA
);
342 I915_WRITE(PEG_BAND_GAP_DATA
, (temp
& ~0xf) | 0xd);
348 drm_connector_cleanup(connector
);