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
,
228 void intel_hdmi_init(struct drm_device
*dev
, int sdvox_reg
)
230 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
231 struct drm_connector
*connector
;
232 struct intel_output
*intel_output
;
233 struct intel_hdmi_priv
*hdmi_priv
;
235 intel_output
= kcalloc(sizeof(struct intel_output
) +
236 sizeof(struct intel_hdmi_priv
), 1, GFP_KERNEL
);
239 hdmi_priv
= (struct intel_hdmi_priv
*)(intel_output
+ 1);
241 connector
= &intel_output
->base
;
242 drm_connector_init(dev
, connector
, &intel_hdmi_connector_funcs
,
243 DRM_MODE_CONNECTOR_HDMIA
);
244 drm_connector_helper_add(connector
, &intel_hdmi_connector_helper_funcs
);
246 intel_output
->type
= INTEL_OUTPUT_HDMI
;
248 connector
->interlace_allowed
= 0;
249 connector
->doublescan_allowed
= 0;
250 intel_output
->crtc_mask
= (1 << 0) | (1 << 1);
252 /* Set up the DDC bus. */
253 if (sdvox_reg
== SDVOB
) {
254 intel_output
->clone_mask
= (1 << INTEL_HDMIB_CLONE_BIT
);
255 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOE
, "HDMIB");
256 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
257 } else if (sdvox_reg
== SDVOC
) {
258 intel_output
->clone_mask
= (1 << INTEL_HDMIC_CLONE_BIT
);
259 intel_output
->ddc_bus
= intel_i2c_create(dev
, GPIOD
, "HDMIC");
260 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
261 } else if (sdvox_reg
== HDMIB
) {
262 intel_output
->clone_mask
= (1 << INTEL_HDMID_CLONE_BIT
);
263 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOE
,
265 dev_priv
->hotplug_supported_mask
|= HDMIB_HOTPLUG_INT_STATUS
;
266 } else if (sdvox_reg
== HDMIC
) {
267 intel_output
->clone_mask
= (1 << INTEL_HDMIE_CLONE_BIT
);
268 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOD
,
270 dev_priv
->hotplug_supported_mask
|= HDMIC_HOTPLUG_INT_STATUS
;
271 } else if (sdvox_reg
== HDMID
) {
272 intel_output
->clone_mask
= (1 << INTEL_HDMIF_CLONE_BIT
);
273 intel_output
->ddc_bus
= intel_i2c_create(dev
, PCH_GPIOF
,
275 dev_priv
->hotplug_supported_mask
|= HDMID_HOTPLUG_INT_STATUS
;
277 if (!intel_output
->ddc_bus
)
280 hdmi_priv
->sdvox_reg
= sdvox_reg
;
281 intel_output
->dev_priv
= hdmi_priv
;
283 drm_encoder_init(dev
, &intel_output
->enc
, &intel_hdmi_enc_funcs
,
284 DRM_MODE_ENCODER_TMDS
);
285 drm_encoder_helper_add(&intel_output
->enc
, &intel_hdmi_helper_funcs
);
287 drm_mode_connector_attach_encoder(&intel_output
->base
,
289 drm_sysfs_connector_add(connector
);
291 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
292 * 0xd. Failure to do so will result in spurious interrupts being
293 * generated on the port when a cable is not attached.
295 if (IS_G4X(dev
) && !IS_GM45(dev
)) {
296 u32 temp
= I915_READ(PEG_BAND_GAP_DATA
);
297 I915_WRITE(PEG_BAND_GAP_DATA
, (temp
& ~0xf) | 0xd);
303 drm_connector_cleanup(connector
);