blob: ea9cf4c689f6aff124972275682165e17537739a [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright 2006 Dave Airlie <airlied@linux.ie>
3 * Copyright © 2006-2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Eric Anholt <eric@anholt.net>
27 */
28#include <linux/i2c.h>
29#include <linux/delay.h>
30#include "drmP.h"
31#include "drm.h"
32#include "drm_crtc.h"
33#include "intel_drv.h"
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +080034#include "drm_edid.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "i915_drm.h"
36#include "i915_drv.h"
37#include "intel_sdvo_regs.h"
38
Zhenyu Wang14571b42010-03-30 14:06:33 +080039#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
40#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
41#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
42#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0)
43
44#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
45 SDVO_TV_MASK)
46
47#define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
48#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
49
50
Zhao Yakuice6feab2009-08-24 13:50:26 +080051static char *tv_format_names[] = {
52 "NTSC_M" , "NTSC_J" , "NTSC_443",
53 "PAL_B" , "PAL_D" , "PAL_G" ,
54 "PAL_H" , "PAL_I" , "PAL_M" ,
55 "PAL_N" , "PAL_NC" , "PAL_60" ,
56 "SECAM_B" , "SECAM_D" , "SECAM_G" ,
57 "SECAM_K" , "SECAM_K1", "SECAM_L" ,
58 "SECAM_60"
59};
60
61#define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
62
Jesse Barnes79e53942008-11-07 14:24:08 -080063struct intel_sdvo_priv {
Keith Packardf9c10a92009-05-30 12:16:25 -070064 u8 slave_addr;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080065
66 /* Register for the SDVO device: SDVOB or SDVOC */
Eric Anholtc751ce42010-03-25 11:48:48 -070067 int sdvo_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -080068
Jesse Barnese2f0ba92009-02-02 15:11:52 -080069 /* Active outputs controlled by this SDVO output */
70 uint16_t controlled_output;
Jesse Barnes79e53942008-11-07 14:24:08 -080071
Jesse Barnese2f0ba92009-02-02 15:11:52 -080072 /*
73 * Capabilities of the SDVO device returned by
74 * i830_sdvo_get_capabilities()
75 */
Jesse Barnes79e53942008-11-07 14:24:08 -080076 struct intel_sdvo_caps caps;
Jesse Barnese2f0ba92009-02-02 15:11:52 -080077
78 /* Pixel clock limitations reported by the SDVO device, in kHz */
Jesse Barnes79e53942008-11-07 14:24:08 -080079 int pixel_clock_min, pixel_clock_max;
80
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +080081 /*
82 * For multiple function SDVO device,
83 * this is for current attached outputs.
84 */
85 uint16_t attached_output;
86
Jesse Barnese2f0ba92009-02-02 15:11:52 -080087 /**
88 * This is set if we're going to treat the device as TV-out.
89 *
90 * While we have these nice friendly flags for output types that ought
91 * to decide this for us, the S-Video output on our HDMI+S-Video card
92 * shows up as RGB1 (VGA).
93 */
94 bool is_tv;
95
Zhao Yakuice6feab2009-08-24 13:50:26 +080096 /* This is for current tv format name */
97 char *tv_format_name;
98
Jesse Barnese2f0ba92009-02-02 15:11:52 -080099 /**
100 * This is set if we treat the device as HDMI, instead of DVI.
101 */
102 bool is_hdmi;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800103
Ma Ling7086c872009-05-13 11:20:06 +0800104 /**
105 * This is set if we detect output of sdvo device as LVDS.
106 */
107 bool is_lvds;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800108
109 /**
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800110 * This is sdvo flags for input timing.
111 */
112 uint8_t sdvo_flags;
113
114 /**
115 * This is sdvo fixed pannel mode pointer
116 */
117 struct drm_display_mode *sdvo_lvds_fixed_mode;
118
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800119 /*
120 * supported encoding mode, used to determine whether HDMI is
121 * supported
122 */
123 struct intel_sdvo_encode encode;
124
Eric Anholtc751ce42010-03-25 11:48:48 -0700125 /* DDC bus used by this SDVO encoder */
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800126 uint8_t ddc_bus;
127
Keith Packard57cdaf92009-09-04 13:07:54 +0800128 /* Mac mini hack -- use the same DDC as the analog connector */
129 struct i2c_adapter *analog_ddc_bus;
130
Zhenyu Wang14571b42010-03-30 14:06:33 +0800131};
132
133struct intel_sdvo_connector {
134 /* Mark the type of connector */
135 uint16_t output_flag;
136
137 /* This contains all current supported TV format */
138 char *tv_format_supported[TV_FORMAT_NUM];
139 int format_supported_num;
140 struct drm_property *tv_format_property;
141 struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
142
143 /**
144 * Returned SDTV resolutions allowed for the current format, if the
145 * device reported it.
146 */
147 struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
148
Zhao Yakuib9219c52009-09-10 15:45:46 +0800149 /* add the property for the SDVO-TV */
150 struct drm_property *left_property;
151 struct drm_property *right_property;
152 struct drm_property *top_property;
153 struct drm_property *bottom_property;
154 struct drm_property *hpos_property;
155 struct drm_property *vpos_property;
156
157 /* add the property for the SDVO-TV/LVDS */
158 struct drm_property *brightness_property;
159 struct drm_property *contrast_property;
160 struct drm_property *saturation_property;
161 struct drm_property *hue_property;
162
163 /* Add variable to record current setting for the above property */
164 u32 left_margin, right_margin, top_margin, bottom_margin;
165 /* this is to get the range of margin.*/
166 u32 max_hscan, max_vscan;
167 u32 max_hpos, cur_hpos;
168 u32 max_vpos, cur_vpos;
169 u32 cur_brightness, max_brightness;
170 u32 cur_contrast, max_contrast;
171 u32 cur_saturation, max_saturation;
172 u32 cur_hue, max_hue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800173};
174
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800175static bool
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800176intel_sdvo_output_setup(struct intel_encoder *intel_encoder,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800177 uint16_t flags);
Zhenyu Wang14571b42010-03-30 14:06:33 +0800178static void
179intel_sdvo_tv_create_property(struct drm_connector *connector, int type);
180static void
181intel_sdvo_create_enhance_property(struct drm_connector *connector);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +0800182
Jesse Barnes79e53942008-11-07 14:24:08 -0800183/**
184 * Writes the SDVOB or SDVOC with the given value, but always writes both
185 * SDVOB and SDVOC to work around apparent hardware issues (according to
186 * comments in the BIOS).
187 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700188static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800189{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +0800190 struct drm_device *dev = intel_encoder->enc.dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800191 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -0700192 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800193 u32 bval = val, cval = val;
194 int i;
195
Zhao Yakui461ed3c2010-03-30 15:11:33 +0800196 if (sdvo_priv->sdvo_reg == PCH_SDVOB) {
197 I915_WRITE(sdvo_priv->sdvo_reg, val);
198 I915_READ(sdvo_priv->sdvo_reg);
199 return;
200 }
201
Eric Anholtc751ce42010-03-25 11:48:48 -0700202 if (sdvo_priv->sdvo_reg == SDVOB) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800203 cval = I915_READ(SDVOC);
204 } else {
205 bval = I915_READ(SDVOB);
206 }
207 /*
208 * Write the registers twice for luck. Sometimes,
209 * writing them only once doesn't appear to 'stick'.
210 * The BIOS does this too. Yay, magic
211 */
212 for (i = 0; i < 2; i++)
213 {
214 I915_WRITE(SDVOB, bval);
215 I915_READ(SDVOB);
216 I915_WRITE(SDVOC, cval);
217 I915_READ(SDVOC);
218 }
219}
220
Eric Anholt21d40d32010-03-25 11:11:14 -0700221static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800222 u8 *ch)
223{
Eric Anholt21d40d32010-03-25 11:11:14 -0700224 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800225 u8 out_buf[2];
226 u8 buf[2];
227 int ret;
228
229 struct i2c_msg msgs[] = {
230 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700231 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800232 .flags = 0,
233 .len = 1,
234 .buf = out_buf,
235 },
236 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700237 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800238 .flags = I2C_M_RD,
239 .len = 1,
240 .buf = buf,
241 }
242 };
243
244 out_buf[0] = addr;
245 out_buf[1] = 0;
246
Eric Anholt21d40d32010-03-25 11:11:14 -0700247 if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800248 {
249 *ch = buf[0];
250 return true;
251 }
252
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800253 DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
Jesse Barnes79e53942008-11-07 14:24:08 -0800254 return false;
255}
256
Eric Anholt21d40d32010-03-25 11:11:14 -0700257static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr,
Jesse Barnes79e53942008-11-07 14:24:08 -0800258 u8 ch)
259{
Eric Anholt21d40d32010-03-25 11:11:14 -0700260 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800261 u8 out_buf[2];
262 struct i2c_msg msgs[] = {
263 {
Keith Packardf9c10a92009-05-30 12:16:25 -0700264 .addr = sdvo_priv->slave_addr >> 1,
Jesse Barnes79e53942008-11-07 14:24:08 -0800265 .flags = 0,
266 .len = 2,
267 .buf = out_buf,
268 }
269 };
270
271 out_buf[0] = addr;
272 out_buf[1] = ch;
273
Eric Anholt21d40d32010-03-25 11:11:14 -0700274 if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800275 {
276 return true;
277 }
278 return false;
279}
280
281#define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
282/** Mapping of command numbers to names, for debug output */
Tobias Klauser005568b2009-02-09 22:02:42 +0100283static const struct _sdvo_cmd_name {
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800284 u8 cmd;
285 char *name;
Jesse Barnes79e53942008-11-07 14:24:08 -0800286} sdvo_cmd_names[] = {
287 SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
288 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
289 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
290 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
291 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
292 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
293 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
294 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
295 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
296 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
297 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
298 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
299 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
300 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
301 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
302 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
303 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
304 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
305 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
306 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
307 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
308 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
309 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
310 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
311 SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
312 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
313 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
314 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
315 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
316 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
317 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
318 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
319 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
320 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
321 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800322 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
323 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
324 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
325 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
Jesse Barnes79e53942008-11-07 14:24:08 -0800326 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800327 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
328 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
329 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
Zhao Yakuib9219c52009-09-10 15:45:46 +0800330 /* Add the op code for SDVO enhancements */
331 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
332 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
333 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
334 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
335 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
336 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
337 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
338 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
339 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
340 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
341 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
342 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
343 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
344 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
345 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
346 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
347 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
348 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
349 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
350 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
351 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
352 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
353 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
354 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800355 /* HDMI op code */
356 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
357 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
358 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
359 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
360 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
361 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
362 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
363 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
364 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
365 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
366 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
367 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
368 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
369 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
370 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
371 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
372 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
373 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
374 SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
375 SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
Jesse Barnes79e53942008-11-07 14:24:08 -0800376};
377
Zhao Yakui461ed3c2010-03-30 15:11:33 +0800378#define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB)
379#define SDVO_NAME(dev_priv) (IS_SDVOB((dev_priv)->sdvo_reg) ? "SDVOB" : "SDVOC")
Eric Anholtc751ce42010-03-25 11:48:48 -0700380#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -0800381
Eric Anholt21d40d32010-03-25 11:11:14 -0700382static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800383 void *args, int args_len)
384{
Eric Anholt21d40d32010-03-25 11:11:14 -0700385 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -0800386 int i;
387
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800388 DRM_DEBUG_KMS("%s: W: %02X ",
yakui_zhao342dc382009-06-02 14:12:00 +0800389 SDVO_NAME(sdvo_priv), cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800390 for (i = 0; i < args_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800391 DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800392 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800393 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800394 for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
395 if (cmd == sdvo_cmd_names[i].cmd) {
yakui_zhao342dc382009-06-02 14:12:00 +0800396 DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
Jesse Barnes79e53942008-11-07 14:24:08 -0800397 break;
398 }
399 }
400 if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
yakui_zhao342dc382009-06-02 14:12:00 +0800401 DRM_LOG_KMS("(%02X)", cmd);
402 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800403}
Jesse Barnes79e53942008-11-07 14:24:08 -0800404
Eric Anholt21d40d32010-03-25 11:11:14 -0700405static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800406 void *args, int args_len)
407{
408 int i;
409
Eric Anholt21d40d32010-03-25 11:11:14 -0700410 intel_sdvo_debug_write(intel_encoder, cmd, args, args_len);
Jesse Barnes79e53942008-11-07 14:24:08 -0800411
412 for (i = 0; i < args_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700413 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i,
Jesse Barnes79e53942008-11-07 14:24:08 -0800414 ((u8*)args)[i]);
415 }
416
Eric Anholt21d40d32010-03-25 11:11:14 -0700417 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd);
Jesse Barnes79e53942008-11-07 14:24:08 -0800418}
419
Jesse Barnes79e53942008-11-07 14:24:08 -0800420static const char *cmd_status_names[] = {
421 "Power on",
422 "Success",
423 "Not supported",
424 "Invalid arg",
425 "Pending",
426 "Target not specified",
427 "Scaling not supported"
428};
429
Eric Anholt21d40d32010-03-25 11:11:14 -0700430static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800431 void *response, int response_len,
432 u8 status)
433{
Eric Anholt21d40d32010-03-25 11:11:14 -0700434 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang33b52962009-03-24 14:02:40 +0800435 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -0800436
Zhao Yakui8a4c47f2009-07-20 13:48:04 +0800437 DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -0800438 for (i = 0; i < response_len; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800439 DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800440 for (; i < 8; i++)
yakui_zhao342dc382009-06-02 14:12:00 +0800441 DRM_LOG_KMS(" ");
Jesse Barnes79e53942008-11-07 14:24:08 -0800442 if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
yakui_zhao342dc382009-06-02 14:12:00 +0800443 DRM_LOG_KMS("(%s)", cmd_status_names[status]);
Jesse Barnes79e53942008-11-07 14:24:08 -0800444 else
yakui_zhao342dc382009-06-02 14:12:00 +0800445 DRM_LOG_KMS("(??? %d)", status);
446 DRM_LOG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800447}
Jesse Barnes79e53942008-11-07 14:24:08 -0800448
Eric Anholt21d40d32010-03-25 11:11:14 -0700449static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800450 void *response, int response_len)
451{
452 int i;
453 u8 status;
454 u8 retry = 50;
455
456 while (retry--) {
457 /* Read the command response */
458 for (i = 0; i < response_len; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -0700459 intel_sdvo_read_byte(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800460 SDVO_I2C_RETURN_0 + i,
461 &((u8 *)response)[i]);
462 }
463
464 /* read the return status */
Eric Anholt21d40d32010-03-25 11:11:14 -0700465 intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS,
Jesse Barnes79e53942008-11-07 14:24:08 -0800466 &status);
467
Eric Anholt21d40d32010-03-25 11:11:14 -0700468 intel_sdvo_debug_response(intel_encoder, response, response_len,
Jesse Barnes79e53942008-11-07 14:24:08 -0800469 status);
470 if (status != SDVO_CMD_STATUS_PENDING)
471 return status;
472
473 mdelay(50);
474 }
475
476 return status;
477}
478
Hannes Ederb358d0a2008-12-18 21:18:47 +0100479static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800480{
481 if (mode->clock >= 100000)
482 return 1;
483 else if (mode->clock >= 50000)
484 return 2;
485 else
486 return 4;
487}
488
489/**
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800490 * Try to read the response after issuie the DDC switch command. But it
491 * is noted that we must do the action of reading response and issuing DDC
492 * switch command in one I2C transaction. Otherwise when we try to start
493 * another I2C transaction after issuing the DDC bus switch, it will be
494 * switched to the internal SDVO register.
Jesse Barnes79e53942008-11-07 14:24:08 -0800495 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700496static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder,
Hannes Ederb358d0a2008-12-18 21:18:47 +0100497 u8 target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800498{
Eric Anholt21d40d32010-03-25 11:11:14 -0700499 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800500 u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
501 struct i2c_msg msgs[] = {
502 {
503 .addr = sdvo_priv->slave_addr >> 1,
504 .flags = 0,
505 .len = 2,
506 .buf = out_buf,
507 },
508 /* the following two are to read the response */
509 {
510 .addr = sdvo_priv->slave_addr >> 1,
511 .flags = 0,
512 .len = 1,
513 .buf = cmd_buf,
514 },
515 {
516 .addr = sdvo_priv->slave_addr >> 1,
517 .flags = I2C_M_RD,
518 .len = 1,
519 .buf = ret_value,
520 },
521 };
522
Eric Anholt21d40d32010-03-25 11:11:14 -0700523 intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800524 &target, 1);
525 /* write the DDC switch command argument */
Eric Anholt21d40d32010-03-25 11:11:14 -0700526 intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800527
528 out_buf[0] = SDVO_I2C_OPCODE;
529 out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
530 cmd_buf[0] = SDVO_I2C_CMD_STATUS;
531 cmd_buf[1] = 0;
532 ret_value[0] = 0;
533 ret_value[1] = 0;
534
Eric Anholt21d40d32010-03-25 11:11:14 -0700535 ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3);
Zhao Yakui6a304ca2010-01-08 10:58:19 +0800536 if (ret != 3) {
537 /* failure in I2C transfer */
538 DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
539 return;
540 }
541 if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
542 DRM_DEBUG_KMS("DDC switch command returns response %d\n",
543 ret_value[0]);
544 return;
545 }
546 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800547}
548
Eric Anholt21d40d32010-03-25 11:11:14 -0700549static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1)
Jesse Barnes79e53942008-11-07 14:24:08 -0800550{
551 struct intel_sdvo_set_target_input_args targets = {0};
552 u8 status;
553
554 if (target_0 && target_1)
555 return SDVO_CMD_STATUS_NOTSUPP;
556
557 if (target_1)
558 targets.target_1 = 1;
559
Eric Anholt21d40d32010-03-25 11:11:14 -0700560 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets,
Jesse Barnes79e53942008-11-07 14:24:08 -0800561 sizeof(targets));
562
Eric Anholt21d40d32010-03-25 11:11:14 -0700563 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800564
565 return (status == SDVO_CMD_STATUS_SUCCESS);
566}
567
568/**
569 * Return whether each input is trained.
570 *
571 * This function is making an assumption about the layout of the response,
572 * which should be checked against the docs.
573 */
Eric Anholt21d40d32010-03-25 11:11:14 -0700574static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2)
Jesse Barnes79e53942008-11-07 14:24:08 -0800575{
576 struct intel_sdvo_get_trained_inputs_response response;
577 u8 status;
578
Eric Anholt21d40d32010-03-25 11:11:14 -0700579 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
580 status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response));
Jesse Barnes79e53942008-11-07 14:24:08 -0800581 if (status != SDVO_CMD_STATUS_SUCCESS)
582 return false;
583
584 *input_1 = response.input0_trained;
585 *input_2 = response.input1_trained;
586 return true;
587}
588
Eric Anholt21d40d32010-03-25 11:11:14 -0700589static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800590 u16 outputs)
591{
592 u8 status;
593
Eric Anholt21d40d32010-03-25 11:11:14 -0700594 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800595 sizeof(outputs));
Eric Anholt21d40d32010-03-25 11:11:14 -0700596 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 return (status == SDVO_CMD_STATUS_SUCCESS);
598}
599
Eric Anholt21d40d32010-03-25 11:11:14 -0700600static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800601 int mode)
602{
603 u8 status, state = SDVO_ENCODER_STATE_ON;
604
605 switch (mode) {
606 case DRM_MODE_DPMS_ON:
607 state = SDVO_ENCODER_STATE_ON;
608 break;
609 case DRM_MODE_DPMS_STANDBY:
610 state = SDVO_ENCODER_STATE_STANDBY;
611 break;
612 case DRM_MODE_DPMS_SUSPEND:
613 state = SDVO_ENCODER_STATE_SUSPEND;
614 break;
615 case DRM_MODE_DPMS_OFF:
616 state = SDVO_ENCODER_STATE_OFF;
617 break;
618 }
619
Eric Anholt21d40d32010-03-25 11:11:14 -0700620 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
Jesse Barnes79e53942008-11-07 14:24:08 -0800621 sizeof(state));
Eric Anholt21d40d32010-03-25 11:11:14 -0700622 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800623
624 return (status == SDVO_CMD_STATUS_SUCCESS);
625}
626
Eric Anholt21d40d32010-03-25 11:11:14 -0700627static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800628 int *clock_min,
629 int *clock_max)
630{
631 struct intel_sdvo_pixel_clock_range clocks;
632 u8 status;
633
Eric Anholt21d40d32010-03-25 11:11:14 -0700634 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
Jesse Barnes79e53942008-11-07 14:24:08 -0800635 NULL, 0);
636
Eric Anholt21d40d32010-03-25 11:11:14 -0700637 status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks));
Jesse Barnes79e53942008-11-07 14:24:08 -0800638
639 if (status != SDVO_CMD_STATUS_SUCCESS)
640 return false;
641
642 /* Convert the values from units of 10 kHz to kHz. */
643 *clock_min = clocks.min * 10;
644 *clock_max = clocks.max * 10;
645
646 return true;
647}
648
Eric Anholt21d40d32010-03-25 11:11:14 -0700649static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800650 u16 outputs)
651{
652 u8 status;
653
Eric Anholt21d40d32010-03-25 11:11:14 -0700654 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
Jesse Barnes79e53942008-11-07 14:24:08 -0800655 sizeof(outputs));
656
Eric Anholt21d40d32010-03-25 11:11:14 -0700657 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800658 return (status == SDVO_CMD_STATUS_SUCCESS);
659}
660
Eric Anholt21d40d32010-03-25 11:11:14 -0700661static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd,
Jesse Barnes79e53942008-11-07 14:24:08 -0800662 struct intel_sdvo_dtd *dtd)
663{
664 u8 status;
665
Eric Anholt21d40d32010-03-25 11:11:14 -0700666 intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1));
667 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800668 if (status != SDVO_CMD_STATUS_SUCCESS)
669 return false;
670
Eric Anholt21d40d32010-03-25 11:11:14 -0700671 intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2));
672 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800673 if (status != SDVO_CMD_STATUS_SUCCESS)
674 return false;
675
676 return true;
677}
678
Eric Anholt21d40d32010-03-25 11:11:14 -0700679static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800680 struct intel_sdvo_dtd *dtd)
681{
Eric Anholt21d40d32010-03-25 11:11:14 -0700682 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800683 SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
684}
685
Eric Anholt21d40d32010-03-25 11:11:14 -0700686static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800687 struct intel_sdvo_dtd *dtd)
688{
Eric Anholt21d40d32010-03-25 11:11:14 -0700689 return intel_sdvo_set_timing(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -0800690 SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
691}
692
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800693static bool
Eric Anholtc751ce42010-03-25 11:48:48 -0700694intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800695 uint16_t clock,
696 uint16_t width,
697 uint16_t height)
698{
699 struct intel_sdvo_preferred_input_timing_args args;
Eric Anholtc751ce42010-03-25 11:48:48 -0700700 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800701 uint8_t status;
702
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800703 memset(&args, 0, sizeof(args));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800704 args.clock = clock;
705 args.width = width;
706 args.height = height;
Zhenyu Wange642c6f2009-03-24 14:02:42 +0800707 args.interlace = 0;
ling.ma@intel.com12682a92009-06-30 11:35:35 +0800708
709 if (sdvo_priv->is_lvds &&
710 (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
711 sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
712 args.scaled = 1;
713
Eric Anholtc751ce42010-03-25 11:48:48 -0700714 intel_sdvo_write_cmd(intel_encoder,
715 SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800716 &args, sizeof(args));
Eric Anholtc751ce42010-03-25 11:48:48 -0700717 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800718 if (status != SDVO_CMD_STATUS_SUCCESS)
719 return false;
720
721 return true;
722}
723
Eric Anholtc751ce42010-03-25 11:48:48 -0700724static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800725 struct intel_sdvo_dtd *dtd)
726{
727 bool status;
728
Eric Anholtc751ce42010-03-25 11:48:48 -0700729 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800730 NULL, 0);
731
Eric Anholtc751ce42010-03-25 11:48:48 -0700732 status = intel_sdvo_read_response(intel_encoder, &dtd->part1,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800733 sizeof(dtd->part1));
734 if (status != SDVO_CMD_STATUS_SUCCESS)
735 return false;
736
Eric Anholtc751ce42010-03-25 11:48:48 -0700737 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800738 NULL, 0);
739
Eric Anholtc751ce42010-03-25 11:48:48 -0700740 status = intel_sdvo_read_response(intel_encoder, &dtd->part2,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800741 sizeof(dtd->part2));
742 if (status != SDVO_CMD_STATUS_SUCCESS)
743 return false;
744
745 return false;
746}
Jesse Barnes79e53942008-11-07 14:24:08 -0800747
Eric Anholt21d40d32010-03-25 11:11:14 -0700748static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val)
Jesse Barnes79e53942008-11-07 14:24:08 -0800749{
750 u8 status;
751
Eric Anholt21d40d32010-03-25 11:11:14 -0700752 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
753 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -0800754 if (status != SDVO_CMD_STATUS_SUCCESS)
755 return false;
756
757 return true;
758}
759
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800760static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
761 struct drm_display_mode *mode)
Jesse Barnes79e53942008-11-07 14:24:08 -0800762{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800763 uint16_t width, height;
764 uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
765 uint16_t h_sync_offset, v_sync_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800766
767 width = mode->crtc_hdisplay;
768 height = mode->crtc_vdisplay;
769
770 /* do some mode translations */
771 h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
772 h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
773
774 v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
775 v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
776
777 h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
778 v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
779
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800780 dtd->part1.clock = mode->clock / 10;
781 dtd->part1.h_active = width & 0xff;
782 dtd->part1.h_blank = h_blank_len & 0xff;
783 dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800784 ((h_blank_len >> 8) & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800785 dtd->part1.v_active = height & 0xff;
786 dtd->part1.v_blank = v_blank_len & 0xff;
787 dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800788 ((v_blank_len >> 8) & 0xf);
789
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800790 dtd->part2.h_sync_off = h_sync_offset & 0xff;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800791 dtd->part2.h_sync_width = h_sync_len & 0xff;
792 dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
Jesse Barnes79e53942008-11-07 14:24:08 -0800793 (v_sync_len & 0xf);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800794 dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
Jesse Barnes79e53942008-11-07 14:24:08 -0800795 ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
796 ((v_sync_len & 0x30) >> 4);
797
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800798 dtd->part2.dtd_flags = 0x18;
Jesse Barnes79e53942008-11-07 14:24:08 -0800799 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800800 dtd->part2.dtd_flags |= 0x2;
Jesse Barnes79e53942008-11-07 14:24:08 -0800801 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800802 dtd->part2.dtd_flags |= 0x4;
Jesse Barnes79e53942008-11-07 14:24:08 -0800803
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800804 dtd->part2.sdvo_flags = 0;
805 dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
806 dtd->part2.reserved = 0;
807}
Jesse Barnes79e53942008-11-07 14:24:08 -0800808
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800809static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
810 struct intel_sdvo_dtd *dtd)
811{
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800812 mode->hdisplay = dtd->part1.h_active;
813 mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
814 mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800815 mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800816 mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
817 mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
818 mode->htotal = mode->hdisplay + dtd->part1.h_blank;
819 mode->htotal += (dtd->part1.h_high & 0xf) << 8;
820
821 mode->vdisplay = dtd->part1.v_active;
822 mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
823 mode->vsync_start = mode->vdisplay;
824 mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800825 mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800826 mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
827 mode->vsync_end = mode->vsync_start +
828 (dtd->part2.v_sync_off_width & 0xf);
829 mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
830 mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
831 mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
832
833 mode->clock = dtd->part1.clock * 10;
834
Zhenyu Wang171a9e92009-03-24 14:02:41 +0800835 mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800836 if (dtd->part2.dtd_flags & 0x2)
837 mode->flags |= DRM_MODE_FLAG_PHSYNC;
838 if (dtd->part2.dtd_flags & 0x4)
839 mode->flags |= DRM_MODE_FLAG_PVSYNC;
840}
841
Eric Anholtc751ce42010-03-25 11:48:48 -0700842static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800843 struct intel_sdvo_encode *encode)
844{
845 uint8_t status;
846
Eric Anholtc751ce42010-03-25 11:48:48 -0700847 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
848 status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode));
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800849 if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
850 memset(encode, 0, sizeof(*encode));
851 return false;
852 }
853
854 return true;
855}
856
Eric Anholtc751ce42010-03-25 11:48:48 -0700857static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder,
858 uint8_t mode)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800859{
860 uint8_t status;
861
Eric Anholtc751ce42010-03-25 11:48:48 -0700862 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1);
863 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800864
865 return (status == SDVO_CMD_STATUS_SUCCESS);
866}
867
Eric Anholtc751ce42010-03-25 11:48:48 -0700868static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800869 uint8_t mode)
870{
871 uint8_t status;
872
Eric Anholtc751ce42010-03-25 11:48:48 -0700873 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
874 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800875
876 return (status == SDVO_CMD_STATUS_SUCCESS);
877}
878
879#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -0700880static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800881{
882 int i, j;
883 uint8_t set_buf_index[2];
884 uint8_t av_split;
885 uint8_t buf_size;
886 uint8_t buf[48];
887 uint8_t *pos;
888
Eric Anholtc751ce42010-03-25 11:48:48 -0700889 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
890 intel_sdvo_read_response(encoder, &av_split, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800891
892 for (i = 0; i <= av_split; i++) {
893 set_buf_index[0] = i; set_buf_index[1] = 0;
Eric Anholtc751ce42010-03-25 11:48:48 -0700894 intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800895 set_buf_index, 2);
Eric Anholtc751ce42010-03-25 11:48:48 -0700896 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
897 intel_sdvo_read_response(encoder, &buf_size, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800898
899 pos = buf;
900 for (j = 0; j <= buf_size; j += 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700901 intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800902 NULL, 0);
Eric Anholtc751ce42010-03-25 11:48:48 -0700903 intel_sdvo_read_response(encoder, pos, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800904 pos += 8;
905 }
906 }
907}
908#endif
909
Eric Anholtc751ce42010-03-25 11:48:48 -0700910static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder,
911 int index,
912 uint8_t *data, int8_t size, uint8_t tx_rate)
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800913{
914 uint8_t set_buf_index[2];
915
916 set_buf_index[0] = index;
917 set_buf_index[1] = 0;
918
Eric Anholtc751ce42010-03-25 11:48:48 -0700919 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX,
920 set_buf_index, 2);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800921
922 for (; size > 0; size -= 8) {
Eric Anholtc751ce42010-03-25 11:48:48 -0700923 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800924 data += 8;
925 }
926
Eric Anholtc751ce42010-03-25 11:48:48 -0700927 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -0800928}
929
930static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
931{
932 uint8_t csum = 0;
933 int i;
934
935 for (i = 0; i < size; i++)
936 csum += data[i];
937
938 return 0x100 - csum;
939}
940
941#define DIP_TYPE_AVI 0x82
942#define DIP_VERSION_AVI 0x2
943#define DIP_LEN_AVI 13
944
945struct dip_infoframe {
946 uint8_t type;
947 uint8_t version;
948 uint8_t len;
949 uint8_t checksum;
950 union {
951 struct {
952 /* Packet Byte #1 */
953 uint8_t S:2;
954 uint8_t B:2;
955 uint8_t A:1;
956 uint8_t Y:2;
957 uint8_t rsvd1:1;
958 /* Packet Byte #2 */
959 uint8_t R:4;
960 uint8_t M:2;
961 uint8_t C:2;
962 /* Packet Byte #3 */
963 uint8_t SC:2;
964 uint8_t Q:2;
965 uint8_t EC:3;
966 uint8_t ITC:1;
967 /* Packet Byte #4 */
968 uint8_t VIC:7;
969 uint8_t rsvd2:1;
970 /* Packet Byte #5 */
971 uint8_t PR:4;
972 uint8_t rsvd3:4;
973 /* Packet Byte #6~13 */
974 uint16_t top_bar_end;
975 uint16_t bottom_bar_start;
976 uint16_t left_bar_end;
977 uint16_t right_bar_start;
978 } avi;
979 struct {
980 /* Packet Byte #1 */
981 uint8_t channel_count:3;
982 uint8_t rsvd1:1;
983 uint8_t coding_type:4;
984 /* Packet Byte #2 */
985 uint8_t sample_size:2; /* SS0, SS1 */
986 uint8_t sample_frequency:3;
987 uint8_t rsvd2:3;
988 /* Packet Byte #3 */
989 uint8_t coding_type_private:5;
990 uint8_t rsvd3:3;
991 /* Packet Byte #4 */
992 uint8_t channel_allocation;
993 /* Packet Byte #5 */
994 uint8_t rsvd4:3;
995 uint8_t level_shift:4;
996 uint8_t downmix_inhibit:1;
997 } audio;
998 uint8_t payload[28];
999 } __attribute__ ((packed)) u;
1000} __attribute__((packed));
1001
Eric Anholtc751ce42010-03-25 11:48:48 -07001002static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001003 struct drm_display_mode * mode)
1004{
1005 struct dip_infoframe avi_if = {
1006 .type = DIP_TYPE_AVI,
1007 .version = DIP_VERSION_AVI,
1008 .len = DIP_LEN_AVI,
1009 };
1010
1011 avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
1012 4 + avi_if.len);
Eric Anholtc751ce42010-03-25 11:48:48 -07001013 intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if,
1014 4 + avi_if.len,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001015 SDVO_HBUF_TX_VSYNC);
1016}
1017
Eric Anholtc751ce42010-03-25 11:48:48 -07001018static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001019{
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001020
Zhao Yakuice6feab2009-08-24 13:50:26 +08001021 struct intel_sdvo_tv_format format;
Eric Anholtc751ce42010-03-25 11:48:48 -07001022 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001023 uint32_t format_map, i;
1024 uint8_t status;
1025
1026 for (i = 0; i < TV_FORMAT_NUM; i++)
1027 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1028 break;
1029
1030 format_map = 1 << i;
1031 memset(&format, 0, sizeof(format));
1032 memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
1033 sizeof(format) : sizeof(format_map));
1034
Eric Anholtc751ce42010-03-25 11:48:48 -07001035 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format_map,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001036 sizeof(format));
1037
Eric Anholtc751ce42010-03-25 11:48:48 -07001038 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001039 if (status != SDVO_CMD_STATUS_SUCCESS)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001040 DRM_DEBUG_KMS("%s: Failed to set TV format\n",
Zhao Yakuice6feab2009-08-24 13:50:26 +08001041 SDVO_NAME(sdvo_priv));
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001042}
1043
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001044static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
1045 struct drm_display_mode *mode,
1046 struct drm_display_mode *adjusted_mode)
1047{
Eric Anholtc751ce42010-03-25 11:48:48 -07001048 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1049 struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001050
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001051 if (dev_priv->is_tv) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001052 struct intel_sdvo_dtd output_dtd;
1053 bool success;
1054
1055 /* We need to construct preferred input timings based on our
1056 * output timings. To do that, we have to set the output
1057 * timings, even though this isn't really the right place in
1058 * the sequence to do it. Oh well.
1059 */
1060
1061
1062 /* Set output timings */
1063 intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
Eric Anholtc751ce42010-03-25 11:48:48 -07001064 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001065 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001066 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001067
1068 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001069 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001070
1071
Eric Anholtc751ce42010-03-25 11:48:48 -07001072 success = intel_sdvo_create_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001073 mode->clock / 10,
1074 mode->hdisplay,
1075 mode->vdisplay);
1076 if (success) {
1077 struct intel_sdvo_dtd input_dtd;
1078
Eric Anholtc751ce42010-03-25 11:48:48 -07001079 intel_sdvo_get_preferred_input_timing(intel_encoder,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001080 &input_dtd);
1081 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001082 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001083
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001084 drm_mode_set_crtcinfo(adjusted_mode, 0);
1085
1086 mode->clock = adjusted_mode->clock;
1087
1088 adjusted_mode->clock *=
1089 intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001090 } else {
1091 return false;
1092 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001093 } else if (dev_priv->is_lvds) {
1094 struct intel_sdvo_dtd output_dtd;
1095 bool success;
1096
1097 drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
1098 /* Set output timings */
1099 intel_sdvo_get_dtd_from_mode(&output_dtd,
1100 dev_priv->sdvo_lvds_fixed_mode);
1101
Eric Anholtc751ce42010-03-25 11:48:48 -07001102 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001103 dev_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001104 intel_sdvo_set_output_timing(intel_encoder, &output_dtd);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001105
1106 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001107 intel_sdvo_set_target_input(intel_encoder, true, false);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001108
1109
1110 success = intel_sdvo_create_preferred_input_timing(
Eric Anholtc751ce42010-03-25 11:48:48 -07001111 intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001112 mode->clock / 10,
1113 mode->hdisplay,
1114 mode->vdisplay);
1115
1116 if (success) {
1117 struct intel_sdvo_dtd input_dtd;
1118
Eric Anholtc751ce42010-03-25 11:48:48 -07001119 intel_sdvo_get_preferred_input_timing(intel_encoder,
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001120 &input_dtd);
1121 intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
1122 dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
1123
1124 drm_mode_set_crtcinfo(adjusted_mode, 0);
1125
1126 mode->clock = adjusted_mode->clock;
1127
1128 adjusted_mode->clock *=
1129 intel_sdvo_get_pixel_multiplier(mode);
1130 } else {
1131 return false;
1132 }
1133
1134 } else {
1135 /* Make the CRTC code factor in the SDVO pixel multiplier. The
1136 * SDVO device will be told of the multiplier during mode_set.
1137 */
1138 adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001139 }
1140 return true;
1141}
1142
1143static void intel_sdvo_mode_set(struct drm_encoder *encoder,
1144 struct drm_display_mode *mode,
1145 struct drm_display_mode *adjusted_mode)
1146{
1147 struct drm_device *dev = encoder->dev;
1148 struct drm_i915_private *dev_priv = dev->dev_private;
1149 struct drm_crtc *crtc = encoder->crtc;
1150 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Eric Anholtc751ce42010-03-25 11:48:48 -07001151 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1152 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001153 u32 sdvox = 0;
1154 int sdvo_pixel_multiply;
1155 struct intel_sdvo_in_out_map in_out;
1156 struct intel_sdvo_dtd input_dtd;
1157 u8 status;
1158
1159 if (!mode)
1160 return;
1161
1162 /* First, set the input mapping for the first input to our controlled
1163 * output. This is only correct if we're a single-input device, in
1164 * which case the first input is the output from the appropriate SDVO
1165 * channel on the motherboard. In a two-input device, the first input
1166 * will be SDVOB and the second SDVOC.
1167 */
Zhenyu Wang14571b42010-03-30 14:06:33 +08001168 in_out.in0 = sdvo_priv->attached_output;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001169 in_out.in1 = 0;
1170
Eric Anholtc751ce42010-03-25 11:48:48 -07001171 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001172 &in_out, sizeof(in_out));
Eric Anholtc751ce42010-03-25 11:48:48 -07001173 status = intel_sdvo_read_response(intel_encoder, NULL, 0);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001174
1175 if (sdvo_priv->is_hdmi) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001176 intel_sdvo_set_avi_infoframe(intel_encoder, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001177 sdvox |= SDVO_AUDIO_ENABLE;
1178 }
1179
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001180 /* We have tried to get input timing in mode_fixup, and filled into
1181 adjusted_mode */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001182 if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001183 intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001184 input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
1185 } else
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001186 intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001187
1188 /* If it's a TV, we already set the output timing in mode_fixup.
1189 * Otherwise, the output timing is equal to the input timing.
1190 */
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001191 if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001192 /* Set the output timing to the screen */
Eric Anholtc751ce42010-03-25 11:48:48 -07001193 intel_sdvo_set_target_output(intel_encoder,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001194 sdvo_priv->attached_output);
Eric Anholtc751ce42010-03-25 11:48:48 -07001195 intel_sdvo_set_output_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001196 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001197
1198 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholtc751ce42010-03-25 11:48:48 -07001199 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08001200
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001201 if (sdvo_priv->is_tv)
Eric Anholtc751ce42010-03-25 11:48:48 -07001202 intel_sdvo_set_tv_format(intel_encoder);
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001203
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001204 /* We would like to use intel_sdvo_create_preferred_input_timing() to
Jesse Barnes79e53942008-11-07 14:24:08 -08001205 * provide the device with a timing it can support, if it supports that
1206 * feature. However, presumably we would need to adjust the CRTC to
1207 * output the preferred timing, and we don't support that currently.
1208 */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001209#if 0
Eric Anholtc751ce42010-03-25 11:48:48 -07001210 success = intel_sdvo_create_preferred_input_timing(encoder, clock,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001211 width, height);
1212 if (success) {
1213 struct intel_sdvo_dtd *input_dtd;
1214
Eric Anholtc751ce42010-03-25 11:48:48 -07001215 intel_sdvo_get_preferred_input_timing(encoder, &input_dtd);
1216 intel_sdvo_set_input_timing(encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001217 }
1218#else
Eric Anholtc751ce42010-03-25 11:48:48 -07001219 intel_sdvo_set_input_timing(intel_encoder, &input_dtd);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001220#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001221
1222 switch (intel_sdvo_get_pixel_multiplier(mode)) {
1223 case 1:
Eric Anholtc751ce42010-03-25 11:48:48 -07001224 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001225 SDVO_CLOCK_RATE_MULT_1X);
1226 break;
1227 case 2:
Eric Anholtc751ce42010-03-25 11:48:48 -07001228 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001229 SDVO_CLOCK_RATE_MULT_2X);
1230 break;
1231 case 4:
Eric Anholtc751ce42010-03-25 11:48:48 -07001232 intel_sdvo_set_clock_rate_mult(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08001233 SDVO_CLOCK_RATE_MULT_4X);
1234 break;
1235 }
1236
1237 /* Set the SDVO control regs. */
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001238 if (IS_I965G(dev)) {
1239 sdvox |= SDVO_BORDER_ENABLE |
1240 SDVO_VSYNC_ACTIVE_HIGH |
1241 SDVO_HSYNC_ACTIVE_HIGH;
1242 } else {
Eric Anholtc751ce42010-03-25 11:48:48 -07001243 sdvox |= I915_READ(sdvo_priv->sdvo_reg);
1244 switch (sdvo_priv->sdvo_reg) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001245 case SDVOB:
1246 sdvox &= SDVOB_PRESERVE_MASK;
1247 break;
1248 case SDVOC:
1249 sdvox &= SDVOC_PRESERVE_MASK;
1250 break;
1251 }
1252 sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
1253 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001254 if (intel_crtc->pipe == 1)
1255 sdvox |= SDVO_PIPE_B_SELECT;
1256
1257 sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
1258 if (IS_I965G(dev)) {
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001259 /* done in crtc_mode_set as the dpll_md reg must be written early */
1260 } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
1261 /* done in crtc_mode_set as it lives inside the dpll register */
Jesse Barnes79e53942008-11-07 14:24:08 -08001262 } else {
1263 sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
1264 }
1265
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001266 if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
1267 sdvox |= SDVO_STALL_SELECT;
Eric Anholtc751ce42010-03-25 11:48:48 -07001268 intel_sdvo_write_sdvox(intel_encoder, sdvox);
Jesse Barnes79e53942008-11-07 14:24:08 -08001269}
1270
1271static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
1272{
1273 struct drm_device *dev = encoder->dev;
1274 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001275 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1276 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001277 u32 temp;
1278
1279 if (mode != DRM_MODE_DPMS_ON) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001280 intel_sdvo_set_active_outputs(intel_encoder, 0);
Jesse Barnes79e53942008-11-07 14:24:08 -08001281 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001282 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Jesse Barnes79e53942008-11-07 14:24:08 -08001283
1284 if (mode == DRM_MODE_DPMS_OFF) {
Eric Anholtc751ce42010-03-25 11:48:48 -07001285 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001286 if ((temp & SDVO_ENABLE) != 0) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001287 intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001288 }
1289 }
1290 } else {
1291 bool input1, input2;
1292 int i;
1293 u8 status;
1294
Eric Anholtc751ce42010-03-25 11:48:48 -07001295 temp = I915_READ(sdvo_priv->sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08001296 if ((temp & SDVO_ENABLE) == 0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001297 intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE);
Jesse Barnes79e53942008-11-07 14:24:08 -08001298 for (i = 0; i < 2; i++)
1299 intel_wait_for_vblank(dev);
1300
Eric Anholt21d40d32010-03-25 11:11:14 -07001301 status = intel_sdvo_get_trained_inputs(intel_encoder, &input1,
Jesse Barnes79e53942008-11-07 14:24:08 -08001302 &input2);
1303
1304
1305 /* Warn if the device reported failure to sync.
1306 * A lot of SDVO devices fail to notify of sync, but it's
1307 * a given it the status is a success, we succeeded.
1308 */
1309 if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001310 DRM_DEBUG_KMS("First %s output reported failure to "
1311 "sync\n", SDVO_NAME(sdvo_priv));
Jesse Barnes79e53942008-11-07 14:24:08 -08001312 }
1313
1314 if (0)
Eric Anholt21d40d32010-03-25 11:11:14 -07001315 intel_sdvo_set_encoder_power_state(intel_encoder, mode);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001316 intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output);
Jesse Barnes79e53942008-11-07 14:24:08 -08001317 }
1318 return;
1319}
1320
Jesse Barnes79e53942008-11-07 14:24:08 -08001321static int intel_sdvo_mode_valid(struct drm_connector *connector,
1322 struct drm_display_mode *mode)
1323{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001324 struct drm_encoder *encoder = intel_attached_encoder(connector);
1325 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001326 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08001327
1328 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
1329 return MODE_NO_DBLESCAN;
1330
1331 if (sdvo_priv->pixel_clock_min > mode->clock)
1332 return MODE_CLOCK_LOW;
1333
1334 if (sdvo_priv->pixel_clock_max < mode->clock)
1335 return MODE_CLOCK_HIGH;
1336
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001337 if (sdvo_priv->is_lvds == true) {
1338 if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
1339 return MODE_PANEL;
1340
1341 if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
1342 return MODE_PANEL;
1343
1344 if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
1345 return MODE_PANEL;
1346 }
1347
Jesse Barnes79e53942008-11-07 14:24:08 -08001348 return MODE_OK;
1349}
1350
Eric Anholt21d40d32010-03-25 11:11:14 -07001351static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps)
Jesse Barnes79e53942008-11-07 14:24:08 -08001352{
1353 u8 status;
1354
Eric Anholt21d40d32010-03-25 11:11:14 -07001355 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
1356 status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps));
Jesse Barnes79e53942008-11-07 14:24:08 -08001357 if (status != SDVO_CMD_STATUS_SUCCESS)
1358 return false;
1359
1360 return true;
1361}
1362
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001363/* No use! */
1364#if 0
Jesse Barnes79e53942008-11-07 14:24:08 -08001365struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
1366{
1367 struct drm_connector *connector = NULL;
Eric Anholt21d40d32010-03-25 11:11:14 -07001368 struct intel_encoder *iout = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001369 struct intel_sdvo_priv *sdvo;
1370
1371 /* find the sdvo connector */
1372 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001373 iout = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001374
1375 if (iout->type != INTEL_OUTPUT_SDVO)
1376 continue;
1377
1378 sdvo = iout->dev_priv;
1379
Eric Anholtc751ce42010-03-25 11:48:48 -07001380 if (sdvo->sdvo_reg == SDVOB && sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001381 return connector;
1382
Eric Anholtc751ce42010-03-25 11:48:48 -07001383 if (sdvo->sdvo_reg == SDVOC && !sdvoB)
Jesse Barnes79e53942008-11-07 14:24:08 -08001384 return connector;
1385
1386 }
1387
1388 return NULL;
1389}
1390
1391int intel_sdvo_supports_hotplug(struct drm_connector *connector)
1392{
1393 u8 response[2];
1394 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001395 struct intel_encoder *intel_encoder;
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08001396 DRM_DEBUG_KMS("\n");
Jesse Barnes79e53942008-11-07 14:24:08 -08001397
1398 if (!connector)
1399 return 0;
1400
Eric Anholt21d40d32010-03-25 11:11:14 -07001401 intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001402
Eric Anholt21d40d32010-03-25 11:11:14 -07001403 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1404 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001405
1406 if (response[0] !=0)
1407 return 1;
1408
1409 return 0;
1410}
1411
1412void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
1413{
1414 u8 response[2];
1415 u8 status;
Eric Anholt21d40d32010-03-25 11:11:14 -07001416 struct intel_encoder *intel_encoder = to_intel_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001417
Eric Anholt21d40d32010-03-25 11:11:14 -07001418 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1419 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001420
1421 if (on) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001422 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
1423 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001424
Eric Anholt21d40d32010-03-25 11:11:14 -07001425 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001426 } else {
1427 response[0] = 0;
1428 response[1] = 0;
Eric Anholt21d40d32010-03-25 11:11:14 -07001429 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001430 }
1431
Eric Anholt21d40d32010-03-25 11:11:14 -07001432 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
1433 intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001434}
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001435#endif
Jesse Barnes79e53942008-11-07 14:24:08 -08001436
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001437static bool
Eric Anholt21d40d32010-03-25 11:11:14 -07001438intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001439{
Eric Anholt21d40d32010-03-25 11:11:14 -07001440 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001441 int caps = 0;
1442
1443 if (sdvo_priv->caps.output_flags &
1444 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1445 caps++;
1446 if (sdvo_priv->caps.output_flags &
1447 (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
1448 caps++;
1449 if (sdvo_priv->caps.output_flags &
Roel Kluin19e1f882009-08-09 13:50:53 +02001450 (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001451 caps++;
1452 if (sdvo_priv->caps.output_flags &
1453 (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
1454 caps++;
1455 if (sdvo_priv->caps.output_flags &
1456 (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
1457 caps++;
1458
1459 if (sdvo_priv->caps.output_flags &
1460 (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
1461 caps++;
1462
1463 if (sdvo_priv->caps.output_flags &
1464 (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
1465 caps++;
1466
1467 return (caps > 1);
1468}
1469
Keith Packard57cdaf92009-09-04 13:07:54 +08001470static struct drm_connector *
1471intel_find_analog_connector(struct drm_device *dev)
1472{
1473 struct drm_connector *connector;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001474 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07001475 struct intel_encoder *intel_encoder;
Keith Packard57cdaf92009-09-04 13:07:54 +08001476
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001477 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1478 intel_encoder = enc_to_intel_encoder(encoder);
1479 if (intel_encoder->type == INTEL_OUTPUT_ANALOG) {
1480 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
1481 if (connector && encoder == intel_attached_encoder(connector))
1482 return connector;
1483 }
1484 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001485 }
1486 return NULL;
1487}
1488
1489static int
1490intel_analog_is_connected(struct drm_device *dev)
1491{
1492 struct drm_connector *analog_connector;
1493 analog_connector = intel_find_analog_connector(dev);
1494
1495 if (!analog_connector)
1496 return false;
1497
1498 if (analog_connector->funcs->detect(analog_connector) ==
1499 connector_status_disconnected)
1500 return false;
1501
1502 return true;
1503}
1504
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001505enum drm_connector_status
1506intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
Ma Ling9dff6af2009-04-02 13:13:26 +08001507{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001508 struct drm_encoder *encoder = intel_attached_encoder(connector);
1509 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001510 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001511 enum drm_connector_status status = connector_status_connected;
Ma Ling9dff6af2009-04-02 13:13:26 +08001512 struct edid *edid = NULL;
1513
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001514 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001515 intel_encoder->ddc_bus);
Keith Packard57cdaf92009-09-04 13:07:54 +08001516
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001517 /* This is only applied to SDVO cards with multiple outputs */
Eric Anholt21d40d32010-03-25 11:11:14 -07001518 if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) {
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001519 uint8_t saved_ddc, temp_ddc;
1520 saved_ddc = sdvo_priv->ddc_bus;
1521 temp_ddc = sdvo_priv->ddc_bus >> 1;
1522 /*
1523 * Don't use the 1 as the argument of DDC bus switch to get
1524 * the EDID. It is used for SDVO SPD ROM.
1525 */
1526 while(temp_ddc > 1) {
1527 sdvo_priv->ddc_bus = temp_ddc;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001528 edid = drm_get_edid(connector,
Eric Anholt21d40d32010-03-25 11:11:14 -07001529 intel_encoder->ddc_bus);
Zhao Yakui7c3f0a22010-01-08 10:58:20 +08001530 if (edid) {
1531 /*
1532 * When we can get the EDID, maybe it is the
1533 * correct DDC bus. Update it.
1534 */
1535 sdvo_priv->ddc_bus = temp_ddc;
1536 break;
1537 }
1538 temp_ddc >>= 1;
1539 }
1540 if (edid == NULL)
1541 sdvo_priv->ddc_bus = saved_ddc;
1542 }
Keith Packard57cdaf92009-09-04 13:07:54 +08001543 /* when there is no edid and no monitor is connected with VGA
1544 * port, try to use the CRT ddc to read the EDID for DVI-connector
1545 */
1546 if (edid == NULL &&
1547 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001548 !intel_analog_is_connected(connector->dev))
1549 edid = drm_get_edid(connector,
Keith Packard57cdaf92009-09-04 13:07:54 +08001550 sdvo_priv->analog_ddc_bus);
Ma Ling9dff6af2009-04-02 13:13:26 +08001551 if (edid != NULL) {
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001552 /* Don't report the output as connected if it's a DVI-I
1553 * connector with a non-digital EDID coming out.
1554 */
1555 if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
1556 if (edid->input & DRM_EDID_INPUT_DIGITAL)
1557 sdvo_priv->is_hdmi =
1558 drm_detect_hdmi_monitor(edid);
1559 else
1560 status = connector_status_disconnected;
1561 }
1562
Ma Ling9dff6af2009-04-02 13:13:26 +08001563 kfree(edid);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001564 connector->display_info.raw_edid = NULL;
ling.ma@intel.com2b8d33f2009-07-29 11:31:18 +08001565
1566 } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1567 status = connector_status_disconnected;
1568
1569 return status;
Ma Ling9dff6af2009-04-02 13:13:26 +08001570}
1571
Jesse Barnes79e53942008-11-07 14:24:08 -08001572static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
1573{
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001574 uint16_t response;
Jesse Barnes79e53942008-11-07 14:24:08 -08001575 u8 status;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001576 struct drm_encoder *encoder = intel_attached_encoder(connector);
1577 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1578 struct intel_connector *intel_connector = to_intel_connector(connector);
Eric Anholt21d40d32010-03-25 11:11:14 -07001579 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001580 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1581 enum drm_connector_status ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001582
Eric Anholt21d40d32010-03-25 11:11:14 -07001583 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08001584 SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
Zhao Yakuid09c23d2009-11-06 15:39:56 +08001585 if (sdvo_priv->is_tv) {
1586 /* add 30ms delay when the output type is SDVO-TV */
1587 mdelay(30);
1588 }
Eric Anholt21d40d32010-03-25 11:11:14 -07001589 status = intel_sdvo_read_response(intel_encoder, &response, 2);
Jesse Barnes79e53942008-11-07 14:24:08 -08001590
Dave Airlie51c8b402009-08-20 13:38:04 +10001591 DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001592
1593 if (status != SDVO_CMD_STATUS_SUCCESS)
1594 return connector_status_unknown;
1595
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001596 if (response == 0)
Jesse Barnes79e53942008-11-07 14:24:08 -08001597 return connector_status_disconnected;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001598
Zhenyu Wang14571b42010-03-30 14:06:33 +08001599 sdvo_priv->attached_output = response;
1600
1601 if ((sdvo_connector->output_flag & response) == 0)
1602 ret = connector_status_disconnected;
1603 else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
1604 ret = intel_sdvo_hdmi_sink_detect(connector, response);
1605 else
1606 ret = connector_status_connected;
1607
1608 /* May update encoder flag for like clock for SDVO TV, etc.*/
1609 if (ret == connector_status_connected) {
1610 sdvo_priv->is_tv = false;
1611 sdvo_priv->is_lvds = false;
1612 intel_encoder->needs_tv_clock = false;
1613
1614 if (response & SDVO_TV_MASK) {
1615 sdvo_priv->is_tv = true;
1616 intel_encoder->needs_tv_clock = true;
1617 }
1618 if (response & SDVO_LVDS_MASK)
1619 sdvo_priv->is_lvds = true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08001620 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001621
1622 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -08001623}
1624
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001625static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
Jesse Barnes79e53942008-11-07 14:24:08 -08001626{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001627 struct drm_encoder *encoder = intel_attached_encoder(connector);
1628 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001629 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Keith Packard57cdaf92009-09-04 13:07:54 +08001630 int num_modes;
Jesse Barnes79e53942008-11-07 14:24:08 -08001631
1632 /* set the bus switch and get the modes */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001633 num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Jesse Barnes79e53942008-11-07 14:24:08 -08001634
Keith Packard57cdaf92009-09-04 13:07:54 +08001635 /*
1636 * Mac mini hack. On this device, the DVI-I connector shares one DDC
1637 * link between analog and digital outputs. So, if the regular SDVO
1638 * DDC fails, check to see if the analog output is disconnected, in
1639 * which case we'll look there for the digital DDC data.
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001640 */
Keith Packard57cdaf92009-09-04 13:07:54 +08001641 if (num_modes == 0 &&
1642 sdvo_priv->analog_ddc_bus &&
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001643 !intel_analog_is_connected(connector->dev)) {
Keith Packard57cdaf92009-09-04 13:07:54 +08001644 /* Switch to the analog ddc bus and try that
1645 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001646 (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001647 }
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001648}
1649
1650/*
1651 * Set of SDVO TV modes.
1652 * Note! This is in reply order (see loop in get_tv_modes).
1653 * XXX: all 60Hz refresh?
1654 */
1655struct drm_display_mode sdvo_tv_modes[] = {
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001656 { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
1657 416, 0, 200, 201, 232, 233, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001658 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001659 { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
1660 416, 0, 240, 241, 272, 273, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001661 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001662 { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
1663 496, 0, 300, 301, 332, 333, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001664 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001665 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
1666 736, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001667 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001668 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
1669 736, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001670 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001671 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
1672 736, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001673 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001674 { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
1675 800, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001676 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001677 { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
1678 800, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001679 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001680 { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
1681 816, 0, 350, 351, 382, 383, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001682 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001683 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
1684 816, 0, 400, 401, 432, 433, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001685 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001686 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
1687 816, 0, 480, 481, 512, 513, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001688 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001689 { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
1690 816, 0, 540, 541, 572, 573, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001691 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001692 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
1693 816, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001694 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001695 { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
1696 864, 0, 576, 577, 608, 609, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001697 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001698 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
1699 896, 0, 600, 601, 632, 633, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001700 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001701 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
1702 928, 0, 624, 625, 656, 657, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001703 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001704 { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
1705 1016, 0, 766, 767, 798, 799, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001706 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001707 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
1708 1120, 0, 768, 769, 800, 801, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001709 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001710 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
1711 1376, 0, 1024, 1025, 1056, 1057, 0,
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001712 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
1713};
1714
1715static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
1716{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001717 struct drm_encoder *encoder = intel_attached_encoder(connector);
1718 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
1719 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001720 struct intel_sdvo_sdtv_resolution_request tv_res;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001721 uint32_t reply = 0, format_map = 0;
1722 int i;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001723 uint8_t status;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001724
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001725
1726 /* Read the list of supported input resolutions for the selected TV
1727 * format.
1728 */
Zhao Yakuice6feab2009-08-24 13:50:26 +08001729 for (i = 0; i < TV_FORMAT_NUM; i++)
1730 if (tv_format_names[i] == sdvo_priv->tv_format_name)
1731 break;
1732
1733 format_map = (1 << i);
1734 memcpy(&tv_res, &format_map,
1735 sizeof(struct intel_sdvo_sdtv_resolution_request) >
1736 sizeof(format_map) ? sizeof(format_map) :
1737 sizeof(struct intel_sdvo_sdtv_resolution_request));
1738
Zhenyu Wang14571b42010-03-30 14:06:33 +08001739 intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output);
Zhao Yakuice6feab2009-08-24 13:50:26 +08001740
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001741 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001742 &tv_res, sizeof(tv_res));
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001743 status = intel_sdvo_read_response(intel_encoder, &reply, 3);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001744 if (status != SDVO_CMD_STATUS_SUCCESS)
1745 return;
1746
1747 for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
Zhenyu Wang7026d4a2009-03-24 14:02:43 +08001748 if (reply & (1 << i)) {
1749 struct drm_display_mode *nmode;
1750 nmode = drm_mode_duplicate(connector->dev,
1751 &sdvo_tv_modes[i]);
1752 if (nmode)
1753 drm_mode_probed_add(connector, nmode);
1754 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001755
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001756}
1757
Ma Ling7086c872009-05-13 11:20:06 +08001758static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
1759{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001760 struct drm_encoder *encoder = intel_attached_encoder(connector);
1761 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Ma Ling7086c872009-05-13 11:20:06 +08001762 struct drm_i915_private *dev_priv = connector->dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07001763 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001764 struct drm_display_mode *newmode;
Ma Ling7086c872009-05-13 11:20:06 +08001765
1766 /*
1767 * Attempt to get the mode list from DDC.
1768 * Assume that the preferred modes are
1769 * arranged in priority order.
1770 */
Zhenyu Wang335af9a2010-03-30 14:39:31 +08001771 intel_ddc_get_modes(connector, intel_encoder->ddc_bus);
Ma Ling7086c872009-05-13 11:20:06 +08001772 if (list_empty(&connector->probed_modes) == false)
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001773 goto end;
Ma Ling7086c872009-05-13 11:20:06 +08001774
1775 /* Fetch modes from VBT */
1776 if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
Ma Ling7086c872009-05-13 11:20:06 +08001777 newmode = drm_mode_duplicate(connector->dev,
1778 dev_priv->sdvo_lvds_vbt_mode);
1779 if (newmode != NULL) {
1780 /* Guarantee the mode is preferred */
1781 newmode->type = (DRM_MODE_TYPE_PREFERRED |
1782 DRM_MODE_TYPE_DRIVER);
1783 drm_mode_probed_add(connector, newmode);
1784 }
1785 }
ling.ma@intel.com12682a92009-06-30 11:35:35 +08001786
1787end:
1788 list_for_each_entry(newmode, &connector->probed_modes, head) {
1789 if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
1790 sdvo_priv->sdvo_lvds_fixed_mode =
1791 drm_mode_duplicate(connector->dev, newmode);
1792 break;
1793 }
1794 }
1795
Ma Ling7086c872009-05-13 11:20:06 +08001796}
1797
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001798static int intel_sdvo_get_modes(struct drm_connector *connector)
1799{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001800 struct intel_connector *intel_connector = to_intel_connector(connector);
1801 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001802
Zhenyu Wang14571b42010-03-30 14:06:33 +08001803 if (IS_TV(sdvo_connector))
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001804 intel_sdvo_get_tv_modes(connector);
Zhenyu Wang14571b42010-03-30 14:06:33 +08001805 else if (IS_LVDS(sdvo_connector))
Ma Ling7086c872009-05-13 11:20:06 +08001806 intel_sdvo_get_lvds_modes(connector);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08001807 else
1808 intel_sdvo_get_ddc_modes(connector);
1809
Jesse Barnes79e53942008-11-07 14:24:08 -08001810 if (list_empty(&connector->probed_modes))
1811 return 0;
1812 return 1;
1813}
1814
Zhao Yakuib9219c52009-09-10 15:45:46 +08001815static
1816void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
1817{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001818 struct intel_connector *intel_connector = to_intel_connector(connector);
1819 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
1820 struct drm_device *dev = connector->dev;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001821
Zhenyu Wang14571b42010-03-30 14:06:33 +08001822 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001823 if (sdvo_priv->left_property)
1824 drm_property_destroy(dev, sdvo_priv->left_property);
1825 if (sdvo_priv->right_property)
1826 drm_property_destroy(dev, sdvo_priv->right_property);
1827 if (sdvo_priv->top_property)
1828 drm_property_destroy(dev, sdvo_priv->top_property);
1829 if (sdvo_priv->bottom_property)
1830 drm_property_destroy(dev, sdvo_priv->bottom_property);
1831 if (sdvo_priv->hpos_property)
1832 drm_property_destroy(dev, sdvo_priv->hpos_property);
1833 if (sdvo_priv->vpos_property)
1834 drm_property_destroy(dev, sdvo_priv->vpos_property);
Zhao Yakuib9219c52009-09-10 15:45:46 +08001835 if (sdvo_priv->saturation_property)
1836 drm_property_destroy(dev,
1837 sdvo_priv->saturation_property);
1838 if (sdvo_priv->contrast_property)
1839 drm_property_destroy(dev,
1840 sdvo_priv->contrast_property);
1841 if (sdvo_priv->hue_property)
1842 drm_property_destroy(dev, sdvo_priv->hue_property);
1843 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08001844 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001845 if (sdvo_priv->brightness_property)
1846 drm_property_destroy(dev,
1847 sdvo_priv->brightness_property);
1848 }
1849 return;
1850}
1851
Jesse Barnes79e53942008-11-07 14:24:08 -08001852static void intel_sdvo_destroy(struct drm_connector *connector)
1853{
Zhenyu Wang14571b42010-03-30 14:06:33 +08001854 struct intel_connector *intel_connector = to_intel_connector(connector);
1855 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
1856
1857 if (sdvo_connector->tv_format_property)
1858 drm_property_destroy(connector->dev,
1859 sdvo_connector->tv_format_property);
1860
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001861 intel_sdvo_destroy_enhance_property(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001862 drm_sysfs_connector_remove(connector);
1863 drm_connector_cleanup(connector);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001864 kfree(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -08001865}
1866
Zhao Yakuice6feab2009-08-24 13:50:26 +08001867static int
1868intel_sdvo_set_property(struct drm_connector *connector,
1869 struct drm_property *property,
1870 uint64_t val)
1871{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08001872 struct drm_encoder *encoder = intel_attached_encoder(connector);
1873 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07001874 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001875 struct intel_connector *intel_connector = to_intel_connector(connector);
1876 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001877 struct drm_crtc *crtc = encoder->crtc;
1878 int ret = 0;
1879 bool changed = false;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001880 uint8_t cmd, status;
1881 uint16_t temp_value;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001882
1883 ret = drm_connector_property_set_value(connector, property, val);
1884 if (ret < 0)
1885 goto out;
1886
Zhenyu Wang14571b42010-03-30 14:06:33 +08001887 if (property == sdvo_connector->tv_format_property) {
Zhao Yakuice6feab2009-08-24 13:50:26 +08001888 if (val >= TV_FORMAT_NUM) {
1889 ret = -EINVAL;
1890 goto out;
1891 }
1892 if (sdvo_priv->tv_format_name ==
Zhenyu Wang14571b42010-03-30 14:06:33 +08001893 sdvo_connector->tv_format_supported[val])
Zhao Yakuice6feab2009-08-24 13:50:26 +08001894 goto out;
1895
Zhenyu Wang14571b42010-03-30 14:06:33 +08001896 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val];
Zhao Yakuice6feab2009-08-24 13:50:26 +08001897 changed = true;
Zhao Yakuice6feab2009-08-24 13:50:26 +08001898 }
1899
Zhenyu Wang14571b42010-03-30 14:06:33 +08001900 if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001901 cmd = 0;
1902 temp_value = val;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001903 if (sdvo_connector->left_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001904 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001905 sdvo_connector->right_property, val);
1906 if (sdvo_connector->left_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001907 goto out;
1908
Zhenyu Wang14571b42010-03-30 14:06:33 +08001909 sdvo_connector->left_margin = temp_value;
1910 sdvo_connector->right_margin = temp_value;
1911 temp_value = sdvo_connector->max_hscan -
1912 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001913 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001914 } else if (sdvo_connector->right_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001915 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001916 sdvo_connector->left_property, val);
1917 if (sdvo_connector->right_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001918 goto out;
1919
Zhenyu Wang14571b42010-03-30 14:06:33 +08001920 sdvo_connector->left_margin = temp_value;
1921 sdvo_connector->right_margin = temp_value;
1922 temp_value = sdvo_connector->max_hscan -
1923 sdvo_connector->left_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001924 cmd = SDVO_CMD_SET_OVERSCAN_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001925 } else if (sdvo_connector->top_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001926 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001927 sdvo_connector->bottom_property, val);
1928 if (sdvo_connector->top_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001929 goto out;
1930
Zhenyu Wang14571b42010-03-30 14:06:33 +08001931 sdvo_connector->top_margin = temp_value;
1932 sdvo_connector->bottom_margin = temp_value;
1933 temp_value = sdvo_connector->max_vscan -
1934 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001935 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001936 } else if (sdvo_connector->bottom_property == property) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08001937 drm_connector_property_set_value(connector,
Zhenyu Wang14571b42010-03-30 14:06:33 +08001938 sdvo_connector->top_property, val);
1939 if (sdvo_connector->bottom_margin == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001940 goto out;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001941 sdvo_connector->top_margin = temp_value;
1942 sdvo_connector->bottom_margin = temp_value;
1943 temp_value = sdvo_connector->max_vscan -
1944 sdvo_connector->top_margin;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001945 cmd = SDVO_CMD_SET_OVERSCAN_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001946 } else if (sdvo_connector->hpos_property == property) {
1947 if (sdvo_connector->cur_hpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001948 goto out;
1949
1950 cmd = SDVO_CMD_SET_POSITION_H;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001951 sdvo_connector->cur_hpos = temp_value;
1952 } else if (sdvo_connector->vpos_property == property) {
1953 if (sdvo_connector->cur_vpos == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001954 goto out;
1955
1956 cmd = SDVO_CMD_SET_POSITION_V;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001957 sdvo_connector->cur_vpos = temp_value;
1958 } else if (sdvo_connector->saturation_property == property) {
1959 if (sdvo_connector->cur_saturation == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001960 goto out;
1961
1962 cmd = SDVO_CMD_SET_SATURATION;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001963 sdvo_connector->cur_saturation = temp_value;
1964 } else if (sdvo_connector->contrast_property == property) {
1965 if (sdvo_connector->cur_contrast == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001966 goto out;
1967
1968 cmd = SDVO_CMD_SET_CONTRAST;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001969 sdvo_connector->cur_contrast = temp_value;
1970 } else if (sdvo_connector->hue_property == property) {
1971 if (sdvo_connector->cur_hue == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001972 goto out;
1973
1974 cmd = SDVO_CMD_SET_HUE;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001975 sdvo_connector->cur_hue = temp_value;
1976 } else if (sdvo_connector->brightness_property == property) {
1977 if (sdvo_connector->cur_brightness == temp_value)
Zhao Yakuib9219c52009-09-10 15:45:46 +08001978 goto out;
1979
1980 cmd = SDVO_CMD_SET_BRIGHTNESS;
Zhenyu Wang14571b42010-03-30 14:06:33 +08001981 sdvo_connector->cur_brightness = temp_value;
Zhao Yakuib9219c52009-09-10 15:45:46 +08001982 }
1983 if (cmd) {
Eric Anholt21d40d32010-03-25 11:11:14 -07001984 intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2);
1985 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08001986 NULL, 0);
1987 if (status != SDVO_CMD_STATUS_SUCCESS) {
1988 DRM_DEBUG_KMS("Incorrect SDVO command \n");
1989 return -EINVAL;
1990 }
1991 changed = true;
1992 }
1993 }
Zhao Yakuice6feab2009-08-24 13:50:26 +08001994 if (changed && crtc)
1995 drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
1996 crtc->y, crtc->fb);
1997out:
1998 return ret;
1999}
2000
Jesse Barnes79e53942008-11-07 14:24:08 -08002001static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
2002 .dpms = intel_sdvo_dpms,
2003 .mode_fixup = intel_sdvo_mode_fixup,
2004 .prepare = intel_encoder_prepare,
2005 .mode_set = intel_sdvo_mode_set,
2006 .commit = intel_encoder_commit,
2007};
2008
2009static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
Keith Packardc9fb15f2009-05-30 20:42:28 -07002010 .dpms = drm_helper_connector_dpms,
Jesse Barnes79e53942008-11-07 14:24:08 -08002011 .detect = intel_sdvo_detect,
2012 .fill_modes = drm_helper_probe_single_connector_modes,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002013 .set_property = intel_sdvo_set_property,
Jesse Barnes79e53942008-11-07 14:24:08 -08002014 .destroy = intel_sdvo_destroy,
2015};
2016
2017static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
2018 .get_modes = intel_sdvo_get_modes,
2019 .mode_valid = intel_sdvo_mode_valid,
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002020 .best_encoder = intel_attached_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002021};
2022
Hannes Ederb358d0a2008-12-18 21:18:47 +01002023static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -08002024{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002025 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
2026 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2027
2028 if (intel_encoder->i2c_bus)
2029 intel_i2c_destroy(intel_encoder->i2c_bus);
2030 if (intel_encoder->ddc_bus)
2031 intel_i2c_destroy(intel_encoder->ddc_bus);
2032 if (sdvo_priv->analog_ddc_bus)
2033 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
2034
2035 if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
2036 drm_mode_destroy(encoder->dev,
2037 sdvo_priv->sdvo_lvds_fixed_mode);
2038
Jesse Barnes79e53942008-11-07 14:24:08 -08002039 drm_encoder_cleanup(encoder);
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002040 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002041}
2042
2043static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
2044 .destroy = intel_sdvo_enc_destroy,
2045};
2046
2047
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002048/**
2049 * Choose the appropriate DDC bus for control bus switch command for this
2050 * SDVO output based on the controlled output.
2051 *
2052 * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
2053 * outputs, then LVDS outputs.
2054 */
2055static void
2056intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
2057{
2058 uint16_t mask = 0;
2059 unsigned int num_bits;
2060
2061 /* Make a mask of outputs less than or equal to our own priority in the
2062 * list.
2063 */
2064 switch (dev_priv->controlled_output) {
2065 case SDVO_OUTPUT_LVDS1:
2066 mask |= SDVO_OUTPUT_LVDS1;
2067 case SDVO_OUTPUT_LVDS0:
2068 mask |= SDVO_OUTPUT_LVDS0;
2069 case SDVO_OUTPUT_TMDS1:
2070 mask |= SDVO_OUTPUT_TMDS1;
2071 case SDVO_OUTPUT_TMDS0:
2072 mask |= SDVO_OUTPUT_TMDS0;
2073 case SDVO_OUTPUT_RGB1:
2074 mask |= SDVO_OUTPUT_RGB1;
2075 case SDVO_OUTPUT_RGB0:
2076 mask |= SDVO_OUTPUT_RGB0;
2077 break;
2078 }
2079
2080 /* Count bits to find what number we are in the priority list. */
2081 mask &= dev_priv->caps.output_flags;
2082 num_bits = hweight16(mask);
2083 if (num_bits > 3) {
2084 /* if more than 3 outputs, default to DDC bus 3 for now */
2085 num_bits = 3;
2086 }
2087
2088 /* Corresponds to SDVO_CONTROL_BUS_DDCx */
2089 dev_priv->ddc_bus = 1 << num_bits;
2090}
2091
2092static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002093intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device)
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002094{
2095 struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
2096 uint8_t status;
2097
Zhenyu Wang14571b42010-03-30 14:06:33 +08002098 if (device == 0)
2099 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0);
2100 else
2101 intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1);
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002102
2103 intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
2104 status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
2105 if (status != SDVO_CMD_STATUS_SUCCESS)
2106 return false;
2107 return true;
2108}
2109
Eric Anholt21d40d32010-03-25 11:11:14 -07002110static struct intel_encoder *
2111intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan)
Ma Ling619ac3b2009-05-18 16:12:46 +08002112{
2113 struct drm_device *dev = chan->drm_dev;
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002114 struct drm_encoder *encoder;
Eric Anholt21d40d32010-03-25 11:11:14 -07002115 struct intel_encoder *intel_encoder = NULL;
Ma Ling619ac3b2009-05-18 16:12:46 +08002116
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002117 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2118 intel_encoder = enc_to_intel_encoder(encoder);
2119 if (intel_encoder->ddc_bus == &chan->adapter)
Ma Ling619ac3b2009-05-18 16:12:46 +08002120 break;
Ma Ling619ac3b2009-05-18 16:12:46 +08002121 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002122 return intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002123}
2124
2125static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
2126 struct i2c_msg msgs[], int num)
2127{
Eric Anholt21d40d32010-03-25 11:11:14 -07002128 struct intel_encoder *intel_encoder;
Ma Ling619ac3b2009-05-18 16:12:46 +08002129 struct intel_sdvo_priv *sdvo_priv;
2130 struct i2c_algo_bit_data *algo_data;
Keith Packardf9c10a92009-05-30 12:16:25 -07002131 const struct i2c_algorithm *algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002132
2133 algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
Eric Anholt21d40d32010-03-25 11:11:14 -07002134 intel_encoder =
2135 intel_sdvo_chan_to_intel_encoder(
Ma Ling619ac3b2009-05-18 16:12:46 +08002136 (struct intel_i2c_chan *)(algo_data->data));
Eric Anholt21d40d32010-03-25 11:11:14 -07002137 if (intel_encoder == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002138 return -EINVAL;
2139
Eric Anholt21d40d32010-03-25 11:11:14 -07002140 sdvo_priv = intel_encoder->dev_priv;
2141 algo = intel_encoder->i2c_bus->algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002142
Eric Anholt21d40d32010-03-25 11:11:14 -07002143 intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus);
Ma Ling619ac3b2009-05-18 16:12:46 +08002144 return algo->master_xfer(i2c_adap, msgs, num);
2145}
2146
2147static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
2148 .master_xfer = intel_sdvo_master_xfer,
2149};
2150
yakui_zhao714605e2009-05-31 17:18:07 +08002151static u8
Eric Anholtc751ce42010-03-25 11:48:48 -07002152intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg)
yakui_zhao714605e2009-05-31 17:18:07 +08002153{
2154 struct drm_i915_private *dev_priv = dev->dev_private;
2155 struct sdvo_device_mapping *my_mapping, *other_mapping;
2156
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002157 if (IS_SDVOB(sdvo_reg)) {
yakui_zhao714605e2009-05-31 17:18:07 +08002158 my_mapping = &dev_priv->sdvo_mappings[0];
2159 other_mapping = &dev_priv->sdvo_mappings[1];
2160 } else {
2161 my_mapping = &dev_priv->sdvo_mappings[1];
2162 other_mapping = &dev_priv->sdvo_mappings[0];
2163 }
2164
2165 /* If the BIOS described our SDVO device, take advantage of it. */
2166 if (my_mapping->slave_addr)
2167 return my_mapping->slave_addr;
2168
2169 /* If the BIOS only described a different SDVO device, use the
2170 * address that it isn't using.
2171 */
2172 if (other_mapping->slave_addr) {
2173 if (other_mapping->slave_addr == 0x70)
2174 return 0x72;
2175 else
2176 return 0x70;
2177 }
2178
2179 /* No SDVO device info is found for another DVO port,
2180 * so use mapping assumption we had before BIOS parsing.
2181 */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002182 if (IS_SDVOB(sdvo_reg))
yakui_zhao714605e2009-05-31 17:18:07 +08002183 return 0x70;
2184 else
2185 return 0x72;
2186}
2187
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002188static bool
Zhenyu Wang14571b42010-03-30 14:06:33 +08002189intel_sdvo_connector_alloc (struct intel_connector **ret)
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002190{
Zhenyu Wang14571b42010-03-30 14:06:33 +08002191 struct intel_connector *intel_connector;
2192 struct intel_sdvo_connector *sdvo_connector;
2193
2194 *ret = kzalloc(sizeof(*intel_connector) +
2195 sizeof(*sdvo_connector), GFP_KERNEL);
2196 if (!*ret)
2197 return false;
2198
2199 intel_connector = *ret;
2200 sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1);
2201 intel_connector->dev_priv = sdvo_connector;
2202
2203 return true;
2204}
2205
2206static void
2207intel_sdvo_connector_create (struct drm_encoder *encoder,
2208 struct drm_connector *connector)
2209{
2210 drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs,
2211 connector->connector_type);
2212
2213 drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
2214
2215 connector->interlace_allowed = 0;
2216 connector->doublescan_allowed = 0;
2217 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
2218
2219 drm_mode_connector_attach_encoder(connector, encoder);
2220 drm_sysfs_connector_add(connector);
2221}
2222
2223static bool
2224intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device)
2225{
Eric Anholt21d40d32010-03-25 11:11:14 -07002226 struct drm_encoder *encoder = &intel_encoder->enc;
2227 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002228 struct drm_connector *connector;
2229 struct intel_connector *intel_connector;
2230 struct intel_sdvo_connector *sdvo_connector;
2231
2232 if (!intel_sdvo_connector_alloc(&intel_connector))
2233 return false;
2234
2235 sdvo_connector = intel_connector->dev_priv;
2236
2237 if (device == 0) {
2238 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0;
2239 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
2240 } else if (device == 1) {
2241 sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1;
2242 sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
2243 }
2244
2245 connector = &intel_connector->base;
2246 encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
2247 connector->connector_type = DRM_MODE_CONNECTOR_DVID;
2248
2249 if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode)
2250 && intel_sdvo_get_digital_encoding_mode(intel_encoder, device)
2251 && sdvo_priv->is_hdmi) {
2252 /* enable hdmi encoding mode if supported */
2253 intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI);
2254 intel_sdvo_set_colorimetry(intel_encoder,
2255 SDVO_COLORIMETRY_RGB256);
2256 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
2257 }
2258 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2259 (1 << INTEL_ANALOG_CLONE_BIT);
2260
2261 intel_sdvo_connector_create(encoder, connector);
2262
2263 return true;
2264}
2265
2266static bool
2267intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type)
2268{
2269 struct drm_encoder *encoder = &intel_encoder->enc;
2270 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2271 struct drm_connector *connector;
2272 struct intel_connector *intel_connector;
2273 struct intel_sdvo_connector *sdvo_connector;
2274
2275 if (!intel_sdvo_connector_alloc(&intel_connector))
2276 return false;
2277
2278 connector = &intel_connector->base;
2279 encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
2280 connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
2281 sdvo_connector = intel_connector->dev_priv;
2282
2283 sdvo_priv->controlled_output |= type;
2284 sdvo_connector->output_flag = type;
2285
2286 sdvo_priv->is_tv = true;
2287 intel_encoder->needs_tv_clock = true;
2288 intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
2289
2290 intel_sdvo_connector_create(encoder, connector);
2291
2292 intel_sdvo_tv_create_property(connector, type);
2293
2294 intel_sdvo_create_enhance_property(connector);
2295
2296 return true;
2297}
2298
2299static bool
2300intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device)
2301{
2302 struct drm_encoder *encoder = &intel_encoder->enc;
2303 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2304 struct drm_connector *connector;
2305 struct intel_connector *intel_connector;
2306 struct intel_sdvo_connector *sdvo_connector;
2307
2308 if (!intel_sdvo_connector_alloc(&intel_connector))
2309 return false;
2310
2311 connector = &intel_connector->base;
2312 encoder->encoder_type = DRM_MODE_ENCODER_DAC;
2313 connector->connector_type = DRM_MODE_CONNECTOR_VGA;
2314 sdvo_connector = intel_connector->dev_priv;
2315
2316 if (device == 0) {
2317 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0;
2318 sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
2319 } else if (device == 1) {
2320 sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1;
2321 sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
2322 }
2323
2324 intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
2325 (1 << INTEL_ANALOG_CLONE_BIT);
2326
2327 intel_sdvo_connector_create(encoder, connector);
2328 return true;
2329}
2330
2331static bool
2332intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device)
2333{
2334 struct drm_encoder *encoder = &intel_encoder->enc;
2335 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
2336 struct drm_connector *connector;
2337 struct intel_connector *intel_connector;
2338 struct intel_sdvo_connector *sdvo_connector;
2339
2340 if (!intel_sdvo_connector_alloc(&intel_connector))
2341 return false;
2342
2343 connector = &intel_connector->base;
2344 encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
2345 connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
2346 sdvo_connector = intel_connector->dev_priv;
2347
2348 sdvo_priv->is_lvds = true;
2349
2350 if (device == 0) {
2351 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0;
2352 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
2353 } else if (device == 1) {
2354 sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1;
2355 sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
2356 }
2357
2358 intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
2359 (1 << INTEL_SDVO_LVDS_CLONE_BIT);
2360
2361 intel_sdvo_connector_create(encoder, connector);
2362 intel_sdvo_create_enhance_property(connector);
2363 return true;
2364}
2365
2366static bool
2367intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags)
2368{
2369 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002370
2371 sdvo_priv->is_tv = false;
Eric Anholt21d40d32010-03-25 11:11:14 -07002372 intel_encoder->needs_tv_clock = false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002373 sdvo_priv->is_lvds = false;
2374
Zhenyu Wang14571b42010-03-30 14:06:33 +08002375 /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002376
Zhenyu Wang14571b42010-03-30 14:06:33 +08002377 if (flags & SDVO_OUTPUT_TMDS0)
2378 if (!intel_sdvo_dvi_init(intel_encoder, 0))
2379 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002380
Zhenyu Wang14571b42010-03-30 14:06:33 +08002381 if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
2382 if (!intel_sdvo_dvi_init(intel_encoder, 1))
2383 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002384
Zhenyu Wang14571b42010-03-30 14:06:33 +08002385 /* TV has no XXX1 function block */
Zhenyu Wanga1f4b7f2010-03-29 23:16:13 +08002386 if (flags & SDVO_OUTPUT_SVID0)
Zhenyu Wang14571b42010-03-30 14:06:33 +08002387 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0))
2388 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002389
Zhenyu Wang14571b42010-03-30 14:06:33 +08002390 if (flags & SDVO_OUTPUT_CVBS0)
2391 if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0))
2392 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002393
Zhenyu Wang14571b42010-03-30 14:06:33 +08002394 if (flags & SDVO_OUTPUT_RGB0)
2395 if (!intel_sdvo_analog_init(intel_encoder, 0))
2396 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002397
Zhenyu Wang14571b42010-03-30 14:06:33 +08002398 if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
2399 if (!intel_sdvo_analog_init(intel_encoder, 1))
2400 return false;
Zhao Yakui2dd87382010-01-27 16:32:46 +08002401
Zhenyu Wang14571b42010-03-30 14:06:33 +08002402 if (flags & SDVO_OUTPUT_LVDS0)
2403 if (!intel_sdvo_lvds_init(intel_encoder, 0))
2404 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002405
Zhenyu Wang14571b42010-03-30 14:06:33 +08002406 if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
2407 if (!intel_sdvo_lvds_init(intel_encoder, 1))
2408 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002409
Zhenyu Wang14571b42010-03-30 14:06:33 +08002410 if ((flags & SDVO_OUTPUT_MASK) == 0) {
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002411 unsigned char bytes[2];
2412
2413 sdvo_priv->controlled_output = 0;
2414 memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
Dave Airlie51c8b402009-08-20 13:38:04 +10002415 DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
2416 SDVO_NAME(sdvo_priv),
2417 bytes[0], bytes[1]);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002418 return false;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002419 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002420 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002421
Zhenyu Wang14571b42010-03-30 14:06:33 +08002422 return true;
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002423}
2424
Zhenyu Wang14571b42010-03-30 14:06:33 +08002425static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002426{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002427 struct drm_encoder *encoder = intel_attached_encoder(connector);
2428 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Eric Anholt21d40d32010-03-25 11:11:14 -07002429 struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv;
Zhenyu Wang14571b42010-03-30 14:06:33 +08002430 struct intel_connector *intel_connector = to_intel_connector(connector);
2431 struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002432 struct intel_sdvo_tv_format format;
2433 uint32_t format_map, i;
2434 uint8_t status;
2435
Zhenyu Wang14571b42010-03-30 14:06:33 +08002436 intel_sdvo_set_target_output(intel_encoder, type);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002437
Eric Anholt21d40d32010-03-25 11:11:14 -07002438 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002439 SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002440 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuice6feab2009-08-24 13:50:26 +08002441 &format, sizeof(format));
2442 if (status != SDVO_CMD_STATUS_SUCCESS)
2443 return;
2444
2445 memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
2446 sizeof(format_map) : sizeof(format));
2447
2448 if (format_map == 0)
2449 return;
2450
Zhenyu Wang14571b42010-03-30 14:06:33 +08002451 sdvo_connector->format_supported_num = 0;
Zhao Yakuice6feab2009-08-24 13:50:26 +08002452 for (i = 0 ; i < TV_FORMAT_NUM; i++)
2453 if (format_map & (1 << i)) {
Zhenyu Wang14571b42010-03-30 14:06:33 +08002454 sdvo_connector->tv_format_supported
2455 [sdvo_connector->format_supported_num++] =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002456 tv_format_names[i];
2457 }
2458
2459
Zhenyu Wang14571b42010-03-30 14:06:33 +08002460 sdvo_connector->tv_format_property =
Zhao Yakuice6feab2009-08-24 13:50:26 +08002461 drm_property_create(
2462 connector->dev, DRM_MODE_PROP_ENUM,
Zhenyu Wang14571b42010-03-30 14:06:33 +08002463 "mode", sdvo_connector->format_supported_num);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002464
Zhenyu Wang14571b42010-03-30 14:06:33 +08002465 for (i = 0; i < sdvo_connector->format_supported_num; i++)
Zhao Yakuice6feab2009-08-24 13:50:26 +08002466 drm_property_add_enum(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002467 sdvo_connector->tv_format_property, i,
2468 i, sdvo_connector->tv_format_supported[i]);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002469
Zhenyu Wang14571b42010-03-30 14:06:33 +08002470 sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0];
Zhao Yakuice6feab2009-08-24 13:50:26 +08002471 drm_connector_attach_property(
Zhenyu Wang14571b42010-03-30 14:06:33 +08002472 connector, sdvo_connector->tv_format_property, 0);
Zhao Yakuice6feab2009-08-24 13:50:26 +08002473
2474}
2475
Zhao Yakuib9219c52009-09-10 15:45:46 +08002476static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
2477{
Zhenyu Wangd2a82a62010-03-29 21:22:55 +08002478 struct drm_encoder *encoder = intel_attached_encoder(connector);
2479 struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder);
Zhenyu Wang14571b42010-03-30 14:06:33 +08002480 struct intel_connector *intel_connector = to_intel_connector(connector);
2481 struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv;
Zhao Yakuib9219c52009-09-10 15:45:46 +08002482 struct intel_sdvo_enhancements_reply sdvo_data;
2483 struct drm_device *dev = connector->dev;
2484 uint8_t status;
2485 uint16_t response, data_value[2];
2486
Eric Anholt21d40d32010-03-25 11:11:14 -07002487 intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002488 NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002489 status = intel_sdvo_read_response(intel_encoder, &sdvo_data,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002490 sizeof(sdvo_data));
2491 if (status != SDVO_CMD_STATUS_SUCCESS) {
2492 DRM_DEBUG_KMS(" incorrect response is returned\n");
2493 return;
2494 }
2495 response = *((uint16_t *)&sdvo_data);
2496 if (!response) {
2497 DRM_DEBUG_KMS("No enhancement is supported\n");
2498 return;
2499 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002500 if (IS_TV(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002501 /* when horizontal overscan is supported, Add the left/right
2502 * property
2503 */
2504 if (sdvo_data.overscan_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002505 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002506 SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002507 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002508 &data_value, 4);
2509 if (status != SDVO_CMD_STATUS_SUCCESS) {
2510 DRM_DEBUG_KMS("Incorrect SDVO max "
2511 "h_overscan\n");
2512 return;
2513 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002514 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002515 SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002516 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002517 &response, 2);
2518 if (status != SDVO_CMD_STATUS_SUCCESS) {
2519 DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
2520 return;
2521 }
2522 sdvo_priv->max_hscan = data_value[0];
2523 sdvo_priv->left_margin = data_value[0] - response;
2524 sdvo_priv->right_margin = sdvo_priv->left_margin;
2525 sdvo_priv->left_property =
2526 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2527 "left_margin", 2);
2528 sdvo_priv->left_property->values[0] = 0;
2529 sdvo_priv->left_property->values[1] = data_value[0];
2530 drm_connector_attach_property(connector,
2531 sdvo_priv->left_property,
2532 sdvo_priv->left_margin);
2533 sdvo_priv->right_property =
2534 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2535 "right_margin", 2);
2536 sdvo_priv->right_property->values[0] = 0;
2537 sdvo_priv->right_property->values[1] = data_value[0];
2538 drm_connector_attach_property(connector,
2539 sdvo_priv->right_property,
2540 sdvo_priv->right_margin);
2541 DRM_DEBUG_KMS("h_overscan: max %d, "
2542 "default %d, current %d\n",
2543 data_value[0], data_value[1], response);
2544 }
2545 if (sdvo_data.overscan_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002546 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002547 SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002548 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002549 &data_value, 4);
2550 if (status != SDVO_CMD_STATUS_SUCCESS) {
2551 DRM_DEBUG_KMS("Incorrect SDVO max "
2552 "v_overscan\n");
2553 return;
2554 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002555 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002556 SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002557 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002558 &response, 2);
2559 if (status != SDVO_CMD_STATUS_SUCCESS) {
2560 DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
2561 return;
2562 }
2563 sdvo_priv->max_vscan = data_value[0];
2564 sdvo_priv->top_margin = data_value[0] - response;
2565 sdvo_priv->bottom_margin = sdvo_priv->top_margin;
2566 sdvo_priv->top_property =
2567 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2568 "top_margin", 2);
2569 sdvo_priv->top_property->values[0] = 0;
2570 sdvo_priv->top_property->values[1] = data_value[0];
2571 drm_connector_attach_property(connector,
2572 sdvo_priv->top_property,
2573 sdvo_priv->top_margin);
2574 sdvo_priv->bottom_property =
2575 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2576 "bottom_margin", 2);
2577 sdvo_priv->bottom_property->values[0] = 0;
2578 sdvo_priv->bottom_property->values[1] = data_value[0];
2579 drm_connector_attach_property(connector,
2580 sdvo_priv->bottom_property,
2581 sdvo_priv->bottom_margin);
2582 DRM_DEBUG_KMS("v_overscan: max %d, "
2583 "default %d, current %d\n",
2584 data_value[0], data_value[1], response);
2585 }
2586 if (sdvo_data.position_h) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002587 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002588 SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002589 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002590 &data_value, 4);
2591 if (status != SDVO_CMD_STATUS_SUCCESS) {
2592 DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
2593 return;
2594 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002595 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002596 SDVO_CMD_GET_POSITION_H, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002597 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002598 &response, 2);
2599 if (status != SDVO_CMD_STATUS_SUCCESS) {
2600 DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
2601 return;
2602 }
2603 sdvo_priv->max_hpos = data_value[0];
2604 sdvo_priv->cur_hpos = response;
2605 sdvo_priv->hpos_property =
2606 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2607 "hpos", 2);
2608 sdvo_priv->hpos_property->values[0] = 0;
2609 sdvo_priv->hpos_property->values[1] = data_value[0];
2610 drm_connector_attach_property(connector,
2611 sdvo_priv->hpos_property,
2612 sdvo_priv->cur_hpos);
2613 DRM_DEBUG_KMS("h_position: max %d, "
2614 "default %d, current %d\n",
2615 data_value[0], data_value[1], response);
2616 }
2617 if (sdvo_data.position_v) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002618 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002619 SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002620 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002621 &data_value, 4);
2622 if (status != SDVO_CMD_STATUS_SUCCESS) {
2623 DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
2624 return;
2625 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002626 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002627 SDVO_CMD_GET_POSITION_V, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002628 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002629 &response, 2);
2630 if (status != SDVO_CMD_STATUS_SUCCESS) {
2631 DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
2632 return;
2633 }
2634 sdvo_priv->max_vpos = data_value[0];
2635 sdvo_priv->cur_vpos = response;
2636 sdvo_priv->vpos_property =
2637 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2638 "vpos", 2);
2639 sdvo_priv->vpos_property->values[0] = 0;
2640 sdvo_priv->vpos_property->values[1] = data_value[0];
2641 drm_connector_attach_property(connector,
2642 sdvo_priv->vpos_property,
2643 sdvo_priv->cur_vpos);
2644 DRM_DEBUG_KMS("v_position: max %d, "
2645 "default %d, current %d\n",
2646 data_value[0], data_value[1], response);
2647 }
Zhao Yakuib9219c52009-09-10 15:45:46 +08002648 if (sdvo_data.saturation) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002649 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002650 SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002651 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002652 &data_value, 4);
2653 if (status != SDVO_CMD_STATUS_SUCCESS) {
2654 DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
2655 return;
2656 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002657 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002658 SDVO_CMD_GET_SATURATION, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002659 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002660 &response, 2);
2661 if (status != SDVO_CMD_STATUS_SUCCESS) {
2662 DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
2663 return;
2664 }
2665 sdvo_priv->max_saturation = data_value[0];
2666 sdvo_priv->cur_saturation = response;
2667 sdvo_priv->saturation_property =
2668 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2669 "saturation", 2);
2670 sdvo_priv->saturation_property->values[0] = 0;
2671 sdvo_priv->saturation_property->values[1] =
2672 data_value[0];
2673 drm_connector_attach_property(connector,
2674 sdvo_priv->saturation_property,
2675 sdvo_priv->cur_saturation);
2676 DRM_DEBUG_KMS("saturation: max %d, "
2677 "default %d, current %d\n",
2678 data_value[0], data_value[1], response);
2679 }
2680 if (sdvo_data.contrast) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002681 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002682 SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002683 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002684 &data_value, 4);
2685 if (status != SDVO_CMD_STATUS_SUCCESS) {
2686 DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
2687 return;
2688 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002689 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002690 SDVO_CMD_GET_CONTRAST, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002691 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002692 &response, 2);
2693 if (status != SDVO_CMD_STATUS_SUCCESS) {
2694 DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
2695 return;
2696 }
2697 sdvo_priv->max_contrast = data_value[0];
2698 sdvo_priv->cur_contrast = response;
2699 sdvo_priv->contrast_property =
2700 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2701 "contrast", 2);
2702 sdvo_priv->contrast_property->values[0] = 0;
2703 sdvo_priv->contrast_property->values[1] = data_value[0];
2704 drm_connector_attach_property(connector,
2705 sdvo_priv->contrast_property,
2706 sdvo_priv->cur_contrast);
2707 DRM_DEBUG_KMS("contrast: max %d, "
2708 "default %d, current %d\n",
2709 data_value[0], data_value[1], response);
2710 }
2711 if (sdvo_data.hue) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002712 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002713 SDVO_CMD_GET_MAX_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002714 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002715 &data_value, 4);
2716 if (status != SDVO_CMD_STATUS_SUCCESS) {
2717 DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
2718 return;
2719 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002720 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002721 SDVO_CMD_GET_HUE, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002722 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002723 &response, 2);
2724 if (status != SDVO_CMD_STATUS_SUCCESS) {
2725 DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
2726 return;
2727 }
2728 sdvo_priv->max_hue = data_value[0];
2729 sdvo_priv->cur_hue = response;
2730 sdvo_priv->hue_property =
2731 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2732 "hue", 2);
2733 sdvo_priv->hue_property->values[0] = 0;
2734 sdvo_priv->hue_property->values[1] =
2735 data_value[0];
2736 drm_connector_attach_property(connector,
2737 sdvo_priv->hue_property,
2738 sdvo_priv->cur_hue);
2739 DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
2740 data_value[0], data_value[1], response);
2741 }
2742 }
Zhenyu Wang14571b42010-03-30 14:06:33 +08002743 if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) {
Zhao Yakuib9219c52009-09-10 15:45:46 +08002744 if (sdvo_data.brightness) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002745 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002746 SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002747 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002748 &data_value, 4);
2749 if (status != SDVO_CMD_STATUS_SUCCESS) {
2750 DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
2751 return;
2752 }
Eric Anholt21d40d32010-03-25 11:11:14 -07002753 intel_sdvo_write_cmd(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002754 SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
Eric Anholt21d40d32010-03-25 11:11:14 -07002755 status = intel_sdvo_read_response(intel_encoder,
Zhao Yakuib9219c52009-09-10 15:45:46 +08002756 &response, 2);
2757 if (status != SDVO_CMD_STATUS_SUCCESS) {
2758 DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
2759 return;
2760 }
2761 sdvo_priv->max_brightness = data_value[0];
2762 sdvo_priv->cur_brightness = response;
2763 sdvo_priv->brightness_property =
2764 drm_property_create(dev, DRM_MODE_PROP_RANGE,
2765 "brightness", 2);
2766 sdvo_priv->brightness_property->values[0] = 0;
2767 sdvo_priv->brightness_property->values[1] =
2768 data_value[0];
2769 drm_connector_attach_property(connector,
2770 sdvo_priv->brightness_property,
2771 sdvo_priv->cur_brightness);
2772 DRM_DEBUG_KMS("brightness: max %d, "
2773 "default %d, current %d\n",
2774 data_value[0], data_value[1], response);
2775 }
2776 }
2777 return;
2778}
2779
Eric Anholtc751ce42010-03-25 11:48:48 -07002780bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg)
Jesse Barnes79e53942008-11-07 14:24:08 -08002781{
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002782 struct drm_i915_private *dev_priv = dev->dev_private;
Eric Anholt21d40d32010-03-25 11:11:14 -07002783 struct intel_encoder *intel_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -08002784 struct intel_sdvo_priv *sdvo_priv;
Jesse Barnes79e53942008-11-07 14:24:08 -08002785 u8 ch[0x40];
2786 int i;
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002787 u32 i2c_reg, ddc_reg, analog_ddc_reg;
Jesse Barnes79e53942008-11-07 14:24:08 -08002788
Eric Anholt21d40d32010-03-25 11:11:14 -07002789 intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
2790 if (!intel_encoder) {
Eric Anholt7d573822009-01-02 13:33:00 -08002791 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002792 }
2793
Eric Anholt21d40d32010-03-25 11:11:14 -07002794 sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1);
Eric Anholtc751ce42010-03-25 11:48:48 -07002795 sdvo_priv->sdvo_reg = sdvo_reg;
Keith Packard308cd3a2009-06-14 11:56:18 -07002796
Eric Anholt21d40d32010-03-25 11:11:14 -07002797 intel_encoder->dev_priv = sdvo_priv;
2798 intel_encoder->type = INTEL_OUTPUT_SDVO;
Jesse Barnes79e53942008-11-07 14:24:08 -08002799
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002800 if (HAS_PCH_SPLIT(dev)) {
2801 i2c_reg = PCH_GPIOE;
2802 ddc_reg = PCH_GPIOE;
2803 analog_ddc_reg = PCH_GPIOA;
2804 } else {
2805 i2c_reg = GPIOE;
2806 ddc_reg = GPIOE;
2807 analog_ddc_reg = GPIOA;
2808 }
2809
Jesse Barnes79e53942008-11-07 14:24:08 -08002810 /* setup the DDC bus. */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002811 if (IS_SDVOB(sdvo_reg))
2812 intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB");
Keith Packard308cd3a2009-06-14 11:56:18 -07002813 else
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002814 intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC");
Keith Packard308cd3a2009-06-14 11:56:18 -07002815
Eric Anholt21d40d32010-03-25 11:11:14 -07002816 if (!intel_encoder->i2c_bus)
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002817 goto err_inteloutput;
Jesse Barnes79e53942008-11-07 14:24:08 -08002818
Eric Anholtc751ce42010-03-25 11:48:48 -07002819 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg);
Jesse Barnes79e53942008-11-07 14:24:08 -08002820
Keith Packard308cd3a2009-06-14 11:56:18 -07002821 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
Eric Anholt21d40d32010-03-25 11:11:14 -07002822 intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality;
Jesse Barnes79e53942008-11-07 14:24:08 -08002823
Jesse Barnes79e53942008-11-07 14:24:08 -08002824 /* Read the regs to test if we can talk to the device */
2825 for (i = 0; i < 0x40; i++) {
Eric Anholt21d40d32010-03-25 11:11:14 -07002826 if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) {
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002827 DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002828 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002829 goto err_i2c;
2830 }
2831 }
2832
Ma Ling619ac3b2009-05-18 16:12:46 +08002833 /* setup the DDC bus. */
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002834 if (IS_SDVOB(sdvo_reg)) {
2835 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS");
2836 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
Keith Packard57cdaf92009-09-04 13:07:54 +08002837 "SDVOB/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002838 dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002839 } else {
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002840 intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS");
2841 sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg,
Keith Packard57cdaf92009-09-04 13:07:54 +08002842 "SDVOC/VGA DDC BUS");
Jesse Barnesb01f2c32009-12-11 11:07:17 -08002843 dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
Keith Packard57cdaf92009-09-04 13:07:54 +08002844 }
Ma Ling619ac3b2009-05-18 16:12:46 +08002845
Eric Anholt21d40d32010-03-25 11:11:14 -07002846 if (intel_encoder->ddc_bus == NULL)
Ma Ling619ac3b2009-05-18 16:12:46 +08002847 goto err_i2c;
2848
Keith Packard308cd3a2009-06-14 11:56:18 -07002849 /* Wrap with our custom algo which switches to DDC mode */
Eric Anholt21d40d32010-03-25 11:11:14 -07002850 intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
Ma Ling619ac3b2009-05-18 16:12:46 +08002851
Zhenyu Wang14571b42010-03-30 14:06:33 +08002852 /* encoder type will be decided later */
2853 drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0);
2854 drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs);
2855
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002856 /* In default case sdvo lvds is false */
Eric Anholt21d40d32010-03-25 11:11:14 -07002857 intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps);
Jesse Barnes79e53942008-11-07 14:24:08 -08002858
Zhenyu Wang14571b42010-03-30 14:06:33 +08002859 if (intel_sdvo_output_setup(intel_encoder,
ling.ma@intel.comfb7a46f2009-07-23 17:11:34 +08002860 sdvo_priv->caps.output_flags) != true) {
Dave Airlie51c8b402009-08-20 13:38:04 +10002861 DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
Zhao Yakui461ed3c2010-03-30 15:11:33 +08002862 IS_SDVOB(sdvo_reg) ? 'B' : 'C');
Jesse Barnes79e53942008-11-07 14:24:08 -08002863 goto err_i2c;
2864 }
2865
Jesse Barnese2f0ba92009-02-02 15:11:52 -08002866 intel_sdvo_select_ddc_bus(sdvo_priv);
2867
Jesse Barnes79e53942008-11-07 14:24:08 -08002868 /* Set the input timing to the screen. Assume always input 0. */
Eric Anholt21d40d32010-03-25 11:11:14 -07002869 intel_sdvo_set_target_input(intel_encoder, true, false);
Jesse Barnes79e53942008-11-07 14:24:08 -08002870
Eric Anholt21d40d32010-03-25 11:11:14 -07002871 intel_sdvo_get_input_pixel_clock_range(intel_encoder,
Jesse Barnes79e53942008-11-07 14:24:08 -08002872 &sdvo_priv->pixel_clock_min,
2873 &sdvo_priv->pixel_clock_max);
2874
2875
Zhao Yakui8a4c47f2009-07-20 13:48:04 +08002876 DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
yakui_zhao342dc382009-06-02 14:12:00 +08002877 "clock range %dMHz - %dMHz, "
2878 "input 1: %c, input 2: %c, "
2879 "output 1: %c, output 2: %c\n",
2880 SDVO_NAME(sdvo_priv),
2881 sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
2882 sdvo_priv->caps.device_rev_id,
2883 sdvo_priv->pixel_clock_min / 1000,
2884 sdvo_priv->pixel_clock_max / 1000,
2885 (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
2886 (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
2887 /* check currently supported outputs */
2888 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002889 (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
yakui_zhao342dc382009-06-02 14:12:00 +08002890 sdvo_priv->caps.output_flags &
Jesse Barnes79e53942008-11-07 14:24:08 -08002891 (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
2892
Eric Anholt7d573822009-01-02 13:33:00 -08002893 return true;
Jesse Barnes79e53942008-11-07 14:24:08 -08002894
2895err_i2c:
Keith Packard57cdaf92009-09-04 13:07:54 +08002896 if (sdvo_priv->analog_ddc_bus != NULL)
2897 intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
Eric Anholt21d40d32010-03-25 11:11:14 -07002898 if (intel_encoder->ddc_bus != NULL)
2899 intel_i2c_destroy(intel_encoder->ddc_bus);
2900 if (intel_encoder->i2c_bus != NULL)
2901 intel_i2c_destroy(intel_encoder->i2c_bus);
Jonas Bonnad5b2a62009-05-15 09:10:41 +02002902err_inteloutput:
Eric Anholt21d40d32010-03-25 11:11:14 -07002903 kfree(intel_encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -08002904
Eric Anholt7d573822009-01-02 13:33:00 -08002905 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -08002906}