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/slab.h>
31 #include <linux/delay.h>
36 #include "intel_drv.h"
40 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_encoder
*intel_encoder
= enc_to_intel_encoder(encoder
);
54 struct intel_hdmi_priv
*hdmi_priv
= intel_encoder
->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) {
67 sdvox
|= PORT_TRANS_B_SEL_CPT
;
69 sdvox
|= SDVO_PIPE_B_SELECT
;
72 I915_WRITE(hdmi_priv
->sdvox_reg
, sdvox
);
73 POSTING_READ(hdmi_priv
->sdvox_reg
);
76 static void intel_hdmi_dpms(struct drm_encoder
*encoder
, int mode
)
78 struct drm_device
*dev
= encoder
->dev
;
79 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
80 struct intel_encoder
*intel_encoder
= enc_to_intel_encoder(encoder
);
81 struct intel_hdmi_priv
*hdmi_priv
= intel_encoder
->dev_priv
;
84 temp
= I915_READ(hdmi_priv
->sdvox_reg
);
86 /* HW workaround, need to toggle enable bit off and on for 12bpc, but
87 * we do this anyway which shows more stable in testing.
89 if (HAS_PCH_SPLIT(dev
)) {
90 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
& ~SDVO_ENABLE
);
91 POSTING_READ(hdmi_priv
->sdvox_reg
);
94 if (mode
!= DRM_MODE_DPMS_ON
) {
100 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
);
101 POSTING_READ(hdmi_priv
->sdvox_reg
);
103 /* HW workaround, need to write this twice for issue that may result
104 * in first write getting masked.
106 if (HAS_PCH_SPLIT(dev
)) {
107 I915_WRITE(hdmi_priv
->sdvox_reg
, temp
);
108 POSTING_READ(hdmi_priv
->sdvox_reg
);
112 static int intel_hdmi_mode_valid(struct drm_connector
*connector
,
113 struct drm_display_mode
*mode
)
115 if (mode
->clock
> 165000)
116 return MODE_CLOCK_HIGH
;
117 if (mode
->clock
< 20000)
118 return MODE_CLOCK_HIGH
;
120 if (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
121 return MODE_NO_DBLESCAN
;
126 static bool intel_hdmi_mode_fixup(struct drm_encoder
*encoder
,
127 struct drm_display_mode
*mode
,
128 struct drm_display_mode
*adjusted_mode
)
133 static enum drm_connector_status
134 intel_hdmi_detect(struct drm_connector
*connector
)
136 struct drm_encoder
*encoder
= intel_attached_encoder(connector
);
137 struct intel_encoder
*intel_encoder
= enc_to_intel_encoder(encoder
);
138 struct intel_hdmi_priv
*hdmi_priv
= intel_encoder
->dev_priv
;
139 struct edid
*edid
= NULL
;
140 enum drm_connector_status status
= connector_status_disconnected
;
142 hdmi_priv
->has_hdmi_sink
= false;
143 edid
= drm_get_edid(connector
,
144 intel_encoder
->ddc_bus
);
147 if (edid
->input
& DRM_EDID_INPUT_DIGITAL
) {
148 status
= connector_status_connected
;
149 hdmi_priv
->has_hdmi_sink
= drm_detect_hdmi_monitor(edid
);
151 connector
->display_info
.raw_edid
= NULL
;
158 static int intel_hdmi_get_modes(struct drm_connector
*connector
)
160 struct drm_encoder
*encoder
= intel_attached_encoder(connector
);
161 struct intel_encoder
*intel_encoder
= enc_to_intel_encoder(encoder
);
163 /* We should parse the EDID data and find out if it's an HDMI sink so
164 * we can send audio to it.
167 return intel_ddc_get_modes(connector
, intel_encoder
->ddc_bus
);
170 static void intel_hdmi_destroy(struct drm_connector
*connector
)
172 drm_sysfs_connector_remove(connector
);
173 drm_connector_cleanup(connector
);
177 static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs
= {
178 .dpms
= intel_hdmi_dpms
,
179 .mode_fixup
= intel_hdmi_mode_fixup
,
180 .prepare
= intel_encoder_prepare
,
181 .mode_set
= intel_hdmi_mode_set
,
182 .commit
= intel_encoder_commit
,
185 static const struct drm_connector_funcs intel_hdmi_connector_funcs
= {
186 .dpms
= drm_helper_connector_dpms
,
187 .detect
= intel_hdmi_detect
,
188 .fill_modes
= drm_helper_probe_single_connector_modes
,
189 .destroy
= intel_hdmi_destroy
,
192 static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs
= {
193 .get_modes
= intel_hdmi_get_modes
,
194 .mode_valid
= intel_hdmi_mode_valid
,
195 .best_encoder
= intel_attached_encoder
,
198 static void intel_hdmi_enc_destroy(struct drm_encoder
*encoder
)
200 struct intel_encoder
*intel_encoder
= enc_to_intel_encoder(encoder
);
202 if (intel_encoder
->i2c_bus
)
203 intel_i2c_destroy(intel_encoder
->i2c_bus
);
204 drm_encoder_cleanup(encoder
);
205 kfree(intel_encoder
);
208 static const struct drm_encoder_funcs intel_hdmi_enc_funcs
= {
209 .destroy
= intel_hdmi_enc_destroy
,
212 void intel_hdmi_init(struct drm_device
*dev
, int sdvox_reg
)
214 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
215 struct drm_connector
*connector
;
216 struct intel_encoder
*intel_encoder
;
217 struct intel_connector
*intel_connector
;
218 struct intel_hdmi_priv
*hdmi_priv
;
220 intel_encoder
= kcalloc(sizeof(struct intel_encoder
) +
221 sizeof(struct intel_hdmi_priv
), 1, GFP_KERNEL
);
225 intel_connector
= kzalloc(sizeof(struct intel_connector
), GFP_KERNEL
);
226 if (!intel_connector
) {
227 kfree(intel_encoder
);
231 hdmi_priv
= (struct intel_hdmi_priv
*)(intel_encoder
+ 1);
233 connector
= &intel_connector
->base
;
234 drm_connector_init(dev
, connector
, &intel_hdmi_connector_funcs
,
235 DRM_MODE_CONNECTOR_HDMIA
);
236 drm_connector_helper_add(connector
, &intel_hdmi_connector_helper_funcs
);
238 intel_encoder
->type
= INTEL_OUTPUT_HDMI
;
240 connector
->interlace_allowed
= 0;
241 connector
->doublescan_allowed
= 0;
242 intel_encoder
->crtc_mask
= (1 << 0) | (1 << 1);
244 /* Set up the DDC bus. */
245 if (sdvox_reg
== SDVOB
) {
246 intel_encoder
->clone_mask
= (1 << INTEL_HDMIB_CLONE_BIT
);
247 intel_encoder
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "HDMIB");
248 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
249 } else if (sdvox_reg
== SDVOC
) {
250 intel_encoder
->clone_mask
= (1 << INTEL_HDMIC_CLONE_BIT
);
251 intel_encoder
->ddc_bus
= intel_i2c_create(dev
, GPIOD
, "HDMIC");
252 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
253 } else if (sdvox_reg
== HDMIB
) {
254 intel_encoder
->clone_mask
= (1 << INTEL_HDMID_CLONE_BIT
);
255 intel_encoder
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOE
,
257 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
258 } else if (sdvox_reg
== HDMIC
) {
259 intel_encoder
->clone_mask
= (1 << INTEL_HDMIE_CLONE_BIT
);
260 intel_encoder
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOD
,
262 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
263 } else if (sdvox_reg
== HDMID
) {
264 intel_encoder
->clone_mask
= (1 << INTEL_HDMIF_CLONE_BIT
);
265 intel_encoder
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOF
,
267 dev_priv
->hotplug_supported_mask
|= HDMID_HOTPLUG_INT_STATUS
;
269 if (!intel_encoder
->ddc_bus
)
272 hdmi_priv
->sdvox_reg
= sdvox_reg
;
273 intel_encoder
->dev_priv
= hdmi_priv
;
275 drm_encoder_init(dev
, &intel_encoder
->enc
, &intel_hdmi_enc_funcs
,
276 DRM_MODE_ENCODER_TMDS
);
277 drm_encoder_helper_add(&intel_encoder
->enc
, &intel_hdmi_helper_funcs
);
279 drm_mode_connector_attach_encoder(&intel_connector
->base
,
280 &intel_encoder
->enc
);
281 drm_sysfs_connector_add(connector
);
283 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
284 * 0xd. Failure to do so will result in spurious interrupts being
285 * generated on the port when a cable is not attached.
287 if (IS_G4X(dev
) && !IS_GM45(dev
)) {
288 u32 temp
= I915_READ(PEG_BAND_GAP_DATA
);
289 I915_WRITE(PEG_BAND_GAP_DATA
, (temp
& ~0xf) | 0xd);
295 drm_connector_cleanup(connector
);
296 kfree(intel_encoder
);
297 kfree(intel_connector
);